Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!brutus.cs.uiuc.edu!samsung!ginosko!uunet!portal!cup.portal.com!Hoke From: Hoke@cup.portal.com (Hoke S Johnson) Newsgroups: comp.graphics Subject: VGA 360x480x256 mode usage code examples Message-ID: <23502@cup.portal.com> Date: 30 Oct 89 06:48:05 GMT Organization: The Portal System (TM) Lines: 193 Since I received a large number of requests for code examples on how to set and use the 360x480x256 color mode on the VGA card I am posting some Turbo Pascal Code routines and code fragments that demonstrate the use of this mode. I have also included a 320x400x256 color mode set as well which is very similar to the 360x480x256 color mode. This code has been tried on the Compaq VGA card and on the Orchid Designer VGA card and it works on both. I cannot guarantee the suitability of this code for any particular VGA card but believe that it will work fine for all register level compatible VGA cards. Have fun and enjoy. The following VGA 360x480x256 mode set procedure was converted from assembly language code which appeared in the Sept/Oct 1989 Programmer's Journal Volume 7.5 in an article by Michael Abrash, who received the 360x480x256 mode set code from John Bridges who has placed them in the public domain. The conversion from assembly language to Turbo Pascal Version 5.0 was done by Hoke Johnson. {Global Declarations} Var Regs:Registers; {Turbo predefined variable} Const VGAPage:Word = $A000; {VGA video RAM segment address} Procedure VGA360; {Procedure to set standard VGA card into 360x480x256 color mode} Var Inbyte : Byte; Begin Regs.AX := $0013; Intr ($10,Regs); {Let the bios set up into 320x200x256 mode first} Port[$3c4] := $04; Port[$3c5] := $06; {Disable chain 4} {Clear out the display memory, this did not appear in the Journal article} Port[$3c4] := $02; Port[$3c5] := $0F; FillChar(Mem[VGAPage:0],65535,chr($00)); {The following Sync reset was included in the Programmer's Journal article, but I had to disable it since it causes all of my PCs to hang when I include it} { Port[$3c4] := $00; Port[$3c5] := $01;} {Sync reset} Port[$3c2] := $E7; {Use the 28mHz clock} Port[$3d4] := $11; Inbyte := Port[$3d5]; Inbyte := Inbyte and $7f; Port[$3d4] := $11; Port[$3d5] := Inbyte; {Enable the writing of CRTC Registers} {Write the CRTC Registers} Port[$3d4] := $00; Port[$3d5] := $6b; Port[$3d4] := $01; Port[$3d5] := $59; Port[$3d4] := $02; Port[$3d5] := $5a; Port[$3d4] := $03; Port[$3d5] := $8e; Port[$3d4] := $04; Port[$3d5] := $5e; Port[$3d4] := $05; Port[$3d5] := $8a; Port[$3d4] := $06; Port[$3d5] := $0d; Port[$3d4] := $07; Port[$3d5] := $3e; Port[$3d4] := $09; Port[$3d5] := $40; Port[$3d4] := $10; Port[$3d5] := $ea; Port[$3d4] := $12; Port[$3d5] := $df; Port[$3d4] := $13; Port[$3d5] := $2d; Port[$3d4] := $14; Port[$3d5] := $00; Port[$3d4] := $15; Port[$3d5] := $e7; Port[$3d4] := $16; Port[$3d5] := $06; Port[$3d4] := $17; Port[$3d5] := $e3; Port[$3d4] := $11; Port[$3d5] := $ac; End; The following code fragment shows how to write an arbitrary scanline of pixels on the screen in 360x480x256 VGA mode. The Linenumbers are numbered from 0 to 479 starting from the upper left. A byte array (Scanline) contains the pixels to be displayed. I,J,K,L are Words or Integers BT is a Byte I := Linenumber * 90; {The start of each graphic scan line is 360/4 or 90 memory addresses after the previous scan line. Each scan line occupies 90 bytes of address space and since there are four memory planes there are 90 X 4 bytes of memory (360) for each scan line. If the upper left pixel is pixel number 0, and the lower right pixel is pixel number 360x480-1, an arbitrary pixel is accessed by finding the VGA memory address which is the pixel number shifted right 2 places relative to the start of VGA memory and the memory plane number is the 2 LSBs of the pixel number} For J := 0 to DispWidth - 1 do Begin L := I + j div 4; {Calculate VGA memory address offset} k := j mod 4; {Set K = 2 LSBs of pixel number} BT := $01 shl k; {Set BT = memory plane mask code} Port[$3c4] := $02; {Index Timing Sequencer register 2} Port[$3c5] := BT; {Write memory plane select mask} Mem[VGAPage:L] := ScanLine[j]; {Write pixel} End; The following routine sets the standard VGA into 320x400x256 mode, which is very similar to the 360x480x256 mode. Writing to the screen in 320x400x256 is the same as 360x480x256 mode, the only difference is the address span of each scan line which is 80 rather than 90. Procedure VGA320x400; Var Inbyte : Byte; Begin Regs.AX := $0013; Intr ($10,Regs); Port[$3c4] := $04; Port[$3c5] := $06; {Disable chain 4} Port[$3c4] := $02; Port[$3c5] := $0F; FillChar(Mem[VGAPage:0],65535,chr($00)); Port[$3c2] := $E3; {Set the 25mHz clock} Port[$3d4] := $11; Inbyte := Port[$3d5]; Inbyte := Inbyte and $7f; Port[$3d4] := $11; Port[$3d5] := Inbyte; {Enable the writing of CRTC Registers} Port[$3d4] := $09; Port[$3d5] := $40; Port[$3d4] := $14; Port[$3d5] := $00; Port[$3d4] := $17; Port[$3d5] := $e3; End; Hoke Johnson hoke@cup.portal.com