From 21724233d44593117662efd6ffdf47cf31c194b8 Mon Sep 17 00:00:00 2001 From: Kevin Cathcart Date: Sat, 6 Oct 2018 18:21:59 -0400 Subject: [PATCH] Implement password screen --- LTTP_RND_GeneralBugfixes.asm | 1 + decryption.asm | 2 - fileselect.asm | 130 ++++++-- fileselect.chr.gfx | Bin 4096 -> 4096 bytes hashalphabet.asm | 32 +- hashalphabethooks.asm | 19 +- hooks.asm | 41 ++- password.asm | 608 +++++++++++++++++++++++++++++++++++ tables.asm | 10 +- 9 files changed, 784 insertions(+), 59 deletions(-) create mode 100644 password.asm diff --git a/LTTP_RND_GeneralBugfixes.asm b/LTTP_RND_GeneralBugfixes.asm index dc3cb3a..7fee8b6 100644 --- a/LTTP_RND_GeneralBugfixes.asm +++ b/LTTP_RND_GeneralBugfixes.asm @@ -172,6 +172,7 @@ incsrc inverted.asm incsrc invertedmaps.asm incsrc newhud.asm incsrc compasses.asm +incsrc password.asm warnpc $A58000 ;org $228000 ; contrib area diff --git a/decryption.asm b/decryption.asm index 438cf0d..f581a18 100644 --- a/decryption.asm +++ b/decryption.asm @@ -32,8 +32,6 @@ RetrieveValueFromEncryptedTable: LDA [$00], Y : STA.l !CryptoBuffer+4 : INY #2 LDA [$00], Y : STA.l !CryptoBuffer+6 - ; TODO: copy key into crypto Memory - LDA.w #$0002 : STA $04 ;set block size JSL.l XXTEA_Decode diff --git a/fileselect.asm b/fileselect.asm index 92b9881..32ecebd 100644 --- a/fileselect.asm +++ b/fileselect.asm @@ -1,4 +1,5 @@ !ExtendedPlayerName = "$700500" +!ValidKeyLoaded = "$7F509E" ;FS prefix means file_select, since these defines and macros are specific to this screen !FS_INVENTORY_SWAP = "$70038C" @@ -118,7 +119,7 @@ DrawPlayerFile: ; re-enable Stripe Image format upload on this frame ; Value loaded must match what gets set by AltBufferTable - LDA.w #$2161 : STA $1002 + LDA.w #$0161 : STA $1002 BRA .done .normal STZ $0710 ; ensure core animated tile updates are not suppressed @@ -136,22 +137,22 @@ DrawPlayerFileShared: REP #$20 ; restore 16 bit accumulator LDA !ExtendedPlayerName+$00 : ORA.w #!FS_COLOR_BW - %fs_draw8x16(6,3) - LDA !ExtendedPlayerName+$02 : ORA.w #!FS_COLOR_BW %fs_draw8x16(6,5) + LDA !ExtendedPlayerName+$02 : ORA.w #!FS_COLOR_BW + %fs_draw8x16(6,6) LDA !ExtendedPlayerName+$04 : ORA.w #!FS_COLOR_BW %fs_draw8x16(6,7) LDA !ExtendedPlayerName+$06 : ORA.w #!FS_COLOR_BW - %fs_draw8x16(6,9) + %fs_draw8x16(6,8) LDA !ExtendedPlayerName+$08 : ORA.w #!FS_COLOR_BW - %fs_draw8x16(9,3) - LDA !ExtendedPlayerName+$0A : ORA.w #!FS_COLOR_BW %fs_draw8x16(9,5) + LDA !ExtendedPlayerName+$0A : ORA.w #!FS_COLOR_BW + %fs_draw8x16(9,6) LDA !ExtendedPlayerName+$0C : ORA.w #!FS_COLOR_BW %fs_draw8x16(9,7) LDA !ExtendedPlayerName+$0E : ORA.w #!FS_COLOR_BW - %fs_draw8x16(9,9) + %fs_draw8x16(9,8) JSR FileSelectDrawHudBar @@ -427,6 +428,7 @@ DrawPlayerFileShared: LDA.w #$0287|!FS_COLOR_GRAY ++ : %fs_draw16x8(13,24) + PLB : PLY : PLX RTS ;-------------------------------------------------------------------------------- @@ -590,7 +592,7 @@ AltBufferTable: LDA.b #$02 : STA $210c ; Have Screen 3 use same tile area as screens 1 .noScreen3Change REP #$20 - LDX.w #$0380 ; 14 rows with 64 bytes (30 tiles * 2 + 4 byte header) + LDX.w #$0400 ; 14 rows with 64 bytes (30 tiles * 2 + 4 byte header) ;fill with the blank character LDA.w #$0188 - @@ -598,26 +600,29 @@ AltBufferTable: DEX : DEX : BNE - ; set vram offsets - LDA.w #$2161 : STA $1002 ;file 1 top row - LDA.w #$4161 : STA $1042 ;file 1 bottom row + LDA.w #$0161 : STA $1002 ;file 1 top row + LDA.w #$2161 : STA $1042 ;file 1 bottom row - LDA.w #$6161 : STA $1082 ;gap row top - LDA.w #$8161 : STA $10C2 ;gap row bottom + LDA.w #$4161 : STA $1082 ;gap row top + LDA.w #$6161 : STA $10C2 ;gap row bottom - LDA.w #$A161 : STA $1102 ;file 2 top row - LDA.w #$C161 : STA $1142 ;file 2 bottom row + LDA.w #$8161 : STA $1102 ;file 2 top row + LDA.w #$A161 : STA $1142 ;file 2 bottom row - LDA.w #$E161 : STA $1182 ;gap row top - LDA.w #$0162 : STA $11c2 ;gap row bottom + LDA.w #$C161 : STA $1182 ;gap row top + LDA.w #$E161 : STA $11c2 ;gap row bottom - LDA.w #$2162 : STA $1202 ;file 3 top row - LDA.w #$4162 : STA $1242 ;file 3 bottom row + LDA.w #$0162 : STA $1202 ;file 3 top row + LDA.w #$2162 : STA $1242 ;file 3 bottom row - LDA.w #$6162 : STA $1282 ;extra gap row top - LDA.w #$8162 : STA $12c2 ;extra gap row bottom + LDA.w #$4162 : STA $1282 ;extra gap row top + LDA.w #$6162 : STA $12c2 ;extra gap row bottom - LDA.w #$A162 : STA $1302 ;extra gap row top - LDA.w #$C162 : STA $1342 ;extra gap row bottom + LDA.w #$8162 : STA $1302 ;extra gap row top + LDA.w #$A162 : STA $1342 ;extra gap row bottom + + LDA.w #$C162 : STA $1382 ;extra gap row top + LDA.w #$E162 : STA $13C2 ;extra gap row bottom ; set lengths LDA.w #$3B00 @@ -635,10 +640,26 @@ AltBufferTable: STA $12c4 ;extra gap row bottom STA $1304 ;extra gap row top STA $1344 ;extra gap row bottom + STA $1384 ;extra gap row top + STA $13c4 ;extra gap row bottom ; Set last packet marker - LDA.w #$00FF : STA $1382 - SEP #$20 + LDA.w #$00FF : STA $1402 + + ; Draw Unlock option if applicable + LDA $10 : AND.w #$00FF : CMP.w #$0001 : BNE + + LDA.l IsEncrypted : AND.w #$00FF : CMP.w #$0002 : BNE + + PHP : SEP #$30 : PHX : PHY : JSL ValidatePassword : PLY : PLX : PLP + AND.w #$00FF : BNE + + LDA.w #!FSTILE_U_TOP : %fs_draw8x16(14,5) + LDA.w #!FSTILE_N_TOP : %fs_draw8x16(14,6) + LDA.w #!FSTILE_L_TOP : %fs_draw8x16(14,7) + LDA.w #!FSTILE_O_TOP : %fs_draw8x16(14,8) + LDA.w #!FSTILE_C_TOP : %fs_draw8x16(14,9) + LDA.w #!FSTILE_K_TOP : %fs_draw8x16(14,10) + + + + SEP #$20 RTL ;-------------------------------------------------------------------------------- @@ -666,6 +687,10 @@ AltBufferTable_credits: LDA.w #$E169 : STA $1302 ;extra gap row top LDA.w #$016A : STA $1342 ;extra gap row bottom + + LDA.w #$216A : STA $1382 ;extra gap row top + LDA.w #$416A : STA $13C2 ;extra gap row bottom + SEP #$20 RTL ;-------------------------------------------------------------------------------- @@ -772,13 +797,13 @@ DrawPlayerFile_credits: REP #$20 ; set 16 bit accumulator LDA $7003D9 : ORA.w #!FS_COLOR_BW - %fs_draw8x16(3,3) - LDA $7003DB : ORA.w #!FS_COLOR_BW %fs_draw8x16(3,5) + LDA $7003DB : ORA.w #!FS_COLOR_BW + %fs_draw8x16(3,6) LDA $7003DD : ORA.w #!FS_COLOR_BW %fs_draw8x16(3,7) LDA $7003DF : ORA.w #!FS_COLOR_BW - %fs_draw8x16(3,9) + %fs_draw8x16(3,8) LDA $70036C : AND.w #$00FF : LSR #3 : STA $02 %fs_LDY_screenpos(0,20) @@ -799,3 +824,54 @@ DrawPlayerFile_credits: JSR DrawPlayerFileShared RTL ;-------------------------------------------------------------------------------- +FSCursorUp: + LDA $C8 : BNE + + LDA #$04 ; up from file becomes delete + BRA .done + + : CMP #$03 : BNE + + LDA #$00 ; up from unlock is the file + BRA .done + + + LDA.l IsEncrypted : CMP.b #$02 : BNE + + LDA.l !ValidKeyLoaded : BNE + + LDA #$03 ; up from delete is unlock for password protected seeds + BRA .done + + + LDA #$00 ;otherwise up from delete is file + .done + STA $C8 +RTL +FSCursorDown: + LDA $C8 : BNE + + LDA.l IsEncrypted : CMP.b #$02 : BNE ++ + LDA.l !ValidKeyLoaded : BNE ++ + LDA #$03 ; down from file is unlock for password protected seeds + BRA .done + ++ + LDA #$04 ;otherwise down from file is delete + BRA .done + + : CMP #$03 : BNE + + LDA #$04 ; down from unlock is delete + BRA .done + + + LDA #$00 ; down from delete is file + .done + STA $C8 +RTL +;-------------------------------------------------------------------------------- +FSSelectFile: + LDA.l IsEncrypted : CMP.b #$02 : BNE .normal + STZ $012E ; temporarily cancel file screen selection sound + PHX : PHY + JSL ValidatePassword : BEQ .must_unlock + PLY : PLX + LDA.b #$2C : STA $012E ;file screen selection sound + .normal + LDA.b #$F1 : STA $012C +JML FSSelectFile_continue + .must_unlock + PLY : PLX + LDA #$03 : STA $C8 ;set cursor to unlock + LDA.b #$3C : STA $012E ; play error sound +JML FSSelectFile_return +;-------------------------------------------------------------------------------- diff --git a/fileselect.chr.gfx b/fileselect.chr.gfx index 6b76ebd44c73bd8143f91962f1f3beeaec7f178a..858c3f29b44070033e4f261ccc883f8d638720cd 100755 GIT binary patch delta 42 tcmZorXi(U&fqQa1o4DkU{}2AR|Cj$?|NqbbpFsE-2%m%C=8fD6EC3>8 +org $008099+$02 ; <- Bank00.asm : 103 (dl Module_CopyFile) +db Module_Password>>16 + +; Hook up password screen tilemap +org $00937a+$07 +db Password_Tilemap +org $009383+$07 +db Password_Tilemap>>8 +org $00938c+$07 +db Password_Tilemap>>16 +;-------------------------------------------------------------------------------- org $0CD527 ; <- 65527 : Bank0C.asm : 2913 (LDA.w #$0004 : STA $02) [LDA.w #$0006 : STA $02] JSL.l DrawPlayerFile : NOP ; hijack hearts draw routine to draw a full inventory @@ -108,15 +130,24 @@ LDA.w #$0180 ; change which character is used as the blank character for the sel org $0CD50C ; <- 6550C (Not in disassembly, would be in bank0c.asm if it were) Position table for Name and Hearts ;dw $0012, $0112, $0212 ; vanilla-ish positions of file names ;dw $0026, $0126, $0226 ; vanilla-ish positions of hearts names -dw $00C8, $014A, $01CA ; repositioned, only the first value matters +dw $00CC, $014A, $01CA ; repositioned, only the first value matters dw $002A, $0192, $0112 org $0CD53B ; <- 6553B : Bank0c.asm : 2919 (ADD.w #$0010 : STA $102C, Y) [... : STA $1034, Y] STA.w $1042, Y ; Make 2nd half of names line up properly -;org $0CD540 ; <- 65540 : Bank0c.asm : 2923 (INY #2) [INY #4] -;NOP #2 ; Remove space between name characters +org $0CD540 ; <- 65540 : Bank0c.asm : 2923 (INY #2) [INY #4] +NOP #2 ; Remove space between name characters org $0CD571 ; <- 65571 : Bank0c.asm : 2943 (LDA $04 : ADD.w #$002A : TAY) [... : ADD.w #$0032 : ...] ADC.w #$0040 ;make Hearts line up properly ;-------------------------------------------------------------------------------- +org $0CCC67 ; <- (Not in disassembly, would be in bank0c.asm if it were) Y position table for File select fairy +db $42, $00, $00, $AF, $C7 +org $0CD308 ; <- (Not in disassembly, would be in bank0c.asm if it were) Y position table for File Delete fairy +db $42, $00, $00, $C7 +org $0CD57E ; <- Y position table for File select link sprite +db $3d +org $0CD6BD ; <- Y position table for Death Counts +db $51 +;-------------------------------------------------------------------------------- ;================================================================================ ; Name Entry Screen diff --git a/password.asm b/password.asm new file mode 100644 index 0000000..ff45b74 --- /dev/null +++ b/password.asm @@ -0,0 +1,608 @@ +!PASSWORD_CODE_POSITION = "$C8" +!PASSWORD_SELECTION_POSITION = "$C9" +!PASSWORD_SRAM = "$700510" + + +Module_Password: + LDA $11 + + JSL.l UseImplicitRegIndexedLongJumpTable + + dl Password_BeginInit ; 0 + dl Password_EndInit ; 1 + dl Password_Main ; 2 + dl Password_Check ; 3 + dl Password_Return ; 4 + +Password_BeginInit: + LDA.b #$80 : STA $0710 ;skip animated sprite updates in NMI + + JSL EnableForceBlank + JSL Vram_EraseTilemaps_triforce + ;JSL Palette_SelectScreen + + JSL LoadCustomHudPalette ; replace the 2bpp palettes, and trigger upload + LDA.b #$07 : STA $14 ; have NMI load up the initial tilemap from Password_Tilemap + + INC $11 +RTL + +Password_EndInit: + JSR LoadPasswordStripeTemplate + + ;reset the variables used by this screen + STZ !PASSWORD_CODE_POSITION + STZ !PASSWORD_SELECTION_POSITION + + JSL ValidatePassword : BNE + + ; zero out password if not valid + LDX.b #$0F + LDA.b #$00 + - + STA.l !PASSWORD_SRAM, X + DEX : BPL - + + + + LDA.b #$0F : STA $13 + INC $11 +RTL + +Password_Main: + PHB + PHK : PLB + + JSR PasswordEraseOldCursors + + ; handle joypad input + LDA $F6 : AND.b #$10 : BEQ + ; R Button + JSR PasswordMoveCursorRight + + + LDA $F6 : AND.b #$20 : BEQ + ; L Button + JSR PasswordMoveCursorLeft + + + LDA $F4 : AND.b #$01 : BEQ + ; right + LDA !PASSWORD_SELECTION_POSITION : INC A : CMP.b #$24 : !BLT ++ + !SUB.b #$24 + ++ + STA !PASSWORD_SELECTION_POSITION + LDA.b #$20 : STA $012F + + + LDA $F4 : AND.b #$02 : BEQ + ; left + LDA !PASSWORD_SELECTION_POSITION : DEC A : BPL ++ + !ADD.b #$24 + ++ + STA !PASSWORD_SELECTION_POSITION + LDA.b #$20 : STA $012F + + + LDA $F4 : AND.b #$04 : BEQ + ; down + LDA !PASSWORD_SELECTION_POSITION : !ADD.b #$09 : CMP.b #$24 : !BLT ++ + !SUB.b #$24 + ++ + STA !PASSWORD_SELECTION_POSITION + LDA.b #$20 : STA $012F + + + LDA $F4 : AND.b #$08 : BEQ + ; up + LDA !PASSWORD_SELECTION_POSITION : !SUB.b #$09 : BPL ++ + !ADD.b #$24 + ++ + STA !PASSWORD_SELECTION_POSITION + LDA.b #$20 : STA $012F + + + LDA $F4 : ORA $F6 : AND.b #$C0 : BEQ + ; face button + LDX !PASSWORD_SELECTION_POSITION + LDA .selectionValues, X : BPL ++ + CMP #$F0 : BNE +++ + INC $11 + BRA .endOfButtonChecks + +++ : CMP #$F1 : BNE +++ + JSR PasswordMoveCursorLeft + BRA + + +++ : CMP #$F2 : BNE +++ + JSR PasswordMoveCursorRight + BRA + + +++ : CMP #$F3 : BNE +++ + INC $11 : INC $11 ; skip to return submodule + LDA.b #$2C : STA $012E ;file screen selection sound + BRA .endOfButtonChecks + +++ + BRA + + ++ + LDX !PASSWORD_CODE_POSITION + STA !PASSWORD_SRAM,X + TXA : INC A : AND.b #$0F : STA !PASSWORD_CODE_POSITION + BNE ++ + STZ $012E + INC $11 + BRA .endOfButtonChecks + ++ + LDA.b #$2B : STA $012E + + + LDA $F4 : AND.b #$10 : BEQ + ; start + INC $11 + + + .endOfButtonChecks + + JSR UpdatePasswordTiles + + JSR PasswordSetNewCursors + LDA.b #$01 : STA $14 + PLB +RTL +.selectionValues +db $01, $02, $03, $04, $05, $06, $07, $08, $F0 +db $09, $0A, $0B, $0C, $0D, $0E, $0F, $10, $F1 +db $11, $12, $13, $14, $15, $16, $17, $18, $F2 +db $19, $1A, $1B, $1C, $1D, $1E, $1F, $20, $F3 + +Password_Check: + JSL.l ValidatePassword : BNE .correct + LDA.b #$3C : STA $012E ; error + DEC $11 +RTL + .correct + LDA.b #$1B : STA $012F ; solved puzzle sound + INC $11 +RTL + +Password_Return: + LDA.b #$01 : STA $10 ; select screen + LDA.b #$01 : STA $11 ; Skip the first submodule + STZ $B0 + STZ $0B9D ; Reset file screen cursor pre-selection + STZ $C8 + STZ $C9 +RTL + +;-------------------------------------------------------------------------------- +; Exported Function +;-------------------------------------------------------------------------------- + +ValidatePassword: + ; returns 1/Not Z for correct, 0/Z for incorrect + ; REQUIRES: 8 bit both + ; has a deliberate side effect of key being loaded into RAM if password is correct. + PHX : PHY + + ;check for incomplete password + LDX #$0F + - + LDA.l !PASSWORD_SRAM, X : BNE + + BRL .incorrect + + + DEX : BPL - + + REP #$20 ; 16 bit Accumulator + + ; Clear out any existing encryption key + LDX.b #$0E + LDA.w #$0000 + - : STA.l !keyBase, X : DEX #2 : BPL - + + JSR PasswordToKey + + + LDA.l StaticDecryptionKey+$0A : STA.l !keyBase+$0A + LDA.l StaticDecryptionKey+$0C : STA.l !keyBase+$0C + LDA.l StaticDecryptionKey+$0E : STA.l !keyBase+$0E + + LDA.l KnownEncryptedValue : STA.l !CryptoBuffer + LDA.l KnownEncryptedValue+2 : STA.l !CryptoBuffer+2 + LDA.l KnownEncryptedValue+4 : STA.l !CryptoBuffer+4 + LDA.l KnownEncryptedValue+6 : STA.l !CryptoBuffer+6 + + LDA.w #$0002 : STA $04 ;set block size + + JSL.l XXTEA_Decode + + SEP #$20 ; 8 bit accumulator + + LDA !CryptoBuffer+0 : CMP #$31 : BNE .incorrect + LDA !CryptoBuffer+1 : CMP #$41 : BNE .incorrect + LDA !CryptoBuffer+2 : CMP #$59 : BNE .incorrect + LDA !CryptoBuffer+3 : CMP #$26 : BNE .incorrect + LDA !CryptoBuffer+4 : CMP #$53 : BNE .incorrect + LDA !CryptoBuffer+5 : CMP #$58 : BNE .incorrect + LDA !CryptoBuffer+6 : CMP #$97 : BNE .incorrect + LDA !CryptoBuffer+7 : CMP #$93 : BNE .incorrect + + ;trial decrypt the known plaintext, and verify if result is correct + + .correct + PLY : PLX + + LDA #$01 : STA.l !ValidKeyLoaded +RTL + .incorrect + PLY : PLX + LDA #$00 +RTL + +;-------------------------------------------------------------------------------- +; Local Helper functions +;-------------------------------------------------------------------------------- + +PasswordToKey: + ; $00 input offset + ; $02 output offset + ; $04 shift amount + LDA.w #$0000 : STA $00 : STA $02 + LDA.w #$000B : STA $04 + - + LDX $00 + LDA !PASSWORD_SRAM, X : DEC : AND #$001F + LDY $04 + -- : BEQ + : ASL : DEY : BRA -- : + ; Shift left by Y + XBA + LDX $02 + ORA !keyBase, X + STA !keyBase, X + + LDA $04 : !SUB.w #$0005 : BPL + + !ADD.w #$0008 + INC $02 + + : STA $04 + + LDA $00 : INC : STA $00 : CMP.w #$0010 : !BLT - +RTS + +LoadPasswordStripeTemplate: + LDA $4300 : PHA : LDA $4301 : PHA : LDA $4302 : PHA ; preserve DMA parameters + LDA $4303 : PHA : LDA $4304 : PHA : LDA $4305 : PHA ; preserve DMA parameters + LDA $4306 : PHA ; preserve DMA parameters + + LDA.b #$00 : STA $4300 ; set DMA transfer direction A -> B, bus A auto increment, single-byte mode + LDA.b #$80 : STA $4301 ; set bus B destination to WRAM register + + LDA.b #$02 : STA $2181 ; set WRAM register source address + LDA.b #$10 : STA $2182 + LDA.b #$7E : STA $2183 + + LDA.b #Password_StripeImageTemplate : STA $4302 ; set bus A source address + LDA.b #Password_StripeImageTemplate>>8 : STA $4303 ; set bus A source address + LDA.b #Password_StripeImageTemplate>>16 : STA $4304 ; set bus A source bank + + LDA.b #Password_StripeImageTemplate_end-Password_StripeImageTemplate + STA $4305 ; + LDA.b #Password_StripeImageTemplate_end-Password_StripeImageTemplate>>8 + STA $4306 ; set transfer size + + LDA #$01 : STA $420B ; begin DMA transfer + + PLA : STA $4306 : PLA : STA $4305 : PLA : STA $4304 ; restore DMA parameters + PLA : STA $4303 : PLA : STA $4302 : PLA : STA $4301 ; restore DMA parameters + PLA : STA $4300 ; restore DMA parameters +RTS + +!PASSWORD_INPUT_START_X = $03 +!PASSWORD_INPUT_START_Y = $0D + +!PASSWORD_DISPLAY_START_X = $04 +!PASSWORD_DISPLAY_START_Y = $04 + +PasswordEraseOldCursors: + + REP #$20 ; set 16-bit accumulator + + ;Code Cursor + LDA !PASSWORD_CODE_POSITION : AND.w #$00FF : ASL : TAX + LDA .code_offsets, X + !ADD.w #$20*!PASSWORD_DISPLAY_START_Y+!PASSWORD_DISPLAY_START_X+$6000 + XBA ; because big endian is needed + STA $1002+Password_StripeImageTemplate_CodeCursorErase-Password_StripeImageTemplate + + ;selection cursor + LDA !PASSWORD_SELECTION_POSITION : AND.w #$00FF : ASL : TAX + LDA .selection_offsets, X + !ADD.w #$20*!PASSWORD_INPUT_START_Y+!PASSWORD_INPUT_START_X+$6000 + XBA ; because big endian is needed + STA $1002+Password_StripeImageTemplate_SelectionCursorErase-Password_StripeImageTemplate + XBA : !ADD.w #$0020 : XBA + STA $1002+$0C+Password_StripeImageTemplate_SelectionCursorErase-Password_StripeImageTemplate + XBA : !ADD.w #$0003 : XBA + STA $1002+$14+Password_StripeImageTemplate_SelectionCursorErase-Password_StripeImageTemplate + XBA : !ADD.w #$0040-$0003 : XBA + STA $1002+$1C+Password_StripeImageTemplate_SelectionCursorErase-Password_StripeImageTemplate + + SEP #$20 ; restore 8-bit accumulator +RTS +.code_offsets + dw $0040, $0043, $0046, $0049, $004C, $004F, $0052, $0055 + dw $00A0, $00A3, $00A6, $00A9, $00AC, $00AF, $00B2, $00B5 +.selection_offsets + dw $FFDF, $FFE2, $FFE5, $FFE8, $FFEB, $FFEE, $FFF1, $FFF4, $FFF7 + dw $003F, $0042, $0045, $0048, $004B, $004E, $0051, $0054, $0057 + dw $009F, $00A2, $00A5, $00A8, $00AB, $00AE, $00B1, $00B4, $00B7 + dw $00FF, $0102, $0105, $0108, $010B, $010E, $0111, $0114, $0117 + +PasswordSetNewCursors: + REP #$20 ; set 16-bit accumulator + ;Code Cursor + LDA !PASSWORD_CODE_POSITION : AND.w #$00FF : ASL : TAX + LDA PasswordEraseOldCursors_code_offsets, X + !ADD.w #$20*!PASSWORD_DISPLAY_START_Y+!PASSWORD_DISPLAY_START_X+$6000 + XBA ; because big endian is needed + STA $1002+Password_StripeImageTemplate_CodeCursorDraw-Password_StripeImageTemplate + + ;Selection cursor + LDA !PASSWORD_SELECTION_POSITION : AND.w #$00FF : ASL : TAX + LDA PasswordEraseOldCursors_selection_offsets, X + !ADD.w #$20*!PASSWORD_INPUT_START_Y+!PASSWORD_INPUT_START_X+$6000 + XBA ; because big endian is needed + STA $1002+Password_StripeImageTemplate_SelectionCursorDraw-Password_StripeImageTemplate + XBA : !ADD.w #$0020 : XBA + STA $1002+$0C+Password_StripeImageTemplate_SelectionCursorDraw-Password_StripeImageTemplate + XBA : !ADD.w #$0003 : XBA + STA $1002+$14+Password_StripeImageTemplate_SelectionCursorDraw-Password_StripeImageTemplate + XBA : !ADD.w #$0040-$0003 : XBA + STA $1002+$1C+Password_StripeImageTemplate_SelectionCursorDraw-Password_StripeImageTemplate + + SEP #$20 ; restore 8-bit accumulator +RTS + +UpdatePasswordTiles: + REP #$30 ; set 16-bit both + LDX.w #$000F + - + LDA.l !PASSWORD_SRAM, X : AND.w #$00FF : TXY + ASL #3 : STA $00 + TYA : ASL #4 : STA $03 + LDX $00 : LDA.l HashAlphabetTilesWithBlank, X + LDX $03 : STA $1006, X + LDX $00 : LDA.l HashAlphabetTilesWithBlank+$02, X + LDX $03 : STA $1008, X + LDX $00 : LDA.l HashAlphabetTilesWithBlank+$04, X + LDX $03 : STA $100E, X + LDX $00 : LDA.l HashAlphabetTilesWithBlank+$06, X + LDX $03 : STA $1010, X + + TYX : DEX : BMI + : BRA - + + + SEP #$30 ; restore 8-bit both +RTS + +PasswordMoveCursorRight: + ; return new code position + LDA.b #$2B : STA $012E + LDA !PASSWORD_CODE_POSITION : INC A : AND.b #$0F : STA !PASSWORD_CODE_POSITION +RTS +PasswordMoveCursorLeft: + ; return new code position + LDA.b #$2B : STA $012E + LDA !PASSWORD_CODE_POSITION : DEC A : AND.b #$0F : STA !PASSWORD_CODE_POSITION +RTS + +macro dw_big_endian(value) + db >>8 + db +endmacro +macro Layer3_VRAM_Address(x,y) + %dw_big_endian(*$20++$6000) +endmacro + + +Password_Tilemap: +;Add any graphics for background 0 here +%Layer3_VRAM_Address(!PASSWORD_INPUT_START_X,!PASSWORD_INPUT_START_Y+0) +%dw_big_endian(51) ;(9*4)+(8*2)-1 +dw #$0201|!FS_COLOR_YELLOW, #$0202|!FS_COLOR_YELLOW ;BOW +dw #$0200 +dw #$0205|!FS_COLOR_BLUE, #$0206|!FS_COLOR_BLUE ;BOOM +dw #$0200 +dw #$0200|!FS_COLOR_RED, #$0215|!FS_COLOR_RED ;HOOK +dw #$0200 +dw #$020C|!FS_COLOR_BLUE, #$020D|!FS_COLOR_BLUE ;BOMB +dw #$0200 +dw #$0262|!FS_COLOR_RED, #$0263|!FS_COLOR_RED ;SHROOM +dw #$0200 +dw #$020A|!FS_COLOR_BROWN, #$020B|!FS_COLOR_BROWN ;POWDER +dw #$0200 +dw #$0220|!FS_COLOR_BLUE, #$0221|!FS_COLOR_BLUE ;ROD +dw #$0200 +dw #$0285|!FS_COLOR_GREEN, #$0286|!FS_COLOR_GREEN ;PENDANT +dw #$0200 +dw #$02AB|!FS_COLOR_BW, #$02AB|!FS_COLOR_BW ;placeholder upper half action button + +%Layer3_VRAM_Address(!PASSWORD_INPUT_START_X,!PASSWORD_INPUT_START_Y+1) +%dw_big_endian(51) ;(9*4)+(8*2)-1 +dw #$0211|!FS_COLOR_YELLOW, #$0212|!FS_COLOR_YELLOW ;BOW +dw #$0200 +dw #$0200|!FS_COLOR_BW, #$0216|!FS_COLOR_BLUE ;BOOM +dw #$0200 +dw #$0230|!FS_COLOR_RED, #$0200|!FS_COLOR_BW ;HOOK +dw #$0200 +dw #$021C|!FS_COLOR_BLUE, #$021C|!FS_COLOR_BLUE|!FS_HFLIP ;BOMB +dw #$0200 +dw #$0272|!FS_COLOR_RED, #$0273|!FS_COLOR_RED ;SHROOM +dw #$0200 +dw #$021A|!FS_COLOR_BROWN, #$021B|!FS_COLOR_BROWN ;POWDER +dw #$0200 +dw #$0230|!FS_COLOR_BLUE, #$0231|!FS_COLOR_BLUE ;ROD +dw #$0200 +dw #$0295|!FS_COLOR_GREEN, #$0296|!FS_COLOR_GREEN ;PENDANT +dw #$0200 +dw #$02AB|!FS_COLOR_BW, #$02AB|!FS_COLOR_BW ;placeholder lower half action button + +%Layer3_VRAM_Address(!PASSWORD_INPUT_START_X,!PASSWORD_INPUT_START_Y+3) +%dw_big_endian(51) ;(9*4)+(8*2)-1 +dw #$0207|!FS_COLOR_YELLOW, #$0217|!FS_COLOR_YELLOW|!FS_HFLIP|!FS_VFLIP ;BOMBOS +dw #$0200 +dw #$0208|!FS_COLOR_YELLOW, #$0218|!FS_COLOR_YELLOW|!FS_HFLIP|!FS_VFLIP ;ETHER +dw #$0200 +dw #$0209|!FS_COLOR_YELLOW, #$0219|!FS_COLOR_YELLOW|!FS_HFLIP|!FS_VFLIP ;QUAKE +dw #$0200 +dw #$022C|!FS_COLOR_RED, #$022C|!FS_COLOR_RED|!FS_HFLIP ;LAMP +dw #$0200 +dw #$0222|!FS_COLOR_BROWN, #$0223|!FS_COLOR_BROWN ;HAMMER +dw #$0200 +dw #$0224|!FS_COLOR_BROWN, #$0225|!FS_COLOR_BROWN ;SHOVEL +dw #$0200 +dw #$0226|!FS_COLOR_BLUE, #$0227|!FS_COLOR_BLUE ;FLUTE +dw #$0200 +dw #$0228|!FS_COLOR_YELLOW, #$0229|!FS_COLOR_YELLOW ;NET +dw #$0200 +dw #$018A|!FS_COLOR_BW, #$0200 ; Left + +%Layer3_VRAM_Address(!PASSWORD_INPUT_START_X,!PASSWORD_INPUT_START_Y+4) +%dw_big_endian(51) ;(9*4)+(8*2)-1 +dw #$0217|!FS_COLOR_YELLOW, #$0207|!FS_COLOR_YELLOW|!FS_HFLIP|!FS_VFLIP ;BOMBOS +dw #$0200 +dw #$0218|!FS_COLOR_YELLOW, #$0208|!FS_COLOR_YELLOW|!FS_HFLIP|!FS_VFLIP ;ETHER +dw #$0200 +dw #$0219|!FS_COLOR_YELLOW, #$0209|!FS_COLOR_YELLOW|!FS_HFLIP|!FS_VFLIP ;QUAKE +dw #$0200 +dw #$023C|!FS_COLOR_RED, #$023D|!FS_COLOR_RED ;LAMP +dw #$0200 +dw #$0232|!FS_COLOR_BROWN, #$0233|!FS_COLOR_BROWN ;HAMMER +dw #$0200 +dw #$0234|!FS_COLOR_BROWN, #$0235|!FS_COLOR_BROWN ;SHOVEL +dw #$0200 +dw #$0236|!FS_COLOR_BLUE, #$0237|!FS_COLOR_BLUE ;FLUTE +dw #$0200 +dw #$0238|!FS_COLOR_YELLOW, #$0239|!FS_COLOR_YELLOW ;NET +dw #$0200 +dw #$019A|!FS_COLOR_BW, #$0200 ; Left + +%Layer3_VRAM_Address(!PASSWORD_INPUT_START_X,!PASSWORD_INPUT_START_Y+6) +%dw_big_endian(51) ;(9*4)+(8*2)-1 +dw #$022A|!FS_COLOR_GREEN, #$022B|!FS_COLOR_GREEN ;BOOK +dw #$0200 +dw #$0240|!FS_COLOR_BW, #$0241|!FS_COLOR_BW ;BOTTLE +dw #$0200 +dw #$0242|!FS_COLOR_GREEN, #$0242|!FS_COLOR_GREEN|!FS_HFLIP ;POTION +dw #$0200 +dw #$021D|!FS_COLOR_RED, #$021E|!FS_COLOR_RED +dw #$0200 +dw #$0248|!FS_COLOR_RED, #$0249|!FS_COLOR_RED +dw #$0200 +dw #$024A|!FS_COLOR_BLUE, #$024B|!FS_COLOR_BLUE +dw #$0200 +dw #$024C|!FS_COLOR_BOOTS, #$024D|!FS_COLOR_BOOTS +dw #$0200 +dw #$024E|!FS_COLOR_BROWN, #$024F|!FS_COLOR_BROWN +dw #$0200 +dw #$0200, #$018B|!FS_COLOR_BW ; Right + +%Layer3_VRAM_Address(!PASSWORD_INPUT_START_X,!PASSWORD_INPUT_START_Y+7) +%dw_big_endian(51) ;(9*4)+(8*2)-1 +dw #$023A|!FS_COLOR_GREEN, #$023B|!FS_COLOR_GREEN ;BOOK +dw #$0200 +dw #$0250|!FS_COLOR_BW, #$0251|!FS_COLOR_BW ;BOTTLE +dw #$0200 +dw #$0252|!FS_COLOR_GREEN, #$0253|!FS_COLOR_GREEN ;POTION +dw #$0200 +dw #$022D|!FS_COLOR_RED, #$022E|!FS_COLOR_RED ;CANE +dw #$0200 +dw #$0258|!FS_COLOR_RED, #$0259|!FS_COLOR_RED ;CAPE +dw #$0200 +dw #$025A|!FS_COLOR_BLUE, #$025B|!FS_COLOR_BLUE ;MIRROR +dw #$0200 +dw #$025C|!FS_COLOR_BOOTS, #$025D|!FS_COLOR_BOOTS ;BOOTS +dw #$0200 +dw #$025E|!FS_COLOR_BROWN, #$025F|!FS_COLOR_BROWN ;GLOVES +dw #$0200 +dw #$0200, #$019B|!FS_COLOR_BW ; Right + +%Layer3_VRAM_Address(!PASSWORD_INPUT_START_X,!PASSWORD_INPUT_START_Y+9) +%dw_big_endian(51) ;(9*4)+(8*2)-1 +dw #$020E|!FS_COLOR_BLUE, #$020F|!FS_COLOR_BLUE ;FLIPPERS +dw #$0200 +dw #$0264|!FS_COLOR_RED, #$0265|!FS_COLOR_RED ;PEARL +dw #$0200 +dw #$026D|!FS_COLOR_YELLOW, #$026E|!FS_COLOR_YELLOW ;SHIELD +dw #$0200 +dw #$026F|!FS_COLOR_GREEN, #$026F|!FS_COLOR_GREEN|!FS_HFLIP ;TUNIC +dw #$0200 +dw #$0281|!FS_COLOR_RED, #$0281|!FS_COLOR_RED|!FS_HFLIP ;HEART +dw #$0200 +dw #$0282|!FS_COLOR_YELLOW, #$0283|!FS_COLOR_YELLOW ;MAP +dw #$0200 +dw #$0284|!FS_COLOR_RED, #$0284|!FS_COLOR_RED|!FS_HFLIP ;COMPASS +dw #$0200 +dw #$022F|!FS_COLOR_YELLOW|!FS_HFLIP, #$022F|!FS_COLOR_YELLOW ;KEY +dw #$0200 +dw #$0267|!FS_COLOR_BW|!FS_HFLIP, #$0267|!FS_COLOR_BW ;cancel + +%Layer3_VRAM_Address(!PASSWORD_INPUT_START_X,!PASSWORD_INPUT_START_Y+10) +%dw_big_endian(51) ;(9*4)+(8*2)-1 +dw #$021F|!FS_COLOR_BLUE|!FS_HFLIP, #$021F|!FS_COLOR_BLUE ;FLIPPERS +dw #$0200 +dw #$0274|!FS_COLOR_RED, #$0275|!FS_COLOR_RED ;PEARL +dw #$0200 +dw #$027D|!FS_COLOR_YELLOW, #$027E|!FS_COLOR_YELLOW ;SHIELD +dw #$0200 +dw #$027F|!FS_COLOR_GREEN, #$027F|!FS_COLOR_GREEN|!FS_HFLIP ;TUNIC +dw #$0200 +dw #$0291|!FS_COLOR_RED, #$0291|!FS_COLOR_RED|!FS_HFLIP ;HEART +dw #$0200 +dw #$0292|!FS_COLOR_YELLOW, #$0293|!FS_COLOR_YELLOW ;MAP +dw #$0200 +dw #$0294|!FS_COLOR_RED, #$0294|!FS_COLOR_RED|!FS_HFLIP ;COMPASS +dw #$0200 +dw #$023E|!FS_COLOR_YELLOW, #$023F|!FS_COLOR_YELLOW ;KEY +dw #$0200 +dw #$0267|!FS_COLOR_BW|!FS_HFLIP|!FS_VFLIP, #$0267|!FS_VFLIP|!FS_COLOR_BW ;cancel + +dw $FFFF + +macro PasswordDisplaySlot(x,y) + %Layer3_VRAM_Address(!PASSWORD_DISPLAY_START_X+,!PASSWORD_DISPLAY_START_Y+) + %dw_big_endian(3) + dw #$0186|!FS_COLOR_BW, #$0186|!FS_COLOR_BW + %Layer3_VRAM_Address(!PASSWORD_DISPLAY_START_X+,!PASSWORD_DISPLAY_START_Y+1+) + %dw_big_endian(3) + dw #$0196|!FS_COLOR_BW, #$0196|!FS_COLOR_BW +endmacro +!FS_VERT_STRIPE = $8000 +Password_StripeImageTemplate: + %PasswordDisplaySlot(0,0) + %PasswordDisplaySlot(3,0) + %PasswordDisplaySlot(6,0) + %PasswordDisplaySlot(9,0) + %PasswordDisplaySlot(12,0) + %PasswordDisplaySlot(15,0) + %PasswordDisplaySlot(18,0) + %PasswordDisplaySlot(21,0) + %PasswordDisplaySlot(0,3) + %PasswordDisplaySlot(3,3) + %PasswordDisplaySlot(6,3) + %PasswordDisplaySlot(9,3) + %PasswordDisplaySlot(12,3) + %PasswordDisplaySlot(15,3) + %PasswordDisplaySlot(18,3) + %PasswordDisplaySlot(21,3) +.CodeCursorErase ; a code cursor erase (position get be updated) + %Layer3_VRAM_Address(!PASSWORD_DISPLAY_START_X,!PASSWORD_DISPLAY_START_Y+2) + %dw_big_endian(3) + dw #$0200, #$0200 +.CodeCursorDraw ; Then comes a code cursor draw (will override the erase if same position) + %Layer3_VRAM_Address(!PASSWORD_DISPLAY_START_X,!PASSWORD_DISPLAY_START_Y+2) + %dw_big_endian(3) + dw #$0267|!FS_COLOR_BW|!FS_HFLIP|!FS_VFLIP, #$0267|!FS_VFLIP|!FS_COLOR_BW +.SelectionCursorErase ; a selection cursor erase (position get be updated) + %Layer3_VRAM_Address(!PASSWORD_INPUT_START_X-1,!PASSWORD_INPUT_START_Y-1) + %dw_big_endian(7) + dw #$0200, #$0200, #$0200, #$0200 + %Layer3_VRAM_Address(!PASSWORD_INPUT_START_X-1,!PASSWORD_INPUT_START_Y) + %dw_big_endian(3|!FS_VERT_STRIPE) + dw #$0200, #$0200 + %Layer3_VRAM_Address(!PASSWORD_INPUT_START_X+2,!PASSWORD_INPUT_START_Y) + %dw_big_endian(3|!FS_VERT_STRIPE) + dw #$0200, #$0200 + %Layer3_VRAM_Address(!PASSWORD_INPUT_START_X-1,!PASSWORD_INPUT_START_Y+2) + %dw_big_endian(7) + dw #$0200, #$0200, #$0200, #$0200 +.SelectionCursorDraw ; Then comes a selection cursor draw (will override the erase if same position) + %Layer3_VRAM_Address(!PASSWORD_INPUT_START_X-1,!PASSWORD_INPUT_START_Y-1) + %dw_big_endian(7) + dw #$02BB|!FS_COLOR_GREEN, #$02BC|!FS_COLOR_GREEN, #$02BC|!FS_COLOR_GREEN|!FS_HFLIP, #$02BB|!FS_COLOR_GREEN|!FS_HFLIP + %Layer3_VRAM_Address(!PASSWORD_INPUT_START_X-1,!PASSWORD_INPUT_START_Y) + %dw_big_endian(3|!FS_VERT_STRIPE) + dw #$02BD|!FS_COLOR_GREEN, #$02BD|!FS_COLOR_GREEN|!FS_VFLIP + %Layer3_VRAM_Address(!PASSWORD_INPUT_START_X+2,!PASSWORD_INPUT_START_Y) + %dw_big_endian(3|!FS_VERT_STRIPE) + dw #$02BD|!FS_COLOR_GREEN|!FS_HFLIP, #$02BD|!FS_COLOR_GREEN|!FS_HFLIP|!FS_VFLIP + %Layer3_VRAM_Address(!PASSWORD_INPUT_START_X-1,!PASSWORD_INPUT_START_Y+2) + %dw_big_endian(7) + dw #$02BB|!FS_COLOR_GREEN|!FS_VFLIP, #$02BC|!FS_COLOR_GREEN|!FS_VFLIP, #$02BC|!FS_COLOR_GREEN|!FS_HFLIP|!FS_VFLIP, #$02BB|!FS_COLOR_GREEN|!FS_HFLIP|!FS_VFLIP +dw $FFFF +.end diff --git a/tables.asm b/tables.asm index 79a20e8..1c89fb8 100644 --- a/tables.asm +++ b/tables.asm @@ -357,7 +357,7 @@ db #$00 ; $00 = static rng, $01 = no extra blue balls/warps ;-------------------------------------------------------------------------------- org $308087 ; PC 0x180087 IsEncrypted: -dw #$0000 ; $0000 = not encrypted, $0001 = encrypted with static key, $0002 = Encrypted w/ passcode entry screen (Not implemented yet) +dw #$0000 ; $0000 = not encrypted, $0001 = encrypted with static key, $0002 = Encrypted w/ passcode entry screen ;-------------------------------------------------------------------------------- org $308089 ; PC 0x180089 TurtleRockAutoOpenFix: @@ -403,7 +403,11 @@ org $3080B0 ; 0x1800B0-0x1800BF StaticDecryptionKey: dd $00000000, $00000000, $00000000, $00000000 ;-------------------------------------------------------------------------------- -; 0x1800C0 - 0x1800FF (unused) +org $3080C0 ; 0x1800C0-0x1800C7 [encrypted] +KnownEncryptedValue: +db $31, $41, $59, $26, $53, $58, $97, $93 +;-------------------------------------------------------------------------------- +; 0x1800C8 - 0x1800FF (unused) ;-------------------------------------------------------------------------------- org $308100 ; PC 0x180100 (0x40 bytes) ShovelSpawnTable: @@ -1403,7 +1407,7 @@ dw #9999 ; Rupee Limit ; $7F509B - MSU Flag ; $7F509C - Inverted Mode Duck Map Temporary ; $7F509D - Stalfos Bomb Damage Value - +; $7F509E - Valid Key Loaded ; $7F50A0 - Event Parameter 1 ; $7F50B0 - $7F50BF - Downstream Reserved (Enemizer)