-
Notifications
You must be signed in to change notification settings - Fork 0
/
EWoz_bdg.a65
367 lines (347 loc) · 10.3 KB
/
EWoz_bdg.a65
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
; EWoz Monitor v1.0B
;
; Modified to work on the 6502 Badge, kits available from Lee Hart
;
; This version by Jim McClanahan, W4JBM, January 2021
;
; Build with:
; $ 64tass --intel-hex ewozb.a65 -o ewozb.hex -m --verbose-list -L ewozb.lst
; $ ./hex2bmon ewozb.hex ewozb.mon
;
; Based on EWoz 1.0 by fsafstrom, March 2007. Relevant notes from original:
;
; The EWoz 1.0 is just the good old Woz mon with a few improvements and extensions so to say.
;
; It prints a small welcome message when started.
; All key strokes are converted to uppercase.
; The backspace works so the _ is no longer needed.
; When you run a program, it's called with an JSR so if the program ends
; with an RTS, you will be taken back to the monitor.
; You can load Intel HEX format files and it keeps track of the checksum.
; To load an Intel Hex file, just type L and hit return.
; Now just send a Text file that is in the Intel HEX Format just as you
; would send a text file for the Woz mon. You can abort the transfer by
; hitting ESC.
;
; I have also incorporated some changes from the Glitch Works and TangentDelta
; version created for the R65x1Q SBC.
;
; Notes for this version (1.0B as in 'Badge'):
;
; Currently designed to load into RAM.
; Makes use of I/O routines in the Badge's ROM.
; May clobber Page Zero locations used by other applications, so you should
; probably cold start anything else like ehBASIC or the original monitor.
; Interupts are left enabled because they are necessary for serial input on
; the Badge
;
;
; Define routines in the Badge's ROM that we'll be using...
xReset = $FFC3 ; Cold start of the system
xPr2By = $EB76 ; Prints AAXX hex digits
xPr1By = $EB7A ; Prints AA hex digits
xPrDig = $EB83 ; Prints A hex nibble (low 4 bits)
xPrCR = $EB69 ; Prints a CR (ASCII 13)and LF (ASCII 10)
xPrXSP = $EB92 ; Prints # of spaces in X Reg
xPr2SP = $EB97 ; Prints 2 spaces
xPr1SP = $EB9A ; Prints 1 space
; Input buffer is located at $0300.
xBuffr = $0300 ; Input buffer area
; Note: Doing an LDA #xx and jumping to xInput+2 allows you to change
; the input prompt. The logic allows the monitor to have different
; prompts while in assembler mode.
xInpAs = $EB9F ; Alternate input prompt for Assembler
xInput = $EBA2 ; Print <CR> and prompt then get a line of input, store at buffer
xInChr = $EB39 ; Get one byte from input port, waits for input
xScnIn = $EB50 ; Checks for an input character (no waiting)
xOutpt = $EAEC ; Send one byte to the output port
xBell = $EC06 ; Send Ctrl-G ($07 / Bell) to output port
; Keys and Characters
BS = $08 ; Backspace
LF = $0A ; Line Feed
CR = $0D ; Carriage Return
ESC = $1B ; Escape
SPC = $20 ; Space
DOT = $2E ; Period
CLN = $3A ; Colon
IN = xBuffr ;Input Buffer
; Pointers conflict with ehBASIC!
XAML = $70 ;*Index pointers
XAMH = $71
STL = $72
STH = $73
L = $74
H = $75
YSAV = $76
MODE = $77
MSGL = $78
MSGH = $79
COUNTR = $7A
CRC = $7B
CRCCHK = $7C
; We can load this towards the top of the 32K of RAM...
;
* = $7C00
; Note: For the 6502 Badge, the serial input is directly on the
; NMI line. Because of that, this monitor does not include
; the CLI to clear interupts that you might expect. We let
; the rest of the system handle interupts and don't do some
; of the housekeeping you would normally expect of a monitor.
RESET: CLD ; Clear decimal mode (just in case)
LDX #$FF ; Set up stack
TXS
JSR xPrCR ; Print CR/LF
LDA #<WLCMSG ; Load pointer to welcom message
STA MSGL ; into Page Zero
LDA #>WLCMSG
STA MSGH
JSR SHWMSG ; Display welcome message
; SFTRST loads the Escape key. We drop through and this prints
; the initial prompt.
SFTRST: LDA #ESC ; Load Escape key
NOTCR: CMP #BS ; Was it a backspace?
BEQ BCKSPC
CMP #ESC ; Was it an Escape?
BEQ ESCAPE
INY ; Increment Buffer Index (Y)
BPL NXTCHR ; 'Auto-Escape' if buffer >127
ESCAPE: LDA #'\' ; Load the prompt character ("\")
JSR ECHO ; ...and display it
GETLIN: JSR xPrCR ; Print CR/LF
LDY #$01 ; Initialize Buffer Index (Y)
BCKSPC: DEY ; If backspacing, decrement Buffer Index (Y)
BMI GETLIN ; If we backspace to far, start again
LDA #SPC ; Overwrite the backspaced char with Space
JSR ECHO
LDA #BS ; And backspace again
JSR ECHO
NXTCHR: JSR xInChr ; Get next incoming char
CMP #$60 ; Is it lower case?
BMI CNVRT ; If not, skip ahead
AND #$5F ; Otherwise, convert to UPPER CASE
; CNVRT origially did an ORA #$80 which set the high bit. This is
; needed on the Apple to reset the high bit after conversion to
; upper case. We are just using ASCII so we can skip this.
CNVRT: STA IN,Y ; Add the character to the text buffer
JSR ECHO ; Display it to the screen
CMP #CR ; Was it a carriage return?
BNE NOTCR ; If not, loop back for next character
LDY #$FF ; Reset text index.
LDA #$00 ; For XAM mode.
TAX ; 0->X.
SETSTR: ASL ; Leaves $7B if setting STOR mode.
SETMOD: STA MODE ; $00 = XAM, $7B = STOR, $AE = BLOK XAM.
BLSKIP: INY ; Advance text index.
NXTITM: LDA IN,Y ; Get character.
CMP #CR ; CR?
BEQ GETLIN ; Yes, done this line.
CMP #DOT ; "."?
BCC BLSKIP ; Skip delimiter.
BEQ SETMOD ; vSet BLOCK XAM mode.
CMP #':' ; ":"?
BEQ SETSTR ; Yes, set STOR mode.
CMP #'R' ; "R"?
BEQ RUN ; Yes, run user program.
CMP #'L' ; * "L"?
BEQ LDINT ; * Yes, Load Intel Code.
STX L ; $00->L.
STX H ; and H.
STY YSAV ; Save Y for comparison.
NXTHEX: 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.
HEXSFT: ASL ; Hex digit left MSB to carry.
ROL L ; Rotate into LSD.
ROL H ; Rotate into MSD's.
DEX ; Done 4 shifts?
BNE HEXSFT ; No, loop.
INY ; Advance text index.
BNE NXTHEX ; Always taken. Check next character for hex.
NOTHEX: CPY YSAV ; Check if L, H empty (no hex digits).
BNE NOESC ; * Branch out of range, had to improvise...
JMP SFTRST ; Yes, do a soft reset
RUN: JSR ACTRUN ; * JSR to the Address we want to run.
JMP SFTRST ; * When returned for the program, reset EWOZ.
ACTRUN: JMP (XAML) ; Run at current XAM index.
LDINT: JSR LDINTL ; * Load the Intel code.
JMP SFTRST ; * When returned from the program, reset EWOZ.
NOESC: BIT MODE ; Test MODE byte.
BVC NOTSTR ; B6=0 for STOR, 1 for XAM and BLOCK XAM
LDA L ; LSD's of hex data.
STA (STL,X) ; Store at current "store index".
INC STL ; Increment store index.
BNE NXTITM ; Get next item. (no carry).
INC STH ; Add carry to 'store index' high order.
TONXIT: JMP NXTITM ; Get next command item.
NOTSTR: LDA MODE
CMP #DOT
BEQ XAMNXT
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.
NXTPRN: BNE PRDATA ; NE means no address to print.
JSR xPrCR ; Output CR/LF
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 #':' ; ":".
JSR ECHO ; Output it.
PRDATA: LDA #SPC ; Blank.
JSR ECHO ; Output it.
LDA (XAML,X) ; Get data byte at 'examine index".
JSR PRBYTE ; Output it in hex format.
XAMNXT: STX MODE ; 0-> MODE (XAM mode).
LDA XAML
CMP L ; Compare 'examine index" to hex data.
LDA XAMH
SBC H
BCS TONXIT ; Not less, so no more data to output.
INC XAML
BNE MD8CHK ; Increment 'examine index".
INC XAMH
MD8CHK: LDA XAML ; Check low-order 'exainine index' byte
AND #$0F ; For MOD 8=0 ** changed to $0F to get 16 values per row **
BPL NXTPRN ; 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 #'0' ; Add "0".
CMP #$3A ; Digit?
BCC ECHO ; Yes, output it.
ADC #$06 ; Add offset for letter.
ECHO: PHA ; *Save A
AND #$7F ; *Change to "standard ASCII"
JSR xOutpt ; *Send it.
PLA ; *Restore A
RTS ; *Done, over and out...
SHWMSG: LDY #$0
LPRT: LDA (MSGL),Y
BEQ LDONE
JSR ECHO
INY
BNE LPRT
LDONE: RTS
; Load an program in Intel Hex Format.
LDINTL: JSR xPrCR ; New line.
LDA #<MSG2
STA MSGL
LDA #>MSG2
STA MSGH
JSR SHWMSG ; Show Start Transfer.
LDY #$00
STY CRCCHK ; If CRCCHECK=0, all is good.
INTLIN: JSR xInChr ; Get char
STA IN,Y ; Store it
INY ; Next
CMP #ESC ; Escape ?
BEQ INTDON ; Yes, abort.
CMP #CR ; Did we find a new line ?
BNE INTLIN ; Nope, continue to scan line.
LDY #$FF ; Find (:)
FNDCOL: INY
LDA IN,Y
CMP #':' ; Is it Colon ?
BNE FNDCOL ; Nope, try next.
INY ; Skip colon
LDX #$00 ; Zero in X
STX CRC ; Zero Check sum
JSR GETHEX ; Get Number of bytes.
STA COUNTR ; Number of bytes in Counter.
CLC ; Clear carry
ADC CRC ; Add CRC
STA CRC ; Store it
JSR GETHEX ; Get Hi byte
STA STH ; Store it
CLC ; Clear carry
ADC CRC ; Add CRC
STA CRC ; Store it
JSR GETHEX ; Get Lo byte
STA STL ; Store it
CLC ; Clear carry
ADC CRC ; Add CRC
STA CRC ; Store it
LDA #'.' ; Load "."
JSR ECHO ; Print it to indicate activity.
NODOT: JSR GETHEX ; Get Control byte.
CMP #$01 ; Is it a Termination record ?
BEQ INTDON ; Yes, we are done.
CLC ; Clear carry
ADC CRC ; Add CRC
STA CRC ; Store it
INTSTR: JSR GETHEX ; Get Data Byte
STA (STL,X) ; Store it
CLC ; Clear carry
ADC CRC ; Add CRC
STA CRC ; Store it
INC STL ; Next Address
BNE TSTCNT ; Test to see if Hi byte needs INC
INC STH ; If so, INC it.
TSTCNT: DEC COUNTR ; Count down.
BNE INTSTR ; Next byte
JSR GETHEX ; Get Checksum
LDY #$00 ; Zero Y
CLC ; Clear carry
ADC CRC ; Add CRC
BEQ INTLIN ; Checksum OK.
LDA #$01 ; Flag CRC error.
STA CRCCHK ; Store it
JMP INTLIN ; Process next line.
INTDON: LDA CRCCHK ; Test if everything is OK.
BEQ OKMSG ; Show OK message.
JSR xPrCR ; New Line
LDA #<MSG4 ; Load Error Message
STA MSGL
LDA #>MSG4
STA MSGH
JSR SHWMSG ; Show Error.
RTS
OKMSG: JSR xPrCR ; New Line
LDA #<MSG3 ;Load OK Message.
STA MSGL
LDA #>MSG3
STA MSGH
JSR SHWMSG ; Show Done.
RTS
GETHEX: LDA IN,Y ; Get first char.
EOR #$30
CMP #$0A
BCC DONE1
ADC #$08
DONE1: ASL
ASL
ASL
ASL
STA L
INY
LDA IN,Y ; Get next char.
EOR #$30
CMP #$0A
BCC DONE2
ADC #$08
DONE2: AND #$0F
ORA L
INY
RTS
; Messages (null terminated)
WLCMSG: .NULL "Welcome to EWoz 1.0B.",CR,LF
MSG2: .NULL "Start Intel Hex Transfer.",CR,LF
MSG3: .NULL "Intel Hex Imported OK.",CR,LF
MSG4: .NULL "Intel Hex Encountered Checksum Error.",CR,LF