Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2011
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.47 KB | None | 0 0
  1. TITLE The New DOS
  2.  
  3. .model small
  4. .386p
  5. .stack 100h
  6. OPTION CaseMap:None
  7.  
  8. ; Set the window variable framework
  9. WINDESC STRUCT
  10. upperRow BYTE ?
  11. leftCol BYTE ?
  12. lowerRow BYTE ?
  13. rightCol BYTE ?
  14. foreColor BYTE ?
  15. backColor BYTE ?
  16. WINDESC ENDS
  17.  
  18. ; Not really sure about this one
  19. exit MACRO
  20. mov ax, 4C00h
  21. int 21h
  22. ENDM
  23.  
  24. ;set variables
  25. .data
  26. BufLen db 20
  27. RetLen db 0
  28. BufInp db 21 dup(?)
  29. application WINDESC <05h, 05h, 15h, 45h, 07h, 10h>
  30. msgNoMouseDriver db "no mouse driver",13,10,"$"
  31. msgPressAnyKey db "press any key to exit",13,10,"$"
  32. ;==============================================================================
  33.  
  34. ;-------------------------------------------------------------------
  35. ; With MASM the mouse driver functions are called with the function
  36. ; number in AX, and depending on the function, the return values may
  37. ; be in AX, BX, CX, or DX.
  38. ;-------------------------------------------------------------------
  39.  
  40. ;----------------------------------------------------------------------
  41. ; Check for a mouse driver. Use the DOS Get Interrupt Vector function
  42. ; to get the interrupt 33h vector. If the segment address is zero then
  43. ; the mouse driver is not installed.
  44. ;----------------------------------------------------------------------
  45.  
  46.  
  47. .code
  48. ;User buffer to enter text
  49. mov dx,offset BufLen
  50. mov ah,0Ah
  51. int 21h
  52.  
  53. ;mouse driver
  54. mouse proc
  55.  
  56. mov ax,3533h
  57. int 21h
  58. mov ax, es
  59. .IF ax == 0
  60. mov ah, 9
  61. mov dx, OFFSET msgNoMouseDriver
  62. int 21h
  63. jmp myExit
  64. .ENDIF
  65.  
  66. ;-------------------------------------------------------------------------
  67. ; Attempt to reset the mouse driver by calling the Mouse Reset And Status
  68. ; function. If the reset fails, indicated by the function returning zero,
  69. ; then the mouse driver is not installed.
  70. ;-------------------------------------------------------------------------
  71.  
  72. xor ax, ax
  73. int 33h
  74. .IF ax == 0
  75. mov ah, 9
  76. mov dx, OFFSET msgNoMouseDriver
  77. int 21h
  78. jmp myExit
  79. .ENDIF
  80.  
  81. ;------------------------------------------------------------------
  82. ; Show the mouse cursor by calling the Mouse Show Cursor function.
  83. ;------------------------------------------------------------------
  84.  
  85. mov ax, 1
  86. int 33h
  87.  
  88. ;-----------------------------------------------------------------------
  89. ; Loop, calling the Mouse Get Button Status And Mouse Position function
  90. ; until the user presses the left mouse button with the mouse cursor
  91. ; at character coordinate 0,0 (the first character at the upper-left
  92. ; corner of screen). The function returns the button status in BX, the
  93. ; horizontal cursor coordinate in CX, and the vertical cursor coordinate
  94. ; in DX. The button status for the left mouse button is returned in
  95. ; bit 0 of BX, and the status for the right mouse button in bit 1, with
  96. ; the bit set if the button is pressed or cleared if the button is
  97. ; released. The cursor coordinates are returned as mouse-driver virtual-
  98. ; screen coordinates, where the virtual screen for most of the display
  99. ; modes is 640x200. For the 80x25 character (AKA "text") modes you
  100. ; convert the virtual-screen coordinates to character coordinates by
  101. ; simply dividing the virtual-screen coordinates by 8.
  102. ;-----------------------------------------------------------------------
  103.  
  104. @@:
  105. mov ax, 3
  106. int 33h
  107. .IF bx & 1 ; left mouse button is pressed
  108. shr cx, 3
  109. shr dx, 3
  110. .IF cx || dx ; mouse cursor not over character 0,0 so keep looping
  111. jmp @B
  112. .ENDIF
  113. .ELSE
  114. jmp @B ; left mouse button not pressed so keep looping
  115. .ENDIF
  116.  
  117. myExit:
  118.  
  119. mov ah, 9
  120. mov dx, OFFSET msgPressAnyKey
  121. int 21h
  122.  
  123. xor ah, ah
  124. int 16h
  125.  
  126. ret
  127.  
  128. mouse endp
  129.  
  130. ; -------------------------------------------------------------
  131. ; This proc calls the BIOS Read Keyboard Status and Read
  132. ; Keyboard Input functions to flush the keyboard buffer,
  133. ; wait for a key press, and then flush the buffer again,
  134. ; leaving it empty. The BIOS scan code for the key pressed
  135. ; is returned in AH and the character code in AL.
  136. ; -------------------------------------------------------------
  137.  
  138. waitkey proc c
  139. @@:
  140. mov ah, 1
  141. int 16h ; Check for key press
  142. jz @F ; Jump if buffer empty
  143. mov ah, 0
  144. int 16h ; Get key
  145. jmp @B ; Repeat
  146. @@:
  147. mov ah, 1
  148. int 16h ; Check for key press
  149. jz @B ; Repeat
  150. mov ah, 0
  151. int 16h ; Get key
  152. push ax ; Preserve it
  153. @@:
  154. mov ah, 1
  155. int 16h ; Check for key press
  156. jz @F ; Jump if buffer empty
  157. mov ah, 0
  158. int 16h ; Get key
  159. jmp @B ; Repeat
  160. @@:
  161. pop ax ; Recover key
  162. ret
  163. waitkey endp
  164.  
  165. curpos PROC
  166. push bp
  167. mov bp, sp
  168. push ax
  169. push bx
  170. push dx
  171.  
  172. mov ax, 0200h
  173. mov bh, 0
  174. mov dx, [bp+4]
  175. ; interrupt
  176. int 10h
  177.  
  178. pop dx
  179. pop bx
  180. pop ax
  181. pop bp
  182. ret 2
  183. curpos ENDP
  184.  
  185.  
  186. ;still unused
  187. putchar PROC
  188. push bp
  189. mov bp, sp
  190. push ax
  191. push bx
  192. push cx
  193. push dx
  194.  
  195.  
  196. pop dx
  197. pop cx
  198. pop bx
  199. pop ax
  200. pop bp
  201. ret 2
  202. putchar ENDP
  203.  
  204.  
  205. getchar PROC
  206. mov ah,00h
  207. int 16h
  208. ret
  209. getchar ENDP
  210.  
  211.  
  212. ;window construction
  213. makewin PROC
  214. push bp
  215. mov bp, sp
  216. push ax
  217. push bx
  218. push cx
  219. push dx
  220. push si
  221.  
  222. mov si, [bp+4]
  223.  
  224. mov ax, 0600h
  225. mov bh, (WINDESC PTR[si]) .backColor
  226. mov ch, (WINDESC PTR[si]) .upperRow
  227. mov cl, (WINDESC PTR[si]) .leftCol
  228. mov dh, (WINDESC PTR[si]) .lowerRow
  229. mov dl, (WINDESC PTR[si]) .rightCol
  230. ;interrupt
  231. int 10h
  232.  
  233. push cx
  234. call curpos
  235.  
  236. Filler1:
  237. MOV BYTE PTR[EAX], BL
  238. ADD AX, 4
  239. DEC CX
  240. JNZ Filler1
  241.  
  242. MOVZX BX, BYTE PTR [RightCol]
  243. MOV BYTE PTR [EAX], BL
  244. ADD AX, 4
  245.  
  246. MOV CX, Row2
  247. SUB CX, Row1
  248. DEC CX
  249. MOVZX BX, BYTE PTR [Vertical]
  250. BorderFill:
  251. MOV BYTE PTR [AX], BL
  252. ADD AX, 4
  253. MOV DX, 4
  254. IMUL DX, 78
  255. ADD AX, DX
  256. MOV BYTE PTR[AX], BL
  257. ADD AX, 4
  258. DEC CX
  259. JNZ BorderFill
  260.  
  261. MOVZX BX, BYTE PTR [LowerRow]
  262. MOV BYTE PTR [AX], BL
  263. ADD AX, 4
  264. MOV CX, 78
  265. MOVZX BX, BYTE PTR [Horizontal]
  266.  
  267. Filler2:
  268. MOV BYTE PTR [AX], BL
  269. ADD AX, 4
  270. DEC CX
  271. JNZ Filler2
  272.  
  273. MOVZX BX, BYTE PTR [LeftCol]
  274. MOV BYTE PTR [AX], BL
  275. ; RET
  276. pop si
  277. pop dx
  278. pop cx
  279. pop bx
  280. pop ax
  281. pop bp
  282. ret 2
  283. makewin ENDP
  284.  
  285.  
  286. main PROC
  287. mov ax, @data
  288. mov ds, ax
  289. mov ax, OFFSET application
  290. push ax
  291. call makewin
  292. mov al,application.leftCol
  293. mov ah,application.upperRow
  294. push ax
  295. call curpos
  296. call waitkey
  297. call mouse
  298. call getchar
  299. exit
  300. main ENDP
  301.  
  302. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement