/
konamigx.cpp
4123 lines (3426 loc) · 189 KB
/
konamigx.cpp
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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// license:BSD-3-Clause
// copyright-holders:R. Belmont, Acho A. Tang, Phil Stroffolino, Olivier Galibert
/**************************************************************************
*
* konamigx.cpp - Konami System GX
* Driver by R. Belmont, Acho A. Tang, and Phil Stroffolino.
* ESC protection emulation by Olivier Galibert.
*
* Basic hardware consists of:
* - MC68EC020 main CPU at 24 MHz
* - MC68000 sound CPU with 2x K054539 PCM chips plus a TMS57002 DASP for effects
*
* Tilemaps are handled by the old familiar K054156 with a new partner K056832.
* This combination is mostly compatible with the 156/157 combo but now sports
* up to 8 bits per pixel as well as larger 128x64 tile planes.
*
* Sprites are handled by a K053246 combined with a K055673. This combo was
* actually used on some 16 bit Konami games as well. It appears identical
* to the standard 246/247 combo except with 5-8 bits per pixel.
*
* Video output is handled by a K055555 mixer/priority encoder. This is a much
* more capable beast than the earlier 53251, supporting a background gradient
* and flexible priority handling among other features. It's combined with the
* 54338 alpha blending engine first seen in Xexex for flexible blending.
*
* There are actually 4 types of System GX hardware, which are differentiated
* by their ROM board. The most common is the "Type 2".
*
* 68020 memory map for Type 2:
* 000000: BIOS ROM (128k)
* 200000: game program ROM (1 meg, possibly up to 2)
* 400000: data ROMs
* c00000: Work RAM (128k)
* cc0000: Protection chip
* d00000: 054157 ROM readback for memory test
* d20000: sprite RAM (4k)
* d40000: 054157/056832 tilemap generator (VACSET)
* d44000: tile bank selectors (VSCCS)
* d48000: 053246/055673 sprite generator (OBJSET1)
* d4a000: more readback for sprite generator (OBJSET2)
* d4c000: CCU1 registers (CCUS1)
* 00: HCH 6M/288 8M/384 12M/576 224 256
* 02: HCL HCH 01 01 02 VCH 01 01
* 04: HFPH HCL 7f ff ff VCL 07 20
* 06: HFPL HFPH 00 00 00 VFP 11 0c
* 08: HBPH HFPL 10 19 23 VBP 0e 0e
* 0A: HBPL HBPH 00 00 00 VSW 07 05
* 10: VCH HBPL 30 3f 4d
* 12: VCL HSW 03 04 09
* 14: VFP
* 16: VBP
* 18: VSW/HSW
* 1A: INT TIME
* 1C: INT1ACK (read VCTH) INT1 = V blank
* 1E: INT2ACK (read VCTL) INT2 = H blank
* d4e000: CCU2 registers (CCUS2)
* d50000: K055555 8-bit-per-pixel priority encoder (PCUCS)
* d52000: shared RAM with audio 68000 (SOUNDCS)
* d56000: EEPROM comms, bit 7 is watchdog, bit 5 is frame?? (WRPOR1)
* d56001: IRQ acknowledge (bits 0->3 = irq 1->4), IRQ enable in hi nibble (bits 4->7 = irq 1->4)
* d58000: control register (OBJCHA, 68000 enable/disable, probably more) (WRPOR2)
* d5a000: dipswitch bank 1 (RDPORT1)
* d5a001: dipswitch bank 2
* d5a002: input port (service switch)
* d5a003: EEPROM data/ready in bit 0
* d5c000: player 1 inputs (RDPORT2)
* d5c001: player 2 inputs
* d5e000: test switch (RDPORT3)
* d80000: K054338 alpha blender registers
* d90000: palette RAM for tilemaps
* da0000: tilemap RAM (8k window, bankswitched by d40033)
* dc0000: LANCRAMCS
* dd0000: LANCIOCS
* dd2000: RS232C-1
* dd4000: RS232C-2
* dd6000: trackball 1
* dd8000: trackball 2
* dda000: ADC-WRPORT
* ddc000: ADC-RDPORT
* dde000: EXT-WRPORT
* de0000: EXT_RDPORT
* e00000: type3/4: PSAC2 registers
* e20000: type3/4: unk. register
* e40000: type3/4: unk. register
* e60000: type3/4: PSAC2 linecontrol RAM
* e80000: type3/4: main monitor's palette
* ea0000: type3/4: sub monitor's palette
* ec0000: type3/4: frame flag
* f00000: 32k of RnG2 additional RAM
*
* IRQs:
* 1: VBL (at 60 Hz)
* 2: HBL
* 3: Sprite DMA complete
* 4: from protection device, indicates command completion for "ESC" chip
*
*/
#include "emu.h"
#include "konamigx.h"
#include "cpu/m68000/m68000.h"
#include "cpu/m68000/m68020.h"
#include "cpu/tms57002/tms57002.h"
#include "cpu/z80/z80.h"
#include "machine/eepromser.h"
#include "sound/k054539.h"
//#include "machine/k056230.h"
#include "sound/k056800.h"
#include "speaker.h"
#include "layout/generic.h"
// TODO: check on PCB
#define MASTER_CLOCK XTAL(24'000'000)
#define SUB_CLOCK XTAL(16'000'000)
/**********************************************************************************/
/*
Konami ESC (E Security Chip) protection chip found on:
- Salamander 2
- Sexy Parodius
- Twinbee Yahhoo
- Dragoon Might
- Daisu-Kiss
The ESC is a custom microcontroller with external SRAM connected
to it. It's microprogram is uploaded by the host game. The ESC
has complete DMA access to the entire 68020 address space, like
most Konami protection devices.
Most games use the same or a compatible microprogram. This
program gathers the sprite information scattered around work RAM
and builds a sprite list in sprite RAM which is properly sorted
in priority order. The Japanese version of Gokujou Parodius
contains a 68020 version of this program at 0x2a285c. The code
below is almost a direct translation into C of that routine.
Salamander 2 uses a different work RAM format and a different
ESC program, and Dragoon Might uses a third format and program.
These games haven't been reverse-engineered yet and so have
no sprites.
Winning Spike and the Type 4 games use a new protection chip
made from a Xilinx FPGA. See type4_prot_w for details.
*/
/* constant names mostly taken from sexy parodius, which includes
a debug protection routine with asserts intact! Cracking the ESC
would have been much more difficult without it.
*/
#define ESC_INIT_CONSTANT 0x0108db04
#define ESC_OBJECT_MAGIC_ID 0xfef724fb
#define ESTATE_END 2
#define ESTATE_ERROR 3
// opcode 1
// dragoonj
// ESC Opcode 1 : 000000xx 000000xx 00000xx0 00000000
// tbyahhoo sprites at c00000
// ESC Opcode 1 : 0000ffff 0000ffff 0000ffff 0000000e
// sexyparo sprites at c00604
// ESC Opcode 1 : 00000000 00000000 00d20000 00000000
// ESC Opcode 1 : 00000000 00000000 00d21000 00000000
// salmndr2
// ESC Opcode 1 : 00c1f7f8 0022002c 00c00060 00010014
// tokkae
// ESC Opcode 1 : 00c00000 0000000x 00000023 0000ffff
// puzldama
// ESC Opcode 1 : 002xxxxx 00236102 xxxxxx01 xxxxxxxx
// Say hello to gokuparo at 0x2a285c
/*!
@todo
- Daisu Kiss: sets up 0x00257e28 as set variable in a 2p game after beating specific stages, and causes a game breaking sticky sprite.
It actually also sets up something that looks like non-sprite sub-commands in the same area (example is for character select), I'm inclined to think upper bits are actually used for something else:
00010005
00000006
000e0002
002e0080
- Sexy Parodius: sets up p1 as 2 at start of stage 1, 4 during stage 3A (attract mode), p4 is autoincremented at each gameplay frame. Related to missing effects?
- Tokimeki Memorial: wrong horizontal flip for mode select arrows;
*/
static struct sprite_entry {
int pri;
uint32_t adr;
} sprites[0x100];
void konamigx_state::generate_sprites(address_space &space, uint32_t src, uint32_t spr, int count)
{
int scount = 0;
int ecount = 0;
for(int i=0; i<count; i++) {
uint32_t adr = src + 0x100*i;
int pri;
if(!space.read_word(adr+2))
continue;
pri = space.read_word(adr+28);
if(pri < 256) {
sprites[ecount].pri = pri;
sprites[ecount].adr = adr;
ecount++;
}
}
//qsort(sprites, ecount, sizeof(struct sprite_entry), pri_comp);
for(int i=0; i<ecount; i++) {
uint32_t adr = sprites[i].adr;
if(adr) {
uint32_t set =(space.read_word(adr) << 16)|space.read_word(adr+2);
uint16_t glob_x = space.read_word(adr+4);
uint16_t glob_y = space.read_word(adr+8);
uint16_t flip_x = space.read_word(adr+12) ? 0x1000 : 0x0000;
uint16_t flip_y = space.read_word(adr+14) ? 0x2000 : 0x0000;
uint16_t glob_f = flip_x | (flip_y ^ 0x2000);
uint16_t zoom_x = space.read_word(adr+20);
uint16_t zoom_y = space.read_word(adr+22);
uint16_t color_val = 0x0000;
uint16_t color_mask = 0xffff;
uint16_t color_set = 0x0000;
uint16_t color_rotate = 0x0000;
uint16_t v;
v = space.read_word(adr+24);
if(v & 0x8000) {
color_mask = 0xf3ff;
color_val |= (v & 3) << 10;
}
v = space.read_word(adr+26);
if(v & 0x8000) {
color_mask &= 0xfcff;
color_val |= (v & 3) << 8;
}
v = space.read_word(adr+18);
if(v & 0x8000) {
color_mask &= 0xff1f;
color_val |= v & 0xe0;
}
v = space.read_word(adr+16);
if(v & 0x8000)
color_set = v & 0x1f;
if(v & 0x4000)
color_rotate = v & 0x1f;
if(!zoom_x)
zoom_x = 0x40;
if(!zoom_y)
zoom_y = 0x40;
if(set >= 0x200000 && set < 0xd00000)
{
uint16_t count2 = space.read_word(set);
set += 2;
while(count2) {
uint16_t idx = space.read_word(set);
uint16_t flip = space.read_word(set+2);
uint16_t col = space.read_word(set+4);
short y = space.read_word(set+6);
short x = space.read_word(set+8);
if(idx == 0xffff) {
set = (flip<<16) | col;
if(set >= 0x200000 && set < 0xd00000)
continue;
else
break;
}
if(zoom_y != 0x40)
y = y*0x40/zoom_y;
if(zoom_x != 0x40)
x = x*0x40/zoom_x;
if(flip_x)
x = glob_x - x;
else
x = glob_x + x;
if(x < -256 || x > 512+32)
goto next;
if(flip_y)
y = glob_y - y;
else
y = glob_y + y;
if(y < -256 || y > 512)
goto next;
col = (col & color_mask) | color_val;
if(color_set)
col = (col & 0xffe0) | color_set;
if(color_rotate)
col = (col & 0xffe0) | ((col + color_rotate) & 0x1f);
space.write_word(spr , (flip ^ glob_f) | sprites[i].pri);
space.write_word(spr+ 2, idx);
space.write_word(spr+ 4, y);
space.write_word(spr+ 6, x);
space.write_word(spr+ 8, zoom_y);
space.write_word(spr+10, zoom_x);
space.write_word(spr+12, col);
spr += 16;
scount++;
if(scount == 256)
return;
next:
count2--;
set += 10;
}
}
}
}
while(scount < 256) {
space.write_word(spr, scount);
scount++;
spr += 16;
}
}
void konamigx_state::tkmmpzdm_esc(address_space &space, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4)
{
konamigx_esc_alert(m_workram, 0x0142, 0x100, 0);
}
void konamigx_state::dragoonj_esc(address_space &space, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4)
{
konamigx_esc_alert(m_workram, 0x5c00, 0x100, 0);
}
void konamigx_state::sal2_esc(address_space &space, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4)
{
konamigx_esc_alert(m_workram, 0x1c8c, 0x172, 1);
}
void konamigx_state::sexyparo_esc(address_space &space, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4)
{
// The d20000 should probably be p3
// TODO: debugging bootcamp, remove once finished
#if 0
if (p1 != 0)
{
logerror("sexyparo_esc P1 param: %02x\n", p1);
}
#endif
generate_sprites(space, 0xc00604, 0xd20000, 0xfc);
}
void konamigx_state::tbyahhoo_esc(address_space &space, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4)
{
generate_sprites(space, 0xc00000, 0xd20000, 0x100);
}
void konamigx_state::daiskiss_esc(address_space &space, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4)
{
generate_sprites(space, 0xc00000, 0xd20000, 0x100);
}
void konamigx_state::esc_w(address_space &space, uint32_t data)
{
uint32_t opcode;
uint32_t params;
/* ignore nullptr writes to the ESC (these appear to be "keepalives" on the real hardware) */
if (!data)
{
return;
}
/* ignore out-of-range addresses */
if ((data < 0xc00000) || (data > 0xc1ffff))
{
return;
}
/* the master opcode can be at an unaligned address, so get it "safely" */
opcode = (space.read_word(data+2))|(space.read_word(data)<<16);
/* if there's an OBJECT_MAGIC_ID, that means
there is a valid ESC command packet. */
if (opcode == ESC_OBJECT_MAGIC_ID)
{
int i;
/* get the subop now */
opcode = space.read_byte(data+8);
params = (space.read_word(data+12) << 16) | space.read_word(data+14);
switch(opcode) {
case 5: // Reset
break;
case 2: // Load program
for(i=0; i<4096; i++)
m_esc_program[i] = space.read_byte(params+i);
/*
{
FILE *f;
f = fopen("esc.bin", "wb");
fwrite(esc_program, 4096, 1, f);
fclose(f);
logerror("Dumping ESC program\n");
}
*/
break;
case 1: // Run program
if(m_esc_cb) {
uint32_t p1 = (space.read_word(params+0)<<16) | space.read_word(params+2);
uint32_t p2 = (space.read_word(params+4)<<16) | space.read_word(params+6);
uint32_t p3 = (space.read_word(params+8)<<16) | space.read_word(params+10);
uint32_t p4 = (space.read_word(params+12)<<16) | space.read_word(params+14);
(this->*m_esc_cb)(space, p1, p2, p3, p4);
}
break;
default:
// logerror("Unknown ESC opcode %d\n", opcode);
break;
}
space.write_byte(data+9, ESTATE_END);
if (m_gx_wrport1_1 & 0x10)
{
m_gx_rdport1_3 &= ~8;
m_maincpu->set_input_line(4, HOLD_LINE);
}
}
else
{
/* INIT_CONSTANT means just for the ESC to initialize itself,
there is not normal command parsing here. */
if (opcode == ESC_INIT_CONSTANT)
{
// logerror("Got ESC_INIT_CONSTANT, 'booting' ESC\n");
return;
}
/* unknown constant (never been seen in any game..) */
}
}
/**********************************************************************************/
/* EEPROM handlers */
CUSTOM_INPUT_MEMBER(konamigx_state::gx_rdport1_3_r)
{
return (m_gx_rdport1_3 >> 1);
}
void konamigx_state::eeprom_w(offs_t offset, uint32_t data, uint32_t mem_mask)
{
uint32_t odata;
if (ACCESSING_BITS_24_31)
{
odata = data >> 24;
/*
bit 7: afr, a watchdog timer bit
bit 6: objscan
bit 5: background color select: 0 = 338 solid color, 1 = 5^5 gradient
bit 4: coin counter 2
bit 3: coin counter 1
bit 2: eeprom clock
bit 1: eeprom chip select
bit 0: eeprom data
*/
m_eepromout->write(odata, 0xff);
machine().bookkeeping().coin_counter_w(0, odata & 0x08);
machine().bookkeeping().coin_counter_w(1, odata & 0x10);
m_gx_wrport1_0 = odata;
}
if (ACCESSING_BITS_16_23)
{
/*
bit 7 = mask all IRQ
bit 6 = LAN IRQ enable
bit 5 = CCU2 IRQ enable
bit 4 = ESC IRQ enable
bit 3 = EXCPU IRQ enable
bit 2 = OBJ IRQ enable
bit 1 = CCU1-INT2 enable
bit 0 = CCU1-INT1 enable
*/
m_gx_wrport1_1 = (data>>16)&0xff;
// logerror("write %x to IRQ register (PC=%x)\n", m_gx_wrport1_1, m_maincpu->pc());
// m_gx_syncen is to ensure each IRQ is triggered at least once after being enabled
if (m_gx_wrport1_1 & 0x80)
m_gx_syncen |= m_gx_wrport1_1 & 0x1f;
}
}
void konamigx_state::control_w(offs_t offset, uint32_t data, uint32_t mem_mask)
{
// TODO: derive from reported PCB XTALs
const uint32_t pixclock[4] = { 6'000'000, 8'000'000, 12'000'000, 16'000'000 };
//logerror("write %x to control register (mask=%x)\n", data, mem_mask);
// known controls:
// bit 23 = reset graphics chips
// bit 22 = 0 to halt 68000, 1 to let it run (SOUNDRESET)
// bit 21 = VRAM-CHARD 0=VRAM, 1=ROM
// bit 20 = OBJCHA line for '246
// bit 19 = select top 2 sprite priority bits to be 14/15 or 16/17 of the
// spritelist "color" word.
// bit 18 = if 0, the top 2 sprite priority bits are "11" else use bit 19's
// results.
// bit 17 = DOTSEL1 : 0 = 6M, 1=8M, 2=12M, 3=16M
// bit 16 = DOTSEL0
if (ACCESSING_BITS_16_23)
{
if (data & 0x400000)
{
// Enable sound CPU and DSP
m_soundcpu->set_input_line(INPUT_LINE_HALT, CLEAR_LINE);
m_soundcpu->set_input_line(INPUT_LINE_RESET, CLEAR_LINE);
if (m_sound_ctrl & 0x10)
m_dasp->set_input_line(INPUT_LINE_RESET, CLEAR_LINE);
}
else
{
m_sound_ctrl = 0;
// Reset sound CPU and DSP
m_soundcpu->set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
m_soundcpu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE);
m_dasp->set_input_line(INPUT_LINE_RESET, ASSERT_LINE);
m_k056832->reset();
}
m_k055673->k053246_set_objcha_line((data&0x100000) ? ASSERT_LINE : CLEAR_LINE);
m_gx_wrport2 = (data>>16)&0xff;
if(m_prev_pixel_clock != (m_gx_wrport2 & 3))
{
m_k053252->set_unscaled_clock(pixclock[m_gx_wrport2 & 3]);
m_prev_pixel_clock = m_gx_wrport2 & 3;
}
}
}
/**********************************************************************************/
/* IRQ controllers */
TIMER_CALLBACK_MEMBER(konamigx_state::boothack_callback)
{
// Restore main CPU normal operating frequency
m_maincpu->set_clock_scale(1.0f);
}
/*
GX object DMA timings:
6Mhz dotclock: 42.7us(clear) / 341.3us(transfer)
8Mhz dotclock: 32.0us(clear) / 256.0us(transfer)
12Mhz dotclock: 42.7us(clear) / 341.3us(transfer)
*/
TIMER_CALLBACK_MEMBER(konamigx_state::dmaend_callback)
{
// foul-proof (CPU0 could be deactivated while we wait)
if (m_resume_trigger && m_suspension_active)
{
m_suspension_active = 0;
machine().scheduler().trigger(m_resume_trigger);
}
// DMA busy flag must be cleared before triggering IRQ 3
m_gx_rdport1_3 &= ~2;
// IRQ 3 is the "object DMA end" IRQ also happens during vblank
if ((m_gx_wrport1_1 & 0x84) == 0x84 || (m_gx_syncen & 4))
{
m_gx_syncen &= ~4;
// lower OBJINT-REQ flag and trigger interrupt
m_gx_rdport1_3 &= ~0x80;
m_maincpu->set_input_line(3, HOLD_LINE);
}
}
void konamigx_state::dmastart_callback(int data)
{
int sprite_timing;
// raise the DMA busy flag
// TODO: is it supposed to raise even if DMA is disabled?
m_gx_rdport1_3 |= 2;
// begin transfer if DMAEN(bit4 of OBJSET1) is set (see p.48)
if (m_k055673->k053246_read_register(5) & 0x10)
{
// disabled by default since it doesn't work too well in MAME
konamigx_objdma();
}
// simulate DMA delay
// TODO: Rushing Heroes doesn't like reported sprite timings, probably due of sprite protection being issued istantly or requires the double buffering ...
if(m_gx_rushingheroes_hack == 1)
sprite_timing = 64;
else
sprite_timing = m_gx_wrport2 & 1 ? (256+32) : (342+42);
m_dmadelay_timer->adjust(attotime::from_usec(sprite_timing));
}
INTERRUPT_GEN_MEMBER(konamigx_state::konamigx_type2_vblank_irq)
{
// lift idle suspension
if (m_resume_trigger && m_suspension_active)
{
m_suspension_active = 0;
machine().scheduler().trigger(m_resume_trigger);
}
// IRQ 1 is the main 60hz vblank interrupt
if (m_gx_syncen & 0x20)
{
m_gx_syncen &= ~0x20;
if ((m_gx_wrport1_1 & 0x81) == 0x81 || (m_gx_syncen & 1))
{
m_gx_syncen &= ~1;
// TODO: enabling ASSERT_LINE breaks opengolf, annoying.
device.execute().set_input_line(1, HOLD_LINE);
}
}
dmastart_callback(0);
}
TIMER_DEVICE_CALLBACK_MEMBER(konamigx_state::konamigx_type2_scanline)
{
int scanline = param;
if(scanline == 48)
{
if (m_gx_syncen & 0x40)
{
m_gx_syncen &= ~0x40;
if ((m_gx_wrport1_1 & 0x82) == 0x82 || (m_gx_syncen & 2))
{
popmessage("HBlank IRQ enabled, contact MAMEdev");
m_gx_syncen &= ~2;
m_maincpu->set_input_line(2, HOLD_LINE);
}
}
}
}
TIMER_DEVICE_CALLBACK_MEMBER(konamigx_state::konamigx_type4_scanline)
{
int scanline = param;
if (scanline == 240)
{
// lift idle suspension
if (m_resume_trigger && m_suspension_active)
{
m_suspension_active = 0;
machine().scheduler().trigger(m_resume_trigger);
}
// IRQ 1 is the main 60hz vblank interrupt
// the m_gx_syncen & 0x20 test doesn't work on type 3 or 4 ROM boards, likely because the ROM board
// generates the timing in those cases. With this change, rushing heroes and rng2 boot :)
// maybe this interrupt should only be every 30fps, or maybe there are flags to prevent the game running too fast
// the real hardware should output the display for each screen on alternate frames
// if(device->m_screen->frame_number() & 1)
if (1) // m_gx_syncen & 0x20)
{
m_gx_syncen &= ~0x20;
if ((m_gx_wrport1_1 & 0x81) == 0x81 || (m_gx_syncen & 1))
{
m_gx_syncen &= ~1;
m_maincpu->set_input_line(1, HOLD_LINE);
}
}
dmastart_callback(0);
}
else if(scanline < 240) // hblank
{
// IRQ 2 is a programmable interrupt with scanline resolution
if (m_gx_syncen & 0x40)
{
m_gx_syncen &= ~0x40;
if ((m_gx_wrport1_1 & 0x82) == 0x82 || (m_gx_syncen & 2))
{
m_gx_syncen &= ~2;
m_maincpu->set_input_line(2, HOLD_LINE);
}
}
}
}
/**********************************************************************************/
/* input handlers */
/* National Semiconductor ADC0834 4-channel serial ADC emulation */
double konamigx_state::adc0834_callback(uint8_t input)
{
switch (input)
{
case ADC083X_CH0:
return (double)(5 * m_an0->read()) / 255.0; // steer
case ADC083X_CH1:
return (double)(5 * m_an1->read()) / 255.0; // gas
case ADC083X_VREF:
return 5;
}
return 0;
}
uint32_t konamigx_state::le2_gun_H_r()
{
int p1x = m_light0_x->read()*290/0xff+20;
int p2x = m_light1_x->read()*290/0xff+20;
return (p1x<<16)|p2x;
}
uint32_t konamigx_state::le2_gun_V_r()
{
int p1y = m_light0_y->read()*224/0xff;
int p2y = m_light1_y->read()*224/0xff;
// make "off the bottom" reload too
if (p1y >= 0xdf) p1y = 0;
if (p2y >= 0xdf) p2y = 0;
return (p1y<<16)|p2y;
}
/**********************************************************************************/
/* system or game dependent handlers */
uint32_t konamigx_state::type1_roz_r1(offs_t offset)
{
uint32_t *ROM = (uint32_t *)memregion("gfx3")->base();
return ROM[offset];
}
uint32_t konamigx_state::type1_roz_r2(offs_t offset)
{
uint32_t *ROM = (uint32_t *)memregion("gfx3")->base();
ROM += (0x600000/2);
return ROM[offset];
}
uint32_t konamigx_state::type3_sync_r()
{
if(m_konamigx_current_frame==0)
return -1; // return 0xfffffffe | 1;
else
return 0;// return 0xfffffffe | 0;
}
/*
Run and Gun 2, Rushing Heroes, Winning Spike, and Vs. Net Soccer contain a XILINX FPGA that serves as security.
RnG2's version is "K002204"
Rushing Heroes' is "K0000035891"
Vs Net Soccer is "003462"
Winning Spike's is "0000032652"
RnG2's is used to generate the sprite list just like the ESC, among other tasks. (RnG2 sends many commands per frame to the protection).
Rushing Heroes is much simpler and uses only 1 command during gameplay. They set up a giant table of pointers
at C10200->C102EF (see the routine at 2043CE. C10001 contains which monitor they want to update (main or sub)
and it changes the pointers accordingly). This sets up the palettes, the sprite list, and the ROZ tilemap, from the looks of things.
Here are the lists constructed by Rushing Heroes (I've reordered the original code so it's in linear address order).
Vs. Net Soccer does the same thing starting at 2064DC (in fact, Rushing Heroes appears to be heavily based on Vs. Net's code).
main monitor (2043da) sub monitor (204616)
move.l #$C0C000,($C10200).l move.l #$C1C000,($C10200).l
move.l #$C10000,($C10204).l move.l #$C20000,($C10204).l
move.l #$C0C000,($C10208).l move.l #$C1C000,($C10208).l
move.l #$C0C200,($C1020C).l move.l #$C1C200,($C1020C).l
move.l #$C0C200,($C10210).l move.l #$C1C200,($C10210).l
move.l #$C0D800,($C10214).l move.l #$C1D800,($C10214).l
move.l #$C0D800,($C10218).l move.l #$C1D800,($C10218).l
move.l #$C0EE00,($C1021C).l move.l #$C1EE00,($C1021C).l
move.l #$C0EE00,($C10220).l move.l #$C1EE00,($C10220).l
move.l #$C0F200,($C10224).l move.l #$C1F200,($C10224).l
move.l #$C0EE00,($C10228).l move.l #$C1EE00,($C10228).l
move.l #$C0EE00,($C1022C).l move.l #$C1EE00,($C1022C).l
move.l #$C0F000,($C10230).l move.l #$C1F000,($C10230).l
move.l #$C1C200,($C10234).l move.l #$C0C200,($C10234).l
move.l #$C1EE00,($C10238).l move.l #$C0EE00,($C10238).l
move.l #$C0A000,($C1023C).l move.l #$C1A000,($C1023C).l
move.l #$C0C000,($C10240).l move.l #$C1C000,($C10240).l
move.l #$C0A000,($C10244).l move.l #$C1A000,($C10244).l
move.l #$C10000,($C10248).l move.l #$C20000,($C10248).l
move.l #$C0FA00,($C1024C).l move.l #$C1FA00,($C1024C).l
move.l #$C1A000,($C10250).l move.l #$C0A000,($C10250).l
move.l #$C00000,($C10260).l move.l #$C10000,($C10260).l
move.l #$C10000,($C10264).l move.l #$C00000,($C10264).l
move.l #$C00800,($C10268).l move.l #$C10800,($C10268).l
move.l #$C01000,($C1026C).l move.l #$C11000,($C1026C).l
move.l #$C00500,($C10270).l move.l #$C10500,($C10270).l
move.l #$C00520,($C10274).l move.l #$C10520,($C10274).l
move.l #$C00540,($C10278).l move.l #$C10540,($C10278).l
move.l #$C00560,($C1027C).l move.l #$C10560,($C1027C).l
move.l #$C100C0,($C10280).l move.l #$C100E0,($C10280).l
move.l #$C100D0,($C10284).l move.l #$C100F0,($C10284).l
move.l #$C100E0,($C10288).l move.l #$C100C0,($C10288).l
move.l #$C100F0,($C1028C).l move.l #$C100D0,($C1028C).l
move.l #$E82000,($C10290).l move.l #$EA2000,($C10290).l palette segment (E80000 = main monitor palette, EA0000 = sub monitor palette)
move.l #$E83000,($C10294).l move.l #$EA3000,($C10294).l palette segment
move.l #$E84000,($C10298).l move.l #$EA4000,($C10298).l palette segment
move.l #$E85000,($C1029C).l move.l #$EA5000,($C1029C).l palette segment
move.l #$E80000,($C102A0).l move.l #$EA0000,($C102A0).l palette segment
move.l #$E86000,($C102A4).l move.l #$EA6000,($C102A4).l palette segment
move.l #$E86800,($C102A8).l move.l #$EA6800,($C102A8).l palette segment
move.l #$D20000,($C102B0).l move.l #$D21000,($C102B0).l sprite list
move.l #$D21000,($C102B4).l move.l #$D22000,($C102B4).l sprite end
move.l #$C09000,($C102B8).l move.l #$C19000,($C102B8).l
move.l #$C0A000,($C102BC).l move.l #$C1A000,($C102BC).l
move.l #$C00700,($C102C0).l move.l #$C10700,($C102C0).l
move.l #$C00780,($C102C4).l move.l #$C10780,($C102C4).l
move.l #$C10700,($C102C8).l move.l #$C00700,($C102C8).l
move.l #$C10780,($C102CC).l move.l #$C00780,($C102CC).l
move.l #$C02070,($C102D0).l move.l #$C12070,($C102D0).l
move.l #$C09000,($C102D4).l move.l #$C19000,($C102D4).l
move.l #$C12070,($C102D8).l move.l #$C02070,($C102D8).l
move.l #$C19000,($C102DC).l move.l #$C09000,($C102DC).l
move.l #$C12000,($C102E0).l move.l #$C12000,($C102E0).l
move.l #$C20000,($C102E4).l move.l #$C20000,($C102E4).l
move.l #$C10300,($C102E8).l move.l #$C10300,($C102E8).l
move.l #$C10400,($C102EC).l move.l #$C10400,($C102EC).l
*/
void konamigx_state::type4_prot_w(address_space &space, offs_t offset, uint32_t data)
{
int clk;
int i;
if (offset == 1)
{
m_last_prot_op = data>>16;
}
else
{
if ((data & 0xff00) == 0)
m_last_prot_param = data & 0xffff;
data >>= 16;
clk = data & 0x200;
if ((clk == 0) && (m_last_prot_clk != 0))
{
if (m_last_prot_op != -1)
{
// osd_printf_debug("type 4 prot command: %x\n", m_last_prot_op);
/*
known commands:
rng2 rushhero vsnet winspike what
------------------------------------------------------------------------------
0a56 0d96 0d14 0d1c memcpy from c01000 to c01400 for 0x400 bytes
0b16 generate sprite list at c01000 or c08400 (not sure entirely, see routine at 209922 in rungun2)
0d97 0515 parse big DMA list at c10200
057a copy 4 bytes from c00f10 to c10f00 and 4 bytes from c00f30 to c0fe00
*/
if ((m_last_prot_op == 0xa56) || (m_last_prot_op == 0xd96) || (m_last_prot_op == 0xd14) || (m_last_prot_op == 0xd1c))
{
// memcpy from c01000 to c01400 for 0x400 bytes (startup check for type 4 games)
for (i = 0; i < 0x400; i += 2)
{
space.write_word(0xc01400+i, space.read_word(0xc01000+i));
}
}
else if(m_last_prot_op == 0x57a) // winspike
{
/* player 1 input buffer protection */
space.write_dword(0xc10f00, space.read_dword(0xc00f10));
space.write_dword(0xc10f04, space.read_dword(0xc00f14));
/* player 2 input buffer protection */
space.write_dword(0xc10f20, space.read_dword(0xc00f20));
space.write_dword(0xc10f24, space.read_dword(0xc00f24));
/* ... */
space.write_dword(0xc0fe00, space.read_dword(0xc00f30));
space.write_dword(0xc0fe04, space.read_dword(0xc00f34));
}
else if(m_last_prot_op == 0xd97) // rushhero
{
u32 src = 0xc09ff0;
u32 dst = 0xd20000;
//u32 input_src = 0xc01cc0;
//u32 input_dst = 0xc00507;
// screen 1
// if (m_last_prot_param == 0x004a)
// screen 2
if (m_last_prot_param == 0x0062)
{
src = 0xc19ff0;
dst = 0xd21000;
//input_src += 0x10000;
//input_dst += 0x40;
}
for (int spr = 0; spr < 256; spr++)
{
for (i = 0; i <= 0x10; i += 4)
{
space.write_dword(dst + i, space.read_dword(src+i));
}
src -= 0x10;
dst += 0x10;
}
/* Input buffer copiers, only this command is executed so it's safe to assume that's polled here */
space.write_byte(0xc01cc0 + 0, ~space.read_byte(0xc00507 + 0x00));
space.write_byte(0xc01cc0 + 1, ~space.read_byte(0xc00507 + 0x20));
space.write_byte(0xc01cc0 + 4, ~space.read_byte(0xc00507 + 0x40));
space.write_byte(0xc01cc0 + 5, ~space.read_byte(0xc00507 + 0x60));
space.write_byte(0xc11cc0 + 0, ~space.read_byte(0xc00507 + 0x00));
space.write_byte(0xc11cc0 + 1, ~space.read_byte(0xc00507 + 0x20));
space.write_byte(0xc11cc0 + 4, ~space.read_byte(0xc00507 + 0x40));
space.write_byte(0xc11cc0 + 5, ~space.read_byte(0xc00507 + 0x60));
}
else if(m_last_prot_op == 0xb16) // slamdnk2
{
int src = 0xc01000;
int dst = 0xd20000;
int spr;
for (spr = 0; spr < 0x100; spr++)
{
space.write_word(dst, space.read_word(src));
src += 4;
dst += 2;
}
//maybe here there's a [$d8001f] <- 0x31 write too?
}
// TODO: it actually calls 0x1b54-335e-125c-3a56-1b55-3357-1255-3a4f on odd frames
// should first move a block to a work RAM buffer then send it to the actual sprite entries
else if (m_last_prot_op == 0x3a4f) // slamdnk2 right screen
{
u32 src = 0xc18400;
u32 dst = 0xd21000;
for (int spr = 0; spr < 0x400; spr++)
{
space.write_word(dst, space.read_word(src));
src += 4;
dst += 2;
}
}
else if(m_last_prot_op == 0x515) // vsnetscr screen 1
{
int adr;
//printf("GXT4: command %x %d (PC=%x)\n", m_last_prot_op, cc++, m_maincpu->pc());
for (adr = 0; adr < 0x400; adr += 2)
space.write_word(0xc01c00+adr, space.read_word(0xc01800+adr));
}
else if(m_last_prot_op == 0x115d) // vsnetscr screen 2
{
int adr;
//printf("GXT4: command %x %d (PC=%x)\n", m_last_prot_op, cc++, m_maincpu->pc());
for (adr = 0; adr < 0x400; adr += 2)
space.write_word(0xc18c00+adr, space.read_word(0xc18800+adr));
}
else
{
//printf("GXT4: unknown protection command %x (PC=%x)\n", m_last_prot_op, m_maincpu->pc());
}