Previous 15994 Revisions Next

r7419 Thursday 18th February, 2010 at 12:14:07 UTC by Curt Coder
[TRS80M2] Fixed memory banking.
[src/mess/drivers]trs80m2.c
[src/mess/includes]trs80m2.h

src/mess/includes/trs80m2.h
r7418r7419
1717struct _trs80m2_state
1818{
1919   /* memory state */
20   int boot_rom;
2021   int bank;
22   int msel;
2123 
2224   /* floppy state */
2325   int fdc_intrq;
src/mess/drivers/trs80m2.c
r7418r7419
9090   wd17xx_dden_w(device, BIT(data, 7));
9191}
9292 
93static void bankswitch(running_machine *machine)
94{
95   trs80m2_state *state = (trs80m2_state *)machine->driver_data;
96 
97   const address_space *program = cputag_get_address_space(machine, Z80_TAG, ADDRESS_SPACE_PROGRAM);
98   running_device *messram = devtag_get_device(machine, "messram");
99   UINT8 *rom = memory_region(machine, Z80_TAG);
100   UINT8 *ram = messram_get_ptr(messram);
101   int last_page = (messram_get_size(messram) / 0x8000) - 1;
102 
103   if (state->boot_rom)
104   {
105      /* enable BOOT ROM */
106      memory_install_rom(program, 0x0000, 0x07ff, 0, 0x800, rom);
107      memory_install_ram(program, 0x1000, 0x7fff, 0, 0, ram + 0x1000);
108   }
109   else
110   {
111      /* enable RAM */
112      memory_install_ram(program, 0x0000, 0x7fff, 0, 0, ram);
113   }
114 
115   if (state->bank > last_page)
116   {
117      memory_unmap_readwrite(program, 0x8000, 0xffff, 0, 0);
118   }
119   else
120   {
121      /* enable RAM */
122      memory_install_ram(program, 0x8000, 0xffff, 0, 0, ram + (state->bank * 0x8000));
123   }
124 
125   if (state->msel)
126   {
127      /* enable video RAM */
128      memory_install_ram(program, 0xf800, 0xffff, 0, 0, state->video_ram);
129   }
130}
131 
93132static WRITE8_HANDLER( rom_enable_w )
94133{
95134   /*
r7418r7419
107146 
108147    */
109148 
110   const address_space *program = cputag_get_address_space(space->machine, Z80_TAG, ADDRESS_SPACE_PROGRAM);
111   UINT8 *ram = messram_get_ptr(devtag_get_device(space->machine, "messram"));
112   UINT8 *rom = memory_region(space->machine, Z80_TAG);
149   trs80m2_state *state = (trs80m2_state *)space->machine->driver_data;
113150 
114   if (BIT(data, 0))
115   {
116      /* enable BOOT ROM */
117      memory_install_rom(program, 0x0000, 0x07ff, 0, 0x800, rom);
118   }
119   else
120   {
121      /* enable RAM */
122      memory_install_ram(program, 0x0000, 0x0fff, 0, 0, ram);
123   }
151   state->boot_rom = BIT(data, 0);
152   bankswitch(space->machine);
124153}
125154 
126155static READ8_HANDLER( keyboard_r )
r7418r7419
199228 
200229   trs80m2_state *state = (trs80m2_state *)space->machine->driver_data;
201230 
202   const address_space *program = cputag_get_address_space(space->machine, Z80_TAG, ADDRESS_SPACE_PROGRAM);
203   UINT8 *ram = messram_get_ptr(devtag_get_device(space->machine, "messram"));
204   int last_page = (messram_get_size(devtag_get_device(space->machine, "messram")) / 0x8000) - 1;
205 
206231   /* memory bank select */
207232   state->bank = data & 0x0f;
208233 
r7418r7419
213238   /* RTC interrupt enable */
214239   state->enable_rtc_int = BIT(data, 5);
215240 
216   if ((state->rtc_int == 2) && state->enable_rtc_int)
241   if (state->enable_rtc_int && state->rtc_int)
217242   {
218243      /* trigger RTC interrupt */
219244      cputag_set_input_line(space->machine, Z80_TAG, INPUT_LINE_NMI, ASSERT_LINE);
r7418r7419
222247   /* video display enable */
223248   state->blnkvid = BIT(data, 6);
224249 
225   if (BIT(data, 7))
226   {
227      /* enable video RAM */
228      memory_install_ram(program, 0xf800, 0xffff, 0, 0, state->video_ram);
229   }
230   else
231   {
232      if (state->bank > last_page)
233      {
234         memory_unmap_readwrite(program, 0x8000, 0xffff, 0, 0);
235      }
236      else
237      {
238         /* enable RAM */
239         memory_install_ram(program, 0x8000, 0xffff, 0, 0, ram + (state->bank * 0x8000));
240      }
241   }
250   /* video RAM enable */
251   state->msel = BIT(data, 7);
252   bankswitch(space->machine);
242253}
243254 
244255static READ8_HANDLER( keyboard_busy_r )
r7418r7419
521532{
522533   trs80m2_state *driver_state = (trs80m2_state *)device->machine->driver_data;
523534 
524   if (state) driver_state->rtc_int++;
525 
526   if (driver_state->rtc_int == 2)
535   if (state)
527536   {
528      driver_state->rtc_int = 0;
537      driver_state->rtc_int = !driver_state->rtc_int;
529538 
530      if (driver_state->enable_rtc_int)
539      if (driver_state->enable_rtc_int && driver_state->rtc_int)
531540      {
541         logerror("RTC INT\n");
532542         /* trigger RTC interrupt */
533543         cputag_set_input_line(device->machine, Z80_TAG, INPUT_LINE_NMI, ASSERT_LINE);
534544      }
r7418r7419
779789   state->centronics = devtag_get_device(machine, CENTRONICS_TAG);
780790 
781791   /* register for state saving */
792   state_save_register_global(machine, state->boot_rom);
793   state_save_register_global(machine, state->bank);
794   state_save_register_global(machine, state->msel);
795   state_save_register_global(machine, state->fdc_intrq);
782796   state_save_register_global(machine, state->key_latch);
783797   state_save_register_global(machine, state->key_data);
798   state_save_register_global(machine, state->key_bit);
799   state_save_register_global(machine, state->kbclk);
800   state_save_register_global(machine, state->kbdata);
801   state_save_register_global(machine, state->kbirq);
802   state_save_register_global(machine, state->blnkvid);
803   state_save_register_global(machine, state->_80_40_char_en);
804   state_save_register_global(machine, state->de);
805   state_save_register_global(machine, state->rtc_int);
806   state_save_register_global(machine, state->enable_rtc_int);
784807}
785808 
786809static MACHINE_RESET( trs80m2 )
787810{
788811   trs80m2_state *state = (trs80m2_state *)machine->driver_data;
789   const address_space *program = cputag_get_address_space(machine, Z80_TAG, ADDRESS_SPACE_PROGRAM);
790812 
813   /* clear keyboard interrupt */
814   state->kbirq = 1;
815 
791816   /* enable boot ROM */
792   rom_enable_w(program, 0, 1);
817   state->boot_rom = 1;
793818 
794   state->kbirq = 1;
819   /* disable video RAM */
820   state->msel = 0;
821 
822   bankswitch(machine);
795823}
796824 
797825/* Machine Driver */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team