EvilActivity Posted June 6, 2015 Share Posted June 6, 2015 (edited) Hey guys, I've just found a weird little bug in my game caused by "SUZY.hoff += 2;". When I converted it to "SUZY.hoff = SUZY.hoff + 2;" it worked just fine. Looking at the assembly output, I can't see anything off, but since I'm learning the 6502 assembly while doing this project, I'm probably missing something. The assembly conversion of the additional assignment operator (... += 2) becomes: ; SUZY.hoff += 2 lda #$02 clc adc $FC04 sta $FC04 bcc L00DE inc $FC04+1 L00DE: <..> So the problem shows up when the value of FC04 is [00 01] (0x0100 / 256) and I start to increase it by another 2. What I end up with is 0x0002 and not the 0x0102. From what I understand, the code is doing the following: Loading up 'A' with 2 Clear the carry flag Add the first byte of FC04 to 'A' Store 'A' in FC04 Skip the increase of the second byte of FC04 if there was no carry Can anyone explain to me why the second byte is set to zero in my case? Edited June 6, 2015 by EvilActivity Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted June 6, 2015 Share Posted June 6, 2015 From :- http://www.monlynx.de/lynx/hardware.html "Any CPU write to an LSB will set the MSB to 0" So as soon as the CPU writes to the low byte the upper byte is zeroed in hardware. The compiler is doing the right thing but it doesn't know that the MSB will be cleared when the CPU writes to the LSB. The correct way to update the register would be take a temporary/shadow copy of it, update that and then write that back to the hardware. 2 Quote Link to comment Share on other sites More sharing options...
EvilActivity Posted June 7, 2015 Author Share Posted June 7, 2015 From :- http://www.monlynx.de/lynx/hardware.html "Any CPU write to an LSB will set the MSB to 0" So as soon as the CPU writes to the low byte the upper byte is zeroed in hardware. The compiler is doing the right thing but it doesn't know that the MSB will be cleared when the CPU writes to the LSB. The correct way to update the register would be take a temporary/shadow copy of it, update that and then write that back to the hardware. Ahhh nice, thanks for that! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.