home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pctech / pctj1188.arc / VGAZOOM2.ASM < prev   
Assembly Source File  |  1988-09-14  |  16KB  |  353 lines

  1. ;********************************************************************
  2. ; File VGAZOOM2 - 1280*400 VGA driver procedures
  3. ; Written by Arun Johary & Bo Ericsson,
  4. ; Chips & Technologies Inc.
  5.  
  6. ; This file is not executable as stand-alone. 
  7. ; After assembling, link it with VGAZOOM.OBJ, 
  8. ; then convert to .COM with EXE2BIN.
  9.  
  10. ; Resulting VGAZOOM.COM is a TSR for implementing 1280x480 mode,
  11. ; with zooming to/from 640X480 mode and panning. 
  12. ;********************************************************************
  13.  
  14. LORES equ 0
  15. HIRES equ 1
  16.  
  17. public DRAWCHR
  18. public SETMODE
  19. public HORIZ_SCROLL_4
  20. public VERT_SCROLL
  21. public EndOfProgram
  22.  
  23. code segment para public 'code'
  24.      assume cs:code
  25.  
  26. ;********************************************************************
  27. SETMODE proc near
  28. ; This procedure programs the VGA registers for one of two
  29. ; modes depending on AX
  30. ;  AX  = HIRES -- high resolution 1280*400 monochrome mode
  31. ;  AX  = LORES -- 640*400 monochrome mode
  32.  
  33.         push    cs      ; DS = CS because parameter tables
  34.         pop     ds      ;  are in the current segment
  35.         cld             ; clear for subsequent auto increment
  36.         cmp     ax, HIRES       ; Hires mode ?
  37.         jne     SetMode01       ; if no, test for LORES mode
  38.         lea     bx, HTABLE      ;HIRES table selected
  39.         jmp     SetTheMode      ;program the parameters
  40. SetMode01:                      ;Test for LORES mode
  41.         cmp     ax, LORES       ;LORES mode ?
  42.         jne     SetMode_End1    ;invalid parameter, return to caller
  43.         lea     bx, LTABLE      ;lores table selected
  44.         jmp     SetTheMode      ;program the parameters
  45. SetMode_End1:
  46.         jmp     SetMode_End
  47. SetTheMode:                     ;Sync reset while programming mode
  48.         mov     dx, 3C4H        ;sequencer address
  49.         mov     ax, 0200h       ;sync. reset
  50.         out     dx, ax          ;write the register
  51.                                 ;Set miscellaneous output register
  52.         mov     dx, 3C2H        ;miscllaneous output register address
  53.         mov     al, [bx+9]      ;table value for Misc Output Register.
  54.         out     dx, al          ;write the register
  55.                                 ;Set sequencer registers 01-04
  56.         mov     dx, 3C4H        ;sequencer address
  57.         mov     cx, 4           ;4 registers to write
  58.         mov     ah, 1           ;start with register 1
  59.         mov     si, bx          ;beginning of parameter table
  60.         add     si, 5           ;point to sequencer params in table
  61.         call    W_IndexRegs     ;program the registers
  62.                                 ;Get out of synchronous reset
  63.         mov     dx, 3C4H        ;sequencer address
  64.         mov     ax, 0300h       ;out of reset mode
  65.         out     dx, ax          ;write register
  66.                                 ;Unprotect CRT controller
  67.         mov     dx, 3D4H        ;crtc address
  68.         mov     ax, 011h        ;vertical sync end register
  69.         out     dx, ax          ;set protect bit (D7) to 0
  70.                                 ;Set CRT controller registers 00-18
  71.         mov     cx, 25          ;25 registers to write
  72.         xor     ah, ah          ;start with CRTC register 0
  73.         mov     si, bx          ;beginning of parameter table
  74.         add     si, 10          ;point to CRTC parameters in the table
  75.         call    W_IndexRegs     ;program the registers
  76.                                 ;Set Graphics controller regs 00-08
  77.         mov     dx, 3CEH        ;graphics ctrl address
  78.         mov     cx, 9           ;9 registers to write
  79.         xor     ah, ah          ;start with GC register 0
  80.         mov     si, bx          ;beginning of parameter table
  81.         add     si, 55          ;point to GC parameter in the table
  82.         call    W_IndexRegs     ;program the registers
  83.                                 ;Set Attribute controller regs 00-14
  84.         mov     dx, 3DAH        ;Status register address
  85.         in      al, dx          ;reset attribute flip-flop
  86.         mov     dx, 3c0h        ;attribute ctrl address
  87.         mov     cx, 20          ;20 registers to write
  88.         xor     ah, ah          ;start with register 0
  89.         mov     si, bx          ;beginning of parameter table
  90.         add     si, 35          ;point to Attr. Ctrl params in table
  91.         call    W_Attr_Regs     ;program the registers
  92.         mov     al, 14h         ;write to Attribute color select reg 
  93.         out     dx, al          ;(not stored in parameter table)
  94.         xor     al, al          ;data = 0
  95.         out     dx, al          ;write data
  96.         mov     al, 20h         ;reenable video
  97.         out     dx, al          ;write the index reg to reenable video
  98.                                 ;Set external palette
  99.         mov     dx, 3C6H        ;Palette mask register
  100.         mov     al, 0ffh        ;enable all 8 bits
  101.         out     dx, al          ;write the mask
  102.         mov     dx, 3C8H        ;Palette address register
  103.         lea     si,[bx+64]      ;point to palette parms in table
  104.         xor     ah,ah           ;start at palette reg 0
  105.         mov     cx,4            ;set 4 colors
  106.         call    W_Palette       ;program the palette registers
  107. SetMode_End:    ;end of this procedure
  108.         ret
  109.  
  110. ;********************************************************************
  111. ; These two tables provide parameters for programming VGA hardware
  112. ; in each of two modes.
  113.  
  114. HTABLE label byte  ; parameter table for 1280*400 mono mode
  115.  
  116. db 000h, 000h, 000h, 000h, 000h   ; Dymmy header
  117. db 005h, 00Fh, 000h, 00eh         ; Sequencer offsets 01-04
  118. db 063h                           ; Miscellaneous register
  119.  
  120.                    ; CRT Controller offsets 00-18h
  121. db 05Fh, 04Fh, 050h, 082h, 054h, 080h, 0bFh, 01Fh
  122. db 020h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
  123. db 09ch, 00eh, 08Fh, 014h, 060h, 096h, 0b9h, 0abh, 0FFh
  124.  
  125.                    ; Attribute Controller offsets 00-13h
  126. db 000h, 001h, 002h, 003h, 004h, 005h, 006h, 007h
  127. db 008h, 009h, 00ah, 00bh, 00ch, 00dh, 00eh, 00Fh
  128. db 001h, 000h, 003h, 000h
  129.  
  130.                    ; Graphics Controller offsets 00-08
  131. db 000h, 000h, 000h, 000h, 000h, 020h, 005h, 00Fh, 0FFh
  132.  
  133.                    ; DAC Palette registers 0-3
  134. db 000h, 000h, 000h               ;reg 0: black
  135. db 01ah, 01ah, 01ah               ;reg 1: grey
  136. db 01ah, 01ah, 01ah               ;reg 2: grey
  137. db 02ah, 02ah, 02ah               ;reg 3: white
  138.  
  139. ;********************************************************************
  140. LTABLE label byte  ; parameter table for 640*400 mode
  141.  
  142. db 000h, 000h, 000h, 000h, 000h   ; Dymmy header
  143. db 011h, 00Fh, 000h, 00eh         ; Sequencer offsets 01-04
  144. db 063h                           ; Miscellaneous register
  145.  
  146.                    ; CRT Controller offsets 00-18h
  147. db 05Fh, 050h, 052h, 0e2h, 054h, 0e0h, 0bFh, 01Fh
  148. db 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
  149. db 09ch, 00eh, 08Fh, 014h, 060h, 096h, 0b9h, 0a3h, 0FFh
  150.  
  151.                    ; Attribute Controller offsets 00-13h
  152. db 000h, 001h, 002h, 003h, 004h, 005h, 006h, 007h
  153. db 008h, 009h, 00ah, 00bh, 00ch, 00dh, 00eh, 00Fh
  154. db 001h, 000h, 001h, 000h
  155.  
  156.                    ; Graphics Controller offsets 0-8
  157. db 000h, 000h, 000h, 000h, 000h, 000h, 005h, 00Fh, 0FFh
  158.  
  159.                    ; DAC Palette registers 0-3
  160. db 000h, 000h, 000h               ;reg 0: black
  161. db 02ah, 02ah, 02ah               ;reg 1: white
  162. db 02ah, 02ah, 02ah               ;reg 2: white
  163. db 02ah, 02ah, 02ah               ;reg 3: white
  164.  
  165. SETMODE endp
  166.  
  167. ;********************************************************************
  168. DRAWCHR proc near
  169. ; this procedure draws a character on the screen in the graphics
  170. ; mode; parameters are expected to be as follows:
  171. ; AL: -- char code
  172. ; BX: -- bit map width
  173. ; DX: -- font height (8 bits only)
  174. ; DS:SI -- Disp Mem pointer
  175. ; ES:DI -- Font pointer
  176.  
  177.         push    cx              ;save CX
  178.         mov     cx,dx           ;get char height in CX
  179.         mul     dl              ;AX gets font offset for character
  180.         add     di,ax           ;ES:DI gets font address for font
  181. LABL0:
  182.         mov     ah,es:[di]      ;read font pattern
  183.         mov     ds:[si],ah      ;write into display memory
  184.         inc     di              ;next line of font pattern
  185.         add     si,bx           ;next line in display memory
  186.         loop    LABL0           ;repeat for every scan line
  187.         pop     cx              ;retrieve CX
  188.         ret
  189. DRAWCHR endp
  190.  
  191. ;********************************************************************
  192. W_INDEXREGS proc near
  193. ;This procedure reads a byte from the parameter table and then
  194. ;writes it to a index/data register. 
  195. ; AH = index number of first register to receive parameter
  196. ; CX = # of index registers to be loaded
  197. ; DX -- I/O port address,
  198. ; DS:SI -- points to parameters
  199.  
  200.         lodsb                   ;load parameter from table into AL
  201.         xchg    al, ah          ;get index in AL, data in AH
  202.         out     dx, ax          ;write index/data register pair
  203.         xchg    al, ah          ;get index in AH
  204.         inc     ah              ;next index
  205.         loop    W_IndexRegs     ;repeat
  206.         ret
  207. W_INDEXREGS endp
  208.  
  209. ;********************************************************************
  210. W_ATTR_REGS proc near
  211. ;This procedure reads a byte from the parameter table and then
  212. ; writes it to a self index/data register. 
  213. ; AH = index number of first register to receive parameter
  214. ; CX = # of index registers to be loaded
  215. ; DX -- I/O port address,
  216. ; DS:SI -- points to parameters
  217.  
  218.         xchg    al, ah          ;get index in AL
  219.         out     dx, al          ;write index
  220.         xchg    al, ah          ;get index in AH
  221.         lodsb                   ;get data from table in AL
  222.         out     dx, al          ;write data
  223.         inc     ah              ;next index
  224.         loop    W_Attr_Regs     ;repeat
  225.         ret
  226. W_ATTR_REGS endp
  227.  
  228. ;********************************************************************
  229. W_PALETTE proc near
  230. ; This procedure reads a byte from the parameter table and then
  231. ; writes it to the G171 palette/DAC. DS:SI -- point to parameters,
  232. ; AH = starting index number, 
  233. ; CX = # of index registers, 
  234. ; DX -- I/O addr of DAC address reg, 
  235. ; DS:SI pointer to data area
  236.  
  237.         mov     al,ah           ;get start index number
  238.         out     dx,al           ;send it to address reg
  239.         inc     dx              ;point to DAC data reg
  240. W_pal1: lodsb                   ;load data parameter
  241.         out     dx, al          ;write red data 
  242.         lodsb                   ;load next data byte    
  243.         out     dx, al          ;write green data
  244.         lodsb                   ;repeat w/blue data 
  245.         out     dx, al
  246.         loop    W_Pal1          ;repeat w/next palette reg
  247.         ret
  248. W_PALETTE endp
  249.  
  250. ;********************************************************************
  251. RD_INDEXREG proc near
  252. ;This procedure reads an indexed VGA register
  253. ; Input: AL = index number of register
  254. ;        DX = I/O address of register
  255. ; Ouput: register contents returned in AL
  256.  
  257.         out     dx,al           ; write index
  258.         inc     dx              ; point to data register
  259.         in      al,dx           ; read data register
  260.         dec     dx              ; point to index register
  261.         ret
  262. RD_INDEXREG endp
  263.  
  264. ;********************************************************************
  265. VERT_SCROLL proc near
  266. ; This procedure scrolls the screen up or down by a specified number 
  267. ; of lines; parameters are expected to be as follows:
  268. ;       AX -- scroll count, # scan lines in 2's complement form,
  269. ;             negative for scroll down
  270. ;       BX -- bit map width
  271.  
  272.         imul    bx              ;AX = bytes to scroll
  273.         mov     bx,ax           ;save start address change in BX
  274.         mov     dx,3d4h         ; CRT address
  275.         mov     al,0ch          ; start address high
  276.         call    Rd_IndexReg     ;read register
  277.         mov     ah,al           ;move to AH
  278.         mov     dx,3d4h         ; CRT address
  279.         mov     al,0dh          ; start address low
  280.         call    Rd_IndexReg     ;read register
  281.         add     bx,ax           ;add change to old start address
  282.         mov     ah,bh           ;to get new start address, write the
  283.         mov     al,0ch          ;high byte back to CRTC
  284.         out     dx,ax           ;write new start address (HIGH)
  285.         inc     al              ;point to start address LOW register
  286.         mov     ah,bl           ;get lower byte of start address
  287.         out     dx,ax           ;write new start address (LOW)
  288.         ret
  289. VERT_SCROLL endp
  290.  
  291. ;********************************************************************
  292. HORIZ_SCROLL_4 proc near
  293. ; This procedure scrolls the screen left or right by a specified
  294. ; number of pixels. Parameters are expected to be as follows:
  295. ;       AX -- scroll count, # pixels in 2's complement form,
  296. ;             positive - scroll right, negative, scroll left.
  297.  
  298.         mov     bx, ax          ;save scroll count
  299.         mov     dx,3d4h         ; CRT address
  300.         mov     al,0ch          ; start address high
  301.         call    Rd_IndexReg     ;read register
  302.         mov     ah,al           ;move to AH
  303.         mov     dx,3d4h         ; CRT address
  304.         mov     al,0dh          ; start address low
  305.         call    Rd_IndexReg     ;read register
  306.         mov     bp,ax           ;save current start address
  307.         mov     dx,3d4h         ; CRT address
  308.         mov     al,08h          ; byte panning control
  309.         call    Rd_IndexReg     ;read register
  310.         mov     cl,2
  311.         shr     al,cl           ;divide by 4
  312.         and     al,18h          ;retain bits D3 and D4 only
  313.         mov     ah,al           ;save in ah
  314.         mov     dx,3DAH         ;Status register address
  315.         in      al,dx           ;reset attribute flip flop
  316.         mov     dx,3C0H         ;address for attribute controller
  317.         mov     al,33h          ;Panning Control
  318.         out     dx,al           ;point to attribute panning register
  319.         inc     dx              ;point to data register
  320.         in      al,dx           ;read current byte panning control
  321.         dec     dx              ;point back to Attr Ctrl address
  322.         and     al,7            ;retain bits D0-D2
  323.         add     ah,al           ;get old absolute panning control
  324.         mov     al,ah           ;move to AL, 0 into AH
  325.         xor     ah,ah           ;Absolute panning in AX
  326.         add     bx,ax           ;compute new absolute panning
  327.         mov     ax,bx           ;get it into AX
  328.         and     al,7            ;retain bits D0-D2
  329.         out     dx,al           ;write new attribute pan control
  330.         mov     ax,bx           ;new absolute pan control in AX
  331.         mov     cl,2    
  332.         shl     ax,cl           ;multiply by 4
  333.         mov     ah,al           ;save in AH
  334.         and     ah,60h          ;retain bits D6-D5
  335.         mov     dx,3D4H         ;CRTC address
  336.         mov     al,8            ;index for byte panning control reg
  337.         out     dx,ax           ;write new byte panning control
  338.         mov     cl,5    
  339.         sar     bx,cl           ;start address adjust
  340.         add     bx,bp           ;new start address
  341.         mov     ah,bh           ;upper bits go into start address
  342.         mov     al,0ch          ;Start Address high register index
  343.         out     dx,ax           ;Write start address high
  344.         inc     al              ;Start Address low index
  345.         mov     ah,bl           ;low byte of start address
  346.         out     dx,ax           ;Write start address low
  347.         ret
  348. HORIZ_SCROLL_4 endp
  349.  
  350. EndOfProgram label byte
  351. code    ends
  352.         end
  353.