| 1 |
#ifdef PPU_CPP |
| 2 |
|
| 3 |
inline uint16 PPU::get_palette(uint8 index) { |
| 4 |
const unsigned addr = index << 1; |
| 5 |
return cgram[addr] + (cgram[addr + 1] << 8); |
| 6 |
} |
| 7 |
|
| 8 |
//p = 00000bgr <palette data> |
| 9 |
//t = BBGGGRRR <tilemap data> |
| 10 |
//r = 0BBb00GGGg0RRRr0 <return data> |
| 11 |
inline uint16 PPU::get_direct_color(uint8 p, uint8 t) { |
| 12 |
return ((t & 7) << 2) | ((p & 1) << 1) | |
| 13 |
(((t >> 3) & 7) << 7) | (((p >> 1) & 1) << 6) | |
| 14 |
((t >> 6) << 13) | ((p >> 2) << 12); |
| 15 |
} |
| 16 |
|
| 17 |
inline uint16 PPU::get_pixel_normal(uint32 x) { |
| 18 |
pixel_t& p = pixel_cache[x]; |
| 19 |
uint16 src_main, src_sub; |
| 20 |
uint8 bg_sub; |
| 21 |
|
| 22 |
src_main = p.src_main; |
| 23 |
|
| 24 |
if(!regs.addsub_mode) { |
| 25 |
bg_sub = BACK; |
| 26 |
src_sub = regs.color_rgb; |
| 27 |
} else { |
| 28 |
bg_sub = p.bg_sub; |
| 29 |
src_sub = p.src_sub; |
| 30 |
} |
| 31 |
|
| 32 |
if(!window[COL].main[x]) { |
| 33 |
if(!window[COL].sub[x]) { |
| 34 |
return 0x0000; |
| 35 |
} |
| 36 |
src_main = 0x0000; |
| 37 |
} |
| 38 |
|
| 39 |
if(!p.ce_main && regs.color_enabled[p.bg_main] && window[COL].sub[x]) { |
| 40 |
bool halve = false; |
| 41 |
if(regs.color_halve && window[COL].main[x]) { |
| 42 |
if(regs.addsub_mode && bg_sub == BACK); |
| 43 |
else { |
| 44 |
halve = true; |
| 45 |
} |
| 46 |
} |
| 47 |
return addsub(src_main, src_sub, halve); |
| 48 |
} |
| 49 |
|
| 50 |
return src_main; |
| 51 |
} |
| 52 |
|
| 53 |
inline uint16 PPU::get_pixel_swap(uint32 x) { |
| 54 |
pixel_t& p = pixel_cache[x]; |
| 55 |
uint16 src_main, src_sub; |
| 56 |
uint8 bg_sub; |
| 57 |
|
| 58 |
src_main = p.src_sub; |
| 59 |
|
| 60 |
if(!regs.addsub_mode) { |
| 61 |
bg_sub = BACK; |
| 62 |
src_sub = regs.color_rgb; |
| 63 |
} else { |
| 64 |
bg_sub = p.bg_main; |
| 65 |
src_sub = p.src_main; |
| 66 |
} |
| 67 |
|
| 68 |
if(!window[COL].main[x]) { |
| 69 |
if(!window[COL].sub[x]) { |
| 70 |
return 0x0000; |
| 71 |
} |
| 72 |
src_main = 0x0000; |
| 73 |
} |
| 74 |
|
| 75 |
if(!p.ce_sub && regs.color_enabled[p.bg_sub] && window[COL].sub[x]) { |
| 76 |
bool halve = false; |
| 77 |
if(regs.color_halve && window[COL].main[x]) { |
| 78 |
if(regs.addsub_mode && bg_sub == BACK); |
| 79 |
else { |
| 80 |
halve = true; |
| 81 |
} |
| 82 |
} |
| 83 |
return addsub(src_main, src_sub, halve); |
| 84 |
} |
| 85 |
|
| 86 |
return src_main; |
| 87 |
} |
| 88 |
|
| 89 |
inline void PPU::render_line_output() { |
| 90 |
uint32* ptr = (uint32*)output + (line * 1024) + ((interlace() && field()) ? 512 : 0); |
| 91 |
uint32 curr, prev; |
| 92 |
|
| 93 |
if(!regs.pseudo_hires && regs.bg_mode != 5 && regs.bg_mode != 6) { |
| 94 |
for(unsigned x = 0; x < 256; x++) { |
| 95 |
curr = (regs.display_brightness << 15) | get_pixel_normal(x); |
| 96 |
*ptr++ = curr; |
| 97 |
} |
| 98 |
} else { |
| 99 |
for(unsigned x = 0, prev = 0; x < 256; x++) { |
| 100 |
//blending is disabled below, as this should be done via video filtering |
| 101 |
//blending code is left for reference purposes |
| 102 |
|
| 103 |
curr = (regs.display_brightness << 15) | get_pixel_swap(x); |
| 104 |
*ptr++ = curr; //(prev + curr - ((prev ^ curr) & 0x0421)) >> 1; |
| 105 |
//prev = curr; |
| 106 |
|
| 107 |
curr = (regs.display_brightness << 15) | get_pixel_normal(x); |
| 108 |
*ptr++ = curr; //(prev + curr - ((prev ^ curr) & 0x0421)) >> 1; |
| 109 |
//prev = curr; |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
inline void PPU::render_line_clear() { |
| 115 |
uint32* ptr = (uint32*)output + (line * 1024) + ((interlace() && field()) ? 512 : 0); |
| 116 |
unsigned width = (!regs.pseudo_hires && regs.bg_mode != 5 && regs.bg_mode != 6) ? 256 : 512; |
| 117 |
memset(ptr, 0, width * 2 * sizeof(uint32)); |
| 118 |
} |
| 119 |
|
| 120 |
#endif |