aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <msabate@suse.com>2023-12-03 07:45:53 +0100
committerMiquel Sabaté Solà <msabate@suse.com>2023-12-03 07:45:53 +0100
commitdd7a4efc643c20c56b845aa11af1fec4b0760d92 (patch)
treeb3e213c7ba4dbff04691f41bd80975bfd1eb600e /include
downloadaoc2023.nes-dd7a4efc643c20c56b845aa11af1fec4b0760d92.tar.gz
aoc2023.nes-dd7a4efc643c20c56b845aa11af1fec4b0760d92.zip
First day of advent of code
Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
Diffstat (limited to 'include')
-rw-r--r--include/apu.s6
-rw-r--r--include/globals.s39
-rw-r--r--include/oam.s13
-rw-r--r--include/ppu.s27
-rw-r--r--include/reset.s63
5 files changed, 148 insertions, 0 deletions
diff --git a/include/apu.s b/include/apu.s
new file mode 100644
index 0000000..32ccff2
--- /dev/null
+++ b/include/apu.s
@@ -0,0 +1,6 @@
+.segment "CODE"
+
+.scope APU
+ DMC = $4010
+ FRAME_COUNTER = $4017
+.endscope
diff --git a/include/globals.s b/include/globals.s
new file mode 100644
index 0000000..41d3e6c
--- /dev/null
+++ b/include/globals.s
@@ -0,0 +1,39 @@
+.scope Globals
+ ;;;
+ ;; Temporary values.
+
+ m_tmp_1 = $00
+ m_tmp_2 = $01
+ m_tmp_3 = $02
+ m_tmp_4 = $03
+ m_tmp_5 = $04
+
+ ;; Bit map to be used as flags during execution.
+ m_flags = $20
+
+ ;; Initialize global variables.
+ .proc init
+ lda #0
+ sta m_tmp_1
+ sta m_tmp_2
+ sta m_tmp_3
+ sta m_tmp_4
+ sta m_tmp_5
+ sta m_flags
+ rts
+ .endproc
+.endscope
+
+;; SET_RENDER_FLAG sets the render bit on Globals::m_flags to 1.
+.macro SET_RENDER_FLAG
+ lda #%10000000
+ ora Globals::m_flags
+ sta Globals::m_flags
+.endmacro
+
+;; UNSET_RENDER_FLAG sets the render bit on Globals::m_flags to 0.
+.macro UNSET_RENDER_FLAG
+ lda #%01111111
+ and Globals::m_flags
+ sta Globals::m_flags
+.endmacro
diff --git a/include/oam.s b/include/oam.s
new file mode 100644
index 0000000..ecd1b7d
--- /dev/null
+++ b/include/oam.s
@@ -0,0 +1,13 @@
+.segment "CODE"
+
+.scope OAM
+ ADDR = $2003
+ DMA = $4014
+.endscope
+
+.macro OAM_WRITE_SPRITES
+ lda #$00
+ sta OAM::ADDR
+ lda #$02
+ sta OAM::DMA
+.endmacro
diff --git a/include/ppu.s b/include/ppu.s
new file mode 100644
index 0000000..23fd978
--- /dev/null
+++ b/include/ppu.s
@@ -0,0 +1,27 @@
+.segment "CODE"
+
+.scope PPU
+ CONTROL = $2000
+ MASK = $2001
+ STATUS = $2002
+ SCROLL = $2005
+ ADDRESS = $2006
+ DATA = $2007
+.endscope
+
+.macro PPU_ADDR address
+ lda #.HIBYTE(address)
+ sta PPU::ADDRESS
+ lda #.LOBYTE(address)
+ sta PPU::ADDRESS
+.endmacro
+
+;; WRITE_PPU_DATA is a macro that will write into PPU::ADDRESS the given address
+;; and into PPU::DATA the given byte value.
+.macro WRITE_PPU_DATA address, value
+ bit PPU::STATUS
+
+ PPU_ADDR address
+ lda #value
+ sta PPU::DATA
+.endmacro
diff --git a/include/reset.s b/include/reset.s
new file mode 100644
index 0000000..e68d3db
--- /dev/null
+++ b/include/reset.s
@@ -0,0 +1,63 @@
+;; Common `reset` procedure for NROM "games". Check `basics/sprite.s` on
+;; @mssola/NES for a proper explanation on the code (will be open soon,
+;; promise!).
+reset:
+ sei
+ cld
+
+ ldx #$40
+ stx $4017
+
+ ldx #$ff
+ txs
+
+ inx
+ stx $2000
+ stx $2001
+ stx $4010
+
+@vblankwait1:
+ bit $2002
+ bpl @vblankwait1
+
+ ldx #0
+ lda #0
+@ram_reset_loop:
+ sta $000, x
+ sta $100, x
+ sta $300, x
+ sta $400, x
+ sta $500, x
+ sta $600, x
+ sta $700, x
+ inx
+ bne @ram_reset_loop
+
+ lda #$ef
+@sprite_reset_loop:
+ sta $200, x
+ inx
+ bne @sprite_reset_loop
+
+ lda #$00
+ sta $2003
+ lda #$02
+ sta $4014
+
+@vblankwait2:
+ bit $2002
+ bpl @vblankwait2
+
+ lda #$3F
+ sta $2006
+ lda #$00
+ sta $2006
+
+ lda #$0F
+ ldx #$20
+@palettes_reset_loop:
+ sta $2007
+ dex
+ bne @palettes_reset_loop
+
+ jmp main