Z80 Routines:Other:DispHL: Difference between revisions

From WikiTI
Jump to navigationJump to search
Galandros (talk | contribs)
New page: DispHL DispHL == Unsigned Version == <nowiki>;DispHL, especially adapted to some kind of games (RPG's actually) ;input: hl=num, ...
 
Galandros (talk | contribs)
optimized routine
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:Z80 Routines:Display|DispHL]]
[[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.
;input: hl=num, d=row,e=col, bc=number of algarisms to skip
 
== 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, c=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, with algarisms skiped and spaces for initial zeros
DispHL:
DispHL_games:
push bc
inc c
ld b,1 ;skip 0 flag
ld (CurRow),de
ld (CurRow),de
ld de,OP1
;Number in hl to decimal ASCII
push de
;Thanks to z80 Bits
push de ;save twice...
;inputs: hl = number to ASCII
call Num2Dec
;example: hl=300 outputs '  300'
ex de,hl
;destroys: af, hl, de used
ld (hl),0
ld de,-10000
pop hl
call Num1
jr firsttime
ld de,-1000
nozerodisp:
call Num1
ld (hl),' ' ;suppress starting zeros, but you can delete this code if you don't want it
ld de,-100
inc hl
call Num1
firsttime:
ld e,-10
ld a,(hl)
call Num1
ld e,-1
Num1:
ld a,'0'-1
Num2: inc a
add hl,de
jr c,Num2
sbc hl,de
dec c ;c is skipping
jr nz,skipnum
inc c
djnz notcharnumzero
cp '0'
cp '0'
jr z,nozerodisp
jr nz,notcharnumzero
pop hl
leadingzero:
inc b
skipnum:
ld a,' '
notcharnumzero:
push bc
call PUTCHAR  ;bcall(_PutC) works, not sure if it preserves bc
pop bc
pop bc
add hl,bc
ret</nowiki>
b_call(_PutS)
ret


;also adaptable for a DispA routine!
== Hexadecimal Version ==
DispA:
<nowiki>;Display a 16- or 8-bit number in hex.
ld h,0
DispHLhex:
ld l,a
; Input: HL
ld bc,2
  ld c,h
jr DispHL</nowiki>
  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>


== Signed Version ==
== Decimal Signed Version ==
{{stub}}
{{stub}}
  <nowiki>;
  <nowiki>;DispHL signed
DispHLsign:</nowiki>
;
DispHLdecsigned:
 
 
  ret</nowiki>

Latest revision as of 13:56, 21 April 2010


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, c=number of algarisms to skip
;number of numbers' characters to display: 5 ; example: 65000
;output: hl displayed, with algarisms skiped and spaces for initial zeros
DispHL_games:
	inc c
	ld b,1		;skip 0 flag
	ld (CurRow),de
;Number in hl to decimal ASCII
;Thanks to z80 Bits
;inputs:	hl = number to ASCII
;example: hl=300 outputs '  300'
;destroys: af, hl, de used
	ld	de,-10000
	call	Num1
	ld	de,-1000
	call	Num1
	ld	de,-100
	call	Num1
	ld	e,-10
	call	Num1
	ld	e,-1
Num1:
	ld	a,'0'-1
Num2:	inc	a
	add	hl,de
	jr	c,Num2
	sbc	hl,de
	dec c			;c is skipping
	jr nz,skipnum
	inc c
	djnz notcharnumzero
	cp '0'
	jr nz,notcharnumzero
leadingzero:
	inc b
skipnum:
	ld a,' '
notcharnumzero:
	push bc
	call PUTCHAR  ;bcall(_PutC) works, not sure if it preserves bc
	pop bc
	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
;
DispHLdecsigned:


   ret