home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
ZSYS
/
SIMTEL20
/
SYSLIB
/
SLIB2.LBR
/
SLHLFDC.Z80
< prev
next >
Wrap
Text File
|
2000-06-30
|
2KB
|
80 lines
;
; SYSLIB Module Name: SLHLFDC
; Author: Richard Conn
; SYSLIB Version Number: 3.6
; Module Version Number: 1.1
public lhlfdc
EXT LOUT
PUTRG MACRO
PUSH BC ; SAVE BC, DE, HL
PUSH DE
PUSH HL
ENDM
GETRG MACRO
POP HL ; RESTORE HL, DE, BC
POP DE
POP BC
ENDM
;
; LHLFDC --
; PRINT HL AS DECIMAL CHARACTERS IN N-CHAR FIELD ON LST:
; FLOATING PRINT, WHERE FIELD SIZE IS FROM 1 TO 5 CHARS
;
LHLFDC:
PUSH AF ; SAVE ALL REGS
PUTRG
LD B,1 ; B=1 FOR LEADING <SP>
;
; PRINT HL USING LEADING <SP> FLAG IN B
;
LD DE,10000 ; PRINT 10000'S
CALL PHDC1
LD DE,1000 ; PRINT 1000'S
CALL PHDC1
LD DE,100 ; PRINT 100'S
CALL PHDC1
LD DE,10 ; PRINT 10'S
CALL PHDC1
LD A,L ; PRINT 1'S
ADD '0' ; CONVERT TO ASCII
CALL LOUT
GETRG ; RESTORE ALL REGS
POP AF
RET
;
; DIVIDE HL BY DE AND PRINT QUOTIENT WITH LEADING <SP>S
;
PHDC1: LD C,0 ; SET COUNT
PHDC2: LD A,L ; SUB E FROM L
SUB E
LD L,A ; RESULT IN L
LD A,H ; SUB D FROM H W/BORROW
SBC A,D
LD H,A ; RESULT IN H
JP C,PHDC3 ; DONE IF CARRY SET (FURTHER BORROW)
INC C ; INCR COUNT
JP PHDC2
PHDC3: LD A,L ; ADD E TO L
ADD E
LD L,A ; RESULT IN L
LD A,H ; ADD D TO H W/CARRY
ADC A,D
LD H,A ; RESULT IN H
LD A,C ; GET RESULT
OR A ; CHECK FOR ZERO
JP NZ,PHDC4
OR B ; 0=NO LEADING SP (A=0, A OR B = 0 MEANS B = 0)
RET NZ
PHDC4: LD B,0 ; TURN OFF LEADING <SP>
LD A,C ; GET VALUE
ADD '0' ; CONVERT TO ASCII
JP LOUT
END