Previous 199869 Revisions Next

r20449 Thursday 24th January, 2013 at 19:46:15 UTC by Wilbert Pol
(MESS) wswan.c: Some small cleanups and tag lookup reduction. (nw)
[src/mess/includes]wswan.h
[src/mess/machine]wswan.c

trunk/src/mess/machine/wswan.c
r20448r20449
8383   0xea, 0xc0, 0xff, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8484};
8585
86static void wswan_handle_irqs( running_machine &machine )
86void wswan_state::wswan_handle_irqs()
8787{
88   wswan_state *state = machine.driver_data<wswan_state>();
89   if ( state->m_ws_portram[0xb2] & state->m_ws_portram[0xb6] & WSWAN_IFLAG_HBLTMR ) {
90      machine.device("maincpu")->execute().set_input_line_and_vector(0, HOLD_LINE, state->m_ws_portram[0xb0] + WSWAN_INT_HBLTMR );
91   } else if ( state->m_ws_portram[0xb2] & state->m_ws_portram[0xb6] & WSWAN_IFLAG_VBL ) {
92      machine.device("maincpu")->execute().set_input_line_and_vector(0, HOLD_LINE, state->m_ws_portram[0xb0] + WSWAN_INT_VBL );
93   } else if ( state->m_ws_portram[0xb2] & state->m_ws_portram[0xb6] & WSWAN_IFLAG_VBLTMR ) {
94      machine.device("maincpu")->execute().set_input_line_and_vector(0, HOLD_LINE, state->m_ws_portram[0xb0] + WSWAN_INT_VBLTMR );
95   } else if ( state->m_ws_portram[0xb2] & state->m_ws_portram[0xb6] & WSWAN_IFLAG_LCMP ) {
96      machine.device("maincpu")->execute().set_input_line_and_vector(0, HOLD_LINE, state->m_ws_portram[0xb0] + WSWAN_INT_LCMP );
97   } else if ( state->m_ws_portram[0xb2] & state->m_ws_portram[0xb6] & WSWAN_IFLAG_SRX ) {
98      machine.device("maincpu")->execute().set_input_line_and_vector(0, HOLD_LINE, state->m_ws_portram[0xb0] + WSWAN_INT_SRX );
99   } else if ( state->m_ws_portram[0xb2] & state->m_ws_portram[0xb6] & WSWAN_IFLAG_RTC ) {
100      machine.device("maincpu")->execute().set_input_line_and_vector(0, HOLD_LINE, state->m_ws_portram[0xb0] + WSWAN_INT_RTC );
101   } else if ( state->m_ws_portram[0xb2] & state->m_ws_portram[0xb6] & WSWAN_IFLAG_KEY ) {
102      machine.device("maincpu")->execute().set_input_line_and_vector(0, HOLD_LINE, state->m_ws_portram[0xb0] + WSWAN_INT_KEY );
103   } else if ( state->m_ws_portram[0xb2] & state->m_ws_portram[0xb6] & WSWAN_IFLAG_STX ) {
104      machine.device("maincpu")->execute().set_input_line_and_vector(0, HOLD_LINE, state->m_ws_portram[0xb0] + WSWAN_INT_STX );
105   } else {
106      machine.device("maincpu")->execute().set_input_line(0, CLEAR_LINE );
88   if ( m_ws_portram[0xb2] & m_ws_portram[0xb6] & WSWAN_IFLAG_HBLTMR )
89   {
90      m_maincpu->set_input_line_and_vector(0, HOLD_LINE, m_ws_portram[0xb0] + WSWAN_INT_HBLTMR );
10791   }
92   else if ( m_ws_portram[0xb2] & m_ws_portram[0xb6] & WSWAN_IFLAG_VBL )
93   {
94      m_maincpu->set_input_line_and_vector(0, HOLD_LINE, m_ws_portram[0xb0] + WSWAN_INT_VBL );
95   }
96   else if ( m_ws_portram[0xb2] & m_ws_portram[0xb6] & WSWAN_IFLAG_VBLTMR )
97   {
98      m_maincpu->set_input_line_and_vector(0, HOLD_LINE, m_ws_portram[0xb0] + WSWAN_INT_VBLTMR );
99   }
100   else if ( m_ws_portram[0xb2] & m_ws_portram[0xb6] & WSWAN_IFLAG_LCMP )
101   {
102      m_maincpu->set_input_line_and_vector(0, HOLD_LINE, m_ws_portram[0xb0] + WSWAN_INT_LCMP );
103   }
104   else if ( m_ws_portram[0xb2] & m_ws_portram[0xb6] & WSWAN_IFLAG_SRX )
105   {
106      m_maincpu->set_input_line_and_vector(0, HOLD_LINE, m_ws_portram[0xb0] + WSWAN_INT_SRX );
107   }
108   else if ( m_ws_portram[0xb2] & m_ws_portram[0xb6] & WSWAN_IFLAG_RTC )
109   {
110      m_maincpu->set_input_line_and_vector(0, HOLD_LINE, m_ws_portram[0xb0] + WSWAN_INT_RTC );
111   }
112   else if ( m_ws_portram[0xb2] & m_ws_portram[0xb6] & WSWAN_IFLAG_KEY )
113   {
114      m_maincpu->set_input_line_and_vector(0, HOLD_LINE, m_ws_portram[0xb0] + WSWAN_INT_KEY );
115   }
116   else if ( m_ws_portram[0xb2] & m_ws_portram[0xb6] & WSWAN_IFLAG_STX )
117   {
118      m_maincpu->set_input_line_and_vector(0, HOLD_LINE, m_ws_portram[0xb0] + WSWAN_INT_STX );
119   }
120   else
121   {
122      m_maincpu->set_input_line(0, CLEAR_LINE );
123   }
108124}
109125
110static void wswan_set_irq_line( running_machine &machine, int irq)
126void wswan_state::wswan_set_irq_line(int irq)
111127{
112   wswan_state *state = machine.driver_data<wswan_state>();
113   if ( state->m_ws_portram[0xb2] & irq )
128   if ( m_ws_portram[0xb2] & irq )
114129   {
115      state->m_ws_portram[0xb6] |= irq;
116      wswan_handle_irqs( machine );
130      m_ws_portram[0xb6] |= irq;
131      wswan_handle_irqs();
117132   }
118133}
119134
120135void wswan_state::wswan_clear_irq_line(int irq)
121136{
122137   m_ws_portram[0xb6] &= ~irq;
123   wswan_handle_irqs( machine() );
138   wswan_handle_irqs();
124139}
125140
126141TIMER_CALLBACK_MEMBER(wswan_state::wswan_rtc_callback)
r20448r20449
176191   }
177192}
178193
179static void wswan_setup_bios( running_machine &machine )
194void wswan_state::wswan_setup_bios()
180195{
181   wswan_state *state = machine.driver_data<wswan_state>();
182   if ( state->m_ws_bios_bank == NULL )
196   if ( m_ws_bios_bank == NULL )
183197   {
184      state->m_ws_bios_bank = auto_alloc_array(machine, UINT8, 0x10000 );
185      memcpy( state->m_ws_bios_bank + 0xffc0, ws_fake_bios_code, 0x40 );
198      m_ws_bios_bank = auto_alloc_array(machine(), UINT8, 0x10000 );
199      memcpy( m_ws_bios_bank + 0xffc0, ws_fake_bios_code, 0x40 );
186200   }
187201}
188202
r20448r20449
194208   m_vdp.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(wswan_state::wswan_scanline_interrupt),this), &m_vdp );
195209   m_vdp.timer->adjust( attotime::from_ticks( 256, 3072000 ), 0, attotime::from_ticks( 256, 3072000 ) );
196210
197   wswan_setup_bios(machine());
211   wswan_setup_bios();
198212
199213   /* Set up RTC timer */
200214   if ( m_rtc.present )
r20448r20449
211225   m_vdp.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(wswan_state::wswan_scanline_interrupt),this), &m_vdp );
212226   m_vdp.timer->adjust( attotime::from_ticks( 256, 3072000 ), 0, attotime::from_ticks( 256, 3072000 ) );
213227
214   wswan_setup_bios(machine());
228   wswan_setup_bios();
215229
216230   /* Set up RTC timer */
217231   if ( m_rtc.present )
r20448r20449
222236
223237void wswan_state::machine_reset()
224238{
225   address_space &space = machine().device( "maincpu")->memory().space( AS_PROGRAM );
239   address_space &space = m_maincpu->space( AS_PROGRAM );
226240
227241   /* Intialize ports */
228242   memcpy( m_ws_portram, ws_portram_init, 256 );
r20448r20449
285299   UINT8 value = m_ws_portram[offset];
286300
287301   if ( offset != 2 )
288      logerror( "PC=%X: port read %02X\n", machine().device("maincpu") ->safe_pc( ), offset );
302      logerror( "PC=%X: port read %02X\n", m_maincpu->pc(), offset );
289303   switch( offset )
290304   {
291305      case 0x02:      /* Current line */
r20448r20449
354368WRITE8_MEMBER( wswan_state::wswan_port_w )
355369{
356370   address_space &mem = m_maincpu->space(AS_PROGRAM);
357   wswan_state *state = machine().driver_data<wswan_state>();
358371   UINT8 input;
359   logerror( "PC=%X: port write %02X <- %02X\n", mem.device().safe_pc(), offset, data );
372   logerror( "PC=%X: port write %02X <- %02X\n", m_maincpu->pc(), offset, data );
360373   switch( offset )
361374   {
362375      case 0x00:  /* Display control
r20448r20449
953966         switch( data )
954967         {
955968            case 0x10:  /* Read Y cursors: Y1 - Y2 - Y3 - Y4 */
956               input = ioport("CURSY")->read();
957               if (state->m_rotate) // reorient controls if the console is rotated
969               input = m_cursy->read();
970               if (m_rotate) // reorient controls if the console is rotated
958971               {
959972                  if (input & 0x01) data |= 0x02;
960973                  if (input & 0x02) data |= 0x04;
r20448r20449
965978                  data = data | input;
966979            break;
967980            case 0x20:  /* Read X cursors: X1 - X2 - X3 - X4 */
968               input = ioport("CURSX")->read();
969               if (state->m_rotate) // reorient controls if the console is rotated
981               input = m_cursx->read();
982               if (m_rotate) // reorient controls if the console is rotated
970983               {
971984                  if (input & 0x01) data |= 0x02;
972985                  if (input & 0x02) data |= 0x04;
r20448r20449
977990                  data = data | input;
978991            break;
979992            case 0x40:  /* Read buttons: START - A - B */
980               data = data | ioport("BUTTONS")->read();
993               data = data | m_buttons->read();
981994            break;
982995         }
983996         break;
r20448r20449
13491362   else
13501363      size = image.get_software_region_length("rom");
13511364
1352   state->m_ws_ram = (UINT8*) image.device().machine().device("maincpu")->memory().space(AS_PROGRAM).get_read_ptr(0);
1365   state->m_ws_ram = (UINT8*) state->m_maincpu->space(AS_PROGRAM).get_read_ptr(0);
13531366   memset(state->m_ws_ram, 0, 0xffff);
13541367   state->m_ROMBanks = size / 65536;
13551368
r20448r20449
14501463            m_vdp.timer_hblank_reload = 0;
14511464         }
14521465         logerror( "trigerring hbltmr interrupt\n" );
1453         wswan_set_irq_line( machine(), WSWAN_IFLAG_HBLTMR );
1466         wswan_set_irq_line( WSWAN_IFLAG_HBLTMR );
14541467      }
14551468   }
14561469
14571470   /* Handle Sound DMA */
14581471   if ( ( m_sound_dma.enable & 0x88 ) == 0x80 )
14591472   {
1460      address_space &space = machine().device("maincpu")->memory().space(AS_PROGRAM );
1473      address_space &space = m_maincpu->space(AS_PROGRAM );
14611474      /* TODO: Output sound DMA byte */
14621475      wswan_port_w( space, 0x89, space.read_byte(m_sound_dma.source ) );
14631476      m_sound_dma.size--;
r20448r20449
14791492
14801493   if( m_vdp.current_line == 144 )
14811494   {
1482      wswan_set_irq_line( machine(), WSWAN_IFLAG_VBL );
1495      wswan_set_irq_line( WSWAN_IFLAG_VBL );
14831496      /* Decrement 75Hz (VBlank) counter */
14841497      if ( m_vdp.timer_vblank_enable && m_vdp.timer_vblank_reload != 0 )
14851498      {
r20448r20449
14961509               m_vdp.timer_vblank_reload = 0;
14971510            }
14981511            logerror( "triggering vbltmr interrupt\n" );
1499            wswan_set_irq_line( machine(), WSWAN_IFLAG_VBLTMR );
1512            wswan_set_irq_line( WSWAN_IFLAG_VBLTMR );
15001513         }
15011514      }
15021515   }
r20448r20449
15051518
15061519   if ( m_vdp.current_line == m_vdp.line_compare )
15071520   {
1508      wswan_set_irq_line( machine(), WSWAN_IFLAG_LCMP );
1521      wswan_set_irq_line( WSWAN_IFLAG_LCMP );
15091522   }
15101523
15111524   m_vdp.current_line = (m_vdp.current_line + 1) % 159;
trunk/src/mess/includes/wswan.h
r20448r20449
1313#define WSWAN_X_PIXELS  (28*8)
1414#define WSWAN_Y_PIXELS  (18*8)
1515
16/* Interrupt flags */
17#define WSWAN_IFLAG_STX    0x1
18#define WSWAN_IFLAG_KEY    0x2
19#define WSWAN_IFLAG_RTC    0x4
20#define WSWAN_IFLAG_SRX    0x8
21#define WSWAN_IFLAG_LCMP   0x10
22#define WSWAN_IFLAG_VBLTMR 0x20
23#define WSWAN_IFLAG_VBL    0x40
24#define WSWAN_IFLAG_HBLTMR 0x80
25/* Interrupts */
26#define WSWAN_INT_STX    0
27#define WSWAN_INT_KEY    1
28#define WSWAN_INT_RTC    2
29#define WSWAN_INT_SRX    3
30#define WSWAN_INT_LCMP   4
31#define WSWAN_INT_VBLTMR 5
32#define WSWAN_INT_VBL    6
33#define WSWAN_INT_HBLTMR 7
34
3516#define INTERNAL_EEPROM_SIZE    1024
3617
3718#include "emu.h"
r20448r20449
123104{
124105public:
125106   wswan_state(const machine_config &mconfig, device_type type, const char *tag)
126      : driver_device(mconfig, type, tag),
127   m_maincpu(*this, "maincpu")
107      : driver_device(mconfig, type, tag)
108      , m_maincpu(*this, "maincpu")
109      , m_cursx(*this, "CURSX")
110      , m_cursy(*this, "CURSY")
111      , m_buttons(*this, "BUTTONS")
128112   { }
129113
130114   virtual void video_start();
r20448r20449
159143   DECLARE_PALETTE_INIT(wscolor);
160144   TIMER_CALLBACK_MEMBER(wswan_rtc_callback);
161145   TIMER_CALLBACK_MEMBER(wswan_scanline_interrupt);
146
147protected:
148   /* Interrupt flags */
149   static const UINT8 WSWAN_IFLAG_STX    = 0x01;
150   static const UINT8 WSWAN_IFLAG_KEY    = 0x02;
151   static const UINT8 WSWAN_IFLAG_RTC    = 0x04;
152   static const UINT8 WSWAN_IFLAG_SRX    = 0x08;
153   static const UINT8 WSWAN_IFLAG_LCMP   = 0x10;
154   static const UINT8 WSWAN_IFLAG_VBLTMR = 0x20;
155   static const UINT8 WSWAN_IFLAG_VBL    = 0x40;
156   static const UINT8 WSWAN_IFLAG_HBLTMR = 0x80;
157
158   /* Interrupts */
159   static const UINT8 WSWAN_INT_STX    = 0;
160   static const UINT8 WSWAN_INT_KEY    = 1;
161   static const UINT8 WSWAN_INT_RTC    = 2;
162   static const UINT8 WSWAN_INT_SRX    = 3;
163   static const UINT8 WSWAN_INT_LCMP   = 4;
164   static const UINT8 WSWAN_INT_VBLTMR = 5;
165   static const UINT8 WSWAN_INT_VBL    = 6;
166   static const UINT8 WSWAN_INT_HBLTMR = 7;
167
168   required_ioport m_cursx;
169   required_ioport m_cursy;
170   required_ioport m_buttons;
171
172   void wswan_setup_bios();
173   void wswan_handle_irqs();
174   void wswan_set_irq_line(int irq);
162175};
163176
164177

Previous 199869 Revisions Next


© 1997-2024 The MAME Team