Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.42 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.  
  27. application WINDESC <05h, 05h, 15h, 45h, 07h, 10h>
  28. msgNoMouseDriver db "no mouse driver",13,10,"$"
  29. msgPressAnyKey db "press any key to exit",13,10,"$"
  30. ;==============================================================================
  31.  
  32. ;-------------------------------------------------------------------
  33. ; With MASM the mouse driver functions are called with the function
  34. ; number in AX, and depending on the function, the return values may
  35. ; be in AX, BX, CX, or DX.
  36. ;-------------------------------------------------------------------
  37.  
  38. ;----------------------------------------------------------------------
  39. ; Check for a mouse driver. Use the DOS Get Interrupt Vector function
  40. ; to get the interrupt 33h vector. If the segment address is zero then
  41. ; the mouse driver is not installed.
  42. ;----------------------------------------------------------------------
  43.  
  44.  
  45. .code
  46.  
  47. ;mouse driver
  48. mouse proc
  49.  
  50. mov ax,3533h
  51. int 21h
  52. mov ax, es
  53. .IF ax == 0
  54. mov ah, 9
  55. mov dx, OFFSET msgNoMouseDriver
  56. int 21h
  57. jmp myExit
  58. .ENDIF
  59.  
  60. ;-------------------------------------------------------------------------
  61. ; Attempt to reset the mouse driver by calling the Mouse Reset And Status
  62. ; function. If the reset fails, indicated by the function returning zero,
  63. ; then the mouse driver is not installed.
  64. ;-------------------------------------------------------------------------
  65.  
  66. xor ax, ax
  67. int 33h
  68. .IF ax == 0
  69. mov ah, 9
  70. mov dx, OFFSET msgNoMouseDriver
  71. int 21h
  72. jmp myExit
  73. .ENDIF
  74.  
  75. ;------------------------------------------------------------------
  76. ; Show the mouse cursor by calling the Mouse Show Cursor function.
  77. ;------------------------------------------------------------------
  78.  
  79. mov ax, 1
  80. int 33h
  81.  
  82. ;-----------------------------------------------------------------------
  83. ; Loop, calling the Mouse Get Button Status And Mouse Position function
  84. ; until the user presses the left mouse button with the mouse cursor
  85. ; at character coordinate 0,0 (the first character at the upper-left
  86. ; corner of screen). The function returns the button status in BX, the
  87. ; horizontal cursor coordinate in CX, and the vertical cursor coordinate
  88. ; in DX. The button status for the left mouse button is returned in
  89. ; bit 0 of BX, and the status for the right mouse button in bit 1, with
  90. ; the bit set if the button is pressed or cleared if the button is
  91. ; released. The cursor coordinates are returned as mouse-driver virtual-
  92. ; screen coordinates, where the virtual screen for most of the display
  93. ; modes is 640x200. For the 80x25 character (AKA "text") modes you
  94. ; convert the virtual-screen coordinates to character coordinates by
  95. ; simply dividing the virtual-screen coordinates by 8.
  96. ;-----------------------------------------------------------------------
  97.  
  98. @@:
  99. mov ax, 3
  100. int 33h
  101. .IF bx & 1 ; left mouse button is pressed
  102. shr cx, 3
  103. shr dx, 3
  104. .IF cx || dx ; mouse cursor not over character 0,0 so keep looping
  105. jmp @B
  106. .ENDIF
  107. .ELSE
  108. jmp @B ; left mouse button not pressed so keep looping
  109. .ENDIF
  110.  
  111. myExit:
  112.  
  113. mov ah, 9
  114. mov dx, OFFSET msgPressAnyKey
  115. int 21h
  116.  
  117. xor ah, ah
  118. int 16h
  119.  
  120. ret
  121.  
  122. mouse endp
  123.  
  124. ; -------------------------------------------------------------
  125. ; This proc calls the BIOS Read Keyboard Status and Read
  126. ; Keyboard Input functions to flush the keyboard buffer,
  127. ; wait for a key press, and then flush the buffer again,
  128. ; leaving it empty. The BIOS scan code for the key pressed
  129. ; is returned in AH and the character code in AL.
  130. ; -------------------------------------------------------------
  131.  
  132. waitkey proc c
  133. @@:
  134. mov ah, 1
  135. int 16h ; Check for key press
  136. jz @F ; Jump if buffer empty
  137. mov ah, 0
  138. int 16h ; Get key
  139. jmp @B ; Repeat
  140. @@:
  141. mov ah, 1
  142. int 16h ; Check for key press
  143. jz @B ; Repeat
  144. mov ah, 0
  145. int 16h ; Get key
  146. push ax ; Preserve it
  147. @@:
  148. mov ah, 1
  149. int 16h ; Check for key press
  150. jz @F ; Jump if buffer empty
  151. mov ah, 0
  152. int 16h ; Get key
  153. jmp @B ; Repeat
  154. @@:
  155. pop ax ; Recover key
  156. ret
  157. waitkey endp
  158.  
  159. curpos PROC
  160. push bp
  161. mov bp, sp
  162. push ax
  163. push bx
  164. push dx
  165.  
  166. mov ax, 0200h
  167. mov bh, 0
  168. mov dx, [bp+4]
  169. ; interrupt
  170. int 10h
  171.  
  172. pop dx
  173. pop bx
  174. pop ax
  175. pop bp
  176. ret 2
  177. curpos ENDP
  178.  
  179.  
  180. ;still unused
  181. putchar PROC
  182. push bp
  183. mov bp, sp
  184. push ax
  185. push bx
  186. push cx
  187. push dx
  188.  
  189.  
  190. pop dx
  191. pop cx
  192. pop bx
  193. pop ax
  194. pop bp
  195. ret 2
  196. putchar ENDP
  197.  
  198.  
  199. getchar PROC
  200. mov ah,00h
  201. int 16h
  202. ret
  203. getchar ENDP
  204.  
  205.  
  206. ;window construction
  207. makewin PROC
  208. push bp
  209. mov bp, sp
  210. push ax
  211. push bx
  212. push cx
  213. push dx
  214. push si
  215.  
  216. mov si, [bp+4]
  217.  
  218. mov ax, 0600h
  219. mov bh, (WINDESC PTR[si]) .backColor
  220. mov ch, (WINDESC PTR[si]) .upperRow
  221. mov cl, (WINDESC PTR[si]) .leftCol
  222. mov dh, (WINDESC PTR[si]) .lowerRow
  223. mov dl, (WINDESC PTR[si]) .rightCol
  224. ;interrupt
  225. int 10h
  226.  
  227. push cx
  228. call curpos
  229.  
  230. pop si
  231. pop dx
  232. pop cx
  233. pop bx
  234. pop ax
  235. pop bp
  236. ret 2
  237. makewin ENDP
  238.  
  239.  
  240. main PROC
  241. mov ax, @data
  242. mov ds, ax
  243. mov ax, OFFSET application
  244. push ax
  245. call makewin
  246. call curpos
  247. call waitkey
  248. call mouse
  249. call getchar
  250. exit
  251. main ENDP
  252.  
  253. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement