SCREEN.H
[目次 | 型・クラス・構造体 | マクロ]
1|/************************************************************************
2|* 1. <<< 画面・ワーク画面 (Screen) >>>
3|*************************************************************************/
4|
5|#ifndef __SCREEN_H
6|#define __SCREEN_H
7|
8|/*----------------------------------------------------------------------
9|[Module Property]
10|name = Screen
11|title = 画面・ワーク画面
12|category = グラフィック
13|src = screen.c
14|depend =
15|priority =
16|accord =
17|----------------------------------------------------------------------*/
18|
19|#ifndef USES_PRIORITY_HEADER
20|/*[START_OF_PRIORITY_HEADER]*/
21|
22|#ifndef USES_SCREEN
23|#define USES_SCREEN
24|
25|typedef struct _Screen Screen;
26|typedef struct _Screen_Sw Screen_Sw;
27|
28|#endif
29|
30|/*[END_OF_PRIORITY_HEADER]*/
31|#endif /* USES_PRIORITY_HEADER */
32|
33|
34|/*-------------------------------------------------------------------*/
35|/* 2. <<< Interface Area ------------------------------------------ >>> */
36|/*-------------------------------------------------------------------*/
37|
38|#ifdef __cplusplus
39|extern "C" {
40|#endif
41|
42|/************************************************************************
43|* 3. <<< 画面 [Screen] >>>
44|*【補足】
45|*・座標は (0,0)-(width-1+_pixelParByte, height) のように x が補正されます
46|*************************************************************************/
47|struct _Screen {
48| char* adr; /* フレームバッファの先頭アドレス */
49| int width; int height;
50|
51| int offsetX; int offsetY; /* オフセット */
52|
53| int clipX; int clipY; /* クリッピング領域の左上座標 */
54| int clipWidth; int clipHeight; /* クリッピング領域のサイズ */
55|};
56|
57|/*** 属性 ***/
58|void Screen_setOffset( Screen*, int x, int y );
59|int Screen_getOffsetX( Screen* ); /* オフセット X */
60|int Screen_getOffsetY( Screen* ); /* オフセット Y */
61|void Screen_setClip( Screen*, int x, int y, int w, int h );
62|void Screen_clearClip( Screen* );
63|
64|/*** 基本設定 ***/
65|void Screen_init( Screen*, void* adr, int width, int height );
66|int Screen_getNeedMemSize( int width, int height );
67|void Screen_clear( Screen*, int color );
68|char* Screen_pgetAdr( Screen*, int x, int y );
69|u_long Screen_getExAdr( Screen*, int x, int y );
70|u_long Screen_getExVector( Screen*, int dx, int dy );
71|void Screen_getExVectors( Screen*, int dir, u_long* plus0, u_long* plus1 );
72|unsigned int* Screen_pgetAdr_byExAdr( Screen*, u_long exAdr );
73|unsigned int Screen_getBit_byExAdr( Screen*, u_long exAdr, int color );
74|
75|/*** 描画操作 ***/
76|void Screen_pset( Screen*, int x, int y, int color );
77|int Screen_pget( Screen*, int x, int y );
78|void Screen_psetXor( Screen*, int x, int y, int color );
79|void Screen_psets( Screen*, int x, int y, unsigned char* pattern,
80| int nPixel, int color );
81|void Screen_exPset( Screen*, u_long exAdr, int color );
82|void Screen_line( Screen*, int x1, int y1, int x2, int y2, int color );
83|void Screen_line2( Screen*, int x1, int y1, int x2, int y2, int color );
84|void Screen_loseLine( Screen*, int x1, int y1, int x2, int y2,
85| int color, int pattern, int pattern_n );
86|void Screen_boldLine( Screen*, int x1, int y1, int x2, int y2,
87| int color, int width );
88|void Screen_rectFill2( Screen*, int x1, int y1, int x2, int y2,
89| int color );
90|void Screen_xorPaint( Screen* );
91|#ifdef USES_MASK
92|void Screen_xorPartPaintFlushToScreen( Screen*, Screen* dec,
93| Mask_A* mask, int baseX, int baseY,
94| int x1, int y1, int x2, int y2 );
95|#endif
96|#ifdef USES_MMPAINT
97|void Screen_paintByMMPaint( Screen*, MMPaint* paint, int color );
98|#endif
99|
100|/*** 画面コピー ***/
101|#ifdef USES_RECT
102|#ifdef USES_MASK
103|#ifdef USES_DRAWSCR
104|void Screen_flushTo( Screen*, DrawScr target );
105|void Screen_flushTo2( Screen*, DrawScr target, Mask_A* mask,
106| int baseX, int baseY );
107|#endif /* USES_DRAWSCR */
108|void Screen_flushFromScreen( Screen*, Screen* work );
109|void Screen_flushFromScreen2( Screen*, Screen* work, Mask_A* mask,
110| int baseX, int baseY );
111|void Screen_orFlushFromScreen( Screen*, Screen* work, Mask_A* mask,
112| int baseX, int baseY );
113|#endif /* USES_MASK */
114|#endif /* USES_RECT */
115|
116|#ifdef USES_DSCREEN
117|#ifdef USES_RECT
118|void Screen_flushFromDScreen( Screen*, DScreen* work );
119|void Screen_flushFromDScreen2( Screen*, DScreen* work, Mask_A* mask,
120| int baseX, int baseY );
121|#endif /* USES_RECT */
122|void Screen_flushFromPartDScreen( Screen* to, DScreen* from,
123| Mask_A* mask, int baseX, int baseY );
124|#endif /* USES_DSCREEN */
125|
126|void Screen_outBmp( Screen*, char* buf, int width, int height,
127| int bpp, unsigned int* palette );
128|
129|/*** インターフェイス ***/
130|#ifdef USES_DRAWSCR
131|DrawScr Screen_inf_DrawScr( Screen* );
132|Screen* Screen_by_DrawScr( DrawScr inf );
133|int Screen_getWidthX( Screen* );
134|int Screen_getHeightX( Screen* );
135|#endif
136|#ifdef USES_STDLIB
137|void Screen_print( Screen*, FILE* file );
138|#endif
139|
140|
141|/**************************************************************************
142|* 4. <<< 裏画面スイッチ [Screen_Sw] >>>
143|*【役割】
144|*・2つの VRAM を用意し、描画対象の VRAM と表示させる VRAM を高速に切り
145|* 替えることによって、描画中のちらつきを無くします。
146|***************************************************************************/
147|struct _Screen_Sw {
148| Screen* front; /* 見えている画面 */
149| Screen* back; /* 描画対象画面 */
150|};
151|
152|Screen* Screen_Sw_init( Screen_Sw*, Screen* front, Screen* back );
153|void* Screen_Sw_getVisiAdr( Screen_Sw* );
154|void* Screen_Sw_swap( Screen_Sw* );
155|
156|#ifdef __cplusplus
157|}
158|#endif
159|
160|/*-------------------------------------------------------------------*/
161|/* 5. <<< Mapping Area -------------------------------------------- >>> */
162|/*-------------------------------------------------------------------*/
163|
164|/*-------------------------------------------------------------------*/
165|/*
166|* Screen インターフェイス・マッピング
167|*/
168|#define Screen_getAdr(this) ((Screen*)(this))->adr
169|#define Screen_getWidth(this) ((Screen*)(this))->width
170|#define Screen_getHeight(this) ((Screen*)(this))->height
171|#define Screen_getPixelPerByte(this) 2 /* 1バイトあたりのピクセル数 */
172|#define Screen_getBitPerPixel(this) ( 8 / Screen_getPixelPerByte(this) )
173| /* 1ピクセルあたりのビット数 */
174|#define Screen_pgetAdr( this,x, y ) \
175| ( Screen_getAdr(this) + ( Screen_getWidth(this) * (y) + (x) ) / \
176| Screen_getPixelPerByte(this) ) /* x,y の点の位置のアドレス */
177|#define Screen_getOffsetX(this) ((Screen*)(this))->offsetX
178|#define Screen_getOffsetY(this) ((Screen*)(this))->offsetY
179|#define Screen_setOffset(this, x, y ) \
180| { Screen_getOffsetX(this) = (x); Screen_getOffsetY(this) = (y); }
181|#ifdef USES_RECT
182|#define Screen_flushTo( this, target ) \
183| Screen_flushTo2( this, target, NULL, 0, 0, 0 )
184|#define Screen_flushFromScreen( this, target ) \
185| Screen_flushFromScreen2( this, target, NULL, 0, 0 )
186|#ifdef USES_DSCREEN
187|#define Screen_flushFromDScreen( this, target ) \
188| Screen_flushFromDScreen2( this, target, NULL, 0, 0 )
189|#endif /* USES_DSCREEN */
190|#endif /* USES_RECT */
191|
192|
193|/*********************************************************************
194|* 6. <<< [Screen_getNeedMemSize] バッファに必要なメモリサイズ(byte)を返す >>>
195|*【引数】
196|* ・int width, height; フレームバッファのサイズ
197|*********************************************************************/
198|#define Screen_getNeedMemSize( width, height ) \
199| ( ((width) * (height) + 1) / 2 )
200|
201|
202|/*************************************************************************
203|* 7. <<< 拡張座標値を取得する [Screen_getExAdr2()] >>>
204|*【補足】
205|*・マクロ版です。
206|*・「拡張座標値」は、ベクトルの和とピクセル描画が高速になるように最適化
207|* された x,y 座標値です。ベクトルの和は、隣接するピクセルを計算するときに
208|* 用いられます。
209|*・拡張座標値は、1つの int 型から構成され、
210|* 第5ビット以上が、アドレス部、第4ビット以下が、ビット番号部です。
211|*・4bpp * 8pixels 用です(32bit = [0123|4567|89AB|CDEF|0123|4567|89AB|CDEF])
212|**************************************************************************/
213|#define Screen_getExAdr2( this, x, y ) \
214|( \
215| ( ((((u_long)(int)Screen_pgetAdr( this, x, y )) - \
216| ((u_long)(int)(this)->adr) \
217| ) & 0xFFFFFFFC) << 3 ) | ( (u_long)((x) & 0x7) << 2 ) \
218|)
219|
220|
221|/*************************************************************************
222|* 8. <<< 拡張ベクトル値を取得する [Screen_getExVector2()] >>>
223|*【引数】
224|* ・u_long dx, dy; ベクトルの x,y 成分
225|*【補足】
226|*・マクロ版です。
227|*・「拡張ベクトル値」は、次のような性質があります。
228|* (x,y)=(100,100) の拡張座標値に、(dx,dy)=(1,-1)の拡張ベクトル値を足すと、
229|* (x,y)=(101,99) の拡張座標値を返します。
230|**************************************************************************/
231|#define Screen_getExVector2 Screen_getExAdr2
232|
233|
234|/*************************************************************************
235|* 9. <<< Draw_line2 用の拡張ベクトル値を取得する [Screen_getExVectors2()] >>>
236|*【引数】
237|* ・int dir; 方向番号
238|* ・u_long plus0; 水平 or 垂直の拡張ベクトル値(出力)
239|* ・u_long plus1; ななめの拡張ベクトル値(出力)
240|*【補足】
241|*・マクロ版です。
242|*・plus0, plus1 には、変数名を指定してください。するとその変数に
243|* 出力データが格納されます。
244|*・方向番号は Draw_getDirec 関数から取得できます。
245|**************************************************************************/
246|#define Screen_getExVectors2( this, dir, plus0, plus1 ) \
247|{ \
248| const int dxy[] =\
249| { 1,0, 1,-1, 1,0, 1, 1, 0, 1, 1, 1, 0, 1,-1, 1,\
250| -1,0,-1, 1, -1,0,-1,-1, 0,-1,-1,-1, 0,-1, 1,-1 };\
251|\
252| (dir) <<= 2; /* dir *= 4 */\
253| plus0 = Screen_getExVector2( this, dxy[dir], dxy[(dir)+1] );\
254| plus1 = Screen_getExVector2( this, dxy[(dir)+2], dxy[(dir)+3] );\
255|}
256|
257|
258|/*************************************************************************
259|* 10. <<< 拡張座標値から画面のアドレスを取得する [Screen_pgetAdr_byExAdr()] >>>
260|*【補足】
261|*・Screen_pgetAdr の拡張座標版です。
262|**************************************************************************/
263|#define Screen_pgetAdr_byExAdr( this, exAdr ) \
264| ( (u_long*) ((char*)(this)->adr + (int)( ((exAdr) >> 3) & 0xFFFFFFFC )) )
265|
266|
267|/*************************************************************************
268|* 11. <<< 拡張座標値からビットパターンを取得する [Screen_getBit_byExAdr()] >>>
269|*【引数】
270|* ・int color; 色番号
271|*【補足】
272|*・color を 0xF にして、該当する座標のマスク・パターンを取得できます。
273|*【例】
274|*・(x,y)=(1,0) の拡張座標値を用いて color = 0xC を指定した場合、
275|* 返り値は 0x000000C0 になります。
276|**************************************************************************/
277|#define Screen_getBit_byExAdr( this, exAdr, color ) \
278| ( (u_long)(color) << ((exAdr) & 0x1C) )
279|
280|
281|/*************************************************************************
282|* 12. <<< 点を描画する(拡張座標値版)[Screen_exPset2()] >>>
283|*【補足】
284|*・マクロ版です。
285|*・拡張座標値を用いることにより高速に描画します。
286|*・オフセットとクリッピング領域は、無視されます。
287|**************************************************************************/
288|#define Screen_exPset2( this, exAdr, color ) \
289|{ \
290| u_long* adr = Screen_pgetAdr_byExAdr( this, exAdr ); \
291|\
292| *adr &= ~Screen_getBit_byExAdr( this, exAdr, 0xF ); \
293| *adr |= Screen_getBit_byExAdr( this, exAdr, color ); \
294|}
295|
296|
297|/**************************************************************************
298|* 13. <<< 現在表示されている VRAM のアドレスを返す [Screen_Sw_getVisiAdr()] >>>
299|***************************************************************************/
300|#define Screen_Sw_getVisiAdr( this ) ((this)->front->adr)
301|
302|
303|#endif /* __SCREEN_H */
304|
305|