1 include(__link__.m4)
2 
3 #ifndef __BIFROST_H_H__
4 #define __BIFROST_H_H__
5 
6 #include <intrinsic.h>
7 
8 /* ----------------------------------------------------------------
9  * Z88DK INTERFACE LIBRARY FOR THE BIFROST* ENGINE - RELEASE 1.2/H
10  *
11  * If you use this interface library, you must load afterwards the
12  * BIFROST* ENGINE and a multicolor tile set. For a detailed sample
13  * see file "bifrostdem.c".
14  *
15  * Original version and further information is available at
16  * http://www.worldofspectrum.org/infoseekid.cgi?id=0027405
17  *
18  * Copyleft (k) Einar Saukas, Timmy
19  * Additional improvements provided by Alcoholics Anonymous
20  * ----------------------------------------------------------------
21  */
22 
23 // ----------------------------------------------------------------
24 // Constants
25 // ----------------------------------------------------------------
26 
27 extern unsigned char BIFROSTH_tilemap[81];
28 
29 #define BIFROSTH_STATIC    128
30 #define BIFROSTH_DISABLED  255
31 
32 // ----------------------------------------------------------------
33 // Activate multicolor rendering with BIFROST* ENGINE
34 // ----------------------------------------------------------------
35 
36 __OPROTO(`b,c,d,e',`b,c,d,e',void,,BIFROSTH_start,void)
37 
38 // ----------------------------------------------------------------
39 // Deactivate multicolor rendering with BIFROST* ENGINE
40 // ----------------------------------------------------------------
41 
42 __OPROTO(`b,c,d,e',`b,c,d,e',void,,BIFROSTH_stop,void)
43 
44 // ----------------------------------------------------------------
45 // Execute HALT (wait for next frame).
46 //
47 // If an interrupt occurs while certain routines (BIFROSTH_drawTileH,
48 // BIFROSTH_showTilePosH, BIFROSTH_showNextTile, etc) are under
49 // execution, the program may crash.
50 //
51 // Routine BIFROSTH_halt can be used to avoid these problems.
52 // Immediately after calling it, your program will have some time
53 // (about 20K T) to execute a few other routines without any
54 // interruption.
55 // ----------------------------------------------------------------
56 
57 #define BIFROSTH_halt()  intrinsic_halt()
58 
59 // ----------------------------------------------------------------
60 // Location of BIFROST ISR hook
61 // ----------------------------------------------------------------
62 
63 extern unsigned BIFROSTH_ISR_HOOK[3];
64 
65 // ----------------------------------------------------------------
66 // Place a multicolor tile index into the tile map. Add value
67 // BIFROSTH_STATIC for static tile, otherwise it will be animated
68 //
69 // Parameters:
70 //     px: tile vertical position (0-8)
71 //     py: tile horizontal position (0-8)
72 //     tile: tile index (0-255)
73 //
74 // Obs: Also available as inline macro (for constant parameters)
75 // ----------------------------------------------------------------
76 
77 __DPROTO(`b',`b,d',void,,BIFROSTH_setTile,unsigned char px, unsigned char py, unsigned char tile)
78 
79 #define M_BIFROSTH_SETTILE(px, py, tile)  BIFROSTH_tilemap[(px)*9+(py)] = (tile)
80 
81 // ----------------------------------------------------------------
82 // Obtain a multicolor tile index from the tile map
83 //
84 // Parameters:
85 //     px: tile vertical position (0-8)
86 //     py: tile horizontal position (0-8)
87 //
88 // Returns:
89 //     Tile index currently stored in this position
90 //
91 // Obs: Also available as inline macro (for constant parameters)
92 // ----------------------------------------------------------------
93 
94 __DPROTO(`b,d,e',`b,d,e',unsigned char,,BIFROSTH_getTile,unsigned char px, unsigned char py)
95 
96 #define M_BIFROSTH_GETTILE(px, py)   BIFROSTH_tilemap[(px)*9+(py)]
97 
98 // ----------------------------------------------------------------
99 // Convert multicolor tile index into the equivalent animation group
100 //
101 // Parameters:
102 //     tile: tile index (0-255)
103 //
104 // Returns:
105 //     Animation group for animated tile, otherwise the same tile index
106 // ----------------------------------------------------------------
107 
108 __DPROTO(`b,c,d,e,h',`b,c,d,e',unsigned char,,BIFROSTH_getAnimGroup,unsigned char tile)
109 
110 // ----------------------------------------------------------------
111 // Locate memory address that stores the multicolor attribute of a
112 // certain screen position inside the multicolor area
113 //
114 // Parameters:
115 //     lin: pixel line (16-159)
116 //     col: char column (1-18)
117 //
118 // Returns:
119 //     Memory address of the multicolor attribute
120 // ----------------------------------------------------------------
121 
122 __DPROTO(`a,b',`a,b',unsigned char,*,BIFROSTH_findAttrH,unsigned char lin, unsigned char col)
123 
124 // ----------------------------------------------------------------
125 // Reconfigure BIFROST* ENGINE to read tile images from another address
126 //
127 // Parameters:
128 //     addr: New tile images address
129 // ----------------------------------------------------------------
130 
131 extern unsigned char BIFROSTH_TILE_IMAGES[];
132 #define BIFROSTH_resetTileImages(addr)   intrinsic_store16(_BIFROSTH_TILE_IMAGES,addr)
133 
134 // ----------------------------------------------------------------
135 // Reconfigure BIFROST* ENGINE to animate at 2 frames per second
136 // ----------------------------------------------------------------
137 
138 #define BIFROSTH_resetAnimSlow()  (*((unsigned char*)59035)=254)
139 
140 // ----------------------------------------------------------------
141 // Reconfigure BIFROST* ENGINE to animate at 4 frames per second
142 // ----------------------------------------------------------------
143 
144 #define BIFROSTH_resetAnimFast()  (*((unsigned char*)59035)=198)
145 
146 // ----------------------------------------------------------------
147 // Reconfigure BIFROST* ENGINE to use 2 frames per animation group
148 // ----------------------------------------------------------------
149 
150 __OPROTO(`b,c,d,e',`b,c,d,e',void,,BIFROSTH_resetAnim2Frames,void)
151 
152 // ----------------------------------------------------------------
153 // Reconfigure BIFROST* ENGINE to use 4 frames per animation group
154 // ----------------------------------------------------------------
155 
156 __OPROTO(`b,c,d,e',`b,c,d,e',void,,BIFROSTH_resetAnim4Frames,void)
157 
158 // ----------------------------------------------------------------
159 // Advanced conversions
160 // ----------------------------------------------------------------
161 
162 #define PX2LIN(px)              (((px)+1)<<4)
163 #define PX2ROW(px)              (((px)<<1)+1)
164 
165 #define ROW2LIN(row)            (((row)+1)<<3)
166 #define ROW2PX_UP(row)          ((row)>>1)
167 #define ROW2PX_DOWN(row)        (((row)-1)>>1)
168 
169 #define LIN2ROW_UP(lin)         (((lin)>>3)-1)
170 #define LIN2ROW_DOWN(lin)       (((lin)-1)>>3)
171 #define LIN2PX_UP(lin)          (((lin)>>4)-1)
172 #define LIN2PX_DOWN(lin)        (((lin)-1)>>4)
173 
174 #define PY2COL(py)              (((py)<<1)+1)
175 #define COL2PY_LEFT(col)        (((col)-1)>>1)
176 #define COL2PY_RIGHT(col)       ((col)>>1)
177 
178 // ----------------------------------------------------------------
179 // Instantly draw a multicolor tile at the specified screen position
180 //
181 // Parameters:
182 //     lin: pixel line (0-160)
183 //     col: char column (0-18)
184 //     tile: tile index (0-255)
185 //
186 // WARNING: If this routine is under execution when interrupt
187 //          occurs, program may crash!!! (see BIFROSTH_halt)
188 // ----------------------------------------------------------------
189 
190 __DPROTO(,,void,,BIFROSTH_drawTileH,unsigned char lin, unsigned char col, unsigned char tile)
191 
192 // ----------------------------------------------------------------
193 // Instantly show/animate the multicolor tile currently stored in
194 // the specified tile map position
195 //
196 // Parameters:
197 //     lin: pixel line (16,32,48..144)
198 //     col: char column (1,3,5..17)
199 //
200 // WARNING: If this routine is under execution when interrupt
201 //          occurs, program may crash!!! (see BIFROSTH_halt)
202 // ----------------------------------------------------------------
203 
204 __DPROTO(,,void,,BIFROSTH_showTilePosH,unsigned char lin, unsigned char col)
205 
206 // ----------------------------------------------------------------
207 // Instantly show/animate the next multicolor tile currently stored
208 // in the tile map position, according to a pre-established drawing
209 // order
210 //
211 // WARNING: If this routine is under execution when interrupt
212 //          occurs, program may crash!!! (see BIFROSTH_halt)
213 // ----------------------------------------------------------------
214 
215 __OPROTO(,,void,,BIFROSTH_showNextTile,void)
216 
217 // ----------------------------------------------------------------
218 // Instantly change the attributes in a tile area (16x16 pixels) to
219 // the specified value (use the same INK and PAPER values to "erase"
220 // a tile)
221 //
222 // Parameters:
223 //     lin: pixel line (0-160)
224 //     col: char column (0-18)
225 //     attr: attribute value (0-255), INK+8*PAPER+64*BRIGHT+128*FLASH
226 //
227 // WARNING: If this routine is under execution when interrupt
228 //          occurs, program may crash!!! (see BIFROSTH_halt)
229 // ----------------------------------------------------------------
230 
231 __DPROTO(,,void,,BIFROSTH_fillTileAttrH,unsigned char lin, unsigned char col, unsigned char attr)
232 
233 // ----------------------------------------------------------------
234 // Sprite addresses
235 // ----------------------------------------------------------------
236 #define BIFROSTHSPRITE1LIN   ((unsigned char *)58056)
237 #define BIFROSTHSPRITE1COL   ((unsigned char *)58055)
238 #define BIFROSTHSPRITE1TILE  ((unsigned char *)58058)
239 #define BIFROSTHSPRITE2LIN   ((unsigned char *)58065)
240 #define BIFROSTHSPRITE2COL   ((unsigned char *)58064)
241 #define BIFROSTHSPRITE2TILE  ((unsigned char *)58067)
242 
243 // ----------------------------------------------------------------
244 // Reconfigure BIFROST* ENGINE to draw sprites at every frame
245 //
246 // NOTE: Regular tiles will be updated/animated at 2 frames per
247 // second (slow)
248 // ----------------------------------------------------------------
249 
250 #define BIFROSTH_enableSprites()  intrinsic_store16(59040,58054)
251 
252 // ----------------------------------------------------------------
253 // Reconfigure BIFROST* ENGINE to stop drawing sprites
254 // ----------------------------------------------------------------
255 
256 #define BIFROSTH_disableSprites()  intrinsic_store16(59040,58636)
257 
258 // ----------------------------------------------------------------
259 // Instantly redraw all multicolor tiles stored in tile map positions
260 // behind the specified screen position. Positions that store value
261 // BIFROSTDISABLED in the tile map are "erased" by filling the position
262 // with the specified attribute
263 //
264 // Parameters:
265 //     lin: pixel line (0-160)
266 //     col: char column (0-18)
267 //     attr: attribute value (0-255), INK+8*PAPER+64*BRIGHT+128*FLASH
268 //
269 // WARNING: If this routine is under execution when interrupt
270 //          occurs, program may crash!!! (see BIFROSTH_halt)
271 // ----------------------------------------------------------------
272 
273 __DPROTO(,,void,,BIFROSTH_drawBackTilesH,unsigned char lin,unsigned char col,unsigned char attr)
274 
275 // ----------------------------------------------------------------
276 // Instantly redraw the multicolor tile currently stored in the
277 // specified tile map position. If this position stores value
278 // BIFROSTH_DISABLED in the tile map, it will be "erased" by filling
279 // its position with the specified attribute
280 //
281 // Parameters:
282 //     lin: pixel line (0-160)
283 //     col: char column (0-18)
284 //     attr: attribute value (0-255), INK+8*PAPER+64*BRIGHT+128*FLASH
285 //
286 // WARNING: If this routine is under execution when interrupt
287 //          occurs, program may crash!!! (see BIFROSTH_halt)
288 // ----------------------------------------------------------------
289 
290 __DPROTO(,,void,,BIFROSTH_drawTilePosH,unsigned char lin,unsigned char col,unsigned char attr)
291 
292 #endif
293