Previous 15994 Revisions Next

r7618 Monday 22nd March, 2010 at 07:13:28 UTC by Barry Rodewald
[FMTOWNS] Added preliminary mouse support (joystick port 1 only for now)
[src/mess/drivers]fmtowns.c

src/mess/drivers/fmtowns.c
r7617r7618
127127#define TOWNS_CD_IRQ_MPU 1
128128#define TOWNS_CD_IRQ_DMA 2
129129
130enum
131{
132   MOUSE_START,
133   MOUSE_SYNC,
134   MOUSE_X_HIGH,
135   MOUSE_X_LOW,
136   MOUSE_Y_HIGH,
137   MOUSE_Y_LOW
138};
139
130140static UINT8 ftimer;
131141static UINT8 nmi_mask;
132142static UINT8 compat_mode;
r7617r7618
156166static UINT8 towns_kb_output;  // key output
157167static UINT8 towns_kb_extend;  // extended key output
158168static emu_timer* towns_kb_timer;
169static emu_timer* towns_mouse_timer;
159170static UINT8 towns_fm_irq_flag;
160171static UINT8 towns_pcm_irq_flag;
161172static UINT8 towns_pcm_channel_flag;
162173static UINT8 towns_pcm_channel_mask;
163174static UINT8 towns_pad_mask;
175static UINT8 towns_mouse_output;
176static UINT8 towns_mouse_x;
177static UINT8 towns_mouse_y;
164178
165179static struct towns_cdrom_controller
166180{
r7617r7618
748762
749763// Controller ports
750764// Joysticks are multiplexed, with fire buttons available when bits 0 and 1 of port 0x4d6 are high. (bits 2 and 3 for second port?)
765static TIMER_CALLBACK(towns_mouse_timeout)
766{
767   towns_mouse_output = MOUSE_START;  // reset mouse data
768}
769
751770static READ32_HANDLER(towns_padport_r)
752771{
753772   UINT32 ret = 0;
754   UINT8 extra1 = input_port_read(space->machine,"joy1_ex");
755   UINT8 extra2 = input_port_read(space->machine,"joy2_ex");
773   UINT32 porttype = input_port_read(space->machine,"ctrltype");
774   UINT8 extra1;
775   UINT8 extra2;
776   UINT32 state;
756777
757   if(towns_pad_mask & 0x10)
758      ret |= (input_port_read(space->machine,"joy1") & 0x3f) | 0x00000040;
759   else
760      ret |= (input_port_read(space->machine,"joy1") & 0x0f) | 0x00000030;
778   if((porttype & 0x0f) == 0x00)
779      ret |= 0x000000ff;
780   if((porttype & 0xf0) == 0x00)
781      ret |= 0x00ff0000;
782   if((porttype & 0x0f) == 0x01)
783   {
784      extra1 = input_port_read(space->machine,"joy1_ex");
785   
786      if(towns_pad_mask & 0x10)
787         ret |= (input_port_read(space->machine,"joy1") & 0x3f) | 0x00000040;
788      else
789         ret |= (input_port_read(space->machine,"joy1") & 0x0f) | 0x00000030;
790   
791      if(extra1 & 0x01) // Run button = left+right
792         ret &= ~0x0000000c;
793      if(extra1 & 0x02) // Select button = up+down
794         ret &= ~0x00000003;
795   
796      if((extra1 & 0x10) && (towns_pad_mask & 0x01))
797         ret &= ~0x00000010;
798      if((extra1 & 0x20) && (towns_pad_mask & 0x02))
799         ret &= ~0x00000020;
800   }
801   if((porttype & 0xf0) == 0x10)
802   {
803      extra2 = input_port_read(space->machine,"joy2_ex");
761804
762   if(towns_pad_mask & 0x20)
763      ret |= ((input_port_read(space->machine,"joy2") & 0x3f) << 16) | 0x00400000;
764   else
765      ret |= ((input_port_read(space->machine,"joy2") & 0x0f) << 16) | 0x00300000;
805      if(towns_pad_mask & 0x20)
806         ret |= ((input_port_read(space->machine,"joy2") & 0x3f) << 16) | 0x00400000;
807      else
808         ret |= ((input_port_read(space->machine,"joy2") & 0x0f) << 16) | 0x00300000;
809   
810      if(extra2 & 0x01)
811         ret &= ~0x000c0000;
812      if(extra2 & 0x02)
813         ret &= ~0x00030000;
766814
767   if(extra1 & 0x01) // Run button = left+right
768      ret &= ~0x0000000c;
769   if(extra2 & 0x01)
770      ret &= ~0x000c0000;
771   if(extra1 & 0x02) // Select button = up+down
772      ret &= ~0x00000003;
773   if(extra2 & 0x02)
774      ret &= ~0x00030000;
775
776   if((extra1 & 0x10) && (towns_pad_mask & 0x01))
777      ret &= ~0x00000010;
778   if((extra1 & 0x20) && (towns_pad_mask & 0x02))
779      ret &= ~0x00000020;
780   if((extra2 & 0x10) && (towns_pad_mask & 0x04))
781      ret &= ~0x00100000;
782   if((extra2 & 0x20) && (towns_pad_mask & 0x08))
783      ret &= ~0x00200000;
784
815      if((extra2 & 0x10) && (towns_pad_mask & 0x04))
816         ret &= ~0x00100000;
817      if((extra2 & 0x20) && (towns_pad_mask & 0x08))
818         ret &= ~0x00200000;
819   }
820   if((porttype & 0x0f) == 0x02)  // mouse
821   {
822      switch(towns_mouse_output)
823      {
824         case MOUSE_X_HIGH:
825            ret |= ((towns_mouse_x & 0xf0) >> 4);
826            break;
827         case MOUSE_X_LOW:
828            ret |= (towns_mouse_x & 0x0f);
829            break;
830         case MOUSE_Y_HIGH:
831            ret |= ((towns_mouse_y & 0xf0) >> 4);
832            break;
833         case MOUSE_Y_LOW:
834            ret |= (towns_mouse_y & 0x0f);
835            break;
836         case MOUSE_START:
837         case MOUSE_SYNC:
838         default:
839            if(towns_mouse_output < MOUSE_Y_LOW)
840               ret |= 0x0000000f;
841      }
842     
843      //logerror("Mouse: X=%02x Y=%02x state=%i\n",towns_mouse_x,towns_mouse_y,towns_mouse_output);
844      // button states are always visible
845      state = input_port_read(space->machine,"mouse1");
846      if(!(state & 0x01))
847         ret |= 0x00000010;
848      if(!(state & 0x02))
849         ret |= 0x00000020;
850      if(towns_pad_mask & 0x10)
851         ret |= 0x00000040;
852   }
853   
785854   return ret;
786855}
787856
788857static WRITE32_HANDLER(towns_pad_mask_w)
789858{
859   static UINT8 prev;
860   static UINT8 prev_x,prev_y;
861   UINT8 current_x,current_y;
862   
790863   if(ACCESSING_BITS_16_23)
864   {
791865      towns_pad_mask = (data & 0x00ff0000) >> 16;
866      if((input_port_read(space->machine,"ctrltype") & 0x0f) == 0x02)  // mouse
867      {
868         if((towns_pad_mask & 0x10) != 0 && (prev & 0x10) == 0)
869         {
870            if(towns_mouse_output == MOUSE_START)
871            {
872               towns_mouse_output = MOUSE_X_HIGH;
873               current_x = input_port_read(space->machine,"mouse2");
874               current_y = input_port_read(space->machine,"mouse3");
875               towns_mouse_x = prev_x - current_x;
876               towns_mouse_y = prev_y - current_y;
877               prev_x = current_x;
878               prev_y = current_y;
879            }
880            else
881               towns_mouse_output++;
882            timer_adjust_periodic(towns_mouse_timer,ATTOTIME_IN_USEC(600),0,attotime_zero);
883         }
884         if((towns_pad_mask & 0x10) == 0 && (prev & 0x10) != 0)
885         {
886            if(towns_mouse_output == MOUSE_START)
887            {
888               towns_mouse_output = MOUSE_SYNC;
889               current_x = input_port_read(space->machine,"mouse2");
890               current_y = input_port_read(space->machine,"mouse3");
891               towns_mouse_x = prev_x - current_x;
892               towns_mouse_y = prev_y - current_y;
893               prev_x = current_x;
894               prev_y = current_y;
895            }
896            else
897               towns_mouse_output++;
898            timer_adjust_periodic(towns_mouse_timer,ATTOTIME_IN_USEC(600),0,attotime_zero);
899         }
900         prev = towns_pad_mask;
901      }
902   }
792903}
793904
794905static READ8_HANDLER( towns_cmos8_r )
r7617r7618
17471858
17481859/* Input ports */
17491860static INPUT_PORTS_START( towns )
1861  PORT_START("ctrltype")
1862    PORT_CATEGORY_CLASS(0x0f,0x01,"Joystick port 1")
1863    PORT_CATEGORY_ITEM(0x00,"Nothing",10)
1864    PORT_CATEGORY_ITEM(0x01,"Standard 2-button joystick",11)
1865    PORT_CATEGORY_ITEM(0x02,"Mouse",12)
1866    PORT_CATEGORY_CLASS(0xf0,0x10,"Joystick port 2")
1867    PORT_CATEGORY_ITEM(0x00,"Nothing",20)
1868    PORT_CATEGORY_ITEM(0x10,"Standard 2-button joystick",21)
1869
17501870// Keyboard
17511871  PORT_START( "key1" )  // scancodes 0x00-0x1f
17521872    PORT_BIT(0x00000001,IP_ACTIVE_HIGH,IPT_UNUSED)
r7617r7618
18832003    PORT_BIT(0x20000000,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_NAME("COPY")
18842004
18852005  PORT_START("joy1")
1886    PORT_BIT(0x00000001,IP_ACTIVE_LOW, IPT_JOYSTICK_UP) PORT_PLAYER(1)
1887    PORT_BIT(0x00000002,IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN) PORT_PLAYER(1)
1888    PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT) PORT_PLAYER(1)
1889    PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) PORT_PLAYER(1)
1890    PORT_BIT(0x00000010,IP_ACTIVE_LOW, IPT_UNUSED)
1891    PORT_BIT(0x00000020,IP_ACTIVE_LOW, IPT_UNUSED)
1892    PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED)
1893    PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED)
2006    PORT_BIT(0x00000001,IP_ACTIVE_LOW, IPT_JOYSTICK_UP) PORT_PLAYER(1) PORT_CATEGORY(11)
2007    PORT_BIT(0x00000002,IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN) PORT_PLAYER(1) PORT_CATEGORY(11)
2008    PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT) PORT_PLAYER(1) PORT_CATEGORY(11)
2009    PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) PORT_PLAYER(1) PORT_CATEGORY(11)
2010    PORT_BIT(0x00000010,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(11)
2011    PORT_BIT(0x00000020,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(11)
2012    PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(11)
2013    PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(11)
18942014
18952015  PORT_START("joy1_ex")
1896    PORT_BIT(0x00000001,IP_ACTIVE_HIGH, IPT_START) PORT_NAME("1P Run") PORT_PLAYER(1)
1897    PORT_BIT(0x00000002,IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("1P Select") PORT_PLAYER(1)
1898    PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_UNUSED)
1899    PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_UNUSED)
1900    PORT_BIT(0x00000010,IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_PLAYER(1)
1901    PORT_BIT(0x00000020,IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_PLAYER(1)
1902    PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED)
1903    PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED)
2016    PORT_BIT(0x00000001,IP_ACTIVE_HIGH, IPT_START) PORT_NAME("1P Run") PORT_PLAYER(1) PORT_CATEGORY(11)
2017    PORT_BIT(0x00000002,IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("1P Select") PORT_PLAYER(1) PORT_CATEGORY(11)
2018    PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(11)
2019    PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(11)
2020    PORT_BIT(0x00000010,IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_PLAYER(1) PORT_CATEGORY(11)
2021    PORT_BIT(0x00000020,IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_PLAYER(1) PORT_CATEGORY(11)
2022    PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(11)
2023    PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(11)
19042024
19052025  PORT_START("joy2")
1906    PORT_BIT(0x00000001,IP_ACTIVE_LOW, IPT_JOYSTICK_UP) PORT_PLAYER(2)
1907    PORT_BIT(0x00000002,IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN) PORT_PLAYER(2)
1908    PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT) PORT_PLAYER(2)
1909    PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) PORT_PLAYER(2)
1910    PORT_BIT(0x00000010,IP_ACTIVE_LOW, IPT_UNUSED)
1911    PORT_BIT(0x00000020,IP_ACTIVE_LOW, IPT_UNUSED)
1912    PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED)
1913    PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED)
2026    PORT_BIT(0x00000001,IP_ACTIVE_LOW, IPT_JOYSTICK_UP) PORT_PLAYER(2) PORT_CATEGORY(21)
2027    PORT_BIT(0x00000002,IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN) PORT_PLAYER(2) PORT_CATEGORY(21)
2028    PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT) PORT_PLAYER(2) PORT_CATEGORY(21)
2029    PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) PORT_PLAYER(2) PORT_CATEGORY(21)
2030    PORT_BIT(0x00000010,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(21)
2031    PORT_BIT(0x00000020,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(21)
2032    PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(21)
2033    PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(21)
19142034
19152035  PORT_START("joy2_ex")
1916    PORT_BIT(0x00000001,IP_ACTIVE_HIGH, IPT_START) PORT_NAME("2P Run") PORT_PLAYER(2)
1917    PORT_BIT(0x00000002,IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("2P Select") PORT_PLAYER(2)
1918    PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_UNUSED)
1919    PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_UNUSED)
1920    PORT_BIT(0x00000010,IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_PLAYER(2)
1921    PORT_BIT(0x00000020,IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_PLAYER(2)
1922    PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED)
1923    PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED)
2036    PORT_BIT(0x00000001,IP_ACTIVE_HIGH, IPT_START) PORT_NAME("2P Run") PORT_PLAYER(2) PORT_CATEGORY(21)
2037    PORT_BIT(0x00000002,IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("2P Select") PORT_PLAYER(2) PORT_CATEGORY(21)
2038    PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(21)
2039    PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(21)
2040    PORT_BIT(0x00000010,IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_PLAYER(2) PORT_CATEGORY(21)
2041    PORT_BIT(0x00000020,IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_PLAYER(2) PORT_CATEGORY(21)
2042    PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(21)
2043    PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(21)
2044   
2045  PORT_START("mouse1")  // buttons
2046     PORT_BIT( 0x00000001, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Left mouse button") PORT_CODE(MOUSECODE_BUTTON1) PORT_CATEGORY(12)
2047   PORT_BIT( 0x00000002, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Right mouse button") PORT_CODE(MOUSECODE_BUTTON2) PORT_CATEGORY(12)
2048     
2049  PORT_START("mouse2")  // X-axis
2050   PORT_BIT( 0xff, 0x00, IPT_MOUSE_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_CATEGORY(12)
2051
2052  PORT_START("mouse3")  // Y-axis
2053   PORT_BIT( 0xff, 0x00, IPT_MOUSE_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_CATEGORY(12)
2054
19242055INPUT_PORTS_END
19252056
19262057static INPUT_PORTS_START( marty )
r7617r7618
19482079   towns_init_rtc();
19492080   towns_rtc_timer = timer_alloc(machine,rtc_second,NULL);
19502081   towns_kb_timer = timer_alloc(machine,poll_keyboard,NULL);
2082   towns_mouse_timer = timer_alloc(machine,towns_mouse_timeout,NULL);
19512083
19522084   // CD-ROM init
19532085   towns_cd.read_timer = timer_alloc(machine,towns_cdrom_read_byte,(void*)devtag_get_device(machine,"dma_1"));
r7617r7618
19732105   towns_kb_status = 0x18;
19742106   towns_kb_irq1_enable = 0;
19752107   towns_pad_mask = 0x7f;
2108   towns_mouse_output = MOUSE_START;
19762109   towns_cd.status = 0x01;  // CDROM controller ready
19772110   towns_cd.buffer_ptr = -1;
19782111   timer_adjust_periodic(towns_rtc_timer,attotime_zero,0,ATTOTIME_IN_HZ(1));

Previous 15994 Revisions Next


© 1998-2018 The MESS Team