; Copyright (C) Reston Publishing Company, Inc. 1983 ; #start TypeCommon -- very common console output routines ----- ; All routines depend on TypeChar, which is part of this unit. ;--------------------------------------------------------------- ; TypeBlank: write a space to the console. ; preserves -- all ; NOTE: exits via TypeChar to save code ;--------------------------------------------------------------- TypeBlank: push psw mvi a,AsciiBlank jmp TypeChar2 ;--------------------------------------------------------------- ; TypeCRLF: write the two characters CR, LF to the console. ; preserves -- all ; NOTE: exits via TypeChar to save on code. ;--------------------------------------------------------------- TypeCRLF: push psw push b push d push h mvi e,AsciiCR mvi c,BdosType call Bdos mvi e,AsciiLF jmp TypeChar3 ;--------------------------------------------------------------- ; TypeMessage: write a string terminated by '$' to the console. ; Input: DE-->string. ; preserves -- all ; NOTE: exits via TypeChar to save code ;--------------------------------------------------------------- TypeMessage: push psw push b push d push h mvi c,BdosString jmp TypeChar4 ; #start TypeChar ---------------------------------------------- ; TypeChar: write the byte in A to the console. ; preserves -- all ;--------------------------------------------------------------- TypeChar: push psw TypeChar2: ; enter here from TypeBlank with A=AsciiBlank push b push d push h mov e,a TypeChar3: ; enter here from TypeCRLF with E=AsciiLF mvi c,BdosType TypeChar4: ; enter here from TypeMessage, DE->msg, C=BdosString call Bdos pop h pop d pop b pop psw ret ; #end TypeChar ; #end TypeCommon ; #start TypeString -------------------------------------------- ; ; TypeString: HL--> a string of characters terminated by 00h. ; Send the string to the console. ; preserves -- all ;--------------------------------------------------------------- TypeString: push psw push b push d push h ; TypeString1: mov a,m ora a ; end of the string? JRZ TypeString2 ; (yes, quit) push h ; save HL->next byte over Bdos call mov e,a mvi c,BdosType call Bdos pop h ; recover data-pointer inx h ; ..and step it JMPR TypeString1 ; TypeString2: pop h pop d pop b pop psw ret ; #end TypeString ; #start TypeXXXX (includes TypeXX) ---------------------------- ; ; TypeXXXX: Display the word in HL as four hex digits at the ; console. ; preserves -- all ;--------------------------------------------------------------- TypeXXXX: push psw mov a,h call TypeXX mov a,l jmp TypeXX2 ; #start TypeXX ------------------------------------------------ ; ; TypeXX: Display the byte in A, as two hex digits, at the ; console. ; preserves -- all ;--------------------------------------------------------------- TypeXX: push psw TypeXX2: ; enter here from TypeXXXX, A=2nd byte of word push psw ; save over first conversion call HexDisplayL ; get the left nybble call TypeChar ; and type it pop psw ; recover the byte, get the call HexDisplayR ; least significant bits call TypeChar ; and type them. pop psw ret ; #include TypeSubs.Inc,TypeChar ; #include Arithlib.Inc,HexDisplay ; #end TypeXX ; #end TypeXXXX ; #start Type9999 ---------------------------------------------- ; ; Type9999: Type the number in HL as four decimal digits. This ; is a faster, simpler, decimal output routine than the others ; in this unit. It is restricted to numbers from 0..9999. The ; high-order digit of a number outside that range will be lost, ; so that, say, 65535 will print as 5535. ; preserves -- all ;--------------------------------------------------------------- Type9999: push psw push b push d ; call UnpackBCD ; DE:=4 BCD digits xchg ; put them in HL, call TypeXXXX ; ..print them. xchg ; pop d pop b pop psw ret ; #include TypeSubs.Inc,TypeXXXX ; #include Arithlib.Inc,UnpackBCD ; #end Type9999 ; #start TypeDecimal ------------------------------------------- ; ; Each of these routines types a binary integer as decimal with ; leading zeros suppressed. They differ as follows: ; ; TypeZZ9 : takes a single byte in A, types 0..255 ; TypeZZZZ9 : takes a word in HL, types 0..65535 ; TypeSint : takes a word in HL, types "-32767".." 32767" ; ; Note that TypeSint is the only routine for signed numbers. ; All three routines preserve the BC, DE, and HL registers. All ; three return in the A register the number of bytes typed, so ; that the caller can keep track of the output column number. ; ;--------------------------------------------------------------- TypeZZ9: push b push d push h mvi h,0 mov l,a ; HL= 00xx JMPR TypeZZZZ9X ; share code with other routines ; TypeZZZZ9: push b push d push h TypeZZZZ9X: ; enter here from TypeZZ9 mvi b,0 ; no bytes typed yet JMPR TypeSint3 ; share code with TypeSint ; TypeSint: push b push d push h ; ; Type the sign byte. Note that the constants "DecimalPlus" and ; "DecimalMinus" are declared in SET statements in CPMEQU.LIB. ; They can be re-declared with SET statements preceding the ; include of this routine. ; mov a,h ora a ; transfer sign to flags mvi a,DecimalPlus ; assume positive number jp TypeSint2 ; (it is) mov a,h ; HL is minus, complement it cma mov h,a mov a,l cma mov l,a inx h ; two's complement of HL mvi a,DecimalMinus TypeSint2: call TypeChar ; type the sign byte, and mvi b,1 ; ..account for its length. ; ; Enter here from TypeZZZZ9, TypeZZ9, with B=0. ; TypeSint3: call UnpackBCD ; C,D,E = 0d,dd,dd ; ; Find out how many digits we have to do, and do them ; mov a,c ora a ; five digits? JRNZ TypeSintD5 ; (yes) mov a,d cpi 10 ; four digits? JRNC TypeSintD4 ; (yes) ora a ; three digits? JRNZ TypeSintD3 ; (yes) mov a,e cpi 10 ; well, two then? JRNC TypeSintD2 ; (yes) JMPR TypeSintD1 ; no, but one digit always ; TypeSintD5: call TypeSintR ; type right digit of A=C TypeSintD4: mov a,d call TypeSintL ; left digit of d TypeSintD3: mov a,d call TypeSintR ; right digit of d TypeSintD2: mov a,e call TypeSintL ; left digit of e TypeSintD1: mov a,e call TypeSintR ; right digit of e ; mov a,b ; return byte-count in a pop h pop d pop b ret ; ; Inner routines of TypeSint to type one bcd digit from A, ; and increment the byte count in B. Do the Bdos call here ; to save some time over a call to TypeChar (and the need ; of including it). ; TypeSintL: rar rar rar rar TypeSintR: push b ; save just two essential regs push d ani 0Fh ; clear garbage, adi '0' ; convert to Ascii-decimal mov e,a mvi c,BdosType call Bdos pop d pop b inr b ; count the byte ret ; #include Arithlib.inc,UnpackBCD ; #end TypeDecimal  c,BdosType call Bdos pop d pop b inr b ; count the byte ret