16 color cga mode 1/2

 BBS: Inland Empire Archive
Date: 04-10-93 (02:18)             Number: 157
From: MATT PRITCHARD @ 930/21      Refer#: NONE
  To: ALL                           Recvd: NO  
Subj: 16 color cga mode     1/2      Conf: (1) 80xxx

Here is a reprint of an old message on 16 color CGA 160x100 graphics. The code is QuickBASIC, but should be understandable. ============================================================ ======== The following four messages are an example of how to program in the 160x100 16-color CGA mode. This mode is not supported by BIOS on standard PCs and PC clones, although it is supported on the PC Jr. No attempt to test the code on a PC Junior has been made, simply because I have no access to one. DEFINT A-Z DECLARE SUB ScreenMode160 (Mode%) DECLARE SUB ClearScreen (Mode%, DrawColor%, NoClear%) DECLARE SUB ExitMode () DECLARE SUB DrawDot (x%, y%, DrawColor%) DECLARE SUB DrawLine (x1%, y1%, x2%, y2%, DrawColor%) DECLARE SUB GetInput () DECLARE SUB Pause () RANDOMIZE TIMER ' SuperCGA version 1.0 ' Color Graphics Adapter Enhancement Routines ' Tesseract Productions ' ' BEGIN (main) SCREEN 0, 0, 0: WIDTH 80 PRINT "Super CGA" PRINT "Version 1.0" PRINT "Tesseract Productions" PRINT "Programmed by Lawrence McAlpin" PRINT "" PRINT "Demonstration program on the 160x100 128-color capabilities of the CGA" PRINT "monitor. Tested on an AT&T PC 6300 with built- in AT&T CGA and a" PRINT "Verxion 386 with BOCA SuperVGA." PRINT PRINT "WARNING! This program may not work properly on emulated CGA sreen" PRINT "modes (i.e., it may not work right on EGA, VGA, MCGA, or XGA cards.)" PRINT "The author assumes no liability for any damag that may result from" PRINT "the use of this program. If you try this program out you are" PRINT "responsible for anything that may occur." PRINT PRINT "128 Color CGA Demonstration Program" PRINT PRINT "Hit '+' or '-' to change the 'background'" PRINT "Hit 'L' or 'l' to draw random dots and lines" PRINT "Hit 'M' or 'm' to change between box and fuzzy modes" PRINT "Hit 'Q' or 'q' to quit" PRINT "PRESS ANY KEY TO CONTINUE" Pause ScreenMode160 1 ClearScreen 1, 0, 0 DrawLine 0, 1, 79, 1, 3 DrawLine 0, 1, 0, 79, 3 DrawLine 3, 1, 40, 80, 4 ' demonstrate the first 128 colors FOR counter = 0 TO 79 DrawDot counter, 15, counter NEXT counter FOR counter = 80 TO 127 DrawDot counter - 80, 20, counter NEXT counter GetInput ' Pause ' there are two types of screen 'modes' ' they are box and fuzz, ScreenMode160 and ClearScreen take the mode ' parameter for box as zero, and fuzz for anything else ' fuzz mode smooths the box-graphics so they don't look AS boxy as they ' really are ClearScreen 1, 0, 0 ' this returns you to the regular 320x200 CGA 4-color mode ' if you neglect to ExitMode then you will find your screen display ' acting extremely strangely as the registers won't be restored to ' something normal ExitMode ' END (main) END SUB DrawDot (x, y, DrawColor) ' check for out of bounds errors IF DrawColor < 0 OR DrawColor > 255 THEN EXIT SUB IF x < 0 OR x > 79 THEN EXIT SUB IF y < 0 OR y > 99 THEN EXIT SUB a = ((2 * x + (y * 160)) AND &HFFFE) + 1 n = PEEK(a) POKE a, (n AND &HF0) OR DrawColor END SUB DEFINT A-Z SUB DrawLine (x1, y1, x2, y2, DrawColor) IF ABS(x1 - x2) > ABS(y1 - y2) THEN IF x1 > x2 THEN SWAP x1, x2 SWAP y1, y2 END IF dx = (x2 - x1) dy = (y2 - y1) IF dx <> 0 THEN b! = dy / dx ELSE b! = 0 END IF m! = y1 - x1 * b! FOR x = x1 TO x2 IF b! <> 0 THEN y = INT(m! + x * b!) + .5 ELSE y = y1 END IF DrawDot x, y, DrawColor NEXT x ELSE IF y1 > y2 THEN SWAP y1, y2 SWAP x1, x2 END IF dx = (x2 - x1) dy = (y2 - y1) IF dx <> 0 THEN >>> Continued to next message === * SLMR 2.1a * Yesterday I got so old --- InterPCB 1.50 # Origin: CENTRAL BBS -Texas' BEST BBS! 214-393-7090 HST 3+GIGs (8:930/21) * Origin: Gateway System to/from RBBS-NET (RBBS-PC 1:10/8)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET