4 ; Handling of linked sprite areas (MDW)
6 ; © 1995-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; Sprinkle is free software; you can redistribute it and/or modify
12 ; it under the terms of the GNU General Public License as published by
13 ; the Free Software Foundation; either version 2, or (at your option)
16 ; Sprinkle is distributed in the hope that it will be useful,
17 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ; GNU General Public License for more details.
21 ; You should have received a copy of the GNU General Public License
22 ; along with Sprinkle. If not, write to the Free Software Foundation,
23 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 ;----- Standard header ------------------------------------------------------
32 ;----- External dependencies ------------------------------------------------
36 ;----- Main code ------------------------------------------------------------
38 AREA |!!!Module$$Header|,CODE,READONLY
48 sl__name DCB "Sprinkle",0
50 ;----- Module header --------------------------------------------------------
52 AREA |Module$$Code|,CODE,READONLY
58 ; On exit: R0-R6 corrupted
60 ; Use: Initialises our module.
64 STMFD R13!,{R14} ;Save the link register
65 MOV R0,#&1F ;SpriteV's vector number
66 ADR R1,sl__spriteV ;Point to my handler routine
67 MOV R2,#0 ;No workspace required
68 SWI XOS_Claim ;Try to claim the vector
69 LDMFD R13!,{PC} ;Return with that status
77 ; On exit: R0-R6 corrupted
79 ; Use: Finalises our module when it's not needed any more.
83 STMFD R13!,{R14} ;Save the link register
84 MOV R0,#&1F ;SpriteV's vector number
85 ADR R1,sl__spriteV ;Point to the handler routine
86 MOV R2,#0 ;No workspace passed
87 SWI XOS_Release ;Release the vector
88 LDMFD R13!,{PC}^ ;Return without hassle
94 ; On entry: R0 == reason code
95 ; R1 == pointer to sprite area, normally
97 ; On exit: As for OS_SpriteOp
99 ; Use: Catches calls to OS_SpriteOp, to allow linked sprite areas.
103 TST R0,#&100 ;Is it named/user area?
104 MOVEQS PC,R14 ;No -- pass on the call then
106 STMFD R13!,{R10,R14} ;Save some registers
108 ; --- See if this call needs a sprite area in R1 ---
110 AND R14,R0,#&300 ;Get the magic extra bits
111 CMP R14,#&100 ;Using a user area?
112 LDMNEFD R13!,{R10,PC}^ ;No -- then do nothing
114 BIC R14,R0,#&300 ;Clear the magic bits
115 CMP R14,#8 ;Does call need area in R1?
116 LDMCCFD R13!,{R10,PC}^ ;No -- do nothing then
118 ; --- See if the sprite area is linked ---
120 10sl__spriteV LDR R14,[R1,#8] ;Load offset to first sprite
121 CMP R14,#24 ;Enough space for link?
122 LDMCCFD R13!,{R10,PC}^ ;No -- do nothing then
124 LDR R10,[R1,#16] ;Load first word of link
125 LDR R14,sl__magic ;Load the magic word
126 CMP R10,R14 ;Do these match?
127 LDMNEFD R13!,{R10,PC}^ ;No -- do nothing then
129 ; --- Now worked it out then ---
131 LDR R10,[R1,#20] ;Load the link pointer
132 CMP R10,#0 ;End of the list?
133 LDMEQFD R13!,{R10,PC}^ ;Yes -- do nothing then
135 ; --- Now call OS_SpriteOp and post-process ---
137 STMFD R13!,{R0,R10} ;Save reason code and link
138 MOV R14,PC ;Get PC and flags in R14
139 ADD R14,R14,#12 ;Point to postprocess code
140 STMFD R13!,{R14} ;Save those registers away
141 ADD R14,R13,#12 ;Skip over stacked registers
142 LDMIA R14,{R10,PC}^ ;And call OS_SpriteOp
144 ; --- Returned from OS_SpriteOp ---
146 LDMVSFD R13!,{R0,R1} ;If failed, load link pointer
147 BVS %10sl__spriteV ;And loop backwards to next
148 ADD R13,R13,#8 ;Point to old stack frame
149 LDMFD R13!,{R10,R14,PC}^ ;And claim the call
155 ;----- That's all, folks ----------------------------------------------------