Initial revision
[ssr] / StraySrc / Libraries / Core / EmbTemp / s / embTemp
1 ;
2 ; embTemp.s
3 ;
4 ; Handle embedded templates
5 ;
6 ; © 1995-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's core libraries (corelib).
12 ;
13 ; Corelib 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 ; Corelib 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 Corelib. 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 GET libs:stream
33
34 ;----- Main code ------------------------------------------------------------
35
36 AREA |Resources$$Code|,CODE,READONLY
37
38 ; --- embTemp_extract ---
39 ;
40 ; On entry: R0 == pointer to template block
41 ; R1 == pointer to window definition block
42 ; R2 == pointer to indirection space
43 ; R3 == pointer to end of indirection space
44 ; R4 == pointer to window sprite area
45 ; R5 == pointer to icon sprite area
46 ;
47 ; On exit: R2 == updated
48 ;
49 ; Use: Loads an embedded template (generated by templAOF) into a
50 ; block.
51
52 EXPORT embTemp_extract
53 embTemp_extract ROUT
54
55 STMFD R13!,{R0,R1,R3-R12,R14} ;Save some registers
56 MOV R12,R0 ;Look after this pointer
57 LDMIA R0!,{R9-R11} ;Load offsets from block
58 ADD R9,R9,R12 ;Relocate window offset
59 ADD R10,R10,R12 ;And the indirected offset
60 ADD R11,R11,R12 ;And the limit offset
61
62 ; --- Copy the window block over --
63
64 MOV R0,R1 ;Point to destination block
65 00 LDMIA R9!,{R6-R8,R14} ;Load 16 words
66 STMIA R0!,{R6-R8,R14} ;And blat them out again
67 CMP R9,R10 ;Have we finished yet?
68 BCC %b00 ;No -- keep on going then
69
70 ; --- Now copy the indirected data ---
71
72 SUB R14,R3,R2 ;Find how much room we have
73 SUB R9,R11,R10 ;And how much there is
74 CMP R14,R9 ;Do we have enough?
75 ADRCC R0,embTemp_noRoom ;No -- complain then
76 SWICC OS_GenerateError ;Really make a go of it
77 MOV R0,R2 ;Get a copy of output pointer
78
79 00 SUBS R9,R9,#16 ;Knock another 16 bytes off
80 LDMCSIA R10!,{R6-R8,R14} ;If OK, load lots of data
81 STMCSIA R2!,{R6-R8,R14} ;And store it out again
82 BCS %b00 ;And loop back for more
83
84 ADD R9,R9,#16 ;Now we overshot a bit
85 00 SUBS R9,R9,#1 ;Knock one byte off
86 LDRCSB R14,[R10],#1 ;Load a byte out
87 STRCSB R14,[R2],#1 ;Store it out again
88 BCS %b00 ;And loop back for more
89 ADD R2,R2,#3 ;Word align output pointer
90 BIC R2,R2,#3 ;To make next call nice
91
92 ; --- Now do the relocation ---
93
94 ADD R10,R12,#12 ;Point to relocation table
95 LDR R11,[R12,#0] ;Find end of relocations
96 ADD R11,R11,R12 ;Relocate that nicely
97
98 00 CMP R10,R11 ;Reached the end yet?
99 LDMCSFD R13!,{R0,R1,R3-R12,PC}^ ;Yes -- that's it then
100 LDR R14,[R10],#4 ;Load next directive
101 BIC R3,R14,#&F0000000 ;Just leave the offset
102 ADD PC,PC,R14,LSR #26 ;Jump table time
103 DCB "MDW!"
104 B %10embTemp_extract ;Handle indirect data reloc
105 B %20embTemp_extract ;Handle window sprite reloc
106 B %30embTemp_extract ;Handle icon sprite reloc
107
108 10 LDR R14,[R1,R3] ;Load the word
109 ADD R14,R14,R0 ;Relocate by indirected space
110 STR R14,[R1,R3] ;Store it back again
111 B %b00 ;And loop
112
113 20 STR R4,[R1,R3] ;Store window sprite area
114 B %b00 ;And loop
115
116 30 STR R5,[R1,R3] ;Store icon sprite area
117 B %b00 ;And loop
118
119 embTemp_noRoom DCD 1
120 DCB "No memory for indirected data",0
121
122 LTORG
123
124 ;----- That's all, folks ----------------------------------------------------
125
126 END