1 /*=========================================================================
2 
3 Compatibility headers for Z88DK
4 
5 GFX - a small graphics library
6 
7 Copyright (C) 2004  Rafael de Oliveira Jannone
8 
9 
10 Contact the author:
11 	by e-mail : rafael AT jannone DOT org
12 	homepage  : http://jannone.org/gfxlib
13 	ICQ UIN   : 10115284
14 
15 
16 $Id: gfx.h,v 1.9 2014-05-02 08:10:24 stefano Exp $
17 
18 
19 =========================================================================*/
20 
21 /*! \file gfx.h
22     \brief main library functions
23 */
24 // GFX.H : main library functions (header)
25 
26 /* === WARNING ==
27 
28 	This is a work-in-progress, meaning that most of this code is unstable
29 	and it's subject to future changes.  Also, most of it is very hackish,
30 	not properly cleaned up nor tested.
31 
32    === WARNING == */
33 
34 #ifndef MSXGFX_H
35 #define MSXGFX_H
36 
37 
38 #include <msx/defs.h>
39 #include <stdlib.h>
40 #include <msx.h>
41 #include <string.h>
42 #include <graphics.h>
43 #include <psg.h>
44 
45 // --- library functions / enums
46 
47 /// @name Video
48 /// VRAM and VDP related functions
49 //@{
50 
51 // VDP and VRAM functions
52 
53 /// set screen mode
54 #define set_mode(mode) msx_set_mode(mode)
55 
56 /// set screen to mangled mode (screen 1 + 2)
57 #define set_mangled_mode() msx_set_mangled_mode()
58 
59 /// set screen color
60 #define set_color(front,back,border) msx_color(front,back,border)
61 
62 
63 // SORRY, WE HAVE A FUNCTION NAME CONFLICT.
64 // GET RID OF THE "DEFAULT" FILL FUNCTION (FILLS GRAPHICS AREA)
65 // AND DEFINE THE NEW ONE (VRAM FILL)
66 
67 #undef fill
68 
69 /// fill vram from \a addr, with \a value, for \a count bytes
70 #define fill(addr,value,count) msx_vfill(addr,value,count)
71 
72 
73 /// set \a value at a given vram address \a addr
74 //define vpoke(addr,value) msx_vpoke(addr,value)
75 
76 /// get value from a given vram address \a addr
77 //#define vpeek(addr) msx_vpeek(addr)
78 
79 /// set \a value at a given vram address \a addr, merging bits (OR) with the existing value
80 #define vmerge(addr,value) msx_vmerge(addr,value)
81 
82 /// transfer \a count bytes from ram to vram
83 #define vwrite(source,dest,count) msx_vwrite(source,dest,count)
84 
85 /// transfer \a count bytes from vram to ram
86 #define vread(source,dest,count) msx_vread(source,dest,count)
87 
88 /// set a vdp register with a \a value
89 #define set_vdp(reg,value) set_vdp_reg(reg,value)
90 
91 /// get a vdp value from register \a reg
92 #define get_vdp(reg) get_vdp_reg(reg)
93 
94 /// move the screen cursor to a given position
95 #define locate(x,y) msx_locate(x,y)
96 
97 
98 
99 // primitives (not many yet :))
100 
101 /// vertical fill on vram starting at adress \a addr, of a given \a value, for \a count lines
102 #define fill_v(addr,value,count) msx_vfill_v(addr,value,count)
103 
104 
105 
106 // mangled mode chars
107 
108 /// set char \a c shape, from \a form, at the given screen map \a place
109 #define set_char_form(c,form,place) msx_set_char_form(c,form,place)
110 
111 /// set char \a c attributes, from \a attr, at the given screen map \a place
112 #define set_char_attr(c,attr,place) msx_set_char_attr(c,attr,place)
113 
114 /// set char \a c with \a color, at the given screen map \a place
115 #define set_char_color(c,color,place) msx_set_char_color(c,color,place)
116 
117 // set char \a c shape, attributes and color, all in one
118 #define set_char(c,form,attr,color,place) msx_set_char(c,form,attr,color,place)
119 
120 //@}
121 
122 
123 /// @name Sprites
124 //@{
125 
126 
127 /// set the sprite \a mode
128 #define set_sprite_mode(mode) msx_set_sprite_mode(mode)
129 
130 /*
131 // this is not compiling... I suggest some #define's instead
132 
133 extern void *set_sprite(unsigned char, void*);
134 extern void *put_sprite(unsigned char, int, int, unsigned char, unsigned char);
135 */
136 
137 /// set the sprite \a handle, with the shape from \a data (small size)
138 #define set_sprite_8(handle,data) msx_set_sprite_8(handle,data)
139 
140 
141 /// set the sprite \a handle, with the shape from \a data (big size)
142 #define set_sprite_16(handle,data) msx_set_sprite_16(handle,data)
143 
144 /// put the sprite with \a id and shape from \a handle, into the given position with \a color (small size)
145 #define put_sprite_8(id,x,y,handle,color) msx_put_sprite_8(id,x,y,handle,color)
146 
147 /// put the sprite with \a id and shape from \a handle, into the given position with \a color (big size)
148 #define put_sprite_16(id,x,y,handle,color) msx_put_sprite_16(id,x,y,handle,color)
149 
150 //@}
151 
152 
153 // surface
154 // FIXME: this is not usable right now
155 
156 #define blit(source,dest,from,to) msx_blit(source,dest,from,to)
157 #define blit_ram_vram(source,dest,w,h,sjmp,djmp) msx_blit_ram_vram(source,dest,w,h,sjmp,djmp)
158 #define blit_fill_vram(dest,value,w,h,djmp) msx_blit_fill_vram(dest,value,w,h,djmp)
159 
160 
161 /// @name Controllers
162 //@{
163 
164 /// get state of joystick number \a id
165 #define get_stick(x) msx_get_stick(x)
166 
167 // get state of joystick button (trigger) number \a id, true = pressed
168 #define get_trigger(x) msx_get_trigger(x)
169 
170 //@}
171 
172 
173 /// @name Random
174 /// Fast and dirty pseudo-random number generator
175 //@{
176 
177 /// seed the pseudo-random number generator
178 #define seed_rnd(seed) srand(seed)
179 
180 /// get the next number from the pseudo-random number generator
181 #define get_rnd() rand()
182 
183 //@}
184 
185 
186 // alias for setting psg registers (for the BASIC fans)
187 #define sound(reg, value) set_psg(reg, value)
188 
189 // set a psg register with a \a value
190 #define psg_set(reg, value) set_psg(reg, value)
191 
192 // get value from psg register
193 #define psg_get(reg) get_psg(reg)
194 
195 
196 #endif
197 
198