Nametable confusion
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
*.o
|
||||||
|
.DS_Store
|
||||||
|
run
|
||||||
Binary file not shown.
306
game.s → plat.s
306
game.s → plat.s
@@ -26,8 +26,9 @@ INES_SRAM = 0
|
|||||||
.segment "CODE"
|
.segment "CODE"
|
||||||
reset:
|
reset:
|
||||||
sei
|
sei
|
||||||
lda #0
|
lda #%00100000 ; 8x16 sprites
|
||||||
sta $2000
|
sta $2000
|
||||||
|
lda #0
|
||||||
sta $2001
|
sta $2001
|
||||||
sta $4015
|
sta $4015
|
||||||
sta $4010
|
sta $4010
|
||||||
@@ -324,7 +325,27 @@ gamepad_poll:
|
|||||||
|
|
||||||
|
|
||||||
.segment "RODATA"
|
.segment "RODATA"
|
||||||
|
|
||||||
|
level:
|
||||||
|
.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
.byte 0,1,0,0,1,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,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
.byte 0,0,1,1,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,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,0,0,0,0,0
|
||||||
|
.byte 0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0
|
||||||
|
.byte 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0
|
||||||
|
.byte 0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0
|
||||||
|
.byte 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0
|
||||||
|
.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
|
||||||
example_palette:
|
example_palette:
|
||||||
|
.byte $0F,$00,$3D,$20 ; greyscale
|
||||||
|
.byte $0F,$09,$1A,$16 ; grass
|
||||||
.byte $0F,$15,$26,$37 ; bg0 purple/pink
|
.byte $0F,$15,$26,$37 ; bg0 purple/pink
|
||||||
.byte $0F,$09,$19,$29 ; bg1 green
|
.byte $0F,$09,$19,$29 ; bg1 green
|
||||||
.byte $0F,$01,$11,$21 ; bg2 blue
|
.byte $0F,$01,$11,$21 ; bg2 blue
|
||||||
@@ -335,12 +356,16 @@ example_palette:
|
|||||||
.byte $0F,$12,$22,$32 ; sp3 marine
|
.byte $0F,$12,$22,$32 ; sp3 marine
|
||||||
|
|
||||||
.segment "ZEROPAGE"
|
.segment "ZEROPAGE"
|
||||||
velocities: .res 8
|
buttons: .res 1
|
||||||
|
|
||||||
|
vel_x: .res 1
|
||||||
|
vel_y: .res 1
|
||||||
|
|
||||||
cursor_x: .res 1
|
cursor_x: .res 1
|
||||||
cursor_y: .res 1
|
cursor_y: .res 1
|
||||||
temp_x: .res 1
|
temp_x: .res 1
|
||||||
temp_y: .res 1
|
temp_y: .res 1
|
||||||
|
temp_mul: .res 1
|
||||||
var_m: .res 1
|
var_m: .res 1
|
||||||
var_n: .res 1
|
var_n: .res 1
|
||||||
var_o: .res 1
|
var_o: .res 1
|
||||||
@@ -370,14 +395,18 @@ main:
|
|||||||
|
|
||||||
jsr init_objects
|
jsr init_objects
|
||||||
@loop:
|
@loop:
|
||||||
@draw:
|
|
||||||
jsr draw
|
|
||||||
jsr ppu_update
|
|
||||||
|
|
||||||
lda frame_counter
|
lda frame_counter
|
||||||
clc
|
clc
|
||||||
adc #1
|
adc #1
|
||||||
sta frame_counter
|
sta frame_counter
|
||||||
|
|
||||||
|
jsr controller
|
||||||
|
jsr movement
|
||||||
|
|
||||||
|
@draw:
|
||||||
|
jsr update_background
|
||||||
|
jsr ppu_update
|
||||||
|
|
||||||
jmp @loop
|
jmp @loop
|
||||||
|
|
||||||
init_objects:
|
init_objects:
|
||||||
@@ -398,10 +427,6 @@ init_objects:
|
|||||||
lsr
|
lsr
|
||||||
sta oam+1, X
|
sta oam+1, X
|
||||||
|
|
||||||
tay
|
|
||||||
lda #0
|
|
||||||
sta velocities, Y
|
|
||||||
|
|
||||||
inx
|
inx
|
||||||
inx
|
inx
|
||||||
inx
|
inx
|
||||||
@@ -409,43 +434,119 @@ init_objects:
|
|||||||
cpx #(8*4)
|
cpx #(8*4)
|
||||||
bne :-
|
bne :-
|
||||||
|
|
||||||
|
lda #0
|
||||||
|
sta vel_x
|
||||||
|
sta vel_y
|
||||||
|
|
||||||
rts
|
rts
|
||||||
|
|
||||||
draw:
|
draw:
|
||||||
|
@end:
|
||||||
|
rts
|
||||||
|
|
||||||
|
movement:
|
||||||
|
; Horizontal velocity
|
||||||
|
ldx #0
|
||||||
|
jsr btn_right
|
||||||
|
cmp #0
|
||||||
|
beq :+
|
||||||
|
ldx #1
|
||||||
|
lda #3
|
||||||
|
sta vel_x
|
||||||
|
:
|
||||||
|
|
||||||
|
jsr btn_left
|
||||||
|
cmp #0
|
||||||
|
beq :+
|
||||||
|
ldx #1
|
||||||
|
lda #253
|
||||||
|
sta vel_x
|
||||||
|
:
|
||||||
|
|
||||||
|
cpx #1
|
||||||
|
beq @end
|
||||||
|
lda frame_counter
|
||||||
|
and #1
|
||||||
|
cmp #0
|
||||||
|
bne @end
|
||||||
|
|
||||||
|
lda #0
|
||||||
|
cmp vel_x
|
||||||
|
beq @end ; If vel_x = 0, skip decay
|
||||||
|
|
||||||
|
; If vel_x > 0, decrement
|
||||||
|
bpl :+
|
||||||
|
ldx vel_x
|
||||||
|
dex
|
||||||
|
stx vel_x
|
||||||
|
jmp @end
|
||||||
|
:
|
||||||
|
; Else if vel_x < 0, increment
|
||||||
|
ldx vel_x
|
||||||
|
inx
|
||||||
|
stx vel_x
|
||||||
|
@end:
|
||||||
|
|
||||||
|
; Jump
|
||||||
|
jsr btn_up
|
||||||
|
cmp #0
|
||||||
|
beq :+
|
||||||
|
lda #250
|
||||||
|
sta vel_y
|
||||||
|
:
|
||||||
|
|
||||||
|
|
||||||
|
; Gravity
|
||||||
lda frame_counter
|
lda frame_counter
|
||||||
and #1
|
and #1
|
||||||
cmp #0
|
cmp #0
|
||||||
bne @end
|
bne :+
|
||||||
|
lda vel_y
|
||||||
ldx #0
|
|
||||||
ldy #0
|
|
||||||
:
|
|
||||||
lda velocities, Y
|
|
||||||
clc
|
clc
|
||||||
adc #1 ; Add 2 to velocity
|
adc #1 ; Add 2 to velocity
|
||||||
sta velocities, Y
|
sta vel_y
|
||||||
|
:
|
||||||
|
|
||||||
lda oam+0, X
|
; Apply Y velocity
|
||||||
clc
|
lda oam+0
|
||||||
adc velocities, Y
|
clc
|
||||||
sta oam+0, X
|
adc vel_y
|
||||||
|
sta oam+0
|
||||||
|
|
||||||
cmp #200
|
; Keep grounded
|
||||||
bmi :+
|
cmp #200
|
||||||
lda #245
|
bcc :+
|
||||||
sta velocities, Y
|
lda #0
|
||||||
:
|
sta vel_y
|
||||||
|
lda #200
|
||||||
|
sta oam+0
|
||||||
|
:
|
||||||
|
|
||||||
inx
|
; Apply X velocity
|
||||||
inx
|
lda oam+3
|
||||||
inx
|
clc
|
||||||
inx
|
adc vel_x
|
||||||
|
sta oam+3
|
||||||
|
|
||||||
iny
|
|
||||||
cpy #8
|
rts
|
||||||
bne :--
|
|
||||||
@end:
|
update_background:
|
||||||
rts
|
rts
|
||||||
|
;lda $2002
|
||||||
|
;lda #$20
|
||||||
|
;sta $2006
|
||||||
|
;lda #$00
|
||||||
|
;sta $2006
|
||||||
|
|
||||||
|
ldx #1
|
||||||
|
ldy #1
|
||||||
|
jsr ppu_update_tile
|
||||||
|
|
||||||
|
lda #1
|
||||||
|
sta $2007
|
||||||
|
|
||||||
|
rts
|
||||||
|
|
||||||
setup_background:
|
setup_background:
|
||||||
lda $2002 ; reset latch
|
lda $2002 ; reset latch
|
||||||
@@ -465,14 +566,45 @@ setup_background:
|
|||||||
dey
|
dey
|
||||||
bne :--
|
bne :--
|
||||||
; set all attributes to 0
|
; set all attributes to 0
|
||||||
|
lda #0
|
||||||
ldx #64 ; 64 bytes
|
ldx #64 ; 64 bytes
|
||||||
:
|
:
|
||||||
|
txa
|
||||||
|
and #%00000011
|
||||||
|
asl
|
||||||
|
asl
|
||||||
|
asl
|
||||||
|
asl
|
||||||
|
sta temp
|
||||||
|
txa
|
||||||
|
and #%00000011
|
||||||
|
ora temp
|
||||||
|
lda #0
|
||||||
|
|
||||||
sta $2007
|
sta $2007
|
||||||
dex
|
dex
|
||||||
bne :-
|
bne :-
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
lda $2002
|
||||||
|
lda $20
|
||||||
|
sta $2006
|
||||||
|
lda $00
|
||||||
|
sta $2006
|
||||||
|
ldy #0
|
||||||
|
:
|
||||||
|
lda level, Y
|
||||||
|
lda #4
|
||||||
|
sta $2007
|
||||||
|
iny
|
||||||
|
cpy #240
|
||||||
|
bne :-
|
||||||
|
|
||||||
|
|
||||||
; fill in an area in the middle with 1/2 checkerboard
|
; fill in an area in the middle with 1/2 checkerboard
|
||||||
lda #1
|
lda #1
|
||||||
ldy #8 ; start at row 8
|
ldy #0 ; start at row 8
|
||||||
:
|
:
|
||||||
pha ; temporarily store A, it will be clobbered by ppu_address_tile routine
|
pha ; temporarily store A, it will be clobbered by ppu_address_tile routine
|
||||||
ldx #8 ; start at column 8
|
ldx #8 ; start at column 8
|
||||||
@@ -528,3 +660,105 @@ setup_background:
|
|||||||
|
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
mul_x:
|
||||||
|
sta temp_mul
|
||||||
|
lda #0
|
||||||
|
:
|
||||||
|
clc
|
||||||
|
adc temp_mul
|
||||||
|
dex
|
||||||
|
bne :-
|
||||||
|
rts
|
||||||
|
|
||||||
|
mul_y:
|
||||||
|
sta temp_mul
|
||||||
|
lda #0
|
||||||
|
:
|
||||||
|
clc
|
||||||
|
adc temp_mul
|
||||||
|
dey
|
||||||
|
bne :-
|
||||||
|
rts
|
||||||
|
|
||||||
|
controller:
|
||||||
|
lda #1
|
||||||
|
sta $4016
|
||||||
|
sta buttons
|
||||||
|
lda #0
|
||||||
|
sta $4016
|
||||||
|
:
|
||||||
|
lda $4016
|
||||||
|
lsr
|
||||||
|
rol buttons
|
||||||
|
bcc :-
|
||||||
|
|
||||||
|
rts
|
||||||
|
|
||||||
|
btn_right:
|
||||||
|
lda buttons
|
||||||
|
and #%00000001
|
||||||
|
rts
|
||||||
|
|
||||||
|
btn_left:
|
||||||
|
lda buttons
|
||||||
|
and #%00000010
|
||||||
|
lsr
|
||||||
|
rts
|
||||||
|
|
||||||
|
btn_down:
|
||||||
|
lda buttons
|
||||||
|
and #%00000100
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
rts
|
||||||
|
|
||||||
|
btn_up:
|
||||||
|
lda buttons
|
||||||
|
and #%00001000
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
rts
|
||||||
|
|
||||||
|
btn_start:
|
||||||
|
lda buttons
|
||||||
|
and #%00010000
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
rts
|
||||||
|
|
||||||
|
btn_select:
|
||||||
|
lda buttons
|
||||||
|
and #%00100000
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
rts
|
||||||
|
|
||||||
|
btn_b:
|
||||||
|
lda buttons
|
||||||
|
and #%01000000
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
rts
|
||||||
|
|
||||||
|
btn_a:
|
||||||
|
lda buttons
|
||||||
|
and #%10000000
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
rts
|
||||||
|
|
||||||
BIN
sprite.chr
BIN
sprite.chr
Binary file not shown.
Reference in New Issue
Block a user