From 74a6d52420b641b11302b6d71aef198a2696a501 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Sat, 13 Apr 2019 10:33:15 -0700 Subject: [PATCH] support Choplifter copying --- src/id/inspect0.a | 4 +- src/id/trace32.a | 36 +++++- src/passport.a | 18 ++- src/patchers/choplifter.a | 257 ++++++++++++++++++++++++++++++++++++++ src/rwts.a | 3 +- src/strings/en.a | 3 + src/strings/enid.a | 3 +- 7 files changed, 306 insertions(+), 18 deletions(-) create mode 100644 src/patchers/choplifter.a diff --git a/src/id/inspect0.a b/src/id/inspect0.a index 9aff5ca..09838c1 100755 --- a/src/id/inspect0.a +++ b/src/id/inspect0.a @@ -218,7 +218,7 @@ IDBootloader sta gIsProDOS jsr IDVolumeName bcc + - jmp .useuniv + jmp UseUniversal + ; ; Dinkey-DOS (ProDOS file structure with DOS 3.3-ish RWTS in language card) @@ -227,7 +227,7 @@ IDBootloader ; jsr IDDinkeyDOS bcc + - jmp .useuniv + jmp UseUniversal + lda #s_dinkeydos jsr PrintByID lda #TRUE diff --git a/src/id/trace32.a b/src/id/trace32.a index 26b9702..bedd376 100644 --- a/src/id/trace32.a +++ b/src/id/trace32.a @@ -74,6 +74,11 @@ IDDOS32LO ldy #$03 jsr compare !byte $4C,$01,$03; JMP $0301 + bcc .exit + ldx #$37 + ldy #$03 + jsr compare + !byte $4C,$01,$03; JMP $0301 .exit rts } @@ -99,10 +104,15 @@ TraceDOS32LO jmp $0801 .TraceDOS32LOb - lda #<.TraceDOS32c - sta $0842 + ldy #$00 + lda $0837 + cmp #$4C + beq + + ldy #$0A ++ lda #<.TraceDOS32c + sta $0838,y lda #>.TraceDOS32c - sta $0843 + sta $0839,y jmp $0801 .TraceDOS32c @@ -138,7 +148,7 @@ TraceDOS32LO !byte $85,$3F !byte $E6,$3F !byte $6C,$3E,$00 - bcs .fail + bcs .tryChoplifter lda $03CC cmp #$B6 beq + @@ -174,6 +184,24 @@ TraceDOS32LO ldy $0300 jmp $0301 +.tryChoplifter + lda #$03 + ldx #$01 + ldy #$10 + jsr CompareMemory + !byte $A2,$2E ;LDX #$2E + !byte $9A ;TXS + !byte $84,$48 ;STY $48 + !byte $A2,$00 ;LDX #$00 + !byte $BC,$00,$03 ;LDY $0300,X + !byte $88 ;DEY + !byte $A9,$EA ;LDA #$EA + !byte $20,$26,$03 ;JSR $0326 + bcs .fail + lda #s_choplifter + jsr PrintByID + jmp Choplifter + ; something did not match, not comfortable tracing, ; but we know enough to know that the universal RWTS won't work, ; so we're done diff --git a/src/passport.a b/src/passport.a index 40544c4..489508e 100755 --- a/src/passport.a +++ b/src/passport.a @@ -411,17 +411,15 @@ ReadWithRWTS checksector lda $FFFF ; status of current sector in sector map (modified above) - pha cmp #kSectorCustomFirst ; call a custom routine before deciding what to do with this sector? bcc + cmp #kSectorCustomLast bcs + - pla jsr PreReadSector - pha ; replace status (on stack) with new status returned from PreReadSector -+ cmp #kSectorIgnore ; skip this sector? ++ pha ; replace status (on stack) with new status returned from PreReadSector + cmp #kSectorIgnore ; skip this sector? beq nextsector -+ cmp #kSectorSwitchToBuiltinRWTS ; switch to built-in RWTS before reading this sector? + cmp #kSectorSwitchToBuiltinRWTS ; switch to built-in RWTS before reading this sector? bne + lda gTriedUniv beq + @@ -499,12 +497,11 @@ checksector nextsector pla - dec checksector+1 lda checksector+1 - cmp #$FF bne .nodec dec checksector+2 .nodec + dec checksector+1 lda gSector sec sbc #$01 @@ -524,11 +521,11 @@ nextsector jsr ChangeTrack jsr IncProgress lda gTrack - bmi .pass + bmi Pass cmp gLastTrack - bcc .pass + bcc Pass jmp .read -.pass +Pass bit gMode bmi .passwrite lda #s_pass @@ -847,6 +844,7 @@ _applyToAll !source "patchers/holle.a" ; gIsHolle only !source "patchers/zoomgrafix.a" ; gIsPhoenix only !source "patchers/e7everywhere.a" ; gIsBoot0 || gIsProDOS only + !source "patchers/choplifter.a" ; gIsChoplifter only lda gPatchCount beq .nopatches diff --git a/src/patchers/choplifter.a b/src/patchers/choplifter.a new file mode 100644 index 0000000..5a24a77 --- /dev/null +++ b/src/patchers/choplifter.a @@ -0,0 +1,257 @@ +;------------------------------- +; #Choplifter +; insane protection by Roland Gustafsson +; licensed by Broderbund, Gebelli, and others +; +; module by qkumba +;------------------------------- +!zone { +.exit rts ; reachable only via inspect + +Choplifter + bit gMode ; nothing to do here in verify-only mode + bpl .exit + lda #$00 + sta gCommand + sta dct+1 + jsr ChangeTrackNW + jsr IncProgress + +.read + lda KEY + bmi .cancel + asl gTrack + jsr ReadChoplifter + lsr gTrack + jsr WriteTrackNA + lda gTrack + clc + adc #$01 + jsr ChangeTrackNW + jsr IncProgress + lda gTrack + cmp #$23 + bne .read + jsr .cleanup + jmp Pass + +.cleanup + lda $C0E8 + lda #$01 + sta gCommand + sta dct+1 + rts + +.fatal + jsr .cleanup + ; if we get to here, we've + jmp FatalError ; decided the read error is fatal + +.cancel + jsr .cleanup + jmp Cancel + +ReadChoplifter + lda #BASEPAGE + sta modsrc+1 + lda #$00 + sta modsrc +- jsr ReadSector ; really just seek + lda $C0E9 ; turn the drive back on + ; no need for spin-up because we are fast enough + ldx #$04 + lda gTrack + beq .settrack00 + cmp #$12 + bcc .settrack01 + cmp #$16 + bcc .ignore + beq .readtrack0B + cmp #$3E + bcs .checktrack1E + jsr .readtrack + inc gTrack + lda gTrack + lsr + bcs - + dec gTrack +.ignore + rts + +.readtrack0B + +.checkkey1 + lda KEY + bmi .cancel + jsr .readnib +- cmp #$DD + bne .checkkey1 + jsr .readnib +-- cmp #$F5 + bne - + jsr .readnib + cmp #$D5 + bne -- ; this is the same bug + ldx #$03 +- jsr .read4x4 + jsr .read4x4 + jsr .read4x4 + sta cmp1+0,x + dex + bpl - + rts + +.checktrack1E + cmp #$40 + bcs .checktrack20 + rts + +.settrack00 + lda #$D5 + sta cmp1+1 + sta cmp2+1 + lda #$DD + sta cmp1+0 + sta cmp2+0 + !byte $2C +.settrack01 + ldx #$08 + +.readtrack + stx tmpx + ldx #3 + +.retry0 + dex + beq .jmpfatal + +.checkkey0 + lda KEY + bmi .jmpcancel + jsr .readnib +- cmp cmp2+1 + bne .checkkey0 + jsr .readnib +-- cmp cmp2+0 + bne - + jsr .readnib + cmp cmp1+1 + bne -- ; this is a bug + ; it allows PR0 PR1 [any] PR1 PR2 instead of requiring PR0 PR1 PR2 + ldy #0 +-- jsr .read4x4 + sta (modsrc), y + iny + bne -- +- lda $C0EC + bpl - + cmp cmp1+0 + bne .retry0 + inc modsrc+1 + dec tmpx + bne -- + jsr .readnib + sta cmp1+1 ; prologue 3 + jsr .readnib + sta cmp2+0 ; prologue 2 + jsr .readnib + sta cmp2+1 ; prologue 1 + jsr .readnib + sta cmp1+0 ; epilog + rts + +.jmpfatal + jmp .fatal + +.jmpcancel + jmp .cancel + +.checktrack20 + beq .readtrack20 + cmp #$44 + beq .readtrack22 + rts + +.readtrack20 + ldx #1 + jsr .readtrack + lda (BASEPAGE<<8)+$C5 + sta .prolog1+1 + lda (BASEPAGE<<8)+$CC + sta .prolog2+1 + lda (BASEPAGE<<8)+$D3 + sta .prolog3+1 + +.checkkey2 + lda KEY + bmi .jmpcancel + jsr .readnib +.prolog1 +- cmp #$D1 ; SMC + bne .checkkey2 + jsr .readnib +.prolog2 +-- cmp #$D1 ; SMC + bne - + jsr .readnib +.prolog3 + cmp #$D1 ; SMC + bne -- ; this is the same bug + nop ; timing bits + ldx #$00 +- jsr .read4x4 + sta (BASEPAGE+1)<<8,x + inx + jsr .read4x4 + sta (BASEPAGE+1)<<8,x + inx + jsr .read4x4 + sta (BASEPAGE+1)<<8,x + inx + cmp #$EA + bne - + rts + +.readtrack22 + ldx #$40 + ldy #0 + +.checkkey3 + dey + bne + + dex + beq ++ ++ lda KEY + bmi .jmpcancel + jsr .readnib +- cmp #$D5 + bne .checkkey3 + jsr .readnib +-- cmp #$FF + bne - + jsr .readnib + cmp #$DD + bne -- ; this is the same bug + ldx #$00 +- jsr .read4x4 + sta BASEPAGE<<8,x + inx + bne - +++ rts + +.read4x4 +- lda $C0EC + bpl - + sec + rol + sta tmp +- lda $C0EC + bpl - + and tmp + rts + +.readnib +- lda $C0EC + bpl - + rts +} diff --git a/src/rwts.a b/src/rwts.a index 27d1b31..51ff023 100755 --- a/src/rwts.a +++ b/src/rwts.a @@ -199,5 +199,6 @@ _track !byte $00 _sector !byte $00 !word dct gAddress !word $1F00 - !byte $00,$00,$01,$00,$FE,$60,$01,$00,$00 + !byte $00,$00 +gCommand !byte $01,$00,$FE,$60,$01,$00,$00 dct !byte $00,$01,$EF,$D8,$00 diff --git a/src/strings/en.a b/src/strings/en.a index fa5549a..e273964 100755 --- a/src/strings/en.a +++ b/src/strings/en.a @@ -133,6 +133,7 @@ StringTable !word .hoffman !word .diskvol0 !word .e7everywhere + !word .choplifter ; ; Text can contain substitution strings, which ; are replaced by current values at runtime. Each @@ -486,4 +487,6 @@ StringTable !text "T%t,S%0 Disk requires volume number 000",$8D,$00 .e7everywhere !text "T%t,S%0 Found E7 Everywhere protection",$8D,$00 +.choplifter + !text "T00,S01 Found Choplifter protection",$8D,$00 } diff --git a/src/strings/enid.a b/src/strings/enid.a index 8ea28a4..899f190 100644 --- a/src/strings/enid.a +++ b/src/strings/enid.a @@ -119,4 +119,5 @@ s_holle = $71 s_hoffman = $72 s_diskvol0 = $73 s_e7everywhere=$74 -STRINGCOUNT = $75 +s_choplifter = $75 +STRINGCOUNT = $76