aboutsummaryrefslogtreecommitdiff
path: root/src/jetpac.s
blob: 8acbb4eca6c7079928b4780443c3bedb0b9fcb06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
.segment "HEADER"
    .byte 'N', 'E', 'S', $1A
    .byte $02, $01
    .res $0A, $00

.segment "CODE"

;; NOTE: automatically generated by the build system.
.include "../config/generated.s"

.include "../include/apu.s"
.include "../include/oam.s"
.include "../include/ppu.s"
.include "../include/asm.s"
.include "../include/joypad.s"
.include "../include/globals.s"

.include "assets.s"
.include "driver.s"
.include "title.s"
.include "vectors.s"

.proc main
    ;; Disable the PPU.
    lda #0
    sta PPU::MASK

    ;; Initialize the assets for the game.
    jsr Assets::init

    ;; We shadow the PPU control register in memory. Depending on the `make`
    ;; target we might need to switch directly to the main game. Otherwise we go
    ;; into the title as expected.
    .ifdef PARTIAL
        jsr Driver::switch

        lda PPU::zp_control
        sta PPU::CONTROL
    .else
        jsr Title::init

        lda #%10001000
        sta PPU::zp_control
        sta PPU::CONTROL
    .endif

    cli

    ;; Enable back the PPU
    lda #%00011110
    sta PPU::MASK

@main_game_loop:
    READ_JOYPAD1

    lda Globals::zp_flags
    and #%00000011
    beq @title_screen
    cmp #1
    beq @game_screen
    jmp @over

@title_screen:
    jsr Title::update
    beq @set_flags

    ;; Start was pressed by the player, switch to the main game.
    jsr Driver::switch
    jmp @set_flags

@game_screen:
    jsr Driver::update
    ;; NOTE: fallthrough

@set_flags:
    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

@over:
    ;; TODO: allow to start over, reset flags, control register, etc.
    jmp @over
.endproc