4 ms·
I don’t see where “a division of 90° by 16” would be used in the game. Given the CPUs of the time, I would think they wouldn’t compute angles, but use a lookup
by Someone 6y ago
I don’t see where “a division of 90° by 16” would be used in the game.
Given the CPUs of the time, I would think they wouldn’t compute angles, but use a lookup table of sines and cosines (possibly in a single table, and scaled by a convenient factor).
I would guess they used a lookup table to look up sines and cosines, and picked a power of two for the number of different angles because increasing the angle with wraparound is faster that way. Compare (made up assembly language)
INC reg
CMP reg, #0x10
BNE dontWrap
CLR reg
dontWrap:
RTS
with
INC REG
AND REG, #0x0F
RTS
- FatalLogic 6y agoWhat you've said sounds more likely. The original code can be seen here: http://www.ionpool.net/arcade/astcode/asteroids_code_project.html http://www.ionpool.net/arcade/astcode/asteroids_code_project... The rotation code apparently starts at 0x7086, which adds or subtracts 3 from a one byte variable. If that 8 bit variable maps to a full 360 degrees of rotation, that would result in steps of about 4.2 degrees, but I don't know because I couldn't follow the code after that
- justinlloyd 6y agoReaching back in some ancient memory from 35+ years ago I recall that the rotation tables were sin/cos and the cos table overlapped the sin table by 180 degrees. I think there was 256 entries in When the ship rotated it stepped through the rotation table by three entries at a time, and took advantage of the 8-bit accumulator wrapping around. Then the value was used as a look-up in a table. The ships direction was a value of 0x00 to 0xFF, and that was used as an index in to the rotation table. I would need to read through the disassembly again to refresh my memory.