| 1 |
uint8 PPU::read(uint32 addr) { |
| 2 |
switch(addr) { |
| 3 |
|
| 4 |
//DISPCNT |
| 5 |
case 0x04000000: return regs.control >> 0; |
| 6 |
case 0x04000001: return regs.control >> 8; |
| 7 |
|
| 8 |
//GRSWP |
| 9 |
case 0x04000002: return regs.greenswap; |
| 10 |
case 0x04000003: return 0u; |
| 11 |
|
| 12 |
//DISPSTAT |
| 13 |
case 0x04000004: return regs.status >> 0; |
| 14 |
case 0x04000005: return regs.status >> 8; |
| 15 |
|
| 16 |
//VCOUNT |
| 17 |
case 0x04000006: return regs.vcounter >> 0; |
| 18 |
case 0x04000007: return regs.vcounter >> 8; |
| 19 |
|
| 20 |
//BG0CNT,BG1CNT,BG2CNT,BG3CNT |
| 21 |
case 0x04000008: case 0x04000009: |
| 22 |
case 0x0400000a: case 0x0400000b: |
| 23 |
case 0x0400000c: case 0x0400000d: |
| 24 |
case 0x0400000e: case 0x0400000f: { |
| 25 |
auto& bg = regs.bg[(addr >> 1) & 3]; |
| 26 |
unsigned shift = (addr & 1) * 8; |
| 27 |
return bg.control >> shift; |
| 28 |
} |
| 29 |
|
| 30 |
//WININ |
| 31 |
case 0x04000048: return regs.windowflags[In0]; |
| 32 |
case 0x04000049: return regs.windowflags[In1]; |
| 33 |
case 0x0400004a: return regs.windowflags[Out]; |
| 34 |
case 0x0400004b: return regs.windowflags[Obj]; |
| 35 |
|
| 36 |
//BLTCNT |
| 37 |
case 0x04000050: return regs.blend.control >> 0; |
| 38 |
case 0x04000051: return regs.blend.control >> 8; |
| 39 |
|
| 40 |
} |
| 41 |
|
| 42 |
return 0u; |
| 43 |
} |
| 44 |
|
| 45 |
void PPU::write(uint32 addr, uint8 byte) { |
| 46 |
switch(addr) { |
| 47 |
|
| 48 |
//DISPCNT |
| 49 |
case 0x04000000: regs.control = (regs.control & 0xff00) | (byte << 0); return; |
| 50 |
case 0x04000001: regs.control = (regs.control & 0x00ff) | (byte << 8); return; |
| 51 |
|
| 52 |
//GRSWP |
| 53 |
case 0x04000002: regs.greenswap = byte >> 0; return; |
| 54 |
case 0x04000003: return; |
| 55 |
|
| 56 |
//DISPSTAT |
| 57 |
case 0x04000004: |
| 58 |
regs.status.irqvblank = byte >> 3; |
| 59 |
regs.status.irqhblank = byte >> 4; |
| 60 |
regs.status.irqvcoincidence = byte >> 5; |
| 61 |
return; |
| 62 |
case 0x04000005: |
| 63 |
regs.status.vcompare = byte; |
| 64 |
return; |
| 65 |
|
| 66 |
//BG0CNT,BG1CNT,BG2CNT,BG3CNT |
| 67 |
case 0x04000008: case 0x04000009: |
| 68 |
case 0x0400000a: case 0x0400000b: |
| 69 |
case 0x0400000c: case 0x0400000d: |
| 70 |
case 0x0400000e: case 0x0400000f: { |
| 71 |
auto& bg = regs.bg[(addr >> 1) & 3]; |
| 72 |
unsigned shift = (addr & 1) * 8; |
| 73 |
bg.control = (bg.control & ~(255 << shift)) | (byte << shift); |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
//BG0HOFS,BG1HOFS,BG2BOFS,BG3HOFS |
| 78 |
case 0x04000010: case 0x04000011: |
| 79 |
case 0x04000014: case 0x04000015: |
| 80 |
case 0x04000018: case 0x04000019: |
| 81 |
case 0x0400001c: case 0x0400001d: { |
| 82 |
auto& bg = regs.bg[(addr >> 2) & 3]; |
| 83 |
unsigned shift = (addr & 1) * 8; |
| 84 |
bg.hoffset = (bg.hoffset & ~(255 << shift)) | (byte << shift); |
| 85 |
return; |
| 86 |
} |
| 87 |
|
| 88 |
//BG0VOFS,BG1VOFS,BG2VOFS,BG3VOFS |
| 89 |
case 0x04000012: case 0x04000013: |
| 90 |
case 0x04000016: case 0x04000017: |
| 91 |
case 0x0400001a: case 0x0400001b: |
| 92 |
case 0x0400001e: case 0x0400001f: { |
| 93 |
auto& bg = regs.bg[(addr >> 2) & 3]; |
| 94 |
unsigned shift = (addr & 1) * 8; |
| 95 |
bg.voffset = (bg.voffset & ~(255 << shift)) | (byte << shift); |
| 96 |
return; |
| 97 |
} |
| 98 |
|
| 99 |
//BG2PA,BG3PA |
| 100 |
case 0x04000020: case 0x04000021: |
| 101 |
case 0x04000030: case 0x04000031: { |
| 102 |
auto& bg = regs.bg[(addr >> 4) & 3]; |
| 103 |
unsigned shift = (addr & 1) * 8; |
| 104 |
bg.pa = (bg.pa & ~(255 << shift)) | (byte << shift); |
| 105 |
return; |
| 106 |
} |
| 107 |
|
| 108 |
//BG2PB,BG3PB |
| 109 |
case 0x04000022: case 0x04000023: |
| 110 |
case 0x04000032: case 0x04000033: { |
| 111 |
auto& bg = regs.bg[(addr >> 4) & 3]; |
| 112 |
unsigned shift = (addr & 1) * 8; |
| 113 |
bg.pb = (bg.pb & ~(255 << shift)) | (byte << shift); |
| 114 |
return; |
| 115 |
} |
| 116 |
|
| 117 |
//BG2PC,BG3PC |
| 118 |
case 0x04000024: case 0x04000025: |
| 119 |
case 0x04000034: case 0x04000035: { |
| 120 |
auto& bg = regs.bg[(addr >> 4) & 3]; |
| 121 |
unsigned shift = (addr & 1) * 8; |
| 122 |
bg.pc = (bg.pc & ~(255 << shift)) | (byte << shift); |
| 123 |
return; |
| 124 |
} |
| 125 |
|
| 126 |
//BG2PD,BG3PD |
| 127 |
case 0x04000026: case 0x04000027: |
| 128 |
case 0x04000036: case 0x04000037: { |
| 129 |
auto& bg = regs.bg[(addr >> 4) & 3]; |
| 130 |
unsigned shift = (addr & 1) * 8; |
| 131 |
bg.pd = (bg.pd & ~(255 << shift)) | (byte << shift); |
| 132 |
return; |
| 133 |
} |
| 134 |
|
| 135 |
//BG2X_L,BG2X_H,BG3X_L,BG3X_H |
| 136 |
case 0x04000028: case 0x04000029: case 0x0400002a: case 0x0400002b: |
| 137 |
case 0x04000038: case 0x04000039: case 0x0400003a: case 0x0400003b: { |
| 138 |
auto& bg = regs.bg[(addr >> 4) & 3]; |
| 139 |
unsigned shift = (addr & 3) * 8; |
| 140 |
bg.lx = bg.x = (bg.x & ~(255 << shift)) | (byte << shift); |
| 141 |
return; |
| 142 |
} |
| 143 |
|
| 144 |
//BG2Y_L,BG2Y_H,BG3Y_L,BG3Y_H |
| 145 |
case 0x0400002c: case 0x0400002d: case 0x0400002e: case 0x0400002f: |
| 146 |
case 0x0400003c: case 0x0400003d: case 0x0400003e: case 0x0400003f: { |
| 147 |
auto& bg = regs.bg[(addr >> 4) & 3]; |
| 148 |
unsigned shift = (addr & 3) * 8; |
| 149 |
bg.ly = bg.y = (bg.y & ~(255 << shift)) | (byte << shift); |
| 150 |
return; |
| 151 |
} |
| 152 |
|
| 153 |
//WIN0H |
| 154 |
case 0x04000040: regs.window[0].x2 = byte; return; |
| 155 |
case 0x04000041: regs.window[0].x1 = byte; return; |
| 156 |
|
| 157 |
//WIN1H |
| 158 |
case 0x04000042: regs.window[1].x2 = byte; return; |
| 159 |
case 0x04000043: regs.window[1].x1 = byte; return; |
| 160 |
|
| 161 |
//WIN0V |
| 162 |
case 0x04000044: regs.window[0].y2 = byte; return; |
| 163 |
case 0x04000045: regs.window[0].y1 = byte; return; |
| 164 |
|
| 165 |
//WIN1V |
| 166 |
case 0x04000046: regs.window[1].y2 = byte; return; |
| 167 |
case 0x04000047: regs.window[1].y1 = byte; return; |
| 168 |
|
| 169 |
//WININ |
| 170 |
case 0x04000048: regs.windowflags[In0] = byte; return; |
| 171 |
case 0x04000049: regs.windowflags[In1] = byte; return; |
| 172 |
|
| 173 |
//WINOUT |
| 174 |
case 0x0400004a: regs.windowflags[Out] = byte; return; |
| 175 |
case 0x0400004b: regs.windowflags[Obj] = byte; return; |
| 176 |
|
| 177 |
//MOSAIC |
| 178 |
case 0x0400004c: |
| 179 |
regs.mosaic.bghsize = byte >> 0; |
| 180 |
regs.mosaic.bgvsize = byte >> 4; |
| 181 |
return; |
| 182 |
case 0x0400004d: |
| 183 |
regs.mosaic.objhsize = byte >> 0; |
| 184 |
regs.mosaic.objvsize = byte >> 4; |
| 185 |
return; |
| 186 |
|
| 187 |
//BLDCNT |
| 188 |
case 0x04000050: regs.blend.control = (regs.blend.control & 0xff00) | (byte << 0); return; |
| 189 |
case 0x04000051: regs.blend.control = (regs.blend.control & 0x00ff) | (byte << 8); return; |
| 190 |
|
| 191 |
//BLDALPHA |
| 192 |
case 0x04000052: regs.blend.eva = std::min(16, byte & 0x1f); return; |
| 193 |
case 0x04000053: regs.blend.evb = std::min(16, byte & 0x1f); return; |
| 194 |
|
| 195 |
//BLDY |
| 196 |
case 0x04000054: regs.blend.evy = std::min(16, byte & 0x1f); return; |
| 197 |
case 0x04000055: return; |
| 198 |
|
| 199 |
} |
| 200 |
} |