From bab57f6e438a06d00172059d2f27281c2b8617c7 Mon Sep 17 00:00:00 2001 From: Lucas Scharenbroich Date: Fri, 12 Nov 2021 11:27:43 -0600 Subject: [PATCH] Add VSYNC toggle --- demos/sprites/App.Main.s | 38 +++++++++++++++++++++++++++++++++++++- src/Core.s | 17 +++++++++++++++-- src/Defs.s | 5 +++++ src/GTE.s | 2 ++ src/Graphics.s | 3 +++ 5 files changed, 62 insertions(+), 3 deletions(-) diff --git a/demos/sprites/App.Main.s b/demos/sprites/App.Main.s index ba8d8ef..de18de2 100644 --- a/demos/sprites/App.Main.s +++ b/demos/sprites/App.Main.s @@ -94,6 +94,22 @@ EvtLoop lda #$FFF8 sta PlayerYVel :no_jump + + +; Enable/disable v-sync + lda 1,s + bit #$0400 + beq :no_key_down + and #$007F + cmp #'v' + bne :not_v + lda #$0001 + eor vsync + sta vsync +:not_v +:no_key_down + + pla and #$007F ; Ignore the buttons for now @@ -165,6 +181,7 @@ EvtLoop bra :do_render :not_l + ; Update the camera position :do_render @@ -178,8 +195,25 @@ EvtLoop jsl UpdateSprite ; Move the sprite to this local position ; Let's see what it looks like! - + lda vsync + beq :no_vsync +:vsyncloop jsl GetVerticalCounter ; 8-bit value + cmp ScreenY0 + bcc :vsyncloop + sec + sbc ScreenY0 + cmp #8 + bcs :vsyncloop + lda #1 + jsl SetBorderColor +:no_vsync jsl Render + + lda vsync + beq :no_vsync2 + lda #0 + jsl SetBorderColor +:no_vsync2 ; Update the performance counters @@ -435,6 +469,8 @@ MovePlayerToOrigin qtRec adrl $0000 da $00 +vsync dw $0000 + PUT ../shell/Overlay.s PUT gen/App.TileMapBG0.s PUT gen/App.TileSetAnim.s diff --git a/src/Core.s b/src/Core.s index cde25af..7a26c4d 100644 --- a/src/Core.s +++ b/src/Core.s @@ -343,6 +343,7 @@ ClearKbdStrobe sep #$20 rts ; Read the keyboard and paddle controls and return in a game-controller-like format +LastKey db 0 ReadControl ENT pea $0000 ; low byte = key code, high byte = %------AB @@ -351,7 +352,7 @@ ReadControl ENT and #$80 beq :BNotDown - lda #1 + lda #PAD_BUTTON_B ora 2,s sta 2,s @@ -360,7 +361,7 @@ ReadControl ENT and #$80 beq :ANotDown - lda #2 + lda #PAD_BUTTON_A ora 2,s sta 2,s @@ -372,7 +373,19 @@ ReadControl ENT ora 1,s sta 1,s + cmpl LastKey + beq :KbdDown + stal LastKey + + lda #PAD_KEY_DOWN ; set the keydown flag + ora 2,s + sta 2,s + bra :KbdDown + :KbdNotDwn + lda #0 + stal LastKey +:KbdDown rep #$20 pla rtl diff --git a/src/Defs.s b/src/Defs.s index c393e99..2052382 100644 --- a/src/Defs.s +++ b/src/Defs.s @@ -119,6 +119,11 @@ SWAP_PALETTE_ENTRY equ $0004 SET_DYN_TILE equ $0006 CALLBACK equ $0010 +; ReadControl return value bits +PAD_BUTTON_B equ $01 +PAD_BUTTON_A equ $02 +PAD_KEY_DOWN equ $04 + ; Tile constants TILE_ID_MASK equ $01FF TILE_SPRITE_BIT equ $8000 ; Set if this tile intersects an active sprite diff --git a/src/GTE.s b/src/GTE.s index ba7d000..def5f30 100644 --- a/src/GTE.s +++ b/src/GTE.s @@ -10,6 +10,8 @@ ReadControl EXT ; Low-Level Functions SetPalette EXT GetVBLTicks EXT +GetVerticalCounter EXT +SetBorderColor EXT ; Tilemap functions SetBG0XPos EXT diff --git a/src/Graphics.s b/src/Graphics.s index 1e35274..fae2ddc 100644 --- a/src/Graphics.s +++ b/src/Graphics.s @@ -126,6 +126,9 @@ _ShadowOff rep #$20 rts +GetVerticalCounter ENT + jsr _GetVBL + rtl _GetVBL sep #$20 ldal VBL_HORZ_REG