dostunnel

diff src/wvga.c @ 0:c525cfbfd4a2

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 15 Mar 2013 16:46:41 +0200
parents
children a8024271c662
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/wvga.c	Fri Mar 15 16:46:41 2013 +0200
     1.3 @@ -0,0 +1,75 @@
     1.4 +#include <stdio.h>
     1.5 +#include <stdlib.h>
     1.6 +#include <string.h>
     1.7 +#include "wvga.h"
     1.8 +#include "dpmi.h"
     1.9 +
    1.10 +/* VGA DAC registers used for palette setting in 8bpp modes */
    1.11 +#define VGA_DAC_STATE		0x3c7
    1.12 +#define VGA_DAC_ADDR_RD		0x3c7
    1.13 +#define VGA_DAC_ADDR_WR		0x3c8
    1.14 +#define VGA_DAC_DATA		0x3c9
    1.15 +
    1.16 +static void *framebuffer;
    1.17 +
    1.18 +int set_video_mode(int mode)
    1.19 +{
    1.20 +	struct dpmi_real_regs regs;
    1.21 +
    1.22 +	memset(&regs, 0, sizeof regs);
    1.23 +	regs.eax = mode;
    1.24 +	dpmi_real_int(0x10, &regs);
    1.25 +
    1.26 +	if(regs.eax == 0x100) {
    1.27 +		return -1;
    1.28 +	}
    1.29 +
    1.30 +	if(mode != 3) {
    1.31 +		framebuffer = (void*)dpmi_mmap((void*)0xa0000, 64000);
    1.32 +	} else {
    1.33 +		dpmi_munmap((void*)0xa0000);
    1.34 +	}
    1.35 +	return 0;
    1.36 +}
    1.37 +
    1.38 +void set_palette(int idx, int *col, int count)
    1.39 +{
    1.40 +	int i;
    1.41 +
    1.42 +	__asm {
    1.43 +		mov dx, VGA_DAC_ADDR_WR
    1.44 +		mov eax, idx
    1.45 +		out dx, al
    1.46 +	}
    1.47 +
    1.48 +	for(i=0; i<count; i++) {
    1.49 +		unsigned char r = *col++ >> 2;
    1.50 +		unsigned char g = *col++ >> 2;
    1.51 +		unsigned char b = *col++ >> 2;
    1.52 +
    1.53 +		__asm {
    1.54 +			mov dx, VGA_DAC_DATA
    1.55 +			mov al, r
    1.56 +			out dx, al
    1.57 +			mov al, g
    1.58 +			out dx, al
    1.59 +			mov al, b
    1.60 +			out dx, al
    1.61 +		}
    1.62 +	}
    1.63 +}
    1.64 +
    1.65 +void set_pal_entry(int idx, int r, int g, int b)
    1.66 +{
    1.67 +	int color[3];
    1.68 +	color[0] = r;
    1.69 +	color[1] = g;
    1.70 +	color[2] = b;
    1.71 +
    1.72 +	set_palette(idx, color, 1);
    1.73 +}
    1.74 +
    1.75 +void copy_frame(void *pixels)
    1.76 +{
    1.77 +	memcpy(framebuffer, pixels, 64000);
    1.78 +}