vdub_bobby Posted December 31, 2004 Share Posted December 31, 2004 Can someone please tell me why this doesn't work? sed ;set decimal flag lda #0 clc adc #99 ;set timer to 99 for now. sta Timer cld ;clear decimal flag. I want Timer to hold #%10011001 ($99) but this puts #%01100011 (99) in Timer instead. What am I doing wrong? Do I need to use hex? Quote Link to comment Share on other sites More sharing options...
CPUWIZ Posted December 31, 2004 Share Posted December 31, 2004 Why don't you just do this? lda #$99 sta Timer Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted December 31, 2004 Author Share Posted December 31, 2004 Why don't you just do this? lda #$99 sta Timer Well, I could. But I would like to know how BCD works Because I also want to put in a score at some point, and if I want to add 99 to the score, do I need to use hex? Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted December 31, 2004 Share Posted December 31, 2004 Yup, you need hex, so you missed the '$' before 99. Quote Link to comment Share on other sites More sharing options...
CPUWIZ Posted December 31, 2004 Share Posted December 31, 2004 if I want to add 99 to the score, do I need to use hex? Yes. Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted December 31, 2004 Share Posted December 31, 2004 Hi there! Because I also want to put in a score at some point, and if I want to add 99 to the score, do I need to use hex? Yup. It's easier to read. The correct decimal value for adding 99 in bcd would be 153 For a 6 digit bcd score, this might come in handy at times: AddScore SED CLC ADC bcdScore+2 STA bcdScore+2 LDA bcdScore+1 ADC #$00 STA bcdScore+1 LDA bcdScore ADC #$00 STA bcdScore CLD RTS Greetings, Manuel Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted December 31, 2004 Author Share Posted December 31, 2004 Thanks, folks Quote Link to comment Share on other sites More sharing options...
CPUWIZ Posted December 31, 2004 Share Posted December 31, 2004 For a 6 digit bcd score, this might come in handy at times: AddScore SED CLC ADC bcdScore+2 STA bcdScore+2 LDA bcdScore+1 ADC #$00 STA bcdScore+1 LDA bcdScore ADC #$00 STA bcdScore CLD RTS Greetings, Manuel Unless, of course, you are trying to add 200 to your score. Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted December 31, 2004 Share Posted December 31, 2004 Hi there! Unless, of course, you are trying to add 200 to your score. So you're getting an idea why nothing in Star Fire or Seawolf scores more than 99 points? Greetings, Manuel Quote Link to comment Share on other sites More sharing options...
CPUWIZ Posted December 31, 2004 Share Posted December 31, 2004 Hi there! Unless, of course, you are trying to add 200 to your score. So you're getting an idea why nothing in Star Fire or Seawolf scores more than 99 points? Greetings, Manuel Yep, those pesky extra bytes for a second routine. Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted December 31, 2004 Share Posted December 31, 2004 Yep, those pesky extra bytes for a second routine. Well, something like this does the Job too. Add8: ldy #0 Add16: sed clc adc score sta score tya adc score+1 sta score+1 cld rts More sophisticated variants are of course possible. Quote Link to comment Share on other sites More sharing options...
CPUWIZ Posted December 31, 2004 Share Posted December 31, 2004 Yep, those pesky extra bytes for a second routine. Well, something like this does the Job too. Add8: ldy #0 Add16: sed clc adc score sta score tya adc score+1 sta score+1 cld rts More sophisticated variants are of course possible. Yep, that works, still extra bytes though. Interesting to see that you and Manuel have different endian styles. I do it your way myself. Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted December 31, 2004 Share Posted December 31, 2004 Hi there! Interesting to see that you and Manuel have different endian styles. I do it your way myself. I prefer to have my bits in the right order Greetings, Manuel Quote Link to comment Share on other sites More sharing options...
+Andrew Davie Posted December 31, 2004 Share Posted December 31, 2004 Hi there! Interesting to see that you and Manuel have different endian styles. I do it your way myself. I prefer to have my bits in the right order Greetings, Manuel Just to be absolutely clear about this, Manuel's way is wrong. The 6502 is a little-endian machine, and the lowest byte in, for example, a pointer to a memory address, is always the lowest byte of the memory address. Store your low byte in address, the next in address+1, etc. One day, Manuel's screwy way of doing things is going to bite him in the bum. Also, I refuse to assist or debug code deliberately written in this fashion (big-endian), as a matter of principle. To all those out there learning, don't do it Manuel's way. It is wrong for this machine/processor. Cheers A 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.