mirror of
https://github.com/lscharen/iigs-game-engine.git
synced 2024-06-12 13:29:30 +00:00
Handle memory cleanup and interrup setup more robustly
This commit is contained in:
parent
5a0e0e447e
commit
5114ef569a
|
@ -28,6 +28,22 @@ _Deref MAC
|
|||
plb ; restore the caller's data bank register
|
||||
<<<
|
||||
|
||||
|
||||
; Call _NewHandle, but track the allocation
|
||||
_TrackHandle mac
|
||||
_NewHandle
|
||||
bcs err
|
||||
ldx NumHandles
|
||||
lda 1,s
|
||||
sta Handles,x
|
||||
lda 3,s
|
||||
sta Handles+2,x
|
||||
txa
|
||||
adc #4
|
||||
sta NumHandles
|
||||
err
|
||||
<<<
|
||||
|
||||
_Mul128 mac
|
||||
asl
|
||||
asl
|
||||
|
|
|
@ -97,6 +97,7 @@ _CoreStartUp
|
|||
rts
|
||||
|
||||
_CoreShutDown
|
||||
jsr UnInitMemory
|
||||
jsr IntShutDown
|
||||
rts
|
||||
|
||||
|
@ -107,11 +108,15 @@ _CoreShutDown
|
|||
IntStartUp
|
||||
lda #NO_INTERRUPTS
|
||||
bne :no_interrupts
|
||||
|
||||
PushLong #0
|
||||
pea $0015 ; Get the existing 1-second interrupt handler and save
|
||||
_GetVector
|
||||
PullLong OldOneSecVec
|
||||
|
||||
pea $0007
|
||||
_IntSource
|
||||
|
||||
pea $0015 ; Set the new handler and enable interrupts
|
||||
PushLong #OneSecHandler
|
||||
_SetVector
|
||||
|
@ -119,8 +124,8 @@ IntStartUp
|
|||
pea $0006
|
||||
_IntSource
|
||||
|
||||
PushLong #VBLTASK ; Also register a Heart Beat Task
|
||||
_SetHeartBeat
|
||||
; PushLong #VBLTASK ; Also register a Heart Beat Task
|
||||
; _SetHeartBeat
|
||||
|
||||
:no_interrupts
|
||||
rts
|
||||
|
@ -129,12 +134,12 @@ IntShutDown
|
|||
lda #NO_INTERRUPTS
|
||||
bne :no_interrupts
|
||||
|
||||
; PushLong #VBLTASK ; Remove our heartbeat task
|
||||
; _DelHeartBeat
|
||||
|
||||
pea $0007 ; disable 1-second interrupts
|
||||
_IntSource
|
||||
|
||||
PushLong #VBLTASK ; Remove our heartbeat task
|
||||
_DelHeartBeat
|
||||
|
||||
pea $0015
|
||||
PushLong OldOneSecVec ; Reset the interrupt vector
|
||||
_SetVector
|
||||
|
|
|
@ -266,6 +266,8 @@ VBuffHorzTableSelect EXT
|
|||
Overlays EXT
|
||||
BG1YCache EXT
|
||||
ScalingTables EXT
|
||||
NumHandles EXT
|
||||
Handles EXT
|
||||
|
||||
; Tool error codes
|
||||
NO_TIMERS_AVAILABLE equ 10
|
||||
|
|
30
src/Memory.s
30
src/Memory.s
|
@ -25,7 +25,7 @@ InitMemory lda EngineMode
|
|||
PushWord UserId
|
||||
PushWord #%11000000_00010111 ; Fixed location
|
||||
PushLong #$002000
|
||||
_NewHandle ; returns LONG Handle on stack
|
||||
_TrackHandle ; returns LONG Handle on stack
|
||||
plx ; base address of the new handle
|
||||
pla ; high address 00XX of the new handle (bank)
|
||||
; _Deref
|
||||
|
@ -38,7 +38,7 @@ InitMemory lda EngineMode
|
|||
PushWord UserId
|
||||
PushWord #%11000000_00010111 ; Fixed location
|
||||
PushLong #$012000
|
||||
_NewHandle ; returns LONG Handle on stack
|
||||
_TrackHandle ; returns LONG Handle on stack
|
||||
plx ; base address of the new handle
|
||||
pla ; high address 00XX of the new handle (bank)
|
||||
; _Deref
|
||||
|
@ -58,7 +58,7 @@ InitMemory lda EngineMode
|
|||
PushWord UserId
|
||||
PushWord #%11000000_00010101 ; Page-aligned, fixed bank
|
||||
PushLong #$000000
|
||||
_NewHandle ; returns LONG Handle on stack
|
||||
_TrackHandle ; returns LONG Handle on stack
|
||||
plx ; base address of the new handle
|
||||
pla ; high address 00XX of the new handle (bank)
|
||||
_Deref
|
||||
|
@ -156,6 +156,26 @@ InitMemory lda EngineMode
|
|||
:exit
|
||||
rts
|
||||
|
||||
UnInitMemory
|
||||
ldx #0
|
||||
:loop
|
||||
phx ; save
|
||||
lda Handles+2,x
|
||||
pha
|
||||
lda Handles,x
|
||||
pha
|
||||
_DisposeHandle
|
||||
|
||||
pla
|
||||
clc
|
||||
adc #4
|
||||
tax
|
||||
cpx NumHandles
|
||||
bcc :loop
|
||||
|
||||
stz NumHandles
|
||||
rts
|
||||
|
||||
; Bank allocator (for one full, fixed bank of memory. Can be immediately deferenced)
|
||||
|
||||
AllocOneBank PushLong #0
|
||||
|
@ -163,7 +183,7 @@ AllocOneBank PushLong #0
|
|||
PushWord UserId
|
||||
PushWord #%11000000_00011100
|
||||
PushLong #0
|
||||
_NewHandle ; returns LONG Handle on stack
|
||||
_TrackHandle ; returns LONG Handle on stack
|
||||
plx ; base address of the new handle
|
||||
pla ; high address 00XX of the new handle (bank)
|
||||
xba ; swap accumulator bytes to XX00
|
||||
|
@ -177,7 +197,7 @@ AllocOneBank2 PushLong #0
|
|||
PushWord UserId
|
||||
PushWord #%11000000_00011100
|
||||
PushLong #0
|
||||
_NewHandle
|
||||
_TrackHandle
|
||||
plx ; base address of the new handle
|
||||
pla ; high address 00XX of the new handle (bank)
|
||||
_Deref
|
||||
|
|
18
src/Tool.s
18
src/Tool.s
|
@ -110,12 +110,18 @@ _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
|
||||
;_SetDataBank
|
||||
; sep #$20
|
||||
; lda #^TileStore
|
||||
; pha
|
||||
; plb
|
||||
; rep #$20
|
||||
; rts
|
||||
_SetDataBank
|
||||
pea #>TileStore ; This does not depend on Acc being 8 or 16 bit
|
||||
plb
|
||||
plb
|
||||
rts
|
||||
|
||||
; Do nothing when the tool set is installed
|
||||
_TSBootInit
|
||||
|
|
|
@ -534,5 +534,11 @@ Scale13 dw $0036,$0036,$0036,$0038,$0038,$0038,$003A,$003A,$003A,$003C,$003C,$
|
|||
Scale14 dw $0038,$003A,$003A,$003A,$003C,$003C,$003C,$003C,$003E,$003E,$003E,$0040,$0040,$0040,$0040,$0042,$0042,$0042,$0044,$0044,$0044,$0044,$0046,$0046,$0046,$0048,$0048,$0048,$0048,$004A,$004A,$004A,$004C,$004C,$004C,$004C,$004E,$004E,$004E,$0050,$0050,$0050,$0050,$0052,$0052,$0052,$0054,$0054,$0054,$0054,$0056,$0056,$0056,$0058,$0058,$0058,$0058,$005A,$005A,$005A,$005C,$005C,$005C,$005C,$005E,$005E,$005E,$0060,$0060,$0060,$0060,$0062,$0062,$0062,$0064,$0064,$0064,$0064,$0066,$0066,$0066,$0068
|
||||
Scale15 dw $003C,$003C,$003C,$003E,$003E,$003E,$003E,$0040,$0040,$0040,$0040,$0042,$0042,$0042,$0042,$0044,$0044,$0044,$0044,$0046,$0046,$0046,$0046,$0048,$0048,$0048,$0048,$004A,$004A,$004A,$004A,$004C,$004C,$004C,$004C,$004E,$004E,$004E,$004E,$0050,$0050,$0050,$0050,$0052,$0052,$0052,$0052,$0054,$0054,$0054,$0054,$0056,$0056,$0056,$0056,$0058,$0058,$0058,$0058,$005A,$005A,$005A,$005A,$005C,$005C,$005C,$005C,$005E,$005E,$005E,$005E,$0060,$0060,$0060,$0060,$0062,$0062,$0062,$0062,$0064,$0064,$0064
|
||||
|
||||
; List of handles that are allocated in InitMemory so we can explicitly release the handles
|
||||
NumHandles ENT
|
||||
dw 0
|
||||
Handles ENT
|
||||
ds 4*32
|
||||
|
||||
blt_return
|
||||
stk_save
|
Loading…
Reference in New Issue
Block a user