iigs-game-engine/src/Tool.s

366 lines
9.8 KiB
ArmAsm
Raw Normal View History

2022-02-02 16:21:31 +00:00
; Toolbox wrapper for the GTE library. Implemented as a user tool
;
; Ref: Toolbox Reference, Volume 2, Appendix A
; Ref: IIgs Tech Note #73
use Mem.Macs.s
use Misc.Macs.s
use Util.Macs
use Locator.Macs
use Core.MACS.s
use Defs.s
use static/TileStoreDefs.s
2022-02-02 16:21:31 +00:00
ToStrip equ $E10184
2022-04-24 19:45:07 +00:00
; Define some macros to help streamline the entry and exit from the toolbox calls
_TSEntry mac
phd
phb
tcd
jsr _SetDataBank
2022-04-24 19:45:07 +00:00
<<<
_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
2022-02-02 16:21:31 +00:00
_CallTable
adrl {_CTEnd-_CallTable}/4
2022-02-02 16:21:31 +00:00
adrl _TSBootInit-1
adrl _TSStartUp-1
adrl _TSShutDown-1
adrl _TSVersion-1
adrl _TSReset-1
adrl _TSStatus-1
adrl _TSReserved-1
adrl _TSReserved-1
adrl _TSReadControl-1
adrl _TSSetScreenMode-1
adrl _TSSetTile-1
adrl _TSSetBG0Origin-1
adrl _TSRender-1
adrl _TSLoadTileSet-1
adrl _TSCreateSpriteStamp-1
adrl _TSAddSprite-1
adrl _TSMoveSprite-1
adrl _TSUpdateSprite-1
adrl _TSRemoveSprite-1
2022-02-02 16:21:31 +00:00
_CTEnd
_GTEAddSprite MAC
UserTool $1000+GTEToolNum
<<<
_GTEMoveSprite MAC
UserTool $1100+GTEToolNum
<<<
_GTEUpdateSprite MAC
UserTool $1200+GTEToolNum
<<<
_GTERemoveSprite MAC
UserTool $1300+GTEToolNum
<<<
; Helper function to set the data back to the toolset default
_SetDataBank sep #$20
lda #^TileStore
pha
plb
rep #$20
rts
2022-02-02 16:21:31 +00:00
; Do nothing when the tool set is installed
_TSBootInit
lda #0
clc
rtl
; 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
;
2022-04-24 19:45:07 +00:00
; X = tool set number in low byte and function number in high byte
2022-02-02 16:21:31 +00:00
;
2022-04-24 19:45:07 +00:00
; StartUp(dPageAddr, capFlags, userId)
2022-02-02 16:21:31 +00:00
_TSStartUp
userId = 7
2022-04-24 19:45:07 +00:00
capFlags = userId+2
zpToUse = userId+4
lda zpToUse,s ; Get the direct page address
phd ; Save the current direct page
tcd ; Set to our working direct page space
2022-02-02 16:21:31 +00:00
txa
and #$00FF ; Get just the tool number
sta ToolNum
lda userId+2,s ; Get the userId for memory allocations
sta UserId
2022-04-24 19:45:07 +00:00
lda capFlags+2,s ; Get the engine capability bits
sta EngineMode
2022-04-25 16:32:25 +00:00
phb
jsr _SetDataBank
jsr _CoreStartUp ; Initialize the library
2022-04-25 16:32:25 +00:00
plb
; SetWAP(userOrSystem, tsNum, waptPtr)
pea #$8000 ; $8000 = user tool set
pei ToolNum ; Push the tool number from the direct page
pea $0000 ; High word of WAP is zero (bank 0)
phd ; Low word of WAP is the direct page
2022-02-02 16:21:31 +00:00
_SetWAP
pld ; Restore the caller's direct page
ldx #0 ; No error
2022-04-24 19:45:07 +00:00
ldy #6 ; Remove the 6 input bytes
jml ToStrip
2022-02-02 16:21:31 +00:00
2022-04-24 19:45:07 +00:00
; ShutDown()
2022-02-02 16:21:31 +00:00
_TSShutDown
cmp #0 ; Acc is low word of the WAP (direct page)
beq :inactive
phd
tcd ; Set the direct page for the toolset
2022-02-02 16:21:31 +00:00
2022-04-25 16:32:25 +00:00
phb
jsr _SetDataBank
jsr _CoreShutDown ; Shut down the library
2022-04-25 16:32:25 +00:00
plb
2022-02-02 16:21:31 +00:00
pea $8000
pei ToolNum
2022-02-02 16:21:31 +00:00
pea $0000 ; Set WAP to null
pea $0000
_SetWAP
pld ; Restore the direct page
:inactive
lda #0
clc
rtl
_TSVersion
lda #$0100 ; Version 1
2022-02-02 16:21:31 +00:00
sta 7,s
lda #0
clc
rtl
_TSReset
lda #0
clc
rtl
; Check the WAP values in the A, Y registers
_TSStatus
sta 1,s
tya
ora 1,s
2022-04-24 19:45:07 +00:00
sta 1,s ; 0 if WAP is null, non-zero if WAP is set
2022-02-02 16:21:31 +00:00
lda #0
clc
rtl
_TSReserved
txa
xba
ora #$00FF ; Put error code $FF in the accumulator
sec
rtl
; SetScreenMode(width, height)
2022-02-02 16:21:31 +00:00
_TSSetScreenMode
2022-04-24 19:45:07 +00:00
height equ FirstParam
width equ FirstParam+2
2022-04-24 19:45:07 +00:00
_TSEntry
2022-02-02 16:21:31 +00:00
2022-04-24 19:45:07 +00:00
lda height,s
2022-02-02 16:21:31 +00:00
tay
2022-04-24 19:45:07 +00:00
lda width,s
2022-02-02 16:21:31 +00:00
tax
2022-04-25 21:35:47 +00:00
jsr _SetScreenMode
2022-04-24 19:45:07 +00:00
_TSExit #0;#4
2022-02-02 16:21:31 +00:00
; ReadControl()
2022-02-02 16:21:31 +00:00
_TSReadControl
2022-04-24 19:45:07 +00:00
output equ FirstParam
2022-04-24 19:45:07 +00:00
_TSEntry
2022-02-02 16:21:31 +00:00
jsr _ReadControl
2022-04-24 19:45:07 +00:00
sta output,s
2022-02-02 16:21:31 +00:00
_TSExit #0;#0
; SetTile(xTile, yTile, tileId)
_TSSetTile
tileId equ FirstParam
yTile equ FirstParam+2
xTile equ FirstParam+4
_TSEntry
2022-04-29 17:38:04 +00:00
lda xTile,s ; Valid range [0, 40] (41 columns)
tax
lda yTile,s ; Valid range [0, 25] (26 rows)
tay
lda tileId,s
2022-04-29 17:38:04 +00:00
jsr _SetTile
_TSExit #0;#6
; SetBG0Origin(x, y)
_TSSetBG0Origin
yPos equ FirstParam
xPos equ FirstParam+2
_TSEntry
2022-04-29 17:38:04 +00:00
lda xPos,s
jsr _SetBG0XPos
lda yPos,s
jsr _SetBG0YPos
_TSExit #0;#4
; Render()
_TSRender
_TSEntry
jsr _Render
2022-04-24 19:45:07 +00:00
_TSExit #0;#0
; LoadTileSet(Pointer)
_TSLoadTileSet
TSPtr equ FirstParam
_TSEntry
lda TSPtr+2,s
tax
lda TSPtr,s
jsr _LoadTileSet
_TSExit #0;#4
; CreateSpriteStamp(spriteId: Word, vbuffAddr: Word)
_TSCreateSpriteStamp
:vbuff equ FirstParam
:spriteId equ FirstParam+2
_TSEntry
lda :vbuff,s
tay
lda :spriteId,s
jsr _CreateSpriteStamp
_TSExit #0;#4
_TSAddSprite
:spriteSlot equ FirstParam+0
:spriteY equ FirstParam+2
:spriteX equ FirstParam+4
:spriteId equ FirstParam+6
_TSEntry
lda :spriteY,s
and #$00FF
xba
sta :spriteY,s
lda :spriteX,s
and #$00FF
ora :spriteY,s
tay
lda :spriteSlot,s
tax
lda :spriteId,s
jsr _AddSprite
_TSExit #0;#8
_TSMoveSprite
:spriteY equ FirstParam+0
:spriteX equ FirstParam+2
:spriteSlot equ FirstParam+4
_TSEntry
lda :spriteX,s
tax
lda :spriteY,s
tay
lda :spriteSlot,s
jsr _MoveSprite
_TSExit #0;#6
_TSUpdateSprite
:vbuff equ FirstParam+0
:spriteFlags equ FirstParam+2
:spriteSlot equ FirstParam+4
_TSEntry
lda :spriteFlags,s
tax
lda :vbuff,s
tay
lda :spriteSlot,s
jsr _UpdateSprite
_TSExit #0;#6
_TSRemoveSprite
:spriteSlot equ FirstParam+0
_TSEntry
lda :spriteSlot,s
jsr _UpdateSprite
_TSExit #0;#2
2022-04-25 16:32:25 +00:00
; Insert the GTE code
2022-04-25 16:32:25 +00:00
put Math.s
put CoreImpl.s
put Memory.s
put Timer.s
2022-04-25 16:32:25 +00:00
put Graphics.s
2022-04-25 21:35:47 +00:00
put Tiles.s
put Sprite.s
2022-05-27 00:36:40 +00:00
put Sprite2.s
put SpriteRender.s
put Render.s
put tiles/DirtyTileQueue.s
put tiles/FastRenderer.s
put blitter/Horz.s
put blitter/Vert.s
2022-04-25 16:32:25 +00:00
put blitter/BG0.s
put blitter/BG1.s
put blitter/Template.s
2022-04-25 21:35:47 +00:00
put blitter/TemplateUtils.s
2022-04-25 16:32:25 +00:00
put blitter/Blitter.s
put blitter/TileProcs.s
put blitter/Tiles00000.s
2022-04-25 21:35:47 +00:00
; put blitter/Tiles.s