hi guys
i've written an bare OS and now im trying to go a little furthur and create a very simple GUI for it .
but i have no idea how to create such a thing .
my os is running in text_mode though i can change to some other mode but it will couse some problems as i've written nearly all the nessecary libraries of c myself (couse i didn't have them for direct developing ) and by doing this it will be no longer possible to write characters on the screen . i got to write a VGA driver then .
anyway ... i found a tutorial and did some of thigs to create a bitmap based simple gui :
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
unsigned char *dbl_buffer;
unsigned char *VGA = (unsigned char *)0xA0000000L;
typedef struct tagBITMAP /* the structure for a bitmap. */
{
unsigned int width;
unsigned int height;
unsigned char *data;
} BITMAP;
BITMAP BITMAP1;
typedef struct tagRECT
{
long x1;
long y1;
long x2;
long y2;
} RECT;
void init_dbl_buffer(void)
{
dbl_buffer = (unsigned char *) malloc (640 * 480);
if (dbl_buffer == NULL)
{
printf("Not enough memory for double buffer.\n");
getchar();
/*exit(1);*/
return;
}
}
void update_screen(void)
{
#ifdef VERTICAL_RETRACE
while ((inportb(0x3DA) & 0x08));
while (!(inportb(0x3DA) & 0x08));
#endif
memcpy(VGA, dbl_buffer, (unsigned int)(640 * 480));
}
void setpixel (BITMAP *bmp, int x, int y, unsigned char color)
{
bmp->data[y * bmp->width + x];
}
/* Draws a filled in rectangle IN A BITMAP. To fill a full bitmap call as
drawrect (&bmp, 0, 0, bmp.width, bmp.height, color); */
void drawrect(BITMAP *bmp, unsigned short x, unsigned short y,
unsigned short x2, unsigned short y2,
unsigned char color)
{
unsigned short tx, ty, screen_offset = 1, bitmap_offset = 1;
for (ty = y; ty < bmp->height; ty++)
{
memcpy(&dbl_buffer[screen_offset], &bmp->data[bitmap_offset], bmp->width);
bitmap_offset += bmp->width;
screen_offset += 640;
}
}
int main()
{
unsigned char key;
do
{
key = 0;
if (getch()) key = getch();
/* You must clear the double buffer every time to avoid evil messes
(go ahead and try without this, you will see) */
memset (&dbl_buffer, 0, 640 * 480);
/* DRAW ALL BITMAPS AND DO GUI CODE HERE */
/* Draws the double buffer */
update_screen();
} while (key != 27); /* keep going until escape */
}
now i wanna know how should i show some bitmaps on the screen ? how to add them ?
thanks ,