0

I'm right now programming a game for MS DOS using mode 13h of the VGA card. I'm using DJGPP as my compiler. The following problem is with my Display class. I've originally used _farpokeb() to copy my buffer (which is an array with the size of the entire screen) byte by byte to the VGA card's VRAM. But, since this is increibly slow (due to copying it bytewise and because _farpokeb() apparently is slow), I've decided to just copy the array to VRAM in one go. This does compile and run, but the screen just stays black. can somebody help me?

#include "Display.h"

Display::Display()
{
    backBuffer = new byte[screenHeight * screenWidth];
}

Display::~Display()
{
    delete[] backBuffer;
}

void Display::SwapBuffers()
{
    memcpy(VGA, backBuffer, screenWidth * screenHeight);
}

bool Display::IsVBlank()
{
    return ((inportb(0x3da) & 0x08) != 0);
}

void Display::SetVideoMode(byte mode) 
{
    __dpmi_regs r;

    r.x.ax = mode;
    __dpmi_int(0x10, &r);
}

void Display::SetPixel(int x, int y, byte color) 
{
    int address = y * 320 + x;
    if(address < 64000)
    {
        backBuffer[address] = color;
    }
}

void Display::ClearBackground()
{
    memset(backBuffer, 0x00, screenWidth * screenHeight);
}

void Display::DrawBitmap(int x, int y, byte bitmap[], int lines, int columns) 
{   
    for (int i = 0; i < lines*columns ; i++)
    {
        if (bitmap[i] != 0xff)
        {
            SetPixel(x + (i % columns), y + (i / columns), bitmap[i]);
        }
    }
}

void Display::FrameUpdate(Scene *scene)
{
    ClearBackground();

    for(Entity* e : scene->outlinerLayer0)
    {
        DrawBitmap(e->position.x, e->position.y, (byte*)e->sprite.texture[0], e->sprite.lines, e->sprite.columns);
    }

     for(Entity* e : scene->outlinerLayer1)
    {
        DrawBitmap(e->position.x, e->position.y, (byte*)e->sprite.texture[0], e->sprite.lines, e->sprite.columns);
    }

    for(Entity* e : scene->outlinerLayer2)
    {
        DrawBitmap(e->position.x, e->position.y, (byte*)e->sprite.texture[0], e->sprite.lines, e->sprite.columns);
    }

    for(Entity* e : scene->outlinerLayer3)
    {
        DrawBitmap(e->position.x, e->position.y, (byte*)e->sprite.texture[0], e->sprite.lines, e->sprite.columns);
    }

}
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Nkl29
  • 11
  • 2
  • Are you sure you're copying to the correct address? What is `VGA` set to? There isn't enough information here to help us help you, and there is a lot that we don't need. Try to cut this down into a minimum reproducible test case – Tim Randall Jul 19 '23 at 17:09
  • 0xA0000. As I said, when using _farpokeb() it works. – Nkl29 Jul 19 '23 at 17:16
  • I think that your minimal reproducible example is going to want to just copy 320x200 bytes to the address passed in. You should be able to switch directly between calls to two functions, with the same signature, and from there it ought to be easy to narrow down what the difference is – Tim Randall Jul 19 '23 at 18:43
  • Most likely, the problem is in translating between flat mode addresses and segment:offset addresses. In other words, your target address will be either 16 times larger or smaller depending on whether you're using `memcpy()` or `_farpokeb()` – Tim Randall Jul 19 '23 at 18:49

0 Answers0