deepstone

annotate src/wvga.c @ 30:a8d42276b5ad

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