#name ^.Object.TextHandle
#type &ffd
#include Oddball:Sources.Structures
#include Oddball:Sources.Variables

; *** The message creator must follow this code 
; immediately in memory for links to work.

; Text handler
.start
STMFD R13!,{R14}
MOV R0,#texttab
MOV R1,#0
MOV R2,#0
SWI Amnesia_SelectTable
.loop
SWI Amnesia_ProcessTable
TST R2,#1<<1; user plot bit
BLNE foundtext
TST R2,#1<<8; timer expiry
BLNE timerexp
CMP R2,#0
BNE loop
LDMFD R13!,{PC}

.foundtext
STMFD R13!,{R0-R2,R8,R14}
LDR R3,[R1,#28]
MOV R3,R3,LSR #17; get xsize/2
LDR R4,[R1,#8]
LDR R5,[R1,#12]
MOV R4,R4,ASR #12
MOV R5,R5,ASR #12
SUB R4,R4,R3
LDR R6,[R1,#32]; address of text
ADD R4,R4,R8
.loop2
LDRB R0,[R6],#1
CMP R0,#32
BLT textend
ADDEQ R4,R4,#6
BEQ loop2
ADD R0,R0,#texttab<<24
MOV R7,R0
SWI XFastSpr_ReadSize
MOV R3,R0
ADD R4,R4,R0,LSR #1
MOV R0,R7
MOV R1,R4
MOV R2,R5
SWI XFastSpr_Plot
ADD R4,R4,R3,LSR #1
ADD R4,R4,#2
B loop2
.textend
LDMFD R13!,{R0-R2,R8,PC}
.timerexp
STMFD R13!,{R0-R2,R8,R14}
LDR R3,[R1,#32]
SUB R3,R3,#24
LDR R4,[R3,#20]; get link offset
CMP R4,#0
ADD R0,R3,R4
BLNE message
LDMFD R13!,{R0-R2,R8,PC}
.message
; place nothing after this label




