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

Subversion Repositories lattice6502

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

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

powered by: WebSVN 2.1.0

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