home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / BLACDEMO.ZIP / modex2.inc < prev    next >
Text File  |  1995-03-09  |  6KB  |  232 lines

  1. SC_INDEX     equ    03c4h   ;Sequence Controller Index
  2. CRTC_INDEX     equ    03d4h   ;CRT Controller Index
  3. MISC_OUTPUT     equ    03c2h   ;Miscellaneous Output register
  4. SCREEN_SEG     equ    0a000h  ;segment of display memory in mode X
  5. DAC_INDEX     equ    03c8h   ;DAC registers
  6. GC_INDEX    equ    03ceh    ;Graphics controller
  7.  
  8. .data
  9.  
  10. CRTParms label  word
  11.         dw      00d06h  ;vertical total
  12.         dw      03e07h  ;overflow (bit 8 of vertical counts)
  13.         dw      04109h  ;cell height (2 to double-scan)
  14.         dw      0ea10h  ;v sync start
  15.         dw      0ac11h  ;v sync end and protect cr0-cr7
  16.         dw      0df12h  ;vertical displayed
  17.         dw      00014h  ;turn off dword mode
  18.         dw      0e715h  ;v blank start
  19.         dw      00616h  ;v blank end
  20.         dw      0e317h  ;turn on byte mode
  21. CRT_PARM_LENGTH equ     (($-CRTParms)/2)
  22.  
  23.         .code
  24.  
  25. ; *********************** PROCEDURES ***************************
  26.  
  27. ;------------------- Set Mode X ----------------------
  28. ; Must be called after mode 13h is already set
  29. ;***PRE-LOAD:
  30. ;    cx = horizontal width of virtual screen ( in steps of 8 )
  31. ;        ie 320 (1 screen) requires a pre-load of 40
  32.  
  33. SetModeX    PROC NEAR
  34.     mov     dx, SC_INDEX            ;Sequencer Address register
  35.     mov     ax, 0604h               ;Index 4, unset bit 3
  36.     out     dx, ax                  ;disable Chain 4
  37.  
  38.     mov     dx, CRTC_INDEX
  39.     mov     al, 13h                 ;mode 13..chain4 dimensions
  40.     out     dx, al
  41.     inc     dx                      ;port 03d5..where we set the size
  42.     mov     al, cl                  ;screen width / 8
  43.     out     dx, al
  44.  
  45.     mov     dx, CRTC_INDEX
  46.     mov     ax, 0014h               ;disableing doubleword mode
  47.     out     dx, ax
  48.  
  49.                     ;enableing byte mode
  50.     mov     ax, 0E317h
  51.     out     dx, ax
  52.     ret
  53. SetModeX     ENDP
  54.  
  55. ;----------------------- Clear a Mode X Screen ----------------------
  56. ClearModeX    PROC NEAR
  57.  
  58.     ;clear a full unchained screen
  59.     mov     dx, 03c4h               ;Map mask register
  60.     mov     al, 2
  61.     out     dx, al
  62.     inc     dx
  63.     mov     al, 00001111b           ;ALL planes
  64.     out     dx, al
  65.  
  66.     mov     ax, 0a000h
  67.     mov     es, ax
  68.     xor     di,di
  69.     mov     cx, 32768
  70.     mov     ax, 0                   ;colour = black
  71.     cld
  72.     rep     stosw                   ;put zeros 1 word at a time
  73.     ret
  74. ClearModeX    ENDP
  75.  
  76. ;----------------- Set 320 by 240 mode -----------------
  77. ; Must be called after Mode X has been set
  78.  
  79. Set320x240 PROC NEAR
  80.         mov     dx,SC_INDEX
  81.         mov     ax,0100h
  82.         out     dx,ax   ;synchronous reset while switching clocks
  83.  
  84. ;    mov    dx, MISC_OUTPUT
  85. ;    mov    ax, 2c11h
  86. ;    out    dx, ax        ;turn off write protect
  87.  
  88.         mov     dx,MISC_OUTPUT
  89.         mov     al,0e3h
  90.         out     dx,al           ;select 28 MHz dot clock & 60 Hz scanning rate
  91.  
  92.         mov     dx,SC_INDEX
  93.         mov     ax,0300h
  94.         out     dx,ax           ;undo reset (restart sequencer)
  95.  
  96.         mov     dx,CRTC_INDEX         ;reprogram the CRT Controller
  97.         mov     al,11h          ;VSync End reg contains register write
  98.         out     dx,al           ; protect bit
  99.         inc     dx              ;CRT Controller Data register
  100.         in      al,dx           ;get current VSync End register setting
  101.         and     al,7fh          ;remove write protect on various
  102.         out     dx,al           ; CRTC registers
  103.         dec     dx              ;CRT Controller Index
  104.         cld
  105.         mov     si,offset CRTParms     ;point to CRT parameter table
  106.         mov     cx,CRT_PARM_LENGTH     ;# of table entries
  107. SetCRTParmsLoop:
  108.         lodsw                   ;get the next CRT Index/Data pair
  109.         out     dx,ax           ;set the next CRT Index/Data pair
  110.         loop    SetCRTParmsLoop
  111.  
  112.         ret
  113. Set320x240    ENDP
  114.  
  115. ;---------------- SET SCAN LINE DUPLICATION ----------------------
  116. ; *** PRE-LOAD:
  117. ;        CL = No of duplicate scan lines 
  118.  
  119. SetDScan    PROC NEAR
  120.     mov    dx, CRTC_INDEX
  121.     mov     al, 9
  122.     out     dx, al
  123.     inc     dx
  124.     in      al, dx
  125.     and     al, 0e0h                 ; Duplicate each scan ( x4 )
  126.     add     al, cl
  127.     out     dx, al
  128.     ret
  129. SetDScan    ENDP
  130.  
  131.  
  132. ; ---------------------Set the VGA Start Offset --------------------------
  133. ; *** PRE-LOAD:
  134. ;        BX = offset of screen (in multiples of 4)
  135.  
  136. SetVGAOffset    PROC NEAR
  137.     mov    dx, 3dah        ;wait for retrace before setting
  138.   l1:
  139.       in    al, dx
  140.       and    al, 08h
  141.       jnz     l1
  142.   l2:    
  143.       in    al, dx
  144.       and    al,08h
  145.       jz    l2
  146.       
  147.     mov    dx, CRTC_INDEX
  148.     mov    al, 0ch
  149.     mov    ah, bh
  150.     out    dx, ax            ;high byte
  151.     mov    al, 0dh
  152.     mov    ah, bl            ;low byte
  153.     out    dx, ax
  154.     ret
  155. SetVGAOffset    ENDP    
  156.     
  157. ;-------------------- SET WRITE MODE 1 ----------------------------------
  158. ; Sets up WM1 (write pixels from latches)
  159.  
  160. SetWM1    PROC NEAR
  161.     mov    dx, GC_INDEX
  162.     xor    ax, ax
  163.     mov    al, 08h
  164.     out    dx, al
  165.     ret
  166. SetWM1    ENDP
  167.  
  168. ;-------------------- SET WRITE MODE 0 ----------------------------------
  169. ; Returns to normal pixel writing
  170.  
  171. SetWM0    PROC NEAR
  172.     mov    dx, GC_INDEX+1
  173.     mov    al, 0FFh
  174.     out    dx, al
  175.     ret
  176. SetWM0    ENDP
  177.  
  178. ; -------------------------- SET WRITE MODE -------------------------------
  179. ; *** PRE-LOAD:
  180. ;        AH: Write Mode (0-3)
  181.  
  182. SetWriteMode    PROC NEAR
  183.     mov     dx, GC_INDEX
  184.     mov     al,5
  185.     out     dx,al
  186.     inc     dx
  187.     in      al,dx
  188.     and     al,11111100b    ;clear out write mode bits
  189.     or      al,ah
  190.     out     dx,al
  191.     ret
  192. SetWriteMode    ENDP
  193.  
  194. ; --------------- LOAD IN MASK FILE ------------------------------ 
  195. ; *** PRE-LOAD :
  196. ;        DX -  offset of filename
  197. ;        DS -  segment of buffer for mask
  198. ;        DI -  offset of buffer for mask
  199. ;        CX -  size of mask file
  200.     
  201. LoadMask    PROC NEAR
  202.  
  203.     mov ax, 3d00h                ;Open file, read only
  204.     int 21h
  205.     mov bx, ax            ;store the handle in BX
  206.     
  207.     mov    dx, di            ;& offset 
  208.     mov ah, 3Fh              ;read file
  209.     int 21h
  210.     
  211.     mov ah, 3Eh               ;close file (BX already set)
  212.     int 21h
  213.     ret
  214.  
  215. LoadMask    ENDP        
  216.  
  217.  
  218.  
  219.  
  220. ; ************************ MACROS ***************************************
  221.         
  222. ;-------------------------- Set the Map Mask ------------------------------
  223. ;*** PRE-LOAD:
  224. ;        AH - bit mask (in low nibble)
  225.  
  226. SetMask        MACRO
  227.     mov     dx, SC_INDEX
  228.         mov     al,02h            ;Map Mask index
  229.         out     dx,ax  
  230.         ENDM
  231.         
  232.