;Small Set of System Subroutines ;Morrow Designs, Inc. ;Namdar Bolour ;25-Jul-84 ;------------------------------------------------------------------------- ;Collection of often-needed display and conversion subroutines. Use them ;by linking this file with yours, and declaring the subroutines you need ;as External. ;--------------------------------------------------------------------------- ; Cseg .z80 .Radix 16 Include SYSEQU ;System constants defintion file. Public ShoNum, WrtNum, BinHex, NibHex ;------------------------------------------------------------------------ ;Subroutine to write in hex a byte or 2 bytes, interpreted as a binary ;unsigned integer, preceded by a caption. ; ;On entry: ; DE = pointer to caption string (must end with CP/M '$' end flag), ; A = zero means write just the byte in C, ; A = non-zero means write the 2 bytes in BC, with B the most sig. ; byte, ; BC = binary integer to write, in C if single byte, or in BC if ; 2 bytes. ;On exit: ; Caption first, then value of C or BC, are witten to console. ;Registers preserved: IX, IY. ; ShoNum: Push AF ;Save # bytes indicator. Push BC ;Save # to convert. Ld C, PrtStr ;First write Call Bdos ;the caption. Pop BC ;Restore # to convert. Pop AF ;Restore # bytes indicator. Call WrtNum ;Write the number. Ret ;------------------------------------------------------------------------ ;Subroutine to write in hex a byte or 2 bytes, interpreted as a binary ;unsigned integer. ; ;On entry: ; A = zero means write just the byte in C, ; A = non-zero means write the 2 bytes in BC, with B the most sig. ; byte, ; BC = binary integer to write, in C if single byte, or in BC if ; 2 bytes. ;On exit: ; Value of C or BC, are witten to console. ;Registers preserved: IX, IY. ; WrtNum: Ld HL, HexDigitString ;Start of hex digit string. Or A ;Write BC or just C? JR Z, OneByte ;Write just C. Ld A, B ;Write BC: Convert upper byte Call BinHex ;to 2 hex digits. Ld (HL), D ;Put Inc HL ;into Ld (HL), E ;hex digit Inc HL ;string. OneByte: Ld A, C ;Convert lower byte Call BinHex ;to 2 hex digits. Ld (HL), D ;Put Inc HL ;into Ld (HL), E ;hex digit string. Inc HL Ld (HL), 'H' ;Hex indicator at end of string. Inc HL Ld (HL), '$' ;CP/M string terminator. Ld C, PrtStr ;Now write the Ld DE, HexDigitString ;hex digit string. Call Bdos Ret HexDigitString: DS 4 ;Ascii hex digit storage area. DS 2 ;For 'H' hex indicator letter and ;'$' string terminator. ;--------------------------------------------------------------------------- ;Subroutine to convert a byte into 2 ASCII hexadecimal digits. ; ;On entry: A = byte to convert. ; ;On exit: DE = the 2 ASCII hex digits, with D containing the most ; siginificant digit. ; ;Registers preserved: C, HL, IX, IY. ; BinHex: Ld B, A ;Save byte to convert. Call NibHex ;Convert lower nibble Ld E, A ;and return in E. Ld A, B ;Restore original byte. RRCA ;Shift upper RRCA ;nibble into RRCA ;lower RRCA ;nibble. Call NibHex ;Convert upper nibble Ld D, A ;and return in D. Ret ;--------------------------------------------------------------------------- ;Subroutine to convert the lower nibble of a byte into an ASCII hex digit. ; ;On entry: A = byte containing the nibble in its 4 least sig. bits - ; the upper 4 bits are disregarded. ; ;On exit: A = the ASCII hex digit. ; ;Registers preserved: BC, DE, HL, IX, IY. ; NibHex: And 0f ;Zero upper 4 bits. Add A, '0' ;Assume digit won't be alphabetic, ;(i.e., it won't be a - f) Cp ':' ;If so, Ret C ;done. Add A, 'a' - ':' ;Else add # of ASCII chars. between Ret ;'9' and 'a'. END