mirror of
https://github.com/freitz85/AppleIISd.git
synced 2024-11-19 08:30:54 +00:00
727 lines
31 KiB
Plaintext
727 lines
31 KiB
Plaintext
1 ********************************
|
||
2 *
|
||
3 * Apple][Sd Firmware
|
||
4 * Version 0.5
|
||
5 *
|
||
6 * (c) Florian Reitz, 2017
|
||
7 *
|
||
8 * X register usually contains SLOT16
|
||
9 * Y register is used for counting or SLOT
|
||
10 *
|
||
11 ********************************
|
||
12
|
||
16-JUL-17 15:06
|
||
14
|
||
15 XC ; enable 65C02 code
|
||
16 DEBUG = 1
|
||
17 DO DEBUG
|
||
18 ORG $8000
|
||
19 ELSE
|
||
20 ORG $C800 ; Expansion ROM
|
||
21 FIN
|
||
22
|
||
23 * Memory defines
|
||
24
|
||
25 SLOT16 = $2B ; $s0 -> slot * 16
|
||
26 WORK = $3C
|
||
27 SLOT = $3D ; $0s
|
||
28 CMDLO = $40
|
||
29 CMDHI = $41
|
||
30
|
||
31 CURSLOT = $07F8 ; $Cs
|
||
32 DATA = $C080
|
||
33 CTRL = DATA+1
|
||
34 DIV = DATA+2
|
||
35 SS = DATA+3
|
||
36 R30 = $0478
|
||
37 R31 = $04F8
|
||
38 R32 = $0578
|
||
39 R33 = $05F8
|
||
40
|
||
41 * Constants
|
||
42
|
||
43 SSNONE = $0F
|
||
44 SS0 = $0E
|
||
45 DUMMY = $FF
|
||
46
|
||
47
|
||
48 ********************************
|
||
49 *
|
||
50 * Install SD card driver
|
||
51 *
|
||
52 ********************************
|
||
53
|
||
54 * signature bytes
|
||
55
|
||
8000: A2 20 56 LDX #$20
|
||
8002: A0 00 57 LDY #$00
|
||
8004: A2 03 58 LDX #$03
|
||
8006: 86 3C 59 STX WORK
|
||
===== Page 2 =====
|
||
|
||
60
|
||
61 * find slot nr
|
||
62
|
||
63 DO DEBUG
|
||
8008: A9 04 64 LDA #$04
|
||
800A: 85 3D 65 STA SLOT
|
||
800C: A9 C4 66 LDA #$C4
|
||
800E: 8D F8 07 67 STA CURSLOT
|
||
8011: A9 40 68 LDA #$40
|
||
8013: 85 2B 69 STA SLOT16
|
||
70 ELSE
|
||
71 JSR $FF58
|
||
72 TSX
|
||
73 LDA $0100,X
|
||
74 AND #$0F
|
||
75 STA SLOT ; $0s
|
||
76 ORA #$C0
|
||
77 STA CURSLOT ; $Cs
|
||
78 ASL A
|
||
79 ASL A
|
||
80 ASL A
|
||
81 ASL A
|
||
82 STA SLOT16 ; $s0
|
||
83 FIN
|
||
8015: AA 84 TAX ; X holds now SLOT16
|
||
85
|
||
8016: 20 00 81 86 JSR INIT
|
||
8019: 2C FF CF 87 BIT $CFFF
|
||
88
|
||
89 *
|
||
90 * TODO: check for init error
|
||
91 *
|
||
92
|
||
93 * see if slot has a driver already
|
||
94
|
||
801C: AE 31 BF 95 LDX $BF31 ; get devcnt
|
||
801F: BD 32 BF 96 INSLP LDA $BF32,X ; get a devnum
|
||
8022: 29 70 97 AND #$70 ; isolate slot
|
||
8024: C5 2B 98 CMP SLOT16 ; slot?
|
||
8026: F0 31 99 BEQ INSOUT ; yes, skip it
|
||
8028: CA 100 DEX
|
||
8029: 10 F4 101 BPL INSLP ; keep up the search
|
||
102
|
||
103 * restore the devnum to the list
|
||
104
|
||
802B: AE 31 BF 105 LDX $BF31 ; get devcnt again
|
||
802E: E0 0D 106 CPX #$0D ; device table full?
|
||
8030: D0 06 107 BNE INSLP2
|
||
108
|
||
8032: 20 3A FF 109 JSR $FF3A ; bell
|
||
8035: 4C 59 80 110 JMP INSOUT ; do something!
|
||
111
|
||
8038: BD 31 BF 112 INSLP2 LDA $BF32-1,X ; move all entries down
|
||
803B: 9D 32 BF 113 STA $BF32,X ; to make room at front
|
||
803E: CA 114 DEX ; for a new entry
|
||
803F: D0 F7 115 BNE INSLP2
|
||
8041: A9 04 116 LDA #$04 ; ProFile type device
|
||
===== Page 3 =====
|
||
|
||
8043: 05 2B 117 ORA SLOT16
|
||
8045: 8D 32 BF 118 STA $BF32 ; slot, drive 1 at top of list
|
||
8048: EE 31 BF 119 INC $BF31 ; update devcnt
|
||
120
|
||
121 * now insert the device driver vector
|
||
122
|
||
804B: A5 3D 123 LDA SLOT
|
||
804D: 0A 124 ASL
|
||
804E: AA 125 TAX
|
||
804F: A9 5A 126 LDA #<DRIVER
|
||
8051: 9D 10 BF 127 STA $BF10,X ; write to driver table
|
||
128 DO DEBUG
|
||
8054: A9 80 129 LDA #>DRIVER
|
||
130 ELSE
|
||
131 LDA CURSLOT
|
||
132 FIN
|
||
8056: 9D 11 BF 133 STA $BF11,X
|
||
134
|
||
8059: 60 135 INSOUT RTS
|
||
136
|
||
137
|
||
138 ********************************
|
||
139 *
|
||
140 * Jump table
|
||
141 *
|
||
142 ********************************
|
||
143
|
||
805A: D8 144 DRIVER CLD
|
||
145 DO DEBUG
|
||
805B: A9 04 146 LDA #$04
|
||
805D: 85 3D 147 STA SLOT
|
||
805F: A9 C4 148 LDA #$C4
|
||
8061: 8D F8 07 149 STA CURSLOT
|
||
8064: A9 40 150 LDA #$40
|
||
8066: 85 2B 151 STA SLOT16
|
||
152 ELSE
|
||
153 JSR $FF58 ; find slot nr
|
||
154 TSX
|
||
155 LDA $0100,X
|
||
156 AND #$0F
|
||
157 STA SLOT ; $0s
|
||
158 ORA #$C0
|
||
159 STA CURSLOT ; $Cs
|
||
160 ASL A
|
||
161 ASL A
|
||
162 ASL A
|
||
163 ASL A
|
||
164 STA SLOT16 ; $s0
|
||
165 FIN
|
||
8068: AA 166 TAX ; X holds now SLOT16
|
||
167
|
||
8069: 2C FF CF 168 BIT $CFFF
|
||
806C: A5 42 169 LDA $42 ; get command
|
||
806E: C9 00 170 CMP #$00
|
||
8070: F0 10 171 BEQ :STATUS
|
||
8072: C9 01 172 CMP #$01
|
||
8074: F0 0F 173 BEQ :READ
|
||
===== Page 4 =====
|
||
|
||
8076: C9 02 174 CMP #$02
|
||
8078: F0 0E 175 BEQ :WRITE
|
||
807A: C9 03 176 CMP #$03
|
||
807C: F0 0D 177 BEQ :FORMAT
|
||
807E: 38 178 SEC ; unknown command
|
||
807F: A9 01 179 LDA #$01
|
||
8081: 60 180 RTS
|
||
181
|
||
8082: 4C B8 82 182 :STATUS JMP STATUS
|
||
8085: 4C C0 82 183 :READ JMP READ
|
||
8088: 4C 06 83 184 :WRITE JMP WRITE
|
||
808B: 4C 47 83 185 :FORMAT JMP FORMAT
|
||
186
|
||
187 * Signature bytes
|
||
188
|
||
808E: 00 00 00 189 DS \ ; fill with zeroes
|
||
8091: 00 00 00 00
|
||
8095: 00 00 00 00
|
||
8099: 00 00 00 00
|
||
809D: 00 00 00 00
|
||
80A1: 00 00 00 00
|
||
80A5: 00 00 00 00
|
||
80A9: 00 00 00 00
|
||
80AD: 00 00 00 00
|
||
80B1: 00 00 00 00
|
||
80B5: 00 00 00 00
|
||
80B9: 00 00 00 00
|
||
80BD: 00 00 00 00
|
||
80C1: 00 00 00 00
|
||
80C5: 00 00 00 00
|
||
80C9: 00 00 00 00
|
||
80CD: 00 00 00 00
|
||
80D1: 00 00 00 00
|
||
80D5: 00 00 00 00
|
||
80D9: 00 00 00 00
|
||
80DD: 00 00 00 00
|
||
80E1: 00 00 00 00
|
||
80E5: 00 00 00 00
|
||
80E9: 00 00 00 00
|
||
80ED: 00 00 00 00
|
||
80F1: 00 00 00 00
|
||
80F5: 00 00 00 00
|
||
80F9: 00 00 00 00
|
||
80FD: 00 00 00
|
||
190 DS -4 ; locate to $C8FC
|
||
80FC: FF FF 191 DW $FFFF ; 65535 blocks
|
||
80FE: 47 192 DB $47 ; Status bits
|
||
80FF: 5A 193 DB #<DRIVER ; LSB of driver
|
||
194
|
||
195
|
||
196 ********************************
|
||
197 *
|
||
198 * Initialize SD card
|
||
199 *
|
||
200 * C Clear - No error
|
||
201 * Set - Error
|
||
202 * A $00 - No error
|
||
===== Page 5 =====
|
||
|
||
203 * $27 - I/O error - Init failed
|
||
204 * $28 - No card inserted
|
||
205 *
|
||
206 ********************************
|
||
207
|
||
8100: D8 208 INIT CLD
|
||
8101: A9 03 209 LDA #$03 ; set SPI mode 3
|
||
8103: 9D 81 C0 210 STA CTRL,X
|
||
8106: A9 0F 211 LDA #SSNONE
|
||
8108: 9D 83 C0 212 STA SS,X
|
||
810B: A9 07 213 LDA #7
|
||
810D: 9D 82 C0 214 STA DIV,X
|
||
8110: A0 0A 215 LDY #10
|
||
8112: A9 FF 216 LDA #DUMMY
|
||
217
|
||
8114: 9D 80 C0 218 :LOOP STA DATA,X
|
||
8117: 3C 81 C0 219 :WAIT BIT CTRL,X
|
||
811A: 10 FB 220 BPL :WAIT
|
||
811C: 88 221 DEY
|
||
811D: D0 F5 222 BNE :LOOP ; do 10 times
|
||
811F: A9 0E 223 LDA #SS0 ; set CS low
|
||
8121: 9D 83 C0 224 STA SS,X
|
||
225
|
||
8124: A9 4B 226 LDA #<CMD0 ; send CMD0
|
||
8126: 85 40 227 STA CMDLO
|
||
8128: A9 83 228 LDA #>CMD0
|
||
812A: 85 41 229 STA CMDHI
|
||
812C: 20 D7 81 230 JSR CMD
|
||
812F: 20 EB 81 231 JSR GETR1 ; get response
|
||
8132: C9 01 232 CMP #$01
|
||
8134: D0 39 233 BNE :ERROR1 ; error!
|
||
234
|
||
8136: A9 57 235 LDA #<CMD8 ; send CMD8
|
||
8138: 85 40 236 STA CMDLO
|
||
813A: A9 83 237 LDA #>CMD8
|
||
813C: 85 41 238 STA CMDHI
|
||
813E: 20 D7 81 239 JSR CMD
|
||
8141: 20 06 82 240 JSR GETR3
|
||
8144: C9 01 241 CMP #$01
|
||
8146: D0 2A 242 BNE :SDV1 ; may be SD Ver. 1
|
||
243
|
||
244 * check for $01aa match!
|
||
8148: A9 63 245 :SDV2 LDA #<CMD55
|
||
814A: 85 40 246 STA CMDLO
|
||
814C: A9 83 247 LDA #>CMD55
|
||
814E: 85 41 248 STA CMDHI
|
||
8150: 20 D7 81 249 JSR CMD
|
||
8153: 20 EB 81 250 JSR GETR1
|
||
8156: A9 69 251 LDA #<ACMD4140
|
||
8158: 85 40 252 STA CMDLO
|
||
815A: A9 83 253 LDA #>ACMD4140
|
||
815C: 85 41 254 STA CMDHI
|
||
815E: 20 D7 81 255 JSR CMD
|
||
8161: 20 EB 81 256 JSR GETR1
|
||
8164: C9 01 257 CMP #$01
|
||
8166: F0 E0 258 BEQ :SDV2 ; wait for ready
|
||
8168: C9 00 259 CMP #$00
|
||
===== Page 6 =====
|
||
|
||
816A: D0 03 260 BNE :ERROR1 ; error!
|
||
261 * send CMD58
|
||
262 * SD Ver. 2 initialized!
|
||
816C: 4C AC 81 263 JMP :BLOCKSZ
|
||
264
|
||
816F: 4C C8 81 265 :ERROR1 JMP :IOERROR ; needed for far jump
|
||
266
|
||
8172: A9 63 267 :SDV1 LDA #<CMD55
|
||
8174: 85 40 268 STA CMDLO
|
||
8176: A9 83 269 LDA #>CMD55
|
||
8178: 85 41 270 STA CMDHI
|
||
817A: 20 D7 81 271 JSR CMD ; ignore response
|
||
817D: A9 6F 272 LDA #<ACMD410
|
||
817F: 85 40 273 STA CMDLO
|
||
8181: A9 83 274 LDA #>ACMD410
|
||
8183: 85 41 275 STA CMDHI
|
||
8185: 20 D7 81 276 JSR CMD
|
||
8188: 20 EB 81 277 JSR GETR1
|
||
818B: C9 01 278 CMP #$01
|
||
818D: F0 E3 279 BEQ :SDV1 ; wait for ready
|
||
818F: C9 00 280 CMP #$00
|
||
8191: D0 03 281 BNE :MMC ; may be MMC card
|
||
282 * SD Ver. 1 initialized!
|
||
8193: 4C AC 81 283 JMP :BLOCKSZ
|
||
284
|
||
8196: A9 51 285 :MMC LDA #<CMD1
|
||
8198: 85 40 286 STA CMDLO
|
||
819A: A9 83 287 LDA #>CMD1
|
||
819C: 85 41 288 STA CMDHI
|
||
819E: 20 D7 81 289 :LOOP1 JSR CMD
|
||
81A1: 20 EB 81 290 JSR GETR1
|
||
81A4: C9 01 291 CMP #$01
|
||
81A6: F0 F6 292 BEQ :LOOP1 ; wait for ready
|
||
81A8: C9 00 293 CMP #$00
|
||
81AA: D0 1C 294 BNE :IOERROR ; error!
|
||
295 * MMC Ver. 3 initialized!
|
||
296
|
||
81AC: A9 5D 297 :BLOCKSZ LDA #<CMD16
|
||
81AE: 85 40 298 STA CMDLO
|
||
81B0: A9 83 299 LDA #>CMD16
|
||
81B2: 85 41 300 STA CMDHI
|
||
81B4: 20 D7 81 301 JSR CMD
|
||
81B7: 20 EB 81 302 JSR GETR1
|
||
81BA: C9 00 303 CMP #$00
|
||
81BC: D0 0A 304 BNE :IOERROR ; error!
|
||
305
|
||
81BE: 18 306 :END CLC ; all ok
|
||
81BF: A0 00 307 LDY #0
|
||
81C1: 90 08 308 BCC :END1
|
||
81C3: 38 309 :CDERROR SEC
|
||
81C4: A0 28 310 LDY #$28 ; no card error
|
||
81C6: B0 03 311 BCS :END1
|
||
81C8: 38 312 :IOERROR SEC
|
||
81C9: A0 27 313 LDY #$27 ; init error
|
||
81CB: A9 0F 314 :END1 LDA #SSNONE ; deselect card
|
||
81CD: 9D 83 C0 315 STA SS,X
|
||
81D0: A9 00 316 LDA #0 ; set div to 2
|
||
===== Page 7 =====
|
||
|
||
81D2: 9D 82 C0 317 STA DIV,X
|
||
81D5: 98 318 TYA ; retval in A
|
||
81D6: 60 319 RTS
|
||
320
|
||
321
|
||
322 ********************************
|
||
323 *
|
||
324 * Send SD command
|
||
325 * Call with command in CMDHI and CMDLO
|
||
326 *
|
||
327 ********************************
|
||
328
|
||
81D7: 5A 329 CMD PHY
|
||
81D8: A0 00 330 LDY #0
|
||
81DA: B1 40 331 :LOOP LDA (CMDLO),Y
|
||
81DC: 9D 80 C0 332 STA DATA,X
|
||
81DF: 3C 81 C0 333 :WAIT BIT CTRL,X ; TC is in N
|
||
81E2: 10 FB 334 BPL :WAIT
|
||
81E4: C8 335 INY
|
||
81E5: C0 06 336 CPY #6
|
||
81E7: 90 F1 337 BCC :LOOP
|
||
81E9: 7A 338 PLY
|
||
81EA: 60 339 RTS
|
||
340
|
||
341
|
||
342 ********************************
|
||
343 *
|
||
344 * Get R1
|
||
345 * R1 is in A
|
||
346 *
|
||
347 ********************************
|
||
348
|
||
81EB: A9 FF 349 GETR1 LDA #DUMMY
|
||
81ED: 9D 80 C0 350 STA DATA,X
|
||
81F0: 3C 81 C0 351 :WAIT BIT CTRL,X
|
||
81F3: 10 FB 352 BPL :WAIT
|
||
81F5: BD 80 C0 353 LDA DATA,X ; get response
|
||
81F8: 85 3C 354 STA WORK ; save R1
|
||
81FA: 29 80 355 AND #$80
|
||
81FC: D0 ED 356 BNE GETR1 ; wait for MSB=0
|
||
81FE: A9 FF 357 LDA #DUMMY
|
||
8200: 9D 80 C0 358 STA DATA,X ; send another dummy
|
||
8203: A5 3C 359 LDA WORK ; restore R1
|
||
8205: 60 360 RTS
|
||
361
|
||
362
|
||
363 ********************************
|
||
364 *
|
||
365 * Get R3
|
||
366 * R1 is in A
|
||
367 * R3 is in scratchpad ram
|
||
368 *
|
||
369 ********************************
|
||
370
|
||
8206: 20 EB 81 371 GETR3 JSR GETR1 ; get R1 first
|
||
8209: 48 372 PHA ; save R1
|
||
820A: 5A 373 PHY ; save Y
|
||
===== Page 8 =====
|
||
|
||
820B: A0 04 374 LDY #04 ; load counter
|
||
820D: A9 FF 375 :LOOP LDA #DUMMY ; send dummy
|
||
820F: 9D 80 C0 376 STA DATA,X
|
||
8212: 3C 81 C0 377 :WAIT BIT CTRL,X
|
||
8215: 10 FB 378 BPL :WAIT
|
||
8217: BD 80 C0 379 LDA DATA,X
|
||
821A: 48 380 PHA
|
||
821B: 88 381 DEY
|
||
821C: D0 EF 382 BNE :LOOP ; do 4 times
|
||
821E: A4 3D 383 LDY SLOT
|
||
8220: 68 384 PLA
|
||
8221: 99 F8 05 385 STA R33,Y ; save R3
|
||
8224: 68 386 PLA
|
||
8225: 99 78 05 387 STA R32,Y
|
||
8228: 68 388 PLA
|
||
8229: 99 F8 04 389 STA R31,Y
|
||
822C: 68 390 PLA
|
||
822D: 99 78 04 391 STA R30,Y
|
||
8230: 7A 392 PLY ; restore Y
|
||
8231: A9 FF 393 LDA #DUMMY
|
||
8233: 9D 80 C0 394 STA DATA,X ; send another dummy
|
||
8236: 68 395 PLA ; restore R1
|
||
8237: 60 396 RTS
|
||
397
|
||
398
|
||
399 ********************************
|
||
400 *
|
||
401 * Calculate block address
|
||
402 * Block no is in $46-47
|
||
403 * Address is in R30-R33
|
||
404 *
|
||
405 ********************************
|
||
406
|
||
8238: 5A 407 BLOCK PHY ; save Y
|
||
8239: A4 3D 408 LDY SLOT
|
||
823B: A5 46 409 LDA $46 ; store block num
|
||
823D: 99 F8 05 410 STA R33,Y ; in R30-R33
|
||
8240: A5 47 411 LDA $47
|
||
8242: 99 78 05 412 STA R32,Y
|
||
8245: A9 00 413 LDA #0
|
||
8247: 99 F8 04 414 STA R31,Y
|
||
824A: 99 78 04 415 STA R30,Y
|
||
416
|
||
824D: DA 417 PHX
|
||
824E: A0 09 418 LDY #9
|
||
8250: A6 3D 419 LDX SLOT ; ASL can't be done with Y
|
||
8252: 1E F8 05 420 :LOOP ASL R33,X ; mul block num
|
||
8255: 3E 78 05 421 ROL R32,X ; by 512 to get
|
||
8258: 3E F8 04 422 ROL R31,X ; real address
|
||
825B: 3E 78 04 423 ROL R30,X
|
||
825E: 88 424 DEY
|
||
825F: D0 F1 425 BNE :LOOP
|
||
8261: FA 426 PLX
|
||
8262: 7A 427 PLY ; restore Y
|
||
8263: 60 428 RTS
|
||
429
|
||
430
|
||
===== Page 9 =====
|
||
|
||
431 ********************************
|
||
432 *
|
||
433 * Send SD command
|
||
434 * Cmd is in A
|
||
435 *
|
||
436 ********************************
|
||
437
|
||
8264: 7A 438 COMMAND PLY ; save Y
|
||
8265: A4 3D 439 LDY SLOT
|
||
8267: 9D 80 C0 440 STA DATA,X ; send command
|
||
826A: 3C 81 C0 441 :WAIT BIT CTRL,X
|
||
826D: 10 FB 442 BPL :WAIT
|
||
826F: B9 78 04 443 :ARG LDA R30,Y ; get arg from R30 on
|
||
8272: 9D 80 C0 444 STA DATA,X
|
||
8275: 3C 81 C0 445 :WAIT1 BIT CTRL,X
|
||
8278: 10 FB 446 BPL :WAIT1
|
||
827A: B9 F8 04 447 LDA R31,Y
|
||
827D: 9D 80 C0 448 STA DATA,X
|
||
8280: 3C 81 C0 449 :WAIT11 BIT CTRL,X
|
||
8283: 10 FB 450 BPL :WAIT11
|
||
8285: B9 78 05 451 LDA R32,Y
|
||
8288: 9D 80 C0 452 STA DATA,X
|
||
828B: 3C 81 C0 453 :WAIT12 BIT CTRL,X
|
||
828E: 10 FB 454 BPL :WAIT12
|
||
8290: B9 F8 05 455 LDA R33,Y
|
||
8293: 9D 80 C0 456 STA DATA,X
|
||
8296: 3C 81 C0 457 :WAIT13 BIT CTRL,X
|
||
8299: 10 FB 458 BPL :WAIT13
|
||
829B: A9 FF 459 LDA #DUMMY
|
||
829D: 9D 80 C0 460 STA DATA,X ; dummy crc
|
||
82A0: 3C 81 C0 461 :WAIT2 BIT CTRL,X
|
||
82A3: 10 FB 462 BPL :WAIT2
|
||
82A5: A9 FF 463 :GETR1 LDA #DUMMY
|
||
82A7: 9D 80 C0 464 STA DATA,X ; get R1
|
||
82AA: 3C 81 C0 465 :WAIT3 BIT CTRL,X
|
||
82AD: 10 FB 466 BPL :WAIT3
|
||
82AF: BD 80 C0 467 LDA DATA,X ; get response
|
||
468 *
|
||
469 * TODO: check for error!
|
||
470 *
|
||
82B2: C9 FE 471 CMP #$FE
|
||
82B4: D0 EF 472 BNE :GETR1 ; wait for $FE
|
||
82B6: 7A 473 PLY ; restore Y
|
||
82B7: 60 474 RTS
|
||
475
|
||
476
|
||
477 ********************************
|
||
478 *
|
||
479 * Status request
|
||
480 * $43 Unit number DSSS000
|
||
481 * $44-45 Unused
|
||
482 * $46-47 Unused
|
||
483 *
|
||
484 * C Clear - No error
|
||
485 * Set - Error
|
||
486 * A $00 - No error
|
||
487 * $27 - I/O error
|
||
===== Page 10 =====
|
||
|
||
488 * $28 - No card inserted / no init
|
||
489 * $2B - Card write protected
|
||
490 * x - Blocks avail (low byte)
|
||
491 * y - Blocks avail (high byte)
|
||
492 *
|
||
493 ********************************
|
||
494
|
||
82B8: 18 495 STATUS CLC ; no error
|
||
82B9: A9 00 496 LDA #0
|
||
82BB: A2 FF 497 LDX #$FF ; 32 MB partition
|
||
82BD: A0 FF 498 LDY #$FF
|
||
82BF: 60 499 RTS
|
||
500
|
||
501 * TODO: check for card detect and write protect!
|
||
502
|
||
503
|
||
504 ********************************
|
||
505 *
|
||
506 * Read 512 byte block
|
||
507 * $43 Unit number DSSS0000
|
||
508 * $44-45 Address (LO/HI) of buffer
|
||
509 * $46-47 Block number (LO/HI)
|
||
510 *
|
||
511 * C Clear - No error
|
||
512 * Set - Error
|
||
513 * A $00 - No error
|
||
514 * $27 - Bad block number
|
||
515 * $28 - No card inserted
|
||
516 *
|
||
517 ********************************
|
||
518
|
||
519 * TODO: check for card detect!
|
||
520
|
||
82C0: 20 38 82 521 READ JSR BLOCK ; calc block address
|
||
522
|
||
82C3: A9 0E 523 LDA #SS0 ; enable /CS
|
||
82C5: 9D 83 C0 524 STA SS,X
|
||
82C8: A9 51 525 LDA #$51 ; send CMD17
|
||
82CA: 20 64 82 526 JSR COMMAND ; send command
|
||
527
|
||
82CD: 5A 528 PHY
|
||
82CE: A0 02 529 LDY #2 ; read data from card
|
||
82D0: 64 3C 530 :LOOPY STZ WORK
|
||
82D2: A9 FF 531 :LOOPW LDA #DUMMY
|
||
82D4: 9D 80 C0 532 STA DATA,X
|
||
82D7: 3C 81 C0 533 :WAIT4 BIT CTRL,X
|
||
82DA: 10 FB 534 BPL :WAIT4
|
||
82DC: BD 80 C0 535 LDA DATA,X
|
||
82DF: 92 44 536 STA ($44)
|
||
82E1: E6 44 537 INC $44
|
||
82E3: D0 02 538 BNE :INW
|
||
82E5: E6 45 539 INC $45 ; inc msb on page boundary
|
||
82E7: E6 3C 540 :INW INC WORK
|
||
82E9: D0 E7 541 BNE :LOOPW
|
||
82EB: 88 542 DEY
|
||
82EC: D0 E2 543 BNE :LOOPY
|
||
82EE: 7A 544 PLY
|
||
===== Page 11 =====
|
||
|
||
545
|
||
82EF: 20 06 82 546 JSR GETR3 ; read 2 bytes crc
|
||
82F2: A9 0F 547 LDA #SSNONE
|
||
82F4: 9D 83 C0 548 STA SS,X ; disable /CS
|
||
82F7: 18 549 CLC ; no error
|
||
82F8: A9 00 550 LDA #$00
|
||
82FA: 7A 551 PLY ; restore Y
|
||
82FB: 60 552 RTS
|
||
553
|
||
82FC: A9 0F 554 :ERROR LDA #SSNONE
|
||
82FE: 9D 83 C0 555 STA SS,X ; disable /CS
|
||
8301: 38 556 SEC ; an error occured
|
||
8302: A9 27 557 LDA #$27
|
||
8304: 7A 558 PLY ; restore Y
|
||
8305: 60 559 RTS
|
||
560
|
||
561
|
||
562 ********************************
|
||
563 *
|
||
564 * Write 512 byte block
|
||
565 * $43 Unit number DSSS000
|
||
566 * $44-45 Address (LO/HI) of buffer
|
||
567 * $46-47 Block number (LO/HI)
|
||
568 *
|
||
569 * C Clear - No error
|
||
570 * Set - Error
|
||
571 * A $00 - No error
|
||
572 * $27 - Bad block number
|
||
573 * $28 - No card inserted
|
||
574 *
|
||
575 ********************************
|
||
576
|
||
577 * TODO: check for card detect and write protect!
|
||
578
|
||
8306: 20 38 82 579 WRITE JSR BLOCK ; calc block address
|
||
580
|
||
8309: A9 0E 581 LDA #SS0 ; enable /CS
|
||
830B: 9D 83 C0 582 STA SS,X
|
||
830E: A9 58 583 LDA #$58 ; send CMD24
|
||
8310: 20 64 82 584 JSR COMMAND ; send command
|
||
585
|
||
8313: 5A 586 PHY
|
||
8314: A0 02 587 LDY #2 ; send data to card
|
||
8316: 64 3C 588 :LOOPY STZ WORK
|
||
8318: B2 44 589 :LOOPW LDA ($44)
|
||
831A: 9D 80 C0 590 STA DATA,X
|
||
831D: 3C 81 C0 591 :WAIT4 BIT CTRL,X
|
||
8320: 10 FB 592 BPL :WAIT4
|
||
8322: E6 44 593 INC $44
|
||
8324: D0 02 594 BNE :INW
|
||
8326: E6 45 595 INC $45 ; inc msb on page boundary
|
||
8328: E6 3C 596 :INW INC WORK
|
||
832A: D0 EC 597 BNE :LOOPW
|
||
832C: 88 598 DEY
|
||
832D: D0 E7 599 BNE :LOOPY
|
||
600
|
||
832F: A0 02 601 LDY #2 ; send 2 dummy crc bytes
|
||
===== Page 12 =====
|
||
|
||
8331: 9D 80 C0 602 :CRC STA DATA,X
|
||
8334: 3C 81 C0 603 :WAIT5 BIT CTRL,X
|
||
8337: 10 FB 604 BPL :WAIT5
|
||
8339: 88 605 DEY
|
||
833A: D0 F5 606 BNE :CRC
|
||
833C: 7A 607 PLY
|
||
608
|
||
833D: A9 0F 609 LDA #SSNONE ; disable /CS
|
||
833F: 9D 83 C0 610 STA SS,X
|
||
8342: 18 611 CLC ; no error
|
||
8343: A9 00 612 LDA #0
|
||
8345: 7A 613 PLY
|
||
8346: 60 614 RTS
|
||
615
|
||
616
|
||
617 ********************************
|
||
618 *
|
||
619 * Format
|
||
620 * not supported!
|
||
621 *
|
||
622 ********************************
|
||
623
|
||
8347: 38 624 FORMAT SEC
|
||
8348: A9 01 625 LDA #$01 ; invalid command
|
||
834A: 60 626 RTS
|
||
627
|
||
628
|
||
834B: 40 00 00 629 CMD0 HEX 400000
|
||
834E: 00 00 95 630 HEX 000095
|
||
8351: 41 00 00 631 CMD1 HEX 410000
|
||
8354: 00 00 F9 632 HEX 0000F9
|
||
8357: 48 00 00 633 CMD8 HEX 480000
|
||
835A: 01 AA 87 634 HEX 01AA87
|
||
835D: 50 00 00 635 CMD16 HEX 500000
|
||
8360: 02 00 FF 636 HEX 0200FF
|
||
8363: 77 00 00 637 CMD55 HEX 770000
|
||
8366: 00 00 65 638 HEX 000065
|
||
8369: 69 40 00 639 ACMD4140 HEX 694000
|
||
836C: 00 00 77 640 HEX 000077
|
||
836F: 69 00 00 641 ACMD410 HEX 690000
|
||
8372: 00 00 FF 642 HEX 0000FF
|
||
|
||
|
||
--End assembly, 885 bytes, Errors: 0
|
||
|
||
|
||
Symbol table - alphabetical order:
|
||
|
||
ACMD410 =$836F ACMD4140=$8369 BLOCK =$8238 CMD =$81D7
|
||
CMD0 =$834B CMD1 =$8351 CMD16 =$835D CMD55 =$8363
|
||
CMD8 =$8357 CMDHI =$41 CMDLO =$40 COMMAND =$8264
|
||
CTRL =$C081 CURSLOT =$07F8 DATA =$C080 DEBUG =$01
|
||
DIV =$C082 DRIVER =$805A DUMMY =$FF FORMAT =$8347
|
||
GETR1 =$81EB GETR3 =$8206 INIT =$8100 INSLP =$801F
|
||
INSLP2 =$8038 INSOUT =$8059 R30 =$0478 R31 =$04F8
|
||
R32 =$0578 R33 =$05F8 READ =$82C0 SLOT =$3D
|
||
SLOT16 =$2B SS =$C083 SS0 =$0E SSNONE =$0F
|
||
===== Page 13 =====
|
||
|
||
STATUS =$82B8 WORK =$3C WRITE =$8306
|
||
|
||
|
||
Symbol table - numerical order:
|
||
|
||
DEBUG =$01 SS0 =$0E SSNONE =$0F SLOT16 =$2B
|
||
WORK =$3C SLOT =$3D CMDLO =$40 CMDHI =$41
|
||
DUMMY =$FF R30 =$0478 R31 =$04F8 R32 =$0578
|
||
R33 =$05F8 CURSLOT =$07F8 INSLP =$801F INSLP2 =$8038
|
||
INSOUT =$8059 DRIVER =$805A INIT =$8100 CMD =$81D7
|
||
GETR1 =$81EB GETR3 =$8206 BLOCK =$8238 COMMAND =$8264
|
||
STATUS =$82B8 READ =$82C0 WRITE =$8306 FORMAT =$8347
|
||
CMD0 =$834B CMD1 =$8351 CMD8 =$8357 CMD16 =$835D
|
||
CMD55 =$8363 ACMD4140=$8369 ACMD410 =$836F DATA =$C080
|
||
CTRL =$C081 DIV =$C082 SS =$C083
|
||
|