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

Subversion Repositories System09

[/] [System09/] [trunk/] [src/] [dump/] [dump_ide.asm] - Blame information for rev 209

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 59 davidgb
*
2
* Sector Dump Utility
3
* for IDE Drives or Compact Flash
4
* for the 6809
5
* revised for 16 bit peripheral bus
6
* on XESS XSA-3S1000 / XST-3.0
7
*
8
* John Kent
9
* 1 Feb 2008
10
*
11
* SYS09BUG
12
*
13
MON_BASE  EQU $F800
14
MONV      EQU MON_BASE+0
15
NEXTCV    EQU MON_BASE+2
16
INCHV     EQU MON_BASE+4
17
INCHEV    EQU MON_BASE+6
18
INCHEKV   EQU MON_BASE+8
19
OUTCHV    EQU MON_BASE+10
20
PDATAV    EQU MON_BASE+12
21
PCRLFV    EQU MON_BASE+14
22
PSTRGV    EQU MON_BASE+16
23
*
24
* Register Equates
25
*
26
CF_BASE    EQU $E100
27
CF_DATA    EQU CF_BASE+0
28
CF_ERROR   EQU CF_BASE+2 ; read error
29
CF_FEATURE EQU CF_BASE+2 ; write feature
30
CF_SECCNT  EQU CF_BASE+4
31
CF_SECNUM  EQU CF_BASE+6
32
CF_CYLLO   EQU CF_BASE+8
33
CF_CYLHI   EQU CF_BASE+10
34
CF_HEAD    EQU CF_BASE+12
35
CF_STATUS  EQU CF_BASE+14 ; read status
36
CF_COMAND  EQU CF_BASE+14 ; write command
37
CF_AUX     EQU CF_BASE+30
38
*
39
* Command Equates
40
*
41
AUXRESET   EQU $06 ; CF_AUX Reset command
42
AUXRELEA   EQU $02
43
CMDREAD    EQU $20 ; Read Single sector
44
CMDWRITE   EQU $30 ; Write Single sector
45
HEADLBA    EQU $E0
46
*
47
* Status bit equates
48
*
49
BUSY       EQU $80
50
DRDY       EQU $40
51
DRQ        EQU $08
52
ERR        EQU $01
53
*
54
* Start of Program
55
*
56
         ORG $0100
57
START    LBRA START1
58
*
59
* DATA STORAGE
60
*
61
SECNUM   FCB $00,$00,$00
62
CPORT    FDB $E000
63
ECHO     FCB $FF
64
*
65
* SECTOR BUFFER
66
*
67
SECBUF   RMB 512
68
*
69
* PROGRAM STACK
70
*
71
         RMB 64
72
STACK    EQU *
73
*
74
* Initialization
75
*
76
START1 LDS #STACK
77
*
78
* Clear sector buffer
79
*
80
       LDX #SECBUF
81
       LDY #0
82
       LDB #0
83
ZEROLP STY ,X++
84
       DECB
85
       BNE ZEROLP
86
*
87
* INITIALIZE CF CARD FOR 8 BIT LBA MODE
88
*
89
       LDD #AUXRESET
90
       STD CF_AUX
91
       LDD #AUXRELEA
92
       STD CF_AUX
93
       JSR WAITRDY
94
       LDD #HEADLBA
95
       STD CF_HEAD
96
       JSR WAITRDY
97
*
98
* DISPLAY TITTLE BANNER
99
*
100
       LDX #TTLMSG
101
       JSR PDATA
102
*
103
* COMMAND LOOP
104
* R - READ
105
* W - WRITE
106
* N - NEXT
107
* P - PREV
108
* M - MODIFY
109
* Q - QUIT
110
*
111
CMDLP  LDX #CMDMSG
112
       JSR PDATA
113
       JSR ECHON
114
       CMPA #'R'
115
       BEQ READ
116
       CMPA #'N'
117
       BEQ NEXT
118
       CMPA #'P'
119
       BEQ PREV
120
       CMPA #'W'
121
       LBEQ WRITE
122
       CMPA #'M'
123
       BEQ MODIFY
124
       CMPA #'Q'
125
       BEQ QUIT
126
       CMPA #'r'
127
       BEQ READ
