-
Notifications
You must be signed in to change notification settings - Fork 1
/
term.sub
398 lines (340 loc) · 16.6 KB
/
term.sub
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
;*******************************************************************************
; Terminal service on UART
;*******************************************************************************
;*******************************************************************************
; MACROS
;*******************************************************************************
putspace macro Count
mdef 1,1
lda #' '
jsr:~1~ sciputc
endm
;-------------------------------------------------------------------------------
putn macro
lda #LF ; '\n'
jsr sciputc
endm
;*******************************************************************************
; STRINGS
;*******************************************************************************
startstrt fcs ' Push T button for terminal!',LF
termstr fcs 'Serial terminal. Push ? for help!',LF
warn1str fcs LF,'Warning! Last byte was half byte.',LF
err1str fcs LF,'Error! Data outside page.',LF
err2str fcs LF,'Error! Address too high.',LF
helpstr fcc LF,'x : Exit terminal.'
fcc LF,'r : Reset MCU.'
fcc LF,'dAAAA : Dump from address $AAAA (Default $0000).'
fcc LF,'n : Next (Dump).'
fcc LF,'b : Back (Dump).'
fcc LF,'a : Again (Dump).'
fcc LF,'hAAAA11223344 [ENTER] : Hexa write from address $AAAA,'
fcc LF,'tAAAAwww.butyi.hu [ENTER] : Text write from address $AAAA,'
fcc LF,'eAAAA : Erase page from address $AAAA (128 bytes).'
fcs LF
;*******************************************************************************
TERM_Init proc
ldhx #startstrt
jmp sciputs
;*******************************************************************************
egetkey proc
Loop@@ jsr TBMHandle ; loop when waiting for a terminal character
@ledneg ; Toggle LED
;--------------------------------------
; Check if timeout elapsed (user didn't do anything in the last 8s)
;--------------------------------------
tst comtimer
bne _1@@ ; Jump through on timeout handling
;--------------------------------------
; Timeout handling: Simulate pushed 'x' button to leave terminal
;--------------------------------------
lda #'x'
bra Enter@@
_1@@ ; No timeout
jsr scigetc ; Check character from useer
bcc Loop@@ ; No character arrived, wait further
@msec 8000 ; Character arrived, pull up 8s timer
;-------------------------------------- ; Change Linux ENTER key to Windows ENTER key
cmpa #LF ; Linux ENTER
bne Enter@@
lda #CR ; Windows ENTER
Enter@@ jsr sciputc ; Echo back the pushed key
tsta ; Set CCR to be able to use conditional branches after return
rts
;*******************************************************************************
; Serial terminal
?TermHelp proc
ldhx #helpstr
jsr sciputs
bra ?Terminal
;*******************************************************************************
Terminal proc
clr cs_trign ; Reset pending connection attempt
ldhx #termstr
jsr sciputs
@msec 8000
?Terminal bsr egetkey
cbeqa #'x',Done@@
cbeqa #'r',* ; proci reset
cbeqa #'d',?TermDump
cbeqa #'n',?TermDumpN
cbeqa #'a',?TermDumpA
cbeqa #'b',?TermDumpB
cbeqa #'?',?TermHelp
@cjeqa #'t',term_text
@cjeqa #'h',term_hexa
@cjeqa #'e',term_erase
bra ?Terminal
Done@@ @putn
rts
;*******************************************************************************
?TermDumpB proc
bsr ?TermDumpAB
bra ?TermDumpA
;*******************************************************************************
?TermDumpAB proc
ldhx dump_addr
tha
deca
tah
sthx dump_addr
rts
;*******************************************************************************
?TermDumpA proc
bsr ?TermDumpAB
bra ?TermDumpN
;*******************************************************************************
?TermDump proc
jsr getdumpaddr
; bra ?TermDumpN
;*******************************************************************************
?TermDumpN proc
ldhx dump_addr ;continue
bsr Dump8Lines
@putn
bsr Dump8Lines
@putn
sthx dump_addr
bra ?Terminal
;*******************************************************************************
Dump8Lines proc
lda #8
Loop@@ psha
bsr dumpline
pula
dbnza Loop@@
rts
;*******************************************************************************
dumph4 proc ; Dump Hexa 4-times
lda #4
; bra dumphn
;*******************************************************************************
dumphn proc ; Dump Hexa n-times
Loop@@ psha
lda ,x
jsr sciputb
aix #1
pula
dbnza Loop@@
rts
;*******************************************************************************
dumpline proc
@putn
tha
jsr sciputb
txa
jsr sciputb
lda #':'
jsr sciputc
@putspace
bsr dumph4
@putspace
bsr dumph4
@putspace 2
bsr dumph4
@putspace
bsr dumph4
@putspace
lda #'|'
jsr sciputc
@putspace
aix #-16
bsr dumpa8
@putspace
; bra dumpa8
;*******************************************************************************
dumpa8 proc
lda #8
; bra dumpan
;*******************************************************************************
dumpan proc ; Dump ASCII n-times
Loop@@ psha
lda ,x
;-------------------------------------- ; For non-displayable char, print dot
cmpa #' '
blo Dot@@
cmpa #$7F
bls Char@@
Dot@@ lda #'.'
Char@@ jsr sciputc
aix #1
pula
dbnza Loop@@
rts
;*******************************************************************************
term_common proc
clr wr_datac ; Clear length of write
ldhx #wr_datat ; Copy buffer address
sthx wr_datap ; to pointer variable
jmp getdumpaddr ; Read address from user
;*******************************************************************************
; Text write into flash
term_text proc
bsr term_common ; Call common part of terminal write
bsr gettextdata ; Read text data from user
bra ?TermCommEnd ; Jump to write
;*******************************************************************************
; Hexa data write into flash
term_hexa proc
bsr term_common ; Call common part of terminal write
bsr gethexadata ; Read hexa data from user
;--------------------------------------
; Check if complete byte are given (in
; hexa mode one character is just 4 bits)
;--------------------------------------
lda wr_datac
and #1
beq ?TermCommEnd ; If even, no problem
;-------------------------------------- ; If odd, print a warning
ldhx #warn1str
jsr sciputs
;-------------------------------------- ; Check if is there any data to be written
?TermCommEnd tst wr_datac
jeq ?Terminal ; If no, jump back to main menu
;--------------------------------------
; Check if data to be written is still
; inside the page. if $80 < ((cim & $7f) + len) then too long
;--------------------------------------
lda dump_addr+1 ; Low byte of address
and #$7F
deca
add wr_datac
bpl TermInPage@@ ; If positive, so sign bit is zero, then still inside the page
;-------------------------------------- ; Error message about too long data
ldhx #err1str
jsr sciputs
jmp ?Terminal
;--------------------------------------
; Check that all addresses to be written
; are lower that bootloader area
;--------------------------------------
TermInPage@@ ldhx dump_addr
lda wr_datac
jsr aax
cphx #Start
blo TermAddrGood@@
;--------------------------------------
; Write attempt to not allowed area, error message is reported
;--------------------------------------
ldhx #err2str
jsr sciputs
jmp ?Terminal ; Back to main menu
TermAddrGood@@ jsr write ; Write data into flash
clr dump_addr+1 ; Dump from begin of 256 byte long page
jmp ?TermDumpN ; Print dump to verify write was successful
;*******************************************************************************
; Erase page from terminal
term_erase proc
;-------------------------------------- ; Read address
bsr getdumpaddr
jsr erasepage ; Erase flash page
jmp ?TermDumpN ; Print dump to verify erase was successful
;*******************************************************************************
; Read hexa bytes from user till ENTER key
gethexadata proc
;-------------------------------------- ; Check if data is not too long
lda wr_datac
cmpa #128
@req
jsr egetkey ; Read a character from user
cmpa #CR ; Windows enter
@req
bsr convtoval ; Convert character to 4 bits binary value
nsa ; Shift up by 4 bits
psha ; Save high nibble
jsr egetkey ; Read a character from user
cmpa #CR ; Windows enter
@req
bsr convtoval ; Convert character to 4 bits binary value
ldhx wr_datap ; Load buffer pointer as index
ora 1,sp ; Binary or with high nibble
sta ,x ; Write character to buffer
ais #1 ; Drop out high nibble from stack
;--------------------------------------
bsr getdata_next
bra gethexadata
;*******************************************************************************
; Read string from user till ENTER key
gettextdata proc
;-------------------------------------- ; Check if data is not too long
Loop@@ lda wr_datac
cmpa #128
@req
jsr egetkey ; Read a character from user
cmpa #CR ; Windows enter
@req
ldhx wr_datap ; Load buffer pointer as index
sta ,x ; Write character to buffer
bsr getdata_next
bra Loop@@
;*******************************************************************************
getdata_next proc
inc wr_datac ; Increase length
ldhx wr_datap ; Increase pointer
aix #1
sthx wr_datap
rts
;*******************************************************************************
; Convert character to 4 bits binary value
convtoval proc
sub #'0'
bmi _0@@
cmpa #10
blo Done@@
sub #7
bmi _0@@
cmpa #10
blo _0@@
cmpa #16
blo Done@@
sub #32
bmi _0@@
cmpa #10
blo _0@@
cmpa #16
blo Done@@
_0@@ clra
Done@@ and #$0F
rts
;*******************************************************************************
getdumpaddr proc
jsr egetkey
bsr convtoval ; Convert character to 4 bits binary value
nsa
sta dump_addr
jsr egetkey
bsr convtoval ; Convert character to 4 bits binary value
ora dump_addr
sta dump_addr
jsr egetkey
bsr convtoval ; Convert character to 4 bits binary value
nsa
sta dump_addr+1
jsr egetkey
bsr convtoval ; Convert character to 4 bits binary value
ora dump_addr+1
sta dump_addr+1
rts
;*******************************************************************************
#sp
;*******************************************************************************