A86: Re: displaying value of "A" register


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

A86: Re: displaying value of "A" register




Here's a nifty 23 byte routine I just wrote that will display either A or
HL.  If you only need one or the other, you can save a few bytes and t's.
The reason the <ld h,0> / <sub a> / <ld (de),a> stuff looks a little funny
is because the same code is used for both A and HL.  Any optimizations?

(No, preloading B/C with '0' won't help, because you gain a byte, destroy a
register a pair and only gain t's if the loop runs more than twice)

; in: a or hl = number to print at current cursor position
; out: value of A or HL printed in large font
; destroyed: AF, DE, HL, OP1  (23 bytes total)
DispA:
   ld l,a
   ld h,0
DispHL:
   ld de,_OP1+5
   sub a
   ld (de),a
 DispLoop:
   call _divHLby10      ; UNPACK_HL
   add a,'0'
   dec de
   ld (de),a
   ld a,h
   or l
   jr nz,DispLoop
   ex de,hl
   jp _puts

>
>    Sometime ago I think someone posted a routine to display the number in
>the "A" register.  Could anyone tell me where to find it.  It just need to
>display a number to tell the player how many points they have.  I just need
>to display this number in the top left corner of the screen.