Videopac / Odyssey2 forum
December 10, 2019, 09:10:20 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Al lot of attachments from Nov 2011 till april 2012 are damaged. Please ask the original poster to re-upload if you need them.
 
   Home   arcade Help Login Register links videopac.nl  
Pages: [1]   Go Down
  Print  
Author Topic: High score with three digits.  (Read 3509 times)
Chris!
Give this man a Jopac!
******
Posts: 1148



WWW
« on: February 05, 2015, 09:55:35 AM »

So I have three characters that make up the score and three more characters that make up the high score. I found that this works for the ones and the tens digit:
Code:
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
mov r0,#score_ones
mov a,@r0 ; get score
mov r1,#hscore_ones ; point to highscore low byte
mov @r1,a ; store new highscore

mov r0,#score_tens
mov a,@r0 ; get score
mov r1,#hscore_tens ; point to highscore low byte
mov @r1,a ; store new highscore

mov r0,#score_huns
mov a,@r0 ; get score
mov r1,#hscore_huns ; point to highscore low byte
mov @r1,a ; store new highscore

no_highscore
jmp start_2
But I have tried and failed to implement the hundreds score (score_huns and hscore_huns) as well as the tens and ones digits. How would I do this?
Logged

All my Odyssey2 projects, now in one place!
http://www.atari2600land.com/odyssey2.html
gertk
Post Axe Pete!
*****
Posts: 859



gertk64
WWW
« Reply #1 on: February 06, 2015, 07:49:05 AM »

here is a snippet of my score code for Omega Race:
It uses a 4 digit counter (using quad 0 and 1 interleaved to display score and highscore)
To add a value to the current score set the value in r2 and call 'add_score'


Code:
<<<--- snip --->>>
score_l .equ 0x24 ; score low byte
score_h .equ 0x25 ; score high byte


; this adds 'r2' to current score
add_score:
mov r1,#score_l ; point to score low byte
mov a,@r1 ; get current value
add a,r2 ; add r2
da a ; decimal adjust
mov @r1,a ; store back
inc r1 ; point to high byte
mov a,@r1 ; get current value
addc a,#0
da a ; decimal adjust a (adding a possible carry)
mov @r1,a ; store back
ret


show_score:
mov r4,#102 ; quad 0 and 1 yposition

; set up quad 0 character 2 (thousands of score)
mov r0,#vdc_quad0+0x0a

; evaluate score high byte, high nibble
mov r1,#score_h ; get high byte
mov a,@r1 ; in a
swap a ; swap nibbles
anl a,#0x0f ; use only lower 4 bits
jnz show_score_skip1
mov a,#vdc_space ; hide first 0
show_score_skip1:
mov r5,a ; thousands number
mov r6,#col_chr_white ; set the color

call calcchar23 ; convert
mov a,r5 ; get code
movx @r0,a ; save it
inc r0 ; point to next address
mov a,r6 ; get color
movx @r0,a ; save it

; set up quad 1 character 2 (hundreths of score)
mov r0,#vdc_quad1+0x0a

; evalute score high byte, low nibble
mov r1,#score_h ; get high byte
mov a,@r1
anl a,#0x0f ; use only lower nibble
mov r5,a ; hundreths number
mov r6,#col_chr_white ; set the color
call calcchar23 ; convert
mov a,r5 ; get code
movx @r0,a ; save it
inc r0
mov a,r6 ; get color
movx @r0,a ; save it

; set up quad 0 character 3 (tens of score)
mov r0,#vdc_quad0+0x0e

; evaluate score low byte, high nibble
mov r1,#score_l
mov a,@r1
swap a
anl a,#0x0f
mov r5,a ; tens number
mov r6,#col_chr_white ; set the color
call calcchar23 ; convert
mov a,r5 ; get code
movx @r0,a ; save it
inc r0
mov a,r6 ; get color
movx @r0,a ; save it


; set up quad 1 character 3 (units of score)
mov r0,#vdc_quad1+0x0e

; evaluate score low byte low nibble
mov r1,#score_l
mov a,@r1
anl a,#0x0f
mov r5,a ; units number
mov r6,#col_chr_white ; set the color
call calcchar23 ; convert
mov a,r5 ; get code
movx @r0,a ; save it
inc r0
mov a,r6 ; get color
movx @r0,a ; save it
ret

init_score:
; preset x positions (they are fixed)
mov r3,#50 ; quad 0 xposition
mov r4,#102 ; quad 0 and 1 yposition

mov r0,#vdc_quad0
call store_r3r4

mov r0,#vdc_quad0+0x04
call store_r3r4

mov r0,#vdc_quad0+0x08
call store_r3r4

mov r0,#vdc_quad0+0x0c
call store_r3r4

mov r3,#58 ; quad 1 xposition

mov r0,#vdc_quad1
call store_r3r4

mov r0,#vdc_quad1+0x04
call store_r3r4

mov r0,#vdc_quad1+0x08
call store_r3r4

mov r0,#vdc_quad1+0x0c
call store_r3r4

jmp show_score

store_r3r4:
mov a,r4
movx @r0,a ; store it
inc r0
mov a,r3
movx @r0,a
ret

<<<--- snip --->>>
Logged

>>G7000 G7200(P+S) G7400 N60 JET27 VG5000 ZX80 ZX81 ORIC-1 COMX35 Aquarius<<
Chris!
Give this man a Jopac!
******
Posts: 1148



WWW
« Reply #2 on: February 06, 2015, 07:53:58 AM »

I want the high score function to work on all three digits, not just the tens and the ones. The rest of the code I have figured out, but I just need help getting the last digit (hundreds) to compare and if so, change with the rest of the digits when a new high score is reached. Right now, if the high score is, say, 94, if you get 100 and die, 094 will still be in the high score even though you got a score of 100.
Logged

