-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathio.cpp
More file actions
177 lines (160 loc) · 2.95 KB
/
Copy pathio.cpp
File metadata and controls
177 lines (160 loc) · 2.95 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <Arduino.h>
#include <r65emu.h>
#include <i8080.h>
#include <hardware.h>
#include <sound_dac.h>
#include "io.h"
#include "config.h"
#if defined(DAC_SOUND)
#include "sounds.h"
DAC sound;
const uint8_t *playing;
#endif
void IO::begin() {
#if defined(DAC_SOUND)
sound.begin(DAC_SOUND, 11127);
#endif
}
uint8_t IO::in(uint16_t port) {
uint16_t w;
switch (port) {
case 0:
return 0x0f;
case 1:
return _p1;
case 2:
return _p2;
case 3:
w = (_s1 << 8) + _s0;
return (w >> (8 - _soff)) & 0xff;
}
return 0x00;
}
#if DEBUGGING != DEBUG_NONE
static const char debug[] PROGMEM = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', '<', '>', ' ', '=',
'*', '^', '_', '_', '_', '_', '_', '_',
'Y', '%', '_', '_', '_', '_', 'Y', '&',
'?', '_', '_', '_', '_', '_', '_', '-',
};
#endif
void IO::out(uint16_t port, uint8_t b) {
switch (port) {
case 1:
_p1 = b;
break;
case 2:
_soff = b & 0x07;
break;
case 4:
_s0 = _s1;
_s1 = b;
break;
#if defined(DAC_SOUND)
case 3:
if (b & 1)
playing = sound.play(ufo, sizeof(ufo));
if (playing != shot && (b & 2))
playing = sound.play(shot, sizeof(shot));
if (playing != basehit && (b & 4))
playing = sound.play(basehit, sizeof(basehit));
if (playing != invhit && (b & 8))
playing = sound.play(invhit, sizeof(invhit));
if (playing != extend && (b & 16))
playing = sound.play(extend, sizeof(extend));
break;
case 5:
if (playing != walk1 && (b & 1))
playing = sound.play(walk1, sizeof(walk1));
if (playing != walk2 && (b & 2))
playing = sound.play(walk2, sizeof(walk2));
if (playing != walk3 && (b & 4))
playing = sound.play(walk3, sizeof(walk3));
if (playing != walk4 && (b & 8))
playing = sound.play(walk4, sizeof(walk4));
if (playing != ufohit && (b & 16))
playing = sound.play(ufohit, sizeof(ufohit));
break;
#endif
#if DEBUGGING != DEBUG_NONE
case 6:
Serial.print(pgm_read_byte(debug+b));
break;
#endif
}
}
void IO::down(uint8_t key) {
switch (key) {
case P1_START:
_p1 |= 0x04;
break;
case P1_LEFT:
_p1 |= 0x20;
break;
case P1_RIGHT:
_p1 |= 0x40;
break;
case P1_SHOOT:
_p1 |= 0x10;
break;
case P2_START:
_p1 |= 0x02;
break;
case P2_LEFT:
_p2 |= 0x20;
break;
case P2_RIGHT:
_p2 |= 0x40;
break;
case P2_SHOOT:
_p2 |= 0x10;
break;
case COIN:
_p1 |= 0x01;
break;
default:
_p1 = _p2 = 0;
break;
}
}
void IO::up(uint8_t key) {
switch (key) {
case P1_START:
_p1 &= ~0x04;
break;
case P1_LEFT:
_p1 &= ~0x20;
break;
case P1_RIGHT:
_p1 &= ~0x40;
break;
case P1_SHOOT:
_p1 &= ~0x10;
break;
case P2_START:
_p1 &= ~0x02;
break;
case P2_LEFT:
_p2 &= ~0x20;
break;
case P2_RIGHT:
_p2 &= ~0x40;
break;
case P2_SHOOT:
_p2 &= ~0x10;
break;
case COIN:
_p1 &= ~0x01;
break;
case PAUSE:
_paused = !_paused;
break;
default:
_p1 = _p2 = 0;
break;
}
}