Skip to content

Commit 49dfc83

Browse files
authored
Keyboards (#6)
* ... * bugfix * ... * refactor
1 parent b0e8b03 commit 49dfc83

File tree

6 files changed

+31
-42
lines changed

6 files changed

+31
-42
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
t ?= esp32
22

33
CPPFLAGS = -DNO_STORAGE -DNO_SPIRAM
4-
LIBRARIES = SPI
4+
LIBRARIES = SPI PS2KeyRaw
55
TERMINAL_SPEED := 115200
66

77
ifeq ($t, tivac)

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ was a useful reference, as was Chris Lomont's [Pac Man emulation
1010
guide](http://www.lomont.org/Software/Games/PacMan/PacmanEmulation.pdf).
1111
(Reproduced [here](docs/PacmanEmulation.pdf).)
1212

13+
There is a commented disassembly [here](http://cubeman.org/arcade-source/pacman.asm).
14+
1315
There are still several bugs, see issue #1.
1416

1517
Keyboard

config.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#define P2_START 0x1e // 2
66
#define COIN 0x26 // 3
77

8-
#define KEY_LEFT PS2_KP_4
9-
#define KEY_RIGHT PS2_KP_6
10-
#define KEY_UP PS2_KP_8
11-
#define KEY_DOWN PS2_KP_2
8+
#define KEY_LEFT 0x6b // keypad #4
9+
#define KEY_RIGHT 0x74 // keypad #6
10+
#define KEY_UP 0x75 // keypad #8
11+
#define KEY_DOWN 0x72 // keypad #2
1212

1313
#define PAUSE 0x29 // space
1414
#define ROTATE 0x2d // r

io.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ void IO::up(uint8_t key) {
5454
case COIN:
5555
_coin = true;
5656
break;
57+
case PAUSE:
58+
_paused = !_paused;
59+
break;
5760
case ROTATE:
5861
_screen_flipped = !_screen_flipped;
5962
break;

io.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#define ALTERNATE_NAMES 0b00000000
4242
#define NORMAL_NAMES 0b10000000
4343

44-
class IO: public Memory::Device {
44+
class IO: public Memory::Device, public matrix_keyboard {
4545
public:
4646
IO(Screen &screen): Memory::Device(256), _screen(screen) {
4747
_up = _down = _left = _right = true;
@@ -57,12 +57,13 @@ class IO: public Memory::Device {
5757
bool int_enabled() { return _int_enabled; }
5858
bool sound_enabled() { return _sound_enabled; }
5959
bool screen_flipped() { return _screen_flipped; }
60+
bool paused() { return _paused; }
6061

6162
private:
6263
uint8_t _sx;
6364

6465
bool _up, _down, _left, _right, _coin, _p1_start, _p2_start;
65-
bool _int_enabled, _sound_enabled, _screen_flipped;
66+
bool _int_enabled, _sound_enabled, _screen_flipped, _paused;
6667

6768
Screen &_screen;
6869
};

pacman.ino

+18-35
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,27 @@ prom f6(rom6f, sizeof(rom6f));
3838
prom h6(rom6h, sizeof(rom6h));
3939
prom j6(rom6j, sizeof(rom6j));
4040

41-
static bool paused;
4241
Screen screen(memory);
4342
IO io(screen);
43+
ps2_raw_kbd kbd(io);
4444

4545
void reset(void) {
4646
hardware_reset();
47+
kbd.reset();
4748
screen.begin();
4849
}
4950

51+
void function_keys(uint8_t key) {
52+
switch (key) {
53+
case 1:
54+
reset();
55+
break;
56+
case 10:
57+
hardware_debug_cpu();
58+
break;
59+
}
60+
}
61+
5062
void setup(void) {
5163
hardware_init(cpu);
5264

@@ -60,48 +72,19 @@ void setup(void) {
6072
memory.put(pages[1], 0x4c00);
6173
memory.put(io, 0x5000);
6274

63-
#if defined(DEBUGGING)
64-
Serial.begin(115200);
65-
#endif
66-
6775
reset();
6876
}
6977

7078
void loop(void) {
71-
static bool debug;
72-
73-
if (ps2.available()) {
74-
unsigned scan = ps2.read2();
75-
uint8_t key = scan & 0xff;
76-
if (is_down(scan))
77-
io.down(key);
78-
else
79-
switch (key) {
80-
case PS2_F1:
81-
reset();
82-
break;
83-
case PAUSE:
84-
paused = !paused;
85-
break;
86-
case PS2_F8:
87-
debug = !debug;
88-
break;
89-
default:
90-
io.up(key);
91-
break;
92-
}
93-
} else if (!paused) {
94-
cpu.run(1000);
79+
80+
kbd.poll();
81+
82+
if (!io.paused()) {
83+
hardware_run();
9584
if (cpu.ts() > 51200) {
9685
cpu.reset_ts();
9786
if (io.int_enabled())
9887
cpu.raise(irq);
9988
}
100-
#if defined(DEBUGGING)
101-
if (debug) {
102-
char buf[160];
103-
Serial.println(cpu.status(buf, sizeof(buf)));
104-
}
105-
#endif
10689
}
10790
}

0 commit comments

Comments
 (0)