Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- update in: https://pastebin.com/b6i5JTBf
- *=$0801
- BYTE $0B, $08, $0A, $00, $9E, $32, $30, $36, $31, $00, $00, $00
- ;---------------------------------
- Example
- lda #$49
- sta lobyte
- lda #1
- sta hibyte
- jsr _ItoA ; converts Int16 to String
- jsr _trimnum ; trims leading spaces
- ; prints trimmed string
- lda #<CnvTrm
- ldy #>CnvTrm
- jsr $ab1e
- lda #13
- jsr $ffd2
- ; prints untrimmed string
- lda #<CnvStr
- ldy #>CnvStr
- jsr $ab1e
- rts
- ;-------------------------------
- ; Converts a 16bit number to BCD
- ;-------------------------------
- BINBCD16
- SED ; Switch to decimal mode
- LDA #0 ; Ensure the result is clear
- STA bcd+0
- STA bcd+1
- STA bcd+2
- LDX #16 ; The number of source bits
- CNVBIT
- ASL lobyte ; Shift out one bit
- ROL hibyte
- LDA bcd+0 ; And add into result
- ADC bcd+0
- STA bcd+0
- LDA bcd+1 ; propagating any carry
- ADC bcd+1
- STA bcd+1
- LDA bcd+2 ; ... thru whole result
- ADC bcd+2
- STA bcd+2
- DEX ; And repeat for next bit
- BNE CNVBIT
- CLD ; Back to binary
- rts ; All Done.
- ;-------------------------------
- ; Converts a 16bit unsigned number into string
- ;-------------------------------
- ;
- ; Call with 16 bit number in lobyte/hibyte
- ;
- ;-------------------------------
- _ItoA
- jsr BinBcd16
- ;lda bcd+2
- and #$0f
- ora #$30
- sta CnvStr+0
- lda bcd+1
- and #$0f
- ora #$30
- sta CnvStr+2
- lda bcd+1
- lsr
- lsr
- lsr
- lsr
- ora #$30
- sta CnvStr+1
- lda bcd+0
- and #$0f
- ora #$30
- sta CnvStr+4
- lda bcd+0
- lsr
- lsr
- lsr
- lsr
- ora #$30
- sta CnvStr+3
- ; rts ; decomment to avoid stripping leading 0s
- ldx #0 ;remove 0s at beginning
- _rem0 lda CnvStr,x
- cmp #$30
- bne _rts
- lda #$20 ;put a space instead
- sta CnvStr,x
- inx
- cpx #$5
- bne _rem0
- _rts rts
- _trimnum
- ldy #0
- _trmlp lda CnvStr,x
- sta CnvTrm,y
- beq _rts
- inx
- iny
- jmp _trmlp
- bcd byte 0,0,0
- lobyte byte 0
- hibyte byte 0
- CnvStr byte 0,0,0,0,0,0
- CnvTrm byte 0,0,0,0,0,0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement