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
/
SMADC.Z80
< prev
next >
Wrap
Text File
|
2000-06-30
|
2KB
|
83 lines
;
; SYSLIB Module Name: SMADC
; Author: Richard Conn
; SYSLIB Version Number: 3.6
; Module Version Number: 1.1
public ma3dc,madc
;
; MA3DC --
; STORE REG A AS 3 DECIMAL CHARACTERS IN MEMORY
; ON INPUT, A=VALUE AND DE=PTR TO 3-BYTE BUFFER
; ON RETURN, DE PTS TO BYTE AFTER BUFFER
;
MA3DC:
EX DE,HL ; PTR IN HL
PUSH AF ; SAVE A
PUSH AF
XOR A ; TURN OFF LEADING <SP> FLAG
LD (LSFLG),A
JP PADC1
;
; MADC --
; STORE REG A AS DECIMAL CHARACTERS W/LEADING <SP> IN 3-CHAR FIELD
; IN MEMORY; ON INPUT, A=VALUE AND HL=PTR TO 3-BYTE BUFFER
; ON RETURN, HL PTS TO BYTE AFTER BUFFER
;
MADC:
EX DE,HL ; PTR IN HL
PUSH AF ; SAVE A
PUSH AF
LD A,1 ; TURN ON LEADING <SP> FLAG
LD (LSFLG),A
;
; PRINT ROUTINE
;
PADC1: POP AF ; GET A
PUSH BC ; SAVE BC
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
POP BC ; RESTORE BC
POP AF ; RESTORE A
EX DE,HL ; PTR BACK IN DE
RET
; BUFFER
LSFLG: DS 1 ; LEADING <SP> FLAG
; PRINT RESULT OF DIVISION OF A BY B W/LEADING <SP> (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
PUSH AF ; SAVE A
LD A,C ; GET COUNT
OR A ; ZERO?
JP NZ,PACD1
LD A,(LSFLG) ; CHECK FOR LEADING <SP>
OR A ; 0 MEANS NO
JP Z,PACD1
LD A,' ' ; PRINT <SP>
CALL PUT
POP AF ; RESTORE A
RET
PACD1: XOR A ; A=0
LD (LSFLG),A ; TURN OFF LEADING <SP> FLAG
LD A,C ; GET COUNT
ADD '0' ; CONVERT TO DECIMAL
CALL PUT ; PRINT IT
POP AF ; RESTORE A
RET
PUT:
LD (HL),A ; PUT BYTE
INC HL ; PT TO NEXT
RET
END