#include #include #define VIDEO_SEGMENT 0XA0000000 #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 200 // 64k palette index 0xA0000000-0xA000FFFF (upper left to lower right) char far *vram = MK_FP(0xA000, 0x0000); unsigned char car_sprite[] = {21, 0, 6, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 4, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 4, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 0 }; unsigned char ball_sprite[] = {5, 0, 5, 0, /* width 5, height 5 */ 0, 11, 11, 11, 0, 11, 14, 3, 3, 9, 11, 3, 3, 3, 9, 11, 3, 3, 3, 9, 0, 9, 9, 9, 0 }; /* INT 10h, Service 0h Set Screen Mode Input: AH = 0h AL = Mode Number (see below) Output: The video mode is changed. Mode Number Text Res. Graphics Res. Description Adapters Max. Pages --------------------------------------------------------------------------- 0h 40x25 ------ B&W Text CGA+ 8 1h 80x25 ------ B&W Text MDPA+ 8 2h 40x25 ------ Color Text CGA+ 4 or 8 3h 80x25 ------ Color Text (MDPA?)/CGA+ 4 or 8 4h 40x25 320x200 4 colors CGA+ 1 5h 40x25 320x200 2 colors CGA+ 1 6h 80x25 640x200 2 colors CGA+ 1 7h 80x25 ------ B&W MDPA (CGA+?) 1 8h to Ch -- PCjr or other adapters; no longer used Dh 40x25 320x200 16 colors EGA+ 8 Eh 80x25 640x200 16 colors EGA+ 4 Fh 80x25 640x350 2 colors EGA+ 2 10h 80x25 640x350 16 colors EGA+ 2 11h 80x25 640x480 2 colors VGA+ 1 12h 80x25 640x480 16 colors VGA+ 1 13h 40x25 320x200 256 colors VGA+ 1 */ void r_mode(int mode) { union REGS in_reg, out_reg; struct SREGS segreg; segread(&segreg); in_reg.h.ah = (unsigned char)0x0; in_reg.h.al = (unsigned char)mode; int86x(0x10, &in_reg, &out_reg, &segreg); } void PutPixel (int x, int y, unsigned char color) { pokeb (VIDEO_SEGMENT, (y * SCREEN_WIDTH) + x, color); } unsigned char ReadPixel (int x, int y) { return peekb(VIDEO_SEGMENT, (y * SCREEN_WIDTH) + x); } void PutSprite (int x, int y, unsigned char sprite[]) { int x_count, y_count; int width, height; /* Extract the width from the first two bytes of the array, and the height from the third and fourth bytes of the array: */ width = sprite[0] + (sprite[1] << 8); height = sprite[2] + (sprite[3] << 8); /* Loop through the rows: */ for (y_count = 0; y_count <= height - 1; y_count++) /* Loop through the columns: */ for (x_count = 0; x_count <= width - 1; x_count++) PutPixel (x + x_count, y + y_count, sprite[4 + (y_count * width) + x_count]); } void clear(unsigned char color) { unsigned int i; int x = 0; int y = 0; for(i = 0; i < 0xFFFF; i++) { vram[(y * SCREEN_WIDTH) + x++] = color; if (x >= 320) { y++; x = 0; } } } // mouse cursors made with 2L8 Cursor editor // downloaded from http://ftp.gnome.org/mirror/archive/ftp.sunet.se/pub/simtelnet/msdos/mouse/ int POINT[32] = { 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff, 0x00ff, 0x007f, 0x003f, 0x003f, 0x01ff, 0x10ff, 0x30ff, 0xf87f, 0xf87f, 0xfc7f, 0x0000, 0x4000, 0x6000, 0x7000, 0x7800, 0x7c00, 0x7e00, 0x7f00, 0x7f80, 0x7c00, 0x6c00, 0x4600, 0x0600, 0x0300, 0x0300, 0x0000 }; short Mouse_Init (void) { union REGS in_reg, out_reg; struct SREGS segreg; segread(&segreg); in_reg.x.ax = (unsigned char)0x0; int86x(0x33, &in_reg, &out_reg, &segreg); // return # of mouse buttons (-1 if no mouse) return out_reg.x.bx; } void Mouse_Show (void) { union REGS in_reg, out_reg; struct SREGS segreg; segread(&segreg); in_reg.x.ax = (unsigned char)0x1; int86x(0x33, &in_reg, &out_reg, &segreg); } void Mouse_Hide (void) { union REGS in_reg, out_reg; struct SREGS segreg; segread(&segreg); in_reg.x.ax = (unsigned char)0x2; int86x(0x33, &in_reg, &out_reg, &segreg); } void Mouse_Status( int *x, int *y, int *b ) { union REGS in_reg, out_reg; struct SREGS segreg; segread(&segreg); in_reg.x.ax = 0x3; in_reg.x.bx = 0; in_reg.x.cx = 0; in_reg.x.dx = 0; int86x(0x33, &in_reg, &out_reg, &segreg); *b = out_reg.x.bx; *x = out_reg.x.cx; *y = out_reg.x.dx; } void Mouse_Cursor(int *shape, int x, int y) { union REGS inreg, outreg; struct SREGS s; inreg.x.ax = 0x9; inreg.x.bx = x; inreg.x.cx = y; inreg.x.dx = (unsigned)shape; segread(&s); s.es = s.ds; int86x(0x33,&inreg,&outreg,&s); } void main(void) { int x = 0; int y = 0; int j = 0; printf("Entering mode 13\n"); delay(500); r_mode(0x13); x = 0; y = 0; Mouse_Init(); Mouse_Show(); Mouse_Cursor(POINT, 0, 0); clear(0); while (j < 60 * 10) { j++; PutSprite(50 + x, 100 + x, car_sprite); PutSprite(150 + y, 100 + 2*y, ball_sprite); x++; y++; delay(15); clear(0); } r_mode(0x3); printf("Exiting mode 13\n"); delay(500); }