Jump to content
IGNORED

Help needed - BCD


Heaven/TQA

Recommended Posts

Hi guys,

 

as some of you might know i am heavily working on a diablo-look a like on a800 (so...thats why i am posting my question here in 2600... ;)) and i am doing some BCD calculations/conversions esp. for the on-screen display. i got bin2bcd routines from www.6502.org but i am not sure if there work with signed numbers as well...

 

so...my question is... does the BCD mode of 6502 calculate with signed numbers as well? is there anything special i have to keep in mind? some of my weapons player can found should have malus instead of bonus and should alter the stats correctly... :)

 

http://www.6502.org/source/

 

so... how would be -5 be represented in BCD?

Link to comment
Share on other sites

issue solved... it seems that negative values can not work in bcd as $fe does not convert correctly to bcd... ;)

 

here is the code

 

	org $4000
	
init cld
lda #-5

jsr writebcd_ascii

ende jmp ende

writebcd_ascii jsr bin2bcd
	lda bcd

writebcd_ascii_direct pha
	lsr @
	lsr @
	lsr @
	lsr @
	ldy #0
	jsr writenumber_ascii
	pla
	and #$0f
writenumber_ascii clc
	adc #48
	sta ascii+1,y
	iny
	rts



;first convert A into BCD
bin2bcd	tax
	lda #"+"
	sta ascii
	txa
	bpl INBCD8	;if already positive then procede as normal
;negative value so make it positve
	eor #$ff
	clc
	adc #1
	ldx #"-"
	stx ascii
INBCD8	SED	; Switch to decimal mode
	sta bin
	LDA #0	; Ensure the result is clear
	STA BCD+0
	STA BCD+1
	LDX #8	; The number of source bits
	
CNVBIT	ASL BIN	; Shift out one bit
	LDA BCD; And add into result
	ADC BCD
	STA BCD
	LDA BCD+1; propagating any carry
	ADC BCD+1
	STA BCD+1
	DEX	; And repeat for next bit
	BNE CNVBIT
	CLD	; Back to binary
	rts

	
	org $0600
bin		dta 0
bcd		dta 0,0

ascii	dta c"+00",0			;holds 2 digits in ascii and the sign 


run init

Link to comment
Share on other sites

so... how would be -5 be represented in BCD?

 

It would be $95. Note that the "N" flag is generally not useful in BCD unless the most negative value used is -$20 (also known as $80); note also that even with that caveat the ADC/SBC instructions will not set the N flag in consistent or useful fashion.

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