Commit: f8502ff279c0d044d87d94b7fea9373f204d7dd5 Parent: d5773686022a9c34ecc5c1c2b9d02e404e3a5535 Author: Vi Grey Date: 2026-01-25 07:43 UTC Summary: I think I'm (hopefully) finished with the NES port nes/src/achievements.asm | 63 +++++++++++++++++++++++++++++++++++++++------------------------ nes/src/defs.asm | 2 ++ nes/src/draw.asm | 2 -- nes/src/prg.asm | 18 ++++++++++++++---- nes/src/ram.asm | 8 ++++---- nes/src/save.asm | 21 ++++++++++++++------- nes/src/turn.asm | 2 +- 7 files changed, 74 insertions(+), 42 deletions(-) diff --git a/nes/src/achievements.asm b/nes/src/achievements.asm index 7887bea..b2094d5 100644 --- a/nes/src/achievements.asm +++ b/nes/src/achievements.asm @@ -1,7 +1,14 @@ +; Achievements[i]: +; i=0: 3x3 +; i=1: 3x3x1 +; i=2: 3x3x3? +; i=3: 3x3x3 +; i=4: solvedFalse +; i=5: solvedTrue ResetScrambleAchievements: push setBusy - ldx #3 + ldx #5 lda #0 @loop: sta scrambleAchievements, x @@ -16,20 +23,10 @@ ResetScrambleAchievements: HandleTotalSolveAchievements: push - lda (totalAchievements + 2) - and (totalAchievements + 3) - and #1 - bne + - ; 1 or 0 of the Solved achievements have been gained - lda (totalAchievements + 2) - ora (totalAchievements + 3) - and #1 - ; Set SolvedFalse achievement to 1 if either solve happened - sta (totalAchievements + 2) - ldx #0 - ; set SolvedTrue achievement to 0 - sta (totalAchievements + 3) -+ + lda (totalAchievements + 4) + and (totalAchievements + 5) + sta (totalAchievements + 4) + sta (totalAchievements + 5) pop rts @@ -67,13 +64,13 @@ CheckFrontEdge: bne + dex bpl @loopUD - ldx #5 + ldx #6 @loopLR: lda (cubeShades + 38), x - cmp (cubeShades + 40) + cmp (cubeShades + 41) bne + lda (cubeShades + 18), x - cmp (cubeShades + 22) + cmp (cubeShades + 21) bne + dex dex @@ -91,7 +88,7 @@ CheckSolveFalse: push lda #0 sta checkTmp - ldx #8 + ldx #2 @loop: lda (cubeShades + 0), x cmp (cubeShades + 49) @@ -117,7 +114,7 @@ CheckSolveTrue: push lda #0 sta checkTmp - ldx #8 + ldx #2 @loop: lda (cubeShades + 0), x cmp (cubeShades + 4) @@ -154,22 +151,40 @@ SetAchievements: lda #1 sta (scrambleAchievements + 1) sta (totalAchievements + 1) + inc $4f0 jsr CheckSolveFalse lda checkTmp beq + + inc $4f1 ; Cube appears solved, but technically isn't due to U, R, L, and D centers lda #1 - sta (scrambleAchievements + 2) - sta (totalAchievements + 2) + sta (scrambleAchievements + 4) + sta (totalAchievements + 4) + jsr CheckSolveTrue lda checkTmp beq ++ ; Cube is truly solved lda #1 - sta (scrambleAchievements + 3) - sta (totalAchievements + 3) + sta (scrambleAchievements + 5) + sta (totalAchievements + 5) ++ + lda (scrambleAchievements + 4) + ora (scrambleAchievements + 5) ; scramble solvedFalse | scramble solvedTrue (either happened) + ora (scrambleAchievements + 2) ; either happened or 3x3x3? achievement already set + sta (scrambleAchievements + 2) + lda (scrambleAchievements + 4) + and (scrambleAchievements + 5) ; scramble solvedFalse & scramble solvedTrue (both happened) + ora (scrambleAchievements + 3) ; both happened or 3x3x3 achievement already set + sta (scrambleAchievements + 3) + lda (totalAchievements + 4) + ora (totalAchievements + 5) ; total solvedFalse | total solvedTrue (either happened) + ora (totalAchievements + 2) ; either happened or 3x3x3? achievement already set + sta (totalAchievements + 2) + lda (totalAchievements + 4) + and (totalAchievements + 5) ; total solvedFalse & total solvedTrue (both happened) + ora (totalAchievements + 3) ; both happened or 3x3x3 achievement already set + sta (totalAchievements + 3) pop rts diff --git a/nes/src/defs.asm b/nes/src/defs.asm index 946bf96..9acde89 100644 --- a/nes/src/defs.asm +++ b/nes/src/defs.asm @@ -98,3 +98,5 @@ FACE_R = 2 << 1 FACE_B = 3 << 1 FACE_L = 4 << 1 FACE_D = 5 << 1 + +SAVE_DATA_SIZE = 54 + 6 + 6 + 2 diff --git a/nes/src/draw.asm b/nes/src/draw.asm index ae1f292..8258f2e 100644 --- a/nes/src/draw.asm +++ b/nes/src/draw.asm @@ -319,8 +319,6 @@ ResetCubeAttributes: sta shadowAttributeTable, x dey bpl @loop - lda #1 - sta grayscale jsr DrawCubeAttributes lda #1 sta vramBufferReady diff --git a/nes/src/prg.asm b/nes/src/prg.asm index 0902061..4b2fc85 100644 --- a/nes/src/prg.asm +++ b/nes/src/prg.asm @@ -15,13 +15,23 @@ RESET: jsr VBlankWait ; Wait 2 frames before writing anything to PPU memory jsr VBlankWait jsr SetPalettes ; Set palette to prevent random startup blank color - lda #1 - sta grayscale jsr InitializeLFSR - jsr DrawScreen - jsr InitializeCubeData + lda #0 + sta grayscale jsr InitializeShadowAttributeTable + jsr InitialCubeCheck + lda checkTmp + bne + + lda #1 + sta grayscale + jsr DrawScreen + jsr NMIWait + jsr ResetInitialCube + jmp ++ ++: + jsr DrawScreen jsr NMIWait +++: jsr ResetCubeAttributes lda #0 sta grayscale diff --git a/nes/src/ram.asm b/nes/src/ram.asm index 8cf392d..2fb748c 100644 --- a/nes/src/ram.asm +++ b/nes/src/ram.asm @@ -22,8 +22,8 @@ ende ; Cube and Achievements enum $0400 Cube: - totalAchievements dsb 4 - scrambleAchievements dsb 4 + totalAchievements dsb 6 + scrambleAchievements dsb 6 cubeShades dsb 54 crc16 dsb 2 crc16Tmp dsb 2 @@ -54,8 +54,8 @@ ende enum $6000 CubeSaved: - totalAchievementsSaved dsb 4 - scrambleAchievementsSaved dsb 4 + totalAchievementsSaved dsb 6 + scrambleAchievementsSaved dsb 6 cubeShadesSaved dsb 54 crc16Saved dsb 2 ende diff --git a/nes/src/save.asm b/nes/src/save.asm index f317aa6..f473e44 100644 --- a/nes/src/save.asm +++ b/nes/src/save.asm @@ -114,7 +114,7 @@ CheckAchievements: SaveData: push - ldy #(4 + 4 + 54 + 2 - 1) + ldy #(SAVE_DATA_SIZE - 1) @loop: lda Cube, y sta CubeSaved, y @@ -125,7 +125,7 @@ SaveData: LoadData: push - ldy #(4 + 4 + 54 + 2 - 1) + ldy #(SAVE_DATA_SIZE - 1) @loop: lda CubeSaved, y sta Cube, y @@ -143,7 +143,7 @@ CheckSaveData: sta addr lda #>(CubeSaved) sta (addr + 1) - lda #(54 + 4 + 4 - 1) + lda #(SAVE_DATA_SIZE - 2 - 1) sta counter jsr CRC16IBMChecksum lda crc16Tmp @@ -171,7 +171,7 @@ CheckCubeData: sta addr lda #>(Cube) sta (addr + 1) - lda #(54 + 4 + 4 - 1) + lda #(SAVE_DATA_SIZE - 2 - 1) sta counter jsr CRC16IBMChecksum lda crc16Tmp @@ -192,8 +192,10 @@ CheckCubeData: ; Checks save data ; If save data is invalid, check cube RAM data -; If cube RAM data is invalid, scramble cube -InitializeCubeData: +; If cube RAM data is invalid, set checkTmp to 0 +; otherwise set checkTmp to 1 +; If valid, both RAM points will be set to equal +InitialCubeCheck: push jsr CheckSaveData lda checkTmp @@ -207,9 +209,14 @@ InitializeCubeData: jsr SaveData jmp ++ + +++ + pop + rts + +ResetInitialCube: + push jsr ResetCubeRAM jsr ScrambleCube jsr AfterTurn -++ pop rts diff --git a/nes/src/turn.asm b/nes/src/turn.asm index 4cbb19f..8c5f952 100644 --- a/nes/src/turn.asm +++ b/nes/src/turn.asm @@ -5,7 +5,7 @@ AfterTurn: sta addr lda #>(Cube) sta (addr + 1) - lda #(54 + 4 + 4 - 1) + lda #(SAVE_DATA_SIZE - 2 - 1) sta counter jsr CRC16IBMChecksum lda crc16Tmp