summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/machine/nes_sachen.c
blob: fe0ca5b2c62c0d97a8b509c1b8289c9ab76b97a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
/***********************************************************************************************************


 NES/Famicom cartridge emulation for Sachen PCBs

 Copyright MESS Team.
 Visit http://mamedev.org for licensing and usage restrictions.


 Here we emulate the following PCBs

 * Sachen SA-009 [mapper 160]
 * Sachen SA-0036 [mapper 148]
 * Sachen SA-0037 [mapper 149]
 * Sachen SA-72007 [mapper 145]
 * Sachen SA-72008 [mapper 133]
 * Sachen TCA-01 [mapper 143]
 * Sachen TCU-01 [mapper 147]
 * Sachen TCU-02 [mapper 136]
 * Sachen Discrete PCBs [mapper 150 & 243]
 * Sachen 8259 [mapper 141 (A), 138 (B), 139 (C), 137 (D)]

 Known issues on specific mappers:

 * 133 Qi Wang starts with corrupted graphics (ingame seems better)


 ***********************************************************************************************************/


#include "emu.h"
#include "machine/nes_sachen.h"


#ifdef NES_PCB_DEBUG
#define VERBOSE 1
#else
#define VERBOSE 0
#endif

#define LOG_MMC(x) do { if (VERBOSE) logerror x; } while (0)


//-------------------------------------------------
//  constructor
//-------------------------------------------------

const device_type NES_SACHEN_SA009 = &device_creator<nes_sachen_sa009_device>;
const device_type NES_SACHEN_SA0036 = &device_creator<nes_sachen_sa0036_device>;
const device_type NES_SACHEN_SA0037 = &device_creator<nes_sachen_sa0037_device>;
const device_type NES_SACHEN_SA72007 = &device_creator<nes_sachen_sa72007_device>;
const device_type NES_SACHEN_SA72008 = &device_creator<nes_sachen_sa72008_device>;
const device_type NES_SACHEN_TCA01 = &device_creator<nes_sachen_tca01_device>;
const device_type NES_SACHEN_TCU01 = &device_creator<nes_sachen_tcu01_device>;
const device_type NES_SACHEN_TCU02 = &device_creator<nes_sachen_tcu02_device>;
const device_type NES_SACHEN_74X374 = &device_creator<nes_sachen_74x374_device>;
const device_type NES_SACHEN_74X374_ALT = &device_creator<nes_sachen_74x374_alt_device>;
const device_type NES_SACHEN_8259A = &device_creator<nes_sachen_8259a_device>;
const device_type NES_SACHEN_8259B = &device_creator<nes_sachen_8259b_device>;
const device_type NES_SACHEN_8259C = &device_creator<nes_sachen_8259c_device>;
const device_type NES_SACHEN_8259D = &device_creator<nes_sachen_8259d_device>;


nes_sachen_sa009_device::nes_sachen_sa009_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: nes_nrom_device(mconfig, NES_SACHEN_SA009, "NES Cart Sachen SA009 PCB", tag, owner, clock, "nes_sa009", __FILE__)
{
}

nes_sachen_sa0036_device::nes_sachen_sa0036_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: nes_nrom_device(mconfig, NES_SACHEN_SA0036, "NES Cart Sachen sa0036 PCB", tag, owner, clock, "nes_sa0036", __FILE__)
{
}

nes_sachen_sa0037_device::nes_sachen_sa0037_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: nes_nrom_device(mconfig, NES_SACHEN_SA0037, "NES Cart Sachen sa0037 PCB", tag, owner, clock, "nes_sa0037", __FILE__)
{
}

nes_sachen_sa72007_device::nes_sachen_sa72007_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: nes_nrom_device(mconfig, NES_SACHEN_SA72007, "NES Cart Sachen SA72007 PCB", tag, owner, clock, "nes_sa72007", __FILE__)
{
}

nes_sachen_sa72008_device::nes_sachen_sa72008_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: nes_nrom_device(mconfig, NES_SACHEN_SA72008, "NES Cart Sachen SA72008 PCB", tag, owner, clock, "nes_sa72008", __FILE__)
{
}

nes_sachen_tca01_device::nes_sachen_tca01_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: nes_nrom_device(mconfig, NES_SACHEN_TCA01, "NES Cart Sachen TCA-01 PCB", tag, owner, clock, "nes_tca01", __FILE__)
{
}

