1 // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
2 // Copyright (C) 1999-2003 Forgotten
3 // Copyright (C) 2004 Forgotten and the VBA development team
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2, or(at your option)
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 void mode0RenderLine()
25 u16
*palette
= (u16
*)paletteRAM
;
28 for(int x
= 0; x
< 240; x
++) {
34 if(layerEnable
& 0x0100) {
35 gfxDrawTextScreen(BG0CNT
, BG0HOFS
, BG0VOFS
, line0
);
38 if(layerEnable
& 0x0200) {
39 gfxDrawTextScreen(BG1CNT
, BG1HOFS
, BG1VOFS
, line1
);
42 if(layerEnable
& 0x0400) {
43 gfxDrawTextScreen(BG2CNT
, BG2HOFS
, BG2VOFS
, line2
);
46 if(layerEnable
& 0x0800) {
47 gfxDrawTextScreen(BG3CNT
, BG3HOFS
, BG3VOFS
, line3
);
50 gfxDrawSprites(lineOBJ
);
52 u32 backdrop
= (READ16LE(&palette
[0]) | 0x30000000);
54 for(int x
= 0; x
< 240; x
++) {
58 if(line0
[x
] < color
) {
63 if((u8
)(line1
[x
]>>24) < (u8
)(color
>> 24)) {
68 if((u8
)(line2
[x
]>>24) < (u8
)(color
>> 24)) {
73 if((u8
)(line3
[x
]>>24) < (u8
)(color
>> 24)) {
78 if((u8
)(lineOBJ
[x
]>>24) < (u8
)(color
>> 24)) {
83 if((top
& 0x10) && (color
& 0x00010000)) {
84 // semi-transparent OBJ
88 if((u8
)(line0
[x
]>>24) < (u8
)(back
>> 24)) {
93 if((u8
)(line1
[x
]>>24) < (u8
)(back
>> 24)) {
98 if((u8
)(line2
[x
]>>24) < (u8
)(back
>> 24)) {
103 if((u8
)(line3
[x
]>>24) < (u8
)(back
>> 24)) {
108 if(top2
& (BLDMOD
>>8))
109 color
= gfxAlphaBlend(color
, back
,
111 coeff
[(COLEV
>> 8) & 0x1F]);
113 switch((BLDMOD
>> 6) & 3) {
116 color
= gfxIncreaseBrightness(color
, coeff
[COLY
& 0x1F]);
120 color
= gfxDecreaseBrightness(color
, coeff
[COLY
& 0x1F]);
130 void mode0RenderLineNoWindow()
132 u16
*palette
= (u16
*)paletteRAM
;
135 for(int x
= 0; x
< 240; x
++) {
141 if(layerEnable
& 0x0100) {
142 gfxDrawTextScreen(BG0CNT
, BG0HOFS
, BG0VOFS
, line0
);
145 if(layerEnable
& 0x0200) {
146 gfxDrawTextScreen(BG1CNT
, BG1HOFS
, BG1VOFS
, line1
);
149 if(layerEnable
& 0x0400) {
150 gfxDrawTextScreen(BG2CNT
, BG2HOFS
, BG2VOFS
, line2
);
153 if(layerEnable
& 0x0800) {
154 gfxDrawTextScreen(BG3CNT
, BG3HOFS
, BG3VOFS
, line3
);
157 gfxDrawSprites(lineOBJ
);
159 u32 backdrop
= (READ16LE(&palette
[0]) | 0x30000000);
161 int effect
= (BLDMOD
>> 6) & 3;
163 for(int x
= 0; x
< 240; x
++) {
164 u32 color
= backdrop
;
167 if(line0
[x
] < color
) {
172 if(line1
[x
] < (color
& 0xFF000000)) {
177 if(line2
[x
] < (color
& 0xFF000000)) {
182 if(line3
[x
] < (color
& 0xFF000000)) {
187 if(lineOBJ
[x
] < (color
& 0xFF000000)) {
192 if(!(color
& 0x00010000)) {
201 if(line0
[x
] < back
) {
208 if(line1
[x
] < (back
& 0xFF000000)) {
215 if(line2
[x
] < (back
& 0xFF000000)) {
222 if(line3
[x
] < (back
& 0xFF000000)) {
229 if(lineOBJ
[x
] < (back
& 0xFF000000)) {
236 if(top2
& (BLDMOD
>>8))
237 color
= gfxAlphaBlend(color
, back
,
239 coeff
[(COLEV
>> 8) & 0x1F]);
246 color
= gfxIncreaseBrightness(color
, coeff
[COLY
& 0x1F]);
250 color
= gfxDecreaseBrightness(color
, coeff
[COLY
& 0x1F]);
254 // semi-transparent OBJ
258 if(line0
[x
] < back
) {
263 if(line1
[x
] < (back
& 0xFF000000)) {
268 if(line2
[x
] < (back
& 0xFF000000)) {
273 if(line3
[x
] < (back
& 0xFF000000)) {
278 if(top2
& (BLDMOD
>>8))
279 color
= gfxAlphaBlend(color
, back
,
281 coeff
[(COLEV
>> 8) & 0x1F]);
283 switch((BLDMOD
>> 6) & 3) {
286 color
= gfxIncreaseBrightness(color
, coeff
[COLY
& 0x1F]);
290 color
= gfxDecreaseBrightness(color
, coeff
[COLY
& 0x1F]);
300 void mode0RenderLineAll()
302 u16
*palette
= (u16
*)paletteRAM
;
305 for(int x
= 0; x
< 240; x
++) {
311 bool inWindow0
= false;
312 bool inWindow1
= false;
314 if(layerEnable
& 0x2000) {
317 inWindow0
= ((v0
== v1
) && (v0
>= 0xe8));
319 inWindow0
|= (VCOUNT
>= v0
&& VCOUNT
< v1
);
321 inWindow0
|= (VCOUNT
>= v0
|| VCOUNT
< v1
);
323 if(layerEnable
& 0x4000) {
326 inWindow1
= ((v0
== v1
) && (v0
>= 0xe8));
328 inWindow1
|= (VCOUNT
>= v0
&& VCOUNT
< v1
);
330 inWindow1
|= (VCOUNT
>= v0
|| VCOUNT
< v1
);
333 if((layerEnable
& 0x0100)) {
334 gfxDrawTextScreen(BG0CNT
, BG0HOFS
, BG0VOFS
, line0
);
337 if((layerEnable
& 0x0200)) {
338 gfxDrawTextScreen(BG1CNT
, BG1HOFS
, BG1VOFS
, line1
);
341 if((layerEnable
& 0x0400)) {
342 gfxDrawTextScreen(BG2CNT
, BG2HOFS
, BG2VOFS
, line2
);
345 if((layerEnable
& 0x0800)) {
346 gfxDrawTextScreen(BG3CNT
, BG3HOFS
, BG3VOFS
, line3
);
349 gfxDrawSprites(lineOBJ
);
350 gfxDrawOBJWin(lineOBJWin
);
352 u32 backdrop
= (READ16LE(&palette
[0]) | 0x30000000);
354 u8 inWin0Mask
= WININ
& 0xFF;
355 u8 inWin1Mask
= WININ
>> 8;
356 u8 outMask
= WINOUT
& 0xFF;
358 for(int x
= 0; x
< 240; x
++) {
359 u32 color
= backdrop
;
363 if(!(lineOBJWin
[x
] & 0x80000000)) {
378 if((mask
& 1) && (line0
[x
] < color
)) {
383 if((mask
& 2) && ((u8
)(line1
[x
]>>24) < (u8
)(color
>> 24))) {
388 if((mask
& 4) && ((u8
)(line2
[x
]>>24) < (u8
)(color
>> 24))) {
393 if((mask
& 8) && ((u8
)(line3
[x
]>>24) < (u8
)(color
>> 24))) {
398 if((mask
& 16) && ((u8
)(lineOBJ
[x
]>>24) < (u8
)(color
>> 24))) {
403 // special FX on in the window
405 if(!(color
& 0x00010000)) {
406 switch((BLDMOD
>> 6) & 3) {
414 if((mask
& 1) && (u8
)(line0
[x
]>>24) < (u8
)(back
>> 24)) {
421 if((mask
& 2) && (u8
)(line1
[x
]>>24) < (u8
)(back
>> 24)) {
428 if((mask
& 4) && (u8
)(line2
[x
]>>24) < (u8
)(back
>> 24)) {
435 if((mask
& 8) && (u8
)(line3
[x
]>>24) < (u8
)(back
>> 24)) {
442 if((mask
& 16) && (u8
)(lineOBJ
[x
]>>24) < (u8
)(back
>> 24)) {
449 if(top2
& (BLDMOD
>>8))
450 color
= gfxAlphaBlend(color
, back
,
452 coeff
[(COLEV
>> 8) & 0x1F]);
458 color
= gfxIncreaseBrightness(color
, coeff
[COLY
& 0x1F]);
462 color
= gfxDecreaseBrightness(color
, coeff
[COLY
& 0x1F]);
466 // semi-transparent OBJ
470 if((mask
& 1) && ((u8
)(line0
[x
]>>24) < (u8
)(back
>> 24))) {
475 if((mask
& 2) && ((u8
)(line1
[x
]>>24) < (u8
)(back
>> 24))) {
480 if((mask
& 4) && ((u8
)(line2
[x
]>>24) < (u8
)(back
>> 24))) {
485 if((mask
& 8) && ((u8
)(line3
[x
]>>24) < (u8
)(back
>> 24))) {
490 if(top2
& (BLDMOD
>>8))
491 color
= gfxAlphaBlend(color
, back
,
493 coeff
[(COLEV
>> 8) & 0x1F]);
495 switch((BLDMOD
>> 6) & 3) {
498 color
= gfxIncreaseBrightness(color
, coeff
[COLY
& 0x1F]);
502 color
= gfxDecreaseBrightness(color
, coeff
[COLY
& 0x1F]);
507 } else if(color
& 0x00010000) {
508 // semi-transparent OBJ
512 if((mask
& 1) && ((u8
)(line0
[x
]>>24) < (u8
)(back
>> 24))) {
517 if((mask
& 2) && ((u8
)(line1
[x
]>>24) < (u8
)(back
>> 24))) {
522 if((mask
& 4) && ((u8
)(line2
[x
]>>24) < (u8
)(back
>> 24))) {
527 if((mask
& 8) && ((u8
)(line3
[x
]>>24) < (u8
)(back
>> 24))) {
532 if(top2
& (BLDMOD
>>8))
533 color
= gfxAlphaBlend(color
, back
,
535 coeff
[(COLEV
>> 8) & 0x1F]);
537 switch((BLDMOD
>> 6) & 3) {
540 color
= gfxIncreaseBrightness(color
, coeff
[COLY
& 0x1F]);
544 color
= gfxDecreaseBrightness(color
, coeff
[COLY
& 0x1F]);