Difference between revisions of "Z80 Routines:Other:DispHL"

From WikiTI
Jump to: navigation, search
(New page: DispHL DispHL == Unsigned Version == <nowiki>;DispHL, especially adapted to some kind of games (RPG's actually) ;input: hl=num, ...)
 
(added description, hex version and optimized the decimal version. all tested!)
Line 1: Line 1:
 
[[Category:Z80 Routines:Other|DispHL]]
 
[[Category:Z80 Routines:Other|DispHL]]
 
[[Category:Z80 Routines|DispHL]]
 
[[Category:Z80 Routines|DispHL]]
== Unsigned Version ==
 
  
  <nowiki>;DispHL, especially adapted to some kind of games (RPG's actually)
+
Simple and small routines that print the value of z80 register pair hl.
 +
 
 +
== Decimal Unsigned Versions ==
 +
 
 +
* First a simple and small to show. Mostly for debugging or simple programs.
 +
  <nowiki>;Number in hl to decimal ASCII
 +
;Thanks to z80 Bits
 +
;inputs: hl = number to ASCII
 +
;example: hl=300 outputs '00300'
 +
;destroys: af, bc, hl, de used
 +
DispHL:
 +
ld bc,-10000
 +
call Num1
 +
ld bc,-1000
 +
call Num1
 +
ld bc,-100
 +
call Num1
 +
ld c,-10
 +
call Num1
 +
ld c,-1
 +
Num1: ld a,'0'-1
 +
Num2: inc a
 +
add hl,bc
 +
jr c,Num2
 +
sbc hl,bc
 +
call PUTCHAR
 +
ret </nowiki>
 +
 
 +
<nowiki>;Bonus! DispA routine
 +
;adaptable for a DispA routine or any other 8-bit register
 +
DispA:
 +
ld h,0
 +
ld l,a
 +
jp DispHL</nowiki>
 +
 
 +
* DispHL especially adapted to games (nifty to RPG)
 +
 
 +
<nowiki>;DispHL for games
 
;input: hl=num, d=row,e=col, bc=number of algarisms to skip
 
;input: hl=num, d=row,e=col, bc=number of algarisms to skip
 
;number of numbers' characters to display: 5 ; example: 65000
 
;number of numbers' characters to display: 5 ; example: 65000
 
;output: hl displayed
 
;output: hl displayed
DispHL:
+
DispHL_game:
 
push bc
 
push bc
 
ld (CurRow),de
 
ld (CurRow),de
Line 28: Line 64:
 
pop bc
 
pop bc
 
add hl,bc
 
add hl,bc
b_call(_PutS)
+
call PUTSTR ;b_call(_PutS)
ret
+
ret </nowiki>
  
;also adaptable for a DispA routine!
+
<!-- It would be good a optimized version but I don't know how to avoid OP1 temp use -->
DispA:
+
ld h,0
+
ld l,a
+
ld bc,2
+
jr DispHL</nowiki>
+
  
== Signed Version ==
+
== Hexadecimal Version ==
 +
<nowiki>;Display a 16- or 8-bit number in hex.
 +
DispHLhex:
 +
; Input: HL
 +
  ld  c,h
 +
  call  OutHex8
 +
  ld  c,l
 +
OutHex8:
 +
; Input: C
 +
  ld  a,c
 +
  rra
 +
  rra
 +
  rra
 +
  rra
 +
  call  Conv
 +
  ld  a,c
 +
Conv:
 +
  and  $0F
 +
  add  a,$90
 +
  daa
 +
  adc  a,$40
 +
  daa
 +
  call PUTCHAR  ;replace by bcall(_PutC) or similar
 +
  ret
 +
</nowiki>
 +
 
 +
== Decimal Signed Version ==
 
{{stub}}
 
{{stub}}
  <nowiki>;
+
  <nowiki>;DispHL signed
DispHLsign:</nowiki>
+
;
 +
DispHLsign:
 +
 
 +
</nowiki>

Revision as of 09:07, 28 November 2009


Simple and small routines that print the value of z80 register pair hl.

Decimal Unsigned Versions

  • First a simple and small to show. Mostly for debugging or simple programs.
;Number in hl to decimal ASCII
;Thanks to z80 Bits
;inputs:	hl = number to ASCII
;example: hl=300 outputs '00300'
;destroys: af, bc, hl, de used
DispHL:
	ld	bc,-10000
	call	Num1
	ld	bc,-1000
	call	Num1
	ld	bc,-100
	call	Num1
	ld	c,-10
	call	Num1
	ld	c,-1
Num1:	ld	a,'0'-1
Num2:	inc	a
	add	hl,bc
	jr	c,Num2
	sbc	hl,bc
	call PUTCHAR
	ret 
;Bonus! DispA routine
;adaptable for a DispA routine or any other 8-bit register
DispA:
	ld h,0
	ld l,a
	jp DispHL
  • DispHL especially adapted to games (nifty to RPG)
;DispHL for games
;input: hl=num, d=row,e=col, bc=number of algarisms to skip
;number of numbers' characters to display: 5 ; example: 65000
;output: hl displayed
DispHL_game:
	push bc
	ld (CurRow),de
	ld de,OP1
	push de
	push de		;save twice...
	call Num2Dec
	ex de,hl
	ld (hl),0
	pop hl
	jr firsttime
nozerodisp:
	ld (hl),' '	;suppress starting zeros, but you can delete this code if you don't want it
	inc hl
firsttime:
	ld a,(hl)
	cp '0'
	jr z,nozerodisp
	pop hl
	pop bc
	add hl,bc
	call PUTSTR		;b_call(_PutS)
	ret 


Hexadecimal Version

;Display a 16- or 8-bit number in hex.
DispHLhex:
; Input: HL
   ld  c,h
   call  OutHex8
   ld  c,l
OutHex8:
; Input: C
   ld  a,c
   rra
   rra
   rra
   rra
   call  Conv
   ld  a,c
Conv:
   and  $0F
   add  a,$90
   daa
   adc  a,$40
   daa
   call PUTCHAR  ;replace by bcall(_PutC) or similar
   ret
 

Decimal Signed Version

This article is a stub. You can help WikiTI by expanding it.


;DispHL signed
;
DispHLsign: