#include "vga.h" #include "pc_stuff.h" #include #include #include #include #include int activePage = 0; byte *drawBuffer; byte *initializeDrawBuffer() { int i; drawBuffer = (byte *)malloc(VGA_DISPLAY_WIDTH * VGA_DISPLAY_HEIGHT); for (i = 0; i < VGA_DISPLAY_WIDTH * VGA_DISPLAY_HEIGHT; ++i) { drawBuffer[i] = 0; } return drawBuffer; } void copyDrawBufferToDisplay() { memcpy(VGA, drawBuffer, VGA_DISPLAY_WIDTH * VGA_DISPLAY_HEIGHT); } void freeDrawBuffer() { free(drawBuffer); } byte *getDrawBuffer() { return drawBuffer; } clock_t startTime, endTime; void buildSpriteFromSpritesheet( struct BMPImage *spritesheetImage, struct SpriteRender *spriteRender, int positionX, int positionY, int width, int height ) { spriteRender->data = spritesheetImage->memoryStart + positionY * spritesheetImage->width + positionX; spriteRender->modulo = spritesheetImage->width - width; spriteRender->width = width; spriteRender->height = height; spriteRender->transparentColor = spritesheetImage->transparentColor; } void drawPixel(int x, int y, int color) { drawBuffer[y * VGA_DISPLAY_WIDTH + x] = color; } void drawSprite(struct SpriteRender* sprite) { int x, y; byte pixel; int modulo = VGA_DISPLAY_WIDTH - sprite->width; byte* spriteData = sprite->data; byte* drawBufferPos = drawBuffer + sprite->x - sprite->offsetX + ( (sprite->y - sprite->offsetY) * VGA_DISPLAY_WIDTH ); for (y = 0; y < sprite->height; ++y) { for (x = 0; x < sprite->width; ++x) { pixel = *(spriteData++); if (pixel != sprite->transparentColor) { *(drawBufferPos) = pixel; } drawBufferPos++; } drawBufferPos += modulo; spriteData += sprite->modulo; } } void getSpriteBounds(struct SpriteRender *sprite, struct SpriteBounds *bounds) { bounds->top = sprite->y - sprite->offsetY; bounds->bottom = bounds->top + sprite->height; bounds->left = sprite->x - sprite->offsetX; bounds->right = bounds->left + sprite->width; } void setVGAColors(struct VGAColor colors[], int totalColors) { int i; outp(0x3c8,0); for (i = 0; i < totalColors; ++i) { outp(0x3c9, colors[i].red); outp(0x3c9, colors[i].green); outp(0x3c9, colors[i].blue); } }