Re: A86: Re: Random Integer


[Prev][Next][Index][Thread]

Re: A86: Re: Random Integer




I think it is Seagoe's routine.  This one displays HL, and is a little
faster, because it only calls UNPACK_HL when there is something left to
divide (i.e. it strips off the leading zeros and converts it all in one
step, not two).  Below that one is one I wrote to display A in hex, in case
anyone finds it useful...
(yes, the loop in the second one beats hard-coding it for both digits)

;====================================================================
; DisplayHL:  (idea from SCaBBy/Mardell)    [Assembly Coder's Zenith]
;  Display HL as a 5-digit decimal number with no leading zeros
;  out: AF, HL, BC, DE destroyed
;====================================================================
DisplayHL:
 ld c,'0'             ; save ascii value for zero
 ld de,_OP1+5         ; point to end of the buffer
 xor a                ; zero terminate string
 ld (de),a            ; set last byte to zero
DisplayHLl:
 call UNPACK_HL       ; next digit
 dec de               ; next position
 add a,c              ; convert to ascii
 ld (de),a            ; save digit
 ld a,h               ; load upper byte
 or l                 ; check with lower byte for zero
 jr nz,DisplayHLl     ; loop
 ex de,hl             ; point to buffer
 call _vputs          ; print number
 ret                  ; we're done

;===========================================
; DispAhex         [Assembly Coder's Zenith]
;  prints A in hexadecimal
; in: A = number to display
; modified: AF, B, HL, OP1
;===========================================
DispAhex:
 ld hl,_OP1
 ld (hl),a
 ld b,2
DispAhexl:
 xor a
 rld
 add a,48   ; '0'
 cp 58    ; '9' + 1
 jr c,DispAhexs
 add a,7   ; 'A' - '9'
DispAhexs:
 call _putc
 djnz DispAhexl
 ret

--
David Phillips <electrum@tfs.net>
ICQ: 13811951
AOL/AIM: Electrum32
86 Central: http://www.tfs.net/~electrum/

-----Original Message-----
From: Cassady Roop <croop@oregontrail.net>
To: assembly-86@lists.ticalc.org <assembly-86@lists.ticalc.org>
Date: Sunday, November 29, 1998 7:33 PM
Subject: Re: A86: Re: Random Integer


>
>> Now, you can use SCaBBy's display a routine (which I don't have handy
( )
>> to display a in var-width font...
>
>Somewhere along the line I picked this up, but I think it is by Joshua
>Seagoe.  ???
>
>;DispA Display A routine by Joshua Seagoe???
>;INPUT-- value in register A
>;OUTPUT-- decimal value, vWidth text, current pen position, no leading
>0's
>;--------------------------------------------------------------------------
>DispA:
>        ld l,a
>        ld h,0
>        ld de,$c08d
>        ld b,3          ;3 digits
>DispA1:
>        call _hldiv10   ;=$4044  a=hl%10  hl=hl/10
>        add a,$30       ;convert to decimal digit
>        ld (de),a       ;store it
>        dec de
>        djnz DispA1
>        xor a
>        ld ($c08e),a    ;end the string
>        ex de,hl
>        ld a,$30        ;trim leading zeros
>        ld b,2          ;take these 7 lines
>DispA2:                 ;out and put in one
>        inc hl          ;inc hl
>        cp (hl)         ;instruction if
>        jp nz,DispA3    ;you want to keep them
>        djnz DispA2     ;
>DispA3:
>        call _vputs     ;display it
>        ret
>
>Cassady Roop
>Slightly Immoral Technologies