Previous 15994 Revisions Next

r7659 Sunday 28th March, 2010 at 16:55:55 UTC by Angelo Salese
[MZ2500]: rewritten the bankswitch system by using custom code, hooked up basic PCG support and removed the PIO kludge
[src/mess/drivers]mz2500.c

src/mess/drivers/mz2500.c
r7658r7659
99    0x00000-0x3ffff Work RAM
1010    0x40000-0x5ffff CG RAM (address bitswapped?)
1111    0x60000-0x67fff "Read modify write" area (related to the CG RAM)
12    0x68000-0x6ffff IPL ROM
13    0x70000-0x71fff TVRAM
14    0x72000-0x73fff Kanji ROM / PCG RAM (banked)
15    0x74000-0x75fff Dictionary ROM (banked)
16    0x76000-0x77fff NOP
17    0x78000-0x7ffff Phone ROM
12    0x68000-0x6ffff IPL ROM (0x34-0x37)
13    0x70000-0x71fff TVRAM (0x38)
14    0x72000-0x73fff Kanji ROM / PCG RAM (banked) (0x39)
15    0x74000-0x75fff Dictionary ROM (banked) (0x3a)
16    0x76000-0x77fff NOP (0x3b)
17    0x78000-0x7ffff Phone ROM (0x3c-0x3f)
1818
1919    start-up vblank irq is rst $28 (0xef), this system has mixed im 0 and im 2 (!)
2020
2121   after some time, clear work ram [$919] to 0 ... something to do with irqs?
2222
23   currently emulation speed crawls a lot when you use the debugger,
24   comment out lines 983/984 of emu/memory.c for the time being.
25
2326****************************************************************************/
2427
2528#include "emu.h"
r7658r7659
2932/* machine stuff */
3033static UINT8 bank_val[8],bank_addr;
3134static UINT8 irq_sel,irq_vector[4];
35static UINT8 kanji_bank;
3236
3337/* video stuff*/
3438static UINT8 text_reg[0x100], text_reg_index;
r7658r7659
4246{
4347   UINT8 *vram = memory_region(screen->machine, "maincpu");
4448   int x,y,count;
45   const gfx_element *gfx = screen->machine->gfx[0];
49//   gfx_element *gfx;// = screen->machine->gfx[0];
4650
4751   count = 0x70000;
4852
r7658r7659
5357         for (x=0;x<text_col_size;x++)
5458         {
5559            int tile = vram[count+0x0000] & 0xff;
56            //int attr = vram[count+0x800];
60            int attr = vram[count+0x800];
5761            int tile_bank = vram[count+0x1000] & 0x3f;
62            int gfx_sel = (attr & 0x38) | (vram[count+0x1000] & 0xc0);
63            int gfx_num;
5864
65            if(gfx_sel == 0x00)
66               gfx_num = 3;
67            else
68               gfx_num = 0; //TODO
69
5970            tile|= tile_bank << 8;
6071
61            drawgfx_opaque(bitmap,cliprect,gfx,tile,0,0,0,x*8,(y)*8);
72            drawgfx_opaque(bitmap,cliprect,screen->machine->gfx[gfx_num],tile,0,0,0,x*8,(y)*8);
6273
6374            count++;
6475         }
r7658r7659
7182         for (x=0;x<text_col_size;x++)
7283         {
7384            int tile = vram[count+0x0000] & 0xfe;
74            //int attr = vram[count+0x800];
85            int attr = vram[count+0x800];
7586            int tile_bank = vram[count+0x1000] & 0x3f;
87            int gfx_sel = (attr & 0x38) | (vram[count+0x1000] & 0xc0);
88            int gfx_num;
7689
90            if(gfx_sel == 0x00)
91               gfx_num = 3;
92            else
93               gfx_num = 0; //TODO
94
7795            tile|= tile_bank << 8;
7896
79            drawgfx_opaque(bitmap,cliprect,gfx,tile,0,0,0,x*8,(y)*8);
80            drawgfx_opaque(bitmap,cliprect,gfx,tile+1,0,0,0,x*8,(y+1)*8);
97            drawgfx_opaque(bitmap,cliprect,screen->machine->gfx[gfx_num],tile,0,0,0,x*8,(y)*8);
98            drawgfx_opaque(bitmap,cliprect,screen->machine->gfx[gfx_num],tile+1,0,0,0,x*8,(y+1)*8);
8199
82100            count++;
83101         }
r7658r7659
87105    return 0;
88106}
89107
108static UINT8 mz2500_ram_read(running_machine *machine, UINT16 offset, UINT8 bank_num)
109{
110   UINT8 *ram = memory_region(machine, "maincpu");
111   UINT8 cur_bank = bank_val[bank_num];
112
113   switch(cur_bank)
114   {
115      case 0x39:
116      {
117         if(kanji_bank & 0x80) //kanji ROM
118         {
119            UINT8 *knj_rom = memory_region(machine, "kanji");
120
121            return knj_rom[(offset & 0x7ff)+((kanji_bank & 0x7f)*0x800)];
122         }
123         else //PCG RAM
124         {
125            UINT8 *pcg_ram = memory_region(machine, "pcg");
126
127            return pcg_ram[offset];
128         }
129      }
130      break;
131      default: return ram[offset+cur_bank*0x2000];
132   }
133
134   return 0xff;
135}
136
137static void mz2500_ram_write(running_machine *machine, UINT16 offset, UINT8 data, UINT8 bank_num)
138{
139   UINT8 *ram = memory_region(machine, "maincpu");
140   UINT8 cur_bank = bank_val[bank_num];
141
142   switch(cur_bank)
143   {
144      case 0x39:
145      {
146         if(kanji_bank & 0x80) //kanji ROM
147         {
148            //NOP
149         }
150         else //PCG RAM
151         {
152            UINT8 *pcg_ram = memory_region(machine, "pcg");
153            pcg_ram[offset] = data;
154            gfx_element_mark_dirty(machine->gfx[3], (offset) >> 3);
155         }
156      }
157      break;
158      default: ram[offset+cur_bank*0x2000] = data; break;
159   }
160}
161
162static READ8_HANDLER( bank0_r ) { return mz2500_ram_read(space->machine, offset, 0); }
163static READ8_HANDLER( bank1_r ) { return mz2500_ram_read(space->machine, offset, 1); }
164static READ8_HANDLER( bank2_r ) { return mz2500_ram_read(space->machine, offset, 2); }
165static READ8_HANDLER( bank3_r ) { return mz2500_ram_read(space->machine, offset, 3); }
166static READ8_HANDLER( bank4_r ) { return mz2500_ram_read(space->machine, offset, 4); }
167static READ8_HANDLER( bank5_r ) { return mz2500_ram_read(space->machine, offset, 5); }
168static READ8_HANDLER( bank6_r ) { return mz2500_ram_read(space->machine, offset, 6); }
169static READ8_HANDLER( bank7_r ) { return mz2500_ram_read(space->machine, offset, 7); }
170static WRITE8_HANDLER( bank0_w ) { mz2500_ram_write(space->machine, offset, data, 0); }
171static WRITE8_HANDLER( bank1_w ) { mz2500_ram_write(space->machine, offset, data, 1); }
172static WRITE8_HANDLER( bank2_w ) { mz2500_ram_write(space->machine, offset, data, 2); }
173static WRITE8_HANDLER( bank3_w ) { mz2500_ram_write(space->machine, offset, data, 3); }
174static WRITE8_HANDLER( bank4_w ) { mz2500_ram_write(space->machine, offset, data, 4); }
175static WRITE8_HANDLER( bank5_w ) { mz2500_ram_write(space->machine, offset, data, 5); }
176static WRITE8_HANDLER( bank6_w ) { mz2500_ram_write(space->machine, offset, data, 6); }
177static WRITE8_HANDLER( bank7_w ) { mz2500_ram_write(space->machine, offset, data, 7); }
178
179
90180static READ8_HANDLER( mz2500_bank_addr_r )
91181{
92182   return bank_addr;
r7658r7659
111201
112202static WRITE8_HANDLER( mz2500_bank_data_w )
113203{
114   UINT8 *ROM = memory_region(space->machine, "maincpu");
115   static const char *const bank_name[] = { "bank0", "bank1", "bank2", "bank3", "bank4", "bank5", "bank6", "bank7" };
204//   UINT8 *ROM = memory_region(space->machine, "maincpu");
205//   static const char *const bank_name[] = { "bank0", "bank1", "bank2", "bank3", "bank4", "bank5", "bank6", "bank7" };
116206
117207   bank_val[bank_addr] = data & 0x3f;
118208
119   if((data*2) >= 0x70)
120   printf("%s %02x\n",bank_name[bank_addr],bank_val[bank_addr]*2);
209//   if((data*2) >= 0x70)
210//   printf("%s %02x\n",bank_name[bank_addr],bank_val[bank_addr]*2);
121211
122   memory_set_bankptr(space->machine, bank_name[bank_addr], &ROM[bank_val[bank_addr]*0x2000]);
212//   memory_set_bankptr(space->machine, bank_name[bank_addr], &ROM[bank_val[bank_addr]*0x2000]);
123213
124214   bank_addr++;
125215   bank_addr&=7;
126216}
127217
218static WRITE8_HANDLER( mz2500_kanji_bank_w )
219{
220   kanji_bank = data;
221}
222
128223static READ8_HANDLER( mz2500_crtc_r )
129224{
130225   static UINT8 vblank_bit, hblank_bit;
r7658r7659
173268}
174269
175270static ADDRESS_MAP_START(mz2500_map, ADDRESS_SPACE_PROGRAM, 8)
176   AM_RANGE(0x0000, 0x1fff) AM_RAMBANK("bank0")
177   AM_RANGE(0x2000, 0x3fff) AM_RAMBANK("bank1")
178   AM_RANGE(0x4000, 0x5fff) AM_RAMBANK("bank2")
179   AM_RANGE(0x6000, 0x7fff) AM_RAMBANK("bank3")
180   AM_RANGE(0x8000, 0x9fff) AM_RAMBANK("bank4")
181   AM_RANGE(0xa000, 0xbfff) AM_RAMBANK("bank5")
182   AM_RANGE(0xc000, 0xdfff) AM_RAMBANK("bank6")
183   AM_RANGE(0xe000, 0xffff) AM_RAMBANK("bank7")
271   AM_RANGE(0x0000, 0x1fff) AM_READWRITE(bank0_r,bank0_w)
272   AM_RANGE(0x2000, 0x3fff) AM_READWRITE(bank1_r,bank1_w)
273   AM_RANGE(0x4000, 0x5fff) AM_READWRITE(bank2_r,bank2_w)
274   AM_RANGE(0x6000, 0x7fff) AM_READWRITE(bank3_r,bank3_w)
275   AM_RANGE(0x8000, 0x9fff) AM_READWRITE(bank4_r,bank4_w)
276   AM_RANGE(0xa000, 0xbfff) AM_READWRITE(bank5_r,bank5_w)
277   AM_RANGE(0xc000, 0xdfff) AM_READWRITE(bank6_r,bank6_w)
278   AM_RANGE(0xe000, 0xffff) AM_READWRITE(bank7_r,bank7_w)
184279ADDRESS_MAP_END
185280
281#if 0
186282static READ8_HANDLER( kludge_r )
187283{
188284   return 0xff; //mame_rand(space->machine);
189285}
286#endif
190287
191288static ADDRESS_MAP_START(mz2500_io, ADDRESS_SPACE_IO, 8)
192289   ADDRESS_MAP_GLOBAL_MASK(0xff)
r7658r7659
210307//   AM_RANGE(0xc8, 0xc9) AM_READ(kludge_r)
211308//   AM_RANGE(0xca, 0xca) AM_READWRITE(voice_r,voice_w)
212309//   AM_RANGE(0xcc, 0xcc) AM_READWRITE(calendar_r,calendar_w)
213//   AM_RANGE(0xce, 0xcf) AM_WRITE(memory_w)
310//   AM_RANGE(0xce, 0xce) AM_WRITE(mz2500_dictionary_bank_w)
311   AM_RANGE(0xcf, 0xcf) AM_WRITE(mz2500_kanji_bank_w)
214312//   AM_RANGE(0xd8, 0xdb) AM_READWRITE(fdc_r,fdc_w)
215313//   AM_RANGE(0xdc, 0xdd) AM_WRITE(floppy_w)
216   AM_RANGE(0xe0, 0xe3) AM_DEVREADWRITE("z80pio_0",z80pio_cd_ba_r,z80pio_cd_ba_w)
314   AM_RANGE(0xe0, 0xe1) AM_DEVREADWRITE("z80pio_0", z80pio_c_r, z80pio_c_w)
315   AM_RANGE(0xe2, 0xe3) AM_DEVREADWRITE("z80pio_0", z80pio_d_r, z80pio_d_w)
316//   AM_RANGE(0xe0, 0xe3) AM_DEVREADWRITE("z80pio_0",z80pio_cd_ba_r,z80pio_cd_ba_w)
217317//   AM_RANGE(0xe4, 0xe7) AM_READWRITE(pit_r,pit_w)
218   AM_RANGE(0xea, 0xea) AM_READ(kludge_r) //pio core bug? this seems to be used as a diagnostic port
219   AM_RANGE(0xe8, 0xeb) AM_DEVREADWRITE("z80pio_1",z80pio_cd_ba_r,z80pio_cd_ba_w)
318//   AM_RANGE(0xea, 0xea) AM_READ(kludge_r) //pio core bug? this seems to be used as a diagnostic port
319//   AM_RANGE(0xe8, 0xeb) AM_DEVREADWRITE("z80pio_1",z80pio_cd_ba_r,z80pio_cd_ba_w)
320   AM_RANGE(0xe8, 0xe9) AM_DEVREADWRITE("z80pio_1", z80pio_c_r, z80pio_c_w)
321   AM_RANGE(0xea, 0xeb) AM_DEVREADWRITE("z80pio_1", z80pio_d_r, z80pio_d_w)
220322//   AM_RANGE(0xef, 0xef) AM_READWRITE(joystick_r,joystick_w)
221323//   AM_RANGE(0xf0, 0xf3) AM_WRITE(timer_w)
222324   AM_RANGE(0xf4, 0xf7) AM_READ(mz2500_crtc_r) AM_WRITE(mz2500_crtc_w)
r7658r7659
230332
231333static MACHINE_RESET(mz2500)
232334{
233   UINT8 *ROM = memory_region(machine, "maincpu");
335   UINT8 *RAM = memory_region(machine, "maincpu");
336   UINT8 *IPL = memory_region(machine, "ipl");
337   int i;
234338
235339   bank_val[0] = 0x00;
236340   bank_val[1] = 0x01;
r7658r7659
241345   bank_val[6] = 0x06;
242346   bank_val[7] = 0x07;
243347
244   memory_set_bankptr(machine, "bank0", &ROM[bank_val[0]*0x2000]);
348/*   memory_set_bankptr(machine, "bank0", &ROM[bank_val[0]*0x2000]);
245349   memory_set_bankptr(machine, "bank1", &ROM[bank_val[1]*0x2000]);
246350   memory_set_bankptr(machine, "bank2", &ROM[bank_val[2]*0x2000]);
247351   memory_set_bankptr(machine, "bank3", &ROM[bank_val[3]*0x2000]);
248352   memory_set_bankptr(machine, "bank4", &ROM[bank_val[4]*0x2000]);
249353   memory_set_bankptr(machine, "bank5", &ROM[bank_val[5]*0x2000]);
250354   memory_set_bankptr(machine, "bank6", &ROM[bank_val[6]*0x2000]);
251   memory_set_bankptr(machine, "bank7", &ROM[bank_val[7]*0x2000]);
355   memory_set_bankptr(machine, "bank7", &ROM[bank_val[7]*0x2000]);*/
252356
253357   irq_vector[0] = 0xef; /* RST 28h - vblank */
254358
255359   text_col_size = 40;
256360   text_font_reg = 0;
361
362   for(i=0;i<0x8000;i++)
363   {
364      RAM[i] = IPL[i];
365      RAM[i+0x68000] = IPL[i];
366   }
257367}
258368
259369static const gfx_layout mz2500_cg_layout =
r7658r7659
291401};
292402
293403static GFXDECODE_START( mz2500 )
294   GFXDECODE_ENTRY("gfx1", 0, mz2500_cg_layout, 0, 256)
295   GFXDECODE_ENTRY("gfx1", 0x4400, mz2500_8_layout, 0, 256)   // for viewer only
296   GFXDECODE_ENTRY("gfx1", 0, mz2500_16_layout, 0, 256)      // for viewer only
404   GFXDECODE_ENTRY("kanji", 0, mz2500_cg_layout, 0, 256)
405   GFXDECODE_ENTRY("kanji", 0x4400, mz2500_8_layout, 0, 256)   // for viewer only
406   GFXDECODE_ENTRY("kanji", 0, mz2500_16_layout, 0, 256)      // for viewer only
407   GFXDECODE_ENTRY("pcg", 0, mz2500_cg_layout, 0, 256)
297408GFXDECODE_END
298409
299410static INTERRUPT_GEN( mz2500_vbl )
r7658r7659
380491/* ROM definition */
381492ROM_START( mz2500 )
382493   ROM_REGION( 0x80000, "maincpu", ROMREGION_ERASEFF )
494
495   ROM_REGION( 0x08000, "ipl", 0 )
383496   ROM_LOAD( "ipl.rom", 0x00000, 0x8000, CRC(7a659f20) SHA1(ccb3cfdf461feea9db8d8d3a8815f7e345d274f7) )
384   ROM_RELOAD( 0x68000, 0x8000 )
385497
386498   /* this is probably an hand made ROM, will be removed in the end ...*/
387499   ROM_REGION( 0x1000, "cgrom", 0 )
388500   ROM_LOAD( "cg.rom", 0x0000, 0x0800, CRC(a082326f) SHA1(dfa1a797b2159838d078650801c7291fa746ad81) )
389501
390   ROM_REGION( 0x40000, "gfx1", 0 )
502   ROM_REGION( 0x40000, "kanji", 0 )
391503   ROM_LOAD( "kanji.rom", 0x0000, 0x40000, CRC(dd426767) SHA1(cc8fae0cd1736bc11c110e1c84d3f620c5e35b80) )
392504
393505   ROM_REGION( 0x40000, "dictionary", 0 )
394506   ROM_LOAD( "dict.rom", 0x00000, 0x40000, CRC(aa957c2b) SHA1(19a5ba85055f048a84ed4e8d471aaff70fcf0374) )
507
508   ROM_REGION( 0x2000, "pcg", ROMREGION_ERASEFF )
395509ROM_END
396510
397511/* Driver */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team