/ Published in: C

Provides the basics for mode 13h
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <go32.h> #include <dpmi.h> #include <pc.h> #include <sys/movedata.h> #include <sys/farptr.h> static inline void vgamode(int n){ __dpmi_regs r; r.x.ax=n; __dpmi_int(0x10,&r); } /* switch to mode 13h when program starts */ __attribute__((constructor)) void grafixinit(){ vgamode(0x13); } /* switch back to mode 3 and kill sound when program exits */ __attribute__((destructor)) void grafixend(){ vgamode(3); nosound(); } static inline void vsync(){ /* wait until any previous retrace has ended */ do{}while(inportb(0x3DA) & 8); /* wait until a new retrace has just begun */ do{}while(!(inportb(0x3DA) & 8)); } /* sets a color 0..255 in the palette with rgb values 0,,63 */ static inline void setcolor(const unsigned char n,const unsigned char r,const unsigned char g,const unsigned char b){ outportb(0x3C8,n); outportb(0x3C9,r); outportb(0x3C9,g); outportb(0x3C9,b); } /* set pixel */ static inline void pset(const unsigned x,const unsigned y,const unsigned char color){ if(x<320&&y<200) _farpokeb(_dos_ds, 0xA0000+x+((y<<8)+(y<<6)), color); } /* sets 2 pixels at once, color is 2 bytes */ static inline void psetw(const unsigned x,const unsigned y,const unsigned short color){ if(x<319&&y<200) _farpokew(_dos_ds, 0xA0000+x+((y<<8)+(y<<6)), color); } /* sets 4 pixels at once, color is 4 bytes */ static inline void psetl(const unsigned x,const unsigned y,const unsigned long color){ if(x<317&&y<200) _farpokel(_dos_ds, 0xA0000+x+((y<<8)+(y<<6)), color); }
Comments
