Initial revision
[ssr] / StraySrc / Libraries / Sapphire / s / dynPtr
1 ;
2 ; dynPtr.s
3 ;
4 ; Dynamic pointer changing (TMA)
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sapphire library.
12 ;
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Standard header ------------------------------------------------------
28
29 GET libs:header
30 GET libs:swis
31
32 ;----- External dependencies ------------------------------------------------
33
34 GET sapphire:ptr
35 GET sapphire:resspr
36
37 ;----- Main code ------------------------------------------------------------
38
39 AREA |Sapphire$$Code|,CODE,READONLY
40
41 ; --- dynPtr_change ---
42 ;
43 ; On entry: R0 == pointer to string to use
44 ; R1 == pointer to pointer name
45 ; R2 == x hot spot
46 ; R3 == y hot spot
47 ;
48 ; On exit: --
49 ;
50 ; Use: Attaches a string to the default pointer shape.
51
52 EXPORT dynPtr_change
53 dynPtr_change ROUT
54
55 STMFD R13!,{R0-R10,R14} ;Stack some registers
56
57 MOV R9,R0 ;Remember this pointer
58
59 ; --- Output VDU operations to our sprite ---
60
61 BL resspr_area ;Get the address
62 MOV R8,R0 ;Remember this
63 MOV R1,R0 ;Put that in R1
64 MOV R0,#60+256 ;Output to a sprite
65 ADR R2,dynPtr__blank ;To this sprite please
66 MOV R3,#0 ;No save area
67 SWI OS_SpriteOp ;Okay dokay
68 STMFD R13!,{R0-R3} ;For the reversal operation
69
70 ; --- Clear the background ---
71
72 SWI OS_WriteI+16 ;CLG (Me... cheat?)
73
74 ; --- Copy the default pointer into our sprite ---
75
76 BL resspr_area ;Get callers sprite area
77 MOV R1,R0 ;Put it in R1
78 MOV R0,#256 ;Use area pointer
79 ADD R0,R0,#40 ;Get info
80 LDR R2,[R13,#20] ;Load the name ptr
81 SWI XOS_SpriteOp ;Try it then
82 MOVVS R0,#40 ;If no go -- try WIMP area
83 SWIVS Wimp_SpriteOp ;Get the info
84
85 MOV R0,R6 ;The screen mode
86 MOV R1,#4 ;XEig factor
87 SWI OS_ReadModeVariable ;Read it now
88 MOV R5,R2 ;Remember this
89 MOV R1,#5 ;YEig factor
90 SWI OS_ReadModeVariable ;Read it now
91
92 MOV R14,#1 ;Get a nice unit value
93 MOV R0,R14,LSL R5 ;Turn it into a useful value
94 MOV R1,R14,LSL R2 ;This one too
95 SUB R13,R13,#16 ;Get a block
96 MOV R14,R13 ;Remember this value
97 STMIA R14!,{R0,R1} ;Put this in the block
98 MOV R0,#2 ;XEig of our sprite
99 MOV R1,#2 ;YEig of our sprite
100 STMIA R14!,{R0,R1} ;Put this in the block too
101
102 MOV R4,R4,LSL R2 ;Height in OS pixels
103 RSB R4,R4,#64 ;Plot it here please
104 MOV R3,#0 ;And here too
105 MOV R5,#&08 ;Plot action
106 MOV R6,R13 ;Point to the block
107 MOV R7,#0 ;No translation table
108 LDR R2,[R13,#36] ;Load the name ptr
109 BL resspr_area ;Get callers sprite area
110 MOV R1,R0 ;Put it in R1
111 MOV R0,#256 ;Use area pointer
112 ADD R0,R0,#52 ;Plot scaled
113 SWI XOS_SpriteOp ;Try it then
114 MOVVS R0,#52 ;If no go -- try WIMP area
115 SWIVS Wimp_SpriteOp ;Plot it
116 ADD R13,R13,#12 ;Mark remembered it!!!
117
118 ; --- Now work out the width of the text ---
119
120 MOV R7,#2 ;Width so far
121 MOV R14,#0 ;A NULL word
122 STRB R14,[R13,#1] ;A NULL terminated string!
123 MOV R14,R9 ;Point to the string
124 MOV R1,R8 ;The sprite area
125 MOV R0,#40+256 ;Sprite info
126 MOV R2,R13 ;Point to our name buffer
127 10dynPtr_change LDRB R3,[R14],#1 ;Load out a character
128 CMP R3,#32 ;Is it a control character
129 BLT %20dynPtr_change ;Yes -- skip out of loop
130 STRB R3,[R2] ;Store in my block
131 SWI OS_SpriteOp ;Get the width
132 ADD R7,R7,R3,LSL #1 ;Add on the width
133 ADD R7,R7,#2 ;Don't forget the gap
134 B %10dynPtr_change ;Keep on looping
135
136 ; --- Do a background rectangle ---
137
138 20dynPtr_change SWI OS_WriteI+18 ;Change colour
139 SWI OS_WriteI+0 ;Still doing it
140 SWI OS_WriteI+1 ;Ahhh... this is the colour
141 MOV R0,#4 ;Do a move absolute
142 MOV R1,#0 ;Start at the left
143 MOV R2,#0 ;Bottom left
144 SWI OS_Plot ;Move to the point
145 MOV R0,#101 ;Rectangle fill
146 MOV R1,R7 ;The width
147 MOV R2,#26 ;Draw it this high
148 SWI OS_Plot ;Fill in the rectangle
149
150 ; --- Now plot the string ---
151
152 MOV R0,#1 ;Don't scale horizontally
153 MOV R1,#2 ;Double height
154 MOV R2,#1 ;Don't divide
155 MOV R3,#1 ;No, not at all
156 STMFD R13!,{R0-R3} ;Save the scale factors
157 MOV R1,R8 ;Point to the sprite area
158 ADD R2,R13,#16 ;Point to sprite names
159 MOV R10,#2 ;Current x position
160
161 30dynPtr_change LDRB R14,[R9],#1 ;Get byte from string
162 CMP R14,#32 ;Is it the end?
163 BLO %40dynPtr_change ;Yes -- skip to the end then
164
165 STRB R14,[R2] ;Save the sprite name
166 MOV R0,#52+256 ;Plot sprite scaled, please
167 MOV R3,R10 ;Get x position
168 MOV R4,#4 ;And a little bit up
169 MOV R5,#0 ;No GCOL action
170 MOV R6,R13 ;Point to scale factors
171 MOV R7,#0 ;No translate table please
172 SWI OS_SpriteOp ;Plot the sprite nicely
173
174 MOV R0,#40+256 ;Get sprite information
175 SWI OS_SpriteOp ;Read the sprite information
176 ADD R10,R10,R3,LSL #1 ;Add on the sprite's width
177 ADD R10,R10,#2 ;And a little bit of space
178 B %30dynPtr_change ;And go round for more
179
180 ; --- Reset screen context, set shape and return ---
181
182 40dynPtr_change ADD R13,R13,#20 ;Reset the stack pointer
183 LDMFD R13!,{R0-R3} ;Load back the context
184 SWI OS_SpriteOp ;Back to the screen please
185
186 ADR R0,dynPtr__blank ;Point to the sprite name
187 ADD R14,R13,#8 ;Point to the hot spot values
188 LDMIA R14,{R1,R2} ;Lad them out
189 BL ptr_setShape ;And set the pointer
190 LDMFD R13!,{R0-R10,PC}^ ;Ta-da! Return to caller
191
192 dynPtr__blank DCB "ptr_blank",0,0,0
193
194 LTORG
195
196 ;----- That's all, folks ----------------------------------------------------
197
198 END