diff --git a/AppleIISd.bin b/AppleIISd.bin index 3ae11c1..33a4b37 100644 Binary files a/AppleIISd.bin and b/AppleIISd.bin differ diff --git a/AppleIISd.hex b/AppleIISd.hex index 8f8c52d..1113526 100644 --- a/AppleIISd.hex +++ b/AppleIISd.hex @@ -1,129 +1,71 @@ -:10000000D8A9039D81C0BD83C009019D83C0A907F4 -:100010009D82C0A00AA9FF9D80C03C81C010FB88C2 -:10002000D0F5BD83C029FE9D83C0A9C58540A9CA5E -:10003000854120F0C82004C9C901D039A9D1854023 -:10004000A9CA854120F0C8201FC9C901D02AA9DD4D -:100050008540A9CA854120F0C82004C9A9E385408C -:10006000A9CA854120F0C82004C9C901F0E0C9002F -:10007000D0034CB2C84CDEC8A9DD8540A9CA854171 -:1000800020F0C8A9E98540A9CA854120F0C820040C -:10009000C9C901F0E3C900D0034CB2C8A9CB85405F -:1000A000A9CA854120F0C82004C9C901F0F6C900D9 -:1000B000D02CA9D78540A9CA854120F0C82004C901 -:1000C000C900D01ABD83C009809D83C0BD81C0090D -:1000D000049D81C018A000900838A02FB00338A05C -:1000E00027BD83C009019D83C0A9009D82C098607F -:1000F0005AA000B1409D80C03C81C010FBC8C00622 -:1001000090F17A60A9FF9D80C03C81C010FBBD804A -:10011000C0853C2980D0EDA9FF9D80C0A53C602012 -:1001200004C9485AA004A9FF9D80C03C81C010FBAF -:10013000BD80C04888D0EFA43D6899F805689978DB -:10014000056899F804689978047AA9FF9D80C068C9 -:1001500060DA5AA63DA5469DF805A5479D7805A9F4 -:10016000009DF8049D7804A9802443F005A9019D11 -:10017000F804A0091EF8053E78053EF8043E780410 -:1001800088D0F17AFA605AA43D9D80C0B978049D68 -:1001900080C0B9F8049D80C0B978059D80C0B9F8C9 -:1001A000059D80C0A9FF9D80C02004C97A6048A930 -:1001B000403C83C018F00138686048A9203C83C0E7 -:1001C00018F001386860A900A2FFA0FF20AEC99016 -:1001D00004A92F800720BAC99002A92B6020AEC9BC -:1001E000B0642051C9BD83C029FE9D83C0A95120A0 -:1001F00086C9C900D050A9FF9D80C0BD80C0C9FE7E -:10020000D0F4A002BD81C009109D81C0A9FF9D80CE -:10021000C0643CBD80C09244E644D002E645E63C62 -:10022000D0F188D0ECBD80C0BD80C0BD80C0BD8194 -:10023000C029EF9D81C018A9000848BD83C00901ED -:100240009D83C068286038A92780EE20AEC9B067BA -:1002500020BAC9B0672051C9BD83C029FE9D83C0A3 -:10026000A9582086C9C900D04EA9FF9D80C0A9FE0B -:100270009D80C0A002643CB2449D80C0E644D00290 -:10028000E645E63CD0F188D0EC9D80C09D80C09DC5 -:1002900080C0BD80C0291FC905D01C18A90008480E -:1002A000A9FF9D80C0BD80C0C900F0F4BD83C00916 -:1002B000019D83C068286038A92780E238A92B8077 -:1002C000DD38A901604000000000954100000000F9 -:1002D000F948000001AA875000000200FF770000E3 -:1002E0000000656940000000776900000000FF0021 -:1002F00000000000000000000000000000000000FE -:1003000000000000000000000000000000000000ED -:1003100000000000000000000000000000000000DD -:1003200000000000000000000000000000000000CD -:1003300000000000000000000000000000000000BD -:1003400000000000000000000000000000000000AD -:10035000000000000000000000000000000000009D -:10036000000000000000000000000000000000008D -:10037000000000000000000000000000000000007D -:10038000000000000000000000000000000000006D -:10039000000000000000000000000000000000005D -:1003A000000000000000000000000000000000004D -:1003B000000000000000000000000000000000003D -:1003C000000000000000000000000000000000002D -:1003D000000000000000000000000000000000001D -:1003E000000000000000000000000000000000000D -:1003F00000000000000000000000000000000000FD -:1004000000000000000000000000000000000000EC -:1004100000000000000000000000000000000000DC -:1004200000000000000000000000000000000000CC -:1004300000000000000000000000000000000000BC -:1004400000000000000000000000000000000000AC -:10045000000000000000000000000000000000009C -:10046000000000000000000000000000000000008C -:10047000000000000000000000000000000000007C -:10048000000000000000000000000000000000006C -:10049000000000000000000000000000000000005C -:1004A000000000000000000000000000000000004C -:1004B000000000000000000000000000000000003C -:1004C000000000000000000000000000000000002C -:1004D000000000000000000000000000000000001C -:1004E000000000000000000000000000000000000C -:1004F00000000000000000000000000000000000FC -:1005000000000000000000000000000000000000EB -:1005100000000000000000000000000000000000DB -:1005200000000000000000000000000000000000CB -:1005300000000000000000000000000000000000BB -:1005400000000000000000000000000000000000AB -:10055000000000000000000000000000000000009B -:10056000000000000000000000000000000000008B -:10057000000000000000000000000000000000007B -:10058000000000000000000000000000000000006B -:10059000000000000000000000000000000000005B -:1005A000000000000000000000000000000000004B -:1005B000000000000000000000000000000000003B -:1005C000000000000000000000000000000000002B -:1005D000000000000000000000000000000000001B -:1005E000000000000000000000000000000000000B -:1005F00000000000000000000000000000000000FB -:1006000000000000000000000000000000000000EA -:1006100000000000000000000000000000000000DA -:1006200000000000000000000000000000000000CA -:1006300000000000000000000000000000000000BA -:1006400000000000000000000000000000000000AA -:10065000000000000000000000000000000000009A -:10066000000000000000000000000000000000008A -:10067000000000000000000000000000000000007A -:10068000000000000000000000000000000000006A -:10069000000000000000000000000000000000005A -:1006A000000000000000000000000000000000004A -:1006B000000000000000000000000000000000003A -:1006C000000000000000000000000000000000002A -:1006D000000000000000000000000000000000001A -:1006E000000000000000000000000000000000000A -:1006F00000000000000000000000000000000000FA -:10070000A220A000A203A0FF2058FFBABD00018DC7 -:10071000F807290F853D0A0A0A0A852BAA2CFFCF64 -:1007200020AEC99003A927002000C8C900F001002D -:10073000A9018542A62B85436444A90885456446E2 -:1007400064472CFFCF20DDC94C0108D82058FFBAE0 -:10075000BD00018DF807290F853D0A0A0A0A852B7D -:10076000AA2CFFCF20AEC99004A927801BA9803CEA -:1007700083C0F022A542C900F010C901F00FC902E0 -:10078000F00EC903F00DA90138604CC6C94CDDC993 -:100790004C4BCA4CC1CA2000C8B0ED80D700000045 -:1007A0000000000000000000000000000000000049 -:1007B0000000000000000000000000000000000039 -:1007C0000000000000000000000000000000000029 -:1007D0000000000000000000000000000000000019 -:1007E0000000000000000000000000000000000009 -:1007F000000000000000000000000000FFFF174B99 +:10000000A220A000A203A0FF2058FFBABD00018DCE +:10001000F807290F853D0A0A0A0A852BAA2CFFCF6B +:1000200020A9C99003A92F002000C8C900F0010031 +:10003000A9018542A62B85436444A90885456446E9 +:1000400064472CFFCF20CFC94C0108D82058FFBAF5 +:10005000BD00018DF807290F853D0A0A0A0A852B84 +:10006000AA2CFFCF20A9C99004A92F801FA9803CEA +:1000700083C0F029A542C900F014C901F013C902D8 +:10008000F012C903F011C9FFF010A90138604CC18A +:10009000C94CCFC94C38CA4CA9CA4CADCA2000C8FB +:1000A000B0EA80D000000000000000000000000066 +:1000B0000000000000000000000000000000000040 +:1000C0000000000000000000000000000000000030 +:1000D0000000000000000000000000000000000020 +:1000E0000000000000000000000000000000000010 +:1000F000000000000000000000000000FFFF174BA0 +:10010000D8A9039D81C0BD83C009019D83C0A907F3 +:100110009D82C0A00AA9FF9D80C03C81C010FB88C1 +:10012000D0F5BD83C029FE9D83C0A9318540A9CBF0 +:10013000854120EBC820FFC8C901D039A93D8540C1 +:10014000A9CB854120EBC8201AC9C901D02AA949E9 +:100150008540A9CB854120EBC820FFC8A94F854029 +:10016000A9CB854120EBC820FFC8C901F0E0C90038 +:10017000D0034CB2C84CD9C8A9498540A9CB854108 +:1001800020EBC8A9558540A9CB854120EBC820FFAD +:10019000C8C901F0E3C900D0034CB2C8A9378540F3 +:1001A000A9CB854120EBC820FFC8C901F0F6C900E2 +:1001B000D027A9438540A9CB854120EBC820FFC8A3 +:1001C000C900D015BD83C009809D83C0BD81C00911 +:1001D000049D81C018A000900338A027BD83C009EA +:1001E000019D83C0A9009D82C098605AA000B140C3 +:1001F0009D80C03C81C010FBC8C00690F17A60A908 +:10020000FF9D80C03C81C010FBBD80C0853C298023 +:10021000D0EDA9FF9D80C0A53C6020FFC8485AA032 +:1002200004A9FF9D80C03C81C010FBBD80C04888F0 +:10023000D0EFA43D6899F805689978056899F804A5 +:10024000689978047AA9FF9D80C06860DA5AA63D53 +:10025000A5469DF805A5479D7805A9009DF8049D34 +:100260007804A9802443F005A9019DF804A0091E83 +:10027000F8053E78053EF8043E780488D0F17AFA15 +:10028000605AA43D9D80C0B978049D80C0B9F8042F +:100290009D80C0B978059D80C0B9F8059D80C0A932 +:1002A000FF9D80C020FFC87A6048A9403C83C018E9 +:1002B000F00138686048A9203C83C018F001386814 +:1002C00060A900A2FFA0FF20B5C99002A92B602061 +:1002D0004CC9BD83C029FE9D83C0A9512081C9C9D5 +:1002E00000D050A9FF9D80C0BD80C0C9FED0F4A041 +:1002F00002BD81C009109D81C0A9FF9D80C0643CE2 +:10030000BD80C09244E644D002E645E63CD0F18888 +:10031000D0ECBD80C0BD80C0BD80C0BD81C029EF14 +:100320009D81C018A9000848BD83C009019D83C0F4 +:1003300068286038A92780EE20B5C9B067204CC96D +:10034000BD83C029FE9D83C0A9582081C9C900D0A2 +:100350004EA9FF9D80C0A9FE9D80C0A002643CB252 +:10036000449D80C0E644D002E645E63CD0F188D00A +:10037000EC9D80C09D80C09D80C0BD80C0291FC9EC +:1003800005D01C18A9000848A9FF9D80C0BD80C0E9 +:10039000C900F0F4BD83C009019D83C0682860389E +:1003A000A92780E238A92B80DD38A90160A43DA9E6 +:1003B0000220F5BEB07999F8068545A9009978061E +:1003C0008544A000989144C8D0FAE645989144C865 +:1003D000D0FAA902A43D8542AD78068544B9F80655 +:1003E000854564466447A62B204BC7B042A901A4AB +:1003F0003D8542B978068544B9F80685456446646A +:1004000047A62B204BC7B027A43DB978068544B931 +:10041000F8068545A00098D144D015C8D0F8E64527 +:1004200098D144D00BC8D0F820F8BE18A9006000BD +:10043000004000000000954100000000F948000065 +:1004400001AA875000000200FF77000000006569E4 +:0B04500040000000776900000000FF82 :00000001FF diff --git a/AppleIISd.lst b/AppleIISd.lst index de5a9c6..8f6b4eb 100644 --- a/AppleIISd.lst +++ b/AppleIISd.lst @@ -10,14 +10,14 @@ 10 * 11 ******************************** 12 - 16-OCT-17 23:58 + 22-OCT-17 20:21 14 15 XC ; enable 65C02 code 16 DEBUG = 0 17 DO DEBUG 18 ORG $8000 19 ELSE - 20 ORG $C800 ; Expansion ROM + 20 ORG $C700 ; Expansion ROM 21 FIN 22 23 * Memory defines @@ -41,1151 +41,859 @@ 41 R31 = $04F8 42 R32 = $0578 43 R33 = $05F8 - 44 - 45 * Constants + 44 RAM0 = $0678 + 45 RAM1 = $06F8 46 - 47 DUMMY = $FF - 48 FRX = $10 ; CTRL register - 49 ECE = $04 - 50 SS0 = $01 ; SS register - 51 WP = $20 - 52 CD = $40 - 53 INITED = $80 - 54 - 55 - 56 ******************************** - 57 * - 58 * Initialize SD card - 59 * - 60 * C Clear - No error - 61 * Set - Error - 62 * A $00 - No error - 63 * $27 - I/O error - Init failed - 64 * $2F - No card inserted - 65 * - 66 ******************************** - 67 -C800: D8 68 INIT CLD -C801: A9 03 69 LDA #$03 ; set SPI mode 3 -C803: 9D 81 C0 70 STA CTRL,X -C806: BD 83 C0 71 LDA SS,X -C809: 09 01 72 ORA #SS0 ; set CS high -C80B: 9D 83 C0 73 STA SS,X -C80E: A9 07 74 LDA #7 -C810: 9D 82 C0 75 STA DIV,X -C813: A0 0A 76 LDY #10 -C815: A9 FF 77 LDA #DUMMY - 78 -C817: 9D 80 C0 79 :LOOP STA DATA,X -C81A: 3C 81 C0 80 :WAIT BIT CTRL,X -C81D: 10 FB 81 BPL :WAIT -C81F: 88 82 DEY -C820: D0 F5 83 BNE :LOOP ; do 10 times -C822: BD 83 C0 84 LDA SS,X -C825: 29 FE 85 AND #$FF!SS0 ; set CS low -C827: 9D 83 C0 86 STA SS,X - 87 -C82A: A9 C5 88 LDA #CMD0 -C830: 85 41 91 STA CMDHI -C832: 20 F0 C8 92 JSR CMD -C835: 20 04 C9 93 JSR GETR1 ; get response -C838: C9 01 94 CMP #$01 -C83A: D0 39 95 BNE :ERROR1 ; error! + 47 * Constants + 48 + 49 DUMMY = $FF + 50 FRX = $10 ; CTRL register + 51 ECE = $04 + 52 SS0 = $01 ; SS register + 53 WP = $20 + 54 CD = $40 + 55 INITED = $80 + 56 + 57 + 58 * signature bytes + 59 +C700: A2 20 60 LDX #$20 +C702: A0 00 61 LDY #$00 +C704: A2 03 62 LDX #$03 +C706: A0 FF 63 LDY #$FF ; neither 5.25 nor Smartport + 64 + 65 * find slot nr + 66 + 67 DO DEBUG + 68 LDA #$04 + 69 STA SLOT + 70 LDA #$C4 + 71 STA CURSLOT + 72 LDA #$40 + 73 + 74 ELSE +C708: 20 58 FF 75 JSR $FF58 +C70B: BA 76 TSX +C70C: BD 00 01 77 LDA $0100,X +C70F: 8D F8 07 78 STA CURSLOT ; $Cs +C712: 29 0F 79 AND #$0F +C714: 85 3D 80 STA SLOT ; $0s +C716: 0A 81 ASL A +C717: 0A 82 ASL A +C718: 0A 83 ASL A +C719: 0A 84 ASL A + 85 FIN + 86 +C71A: 85 2B 87 STA SLOT16 ; $s0 +C71C: AA 88 TAX ; X holds now SLOT16 +C71D: 2C FF CF 89 BIT $CFFF +C720: 20 A9 C9 90 JSR CARDDET +C723: 90 03 91 BCC :INIT +C725: A9 2F 92 LDA #$2F ; no card inserted +C727: 00 93 BRK + 94 +C728: 20 00 C8 95 :INIT JSR INIT 96 -C83C: A9 D1 97 LDA #CMD8 -C842: 85 41 100 STA CMDHI -C844: 20 F0 C8 101 JSR CMD -C847: 20 1F C9 102 JSR GETR3 -C84A: C9 01 103 CMP #$01 -C84C: D0 2A 104 BNE :SDV1 ; may be SD Ver. 1 + 97 + 98 ******************************** + 99 * + 100 * Install SD card driver + 101 * + 102 ******************************** + 103 + 104 DO DEBUG 105 - 106 * check for $01aa match! -C84E: A9 DD 107 :SDV2 LDA #CMD55 -C854: 85 41 110 STA CMDHI -C856: 20 F0 C8 111 JSR CMD -C859: 20 04 C9 112 JSR GETR1 -C85C: A9 E3 113 LDA #ACMD4140 -C862: 85 41 116 STA CMDHI -C864: 20 F0 C8 117 JSR CMD -C867: 20 04 C9 118 JSR GETR1 -C86A: C9 01 119 CMP #$01 -C86C: F0 E0 120 BEQ :SDV2 ; wait for ready -C86E: C9 00 121 CMP #$00 -C870: D0 03 122 BNE :ERROR1 ; error! - 123 * send CMD58 - 124 * SD Ver. 2 initialized! -C872: 4C B2 C8 125 JMP :BLOCKSZ - 126 -C875: 4C DE C8 127 :ERROR1 JMP :IOERROR ; needed for far jump - 128 -C878: A9 DD 129 :SDV1 LDA #CMD55 -C87E: 85 41 132 STA CMDHI -C880: 20 F0 C8 133 JSR CMD ; ignore response -C883: A9 E9 134 LDA #ACMD410 -C889: 85 41 137 STA CMDHI -C88B: 20 F0 C8 138 JSR CMD -C88E: 20 04 C9 139 JSR GETR1 -C891: C9 01 140 CMP #$01 -C893: F0 E3 141 BEQ :SDV1 ; wait for ready -C895: C9 00 142 CMP #$00 -C897: D0 03 143 BNE :MMC ; may be MMC card - 144 * SD Ver. 1 initialized! -C899: 4C B2 C8 145 JMP :BLOCKSZ - 146 -C89C: A9 CB 147 :MMC LDA #CMD1 -C8A2: 85 41 150 STA CMDHI -C8A4: 20 F0 C8 151 :LOOP1 JSR CMD -C8A7: 20 04 C9 152 JSR GETR1 -C8AA: C9 01 153 CMP #$01 -C8AC: F0 F6 154 BEQ :LOOP1 ; wait for ready -C8AE: C9 00 155 CMP #$00 -C8B0: D0 2C 156 BNE :IOERROR ; error! - 157 * MMC Ver. 3 initialized! - 158 -C8B2: A9 D7 159 :BLOCKSZ LDA #CMD16 -C8B8: 85 41 162 STA CMDHI -C8BA: 20 F0 C8 163 JSR CMD -C8BD: 20 04 C9 164 JSR GETR1 -C8C0: C9 00 165 CMP #$00 -C8C2: D0 1A 166 BNE :IOERROR ; error! - 167 -C8C4: BD 83 C0 168 :END LDA SS,X -C8C7: 09 80 169 ORA #INITED ; initialized -C8C9: 9D 83 C0 170 STA SS,X -C8CC: BD 81 C0 171 LDA CTRL,X -C8CF: 09 04 172 ORA #ECE ; enable 7MHz -C8D1: 9D 81 C0 173 STA CTRL,X -C8D4: 18 174 CLC ; all ok -C8D5: A0 00 175 LDY #0 -C8D7: 90 08 176 BCC :END1 -C8D9: 38 177 :CDERROR SEC -C8DA: A0 2F 178 LDY #$2F ; no card error -C8DC: B0 03 179 BCS :END1 -C8DE: 38 180 :IOERROR SEC -C8DF: A0 27 181 LDY #$27 ; init error -C8E1: BD 83 C0 182 :END1 LDA SS,X ; set CS high -C8E4: 09 01 183 ORA #SS0 -C8E6: 9D 83 C0 184 STA SS,X -C8E9: A9 00 185 LDA #0 ; set div to 2 -C8EB: 9D 82 C0 186 STA DIV,X -C8EE: 98 187 TYA ; retval in A -C8EF: 60 188 RTS - 189 - 190 - 191 ******************************** - 192 * - 193 * Send SD command - 194 * Call with command in CMDHI and CMDLO - 195 * - 196 ******************************** - 197 -C8F0: 5A 198 CMD PHY -C8F1: A0 00 199 LDY #0 -C8F3: B1 40 200 :LOOP LDA (CMDLO),Y -C8F5: 9D 80 C0 201 STA DATA,X -C8F8: 3C 81 C0 202 :WAIT BIT CTRL,X ; TC is in N -C8FB: 10 FB 203 BPL :WAIT -C8FD: C8 204 INY -C8FE: C0 06 205 CPY #6 -C900: 90 F1 206 BCC :LOOP -C902: 7A 207 PLY -C903: 60 208 RTS + 106 * see if slot has a driver already + 107 + 108 LDX $BF31 ; get devcnt + 109 INSTALL LDA $BF32,X ; get a devnum + 110 AND #$70 ; isolate slot + 111 CMP SLOT16 ; slot? + 112 BEQ :INSOUT ; yes, skip it + 113 DEX + 114 BPL INSTALL ; keep up the search + 115 + 116 * restore the devnum to the list + 117 + 118 LDX $BF31 ; get devcnt again + 119 CPX #$0D ; device table full? + 120 BNE :INST2 + 121 + 122 JSR $FF3A ; bell + 123 JMP :INSOUT ; do something! + 124 + 125 :INST2 LDA $BF32-1,X ; move all entries down + 126 STA $BF32,X ; to make room at front + 127 DEX ; for a new entry + 128 BNE :INST2 + 129 LDA #$04 ; ProFile type device + 130 ORA SLOT16 + 131 STA $BF32 ; slot, drive 1 at top of list + 132 INC $BF31 ; update devcnt + 133 + 134 * now insert the device driver vector + 135 + 136 LDA SLOT + 137 ASL + 138 TAX + 139 LDA #DRIVER + 142 STA $BF11,X + 143 :INSOUT RTS + 144 + 145 + 146 ******************************** + 147 * + 148 * Boot from SD card + 149 * + 150 ******************************** + 151 + 152 ELSE + 153 +C72B: C9 00 154 BOOT CMP #0 ; check for error +C72D: F0 01 155 BEQ :BOOT1 +C72F: 00 156 BRK + 157 +C730: A9 01 158 :BOOT1 LDA #$01 +C732: 85 42 159 STA DCMD ; load command +C734: A6 2B 160 LDX SLOT16 +C736: 85 43 161 STA $43 ; slot number +C738: 64 44 162 STZ BUFFER ; buffer lo +C73A: A9 08 163 LDA #$08 +C73C: 85 45 164 STA BUFFER+1 ; buffer hi +C73E: 64 46 165 STZ BLOCK ; block lo +C740: 64 47 166 STZ BLOCK+1 ; block hi +C742: 2C FF CF 167 BIT $CFFF +C745: 20 CF C9 168 JSR READ ; call driver +C748: 4C 01 08 169 JMP $801 ; goto bootloader + 170 + 171 FIN + 172 + 173 + 174 ******************************** + 175 * + 176 * Jump table + 177 * + 178 ******************************** + 179 +C74B: D8 180 DRIVER CLD + 181 + 182 DO DEBUG + 183 LDA #$04 + 184 STA SLOT + 185 LDA #$C4 + 186 STA CURSLOT + 187 LDA #$40 + 188 + 189 ELSE +C74C: 20 58 FF 190 JSR $FF58 ; find slot nr +C74F: BA 191 TSX +C750: BD 00 01 192 LDA $0100,X +C753: 8D F8 07 193 STA CURSLOT ; $Cs +C756: 29 0F 194 AND #$0F +C758: 85 3D 195 STA SLOT ; $0s +C75A: 0A 196 ASL A +C75B: 0A 197 ASL A +C75C: 0A 198 ASL A +C75D: 0A 199 ASL A + 200 FIN + 201 +C75E: 85 2B 202 STA SLOT16 ; $s0 +C760: AA 203 TAX ; X holds now SLOT16 +C761: 2C FF CF 204 BIT $CFFF +C764: 20 A9 C9 205 JSR CARDDET +C767: 90 04 206 BCC :INITED +C769: A9 2F 207 LDA #$2F ; no card inserted +C76B: 80 1F 208 BRA :DONE 209 - 210 - 211 ******************************** - 212 * - 213 * Get R1 - 214 * R1 is in A - 215 * - 216 ******************************** - 217 -C904: A9 FF 218 GETR1 LDA #DUMMY -C906: 9D 80 C0 219 STA DATA,X -C909: 3C 81 C0 220 :WAIT BIT CTRL,X -C90C: 10 FB 221 BPL :WAIT -C90E: BD 80 C0 222 LDA DATA,X ; get response -C911: 85 3C 223 STA WORK ; save R1 -C913: 29 80 224 AND #$80 -C915: D0 ED 225 BNE GETR1 ; wait for MSB=0 -C917: A9 FF 226 LDA #DUMMY -C919: 9D 80 C0 227 STA DATA,X ; send another dummy -C91C: A5 3C 228 LDA WORK ; restore R1 -C91E: 60 229 RTS - 230 - 231 - 232 ******************************** - 233 * - 234 * Get R3 - 235 * R1 is in A - 236 * R3 is in scratchpad ram - 237 * - 238 ******************************** +C76D: A9 80 210 :INITED LDA #INITED ; check for init +C76F: 3C 83 C0 211 BIT SS,X +C772: F0 29 212 BEQ :INIT + 213 +C774: A5 42 214 :CMD LDA DCMD ; get command +C776: C9 00 215 CMP #0 +C778: F0 14 216 BEQ :STATUS +C77A: C9 01 217 CMP #1 +C77C: F0 13 218 BEQ :READ +C77E: C9 02 219 CMP #2 +C780: F0 12 220 BEQ :WRITE +C782: C9 03 221 CMP #3 +C784: F0 11 222 BEQ :FORMAT +C786: C9 FF 223 CMP #$FF +C788: F0 10 224 BEQ :TEST +C78A: A9 01 225 LDA #1 ; unknown command + 226 +C78C: 38 227 :DONE SEC +C78D: 60 228 RTS + 229 +C78E: 4C C1 C9 230 :STATUS JMP STATUS +C791: 4C CF C9 231 :READ JMP READ +C794: 4C 38 CA 232 :WRITE JMP WRITE +C797: 4C A9 CA 233 :FORMAT JMP FORMAT +C79A: 4C AD CA 234 :TEST JMP TEST ; do device test +C79D: 20 00 C8 235 :INIT JSR INIT +C7A0: B0 EA 236 BCS :DONE ; init failure +C7A2: 80 D0 237 BRA :CMD + 238 239 -C91F: 20 04 C9 240 GETR3 JSR GETR1 ; get R1 first -C922: 48 241 PHA ; save R1 -C923: 5A 242 PHY ; save Y -C924: A0 04 243 LDY #04 ; load counter -C926: A9 FF 244 :LOOP LDA #DUMMY ; send dummy -C928: 9D 80 C0 245 STA DATA,X -C92B: 3C 81 C0 246 :WAIT BIT CTRL,X -C92E: 10 FB 247 BPL :WAIT -C930: BD 80 C0 248 LDA DATA,X -C933: 48 249 PHA -C934: 88 250 DEY -C935: D0 EF 251 BNE :LOOP ; do 4 times -C937: A4 3D 252 LDY SLOT -C939: 68 253 PLA -C93A: 99 F8 05 254 STA R33,Y ; save R3 -C93D: 68 255 PLA -C93E: 99 78 05 256 STA R32,Y -C941: 68 257 PLA -C942: 99 F8 04 258 STA R31,Y -C945: 68 259 PLA -C946: 99 78 04 260 STA R30,Y -C949: 7A 261 PLY ; restore Y -C94A: A9 FF 262 LDA #DUMMY -C94C: 9D 80 C0 263 STA DATA,X ; send another dummy -C94F: 68 264 PLA ; restore R1 -C950: 60 265 RTS - 266 - 267 - 268 ******************************** - 269 * - 270 * Calculate block address - 271 * Unit number is in $43 DSSS0000 - 272 * Block no is in $46-47 - 273 * Address is in R30-R33 - 274 * - 275 ******************************** - 276 -C951: DA 277 GETBLOCK PHX ; save X -C952: 5A 278 PHY ; save Y -C953: A6 3D 279 LDX SLOT -C955: A5 46 280 LDA BLOCK ; store block num -C957: 9D F8 05 281 STA R33,X ; in R30-R33 -C95A: A5 47 282 LDA BLOCK+1 -C95C: 9D 78 05 283 STA R32,X -C95F: A9 00 284 LDA #0 -C961: 9D F8 04 285 STA R31,X -C964: 9D 78 04 286 STA R30,X - 287 -C967: A9 80 288 LDA #$80 ; drive number -C969: 24 43 289 BIT $43 -C96B: F0 05 290 BEQ :SHIFT ; D1 -C96D: A9 01 291 LDA #1 ; D2 -C96F: 9D F8 04 292 STA R31,X - 293 -C972: A0 09 294 :SHIFT LDY #9 ; ASL can't be used with Y -C974: 1E F8 05 295 :LOOP ASL R33,X ; mul block num -C977: 3E 78 05 296 ROL R32,X ; by 512 to get -C97A: 3E F8 04 297 ROL R31,X ; real address -C97D: 3E 78 04 298 ROL R30,X -C980: 88 299 DEY -C981: D0 F1 300 BNE :LOOP -C983: 7A 301 PLY ; restore Y -C984: FA 302 PLX ; restore X -C985: 60 303 RTS - 304 - 305 - 306 ******************************** - 307 * - 308 * Send SD command - 309 * Cmd is in A - 310 * - 311 ******************************** - 312 -C986: 5A 313 COMMAND PHY ; save Y -C987: A4 3D 314 LDY SLOT -C989: 9D 80 C0 315 STA DATA,X ; send command -C98C: B9 78 04 316 LDA R30,Y ; get arg from R30 on -C98F: 9D 80 C0 317 STA DATA,X -C992: B9 F8 04 318 LDA R31,Y -C995: 9D 80 C0 319 STA DATA,X -C998: B9 78 05 320 LDA R32,Y -C99B: 9D 80 C0 321 STA DATA,X -C99E: B9 F8 05 322 LDA R33,Y -C9A1: 9D 80 C0 323 STA DATA,X -C9A4: A9 FF 324 LDA #DUMMY -C9A6: 9D 80 C0 325 STA DATA,X ; dummy crc -C9A9: 20 04 C9 326 JSR GETR1 -C9AC: 7A 327 PLY ; restore Y -C9AD: 60 328 RTS - 329 - 330 - 331 ******************************** - 332 * - 333 * Check for card detect - 334 * - 335 * C Clear - card in slot - 336 * Set - no card in slot - 337 * - 338 ******************************** - 339 -C9AE: 48 340 CARDDET PHA -C9AF: A9 40 341 LDA #CD ; 0: card in -C9B1: 3C 83 C0 342 BIT SS,X ; 1: card out -C9B4: 18 343 CLC -C9B5: F0 01 344 BEQ :DONE ; card is in -C9B7: 38 345 SEC ; card is out -C9B8: 68 346 :DONE PLA -C9B9: 60 347 RTS - 348 - 349 - 350 ******************************** - 351 * - 352 * Check for write protect - 353 * - 354 * C Clear - card not protected - 355 * Set - card write protected - 356 * - 357 ******************************** - 358 -C9BA: 48 359 WRPROT PHA -C9BB: A9 20 360 LDA #WP ; 0: write enabled -C9BD: 3C 83 C0 361 BIT SS,X ; 1: write disabled -C9C0: 18 362 CLC -C9C1: F0 01 363 BEQ :DONE -C9C3: 38 364 SEC -C9C4: 68 365 :DONE PLA -C9C5: 60 366 RTS - 367 - 368 - 369 ******************************** - 370 * - 371 * Status request - 372 * $43 Unit number DSSS000 - 373 * $44-45 Unused - 374 * $46-47 Unused - 375 * - 376 * C Clear - No error - 377 * Set - Error - 378 * A $00 - No error - 379 * $2B - Card write protected - 380 * $2F - No card inserted - 381 * X - Blocks avail (low byte) - 382 * Y - Blocks avail (high byte) - 383 * - 384 ******************************** - 385 -C9C6: A9 00 386 STATUS LDA #0 ; no error -C9C8: A2 FF 387 LDX #$FF ; 32 MB partition -C9CA: A0 FF 388 LDY #$FF - 389 -C9CC: 20 AE C9 390 JSR CARDDET -C9CF: 90 04 391 BCC :WRPROT -C9D1: A9 2F 392 LDA #$2F ; no card inserted -C9D3: 80 07 393 BRA :DONE - 394 -C9D5: 20 BA C9 395 :WRPROT JSR WRPROT -C9D8: 90 02 396 BCC :DONE -C9DA: A9 2B 397 LDA #$2B ; card write protected + 240 * Signature bytes + 241 +C7A4: 00 00 00 242 DS \ ; fill with zeroes +C7A7: 00 00 00 00 +C7AB: 00 00 00 00 +C7AF: 00 00 00 00 +C7B3: 00 00 00 00 +C7B7: 00 00 00 00 +C7BB: 00 00 00 00 +C7BF: 00 00 00 00 +C7C3: 00 00 00 00 +C7C7: 00 00 00 00 +C7CB: 00 00 00 00 +C7CF: 00 00 00 00 +C7D3: 00 00 00 00 +C7D7: 00 00 00 00 +C7DB: 00 00 00 00 +C7DF: 00 00 00 00 +C7E3: 00 00 00 00 +C7E7: 00 00 00 00 +C7EB: 00 00 00 00 +C7EF: 00 00 00 00 +C7F3: 00 00 00 00 +C7F7: 00 00 00 00 +C7FB: 00 00 00 00 +C7FF: 00 + 243 DS -4 ; locate to $xxFC +C7FC: FF FF 244 DW $FFFF ; 65535 blocks +C7FE: 17 245 DB $17 ; Status bits +C7FF: 4B 246 DB #CMD0 +C830: 85 41 283 STA CMDHI +C832: 20 EB C8 284 JSR CMD +C835: 20 FF C8 285 JSR GETR1 ; get response +C838: C9 01 286 CMP #$01 +C83A: D0 39 287 BNE :ERROR1 ; error! + 288 +C83C: A9 3D 289 LDA #CMD8 +C842: 85 41 292 STA CMDHI +C844: 20 EB C8 293 JSR CMD +C847: 20 1A C9 294 JSR GETR3 +C84A: C9 01 295 CMP #$01 +C84C: D0 2A 296 BNE :SDV1 ; may be SD Ver. 1 + 297 + 298 * check for $01aa match! +C84E: A9 49 299 :SDV2 LDA #CMD55 +C854: 85 41 302 STA CMDHI +C856: 20 EB C8 303 JSR CMD +C859: 20 FF C8 304 JSR GETR1 +C85C: A9 4F 305 LDA #ACMD4140 +C862: 85 41 308 STA CMDHI +C864: 20 EB C8 309 JSR CMD +C867: 20 FF C8 310 JSR GETR1 +C86A: C9 01 311 CMP #$01 +C86C: F0 E0 312 BEQ :SDV2 ; wait for ready +C86E: C9 00 313 CMP #$00 +C870: D0 03 314 BNE :ERROR1 ; error! + 315 * send CMD58 + 316 * SD Ver. 2 initialized! +C872: 4C B2 C8 317 JMP :BLOCKSZ + 318 +C875: 4C D9 C8 319 :ERROR1 JMP :IOERROR ; needed for far jump + 320 +C878: A9 49 321 :SDV1 LDA #CMD55 +C87E: 85 41 324 STA CMDHI +C880: 20 EB C8 325 JSR CMD ; ignore response +C883: A9 55 326 LDA #ACMD410 +C889: 85 41 329 STA CMDHI +C88B: 20 EB C8 330 JSR CMD +C88E: 20 FF C8 331 JSR GETR1 +C891: C9 01 332 CMP #$01 +C893: F0 E3 333 BEQ :SDV1 ; wait for ready +C895: C9 00 334 CMP #$00 +C897: D0 03 335 BNE :MMC ; may be MMC card + 336 * SD Ver. 1 initialized! +C899: 4C B2 C8 337 JMP :BLOCKSZ + 338 +C89C: A9 37 339 :MMC LDA #CMD1 +C8A2: 85 41 342 STA CMDHI +C8A4: 20 EB C8 343 :LOOP1 JSR CMD +C8A7: 20 FF C8 344 JSR GETR1 +C8AA: C9 01 345 CMP #$01 +C8AC: F0 F6 346 BEQ :LOOP1 ; wait for ready +C8AE: C9 00 347 CMP #$00 +C8B0: D0 27 348 BNE :IOERROR ; error! + 349 * MMC Ver. 3 initialized! + 350 +C8B2: A9 43 351 :BLOCKSZ LDA #CMD16 +C8B8: 85 41 354 STA CMDHI +C8BA: 20 EB C8 355 JSR CMD +C8BD: 20 FF C8 356 JSR GETR1 +C8C0: C9 00 357 CMP #$00 +C8C2: D0 15 358 BNE :IOERROR ; error! + 359 +C8C4: BD 83 C0 360 :END LDA SS,X +C8C7: 09 80 361 ORA #INITED ; initialized +C8C9: 9D 83 C0 362 STA SS,X +C8CC: BD 81 C0 363 LDA CTRL,X +C8CF: 09 04 364 ORA #ECE ; enable 7MHz +C8D1: 9D 81 C0 365 STA CTRL,X +C8D4: 18 366 CLC ; all ok +C8D5: A0 00 367 LDY #0 +C8D7: 90 03 368 BCC :END1 +C8D9: 38 369 :IOERROR SEC +C8DA: A0 27 370 LDY #$27 ; init error +C8DC: BD 83 C0 371 :END1 LDA SS,X ; set CS high +C8DF: 09 01 372 ORA #SS0 +C8E1: 9D 83 C0 373 STA SS,X +C8E4: A9 00 374 LDA #0 ; set div to 2 +C8E6: 9D 82 C0 375 STA DIV,X +C8E9: 98 376 TYA ; retval in A +C8EA: 60 377 RTS + 378 + 379 + 380 ******************************** + 381 * + 382 * Send SD command + 383 * Call with command in CMDHI and CMDLO + 384 * + 385 ******************************** + 386 +C8EB: 5A 387 CMD PHY +C8EC: A0 00 388 LDY #0 +C8EE: B1 40 389 :LOOP LDA (CMDLO),Y +C8F0: 9D 80 C0 390 STA DATA,X +C8F3: 3C 81 C0 391 :WAIT BIT CTRL,X ; TC is in N +C8F6: 10 FB 392 BPL :WAIT +C8F8: C8 393 INY +C8F9: C0 06 394 CPY #6 +C8FB: 90 F1 395 BCC :LOOP +C8FD: 7A 396 PLY +C8FE: 60 397 RTS 398 -C9DC: 60 399 :DONE RTS - 400 - 401 - 402 ******************************** - 403 * - 404 * Read 512 byte block - 405 * $43 Unit number DSSS0000 - 406 * $44-45 Address (LO/HI) of buffer - 407 * $46-47 Block number (LO/HI) - 408 * - 409 * C Clear - No error - 410 * Set - Error - 411 * A $00 - No error - 412 * $27 - Bad block number - 413 * $28 - No card inserted - 414 * - 415 ******************************** - 416 -C9DD: 20 AE C9 417 READ JSR CARDDET -C9E0: B0 64 418 BCS :ERROR ; no card inserted + 399 + 400 ******************************** + 401 * + 402 * Get R1 + 403 * R1 is in A + 404 * + 405 ******************************** + 406 +C8FF: A9 FF 407 GETR1 LDA #DUMMY +C901: 9D 80 C0 408 STA DATA,X +C904: 3C 81 C0 409 :WAIT BIT CTRL,X +C907: 10 FB 410 BPL :WAIT +C909: BD 80 C0 411 LDA DATA,X ; get response +C90C: 85 3C 412 STA WORK ; save R1 +C90E: 29 80 413 AND #$80 +C910: D0 ED 414 BNE GETR1 ; wait for MSB=0 +C912: A9 FF 415 LDA #DUMMY +C914: 9D 80 C0 416 STA DATA,X ; send another dummy +C917: A5 3C 417 LDA WORK ; restore R1 +C919: 60 418 RTS 419 -C9E2: 20 51 C9 420 JSR GETBLOCK ; calc block address - 421 -C9E5: BD 83 C0 422 LDA SS,X ; enable /CS -C9E8: 29 FE 423 AND #$FF!SS0 -C9EA: 9D 83 C0 424 STA SS,X -C9ED: A9 51 425 LDA #$51 ; send CMD17 -C9EF: 20 86 C9 426 JSR COMMAND ; send command - 427 -C9F2: C9 00 428 CMP #0 ; check for error -C9F4: D0 50 429 BNE :ERROR - 430 -C9F6: A9 FF 431 :GETTOK LDA #DUMMY ; get data token -C9F8: 9D 80 C0 432 STA DATA,X -C9FB: BD 80 C0 433 LDA DATA,X ; get response -C9FE: C9 FE 434 CMP #$FE -CA00: D0 F4 435 BNE :GETTOK ; wait for $FE - 436 -CA02: A0 02 437 LDY #2 ; read data from card -CA04: BD 81 C0 438 LDA CTRL,X ; enable FRX -CA07: 09 10 439 ORA #FRX -CA09: 9D 81 C0 440 STA CTRL,X -CA0C: A9 FF 441 LDA #DUMMY -CA0E: 9D 80 C0 442 STA DATA,X -CA11: 64 3C 443 :LOOPY STZ WORK -CA13: BD 80 C0 444 :LOOPW LDA DATA,X -CA16: 92 44 445 STA (BUFFER) -CA18: E6 44 446 INC BUFFER -CA1A: D0 02 447 BNE :INW -CA1C: E6 45 448 INC BUFFER+1 ; inc msb on page boundary -CA1E: E6 3C 449 :INW INC WORK -CA20: D0 F1 450 BNE :LOOPW -CA22: 88 451 DEY -CA23: D0 EC 452 BNE :LOOPY - 453 -CA25: BD 80 C0 454 :CRC LDA DATA,X ; read two bytes crc -CA28: BD 80 C0 455 LDA DATA,X ; and ignore -CA2B: BD 80 C0 456 LDA DATA,X ; read a dummy byte - 457 -CA2E: BD 81 C0 458 LDA CTRL,X ; disable FRX -CA31: 29 EF 459 AND #$FF!FRX -CA33: 9D 81 C0 460 STA CTRL,X -CA36: 18 461 CLC ; no error -CA37: A9 00 462 LDA #0 - 463 -CA39: 08 464 :DONE PHP -CA3A: 48 465 PHA -CA3B: BD 83 C0 466 LDA SS,X -CA3E: 09 01 467 ORA #SS0 -CA40: 9D 83 C0 468 STA SS,X ; disable /CS -CA43: 68 469 PLA -CA44: 28 470 PLP -CA45: 60 471 RTS - 472 -CA46: 38 473 :ERROR SEC ; an error occured -CA47: A9 27 474 LDA #$27 -CA49: 80 EE 475 BRA :DONE + 420 + 421 ******************************** + 422 * + 423 * Get R3 + 424 * R1 is in A + 425 * R3 is in scratchpad ram + 426 * + 427 ******************************** + 428 +C91A: 20 FF C8 429 GETR3 JSR GETR1 ; get R1 first +C91D: 48 430 PHA ; save R1 +C91E: 5A 431 PHY ; save Y +C91F: A0 04 432 LDY #04 ; load counter +C921: A9 FF 433 :LOOP LDA #DUMMY ; send dummy +C923: 9D 80 C0 434 STA DATA,X +C926: 3C 81 C0 435 :WAIT BIT CTRL,X +C929: 10 FB 436 BPL :WAIT +C92B: BD 80 C0 437 LDA DATA,X +C92E: 48 438 PHA +C92F: 88 439 DEY +C930: D0 EF 440 BNE :LOOP ; do 4 times +C932: A4 3D 441 LDY SLOT +C934: 68 442 PLA +C935: 99 F8 05 443 STA R33,Y ; save R3 +C938: 68 444 PLA +C939: 99 78 05 445 STA R32,Y +C93C: 68 446 PLA +C93D: 99 F8 04 447 STA R31,Y +C940: 68 448 PLA +C941: 99 78 04 449 STA R30,Y +C944: 7A 450 PLY ; restore Y +C945: A9 FF 451 LDA #DUMMY +C947: 9D 80 C0 452 STA DATA,X ; send another dummy +C94A: 68 453 PLA ; restore R1 +C94B: 60 454 RTS + 455 + 456 + 457 ******************************** + 458 * + 459 * Calculate block address + 460 * Unit number is in $43 DSSS0000 + 461 * Block no is in $46-47 + 462 * Address is in R30-R33 + 463 * + 464 ******************************** + 465 +C94C: DA 466 GETBLOCK PHX ; save X +C94D: 5A 467 PHY ; save Y +C94E: A6 3D 468 LDX SLOT +C950: A5 46 469 LDA BLOCK ; store block num +C952: 9D F8 05 470 STA R33,X ; in R30-R33 +C955: A5 47 471 LDA BLOCK+1 +C957: 9D 78 05 472 STA R32,X +C95A: A9 00 473 LDA #0 +C95C: 9D F8 04 474 STA R31,X +C95F: 9D 78 04 475 STA R30,X 476 - 477 - 478 ******************************** - 479 * - 480 * Write 512 byte block - 481 * $43 Unit number DSSS0000 - 482 * $44-45 Address (LO/HI) of buffer - 483 * $46-47 Block number (LO/HI) - 484 * - 485 * C Clear - No error - 486 * Set - Error - 487 * A $00 - No error - 488 * $27 - I/O error or bad block number - 489 * $2B - Card write protected - 490 * - 491 ******************************** - 492 -CA4B: 20 AE C9 493 WRITE JSR CARDDET -CA4E: B0 67 494 BCS :IOERROR ; no card inserted - 495 -CA50: 20 BA C9 496 JSR WRPROT -CA53: B0 67 497 BCS :WPERROR ; card write protected - 498 -CA55: 20 51 C9 499 JSR GETBLOCK ; calc block address - 500 -CA58: BD 83 C0 501 LDA SS,X ; enable /CS -CA5B: 29 FE 502 AND #$FF!SS0 -CA5D: 9D 83 C0 503 STA SS,X -CA60: A9 58 504 LDA #$58 ; send CMD24 -CA62: 20 86 C9 505 JSR COMMAND ; send command - 506 -CA65: C9 00 507 CMP #0 ; check for error -CA67: D0 4E 508 BNE :IOERROR - 509 -CA69: A9 FF 510 LDA #DUMMY -CA6B: 9D 80 C0 511 STA DATA,X ; send dummy -CA6E: A9 FE 512 LDA #$FE -CA70: 9D 80 C0 513 STA DATA,X ; send data token - 514 -CA73: A0 02 515 LDY #2 ; send data to card -CA75: 64 3C 516 :LOOPY STZ WORK -CA77: B2 44 517 :LOOPW LDA (BUFFER) -CA79: 9D 80 C0 518 STA DATA,X -CA7C: E6 44 519 INC BUFFER -CA7E: D0 02 520 BNE :INW -CA80: E6 45 521 INC BUFFER+1 ; inc msb on page boundary -CA82: E6 3C 522 :INW INC WORK -CA84: D0 F1 523 BNE :LOOPW -CA86: 88 524 DEY -CA87: D0 EC 525 BNE :LOOPY - 526 -CA89: 9D 80 C0 527 :CRC STA DATA,X ; send 2 dummy crc bytes -CA8C: 9D 80 C0 528 STA DATA,X - 529 -CA8F: 9D 80 C0 530 STA DATA,X ; get data response -CA92: BD 80 C0 531 LDA DATA,X -CA95: 29 1F 532 AND #$1F -CA97: C9 05 533 CMP #$05 -CA99: D0 1C 534 BNE :IOERROR ; check for write error -CA9B: 18 535 CLC ; no error -CA9C: A9 00 536 LDA #0 +C962: A9 80 477 LDA #$80 ; drive number +C964: 24 43 478 BIT $43 +C966: F0 05 479 BEQ :SHIFT ; D1 +C968: A9 01 480 LDA #1 ; D2 +C96A: 9D F8 04 481 STA R31,X + 482 +C96D: A0 09 483 :SHIFT LDY #9 ; ASL can't be used with Y +C96F: 1E F8 05 484 :LOOP ASL R33,X ; mul block num +C972: 3E 78 05 485 ROL R32,X ; by 512 to get +C975: 3E F8 04 486 ROL R31,X ; real address +C978: 3E 78 04 487 ROL R30,X +C97B: 88 488 DEY +C97C: D0 F1 489 BNE :LOOP +C97E: 7A 490 PLY ; restore Y +C97F: FA 491 PLX ; restore X +C980: 60 492 RTS + 493 + 494 + 495 ******************************** + 496 * + 497 * Send SD command + 498 * Cmd is in A + 499 * + 500 ******************************** + 501 +C981: 5A 502 COMMAND PHY ; save Y +C982: A4 3D 503 LDY SLOT +C984: 9D 80 C0 504 STA DATA,X ; send command +C987: B9 78 04 505 LDA R30,Y ; get arg from R30 on +C98A: 9D 80 C0 506 STA DATA,X +C98D: B9 F8 04 507 LDA R31,Y +C990: 9D 80 C0 508 STA DATA,X +C993: B9 78 05 509 LDA R32,Y +C996: 9D 80 C0 510 STA DATA,X +C999: B9 F8 05 511 LDA R33,Y +C99C: 9D 80 C0 512 STA DATA,X +C99F: A9 FF 513 LDA #DUMMY +C9A1: 9D 80 C0 514 STA DATA,X ; dummy crc +C9A4: 20 FF C8 515 JSR GETR1 +C9A7: 7A 516 PLY ; restore Y +C9A8: 60 517 RTS + 518 + 519 + 520 ******************************** + 521 * + 522 * Check for card detect + 523 * + 524 * C Clear - card in slot + 525 * Set - no card in slot + 526 * + 527 ******************************** + 528 +C9A9: 48 529 CARDDET PHA +C9AA: A9 40 530 LDA #CD ; 0: card in +C9AC: 3C 83 C0 531 BIT SS,X ; 1: card out +C9AF: 18 532 CLC +C9B0: F0 01 533 BEQ :DONE ; card is in +C9B2: 38 534 SEC ; card is out +C9B3: 68 535 :DONE PLA +C9B4: 60 536 RTS 537 -CA9E: 08 538 :DONE PHP -CA9F: 48 539 PHA -CAA0: A9 FF 540 :WAIT LDA #DUMMY -CAA2: 9D 80 C0 541 STA DATA,X ; wait for write cycle -CAA5: BD 80 C0 542 LDA DATA,X ; to complete -CAA8: C9 00 543 CMP #$00 -CAAA: F0 F4 544 BEQ :WAIT - 545 -CAAC: BD 83 C0 546 LDA SS,X ; disable /CS -CAAF: 09 01 547 ORA #SS0 -CAB1: 9D 83 C0 548 STA SS,X -CAB4: 68 549 PLA -CAB5: 28 550 PLP -CAB6: 60 551 RTS - 552 -CAB7: 38 553 :IOERROR SEC ; an error occured -CAB8: A9 27 554 LDA #$27 -CABA: 80 E2 555 BRA :DONE + 538 + 539 ******************************** + 540 * + 541 * Check for write protect + 542 * + 543 * C Clear - card not protected + 544 * Set - card write protected + 545 * + 546 ******************************** + 547 +C9B5: 48 548 WRPROT PHA +C9B6: A9 20 549 LDA #WP ; 0: write enabled +C9B8: 3C 83 C0 550 BIT SS,X ; 1: write disabled +C9BB: 18 551 CLC +C9BC: F0 01 552 BEQ :DONE +C9BE: 38 553 SEC +C9BF: 68 554 :DONE PLA +C9C0: 60 555 RTS 556 -CABC: 38 557 :WPERROR SEC -CABD: A9 2B 558 LDA #$2B -CABF: 80 DD 559 BRA :DONE - 560 - 561 - 562 - 563 ******************************** + 557 + 558 ******************************** + 559 * + 560 * Status request + 561 * $43 Unit number DSSS000 + 562 * $44-45 Unused + 563 * $46-47 Unused 564 * - 565 * Format - 566 * not supported! - 567 * - 568 ******************************** - 569 -CAC1: 38 570 FORMAT SEC -CAC2: A9 01 571 LDA #$01 ; invalid command -CAC4: 60 572 RTS - 573 + 565 * C Clear - No error + 566 * Set - Error + 567 * A $00 - No error + 568 * $2B - Card write protected + 569 * $2F - No card inserted + 570 * X - Blocks avail (low byte) + 571 * Y - Blocks avail (high byte) + 572 * + 573 ******************************** 574 - 575 ******************************** - 576 * - 577 * Test routine - 578 * - 579 ******************************** - 580 - 581 DO DEBUG - 582 TEST - 583 - 584 * get buffer - 585 LDA #2 ; get 512 byte buffer - 586 JSR $BEF5 ; call GETBUFR - 587 BCS :ERROR - 588 STA BUFADD+1 - 589 STA BUFFER+1 - 590 STZ BUFADD - 591 STZ BUFFER - 592 - 593 * fill buffer - 594 LDY #0 - 595 :LOOP TYA - 596 STA (BUFFER),Y - 597 INY - 598 BNE :LOOP - 599 INC BUFFER+1 - 600 :LOOP1 TYA - 601 STA (BUFFER),Y - 602 INY - 603 BNE :LOOP1 - 604 - 605 * write to card - 606 LDA #2 ; write cmd - 607 STA DCMD - 608 LDA BUFADD ; buffer address - 609 STA BUFFER - 610 LDA BUFADD+1 - 611 STA BUFFER+1 - 612 STZ BLOCK ; block number - 613 STZ BLOCK+1 - 614 LDX SLOT16 - 615 JSR DRIVER - 616 BCS :ERROR - 617 - 618 * read from card - 619 LDA #1 ; read cmd - 620 STA DCMD - 621 LDA BUFADD ; buffer address - 622 STA BUFFER - 623 LDA BUFADD+1 - 624 STA BUFFER+1 - 625 STZ BLOCK ; block number - 626 STZ BLOCK+1 - 627 LDX SLOT16 - 628 JSR DRIVER - 629 BCS :ERROR - 630 - 631 * check for errors - 632 LDA BUFADD ; buffer address - 633 STA BUFFER - 634 LDA BUFADD+1 - 635 STA BUFFER+1 - 636 LDY #0 - 637 :LOOP2 TYA - 638 CMP (BUFFER),Y - 639 BNE :ERRCMP ; error in buffer - 640 INY - 641 BNE :LOOP2 - 642 INC BUFFER+1 - 643 :LOOP3 TYA - 644 CMP (BUFFER),Y - 645 BNE :ERRCMP - 646 INY - 647 BNE :LOOP3 - 648 - 649 * free buffer - 650 JSR $BEF8 ; call FREEBUFR - 651 CLC - 652 LDA #0 - 653 RTS - 654 - 655 :ERROR BRK - 656 :ERRCMP BRK +C9C1: A9 00 575 STATUS LDA #0 ; no error +C9C3: A2 FF 576 LDX #$FF ; 32 MB partition +C9C5: A0 FF 577 LDY #$FF + 578 +C9C7: 20 B5 C9 579 JSR WRPROT +C9CA: 90 02 580 BCC :DONE +C9CC: A9 2B 581 LDA #$2B ; card write protected + 582 +C9CE: 60 583 :DONE RTS + 584 + 585 + 586 ******************************** + 587 * + 588 * Read 512 byte block + 589 * $43 Unit number DSSS0000 + 590 * $44-45 Address (LO/HI) of buffer + 591 * $46-47 Block number (LO/HI) + 592 * + 593 * C Clear - No error + 594 * Set - Error + 595 * A $00 - No error + 596 * $27 - Bad block number + 597 * + 598 ******************************** + 599 +C9CF: 20 4C C9 600 READ JSR GETBLOCK ; calc block address + 601 +C9D2: BD 83 C0 602 LDA SS,X ; enable /CS +C9D5: 29 FE 603 AND #$FF!SS0 +C9D7: 9D 83 C0 604 STA SS,X +C9DA: A9 51 605 LDA #$51 ; send CMD17 +C9DC: 20 81 C9 606 JSR COMMAND ; send command + 607 +C9DF: C9 00 608 CMP #0 ; check for error +C9E1: D0 50 609 BNE :ERROR + 610 +C9E3: A9 FF 611 :GETTOK LDA #DUMMY ; get data token +C9E5: 9D 80 C0 612 STA DATA,X +C9E8: BD 80 C0 613 LDA DATA,X ; get response +C9EB: C9 FE 614 CMP #$FE +C9ED: D0 F4 615 BNE :GETTOK ; wait for $FE + 616 +C9EF: A0 02 617 LDY #2 ; read data from card +C9F1: BD 81 C0 618 LDA CTRL,X ; enable FRX +C9F4: 09 10 619 ORA #FRX +C9F6: 9D 81 C0 620 STA CTRL,X +C9F9: A9 FF 621 LDA #DUMMY +C9FB: 9D 80 C0 622 STA DATA,X +C9FE: 64 3C 623 :LOOPY STZ WORK +CA00: BD 80 C0 624 :LOOPW LDA DATA,X +CA03: 92 44 625 STA (BUFFER) +CA05: E6 44 626 INC BUFFER +CA07: D0 02 627 BNE :INW +CA09: E6 45 628 INC BUFFER+1 ; inc msb on page boundary +CA0B: E6 3C 629 :INW INC WORK +CA0D: D0 F1 630 BNE :LOOPW +CA0F: 88 631 DEY +CA10: D0 EC 632 BNE :LOOPY + 633 +CA12: BD 80 C0 634 :CRC LDA DATA,X ; read two bytes crc +CA15: BD 80 C0 635 LDA DATA,X ; and ignore +CA18: BD 80 C0 636 LDA DATA,X ; read a dummy byte + 637 +CA1B: BD 81 C0 638 LDA CTRL,X ; disable FRX +CA1E: 29 EF 639 AND #$FF!FRX +CA20: 9D 81 C0 640 STA CTRL,X +CA23: 18 641 CLC ; no error +CA24: A9 00 642 LDA #0 + 643 +CA26: 08 644 :DONE PHP +CA27: 48 645 PHA +CA28: BD 83 C0 646 LDA SS,X +CA2B: 09 01 647 ORA #SS0 +CA2D: 9D 83 C0 648 STA SS,X ; disable /CS +CA30: 68 649 PLA +CA31: 28 650 PLP +CA32: 60 651 RTS + 652 +CA33: 38 653 :ERROR SEC ; an error occured +CA34: A9 27 654 LDA #$27 +CA36: 80 EE 655 BRA :DONE + 656 657 - 658 BUFADD DW 0 - 659 FIN - 660 - 661 -CAC5: 40 00 00 662 CMD0 HEX 400000 -CAC8: 00 00 95 663 HEX 000095 -CACB: 41 00 00 664 CMD1 HEX 410000 -CACE: 00 00 F9 665 HEX 0000F9 -CAD1: 48 00 00 666 CMD8 HEX 480000 -CAD4: 01 AA 87 667 HEX 01AA87 -CAD7: 50 00 00 668 CMD16 HEX 500000 -CADA: 02 00 FF 669 HEX 0200FF -CADD: 77 00 00 670 CMD55 HEX 770000 -CAE0: 00 00 65 671 HEX 000065 -CAE3: 69 40 00 672 ACMD4140 HEX 694000 -CAE6: 00 00 77 673 HEX 000077 -CAE9: 69 00 00 674 ACMD410 HEX 690000 -CAEC: 00 00 FF 675 HEX 0000FF - 676 + 658 ******************************** + 659 * + 660 * Write 512 byte block + 661 * $43 Unit number DSSS0000 + 662 * $44-45 Address (LO/HI) of buffer + 663 * $46-47 Block number (LO/HI) + 664 * + 665 * C Clear - No error + 666 * Set - Error + 667 * A $00 - No error + 668 * $27 - I/O error or bad block number + 669 * $2B - Card write protected + 670 * + 671 ******************************** + 672 +CA38: 20 B5 C9 673 WRITE JSR WRPROT +CA3B: B0 67 674 BCS :WPERROR ; card write protected + 675 +CA3D: 20 4C C9 676 JSR GETBLOCK ; calc block address 677 - 678 ******************************** - 679 * - 680 * This region is mapped to - 681 * the $CsXX space. On the ROM - 682 * it must appear at address $700 - 683 * - 684 ******************************** - 685 - 686 DO DEBUG-1 -CAEF: 00 00 00 687 DS \ -CAF2: 00 00 00 00 -CAF6: 00 00 00 00 -CAFA: 00 00 00 00 -CAFE: 00 00 -CB00: 00 00 00 688 DS $400 -CB03: 00 00 00 00 -CB07: 00 00 00 00 -CB0B: 00 00 00 00 -CB0F: 00 00 00 00 -CB13: 00 00 00 00 -CB17: 00 00 00 00 -CB1B: 00 00 00 00 -CB1F: 00 00 00 00 -CB23: 00 00 00 00 -CB27: 00 00 00 00 -CB2B: 00 00 00 00 -CB2F: 00 00 00 00 -CB33: 00 00 00 00 -CB37: 00 00 00 00 -CB3B: 00 00 00 00 -CB3F: 00 00 00 00 -CB43: 00 00 00 00 -CB47: 00 00 00 00 -CB4B: 00 00 00 00 -CB4F: 00 00 00 00 -CB53: 00 00 00 00 -CB57: 00 00 00 00 -CB5B: 00 00 00 00 -CB5F: 00 00 00 00 -CB63: 00 00 00 00 -CB67: 00 00 00 00 -CB6B: 00 00 00 00 -CB6F: 00 00 00 00 -CB73: 00 00 00 00 -CB77: 00 00 00 00 -CB7B: 00 00 00 00 -CB7F: 00 00 00 00 -CB83: 00 00 00 00 -CB87: 00 00 00 00 -CB8B: 00 00 00 00 -CB8F: 00 00 00 00 -CB93: 00 00 00 00 -CB97: 00 00 00 00 -CB9B: 00 00 00 00 -CB9F: 00 00 00 00 -CBA3: 00 00 00 00 -CBA7: 00 00 00 00 -CBAB: 00 00 00 00 -CBAF: 00 00 00 00 -CBB3: 00 00 00 00 -CBB7: 00 00 00 00 -CBBB: 00 00 00 00 -CBBF: 00 00 00 00 -CBC3: 00 00 00 00 -CBC7: 00 00 00 00 -CBCB: 00 00 00 00 -CBCF: 00 00 00 00 -CBD3: 00 00 00 00 -CBD7: 00 00 00 00 -CBDB: 00 00 00 00 -CBDF: 00 00 00 00 -CBE3: 00 00 00 00 -CBE7: 00 00 00 00 -CBEB: 00 00 00 00 -CBEF: 00 00 00 00 -CBF3: 00 00 00 00 -CBF7: 00 00 00 00 -CBFB: 00 00 00 00 -CBFF: 00 00 00 00 -CC03: 00 00 00 00 -CC07: 00 00 00 00 -CC0B: 00 00 00 00 -CC0F: 00 00 00 00 -CC13: 00 00 00 00 -CC17: 00 00 00 00 -CC1B: 00 00 00 00 -CC1F: 00 00 00 00 -CC23: 00 00 00 00 -CC27: 00 00 00 00 -CC2B: 00 00 00 00 -CC2F: 00 00 00 00 -CC33: 00 00 00 00 -CC37: 00 00 00 00 -CC3B: 00 00 00 00 -CC3F: 00 00 00 00 -CC43: 00 00 00 00 -CC47: 00 00 00 00 -CC4B: 00 00 00 00 -CC4F: 00 00 00 00 -CC53: 00 00 00 00 -CC57: 00 00 00 00 -CC5B: 00 00 00 00 -CC5F: 00 00 00 00 -CC63: 00 00 00 00 -CC67: 00 00 00 00 -CC6B: 00 00 00 00 -CC6F: 00 00 00 00 -CC73: 00 00 00 00 -CC77: 00 00 00 00 -CC7B: 00 00 00 00 -CC7F: 00 00 00 00 -CC83: 00 00 00 00 -CC87: 00 00 00 00 -CC8B: 00 00 00 00 -CC8F: 00 00 00 00 -CC93: 00 00 00 00 -CC97: 00 00 00 00 -CC9B: 00 00 00 00 -CC9F: 00 00 00 00 -CCA3: 00 00 00 00 -CCA7: 00 00 00 00 -CCAB: 00 00 00 00 -CCAF: 00 00 00 00 -CCB3: 00 00 00 00 -CCB7: 00 00 00 00 -CCBB: 00 00 00 00 -CCBF: 00 00 00 00 -CCC3: 00 00 00 00 -CCC7: 00 00 00 00 -CCCB: 00 00 00 00 -CCCF: 00 00 00 00 -CCD3: 00 00 00 00 -CCD7: 00 00 00 00 -CCDB: 00 00 00 00 -CCDF: 00 00 00 00 -CCE3: 00 00 00 00 -CCE7: 00 00 00 00 -CCEB: 00 00 00 00 -CCEF: 00 00 00 00 -CCF3: 00 00 00 00 -CCF7: 00 00 00 00 -CCFB: 00 00 00 00 -CCFF: 00 00 00 00 -CD03: 00 00 00 00 -CD07: 00 00 00 00 -CD0B: 00 00 00 00 -CD0F: 00 00 00 00 -CD13: 00 00 00 00 -CD17: 00 00 00 00 -CD1B: 00 00 00 00 -CD1F: 00 00 00 00 -CD23: 00 00 00 00 -CD27: 00 00 00 00 -CD2B: 00 00 00 00 -CD2F: 00 00 00 00 -CD33: 00 00 00 00 -CD37: 00 00 00 00 -CD3B: 00 00 00 00 -CD3F: 00 00 00 00 -CD43: 00 00 00 00 -CD47: 00 00 00 00 -CD4B: 00 00 00 00 -CD4F: 00 00 00 00 -CD53: 00 00 00 00 -CD57: 00 00 00 00 -CD5B: 00 00 00 00 -CD5F: 00 00 00 00 -CD63: 00 00 00 00 -CD67: 00 00 00 00 -CD6B: 00 00 00 00 -CD6F: 00 00 00 00 -CD73: 00 00 00 00 -CD77: 00 00 00 00 -CD7B: 00 00 00 00 -CD7F: 00 00 00 00 -CD83: 00 00 00 00 -CD87: 00 00 00 00 -CD8B: 00 00 00 00 -CD8F: 00 00 00 00 -CD93: 00 00 00 00 -CD97: 00 00 00 00 -CD9B: 00 00 00 00 -CD9F: 00 00 00 00 -CDA3: 00 00 00 00 -CDA7: 00 00 00 00 -CDAB: 00 00 00 00 -CDAF: 00 00 00 00 -CDB3: 00 00 00 00 -CDB7: 00 00 00 00 -CDBB: 00 00 00 00 -CDBF: 00 00 00 00 -CDC3: 00 00 00 00 -CDC7: 00 00 00 00 -CDCB: 00 00 00 00 -CDCF: 00 00 00 00 -CDD3: 00 00 00 00 -CDD7: 00 00 00 00 -CDDB: 00 00 00 00 -CDDF: 00 00 00 00 -CDE3: 00 00 00 00 -CDE7: 00 00 00 00 -CDEB: 00 00 00 00 -CDEF: 00 00 00 00 -CDF3: 00 00 00 00 -CDF7: 00 00 00 00 -CDFB: 00 00 00 00 -CDFF: 00 00 00 00 -CE03: 00 00 00 00 -CE07: 00 00 00 00 -CE0B: 00 00 00 00 -CE0F: 00 00 00 00 -CE13: 00 00 00 00 -CE17: 00 00 00 00 -CE1B: 00 00 00 00 -CE1F: 00 00 00 00 -CE23: 00 00 00 00 -CE27: 00 00 00 00 -CE2B: 00 00 00 00 -CE2F: 00 00 00 00 -CE33: 00 00 00 00 -CE37: 00 00 00 00 -CE3B: 00 00 00 00 -CE3F: 00 00 00 00 -CE43: 00 00 00 00 -CE47: 00 00 00 00 -CE4B: 00 00 00 00 -CE4F: 00 00 00 00 -CE53: 00 00 00 00 -CE57: 00 00 00 00 -CE5B: 00 00 00 00 -CE5F: 00 00 00 00 -CE63: 00 00 00 00 -CE67: 00 00 00 00 -CE6B: 00 00 00 00 -CE6F: 00 00 00 00 -CE73: 00 00 00 00 -CE77: 00 00 00 00 -CE7B: 00 00 00 00 -CE7F: 00 00 00 00 -CE83: 00 00 00 00 -CE87: 00 00 00 00 -CE8B: 00 00 00 00 -CE8F: 00 00 00 00 -CE93: 00 00 00 00 -CE97: 00 00 00 00 -CE9B: 00 00 00 00 -CE9F: 00 00 00 00 -CEA3: 00 00 00 00 -CEA7: 00 00 00 00 -CEAB: 00 00 00 00 -CEAF: 00 00 00 00 -CEB3: 00 00 00 00 -CEB7: 00 00 00 00 -CEBB: 00 00 00 00 -CEBF: 00 00 00 00 -CEC3: 00 00 00 00 -CEC7: 00 00 00 00 -CECB: 00 00 00 00 -CECF: 00 00 00 00 -CED3: 00 00 00 00 -CED7: 00 00 00 00 -CEDB: 00 00 00 00 -CEDF: 00 00 00 00 -CEE3: 00 00 00 00 -CEE7: 00 00 00 00 -CEEB: 00 00 00 00 -CEEF: 00 00 00 00 -CEF3: 00 00 00 00 -CEF7: 00 00 00 00 -CEFB: 00 00 00 00 -CEFF: 00 - 689 ERR *-1/$CF00 ; must be at $CF00 - 690 FIN +CA40: BD 83 C0 678 LDA SS,X ; enable /CS +CA43: 29 FE 679 AND #$FF!SS0 +CA45: 9D 83 C0 680 STA SS,X +CA48: A9 58 681 LDA #$58 ; send CMD24 +CA4A: 20 81 C9 682 JSR COMMAND ; send command + 683 +CA4D: C9 00 684 CMP #0 ; check for error +CA4F: D0 4E 685 BNE :IOERROR + 686 +CA51: A9 FF 687 LDA #DUMMY +CA53: 9D 80 C0 688 STA DATA,X ; send dummy +CA56: A9 FE 689 LDA #$FE +CA58: 9D 80 C0 690 STA DATA,X ; send data token 691 - 692 * signature bytes - 693 -CF00: A2 20 694 START LDX #$20 -CF02: A0 00 695 LDY #$00 -CF04: A2 03 696 LDX #$03 -CF06: A0 FF 697 LDY #$FF ; neither 5.25 nor Smartport - 698 - 699 * find slot nr - 700 - 701 DO DEBUG - 702 LDA #$04 - 703 STA SLOT - 704 LDA #$C4 - 705 STA CURSLOT - 706 LDA #$40 - 707 - 708 ELSE -CF08: 20 58 FF 709 JSR $FF58 -CF0B: BA 710 TSX -CF0C: BD 00 01 711 LDA $0100,X -CF0F: 8D F8 07 712 STA CURSLOT ; $Cs -CF12: 29 0F 713 AND #$0F -CF14: 85 3D 714 STA SLOT ; $0s -CF16: 0A 715 ASL A -CF17: 0A 716 ASL A -CF18: 0A 717 ASL A -CF19: 0A 718 ASL A - 719 FIN - 720 -CF1A: 85 2B 721 STA SLOT16 ; $s0 -CF1C: AA 722 TAX ; X holds now SLOT16 -CF1D: 2C FF CF 723 BIT $CFFF -CF20: 20 AE C9 724 JSR CARDDET -CF23: 90 03 725 BCC :INIT -CF25: A9 27 726 LDA #$27 ; no card inserted -CF27: 00 727 BRK - 728 -CF28: 20 00 C8 729 :INIT JSR INIT - 730 - 731 - 732 ******************************** - 733 * - 734 * Install SD card driver - 735 * - 736 ******************************** +CA5B: A0 02 692 LDY #2 ; send data to card +CA5D: 64 3C 693 :LOOPY STZ WORK +CA5F: B2 44 694 :LOOPW LDA (BUFFER) +CA61: 9D 80 C0 695 STA DATA,X +CA64: E6 44 696 INC BUFFER +CA66: D0 02 697 BNE :INW +CA68: E6 45 698 INC BUFFER+1 ; inc msb on page boundary +CA6A: E6 3C 699 :INW INC WORK +CA6C: D0 F1 700 BNE :LOOPW +CA6E: 88 701 DEY +CA6F: D0 EC 702 BNE :LOOPY + 703 +CA71: 9D 80 C0 704 :CRC STA DATA,X ; send 2 dummy crc bytes +CA74: 9D 80 C0 705 STA DATA,X + 706 +CA77: 9D 80 C0 707 STA DATA,X ; get data response +CA7A: BD 80 C0 708 LDA DATA,X +CA7D: 29 1F 709 AND #$1F +CA7F: C9 05 710 CMP #$05 +CA81: D0 1C 711 BNE :IOERROR ; check for write error +CA83: 18 712 CLC ; no error +CA84: A9 00 713 LDA #0 + 714 +CA86: 08 715 :DONE PHP +CA87: 48 716 PHA +CA88: A9 FF 717 :WAIT LDA #DUMMY +CA8A: 9D 80 C0 718 STA DATA,X ; wait for write cycle +CA8D: BD 80 C0 719 LDA DATA,X ; to complete +CA90: C9 00 720 CMP #$00 +CA92: F0 F4 721 BEQ :WAIT + 722 +CA94: BD 83 C0 723 LDA SS,X ; disable /CS +CA97: 09 01 724 ORA #SS0 +CA99: 9D 83 C0 725 STA SS,X +CA9C: 68 726 PLA +CA9D: 28 727 PLP +CA9E: 60 728 RTS + 729 +CA9F: 38 730 :IOERROR SEC ; an error occured +CAA0: A9 27 731 LDA #$27 +CAA2: 80 E2 732 BRA :DONE + 733 +CAA4: 38 734 :WPERROR SEC +CAA5: A9 2B 735 LDA #$2B +CAA7: 80 DD 736 BRA :DONE 737 - 738 DO DEBUG + 738 739 - 740 * see if slot has a driver already - 741 - 742 LDX $BF31 ; get devcnt - 743 INSTALL LDA $BF32,X ; get a devnum - 744 AND #$70 ; isolate slot - 745 CMP SLOT16 ; slot? - 746 BEQ :INSOUT ; yes, skip it - 747 DEX - 748 BPL INSTALL ; keep up the search - 749 - 750 * restore the devnum to the list + 740 ******************************** + 741 * + 742 * Format + 743 * not supported! + 744 * + 745 ******************************** + 746 +CAA9: 38 747 FORMAT SEC +CAAA: A9 01 748 LDA #$01 ; invalid command +CAAC: 60 749 RTS + 750 751 - 752 LDX $BF31 ; get devcnt again - 753 CPX #$0D ; device table full? - 754 BNE :INST2 - 755 - 756 JSR $FF3A ; bell - 757 JMP :INSOUT ; do something! - 758 - 759 :INST2 LDA $BF32-1,X ; move all entries down - 760 STA $BF32,X ; to make room at front - 761 DEX ; for a new entry - 762 BNE :INST2 - 763 LDA #$04 ; ProFile type device - 764 ORA SLOT16 - 765 STA $BF32 ; slot, drive 1 at top of list - 766 INC $BF31 ; update devcnt - 767 - 768 * now insert the device driver vector - 769 - 770 LDA SLOT - 771 ASL - 772 TAX - 773 LDA #DRIVER - 776 STA $BF11,X - 777 :INSOUT RTS - 778 - 779 - 780 ******************************** - 781 * - 782 * Boot from SD card - 783 * - 784 ******************************** - 785 - 786 ELSE - 787 -CF2B: C9 00 788 BOOT CMP #0 ; check for error -CF2D: F0 01 789 BEQ :BOOT1 -CF2F: 00 790 BRK - 791 -CF30: A9 01 792 :BOOT1 LDA #$01 -CF32: 85 42 793 STA DCMD ; load command -CF34: A6 2B 794 LDX SLOT16 -CF36: 85 43 795 STA $43 ; slot number -CF38: 64 44 796 STZ BUFFER ; buffer lo -CF3A: A9 08 797 LDA #$08 -CF3C: 85 45 798 STA BUFFER+1 ; buffer hi -CF3E: 64 46 799 STZ BLOCK ; block lo -CF40: 64 47 800 STZ BLOCK+1 ; block hi -CF42: 2C FF CF 801 BIT $CFFF -CF45: 20 DD C9 802 JSR READ ; call driver -CF48: 4C 01 08 803 JMP $801 ; goto bootloader - 804 - 805 FIN - 806 - 807 - 808 ******************************** - 809 * - 810 * Jump table - 811 * - 812 ******************************** - 813 -CF4B: D8 814 DRIVER CLD - 815 - 816 DO DEBUG - 817 LDA #$04 - 818 STA SLOT - 819 LDA #$C4 - 820 STA CURSLOT - 821 LDA #$40 - 822 - 823 ELSE -CF4C: 20 58 FF 824 JSR $FF58 ; find slot nr -CF4F: BA 825 TSX -CF50: BD 00 01 826 LDA $0100,X -CF53: 8D F8 07 827 STA CURSLOT ; $Cs -CF56: 29 0F 828 AND #$0F -CF58: 85 3D 829 STA SLOT ; $0s -CF5A: 0A 830 ASL A -CF5B: 0A 831 ASL A -CF5C: 0A 832 ASL A -CF5D: 0A 833 ASL A - 834 FIN + 752 ******************************** + 753 * + 754 * Test routine + 755 * + 756 ******************************** + 757 + 758 TEST + 759 + 760 * get buffer +CAAD: A4 3D 761 LDY SLOT +CAAF: A9 02 762 LDA #2 ; get 512 byte buffer +CAB1: 20 F5 BE 763 JSR $BEF5 ; call GETBUFR +CAB4: B0 79 764 BCS :ERROR +CAB6: 99 F8 06 765 STA RAM1,Y +CAB9: 85 45 766 STA BUFFER+1 +CABB: A9 00 767 LDA #0 +CABD: 99 78 06 768 STA RAM0,Y +CAC0: 85 44 769 STA BUFFER + 770 + 771 * fill buffer +CAC2: A0 00 772 LDY #0 +CAC4: 98 773 :LOOP TYA +CAC5: 91 44 774 STA (BUFFER),Y +CAC7: C8 775 INY +CAC8: D0 FA 776 BNE :LOOP +CACA: E6 45 777 INC BUFFER+1 +CACC: 98 778 :LOOP1 TYA +CACD: 91 44 779 STA (BUFFER),Y +CACF: C8 780 INY +CAD0: D0 FA 781 BNE :LOOP1 + 782 + 783 * write to card +CAD2: A9 02 784 LDA #2 ; write cmd +CAD4: A4 3D 785 LDY SLOT +CAD6: 85 42 786 STA DCMD +CAD8: AD 78 06 787 LDA RAM0 ; buffer address +CADB: 85 44 788 STA BUFFER +CADD: B9 F8 06 789 LDA RAM1,Y +CAE0: 85 45 790 STA BUFFER+1 +CAE2: 64 46 791 STZ BLOCK ; block number +CAE4: 64 47 792 STZ BLOCK+1 +CAE6: A6 2B 793 LDX SLOT16 +CAE8: 20 4B C7 794 JSR DRIVER +CAEB: B0 42 795 BCS :ERROR + 796 + 797 * read from card +CAED: A9 01 798 LDA #1 ; read cmd +CAEF: A4 3D 799 LDY SLOT +CAF1: 85 42 800 STA DCMD +CAF3: B9 78 06 801 LDA RAM0,Y ; buffer address +CAF6: 85 44 802 STA BUFFER +CAF8: B9 F8 06 803 LDA RAM1,Y +CAFB: 85 45 804 STA BUFFER+1 +CAFD: 64 46 805 STZ BLOCK ; block number +CAFF: 64 47 806 STZ BLOCK+1 +CB01: A6 2B 807 LDX SLOT16 +CB03: 20 4B C7 808 JSR DRIVER +CB06: B0 27 809 BCS :ERROR + 810 + 811 * check for errors +CB08: A4 3D 812 LDY SLOT +CB0A: B9 78 06 813 LDA RAM0,Y ; buffer address +CB0D: 85 44 814 STA BUFFER +CB0F: B9 F8 06 815 LDA RAM1,Y +CB12: 85 45 816 STA BUFFER+1 +CB14: A0 00 817 LDY #0 +CB16: 98 818 :LOOP2 TYA +CB17: D1 44 819 CMP (BUFFER),Y +CB19: D0 15 820 BNE :ERRCMP ; error in buffer +CB1B: C8 821 INY +CB1C: D0 F8 822 BNE :LOOP2 +CB1E: E6 45 823 INC BUFFER+1 +CB20: 98 824 :LOOP3 TYA +CB21: D1 44 825 CMP (BUFFER),Y +CB23: D0 0B 826 BNE :ERRCMP +CB25: C8 827 INY +CB26: D0 F8 828 BNE :LOOP3 + 829 + 830 * free buffer +CB28: 20 F8 BE 831 JSR $BEF8 ; call FREEBUFR +CB2B: 18 832 CLC +CB2C: A9 00 833 LDA #0 +CB2E: 60 834 RTS 835 -CF5E: 85 2B 836 STA SLOT16 ; $s0 -CF60: AA 837 TAX ; X holds now SLOT16 -CF61: 2C FF CF 838 BIT $CFFF -CF64: 20 AE C9 839 JSR CARDDET -CF67: 90 04 840 BCC :INITED -CF69: A9 27 841 LDA #$27 ; no card inserted -CF6B: 80 1B 842 BRA :DONE - 843 -CF6D: A9 80 844 :INITED LDA #INITED ; check for init -CF6F: 3C 83 C0 845 BIT SS,X -CF72: F0 22 846 BEQ :INIT - 847 -CF74: A5 42 848 :CMD LDA DCMD ; get command -CF76: C9 00 849 CMP #0 -CF78: F0 10 850 BEQ :STATUS -CF7A: C9 01 851 CMP #1 -CF7C: F0 0F 852 BEQ :READ -CF7E: C9 02 853 CMP #2 -CF80: F0 0E 854 BEQ :WRITE -CF82: C9 03 855 CMP #3 -CF84: F0 0D 856 BEQ :FORMAT - 857 DO DEBUG - 858 CMP #$FF - 859 BEQ :TEST - 860 FIN -CF86: A9 01 861 LDA #1 ; unknown command - 862 -CF88: 38 863 :DONE SEC -CF89: 60 864 RTS - 865 -CF8A: 4C C6 C9 866 :STATUS JMP STATUS -CF8D: 4C DD C9 867 :READ JMP READ -CF90: 4C 4B CA 868 :WRITE JMP WRITE -CF93: 4C C1 CA 869 :FORMAT JMP FORMAT -CF96: 20 00 C8 870 :INIT JSR INIT -CF99: B0 ED 871 BCS :DONE ; init failure -CF9B: 80 D7 872 BRA :CMD - 873 - 874 DO DEBUG - 875 :TEST JMP TEST ; do device test - 876 FIN - 877 - 878 - 879 * Signature bytes - 880 -CF9D: 00 00 00 881 DS \ ; fill with zeroes -CFA0: 00 00 00 00 -CFA4: 00 00 00 00 -CFA8: 00 00 00 00 -CFAC: 00 00 00 00 -CFB0: 00 00 00 00 -CFB4: 00 00 00 00 -CFB8: 00 00 00 00 -CFBC: 00 00 00 00 -CFC0: 00 00 00 00 -CFC4: 00 00 00 00 -CFC8: 00 00 00 00 -CFCC: 00 00 00 00 -CFD0: 00 00 00 00 -CFD4: 00 00 00 00 -CFD8: 00 00 00 00 -CFDC: 00 00 00 00 -CFE0: 00 00 00 00 -CFE4: 00 00 00 00 -CFE8: 00 00 00 00 -CFEC: 00 00 00 00 -CFF0: 00 00 00 00 -CFF4: 00 00 00 00 -CFF8: 00 00 00 00 -CFFC: 00 00 00 00 - 882 DS -4 ; locate to $xxFC -CFFC: FF FF 883 DW $FFFF ; 65535 blocks -CFFE: 17 884 DB $17 ; Status bits -CFFF: 4B 885 DB #DRIVER + STA $BF11,X +:INSOUT RTS + + +******************************** +* +* Boot from SD card +* +******************************** + + ELSE + +BOOT CMP #0 ; check for error + BEQ :BOOT1 + BRK + +:BOOT1 LDA #$01 + STA DCMD ; load command + LDX SLOT16 + STA $43 ; slot number + STZ BUFFER ; buffer lo + LDA #$08 + STA BUFFER+1 ; buffer hi + STZ BLOCK ; block lo + STZ BLOCK+1 ; block hi + BIT $CFFF + JSR READ ; call driver + JMP $801 ; goto bootloader + + FIN + + +******************************** +* +* Jump table +* +******************************** + +DRIVER CLD + + DO DEBUG + LDA #$04 + STA SLOT + LDA #$C4 + STA CURSLOT + LDA #$40 + + ELSE + JSR $FF58 ; find slot nr + TSX + LDA $0100,X + STA CURSLOT ; $Cs + AND #$0F + STA SLOT ; $0s + ASL A + ASL A + ASL A + ASL A + FIN + + STA SLOT16 ; $s0 + TAX ; X holds now SLOT16 + BIT $CFFF + JSR CARDDET + BCC :INITED + LDA #$2F ; no card inserted + BRA :DONE + +:INITED LDA #INITED ; check for init + BIT SS,X + BEQ :INIT + +:CMD LDA DCMD ; get command + CMP #0 + BEQ :STATUS + CMP #1 + BEQ :READ + CMP #2 + BEQ :WRITE + CMP #3 + BEQ :FORMAT + CMP #$FF + BEQ :TEST + LDA #1 ; unknown command + +:DONE SEC + RTS + +:STATUS JMP STATUS +:READ JMP READ +:WRITE JMP WRITE +:FORMAT JMP FORMAT +:TEST JMP TEST ; do device test +:INIT JSR INIT + BCS :DONE ; init failure + BRA :CMD + + +* Signature bytes + + DS \ ; fill with zeroes + DS -4 ; locate to $xxFC + DW $FFFF ; 65535 blocks + DB $17 ; Status bits + DB #DRIVER - STA $BF11,X -:INSOUT RTS - - -******************************** -* -* Boot from SD card -* -******************************** - - ELSE - -BOOT CMP #0 ; check for error - BEQ :BOOT1 - BRK - -:BOOT1 LDA #$01 - STA DCMD ; load command - LDX SLOT16 - STA $43 ; slot number - STZ BUFFER ; buffer lo - LDA #$08 - STA BUFFER+1 ; buffer hi - STZ BLOCK ; block lo - STZ BLOCK+1 ; block hi - BIT $CFFF - JSR READ ; call driver - JMP $801 ; goto bootloader - - FIN - - -******************************** -* -* Jump table -* -******************************** - -DRIVER CLD - - DO DEBUG - LDA #$04 - STA SLOT - LDA #$C4 - STA CURSLOT - LDA #$40 - - ELSE - JSR $FF58 ; find slot nr - TSX - LDA $0100,X - STA CURSLOT ; $Cs - AND #$0F - STA SLOT ; $0s - ASL A - ASL A - ASL A - ASL A - FIN - - STA SLOT16 ; $s0 - TAX ; X holds now SLOT16 - BIT $CFFF - JSR CARDDET - BCC :INITED - LDA #$27 ; no card inserted - BRA :DONE - -:INITED LDA #INITED ; check for init - BIT SS,X - BEQ :INIT - -:CMD LDA DCMD ; get command - CMP #0 - BEQ :STATUS - CMP #1 - BEQ :READ - CMP #2 - BEQ :WRITE - CMP #3 - BEQ :FORMAT - DO DEBUG - CMP #$FF - BEQ :TEST - FIN - LDA #1 ; unknown command - -:DONE SEC - RTS - -:STATUS JMP STATUS -:READ JMP READ -:WRITE JMP WRITE -:FORMAT JMP FORMAT -:INIT JSR INIT - BCS :DONE ; init failure - BRA :CMD - - DO DEBUG -:TEST JMP TEST ; do device test - FIN - - -* Signature bytes - - DS \ ; fill with zeroes - DS -4 ; locate to $xxFC - DW $FFFF ; 65535 blocks - DB $17 ; Status bits - DB #