Previous 199869 Revisions Next

r34360 Monday 12th January, 2015 at 18:58:20 UTC by Miodrag Milanović
(MESS)gamate : added newer bios and emulated protection [PeT]
[src/mess/drivers]gamate.c

trunk/src/mess/drivers/gamate.c
r242871r242872
1111#include "bus/generic/carts.h"
1212#include "rendlay.h"
1313
14//#define USE_GFX
15
1416class gamate_state : public driver_device
1517{
1618public:
r242871r242872
1820      : driver_device(mconfig, type, tag)
1921      , m_maincpu(*this, "maincpu")
2022      , m_cart(*this, "cartslot")
21//      , m_gfxdecode(*this, "gfxdecode")
23#ifdef USE_GFX     
24      , m_gfxdecode(*this, "gfxdecode")
25#endif
2226      , m_io_joy(*this, "JOY")
2327      , m_palette(*this, "palette")
2428      , m_bios(*this, "bios")
r242871r242872
2630
2731   DECLARE_PALETTE_INIT(gamate);
2832   DECLARE_READ8_MEMBER(protection_r);
33   DECLARE_READ8_MEMBER(newer_protection_set);
34   DECLARE_WRITE8_MEMBER(protection_reset);
2935   DECLARE_READ8_MEMBER(gamate_cart_protection_r);
3036   DECLARE_WRITE8_MEMBER(gamate_cart_protection_w);
3137   DECLARE_WRITE8_MEMBER(cart_bankswitchmulti_w);
r242871r242872
4753
4854   struct
4955   {
50   UINT8 reg[8];
51   struct {
52      bool write;
53      bool page2; // else page1
56     UINT8 reg[8];
57     struct {
58       bool write;
59       bool page2; // else page1
5460   UINT8 ypos, xpos/*tennis*/;
55      UINT8 data[2][0x100][0x20];
56      } bitmap;
57   UINT8 x, y;
61       UINT8 data[2][0x100][0x20];
62     } bitmap;
63     UINT8 x, y;
5864      bool y_increment;
5965   } video;
6066
6167   struct {
68     bool set;
6269      int bit_shifter;
6370      UINT8 cartridge_byte;
6471      UINT16 address; // in reality something more like short local cartridge address offset
6572      bool unprotected;
6673      bool failed;
74     
6775   } card_protection;
6876
6977   required_device<cpu_device> m_maincpu;
7078   required_device<generic_slot_device> m_cart;
71//  required_device<gfxdecode_device> m_gfxdecode;
79#ifdef USE_GFX
80   required_device<gfxdecode_device> m_gfxdecode;
81#endif
7282   required_ioport m_io_joy;
7383   required_device<palette_device> m_palette;
7484   required_shared_ptr<UINT8> m_bios;
7585   emu_timer *timer1;
7686   emu_timer *timer2;
87   UINT8 bank_multi; 
7788};
7889
7990WRITE8_MEMBER( gamate_state::gamate_cart_protection_w )
8091{
92        logerror("%.6f protection write %x %x address:%x data:%x shift:%d\n",machine().time().as_double(), offset, data, card_protection.address, card_protection.cartridge_byte, card_protection.bit_shifter);
93 
8194   switch (offset) {
8295   case 0:
8396      card_protection.failed= card_protection.failed || ((card_protection.cartridge_byte&0x80)!=0) != ((data&4)!=0);
r242871r242872
91104}
92105READ8_MEMBER( gamate_state::gamate_cart_protection_r )
93106{
94   UINT8 ret=1;
95   switch (offset) {
96   case 0:
97      ret=(card_protection.cartridge_byte&0x80)?2:0;
98      card_protection.cartridge_byte<<=1;
99      card_protection.bit_shifter++;
100      if (card_protection.bit_shifter>=8) {
101         card_protection.bit_shifter=0;
102         card_protection.cartridge_byte=m_cart->get_rom_base()[card_protection.address++];
103         card_protection.unprotected=true;
104         if (!card_protection.failed) {
105         } // now protection chip on cartridge activates cartridge chip select on cpu accesses
106      }
107      break;
107
108  UINT8 ret=1;
109  if (card_protection.bit_shifter==7 && card_protection.unprotected) {
110    ret=m_cart->get_rom_base()[bank_multi*0x4000];
111  } else {
112   card_protection.bit_shifter++;
113   if (card_protection.bit_shifter==8) {
114      card_protection.bit_shifter=0;
115      card_protection.cartridge_byte='G';
116      card_protection.unprotected=true;
108117   }
109   return ret;
118   ret=(card_protection.cartridge_byte&0x80)?2:0;
119   if (card_protection.bit_shifter==7 && !card_protection.failed) { // now protection chip on cartridge activates cartridge chip select on cpu accesses
120//        m_maincpu->space(AS_PROGRAM).install_read_handler(0x6000, 0x6000, READ8_DELEGATE(gamate_state, gamate_cart_protection_r)); // next time I will try to get this working
121   }
122   card_protection.cartridge_byte<<=1;
123  }
124  logerror("%.6f protection read %x %x address:%x data:%x shift:%d\n",machine().time().as_double(), offset, ret, card_protection.address, card_protection.cartridge_byte, card_protection.bit_shifter);
125  return ret;
110126}
111127
112READ8_MEMBER( gamate_state::protection_r ) { return 1; }
128READ8_MEMBER( gamate_state::protection_r ) { return card_protection.set? 3: 1; } // bits 0 and 1 checked
113129
130WRITE8_MEMBER( gamate_state::protection_reset )
131{
132  // writes 0x20
133  card_protection.address=0x6005-0x6001;
134  card_protection.bit_shifter=0;
135  card_protection.cartridge_byte=m_cart->get_rom_base()[card_protection.address++];//m_cart_rom[card_protection.address++];
136  card_protection.failed=false;
137  card_protection.unprotected=false;
138}
139
140READ8_MEMBER( gamate_state::newer_protection_set )
141{
142  card_protection.set=true;
143  return 0;
144}
145
146
114147WRITE8_MEMBER( gamate_state::gamate_video_w )
115148{
116   video.reg[offset]=data;
117   switch (offset) {
118   case 1: video.bitmap.write=data&0xc0; // more addressing mode
149  video.reg[offset]=data;
150  switch (offset) {
151  case 1: video.bitmap.write=data&0xc0; // more addressing mode
119152      video.y_increment=data&0x40;
120153      break;
121154   case 2: video.bitmap.xpos=data;break; // at least 7 bits
122155   case 3: video.bitmap.ypos=data;break; // at least 7 bits
123   case 4: video.bitmap.page2=data&0x80;video.x=data&0x7f;break;
124   case 5: video.y=data;break;
125   case 7:
126   if (video.bitmap.write) {
127      if (video.x<ARRAY_LENGTH(video.bitmap.data[0][0]) /*&& video.y<ARRAY_LENGTH(video.bitmap.data[0])*/)
128      video.bitmap.data[video.bitmap.page2][video.y][video.x]=data;
129      else
130      logerror("%.6f %04x video bitmap x %x invalid\n",machine().time().as_double(), m_maincpu->pc(), video.x);
131   } else {
132      video.bitmap.data[0][video.y][video.x&(ARRAY_LENGTH(video.bitmap.data[0][0])-1)]=data;
133   }
134   if (video.y_increment) video.y++;
156  case 4: video.bitmap.page2=data&0x80;video.x=data&0x7f;break;
157  case 5: video.y=data;break;
158  case 7:
159    if (video.bitmap.write) {
160      if (video.x<ARRAY_LENGTH(video.bitmap.data[0][0]) /*&& video.y<ARRAY_LENGTH(video.bitmap.data[0])*/)
161        video.bitmap.data[video.bitmap.page2][video.y][video.x]=data;
162      else
163        logerror("%.6f %04x video bitmap x %x invalid\n",machine().time().as_double(), m_maincpu->pc(), video.x);
164    } else {
165        video.bitmap.data[0][video.y][video.x&(ARRAY_LENGTH(video.bitmap.data[0][0])-1)]=data;
166    }
167    if (video.y_increment) video.y++;
135168      else video.x++;
136   }
169  }
137170}
138171
139172WRITE8_MEMBER( gamate_state::cart_bankswitchmulti_w )
140173{
141   membank("bankmulti")->set_base(m_cart->get_rom_base()+0x4000*data);
174  bank_multi=data;
175  membank("bankmulti")->set_base(m_cart->get_rom_base()+0x4000*data+1);
142176}
143177
144178WRITE8_MEMBER( gamate_state::cart_bankswitch_w )
r242871r242872
149183READ8_MEMBER( gamate_state::gamate_video_r )
150184{
151185   if (offset!=6) return 0;
152   UINT8 data=0;
153   if (video.bitmap.write) {
154      if (video.x<ARRAY_LENGTH(video.bitmap.data[0][0]) /*&& video.y<ARRAY_LENGTH(video.bitmap.data[0])*/)
155      data=video.bitmap.data[video.bitmap.page2][video.y][video.x];
156      else
157      logerror("%.6f video bitmap x %x invalid\n",machine().time().as_double(),video.x);
158   } else {
159   data=video.bitmap.data[0][video.y][video.x&(ARRAY_LENGTH(video.bitmap.data[0][0])-1)];
160   }
161   if (m_maincpu->pc()<0xf000)
162   logerror("%.6f video read %04x %02x\n",machine().time().as_double(),offset, data);
163   return data;
186  UINT8 data=0;
187  if (video.bitmap.write) {
188      if (video.x<ARRAY_LENGTH(video.bitmap.data[0][0]) /*&& video.y<ARRAY_LENGTH(video.bitmap.data[0])*/)
189        data=video.bitmap.data[video.bitmap.page2][video.y][video.x];
190      else
191        logerror("%.6f video bitmap x %x invalid\n",machine().time().as_double(),video.x);
192  } else {
193    data=video.bitmap.data[0][video.y][video.x&(ARRAY_LENGTH(video.bitmap.data[0][0])-1)];
194  }
195  if (m_maincpu->pc()<0xf000)
196    logerror("%.6f video read %04x %02x\n",machine().time().as_double(),offset, data);
197  return data;
164198}
165199
166200WRITE8_MEMBER( gamate_state::gamate_audio_w )
167201{
168   logerror("%.6f %04x audio write %04x %02x\n",machine().time().as_double(),m_maincpu->pc(),offset,data);
202  logerror("%.6f %04x audio write %04x %02x\n",machine().time().as_double(),m_maincpu->pc(),offset,data);
169203}
170204
171205READ8_MEMBER( gamate_state::gamate_audio_r )
172206{
173   logerror("%.6f %04x audio read %04x \n",machine().time().as_double(),m_maincpu->pc(),offset);
207  logerror("%.6f %04x audio read %04x \n",machine().time().as_double(),m_maincpu->pc(),offset);
174208   return 0;
175209}
176210
177211
178212READ8_MEMBER( gamate_state::gamate_pad_r )
179213{
180   UINT8 data=m_io_joy->read();
181   return data;
214  UINT8 data=m_io_joy->read();
215  return data;
182216}
183217
184218static ADDRESS_MAP_START( gamate_mem, AS_PROGRAM, 8, gamate_state )
185   AM_RANGE(0x0000, 0x03ff) AM_RAM
186   AM_RANGE(0x4000, 0x400d) AM_READWRITE(gamate_audio_r, gamate_audio_w)
187   AM_RANGE(0x4400, 0x4400) AM_READ(gamate_pad_r)
188   AM_RANGE(0x5000, 0x5007) AM_READWRITE(gamate_video_r, gamate_video_w)
189   AM_RANGE(0x5a00, 0x5a00) AM_READ(protection_r)
219    AM_RANGE(0x0000, 0x03ff) AM_RAM
220  AM_RANGE(0x4000, 0x400d) AM_READWRITE(gamate_audio_r, gamate_audio_w)
221  AM_RANGE(0x4400, 0x4400) AM_READ(gamate_pad_r)
222  AM_RANGE(0x5000, 0x5007) AM_READWRITE(gamate_video_r, gamate_video_w)
223  AM_RANGE(0x5800, 0x5800) AM_READ(newer_protection_set)
224  AM_RANGE(0x5900, 0x5900) AM_WRITE(protection_reset)
225  AM_RANGE(0x5a00, 0x5a00) AM_READ(protection_r)
190226
191   AM_RANGE(0x6000, 0x9fff) AM_READ_BANK("bankmulti")
192   AM_RANGE(0xa000, 0xdfff) AM_READ_BANK("bank")
227  AM_RANGE(0x6001, 0x9fff) AM_READ_BANK("bankmulti")
228  AM_RANGE(0xa000, 0xdfff) AM_READ_BANK("bank")
193229
194   AM_RANGE(0x6000, 0x6002) AM_READWRITE(gamate_cart_protection_r, gamate_cart_protection_w)
195//  AM_RANGE(0x6000, 0xdfff) AM_READWRITE(gamate_cart_r, gamate_cart_w)
230   AM_RANGE(0x6000, 0x6000) AM_READWRITE(gamate_cart_protection_r, gamate_cart_protection_w)
196231   AM_RANGE(0x8000, 0x8000) AM_WRITE(cart_bankswitchmulti_w)
197232   AM_RANGE(0xc000, 0xc000) AM_WRITE(cart_bankswitch_w)
198233
199   AM_RANGE(0xf000, 0xffff) AM_ROM AM_SHARE("bios")
234  AM_RANGE(0xf000, 0xffff) AM_ROM AM_SHARE("bios")
200235ADDRESS_MAP_END
201236
202237
r242871r242872
212247   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_SELECT) PORT_NAME("Select")
213248INPUT_PORTS_END
214249
215#ifdef UNUSED_CODE
250#ifdef USE_GFX
216251static const struct gfx_layout gamate_charlayout =
217252{
218      4,      /* width of object */
219      1,      /* height of object */
220      256,/* 256 characters */
221      2,      /* bits per pixel */
222      { 0,1 }, /* no bitplanes */
223      /* x offsets */
224      { 0,2,4,6 },
225      /* y offsets */
226      { 0 },
227      8*1 /* size of 1 object in bits */
253        4,      /* width of object */
254        1,      /* height of object */
255        256,/* 256 characters */
256        2,      /* bits per pixel */
257        { 0,4 }, /* no bitplanes */
258        /* x offsets */
259        { 0,1,2,3 },
260        /* y offsets */
261        { 0 },
262        8*1 /* size of 1 object in bits */
228263};
229264
265static GFXDECODE_START( gamate )
266        GFXDECODE_ENTRY( "gfx1", 0x0000, gamate_charlayout, 0, 0x100 )
267GFXDECODE_END
268#endif
269
230270static const unsigned short gamate_palette[4] =
231271{
232272   0,1,2,3
233273};
234274
235static GFXDECODE_START( gamate_charlayout )
236      GFXDECODE_ENTRY( "gfx1", 0x0000, gamate_charlayout, 0, 0x100 )
237GFXDECODE_END
238#endif
239275
240276/* palette in red, green, blue tribles */
241277static const unsigned char gamate_colors[4][3] =
242278{
243   { 255,255,255 },
244   { 0xa0, 0xa0, 0xa0 },
245   { 0x60, 0x60, 0x60 },
246   { 0, 0, 0 }
279  { 255,255,255 },
280  { 0xa0, 0xa0, 0xa0 },
281  { 0x60, 0x60, 0x60 },
282  { 0, 0, 0 }
247283};
248284
249285PALETTE_INIT_MEMBER(gamate_state, gamate)
r242871r242872
254290   {
255291      palette.set_pen_color(i, gamate_colors[i][0], gamate_colors[i][1], gamate_colors[i][2]);
256292   }
257#if 0
258   for (int i = 0; i < 8; i++)
259      palette.set_indirect_color(i, arcadia_colors[i]);
260
261   for (int i = 0; i < 128+8; i++)
262      palette.set_pen_indirect(i, arcadia_palette[i]);
263#endif
264293}
265294
266
295#ifndef USE_GFX
267296static void BlitPlane(UINT16* line, UINT8 plane1, UINT8 plane2)
268297{
269298   line[3]=(plane1&1)|((plane2<<1)&2);
r242871r242872
271300   line[1]=((plane1>>2)&1)|((plane2>>1)&2);
272301   line[0]=((plane1>>3)&1)|((plane2>>2)&2);
273302}
303#endif
274304
275305UINT32 gamate_state::screen_update_gamate(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
276306{
277   int x, y, j;
278   for (y=0;y<152;y++) {
279   for (x=-(video.bitmap.xpos&7), j=0;x<160;x+=8, j++) {
280      UINT8 d1=video.bitmap.data[0][(y+video.bitmap.ypos)&0xff][(j+video.bitmap.xpos/8)&0x1f];
281      UINT8 d2=video.bitmap.data[1][(y+video.bitmap.ypos)&0xff][(j+video.bitmap.xpos/8)&0x1f];
282      BlitPlane(&bitmap.pix16(y, x+4), d1, d2);
283      BlitPlane(&bitmap.pix16(y, x), d1>>4, d2>>4);
284   }
285   }
286   return 0;
307  int x, y, j;
308  for (y=0;y<152;y++) {
309    for (x=-(video.bitmap.xpos&7), j=0;x<160;x+=8, j++) {
310      UINT8 d1=video.bitmap.data[0][(y+video.bitmap.ypos)&0xff][(j+video.bitmap.xpos/8)&0x1f];
311      UINT8 d2=video.bitmap.data[1][(y+video.bitmap.ypos)&0xff][(j+video.bitmap.xpos/8)&0x1f];
312#ifdef USE_GFX
313      m_gfxdecode->gfx(0)->opaque(bitmap,cliprect, (d1&0xf)|((d2&0xf)<<4), 0,0,0,x+4,y);
314   m_gfxdecode->gfx(0)->opaque(bitmap,cliprect, (d1>>4)|(d2&0xf0),0,0,0,x,y);
315#else
316      BlitPlane(&bitmap.pix16(y, x+4), d1, d2);
317      BlitPlane(&bitmap.pix16(y, x), d1>>4, d2>>4);
318#endif     
319    }
320  }
321  return 0;
287322}
288323
289324DRIVER_INIT_MEMBER(gamate_state,gamate)
290325{
291326   memset(&video, 0, sizeof(video));/* memset(m_ram, 0, sizeof(m_ram));*/
292   UINT8 *gfx=memregion("gfx1")->base();   for (int i=0; i<256; i++) gfx[i]=i;
327#ifdef USE_GFX
328   UINT8 *gfx=memregion("gfx1")->base();
329   for (int i=0; i<256; i++) gfx[i]=i;
330#endif   
293331   timer1 = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gamate_state::gamate_timer),this));
294332   timer2 = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gamate_state::gamate_timer2),this));
295333}
r242871r242872
298336void gamate_state::machine_start()
299337{
300338   if (m_cart->exists()) {
301//      m_maincpu->space(AS_PROGRAM).install_read_handler(0x6000, 0x6000, READ8_DELEGATE(gamate_state, gamate_cart_protection_r));
302      membank("bankmulti")->set_base(m_cart->get_rom_base());
339//      m_maincpu->space(AS_PROGRAM).install_read_handler(0x6000, 0x6000, READ8_DELEGATE(gamate_state, gamate_cart_protection_r));
340      membank("bankmulti")->set_base(m_cart->get_rom_base()+1);
303341      membank("bank")->set_base(m_cart->get_rom_base()+0x4000); // bankswitched games in reality no offset
304342   }
305   m_bios[0xdf1]=0xea; m_bios[0xdf2]=0xea; // $47 protection readback
306   card_protection.address=0x6005-0x6001;
307   card_protection.bit_shifter=0;
308   card_protection.cartridge_byte=m_cart->get_rom_base()[card_protection.address++];//m_cart_rom[card_protection.address++];
309   card_protection.failed=false;
343//   m_bios[0xdf1]=0xea; m_bios[0xdf2]=0xea; // default bios: $47 protection readback
344   card_protection.set=false;
345   bank_multi=0;
310346   card_protection.unprotected=false;
311347   timer2->enable(TRUE);
312348   timer2->reset(m_maincpu->cycles_to_attotime(1000));
r242871r242872
355391   MCFG_SCREEN_UPDATE_DRIVER(gamate_state, screen_update_gamate)
356392   MCFG_SCREEN_PALETTE("palette")
357393
358//  MCFG_GFXDECODE_ADD("gfxdecode", "palette", gamate )
394#ifdef USE_GFX
395   MCFG_GFXDECODE_ADD("gfxdecode", "palette", gamate )
396#endif   
359397   MCFG_PALETTE_ADD("palette", ARRAY_LENGTH(gamate_colors))
360//  MCFG_PALETTE_INDIRECT_ENTRIES(4)
361398   MCFG_PALETTE_INIT_OWNER(gamate_state, gamate)
362399   MCFG_DEFAULT_LAYOUT(layout_lcd)
363400
r242871r242872
370407
371408ROM_START(gamate)
372409   ROM_REGION(0x10000,"maincpu", 0)
373   ROM_LOAD("gamate_bios_umc.bin", 0xf000, 0x1000, CRC(07090415) SHA1(ea449dc607601f9a68d855ad6ab53800d2e99297) )
410   ROM_SYSTEM_BIOS(0, "default", "DEFAULT")
411   ROMX_LOAD("gamate_bios_umc.bin", 0xf000, 0x1000, CRC(07090415) SHA1(ea449dc607601f9a68d855ad6ab53800d2e99297), ROM_BIOS(1) )
412   ROM_SYSTEM_BIOS(1, "newer", "NEWER")
413   ROMX_LOAD("gamate_bios_9130__unknown__bit_icasc00001_9130-bs_r32261.bin", 0xf000, 0x1000, CRC(03a5f3a7) SHA1(4e9dfbfe916ca485530ef4221593ab68738e2217), ROM_BIOS(2) )
414#ifdef USE_GFX   
374415   ROM_REGION(0x100,"gfx1", ROMREGION_ERASEFF)
416#endif   
375417ROM_END
376418
377419
378420/*    YEAR  NAME      PARENT  COMPAT    MACHINE   INPUT    CLASS          INIT      COMPANY    FULLNAME */
379421CONS( 19??, gamate,  0,      0,        gamate,  gamate, gamate_state, gamate, "Bit Corp", "Gamate", GAME_NO_SOUND)
422
423


Previous 199869 Revisions Next


© 1997-2024 The MAME Team