Previous 199869 Revisions Next

r32632 Friday 10th October, 2014 at 20:39:28 UTC by David Haywood
further st0016 reorganization (nw)
[src/mame/drivers]jclub2.c macs.c speglsht.c srmp5.c st0016.c
[src/mame/includes]st0016.h
[src/mame/machine]st0016.c st0016.h
[src/mame/video]st0016.c

trunk/src/mame/drivers/srmp5.c
r32631r32632
3434*/
3535
3636
37// this uploads a charset for the st0016, but never a palette, seems to be for sound only?
38
3739#include "emu.h"
3840#include "machine/st0016.h"
3941#include "cpu/mips/r3000.h"
r32631r32632
6466{
6567public:
6668   srmp5_state(const machine_config &mconfig, device_type type, const char *tag)
67      : st0016_state(mconfig, type, tag) { }
69      : st0016_state(mconfig, type, tag),
70       m_gfxdecode(*this, "gfxdecode"),
71       m_palette(*this, "palette")
72   
73   { }
6874
6975   UINT32 m_databank;
7076   UINT16 *m_tileram;
r32631r32632
102108   DECLARE_READ8_MEMBER(cmd_stat8_r);
103109   DECLARE_DRIVER_INIT(srmp5);
104110   UINT32 screen_update_srmp5(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
111   required_device<gfxdecode_device> m_gfxdecode;
112   required_device<palette_device> m_palette;
105113};
106114
107115
r32631r32632
370378   AM_RANGE(0x0000, 0x7fff) AM_ROM
371379   AM_RANGE(0x8000, 0xbfff) AM_ROMBANK("bank1")
372380   //AM_RANGE(0xe900, 0xe9ff) // sound - internal
373   AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
381   //AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
374382   AM_RANGE(0xf000, 0xffff) AM_RAM
375383ADDRESS_MAP_END
376384
r32631r32632
392400
393401static ADDRESS_MAP_START( st0016_io, AS_IO, 8, srmp5_state )
394402   ADDRESS_MAP_GLOBAL_MASK(0xff)
395   AM_RANGE(0x00, 0xbf) AM_READ(st0016_vregs_r) AM_WRITE(st0016_vregs_w)
403   //AM_RANGE(0x00, 0xbf) AM_READ(st0016_vregs_r) AM_WRITE(st0016_vregs_w)
396404   AM_RANGE(0xc0, 0xc0) AM_READ(cmd1_r)
397405   AM_RANGE(0xc1, 0xc1) AM_READ(cmd2_r)
398406   AM_RANGE(0xc2, 0xc2) AM_READ(cmd_stat8_r)
399407   AM_RANGE(0xe1, 0xe1) AM_WRITE(st0016_rom_bank_w)
400408   AM_RANGE(0xe7, 0xe7) AM_WRITE(st0016_rom_bank_w)
401   AM_RANGE(0xf0, 0xf0) AM_READ(st0016_dma_r)
409   //AM_RANGE(0xf0, 0xf0) AM_READ(st0016_dma_r)
402410ADDRESS_MAP_END
403411
404412
r32631r32632
583591
584592DRIVER_INIT_MEMBER(srmp5_state,srmp5)
585593{
586   st0016_game = 9;
594   m_maincpu->st0016_game = 9;
587595
588596   m_tileram = auto_alloc_array(machine(), UINT16, 0x100000/2);
589597   m_sprram  = auto_alloc_array(machine(), UINT16, 0x080000/2);
trunk/src/mame/drivers/st0016.c
r32631r32632
2828static ADDRESS_MAP_START( st0016_mem, AS_PROGRAM, 8, st0016_state )
2929   AM_RANGE(0x0000, 0x7fff) AM_ROM
3030   AM_RANGE(0x8000, 0xbfff) AM_ROMBANK("bank1")
31   AM_RANGE(0xc000, 0xcfff) AM_READ(st0016_sprite_ram_r) AM_WRITE(st0016_sprite_ram_w)
32   AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w)
3331   AM_RANGE(0xe000, 0xe7ff) AM_RAM
3432   AM_RANGE(0xe800, 0xe87f) AM_RAM /* common ram */
35   //AM_RANGE(0xe900, 0xe9ff) // sound - internal
36   AM_RANGE(0xea00, 0xebff) AM_READ(st0016_palette_ram_r) AM_WRITE(st0016_palette_ram_w)
37   AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
3833   AM_RANGE(0xf000, 0xffff) AM_RAM /* work ram */
3934ADDRESS_MAP_END
4035
r32631r32632
8176
8277static ADDRESS_MAP_START( st0016_io, AS_IO, 8, st0016_state )
8378   ADDRESS_MAP_GLOBAL_MASK(0xff)
84   AM_RANGE(0x00, 0xbf) AM_READ(st0016_vregs_r) AM_WRITE(st0016_vregs_w) /* video/crt regs ? */
8579   AM_RANGE(0xc0, 0xc0) AM_READ_PORT("P1") AM_WRITE(mux_select_w)
8680   AM_RANGE(0xc1, 0xc1) AM_READ_PORT("P2") AM_WRITENOP
8781   AM_RANGE(0xc2, 0xc2) AM_READ(mux_r) AM_WRITENOP
8882   AM_RANGE(0xc3, 0xc3) AM_READ_PORT("P2") AM_WRITENOP
8983   AM_RANGE(0xe0, 0xe0) AM_WRITENOP /* renju = $40, neratte = 0 */
9084   AM_RANGE(0xe1, 0xe1) AM_WRITE(st0016_rom_bank_w)
91   AM_RANGE(0xe2, 0xe2) AM_WRITE(st0016_sprite_bank_w)
92   AM_RANGE(0xe3, 0xe4) AM_WRITE(st0016_character_bank_w)
93   AM_RANGE(0xe5, 0xe5) AM_WRITE(st0016_palette_bank_w)
9485   AM_RANGE(0xe6, 0xe6) AM_WRITENOP /* banking ? ram bank ? shared rambank ? */
9586   AM_RANGE(0xe7, 0xe7) AM_WRITENOP /* watchdog */
96   AM_RANGE(0xf0, 0xf0) AM_READ(st0016_dma_r)
9787ADDRESS_MAP_END
9888
9989
r32631r32632
145135
146136static ADDRESS_MAP_START( st0016_m2_io, AS_IO, 8, st0016_state )
147137   ADDRESS_MAP_GLOBAL_MASK(0xff)
148   AM_RANGE(0x00, 0xbf) AM_READ(st0016_vregs_r) AM_WRITE(st0016_vregs_w)
149138   AM_RANGE(0xc0, 0xc3) AM_READ(latch8_r) AM_WRITE(latch8_w)
150139   AM_RANGE(0xd0, 0xd0) AM_READ_PORT("P1") AM_WRITE(mux_select_w)
151140   AM_RANGE(0xd1, 0xd1) AM_READ_PORT("P2") AM_WRITENOP
r32631r32632
153142   AM_RANGE(0xd3, 0xd3) AM_READ_PORT("P2") AM_WRITENOP
154143   AM_RANGE(0xe0, 0xe0) AM_WRITENOP
155144   AM_RANGE(0xe1, 0xe1) AM_WRITE(st0016_rom_bank_w)
156   AM_RANGE(0xe2, 0xe2) AM_WRITE(st0016_sprite_bank_w)
157   AM_RANGE(0xe3, 0xe4) AM_WRITE(st0016_character_bank_w)
158   AM_RANGE(0xe5, 0xe5) AM_WRITE(st0016_palette_bank_w)
159145   AM_RANGE(0xe6, 0xe6) AM_WRITENOP /* banking ? ram bank ? shared rambank ? */
160146   AM_RANGE(0xe7, 0xe7) AM_WRITENOP /* watchdog */
161   AM_RANGE(0xf0, 0xf0) AM_READ(st0016_dma_r)
162147ADDRESS_MAP_END
163148
164149/*************************************
r32631r32632
418403   MCFG_SCREEN_SIZE(48*8, 48*8)
419404   MCFG_SCREEN_VISIBLE_AREA(0*8, 48*8-1, 0*8, 48*8-1)
420405   MCFG_SCREEN_UPDATE_DRIVER(st0016_state, screen_update_st0016)
421   MCFG_SCREEN_PALETTE("palette")
406   MCFG_SCREEN_PALETTE("maincpu:palette")
422407
423   MCFG_GFXDECODE_ADD("gfxdecode", "palette", st0016)
424   MCFG_PALETTE_ADD("palette", 16*16*4+1)
425408
426409   MCFG_VIDEO_START_OVERRIDE(st0016_state,st0016)
427410
r32631r32632
637620
638621DRIVER_INIT_MEMBER(st0016_state,renju)
639622{
640   st0016_game=0;
623   m_maincpu->st0016_game=0;
641624}
642625
643626DRIVER_INIT_MEMBER(st0016_state,nratechu)
644627{
645   st0016_game=1;
628   m_maincpu->st0016_game=1;
646629}
647630
648631DRIVER_INIT_MEMBER(st0016_state,mayjinsn)
649632{
650   st0016_game=4;//|0x80;
633   m_maincpu->st0016_game=4;//|0x80;
651634   membank("bank2")->set_base(memregion("user1")->base());
652635}
653636
654637DRIVER_INIT_MEMBER(st0016_state,mayjisn2)
655638{
656   st0016_game=4;
639   m_maincpu->st0016_game=4;
657640   membank("bank2")->set_base(memregion("user1")->base());
658641}
659642
trunk/src/mame/drivers/jclub2.c
r32631r32632
112112      m_tmapscroll2(*this, "tmapscroll2"),
113113      m_spriteram(*this, "spriteram"),
114114      m_gdfs_st0020(*this, "st0020_spr"),
115      m_maincpu(*this, "maincpu"),
115      m_gamecpu(*this, "gamecpu"),
116116      m_eeprom(*this, "eeprom"),
117      m_palette(*this, "palette") { }
117      m_palette(*this, "palette"),
118       m_gfxdecode(*this, "gfxdecode")
119   { }
118120
119121   tilemap_t *m_tmap;
120122   tilemap_t *m_tmap2;
r32631r32632
128130   int m_jclub2_gfx_index;
129131   optional_shared_ptr<UINT32> m_spriteram;
130132   optional_device<st0020_device> m_gdfs_st0020;
131   required_device<cpu_device> m_maincpu;
133   required_device<cpu_device> m_gamecpu;
132134   required_device<eeprom_serial_93cxx_device> m_eeprom;
133135   required_device<palette_device> m_palette;
134136   DECLARE_WRITE32_MEMBER(darkhors_tmapram_w);
r32631r32632
155157   UINT32 screen_update_jclub2o(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
156158   TIMER_DEVICE_CALLBACK_MEMBER(darkhors_irq);
157159   void draw_sprites_darkhors(bitmap_ind16 &bitmap, const rectangle &cliprect);
160   required_device<gfxdecode_device> m_gfxdecode;
158161};
159162
160163
r32631r32632
948951   int scanline = param;
949952
950953   if(scanline == 248)
951      m_maincpu->set_input_line(5, HOLD_LINE);
954      m_gamecpu->set_input_line(5, HOLD_LINE);
952955
953956   if(scanline == 0)
954      m_maincpu->set_input_line(3, HOLD_LINE);
957      m_gamecpu->set_input_line(3, HOLD_LINE);
955958
956959   if(scanline == 128)
957      m_maincpu->set_input_line(4, HOLD_LINE);
960      m_gamecpu->set_input_line(4, HOLD_LINE);
958961}
959962
960963static MACHINE_CONFIG_START( darkhors, darkhors_state )
961   MCFG_CPU_ADD("maincpu", M68EC020, 12000000) // 36MHz/3 ??
964   MCFG_CPU_ADD("gamecpu", M68EC020, 12000000) // 36MHz/3 ??
962965   MCFG_CPU_PROGRAM_MAP(darkhors_map)
963966   MCFG_TIMER_DRIVER_ADD_SCANLINE("scantimer", darkhors_state, darkhors_irq, "screen", 0, 1)
964967
r32631r32632
10011004}
10021005
10031006static MACHINE_CONFIG_START( jclub2, darkhors_state )
1004   MCFG_CPU_ADD("maincpu", M68EC020, 12000000)
1007   MCFG_CPU_ADD("gamecpu", M68EC020, 12000000)
10051008   MCFG_CPU_PROGRAM_MAP(jclub2_map)
10061009   MCFG_TIMER_DRIVER_ADD_SCANLINE("scantimer", darkhors_state, darkhors_irq, "screen", 0, 1)
10071010
r32631r32632
10381041   AM_RANGE(0x0000, 0x7fff) AM_ROM
10391042   AM_RANGE(0x8000, 0xbfff) AM_ROMBANK("bank1")
10401043   //AM_RANGE(0xe900, 0xe9ff) // sound - internal
1041   AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
1044   //AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
10421045   AM_RANGE(0xe82f, 0xe830) AM_READNOP
10431046   AM_RANGE(0xf000, 0xffff) AM_RAM
10441047ADDRESS_MAP_END
10451048
10461049static ADDRESS_MAP_START( st0016_io, AS_IO, 8, darkhors_state )
10471050   ADDRESS_MAP_GLOBAL_MASK(0xff)
1048   AM_RANGE(0x00, 0xbf) AM_READ(st0016_vregs_r) AM_WRITE(st0016_vregs_w)
1051   //AM_RANGE(0x00, 0xbf) AM_READ(st0016_vregs_r) AM_WRITE(st0016_vregs_w)
10491052   //AM_RANGE(0xc0, 0xc0) AM_READ(cmd1_r)
10501053   //AM_RANGE(0xc1, 0xc1) AM_READ(cmd2_r)
10511054   //AM_RANGE(0xc2, 0xc2) AM_READ(cmd_stat8_r)
r32631r32632
10661069}
10671070
10681071static MACHINE_CONFIG_START( jclub2o, darkhors_state )
1069   MCFG_CPU_ADD("maincpu", M68EC020, 12000000)
1072   MCFG_CPU_ADD("gamecpu", M68EC020, 12000000)
10701073   MCFG_CPU_PROGRAM_MAP(jclub2o_map)
10711074   MCFG_TIMER_DRIVER_ADD_SCANLINE("scantimer", darkhors_state, darkhors_irq, "screen", 0, 1)
10721075
1073   MCFG_CPU_ADD("st0016",ST0016_CPU,8000000)
1076   MCFG_CPU_ADD("maincpu",ST0016_CPU,8000000)
10741077   MCFG_CPU_PROGRAM_MAP(st0016_mem)
10751078   MCFG_CPU_IO_MAP(st0016_io)
10761079   MCFG_CPU_VBLANK_INT_DRIVER("screen", darkhors_state,  irq0_line_hold)
r32631r32632
11111114***************************************************************************/
11121115
11131116ROM_START( darkhors )
1114   ROM_REGION( 0x100000, "maincpu", 0 )    // 68EC020 code
1117   ROM_REGION( 0x100000, "gamecpu", 0 )    // 68EC020 code
11151118   ROM_LOAD32_WORD_SWAP( "prg2", 0x00000, 0x80000, CRC(f2ec5818) SHA1(326937a331496880f517f41b0b8ab54e55fd7af7) )
11161119   ROM_LOAD32_WORD_SWAP( "prg1", 0x00002, 0x80000, CRC(b80f8f59) SHA1(abc26dd8b36da0d510978364febe385f69fb317f) )
11171120
r32631r32632
11861189
11871190// this contains mutliple sets, although splitting them as listed above makes no sense.. especially not the 'subcpu' roms
11881191ROM_START( jclub2 )
1189   ROM_REGION( 0x200000, "maincpu", 0 )    // 68EC020 code  + compressed GFX
1192   ROM_REGION( 0x200000, "gamecpu", 0 )    // 68EC020 code  + compressed GFX
11901193   // main program (similar to main program of bootleg
11911194   ROM_LOAD16_WORD_SWAP( "m88-01b.u38",0x00000, 0x200000, CRC(f1054c69) SHA1(be6d92653f0d3cc0a36a2ff0798043f4a95439bc) )
11921195   ROM_LOAD16_WORD_SWAP( "m88-01a.u38",0x00000, 0x200000, CRC(c1243e1c) SHA1(2a5857738b8950daf77ddaa8304b765f809f8241) ) // alt revision?
r32631r32632
12441247
12451248// this contains mutliple sets
12461249ROM_START( jclub2o )
1247   ROM_REGION( 0x200000, "maincpu", 0 )    // 68EC020 code + compressed gfx
1250   ROM_REGION( 0x200000, "gamecpu", 0 )    // 68EC020 code + compressed gfx
12481251   ROM_LOAD16_WORD_SWAP( "sx006a-01.106",0x00000, 0x200000, CRC(55e249bc) SHA1(ed0f066ed17f047760b712cbbfba1a62d4b452ba) )
12491252   ROM_LOAD16_WORD_SWAP( "sx006b-01.u26",0x00000, 0x200000, CRC(f730dded) SHA1(efb966dcb98440a072d4825ef2788c85acdfd103) )  // alt revision?
12501253
r32631r32632
12541257   ROM_LOAD16_WORD_SWAP( "jc2-110x.u27",0x00000, 0x080000, CRC(03aa6882) SHA1(e0343bc77a19994ddafa614891663b40e1476332) )
12551258   ROM_LOAD16_WORD_SWAP( "jc2-112x.u27",0x00000, 0x080000, CRC(e1ab93bd) SHA1(78b618b3f7819bd5351ebf949f328fec7795cec9) ) // alt revision?
12561259
1257   ROM_REGION( 0x80000, "st0016", 0 ) // z80 core (used for sound?)
1260   ROM_REGION( 0x80000, "maincpu", 0 ) // z80 core (used for sound?)
12581261   ROM_LOAD( "sx006-04.u87", 0x00000, 0x80000, CRC(a87adedd) SHA1(1cd5af2d03738fff2230b46241659179467c828c) )
12591262
12601263   ROM_REGION( 0x100, "eeprom", 0 ) // eeprom 16 bit one!!!
r32631r32632
12671270  Maybe upgraded to a release candidate software revision.
12681271*/
12691272ROM_START( jclub2ob )
1270   ROM_REGION( 0x200000, "maincpu", 0 )    // 68EC020 code + compressed gfx
1273   ROM_REGION( 0x200000, "gamecpu", 0 )    // 68EC020 code + compressed gfx
12711274   ROM_LOAD16_WORD_SWAP( "sx006a-01.u26",0x00000, 0x200000, CRC(55e249bc) SHA1(ed0f066ed17f047760b712cbbfba1a62d4b452ba) )
12721275
12731276   ROM_REGION( 0x200000, "patch", 0 )  // 68EC020 code
r32631r32632
12751278   // overriding the initial 0x80000 bytes of the program rom.
12761279   ROM_LOAD16_WORD_SWAP( "203x-rom1.u27",0x00000, 0x080000, CRC(7446ed3e) SHA1(b0936e42549280e2965159270429c4fdacba114a) )
12771280
1278   ROM_REGION( 0x80000, "st0016", 0 ) // z80 core (used for sound?)
1281   ROM_REGION( 0x80000, "maincpu", 0 ) // z80 core (used for sound?)
12791282   ROM_LOAD( "sx006-04.u87", 0x00000, 0x80000, CRC(a87adedd) SHA1(1cd5af2d03738fff2230b46241659179467c828c) )
12801283
12811284   ROM_REGION( 0x100, "eeprom", 0 ) // eeprom 16 bit one!!!
trunk/src/mame/drivers/macs.c
r32631r32632
8989static ADDRESS_MAP_START( macs_mem, AS_PROGRAM, 8, macs_state )
9090   AM_RANGE(0x0000, 0x7fff) AM_ROMBANK("bank4")
9191   AM_RANGE(0x8000, 0xbfff) AM_ROMBANK("bank1")
92   AM_RANGE(0xc000, 0xcfff) AM_READ(st0016_sprite_ram_r) AM_WRITE(st0016_sprite_ram_w)
93   AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w)
92   //AM_RANGE(0xc000, 0xcfff) AM_READ(st0016_sprite_ram_r) AM_WRITE(st0016_sprite_ram_w)
93   //AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w)
9494   AM_RANGE(0xe000, 0xe7ff) AM_RAM /* work ram ? */
9595   AM_RANGE(0xe800, 0xe87f) AM_RAM AM_SHARE("ram2")
9696   //AM_RANGE(0xe900, 0xe9ff) // sound - internal
97   AM_RANGE(0xea00, 0xebff) AM_READ(st0016_palette_ram_r) AM_WRITE(st0016_palette_ram_w)
98   AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
97   //AM_RANGE(0xea00, 0xebff) AM_READ(st0016_palette_ram_r) AM_WRITE(st0016_palette_ram_w)
98   //AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
9999   AM_RANGE(0xf000, 0xf7ff) AM_RAMBANK("bank3") /* common /backup ram ?*/
100100   AM_RANGE(0xf800, 0xffff) AM_RAMBANK("bank2") /* common /backup ram ?*/
101101ADDRESS_MAP_END
r32631r32632
178178
179179static ADDRESS_MAP_START( macs_io, AS_IO, 8, macs_state )
180180   ADDRESS_MAP_GLOBAL_MASK(0xff)
181   AM_RANGE(0x00, 0xbf) AM_READ(st0016_vregs_r) AM_WRITE(st0016_vregs_w) /* video/crt regs ? */
181   //AM_RANGE(0x00, 0xbf) AM_READ(st0016_vregs_r) AM_WRITE(st0016_vregs_w) /* video/crt regs ? */
182182   AM_RANGE(0xc0, 0xc7) AM_READWRITE(macs_input_r,macs_output_w)
183183   AM_RANGE(0xe0, 0xe0) AM_WRITENOP /* renju = $40, neratte = 0 */
184184   AM_RANGE(0xe1, 0xe1) AM_WRITE(macs_rom_bank_w)
185   AM_RANGE(0xe2, 0xe2) AM_WRITE(st0016_sprite_bank_w)
186   AM_RANGE(0xe3, 0xe4) AM_WRITE(st0016_character_bank_w)
187   AM_RANGE(0xe5, 0xe5) AM_WRITE(st0016_palette_bank_w)
185   //AM_RANGE(0xe2, 0xe2) AM_WRITE(st0016_sprite_bank_w)
186   //AM_RANGE(0xe3, 0xe4) AM_WRITE(st0016_character_bank_w)
187   //AM_RANGE(0xe5, 0xe5) AM_WRITE(st0016_palette_bank_w)
188188   AM_RANGE(0xe6, 0xe6) AM_WRITE(rambank_w) /* banking ? ram bank ? shared rambank ? */
189189   AM_RANGE(0xe7, 0xe7) AM_WRITENOP /* watchdog */
190   AM_RANGE(0xf0, 0xf0) AM_READ(st0016_dma_r)
190   //AM_RANGE(0xf0, 0xf0) AM_READ(st0016_dma_r)
191191ADDRESS_MAP_END
192192
193193static GFXDECODE_START( macs )
r32631r32632
488488   MCFG_SCREEN_SIZE(128*8, 128*8)
489489   MCFG_SCREEN_VISIBLE_AREA(0*8, 128*8-1, 0*8, 128*8-1)
490490   MCFG_SCREEN_UPDATE_DRIVER(st0016_state, screen_update_st0016)
491   MCFG_SCREEN_PALETTE("palette")
491   MCFG_SCREEN_PALETTE("maincpu:palette")
492492
493   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macs)
494   MCFG_PALETTE_ADD("palette", 16*16*4+1)
495
496493   MCFG_VIDEO_START_OVERRIDE(st0016_state,st0016)
497494MACHINE_CONFIG_END
498495
r32631r32632
711708DRIVER_INIT_MEMBER(macs_state,macs)
712709{
713710   m_ram1=auto_alloc_array(machine(), UINT8, 0x20000);
714   st0016_game=10|0x80;
711   m_maincpu->st0016_game=10|0x80;
715712   m_rev = 1;
716713}
717714
718715DRIVER_INIT_MEMBER(macs_state,macs2)
719716{
720717   m_ram1=auto_alloc_array(machine(), UINT8, 0x20000);
721   st0016_game=10|0x80;
718   m_maincpu->st0016_game=10|0x80;
722719   m_rev = 2;
723720}
724721
725722DRIVER_INIT_MEMBER(macs_state,kisekaeh)
726723{
727724   m_ram1=auto_alloc_array(machine(), UINT8, 0x20000);
728   st0016_game=11|0x180;
725   m_maincpu->st0016_game=11|0x180;
729726   m_rev = 1;
730727}
731728
732729DRIVER_INIT_MEMBER(macs_state,kisekaem)
733730{
734731   m_ram1=auto_alloc_array(machine(), UINT8, 0x20000);
735   st0016_game=10|0x180;
732   m_maincpu->st0016_game=10|0x180;
736733   m_rev = 1;
737734}
738735
trunk/src/mame/drivers/speglsht.c
r32631r32632
116116      : st0016_state(mconfig, type, tag),
117117         m_shared(*this, "shared"),
118118         m_framebuffer(*this, "framebuffer"),
119         m_cop_ram(*this, "cop_ram") { }
119         m_cop_ram(*this, "cop_ram"),
120         m_palette(*this, "palette")
121         { }
120122
121123   required_shared_ptr<UINT8> m_shared;
122124   required_shared_ptr<UINT32> m_framebuffer;
r32631r32632
133135   DECLARE_MACHINE_RESET(speglsht);
134136   DECLARE_VIDEO_START(speglsht);
135137   UINT32 screen_update_speglsht(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
138   required_device<palette_device> m_palette;
139
136140};
137141
138142
139143static ADDRESS_MAP_START( st0016_mem, AS_PROGRAM, 8, speglsht_state )
140144   AM_RANGE(0x0000, 0x7fff) AM_ROM
141145   AM_RANGE(0x8000, 0xbfff) AM_ROMBANK("bank1")
142   AM_RANGE(0xc000, 0xcfff) AM_READ(st0016_sprite_ram_r) AM_WRITE(st0016_sprite_ram_w)
143   AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w)
146   //AM_RANGE(0xc000, 0xcfff) AM_READ(st0016_sprite_ram_r) AM_WRITE(st0016_sprite_ram_w)
147   //AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w)
144148   AM_RANGE(0xe000, 0xe7ff) AM_RAM
145149   AM_RANGE(0xe800, 0xe87f) AM_RAM
146150   //AM_RANGE(0xe900, 0xe9ff) // sound - internal
147   AM_RANGE(0xea00, 0xebff) AM_READ(st0016_palette_ram_r) AM_WRITE(st0016_palette_ram_w)
148   AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
151   //AM_RANGE(0xea00, 0xebff) AM_READ(st0016_palette_ram_r) AM_WRITE(st0016_palette_ram_w)
152   //AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
149153   AM_RANGE(0xf000, 0xffff) AM_RAM AM_SHARE("shared")
150154ADDRESS_MAP_END
151155
152156static ADDRESS_MAP_START( st0016_io, AS_IO, 8, speglsht_state )
153157   ADDRESS_MAP_GLOBAL_MASK(0xff)
154   AM_RANGE(0x00, 0xbf) AM_READ(st0016_vregs_r) AM_WRITE(st0016_vregs_w)
158   //AM_RANGE(0x00, 0xbf) AM_READ(st0016_vregs_r) AM_WRITE(st0016_vregs_w)
155159   AM_RANGE(0xe1, 0xe1) AM_WRITE(st0016_rom_bank_w)
156   AM_RANGE(0xe2, 0xe2) AM_WRITE(st0016_sprite_bank_w)
157   AM_RANGE(0xe3, 0xe4) AM_WRITE(st0016_character_bank_w)
158   AM_RANGE(0xe5, 0xe5) AM_WRITE(st0016_palette_bank_w)
160   //AM_RANGE(0xe2, 0xe2) AM_WRITE(st0016_sprite_bank_w)
161   //AM_RANGE(0xe3, 0xe4) AM_WRITE(st0016_character_bank_w)
162   //AM_RANGE(0xe5, 0xe5) AM_WRITE(st0016_palette_bank_w)
159163   AM_RANGE(0xe6, 0xe6) AM_WRITENOP
160164   AM_RANGE(0xe7, 0xe7) AM_WRITENOP
161   AM_RANGE(0xf0, 0xf0) AM_READ(st0016_dma_r)
165   //AM_RANGE(0xf0, 0xf0) AM_READ(st0016_dma_r)
162166ADDRESS_MAP_END
163167
164168READ32_MEMBER(speglsht_state::shared_r)
r32631r32632
354358
355359   //draw st0016 gfx to temporary bitmap (indexed 16)
356360   m_bitmap->fill(0);
357   st0016_draw_screen(screen, *m_bitmap, cliprect);
361   m_maincpu->st0016_draw_screen(screen, *m_bitmap, cliprect);
358362
359363   //copy temporary bitmap to rgb 32 bit bitmap
360364   for(y=cliprect.min_y; y<cliprect.max_y;y++)
r32631r32632
364368      {
365369         if(srcline[x])
366370         {
367            rgb_t color=m_palette->pen_color(srcline[x]);
371            rgb_t color=m_maincpu->m_palette->pen_color(srcline[x]);
368372            PLOT_PIXEL_RGB(x,y,color.r(),color.g(),color.b());
369373         }
370374      }
r32631r32632
425429
426430DRIVER_INIT_MEMBER(speglsht_state,speglsht)
427431{
428   st0016_game=3;
432   m_maincpu->st0016_game=3;
429433}
430434
431435
trunk/src/mame/machine/st0016.c
r32631r32632
44
55const device_type ST0016_CPU = &device_creator<st0016_cpu_device>;
66
7UINT8 *st0016_charram; // todo, get it in the device
8UINT8 macs_cart_slot;
79
10
811static ADDRESS_MAP_START(st0016_cpu_internal_map, AS_PROGRAM, 8, st0016_cpu_device)
12   AM_RANGE(0xc000, 0xcfff) AM_READ(st0016_sprite_ram_r) AM_WRITE(st0016_sprite_ram_w)
13   AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w)   
14   AM_RANGE(0xea00, 0xebff) AM_READ(st0016_palette_ram_r) AM_WRITE(st0016_palette_ram_w)
15   AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
916   AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE("stsnd", st0016_device, st0016_snd_r, st0016_snd_w) /* sound regs 8 x $20 bytes, see notes */
1017ADDRESS_MAP_END
1118
1219
1320static ADDRESS_MAP_START(st0016_cpu_internal_io_map, AS_IO, 8, st0016_cpu_device)
21   ADDRESS_MAP_GLOBAL_MASK(0xff)
22   AM_RANGE(0x00, 0xbf) AM_READ(st0016_vregs_r) AM_WRITE(st0016_vregs_w) /* video/crt regs ? */
23   AM_RANGE(0xe2, 0xe2) AM_WRITE(st0016_sprite_bank_w)
24   AM_RANGE(0xe3, 0xe4) AM_WRITE(st0016_character_bank_w)
25   AM_RANGE(0xe5, 0xe5) AM_WRITE(st0016_palette_bank_w)
26   AM_RANGE(0xf0, 0xf0) AM_READ(st0016_dma_r)
1427ADDRESS_MAP_END
1528
29// note: a lot of bits are left uninitialized by the games, the default values are uncertain
1630
1731st0016_cpu_device::st0016_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
1832   : z80_device(mconfig, ST0016_CPU, "ST0016", tag, owner, clock, "st0016_cpu", __FILE__),
19       m_io_space_config("io", ENDIANNESS_LITTLE, 8, 16, 0, ADDRESS_MAP_NAME(st0016_cpu_internal_io_map)),
20     m_space_config("regs", ENDIANNESS_LITTLE, 8, 16, 0, ADDRESS_MAP_NAME(st0016_cpu_internal_map))
33     st0016_game(-1),
34     st0016_spr_bank(0),
35     st0016_spr2_bank(0),
36     st0016_pal_bank(0),
37     st0016_char_bank(0),
38     spr_dx(0),
39     spr_dy(0),
40     st0016_ramgfx(0),
41   
42     m_io_space_config("io", ENDIANNESS_LITTLE, 8, 16, 0, ADDRESS_MAP_NAME(st0016_cpu_internal_io_map)),
43     m_space_config("regs", ENDIANNESS_LITTLE, 8, 16, 0, ADDRESS_MAP_NAME(st0016_cpu_internal_map)),
44
45
46     m_screen(*this, ":screen"),
47     m_gfxdecode(*this, "gfxdecode"),
48     m_palette(*this, "palette")
49
2150{
51   for (int i = 0; i < 0xc0; i++)
52      st0016_vregs[i] = 0;
2253}
2354
2455
2556
57
2658//-------------------------------------------------
2759//  device_start - device-specific startup
2860//-------------------------------------------------
r32631r32632
3062void st0016_cpu_device::device_start()
3163{
3264   z80_device::device_start();
65   startup();
3366}
3467
3568
r32631r32632
4073void st0016_cpu_device::device_reset()
4174{
4275   z80_device::device_reset();
76
77   switch(st0016_game&0x3f)
78   {
79      case 0: //renju kizoku
80         m_screen->set_visible_area(0, 40*8-1, 0, 30*8-1);
81         spr_dx=0;
82         spr_dy=0;
83      break;
84
85      case 1: //neratte chu!
86         m_screen->set_visible_area(8,41*8-1,0,30*8-1);
87         spr_dx=0;
88         spr_dy=8;
89      break;
90
91      case 4: //mayjinsen 1&2
92         m_screen->set_visible_area(0,32*8-1,0,28*8-1);
93      break;
94
95      case 10:
96         m_screen->set_visible_area(0,383,0,255);
97      break;
98
99      case 11:
100         m_screen->set_visible_area(0,383,0,383);
101      break;
102
103   }
43104}
44105
45106static const st0016_interface st0016_config =
r32631r32632
47108   &st0016_charram
48109};
49110
111static GFXDECODE_START( st0016 )
112GFXDECODE_END
113
50114/* CPU interface */
51115static MACHINE_CONFIG_FRAGMENT( st0016_cpu )
52116   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
53117
118   MCFG_GFXDECODE_ADD("gfxdecode", "palette", st0016)
119   MCFG_PALETTE_ADD("palette", 16*16*4+1)
120
54121   MCFG_ST0016_ADD("stsnd", 0)
55122   MCFG_SOUND_CONFIG(st0016_config)
56123   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
r32631r32632
64131}
65132
66133
134
135
136
137
138
139
140static const gfx_layout charlayout =
141{
142   8,8,
143   0x10000,
144   4,
145   { 0, 1, 2, 3 },
146   { 1*4, 0*4, 3*4, 2*4, 5*4, 4*4, 7*4, 6*4 },
147   { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
148   8*8*4
149};
150
151WRITE8_MEMBER(st0016_cpu_device::st0016_sprite_bank_w)
152{
153/*
154    76543210
155        xxxx - spriteram  bank1
156    xxxx     - spriteram  bank2
157*/
158   st0016_spr_bank=data&ST0016_SPR_BANK_MASK;
159   st0016_spr2_bank=(data>>4)&ST0016_SPR_BANK_MASK;
160}
161
162WRITE8_MEMBER(st0016_cpu_device::st0016_palette_bank_w)
163{
164/*
165    76543210
166          xx - palram  bank
167    xxxxxx   - unknown/unused
168*/
169   st0016_pal_bank=data&ST0016_PAL_BANK_MASK;
170}
171
172WRITE8_MEMBER(st0016_cpu_device::st0016_character_bank_w)
173{
174/*
175    fedcba9876543210
176    xxxxxxxxxxxxxxxx - character (bank )
177*/
178
179   if(offset&1)
180      st0016_char_bank=(st0016_char_bank&0xff)|(data<<8);
181   else
182      st0016_char_bank=(st0016_char_bank&0xff00)|data;
183
184   st0016_char_bank&=ST0016_CHAR_BANK_MASK;
185}
186
187
188READ8_MEMBER(st0016_cpu_device::st0016_sprite_ram_r)
189{
190   return st0016_spriteram[ST0016_SPR_BANK_SIZE*st0016_spr_bank+offset];
191}
192
193WRITE8_MEMBER(st0016_cpu_device::st0016_sprite_ram_w)
194{
195   st0016_spriteram[ST0016_SPR_BANK_SIZE*st0016_spr_bank+offset]=data;
196}
197
198READ8_MEMBER(st0016_cpu_device::st0016_sprite2_ram_r)
199{
200   return st0016_spriteram[ST0016_SPR_BANK_SIZE*st0016_spr2_bank+offset];
201}
202
203WRITE8_MEMBER(st0016_cpu_device::st0016_sprite2_ram_w)
204{
205   st0016_spriteram[ST0016_SPR_BANK_SIZE*st0016_spr2_bank+offset]=data;
206}
207
208READ8_MEMBER(st0016_cpu_device::st0016_palette_ram_r)
209{
210   return st0016_paletteram[ST0016_PAL_BANK_SIZE*st0016_pal_bank+offset];
211}
212
213WRITE8_MEMBER(st0016_cpu_device::st0016_palette_ram_w)
214{
215   int color=(ST0016_PAL_BANK_SIZE*st0016_pal_bank+offset)/2;
216   int val;
217   st0016_paletteram[ST0016_PAL_BANK_SIZE*st0016_pal_bank+offset]=data;
218   val=st0016_paletteram[color*2]+(st0016_paletteram[color*2+1]<<8);
219   if(!color)
220      m_palette->set_pen_color(UNUSED_PEN,pal5bit(val >> 0),pal5bit(val >> 5),pal5bit(val >> 10)); /* same as color 0 - bg ? */
221   m_palette->set_pen_color(color,pal5bit(val >> 0),pal5bit(val >> 5),pal5bit(val >> 10));
222}
223
224READ8_MEMBER(st0016_cpu_device::st0016_character_ram_r)
225{
226   return st0016_charram[ST0016_CHAR_BANK_SIZE*st0016_char_bank+offset];
227}
228
229WRITE8_MEMBER(st0016_cpu_device::st0016_character_ram_w)
230{
231   st0016_charram[ST0016_CHAR_BANK_SIZE*st0016_char_bank+offset]=data;
232   m_gfxdecode->gfx(st0016_ramgfx)->mark_dirty(st0016_char_bank);
233}
234
235READ8_MEMBER(st0016_cpu_device::st0016_vregs_r)
236{
237/*
238        $0, $1 = max scanline(including vblank)/timer? ($3e7)
239
240        $8-$40 = bg tilemaps  (8 bytes each) :
241                   0 - ? = usually 0/20/ba*
242                   1 - 0 = disabled , !zero = address of tilemap in spriteram /$1000  (for example: 3 -> tilemap at $3000 )
243                   2 - ? = usually ff/1f/af*
244                   3 - priority ? = 0 - under sprites , $ff - over sprites \
245                   4 - ? = $7f/$ff
246                   5 - ? = $29/$20 (29 when tilemap must be drawn over sprites . maybe this is real priority ?)
247                   6 - ? = 0
248                   7 - ? =$20/$10/$12*
249
250
251        $40-$60 = scroll registers , X.w, Y.w
252
253*/
254
255   switch (offset)
256   {
257      case 0:
258      case 1:
259         return machine().rand();
260   }
261
262   return st0016_vregs[offset];
263}
264
265READ8_MEMBER(st0016_cpu_device::st0016_dma_r)
266{
267   /* bits 0 and 1 = 0 -> DMA transfer complete */
268   if(ISMACS)
269      return 0;
270   else
271      return 0;
272}
273
274
275WRITE8_MEMBER(st0016_cpu_device::st0016_vregs_w)
276{
277   /*
278
279      I/O ports:
280
281       $a0 \
282       $a1 - source address >> 1
283       $a2 /
284
285       $a3 \
286       $a4 - destination address >> 1  (inside character ram)
287       $a5 /
288
289       $a6 \
290       &a7 - (length inbytes - 1 ) >> 1
291
292       $a8 - 76543210
293             ??faaaaa
294
295             a - most sign. bits of length
296             f - DMA start latch
297
298   */
299
300   st0016_vregs[offset]=data;
301   if(offset==0xa8 && (data&0x20))
302   {
303      UINT32 srcadr=(st0016_vregs[0xa0]|(st0016_vregs[0xa1]<<8)|(st0016_vregs[0xa2]<<16))<<1;
304      UINT32 dstadr=(st0016_vregs[0xa3]|(st0016_vregs[0xa4]<<8)|(st0016_vregs[0xa5]<<16))<<1;
305      UINT32 length=((st0016_vregs[0xa6]|(st0016_vregs[0xa7]<<8)|((st0016_vregs[0xa8]&0x1f)<<16))+1)<<1;
306     
307      // todo : dma callback so macs_cart_slot can be local to MACs driver?
308
309      UINT32 srclen = (memregion(":maincpu")->bytes());
310      UINT8 *mem = memregion(":maincpu")->base();
311
312      srcadr += macs_cart_slot*0x400000;
313
314      while(length>0)
315      {
316         if( srcadr < srclen && (dstadr < ST0016_MAX_CHAR_BANK*ST0016_CHAR_BANK_SIZE))
317         {
318            st0016_char_bank=dstadr>>5;
319            st0016_character_ram_w(space,dstadr&0x1f,mem[srcadr]);
320            srcadr++;
321            dstadr++;
322            length--;
323         }
324         else
325         {
326            /* samples ? sound dma ? */
327            // speaglsht:  unknown DMA copy : src - 2B6740, dst - 4400, len - 1E400
328            logerror("unknown DMA copy : src - %X, dst - %X, len - %X, PC - %X\n",srcadr,dstadr,length,space.device().safe_pcbase());
329            break;
330         }
331      }
332   }
333}
334
335void st0016_cpu_device::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
336{
337   /*
338   object ram :
339
340    each entry is 8 bytes:
341
342      76543210 (bit)
343    0 llllllll
344    1 ---1SSSl
345    2 oooooooo
346    3 fooooooo
347    4 xxxxxxxx
348    5 ------xx
349    6 yyyyyyyy
350    7 ------yy
351
352      1 - always(?) set
353      S - scroll index ? (ports $40-$60, X(word),Y(word) )
354      l - sublist length (8 byte entries -1)
355      o - sublist offset (*8 to get real offset)
356      f - end of list  flag
357      x,y - sprite coords
358
359    sublist format (8 bytes/entry):
360
361      76543210
362    0 cccccccc
363    1 cccccccc
364    2 --kkkkkk
365    3 QW------
366    4 xxxxxxxx
367    5 -B---XXx
368    6 yyyyyyyy
369    7 -----YYy
370
371     c - character code
372     k - palette
373     QW - flips
374     x,y - coords
375     XX,YY - size (1<<size)
376     B - merge pixel data with prevoius one (8bpp mode - neratte: seta logo and title screen)
377
378   */
379
380   gfx_element *gfx = m_gfxdecode->gfx(st0016_ramgfx);
381   int i,j,lx,ly,x,y,code,offset,length,sx,sy,color,flipx,flipy,scrollx,scrolly/*,plx,ply*/;
382
383
384   for(i=0;i<ST0016_SPR_BANK_SIZE*ST0016_MAX_SPR_BANK;i+=8)
385   {
386      x=st0016_spriteram[i+4]+((st0016_spriteram[i+5]&3)<<8);
387   y=st0016_spriteram[i+6]+((st0016_spriteram[i+7]&3)<<8);
388
389   scrollx=(st0016_vregs[(((st0016_spriteram[i+1]&0x0f)>>1)<<2)+0x40]+256*st0016_vregs[(((st0016_spriteram[i+1]&0x0f)>>1)<<2)+1+0x40])&0x3ff;
390   scrolly=(st0016_vregs[(((st0016_spriteram[i+1]&0x0f)>>1)<<2)+2+0x40]+256*st0016_vregs[(((st0016_spriteram[i+1]&0x0f)>>1)<<2)+3+0x40])&0x3ff;
391
392   if(!ISMACS)
393   {
394      if (x & 0x200) x-= 0x400; //sign
395      if (y & 0x200) y-= 0x400;
396
397      if (scrollx & 0x200) scrollx-= 0x400; //sign
398      if (scrolly & 0x200) scrolly-= 0x400;
399   }
400
401   if(ISMACS1)
402   {
403      if (x & 0x200) x-= 0x400; //sign
404      if (y & 0x200) y-= 0x2b0;//0x400;
405
406      if (scrollx & 0x200) scrollx-= 0x400; //sign
407      if (scrolly & 0x200) scrolly-= 0x400;
408   }
409
410   x+=scrollx;
411   y+=scrolly;
412
413   if(ISMACS)
414   {
415      y+=0x20;
416   }
417
418   if( st0016_spriteram[i+3]&0x80) /* end of list */
419      break;
420
421      offset=st0016_spriteram[i+2]+256*(st0016_spriteram[i+3]);
422      offset<<=3;
423
424      length=st0016_spriteram[i+0]+1+256*(st0016_spriteram[i+1]&1);
425
426      //plx=(st0016_spriteram[i+5]>>2)&0x3;
427      //ply=(st0016_spriteram[i+7]>>2)&0x3;
428
429      if(offset<ST0016_SPR_BANK_SIZE*ST0016_MAX_SPR_BANK)
430      {
431         for(j=0;j<length;j++)
432         {
433            code=st0016_spriteram[offset]+256*st0016_spriteram[offset+1];
434            sx=st0016_spriteram[offset+4]+((st0016_spriteram[offset+5]&1)<<8);
435            sy=st0016_spriteram[offset+6]+((st0016_spriteram[offset+7]&1)<<8);
436
437            if(ISMACS && !(ISMACS1))
438            {
439               if (sy & 0x100) sy-= 0x200; //yuka & yujan
440            }
441
442            if(ISMACS)
443            {
444               sy=0xe0-sy;
445            }
446
447            sx+=x;
448            sy+=y;
449            color=st0016_spriteram[offset+2]&0x3f;
450            lx=(st0016_spriteram[offset+5]>>2)&3;
451            ly=(st0016_spriteram[offset+7]>>2)&3;
452         /*
453             if(plx |ply) //parent
454             {
455                 lx=plx;
456                 ly=ply;
457             }
458             */
459
460            flipx=st0016_spriteram[offset+3]&0x80;
461            flipy=st0016_spriteram[offset+3]&0x40;
462
463            if(ISMACS)
464               sy-=(1<<ly)*8;
465
466            {
467               int x0,y0,i0=0;
468               for(x0=(flipx?((1<<lx)-1):0);x0!=(flipx?-1:(1<<lx));x0+=(flipx?-1:1))
469                  for(y0=(flipy?((1<<ly)-1):0);y0!=(flipy?-1:(1<<ly));y0+=(flipy?-1:1))
470                  {
471                     /* custom draw */
472                     UINT16 *destline;
473                     int yloop,xloop;
474                     int ypos, xpos;
475                     int tileno;
476                     const UINT8 *srcgfx;
477                     int gfxoffs;
478                     ypos = sy+y0*8+spr_dy;
479                     xpos = sx+x0*8+spr_dx;
480                     tileno = (code+i0++)&ST0016_CHAR_BANK_MASK ;
481
482                     gfxoffs = 0;
483                     srcgfx= gfx->get_data(tileno);
484
485                     for (yloop=0; yloop<8; yloop++)
486                     {
487                        UINT16 drawypos;
488
489                        if (!flipy) {drawypos = ypos+yloop;} else {drawypos = (ypos+8-1)-yloop;}
490                        destline = &bitmap.pix16(drawypos);
491
492                        for (xloop=0; xloop<8; xloop++)
493                        {
494                           UINT16 drawxpos;
495                           int pixdata;
496                           pixdata = srcgfx[gfxoffs];
497
498                           if (!flipx) { drawxpos = xpos+xloop; } else { drawxpos = (xpos+8-1)-xloop; }
499
500                           if (drawxpos > cliprect.max_x)
501                              drawxpos -= 512; // wrap around
502
503                           if (cliprect.contains(drawxpos, drawypos))
504                           {
505                              if(st0016_spriteram[offset+5]&0x40)
506                              {
507                                 destline[drawxpos] =(destline[drawxpos] | pixdata<<4)&0x3ff;
508                              }
509                              else
510                              {
511                                 if(ISMACS2)
512                                 {
513                                    if(pixdata )//|| destline[drawxpos]==UNUSED_PEN)
514                                    {
515                                       destline[drawxpos] = pixdata + (color*16);
516                                    }
517                                 }
518                                 else
519                                 {
520                                    if(pixdata || destline[drawxpos]==UNUSED_PEN)
521                                    {
522                                       destline[drawxpos] = pixdata + (color*16);
523                                    }
524                                 }
525                              }
526                           }
527
528                           gfxoffs++;
529                        }
530                     }
531                  }
532            }
533            offset+=8;
534            if(offset>=ST0016_SPR_BANK_SIZE*ST0016_MAX_SPR_BANK)
535               break;
536         }
537      }
538   }
539}
540
541
542void st0016_cpu_device::st0016_save_init()
543{
544   save_item(NAME(st0016_spr_bank));
545   save_item(NAME(st0016_spr2_bank));
546   save_item(NAME(st0016_pal_bank));
547   save_item(NAME(st0016_char_bank));
548   //save_item(NAME(st0016_rom_bank));
549   save_item(NAME(st0016_vregs));
550   save_pointer(NAME(st0016_charram), ST0016_MAX_CHAR_BANK*ST0016_CHAR_BANK_SIZE);
551   save_pointer(NAME(st0016_paletteram), ST0016_MAX_PAL_BANK*ST0016_PAL_BANK_SIZE);
552   save_pointer(NAME(st0016_spriteram), ST0016_MAX_SPR_BANK*ST0016_SPR_BANK_SIZE);
553}
554
555
556void st0016_cpu_device::startup()
557{
558   int gfx_index=0;
559
560   macs_cart_slot = 0;
561   st0016_charram=auto_alloc_array_clear(machine(), UINT8, ST0016_MAX_CHAR_BANK*ST0016_CHAR_BANK_SIZE);
562   st0016_spriteram=auto_alloc_array_clear(machine(), UINT8, ST0016_MAX_SPR_BANK*ST0016_SPR_BANK_SIZE);
563   st0016_paletteram=auto_alloc_array_clear(machine(), UINT8, ST0016_MAX_PAL_BANK*ST0016_PAL_BANK_SIZE);
564
565   /* find first empty slot to decode gfx */
566   for (gfx_index = 0; gfx_index < MAX_GFX_ELEMENTS; gfx_index++)
567      if (m_gfxdecode->gfx(gfx_index) == 0)
568         break;
569
570   assert(gfx_index != MAX_GFX_ELEMENTS);
571
572   /* create the char set (gfx will then be updated dynamically from RAM) */
573   m_gfxdecode->set_gfx(gfx_index, global_alloc(gfx_element(m_palette, charlayout, (UINT8 *) st0016_charram, 0, 0x40, 0)));
574   st0016_ramgfx = gfx_index;
575
576   spr_dx=0;
577   spr_dy=0;
578
579
580
581   st0016_save_init();
582}
583
584
585void st0016_cpu_device::draw_bgmap(bitmap_ind16 &bitmap,const rectangle &cliprect, int priority)
586{
587   gfx_element *gfx = m_gfxdecode->gfx(st0016_ramgfx);
588   int j;
589   //for(j=0x40-8;j>=0;j-=8)
590   for(j=0;j<0x40;j+=8)
591   {
592      if(st0016_vregs[j+1] && ((priority && (st0016_vregs[j+3]==0xff))||((!priority)&&(st0016_vregs[j+3]!=0xff))))
593      {
594         int x,y,code,color,flipx,flipy;
595         int i=st0016_vregs[j+1]*0x1000;
596         for(x=0;x<32*2;x++)
597            for(y=0;y<8*4;y++)
598            {
599               code=st0016_spriteram[i]+256*st0016_spriteram[i+1];
600               color=st0016_spriteram[i+2]&0x3f;
601
602               flipx=st0016_spriteram[i+3]&0x80;
603               flipy=st0016_spriteram[i+3]&0x40;
604
605               if(priority)
606               {
607                  gfx->transpen(bitmap,cliprect,
608                              code,
609                              color,
610                              flipx,flipy,
611                              x*8+spr_dx,y*8+spr_dy,0);
612               }
613               else
614               {
615                     UINT16 *destline;
616                     int yloop,xloop;
617                     int ypos, xpos;
618                     const UINT8 *srcgfx;
619                     int gfxoffs;
620                     ypos = y*8+spr_dy;//+((st0016_vregs[j+2]==0xaf)?0x50:0);//hack for mayjinsen title screen
621                     xpos = x*8+spr_dx;
622                     gfxoffs = 0;
623                     srcgfx= gfx->get_data(code);
624
625                     for (yloop=0; yloop<8; yloop++)
626                     {
627                        UINT16 drawypos;
628
629                        if (!flipy) {drawypos = ypos+yloop;} else {drawypos = (ypos+8-1)-yloop;}
630                        destline = &bitmap.pix16(drawypos);
631
632                        for (xloop=0; xloop<8; xloop++)
633                        {
634                           UINT16 drawxpos;
635                           int pixdata;
636                           pixdata = srcgfx[gfxoffs];
637
638                           if (!flipx) { drawxpos = xpos+xloop; } else { drawxpos = (xpos+8-1)-xloop; }
639
640                           if (drawxpos > cliprect.max_x)
641                              drawxpos -= 512; // wrap around
642
643                           if (cliprect.contains(drawxpos, drawypos))
644                           {
645                              if(st0016_vregs[j+7]==0x12)
646                                 destline[drawxpos] = (destline[drawxpos] | (pixdata<<4))&0x3ff;
647                              else
648                              {
649                                 if(ISMACS2)
650                                 {
651                                    if(pixdata)// || destline[drawxpos]==UNUSED_PEN)
652                                    {
653                                       destline[drawxpos] = pixdata + (color*16);
654                                    }
655                                 }
656                                 else
657                                 {
658                                    if(pixdata || destline[drawxpos]==UNUSED_PEN)
659                                    {
660                                       destline[drawxpos] = pixdata + (color*16);
661                                    }
662                                 }
663
664                              }
665                           }
666
667                           gfxoffs++;
668
669                        }
670                     }
671               }
672               i+=4;
673            }
674      }
675   }
676}
677
678
679void st0016_cpu_device::st0016_draw_screen(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
680{
681   draw_bgmap(bitmap,cliprect,0);
682   draw_sprites(bitmap,cliprect);
683   draw_bgmap(bitmap,cliprect,1);
684}
685
686UINT32 st0016_cpu_device::update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
687{
688#ifdef MAME_DEBUG
689   if(machine().input().code_pressed_once(KEYCODE_Z))
690   {
691      int h,j;
692      FILE *p=fopen("vram.bin","wb");
693      fwrite(st0016_spriteram,1,0x1000*ST0016_MAX_SPR_BANK,p);
694      fclose(p);
695
696      p=fopen("vram.txt","wt");
697      for(h=0;h<0xc0;h++)
698         fprintf(p,"VREG %.4x - %.4x\n",h,st0016_vregs[h]);
699      for(h=0;h<0x1000*ST0016_MAX_SPR_BANK;h+=8)
700      {
701         fprintf(p,"%.4x - %.4x - ",h,h>>3);
702         for(j=0;j<8;j++)
703            fprintf(p,"%.2x ",st0016_spriteram[h+j]);
704            fprintf(p,"\n");
705      }
706      fclose(p);
707   }
708#endif
709
710   bitmap.fill(UNUSED_PEN, cliprect);
711   st0016_draw_screen(screen, bitmap, cliprect);
712   return 0;
713}
714
trunk/src/mame/machine/st0016.h
r32631r32632
99#include "cpu/z80/z80.h"
1010#include "sound/st0016.h"
1111
12extern UINT8 *st0016_charram;
12extern UINT8 macs_cart_slot;
1313
14#define ISMACS  (st0016_game&0x80)
15#define ISMACS1 (((st0016_game&0x180)==0x180))
16#define ISMACS2 (((st0016_game&0x180)==0x080))
1417
18
19#define ST0016_MAX_SPR_BANK   0x10
20#define ST0016_MAX_CHAR_BANK  0x10000
21#define ST0016_MAX_PAL_BANK   4
22
23#define ST0016_SPR_BANK_SIZE  0x1000
24#define ST0016_CHAR_BANK_SIZE 0x20
25#define ST0016_PAL_BANK_SIZE  0x200
26
27#define UNUSED_PEN 1024
28
29#define ST0016_SPR_BANK_MASK  (ST0016_MAX_SPR_BANK-1)
30#define ST0016_CHAR_BANK_MASK (ST0016_MAX_CHAR_BANK-1)
31#define ST0016_PAL_BANK_MASK  (ST0016_MAX_PAL_BANK-1)
32
33
34
1535class st0016_cpu_device : public z80_device
1636{
1737public:
1838   st0016_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32);
1939
40   DECLARE_WRITE8_MEMBER(st0016_sprite_bank_w);
41   DECLARE_WRITE8_MEMBER(st0016_palette_bank_w);
42   DECLARE_WRITE8_MEMBER(st0016_character_bank_w);
43   DECLARE_READ8_MEMBER(st0016_sprite_ram_r);
44   DECLARE_WRITE8_MEMBER(st0016_sprite_ram_w);
45   DECLARE_READ8_MEMBER(st0016_sprite2_ram_r);
46   DECLARE_WRITE8_MEMBER(st0016_sprite2_ram_w);
47   DECLARE_READ8_MEMBER(st0016_palette_ram_r);
48   DECLARE_WRITE8_MEMBER(st0016_palette_ram_w);
49   DECLARE_READ8_MEMBER(st0016_character_ram_r);
50   DECLARE_WRITE8_MEMBER(st0016_character_ram_w);
51   DECLARE_READ8_MEMBER(st0016_vregs_r);
52   DECLARE_READ8_MEMBER(st0016_dma_r);
53   DECLARE_WRITE8_MEMBER(st0016_vregs_w);
54   
55   void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect);
56   void st0016_save_init();
57   void draw_bgmap(bitmap_ind16 &bitmap,const rectangle &cliprect, int priority);
58
59   void startup();
60   UINT32 update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
61   void st0016_draw_screen(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
62
63   UINT8 *st0016_spriteram,*st0016_paletteram;
64
65   UINT32 st0016_game;
66
67
68   INT32 st0016_spr_bank,st0016_spr2_bank,st0016_pal_bank,st0016_char_bank;
69   int spr_dx,spr_dy;
70
71   UINT8 st0016_vregs[0xc0];
72   int st0016_ramgfx;
73
74
2075protected:
2176   // device-level overrides
2277   virtual machine_config_constructor device_mconfig_additions() const;
r32631r32632
3590         case AS_PROGRAM: return &m_space_config;
3691         default: return z80_device::memory_space_config(spacenum);
3792      }
38   }
93   };
94   required_device<screen_device> m_screen;
95   required_device<gfxdecode_device> m_gfxdecode;
3996
97public: // speglsht needs to access this for mixing
98   required_device<palette_device> m_palette;
4099
41100private:
42101
trunk/src/mame/includes/st0016.h
r32631r32632
11
2#include "machine/st0016.h"
3
24class st0016_state : public driver_device
35{
46public:
r32631r32632
68      : driver_device(mconfig, type, tag),
79      m_maincpu(*this,"maincpu"),
810      m_subcpu(*this, "sub"),
9      m_gfxdecode(*this, "gfxdecode"),
10      m_screen(*this, "screen"),
11      m_palette(*this, "palette") { }
11      m_screen(*this, "screen")
12   { }
1213
1314   int mux_port;
1415   UINT32 m_st0016_rom_bank;
1516
16   required_device<cpu_device> m_maincpu;
17   optional_device<st0016_cpu_device> m_maincpu;
1718   DECLARE_READ8_MEMBER(mux_r);
1819   DECLARE_WRITE8_MEMBER(mux_select_w);
1920   DECLARE_READ32_MEMBER(latch32_r);
2021   DECLARE_WRITE32_MEMBER(latch32_w);
2122   DECLARE_READ8_MEMBER(latch8_r);
2223   DECLARE_WRITE8_MEMBER(latch8_w);
23   DECLARE_WRITE8_MEMBER(st0016_sprite_bank_w);
24   DECLARE_WRITE8_MEMBER(st0016_palette_bank_w);
25   DECLARE_WRITE8_MEMBER(st0016_character_bank_w);
26   DECLARE_READ8_MEMBER(st0016_sprite_ram_r);
27   DECLARE_WRITE8_MEMBER(st0016_sprite_ram_w);
28   DECLARE_READ8_MEMBER(st0016_sprite2_ram_r);
29   DECLARE_WRITE8_MEMBER(st0016_sprite2_ram_w);
30   DECLARE_READ8_MEMBER(st0016_palette_ram_r);
31   DECLARE_WRITE8_MEMBER(st0016_palette_ram_w);
32   DECLARE_READ8_MEMBER(st0016_character_ram_r);
33   DECLARE_WRITE8_MEMBER(st0016_character_ram_w);
34   DECLARE_READ8_MEMBER(st0016_vregs_r);
35   DECLARE_READ8_MEMBER(st0016_dma_r);
36   DECLARE_WRITE8_MEMBER(st0016_vregs_w);
24
3725   DECLARE_WRITE8_MEMBER(st0016_rom_bank_w);
3826   DECLARE_DRIVER_INIT(nratechu);
3927   DECLARE_DRIVER_INIT(mayjinsn);
r32631r32632
4331   void st0016_draw_screen(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
4432   UINT32 screen_update_st0016(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
4533   TIMER_DEVICE_CALLBACK_MEMBER(st0016_int);
46   void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect);
47   void st0016_save_init();
48   void draw_bgmap(bitmap_ind16 &bitmap,const rectangle &cliprect, int priority);
4934   optional_device<cpu_device> m_subcpu;
50   required_device<gfxdecode_device> m_gfxdecode;
5135   required_device<screen_device> m_screen;
52   required_device<palette_device> m_palette;
5336};
5437
55#define ISMACS  (st0016_game&0x80)
56#define ISMACS1 (((st0016_game&0x180)==0x180))
57#define ISMACS2 (((st0016_game&0x180)==0x080))
5838
59
60#define ST0016_MAX_SPR_BANK   0x10
61#define ST0016_MAX_CHAR_BANK  0x10000
62#define ST0016_MAX_PAL_BANK   4
63
64#define ST0016_SPR_BANK_SIZE  0x1000
65#define ST0016_CHAR_BANK_SIZE 0x20
66#define ST0016_PAL_BANK_SIZE  0x200
67
68#define UNUSED_PEN 1024
69
70#define ST0016_SPR_BANK_MASK  (ST0016_MAX_SPR_BANK-1)
71#define ST0016_CHAR_BANK_MASK (ST0016_MAX_CHAR_BANK-1)
72#define ST0016_PAL_BANK_MASK  (ST0016_MAX_PAL_BANK-1)
73
7439/*----------- defined in video/st0016.c -----------*/
7540
7641extern UINT8 macs_cart_slot;
77extern UINT32 st0016_game;
78extern UINT8 *st0016_charram;
trunk/src/mame/video/st0016.c
r32631r32632
66#include "emu.h"
77#include "includes/st0016.h"
88
9UINT8 *st0016_charram;
10static UINT8 *st0016_spriteram,*st0016_paletteram;
11
12UINT32 st0016_game;
13
14UINT8 macs_cart_slot;
15
16static INT32 st0016_spr_bank,st0016_spr2_bank,st0016_pal_bank,st0016_char_bank;
17static int spr_dx,spr_dy;
18
19static UINT8 st0016_vregs[0xc0];
20static int st0016_ramgfx;
21
22static const gfx_layout charlayout =
9UINT32 st0016_state::screen_update_st0016(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
2310{
24   8,8,
25   0x10000,
26   4,
27   { 0, 1, 2, 3 },
28   { 1*4, 0*4, 3*4, 2*4, 5*4, 4*4, 7*4, 6*4 },
29   { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
30   8*8*4
31};
32
33WRITE8_MEMBER(st0016_state::st0016_sprite_bank_w)
34{
35/*
36    76543210
37        xxxx - spriteram  bank1
38    xxxx     - spriteram  bank2
39*/
40   st0016_spr_bank=data&ST0016_SPR_BANK_MASK;
41   st0016_spr2_bank=(data>>4)&ST0016_SPR_BANK_MASK;
11   return m_maincpu->update(screen,bitmap,cliprect);
4212}
4313
44WRITE8_MEMBER(st0016_state::st0016_palette_bank_w)
14VIDEO_START_MEMBER(st0016_state, st0016)
4515{
46/*
47    76543210
48          xx - palram  bank
49    xxxxxx   - unknown/unused
50*/
51   st0016_pal_bank=data&ST0016_PAL_BANK_MASK;
5216}
5317
54WRITE8_MEMBER(st0016_state::st0016_character_bank_w)
55{
56/*
57    fedcba9876543210
58    xxxxxxxxxxxxxxxx - character (bank )
59*/
60
61   if(offset&1)
62      st0016_char_bank=(st0016_char_bank&0xff)|(data<<8);
63   else
64      st0016_char_bank=(st0016_char_bank&0xff00)|data;
65
66   st0016_char_bank&=ST0016_CHAR_BANK_MASK;
67}
68
69
70READ8_MEMBER(st0016_state::st0016_sprite_ram_r)
71{
72   return st0016_spriteram[ST0016_SPR_BANK_SIZE*st0016_spr_bank+offset];
73}
74
75WRITE8_MEMBER(st0016_state::st0016_sprite_ram_w)
76{
77   st0016_spriteram[ST0016_SPR_BANK_SIZE*st0016_spr_bank+offset]=data;
78}
79
80READ8_MEMBER(st0016_state::st0016_sprite2_ram_r)
81{
82   return st0016_spriteram[ST0016_SPR_BANK_SIZE*st0016_spr2_bank+offset];
83}
84
85WRITE8_MEMBER(st0016_state::st0016_sprite2_ram_w)
86{
87   st0016_spriteram[ST0016_SPR_BANK_SIZE*st0016_spr2_bank+offset]=data;
88}
89
90READ8_MEMBER(st0016_state::st0016_palette_ram_r)
91{
92   return st0016_paletteram[ST0016_PAL_BANK_SIZE*st0016_pal_bank+offset];
93}
94
95WRITE8_MEMBER(st0016_state::st0016_palette_ram_w)
96{
97   int color=(ST0016_PAL_BANK_SIZE*st0016_pal_bank+offset)/2;
98   int val;
99   st0016_paletteram[ST0016_PAL_BANK_SIZE*st0016_pal_bank+offset]=data;
100   val=st0016_paletteram[color*2]+(st0016_paletteram[color*2+1]<<8);
101   if(!color)
102      m_palette->set_pen_color(UNUSED_PEN,pal5bit(val >> 0),pal5bit(val >> 5),pal5bit(val >> 10)); /* same as color 0 - bg ? */
103   m_palette->set_pen_color(color,pal5bit(val >> 0),pal5bit(val >> 5),pal5bit(val >> 10));
104}
105
106READ8_MEMBER(st0016_state::st0016_character_ram_r)
107{
108   return st0016_charram[ST0016_CHAR_BANK_SIZE*st0016_char_bank+offset];
109}
110
111WRITE8_MEMBER(st0016_state::st0016_character_ram_w)
112{
113   st0016_charram[ST0016_CHAR_BANK_SIZE*st0016_char_bank+offset]=data;
114   m_gfxdecode->gfx(st0016_ramgfx)->mark_dirty(st0016_char_bank);
115}
116
117READ8_MEMBER(st0016_state::st0016_vregs_r)
118{
119/*
120        $0, $1 = max scanline(including vblank)/timer? ($3e7)
121
122        $8-$40 = bg tilemaps  (8 bytes each) :
123                   0 - ? = usually 0/20/ba*
124                   1 - 0 = disabled , !zero = address of tilemap in spriteram /$1000  (for example: 3 -> tilemap at $3000 )
125                   2 - ? = usually ff/1f/af*
126                   3 - priority ? = 0 - under sprites , $ff - over sprites \
127                   4 - ? = $7f/$ff
128                   5 - ? = $29/$20 (29 when tilemap must be drawn over sprites . maybe this is real priority ?)
129                   6 - ? = 0
130                   7 - ? =$20/$10/$12*
131
132
133        $40-$60 = scroll registers , X.w, Y.w
134
135*/
136
137   switch (offset)
138   {
139      case 0:
140      case 1:
141         return machine().rand();
142   }
143
144   return st0016_vregs[offset];
145}
146
147READ8_MEMBER(st0016_state::st0016_dma_r)
148{
149   /* bits 0 and 1 = 0 -> DMA transfer complete */
150   if(ISMACS)
151      return 0;
152   else
153      return 0;
154}
155
156
157WRITE8_MEMBER(st0016_state::st0016_vregs_w)
158{
159   /*
160
161      I/O ports:
162
163       $a0 \
164       $a1 - source address >> 1
165       $a2 /
166
167       $a3 \
168       $a4 - destination address >> 1  (inside character ram)
169       $a5 /
170
171       $a6 \
172       &a7 - (length inbytes - 1 ) >> 1
173
174       $a8 - 76543210
175             ??faaaaa
176
177             a - most sign. bits of length
178             f - DMA start latch
179
180   */
181
182   st0016_vregs[offset]=data;
183   if(offset==0xa8 && (data&0x20))
184   {
185      UINT32 srcadr=(st0016_vregs[0xa0]|(st0016_vregs[0xa1]<<8)|(st0016_vregs[0xa2]<<16))<<1;
186      UINT32 dstadr=(st0016_vregs[0xa3]|(st0016_vregs[0xa4]<<8)|(st0016_vregs[0xa5]<<16))<<1;
187      UINT32 length=((st0016_vregs[0xa6]|(st0016_vregs[0xa7]<<8)|((st0016_vregs[0xa8]&0x1f)<<16))+1)<<1;
188      UINT32 srclen = (memregion("maincpu")->bytes());
189      UINT8 *mem = memregion("maincpu")->base();
190
191      srcadr += macs_cart_slot*0x400000;
192
193      while(length>0)
194      {
195         if( srcadr < srclen && (dstadr < ST0016_MAX_CHAR_BANK*ST0016_CHAR_BANK_SIZE))
196         {
197            st0016_char_bank=dstadr>>5;
198            st0016_character_ram_w(space,dstadr&0x1f,mem[srcadr]);
199            srcadr++;
200            dstadr++;
201            length--;
202         }
203         else
204         {
205            /* samples ? sound dma ? */
206            // speaglsht:  unknown DMA copy : src - 2B6740, dst - 4400, len - 1E400
207            logerror("unknown DMA copy : src - %X, dst - %X, len - %X, PC - %X\n",srcadr,dstadr,length,space.device().safe_pcbase());
208            break;
209         }
210      }
211   }
212}
213
214void st0016_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
215{
216   /*
217   object ram :
218
219    each entry is 8 bytes:
220
221      76543210 (bit)
222    0 llllllll
223    1 ---1SSSl
224    2 oooooooo
225    3 fooooooo
226    4 xxxxxxxx
227    5 ------xx
228    6 yyyyyyyy
229    7 ------yy
230
231      1 - always(?) set
232      S - scroll index ? (ports $40-$60, X(word),Y(word) )
233      l - sublist length (8 byte entries -1)
234      o - sublist offset (*8 to get real offset)
235      f - end of list  flag
236      x,y - sprite coords
237
238    sublist format (8 bytes/entry):
239
240      76543210
241    0 cccccccc
242    1 cccccccc
243    2 --kkkkkk
244    3 QW------
245    4 xxxxxxxx
246    5 -B---XXx
247    6 yyyyyyyy
248    7 -----YYy
249
250     c - character code
251     k - palette
252     QW - flips
253     x,y - coords
254     XX,YY - size (1<<size)
255     B - merge pixel data with prevoius one (8bpp mode - neratte: seta logo and title screen)
256
257   */
258
259   gfx_element *gfx = m_gfxdecode->gfx(st0016_ramgfx);
260   int i,j,lx,ly,x,y,code,offset,length,sx,sy,color,flipx,flipy,scrollx,scrolly/*,plx,ply*/;
261
262
263   for(i=0;i<ST0016_SPR_BANK_SIZE*ST0016_MAX_SPR_BANK;i+=8)
264   {
265      x=st0016_spriteram[i+4]+((st0016_spriteram[i+5]&3)<<8);
266   y=st0016_spriteram[i+6]+((st0016_spriteram[i+7]&3)<<8);
267
268   scrollx=(st0016_vregs[(((st0016_spriteram[i+1]&0x0f)>>1)<<2)+0x40]+256*st0016_vregs[(((st0016_spriteram[i+1]&0x0f)>>1)<<2)+1+0x40])&0x3ff;
269   scrolly=(st0016_vregs[(((st0016_spriteram[i+1]&0x0f)>>1)<<2)+2+0x40]+256*st0016_vregs[(((st0016_spriteram[i+1]&0x0f)>>1)<<2)+3+0x40])&0x3ff;
270
271   if(!ISMACS)
272   {
273      if (x & 0x200) x-= 0x400; //sign
274      if (y & 0x200) y-= 0x400;
275
276      if (scrollx & 0x200) scrollx-= 0x400; //sign
277      if (scrolly & 0x200) scrolly-= 0x400;
278   }
279
280   if(ISMACS1)
281   {
282      if (x & 0x200) x-= 0x400; //sign
283      if (y & 0x200) y-= 0x2b0;//0x400;
284
285      if (scrollx & 0x200) scrollx-= 0x400; //sign
286      if (scrolly & 0x200) scrolly-= 0x400;
287   }
288
289   x+=scrollx;
290   y+=scrolly;
291
292   if(ISMACS)
293   {
294      y+=0x20;
295   }
296
297   if( st0016_spriteram[i+3]&0x80) /* end of list */
298      break;
299
300      offset=st0016_spriteram[i+2]+256*(st0016_spriteram[i+3]);
301      offset<<=3;
302
303      length=st0016_spriteram[i+0]+1+256*(st0016_spriteram[i+1]&1);
304
305      //plx=(st0016_spriteram[i+5]>>2)&0x3;
306      //ply=(st0016_spriteram[i+7]>>2)&0x3;
307
308      if(offset<ST0016_SPR_BANK_SIZE*ST0016_MAX_SPR_BANK)
309      {
310         for(j=0;j<length;j++)
311         {
312            code=st0016_spriteram[offset]+256*st0016_spriteram[offset+1];
313            sx=st0016_spriteram[offset+4]+((st0016_spriteram[offset+5]&1)<<8);
314            sy=st0016_spriteram[offset+6]+((st0016_spriteram[offset+7]&1)<<8);
315
316            if(ISMACS && !(ISMACS1))
317            {
318               if (sy & 0x100) sy-= 0x200; //yuka & yujan
319            }
320
321            if(ISMACS)
322            {
323               sy=0xe0-sy;
324            }
325
326            sx+=x;
327            sy+=y;
328            color=st0016_spriteram[offset+2]&0x3f;
329            lx=(st0016_spriteram[offset+5]>>2)&3;
330            ly=(st0016_spriteram[offset+7]>>2)&3;
331         /*
332             if(plx |ply) //parent
333             {
334                 lx=plx;
335                 ly=ply;
336             }
337             */
338
339            flipx=st0016_spriteram[offset+3]&0x80;
340            flipy=st0016_spriteram[offset+3]&0x40;
341
342            if(ISMACS)
343               sy-=(1<<ly)*8;
344
345            {
346               int x0,y0,i0=0;
347               for(x0=(flipx?((1<<lx)-1):0);x0!=(flipx?-1:(1<<lx));x0+=(flipx?-1:1))
348                  for(y0=(flipy?((1<<ly)-1):0);y0!=(flipy?-1:(1<<ly));y0+=(flipy?-1:1))
349                  {
350                     /* custom draw */
351                     UINT16 *destline;
352                     int yloop,xloop;
353                     int ypos, xpos;
354                     int tileno;
355                     const UINT8 *srcgfx;
356                     int gfxoffs;
357                     ypos = sy+y0*8+spr_dy;
358                     xpos = sx+x0*8+spr_dx;
359                     tileno = (code+i0++)&ST0016_CHAR_BANK_MASK ;
360
361                     gfxoffs = 0;
362                     srcgfx= gfx->get_data(tileno);
363
364                     for (yloop=0; yloop<8; yloop++)
365                     {
366                        UINT16 drawypos;
367
368                        if (!flipy) {drawypos = ypos+yloop;} else {drawypos = (ypos+8-1)-yloop;}
369                        destline = &bitmap.pix16(drawypos);
370
371                        for (xloop=0; xloop<8; xloop++)
372                        {
373                           UINT16 drawxpos;
374                           int pixdata;
375                           pixdata = srcgfx[gfxoffs];
376
377                           if (!flipx) { drawxpos = xpos+xloop; } else { drawxpos = (xpos+8-1)-xloop; }
378
379                           if (drawxpos > cliprect.max_x)
380                              drawxpos -= 512; // wrap around
381
382                           if (cliprect.contains(drawxpos, drawypos))
383                           {
384                              if(st0016_spriteram[offset+5]&0x40)
385                              {
386                                 destline[drawxpos] =(destline[drawxpos] | pixdata<<4)&0x3ff;
387                              }
388                              else
389                              {
390                                 if(ISMACS2)
391                                 {
392                                    if(pixdata )//|| destline[drawxpos]==UNUSED_PEN)
393                                    {
394                                       destline[drawxpos] = pixdata + (color*16);
395                                    }
396                                 }
397                                 else
398                                 {
399                                    if(pixdata || destline[drawxpos]==UNUSED_PEN)
400                                    {
401                                       destline[drawxpos] = pixdata + (color*16);
402                                    }
403                                 }
404                              }
405                           }
406
407                           gfxoffs++;
408                        }
409                     }
410                  }
411            }
412            offset+=8;
413            if(offset>=ST0016_SPR_BANK_SIZE*ST0016_MAX_SPR_BANK)
414               break;
415         }
416      }
417   }
418}
419
420
421void st0016_state::st0016_save_init()
422{
423   save_item(NAME(st0016_spr_bank));
424   save_item(NAME(st0016_spr2_bank));
425   save_item(NAME(st0016_pal_bank));
426   save_item(NAME(st0016_char_bank));
427   //save_item(NAME(st0016_rom_bank));
428   save_item(NAME(st0016_vregs));
429   save_pointer(NAME(st0016_charram), ST0016_MAX_CHAR_BANK*ST0016_CHAR_BANK_SIZE);
430   save_pointer(NAME(st0016_paletteram), ST0016_MAX_PAL_BANK*ST0016_PAL_BANK_SIZE);
431   save_pointer(NAME(st0016_spriteram), ST0016_MAX_SPR_BANK*ST0016_SPR_BANK_SIZE);
432}
433
434
435VIDEO_START_MEMBER(st0016_state,st0016)
436{
437   int gfx_index=0;
438
439   macs_cart_slot = 0;
440   st0016_charram=auto_alloc_array(machine(), UINT8, ST0016_MAX_CHAR_BANK*ST0016_CHAR_BANK_SIZE);
441   st0016_spriteram=auto_alloc_array(machine(), UINT8, ST0016_MAX_SPR_BANK*ST0016_SPR_BANK_SIZE);
442   st0016_paletteram=auto_alloc_array(machine(), UINT8, ST0016_MAX_PAL_BANK*ST0016_PAL_BANK_SIZE);
443
444   /* find first empty slot to decode gfx */
445   for (gfx_index = 0; gfx_index < MAX_GFX_ELEMENTS; gfx_index++)
446      if (m_gfxdecode->gfx(gfx_index) == 0)
447         break;
448
449   assert(gfx_index != MAX_GFX_ELEMENTS);
450
451   /* create the char set (gfx will then be updated dynamically from RAM) */
452   m_gfxdecode->set_gfx(gfx_index, global_alloc(gfx_element(m_palette, charlayout, (UINT8 *) st0016_charram, 0, 0x40, 0)));
453   st0016_ramgfx = gfx_index;
454
455   spr_dx=0;
456   spr_dy=0;
457
458   switch(st0016_game&0x3f)
459   {
460      case 0: //renju kizoku
461         m_screen->set_visible_area(0, 40*8-1, 0, 30*8-1);
462         spr_dx=0;
463         spr_dy=0;
464      break;
465
466      case 1: //neratte chu!
467         m_screen->set_visible_area(8,41*8-1,0,30*8-1);
468         spr_dx=0;
469         spr_dy=8;
470      break;
471
472      case 4: //mayjinsen 1&2
473         m_screen->set_visible_area(0,32*8-1,0,28*8-1);
474      break;
475
476      case 10:
477         m_screen->set_visible_area(0,383,0,255);
478      break;
479
480      case 11:
481         m_screen->set_visible_area(0,383,0,383);
482      break;
483
484   }
485
486   st0016_save_init();
487}
488
489
490void st0016_state::draw_bgmap(bitmap_ind16 &bitmap,const rectangle &cliprect, int priority)
491{
492   gfx_element *gfx = m_gfxdecode->gfx(st0016_ramgfx);
493   int j;
494   //for(j=0x40-8;j>=0;j-=8)
495   for(j=0;j<0x40;j+=8)
496   {
497      if(st0016_vregs[j+1] && ((priority && (st0016_vregs[j+3]==0xff))||((!priority)&&(st0016_vregs[j+3]!=0xff))))
498      {
499         int x,y,code,color,flipx,flipy;
500         int i=st0016_vregs[j+1]*0x1000;
501         for(x=0;x<32*2;x++)
502            for(y=0;y<8*4;y++)
503            {
504               code=st0016_spriteram[i]+256*st0016_spriteram[i+1];
505               color=st0016_spriteram[i+2]&0x3f;
506
507               flipx=st0016_spriteram[i+3]&0x80;
508               flipy=st0016_spriteram[i+3]&0x40;
509
510               if(priority)
511               {
512                  gfx->transpen(bitmap,cliprect,
513                              code,
514                              color,
515                              flipx,flipy,
516                              x*8+spr_dx,y*8+spr_dy,0);
517               }
518               else
519               {
520                     UINT16 *destline;
521                     int yloop,xloop;
522                     int ypos, xpos;
523                     const UINT8 *srcgfx;
524                     int gfxoffs;
525                     ypos = y*8+spr_dy;//+((st0016_vregs[j+2]==0xaf)?0x50:0);//hack for mayjinsen title screen
526                     xpos = x*8+spr_dx;
527                     gfxoffs = 0;
528                     srcgfx= gfx->get_data(code);
529
530                     for (yloop=0; yloop<8; yloop++)
531                     {
532                        UINT16 drawypos;
533
534                        if (!flipy) {drawypos = ypos+yloop;} else {drawypos = (ypos+8-1)-yloop;}
535                        destline = &bitmap.pix16(drawypos);
536
537                        for (xloop=0; xloop<8; xloop++)
538                        {
539                           UINT16 drawxpos;
540                           int pixdata;
541                           pixdata = srcgfx[gfxoffs];
542
543                           if (!flipx) { drawxpos = xpos+xloop; } else { drawxpos = (xpos+8-1)-xloop; }
544
545                           if (drawxpos > cliprect.max_x)
546                              drawxpos -= 512; // wrap around
547
548                           if (cliprect.contains(drawxpos, drawypos))
549                           {
550                              if(st0016_vregs[j+7]==0x12)
551                                 destline[drawxpos] = (destline[drawxpos] | (pixdata<<4))&0x3ff;
552                              else
553                              {
554                                 if(ISMACS2)
555                                 {
556                                    if(pixdata)// || destline[drawxpos]==UNUSED_PEN)
557                                    {
558                                       destline[drawxpos] = pixdata + (color*16);
559                                    }
560                                 }
561                                 else
562                                 {
563                                    if(pixdata || destline[drawxpos]==UNUSED_PEN)
564                                    {
565                                       destline[drawxpos] = pixdata + (color*16);
566                                    }
567                                 }
568
569                              }
570                           }
571
572                           gfxoffs++;
573
574                        }
575                     }
576               }
577               i+=4;
578            }
579      }
580   }
581}
582
583
584void st0016_state::st0016_draw_screen(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
585{
586   draw_bgmap(bitmap,cliprect,0);
587   draw_sprites(bitmap,cliprect);
588   draw_bgmap(bitmap,cliprect,1);
589}
590
591UINT32 st0016_state::screen_update_st0016(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
592{
593#ifdef MAME_DEBUG
594   if(machine().input().code_pressed_once(KEYCODE_Z))
595   {
596      int h,j;
597      FILE *p=fopen("vram.bin","wb");
598      fwrite(st0016_spriteram,1,0x1000*ST0016_MAX_SPR_BANK,p);
599      fclose(p);
600
601      p=fopen("vram.txt","wt");
602      for(h=0;h<0xc0;h++)
603         fprintf(p,"VREG %.4x - %.4x\n",h,st0016_vregs[h]);
604      for(h=0;h<0x1000*ST0016_MAX_SPR_BANK;h+=8)
605      {
606         fprintf(p,"%.4x - %.4x - ",h,h>>3);
607         for(j=0;j<8;j++)
608            fprintf(p,"%.2x ",st0016_spriteram[h+j]);
609            fprintf(p,"\n");
610      }
611      fclose(p);
612   }
613#endif
614
615   bitmap.fill(UNUSED_PEN, cliprect);
616   st0016_draw_screen(screen, bitmap, cliprect);
617   return 0;
618}

Previous 199869 Revisions Next


© 1997-2024 The MAME Team