dostunnel

view src/wvga.c @ 2:a52d0b786ce1

added files
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 15 Mar 2013 19:55:29 +0200
parents
children a8024271c662
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 = (void*)dpmi_mmap((void*)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 }