3 GraphicsDevice::GraphicsDevice(void)
6 buffer = new unsigned char[64000];
9 // screen=(unsigned char *) MK_FP(0xa000, 0);
14 memset(buffer, 0, screen_size);
18 // no mem! Return error code!
19 printf("Out of mem!\n");
24 GraphicsDevice::~GraphicsDevice()
30 void GraphicsDevice::enter_mode13h(void)
37 int86(0x10, &in, &out);
43 int86(0x10, &in, &out);
54 void GraphicsDevice::leave_mode13h()
59 // change to the video mode we were in before we switched to mode 13h
62 int86(0x10, &in, &out);
71 void GraphicsDevice::drawPixel(int x, int y, unsigned char color)
73 if( x > screen_width || x < 0 || y > screen_height || y < 0 )
76 *(buffer + (y*screen_width) + x) = color;
79 //TODO fix bug when sprite is drawn on the right side of the screen
80 void GraphicsDevice::drawSprite(int x, int y, struct sprite * aSprite)
82 for(int i = 0; i< aSprite->height; i++)
84 for(int j = 0; j < aSprite->width; j++)
86 // if off-screen dont draw
87 if(!(x + j > screen_width || x + j < 0 || y + i > screen_height || y + i < 0)
88 && !(*(aSprite->bitmap + (i*aSprite->width) + j) == 0))
89 *(buffer + ( (y+i) * screen_width) + (x+j)) = *(aSprite->bitmap + (i*aSprite->width) + j);
94 void GraphicsDevice::drawHorizontalLine(int x, int y, unsigned int length, unsigned char color)
97 if( y < 0 || y > screen_height)
100 for(int i = 0; i < length; i++)
102 if( (x+ i) > screen_width)
105 *(buffer + (y * screen_width) + x + i) = color;
109 void GraphicsDevice::drawVerticalLine(int x, int y, unsigned int length, unsigned char color)
111 if( x < 0 || x > screen_width)
114 for(int i = 0; i < length; i++)
116 if(y+i > screen_height)
119 *(buffer + ( (y+i) * screen_width) + x) = color;
123 void GraphicsDevice::drawLine(int x1, int y1, int x2, int y2, unsigned char color)
128 void GraphicsDevice::drawRectangle(int x1, int y1, int x2, int y2, unsigned char color)
133 void GraphicsDevice::drawString8x8(int x, int y, char * aString)
137 void GraphicsDevice::drawString8x14(int x, int y, char * aString)
142 void GraphicsDevice::getPalette(char * palette)
146 /* get the palette */
147 outportb(0x3c7, 0); /* want to read */
148 for (int i = 0; i < 768; i++)
149 palette[i] = inportb(0x3c9);
154 // number should be a multiple of 3 and max is 768 or else it doesnt do anything
155 void GraphicsDevice::setPalette(char * palette, int number)
157 if(number % 3 != 0 || number < 0 || number > 768 || palette == NULL)
162 for (int i = 0; i < number; i++)
164 outportb(0x3c9, palette[i] /4); // divide by 4 because color needs to be between 0-63
169 void GraphicsDevice::clearScreen()
171 memset(buffer, 0, screen_size);
174 // with a defined color
175 void GraphicsDevice::clearScreen(char color)
177 memset(buffer, color, screen_size);
180 // draws the stuff on the screen
181 void GraphicsDevice::updateBuffer()
183 // wait for vertical re-trace
184 while ( inportb(INPUT_STATUS_0) & 8 )
186 while ( !(inportb(INPUT_STATUS_0) & 8) )
189 // copy everything to video memory
190 //_fmemcpy(screen, buffer, screen_size);
191 dosmemput(buffer, screen_size, SCREEN);
194 unsigned int GraphicsDevice::getScreenWidth(){ return screen_width; }
195 unsigned int GraphicsDevice::getScreenHeight(){ return screen_height; }