Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Dec 24th, 2011  |  syntax: None  |  size: 5.78 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. TITLE The New DOS
  2.  
  3. .model      small
  4. .386p
  5. .stack      100h
  6. OPTION          CaseMap:None
  7.  
  8.  
  9. ; Set the window variable framework
  10. WINDESC      STRUCT
  11.                         upperRow       BYTE   ?
  12.                         leftCol        BYTE   ?
  13.                         lowerRow       BYTE   ?
  14.                         rightCol       BYTE   ?
  15.                         foreColor      BYTE   ?
  16.                         backColor      BYTE   ?
  17.  
  18. WINDESC      ENDS
  19.  
  20. ; Not really sure about this one
  21. exit         MACRO
  22.                         mov            ax, 4C00h
  23.                         int            21h
  24.                         ENDM
  25.  
  26. ;set variables        
  27. .data
  28.                         BufLen                  db 20
  29.                         RetLen                  db 0
  30.                         BufInp                  db 21 dup(?)
  31.                         application             WINDESC         <05h, 05h, 15h, 45h, 07h, 10h>
  32.                         msgNoMouseDriver db "no mouse driver",13,10,"$"
  33.                         msgPressAnyKey   db "press any key to exit",13,10,"$"
  34. ;below is newly added border parameters
  35.                         upperRow2               DB 218
  36.                         RightCol2               DB 191
  37.                         LowerRow2               DB 192
  38.                         LeftCol2                DB 217
  39.                         Horizontal              DB 196
  40.                         Vertical                DB 179
  41.                         Row1                    WORD ?
  42.                         Row2                    WORD ?
  43.                         ConsoleScreen   CHAR_INFO 2000 DUP (<>)
  44. ;==============================================================================
  45.  
  46.     ;-------------------------------------------------------------------
  47.     ; With MASM the mouse driver functions are called with the function
  48.     ; number in AX, and depending on the function, the return values may
  49.     ; be in AX, BX, CX, or DX.
  50.     ;-------------------------------------------------------------------
  51.  
  52.     ;----------------------------------------------------------------------
  53.     ; Check for a mouse driver. Use the DOS Get Interrupt Vector function
  54.     ; to get the interrupt 33h vector. If the segment address is zero then
  55.     ; the mouse driver is not installed.
  56.     ;----------------------------------------------------------------------
  57.  
  58.                
  59. .code
  60. ;User buffer to enter text
  61.                         mov     dx,offset BufLen
  62.                         mov     ah,0Ah
  63.                         int     21h
  64.        
  65. ;mouse driver
  66. mouse proc
  67. @@:
  68.                         mov     ax, 3
  69.                         int     33h
  70.                         test    bx, 1
  71.                         jz      @B
  72. mouse endp
  73.  
  74. ; -------------------------------------------------------------
  75. ; This proc calls the BIOS Read Keyboard Status and Read
  76. ; Keyboard Input functions to flush the keyboard buffer,
  77. ; wait for a key press, and then flush the buffer again,
  78. ; leaving it empty. The BIOS scan code for the key pressed
  79. ; is returned in AH and the character code in AL.
  80. ; -------------------------------------------------------------
  81.  
  82. waitkey         proc c
  83.   @@:
  84.                         mov     ah, 1
  85.                         int             16h                   ; Check for key press
  86.                         jz              @F                    ; Jump if buffer empty
  87.                         mov     ah, 0
  88.                         int     16h                   ; Get key
  89.                         jmp @B                    ; Repeat
  90.   @@:
  91.                         mov     ah, 1
  92.                         int     16h                   ; Check for key press
  93.                         jz  @B                    ; Repeat
  94.                         mov     ah, 0
  95.                         int     16h                   ; Get key
  96.                         push    ax                   ; Preserve it
  97.   @@:
  98.                         mov     ah, 1
  99.                         int     16h                   ; Check for key press
  100.                         jz  @F                    ; Jump if buffer empty
  101.                         mov     ah, 0
  102.                         int     16h                   ; Get key
  103.                         jmp @B                    ; Repeat
  104.   @@:
  105.                         pop ax                    ; Recover key
  106.                         ret
  107. waitkey         endp
  108.  
  109. curpos      PROC
  110.                         push    bp
  111.                         mov     bp, sp
  112.                         push    ax
  113.                         push    bx
  114.                         push    dx
  115.          
  116.                         mov     ax, 0200h
  117.                         mov     bh, 0
  118.                         mov     dx, [bp+4]
  119. ; interrupt
  120.                         int     10h
  121.          
  122.                         pop     dx
  123.                         pop     bx
  124.                         pop     ax
  125.                         pop     bp
  126.                         ret     2
  127. curpos      ENDP
  128.  
  129.  
  130. getchar     PROC
  131.                         mov     ah,00h
  132.                         int     16h
  133.                         ret
  134. getchar         ENDP
  135.  
  136. FORMAT                          PROC    szFmtName:DWORD
  137.                                         INVOKE  WriteConsoleOutput, Handler1, szFmtName, DWORD PTR BufSize,
  138.                                                         DWORD PTR Starter, OFFSET WindowSize                                                   
  139.                                         RET
  140. FORMAT                          ENDP
  141.  
  142.  
  143. ;window construction
  144. makewin     PROC
  145.                         push    bp
  146.                         mov     bp, sp
  147.                         push    ax
  148.                         push    bx
  149.                         push    cx
  150.                         push    dx
  151.                         push    si
  152.          
  153.                         mov     si, [bp+4]
  154.          
  155.                         mov     ax, 0600h
  156.                         mov     bh, (WINDESC PTR[si]) .backColor
  157.                         mov     ch, (WINDESC PTR[si]) .upperRow
  158.                         mov     cl, (WINDESC PTR[si]) .leftCol
  159.                         mov     dh, (WINDESC PTR[si]) .lowerRow
  160.                         mov     dl, (WINDESC PTR[si]) .rightCol
  161. ;interrupt
  162.                         int     10h
  163.          
  164.                         push    cx
  165. ; newly added window border info
  166.  
  167.                         MOV             AX, Row1
  168.                         SUB             AL, 1
  169.                         IMUL    AX, 320 ;pg627 perform a signed integer multiplication.
  170.                         MOV             DX, AX
  171.                         LEA             AX, ConsoleScreen ;pg631 calculate and load the memory address.  
  172.                         ADD             AX, DX
  173.                                
  174.                         MOVZX   BX, BYTE PTR[upperRow2]
  175.                         MOV             SI, AX
  176.                         MOV             BYTE PTR [SI], BL
  177.                         ADD             SI, 4
  178.                         MOV             CX, 78
  179.                                
  180.                         MOVZX   BX, BYTE PTR [Horizontal]
  181.                         MOV             BL, Horizontal
  182. Filler1:
  183.                         MOV             SI, AX
  184.                         MOV             BYTE PTR[SI], BL
  185.                         ADD             SI, 4
  186.                         DEC             CX
  187.                         JNZ             Filler1
  188.                                
  189.                         MOVZX   BX, BYTE PTR [RightCol2]
  190.                         MOV             BYTE PTR [SI], BL
  191.                         ADD             SI, 4
  192.                                        
  193.                         MOV             CX, Row2
  194.                         SUB             CX, Row1
  195.                         DEC     CX
  196.                         MOVZX   BX, BYTE PTR [Vertical]
  197. BorderFill:
  198.                         MOV             SI, AX
  199.                         MOV             BYTE PTR [SI], BL
  200.                         ADD             SI, 4
  201.                         MOV             DX, 4
  202.                         IMUL    DX, 78
  203.                         ADD             SI, DX
  204.                         MOV             BYTE PTR[SI], BL
  205.                         ADD             SI, 4
  206.                         DEC             CX
  207.                         JNZ             BorderFill
  208.                                        
  209.                         MOVZX   BX, BYTE PTR [LowerRow2]
  210.                         MOV             BYTE PTR [SI], BL
  211.                         ADD             SI, 4
  212.                         MOV             CX, 78
  213.                         MOVZX   BX, BYTE PTR [Horizontal]
  214.                                        
  215. Filler2:
  216.                         MOV             SI, AX
  217.                         MOV             BYTE PTR [SI], BL
  218.                         ADD             SI, 4
  219.                         DEC             CX
  220.                         JNZ             Filler2
  221.                                        
  222.                         MOVZX   BX, BYTE PTR [LeftCol2]
  223.                         MOV             BYTE PTR [SI], BL
  224.                         RET
  225.  
  226.                        
  227.                         call    curpos
  228.  
  229. ;                                       RET
  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.                         INVOKE  FORMAT, offset ConsoleScreen
  246.                         call    makewin
  247.                         mov     al,application.leftCol
  248.                         mov     ah,application.upperRow
  249.                         push    ax
  250.                         call    curpos
  251.                         call    waitkey
  252.                         call    mouse
  253.                         call    getchar
  254. exit
  255. main        ENDP
  256.  
  257.             end     main