Previous 15994 Revisions Next

r9687 Sunday 28th November, 2010 at 01:33:24 UTC by Nathan Woods
[C64] Multisession fixes. [Atari Ace]
[docs]messnew.txt
[src/mess/drivers]c128.c c64.c c65.c
[src/mess/includes]c128.h c64.h c65.h
[src/mess/machine]c128.c c64.c c65.c
[src/mess/video]vic4567.c vic4567.h vic6567.c

src/mess/machine/c65.c
r9686r9687
195195
196196static WRITE8_DEVICE_HANDLER( c65_cia1_port_a_w )
197197{
198   c65_state *state = device->machine->driver_data<c65_state>();
198199   static const int helper[4] = {0xc000, 0x8000, 0x4000, 0x0000};
199200   running_device *serbus = device->machine->device("serial_bus");
200201
r9686r9687
202203   cbm_iec_clk_w(serbus, device, !BIT(data, 4));
203204   cbm_iec_data_w(serbus, device, !BIT(data, 5));
204205
205   c64_vicaddr = c64_memory + helper[data & 0x03];
206   state->vicaddr = state->memory + helper[data & 0x03];
206207}
207208
208209static WRITE_LINE_DEVICE_HANDLER( c65_cia1_interrupt )
r9686r9687
247248/* dma controller and bankswitch hardware ?*/
248249static READ8_HANDLER( c65_read_mem )
249250{
251   c65_state *state = space->machine->driver_data<c65_state>();
250252   UINT8 result;
251253   if (offset <= 0x0ffff)
252      result = c64_memory[offset];
254      result = state->memory[offset];
253255   else
254256      result = space->read_byte(offset);
255257   return result;
r9686r9687
257259
258260static WRITE8_HANDLER( c65_write_mem )
259261{
262   c65_state *state = space->machine->driver_data<c65_state>();
260263   if (offset <= 0x0ffff)
261      c64_memory[offset] = data;
264      state->memory[offset] = data;
262265   else
263266      space->write_byte(offset, data);
264267}
r9686r9687
815818   {
816819      if (value & 1)
817820      {
818         memory_set_bankptr(machine, "bank8", c64_colorram + 0x400);
819         memory_set_bankptr(machine, "bank9", c64_colorram + 0x400);
821         memory_set_bankptr(machine, "bank8", state->colorram + 0x400);
822         memory_set_bankptr(machine, "bank9", state->colorram + 0x400);
820823         memory_install_read_bank(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0dc00, 0x0dfff, 0, 0, "bank8");
821824         memory_install_write_bank(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0dc00, 0x0dfff, 0, 0, "bank9");
822825      }
r9686r9687
831834#if 0
832835   /* cartridge roms !?*/
833836   if (value & 0x08)
834      memory_set_bankptr(machine, "bank1", c64_roml);
837      memory_set_bankptr(machine, "bank1", state->roml);
835838   else
836      memory_set_bankptr(machine, "bank1", c64_memory + 0x8000);
839      memory_set_bankptr(machine, "bank1", state->memory + 0x8000);
837840
838841   if (value & 0x10)
839      memory_set_bankptr(machine, "bank2", c64_basic);
842      memory_set_bankptr(machine, "bank2", state->basic);
840843   else
841      memory_set_bankptr(machine, "bank2", c64_memory + 0xa000);
844      memory_set_bankptr(machine, "bank2", state->memory + 0xa000);
842845#endif
843846   if ((state->old_value^value) & 0x20)
844847   {
r9686r9687
846849      if (value & 0x20)
847850         memory_set_bankptr(machine, "bank3", state->interface);
848851      else
849         memory_set_bankptr(machine, "bank3", c64_memory + 0xc000);
852         memory_set_bankptr(machine, "bank3", state->memory + 0xc000);
850853   }
851854   state->charset_select = value & 0x40;
852855#if 0
853856   /* cartridge roms !?*/
854857   if (value & 0x80)
855      memory_set_bankptr(machine, "bank8", c64_kernal);
858      memory_set_bankptr(machine, "bank8", state->kernal);
856859   else
857      memory_set_bankptr(machine, "bank6", c64_memory + 0xe000);
860      memory_set_bankptr(machine, "bank6", state->memory + 0xe000);
858861#endif
859862   state->old_value = value;
860863}
r9686r9687
873876   hiram = (data & 2) ? 1 : 0;
874877   charen = (data & 4) ? 1 : 0;
875878
876   if ((!c64_game && c64_exrom) || (loram && hiram && !c64_exrom))
877      memory_set_bankptr(machine, "bank1", c64_roml);
879   if ((!state->game && state->exrom) || (loram && hiram && !state->exrom))
880      memory_set_bankptr(machine, "bank1", state->roml);
878881   else
879      memory_set_bankptr(machine, "bank1", c64_memory + 0x8000);
882      memory_set_bankptr(machine, "bank1", state->memory + 0x8000);
880883
881   if ((!c64_game && c64_exrom && hiram) || (!c64_exrom))
882      memory_set_bankptr(machine, "bank2", c64_romh);
884   if ((!state->game && state->exrom && hiram) || (!state->exrom))
885      memory_set_bankptr(machine, "bank2", state->romh);
883886   else if (loram && hiram)
884      memory_set_bankptr(machine, "bank2", c64_basic);
887      memory_set_bankptr(machine, "bank2", state->basic);
885888   else
886      memory_set_bankptr(machine, "bank2", c64_memory + 0xa000);
889      memory_set_bankptr(machine, "bank2", state->memory + 0xa000);
887890
888   if ((!c64_game && c64_exrom) || (charen && (loram || hiram)))
891   if ((!state->game && state->exrom) || (charen && (loram || hiram)))
889892   {
890893      state->io_on = 1;
891      memory_set_bankptr(machine, "bank6", c64_colorram);
892      memory_set_bankptr(machine, "bank7", c64_colorram);
894      memory_set_bankptr(machine, "bank6", state->colorram);
895      memory_set_bankptr(machine, "bank7", state->colorram);
893896
894897      if (state->io_dc00_on)
895898      {
r9686r9687
900903      {
901904         memory_install_read_bank(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0dc00, 0x0dfff, 0, 0, "bank8");
902905         memory_install_write_bank(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0dc00, 0x0dfff, 0, 0, "bank9");
903         memory_set_bankptr(machine, "bank8", c64_colorram + 0x400);
904         memory_set_bankptr(machine, "bank9", c64_colorram + 0x400);
906         memory_set_bankptr(machine, "bank8", state->colorram + 0x400);
907         memory_set_bankptr(machine, "bank9", state->colorram + 0x400);
905908      }
906909      memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0d000, 0x0d7ff, 0, 0, c65_read_io);
907910      memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0d000, 0x0d7ff, 0, 0, c65_write_io);
r9686r9687
909912   else
910913   {
911914      state->io_on = 0;
912      memory_set_bankptr(machine, "bank5", c64_memory + 0xd000);
913      memory_set_bankptr(machine, "bank7", c64_memory + 0xd800);
914      memory_set_bankptr(machine, "bank9", c64_memory + 0xdc00);
915      memory_set_bankptr(machine, "bank5", state->memory + 0xd000);
916      memory_set_bankptr(machine, "bank7", state->memory + 0xd800);
917      memory_set_bankptr(machine, "bank9", state->memory + 0xdc00);
915918      if (!charen && (loram || hiram))
916919      {
917         memory_set_bankptr(machine, "bank4", c64_chargen);
918         memory_set_bankptr(machine, "bank6", c64_chargen + 0x800);
919         memory_set_bankptr(machine, "bank8", c64_chargen + 0xc00);
920         memory_set_bankptr(machine, "bank4", state->chargen);
921         memory_set_bankptr(machine, "bank6", state->chargen + 0x800);
922         memory_set_bankptr(machine, "bank8", state->chargen + 0xc00);
920923      }
921924      else
922925      {
923         memory_set_bankptr(machine, "bank4", c64_memory + 0xd000);
924         memory_set_bankptr(machine, "bank6", c64_memory + 0xd800);
925         memory_set_bankptr(machine, "bank8", c64_memory + 0xdc00);
926         memory_set_bankptr(machine, "bank4", state->memory + 0xd000);
927         memory_set_bankptr(machine, "bank6", state->memory + 0xd800);
928         memory_set_bankptr(machine, "bank8", state->memory + 0xdc00);
926929      }
927930      memory_install_read_bank(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0d000, 0x0d7ff, 0, 0, "bank4");
928931      memory_install_write_bank(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0d000, 0x0d7ff, 0, 0, "bank5");
929932   }
930933
931   if (!c64_game && c64_exrom)
934   if (!state->game && state->exrom)
932935   {
933      memory_set_bankptr(machine, "bank10", c64_romh);
936      memory_set_bankptr(machine, "bank10", state->romh);
934937   }
935938   else
936939   {
937940      if (hiram)
938941      {
939         memory_set_bankptr(machine, "bank10", c64_kernal);
942         memory_set_bankptr(machine, "bank10", state->kernal);
940943      }
941944      else
942945      {
943         memory_set_bankptr(machine, "bank10", c64_memory + 0xe000);
946         memory_set_bankptr(machine, "bank10", state->memory + 0xe000);
944947      }
945948   }
946949   state->old_data = data;
947950}
948951
949void c65_colorram_write( int offset, int value )
952#ifdef UNUSED_FUNCTION
953void c65_colorram_write( running_machine *machine, int offset, int value )
950954{
951   c64_colorram[offset & 0x7ff] = value | 0xf0;
955   c65_state *state = machine->driver_data<c65_state>();
956   state->colorram[offset & 0x7ff] = value | 0xf0;
952957}
958#endif
953959
954960/*
955961 * only 14 address lines
r9686r9687
959965int c65_dma_read( running_machine *machine, int offset )
960966{
961967   c65_state *state = machine->driver_data<c65_state>();
962   if (!c64_game && c64_exrom)
968   if (!state->game && state->exrom)
963969   {
964970      if (offset < 0x3000)
965         return c64_memory[offset];
966      return c64_romh[offset & 0x1fff];
971         return state->memory[offset];
972      return state->romh[offset & 0x1fff];
967973   }
968   if ((c64_vicaddr == c64_memory) || (c64_vicaddr == c64_memory + 0x8000))
974   if ((state->vicaddr == state->memory) || (state->vicaddr == state->memory + 0x8000))
969975   {
970976      if (offset < 0x1000)
971         return c64_vicaddr[offset & 0x3fff];
977         return state->vicaddr[offset & 0x3fff];
972978      if (offset < 0x2000) {
973979         if (state->charset_select)
974980            return state->chargen[offset & 0xfff];
975981         else
976            return c64_chargen[offset & 0xfff];
982            return state->chargen[offset & 0xfff];
977983      }
978      return c64_vicaddr[offset & 0x3fff];
984      return state->vicaddr[offset & 0x3fff];
979985   }
980   return c64_vicaddr[offset & 0x3fff];
986   return state->vicaddr[offset & 0x3fff];
981987}
982988
983989int c65_dma_read_color( running_machine *machine, int offset )
984990{
985991   c65_state *state = machine->driver_data<c65_state>();
986992   if (state->c64mode)
987      return c64_colorram[offset & 0x3ff] & 0xf;
988   return c64_colorram[offset & 0x7ff];
993      return state->colorram[offset & 0x3ff] & 0xf;
994   return state->colorram[offset & 0x7ff];
989995}
990996
991997static void c65_common_driver_init( running_machine *machine )
992998{
993999   c65_state *state = machine->driver_data<c65_state>();
994   c64_memory = auto_alloc_array_clear(machine, UINT8, 0x10000);
995   memory_set_bankptr(machine, "bank11", c64_memory + 0x00000);
996   memory_set_bankptr(machine, "bank12", c64_memory + 0x08000);
997   memory_set_bankptr(machine, "bank13", c64_memory + 0x0a000);
998   memory_set_bankptr(machine, "bank14", c64_memory + 0x0c000);
999   memory_set_bankptr(machine, "bank15", c64_memory + 0x0e000);
1000   state->memory = auto_alloc_array_clear(machine, UINT8, 0x10000);
1001   memory_set_bankptr(machine, "bank11", state->memory + 0x00000);
1002   memory_set_bankptr(machine, "bank12", state->memory + 0x08000);
1003   memory_set_bankptr(machine, "bank13", state->memory + 0x0a000);
1004   memory_set_bankptr(machine, "bank14", state->memory + 0x0c000);
1005   memory_set_bankptr(machine, "bank15", state->memory + 0x0e000);
10001006
10011007   cbm_common_init();
10021008   state->keyline = 0xff;
10031009
1004   c64_pal = 0;
1010   state->pal = 0;
10051011   state->charset_select = 0;
10061012   state->_6511_port = 0xff;
10071013   state->vicirq = 0;
10081014   state->old_data = -1;
10091015
10101016   /* C65 had no datasette port */
1011   c64_tape_on = 0;
1012   c64_game = 1;
1013   c64_exrom = 1;
1017   state->tape_on = 0;
1018   state->game = 1;
1019   state->exrom = 1;
10141020
1015   /*memset(c64_memory + 0x40000, 0, 0x800000 - 0x40000); */
1021   /*memset(state->memory + 0x40000, 0, 0x800000 - 0x40000); */
10161022}
10171023
10181024DRIVER_INIT( c65 )
r9686r9687
10271033   c65_state *state = machine->driver_data<c65_state>();
10281034   state->dma.version = 1;
10291035   c65_common_driver_init(machine);
1030   c64_pal = 1;
1036   state->pal = 1;
10311037}
10321038
10331039MACHINE_START( c65 )
r9686r9687
10381044
10391045//removed   cbm_drive_0_config (SERIAL, 10);
10401046//removed   cbm_drive_1_config (SERIAL, 11);
1041   c64_vicaddr = c64_memory;
1047   state->vicaddr = state->memory;
10421048
10431049   state->c64mode = 0;
10441050
src/mess/machine/c128.c
r9686r9687
336336
337337   cbm_iec_atn_w(serbus, device, !BIT(data, 3));
338338
339   c64_vicaddr = c64_memory + helper[data & 0x03];
340   c128_vicaddr = c64_memory + helper[data & 0x03] + state->va1617;
339   state->vicaddr = state->memory + helper[data & 0x03];
340   state->c128_vicaddr = state->memory + helper[data & 0x03] + state->va1617;
341341}
342342
343343static void c128_cia1_interrupt( running_device *device, int level )
r9686r9687
401401   if (!state->write_io)
402402   {
403403      if (offset + 0xd000 >= state->ram_top)
404         c64_memory[0xd000 + offset] = data;
404         state->memory[0xd000 + offset] = data;
405405      else
406406         state->ram[0xd000 + offset] = data;
407407   }
r9686r9687
423423         break;
424424      case 8: case 9: case 0xa: case 0xb:
425425          if (state->c64mode)
426            c64_colorram[(offset & 0x3ff)] = data | 0xf0;
426            state->colorram[(offset & 0x3ff)] = data | 0xf0;
427427          else
428            c64_colorram[(offset & 0x3ff)|((c64_port6510&3)<<10)] = data | 0xf0; // maybe all 8 bit connected!
428            state->colorram[(offset & 0x3ff)|((c64_port6510&3)<<10)] = data | 0xf0; // maybe all 8 bit connected!
429429          break;
430430      case 0xc:
431431         mos6526_w(cia_0, offset, data);
r9686r9687
447447
448448static READ8_HANDLER( c128_read_io )
449449{
450   c128_state *state = space->machine->driver_data<c128_state>();
450451   running_device *cia_0 = space->machine->device("cia_0");
451452   running_device *cia_1 = space->machine->device("cia_1");
452453   running_device *sid = space->machine->device("sid6581");
r9686r9687
462463   else if (offset < 0x800)
463464      return vdc8563_port_r(vdc8563, offset & 0xff);
464465   else if (offset < 0xc00)
465      return c64_colorram[offset & 0x3ff];
466      return state->colorram[offset & 0x3ff];
466467   else if (offset == 0xc00)
467468      {
468469         cia_set_port_mask_value(cia_0, 0, input_port_read(space->machine, "CTRLSEL") & 0x80 ? c64_keyline[8] : c64_keyline[9] );
r9686r9687
492493      return;
493494
494495   data = m6510_get_port(machine->device<legacy_cpu_device>("m8502")) & 0x07;
495   if ((state->old_data == data) && (state->old_exrom == c64_exrom) && (state->old_game == c64_game) && !reset)
496   if ((state->old_data == data) && (state->old_exrom == state->exrom) && (state->old_game == state->game) && !reset)
496497      return;
497498
498499   DBG_LOG(machine, 1, "bankswitch", ("%d\n", data & 7));
r9686r9687
500501   hiram = (data & 2) ? 1 : 0;
501502   charen = (data & 4) ? 1 : 0;
502503
503   if ((!c64_game && c64_exrom) || (loram && hiram && !c64_exrom))
504      memory_set_bankptr(machine, "bank8", c64_roml);
504   if ((!state->game && state->exrom) || (loram && hiram && !state->exrom))
505      memory_set_bankptr(machine, "bank8", state->roml);
505506   else
506      memory_set_bankptr(machine, "bank8", c64_memory + 0x8000);
507      memory_set_bankptr(machine, "bank8", state->memory + 0x8000);
507508
508   if ((!c64_game && c64_exrom && hiram) || (!c64_exrom))
509      memory_set_bankptr(machine, "bank9", c64_romh);
509   if ((!state->game && state->exrom && hiram) || (!state->exrom))
510      memory_set_bankptr(machine, "bank9", state->romh);
510511   else if (loram && hiram)
511      memory_set_bankptr(machine, "bank9", c64_basic);
512      memory_set_bankptr(machine, "bank9", state->basic);
512513   else
513      memory_set_bankptr(machine, "bank9", c64_memory + 0xa000);
514      memory_set_bankptr(machine, "bank9", state->memory + 0xa000);
514515
515   if ((!c64_game && c64_exrom) || (charen && (loram || hiram)))
516   if ((!state->game && state->exrom) || (charen && (loram || hiram)))
516517   {
517518      memory_install_read8_handler(cpu_get_address_space(machine->device("m8502"), ADDRESS_SPACE_PROGRAM), 0xd000, 0xdfff, 0, 0, c128_read_io);
518519      state->write_io = 1;
r9686r9687
522523      memory_install_read_bank(cpu_get_address_space(machine->device("m8502"), ADDRESS_SPACE_PROGRAM), 0xd000, 0xdfff, 0, 0, "bank5");
523524      state->write_io = 0;
524525      if ((!charen && (loram || hiram)))
525         memory_set_bankptr(machine, "bank13", c64_chargen);
526         memory_set_bankptr(machine, "bank13", state->chargen);
526527      else
527         memory_set_bankptr(machine, "bank13", c64_memory + 0xd000);
528         memory_set_bankptr(machine, "bank13", state->memory + 0xd000);
528529   }
529530
530   if (!c64_game && c64_exrom)
531   if (!state->game && state->exrom)
531532   {
532      memory_set_bankptr(machine, "bank14", c64_romh);
533      memory_set_bankptr(machine, "bank15", c64_romh+0x1f00);
534      memory_set_bankptr(machine, "bank16", c64_romh+0x1f05);
533      memory_set_bankptr(machine, "bank14", state->romh);
534      memory_set_bankptr(machine, "bank15", state->romh+0x1f00);
535      memory_set_bankptr(machine, "bank16", state->romh+0x1f05);
535536   }
536537   else
537538   {
538539      if (hiram)
539540      {
540         memory_set_bankptr(machine, "bank14", c64_kernal);
541         memory_set_bankptr(machine, "bank15", c64_kernal+0x1f00);
542         memory_set_bankptr(machine, "bank16", c64_kernal+0x1f05);
541         memory_set_bankptr(machine, "bank14", state->kernal);
542         memory_set_bankptr(machine, "bank15", state->kernal+0x1f00);
543         memory_set_bankptr(machine, "bank16", state->kernal+0x1f05);
543544      }
544545      else
545546      {
546         memory_set_bankptr(machine, "bank14", c64_memory + 0xe000);
547         memory_set_bankptr(machine, "bank15", c64_memory + 0xff00);
548         memory_set_bankptr(machine, "bank16", c64_memory + 0xff05);
547         memory_set_bankptr(machine, "bank14", state->memory + 0xe000);
548         memory_set_bankptr(machine, "bank15", state->memory + 0xff00);
549         memory_set_bankptr(machine, "bank16", state->memory + 0xff05);
549550      }
550551   }
551552   state->old_data = data;
552   state->old_exrom = c64_exrom;
553   state->old_game =c64_game;
553   state->old_exrom = state->exrom;
554   state->old_game =state->game;
554555}
555556
556557/* typical z80 configuration
r9686r9687
558559static void c128_bankswitch_z80( running_machine *machine )
559560{
560561   c128_state *state = machine->driver_data<c128_state>();
561    state->ram = c64_memory + MMU_RAM_ADDR;
562    state->ram = state->memory + MMU_RAM_ADDR;
562563    state->va1617 = MMU_VIC_ADDR;
563564#if 1
564565    memory_set_bankptr(machine, "bank10", state->z80);
r9686r9687
578579    }
579580    else
580581    {
581       memory_set_bankptr(machine, "bank10", (state->ram_bottom > 0 ? c64_memory : state->ram));
582       memory_set_bankptr(machine, "bank11", (state->ram_bottom > 0x400 ? c64_memory : state->ram) + 0x400);
582       memory_set_bankptr(machine, "bank10", (state->ram_bottom > 0 ? state->memory : state->ram));
583       memory_set_bankptr(machine, "bank11", (state->ram_bottom > 0x400 ? state->memory : state->ram) + 0x400);
583584    }
584585
585    memory_set_bankptr(machine, "bank1", (state->ram_bottom > 0 ? c64_memory : state->ram));
586    memory_set_bankptr(machine, "bank2", (state->ram_bottom > 0x400 ? c64_memory : state->ram) + 0x400);
586    memory_set_bankptr(machine, "bank1", (state->ram_bottom > 0 ? state->memory : state->ram));
587    memory_set_bankptr(machine, "bank2", (state->ram_bottom > 0x400 ? state->memory : state->ram) + 0x400);
587588
588    memory_set_bankptr(machine, "bank3", (state->ram_bottom > 0x1000 ? c64_memory : state->ram) + 0x1000);
589    memory_set_bankptr(machine, "bank4", (state->ram_bottom > 0x2000 ? c64_memory : state->ram) + 0x2000);
589    memory_set_bankptr(machine, "bank3", (state->ram_bottom > 0x1000 ? state->memory : state->ram) + 0x1000);
590    memory_set_bankptr(machine, "bank4", (state->ram_bottom > 0x2000 ? state->memory : state->ram) + 0x2000);
590591    memory_set_bankptr(machine, "bank5", state->ram + 0x4000);
591592
592593    if (MMU_TOP)
r9686r9687
597598    if (state->ram_top > 0xc000)
598599      memory_set_bankptr(machine, "bank6", state->ram + 0xc000);
599600    else
600      memory_set_bankptr(machine, "bank6", c64_memory + 0xc000);
601      memory_set_bankptr(machine, "bank6", state->memory + 0xc000);
601602
602603    if (state->ram_top > 0xe000)
603604      memory_set_bankptr(machine, "bank7", state->ram + 0xe000);
604605    else
605      memory_set_bankptr(machine, "bank7", c64_memory + 0xd000);
606      memory_set_bankptr(machine, "bank7", state->memory + 0xd000);
606607
607608    if (state->ram_top > 0xf000)
608609      memory_set_bankptr(machine, "bank8", state->ram + 0xf000);
609610    else
610      memory_set_bankptr(machine, "bank8", c64_memory + 0xe000);
611      memory_set_bankptr(machine, "bank8", state->memory + 0xe000);
611612
612613    if (state->ram_top > 0xff05)
613614      memory_set_bankptr(machine, "bank9", state->ram + 0xff05);
614615    else
615      memory_set_bankptr(machine, "bank9", c64_memory + 0xff05);
616      memory_set_bankptr(machine, "bank9", state->memory + 0xff05);
616617
617618    if ( (( (input_port_read(machine, "SPECIAL") & 0x06) == 0x02 ) && (MMU_RAM_ADDR >= 0x40000))
618619        || (( (input_port_read(machine, "SPECIAL") & 0x06) == 0x00) && (MMU_RAM_ADDR >= 0x20000)) )
r9686r9687
627628   if (state->c64mode)
628629   {
629630      /* mmu works also in c64 mode, but this can wait */
630      state->ram = c64_memory;
631      state->ram = state->memory;
631632      state->va1617 = 0;
632633      state->ram_bottom = 0;
633634      state->ram_top = 0x10000;
634635
635      memory_set_bankptr(machine, "bank1", c64_memory);
636      memory_set_bankptr(machine, "bank2", c64_memory + 0x100);
636      memory_set_bankptr(machine, "bank1", state->memory);
637      memory_set_bankptr(machine, "bank2", state->memory + 0x100);
637638
638      memory_set_bankptr(machine, "bank3", c64_memory + 0x200);
639      memory_set_bankptr(machine, "bank4", c64_memory + 0x400);
640      memory_set_bankptr(machine, "bank5", c64_memory + 0x1000);
641      memory_set_bankptr(machine, "bank6", c64_memory + 0x2000);
639      memory_set_bankptr(machine, "bank3", state->memory + 0x200);
640      memory_set_bankptr(machine, "bank4", state->memory + 0x400);
641      memory_set_bankptr(machine, "bank5", state->memory + 0x1000);
642      memory_set_bankptr(machine, "bank6", state->memory + 0x2000);
642643
643      memory_set_bankptr(machine, "bank7", c64_memory + 0x4000);
644      memory_set_bankptr(machine, "bank7", state->memory + 0x4000);
644645
645      memory_set_bankptr(machine, "bank12", c64_memory + 0xc000);
646      memory_set_bankptr(machine, "bank12", state->memory + 0xc000);
646647
647648      c128_bankswitch_64(machine, reset);
648649   }
649650   else
650651   {
651      state->ram = c64_memory + MMU_RAM_ADDR;
652      state->ram = state->memory + MMU_RAM_ADDR;
652653      state->va1617 = MMU_VIC_ADDR;
653      memory_set_bankptr(machine, "bank1", c64_memory + state->mmu_page0);
654      memory_set_bankptr(machine, "bank2", c64_memory + state->mmu_page1);
654      memory_set_bankptr(machine, "bank1", state->memory + state->mmu_page0);
655      memory_set_bankptr(machine, "bank2", state->memory + state->mmu_page1);
655656      if (MMU_BOTTOM)
656657         {
657658            state->ram_bottom = MMU_SIZE;
658659         }
659660      else
660661         state->ram_bottom = 0;
661      memory_set_bankptr(machine, "bank3", (state->ram_bottom > 0x200 ? c64_memory : state->ram) + 0x200);
662      memory_set_bankptr(machine, "bank4", (state->ram_bottom > 0x400 ? c64_memory : state->ram) + 0x400);
663      memory_set_bankptr(machine, "bank5", (state->ram_bottom > 0x1000 ? c64_memory : state->ram) + 0x1000);
664      memory_set_bankptr(machine, "bank6", (state->ram_bottom > 0x2000 ? c64_memory : state->ram) + 0x2000);
662      memory_set_bankptr(machine, "bank3", (state->ram_bottom > 0x200 ? state->memory : state->ram) + 0x200);
663      memory_set_bankptr(machine, "bank4", (state->ram_bottom > 0x400 ? state->memory : state->ram) + 0x400);
664      memory_set_bankptr(machine, "bank5", (state->ram_bottom > 0x1000 ? state->memory : state->ram) + 0x1000);
665      memory_set_bankptr(machine, "bank6", (state->ram_bottom > 0x2000 ? state->memory : state->ram) + 0x2000);
665666
666667      if (MMU_RAM_LO)
667668      {
r9686r9687
669670      }
670671      else
671672      {
672         memory_set_bankptr(machine, "bank7", state->basic);
673         memory_set_bankptr(machine, "bank7", state->c128_basic);
673674      }
674675
675676      if (MMU_RAM_MID)
r9686r9687
679680      }
680681      else if (MMU_ROM_MID)
681682      {
682         memory_set_bankptr(machine, "bank8", state->basic + 0x4000);
683         memory_set_bankptr(machine, "bank9", state->basic + 0x6000);
683         memory_set_bankptr(machine, "bank8", state->c128_basic + 0x4000);
684         memory_set_bankptr(machine, "bank9", state->c128_basic + 0x6000);
684685      }
685686      else if (MMU_INTERNAL_ROM_MID)
686687      {
r9686r9687
722723         }
723724         else
724725         {
725            memory_set_bankptr(machine, "bank12", c64_memory + 0xc000);
726            memory_set_bankptr(machine, "bank12", state->memory + 0xc000);
726727         }
727728         if (!MMU_IO_ON)
728729         {
r9686r9687
732733            }
733734            else
734735            {
735               memory_set_bankptr(machine, "bank13", c64_memory + 0xd000);
736               memory_set_bankptr(machine, "bank13", state->memory + 0xd000);
736737            }
737738         }
738739         if (state->ram_top > 0xe000)
r9686r9687
741742         }
742743         else
743744         {
744            memory_set_bankptr(machine, "bank14", c64_memory + 0xe000);
745            memory_set_bankptr(machine, "bank14", state->memory + 0xe000);
745746         }
746747         if (state->ram_top > 0xff05)
747748         {
r9686r9687
749750         }
750751         else
751752         {
752            memory_set_bankptr(machine, "bank16", c64_memory + 0xff05);
753            memory_set_bankptr(machine, "bank16", state->memory + 0xff05);
753754         }
754755      }
755756      else if (MMU_ROM_HI)
756757      {
757758         memory_set_bankptr(machine, "bank12", state->editor);
758759         if (!MMU_IO_ON) {
759            memory_set_bankptr(machine, "bank13", state->chargen);
760            memory_set_bankptr(machine, "bank13", state->c128_chargen);
760761         }
761         memory_set_bankptr(machine, "bank14", state->kernal);
762         memory_set_bankptr(machine, "bank16", state->kernal + 0x1f05);
762         memory_set_bankptr(machine, "bank14", state->c128_kernal);
763         memory_set_bankptr(machine, "bank16", state->c128_kernal + 0x1f05);
763764      }
764765      else if (MMU_INTERNAL_ROM_HI)
765766      {
r9686r9687
903904      data = state->mmu[offset] | 6;
904905      if ( /*disk enable signal */ 0)
905906         data &= ~8;
906      if (!c64_game)
907      if (!state->game)
907908         data &= ~0x10;
908      if (!c64_exrom)
909      if (!state->exrom)
909910         data &= ~0x20;
910911      if (input_port_read(space->machine, "SPECIAL") & 0x10)
911912         data &= ~0x80;
r9686r9687
10061007{
10071008   c128_state *state = space->machine->driver_data<c128_state>();
10081009   if (offset + 0xe000 >= state->ram_top)
1009      c64_memory[0xe000 + offset] = data;
1010      state->memory[0xe000 + offset] = data;
10101011   else if (state->ram != NULL)
10111012      state->ram[0xe000 + offset] = data;
10121013}
r9686r9687
10171018   if (!state->c64mode)
10181019      c128_mmu8722_ff00_w(space, offset, data);
10191020   else if (state->ram!=NULL)
1020      c64_memory[0xff00 + offset] = data;
1021      state->memory[0xff00 + offset] = data;
10211022}
10221023
10231024WRITE8_HANDLER( c128_write_ff05 )
10241025{
10251026   c128_state *state = space->machine->driver_data<c128_state>();
10261027   if (offset + 0xff05 >= state->ram_top)
1027      c64_memory[0xff05 + offset] = data;
1028      state->memory[0xff05 + offset] = data;
10281029   else if (state->ram!=NULL)
10291030      state->ram[0xff05 + offset] = data;
10301031}
r9686r9687
10421043   /* main memory configuration to include */
10431044   if (state->c64mode)
10441045   {
1045      if (!c64_game && c64_exrom)
1046      if (!state->game && state->exrom)
10461047      {
10471048         if (offset < 0x3000)
1048            return c64_memory[offset];
1049         return c64_romh[offset & 0x1fff];
1049            return state->memory[offset];
1050         return state->romh[offset & 0x1fff];
10501051      }
1051      if (((c64_vicaddr - c64_memory + offset) & 0x7000) == 0x1000)
1052         return c64_chargen[offset & 0xfff];
1053      return c64_vicaddr[offset];
1052      if (((state->vicaddr - state->memory + offset) & 0x7000) == 0x1000)
1053         return state->chargen[offset & 0xfff];
1054      return state->vicaddr[offset];
10541055   }
1055   if (!(c64_port6510 & 4) && (((c128_vicaddr - c64_memory + offset) & 0x7000) == 0x1000))
1056      return state->chargen[offset & 0xfff];
1057   return c128_vicaddr[offset];
1056   if (!(c64_port6510 & 4) && (((state->c128_vicaddr - state->memory + offset) & 0x7000) == 0x1000))
1057      return state->c128_chargen[offset & 0xfff];
1058   return state->c128_vicaddr[offset];
10581059}
10591060
10601061int c128_dma_read_color(running_machine *machine, int offset)
r9686r9687
10631064   UINT8 c64_port6510 = m6510_get_port(machine->device<legacy_cpu_device>("m8502"));
10641065
10651066   if (state->c64mode)
1066      return c64_colorram[offset & 0x3ff] & 0xf;
1067      return state->colorram[offset & 0x3ff] & 0xf;
10671068   else
1068      return c64_colorram[(offset & 0x3ff)|((c64_port6510 & 0x3) << 10)] & 0xf;
1069      return state->colorram[(offset & 0x3ff)|((c64_port6510 & 0x3) << 10)] & 0xf;
10691070}
10701071
10711072/* 2008-09-01
r9686r9687
10931094
10941095   state->c64_port_data = data;
10951096
1096   if (c64_tape_on)
1097   if (state->tape_on)
10971098   {
10981099      if (direction & 0x08)
10991100      {
r9686r9687
11171118
11181119   c128_bankswitch_64(device->machine, 0);
11191120
1120   c64_memory[0x000] = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM)->read_byte(0);
1121   c64_memory[0x001] = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM)->read_byte(1);
1121   state->memory[0x000] = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM)->read_byte(0);
1122   state->memory[0x001] = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM)->read_byte(1);
11221123
11231124}
11241125
r9686r9687
11471148   UINT8 *ram = memory_region(machine, "maincpu");
11481149   int i;
11491150
1150   c64_memory = ram;
1151   state->memory = ram;
11511152
1152   state->basic = ram + 0x100000;
1153   c64_basic = ram + 0x108000;
1154   c64_kernal = ram + 0x10a000;
1153   state->c128_basic = ram + 0x100000;
1154   state->basic = ram + 0x108000;
1155   state->kernal = ram + 0x10a000;
11551156   state->editor = ram + 0x10c000;
11561157   state->z80 = ram + 0x10d000;
1157   state->kernal = ram + 0x10e000;
1158   state->c128_kernal = ram + 0x10e000;
11581159   state->internal_function = ram + 0x110000;
11591160   state->external_function = ram + 0x118000;
1160   c64_chargen = ram + 0x120000;
1161   state->chargen = ram + 0x121000;
1162   c64_colorram = ram + 0x122000;
1161   state->chargen = ram + 0x120000;
1162   state->c128_chargen = ram + 0x121000;
1163   state->colorram = ram + 0x122000;
11631164   state->vdcram = ram + 0x122800;
11641165
1165   c64_tape_on = 1;
1166   c64_game = 1;
1167   c64_exrom = 1;
1168   c64_pal = 0;
1166   state->tape_on = 1;
1167   state->game = 1;
1168   state->exrom = 1;
1169   state->pal = 0;
11691170   state->c64mode = 0;
1170   state->cia1_on = 1;
11711171   state->vicirq = 0;
11721172
11731173   state->monitor = -1;
r9686r9687
11791179   for (i = 0; i < 0x100; i++)
11801180      gfx[i] = i;
11811181
1182   if (c64_tape_on)
1182   if (state->tape_on)
11831183      state->datasette_timer = timer_alloc(machine, c64_tape_timer, NULL);
11841184}
11851185
r9686r9687
11961196
11971197DRIVER_INIT( c128pal )
11981198{
1199   c128_state *state = machine->driver_data<c128_state>();
11991200   running_device *vic2e = machine->device("vic2e");
12001201   running_device *vdc8563 = machine->device("vdc8563");
12011202
12021203   c128_common_driver_init(machine);
1203   c64_pal = 1;
1204   state->pal = 1;
12041205
12051206   vic2_set_rastering(vic2e, 1);
12061207   vdc8563_set_rastering(vdc8563, 0);
r9686r9687
12431244MACHINE_RESET( c128 )
12441245{
12451246   c128_state *state = machine->driver_data<c128_state>();
1246   c128_vicaddr = c64_vicaddr = c64_memory;
1247   state->c128_vicaddr = state->vicaddr = state->memory;
12471248   state->c64mode = 0;
12481249   c128_mmu8722_reset(machine);
12491250   cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, CLEAR_LINE);
r9686r9687
12731274      {
12741275         vic2_set_rastering(vic2e, 1);
12751276         vdc8563_set_rastering(vdc8563, 0);
1276         if (c64_pal)
1277         if (state->pal)
12771278            device->machine->primary_screen->set_visible_area(0, VIC6569_VISIBLECOLUMNS - 1, 0, VIC6569_VISIBLELINES - 1);
12781279         else
12791280            device->machine->primary_screen->set_visible_area(0, VIC6567_VISIBLECOLUMNS - 1, 0, VIC6567_VISIBLELINES - 1);
src/mess/machine/c64.c
r9686r9687
4242#define log_cart 0
4343
4444/* expansion port lines input */
45int c64_pal;
46UINT8 c64_game, c64_exrom;
4745
4846/* cpu port */
49UINT8 *c64_vicaddr, *c128_vicaddr;
50UINT8 *c64_memory;
51UINT8 *c64_colorram;
52UINT8 *c64_basic;
53UINT8 *c64_kernal;
54UINT8 *c64_chargen;
55UINT8 *c64_roml = 0;
56UINT8 *c64_romh = 0;
57static UINT8 *c64_io_mirror = NULL;
5847
59static UINT8 c64_port_data;
6048
61static UINT8 *roml = 0, *romh = 0;
62static int ultimax;
63int c64_tape_on;
64static int c64_cia1_on;
65static int c64_io_enabled;
66static int is_sx64;            // temporary workaround until we implement full vc1541 emulation for every c64 set
6749
68static UINT8 vicirq;
69static int old_level;
70static int old_data, old_exrom, old_game;
71
7250static void c64_nmi( running_machine *machine )
7351{
7452   static int nmilevel = 0;
r9686r9687
122100
123101static void c64_irq( running_machine *machine, int level )
124102{
125   if (level != old_level)
103   c64_state *state = machine->driver_data<c64_state>();
104   if (level != state->old_level)
126105   {
127106      DBG_LOG(machine, 3, "mos6510", ("irq %s\n", level ? "start" : "end"));
128107      cputag_set_input_line(machine, "maincpu", M6510_IRQ_LINE, level);
129      old_level = level;
108      state->old_level = level;
130109   }
131110}
132111
133112static void c64_cia0_interrupt( running_device *device, int level )
134113{
135   c64_irq (device->machine, level || vicirq);
114   c64_state *state = device->machine->driver_data<c64_state>();
115   c64_irq (device->machine, level || state->vicirq);
136116}
137117
138118void c64_vic_interrupt( running_machine *machine, int level )
139119{
120   c64_state *state = machine->driver_data<c64_state>();
140121   running_device *cia_0 = machine->device("cia_0");
141122#if 1
142   if (level != vicirq)
123   if (level != state->vicirq)
143124   {
144125      c64_irq(machine, level || mos6526_irq_r(cia_0));
145      vicirq = level;
126      state->vicirq = level;
146127   }
147128#endif
148129}
r9686r9687
213194
214195static WRITE8_DEVICE_HANDLER( c64_cia1_port_a_w )
215196{
197   c64_state *state = device->machine->driver_data<c64_state>();
216198   static const int helper[4] = {0xc000, 0x8000, 0x4000, 0x0000};
217199   running_device *serbus = device->machine->device("iec");
218200
219201   cbm_iec_clk_w(serbus, device, !(data & 0x10));
220202   cbm_iec_data_w(serbus, device, !(data & 0x20));
221203   cbm_iec_atn_w(serbus, device, !(data & 0x08));
222   c64_vicaddr = c64_memory + helper[data & 0x03];
204   state->vicaddr = state->memory + helper[data & 0x03];
223205}
224206
225207static void c64_cia1_interrupt( running_device *device, int level )
r9686r9687
259241
260242***********************************************/
261243
262static UINT8 *c64_io_ram_w_ptr;
263static UINT8 *c64_io_ram_r_ptr;
264244
265245WRITE8_HANDLER( c64_write_io )
266246{
247   c64_state *state = space->machine->driver_data<c64_state>();
267248   running_device *cia_0 = space->machine->device("cia_0");
268249   running_device *cia_1 = space->machine->device("cia_1");
269250   running_device *sid = space->machine->device("sid6581");
270251   running_device *vic2 = space->machine->device("vic2");
271252
272   c64_io_mirror[offset] = data;
253   state->io_mirror[offset] = data;
273254   if (offset < 0x400)
274255      vic2_port_w(vic2, offset & 0x3ff, data);
275256   else if (offset < 0x800)
276257      sid6581_w(sid, offset & 0x3ff, data);
277258   else if (offset < 0xc00)
278      c64_colorram[offset & 0x3ff] = data | 0xf0;
259      state->colorram[offset & 0x3ff] = data | 0xf0;
279260   else if (offset < 0xd00)
280261      mos6526_w(cia_0, offset, data);
281262   else if (offset < 0xe00)
282263   {
283      if (c64_cia1_on)
264      if (state->cia1_on)
284265         mos6526_w(cia_1, offset, data);
285266      else
286267         DBG_LOG(space->machine, 1, "io write", ("%.3x %.2x\n", offset, data));
r9686r9687
293274
294275WRITE8_HANDLER( c64_ioarea_w )
295276{
296   if (c64_io_enabled)
277   c64_state *state = space->machine->driver_data<c64_state>();
278   if (state->io_enabled)
297279      c64_write_io(space, offset, data);
298280   else
299      c64_io_ram_w_ptr[offset] = data;
281      state->io_ram_w_ptr[offset] = data;
300282}
301283
302284READ8_HANDLER( c64_read_io )
303285{
286   c64_state *state = space->machine->driver_data<c64_state>();
304287   running_device *cia_0 = space->machine->device("cia_0");
305288   running_device *cia_1 = space->machine->device("cia_1");
306289   running_device *sid = space->machine->device("sid6581");
r9686r9687
313296      return sid6581_r(sid, offset & 0x3ff);
314297
315298   else if (offset < 0xc00)
316      return c64_colorram[offset & 0x3ff];
299      return state->colorram[offset & 0x3ff];
317300
318301   else if (offset < 0xd00)
319302      {
r9686r9687
325308         return mos6526_r(cia_0, offset);
326309      }
327310
328   else if (c64_cia1_on && (offset < 0xe00))
311   else if (state->cia1_on && (offset < 0xe00))
329312      return mos6526_r(cia_1, offset);
330313
331314   DBG_LOG(space->machine, 1, "io read", ("%.3x\n", offset));
r9686r9687
335318
336319READ8_HANDLER( c64_ioarea_r )
337320{
338   return c64_io_enabled ? c64_read_io(space, offset) : c64_io_ram_r_ptr[offset];
321   c64_state *state = space->machine->driver_data<c64_state>();
322   return state->io_enabled ? c64_read_io(space, offset) : state->io_ram_r_ptr[offset];
339323}
340324
341325
r9686r9687
454438
455439static void c64_bankswitch( running_machine *machine, int reset )
456440{
441   c64_state *state = machine->driver_data<c64_state>();
457442   int loram, hiram, charen;
458443   int ultimax_mode = 0;
459444   int data = m6510_get_port(machine->device<legacy_cpu_device>("maincpu")) & 0x07;
460445
461446   /* If nothing has changed or reset = 0, don't do anything */
462   if ((old_data == data) && (old_exrom == c64_exrom) && (old_game == c64_game) && !reset)
447   if ((state->old_data == data) && (state->old_exrom == state->exrom) && (state->old_game == state->game) && !reset)
463448      return;
464449
465450   /* Are we in Ultimax mode? */
466   if (!c64_game && c64_exrom)
451   if (!state->game && state->exrom)
467452      ultimax_mode = 1;
468453
469454   DBG_LOG(machine, 1, "bankswitch", ("%d\n", data & 7));
470455   loram  = (data & 1) ? 1 : 0;
471456   hiram  = (data & 2) ? 1 : 0;
472457   charen = (data & 4) ? 1 : 0;
473   logerror("Bankswitch mode || charen, ultimax\n");
474   logerror("%d, %d, %d, %d  ||   %d,      %d  \n", loram, hiram, c64_game, c64_exrom, charen, ultimax_mode);
458   logerror("Bankswitch mode || charen, state->ultimax\n");
459   logerror("%d, %d, %d, %d  ||   %d,      %d  \n", loram, hiram, state->game, state->exrom, charen, ultimax_mode);
475460
476461   if (ultimax_mode)
477462   {
478         c64_io_enabled = 1;      // charen has no effect in ultimax_mode
463         state->io_enabled = 1;      // charen has no effect in ultimax_mode
479464
480         memory_set_bankptr(machine, "bank1", roml);
481         memory_set_bankptr(machine, "bank2", c64_memory + 0x8000);
482         memory_set_bankptr(machine, "bank3", c64_memory + 0xa000);
483         memory_set_bankptr(machine, "bank4", romh);
465         memory_set_bankptr(machine, "bank1", state->roml);
466         memory_set_bankptr(machine, "bank2", state->memory + 0x8000);
467         memory_set_bankptr(machine, "bank3", state->memory + 0xa000);
468         memory_set_bankptr(machine, "bank4", state->romh);
484469         memory_nop_write(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xe000, 0xffff, 0, 0);
485470   }
486471   else
487472   {
488473      /* 0x8000-0x9000 */
489      if (loram && hiram && !c64_exrom)
474      if (loram && hiram && !state->exrom)
490475      {
491         memory_set_bankptr(machine, "bank1", roml);
492         memory_set_bankptr(machine, "bank2", c64_memory + 0x8000);
476         memory_set_bankptr(machine, "bank1", state->roml);
477         memory_set_bankptr(machine, "bank2", state->memory + 0x8000);
493478      }
494479      else
495480      {
496         memory_set_bankptr(machine, "bank1", c64_memory + 0x8000);
497         memory_set_bankptr(machine, "bank2", c64_memory + 0x8000);
481         memory_set_bankptr(machine, "bank1", state->memory + 0x8000);
482         memory_set_bankptr(machine, "bank2", state->memory + 0x8000);
498483      }
499484
500485      /* 0xa000 */
501      if (hiram && !c64_game && !c64_exrom)
502         memory_set_bankptr(machine, "bank3", romh);
486      if (hiram && !state->game && !state->exrom)
487         memory_set_bankptr(machine, "bank3", state->romh);
503488
504      else if (loram && hiram && c64_game)
505         memory_set_bankptr(machine, "bank3", c64_basic);
489      else if (loram && hiram && state->game)
490         memory_set_bankptr(machine, "bank3", state->basic);
506491
507492      else
508         memory_set_bankptr(machine, "bank3", c64_memory + 0xa000);
493         memory_set_bankptr(machine, "bank3", state->memory + 0xa000);
509494
510495      /* 0xd000 */
511496      // RAM
512      if (!loram && !hiram && (c64_game || !c64_exrom))
497      if (!loram && !hiram && (state->game || !state->exrom))
513498      {
514         c64_io_enabled = 0;
515         c64_io_ram_r_ptr = c64_memory + 0xd000;
516         c64_io_ram_w_ptr = c64_memory + 0xd000;
499         state->io_enabled = 0;
500         state->io_ram_r_ptr = state->memory + 0xd000;
501         state->io_ram_w_ptr = state->memory + 0xd000;
517502      }
518503      // IO/RAM
519      else if (loram && !hiram && !c64_game)   // remember we cannot be in ultimax_mode, no need of !c64_exrom
504      else if (loram && !hiram && !state->game)   // remember we cannot be in ultimax_mode, no need of !state->exrom
520505      {
521         c64_io_enabled = 1;
522         c64_io_ram_r_ptr = (!charen) ? c64_chargen : c64_memory + 0xd000;
523         c64_io_ram_w_ptr = c64_memory + 0xd000;
506         state->io_enabled = 1;
507         state->io_ram_r_ptr = (!charen) ? state->chargen : state->memory + 0xd000;
508         state->io_ram_w_ptr = state->memory + 0xd000;
524509      }
525510      // IO/C
526511      else
527512      {
528         c64_io_enabled = charen ? 1 : 0;
513         state->io_enabled = charen ? 1 : 0;
529514
530515         if (!charen)
531516         {
532         c64_io_ram_r_ptr = c64_chargen;
533         c64_io_ram_w_ptr = c64_memory + 0xd000;
517         state->io_ram_r_ptr = state->chargen;
518         state->io_ram_w_ptr = state->memory + 0xd000;
534519         }
535520      }
536521
537522      /* 0xe000-0xf000 */
538      memory_set_bankptr(machine, "bank4", hiram ? c64_kernal : c64_memory + 0xe000);
539      memory_set_bankptr(machine, "bank5", c64_memory + 0xe000);
523      memory_set_bankptr(machine, "bank4", hiram ? state->kernal : state->memory + 0xe000);
524      memory_set_bankptr(machine, "bank5", state->memory + 0xe000);
540525   }
541526
542527   /* make sure the opbase function gets called each time */
543528   /* NPW 15-May-2008 - Another hack in the C64 drivers broken! */
544529   /* opbase->mem_max = 0xcfff; */
545530
546   old_game = c64_game;
547   old_exrom = c64_exrom;
548   old_data = data;
531   state->old_game = state->game;
532   state->old_exrom = state->exrom;
533   state->old_data = data;
549534}
550535
551536/**
r9686r9687
561546  p6,7 not available on M6510
562547 */
563548
564static emu_timer *datasette_timer;
565
566549void c64_m6510_port_write( running_device *device, UINT8 direction, UINT8 data )
567550{
551   c64_state *state = device->machine->driver_data<c64_state>();
552
568553   /* if line is marked as input then keep current value */
569   data = (c64_port_data & ~direction) | (data & direction);
554   data = (state->port_data & ~direction) | (data & direction);
570555
571556   /* resistors make P0,P1,P2 go high when respective line is changed to input */
572557   if (!(direction & 0x04))
r9686r9687
578563   if (!(direction & 0x01))
579564      data |= 0x01;
580565
581   c64_port_data = data;
566   state->port_data = data;
582567
583   if (c64_tape_on)
568   if (state->tape_on)
584569   {
585570      if (direction & 0x08)
586571      {
r9686r9687
592577         if(!(data & 0x20))
593578         {
594579            cassette_change_state(device->machine->device("cassette"), CASSETTE_MOTOR_ENABLED, CASSETTE_MASK_MOTOR);
595            timer_adjust_periodic(datasette_timer, attotime_zero, 0, ATTOTIME_IN_HZ(44100));
580            timer_adjust_periodic(state->datasette_timer, attotime_zero, 0, ATTOTIME_IN_HZ(44100));
596581         }
597582         else
598583         {
599584            cassette_change_state(device->machine->device("cassette"), CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR);
600            timer_reset(datasette_timer, attotime_never);
585            timer_reset(state->datasette_timer, attotime_never);
601586         }
602587      }
603588   }
604589
605   if (!ultimax)
590   if (!state->ultimax)
606591      c64_bankswitch(device->machine, 0);
607592
608   c64_memory[0x000] = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM)->read_byte(0);
609   c64_memory[0x001] = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM)->read_byte(1);
593   state->memory[0x000] = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM)->read_byte(0);
594   state->memory[0x001] = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM)->read_byte(1);
610595
611596}
612597
613598UINT8 c64_m6510_port_read( running_device *device, UINT8 direction )
614599{
615   UINT8 data = c64_port_data;
600   c64_state *state = device->machine->driver_data<c64_state>();
601   UINT8 data = state->port_data;
616602
617   if (c64_tape_on)
603   if (state->tape_on)
618604   {
619605      if ((cassette_get_state(device->machine->device("cassette")) & CASSETTE_MASK_UISTATE) != CASSETTE_STOPPED)
620606         data &= ~0x10;
r9686r9687
742728
743729READ8_HANDLER( c64_colorram_read )
744730{
745   return c64_colorram[offset & 0x3ff];
731   c64_state *state = space->machine->driver_data<c64_state>();
732   return state->colorram[offset & 0x3ff];
746733}
747734
748735WRITE8_HANDLER( c64_colorram_write )
749736{
750   c64_colorram[offset & 0x3ff] = data | 0xf0;
737   c64_state *state = space->machine->driver_data<c64_state>();
738   state->colorram[offset & 0x3ff] = data | 0xf0;
751739}
752740
753741TIMER_CALLBACK( c64_tape_timer )
r9686r9687
760748
761749static void c64_common_driver_init( running_machine *machine )
762750{
751   c64_state *state = machine->driver_data<c64_state>();
763752   cbm_common_init();
764   c64_game = 1;
765   c64_exrom = 1;
766   old_data = -1;
753   state->game = 1;
754   state->exrom = 1;
755   state->old_data = -1;
767756
768   if (!ultimax)
757   if (!state->ultimax)
769758   {
770759      UINT8 *mem = memory_region(machine, "maincpu");
771      c64_basic    = mem + 0x10000;
772      c64_kernal   = mem + 0x12000;
773      c64_chargen  = mem + 0x14000;
774      c64_colorram = mem + 0x15000;
775      c64_roml     = mem + 0x15400;
776      c64_romh     = mem + 0x17400;
760      state->basic    = mem + 0x10000;
761      state->kernal   = mem + 0x12000;
762      state->chargen  = mem + 0x14000;
763      state->colorram = mem + 0x15000;
764      state->c64_roml     = mem + 0x15400;
765      state->c64_romh     = mem + 0x17400;
777766   }
778767
779   if (c64_tape_on)
780      datasette_timer = timer_alloc(machine, c64_tape_timer, NULL);
768   if (state->tape_on)
769      state->datasette_timer = timer_alloc(machine, c64_tape_timer, NULL);
781770
782771   // "cyberload" tape loader check the e000-ffff ram; the init ram need to return different value
783772   {
784773      int i;
785774      for (i = 0; i < 0x2000; i += 0x40)
786         memset(c64_memory + (0xe000 + i), ((i & 0x40) >> 6) * 0xff, 0x40);
775         memset(state->memory + (0xe000 + i), ((i & 0x40) >> 6) * 0xff, 0x40);
787776   }
788777}
789778
790779DRIVER_INIT( c64 )
791780{
792   ultimax = 0;
793   is_sx64 = 0;
794   c64_pal = 0;
795   c64_cia1_on = 1;
796   c64_tape_on = 1;
781   c64_state *state = machine->driver_data<c64_state>();
782   state->ultimax = 0;
783   state->is_sx64 = 0;
784   state->pal = 0;
785   state->cia1_on = 1;
786   state->tape_on = 1;
797787   c64_common_driver_init(machine);
798788}
799789
800790DRIVER_INIT( c64pal )
801791{
802   ultimax = 0;
803   is_sx64 = 0;
804   c64_pal = 1;
805   c64_cia1_on = 1;
806   c64_tape_on = 1;
792   c64_state *state = machine->driver_data<c64_state>();
793   state->ultimax = 0;
794   state->is_sx64 = 0;
795   state->pal = 1;
796   state->cia1_on = 1;
797   state->tape_on = 1;
807798   c64_common_driver_init(machine);
808799}
809800
810801DRIVER_INIT( ultimax )
811802{
812   ultimax = 1;
813   is_sx64 = 0;
814   c64_pal = 0;
815   c64_cia1_on = 0;
816   c64_tape_on = 1;
803   c64_state *state = machine->driver_data<c64_state>();
804   state->ultimax = 1;
805   state->is_sx64 = 0;
806   state->pal = 0;
807   state->cia1_on = 0;
808   state->tape_on = 1;
817809   c64_common_driver_init(machine);
818810}
819811
820812DRIVER_INIT( c64gs )
821813{
822   ultimax = 0;
823   is_sx64 = 0;
824   c64_pal = 1;
825   c64_cia1_on = 1;
826   c64_tape_on = 0;
814   c64_state *state = machine->driver_data<c64_state>();
815   state->ultimax = 0;
816   state->is_sx64 = 0;
817   state->pal = 1;
818   state->cia1_on = 1;
819   state->tape_on = 0;
827820   c64_common_driver_init(machine);
828821}
829822
830823DRIVER_INIT( sx64 )
831824{
832   ultimax = 0;
833   is_sx64 = 1;
834   c64_pal = 1;
835   c64_cia1_on = 1;
836   c64_tape_on = 0;
825   c64_state *state = machine->driver_data<c64_state>();
826   state->ultimax = 0;
827   state->is_sx64 = 1;
828   state->pal = 1;
829   state->cia1_on = 1;
830   state->tape_on = 0;
837831   c64_common_driver_init(machine);
838832}
839833
840834MACHINE_START( c64 )
841835{
842   c64_port_data = 0x17;
836   c64_state *state = machine->driver_data<c64_state>();
837   state->port_data = 0x17;
843838
844   c64_io_mirror = auto_alloc_array(machine, UINT8, 0x1000);
845   c64_io_enabled = 0;
839   state->io_mirror = auto_alloc_array(machine, UINT8, 0x1000);
840   state->io_enabled = 0;
846841
847   c64_vicaddr = c64_memory;
848   vicirq = 0;
842   state->vicaddr = state->memory;
843   state->vicirq = 0;
849844
850   if (!ultimax)
845   if (!state->ultimax)
851846      c64_bankswitch(machine, 1);
852847}
853848
r9686r9687
994989    *****************************************/
995990};
996991
997#define C64_MAX_ROMBANK 64 // .crt files contain multiple 'CHIPs', i.e. rom banks (of variable size) with headers. Known carts have at most 64 'CHIPs'.
998
999typedef struct {
1000   int addr, size, index, start;
1001} C64_ROM;
1002
1003typedef struct _c64_cart_t c64_cart_t;
1004struct _c64_cart_t {
1005   C64_ROM     bank[C64_MAX_ROMBANK];
1006   INT8        game;
1007   INT8        exrom;
1008   UINT8       mapper;
1009   UINT8       n_banks;
1010};
1011
1012static c64_cart_t c64_cart;
1013
1014992static DEVICE_IMAGE_UNLOAD( c64_cart )
1015993{
994   c64_state *state = image.device().machine->driver_data<c64_state>();
1016995   int i;
1017996
1018997   for (i = 0; i < C64_MAX_ROMBANK; i++)
1019998   {
1020      c64_cart.bank[i].size = 0;
1021      c64_cart.bank[i].addr = 0;
1022      c64_cart.bank[i].index = 0;
1023      c64_cart.bank[i].start = 0;
999      state->cart.bank[i].size = 0;
1000      state->cart.bank[i].addr = 0;
1001      state->cart.bank[i].index = 0;
1002      state->cart.bank[i].start = 0;
10241003   }
10251004}
10261005
10271006
10281007static DEVICE_START( c64_cart )
10291008{
1009   c64_state *state = device->machine->driver_data<c64_state>();
10301010   /* In the first slot we can load a .crt file. In this case we want
10311011        to use game & exrom values from the header, not the default ones. */
1032   c64_cart.game = -1;
1033   c64_cart.exrom = -1;
1034   c64_cart.mapper = GENERIC_CRT;
1035   c64_cart.n_banks = 0;
1012   state->cart.game = -1;
1013   state->cart.exrom = -1;
1014   state->cart.mapper = GENERIC_CRT;
1015   state->cart.n_banks = 0;
10361016}
10371017
10381018static int c64_crt_load( device_image_interface &image )
10391019{
1020   c64_state *state = image.device().machine->driver_data<c64_state>();
10401021   int size = image.length(), test, i = 0, ii;
10411022   int _80_loaded = 0, _90_loaded = 0, a0_loaded = 0, b0_loaded = 0, e0_loaded = 0, f0_loaded = 0;
10421023   const char *filetype = image.filetype();
r9686r9687
10571038      /* 0x16-0x17 is Hardware type */
10581039      image.fseek(0x16, SEEK_SET);
10591040      image.fread(&c64_cart_type, 2);
1060      c64_cart.mapper = BIG_ENDIANIZE_INT16(c64_cart_type);
1041      state->cart.mapper = BIG_ENDIANIZE_INT16(c64_cart_type);
10611042
10621043      /* If it is unsupported cart type, warn the user */
1063      switch (c64_cart.mapper)
1044      switch (state->cart.mapper)
10641045      {
10651046         case SIMONS_BASIC:   /* Type #  4 */
10661047         case OCEAN_1:      /* Type #  5 */
r9686r9687
10741055         case DOMARK:      /* Type # 19 */
10751056         case COMAL_80:      /* Type # 21 */
10761057         case GENERIC_CRT:      /* Type #  0 */
1077            printf("Currently supported cart type (Type %d)\n", c64_cart.mapper);
1058            printf("Currently supported cart type (Type %d)\n", state->cart.mapper);
10781059            break;
10791060
10801061         default:
r9686r9687
10871068         case FINAL_CART_I:   /* Type # 13 */
10881069         case MAGIC_FORMEL:   /* Type # 14 */
10891070         case SUPER_SNAP_5:   /* Type # 20 */
1090            printf("Currently unsupported cart type (Type %d)\n", c64_cart.mapper);
1071            printf("Currently unsupported cart type (Type %d)\n", state->cart.mapper);
10911072            break;
10921073      }
10931074
10941075      /* 0x18 is EXROM */
10951076      image.fseek(0x18, SEEK_SET);
1096      image.fread(&c64_cart.exrom, 1);
1077      image.fread(&state->cart.exrom, 1);
10971078
10981079      /* 0x19 is GAME */
1099      image.fread(&c64_cart.game, 1);
1080      image.fread(&state->cart.game, 1);
11001081
11011082      /* We can pass to the data: it starts from 0x40 */
11021083      image.fseek(0x40, SEEK_SET);
11031084      j = 0x40;
11041085
11051086      logerror("Loading cart %s size:%.4x\n", image.filename(), size);
1106      logerror("Header info: EXROM %d, GAME %d, Cart Type %d \n", c64_cart.exrom, c64_cart.game, c64_cart_type);
1087      logerror("Header info: EXROM %d, GAME %d, Cart Type %d \n", state->cart.exrom, state->cart.game, c64_cart_type);
11071088
11081089
11091090      /* Data in a .crt image are organized in blocks called 'CHIP':
r9686r9687
11461127         logerror("Loading CHIP data at %.4x size:%.4x\n", address, chip_data_size);
11471128
11481129         /* Store data, address & size of the CHIP block */
1149         c64_cart.bank[i].addr = address;
1150         c64_cart.bank[i].index = chip_bank_index;
1151         c64_cart.bank[i].size = chip_data_size;
1152         c64_cart.bank[i].start = new_start;
1130         state->cart.bank[i].addr = address;
1131         state->cart.bank[i].index = chip_bank_index;
1132         state->cart.bank[i].size = chip_data_size;
1133         state->cart.bank[i].start = new_start;
11531134
1154         test = image.fread(cart_cpy + new_start, c64_cart.bank[i].size);
1155         new_start += c64_cart.bank[i].size;
1135         test = image.fread(cart_cpy + new_start, state->cart.bank[i].size);
1136         new_start += state->cart.bank[i].size;
11561137
11571138         /* Does CHIP contain any data? */
1158         if (test != c64_cart.bank[i].size)
1139         if (test != state->cart.bank[i].size)
11591140            return IMAGE_INIT_FAIL;
11601141
11611142         /* Advance to the next CHIP block */
r9686r9687
11781159      logerror("loading %s rom at %.4x size:%.4x\n", image.filename(), address, size);
11791160
11801161      /* Store data, address & size */
1181      c64_cart.bank[0].addr = address;
1182      c64_cart.bank[0].size = size;
1183      c64_cart.bank[0].start = new_start;
1162      state->cart.bank[0].addr = address;
1163      state->cart.bank[0].size = size;
1164      state->cart.bank[0].start = new_start;
11841165
1185      test = image.fread(cart_cpy + new_start, c64_cart.bank[0].size);
1186      new_start += c64_cart.bank[0].size;
1166      test = image.fread(cart_cpy + new_start, state->cart.bank[0].size);
1167      new_start += state->cart.bank[0].size;
11871168
11881169      /* Does cart contain any data? */
1189      if (test != c64_cart.bank[0].size)
1170      if (test != state->cart.bank[0].size)
11901171         return IMAGE_INIT_FAIL;
11911172   }
11921173
1193   c64_cart.n_banks = i; // this is also needed so that we only set mappers if a cart is present!
1174   state->cart.n_banks = i; // this is also needed so that we only set mappers if a cart is present!
11941175
11951176   /* If we load a .crt file, use EXROM & GAME from the header! */
1196   if ((c64_cart.exrom != -1) && (c64_cart.game != -1))
1177   if ((state->cart.exrom != -1) && (state->cart.game != -1))
11971178   {
1198      c64_exrom = c64_cart.exrom;
1199      c64_game  = c64_cart.game;
1179      state->exrom = state->cart.exrom;
1180      state->game  = state->cart.game;
12001181   }
12011182
12021183   /* Finally load the cart */
1203   roml = c64_roml;
1204   romh = c64_romh;
1184   state->roml = state->c64_roml;
1185   state->romh = state->c64_romh;
12051186
1206   memset(roml, 0, 0x2000);
1207   memset(romh, 0, 0x2000);
1187   memset(state->roml, 0, 0x2000);
1188   memset(state->romh, 0, 0x2000);
12081189
1209   switch (c64_cart.mapper)
1190   switch (state->cart.mapper)
12101191   {
12111192   default:
1212      if (!c64_game && c64_exrom && (c64_cart.n_banks == 1))
1193      if (!state->game && state->exrom && (state->cart.n_banks == 1))
12131194      {
1214         memcpy(romh, cart_cpy, 0x2000);
1195         memcpy(state->romh, cart_cpy, 0x2000);
12151196      }
12161197      else
12171198      {
12181199         // we first attempt to load the first 'CHIPs' with address 0x8000-0xb000 and 0xe000-0xf000, otherwise we load the first (or first two) 'CHIPs' of the image
1219         for (ii = 0; ii < c64_cart.n_banks; ii++)
1200         for (ii = 0; ii < state->cart.n_banks; ii++)
12201201         {
1221            if (c64_cart.bank[ii].addr == 0x8000 && !_80_loaded)
1202            if (state->cart.bank[ii].addr == 0x8000 && !_80_loaded)
12221203            {
1223               memcpy(roml, cart_cpy + c64_cart.bank[ii].start, c64_cart.bank[ii].size);
1204               memcpy(state->roml, cart_cpy + state->cart.bank[ii].start, state->cart.bank[ii].size);
12241205               _80_loaded = 1;
1225               if (c64_cart.bank[ii].size > 0x1000)
1206               if (state->cart.bank[ii].size > 0x1000)
12261207                  _90_loaded = 1;
1227               if (c64_cart.bank[ii].size > 0x2000)
1208               if (state->cart.bank[ii].size > 0x2000)
12281209                  a0_loaded = 1;
1229               if (c64_cart.bank[ii].size > 0x3000)
1210               if (state->cart.bank[ii].size > 0x3000)
12301211                  b0_loaded = 1;
12311212//                  printf("addr 0x8000: 80 %d, 90 %d, a0 %d, b0 %d\n", _80_loaded, _90_loaded, a0_loaded, b0_loaded);
12321213            }
12331214
1234            if (c64_cart.bank[ii].addr == 0x9000 && !_90_loaded)
1215            if (state->cart.bank[ii].addr == 0x9000 && !_90_loaded)
12351216            {
1236               memcpy(roml + 0x1000, cart_cpy + c64_cart.bank[ii].start, c64_cart.bank[ii].size);
1217               memcpy(state->roml + 0x1000, cart_cpy + state->cart.bank[ii].start, state->cart.bank[ii].size);
12371218               _90_loaded = 1;
1238               if (c64_cart.bank[ii].size > 0x1000)
1219               if (state->cart.bank[ii].size > 0x1000)
12391220                  a0_loaded = 1;
1240               if (c64_cart.bank[ii].size > 0x2000)
1221               if (state->cart.bank[ii].size > 0x2000)
12411222                  b0_loaded = 1;
12421223//                  printf("addr 0x9000: 80 %d, 90 %d, a0 %d, b0 %d\n", _80_loaded, _90_loaded, a0_loaded, b0_loaded);
12431224            }
12441225
1245            if (c64_cart.bank[ii].addr == 0xa000 && !a0_loaded)
1226            if (state->cart.bank[ii].addr == 0xa000 && !a0_loaded)
12461227            {
1247               memcpy(roml + 0x2000, cart_cpy + c64_cart.bank[ii].start, c64_cart.bank[ii].size);
1228               memcpy(state->roml + 0x2000, cart_cpy + state->cart.bank[ii].start, state->cart.bank[ii].size);
12481229               a0_loaded = 1;
1249               if (c64_cart.bank[ii].size > 0x1000)
1230               if (state->cart.bank[ii].size > 0x1000)
12501231                  b0_loaded = 1;
12511232//                  printf("addr 0xa000: 80 %d, 90 %d, a0 %d, b0 %d\n", _80_loaded, _90_loaded, a0_loaded, b0_loaded);
12521233            }
12531234
1254            if (c64_cart.bank[ii].addr == 0xb000 && !b0_loaded)
1235            if (state->cart.bank[ii].addr == 0xb000 && !b0_loaded)
12551236            {
1256               memcpy(roml + 0x3000, cart_cpy + c64_cart.bank[ii].start, c64_cart.bank[ii].size);
1237               memcpy(state->roml + 0x3000, cart_cpy + state->cart.bank[ii].start, state->cart.bank[ii].size);
12571238               b0_loaded = 1;
12581239//                  printf("addr 0xb000: 80 %d, 90 %d, a0 %d, b0 %d\n", _80_loaded, _90_loaded, a0_loaded, b0_loaded);
12591240            }
12601241
1261            if (c64_cart.bank[ii].addr == 0xe000 && !e0_loaded)
1242            if (state->cart.bank[ii].addr == 0xe000 && !e0_loaded)
12621243            {
1263               memcpy(romh, cart_cpy + c64_cart.bank[ii].start, c64_cart.bank[ii].size);
1244               memcpy(state->romh, cart_cpy + state->cart.bank[ii].start, state->cart.bank[ii].size);
12641245               e0_loaded = 1;
1265               if (c64_cart.bank[ii].size > 0x1000)
1246               if (state->cart.bank[ii].size > 0x1000)
12661247                  f0_loaded = 1;
12671248//                  printf("addr 0xe000: e0 %d, f0 %d\n", e0_loaded, f0_loaded);
12681249            }
12691250
1270            if (c64_cart.bank[ii].addr == 0xf000 && !f0_loaded)
1251            if (state->cart.bank[ii].addr == 0xf000 && !f0_loaded)
12711252            {
1272               memcpy(romh + 0x1000, cart_cpy + c64_cart.bank[ii].start, c64_cart.bank[ii].size);
1253               memcpy(state->romh + 0x1000, cart_cpy + state->cart.bank[ii].start, state->cart.bank[ii].size);
12731254               f0_loaded = 1;
12741255//                  printf("addr 0xe000: e0 %d, f0 %d\n", e0_loaded, f0_loaded);
12751256            }
r9686r9687
12871268
12881269static DEVICE_IMAGE_LOAD( max_cart )
12891270{
1271   c64_state *state = image.device().machine->driver_data<c64_state>();
12901272   int result = IMAGE_INIT_PASS;
12911273
12921274   if (image.software_entry() != NULL)
r9686r9687
12941276      UINT32 size;
12951277
12961278      // setup Ultimax mode
1297      c64_exrom = 1;
1298      c64_game  = 0;
1279      state->exrom = 1;
1280      state->game  = 0;
12991281
1300      roml = c64_roml;
1301      romh = c64_romh;
1282      state->roml = state->c64_roml;
1283      state->romh = state->c64_romh;
13021284
1303      memset(roml, 0, 0x2000);
1304      memset(romh, 0, 0x2000);
1285      memset(state->roml, 0, 0x2000);
1286      memset(state->romh, 0, 0x2000);
13051287
13061288      // is there anything to load at 0x8000?
13071289      size = image.get_software_region_length("roml");
13081290      if (size)
1309         memcpy(roml, image.get_software_region("roml"), size);
1291         memcpy(state->roml, image.get_software_region("roml"), size);
13101292
13111293      // is there anything to load at 0xe000?
13121294      size = image.get_software_region_length("romh");
13131295      if (size)
1314         memcpy(romh, image.get_software_region("romh"), size);
1296         memcpy(state->romh, image.get_software_region("romh"), size);
13151297   }
13161298   else
13171299      result = c64_crt_load(image);
r9686r9687
13221304
13231305static WRITE8_HANDLER( fc3_bank_w )
13241306{
1307   c64_state *state = space->machine->driver_data<c64_state>();
13251308   // Type # 3
13261309   // working:
13271310   // not working:
r9686r9687
13351318         logerror("Warning: This cart type should have at most 4 banks and the cart looked for bank %d... Something strange is going on!\n", bank);
13361319      else
13371320      {
1338         memcpy(roml, cart + bank * 0x4000, 0x2000);
1339         memcpy(romh, cart + bank * 0x4000 + 0x2000, 0x2000);
1321         memcpy(state->roml, cart + bank * 0x4000, 0x2000);
1322         memcpy(state->romh, cart + bank * 0x4000 + 0x2000, 0x2000);
13401323/*
13411324            if (log_cart)
13421325            {
1343                logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cart.bank[bank].size, c64_cart.bank[bank].addr);
1344                if (c64_cart.bank[bank].index != bank)
1345                    logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cart.bank[bank].index, bank);
1326                logerror("bank %d of size %d successfully loaded at %d!\n", bank, state->cart.bank[bank].size, state->cart.bank[bank].addr);
1327                if (state->cart.bank[bank].index != bank)
1328                    logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", state->cart.bank[bank].index, bank);
13461329            }
13471330*/
13481331      }
r9686r9687
13511334
13521335static WRITE8_HANDLER( ocean1_bank_w )
13531336{
1337   c64_state *state = space->machine->driver_data<c64_state>();
13541338   // Type # 5
13551339   // working: Double Dragon, Ghostbusters, Terminator 2
13561340   // not working: Pang, Robocop 2, Toki
r9686r9687
13581342   UINT8 bank = data & 0x3f;
13591343   UINT8 *cart = memory_region(space->machine, "user1");
13601344
1361   switch (c64_cart.bank[bank].addr)
1345   switch (state->cart.bank[bank].addr)
13621346   {
13631347   case 0x8000:
1364      memcpy(roml, cart + bank * 0x2000, c64_cart.bank[bank].size);
1348      memcpy(state->roml, cart + bank * 0x2000, state->cart.bank[bank].size);
13651349      break;
13661350   case 0xa000:
1367      memcpy(roml + 0x2000, cart + bank * 0x2000, c64_cart.bank[bank].size);
1351      memcpy(state->roml + 0x2000, cart + bank * 0x2000, state->cart.bank[bank].size);
13681352      break;
13691353   case 0xe000:
1370      memcpy(romh, cart + bank * 0x2000, c64_cart.bank[bank].size);
1354      memcpy(state->romh, cart + bank * 0x2000, state->cart.bank[bank].size);
13711355      break;
13721356   default:
1373      logerror("Unexpected loading address (%x) for bank %x\n", c64_cart.bank[bank].addr, bank);
1357      logerror("Unexpected loading address (%x) for bank %x\n", state->cart.bank[bank].addr, bank);
13741358      break;
13751359   }
13761360/*
13771361    if (log_cart)
13781362    {
1379        logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cart.bank[bank].size, c64_cart.bank[bank].addr);
1380        if (c64_cart.bank[bank].index != bank)
1381            logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cart.bank[bank].index, bank);
1363        logerror("bank %d of size %d successfully loaded at %d!\n", bank, state->cart.bank[bank].size, state->cart.bank[bank].addr);
1364        if (state->cart.bank[bank].index != bank)
1365            logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", state->cart.bank[bank].index, bank);
13821366    }
13831367*/
13841368}
13851369
13861370static WRITE8_HANDLER( funplay_bank_w )
13871371{
1372   c64_state *state = space->machine->driver_data<c64_state>();
13881373   // Type # 7
13891374   // working:
13901375   // not working:
r9686r9687
13971382      logerror("Reserved value written\n");
13981383   else
13991384   {
1400      /* bank number is not the value written, but c64_cart.bank[bank].index IS the value written! */
1385      /* bank number is not the value written, but state->cart.bank[bank].index IS the value written! */
14011386      real_bank = ((bank & 0x01) << 3) + ((bank & 0x38) >> 3);
14021387
1403      memcpy(roml, cart + real_bank * 0x2000, 0x2000);
1388      memcpy(state->roml, cart + real_bank * 0x2000, 0x2000);
14041389/*
14051390        if (log_cart)
14061391        {
1407            logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cart.bank[bank].size, c64_cart.bank[bank].addr);
1408            if (c64_cart.bank[bank].index != bank)
1409                logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cart.bank[bank].index, bank);
1392            logerror("bank %d of size %d successfully loaded at %d!\n", bank, state->cart.bank[bank].size, state->cart.bank[bank].addr);
1393            if (state->cart.bank[bank].index != bank)
1394                logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", state->cart.bank[bank].index, bank);
14101395        }
14111396*/
14121397   }
r9686r9687
14141399
14151400static WRITE8_HANDLER( supergames_bank_w )
14161401{
1402   c64_state *state = space->machine->driver_data<c64_state>();
14171403   // Type # 8
14181404   // working:
14191405   // not working:
r9686r9687
14231409
14241410   if (data & 0x04)
14251411   {
1426      c64_game = 0;
1427      c64_exrom = 0;
1412      state->game = 0;
1413      state->exrom = 0;
14281414   }
14291415   else
14301416   {
1431      c64_game = 0;
1432      c64_exrom = 0;
1417      state->game = 0;
1418      state->exrom = 0;
14331419   }
14341420
14351421   if (data == 0xc)
14361422   {
1437      c64_game = 1;
1438      c64_exrom = 1;
1423      state->game = 1;
1424      state->exrom = 1;
14391425   }
14401426
14411427   if (bit2)
14421428   {
1443      memcpy(roml, cart + bank * 0x4000, 0x2000);
1444      memcpy(romh, cart + bank * 0x4000 + 0x2000, 0x2000);
1429      memcpy(state->roml, cart + bank * 0x4000, 0x2000);
1430      memcpy(state->romh, cart + bank * 0x4000 + 0x2000, 0x2000);
14451431   }
14461432   else
14471433   {
1448      memcpy(roml, cart + bank * 0x4000, 0x2000);
1449      memcpy(romh, cart + bank * 0x4000 + 0x2000, 0x2000);
1434      memcpy(state->roml, cart + bank * 0x4000, 0x2000);
1435      memcpy(state->romh, cart + bank * 0x4000 + 0x2000, 0x2000);
14501436   }
14511437}
14521438
14531439static WRITE8_HANDLER( c64gs_bank_w )
14541440{
1441   c64_state *state = space->machine->driver_data<c64_state>();
14551442   // Type # 15
14561443   // working:
14571444   // not working: The Last Ninja Remix
r9686r9687
14621449   if (bank > 0x3f)
14631450      logerror("Warning: This cart type should have at most 64 banks and the cart looked for bank %d... Something strange is going on!\n", bank);
14641451
1465   memcpy(roml, cart + bank * 0x2000, 0x2000);
1452   memcpy(state->roml, cart + bank * 0x2000, 0x2000);
14661453/*
14671454    if (log_cart)
14681455    {
1469        logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cart.bank[bank].size, c64_cart.bank[bank].addr);
1470        if (c64_cart.bank[bank].index != bank)
1471            logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cart.bank[bank].index, bank);
1456        logerror("bank %d of size %d successfully loaded at %d!\n", bank, state->cart.bank[bank].size, state->cart.bank[bank].addr);
1457        if (state->cart.bank[bank].index != bank)
1458            logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", state->cart.bank[bank].index, bank);
14721459    }
14731460*/
14741461}
14751462
14761463static READ8_HANDLER( dinamic_bank_r )
14771464{
1465   c64_state *state = space->machine->driver_data<c64_state>();
14781466   // Type # 17
14791467   // working: Satan
14801468   // not working:
r9686r9687
14851473   if (bank > 0xf)
14861474      logerror("Warning: This cart type should have 16 banks and the cart looked for bank %d... Something strange is going on!\n", bank);
14871475
1488   memcpy(roml, cart + bank * 0x2000, 0x2000);
1476   memcpy(state->roml, cart + bank * 0x2000, 0x2000);
14891477/*
14901478    if (log_cart)
14911479    {
1492        logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cart.bank[bank].size, c64_cart.bank[bank].addr);
1493        if (c64_cart.bank[bank].index != bank)
1494            logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cart.bank[bank].index, bank);
1480        logerror("bank %d of size %d successfully loaded at %d!\n", bank, state->cart.bank[bank].size, state->cart.bank[bank].addr);
1481        if (state->cart.bank[bank].index != bank)
1482            logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", state->cart.bank[bank].index, bank);
14951483    }
14961484*/
14971485   return 0;
r9686r9687
14991487
15001488static READ8_HANDLER( zaxxon_bank_r )
15011489{
1490   c64_state *state = space->machine->driver_data<c64_state>();
15021491   // Type # 18
15031492   // working:
15041493   // not working:
r9686r9687
15111500   else
15121501      bank = 1;
15131502
1514   // c64_game = 0;
1515   // c64_exrom = 0;
1503   // state->game = 0;
1504   // state->exrom = 0;
15161505
1517   memcpy(romh, cart + bank * 0x2000 + 0x1000, 0x2000);
1506   memcpy(state->romh, cart + bank * 0x2000 + 0x1000, 0x2000);
15181507
15191508   return cart[offset & 0x0fff];
15201509}
15211510
15221511static WRITE8_HANDLER( domark_bank_w )
15231512{
1513   c64_state *state = space->machine->driver_data<c64_state>();
15241514   // Type # 19
15251515   // working:
15261516   // not working:
r9686r9687
15301520
15311521   if (data & 0x80)
15321522   {
1533      c64_game = 1;
1534      c64_exrom = 1;
1523      state->game = 1;
1524      state->exrom = 1;
15351525   }
15361526   else
15371527   {
1538      c64_game = 1;
1539      c64_exrom = 0;
1540      memcpy(roml, cart + bank * 0x2000, 0x2000);
1528      state->game = 1;
1529      state->exrom = 0;
1530      memcpy(state->roml, cart + bank * 0x2000, 0x2000);
15411531   }
15421532}
15431533
15441534static WRITE8_HANDLER( comal80_bank_w )
15451535{
1536   c64_state *state = space->machine->driver_data<c64_state>();
15461537   // Type # 21
15471538   // working: Comal 80
15481539   // not working:
r9686r9687
15571548   {
15581549      bank &= 0x03;
15591550
1560      memcpy(roml, cart + bank * 0x4000, 0x4000);
1551      memcpy(state->roml, cart + bank * 0x4000, 0x4000);
15611552/*
15621553        if (log_cart)
15631554        {
1564            logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cart.bank[bank].size, c64_cart.bank[bank].addr);
1565            if (c64_cart.bank[bank].index != bank)
1566                logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cart.bank[bank].index, bank);
1555            logerror("bank %d of size %d successfully loaded at %d!\n", bank, state->cart.bank[bank].size, state->cart.bank[bank].addr);
1556            if (state->cart.bank[bank].index != bank)
1557                logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", state->cart.bank[bank].index, bank);
15671558        }
15681559*/
15691560   }
r9686r9687
15711562
15721563static void setup_c64_custom_mappers(running_machine *machine)
15731564{
1565   c64_state *state = machine->driver_data<c64_state>();
15741566   address_space *space = cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM );
15751567
1576   switch (c64_cart.mapper)
1568   switch (state->cart.mapper)
15771569   {
15781570      case ACTION_REPLAY:   /* Type #  1 not working */
15791571         break;
r9686r9687
16331625
16341626MACHINE_RESET( c64 )
16351627{
1636   if (c64_cart.n_banks)
1628   c64_state *state = machine->driver_data<c64_state>();
1629   if (state->cart.n_banks)
16371630      setup_c64_custom_mappers(machine);
16381631}
16391632
src/mess/video/vic4567.c
r9686r9687
15561556    if (M)                                                      \
15571557    {                                                           \
15581558        if (M & 0x01)                                           \
1559            colors[0] = vic3->c64_mem_r(VIC3_ADDR(0) + offset);        \
1559            colors[0] = vic3->c64_mem_r(device->machine, VIC3_ADDR(0) + offset);        \
15601560        if (M & 0x02)                                           \
1561            colors[1] = vic3->c64_mem_r(VIC3_ADDR(1) + offset) << 1;     \
1561            colors[1] = vic3->c64_mem_r(device->machine, VIC3_ADDR(1) + offset) << 1;     \
15621562        if (M & 0x04)                                           \
1563            colors[2] = vic3->c64_mem_r(VIC3_ADDR(2) + offset) << 2;     \
1563            colors[2] = vic3->c64_mem_r(device->machine, VIC3_ADDR(2) + offset) << 2;     \
15641564        if (M & 0x08)                                           \
1565            colors[3] = vic3->c64_mem_r(VIC3_ADDR(3) + offset) << 3;     \
1565            colors[3] = vic3->c64_mem_r(device->machine, VIC3_ADDR(3) + offset) << 3;     \
15661566        if (M & 0x10)                                           \
1567            colors[4] = vic3->c64_mem_r(VIC3_ADDR(4) + offset) << 4;     \
1567            colors[4] = vic3->c64_mem_r(device->machine, VIC3_ADDR(4) + offset) << 4;     \
15681568        if (M & 0x20)                                           \
1569            colors[5] = vic3->c64_mem_r(VIC3_ADDR(5) + offset) << 5;     \
1569            colors[5] = vic3->c64_mem_r(device->machine, VIC3_ADDR(5) + offset) << 5;     \
15701570        if (M & 0x40)                                           \
1571            colors[6] = vic3->c64_mem_r(VIC3_ADDR(6) + offset) << 6;     \
1571            colors[6] = vic3->c64_mem_r(device->machine, VIC3_ADDR(6) + offset) << 6;     \
15721572        if (M & 0x80)                                           \
1573            colors[7] = vic3->c64_mem_r(VIC3_ADDR(7) + offset) << 7;     \
1573            colors[7] = vic3->c64_mem_r(device->machine, VIC3_ADDR(7) + offset) << 7;     \
15741574        for (i = 7; i >= 0; i--)                                \
15751575        {                                                       \
15761576            p = 0;                                              \
r9686r9687
16471647      break;
16481648   default:
16491649      if (VIC3_BITPLANES_MASK & 0x01)
1650         colors[0] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(0) + offset);
1650         colors[0] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_IADDR(0) + offset);
16511651
16521652      if (VIC3_BITPLANES_MASK & 0x02)
1653         colors[1] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(1) + offset) << 1;
1653         colors[1] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_IADDR(1) + offset) << 1;
16541654
16551655      if (VIC3_BITPLANES_MASK & 0x04)
1656         colors[2] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(2) + offset) << 2;
1656         colors[2] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_IADDR(2) + offset) << 2;
16571657
16581658      if (VIC3_BITPLANES_MASK & 0x08)
1659         colors[3] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(3) + offset) << 3;
1659         colors[3] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_IADDR(3) + offset) << 3;
16601660
16611661      if (VIC3_BITPLANES_MASK & 0x10)
1662         colors[4] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(4) + offset) << 4;
1662         colors[4] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_IADDR(4) + offset) << 4;
16631663
16641664      if (VIC3_BITPLANES_MASK & 0x20)
1665         colors[5] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(5) + offset) << 5;
1665         colors[5] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_IADDR(5) + offset) << 5;
16661666
16671667      if (VIC3_BITPLANES_MASK & 0x40)
1668         colors[6] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(6) + offset) << 6;
1668         colors[6] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_IADDR(6) + offset) << 6;
16691669
16701670      if (VIC3_BITPLANES_MASK & 0x80)
1671         colors[7] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(7) + offset) << 7;
1671         colors[7] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_IADDR(7) + offset) << 7;
16721672
16731673      for (i = 7; i >= 0; i--)
16741674      {
r9686r9687
17191719      break;
17201720   default:
17211721      if (VIC3_BITPLANES_MASK & 0x01)
1722         colors[0] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(0) + offset);
1722         colors[0] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_ADDR(0) + offset);
17231723
17241724      if (VIC3_BITPLANES_MASK & 0x02)
1725         colors[1] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(1) + offset) << 1;
1725         colors[1] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_ADDR(1) + offset) << 1;
17261726
17271727      if (VIC3_BITPLANES_MASK & 0x04)
1728         colors[2] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(2) + offset) << 2;
1728         colors[2] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_ADDR(2) + offset) << 2;
17291729
17301730      if (VIC3_BITPLANES_MASK & 0x08)
1731         colors[3] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(3) + offset) << 3;
1731         colors[3] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_ADDR(3) + offset) << 3;
17321732
17331733      if (VIC3_BITPLANES_MASK & 0x10)
1734         colors[4] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(4) + offset) << 4;
1734         colors[4] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_ADDR(4) + offset) << 4;
17351735
17361736      if (VIC3_BITPLANES_MASK & 0x20)
1737         colors[5] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(5) + offset) << 5;
1737         colors[5] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_ADDR(5) + offset) << 5;
17381738
17391739      if (VIC3_BITPLANES_MASK & 0x40)
1740         colors[6] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(6) + offset) << 6;
1740         colors[6] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_ADDR(6) + offset) << 6;
17411741
17421742      if (VIC3_BITPLANES_MASK & 0x80)
1743         colors[7] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(7) + offset) << 7;
1743         colors[7] = vic3->c64_mem_r(device->machine, VIC3_BITPLANE_ADDR(7) + offset) << 7;
17441744
17451745      for (i = 7; i >= 0; i--)
17461746      {
src/mess/video/vic4567.h
r9686r9687
2424
2525typedef void (*vic3_port_changed_callback) (running_machine *, int);
2626
27typedef UINT8 (*vic3_c64mem_callback)(int offset);
27typedef UINT8 (*vic3_c64mem_callback)(running_machine *machine, int offset);
2828
2929typedef enum
3030{
src/mess/video/vic6567.c
r9686r9687
7474#include "emu.h"
7575#include "video/vic6567.h"
7676
77static UINT8 rdy_cycles = 0;
78
7977typedef struct _vic2_state  vic2_state;
8078struct _vic2_state
8179{
r9686r9687
8482   screen_device *screen;         // screen which sets bitmap properties
8583   running_device *cpu;
8684
85   UINT8 rdy_cycles;
8786   UINT8 reg[0x80];
8887
8988   int on;                        /* rastering of the screen */
r9686r9687
999998   vic2_state *vic2 = (vic2_state *)ptr;
1000999   int i;
10011000   UINT8 mask;
1002   static int adjust[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1001   //static int adjust[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
10031002
10041003   UINT8 cpu_cycles = machine->device<cpu_device>("maincpu")->total_cycles() & 0xff;
10051004   UINT8 vic_cycles = (vic2->cycles_counter + 1) & 0xff;
10061005   vic2->cycles_counter++;
10071006
1008//  printf("%02x %02x %02x\n",cpu_cycles,vic_cycles,rdy_cycles);
1009/*
1007//  printf("%02x %02x %02x\n",cpu_cycles,vic_cycles,vic2->rdy_cycles);
1008#if 0
10101009if (input_code_pressed(machine, KEYCODE_X))
10111010{
10121011if (input_code_pressed_once(machine, KEYCODE_Q)) adjust[1]++;
r9686r9687
10301029if (input_code_pressed_once(machine, KEYCODE_Z)) printf("b:%02x 1:%02x 2:%02x 3:%02x 4:%02x 5:%02x 6:%02x 7:%02x 8:%02x\n",
10311030                                adjust[0],adjust[1],adjust[2],adjust[3],adjust[4],adjust[5],adjust[6],adjust[7],adjust[8]);
10321031}
1033*/
1032#define adjust(x) adjust[x]
1033#else
1034#define adjust(x) 0
1035#endif
10341036
10351037   switch(vic2->cycle)
10361038   {
r9686r9687
10711073      else
10721074         vic2_resume_cpu(machine, vic2);
10731075
1074      if (vic2->spr_dma_on & 0x08) rdy_cycles += (2 + adjust[1]);
1076      if (vic2->spr_dma_on & 0x08) vic2->rdy_cycles += (2 + adjust(1));
10751077
10761078      vic2->cycle++;
10771079      break;
r9686r9687
11171119      else
11181120         vic2_resume_cpu(machine, vic2);
11191121
1120      if (vic2->spr_dma_on & 0x10) rdy_cycles += (2 + adjust[2]);
1122      if (vic2->spr_dma_on & 0x10) vic2->rdy_cycles += (2 + adjust(2));
11211123
11221124      vic2->cycle++;
11231125      break;
r9686r9687
11421144      else
11431145         vic2_resume_cpu(machine, vic2);
11441146
1145      if (vic2->spr_dma_on & 0x20) rdy_cycles += (2 + adjust[3]);
1147      if (vic2->spr_dma_on & 0x20) vic2->rdy_cycles += (2 + adjust(3));
11461148
11471149      vic2->cycle++;
11481150      break;
r9686r9687
11671169      else
11681170         vic2_resume_cpu(machine, vic2);
11691171
1170      if (vic2->spr_dma_on & 0x40) rdy_cycles += (2 + adjust[4]);
1172      if (vic2->spr_dma_on & 0x40) vic2->rdy_cycles += (2 + adjust(4));
11711173
11721174      vic2->cycle++;
11731175      break;
r9686r9687
11921194      else
11931195         vic2_resume_cpu(machine, vic2);
11941196
1195      if (vic2->spr_dma_on & 0x80) rdy_cycles += (2 + adjust[5]);
1197      if (vic2->spr_dma_on & 0x80) vic2->rdy_cycles += (2 + adjust(5));
11961198
11971199      vic2->cycle++;
11981200      break;
r9686r9687
12341236      vic2->raster_x = 0xfffc;
12351237
12361238      if ((vic2->rdy_workaround_cb(machine) == 0 ) && (vic2->is_bad_line))
1237         rdy_cycles += (43+adjust[0]);
1239         vic2->rdy_cycles += (43+adjust(0));
12381240
12391241      vic2->cycle++;
12401242      break;
r9686r9687
12491251      vic2->vc = vic2->vc_base;
12501252
12511253      if ((vic2->rdy_workaround_cb(machine) == 1 ) && (vic2->is_bad_line))
1252         rdy_cycles += (42+adjust[0]);
1254         vic2->rdy_cycles += (42+adjust(0));
12531255
12541256      vic2->cycle++;
12551257      break;
r9686r9687
12691271      vic2_matrix_access(machine, vic2);
12701272
12711273      if ((vic2->rdy_workaround_cb(machine) == 2 ) && (vic2->is_bad_line))
1272         rdy_cycles += (41+adjust[0]);
1274         vic2->rdy_cycles += (41+adjust(0));
12731275
12741276      vic2->cycle++;
12751277      break;
r9686r9687
12931295      vic2_matrix_access(machine, vic2);
12941296
12951297      if ((vic2->rdy_workaround_cb(machine) == 3 ) && (vic2->is_bad_line))
1296         rdy_cycles += (40+adjust[0]);
1298         vic2->rdy_cycles += (40+adjust(0));
12971299
12981300      vic2->cycle++;
12991301      break;
r9686r9687
13301332      vic2_matrix_access(machine, vic2);
13311333
13321334      if ((vic2->rdy_workaround_cb(machine) == 4 ) && (vic2->is_bad_line))
1333         rdy_cycles += (40+adjust[0]);
1335         vic2->rdy_cycles += (40+adjust(0));
13341336
13351337      vic2->cycle++;
13361338      break;
r9686r9687
15031505      else
15041506         vic2_resume_cpu(machine, vic2);
15051507
1506      if (vic2->spr_dma_on & 0x01) rdy_cycles += (2 + adjust[6]);
1508      if (vic2->spr_dma_on & 0x01) vic2->rdy_cycles += (2 + adjust(6));
15071509
15081510      vic2->cycle++;
15091511      break;
r9686r9687
15601562      else
15611563         vic2_resume_cpu(machine, vic2);
15621564
1563      if (vic2->spr_dma_on & 0x02) rdy_cycles += (2 + adjust[7]);
1565      if (vic2->spr_dma_on & 0x02) vic2->rdy_cycles += (2 + adjust(7));
15641566
15651567      vic2->cycle++;
15661568      break;
r9686r9687
15851587      else
15861588         vic2_resume_cpu(machine, vic2);
15871589
1588      if (vic2->spr_dma_on & 0x04) rdy_cycles += (2 + adjust[8]);
1590      if (vic2->spr_dma_on & 0x04) vic2->rdy_cycles += (2 + adjust(8));
15891591
15901592      vic2->cycle++;
15911593      break;
r9686r9687
16061608      vic2->cycle = 1;
16071609   }
16081610
1609   if ((cpu_cycles == vic_cycles) && (rdy_cycles > 0))
1611   if ((cpu_cycles == vic_cycles) && (vic2->rdy_cycles > 0))
16101612   {
1611      device_spin_until_time (machine->firstcpu, machine->device<cpu_device>("maincpu")->cycles_to_attotime(rdy_cycles));
1612      rdy_cycles = 0;
1613      device_spin_until_time (machine->firstcpu, machine->device<cpu_device>("maincpu")->cycles_to_attotime(vic2->rdy_cycles));
1614      vic2->rdy_cycles = 0;
16131615   }
16141616
16151617   vic2->raster_x += 8;
src/mess/includes/c65.h
r9686r9687
77#ifndef C65_H_
88#define C65_H_
99
10#include "includes/c64.h"
1011#include "machine/6526cia.h"
1112
1213typedef struct
r9686r9687
3637   UINT8 reg;
3738} expansion_ram_t;
3839
39class c65_state : public driver_device
40class c65_state : public c64_state
4041{
4142public:
4243   c65_state(running_machine &machine, const driver_device_config_base &config)
43      : driver_device(machine, config) { }
44      : c64_state(machine, config) { }
4445
4546   UINT8 *chargen;
4647   UINT8 *interface;
r9686r9687
4849   int c64mode;
4950   UINT8 _6511_port;
5051   UINT8 keyline;
51   UINT8 vicirq;
52   int old_level;
5352   int old_value;
54   int old_data;
5553   int nmilevel;
5654   dma_t dma;
5755   int dump_dma;
r9686r9687
7270/*extern UINT8 *c65_graphics; */
7371
7472void c65_bankswitch (running_machine *machine);
75void c65_colorram_write (int offset, int value);
73//void c65_colorram_write (running_machine *machine, int offset, int value);
7674
7775int c65_dma_read(running_machine *machine, int offset);
7876int c65_dma_read_color(running_machine *machine, int offset);
src/mess/includes/c128.h
r9686r9687
1414#ifndef __C128_H__
1515#define __C128_H__
1616
17#include "includes/c64.h"
1718#include "machine/6526cia.h"
1819
19class c128_state : public driver_device
20class c128_state : public c64_state
2021{
2122public:
2223   c128_state(running_machine &machine, const driver_device_config_base &config)
23      : driver_device(machine, config) { }
24      : c64_state(machine, config) { }
2425
25   UINT8 *basic;
26   UINT8 *kernal;
27   UINT8 *chargen;
26   UINT8 *c128_basic;
27   UINT8 *c128_kernal;
28   UINT8 *c128_chargen;
2829   UINT8 *z80;
2930   UINT8 *editor;
3031   UINT8 *internal_function;
r9686r9687
4546   int sp1;
4647   int data_out;
4748   int va1617;
48   int cia1_on;
4949   int monitor;
50   UINT8 vicirq;
5150   int nmilevel;
52   int old_level;
53   int old_data;
54   int old_exrom;
55   int old_game;
56   emu_timer *datasette_timer;
5751};
5852
5953
src/mess/includes/c64.h
r9686r9687
1616#include "machine/6526cia.h"
1717#include "devices/cartslot.h"
1818
19#define C64_MAX_ROMBANK 64 // .crt files contain multiple 'CHIPs', i.e. rom banks (of variable size) with headers. Known carts have at most 64 'CHIPs'.
20
21typedef struct {
22   int addr, size, index, start;
23} C64_ROM;
24
25typedef struct _c64_cart_t c64_cart_t;
26struct _c64_cart_t {
27   C64_ROM     bank[C64_MAX_ROMBANK];
28   INT8        game;
29   INT8        exrom;
30   UINT8       mapper;
31   UINT8       n_banks;
32};
33
34class c64_state : public driver_device
35{
36public:
37   c64_state(running_machine &machine, const driver_device_config_base &config)
38      : driver_device(machine, config) { }
39
40   int old_level;
41   int old_data;
42   int old_exrom;
43   int old_game;
44   UINT8 vicirq;
45   emu_timer *datasette_timer;
46   UINT8 *colorram;
47   UINT8 *basic;
48   UINT8 *kernal;
49   UINT8 *chargen;
50   UINT8 *memory;
51   int pal;
52   int tape_on;
53   UINT8 *c64_roml;
54   UINT8 *c64_romh;
55   UINT8 *vicaddr;
56   UINT8 *c128_vicaddr;
57   UINT8 game;
58   UINT8 exrom;
59   UINT8 *io_mirror;
60   UINT8 port_data;
61   UINT8 *roml;
62   UINT8 *romh;
63   int ultimax;
64   int cia1_on;
65   int io_enabled;
66   int is_sx64;
67   UINT8 *io_ram_w_ptr;
68   UINT8 *io_ram_r_ptr;
69   c64_cart_t cart;
70};
71
72
1973/*----------- defined in machine/c64.c -----------*/
2074
2175/* private area */
22extern UINT8 *c64_colorram;
23extern UINT8 *c64_basic;
24extern UINT8 *c64_kernal;
25extern UINT8 *c64_chargen;
26extern UINT8 *c64_memory;
2776
2877UINT8 c64_m6510_port_read(running_device *device, UINT8 direction);
2978void c64_m6510_port_write(running_device *device, UINT8 direction, UINT8 data);
r9686r9687
51100int c64_paddle_read (running_device *device, int which);
52101void c64_vic_interrupt (running_machine *machine, int level);
53102
54extern int c64_pal;
55extern int c64_tape_on;
56extern UINT8 *c64_roml;
57extern UINT8 *c64_romh;
58extern UINT8 *c64_vicaddr, *c128_vicaddr;
59extern UINT8 c64_game, c64_exrom;
60103extern const mos6526_interface c64_ntsc_cia0, c64_pal_cia0;
61104extern const mos6526_interface c64_ntsc_cia1, c64_pal_cia1;
62105
src/mess/drivers/c65.c
r9686r9687
8484   AM_RANGE(0x0dc00, 0x0dfff) AM_READ_BANK("bank8") AM_WRITE_BANK("bank9")
8585   AM_RANGE(0x0e000, 0x0ffff) AM_READ_BANK("bank10") AM_WRITE_BANK("bank15")
8686   AM_RANGE(0x10000, 0x1f7ff) AM_RAM
87   AM_RANGE(0x1f800, 0x1ffff) AM_RAM AM_BASE(&c64_colorram)
87   AM_RANGE(0x1f800, 0x1ffff) AM_RAM AM_BASE_MEMBER(c65_state, colorram)
8888
8989   AM_RANGE(0x20000, 0x23fff) AM_ROM /* &c65_dos,     maps to 0x8000    */
9090   AM_RANGE(0x24000, 0x28fff) AM_ROM /* reserved */
9191   AM_RANGE(0x29000, 0x29fff) AM_ROM AM_BASE_MEMBER(c65_state, chargen)
92   AM_RANGE(0x2a000, 0x2bfff) AM_ROM AM_BASE(&c64_basic)
92   AM_RANGE(0x2a000, 0x2bfff) AM_ROM AM_BASE_MEMBER(c65_state, basic)
9393   AM_RANGE(0x2c000, 0x2cfff) AM_ROM AM_BASE_MEMBER(c65_state, interface)
94   AM_RANGE(0x2d000, 0x2dfff) AM_ROM AM_BASE(&c64_chargen)
95   AM_RANGE(0x2e000, 0x2ffff) AM_ROM AM_BASE(&c64_kernal)
94   AM_RANGE(0x2d000, 0x2dfff) AM_ROM AM_BASE_MEMBER(c65_state, chargen)
95   AM_RANGE(0x2e000, 0x2ffff) AM_ROM AM_BASE_MEMBER(c65_state, kernal)
9696
9797   AM_RANGE(0x30000, 0x31fff) AM_ROM /*&c65_monitor,     monitor maps to 0x6000    */
9898   AM_RANGE(0x32000, 0x37fff) AM_ROM /*&c65_basic, */
r9686r9687
236236   return input_port_read(machine, "OTHER") & 0x04;
237237}
238238
239static UINT8 c65_c64_mem_r( int offset )
239static UINT8 c65_c64_mem_r( running_machine *machine, int offset )
240240{
241   return c64_memory[offset];
241   c65_state *state = machine->driver_data<c65_state>();
242   return state->memory[offset];
242243}
243244
244245static const vic3_interface c65_vic3_ntsc_intf = {
src/mess/drivers/c128.c
r9686r9687
235235#if 0
236236   AM_RANGE(0x10000, 0x1ffff) AM_WRITEONLY
237237   AM_RANGE(0x20000, 0xfffff) AM_WRITEONLY      /* or nothing */
238   AM_RANGE(0x100000, 0x107fff) AM_BASE_MEMBER(c128_state, basic)   /* maps to 0x4000 */
239   AM_RANGE(0x108000, 0x109fff) AM_BASE(&c64_basic)   /* maps to 0xa000 */
240   AM_RANGE(0x10a000, 0x10bfff) AM_BASE(&c64_kernal)   /* maps to 0xe000 */
238   AM_RANGE(0x100000, 0x107fff) AM_BASE_MEMBER(c128_state, c128_basic)   /* maps to 0x4000 */
239   AM_RANGE(0x108000, 0x109fff) AM_BASE_MEMBER(c128_state, basic)   /* maps to 0xa000 */
240   AM_RANGE(0x10a000, 0x10bfff) AM_BASE_MEMBER(c128_state, kernal)   /* maps to 0xe000 */
241241   AM_RANGE(0x10c000, 0x10cfff) AM_BASE_MEMBER(c128_state, editor)
242242   AM_RANGE(0x10d000, 0x10dfff) AM_BASE_MEMBER(c128_state, z80)      /* maps to z80 0 */
243   AM_RANGE(0x10e000, 0x10ffff) AM_BASE_MEMBER(c128_state, kernal)
243   AM_RANGE(0x10e000, 0x10ffff) AM_BASE_MEMBER(c128_state, c128_kernal)
244244   AM_RANGE(0x110000, 0x117fff) AM_BASE_MEMBER(c128_state, internal_function)
245245   AM_RANGE(0x118000, 0x11ffff) AM_BASE_MEMBER(c128_state, external_function)
246   AM_RANGE(0x120000, 0x120fff) AM_BASE(&c64_chargen)
247   AM_RANGE(0x121000, 0x121fff) AM_BASE_MEMBER(c128_state, chargen)
248   AM_RANGE(0x122000, 0x1227ff) AM_BASE(&c64_colorram)
246   AM_RANGE(0x120000, 0x120fff) AM_BASE_MEMBER(c128_state, chargen)
247   AM_RANGE(0x121000, 0x121fff) AM_BASE_MEMBER(c128_state, c128_chargen)
248   AM_RANGE(0x122000, 0x1227ff) AM_BASE_MEMBER(c128_state, colorram)
249249   AM_RANGE(0x122800, 0x1327ff) AM_BASE_MEMBER(c128_state, vdcram)
250250   /* 2 kbyte by 8 bits, only 1 kbyte by 4 bits used) */
251251#endif
src/mess/drivers/c64.c
r9686r9687
399399 *************************************/
400400
401401static ADDRESS_MAP_START(ultimax_mem , ADDRESS_SPACE_PROGRAM, 8)
402   AM_RANGE(0x0000, 0x0fff) AM_RAM AM_BASE(&c64_memory)
403   AM_RANGE(0x8000, 0x9fff) AM_ROM AM_BASE(&c64_roml)
402   AM_RANGE(0x0000, 0x0fff) AM_RAM AM_BASE_MEMBER(c64_state, memory)
403   AM_RANGE(0x8000, 0x9fff) AM_ROM AM_BASE_MEMBER(c64_state, c64_roml)
404404   AM_RANGE(0xd000, 0xd3ff) AM_DEVREADWRITE("vic2", vic2_port_r, vic2_port_w)
405405   AM_RANGE(0xd400, 0xd7ff) AM_DEVREADWRITE("sid6581", sid6581_r, sid6581_w)
406   AM_RANGE(0xd800, 0xdbff) AM_RAM_WRITE( c64_colorram_write) AM_BASE(&c64_colorram) /* colorram  */
406   AM_RANGE(0xd800, 0xdbff) AM_RAM_WRITE( c64_colorram_write) AM_BASE_MEMBER(c64_state, colorram) /* colorram  */
407407   AM_RANGE(0xdc00, 0xdcff) AM_DEVREADWRITE("cia_0", mos6526_r, mos6526_w)
408   AM_RANGE(0xe000, 0xffff) AM_ROM AM_BASE(&c64_romh)            /* ram or kernel rom */
408   AM_RANGE(0xe000, 0xffff) AM_ROM AM_BASE_MEMBER(c64_state, c64_romh)            /* ram or kernel rom */
409409ADDRESS_MAP_END
410410
411411static ADDRESS_MAP_START(c64_mem, ADDRESS_SPACE_PROGRAM, 8)
412   AM_RANGE(0x0000, 0x7fff) AM_RAM AM_BASE(&c64_memory)
412   AM_RANGE(0x0000, 0x7fff) AM_RAM AM_BASE_MEMBER(c64_state, memory)
413413   AM_RANGE(0x8000, 0x9fff) AM_READ_BANK("bank1") AM_WRITE_BANK("bank2")      /* ram or external roml */
414414   AM_RANGE(0xa000, 0xbfff) AM_ROMBANK("bank3") AM_WRITEONLY            /* ram or basic rom or external romh */
415415   AM_RANGE(0xc000, 0xcfff) AM_RAM
r9686r9687
591591
592592static int c64_dma_read( running_machine *machine, int offset )
593593{
594   if (!c64_game && c64_exrom)
594   c64_state *state = machine->driver_data<c64_state>();
595   if (!state->game && state->exrom)
595596   {
596597      if (offset < 0x3000)
597         return c64_memory[offset];
598         return state->memory[offset];
598599
599      return c64_romh[offset & 0x1fff];
600      return state->c64_romh[offset & 0x1fff];
600601   }
601602
602   if (((c64_vicaddr - c64_memory + offset) & 0x7000) == 0x1000)
603      return c64_chargen[offset & 0xfff];
603   if (((state->vicaddr - state->memory + offset) & 0x7000) == 0x1000)
604      return state->chargen[offset & 0xfff];
604605
605   return c64_vicaddr[offset];
606   return state->vicaddr[offset];
606607}
607608
608609static int c64_dma_read_ultimax( running_machine *machine, int offset )
609610{
611   c64_state *state = machine->driver_data<c64_state>();
610612   if (offset < 0x3000)
611      return c64_memory[offset];
613      return state->memory[offset];
612614
613   return c64_romh[offset & 0x1fff];
615   return state->c64_romh[offset & 0x1fff];
614616}
615617
616618static int c64_dma_read_color( running_machine *machine, int offset )
617619{
618   return c64_colorram[offset & 0x3ff] & 0xf;
620   c64_state *state = machine->driver_data<c64_state>();
621   return state->colorram[offset & 0x3ff] & 0xf;
619622}
620623
621624static UINT8 c64_rdy_cb( running_machine *machine )
r9686r9687
669672 *
670673 *************************************/
671674
672static MACHINE_CONFIG_START( c64, driver_device )
675static MACHINE_CONFIG_START( c64, c64_state )
673676   /* basic machine hardware */
674677   MDRV_CPU_ADD("maincpu", M6510, VIC6567_CLOCK)
675678   MDRV_CPU_PROGRAM_MAP(c64_mem)
r9686r9687
721724   MDRV_FRAGMENT_ADD(c64_cartslot)
722725MACHINE_CONFIG_END
723726
724static MACHINE_CONFIG_START( c64pal, driver_device )
727static MACHINE_CONFIG_START( c64pal, c64_state )
725728   MDRV_CPU_ADD( "maincpu", M6510, VIC6569_CLOCK)
726729   MDRV_CPU_PROGRAM_MAP(c64_mem)
727730   MDRV_CPU_CONFIG( c64_m6510_interface )
docs/messnew.txt
r9686r9687
3737- [C64] Added known good dumps softlist for cartridges. Not hooked up
3838  to driver code yet. [Curt Coder]
3939
40- [C64] Multisession fixes.  [Atari Ace]
41
4042- [CHANNELF/LYNX/SPECIAL/SVISION/WSWAN] Tokenized audio state.  [Atari Ace]
4143
4244- [GENESIS] Added support for several genesis PCB carts [El Barto]

Previous 15994 Revisions Next


© 1998-2018 The MESS Team