Jump to content



0

I'm Back with a question


11 replies to this topic

#1 Happy_Dude OFFLINE  

Happy_Dude

    River Patroller

  • 4,208 posts
  • Forum Slacker
  • Location:Sydney, Australia

Posted Tue Aug 5, 2003 3:25 AM

I had some internet issues and have been away from the net for 4 whole days.

Wait a minute, just what is this doing in the homebrew section you may wonder,
well I'v got 4 days of solid coding behing me and although I'v given up on
Mr Driller for now I'v made a little hack that shows me the decimal value
of a colour being displayed on screen and allows joystick control of the colour.
Very simple and probably been done before but I'm just happy to have made something work :D

Now to my question, I'v had some trouble with getting a score decreasing
routine working.
heres a snipit from my code which I'll post after I'm happy with it (which means when this bit is working ;) )
Someone tell me what I'm doing wrong binary math is not my strong point


;decrease score; Not working past 0
	ldx #5
scloop2  
	dec score,x  	; decrease score
	lda score,x
	cmp #0    ; is it 0
	bne scdone2  	; no? then move on
	lda #10    ; yes? then make it 10
	sta score,x
	dex    	; and the next number is 
	beq scloop2  	; decreased ?
scdone2


#2 Cybergoth OFFLINE  

Cybergoth

    Quadrunner

  • 8,207 posts
  • This is Sparta!
  • Location:Bavaria

Posted Tue Aug 5, 2003 3:48 AM

Hi there!

;decrease score
; Not working past 0

	ldx #5

scloop2  

	dec score,x  	; decrease score

	lda score,x

	cmp #0    ; is it 0

	bne scdone2  	; no? then move on

	lda #10    ; yes? then make it 10

	sta score,x

	dex    	; and the next number is 

	beq scloop2  	; decreased ?

scdone2


Ok. The main bug is that you do "beq scloop2", ie "Branch if Equal". In this case an implicit compare with 0 happens, so it'd branch if X would be zero.

You should replace it with "bpl scloop2", ie "Branch if Positive". Then it is running from 5 to 0 as intended (As I assume :) )

Next thing is, you don't need to do "cmp #0" after a load. This is done implicit again, so you can remove that for being redundant.

And you probably want to switch from 0 to 9 rather than 1 to 10.

Finally, I hope you're aware that you're decreasing all 6 digits at once with this. For a real score display you'd better switch to BCD and 3 byte storage, as with 6 bytes in binary you'll most likely kill yourself programmig that... :twisted:

HTH

Greetings,
Manuel

#3 Happy_Dude OFFLINE  

Happy_Dude

    River Patroller

  • 4,208 posts
  • Forum Slacker
  • Location:Sydney, Australia

Posted Tue Aug 5, 2003 4:59 AM

Cybergoth said:

Hi there!

;decrease score; Not working past 0
ldx #5
scloop2  
dec score,x  	; decrease score
lda score,x
cmp #0    ; is it 0
bne scdone2  	; no? then move on
lda #10    ; yes? then make it 10
sta score,x
dex    	; and the next number is 
beq scloop2  	; decreased ?
scdone2

Ok. The main bug is that you do "beq scloop2", ie "Branch if Equal". In this case an implicit compare with 0 happens, so it'd branch if X would be zero.

You should replace it with "bpl scloop2", ie "Branch if Positive". Then it is running from 5 to 0 as intended (As I assume :) )

Next thing is, you don't need to do "cmp #0" after a load. This is done implicit again, so you can remove that for being redundant.

And you probably want to switch from 0 to 9 rather than 1 to 10.

Finally, I hope you're aware that you're decreasing all 6 digits at once with this. For a real score display you'd better switch to BCD and 3 byte storage, as with 6 bytes in binary you'll most likely kill yourself programmig that...  :twisted:

HTH

Greetings,
Manuel

I figured "cld" at startup meant all numbers were BCD

Your suggestions worked but it just wont roll from 1 to 0 but straight to 9
and 11 to 10 is messed up :(

btw it doesn't do all 6 numbers just the first one and if it's changed it checks the next one. also it's not a "real" score display so this should work just fine ;)

#4 Sheddy OFFLINE  

Sheddy

    Dragonstomper

  • 587 posts
  • Location:UK

Posted Tue Aug 5, 2003 5:33 AM

Happy_Dude said:

Cybergoth said:

Hi there!

;decrease score
; Not working past 0

ldx #5

scloop2  

dec score,x  	; decrease score

lda score,x

cmp #0    ; is it 0

bne scdone2  	; no? then move on

lda #10    ; yes? then make it 10

sta score,x

dex    	; and the next number is 

beq scloop2  	; decreased ?

scdone2


Ok. The main bug is that you do "beq scloop2", ie "Branch if Equal". In this case an implicit compare with 0 happens, so it'd branch if X would be zero.  

You should replace it with "bpl scloop2", ie "Branch if Positive". Then it is running from 5 to 0 as intended (As I assume :) )

Next thing is, you don't need to do "cmp #0" after a load. This is done implicit again, so you can remove that for being redundant.

And you probably want to switch from 0 to 9 rather than 1 to 10.

Finally, I hope you're aware that you're decreasing all 6 digits at once with this. For a real score display you'd better switch to BCD and 3 byte storage, as with 6 bytes in binary you'll most likely kill yourself programmig that...  :twisted:  

HTH

Greetings,
Manuel

I figured "cld" at startup meant all numbers were BCD

