aboutsummaryrefslogtreecommitdiff
path: root/dos/ch375dos.h
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2026-10-26 00:50:06 +0100
committerJavier <dev.git@javispedro.com>2026-10-26 00:50:06 +0100
commit6b8a368c51082fdd010ef5e1b0be4eb9b5059d1a (patch)
treee274d41a8dd5e912e20617a937a1fda5af91f8de /dos/ch375dos.h
parent9b1cf601360fb194047e6dcc2af75c2f38c611ec (diff)
downloadchu-6b8a368c51082fdd010ef5e1b0be4eb9b5059d1a.tar.gz
chu-6b8a368c51082fdd010ef5e1b0be4eb9b5059d1a.zip
refactor common parts into inc/ch375.h and add win9x, linux drivers
Diffstat (limited to 'dos/ch375dos.h')
-rw-r--r--dos/ch375dos.h103
1 files changed, 103 insertions, 0 deletions
diff --git a/dos/ch375dos.h b/dos/ch375dos.h
new file mode 100644
index 0000000..d0ee84c
--- /dev/null
+++ b/dos/ch375dos.h
@@ -0,0 +1,103 @@
+/*
+ * CHU - IO routines to CH375 from DOS
+ * 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 CH375DOS_H
+#define CH375DOS_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <conio.h>
+#include <ch375.h>
+
+/* This file defines the routines that are used by ch375.h to actually IO
+ * to the underlying device. */
+
+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). */
+#if _M_IX86 >= 200
+// 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, [bx]" \
+ "in al, dx" \
+ "movzx cx, al" \
+ "rep ins byte ptr es:[di], dx" \
+ __parm [bx] [es di] \
+ __value [al] \
+ __modify exact [cx dx di]
+#else
+static uint8_t ch375_read_data_block(struct ch375 *dev, uint8_t far *buffer)
+{
+ uint8_t i, n = ch375_read_data(dev);
+
+ for (i = 0; i < n; i++) {
+ buffer[i] = ch375_read_data(dev);
+ }
+
+ return n;
+}
+#endif
+
+#if _M_IX86 >= 200
+static void ch375_write_data_block(struct ch375 *dev, uint8_t far * buffer, uint8_t n);
+#pragma aux ch375_write_data_block = \
+ "mov dx, [bx]" \
+ "out dx, al" \
+ "movzx cx, al" \
+ "rep outs dx, byte ptr es:[si]" \
+ __parm [bx] [es si] [al] \
+ __modify exact [cx dx si]
+#else
+static void ch375_write_data_block(struct ch375 *dev, uint8_t far * buffer, uint8_t n)
+{
+ uint8_t i;
+
+ ch375_write_data(dev, n);
+
+ for (i = 0; i < n; i++) {
+ ch375_write_data(dev, buffer[i]);
+ }
+}
+#endif
+
+#endif // CH375DOS_H