chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Sapphire / Modules / s / sprinkle
1 ;
2 ; sprinkle.s
3 ;
4 ; Handling of linked sprite areas (MDW)
5 ;
6 ; © 1995-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
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)
14 ; any later version.
15 ;
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.
20 ;
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.
24
25 ;----- Standard header ------------------------------------------------------
26
27                 GET     libs:header
28                 GET     libs:swis
29
30                 GET     libs:stream
31
32 ;----- External dependencies ------------------------------------------------
33
34                 IMPORT  version
35
36 ;----- Main code ------------------------------------------------------------
37
38                 AREA    |!!!Module$$Header|,CODE,READONLY
39
40                 DCD     0
41                 DCD     sl__init
42                 DCD     sl__final
43                 DCD     0
44                 DCD     sl__name
45                 DCD     version
46                 DCD     0
47
48 sl__name        DCB     "Sprinkle",0
49
50 ;----- Module header --------------------------------------------------------
51
52                 AREA    |Module$$Code|,CODE,READONLY
53
54 ; --- sl__init ---
55 ;
56 ; On entry:     --
57 ;
58 ; On exit:      R0-R6 corrupted
59 ;
60 ; Use:          Initialises our module.
61
62 sl__init        ROUT
63
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
70
71                 LTORG
72
73 ; --- sl__final ---
74 ;
75 ; On entry:     --
76 ;
77 ; On exit:      R0-R6 corrupted
78 ;
79 ; Use:          Finalises our module when it's not needed any more.
80
81 sl__final       ROUT
82
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
89
90                 LTORG
91
92 ; --- sl__spriteV ---
93 ;
94 ; On entry:     R0 == reason code
95 ;               R1 == pointer to sprite area, normally
96 ;
97 ; On exit:      As for OS_SpriteOp
98 ;
99 ; Use:          Catches calls to OS_SpriteOp, to allow linked sprite areas.
100
101 sl__spriteV     ROUT
102
103                 TST     R0,#&100                ;Is it named/user area?
104                 MOVEQS  PC,R14                  ;No -- pass on the call then
105
106                 STMFD   R13!,{R10,R14}          ;Save some registers
107
108                 ; --- See if this call needs a sprite area in R1 ---
109
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
113
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
117
118                 ; --- See if the sprite area is linked ---
119
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
123
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
128
129                 ; --- Now worked it out then ---
130
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
134
135                 ; --- Now call OS_SpriteOp and post-process ---
136
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
143
144                 ; --- Returned from OS_SpriteOp ---
145
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
150
151 sl__magic       DCB     "SPLK"
152
153                 LTORG
154
155 ;----- That's all, folks ----------------------------------------------------
156
157                 END