Trying to nametable the player

This commit is contained in:
2026-02-19 16:52:08 -05:00
parent ce263cfa0d
commit 739fab66b4
2 changed files with 56 additions and 1 deletions

BIN
plat.nes

Binary file not shown.

57
plat.s
View File

@@ -326,6 +326,7 @@ example_palette:
buttons: .res 1 buttons: .res 1
player_pos_x: .res 1 player_pos_x: .res 1
player_nmt_x: .res 1
player_pos_y: .res 1 player_pos_y: .res 1
player_subpos_x: .res 1 ; XXXXYYYY | first 4 bits X subposition, last 4 bits Y player_subpos_x: .res 1 ; XXXXYYYY | first 4 bits X subposition, last 4 bits Y
player_subpos_y: .res 1 ; XXXXYYYY | first 4 bits X subposition, last 4 bits Y player_subpos_y: .res 1 ; XXXXYYYY | first 4 bits X subposition, last 4 bits Y
@@ -333,6 +334,8 @@ player_vel_x: .res 1 ; +PPPSSSS | first bit sign, next 3 pixels, last subpixel
player_vel_y: .res 1 ; in subpixels player_vel_y: .res 1 ; in subpixels
player_status: .res 1 ; 76543210 | 0: facing (0 right, 1 left) player_status: .res 1 ; 76543210 | 0: facing (0 right, 1 left)
; | 1: nametable X
; | 2: nametable Y
; | 7: talking ; | 7: talking
horizontal_speed: .res 1 horizontal_speed: .res 1
@@ -382,8 +385,15 @@ main:
adc #1 adc #1
sta frame_counter sta frame_counter
lda scroll_x
adc #1
cmp scroll_x
sta scroll_x sta scroll_x
bcs :+
lda scroll_nmt
eor #%00000001
sta scroll_nmt
:
jsr controller jsr controller
jsr movement jsr movement
@@ -406,6 +416,47 @@ draw_player:
sta oam + (4 * 0) + 0 sta oam + (4 * 0) + 0
sta oam + (4 * 1) + 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 lda player_status
and #%00000001 and #%00000001
cmp #0 cmp #0
@@ -432,6 +483,8 @@ draw_player:
sta oam + (4 * 3) + 3 sta oam + (4 * 3) + 3
: :
@end_position_application:
lda player_status lda player_status
and #%10000000 and #%10000000
cmp #0 cmp #0
@@ -606,6 +659,8 @@ movement:
: :
@end: @end:
; Jump ; Jump
jsr btn_a jsr btn_a
cmp #0 cmp #0