Your suggestions worked but it just wont roll from 1 to 0 but straight to 9
and 11 to 10 is messed up :(

btw it doesn't do all 6 numbers just the first one and if it's changed it checks the next one. also it's not a "real" score display so this should work just fine ;)

The CLD won't make a difference to INC or DEC. Only the maths instructions are affected (ADC and SBC). Don't ask me why, but INC and DEC don't count as maths.....well they do COUNT......but you know what I mean :P

Assuming you are NOT working in decimal, you also don't need the "lda score,x" - the DEC will also flag for zero or negative. And just change the "lda #10" to "lda #9" as Manuel suggests, and you should be in business (I think!) :D

#5 Cybergoth OFFLINE  

Cybergoth

    Quadrunner

  • 8,207 posts
  • This is Sparta!
  • Location:Bavaria

Posted Tue Aug 5, 2003 5:34 AM

Hi there!

Happy_Dude said:

Your suggestions worked but  it  just  wont roll from 1 to 0 but straight to 9 and 11 to 10 is messed up :(

I'm short of time at the moment so here's a quicky: Try replacing
"bne scdone2" with "bmi scdone2" so it should go to 0.

Greetings,
Manuel

#6 Happy_Dude OFFLINE  

Happy_Dude

    River Patroller

  • 4,208 posts
  • Forum Slacker
  • Location:Sydney, Australia

Posted Tue Aug 5, 2003 6:41 AM

Cybergoth said:

Hi there!

Happy_Dude said:

Your suggestions worked but  it  just  wont roll from 1 to 0 but straight to 9 and 11 to 10 is messed up :(

I'm short of time at the moment so here's a quicky: Try replacing
"bne scdone2" with "bmi scdone2" so it should go to 0.

Greetings,
Manuel
Very close :) I replaced it with bpl and it works now


	ldx #5 

scloop2  

   dec score,x            ; decrease score 

   bpl scdone2           ; no? then move on 

   lda #9              	; yes? then make it 9

   sta score,x 

   dex                  ; and the next number is 

   bpl scloop2            ; decreased ? 

scdone2 


I'm happy with the code now it does what I want it to :)
When I'v learnt a bit more (mabye in a few years) I'll probably come
back to this and optimise the heck out of it ;)
Or mabye I'll just do stuff as I learn.

Anyway, heres the offending peice of code :D



p.s Fell free to tell me its crap :P

Attached Files



#7 Cybergoth OFFLINE  

Cybergoth

    Quadrunner

  • 8,207 posts
  • This is Sparta!
  • Location:Bavaria

Posted Wed Aug 6, 2003 3:39 AM

Hi there!

Happy_Dude said:

Very close :) I replaced it with bpl and it works now

Just to see if you learned something: Why does it work with BPL? :wink:

Greetings,
Manuel

#8 Happy_Dude OFFLINE  

Happy_Dude

    River Patroller

  • 4,208 posts
  • Forum Slacker
  • Location:Sydney, Australia

Posted Wed Aug 6, 2003 4:06 AM

Cybergoth said:

Hi there!

Happy_Dude said:

Very close :) I replaced it with bpl and it works now

Just to see if you learned something: Why does it work with BPL? :wink:

Greetings,
Manuel
BPL checks if score,x is "more" than zero.
Because it doesn't need to do anything unless it is zero :wink:

#9 Cybergoth OFFLINE  

Cybergoth

    Quadrunner

  • 8,207 posts
  • This is Sparta!
  • Location:Bavaria

Posted Wed Aug 6, 2003 4:19 AM

Hi there!

Happy_Dude said:

BPL checks if score,x is "more" than zero.
Because it doesn't need to do anything unless it is zero :wink:

Almost. It checks wether it is still positive. If score,x is 0, it still doesn't do anything (and so displays the 0 this frame). But when you decrease it once more, it'll turn to $FF (a negative number!) and then we do something.

With the BNE you used before, you already did something when 0 was reached, so when decreasing from 1 to 0, you immediately switched that to 9, thereby skipping the display of the 0.

Greetings,
Manuel

#10 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!

  • 16,745 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany

Posted Wed Aug 6, 2003 4:21 AM

Happy_Dude said:

BPL checks if score,x is "more" than zero.
Because it doesn't need to do anything unless it is zero :wink:
So how about e.g. x=200 :?:

#11 Happy_Dude OFFLINE  

Happy_Dude

    River Patroller

  • 4,208 posts
  • Forum Slacker
  • Location:Sydney, Australia

Posted Fri Sep 19, 2003 10:46 AM

Thomas Jentzsch said:

Happy_Dude said:

BPL checks if score,x is "more" than zero.
Because it doesn't need to do anything unless it is zero :wink:
So how about e.g. x=200 :?:
I'm looking around for some BCD info and found that I didn't respond to this
(mabey my computer crashed just as I posted like always :roll: )

Anyway, x is the index it can only be 5 to 0.
also, score,x can only be 9 to 0 because this routine resets each digit to 9 after 0 ;)
so no x=200 ;)

I do realise how faulty my explanation of BPL was but I really do understand it ..... (no really I do ....)

#12 Happy_Dude OFFLINE  

Happy_Dude

    River Patroller

  • 4,208 posts
  • Forum Slacker
  • Location:Sydney, Australia

Posted Fri Apr 16, 2004 6:35 AM

It's been awhile but I finaly came back to this little program.
I'v added 2 T.V modes. 50 & 60hz. Use the Colour/B&W switch to change between them.
I'v also added a indicator of what mode you are currently in, which was an exercise in
repositioning the players during the display.
And now you can reset the whole thing by pressing reset

I'd like to know if this works on a real PAL telivision because the values I needed to get 312
scanlines looked way too weird.

Attached Files






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users