dostunnel

annotate src/wvga.c @ 3:a8024271c662

added timer
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 16 Mar 2013 03:35:08 +0200
parents c525cfbfd4a2
children
rev   line source
nuclear@0 1 #include <stdio.h>
nuclear@0 2 #include <stdlib.h>
nuclear@0 3 #include <string.h>
nuclear@0 4 #include "wvga.h"
nuclear@0 5 #include "dpmi.h"
nuclear@0 6
nuclear@0 7 /* VGA DAC registers used for palette setting in 8bpp modes */
nuclear@0 8 #define VGA_DAC_STATE 0x3c7
nuclear@0 9 #define VGA_DAC_ADDR_RD 0x3c7
nuclear@0 10 #define VGA_DAC_ADDR_WR 0x3c8
nuclear@0 11 #define VGA_DAC_DATA 0x3c9
nuclear@0 12
nuclear@0 13 static void *framebuffer;
nuclear@0 14
nuclear@0 15 int set_video_mode(int mode)
nuclear@0 16 {
nuclear@0 17 struct dpmi_real_regs regs;
nuclear@0 18
nuclear@0 19 memset(&regs, 0, sizeof regs);
nuclear@0 20 regs.eax = mode;
nuclear@0 21 dpmi_real_int(0x10, &regs);
nuclear@0 22
nuclear@0 23 if(regs.eax == 0x100) {
nuclear@0 24 return -1;
nuclear@0 25 }
nuclear@0 26
nuclear@0 27 if(mode != 3) {
nuclear@3 28 framebuffer = dpmi_mmap(0xa0000, 64000);
nuclear@0 29 } else {
nuclear@0 30 dpmi_munmap((void*)0xa0000);
nuclear@0 31 }
nuclear@0 32 return 0;
nuclear@0 33 }
nuclear@0 34
nuclear@0 35 void set_palette(int idx, int *col, int count)
nuclear@0 36 {
nuclear@0 37 int i;
nuclear@0 38
nuclear@0 39 __asm {
nuclear@0 40 mov dx, VGA_DAC_ADDR_WR
nuclear@0 41 mov eax, idx
nuclear@0 42 out dx, al
nuclear@0 43 }
nuclear@0 44
nuclear@0 45 for(i=0; i<count; i++) {
nuclear@0 46 unsigned char r = *col++ >> 2;
nuclear@0 47 unsigned char g = *col++ >> 2;
nuclear@0 48 unsigned char b = *col++ >> 2;
nuclear@0 49
nuclear@0 50 __asm {
nuclear@0 51 mov dx, VGA_DAC_DATA
nuclear@0 52 mov al, r
nuclear@0 53 out dx, al
nuclear@0 54 mov al, g
nuclear@0 55 out dx, al
nuclear@0 56 mov al, b
nuclear@0 57 out dx, al
nuclear@0 58 }
nuclear@0 59 }
nuclear@0 60 }
nuclear@0 61
nuclear@0 62 void set_pal_entry(int idx, int r, int g, int b)
nuclear@0 63 {
nuclear@0 64 int color[3];
nuclear@0 65 color[0] = r;
nuclear@0 66 color[1] = g;
nuclear@0 67 color[2] = b;
nuclear@0 68
nuclear@0 69 set_palette(idx, color, 1);
nuclear@0 70 }
nuclear@0 71
nuclear@0 72 void copy_frame(void *pixels)
nuclear@0 73 {
nuclear@0 74 memcpy(framebuffer, pixels, 64000);
nuclear@0 75 }