delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/05/04:18:36

From: "Alex Barsamian" <bigalex AT worldnet DOT att DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Yet another graphics problem...
Date: Sun, 5 Oct 1997 01:28:48 -0600
Organization: Biohazard Software
Lines: 342
Message-ID: <617g3k$ipr@bgtnsc03.worldnet.att.net>
NNTP-Posting-Host: 12.65.147.223
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

 I started out tonite porting my crusty mode 13h real mode graphics code out
to djgpp.  I can init the graphics mode okay, even write to the screen
without too much trouble.  Now for some reason when I began to implement the
double buffer routines into the new source file, I compile without any
trouble, but about 1/4 of the time, when I should be seeing a PCX image, I
see a blank screen (in graphics mode), and the rest of the time I get a
lovely page fault.  The source code from tonite's work follows.  It's just a
series of simple, non-portable (yet!) functions to muck around in graphics,
yet I am confounded as to why it is not working as it should.  Any
suggestions? (besides getting Allegro, which I do have, and think is
wonderful, but I just want to write this code by myself for the most part,
for the experience benefit :-)   I think we can all understand that, huh?)
Thanks in advance.  Please email as well as post, I may not be able to read
the newsgroups for a bit and I'd hate to muck thru bluesnews to find the
responses :-) )

regards,
alex

djvbepcx.c follows (the source is also attached in case the horribleness
that is IE4 screws up the formatting):

#include <stdio.h>
#include <stdlib.h>
#include <dpmi.h>
#include <sys/nearptr.h>

int c, width, height, bytes_per_line, i;
char ch;
unsigned char *videoptr = (unsigned char *)0xA0000;
unsigned char pallete[768];
unsigned char *buffer;

// switch vesa banks using int10

void VBE_SwitchBank(short bank) {
 __asm__ __volatile__("
  movw $0x4F05, %%ax;
  xorw %%bx, %%bx;
  int $0x10"
  : : "d" (bank) : "ax", "bx", "dx"
 );
}

// set a vbe mode

void VBE_SetMode(unsigned short mode) {
 __dpmi_regs regs;
 regs.x.ax = 0x4F02;
 regs.x.bx = mode;
 __dpmi_int(0x10, &regs);
}

// goto textmode

void VBE_Shutdown() {
 VBE_SetMode(0x0003);  // set to text mode
}

// Blit a buffer (unsigned char *) onscreen, switching
// banks no more than absolutely neccesary.
// this assumes the vbe 1.2 are present and functioning correctly, that is
// to say, all banks look like they are 64k whether they physically are or
// not

void copy_buffer()

        char *source;
        char *dest;
        source=buffer;
 dest = videoptr + __djgpp_conventional_base;
 __djgpp_nearptr_enable();
     /* 640*480*8bpp = 307200 bytes = 4*64K + 45056 bytes */
        VBE_SwitchBank(0);              // start at bank 0
        memcpy(dest, source, 65536L);   // copy 64k
        VBE_SwitchBank(1);              // switch to bank 1
        source += 65536L;               // copy 64k
        memcpy(dest, source, 65536L);   // rinse, lather, repeat . . . .
 VBE_SwitchBank(2);
        source += 65536L;
        memcpy(dest, source, 65536L);
 VBE_SwitchBank(3);
        source += 65536L;
        memcpy(dest, source, 65536L);
 VBE_SwitchBank(4);
        source += 65536L;
        memcpy(dest, source, 45056L);   // only 45056 because
640*480!=65536*5
        __djgpp_nearptr_disable();
}

// get a pcx, skipping most unnecessary stuff that can be assumed
// e.g., size (for now 640x480 pcx's are all i'll use, 8 bpp, etc.
// I know this is far from portable but this is just to get this thing
// rolling

