10REM > IDEPatch 1.18 20REM J.G.Harston, M.Firth 30REM Patch ADFS 1.30 to access IDE devices 40REM v1.10 Trial version, incorporates context preservation on Ctrl-Break 50REM v1.11 Verified with real hardware 60REM v1.13 Stack params, do one sector at a time 70REM v1.14 IDE transfers done twice to avoid DRQ bug, Tube works 80REM v1.15 SetGeo uses correct drive, errors translated 90REM v1.16 Automatically finds Library directory 100REM v1.17 Two drives per device, no wait for spin-up on power-on 105REM v1.18 Ported to update ADFS 1.30 instead of 1.50 110: 120DIM mcode% &3FFF:ver$="1.33":cyl0%=0:vb%=FALSE 125prctxt%=TRUE:btcwd%=TRUE 130INPUT"ADFS 1.30 ROM image: "file$ 140OSCLI"Load "+file$+" "+STR$~mcode% 150IF mcode%!&14<>&30332E31:PRINT"Not ADFS v1.30":END 160DEF FNorg(A%):P%=A%:O%=A%-&8000+mcode%:=P*(2-vb%)+4 170: 180FOR P=0 TO 1 190[OPT FNorg(&8008) 200EQUB EVAL("&"+MID$(ver$,3)) :\ New version byte 210] 220[OPT FNorg(&8014) 230EQUS ver$ :\ New version string 240] 250[OPT FNorg(&8057) 260LDA &FC47:STA &CC:LDA &FC47 :\ Read IDE status byte 270] 280[OPT FNorg(&8065) 290RTS:NOP:NOP:NOP :\ Remove SCSI code 300NOP :\ RTS changed to NOP in 1.32 patch - Why??? 310.ReadBreak 320LDA &028D:AND #&01:RTS :\ Power-on Reset? :\ Replaced legal JSR 9A88 with read of &028D, as per ADFS 1.30 330NOP :\ MF - Added to make next code align with supplied 1.33... 340.WaitForData 350LDA &FC47:AND #8:BEQ WaitForData:\ Loop until data ready :\ Replaced from BIT #8 360RTS 370: 380.MountCheck 390JSR &A15E:JMP &9B38 :\ Do *MOUNT, then reselect ADFS :\ CHANGED from &A19E and &9B4A 400: 410\ next=&8080 420] 430[OPT FNorg(&80F6) :\ Access hard drive 440LDY #0 450NOP 460] 470[OPT FNorg(&8114) 480JMP BYE 510NOP 520NOP 530NOP 540NOP 541.CommandSaveLp1 542LDY #9 543.CommandSaveLp 544LDA &7F,Y:PHA:LDA (&B0),Y:STA &7F,Y 545DEY:BNE CommandSaveLp :\ Save &80-&89 and copy block 550: 560LDA &B0:PHA:LDA &B1:PHA 570JSR UpdateDrive :\ Merge drive 580STA &B0:STY &B1 :\ Point to block in RAM 590PHP:JSR SetGeometry:PLP :\ Set shape to c*4*64 600.CommandLoop 610LDX #2:.Twice :\ First pass to seek sector 620BIT &CD:BVC CommandStart :\ Accessing I/O memory 630PHP:TXA:PHA:LDX #&27:LDY #&10:LDA #0:\ Point to address block :\ CHANGED PHX :\ Changed C2 to 10 640ROL A:EOR #1:JSR SetTubeAction+1:PLA:TAX:PLP :\ Set Tube action :\ CHANGED PLX :\ Replaced &8213 with SetTubeAction+1 650.CommandStart :\ C=R/W, &B0/1=>block 660JSR SetSector :\ Set sector, count, command 670.TransferLoop 680JSR WaitForData:AND #&21:BNE TransDone 690BIT &CD:BVS TransTube:BCC IORead 700.IOWrite :LDA (&80),Y:STA &FC40:JMP TransferByte :\ Replaced BRA with JMP 710.IORead :LDA &FC40:STA (&80),Y:JMP TransferByte :\ Replaced BRA with JMP 720.TransTube:BCC TubeRead 730.TubeWrite:LDA &FEE5:STA &FC40:JMP TransferByte :\ Replaced BRA with JMP 740.TubeRead :LDA &FC40:STA &FEE5:JMP TransferByte :\ Replaced BRA with JMP 750.CommandLoop1 :\ Added CommandLoop1 - MF Why??? 755JMP CommandLoop 760\ next=&818A :\ Changed from &81AD - does any of this 'next=' stuff do anything? 770] 780[OPT FNorg(&818A) :\ Transfer completed 790.CommandDone 800JSR GetResult :\ Get IDE result 810.CommandExit 820PHA:JSR &8043:PLA :\ Release Tube :\ CHANGED from 803A 830LDX &B0:LDY &B1:AND #&7F :\ Restore registers 840RTS 850: 860.TransferByte 870INY:BNE TransferLoop :\ Loop for 256 bytes 880DEX:BNE Twice:INC &81 :\ Second pass to do real transfer 890LDA &FC47:AND #&21:BNE TransDone:\ Error occured 900INC &1028:BNE TubeAddr :\ Increment Tube address :\ CHANGED from &C228 910INC &1029:BNE TubeAddr:INC &102A :\ CHANGED from &C229 and &C22A 920.TubeAddr 930INC &87:BNE TransCount :\ Increment sector 940INC &86:BNE TransCount:INC &85 950.TransCount 960DEC &88:BNE CommandLoop1 :\ Loop for all sectors 970 :\ Done, check for errors 980: 990.TransDone 1000PLA:STA &B1:PLA:STA &B0:INY :\ Restore pointer 1010.CommandRestore :\ Restore memory 1020PLA:STA &7F,Y:INY:CPY #10:BNE CommandRestore 1030BEQ CommandDone :\ Jump to get result :\ Replaced BRA with BEQ 1040: 1050.SetGeometry 1060JSR WaitNotBusy 1070LDA #64:STA &FC42:STA &FC43 :\ 64 sectors per track 1080LDY #6:LDA (&B0),Y:LSR A:LSR A:ORA #3 :\ Get drive number 1090JSR SetDriveA:LDA #&91:BNE SetCmd :\ 4 heads per cylinder 1100.SetTubeAction 1110\ next=&81EF CHANGED from &8212 1120] 1130[OPT FNorg(&81FC) :\ CHANGED from &821F 1140.SetSector 1150PHP:JSR WaitNotBusy :\ Save CC/CS Read/Write 1160LDY #8:LDA #1:STA &FC42 :\ One sector 1170CLC:LDA (&B0),Y:AND #63:ADC #1:STA &FC43:\ Set sector b0-b5 1180DEY:LDA (&B0),Y:ADC #cyl0%:STA &FC44 :\ Set sector b8-b15 1190DEY:LDA (&B0),Y:JSR SetCylinder :\ Set sector b16-b21 1200INY:INY:EOR (&B0),Y:AND #2:EOR (&B0),Y :\ Merge Drive and Head 1210JSR SetDrive:DEY:DEY:DEY:LDA (&B0),Y :\ Get command &08 or &0A 1220.SetCommand 1230AND #2:PHA:EOR #2:LSR A:LSR A :\ Copy ~b1 into Cy 1240PLA:ASL A:ASL A:ASL A:ORA #&20 :\ Translate CS->&20 or CC->&30 1250LDY #0:PLP:.SetCmd:STA &FC47:RTS :\ Set command &08 or &0A 1260: 1270.SetDrive 1280ROL A:ROL A:ROL A :\ Move into position 1290.SetDriveA 1300AND #&13:STA &FC46:RTS :\ Set device + sector b6-b7 1310: 1320.SetCylinder 1330PHA:AND #&3F:ADC #0:STA &FC45 :\ Set sector b16-b21 1340PLA:ROL A:ROL A:ROL A:ROL A:RTS :\ Get Drive 0-1/2-3 into b1 1350: 1360.SetRandom 1370JSR SetCylinder :\ Set sector b16-b21 1380EOR &1001,X:AND #&02:EOR &1001,X :\ Merge Drive and Head :\ Changed from &C201 x2 1390JSR SetDrive:PLA:JMP SetCommand1 :\ Set device and command :\ Replaced BRA with JMP, moved PHP up to compensate for extra 2 bytes 1400: 1410.GetResult 1420LDA &FC47:AND #&21:BEQ GetResOk :\ Get IDE result 1430ORA &FC41:LDX #&FF :\ Get IDE error code 1440.GetResLp 1450INX:ROR A:BCC GetResLp:LDA ResultCodes,X:\ Translate result code 1460.GetResOk 1470RTS 1480NOP:NOP:NOP :\ Why extra NOPs? 1485NOP:NOP:NOP:NOP :\ 4 extra NOPs to make code align with supplied 1.33 1490\ next=&8287 :\ CHANGED from &82A5 1500] 1510[OPT FNorg(&8305) :\ CHANGED from &8328 1515.FakeComplete 1520LDA &CD:AND #&FE:STA &CD :\ Fake that ensuring has completed 1530RTS 1532BNE FakeComplete:RTS :\ Extra code from supplied 1.33 ???? 1535\NOP:NOP:NOP :\ Why extra NOPs? 1540] 1550[OPT FNorg(&830F) :\ CHANGED from &8332 1560.WaitNotBusy 1570PHP 1573.IDEstatus 1577JSR &8056 :\ Get IDE status :\ CHANGED from &806F 1580AND #&C0:CMP #&40:BNE IDEstatus :\ Wait for IDE not busy and ready :\ IDEstatus replaces explicit &8333 1590PLP:RTS 1600\ 11 spare bytes 1610] 1620[OPT FNorg(&8B72) :\ Load a partial sector :\ CHANGED from &8B7F 1640TXA:PHA:JSR SetGeometry:JSR SetSector:\ Pass sector address to IDE :\ Replaced PHX 1660PLA:TAX:NOP:NOP:NOP :\ Replaced PLX - Two extra NOPs to align with supplied 1.33 1670] 1680[OPT FNorg(&8FEA) :\ CHANGED from &8FF3 1690RTS :\ Bodge 'Bad FS map' check 1700] 1710[OPT FNorg(&9A63) :\ Check if hard drive present :\ CHANGED from &9A6C 1720LDA &FC47 :\ &FF - absent, <>&FF - present 1730CLC:ADC #1:BEQ DriveNotPresent :\ &00 - absent, <>&00 - present :\ Replaced INC A 1740LDA #0:RTS :\ EQ - present 1750.DriveNotPresent 1760SEC:SBC #1 :RTS :\ A=&FF - NE -> absent :\ Replaced DEC A 1770NOP:NOP:NOP:NOP:NOP:NOP :\ Why 5 extra NOPs??? 1780\ next=&9A78 :\ CHANGED from &9A7F 1790] 1791IF btcwd% = FALSE GOTO 1799 1792[OPT FNorg(&9A7D) 1793EQUB &20:EQUB &20 :\ Replace '$.' with ' ' 1794] 1792[OPT FNorg(&9A87) 1793EQUB &20:EQUB &20 :\ Replace '$.' with ' ' 1794] 1799IF prctxt% = FALSE GOTO 1860 1800[OPT FNorg(&9AF6) :\ CHANGED from &9B0B 1810JSR ReadBreak :\ Preserve context on Ctrl-Break 1820] 1830[OPT FNorg(&9B50) :\ CHANGED from &9B7C 1840JSR ReadBreak :\ Preserve context on Ctrl-Break 1850] 1860[OPT FNorg(&9C29) :\ CHANGED from &9C2F 1870LDA &111B:CLC:ADC #1:BNE &9C74 :\ Lib not unset, jump ahead :\ CHANGED from &C31B and &9C7A :\ Replaced INC A 1880LDA &CD:AND #32:BEQ &9C74:BNE &9C3B :\ If HD, look for $.Library :\ CHANGED from &9C7A and &9C41 1890RTS:RTS :\ Why two extra RTSs??? 1900] 1910[OPT FNorg(&9DB8) :\ CHANGED from &9E07 1920EQUS ver$ :\ New version string 1930] 1940[OPT FNorg(&9F6E) :\ CHANGED from &9F9B 1950EQUB (MountCheck-1) DIV 256 :\ Ensure *MOUNT checks for LIB 1960EQUB (MountCheck-1) AND 255 1970] 1971[OPT FNorg(&A0C3) :\New area because 8114 area is too small 1972RTS 1973.BYE 1974LDY #5:LDA (&B0),Y:CMP #&09 :\ Get command, CC=Read, CS=Write 1975AND #&FD:EOR #&08:BEQ CommandOk :\ Jump if Read (&08) or Write (&0A) 1976LDA #&60:JMP CommandExit :\ Return 'bad command' otherwise :\ Replaced BRA with JMP 1977.CommandOk 1982JMP CommandSaveLp1 :\ Memory FULL 1983.SetCommand1 1984PHP:JMP SetCommand 1985] 1988[OPT FNorg(&AACA) :\ Select sector for BGET/BPUT :\ CHANGED from &AADD 1990JSR WaitNotBusy:LDA #1:STA &FC42:CLC :\ one sector 2000LDA &1001,X:AND #63:ADC #1:STA &FC43 :\ Set sector b0-b5 :\ CHANGED from &C201 2010LDA &1002,X:ADC #cyl0%:STA &FC44 :\ Set sector b8-b15 :\ CHANGED from &C202 2020LDA &1003,X:STA &1133:JMP SetRandom :\ Set sector b16-b21 :\ CHANGED from &C203 and &C333 2030NOP:NOP: :\ Why extra NOPs??? 2040\ next=&AAF0 :\ CHANGED from &AB03 2050] 2060[OPT FNorg(&AB57) :\ BPUT to hard drive :\ CHANGED from &AB6A 2070NOP:JMP &AB63 :\ Always jump to write :\ Replaced BRA with JMP :\ CHANGED from &AB76 2080: 2090.ResultCodes 2100EQUB &FF:EQUB &FF:EQUB &60:EQUB &FF 2110EQUB &50:EQUB &65:EQUB &48:EQUB &FF 2120] 2130[OPT FNorg(&AB72) :\ CHANGED from &AB83 2140NOP:NOP:NOP :\ Don't trample on IDE register 2150] 2160[OPT FNorg(&AB78) :\ CHANGED from &AB89 2170RTS :\ Remove IRQ routine 2180: 2190.UpdateDrive 2200LDA &85:ORA &1117:STA &85 :\ Merge with current drive :\ CHANGED from &C317 2210STA &1133:LDA #&7F:RTS :\ Store for any error :\ CHANGED from &C333 2220NOP 2230\ next=&AB87 :\ CHANGED from &ABB4 ??? Patch132 has AB97.... 2240] 2250[OPT FNorg(&ACBA) :\ BGET from hard drive :\ CHANGED from &ACC9 2260NOP:NOP :\ Always continue into read 2270] 2280NEXT 2290IF RIGHT$(file$,2)="30":file$=LEFT$(file$,LEN file$-2)+MID$(ver$,3) 2300PRINT"Save filename (";file$;:INPUT"): "A$:IF A$<>"":file$=A$ 2310OSCLI"Save "+file$+" "+STR$~mcode%+"+4000 FFFF0000 FFFF8000"