diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-03-13 22:52:49 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-03-13 22:52:49 +0100 |
| commit | 9ff2033e936689135210989a5fee057a4a13527e (patch) | |
| tree | dd41ffd78f451d28a554f105ff40017ed31106a2 /src/title.s | |
| parent | 2627b459d9a19ce7f1b7f3a359dca3b30b66b34e (diff) | |
| download | jetpac.nes-9ff2033e936689135210989a5fee057a4a13527e.tar.gz jetpac.nes-9ff2033e936689135210989a5fee057a4a13527e.zip | |
Add a title and a main screens
This commit adds the skeleton for having a title and a main screen. For
now the title menu doesn't do much, as the selection is simply ignored,
but at least it already knows how to cycle between these two states.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'src/title.s')
| -rw-r--r-- | src/title.s | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/title.s b/src/title.s new file mode 100644 index 0000000..db627ae --- /dev/null +++ b/src/title.s @@ -0,0 +1,100 @@ +.segment "CODE" + +;; All the functions and variables which are related to the title screen. +.scope Title + ;; Y and X coordinates for the sprite that guides the player on the menu. + SPRITE_Y_POSITION0 = $A7 + SPRITE_Y_POSITION1 = $BF + SPRITE_X_POSITION = $40 + + ;; The title has a timer as a delay between joypad presses from the player. + TIMER_INIT_VALUE = 20 + zp_title_timer = $30 + + ;; Initialize all the elements for the title screen. + .proc init + lda #0 + sta zp_title_timer + + ;; Initialize the sprite that guides the player on the menu. + lda #SPRITE_Y_POSITION0 + sta $200 + lda #$30 + sta $201 + lda #$00 + sta $202 + lda #SPRITE_X_POSITION + sta $203 + + rts + .endproc + + ;; Checks the pressed buttons from the joypad and moves the sprite for the + ;; menu accordingly. + ;; + ;; Returns 1 if the player hit start and the game can start, 0 otherwise. + .proc update + lda zp_title_timer + bne @end + + lda #Joypad::BUTTON_UP + and Joypad::zp_buttons1 + beq @check_down + + lda #SPRITE_Y_POSITION0 + cmp $200 + beq @end + sta $200 + jmp @set_timer_and_end + + @check_down: + lda #Joypad::BUTTON_DOWN + and Joypad::zp_buttons1 + beq @check_select + + lda #SPRITE_Y_POSITION1 + cmp $200 + beq @end + sta $200 + jmp @set_timer_and_end + + @check_select: + lda #Joypad::BUTTON_SELECT + and Joypad::zp_buttons1 + beq @check_start + + lda #SPRITE_Y_POSITION0 + cmp $200 + beq @down + sta $200 + jmp @set_timer_and_end + + @check_start: + lda #Joypad::BUTTON_START + and Joypad::zp_buttons1 + beq @end + JAL start + + @down: + lda #SPRITE_Y_POSITION1 + sta $200 + + @set_timer_and_end: + lda #TIMER_INIT_VALUE + sta zp_title_timer + @end: + lda #0 + rts + .endproc + + ;; Save the selection from the menu (TODO), hide all elements from the title + ;; screen, and return always 1. + .proc start + ;; Hide the sprite from the menu. + lda #$EF + sta $200 + + lda #1 + rts + .endproc +.endscope |
