-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmsreader.asm
96 lines (89 loc) · 2.7 KB
/
dmsreader.asm
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
!cpu 6502
;!to "build/dmsreader",cbm ; output file
;
; ---- Code
;
; We're going to use kernal functions to read/write to disk.
; http://sta.c64.org/cbm64krnfunc.html
; http://codebase64.org/doku.php?id=base:saving_a_file
*=$CE00
; Write data to a file call X.DMS where X is A->Z
; The filename is stored in #CE40.
; Line 130 of the BASIC loader increments the filename.
; SETLFS. Set file parameters.
; Input: A = Logical number; X = Device number; Y = Secondary address.
file_start = $1000
; SETNAM. Set file name parameters.
; Input: A = File name length; X/Y = Pointer to file name.
LDA #fname_end-fname
LDX #<fname
LDY #>fname
JSR $FFBD ; SETNAM
LDA #$00
LDX #$08
LDY #$00
JSR $FFBA ; SETLFS
; SAVE. Save file. (Must call SETLFS and SETNAM beforehands.)
; Input: A = Address of zero page register holding start address of memory area to save; X/Y = End address of memory area plus 1.
; Output: Carry: 0 = No errors, 1 = Error; A = KERNAL error code (if Carry = 1).
; Used registers: A, X, Y.
LDA #$00
STA $FD
LDA #$10
STA $FE
LDA #$FD
LDX #$01
LDY $FC
STY $D020
JSR $FFD8
BCS .error
RTS
.error
; Akkumulator contains BASIC error code
RTS
; name used to save the DMS files.
*=$CE40
fname: !pet "a.dms"
fname_end:
; !byte $4d, $2e, $44, $4d, $53, $00
; http://codebase64.org/doku.php?id=base:reading_a_sector_from_disk
; READ FROM DISC INTO MEMORY
*=$CF00
LDA #$10
STA $FC
LDA #$00
STA $FB
STA $FF
RTS
*=$CF10
; Open channel 5 for reading, and then read data from it.
; Use indirect indexed addressing (https://www.c64-wiki.com/wiki/Indirect-indexed_addressing)
; to write data to $1000 onwards, through the locations $FB/$FC.
; At the end of the loop we have written 255 bytes so increment $FC
; Turn off BASIC and other ROMs to write data to RAM.
; It also writes the data to the screen at $0400,Y to show progress.
; CHKIN. Define file as default input. (Must call OPEN beforehands.)
; Input: X = Logical number.
LDX #$05
JSR $FFC6
; CHRIN. Read byte from default input (for keyboard, read a line from the screen). (If not keyboard, must call OPEN and CHKIN beforehands.)
; Input: –
; Output: A = Byte read.
; Used registers: A, Y.
LDY #$00
L_108C: JSR $FFCF
LDX #$36 ; 0011 0110
STX $01 ; Turn off all ROMs http://sta.c64.org/cbm64mem.html
STA ($FB),Y
STA $0400,Y
STY $0400
STY $D020
LDX #$37 ; Turn ROMs on again.
STX $01
INY
BNE L_108C
INC $FC
LDA #$00
STA $D020
JSR $FFCC
RTS