Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TITLE The New DOS
- .model small
- .386p
- .stack 100h
- OPTION CaseMap:None
- ; Set the window variable framework
- WINDESC STRUCT
- upperRow BYTE ?
- leftCol BYTE ?
- lowerRow BYTE ?
- rightCol BYTE ?
- foreColor BYTE ?
- backColor BYTE ?
- WINDESC ENDS
- ; Not really sure about this one
- exit MACRO
- mov ax, 4C00h
- int 21h
- ENDM
- ;set variables
- .data
- application WINDESC <05h, 05h, 15h, 45h, 07h, 10h>
- msgNoMouseDriver db "no mouse driver",13,10,"$"
- msgPressAnyKey db "press any key to exit",13,10,"$"
- ;==============================================================================
- ;-------------------------------------------------------------------
- ; With MASM the mouse driver functions are called with the function
- ; number in AX, and depending on the function, the return values may
- ; be in AX, BX, CX, or DX.
- ;-------------------------------------------------------------------
- ;----------------------------------------------------------------------
- ; Check for a mouse driver. Use the DOS Get Interrupt Vector function
- ; to get the interrupt 33h vector. If the segment address is zero then
- ; the mouse driver is not installed.
- ;----------------------------------------------------------------------
- .code
- ;mouse driver
- mouse proc
- mov ax,3533h
- int 21h
- mov ax, es
- .IF ax == 0
- mov ah, 9
- mov dx, OFFSET msgNoMouseDriver
- int 21h
- jmp myExit
- .ENDIF
- ;-------------------------------------------------------------------------
- ; Attempt to reset the mouse driver by calling the Mouse Reset And Status
- ; function. If the reset fails, indicated by the function returning zero,
- ; then the mouse driver is not installed.
- ;-------------------------------------------------------------------------
- xor ax, ax
- int 33h
- .IF ax == 0
- mov ah, 9
- mov dx, OFFSET msgNoMouseDriver
- int 21h
- jmp myExit
- .ENDIF
- ;------------------------------------------------------------------
- ; Show the mouse cursor by calling the Mouse Show Cursor function.
- ;------------------------------------------------------------------
- mov ax, 1
- int 33h
- ;-----------------------------------------------------------------------
- ; Loop, calling the Mouse Get Button Status And Mouse Position function
- ; until the user presses the left mouse button with the mouse cursor
- ; at character coordinate 0,0 (the first character at the upper-left
- ; corner of screen). The function returns the button status in BX, the
- ; horizontal cursor coordinate in CX, and the vertical cursor coordinate
- ; in DX. The button status for the left mouse button is returned in
- ; bit 0 of BX, and the status for the right mouse button in bit 1, with
- ; the bit set if the button is pressed or cleared if the button is
- ; released. The cursor coordinates are returned as mouse-driver virtual-
- ; screen coordinates, where the virtual screen for most of the display
- ; modes is 640x200. For the 80x25 character (AKA "text") modes you
- ; convert the virtual-screen coordinates to character coordinates by
- ; simply dividing the virtual-screen coordinates by 8.
- ;-----------------------------------------------------------------------
- @@:
- mov ax, 3
- int 33h
- .IF bx & 1 ; left mouse button is pressed
- shr cx, 3
- shr dx, 3
- .IF cx || dx ; mouse cursor not over character 0,0 so keep looping
- jmp @B
- .ENDIF
- .ELSE
- jmp @B ; left mouse button not pressed so keep looping
- .ENDIF
- myExit:
- mov ah, 9
- mov dx, OFFSET msgPressAnyKey
- int 21h
- xor ah, ah
- int 16h
- ret
- mouse endp
- ; -------------------------------------------------------------
- ; This proc calls the BIOS Read Keyboard Status and Read
- ; Keyboard Input functions to flush the keyboard buffer,
- ; wait for a key press, and then flush the buffer again,
- ; leaving it empty. The BIOS scan code for the key pressed
- ; is returned in AH and the character code in AL.
- ; -------------------------------------------------------------
- waitkey proc c
- @@:
- mov ah, 1
- int 16h ; Check for key press
- jz @F ; Jump if buffer empty
- mov ah, 0
- int 16h ; Get key
- jmp @B ; Repeat
- @@:
- mov ah, 1
- int 16h ; Check for key press
- jz @B ; Repeat
- mov ah, 0
- int 16h ; Get key
- push ax ; Preserve it
- @@:
- mov ah, 1
- int 16h ; Check for key press
- jz @F ; Jump if buffer empty
- mov ah, 0
- int 16h ; Get key
- jmp @B ; Repeat
- @@:
- pop ax ; Recover key
- ret
- waitkey endp
- curpos PROC
- push bp
- mov bp, sp
- push ax
- push bx
- push dx
- mov ax, 0200h
- mov bh, 0
- mov dx, [bp+4]
- ; interrupt
- int 10h
- pop dx
- pop bx
- pop ax
- pop bp
- ret 2
- curpos ENDP
- ;still unused
- putchar PROC
- push bp
- mov bp, sp
- push ax
- push bx
- push cx
- push dx
- pop dx
- pop cx
- pop bx
- pop ax
- pop bp
- ret 2
- putchar ENDP
- getchar PROC
- mov ah,00h
- int 16h
- ret
- getchar ENDP
- ;window construction
- makewin PROC
- push bp
- mov bp, sp
- push ax
- push bx
- push cx
- push dx
- push si
- mov si, [bp+4]
- mov ax, 0600h
- mov bh, (WINDESC PTR[si]) .backColor
- mov ch, (WINDESC PTR[si]) .upperRow
- mov cl, (WINDESC PTR[si]) .leftCol
- mov dh, (WINDESC PTR[si]) .lowerRow
- mov dl, (WINDESC PTR[si]) .rightCol
- ;interrupt
- int 10h
- push cx
- call curpos
- pop si
- pop dx
- pop cx
- pop bx
- pop ax
- pop bp
- ret 2
- makewin ENDP
- main PROC
- mov ax, @data
- mov ds, ax
- mov ax, OFFSET application
- push ax
- call makewin
- call curpos
- call waitkey
- call mouse
- call getchar
- exit
- main ENDP
- end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement