Posted By

Zufolek on 05/20/09


Tagged

vga djgpp


Versions (?)

vga mode 13h for djgpp


 / Published in: C
 

Provides the basics for mode 13h

  1. #include <go32.h>
  2. #include <dpmi.h>
  3. #include <pc.h>
  4. #include <sys/movedata.h>
  5. #include <sys/farptr.h>
  6.  
  7.  
  8.  
  9. static inline void vgamode(int n){
  10. __dpmi_regs r;
  11. r.x.ax=n;
  12. __dpmi_int(0x10,&r);
  13. }
  14.  
  15.  
  16. /* switch to mode 13h when program starts */
  17. __attribute__((constructor))
  18. void grafixinit(){
  19. vgamode(0x13);
  20. }
  21.  
  22.  
  23. /* switch back to mode 3 and kill sound when program exits */
  24. __attribute__((destructor))
  25. void grafixend(){
  26. vgamode(3);
  27. nosound();
  28. }
  29.  
  30.  
  31. static inline void vsync(){
  32. /* wait until any previous retrace has ended */
  33. do{}while(inportb(0x3DA) & 8);
  34.  
  35. /* wait until a new retrace has just begun */
  36. do{}while(!(inportb(0x3DA) & 8));
  37. }
  38.  
  39.  
  40. /* sets a color 0..255 in the palette with rgb values 0,,63 */
  41. static inline void setcolor(const unsigned char n,const unsigned char r,const unsigned char g,const unsigned char b){
  42. outportb(0x3C8,n);
  43. outportb(0x3C9,r);
  44. outportb(0x3C9,g);
  45. outportb(0x3C9,b);
  46. }
  47.  
  48.  
  49. /* set pixel */
  50. static inline void pset(const unsigned x,const unsigned y,const unsigned char color){
  51. if(x<320&&y<200)
  52. _farpokeb(_dos_ds, 0xA0000+x+((y<<8)+(y<<6)), color);
  53. }
  54.  
  55.  
  56. /* sets 2 pixels at once, color is 2 bytes */
  57. static inline void psetw(const unsigned x,const unsigned y,const unsigned short color){
  58. if(x<319&&y<200)
  59. _farpokew(_dos_ds, 0xA0000+x+((y<<8)+(y<<6)), color);
  60. }
  61.  
  62.  
  63. /* sets 4 pixels at once, color is 4 bytes */
  64. static inline void psetl(const unsigned x,const unsigned y,const unsigned long color){
  65. if(x<317&&y<200)
  66. _farpokel(_dos_ds, 0xA0000+x+((y<<8)+(y<<6)), color);
  67. }

Report this snippet  

You need to login to post a comment.