OpenCores
URL https://opencores.org/ocsvn/lattice6502/lattice6502/trunk

Subversion Repositories lattice6502

[/] [lattice6502/] [ghdl/] [kernel4.asm] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 stanley82
;       Kernel
2
;       Reads uart input
3
;       Processes the command
4
;               raddress = reads one byte outs to uart
5
;               Raddress = reads 16 bytes outs to uart
6
;               waddress data = write one databyte to address location
7
;               Faddress data nn = Fill databyte into nn locations
8
;               S1bcadd d d d d d chksum= see Motorolla hex format used to load short program
9
;               Gaddress start from this address
10
;       Sends the stuff in the output buffer to uart tx.
11
;
12
;
13
        cpu 6502
14
PAGE 40,120
15
 
16
led     equ     $4007
17
dat232  equ     $4000
18
stat232 equ     $4001
19
tx232   equ     $4000
20 7 stanley82
irq     equ     $4002
21
nmi     equ     $4003
22
break   equ     $10
23
intrpt  equ     $04
24 2 stanley82
 
25
;dat232 equ     $290            ;used to help debug
26
;stat232        equ     $291
27
;tx232  equ     $292
28
 
29
tx_rdy  equ     $80     ;bit 7
30
rx_rdy  equ     $40     ;bit 6
31
;
32
inbuflen        equ     $40     ;input buffer table length
33
otbuflen        equ     $40     ;output buffer table length
34
cr      equ     $0d     ;cariage return
35
 
36
 
37
;       ZERO PAGE STUFF
38
*       =       $0
39
ptr     dw      $0      ;reserve 2 bytes
40
hexword dw      $0      ;accumulates hex word
41
 
42
 
43
;       STUFF IN UPPER MEMORY
44
*       =       $200
45
 
46
inbuff  db      0        ;reserve 64 bytes for command input
47
*       =       inbuff + inbuflen
48
outbuff db      0
49
*       =       outbuff + otbuflen
50
 
51
txoutpt db      0        ;output pointer index
52
txinpt  db      0        ;input pointer index
53
txoutct db      0        ;Counter
54
inbufpt db      0        ;Ponts where to put kb text
55
txtpt   db      0        ;Points to text to be processed
56
sp1     db      $0
57
sp2     db      $0
58
sp3     db      $0
59
temp_y  db      0
60
bytcnt  db      0
61
n       db      0
62
 
63
 
64
page
65
*       =       $fc00
66
;       This is the main loop.
67
;
68
main    ldx     #$0
69
        txs             ;Set stack pointer to x100
70
        stx     txoutpt
71
        stx     txinpt
72
        stx     txoutct
73
        stx     inbufpt
74
        stx     txtpt
75
 
76
        lda     #"?"    ;Illegal char or restart
77
        jsr     sendtxt ;or bad frap
78
 
79
loop    jmp     input   ;Read serial character
80
back1   jmp     process ;It's in reg a and stored in inbuff
81
back2   jmp     sendbuf
82
back3   jmp     loop
83
;
84
;
85
page
86
;       This is where the uart receiver  character is picked up and dumped
87
;       into the input buffer (inbuff)
88
code
89
input   jmp     getchar
90
;       beq     back1           ;No new character
91
.loop   ldx     inbufpt         ;Returns with it in y
92
        sta     inbuff,x        ;input buffer
93
        tay
94
        inx
95
        txa
96
        and     #inbuflen - 1
97
        sta     inbufpt
98
        tya
99
        jmp     back1           ;return with character in a
100
 
101
getchar lda     stat232
102
        and     #rx_rdy
103
        beq     .exit
104
        lda     dat232          ;Character in a
105
        jmp     .loop
106
.exit   lda     #$0
107
        jmp     back1
108
code
109
page
110
code
111
;       This is where the complicated stuff is done
112
process beq     .exit   ;It's a null character
113
        pha
114
        jsr     sendtxt ;Echo character to terminal
