+atari2600land Posted February 5, 2015 Share Posted February 5, 2015 I am hoping that someone here knows Odyssey 2 programming (or cpu 8048) because the Odyssey 2 forum I usually visit for help is a ghost town. What I'm trying to do is this: I have three characters (score_ones, score_tens, & score_huns) for the score, and three characters (hscore_ones, hscore_tens & hscore_huns) for the high score. I am trying to make all three digits change when a new high score has been reached. Everything I try has been unsuccessful. So I come back to this code and try again. check_highscore mov r1,#hscore_ones mov a,@r1 ; get highscore cpl a ; make highscore negative mov r0,#score_ones add a,@r0 ; subtract highscore from score jnc replace_highscore2 mov r1,#hscore_tens mov a,@r1 ; get red car speed mov r2,a ; store in R2 mov r0,#score_tens mov a,@r0 xrl a,r2 jz replace_highscore replace_highscore2 mov r1,#hscore_tens mov a,@r1 ; get highscore cpl a ; make highscore negative mov r0,#score_tens add a,@r0 ; subtract highscore from score jnc no_highscore replace_highscore Unfortunately, only the first two digits would change (the hscore_ones and hscore_tens.) So if a player reaches 100 points and the current high score is, say. 94, it will still say 94 instead of 100 when the game is over. I want to incorporate the hundreds digit into this, but I can't seem to make anything work. It seems so simple, but I can't do it. I'm asking for help here. Quote Link to comment Share on other sites More sharing options...
carlsson Posted February 6, 2015 Share Posted February 6, 2015 (edited) I don't know 8048 machine code, but it seems to me that you are measuring the score backwards? 1. If the least digit (ones) is greater than the least digit of the highscore, update the highscore 2. If the second least digit (tens) is greater than the second least digit of the highscore, update 3. (code not shown as far as I can tell) If the most significant digit (hundreds) is greater ... I.e. if you reverse the code order so first you check if the hundreds were greater, then tens and in the last case ones, perhaps your routine would work? Also if the most significant digit was greater than the highscore, you probably want to update all three digits of the highscore instead of just the first one. Only if the most significant digit is equal to the previous highscore, you need to check the following two: Score: 101, highscore 099: only need to check the first digit Score: 112, highscore 101: need to check the first two digits Score: 119, highscore 112: need to check all three digits Score: 099, highscore 112: only need to check the first digit etc Edited February 6, 2015 by carlsson Quote Link to comment Share on other sites More sharing options...
+atari2600land Posted March 3, 2015 Author Share Posted March 3, 2015 Can someone write me some code to do this? I apparently can't do it. Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted March 3, 2015 Share Posted March 3, 2015 Don't forget to test for all 3 outcomes. For each digit (100's, 10's, and 1's last), skip to the next digit check only if the result is equal in value. Otherwise...abandon the routine if the score digit is less than the highscore's, or set the new highscore if the score digit is greater than what highscore holds (all in that order). Quote Link to comment Share on other sites More sharing options...
carlsson Posted March 5, 2015 Share Posted March 5, 2015 (edited) Good call by Nukey that in the case the MSB of current score is less than the highscore, the routine should exit instead of continue. I have never programmed 8048, but based on your code and a data sheet found online, I came up with this rough, untested code below. However I have a few questions: 1. Aren't # values immediate constants? Do you store score as variables somewhere, perhaps as external memory so you need MOVX? Are those immediate offsets into external memory? 2. What is the difference between r0 and @r0? Is the latter used as a pointer to retrieve the value of the address pointed by the register? 3. Will ADD ignore the incoming carry flag and just set it based on result? I see there is an ADDC that handles incoming carry, so I suppose it is right. 4. How do you store values back to memory? As you can see, some of my code surely won't pass the assembler, but once you got the algorithm/logic set up, you can make adjustments to get the code to actually work. (Note to self: Don't include text below a code block or similar, as this forum software appears to cut off messages at the ending of a such block) check_highscore mov a,#hscore_huns cpl a mov r0,#score_huns add a,@r0 jnc replace_highscore ; if score_huns > hscore_huns inc a ; after complement highscore and adding current score, ; the result will always be $FF in case those are equal, ; so increasing accumulator once will then make it zero jnz exit ; if score_huns < hscore_huns mov a,#hscore_tens cpl a mov r0,#score_tens add a,@r0 jnc replace_highscore ; if score_tens > hscore_tens inc a jnz exit ; if score_tens < hscore_tens mov a,#hscore_ones cpl a mov r0,#score_ones add a,@r0 jc exit ; if score_ones <= hscore_ones replace_highscore: mov r0,#score_huns mov r1,#score_tens mov r2,#score_ones mov #hscore_huns,@r0 ; likely won't pass the assembler mov #hscore_tens,@r1 ; ditto mov #hscore_ones,@r2 ; ditto exit: retr ; or whatever Edited March 5, 2015 by carlsson 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.