4 ms·
SNK were the gods of the 68000. I still remember back in the day getting a bug report on my 68000 emulator: When playing King of Fighters, the time counter wou
by kstenerud 1y ago
SNK were the gods of the 68000. I still remember back in the day getting a bug report on my 68000 emulator:
When playing King of Fighters, the time counter would go down to 0 and then wrap around to 99, effectively preventing the round from ending.
Eventually I tracked it down to the behavior of SBCD (Subtract Binary Coded Decimal): Internally, the chip actually does update the overflow flag reliably (it's marked as undefined in the docs). SNK was checking the V flag and ending the round when it got set.
https://github.com/kstenerud/Musashi/blob/master/m68k_in.c#L9418 https://github.com/kstenerud/Musashi/blob/master/m68k_in.c#L...
SBCD was an old throwback instruction that was hardly used anymore, and the register variant took 6 cycles to complete (vs 4 for binary subtraction).
HOWEVER... For displaying the timer counter on-screen, they saved a ton of cycles with this scheme because extracting the digits from a BCD value is a simple shift by 4 bits (6 cycles) rather than a VERY expensive divide (140 cycles).
- kevin_thibedeau 1y agoYou don't need division to convert to decimal, though it will still be slower than using BCD operations.
- MobiusHorizons 1y agoOh? How do you do it? Some kind of lookup table?
- kevin_thibedeau 1y agohttps://en.wikipedia.org/wiki/Double_dabble https://en.wikipedia.org/wiki/Double_dabble A software implementation with masks and shifts will beat traditional CISC dividers.
- kstenerud 1y agoTechnically no, but they were also always fighting against the ROM size, trying to keep costs down. Every byte helped.