nes_sachen_tcu01_device::nes_sachen_tcu01_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: nes_nrom_device(mconfig, NES_SACHEN_TCU01, "NES Cart Sachen TCU-01 PCB", tag, owner, clock, "nes_tcu01", __FILE__)
{
}

nes_sachen_tcu02_device::nes_sachen_tcu02_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: nes_nrom_device(mconfig, NES_SACHEN_TCU02, "NES Cart Sachen TCU-02 PCB", tag, owner, clock, "nes_tcu02", __FILE__)
{
}

nes_sachen_74x374_device::nes_sachen_74x374_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source)
					: nes_nrom_device(mconfig, type, name, tag, owner, clock, shortname, source)
{
}

nes_sachen_74x374_device::nes_sachen_74x374_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: nes_nrom_device(mconfig, NES_SACHEN_74X374, "NES Cart Sachen 74*374 PCB", tag, owner, clock, "nes_s74x34", __FILE__)
{
}

nes_sachen_74x374_alt_device::nes_sachen_74x374_alt_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: nes_sachen_74x374_device(mconfig, NES_SACHEN_74X374_ALT, "NES Cart Sachen 74*374 Alt PCB", tag, owner, clock, "nes_s74x34a", __FILE__)
{
}

nes_sachen_8259a_device::nes_sachen_8259a_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source)
					: nes_sachen_74x374_device(mconfig, type, name, tag, owner, clock, shortname, source)
{
}

nes_sachen_8259a_device::nes_sachen_8259a_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: nes_sachen_74x374_device(mconfig, NES_SACHEN_8259A, "NES Cart Sachen 8259A PCB", tag, owner, clock, "nes_s8259a", __FILE__)
{
}

nes_sachen_8259b_device::nes_sachen_8259b_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: nes_sachen_8259a_device(mconfig, NES_SACHEN_8259B, "NES Cart Sachen 8259B PCB", tag, owner, clock, "nes_s8259b", __FILE__)
{
}

nes_sachen_8259c_device::nes_sachen_8259c_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: nes_sachen_8259a_device(mconfig, NES_SACHEN_8259C, "NES Cart Sachen 8259C PCB", tag, owner, clock, "nes_s8259c", __FILE__)
{
}

nes_sachen_8259d_device::nes_sachen_8259d_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: nes_sachen_8259a_device(mconfig, NES_SACHEN_8259D, "NES Cart Sachen 8259D PCB", tag, owner, clock, "nes_s8259d", __FILE__)
{
}




void nes_sachen_sa009_device::device_start()
{
	common_start();
}

void nes_sachen_sa009_device::pcb_reset()
{
	m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
	prg32(0);
	chr8(0, m_chr_source);
}

void nes_sachen_sa0036_device::device_start()
{
	common_start();
}

void nes_sachen_sa0036_device::pcb_reset()
{
	m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
	prg32(0);
	chr8(0, m_chr_source);
}

void nes_sachen_sa0037_device::device_start()
{
	common_start();
}

void nes_sachen_sa0037_device::pcb_reset()
{
	m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
	prg32(0);
	chr8(0, m_chr_source);
}

void nes_sachen_sa72007_device::device_start()
{
	common_start();
}

void nes_sachen_sa72007_device::pcb_reset()
{
	m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
	prg32(0);
	chr8(0, m_chr_source);
}

void nes_sachen_sa72008_device::device_start()
{
	common_start();
}

void nes_sachen_sa72008_device::pcb_reset()
{
	m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
	prg32(0);
	chr8(0, m_chr_source);
}

void nes_sachen_tca01_device::device_start()
{
	common_start();
}

void nes_sachen_tca01_device::pcb_reset()
{
	m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
	prg16_89ab(0);
	prg16_cdef(1);
	chr8(0, m_chr_source);
}

void nes_sachen_tcu01_device::device_start()
{
	common_start();
}

void nes_sachen_tcu01_device::pcb_reset()
{
	m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
	prg32(0);
	chr8(0, m_chr_source);
}

void nes_sachen_tcu02_device::device_start()
{
	common_start();
	save_item(NAME(m_latch));
}

void nes_sachen_tcu02_device::pcb_reset()
{
	m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
	prg32(0);
	chr8(0, m_chr_source);

	m_latch = 0;
}

void nes_sachen_74x374_device::device_start()
{
	common_start();
	save_item(NAME(m_latch));
	save_item(NAME(m_mmc_vrom_bank));
}

