Previous 15994 Revisions Next

r5843 Tuesday 22nd September, 2009 at 12:37:53 UTC by Fabio Priuli
[CBM] Misc work:
- Fixed sx64 & c16c regressions from rev 4777
- Made CBM drivers a bit more robust at multisession emulation (more work may be needed)
- As a result, fixed longstanding bug #1387
- Run srcclean and done some cosmetic changes
[src/mess/includes]vc1541.h
[src/mess/machine]c128.c c16.c c64.c c65.c cbm.c cbmb.c cbmdrive.c cbmieeeb.c cbmipt.c cbmserb.c pet.c vc1541.c vc20.c
[src/mess/video]ted7360.c

src/mess/video/ted7360.c
r5842r5843
352352   and reads the rasterline value!
353353   so i no exact column value reachable!
354354*/
355#include <math.h>
356#include <stdio.h>
357355#include "driver.h"
358356#include "utils.h"
359357
360358#include "includes/c16.h"
361359
362#include "ted7360.h"
360#include "video/ted7360.h"
363361
364362
365363#define VERBOSE_LEVEL 0
r5842r5843
487485   0xd1, 0xff, 0xff, 0xeb, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xed, 0xff, 0xbc
488486};
489487
490UINT8 ted7360[0x20] =
491{0};
492
488UINT8 ted7360[0x20];
493489int ted7360_pal;
494490int ted7360_rom;
495491
496492static int lines;
497493static int timer1_active, timer2_active, timer3_active;
498494static emu_timer *timer1, *timer2, *timer3;
499static int cursor1 = FALSE;
495static int cursor1;
500496static read8_space_func vic_dma_read;
501497static read8_space_func vic_dma_read_rom;
502498static int chargenaddr, bitmapaddr, videoaddr;
r5842r5843
530526
531527static TIMER_CALLBACK(ted7360_timer_timeout);
532528
533void ted7360_init (running_machine *machine, int pal)
529void ted7360_init( running_machine *machine, int pal )
534530{
535531   ted7360_pal = pal;
536532   lines = TED7360_LINES;
r5842r5843
957953   /* cursorelement->colortable = cursorcolortable; */
958954   cursorcolortable[1] = 1;
959955   cursorelement->total_colors = 2;
956   cursor1 = FALSE;
960957   ted7360_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16);
961958}
962959
src/mess/includes/vc1541.h
r5842r5843
4444};
4545
4646
47void drive_config(running_machine *machine, int type, int id, int mode, const char *cputag, int devicenr);
47void cbm_drive_config(running_machine *machine, int type, int id, int mode, const char *cputag, int devicenr);
4848void c1551_config(running_machine *machine, const char *cputag);
49void drive_reset(void);
49void cbm_drive_reset(running_machine *machine);
5050void c1551_drive_reset(void);
5151
5252void vc1541_device_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info);
src/mess/machine/c65.c
r5842r5843
11/***************************************************************************
2   commodore c65 home computer
3   peter.trauner@jk.uni-linz.ac.at
2    commodore c65 home computer
3    peter.trauner@jk.uni-linz.ac.at
44    documention
55     www.funet.fi
66 ***************************************************************************/
r5842r5843
3030      } \
3131   } while (0)
3232
33static int c65_charset_select = 0;
33static int c65_charset_select;
3434
35static int c64mode = 0;
35static int c64mode;
3636
37static UINT8 c65_6511_port = 0xff;
37static UINT8 c65_6511_port;
3838static UINT8 c65_keyline = { 0xff };
3939
4040static UINT8 serial_clock, serial_data, serial_atn;
41static UINT8 vicirq = 0;
41static UINT8 vicirq;
4242
4343/*UINT8 *c65_basic; */
4444/*UINT8 *c65_kernal; */
r5842r5843
4949/*UINT8 *c65_graphics; */
5050
5151
52static void c65_nmi(running_machine *machine)
52static void c65_nmi( running_machine *machine )
5353{
5454   static int nmilevel = 0;
5555   const device_config *cia_1 = devtag_get_device(machine, "cia_1");
r5842r5843
6666
6767/***********************************************
6868
69   CIA Interfaces
69    CIA Interfaces
7070
7171***********************************************/
7272
7373/*
74 *   CIA 0 - Port A keyboard line select
75 *   CIA 0 - Port B keyboard line read
74 *  CIA 0 - Port A keyboard line select
75 *  CIA 0 - Port B keyboard line read
7676 *
77 *   flag cassette read input, serial request in
78 *   irq to irq connected
77 *  flag cassette read input, serial request in
78 *  irq to irq connected
7979 *
80 *   see machine/cbm.c
80 *  see machine/cbm.c
8181 */
8282
8383static READ8_DEVICE_HANDLER( c65_cia0_port_a_r )
r5842r5843
102102
103103static WRITE8_DEVICE_HANDLER( c65_cia0_port_b_w )
104104{
105//   was there lightpen support in c65 video chip?
106//   vic2_lightpen_write(data & 0x10);
105//  was there lightpen support in c65 video chip?
106//  vic2_lightpen_write(data & 0x10);
107107}
108108
109static void c65_irq (running_machine *machine, int level)
109static void c65_irq( running_machine *machine, int level )
110110{
111111   static int old_level = 0;
112112
r5842r5843
119119}
120120
121121/* is this correct for c65 as well as c64? */
122static void c65_cia0_interrupt (const device_config *device, int level)
122static void c65_cia0_interrupt( const device_config *device, int level )
123123{
124124   c65_irq (device->machine, level || vicirq);
125125}
126126
127127/* is this correct for c65 as well as c64? */
128static void c65_vic_interrupt (running_machine *machine, int level)
128static void c65_vic_interrupt( running_machine *machine, int level )
129129{
130130   const device_config *cia_0 = devtag_get_device(machine, "cia_0");
131131#if 1
r5842r5843
209209   c64_vicaddr = c64_memory + helper[data & 0x03];
210210}
211211
212static void c65_cia1_interrupt (const device_config *device, int level)
212static void c65_cia1_interrupt( const device_config *device, int level )
213213{
214214   c65_nmi(device->machine);
215215}
r5842r5843
241241
242242/***********************************************
243243
244   Memory Handlers
244    Memory Handlers
245245
246246***********************************************/
247247
248248/* processor has only 1 mega address space !? */
249249/* and system 8 megabyte */
250250/* dma controller and bankswitch hardware ?*/
251static READ8_HANDLER(c65_read_mem)
251static READ8_HANDLER( c65_read_mem )
252252{
253253   UINT8 result;
254   if (offset <= 0x0FFFF)
254   if (offset <= 0x0ffff)
255255      result = c64_memory[offset];
256256   else
257257      result = memory_read_byte(space, offset);
258258   return result;
259259}
260260
261static WRITE8_HANDLER(c65_write_mem)
261static WRITE8_HANDLER( c65_write_mem )
262262{
263   if (offset <= 0x0FFFF)
263   if (offset <= 0x0ffff)
264264      c64_memory[offset] = data;
265265   else
266266      memory_write_byte(space, offset, data);
r5842r5843
275275   writing banknumber to offset 2
276276   writing hibyte to offset 1
277277   writing lobyte to offset 0
278    cpu holded, dma transfer (data at address) executed, cpu activated
278    cpu holded, dma transfer(data at address) executed, cpu activated
279279
280280  command data:
281281   0 command (0 copy, 3 fill)
r5842r5843
295295   version 2:
296296   cmd 0x30 used for this
297297*/
298static void c65_dma_port_w(running_machine *machine, int offset, int value)
298static void c65_dma_port_w( running_machine *machine, int offset, int value )
299299{
300300   static int dump = 0;
301301   PAIR pair, src, dst, len;
r5842r5843
303303   int i;
304304   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
305305
306   switch (offset & 3)
306   switch (offset & 3)
307307   {
308308   case 2:
309309   case 1:
r5842r5843
327327      dst.b.h = c65_read_mem(space, pair.d++);
328328      dst.b.h2 = c65_read_mem(space, pair.d++);
329329
330      switch (cmd)
330      switch (cmd)
331331      {
332332      case 0:
333333         if (src.d == 0x3ffff) dump = 1;
r5842r5843
337337                   len.w.l, src.d, dst.d, c65_read_mem(space, pair.d),
338338                   c65_read_mem(space, pair.d + 1) ) );
339339         if ((dma.version == 1)
340             && ( (src.d&0x400000) || (dst.d & 0x400000)))
340             && ( (src.d&0x400000) || (dst.d & 0x400000)))
341341         {
342            if (!(src.d & 0x400000))
342            if (!(src.d & 0x400000))
343343            {
344344               dst.d &= ~0x400000;
345345               for (i = 0; i < len.w.l; i++)
346346                  c65_write_mem(space, dst.d--, c65_read_mem(space, src.d++));
347347            }
348            else if (!(dst.d & 0x400000))
348            else if (!(dst.d & 0x400000))
349349            {
350350               src.d &= ~0x400000;
351351               for (i = 0; i < len.w.l; i++)
352352                  c65_write_mem(space, dst.d++, c65_read_mem(space, src.d--));
353            }
354            else
353            }
354            else
355355            {
356356               src.d &= ~0x400000;
357357               dst.d &= ~0x400000;
358358               for (i = 0; i < len.w.l; i++)
359359                  c65_write_mem(space, --dst.d, c65_read_mem(space, --src.d));
360360            }
361         }
362         else
361         }
362         else
363363         {
364364            for (i = 0; i < len.w.l; i++)
365365               c65_write_mem(space, dst.d++, c65_read_mem(space, src.d++));
r5842r5843
394394   }
395395}
396396
397static int c65_dma_port_r(running_machine *machine, int offset)
397static int c65_dma_port_r( running_machine *machine, int offset )
398398{
399399   /* offset 3 bit 7 in progress ? */
400400   DBG_LOG(machine, 2, "dma chip read", ("%.3x\n", offset));
401401    return 0x7f;
402402}
403403
404static void c65_6511_port_w(running_machine *machine, int offset, int value)
404static void c65_6511_port_w( running_machine *machine, int offset, int value )
405405{
406   if (offset == 7)
406   if (offset == 7)
407407   {
408408      c65_6511_port = value;
409409   }
410410   DBG_LOG(machine, 2, "r6511 write", ("%.2x %.2x\n", offset, value));
411411}
412412
413static int c65_6511_port_r(running_machine *machine, int offset)
413static int c65_6511_port_r( running_machine *machine, int offset )
414414{
415415   int data = 0xff;
416416
417   if (offset == 7)
417   if (offset == 7)
418418   {
419      if (input_port_read(machine, "SPECIAL") & 0x20)
419      if (input_port_read(machine, "SPECIAL") & 0x20)
420420         data &= ~1;
421421   }
422422   DBG_LOG(machine, 2, "r6511 read", ("%.2x\n", offset));
r5842r5843
537537#if 0
538538static void c65_fdc_state(void)
539539{
540   switch (c65_fdc.state)
540   switch (c65_fdc.state)
541541   {
542542   case FDC_CMD_MOTOR_SPIN_UP:
543      if (timer_get_time(machine) - c65_fdc.time)
543      if (timer_get_time(machine) - c65_fdc.time)
544544      {
545545         c65_fdc.state = 0;
546546         c65_fdc.status &= ~FDC_BUSY;
r5842r5843
553553static void c65_fdc_w( running_machine *machine, int offset, int data )
554554{
555555   DBG_LOG(machine, 1, "fdc write", ("%.5x %.2x %.2x\n", cpu_get_pc(cputag_get_cpu(machine, "maincpu")), offset, data));
556   switch (offset & 0xf)
556   switch (offset & 0xf)
557557   {
558558   case 0:
559559      c65_fdc.reg[0] = data;
560560      break;
561561   case 1:
562562      c65_fdc.reg[1] = data;
563      switch (data & 0xf9)
563      switch (data & 0xf9)
564564      {
565565      case 0x20: // wait for motor spin up
566566         c65_fdc.status &= ~(FDC_IRQ|FDC_LOST|FDC_CRC|FDC_RNF);
r5842r5843
606606static int c65_fdc_r( running_machine *machine, int offset )
607607{
608608   UINT8 data = 0;
609   switch (offset & 0xf)
609   switch (offset & 0xf)
610610   {
611611   case 0:
612612      data = c65_fdc.reg[0];
r5842r5843
659659   UINT8 reg;
660660} expansion_ram = {0};
661661
662static READ8_HANDLER(c65_ram_expansion_r)
662static READ8_HANDLER( c65_ram_expansion_r )
663663{
664664   UINT8 data = 0xff;
665665   if (mess_ram_size > (128 * 1024))
r5842r5843
667667   return data;
668668}
669669
670static WRITE8_HANDLER(c65_ram_expansion_w)
670static WRITE8_HANDLER( c65_ram_expansion_w )
671671{
672672   offs_t expansion_ram_begin;
673673   offs_t expansion_ram_end;
r5842r5843
689689   }
690690}
691691
692static WRITE8_HANDLER ( c65_write_io )
692static WRITE8_HANDLER( c65_write_io )
693693{
694694   const device_config *sid_0 = devtag_get_device(space->machine, "sid_r");
695695   const device_config *sid_1 = devtag_get_device(space->machine, "sid_l");
696696
697   switch(offset&0xf00) {
697   switch (offset & 0xf00)
698   {
698699   case 0x000:
699700      if (offset < 0x80)
700         vic3_port_w (space, offset & 0x7f, data);
701      else if (offset < 0xa0) {
701         vic3_port_w(space, offset & 0x7f, data);
702      else if (offset < 0xa0)
702703         c65_fdc_w(space->machine, offset&0x1f,data);
703      } else {
704      else
705      {
704706         c65_ram_expansion_w(space, offset&0x1f, data);
705707         /*ram expansion crtl optional */
706708      }
707709      break;
708   case 0x100:case 0x200: case 0x300:
710   case 0x100:
711   case 0x200:
712   case 0x300:
709713      vic3_palette_w(space, offset-0x100,data);
710714      break;
711715   case 0x400:
r5842r5843
728732   }
729733}
730734
731static WRITE8_HANDLER ( c65_write_io_dc00 )
735static WRITE8_HANDLER( c65_write_io_dc00 )
732736{
733737   const device_config *cia_0 = devtag_get_device(space->machine, "cia_0");
734738   const device_config *cia_1 = devtag_get_device(space->machine, "cia_1");
735739
736   switch(offset & 0xf00)
740   switch (offset & 0xf00)
737741   {
738742   case 0x000:
739743      cia_w(cia_0, offset, data);
r5842r5843
748752   }
749753}
750754
751static READ8_HANDLER ( c65_read_io )
755static READ8_HANDLER( c65_read_io )
752756{
753757   const device_config *sid_0 = devtag_get_device(space->machine, "sid_r");
754758   const device_config *sid_1 = devtag_get_device(space->machine, "sid_l");
755759
756   switch(offset & 0xf00)
760   switch (offset & 0xf00)
757761   {
758762   case 0x000:
759763      if (offset < 0x80)
760         return vic3_port_r (space, offset & 0x7f);
761      if (offset < 0xa0)
762      {
764         return vic3_port_r(space, offset & 0x7f);
765      if (offset < 0xa0)
763766         return c65_fdc_r(space->machine, offset&0x1f);
764      }
765      else
767      else
766768      {
767769         return c65_ram_expansion_r(space, offset&0x1f);
768770         /*return; ram expansion crtl optional */
769771      }
770772      break;
771773   case 0x100:
772   case 0x200:
774   case 0x200:
773775   case 0x300:
774776   /* read only !? */
775777      DBG_LOG(space->machine, 1, "io read", ("%.3x\n", offset));
r5842r5843
792794   return 0xff;
793795}
794796
795static READ8_HANDLER ( c65_read_io_dc00 )
797static READ8_HANDLER( c65_read_io_dc00 )
796798{
797799   const device_config *cia_0 = devtag_get_device(space->machine, "cia_0");
798800   const device_config *cia_1 = devtag_get_device(space->machine, "cia_1");
799801
800   switch(offset & 0x300)
802   switch (offset & 0x300)
801803   {
802804   case 0x000:
803805      return cia_r(cia_0, offset);
r5842r5843
822824/* bit 1 external sync enable (genlock)
823825   bit 2 palette enable
824826   bit 6 vic3 c65 character set */
825static void c65_bankswitch_interface(running_machine *machine, int value)
827static void c65_bankswitch_interface( running_machine *machine, int value )
826828{
827829   static int old = 0;
828830   read8_space_func rh;
r5842r5843
848850      memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0dc00, 0x0dfff, 0, 0, wh);
849851   }
850852
851   c65_io_dc00_on =! (value & 1);
853   c65_io_dc00_on = !(value & 1);
852854#if 0
853855   /* cartridge roms !?*/
854856   if (value & 0x08)
855      memory_set_bankptr (machine, 1, c64_roml);
857      memory_set_bankptr(machine, 1, c64_roml);
856858   else
857      memory_set_bankptr (machine, 1, c64_memory + 0x8000);
859      memory_set_bankptr(machine, 1, c64_memory + 0x8000);
858860
859861   if (value & 0x10)
860      memory_set_bankptr (machine, 2, c64_basic);
862      memory_set_bankptr(machine, 2, c64_basic);
861863   else
862      memory_set_bankptr (machine, 2, c64_memory + 0xa000);
864      memory_set_bankptr(machine, 2, c64_memory + 0xa000);
863865#endif
864   if ((old^value) & 0x20)
865   {
866   if ((old^value) & 0x20)
867   {
866868   /* bankswitching faulty when doing actual page */
867      if (value & 0x20)
868         memory_set_bankptr (machine, 3, c65_interface);
869      if (value & 0x20)
870         memory_set_bankptr(machine, 3, c65_interface);
869871      else
870         memory_set_bankptr (machine, 3, c64_memory + 0xc000);
872         memory_set_bankptr(machine, 3, c64_memory + 0xc000);
871873   }
872   c65_charset_select=value&0x40;
874   c65_charset_select = value & 0x40;
873875#if 0
874876   /* cartridge roms !?*/
875877   if (value & 0x80)
876      memory_set_bankptr (machine, 8, c64_kernal);
878      memory_set_bankptr(machine, 8, c64_kernal);
877879   else
878      memory_set_bankptr (machine, 6, c64_memory + 0xe000);
880      memory_set_bankptr(machine, 6, c64_memory + 0xe000);
879881#endif
880   old=value;
882   old = value;
881883}
882884
883void c65_bankswitch (running_machine *machine)
885void c65_bankswitch( running_machine *machine )
884886{
885887   static int old = -1;
886888   int data, loram, hiram, charen;
r5842r5843
896898   hiram = (data & 2) ? 1 : 0;
897899   charen = (data & 4) ? 1 : 0;
898900
899   if ((!c64_game && c64_exrom)
900      || (loram && hiram && !c64_exrom))
901   {
902      memory_set_bankptr (machine, 1, c64_roml);
903   }
901   if ((!c64_game && c64_exrom) || (loram && hiram && !c64_exrom))
902      memory_set_bankptr(machine, 1, c64_roml);
904903   else
905   {
906      memory_set_bankptr (machine, 1, c64_memory + 0x8000);
907   }
904      memory_set_bankptr(machine, 1, c64_memory + 0x8000);
908905
909   if ((!c64_game && c64_exrom && hiram)
910      || (!c64_exrom))
911   {
912      memory_set_bankptr (machine, 2, c64_romh);
913   }
906   if ((!c64_game && c64_exrom && hiram) || (!c64_exrom))
907      memory_set_bankptr(machine, 2, c64_romh);
914908   else if (loram && hiram)
915   {
916      memory_set_bankptr (machine, 2, c64_basic);
917   }
909      memory_set_bankptr(machine, 2, c64_basic);
918910   else
919   {
920      memory_set_bankptr (machine, 2, c64_memory + 0xa000);
921   }
911      memory_set_bankptr(machine, 2, c64_memory + 0xa000);
922912
923   if ((!c64_game && c64_exrom)
924      || (charen && (loram || hiram)))
913   if ((!c64_game && c64_exrom) || (charen && (loram || hiram)))
925914   {
926915      c65_io_on = 1;
927916      rh4 = c65_read_io;
928917      wh5 = c65_write_io;
929      memory_set_bankptr (machine, 6, c64_colorram);
930      memory_set_bankptr (machine, 7, c64_colorram);
918      memory_set_bankptr(machine, 6, c64_colorram);
919      memory_set_bankptr(machine, 7, c64_colorram);
931920
932921      if (c65_io_dc00_on)
933922      {
r5842r5843
938927      {
939928         rh8 = SMH_BANK(8);
940929         wh9 = SMH_BANK(9);
941         memory_set_bankptr (machine, 8, c64_colorram+0x400);
942         memory_set_bankptr (machine, 9, c64_colorram+0x400);
930         memory_set_bankptr(machine, 8, c64_colorram + 0x400);
931         memory_set_bankptr(machine, 9, c64_colorram + 0x400);
943932      }
944933      memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0dc00, 0x0dfff, 0, 0, rh8);
945934      memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0dc00, 0x0dfff, 0, 0, wh9);
r5842r5843
949938      c65_io_on = 0;
950939      rh4 = SMH_BANK(4);
951940      wh5 = SMH_BANK(5);
952      memory_set_bankptr(machine, 5, c64_memory+0xd000);
953      memory_set_bankptr(machine, 7, c64_memory+0xd800);
954      memory_set_bankptr(machine, 9, c64_memory+0xdc00);
941      memory_set_bankptr(machine, 5, c64_memory + 0xd000);
942      memory_set_bankptr(machine, 7, c64_memory + 0xd800);
943      memory_set_bankptr(machine, 9, c64_memory + 0xdc00);
955944      if (!charen && (loram || hiram))
956945      {
957         memory_set_bankptr (machine, 4, c64_chargen);
958         memory_set_bankptr (machine, 6, c64_chargen+0x800);
959         memory_set_bankptr (machine, 8, c64_chargen+0xc00);
946         memory_set_bankptr(machine, 4, c64_chargen);
947         memory_set_bankptr(machine, 6, c64_chargen + 0x800);
948         memory_set_bankptr(machine, 8, c64_chargen + 0xc00);
960949      }
961950      else
962951      {
963         memory_set_bankptr (machine, 4, c64_memory + 0xd000);
964         memory_set_bankptr (machine, 6, c64_memory + 0xd800);
965         memory_set_bankptr (machine, 8, c64_memory + 0xdc00);
952         memory_set_bankptr(machine, 4, c64_memory + 0xd000);
953         memory_set_bankptr(machine, 6, c64_memory + 0xd800);
954         memory_set_bankptr(machine, 8, c64_memory + 0xdc00);
966955      }
967956   }
968957   memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0d000, 0x0d7ff, 0, 0, rh4);
r5842r5843
970959
971960   if (!c64_game && c64_exrom)
972961   {
973      memory_set_bankptr (machine, 10, c64_romh);
962      memory_set_bankptr(machine, 10, c64_romh);
974963   }
975964   else
976965   {
977966      if (hiram)
978967      {
979         memory_set_bankptr (machine, 10, c64_kernal);
968         memory_set_bankptr(machine, 10, c64_kernal);
980969      }
981970      else
982971      {
983         memory_set_bankptr (machine, 10, c64_memory + 0xe000);
972         memory_set_bankptr(machine, 10, c64_memory + 0xe000);
984973      }
985974   }
986975   old = data;
987976}
988977
989void c65_colorram_write (int offset, int value)
978void c65_colorram_write( int offset, int value )
990979{
991980   c64_colorram[offset & 0x7ff] = value | 0xf0;
992981}
r5842r5843
996985 * a15 and a14 portlines
997986 * 0x1000-0x1fff, 0x9000-0x9fff char rom
998987 */
999static int c65_dma_read(running_machine *machine, int offset)
988static int c65_dma_read( running_machine *machine, int offset )
1000989{
1001990   if (!c64_game && c64_exrom)
1002991   {
r5842r5843
10191008   return c64_vicaddr[offset & 0x3fff];
10201009}
10211010
1022static int c65_dma_read_color(running_machine *machine, int offset)
1011static int c65_dma_read_color( running_machine *machine, int offset )
10231012{
1024   if (c64mode) return c64_colorram[offset&0x3ff]&0xf;
1013   if (c64mode)
1014      return c64_colorram[offset & 0x3ff] & 0xf;
10251015   return c64_colorram[offset & 0x7ff];
10261016}
10271017
1028static void c65_common_driver_init (running_machine *machine)
1018static void c65_common_driver_init( running_machine *machine )
10291019{
10301020   c64_memory = auto_alloc_array_clear(machine, UINT8, 0x10000);
10311021   memory_set_bankptr(machine, 11, c64_memory + 0x00000);
r5842r5843
10341024   memory_set_bankptr(machine, 14, c64_memory + 0x0c000);
10351025   memory_set_bankptr(machine, 15, c64_memory + 0x0e000);
10361026
1027   c65_charset_select = 0;
1028   c65_6511_port = 0xff;
1029   vicirq = 0;
1030
10371031   /* C65 had no datasette port */
10381032   c64_tape_on = 0;
10391033
1040   /*memset(c64_memory+0x40000, 0, 0x800000-0x40000); */
1034   /*memset(c64_memory + 0x40000, 0, 0x800000 - 0x40000); */
10411035
10421036   vic4567_init(machine, c64_pal, c65_dma_read, c65_dma_read_color, c65_vic_interrupt, c65_bankswitch_interface);
10431037}
r5842r5843
10471041   c64_pal = 0;
10481042   dma.version = 2;
10491043   c65_common_driver_init(machine);
1050
10511044}
10521045
10531046DRIVER_INIT( c65pal )
src/mess/machine/cbmb.c
r5842r5843
3636      } \
3737   } while (0)
3838
39static TIMER_CALLBACK(cbmb_frame_interrupt);
39static TIMER_CALLBACK( cbmb_frame_interrupt );
4040/* keyboard lines */
4141static int cbmb_keyline_a, cbmb_keyline_b, cbmb_keyline_c;
4242
r5842r5843
7373   const device_config *ieeebus = devtag_get_device(device->machine, "ieee_bus");
7474   int data = 0;
7575
76   if (cbm_ieee_nrfd_r(ieeebus, 0))
76   if (cbm_ieee_nrfd_r(ieeebus, 0))
7777      data |= 0x80;
7878
79   if (cbm_ieee_ndac_r(ieeebus, 0))
79   if (cbm_ieee_ndac_r(ieeebus, 0))
8080      data |= 0x40;
8181
82   if (cbm_ieee_eoi_r(ieeebus, 0))
82   if (cbm_ieee_eoi_r(ieeebus, 0))
8383      data |= 0x20;
8484
85   if (cbm_ieee_dav_r(ieeebus, 0))
85   if (cbm_ieee_dav_r(ieeebus, 0))
8686      data |= 0x10;
8787
88   if (cbm_ieee_atn_r(ieeebus, 0))
88   if (cbm_ieee_atn_r(ieeebus, 0))
8989      data |= 0x08;
9090
91/*  if (cbm_ieee_ren_r(ieeebus, 0))
92      data |= 0x04; */
91/*  if (cbm_ieee_ren_r(ieeebus, 0))
92        data |= 0x04; */
9393
9494   return data;
9595}
r5842r5843
221221   return data ^0xff;
222222}
223223
224void cbmb_irq(const device_config *device, int level)
224void cbmb_irq( const device_config *device, int level )
225225{
226226   static int old_level = 0;
227227
r5842r5843
266266   }
267267};
268268
269WRITE8_HANDLER ( cbmb_colorram_w )
269WRITE8_HANDLER( cbmb_colorram_w )
270270{
271271   cbmb_colorram[offset] = data | 0xf0;
272272}
273273
274static int cbmb_dma_read(running_machine *machine, int offset)
274static int cbmb_dma_read( running_machine *machine, int offset )
275275{
276276   if (offset >= 0x1000)
277277      return cbmb_videoram[offset & 0x3ff];
r5842r5843
279279      return cbmb_chargen[offset & 0xfff];
280280}
281281
282static int cbmb_dma_read_color(running_machine *machine, int offset)
282static int cbmb_dma_read_color( running_machine *machine, int offset )
283283{
284284   return cbmb_colorram[offset & 0x3ff];
285285}
r5842r5843
289289   cbmb_vh_set_font(data);
290290}
291291
292static void cbmb_common_driver_init(running_machine *machine)
292static void cbmb_common_driver_init( running_machine *machine )
293293{
294294   cbmb_state *state = machine->driver_data;
295   cbmb_chargen=memory_region(machine, "maincpu") + 0x100000;
295   cbmb_chargen = memory_region(machine, "maincpu") + 0x100000;
296296   /*    memset(c64_memory, 0, 0xfd00); */
297297
298298   timer_pulse(machine, ATTOTIME_IN_MSEC(10), NULL, 0, cbmb_frame_interrupt);
r5842r5843
365365
366366#if 0
367367   value = 0xff;
368   switch(controller1)
368   switch (controller1)
369369   {
370370      case 0x00:
371371         value &= ~input_port_read(machine, "JOY1_1B");         /* Joy1 Directions + Button 1 */
r5842r5843
407407
408408
409409   value = 0xff;
410   switch(controller2)
410   switch (controller2)
411411   {
412412      case 0x00:
413413         value &= ~input_port_read(machine, "JOY2_1B");         /* Joy2 Directions + Button 1 */
r5842r5843
451451// 128u4 FIXME
452452//  vic2_frame_interrupt (device);
453453
454   set_led_status (1, input_port_read(machine, "SPECIAL") & 0x04 ? 1 : 0);      /* Shift Lock */
454   set_led_status(1, input_port_read(machine, "SPECIAL") & 0x04 ? 1 : 0);      /* Shift Lock */
455455}
456456
457457
r5842r5843
472472
473473   filetype = image_filetype(image);
474474
475    if (!mame_stricmp (filetype, "crt"))
475    if (!mame_stricmp(filetype, "crt"))
476476   {
477477   /* We temporarily remove .crt loading. Previous versions directly used
478478    the same routines used to load C64 .crt file, but I seriously doubt the
r5842r5843
482482   else
483483   {
484484      /* Assign loading address according to extension */
485      if (!mame_stricmp (filetype, "10"))
485      if (!mame_stricmp(filetype, "10"))
486486         address = 0x1000;
487487
488      else if (!mame_stricmp (filetype, "20"))
488      else if (!mame_stricmp(filetype, "20"))
489489         address = 0x2000;
490490
491      else if (!mame_stricmp (filetype, "40"))
491      else if (!mame_stricmp(filetype, "40"))
492492         address = 0x4000;
493493
494      else if (!mame_stricmp (filetype, "60"))
494      else if (!mame_stricmp(filetype, "60"))
495495         address = 0x6000;
496496
497497      logerror("Loading cart %s at %.4x size:%.4x\n", image_filename(image), address, size);
src/mess/machine/vc1541.c
r5842r5843
9696 2 heads
9797
9898 */
99/* 2008-09 FP
99/* 2008-09 FP
100100Started some work on the floppy emulation code:
101   + made the functions / structs less vc1541-centric & d64-centric
102   + unified config & reset functions, using type variable
103      to choose the actions to be done
104   + moved GCR encoding at loading time (wip untested code)
105 
101    + made the functions / structs less vc1541-centric & d64-centric
102    + unified config & reset functions, using type variable
103        to choose the actions to be done
104    + moved GCR encoding at loading time (wip untested code)
105
106106A limitation is clear: only a single occurrence of emulated drive
107is expected.
107is expected.
108108At a later stage, at least drive_config & drive_reset will need
109109an index to choose between the drives
110110In the end, we could also split the floppy drives emulation from the
111111disk image handling...
112112
113113Current status:
114   + preliminary vc1541 & c1551 implementation (quite slow, especially
115      if you turn on logging)
116   + no support for other drive types (even if now I list all
117      the variants supported by Vice in the enum)
118   + communications between the drive CPU and the computer CPU have
119      to be checked, debugged and improved: somehow it works, but no
120      sync bit is set (encoding bug? timers-related bug?) and the drive
121      keeps reading beyond the end of the track (synchronization
122      problems?)
123   + all but .g64 images should be correctly encoded at loading time
124      (I actually have doubts about some .d82 details)
125   + error maps are not still used, even if their presence is
126      acknowledged
127   + floppy drives should become devices and use ROMREGION_LOADBYNAME
128      for their ROMs (not the current defines)
129   + all available drive dumps are included for each systems using it
130      (vc1541 = sx64, vip64, c16v, plus4v; vc1571 = c128d; vc1571cr = c128dcr;
131      vc1581 = c128d81; vc1540 = vc20v, vic20plv; c2031 = vc20i (only dumps added);
132      c1551 = c16c, plus4c). this is only a temporary workaround to document
133      available dumps. correct revisions will be used with each systems when
134      emulation works (or 'default' bios will be used for most common
135      configurations, when machines were compatible with more than a single
136      drive model)
114    + preliminary vc1541 & c1551 implementation (quite slow, especially
115        if you turn on logging)
116    + no support for other drive types (even if now I list all
117        the variants supported by Vice in the enum)
118    + communications between the drive CPU and the computer CPU have
119        to be checked, debugged and improved: somehow it works, but no
120        sync bit is set (encoding bug? timers-related bug?) and the drive
121        keeps reading beyond the end of the track (synchronization
122        problems?)
123    + all but .g64 images should be correctly encoded at loading time
124        (I actually have doubts about some .d82 details)
125    + error maps are not still used, even if their presence is
126        acknowledged
127    + floppy drives should become devices and use ROMREGION_LOADBYNAME
128        for their ROMs (not the current defines)
129    + all available drive dumps are included for each systems using it
130        (vc1541 = sx64, vip64, c16v, plus4v; vc1571 = c128d; vc1571cr = c128dcr;
131        vc1581 = c128d81; vc1540 = vc20v, vic20plv; c2031 = vc20i (only dumps added);
132        c1551 = c16c, plus4c). this is only a temporary workaround to document
133        available dumps. correct revisions will be used with each systems when
134        emulation works (or 'default' bios will be used for most common
135        configurations, when machines were compatible with more than a single
136        drive model)
137137*/
138138/*
139139Informations on the fileformats (which the code is based on)
r5842r5843
146146GCR - http://www.baltissen.org/newhtm/1541c.htm
147147
148148Other info sources:
149   http://sta.c64.org/cbm1541mem.html
149    http://sta.c64.org/cbm1541mem.html
150150
151151*/
152152
r5842r5843
184184
185185/*******************************************
186186
187   Structures
187    Structures
188188
189189*******************************************/
190190
191191/* Legacy code. At a later stage, we should convert everything to devices.
192However, fixing the C64 / Floppy drive communications is a priority over
192However, fixing the C64 / Floppy drive communications is a priority over
193193cleaning up of this part */
194194
195195
r5842r5843
200200}
201201serial;
202202
203typedef struct
203typedef struct
204204{
205205   int sync;            // active after > 9 '1's
206206   int ones_count;
207207   int ready;            // needed for 1551
208   UINT8 data[0x500000];   // entire d64 image encoded at loading time
208   UINT8 *data;         // entire d64 image encoded at loading time
209209} GCR_data;
210210
211211typedef struct
r5842r5843
232232
233233   int via0irq, via1irq;
234234
235} vc1541_drive_emu;
235} _vc1541_drive_emu_t;
236236
237237typedef struct
238238{
r5842r5843
253253   UINT8 cpu_ddr, cpu_port;
254254   void *irq_timer;
255255
256} c1551_drive_emu;
256} _c1551_drive_emu_t;
257257
258static vc1541_drive_emu vc1541_drive_static = { 0 }, *vc1541_drive = &vc1541_drive_static;
259static c1551_drive_emu c1551_drive_static = { 0 }, *c1551_drive = &c1551_drive_static;
258static _vc1541_drive_emu_t vc1541_drive;
259static _c1551_drive_emu_t c1551_drive;
260260
261261
262262/*******************************************
263263
264   Format specific code
264    Format specific code
265265
266266*******************************************/
267267
r5842r5843
279279   18, 18, 18, 18, 18, 18,
280280   17, 17, 17, 17, 17,
281281   17, 17, 17, 17, 17,      /* only for 40 tracks d64 */
282   17, 17               /* in principle the drive could read 42 tracks */
282   17, 17            /* in principle the drive could read 42 tracks */
283283};
284284
285285#define D71_MAX_TRACKS 70
r5842r5843
305305static const int d80_sectors_per_track[] =
306306{
307307   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
308   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
308   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
309309   27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
310310   25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
311311   23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23
r5842r5843
319319static const int d82_sectors_per_track[] =
320320{
321321   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
322   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
322   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
323323   27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
324324   25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
325325   23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
326326   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
327   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
327   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
328328   27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
329329   25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
330330   23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23
r5842r5843
346346   0      /* Still to add support for .g64 */
347347};
348348
349static int image_offset[IMAGE_MAX_TRACKS] = { 0 };
350static int gcr_offset[IMAGE_MAX_TRACKS] = { 0 };
349static int image_offset[IMAGE_MAX_TRACKS];
350static int gcr_offset[IMAGE_MAX_TRACKS];
351351
352352/*******************************************
353353
354   Offset initialization
354    Offset initialization
355355
356356*******************************************/
357357
r5842r5843
411411
412412/*******************************************
413413
414   Generic image handling
414    Generic image handling
415415
416416*******************************************/
417417
418418
419419/* This calculates starting offset (from the beginning of the image file) of a sector */
420420/* Since sectors are always 256 bytes large, this works no matter the file format! */
421static int image_tracksector2offset (int track, int sector)
421static int image_tracksector2offset( int track, int sector )
422422{
423423   return image_offset[track - 1] + sector * 256;
424424}
425425
426426/*
427427// WARNING: this would work with a d64 image... it has to be adapted to work with GCR image we store at loading time
428static void image_offset2tracksector (int offset)
428static void image_offset2tracksector( int offset )
429429{
430   int track = 0, sector = 0, helper, i = 0;
431   
432   helper = offset;
433   
434   do
435   {
436   helper -= (d64_sectors_per_track[++i] * 256);
437   } while ( helper > 0);
438   
439   track = i;
430    int track = 0, sector = 0, helper, i = 0;
440431
441   sector = (offset - image_offset[track]) / 256;
432    helper = offset;
442433
443   logerror("We are reading at offset %d, which is in track %d and sector %d \n", offset, track, sector);
434    do
435    {
436    helper -= (d64_sectors_per_track[++i] * 256);
437    } while (helper > 0);
438
439    track = i;
440
441    sector = (offset - image_offset[track]) / 256;
442
443    logerror("We are reading at offset %d, which is in track %d and sector %d \n", offset, track, sector);
444444}
445445*/
446446
r5842r5843
450450   indeed, in these cases a g64 image is needed (which stores the
451451   Disk ID as coded in the GCR data) */
452452
453static int disk_id1 (int format)
453static int disk_id1( int format )
454454{
455455   int id1 = 0;
456456
r5842r5843
480480         logerror("Unsupported format\n");
481481         break;
482482   }
483   
483
484484   return id1;
485485}
486486
487487
488static int disk_id2 (int format)
488static int disk_id2( int format )
489489{
490490   int id2 = 0;
491491
r5842r5843
515515         logerror("Unsupported format\n");
516516         break;
517517   }
518   
518
519519   return id2;
520520}
521521
522522
523523/* Four different frequencies for the 4 different zones on the disk */
524524/* These work for 1541 drives, are the same for other drives? */
525static const double drive_times[4]=
525static const double drive_times[4]=
526526{
527527   XTAL_16_MHz / 13, XTAL_16_MHz / 14, XTAL_16_MHz / 15, XTAL_16_MHz / 16
528528};
r5842r5843
530530
531531/* Commodore GCR format */
532532/*
533Original   Encoded
5344 bits      5 bits
533Original    Encoded
5344 bits      5 bits
535535
5360000   ->   01010 = 0x0a
5370001   ->   01011 = 0x0b
5380010   ->   10010 = 0x12
5390011   ->   10011 = 0x13
5400100   ->   01110 = 0x0e
5410101   ->   01111 = 0x0f
5420110   ->   10110 = 0x16
5430111   ->   10111 = 0x17
5441000   ->   01001 = 0x09
5451001   ->   11001 = 0x19
5461010   ->   11010 = 0x1a
5471011   ->   11011 = 0x1b
5481100   ->   01101 = 0x0d
5491101   ->   11101 = 0x1d
5501110   ->   11110 = 0x1e
5511111   ->   10101 = 0x15
5360000    ->  01010 = 0x0a
5370001    ->  01011 = 0x0b
5380010    ->  10010 = 0x12
5390011    ->  10011 = 0x13
5400100    ->  01110 = 0x0e
5410101    ->  01111 = 0x0f
5420110    ->  10110 = 0x16
5430111    ->  10111 = 0x17
5441000    ->  01001 = 0x09
5451001    ->  11001 = 0x19
5461010    ->  11010 = 0x1a
5471011    ->  11011 = 0x1b
5481100    ->  01101 = 0x0d
5491101    ->  11101 = 0x1d
5501110    ->  11110 = 0x1e
5511111    ->  10101 = 0x15
552552
553We use the encoded values in bytes because we use them to encode
553We use the encoded values in bytes because we use them to encode
554554groups of 4 bytes into groups of 5 bytes, below.
555555*/
556556
r5842r5843
563563
564564/* This could be of use if we ever implement saving in .d64 format, to convert back GCR -> d64 */
565565/*
566static const int gcr_2_bin[] =
566static const int gcr_2_bin[] =
567567{
568   -1, -1,   -1,   -1,
569   -1, -1,   -1,   -1,
570   -1, 0x08, 0x00, 0x01,
571   -1, 0x0c, 0x04, 0x05,
572   -1, -1,   0x02, 0x03,
573   -1, 0x0f, 0x06, 0x07,
574   -1, 0x09, 0x0a, 0x0b,
575   -1, 0x0d, 0x0e, -1
568    -1, -1,   -1,   -1,
569    -1, -1,   -1,   -1,
570    -1, 0x08, 0x00, 0x01,
571    -1, 0x0c, 0x04, 0x05,
572    -1, -1,   0x02, 0x03,
573    -1, 0x0f, 0x06, 0x07,
574    -1, 0x09, 0x0a, 0x0b,
575    -1, 0x0d, 0x0e, -1
576576};
577577*/
578578
579579
580580/* gcr_double_2_gcr takes 4 bytes (a, b, c, d) and shuffles their nibbles to obtain 5 bytes in dest */
581/* The result is basically res = (enc(a) << 15) | (enc(b) << 10) | (enc(c) << 5) | enc(d)
581/* The result is basically res = (enc(a) << 15) | (enc(b) << 10) | (enc(c) << 5) | enc(d)
582582 * with res being 5 bytes long and enc(x) being the GCR encode of x.
583583 * In fact, we store the result as five separate bytes in the dest argument
584584 */
585static void gcr_double_2_gcr(UINT8 a, UINT8 b, UINT8 c, UINT8 d, UINT8 *dest)
585static void gcr_double_2_gcr( UINT8 a, UINT8 b, UINT8 c, UINT8 d, UINT8 *dest )
586586{
587587   UINT8 gcr[8];
588588
r5842r5843
604604   dest[4] = (gcr[6] << 5) | gcr[7];
605605}
606606
607/* FIXME: temp workaround */
608static void filling_byte( UINT8 a, UINT8 *dest )
609{
610   dest[0] = a;
611}
607612
613
608614/**************************************
609615
610   Drive timers (aka floppy reading)
616    Drive timers (aka floppy reading)
611617
612618**************************************/
613619
614static TIMER_CALLBACK(vc1541_drive_timer)
620static TIMER_CALLBACK( vc1541_drive_timer )
615621{
616622   const device_config *via_1 = devtag_get_device(machine, "_1541_via_1");
617623
618   if (vc1541_drive->clock == 0)
624   if (vc1541_drive.clock == 0)
619625   {
620      vc1541_drive->gcr.ready = 0;
626      vc1541_drive.gcr.ready = 0;
621627      // why put sync back to 0 here?!? it would break the sync count, isn't it?
622628      // or is it the way the serial port reads the sync count?!?
623      vc1541_drive->gcr.sync = 0;
624   
625      cputag_set_input_line(machine, vc1541_drive->cputag, M6502_SET_OVERFLOW, 1);
629      vc1541_drive.gcr.sync = 0;
630
631      cputag_set_input_line(machine, vc1541_drive.cputag, M6502_SET_OVERFLOW, 1);
626632      via_ca1_w(via_1, 0, 1);
627633
628      vc1541_drive->clock = 1;
634      vc1541_drive.clock = 1;
629635      return;
630636   }
631637
632638   // this code has 2 effects: move on the pos on the data and reset it to 0 at the end of the track!
633639   // size of the track is: (# sectors in the track) * (size of sector GCR endoded)
634   // Here, size of sector is 368 because of our choices in the loading: 9 bytes of header gap & 14 bytes of sector gap
640   // Here, size of sector is 368 because of our choices in the loading: 9 bytes of header gap & 14 bytes of sector gap
635641   // We will need to set the size at loading time when adding support for G64 images
636   if (++(vc1541_drive->pos) >= (d64_sectors_per_track[(int)vc1541_drive->track - 1] * 368))
637      vc1541_drive->pos = 0;
642   if (++(vc1541_drive.pos) >= (d64_sectors_per_track[(int)vc1541_drive.track - 1] * 368))
643      vc1541_drive.pos = 0;
638644   // should we check if there is a change of track? to reset the pos in that case as well?
639645
640   vc1541_drive->gcr.ready = 1;
646   vc1541_drive.gcr.ready = 1;
641647
642   // notice that if there is a sequence of more than 40 1s it correctly does not reset the sync
648   // notice that if there is a sequence of more than 40 1s it correctly does not reset the sync
643649   // counter until a 0 is found
644   if (vc1541_drive->gcr.data[vc1541_drive->pos] == 0xff)
650   if (vc1541_drive.gcr.data[vc1541_drive.pos] == 0xff)
645651   {
646      vc1541_drive->gcr.ones_count++;
652      vc1541_drive.gcr.ones_count++;
647653
648//      if (vc1541_drive->gcr.ones_count == 2) // 9 ones should already mark it as a sync, even if CBM chose to use 40 of them
649      if (vc1541_drive->gcr.ones_count == 5)
650         vc1541_drive->gcr.sync = 1;
651   }
652   else
654//      if (vc1541_drive.gcr.ones_count == 2) // 9 ones should already mark it as a sync, even if CBM chose to use 40 of them
655      if (vc1541_drive.gcr.ones_count == 5)
656         vc1541_drive.gcr.sync = 1;
657   }
658   else
653659   {
654      vc1541_drive->gcr.ones_count = 0;
655      vc1541_drive->gcr.sync = 0;
660      vc1541_drive.gcr.ones_count = 0;
661      vc1541_drive.gcr.sync = 0;
656662   }
657663
658   cputag_set_input_line(machine, vc1541_drive->cputag, M6502_SET_OVERFLOW, 0);
664   cputag_set_input_line(machine, vc1541_drive.cputag, M6502_SET_OVERFLOW, 0);
659665   via_ca1_w(via_1, 0, 0);
660666
661   vc1541_drive->clock = 0;
667   vc1541_drive.clock = 0;
662668}
663669
664static TIMER_CALLBACK(c1551_drive_timer)
670static TIMER_CALLBACK( c1551_drive_timer )
665671{
666   if (c1551_drive->clock == 0)
672   if (c1551_drive.clock == 0)
667673   {
668      c1551_drive->gcr.ready = 0;
674      c1551_drive.gcr.ready = 0;
669675      // why put sync back to 0 here?!? it would break the sync count, isn't it?
670676      // or is it the way the serial port reads the sync count?!?
671      c1551_drive->gcr.sync = 0;
672   
673      c1551_drive->clock = 1;
677      c1551_drive.gcr.sync = 0;
678
679      c1551_drive.clock = 1;
674680      return;
675681   }
676682
677683   // this code has 2 effects: move on the pos on the data and reset it to 0 at the end of the track!
678684   // size of the track is: (# sectors in the track) * (size of sector GCR endoded)
679   // Here, size of sector is 368 because of our choices in the loading: 9 bytes of header gap & 14 bytes of sector gap
685   // Here, size of sector is 368 because of our choices in the loading: 9 bytes of header gap & 14 bytes of sector gap
680686   // We will need to set the size at loading time when adding support for G64 images
681   if (++(c1551_drive->pos) >= (d64_sectors_per_track[(int)c1551_drive->track - 1] * 368))
682      c1551_drive->pos = 0;
687   if (++(c1551_drive.pos) >= (d64_sectors_per_track[(int)c1551_drive.track - 1] * 368))
688      c1551_drive.pos = 0;
683689   // should we check if there is a change of track? to reset the pos in that case as well?
684690
685   c1551_drive->gcr.ready = 1;
691   c1551_drive.gcr.ready = 1;
686692
687   // notice that if there is a sequence of more than 40 1s it correctly does not reset the sync
693   // notice that if there is a sequence of more than 40 1s it correctly does not reset the sync
688694   // counter until a 0 is found
689   if (c1551_drive->gcr.data[c1551_drive->pos] == 0xff)
695   if (c1551_drive.gcr.data[c1551_drive.pos] == 0xff)
690696   {
691      c1551_drive->gcr.ones_count++;
697      c1551_drive.gcr.ones_count++;
692698
693//      if (c1551_drive->gcr.ones_count == 2) // 9 ones should already mark it as a sync, even if CBM chose to use 40 of them
694      if (c1551_drive->gcr.ones_count == 5)
695         c1551_drive->gcr.sync = 1;
696   }
697   else
699//      if (c1551_drive.gcr.ones_count == 2) // 9 ones should already mark it as a sync, even if CBM chose to use 40 of them
700      if (c1551_drive.gcr.ones_count == 5)
701         c1551_drive.gcr.sync = 1;
702   }
703   else
698704   {
699      c1551_drive->gcr.ones_count = 0;
700      c1551_drive->gcr.sync = 0;
705      c1551_drive.gcr.ones_count = 0;
706      c1551_drive.gcr.sync = 0;
701707   }
702708
703   c1551_drive->clock = 0;
709   c1551_drive.clock = 0;
704710}
705711
706712
707713/**************************************
708714
709   VC1541 Serial Bus Device Interface
715    VC1541 Serial Bus Device Interface
710716
711717**************************************/
712718
713/* 2009-05 FP - Note: I could use directly these functions as DEVICE_HANDLERs for
714the serial bus device, but these are also used in the VIA interface above, so I
715prefer to keep the handlers separated at this stage. Further work on the serial
719/* 2009-05 FP - Note: I could use directly these functions as DEVICE_HANDLERs for
720the serial bus device, but these are also used in the VIA interface above, so I
721prefer to keep the handlers separated at this stage. Further work on the serial
716722bus emulation should allow to remove the duplicated code. */
717723
718724static void vc1541_serial_reset_write( running_machine *machine, int which, int level )
r5842r5843
754760         #endif
755761            via_ca1_w (via_0, 0, !level);
756762#if 0
757            value = vc1541_drive->vc1541_serial.data;
758            if (vc1541_drive->vc1541_serial.acka != !level)
763            value = vc1541_drive.vc1541_serial.data;
764            if (vc1541_drive.vc1541_serial.acka != !level)
759765               value = 0;
760            if (value != serial.data[2])
766            if (value != serial.data[2])
761767            {
762768               serial.data[2] = value;
763               if (serial.data[0] != value)
769               if (serial.data[0] != value)
764770               {
765771                  serial.data[0] = serial.data[1] && serial.data[2];
766772               }
r5842r5843
828834         serial.clock[0] = serial.clock[1] && serial.clock[2];
829835         if (serial.clock[0] == level)
830836         {
831/*            DBG_LOG(machine, 1, "vc1541",("%d:%.4x clock %s\n",
832                            cpu_getactivecpu (),
833                            activecpu_get_pc(),
834                            serial.clock[0]?"CLOCK":"clock"));*/
837/*              DBG_LOG(machine, 1, "vc1541",("%d:%.4x clock %s\n",
838                                     cpu_getactivecpu (),
839                                     activecpu_get_pc(),
840                                     serial.clock[0]?"CLOCK":"clock"));*/
835841         }
836842      }
837843   }
r5842r5843
847853}
848854
849855
850/* 2009-05 FP - TODO: better implementation of the DEVICE_HANDLERs below. Right now they are
856/* 2009-05 FP - TODO: better implementation of the DEVICE_HANDLERs below. Right now they are
851857redundant (see also my Note above)  */
852858static READ8_DEVICE_HANDLER( emu_drive_atn_read )
853859{
r5842r5843
868874{
869875   return vc1541_serial_request_read(device->machine, 0);
870876}
871   
877
872878static WRITE8_DEVICE_HANDLER( emu_drive_atn_write )
873879{
874880   vc1541_serial_atn_write(device->machine, 0, data);
r5842r5843
912918
913919
914920/**************************************************************************
915 *   VIA 6522 at 0x1800
921 *  VIA 6522 at 0x1800
916922 *
917 *   0x1800  port B
918 *      bit 0 : data in (inverted: 0 = Low, 1 = High)
919 *      bit 1 : data out (inverted: 0 = Low, 1 = High)
920 *      bit 2 : clock in (inverted: 0 = Low, 1 = High)
921 *      bit 3 : clock out (inverted: 0 = Low, 1 = High)
922 *      bit 4 : atna out (inverted: 0 = Low, 1 = High)
923 *      bit 5 : device id 1
924 *      bit 6 : device id 2
925 *            device ID number is set by a jumper:
926 *            00 = 8 (default), 01 = 9, 10 = 10, 11 = 11
927 *      bit 7 : atn in (inverted: 0 = Low, 1 = High)
928 *   0x1801   port A - Read to acknowledge interrupt generated by ATN IN going high.
929 *   0x1802   port B data direction register.
930 *         if a bit here is 0, then the corresponding bit of portB can only be read
931 *         if a bit here is 1, then the corresponding bit of portB can be read and written
932 *         default value 0x1a
933 *   0x1803   port A data direction register.
934 *         default value 0xff
935 *   0x1804   timer 1 counter (low)
936 *   0x1805   timer 1 counter (high) / Timer one counter
937 *         Read low byte or write high byte to start timer or restart timer upon underflow.
938 *   0x1806   timer 1 latch (low)
939 *   0x1807   timer 1 latch (high)
940 *         read/write starting value of timer from/to here.
941 *   0x1808   timer 2 counter (low)
942 *   0x1809   timer 2 counter (high)
943 *   0x180a   shift register
944 *   0x180b   auxiliary control register. bit 6: 0 = Stop timer; 1 = Start timer.
945 *   0x180c   peripheral control register
946 *   0x180d   interrupt flag register. bit 1: 1 = ATN IN went high, bit 6: 1 = Timer underflow occurred.
947 *   0x180e   interrupt enable register.
948 *         bit 1: write -  1 = Enable interrupts generated by ATN IN going high
949 *         bit 7: read - interrupt has been generated.
950 *         bit 7: write - Fill bit: bits 0-6, that are set to 1, get their values from this bit; bits 0-6, that are set to 0, are left unchanged
923 *  0x1800  port B
924 *      bit 0 : data in (inverted: 0 = Low, 1 = High)
925 *      bit 1 : data out (inverted: 0 = Low, 1 = High)
926 *      bit 2 : clock in (inverted: 0 = Low, 1 = High)
927 *      bit 3 : clock out (inverted: 0 = Low, 1 = High)
928 *      bit 4 : atna out (inverted: 0 = Low, 1 = High)
929 *      bit 5 : device id 1
930 *      bit 6 : device id 2
931 *              device ID number is set by a jumper:
932 *              00 = 8 (default), 01 = 9, 10 = 10, 11 = 11
933 *      bit 7 : atn in (inverted: 0 = Low, 1 = High)
934 *  0x1801  port A - Read to acknowledge interrupt generated by ATN IN going high.
935 *  0x1802  port B data direction register.
936 *          if a bit here is 0, then the corresponding bit of portB can only be read
937 *          if a bit here is 1, then the corresponding bit of portB can be read and written
938 *          default value 0x1a
939 *  0x1803  port A data direction register.
940 *          default value 0xff
941 *  0x1804  timer 1 counter (low)
942 *  0x1805  timer 1 counter (high) / Timer one counter
943 *          Read low byte or write high byte to start timer or restart timer upon underflow.
944 *  0x1806  timer 1 latch (low)
945 *  0x1807  timer 1 latch (high)
946 *          read/write starting value of timer from/to here.
947 *  0x1808  timer 2 counter (low)
948 *  0x1809  timer 2 counter (high)
949 *  0x180a  shift register
950 *  0x180b  auxiliary control register. bit 6: 0 = Stop timer; 1 = Start timer.
951 *  0x180c  peripheral control register
952 *  0x180d  interrupt flag register. bit 1: 1 = ATN IN went high, bit 6: 1 = Timer underflow occurred.
953 *  0x180e  interrupt enable register.
954 *          bit 1: write -  1 = Enable interrupts generated by ATN IN going high
955 *          bit 7: read - interrupt has been generated.
956 *          bit 7: write - Fill bit: bits 0-6, that are set to 1, get their values from this bit; bits 0-6, that are set to 0, are left unchanged
951957 *
952958 * also ca1 (books says cb2)
953959 * irq to m6502 irq connected (or with second via irq)
954960 *
955961 **************************************************************************/
956962
957static void vc1541_via0_irq(const device_config *device, int level)
963static void vc1541_via0_irq( const device_config *device, int level )
958964{
959   vc1541_drive->via0irq = level;
960   DBG_LOG(device->machine, 2, "vc1541 via0 irq", ("level %d %d\n", vc1541_drive->via0irq, vc1541_drive->via1irq));
965   vc1541_drive.via0irq = level;
966   DBG_LOG(device->machine, 2, "vc1541 via0 irq", ("level %d %d\n", vc1541_drive.via0irq, vc1541_drive.via1irq));
961967
962   cputag_set_input_line(device->machine, vc1541_drive->cputag, M6502_IRQ_LINE, vc1541_drive->via1irq || vc1541_drive->via0irq);
968   cputag_set_input_line(device->machine, vc1541_drive.cputag, M6502_IRQ_LINE, vc1541_drive.via1irq || vc1541_drive.via0irq);
963969}
964970
965971static READ8_DEVICE_HANDLER( vc1541_via0_read_portb )
966972{
967973   int value = 0x7a;
968974
969   if (!vc1541_drive->vc1541_serial.serial_data || !serial.data[0])
975   if (!vc1541_drive.vc1541_serial.serial_data || !serial.data[0])
970976      value |= 0x01;
971977
972   if (!vc1541_drive->vc1541_serial.serial_clock || !serial.clock[0])
978   if (!vc1541_drive.vc1541_serial.serial_clock || !serial.clock[0])
973979      value |= 0x04;
974980
975   if (!serial.atn[0])
981   if (!serial.atn[0])
976982      value |= 0x80;
977983
978   switch (vc1541_drive->vc1541_serial.deviceid)
984   switch (vc1541_drive.vc1541_serial.deviceid)
979985   {
980986      case 8:
981987         value &= ~0x60;
r5842r5843
10001006                            data & 0x08 ? "CLOCK" : "clock",
10011007                            data & 0x02 ? "DATA"  : "data"));
10021008
1003   vc1541_drive->vc1541_serial.data = data & 0x02 ? 0 : 1;
1004   vc1541_drive->vc1541_serial.acka = data & 0x10 ? 1 : 0;
1009   vc1541_drive.vc1541_serial.data = data & 0x02 ? 0 : 1;
1010   vc1541_drive.vc1541_serial.acka = data & 0x10 ? 1 : 0;
10051011
1006   if ((!(data & 0x02)) != vc1541_drive->vc1541_serial.serial_data)
1012   if ((!(data & 0x02)) != vc1541_drive.vc1541_serial.serial_data)
10071013   {
1008      vc1541_serial_data_write(device->machine, 1, vc1541_drive->vc1541_serial.serial_data = !(data & 0x02));
1014      vc1541_serial_data_write(device->machine, 1, vc1541_drive.vc1541_serial.serial_data = !(data & 0x02));
10091015   }
10101016
1011   if ((!(data & 0x08)) != vc1541_drive->vc1541_serial.serial_clock)
1017   if ((!(data & 0x08)) != vc1541_drive.vc1541_serial.serial_clock)
10121018   {
1013      vc1541_serial_clock_write(device->machine, 1, vc1541_drive->vc1541_serial.serial_clock = !(data & 0x08));
1019      vc1541_serial_clock_write(device->machine, 1, vc1541_drive.vc1541_serial.serial_clock = !(data & 0x08));
10141020   }
10151021
1016   vc1541_serial_atn_write(device->machine, 1, vc1541_drive->vc1541_serial.serial_atn = 1);
1022   vc1541_serial_atn_write(device->machine, 1, vc1541_drive.vc1541_serial.serial_atn = 1);
10171023}
10181024
10191025static const via6522_interface vc1541_via0 =
r5842r5843
10351041
10361042
10371043/**************************************************************************
1038 *   VIA 6522 at 0x1c00
1044 *  VIA 6522 at 0x1c00
10391045 *
1040 *   0x1c00  port B - Disk controller i/o control line
1041 *      bit 0 : step head motor output 1
1042 *      bit 1 : step head motor output 2
1043 *      bit 2 : motor on output (0 = Off, 1 = On) - 300 revolutions per minute
1044 *      bit 3 : LED control output (0 = Off, 1 = On)
1045 *      bit 4 : write protect sense (0 = protected, 1 = unprotected)
1046 *      bit 5 : density select 0
1047 *      bit 6 : density select 1
1048 *         data density (track dependend): 00 = lowest (faster time), 11 = highest (slower timer)
1049 *      bit 7 : sync signal (more then nine 1 bits) detect
1050 *   0x1c01   Port A - byte in gcr format from or to floppy
1051 *   0x1c02   Port B data direction register + LED output - default 0x6f
1052 *   0x1c03   Port A data direction register - 0x00 read from disk, 0xff write to disk
1053 *   0x1c04   Timer 1 counter (low)
1054 *   0x1c05   Timer 1 counter (high)
1055 *         Read low byte or write high byte to start timer or restart timer upon underflow.
1056 *   0x1c06   Timer 1 latch (low)
1057 *   0x1c07   Timer 1 latch (high)
1058 *         read/write starting value of timer from/to here.
1059 *   0x1c08   Timer 2 latch (low)
1060 *   0x1c09   Timer 2 latch (high)
1061 *   0x1c0a   Shift register
1062 *   0x1c0b   Auxiliary control register. bit 6: 0 = Stop timer; 1 = Start timer.
1063 *   0x1c0c   Peripheral control register
1064 *   0x1c0d   Interrupt flag register. bit 6: 1 = Timer underflow occurred.
1065 *   0x1c0e   Interrupt enable register
1066 *         bit 6: write -  1 = Enable interrupts generated by timer underflow
1067 *         bit 7: read - interrupt has been generated.
1068 *         bit 7: write - Fill bit: bits 0-6, that are set to 1, get their values from this bit; bits 0-6, that are set to 0, are left unchanged
1046 *  0x1c00  port B - Disk controller i/o control line
1047 *      bit 0 : step head motor output 1
1048 *      bit 1 : step head motor output 2
1049 *      bit 2 : motor on output (0 = Off, 1 = On) - 300 revolutions per minute
1050 *      bit 3 : LED control output (0 = Off, 1 = On)
1051 *      bit 4 : write protect sense (0 = protected, 1 = unprotected)
1052 *      bit 5 : density select 0
1053 *      bit 6 : density select 1
1054 *          data density (track dependend): 00 = lowest (faster time), 11 = highest (slower timer)
1055 *      bit 7 : sync signal (more then nine 1 bits) detect
1056 *  0x1c01  Port A - byte in gcr format from or to floppy
1057 *  0x1c02  Port B data direction register + LED output - default 0x6f
1058 *  0x1c03  Port A data direction register - 0x00 read from disk, 0xff write to disk
1059 *  0x1c04  Timer 1 counter (low)
1060 *  0x1c05  Timer 1 counter (high)
1061 *          Read low byte or write high byte to start timer or restart timer upon underflow.
1062 *  0x1c06  Timer 1 latch (low)
1063 *  0x1c07  Timer 1 latch (high)
1064 *          read/write starting value of timer from/to here.
1065 *  0x1c08  Timer 2 latch (low)
1066 *  0x1c09  Timer 2 latch (high)
1067 *  0x1c0a  Shift register
1068 *  0x1c0b  Auxiliary control register. bit 6: 0 = Stop timer; 1 = Start timer.
1069 *  0x1c0c  Peripheral control register
1070 *  0x1c0d  Interrupt flag register. bit 6: 1 = Timer underflow occurred.
1071 *  0x1c0e  Interrupt enable register
1072 *          bit 6: write -  1 = Enable interrupts generated by timer underflow
1073 *          bit 7: read - interrupt has been generated.
1074 *          bit 7: write - Fill bit: bits 0-6, that are set to 1, get their values from this bit; bits 0-6, that are set to 0, are left unchanged
10691075 *
10701076 * ca1 byte ready input (also m6502 set overflow input)
10711077 * ca2 set overflow enable for 6502
r5842r5843
10761082 **************************************************************************/
10771083
10781084
1079static void vc1541_via1_irq (const device_config *device, int level)
1085static void vc1541_via1_irq( const device_config *device, int level )
10801086{
1081   vc1541_drive->via1irq = level;
1082   DBG_LOG(device->machine, 2, "vc1541 via1 irq", ("level %d %d\n", vc1541_drive->via0irq, vc1541_drive->via1irq));
1087   vc1541_drive.via1irq = level;
1088   DBG_LOG(device->machine, 2, "vc1541 via1 irq", ("level %d %d\n", vc1541_drive.via0irq, vc1541_drive.via1irq));
10831089
1084   cputag_set_input_line(device->machine, vc1541_drive->cputag, M6502_IRQ_LINE, vc1541_drive->via1irq || vc1541_drive->via0irq);
1090   cputag_set_input_line(device->machine, vc1541_drive.cputag, M6502_IRQ_LINE, vc1541_drive.via1irq || vc1541_drive.via0irq);
10851091}
10861092
10871093static READ8_DEVICE_HANDLER( vc1541_via1_read_porta )
10881094{
1089   UINT8 data = vc1541_drive->gcr.data[vc1541_drive->start_pos + vc1541_drive->pos];
1095   UINT8 data = vc1541_drive.gcr.data[vc1541_drive.start_pos + vc1541_drive.pos];
10901096
1091//   logerror("Data read: Track %.1f Pos %d\n", vc1541_drive->track, vc1541_drive->pos);
1097//  logerror("Data read: Track %.1f Pos %d\n", vc1541_drive.track, vc1541_drive.pos);
10921098
10931099   DBG_LOG(device->machine, 2, "vc1541 drive", ("port a read %.2x\n", data));
10941100   return data;
r5842r5843
11081114      value &= ~0x10;
11091115#endif
11101116
1111   if (vc1541_drive->gcr.sync)
1117   if (vc1541_drive.gcr.sync)
11121118   {
11131119      value &= ~0x80;
11141120   }
r5842r5843
11201126
11211127static WRITE8_DEVICE_HANDLER( vc1541_via1_write_portb )
11221128{
1123   if (data != old)
1129   if (data != old)
11241130   {
11251131      DBG_LOG(device->machine, 1, "vc1541 drive",("%.2x\n", data));
11261132
1127   /*   decrease value (%00-%11-%10-%01-%00...) to move head downwards; */
1128   /*   increase value (%00-%01-%10-%11-%00...) to move head upwards.   */
1129      if ((old & 0x03) != (data & 0x03))
1133   /*  decrease value (%00-%11-%10-%01-%00...) to move head downwards; */
1134   /*  increase value (%00-%01-%10-%11-%00...) to move head upwards.   */
1135      if ((old & 0x03) != (data & 0x03))
11301136      {
1131         switch (old & 0x03)
1137         switch (old & 0x03)
11321138         {
11331139         case 0:
1134            if ((data & 0x03) == 1)
1135               vc1541_drive->track += 0.5;
1136            else if ((data & 0x03) == 3)
1137               vc1541_drive->track -= 0.5;
1140            if ((data & 0x03) == 1)
1141               vc1541_drive.track += 0.5;
1142            else if ((data & 0x03) == 3)
1143               vc1541_drive.track -= 0.5;
11381144            break;
11391145
11401146         case 1:
1141            if ((data & 0x03) == 2)
1142               vc1541_drive->track += 0.5;
1143            else if ((data & 0x03) == 0)
1144               vc1541_drive->track -= 0.5;
1147            if ((data & 0x03) == 2)
1148               vc1541_drive.track += 0.5;
1149            else if ((data & 0x03) == 0)
1150               vc1541_drive.track -= 0.5;
11451151            break;
11461152
11471153         case 2:
1148            if ((data & 0x03) == 3)
1149               vc1541_drive->track += 0.5;
1150            else if ((data & 0x03) == 1)
1151               vc1541_drive->track -= 0.5;
1154            if ((data & 0x03) == 3)
1155               vc1541_drive.track += 0.5;
1156            else if ((data & 0x03) == 1)
1157               vc1541_drive.track -= 0.5;
11521158            break;
11531159
11541160         case 3:
1155            if ((data & 0x03) == 0)
1156               vc1541_drive->track += 0.5;
1157            else if ((data & 0x03) == 2)
1158               vc1541_drive->track -= 0.5;
1161            if ((data & 0x03) == 0)
1162               vc1541_drive.track += 0.5;
1163            else if ((data & 0x03) == 2)
1164               vc1541_drive.track -= 0.5;
11591165            break;
11601166         }
11611167
11621168         /* If we have reached the first or last track, we cannot proceed further! */
1163         if (vc1541_drive->track < 1)
1164            vc1541_drive->track = 1.0;
1165         if (vc1541_drive->track > 35)
1166            vc1541_drive->track = 35.0;
1169         if (vc1541_drive.track < 1)
1170            vc1541_drive.track = 1.0;
1171         if (vc1541_drive.track > 35)
1172            vc1541_drive.track = 35.0;
11671173
1168         logerror("Track #: %.1f\n", vc1541_drive->track);
1174         logerror("Track #: %.1f\n", vc1541_drive.track);
11691175
1170         /* We now adjust the vc1541_drive->pos according to the new track */
1176         /* We now adjust the vc1541_drive.pos according to the new track */
11711177         /* This seems a simple way to deal with half tracks */
1172         vc1541_drive->pos = 0;
1173         vc1541_drive->start_pos = gcr_offset[(int)vc1541_drive->track - 1]            // starting point of Track #
1174            + (int)(2 * (vc1541_drive->track - (int)vc1541_drive->track)) * 184 / 2;   // half track if needed (again, 184 comes from out loading choices)
1178         vc1541_drive.pos = 0;
1179         vc1541_drive.start_pos = gcr_offset[(int)vc1541_drive.track - 1]            // starting point of Track #
1180            + (int)(2 * (vc1541_drive.track - (int)vc1541_drive.track)) * 184 / 2;   // half track if needed (again, 184 comes from out loading choices)
11751181      }
11761182
1177      if ((vc1541_drive->motor != (data & 0x04)) || (vc1541_drive->frequency != (data & 0x60)))
1183      if ((vc1541_drive.motor != (data & 0x04)) || (vc1541_drive.frequency != (data & 0x60)))
11781184      {
11791185         double tme;
1180         vc1541_drive->motor = data & 0x04;
1181         vc1541_drive->frequency = data & 0x60;
1182         tme = drive_times[vc1541_drive->frequency >> 5];
1186         vc1541_drive.motor = data & 0x04;
1187         vc1541_drive.frequency = data & 0x60;
1188         tme = drive_times[vc1541_drive.frequency >> 5];
11831189
1184         if (vc1541_drive->motor)
1190         if (vc1541_drive.motor)
11851191         {
1186            if (attotime_to_double(timer_timeelapsed(vc1541_drive->timer)) > 1.0e29)
1192            if (attotime_to_double(timer_timeelapsed(vc1541_drive.timer)) > 1.0e29)
11871193            {
1188               timer_reset(vc1541_drive->timer, attotime_never);
1194               timer_reset(vc1541_drive.timer, attotime_never);
11891195            }
11901196            else
11911197            {
1192               timer_adjust_periodic(vc1541_drive->timer, attotime_zero, 0, ATTOTIME_IN_HZ(tme));
1198               timer_adjust_periodic(vc1541_drive.timer, attotime_zero, 0, ATTOTIME_IN_HZ(tme));
11931199               logerror("Freq changed: %f\n", tme);
11941200            }
11951201         }
11961202         else
11971203         {
1198            timer_reset(vc1541_drive->timer, attotime_never);
1204            timer_reset(vc1541_drive.timer, attotime_never);
11991205            logerror("Motor turned off\n");
12001206         }
12011207      }
12021208      old = data;
12031209   }
12041210
1205   vc1541_drive->led = data & 0x08;
1211   vc1541_drive.led = data & 0x08;
12061212}
12071213
12081214static const via6522_interface vc1541_via1 =
r5842r5843
12251231
12261232/**************************************
12271233
1228   1541 / 1541B / 1541C / 1541II /
1229      2031 (same as 1541 but IEEE)
1234    1541 / 1541B / 1541C / 1541II /
1235        2031 (same as 1541 but IEEE)
12301236
12311237**************************************/
12321238
r5842r5843
12481254
12491255/**************************************
12501256
1251   1570 / 1571 / 1571CR
1257    1570 / 1571 / 1571CR
12521258
12531259**************************************/
12541260
r5842r5843
12561262   AM_RANGE(0x0000, 0x07ff) AM_RAM
12571263   AM_RANGE(0x1800, 0x180f) AM_DEVREADWRITE("_1541_via_0", via_r, via_w)  /* 0 and 1 used in vc20 */
12581264   AM_RANGE(0x1c00, 0x1c0f) AM_DEVREADWRITE("_1541_via_1", via_r, via_w)
1259//   AM_RANGE(0x2000, 0x2003) // WD17xx
1260//   AM_RANGE(0x4000, 0x400f) // CIA
1265//  AM_RANGE(0x2000, 0x2003) // WD17xx
1266//  AM_RANGE(0x4000, 0x400f) // CIA
12611267   AM_RANGE(0x8000, 0xffff) AM_ROM
12621268ADDRESS_MAP_END
12631269
r5842r5843
12651271/*
12661272David Gahris provided info about differences between 128DCR and stand-alone 1571s
12671273
1268* There is no 6526 or 8521 in the drive section of the 128DCR.  I believe the
1269  5710 handles fast serial because the 5710 is a Commodore custom chip and
1274* There is no 6526 or 8521 in the drive section of the 128DCR.  I believe the
1275  5710 handles fast serial because the 5710 is a Commodore custom chip and
12701276  128 fast serial is a Commodore custom protocol.  [Ed's note: Commodore lists
12711277  NTE229, ECG229, SK3246A/229, and 121-Z9021 as substitutes of the 5710.]
12721278
1273* There is no 177x or heat-shrink-wrapped daughterboard in the drive section
1274  of the 128DCR.  I believe the Motorola plastic quad flat-pack chip handles
1275  MFM because I am pretty sure that I have seen this chip in IBM PC drive
1276  mechanisms. 
1279* There is no 177x or heat-shrink-wrapped daughterboard in the drive section
1280  of the 128DCR.  I believe the Motorola plastic quad flat-pack chip handles
1281  MFM because I am pretty sure that I have seen this chip in IBM PC drive
1282  mechanisms.
12771283
1278* The 1571cr ROM works great in 1541 mode but not at all in 1571 mode in a
1279  standalone 1571. 
1284* The 1571cr ROM works great in 1541 mode but not at all in 1571 mode in a
1285  standalone 1571.
12801286
1281* Olaf Seibert informed me that the 1571cr ROM contains a string to the
1287* Olaf Seibert informed me that the 1571cr ROM contains a string to the
12821288  effect of "5710 (c) 1986 by c. hauck"
12831289*/
12841290static ADDRESS_MAP_START( _1571cr_map, ADDRESS_SPACE_PROGRAM, 8 )
12851291   AM_RANGE(0x0000, 0x07ff) AM_RAM
12861292   AM_RANGE(0x1800, 0x180f) AM_DEVREADWRITE("_1541_via_0", via_r, via_w)  /* 0 and 1 used in vc20 */
12871293   AM_RANGE(0x1c00, 0x1c0f) AM_DEVREADWRITE("_1541_via_1", via_r, via_w)
1288//   AM_RANGE(0x2000, 0x2005) // 5710 FDC
1289//   AM_RANGE(0x400c, 0x400f) // 5710 CIA Serial Port
1290//   AM_RANGE(0x4010, 0x4017) // 5710 FDC2
1291//   AM_RANGE(0x6000, 0x7fff) // RAM shadows
1294//  AM_RANGE(0x2000, 0x2005) // 5710 FDC
1295//  AM_RANGE(0x400c, 0x400f) // 5710 CIA Serial Port
1296//  AM_RANGE(0x4010, 0x4017) // 5710 FDC2
1297//  AM_RANGE(0x6000, 0x7fff) // RAM shadows
12921298   AM_RANGE(0x8000, 0xffff) AM_ROM
12931299ADDRESS_MAP_END
12941300
12951301
12961302/**************************************
12971303
1298   1581
1304    1581
12991305
13001306**************************************/
13011307
13021308static ADDRESS_MAP_START( _1581_map, ADDRESS_SPACE_PROGRAM, 8 )
1303//   AM_RANGE(0x4000, 0x400f) // CIA
1304//   AM_RANGE(0x6000, 0x6003) // WD17xx
1309//  AM_RANGE(0x4000, 0x400f) // CIA
1310//  AM_RANGE(0x6000, 0x6003) // WD17xx
13051311   AM_RANGE(0x8000, 0xffff) AM_ROM
13061312ADDRESS_MAP_END
13071313
13081314
13091315/**************************************
13101316
1311   1001 / 8050 / 8250
1317    1001 / 8050 / 8250
13121318
13131319http://www.zimmers.net/anonftp/pub/cbm/firmware/drives/old/8050/d/8250.notes
13141320
13151321**************************************/
13161322
13171323static ADDRESS_MAP_START( sfd1001_map, ADDRESS_SPACE_PROGRAM, 8 )
1318//   AM_RANGE(0x0200, 0x021f) // RIOT1
1319//   AM_RANGE(0x0280, 0x029f) // RIOT2
1324//  AM_RANGE(0x0200, 0x021f) // RIOT1
1325//  AM_RANGE(0x0280, 0x029f) // RIOT2
13201326   AM_RANGE(0xc000, 0xffff) AM_ROM
13211327ADDRESS_MAP_END
13221328
13231329
13241330/**************************************
13251331
1326   2040 / 3040 / 4040
1332    2040 / 3040 / 4040
13271333
13281334http://www.zimmers.net/anonftp/pub/cbm/schematics/drives/old/4040/memorymap.txt
13291335
r5842r5843
13351341
13361342/**************************************
13371343
1338   1551
1344    1551
13391345
13401346**************************************/
13411347
r5842r5843
13451351 */
13461352static TIMER_CALLBACK(c1551_irq_timer)
13471353{
1348   cputag_set_input_line(machine, c1551_drive->cputag, M6502_IRQ_LINE, ASSERT_LINE);
1354   cputag_set_input_line(machine, c1551_drive.cputag, M6502_IRQ_LINE, ASSERT_LINE);
13491355}
13501356
13511357/*
r5842r5843
13601366
13611367static WRITE8_HANDLER( c1551_port_w )
13621368{
1363   if (offset)
1369   if (offset)
13641370   {
13651371      DBG_LOG(space->machine, 1, "c1551 port",("write %.2x\n", data));
1366      c1551_drive->cpu_port = data;
1372      c1551_drive.cpu_port = data;
13671373
1368      if (data != old)
1374      if (data != old)
13691375      {
13701376         DBG_LOG(space->machine, 1, "c1551 drive",("%.2x\n", data));
1371     
1372         if ((old & 0x03) != (data & 0x03))
1377
1378         if ((old & 0x03) != (data & 0x03))
13731379         {
1374            switch (old & 0x03)
1380            switch (old & 0x03)
13751381            {
13761382            case 0:
1377               if ((data & 0x03) == 1)
1378                  c1551_drive->track += 0.5;
1379               else if ((data & 0x03) == 3)
1380                  c1551_drive->track -= 0.5;
1383               if ((data & 0x03) == 1)
1384                  c1551_drive.track += 0.5;
1385               else if ((data & 0x03) == 3)
1386                  c1551_drive.track -= 0.5;
13811387               break;
13821388
13831389            case 1:
1384               if ((data & 0x03) == 2)
1385                  c1551_drive->track += 0.5;
1386               else if ((data & 0x03) == 0)
1387                  c1551_drive->track -= 0.5;
1390               if ((data & 0x03) == 2)
1391                  c1551_drive.track += 0.5;
1392               else if ((data & 0x03) == 0)
1393                  c1551_drive.track -= 0.5;
13881394               break;
13891395
13901396            case 2:
1391               if ((data & 0x03) == 3)
1392                  c1551_drive->track += 0.5;
1393               else if ((data & 0x03) == 1)
1394                  c1551_drive->track -= 0.5;
1397               if ((data & 0x03) == 3)
1398                  c1551_drive.track += 0.5;
1399               else if ((data & 0x03) == 1)
1400                  c1551_drive.track -= 0.5;
13951401               break;
13961402
13971403            case 3:
1398               if ((data & 0x03) == 0)
1399                  c1551_drive->track += 0.5;
1400               else if ((data & 0x03) == 2)
1401                  c1551_drive->track -= 0.5;
1404               if ((data & 0x03) == 0)
1405                  c1551_drive.track += 0.5;
1406               else if ((data & 0x03) == 2)
1407                  c1551_drive.track -= 0.5;
14021408               break;
14031409            }
14041410
14051411            /* If we have reached the first or last track, we cannot proceed further! */
1406            if (c1551_drive->track < 1)
1407               c1551_drive->track = 1.0;
1408            if (c1551_drive->track > 35)
1409               c1551_drive->track = 35.0;
1412            if (c1551_drive.track < 1)
1413               c1551_drive.track = 1.0;
1414            if (c1551_drive.track > 35)
1415               c1551_drive.track = 35.0;
14101416
1411         logerror("Track #: %.1f\n", c1551_drive->track);
1417         logerror("Track #: %.1f\n", c1551_drive.track);
14121418
1413         /* We now adjust the c1551_drive->pos according to the new track */
1419         /* We now adjust the c1551_drive.pos according to the new track */
14141420         /* This seems a simple way to deal with half tracks */
1415         c1551_drive->pos = 0;
1416         c1551_drive->start_pos = gcr_offset[(int)c1551_drive->track - 1]            // starting point of Track #
1417            + (int)(2 * (c1551_drive->track - (int)c1551_drive->track)) * 184 / 2;   // half track if needed (again, 184 comes from out loading choices)
1421         c1551_drive.pos = 0;
1422         c1551_drive.start_pos = gcr_offset[(int)c1551_drive.track - 1]            // starting point of Track #
1423            + (int)(2 * (c1551_drive.track - (int)c1551_drive.track)) * 184 / 2;   // half track if needed (again, 184 comes from out loading choices)
14181424         }
14191425
1420         if ((c1551_drive->motor != (data & 0x04)) || (c1551_drive->frequency != (data & 0x60)))
1426         if ((c1551_drive.motor != (data & 0x04)) || (c1551_drive.frequency != (data & 0x60)))
14211427         {
14221428            double tme;
1423            c1551_drive->motor = data & 0x04;
1424            c1551_drive->frequency = data & 0x60;
1429            c1551_drive.motor = data & 0x04;
1430            c1551_drive.frequency = data & 0x60;
14251431
1426            tme = drive_times[c1551_drive->frequency >> 5];
1427            if (c1551_drive->motor)
1432            tme = drive_times[c1551_drive.frequency >> 5];
1433            if (c1551_drive.motor)
14281434            {
1429               if (attotime_to_double(timer_timeelapsed(c1551_drive->timer)) > 1.0e29)
1430                  timer_reset(c1551_drive->timer, attotime_never);
1435               if (attotime_to_double(timer_timeelapsed(c1551_drive.timer)) > 1.0e29)
1436                  timer_reset(c1551_drive.timer, attotime_never);
14311437               else
1432                  timer_adjust_periodic(c1551_drive->timer, attotime_zero, 0, ATTOTIME_IN_HZ(tme));
1438                  timer_adjust_periodic(c1551_drive.timer, attotime_zero, 0, ATTOTIME_IN_HZ(tme));
14331439            }
14341440            else
14351441            {
1436               timer_reset(c1551_drive->timer, attotime_never);
1442               timer_reset(c1551_drive.timer, attotime_never);
14371443            }
14381444         }
14391445         old = data;
14401446      }
1441      c1551_drive->led = data & 0x08;
1442   }
1443   else
1447      c1551_drive.led = data & 0x08;
1448   }
1449   else
14441450   {
1445      c1551_drive->cpu_ddr = data;
1451      c1551_drive.cpu_ddr = data;
14461452      DBG_LOG(space->machine, 1, "c1551 ddr", ("write %.2x\n", data));
14471453   }
14481454}
r5842r5843
14511457{
14521458   int data;
14531459
1454   if (offset)
1460   if (offset)
14551461   {
14561462      data = 0x7f;
14571463#if 0
14581464      if (WRITEPROTECTED)
14591465         data &= ~0x10;
14601466#endif
1461      if (c1551_drive->gcr.ready)
1467      if (c1551_drive.gcr.ready)
14621468      {
14631469         data |= 0x80;
1464         c1551_drive->gcr.ready = 0;
1470         c1551_drive.gcr.ready = 0;
14651471      }
14661472
1467      data &= ~c1551_drive->cpu_ddr;
1468      data |= c1551_drive->cpu_ddr & c1551_drive->cpu_port;
1473      data &= ~c1551_drive.cpu_ddr;
1474      data |= c1551_drive.cpu_ddr & c1551_drive.cpu_port;
14691475      DBG_LOG(space->machine, 3, "c1551 port",("read %.2x\n", data));
1470   }
1471   else
1476   }
1477   else
14721478   {
1473      data = c1551_drive->cpu_ddr;
1479      data = c1551_drive.cpu_ddr;
14741480      DBG_LOG(space->machine, 3, "c1551 ddr",("read %.2x\n", data));
14751481   }
14761482   return data;
r5842r5843
14781484
14791485
14801486static ADDRESS_MAP_START( _1551_map, ADDRESS_SPACE_PROGRAM, 8 )
1481    AM_RANGE(0x0000, 0x0001) AM_READWRITE(c1551_port_r, c1551_port_w)
1487   AM_RANGE(0x0000, 0x0001) AM_READWRITE(c1551_port_r, c1551_port_w)
14821488   AM_RANGE(0x0002, 0x07ff) AM_RAM
1483    AM_RANGE(0x4000, 0x4007) AM_DEVREADWRITE("c1551_tpi", tpi6525_r, tpi6525_w)
1489   AM_RANGE(0x4000, 0x4007) AM_DEVREADWRITE("c1551_tpi", tpi6525_r, tpi6525_w)
14841490   AM_RANGE(0xc000, 0xffff) AM_ROM
14851491ADDRESS_MAP_END
14861492
r5842r5843
14951501    drive data in/out
14961502   port c ddr (0x1f)
14971503    0 output status out
1498   1 output status out
1499   2 output
1500   3 output handshake out
1501   4 output
1502   5 input drive number 9
1503   6 input sync 0 active
1504   7 input handshake in
1504    1 output status out
1505    2 output
1506    3 output handshake out
1507    4 output
1508    5 input drive number 9
1509    6 input sync 0 active
1510    7 input handshake in
15051511 */
15061512static READ8_DEVICE_HANDLER( c1551_port_c_r )
15071513{
15081514   int data = 0xff;
1509   
1515
15101516   data &= ~0x20;
15111517
1512   if (c1551_drive->gcr.sync)
1518   if (c1551_drive.gcr.sync)
15131519      data &= ~0x40;
15141520
15151521   return data;
r5842r5843
15171523
15181524static READ8_DEVICE_HANDLER( c1551_port_b_r )
15191525{
1520   UINT8 data = c1551_drive->gcr.data[c1551_drive->start_pos + c1551_drive->pos];
1526   UINT8 data = c1551_drive.gcr.data[c1551_drive.start_pos + c1551_drive.pos];
15211527
15221528   DBG_LOG(device->machine, 2, "c1551 drive",("port a read %.2x\n", data));
15231529   return data;
r5842r5843
15411547
15421548WRITE8_DEVICE_HANDLER( c1551x_write_data )
15431549{
1544//   DBG_LOG(device->machine, 1, "c1551 cpu", ("%d write data %.2x\n", cpu_getactivecpu (), data));
1550//  DBG_LOG(device->machine, 1, "c1551 cpu", ("%d write data %.2x\n", cpu_getactivecpu (), data));
15451551#ifdef CPU_SYNC
15461552   cpu_sync();
15471553#endif
r5842r5843
15601566#endif
15611567
15621568   data = tpi6525_porta_r(tpi_0, 0);
1563//   DBG_LOG(device->machine, 2, "c1551 cpu",("%d read data %.2x\n", cpu_getactivecpu (), data));
1569//  DBG_LOG(device->machine, 2, "c1551 cpu",("%d read data %.2x\n", cpu_getactivecpu (), data));
15641570   return data;
15651571}
15661572
15671573WRITE8_DEVICE_HANDLER( c1551x_write_handshake )
15681574{
15691575   const device_config *tpi_0 = devtag_get_device(device->machine, "c1551_tpi");
1570//   DBG_LOG(device->machine, 1, "c1551 cpu",("%d write handshake %.2x\n", cpu_getactivecpu (), data));
1576//  DBG_LOG(device->machine, 1, "c1551 cpu",("%d write handshake %.2x\n", cpu_getactivecpu (), data));
15711577#ifdef CPU_SYNC
15721578   cpu_sync();
15731579#endif
r5842r5843
15841590#endif
15851591
15861592   data = tpi6525_portc_r(tpi_0, 0) & 0x08 ? 0x80 : 0x00;
1587//   DBG_LOG(device->machine, 2, "c1551 cpu",("%d read handshake %.2x\n", cpu_getactivecpu (), data));
1593//  DBG_LOG(device->machine, 2, "c1551 cpu",("%d read handshake %.2x\n", cpu_getactivecpu (), data));
15881594   return data;
15891595}
15901596
r5842r5843
15971603#endif
15981604
15991605   data = tpi6525_portc_r(tpi_0, 0) & 0x03;
1600//   DBG_LOG(device->machine, 1, "c1551 cpu",("%d read status %.2x\n", cpu_getactivecpu (), data));
1606//  DBG_LOG(device->machine, 1, "c1551 cpu",("%d read status %.2x\n", cpu_getactivecpu (), data));
16011607
16021608   return data;
16031609}
r5842r5843
16061612
16071613/**************************************
16081614
1609   Machine drivers
1615    Machine drivers
16101616
16111617**************************************/
16121618
r5842r5843
16731679
16741680/**************************************
16751681
1676   Drive init & reset
1682    Drive init & reset
16771683
16781684**************************************/
16791685
1680void drive_config( running_machine *machine, int type, int id, int mode, const char *cputag, int devicenr )
1686void cbm_drive_config( running_machine *machine, int type, int id, int mode, const char *cputag, int devicenr )
16811687{
1682   vc1541_drive->type = type;
1683   vc1541_drive->cputag = cputag;
1684   vc1541_drive->vc1541_serial.deviceid = devicenr;
1685   vc1541_drive->timer = timer_alloc(machine, vc1541_drive_timer, NULL);
1688   vc1541_drive.type = type;
1689   vc1541_drive.cputag = cputag;
1690   vc1541_drive.vc1541_serial.deviceid = devicenr;
1691   vc1541_drive.timer = timer_alloc(machine, vc1541_drive_timer, NULL);
1692   vc1541_drive.gcr.data = (UINT8*)auto_alloc_array(machine, UINT8, 0x500000);
16861693}
16871694
16881695void c1551_config( running_machine *machine, const char *cputag )
16891696{
1690   c1551_drive->type = type_1551;
1691   c1551_drive->cputag = cputag;
1692   c1551_drive->timer = timer_alloc(machine, c1551_drive_timer, NULL);
1697   c1551_drive.type = type_1551;
1698   c1551_drive.cputag = cputag;
1699   c1551_drive.timer = timer_alloc(machine, c1551_drive_timer, NULL);
1700   c1551_drive.gcr.data = (UINT8*)auto_alloc_array(machine, UINT8, 0x500000);
16931701
16941702   /* time should be small enough to allow quitting of the irq
1695   line before the next interrupt is triggered */
1696   c1551_drive->irq_timer = timer_alloc(machine, c1551_irq_timer, NULL);
1697   timer_adjust_periodic(c1551_drive->irq_timer, attotime_zero, 0, ATTOTIME_IN_HZ(60));
1703    line before the next interrupt is triggered */
1704   c1551_drive.irq_timer = timer_alloc(machine, c1551_irq_timer, NULL);
1705   timer_adjust_periodic(c1551_drive.irq_timer, attotime_zero, 0, ATTOTIME_IN_HZ(60));
16981706}
16991707
1700void drive_reset (void)
1708void cbm_drive_reset( running_machine* machine )
17011709{
17021710   int i;
17031711
1704   if (vc1541_drive->type == type_1541)
1712   if (vc1541_drive.type == type_1541)
17051713   {
17061714      for (i = 0; i < sizeof (serial.atn) / sizeof (serial.atn[0]); i++)
17071715      {
r5842r5843
17101718   }
17111719
17121720   /* Create offset map for GCR encoded images: it speeds up finding position where to read data from */
1713   switch (vc1541_drive->type)
1721   switch (vc1541_drive.type)
17141722   {
17151723      case type_1541:
17161724      case type_1541ii:
r5842r5843
17311739         logerror("GCR offset map not created\n");
17321740   }
17331741
1734   vc1541_drive->track = 1.0;
1735   vc1541_drive->start_pos = 0;
1736   vc1541_drive->pos = 0;
1742   vc1541_drive.gcr.sync = 0;
1743   vc1541_drive.gcr.ones_count = 0;
1744   vc1541_drive.gcr.ready = 0;
1745
1746   vc1541_drive.track = 1.0;
1747   vc1541_drive.start_pos = 0;
1748   vc1541_drive.pos = 0;
1749   vc1541_drive.led = 0;
1750   vc1541_drive.motor = 0;
1751   vc1541_drive.frequency = 0;
1752   vc1541_drive.clock = 0;
1753
1754   vc1541_drive.vc1541_serial.acka = 0;
1755   vc1541_drive.vc1541_serial.data = 0;
1756
17371757}
17381758
1739void c1551_drive_reset (void)
1759void c1551_drive_reset( void )
17401760{
17411761   offset_init(format_d64_40t, gcr_offset, 368);   // offset map is the same for both 35 and 40 track discs
1742   c1551_drive->track = 1.0;
1743   c1551_drive->start_pos = 0;
1744   c1551_drive->pos = 0;
1762
1763   c1551_drive.gcr.sync = 0;
1764   c1551_drive.gcr.ones_count = 0;
1765   c1551_drive.gcr.ready = 0;
1766
1767   c1551_drive.track = 1.0;
1768   c1551_drive.start_pos = 0;
1769   c1551_drive.pos = 0;
1770   c1551_drive.led = 0;
1771   c1551_drive.motor = 0;
1772   c1551_drive.frequency = 0;
1773   c1551_drive.clock = 0;
17451774}
17461775
17471776
17481777
17491778/**************************************
17501779
1751   Device configurations
1780    Device configurations
17521781
17531782**************************************/
17541783
r5842r5843
17621791
17631792   for (k = 1; k <= max_tracks_per_format[format]; k++)
17641793   {
1765/*      logerror("decoding track %d offset %d %d %d %d %d\n", k,
1766                  image_tracksector2offset(k, 0) / (16*16*16*16),
1767                  (image_tracksector2offset(k, 0) % (16*16*16*16)) / (16*16*16),
1768                  (image_tracksector2offset(k, 0) % (16*16*16)) / (16*16),
1769                  (image_tracksector2offset(k, 0) % (16*16)) / 16,
1770                  image_tracksector2offset(k, 0) % 16);
1794/*      logerror("decoding track %d offset %d %d %d %d %d\n", k,
1795                        image_tracksector2offset(k, 0) / (16*16*16*16),
1796                        (image_tracksector2offset(k, 0) % (16*16*16*16)) / (16*16*16),
1797                        (image_tracksector2offset(k, 0) % (16*16*16)) / (16*16),
1798                        (image_tracksector2offset(k, 0) % (16*16)) / 16,
1799                        image_tracksector2offset(k, 0) % 16);
17711800*/
17721801
17731802      for (l = 0; l < d64_sectors_per_track[k - 1]; l++)
r5842r5843
17801809         pos = image_tracksector2offset(k, l);
17811810
17821811         /*
1783            1. Header sync       FF FF FF FF FF (40 'on' bits, not GCR encoded)
1784            2. Header info       52 54 B5 29 4B 7A 5E 95 55 55 (10 GCR bytes)
1785            3. Header gap        55 55 55 55 55 55 55 55 55 (9 bytes, never read)
1786            4. Data sync         FF FF FF FF FF (40 'on' bits, not GCR encoded)
1787            5. Data block        55...4A (325 GCR bytes)
1788            6. Inter-sector gap  55 55 55 55...55 55 (4 to 19 bytes, never read)
1789         */
1812                1. Header sync       FF FF FF FF FF (40 'on' bits, not GCR encoded)
1813                2. Header info       52 54 B5 29 4B 7A 5E 95 55 55 (10 GCR bytes)
1814                3. Header gap        55 55 55 55 55 55 55 55 55 (9 bytes, never read)
1815                4. Data sync         FF FF FF FF FF (40 'on' bits, not GCR encoded)
1816                5. Data block        55...4A (325 GCR bytes)
1817                6. Inter-sector gap  55 55 55 55...55 55 (4 to 19 bytes, never read)
1818            */
17901819
17911820         /* Header sync */
17921821         for (j = 0; j < 5; j++)
1793            gcr.data[i + j] = 0xff;
1822            filling_byte(0xff, gcr.data + i + j);
17941823         i += 5;
17951824
17961825         /* Header info */
17971826         /* These are 8 bytes unencoded, which become 10 bytes encoded */
1798         // $00 - header block ID ($08)                  // this byte can be modified by error code 20 -> 0xff
1799         // $01 - header block checksum (EOR of $02-$05)      // this byte can be modified by error code 27 -> ^ 0xff
1827         // $00 - header block ID ($08)                      // this byte can be modified by error code 20 -> 0xff
1828         // $01 - header block checksum (EOR of $02-$05)     // this byte can be modified by error code 27 -> ^ 0xff
18001829         // $02 - Sector# of data block
18011830         // $03 - Track# of data block
1802         gcr_double_2_gcr(0x08, l ^ k ^ id2 ^ id1, l, k, gcr.data + i);   
1831         gcr_double_2_gcr(0x08, l ^ k ^ id2 ^ id1, l, k, gcr.data + i);
18031832         i += 5;
18041833
18051834         // $04 - Format ID byte #2
r5842r5843
18111840
18121841         /* Header gap */
18131842         for (j = 0; j < 9; j++)
1814            gcr.data[i + j] = 0x55;
1843            filling_byte(0x55, gcr.data + i + j);
18151844         i += 9;
18161845
18171846         /* Data sync */
18181847         for (j = 0; j < 5; j++)
1819            gcr.data[i + j] = 0xff;
1848            filling_byte(0xff, gcr.data + i + j);
18201849         i += 5;
18211850
18221851         /* Data block */
r5842r5843
18261855            sector_checksum ^= copy[pos + j];
18271856
18281857         /*
1829            $00      - data block ID ($07)
1830            $01-100  - 256 bytes sector data
1831            $101     - data block checksum (EOR of $01-100)
1832            $102-103 - $00 ("off" bytes, to make the sector size a multiple of 5)
1833         */
1834         gcr_double_2_gcr(0x07, copy[pos], copy[pos + 1],
1858                $00      - data block ID ($07)
1859                $01-100  - 256 bytes sector data
1860                $101     - data block checksum (EOR of $01-100)
1861                $102-103 - $00 ("off" bytes, to make the sector size a multiple of 5)
1862            */
1863         gcr_double_2_gcr(0x07, copy[pos], copy[pos + 1],
18351864                        copy[pos + 2], gcr.data + i);
18361865         i += 5;
18371866
18381867         for (j = 1; j < 64; j++)
18391868         {
1840            gcr_double_2_gcr(copy[pos + 4 * j - 1], copy[pos + 4 * j],
1869            gcr_double_2_gcr(copy[pos + 4 * j - 1], copy[pos + 4 * j],
18411870                           copy[pos + 4 * j + 1], copy[pos + 4 * j + 2], gcr.data + i);
18421871            i += 5;
18431872         }
1844   
1873
18451874         gcr_double_2_gcr(copy[pos + 255], sector_checksum, 0x00, 0x00, gcr.data + i);
18461875         i += 5;
18471876
r5842r5843
18491878         // "In tests that the author conducted on a real 1541 disk, gap sizes of 8  to  19 bytes were seen."
18501879         // Here we put 14 as an average...
18511880         for (j = 0; j < 14; j++)
1852            gcr.data[i + j] = 0x55;
1881            filling_byte(0x55, gcr.data + i + j);
18531882         i += 14;
18541883      }
18551884   }
r5842r5843
18841913            format = format_d64_40t_err;
18851914            break;
18861915         default:
1887            logerror("The image you're trying to load has not the regular size of a .d64 image: \n");
1916            logerror("The image you're trying to load has not the regular size of a .d64 image: \n");
18881917            logerror("Image %s size %d\n", image_filename(image), filesize);
18891918            return INIT_FAIL;
18901919      }
r5842r5843
19011930            format = format_d71_err;
19021931            break;
19031932         default:
1904            logerror("The image you're trying to load has not the regular size of a .d71 image: \n");
1933            logerror("The image you're trying to load has not the regular size of a .d71 image: \n");
19051934            logerror("Image %s size %d\n", image_filename(image), filesize);
19061935            return INIT_FAIL;
19071936      }
r5842r5843
19201949      logerror("Unsupported format\n");
19211950      return INIT_FAIL;
19221951   }
1923   
1952
19241953   /* Set up track / sector map according to the format of the image */
19251954   offset_init(format, image_offset, 256);
19261955
r5842r5843
19341963   format_id_1 = temp_copy[disk_id1(format)];   // can be modified by error code 29 -> ^ 0xff
19351964   format_id_2 = temp_copy[disk_id2(format)];
19361965
1937   /* Disk is encoded and stored in xxx_drive->gcr.data */
1938   cbm_floppy_image_loading( format, format_id_1, format_id_2, temp_copy, vc1541_drive->gcr );
1966   /* Disk is encoded and stored in xxx_drive.gcr.data */
1967   cbm_floppy_image_loading( format, format_id_1, format_id_2, temp_copy, vc1541_drive.gcr );
19391968
19401969   logerror("Floppy image %s successfully loaded\n", image_filename(image));
19411970   return INIT_PASS;
r5842r5843
19691998            format = format_d64_40t_err;
19701999            break;
19712000         default:
1972            logerror("The image you're trying to load has not the regular size of a .d64 image: \n");
2001            logerror("The image you're trying to load has not the regular size of a .d64 image: \n");
19732002            logerror("Image %s size %d\n", image_filename(image), filesize);
19742003            return INIT_FAIL;
19752004      }
r5842r5843
19792008      logerror("Unsupported format\n");
19802009      return INIT_FAIL;
19812010   }
1982   
2011
19832012   /* Set up track / sector map according to the format of the image */
19842013   offset_init(format, image_offset, 256);
19852014
r5842r5843
19932022   format_id_1 = temp_copy[disk_id1(format)];   // can be modified by error code 29 -> ^ 0xff
19942023   format_id_2 = temp_copy[disk_id2(format)];
19952024
1996   /* Disk is encoded and stored in xxx_drive->gcr.data */
1997   cbm_floppy_image_loading( format, format_id_1, format_id_2, temp_copy, c1551_drive->gcr );
2025   /* Disk is encoded and stored in xxx_drive.gcr.data */
2026   cbm_floppy_image_loading( format, format_id_1, format_id_2, temp_copy, c1551_drive.gcr );
19982027
19992028   logerror("Floppy image %s successfully loaded\n", image_filename(image));
20002029   return INIT_PASS;
r5842r5843
20192048      /* --- the following bits of info are returned as pointers to data or functions --- */
20202049      case MESS_DEVINFO_PTR_LOAD:               info->load = DEVICE_IMAGE_LOAD_NAME(_1541); break;
20212050      case MESS_DEVINFO_PTR_UNLOAD:            info->unload = DEVICE_IMAGE_UNLOAD_NAME(_1541); break;
2022      case MESS_DEVINFO_PTR_DEV_SPECIFIC:         info->f = (genf *) drive_config; break;
2051      case MESS_DEVINFO_PTR_DEV_SPECIFIC:         info->f = (genf *) cbm_drive_config; break;
20232052
20242053      /* --- the following bits of info are returned as NULL-terminated strings --- */
20252054      case MESS_DEVINFO_STR_FILE_EXTENSIONS:      strcpy(info->s = device_temp_str(), "d64"); break;
r5842r5843
20392068   {
20402069      /* --- the following bits of info are returned as pointers to data or functions --- */
20412070      case MESS_DEVINFO_PTR_LOAD:               info->load = DEVICE_IMAGE_LOAD_NAME(_1551); break;
2071      case MESS_DEVINFO_PTR_DEV_SPECIFIC:            info->f = (genf *) c1551_config; break;
20422072
20432073      default:                           vc1541_device_getinfo(devclass, state, info);
20442074   }
src/mess/machine/c128.c
r5842r5843
11/***************************************************************************
22
3   commodore c128 home computer
3    commodore c128 home computer
44
5   peter.trauner@jk.uni-linz.ac.at
5    peter.trauner@jk.uni-linz.ac.at
66    documentation:
7     iDOC (http://www.softwolves.pp.se/idoc)
7     iDOC (http://www.softwolves.pp.se/idoc)
88           Christian Janoff  mepk@c64.org
99
1010***************************************************************************/
r5842r5843
6666UINT8 *c128_external_function;
6767UINT8 *c128_vdcram;
6868
69static int c64mode = 0, c128_write_io;
69static int c64mode, c128_write_io;
7070
7171static int c128_ram_bottom, c128_ram_top;
7272static UINT8 *c128_ram;
r5842r5843
7676static UINT8 c128_keyline[3] = {0xff, 0xff, 0xff};
7777
7878static int c128_va1617;
79static int c128_cia1_on = 1;
79static int c128_cia1_on;
8080static UINT8 serial_clock, serial_data, serial_atn;
81static UINT8 vicirq = 0;
82static int emulated_drive = 0;
81static UINT8 vicirq;
82static int emulated_drive;
8383
84static void c128_nmi(running_machine *machine)
84static void c128_nmi( running_machine *machine )
8585{
8686   static int nmilevel = 0;
8787   const device_config *cia_1 = devtag_get_device(machine, "cia_1");
r5842r5843
105105
106106/***********************************************
107107
108   CIA Interfaces
108    CIA Interfaces
109109
110110***********************************************/
111111
112112/*
113 *   CIA 0 - Port A keyboard line select
114 *   CIA 0 - Port B keyboard line read
113 *  CIA 0 - Port A keyboard line select
114 *  CIA 0 - Port B keyboard line read
115115 *
116 *   flag cassette read input, serial request in
117 *   irq to irq connected
116 *  flag cassette read input, serial request in
117 *  irq to irq connected
118118 *
119 *   see machine/cbm.c
119 *  see machine/cbm.c
120120 */
121121
122122static READ8_DEVICE_HANDLER( c128_cia0_port_a_r )
r5842r5843
128128
129129static READ8_DEVICE_HANDLER( c128_cia0_port_b_r )
130130{
131    UINT8 value = 0xff;
131   UINT8 value = 0xff;
132132   UINT8 cia0porta = cia_get_output_a(devtag_get_device(device->machine, "cia_0"));
133133
134134   value &= common_cia0_port_b_r(device, cia0porta);
r5842r5843
148148    vic2_lightpen_write(data & 0x10);
149149}
150150
151static void c128_irq (running_machine *machine, int level)
151static void c128_irq( running_machine *machine, int level )
152152{
153153   static int old_level = 0;
154154
r5842r5843
169169   }
170170}
171171
172static void c128_cia0_interrupt (const device_config *device, int level)
172static void c128_cia0_interrupt( const device_config *device, int level )
173173{
174174   c128_irq (device->machine, level || vicirq);
175175}
176176
177static void c128_vic_interrupt (running_machine *machine, int level)
177static void c128_vic_interrupt( running_machine *machine, int level )
178178{
179179   const device_config *cia_0 = devtag_get_device(machine, "cia_0");
180180#if 1
r5842r5843
260260   c128_vicaddr = c64_memory + helper[data & 0x03] + c128_va1617;
261261}
262262
263static void c128_cia1_interrupt (const device_config *device, int level)
263static void c128_cia1_interrupt( const device_config *device, int level )
264264{
265265   c128_nmi(device->machine);
266266}
r5842r5843
291291
292292/***********************************************
293293
294   Memory Handlers
294    Memory Handlers
295295
296296***********************************************/
297297
298static void c128_set_m8502_read_handler(running_machine *machine, UINT16 start, UINT16 end, read8_space_func rh)
298static void c128_set_m8502_read_handler( running_machine *machine, UINT16 start, UINT16 end, read8_space_func rh )
299299{
300300   const device_config *cpu;
301301   cpu = cputag_get_cpu(machine, "m8502");
302302   memory_install_read8_handler(cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM), start, end, 0, 0, rh);
303303}
304304
305static WRITE8_HANDLER(c128_dma8726_port_w)
305static WRITE8_HANDLER( c128_dma8726_port_w )
306306{
307307   DBG_LOG(space->machine, 1, "dma write", ("%.3x %.2x\n",offset,data));
308308}
309309
310static READ8_HANDLER(c128_dma8726_port_r)
310static READ8_HANDLER( c128_dma8726_port_r )
311311{
312312   DBG_LOG(space->machine, 1, "dma read", ("%.3x\n",offset));
313313   return 0xff;
r5842r5843
404404   return 0xff;
405405}
406406
407void c128_bankswitch_64(running_machine *machine, int reset)
407void c128_bankswitch_64( running_machine *machine, int reset )
408408{
409409   static int old, exrom, game;
410410   int data, loram, hiram, charen;
r5842r5843
422422   hiram = (data & 2) ? 1 : 0;
423423   charen = (data & 4) ? 1 : 0;
424424
425   if ((!c64_game && c64_exrom)
426      || (loram && hiram && !c64_exrom))
427   {
428      memory_set_bankptr (machine, 8, c64_roml);
429   }
425   if ((!c64_game && c64_exrom) || (loram && hiram && !c64_exrom))
426      memory_set_bankptr(machine, 8, c64_roml);
430427   else
431   {
432      memory_set_bankptr (machine, 8, c64_memory + 0x8000);
433   }
428      memory_set_bankptr(machine, 8, c64_memory + 0x8000);
434429
435   if ((!c64_game && c64_exrom && hiram)
436      || (!c64_exrom))
437   {
438      memory_set_bankptr (machine, 9, c64_romh);
439   }
430   if ((!c64_game && c64_exrom && hiram) || (!c64_exrom))
431      memory_set_bankptr(machine, 9, c64_romh);
440432   else if (loram && hiram)
441   {
442      memory_set_bankptr (machine, 9, c64_basic);
443   }
433      memory_set_bankptr(machine, 9, c64_basic);
444434   else
445   {
446      memory_set_bankptr (machine, 9, c64_memory + 0xa000);
447   }
435      memory_set_bankptr(machine, 9, c64_memory + 0xa000);
448436
449   if ((!c64_game && c64_exrom)
450      || (charen && (loram || hiram)))
437   if ((!c64_game && c64_exrom) || (charen && (loram || hiram)))
451438   {
452439      rh = c128_read_io;
453440      c128_write_io = 1;
r5842r5843
457444      rh = SMH_BANK(5);
458445      c128_write_io = 0;
459446      if ((!charen && (loram || hiram)))
460         memory_set_bankptr (machine, 13, c64_chargen);
447         memory_set_bankptr(machine, 13, c64_chargen);
461448      else
462         memory_set_bankptr (machine, 13, c64_memory + 0xd000);
449         memory_set_bankptr(machine, 13, c64_memory + 0xd000);
463450   }
451
464452   c128_set_m8502_read_handler(machine, 0xd000, 0xdfff, rh);
465453
466454   if (!c64_game && c64_exrom)
467455   {
468      memory_set_bankptr (machine, 14, c64_romh);
469      memory_set_bankptr (machine, 15, c64_romh+0x1f00);
470      memory_set_bankptr (machine, 16, c64_romh+0x1f05);
456      memory_set_bankptr(machine, 14, c64_romh);
457      memory_set_bankptr(machine, 15, c64_romh+0x1f00);
458      memory_set_bankptr(machine, 16, c64_romh+0x1f05);
471459   }
472460   else
473461   {
474462      if (hiram)
475463      {
476         memory_set_bankptr (machine, 14, c64_kernal);
477         memory_set_bankptr (machine, 15, c64_kernal+0x1f00);
478         memory_set_bankptr (machine, 16, c64_kernal+0x1f05);
464         memory_set_bankptr(machine, 14, c64_kernal);
465         memory_set_bankptr(machine, 15, c64_kernal+0x1f00);
466         memory_set_bankptr(machine, 16, c64_kernal+0x1f05);
479467      }
480468      else
481469      {
482         memory_set_bankptr (machine, 14, c64_memory + 0xe000);
483         memory_set_bankptr (machine, 15, c64_memory + 0xff00);
484         memory_set_bankptr (machine, 16, c64_memory + 0xff05);
470         memory_set_bankptr(machine, 14, c64_memory + 0xe000);
471         memory_set_bankptr(machine, 15, c64_memory + 0xff00);
472         memory_set_bankptr(machine, 16, c64_memory + 0xff05);
485473      }
486474   }
487475   old = data;
488   exrom= c64_exrom;
489   game=c64_game;
476   exrom = c64_exrom;
477   game =c64_game;
490478}
491479
492480static UINT8 c128_mmu[0x0b];
493481static const int c128_mmu_helper[4] =
494482{0x400, 0x1000, 0x2000, 0x4000};
495static int mmu_cpu=0;
483static int mmu_cpu;
496484static int mmu_page0, mmu_page1;
497485
498486#define MMU_PAGE1 ((((c128_mmu[10]&0xf)<<8)|c128_mmu[9])<<8)
r5842r5843
526514
527515/* typical z80 configuration
528516   0x3f 0x3f 0x7f 0x3e 0x7e 0xb0 0x0b 0x00 0x00 0x01 0x00 */
529static void c128_bankswitch_z80(running_machine *machine)
517static void c128_bankswitch_z80( running_machine *machine )
530518{
531519    c128_ram = c64_memory + MMU_RAM_ADDR;
532520    c128_va1617 = MMU_VIC_ADDR;
533521#if 1
534    memory_set_bankptr (machine, 10, c128_z80);
535    memory_set_bankptr (machine, 11, c128_ram + 0x1000);
522    memory_set_bankptr(machine, 10, c128_z80);
523    memory_set_bankptr(machine, 11, c128_ram + 0x1000);
536524    if ( (( (input_port_read(machine, "SPECIAL") & 0x06) == 0x02 ) && (MMU_RAM_ADDR >= 0x40000))
537525        || (( (input_port_read(machine, "SPECIAL") & 0x06) == 0x00) && (MMU_RAM_ADDR >= 0x20000)) )
538526       c128_ram = NULL;
r5842r5843
543531       c128_ram_bottom = 0;
544532
545533    if (MMU_RAM_ADDR==0) { /* this is used in z80 mode for rom on/off switching !*/
546       memory_set_bankptr (machine, 10, c128_z80);
547       memory_set_bankptr (machine, 11, c128_z80 + 0x400);
548    }
549    else
534       memory_set_bankptr(machine, 10, c128_z80);
535       memory_set_bankptr(machine, 11, c128_z80 + 0x400);
536    }
537    else
550538    {
551       memory_set_bankptr (machine, 10, (c128_ram_bottom > 0 ? c64_memory : c128_ram));
552       memory_set_bankptr (machine, 11, (c128_ram_bottom > 0x400 ? c64_memory : c128_ram) + 0x400);
539       memory_set_bankptr(machine, 10, (c128_ram_bottom > 0 ? c64_memory : c128_ram));
540       memory_set_bankptr(machine, 11, (c128_ram_bottom > 0x400 ? c64_memory : c128_ram) + 0x400);
553541    }
554   
555    memory_set_bankptr (machine, 1, (c128_ram_bottom > 0 ? c64_memory : c128_ram));
556    memory_set_bankptr (machine, 2, (c128_ram_bottom > 0x400 ? c64_memory : c128_ram) + 0x400);
557542
558    memory_set_bankptr (machine, 3, (c128_ram_bottom > 0x1000 ? c64_memory : c128_ram) + 0x1000);
559    memory_set_bankptr (machine, 4, (c128_ram_bottom > 0x2000 ? c64_memory : c128_ram) + 0x2000);
560    memory_set_bankptr (machine, 5, c128_ram + 0x4000);
543    memory_set_bankptr(machine, 1, (c128_ram_bottom > 0 ? c64_memory : c128_ram));
544    memory_set_bankptr(machine, 2, (c128_ram_bottom > 0x400 ? c64_memory : c128_ram) + 0x400);
561545
546    memory_set_bankptr(machine, 3, (c128_ram_bottom > 0x1000 ? c64_memory : c128_ram) + 0x1000);
547    memory_set_bankptr(machine, 4, (c128_ram_bottom > 0x2000 ? c64_memory : c128_ram) + 0x2000);
548    memory_set_bankptr(machine, 5, c128_ram + 0x4000);
549
562550    if (MMU_TOP)
563551       c128_ram_top = 0x10000 - MMU_SIZE;
564552    else
565553       c128_ram_top = 0x10000;
566554
567    if (c128_ram_top > 0xc000)
568    {
569      memory_set_bankptr (machine, 6, c128_ram + 0xc000);
570    }
571    else
572    {
573      memory_set_bankptr (machine, 6, c64_memory + 0xc000);
574    }
555    if (c128_ram_top > 0xc000)
556      memory_set_bankptr(machine, 6, c128_ram + 0xc000);
557    else
558      memory_set_bankptr(machine, 6, c64_memory + 0xc000);
575559
576    if (c128_ram_top > 0xe000)
577    {
578      memory_set_bankptr (machine, 7, c128_ram + 0xe000);
579    }
580    else
581    {
582      memory_set_bankptr (machine, 7, c64_memory + 0xd000);
583    }
560    if (c128_ram_top > 0xe000)
561      memory_set_bankptr(machine, 7, c128_ram + 0xe000);
562    else
563      memory_set_bankptr(machine, 7, c64_memory + 0xd000);
584564
585    if (c128_ram_top > 0xf000)
586    {
587      memory_set_bankptr (machine, 8, c128_ram + 0xf000);
588    }
589    else
590    {
591      memory_set_bankptr (machine, 8, c64_memory + 0xe000);
592    }
565    if (c128_ram_top > 0xf000)
566      memory_set_bankptr(machine, 8, c128_ram + 0xf000);
567    else
568      memory_set_bankptr(machine, 8, c64_memory + 0xe000);
593569
594    if (c128_ram_top > 0xff05)
595    {
596      memory_set_bankptr (machine, 9, c128_ram + 0xff05);
597    }
598    else
599    {
600      memory_set_bankptr (machine, 9, c64_memory + 0xff05);
601    }
570    if (c128_ram_top > 0xff05)
571      memory_set_bankptr(machine, 9, c128_ram + 0xff05);
572    else
573      memory_set_bankptr(machine, 9, c64_memory + 0xff05);
602574
603575    if ( (( (input_port_read(machine, "SPECIAL") & 0x06) == 0x02 ) && (MMU_RAM_ADDR >= 0x40000))
604576        || (( (input_port_read(machine, "SPECIAL") & 0x06) == 0x00) && (MMU_RAM_ADDR >= 0x20000)) )
r5842r5843
606578#endif
607579}
608580
609static void c128_bankswitch_128 (running_machine *machine, int reset)
581static void c128_bankswitch_128( running_machine *machine, int reset )
610582{
611583   read8_space_func rh;
612584
r5842r5843
619591      c128_ram_bottom = 0;
620592      c128_ram_top = 0x10000;
621593
622      memory_set_bankptr (machine, 1, c64_memory);
623      memory_set_bankptr (machine, 2, c64_memory + 0x100);
594      memory_set_bankptr(machine, 1, c64_memory);
595      memory_set_bankptr(machine, 2, c64_memory + 0x100);
624596
625      memory_set_bankptr (machine, 3, c64_memory + 0x200);
626      memory_set_bankptr (machine, 4, c64_memory + 0x400);
627      memory_set_bankptr (machine, 5, c64_memory + 0x1000);
628      memory_set_bankptr (machine, 6, c64_memory + 0x2000);
597      memory_set_bankptr(machine, 3, c64_memory + 0x200);
598      memory_set_bankptr(machine, 4, c64_memory + 0x400);
599      memory_set_bankptr(machine, 5, c64_memory + 0x1000);
600      memory_set_bankptr(machine, 6, c64_memory + 0x2000);
629601
630      memory_set_bankptr (machine, 7, c64_memory + 0x4000);
602      memory_set_bankptr(machine, 7, c64_memory + 0x4000);
631603
632      memory_set_bankptr (machine, 12, c64_memory + 0xc000);
604      memory_set_bankptr(machine, 12, c64_memory + 0xc000);
633605
634      c128_bankswitch_64 (machine, reset);
606      c128_bankswitch_64(machine, reset);
635607   }
636608   else
637609   {
638610      c128_ram = c64_memory + MMU_RAM_ADDR;
639611      c128_va1617 = MMU_VIC_ADDR;
640      memory_set_bankptr (machine, 1, c64_memory + mmu_page0);
641      memory_set_bankptr (machine, 2, c64_memory + mmu_page1);
612      memory_set_bankptr(machine, 1, c64_memory + mmu_page0);
613      memory_set_bankptr(machine, 2, c64_memory + mmu_page1);
642614      if (MMU_BOTTOM)
643615         {
644616            c128_ram_bottom = MMU_SIZE;
645617         }
646618      else
647619         c128_ram_bottom = 0;
648      memory_set_bankptr (machine, 3, (c128_ram_bottom > 0x200 ? c64_memory : c128_ram) + 0x200);
649      memory_set_bankptr (machine, 4, (c128_ram_bottom > 0x400 ? c64_memory : c128_ram) + 0x400);
650      memory_set_bankptr (machine, 5, (c128_ram_bottom > 0x1000 ? c64_memory : c128_ram) + 0x1000);
651      memory_set_bankptr (machine, 6, (c128_ram_bottom > 0x2000 ? c64_memory : c128_ram) + 0x2000);
620      memory_set_bankptr(machine, 3, (c128_ram_bottom > 0x200 ? c64_memory : c128_ram) + 0x200);
621      memory_set_bankptr(machine, 4, (c128_ram_bottom > 0x400 ? c64_memory : c128_ram) + 0x400);
622      memory_set_bankptr(machine, 5, (c128_ram_bottom > 0x1000 ? c64_memory : c128_ram) + 0x1000);
623      memory_set_bankptr(machine, 6, (c128_ram_bottom > 0x2000 ? c64_memory : c128_ram) + 0x2000);
652624
653625      if (MMU_RAM_LO)
654626      {
655         memory_set_bankptr (machine, 7, c128_ram + 0x4000);
627         memory_set_bankptr(machine, 7, c128_ram + 0x4000);
656628      }
657629      else
658630      {
659         memory_set_bankptr (machine, 7, c128_basic);
631         memory_set_bankptr(machine, 7, c128_basic);
660632      }
661633
662634      if (MMU_RAM_MID)
663635      {
664         memory_set_bankptr (machine, 8, c128_ram + 0x8000);
665         memory_set_bankptr (machine, 9, c128_ram + 0xa000);
636         memory_set_bankptr(machine, 8, c128_ram + 0x8000);
637         memory_set_bankptr(machine, 9, c128_ram + 0xa000);
666638      }
667639      else if (MMU_ROM_MID)
668640      {
669         memory_set_bankptr (machine, 8, c128_basic + 0x4000);
670         memory_set_bankptr (machine, 9, c128_basic + 0x6000);
641         memory_set_bankptr(machine, 8, c128_basic + 0x4000);
642         memory_set_bankptr(machine, 9, c128_basic + 0x6000);
671643      }
672644      else if (MMU_INTERNAL_ROM_MID)
673645      {
674         memory_set_bankptr (machine, 8, c128_internal_function);
675         memory_set_bankptr (machine, 9, c128_internal_function + 0x2000);
646         memory_set_bankptr(machine, 8, c128_internal_function);
647         memory_set_bankptr(machine, 9, c128_internal_function + 0x2000);
676648      }
677649      else
678650      {
679         memory_set_bankptr (machine, 8, c128_external_function);
680         memory_set_bankptr (machine, 9, c128_external_function + 0x2000);
651         memory_set_bankptr(machine, 8, c128_external_function);
652         memory_set_bankptr(machine, 9, c128_external_function + 0x2000);
681653      }
682654
683655      if (MMU_TOP)
r5842r5843
705677      {
706678         if (c128_ram_top > 0xc000)
707679         {
708            memory_set_bankptr (machine, 12, c128_ram + 0xc000);
680            memory_set_bankptr(machine, 12, c128_ram + 0xc000);
709681         }
710682         else
711683         {
712            memory_set_bankptr (machine, 12, c64_memory + 0xc000);
684            memory_set_bankptr(machine, 12, c64_memory + 0xc000);
713685         }
714686         if (!MMU_IO_ON)
715687         {
716688            if (c128_ram_top > 0xd000)
717689            {
718               memory_set_bankptr (machine, 13, c128_ram + 0xd000);
690               memory_set_bankptr(machine, 13, c128_ram + 0xd000);
719691            }
720692            else
721693            {
722               memory_set_bankptr (machine, 13, c64_memory + 0xd000);
694               memory_set_bankptr(machine, 13, c64_memory + 0xd000);
723695            }
724696         }
725697         if (c128_ram_top > 0xe000)
726698         {
727            memory_set_bankptr (machine, 14, c128_ram + 0xe000);
699            memory_set_bankptr(machine, 14, c128_ram + 0xe000);
728700         }
729701         else
730702         {
731            memory_set_bankptr (machine, 14, c64_memory + 0xe000);
703            memory_set_bankptr(machine, 14, c64_memory + 0xe000);
732704         }
733705         if (c128_ram_top > 0xff05)
734706         {
735            memory_set_bankptr (machine, 16, c128_ram + 0xff05);
707            memory_set_bankptr(machine, 16, c128_ram + 0xff05);
736708         }
737709         else
738710         {
739            memory_set_bankptr (machine, 16, c64_memory + 0xff05);
711            memory_set_bankptr(machine, 16, c64_memory + 0xff05);
740712         }
741713      }
742714      else if (MMU_ROM_HI)
743715      {
744         memory_set_bankptr (machine, 12, c128_editor);
716         memory_set_bankptr(machine, 12, c128_editor);
745717         if (!MMU_IO_ON) {
746            memory_set_bankptr (machine, 13, c128_chargen);
718            memory_set_bankptr(machine, 13, c128_chargen);
747719         }
748         memory_set_bankptr (machine, 14, c128_kernal);
749         memory_set_bankptr (machine, 16, c128_kernal + 0x1f05);
720         memory_set_bankptr(machine, 14, c128_kernal);
721         memory_set_bankptr(machine, 16, c128_kernal + 0x1f05);
750722      }
751723      else if (MMU_INTERNAL_ROM_HI)
752724      {
753         memory_set_bankptr (machine, 12, c128_internal_function);
725         memory_set_bankptr(machine, 12, c128_internal_function);
754726         if (!MMU_IO_ON) {
755            memory_set_bankptr (machine, 13, c128_internal_function + 0x1000);
727            memory_set_bankptr(machine, 13, c128_internal_function + 0x1000);
756728         }
757         memory_set_bankptr (machine, 14, c128_internal_function + 0x2000);
758         memory_set_bankptr (machine, 16, c128_internal_function + 0x3f05);
729         memory_set_bankptr(machine, 14, c128_internal_function + 0x2000);
730         memory_set_bankptr(machine, 16, c128_internal_function + 0x3f05);
759731      }
760732      else                  /*if (MMU_EXTERNAL_ROM_HI) */
761733      {
762         memory_set_bankptr (machine, 12, c128_external_function);
734         memory_set_bankptr(machine, 12, c128_external_function);
763735         if (!MMU_IO_ON) {
764            memory_set_bankptr (machine, 13, c128_external_function + 0x1000);
736            memory_set_bankptr(machine, 13, c128_external_function + 0x1000);
765737         }
766         memory_set_bankptr (machine, 14, c128_external_function + 0x2000);
767         memory_set_bankptr (machine, 16, c128_external_function + 0x3f05);
738         memory_set_bankptr(machine, 14, c128_external_function + 0x2000);
739         memory_set_bankptr(machine, 16, c128_external_function + 0x3f05);
768740      }
769741
770742      if ( (( (input_port_read(machine, "SPECIAL") & 0x06) == 0x02 ) && (MMU_RAM_ADDR >= 0x40000))
r5842r5843
775747
776748// 128u4
777749// FIX-ME: are the bankswitch functions working in the expected way without the memory_set_context?
778static void c128_bankswitch (running_machine *machine, int reset)
750static void c128_bankswitch( running_machine *machine, int reset )
779751{
780752   if (mmu_cpu != MMU_CPU8502)
781753   {
782754      if (!MMU_CPU8502)
783755      {
784//         DBG_LOG(machine, 1, "switching to z80", ("active %d\n",cpu_getactivecpu()) );
785//         memory_set_context(machine, 0);
756//          DBG_LOG(machine, 1, "switching to z80", ("active %d\n",cpu_getactivecpu()) );
757//          memory_set_context(machine, 0);
786758         c128_bankswitch_z80(machine);
787//         memory_set_context(machine, 1);
759//          memory_set_context(machine, 1);
788760         cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, CLEAR_LINE);
789761         cputag_set_input_line(machine, "m8502", INPUT_LINE_HALT, ASSERT_LINE);
790762      }
791763      else
792764      {
793//         DBG_LOG(machine, 1, "switching to m6502", ("active %d\n",cpu_getactivecpu()) );
794//         memory_set_context(machine, 1);
765//          DBG_LOG(machine, 1, "switching to m6502", ("active %d\n",cpu_getactivecpu()) );
766//          memory_set_context(machine, 1);
795767         c128_bankswitch_128(machine, reset);
796//         memory_set_context(machine, 0);
768//          memory_set_context(machine, 0);
797769         cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, ASSERT_LINE);
798770         cputag_set_input_line(machine, "m8502", INPUT_LINE_HALT, CLEAR_LINE);
799771
800772         /* NPW 19-Nov-2005 - In the C128, CPU #0 starts out and hands over
801          * control to CPU #1.  CPU #1 seems to execute garbage from 0x0000
802          * up to 0x1100, at which point it finally hits some code
803          * (presumably set up by CPU #1.) This always worked, but when I
804          * changed the m8502 CPU core to use an internal memory map, it
805          * started BRK-ing forever when trying to execute 0x0000.
806          *
807          * I am not sure whether the C128 actually executes this invalid
808          * memory or if this is a bug in the C128 driver.  In any case, the
809          * driver used to work with this behavior, so I am doing this hack
810          * where I set CPU #1's PC to 0x1100 on reset.
811          */
773             * control to CPU #1.  CPU #1 seems to execute garbage from 0x0000
774             * up to 0x1100, at which point it finally hits some code
775             * (presumably set up by CPU #1.) This always worked, but when I
776             * changed the m8502 CPU core to use an internal memory map, it
777             * started BRK-ing forever when trying to execute 0x0000.
778             *
779             * I am not sure whether the C128 actually executes this invalid
780             * memory or if this is a bug in the C128 driver.  In any case, the
781             * driver used to work with this behavior, so I am doing this hack
782             * where I set CPU #1's PC to 0x1100 on reset.
783             */
812784         if (cpu_get_reg(cputag_get_cpu(machine, "m8502"), REG_GENPC) == 0x0000)
813785            cpu_set_reg(cputag_get_cpu(machine, "m8502"), REG_GENPC, 0x1100);
814786      }
r5842r5843
821793      c128_bankswitch_128(machine, reset);
822794}
823795
824static void c128_mmu8722_reset (running_machine *machine)
796static void c128_mmu8722_reset( running_machine *machine )
825797{
826798   memset(c128_mmu, 0, sizeof (c128_mmu));
827799   c128_mmu[5] |= 0x38;
828800   c128_mmu[10] = 1;
829801   mmu_cpu = 0;
830    mmu_page0 = 0;
831    mmu_page1 = 0x0100;
802   mmu_page0 = 0;
803   mmu_page1 = 0x0100;
832804   c128_bankswitch (machine, 1);
833805}
834806
r5842r5843
892864      /* hinybble number of 64 kb memory blocks */
893865      if ((input_port_read(space->machine, "SPECIAL") & 0x06) == 0x02)      // 256KB RAM
894866         data = 0x4f;
895      else if ((input_port_read(space->machine, "SPECIAL") & 0x06) == 0x04)   //   1MB
867      else if ((input_port_read(space->machine, "SPECIAL") & 0x06) == 0x04)   //  1MB
896868         data = 0xf;
897      else
869      else
898870         data = 0x2f;
899871      break;
900872   case 0xc:
r5842r5843
938910
939911WRITE8_HANDLER( c128_write_0000 )
940912{
941   if (c128_ram!=NULL)
913   if (c128_ram != NULL)
942914      c128_ram[0x0000 + offset] = data;
943915}
944916
945917WRITE8_HANDLER( c128_write_1000 )
946918{
947   if (c128_ram!=NULL)
919   if (c128_ram != NULL)
948920      c128_ram[0x1000 + offset] = data;
949921}
950922
951923WRITE8_HANDLER( c128_write_4000 )
952924{
953   if (c128_ram!=NULL)
925   if (c128_ram != NULL)
954926      c128_ram[0x4000 + offset] = data;
955927}
956928
957929WRITE8_HANDLER( c128_write_8000 )
958930{
959   if (c128_ram!=NULL)
931   if (c128_ram != NULL)
960932      c128_ram[0x8000 + offset] = data;
961933}
962934
963935WRITE8_HANDLER( c128_write_a000 )
964936{
965   if (c128_ram!=NULL)
937   if (c128_ram != NULL)
966938      c128_ram[0xa000 + offset] = data;
967939}
968940
969941WRITE8_HANDLER( c128_write_c000 )
970942{
971   if (c128_ram!=NULL)
943   if (c128_ram != NULL)
972944      c128_ram[0xc000 + offset] = data;
973945}
974946
r5842r5843
976948{
977949   if (offset + 0xe000 >= c128_ram_top)
978950      c64_memory[0xe000 + offset] = data;
979   else if (c128_ram!=NULL)
951   else if (c128_ram != NULL)
980952      c128_ram[0xe000 + offset] = data;
981953}
982954
983955WRITE8_HANDLER( c128_write_ff00 )
984956{
985957   if (!c64mode)
986      c128_mmu8722_ff00_w (space, offset, data);
958      c128_mmu8722_ff00_w(space, offset, data);
987959   else if (c128_ram!=NULL)
988960      c64_memory[0xff00 + offset] = data;
989961}
r5842r5843
1018990         return c64_chargen[offset & 0xfff];
1019991      return c64_vicaddr[offset];
1020992   }
1021   if ( !(c64_port6510&4)
1022       && (((c128_vicaddr - c64_memory + offset) & 0x7000) == 0x1000) )
993   if (!(c64_port6510&4)
994       && (((c128_vicaddr - c64_memory + offset) & 0x7000) == 0x1000))
1023995      return c128_chargen[offset & 0xfff];
1024996   return c128_vicaddr[offset];
1025997}
r5842r5843
10351007}
10361008
10371009/* 2008-09-01
1038   We need here the m6510 port handlers from c64, otherwise c128_common_driver_init
1039   seems unable to use correctly the timer.
1040   This will be probably fixed in a future clean up.
1010    We need here the m6510 port handlers from c64, otherwise c128_common_driver_init
1011    seems unable to use correctly the timer.
1012    This will be probably fixed in a future clean up.
10411013*/
10421014
10431015static emu_timer *datasette_timer;
10441016
1045void c128_m6510_port_write(const device_config *device, UINT8 direction, UINT8 data)
1017void c128_m6510_port_write( const device_config *device, UINT8 direction, UINT8 data )
10461018{
10471019   /* if line is marked as input then keep current value */
10481020   data = (c64_port_data & ~direction) | (data & direction);
10491021
10501022   /* resistors make P0,P1,P2 go high when respective line is changed to input */
1051   if (!(direction & 0x04))
1023   if (!(direction & 0x04))
10521024      data |= 0x04;
10531025
10541026   if (!(direction & 0x02))
r5842r5843
10611033
10621034   if (c64_tape_on)
10631035   {
1064      if (direction & 0x08)
1036      if (direction & 0x08)
10651037      {
10661038         cassette_output(devtag_get_device(device->machine, "cassette"), (data & 0x08) ? -(0x5a9e >> 1) : +(0x5a9e >> 1));
10671039      }
10681040
10691041      if (direction & 0x20)
10701042      {
1071         if(!(data & 0x20))
1043         if (!(data & 0x20))
10721044         {
10731045            cassette_change_state(devtag_get_device(device->machine, "cassette"),CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR);
10741046            timer_adjust_periodic(datasette_timer, attotime_zero, 0, ATTOTIME_IN_HZ(44100));
r5842r5843
10871059   c64_memory[0x001] = memory_read_byte( cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM), 1 );
10881060}
10891061
1090UINT8 c128_m6510_port_read(const device_config *device, UINT8 direction)
1062UINT8 c128_m6510_port_read( const device_config *device, UINT8 direction )
10911063{
10921064   UINT8 data = c64_port_data;
10931065
r5842r5843
11041076   return data;
11051077}
11061078
1107static void c128_common_driver_init(running_machine *machine)
1079static void c128_common_driver_init( running_machine *machine )
11081080{
11091081   UINT8 *gfx=memory_region(machine, "gfx1");
11101082   UINT8 *ram = memory_region(machine, "maincpu");
r5842r5843
11121084
11131085   c64_memory = ram;
11141086
1115   c128_basic = ram+0x100000;
1116   c64_basic = ram+0x108000;
1117   c64_kernal = ram+0x10a000;
1118   c128_editor = ram+0x10c000;
1119   c128_z80 = ram+0x10d000;
1120   c128_kernal = ram+0x10e000;
1121   c128_internal_function = ram+0x110000;
1122   c128_external_function = ram+0x118000;
1123   c64_chargen = ram+0x120000;
1124   c128_chargen = ram+0x121000;
1125   c64_colorram = ram+0x122000;
1126   c128_vdcram = ram+0x122800;
1087   c128_basic = ram + 0x100000;
1088   c64_basic = ram + 0x108000;
1089   c64_kernal = ram + 0x10a000;
1090   c128_editor = ram + 0x10c000;
1091   c128_z80 = ram + 0x10d000;
1092   c128_kernal = ram + 0x10e000;
1093   c128_internal_function = ram + 0x110000;
1094   c128_external_function = ram + 0x118000;
1095   c64_chargen = ram + 0x120000;
1096   c128_chargen = ram + 0x121000;
1097   c64_colorram = ram + 0x122000;
1098   c128_vdcram = ram + 0x122800;
11271099
1128   for (i=0; i<0x100; i++)
1129      gfx[i]=i;
1100   c64mode = 0;
1101   c128_cia1_on = 1;
1102   vicirq = 0;
11301103
1104   for (i = 0; i < 0x100; i++)
1105      gfx[i] = i;
1106
11311107   if (c64_tape_on)
11321108      datasette_timer = timer_alloc(machine, c64_tape_timer, NULL);
11331109}
r5842r5843
11351111DRIVER_INIT( c128 )
11361112{
11371113   c64_tape_on = 1;
1114   c64_pal = 0;
1115   emulated_drive = 0;
11381116   c128_common_driver_init(machine);
11391117   vic6567_init(1, c64_pal, c128_dma_read, c128_dma_read_color, c128_vic_interrupt);
11401118   vic2_set_rastering(0);
r5842r5843
11461124{
11471125   c64_tape_on = 1;
11481126   c64_pal = 1;
1127   emulated_drive = 0;
11491128   c128_common_driver_init(machine);
11501129   vic6567_init(1, c64_pal, c128_dma_read, c128_dma_read_color, c128_vic_interrupt);
11511130   vic2_set_rastering(1);
r5842r5843
11571136{
11581137   DRIVER_INIT_CALL( c128 );
11591138   emulated_drive = 1;
1160   drive_config(machine, type_1571, 0, 0, "cpu_vc1571", 8);
1139   cbm_drive_config(machine, type_1571, 0, 0, "cpu_vc1571", 8);
11611140}
11621141
11631142DRIVER_INIT( c128dpal )
11641143{
11651144   DRIVER_INIT_CALL( c128pal );
11661145   emulated_drive = 1;
1167   drive_config(machine, type_1571, 0, 0, "cpu_vc1571", 8);
1146   cbm_drive_config(machine, type_1571, 0, 0, "cpu_vc1571", 8);
11681147}
11691148
11701149DRIVER_INIT( c128dcr )
11711150{
11721151   DRIVER_INIT_CALL( c128 );
11731152   emulated_drive = 1;
1174   drive_config(machine, type_1571cr, 0, 0, "cpu_vc1571", 8);
1153   cbm_drive_config(machine, type_1571cr, 0, 0, "cpu_vc1571", 8);
11751154}
11761155
11771156DRIVER_INIT( c128dcrp )
11781157{
11791158   DRIVER_INIT_CALL( c128pal );
11801159   emulated_drive = 1;
1181   drive_config(machine, type_1571cr, 0, 0, "cpu_vc1571", 8);
1160   cbm_drive_config(machine, type_1571cr, 0, 0, "cpu_vc1571", 8);
11821161}
11831162
11841163DRIVER_INIT( c128d81 )
11851164{
11861165   DRIVER_INIT_CALL( c128 );
11871166   emulated_drive = 1;
1188   drive_config(machine, type_1581, 0, 0, "cpu_vc1571", 8);
1167   cbm_drive_config(machine, type_1581, 0, 0, "cpu_vc1571", 8);
11891168}
11901169
11911170MACHINE_START( c128 )
11921171{
11931172   if (emulated_drive)
11941173   {
1195      drive_reset();
1174      cbm_drive_reset(machine);
11961175   }
11971176   else if (c128_cia1_on)
11981177   {
r5842r5843
12111190{
12121191   c128_vicaddr = c64_vicaddr = c64_memory;
12131192   c64mode = 0;
1214   c128_mmu8722_reset (machine);
1193   c128_mmu8722_reset(machine);
12151194   cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, CLEAR_LINE);
12161195   cputag_set_input_line(machine, "m8502", INPUT_LINE_HALT, ASSERT_LINE);
12171196}
r5842r5843
12501229   cbm_common_interrupt(device);
12511230
12521231   /* Fix Me! Currently, neither left Shift nor Shift Lock work in c128, but reading the correspondent input produces a bug!
1253   Hence, we overwrite the actual reading as it never happens */
1254   if ((input_port_read(device->machine, "SPECIAL") & 0x40))   //
1232    Hence, we overwrite the actual reading as it never happens */
1233   if ((input_port_read(device->machine, "SPECIAL") & 0x40))   //
12551234      c64_keyline[1] |= 0x80;
12561235
12571236   /* c128 specific: keypad input ports */
src/mess/machine/pet.c
r5842r5843
3131      } \
3232   } while (0)
3333
34int pet_font = 0;
34int pet_font;
3535UINT8 *pet_memory;
3636UINT8 *superpet_memory;
3737UINT8 *pet_videoram;
r5842r5843
7474  cb1 video sync in
7575  cb2 cassette 1 motor out
7676*/
77static READ8_DEVICE_HANDLER ( pet_pia0_port_a_read )
77static READ8_DEVICE_HANDLER( pet_pia0_port_a_read )
7878{
7979   const device_config *ieeebus = devtag_get_device(device->machine, "ieee_bus");
8080   int data = 0xf0 | pet_keyline_select;
r5842r5843
9191   return data;
9292}
9393
94static WRITE8_DEVICE_HANDLER ( pet_pia0_port_a_write )
94static WRITE8_DEVICE_HANDLER( pet_pia0_port_a_write )
9595{
9696   pet_keyline_select = data & 0x0f;
9797}
9898
9999/* Keyboard reading/handling for regular keyboard */
100static  READ8_DEVICE_HANDLER ( pet_pia0_port_b_read )
100static  READ8_DEVICE_HANDLER( pet_pia0_port_b_read )
101101{
102102   UINT8 data = 0xff;
103103   static const char *const keynames[] = { "ROW0", "ROW1", "ROW2", "ROW3", "ROW4",
r5842r5843
193193  cb1 srq in
194194  cb2 dav out
195195 */
196static READ8_DEVICE_HANDLER ( pet_pia1_port_a_read )
196static READ8_DEVICE_HANDLER( pet_pia1_port_a_read )
197197{
198198   const device_config *ieeebus = devtag_get_device(device->machine, "ieee_bus");
199199   return cbm_ieee_data_r(ieeebus, 0);
200200}
201201
202static WRITE8_DEVICE_HANDLER ( pet_pia1_port_b_write )
202static WRITE8_DEVICE_HANDLER( pet_pia1_port_b_write )
203203{
204204   const device_config *ieeebus = devtag_get_device(device->machine, "ieee_bus");
205205   cbm_ieee_data_write(ieeebus, 0, data);
206206}
207207
208static READ8_DEVICE_HANDLER ( pet_pia1_ca1_read )
208static READ8_DEVICE_HANDLER( pet_pia1_ca1_read )
209209{
210210   const device_config *ieeebus = devtag_get_device(device->machine, "ieee_bus");
211211   return cbm_ieee_atn_r(ieeebus,0 );
212212}
213213
214static WRITE8_DEVICE_HANDLER ( pet_pia1_ca2_write )
214static WRITE8_DEVICE_HANDLER( pet_pia1_ca2_write )
215215{
216216   const device_config *ieeebus = devtag_get_device(device->machine, "ieee_bus");
217217   cbm_ieee_ndac_write(ieeebus, 0, data);
218218}
219219
220static WRITE8_DEVICE_HANDLER ( pet_pia1_cb2_write )
220static WRITE8_DEVICE_HANDLER( pet_pia1_cb2_write )
221221{
222222   const device_config *ieeebus = devtag_get_device(device->machine, "ieee_bus");
223223   cbm_ieee_dav_write(ieeebus, 0, data);
224224}
225225
226static READ8_DEVICE_HANDLER ( pet_pia1_cb1_read )
226static READ8_DEVICE_HANDLER( pet_pia1_cb1_read )
227227{
228228   const device_config *ieeebus = devtag_get_device(device->machine, "ieee_bus");
229229   return cbm_ieee_srq_r(ieeebus, 0);
r5842r5843
265265{
266266   DEVCB_HANDLER(pet_pia1_port_a_read),      /* in_a_func */
267267   DEVCB_NULL,                  /* in_b_func */
268    DEVCB_HANDLER(pet_pia1_ca1_read),         /* in_ca1_func */
269    DEVCB_HANDLER(pet_pia1_cb1_read),         /* in_cb1_func */
268   DEVCB_HANDLER(pet_pia1_ca1_read),         /* in_ca1_func */
269   DEVCB_HANDLER(pet_pia1_cb1_read),         /* in_cb1_func */
270270   DEVCB_NULL,                  /* in_ca2_func */
271271   DEVCB_NULL,                  /* in_cb2_func */
272272   DEVCB_NULL,                  /* out_a_func */
273    DEVCB_HANDLER(pet_pia1_port_b_write),      /* out_b_func */
274    DEVCB_HANDLER(pet_pia1_ca2_write),         /* out_ca2_func */
275    DEVCB_HANDLER(pet_pia1_cb2_write),         /* out_cb2_func */
273   DEVCB_HANDLER(pet_pia1_port_b_write),      /* out_b_func */
274   DEVCB_HANDLER(pet_pia1_ca2_write),         /* out_ca2_func */
275   DEVCB_HANDLER(pet_pia1_cb2_write),         /* out_cb2_func */
276276   DEVCB_NULL,
277277   DEVCB_NULL
278278};
r5842r5843
306306   const device_config *ieeebus = devtag_get_device(device->machine, "ieee_bus");
307307   UINT8 data = 0;
308308
309   if (cbm_ieee_ndac_r(ieeebus, 0))
309   if (cbm_ieee_ndac_r(ieeebus, 0))
310310      data |= 0x01;
311311
312312   //  data & 0x08 -> cassette write (it seems to BOTH cassettes from schematics)
r5842r5843
322322      timer_reset(datasette2_timer, attotime_never);
323323   }
324324
325   if (cbm_ieee_nrfd_r(ieeebus, 0))
325   if (cbm_ieee_nrfd_r(ieeebus, 0))
326326      data |= 0x40;
327327
328   if (cbm_ieee_dav_r(ieeebus, 0))
328   if (cbm_ieee_dav_r(ieeebus, 0))
329329      data |= 0x80;
330330
331331   return data;
r5842r5843
365365   int rom; /* rom socket 6502? at 0x9000 */
366366} spet= { 0 };
367367
368static WRITE8_HANDLER(cbm8096_io_w)
368static WRITE8_HANDLER( cbm8096_io_w )
369369{
370370   const device_config *via_0 = devtag_get_device(space->machine, "via6522_0");
371371   const device_config *pia_0 = devtag_get_device(space->machine, "pia_0");
r5842r5843
382382   else if (offset == 0x81) pet_mc6845_register_w(space, offset, data);
383383}
384384
385static READ8_HANDLER(cbm8096_io_r)
385static READ8_HANDLER( cbm8096_io_r )
386386{
387387   const device_config *via_0 = devtag_get_device(space->machine, "via6522_0");
388388   const device_config *pia_0 = devtag_get_device(space->machine, "pia_0");
r5842r5843
400400   return data;
401401}
402402
403static WRITE8_HANDLER(pet80_bank1_w) {
403static WRITE8_HANDLER( pet80_bank1_w )
404{
404405   pet80_bank1_base[offset] = data;
405406}
406407
r5842r5843
415416        bit 7    1=enable expansion memory
416417
417418*/
418WRITE8_HANDLER(cbm8096_w)
419WRITE8_HANDLER( cbm8096_w )
419420{
420421   read8_space_func rh;
421422   write8_space_func wh;
r5842r5843
445446      if (data & 0x20)
446447      {
447448         pet80_bank1_base = pet_memory + 0x8000;
448         memory_set_bankptr (space->machine, 1, pet80_bank1_base);
449         memory_set_bankptr(space->machine, 1, pet80_bank1_base);
449450         wh = pet80_bank1_w;
450451      }
451452      else
r5842r5843
467468         if (!(data & 0x20))
468469         {
469470            pet80_bank1_base = pet_memory + 0x14000;
470            memory_set_bankptr (space->machine, 1, pet80_bank1_base);
471            memory_set_bankptr(space->machine, 1, pet80_bank1_base);
471472         }
472         memory_set_bankptr (space->machine, 2, pet_memory + 0x15000);
473         memory_set_bankptr (space->machine, 3, pet_memory + 0x16000);
474         memory_set_bankptr (space->machine, 4, pet_memory + 0x17000);
473         memory_set_bankptr(space->machine, 2, pet_memory + 0x15000);
474         memory_set_bankptr(space->machine, 3, pet_memory + 0x16000);
475         memory_set_bankptr(space->machine, 4, pet_memory + 0x17000);
475476      }
476477      else
477478      {
478479         if (!(data & 0x20))
479480         {
480481            pet80_bank1_base = pet_memory + 0x10000;
481            memory_set_bankptr (space->machine, 1, pet80_bank1_base);
482            memory_set_bankptr(space->machine, 1, pet80_bank1_base);
482483         }
483         memory_set_bankptr (space->machine, 2, pet_memory + 0x11000);
484         memory_set_bankptr (space->machine, 3, pet_memory + 0x12000);
485         memory_set_bankptr (space->machine, 4, pet_memory + 0x13000);
484         memory_set_bankptr(space->machine, 2, pet_memory + 0x11000);
485         memory_set_bankptr(space->machine, 3, pet_memory + 0x12000);
486         memory_set_bankptr(space->machine, 4, pet_memory + 0x13000);
486487      }
487488
488489      if (data & 8)
489490      {
490491         if (!(data & 0x40))
491492         {
492            memory_set_bankptr (space->machine, 7, pet_memory + 0x1e800);
493            memory_set_bankptr(space->machine, 7, pet_memory + 0x1e800);
493494         }
494         memory_set_bankptr (space->machine, 6, pet_memory + 0x1c000);
495         memory_set_bankptr (space->machine, 8, pet_memory + 0x1f000);
496         memory_set_bankptr (space->machine, 9, pet_memory + 0x1fff1);
495         memory_set_bankptr(space->machine, 6, pet_memory + 0x1c000);
496         memory_set_bankptr(space->machine, 8, pet_memory + 0x1f000);
497         memory_set_bankptr(space->machine, 9, pet_memory + 0x1fff1);
497498      }
498499      else
499500      {
500501         if (!(data & 0x40))
501502         {
502            memory_set_bankptr (space->machine, 7, pet_memory+ 0x1a800);
503            memory_set_bankptr(space->machine, 7, pet_memory+ 0x1a800);
503504         }
504         memory_set_bankptr (space->machine, 6, pet_memory + 0x18000);
505         memory_set_bankptr (space->machine, 8, pet_memory + 0x1b000);
506         memory_set_bankptr (space->machine, 9, pet_memory + 0x1bff1);
505         memory_set_bankptr(space->machine, 6, pet_memory + 0x18000);
506         memory_set_bankptr(space->machine, 8, pet_memory + 0x1b000);
507         memory_set_bankptr(space->machine, 9, pet_memory + 0x1bff1);
507508      }
508509   }
509510   else
510511   {
511512      pet80_bank1_base = pet_memory + 0x8000;
512      memory_set_bankptr (space->machine, 1, pet80_bank1_base );
513      memory_set_bankptr(space->machine, 1, pet80_bank1_base );
513514      memory_install_write8_handler(space, 0x8000, 0x8fff, 0, 0, pet80_bank1_w);
514515
515      memory_set_bankptr (space->machine, 2, pet_memory + 0x9000);
516      memory_set_bankptr(space->machine, 2, pet_memory + 0x9000);
516517      memory_install_write8_handler(space, 0x9000, 0x9fff, 0, 0, SMH_UNMAP);
517518
518      memory_set_bankptr (space->machine, 3, pet_memory + 0xa000);
519      memory_set_bankptr(space->machine, 3, pet_memory + 0xa000);
519520      memory_install_write8_handler(space, 0xa000, 0xafff, 0, 0, SMH_UNMAP);
520521
521      memory_set_bankptr (space->machine, 4, pet_memory + 0xb000);
522      memory_set_bankptr(space->machine, 4, pet_memory + 0xb000);
522523      memory_install_write8_handler(space, 0xb000, 0xbfff, 0, 0, SMH_UNMAP);
523524
524      memory_set_bankptr (space->machine, 6, pet_memory + 0xc000);
525      memory_set_bankptr(space->machine, 6, pet_memory + 0xc000);
525526      memory_install_write8_handler(space, 0xc000, 0xe7ff, 0, 0, SMH_UNMAP);
526527
527528      memory_install_read8_handler(space, 0xe800, 0xefff, 0, 0, cbm8096_io_r);
528529      memory_install_write8_handler(space, 0xe800, 0xefff, 0, 0, cbm8096_io_w);
529530
530      memory_set_bankptr (space->machine, 8, pet_memory + 0xf000);
531      memory_set_bankptr(space->machine, 8, pet_memory + 0xf000);
531532      memory_install_write8_handler(space, 0xf000, 0xffef, 0, 0, SMH_UNMAP);
532533
533      memory_set_bankptr (space->machine, 9, pet_memory + 0xfff1);
534      memory_set_bankptr(space->machine, 9, pet_memory + 0xfff1);
534535      memory_install_write8_handler(space, 0xfff1, 0xffff, 0, 0, SMH_UNMAP);
535536   }
536537}
537538
538READ8_HANDLER(superpet_r)
539READ8_HANDLER( superpet_r )
539540{
540541   return 0xff;
541542}
542543
543WRITE8_HANDLER(superpet_w)
544WRITE8_HANDLER( superpet_w )
544545{
545546   switch (offset)
546547   {
r5842r5843
568569   }
569570}
570571
571static TIMER_CALLBACK(pet_interrupt)
572static TIMER_CALLBACK( pet_interrupt )
572573{
573574   const device_config *pia_0 = devtag_get_device(machine, "pia_0");
574575   static int level = 0;
r5842r5843
597598}
598599
599600
600static void pet_common_driver_init(running_machine *machine)
601static void pet_common_driver_init( running_machine *machine )
601602{
602603   int i;
603604   pet_state *state = machine->driver_data;
604605
606   pet_font = 0;
607
605608   state->pet_basic1 = 0;
606609   state->superpet = 0;
607610   state->cbm8096 = 0;
608611
609612   memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0000, mess_ram_size - 1, 0, 0, SMH_BANK(10));
610613   memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0000, mess_ram_size - 1, 0, 0, SMH_BANK(10));
611   memory_set_bankptr (machine, 10, pet_memory);
614   memory_set_bankptr(machine, 10, pet_memory);
612615
613616   if (mess_ram_size < 0x8000)
614617   {
r5842r5843
756759
757760   filetype = image_filetype(image);
758761
759    if (!mame_stricmp (filetype, "crt"))
762    if (!mame_stricmp(filetype, "crt"))
760763   {
761764   /* We temporarily remove .crt loading. Previous versions directly used
762765    the same routines used to load C64 .crt file, but I seriously doubt the
r5842r5843
766769   else
767770   {
768771      /* Assign loading address according to extension */
769      if (!mame_stricmp (filetype, "a0"))
772      if (!mame_stricmp(filetype, "a0"))
770773         address = 0xa000;
771774
772      else if (!mame_stricmp (filetype, "b0"))
775      else if (!mame_stricmp(filetype, "b0"))
773776         address = 0xb000;
774777
775778      logerror("Loading cart %s at %.4x size:%.4x\n", image_filename(image), address, size);
src/mess/machine/c16.c
r5842r5843
11/***************************************************************************
22
3   commodore c16 home computer
3    commodore c16 home computer
44
5   peter.trauner@jk.uni-linz.ac.at
5    peter.trauner@jk.uni-linz.ac.at
66    documentation
7     www.funet.fi
7     www.funet.fi
88
99***************************************************************************/
1010
r5842r5843
5656
5757static UINT8 port6529;
5858
59static int lowrom = 0, highrom = 0;
59static int lowrom, highrom;
6060
6161static UINT8 *c16_memory_10000;
6262static UINT8 *c16_memory_14000;
r5842r5843
6767static UINT8 *c16_memory_28000;
6868static UINT8 *c16_memory_2c000;
6969
70static int has_c1551 = 0, has_vc1541 = 0, has_iec8 = 0, has_iec9 = 0; // Notice that iec8 & iec9 have never been implemented
70static int has_c1551, has_vc1541, has_iec8, has_iec9; // Notice that iec8 & iec9 have never been implemented
7171
72static UINT8 read_cfg1(running_machine *machine)
72static UINT8 read_cfg1( running_machine *machine )
7373{
7474   UINT8 result;
75   switch(mame_get_phase(machine))
75   switch (mame_get_phase(machine))
7676   {
7777      case MAME_PHASE_RESET:
7878      case MAME_PHASE_RUNNING:
r5842r5843
110110  p7 serial data in, serial bus 5
111111*/
112112
113void c16_m7501_port_write(const device_config *device, UINT8 direction, UINT8 data)
113void c16_m7501_port_write( const device_config *device, UINT8 direction, UINT8 data )
114114{
115115   const device_config *serbus = devtag_get_device(device->machine, "serial_bus");
116116   int dat, atn, clk;
r5842r5843
121121   cbm_serial_data_write(serbus, 0, dat = !(data & 0x01));
122122
123123   cassette_output(devtag_get_device(device->machine, "cassette"), !(data & 0x02) ? -(0x5a9e >> 1) : +(0x5a9e >> 1));
124   
124
125125   cassette_change_state(devtag_get_device(device->machine, "cassette"), (data & 0x08) ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED, CASSETTE_MASK_MOTOR);
126126}
127127
128UINT8 c16_m7501_port_read(const device_config *device, UINT8 direction)
128UINT8 c16_m7501_port_read( const device_config *device, UINT8 direction )
129129{
130130   UINT8 data = 0xff;
131131   UINT8 c16_port7501 = (UINT8) devtag_get_info_int(device->machine, "maincpu", CPUINFO_INT_M6510_PORT);
r5842r5843
137137   if ((c16_port7501 & 0x02) || !cbm_serial_clock_read(serbus, 0))
138138      data &= ~0x40;
139139
140//   data &= ~0x20; // port bit not in pinout
140//  data &= ~0x20; // port bit not in pinout
141141
142142   if (cassette_input(devtag_get_device(device->machine, "cassette")) > +0.0)
143143      data |=  0x10;
r5842r5843
147147   return data;
148148}
149149
150static void c16_bankswitch (running_machine *machine)
150static void c16_bankswitch( running_machine *machine )
151151{
152152   UINT8 *rom = memory_region(machine, "maincpu");
153   memory_set_bankptr (machine, 9, mess_ram);
153   memory_set_bankptr(machine, 9, mess_ram);
154154
155155   switch (lowrom)
156156   {
157157   case 0:
158      memory_set_bankptr (machine, 2, rom + 0x10000);
158      memory_set_bankptr(machine, 2, rom + 0x10000);
159159      break;
160160   case 1:
161      memory_set_bankptr (machine, 2, rom + 0x18000);
161      memory_set_bankptr(machine, 2, rom + 0x18000);
162162      break;
163163   case 2:
164      memory_set_bankptr (machine, 2, rom + 0x20000);
164      memory_set_bankptr(machine, 2, rom + 0x20000);
165165      break;
166166   case 3:
167      memory_set_bankptr (machine, 2, rom + 0x28000);
167      memory_set_bankptr(machine, 2, rom + 0x28000);
168168      break;
169169   }
170170
171171   switch (highrom)
172172   {
173173   case 0:
174      memory_set_bankptr (machine, 3, rom + 0x14000);
175      memory_set_bankptr (machine, 8, rom + 0x17f20);
174      memory_set_bankptr(machine, 3, rom + 0x14000);
175      memory_set_bankptr(machine, 8, rom + 0x17f20);
176176      break;
177177   case 1:
178      memory_set_bankptr (machine, 3, rom + 0x1c000);
179      memory_set_bankptr (machine, 8, rom + 0x1ff20);
178      memory_set_bankptr(machine, 3, rom + 0x1c000);
179      memory_set_bankptr(machine, 8, rom + 0x1ff20);
180180      break;
181181   case 2:
182      memory_set_bankptr (machine, 3, rom + 0x24000);
183      memory_set_bankptr (machine, 8, rom + 0x27f20);
182      memory_set_bankptr(machine, 3, rom + 0x24000);
183      memory_set_bankptr(machine, 8, rom + 0x27f20);
184184      break;
185185   case 3:
186      memory_set_bankptr (machine, 3, rom + 0x2c000);
187      memory_set_bankptr (machine, 8, rom + 0x2ff20);
186      memory_set_bankptr(machine, 3, rom + 0x2c000);
187      memory_set_bankptr(machine, 8, rom + 0x2ff20);
188188      break;
189189   }
190   memory_set_bankptr (machine, 4, rom + 0x17c00);
190   memory_set_bankptr(machine, 4, rom + 0x17c00);
191191}
192192
193WRITE8_HANDLER(c16_switch_to_rom)
193WRITE8_HANDLER( c16_switch_to_rom )
194194{
195195   ted7360_rom = 1;
196196   c16_bankswitch(space->machine);
r5842r5843
209209 * 0  1  plus4 hi
210210 * 1  0  c1 high
211211 * 1  1  c2 high */
212WRITE8_HANDLER(c16_select_roms)
212WRITE8_HANDLER( c16_select_roms )
213213{
214214   lowrom = offset & 0x03;
215215   highrom = (offset & 0x0c) >> 2;
r5842r5843
217217      c16_bankswitch(space->machine);
218218}
219219
220WRITE8_HANDLER(c16_switch_to_ram)
220WRITE8_HANDLER( c16_switch_to_ram )
221221{
222222   ted7360_rom = 0;
223   memory_set_bankptr (space->machine, 2, mess_ram + (0x8000 % mess_ram_size));
224   memory_set_bankptr (space->machine, 3, mess_ram + (0xc000 % mess_ram_size));
225   memory_set_bankptr (space->machine, 4, mess_ram + (0xfc00 % mess_ram_size));
226   memory_set_bankptr (space->machine, 8, mess_ram + (0xff20 % mess_ram_size));
223   memory_set_bankptr(space->machine, 2, mess_ram + (0x8000 % mess_ram_size));
224   memory_set_bankptr(space->machine, 3, mess_ram + (0xc000 % mess_ram_size));
225   memory_set_bankptr(space->machine, 4, mess_ram + (0xfc00 % mess_ram_size));
226   memory_set_bankptr(space->machine, 8, mess_ram + (0xff20 % mess_ram_size));
227227}
228228
229int c16_read_keyboard (int databus)
229int c16_read_keyboard( int databus )
230230{
231231   int value = 0xff;
232232
r5842r5843
255255      value &= keyline[7];
256256
257257   /* looks like joy 0 needs dataline2 low
258    * and joy 1 needs dataline1 low
259    * write to 0xff08 (value on databus) reloads latches */
258     * and joy 1 needs dataline1 low
259     * write to 0xff08 (value on databus) reloads latches */
260260   if (!(databus & 0x04))
261261      value &= keyline[8];
262262
r5842r5843
277277 * output low means keyboard line selected
278278 * keyboard line is then read into the ted7360 latch
279279 */
280WRITE8_HANDLER(c16_6529_port_w)
280WRITE8_HANDLER( c16_6529_port_w )
281281{
282282   port6529 = data;
283283}
284284
285 READ8_HANDLER(c16_6529_port_r)
285READ8_HANDLER( c16_6529_port_r )
286286{
287287   return port6529 & (c16_read_keyboard (0xff /*databus */ ) | (port6529 ^ 0xff));
288288}
r5842r5843
297297 * p6 Userport j
298298 * p7 Userport f
299299 */
300WRITE8_HANDLER(plus4_6529_port_w)
300WRITE8_HANDLER( plus4_6529_port_w )
301301{
302302}
303303
304READ8_HANDLER(plus4_6529_port_r)
304READ8_HANDLER( plus4_6529_port_r )
305305{
306306   int data = 0x00;
307307
r5842r5843
313313   return data;
314314}
315315
316READ8_HANDLER(c16_fd1x_r)
316READ8_HANDLER( c16_fd1x_r )
317317{
318318   int data = 0x00;
319319
r5842r5843
362362   1111 19200
363363 control register
364364  */
365WRITE8_HANDLER(c16_6551_port_w)
365WRITE8_HANDLER( c16_6551_port_w )
366366{
367367   offset &= 0x03;
368368   DBG_LOG(space->machine, 3, "6551", ("port write %.2x %.2x\n", offset, data));
369369   port6529 = data;
370370}
371371
372READ8_HANDLER(c16_6551_port_r)
372READ8_HANDLER( c16_6551_port_r )
373373{
374374   int data = 0x00;
375375
r5842r5843
378378   return data;
379379}
380380
381static READ8_HANDLER(ted7360_dma_read)
381static READ8_HANDLER( ted7360_dma_read )
382382{
383383   return mess_ram[offset % mess_ram_size];
384384}
385385
386static  READ8_HANDLER(ted7360_dma_read_rom)
386static  READ8_HANDLER( ted7360_dma_read_rom )
387387{
388388   /* should read real c16 system bus from 0xfd00 -ff1f */
389389   if (offset >= 0xc000)
r5842r5843
421421   return mess_ram[offset % mess_ram_size];
422422}
423423
424void c16_interrupt (running_machine *machine, int level)
424void c16_interrupt( running_machine *machine, int level )
425425{
426426   static int old_level;
427427
r5842r5843
433433   }
434434}
435435
436static void c16_common_driver_init (running_machine *machine)
436static void c16_common_driver_init( running_machine *machine )
437437{
438438   UINT8 *rom;
439439
440   lowrom = 0;
441   highrom = 0;
442
440443   c16_select_roms (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), 0, 0);
441444   c16_switch_to_rom (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), 0, 0);
442445
r5842r5843
455458   memset(mess_ram + (0xfdc0 % mess_ram_size), 0xff, 0x40);
456459
457460   memset(mess_ram + (0xfd40 % mess_ram_size), 0xff, 0x20);
458   
461
459462   if (has_c1551)      /* C1551 */
460463      c1551_config(machine, "cpu_c1551");
461464
462465   if (has_vc1541)      /* VC1541 */
463      drive_config(machine, type_1541, 0, 0, "cpu_vc1540", 8);
466      cbm_drive_config(machine, type_1541, 0, 0, "cpu_vc1540", 8);
464467}
465468
466static void c16_driver_init(running_machine *machine)
469static void c16_driver_init( running_machine *machine )
467470{
471   int i;
472
468473   c16_common_driver_init(machine);
469   ted7360_init(machine, (read_cfg1(machine) & 0x10 ) == 0x00);      /* is it PAL? */
474
475   /* not sure this is the right place for this. ATM ted7360[] is shared by video and audio TED */
476   for(i = 0; i < 0x20; i++)
477      ted7360[i] = 0x00;
478   ted7360_rom = 1;   // FIX-ME: at start should be RAM or ROM?
479
480   ted7360_init(machine, (read_cfg1(machine) & 0x10) == 0x00);      /* is it PAL? */
470481   ted7360_set_dma(ted7360_dma_read, ted7360_dma_read_rom);
471482}
472483
473484
474485DRIVER_INIT( c16 )
475{
476   c16_driver_init(machine);
486{
487   has_c1551 = 0;
488   has_vc1541 = 0;
489   has_iec8 = 0;
490   has_iec9 = 0;
491   c16_driver_init(machine);
477492}
478493
479494DRIVER_INIT( c16c )
480{
495{
481496   has_c1551 = 1;
482   c16_driver_init(machine);
497   has_vc1541 = 0;
498   has_iec8 = 0;
499   has_iec9 = 0;
500   c16_driver_init(machine);
483501}
484502
485503DRIVER_INIT( c16v )
486{
504{
505   has_c1551 = 0;
487506   has_vc1541 = 1;
488   c16_driver_init(machine);
507   has_iec8 = 0;
508   has_iec9 = 0;
509   c16_driver_init(machine);
489510}
490511
491512
r5842r5843
493514{
494515   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
495516   const device_config *sid = devtag_get_device(space->machine, "sid");
496   
517
497518   c364_speech_init(machine);
498519
499520   if (read_cfg1(machine) & 0x80)  /* SID card present */
500521   {
501522      memory_install_read8_device_handler(space, sid, 0xfd40, 0xfd5f, 0, 0, sid6581_r);
502      memory_install_write8_device_handler(space, sid, 0xfd40, 0xfd5f, 0, 0, sid6581_w);
523      memory_install_write8_device_handler(space, sid, 0xfd40, 0xfd5f, 0, 0, sid6581_w);
503524      memory_install_read8_device_handler(space, sid, 0xfe80, 0xfe9f, 0, 0, sid6581_r);
504      memory_install_write8_device_handler(space, sid, 0xfe80, 0xfe9f, 0, 0, sid6581_w);
525      memory_install_write8_device_handler(space, sid, 0xfe80, 0xfe9f, 0, 0, sid6581_w);
505526   }
506527   else
507528   {
508529      memory_install_read8_handler(space, 0xfd40, 0xfd5f, 0, 0, SMH_NOP);
509      memory_install_write8_handler(space, 0xfd40, 0xfd5f, 0, 0, SMH_NOP);
530      memory_install_write8_handler(space, 0xfd40, 0xfd5f, 0, 0, SMH_NOP);
510531      memory_install_read8_handler(space, 0xfe80, 0xfe9f, 0, 0, SMH_NOP);
511      memory_install_write8_handler(space, 0xfe80, 0xfe9f, 0, 0, SMH_NOP);
532      memory_install_write8_handler(space, 0xfe80, 0xfe9f, 0, 0, SMH_NOP);
512533   }
513534
514535#if 0
515536   c16_switch_to_rom (0, 0);
516537   c16_select_roms (0, 0);
517538#endif
518   if ((read_cfg1(machine) & 0x0c ) == 0x00)      /* is it C16? */
539   if ((read_cfg1(machine) & 0x0c) == 0x00)      /* is it C16? */
519540   {
520      memory_set_bankptr (machine, 1, mess_ram + (0x4000 % mess_ram_size));
541      memory_set_bankptr(machine, 1, mess_ram + (0x4000 % mess_ram_size));
521542
522      memory_set_bankptr (machine, 5, mess_ram + (0x4000 % mess_ram_size));
523      memory_set_bankptr (machine, 6, mess_ram + (0x8000 % mess_ram_size));
524      memory_set_bankptr (machine, 7, mess_ram + (0xc000 % mess_ram_size));
543      memory_set_bankptr(machine, 5, mess_ram + (0x4000 % mess_ram_size));
544      memory_set_bankptr(machine, 6, mess_ram + (0x8000 % mess_ram_size));
545      memory_set_bankptr(machine, 7, mess_ram + (0xc000 % mess_ram_size));
525546
526547      memory_install_write8_handler(space, 0xff20, 0xff3d, 0, 0, SMH_BANK(10));
527548      memory_install_write8_handler(space, 0xff40, 0xffff, 0, 0, SMH_BANK(11));
528      memory_set_bankptr (machine, 10, mess_ram + (0xff20 % mess_ram_size));
529      memory_set_bankptr (machine, 11, mess_ram + (0xff40 % mess_ram_size));
549      memory_set_bankptr(machine, 10, mess_ram + (0xff20 % mess_ram_size));
550      memory_set_bankptr(machine, 11, mess_ram + (0xff40 % mess_ram_size));
530551
531552      ted7360_set_dma (ted7360_dma_read, ted7360_dma_read_rom);
532553   }
533554   else
534555   {
535556      memory_install_write8_handler(space, 0x4000, 0xfcff, 0, 0, SMH_BANK(10));
536      memory_set_bankptr (machine, 10, mess_ram + (0x4000 % mess_ram_size));
557      memory_set_bankptr(machine, 10, mess_ram + (0x4000 % mess_ram_size));
537558
538559      ted7360_set_dma (ted7360_dma_read, ted7360_dma_read_rom);
539560   }
r5842r5843
566587   }
567588   if (has_vc1541)      /* vc1541 */
568589   {
569      drive_reset();
590      cbm_drive_reset(machine);
570591   }
571592   else                        /* simulated drives */
572593   {
r5842r5843
589610
590611      /* Shift Lock is mapped on Left/Right Shift */
591612      if ((i == 1) && (input_port_read(device->machine, "SPECIAL") & 0x80))
592         value &= ~0x80;         
613         value &= ~0x80;
593614
594615      keyline[i] = value;
595616   }
596617
597   if (input_port_read(device->machine, "DSW0") & 0x80)
618   if (input_port_read(device->machine, "DSW0") & 0x80)
598619   {
599620      value = 0xff;
600621      if (input_port_read(device->machine, "JOY0") & 0x10)         /* Joypad1_Button */
r5842r5843
613634         keyline[8] = value;
614635   }
615636
616   if (input_port_read(device->machine, "DSW0") & 0x40)
637   if (input_port_read(device->machine, "DSW0") & 0x40)
617638   {
618639      value = 0xff;
619640      if (input_port_read(device->machine, "JOY1") & 0x10)         /* Joypad2_Button */
r5842r5843
625646         }
626647
627648      value &= ~(input_port_read(device->machine, "JOY1") & 0x0f);   /* Other Inputs Joypad2 */
628     
649
629650      if (input_port_read(device->machine, "SPECIAL") & 0x40)
630651         keyline[8] = value;
631652      else
r5842r5843
634655
635656   ted7360_frame_interrupt (device);
636657
637   set_led_status (1, input_port_read(device->machine, "SPECIAL") & 0x80 ? 1 : 0);      /* Shift Lock */
638   set_led_status (0, input_port_read(device->machine, "SPECIAL") & 0x40 ? 1 : 0);      /* Joystick Swap */
658   set_led_status(1, input_port_read(device->machine, "SPECIAL") & 0x80 ? 1 : 0);      /* Shift Lock */
659   set_led_status(0, input_port_read(device->machine, "SPECIAL") & 0x40 ? 1 : 0);      /* Joystick Swap */
639660}
640661
641662
642663/***********************************************
643664
644   C16 Cartridges
665    C16 Cartridges
645666
646667***********************************************/
647668
648static DEVICE_IMAGE_LOAD(c16_cart)
669static DEVICE_IMAGE_LOAD( c16_cart )
649670{
650671   UINT8 *mem = memory_region(image->machine, "maincpu");
651   int size = image_length (image), test;
672   int size = image_length(image), test;
652673   const char *filetype;
653674   int address = 0;
654675
655676    /* magic lowrom at offset 7: $43 $42 $4d */
656677   /* if at offset 6 stands 1 it will immediatly jumped to offset 0 (0x8000) */
657   static const unsigned char magic[] = {0x43, 0x42, 0x4d};
678   static const unsigned char magic[] = {0x43, 0x42, 0x4d};
658679   unsigned char buffer[sizeof (magic)];
659680
660   image_fseek (image, 7, SEEK_SET);
661   image_fread (image, buffer, sizeof (magic));
662   image_fseek (image, 0, SEEK_SET);
681   image_fseek(image, 7, SEEK_SET);
682   image_fread(image, buffer, sizeof (magic));
683   image_fseek(image, 0, SEEK_SET);
663684
664685   /* Check if our cart has the magic string, and set its loading address */
665   if (!memcmp (buffer, magic, sizeof (magic)))
686   if (!memcmp(buffer, magic, sizeof (magic)))
666687      address = 0x20000;
667   
688
668689   /* Give a loading address to non .bin / non .rom carts as well */
669690   filetype = image_filetype(image);
670691
671   /* We would support .hi and .lo files, but currently I'm not sure where to load them.
672      We simply load them at 0x20000 at this stage, even if it's probably wrong!
673      It could also well be that they both need to be loaded at the same time, but this
674      is now impossible since I reduced to 1 the number of cart slots.
675      More investigations are in order if any .hi, .lo dump would surface!             */
676   if (!mame_stricmp (filetype, "hi"))
692   /* We would support .hi and .lo files, but currently I'm not sure where to load them.
693       We simply load them at 0x20000 at this stage, even if it's probably wrong!
694       It could also well be that they both need to be loaded at the same time, but this
695       is now impossible since I reduced to 1 the number of cart slots.
696       More investigations are in order if any .hi, .lo dump would surface!              */
697   if (!mame_stricmp(filetype, "hi"))
677698      address = 0x20000;   /* FIX ME! */
678699
679   else if (!mame_stricmp (filetype, "lo"))
700   else if (!mame_stricmp(filetype, "lo"))
680701      address = 0x20000;   /* FIX ME! */
681702
682   /* As a last try, give a reasonable loading address also to .bin/.rom without the magic string */     
703   /* As a last try, give a reasonable loading address also to .bin/.rom without the magic string */
683704   else if (!address)
684705   {
685706      logerror("Cart %s does not contain the magic string: it may be loaded at the wrong memory address!\n", image_filename(image));
r5842r5843
689710   logerror("Loading cart %s at %.5x size:%.4x\n", image_filename(image), address, size);
690711
691712   /* Finally load the cart */
692   test = image_fread (image, mem + address, size);
713   test = image_fread(image, mem + address, size);
693714
694715   if (test != size)
695716      return INIT_FAIL;
r5842r5843
697718   return INIT_PASS;
698719}
699720
700MACHINE_DRIVER_START(c16_cartslot)
721MACHINE_DRIVER_START( c16_cartslot )
701722   MDRV_CARTSLOT_ADD("cart")
702723   MDRV_CARTSLOT_EXTENSION_LIST("bin,rom,hi,lo")
703724   MDRV_CARTSLOT_NOT_MANDATORY
src/mess/machine/cbmipt.c
r5842r5843
11/**********************************************************************************
22 *
3 *      machine/cbmipt.c
4 *
5 *            Input port macros shared by various CBM computers
3 *      machine/cbmipt.c
64 *
5 *              Input port macros shared by various CBM computers
76 *
8 *      TO DO:
97 *
10 *      - investigate C128 input problem with Left Shift / Shift Lock
11 *      - investigate superpet different reading of Caps Lock (check machine/pet.c)
12 *      - move here lightpen inputs from vc20.c, eventually
13 *      - clean up the "SPECIAL" and "CFG" input ports (e.g. there a quite a lot
14 *        of settings that are not checked anymore! we have either to implement
15 *        the features properly or, if they're hacks, to remove them)
8 *      TO DO:
169 *
10 *      - investigate C128 input problem with Left Shift / Shift Lock
11 *      - investigate superpet different reading of Caps Lock (check machine/pet.c)
12 *      - move here lightpen inputs from vc20.c, eventually
13 *      - clean up the "SPECIAL" and "CFG" input ports (e.g. there a quite a lot
14 *        of settings that are not checked anymore! we have either to implement
15 *        the features properly or, if they're hacks, to remove them)
16 *
1717 *********************************************************************************/
1818
1919#include "driver.h"
r5842r5843
2222
2323/***************************** Commodore 64 ****************************************
2424 *
25 *   - common_cbm_keyboard: C64 keyboard; used by C16, C65 and C128 as well
26 *   - c64_special: input port for the Restore key and the Shift Lock Switch
27 *   - c64_controls: joypads, paddles and lightpen; shared with C65, C128
28 *         and CBMB
25 *  - common_cbm_keyboard: C64 keyboard; used by C16, C65 and C128 as well
26 *  - c64_special: input port for the Restore key and the Shift Lock Switch
27 *  - c64_controls: joypads, paddles and lightpen; shared with C65, C128
28 *          and CBMB
2929 *
3030 **********************************************************************************/
3131
r5842r5843
3535-------------------
3636
3737                                                                           CLR    INST
38    <-   1!   2"   3#   4$   5%   6&   7'   8(   9)   0     +    -    £    HOME   DEL           f 1
38    <-   1!   2"   3#   4$   5%   6&   7'   8(   9)   0     +    -    ?    HOME   DEL           f 1
3939
40
40
4141    CTRL   Q    W    E    R    T     Y    U    I    O    P    @    *     UP    RESTORE          f 3
4242
4343RUN   SHIFT
r5842r5843
5050                                 SPACEBAR
5151
5252
53Notes: "C=" is a key with the Commodore logo, "UP" is an arrow pointing up, the "CRSR" keys at the
54bottom-right corner are used to move the cursor on screen (Up/Down and Left/Right resp.).
53Notes: "C=" is a key with the Commodore logo, "UP" is an arrow pointing up, the "CRSR" keys at the
54bottom-right corner are used to move the cursor on screen (Up/Down and Left/Right resp.).
5555*/
5656
5757
r5842r5843
6868
6969   PORT_START( "ROW1" )
7070   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Shift (Left)") PORT_CODE(KEYCODE_LSHIFT)      PORT_CHAR(UCHAR_SHIFT_1)
71   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_E)       PORT_CHAR('E')   
72   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_S)       PORT_CHAR('S')   
73   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Z)         PORT_CHAR('Z')   
71   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_E)       PORT_CHAR('E')
72   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_S)       PORT_CHAR('S')
73   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Z)         PORT_CHAR('Z')
7474   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_4)         PORT_CHAR('4') PORT_CHAR('$')
75   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_A)       PORT_CHAR('A')   
76   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_W)       PORT_CHAR('W')   
75   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_A)       PORT_CHAR('A')
76   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_W)       PORT_CHAR('W')
7777   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_3)         PORT_CHAR('3') PORT_CHAR('#')
7878
7979   PORT_START( "ROW2" )
80   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_X)       PORT_CHAR('X')   
81   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_T)       PORT_CHAR('T')   
82   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F)       PORT_CHAR('F')   
83   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_C)       PORT_CHAR('C')   
80   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_X)       PORT_CHAR('X')
81   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_T)       PORT_CHAR('T')
82   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F)       PORT_CHAR('F')
83   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_C)       PORT_CHAR('C')
8484   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_6)         PORT_CHAR('6') PORT_CHAR('&')
85   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_D)       PORT_CHAR('D')   
86   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_R)       PORT_CHAR('R')   
85   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_D)       PORT_CHAR('D')
86   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_R)       PORT_CHAR('R')
8787   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_5)         PORT_CHAR('5') PORT_CHAR('%')
8888
8989   PORT_START( "ROW3" )
90   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_V)       PORT_CHAR('V')   
91   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_U)       PORT_CHAR('U')   
92   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_H)       PORT_CHAR('H')   
93   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_B)       PORT_CHAR('B')   
90   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_V)       PORT_CHAR('V')
91   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_U)       PORT_CHAR('U')
92   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_H)       PORT_CHAR('H')
93   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_B)       PORT_CHAR('B')
9494   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_8)         PORT_CHAR('8') PORT_CHAR('(')
95   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_G)       PORT_CHAR('G')   
96   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Y)       PORT_CHAR('Y')   
95   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_G)       PORT_CHAR('G')
96   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Y)       PORT_CHAR('Y')
9797   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_7)         PORT_CHAR('7') PORT_CHAR('\'')
9898
9999   PORT_START( "ROW4" )
100   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_N)       PORT_CHAR('N')   
101   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_O)       PORT_CHAR('O')   
102   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_K)       PORT_CHAR('K')   
103   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_M)       PORT_CHAR('M')   
104   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_0)         PORT_CHAR('0')   
105   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_J)       PORT_CHAR('J')   
106   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_I)       PORT_CHAR('I')   
100   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_N)       PORT_CHAR('N')
101   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_O)       PORT_CHAR('O')
102   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_K)       PORT_CHAR('K')
103   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_M)       PORT_CHAR('M')
104   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_0)         PORT_CHAR('0')
105   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_J)       PORT_CHAR('J')
106   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_I)       PORT_CHAR('I')
107107   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_9)         PORT_CHAR('9') PORT_CHAR(')')
108108
109109   PORT_START( "ROW5" )
110110   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_COMMA)    PORT_CHAR(',') PORT_CHAR('<')
111   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_OPENBRACE) PORT_CHAR('@')   
111   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_OPENBRACE) PORT_CHAR('@')
112112   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_COLON)      PORT_CHAR(':') PORT_CHAR('[')
113113   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_STOP)       PORT_CHAR('.') PORT_CHAR('>')
114   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_EQUALS)   PORT_CHAR('-')   
115   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_L)       PORT_CHAR('L')   
116   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_P)       PORT_CHAR('P')   
117   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_MINUS)      PORT_CHAR('+')   
114   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_EQUALS)   PORT_CHAR('-')
115   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_L)       PORT_CHAR('L')
116   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_P)       PORT_CHAR('P')
117   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_MINUS)      PORT_CHAR('+')
118118
119119   PORT_START( "ROW6" )
120120   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SLASH)                        PORT_CHAR('/') PORT_CHAR('?')
r5842r5843
127127   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH2)                  PORT_CHAR('\xA3')
128128
129129   PORT_START( "ROW7" )
130   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Stop Run") PORT_CODE(KEYCODE_HOME)           
131   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Q)                           PORT_CHAR('Q')   
132   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("CBM") PORT_CODE(KEYCODE_LALT)           
133   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SPACE)                        PORT_CHAR(' ')   
130   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Stop Run") PORT_CODE(KEYCODE_HOME)
131   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Q)                           PORT_CHAR('Q')
132   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("CBM") PORT_CODE(KEYCODE_LALT)
133   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SPACE)                        PORT_CHAR(' ')
134134   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_2)                           PORT_CHAR('2') PORT_CHAR('"')
135135   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_TAB)                        PORT_CHAR(UCHAR_SHIFT_2)
136   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("\xE2\x86\x90") PORT_CODE(KEYCODE_TILDE)   PORT_CHAR(0x2190)   
136   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("\xE2\x86\x90") PORT_CODE(KEYCODE_TILDE)   PORT_CHAR(0x2190)
137137   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_1)                           PORT_CHAR('1') PORT_CHAR('!')
138138INPUT_PORTS_END
139139
140140
141141INPUT_PORTS_START( c64_special )
142   PORT_START( "SPECIAL" )  /* special keys */   
142   PORT_START( "SPECIAL" )  /* special keys */
143143   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Restore") PORT_CODE(KEYCODE_PRTSCR)
144144   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Shift Lock (switch)") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
145   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_UNUSED )                                       
146   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_UNUSED )   
145   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_UNUSED )
146   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_UNUSED )
147147INPUT_PORTS_END
148148
149149
r5842r5843
155155   PORT_CATEGORY_ITEM( 0x02, "Mouse 1351", 12 )
156156   PORT_CATEGORY_ITEM( 0x03, "Mouse (Non Proportional) 1350", 13 )
157157   PORT_CATEGORY_ITEM( 0x04, "Lightpen", 14 )
158//   PORT_CATEGORY_ITEM( 0x05, "Koala Pad", 15 )
158//  PORT_CATEGORY_ITEM( 0x05, "Koala Pad", 15 )
159159   PORT_CATEGORY_ITEM( 0x07, "No Device Connected", 17 )
160160   PORT_CATEGORY_CLASS( 0x70, 0x00, "Gameport B" )
161161   PORT_CATEGORY_ITEM( 0x00, DEF_STR( Joystick ), 20 )
162162   PORT_CATEGORY_ITEM( 0x10, "Paddles 3 & 4", 21 )
163//   PORT_CATEGORY_ITEM( 0x20, "Mouse 1351", 22 )
164//   PORT_CATEGORY_ITEM( 0x30, "Mouse (Non Proportional) 1350", 23 )
163//  PORT_CATEGORY_ITEM( 0x20, "Mouse 1351", 22 )
164//  PORT_CATEGORY_ITEM( 0x30, "Mouse (Non Proportional) 1350", 23 )
165165   PORT_CATEGORY_ITEM( 0x70, "No Device Connected", 27 )
166166   PORT_CONFNAME( 0x08, 0x00, "Workaround for RDY")
167   PORT_CONFSETTING(   0x00, DEF_STR( No ) )     
167   PORT_CONFSETTING(   0x00, DEF_STR( No ) )
168168   PORT_CONFSETTING(   0x08, DEF_STR( Yes ) )
169169   PORT_CONFNAME( 0x80, 0x00, "Swap Gameport A and B") PORT_CODE(KEYCODE_F1) PORT_TOGGLE
170   PORT_CONFSETTING(   0x00, DEF_STR( No ) )     
170   PORT_CONFSETTING(   0x00, DEF_STR( No ) )
171171   PORT_CONFSETTING(   0x80, DEF_STR( Yes ) )
172172
173173   PORT_START("JOY1_1B")
r5842r5843
176176   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(1) PORT_CATEGORY(10)
177177   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1) PORT_CATEGORY(10)
178178   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_CATEGORY(10)
179   PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_UNUSED )
179   PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_UNUSED )
180180
181   PORT_START("JOY2_1B")
181   PORT_START("JOY2_1B")
182182   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(20) PORT_CODE(KEYCODE_HOME) PORT_CODE(JOYCODE_Y_UP_SWITCH)
183183   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(20) PORT_CODE(KEYCODE_END) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)
184184   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(20) PORT_CODE(KEYCODE_DEL) PORT_CODE(JOYCODE_X_LEFT_SWITCH)
185185   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(20) PORT_CODE(KEYCODE_PGDN) PORT_CODE(JOYCODE_X_RIGHT_SWITCH)
186186   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_CATEGORY(20) PORT_CODE(KEYCODE_INSERT) PORT_CODE(JOYCODE_BUTTON1)
187   PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_UNUSED )
187   PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_UNUSED )
188188
189189   /* Mouse Commodore 1350 was basically working as a Joystick */
190190   PORT_START("JOY1_2B")
r5842r5843
194194   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1) PORT_NAME("Mouse 1350 Right") PORT_CATEGORY(13)
195195   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("Mouse 1350 Button 1") PORT_CATEGORY(13)
196196   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("Mouse 1350 Button 2") PORT_CATEGORY(13)
197   PORT_BIT( 0xc0, IP_ACTIVE_HIGH, IPT_UNUSED )
197   PORT_BIT( 0xc0, IP_ACTIVE_HIGH, IPT_UNUSED )
198198
199199   /* Still to verify how many mices you were able to plug into a c64 */
200200   /* Only one, for now */
201   PORT_START("JOY2_2B")
202   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED )
203/*   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(23) PORT_CODE(KEYCODE_HOME) PORT_CODE(JOYCODE_Y_UP_SWITCH)
204   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(23) PORT_CODE(KEYCODE_END) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)
205   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(23) PORT_CODE(KEYCODE_DEL) PORT_CODE(JOYCODE_X_LEFT_SWITCH)
206   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(23) PORT_CODE(KEYCODE_PGDN) PORT_CODE(JOYCODE_X_RIGHT_SWITCH)
207   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_CATEGORY(23) PORT_CODE(KEYCODE_INSERT) PORT_CODE(JOYCODE_BUTTON1)
208   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_CATEGORY(23) PORT_CODE(KEYCODE_PGUP) PORT_CODE(JOYCODE_BUTTON2)
209   PORT_BIT( 0xc0, IP_ACTIVE_HIGH, IPT_UNUSED )
201   PORT_START("JOY2_2B")
202   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED )
203/*  PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(23) PORT_CODE(KEYCODE_HOME) PORT_CODE(JOYCODE_Y_UP_SWITCH)
204    PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(23) PORT_CODE(KEYCODE_END) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)
205    PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(23) PORT_CODE(KEYCODE_DEL) PORT_CODE(JOYCODE_X_LEFT_SWITCH)
206    PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(23) PORT_CODE(KEYCODE_PGDN) PORT_CODE(JOYCODE_X_RIGHT_SWITCH)
207    PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_CATEGORY(23) PORT_CODE(KEYCODE_INSERT) PORT_CODE(JOYCODE_BUTTON1)
208    PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_CATEGORY(23) PORT_CODE(KEYCODE_PGUP) PORT_CODE(JOYCODE_BUTTON2)
209    PORT_BIT( 0xc0, IP_ACTIVE_HIGH, IPT_UNUSED )
210210*/
211211   PORT_START("PADDLE1")
212212   PORT_BIT( 0xff, 128, IPT_PADDLE) PORT_SENSITIVITY(30) PORT_KEYDELTA(20) PORT_MINMAX(0,255) PORT_CENTERDELTA(0) PORT_CODE_DEC(KEYCODE_LEFT) PORT_CODE_INC(KEYCODE_RIGHT) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_CATEGORY(11) PORT_PLAYER(1) PORT_REVERSE
213213
214   PORT_START("PADDLE2")
214   PORT_START("PADDLE2")
215215   PORT_BIT( 0xff, 128, IPT_PADDLE) PORT_SENSITIVITY(30) PORT_KEYDELTA(20) PORT_MINMAX(0,255) PORT_CENTERDELTA(0) PORT_CODE_DEC(KEYCODE_DOWN) PORT_CODE_INC(KEYCODE_UP) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH) PORT_CATEGORY(11) PORT_PLAYER(2) PORT_REVERSE
216216
217   PORT_START("PADDLE3")
217   PORT_START("PADDLE3")
218218   PORT_BIT( 0xff, 128, IPT_PADDLE) PORT_SENSITIVITY(30) PORT_KEYDELTA(20) PORT_MINMAX(0,255) PORT_CENTERDELTA(0) PORT_CODE_DEC(KEYCODE_HOME) PORT_CODE_INC(KEYCODE_PGUP) PORT_CATEGORY(21) PORT_PLAYER(3) PORT_REVERSE
219219
220   PORT_START("PADDLE4")
220   PORT_START("PADDLE4")
221221   PORT_BIT( 0xff, 128, IPT_PADDLE) PORT_SENSITIVITY(30) PORT_KEYDELTA(20) PORT_MINMAX(0,255) PORT_CENTERDELTA(0) PORT_CODE_DEC(KEYCODE_END) PORT_CODE_INC(KEYCODE_PGDN) PORT_CATEGORY(21) PORT_PLAYER(4) PORT_REVERSE
222222
223   PORT_START("TRACKX")
223   PORT_START("TRACKX")
224224   PORT_BIT( 0x7e, 0x00, IPT_TRACKBALL_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_CATEGORY(12)
225225
226   PORT_START("TRACKY")
226   PORT_START("TRACKY")
227227   PORT_BIT( 0x7e, 0x00, IPT_TRACKBALL_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_CATEGORY(12) PORT_REVERSE
228228
229   PORT_START("LIGHTX")
229   PORT_START("LIGHTX")
230230   PORT_BIT( 0x7e, 0x00, IPT_TRACKBALL_X) PORT_NAME("Lightpen X Axis") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(30) PORT_KEYDELTA(2) PORT_PLAYER(1) PORT_CATEGORY(14)
231   /* PORT_BIT( 0x1ff,0,IPT_PADDLE) PORT_SENSITIVITY(30) PORT_KEYDELTA(2) PORT_MINMAX(0,320-1) PORT_CODE_DEC(KEYCODE_LEFT) PORT_CODE_INC(KEYCODE_RIGHT) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(1) */
231   /* PORT_BIT( 0x1ff,0,IPT_PADDLE) PORT_SENSITIVITY(30) PORT_KEYDELTA(2) PORT_MINMAX(0,320-1) PORT_CODE_DEC(KEYCODE_LEFT) PORT_CODE_INC(KEYCODE_RIGHT) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(1) */
232232
233   PORT_START("LIGHTY")
233   PORT_START("LIGHTY")
234234   PORT_BIT( 0x7e, 0x00, IPT_TRACKBALL_Y) PORT_NAME("Lightpen Y Axis") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(30) PORT_KEYDELTA(2) PORT_PLAYER(1) PORT_CATEGORY(14)
235   /* PORT_BIT( 0xff,0,IPT_PADDLE) PORT_SENSITIVITY(30) PORT_KEYDELTA(2) PORT_MINMAX(0,200-1) PORT_CODE_DEC(KEYCODE_UP) PORT_CODE_INC(KEYCODE_DOWN) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH) PORT_PLAYER(2) */
235   /* PORT_BIT( 0xff,0,IPT_PADDLE) PORT_SENSITIVITY(30) PORT_KEYDELTA(2) PORT_MINMAX(0,200-1) PORT_CODE_DEC(KEYCODE_UP) PORT_CODE_INC(KEYCODE_DOWN) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH) PORT_PLAYER(2) */
236236
237237   PORT_START("OTHER")
238238   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Paddle 1 Button") PORT_CATEGORY(11) PORT_CODE(KEYCODE_LCONTROL) PORT_CODE(JOYCODE_BUTTON1)
r5842r5843
247247
248248/***************************** Commodore 16 ****************************************
249249 *
250 *   - C16 shares Keyboard with C64 (only few changes, see c16.c)
251 *   - c16_special: input port for the Shift Lock Switch
252 *   - c16_controls: control inputs
253 *   - c16_config: control and devices configurations
250 *  - C16 shares Keyboard with C64 (only few changes, see c16.c)
251 *  - c16_special: input port for the Shift Lock Switch
252 *  - c16_controls: control inputs
253 *  - c16_config: control and devices configurations
254254 *
255255 **********************************************************************************/
256256
r5842r5843
261261
262262                                                                                   INST
263263     ESC   1!   2"   3#   4$   5%   6&   7'   8(   9)   0^  LEFT RIGHT  UP  DOWN    DEL           f 1
264 
264
265265                                                                                  CLEAR
266266      CTRL   Q    W    E    R    T     Y    U    I    O    P    @    +     -      HOME            f 3
267 
267
268268  RUN   SHIFT
269269  STOP  LOCK   A    S    D    F     G     H    J    K    L   :[   ;]    *      RETURN             f 5
270 
271 
272  C=    SHIFT     Z    X    C    V    B     N    M    ,<   .>   /?   SHIFT     £     =            HELP
273 
274 
270
271
272  C=    SHIFT     Z    X    C    V    B     N    M    ,<   .>   /?   SHIFT     ?     =            HELP
273
274
275275                                 SPACEBAR
276276
277277
278Notes: "C=" is a key with the Commodore logo, Shift+0 produces an arrow pointing up (''^'' above).
278Notes: "C=" is a key with the Commodore logo, Shift+0 produces an arrow pointing up (''^'' above).
279279
280280C116 Keyboard Layout
281281--------------------
282282
283283           F1/F4      F2/F5     F3/F6    HELP/F7     HOME/CLEAR   DEL/INST
284 
285 
286     ESC   1!   2"   3#   4$   5%   6&   7'   8(   9)   0^   +    -     *
287 
288                                                                                 
284
285
286     ESC   1!   2"   3#   4$   5%   6&   7'   8(   9)   0^   +    -     *
287
288
289289   CONTROL   Q    W    E    R    T     Y    U    I    O    P    @   RETURN
290 
291  RUN   
292  STOP    £    A    S    D    F     G     H    J    K    L   :[   ;]    =
293 
294 
290
291  RUN
292  STOP    ??    A    S    D    F     G     H    J    K    L   :[   ;]    =
293
294
295295  C=    SHIFT     Z    X    C    V    B     N    M    ,<   .>   /?   SHIFT
296                                                                                    UP 
297                                                           LEFT       RIGHT
296                                                                                    UP
297                                                                             LEFT       RIGHT
298298                                 SPACEBAR                                          DOWN
299299
300300
r5842r5843
302302-----------------------------------
303303
304304           F1/F4      F2/F5     F3/F6    HELP/F7
305 
305
306306                                                                            CLEAR   INST
307307     ESC   1!   2"   3#   4$   5%   6&   7'   8(   9)   0^   +    -     =    HOME    DEL        ||      @  +  -  =
308308                                                                                                ||
309309                                                                                                ||
310   CONTROL   Q    W    E    R    T     Y    U    I    O    P    @    £     *    CONTROL         ||      7  8  9  *
310   CONTROL   Q    W    E    R    T     Y    U    I    O    P    @    ?     *    CONTROL         ||      7  8  9  *
311311                                                                                                ||
312312  RUN   SHIFT                                                                                   ||
313313  STOP  LOCK   A    S    D    F     G     H    J    K    L   :[   ;]    RETURN                  ||      4  5  6  /
r5842r5843
318318                                                                          LEFT       RIGHT      ||               e
319319                                 SPACEBAR                                      DOWN             ||      0  .  :  r
320320
321The 19-keys keypad on the left was present only in the 364 prototype (but probably those
321The 19-keys keypad on the left was present only in the 364 prototype (but probably those
322322keys were simply wired to the lines of regular number keys of the keyboard).
323323
324324*/
325325
326326INPUT_PORTS_START( c16_special )
327   PORT_START("SPECIAL")                                               
327   PORT_START("SPECIAL")
328328   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Shift Lock (switch)") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE
329329   PORT_CONFNAME( 0x40, 0x00, "Swap Gameport 1 and 2") PORT_CODE(KEYCODE_F1) PORT_TOGGLE
330   PORT_CONFSETTING(   0x00, DEF_STR( No ) )                                   
330   PORT_CONFSETTING(   0x00, DEF_STR( No ) )
331331   PORT_CONFSETTING(   0x40, DEF_STR( Yes ) )
332332INPUT_PORTS_END
333333
334334
335335INPUT_PORTS_START( c16_controls )
336   PORT_START("JOY0")
337   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP)   PORT_8WAY
338   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN)   PORT_8WAY
339   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT)   PORT_8WAY
340   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT) PORT_8WAY
341   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1)
336   PORT_START("JOY0")
337   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP)   PORT_8WAY
338   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN)   PORT_8WAY
339   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT)   PORT_8WAY
340   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT) PORT_8WAY
341   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1)
342342
343   PORT_START("JOY1")
344   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP)   PORT_NAME("P2 Up") PORT_CODE(KEYCODE_HOME) PORT_CODE(JOYCODE_Y_UP_SWITCH) PORT_8WAY PORT_PLAYER(2)
345   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN)   PORT_NAME("P2 Down") PORT_CODE(KEYCODE_END) PORT_CODE(JOYCODE_Y_DOWN_SWITCH) PORT_8WAY PORT_PLAYER(2)
346   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT)   PORT_NAME("P2 Left") PORT_CODE(KEYCODE_DEL) PORT_CODE(JOYCODE_X_LEFT_SWITCH ) PORT_8WAY PORT_PLAYER(2)
347   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT)   PORT_NAME("P2 Right") PORT_CODE(KEYCODE_PGDN) PORT_CODE(JOYCODE_X_RIGHT_SWITCH ) PORT_8WAY PORT_PLAYER(2)
348   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1)      PORT_NAME("P2 Button") PORT_CODE(KEYCODE_LALT) PORT_CODE(JOYCODE_BUTTON1 ) PORT_PLAYER(2)
343   PORT_START("JOY1")
344   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP)   PORT_NAME("P2 Up") PORT_CODE(KEYCODE_HOME) PORT_CODE(JOYCODE_Y_UP_SWITCH) PORT_8WAY PORT_PLAYER(2)
345   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN)   PORT_NAME("P2 Down") PORT_CODE(KEYCODE_END) PORT_CODE(JOYCODE_Y_DOWN_SWITCH) PORT_8WAY PORT_PLAYER(2)
346   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT)   PORT_NAME("P2 Left") PORT_CODE(KEYCODE_DEL) PORT_CODE(JOYCODE_X_LEFT_SWITCH ) PORT_8WAY PORT_PLAYER(2)
347   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT)   PORT_NAME("P2 Right") PORT_CODE(KEYCODE_PGDN) PORT_CODE(JOYCODE_X_RIGHT_SWITCH ) PORT_8WAY PORT_PLAYER(2)
348   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1)      PORT_NAME("P2 Button") PORT_CODE(KEYCODE_LALT) PORT_CODE(JOYCODE_BUTTON1 ) PORT_PLAYER(2)
349349INPUT_PORTS_END
350350
351351
352352INPUT_PORTS_START( c16_config )
353353   PORT_START("DSW0")
354   PORT_DIPNAME( 0x80, 0x80, "Joystick 1")         
355   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )     
356   PORT_DIPSETTING(   0x80, DEF_STR( On ) )     
357   PORT_DIPNAME( 0x40, 0x40, "Joystick 2")         
358   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )     
359   PORT_DIPSETTING(   0x40, DEF_STR( On ) )     
354   PORT_DIPNAME( 0x80, 0x80, "Joystick 1")
355   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
356   PORT_DIPSETTING(   0x80, DEF_STR( On ) )
357   PORT_DIPNAME( 0x40, 0x40, "Joystick 2")
358   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
359   PORT_DIPSETTING(   0x40, DEF_STR( On ) )
360360   PORT_DIPNAME( 0x20, 0x20, "Tape Drive / Device 1")
361   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )     
362   PORT_DIPSETTING(   0x20, DEF_STR( On ) )     
363   PORT_DIPNAME( 0x10, 0x00, "Tape Sound")         
364   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )     
365   PORT_DIPSETTING(   0x10, DEF_STR( On ) )     
361   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
362   PORT_DIPSETTING(   0x20, DEF_STR( On ) )
363   PORT_DIPNAME( 0x10, 0x00, "Tape Sound")
364   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
365   PORT_DIPSETTING(   0x10, DEF_STR( On ) )
366366
367367   PORT_START("CFG1")
368   PORT_DIPNAME( 0x80, 0x80, "Sidcard")               
369   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )           
370   PORT_DIPSETTING(   0x80, DEF_STR( On ) )           
368   PORT_DIPNAME( 0x80, 0x80, "Sidcard")
369   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
370   PORT_DIPSETTING(   0x80, DEF_STR( On ) )
371371   PORT_BIT( 0x40, 0x00, IPT_UNUSED )         /* 2008-05 FP: removed the SID card hack cfg */
372   PORT_BIT( 0x10, 0x00, IPT_UNUSED )         /* pal */   
372   PORT_BIT( 0x10, 0x00, IPT_UNUSED )         /* pal */
373373   PORT_BIT( 0x0c, 0x00, IPT_UNUSED )         /* c16 */
374374INPUT_PORTS_END
375375
376376
377377/***************************** Commodore 128 ***************************************
378378 *
379 *   - C128 shares Controls and Keyboard with C64 (+ a keypad, see c128.c)
380 *   - c128_special: input port for the Restore key and the Shift Lock,
381 *         TV/RGBI and 40/80 columns switches
379 *  - C128 shares Controls and Keyboard with C64 (+ a keypad, see c128.c)
380 *  - c128_special: input port for the Restore key and the Shift Lock,
381 *          TV/RGBI and 40/80 columns switches
382382 *
383383 **********************************************************************************/
384384
r5842r5843
390390
391391                    CAPS                 LINE   40/80    NO
392392     ESC  TAB  ALT  LOCK           HELP  FEED  DISPLAY SCROLL      UP  DOWN  LEFT  RIGHT          F1  F3  F5  F7
393 
393
394394                                                                             CLR    INST
395      <-   1!   2"   3#   4$   5%   6&   7'   8(   9)   0     +    -    £    HOME   DEL           7   8   9   +
396 
397   
395      <-   1!   2"   3#   4$   5%   6&   7'   8(   9)   0     +    -    ?    HOME   DEL           7   8   9   +
396
397
398398   CONTROL   Q    W    E    R    T     Y    U    I    O    P    @    *     UP    RESTORE          4   5   6   -
399 
399
400400  RUN   SHIFT                                                                                                 E
401401  STOP  LOCK   A    S    D    F     G     H    J    K    L   :[   ;]    =      RETURN             1   2   3   n
402402                                                                                                              t
403403                                                                             CRSR  CRSR                       e
404404  C=    SHIFT     Z    X    C    V    B     N    M    ,<   .>   /?   SHIFT   U/D    L/R             0     .   r
405 
406 
405
406
407407                                   SPACEBAR
408408
409Notes: "C=" is a key with the Commodore logo, "UP" is an arrow pointing up, the "CRSR" keys at the bottom-right
410corner are used to move the cursor on screen (Up/Down and Left/Right resp.). 
409Notes: "C=" is a key with the Commodore logo, "UP" is an arrow pointing up, the "CRSR" keys at the bottom-right
410corner are used to move the cursor on screen (Up/Down and Left/Right resp.).
411411
412412*/
413413
414414INPUT_PORTS_START( c128_special )
415   PORT_START( "SPECIAL" )  /* special keys */   
416   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Restore") PORT_CODE(KEYCODE_PRTSCR)   
415   PORT_START( "SPECIAL" )  /* special keys */
416   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Restore") PORT_CODE(KEYCODE_PRTSCR)
417417   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Shift Lock (switch)") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
418   PORT_DIPNAME( 0x20, 0x00, "Caps Lock (switch)")                                       
419   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )                                         
420   PORT_DIPSETTING(   0x20, DEF_STR( On ) )                                         
421   PORT_DIPNAME( 0x10, 0x10, "40 80 Display (switch) (active after a rebooting)")               
422   PORT_DIPSETTING(   0x00, "40 Columns (DIN/TV)")                                   
418   PORT_DIPNAME( 0x20, 0x00, "Caps Lock (switch)")
419   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
420   PORT_DIPSETTING(   0x20, DEF_STR( On ) )
421   PORT_DIPNAME( 0x10, 0x10, "40 80 Display (switch) (active after a rebooting)")
422   PORT_DIPSETTING(   0x00, "40 Columns (DIN/TV)")
423423   PORT_DIPSETTING(   0x10, "80 Columns (RGBI)")
424424   PORT_DIPNAME( 0x08, 0x08, "DIN,TV / RGBI Monitor (switch)") PORT_CODE(KEYCODE_ENTER_PAD)
425   PORT_DIPSETTING(   0x00, "DIN,TV" )                                       
426   PORT_DIPSETTING(   0x08, "RGBI" )                                         
425   PORT_DIPSETTING(   0x00, "DIN,TV" )
426   PORT_DIPSETTING(   0x08, "RGBI" )
427427   PORT_DIPNAME( 0x06, 0x00, "Main Memory / MMU Version")
428428   PORT_DIPSETTING(   0x00, "128 KByte" )
429429   PORT_DIPSETTING(   0x02, "256 KByte" )
r5842r5843
433433
434434/***************************** Commodore 65 ****************************************
435435 *
436 *   - C65 shares Keyboard and Inputs with C64 (+ some function keys, see c65.c)
437 *   - c65_special: input port for the Restore key and the Shift Lock and DIN
438 *         switches
436 *  - C65 shares Keyboard and Inputs with C64 (+ some function keys, see c65.c)
437 *  - c65_special: input port for the Restore key and the Shift Lock and DIN
438 *          switches
439439 *
440440 **********************************************************************************/
441441
r5842r5843
446446
447447    RUN                  CAPS    NO
448448    STOP       ESC  ALT  LOCK  SCROLL    F1   F3   F5   F7        F9    F11   F13   HELP
449 
449
450450                                                                             CLR    INST
451      <-   1!   2"   3#   4$   5%   6&   7'   8(   9)   0     +    -    £    HOME   DEL
452 
453   
451      <-   1!   2"   3#   4$   5%   6&   7'   8(   9)   0     +    -    ??    HOME   DEL
452
453
454454   TAB       Q    W    E    R    T     Y    U    I    O    P    @    *     UP    RESTORE
455 
455
456456        SHIFT
457457  CTRL  LOCK   A    S    D    F     G     H    J    K    L   :[   ;]    =      RETURN
458458
459459
460460  C=    SHIFT     Z    X    C    V    B     N    M    ,<   .>   /?   SHIFT   UP
461 
462 
461
462
463463                                   SPACEBAR                           LEFT  DOWN  RIGHT
464464
465465Notes: "C=" is a key with the Commodore logo, "UP" is an arrow pointing up.
466466
467467*/
468468INPUT_PORTS_START( c65_special )
469   PORT_START( "SPECIAL" )  /* special keys */   
470   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Restore") PORT_CODE(KEYCODE_PRTSCR)   
469   PORT_START( "SPECIAL" )  /* special keys */
470   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Restore") PORT_CODE(KEYCODE_PRTSCR)
471471   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Shift Lock (switch)") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
472   PORT_DIPNAME( 0x20, 0x00, "(C65) Caps Lock (switch)") PORT_CODE(KEYCODE_F3)                 
473   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )                                         
474   PORT_DIPSETTING(   0x20, DEF_STR( On ) )                                         
475   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_UNUSED )   
472   PORT_DIPNAME( 0x20, 0x00, "(C65) Caps Lock (switch)") PORT_CODE(KEYCODE_F3)
473   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
474   PORT_DIPSETTING(   0x20, DEF_STR( On ) )
475   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_UNUSED )
476476INPUT_PORTS_END
477477
478478
479479/***************************** Commodore Pet ***************************************
480480 *
481 *   - pet_keyboard: original keyboard used by PET2001
482 *   - pet_business_keyboard: business keyboard is used by the other computers
483 *         in pet.c
484 *   - pet_special: input port for the Shift Lock Switch
485 *   - pet_config: memory and serial port configurations
481 *  - pet_keyboard: original keyboard used by PET2001
482 *  - pet_business_keyboard: business keyboard is used by the other computers
483 *          in pet.c
484 *  - pet_special: input port for the Shift Lock Switch
485 *  - pet_config: memory and serial port configurations
486486 *
487487 **********************************************************************************/
488488
r5842r5843
493493
494494                                                                                CLR CRSR CRSR INST
495495  @    !    "    #    $    %    '    &    \    (    )    <-    [    ]          HOME  U/D  L/R  DEL
496 
496
497497 RVS
498498 OFF     Q    W    E    R    T     Y    U    I    O    P    UP   <    >          7    8    9    /
499499
500500  SHIFT                                                      STOP
501501  LOCK     A    S    D    F     G     H    J    K    L   :   RUN  RETURN         4    5    6    *
502 
503                                                             
502
503
504504   SHIFT     Z    X    C    V    B     N    M     ,    ;   ?    SHIFT            1    2    3    +
505 
506 
505
506
507507                                 SPACEBAR                                        0    .    -    =
508508
509509
510The PET Keypad has 16 keys, making impossible to map it in a satisfactory way to a PC keypad.
511Therefore, default settings for these keys in Full Emulation are currently based on the effect
510The PET Keypad has 16 keys, making impossible to map it in a satisfactory way to a PC keypad.
511Therefore, default settings for these keys in Full Emulation are currently based on the effect
512512of the key and not on their real position
513513
514514
r5842r5843
521521                                                                        CRSR    DEL
522522    TAB    Q    W    E    R    T     Y    U    I    O    P    [    \    U/D    INST             4   5   6
523523
524    SHIFT
524    SHIFT
525525ESC   LOCK   A    S    D    F     G     H    J    K    L   ;+    @     ]      RETURN            1   2   3
526526
527527RVS                                                                                HOME
r5842r5843
535535INPUT_PORTS_START( pet_keyboard )
536536   PORT_START( "ROW0" )
537537   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Crsr Right Left") PORT_CODE(KEYCODE_PGDN) PORT_CHAR(UCHAR_MAMEKEY(RIGHT)) PORT_CHAR(UCHAR_MAMEKEY(LEFT))
538   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Home  Clr Screen") PORT_CODE(KEYCODE_HOME) PORT_CHAR(UCHAR_MAMEKEY(HOME))
538   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Home  Clr Screen") PORT_CODE(KEYCODE_HOME) PORT_CHAR(UCHAR_MAMEKEY(HOME))
539539   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("\xE2\x86\x90") PORT_CODE(KEYCODE_MINUS) PORT_CHAR(0x2190)
540540   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_9)         PORT_CHAR('(')
541541   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_7)         PORT_CHAR('&')
r5842r5843
545545
546546   PORT_START( "ROW1" )
547547   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Del  Inst") PORT_CODE(KEYCODE_DEL) PORT_CHAR(8) PORT_CHAR(UCHAR_MAMEKEY(INSERT))
548   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Crsr Down Up") PORT_CODE(KEYCODE_PGUP) PORT_CHAR(UCHAR_MAMEKEY(DOWN)) PORT_CHAR(UCHAR_MAMEKEY(UP))   
548   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Crsr Down Up") PORT_CODE(KEYCODE_PGUP) PORT_CHAR(UCHAR_MAMEKEY(DOWN)) PORT_CHAR(UCHAR_MAMEKEY(UP))
549549   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
550550   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_0)         PORT_CHAR(')')
551551   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_8)         PORT_CHAR('\\')
r5842r5843
557557   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_9_PAD)      PORT_CHAR('9')
558558   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_7_PAD)      PORT_CHAR('7')
559559   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("\xE2\x86\x91 Pi") PORT_CODE(KEYCODE_OPENBRACE) PORT_CHAR(0x2191) PORT_CHAR(0x03C0)
560   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_O)         PORT_CHAR('O')   
561   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_U)         PORT_CHAR('U')   
562   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_T)         PORT_CHAR('T')   
563   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_E)         PORT_CHAR('E')   
564   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Q)         PORT_CHAR('Q')   
560   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_O)         PORT_CHAR('O')
561   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_U)         PORT_CHAR('U')
562   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_T)         PORT_CHAR('T')
563   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_E)         PORT_CHAR('E')
564   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Q)         PORT_CHAR('Q')
565565
566566   PORT_START( "ROW3" )
567   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SLASH_PAD)   PORT_CHAR('/')
567   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SLASH_PAD)   PORT_CHAR('/')
568568   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_8_PAD)      PORT_CHAR('8')
569569   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
570   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_P)         PORT_CHAR('P')   
571   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_I)         PORT_CHAR('I')   
572   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Y)         PORT_CHAR('Y')   
573   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_R)         PORT_CHAR('R')   
574   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_W)         PORT_CHAR('W')   
570   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_P)         PORT_CHAR('P')
571   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_I)         PORT_CHAR('I')
572   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Y)         PORT_CHAR('Y')
573   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_R)         PORT_CHAR('R')
574   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_W)         PORT_CHAR('W')
575575
576576   PORT_START( "ROW4" )
577577   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_6_PAD)      PORT_CHAR('6')
578578   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_4_PAD)      PORT_CHAR('4')
579579   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
580   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_L)         PORT_CHAR('L')   
581   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_J)         PORT_CHAR('J')   
582   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_G)         PORT_CHAR('G')   
583   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_D)         PORT_CHAR('D')   
584   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_A)         PORT_CHAR('A')   
580   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_L)         PORT_CHAR('L')
581   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_J)         PORT_CHAR('J')
582   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_G)         PORT_CHAR('G')
583   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_D)         PORT_CHAR('D')
584   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_A)         PORT_CHAR('A')
585585
586586   PORT_START( "ROW5" )
587   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_ASTERISK)   PORT_CHAR('*')
587   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_ASTERISK)   PORT_CHAR('*')
588588   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_5_PAD)      PORT_CHAR('5')
589589   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
590   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_COLON)      PORT_CHAR(':')   
591   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_K)         PORT_CHAR('K')   
592   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_H)         PORT_CHAR('H')   
593   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F)         PORT_CHAR('F')   
594   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_S)         PORT_CHAR('S')   
590   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_COLON)      PORT_CHAR(':')
591   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_K)         PORT_CHAR('K')
592   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_H)         PORT_CHAR('H')
593   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F)         PORT_CHAR('F')
594   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_S)         PORT_CHAR('S')
595595
596596   PORT_START( "ROW6" )
597597   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_3_PAD)      PORT_CHAR('3')
598598   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_1_PAD)      PORT_CHAR('1')
599599   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Return") PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
600   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_STOP)      PORT_CHAR(';')   
601   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_M)         PORT_CHAR('M')   
602   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_B)         PORT_CHAR('B')   
603   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_C)         PORT_CHAR('C')   
604   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Z)         PORT_CHAR('Z')   
600   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_STOP)      PORT_CHAR(';')
601   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_M)         PORT_CHAR('M')
602   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_B)         PORT_CHAR('B')
603   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_C)         PORT_CHAR('C')
604   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Z)         PORT_CHAR('Z')
605605
606606   PORT_START( "ROW7" )
607   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_PLUS_PAD)   PORT_CHAR('+')
607   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_PLUS_PAD)   PORT_CHAR('+')
608608   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_2_PAD)      PORT_CHAR('2')
609609   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
610   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SLASH)      PORT_CHAR('?')   
611   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_COMMA)      PORT_CHAR(',')   
612   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_N)         PORT_CHAR('N')   
613   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_V)         PORT_CHAR('V')   
614   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_X)         PORT_CHAR('X')   
610   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SLASH)      PORT_CHAR('?')
611   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_COMMA)      PORT_CHAR(',')
612   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_N)         PORT_CHAR('N')
613   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_V)         PORT_CHAR('V')
614   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_X)         PORT_CHAR('X')
615615
616616   PORT_START( "ROW8" )
617617   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_MINUS_PAD)   PORT_CHAR('-')
618618   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_0_PAD)      PORT_CHAR('0')
619   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Shift (Right)") PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
620   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR('>')   
619   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Shift (Right)") PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
620   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR('>')
621621   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
622   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSPACE)   PORT_CHAR(']')   
623   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_TILDE)      PORT_CHAR('@')   
622   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSPACE)   PORT_CHAR(']')
623   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_TILDE)      PORT_CHAR('@')
624624   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Shift (Left)") PORT_CODE(KEYCODE_LSHIFT)
625625
626626   PORT_START( "ROW9" )
627   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Keypad =") PORT_CODE(KEYCODE_ENTER_PAD) PORT_CHAR('=')
627   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Keypad =") PORT_CODE(KEYCODE_ENTER_PAD) PORT_CHAR('=')
628628   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_DEL_PAD)   PORT_CHAR('.')
629629   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
630630   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Stop Run") PORT_CODE(KEYCODE_QUOTE)
631   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR('<')   
632   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SPACE)      PORT_CHAR(' ')   
633   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_EQUALS)      PORT_CHAR('[')   
631   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR('<')
632   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SPACE)      PORT_CHAR(' ')
633   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_EQUALS)      PORT_CHAR('[')
634634   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Rvs Off") PORT_CODE(KEYCODE_TAB)
635635INPUT_PORTS_END
636636
r5842r5843
640640   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
641641   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED )
642642   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Crsr Right Left") PORT_CODE(KEYCODE_PGUP) PORT_CHAR(UCHAR_MAMEKEY(RIGHT)) PORT_CHAR(UCHAR_MAMEKEY(LEFT))
643   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_8_PAD)      PORT_CHAR(UCHAR_MAMEKEY(8_PAD))
643   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_8_PAD)      PORT_CHAR(UCHAR_MAMEKEY(8_PAD))
644644   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_EQUALS)      PORT_CHAR('-') PORT_CHAR('=')
645645   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_8)         PORT_CHAR('8') PORT_CHAR('\\')
646646   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_5)         PORT_CHAR('5') PORT_CHAR('%')
647647   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_2)         PORT_CHAR('2') PORT_CHAR('"')
648648
649649   PORT_START( "ROW1" )
650   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_9_PAD)      PORT_CHAR(UCHAR_MAMEKEY(9_PAD))
650   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_9_PAD)      PORT_CHAR(UCHAR_MAMEKEY(9_PAD))
651651   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED )
652652   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("\xE2\x86\x91") PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(0x2191)
653   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_7_PAD)      PORT_CHAR(UCHAR_MAMEKEY(7_PAD))
654   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_0_PAD)      PORT_CHAR(UCHAR_MAMEKEY(0_PAD))
653   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_7_PAD)      PORT_CHAR(UCHAR_MAMEKEY(7_PAD))
654   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_0_PAD)      PORT_CHAR(UCHAR_MAMEKEY(0_PAD))
655655   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_7)         PORT_CHAR('7') PORT_CHAR('&')
656656   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_4)         PORT_CHAR('4') PORT_CHAR('$')
657657   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_1)         PORT_CHAR('1') PORT_CHAR('!')
658658
659659   PORT_START( "ROW2" )
660   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_5_PAD)      PORT_CHAR(UCHAR_MAMEKEY(5_PAD))
660   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_5_PAD)      PORT_CHAR(UCHAR_MAMEKEY(5_PAD))
661661   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_COLON)      PORT_CHAR(';') PORT_CHAR('+')
662   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_K)         PORT_CHAR('K')   
663   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR(']')   
664   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_H)         PORT_CHAR('H')   
665   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F)         PORT_CHAR('F')   
666   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_S)         PORT_CHAR('S')   
667   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_ESC)      PORT_CHAR(UCHAR_MAMEKEY(ESC))
662   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_K)         PORT_CHAR('K')
663   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR(']')
664   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_H)         PORT_CHAR('H')
665   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F)         PORT_CHAR('F')
666   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_S)         PORT_CHAR('S')
667   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_ESC)      PORT_CHAR(UCHAR_MAMEKEY(ESC))
668668
669669   PORT_START( "ROW3" )
670   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_6_PAD)      PORT_CHAR(UCHAR_MAMEKEY(6_PAD))
671   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_QUOTE)      PORT_CHAR('@')   
672   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_L)         PORT_CHAR('L')   
670   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_6_PAD)      PORT_CHAR(UCHAR_MAMEKEY(6_PAD))
671   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_QUOTE)      PORT_CHAR('@')
672   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_L)         PORT_CHAR('L')
673673   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Return") PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
674   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_J)         PORT_CHAR('J')   
675   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_G)         PORT_CHAR('G')   
676   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_D)         PORT_CHAR('D')   
677   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_A)         PORT_CHAR('A')   
674   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_J)         PORT_CHAR('J')
675   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_G)         PORT_CHAR('G')
676   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_D)         PORT_CHAR('D')
677   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_A)         PORT_CHAR('A')
678678
679679   PORT_START( "ROW4" )
680680   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Del  Inst") PORT_CODE(KEYCODE_DEL) PORT_CHAR(8) PORT_CHAR(UCHAR_MAMEKEY(INSERT))
681   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_P)         PORT_CHAR('P')   
682   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_I)         PORT_CHAR('I')   
683   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR('\\')   
684   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Y)         PORT_CHAR('Y')   
685   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_R)         PORT_CHAR('R')   
686   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_W)         PORT_CHAR('W')   
681   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_P)         PORT_CHAR('P')
682   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_I)         PORT_CHAR('I')
683   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR('\\')
684   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Y)         PORT_CHAR('Y')
685   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_R)         PORT_CHAR('R')
686   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_W)         PORT_CHAR('W')
687687   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_TAB)      PORT_CHAR('\t')
688688
689689   PORT_START( "ROW5" )
690   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_4_PAD)      PORT_CHAR(UCHAR_MAMEKEY(4_PAD))
691   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_OPENBRACE)   PORT_CHAR('[')   
692   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_O)         PORT_CHAR('O')   
693   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Crsr Down Up") PORT_CODE(KEYCODE_PGDN) PORT_CHAR(UCHAR_MAMEKEY(DOWN)) PORT_CHAR(UCHAR_MAMEKEY(UP))   
694   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_U)         PORT_CHAR('U')   
695   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_T)         PORT_CHAR('T')   
696   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_E)         PORT_CHAR('E')   
697   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Q)         PORT_CHAR('Q')   
690   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_4_PAD)      PORT_CHAR(UCHAR_MAMEKEY(4_PAD))
691   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_OPENBRACE)   PORT_CHAR('[')
692   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_O)         PORT_CHAR('O')
693   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Crsr Down Up") PORT_CODE(KEYCODE_PGDN) PORT_CHAR(UCHAR_MAMEKEY(DOWN)) PORT_CHAR(UCHAR_MAMEKEY(UP))
694   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_U)         PORT_CHAR('U')
695   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_T)         PORT_CHAR('T')
696   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_E)         PORT_CHAR('E')
697   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Q)         PORT_CHAR('Q')
698698
699699   PORT_START( "ROW6" )
700   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_3_PAD)      PORT_CHAR(UCHAR_MAMEKEY(3_PAD))
701   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Shift (Right)") PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
700   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_3_PAD)      PORT_CHAR(UCHAR_MAMEKEY(3_PAD))
701   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Shift (Right)") PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
702702   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
703   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_DEL_PAD)   PORT_CHAR(UCHAR_MAMEKEY(DEL_PAD))
703   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_DEL_PAD)   PORT_CHAR(UCHAR_MAMEKEY(DEL_PAD))
704704   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_STOP)      PORT_CHAR('.') PORT_CHAR('>')
705   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_B)         PORT_CHAR('B')   
706   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_C)         PORT_CHAR('C')   
705   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_B)         PORT_CHAR('B')
706   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_C)         PORT_CHAR('C')
707707   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Shift (Left)") PORT_CODE(KEYCODE_LSHIFT)
708708
709709   PORT_START( "ROW7" )
710   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_2_PAD)      PORT_CHAR(UCHAR_MAMEKEY(2_PAD))
710   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_2_PAD)      PORT_CHAR(UCHAR_MAMEKEY(2_PAD))
711711   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Repeat") PORT_CODE(KEYCODE_LALT)
712712   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
713713   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_0)         PORT_CHAR('0') PORT_CHAR(')')
714714   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_COMMA)      PORT_CHAR(',') PORT_CHAR('<')
715   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_N)         PORT_CHAR('N')   
716   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_V)         PORT_CHAR('V')   
717   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Z)         PORT_CHAR('Z')   
715   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_N)         PORT_CHAR('N')
716   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_V)         PORT_CHAR('V')
717   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Z)         PORT_CHAR('Z')
718718
719719   PORT_START( "ROW8" )
720   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_1_PAD)      PORT_CHAR(UCHAR_MAMEKEY(1_PAD))
720   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_1_PAD)      PORT_CHAR(UCHAR_MAMEKEY(1_PAD))
721721   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SLASH)      PORT_CHAR('/') PORT_CHAR('?')
722722   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
723   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Home  Clr Screen") PORT_CODE(KEYCODE_HOME) PORT_CHAR(UCHAR_MAMEKEY(HOME))
724   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_M)         PORT_CHAR('M')   
725   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SPACE)      PORT_CHAR(' ')   
726   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_X)         PORT_CHAR('X')   
723   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Home  Clr Screen") PORT_CODE(KEYCODE_HOME) PORT_CHAR(UCHAR_MAMEKEY(HOME))
724   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_M)         PORT_CHAR('M')
725   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SPACE)      PORT_CHAR(' ')
726   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_X)         PORT_CHAR('X')
727727   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Rvs Off") PORT_CODE(KEYCODE_INSERT)
728728
729729   PORT_START( "ROW9" )
r5842r5843
739739
740740
741741INPUT_PORTS_START( pet_special )
742   PORT_START( "SPECIAL" )      /* Special keys */
742   PORT_START( "SPECIAL" )      /* Special keys */
743743   PORT_DIPNAME( 0x80, 0x00, "Shift Lock (switch)") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE
744   PORT_DIPSETTING(0x00, DEF_STR( Off ) )           
744   PORT_DIPSETTING(0x00, DEF_STR( Off ) )
745745   PORT_DIPSETTING(0x80, DEF_STR( On ) )
746746INPUT_PORTS_END
747747
748748
749749INPUT_PORTS_START( pet_config )
750750   PORT_START("CFG")
751   PORT_DIPNAME( 0x180, 0x180, "Memory")               
752   PORT_DIPSETTING(   0x000, "4 KByte" )               
753   PORT_DIPSETTING(   0x080, "8 KByte" )               
754   PORT_DIPSETTING(   0x100, "16 KByte" )               
755   PORT_DIPSETTING(   0x180, "32 KByte" )               
756   PORT_BIT( 0x08, 0x00, IPT_UNUSED ) /* no 8096 hardware */   
751   PORT_DIPNAME( 0x180, 0x180, "Memory")
752   PORT_DIPSETTING(   0x000, "4 KByte" )
753   PORT_DIPSETTING(   0x080, "8 KByte" )
754   PORT_DIPSETTING(   0x100, "16 KByte" )
755   PORT_DIPSETTING(   0x180, "32 KByte" )
756   PORT_BIT( 0x08, 0x00, IPT_UNUSED ) /* no 8096 hardware */
757757   PORT_BIT( 0x04, 0x00, IPT_UNUSED ) /* no superpet switch */
758758   PORT_DIPNAME( 0x02, 0x02, "IEEE488 Bus/Dev 8/Floppy Sim")
759   PORT_DIPSETTING(   0x00, DEF_STR( No ) )           
760   PORT_DIPSETTING(   0x02, DEF_STR( Yes ) )           
759   PORT_DIPSETTING(   0x00, DEF_STR( No ) )
760   PORT_DIPSETTING(   0x02, DEF_STR( Yes ) )
761761   PORT_DIPNAME( 0x01, 0x00, "IEEE488 Bus/Dev 9/Floppy Sim")
762   PORT_DIPSETTING(   0x00, DEF_STR( No ) )           
762   PORT_DIPSETTING(   0x00, DEF_STR( No ) )
763763   PORT_DIPSETTING(   0x01, DEF_STR( Yes ) )
764764INPUT_PORTS_END
765765
r5842r5843
767767
768768/***************************** Commodore CBMB **************************************
769769 *
770 *   - CBMB machines share Controls (in particular Lightpen) with C64
771 *   - cbmb_keyboard: Keyboard used by all the models of this series
772 *   - cbmb_special: input port for the Shift Lock Switch
770 *  - CBMB machines share Controls (in particular Lightpen) with C64
771 *  - cbmb_keyboard: Keyboard used by all the models of this series
772 *  - cbmb_special: input port for the Shift Lock Switch
773773 *
774774 **********************************************************************************/
775775
r5842r5843
779779---------------------------------------------------------
780780
781781     F1    F2   F3   F4   F5   F6   F7   F8   F9  F10      DOWN  UP  LEFT  RIGHT     HOME/CLEAR   DEL/INST
782 
783                                                                            INS 
784     ESC   1!   2"   3#   4$   5%   6^   7&   8*   9(   0)   -   =+   <-£   DEL          ?   CE    .    /
785 
786                                                                         ________   
782
783                                                                            INS
784     ESC   1!   2"   3#   4$   5%   6^   7&   8*   9(   0)   -   =+   <-?   DEL          ?   CE    .    /
785
786                                                                         ________
787787     TAB     Q    W    E    R    T     Y    U    I    O    P    [    ]  | RETURN |       7    8    9    -
788788                                                                        |__      |
789     SHIFT                                                                |     |
790     LOCK     A    S    D    F     G     H    J    K    L   ;:   '"   Pi  |     |       4    5    6    +
791                                                         |_____|
789      SHIFT                                                                |     |
790      LOCK     A    S    D    F     G     H    J    K    L   ;:   '"   Pi  |     |       4    5    6    +
791                                                                           |_____|
792792                                                                                                        E
793793        SHIFT     Z    X    C    V    B     N    M    ,<   .>   /?   SHIFT   C=          1    2    3    n
794794                                                                                                        t
795                                                                                      e
795                                                                                                        e
796796              CTRL               SPACEBAR                                              0      .    00   r
797797
798798
799Notes: "C=" is a key with the Commodore logo, Shift+6 produces an arrow pointing up ("^" above).
799Notes: "C=" is a key with the Commodore logo, Shift+6 produces an arrow pointing up ("^" above).
800800
801801
802802*/
r5842r5843
807807   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("RVS Off") PORT_CODE(KEYCODE_HOME)
808808   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Graph  Norm") PORT_CODE(KEYCODE_PGUP)
809809   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Home  Clr") PORT_CODE(KEYCODE_INSERT) PORT_CHAR(UCHAR_MAMEKEY(HOME))
810   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_UP)         PORT_CHAR(UCHAR_MAMEKEY(UP))
811   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_DOWN)         PORT_CHAR(UCHAR_MAMEKEY(DOWN))
810   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_UP)         PORT_CHAR(UCHAR_MAMEKEY(UP))
811   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_DOWN)         PORT_CHAR(UCHAR_MAMEKEY(DOWN))
812812   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F10)         PORT_CHAR(UCHAR_MAMEKEY(F10))
813813   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F9)         PORT_CHAR(UCHAR_MAMEKEY(F9))
814814
r5842r5843
823823   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F1)         PORT_CHAR(UCHAR_MAMEKEY(F1))
824824
825825   PORT_START("ROW2")
826   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_ASTERISK)      PORT_CHAR(UCHAR_MAMEKEY(SLASH_PAD))
827   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SLASH_PAD)      PORT_CHAR(UCHAR_MAMEKEY(ASTERISK))
826   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_ASTERISK)      PORT_CHAR(UCHAR_MAMEKEY(SLASH_PAD))
827   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SLASH_PAD)      PORT_CHAR(UCHAR_MAMEKEY(ASTERISK))
828828   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Keypad CE") PORT_CODE(KEYCODE_NUMLOCK)
829829   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Keypad ?") PORT_CODE(KEYCODE_END)
830   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_LEFT)         PORT_CHAR(UCHAR_MAMEKEY(LEFT))
830   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_LEFT)         PORT_CHAR(UCHAR_MAMEKEY(LEFT))
831831   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_EQUALS)      PORT_CHAR('=') PORT_CHAR('+')
832832   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_0)            PORT_CHAR('0') PORT_CHAR(')')
833833   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_9)            PORT_CHAR('9') PORT_CHAR('(')
r5842r5843
843843   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_ESC)         PORT_CHAR(UCHAR_MAMEKEY(ESC))
844844
845845   PORT_START("ROW4")
846   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_MINUS_PAD)      PORT_CHAR(UCHAR_MAMEKEY(MINUS_PAD))
847   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_9_PAD)         PORT_CHAR(UCHAR_MAMEKEY(9_PAD))
848   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_8_PAD)         PORT_CHAR(UCHAR_MAMEKEY(8_PAD))
849   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_7_PAD)         PORT_CHAR(UCHAR_MAMEKEY(7_PAD))
850   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_RIGHT)         PORT_CHAR(UCHAR_MAMEKEY(RIGHT))
846   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_MINUS_PAD)      PORT_CHAR(UCHAR_MAMEKEY(MINUS_PAD))
847   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_9_PAD)         PORT_CHAR(UCHAR_MAMEKEY(9_PAD))
848   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_8_PAD)         PORT_CHAR(UCHAR_MAMEKEY(8_PAD))
849   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_7_PAD)         PORT_CHAR(UCHAR_MAMEKEY(7_PAD))
850   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_RIGHT)         PORT_CHAR(UCHAR_MAMEKEY(RIGHT))
851851   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("\xE2\x86\x90  \xC2\xA3") PORT_CODE(KEYCODE_TILDE) PORT_CHAR(0x2190) PORT_CHAR('\xA3')
852852   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_MINUS)         PORT_CHAR('-')
853853   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_O)            PORT_CHAR('o') PORT_CHAR('O')
r5842r5843
863863   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_TAB)         PORT_CHAR('\t')
864864
865865   PORT_START("ROW6")
866   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_PLUS_PAD)      PORT_CHAR(UCHAR_MAMEKEY(PLUS_PAD))
867   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_6_PAD)         PORT_CHAR(UCHAR_MAMEKEY(6_PAD))
868   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_5_PAD)         PORT_CHAR(UCHAR_MAMEKEY(5_PAD))
869   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_4_PAD)         PORT_CHAR(UCHAR_MAMEKEY(4_PAD))
866   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_PLUS_PAD)      PORT_CHAR(UCHAR_MAMEKEY(PLUS_PAD))
867   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_6_PAD)         PORT_CHAR(UCHAR_MAMEKEY(6_PAD))
868   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_5_PAD)         PORT_CHAR(UCHAR_MAMEKEY(5_PAD))
869   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_4_PAD)         PORT_CHAR(UCHAR_MAMEKEY(4_PAD))
870870   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Del  Ins") PORT_CODE(KEYCODE_BACKSPACE)   PORT_CHAR(8) PORT_CHAR(UCHAR_MAMEKEY(INSERT))
871871   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR(']')
872872   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_P)            PORT_CHAR('p') PORT_CHAR('P')
r5842r5843
883883   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED )
884884
885885   PORT_START("ROW8")
886   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_ENTER_PAD)      PORT_CHAR(UCHAR_MAMEKEY(ENTER_PAD))
887   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_3_PAD)         PORT_CHAR(UCHAR_MAMEKEY(3_PAD))
888   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_2_PAD)         PORT_CHAR(UCHAR_MAMEKEY(2_PAD))
889   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_1_PAD)         PORT_CHAR(UCHAR_MAMEKEY(1_PAD))
886   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_ENTER_PAD)      PORT_CHAR(UCHAR_MAMEKEY(ENTER_PAD))
887   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_3_PAD)         PORT_CHAR(UCHAR_MAMEKEY(3_PAD))
888   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_2_PAD)         PORT_CHAR(UCHAR_MAMEKEY(2_PAD))
889   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_1_PAD)         PORT_CHAR(UCHAR_MAMEKEY(1_PAD))
890890   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("CBM") PORT_CODE(KEYCODE_RALT) PORT_CHAR(UCHAR_MAMEKEY(RALT))
891891   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Return") PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
892892   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_OPENBRACE)      PORT_CHAR('[')
r5842r5843
902902   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Z)            PORT_CHAR('z') PORT_CHAR('Z')
903903   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
904904
905   PORT_START("ROW10")   
905   PORT_START("ROW10")
906906   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNUSED )
907907   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Keypad 00") PORT_CODE(KEYCODE_PGDN)
908   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_DEL_PAD)      PORT_CHAR(UCHAR_MAMEKEY(DEL_PAD))
909   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_0_PAD)         PORT_CHAR(UCHAR_MAMEKEY(0_PAD))
908   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_DEL_PAD)      PORT_CHAR(UCHAR_MAMEKEY(DEL_PAD))
909   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_0_PAD)         PORT_CHAR(UCHAR_MAMEKEY(0_PAD))
910910   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
911911   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Pi") PORT_CODE(KEYCODE_BACKSLASH) PORT_CHAR(0x03C0)
912912   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_QUOTE)         PORT_CHAR('\'') PORT_CHAR('"')
913913   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SLASH)         PORT_CHAR('/') PORT_CHAR('?')
914914
915   PORT_START("ROW11")   
915   PORT_START("ROW11")
916916   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_STOP)         PORT_CHAR('.') PORT_CHAR('>')
917917   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SPACE)         PORT_CHAR(' ')
918918   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_N)            PORT_CHAR('n') PORT_CHAR('N')
r5842r5843
926926
927927INPUT_PORTS_START( cbmb_special )
928928   PORT_START("SPECIAL")
929   PORT_BIT( 0x200, 0x200, IPT_UNUSED ) /* ntsc */     
930   PORT_BIT( 0x100, 0x000, IPT_UNUSED ) /* cbm600 */   
929   PORT_BIT( 0x200, 0x200, IPT_UNUSED ) /* ntsc */
930   PORT_BIT( 0x100, 0x000, IPT_UNUSED ) /* cbm600 */
931931   PORT_DIPNAME( 0x04, 0x00, "Shift Lock (switch)") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE
932   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )         
933   PORT_DIPSETTING(   0x04, DEF_STR( On ) )         
932   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
933   PORT_DIPSETTING(   0x04, DEF_STR( On ) )
934934INPUT_PORTS_END
935935
936936
937937 /***************************** Commodore Vic 20 ***********************************
938938 *
939 *   - vic_keyboard: basic Vic 20 keyboard
939 *  - vic_keyboard: basic Vic 20 keyboard
940940 *  - vic_special: input port for the Shift Lock Switch
941 *   - vic_controls: joypads and paddles
942 *   - vic_expansion: RAM expansions
943 *   - VIC20 also has 2 lightpen ports, vic_lightpen_6560 & vic_lightpen_6561
944 *         currently in vc20.c (they need visible area parameters for centering)
941 *  - vic_controls: joypads and paddles
942 *  - vic_expansion: RAM expansions
943 *  - VIC20 also has 2 lightpen ports, vic_lightpen_6560 & vic_lightpen_6561
944 *          currently in vc20.c (they need visible area parameters for centering)
945945 *
946946 **********************************************************************************/
947947
r5842r5843
951951---------------------
952952
953953                                                                           CLR    INST
954    <-   1!   2"   3#   4$   5%   6&   7'   8(   9)   0     +    -    £    HOME   DEL           f 1
954    <-   1!   2"   3#   4$   5%   6&   7'   8(   9)   0     +    -    ?    HOME   DEL           f 1
955955
956
956
957957    CTRL   Q    W    E    R    T     Y    U    I    O    P    @    *     UP    RESTORE          f 3
958958
959959RUN   SHIFT
r5842r5843
966966                                 SPACEBAR
967967
968968
969Notes: "C=" is a key with the Commodore logo, "UP" is an arrow pointing up, the "CRSR" keys at the
969Notes: "C=" is a key with the Commodore logo, "UP" is an arrow pointing up, the "CRSR" keys at the
970970bottom-right corner are used to move the cursor on screen (Up/Down and Left/Right respectively).
971971Notice that this is exactly the same layout of C64 keyboard.
972
972
973973*/
974974
975975INPUT_PORTS_START( vic_keyboard )
976976   PORT_START( "ROW0" )
977977   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Del  Inst") PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(8) PORT_CHAR(UCHAR_MAMEKEY(INSERT))
978   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH2)      PORT_CHAR('\xA3')   
978   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH2)      PORT_CHAR('\xA3')
979979   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_MINUS)         PORT_CHAR('+')
980   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_9)            PORT_CHAR('9') PORT_CHAR(')')   
981   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_7)            PORT_CHAR('7') PORT_CHAR('\'')   
982   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_5)            PORT_CHAR('5') PORT_CHAR('%')   
983   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_3)            PORT_CHAR('3') PORT_CHAR('#')   
984   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_1)            PORT_CHAR('1') PORT_CHAR('!')   
980   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_9)            PORT_CHAR('9') PORT_CHAR(')')
981   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_7)            PORT_CHAR('7') PORT_CHAR('\'')
982   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_5)            PORT_CHAR('5') PORT_CHAR('%')
983   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_3)            PORT_CHAR('3') PORT_CHAR('#')
984   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_1)            PORT_CHAR('1') PORT_CHAR('!')
985985
986986   PORT_START( "ROW1" )
987987   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Return") PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
988   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_CLOSEBRACE)      PORT_CHAR('*')   
989   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_P)            PORT_CHAR('P')   
990   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_I)            PORT_CHAR('I')   
991   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Y)            PORT_CHAR('Y')   
992   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_R)            PORT_CHAR('R')   
993   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_W)            PORT_CHAR('W')   
988   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_CLOSEBRACE)      PORT_CHAR('*')
989   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_P)            PORT_CHAR('P')
990   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_I)            PORT_CHAR('I')
991   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Y)            PORT_CHAR('Y')
992   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_R)            PORT_CHAR('R')
993   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_W)            PORT_CHAR('W')
994994   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("\xE2\x86\x90") PORT_CODE(KEYCODE_TILDE) PORT_CHAR(0x2190)
995995
996996   PORT_START( "ROW2" )
997997   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Crsr Right Left") PORT_CODE(KEYCODE_RCONTROL) PORT_CHAR(UCHAR_MAMEKEY(RIGHT)) PORT_CHAR(UCHAR_MAMEKEY(LEFT))
998998   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_QUOTE)         PORT_CHAR(';') PORT_CHAR(']')
999   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_L)            PORT_CHAR('L')   
1000   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_J)            PORT_CHAR('J')   
1001   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_G)            PORT_CHAR('G')   
1002   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_D)            PORT_CHAR('D')   
1003   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_A)            PORT_CHAR('A')   
999   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_L)            PORT_CHAR('L')
1000   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_J)            PORT_CHAR('J')
1001   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_G)            PORT_CHAR('G')
1002   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_D)            PORT_CHAR('D')
1003   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_A)            PORT_CHAR('A')
10041004   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_TAB)         PORT_CHAR(UCHAR_SHIFT_2)
10051005
10061006   PORT_START( "ROW3" )
10071007   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Crsr Down Up") PORT_CODE(KEYCODE_RALT) PORT_CHAR(UCHAR_MAMEKEY(DOWN)) PORT_CHAR(UCHAR_MAMEKEY(UP))
10081008   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SLASH)          PORT_CHAR('/') PORT_CHAR('?')
10091009   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_COMMA)          PORT_CHAR(',') PORT_CHAR('<')
1010   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_N)            PORT_CHAR('N')   
1011   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_V)            PORT_CHAR('V')   
1012   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_X)            PORT_CHAR('X')   
1010   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_N)            PORT_CHAR('N')
1011   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_V)            PORT_CHAR('V')
1012   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_X)            PORT_CHAR('X')
10131013   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Shift (Left)") PORT_CODE(KEYCODE_LSHIFT)
10141014   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Stop Run") PORT_CODE(KEYCODE_HOME)
10151015
10161016   PORT_START( "ROW4" )
10171017   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F1)            PORT_CHAR(UCHAR_MAMEKEY(F1)) PORT_CHAR(UCHAR_MAMEKEY(F2))
1018   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Shift (Right)") PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)   
1018   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Shift (Right)") PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
10191019   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_STOP)          PORT_CHAR('.') PORT_CHAR('>')
1020   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_M)            PORT_CHAR('M')   
1021   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_B)            PORT_CHAR('B')   
1022   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_C)            PORT_CHAR('C')   
1023   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Z)            PORT_CHAR('Z')   
1024   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SPACE)         PORT_CHAR(' ')   
1020   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_M)            PORT_CHAR('M')
1021   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_B)            PORT_CHAR('B')
1022   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_C)            PORT_CHAR('C')
1023   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Z)            PORT_CHAR('Z')
1024   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SPACE)         PORT_CHAR(' ')
10251025
10261026   PORT_START( "ROW5" )
10271027   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F2)            PORT_CHAR(UCHAR_MAMEKEY(F3)) PORT_CHAR(UCHAR_MAMEKEY(F4))
1028   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH)      PORT_CHAR('=')   
1028   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH)      PORT_CHAR('=')
10291029   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_COLON)         PORT_CHAR(':') PORT_CHAR('[')
1030   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_K)            PORT_CHAR('K')   
1031   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_H)            PORT_CHAR('H')   
1032   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F)            PORT_CHAR('F')   
1033   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_S)            PORT_CHAR('S')   
1030   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_K)            PORT_CHAR('K')
1031   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_H)            PORT_CHAR('H')
1032   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F)            PORT_CHAR('F')
1033   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_S)            PORT_CHAR('S')
10341034   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("CBM") PORT_CODE(KEYCODE_LCONTROL)
10351035
10361036   PORT_START( "ROW6" )
10371037   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F3)            PORT_CHAR(UCHAR_MAMEKEY(F5)) PORT_CHAR(UCHAR_MAMEKEY(F6))
10381038   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("\xE2\x86\x91  Pi") PORT_CODE(KEYCODE_DEL) PORT_CHAR(0x2191) PORT_CHAR(0x03C0)
1039   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_OPENBRACE)       PORT_CHAR('@')   
1040   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_O)            PORT_CHAR('O')   
1041   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_U)            PORT_CHAR('U')   
1042   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_T)            PORT_CHAR('T')   
1043   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_E)            PORT_CHAR('E')   
1044   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Q)            PORT_CHAR('Q')   
1039   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_OPENBRACE)       PORT_CHAR('@')
1040   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_O)            PORT_CHAR('O')
1041   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_U)            PORT_CHAR('U')
1042   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_T)            PORT_CHAR('T')
1043   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_E)            PORT_CHAR('E')
1044   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Q)            PORT_CHAR('Q')
10451045
10461046   PORT_START( "ROW7" )
10471047   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F4)            PORT_CHAR(UCHAR_MAMEKEY(F7)) PORT_CHAR(UCHAR_MAMEKEY(F8))
10481048   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Home  Clr") PORT_CODE(KEYCODE_INSERT) PORT_CHAR(UCHAR_MAMEKEY(HOME))
1049   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_EQUALS)         PORT_CHAR('-')   
1050   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_0)            PORT_CHAR('0')   
1049   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_EQUALS)         PORT_CHAR('-')
1050   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_0)            PORT_CHAR('0')
10511051   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_8)            PORT_CHAR('8') PORT_CHAR('(')
10521052   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_6)            PORT_CHAR('6') PORT_CHAR('&')
10531053   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_4)            PORT_CHAR('4') PORT_CHAR('$')
r5842r5843
10561056
10571057
10581058INPUT_PORTS_START( vic_special )
1059   PORT_START( "SPECIAL" )  /* special keys */   
1060   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Restore") PORT_CODE(KEYCODE_PRTSCR)   
1061   PORT_DIPNAME( 0x01, 0x00, "Shift Lock (switch)") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE     
1062   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )                                         
1059   PORT_START( "SPECIAL" )  /* special keys */
1060   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Restore") PORT_CODE(KEYCODE_PRTSCR)
1061   PORT_DIPNAME( 0x01, 0x00, "Shift Lock (switch)") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE
1062   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
10631063   PORT_DIPSETTING(   0x01, DEF_STR( On ) )
10641064INPUT_PORTS_END
10651065
r5842r5843
10691069{
10701070   int bit_mask = (FPTR)param;
10711071   UINT8 port = 0;
1072   
1072
10731073   if ((input_port_read(field->port->machine, "CTRLSEL") & 0xf0) == 0x10)
10741074      port |= (input_port_read(field->port->machine, "FAKE0") & bit_mask) ? 1 : 0;
10751075
r5842r5843
10781078
10791079   return port;
10801080}
1081   
1081
10821082INPUT_PORTS_START( vic_controls )
10831083   PORT_START( "CTRLSEL" )
10841084   PORT_CATEGORY_CLASS( 0xf0, 0x00, DEF_STR( Controller ) )
r5842r5843
11141114   PORT_START( "EXP" )
11151115   PORT_DIPNAME( 0x07, 0x00, "RAM Cartridge")
11161116   PORT_DIPSETTING(   0x00, DEF_STR( None ) )
1117   PORT_DIPSETTING(   0x01, "3k" )     
1118   PORT_DIPSETTING(   0x02, "8k" )     
1119   PORT_DIPSETTING(   0x03, "16k" )     
1120   PORT_DIPSETTING(   0x04, "32k" )     
1121   PORT_DIPSETTING(   0x05, "Custom" )   
1117   PORT_DIPSETTING(   0x01, "3k" )
1118   PORT_DIPSETTING(   0x02, "8k" )
1119   PORT_DIPSETTING(   0x03, "16k" )
1120   PORT_DIPSETTING(   0x04, "32k" )
1121   PORT_DIPSETTING(   0x05, "Custom" )
11221122   PORT_DIPNAME( 0x08, 0x00, "RAM at 0x0400")
11231123   PORT_DIPSETTING(   0x00, DEF_STR( No ) )
11241124   PORT_DIPSETTING(   0x08, DEF_STR( Yes ) )
r5842r5843
11331133   PORT_DIPSETTING(   0x40, DEF_STR( Yes ) )
11341134   PORT_DIPNAME( 0x80, 0x00, "RAM at 0xa000")
11351135   PORT_DIPSETTING(   0x00, DEF_STR( No ) )
1136   PORT_DIPSETTING(   0x80, DEF_STR( Yes ) )   
1136   PORT_DIPSETTING(   0x80, DEF_STR( Yes ) )
11371137INPUT_PORTS_END
src/mess/machine/cbmdrive.c
r5842r5843
1#include <stdio.h>
2#include <stdlib.h>
1/***************************************************************
2
3    CBM Floppy Drive Simulation
4
5    This code incercepts commands from the CBM machine and
6    send/return the appropriate data to/from the disk image
7
8    This code will be eventually replaced by proper emulation
9    (see vc1541.c)
10
11***************************************************************/
12
313#include <ctype.h>
4#include <string.h>
514#include "driver.h"
615
716#include "includes/cbmserb.h"
r5842r5843
2231
2332/***********************************************
2433
25   D64 images handling
34    D64 images handling
2635
2736***********************************************/
2837
r5842r5843
342351
343352   CBM Serial Bus Control Codes
344353
345   20   Talk
346   3F   Untalk
347   40   Listen
348   5F   Unlisten
349   60   Open Channel
350   70   -
351   80   -
352   90   -
353   A0   -
354   B0   -
355   C0   -
356   D0   -
357   E0   Close
358   F0   Open
354    20  Talk
355    3F  Untalk
356    40  Listen
357    5F  Unlisten
358    60  Open Channel
359    70  -
360    80  -
361    90  -
362    A0  -
363    B0  -
364    C0  -
365    D0  -
366    E0  Close
367    F0  Open
359368
360369
361370
362    How the C1541 is called by the C64:
371    How the C1541 is called by the C64:
363372
364      read (drive 8)
365      /28 /f0 filename /3f
366      /48 /60 read data /5f
367      /28 /e0 /3f
373        read (drive 8)
374        /28 /f0 filename /3f
375        /48 /60 read data /5f
376        /28 /e0 /3f
368377
369      write (drive 8)
370      /28 /f0 filename /3f
371      /28 /60 send data /3f
372      /28 /e0 /3f
378        write (drive 8)
379        /28 /f0 filename /3f
380        /28 /60 send data /3f
381        /28 /e0 /3f
373382
374    I used '/' to denote bytes sent under Attention (ATN low).
383    I used '/' to denote bytes sent under Attention (ATN low).
375384
376   28 == LISTEN command + device number 8
377   f0 == secondary addres for OPEN file on channel 0
385    28 == LISTEN command + device number 8
386    f0 == secondary addres for OPEN file on channel 0
378387
379388  Note that there's no acknowledge bit, but timeout/EOI handshake for each
380389  byte. Check the C64 Kernel for exact description...
r5842r5843
504513
505514/***********************************************
506515
507   Drive state update
516    Drive state update
508517
509518***********************************************/
510519
r5842r5843
696705      if (VERBOSE_LEVEL >= 1) logerror("state %d->%d %d\n", oldstate, drive->i.iec.state, drive->state);
697706}
698707
699static int vc1541_time_greater(running_machine *machine, CBM_Drive * drive, attotime threshold)
708static int vc1541_time_greater( running_machine *machine, CBM_Drive * drive, attotime threshold )
700709{
701710   return attotime_compare(
702711      attotime_sub(timer_get_time(machine), drive->i.serial.time),
r5842r5843
899908      }
900909      break;
901910      /* if computer lowers clk not in 200micros (last byte following)
902      * negativ pulse on data by listener */
911        * negativ pulse on data by listener */
903912   case 118:
904913      if (!cbm_serial.clock[0])
905914      {
r5842r5843
13181327/* difference between vic20 and pet (first series)
13191328   pet lowers atn and wants a reaction on ndac */
13201329
1321void c2031_state(running_machine *machine, CBM_Drive *drive)
1330void c2031_state( running_machine *machine, CBM_Drive *drive )
13221331{
13231332   const device_config *ieeebus = devtag_get_device(machine, "ieee_bus");
13241333   int oldstate = drive->i.ieee.state;
r5842r5843
13271336   switch (drive->i.ieee.state)
13281337   {
13291338   case 0:
1330      if (!cbm_ieee_dav_r(ieeebus, 0))
1339      if (!cbm_ieee_dav_r(ieeebus, 0))
13311340      {
13321341         drive->i.ieee.state = 10;
1333      }
1334      else if (!cbm_ieee_atn_r(ieeebus, 0))
1342      }
1343      else if (!cbm_ieee_atn_r(ieeebus, 0))
13351344      {
13361345         drive->i.ieee.state = 11;
13371346         cbm_ieee_ndac_w(ieeebus, 1, 0);
r5842r5843
13411350   case 1:
13421351      break;
13431352   case 10:
1344      if (cbm_ieee_dav_r(ieeebus, 0))
1353      if (cbm_ieee_dav_r(ieeebus, 0))
13451354      {
13461355         drive->i.ieee.state++;
13471356         cbm_ieee_nrfd_w(ieeebus, 1, 1);
r5842r5843
13491358      }
13501359      break;
13511360   case 11:
1352      if (!cbm_ieee_dav_r(ieeebus, 0))
1361      if (!cbm_ieee_dav_r(ieeebus, 0))
13531362      {
13541363         cbm_ieee_nrfd_w(ieeebus, 1, 0);
13551364         data = cbm_ieee_data_r(ieeebus, 0) ^ 0xff;
13561365         cbm_ieee_ndac_w(ieeebus, 1, 1);
13571366         logerror("byte received %.2x\n",data);
1358         if (!cbm_ieee_atn_r(ieeebus, 0) && ((data & 0x0f) == drive->i.ieee.device))
1367         if (!cbm_ieee_atn_r(ieeebus, 0) && ((data & 0x0f) == drive->i.ieee.device))
13591368         {
13601369            if ((data & 0xf0) == 0x40)
13611370               drive->i.ieee.state = 30;
r5842r5843
13631372               drive->i.ieee.state = 20;
13641373            if (drive->cmdpos < sizeof (drive->cmdbuffer))
13651374               drive->cmdbuffer[drive->cmdpos++] = data;
1366         }
1367         else if ((data&0xf) == 0xf)
1375         }
1376         else if ((data&0xf) == 0xf)
13681377         {
13691378            drive->i.ieee.state--;
1370         }
1371         else
1379         }
1380         else
13721381         {
13731382            drive->i.ieee.state++;
13741383         }
r5842r5843
13761385      break;
13771386      /* wait until atn is released */
13781387   case 12:
1379      if (cbm_ieee_atn_r(ieeebus, 0))
1388      if (cbm_ieee_atn_r(ieeebus, 0))
13801389      {
13811390         drive->i.ieee.state++;
13821391         cbm_ieee_nrfd_w(ieeebus, 1, 0);
13831392      }
13841393      break;
13851394   case 13:
1386      if (!cbm_ieee_atn_r(ieeebus, 0))
1395      if (!cbm_ieee_atn_r(ieeebus, 0))
13871396      {
13881397         drive->i.ieee.state = 10;
1389/*         cbm_ieee_nrfd_w(ieeebus, 1, 0); */
1398/*          cbm_ieee_nrfd_w(ieeebus, 1, 0); */
13901399      }
13911400      break;
13921401
13931402      /* receiving rest of command */
13941403   case 20:
1395      if (cbm_ieee_dav_r(ieeebus, 0))
1404      if (cbm_ieee_dav_r(ieeebus, 0))
13961405      {
13971406         drive->i.ieee.state++;
13981407         cbm_ieee_nrfd_w(ieeebus, 1, 1);
r5842r5843
14001409      }
14011410      break;
14021411   case 21:
1403      if (!cbm_ieee_dav_r(ieeebus, 0))
1412      if (!cbm_ieee_dav_r(ieeebus, 0))
14041413      {
14051414         cbm_ieee_nrfd_w(ieeebus, 1, 0);
14061415         data = cbm_ieee_data_r(ieeebus, 0) ^ 0xff;
14071416         logerror("byte received %.2x\n",data);
14081417         if (drive->cmdpos < sizeof (drive->cmdbuffer))
14091418            drive->cmdbuffer[drive->cmdpos++] = data;
1410         if (!cbm_ieee_atn_r(ieeebus, 0) && ((data & 0xf) == 0xf))
1419         if (!cbm_ieee_atn_r(ieeebus, 0) && ((data & 0xf) == 0xf))
14111420         {
14121421            cbm_command(machine, drive);
14131422            drive->i.ieee.state = 10;
1414         }
1423         }
14151424         else
14161425            drive->i.ieee.state = 20;
14171426
r5842r5843
14211430
14221431      /* read command */
14231432   case 30:
1424      if (cbm_ieee_dav_r(ieeebus, 0))
1433      if (cbm_ieee_dav_r(ieeebus, 0))
14251434      {
14261435         drive->i.ieee.state++;
14271436         cbm_ieee_nrfd_w(ieeebus, 1, 1);
r5842r5843
14291438      }
14301439      break;
14311440   case 31:
1432      if (!cbm_ieee_dav_r(ieeebus, 0))
1441      if (!cbm_ieee_dav_r(ieeebus, 0))
14331442      {
14341443         cbm_ieee_nrfd_w(ieeebus, 1, 0);
14351444         data = cbm_ieee_data_r(ieeebus, 0) ^ 0xff;
r5842r5843
14451454      }
14461455      break;
14471456   case 32:
1448      if (cbm_ieee_dav_r(ieeebus, 0))
1457      if (cbm_ieee_dav_r(ieeebus, 0))
14491458      {
14501459         cbm_ieee_nrfd_w(ieeebus, 1, 1);
14511460         drive->i.ieee.state = 40;
14521461      }
14531462      break;
14541463   case 40:
1455      if (!cbm_ieee_ndac_r(ieeebus, 0))
1464      if (!cbm_ieee_ndac_r(ieeebus, 0))
14561465      {
14571466         cbm_ieee_data_w(ieeebus, 1, drive->buffer[drive->pos++] ^ 0xff);
14581467         if (drive->pos >= drive->size)
r5842r5843
14621471      }
14631472      break;
14641473   case 41:
1465      if (!cbm_ieee_nrfd_r(ieeebus, 0))
1474      if (!cbm_ieee_nrfd_r(ieeebus, 0))
14661475      {
14671476         drive->i.ieee.state++;
14681477      }
14691478      break;
14701479   case 42:
1471      if (cbm_ieee_ndac_r(ieeebus, 0))
1480      if (cbm_ieee_ndac_r(ieeebus, 0))
14721481      {
14731482         if (cbm_ieee_eoi_r(ieeebus, 0))
14741483            drive->i.ieee.state = 40;
14751484
1476         else
1485         else
14771486         {
14781487            cbm_ieee_data_w(ieeebus, 1, 0xff);
14791488            cbm_ieee_ndac_w(ieeebus, 1, 0);
r5842r5843
14971506
14981507/**************************************
14991508
1500   C1551 handlers
1509    C1551 handlers
15011510
15021511**************************************/
15031512
15041513
1505static void c1551_write_data (running_machine *machine, CBM_Drive * drive, int data)
1514static void c1551_write_data( running_machine *machine, CBM_Drive * drive, int data )
15061515{
15071516   drive->i.iec.datain = data;
15081517   c1551_state (machine, drive);
15091518}
15101519
1511static int c1551_read_data (running_machine *machine, CBM_Drive * drive)
1520static int c1551_read_data( running_machine *machine, CBM_Drive * drive )
15121521{
15131522   c1551_state (machine, drive);
15141523   return drive->i.iec.dataout;
15151524}
15161525
1517static void c1551_write_handshake (running_machine *machine, CBM_Drive * drive, int data)
1526static void c1551_write_handshake( running_machine *machine, CBM_Drive * drive, int data )
15181527{
15191528   drive->i.iec.handshakein = data&0x40?1:0;
15201529   c1551_state (machine, drive);
15211530}
15221531
1523static int c1551_read_handshake (running_machine *machine, CBM_Drive * drive)
1532static int c1551_read_handshake( running_machine *machine, CBM_Drive * drive )
15241533{
15251534   c1551_state (machine, drive);
15261535   return drive->i.iec.handshakeout?0x80:0;
15271536}
15281537
1529static int c1551_read_status (running_machine *machine, CBM_Drive * drive)
1538static int c1551_read_status( running_machine *machine, CBM_Drive * drive )
15301539{
15311540   c1551_state (machine, drive);
15321541   return drive->i.iec.status;
r5842r5843
15861595
15871596/**************************************
15881597
1589   VC1541 Serial Bus Device Interface
1598    VC1541 Serial Bus Device Interface
15901599
15911600**************************************/
15921601
r5842r5843
17511760
17521761/***********************************************
17531762
1754   Drive handling
1763    Drive handling
17551764
17561765***********************************************/
17571766
r5842r5843
17601769CBM_Serial cbm_serial;
17611770
17621771/* must be called before other functions */
1763static void cbm_drive_open (void)
1772static void cbm_drive_open( void )
17641773{
17651774   int i;
17661775
17671776   memset(cbm_drive, 0, sizeof(cbm_drive));
17681777   memset(&cbm_serial, 0, sizeof(cbm_serial));
17691778
1770   cbm_drive_open_helper ();
1779   cbm_drive_open_helper();
17711780
17721781   cbm_serial.count = 0;
17731782   for (i = 0; i < sizeof(cbm_serial.atn) / sizeof(int); i++)
r5842r5843
17791788   }
17801789}
17811790
1782static void cbm_drive_close (void)
1791static void cbm_drive_close( void )
17831792{
17841793   int i;
17851794
r5842r5843
17871796   for (i = 0; i < sizeof(cbm_drive) / sizeof(CBM_Drive); i++)
17881797   {
17891798      cbm_drive[i].interface = 0;
1790     
1791      if( cbm_drive[i].buffer )
1799
1800      if( cbm_drive[i].buffer )
17921801      {
17931802         free(cbm_drive[i].buffer);
17941803         cbm_drive[i].buffer = NULL;
r5842r5843
18531862
18541863/**************************************
18551864
1856   Floppy device configurations
1865    Floppy device configurations
18571866
18581867**************************************/
18591868
src/mess/machine/cbmieeeb.c
r5842r5843
44
55
66
7    2009-05 FP: Changed the implementation to be a MAME device. However,
7    2009-05 FP: Changed the implementation to be a MAME device. However,
88    the main code has been kept the same as before (to reduce the risk of
99    regressions, at this early stage). More work will be eventually done
10    to improve emulation and to allow more devices (possibly of different
10    to improve emulation and to allow more devices (possibly of different
1111    kinds) to be connected to the bus like in the real thing.
12    Notice that write handlers which are passed to the drivers, are always
13    calling functions with the "device" parameter as 0. In turn, this calls
14    c2031_state from machine/cbmdrive.c which calls again the functions with
15    "device" parameter = 1! This forces the current code to export both the
16    DEVICE_HANDLERs and the functions called by them.
17    Eventually, proper emulation will remove the need of c2031_state (multiple
18    devices would be identified by their tags) and it will allow to only export
12    Notice that write handlers which are passed to the drivers, are always
13    calling functions with the "device" parameter as 0. In turn, this calls
14    c2031_state from machine/cbmdrive.c which calls again the functions with
15    "device" parameter = 1! This forces the current code to export both the
16    DEVICE_HANDLERs and the functions called by them.
17    Eventually, proper emulation will remove the need of c2031_state (multiple
18    devices would be identified by their tags) and it will allow to only export
1919    the DEVICE_HANDLERs, as it would be preferable.
2020
21    As I have written in cbmserb.c, you should not use this driver as an
21    As I have written in cbmserb.c, you should not use this driver as an
2222    example of the right way to implement parallel devices in MAME/MESS!
2323
2424***************************************************************************/
r5842r5843
334334{
335335   struct {
336336      UINT8 data;
337/*      int fic; */
337/*      int fic; */
338338      int dav, nrfd, ndac, atn, eoi, ren;
339339      int srq;
340340   } bus[2];
r5842r5843
390390 srq serial request master input, other output
391391 */
392392
393/* TODO - These functions are used in the write handlers but also in c2031_state, hence
393/* TODO - These functions are used in the write handlers but also in c2031_state, hence
394394cannot be static. However, it would be better if only the WRITE8_DEVICE_HANDLER would be
395395made available to the rest of the source. */
396396
r5842r5843
398398{
399399   cbm_ieee_bus_t *ieeebus = get_safe_token(ieeedev);
400400
401//   DBG_LOG(ieeedev->machine, 1, "cbm ieee dav", ("%.4x dev:%d %d\n", activecpu_get_pc(), device, data));
401//  DBG_LOG(ieeedev->machine, 1, "cbm ieee dav", ("%.4x dev:%d %d\n", activecpu_get_pc(), device, data));
402402   ieeebus->bus[device].dav = data;
403   if (device == 0)
403   if (device == 0)
404404      c2031_state(ieeedev->machine, cbm_drive);
405405}
406406
r5842r5843
413413{
414414   cbm_ieee_bus_t *ieeebus = get_safe_token(ieeedev);
415415
416//   DBG_LOG(ieeedev->machine, 1, "cbm ieee nrfd", ("%.4x dev:%d %d\n", activecpu_get_pc(), device, data));
416//  DBG_LOG(ieeedev->machine, 1, "cbm ieee nrfd", ("%.4x dev:%d %d\n", activecpu_get_pc(), device, data));
417417   ieeebus->bus[device].nrfd = data;
418   if (device == 0)
418   if (device == 0)
419419      c2031_state(ieeedev->machine, cbm_drive);
420420}
421421
422422WRITE8_DEVICE_HANDLER( cbm_ieee_nrfd_write )
423423{
424   cbm_ieee_nrfd_w(device, 0, data );   
424   cbm_ieee_nrfd_w(device, 0, data );
425425}
426426
427427void cbm_ieee_ndac_w( const device_config *ieeedev, int device, int data )
428428{
429429   cbm_ieee_bus_t *ieeebus = get_safe_token(ieeedev);
430430
431//   DBG_LOG(ieeedev->machine, 1, "cbm ieee ndac",("%.4x dev:%d %d\n", activecpu_get_pc(), device, data));
431//  DBG_LOG(ieeedev->machine, 1, "cbm ieee ndac",("%.4x dev:%d %d\n", activecpu_get_pc(), device, data));
432432   ieeebus->bus[device].ndac = data;
433   if (device == 0)
433   if (device == 0)
434434      c2031_state(ieeedev->machine, cbm_drive);
435435}
436436
437437WRITE8_DEVICE_HANDLER( cbm_ieee_ndac_write )
438438{
439   cbm_ieee_ndac_w(device, 0, data );   
439   cbm_ieee_ndac_w(device, 0, data );
440440}
441441
442442void cbm_ieee_atn_w( const device_config *ieeedev, int device, int data )
443443{
444444   cbm_ieee_bus_t *ieeebus = get_safe_token(ieeedev);
445445
446//   DBG_LOG(ieeedev->machine, 1, "cbm ieee atn",("%.4x dev:%d %d\n", activecpu_get_pc(), device, data));
446//  DBG_LOG(ieeedev->machine, 1, "cbm ieee atn",("%.4x dev:%d %d\n", activecpu_get_pc(), device, data));
447447   ieeebus->bus[device].atn = data;
448   if (device == 0)
448   if (device == 0)
449449      c2031_state(ieeedev->machine, cbm_drive);
450450}
451451
452452WRITE8_DEVICE_HANDLER( cbm_ieee_atn_write )
453453{
454   cbm_ieee_atn_w(device, 0, data );   
454   cbm_ieee_atn_w(device, 0, data );
455455}
456456
457457void cbm_ieee_eoi_w( const device_config *ieeedev, int device, int data )
458458{
459459   cbm_ieee_bus_t *ieeebus = get_safe_token(ieeedev);
460460
461//   DBG_LOG(ieeedev->machine, 1, "cbm ieee eoi", ("%.4x dev:%d %d\n", activecpu_get_pc(), device, data));
461//  DBG_LOG(ieeedev->machine, 1, "cbm ieee eoi", ("%.4x dev:%d %d\n", activecpu_get_pc(), device, data));
462462   ieeebus->bus[device].eoi = data;
463   if (device == 0)
463   if (device == 0)
464464      c2031_state(ieeedev->machine, cbm_drive);
465465}
466466
467467WRITE8_DEVICE_HANDLER( cbm_ieee_eoi_write )
468468{
469   cbm_ieee_eoi_w(device, 0, data );   
469   cbm_ieee_eoi_w(device, 0, data );
470470}
471471
472472void cbm_ieee_data_w( const device_config *ieeedev, int device, int data )
473473{
474474   cbm_ieee_bus_t *ieeebus = get_safe_token(ieeedev);
475475
476//   DBG_LOG(ieeedev->machine, 1, "cbm ieee data", ("%.4x dev:%d %.2x\n", activecpu_get_pc(), device, data));
476//  DBG_LOG(ieeedev->machine, 1, "cbm ieee data", ("%.4x dev:%d %.2x\n", activecpu_get_pc(), device, data));
477477   ieeebus->bus[device].data = data;
478   if (device == 0)
478   if (device == 0)
479479      c2031_state(ieeedev->machine, cbm_drive);
480480}
481481
482482WRITE8_DEVICE_HANDLER( cbm_ieee_data_write )
483483{
484   cbm_ieee_data_w(device, 0, data );   
484   cbm_ieee_data_w(device, 0, data );
485485}
486486
487487
r5842r5843
535535   cbm_ieee_bus_t *ieeebus = get_safe_token(device);
536536   int data = ieeebus->bus[0].eoi && ieeebus->bus[1].eoi;
537537
538/*   DBG_LOG(device->machine, 1, "cbm ieee eoi", ("read %d\n", data)); */
538/*  DBG_LOG(device->machine, 1, "cbm ieee eoi", ("read %d\n", data)); */
539539   return data;
540540}
541541
r5842r5843
553553{
554554   cbm_ieee_bus_t *ieeebus = get_safe_token(device);
555555
556   switch (offset)
556   switch (offset)
557557   {
558558      case 0: return ieeebus->bus[0].data;
559559      case 1: return ieeebus->bus[0].atn;
r5842r5843
600600   cbm_ieee_bus_t *ieeebus = get_safe_token(device);
601601   int i;
602602
603   for (i = 0; i < 2; i++)
603   for (i = 0; i < 2; i++)
604604   {
605605      ieeebus->bus[i].dav = 1;
606606      ieeebus->bus[i].nrfd = 1;
src/mess/machine/cbm.c
r5842r5843
88
99/***********************************************
1010
11   Input Reading - Common Components
11    Input Reading - Common Components
1212
1313***********************************************/
1414
15/* These are needed by c64, c65 and c128, each machine has also additional specific
15/* These are needed by c64, c65 and c128, each machine has also additional specific
1616components in its INTERRUPT_GEN */
1717
1818/* keyboard lines */
r5842r5843
8484
8585      case 0x04:
8686/* was there any input on the lightpen? where is it mapped? */
87//         if (input_port_read(device->machine, "OTHER") & 0x04)         /* Lightpen Signal */
88//            value &= ?? ;
87//          if (input_port_read(device->machine, "OTHER") & 0x04)           /* Lightpen Signal */
88//              value &= ?? ;
8989         break;
9090
9191      case 0x07:
r5842r5843
126126
127127      case 0x40:
128128/* was there any input on the lightpen? where is it mapped? */
129//         if (input_port_read(device->machine, "OTHER") & 0x04)         /* Lightpen Signal */
130//            value &= ?? ;
129//          if (input_port_read(device->machine, "OTHER") & 0x04)           /* Lightpen Signal */
130//              value &= ?? ;
131131         break;
132132
133133      case 0x70:
r5842r5843
140140
141141   c64_keyline[9] = value;
142142
143//   vic2_frame_interrupt does nothing so this is not necessary
144//   vic2_frame_interrupt (device);
143//  vic2_frame_interrupt does nothing so this is not necessary
144//  vic2_frame_interrupt (device);
145145
146146   /* check if lightpen has been chosen as input: if so, enable crosshair */
147147   timer_set(device->machine, attotime_zero, NULL, 0, lightpen_tick);
r5842r5843
153153
154154/***********************************************
155155
156   CIA Common Handlers
156    CIA Common Handlers
157157
158158***********************************************/
159159
160/* These are shared by c64, c65 and c128. c65 and c128 also have additional specific
160/* These are shared by c64, c65 and c128. c65 and c128 also have additional specific
161161components (to select/read additional keyboard lines) */
162162
163163/*
164 *   CIA 0 - Port A
164 *  CIA 0 - Port A
165165 * bits 7-0 keyboard line select
166166 * bits 7,6: paddle select( 01 port a, 10 port b)
167167 * bit 4: joystick a fire button
168168 * bits 3,2: Paddles port a fire button
169169 * bits 3-0: joystick a direction
170170 *
171 *   CIA 0 - Port B
171 *  CIA 0 - Port B
172172 * bits 7-0: keyboard raw values
173173 * bit 4: joystick b fire button, lightpen select
174174 * bits 3,2: paddle b fire buttons (left,right)
r5842r5843
326326
327327/***********************************************
328328
329   CBM Quickloads
329    CBM Quickloads
330330
331331***********************************************/
332332
333333
334static int general_cbm_loadsnap(const device_config *image, const char *file_type, int snapshot_size,
335   offs_t offset, void (*cbm_sethiaddress)(running_machine *machine, UINT16 hiaddress))
334static int general_cbm_loadsnap( const device_config *image, const char *file_type, int snapshot_size,
335   offs_t offset, void (*cbm_sethiaddress)(running_machine *machine, UINT16 hiaddress) )
336336{
337337   char buffer[7];
338338   UINT8 *data = NULL;
r5842r5843
400400   return INIT_FAIL;
401401}
402402
403static void cbm_quick_sethiaddress(running_machine *machine, UINT16 hiaddress)
403static void cbm_quick_sethiaddress( running_machine *machine, UINT16 hiaddress )
404404{
405405   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
406406
r5842r5843
427427   return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbm_quick_sethiaddress);
428428}
429429
430static void cbm_pet_quick_sethiaddress(running_machine *machine, UINT16 hiaddress)
430static void cbm_pet_quick_sethiaddress( running_machine *machine, UINT16 hiaddress )
431431{
432432   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
433433
r5842r5843
479479   return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbmb_quick_sethiaddress);
480480}
481481
482static void cbm_c65_quick_sethiaddress(running_machine *machine, UINT16 hiaddress)
482static void cbm_c65_quick_sethiaddress( running_machine *machine, UINT16 hiaddress )
483483{
484484   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
485485
r5842r5843
495495
496496/***********************************************
497497
498   CBM Cartridges
498    CBM Cartridges
499499
500500***********************************************/
501501
502502
503/*   All the cartridge specific code has been moved
504   to machine/ drivers. Once more informations
505   surface about the cart expansions for systems
506   in c65.c, c128.c, cbmb.c and pet.c, the shared
507   code could be refactored to have here the
508   common functions                        */
503/*  All the cartridge specific code has been moved
504    to machine/ drivers. Once more informations
505    surface about the cart expansions for systems
506    in c65.c, c128.c, cbmb.c and pet.c, the shared
507    code could be refactored to have here the
508    common functions                                */
509509
510510
511511
512512/***********************************************
513513
514   CBM Datasette Tapes
514    CBM Datasette Tapes
515515
516516***********************************************/
517517
src/mess/machine/cbmserb.c
r5842r5843
44
55
66
7    2009-05 FP: Changed the implementation to be a MAME device. However,
7    2009-05 FP: Changed the implementation to be a MAME device. However,
88    the main code has been kept the same as before (to reduce the risk of
99    regressions, at this early stage). More work will be eventually done
10    to improve emulation and to allow more devices (possibly of different
10    to improve emulation and to allow more devices (possibly of different
1111    kinds) to be connected to the bus like in the real thing.
12    Notice that, imho, the current implementation is not very satisfactory:
13    it is not really emulating the serial bus, but (in some sense) the plug
14    of the devices which would be connected to the serial bus. Hence, the
15    provided handlers pass the serial state of the floppy drives to the CPU
16    of the main machine.
12    Notice that, imho, the current implementation is not very satisfactory:
13    it is not really emulating the serial bus, but (in some sense) the plug
14    of the devices which would be connected to the serial bus. Hence, the
15    provided handlers pass the serial state of the floppy drives to the CPU
16    of the main machine.
1717    As a byproduct of this implementation, the serial_bus device is currently
1818    tied to the floppy drives (i.e. you will find MDRV_CBM_SERBUS_ADD used
1919    in the floppy drive MACHINE_DRIVERs, not in the main computer ones)
src/mess/machine/vc20.c
r5842r5843
11/***************************************************************************
22
3   commodore vic20 home computer
4   Peter Trauner
5   (peter.trauner@jk.uni-linz.ac.at)
3    commodore vic20 home computer
4    Peter Trauner
5    (peter.trauner@jk.uni-linz.ac.at)
66
77    documentation
88     Marko.Makela@HUT.FI (vic6560)
r5842r5843
4545{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
4646
4747static int via1_portb, via1_porta, via0_ca2;
48static int serial_atn = 1, serial_clock = 1, serial_data = 1;
48static int serial_atn, serial_clock, serial_data;
4949
50static int has_vc1541 = 0;
51static int ieee = 0; /* ieee cartridge (interface and rom)*/
50static int has_vc1541;
51static int ieee; /* ieee cartridge (interface and rom)*/
5252static UINT8 *vc20_rom_2000;
5353static UINT8 *vc20_rom_4000;
5454static UINT8 *vc20_rom_6000;
r5842r5843
7373 pa2 till pa6, port b, cb1, cb2 userport
7474 irq connected to m6502 nmi
7575*/
76static void vc20_via0_irq (const device_config *device, int level)
76static void vc20_via0_irq( const device_config *device, int level )
7777{
7878   cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_NMI, level);
7979}
r5842r5843
115115   /* to short to be recognized normally */
116116   /* should be reduced to about 1 or 2 microseconds */
117117   /*  if ((input_port_read(space->machine, "CTRLSEL") & 0x20 ) && (input_port_read(space->machine, "JOY") & 0x40) )  // i.e. LIGHTPEN_BUTTON
118      value &= ~0x20; */
118        value &= ~0x20; */
119119   if (!serial_clock || !cbm_serial_clock_read(serbus, 0))
120120      value &= ~0x01;
121121   if (!serial_data || !cbm_serial_data_read(serbus, 0))
r5842r5843
148148 * cb2 inverted serial data out
149149 * irq connected to m6502 irq
150150 */
151static void vc20_via1_irq (const device_config *device, int level)
151static void vc20_via1_irq( const device_config *device, int level )
152152{
153153   cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, level);
154154}
r5842r5843
201201{
202202   UINT8 value = 0xff;
203203
204   if (!(via1_porta & 0x80))
204   if (!(via1_porta & 0x80))
205205   {
206206      UINT8 t = 0xff;
207207      if (!(keyboard[7] & 0x80)) t &= ~0x80;
r5842r5843
213213      if (!(keyboard[1] & 0x80)) t &= ~0x02;
214214      if (!(keyboard[0] & 0x80)) t &= ~0x01;
215215      value &= t;
216    }
216   }
217217
218   if (!(via1_porta & 0x40))
218   if (!(via1_porta & 0x40))
219219   {
220220      UINT8 t = 0xff;
221221      if (!(keyboard[7] & 0x40)) t &= ~0x80;
r5842r5843
227227      if (!(keyboard[1] & 0x40)) t &= ~0x02;
228228      if (!(keyboard[0] & 0x40)) t &= ~0x01;
229229      value &= t;
230    }
230   }
231231
232   if (!(via1_porta & 0x20))
232   if (!(via1_porta & 0x20))
233233   {
234234      UINT8 t = 0xff;
235235      if (!(keyboard[7] & 0x20)) t &= ~0x80;
r5842r5843
241241      if (!(keyboard[1] & 0x20)) t &= ~0x02;
242242      if (!(keyboard[0] & 0x20)) t &= ~0x01;
243243      value &= t;
244    }
244   }
245245
246   if (!(via1_porta & 0x10))
246   if (!(via1_porta & 0x10))
247247   {
248248      UINT8 t = 0xff;
249249      if (!(keyboard[7] & 0x10)) t &= ~0x80;
r5842r5843
255255      if (!(keyboard[1] & 0x10)) t &= ~0x02;
256256      if (!(keyboard[0] & 0x10)) t &= ~0x01;
257257      value &= t;
258    }
258   }
259259
260   if (!(via1_porta & 0x08))
260   if (!(via1_porta & 0x08))
261261   {
262262      UINT8 t = 0xff;
263263      if (!(keyboard[7] & 0x08)) t &= ~0x80;
r5842r5843
269269      if (!(keyboard[1] & 0x08)) t &= ~0x02;
270270      if (!(keyboard[0] & 0x08)) t &= ~0x01;
271271      value &= t;
272    }
272   }
273273
274   if (!(via1_porta & 0x04))
274   if (!(via1_porta & 0x04))
275275   {
276276      UINT8 t = 0xff;
277277      if (!(keyboard[7] & 0x04)) t &= ~0x80;
r5842r5843
283283      if (!(keyboard[1] & 0x04)) t &= ~0x02;
284284      if (!(keyboard[0] & 0x04)) t &= ~0x01;
285285      value &= t;
286    }
286   }
287287
288   if (!(via1_porta & 0x02))
288   if (!(via1_porta & 0x02))
289289   {
290290      UINT8 t = 0xff;
291291      if (!(keyboard[7] & 0x02)) t &= ~0x80;
r5842r5843
297297      if (!(keyboard[1] & 0x02)) t &= ~0x02;
298298      if (!(keyboard[0] & 0x02)) t &= ~0x01;
299299      value &= t;
300    }
300   }
301301
302   if (!(via1_porta & 0x01))
302   if (!(via1_porta & 0x01))
303303   {
304304      UINT8 t = 0xff;
305305      if (!(keyboard[7] & 0x01)) t &= ~0x80;
r5842r5843
311311      if (!(keyboard[1] & 0x01)) t &= ~0x02;
312312      if (!(keyboard[0] & 0x01)) t &= ~0x01;
313313      value &= t;
314    }
314   }
315315
316316   value &= ~(input_port_read(device->machine, "JOY") & 0x80);
317317
r5842r5843
361361   const device_config *ieeebus = devtag_get_device(device->machine, "ieee_bus");
362362   UINT8 data = 0;
363363
364   if (cbm_ieee_eoi_r(ieeebus, 0))
364   if (cbm_ieee_eoi_r(ieeebus, 0))
365365      data |= 0x08;
366366
367   if (cbm_ieee_dav_r(ieeebus, 0))
367   if (cbm_ieee_dav_r(ieeebus, 0))
368368      data |= 0x10;
369369
370   if (cbm_ieee_nrfd_r(ieeebus, 0))
370   if (cbm_ieee_nrfd_r(ieeebus, 0))
371371      data |= 0x20;
372372
373   if (cbm_ieee_ndac_r(ieeebus, 0))
373   if (cbm_ieee_ndac_r(ieeebus, 0))
374374      data |= 0x40;
375375
376   if (cbm_ieee_atn_r(ieeebus, 0))
376   if (cbm_ieee_atn_r(ieeebus, 0))
377377      data |= 0x80;
378378
379379   return data;
r5842r5843
440440   DEVCB_HANDLER(vc20_via0_write_ca2),
441441   DEVCB_NULL,                           /*via0_write_cb2, */
442442   DEVCB_LINE(vc20_via0_irq)
443},
443},
444444
445445vc20_via1 =
446446{
r5842r5843
474474   DEVCB_NULL, /*vc20_via2_write_ca2, */
475475   DEVCB_NULL, /*vc20_via2_write_cb2, */
476476   DEVCB_LINE(vc20_via1_irq)
477},
477},
478478
479479vc20_via3 =
480480{
r5842r5843
493493   DEVCB_LINE(vc20_via1_irq)
494494};
495495
496WRITE8_HANDLER ( vc20_write_9400 )
496WRITE8_HANDLER( vc20_write_9400 )
497497{
498498   vc20_memory_9400[offset] = data | 0xf0;
499499}
500500
501501
502int vic6560_dma_read_color (running_machine *machine, int offset)
502int vic6560_dma_read_color( running_machine *machine, int offset )
503503{
504504   return vc20_memory_9400[offset & 0x3ff];
505505}
506506
507int vic6560_dma_read (running_machine *machine, int offset)
507int vic6560_dma_read( running_machine *machine, int offset )
508508{
509509   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
510510   /* should read real system bus between 0x9000 and 0xa000 */
511   return memory_read_byte(space, VIC6560ADDR2VC20ADDR (offset));
511   return memory_read_byte(space, VIC6560ADDR2VC20ADDR(offset));
512512}
513513
514WRITE8_HANDLER( vc20_0400_w )
514WRITE8_HANDLER( vc20_0400_w )
515515{
516   if (mess_ram_size >= 8 * 1024)
516   if (mess_ram_size >= 8 * 1024)
517517   {
518518      mess_ram[0x0400 + offset] = data;
519519   }
520520}
521521
522WRITE8_HANDLER( vc20_2000_w )
522WRITE8_HANDLER( vc20_2000_w )
523523{
524524   if ((mess_ram_size >= 16 * 1024) && vc20_rom_2000 == NULL)
525525   {
r5842r5843
527527   }
528528}
529529
530WRITE8_HANDLER( vc20_4000_w )
530WRITE8_HANDLER( vc20_4000_w )
531531{
532   if ((mess_ram_size >= 24 * 1024) && vc20_rom_4000 == NULL)
532   if ((mess_ram_size >= 24 * 1024) && vc20_rom_4000 == NULL)
533533   {
534534      mess_ram[0x4000 + offset] = data;
535535   }
536536}
537537
538WRITE8_HANDLER( vc20_6000_w )
538WRITE8_HANDLER( vc20_6000_w )
539539{
540   if ((mess_ram_size >= 32 * 1024) && vc20_rom_6000 == NULL)
540   if ((mess_ram_size >= 32 * 1024) && vc20_rom_6000 == NULL)
541541   {
542542      mess_ram[0x6000 + offset] = data;
543543   }
544544}
545545
546546
547static void vc20_memory_init(running_machine *machine)
547static void vc20_memory_init( running_machine *machine )
548548{
549549   static int inited = 0;
550550   UINT8 *memory = memory_region (machine, "maincpu");
551551
552552   if (inited) return;
553553   /* power up values are random (more likely bit set)
554      measured in cost reduced german vc20
555      6116? 2kbx8 ram in main area
556      2114 1kbx4 ram at non used color ram area 0x9400 */
554       measured in cost reduced german vc20
555       6116? 2kbx8 ram in main area
556       2114 1kbx4 ram at non used color ram area 0x9400 */
557557
558558   memset(memory, 0, 0x400);
559559   memset(memory + 0x1000, 0, 0x1000);
r5842r5843
571571   }
572572   // this would be the straight forward memory init for
573573   // non cost reduced vic20 (2114 rams)
574   for (i = 0x1000; i < 0x2000; i += 0x40)
574   for (i = 0x1000; i < 0x2000; i += 0x40)
575575      memset(memory + i, i & 0x40 ? 0 : 0xff, 0x40);
576576#endif
577577
r5842r5843
593593{
594594   vc20_memory_init(machine);
595595
596   serial_atn = 1;
597   serial_clock = 1;
598   serial_data = 1;
599
596600   datasette_timer = timer_alloc(machine, vic20_tape_timer, NULL);
597601
598602   if (has_vc1541)
599      drive_config(machine, type_1541, 0, 0, "cpu_vc1540", 8);
603      cbm_drive_config(machine, type_1541, 0, 0, "cpu_vc1540", 8);
600604}
601605
602606DRIVER_INIT( vc20 )
603607{
608   ieee = 0;
609   has_vc1541 = 0;
604610   vc20_common_driver_init(machine);
605611   vic6561_init(vic6560_dma_read, vic6560_dma_read_color);
606612}
607613
608614DRIVER_INIT( vic20 )
609615{
616   ieee = 0;
617   has_vc1541 = 0;
610618   vc20_common_driver_init(machine);
611619   vic6560_init(vic6560_dma_read, vic6560_dma_read_color);
612620}
r5842r5843
618626
619627DRIVER_INIT( vc20v )
620628{
629   ieee = 0;
621630   has_vc1541 = 1;
622631   vc20_common_driver_init(machine);
623632   vic6561_init(vic6560_dma_read, vic6560_dma_read_color);
r5842r5843
625634
626635DRIVER_INIT( vic20v )
627636{
637   ieee = 0;
628638   has_vc1541 = 1;
629639   vc20_common_driver_init(machine);
630640   vic6560_init(vic6560_dma_read, vic6560_dma_read_color);
631   drive_config(machine, type_1541, 0, 0, "cpu_vc1540", 8);
632641}
633642
634643DRIVER_INIT( vic20i )
635644{
636645   ieee = 1;
646   has_vc1541 = 0;
637647   vc20_common_driver_init(machine);
638648   vic6560_init(vic6560_dma_read, vic6560_dma_read_color);
639649}
r5842r5843
644654
645655   if (has_vc1541)
646656   {
647      drive_reset();
657      cbm_drive_reset(machine);
648658   }
649659   else
650660   {
651      if (ieee)
661      if (ieee)
652662      {
653663         cbm_drive_0_config(IEEE, 8);
654664         cbm_drive_1_config(IEEE, 9);
655      }
656      else
665      }
666      else
657667      {
658668         cbm_drive_0_config(SERIAL, 8);
659669         cbm_drive_1_config(SERIAL, 9);
r5842r5843
663673   via_ca1_w(via_0, 0, vc20_via0_read_ca1(via_0, 0));
664674
665675   /* Set up memory banks */
666   memory_set_bankptr (machine,  1, ( ( mess_ram_size >=  8 * 1024 ) ? mess_ram : memory_region(machine, "maincpu") ) + 0x0400 );
667   memory_set_bankptr (machine,  2, vc20_rom_2000 ? vc20_rom_2000 : ( ( ( mess_ram_size >= 16 * 1024 ) ? mess_ram : memory_region(machine, "maincpu") ) + 0x2000 ) );
668   memory_set_bankptr (machine,  3, vc20_rom_4000 ? vc20_rom_4000 : ( ( ( mess_ram_size >= 24 * 1024 ) ? mess_ram : memory_region(machine, "maincpu") ) + 0x4000 ) );
669   memory_set_bankptr (machine,  4, vc20_rom_6000 ? vc20_rom_6000 : ( ( ( mess_ram_size >= 32 * 1024 ) ? mess_ram : memory_region(machine, "maincpu") ) + 0x6000 ) );
670   memory_set_bankptr (machine,  5, vc20_rom_a000 ? vc20_rom_a000 : ( memory_region(machine, "maincpu") + 0xa000 ) );
676   memory_set_bankptr(machine,  1, ( ( mess_ram_size >=  8 * 1024 ) ? mess_ram : memory_region(machine, "maincpu") ) + 0x0400 );
677   memory_set_bankptr(machine,  2, vc20_rom_2000 ? vc20_rom_2000 : ( ( ( mess_ram_size >= 16 * 1024 ) ? mess_ram : memory_region(machine, "maincpu") ) + 0x2000 ) );
678   memory_set_bankptr(machine,  3, vc20_rom_4000 ? vc20_rom_4000 : ( ( ( mess_ram_size >= 24 * 1024 ) ? mess_ram : memory_region(machine, "maincpu") ) + 0x4000 ) );
679   memory_set_bankptr(machine,  4, vc20_rom_6000 ? vc20_rom_6000 : ( ( ( mess_ram_size >= 32 * 1024 ) ? mess_ram : memory_region(machine, "maincpu") ) + 0x6000 ) );
680   memory_set_bankptr(machine,  5, vc20_rom_a000 ? vc20_rom_a000 : ( memory_region(machine, "maincpu") + 0xa000 ) );
671681}
672682
673683
r5842r5843
708718
709719/***********************************************
710720
711   VIC20 Cartridges
721    VIC20 Cartridges
712722
713723***********************************************/
714724
715static DEVICE_START(vic20_cart)
725static DEVICE_START( vic20_cart )
716726{
717727   vc20_memory_init(device->machine);
718728   vc20_rom_2000 = NULL;
r5842r5843
721731   vc20_rom_a000 = NULL;
722732}
723733
724static DEVICE_IMAGE_LOAD(vic20_cart)
734static DEVICE_IMAGE_LOAD( vic20_cart )
725735{
726736   int size = image_length(image), test;
727737   const char *filetype;
r5842r5843
732742   static const unsigned char magic[] = {0x41, 0x30, 0x20, 0xc3, 0xc2, 0xcd};   /* A0 CBM at 0xa004 (module offset 4) */
733743   unsigned char buffer[sizeof (magic)];
734744
735   if (strcmp(image->tag,"cart1")==0) {
745   if (strcmp(image->tag, "cart1") == 0)
736746      index = 0;
737   }
738   if (strcmp(image->tag,"cart2")==0) {
747
748   if (strcmp(image->tag, "cart2") == 0)
739749      index = 1;
740   }
741   
742   image_fseek (image, 4, SEEK_SET);
743   image_fread (image, buffer, sizeof (magic));
744   image_fseek (image, 0, SEEK_SET);
745750
751   image_fseek(image, 4, SEEK_SET);
752   image_fread(image, buffer, sizeof (magic));
753   image_fseek(image, 0, SEEK_SET);
754
746755   /* Check if our cart has the magic string, and set its loading address according to its size */
747   if (!memcmp (buffer, magic, sizeof (magic)))
756   if (!memcmp(buffer, magic, sizeof (magic)))
748757      address = (size == 0x4000) ? 0x4000 : 0xa000;
749758
750759   /* Give a loading address to non .bin / non .rom carts as well */
751760   /* We support .a0, .20, .40 and .60 files */
752761   filetype = image_filetype(image);
753762
754   if (!mame_stricmp (filetype, "a0"))
763   if (!mame_stricmp(filetype, "a0"))
755764      address = 0xa000;
756765
757   else if (!mame_stricmp (filetype, "20"))
766   else if (!mame_stricmp(filetype, "20"))
758767      address = 0x2000;
759768
760   else if (!mame_stricmp (filetype, "40"))
769   else if (!mame_stricmp(filetype, "40"))
761770      address = 0x4000;
762771
763   else if (!mame_stricmp (filetype, "60"))
772   else if (!mame_stricmp(filetype, "60"))
764773      address = 0x6000;
765774
766   /* As a last try, give a reasonable loading address also to .bin/.rom without the magic string */     
775   /* As a last try, give a reasonable loading address also to .bin/.rom without the magic string */
767776   else if (!address)
768777   {
769778      logerror("Cart %s does not contain the magic string: it may be loaded at the wrong memory address!\n", image_filename(image));
r5842r5843
774783   tag = index ? "user2" : "user1";
775784
776785   logerror("Loading cart %s at %.4x size:%.4x\n", image_filename(image), address, size);
777   
786
778787   /* Finally load the cart */
779788   test = image_fread(image, memory_region_alloc( image->machine, tag, ( size & 0x1FFF ) ? ( size + 0x2000 ) : size, 0 ), size);
780789
r5842r5843
782791      return INIT_FAIL;
783792
784793   /* Perform banking for the cartridge, based on the prescribed address */
785   switch( address )
794   switch( address )
786795   {
787796      case 0x2000:
788797         vc20_rom_2000 = memory_region(image->machine, tag);
r5842r5843
790799
791800      case 0x4000:
792801         vc20_rom_4000 = memory_region(image->machine, tag);
793         if ( size > 0x2000 )
794         {
802         if (size > 0x2000)
795803            vc20_rom_6000 = memory_region(image->machine, tag) + 0x2000;
796         }
797804         break;
798805
799806      case 0x6000:
src/mess/machine/c64.c
r5842r5843
11/***************************************************************************
2   commodore c64 home computer
2    commodore c64 home computer
33
44    peter.trauner@jk.uni-linz.ac.at
55    documentation
r5842r5843
77***************************************************************************/
88
99/*
10   2008-09-06: Tape status for C64 & C128 [FP & RZ]
11   - tape loading works
12   - tap files are supported
13   - tape writing works
10    2008-09-06: Tape status for C64 & C128 [FP & RZ]
11    - tape loading works
12    - tap files are supported
13    - tape writing works
1414*/
1515
1616#include "driver.h"
r5842r5843
6666static int ultimax;
6767int c64_tape_on;
6868static int c64_cia1_on;
69static int c64_io_enabled = 0;
69static int c64_io_enabled;
7070static int is_sx64;            // temporary workaround until we implement full vc1541 emulation for every c64 set
7171static UINT8 c64_cart_n_banks = 0;
7272
7373static UINT8 serial_clock, serial_data, serial_atn;
74static UINT8 vicirq = 0;
74static UINT8 vicirq;
7575
76static void c64_nmi(running_machine *machine)
76static void c64_nmi( running_machine *machine )
7777{
7878   static int nmilevel = 0;
7979   const device_config *cia_1 = devtag_get_device(machine, "cia_1");
r5842r5843
9090
9191/***********************************************
9292
93   CIA Interfaces
93    CIA Interfaces
9494
9595***********************************************/
9696
9797/*
98 *   CIA 0 - Port A keyboard line select
99 *   CIA 0 - Port B keyboard line read
98 *  CIA 0 - Port A keyboard line select
99 *  CIA 0 - Port B keyboard line read
100100 *
101 *   flag cassette read input, serial request in
102 *   irq to irq connected
101 *  flag cassette read input, serial request in
102 *  irq to irq connected
103103 *
104 *   see machine/cbm.c
104 *  see machine/cbm.c
105105 */
106106
107107static READ8_DEVICE_HANDLER( c64_cia0_port_a_r )
r5842r5843
123123    vic2_lightpen_write(data & 0x10);
124124}
125125
126static void c64_irq (running_machine *machine, int level)
126static void c64_irq( running_machine *machine, int level )
127127{
128128   static int old_level = 0;
129129
r5842r5843
135135   }
136136}
137137
138static void c64_cia0_interrupt (const device_config *device, int level)
138static void c64_cia0_interrupt( const device_config *device, int level )
139139{
140140   c64_irq (device->machine, level || vicirq);
141141}
142142
143void c64_vic_interrupt (running_machine *machine, int level)
143void c64_vic_interrupt( running_machine *machine, int level )
144144{
145145   const device_config *cia_0 = devtag_get_device(machine, "cia_0");
146146#if 1
r5842r5843
225225   c64_vicaddr = c64_memory + helper[data & 0x03];
226226}
227227
228static void c64_cia1_interrupt (const device_config *device, int level)
228static void c64_cia1_interrupt( const device_config *device, int level )
229229{
230230   c64_nmi(device->machine);
231231}
r5842r5843
256256
257257/***********************************************
258258
259   Memory Handlers
259    Memory Handlers
260260
261261***********************************************/
262262
r5842r5843
269269   const device_config *cia_1 = devtag_get_device(space->machine, "cia_1");
270270   const device_config *sid = devtag_get_device(space->machine, "sid6581");
271271
272   c64_io_mirror[ offset ] = data;
273   if (offset < 0x400) {
274      vic2_port_w (space, offset & 0x3ff, data);
275   } else if (offset < 0x800) {
276      sid6581_w (sid, offset & 0x3ff, data);
277   } else if (offset < 0xc00)
272   c64_io_mirror[offset] = data;
273   if (offset < 0x400)
274      vic2_port_w(space, offset & 0x3ff, data);
275   else if (offset < 0x800)
276      sid6581_w(sid, offset & 0x3ff, data);
277   else if (offset < 0xc00)
278278      c64_colorram[offset & 0x3ff] = data | 0xf0;
279279   else if (offset < 0xd00)
280280      cia_w(cia_0, offset, data);
r5842r5843
286286         DBG_LOG(space->machine, 1, "io write", ("%.3x %.2x\n", offset, data));
287287   }
288288   else if (offset < 0xf00)
289   {
290      /* i/o 1 */
291         DBG_LOG(space->machine, 1, "io write", ("%.3x %.2x\n", offset, data));
292   }
289      DBG_LOG(space->machine, 1, "io write", ("%.3x %.2x\n", offset, data));       /* i/o 1 */
293290   else
294   {
295      /* i/o 2 */
296         DBG_LOG(space->machine, 1, "io write", ("%.3x %.2x\n", offset, data));
297   }
291      DBG_LOG(space->machine, 1, "io write", ("%.3x %.2x\n", offset, data));      /* i/o 2 */
298292}
299293
300WRITE8_HANDLER(c64_ioarea_w)
294WRITE8_HANDLER( c64_ioarea_w )
301295{
302296   if (c64_io_enabled)
303   {
304297      c64_write_io(space, offset, data);
305   }
306298   else
307   {
308299      c64_io_ram_w_ptr[offset] = data;
309   }
310300}
311301
312302READ8_HANDLER( c64_read_io )
r5842r5843
316306   const device_config *sid = devtag_get_device(space->machine, "sid6581");
317307
318308   if (offset < 0x400)
319      return vic2_port_r (space, offset & 0x3ff);
309      return vic2_port_r(space, offset & 0x3ff);
320310
321311   else if (offset < 0x800)
322      return sid6581_r (sid, offset & 0x3ff);
312      return sid6581_r(sid, offset & 0x3ff);
323313
324314   else if (offset < 0xc00)
325315      return c64_colorram[offset & 0x3ff];
r5842r5843
347337   return 0xff;
348338}
349339
350READ8_HANDLER(c64_ioarea_r)
340READ8_HANDLER( c64_ioarea_r )
351341{
352342   return c64_io_enabled ? c64_read_io(space, offset) : c64_io_ram_r_ptr[offset];
353343}
r5842r5843
466456
467457*/
468458
469static void c64_bankswitch(running_machine *machine, int reset)
459static void c64_bankswitch( running_machine *machine, int reset )
470460{
471461   static int old = -1, exrom, game;
472462   int loram, hiram, charen;
r5842r5843
492482   {
493483         c64_io_enabled = 1;      // charen has no effect in ultimax_mode
494484
495         memory_set_bankptr (machine, 1, roml);
496         memory_set_bankptr (machine, 2, c64_memory + 0x8000);
497         memory_set_bankptr (machine, 3, c64_memory + 0xa000);
498         memory_set_bankptr (machine, 4, romh);
485         memory_set_bankptr(machine, 1, roml);
486         memory_set_bankptr(machine, 2, c64_memory + 0x8000);
487         memory_set_bankptr(machine, 3, c64_memory + 0xa000);
488         memory_set_bankptr(machine, 4, romh);
499489         memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xe000, 0xffff, 0, 0, SMH_NOP);
500490   }
501491   else
r5842r5843
503493      /* 0x8000-0x9000 */
504494      if (loram && hiram && !c64_exrom)
505495      {
506         memory_set_bankptr (machine, 1, roml);
507         memory_set_bankptr (machine, 2, c64_memory + 0x8000);
496         memory_set_bankptr(machine, 1, roml);
497         memory_set_bankptr(machine, 2, c64_memory + 0x8000);
508498      }
509499      else
510500      {
511         memory_set_bankptr (machine, 1, c64_memory + 0x8000);
512         memory_set_bankptr (machine, 2, c64_memory + 0x8000);
501         memory_set_bankptr(machine, 1, c64_memory + 0x8000);
502         memory_set_bankptr(machine, 2, c64_memory + 0x8000);
513503      }
514504
515505      /* 0xa000 */
516506      if (hiram && !c64_game && !c64_exrom)
517         memory_set_bankptr (machine, 3, romh);
507         memory_set_bankptr(machine, 3, romh);
518508
519509      else if (loram && hiram && c64_game)
520         memory_set_bankptr (machine, 3, c64_basic);
510         memory_set_bankptr(machine, 3, c64_basic);
521511
522512      else
523         memory_set_bankptr (machine, 3, c64_memory + 0xa000);
513         memory_set_bankptr(machine, 3, c64_memory + 0xa000);
524514
525515      /* 0xd000 */
526516      // RAM
r5842r5843
550540      }
551541
552542      /* 0xe000-0xf000 */
553      memory_set_bankptr (machine, 4, hiram ? c64_kernal : c64_memory + 0xe000);
554      memory_set_bankptr (machine, 5, c64_memory + 0xe000);
543      memory_set_bankptr(machine, 4, hiram ? c64_kernal : c64_memory + 0xe000);
544      memory_set_bankptr(machine, 5, c64_memory + 0xe000);
555545   }
556546
557547   /* make sure the opbase function gets called each time */
r5842r5843
578568
579569static emu_timer *datasette_timer;
580570
581void c64_m6510_port_write(const device_config *device, UINT8 direction, UINT8 data)
571void c64_m6510_port_write( const device_config *device, UINT8 direction, UINT8 data )
582572{
583573   /* if line is marked as input then keep current value */
584574   data = (c64_port_data & ~direction) | (data & direction);
r5842r5843
620610   if (!ultimax)
621611      c64_bankswitch(device->machine, 0);
622612
623   c64_memory[0x000] = memory_read_byte( cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM), 0 );
624   c64_memory[0x001] = memory_read_byte( cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM), 1 );
613   c64_memory[0x000] = memory_read_byte(cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM), 0);
614   c64_memory[0x001] = memory_read_byte(cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM), 1);
625615}
626616
627UINT8 c64_m6510_port_read(const device_config *device, UINT8 direction)
617UINT8 c64_m6510_port_read( const device_config *device, UINT8 direction )
628618{
629619   UINT8 data = c64_port_data;
630620
r5842r5843
640630}
641631
642632
643int c64_paddle_read (const device_config *device, int which)
633int c64_paddle_read( const device_config *device, int which )
644634{
645635   running_machine *machine = device->machine;
646636   int pot1 = 0xff, pot2 = 0xff, pot3 = 0xff, pot4 = 0xff, temp;
r5842r5843
742732   }
743733}
744734
745 READ8_HANDLER(c64_colorram_read)
735READ8_HANDLER( c64_colorram_read )
746736{
747737   return c64_colorram[offset & 0x3ff];
748738}
r5842r5843
757747 * a15 and a14 portlines
758748 * 0x1000-0x1fff, 0x9000-0x9fff char rom
759749 */
760static int c64_dma_read(running_machine *machine, int offset)
750static int c64_dma_read( running_machine *machine, int offset )
761751{
762752   if (!c64_game && c64_exrom)
763753   {
r5842r5843
773763   return c64_vicaddr[offset];
774764}
775765
776static int c64_dma_read_ultimax(running_machine *machine, int offset )
766static int c64_dma_read_ultimax( running_machine *machine, int offset )
777767{
778768   if (offset < 0x3000)
779769      return c64_memory[offset];
r5842r5843
781771   return c64_romh[offset & 0x1fff];
782772}
783773
784static int c64_dma_read_color(running_machine *machine, int offset)
774static int c64_dma_read_color( running_machine *machine, int offset )
785775{
786776   return c64_colorram[offset & 0x3ff] & 0xf;
787777}
r5842r5843
799789   last = tmp;
800790}
801791
802static void c64_common_driver_init (running_machine *machine)
792static void c64_common_driver_init( running_machine *machine )
803793{
804794   if (!ultimax)
805795   {
r5842r5843
876866   c64_cia1_on = 1;
877867   c64_tape_on = 0;
878868   c64_common_driver_init(machine);
879   drive_config(machine, type_1541, 0, 0, "cpu_vc1540", 8);
869   cbm_drive_config(machine, type_1541, 0, 0, "cpu_vc1540", 8);
880870}
881871
882872MACHINE_START( c64 )
r5842r5843
884874   c64_port_data = 0x17;
885875
886876   c64_io_mirror = auto_alloc_array(machine, UINT8, 0x1000);
877   c64_io_enabled = 0;
887878
888879   if (is_sx64)
889880   {
890      drive_reset();
881      cbm_drive_reset(machine);
891882   }
892883   else if (c64_cia1_on)
893884   {
r5842r5843
912903
913904/***********************************************
914905
915   C64 Cartridges
906    C64 Cartridges
916907
917908***********************************************/
918909
919/* Info based on http://ist.uwaterloo.ca/~schepers/formats/CRT.TXT       */
910/* Info based on http://ist.uwaterloo.ca/~schepers/formats/CRT.TXT      */
920911/* Please refer to the webpage for the latest version and for a very
921   complete listing of various cart types and their bankswitch tricks    */
912   complete listing of various cart types and their bankswitch tricks   */
922913/*
923914  Cartridge files were introduced in the CCS64  emulator,  written  by  Per
924915Hakan Sundell, and use the ".CRT" file extension. This format  was  created
r5842r5843
938929
939930[ A .CRT file consists of
940931
941   $0000-0040 :   Header of the whole .crt files
942   $0040-EOF :      Blocks of data
932    $0000-0040 :    Header of the whole .crt files
933    $0040-EOF :     Blocks of data
943934
944935  Each block of data, called 'CHIP', can be of variable size. The first
9459360x10 bytes of each CHIP block is the block header, and it contains various
r5842r5843
1000991static INT8 cbm_c64_game;
1001992static INT8 cbm_c64_exrom;
1002993
1003static DEVICE_IMAGE_UNLOAD(c64_cart)
994static DEVICE_IMAGE_UNLOAD( c64_cart )
1004995{
1005996   int i;
1006997
r5842r5843
10131004}
10141005
10151006
1016static DEVICE_START(c64_cart)
1007static DEVICE_START( c64_cart )
10171008{
10181009   int index = 0;
10191010
1020   if (strcmp(device->tag, "cart1") == 0)
1011   if (strcmp(device->tag, "cart1") == 0)
10211012      index = 0;
10221013
1023   if (strcmp(device->tag, "cart2") == 0)
1014   if (strcmp(device->tag, "cart2") == 0)
10241015      index = 1;
10251016
10261017
1027   /* In the first slot we can load a .crt file. In this case we want
1028      to use game & exrom values from the header, not the default ones. */
1018   /* In the first slot we can load a .crt file. In this case we want
1019        to use game & exrom values from the header, not the default ones. */
10291020   if (index == 0)
10301021   {
10311022      cbm_c64_game = -1;
r5842r5843
10351026
10361027/* Hardware Types for C64 carts */
10371028enum {
1038   GENERIC_CRT = 0,      /* 00 - Normal cartridge               */
1039   ACTION_REPLAY,      /* 01 - Action Replay                  */
1040   KCS_PC,         /* 02 - KCS Power Cartridge               */
1041   FINAL_CART_III,      /* 03 - Final Cartridge III               */
1042   SIMONS_BASIC,      /* 04 - Simons Basic                  */
1043   OCEAN_1,         /* 05 - Ocean type 1 (1)               */
1044   EXPERT,         /* 06 - Expert Cartridge               */
1045   FUN_PLAY,         /* 07 - Fun Play, Power Play               */
1046   SUPER_GAMES,      /* 08 - Super Games                  */
1047   ATOMIC_POWER,      /* 09 - Atomic Power                  */
1048   EPYX_FASTLOAD,      /* 10 - Epyx Fastload                  */
1049   WESTERMANN,         /* 11 - Westermann Learning               */
1050   REX,            /* 12 - Rex Utility                  */
1051   FINAL_CART_I,      /* 13 - Final Cartridge I               */
1052   MAGIC_FORMEL,      /* 14 - Magic Formel                  */
1053   C64GS,         /* 15 - C64 Game System, System 3            */
1054   WARPSPEED,         /* 16 - WarpSpeed                     */
1055   DINAMIC,         /* 17 - Dinamic (2)                  */
1056   ZAXXON,         /* 18 - Zaxxon, Super Zaxxon (SEGA)            */
1057   DOMARK,         /* 19 - Magic Desk, Domark, HES Australia         */
1058   SUPER_SNAP_5,      /* 20 - Super Snapshot 5               */
1059   COMAL_80,         /* 21 - Comal-80                     */
1060   STRUCT_BASIC,      /* 22 - Structured Basic               */
1061   ROSS,            /* 23 - Ross                     */
1062   DELA_EP64,         /* 24 - Dela EP64                     */
1063   DELA_EP7X8,         /* 25 - Dela EP7x8                  */
1064   DELA_EP256,         /* 26 - Dela EP256                  */
1065   REX_EP256,         /* 27 - Rex EP256                     */
1066   MIKRO_ASSMBLR,      /* 28 - Mikro Assembler                  */
1067   REAL_FC_I,         /* 29 - (3)                        */
1068   ACTION_REPLAY_4,      /* 30 - Action Replay 4                  */
1069   STARDOS,         /* 31 - StarDOS                     */
1029   GENERIC_CRT = 0,      /* 00 - Normal cartridge                    */
1030   ACTION_REPLAY,      /* 01 - Action Replay                       */
1031   KCS_PC,         /* 02 - KCS Power Cartridge                 */
1032   FINAL_CART_III,      /* 03 - Final Cartridge III                 */
1033   SIMONS_BASIC,      /* 04 - Simons Basic                        */
1034   OCEAN_1,         /* 05 - Ocean type 1 (1)                    */
1035   EXPERT,         /* 06 - Expert Cartridge                    */
1036   FUN_PLAY,         /* 07 - Fun Play, Power Play                    */
1037   SUPER_GAMES,      /* 08 - Super Games                     */
1038   ATOMIC_POWER,      /* 09 - Atomic Power                        */
1039   EPYX_FASTLOAD,      /* 10 - Epyx Fastload                       */
1040   WESTERMANN,         /* 11 - Westermann Learning                 */
1041   REX,            /* 12 - Rex Utility                     */
1042   FINAL_CART_I,      /* 13 - Final Cartridge I                   */
1043   MAGIC_FORMEL,      /* 14 - Magic Formel                        */
1044   C64GS,         /* 15 - C64 Game System, System 3               */
1045   WARPSPEED,         /* 16 - WarpSpeed                           */
1046   DINAMIC,         /* 17 - Dinamic (2)                     */
1047   ZAXXON,         /* 18 - Zaxxon, Super Zaxxon (SEGA)             */
1048   DOMARK,         /* 19 - Magic Desk, Domark, HES Australia           */
1049   SUPER_SNAP_5,      /* 20 - Super Snapshot 5                    */
1050   COMAL_80,         /* 21 - Comal-80                            */
1051   STRUCT_BASIC,      /* 22 - Structured Basic                    */
1052   ROSS,            /* 23 - Ross                            */
1053   DELA_EP64,         /* 24 - Dela EP64                           */
1054   DELA_EP7X8,         /* 25 - Dela EP7x8                      */
1055   DELA_EP256,         /* 26 - Dela EP256                      */
1056   REX_EP256,         /* 27 - Rex EP256                           */
1057   MIKRO_ASSMBLR,      /* 28 - Mikro Assembler                     */
1058   REAL_FC_I,         /* 29 - (3)                             */
1059   ACTION_REPLAY_4,      /* 30 - Action Replay 4                     */
1060   STARDOS,         /* 31 - StarDOS                         */
10701061   /*
1071   (1) Ocean type 1 includes Navy Seals, Robocop 2 & 3,  Shadow  of
1072   the Beast, Toki, Terminator 2 and more. Both 256 and 128 Kb images.
1073   (2) Dinamic includes Narco Police and more.
1074   (3) Type 29 is reserved for the real Final Cartridge I, the one
1075   above (Type 13) will become Final Cartridge II.               */
1062    (1) Ocean type 1 includes Navy Seals, Robocop 2 & 3,  Shadow  of
1063    the Beast, Toki, Terminator 2 and more. Both 256 and 128 Kb images.
1064    (2) Dinamic includes Narco Police and more.
1065    (3) Type 29 is reserved for the real Final Cartridge I, the one
1066    above (Type 13) will become Final Cartridge II.                 */
10761067   /****************************************
1077   Vice also defines the following types:
1078   #define CARTRIDGE_ACTION_REPLAY3    -29
1079   #define CARTRIDGE_IEEE488           -11
1080   #define CARTRIDGE_IDE64             -7
1081   #define CARTRIDGE_RETRO_REPLAY      -5
1082   #define CARTRIDGE_SUPER_SNAPSHOT    -4
1068    Vice also defines the following types:
1069    #define CARTRIDGE_ACTION_REPLAY3    -29
1070    #define CARTRIDGE_IEEE488           -11
1071    #define CARTRIDGE_IDE64             -7
1072    #define CARTRIDGE_RETRO_REPLAY      -5
1073    #define CARTRIDGE_SUPER_SNAPSHOT    -4
10831074
1084   Can we support these as well?
1085   *****************************************/
1075    Can we support these as well?
1076    *****************************************/
10861077};
10871078
10881079static UINT8 c64_mapper = GENERIC_CRT;
10891080
1090static DEVICE_IMAGE_LOAD(c64_cart)
1081static DEVICE_IMAGE_LOAD( c64_cart )
10911082{
10921083   int size = image_length(image), test, i = 0, n_banks;
10931084   const char *filetype;
r5842r5843
10981089   filetype = image_filetype(image);
10991090
11001091   /* We support .crt files */
1101   if (!mame_stricmp (filetype, "crt"))
1092   if (!mame_stricmp(filetype, "crt"))
11021093   {
11031094      int j;
11041095      unsigned short c64_cart_type;
r5842r5843
11641155
11651156
11661157      /* Data in a .crt image are organized in blocks called 'CHIP':
1167         each 'CHIP' consists of a 0x10 header, which contains the
1168         actual size of the block, the loading address and info on
1169         the bankswitch, followed by the actual data               */
1158           each 'CHIP' consists of a 0x10 header, which contains the
1159           actual size of the block, the loading address and info on
1160           the bankswitch, followed by the actual data                  */
11701161      while (j < size)
11711162      {
11721163         unsigned short chip_size, chip_bank_index, chip_data_size;
r5842r5843
12751266   memset(roml, 0, 0x2000);
12761267   memset(romh, 0, 0x2000);
12771268
1278   switch( c64_mapper )
1269   switch (c64_mapper)
12791270   {
12801271   case ZAXXON:
12811272      memcpy(romh, cart + 0x1000, 0x2000);
r5842r5843
13141305         memcpy(roml, cart + bank * 0x4000, 0x2000);
13151306         memcpy(romh, cart + bank * 0x4000 + 0x2000, 0x2000);
13161307/*
1317         if (log_cart)
1318         {
1319            logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1320            if (c64_cbm_cart[bank].index != bank)
1321               logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1322         }
1308            if (log_cart)
1309            {
1310                logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1311                if (c64_cbm_cart[bank].index != bank)
1312                    logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1313            }
13231314*/
13241315      }
13251316   }
r5842r5843
13461337      memcpy(roml, cart + bank * 0x2000, 0x2000);
13471338   }
13481339/*
1349   if (log_cart)
1350   {
1351      logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1352      if (c64_cbm_cart[bank].index != bank)
1353         logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1354   }
1340    if (log_cart)
1341    {
1342        logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1343        if (c64_cbm_cart[bank].index != bank)
1344            logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1345    }
13551346*/
13561347}
13571348
r5842r5843
13651356   UINT8 *cart = memory_region(space->machine, "cart");
13661357
13671358   /* This should be written after the bankswitch has happened. We log it to see if it is really working */
1368   if (data == 0x86 )
1359   if (data == 0x86)
13691360      logerror("Reserved value written\n");
13701361   else
13711362   {
r5842r5843
13741365
13751366      memcpy(roml, cart + real_bank * 0x2000, 0x2000);
13761367/*
1377      if (log_cart)
1378      {
1379         logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1380         if (c64_cbm_cart[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_cbm_cart[bank].index, bank);
1382      }
1368        if (log_cart)
1369        {
1370            logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1371            if (c64_cbm_cart[bank].index != bank)
1372                logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1373        }
13831374*/
13841375   }
13851376}
r5842r5843
14361427
14371428   memcpy(roml, cart + bank * 0x2000, 0x2000);
14381429/*
1439   if (log_cart)
1440   {
1441      logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1442      if (c64_cbm_cart[bank].index != bank)
1443         logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1444   }
1430    if (log_cart)
1431    {
1432        logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1433        if (c64_cbm_cart[bank].index != bank)
1434            logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1435    }
14451436*/
14461437}
14471438
r5842r5843
14591450
14601451   memcpy(roml, cart + bank * 0x2000, 0x2000);
14611452/*
1462   if (log_cart)
1463   {
1464      logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1465      if (c64_cbm_cart[bank].index != bank)
1466         logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1467   }
1453    if (log_cart)
1454    {
1455        logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1456        if (c64_cbm_cart[bank].index != bank)
1457            logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1458    }
14681459*/
14691460   return 0;
14701461}
r5842r5843
15311522
15321523      memcpy(roml, cart + bank * 0x4000, 0x4000);
15331524/*
1534      if (log_cart)
1535      {
1536         logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1537         if (c64_cbm_cart[bank].index != bank)
1538            logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1539      }
1540*/   
1525        if (log_cart)
1526        {
1527            logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1528            if (c64_cbm_cart[bank].index != bank)
1529                logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1530        }
1531*/
15411532   }
15421533}
15431534
r5842r5843
15451536{
15461537   const address_space *space = cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM );
15471538
1548   switch( c64_mapper )
1539   switch (c64_mapper)
15491540   {
15501541      case ACTION_REPLAY:   /* Type #  1 not working */
15511542         break;
r5842r5843
16051596
16061597MACHINE_RESET( c64 )
16071598{
1608   if(c64_cart_n_banks)
1599   if (c64_cart_n_banks)
16091600      setup_c64_custom_mappers(machine);
16101601}
16111602
16121603
1613MACHINE_DRIVER_START(c64_cartslot)
1604MACHINE_DRIVER_START( c64_cartslot )
16141605   MDRV_CARTSLOT_ADD("cart1")
16151606   MDRV_CARTSLOT_EXTENSION_LIST("crt,80")
16161607   MDRV_CARTSLOT_NOT_MANDATORY
r5842r5843
16261617   MDRV_CARTSLOT_UNLOAD(c64_cart)
16271618MACHINE_DRIVER_END
16281619
1629MACHINE_DRIVER_START(ultimax_cartslot)
1620MACHINE_DRIVER_START( ultimax_cartslot )
16301621   MDRV_CARTSLOT_ADD("cart")
16311622   MDRV_CARTSLOT_EXTENSION_LIST("crt,e0,f0")
16321623   MDRV_CARTSLOT_MANDATORY

Previous 15994 Revisions Next


© 1998-2018 The MESS Team