Compare commits

...

1 Commits
0.1.2 ... main

Author SHA1 Message Date
LinkHpp
ff800acbfc Change NMI to use only necessary, the rest in mainloop 2025-04-01 08:17:37 +02:00
5 changed files with 75 additions and 25 deletions

BIN
spaceship.nes Normal file

Binary file not shown.

BIN
src/controllers.o Normal file

Binary file not shown.

BIN
src/reset.o Normal file

Binary file not shown.

View File

@ -9,35 +9,43 @@
.import read_controller
.proc nmi_handler
PHP
PHA
TXA
PHA
TYA
PHA
; copy sprite data to OAM
LDA #$00
STA OAMADDR
LDA #$02
STA OAMDMA
;Update tiles *after* DMA transfer
JSR update_player
JSR draw_player
JSR read_controller
LDA scroll
CMP #$00
BNE set_scroll_positions
LDA ppucrtl_settings
EOR #%00000010
STA ppucrtl_settings
; set PPUCTRL
LDA ppuctrl_settings
STA PPUCTRL
LDA #240
STA scroll
set_scroll_positions:
LDA #$00
; set scroll values
LDA #$00 ; X scroll first
STA PPUSCROLL
DEC scroll
LDA scroll
STA PPUSCROLL
; all done
LDA #$00
STA sleeping
LDA#$00
STA sleeping
PLA
TAY
PLA
TAX
PLA
PLP
RTI
.endproc
@ -160,9 +168,6 @@ done_checking:
.export main
.proc main
LDA #239
STA scroll
LDX PPUSTATUS
LDX #$3f
STX PPUADDR
@ -236,7 +241,7 @@ insideloop2:
BNE outsideloop2
LDA #%10010000
STA ppucrtl_settings
STA ppuctrl_settings
STA PPUCTRL
vblankwait: ; wait for another vblank before continuing
@ -247,8 +252,34 @@ vblankwait: ; wait for another vblank before continuing
STA PPUCTRL
LDA #%00011110 ; turn on screen
STA PPUMASK
forever:
JMP forever
mainloop:
;Update tiles *after* DMA transfer
JSR update_player
JSR draw_player
JSR read_controller
; Check if PPUCTRL needs to change
LDA scroll ; did we reach the end of a nametable?
BNE update_scroll
; if yes,
; Update base nametable
LDA ppuctrl_settings
EOR #%00000010 ; flip bit 1 to its opposite
STA ppuctrl_settings
; Reset scroll to 240
LDA #240
STA scroll
update_scroll:
DEC scroll
; Done processing; wait for next Vblank
INC sleeping
sleep:
LDA sleeping
BNE sleep
JMP mainloop
.endproc
.segment "ZEROPAGE"
@ -257,11 +288,30 @@ player_y: .res 1
pointerLo: .res 1
pointerHi: .res 1
scroll: .res 1
ppucrtl_settings: .res 1
ppuctrl_settings: .res 1
pad1: .res 1
.exportzp player_x, player_y
.exportzp pad1
sleeping: .res 1
NUM_ENEMIES = 5
; enemy object pool
enemy_x_pos: .res NUM_ENEMIES
enemy_y_pos: .res NUM_ENEMIES
enemy_x_vels: .res NUM_ENEMIES
enemy_y_vels: .res NUM_ENEMIES
enemy_flags: .res NUM_ENEMIES
; player bullet pool
bullet_xs: .res 3
bullet_ys: .res 3
;export all pools
.exportzp enemy_x_pos, enemy_y_pos
.exportzp enemy_x_vels, enemy_y_vels
.exportzp enemy_flags
.segment "RODATA"
palettes: .incbin "background.pal"

BIN
src/spaceship.o Normal file

Binary file not shown.