128
       CMPA #'n'
129
       BEQ NEXT
130
       CMPA #'p'
131
       BEQ PREV
132
       CMPA #'w'
133
       LBEQ WRITE
134
       CMPA #'m'
135
       BEQ MODIFY
136
       CMPA #'q'
137
       BEQ QUIT
138
       LDX #WOTMSG
139
       JSR PSTRNG
140
       BRA CMDLP
141
*
142
* QUIT
143
*
144
QUIT   JMP [MONV]
145
*
146
* MODIFY SECTOR
147
*
148
MODIFY JSR MEMCHG
149
       BRA CMDLP
150
*
151
* NEXT SECTOR (READ)
152
* INCREMENT SECTOR NUMBER
153
* WRAPS AROUND TO ZERO ON $FFFFFF
154
*
155
NEXT   LDX SECNUM+1
156
       LEAX 1,X
157
       STX SECNUM+1
158
       BNE READS
159
       INC SECNUM
160
       BRA READS
161
*
162
* PREVIOUS SECTOR (READ)
163
* DECREMENT SECTOR NUMBER
164
* DON'T DECREMENT PAST $000000
165
*
166
PREV   LDX SECNUM+1
167
       BNE PREV1
168
       TST SECNUM
169
       BEQ READS
170
       DEC SECNUM
171
PREV1  LEAX -1,X
172
       STX SECNUM+1
173
       BRA READS
174
*
175
* READ SECTORS FROM CF
176
*
177
READ   LDX #SECPMT
178
       JSR PSTRNG
179
       JSR IN6HEX
180
       BVS RDEXIT
181
       STB SECNUM
182
       STX SECNUM+1
183
*
184
READS  CLRA
185
       LDB #$01
186
       STD CF_SECCNT
187
*
188
       LDB SECNUM+2
189
       STD CF_SECNUM
190
*
191
       LDB SECNUM+1
192
       STD CF_CYLLO
193
*
194
       LDB SECNUM+0
195
       STD CF_CYLHI
196
*
197
       LDB #CMDREAD ; IDE READ MULTIPLE
198
       STD CF_COMAND
199
       JSR WAITRDY
200
*
201
       LDX #SECBUF
202
       LDY #256
203
*
204
* READ LOOP
205
*
206
RDLOOP JSR WAITDRQ
207
       LDD CF_DATA ; reverse order of bytes
208
       STB ,X+
209
       STA ,X+
210
       LEAY -1,Y
211
       BNE RDLOOP
212
*
213
       JSR WAITRDY
214
       JSR MEMDUMP
215
RDEXIT JMP CMDLP
216
*
217
* WRITE SECTOR TO CF
218
*
219
WRITE  LDX #SECPMT
220
       JSR PSTRNG
221
       JSR IN6HEX
222
       BVS WREXIT
223
       STB SECNUM
224
       STX SECNUM+1
225
*
226
       CLRA
227
       LDB #$01
228
       STD CF_SECCNT
229
*
230
       LDB SECNUM+2
231
       STD CF_SECNUM
232
*
233
       LDB SECNUM+1
234
       STD CF_CYLLO
235
*
236
       LDB SECNUM+0
237
       STD CF_CYLHI
238
*
239
       LDD #CMDWRITE; IDE WRITE MULTIPLE
240
       STD CF_COMAND
241
       JSR WAITRDY
242
*
243
       LDX #SECBUF
244
       LDY #256
245
*
246
* WRITE LOOP
247
*
248
WRLOOP JSR WAITDRQ
249
       LDB ,X+    ; reverse order of bytes
250
       LDA ,X+
251
       STD CF_DATA
252
       LEAY -1,Y
253
       BNE WRLOOP
254
*
255
       JSR WAITRDY
256
WREXIT JMP CMDLP
257
*
258
* WAIT UNTIL READY
259
*
260
WAITRDY LDD CF_STATUS
261
        BITB #BUSY
262
        BNE WAITRDY
263
        LDD CF_STATUS
264
        BITB #DRDY
265
        BEQ WAITRDY
266
        RTS
267
*
268
* WAIT FOR DATA REQUEST
269
*
270
WAITDRQ LDD CF_STATUS
271
        BITB #DRQ
