-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdisk.asm
138 lines (120 loc) · 3.39 KB
/
disk.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
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
;TRACE_FLOPPY = 1
readblocks_numblocks !byte 0
readblocks_currentblock !byte 0,0 ; 257 = ff 1
readblocks_mempos !byte 0,0 ; $2000 = 00 20
readblocks
; read <n> blocks (each 256 bytes) from disc to memory
; set values in readblocks_* before calling this function
- jsr .readblock ; read block
inc readblocks_mempos + 1 ; update mempos,block for next iteration
inc readblocks_currentblock
bne +
inc readblocks_currentblock + 1
+ dec readblocks_numblocks ; loop
bne -
; clear arguments for next call
lda #0
sta readblocks_currentblock + 1
rts
.readblock
; read 1 block from floppy
; $mempos (contains address to store in) [in]
; convert block to track/sector
; (assuming 16 tracks, each with 16 sectors)
lda readblocks_currentblock
and #$0f
sta .sector
lda readblocks_currentblock
sta .track
lda readblocks_currentblock + 1
ldx #4
- lsr
ror .track
dex
bne -
inc .track ; tracks are 1..
; convert track/sector to ascii and update drive command
lda .track
jsr conv2dec
stx .uname_track
sta .uname_track + 1
lda .sector
jsr conv2dec
stx .uname_sector
sta .uname_sector + 1
!ifdef TRACE_FLOPPY {
ldx readblocks_mempos
jsr printx
jsr space
ldx readblocks_mempos + 1
jsr printx
jsr space
ldx readblocks_currentblock
jsr printx
jsr space
lda #<.uname
ldy #>.uname
jsr printstring
}
; open the channel file
lda #cname_len
ldx #<.cname
ldy #>.cname
jsr kernel_setnam ; call SETNAM
lda #$02 ; file number 2
ldx $BA ; last used device number
bne +
ldx #$08 ; default to device 8
+ ldy #$02 ; secondary address 2
jsr kernel_setlfs ; call SETLFS
jsr kernel_open ; call OPEN
bcs .error ; if carry set, the file could not be opened
; open the command channel
lda #uname_len
ldx #<.uname
ldy #>.uname
jsr kernel_setnam ; call SETNAM
lda #$0F ; file number 15
ldx $BA ; last used device number
ldy #$0F ; secondary address 15
jsr kernel_setlfs ; call SETLFS
jsr kernel_open ; call OPEN (open command channel and send U1 command)
bcs .error ; if carry set, the file could not be opened
; check drive error channel here to test for
; FILE NOT FOUND error etc.
ldx #$02 ; filenumber 2
jsr kernel_chkin ; call CHKIN (file 2 now used as input)
lda readblocks_mempos
sta zp_mempos
lda readblocks_mempos+1
sta zp_mempos + 1
ldy #$00
- jsr kernel_readchar ; call CHRIN (get a byte from file)
sta (zp_mempos),Y ; write byte to memory
iny
bne - ; next byte, end when 256 bytes are read
.close
lda #$0F ; filenumber 15
jsr kernel_close ; call CLOSE
lda #$02 ; filenumber 2
jsr kernel_close ; call CLOSE
jsr kernel_clrchn ; call CLRCHN
rts
.error
; accumulator contains BASIC error code
; most likely errors:
; A = $05 (DEVICE NOT PRESENT)
jsr .close ; even if OPEN failed, the file has to be closed
lda #ERROR_FLOPPY_READ_ERROR
jsr fatalerror
.cname !text "#"
cname_len = * - .cname
.uname !text "U1 2 0 "
.uname_track !text "18 "
.uname_sector !text "00"
;!ifdef DEBUG {
!byte 13, 0 ; end of string, so we can print debug messages
;}
uname_len = * - .uname
.track !byte 0
.sector !byte 0