; Copyright (C) Reston Publishing Company, Inc. 1983 ; #start PutCommon -- very common file output routines --------- ;--------------------------------------------------------------- ; PutBlank: write a space to the utility output file. ; preserves -- all ;--------------------------------------------------------------- PutBlank: push psw mvi a,AsciiBlank call PutChar pop psw ret ;--------------------------------------------------------------- ; PutCRLF: write the two characters CR, LF to utility output. ; preserves -- all ;--------------------------------------------------------------- PutCRLF: push psw mvi a,AsciiCR call PutChar mvi a,AsciiLF call PutChar pop psw ret ;--------------------------------------------------------------- ; PutString: HL--> a string of characters terminated by 00h. ; Send the string to the utility output file. ; preserves -- all ;--------------------------------------------------------------- PutString: push psw push h ; PutString1: mov a,m ora a ; end of the string? JRZ PutString2 ; (yes, quit) call PutChar ; no, send this byte inx h ; ..and step pointer JMPR PutString1 ; PutString2: pop h pop psw ret ; #end PutCommon ; #start PutTab ------------------------------------------------ ; PutTab: write a tab to the utility output file. Assuming that ; the B register contains an origin-1 column count, return in A ; the column count after the tab is written (if B doesn't ; contain a column count, no harm is done). ; preserves -- BC, DE, HL ;--------------------------------------------------------------- PutTab: mvi a,AsciiTAB call PutChar mov a,b dcr a ; make the count origin-zero ori 0111b inr a ; round to next 8-multiple inr a ; make origin-one again ret ; #end PutTab ; #start PutXXXX (includes PutXX) ------------------------------ ; ; PutXXXX: Write the word in HL as four hex digits to the ; utility output file. ; preserves -- all ;--------------------------------------------------------------- PutXXXX: push psw mov a,h call PutXX mov a,l jmp PutXX2 ; #start PutXX ------------------------------------------------- ; ; PutXX: Write the byte in A as two hex digits to the utility ; output file. ; preserves -- all ;--------------------------------------------------------------- PutXX: push psw PutXX2: ; enter here from PutXXXX, A=2nd byte of word push psw ; save over first conversion call HexDisplayL ; get the left nybble call PutChar ; and write it pop psw ; recover the byte, get the call HexDisplayR ; least significant bits call PutChar ; and write them. pop psw ret ; #include Arithlib.Inc,HexDisplay ; #end PutXX ; #end PutXXXX ; #start Put9999 ----------------------------------------------- ; ; Put9999: Send the number in HL as four decimal digits to the ; utility output file. This is a faster, simpler decimal output ; routine than the zero-suppressors that follow. It is limited ; 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 ;--------------------------------------------------------------- Put9999: push psw push b push d ; call UnpackBCD ; DE:=4 BCD digits xchg ; put them in HL, call PutXXXX ; ..print them. xchg ; pop d pop b pop psw ret ; #include Putsubs.Inc,PutXXXX ; #include Arithlib.Inc,UnpackBCD ; #end Put9999 ; #start PutDecimal -------------------------------------------- ; ; Each of these routines writes a binary integer as decimal with ; leading zeros suppressed. They differ as follows: ; ; PutZZ9 : takes a single byte in A, writes 0..255 ; PutZZZZ9 : takes a word in HL, writes 0..65535 ; PutSint : takes a word in HL, writes "-32767".." 32767" ; ; Note that PutSint 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 sent, so ; that the caller can keep track of the output column number. ; ;--------------------------------------------------------------- PutZZ9: push b push d push h mvi h,0 mov l,a ; HL= 00xx JMPR PutZZZZ9X ; share code with other routines ; PutZZZZ9: push b push d push h PutZZZZ9X: ; enter here from PutZZ9 mvi b,0 ; no bytes sent yet JMPR PutSint3 ; share code with PutSint ; PutSint: push b push d push h ; ; Send 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 PutSint2 ; (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 PutSint2: call PutChar ; send the sign byte, and mvi b,1 ; ..account for its length. ; ; Enter here from PutZZZZ9, PutZZ9, with B=0. ; PutSint3: 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 PutSintD5 ; (yes) mov a,d cpi 10 ; four digits? JRNC PutSintD4 ; (yes) ora a ; three digits? JRNZ PutSintD3 ; (yes) mov a,e cpi 10 ; well, two then? JRNC PutSintD2 ; (yes) JMPR PutSintD1 ; no, but one digit always ; PutSintD5: call PutSintR ; send right digit of A=C PutSintD4: mov a,d call PutSintL ; left digit of d PutSintD3: mov a,d call PutSintR ; right digit of d PutSintD2: mov a,e call PutSintL ; left digit of e PutSintD1: mov a,e call PutSintR ; right digit of e ; mov a,b ; return byte-count in a pop h pop d pop b ret ; ; Inner routines of PutSint to send one bcd digit from A, ; and increment the byte count in B. ; PutSintL: rar rar rar rar PutSintR: ani 0Fh ; clear garbage, adi '0' ; convert to Ascii-decimal call PutChar inr b ; count the byte ret ; #include Arithlib.inc,UnpackBCD ; #end PutDecimal  convert to Ascii-decimal call PutChar inr b ; count the byte ret ; #include Arithlib.inc,UnpackBC