home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / video / 13 / 13_7.asm < prev    next >
Encoding:
Assembly Source File  |  1988-08-11  |  3.4 KB  |  141 lines

  1.         TITLE    'Listing 13-7'
  2.         NAME    dgisrect
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:     dgisrect
  7. ;
  8. ; Function:    draw a filled rectangle using DGIS
  9. ;
  10. ; Notes:    assemble and link to create DGISRECT.EXE
  11. ;
  12.  
  13. CR        EQU    0Dh
  14. LF        EQU    0Ah
  15.  
  16. _TEXT        SEGMENT    byte public 'CODE'
  17.         ASSUME    cs:_TEXT,ds:_DATA,ss:STACK
  18.  
  19. EntryPoint    PROC    far
  20.  
  21.         mov    ax,seg _DATA
  22.         mov    ds,ax            ; DS -> _DATA
  23.         push    ss
  24.         pop    es            ; ES -> stack segment
  25.  
  26. ; look for installed DGIS devices
  27.  
  28.         xor    dx,dx            ; DX = 0 (buffer length)
  29.         xor    cx,cx            ; CX = 0
  30.         xor    bx,bx            ; BX = 0
  31.         mov    ax,6A00h        ; AX = DGIS opcode (Inquire
  32.                         ;       Available Devices)
  33.         int    10h
  34.         or    cx,cx
  35.         jnz    L01            ; jump if device(s) installed
  36.  
  37.         mov    dx,offset _DATA:Msg0
  38.         jmp    ErrorExit
  39.  
  40. ; find a graphics output device in the list of installed DGIS devices
  41.  
  42. L01:        inc    cx            ; CX = (# of bytes in list) + 1
  43.         and    cx,0FFFEh        ; CX = even number of bytes
  44.         mov    bp,sp
  45.         sub    sp,cx            ; establish stack frame
  46.                         ;  (SS:BP -> end of frame)
  47.         mov    di,sp            ; ES:DI -> start of stack frame
  48.  
  49.         push    di            ; save for later
  50.         mov    dx,cx            ; DX = size of buffer
  51.         xor    cx,cx
  52.         xor    bx,bx
  53.         mov    ax,6A00h        ; AX = DGIS opcode (Inquire
  54.                         ;       Available Devices)
  55.         int    10h            ; get device list at ES:DI
  56.         pop    di            ; ES:DI -> device list
  57.  
  58. L02:        cmp    word ptr es:[di+2],0    ; is this a graphics device?
  59.         je    L04            ; jump if so
  60.  
  61.         sub    bx,es:[di]        ; BX = bytes remaining in list
  62.         jnz    L03            ; jump if more devices in list
  63.  
  64.         mov    dx,offset _DATA:Msg1
  65.         jmp    ErrorExit
  66.  
  67. L03:        add    di,es:[di]        ; ES:DI -> next device in list
  68.         jmp    L02
  69.  
  70. ; establish a logical connection to the graphics device
  71. ;  using the first available configuration on the device
  72.  
  73. L04:        les    di,es:[di+6]        ; ES:DI -> device entry point
  74.         mov    word ptr GrDevEntry,di
  75.         mov    word ptr GrDevEntry+2,es  ; save entry point
  76.  
  77.         mov    cx,0            ; CX = first configuration index
  78.         mov    ax,0027h        ; AX = DGIS opcode (Connect)
  79.         call    dword ptr GrDevEntry    ; connect to graphics device
  80.         cmp    bx,-1            ; test returned handle
  81.         jne    L05            ; jump if connected
  82.  
  83.         mov    dx,offset _DATA:Msg2
  84.         jmp    ErrorExit
  85.  
  86. L05:        mov    ChannelHandle,bx    ; save the handle for later
  87.         mov    ax,001Bh        ; AX = DGIS opcode (Init DGI)
  88.         call    dword ptr GrDevEntry    ; initialize the device with
  89.                         ;  default attributes
  90.  
  91. ; draw a filled rectangle using default attributes
  92.  
  93.         mov    di,100            ; DI = lower right corner y
  94.         mov    si,100            ; SI = lower right corner x
  95.         mov    dx,0            ; DX = upper left corner y
  96.         mov    cx,0            ; CX = upper left corner x
  97.         mov    bx,ChannelHandle    ; BX = handle
  98.         mov    ax,003Fh        ; AX = DGIS opcode (Output
  99.                         ;       Filled Rectangle)
  100.         call    dword ptr GrDevEntry
  101.  
  102. ; disconnect and exit
  103.  
  104.         mov    bx,ChannelHandle    ; BX = handle
  105.         mov    ax,002Bh        ; AX = DGIS opcode (Disconnect)
  106.         call    dword ptr GrDevEntry        
  107.  
  108. Lexit:        mov    ax,4C00h
  109.         int    21h            ; return to DOS
  110.  
  111. ErrorExit:    mov    ah,9
  112.         int    21h            ; display error message
  113.         mov    ax,4C01h
  114.         int    21h            ; return to DOS
  115.  
  116. EntryPoint    ENDP
  117.  
  118. _TEXT        ENDS
  119.  
  120.  
  121. _DATA        SEGMENT    para public 'DATA'
  122.  
  123. GrDevEntry    DD    ?            ; graphics device entry point 
  124. ChannelHandle    DW    ?            ; handle to connected device
  125.                         ;  configuration
  126.  
  127. Msg0        DB    CR,LF,'No DGIS devices installed',CR,LF,'$'
  128. Msg1        DB    CR,LF,'No graphics devices installed',CR,LF,'$'
  129. Msg2        DB    CR,LF,'Can''t connect to graphics device',CR,LF,'$'
  130.  
  131. _DATA        ENDS
  132.  
  133.  
  134. STACK        SEGMENT    stack 'STACK'
  135.  
  136.         DB    400h dup(?)
  137.  
  138. STACK        ENDS
  139.  
  140.         END    EntryPoint
  141.