From 2fb3c16c831cd9ae637ef002182a3b05f596f181 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Wed, 26 Sep 2018 10:20:03 -0700 Subject: [PATCH] convert RDOS13 to 16 sectors + support SSI protection also re-enable RAM disk after cancel --- Makefile | 2 +- src/apicode.a | 4 ++ src/apidefs.a | 8 ++- src/id/trace32.a | 75 ++++++++++++++++++-- src/memory.a | 4 +- src/mli.a | 6 +- src/mods/t00only.a | 1 + src/passport.a | 12 ++-- src/patchers/dos32.a | 16 ++--- src/patchers/rdos13.a | 157 +++++++++++++++++++++++++++++++++++++++++ src/patchers/ssi.a | 33 +++++++++ src/standarddelivery.a | 15 ++++ src/strings/en.a | 10 ++- src/strings/enid.a | 4 +- winmake.bat | 2 +- 15 files changed, 316 insertions(+), 33 deletions(-) create mode 100644 src/patchers/rdos13.a create mode 100644 src/patchers/ssi.a diff --git a/Makefile b/Makefile index e5357e4..6d4bcb0 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ asm: cd src/mods && $(ACME) universalrwts.a $(EXOMIZER) raw -q build/universalrwts.bin -o build/universalrwts.tmp printf "\xB8\x00" | cat - build/universalrwts.tmp > build/universalrwts.pak - cd src/mods && $(ACME) t00only.a + cd src/mods && $(ACME) -r ../../build/t00only.lst t00only.a $(EXOMIZER) raw -q build/t00only.bin -o build/t00only.tmp printf "\x20\x00" | cat - build/t00only.tmp > build/t00only.pak cd src && $(ACME) -r ../build/passport.lst passport.a 2> ../build/relbase.log diff --git a/src/apicode.a b/src/apicode.a index 21b43b1..c65b9e0 100644 --- a/src/apicode.a +++ b/src/apicode.a @@ -54,6 +54,10 @@ ; set in IDBootloader() after reading T00,S00 FIRSTFILTER +;gIsRDOS + !byte FALSE ; 0=true, 1=false + ; reset before each operation + ; set in IDBootloader() after reading T00,S00 ;gIsDavidson !byte FALSE ; 0=true, 1=false ; reset before each operation diff --git a/src/apidefs.a b/src/apidefs.a index 9cf64ca..09da977 100644 --- a/src/apidefs.a +++ b/src/apidefs.a @@ -10,6 +10,7 @@ FALSE = $01 ID_DOS33p = $00 ID_DOS32 = $01 ID_DOS32LO = $02 +ID_RDOS13 = $03 ;------------------------------- ;MECC fast-load variants @@ -48,6 +49,7 @@ RELBASE = $2000 ; dummy assignment for first build ; to allow calculation of proper value } LOWPOINT = $4300 ; lowest available address for code +HIGHPOINT = $B200 ; highest available address+1 for code BASEPAGE = $10 ; Special Delivery tracer assumes ; this is $10, so don't change it! @@ -57,7 +59,7 @@ BASEPAGE = $10 ; Special Delivery tracer assumes ; compressed code to work ;------------------------------- -APIEND = $B600 +APIEND = HIGHPOINT gMode = APIEND-$01 ; byte gPatchCount = gMode-$01 ; byte gTriedUniv = gPatchCount-$01 ; byte @@ -95,9 +97,10 @@ gForceDiskVol = gPolarwareTamperCheck-$01 ; byte gIsAdvent = gForceDiskVol-$01 ; byte gIsPanglosDOS = gIsAdvent-$01 ; byte gIsDavidson = gIsPanglosDOS-$01 ; byte +gIsRDOS13 = gIsDavidson-$01 ; byte ;LASTFILTER ; add new gIs* above this line ;gMECCFastloadType is a special case integer whose default value cannot be #FALSE -gMECCFastloadType = gIsDavidson-$01 ; byte +gMECCFastloadType = gIsRDOS13-$01 ; byte gOnAClearDayYouCanReadForever = gMECCFastloadType-$01 ; byte gUsingRAMDisk = gOnAClearDayYouCanReadForever-$01 ; byte @@ -164,6 +167,7 @@ ConstructStandardDelivery = jConstructStandardDelivery !warn "gIsAdvent=",gIsAdvent !warn "gIsPanglosDOS=",gIsPanglosDOS !warn "gIsDavidson=",gIsDavidson +!warn "gIsRDOS13=",gIsRDOS13 !warn "gOnAClearDayYouCanReadForever=",gOnAClearDayYouCanReadForever !warn "gUsingRAMDisk=",gUsingRAMDisk !warn "gRAMDiskRef=",gRAMDiskRef diff --git a/src/id/trace32.a b/src/id/trace32.a index 463868d..191d909 100644 --- a/src/id/trace32.a +++ b/src/id/trace32.a @@ -143,8 +143,11 @@ TraceDOS32LO cmp #$B6 beq + cmp #$36 + beq + + cmp #$B2 ;RDOS bne .fail -+ + clc ++ php ; ; set up RWTS entry point and other self-modified vectors ; that depend on where the RWTS is in memory @@ -177,7 +180,32 @@ TraceDOS32LO .fail jmp FatalError +.RDOSPatch + lda #$B3 + ldx #$00 ; check for "JMP $B974;LDY #$00" + ldy #$05 ; at RWTS entry point + jsr CompareMemory ; (i.e. $B300) + !byte $4C,$74,$B9,$A0,$00 + bcs .fail + lda #TRUE + sta gIsRDOS13 + lda #s_rdos13 + jsr PrintByID + + lda #<.RDOS13Hook + sta jCallRWTS+1 + lda #>.RDOS13Hook + sta jCallRWTS+2 + + lda #$C9 ; override address prologue to avoid reliance on $48 + sta $BC75 + lda #$D4 + sta $BC76 + bne .patchmap + TraceDOS32d + plp + bcc .RDOSPatch lda jCallRWTS+2 ldx #$00 ; check for "STY $48;STA $49" ldy #$04 ; at RWTS entry point @@ -205,6 +233,8 @@ TraceDOS32d ; if data prologue is not found sta (modsrc),y +.patchmap + ; skip sectors $0D, $0E, and $0F on all tracks ; since this is a 13-sector disk @@ -226,6 +256,16 @@ TraceDOS32d dex bpl .A +; set flag for patcher + + lda #TRUE + sta gIsDOS32 + +;retain track 00 for RDOS because we can + + ldy gIsRDOS13 + beq + + ; skip T00,S00-S0A ; since we're going to construct our own bootloader later @@ -234,11 +274,6 @@ TraceDOS32d dey bpl - -; set flag for patcher - - lda #TRUE - sta gIsDOS32 - ; check for MUSE sector doubling RWTS lda jCallRWTS+2 ldx #$09 @@ -279,8 +314,34 @@ FFer iny cpy #$9A bne .G - clc +- clc rts + sec rts + +.RDOS13Hook + ldx _sector + stx $BAF6 + lda _track + sta $BAF5 + bne + + cpx #$0C + beq - ;lie that T00S0C exists + +;standard 13-sector prologue on T00 +;because we can't decode the 16-sector version + lda #$D5 + sta $BC76 + lda #$B5 + sta $BC8B + ++ lda gAddress + sta $BAF7 + lda gAddress+1 + sta $BAF8 + ldx #1 + stx $B718 ;count of sectors (low part) + dex + stx $B719 ;count of sectors (high part) + jmp $BA00 } diff --git a/src/memory.a b/src/memory.a index c8dbcf4..62bcaaa 100755 --- a/src/memory.a +++ b/src/memory.a @@ -12,8 +12,8 @@ ; 2000..35FF - clobbered by Special Delivery tracer ; 3600..3FFF - clobbered by lomem DOS 3.3 / Special Delivery tracers ; 4000..42FF - backup of zero page, page 3, page $BF (SaveProDOS, SwapProDOS) -; 4300..B5FF - program code -; B600..BFFF - clobbered by DOS 3.3 boot tracer +; 4300..B1FF - program code +; B200..BFFF - clobbered by DOS boot tracer (RDOS is B200+, DOS 3.x is B600+) ;------------------------------- diff --git a/src/mli.a b/src/mli.a index e45c032..fba5f1a 100755 --- a/src/mli.a +++ b/src/mli.a @@ -680,14 +680,16 @@ WriteRAMToDisk bne - jsr IncProgress - lda #TRUE - sta gUsingRAMDisk clc .exit + lda #TRUE + sta gUsingRAMDisk rts .cancel + lda #TRUE + sta gUsingRAMDisk jmp Cancel } diff --git a/src/mods/t00only.a b/src/mods/t00only.a index 7f3af0d..c1d27af 100644 --- a/src/mods/t00only.a +++ b/src/mods/t00only.a @@ -108,6 +108,7 @@ AnalyzeT00 !source "../patchers/dos32dlm.a" !source "../patchers/microfun.a" !source "../patchers/panglosdos.a" + !source "../patchers/rdos13.a" ;add only above this line rts diff --git a/src/passport.a b/src/passport.a index f9473dd..abd9862 100755 --- a/src/passport.a +++ b/src/passport.a @@ -4,7 +4,7 @@ ;------------------------------- ; Passport ; a 4am hack -; (c) 2016-7 by 4am +; (c) 2016-8 by 4am ; ; Permission is hereby granted, free of charge, to any ; person obtaining a copy of this software and associated @@ -88,7 +88,7 @@ UNIV_D3 = $B8FC ldx #$00 FM lda LastMover - 256,x - sta $B500,x + sta HIGHPOINT-$100,x inx bne FM dec FM+2 @@ -375,6 +375,9 @@ ReadWithRWTS .read lda KEY bpl checksector + bit STROBE + cmp #$e0 ;ignore backtick (MAME debug break) + beq checksector jmp Cancel checksector lda $FFFF ; status of current sector in sector map (modified above) @@ -796,6 +799,7 @@ _applyToAll !source "patchers/advent.a" ; gIsAdvent only !source "patchers/davidsonforth.a" ; gIsDavidson only !source "patchers/davidsonasm.a" ; gIsDavidson only + !source "patchers/ssi.a" ; gIsRDOS13 only lda gPatchCount beq .nopatches @@ -818,10 +822,10 @@ LastMover !ifdef PASS2 { } else { ;PASS2 !set PASS2=1 - !warn "RELBASE = ", $B600 - (LastMover - FirstMover) + !warn "RELBASE = ", HIGHPOINT - (LastMover - FirstMover) } } else { - !if ($B600 - (LastMover - FirstMover)) < LOWPOINT { + !if (HIGHPOINT - (LastMover - FirstMover)) < LOWPOINT { !serious "code is too large to fit in available space!" } } diff --git a/src/patchers/dos32.a b/src/patchers/dos32.a index 393107d..6f2f5ac 100644 --- a/src/patchers/dos32.a +++ b/src/patchers/dos32.a @@ -7,8 +7,8 @@ bpl .exit lda gIsDOS32 bne .exit - bit gMode ; nothing to do here in verify-only mode - bpl .exit + lda gIsRDOS13 + beq .exit ; sector 1 @@ -54,21 +54,15 @@ ; sector 0 + ldx #ID_DOS32LO .cr lda #$d1 ; set at runtime cmp #$3D beq + ldx #ID_DOS32 - jsr ConstructStandardDelivery - jmp ++ - -+ ldx #ID_DOS32LO - jsr ConstructStandardDelivery - -++ bit gMode ; do not print in verify mode - bpl +++ ++ jsr ConstructStandardDelivery lda #s_bootwrite jsr PrintByID -+++ inc gPatchCount + inc gPatchCount .exit } diff --git a/src/patchers/rdos13.a b/src/patchers/rdos13.a new file mode 100644 index 0000000..366659e --- /dev/null +++ b/src/patchers/rdos13.a @@ -0,0 +1,157 @@ +;------------------------------- +; #RDOS13 +; patch RDOS to be 16-sector compatible +; +; module by qkumba +;------------------------------- +!zone { + bit gMode ; nothing to do here in verify-only mode + bpl .jmpexit + ldy gIsRDOS13 + beq .okay +.jmpexit + jmp .exit + +.okay + +;build 6-and-2 denibbilisation table for reading + + ldx #$16 +-- stx $48 + txa + asl + bit $48 + beq + + ora $48 + eor #$ff + and #$7e +- bcs + + lsr + bne - + tya + sta (BASEPAGE * $100) + $6B9 - $16, x + +;and 6-and-2 nibbilisation table for writing + + txa + ora #$80 + sta (BASEPAGE * $100) + $B70, y + iny ++ inx + bpl -- + + lda #8 + ldx #$C9 + ldy #3 + jsr modify + !byte $20,$2A,$BB ;JSR $BB2A + +;enable 16-sector address prologue + + lda #$0A + ldx #$75 + ldy #2 + jsr modify + !byte $C9,$D5 ;CMP #$D5 + + lda #$0A + ldx #$8B + ldy #1 + jsr modify + !byte $96 + +;replace 6-and-2 encoder routine +;and introduce DOS-order lookup + + lda #9 + ldx #0 + ldy #$41 + jsr modify + !byte $A2,$00 ;LDX #$00 + !byte $A0,$02 ;LDY #$00 + !byte $88 ;DEY + !byte $B1,$3E ;LDA ($3E),Y + !byte $4A ;LSR + !byte $3E,$00,$BF ;ROL $BF00,X + !byte $4A ;LSR + !byte $3E,$00,$BF ;ROL $BF00,X + !byte $99,$00,$BE ;STA $BE00,Y + !byte $E8 ;INX + !byte $E0,$56 ;CPX #$56 + !byte $90,$ED ;BCC $BC04 + !byte $A2,$00 ;LDX #$00 + !byte $98 ;TYA + !byte $D0,$E8 ;BNE $BC04 + !byte $A2,$55 ;LDX #$55 + !byte $BD,$00,$BF ;LDA $BF00,X + !byte $29,$3F ;AND #$3F + !byte $9D,$00,$BF ;STA $BF00,X + !byte $CA ;DEX + !byte $10,$F5 ;BPL $BC1E + !byte $60 ;RTS + !byte $AC,$F6,$BA ;LDY $BAF6 + !byte $B9,$31,$BB ;LDA $BB31,Y + !byte $60 ;RTS + !byte $00,$0D,$0B,$09,$07,$05,$03,$01 + !byte $0E,$0C,$0A,$08,$06,$04,$02,$0F + + lda #$9 + ldx #$89 + ldy #3 + jsr modify + !byte $04 ;sync delay + !byte $48 ;PHA + !byte $68 ;PLA + +;replace 6-and-2 decoder routine + + lda #$0A + ldx #$16 + ldy #1 + jsr modify + !byte $56 + + lda #$0A + ldx #$2B + ldy #2 + jsr modify + !byte $23,$B8 + + lda #$0A + ldx #$3C + ldy #2 + jsr modify + !byte $23,$B8 + + lda #$0A + ldx #$4C + ldy #2 + jsr modify + !byte $23,$B8 + + lda #$0A + ldx #$C1 + ldy #$18 + jsr modify + !byte $A0,$00 ;LDY #$00 + !byte $A2,$56 ;LDX #$56 + !byte $CA ;DEX + !byte $30,$FB ;BMI $BCC3 + !byte $B9,$00,$BE ;LDA $BE00,Y + !byte $5E,$00,$BF ;LSR $BF00,X + !byte $2A ;ROL + !byte $5E,$00,$BF ;LSR $BF00,X + !byte $2A ;ROL + !byte $91,$3E ;STA ($3E),Y + !byte $C8 ;INY + !byte $D0,$ED ;BNE $BCC5 + !byte $60 ;RTS + + ldx #ID_RDOS13 + jsr ConstructStandardDelivery + + lda #s_bootwrite + jsr PrintByID + +.exit +} diff --git a/src/patchers/ssi.a b/src/patchers/ssi.a new file mode 100644 index 0000000..a5ef41d --- /dev/null +++ b/src/patchers/ssi.a @@ -0,0 +1,33 @@ +;------------------------------- +; #SSI Weak-bit protection +; +; module by qkumba +;------------------------------- +!zone { + bit gMode ; nothing to do here in verify-only mode + bpl .exit + ldy gIsRDOS13 + bne .exit + + ldy #$0D + jsr SearchTrack + !byte $F0,$17 ; BEQ *+$19 + !byte $20,$65,$BC; JSR $BC65 + !byte $B0,$F7 ; BCS *-7 + !byte $C1,$00 ; CMP ($00,X) + !byte $C1,$00 ; CMP ($00,X) + !byte $EA ; NOP + !byte $EA ; NOP + bcs .exit + + sta gDisplayBytes + pha + lda #s_ssi + jsr PrintByID + pla + ldy #$01 + jsr modify + !byte $D0 ; BNE + +.exit +} diff --git a/src/standarddelivery.a b/src/standarddelivery.a index b993279..ff68ee5 100644 --- a/src/standarddelivery.a +++ b/src/standarddelivery.a @@ -17,6 +17,8 @@ ConstructStandardDelivery beq .construct32 dex beq .construct32lo + dex + beq .constructrdos .construct33p lda #SD_DOS32LO + bne + + +.constructrdos + lda #SD_RDOS13 + sta .A+1 stx .A+2 @@ -136,3 +143,11 @@ SD_DOS32LO ; track 2 !byte $2A,$00,$00,$00,$35,$34,$33,$32,$31,$30,$2F,$2E,$2D,$2C,$2B,$00 !byte $C0 + +SD_RDOS13 +; exit via JMP $B300 + !byte $00,$B3 +; track 0 + !byte $00,$00,$00,$BD,$BC,$BB,$BA,$B9,$B8,$B7,$B6,$B5,$B4,$B3 + !byte $C0 + diff --git a/src/strings/en.a b/src/strings/en.a index 69260af..391b5da 100755 --- a/src/strings/en.a +++ b/src/strings/en.a @@ -119,6 +119,8 @@ StringTable !word .advent !word .gathering !word .davidson + !word .rdos13 + !word .ssi ; ; Text can contain substitution strings, which ; are replaced by current values at runtime. Each @@ -144,7 +146,7 @@ StringTable ; can be set directly before calling PrintByID. ; .header - !text "Passport by 4am 2018-09-25",$00 + !text "Passport by 4am 2018-09-26",$00 .mainmenu !text "________________________________________",$8D,$8D,$8D,$8D,$8D,$8D,$8D !text " " @@ -422,7 +424,7 @@ StringTable .rwtswrite !text "T00,S02 Writing built-in RWTS",$8D,$00 .rdos - !text "T00,S00 Found RDOS bootloader",$8D,$00 + !text "T00,S00 Found RDOS 16-sector bootloader",$8D,$00 .sra !text "T%t,S%0 Found SRA protection check",$8D,$00 .muse @@ -446,4 +448,8 @@ StringTable !text "Gathering per-file encryption keys",$8D,$00 .davidson !text "T%t Found Davidson & Associates disk",$8D,$00 +.rdos13 + !text "T00,S00 Found RDOS 13-sector bootloader",$8D,$00 +.ssi + !text "T%t,S%0 Found SSI protection check",$8D,$00 } diff --git a/src/strings/enid.a b/src/strings/enid.a index f102aec..5ea627a 100644 --- a/src/strings/enid.a +++ b/src/strings/enid.a @@ -106,4 +106,6 @@ s_microfun = $64 s_advent = $65 s_gathering = $66 s_davidson = $67 -STRINGCOUNT = $68 +s_rdos13 = $68 +s_ssi = $69 +STRINGCOUNT = $6A diff --git a/winmake.bat b/winmake.bat index 6fcce1e..af26dde 100644 --- a/winmake.bat +++ b/winmake.bat @@ -15,7 +15,7 @@ cd ..\..\build cscript /nologo //e:jscript %~f0 "b8" "00" 1>nul copy /b tmp+universalrwts.tmp universalrwts.pak cd ..\src\mods -%ACME% t00only.a +%ACME% -r ..\..\build\t00only.lst t00only.a cd ..\..\build %EXOMIZER% raw -q t00only.bin -o t00only.tmp cscript /nologo //e:jscript %~f0 "20" "00"