272
        BEQ WAITDRQ
273
        RTS
274
*
275
* DUMP SECTOR IN MEMORY
276
*
277
MEMDUMP LDX  #SECMSG
278
        JSR  PSTRNG
279
        LDA  SECNUM
280
        JSR  OUT2H
281
        LDX  SECNUM+1
282
        JSR  OUT4H
283
        JSR  PCRLF
284
*
285
* Dump first 256 bytes
286
*
287
        LDY  #$0000
288
        LEAX #$0FF,Y
289
        JSR  AJDUMP
290
*
291
* Prompt to continue
292
*
293
        LDX #PAGMSG
294
        JSR PSTRNG
295
        JSR INCH
296
*
297
* Dump second 256 bytes
298
*
299
        LDY  #$0100
300
        LEAX #$0FF,Y
301
*
302
* ADJUST LOWER AND UPPER ADDRESS LIMITS
303
* TO EVEN 16 BYTE BOUNDRIES.
304
*
305
* IF LOWER ADDR = $4532
306
* LOWER BOUNDS WILL BE ADJUSTED TO = $4530.
307
*
308
* IF UPPER ADDR = $4567
309
* UPPER BOUNDS WILL BE ADJUSTED TO = $4570.
310
*
311
* ENTER WITH LOWER ADDRESS IN X-REG.
312
*           -UPPER ADDRESS ON TOP OF STACK.
313
*
314
AJDUMP  TFR  X,D     GET UPPER ADDR IN D-REG
315
        ADDD #$10    ADD 16 TO UPPER ADDRESS
316
        ANDB #$F0    MASK TO EVEN 16 BYTE BOUNDRY
317
        PSHS A,B     SAVE ON STACK AS UPPER DUMP LIMIT
318
        TFR  Y,D     $F9A5 GET LOWER ADDRESS IN D-REG
319
        ANDB #$F0    MASK TO EVEN 16 BYTE BOUNDRY
320
        TFR  D,X     PUT IN X-REG AS LOWER DUMP LIMIT
321
NXTLIN  CMPX ,S      COMPARE LOWER TO UPPER LIMIT
322
        BEQ  SKPDMP  IF EQUAL SKIP HEX-ASCII DUMP
323
        LBSR INCHEK  CHECK FOR INPUT FROM KEYBOARD
324
        BEQ  EDUMP
325
SKPDMP  LEAS 2,S     READJUST STACK IF NOT DUMPING
326
        RTS          ;
327
*
328
* PRINT 16 HEX BYTES FOLLOWED BY 16 ASCII CHARACTERS
329
* FOR EACH LINE THROUGHOUT ADDRESS LIMITS.
330
*
331
EDUMP   PSHS X       PUSH LOWER ADDR LIMIT ON STACK
332
        LDX  #MSG5   POINT TO MSG " - "
333
        LBSR PSTRNG  PRINT MSG
334
        LDX  ,S      LOAD LOWER ADDR FROM TOP OF STACK
335
        LBSR OUT4H   PRINT THE ADDRESS
336
        LBSR OUT2S   2 SPACES
337
        LDB  #$10    LOAD COUNT OF 16 BYTES TO DUMP
338
ELOOP   LDA  SECBUF,X     GET FROM MEMORY HEX BYTE TO PRINT
339
        LEAX 1,X
340
        LBSR OUT2H   OUTPUT HEX BYTE AS ASCII
341
        LBSR OUT1S   OUTPUT SPACE
342
        DECB         $F9D1 DECREMENT BYTE COUNT
343
        BNE  ELOOP   CONTINUE TIL 16 HEX BYTES PRINTED
344
*
345
* PRINT 16 ASCII CHARACTERS
346
* IF NOT PRINTABLE OR NOT VALID
347
* ASCII PRINT A PERIOD (.)
348
        LBSR OUT2S   2 SPACES
349
        LDX  ,S++    GET LOW LIMIT FRM STACK - ADJ STACK
350
        LDB  #$10    SET ASCII CHAR TO PRINT = 16
351
EDPASC  LDA  SECBUF,X     GET CHARACTER FROM MEMORY
352
        LEAX 1,X
353
        CMPA #$20    IF LESS THAN $20, NON-PRINTABLE?
