forked from mist64/msbasic
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathwozmon.s
189 lines (163 loc) · 7.86 KB
/
wozmon.s
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
.setcpu "65C02"
.segment "WOZMON"
XAML = $24 ; Last "opened" location Low
XAMH = $25 ; Last "opened" location High
STL = $26 ; Store address Low
STH = $27 ; Store address High
L = $28 ; Hex value parsing Low
H = $29 ; Hex value parsing High
YSAV = $2A ; Used to see if hex value is given
MODE = $2B ; $00=XAM, $7F=STOR, $AE=BLOCK XAM
IN = $0200 ; Input buffer
RESET:
CLD ; Clear decimal arithmetic mode.
JSR INIT_BUFFER
CLI
LDA #$1F ; 8-N-1, 19200 bps
STA ACIA_CTRL
LDY #$89 ; No parity, no echo, rx interrupts.
STY ACIA_CMD
NOTCR:
CMP #$08 ; Backspace key?
BEQ BACKSPACE ; Yes.
CMP #$1B ; ESC?
BEQ ESCAPE ; Yes.
INY ; Advance text index.
BPL NEXTCHAR ; Auto ESC if line longer than 127.
ESCAPE:
LDA #$5C ; "\".
JSR ECHO ; Output it.
GETLINE:
LDA #$0D ; Send CR
JSR ECHO
LDA #$0A ; Send LF
JSR ECHO
LDY #$01 ; Initialize text index.
BACKSPACE: DEY ; Back up text index.
BMI GETLINE ; Beyond start of line, reinitialize.
NEXTCHAR:
JSR CHRIN
BCC NEXTCHAR
STA IN,Y ; Add to text buffer.
CMP #$0D ; CR?
BNE NOTCR ; No.
LDY #$FF ; Reset text index.
LDA #$00 ; For XAM mode.
TAX ; X=0.
SETBLOCK:
ASL
SETSTOR:
ASL ; Leaves $7B if setting STOR mode.
SETMODE:
STA MODE ; $00 = XAM, $74 = STOR, $B8 = BLOK XAM.
BLSKIP:
INY ; Advance text index.
NEXTITEM:
LDA IN,Y ; Get character.
CMP #$0D ; CR?
BEQ GETLINE ; Yes, done this line.
CMP #$2E ; "."?
BCC BLSKIP ; Skip delimiter.
BEQ SETBLOCK ; Set BLOCK XAM mode.
CMP #$3A ; ":"?
BEQ SETSTOR ; Yes, set STOR mode.
CMP #$52 ; "R"?
BEQ RUNPROG ; Yes, run user program.
STX L ; $00 -> L.
STX H ; and H.
STY YSAV ; Save Y for comparison
NEXTHEX:
LDA IN,Y ; Get character for hex test.
EOR #$30 ; Map digits to $0-9.
CMP #$0A ; Digit?
BCC DIG ; Yes.
ADC #$88 ; Map letter "A"-"F" to $FA-FF.
CMP #$FA ; Hex letter?
BCC NOTHEX ; No, character not hex.
DIG:
ASL
ASL ; Hex digit to MSD of A.
ASL
ASL
LDX #$04 ; Shift count.
HEXSHIFT:
ASL ; Hex digit left, MSB to carry.
ROL L ; Rotate into LSD.
ROL H ; Rotate into MSD's.
DEX ; Done 4 shifts?
BNE HEXSHIFT ; No, loop.
INY ; Advance text index.
BNE NEXTHEX ; Always taken. Check next character for hex.
NOTHEX:
CPY YSAV ; Check if L, H empty (no hex digits).
BEQ ESCAPE ; Yes, generate ESC sequence.
BIT MODE ; Test MODE byte.
BVC NOTSTOR ; B6=0 is STOR, 1 is XAM and BLOCK XAM.
LDA L ; LSD's of hex data.
STA (STL,X) ; Store current 'store index'.
INC STL ; Increment store index.
BNE NEXTITEM ; Get next item (no carry).
INC STH ; Add carry to 'store index' high order.
TONEXTITEM: JMP NEXTITEM ; Get next command item.
RUNPROG:
JMP (XAML) ; Run at current XAM index.
NOTSTOR:
BMI XAMNEXT ; B7 = 0 for XAM, 1 for BLOCK XAM.
LDX #$02 ; Byte count.
SETADR: LDA L-1,X ; Copy hex data to
STA STL-1,X ; 'store index'.
STA XAML-1,X ; And to 'XAM index'.
DEX ; Next of 2 bytes.
BNE SETADR ; Loop unless X = 0.
NXTPRNT:
BNE PRDATA ; NE means no address to print.
LDA #$0D ; CR.
JSR ECHO ; Output it.
LDA #$0A ; LF.
JSR ECHO ; Output it.
LDA XAMH ; 'Examine index' high-order byte.
JSR PRBYTE ; Output it in hex format.
LDA XAML ; Low-order 'examine index' byte.
JSR PRBYTE ; Output it in hex format.
LDA #$3A ; ":".
JSR ECHO ; Output it.
PRDATA:
LDA #$20 ; Blank.
JSR ECHO ; Output it.
LDA (XAML,X) ; Get data byte at 'examine index'.
JSR PRBYTE ; Output it in hex format.
XAMNEXT: STX MODE ; 0 -> MODE (XAM mode).
LDA XAML
CMP L ; Compare 'examine index' to hex data.
LDA XAMH
SBC H
BCS TONEXTITEM ; Not less, so no more data to output.
INC XAML
BNE MOD8CHK ; Increment 'examine index'.
INC XAMH
MOD8CHK:
LDA XAML ; Check low-order 'examine index' byte
AND #$07 ; For MOD 8 = 0
BPL NXTPRNT ; Always taken.
PRBYTE:
PHA ; Save A for LSD.
LSR
LSR
LSR ; MSD to LSD position.
LSR
JSR PRHEX ; Output hex digit.
PLA ; Restore A.
PRHEX:
AND #$0F ; Mask LSD for hex print.
ORA #$30 ; Add "0".
CMP #$3A ; Digit?
BCC ECHO ; Yes, output it.
ADC #$06 ; Add offset for letter.
ECHO:
STA ACIA_DATA ; Output character.
PHA ; Save A.
LDA #$FF ; Initialize delay loop.
TXDELAY: DEC ; Decrement A.
BNE TXDELAY ; Until A gets to 0.
PLA ; Restore A.
RTS ; Return.