deepstone

view src/wvga.c @ 32:7c8402e27b7c

renamed Makefile.dos to Makefile
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 22 Sep 2013 18:37:46 +0300
parents
children 17a5107b6fa4
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "wvga.h"
5 #include "dpmi.h"
7 /* VGA DAC registers used for palette setting in 8bpp modes */
8 #define VGA_DAC_STATE 0x3c7
9 #define VGA_DAC_ADDR_RD 0x3c7
10 #define VGA_DAC_ADDR_WR 0x3c8
11 #define VGA_DAC_DATA 0x3c9
13 static void *framebuffer;
15 int set_video_mode(int mode)
16 {
17 struct dpmi_real_regs regs;
19 memset(&regs, 0, sizeof regs);
20 regs.eax = mode;
21 dpmi_real_int(0x10, &regs);
23 if(regs.eax == 0x100) {
24 return -1;
25 }
27 if(mode != 3) {
28 framebuffer = dpmi_mmap(0xa0000, 64000);
29 } else {
30 dpmi_munmap((void*)0xa0000);
31 }
32 return 0;
33 }
35 void set_palette(int idx, int *col, int count)
36 {
37 int i;
39 __asm {
40 mov dx, VGA_DAC_ADDR_WR
41 mov eax, idx
42 out dx, al
43 }
45 for(i=0; i<count; i++) {
46 unsigned char r = *col++ >> 2;
47 unsigned char g = *col++ >> 2;
48 unsigned char b = *col++ >> 2;
50 __asm {
51 mov dx, VGA_DAC_DATA
52 mov al, r
53 out dx, al
54 mov al, g
55 out dx, al
56 mov al, b
57 out dx, al
58 }
59 }
60 }
62 void set_pal_entry(int idx, int r, int g, int b)
63 {
64 int color[3];
65 color[0] = r;
66 color[1] = g;
67 color[2] = b;
69 set_palette(idx, color, 1);
70 }
72 void copy_frame(void *pixels)
73 {
74 memcpy(framebuffer, pixels, 64000);
75 }
78 void wait_vsync(void)
79 {
80 __asm {
81 mov dx, 0x3da
82 l1:
83 in al, dx
84 and al, 0x8
85 jnz l1
86 l2:
87 in al, dx
88 and al, 0x8
89 jz l2
90 }
91 }