diff --git a/demos/tool/App.Main.s b/demos/tool/App.Main.s index 6809c62..40a3311 100644 --- a/demos/tool/App.Main.s +++ b/demos/tool/App.Main.s @@ -7,10 +7,7 @@ use Misc.Macs use Util.Macs use EDS.GSOS.Macs - -_GTEStartUp MAC - UserTool $02A0 - <<< + use GTE.Macs mx %00 @@ -18,31 +15,27 @@ _GTEStartUp MAC phk plb - sta UserId ; GS/OS passed the memory manager user ID for the aoplication into the program + sta UserId ; GS/OS passes the memory manager user ID for the aoplication into the program + _MTStartUp ; GTE requires the miscellaneous toolset to be running - jsr ToolStartUp ; Start up the basic tools: Locator, Memory Manager, Misc - jsr GTEStartUp + jsr GTEStartUp ; Load and install the GTE User Tool +; Very simple actions +:loop + pha ; space for result, with pattern + _GTEReadControl + pla + and #$00FF + cmp #'q' + bne :loop + +; Shut down eveything + _GTEShutDown _QuitGS qtRec - - bcs Fatal -Fatal brk $00 qtRec adrl $0000 da $00 -ToolStartUp -; _TLStartUp ; normal tool initialization -; pha -; _MMStartUp -; pla -; sta MasterId ; our master handle references the memory allocated to us -; ora #$0100 ; set auxID = $01 (valid values $01-0f) -; sta UserId ; any memory we request must use our own id - - _MTStartUp ; just start up the miscellaneous tools - rts - -; Load the GTE User Tool and register it +; Load the GTE User Tool and install it GTEStartUp pea $0000 _LoaderStatus @@ -60,12 +53,10 @@ GTEStartUp pea #^ToolPath pea #ToolPath pea $0001 ; do not load into special memory -; pea $0001 ; GS/OS string for the argument _InitialLoad bcc :ok1 brk $01 - :ok1 ply pla ; Address of the loaded tool @@ -86,7 +77,8 @@ GTEStartUp tdc adc #$0100 pha - lda UserId + pea $0000 ; No extra capabilities + lda UserId ; Pass the userId for memory allocation pha _GTEStartUp bcc :ok3 diff --git a/demos/tool/package.json b/demos/tool/package.json index 18de1c0..0c8f1e9 100644 --- a/demos/tool/package.json +++ b/demos/tool/package.json @@ -12,7 +12,7 @@ }, "scripts": { "test": "npm run build && build-image.bat %npm_package_config_cadius% && %npm_package_config_gsport%", - "debug": "%npm_package_config_crossrunner% GTEToolTest -Source GTEToolTest_S02_MAINSEG_Output.txt -Debug -CompatibilityLayer", + "debug": "%npm_package_config_crossrunner% GTEToolDemo -Source MAINSEG_Output.txt -Debug -CompatibilityLayer", "build": "%npm_package_config_merlin32% -V %npm_package_config_macros% App.s" }, "repository": { diff --git a/macros/GTE.Macs.s b/macros/GTE.Macs.s new file mode 100644 index 0000000..67f4a3d --- /dev/null +++ b/macros/GTE.Macs.s @@ -0,0 +1,26 @@ +* Generic Tile Engine Macros +* by Lucas Scharenbroich + +GTEToolNum equ $A0 + +_GTEBootInit MAC + UserTool $100+GTEToolNum + <<< +_GTEStartUp MAC + UserTool $200+GTEToolNum + <<< +_GTEShutDown MAC + UserTool $300+GTEToolNum + <<< +_GTEVersion MAC + UserTool $400+GTEToolNum + <<< +_GTEReset MAC + UserTool $500+GTEToolNum + <<< +_GTEStatus MAC + UserTool $600+GTEToolNum + <<< +_GTEReadControl MAC + UserTool $900+GTEToolNum + <<< \ No newline at end of file diff --git a/src/CoreImpl.s b/src/CoreImpl.s index e901ef0..7fae846 100644 --- a/src/CoreImpl.s +++ b/src/CoreImpl.s @@ -85,8 +85,7 @@ Overlay EXT mx %00 -; A = memory manager userId -; X = tool number +; Assumes the direct page is set and EngineMode and UserId has been initialized _CoreStartUp jsr IntStartUp ; Enable certain interrupts @@ -194,7 +193,7 @@ EngineReset stz OldStartY stz StartYMod208 - stz EngineMode +; stz EngineMode stz DirtyBits stz LastRender stz LastPatchOffset diff --git a/src/Defs.s b/src/Defs.s index 2f5e12c..f59e71f 100644 --- a/src/Defs.s +++ b/src/Defs.s @@ -34,6 +34,8 @@ StartX equ 16 ; Which code buffer byte is the left ed StartY equ 18 ; Which code buffer line is the top of the screen. Range = 0 to 207 EngineMode equ 20 ; Defined the mode/capabilities that are enabled ; bit 0: 0 = Single Background, 1 = Parallax + ; bit 1: 0 = No Dynamic Tiles, 1 = Allocate Bank 00 space for dynamic tiles + ; bit 2: 0 = No static buffer, 1 = Allocation Bank 00 space for a static screen buffer DirtyBits equ 22 ; Identify values that have changed between frames BG1DataBank equ 24 ; Data bank that holds BG1 layer data @@ -143,7 +145,12 @@ FREE_SPACE_DP2 equ 160 ; End direct page values +; EngineMode definitions +ENGINE_MODE_TWO_LAYER equ $0001 +ENGINE_MODE_DYN_TILES equ $0002 +ENGINE_MODE_BNK0_BUFF equ $0004 +; DirtyBits definitions DIRTY_BIT_BG0_X equ $0001 DIRTY_BIT_BG0_Y equ $0002 DIRTY_BIT_BG1_X equ $0004 diff --git a/src/Memory.s b/src/Memory.s index 59b75bc..b74790a 100644 --- a/src/Memory.s +++ b/src/Memory.s @@ -16,7 +16,11 @@ mx %00 -InitMemory PushLong #0 ; space for result +InitMemory lda EngineMode + bit #ENGINE_MODE_BNK0_BUFF + beq :no_bnk0_buff + + PushLong #0 ; space for result PushLong #$008000 ; size (32k) PushWord UserId PushWord #%11000000_00010111 ; Fixed location @@ -27,6 +31,7 @@ InitMemory PushLong #0 ; space for result _Deref stx Buff00 sta Buff00+2 +:no_bnk0_buff PushLong #0 ; space for result PushLong #$008000 ; size (32k) @@ -41,7 +46,15 @@ InitMemory PushLong #0 ; space for result sta Buff01+2 PushLong #0 ; space for result - PushLong #$000A00 ; size (10 pages) + + pea #0000 ; size (2 or 10 pages) + lda EngineMode + bit #ENGINE_MODE_DYN_TILES + beq :no_dyn_tiles + pea #$0A00 ; 10 pages if dynamic tiles are enabled + bra :dyn_done +:no_dyn_tiles pea #$0200 ; 2 pages if dynamic tiles are disabled +:dyn_done PushWord UserId PushWord #%11000000_00010101 ; Page-aligned, fixed bank PushLong #$000000 @@ -52,11 +65,15 @@ InitMemory PushLong #0 ; space for result stx BlitterDP ; Allocate banks of memory for BG1 + lda EngineMode + bit #ENGINE_MODE_TWO_LAYER + beq :no_bg1 jsr AllocOneBank2 sta BG1DataBank jsr AllocOneBank2 sta BG1AltBank +:no_bg1 ; Allocate the 13 banks of memory we need and store in double-length array ]step equ 0 diff --git a/src/Tool.s b/src/Tool.s index 4743867..da77a71 100644 --- a/src/Tool.s +++ b/src/Tool.s @@ -14,6 +14,25 @@ ToStrip equ $E10184 +; Define some macros to help streamline the entry and exit from the toolbox calls +_TSEntry mac + phd + phb + tcd + phk ; Default to setting the data back to the current bank. + plb + <<< + +_TSExit mac + plb + pld + ldx ]1 ; Error code + ldy ]2 ; Number of stack bytes to remove + jml ToStrip + <<< + +FirstParam equ 10 ; When using the _TSEntry macro, the first parameter is at 10,s + mx %00 _CallTable @@ -27,7 +46,8 @@ _CallTable adrl _TSReserved-1 adrl _TSReserved-1 - adrl _TSSetScreenMode + adrl _TSReadControl-1 + adrl _TSSetScreenMode-1 _CTEnd ; Do nothing when the tool set is installed @@ -39,13 +59,14 @@ _TSBootInit ; Call the regular GTE startup function after setting the Work Area Pointer (WAP). The caller must provide ; one page of Bank 0 memory for the tool set's private use and a userId to use for allocating memory ; -; X = tool set number in low byte and function umber in high byte +; X = tool set number in low byte and function number in high byte ; -; StartUp(dPageAddr, userId) +; StartUp(dPageAddr, capFlags, userId) _TSStartUp userId = 7 -zpToUse = userId+2 +capFlags = userId+2 +zpToUse = userId+4 lda zpToUse,s ; Get the direct page address phd ; Save the current direct page @@ -58,6 +79,9 @@ zpToUse = userId+2 lda userId+2,s ; Get the userId for memory allocations sta UserId + lda capFlags+2,s ; Get the engine capability bits + sta EngineMode + jsr _CoreStartUp ; Initialize the library ; SetWAP(userOrSystem, tsNum, waptPtr) @@ -71,9 +95,10 @@ zpToUse = userId+2 pld ; Restore the caller's direct page ldx #0 ; No error - ldy #4 ; Remove the 4 input bytes + ldy #6 ; Remove the 6 input bytes jml ToStrip +; ShutDown() _TSShutDown cmp #0 ; Acc is low word of the WAP (direct page) beq :inactive @@ -114,7 +139,7 @@ _TSStatus sta 1,s tya ora 1,s - sta 1,s ; 0 if WAP is null, non-zero if WAP is set + sta 1,s ; 0 if WAP is null, non-zero if WAP is set lda #0 clc @@ -129,37 +154,28 @@ _TSReserved ; SetScreenMode(width, height) _TSSetScreenMode -:height equ 9 -:width equ 11 +height equ FirstParam +width equ FirstParam+2 - phd ; Preserve the direct page - tcd ; Set the tool set direct pafe from WAP + _TSEntry - lda :height,s + lda height,s tay - lda :width,s + lda width,s tax ; jsr _SetScreenMode ; Not implemented yet - pld ; Restore direct page - - ldx #0 ; No error - ldy #4 ; Remove the 4 input bytes - jml ToStrip + _TSExit #0;#4 _TSReadControl -:output equ 9 +output equ FirstParam - phd ; Preserve the direct page - tcd + _TSEntry jsr _ReadControl - sta :output,s + sta output,s - pld - ldx #0 ; No error - ldy #0 ; Remove zero input bytes - jml ToStrip + _TSExit #0;#0 ; Insert the core GTE functions