From 7016042cff8791e37fb5afff2d2bc3461f75836b Mon Sep 17 00:00:00 2001 From: RochesterX Date: Sat, 21 Feb 2026 14:31:21 -0500 Subject: [PATCH] Stable scrolling and nametable logging --- plat.nes | Bin 40976 -> 40976 bytes plat.s | 181 ++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 113 insertions(+), 68 deletions(-) diff --git a/plat.nes b/plat.nes index 82e5f6bb6ad04a961400e53a760db58b787ea3a9..9c9c72f43616632cfbbd307ef4c4cefcb735271c 100644 GIT binary patch delta 919 zcma))PiWIn9LJN_G;Pz>q-rpVU7rj#I#4$}SkZ%>OseD}9z5tlh6TIBF2eBErsbup z7zhMBDM<0nrXUpR{BtM_S;gLZ=oso{hYq@1JV?=l_>!hwD+&^L;F-!?!aO<=%Sg-alj0Dkvp7hy2oj@ID8@HJC}f4J zJm%~Whh6z)-kyyw_n$ykvS&$-{n>GN%t|L#BuX2ec4?tW&GB$Wg%1lbT7Vx_`BR>p zZng__w3qPYu{dH0E!TN@M-mi3bh1O1qdX!W}Q-FV>ZyfZkah^H7 z&@PlsFCohB-xZNq-ySJBE+rDFGbXv>-hpVWGZzQjY_0wGHbZoDo2|96Z5kt`dvSYA za>eZfk!&+%YD#@K)TKY=Y^Ylx`y$+{g+?5~%=jn9r1*SY?CJ}_VoJ89)$PI-naRdte2y`*W z30=;LHY=88&(V0=s%ANv-IKRTV~iVSDynpE_gMe2y}*eWLV$=NMjV5|jWB9S?KAxz zN5zhYXZL-M2Rmcf+8>M>WIf!kik=h|#) zaQqpuPV+BmNl4$>gzGISqR}~P`9AJB=%aFK{fVigap(Zrd}|U%He;k^*1$;-xI~;KZ+Y~)hWaxWSK4bu9?zd XjP*i7>LAd@OaJ11p}Mj`G79|#)oDoD diff --git a/plat.s b/plat.s index 026eb41..a639ff6 100644 --- a/plat.s +++ b/plat.s @@ -279,20 +279,37 @@ level: level2: .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -.byte 0,0,0,0,0,0,0,0,0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te 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +;.byte 0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0 +;.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +;.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +;.byte 0,0,0,0,0,0,0,0,0,0,0,10,10,10,10,10 +;.byte 0,0,0,0,0,0,0,0,0,0,0,11,11,11,11,11 +;.byte 0,1,7,7,7,7,7,7,7,1,0,11,11,11,11,11 +;.byte 0,0,0,0,0,0,0,0,0,0,0,11,11,11,11,11 metatiles: .byte 0,0,0,0,0 @@ -385,19 +402,9 @@ main: adc #1 sta frame_counter - lda scroll_x - adc #1 - cmp scroll_x - sta scroll_x - bcs :+ - lda scroll_nmt - eor #%00000001 - sta scroll_nmt - : - jsr controller jsr movement - lda player_pos_x + jsr move_camera @draw: jsr draw_player @@ -405,7 +412,40 @@ main: jmp @loop +move_camera: + lda scroll_x + clc + adc #0 + cmp scroll_x + sta scroll_x + bcs :+ + lda scroll_nmt + eor #%00000001 + sta scroll_nmt + : + rts + draw_player: + ; see if we can skip drawing the player because it's off screen + lda player_pos_x + sec + sbc scroll_x + cmp player_pos_x ; if underflow, nametable bits must be different to continue + beq @skip_bcs + bcs :+ + @skip_bcs: + lda player_nmt_x + eor scroll_nmt + beq @hide_player + jmp :++ + : + ; if nothing, nametable bits must be same to continue + lda player_nmt_x + eor scroll_nmt + bne @hide_player + : + + lda player_pos_y sec sbc #1 @@ -416,47 +456,6 @@ draw_player: sta oam + (4 * 0) + 0 sta oam + (4 * 1) + 0 - - -jmp @after - ; see if we can skip drawing the player because it's off screen - lda player_pos_x - sec - sbc scroll_x - cmp player_pos_x ; if underflow, nametable bits must be different to continue - bcs :+ - lda player_status - clc - ror - eor scroll_nmt - beq @end_position_application - jmp :++ - : - ; if nothing, nametable bits must be same to continue - lda player_status - clc - ror - eor scroll_nmt - bne @end_position_application - : -@after: - - -;;;;;;;;;;;;;;;;;;;;;;;;;PUT WHEN VELOCITY IS BEING APPLIED - lda player_pos_x - adc #1 - cmp player_pos_x - sta player_pos_x - bcs :+ - lda player_status - eor #%00000010 - sta player_status - : -;;;;;;;;;;;;;;;;;;;;;;;;; - - - - lda player_status and #%00000001 cmp #0 @@ -482,8 +481,17 @@ jmp @after sta oam + (4 * 1) + 3 sta oam + (4 * 3) + 3 : + jmp @end_hide_player - @end_position_application: + @hide_player: + + lda #250 + sta oam + (4 * 2) + 0 + sta oam + (4 * 3) + 0 + sta oam + (4 * 0) + 0 + sta oam + (4 * 1) + 0 + + @end_hide_player: lda player_status and #%10000000 @@ -709,6 +717,7 @@ movement: bne :+ ; 0: right lda player_vel_x + sta var_o ; store initial velocity in o and #%01111111 clc ror @@ -721,6 +730,12 @@ movement: clc adc player_pos_x sta player_pos_x ; add pixels + bcc @end_pixel_overflow_right + lda player_nmt_x + eor #%00000001 + sta player_nmt_x + @end_pixel_overflow_right: + lda player_vel_x ; A contains signed subpixels @@ -732,15 +747,22 @@ movement: sta player_subpos_x beq @end_add_subpos bcs @end_add_subpos ; so skip if subpos is smaller than result - ldx player_pos_x - inx - stx player_pos_x + lda player_pos_x + clc + adc #1 + sta player_pos_x + bcc @end_subpixel_overflow_right + lda player_nmt_x + eor #%00000001 + sta player_nmt_x + @end_subpixel_overflow_right: @end_add_subpos: jmp :++ : ; 1: left lda player_vel_x + sta var_o sec ror sec @@ -751,10 +773,23 @@ movement: ror ora #%10000000 clc - adc #1 - clc adc player_pos_x sta player_pos_x ; add pixels + bcs @end_pixel_overflow_left + lda player_nmt_x + eor #%00000001 + sta player_nmt_x + @end_pixel_overflow_left: + ; :| + lda player_pos_x + clc + adc #1 + sta player_pos_x ; add... correction? + bcc @end_correction + lda player_nmt_x + eor #%00000001 + sta player_nmt_x + @end_correction: lda player_vel_x @@ -767,13 +802,23 @@ movement: sta player_subpos_x beq @end_sub_subpos bcc @end_sub_subpos ; so skip if subpos is bigger than result - ldx player_pos_x - dex - stx player_pos_x + lda player_pos_x + sec + sbc #1 + sta player_pos_x + bcs @end_subpixel_overflow_left + lda player_nmt_x + eor #%00000001 + sta player_nmt_x + @end_subpixel_overflow_left: @end_sub_subpos: : + + + + ; load x pos, filter blocks, check up and down lda player_vel_y