void nes_sachen_74x374_device::pcb_reset()
{
	m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
	prg32(0);
	chr8(0, m_chr_source);

	m_latch = 0;
	m_mmc_vrom_bank = 0;
}

void nes_sachen_8259a_device::device_start()
{
	common_start();
	save_item(NAME(m_latch));
	save_item(NAME(m_reg));
}

void nes_sachen_8259a_device::pcb_reset()
{
	m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
	prg32(0);
	chr8(0, m_chr_source);
	set_nt_mirroring(PPU_MIRROR_VERT);

	m_latch = 0;
	memset(m_reg, 0, sizeof(m_reg));
}

void nes_sachen_8259d_device::pcb_reset()
{
	m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
	prg32(0);
	chr8(m_vrom_chunks - 1, CHRROM);
	set_nt_mirroring(PPU_MIRROR_VERT);

	m_latch = 0;
	memset(m_reg, 0, sizeof(m_reg));
}




/*-------------------------------------------------
 mapper specific handlers
 -------------------------------------------------*/

/*-------------------------------------------------

 Sachen SA009 bootleg boards

 Games: Pipe 5

 iNES: mapper 160

 In MESS: Supported.

 -------------------------------------------------*/

WRITE8_MEMBER(nes_sachen_sa009_device::write_l)
{
	LOG_MMC(("SA009 write_l, offset: %04x, data: %02x\n", offset, data));

	chr8(data, m_chr_source);
}

/*-------------------------------------------------

 Sachen SA0036 bootleg boards

 Games: Taiwan Mahjong 16

 iNES: mapper 149

 In MESS: Supported.

 -------------------------------------------------*/

WRITE8_MEMBER(nes_sachen_sa0036_device::write_h)
{
	LOG_MMC(("sa0036 write_h, offset: %04x, data: %02x\n", offset, data));

	chr8(data >> 7, CHRROM);
}

/*-------------------------------------------------

 Sachen SA0037 bootleg boards

 Games: Mahjong World, Shisen Mahjong

 iNES: mapper 148

 In MESS: Supported.

 -------------------------------------------------*/

WRITE8_MEMBER(nes_sachen_sa0037_device::write_h)
{
	LOG_MMC(("sa0037 write_h, offset: %04x, data: %02x\n", offset, data));

	// this pcb is subject to bus conflict
	data = account_bus_conflict(offset, data);

	prg32(data >> 3);
	chr8(data, CHRROM);
}

/*-------------------------------------------------

 Sachen SA72007 bootleg boards

 Games: Sidewinder

 iNES: mapper 145

 In MESS: Supported.

 -------------------------------------------------*/

