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
/
SLHL5DC.Z80
< prev
next >
Wrap
Text File
|
2000-06-30
|
2KB
|
91 lines
;
; SYSLIB Module Name: SLHL5DC
; Author: Richard Conn
; SYSLIB Version Number: 3.6
; Module Version Number: 1.2
public lhl5dc,lhldc
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
;
; LHL5DC --
; PRINT HL AS 5 DECIMAL CHARACTERS ON LST:
;
LHL5DC:
PUSH AF ; SAVE ALL REGS
PUTRG
LD B,0 ; B=0 FOR NO LEADING <SP>
JP LHDC
;
; LHLDC --
; PRINT HL AS DECIMAL CHARACTERS W/LEADING SPACES IN 5-CHAR FIELD
; ON LST:
;
LHLDC:
PUSH AF ; SAVE ALL REGS
PUTRG
LD B,1 ; A=1 FOR LEADING <SP>
;
; PRINT HL USING LEADING <SP> FLAG IN B
;
LHDC: 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 A,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 IF B=0)
JP Z,PHDC4
LD A,' ' ; PRINT <SP>
JP LOUT
PHDC4: LD B,0 ; TURN OFF LEADING <SP>
LD A,C ; GET VALUE
ADD '0' ; CONVERT TO ASCII
JP LOUT
END