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
/
SLIB3.LBR
/
SMAFDC.Z80
< prev
next >
Wrap
Text File
|
2000-06-30
|
1KB
|
67 lines
;
; SYSLIB Module Name: SMAFDC
; Author: Richard Conn
; SYSLIB Version Number: 3.6
; Module Version Number: 1.1
public mafdc
;
; MAFDC --
; STORE REG A AS DECIMAL CHARACTERS IN 1-TO-3 CHAR FIELD
; IN MEMORY; ON INPUT, A=VALUE AND DE=PTR TO 3-BYTE BUFFER
; ON RETURN, DE PTS TO BYTE AFTER LAST CHAR STORED
;
MAFDC:
PUSH AF ; SAVE REGS
PUSH BC
PUSH HL
EX DE,HL ; PTR IN HL
LD D,1 ; TURN ON LEADING <SP> FLAG
;
; PRINT ROUTINE
;
PADC1: LD B,100 ; PRINT HUNDREDS
CALL PAC ; PRINT A CHAR
LD B,10 ; PRINT TENS
CALL PAC
ADD '0' ; CONVERT TO ASCII
CALL PUT ; PRINT
EX DE,HL ; PTR BACK IN DE
POP HL ; RESTORE REGS
POP BC
POP AF
RET
;
; PRINT RESULT OF DIVISION OF A BY B (INTEGER DIVISION)
;
PAC: LD C,0 ; SET COUNT
PACL: SUB B ; COMPUTE COUNT
JP C,PACD
INC C ; INCR COUNT
JP PACL
PACD: ADD A,B ; ADD B BACK IN
LD E,A ; SAVE A
LD A,C ; GET COUNT
OR A ; ZERO?
JP NZ,PACD1
OR D ; CHECK FOR LEADING <SP> (A=0, A OR D = 0 MEANS D=0)
LD A,E ; RESTORE A FOR POSSIBLE RETURN
RET NZ ; RETURN IF LEADING <SP>
PACD1: LD D,0 ; D=0 FOR NO LEADING <SP>
LD A,C ; GET COUNT
ADD '0' ; CONVERT TO DECIMAL
CALL PUT ; PRINT IT
LD A,E ; RESTORE A
RET
;
; PUT BYTE IN A IN MEMORY AT ADDRESS PTED TO BY HL; ADVANCE HL
;
PUT:
LD (HL),A ; PUT BYTE
INC HL ; PT TO NEXT
RET
END