Sailor wrote:
Hello Gordon
I tested your code , it is great
Update :
can your code be extended to test / set overflow flag as well ?
The overflow (V) flag is a somewhat tricky one and often mis-understood. I suggest you do a lot of reading and this is a good place to start:
http://www.righto.com/2012/12/the-6502- ... ained.htmlAdapting my code to set it on an ADC - well, it's literally one line of code, but a somewhat complex line of code at that.
Adding this into the code would give you a true/false result:
Code:
#include <stdio.h>
#include <stdint.h>
int main (void)
{
uint8_t a,m,c,v ;
union
{
uint16_t t16 ;
uint8_t tt0 [2] ;
} temp ;
m = 0x7E ; c = 0 ; a = 0x82 ; // Test values
temp.t16 = a + m + c ;
v = (m ^ temp.t16) & (a ^ temp.t16) & 0x80 ;
a = temp.tt0 [0] ;
c = temp.tt0 [1] ;
printf ("A: %02X, M: %02X, C: %02X, V: %02X, temp: %04X\n", a, m, c, v, temp.t16) ;
printf (" Carry: %s\n", c ? "Yes" : "No") ;
printf ("Overflow: %s\n", v ? "Yes" : "No") ;
return 0 ;
}
Note that this yields a true (non-zero) or false (zero) result. It's actually either 0X80 or 0x00, so don't test for 1 or 0. Do test it if you use it.
-Gordon
_________________
--
Gordon Henderson.
See my
Ruby 6502 and 65816 SBC projects here:
https://projects.drogon.net/ruby/