115
        pla
116
        cmp     #"\r"
117
        beq     got_cr
118
        cmp     #"\n"
119
        beq     got_cr
120
.exit   jmp     back2
121
 
122
got_cr  ldx     txtpt           ;Decode the KB input
123
        lda     inbuff,x
124
        jsr     inctxt
125
        cmp     #"r"
126
        beq     read1   ;Read one byte rnnnn
127
 
128
        cmp     #"R"
129
        bne     next0
130
        jmp     readn
131
 
132
next0   cmp     #"w"    ;Write one byte wnnnn xx
133
        bne     next1
134
        jmp     write1
135
 
136
next1   cmp     #"F"    ;Fill Fnnnn nn xx
137
        bne     next2
138
        jmp     fill
139
 
140
next2   cmp     #"G"    ;goto nnnn
141
        bne     next3
142
        jmp     goto
143
 
144
next3   cmp     #"g"    ;goto 290
145
        bne     next4
146
        jsr     inctxt  ;Get to end of buffer
147
        jmp     $290
148
 
149
 
150
next4   cmp     #"S"
151
        bne     next5
152
        ldx     txtpt
153
        lda     inbuff,x
154
        jsr     inctxt
155
        cmp     #"1"
156
        bne     next5
157
        jmp     scode
158
next5   cmp     #"9"
159
        bne     next6
160
        jmp     flush   ;Last S code packet not used so flush
161
 
162
next6   jmp     main    ;restart bad input
163
 
164
 
165
 
166
 
167
code
168
page
169
code
170
;       This is where stuff is pulled from the output buffer (outbuff)
171
;       and sent to the terminal
172
sendbuf lda     stat232 ;All regs destroyed
173
        and     #tx_rdy ;Test uart tx status
174
        bne     .exit   ;In use
175
        jmp     .gettxt         ;char in A for return
176
.bak    sta     tx232   ;Byte to terminal
177
.exit   jmp     back3
178
;                       Pull txt from buffer if not empty
179
.gettxt lda     txoutct
180
        beq     .exit
181
        dec     txoutct
182
        lda     txoutpt ;out text out pointer
183
        tay
184
        tax
185
        iny
186
        tya
187
        and     #inbuflen - 1
188
        sta     txoutpt
189
        lda     outbuff,x
190
        jmp     .bak
191
 
192
code
193
page
194
 
195
page                    ;This routing reads one byt"\n"e from address
196
read1   jsr     txt2hex ;Convert string to 16 bit word
197
 
198
        lda     hexword + 1
199
        jsr     hex2txt
200
 
201
        lda     hexword
202
        jsr     hex2txt
203
 
204
        lda     #" "
205
        jsr     sendtxt
206
        ldy     #$0
207
        lda     (hexword),y
208
        jsr     hex2txt
209
        lda     #"\r"
210
        jsr     sendtxt
211
        jmp     back2
212
;       ===============================================
213
 
214
readn   jsr     txt2hex ;Convert string to 16 bit word
215
 
216
        lda     hexword + 1
217
        sta     ptr + 1
218
        jsr     hex2txt
219
 
220
        lda     hexword
221
        and     #$f0
222
        sta     ptr
223
        jsr     hex2txt
224
 
225
        lda     #$0
226
        sta     temp_y
227
read_lp lda     #" "
228
        jsr     sendtxt
229
        ldy     temp_y
230
        lda     (ptr),y
231
        jsr     hex2txt
232
        ldy     temp_y
233
        iny
234
        tya
235
        sta     temp_y
236
        cmp     #$10
237
        bne     read_lp
238
 
239
        lda     #"\r"
240
        jsr     sendtxt
241
        jmp     back2
242
;       ==================================================
243
 
244
;       This routine writes one byte to memory
245
;       address space data
246
write1  jsr     txt2hex ;Convert string to 16 bit word
247
 
248
        lda     hexword + 1     ;Save these locations
