Date: Sun, 2 Feb 1997 17:23:22 -0600 (CST) From: Steve DiCostanzo To: djgpp AT delorie DOT com Subject: Re: Programming Graphics In-Reply-To: <5cumje$n0n@sjx-ixn10.ix.netcom.com> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On 1 Feb 1997, Max wrote: > I've found that what seems to be culprits in the code involve the use > of the _inp, _outp, and _fmemset commands. *sigh* Max baby, many things can go wrong with graphics, and I still get lots of lockups, but I know a few bytes about video i/o. Problems: garbage on screen: data put in the wrong place lockups: data put in the wrong place Writing to a register at a port is theoretically a two step process { 1. select register 2. output to register } But it's really a three step process! { 0. Read from the port to make sure it's on step 1 and hasn't been left waiting for step two by some other events. 1. *Promptly* write your register number to the port to prevent other events from interfering. 2. *Promptly* write the data you want to go to the register } Here's a piece of "trivial" code to change border color on the PCjr, which contained an early, if not the earliest, Video Gate Array. (source Robert Jourdain's _The Programmer's Problem Solver_ (c) 1986 Brady Books Div., Simon & Schuster), because I don't have Michael Abrash's _Zen of Graphics Programming_ with me: asm{ mov dx,3dah ;address of video gate array chip in al,dx ;dummy read to ready the chip (step 0) mov al,2 ;register number out dx,al ;send the request mov al,4 ;turn on only bit 2 (red) out dx,al ;set the border color } Other VGA ports also require reads. In general, I'd say graphics programming is painful if you don't test code more or less a line at a time, and lockups slow you way down! I'm going to build a FAQ from my book collection, and I hate rebooting so much I may be designing a boot ROM card (public domain design) so I can experiment freely.