-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio.cpp
99 lines (90 loc) · 1.56 KB
/
io.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <Arduino.h>
#include <stdint.h>
#include <stddef.h>
#include <memory.h>
#include <CPU.h>
#include <ports.h>
#include <display.h>
#include <serial_kbd.h>
#include <serial_dsp.h>
#include <hardware.h>
#include "banked_memory.h"
#include "screen.h"
#include "io.h"
void IO::reset() {
_kbd.reset();
_dsp.reset();
dsk_reset();
}
uint8_t IO::kbd_poll() {
uint8_t c;
do {
#if !defined(Energia_h)
yield();
#endif
c = _kbd.read();
} while (c == 0xff);
return c;
}
uint8_t IO::in(uint16_t port) {
port &= 0xff;
switch (port) {
case CON_ST:
return _kbd.available()? 0xff: 0x00;
case CON_IN:
return kbd_poll();
case FDC_STATUS:
return dsk_status;
case FDC_IODONE:
return 1;
case FDC_GETSEC_L:
return setsec;
case FDC_GETTRK:
return settrk;
default:
DBG(printf("IO: unhandled IN(%u)\r\n", port));
break;
}
return 0x00;
}
void IO::out(uint16_t port, uint8_t a) {
port &= 0xff;
switch(port) {
case FDC_SELDSK:
dsk_status = dsk_select(a);
break;
case FDC_SETTRK:
dsk_status = dsk_settrk(a);
break;
case FDC_SETSEC_L:
dsk_status = dsk_setsec(a);
break;
case FDC_SETDMA_L:
setdma = (setdma & 0xff00) | a;
break;
case FDC_SETDMA_H:
setdma = (a << 8) | (setdma & 0xff);
break;
case FDC_IO:
dsk_status = (a? dsk_write(): dsk_read());
break;
case CON_OUT:
_dsp.write(a);
break;
case FDC_SETSEC_H:
// ignore?
break;
case MEM_INIT:
_mem.begin(a);
break;
case MEM_SELECT:
_mem.select(a);
break;
case MEM_PAGES:
_mem.size(a);
break;
default:
DBG(printf("IO: unhandled OUT(%u, %u)\r\n", port, a));
break;
}
}