-
Notifications
You must be signed in to change notification settings - Fork 1
/
loader_drive_core.inc
181 lines (181 loc) · 2.54 KB
/
loader_drive_core.inc
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#importonce
.macro driveload(init, dirtrack, dirsect, blk4trk, blk4sec, blk4job, blk4buf, retrycnt, hdrid1, hdrid2, drv0id1, drv0id2, readbyte, writebyte, ledport, ledvalue, serialdata, drive_serial, ledinverted) {
jsr init
mainloop:
jsr readfnam
lda blk4trk
sta temp1
ora blk4sec
bne !+
lda #RTS
sta senderrorend
jsr senderror
jmp ($fffc)
!: lda blk4sec
sta temp2
ldy #dirsect
dirloop:
ldx dirtrack
stx blk4trk
sty blk4sec
jsr readblock
ldy #2
nxtdirent:
lda blk4buf,y
and #$83 // type = PRG?
cmp #$82
bne nomatch
lda blk4buf+3,y // filename first char match?
cmp temp1
bne nomatch
lda blk4buf+4,y // filename second char match?
cmp temp2
bne nomatch
jmp doload
nomatch:
tya
clc
adc #32
tay
bcc nxtdirent
ldy blk4buf+1
bpl dirloop
senderror:
.if (drive_serial) {
lda #%00000000
sta serialdata
}
ldx #$fe
jsr writebyte
ldx #$fe
jsr writebyte
ldx #$ac
jsr writebyte
ldx #$f7
jsr writebyte
senderrorend:
jmp mainloop
doload: lda blk4buf+1,y
sta blk4trk
lda blk4buf+2,y
sta blk4sec
doload1:
jsr readblock
ldy #0
lda blk4buf
sta blk4trk
bne !+
ldy blk4buf + 1
iny
!: sty temp1
lda blk4buf + 1
sta blk4sec
ldy #2
.if (drive_serial) {
lda #%00000000
sta serialdata
}
doload2:
ldx blk4buf,y
cpx #$ac
bne !+
jsr writebyte
ldx #$ac
!: jsr writebyte
iny
cpy temp1
bne doload2
lda blk4buf
beq eof
ldx #$ac
jsr writebyte
ldx #$c3
jsr writebyte
.if (drive_serial) {
lda #%00001000
sta serialdata
}
jmp doload1
eof:
ldx #$ac
jsr writebyte
ldx #$ff
jsr writebyte
jmp mainloop
readfnam:
.if (drive_serial) {
lda #%00001000
sta serialdata
}
lda ledport // turn led off
.if (!ledinverted) {
and #~ledvalue
} else {
ora #ledvalue
}
sta ledport
cli
.if (drive_serial) {
lda #%00000001
!: bit serialdata
beq !-
}
sei
.if (drive_serial) {
lda #%00000000
sta serialdata
}
jsr readbyte
pha
jsr readbyte
sta blk4trk
jsr readbyte
sta blk4sec
.if (drive_serial) {
lda #%00001000
sta serialdata
}
lda ledport // turn led on
.if (!ledinverted) {
ora #ledvalue
} else {
and #~ledvalue
}
sta ledport
pla
rts
readblock:
ldy #5
sty retrycnt
retry: cli
lda #$80 // command: read sector
sta blk4job
!: lda blk4job
bmi !- // wait for block to be read
beq readok
cmp #1 // success
beq readok
dec retrycnt
ldy retrycnt
bmi readerror
cpy #2 // header block not found
bne !+
lda #$c0 // bump head
sta blk4job
!: lda hdrid1
sta drv0id1
lda hdrid2
sta drv0id2
!: lda blk4job
bmi !-
bpl retry
readerror:
pla
pla
sei
jmp senderror
readok: sei
rts
temp1: .byte 0
temp2: .byte 0
}