doomhack / GBADoom

A port of prBoom to the Nintendo GBA.
182 stars 25 forks source link

Question about game speed. #33

Closed P1nkz closed 1 year ago

P1nkz commented 2 years ago

Not an actual issue, more a question.

I've been tempted to try running the game on a overclocked GBA, but for the game to not run too fast while actually getting a FPS benefit, I'd have to change the games internal speed, if it's no hassle and you have a rough idea, could you point me to the right direction? I can compile it fine myself but the code goes a little over my head to find the portion where game speed is set.

Thanks. When I try I'll be sure to report my results.

doomhack commented 2 years ago

Hi,

Can you tell me more about overclocking the GBA?

The game uses the hardware timers to govern the speed of the game so if the overclock mod changes the rate that the timers tick at, the game will run fast.

If you look in i_system_gba.cpp I_InitScreen_e32() we set up the timers.

If you change the value we set REG_TM2CNT_L to, we can change how long a Doom tic (1/35th Second) is in relation to a GBA timer tick.

https://www.coranac.com/tonc/text/timers.htm

A timer tick in our config is every 256 cycles, (16.7mhz / 256 = 65.5khz)

In our case it is 1872 timer ticks. (65.536khz / 1872 = 35hz)

If the CPU is overclocked to say 25mhz, we can compute a new value for REG_TM2CNT_L as follows:

25mhz / 256 = 97.6khz.

REG_TM2CNT_L = 35hz / 97.6khz = 2790.

P1nkz commented 2 years ago

Superb! Thank you very much, that should be all I need to adjust the game speed myself.

Can you tell me more about overclocking the GBA?

There's a piece of kit you can get called GBAccelerator, which lets you jump between several different oscillator speeds resulting in speeds between 0.85x to 1.75x, it overclocks the whole system since it changes the oscillator frequency, so even when it works it can still cause sound problems but it would be fun to try nonetheless (for sample based sounds I might be able to adjust the sound files to match the speedup). Usually it doesn't work with modern flash cartridges, just original games and older flashed cartridges but I recently got confirmation that some people have gotten the MODE B in the EZ Flash Omega DE to work with GBAccelerator for some games.

I haven't gotten a GBAccelerator yet but I plan on eventually and this is on my list of things to try with it.

Anyways thanks for your great work, this is a lovely port that doesn't get talked about nearly enough. I recently also found the -pwad switch for GbaWadUtil and been seeing which vanilla mods I can get to run, it's a blast.

doomhack commented 2 years ago

Ahh...I see. It's a replacement timing crystal.

The only think I would point out though, I suspect the music and sound will run fast if the CPU is overclocked.

I'm not sure how to change this as I use a library (maxmod) to play audio.

You would probably have to build a custom library and the tools for exporting the audio/mod samples.

Edit: Actually. thinking about it, you could just resample the audio to a higher frequency say from 16khz to 25khz and it should playback normally.

Thank you for your kind words. It's been a fun and educational project to work on and I am glad people are having fun with it!