deepstone
diff src/wvga.c @ 21:00d84ab1ef26
switched to wacom
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 21 Sep 2013 18:17:55 +0300 |
parents | |
children | 17a5107b6fa4 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/wvga.c Sat Sep 21 18:17:55 2013 +0300 1.3 @@ -0,0 +1,91 @@ 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(®s, 0, sizeof regs); 1.23 + regs.eax = mode; 1.24 + dpmi_real_int(0x10, ®s); 1.25 + 1.26 + if(regs.eax == 0x100) { 1.27 + return -1; 1.28 + } 1.29 + 1.30 + if(mode != 3) { 1.31 + framebuffer = dpmi_mmap(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 +} 1.79 + 1.80 + 1.81 +void wait_vsync(void) 1.82 +{ 1.83 + __asm { 1.84 + mov dx, 0x3da 1.85 + l1: 1.86 + in al, dx 1.87 + and al, 0x8 1.88 + jnz l1 1.89 + l2: 1.90 + in al, dx 1.91 + and al, 0x8 1.92 + jz l2 1.93 + } 1.94 +}