aboutsummaryrefslogtreecommitdiff
path: root/w9x/ch375vxd.h
blob: 3d3db26165036d02fe425548e6174b9eb3267553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * CHU - IO routines to CH375 from a IOS VxD
 * Copyright (C) 2024-2026 Javier S. Pedro
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef CH375VXD_H
#define CH375VXD_H

#include <stdint.h>
#include <stdbool.h>
#include <conio.h>
#include <ch375.h>

struct ch375 {
	uint16_t io_base;
};

static inline uint8_t ch375_read_data(struct ch375 *dev)
{
	return inp(dev->io_base + CH375_PORT_DATA);
}

static inline void ch375_write_data(struct ch375 *dev, uint8_t data)
{
	outp(dev->io_base + CH375_PORT_DATA, data);
}

static inline void ch375_send_command(struct ch375 *dev, enum ch375_command cmd)
{
	outp(dev->io_base + CH375_PORT_CMD, cmd);
}

/// True if interrupt line is currently active (i.e. low)
static inline bool ch375_poll_interrupt(struct ch375 *dev)
{
	return !(inp(dev->io_base + CH375_PORT_CMD) & 0x80);
}


/** Reads one transfer block (64 bytes max). */
// Watcom does not seem able to synthesize rep ins/outs. Do it in 286+ mode.
static uint8_t ch375_read_data_block(struct ch375 *dev, uint8_t far *buffer);
#pragma aux ch375_read_data_block = \
	"mov dx, [ebx]" \
	"in al, dx" \
	"movzx ecx, al" \
	"rep ins byte ptr [edi], dx" \
	__parm [ebx] [edi] \
	__value [al] \
	__modify exact [ecx dx edi]

static void ch375_write_data_block(struct ch375 *dev, uint8_t far *buffer, uint8_t n);
#pragma aux ch375_write_data_block = \
	"mov dx, [ebx]" \
	"out dx, al" \
	"movzx ecx, al" \
	"rep outs dx, byte ptr [esi]" \
	__parm [ebx] [esi] [al] \
	__modify exact [ecx dx esi]

#endif // CH375VXD_H