WRITE8_MEMBER(nes_sachen_sa72007_device::write_l)
{
	LOG_MMC(("SA72007 write_l, offset: %04x, data: %02x\n", offset, data));

	/* only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
	if (!(offset & 0x100))
		chr8(data >> 7, CHRROM);
}

/*-------------------------------------------------

 Sachen SA72008 bootleg boards

 Games: Jovial Race, Qi Wang

 iNES: mapper 133

 In MESS: Supported.

 -------------------------------------------------*/

WRITE8_MEMBER(nes_sachen_sa72008_device::write_l)
{
	LOG_MMC(("SA72008 write_l, offset: %04x, data: %02x\n", offset, data));

	prg32(data >> 2);
	chr8(data, CHRROM);
}

/*-------------------------------------------------

 Sachen TCA-01 bootleg boards

 iNES: mapper 143

 Games: Dancing Blocks, Magic Mathematic

 In MESS: Supported.

 -------------------------------------------------*/

READ8_MEMBER(nes_sachen_tca01_device::read_l)
{
	LOG_MMC(("TCA-01 read_l, offset: %04x\n", offset));

	/* the address is read only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
	if (!(offset & 0x100))
		return (~offset & 0x3f) | 0x40;
	else
		return 0x00;
}

/*-------------------------------------------------

 Sachen TCU-01 bootleg boards

 Games: Challenge of the Dragon, Chinese Kungfu

 iNES: mapper 147

 In MESS: Supported.

 -------------------------------------------------*/

WRITE8_MEMBER(nes_sachen_tcu01_device::write_l)
{
	LOG_MMC(("TCU-01 write_l, offset: %04x, data: %02x\n", offset, data));

	if ((offset & 0x103) == 0x002)
	{
		prg32(((data >> 6) & 0x02) | ((data >> 2) & 0x01));
		chr8(data >> 3, CHRROM);
	}
}

/*-------------------------------------------------

 Sachen TCU-02 bootleg boards

 Games: Wei Lai Xiao Zi

 iNES: mapper 136

 In MESS: Supported.

 -------------------------------------------------*/

WRITE8_MEMBER(nes_sachen_tcu02_device::write_l)
{
	LOG_MMC(("TCU-02 write_l, offset: %04x, data: %02x\n", offset, data));

	if ((offset & 0x103) == 0x002)
	{
		m_latch = (data & 0x30) | ((data + 3) & 0x0f);
		chr8(m_latch, CHRROM);
	}
}

READ8_MEMBER(nes_sachen_tcu02_device::read_l)
{
	LOG_MMC(("TCU-02 read_l, offset: %04x\n", offset));

	if ((offset & 0x103) == 0x000)
		return m_latch | 0x40;
	else
		return 0x00;
}

/*-------------------------------------------------

 Sachen 74x374 bootleg boards

 Games: Chess Academy, Chinese Checkers Jpn, Mahjong Academy,
 Olympic IQ, Poker II, Tasac [150], Poker III [243]

 iNES: mappers 150 & 243

 -------------------------------------------------*/

void nes_sachen_74x374_device::set_mirror(UINT8 nt) // also used by mappers 137, 138, 139, 141
{
	switch (nt)
	{
		case 0:
		case 1:
			set_nt_mirroring(nt ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
			break;
		case 2:
			set_nt_page(0, CIRAM, 0, 1);
			set_nt_page(1, CIRAM, 1, 1);
			set_nt_page(2, CIRAM, 1, 1);
			set_nt_page(3, CIRAM, 1, 1);
			break;
		case 3:
			set_nt_mirroring(PPU_MIRROR_LOW);
			break;
		default:
			LOG_MMC(("Mapper set NT to invalid value %02x", nt));
			break;
	}
}


WRITE8_MEMBER(nes_sachen_74x374_device::write_l)
{
	LOG_MMC(("Sachen 74*374 write_l, offset: %04x, data: %02x\n", offset, data));

	/* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
	if (!(offset & 0x100))
	{
		if (!(offset & 0x01))
			m_latch = data & 0x07;
		else
		{
			switch (m_latch)
			{
				case 0x02:
					m_mmc_vrom_bank = (m_mmc_vrom_bank & ~0x08) | ((data << 3) & 0x08);
					chr8(m_mmc_vrom_bank, CHRROM);
					prg32(data & 0x01);
					break;
				case 0x04:
					m_mmc_vrom_bank = (m_mmc_vrom_bank & ~0x04) | ((data << 2) & 0x04);
					chr8(m_mmc_vrom_bank, CHRROM);
					break;
				case 0x05:
					prg32(data & 0x07);
					break;
				case 0x06:
					m_mmc_vrom_bank = (m_mmc_vrom_bank & ~0x03) | ((data << 0) & 0x03);
					chr8(m_mmc_vrom_bank, CHRROM);
					break;
				case 0x07:
					set_mirror((data >> 1) & 0x03);
					break;
				default:
					break;
			}
		}
	}
}

READ8_MEMBER(nes_sachen_74x374_device::read_l)
{
	LOG_MMC(("Sachen 74*374 read_l, offset: %04x", offset));

	/* read  happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
	if (!(offset & 0x100))
		return (~m_latch & 0x3f) /* ^ dips*/;  // we would need to check the Dips here
	else
		return 0;
}

WRITE8_MEMBER(nes_sachen_74x374_alt_device::write_l)
{
	LOG_MMC(("Sachen 74*374 Alt write_l, offset: %04x, data: %02x\n", offset, data));

	/* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
	if (!(offset & 0x100))
	{
		if (!(offset & 0x01))
			m_latch = data;
		else
		{
			switch (m_latch & 0x07)
			{
				case 0x00:
					prg32(0);
					chr8(3, CHRROM);
					break;
				case 0x02:
					m_mmc_vrom_bank = (m_mmc_vrom_bank & ~0x08) | ((data << 3) & 0x08);
					chr8(m_mmc_vrom_bank, CHRROM);
					break;
				case 0x04:
					m_mmc_vrom_bank = (m_mmc_vrom_bank & ~0x01) | ((data << 0) & 0x01);
					chr8(m_mmc_vrom_bank, CHRROM);
					break;
				case 0x05:
					prg32(data & 0x01);
					break;
				case 0x06:
					m_mmc_vrom_bank = (m_mmc_vrom_bank & ~0x06) | ((data << 1) & 0x06);
					chr8(m_mmc_vrom_bank, CHRROM);
					break;
				case 0x07:
					set_mirror(BIT(data, 0));
					break;
				default:
					break;
			}
		}
	}
}

/*-------------------------------------------------

 Sachen S8259 bootleg boards

 iNES: mapper 141 (A), 138 (B), 139 (C), 137 (D)

 -------------------------------------------------*/

void nes_sachen_8259a_device::chr_update()
{
	UINT8 bank_helper1 = m_reg[7] & 0x01;
	UINT8 bank_helper2 = (m_reg[4] & 0x07) << 3;

	if (m_chr_source == CHRROM)
	{
		chr2_0(((m_reg[bank_helper1 ? 0 : 0] & 0x07) | bank_helper2) << 1 | 0, CHRROM);
		chr2_2(((m_reg[bank_helper1 ? 0 : 1] & 0x07) | bank_helper2) << 1 | 1, CHRROM);
		chr2_4(((m_reg[bank_helper1 ? 0 : 2] & 0x07) | bank_helper2) << 1 | 0, CHRROM);
		chr2_6(((m_reg[bank_helper1 ? 0 : 3] & 0x07) | bank_helper2) << 1 | 1, CHRROM);
	}
}

WRITE8_MEMBER(nes_sachen_8259a_device::write_l)
{
	LOG_MMC(("Sachen 8259 write_l, offset: %04x, data: %02x\n", offset, data));

	/* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
	if (!(offset & 0x100))
	{
		if (!(offset & 0x01))
			m_latch = data & 0x07;
		else
		{
			m_reg[m_latch] = data;

			switch (m_latch)
			{
				case 0x05:
					prg32(data);
					break;
				case 0x07:
					set_mirror(BIT(data, 0) ? 0 : (data >> 1) & 0x03);
					break;
				default:
					chr_update();
					break;
			}
		}
	}
}

void nes_sachen_8259b_device::chr_update()
{
	UINT8 bank_helper1 = m_reg[7] & 0x01;
	UINT8 bank_helper2 = (m_reg[4] & 0x07) << 3;

	if (m_chr_source == CHRROM)
	{
		chr2_0(((m_reg[bank_helper1 ? 0 : 0] & 0x07) | bank_helper2), CHRROM);
		chr2_2(((m_reg[bank_helper1 ? 0 : 1] & 0x07) | bank_helper2), CHRROM);
		chr2_4(((m_reg[bank_helper1 ? 0 : 2] & 0x07) | bank_helper2), CHRROM);
		chr2_6(((m_reg[bank_helper1 ? 0 : 3] & 0x07) | bank_helper2), CHRROM);
	}
}

void nes_sachen_8259c_device::chr_update()
{
	UINT8 bank_helper1 = m_reg[7] & 0x01;
	UINT8 bank_helper2 = (m_reg[4] & 0x07) << 3;

	if (m_chr_source == CHRROM)
	{
		chr2_0(((m_reg[bank_helper1 ? 0 : 0] & 0x07) | bank_helper2) << 2 | 0, CHRROM);
		chr2_2(((m_reg[bank_helper1 ? 0 : 1] & 0x07) | bank_helper2) << 2 | 1, CHRROM);
		chr2_4(((m_reg[bank_helper1 ? 0 : 2] & 0x07) | bank_helper2) << 2 | 2, CHRROM);
		chr2_6(((m_reg[bank_helper1 ? 0 : 3] & 0x07) | bank_helper2) << 2 | 3, CHRROM);
	}
}

void nes_sachen_8259d_device::chr_update()
{
	if (m_chr_source == CHRROM)
	{
		chr1_0((m_reg[0] & 0x07), CHRROM);
		chr1_1((m_reg[1] & 0x07) | (m_reg[4] << 4 & 0x10), CHRROM);
		chr1_2((m_reg[2] & 0x07) | (m_reg[4] << 3 & 0x10), CHRROM);
		chr1_3((m_reg[3] & 0x07) | (m_reg[4] << 2 & 0x10) | (m_reg[6] << 3 & 0x08), CHRROM);
	}
}