-
Notifications
You must be signed in to change notification settings - Fork 4
/
uc.ino
114 lines (92 loc) · 1.67 KB
/
uc.ino
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
//
// This is a very basic program which reads input from the serial-console,
// converts it to upper-cases, and outputs it.
//
// Steve
//
#include <z80retroshield.h>
//
// Our program.
//
// The source code is located in `uc.z80`.
//
unsigned char memory[32] =
{
0x3e, 0x3e, 0xd3, 0x01, 0xdb, 0x01, 0xfe, 0xff, 0xca, 0x1b, 0x00, 0xfe,
0x61, 0xda, 0x17, 0x00, 0xfe, 0x7a, 0xd2, 0x17, 0x00, 0xd6, 0x20, 0xd3,
0x01, 0x18, 0xe9, 0x76
};
int memory_len = sizeof(memory) / sizeof(memory[0]);
//
// Our helper
//
Z80RetroShield cpu;
//
// RAM I/O function handler.
//
char memory_read(int address)
{
return (memory[address]) ;
}
//
// I/O function handler.
//
char io_read(int address)
{
if (address == 1)
{
while (! Serial.available())
{
delay(1);
}
char r = Serial.read();
return (r);
}
return 0;
}
//
// I/O function handler.
//
void io_write(int address, char byte)
{
if (address == 1)
{
Serial.write(byte);
return;
}
return;
}
//
// Setup routine: Called once.
//
void setup()
{
Serial.begin(115200);
//
// Setup callbacks.
//
// We must setup a RAM-read callback, otherwise the program
// won't be fetched from RAM and executed.
//
cpu.set_memory_read(memory_read);
//
// Now we setup a callback to be executed every time an IN/OUT
// instruction is encountered.
//
cpu.set_io_read(io_read);
cpu.set_io_write(io_write);
//
// Configured.
//
Serial.println("Z80 configured; launching program.");
}
//
// Loop function: Called forever.
//
void loop()
{
//
// Step the CPU.
//
cpu.Tick();
}