src/emu/sound/nes_apu.c
| r5357 | r5358 | |
| 88 | 88 | /* INITIALIZE WAVE TIMES RELATIVE TO SAMPLE RATE */ |
| 89 | 89 | static void create_vbltimes(uint32 * table,const uint8 *vbl,unsigned int rate) |
| 90 | 90 | { |
| 91 | | int i; |
| 91 | int i; |
| 92 | 92 | |
| 93 | | for (i=0;i<0x20;i++) |
| 94 | | table[i]=vbl[i]*rate; |
| 93 | for (i = 0; i < 0x20; i++) |
| 94 | table[i] = vbl[i] * rate; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /* INITIALIZE SAMPLE TIMES IN TERMS OF VSYNCS */ |
| 98 | 98 | static void create_syncs(nesapu_state *info, unsigned long sps) |
| 99 | 99 | { |
| 100 | | int i; |
| 101 | | unsigned long val=sps; |
| 100 | int i; |
| 101 | unsigned long val = sps; |
| 102 | 102 | |
| 103 | | for (i=0;i<SYNCS_MAX1;i++) |
| 104 | | { |
| 105 | | info->sync_times1[i]=val; |
| 106 | | val+=sps; |
| 107 | | } |
| 103 | for (i = 0; i < SYNCS_MAX1; i++) |
| 104 | { |
| 105 | info->sync_times1[i] = val; |
| 106 | val += sps; |
| 107 | } |
| 108 | 108 | |
| 109 | | val=0; |
| 110 | | for (i=0;i<SYNCS_MAX2;i++) |
| 111 | | { |
| 112 | | info->sync_times2[i]=val; |
| 113 | | info->sync_times2[i]>>=2; |
| 114 | | val+=sps; |
| 115 | | } |
| 109 | val = 0; |
| 110 | for (i = 0; i < SYNCS_MAX2; i++) |
| 111 | { |
| 112 | info->sync_times2[i] = val; |
| 113 | info->sync_times2[i] >>= 2; |
| 114 | val += sps; |
| 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /* INITIALIZE NOISE LOOKUP TABLE */ |
| 119 | 119 | static void create_noise(uint8 *buf, const int bits, int size) |
| 120 | 120 | { |
| 121 | | static int m = 0x0011; |
| 122 | | int xor_val, i; |
| 121 | static int m = 0x0011; |
| 122 | int xor_val, i; |
| 123 | 123 | |
| 124 | | for (i = 0; i < size; i++) |
| 125 | | { |
| 126 | | xor_val = m & 1; |
| 127 | | m >>= 1; |
| 128 | | xor_val ^= (m & 1); |
| 129 | | m |= xor_val << (bits - 1); |
| 124 | for (i = 0; i < size; i++) |
| 125 | { |
| 126 | xor_val = m & 1; |
| 127 | m >>= 1; |
| 128 | xor_val ^= (m & 1); |
| 129 | m |= xor_val << (bits - 1); |
| 130 | 130 | |
| 131 | | buf[i] = m; |
| 132 | | } |
| 131 | buf[i] = m; |
| 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /* TODO: sound channels should *ALL* have DC volume decay */ |
| r5357 | r5358 | |
| 137 | 137 | /* OUTPUT SQUARE WAVE SAMPLE (VALUES FROM -16 to +15) */ |
| 138 | 138 | static int8 apu_square(nesapu_state *info, square_t *chan) |
| 139 | 139 | { |
| 140 | | int env_delay; |
| 141 | | int sweep_delay; |
| 142 | | int8 output; |
| 140 | int env_delay; |
| 141 | int sweep_delay; |
| 142 | int8 output; |
| 143 | 143 | |
| 144 | | /* reg0: 0-3=volume, 4=envelope, 5=hold, 6-7=duty cycle |
| 145 | | ** reg1: 0-2=sweep shifts, 3=sweep inc/dec, 4-6=sweep length, 7=sweep on |
| 146 | | ** reg2: 8 bits of freq |
| 147 | | ** reg3: 0-2=high freq, 7-4=vbl length counter |
| 148 | | */ |
| 144 | /* reg0: 0-3=volume, 4=envelope, 5=hold, 6-7=duty cycle |
| 145 | ** reg1: 0-2=sweep shifts, 3=sweep inc/dec, 4-6=sweep length, 7=sweep on |
| 146 | ** reg2: 8 bits of freq |
| 147 | ** reg3: 0-2=high freq, 7-4=vbl length counter |
| 148 | */ |
| 149 | 149 | |
| 150 | | if (FALSE == chan->enabled) |
| 151 | | return 0; |
| 150 | if (FALSE == chan->enabled) |
| 151 | return 0; |
| 152 | 152 | |
| 153 | | /* enveloping */ |
| 154 | | env_delay = info->sync_times1[chan->regs[0] & 0x0F]; |
| 153 | /* enveloping */ |
| 154 | env_delay = info->sync_times1[chan->regs[0] & 0x0F]; |
| 155 | 155 | |
| 156 | | /* decay is at a rate of (env_regs + 1) / 240 secs */ |
| 157 | | chan->env_phase -= 4; |
| 158 | | while (chan->env_phase < 0) |
| 159 | | { |
| 160 | | chan->env_phase += env_delay; |
| 161 | | if (chan->regs[0] & 0x20) |
| 162 | | chan->env_vol = (chan->env_vol + 1) & 15; |
| 163 | | else if (chan->env_vol < 15) |
| 164 | | chan->env_vol++; |
| 165 | | } |
| 156 | /* decay is at a rate of (env_regs + 1) / 240 secs */ |
| 157 | chan->env_phase -= 4; |
| 158 | while (chan->env_phase < 0) |
| 159 | { |
| 160 | chan->env_phase += env_delay; |
| 161 | if (chan->regs[0] & 0x20) |
| 162 | chan->env_vol = (chan->env_vol + 1) & 15; |
| 163 | else if (chan->env_vol < 15) |
| 164 | chan->env_vol++; |
| 165 | } |
| 166 | 166 | |
| 167 | | /* vbl length counter */ |
| 168 | | if (chan->vbl_length > 0 && 0 == (chan->regs [0] & 0x20)) |
| 169 | | chan->vbl_length--; |
| 167 | /* vbl length counter */ |
| 168 | if (chan->vbl_length > 0 && 0 == (chan->regs [0] & 0x20)) |
| 169 | chan->vbl_length--; |
| 170 | 170 | |
| 171 | | if (0 == chan->vbl_length) |
| 172 | | return 0; |
| 171 | if (0 == chan->vbl_length) |
| 172 | return 0; |
| 173 | 173 | |
| 174 | | /* freqsweeps */ |
| 175 | | if ((chan->regs[1] & 0x80) && (chan->regs[1] & 7)) |
| 176 | | { |
| 177 | | sweep_delay = info->sync_times1[(chan->regs[1] >> 4) & 7]; |
| 178 | | chan->sweep_phase -= 2; |
| 179 | | while (chan->sweep_phase < 0) |
| 180 | | { |
| 181 | | chan->sweep_phase += sweep_delay; |
| 182 | | if (chan->regs[1] & 8) |
| 183 | | chan->freq -= chan->freq >> (chan->regs[1] & 7); |
| 184 | | else |
| 185 | | chan->freq += chan->freq >> (chan->regs[1] & 7); |
| 186 | | } |
| 187 | | } |
| 174 | /* freqsweeps */ |
| 175 | if ((chan->regs[1] & 0x80) && (chan->regs[1] & 7)) |
| 176 | { |
| 177 | sweep_delay = info->sync_times1[(chan->regs[1] >> 4) & 7]; |
| 178 | chan->sweep_phase -= 2; |
| 179 | while (chan->sweep_phase < 0) |
| 180 | { |
| 181 | chan->sweep_phase += sweep_delay; |
| 182 | if (chan->regs[1] & 8) |
| 183 | chan->freq -= chan->freq >> (chan->regs[1] & 7); |
| 184 | else |
| 185 | chan->freq += chan->freq >> (chan->regs[1] & 7); |
| 186 | } |
| 187 | } |
| 188 | 188 | |
| 189 | | if ((0 == (chan->regs[1] & 8) && (chan->freq >> 16) > freq_limit[chan->regs[1] & 7]) |
| 190 | | || (chan->freq >> 16) < 4) |
| 191 | | return 0; |
| 189 | if ((0 == (chan->regs[1] & 8) && (chan->freq >> 16) > freq_limit[chan->regs[1] & 7]) |
| 190 | || (chan->freq >> 16) < 4) |
| 191 | return 0; |
| 192 | 192 | |
| 193 | | chan->phaseacc -= (float) info->apu_incsize; /* # of cycles per sample */ |
| 193 | chan->phaseacc -= (float) info->apu_incsize; /* # of cycles per sample */ |
| 194 | 194 | |
| 195 | | while (chan->phaseacc < 0) |
| 196 | | { |
| 197 | | chan->phaseacc += (chan->freq >> 16); |
| 198 | | chan->adder = (chan->adder + 1) & 0x0F; |
| 199 | | } |
| 195 | while (chan->phaseacc < 0) |
| 196 | { |
| 197 | chan->phaseacc += (chan->freq >> 16); |
| 198 | chan->adder = (chan->adder + 1) & 0x0F; |
| 199 | } |
| 200 | 200 | |
| 201 | | if (chan->regs[0] & 0x10) /* fixed volume */ |
| 202 | | output = chan->regs[0] & 0x0F; |
| 203 | | else |
| 204 | | output = 0x0F - chan->env_vol; |
| 201 | if (chan->regs[0] & 0x10) /* fixed volume */ |
| 202 | output = chan->regs[0] & 0x0F; |
| 203 | else |
| 204 | output = 0x0F - chan->env_vol; |
| 205 | 205 | |
| 206 | | if (chan->adder < (duty_lut[chan->regs[0] >> 6])) |
| 207 | | output = -output; |
| 206 | if (chan->adder < (duty_lut[chan->regs[0] >> 6])) |
| 207 | output = -output; |
| 208 | 208 | |
| 209 | | return (int8) output; |
| 209 | return (int8) output; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /* OUTPUT TRIANGLE WAVE SAMPLE (VALUES FROM -16 to +15) */ |
| 213 | 213 | static int8 apu_triangle(nesapu_state *info, triangle_t *chan) |
| 214 | 214 | { |
| 215 | | int freq; |
| 216 | | int8 output; |
| 217 | | /* reg0: 7=holdnote, 6-0=linear length counter |
| 218 | | ** reg2: low 8 bits of frequency |
| 219 | | ** reg3: 7-3=length counter, 2-0=high 3 bits of frequency |
| 220 | | */ |
| 215 | int freq; |
| 216 | int8 output; |
| 217 | /* reg0: 7=holdnote, 6-0=linear length counter |
| 218 | ** reg2: low 8 bits of frequency |
| 219 | ** reg3: 7-3=length counter, 2-0=high 3 bits of frequency |
| 220 | */ |
| 221 | 221 | |
| 222 | | if (FALSE == chan->enabled) |
| 223 | | return 0; |
| 222 | if (FALSE == chan->enabled) |
| 223 | return 0; |
| 224 | 224 | |
| 225 | | if (FALSE == chan->counter_started && 0 == (chan->regs[0] & 0x80)) |
| 226 | | { |
| 227 | | if (chan->write_latency) |
| 228 | | chan->write_latency--; |
| 229 | | if (0 == chan->write_latency) |
| 230 | | chan->counter_started = TRUE; |
| 231 | | } |
| 225 | if (FALSE == chan->counter_started && 0 == (chan->regs[0] & 0x80)) |
| 226 | { |
| 227 | if (chan->write_latency) |
| 228 | chan->write_latency--; |
| 229 | if (0 == chan->write_latency) |
| 230 | chan->counter_started = TRUE; |
| 231 | } |
| 232 | 232 | |
| 233 | | if (chan->counter_started) |
| 234 | | { |
| 235 | | if (chan->linear_length > 0) |
| 236 | | chan->linear_length--; |
| 237 | | if (chan->vbl_length && 0 == (chan->regs[0] & 0x80)) |
| 238 | | chan->vbl_length--; |
| 233 | if (chan->counter_started) |
| 234 | { |
| 235 | if (chan->linear_length > 0) |
| 236 | chan->linear_length--; |
| 237 | if (chan->vbl_length && 0 == (chan->regs[0] & 0x80)) |
| 238 | chan->vbl_length--; |
| 239 | 239 | |
| 240 | | if (0 == chan->vbl_length) |
| 241 | | return 0; |
| 242 | | } |
| 240 | if (0 == chan->vbl_length) |
| 241 | return 0; |
| 242 | } |
| 243 | 243 | |
| 244 | | if (0 == chan->linear_length) |
| 245 | | return 0; |
| 244 | if (0 == chan->linear_length) |
| 245 | return 0; |
| 246 | 246 | |
| 247 | | freq = (((chan->regs[3] & 7) << 8) + chan->regs[2]) + 1; |
| 247 | freq = (((chan->regs[3] & 7) << 8) + chan->regs[2]) + 1; |
| 248 | 248 | |
| 249 | | if (freq < 4) /* inaudible */ |
| 250 | | return 0; |
| 249 | if (freq < 4) /* inaudible */ |
| 250 | return 0; |
| 251 | 251 | |
| 252 | | chan->phaseacc -= (float) info->apu_incsize; /* # of cycles per sample */ |
| 253 | | while (chan->phaseacc < 0) |
| 254 | | { |
| 255 | | chan->phaseacc += freq; |
| 256 | | chan->adder = (chan->adder + 1) & 0x1F; |
| 252 | chan->phaseacc -= (float) info->apu_incsize; /* # of cycles per sample */ |
| 253 | while (chan->phaseacc < 0) |
| 254 | { |
| 255 | chan->phaseacc += freq; |
| 256 | chan->adder = (chan->adder + 1) & 0x1F; |
| 257 | 257 | |
| 258 | | output = (chan->adder & 7) << 1; |
| 259 | | if (chan->adder & 8) |
| 260 | | output = 0x10 - output; |
| 261 | | if (chan->adder & 0x10) |
| 262 | | output = -output; |
| 258 | output = (chan->adder & 7) << 1; |
| 259 | if (chan->adder & 8) |
| 260 | output = 0x10 - output; |
| 261 | if (chan->adder & 0x10) |
| 262 | output = -output; |
| 263 | 263 | |
| 264 | | chan->output_vol = output; |
| 265 | | } |
| 264 | chan->output_vol = output; |
| 265 | } |
| 266 | 266 | |
| 267 | | return (int8) chan->output_vol; |
| 267 | return (int8) chan->output_vol; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /* OUTPUT NOISE WAVE SAMPLE (VALUES FROM -16 to +15) */ |
| 271 | 271 | static int8 apu_noise(nesapu_state *info, noise_t *chan) |
| 272 | 272 | { |
| 273 | | int freq, env_delay; |
| 274 | | uint8 outvol; |
| 275 | | uint8 output; |
| 273 | int freq, env_delay; |
| 274 | uint8 outvol; |
| 275 | uint8 output; |
| 276 | 276 | |
| 277 | | /* reg0: 0-3=volume, 4=envelope, 5=hold |
| 278 | | ** reg2: 7=small(93 byte) sample,3-0=freq lookup |
| 279 | | ** reg3: 7-4=vbl length counter |
| 280 | | */ |
| 277 | /* reg0: 0-3=volume, 4=envelope, 5=hold |
| 278 | ** reg2: 7=small(93 byte) sample,3-0=freq lookup |
| 279 | ** reg3: 7-4=vbl length counter |
| 280 | */ |
| 281 | 281 | |
| 282 | | if (FALSE == chan->enabled) |
| 283 | | return 0; |
| 282 | if (FALSE == chan->enabled) |
| 283 | return 0; |
| 284 | 284 | |
| 285 | | /* enveloping */ |
| 286 | | env_delay = info->sync_times1[chan->regs[0] & 0x0F]; |
| 285 | /* enveloping */ |
| 286 | env_delay = info->sync_times1[chan->regs[0] & 0x0F]; |
| 287 | 287 | |
| 288 | | /* decay is at a rate of (env_regs + 1) / 240 secs */ |
| 289 | | chan->env_phase -= 4; |
| 290 | | while (chan->env_phase < 0) |
| 291 | | { |
| 292 | | chan->env_phase += env_delay; |
| 293 | | if (chan->regs[0] & 0x20) |
| 294 | | chan->env_vol = (chan->env_vol + 1) & 15; |
| 295 | | else if (chan->env_vol < 15) |
| 296 | | chan->env_vol++; |
| 297 | | } |
| 288 | /* decay is at a rate of (env_regs + 1) / 240 secs */ |
| 289 | chan->env_phase -= 4; |
| 290 | while (chan->env_phase < 0) |
| 291 | { |
| 292 | chan->env_phase += env_delay; |
| 293 | if (chan->regs[0] & 0x20) |
| 294 | chan->env_vol = (chan->env_vol + 1) & 15; |
| 295 | else if (chan->env_vol < 15) |
| 296 | chan->env_vol++; |
| 297 | } |
| 298 | 298 | |
| 299 | | /* length counter */ |
| 300 | | if (0 == (chan->regs[0] & 0x20)) |
| 301 | | { |
| 302 | | if (chan->vbl_length > 0) |
| 303 | | chan->vbl_length--; |
| 304 | | } |
| 299 | /* length counter */ |
| 300 | if (0 == (chan->regs[0] & 0x20)) |
| 301 | { |
| 302 | if (chan->vbl_length > 0) |
| 303 | chan->vbl_length--; |
| 304 | } |
| 305 | 305 | |
| 306 | | if (0 == chan->vbl_length) |
| 307 | | return 0; |
| 306 | if (0 == chan->vbl_length) |
| 307 | return 0; |
| 308 | 308 | |
| 309 | | freq = noise_freq[chan->regs[2] & 0x0F]; |
| 310 | | chan->phaseacc -= (float) info->apu_incsize; /* # of cycles per sample */ |
| 311 | | while (chan->phaseacc < 0) |
| 312 | | { |
| 313 | | chan->phaseacc += freq; |
| 309 | freq = noise_freq[chan->regs[2] & 0x0F]; |
| 310 | chan->phaseacc -= (float) info->apu_incsize; /* # of cycles per sample */ |
| 311 | while (chan->phaseacc < 0) |
| 312 | { |
| 313 | chan->phaseacc += freq; |
| 314 | 314 | |
| 315 | | chan->cur_pos++; |
| 316 | | if (NOISE_SHORT == chan->cur_pos && (chan->regs[2] & 0x80)) |
| 317 | | chan->cur_pos = 0; |
| 318 | | else if (NOISE_LONG == chan->cur_pos) |
| 319 | | chan->cur_pos = 0; |
| 320 | | } |
| 315 | chan->cur_pos++; |
| 316 | if (NOISE_SHORT == chan->cur_pos && (chan->regs[2] & 0x80)) |
| 317 | chan->cur_pos = 0; |
| 318 | else if (NOISE_LONG == chan->cur_pos) |
| 319 | chan->cur_pos = 0; |
| 320 | } |
| 321 | 321 | |
| 322 | | if (chan->regs[0] & 0x10) /* fixed volume */ |
| 323 | | outvol = chan->regs[0] & 0x0F; |
| 324 | | else |
| 325 | | outvol = 0x0F - chan->env_vol; |
| 322 | if (chan->regs[0] & 0x10) /* fixed volume */ |
| 323 | outvol = chan->regs[0] & 0x0F; |
| 324 | else |
| 325 | outvol = 0x0F - chan->env_vol; |
| 326 | 326 | |
| 327 | | output = info->noise_lut[chan->cur_pos]; |
| 328 | | if (output > outvol) |
| 329 | | output = outvol; |
| 327 | output = info->noise_lut[chan->cur_pos]; |
| 328 | if (output > outvol) |
| 329 | output = outvol; |
| 330 | 330 | |
| 331 | | if (info->noise_lut[chan->cur_pos] & 0x80) /* make it negative */ |
| 332 | | output = -output; |
| 331 | if (info->noise_lut[chan->cur_pos] & 0x80) /* make it negative */ |
| 332 | output = -output; |
| 333 | 333 | |
| 334 | | return (int8) output; |
| 334 | return (int8) output; |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /* RESET DPCM PARAMETERS */ |
| 338 | 338 | INLINE void apu_dpcmreset(dpcm_t *chan) |
| 339 | 339 | { |
| 340 | | chan->address = 0xC000 + (uint16) (chan->regs[2] << 6); |
| 341 | | chan->length = (uint16) (chan->regs[3] << 4) + 1; |
| 342 | | chan->bits_left = chan->length << 3; |
| 343 | | chan->irq_occurred = FALSE; |
| 344 | | chan->enabled = TRUE; /* Fixed * Proper DPCM channel ENABLE/DISABLE flag behaviour*/ |
| 345 | | chan->vol = 0; /* Fixed * DPCM DAC resets itself when restarted */ |
| 340 | chan->address = 0xC000 + (uint16) (chan->regs[2] << 6); |
| 341 | chan->length = (uint16) (chan->regs[3] << 4) + 1; |
| 342 | chan->bits_left = chan->length << 3; |
| 343 | chan->irq_occurred = FALSE; |
| 344 | chan->enabled = TRUE; /* Fixed * Proper DPCM channel ENABLE/DISABLE flag behaviour*/ |
| 345 | chan->vol = 0; /* Fixed * DPCM DAC resets itself when restarted */ |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | /* OUTPUT DPCM WAVE SAMPLE (VALUES FROM -64 to +63) */ |
| 349 | 349 | /* TODO: centerline naughtiness */ |
| 350 | 350 | static int8 apu_dpcm(nesapu_state *info, dpcm_t *chan) |
| 351 | 351 | { |
| 352 | | int freq, bit_pos; |
| 352 | int freq, bit_pos; |
| 353 | 353 | |
| 354 | | /* reg0: 7=irq gen, 6=looping, 3-0=pointer to clock table |
| 355 | | ** reg1: output dc level, 7 bits unsigned |
| 356 | | ** reg2: 8 bits of 64-byte aligned address offset : $C000 + (value * 64) |
| 357 | | ** reg3: length, (value * 16) + 1 |
| 358 | | */ |
| 354 | /* reg0: 7=irq gen, 6=looping, 3-0=pointer to clock table |
| 355 | ** reg1: output dc level, 7 bits unsigned |
| 356 | ** reg2: 8 bits of 64-byte aligned address offset : $C000 + (value * 64) |
| 357 | ** reg3: length, (value * 16) + 1 |
| 358 | */ |
| 359 | 359 | |
| 360 | | if (chan->enabled) |
| 361 | | { |
| 362 | | freq = dpcm_clocks[chan->regs[0] & 0x0F]; |
| 363 | | chan->phaseacc -= (float) info->apu_incsize; /* # of cycles per sample */ |
| 360 | if (chan->enabled) |
| 361 | { |
| 362 | freq = dpcm_clocks[chan->regs[0] & 0x0F]; |
| 363 | chan->phaseacc -= (float) info->apu_incsize; /* # of cycles per sample */ |
| 364 | 364 | |
| 365 | | while (chan->phaseacc < 0) |
| 366 | | { |
| 367 | | chan->phaseacc += freq; |
| 365 | while (chan->phaseacc < 0) |
| 366 | { |
| 367 | chan->phaseacc += freq; |
| 368 | 368 | |
| 369 | | if (0 == chan->length) |
| 370 | | { |
| 371 | | chan->enabled = FALSE; /* Fixed * Proper DPCM channel ENABLE/DISABLE flag behaviour*/ |
| 372 | | chan->vol=0; /* Fixed * DPCM DAC resets itself when restarted */ |
| 373 | | if (chan->regs[0] & 0x40) |
| 374 | | apu_dpcmreset(chan); |
| 375 | | else |
| 376 | | { |
| 377 | | if (chan->regs[0] & 0x80) /* IRQ Generator */ |
| 378 | | { |
| 379 | | chan->irq_occurred = TRUE; |
| 380 | | n2a03_irq(info->APU.dpcm.memory->cpu); |
| 381 | | } |
| 382 | | break; |
| 383 | | } |
| 384 | | } |
| 369 | if (0 == chan->length) |
| 370 | { |
| 371 | chan->enabled = FALSE; /* Fixed * Proper DPCM channel ENABLE/DISABLE flag behaviour*/ |
| 372 | chan->vol=0; /* Fixed * DPCM DAC resets itself when restarted */ |
| 373 | if (chan->regs[0] & 0x40) |
| 374 | apu_dpcmreset(chan); |
| 375 | else |
| 376 | { |
| 377 | if (chan->regs[0] & 0x80) /* IRQ Generator */ |
| 378 | { |
| 379 | chan->irq_occurred = TRUE; |
| 380 | n2a03_irq(info->APU.dpcm.memory->cpu); |
| 381 | } |
| 382 | break; |
| 383 | } |
| 384 | } |
| 385 | 385 | |
| 386 | 386 | |
| 387 | | chan->bits_left--; |
| 388 | | bit_pos = 7 - (chan->bits_left & 7); |
| 389 | | if (7 == bit_pos) |
| 390 | | { |
| 391 | | chan->cur_byte = memory_read_byte(info->APU.dpcm.memory, chan->address); |
| 392 | | chan->address++; |
| 393 | | chan->length--; |
| 394 | | } |
| 387 | chan->bits_left--; |
| 388 | bit_pos = 7 - (chan->bits_left & 7); |
| 389 | if (7 == bit_pos) |
| 390 | { |
| 391 | chan->cur_byte = memory_read_byte(info->APU.dpcm.memory, chan->address); |
| 392 | chan->address++; |
| 393 | chan->length--; |
| 394 | } |
| 395 | 395 | |
| 396 | | if (chan->cur_byte & (1 << bit_pos)) |
| 397 | | // chan->regs[1]++; |
| 398 | | chan->vol+=2; /* FIXED * DPCM channel only uses the upper 6 bits of the DAC */ |
| 399 | | else |
| 400 | | // chan->regs[1]--; |
| 401 | | chan->vol-=2; |
| 402 | | } |
| 403 | | } |
| 396 | if (chan->cur_byte & (1 << bit_pos)) |
| 397 | // chan->regs[1]++; |
| 398 | chan->vol+=2; /* FIXED * DPCM channel only uses the upper 6 bits of the DAC */ |
| 399 | else |
| 400 | // chan->regs[1]--; |
| 401 | chan->vol-=2; |
| 402 | } |
| 403 | } |
| 404 | 404 | |
| 405 | | if (chan->vol > 63) |
| 406 | | chan->vol = 63; |
| 407 | | else if (chan->vol < -64) |
| 408 | | chan->vol = -64; |
| 405 | if (chan->vol > 63) |
| 406 | chan->vol = 63; |
| 407 | else if (chan->vol < -64) |
| 408 | chan->vol = -64; |
| 409 | 409 | |
| 410 | | return (int8) (chan->vol); |
| 410 | return (int8) (chan->vol); |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /* WRITE REGISTER VALUE */ |
| 414 | 414 | INLINE void apu_regwrite(nesapu_state *info,int address, uint8 value) |
| 415 | 415 | { |
| 416 | | int chan = (address & 4) ? 1 : 0; |
| 416 | int chan = (address & 4) ? 1 : 0; |
| 417 | 417 | |
| 418 | | switch (address) |
| 419 | | { |
| 420 | | /* squares */ |
| 421 | | case APU_WRA0: |
| 422 | | case APU_WRB0: |
| 423 | | info->APU.squ[chan].regs[0] = value; |
| 424 | | break; |
| 418 | switch (address) |
| 419 | { |
| 420 | /* squares */ |
| 421 | case APU_WRA0: |
| 422 | case APU_WRB0: |
| 423 | info->APU.squ[chan].regs[0] = value; |
| 424 | break; |
| 425 | 425 | |
| 426 | | case APU_WRA1: |
| 427 | | case APU_WRB1: |
| 428 | | info->APU.squ[chan].regs[1] = value; |
| 429 | | break; |
| 426 | case APU_WRA1: |
| 427 | case APU_WRB1: |
| 428 | info->APU.squ[chan].regs[1] = value; |
| 429 | break; |
| 430 | 430 | |
| 431 | | case APU_WRA2: |
| 432 | | case APU_WRB2: |
| 433 | | info->APU.squ[chan].regs[2] = value; |
| 434 | | if (info->APU.squ[chan].enabled) |
| 435 | | info->APU.squ[chan].freq = ((((info->APU.squ[chan].regs[3] & 7) << 8) + value) + 1) << 16; |
| 436 | | break; |
| 431 | case APU_WRA2: |
| 432 | case APU_WRB2: |
| 433 | info->APU.squ[chan].regs[2] = value; |
| 434 | if (info->APU.squ[chan].enabled) |
| 435 | info->APU.squ[chan].freq = ((((info->APU.squ[chan].regs[3] & 7) << 8) + value) + 1) << 16; |
| 436 | break; |
| 437 | 437 | |
| 438 | | case APU_WRA3: |
| 439 | | case APU_WRB3: |
| 440 | | info->APU.squ[chan].regs[3] = value; |
| 438 | case APU_WRA3: |
| 439 | case APU_WRB3: |
| 440 | info->APU.squ[chan].regs[3] = value; |
| 441 | 441 | |
| 442 | | if (info->APU.squ[chan].enabled) |
| 443 | | { |
| 444 | | info->APU.squ[chan].vbl_length = info->vbl_times[value >> 3]; |
| 445 | | info->APU.squ[chan].env_vol = 0; |
| 446 | | info->APU.squ[chan].freq = ((((value & 7) << 8) + info->APU.squ[chan].regs[2]) + 1) << 16; |
| 447 | | } |
| 442 | if (info->APU.squ[chan].enabled) |
| 443 | { |
| 444 | info->APU.squ[chan].vbl_length = info->vbl_times[value >> 3]; |
| 445 | info->APU.squ[chan].env_vol = 0; |
| 446 | info->APU.squ[chan].freq = ((((value & 7) << 8) + info->APU.squ[chan].regs[2]) + 1) << 16; |
| 447 | } |
| 448 | 448 | |
| 449 | | break; |
| 449 | break; |
| 450 | 450 | |
| 451 | | /* triangle */ |
| 452 | | case APU_WRC0: |
| 453 | | info->APU.tri.regs[0] = value; |
| 451 | /* triangle */ |
| 452 | case APU_WRC0: |
| 453 | info->APU.tri.regs[0] = value; |
| 454 | 454 | |
| 455 | | if (info->APU.tri.enabled) |
| 456 | | { /* ??? */ |
| 457 | | if (FALSE == info->APU.tri.counter_started) |
| 458 | | info->APU.tri.linear_length = info->sync_times2[value & 0x7F]; |
| 459 | | } |
| 455 | if (info->APU.tri.enabled) |
| 456 | { /* ??? */ |
| 457 | if (FALSE == info->APU.tri.counter_started) |
| 458 | info->APU.tri.linear_length = info->sync_times2[value & 0x7F]; |
| 459 | } |
| 460 | 460 | |
| 461 | | break; |
| 461 | break; |
| 462 | 462 | |
| 463 | | case 0x4009: |
| 464 | | /* unused */ |
| 465 | | info->APU.tri.regs[1] = value; |
| 466 | | break; |
| 463 | case 0x4009: |
| 464 | /* unused */ |
| 465 | info->APU.tri.regs[1] = value; |
| 466 | break; |
| 467 | 467 | |
| 468 | | case APU_WRC2: |
| 469 | | info->APU.tri.regs[2] = value; |
| 470 | | break; |
| 468 | case APU_WRC2: |
| 469 | info->APU.tri.regs[2] = value; |
| 470 | break; |
| 471 | 471 | |
| 472 | | case APU_WRC3: |
| 473 | | info->APU.tri.regs[3] = value; |
| 472 | case APU_WRC3: |
| 473 | info->APU.tri.regs[3] = value; |
| 474 | 474 | |
| 475 | | /* this is somewhat of a hack. there is some latency on the Real |
| 476 | | ** Thing between when trireg0 is written to and when the linear |
| 477 | | ** length counter actually begins its countdown. we want to prevent |
| 478 | | ** the case where the program writes to the freq regs first, then |
| 479 | | ** to reg 0, and the counter accidentally starts running because of |
| 480 | | ** the sound queue's timestamp processing. |
| 481 | | ** |
| 482 | | ** set to a few NES sample -- should be sufficient |
| 483 | | ** |
| 484 | | ** 3 * (1789772.727 / 44100) = ~122 cycles, just around one scanline |
| 485 | | ** |
| 486 | | ** should be plenty of time for the 6502 code to do a couple of table |
| 487 | | ** dereferences and load up the other triregs |
| 488 | | */ |
| 475 | /* this is somewhat of a hack. there is some latency on the Real |
| 476 | ** Thing between when trireg0 is written to and when the linear |
| 477 | ** length counter actually begins its countdown. we want to prevent |
| 478 | ** the case where the program writes to the freq regs first, then |
| 479 | ** to reg 0, and the counter accidentally starts running because of |
| 480 | ** the sound queue's timestamp processing. |
| 481 | ** |
| 482 | ** set to a few NES sample -- should be sufficient |
| 483 | ** |
| 484 | ** 3 * (1789772.727 / 44100) = ~122 cycles, just around one scanline |
| 485 | ** |
| 486 | ** should be plenty of time for the 6502 code to do a couple of table |
| 487 | ** dereferences and load up the other triregs |
| 488 | */ |
| 489 | 489 | |
| 490 | 490 | /* used to be 3, but now we run the clock faster, so base it on samples/sync */ |
| 491 | | info->APU.tri.write_latency = (info->samps_per_sync + 239) / 240; |
| 491 | info->APU.tri.write_latency = (info->samps_per_sync + 239) / 240; |
| 492 | 492 | |
| 493 | | if (info->APU.tri.enabled) |
| 494 | | { |
| 495 | | info->APU.tri.counter_started = FALSE; |
| 496 | | info->APU.tri.vbl_length = info->vbl_times[value >> 3]; |
| 497 | | info->APU.tri.linear_length = info->sync_times2[info->APU.tri.regs[0] & 0x7F]; |
| 498 | | } |
| 493 | if (info->APU.tri.enabled) |
| 494 | { |
| 495 | info->APU.tri.counter_started = FALSE; |
| 496 | info->APU.tri.vbl_length = info->vbl_times[value >> 3]; |
| 497 | info->APU.tri.linear_length = info->sync_times2[info->APU.tri.regs[0] & 0x7F]; |
| 498 | } |
| 499 | 499 | |
| 500 | | break; |
| 500 | break; |
| 501 | 501 | |
| 502 | | /* noise */ |
| 503 | | case APU_WRD0: |
| 504 | | info->APU.noi.regs[0] = value; |
| 505 | | break; |
| 502 | /* noise */ |
| 503 | case APU_WRD0: |
| 504 | info->APU.noi.regs[0] = value; |
| 505 | break; |
| 506 | 506 | |
| 507 | | case 0x400D: |
| 508 | | /* unused */ |
| 509 | | info->APU.noi.regs[1] = value; |
| 510 | | break; |
| 507 | case 0x400D: |
| 508 | /* unused */ |
| 509 | info->APU.noi.regs[1] = value; |
| 510 | break; |
| 511 | 511 | |
| 512 | | case APU_WRD2: |
| 513 | | info->APU.noi.regs[2] = value; |
| 514 | | break; |
| 512 | case APU_WRD2: |
| 513 | info->APU.noi.regs[2] = value; |
| 514 | break; |
| 515 | 515 | |
| 516 | | case APU_WRD3: |
| 517 | | info->APU.noi.regs[3] = value; |
| 516 | case APU_WRD3: |
| 517 | info->APU.noi.regs[3] = value; |
| 518 | 518 | |
| 519 | | if (info->APU.noi.enabled) |
| 520 | | { |
| 521 | | info->APU.noi.vbl_length = info->vbl_times[value >> 3]; |
| 522 | | info->APU.noi.env_vol = 0; /* reset envelope */ |
| 523 | | } |
| 524 | | break; |
| 519 | if (info->APU.noi.enabled) |
| 520 | { |
| 521 | info->APU.noi.vbl_length = info->vbl_times[value >> 3]; |
| 522 | info->APU.noi.env_vol = 0; /* reset envelope */ |
| 523 | } |
| 524 | break; |
| 525 | 525 | |
| 526 | | /* DMC */ |
| 527 | | case APU_WRE0: |
| 528 | | info->APU.dpcm.regs[0] = value; |
| 529 | | if (0 == (value & 0x80)) |
| 530 | | info->APU.dpcm.irq_occurred = FALSE; |
| 531 | | break; |
| 526 | /* DMC */ |
| 527 | case APU_WRE0: |
| 528 | info->APU.dpcm.regs[0] = value; |
| 529 | if (0 == (value & 0x80)) |
| 530 | info->APU.dpcm.irq_occurred = FALSE; |
| 531 | break; |
| 532 | 532 | |
| 533 | | case APU_WRE1: /* 7-bit DAC */ |
| 534 | | //info->APU.dpcm.regs[1] = value - 0x40; |
| 535 | | info->APU.dpcm.regs[1] = value & 0x7F; |
| 536 | | info->APU.dpcm.vol = (info->APU.dpcm.regs[1]-64); |
| 537 | | break; |
| 533 | case APU_WRE1: /* 7-bit DAC */ |
| 534 | //info->APU.dpcm.regs[1] = value - 0x40; |
| 535 | info->APU.dpcm.regs[1] = value & 0x7F; |
| 536 | info->APU.dpcm.vol = (info->APU.dpcm.regs[1]-64); |
| 537 | break; |
| 538 | 538 | |
| 539 | | case APU_WRE2: |
| 540 | | info->APU.dpcm.regs[2] = value; |
| 541 | | //apu_dpcmreset(info->APU.dpcm); |
| 542 | | break; |
| 539 | case APU_WRE2: |
| 540 | info->APU.dpcm.regs[2] = value; |
| 541 | //apu_dpcmreset(info->APU.dpcm); |
| 542 | break; |
| 543 | 543 | |
| 544 | | case APU_WRE3: |
| 545 | | info->APU.dpcm.regs[3] = value; |
| 546 | | break; |
| 544 | case APU_WRE3: |
| 545 | info->APU.dpcm.regs[3] = value; |
| 546 | break; |
| 547 | 547 | |
| 548 | | case APU_IRQCTRL: |
| 549 | | break; |
| 548 | case APU_IRQCTRL: |
| 549 | if(value & 0x80) |
| 550 | info->APU.step_mode = 5; |
| 551 | else |
| 552 | info->APU.step_mode = 4; |
| 553 | break; |
| 550 | 554 | |
| 551 | | case APU_SMASK: |
| 552 | | if (value & 0x01) |
| 553 | | info->APU.squ[0].enabled = TRUE; |
| 554 | | else |
| 555 | | { |
| 556 | | info->APU.squ[0].enabled = FALSE; |
| 557 | | info->APU.squ[0].vbl_length = 0; |
| 558 | | } |
| 555 | case APU_SMASK: |
| 556 | if (value & 0x01) |
| 557 | info->APU.squ[0].enabled = TRUE; |
| 558 | else |
| 559 | { |
| 560 | info->APU.squ[0].enabled = FALSE; |
| 561 | info->APU.squ[0].vbl_length = 0; |
| 562 | } |
| 559 | 563 | |
| 560 | | if (value & 0x02) |
| 561 | | info->APU.squ[1].enabled = TRUE; |
| 562 | | else |
| 563 | | { |
| 564 | | info->APU.squ[1].enabled = FALSE; |
| 565 | | info->APU.squ[1].vbl_length = 0; |
| 566 | | } |
| 564 | if (value & 0x02) |
| 565 | info->APU.squ[1].enabled = TRUE; |
| 566 | else |
| 567 | { |
| 568 | info->APU.squ[1].enabled = FALSE; |
| 569 | info->APU.squ[1].vbl_length = 0; |
| 570 | } |
| 567 | 571 | |
| 568 | | if (value & 0x04) |
| 569 | | info->APU.tri.enabled = TRUE; |
| 570 | | else |
| 571 | | { |
| 572 | | info->APU.tri.enabled = FALSE; |
| 573 | | info->APU.tri.vbl_length = 0; |
| 574 | | info->APU.tri.linear_length = 0; |
| 575 | | info->APU.tri.counter_started = FALSE; |
| 576 | | info->APU.tri.write_latency = 0; |
| 577 | | } |
| 572 | if (value & 0x04) |
| 573 | info->APU.tri.enabled = TRUE; |
| 574 | else |
| 575 | { |
| 576 | info->APU.tri.enabled = FALSE; |
| 577 | info->APU.tri.vbl_length = 0; |
| 578 | info->APU.tri.linear_length = 0; |
| 579 | info->APU.tri.counter_started = FALSE; |
| 580 | info->APU.tri.write_latency = 0; |
| 581 | } |
| 578 | 582 | |
| 579 | | if (value & 0x08) |
| 580 | | info->APU.noi.enabled = TRUE; |
| 581 | | else |
| 582 | | { |
| 583 | | info->APU.noi.enabled = FALSE; |
| 584 | | info->APU.noi.vbl_length = 0; |
| 585 | | } |
| 583 | if (value & 0x08) |
| 584 | info->APU.noi.enabled = TRUE; |
| 585 | else |
| 586 | { |
| 587 | info->APU.noi.enabled = FALSE; |
| 588 | info->APU.noi.vbl_length = 0; |
| 589 | } |
| 586 | 590 | |
| 587 | | if (value & 0x10) |
| 588 | | { |
| 589 | | /* only reset dpcm values if DMA is finished */ |
| 590 | | if (FALSE == info->APU.dpcm.enabled) |
| 591 | | { |
| 592 | | info->APU.dpcm.enabled = TRUE; |
| 593 | | apu_dpcmreset(&info->APU.dpcm); |
| 594 | | } |
| 595 | | } |
| 596 | | else |
| 597 | | info->APU.dpcm.enabled = FALSE; |
| 591 | if (value & 0x10) |
| 592 | { |
| 593 | /* only reset dpcm values if DMA is finished */ |
| 594 | if (FALSE == info->APU.dpcm.enabled) |
| 595 | { |
| 596 | info->APU.dpcm.enabled = TRUE; |
| 597 | apu_dpcmreset(&info->APU.dpcm); |
| 598 | } |
| 599 | } |
| 600 | else |
| 601 | info->APU.dpcm.enabled = FALSE; |
| 598 | 602 | |
| 599 | | info->APU.dpcm.irq_occurred = FALSE; |
| 603 | info->APU.dpcm.irq_occurred = FALSE; |
| 600 | 604 | |
| 601 | | break; |
| 602 | | default: |
| 605 | break; |
| 606 | default: |
| 603 | 607 | #ifdef MAME_DEBUG |
| 604 | 608 | logerror("invalid apu write: $%02X at $%04X\n", value, address); |
| 605 | 609 | #endif |
| 606 | | break; |
| 607 | | } |
| 610 | break; |
| 611 | } |
| 608 | 612 | } |
| 609 | 613 | |
| 610 | 614 | /* UPDATE SOUND BUFFER USING CURRENT DATA */ |
| 611 | 615 | INLINE void apu_update(nesapu_state *info, stream_sample_t *buffer16, int samples) |
| 612 | 616 | { |
| 613 | | int accum; |
| 617 | int accum; |
| 614 | 618 | |
| 615 | | while (samples--) |
| 616 | | { |
| 617 | | accum = apu_square(info, &info->APU.squ[0]); |
| 618 | | accum += apu_square(info, &info->APU.squ[1]); |
| 619 | | accum += apu_triangle(info, &info->APU.tri); |
| 620 | | accum += apu_noise(info, &info->APU.noi); |
| 621 | | accum += apu_dpcm(info, &info->APU.dpcm); |
| 619 | while (samples--) |
| 620 | { |
| 621 | accum = apu_square(info, &info->APU.squ[0]); |
| 622 | accum += apu_square(info, &info->APU.squ[1]); |
| 623 | accum += apu_triangle(info, &info->APU.tri); |
| 624 | accum += apu_noise(info, &info->APU.noi); |
| 625 | accum += apu_dpcm(info, &info->APU.dpcm); |
| 622 | 626 | |
| 623 | | /* 8-bit clamps */ |
| 624 | | if (accum > 127) |
| 625 | | accum = 127; |
| 626 | | else if (accum < -128) |
| 627 | | accum = -128; |
| 627 | /* 8-bit clamps */ |
| 628 | if (accum > 127) |
| 629 | accum = 127; |
| 630 | else if (accum < -128) |
| 631 | accum = -128; |
| 628 | 632 | |
| 629 | | *(buffer16++)=accum<<8; |
| 630 | | } |
| 633 | *(buffer16++)=accum<<8; |
| 634 | } |
| 631 | 635 | } |
| 632 | 636 | |
| 633 | 637 | /* READ VALUES FROM REGISTERS */ |
| 634 | 638 | INLINE uint8 apu_read(nesapu_state *info,int address) |
| 635 | 639 | { |
| 636 | | if (address == 0x0f) /*FIXED* Address $4015 has different behaviour*/ |
| 640 | if (address == 0x15) /*FIXED* Address $4015 has different behaviour*/ |
| 637 | 641 | { |
| 638 | | int readval = 0; |
| 639 | | if ( info->APU.dpcm.enabled == TRUE ) |
| 640 | | { |
| 641 | | readval |= 0x10; |
| 642 | | } |
| 642 | int readval = 0; |
| 643 | if (info->APU.squ[0].vbl_length > 0) |
| 644 | readval |= 0x01; |
| 643 | 645 | |
| 644 | | if ( info->APU.dpcm.irq_occurred == TRUE ) |
| 645 | | { |
| 646 | | readval |= 0x80; |
| 647 | | } |
| 648 | | return readval; |
| 649 | | } |
| 650 | | else |
| 651 | | return info->APU.regs[address]; |
| 646 | if (info->APU.squ[1].vbl_length > 0) |
| 647 | readval |= 0x02; |
| 648 | |
| 649 | if (info->APU.tri.vbl_length > 0) |
| 650 | readval |= 0x04; |
| 651 | |
| 652 | if (info->APU.noi.vbl_length > 0) |
| 653 | readval |= 0x08; |
| 654 | |
| 655 | if (info->APU.dpcm.enabled == TRUE) |
| 656 | readval |= 0x10; |
| 657 | |
| 658 | if (info->APU.dpcm.irq_occurred == TRUE) |
| 659 | readval |= 0x80; |
| 660 | |
| 661 | return readval; |
| 662 | } |
| 663 | else |
| 664 | return info->APU.regs[address]; |
| 652 | 665 | } |
| 653 | 666 | |
| 654 | 667 | /* WRITE VALUE TO TEMP REGISTRY AND QUEUE EVENT */ |
| 655 | 668 | INLINE void apu_write(nesapu_state *info,int address, uint8 value) |
| 656 | 669 | { |
| 657 | | info->APU.regs[address]=value; |
| 658 | | stream_update(info->stream); |
| 659 | | apu_regwrite(info,address,value); |
| 670 | info->APU.regs[address]=value; |
| 671 | stream_update(info->stream); |
| 672 | apu_regwrite(info,address,value); |
| 660 | 673 | } |
| 661 | 674 | |
| 662 | 675 | /* EXTERNAL INTERFACE FUNCTIONS */ |
| r5357 | r5358 | |
| 753 | 766 | state_save_register_device_item(device, 0, info->APU.tail); |
| 754 | 767 | #else |
| 755 | 768 | state_save_register_device_item(device, 0, info->APU.buf_pos); |
| 769 | state_save_register_device_item(device, 0, info->APU.step_mode); |
| 756 | 770 | #endif |
| 757 | 771 | } |
| 758 | 772 | |
src/mess/machine/nes_mmc.c
| r5357 | r5358 | |
| 7 | 7 | . 67 display issues, but vrom fixed |
| 8 | 8 | . 70 (ark2j) starts on round 0 - is this right? Yep! |
| 9 | 9 | . 82 has chr-rom banking problems. Also mapper is in the middle of sram, which is unemulated. |
| 10 | . 95 doesn't match documentation |
| 10 | 11 | . 96 is preliminary. |
| 11 | 12 | . 118 mirroring is a guess, chr-rom banking is likely different |
| 13 | . 164 preliminary - no sprites? |
| 12 | 14 | . 228 seems wrong |
| 13 | 15 | . 229 is preliminary |
| 14 | 16 | . 230 not working yet |
| r5357 | r5358 | |
| 50 | 52 | #define CIRAM 0 |
| 51 | 53 | #define ROM 1 |
| 52 | 54 | #define EXRAM 2 |
| 55 | #define MMC5FILL 3 |
| 56 | #define CART_NTRAM 4 |
| 53 | 57 | |
| 54 | 58 | typedef struct |
| 55 | 59 | { |
| 56 | | int source; //defines source of base pointer |
| 57 | | int origin; //defines offset of 0x400 byte segment at base pointer |
| 58 | | int writable; //ExRAM, at least, can be write-protected AND used as nametable |
| 59 | | UINT8* access; //source translated + origin -> valid pointer! |
| 60 | int source; /* defines source of base pointer */ |
| 61 | int origin; /* defines offset of 0x400 byte segment at base pointer */ |
| 62 | int writable; /* ExRAM, at least, can be write-protected AND used as nametable */ |
| 63 | UINT8* access; /* direct access when possible */ |
| 60 | 64 | } name_table; |
| 61 | 65 | |
| 62 | 66 | /* Global variables */ |
| r5357 | r5358 | |
| 99 | 103 | static int MMC3_chr[6]; |
| 100 | 104 | static int MMC3_prg_base, MMC3_prg_mask; |
| 101 | 105 | static int MMC3_chr_base, MMC3_chr_mask; |
| 106 | UINT8* extended_ntram; |
| 102 | 107 | |
| 103 | 108 | static int MMC5_rom_bank_mode; |
| 104 | 109 | static int MMC5_vrom_bank_mode; |
| 105 | 110 | static int MMC5_vram_protect; |
| 106 | 111 | static int MMC5_scanline; |
| 112 | static int MMC5_floodtile; |
| 113 | static int MMC5_floodattr; |
| 107 | 114 | UINT8 MMC5_vram[0x400]; |
| 108 | 115 | int MMC5_vram_control; |
| 109 | 116 | |
| r5357 | r5358 | |
| 158 | 165 | READ8_HANDLER(nes_nt_r) |
| 159 | 166 | { |
| 160 | 167 | int page = ((offset & 0xc00) >> 10); |
| 168 | if (nt_page[page].source == MMC5FILL) |
| 169 | { |
| 170 | if ((offset & 0x3ff) >= 0x3c0) |
| 171 | return MMC5_floodattr; |
| 161 | 172 | |
| 173 | return MMC5_floodtile; |
| 174 | } |
| 162 | 175 | return nt_page[page].access[offset & 0x3ff]; |
| 163 | 176 | } |
| 164 | 177 | |
| r5357 | r5358 | |
| 246 | 259 | * Some helpful routines used by the mappers |
| 247 | 260 | */ |
| 248 | 261 | |
| 249 | | static void ppu_mirror_custom( int page, int address ) |
| 250 | | { |
| 251 | | logerror("Unimplemented: custom NT mirroring"); |
| 252 | | } |
| 253 | | |
| 254 | 262 | static void ppu_mirror_MMC5( int page, int src ) |
| 255 | 263 | { |
| 256 | 264 | switch(src) |
| r5357 | r5358 | |
| 264 | 272 | case 2: /* ExRAM */ |
| 265 | 273 | set_nt_page(page, EXRAM, 0, 1); // actually only works during rendering. |
| 266 | 274 | break; |
| 267 | | case 3: /* FillRegisters -useless without dot-based PPU, in general */ |
| 275 | case 3: /* Fill Registers */ |
| 276 | set_nt_page(page, MMC5FILL, 0, 0); |
| 277 | break; |
| 268 | 278 | default: |
| 269 | | logerror("Unimplemented: Fill support"); |
| 279 | fatalerror("This should never happen"); |
| 270 | 280 | break; |
| 271 | 281 | } |
| 272 | 282 | } |
| r5357 | r5358 | |
| 363 | 373 | |
| 364 | 374 | switch (source) |
| 365 | 375 | { |
| 376 | case CART_NTRAM: |
| 377 | base_ptr = extended_ntram; |
| 378 | break; |
| 379 | case MMC5FILL: |
| 380 | base_ptr = NULL; |
| 381 | break; |
| 366 | 382 | case ROM: |
| 367 | 383 | base_ptr = nes.vrom; |
| 368 | 384 | break; |
| 369 | | |
| 370 | 385 | case EXRAM: |
| 371 | | base_ptr = nes.exram; |
| 386 | base_ptr = MMC5_vram; |
| 372 | 387 | break; |
| 373 | | |
| 374 | 388 | case CIRAM: |
| 375 | 389 | default: |
| 376 | 390 | base_ptr = nes.ciram; |
| 377 | 391 | break; |
| 378 | 392 | } |
| 379 | 393 | |
| 380 | | page &= 3; // mask down to the 4 logical pages |
| 394 | page &= 3; /* mask down to the 4 logical pages */ |
| 381 | 395 | nt_page[page].source = source; |
| 382 | | nt_page[page].origin = bank * 0x400; |
| 383 | | nt_page[page].access = base_ptr + nt_page[page].origin; |
| 396 | if(NULL != base_ptr) |
| 397 | { |
| 398 | nt_page[page].origin = bank * 0x400; |
| 399 | nt_page[page].access = base_ptr + nt_page[page].origin; |
| 400 | } |
| 384 | 401 | nt_page[page].writable = writable; |
| 385 | 402 | } |
| 386 | 403 | |
| r5357 | r5358 | |
| 422 | 439 | default: |
| 423 | 440 | /* external RAM needs to be used somehow. */ |
| 424 | 441 | /* but as a default, we'll arbitrarily set vertical so as not to crash*/ |
| 442 | /* mappers should use set_nt_page and assign which pages are which */ |
| 443 | |
| 425 | 444 | logerror("Mapper set 4-screen mirroring without supplying external nametable memory!\n"); |
| 426 | 445 | |
| 427 | 446 | set_nt_page(0, CIRAM, 0, 1); |
| r5357 | r5358 | |
| 683 | 702 | int bank = MMC1_reg & (nes.chr_chunks - 1); |
| 684 | 703 | //int bank = MMC1_reg & ((nes.chr_chunks << 1) - 1); |
| 685 | 704 | chr8(space->machine, bank>>1, CHRROM); |
| 686 | | // ppu2c0x_set_videorom_bank(state->ppu, 0, 8, bank, 256); |
| 687 | 705 | LOG_MMC(("MMC1 8k VROM switch: %02x\n", MMC1_reg)); |
| 688 | 706 | } |
| 689 | 707 | else |
| 690 | 708 | { |
| 691 | 709 | int bank = MMC1_reg & ((nes.chr_chunks << 1) - 1); |
| 692 | 710 | chr4_0(space->machine,bank, CHRROM); |
| 693 | | // ppu2c0x_set_videorom_bank(state->ppu, 0, 4, bank, 256); |
| 694 | 711 | LOG_MMC(("MMC1 4k VROM switch (low): %02x\n", MMC1_reg)); |
| 695 | 712 | } |
| 696 | 713 | } |
| r5357 | r5358 | |
| 718 | 735 | { |
| 719 | 736 | int bank = MMC1_reg & ((nes.chr_chunks << 1) - 1); |
| 720 | 737 | chr4_4(space->machine, bank, CHRROM); |
| 721 | | //ppu2c0x_set_videorom_bank(state->ppu, 4, 4, bank, 256); |
| 722 | 738 | LOG_MMC(("MMC1 4k VROM switch (high): %02x\n", MMC1_reg)); |
| 723 | 739 | } |
| 724 | 740 | break; |
| r5357 | r5358 | |
| 826 | 842 | |
| 827 | 843 | static void mapper4_set_chr (running_machine *machine) |
| 828 | 844 | { |
| 829 | | //nes_state *state = machine->driver_data; |
| 830 | 845 | UINT8 chr_page = (MMC3_cmd & 0x80) >> 5; |
| 831 | 846 | |
| 832 | 847 | chr2_x(machine, chr_page ^ 0, MMC3_chr_base | ( (MMC3_chr[0]>>1) & ( MMC3_chr_mask ) ), CHRROM); |
| r5357 | r5358 | |
| 835 | 850 | chr1_x(machine, chr_page ^5, MMC3_chr_base | (MMC3_chr[3]& ( MMC3_chr_mask ) ), CHRROM); |
| 836 | 851 | chr1_x(machine, chr_page ^6, MMC3_chr_base | (MMC3_chr[4]& ( MMC3_chr_mask ) ), CHRROM); |
| 837 | 852 | chr1_x(machine, chr_page ^7, MMC3_chr_base | (MMC3_chr[5]& ( MMC3_chr_mask ) ), CHRROM); |
| 838 | | //ppu2c0x_set_videorom_bank(state->ppu, chr_page ^ 0, 2, MMC3_chr_base * 64 | ( MMC3_chr[0] & ( MMC3_chr_mask * 64 ) ), 1); |
| 839 | | //ppu2c0x_set_videorom_bank(state->ppu, chr_page ^ 2, 2, MMC3_chr_base * 64 | ( MMC3_chr[1] & ( MMC3_chr_mask * 64 ) ), 1); |
| 840 | | //ppu2c0x_set_videorom_bank(state->ppu, chr_page ^ 4, 1, MMC3_chr_base * 64 | ( MMC3_chr[2] & ( MMC3_chr_mask * 64 ) ), 1); |
| 841 | | //ppu2c0x_set_videorom_bank(state->ppu, chr_page ^ 5, 1, MMC3_chr_base * 64 | ( MMC3_chr[3] & ( MMC3_chr_mask * 64 ) ), 1); |
| 842 | | //ppu2c0x_set_videorom_bank(state->ppu, chr_page ^ 6, 1, MMC3_chr_base * 64 | ( MMC3_chr[4] & ( MMC3_chr_mask * 64 ) ), 1); |
| 843 | | //ppu2c0x_set_videorom_bank(state->ppu, chr_page ^ 7, 1, MMC3_chr_base * 64 | ( MMC3_chr[5] & ( MMC3_chr_mask * 64 ) ), 1); |
| 844 | 853 | } |
| 845 | 854 | |
| 846 | 855 | static void mapper4_irq ( const device_config *device, int scanline, int vblank, int blanked ) |
| r5357 | r5358 | |
| 963 | 972 | |
| 964 | 973 | static WRITE8_HANDLER( mapper118_w ) |
| 965 | 974 | { |
| 966 | | //nes_state *state = space->machine->driver_data; |
| 967 | 975 | static UINT8 last_bank = 0xff; |
| 968 | 976 | |
| 969 | 977 | // logerror("mapper4_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline); |
| r5357 | r5358 | |
| 1060 | 1068 | UINT8 chr_page = (MMC3_cmd & 0x80) >> 5; |
| 1061 | 1069 | if(MMC3_chr[0]&0x40) |
| 1062 | 1070 | chr2_x(machine, chr_page ^ 0, (MMC3_chr[0]>>1)&3, CHRRAM); |
| 1063 | | else chr2_x(machine, chr_page ^ 0, ((MMC3_chr[0])>>1), CHRROM); |
| 1071 | else chr2_x(machine, chr_page ^ 0, ((MMC3_chr[0]&0x3f)>>1), CHRROM); |
| 1064 | 1072 | if(MMC3_chr[1]&0x40) |
| 1065 | 1073 | chr2_x(machine, chr_page ^ 2, (MMC3_chr[1]>>1)&3, CHRRAM); |
| 1066 | | else chr2_x(machine, chr_page ^ 2, (MMC3_chr[1]>>1), CHRROM); |
| 1074 | else chr2_x(machine, chr_page ^ 2, ((MMC3_chr[1]&0x3f)>>1), CHRROM); |
| 1067 | 1075 | if(MMC3_chr[2]&0x40) |
| 1068 | 1076 | chr1_x(machine, chr_page ^ 4, MMC3_chr[2]&7, CHRRAM); |
| 1069 | | else chr1_x(machine, chr_page ^ 4, MMC3_chr[2], CHRROM); |
| 1077 | else chr1_x(machine, chr_page ^ 4, MMC3_chr[2]&0x3f, CHRROM); |
| 1070 | 1078 | |
| 1071 | 1079 | if(MMC3_chr[3]&0x40) |
| 1072 | 1080 | chr1_x(machine, chr_page ^ 5, MMC3_chr[3]&7, CHRRAM); |
| 1073 | | else chr1_x(machine, chr_page ^ 5, MMC3_chr[3], CHRROM); |
| 1081 | else chr1_x(machine, chr_page ^ 5, MMC3_chr[3]&0x3f, CHRROM); |
| 1074 | 1082 | if(MMC3_chr[4]&0x40) |
| 1075 | 1083 | chr1_x(machine, chr_page ^ 6, MMC3_chr[4]&7, CHRRAM); |
| 1076 | | else chr1_x(machine, chr_page ^ 6, MMC3_chr[4], CHRROM); |
| 1084 | else chr1_x(machine, chr_page ^ 6, MMC3_chr[4]&0x3f, CHRROM); |
| 1077 | 1085 | if(MMC3_chr[5]&0x40) |
| 1078 | 1086 | chr1_x(machine, chr_page ^ 7, MMC3_chr[5]&7, CHRRAM); |
| 1079 | | else chr1_x(machine, chr_page ^ 7, MMC3_chr[5], CHRROM); |
| 1087 | else chr1_x(machine, chr_page ^ 7, MMC3_chr[5]&0x3f, CHRROM); |
| 1080 | 1088 | } |
| 1081 | 1089 | |
| 1082 | 1090 | static WRITE8_HANDLER( mapper119_w ) |
| 1083 | 1091 | { |
| 1084 | | //nes_state *state = space->machine->driver_data; |
| 1085 | 1092 | static UINT8 last_bank = 0xff; |
| 1086 | 1093 | |
| 1087 | 1094 | // logerror("mapper4_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline); |
| r5357 | r5358 | |
| 1097 | 1104 | { |
| 1098 | 1105 | /* Reset the banks */ |
| 1099 | 1106 | mapper4_set_prg (space); |
| 1100 | | mapper4_set_chr (space->machine); |
| 1107 | mapper119_set_chr (space->machine); |
| 1101 | 1108 | LOG_MMC((" MMC3 reset banks\n")); |
| 1102 | 1109 | } |
| 1103 | 1110 | last_bank = data & 0xc0; |
| r5357 | r5358 | |
| 1109 | 1116 | switch (cmd) |
| 1110 | 1117 | { |
| 1111 | 1118 | case 0: case 1: |
| 1112 | | //data &= 0xfe; |
| 1113 | 1119 | MMC3_chr[cmd] = data; |
| 1114 | 1120 | mapper119_set_chr (space->machine); |
| 1115 | 1121 | LOG_MMC((" MMC3 set vram %d: %d\n", cmd, data)); |
| 1116 | 1122 | break; |
| 1117 | 1123 | |
| 1118 | 1124 | case 2: case 3: case 4: case 5: |
| 1119 | | MMC3_chr[cmd] = data;// * 64; |
| 1125 | MMC3_chr[cmd] = data; |
| 1120 | 1126 | mapper119_set_chr (space->machine); |
| 1121 | 1127 | LOG_MMC((" MMC3 set vram %d: %d\n", cmd, data)); |
| 1122 | 1128 | break; |
| r5357 | r5358 | |
| 1199 | 1205 | { |
| 1200 | 1206 | int retVal; |
| 1201 | 1207 | |
| 1202 | | #ifdef MMC5_VRAM |
| 1203 | 1208 | /* $5c00 - $5fff: extended videoram attributes */ |
| 1204 | 1209 | if ((offset >= 0x1b00) && (offset <= 0x1eff)) |
| 1205 | 1210 | { |
| 1206 | 1211 | return MMC5_vram[offset - 0x1b00]; |
| 1207 | 1212 | } |
| 1208 | | #endif |
| 1209 | 1213 | |
| 1210 | 1214 | switch (offset) |
| 1211 | 1215 | { |
| r5357 | r5358 | |
| 1256 | 1260 | return; |
| 1257 | 1261 | } |
| 1258 | 1262 | |
| 1259 | | #ifdef MMC5_VRAM |
| 1260 | 1263 | /* $5c00 - $5fff: extended videoram attributes */ |
| 1261 | 1264 | if ((offset >= 0x1b00) && (offset <= 0x1eff)) |
| 1262 | 1265 | { |
| r5357 | r5358 | |
| 1264 | 1267 | MMC5_vram[offset - 0x1b00] = data; |
| 1265 | 1268 | return; |
| 1266 | 1269 | } |
| 1267 | | #endif |
| 1268 | 1270 | |
| 1269 | 1271 | switch (offset) |
| 1270 | 1272 | { |
| r5357 | r5358 | |
| 1305 | 1307 | ppu_mirror_MMC5 (3, (data & 0xc0) >> 6); |
| 1306 | 1308 | break; |
| 1307 | 1309 | |
| 1308 | | /* $5106 - Fill mode: Tile bits ?? cv3 sets to 0 */ |
| 1309 | | /* $5107 - Fill mode: Attr bits?? cv3 sets to 0 */ |
| 1310 | /* tile data for MMC5 flood-fill NT mode */ |
| 1311 | case 0x1006: |
| 1312 | MMC5_floodtile=data; |
| 1313 | break; |
| 1310 | 1314 | |
| 1315 | /* attr data for MMC5 flood-fill NT mode */ |
| 1316 | case 0x1007: |
| 1317 | switch (data & 3) |
| 1318 | { |
| 1319 | default: |
| 1320 | case 0: MMC5_floodattr = 0x00; break; |
| 1321 | case 1: MMC5_floodattr = 0x55; break; |
| 1322 | case 2: MMC5_floodattr = 0xaa; break; |
| 1323 | case 3: MMC5_floodattr = 0xff; break; |
| 1324 | } |
| 1325 | break; |
| 1326 | |
| 1311 | 1327 | case 0x1013: /* $5113 */ |
| 1312 | 1328 | logerror ("MMC5 mid RAM bank select: %02x\n", data & 0x07); |
| 1313 | 1329 | memory_set_bankptr (space->machine, 5, &nes.wram[data * 0x2000]); |
| r5357 | r5358 | |
| 1656 | 1672 | { |
| 1657 | 1673 | case 0x00: |
| 1658 | 1674 | /* 8k switch */ |
| 1659 | | chr8 (space->machine, data, CHRROM); |
| 1675 | /* switches in first half of an 8K bank!) */ |
| 1676 | chr4_0 (space->machine, data << 1, CHRROM); |
| 1677 | chr4_4 (space->machine, data << 1, CHRROM); |
| 1660 | 1678 | break; |
| 1661 | 1679 | case 0x01: |
| 1662 | 1680 | /* 4k switch */ |
| r5357 | r5358 | |
| 1960 | 1978 | |
| 1961 | 1979 | switch (offset & 0x000f) |
| 1962 | 1980 | { |
| 1963 | | //use new utility functions for bounds checks! |
| 1964 | 1981 | case 0: |
| 1965 | 1982 | case 1: |
| 1966 | 1983 | case 2: |
| r5357 | r5358 | |
| 2154 | 2171 | vrom_bank[0] = (vrom_bank[0] & 0xf0) | (data & 0x0f); |
| 2155 | 2172 | vrom_bank[0] &= ((nes.chr_chunks << 3) - 1); |
| 2156 | 2173 | chr1_0(space->machine, vrom_bank[0], CHRROM); |
| 2157 | | // ppu2c0x_set_videorom_bank(state->ppu, 0, 1, vrom_bank[0], 64); |
| 2158 | 2174 | break; |
| 2159 | 2175 | case 0x2001: |
| 2160 | 2176 | /* Switch 1k vrom at $0000 - high 4 bits */ |
| 2161 | 2177 | vrom_bank[0] = (vrom_bank[0] & 0x0f) | (data << 4); |
| 2162 | 2178 | vrom_bank[0] &= ((nes.chr_chunks << 3) - 1); |
| 2163 | 2179 | chr1_0(space->machine, vrom_bank[0], CHRROM); |
| 2164 | | // ppu2c0x_set_videorom_bank(state->ppu, 0, 1, vrom_bank[0], 64); |
| 2165 | 2180 | break; |
| 2166 | 2181 | case 0x2002: |
| 2167 | 2182 | /* Switch 1k vrom at $0400 - low 4 bits */ |
| 2168 | 2183 | vrom_bank[1] = (vrom_bank[1] & 0xf0) | (data & 0x0f); |
| 2169 | 2184 | vrom_bank[1] &= ((nes.chr_chunks << 3) - 1); |
| 2170 | 2185 | chr1_1(space->machine, vrom_bank[1], CHRROM); |
| 2171 | | // ppu2c0x_set_videorom_bank(state->ppu, 1, 1, vrom_bank[1], 64); |
| 2172 | 2186 | break; |
| 2173 | 2187 | case 0x2003: |
| 2174 | 2188 | /* Switch 1k vrom at $0400 - high 4 bits */ |
| 2175 | 2189 | vrom_bank[1] = (vrom_bank[1] & 0x0f) | (data << 4); |
| 2176 | 2190 | vrom_bank[1] &= ((nes.chr_chunks << 3) - 1); |
| 2177 | 2191 | chr1_1(space->machine, vrom_bank[1], CHRROM); |
| 2178 | | // ppu2c0x_set_videorom_bank(state->ppu, 1, 1, vrom_bank[1], 64); |
| 2179 | 2192 | break; |
| 2180 | 2193 | case 0x3000: |
| 2181 | 2194 | /* Switch 1k vrom at $0800 - low 4 bits */ |
| 2182 | 2195 | vrom_bank[2] = (vrom_bank[2] & 0xf0) | (data & 0x0f); |
| 2183 | 2196 | vrom_bank[2] &= ((nes.chr_chunks << 3) - 1); |
| 2184 | 2197 | chr1_2(space->machine, vrom_bank[2], CHRROM); |
| 2185 | | // ppu2c0x_set_videorom_bank(state->ppu, 2, 1, vrom_bank[2], 64); |
| 2186 | 2198 | break; |
| 2187 | 2199 | case 0x3001: |
| 2188 | 2200 | /* Switch 1k vrom at $0800 - high 4 bits */ |
| 2189 | 2201 | vrom_bank[2] = (vrom_bank[2] & 0x0f) | (data << 4); |
| 2190 | 2202 | vrom_bank[2] &= ((nes.chr_chunks << 3) - 1); |
| 2191 | 2203 | chr1_2(space->machine, vrom_bank[2], CHRROM); |
| 2192 | | // ppu2c0x_set_videorom_bank(state->ppu, 2, 1, vrom_bank[2], 64); |
| 2193 | 2204 | break; |
| 2194 | 2205 | case 0x3002: |
| 2195 | 2206 | /* Switch 1k vrom at $0c00 - low 4 bits */ |
| 2196 | 2207 | vrom_bank[3] = (vrom_bank[3] & 0xf0) | (data & 0x0f); |
| 2197 | 2208 | vrom_bank[3] &= ((nes.chr_chunks << 3) - 1); |
| 2198 | 2209 | chr1_3(space->machine, vrom_bank[3], CHRROM); |
| 2199 | | // ppu2c0x_set_videorom_bank(state->ppu, 3, 1, vrom_bank[3], 64); |
| 2200 | 2210 | break; |
| 2201 | 2211 | case 0x3003: |
| 2202 | 2212 | /* Switch 1k vrom at $0c00 - high 4 bits */ |
| 2203 | 2213 | vrom_bank[3] = (vrom_bank[3] & 0x0f) | (data << 4); |
| 2204 | 2214 | vrom_bank[3] &= ((nes.chr_chunks << 3) - 1); |
| 2205 | 2215 | chr1_3(space->machine, vrom_bank[3], CHRROM); |
| 2206 | | // ppu2c0x_set_videorom_bank(state->ppu, 3, 1, vrom_bank[3], 64); |
| 2207 | 2216 | break; |
| 2208 | 2217 | case 0x4000: |
| 2209 | 2218 | /* Switch 1k vrom at $1000 - low 4 bits */ |
| 2210 | 2219 | vrom_bank[4] = (vrom_bank[4] & 0xf0) | (data & 0x0f); |
| 2211 | 2220 | vrom_bank[4] &= ((nes.chr_chunks << 3) - 1); |
| 2212 | 2221 | chr1_4(space->machine, vrom_bank[4], CHRROM); |
| 2213 | | // ppu2c0x_set_videorom_bank(state->ppu, 4, 1, vrom_bank[4], 64); |
| 2214 | 2222 | break; |
| 2215 | 2223 | case 0x4001: |
| 2216 | 2224 | /* Switch 1k vrom at $1000 - high 4 bits */ |
| 2217 | 2225 | vrom_bank[4] = (vrom_bank[4] & 0x0f) | (data << 4); |
| 2218 | 2226 | vrom_bank[4] &= ((nes.chr_chunks << 3) - 1); |
| 2219 | 2227 | chr1_4(space->machine, vrom_bank[4], CHRROM); |
| 2220 | | // ppu2c0x_set_videorom_bank(state->ppu, 4, 1, vrom_bank[4], 64); |
| 2221 | 2228 | break; |
| 2222 | 2229 | case 0x4002: |
| 2223 | 2230 | /* Switch 1k vrom at $1400 - low 4 bits */ |
| 2224 | 2231 | vrom_bank[5] = (vrom_bank[5] & 0xf0) | (data & 0x0f); |
| 2225 | 2232 | vrom_bank[5] &= ((nes.chr_chunks << 3) - 1); |
| 2226 | 2233 | chr1_5(space->machine, vrom_bank[5], CHRROM); |
| 2227 | | // ppu2c0x_set_videorom_bank(state->ppu, 5, 1, vrom_bank[5], 64); |
| 2228 | 2234 | break; |
| 2229 | 2235 | case 0x4003: |
| 2230 | 2236 | /* Switch 1k vrom at $1400 - high 4 bits */ |
| 2231 | 2237 | vrom_bank[5] = (vrom_bank[5] & 0x0f) | (data << 4); |
| 2232 | 2238 | vrom_bank[5] &= ((nes.chr_chunks << 3) - 1); |
| 2233 | 2239 | chr1_5(space->machine, vrom_bank[5], CHRROM); |
| 2234 | | // ppu2c0x_set_videorom_bank(state->ppu, 5, 1, vrom_bank[5], 64); |
| 2235 | 2240 | break; |
| 2236 | 2241 | case 0x5000: |
| 2237 | 2242 | /* Switch 1k vrom at $1800 - low 4 bits */ |
| 2238 | 2243 | vrom_bank[6] = (vrom_bank[6] & 0xf0) | (data & 0x0f); |
| 2239 | 2244 | vrom_bank[6] &= ((nes.chr_chunks << 3) - 1); |
| 2240 | 2245 | chr1_6(space->machine, vrom_bank[6], CHRROM); |
| 2241 | | // ppu2c0x_set_videorom_bank(state->ppu, 6, 1, vrom_bank[6], 64); |
| 2242 | 2246 | break; |
| 2243 | 2247 | case 0x5001: |
| 2244 | 2248 | /* Switch 1k vrom at $1800 - high 4 bits */ |
| 2245 | 2249 | vrom_bank[6] = (vrom_bank[6] & 0x0f) | (data << 4); |
| 2246 | 2250 | vrom_bank[6] &= ((nes.chr_chunks << 3) - 1); |
| 2247 | 2251 | chr1_6(space->machine, vrom_bank[6], CHRROM); |
| 2248 | | // ppu2c0x_set_videorom_bank(state->ppu, 6, 1, vrom_bank[6], 64); |
| 2249 | 2252 | break; |
| 2250 | 2253 | case 0x5002: |
| 2251 | 2254 | /* Switch 1k vrom at $1c00 - low 4 bits */ |
| 2252 | 2255 | vrom_bank[7] = (vrom_bank[7] & 0xf0) | (data & 0x0f); |
| 2253 | 2256 | vrom_bank[7] &= ((nes.chr_chunks << 3) - 1); |
| 2254 | 2257 | chr1_7(space->machine, vrom_bank[7], CHRROM); |
| 2255 | | // ppu2c0x_set_videorom_bank(state->ppu, 7, 1, vrom_bank[7], 64); |
| 2256 | 2258 | break; |
| 2257 | 2259 | case 0x5003: |
| 2258 | 2260 | /* Switch 1k vrom at $1c00 - high 4 bits */ |
| 2259 | 2261 | vrom_bank[7] = (vrom_bank[7] & 0x0f) | (data << 4); |
| 2260 | 2262 | vrom_bank[7] &= ((nes.chr_chunks << 3) - 1); |
| 2261 | 2263 | chr1_7(space->machine, vrom_bank[7], CHRROM); |
| 2262 | | // ppu2c0x_set_videorom_bank(state->ppu, 7, 1, vrom_bank[7], 64); |
| 2263 | 2264 | break; |
| 2264 | 2265 | |
| 2265 | 2266 | /* LBO - these are unverified */ |
| r5357 | r5358 | |
| 2628 | 2629 | vrom_bank[0] = (vrom_bank[0] & 0xf0) | (data & 0x0f); |
| 2629 | 2630 | vrom_bank[0] &= ((nes.chr_chunks << 3) - 1); |
| 2630 | 2631 | chr1_0(space->machine, vrom_bank[0], CHRROM); |
| 2631 | | // ppu2c0x_set_videorom_bank(state->ppu, 0, 1, vrom_bank[0], 64); |
| 2632 | 2632 | break; |
| 2633 | 2633 | case 0x3001: |
| 2634 | 2634 | /* Switch 1k vrom at $0000 - high 4 bits */ |
| 2635 | 2635 | vrom_bank[0] = (vrom_bank[0] & 0x0f) | (data << 4); |
| 2636 | 2636 | vrom_bank[0] &= ((nes.chr_chunks << 3) - 1); |
| 2637 | 2637 | chr1_0(space->machine, vrom_bank[0], CHRROM); |
| 2638 | | // ppu2c0x_set_videorom_bank(state->ppu, 0, 1, vrom_bank[0], 64); |
| 2639 | 2638 | break; |
| 2640 | 2639 | case 0x3002: |
| 2641 | 2640 | /* Switch 1k vrom at $0400 - low 4 bits */ |
| 2642 | 2641 | vrom_bank[1] = (vrom_bank[1] & 0xf0) | (data & 0x0f); |
| 2643 | 2642 | vrom_bank[1] &= ((nes.chr_chunks << 3) - 1); |
| 2644 | 2643 | chr1_1(space->machine, vrom_bank[1], CHRROM); |
| 2645 | | // ppu2c0x_set_videorom_bank(state->ppu, 1, 1, vrom_bank[1], 64); |
| 2646 | 2644 | break; |
| 2647 | 2645 | case 0x3003: |
| 2648 | 2646 | /* Switch 1k vrom at $0400 - high 4 bits */ |
| 2649 | 2647 | vrom_bank[1] = (vrom_bank[1] & 0x0f) | (data << 4); |
| 2650 | 2648 | vrom_bank[1] &= ((nes.chr_chunks << 3) - 1); |
| 2651 | 2649 | chr1_1(space->machine, vrom_bank[1], CHRROM); |
| 2652 | | // ppu2c0x_set_videorom_bank(state->ppu, 1, 1, vrom_bank[1], 64); |
| 2653 | 2650 | break; |
| 2654 | 2651 | case 0x4000: |
| 2655 | 2652 | /* Switch 1k vrom at $0800 - low 4 bits */ |
| 2656 | 2653 | vrom_bank[2] = (vrom_bank[2] & 0xf0) | (data & 0x0f); |
| 2657 | 2654 | vrom_bank[2] &= ((nes.chr_chunks << 3) - 1); |
| 2658 | 2655 | chr1_2(space->machine, vrom_bank[2], CHRROM); |
| 2659 | | // ppu2c0x_set_videorom_bank(state->ppu, 2, 1, vrom_bank[2], 64); |
| 2660 | 2656 | break; |
| 2661 | 2657 | case 0x4001: |
| 2662 | 2658 | /* Switch 1k vrom at $0800 - high 4 bits */ |
| 2663 | 2659 | vrom_bank[2] = (vrom_bank[2] & 0x0f) | (data << 4); |
| 2664 | 2660 | vrom_bank[2] &= ((nes.chr_chunks << 3) - 1); |
| 2665 | 2661 | chr1_2(space->machine, vrom_bank[2], CHRROM); |
| 2666 | | // ppu2c0x_set_videorom_bank(state->ppu, 2, 1, vrom_bank[2], 64); |
| 2667 | 2662 | break; |
| 2668 | 2663 | case 0x4002: |
| 2669 | 2664 | /* Switch 1k vrom at $0c00 - low 4 bits */ |
| 2670 | 2665 | vrom_bank[3] = (vrom_bank[3] & 0xf0) | (data & 0x0f); |
| 2671 | 2666 | vrom_bank[3] &= ((nes.chr_chunks << 3) - 1); |
| 2672 | 2667 | chr1_3(space->machine, vrom_bank[3], CHRROM); |
| 2673 | | // ppu2c0x_set_videorom_bank(state->ppu, 3, 1, vrom_bank[3], 64); |
| 2674 | 2668 | break; |
| 2675 | 2669 | case 0x4003: |
| 2676 | 2670 | /* Switch 1k vrom at $0c00 - high 4 bits */ |
| 2677 | 2671 | vrom_bank[3] = (vrom_bank[3] & 0x0f) | (data << 4); |
| 2678 | 2672 | vrom_bank[3] &= ((nes.chr_chunks << 3) - 1); |
| 2679 | 2673 | chr1_3(space->machine, vrom_bank[3], CHRROM); |
| 2680 | | //ppu2c0x_set_videorom_bank(state->ppu, 3, 1, vrom_bank[3], 64); |
| 2681 | 2674 | break; |
| 2682 | 2675 | case 0x5000: |
| 2683 | 2676 | /* Switch 1k vrom at $1000 - low 4 bits */ |
| 2684 | 2677 | vrom_bank[4] = (vrom_bank[4] & 0xf0) | (data & 0x0f); |
| 2685 | 2678 | vrom_bank[4] &= ((nes.chr_chunks << 3) - 1); |
| 2686 | 2679 | chr1_4(space->machine, vrom_bank[4], CHRROM); |
| 2687 | | // ppu2c0x_set_videorom_bank(state->ppu, 4, 1, vrom_bank[4], 64); |
| 2688 | 2680 | break; |
| 2689 | 2681 | case 0x5001: |
| 2690 | 2682 | /* Switch 1k vrom at $1000 - high 4 bits */ |
| 2691 | 2683 | vrom_bank[4] = (vrom_bank[4] & 0x0f) | (data << 4); |
| 2692 | 2684 | vrom_bank[4] &= ((nes.chr_chunks << 3) - 1); |
| 2693 | 2685 | chr1_4(space->machine, vrom_bank[4], CHRROM); |
| 2694 | | // ppu2c0x_set_videorom_bank(state->ppu, 4, 1, vrom_bank[4], 64); |
| 2695 | 2686 | break; |
| 2696 | 2687 | case 0x5002: |
| 2697 | 2688 | /* Switch 1k vrom at $1400 - low 4 bits */ |
| 2698 | 2689 | vrom_bank[5] = (vrom_bank[5] & 0xf0) | (data & 0x0f); |
| 2699 | 2690 | vrom_bank[5] &= ((nes.chr_chunks << 3) - 1); |
| 2700 | 2691 | chr1_5(space->machine, vrom_bank[5], CHRROM); |
| 2701 | | // ppu2c0x_set_videorom_bank(state->ppu, 5, 1, vrom_bank[5], 64); |
| 2702 | 2692 | break; |
| 2703 | 2693 | case 0x5003: |
| 2704 | 2694 | /* Switch 1k vrom at $1400 - high 4 bits */ |
| 2705 | 2695 | vrom_bank[5] = (vrom_bank[5] & 0x0f) | (data << 4); |
| 2706 | 2696 | vrom_bank[5] &= ((nes.chr_chunks << 3) - 1); |
| 2707 | 2697 | chr1_5(space->machine, vrom_bank[5], CHRROM); |
| 2708 | | // ppu2c0x_set_videorom_bank(state->ppu, 5, 1, vrom_bank[5], 64); |
| 2709 | 2698 | break; |
| 2710 | 2699 | case 0x6000: |
| 2711 | 2700 | /* Switch 1k vrom at $1800 - low 4 bits */ |
| 2712 | 2701 | vrom_bank[6] = (vrom_bank[6] & 0xf0) | (data & 0x0f); |
| 2713 | 2702 | vrom_bank[6] &= ((nes.chr_chunks << 3) - 1); |
| 2714 | 2703 | chr1_6(space->machine, vrom_bank[6], CHRROM); |
| 2715 | | // ppu2c0x_set_videorom_bank(state->ppu, 6, 1, vrom_bank[6], 64); |
| 2716 | 2704 | break; |
| 2717 | 2705 | case 0x6001: |
| 2718 | 2706 | /* Switch 1k vrom at $1800 - high 4 bits */ |
| 2719 | 2707 | vrom_bank[6] = (vrom_bank[6] & 0x0f) | (data << 4); |
| 2720 | 2708 | vrom_bank[6] &= ((nes.chr_chunks << 3) - 1); |
| 2721 | 2709 | chr1_6(space->machine, vrom_bank[6], CHRROM); |
| 2722 | | // ppu2c0x_set_videorom_bank(state->ppu, 6, 1, vrom_bank[6], 64); |
| 2723 | 2710 | break; |
| 2724 | 2711 | case 0x6002: |
| 2725 | 2712 | /* Switch 1k vrom at $1c00 - low 4 bits */ |
| 2726 | 2713 | vrom_bank[7] = (vrom_bank[7] & 0xf0) | (data & 0x0f); |
| 2727 | 2714 | vrom_bank[7] &= ((nes.chr_chunks << 3) - 1); |
| 2728 | 2715 | chr1_7(space->machine, vrom_bank[7], CHRROM); |
| 2729 | | // ppu2c0x_set_videorom_bank(state->ppu, 7, 1, vrom_bank[7], 64); |
| 2730 | 2716 | break; |
| 2731 | 2717 | case 0x6003: |
| 2732 | 2718 | /* Switch 1k vrom at $1c00 - high 4 bits */ |
| 2733 | 2719 | vrom_bank[7] = (vrom_bank[7] & 0x0f) | (data << 4); |
| 2734 | 2720 | vrom_bank[7] &= ((nes.chr_chunks << 3) - 1); |
| 2735 | 2721 | chr1_7(space->machine, vrom_bank[7], CHRROM); |
| 2736 | | // ppu2c0x_set_videorom_bank(state->ppu, 7, 1, vrom_bank[7], 64); |
| 2737 | 2722 | break; |
| 2738 | 2723 | case 0x7000: |
| 2739 | 2724 | /* Set low 4 bits of latch */ |
| r5357 | r5358 | |
| 2788 | 2773 | vrom_bank[0] = (vrom_bank[0] & 0xf0) | (data & 0x0f); |
| 2789 | 2774 | vrom_bank[0] &= ((nes.chr_chunks << 3) - 1); |
| 2790 | 2775 | chr1_0(space->machine, vrom_bank[0], CHRROM); |
| 2791 | | // ppu2c0x_set_videorom_bank(state->ppu, 0, 1, vrom_bank[0], 64); |
| 2792 | 2776 | break; |
| 2793 | 2777 | case 0x3002: |
| 2794 | 2778 | /* Switch 1k vrom at $0000 - high 4 bits */ |
| 2795 | 2779 | vrom_bank[0] = (vrom_bank[0] & 0x0f) | (data << 4); |
| 2796 | 2780 | vrom_bank[0] &= ((nes.chr_chunks << 3) - 1); |
| 2797 | 2781 | chr1_0(space->machine, vrom_bank[0], CHRROM); |
| 2798 | | // ppu2c0x_set_videorom_bank(state->ppu, 0, 1, vrom_bank[0], 64); |
| 2799 | 2782 | break; |
| 2800 | 2783 | case 0x3001: |
| 2801 | 2784 | case 0x3004: |
| r5357 | r5358 | |
| 2803 | 2786 | vrom_bank[1] = (vrom_bank[1] & 0xf0) | (data & 0x0f); |
| 2804 | 2787 | vrom_bank[1] &= ((nes.chr_chunks << 3) - 1); |
| 2805 | 2788 | chr1_1(space->machine, vrom_bank[1], CHRROM); |
| 2806 | | // ppu2c0x_set_videorom_bank(state->ppu, 1, 1, vrom_bank[1], 64); |
| 2807 | 2789 | break; |
| 2808 | 2790 | case 0x3003: |
| 2809 | 2791 | case 0x3006: |
| r5357 | r5358 | |
| 2811 | 2793 | vrom_bank[1] = (vrom_bank[1] & 0x0f) | (data << 4); |
| 2812 | 2794 | vrom_bank[1] &= ((nes.chr_chunks << 3) - 1); |
| 2813 | 2795 | chr1_1(space->machine, vrom_bank[1], CHRROM); |
| 2814 | | // ppu2c0x_set_videorom_bank(state->ppu, 1, 1, vrom_bank[1], 64); |
| 2815 | 2796 | break; |
| 2816 | 2797 | case 0x4000: |
| 2817 | 2798 | /* Switch 1k vrom at $0800 - low 4 bits */ |
| 2818 | 2799 | vrom_bank[2] = (vrom_bank[2] & 0xf0) | (data & 0x0f); |
| 2819 | 2800 | vrom_bank[2] &= ((nes.chr_chunks << 3) - 1); |
| 2820 | 2801 | chr1_2(space->machine, vrom_bank[2], CHRROM); |
| 2821 | | // ppu2c0x_set_videorom_bank(state->ppu, 2, 1, vrom_bank[2], 64); |
| 2822 | 2802 | break; |
| 2823 | 2803 | case 0x4002: |
| 2824 | 2804 | /* Switch 1k vrom at $0800 - high 4 bits */ |
| 2825 | 2805 | vrom_bank[2] = (vrom_bank[2] & 0x0f) | (data << 4); |
| 2826 | 2806 | vrom_bank[2] &= ((nes.chr_chunks << 3) - 1); |
| 2827 | 2807 | chr1_2(space->machine, vrom_bank[2], CHRROM); |
| 2828 | | // ppu2c0x_set_videorom_bank(state->ppu, 2, 1, vrom_bank[2], 64); |
| 2829 | 2808 | break; |
| 2830 | 2809 | case 0x4001: |
| 2831 | 2810 | case 0x4004: |
| r5357 | r5358 | |
| 2833 | 2812 | vrom_bank[3] = (vrom_bank[3] & 0xf0) | (data & 0x0f); |
| 2834 | 2813 | vrom_bank[3] &= ((nes.chr_chunks << 3) - 1); |
| 2835 | 2814 | chr1_3(space->machine, vrom_bank[3], CHRROM); |
| 2836 | | // ppu2c0x_set_videorom_bank(state->ppu, 3, 1, vrom_bank[3], 64); |
| 2837 | 2815 | break; |
| 2838 | 2816 | case 0x4003: |
| 2839 | 2817 | case 0x4006: |
| r5357 | r5358 | |
| 2841 | 2819 | vrom_bank[3] = (vrom_bank[3] & 0x0f) | (data << 4); |
| 2842 | 2820 | vrom_bank[3] &= ((nes.chr_chunks << 3) - 1); |
| 2843 | 2821 | chr1_3(space->machine, vrom_bank[3], CHRROM); |
| 2844 | | // ppu2c0x_set_videorom_bank(state->ppu, 3, 1, vrom_bank[3], 64); |
| 2845 | 2822 | break; |
| 2846 | 2823 | case 0x5000: |
| 2847 | 2824 | /* Switch 1k vrom at $1000 - low 4 bits */ |
| 2848 | 2825 | vrom_bank[4] = (vrom_bank[4] & 0xf0) | (data & 0x0f); |
| 2849 | 2826 | vrom_bank[4] &= ((nes.chr_chunks << 3) - 1); |
| 2850 | 2827 | chr1_4(space->machine, vrom_bank[4], CHRROM); |
| 2851 | | // ppu2c0x_set_videorom_bank(state->ppu, 4, 1, vrom_bank[4], 64); |
| 2852 | 2828 | break; |
| 2853 | 2829 | case 0x5002: |
| 2854 | 2830 | /* Switch 1k vrom at $1000 - high 4 bits */ |
| 2855 | 2831 | vrom_bank[4] = (vrom_bank[4] & 0x0f) | (data << 4); |
| 2856 | 2832 | vrom_bank[4] &= ((nes.chr_chunks << 3) - 1); |
| 2857 | 2833 | chr1_4(space->machine, vrom_bank[4], CHRROM); |
| 2858 | | // ppu2c0x_set_videorom_bank(state->ppu, 4, 1, vrom_bank[4], 64); |
| 2859 | 2834 | break; |
| 2860 | 2835 | case 0x5001: |
| 2861 | 2836 | case 0x5004: |
| r5357 | r5358 | |
| 2863 | 2838 | vrom_bank[5] = (vrom_bank[5] & 0xf0) | (data & 0x0f); |
| 2864 | 2839 | vrom_bank[5] &= ((nes.chr_chunks << 3) - 1); |
| 2865 | 2840 | chr1_5(space->machine, vrom_bank[5], CHRROM); |
| 2866 | | // ppu2c0x_set_videorom_bank(state->ppu, 5, 1, vrom_bank[5], 64); |
| 2867 | 2841 | break; |
| 2868 | 2842 | case 0x5003: |
| 2869 | 2843 | case 0x5006: |
| r5357 | r5358 | |
| 2871 | 2845 | vrom_bank[5] = (vrom_bank[5] & 0x0f) | (data << 4); |
| 2872 | 2846 | vrom_bank[5] &= ((nes.chr_chunks << 3) - 1); |
| 2873 | 2847 | chr1_5(space->machine, vrom_bank[5], CHRROM); |
| 2874 | | // ppu2c0x_set_videorom_bank(state->ppu, 5, 1, vrom_bank[5], 64); |
| 2875 | 2848 | break; |
| 2876 | 2849 | case 0x6000: |
| 2877 | 2850 | /* Switch 1k vrom at $1800 - low 4 bits */ |
| 2878 | 2851 | vrom_bank[6] = (vrom_bank[6] & 0xf0) | (data & 0x0f); |
| 2879 | 2852 | vrom_bank[6] &= ((nes.chr_chunks << 3) - 1); |
| 2880 | 2853 | chr1_6(space->machine, vrom_bank[6], CHRROM); |
| 2881 | | // ppu2c0x_set_videorom_bank(state->ppu, 6, 1, vrom_bank[6], 64); |
| 2882 | 2854 | break; |
| 2883 | 2855 | case 0x6002: |
| 2884 | 2856 | /* Switch 1k vrom at $1800 - high 4 bits */ |
| 2885 | 2857 | vrom_bank[6] = (vrom_bank[6] & 0x0f) | (data << 4); |
| 2886 | 2858 | vrom_bank[6] &= ((nes.chr_chunks << 3) - 1); |
| 2887 | 2859 | chr1_6(space->machine, vrom_bank[6], CHRROM); |
| 2888 | | // ppu2c0x_set_videorom_bank(state->ppu, 6, 1, vrom_bank[6], 64); |
| 2889 | 2860 | break; |
| 2890 | 2861 | case 0x6001: |
| 2891 | 2862 | case 0x6004: |
| r5357 | r5358 | |
| 2893 | 2864 | vrom_bank[7] = (vrom_bank[7] & 0xf0) | (data & 0x0f); |
| 2894 | 2865 | vrom_bank[7] &= ((nes.chr_chunks << 3) - 1); |
| 2895 | 2866 | chr1_7(space->machine, vrom_bank[7], CHRROM); |
| 2896 | | // ppu2c0x_set_videorom_bank(state->ppu, 7, 1, vrom_bank[7], 64); |
| 2897 | 2867 | break; |
| 2898 | 2868 | case 0x6003: |
| 2899 | 2869 | case 0x6006: |
| r5357 | r5358 | |
| 2901 | 2871 | vrom_bank[7] = (vrom_bank[7] & 0x0f) | (data << 4); |
| 2902 | 2872 | vrom_bank[7] &= ((nes.chr_chunks << 3) - 1); |
| 2903 | 2873 | chr1_7(space->machine, vrom_bank[7], CHRROM); |
| 2904 | | // ppu2c0x_set_videorom_bank(state->ppu, 7, 1, vrom_bank[7], 64); |
| 2905 | 2874 | break; |
| 2906 | 2875 | case 0x7000: |
| 2907 | 2876 | /* Set low 4 bits of latch */ |
| r5357 | r5358 | |
| 2972 | 2941 | case 0x5003: |
| 2973 | 2942 | /* switch 1k VROM at $0000-$0c00 */ |
| 2974 | 2943 | chr1_x(space->machine, offset&3, data, CHRROM); |
| 2975 | | // ppu2c0x_set_videorom_bank(state->ppu, (offset & 3) + 0, 1, data, 64); |
| 2976 | 2944 | break; |
| 2977 | 2945 | |
| 2978 | 2946 | case 0x6000: |
| r5357 | r5358 | |
| 2981 | 2949 | case 0x6003: |
| 2982 | 2950 | /* switch 1k VROM at $1000-$1c00 */ |
| 2983 | 2951 | chr1_x(space->machine, (offset&3)+4, data, CHRROM); |
| 2984 | | // ppu2c0x_set_videorom_bank(state->ppu, (offset & 3) + 4, 1, data, 64); |
| 2985 | 2952 | break; |
| 2986 | 2953 | |
| 2987 | 2954 | case 0x7000: |
| r5357 | r5358 | |
| 3034 | 3001 | case 0x5000: |
| 3035 | 3002 | /* Switch 1k VROM at $0000 */ |
| 3036 | 3003 | chr1_0(space->machine,data, CHRROM); |
| 3037 | | // ppu2c0x_set_videorom_bank(state->ppu, 0, 1, data, 64); |
| 3038 | 3004 | break; |
| 3039 | 3005 | case 0x5002: |
| 3040 | 3006 | /* Switch 1k VROM at $0400 */ |
| 3041 | 3007 | chr1_1(space->machine,data, CHRROM); |
| 3042 | | // ppu2c0x_set_videorom_bank(state->ppu, 1, 1, data, 64); |
| 3043 | 3008 | break; |
| 3044 | 3009 | case 0x5001: |
| 3045 | 3010 | /* Switch 1k VROM at $0800 */ |
| 3046 | 3011 | chr1_2(space->machine,data, CHRROM); |
| 3047 | | // ppu2c0x_set_videorom_bank(state->ppu, 2, 1, data, 64); |
| 3048 | 3012 | break; |
| 3049 | 3013 | case 0x5003: |
| 3050 | 3014 | /* Switch 1k VROM at $0c00 */ |
| 3051 | 3015 | chr1_3(space->machine,data, CHRROM); |
| 3052 | | // ppu2c0x_set_videorom_bank(state->ppu, 3, 1, data, 64); |
| 3053 | 3016 | break; |
| 3054 | 3017 | case 0x6000: |
| 3055 | 3018 | /* Switch 1k VROM at $1000 */ |
| 3056 | 3019 | chr1_4(space->machine,data, CHRROM); |
| 3057 | | // ppu2c0x_set_videorom_bank(state->ppu, 4, 1, data, 64); |
| 3058 | 3020 | break; |
| 3059 | 3021 | case 0x6002: |
| 3060 | 3022 | /* Switch 1k VROM at $1400 */ |
| 3061 | 3023 | chr1_5(space->machine,data, CHRROM); |
| 3062 | | // ppu2c0x_set_videorom_bank(state->ppu, 5, 1, data, 64); |
| 3063 | 3024 | break; |
| 3064 | 3025 | case 0x6001: |
| 3065 | 3026 | /* Switch 1k VROM at $1800 */ |
| 3066 | 3027 | chr1_6(space->machine,data, CHRROM); |
| 3067 | | // ppu2c0x_set_videorom_bank(state->ppu, 6, 1, data, 64); |
| 3068 | 3028 | break; |
| 3069 | 3029 | case 0x6003: |
| 3070 | 3030 | /* Switch 1k VROM at $1c00 */ |
| 3071 | 3031 | chr1_7(space->machine,data, CHRROM); |
| 3072 | | // ppu2c0x_set_videorom_bank(state->ppu, 7, 1, data, 64); |
| 3073 | 3032 | break; |
| 3074 | 3033 | case 0x7000: |
| 3075 | 3034 | IRQ_count_latch = data; |
| r5357 | r5358 | |
| 3118 | 3077 | case 0x3000: |
| 3119 | 3078 | /* Switch 1k VROM at $1000 */ |
| 3120 | 3079 | chr1_x(space->machine, offset&7, data, CHRROM); |
| 3121 | | //ppu2c0x_set_videorom_bank(state->ppu, offset & 0x07, 1, data, 64); |
| 3122 | 3080 | break; |
| 3123 | 3081 | default: |
| 3124 | 3082 | logerror("Uncaught mapper 32 write, addr: %04x value: %02x\n", offset + 0x8000, data); |
| r5357 | r5358 | |
| 3145 | 3103 | case 0x0002: |
| 3146 | 3104 | /* Switch 2k VROM at $0000 */ |
| 3147 | 3105 | chr2_0(space->machine, data, CHRROM); |
| 3148 | | // ppu2c0x_set_videorom_bank(state->ppu, 0, 2, data, 128); |
| 3149 | 3106 | break; |
| 3150 | 3107 | case 0x0003: |
| 3151 | 3108 | /* Switch 2k VROM at $0800 */ |
| 3152 | 3109 | chr2_2(space->machine, data, CHRROM); |
| 3153 | | // ppu2c0x_set_videorom_bank(state->ppu, 2, 2, data, 128); |
| 3154 | 3110 | break; |
| 3155 | 3111 | case 0x2000: |
| 3156 | 3112 | /* Switch 1k VROM at $1000 */ |
| 3157 | 3113 | chr1_4(space->machine, data, CHRROM); |
| 3158 | | // ppu2c0x_set_videorom_bank(state->ppu, 4, 1, data, 64); |
| 3159 | 3114 | break; |
| 3160 | 3115 | case 0x2001: |
| 3161 | 3116 | /* Switch 1k VROM at $1400 */ |
| 3162 | 3117 | chr1_5(space->machine, data, CHRROM); |
| 3163 | | // ppu2c0x_set_videorom_bank(state->ppu, 5, 1, data, 64); |
| 3164 | 3118 | break; |
| 3165 | 3119 | case 0x2002: |
| 3166 | 3120 | /* Switch 1k VROM at $1800 */ |
| 3167 | 3121 | chr1_6(space->machine, data, CHRROM); |
| 3168 | | // ppu2c0x_set_videorom_bank(state->ppu, 6, 1, data, 64); |
| 3169 | 3122 | break; |
| 3170 | 3123 | case 0x2003: |
| 3171 | 3124 | /* Switch 1k VROM at $1c00 */ |
| 3172 | 3125 | chr1_7(space->machine, data, CHRROM); |
| 3173 | | // ppu2c0x_set_videorom_bank(state->ppu, 7, 1, data, 64); |
| 3174 | 3126 | break; |
| 3175 | 3127 | default: |
| 3176 | 3128 | logerror("Uncaught mapper 33 write, addr: %04x value: %02x\n", offset + 0x8000, data); |
| r5357 | r5358 | |
| 4148 | 4100 | case 0x1ef0: |
| 4149 | 4101 | /* Switch 2k VROM at $0000 */ |
| 4150 | 4102 | chr2_0 (space->machine, (data & 0x7f) >> 1, CHRROM); |
| 4103 | break; |
| 4104 | case 0x1ef1: |
| 4105 | /* Switch 2k VROM at $0000 */ |
| 4106 | chr2_2 (space->machine, (data & 0x7f) >> 1, CHRROM); |
| 4107 | break; |
| 4108 | case 0x1ef2: |
| 4109 | /* Switch 1k VROM at $1000 */ |
| 4110 | chr1_4(space->machine, data, CHRROM); |
| 4111 | break; |
| 4112 | case 0x1ef3: |
| 4113 | /* Switch 1k VROM at $1400 */ |
| 4114 | chr1_5(space->machine, data, CHRROM); |
| 4115 | break; |
| 4116 | case 0x1ef4: |
| 4117 | /* Switch 1k VROM at $1800 */ |
| 4118 | chr1_6(space->machine, data, CHRROM); |
| 4119 | break; |
| 4120 | case 0x1ef5: |
| 4121 | /* Switch 1k VROM at $1c00 */ |
| 4122 | chr1_7(space->machine, data, CHRROM); |
| 4123 | break; |
| 4124 | case 0x1ef6: |
| 4125 | /* Switch 1k VROM at $1c00 */ |
| 4126 | (data&1)? set_nt_mirroring(PPU_MIRROR_VERT):set_nt_mirroring(PPU_MIRROR_HORZ); |
| 4127 | break; |
| 4128 | case 0x1efa: case 0x1efb: |
| 4129 | /* Switch 8k ROM at $8000 */ |
| 4130 | prg8_89 (space, data); |
| 4131 | break; |
| 4132 | case 0x1efc: case 0x1efd: |
| 4133 | /* Switch 8k ROM at $a000 */ |
| 4134 | prg8_ab (space, data); |
| 4135 | break; |
| 4136 | case 0x1efe: case 0x1eff: |
| 4137 | /* Switch 8k ROM at $c000 */ |
| 4138 | prg8_cd (space, data); |
| 4139 | break; |
| 4140 | default: |
| 4141 | logerror("mapper80_m_w uncaught addr: %04x, value: %02x\n", offset + 0x6000, data); |
| 4142 | break; |
| 4143 | } |
| 4144 | } |
| 4145 | /* clone of 80, but with custom nametable stuff */ |
| 4146 | static WRITE8_HANDLER( mapper207_m_w ) |
| 4147 | { |
| 4148 | logerror("mapper80_m_w, offset: %04x, data: %02x\n", offset, data); |
| 4149 | |
| 4150 | switch (offset) |
| 4151 | { |
| 4152 | case 0x1ef0: |
| 4153 | /* Switch 2k VROM at $0000 */ |
| 4154 | chr2_0 (space->machine, (data & 0x7f) >> 1, CHRROM); |
| 4151 | 4155 | if (data & 0x80) |
| 4152 | 4156 | { |
| 4153 | | /* Horizontal, $2000-$27ff */ |
| 4154 | | ppu_mirror_custom (0, 0); |
| 4155 | | ppu_mirror_custom (1, 0); |
| 4157 | set_nt_page(0, CIRAM, 1, 1); |
| 4158 | set_nt_page(1, CIRAM, 1, 1); |
| 4156 | 4159 | } |
| 4157 | 4160 | else |
| 4158 | 4161 | { |
| 4159 | | /* Vertical, $2000-$27ff */ |
| 4160 | | ppu_mirror_custom (0, 0); |
| 4161 | | ppu_mirror_custom (1, 1); |
| 4162 | set_nt_page(0, CIRAM, 0, 1); |
| 4163 | set_nt_page(1, CIRAM, 0, 1); |
| 4162 | 4164 | } |
| 4163 | 4165 | break; |
| 4164 | 4166 | case 0x1ef1: |
| r5357 | r5358 | |
| 4166 | 4168 | chr2_2 (space->machine, (data & 0x7f) >> 1, CHRROM); |
| 4167 | 4169 | if (data & 0x80) |
| 4168 | 4170 | { |
| 4169 | | /* Horizontal, $2800-$2fff */ |
| 4170 | | ppu_mirror_custom (2, 0); |
| 4171 | | ppu_mirror_custom (3, 0); |
| 4171 | set_nt_page(2, CIRAM, 1, 1); |
| 4172 | set_nt_page(3, CIRAM, 1, 1); |
| 4172 | 4173 | } |
| 4173 | 4174 | else |
| 4174 | 4175 | { |
| 4175 | | /* Vertical, $2800-$2fff */ |
| 4176 | | ppu_mirror_custom (2, 0); |
| 4177 | | ppu_mirror_custom (3, 1); |
| 4176 | set_nt_page(2, CIRAM, 0, 1); |
| 4177 | set_nt_page(3, CIRAM, 0, 1); |
| 4178 | 4178 | } |
| 4179 | 4179 | break; |
| 4180 | 4180 | case 0x1ef2: |
| r5357 | r5358 | |
| 4402 | 4402 | case 0x2008: case 0x2010: case 0x2018: |
| 4403 | 4403 | /* Switch 1k VROM at $0400 */ |
| 4404 | 4404 | chr1_1(space->machine, data, CHRROM); |
| 4405 | | // ppu2c0x_set_videorom_bank(state->ppu, 1, 1, data, 64); |
| 4406 | 4405 | break; |
| 4407 | 4406 | case 0x3000: |
| 4408 | 4407 | /* Switch 1k VROM at $0800 */ |
| 4409 | 4408 | chr1_2(space->machine, data, CHRROM); |
| 4410 | | // ppu2c0x_set_videorom_bank(state->ppu, 2, 1, data, 64); |
| 4411 | 4409 | break; |
| 4412 | 4410 | case 0x3008: case 0x3010: case 0x3018: |
| 4413 | 4411 | /* Switch 1k VROM at $0c00 */ |
| 4414 | 4412 | chr1_3(space->machine, data, CHRROM); |
| 4415 | | // ppu2c0x_set_videorom_bank(state->ppu, 3, 1, data, 64); |
| 4416 | 4413 | break; |
| 4417 | 4414 | case 0x4000: |
| 4418 | 4415 | /* Switch 1k VROM at $1000 */ |
| 4419 | 4416 | chr1_4(space->machine, data, CHRROM); |
| 4420 | | // ppu2c0x_set_videorom_bank(state->ppu, 4, 1, data, 64); |
| 4421 | 4417 | break; |
| 4422 | 4418 | case 0x4008: case 0x4010: case 0x4018: |
| 4423 | 4419 | /* Switch 1k VROM at $1400 */ |
| 4424 | 4420 | chr1_5(space->machine, data, CHRROM); |
| 4425 | | // ppu2c0x_set_videorom_bank(state->ppu, 5, 1, data, 64); |
| 4426 | 4421 | break; |
| 4427 | 4422 | case 0x5000: |
| 4428 | 4423 | /* Switch 1k VROM at $1800 */ |
| 4429 | 4424 | chr1_6(space->machine, data, CHRROM); |
| 4430 | | // ppu2c0x_set_videorom_bank(state->ppu, 6, 1, data, 64); |
| 4431 | 4425 | break; |
| 4432 | 4426 | case 0x5008: case 0x5010: case 0x5018: |
| 4433 | 4427 | /* Switch 1k VROM at $1c00 */ |
| 4434 | 4428 | chr1_7(space->machine, data, CHRROM); |
| 4435 | | // ppu2c0x_set_videorom_bank(state->ppu, 7, 1, data, 64); |
| 4436 | 4429 | break; |
| 4437 | 4430 | |
| 4438 | 4431 | case 0x6000: |
| r5357 | r5358 | |
| 4726 | 4719 | } |
| 4727 | 4720 | } |
| 4728 | 4721 | } |
| 4722 | |
| 4723 | static WRITE8_HANDLER( mapper164_l_w ) |
| 4724 | { |
| 4725 | offset += 0x4100; /* the checks work better on addresses */ |
| 4726 | if (0x5000 == (offset & 0x7300)) |
| 4727 | prg32(space, data); |
| 4728 | } |
| 4729 | |
| 4730 | static WRITE8_HANDLER( mapper164_w ) |
| 4731 | { |
| 4732 | if ((offset & 0x7300) == 0x5000) |
| 4733 | prg32(space, data); |
| 4734 | } |
| 4735 | |
| 4729 | 4736 | static WRITE8_HANDLER( mapper88_w ) |
| 4730 | 4737 | { |
| 4731 | | switch(offset&1) |
| 4738 | switch (offset&1) |
| 4732 | 4739 | { |
| 4733 | 4740 | case 0: |
| 4734 | 4741 | { |
| r5357 | r5358 | |
| 5432 | 5439 | prg32(space, 0); |
| 5433 | 5440 | break; |
| 5434 | 5441 | case 4: |
| 5442 | case 206: |
| 5443 | /* Only MMC3 and clones seem to use 4-screen! */ |
| 5444 | |
| 5445 | /* hardware uses an 8K RAM chip, but can't address the high 4K! */ |
| 5446 | /* that much is documented for Nintendo Gauntlet boards */ |
| 5447 | if(nes.four_screen_vram) |
| 5448 | { |
| 5449 | extended_ntram=auto_alloc_array(space->machine, UINT8, 0x2000); |
| 5450 | set_nt_page(0, CART_NTRAM, 0, 1); |
| 5451 | set_nt_page(1, CART_NTRAM, 1, 1); |
| 5452 | set_nt_page(2, CART_NTRAM, 2, 1); |
| 5453 | set_nt_page(3, CART_NTRAM, 3, 1); |
| 5454 | } |
| 5455 | |
| 5435 | 5456 | case 118: |
| 5436 | 5457 | case 119: |
| 5437 | | case 206: |
| 5438 | 5458 | /* Can switch 8k prg banks */ |
| 5439 | 5459 | IRQ_enable = 0; |
| 5440 | 5460 | IRQ_count = IRQ_count_latch = 0; |
| r5357 | r5358 | |
| 5674 | 5694 | case 82: |
| 5675 | 5695 | case 85: |
| 5676 | 5696 | case 86: |
| 5697 | case 207: |
| 5677 | 5698 | prg16_89ab (space, 0); |
| 5678 | 5699 | prg16_cdef (space, nes.prg_chunks-1); |
| 5679 | 5700 | break; |
| r5357 | r5358 | |
| 5734 | 5755 | prg16_89ab (space, nes.prg_chunks-2); |
| 5735 | 5756 | prg16_cdef (space, nes.prg_chunks-1); |
| 5736 | 5757 | break; |
| 5737 | | |
| 5758 | case 164: |
| 5759 | prg32(space, 0xFF); |
| 5760 | nes.mid_ram_enable = 1; |
| 5761 | break; |
| 5738 | 5762 | case 180: |
| 5739 | 5763 | prg16_89ab(space, 0); |
| 5740 | 5764 | prg16_cdef(space, 0); |
| 5765 | break; |
| 5741 | 5766 | case 182: |
| 5742 | 5767 | IRQ_enable = 0; |
| 5743 | 5768 | IRQ_count = 0; |
| r5357 | r5358 | |
| 5803 | 5828 | err = 2; |
| 5804 | 5829 | break; |
| 5805 | 5830 | } |
| 5806 | | |
| 5807 | | // if (nes.chr_chunks) |
| 5808 | | // memcpy (videoram, nes.vrom, 0x2000); |
| 5809 | | |
| 5810 | 5831 | return err; |
| 5811 | 5832 | } |
| 5812 | 5833 | |
| r5357 | r5358 | |
| 5900 | 5921 | { 140, "Jaleco", NULL, NULL, mapper_140_m_w, NULL, NULL, NULL, NULL }, |
| 5901 | 5922 | { 144, "AGCI 50282", NULL, NULL, NULL, mapper144_w, NULL, NULL, NULL }, //Death Race only |
| 5902 | 5923 | { 154, "Devil Man", NULL, NULL, NULL, mapper154_w, NULL, NULL, NULL }, |
| 5924 | { 164, "Final Fantasy V", mapper164_l_w, NULL, NULL, mapper164_w, NULL, NULL, NULL }, |
| 5903 | 5925 | { 180, "Nihon Bussan - PRG HI", NULL, NULL, NULL, mapper180_w, NULL, NULL, NULL }, |
| 5904 | 5926 | { 182, "Super games", NULL, NULL, NULL, mapper182_w, NULL, NULL, mapper182_irq }, |
| 5905 | 5927 | { 184, "Sunsoft VROM/4K", NULL, NULL, mapper184_m_w, NULL, NULL, NULL, NULL }, |
| r5357 | r5358 | |
| 5909 | 5931 | { 201, "X-in-1", NULL, NULL, NULL, mapper201_w, NULL, NULL, NULL }, |
| 5910 | 5932 | { 202, "150-in-1", NULL, NULL, NULL, mapper202_w, NULL, NULL, NULL }, |
| 5911 | 5933 | { 203, "35-in-1", NULL, NULL, NULL, mapper203_w, NULL, NULL, NULL }, |
| 5912 | | { 206, "MMC3 no mirror", NULL, NULL, NULL, mapper206_w, NULL, NULL, mapper4_irq }, |
| 5934 | { 206, "MIMIC-1", NULL, NULL, NULL, mapper206_w, NULL, NULL, mapper4_irq }, |
| 5935 | { 207, "Fudou Myouou Den", NULL, NULL, mapper207_m_w, NULL, NULL, NULL, NULL }, |
| 5913 | 5936 | { 225, "72-in-1 bootleg", NULL, NULL, NULL, mapper225_w, NULL, NULL, NULL }, |
| 5914 | 5937 | { 226, "76-in-1 bootleg", NULL, NULL, NULL, mapper226_w, NULL, NULL, NULL }, |
| 5915 | 5938 | { 227, "1200-in-1 bootleg", NULL, NULL, NULL, mapper227_w, NULL, NULL, NULL }, |