summaryrefslogtreecommitdiffstats
path: root/sw/z80/drivers/pio.c
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2017-10-05 16:09:59 +0200
committerNao Pross <naopross@thearcway.org>2017-10-05 16:09:59 +0200
commiteb169ea5a89909b90794e0388f89d6d372754e46 (patch)
treece7e826fd2dd4e4248cb4f1fbf8ce2885c943f49 /sw/z80/drivers/pio.c
parentTest units are now in their own folder 'z80_test', add programmer cli interface (diff)
downloadz80uPC-eb169ea5a89909b90794e0388f89d6d372754e46.tar.gz
z80uPC-eb169ea5a89909b90794e0388f89d6d372754e46.zip
Move test units to z80/tests, and drivers are now statically linked
Makefiles for the test units were getting messier, so now drivers (that need to be tested) are statically compiled in their own folder under z80/drivers. The kernel makefile and is now broken since everything has been moved.
Diffstat (limited to 'sw/z80/drivers/pio.c')
-rw-r--r--sw/z80/drivers/pio.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/sw/z80/drivers/pio.c b/sw/z80/drivers/pio.c
new file mode 100644
index 0000000..bdbe1c3
--- /dev/null
+++ b/sw/z80/drivers/pio.c
@@ -0,0 +1,50 @@
+#include "pio.h"
+
+static uint8_t *pio_port = (uint8_t *) ADDR_DEV_PIO;
+static uint8_t *pio_ctrl = (uint8_t *) (ADDR_DEV_PIO + 2);
+
+inline void _pio_data(int port, uint8_t data)
+{
+ *(pio_port + port) = data;
+}
+
+inline void _pio_control(int port, uint8_t cmd)
+{
+ *(pio_ctrl + port) = cmd;
+}
+
+void pio_set_mode(int port, int mode, uint8_t io)
+{
+ // 0x0F is a control sequence to set mode
+ _pio_control(port, ((mode << 6) | 0x0F));
+
+ // this mode requires an additional argument that sets
+ // a mode for each pin
+ if (mode == PIO_MODE_BIT_IO) {
+ _pio_control(port, io);
+ }
+}
+
+void pio_set_interrupts(int port, int control)
+{
+ // 0x07 is a control sequence to set interrupts
+ _pio_control(port, (control | 0x07));
+}
+
+void pio_set_interrupts_mask(int port, int control, uint8_t mask)
+{
+ // 0x17 is a control sequence to set interrupts
+ // AND interpret the next byte as a bitmask
+ _pio_control(port, (control | 0x17));
+ _pio_control(port, mask);
+}
+
+uint8_t pio_read(int port)
+{
+ return *(pio_port + port);
+}
+
+void pio_write(int port, uint8_t data)
+{
+ _pio_data(port, data);
+}