; TITLE "SCHLFDC - Syslib 4.0" NAME ('PHLFDC') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SPHLFDC.Z80 by Richard Conn ; Date : 11 Jun 89 ; Version : 1.3 ; Module : SCHLFDC ; Abstract: This module contains the routine PHLFDC which prints ; the contents of the HL register pair in a one to five char- ; acter field on the CON: device. Only the valid characters ; are printed. No registers are affected. ; Revision: ; 1.4 8 Dec 89 Joe Wright ; Added PHL4 entry for PHL4DC and PHL5DC routines. ; Costs three bytes here. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC PHLFDC, PHLD, PHL4 ; From SYSLIB Get.. EXT COUT .Z80 CSEG ;=============================================================== ; NAME - PHLFDC ; Entry: HL - Contains the value to be printed ; Exit : - Nothing returned, the digits are printed to CON: ; Uses : - None ; Special Requirements: None ;=============================================================== PHLFDC: PUSH BC ; Save BC register LD B,-1 ; Set flag for variable-width print PHLD: PUSH HL ; Save the rest of the registers PUSH DE PUSH AF LD DE,10000 ; Print 10000's CALL PHDC1 JR HLD ; ; Called from PHL4DC ; PHL4: PUSH HL ; Save the rest of the registers PUSH DE PUSH AF HLD: 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 CALL DIV0 ; Convert to Ascii and print POP AF ; Restore all regs POP DE POP HL POP BC RET ; Divide HL by DE and print quotient with leading 0 suppression PHDC1: OR -1 ; Clear Carry & Set initial count DIV: SBC HL,DE ; Divide by subtraction INC A ; .accumulate count JR NC,DIV ; ..and loop while more to go ADD HL,DE ; Then compensate for underflow JR NZ,DIV0 ; ..jump if Number other than Zero remains OR B ; What was the previous status? RET M ; ..return if No char (suppress print) LD A,' ' ; Else prepare for Space JR Z,CO ; ..jump to print if Leading Space (0) XOR A ; Otherwise print a Zero DIV0: ADD A,'0' ; Convert to Ascii digit LD B,A ; .and set flag for next pass CO: JP COUT ; ..Jump to CON: device END