summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Guillen Fandos2021-02-23 20:27:59 +0100
committerDavid Guillen Fandos2021-02-23 20:27:59 +0100
commit349e47f0b251b42c7a3d7e2d8072ce976a55b54c (patch)
treefd76187fc7def92e5ed31f7e28611f916a2d8f70
parent300d0c0028e400eabd81dc718ee8cd8c6459b256 (diff)
downloadpicogpsp-349e47f0b251b42c7a3d7e2d8072ce976a55b54c.tar.gz
picogpsp-349e47f0b251b42c7a3d7e2d8072ce976a55b54c.tar.bz2
picogpsp-349e47f0b251b42c7a3d7e2d8072ce976a55b54c.zip
Small fixes to division by zero
This causes crashes in PSP quite often in many games. Other CPUs might (depending on the processor state) silently return zero or some undefined value. The fix is borrowed from ReGBA's codebase
-rw-r--r--gba_memory.c2
-rw-r--r--sound.c7
2 files changed, 6 insertions, 3 deletions
diff --git a/gba_memory.c b/gba_memory.c
index 2cb760a..7675bb0 100644
--- a/gba_memory.c
+++ b/gba_memory.c
@@ -199,7 +199,7 @@ static void sound_control_x(u32 value)
#define sound_update_frequency_step(timer_number) \
timer[timer_number].frequency_step = \
- float_to_fp8_24(GBC_BASE_RATE / (timer_reload * sound_frequency)) \
+ float_to_fp8_24((GBC_BASE_RATE / sound_frequency) / (timer_reload)) \
/* Main */
extern timer_type timer[4];
diff --git a/sound.c b/sound.c
index 126fb5d..10a3261 100644
--- a/sound.c
+++ b/sound.c
@@ -273,8 +273,11 @@ u32 gbc_sound_master_volume;
else \
rate = rate + (rate >> gs->sweep_shift); \
\
- if(rate > 2048) \
- rate = 2048; \
+ if(rate > 2047) { \
+ rate = 2047; \
+ gs->active_flag = 0; \
+ break; \
+ } \
\
frequency_step = float_to_fp16_16(((131072.0f / (2048 - rate)) * 8.0f) \
/ sound_frequency); \