354
        BCS  PERIOD  IF SO, PRINT PERIOD INSTEAD
355
        CMPA #$7E    IS IT VALID ASCII?
356
        BLS  PRASC   IF SO PRINT IT
357
PERIOD  LDA  #'.     LOAD A PERIOD (.)
358
PRASC   LBSR OUTCH   PRINT ASCII CHARACTER
359
        DECB         DECREMENT COUNT
360
        BNE  EDPASC
361
        BRA  NXTLIN
362
*
363
*
364
***** "M" MEMORY EXAMINE AND CHANGE *****
365
*
366
* RESTRICT ADDRESSING RANGE TO 512 BYTES ($000 - $1FF)
367
*
368
MEMCHG  LDX  #MEMMSG
369
        JSR  PSTRNG
370
        LBSR IN3HEX  INPUT ADDRESS
371
        BVS  CHRTN   IF NOT HEX, RETURN
372
        CMPX #$0200
373
        BHS  CHRTN
374
        TFR  X,Y     SAVE ADDR IN "Y"
375
MEMC2   LDX  #MSG5   POINT TO MSG " - "
376
        LBSR PSTRNG  PRINT MSG
377
        TFR  Y,X     FETCH ADDRESS
378
        LBSR OUT4H   PRINT ADDR IN HEX
379
        LBSR OUT1S   OUTPUT SPACE
380
        LDA  SECBUF,Y GET CONTENTS OF CURRENT ADDR.
381
        LBSR OUT2H   OUTPUT CONTENTS IN ASCII
382
        LBSR OUT1S   OUTPUT SPACE
383
        LBSR BYTE    LOOP WAITING FOR OPERATOR INPUT
384
        BVC  CHANGE  IF VALID HEX GO CHANGE MEM. LOC.
385
        CMPA #8      IS IT A BACKSPACE (CNTRL H)?
386
        BEQ  MEMC2   PROMPT OPERATOR AGAIN
387
        CMPA #$18    IS IT A CANCEL (CNTRL X)?
388
        BEQ  MEMC2   PROMPT OPERATOR AGAIN
389
        CMPA #'^     IS IT AN UP ARROW?
390
        BEQ  BACK    DISPLAY PREVIOUS BYTE
391
        CMPA #$D     IS IT A CR?
392
        BNE  FORWRD  DISPLAY NEXT BYTE
393
CHRTN   RTS          EXIT ROUTINE
394
*
395
*
396
CHANGE  STA  SECBUF,Y      CHANGE BYTE IN MEMORY
397
        CMPA SECBUF,Y      DID MEMORY BYTE CHANGE?
398
        BEQ  FORWRD  $F972
399
        LBSR OUT1S   OUTPUT SPACE
400
        LDA  #'?     LOAD QUESTION MARK
401
        LBSR OUTCH   PRINT IT
402
FORWRD  CMPY #$01FF
403
        BEQ  MEMC2
404
        LEAY 1,Y     POINT TO NEXT HIGHER MEM LOCATION
405
        BRA  MEMC2   PRINT LOCATION & CONTENTS
406
BACK    CMPY #$0000
407
        BEQ  MEMC2
408
        LEAY -1,Y    POINT TO LAST MEM LOCATION
409
        BRA  MEMC2   PRINT LOCATION & CONTENTS
410
*
411
* THE FOLLOWING ROUTINE LOOPS WAITING FOR THE
412
* OPERATOR TO INPUT ONE VALID HEX ADDRESS. THE
413
* ADDRESS IS RETURNED IN THE "X" REGISTER.
414
*
415
* IN6HEX - MS BYTE IN ACCB
416
*          LS WORD IN X REG
417
*
418
IN6HEX LEAS -3,S
419
       BSR  BYTE
420
       BVS  NOTHEX
421
       STA  0,S
422
       BSR  BYTE
423
       BVS  NOTHEX
424
       STA  1,S
425
       BSR  BYTE
426
       BVS  NOTHEX
427
       STA  2,S
428
       CLRA
429
       PULS B,X,PC
430
*
431
* INPUT 3 HEX DIGITS
432
* RESULT RETURNED IN X
433
*
434
IN3HEX BSR INHEX INPUT HEX (1 HEX CHAR)
435
       BVS NOTHEX EXIT IF NOT VALID HEX
