All pastes #2096142 Raw Edit

Unnamed

public text v1 · immutable
#2096142 ·published 2011-12-24 08:45 UTC
rendered paste body
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   ?
;below is newly added border parameters
			UpperRow		DB 218
			RightCol		DB 191
			LowerRow		DB 192
			LeftCol			DB 217
			Horizontal		DB 196
			Vertical		DB 179
WINDESC      ENDS

; Not really sure about this one
exit         MACRO
			mov            ax, 4C00h
			int            21h
			ENDM

;set variables         
.data
			BufLen			db 20
			RetLen			db 0
			BufInp			db 21 dup(?)
			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
;User buffer to enter text
			mov     dx,offset BufLen
			mov     ah,0Ah
			int     21h
	
;mouse driver
mouse proc
@@:
			mov 	ax, 3
			int 	33h
			test 	bx, 1
			jz  	@B
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


getchar     PROC
			mov     ah,00h
			int     16h
			ret
getchar    	ENDP


;window construction
makewin     PROC 	Row1:DWORD, Row2:DWORD, Horizontal:BYTE
			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
; newly added window border info

			MOV		AX, Row1
			SUB		AX, 1
			IMUL	AX, 320 ;pg627 perform a signed integer multiplication.
			MOV		DX, AX
			LEA		AX, ConsoleScreen ;pg631 calculate and load the memory address.  
			ADD		AX, DX
				
			MOVZX	BX, BYTE PTR[upperRow]
			MOV		BYTE PTR [AX], BL
			ADD		AX, 4
			MOV		CX, 78
				
			MOVZX	BX, BYTE PTR [Horizontal]
			MOV		BL, Horizontal
Filler1:
			MOV		BYTE PTR[AX], BL
			ADD		AX, 4
			DEC		CX
			JNZ		Filler1
				
			MOVZX	BX, BYTE PTR [RightCol]
			MOV		BYTE PTR [AX], BL
			ADD		AX, 4
					
			MOV		CX, Row2
			SUB		CX, Row1
			DEC 	CX
			MOVZX	BX, BYTE PTR [Vertical]
BorderFill:
			MOV		BYTE PTR [AX], BL
			ADD		AX, 4
			MOV		DX, 4
			IMUL	DX, 78
			ADD		AX, DX
			MOV		BYTE PTR[AX], BL
			ADD		AX, 4
			DEC		CX
			JNZ		BorderFill
					
			MOVZX	BX, BYTE PTR [LowerRow]
			MOV		BYTE PTR [AX], BL
			ADD		AX, 4
			MOV		CX, 78
			MOVZX	BX, BYTE PTR [Horizontal]
					
Filler2:
			MOV		BYTE PTR [AX], BL
			ADD		AX, 4
			DEC		CX
			JNZ		Filler2
					
			MOVZX	BX, BYTE PTR [LeftCol]
			MOV		BYTE PTR [AX], BL
			RET

			
			call    curpos

;					RET
			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
			mov     al,application.leftCol
			mov     ah,application.upperRow
			push    ax
			call    curpos
			call	waitkey
			call	mouse
			call    getchar
exit
main        ENDP

            end     main