Heaven/TQA Posted August 20, 2006 Share Posted August 20, 2006 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? Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted August 20, 2006 Author Share Posted August 20, 2006 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 Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted August 20, 2006 Share Posted August 20, 2006 Use SBC #$05 to subtract 5 in decimal mode. Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted August 20, 2006 Author Share Posted August 20, 2006 yes... that would be a solution but i want to have a hex value, doesnt matter if positive or negative range into BCD and then into an ascii string "+00" or "-00" to print that correctly on screen... Quote Link to comment Share on other sites More sharing options...
supercat Posted August 20, 2006 Share Posted August 20, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.