Re: A82: Displaying value of HL


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

Re: A82: Displaying value of HL



At 03:41 AM 8/24/97 -0500, you wrote:
>    
>    Hallo, I am aware of D_HL_DECI for displaying the value of HL in 
>the big text, but how for the small used on the graph screen? Routine, 
>pointing in the right direction, anything useful. I am suspicious that 
>you need to use UNPACK_HL in some way, is this correct? Thank you,
>                                ~Kurai

Here is the source for DM_HL_DECI, just CALL_(DM_HL_DECI) with a value
between 0 and 65535 stored in HL.

NOTE:  Its not very optimized, but it does the job without additional
spaces.  It also does NOT use UNPACK_HL which speeds it up a little bit
(but that speed is lost with the call to CP_HL_DE).

DM_HL_DECI:
  push af                  ; Temporarily store af on the stack
  push bc                  ; Temporarily store bc on the stack
  push de                  ; Temporarily store de on the stack
  push hl                  ; Temporarily store hl on the stack
  ld b,48                  ; 48 -> b
  ld c,4                   ; 4 -> c
  ld a,h                   ; h -> a
  or l                     ; If a=0 and l=0, then return zero
  jr z,DM_HL_3             ; If zero, then jump to DM_HL_3
  ld c,-1                  ; -1 -> c
  ld b,46                  ; 46 -> b
  jr DM_HL_NEXT2           ; Jump to DM_HL_NEXT2
DM_HL_INIT:
  call CP_HL_DE            ; cp hl,de
  jr c,DM_HL_NEXT2         ; If carry, then jump to DM_HL_NEXT2
  dec c                    ; c = c - 1
DM_HL_NEXT:
  ld b,47                  ; 47 -> b
DM_HL_NEXT2:
  inc c                    ; c = c + 1
  ld a,c                   ; c -> a
  or a                     ; If a=0, then return zero
  ld de,10000              ; 10000 -> de
  jr z,DM_HL_2a            ; If zero, then jump to DM_HL_2a
  cp 1                     ; If a=1, then return zero
  ld de,1000               ; 1000 -> de
  jr z,DM_HL_2a            ; If zero, then jump to DM_HL_2a
  cp 2                     ; If a=2, then return zero
  ld de,100                ; 100 -> de
  jr z,DM_HL_2a            ; If zero, then jump to DM_HL_2a
  cp 3                     ; If a=3, then return zero
  ld de,10                 ; 10 -> de
  jr z,DM_HL_2a            ; If zero, then jump to DM_HL_2a
  ld de,1                  ; 1 -> de
DM_HL_2a:
  ld a,b                   ; b -> a
  cp 46                    ; If a=46, then return zero
  jr z,DM_HL_INIT          ; If zero, then jump to DM_HL_INIT
DM_HL_2b:
  inc b                    ; b = b + 1
  call CP_HL_DE            ; cp hl,de
  jr c,DM_HL_3             ; If carry, then jump to DM_HL_3
  or a                     ; Reset carry flag
  sbc hl,de                ; hl = hl - de
  jr DM_HL_2b              ; Jump to DM_HL_2b
DM_HL_3:
  ld a,b                   ; b -> a
  ROM_CALL(M_CHARPUT)      ; Display the character
  ld a,c                   ; c -> a
  cp 4                     ; If a=4, then return zero
  jr nz,DM_HL_NEXT         ; If not zero, then jump to DM_HL_NEXT
  pop hl                   ; Retrieve hl from the stack
  pop de                   ; Retrieve de from the stack
  pop bc                   ; Retrieve bc from the stack
  pop af                   ; Retrieve af from the stack
  ret                      ; Return to caller

The only advantage that I can think of to using this routine is that is has
no leading spaces.  Hope I could be of help.


                 Thomas J. Hruska -- thruska@tir.com
Shining Light Productions -- "Meeting the needs of fellow programmers"
         http://www.geocities.com/SiliconValley/Heights/8504
                    http://shinelight.home.ml.org


References: