Jump to content



0

Help with BCD


13 replies to this topic

#1 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Thu Dec 30, 2004 6:39 PM

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?

#2 CPUWIZ OFFLINE  

CPUWIZ

    Rarity 11

  • 26,327 posts
  • Cartridge Recycler
  • Location:SoCal

Posted Thu Dec 30, 2004 6:43 PM

Why don't you just do this?

lda #$99
sta Timer

:?

#3 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Thu Dec 30, 2004 6:55 PM

CPUWIZ said:

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?

#4 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!

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

Posted Thu Dec 30, 2004 7:01 PM

:idea: Yup, you need hex, so you missed the '$' before 99.

#5 CPUWIZ OFFLINE  

CPUWIZ

    Rarity 11

  • 26,327 posts
  • Cartridge Recycler
  • Location:SoCal

Posted Thu Dec 30, 2004 7:03 PM

vdub_bobby said:

if I want to add 99 to the score, do I need to use hex?

Yes.

#6 Cybergoth OFFLINE  

Cybergoth

    Quadrunner

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

Posted Thu Dec 30, 2004 7:05 PM

Hi there!

vdub_bobby said:

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

#7 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Thu Dec 30, 2004 7:05 PM

Thanks, folks :)

#8 CPUWIZ OFFLINE  

CPUWIZ

    Rarity 11

  • 26,327 posts
  • Cartridge Recycler
  • Location:SoCal

Posted Thu Dec 30, 2004 7:10 PM

Cybergoth said:

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. :P

#9 Cybergoth OFFLINE  

Cybergoth

    Quadrunner

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

Posted Thu Dec 30, 2004 7:13 PM

Hi there!

CPUWIZ said:

Unless, of course, you are trying to add 200 to your score.  :P

So you're getting an idea why nothing in Star Fire or Seawolf scores more than 99 points? ;)

Greetings,
Manuel

#10 CPUWIZ OFFLINE  

CPUWIZ

    Rarity 11

  • 26,327 posts
  • Cartridge Recycler
  • Location:SoCal

Posted Thu Dec 30, 2004 7:19 PM

Cybergoth said:

Hi there!

CPUWIZ said:

Unless, of course, you are trying to add 200 to your score.  :P

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. :D

#11 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!

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

Posted Thu Dec 30, 2004 7:41 PM

CPUWIZ said:

Yep, those pesky extra bytes for a second routine.  :D
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. :)

#12 CPUWIZ OFFLINE  

CPUWIZ

    Rarity 11

  • 26,327 posts
  • Cartridge Recycler
  • Location:SoCal

Posted Thu Dec 30, 2004 7:48 PM

Thomas Jentzsch said:

CPUWIZ said:

Yep, those pesky extra bytes for a second routine.  :D
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.

#13 Cybergoth OFFLINE  

Cybergoth

    Quadrunner

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

Posted Thu Dec 30, 2004 8:10 PM

Hi there!

CPUWIZ said:

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

#14 Andrew Davie OFFLINE  

Andrew Davie

    Stargunner

  • 1,314 posts
  • Location:Tasmania

Posted Thu Dec 30, 2004 9:39 PM

Cybergoth said:

Hi there!

CPUWIZ said:

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




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users