/
bifrost2.h
281 lines (207 loc) · 10.3 KB
/
bifrost2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
// automatically generated by m4 from headers in proto subdir
#ifndef __BIFROST2_H__
#define __BIFROST2_H__
#include <arch.h>
#include <intrinsic.h>
/* ----------------------------------------------------------------
* Z88DK INTERFACE LIBRARY FOR THE BIFROST*2 ENGINE - by Einar Saukas
*
* If you use this interface library, you must load afterwards the
* BIFROST*2 ENGINE and a multicolor tile set. For a detailed sample
* see file "bifrost2dem.c".
* ----------------------------------------------------------------
*/
// ----------------------------------------------------------------
// Constants
// ----------------------------------------------------------------
extern unsigned char BIFROST2_tilemap[81];
#define BIFROST2_STATIC 128
#define BIFROST2_DISABLED 255
// ----------------------------------------------------------------
// Install BIFROST*2 ENGINE
// ----------------------------------------------------------------
extern void BIFROST2_install(void);
// ----------------------------------------------------------------
// Location of BIFROST*2 ISR hook
// ----------------------------------------------------------------
extern unsigned char BIFROST2_ISR_HOOK[3];
// ----------------------------------------------------------------
// Location of BIFROST*2 hole
// ----------------------------------------------------------------
#define BIFROST2_HOLE_SIZE __BIFROST2_HOLE_SIZE
#if BIFROST2_HOLE_SIZE > 0
extern unsigned char BIFROST2_HOLE[BIFROST2_HOLE_SIZE];
#endif
// ----------------------------------------------------------------
// Activate multicolor rendering with BIFROST*2 ENGINE
// ----------------------------------------------------------------
extern void BIFROST2_start(void) __preserves_regs(b,c,d,e);
// ----------------------------------------------------------------
// Deactivate multicolor rendering with BIFROST*2 ENGINE
// ----------------------------------------------------------------
extern void BIFROST2_stop(void) __preserves_regs(b,c,d,e);
// ----------------------------------------------------------------
// Execute HALT (wait for next frame).
//
// If an interrupt occurs while certain routines (BIFROST2_drawTileH,
// BIFROST2_showTilePosH, BIFROST2_showNextTile, BIFROST2_fillTileAttrH)
// are under execution, the program may crash.
//
// Routine BIFROST2_halt can be used to avoid these problems.
// Immediately after calling it, your program will have some time
// to execute a few other routines without any interruption.
// ----------------------------------------------------------------
#define BIFROST2_halt() intrinsic_halt()
// ----------------------------------------------------------------
// Place a multicolor tile index into the tile map. Add value
// BIFROST2_STATIC for static tile, otherwise it will be animated
//
// Parameters:
// px: tile vertical position (0-10)
// py: tile horizontal position (0-9)
// tile: tile index (0-255)
//
// Obs: Also available as inline macro (for constant parameters)
// ----------------------------------------------------------------
extern void BIFROST2_setTile(unsigned char px,unsigned char py,unsigned char tile) __preserves_regs(b,d);
extern void BIFROST2_setTile_callee(unsigned char px,unsigned char py,unsigned char tile) __preserves_regs(b) __z88dk_callee;
#define BIFROST2_setTile(a,b,c) BIFROST2_setTile_callee(a,b,c)
#define M_BIFROST2_SETTILE(px, py, tile) BIFROST2_tilemap[(px)*10+(py)] = (tile)
// ----------------------------------------------------------------
// Obtain a multicolor tile index from the tile map
//
// Parameters:
// px: tile vertical position (0-10)
// py: tile horizontal position (0-9)
//
// Returns:
// Tile index currently stored in this position
//
// Obs: Also available as inline macro (for constant parameters)
// ----------------------------------------------------------------
extern unsigned char BIFROST2_getTile(unsigned char px,unsigned char py) __preserves_regs(b,d,e);
extern unsigned char BIFROST2_getTile_callee(unsigned char px,unsigned char py) __preserves_regs(b,d,e) __z88dk_callee;
#define BIFROST2_getTile(a,b) BIFROST2_getTile_callee(a,b)
#define M_BIFROST2_GETTILE(px, py) BIFROST2_tilemap[(px)*10+(py)]
// ----------------------------------------------------------------
// Convert multicolor tile index into the equivalent animation group
//
// Parameters:
// tile: tile index (0-255)
//
// Returns:
// Animation group for animated tile, otherwise the same tile index
// ----------------------------------------------------------------
extern unsigned char BIFROST2_getAnimGroup(unsigned char tile) __preserves_regs(b,c,d,e);
extern unsigned char BIFROST2_getAnimGroup_fastcall(unsigned char tile) __preserves_regs(b,c,d,e,h) __z88dk_fastcall;
#define BIFROST2_getAnimGroup(a) BIFROST2_getAnimGroup_fastcall(a)
// ----------------------------------------------------------------
// Locate memory address that stores the multicolor attribute of a
// certain screen position inside the multicolor area
//
// Parameters:
// lin: pixel line (0-192)
// col: char column (1-20)
//
// Returns:
// Memory address of the multicolor attribute
// ----------------------------------------------------------------
extern unsigned char *BIFROST2_findAttrH(unsigned char lin,unsigned char col) __preserves_regs(b);
extern unsigned char *BIFROST2_findAttrH_callee(unsigned char lin,unsigned char col) __preserves_regs(b) __z88dk_callee;
#define BIFROST2_findAttrH(a,b) BIFROST2_findAttrH_callee(a,b)
// ----------------------------------------------------------------
// Reconfigure BIFROST*2 ENGINE to read tile images from another address
//
// Parameters:
// addr: New tile images address
// ----------------------------------------------------------------
extern unsigned char BIFROST2_TILE_IMAGES[];
#define BIFROST2_resetTileImages(addr) intrinsic_store16(_BIFROST2_TILE_IMAGES,addr)
// ----------------------------------------------------------------
// Reconfigure BIFROST*2 ENGINE to use 2 frames per animation group
// ----------------------------------------------------------------
extern void BIFROST2_resetAnim2Frames(void) __preserves_regs(b,c,d,e);
// ----------------------------------------------------------------
// Reconfigure BIFROST*2 ENGINE to use 4 frames per animation group
// ----------------------------------------------------------------
extern void BIFROST2_resetAnim4Frames(void) __preserves_regs(b,c,d,e);
// ----------------------------------------------------------------
// Advanced conversions
// ----------------------------------------------------------------
#define PX2LIN(px) (((px)+1)<<4)
#define PX2ROW(px) (((px)<<1)+1)
#define ROW2LIN(row) (((row)+1)<<3)
#define ROW2PX_UP(row) ((row)>>1)
#define ROW2PX_DOWN(row) (((row)-1)>>1)
#define LIN2ROW_UP(lin) (((lin)>>3)-1)
#define LIN2ROW_DOWN(lin) (((lin)-1)>>3)
#define LIN2PX_UP(lin) (((lin)>>4)-1)
#define LIN2PX_DOWN(lin) (((lin)-1)>>4)
#define PY2COL(py) (((py)<<1)+1)
#define COL2PY_LEFT(col) (((col)-1)>>1)
#define COL2PY_RIGHT(col) ((col)>>1)
// ----------------------------------------------------------------
// Instantly draw a multicolor tile at the specified screen position.
// Adding value BIFROST2STATIC (or not) to tile index won't make any
// difference since it will be drawn only once.
//
// Parameters:
// lin: pixel line (0-192)
// col: char column (0-20)
// tile: tile index (0-255)
//
// WARNING: If this routine is under execution when interrupt
// occurs, program may crash!!! (see BIFROST2_halt)
// ----------------------------------------------------------------
extern void BIFROST2_drawTileH(unsigned char lin,unsigned char col,unsigned char tile);
extern void BIFROST2_drawTileH_callee(unsigned char lin,unsigned char col,unsigned char tile) __z88dk_callee;
#define BIFROST2_drawTileH(a,b,c) BIFROST2_drawTileH_callee(a,b,c)
// ----------------------------------------------------------------
// Instantly show/animate the multicolor tile currently stored in
// the specified tile map position
//
// Parameters:
// lin: pixel line (16,32,48..176)
// col: char column (1,3,5..19)
//
// WARNING: If this routine is under execution when interrupt
// occurs, program may crash!!! (see BIFROST2_halt)
// ----------------------------------------------------------------
extern void BIFROST2_showTilePosH(unsigned char lin,unsigned char col);
extern void BIFROST2_showTilePosH_callee(unsigned char lin,unsigned char col) __z88dk_callee;
#define BIFROST2_showTilePosH(a,b) BIFROST2_showTilePosH_callee(a,b)
// ----------------------------------------------------------------
// Instantly show/animate the next multicolor tile currently stored
// in the tile map position, according to a pre-established drawing
// order
//
// WARNING: If this routine is under execution when interrupt
// occurs, program may crash!!! (see BIFROST2_halt)
// ----------------------------------------------------------------
extern void BIFROST2_showNextTile(void);
// ----------------------------------------------------------------
// Instantly show/animate the next two multicolor tiles currently
// stored in the tile map position, according to a pre-established
// drawing order
//
// WARNING: If this routine is under execution when interrupt
// occurs, program may crash!!! (see BIFROST2_halt)
// ----------------------------------------------------------------
extern void BIFROST2_showNext2Tiles(void);
// ----------------------------------------------------------------
// Instantly change the attributes in a tile area (16x16 pixels) to
// the specified value (use the same INK and PAPER values to "erase"
// a tile)
//
// Parameters:
// lin: pixel line (0-192)
// col: char column (0-20)
// attr: attribute value (0-255), INK+8*PAPER+64*BRIGHT+128*FLASH
//
// WARNING: If this routine is under execution when interrupt
// occurs, program may crash!!! (see BIFROST2_halt)
// ----------------------------------------------------------------
extern void BIFROST2_fillTileAttrH(unsigned char lin,unsigned char col,unsigned char attr) __preserves_regs(b);
extern void BIFROST2_fillTileAttrH_callee(unsigned char lin,unsigned char col,unsigned char attr) __preserves_regs(b) __z88dk_callee;
#define BIFROST2_fillTileAttrH(a,b,c) BIFROST2_fillTileAttrH_callee(a,b,c)
#endif