www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/12/16/06:58:48

From: ANTHONY APPLEYARD <A DOT APPLEYARD AT fs1 DOT mt DOT umist DOT ac DOT uk>
To: DJGPP AT SUN DOT SOE DOT CLARKSON DOT EDU
Date: Fri, 16 Dec 1994 10:41:49 GMT
Subject: Re: New PC: driver or screen funny when in Gnu C

  I asked why in 64K-colours all writes to screen address 0xd0000000+n were
actually going to screen offset (n % 0x10000).
  dj AT stealth DOT ctron DOT com (DJ Delorie) replied on Wed 14 Dec 94 10:43:00 -0500:-
  > The bank flipping isn't happening, so you are always writing to the first
64K of video memory. You need to either use GR or GRX to handle the page
flipping for you, or manually program your VGA card. Selecting the mode with
GRX (heck, <<selecting any mode>>) enables the automatic page flipping.

  Which I did. The new form of my program follows at the end of this message.
  I copied in the declaration and use of void GrSetBIOSMode(int,int,int,int)
hereinunder most carefully out of C:\DJGPP\CONTRIB\LIBGRX\SRC\SETMODE.C, where
it is declared thus:-
 void GrSetBIOSMode(int BIOSno,int width,int height,int colors) {
 int_setmode(GR_80_25_text,((BIOSno > 0) ? BIOSno : 1),width,height,colors);}
  I copied C:\DJGPP\CONTRIB\LIBSRC\LIB\LIBGRX.A into C:\DJGPP\LIB\ so that the
`-l' call-a-library option would find it.
  I compiled the program with    c:\djgpp\bin\gcc test64ks.cc -lgrx
  But gcc then said "test64ks.cc(.text+0x262): undefined reference to
`GrSetBIOSMode(int, int, int, int)'".
  I examined the file LIBGRX.A with a text editor, and I found in it the name
of my desired function `_GrSetBIOSMode' present and correct along with all the
other names of its library functions. What happened? (What I found in LIBGRX.A
was the name `_GrSetBIOSMode' literally with no tail-end rhubarb such as
`_iiii' or whatever added to indicate the parameters. I am calling it from a
Gnu C++ program.)
  ///////////////////////////////////////////////////////
#include <stdio.h>
#include <math.h>
#include <builtin.h>
#include <stdio.h>
#include <std.h>
#include <pc.h>
extern void GrSetBIOSMode(int,int,int,int); /****************/
/*-----*/
long _ax,_bx,_cx,_dx; long _si,_di,_bp,_es; long GP_4; short GP_2; char GP_1;
#define _SWOPR() /* swop registers with saved registers */ ({ \
asm("xchgl %eax,__ax"); asm("xchgl %ebx,__bx"); asm("xchgl %ecx,__cx"); \
asm("xchgl %edx,__dx"); asm("xchgl %esi,__si"); asm("xchgl %edi,__di"); \
asm("xchgl %ebp,__bp");})
/*-----*/
void int10() {_SWOPR(); asm("int $0x10"); _SWOPR();}
void int21() {_SWOPR(); asm("int $0x21"); _SWOPR();}
/*-----*/
unsigned char get_key(){_ax=0x0700; int21(); return _ax&255;}
/*-----*/
unsigned char gp_mode(void) {_ax=0x0f00; int10(); return _ax&255;}
/*-----*/
void gp_mode(char m) {_ax=m; int10();
if(m!=gp_mode()) printf("\007error: this computer has no mode 0x%1x\n",m);}
/*-----*/
class Screen{public:
short int wide,high; char mode,type; unsigned short*screen;
Screen(int Wide,int High,int Mode,unsigned short*scr=0);};
/*-----*/
Screen::Screen(int Wide,int High,int Mode,unsigned short*scr){
wide=Wide; high=High; mode=Mode;
screen=scr?(unsigned short*)scr:(unsigned short*)0xd0000000;}
/*-----*/
unsigned short color(int r,int g,int b) {r>>=3; g>>=2; b>>=3;
unsigned short i=(r<<11)|(g<<5)|b;
return i /* ((i&0xff00)>>8)|((i&0x00ff)<<8) */ ;}
/*-----*/
void Graphmode(Screen&scr){gp_mode(scr.mode);}
void Textmode(){gp_mode(3);}
/*----------*/
main(){long int r,g,b,i,j,k; unsigned short*screen=0;
FILE*debug=fopen("t$debug","w"); unsigned short S[640*480];
GrSetBIOSMode(0x64,640,480,64*1024); /****************************/
Screen scr(640,480,0x64,screen); /* this on my PC is a 64K-color mode */
Graphmode(scr); k=0;
for(r=0;r<256;r+=8) for(g=0;g<256;g+=4) for(b=0;b<256;b+=8) {
    i=(b>>3)+((g>>2)&15)*32; j=(r>>3)+(g>>6)*32; S[i+j*640]=color(r,g,b);}
for(i=0;i<480;i++) S[i*641]=0;
for(j=i=0;i<640*128;i++,j++) {
    if(j==640*32) {if(!get_key()) get_key(); j=0;}
    scr.screen[j]=S[i];}
if(!get_key()) get_key(); OUT: Textmode();
printf("%08x\n",k);}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019