436
       TFR  D,X
437
       BSR BYTE INPUT BYTE (2 HEX CHAR)
438
       BVS NOTHEX
439
       PSHS X
440
       STA  1,S
441
       PULS X,PC
442
*
443
***** INPUT BYTE (2 HEX CHAR.) *****
444
*
445
BYTE   BSR INHEX GET HEX LEFT
446
       BVS NOTHEX EXIT IF NOT VALID HEX
447
       ASLA   ;
448
       ASLA   ;
449
       ASLA   ; SHIFT INTO LEFT NIBBLE
450
       ASLA   ;
451
       TFR  A,B PUT HEXL IN "B"
452
       BSR INHEX GET HEX RIGHT
453
       BVS NOTHEX EXIT IF NOT VALID HEX
454
       PSHS B PUSH HEXL ON STACK
455
       ADDA ,S+ ADD HEXL TO HEXR AND ADJ. STK
456
       RTS  RETURN WITH HEX L&R IN "A"
457
*
458
*
459
INHEX  BSR ECHON INPUT ASCII CHAR.
460
       CMPA #'0 IS IT > OR = "0" ?
461
       BCS NOTHEX IF LESS IT AIN'T HEX
462
       CMPA #'9 IS IT < OR = "9" ?
463
       BHI INHEXA IF > MAYBE IT'S ALPHA
464
       SUBA #$30 ASCII ADJ. NUMERIC
465
       RTS  ;
466
*
467
*
468
INHEXA CMPA #'A IS IT > OR = "A"
469
       BCS NOTHEX IF LESS IT AIN'T HEX
470
       CMPA #'F IS IT < OR = "F" ?
471
       BHI INHEXL IF > IT AIN'T HEX
472
       SUBA #$37 ASCII ADJ. ALPHA
473
       RTS  ;
474
*
475
INHEXL CMPA #'a IS IT > OR = "a"
476
       BCS NOTHEX IF LESS IT AIN'T HEX
477
       CMPA #'f IS IT < "f"
478
       BHI NOTHEX IF > IT AIN'T HEX
479
       SUBA #$57 ADJUST TO LOWER CASE
480
       RTS  ;
481
*
482
*
483
NOTHEX ORCC #2 SET (V) FLAG IN C-CODES REGISTER
484
       RTS  ;
485
*
486
*
487
OUT4H PSHS X PUSH X-REG. ON THE STACK
488
       PULS A POP MS BYTE OF X-REG INTO A-ACC.
489
       BSR OUTHL OUTPUT HEX LEFT
490
       PULS A POP LS BYTE OF X-REG INTO A-ACC.
491
OUTHL EQU *
492
OUT2H PSHS A SAVE IT BACK ON STACK
493
       LSRA CONVERT UPPER HEX NIBBLE TO ASCII
494
       LSRA  ;
495
       LSRA  ;
496
       LSRA  ;
497
       BSR XASCII PRINT HEX NIBBLE AS ASCII
498
OUTHR PULS A CONVERT LOWER HEX NIBBLE TO ASCII
499
       ANDA #$0F STRIP LEFT NIBBLE
500
XASCII ADDA #$30 ASCII ADJ
501
       CMPA #$39 IS IT < OR = "9" ?
502
       BLE  OUTC IF LESS, OUTPUT IT
503
       ADDA #7 IF > MAKE ASCII LETTER
504
OUTC BRA  OUTCH OUTPUT CHAR
505
*
506
* BINARY / ASCII --- THIS ROUTINE
507
* OUTPUTS A BYTE IN ENHANCED
508
* BINARY FORMAT. THE ENHANCEMENT
509
* IS DONE BY SUBSTITUTING ASCII
510
* LETTERS FOR THE ONES IN THE BYTE.
511
* THE ASCII ENHANCEMENT LETTERS
512
* ARE OBTAINED FROM THE STRING
513
* POINTED TO BY THE INDEX REG. "X".
514
*
515
BIASCI PSHS A SAVE "A" ON STACK
516
       LDB  #8 PRESET LOOP# TO BITS PER BYTE
