using memset() functions for graphics
I'm pretty new to programming, so I've been reading like, almost every HOWTO on C++.
I'm tring to run a program that uses the memset() function. It compiles fine, but during runtime, i get the ever-notorious "Segementation fault(core dumped)" error - which i've googled and read a million reasons why that error occurs. Usually due to accessing memory that hasn't yet been initialized.
the program sets up MCGA mode, sets up a function to set the screen a certain color, and sets up a funtion to put a pixel on the screen.
i put a small Main() function at the bottom to test out the functions.
#include <iostream>
#include <stdlib.h>
#include <cstring>
char vga[0xffff];
void setMCGA() {
asm("mov $0x13, %ax");
asm("int $0x10");
}
void screenSet(int color) { //int color is a number between 0 and 255
memset(vga, color, 0xffff);//0xffff = 64000
}
void pixelPut (int x, int y, unsigned char color) {
memset(vga-x-(y*320), color, 1);
}
int main() {
setMCGA();
screenSet(200);
pixelPut(300, 200, 0);
return 0;
}
I somehow think that my runtime error is due to my lack of knowledge on the memset() function. I've looked up usage for it, and I believe I'm doing this right, but apparently not.
Does anyone know??
thanks
giuseppe
|