From 648507f1fd770f5cb06e9ffc7cb26cf418bfae33 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Wed, 26 May 2021 19:22:36 -0700 Subject: [PATCH] 5-5-5 WIP --- src/apicode.a | 14 +- src/id/555.a | 29 ++++ src/id/inspect0.a | 14 +- src/passport.a | 2 + src/patchers/555.a | 388 +++++++++++++++++++++++++++++++++++++++++++++ src/strings/en.a | 7 +- src/strings/enid.a | 1 + 7 files changed, 444 insertions(+), 11 deletions(-) create mode 100644 src/id/555.a create mode 100644 src/patchers/555.a diff --git a/src/apicode.a b/src/apicode.a index 8ff1176..2d5e1d0 100644 --- a/src/apicode.a +++ b/src/apicode.a @@ -52,12 +52,7 @@ ; instead of falling back to built-in RWTS ; compile-time flag, no way to change at runtime -;gIs13Sector - !byte FALSE ; 0=true, 1=false - ; reset before each operation - ; set in IDBootFailure() after reading T00 - -;gIsInfocom18 +;gIsRW18 !byte FALSE ; 0=true, 1=false ; reset before each operation ; set in IDBootFailure() after reading T00 @@ -67,7 +62,12 @@ ; reset before each operation ; set in IDBootloader() after reading T00,S00 -;gIsRW18 +;gIs13Sector + !byte FALSE ; 0=true, 1=false + ; reset before each operation + ; set in IDBootFailure() after reading T00 + +;gIsInfocom18 !byte FALSE ; 0=true, 1=false ; reset before each operation ; set in IDBootFailure() after reading T00 diff --git a/src/id/555.a b/src/id/555.a new file mode 100644 index 0000000..a72039d --- /dev/null +++ b/src/id/555.a @@ -0,0 +1,29 @@ +;------------------------------- +; ID555 +; identify 555 bootloader +; +; in: track buffer contains T00,S00 +; out: C clear if 555 bootloader found +; C set otherwise +; all registers clobbered +; all other flags clobbered +; +; tested with +; - Bumble Games +;------------------------------- +ID555 + lda #8 + ldy #22 + jsr SearchSector + !byte $85,$27 ; STA $27 + !byte $E8 ; INX + !byte $86,WILDCARD ; STX $xx + !byte $84,WILDCARD ; STY $xx + !byte $B9,WILDCARD,$08 ; LDA $08xx,Y + !byte $85,$3D ; STA $3D + !byte $20,WILDCARD,$08 ; JSR $08xx + !byte $A4,WILDCARD ; LDY $xx + !byte $C8 ; INY + !byte $C4,WILDCARD ; CPY $xx + !byte $90,$EF ; BCC *-$0F + rts diff --git a/src/id/inspect0.a b/src/id/inspect0.a index cea9c90..eebc606 100755 --- a/src/id/inspect0.a +++ b/src/id/inspect0.a @@ -315,6 +315,14 @@ IDBootloader jsr PrintByID lda #TRUE sta gIsHolle +; +; 555 bootloader +; ++ jsr ID555 + bcs + + lda #s_555 + jsr PrintByID + jmp Do555 + jmp UseUniversal } @@ -442,7 +450,7 @@ VerifyInfocom18 .RW18 jsr .rw18pro - bne -- + bne .badsect ldx gIsRW18 beq .verifyrw18 sta gIsRW18 @@ -547,10 +555,10 @@ VerifyInfocom18 jsr ReadNib6 ; checksum eor $2C eor $2D - bne .badrw18 + bne + jsr ReadNib6 ; epilogue eor #$AA - rts ++ rts read13 lda $C0E9 diff --git a/src/passport.a b/src/passport.a index 1771b00..20e8ae9 100755 --- a/src/passport.a +++ b/src/passport.a @@ -78,6 +78,7 @@ FirstMover !source "id/davidson.a" !source "id/holle.a" !source "id/phoenix.a" + !source "id/555.a" !source "print.a" !source "compare.a" !source "modify.a" @@ -391,6 +392,7 @@ AnalyzeTrack !source "patchers/b4bbbasic.a" ; gPossibleB4BBBasic only !source "patchers/errord51.a" ; gIsLowDOS only !source "patchers/sigcheck.a" ; gIsDiversi only + !source "patchers/555.a" ; gIs555 only _checkPatchCount lda gPatchCount diff --git a/src/patchers/555.a b/src/patchers/555.a new file mode 100644 index 0000000..206396e --- /dev/null +++ b/src/patchers/555.a @@ -0,0 +1,388 @@ +;------------------------------- +; #555 +; RWTS reads 5 sectors from +; three consecutive half-tracks +; +; module by qkumba +; +; tested on +; - Bumble Games +;------------------------------- +!zone { + jmp .exit2 ; reachable only via inspect + +.refindPC + inc $3E + sec + !byte $A9 +Do555 + clc + inc $3E + php + +.findPC + lda #8 + ldy #3 + ldx $3E + jsr CompareMemory + !byte $A9,WILDCARD ; LDA #$xx + !byte $48 ; PHA + bcc .checkpha + ldy #0 + lda ($3E),y + jsr $F88E ; INSDS2 + lda $2F + sec + adc $3E + sta $3E + bcc .findPC + jmp .fatal + +.checkpha + plp + bcc .refindPC + + lda #0 + sta .curtrk+1 + ldy #1 + adc ($3E),y ; add 1, carry is set by CMP + sta .initPC+1 + tya +.loopsect + sta gSector + jsr ReadSector + bcs .jmpexit + lda #8 + sta $3B +.initPC + ldx #0 ; SMC + ldy #5 + jsr CompareMemory + !byte $46, $4A ; LSR $4A + !byte $20, WILDCARD, $04 ; JSR $04xx + bcc .foundstage + ldy gSector + iny + tya + and #$0F + bne .loopsect +.jmpexit + jmp .fatal + + ;search for seek routine + ;so we can count calls to whole-track seek + +.foundstage + lda gSector + sta .cmpsect+1 + ldy $803,x +.retrystage + sty .stagePC1+1 + sty .stagePC5+1 + sty .patch1+1 + iny + sty .stagePC3+1 + sty .stagePC6+1 + iny + sty .stagePC2+1 + iny + sty .stagePC4+1 + sty .patch2+1 + +.stagePC1 + lda $800 ; SMC + cmp #$20 + bne .jmpexit +.stagePC2 + lda $800 ; SMC + cmp #4 + bne .jmpexit +.stagePC3 + ldy $800 ; SMC +.stagePC4 + cpy #$D1 ; SMC + beq .foundseek +.stagePC5 + ldx #$D1 ; SMC + bne .retrystage ; always + +.foundseek + stx $3A + +.walkcode + ldy #0 + lda ($3A),y + cmp #$AA + beq .isldx + cmp #$A2 + bne .tryseek + iny +.isldx + iny + lda ($3A),y + cmp #$20 + bne .sizeinst + iny +.skipjsr2 + iny +.skipjsr1 + tya + bne .skipinst ; always + +.tryseek + cmp #$20 + bne .trylda + iny + iny + lda ($3A),y + cmp #4 + bne .skipjsr1 + dey + lda ($3A),y + cmp .stagePC5+1 + bcc .skipjsr2 + bne .followjsr + inc .curtrk+1 + bne .skipjsr2 ; always + +.followjsr + sta $3A + bcs .walkcode + +.trylda + lda #8 + ldy #3 + ldx $3A + jsr CompareMemory + !byte $38 ; SEC + !byte $66, $4A ; ROR $4A + bcc .foundpart + +.sizeinst + ldy #0 + lda ($3A),y + jsr $F88E ; INSDS2 + lda $2F +.skipinst + sec + adc $3A + sta $3A + bcc .walkcode + jmp .fatal + + ; success! + ; found where the partial tracks start + ; read whole tracks to this point + ; then the partial tracks + ; and then the rest of the disk + +.foundpart + jsr IncProgress + lda #BASEPAGE + sta gAddress+1 + +.copytracks + ldx #0 + stx gSector + ldy #$10 + jsr .readwrite + lda gTrack +.curtrk + cmp #00 ; SMC + bne .notpartial + jsr .setup2 + ldx #1 + ldy #6 + jsr .readsectors + sec + rol gTrack + dec dct+1 ; half-track stepping! + ldx #6 + ldy #11 + jsr .readsectors + inc gTrack + ldx #11 + ldy #16 + jsr .readsectors + lsr gTrack + dec gTrack + inc dct+1 ; back to normal + jsr .writesectors + inc gTrack + +.notpartial + jsr .setup1 + lda gTrack + cmp #$23 + bcc .copytracks + jsr IncProgress + jsr .cleanup + jmp .exit + +.readwrite + jsr .readsectors + +.writesectors + jsr WriteTrackNA + jsr IncProgress + lda KEY + bmi .cancel + ldx gTrack + inx + txa + jmp ChangeTrackNW + +.readsectors + sty .endsector+1 +.readsector + txa + jsr ChangeSector +.retryread + jsr ReadSector + bcs .maybefatal + lda gTrack + bne .notpatch + lda gSector +.cmpsect + cmp #$00 ; SMC + bne .notpatch + +.stagePC6 + ldy #00 ; SMC + lda $3A + adc #$0E + sta ($3E),y + sec + sbc #3 + tax + lda $3F + sbc #BASEPAGE + ldy #15 + jsr modify +.patch1 + !byte $4C,$00,$04 ; JMP $04xx + !byte $48 ; PHA + !byte $A5,$FC ; LDA $FC + !byte $4A ; LSR + !byte $69,$01 ; ADC #$01 + !byte $85,$41 ; STA $41 + !byte $68 ; PLA +.patch2 + !byte $4C,$00,$04 ; JMP $04xx + txa + tay + dey + dey + dey + dey + lda #$0F + sta ($3E),y + tya + sec + sbc #6 + tay + lda #$EA + sta ($3E),y + dey + dey + dey + lda ($3E),y + cmp #$41 + bne .notpatch + lda #$EA + sta ($3E),y + +.notpatch + ldx gSector + inx +.endsector + cpx #00 ; SMC + bne .readsector + ldy #12 + jsr SearchTrack + !byte $C9,$FF ; CMP #$FF + !byte $D0,$0A ; BNE *+$0C + !byte $EA ; NOP + !byte $BD,$8C,$C0 ; LDA $C08C,X + !byte $10,$FB ; BPL *-3 + !byte $C9,$FF ; CMP #$FF + bcc .patchepi + +.ignore + rts + +.cancel + jsr .cleanup + jmp Cancel + +.maybefatal + lda $BDF2 + cmp #$F0 + jsr .cleanup + bcc .retryread + lda gTrack + cmp #$12 + bcc .fatal + lda gSector + beq .ignore +.fatal + jmp FatalError + +.patchepi + inx + ldy #1 + pha + jsr modify + !byte $DE + txa + clc + adc #10 + tax + ldy #1 + pla + pha + jsr modify + !byte $AA + txa + clc + adc #$52 + tax + ldy #1 + pla + pha + jsr modify + !byte $DE + txa + clc + adc #10 + tax + ldy #1 + pla + jsr modify + !byte $AA + rts + +.setup2 + ldy #$CD + bne .patchDOS2 + +.cleanup + lda #1 + sta dct + ldx #$F0 + !byte $AD +.setup1 + ldx #$90 + ldy #$B9 + +.patchDOS1 + stx $BDF2 +.patchDOS2 + sty $BE2B + rts + +.exit + jmp Pass + +.exit2 +} diff --git a/src/strings/en.a b/src/strings/en.a index e639ce7..f50682c 100755 --- a/src/strings/en.a +++ b/src/strings/en.a @@ -163,6 +163,7 @@ StringTableLow !byte <.targetfile !byte <.targetcffa !byte <.rw18 + !byte <.x555 StringTableHigh !byte >.header @@ -309,6 +310,7 @@ StringTableHigh !byte >.targetfile !byte >.targetcffa !byte >.rw18 + !byte >.x555 ; ; Text can contain substitution strings, which @@ -344,7 +346,7 @@ StringTableHigh .passport !text "Passport ",$00 .header - !text "@",s_passport,"by 4am@",s_space7,"@",s_space7," 2021-05-22",$00 + !text "@",s_passport,"by 4am@",s_space7,"@",s_space7," 2021-05-26",$00 .bar9 !text "_________",$00 .bar18 @@ -719,4 +721,7 @@ StringTableHigh !text "@",s_found,"bad block @",s_protectioncheck,$00 .rw18 !text "@",s_found,"RW18-sector format",$8D,$00 +.x555 + !text "@",s_found,"555 @",s_bootloader,$8D + !text "Doing it the hard way.",$8D,$00 } diff --git a/src/strings/enid.a b/src/strings/enid.a index 8d671b9..a4fc3e8 100644 --- a/src/strings/enid.a +++ b/src/strings/enid.a @@ -146,3 +146,4 @@ s_targetdisk = $8C s_targetfile = $8D s_targetcffa = $8E s_rw18 = $8F +s_555 = $90