Kevin Holditch Posted September 6, 2011 Share Posted September 6, 2011 I was wondering if someone could help me. I've started to write my own Atari 2600 game and I'm starting out by working out an algorithm to display the score. So far I've mapped all of the numbers from 0-9 out in consecutive memory using 8 bytes for each number. To display the any number from 0-9 I simply multiply the number by 8 (by bit shifting left 3 times) and then I know where in memory to start drawing the number from. I then loop round for 8 lines loading each line of memory into the background register to draw the number. This all works great but the problem comes when I want to draw a 2,3 or even 4 digit number. I am having trouble working out how to extract the tens, hundreds, thousands from the number. I need to be able to do this so I can draw each digit using the routine described above. Thanks in advance for any help. Quote Link to comment Share on other sites More sharing options...
RevEng Posted September 6, 2011 Share Posted September 6, 2011 ...I am having trouble working out how to extract the tens, hundreds, thousands from the number. I need to be able to do this so I can draw each digit using the routine described above. Thanks in advance for any help. The usual way to do this is to keep your score in Binary Coded Decimal format, or BCD for short. The 6507/6502 has a native BCD mode that you just need to turn on (SED) when adding or subtracting from the score, and turn off (CLD) when you're done. When it's enabled, for example, if a score byte is $09 and you add 1 it will become $10 instead of $0A. If you used BCD mode with all score additions and subtractions, extracting a lower decimal digit from a score byte is just a matter of an "AND #$0f" and extracting the higher decimal digit is just a matter of 4 "LSR"s. Rinse and repeat for any other score digits you may have. Quote Link to comment Share on other sites More sharing options...
Kevin Holditch Posted September 6, 2011 Author Share Posted September 6, 2011 (edited) ...I am having trouble working out how to extract the tens, hundreds, thousands from the number. I need to be able to do this so I can draw each digit using the routine described above. Thanks in advance for any help. The usual way to do this is to keep your score in Binary Coded Decimal format, or BCD for short. The 6507/6502 has a native BCD mode that you just need to turn on (SED) when adding or subtracting from the score, and turn off (CLD) when you're done. When it's enabled, for example, if a score byte is $09 and you add 1 it will become $10 instead of $0A. Using BCD, extracting the lower digit is just a matter of an "AND #$0f" and extracting the higher digit is just a matter of 4 "LSR"s. Rinse and repeat for any other score digits you may have. Thanks very much for such a quick response. I can see how it would be quite easy (in Atari 2600 terms where nothing is that easy) to do it now. Thanks again. Edited September 6, 2011 by Kevin Holditch Quote Link to comment Share on other sites More sharing options...
RevEng Posted September 6, 2011 Share Posted September 6, 2011 I can see how it would be quite easy (in Atari 2600 terms where nothing is that easy) to do it now. Thanks again. Hah, so true. No problem, and good luck with your game! 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.