view lib/alib/bin_dec.as @ 3220:9ccec98c9897

Updated IDE Driver makefile so it will have place holders for dsk, dskclean, and dskcopy so that make does not error out when chaining into the driver tree to build disk images where applicable.
author David Ladd <drencor-xeen@users.sourceforge.net>
date Wed, 20 Dec 2017 16:10:50 -0600
parents 03f26e88b809
children
line wrap: on
line source

************************************************ 
*
* Binary to decimal conversion

* OTHER MODULES NEEDED: DECTAB$

* ENTRY: X=buffer for ascii string
*        D=binary value to convert

* EXIT: all registers (except cc) preserved

* BGP - 04/11/2009 - Fixed issue where BIN_DEC was printing negative
* sign in certain cases.  Cleared nega flag to fix issue.

 nam Binary to Decimal Conversion
 ttl Assembler Library Module


 section .bss
nega rmb 1
 endsect

 section .text
BIN_SDEC:
 clr nega,u
 tsta
 bpl  BIN_DEC
 sta nega,u
 comb
 coma
 addd #$0001
 bra BIN_DEC_COMMON	+++ added BGP

BIN_DEC:
 clr nega,u		+++ added BGP
BIN_DEC_COMMON
 pshs a,b,x,y
 lda #7 clear out 7 bytes in buffer

bindc1
 clr ,x+
 deca
 bne bindc1
 ldx 2,s restore buffer start address
 ldd ,s get data
 bne bindc2 not 0, do convert
 lda #'0
 sta ,x
 bra bindc8 exit

bindc2
 tst nega,u
 beq bindc25
 pshs a
 lda #'-
 sta ,x+
 puls a
bindc25
 leay DECTAB$,pcr point to conversion table
 clr ,--s temps, flag 1st dgt not placed

bindc3
 clr 1,s current digit=0

bindc4
 subd ,y sub table element
 bcs bindc5 too far, correct
 inc 1,s bump digit
 bra bindc4 loop til done

bindc5
 addd ,y restore, 1 too many subtracts
 pshs a,b save rest of number
 lda 3,s get the digit
 adda #$30 make it ascii
 cmpa #'0 is it zero?
 bne bindc6 no, skip
 tst 2,s is it 1st digit in string?
 beq bindc7 yes, don't do leading 0s

bindc6
 inc 2,s indidicate at least 1 digit
 sta ,x+ save in buffer

bindc7
 leay 2,y next table entry
 tst 1,y end of table
 puls a,b restore data
 bne bindc3 no..loop
 leas 2,s

bindc8
 puls a,b,x,y,pc restore and return

 endsect