From 4ee67fb8be6fec1a4480c78ac8fb23b7ba257183 Mon Sep 17 00:00:00 2001 From: Lucas Scharenbroich Date: Tue, 9 May 2023 10:16:58 -0500 Subject: [PATCH] Add hook for VBL callback --- macros/GTE.Macs.s | 4 +++- src/CoreImpl.s | 8 +++++++- src/Defs.s | 1 + src/Master.s | 14 +++++++------- src/Tiles.s | 2 +- src/Tool.s | 26 +++++++++++++++++++++++--- src/render/Render.s | 2 +- 7 files changed, 43 insertions(+), 14 deletions(-) diff --git a/macros/GTE.Macs.s b/macros/GTE.Macs.s index 5e5cb27..5b8610f 100644 --- a/macros/GTE.Macs.s +++ b/macros/GTE.Macs.s @@ -175,9 +175,11 @@ OVERLAY_SOLID equ $8000 ; Overlay covers the scan line and is fu OVERLAY_ABOVE equ $0000 ; Overlay is drawn above scanline sprites OVERLAY_BELOW equ $4000 ; Overlay is drawn below scanline sprites -; GetAddress table IDs +; GetAddress IDs scanlineHorzOffset equ $0001 scanlineHorzOffset2 equ $0002 +tileStore equ $0003 +vblCallback equ $0004 ; CopyPicToBG1 flags COPY_PIC_NORMAL equ $0000 ; Copy into BG1 buffer in "normal mode" diff --git a/src/CoreImpl.s b/src/CoreImpl.s index 18a2ac9..1ee92bb 100644 --- a/src/CoreImpl.s +++ b/src/CoreImpl.s @@ -166,8 +166,14 @@ OneSecHandler mx %11 ; This is OK, it's referenced by a long address VBLTASK hex 00000000 - dw 0 +TaskCnt dw 1 hex 5AA5 +VblTaskCode mx %11 + lda #1 + stal TaskCnt ; Reset the task count +_VblTaskPatch jml _TaskStub ; Just something to catch the interrupt +_TaskStub rtl + mx %00 ; Reset the engine to a known state ; Blitter initialization diff --git a/src/Defs.s b/src/Defs.s index 4747c96..21a364f 100644 --- a/src/Defs.s +++ b/src/Defs.s @@ -192,6 +192,7 @@ DIRTY_BIT_SPRITE_ARRAY equ $0040 scanlineHorzOffset equ $0001 ; Table of 416 words, a double-array of scanline offset values. Values must be in range [0, 163] scanlineHorzOffset2 equ $0002 ; Table of 416 words, a double-array of scanline offset values. Values must be in range [0, 163] tileStore equ $0003 +vblCallback equ $0004 ; User routine to be called by VBL interrupt. Set to $000000 to disconnect ; CopyPicToBG1 flags COPY_PIC_NORMAL equ $0000 ; Copy into BG1 buffer in "normal mode" treating the buffer as a 164x208 pixmap with stride of 256 diff --git a/src/Master.s b/src/Master.s index 95e0fea..2ff9943 100644 --- a/src/Master.s +++ b/src/Master.s @@ -2,7 +2,7 @@ TYP $BA ; Tool set file DSK Tool160 - XPL + XPL ; Main toolbox interface and code @@ -12,41 +12,41 @@ ; 64KB Tile Memory ASM static/TileData.s - KND #$1001 ; Type and Attributes ($10=Static,$01=Data) + KND #$1101 ; Type and Attributes ($10=Static,$01=Data) ALI BANK SNA TDATA ; 64KB Sprite Plane Data ASM static/SprData.s - KND #$1001 ; Type and Attributes ($11=Static+Bank Relative,$01=Data) + KND #$1101 ; Type and Attributes ($11=Static+Bank Relative,$01=Data) ALI BANK SNA SDATA ; 64KB Sprite Mask Data ASM static/SprMask.s - KND #$1001 ; Type and Attributes ($11=Static+Bank Relative,$01=Data) + KND #$1101 ; Type and Attributes ($11=Static+Bank Relative,$01=Data) ALI BANK SNA SMASK ; 64KB Tile Store ASM static/TileStore.s - KND #$1001 ; Type and Attributes ($11=Static+Bank Relative,$01=Data) + KND #$1101 ; Type and Attributes ($11=Static+Bank Relative,$01=Data) ALI BANK SNA TSTORE ; 64KB Rotation Data Tables ASM RotData.s - KND #$1001 ; Type and Attributes ($11=Static+Bank Relative,$01=Data) + KND #$1101 ; Type and Attributes ($11=Static+Bank Relative,$01=Data) ALI BANK SNA ROTDATA ; Additional code ; ASM FastCopies.s -; KND #$1001 ; Type and Attributes ($11=Static+Bank Relative,$01=Data) +; KND #$1101 ; Type and Attributes ($11=Static+Bank Relative,$01=Data) ; ALI BANK ; SNA FASTCPY diff --git a/src/Tiles.s b/src/Tiles.s index 040465d..11c44f8 100644 --- a/src/Tiles.s +++ b/src/Tiles.s @@ -6,7 +6,7 @@ ; X = first tile ; Y = last tile ; -; To copy in three tiles starting at tile 5, for example, X = 5 and Y = 9 +; To copy in four tiles starting at tile 5, for example, X = 5 and Y = 9 _LoadTileSet txa _Mul128 ; Jump to the target location diff --git a/src/Tool.s b/src/Tool.s index 8559852..af13baf 100644 --- a/src/Tool.s +++ b/src/Tool.s @@ -887,7 +887,7 @@ _TSSetBG1Scale sta BG1Scaling _TSExit #0;#2 -; Pointer GetAddress(tblId) +; Pointer GetAddress(addrId) _TSGetAddress :tblId equ FirstParam+0 :output equ FirstParam+2 @@ -919,7 +919,7 @@ _TSGetAddress :out _TSExit #0;#2 -; SetAddress(tblId, Pointer) +; SetAddress(addrId, Pointer) _TSSetAddress :ptr equ FirstParam+0 :tblId equ FirstParam+4 @@ -944,7 +944,27 @@ _TSSetAddress lda :ptr+2,s sta BG1StartXMod164Tbl+2 bra :out -:next_2 + +:next_2 cmp #vblCallback + bne :next_3 + + lda :ptr,s + ora :ptr+2,s + beq :vbl_restore + + lda :ptr,s + stal _VblTaskPatch+1 ; long addressing because we're patching code in the K bank + lda :ptr+1,s + stal _VblTaskPatch+2 + bra :out + +:vbl_restore + lda #_TaskStub + stal _VblTaskPatch+1 + lda #>_TaskStub + stal _VblTaskPatch+2 + bra :out +:next_3 :out _TSExit #0;#6 diff --git a/src/render/Render.s b/src/render/Render.s index 8bd8606..f5a3fb7 100644 --- a/src/render/Render.s +++ b/src/render/Render.s @@ -4,7 +4,7 @@ _RenderTile lda TileStore+TS_SPRITE_FLAG,x ; any sprites on this tile? bne _HasSprites -; Probably best to rework this to just jump to the tile routine directly, event if there +; Probably best to rework this to just jump to the tile routine directly, even if there ; is some boilerplate code because it is useful to be able to access the data bank before ; switching to the code field bank.