Previous 15994 Revisions Next

r5915 Tuesday 29th September, 2009 at 16:28:44 UTC by Harmony
Adding mouse movement support to the CD-i driver. The mouse pointer can now be moved. [CD-i Fan, Harmony]
[src/mess/drivers]cdi.c

src/mess/drivers/cdi.c
r5914r5915
5757
5858static UINT16 *planea;
5959static UINT16 *planeb;
60static UINT16 *cdic_ram;
6160
61emu_timer *test_timer;
62
63emu_timer *mouse_timer;
64
6265#define ENABLE_UART_PRINTING (0)
6366
6467#define VERBOSE_LEVEL   (6)
r5914r5915
7679   }
7780}
7881
79/*************************
80* Helpful test functions *
81*************************/
82
83emu_timer *test_timer;
84
85TIMER_CALLBACK( test_timer_callback )
86{
87   // This function manually triggers the SLAVE interrupt request.  Currently, it is the only input trigger that will do anything more than
88   // what the driver does otherwise.
89   static UINT8 stage = 0;
90   if(stage == 0)
91   {
92      stage++;
93      //cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_4, 60);
94      cputag_set_input_line(machine, "maincpu", M68K_IRQ_2, ASSERT_LINE);
95      timer_adjust_oneshot(test_timer, ATTOTIME_IN_HZ(10000), 0);
96   }
97   else
98   {
99      cputag_set_input_line(machine, "maincpu", M68K_IRQ_2, CLEAR_LINE);
100      stage = 0;
101   }
102}
103
10482/***********************
10583* On-board peripherals *
10684***********************/
r5914r5915
380358         {
381359            verboselog(space->machine, 2, "scc68070_periphs_r: UART Mode Register: %04x & %04x\n", scc68070_regs.uart.mode_register, mem_mask);
382360         }
383         return scc68070_regs.uart.mode_register;
361         return scc68070_regs.uart.mode_register | 0x20;
384362      case 0x2012/2:
385363         if(ACCESSING_BITS_0_7)
386364         {
387365            verboselog(space->machine, 2, "scc68070_periphs_r: UART Status Register: %04x & %04x\n", scc68070_regs.uart.status_register, mem_mask);
388366         }
389         return scc68070_regs.uart.status_register | USR_TXRDY | USR_RXRDY;
367         return scc68070_regs.uart.status_register /*| USR_TXEMT*/ | USR_TXRDY | (1 << 1) | USR_RXRDY;
390368      case 0x2014/2:
391369         if(ACCESSING_BITS_0_7)
392370         {
393371            verboselog(space->machine, 2, "scc68070_periphs_r: UART Clock Select: %04x & %04x\n", scc68070_regs.uart.clock_select, mem_mask);
394372         }
395         return scc68070_regs.uart.clock_select;
373         return scc68070_regs.uart.clock_select | 0x08;
396374      case 0x2016/2:
397375         if(ACCESSING_BITS_0_7)
398376         {
399377            verboselog(space->machine, 2, "scc68070_periphs_r: UART Command Register: %02x & %04x\n", scc68070_regs.uart.command_register, mem_mask);
400378         }
401         return scc68070_regs.uart.command_register;
379         return scc68070_regs.uart.command_register | 0x80;
402380      case 0x2018/2:
403381         if(ACCESSING_BITS_0_7)
404382         {
r5914r5915
409387         if(ACCESSING_BITS_0_7)
410388         {
411389            verboselog(space->machine, 2, "scc68070_periphs_r: UART Receive Holding Register: %02x & %04x\n", scc68070_regs.uart.receive_holding_register, mem_mask);
390            return scc68070_regs.uart.receive_holding_register;
412391         }
413         return scc68070_regs.uart.receive_holding_register;
392         return 0;
414393
415394      // Timers: 80002020 to 80002029
416395      case 0x2020/2:
r5914r5915
659638      case 0x2018/2:
660639         if(ACCESSING_BITS_0_7)
661640         {
662            verboselog(space->machine, 2, "scc68070_periphs_w: UART Transmit Holding Register: %04x & %04x\n", data, mem_mask);
663            if(data >= 0x20 && data < 0x7f)
641            verboselog(space->machine, 2, "scc68070_periphs_w: UART Transmit Holding Register: %04x & %04x: %c\n", data, mem_mask, (data >= 0x20 && data < 0x7f) ? (data & 0x00ff) : ' ');
642            if((data >= 0x20 && data < 0x7f) || data == 0x08)
664643            {
665644               printf( "%c", data & 0x00ff );
666645            }
646            if(data == 0x0d)
647            {
648               printf( "\n" );
649            }
667650            scc68070_regs.uart.transmit_holding_register = data & 0x00ff;
668651         }
669652         break;
r5914r5915
869852   }
870853}
871854
855#if ENABLE_UART_PRINTING
856static READ16_HANDLER( uart_loopback_enable )
857{
858   return 0x1234;
859}
860#endif
861
862typedef struct
863{
864   UINT16 unknown0x3ffa;
865} cdic_regs_t;
866
867cdic_regs_t cdic_regs;
868
872869static READ16_HANDLER( cdic_r )
873870{
871   offset += 0x3c80/2;
874872   verboselog(space->machine, 0, "cdic_r: UNIMPLEMENTED: Unknown address: %04x & %04x\n", offset*2, mem_mask);
875   if(offset == 0x1400/2 || offset == 0x1402/2)
873   switch(offset)
876874   {
877   #if ENABLE_UART_PRINTING
878      return 0x1234;
879   #endif
875      case 0x3ffa/2:
876         return 0xd7fe;
877      default:
878         return 0;
880879   }
881   if(offset == 0x3ff6/2)
882   {
883      //return 0x8000;
884   }
885   if(offset == 0x3ffe/2)
886   {
887      //return 0x8000;
888   }
889   return cdic_ram[offset];
890880}
891881
892882static WRITE16_HANDLER( cdic_w )
893883{
884   offset += 0x3c80/2;
894885   verboselog(space->machine, 0, "cdic_w: UNIMPLEMENTED: Unknown address: %04x = %04x & %04x\n", offset*2, data, mem_mask);
895   //COMBINE_DATA(&cdic_ram[offset]);
896886}
897887
898888UINT8 slave_register;
r5914r5915
900890
901891static READ16_HANDLER( slave_r )
902892{
903   static UINT32 read_count = 0;
904893   static UINT32 return_count = 0;
905894   verboselog(space->machine, 0, "slave_r: UNIMPLEMENTED: Unknown address: %04x & %04x\n", offset*2, mem_mask);
906895   if(offset == 0x00)
r5914r5915
908897      switch(slave_register)
909898      {
910899         case 0xf7:
911            switch(read_count)
900         {
901            static UINT16 x = 0;
902            static UINT16 y = 0;
903            static UINT8 bytes[4] = { 0, 0, 0, 0 };
904            return_count %= 4;
905            if(return_count == 0)
912906            {
913               case 0:
914                  switch(return_count)
915                  {
916                     case 0:
917                     case 1:
918                     case 2:
919                     case 3:
920                        return_count++;
921                        if(return_count == 4)
922                        {
923                           read_count++;
924                           return_count = 0;
925                        }
926                        return 0;
927                  }
928                  break;
929               case 1:
930                  switch(return_count)
931                  {
932                     case 0:
933                        return_count++;
934                        return 0x35;
935                     case 1:
936                        return_count++;
937                        return 0x0d;
938                     case 2:
939                        return_count++;
940                        return 0x03;
941                     case 3:
942                        return_count = 0;
943                        read_count = 0;
944                        return 0x70;
945                  }
946                  break;
947               default:
948                  return 0;
949                  break;
907               x = input_port_read(space->machine, "MOUSEX");
908               y = input_port_read(space->machine, "MOUSEY");
909               bytes[0] = (x & 0x380) >> 7;
910               bytes[1] = x & 0x7f;
911               bytes[2] = (y & 0x380) >> 7;
912               bytes[3] = y & 0x7f;
950913            }
951            break;
914            return bytes[return_count++];
915         }
952916         default:
953917            break;
954918      }
955919      return 0x0000;
956920   }
957   if(offset == 0x02)
921   else if(offset == 0x02)
958922   {
959923      if(slave_read_index == 0)
960924      {
r5914r5915
973937         }
974938      }
975939   }
940   else if(offset == 0x03)
941   {
942      switch(slave_register)
943      {
944         case 0xfa:
945            switch(slave_read_index)
946            {
947               case 0:
948                  slave_read_index++;
949                  return 0xa4;
950               case 1:
951                  slave_read_index++;
952                  return 0x7a;
953               case 2:
954                  slave_read_index++;
955                  return 0x3b;
956               case 3:
957                  slave_read_index++;
958                  if(slave_read_index == 4)
959                  {
960                     slave_read_index = 0;
961                  }
962                  return 0x1c;
963               default:
964                  return 0;
965            }
966            break;
967         default:
968            break;
969      }
970      return 0x0000;
971   }
976972   return 0;
977973}
978974
979975static WRITE16_HANDLER( slave_w )
980976{
981977   verboselog(space->machine, 0, "slave_w: UNIMPLEMENTED: Unknown address: %04x = %04x & %04x\n", offset*2, data, mem_mask);
978   if(offset == 0x00)
979   {
980      if(ACCESSING_BITS_0_7)
981      {
982         //if((data & 0x00ff) == 0xe3)
983         //{
984            //slave_register = 0xf7;
985            //slave_read_index = 0;
986            //timer_adjust_oneshot(test_timer, ATTOTIME_IN_HZ(1), 0);
987         //}
988      }
989   }
982990   if(offset == 0x03)
983991   {
984992      if(ACCESSING_BITS_0_7)
985993      {
986994         slave_register = data & 0x00ff;
987995         slave_read_index = 0;
988         if(slave_register == 0xf7)
996         if(slave_register == 0xf7)   // Activate input polling?
989997         {
990            timer_adjust_oneshot(test_timer, ATTOTIME_IN_HZ(10000), 0);
998            timer_adjust_oneshot(mouse_timer, ATTOTIME_IN_HZ(60), 0);
991999         }
9921000      }
9931001   }
r5914r5915
10031011
10041012static READ16_HANDLER( m48t08_r )
10051013{
1006   verboselog(space->machine, 4, "m48t08_r: %04x = %02x & %04x\n", offset, m48t08.nvram[offset], mem_mask );
1014   verboselog(space->machine, 11, "m48t08_r: %04x = %02x & %04x\n", offset, m48t08.nvram[offset], mem_mask );
10071015   return m48t08.nvram[offset] << 8;
10081016}
10091017
10101018static WRITE16_HANDLER( m48t08_w )
10111019{
1012   verboselog(space->machine, 4, "m48t08_w: %04x = %02x\n", offset, data >> 8);
1020   verboselog(space->machine, 11, "m48t08_w: %04x = %02x\n", offset, data >> 8);
10131021   switch(offset)
10141022   {
10151023      case 0x1ff9:
r5914r5915
10731081   UINT16 ddr;
10741082   UINT16 dcp;
10751083   UINT32 clut[256];
1076   UINT8 image_coding_method;
1077   UINT8 transparency_control;
1078   UINT8 plane_order;
1079   UINT8 clut_bank;
1080   UINT8 transparent_color_a;
1081   UINT8 reserved0;
1082   UINT8 transparent_color_b;
1083   UINT8 mask_color_a;
1084   UINT8 reserved1;
1085   UINT8 mask_color_b;
1086   UINT8 dyuv_abs_start_a;
1087   UINT8 dyuv_abs_start_b;
1088   UINT8 reserved2;
1089   UINT8 cursor_position;
1090   UINT8 cursor_control;
1091   UINT8 cursor_pattern[16];
1092   UINT8 region_control[8];
1093   UINT8 backdrop_color;
1094   UINT8 mosaic_hold_a;
1095   UINT8 mosaic_hold_b;
1096   UINT8 weight_factor_a;
1097   UINT8 weight_factor_b;
1084   UINT32 image_coding_method;
1085   UINT32 transparency_control;
1086   UINT32 plane_order;
1087   UINT32 clut_bank;
1088   UINT32 transparent_color_a;
1089   UINT32 reserved0;
1090   UINT32 transparent_color_b;
1091   UINT32 mask_color_a;
1092   UINT32 reserved1;
1093   UINT32 mask_color_b;
1094   UINT32 dyuv_abs_start_a;
1095   UINT32 dyuv_abs_start_b;
1096   UINT32 reserved2;
1097   UINT32 cursor_position;
1098   UINT32 cursor_control;
1099   UINT32 cursor_pattern[16];
1100   UINT32 region_control[8];
1101   UINT32 backdrop_color;
1102   UINT32 mosaic_hold_a;
1103   UINT32 mosaic_hold_b;
1104   UINT32 weight_factor_a;
1105   UINT32 weight_factor_b;
10981106} mcd212_channel_t;
10991107
11001108typedef struct
r5914r5915
11051113
11061114mcd212_t mcd212;
11071115
1116#define MCD212_CURCNT_COLOR      0x00000f   // Cursor color
1117#define MCD212_CURCNT_CUW      0x008000   // Cursor width
1118#define MCD212_CURCNT_COF      0x070000   // Cursor off time
1119#define MCD212_CURCNT_COF_SHIFT   16
1120#define MCD212_CURCNT_CON      0x280000   // Cursor on time
1121#define MCD212_CURCNT_CON_SHIFT   19
1122#define MCD212_CURCNT_BLKC      0x400000   // Blink type
1123#define MCD212_CURCNT_EN      0x800000   // Cursor enable
1124
11081125#define MCD212_CSR2R_IT1      0x0004   // Interrupt 1
11091126#define MCD212_CSR2R_IT2      0x0002   // Interrupt 2
11101127#define MCD212_CSR2R_BE         0x0001   // Bus Error
r5914r5915
11321149      case 0x10/2:
11331150         if(ACCESSING_BITS_0_7)
11341151         {
1135            verboselog(space->machine, 2, "mcd212_r: Status Register %d: %02x & %04x\n", channel + 1, mcd212.channel[1 - (offset / 8)].csrr, mem_mask);
1152            verboselog(space->machine, 11, "mcd212_r: Status Register %d: %02x & %04x\n", channel + 1, mcd212.channel[1 - (offset / 8)].csrr, mem_mask);
11361153            if(channel == 0)
11371154            {
11381155               return mcd212.channel[0].csrr | 0x20;
r5914r5915
13071324      case 0xcd: // Cursor Position
13081325         if(channel == 0)
13091326         {
1310            verboselog(machine, 11, "          %04xxxxx: %d: Cursor Position = %08x\n", channel * 0x20, channel, value );
1327            verboselog(machine, 6, "          %04xxxxx: %d: Cursor Position = %08x\n", channel * 0x20, channel, value );
13111328            mcd212.channel[channel].cursor_position = value;
13121329         }
13131330         break;
r5914r5915
17431760   //mcd212_set_vsr(channel, vsr);
17441761}
17451762
1763static void mcd212_draw_cursor(running_machine *machine, UINT32 *scanline, int y)
1764{
1765   if(mcd212.channel[0].cursor_control & MCD212_CURCNT_EN)
1766   {
1767      UINT16 curx = mcd212.channel[0].cursor_position & 0x3ff;
1768      UINT16 cury = (mcd212.channel[0].cursor_position >> 12) & 0x3ff;
1769      UINT32 x = 0;
1770      cury += 22;
1771      if(y >= cury && y < (cury + 16))
1772      {
1773         UINT32 color = 0;
1774         switch(mcd212.channel[0].cursor_control & MCD212_CURCNT_COLOR)
1775         {
1776            case 0x01:
1777               color = 0x0000007f;
1778               break;
1779            case 0x02:
1780               color = 0x00007f00;
1781               break;
1782            case 0x03:
1783               color = 0x00007f7f;
1784               break;
1785            case 0x04:
1786               color = 0x007f0000;
1787               break;
1788            case 0x05:
1789               color = 0x007f007f;
1790               break;
1791            case 0x06:
1792               color = 0x007f7f00;
1793               break;
1794            case 0x07:
1795               color = 0x007f7f7f;
1796               break;
1797            case 0x09:
1798               color = 0x000000ff;
1799               break;
1800            case 0x0a:
1801               color = 0x0000ff00;
1802               break;
1803            case 0x0b:
1804               color = 0x0000ffff;
1805               break;
1806            case 0x0c:
1807               color = 0x00ff0000;
1808               break;
1809            case 0x0d:
1810               color = 0x00ff00ff;
1811               break;
1812            case 0x0e:
1813               color = 0x00ffff00;
1814               break;
1815            case 0x0f:
1816               color = 0x00ffffff;
1817               break;
1818         }
1819         y -= cury;
1820         for(x = curx; x < curx + 16; x++)
1821         {
1822            if(mcd212.channel[0].cursor_pattern[y] & (1 << (15 - (x - curx))))
1823            {
1824               scanline[x] = color;
1825            }
1826            else
1827            {
1828            }
1829         }
1830      }
1831   }
1832}
1833
17461834static void mcd212_draw_scanline(running_machine *machine, int y)
17471835{
17481836   bitmap_t *bitmap = tmpbitmap;
r5914r5915
17501838   UINT32 plane_b[768];
17511839   UINT32 *scanline = BITMAP_ADDR32(bitmap, y, 0);
17521840   int x;
1753   //prinf( "y=%d, m
17541841   mcd212_process_vsr(machine, 0, plane_a);
17551842   mcd212_process_vsr(machine, 1, plane_b);
17561843   for(x = 0; x < 768; x++)
17571844   {
17581845      scanline[x] = plane_a[x];
17591846   }
1847   mcd212_draw_cursor(machine, scanline, y);
17601848}
17611849
17621850TIMER_CALLBACK( mcd212_perform_scan )
r5914r5915
18071895   timer_adjust_oneshot(mcd212.scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0);
18081896}
18091897
1898TIMER_CALLBACK( test_timer_callback )
1899{
1900   // This function manually triggers interrupt requests as a test.
1901   static UINT8 set = 0;
1902   if(set == 0)
1903   {
1904      set = 1;
1905      cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_2, 26);
1906      cputag_set_input_line(machine, "maincpu", M68K_IRQ_2, ASSERT_LINE);
1907      timer_adjust_oneshot(test_timer, ATTOTIME_IN_HZ(10000), 0);
1908   }
1909   else
1910   {
1911      set = 0;
1912      cputag_set_input_line(machine, "maincpu", M68K_IRQ_2, CLEAR_LINE);
1913      timer_adjust_oneshot(test_timer, ATTOTIME_IN_HZ(60), 0);
1914   }
1915}
1916
18101917/*************************
1918*    Input functions     *
1919*************************/
1920
1921TIMER_CALLBACK( mouse_callback )
1922{
1923   static UINT8 set = 0;
1924   if(set == 0)
1925   {
1926      set = 1;
1927      cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_2, 26);
1928      cputag_set_input_line(machine, "maincpu", M68K_IRQ_2, ASSERT_LINE);
1929      timer_adjust_oneshot(mouse_timer, ATTOTIME_IN_HZ(10000), 0);
1930      slave_register = 0xf7;
1931   }
1932   else
1933   {
1934      set = 0;
1935      cputag_set_input_line(machine, "maincpu", M68K_IRQ_2, CLEAR_LINE);
1936      timer_adjust_oneshot(mouse_timer, ATTOTIME_IN_HZ(60), 0);
1937   }
1938}
1939
1940/*************************
18111941*      Memory maps       *
18121942*************************/
18131943
18141944static ADDRESS_MAP_START( cdi_mem, ADDRESS_SPACE_PROGRAM, 16 )
18151945   AM_RANGE(0x00000000, 0x0007ffff) AM_RAM AM_BASE(&planea)
18161946   AM_RANGE(0x00200000, 0x0027ffff) AM_RAM AM_BASE(&planeb)
1817   AM_RANGE(0x00300000, 0x00303fff) AM_READWRITE(cdic_r, cdic_w) AM_BASE(&cdic_ram)
1947#if ENABLE_UART_PRINTING
1948   AM_RANGE(0x00301400, 0x00301403) AM_READ(uart_loopback_enable)
1949   AM_RANGE(0x00301404, 0x00303c7f) AM_RAM
1950#else
1951   AM_RANGE(0x00301400, 0x00303c7f) AM_RAM
1952#endif
1953   AM_RANGE(0x00303c80, 0x00303fff) AM_READWRITE(cdic_r, cdic_w)
18181954   AM_RANGE(0x00310000, 0x00317fff) AM_READWRITE(slave_r, slave_w)
18191955   //AM_RANGE(0x00318000, 0x0031ffff) AM_NOP
18201956   AM_RANGE(0x00320000, 0x00323fff) AM_READWRITE(m48t08_r, m48t08_w)
r5914r5915
18301966*************************/
18311967
18321968static INPUT_PORTS_START( cdi )
1969   PORT_START("MOUSEX")
1970   PORT_BIT(0x3ff, 0x000, IPT_MOUSE_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0)
1971
1972   PORT_START("MOUSEY")
1973   PORT_BIT(0x3ff, 0x000, IPT_MOUSE_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0)
18331974INPUT_PORTS_END
18341975
18351976static MACHINE_RESET( cdi )
r5914r5915
18481989   test_timer = timer_alloc(machine, test_timer_callback, 0);
18491990   timer_adjust_oneshot(test_timer, attotime_never, 0);
18501991
1992   mouse_timer = timer_alloc(machine, mouse_callback, 0);
1993   timer_adjust_oneshot(mouse_timer, attotime_never, 0);
1994
18511995   device_reset(cputag_get_cpu(machine, "maincpu"));
18521996}
18531997
r5914r5915
19062050*************************/
19072051
19082052/*    YEAR  NAME        PARENT  COMPAT  MACHINE     INPUT   INIT    CONFIG  COMPANY     FULLNAME   FLAGS */
1909CONS( 1991, cdi,        0,      0,      cdi,        0,      0,      0,      "Philips",  "CD-i",   GAME_NO_SOUND | GAME_NOT_WORKING )
2053CONS( 1991, cdi,        0,      0,      cdi,        cdi,    0,      0,      "Philips",  "CD-i",   GAME_NO_SOUND | GAME_NOT_WORKING )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team