Jump to content
IGNORED

Help with BCD


vdub_bobby

Recommended Posts

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?

Link to comment
Share on other sites

Hi there!

 

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Hi there!

 

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Hi there!

 

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...