249
        sta     ptr + 1
250
        jsr     hex2txt
251
 
252
        lda     hexword
253
        sta     ptr
254
        jsr     hex2txt
255
 
256
        jsr     txt2hex         ;Convert data
257
        lda     hexword
258
 
259
        ldy     #$0
260
        sta     (ptr),y
261
        lda     #"\r"
262
        jsr     sendtxt
263
        jmp     back2
264
;       ==================================================
265
fill    jsr     txt2hex ;Convert string to 16 bit word
266
 
267
        lda     hexword + 1     ;Save these locations
268
        pha
269
        lda     hexword
270
        pha
271
 
272
        jsr     txt2hex         ;Convert data
273
        lda     hexword
274
        pha                     ;Data on stack
275
 
276
        jsr     txt2hex         ;how many bytes?
277
        lda     hexword
278
        sta     sp1             ;Number of bytes to fill in sp1
279
 
280
        pla
281
        tay                     ;Data into y
282
        pla                     ;Restore hexword
283
        sta     hexword
284
        pla
285
        sta     hexword + 1
286
        tya
287
        pha
288
 
289
        ldy     #$0
290
        sta     temp_y
291
        pla
292
fill_lp sta     (hexword),y
293
        iny
294
        sta     temp_y
295
        cpy     sp1
296
        bne     fill_lp
297
 
298
        lda     #"\r"
299
        jsr     sendtxt
300
        jmp     back2
301
 
302
goto    jsr     txt2hex
303
        jmp     (hexword)       ;goto user code best return to main x"fc00"
304
 
305
page
306
code
307
;       This routine takes the Motorolla  S code generated
308
;       by crasm and loads it into RAM.
309
;       The checksum is not checked since there is no comms.
310
 
311
scode   ldx     #$2             ;convert two bytes byte count
312
        jsr     cod2hex
313
        lda     hexword
314
        clc
315
        sbc     #3
316
        sta     bytcnt          ;total bytes to transfer
317
 
318
        ldx     #$4             ;convert four bytes to address
319
        jsr     cod2hex ;hexword points to where data goes
320
        lda     hexword
321
        sta     ptr
322
        lda     hexword + 1
323
        sta     ptr + 1         ;ptr holds point
324
 
325
        lda     #$0
326
        sta     n
327
 
328
scodelp ldx     #$2     ;4 or 2 bytes to form number
329
        jsr     cod2hex
330
        ldy     n
331
        sta     (ptr),y
332
        iny
333
        sty     n
334
        cpy     bytcnt
335
        bne     scodelp
336
        lda     #"\r"
337
        jsr     sendtxt
338
        jsr     inctxt          ;skip checksum 1
339
        jsr     inctxt          ;and cs2
340
        jsr     inctxt          ;and cr
341
        jmp     back2
342
 
343
cod2hex lda     #$0
344
        sta     hexword
345
        sta     hexword + 1
346
        stx     sp3             ;Save No of bytes to convert this time
347
 
348
.lphex  ldx     sp3
349
        beq     .exit
350
        ldx     txtpt
351
        lda     inbuff,x
352
        jsr     inctxt
353
        ldx     sp3
354
 
355
        ldy     #$0
356
.nothis cmp     asctbl,y
357
        bne     .next
358
        dex                     ;Got 1 match
359
        stx     sp3
360
        jsr     accum
361
        jmp     .lphex
362
.next   iny
363
        cpy     #$10
364
        bne     .nothis ;next hex char
365
.exit   rts     ;last char
366
 
367
flush   jsr     cod2hex ;empty buffer
368
        jmp     back2   ;result of subroutine ignored
369
 
370
 
371
code
372
 
373
 
374
page
375
;       This is where the output buffer (outbuf) is loaded.
376
code
377
sendtxt pha                     ;A hold character to be place in buffer
378
        sty     sp2
379
        lda     txoutct
380
        cmp     #otbuflen -1
