-2

I am trying to import Anand.BMP file in the graphics window of TCPP,
for this its source code is as follows
(NOTE: I have not mentioned the header files in the source code):

struct A
{
 char type[2];
 unsigned long size;
 unsigned short int reserved1,reserved2;
 unsigned long offset;
 unsigned long width,height;
 unsigned short int planes;
 unsigned short int bits;
 unsigned long compression;
 unsigned long imagesize;
 unsigned long xresolution,yresolution;
 unsigned long ncolors;
 unsigned long importantcolors;
}HEADER;
huge DetectSvga()
{
 return 2;
}
void show()
{
 fstream File;
 File.open("C:\\TURBOC3\\BIN\\Anand.BMP",ios::in|ios::binary);
 char ch;
 File.read((char*)&HEADER,sizeof(HEADER));
 unsigned int i;
 char ColorBytes[4];
 char *PaletteData;
 PaletteData=new char[256*3];
 if(PaletteData)
 {
  for(i=0;i<256;i++)
  {
   File.read(ColorBytes,4);
   PaletteData[(int)(i*3+2)]=ColorBytes[0]>>2;
   PaletteData[(int)(i*3+0)]=ColorBytes[2]>>2;
  }
  outp(0x03c8,0);
  for(i=0;i<256*3;i++)
   outp(0x03c9,PaletteData[i]);
  delete[]PaletteData;
 }
 for(i=0;i<HEADER.height;i++)
 {
  for(int j=0;j<HEADER.width;)
  {
   File.read(&ch,1);
   putpixel(0+(j++),0+HEADER.height-i-1,ch);
  }
 }
 File.close();
}
void main()
{
 clrscr();
 int gd=DETECT,gm,a;
 initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
 installuserdriver("svga256",&DetectSvga);
 show();
 getch();
 closegraph();
}

Now, i am not getting the BMP file in the graphics window,
i.e,
Graphics Window is not displaying Anand.bmp properly; Output is displayed like this
so how to fix it?
Here I am attaching my Anand.BMP file for convenience.

I think palette is not properly displayed through PaletteData pointer,
i.e, error is in this block of codes:

for(i=0;i<256;i++)
  {
   File.read(ColorBytes,4);
   PaletteData[(int)(i*3+2)]=ColorBytes[0]>>2;
   PaletteData[(int)(i*3+0)]=ColorBytes[2]>>2;
  }

As per suggestions I have modified the above codes as follows:
[EDIT] :

typedef unsigned long   DWORD;
typedef unsigned int  WORD;
typedef unsigned short  BYTE;

//---------------------------------------------------------------------------
class BMP
{
 public:
  BYTE *data;
  DWORD size;
  #pragma pack(push,1)
  struct _hdr
  {
   char ID[2];
   DWORD size;
   WORD reserved1[2];  // ?
   DWORD offset;
   DWORD reserved2;    // ?
   DWORD width,height;
   WORD planes;
   WORD bits;
   DWORD compression;
   DWORD imagesize;
   DWORD xresolution,yresolution;
   DWORD ncolors;
   DWORD importantcolors;
  };
  #pragma pack(pop)
  BMP(){ data=NULL; free(); }

  ~BMP(){ free(); }

  void free(){ if (data) delete[] data; data=NULL; size=0;  }
  void load(char* filename)
  {
   FILE *hnd;
   free();
   if ((hnd=fopen(filename, "rb")) == NULL) return; // open file for read binary (not sure with the "b" check in build help)
   size=fseek(hnd,0,2);
   fseek(hnd,0,0);
   BYTE data[256];
   if (data==NULL)          // not enough memory or empty file
   {
    size=0;
    fclose(hnd);      
    return;
   }
   fread(data,256,1,hnd); // read 256 of 1 BYTES into data array
   fclose(hnd); // close file
  }
  void draw(int x0,int y0)
  {
   _hdr *hdr=(_hdr*)data;
   int x,y,xs,ys,skip;
   DWORD pal[256],c;  // palete to convert 8bpp -> 32bit VCL color
   BYTE *p;
   if (size<2) return;
   if (hdr->ID[0]!='B') return;    // check magic number
   if (hdr->ID[1]!='M') return;
   if (hdr->planes!=1) return;     // check format
   if (hdr->bits!=8) return;
   if (hdr->compression!=0) return;
   // palette
   p=data+hdr->offset-(3*256);
   p=data+sizeof(_hdr);
   for (x=0;x<256;x++)
   {
    c =(*p)    ; p++;   // B
    c|=(*p)<< 8; p++;   // G
    c|=(*p)<<16; p++;   // R
         p++;   // A
    pal[x]=c;
   }
   // image
   xs=hdr->width;
   ys=hdr->height;
   p=data+hdr->offset;
   skip=(((hdr->bits*hdr->width)+31)>>5)<<2;  // compute scanline align
   skip-=hdr->width;
   for (y=0;y<ys;y++)
   {
    for (x=0;x<xs;x++,p++)
    {
     putpixel(x0+x,y0+ys-y-1,*p);
    }
    p+=skip;                       // handle align
   }
   y++;
  }
};
//---------------------------------------------------------------------------

    huge DetectSvga()
{
 return 2;
}

