Previous 199869 Revisions Next

r30998 Monday 16th June, 2014 at 20:36:37 UTC by hap
nw
[src/emu/cpu/lr35902]lr35902.c lr35902.h opc_main.inc
[src/mess/drivers]gb.c

trunk/src/emu/cpu/lr35902/lr35902.h
r30997r30998
66
77#define MCFG_LR35902_TIMER_CB(_devcb) \
88   lr35902_cpu_device::set_timer_cb(*device, DEVCB_##_devcb);
9
10// The first release of this CPU has a bug where the programcounter
11// is not incremented properly after an interrupt after the halt opcode.
12// This was fixed in a newer revision.
913#define MCFG_LR35902_HALT_BUG \
1014   lr35902_cpu_device::set_halt_bug(*device);
1115
r30997r30998
2832
2933   // static configuration helpers
3034   template<class _Object> static devcb_base &set_timer_cb(device_t &device, _Object object) { return downcast<lr35902_cpu_device &>(device).m_timer_func.set_callback(object); }
31   static void set_halt_bug(device_t &device) { downcast<lr35902_cpu_device &>(device).m_features |= LR35902_FEATURE_HALT_BUG; }
35   static void set_halt_bug(device_t &device) { downcast<lr35902_cpu_device &>(device).m_has_halt_bug = true; }
3236
3337   UINT8 get_speed();
3438   void set_speed( UINT8 speed_request );
r30997r30998
4044   void set_if( UINT8 data ) { m_IF = data; }
4145
4246protected:
43   static const UINT8 LR35902_FEATURE_HALT_BUG = 0x01;
4447
4548   // device-level overrides
4649   virtual void device_start();
r30997r30998
7174   inline void mem_write_word(UINT16 addr, UINT16 data);
7275   inline void check_interrupts();
7376
74protected:
7577   address_space_config m_program_config;
7678
7779   UINT8 m_A;
r30997r30998
8688   UINT16 m_SP;
8789   UINT16 m_PC;
8890   /* Interrupt related */
89   UINT8   m_IE;
90   UINT8   m_IF;
91   UINT8 m_IE;
92   UINT8 m_IF;
9193   int m_irq_state;
92   int m_ei_delay;
94   bool m_handle_ei_delay;
9395   lr35902_cpu_device *m_device;
9496   address_space *m_program;
9597   int m_icount;
9698   /* Timer callback */
9799   devcb_write8 m_timer_func;
98100   /* Fetch & execute related */
99   int     m_execution_state;
101   int m_execution_state;
100102   UINT8   m_op;
101103   /* Others */
102104   int m_gb_speed;
103105   int m_gb_speed_change_pending;
104106   int m_enable;
105   int m_doHALTbug;
106   UINT8   m_features;
107   bool m_handle_halt_bug;
108   bool m_has_halt_bug;
107109};
108110
109111extern const device_type LR35902;
trunk/src/emu/cpu/lr35902/opc_main.inc
r30997r30998
14391439   m_A = mem_read_byte( 0xFF00 + m_C );
14401440   break;
14411441case 0xF3: /*      DI */
1442   m_ei_delay = 0;
1442   m_handle_ei_delay = false;
14431443   m_enable &= ~IME;
14441444   break;
14451445case 0xF5: /*      PUSH AF */
r30997r30998
15051505   break;
15061506case 0xFB: /*      EI */
15071507   m_enable |= IME;
1508   m_ei_delay = 1;
1508   m_handle_ei_delay = true;
15091509   break;
15101510case 0xFE: /*      CP A,n8 */
15111511   x = mem_read_byte( m_PC++ );
trunk/src/emu/cpu/lr35902/lr35902.c
r30997r30998
7878   , m_IF(0)
7979   , m_timer_func(*this)
8080   , m_enable(0)
81   , m_features(0)
81   , m_has_halt_bug(false)
8282{
8383}
8484
r30997r30998
144144   save_item(NAME(m_IE));
145145   save_item(NAME(m_IF));
146146   save_item(NAME(m_irq_state));
147   save_item(NAME(m_ei_delay));
147   save_item(NAME(m_handle_ei_delay));
148148   save_item(NAME(m_execution_state));
149149   save_item(NAME(m_op));
150150   save_item(NAME(m_gb_speed));
151151   save_item(NAME(m_gb_speed_change_pending));
152152   save_item(NAME(m_enable));
153   save_item(NAME(m_doHALTbug));
153   save_item(NAME(m_handle_halt_bug));
154154
155155   // Register state for debugger
156156   state_add( LR35902_PC, "PC", m_PC ).callimport().callexport().formatstr("%04X");
r30997r30998
211211   m_IF = 0;
212212
213213   m_execution_state = 0;
214   m_doHALTbug = 0;
215   m_ei_delay = 0;
214   m_handle_halt_bug = false;
215   m_handle_ei_delay = false;
216216   m_gb_speed_change_pending = 0;
217217   m_gb_speed = 1;
218218}
r30997r30998
230230   UINT8 irq = m_IE & m_IF;
231231
232232   /* Interrupts should be taken after the first instruction after an EI instruction */
233   if (m_ei_delay) {
234      m_ei_delay = 0;
233   if (m_handle_ei_delay) {
234      m_handle_ei_delay = false;
235235      return;
236236   }
237237
r30997r30998
255255            {
256256               m_enable &= ~HALTED;
257257               m_PC++;
258               if ( m_features & LR35902_FEATURE_HALT_BUG ) {
258               if ( m_has_halt_bug ) {
259259                  if ( ! ( m_enable & IME ) ) {
260260                     /* Old cpu core (dmg/mgb/sgb) */
261                     m_doHALTbug = 1;
261                     m_handle_halt_bug = true;
262262                  }
263263               } else {
264264                  /* New cpu core (cgb/agb/ags) */
r30997r30998
311311            m_execution_state = 1;
312312         } else {
313313            m_op = mem_read_byte( m_PC++ );
314            if ( m_doHALTbug ) {
314            if ( m_handle_halt_bug ) {
315315               m_PC--;
316               m_doHALTbug = 0;
316               m_handle_halt_bug = false;
317317            }
318318         }
319319      }
trunk/src/mess/drivers/gb.c
r30997r30998
1212  TODO list:
1313  - Do correct lcd stat timing
1414  - Add Game Boy Light (Japan, 1997) - does it differ from gbpocket?
15  - SGB should be moved to SNES driver
1516
1617
1718Timers
r30997r30998
753754static MACHINE_CONFIG_DERIVED( supergb, gameboy )
754755
755756   /* basic machine hardware */
756   MCFG_CPU_REPLACE("maincpu", LR35902, 4295454) /* 4.295454 MHz */
757   MCFG_CPU_REPLACE("maincpu", LR35902, 4295454) /* 4.295454 MHz, derived from SNES xtal */
757758   MCFG_CPU_PROGRAM_MAP(sgb_map)
758759
759760   MCFG_CPU_MODIFY("maincpu")
760   MCFG_LR35902_TIMER_CB( WRITE8( gb_state, gb_timer_callback ) )
761   MCFG_LR35902_TIMER_CB( WRITE8(gb_state, gb_timer_callback ) )
761762   MCFG_LR35902_HALT_BUG
762763
763764   MCFG_MACHINE_START_OVERRIDE(gb_state, sgb)
r30997r30998
792793
793794   /* basic machine hardware */
794795   MCFG_CPU_MODIFY("maincpu") // todo XTAL_8_388MHz
795   MCFG_CPU_PROGRAM_MAP( gbc_map)
796   MCFG_LR35902_TIMER_CB( WRITE8( gb_state, gb_timer_callback ) )
796   MCFG_CPU_PROGRAM_MAP(gbc_map)
797   MCFG_LR35902_TIMER_CB( WRITE8(gb_state, gb_timer_callback ) )
797798
798799   MCFG_MACHINE_START_OVERRIDE(gb_state,gbc)
799800   MCFG_MACHINE_RESET_OVERRIDE(gb_state,gbc)
r30997r30998
820821
821822   /* basic machine hardware */
822823   MCFG_CPU_ADD("maincpu", LR35902, 4194304) /* 4.194304 MHz */
823   MCFG_CPU_PROGRAM_MAP( megaduck_map)
824   MCFG_LR35902_TIMER_CB( WRITE8( gb_state, gb_timer_callback ) )
824   MCFG_CPU_PROGRAM_MAP(megaduck_map)
825   MCFG_LR35902_TIMER_CB( WRITE8(gb_state, gb_timer_callback ) )
825826   MCFG_LR35902_HALT_BUG
826827
827828   /* video hardware */

Previous 199869 Revisions Next


© 1997-2024 The MAME Team