From 6b27889b992b1aea26b2688fd541d41dc53e99d6 Mon Sep 17 00:00:00 2001 From: Angelo Salese Date: Tue, 24 Mar 2009 14:00:22 +0000 Subject: [PATCH] Added a preliminary implementation for the SLEEP opcode in SH-4 cpu. This fixes Quiz Keitai Q Mode booting [Angelo Salese] --- src/emu/cpu/sh4/sh4.c | 11 ++++++++++- src/emu/cpu/sh4/sh4comn.c | 6 ++++-- src/emu/cpu/sh4/sh4comn.h | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/emu/cpu/sh4/sh4.c b/src/emu/cpu/sh4/sh4.c index 03ef3f4cba8..9194a76d94a 100644 --- a/src/emu/cpu/sh4/sh4.c +++ b/src/emu/cpu/sh4/sh4.c @@ -1546,9 +1546,17 @@ INLINE void SHLR16(SH4 *sh4, UINT32 n) /* SLEEP */ INLINE void SLEEP(SH4 *sh4) { - sh4->pc -= 2; + /* 0 = normal mode */ + /* 1 = enters into power-down mode */ + /* 2 = go out the power-down mode after an exception */ + if(sh4->sleep_mode != 2) + sh4->pc -= 2; sh4->sh4_icount -= 2; /* Wait_for_exception; */ + if(sh4->sleep_mode == 0) + sh4->sleep_mode = 1; + else if(sh4->sleep_mode == 2) + sh4->sleep_mode = 0; } /* STC SR,Rn */ @@ -3317,6 +3325,7 @@ static CPU_RESET( sh4 ) sh4->internal_irq_level = -1; sh4->irln = 15; + sh4->sleep_mode = 0; } /* Execute cycles - returns number of cycles actually run */ diff --git a/src/emu/cpu/sh4/sh4comn.c b/src/emu/cpu/sh4/sh4comn.c index 75e0b0fae8f..bd888fcd1e8 100644 --- a/src/emu/cpu/sh4/sh4comn.c +++ b/src/emu/cpu/sh4/sh4comn.c @@ -212,6 +212,8 @@ void sh4_exception(SH4 *sh4, const char *message, int exception) // handle excep /* fetch PC */ sh4->pc = sh4->vbr + vector; + /* wake up if a sleep opcode is triggered */ + if(sh4->sleep_mode == 1) { sh4->sleep_mode = 2; } } static UINT32 compute_ticks_refresh_timer(emu_timer *timer, int hertz, int base, int divisor) @@ -644,9 +646,9 @@ WRITE32_HANDLER( sh4_internal_w ) case MMUCR: // MMU Control if (data & 1) fatalerror("SH4: MMUCR write enables MMU\n"); - + break; - + // Memory refresh case RTCSR: sh4->m[RTCSR] &= 255; diff --git a/src/emu/cpu/sh4/sh4comn.h b/src/emu/cpu/sh4/sh4comn.h index ed3c541bf40..87df6d90d9f 100644 --- a/src/emu/cpu/sh4/sh4comn.h +++ b/src/emu/cpu/sh4/sh4comn.h @@ -68,6 +68,8 @@ typedef struct UINT32 *m; INT8 nmi_line_state; + UINT8 sleep_mode; + int frt_input; int irln; int internal_irq_level;