All my Odyssey2 projects, now in one place!
http://www.atari2600land.com/odyssey2.html
gertk
Post Axe Pete!
*****
Posts: 859



gertk64
WWW
« Reply #3 on: February 09, 2015, 07:46:20 AM »

You need to compare all three bytes you use to keep the score starting with the hundredths byte first. Something like this:

in pseudo code

Code:
compare_score:
    If score_huns > hscore_huns then jump to update highscore

    if score_tens > hscore_tens then jump to update highscore

    if score_ones > hscore_ones then jump to update highscore
 
return


update highscore:
    hscore_huns = score_huns
    hscore_tens = score_tens
    hscore_ones = score_ones
return

Notice that after the compare you need to jump to update_highscore, not call it, otherwise it would return to do the next compare which is wrong.
Logged

>>G7000 G7200(P+S) G7400 N60 JET27 VG5000 ZX80 ZX81 ORIC-1 COMX35 Aquarius<<
Chris!
Give this man a Jopac!
******
Posts: 1148



WWW
« Reply #4 on: March 03, 2015, 06:13:41 AM »

This does not work:
Code:
mov r1,#hscore_huns
mov a,@r1 ; get highscore
cpl a
mov r0,#score_huns
add a,@r0 ; subtract highscore from score
jc replace_highscore

mov r1,#hscore_tens
mov a,@r1 ; get highscore
cpl a
mov r0,#score_tens
add a,@r0 ; subtract highscore from score
jc replace_highscore

mov r1,#hscore_ones
mov a,@r1 ; get highscore
cpl a
mov r0,#score_ones
add a,@r0 ; subtract highscore from score
jc replace_highscore
Logged

All my Odyssey2 projects, now in one place!
http://www.atari2600land.com/odyssey2.html
gertk
Post Axe Pete!
*****
Posts: 859



gertk64
WWW
« Reply #5 on: March 03, 2015, 04:20:25 PM »

what is the result ?

Logged

>>G7000 G7200(P+S) G7400 N60 JET27 VG5000 ZX80 ZX81 ORIC-1 COMX35 Aquarius<<
Chris!
Give this man a Jopac!
******
Posts: 1148



WWW
« Reply #6 on: March 03, 2015, 07:28:42 PM »

If you score 3 points and the high score is 10, the high score reverts back to 3.
Logged

All my Odyssey2 projects, now in one place!
http://www.atari2600land.com/odyssey2.html
manopac
Game & App Development
Give this man a Jopac!
*
Posts: 1123



« Reply #7 on: March 04, 2015, 07:44:51 AM »

one problem in your code (haven't take a closer look ...):

cpl a  is not the correct way to create a negative number ... it's

cpl a
inc a

example:  a = 00000011   = 3
cpl a             11111100  = -4
inc a             11111101  = -3

Logged

sex, lies, and videopac
gertk
Post Axe Pete!
*****
Posts: 859



gertk64
WWW
« Reply #8 on: March 08, 2015, 10:18:45 AM »

cpl a  is not the correct way to create a negative number ... it's

cpl a
inc a

example:  a = 00000011   = 3
cpl a             11111100  = -4
inc a             11111101  = -3

That must be the cause of the problem:

If, as in Chris' case, the highscore hundreds is still zero it will be complemented to $FF which causes the highscore to be replaced by the current score.

You might try this:

Code:
mov r1,#hscore_huns
mov a,@r1 ; get highscore
cpl a
inc a
mov r0,#score_huns
add a,@r0 ; subtract highscore from score
jc replace_highscore

mov r1,#hscore_tens
mov a,@r1 ; get highscore
cpl a
inc a
mov r0,#score_tens
add a,@r0 ; subtract highscore from score
jc replace_highscore

mov r1,#hscore_ones
mov a,@r1 ; get highscore
cpl a
inc a
mov r0,#score_ones
add a,@r0 ; subtract highscore from score
jc replace_highscore

Any luck with this Chris ?
Logged

>>G7000 G7200(P+S) G7400 N60 JET27 VG5000 ZX80 ZX81 ORIC-1 COMX35 Aquarius<<
Chris!
Give this man a Jopac!
******
Posts: 1148



WWW
« Reply #9 on: March 08, 2015, 10:36:50 AM »

I found some help on another forum, this seems to be working OK:
Code:
check_highscore





mov r1,#score_huns
mov a,@r1 ; get highscore
;cpl a
mov r0,#hscore_huns
xrl a,@r0 ; subtract highscore from score
jz check_highscore2

mov r1,#score_huns
mov a,@r1 ; get highscore
cpl a
mov r0,#hscore_huns
add a,@r0 ; subtract highscore from score
jc no_highscore

jmp replace_highscore

check_highscore2
mov r1,#score_tens
mov a,@r1 ; get highscore
;cpl a
mov r0,#hscore_tens
xrl a,@r0 ; subtract highscore from score
jz check_highscore3

mov r1,#score_tens
mov a,@r1 ; get highscore
cpl a
mov r0,#hscore_tens
add a,@r0 ; subtract highscore from score
jc no_highscore

jmp replace_highscore

check_highscore3
mov r1,#score_ones
mov a,@r1 ; get highscore
;cpl a
mov r0,#hscore_ones
xrl a,@r0 ; subtract highscore from score
jz no_highscore

mov r1,#score_ones
mov a,@r1 ; get highscore
cpl a
mov r0,#hscore_ones
add a,@r0 ; subtract highscore from score
jc no_highscore
Logged

All my Odyssey2 projects, now in one place!
http://www.atari2600land.com/odyssey2.html
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!