Xref: utzoo comp.sys.ibm.pc.hardware:3933 comp.os.msdos.misc:829 Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!casbah.acns.nwu.edu!hpa From: hpa@casbah.acns.nwu.edu (Peter Anvin) Newsgroups: comp.sys.ibm.pc.hardware,comp.os.msdos.misc Subject: Re: CGA 16-color mode AND rare questions Message-ID: <2069@casbah.acns.nwu.edu> Date: 17 Dec 90 22:06:07 GMT References: <1990Dec17.005334.383@iowasp.physics.uiowa.edu> Organization: Northwestern University Lines: 79 >Once upon a time long ago, I saw a reference to a file which would have the >answer to the question I'm about to ask, but I've lost the reference, so ... > >How do you put a CGA (that's right, CGA) into its 16-color, low resolution >mode? I assume it's just a matter of plugging the right values into the >CRTC and mode select registers, but what's the magic combination? > >Also, what and where is the file I mentioned above? It was a sort of >less-than-frequently-asked-questions-with-really-standard-answers file. The CGA has a mutated text mode which permits 160x100x16 graphics. The idea is similar to using the block characters in the range ASCII 219-ASCII 223 to generate very rough text mode graphics in standard text mode. This is how you (supposedly) do it (UNTESTED BY ME SINCE I DON'T RUN CGA ANYMORE): 1. Use BIOS to set the screen to 80x25 colour text mode: mov ax,0003h int 10h 2. Enable background highlight: mov dx,03D8h mov al,29h out dx,al 3. Program the CRTC to show 100 rows of 2-scan-line characters (that is, show only the first 2 rows of each character): mov dx,03D0h mov al,9 out dx,al ; CRTC register #9 mov dx,03D1h mov al,1 out dx,al ; Max line = 01h (00h,01h = 2 lines) mov dx,03D0h mov al,6 out dx,al ; CRTC register #6 mov dx,03D1h mov al,100 out dx,al ; 100 rows of text 4. Fill each even address in the VDU memory with 0DEh (if you can't see why, look it up in the IBM-ASCII table) push es push di mov di,0B800h mov es,di ; Segment address 0B800h xor di,di ; Offset 0000h mov cx,8000 ; 100 lines x 80 characters = 8000 words mov ax,00DEh ; This code makes the screen black rep stosw ; Store on the screen pop di pop es Now, the VDU RAM will consist of 2-byte cells, similar to in text mode, each of which will look like: +-----------------+-----------------+ | 1 1 0 1 1 1 1 0 | B B B B F F F F | +-----------------+-----------------+ -- ASCII code -- ---+--- ---+--- Left Right pixel pixel colour colour The offset address (in segment 0B800h) for a certain pixel (x,y) assuming (0,0) is the upper left corner, is 2*(int(x/2)+80*y)+1, if x is even it is the upper 4 bits, if x is odd it is the lower 4 bits. Since this mode is not supprted by BIOS, you cannot use BIOS to read and write pixels on the screen, nor can you write text on the display in 160x100x16 mode. You must write your own read/write-display for all purpouses. To exit 160x100x16 mode, just use BIOS function 00h to set any standard mode, such as regular 80x25 text mode: mov ax,0003h int 10h -- H. Peter Anvin +++ A Strange Stranger +++ N9ITP/SM4TKN +++ INTERNET: hpa@casbah.acns.nwu.edu FIDONET: 1:115/989.4 BITNET: HPA@NUACC RBBSNET: 8:970/101.4