From 2627b459d9a19ce7f1b7f3a359dca3b30b66b34e Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 12 Mar 2025 22:38:12 +0100 Subject: Start with a skeleton for the project MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- src/jetpac.s | 86 +++++++++++++++++++++++++++++++++++++++++++++ src/vectors.s | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100644 src/jetpac.s create mode 100644 src/vectors.s (limited to 'src') diff --git a/src/jetpac.s b/src/jetpac.s new file mode 100644 index 0000000..2f273a3 --- /dev/null +++ b/src/jetpac.s @@ -0,0 +1,86 @@ +.segment "HEADER" + .byte 'N', 'E', 'S', $1A + .byte $02, $01 + .res $0A, $00 + +.segment "CODE" + +.include "../include/apu.s" +.include "../include/oam.s" +.include "../include/ppu.s" +.include "../include/globals.s" +.include "vectors.s" + +.proc main + jsr init_palettes + jsr init_nametables + +;;; TODO + cli + lda #%10110000 + sta $2000 + lda #%00011110 + sta $2001 + +@main_game_loop: + ;;; + ;; TODO + ;;; + + lda #%10000000 + ora Globals::zp_flags + sta Globals::zp_flags +@wait_for_render: + bit Globals::zp_flags + bmi @wait_for_render + + ;; Rendering is done, we can perform another iteration of the loop! + jmp @main_game_loop +.endproc + +;; Copies all the palettes for our game into the proper PPU address. +.proc init_palettes + lda #$3F + sta PPU::ADDRESS + lda #$00 + sta PPU::ADDRESS + + ldx #0 +@load_palettes_loop: + lda palettes, x + sta PPU::DATA + inx + cpx #$20 + bne @load_palettes_loop + rts +palettes: + ;; Background + ;; 0: score + .byte $0F, $30, $2C, $28 + ;; 1: floating platforms + .byte $0F, $2C, $30, $2A + ;; 2: ground + .byte $0F, $28, $14, $28 + ;; 3: ship + .byte $0F, $16, $30, $00 + + ;; TODO: fuel tank needs color $24 + ;; Foreground + ;; 0: player & ship + .byte $0F, $16, $10, $30 + ;; 1: enemy 1 & bonuses + .byte $0F, $16, $2C, $2A + ;; 2: enemy 2, fuel & bonuses + .byte $0F, $16, $14, $28 + ;; 3: SUSE easter egg + .byte $0F, $16, $00, $2B +.endproc + +.proc init_nametables + ;; TODO + rts +.endproc + + +.segment "CHARS" + .incbin "../assets/jetpac.chr" diff --git a/src/vectors.s b/src/vectors.s new file mode 100644 index 0000000..2edc6a6 --- /dev/null +++ b/src/vectors.s @@ -0,0 +1,109 @@ +.segment "VECTORS" + .addr nmi, reset, irq + +.segment "CODE" + +;; Pretty standard reset function, nothing crazy. +.proc reset + sei + cld + + ldx #$40 + stx APU::FRAME_COUNTER + + ldx #$FF + txs + + inx + stx PPU::CONTROL + stx PPU::MASK + stx APU::DMC + +@vblankwait1: + bit PPU::STATUS + 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 OAM::ADDRESS + lda #$02 + sta OAM::DMA + +@vblankwait2: + bit PPU::STATUS + bpl @vblankwait2 + + lda #$3F + sta PPU::ADDRESS + lda #$00 + sta PPU::ADDRESS + + lda #$0F + ldx #$20 +@palettes_reset_loop: + sta PPU::DATA + dex + bne @palettes_reset_loop + + jmp main +.endproc + +.proc nmi + ;; Should we skip it? + bit Globals::zp_flags + bpl @end + + ;; Save registers. + pha + txa + pha + tya + pha + + lda #$00 + sta OAM::ADDRESS + lda #$02 + sta OAM::DMA + + bit PPU::STATUS + lda #$00 + sta PPU::SCROLL + sta PPU::SCROLL + + lda #%01111111 + and Globals::zp_flags + sta Globals::zp_flags + + ;; Restore registers. + pla + tay + pla + tax + pla + +@end: + rti +.endproc + +;; Unused. +.proc irq + rti +.endproc -- cgit v1.2.3