Wednesday, March 11, 2009

Waving flags

Yesterday I read some on performance tuning for emulator programming. I realized that I did at least one thing in a not optimal way. The N and Z flags, telling if the last operation resulted in a negative or zero result, should be handled lazy. My opcodes had macros calculating those flags for all instructions where it was applicable. That means that I called "Z = !!result" and "N = !!(result & 0x80)" a lot of times. Those flags are only read through branch instructions and used in a few other cases. Now the flags internally contain the value of the latest operation that can affect them. Then, when needed, I decode them as shown above.

I need to refactor some of the memory decoding handling. It has shown out to not be optimal when flag handling comes in count. I still need to add handling of the C and V flag, but after reading some on it it should be no big problem. Other things yet to fix is decimal mode. The 6502 can be set in a decimal mode where arithmetic operations go by base 10 instead of 16. 

Finally a nice Oric 1 motherboard:


0 comments:

Post a Comment