home *** CD-ROM | disk | FTP | other *** search
- List-
-
- ;=============================================================================
- ; Basic I/O Macro Interface
- ;
- ; These macros provide an interface with IO.ASM. They provide methods to
- ; manipulate strings and processes simple I/O. BP might be used by the
- ; macros to set up the interface parameters, so it should not be used to pass
- ; parameters to the macros. See IO.ASM for a description of string formats,
- ; how string addresses are passed, and other pertinent information.
- ;
- ; Here is a brief summary of the available macros:
- ;
- ; String Keyboard Display Attribute Cursor Speaker File
- ; --------- -------- --------- --------- ------ ------- ------
- ; LOAD INPUT CLS NORMAL HOME BELL OPEN
- ; CLEAR KEYBOARD DISPLAY BOLD LEFT BEEP CREATE
- ; TRUNCATE LINE UNDERLINE UP SOUND DELETE
- ; COPY BLINK DOWN READ
- ; APPEND REVERSE SPOS WRITE
- ; FORMAT RPOS SEEK
- ; JUSTIFY LOCATE SIZE
- ; LOWERCASE CLOSE
- ; UPPERCASE
- ; BINARY
- ; DECIMAL
- ; TIME
-
- ;================================================
- ; Load a destination and source address.
- ;
- ; DES_OFF - destination offset: 16 bit operand.
- ; DES_SEG - destination segment: 16 bit operand.
- ; SEG_OFF - source offset: 16 bit operand.
- ; SEG_SEG - source segment: 16 bit operand.
-
- Load Macro Des_Off, Des_Seg, Src_Off, Src_Seg
- Load_Address Des_Off, Des_Seg
- Load_Address Src_Off, Src_Seg
- Endm
-
- ;================================================
- ; Clear a string (set its length to zero). The
- ; address is returned.
- ;
- ; OFF - offset: 16 bit operand.
- ; SEG - segment: 16 bit operand.
-
- Clear Macro Off, Seg
- Load_Address Off, Seg
- Call Clear_Str_P
- Endm
-
- ;================================================
- ; Trucate a string (set its length to defined value).
- ; The string location is returned.
- ;
- ; OFF - offset: 16 bit operand.
- ; SEG - segment: 16 bit operand.
- ; LENGTH - new string length: 8 bit register or
- ; immediate data.
-
- Truncate Macro Off, Seg, Length
- Load_Address Off, Seg
- Sub Sp, 2
- Mov Bp, Sp
- Mov Byte [Bp], Length
- Call Truncate_Str_P
- Endm
-
- ;================================================
- ; Copy the source string to the destination. The
- ; destination string is returned.
- ;
- ; DES_OFF - destination offset: 16 bit operand.
- ; DES_SEG - destination segment: 16 bit operand.
- ; SEG_OFF - source offset: 16 bit operand.
- ; SEG_SEG - source segment: 16 bit operand.
-
- Copy Macro Des_Off, Des_Seg, Src_Off, Src_Seg
- Load_Address Des_Off, Des_Seg
- Load_Address Src_Off, Src_Seg
- Call Copy_Str_P
- Endm
-
- ;================================================
- ; Append the source string to the destination. The
- ; destination string is returned.
- ;
- ; DES_OFF - destination offset: 16 bit operand.
- ; DES_SEG - destination segment: 16 bit operand.
- ; SEG_OFF - source offset: 16 bit operand.
- ; SEG_SEG - source segment: 16 bit operand.
-
- Append Macro Des_Off, Des_Seg, Src_Off, Src_Seg
- Load_Address Des_Off, Des_Seg
- Load_Address Src_Off, Src_Seg
- Call Append_Str_P
- Endm
-
- ;================================================
- ; Format the source string and append it to the
- ; destination. The source string is right justified
- ; to the specified length BEFORE it is appended
- ; (though the original source string is not modified).
- ; The destination string is returned.
- ;
- ; DES_OFF - destination offset: 16 bit operand.
- ; DES_SEG - destination segment: 16 bit operand.
- ; SEG_OFF - source offset: 16 bit operand.
- ; SEG_SEG - source segment: 16 bit operand.
- ; LENGTH - source string length after formatting:
- ; 8 bit register or immediate data.
- ; CHAR - character to pad with: 8 bit register or
- ; immediate data.
-
- Format Macro Des_Off, Des_Seg, Src_Off, Src_Seg, Length, Char
- Load_Address Des_Off, Des_Seg
- Load_Address Src_Off, Src_Seg
- Sub Sp, 2
- Mov Bp, Sp
- Mov Byte [Bp], Length
- Mov Byte [Bp+1], Char
- Call Format_Rgt_P
- Endm
-
- ;================================================
- ; Justify and append the source string to the
- ; destination. The length specifies the total length
- ; of the final string. The destination string is
- ; returned.
- ;
- ; DES_OFF - destination offset: 16 bit operand.
- ; DES_SEG - destination segment: 16 bit operand.
- ; SEG_OFF - source offset: 16 bit operand.
- ; SEG_SEG - source segment: 16 bit operand.
- ; LENGTH - final destination string length: 8 bit
- ; register or immediate data.
- ; CHAR - character to pad with: 8 bit register or
- ; immediate data.
-
- Justify Macro Des_Off, Des_Seg, Src_Off, Src_Seg, Length, Char
- Load_Address Des_Off, Des_Seg
- Load_Address Src_Off, Src_Seg
- Sub Sp, 2
- Mov Bp, Sp
- Mov Byte [Bp], Length
- Mov Byte [Bp+1], Char
- Call Justify_Rgt_P
- Endm
-
- ;================================================
- ; Convert a character to lower-case. AX is not
- ; preserved.
- ;
- ; CHAR - character: 8 bit operand, default is AL.
-
- Lowercase Macro Char
- If Type(Char) and Type()
- Call Lower_Chr_P
- Else
- Mov Al, Char
- Call Lower_Chr_P
- Ifn Type(Char) And Type(0)
- Mov Char, Al
- Endif
- Endif
- Endm
-
- ;================================================
- ; Convert a character to upper-case. AX is not
- ; preserved.
- ;
- ; CHAR - character, default is AL: 8 bit operand.
-
- Uppercase Macro Char
- If Type(Char) and Type()
- Call Upper_Chr_P
- Else
- Mov Al, Char
- Call Upper_Chr_P
- Ifn Type(Char) And Type(0)
- Mov Char, Al
- Endif
- Endif
- Endm
-
- ;================================================
- ; Translate a decimal string into a binary number.
- ; The string is translated to an unsigned 32 bit,
- ; so the number must be in the range 0 to
- ; 4294967295. The number is returned on the
- ; stack.
- ;
- ; SEG_OFF - string offset: 16 bit operand.
- ; SEG_SEG - string segment: 16 bit operand.
-
- Binary Macro Src_Off, Src_Seg
- Load_Address Src_Off, Src_Seg
- Call Make_Bin_P
- Endm
-
- ;================================================
- ; Translate a binary number into a decimal string.
- ; The the number must be an unsigned 32 bit value.
- ; Each word of the value must be in the range 0
- ; to 65535 (0 to FFFFH).
- ;
- ; VAL_LO - low word of number: 16 bit operand.
- ; VAL_HI - high word of number, default 0: 16 bit
- ; operand.
-
- Decimal Macro Val_Lo, Val_Hi
- Ifn Type(Val_Lo) And Type()
- Push_Any Val_Lo
- If Type(Val_Hi) And Type()
- Push_Any 0
- Else
- Push_Any Val_Hi
- Endif
- Endif
- Call Make_Dec_P
- Endm
-
- ;================================================
- ; Get the string representing the present time.
- ; the string address is returned on the stack.
-
- Time Macro
- Mov Ah, 2ch
- Int 21h
- Push Cx
- Call Time_Str_P
- Endm
-
- ;================================================
- ; Input a character or a string from standard
- ; input. If no length is specified, a single
- ; character is input without echo and returned in
- ; AL, otherwise a string is input using the specified
- ; length and its location is returned on the stack.
- ; AX is not preserved.
- ;
- ; LEN - input length: 8 bit operand.
-
- Input Macro Len
- If Type(Len) And Type()
- Call Input_Hid_P
- Else
- Mov Al, Len
- Push Ax
- Call Input_Str_P
- Endif
- Endm
-
- ;================================================
- ; Get the standard input status. Zero flag is set
- ; if there are no characters pending.
-
- Keyboard Macro
- Call Input_Sta_P
- Endm
-
- ;================================================
- ; Move the cursor to the upper left corner.
-
- Home Macro
- Call Home_Cur_P
- Endm
-
- ;================================================
- ; Move the cursor left one column.
-
- Left Macro
- Call Left_Cur_P
- Endm
-
- ;================================================
- ; Move the cursor up one row.
-
- Up Macro
- Call Up_Cur_P
- Endm
-
- ;================================================
- ; Move the cursor down one row.
-
- Down Macro
- Call Down_Cur_P
- Endm
-
- ;================================================
- ; Save cursor position.
-
- Spos Macro
- Call Save_Cur_P
- Endm
-
- ;================================================
- ; Restore cursor position.
-
- Rpos Macro
- Call Restore_Cur_P
- Endm
-
- ;================================================
- ; Move the cursor to a specified position. The upper
- ; left corner is 1,1.
- ;
- ; ROW - row position: 8 bit register or
- ; immediate data.
- ; COLUMN - column position: 8 bit register or
- ; immediate data.
-
- Locate Macro Row, Column
- Sub Sp, 2
- Mov Bp, Sp
- Mov Byte [Bp+1], Row ;set row
- Mov Byte [Bp], Column ;set column
- Call Locate_Cur_P
- Endm
-
- ;================================================
- ; Set display attribute to normal.
-
- Normal Macro
- Call Normal_Atr_P
- Endm
-
- ;================================================
- ; Set display attribute to bold.
-
- Bold Macro
- Call Bold_Atr_P
- Endm
-
- ;================================================
- ; Set display attribute to underline.
-
- Underline Macro
- Call Underline_Atr_P
- Endm
-
- ;================================================
- ; Set display attribute to blink.
-
- Blink Macro
- Call Blink_Atr_P
- Endm
-
- ;================================================
- ; Set display attribute to reverse video.
-
- Reverse Macro
- Call Reverse_Atr_P
- Endm
-
- ;================================================
- ; Clear the screen and home the cursor.
-
- Cls Macro
- Call Clear_Scr_P
- Endm
-
- ;================================================
- ; Sound the speaker (the normal beep).
-
- Bell Macro
- Call Sound_Bel_P
- Endm
-
- Beep Macro
- Call Sound_Bel_P
- Endm
-
- ;================================================
- ; Sound the speaker at the specified frequency
- ; for the specified duration.
- ;
- ; HERTZ - frequency of tone in hertz: 16 bit
- ; register or immediate data.
- ; TIME - duration of the tone in 1/100 seconds: 16
- ; bit register or immediate data.
-
- Sound Macro Hertz, Time
- Push_Any Hertz ;frequency
- Push_Any Time ;duration
- Call Sound_Spk_P
- Endm
-
- ;================================================
- ; Display a string or character to standard output.
- ; If the first parameter is 8 bit non-label, then
- ; it is displayed as a character.
- ;
- ; OFF - offset or character to display: 16 bit
- ; operand, 8 bit immediate data, or byte label.
- ; SEG - segment: 16 bit operand.
-
- Display Macro Off, Seg
- If Not(Size(Off) And Size(Byte())=0) And (Type(Off) And Type([0])=0)
- Push Dx
- Mov Dl, Off
- Call Display_Chr_P
- Pop Dx
- Else
- Load_Address Off, Seg
- Call Display_Str_P
- Endif
- Endm
-
- ;================================================
- ; Works exactly like DISPLAY above, but a new line
- ; is started after the string or character. Also,
- ; if no operand is specified, a string loaded on the
- ; stack is NOT displayed, only a new line is started.
- ;
- ; OFF - offset or character to display: 16 bit
- ; operand or 8 bit immediate data.
- ; SEG - segment: 16 bit operand.
-
- Line Macro Off, Seg
- Ifn Type(Off) And Type()
- Display Off, Seg
- Endif
- Call Line_P
- Endm
-
- ;================================================
- ; Open a file for reading and writing. The handle
- ; is returned on the stack.
- ;
- ; OFF - offset: 16 bit operand.
- ; SEG - segment: 16 bit operand.
-
- Open Macro Off, Seg
- Load_Address Off, Seg
- Call Make_Nam_P
- Call Open_Fil_P
- Endm
-
- ;================================================
- ; Create or truncate a file for reading and writing.
- ; The handle is returned on the stack.
- ;
- ; OFF - offset: 16 bit operand.
- ; SEG - segment: 16 bit operand.
-
- Create Macro Off, Seg
- Load_Address Off, Seg
- Call Make_Nam_P
- Call Create_Fil_P
- Endm
-
- ;================================================
- ; Delete a file.
- ;
- ; OFF - offset: 16 bit operand.
- ; SEG - segment: 16 bit operand.
-
- Delete Macro Off, Seg
- Load_Address Off, Seg
- Call Make_Nam_P
- Call Delete_Fil_P
- Endm
-
- ;================================================
- ; Read from a file. The number of bytes actually
- ; read is returned on the stack.
- ;
- ; HANDLE - file handle: 16 bit operand.
- ; BYTES - number of bytes to read: 16 bit operand.
- ; OFF - offset of bytes to read: 16 bit operand.
- ; SEG - segment of bytes to read, default DS: 16
- ; bit operand.
-
- Read Macro Handle, Bytes, Off, Seg
- Ifn Type(Handle) And Type()
- Push_Any Handle
- Endif
- Push_Any Bytes
- Push_Any Off
- If Type(Seg) And Type()
- Push Ds
- Else
- Push_Any Seg
- Endif
- Call Read_Fil_P
- Endm
-
- ;================================================
- ; Write to a file. The number of bytes actually
- ; written is returned on the stack.
- ;
- ; HANDLE - file handle: 16 bit operand.
- ; BYTES - number of bytes to write: 16 bit
- ; operand.
- ; OFF - offset of bytes to write: 16 bit operand.
- ; SEG - segment of bytes to write, default DS: 16
- ; bit operand.
-
- Write Macro Handle, Bytes, Off, Seg
- Ifn Type(Handle) And Type()
- Push_Any Handle
- Endif
- Push_Any Bytes
- Push_Any Off
- If Type(Seg) And Type()
- Push Ds
- Else
- Push_Any Seg
- Endif
- Call Write_Fil_P
- Endm
-
- ;================================================
- ; Move the read/write pointer of a file to a
- ; specified record location.
- ;
- ; HANDLE - file handle: 16 bit operand.
- ; RECORD_SIZE - record size: 16
- ; bit operand.
- ; RECORD_LOW - low word of record number: 16 bit
- ; operand.
- ; RECORD_HIGH - high word of record number, default
- ; 0: 16 bit operand.
-
- Seek Macro Handle, Rec_Size, Rec_Lo, Rec_Hi
- Ifn Type(Handle) And Type()
- Push_Any Handle
- Endif
- Push_Any Rec_Size
- Push_Any Rec_Lo
- If Type(Rec_Hi) And Type()
- Push_Any 0
- Else
- Push_Any Rec_Hi
- Endif
- Call Seek_Fil_P ;move read/write pointer
- Endm
-
- ;================================================
- ; Return the size of a file and move the read/
- ; write pointer to the end of the file. The 32 bit
- ; size is returned on the stack.
- ;
- ; HANDLE - file handle: 16 bit operand.
-
- Size Macro Handle
- Ifn Type(Handle) And Type()
- Push_Any Handle
- Endif
- Call Size_Fil_P ;get size of file
- Endm
-
- ;================================================
- ; Close a file.
- ;
- ; HANDLE - file handle: 16 bit operand.
-
- Close Macro Handle
- Ifn Type(Handle) And Type()
- Push_Any Handle
- Endif
- Call Close_Fil_P
- Endm
-
- ;================================================
- ; Load a 32 bit address to the stack. If no
- ; parameters are specified, then nothing will be
- ; loaded; if a string is passed, it will be
- ; declared and its address will be loaded; if a
- ; non-word memory label is specified, its offset
- ; and the specified (default code) segment will
- ; be loaded; otherwise the specified offset and
- ; segment will be loaded.
- ;
- ; OFF - offset: 16 bit operand, string, or label.
- ; SEG - segment, default is CS: 16 bit operand.
-
- Load_Address Macro Off, Seg
- Ifn Type(Off) And Type()
- If Type(Off) And Type('')
- Jmps B
- A Db Byte(Offset B - Offset A - 1), Off
- B Mov Bp, Offset A
- Push Bp
- Push Cs
- Else
- Push_Off Off
- Push_Seg Seg
- Endif
- Endif
- Endm
-
- ;================================================
- ; Push the offset part of a 32 bit address. If
- ; the offset is a non-16 bit memory label, its
- ; offset is pushed.
- ;
- ; OFF - offset: 16 bit operand, or label.
-
- Push_Off Macro Op Off
- If Not(Type(Off) And Type([0])=0) And (Size(Off) And Size(Word())=0)
- Push_Any Offset Off
- Else
- Push_Any Off
- Endif
- Endm
-
- ;================================================
- ; Push the segment part of a 32 bit address.
- ;
- ; SEG - segment, default CS: 16 bit operand.
-
- Push_Seg Macro Seg
- If Type(Seg) And Type()
- Push Cs
- Else
- Push_Any Seg
- Endif
- Endm
-
- ;================================================
- ; Push any 16 bit operand.
- ;
- ; OP - operand to be pushed: 16 bit operand.
-
- Push_Any Macro Op
- If Type(Op) And Type(0)
- Mov Bp, Op
- Push Bp
- Else
- Push Op
- Endif
- Endm
-
-