-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzmon.s
More file actions
215 lines (177 loc) · 8.19 KB
/
Copy pathzmon.s
File metadata and controls
215 lines (177 loc) · 8.19 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
; Steve Wozniak's wozmon ported to the Z80, using the Z80-family of peripherals.
; Monitor runs in EEPROM (16k) from address 0x0000.
; Input buffer is placed at 0x4000 - 0x407F, with one extra RAM variable needed.
; The stack is initialised to the top of RAM (48k), 0xFFFF.
;
; Assembled using Vasm oldstyle [http://www.compilers.de/vasm.html].
;
; © 2025 Joey Smalen
; I/O mapping
SIOB = 0xC1
SIOCB = 0xC3
CTC1 = 0xE1
; b = mode
; c = temporary
; de = incoming data/addr (range)
; hl = store iterator addr
; ix = text addr for analysis
; iy = xam iterator addr
; 0x4000 - 0x407F = buffer
; 0x4080 - 0x4081 = text addr copy
.org 0x0000
; processor entrypoint
ld sp, 0xFFFF ; sp = 0xFFFF
di ; no interrupts
call init_io ; init baudrate and sio
; runtime entrypoint to Wozmon
wozmon:
ld a, 0x1B ; begin with escape
not_return: cp 0x08 ; is backspace?
jr z, backspace
cp 0x1B ; is escape?
jr z, escape
inc l ; advance text index
jp p, next_char ; next char only if no overflow
escape: ld a, "\\"
call echo ; print "\"
newline: ld a, 0x0D
call echo ; print newline
ld h, 0x40 ; h = 0x40, l = offset
ld l, 1 ; init text index to 1
backspace: dec l ; backspace
jp m, newline ; newline if minus/underflow
next_char: in a, (SIOCB) ; status word
bit 0, a ; is char available?
jr z, next_char ; no, loop
in a, (SIOB) ; load available char
ld (hl), a ; append to buffer
call echo
cp 0x0D ; is return?
jr nz, not_return
ld ix, 0x3FFF ; init text index to 0x4000
ld a, 0 ; XAM mode
set_block: sla a
set_store: sla a
ld b, a ; 0 xam, 74 store, b8 blok xam
skip_item: inc ix ; advance text index
next_item: ld a, (ix) ; load character
cp 0x0D ; is return?
jr z, newline
cp "." ; is dot?
jp m, skip_item
jr z, set_block
cp ":" ; is colon?
jr z, set_store
cp "R" ; is "R"?
jr z, run
ld de, 0 ; data = 0
ld (0x4080), ix ; store ix for later
next_hex: ld a, (ix) ; load character
xor 0x30 ; map to 0-9
cp 0x0A ; is digit?
jp m, digit
add 0x89 ; map A-F to FA-FF
cp 0xFA ; is hex letter?
jp m, exec
digit: sla a ; move lower to upper
sla a
sla a
sla a
ld c, 4 ; shift count
hex_shift: sla a ; carry = MSB
rl e ; shift in e
rl d ; shift in d
dec c
jp nz, hex_shift ; shift if not done yet
inc ix ; advance text index
jr next_hex
exec: ld c, ixl
ld a, (0x4080)
cp c
jr z, escape ; escape if no hex characters
bit 6, b ; is (block) xam?
jr z, xam
ld (hl), e ; store low digit at store addr
inc hl ; increment store addr
jr next_item
run:
jp (iy) ; run xam
xam:
bit 7, b ; is block xam?
jp nz, xam_next ; yes, skip addr print
push de ; copy addr to store addr
pop hl ; (just a tiny hack)
push de ; copy addr to xam addr
pop iy ; (just a tiny hack)
praddr: ld a, 0x0D
call echo ; print newline
ld a, iyh
call echo_hex_byte ; print xam upper
ld a, iyl
call echo_hex_byte ; print xam lower
ld a, ":"
call echo ; print colon
prdata: ld a, " "
call echo ; print space
ld a, (iy) ; load xam index
call echo_hex_byte
xam_next: ld b, 0 ; mode = 0 (xam)
ld a, iyl
cp e
ld a, iyh
sbc d ; compare xam with range end
jp nc, next_item ; done? next item
inc iy ; next xam index
ld a, iyl
and 0x07 ; is xam mod of 8?
jr z, praddr ; yes, also print address
jr prdata ; no, only print data
echo_hex_byte:
push af ; save lower
srl a ; move upper to lower
srl a
srl a
srl a
call echo_hex ; print upper
pop af ; restore lower, print lower
echo_hex:
and 0x0F ; mask lower nibble
or "0" ; offset by "0"
cp 0x3A ; is digit?
jp m, echo
add 0x07 ; offset by "0" to "A"
echo:
out (SIOB), a ; print character
push af
sio_busy: in a, (SIOCB) ; status word
bit 2, a ; is buffer empty?
jr z, sio_busy ; no, loop
pop af
ret
.org 0x0100
init_io:
; init CTC for baudrate
ld a, 0b01010101
out (CTC1), a ; counter mode, rising edge
ld a, 12
out (CTC1), a ; 1843200 / 12 = 153600
; init SIO for UART communication
ld a, 0b00011000
out (SIOCB), a ; reset
ld a, 4
out (SIOCB), a ; reg 4
ld a, 0b01000100
out (SIOCB), a ; 16x, 1 stop bit, no parity
ld a, 3
out (SIOCB), a ; reg 3
ld a, 0b11000001
out (SIOCB), a ; 8 bits, rx enable
ld a, 5
out (SIOCB), a ; reg 5
ld a, 0b01101000
out (SIOCB), a ; 8 bits, tx enable
ld a, 1
out (SIOCB), a ; reg 1
ld a, 0b00000000
out (SIOCB), a ; all int disable
ret