;------------------------------- ; Passport ; a 4am hack ; (c) 2016-2021 by 4am ; ; Permission is hereby granted, free of charge, to any ; person obtaining a copy of this software and associated ; documentation files (the "Software"), to deal in the ; Software without restriction, including without limitation ; the rights to use, copy, modify, merge, publish, ; distribute, sublicense, and/or sell copies of the ; furnished to do so, subject to the following conditions: ; ; The above copyright notice and this permission notice ; shall be included in all copies or substantial portions of ; the Software. ; ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY ; KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE ; WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR ; PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS ; OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR ; OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR ; OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ; ;------------------------------- !cpu 6502 !ifdef RELBASE { *=RELBASE } else { *=$2000 } !ifndef VERBOSE { VERBOSE = $00 ; set to $01 to display API label addresses } !to "../build/PASSPORT.TMP",plain !ct "lcase.ct" !source "apidefs.a" ; no code in here MainMenu ldx #$FF txs jsr Cleanup ; RAM/HD files might be left open after Ctrl-Reset jsr ClearScreen @refreshMainMenu jsr PrintByID !byte s_header jsr PrintByID !byte s_mainmenu bit gTargetType bmi @usingHardDisk bvs @usingCFFA lda #s_targetdisk !byte $2C @usingCFFA lda #s_targetcffa !byte $2C @usingHardDisk lda #s_targetfile sta + jsr PrintByID + !byte $FD ; SMC @getkey jsr WaitForKey cmp #$80 bne + jsr EnterCFFAIfAvailable bcc MainMenu bcs @getkey + cmp #$9B ; Esc quits beq @jumpToExit cmp #$91 ; Ctrl-Q quits beq @jumpToExit cmp #k_quit bne + @jumpToExit jmp CleanExit + cmp #k_slot bne + jsr NextSlot lda #0 sta HPOS sta VPOS jsr $FBC1 lda #TRUE sta gChangedPrefs beq @refreshMainMenu ; always branches + cmp #k_verify bne + lda #%00000000 beq Action ; always branches + cmp #k_crack bne @getkey lda #%11000000 ; /!\ execution falls through here Action sta gMode jsr InitSectorMap Reaction lda #FALSE sta gTriedUniv sta gSaidWriting sta gIsProtDOS sta gIsInfocom18 sta gIs13Sector sta gIsRW18 lda #$00 sta gTrack sta gSector sta gPatchCount sta jCallRWTS+1 sta CacheDst+1 lda #$08 sta gAddress+1 lda #$D4 sta CacheDst+2 jsr ShowInitialProgressScreen lda gMode bpl @printReading ; don't create RAM disk or hard disk file in verify mode jsr LookupUnitNumberOfSelectedHardDisk beq @notHardDrive jsr SwapProDOS ; ProDOS out -> in (preserves flags) jsr CreateFileOnHardDisk jsr SwapProDOS ; ProDOS in -> out (preserves flags) bcc @printReading jmp FatalWriteError ; failed to create target file on hard disk ; this is fatal @idBootloader jmp IDBootloader ; /src/id/inspect0 @notHardDrive lda RAMDiskImagePath beq @printReading ; no RAM disk available jsr SwapProDOS ; ProDOS out -> in (preserves flags) jsr CreateFileOnRAMDisk jsr SwapProDOS ; ProDOS in -> out (preserves flags) bcc @printReading lda #0 ; failed to create temporary file on RAM disk sta RAMDiskImagePath ; this is not fatal, but we'll mark the RAM ; disk as unavailable so we don't bother with it @printReading jsr PrintByID !byte s_reading lda #$B2 ldx #$00 ldy #$0D jsr ClearMemory jsr CopyUniversal jsr IgnoreAddressChecksum jsr ReadSector bcc @idBootloader jsr IDBootFailure ; /src/id/bootfailure bcc @idBootloader jsr PrintByID !byte s_fatal0000 ; /!\ execution falls through here TheEnd jsr Cleanup jsr PrintByID !byte s_done jsr WaitForKey cmp #$9B beq CleanExit cmp #k_redo beq HandleRedo cmp #k_redo_with_ignore beq HandleRedoWithIgnore jsr CheckLogKeys jmp MainMenu HandleRedoWithIgnore jsr InitSectorMapWithIgnore jmp Reaction HandleRedo jsr ShowInitialProgressScreen jsr PrintByID !byte s_reading ; /!\ execution falls through here ;------------------------------- ; RestartScan ; Print 'Restarting scan...' then do exactly that. ; Used by several patchers that find evidence of a protection ; then activate an expensive search the second time around. ; Can be called from anywhere. ; Resets stack, never returns. ; Exits via ReadWithRWTS ;------------------------------- RestartScan jsr PrintByID !byte s_restart jsr RestartProgress jsr IncProgress ldx #$FF txs jmp ReadWithRWTS ;------------------------------- ; Cleanup ; ; Cleans up open files (if any) ; Also turns off slot 6 drive motor ; ; in: ProDOS is NOT in memory ; out: ProDOS is NOT in memory ; all registers and flags clobbered ;------------------------------- Cleanup lda $C0E8 lda gHardDiskRef ora gRAMDiskRef beq + jsr SwapProDOS ; ProDOS out -> in jsr DeleteFileOnRAMDisk jsr CloseFileOnHardDisk jsr SwapProDOS ; ProDOS in -> out + rts ;------------------------------- ; CleanExit ; ; Cleans up open files, saves preferences (if modified), ; and quits via ProDOS MLI ; ; in: ProDOS is NOT in memory ; out: does not return ;------------------------------- CleanExit jsr Cleanup jsr SwapProDOS ; ProDOS out -> in lda gChangedPrefs bne + jsr SavePrefs + jsr PRODOSMLI ; does not return !byte $65 !word + + !byte $04 ;------------------------------- ; AnalyzeTrack routine ; Looks at buffer in memory to detect known ; copy protections and disable/revert/modify them ; to work on standard disks. ; Prints through COUT ; Makes modifications in memory only. ; in: @BASEPAGE contains one track worth of data ($1000 bytes) ; gTrack contains track number ; out: if C set, no known protections were found and ; no modifications were made ; if C clear, at least one modification was made ;------------------------------- AnalyzeTrack lda gTrack bne @applyToAll ; Track 0 patchers are stored compressed in memory ; then decompressed into $2000 when needed bit gMode bpl @applyToAll ; only run track 0 modules in crack mode lda #>AnalyzeT00 sta _byte_hi lda #