Steem Authors wrote:The M68K runs at 8MHz. CPU timings are measured by two int variables. cpu_cycles stores the number of cycles remaining until the next event (see next section). cpu_timer keeps a running total of the number of cycles executed at the next event. The number of cycles since the emulator started is therefore given by:
#define ABSOLUTE_CPU_TIME (cpu_timer-cpu_cycles)
Because this is an int value, it loops once every 8.5 minutes (approximately). All code takes this into account.
The worst hack in Steem is not from me! They don't joke about it, cpu_timer, which is an int (signed 32bit), does loop, and becomes negative halfway through(4min+). Somehow, magically, the program all holds together (something-cpu_timer_at_such_time still works with negative values), but in C/C++, this is called overflow when you "loop" or "go negative" by adding too much to an int, and it results in undefined behaviour according to the standard,which means that's no good practice at all. I guess it depends on the processor, and I'm not really interested in examining the bit representation in Intel.
I think there could also be bugs caused by this technique in border removal detection when cpu_timer is at the threshold, because the < & > operators don't work like the - operator. I know I had a bug at 4min + in Nostalgia/Lemmings because of this.