unsigned char *load_pcx(char *filename)
{
        FILE *f;                        // file handle
        int count, c;                   // loop vars
        unsigned char data;             // current data
        int num_bytes;                  // number of bytes in RLE run
        unsigned char *b;               // buffer
        f = fopen(filename, "r");
        if (!f) {
                printf("file not found\n");
  return NULL;
                }

 getc(f);                    /* skip manufacturer ID */
 getc(f);                    /* skip version flag */
 getc(f);                    /* skip encoding flag */
        getc(f);

        width = -(getw(f));        /* xmin */
        height = -(getw(f));       /* ymin */
        width += getw(f) + 1;      /* xmax */
        height += getw(f) + 1;     /* ymax */

        b = malloc(width*height);  // malloc an appropriate buffer

        getc(f);                   /* skip DPI values */

        for (c=0; c<16; c++) {           /* skip the 16 color pallete */
                getc(f);                 /* originally intended on using it
*/
                getc(f);                 /* (for some reason . . . )  */
                getc(f);                 /* which is why it looks like this
*/
 }

        getc(f);                    // skip junk

        getc(f);

        bytes_per_line = getw(f);   // just in case i start to use double-
                                    // scripted buffers

 for (c=0; c<60; c++)             /* skip some more junk */
  getc(f);

        count=0;
        while(count<=(width*height)) {
  // grab first piece of RLE data
                data=getc(f);
  // is it RLE?
  if((data>=192) && (data<=255)) {
   // if it is, how long is the run?
   num_bytes=data-192;
   // now that we know how long it is, grab the data
                        // for the actual run.
                        data=getc(f);

   // plug (data) into the buffer (num_bytes) times
   while(num_bytes-->0)
                                b[count++]=data;

  } // end if RLE
 // not RLE?
 else
  // plug it in to the buffer
                b[count++]=data;
       }


 while (!feof(f)) {          /* look for a 256 color pallete */
  if (getc(f)==12) {
  for (c=0; c<256; c++) {
                        pallete[c]   = getc(f) / 4; // load it in
   pallete[c*2] = getc(f) / 4;
   pallete[c*3] = getc(f) / 4;
   }
 break;
 }
}

 fclose(f);
        return b;
}


void VBE_Pal(unsigned char ColorNo, unsigned char R,
      unsigned char G,       unsigned char B) {

 outp (0x03C8,ColorNo); // here is the pallette color I want to set
        outp (0x03C9,R);       // set r,
        outp (0x03C9,G);       // g,
        outp (0x03C9,B);       // and b compo appropriately

}

void main()

        VBE_SetMode(0x101);             // fire up graphics to 0x101
        buffer=load_pcx("picture.pcx");
        if(*buffer==NULL) {             // do we have our picture?
                VBE_Shutdown();
                printf("error loading pcx");
                exit(0);
                }

        for(i=0; i<256; ++i)            // set the pallete appropriately
              VBE_Pal(i, pallete[i], pallete[i*2], pallete[i*3]);

        copy_buffer();                  // put the buffer onscreen
        getch();
        VBE_Shutdown();
}