void main()
{
 clrscr();
 int gd=DETECT,gm,a;
 initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
 installuserdriver("svga256",&DetectSvga);
 BMP bmp;
 bmp.load("C:\\TURBOC3\\BIN\\Anand.BMP");
 bmp.draw(0,0);
 getch();
 closegraph();
}

Now,the above code is giving no errors but 2 warnings !!

WARNING :
1: for(x=0;x<256;x++) : "Functions containing for are not expanded inline"
2 : } , i.e, at the end of void load() function : "Functions containing some if statements are not expanded inline"

As a result image is not displaying in the output window
Output is displayed like this

I think y++; should be inside for (y=0;y<ys;y++){...} loop
So,please analyse the edited code...

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Suresh
  • 141
  • 5
  • 6
    Do yourself a huge favour and *stop* using TurboC++ *right now*. It's several decades out of date, doesn't support modern C++, it will teach you bad habits (like `void main()` which is simply *wrong*), you will have to re-learn almost all C++ you learn with it once you move into a real job or open source project. You are wasting your time trying to use it. – Jesper Juhl Mar 19 '19 at 16:54
  • 2
    As you are using Windows, you need to remind it not to feel free to add and remove characters it likes/dislikes from your files by adding the **binary** mode to the `open()` statement. – Mark Setchell Mar 19 '19 at 17:21
  • @MarkSetchell Even after adding **binary** mode to the open() statement I am getting the same output, so how to resolve it? – Suresh Mar 20 '19 at 04:28
  • @JesperJuhl So which **software** should I use? – Suresh Mar 20 '19 at 04:29
  • 1
    Consider using **CImg** instead. It is modern C++ and easy to use http://cimg.eu – Mark Setchell Mar 20 '19 at 09:20
  • 1
    @Suresh have you try to debug this? using breakpoints and tracing? is the palette read and set properly? are the pixels read with valid data? what happens if you do not change palette ? [IIRC the `outp(0x03c8,0);` should be inside the for loop too](https://stackoverflow.com/a/19642738/2521214) ... Is the bmp image compatible with the fileformat you are decoding (BMP has many formats some are compressed, others use different bpp etc ...) did you set 256 color mode or not? – Spektre Mar 20 '19 at 09:35
  • 1
    @Suresh here you got an alternative to BGI and BMP using VGA/VESA BIOS and 8bit PCX [How to read image file and display on screen in windows tasm dosbox](https://stackoverflow.com/a/45780565/2521214) also take a look at [Graphics rendering](https://stackoverflow.com/a/21699076/2521214) – Spektre Mar 20 '19 at 09:38
  • @Spektre I have uploaded Rama.bmp file in my post for better consideration; Also sharing its specifications here: **Dimensions** : 76 x 97 ; **Width** : 76 pixels ; **Height** : 97 pixels ; **Item Type** : BMP File ; **Bit Depth** : 24 ; **File Format** : Windows ; **Folder Path** : C:\TURBOC3\BIN ; **Size** : 21.6 KB ; kindly help me now to solve my issues – Suresh Mar 20 '19 at 13:31
  • 1
    @Suresh 24 bpp bmps do not have palette that is for 16 and 256 colors bmps ... also you read 1 BYTE per pixel from the BMP instead of 3 BYTES so its clear your bmp does not match your decoding routine try to convert the BMP into 256 colors one in Paint or what ever image SW you got ... Also IIRC the header is 128 BYTE not the size of your struct so you should seek to start of image data ... – Spektre Mar 20 '19 at 16:56
  • @Spektre Even after changing the bmp to 256 color BMP, image is not displaying in the Graphics window ! ; I think issue is present in displaying the palette through **PaletteData** pointer , i.e , here -> `for(i=0;i<256;i++) { File.read(ColorBytes,4); PaletteData[(int)(i*3+2)]=ColorBytes[0]>>2; PaletteData[(int)(i*3+0)]=ColorBytes[2]>>2; }` – Suresh Mar 21 '19 at 04:23

1 Answers1

2

Your decoding BMP code has a lot of problems... As I mentioned in my comments BMP is a mess with too many variations of format where you get lost very quickly so you need to have BMP format matching your decoding routine...

Yes you change BMP to 8bpp but still its format is different to yours slightly ...

Ok let use this image of yours (why to heck imgur is not supporting this???).

After a while of (de)coding I come up with this C++/VCL code that decodes your bmp properly:

//---------------------------------------------------------------------------
class BMP
    {
public:
    BYTE *data;
    DWORD size;
    #pragma pack(push,1)
    struct _hdr
        {
        char ID[2];
        DWORD size;
        WORD reserved1[2];  // ?
        DWORD offset;
        DWORD reserved2;    // ?
        DWORD width,height;
        WORD planes;
        WORD bits;
        DWORD compression;
        DWORD imagesize;
        DWORD xresolution,yresolution;
        DWORD ncolors;
        DWORD importantcolors;
        };
    #pragma pack(pop)
    BMP(){ data=NULL; free(); }
    ~BMP(){ free(); }
    void free(){ if (data) delete[] data; data=NULL; size=0;  }

    void load(AnsiString filename)                      // load BMP into memory
        {
        int hnd;
        free();
        hnd=FileOpen(filename,fmOpenRead);              // open file
        if (hnd<0) return;
        size=FileSeek(hnd,0,2);                         // seek to end of file to obtain filesize
             FileSeek(hnd,0,0);                         // seek to start of file
        data=new BYTE[size];                            // allocate memory space for the BMP
        if (data==NULL)                                 // not enough memory or empty file
            {
            size=0;
            FileClose(hnd);
            return;
            }
        FileRead(hnd,data,size);                        // load the data
        FileClose(hnd);
        }
    void draw(Graphics::TBitmap *bmp,int x0,int y0)     // decode/render bitmap onto VCL bitmap
        {
        _hdr *hdr=(_hdr*)data;
        int x,y,xs,ys,skip;
        DWORD pal[256],c;                               // palete to convert 8bpp -> 32bit VCL color
        BYTE *p;
        if (size<2) return;
        if (hdr->ID[0]!='B') return;                    // check magic number
        if (hdr->ID[1]!='M') return;
        if (hdr->planes!=1) return;                     // check format
        if (hdr->bits!=8) return;
        if (hdr->compression!=0) return;
        // palette
        p=data+hdr->offset-(3*256);
        p=data+sizeof(_hdr);
        for (x=0;x<256;x++)
            {
            c =(*p)    ; p++;   // B
            c|=(*p)<< 8; p++;   // G
            c|=(*p)<<16; p++;   // R
                         p++;   // A
            pal[x]=c;
            }
        // image
        xs=hdr->width;
        ys=hdr->height;
        p=data+hdr->offset;
        skip=(((hdr->bits*hdr->width)+31)>>5)<<2;       // compute scanline align
        skip-=hdr->width;
        for (y=0;y<ys;y++)
            {
            DWORD *q=(DWORD*)bmp->ScanLine[y0+ys-y-1];  // target VCL bitmap scanline pointer
            for (x=0;x<xs;x++,p++) q[x0+x]=pal[*p];     // copy pixels to target VCL bitmap
            p+=skip;                                    // handle align
            }
        y++;
        }
    };
//---------------------------------------------------------------------------

And usage:

BMP bmp;
bmp.load("Anand.bmp");
bmp.draw(target_VCL_bitmap,0,0);

Well as I do have different compiler (but also Borland/Embarcadero) and OS you need to ignore the VCL stuff and replace the rendering with your BGI ... Then change the AnsiString to char* and change the file access routines to your environment (do not forget it should be binary access but IIRC even that did not always work in TCPP had problems with it in past while loading textures into my 3D renderer some control codes where processed regardless of binary access...

Now what you have missing:

  1. header

    the header of BMP used is different than yours (there are a lot of variations out there that is why I suggested to use PCX instead). So take a look at mine _hdr struct and mimic yours ... The DWORD is unsigned 32 bit int, WORD is unsigned 16 bit int and BYTE is unsigned 8 bit int. I think that TCPP knows them but was ages i code in it so I might be wrong so if the case use relevant data types instead.

    You also do not check for the correct BMP format which is wrong and might lead to crashes so you should at least check the magic number and bpp, compression etc ... like I do

    Also do not forget to set the code alignment to 1 Byte (that is what the #pragma pack are for but not sure if TCPP support that. If not the align should be somewhere in the TCPP IDE settings probably in linker or compiler ...

  2. palette

    Your palette loading is suspicious I do not like it ... compare it with mine in the draw routine.

    Also your setting VGA palette routine is wrong see how it should be done. So the target color should be set for each color not just once for whole palette so you need move the out inside loop:

    for(i=0;i<256*3;)
       {
       outp(0x03c8,i/3);
       outp(0x03c9,PaletteData[i]); i++; // R
       outp(0x03c9,PaletteData[i]); i++; // G
       outp(0x03c9,PaletteData[i]); i++; // B
       }
    
  3. Image data

    you are not aligning the scan lines at all that is why your decoded image is shifted (skew like). According to Wiki each scan line is aligned to size:

    (((bits*width)+31)>>5)<<2
    

    So just skip unused BYTEs in the file after each row decoded.

    You also do not use offset which tells you where in the file the image data starts. That is important because the image data can be anywhere not just directly after palette as there might be more data present in the file like important colors etc ...

Also as you can see I loaded whole image into memory and decode from there. As you are in 16bit environment you might not want to do this as your OS might prevent you from allocating as much memory and also you are limited in memory size quite a lot... But I coded the whole stuff so I do not go back and forward so you should have no problems to port it to decoding directly from file like you have now ...

[Edit1]

here I dig some ancient example of file access from TCPP:

#include <stdio.h>
FILE *hnd;
BYTE data[256];
if ((hnd=fopen("texture.txr", "rb")) == NULL) return; // open file for read binary (not sure with the "b" check in build help)
fread(data,256,1,hnd); // read 256 of 1 BYTES into data array
fclose(hnd); // close file

just verify the usage with your inbuild help (CTRL+F1 while cursor is on a keyword there you will also see which include it needs if stdio is not the one) as I used this ~20 years ago and do not remember exactly... You will also need seek I think its called fseek and parameters are similar to mine FileSeek.

[Edit2] from your updated code its obvious you just copy paste code without thinking...

I managed to code this in TCPP+DOSBOX (ouch man that was pain in the ass as DOSBOX keyboard conflicts borland shortcuts ...)

You did not check the inbuild TCPP help and did not port the stuff correctly. For example yours fseek does not return file size like mine which you would detect right away if you try to debug (F8/F7) ... So here my new C++ (TCPP compatible) code for this:

//---------------------------------------------------------------------------
#include <stdio.h>
#include <conio.h>
//---------------------------------------------------------------------------
typedef unsigned long DWORD;
typedef unsigned int  WORD;
typedef unsigned char BYTE;
//---------------------------------------------------------------------------
char far* scr;              // VGA screen
const _sx= 320;             // physical screen size
const _sy= 200;
void gfxinit()
    {
    asm {   mov ax,19
        int 16
        }
    scr=(char far*)0xA0000000;
    }
void gfxexit()
    {
    asm {   mov ax,3
        int 16
        }
    }
void clrscr()
    {
    asm {   push    es
        mov ax,0xA000
        mov es,ax
        mov di,0x0000
        sub ax,ax
        mov cx,32000
        rep stosw
        pop es
        }
    }
void putpixel(int x,int y,char c)
    {
    unsigned int adr;
    if ((x<_sx)&&(x>=0))
     if ((y<_sy)&&(y>=0))
        {
        adr=x+(y*_sx);
        scr[adr]=c;
        }
    }
//---------------------------------------------------------------------------
class BMP
    {
public:
    BYTE *data;
    DWORD size;
    #pragma pack(push,1)
    struct _hdr
        {
        char ID[2];
        DWORD size;
        DWORD reserved1;  // ?
        DWORD offset;
        DWORD reserved2;  // ?
        DWORD width,height;
        WORD planes;
        WORD bits;
        DWORD compression;
        DWORD imagesize;
        DWORD xresolution,yresolution;
        DWORD ncolors;
        DWORD importantcolors;
        };
    #pragma pack(pop)
    BMP(){ data=NULL; free(); }
    ~BMP(){ free(); }
    void free(){ if (data) delete[] data; data=NULL; size=0;  }
    void load(char* filename);
    void draw(int x0,int y0);
    };
//---------------------------------------------------------------------------
void BMP::load(char* filename)
    {
    FILE *hnd;
    free();
    if ((hnd=fopen(filename, "rb")) == NULL) return; // open file for read binary (not sure with the "b" check in build help)
    _hdr hdr;
    hdr.ID[0]=0;
    hdr.ID[1]=0;
    hdr.size=0;
    fread(&hdr,sizeof(_hdr),1,hnd); // read BMP header into memory
    if (hdr.ID[0]=='B')
     if (hdr.ID[1]=='M')
      size=hdr.size;    // get file size
    fseek(hnd,0,0);     // seek back to start
    data=new BYTE[size];
    if (data==NULL)     // not enough memory or empty file
        {
        size=0;
        fclose(hnd);
        return;
        }
    fread(data,size,1,hnd); // read BMP into memory
    fclose(hnd);        // close file
    }
//---------------------------------------------------------------------------
void BMP::draw(int x0,int y0)
    {
    _hdr *hdr=(_hdr*)data;
    int x,y,xs,ys,skip;
    BYTE *p;
    if (size<2) return;
    if (hdr->ID[0]!='B') return;    // check magic number
    if (hdr->ID[1]!='M') return;
    if (hdr->planes!=1) return;     // check format
    if (hdr->bits!=8) return;
    if (hdr->compression!=0) return;
    // palette
    p=data+sizeof(_hdr);
    for (x=0;x<256;x++)
        {
        BYTE r,g,b;
        b=*p>>2; p++;
        g=*p>>2; p++;
        r=*p>>2; p++;
             p++;
        outp(0x3C8,x);
        outp(0x3C9,r);
        outp(0x3C9,g);
        outp(0x3C9,b);
        }
    // image
    xs=hdr->width;
    ys=hdr->height;
    p=data+hdr->offset;
    skip=(((hdr->bits*hdr->width)+31)>>5)<<2;  // compute scanline align
    skip-=hdr->width;
    for (y=0;y<ys;y++,p+=skip)
     for (x=0;x<xs;x++,p++)
      putpixel(x0+x,y0+ys-y-1,*p);
    }
//---------------------------------------------------------------------------
void main()
    {
    BMP bmp;
    bmp.load("C:\\Anand.BMP");
    gfxinit();
    clrscr();
    bmp.draw(0,16);
    // draw palette
    for (int x=0;x<256;x++)
     for (int y=0;y<8;y++)
      putpixel(x,y,x);
    getch();
    getch();
    getch();
    gfxexit();
    }
//---------------------------------------------------------------------------

I do not use BGI as I hate it instead I used direct memory access and VGA mode 13h but I code it so its similar to your BGI so you need to port that (remowing the gfxinit/exit and putpixel function bodies) if you want to use the BGI instead.

I placed the BMP directly into C:\ so I do not need to worry about exe local paths ... You did have a lot of bugs in there like discarted data for BMP storage, wrong palette code etc ... But the biggest bug you got was BYTE definition as yours was 16 bit instead of 8 bit messing up everything... The code above works for me with this output:

screenshot

As you can see I also render the palette for visual check an I got more getch() calls as the DOSBOX bugged keyboard (probably because of CPU Clock tics timing control) drive me crazy ...

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • What should be used for the header file of `FileOpen()` ? – Suresh Mar 21 '19 at 13:36
  • TCPP showing error :"Type qualifier `Graphics` must be a struct or class name" ; so how to resolve this? – Suresh Mar 21 '19 at 14:55
  • 1
    @Suresh read the text too all of this is mentioned there... 1. You need to use your file access routines as you have no access to the VCL ones no header will allow you those in 16 bit MS-DOS... 2. ignore the `Graphics::TBitmap` stuf use your `PutPixel` instead ... so instead of `q[x0+x]=pal[*p];` will be `PutPixel(x0+x,y0+ys-y-1,*p);` and there will be no `bmp` and no `q` pointers ... nor `ScanLine[]` ... so even the header will be `void draw(int x0,int y0)` – Spektre Mar 21 '19 at 18:02
  • Thanks for your valuable comment, `Graphics` issue solved but sorry to say I am not able to use my **file access routines** ; TCPP showing error : " Function 'FileOpen()` should have prototype " ; so how to fix it please explain in details ... Also what should be used in place of `DWORD *q=(DWORD*)bmp->ScanLine[y0+ys-y-1];` ? – Suresh Mar 22 '19 at 05:11
  • Can i use `open()` defined under `#include #include ` whose prototype is as follows: `int open(const char *path, int access [ , unsigned mode ] );` and defined as " **Open a file for reading or writing** " ? – Suresh Mar 22 '19 at 05:13
  • thanks `FileOpen()` issue solved ; but what should i use in place of `DWORD *q=(DWORD*)bmp->ScanLine[y0+ys-y-1];` ? TCPP showing **error** : "undefined symbol `bmp` " . – Suresh Mar 22 '19 at 12:53
  • Can I use `*p=getpixel(x0+x, y0+ys-y-1);` inside `for (x=0;xScanLine[y0+ys-y-1];` ? – Suresh Mar 22 '19 at 14:40
  • 1
    @Suresh that line `DWORD *q=(DWORD*)bmp->ScanLine[y0+ys-y-1];` will be gone (its just pointer to a scan line in my target VCL bmp but in your case you will have `y` position in `PutPixel` so you can delete that line completely (as I mentioned you should have no `bmp` and `q` in your code at all) the line `PutPixel(x0+x,y0+ys-y-1,*p);` inside the for loop covers it. So if you have undefined bmp symbol then you still forgot to get rid of it somewhere ... Why you want to use `getpixel` ? the `bmp->ScanLine[y][x]=color` is the same as your `PutPixel(x,y,color);` – Spektre Mar 22 '19 at 16:07
  • 1
    @Suresh The `q` just holds pointer to actually processed scanline so I do not need to call `bmp->ScanLine[y]` for each pixel as its very slow ... accessing own pointer `q[x]` is faster (about 1000-10000 times) – Spektre Mar 22 '19 at 16:13
  • Fine , looks good **No more Errors** , but image is not displayed in the output!! https://imgur.com/VPmqyHO is what output is displaying ; After the end of the `Class BMP` as suggested by you,I have used the following codes: ` huge DetectSvga() { return 2; } void main() { clrscr(); int gd=DETECT,gm,a; initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); installuserdriver("svga256",&DetectSvga); BMP bmp; bmp.load("C:\\TURBOC3\\BIN\\Anand.BMP"); bmp.draw(0,0); getch(); closegraph(); } ` – Suresh Mar 22 '19 at 16:51
  • Also at the time of compiling TCPP giving **2 Warnings** as follows: 1: `for(x=0;x<256;x++)` : "Functions containing `for` are not expanded inline" 2: `}` , i.e, at the end of `void load()` function : "Functions containing some if statements are not expanded inline" So, do I need to bother about it?? – Suresh Mar 22 '19 at 16:57
  • 1
    @Suresh debug then ... place a breakpoint ... and then when it jumps on it use F7/F8 to step/trace and watch the variables for what is wrong... is the file opening, loading data correctly, palette loading, setting ... etc. Also you are in DOS BOX and using SVGA not sure if that requires some additional configuration of DOSBOX but it need a special BGI driver. Try VGA 320x200x8bit instead that is standard VGA and should be working no matter what. but have no Idea how to force it in BGI. Can you post your new code as an edit in your question (just to look if there is not some obvious problem) – Spektre Mar 22 '19 at 17:15
  • 1
    @Suresh see **[edit2]** I manage to make it work in TCPP from your updated code – Spektre Mar 23 '19 at 10:34
  • 1
    Thanks a lot sir, I searched it for 1 years in internet but could not found the correct code or explanation ; but finally I post it in StackOverflow and due to your greatness today I got my answer; I am very happy, thank you so much StackExchange Team :) – Suresh Mar 23 '19 at 13:57
  • 1
    @Suresh glad to be of help ... as you are doing stuff in old MS-DOS and TCPP take a look at this: [PCGPE 1.0](https://www.pcorner.com/list/UPLOAD/PCGPE.ZIP/INFO/) there is also a winhelp port somwhere out there but my links to it are not working anymore so you need to find it on your own if you want to see it outside MS-DOS.... The **PCGPE** is comprehensive PC game programer tutorials covering 2D,3D graphics, effects, VGA/VESA, sound, HW (PIT DMA etc), and much much more so it is a must read/have stuf on MS-DOS.... – Spektre Mar 23 '19 at 14:02
  • 1
    @Suresh btw the `y++;` was outside the for loop just a leftower from debugging I needed non empty line doing something with y so I can place breakpoint there and check its contents without compiler optimizing it out... another obsolete leftover was `p=data+hdr->offset-(3*256);` and I think there where few more ... current code should be clean ... – Spektre Mar 23 '19 at 14:10