Advertisement
Guest User

Untitled

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