381
        bpl     .exit           ;buffer should never be full
382
        inc     txoutct
383
        lda     txinpt  ;out text out pointer
384
        tay
385
        tax
386
        iny
387
        tya
388
        and     #otbuflen - 1
389
        sta     txinpt
390
        pla
391
        sta     outbuff,x
392
        ldy     sp2
393
        rts
394
.exit   pla
395
        ldy     sp2
396
        rts
397
 
398
 
399
code
400
page
401
code
402
txt2hex ldy     #$0
403
        sty     hexword
404
        sty     hexword + 1
405 7 stanley82
irq     equ     $4002
406
nmi     equ     $4003
407
break   equ     $10
408
intrpt  equ     $04
409 2 stanley82
loophex ldx     txtpt
410
        lda     inbuff,x        ;input buffer
411
        jsr     inctxt          ;inc counter
412
        ldy     #$0
413
nomatch cmp     asctbl,y
414
        bne     .next
415
        jsr     accum
416
        jmp     loophex
417
.next   iny
418
        cpy     #$10
419
        bne     nomatch ;next hex char
420
        rts     ;not hex char
421
 
422
 
423
accum   stx     sp1
424
        ldx     #$4             ;y holds hex of character
425
accloop asl     hexword
426
        rol     hexword + 1
427
        dex
428
        bne     accloop
429
        tya
430
        ora     hexword
431
        sta     hexword
432
        ldx     sp1
433
        rts
434
 
435
 
436
hex2txt tay             ;A holds byte to convert
437
        clc
438
        ror     a
439
        ror     a
440
        ror     a
441
        ror     a
442
        and     #$0f
443
        tax
444
        lda     asctbl,x
445
        jsr     sendtxt
446
        tya
447
        and     #$0f
448
        tax
449
        lda     asctbl,x
450
        jsr     sendtxt
451
        rts
452
;                       inc after reading from inbuff
453
inctxt  pha             ;NOT before
454
        inc     txtpt
455
        lda     txtpt
456
        and     #inbuflen - 1
457
        sta     txtpt
458
        pla
459
        rts
460
 
461
asctbl  asc     "0123456789ABCDEF"
462
code
463
 
464
page    ;All the start up stuff
465
 
466 7 stanley82
nmi_srv lda     #$01
467
        sta     nmi
468
        lda     #"N"
469 2 stanley82
        jsr     sendtxt
470 7 stanley82
        lda     #"M"
471
        jsr     sendtxt
472
        lda     #"I"
473
        jsr     sendtxt
474
        lda     #"\r"
475
        jsr     sendtxt
476 2 stanley82
        rti
477
 
478 7 stanley82
irq_srv pla
479
        pha
480
        and     #break
481
        beq     irqish
482
        lda     #"B"
483 2 stanley82
        jsr     sendtxt
484 7 stanley82
        lda     #"R"
485
        jsr     sendtxt
486
        lda     #"K"
487
        jsr     sendtxt
488
        lda     #"\r"
489
        jsr     sendtxt
490
        jmp     endish
491
 
492
 
493
irqish  lda     #$01
494
        sta     irq
495
        lda     #$01
496
        sta     irq
497
        lda     #"I"
498
        jsr     sendtxt
499
        lda     #"R"
500
        jsr     sendtxt
501
        lda     #"Q"
502
        jsr     sendtxt
503
        lda     #"\r"
504
        jsr     sendtxt
505
endish  rti
506
 
507 2 stanley82
*       =$fff0
508
        jmp     sendtxt ;Links for usrcode
509
        jmp     hex2txt
510 7 stanley82
        dw      back2   ;jmp ($FFF6) in user code.
511 2 stanley82
 
512
*       = $fff8
513
;
514
indjmp  dw      main
515 7 stanley82
nmi_int dw      nmi_srv
516 2 stanley82
rst     dw      main    ;Should be main, this is for test only
517 7 stanley82
irq_int dw      irq_srv

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.