517
OUTBA LDA ,X+ GET LETTER FROM STRING
518
       ASL  ,S TEST BYTE FOR "1" IN B7
519
       BCS PRTBA IF ONE PRINT LETTER
520
       LDA #'- IF ZERO PRINT "-"
521
PRTBA BSR OUTCH PRINT IT
522
       BSR OUT1S PRINT SPACE
523
       DECB SUB 1 FROM #BITS YET TO PRINT
524
       BNE OUTBA
525
       PULS A,PC
526
*
527
* PRINT STRING PRECEEDED BY A CR & LF.
528
*
529
PSTRNG JMP [PSTRGV] PRINT CR/LF
530
*
531
* PCRLF
532
*
533
PCRLF  JMP [PCRLFV]
534
*
535
* PDATA
536
*
537
PDATA  JMP [PDATAV]
538
*
539
ECHON  TST  ECHO IS ECHO REQUIRED ?
540
       BEQ  INCH ECHO NOT REQ. IF CLEAR
541
*
542
* INCHE
543
*
544
* ---GETS CHARACTER FROM TERMINAL AND
545
* ECHOS SAME. THE CHARACTER IS RETURNED
546
* IN THE "A" ACCUMULATOR WITH THE PARITY
547
* BIT MASKED OFF. ALL OTHER REGISTERS
548
* ARE PRESERVED.
549
*
550
INCHE  JMP [INCHEV]
551
*
552
* INCH
553
*
554
* GET CHARACTER FROM TERMINAL. RETURN
555
* CHARACTER IN "A" ACCUMULATOR AND PRESERVE
556
* ALL OTHER REGISTERS. THE INPUT CHARACTER
557
* IS 8 BITS AND IS NOT ECHOED.
558
*
559
*
560
INCH    JMP [INCHV]
561
*
562
* INCHEK
563
*
564
* CHECK FOR A CHARACTER AVAILABLE FROM
565
* THE TERMINAL. THE SERIAL PORT IS CHECKED
566
* FOR READ READY. ALL REGISTERS ARE
567
* PRESERVED, AND THE "Z" BIT WILL BE
568
* CLEAR IF A CHARACTER CAN BE READ.
569
*
570
*
571
INCHEK  JMP [INCHEKV]
572
*
573
OUT2S   BSR OUT1S OUTPUT 2 SPACES
574
OUT1S   LDA  #$20  OUTPUT 1 SPACE
575
*
576
*
577
* OUTCH
578
*
579
* OUTPUT CHARACTER TO TERMINAL.
580
* THE CHAR. TO BE OUTPUT IS
581
* PASSED IN THE A REGISTER.
582
* ALL REGISTERS ARE PRESERVED.
583
*
584
OUTCH   JMP [OUTCHV]
585
*
586
* MESSAGE STRINGS
587
*
588
TTLMSG FCB $0A,$0D
589
       FCC "COMPACT FLASH SECTOR READ/WRITE UTILITY"
590
       FCB $04
591
CMDMSG FCB $0D,$0A
592
       FCC "(R) READ SECTOR   "
593
       FCC "(W) WRITE SECTOR  "
594
       FCB $0D,$0A
595
       FCC "(N) NEXT SECTOR   "
596
       FCC "(P) PREV SECTOR   "
597
       FCB $0D,$0A
598
       FCC "(M) MODIFY SECTOR "
599
       FCC "(Q) QUIT          "
600
       FCB $0D,$0A
601
       FCC ": "
602
       FCB $04
603
SECPMT FCC "SECTOR NUMBER (6 HEX) : "
604
       FCB $04
605
SECMSG FCC "SECTOR NUMBER - $"
606
       FCB $04
607
MEMMSG FCB $0D,$0A
608
       FCC "MEMORY ADDRESS (3 HEX): "
609
       FCB $04
610
MSG5   FCC " - "
611
       FCB $04
612
MSG2   FCB $00,$00,$0A,$0D,$00,$00,$00,$04
613
WOTMSG FCC "What ?"
614
       FCB $0D,$0A,$04
615
PAGMSG FCB $0D,$0A
616
       FCC "Hit any key to continue"
617
       FCB $04
618
*
619
       END START

powered by: WebSVN 2.1.0

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