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"
|
||||
reset:
|
||||
sei
|
||||
lda #0
|
||||
lda #%00100000 ; 8x16 sprites
|
||||
sta $2000
|
||||
lda #0
|
||||
sta $2001
|
||||
sta $4015
|
||||
sta $4010
|
||||
@@ -324,7 +325,27 @@ gamepad_poll:
|
||||
|
||||
|
||||
.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:
|
||||
.byte $0F,$00,$3D,$20 ; greyscale
|
||||
.byte $0F,$09,$1A,$16 ; grass
|
||||
.byte $0F,$15,$26,$37 ; bg0 purple/pink
|
||||
.byte $0F,$09,$19,$29 ; bg1 green
|
||||
.byte $0F,$01,$11,$21 ; bg2 blue
|
||||
@@ -335,12 +356,16 @@ example_palette:
|
||||
.byte $0F,$12,$22,$32 ; sp3 marine
|
||||
|
||||
.segment "ZEROPAGE"
|
||||
velocities: .res 8
|
||||
buttons: .res 1
|
||||
|
||||
vel_x: .res 1
|
||||
vel_y: .res 1
|
||||
|
||||
cursor_x: .res 1
|
||||
cursor_y: .res 1
|
||||
temp_x: .res 1
|
||||
temp_y: .res 1
|
||||
temp_mul: .res 1
|
||||
var_m: .res 1
|
||||
var_n: .res 1
|
||||
var_o: .res 1
|
||||
@@ -370,14 +395,18 @@ main:
|
||||
|
||||
jsr init_objects
|
||||
@loop:
|
||||
@draw:
|
||||
jsr draw
|
||||
jsr ppu_update
|
||||
|
||||
lda frame_counter
|
||||
clc
|
||||
adc #1
|
||||
sta frame_counter
|
||||
|
||||
jsr controller
|
||||
jsr movement
|
||||
|
||||
@draw:
|
||||
jsr update_background
|
||||
jsr ppu_update
|
||||
|
||||
jmp @loop
|
||||
|
||||
init_objects:
|
||||
@@ -398,10 +427,6 @@ init_objects:
|
||||
lsr
|
||||
sta oam+1, X
|
||||
|
||||
tay
|
||||
lda #0
|
||||
sta velocities, Y
|
||||
|
||||
inx
|
||||
inx
|
||||
inx
|
||||
@@ -409,43 +434,119 @@ init_objects:
|
||||
cpx #(8*4)
|
||||
bne :-
|
||||
|
||||
lda #0
|
||||
sta vel_x
|
||||
sta vel_y
|
||||
|
||||
rts
|
||||
|
||||
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
|
||||
and #1
|
||||
cmp #0
|
||||
bne @end
|
||||
|
||||
ldx #0
|
||||
ldy #0
|
||||
:
|
||||
lda velocities, Y
|
||||
bne :+
|
||||
lda vel_y
|
||||
clc
|
||||
adc #1 ; Add 2 to velocity
|
||||
sta velocities, Y
|
||||
sta vel_y
|
||||
:
|
||||
|
||||
lda oam+0, X
|
||||
clc
|
||||
adc velocities, Y
|
||||
sta oam+0, X
|
||||
; Apply Y velocity
|
||||
lda oam+0
|
||||
clc
|
||||
adc vel_y
|
||||
sta oam+0
|
||||
|
||||
cmp #200
|
||||
bmi :+
|
||||
lda #245
|
||||
sta velocities, Y
|
||||
:
|
||||
; Keep grounded
|
||||
cmp #200
|
||||
bcc :+
|
||||
lda #0
|
||||
sta vel_y
|
||||
lda #200
|
||||
sta oam+0
|
||||
:
|
||||
|
||||
inx
|
||||
inx
|
||||
inx
|
||||
inx
|
||||
; Apply X velocity
|
||||
lda oam+3
|
||||
clc
|
||||
adc vel_x
|
||||
sta oam+3
|
||||
|
||||
iny
|
||||
cpy #8
|
||||
bne :--
|
||||
@end:
|
||||
rts
|
||||
|
||||
rts
|
||||
|
||||
update_background:
|
||||
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:
|
||||
lda $2002 ; reset latch
|
||||
@@ -465,14 +566,45 @@ setup_background:
|
||||
dey
|
||||
bne :--
|
||||
; set all attributes to 0
|
||||
lda #0
|
||||
ldx #64 ; 64 bytes
|
||||
:
|
||||
txa
|
||||
and #%00000011
|
||||
asl
|
||||
asl
|
||||
asl
|
||||
asl
|
||||
sta temp
|
||||
txa
|
||||
and #%00000011
|
||||
ora temp
|
||||
lda #0
|
||||
|
||||
sta $2007
|
||||
dex
|
||||
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
|
||||
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
|
||||
ldx #8 ; start at column 8
|
||||
@@ -528,3 +660,105 @@ setup_background:
|
||||
|
||||
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