begin 666 djvesa.c
M(VEN8VQU9&4@/'-T9&EO+F@^#0HC:6YC;'5D92 \<W1D;&EB+F@^#0HC:6YC
M;'5D92 \9'!M:2YH/@T*(VEN8VQU9&4@/'-Y<R]N96%R<'1R+F@^#0H-"FEN
M="!C+"!W:61T:"P@:&5I9VAT+"!B>71E<U]P97)?;&EN92P@:3L-"F-H87(@
M8V@[#0IU;G-I9VYE9"!C:&%R("IV:61E;W!T<B ]("AU;G-I9VYE9"!C:&%R
M("HI,'A!,# P,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!Y7V)U9F9E<B AT I('L@(" @(" @(" -
M"B @(" @(" @8VAA<B J<V]U<F-E.PT*(" @(" @("!C:&%R("ID97-T.PT*
M(" @(" @("!S;W5R8V4]8G5F9F5R.PT*"61E<W0@/2!V:61E;W!T<B K(%]?
M9&IG<'!?8V]N=F5N=&EO;F%L7V)A<V4["2 @#0H)7U]D:F=P<%]N96%R<'1R
M7V5N86)L92 AT I DOT PT*(" @(" O*B V-# J-#@P*CAB<' @/2 S,#<R,# @8GET
M97,@/2 T*C8T2R K(#0U,#4V(&)Y=&5S("HO#0H@(" @(" @(%9"15]3=VET
M8VA"86YK*# I.R @(" @(" @(" @(" @+R\@<W1A<G0 AT 870@8F%N:R P#0H@
M(" @(" @(&UE;6-P>2AD97-T+"!S;W5R8V4L(#8U-3,V3"D[(" @+R\@8V]P
M>2 V-&L@(" @(" @(" @(" @(" @(" @(" @#0H@(" @(" @(%9"15]3=VET
M8VA"86YK*#$I.R @(" @(" @(" @(" @+R\@<W=I=&-H('1O(&)A;FL@,0T*
M(" @(" @("!S;W5R8V4@*ST AT -C4U,S9,.R @(" @(" @(" @(" @("\O(&-O
M<'D-"B @(" @(" @;65M8W!Y*&1E<W0L('-O=7)C92P AT -C4U,S9,*3L@(" O
M+R N("X@+B @( T*"59"15]3=VET8VA"86YK*#(I.PT*(" @(" @("!S;W5R
M8V4@*ST AT -C4U,S9,.R @(" @(" @( T*(" @(" @("!M96UC<'DH9&5S="P@
M<V]U<F-E+" V-34S-DPI.R @(" @#0H)5D)%7U-W:71C:$)A;FLH,RD[#0H@
M(" @(" @('-O=7)C92 K/2 V-34S-DP[(" @(" @(" @#0H@(" @(" @(&UE
M;6-P>2AD97-T+"!S;W5R8V4L(#8U-3,V3"D[(" @(" -"@E60D5?4W=I=&-H
M0F%N:R AT T*3L-"B @(" @(" @<V]U<F-E("L](#8U-3,V3#L@(" @(" @(" -
M"B @(" @(" @;65M8W!Y*&1E<W0L('-O=7)C92P@-#4P-39,*3L@(" -"B @
M(" @(" @7U]D:F=P<%]N96%R<'1R7V1I<V%B;&4H*3L@(" @(" -"GT-"@T*
M+R\@9V5T(&$@<&-X+"!S:VEP<&EN9R!M;W-T('5N;F5C97-S87)Y('-T=69F
M('1H870 AT 8V%N(&)E(&%S<W5M960-"B\O(&4N9RXL('-I>F4@*&9O<B!N;W<@
M-C0P>#0X,"!P8W AT G<R!A<F4 AT 86QL(&DG;&P@=7-E+" X(&)P<"P AT 971C+@T*
M+R\@22!K;F]W('1H:7,@:7,@9F%R(&9R;VT@<&]R=&%B;&4 AT 8G5T('1H:7,@
M:7,@:G5S="!T;R!G970@=&AI<R!T:&EN9PT*+R\@<F]L;&EN9PT*#0IU;G-I
M9VYE9"!C:&%R("IL;V%D7W!C>"AC:&%R("IF:6QE;F%M92D-"GL-"B @(" @
M(" @1DE,12 J9CL@(" @(" @(" @(" @(" @(" @(" @(" O+R!F:6QE(&AA
M;F1L90T*(" @(" @("!I;G0 AT 8V]U;G0L(&,[(" @(" @(" @(" @(" @(" @
M("\O(&QO;W @=F%R<PT*(" @(" @("!U;G-I9VYE9"!C:&%R(&1A=&$[(" @
M(" @(" @(" @("\O(&-U<G)E;G0 AT 9&%T80T*(" @(" @("!I;G0@;G5M7V)Y
M=&5S.R @(" @(" @(" @(" @(" @("\O(&YU;6)E<B!O9B!B>71E<R!I;B!2
M3$4@<G5N#0H@(" @(" @('5N<VEG;F5D(&-H87(@*F([(" @(" @(" @(" @
M(" @+R\@8G5F9F5R#0H@(" @(" @(&8@/2!F;W!E;BAF:6QE;F%M92P@(G(B
M*3L@(" @(" @#0H@(" @(" @(&EF("@A9BD@>PT*(" @(" @(" @(" @(" @
M('!R:6YT9B AT B9FEL92!N;W0 AT 9F]U;F1<;B(I.PT*"0ER971U<FX AT 3E5,3#L-
M"B @(" @(" @(" @(" @("!]#0H-"@EG971C*&8I.R @(" @(" @(" @(" @
M(" @(" @+RH@<VMI<"!M86YU9F%C='5R97(@240@*B\-"@EG971C*&8I.R @
M(" @(" @(" @(" @(" @(" @+RH@<VMI<"!V97)S:6]N(&9L86<@*B\-"@EG
M971C*&8I.R @(" @(" @(" @(" @(" @(" @+RH@<VMI<"!E;F-O9&EN9R!F
M;&%G("HO#0H@(" @(" @(&=E=&,H9BD[#0H-"B @(" @(" @=VED=&@@/2 M
M*&=E='<H9BDI.R @(" @(" @+RH@>&UI;B J+PT*(" @(" @("!H96EG:'0@
M/2 M*&=E='<H9BDI.R @(" @(" O*B!Y;6EN("HO#0H@(" @(" @('=I9'1H
M("L](&=E='<H9BD@*R Q.R @(" @("\J('AM87@@*B\-"B @(" @(" @:&5I
M9VAT("L](&=E='<H9BD@*R Q.R @(" @+RH@>6UA>" J+PT*#0H@(" @(" @
M(&(@/2!M86QL;V,H=VED=&@J:&5I9VAT*3L@("\O(&UA;&QO8R!A;B!A<'!R
M;W!R:6%T92!B=69F97(-"@T*(" @(" @("!G971C*&8I.R @(" @(" @(" @
M(" @(" @(" O*B!S:VEP($1022!V86QU97,@*B\-"@T*(" @(" @("!F;W(@
M*&,],#L AT 8SPQ-CL@8RLK*2![(" @(" @(" @(" O*B!S:VEP('1H92 Q-B!C
M;VQO<B!P86QL971E("HO#0H@(" @(" @(" @(" @(" @9V5T8RAF*3L@(" @
M(" @(" @(" @(" @("\J(&]R:6=I;F%L;'D@:6YT96YD960@;VX@=7-I;F<@
M:70@*B\-"B @(" @(" @(" @(" @("!G971C*&8I.R @(" @(" @(" @(" @
M(" @+RH@*&9O<B!S;VUE(')E87-O;B N("X@+B I(" J+PT*(" @(" @(" @
M(" @(" @(&=E=&,H9BD[(" @(" @(" @(" @(" @(" O*B!W:&EC:"!I<R!W
M:'D@:70@;&]O:W,@;&EK92!T:'5S("HO#0H)?0T*#0H@(" @(" @(&=E=&,H
M9BD[(" @(" @(" @(" @(" @(" @(" O+R!S:VEP(&IU;FL@#0H-"B @(" @
M(" @9V5T8RAF*3L-"@T*(" @(" @("!B>71E<U]P97)?;&EN92 ](&=E='<H
M9BD[(" @+R\@:G5S="!I;B!C87-E(&D@<W1A<G0@=&\@=7-E(&1O=6)L92T-
M"B @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @("\O('-C<FEP
M=&5D(&)U9F9E<G,-"@T*"69O<B H8STP.R!C/#8P.R!C*RLI(" @(" @(" @
M(" @("\J('-K:7 @<V]M92!M;W)E(&IU;FL@*B\-"@D)9V5T8RAF*3L-"@T*
M(" @(" @("!C;W5N=#TP.PT*(" @(" @("!W:&EL92AC;W5N=#P]*'=I9'1H
M*FAE:6=H="DI('L-"@D)+R\@9W)A8B!F:7)S="!P:65C92!O9B!23$4 AT 9&%T
M80T*(" @(" @(" @(" @(" @(&1A=&$]9V5T8RAF*3L-"@D)+R\@:7,@:70@
M4DQ%/PT*"0EI9B AT H9&%T83X],3DR*2 F)B H9&%T83P],C4U*2D@>PT*"0D)
M+R\@:68@:70@:7,L(&AO=R!L;VYG(&ES('1H92!R=6X_#0H)"0EN=6U?8GET
M97,]9&%T82TQ.3([#0H)"0DO+R!N;W<@=&AA="!W92!K;F]W(&AO=R!L;VYG
M(&ET(&ES+"!G<F%B('1H92!D871A#0H@(" @(" @(" @(" @(" @(" @(" @
M(" O+R!F;W(@=&AE(&%C='5A;"!R=6XN#0H@(" @(" @(" @(" @(" @(" @
M(" @("!D871A/6=E=&,H9BD[#0H-"@D)"2\O('!L=6<@*&1A=&$I(&EN=&\@
M=&AE(&)U9F9E<B H;G5M7V)Y=&5S*2!T:6UE<PT*"0D)=VAI;&4H;G5M7V)Y
M=&5S+2T^,"D-"B @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @8EMC
M;W5N="LK73UD871A.PT*#0H)"7T@+R\@96YD(&EF(%),10T*"2\O(&YO="!2
M3$4_#0H)96QS90T*"0DO+R!P;'5G(&ET(&EN('1O('1H92!B=69F97(-"B @
M(" @(" @(" @(" @("!B6V-O=6YT*RM=/61A=&$[#0H@(" @(" @?0T*#0H@
M(" @(" @( T*"7=H:6QE("@A9F5O9BAF*2D@>R @(" @(" @(" O*B!L;V]K
M(&9O<B!A(#(U-B!C;VQO<B!P86QL971E("HO#0H)"6EF("AG971C*&8I/3TQ
M,BD@>PT*"0EF;W(@*&,],#L AT 8SPR-38[(&,K*RD@>PT*(" @(" @(" @(" @
M(" @(" @(" @(" @<&%L;&5T95MC72 @(#T AT 9V5T8RAF*2 O(#0[("\O(&QO
M860@:70@:6X-"@D)"7!A;&QE=&5;8RHR72 ](&=E=&,H9BD@+R T.PT*"0D)
M<&%L;&5T95MC*C-=(#T AT 9V5T8RAF*2 O(#0[#0H)"2!]#0H)8G)E86L[#0H)
M?0T*?0T*#0H)9F-L;W-E*&8I.PT*(" @(" @("!R971U<FX AT 8CL-"GT-"@T*
M#0IV;VED(%9"15]086PH=6YS:6=N960 AT 8VAA<B!#;VQO<DYO+"!U;G-I9VYE
M9"!C:&%R(%(L#0H)(" @("!U;G-I9VYE9"!C:&%R($<L(" @(" @('5N<VEG
M;F5D(&-H87(@0BD@>PT*#0H);W5T<" H,'@P,T,X+$-O;&]R3F\I.R O+R!H
M97)E(&ES('1H92!P86QL971T92!C;VQO<B!)('=A;G0@=&\@<V5T#0H@(" @
M(" @(&]U=' @*#!X,#-#.2Q2*3L@(" @(" @+R\@<V5T('(L#0H@(" @(" @
M(&]U=' @*#!X,#-#.2Q'*3L@(" @(" @+R\@9RP-"B @(" @(" @;W5T<" H
M,'@P,T,Y+$(I.R @(" @(" O+R!A;F0 AT 8B!C;VUP;R!A<'!R;W!R:6%T96QY
M#0H-"GT-"B @(" @(" @(" @(" @(" @(" @(" @(" -"G9O:60@;6%I;B AT I
M('L@(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" -"B @
M(" @(" @5D)%7U-E=$UO9&4H,'@Q,#$I.R @(" @(" @(" @(" O+R!F:7)E
M('5P(&=R87!H:6-S('1O(#!X,3 Q#0H@(" @(" @(&)U9F9E<CUL;V%D7W!C
M>"@B<&EC='5R92YP8W AT B*3L-"B @(" @(" @:68H*F)U9F9E<CT]3E5,3"D@
M>R @(" @(" @(" @(" O+R!D;R!W92!H879E(&]U<B!P:6-T=7)E/PT*(" @
M(" @(" @(" @(" @(%9"15]3:'5T9&]W;B AT I DOT PT*(" @(" @(" @(" @(" @
M('!R:6YT9B AT B97)R;W(@;&]A9&EN9R!P8W AT B*3L-"B @(" @(" @(" @(" @
M("!E>&ET*# I.PT*(" @(" @(" @(" @(" @('T-"@T*(" @(" @("!F;W(H
M:3TP.R!I/#(U-CL@*RMI*2 @(" @(" @(" @("\O('-E="!T:&4@<&%L;&5T
M92!A<'!R;W!R:6%T96QY#0H@(" @(" @(" @(" @(%9"15]086PH:2P@<&%L
M;&5T95MI72P@<&%L;&5T95MI*C)=+"!P86QL971E6VDJ,UTI.PT*#0H@(" @
M(" @(&-O<'E?8G5F9F5R*"D[(" @(" @(" @(" @(" @(" @+R\@<'5T('1H
M92!B=69F97(@;VYS8W)E96X-"B @(" @(" @9V5T8V AT H*3L@(" @(" @(" @
L(" @(" @(" @(" @(" -"B @(" @(" @5D)%7U-H=71D;W=N*"D[#0I]#0H`
`
end

- Raw text -


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