CPU 6502 PAGE 140 ;************************* ;* * ;* Apple FDC4 * ;* Bootloader * ;* * ;************************* ; ; Page Zero references ; loadptr EQU $26 bootsl EQU $2B wrkbyte EQU $3C sctnum EQU $3D trkfnd EQU $40 trknum EQU $41 ; ; Workspace references ; stack EQU $0100 trtbl EQU $02D6 buffer EQU $0300 trntbl EQU $0356 bladr EQU $0800 boot1 EQU $0801 ; ; Hardware references ; phoff EQU $C080 phon EQU $C081 motoron EQU $C089 drive0en EQU $C08A strobio EQU $C08C prepinp EQU $C08E ; ; external routines ; wait EQU $FCA8 iorts EQU $FF58 ; ORG $C600 boot0 LDX #$20 ; disk id bytes LDY #$00 LDX #$03 ; ; build a temporary read translate table ; loop1 STX wrkbyte TXA ASL BIT wrkbyte BEQ loop3 ORA wrkbyte EOR #$FF AND #$7E loop2 BCS loop3 LSR BNE loop2 TYA STA trntbl,X INY loop3 INX BPL loop1 ; ; get number of bootslot and save it ; JSR iorts TSX LDA stack,X ASL ASL ASL ASL STA bootsl TAX ; ; prepare controller's hardware for read ; LDA prepinp,X LDA drive0en,X LDA motoron,X ; ; pull arm back over 160 halftracks ; LDY #$C0 reseek LDA phoff,X TYA AND #$03 ASL ORA bootsl TAX LDA phon,X LDA #$56 JSR wait ; arm move delay DEY CPY #$FF BNE reseek NOP ; ; initalize pointers for read operation ; STA loadptr STA sctnum STA trknum LDA #$08 STA loadptr+1 ; ; read track 0/sector 0 to buffer ; reads CLC radr PHP rdD5 LDA strobio,X BPL rdD5 r1 EOR #$D5 BNE rdD5 rdAA LDA strobio,X BPL rdAA CMP #$AA BNE r1 NOP rd96 LDA strobio,X BPL rd96 CMP #$96 BEQ rhead PLP BCC reads EOR #$AD BEQ rdata0 BNE reads ; ; read the sector header ; rhead LDY #$03 notsec STA trkfnd rdsec LDA strobio,X BPL rdsec ROL STA wrkbyte rdsec2 LDA strobio,X BPL rdsec2 AND wrkbyte DEY BNE notsec PLP CMP sctnum BNE reads LDA trkfnd CMP trknum BNE reads BCS radr ; ; read the data field into buffer ; rdata0 LDY #$56 rdata1 STY wrkbyte rd1 LDY strobio,X BPL rd1 EOR trtbl,Y LDY wrkbyte DEY STA buffer,Y BNE rdata1 rdata2 STY wrkbyte rd2 LDY strobio,X BPL rd2 EOR trtbl,Y LDY wrkbyte STA (loadptr),Y INY BNE rdata2 rd3 LDY strobio,X BPL rd3 EOR trtbl,Y more BNE reads LDY #$00 dnib1 LDX #$56 dnib2 DEX BMI dnib1 LDA (loadptr),Y LSR buffer,X ROL LSR buffer,X ROL STA (loadptr),Y INY BNE dnib2 INC loadptr+1 INC sctnum LDA sctnum CMP bladr LDX bootsl BCC more JMP boot1