; TITLE "SMHLFDC - Syslib 4.0" NAME ('MHLFDC') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SMHLFDC.Z80 by Richard Conn ; Date : 11 Jun 89 ; Version : 1.3 ; Module : SMHLFDC ; Abstract: This module contains the routine MHLFDC which prints ; the contents of the HL register pair in a one to five ; character field to a Memory buffer. Only the valid char- ; acters are printed. ; Revision: ; 1.4 8 Dec 89 Joe Wright ; Add MHL4 entry for SMHL4DC. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC MHLFDC, MHLD, MHL4 .Z80 CSEG ;=============================================================== ; NAME - MHLFDC ; Entry: HL - Contains the value to be printed ; DE - Points to a 1 to 5 char memory buffer ; Exit : DE - Points to the byte after the last digit stored ; Uses : DE ; Special Requirements: None ;=============================================================== MHLFDC: PUSH BC ; Save BC register LD B,-1 ; Set flag for variable-width store MHLD: LD (MEMPTR),DE ; ..and Buffer address PUSH AF ; Save rest of regs PUSH HL LD DE,10000 ; Save 10000's CALL HDVD JR MHL MHL4: LD (MEMPTR),DE PUSH AF PUSH HL MHL: LD DE,1000 ; Save 1000's CALL HDVD LD DE,100 ; Save 100's CALL HDVD LD DE,10 ; Save 10's CALL HDVD LD A,L ; Save 1's CALL DIV0 ; Convert to Ascii and print POP HL ; Restore all regs POP AF ; ..DE still has MEMPTR+1 POP BC RET ; Divide HL by DE and print quotient with leading 0 suppression HDVD: OR -1 ; Clear carry and set initial count HDVD0: SBC HL,DE ; Divide by subtraction (Cy flag) INC A ; .accumulate count (Z flag) JR NC,HDVD0 ; ..and loop while more to go ADD HL,DE ; Then compensate for underflow JR NZ,DIV0 ; ..jump if A other than Zero OR B ; What was the previous status? RET M ; ..return if No char (suppress store) LD A,' ' ; Else prepare for space JR Z,MO ; ..jump to store 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 MO: LD DE,(MEMPTR) ; ..and get pointer LD (DE),A ; Save character INC DE LD (MEMPTR),DE ; Save the new pointer RET ; Data Storage/Buffers DSEG ; Put in data segment MEMPTR: DEFS 2 ; Ptr to next memory address END