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 mode3RenderLine()
25 u16
*palette
= (u16
*)paletteRAM
;
28 for(int x
= 0; x
< 240; x
++) {
31 gfxLastVCOUNT
= VCOUNT
;
35 if(layerEnable
& 0x0400) {
36 int changed
= gfxBG2Changed
;
38 if(gfxLastVCOUNT
> VCOUNT
)
41 gfxDrawRotScreen16Bit(BG2CNT
, BG2X_L
, BG2X_H
,
42 BG2Y_L
, BG2Y_H
, BG2PA
, BG2PB
,
44 gfxBG2X
, gfxBG2Y
, changed
,
48 gfxDrawSprites(lineOBJ
);
50 u32 background
= (READ16LE(&palette
[0]) | 0x30000000);
52 for(int x
= 0; x
< 240; x
++) {
53 u32 color
= background
;
56 if(line2
[x
] < color
) {
61 if((u8
)(lineOBJ
[x
]>>24) < (u8
)(color
>>24)) {
66 if((top
& 0x10) && (color
& 0x00010000)) {
67 // semi-transparent OBJ
68 u32 back
= background
;
76 if(top2
& (BLDMOD
>>8))
77 color
= gfxAlphaBlend(color
, back
,
79 coeff
[(COLEV
>> 8) & 0x1F]);
81 switch((BLDMOD
>> 6) & 3) {
84 color
= gfxIncreaseBrightness(color
, coeff
[COLY
& 0x1F]);
88 color
= gfxDecreaseBrightness(color
, coeff
[COLY
& 0x1F]);
97 gfxLastVCOUNT
= VCOUNT
;
100 void mode3RenderLineNoWindow()
102 u16
*palette
= (u16
*)paletteRAM
;
105 for(int x
= 0; x
< 240; x
++) {
108 gfxLastVCOUNT
= VCOUNT
;
112 if(layerEnable
& 0x0400) {
113 int changed
= gfxBG2Changed
;
115 if(gfxLastVCOUNT
> VCOUNT
)
118 gfxDrawRotScreen16Bit(BG2CNT
, BG2X_L
, BG2X_H
,
119 BG2Y_L
, BG2Y_H
, BG2PA
, BG2PB
,
121 gfxBG2X
, gfxBG2Y
, changed
,
125 gfxDrawSprites(lineOBJ
);
127 u32 background
= (READ16LE(&palette
[0]) | 0x30000000);
129 for(int x
= 0; x
< 240; x
++) {
130 u32 color
= background
;
133 if(line2
[x
] < color
) {
138 if((u8
)(lineOBJ
[x
]>>24) < (u8
)(color
>>24)) {
143 if(!(color
& 0x00010000)) {
144 switch((BLDMOD
>> 6) & 3) {
150 u32 back
= background
;
153 if(line2
[x
] < back
) {
160 if((u8
)(lineOBJ
[x
]>>24) < (u8
)(back
>> 24)) {
167 if(top2
& (BLDMOD
>>8))
168 color
= gfxAlphaBlend(color
, back
,
170 coeff
[(COLEV
>> 8) & 0x1F]);
177 color
= gfxIncreaseBrightness(color
, coeff
[COLY
& 0x1F]);
181 color
= gfxDecreaseBrightness(color
, coeff
[COLY
& 0x1F]);
185 // semi-transparent OBJ
186 u32 back
= background
;
189 if(line2
[x
] < back
) {
194 if(top2
& (BLDMOD
>>8))
195 color
= gfxAlphaBlend(color
, back
,
197 coeff
[(COLEV
>> 8) & 0x1F]);
199 switch((BLDMOD
>> 6) & 3) {
202 color
= gfxIncreaseBrightness(color
, coeff
[COLY
& 0x1F]);
206 color
= gfxDecreaseBrightness(color
, coeff
[COLY
& 0x1F]);
215 gfxLastVCOUNT
= VCOUNT
;
218 void mode3RenderLineAll()
220 u16
*palette
= (u16
*)paletteRAM
;
223 for(int x
= 0; x
< 240; x
++) {
226 gfxLastVCOUNT
= VCOUNT
;
230 bool inWindow0
= false;
231 bool inWindow1
= false;
233 if(layerEnable
& 0x2000) {
236 inWindow0
= ((v0
== v1
) && (v0
>= 0xe8));
238 inWindow0
|= (VCOUNT
>= v0
&& VCOUNT
< v1
);
240 inWindow0
|= (VCOUNT
>= v0
|| VCOUNT
< v1
);
242 if(layerEnable
& 0x4000) {
245 inWindow1
= ((v0
== v1
) && (v0
>= 0xe8));
247 inWindow1
|= (VCOUNT
>= v0
&& VCOUNT
< v1
);
249 inWindow1
|= (VCOUNT
>= v0
|| VCOUNT
< v1
);
252 if(layerEnable
& 0x0400) {
253 int changed
= gfxBG2Changed
;
255 if(gfxLastVCOUNT
> VCOUNT
)
258 gfxDrawRotScreen16Bit(BG2CNT
, BG2X_L
, BG2X_H
,
259 BG2Y_L
, BG2Y_H
, BG2PA
, BG2PB
,
261 gfxBG2X
, gfxBG2Y
, changed
,
265 gfxDrawSprites(lineOBJ
);
266 gfxDrawOBJWin(lineOBJWin
);
268 u8 inWin0Mask
= WININ
& 0xFF;
269 u8 inWin1Mask
= WININ
>> 8;
270 u8 outMask
= WINOUT
& 0xFF;
272 u32 background
= (READ16LE(&palette
[0]) | 0x30000000);
274 for(int x
= 0; x
< 240; x
++) {
275 u32 color
= background
;
279 if(!(lineOBJWin
[x
] & 0x80000000)) {
294 if((mask
& 4) && (line2
[x
] < color
)) {
299 if((mask
& 16) && ((u8
)(lineOBJ
[x
]>>24) < (u8
)(color
>>24))) {
305 if(!(color
& 0x00010000)) {
306 switch((BLDMOD
>> 6) & 3) {
312 u32 back
= background
;
315 if((mask
& 4) && line2
[x
] < back
) {
322 if((mask
& 16) && (u8
)(lineOBJ
[x
]>>24) < (u8
)(back
>> 24)) {
329 if(top2
& (BLDMOD
>>8))
330 color
= gfxAlphaBlend(color
, back
,
332 coeff
[(COLEV
>> 8) & 0x1F]);
339 color
= gfxIncreaseBrightness(color
, coeff
[COLY
& 0x1F]);
343 color
= gfxDecreaseBrightness(color
, coeff
[COLY
& 0x1F]);
347 // semi-transparent OBJ
348 u32 back
= background
;
351 if((mask
& 4) && line2
[x
] < back
) {
356 if(top2
& (BLDMOD
>>8))
357 color
= gfxAlphaBlend(color
, back
,
359 coeff
[(COLEV
>> 8) & 0x1F]);
361 switch((BLDMOD
>> 6) & 3) {
364 color
= gfxIncreaseBrightness(color
, coeff
[COLY
& 0x1F]);
368 color
= gfxDecreaseBrightness(color
, coeff
[COLY
& 0x1F]);
373 } else if(color
& 0x00010000) {
374 // semi-transparent OBJ
375 u32 back
= background
;
378 if((mask
& 4) && line2
[x
] < back
) {
383 if(top2
& (BLDMOD
>>8))
384 color
= gfxAlphaBlend(color
, back
,
386 coeff
[(COLEV
>> 8) & 0x1F]);
388 switch((BLDMOD
>> 6) & 3) {
391 color
= gfxIncreaseBrightness(color
, coeff
[COLY
& 0x1F]);
395 color
= gfxDecreaseBrightness(color
, coeff
[COLY
& 0x1F]);
404 gfxLastVCOUNT
= VCOUNT
;