Commit aa4e3713 authored by Steven Fuller's avatar Steven Fuller

Merged id_in and id_vl into one file (since input and video tend to go hand

in hand with libraries, also place for startup initialization etc)
parent 0c6a347e
CC = gcc
CFLAGS = -O6 -fomit-frame-pointer -ffast-math -funroll-loops -mpentiumpro -mcpu=pentiumpro -march=pentiumpro
#CFLAGS = -O6 -fomit-frame-pointer -ffast-math -funroll-loops -mpentiumpro -mcpu=pentiumpro -march=pentiumpro
#CFLAGS = -g -Wall -pedantic
#CFLAGS = -g
OBJS = objs.o misc.o id_ca.o id_in.o id_sd.o id_vl.o id_vh.o id_us.o \
CFLAGS = -g
#CFLAGS = -Os
OBJS = objs.o misc.o id_ca.o id_sd.o id_vh.o id_us.o vi_svga.o \
wl_scale.o wl_draw.o wl_act1.o wl_act2.o wl_agent.o wl_game.o \
wl_inter.o wl_menu.o wl_play.o wl_state.o wl_text.o wl_main.o \
wl_debug.o
......
......@@ -62,7 +62,6 @@ metaname like sc_Left etc or something
update once per frame or such.. hm
and where is that greenpixel coming from (when using end game with largest
window size)
* merge id_vl.c and id_in.c to get id_svga.c
* change id_sd to sd_oss, sd_win, sd_dos, sd_oal, etc
idea is that different <outputs> can share some drivers, unlike video
* check filehandling (ex, file missing, bad file type, and such)
......
......@@ -27,6 +27,7 @@
#define O_BINARY 0
#endif
int WolfMain(int argc, char *argv[]);
/* ------------------------------------------------------------------------ */
......@@ -80,10 +81,10 @@ typedef struct
#define nil ((void *)0)
#include "vi_comm.h"
#include "id_ca.h"
#include "id_vl.h"
#include "id_vh.h"
#include "id_in.h"
#include "id_sd.h"
#include "id_us.h"
......
/* id_vl.c */
#include "id_heads.h"
boolean screenfaded;
byte palette1[256][3], palette2[256][3];
byte *gfxbuf = NULL;
void VL_WaitVBL(int vbls)
{
vga_waitretrace();
}
void VW_UpdateScreen()
{
memcpy(graph_mem, gfxbuf, 64000);
}
/*
=======================
=
= VL_Startup
=
=======================
*/
void VL_Startup (void)
{
if (gfxbuf == NULL)
gfxbuf = malloc(320 * 200 * 1);
vga_init();
vga_setmode(G320x200x256);
}
/*
=======================
=
= VL_Shutdown
=
=======================
*/
void VL_Shutdown (void)
{
if (gfxbuf != NULL) {
free(gfxbuf);
gfxbuf = NULL;
}
vga_setmode(TEXT);
}
//===========================================================================
/*
=================
=
= VL_ClearVideo
=
= Fill the entire video buffer with a given color
=
=================
*/
void VL_ClearVideo(byte color)
{
memset(gfxbuf, color, 64000);
}
/*
=============================================================================
PALETTE OPS
To avoid snow, do a WaitVBL BEFORE calling these
=============================================================================
*/
/*
=================
=
= VL_FillPalette
=
=================
*/
void VL_FillPalette(int red, int green, int blue)
{
int i;
for (i = 0; i < 256; i++)
vga_setpalette(i, red, green, blue);
}
//===========================================================================
/*
=================
=
= VL_SetColor
=
=================
*/
void VL_SetColor(int color, int red, int green, int blue)
{
vga_setpalette(color, red, green, blue);
}
//===========================================================================
/*
=================
=
= VL_GetColor
=
=================
*/
void VL_GetColor(int color, int *red, int *green, int *blue)
{
vga_getpalette(color, red, green, blue);
}
//===========================================================================
/*
=================
=
= VL_SetPalette
=
=================
*/
void VL_SetPalette(byte *palette)
{
int i;
for (i = 0; i < 256; i++)
vga_setpalette(i, palette[i*3+0], palette[i*3+1], palette[i*3+2]);
}
//===========================================================================
/*
=================
=
= VL_GetPalette
=
=================
*/
void VL_GetPalette(byte *palette)
{
int i, r, g, b;
for (i = 0; i < 256; i++) {
vga_getpalette(i, &r, &g, &b);
palette[i*3+0] = r;
palette[i*3+1] = g;
palette[i*3+2] = b;
}
}
//===========================================================================
/*
=================
=
= VL_FadeOut
=
= Fades the current palette to the given color in the given number of steps
=
=================
*/
void VL_FadeOut(int start, int end, int red, int green, int blue, int steps)
{
int i,j,orig,delta;
byte *origptr, *newptr;
VL_WaitVBL(1);
VL_GetPalette (&palette1[0][0]);
memcpy (palette2,palette1,768);
//
// fade through intermediate frames
//
for (i=0;i<steps;i++)
{
origptr = &palette1[start][0];
newptr = &palette2[start][0];
for (j=start;j<=end;j++)
{
orig = *origptr++;
delta = red-orig;
*newptr++ = orig + delta * i / steps;
orig = *origptr++;
delta = green-orig;
*newptr++ = orig + delta * i / steps;
orig = *origptr++;
delta = blue-orig;
*newptr++ = orig + delta * i / steps;
}
VL_WaitVBL(1);
VL_SetPalette (&palette2[0][0]);
}
//
// final color
//
VL_FillPalette (red,green,blue);
screenfaded = true;
}
/*
=================
=
= VL_FadeIn
=
=================
*/
void VL_FadeIn(int start, int end, byte *palette, int steps)
{
int i,j,delta;
VL_WaitVBL(1);
VL_GetPalette (&palette1[0][0]);
memcpy (&palette2[0][0],&palette1[0][0],sizeof(palette1));
start *= 3;
end = end*3+2;
//
// fade through intermediate frames
//
for (i=0;i<steps;i++)
{
for (j=start;j<=end;j++)
{
delta = palette[j]-palette1[0][j];
palette2[0][j] = palette1[0][j] + delta * i / steps;
}
VL_WaitVBL(1);
VL_SetPalette (&palette2[0][0]);
}
//
// final color
//
VL_SetPalette (palette);
screenfaded = false;
}
/*
==================
=
= VL_ColorBorder
=
==================
*/
void VL_ColorBorder (int color)
{
}
/*
=============================================================================
PIXEL OPS
=============================================================================
*/
byte pixmasks[4] = {1,2,4,8};
byte leftmasks[4] = {15,14,12,8};
byte rightmasks[4] = {1,3,7,15};
/*
=================
=
= VL_Plot
=
=================
*/
void VL_Plot(int x, int y, int color)
{
*(gfxbuf + 320 * y + x) = color;
}
/*
=================
=
= VL_Hlin
=
=================
*/
void VL_Hlin(unsigned x, unsigned y, unsigned width, unsigned color)
{
memset(gfxbuf + 320 * y + x, color, width);
}
/*
=================
=
= VL_Vlin
=
=================
*/
void VL_Vlin (int x, int y, int height, int color)
{
byte *ptr = gfxbuf + 320 * y + x;
while (height--) {
*ptr = color;
ptr += 320;
}
}
/*
=================
=
= VL_Bar
=
=================
*/
void VL_Bar(int x, int y, int width, int height, int color)
{
byte *ptr = gfxbuf + 320 * y + x;
while (height--) {
memset(ptr, color, width);
ptr += 320;
}
}
/*
============================================================================
MEMORY OPS
============================================================================
*/
/*
=================
=
= VL_MemToScreen
=
= Draws a block of data to the screen.
=
=================
*/
void VL_MemToScreen(byte *source, int width, int height, int x, int y)
{
byte *ptr = gfxbuf + 320 * y + x;
while(height--) {
memcpy(ptr, source, width);
source += width;
ptr += 320;
}
}
void VL_DeModeXize(byte *buf, int width, int height)
{
byte *mem, *ptr, *destline;
int plane, x, y;
if (width & 3) {
printf("Not divisible by 4?\n");
return;
}
mem = malloc(width * height);
ptr = buf;
for (plane = 0; plane < 4; plane++) {
destline = mem;
for (y = 0; y < height; y++) {
for (x = 0; x < width / 4; x++)
*(destline + x*4 + plane) = *ptr++;
destline += width;
}
}
memcpy(buf, mem, width * height);
free(mem);
}
#ifndef __ID_VL_H__
#define __ID_VL_H__
//===========================================================================
extern byte *gfxbuf;
extern boolean screenfaded;
//===========================================================================
void VL_Startup (void);
void VL_Shutdown (void);
void VL_ClearVideo (byte color);
void VL_WaitVBL (int vbls);
void VW_UpdateScreen();
void VL_FillPalette(int red, int green, int blue);
void VL_SetColor(int color, int red, int green, int blue);
void VL_GetColor(int color, int *red, int *green, int *blue);
void VL_SetPalette(byte *palette);
void VL_GetPalette(byte *palette);
void VL_FadeOut(int start, int end, int red, int green, int blue, int steps);
void VL_FadeIn(int start, int end, byte *palette, int steps);
void VL_ColorBorder (int color);
void VL_Plot(int x, int y, int color);
void VL_Hlin(unsigned x, unsigned y, unsigned width, unsigned color);
void VL_Vlin(int x, int y, int height, int color);
void VL_Bar(int x, int y, int width, int height, int color);
void VL_MemToLatch(byte *source, int width, int height, word dest);
void VL_MemToScreen(byte *source, int width, int height, int x, int y);
void VL_DeModeXize(byte *buf, int width, int height);
#else
#error "fix me: TODO"
#endif
#ifndef __ID_IN_H__
#define __ID_IN_H__
#ifndef __VI_SVGA_H__
#define __VI_SVGA_H__
//===========================================================================
extern byte *gfxbuf;
extern boolean screenfaded;
//===========================================================================
void VL_Startup (void);
void VL_Shutdown (void);
void VL_ClearVideo (byte color);
void VL_WaitVBL (int vbls);
void VW_UpdateScreen();
void VL_FillPalette(int red, int green, int blue);
void VL_SetColor(int color, int red, int green, int blue);
void VL_GetColor(int color, int *red, int *green, int *blue);
void VL_SetPalette(byte *palette);
void VL_GetPalette(byte *palette);
void VL_FadeOut(int start, int end, int red, int green, int blue, int steps);
void VL_FadeIn(int start, int end, byte *palette, int steps);
void VL_ColorBorder (int color);
void VL_Plot(int x, int y, int color);
void VL_Hlin(unsigned x, unsigned y, unsigned width, unsigned color);
void VL_Vlin(int x, int y, int height, int color);
void VL_Bar(int x, int y, int width, int height, int color);
void VL_MemToLatch(byte *source, int width, int height, word dest);
void VL_MemToScreen(byte *source, int width, int height, int x, int y);
void VL_DeModeXize(byte *buf, int width, int height);
#define MaxPlayers 4
#define MaxJoys 2
......
/* id_in.c */
/* id_vl.c */
#include "id_heads.h"
boolean screenfaded;
byte palette1[256][3], palette2[256][3];
byte *gfxbuf = NULL;
void VL_WaitVBL(int vbls)
{
vga_waitretrace();
}
void VW_UpdateScreen()
{
memcpy(graph_mem, gfxbuf, 64000);
}
/*
=======================
=
= VL_Startup
=
=======================
*/
void VL_Startup (void)
{
if (gfxbuf == NULL)
gfxbuf = malloc(320 * 200 * 1);
vga_init(); /* TODO: maybe move into main or such? */
vga_setmode(G320x200x256);
}
/*
=======================
=
= VL_Shutdown
=
=======================
*/
void VL_Shutdown (void)
{
if (gfxbuf != NULL) {
free(gfxbuf);
gfxbuf = NULL;
}
vga_setmode(TEXT);
}
//===========================================================================
/*
=================
=
= VL_ClearVideo
=
= Fill the entire video buffer with a given color
=
=================
*/
void VL_ClearVideo(byte color)
{
memset(gfxbuf, color, 64000);
}
/*
=============================================================================
PALETTE OPS
To avoid snow, do a WaitVBL BEFORE calling these
=============================================================================
*/
/*
=================
=
= VL_FillPalette
=
=================
*/
void VL_FillPalette(int red, int green, int blue)
{
int i;
for (i = 0; i < 256; i++)
vga_setpalette(i, red, green, blue);
}
//===========================================================================
/*
=================
=
= VL_SetColor
=
=================
*/
void VL_SetColor(int color, int red, int green, int blue)
{
vga_setpalette(color, red, green, blue);
}
//===========================================================================
/*
=================
=
= VL_GetColor
=
=================
*/
void VL_GetColor(int color, int *red, int *green, int *blue)
{
vga_getpalette(color, red, green, blue);
}
//===========================================================================
/*
=================
=
= VL_SetPalette
=
=================
*/
void VL_SetPalette(byte *palette)
{
int i;
for (i = 0; i < 256; i++)
vga_setpalette(i, palette[i*3+0], palette[i*3+1], palette[i*3+2]);
}
//===========================================================================
/*
=================
=
= VL_GetPalette
=
=================
*/
void VL_GetPalette(byte *palette)
{
int i, r, g, b;
for (i = 0; i < 256; i++) {
vga_getpalette(i, &r, &g, &b);
palette[i*3+0] = r;
palette[i*3+1] = g;
palette[i*3+2] = b;
}
}
//===========================================================================
/*
=================
=
= VL_FadeOut
=
= Fades the current palette to the given color in the given number of steps
=
=================
*/
void VL_FadeOut(int start, int end, int red, int green, int blue, int steps)
{
int i,j,orig,delta;
byte *origptr, *newptr;
VL_WaitVBL(1);
VL_GetPalette (&palette1[0][0]);
memcpy (palette2,palette1,768);
//
// fade through intermediate frames
//
for (i=0;i<steps;i++)
{
origptr = &palette1[start][0];
newptr = &palette2[start][0];
for (j=start;j<=end;j++)
{
orig = *origptr++;
delta = red-orig;
*newptr++ = orig + delta * i / steps;
orig = *origptr++;
delta = green-orig;
*newptr++ = orig + delta * i / steps;
orig = *origptr++;
delta = blue-orig;
*newptr++ = orig + delta * i / steps;
}
VL_WaitVBL(1);
VL_SetPalette (&palette2[0][0]);
}
//
// final color
//
VL_FillPalette (red,green,blue);
screenfaded = true;
}
/*
=================
=
= VL_FadeIn
=
=================
*/
void VL_FadeIn(int start, int end, byte *palette, int steps)
{
int i,j,delta;
VL_WaitVBL(1);
VL_GetPalette (&palette1[0][0]);
memcpy (&palette2[0][0],&palette1[0][0],sizeof(palette1));
start *= 3;
end = end*3+2;
//
// fade through intermediate frames
//
for (i=0;i<steps;i++)
{
for (j=start;j<=end;j++)
{
delta = palette[j]-palette1[0][j];
palette2[0][j] = palette1[0][j] + delta * i / steps;
}
VL_WaitVBL(1);
VL_SetPalette (&palette2[0][0]);
}
//
// final color
//
VL_SetPalette (palette);
screenfaded = false;
}
/*
==================
=
= VL_ColorBorder
=
==================
*/
void VL_ColorBorder (int color)
{
}
/*
=============================================================================
PIXEL OPS
=============================================================================
*/
byte pixmasks[4] = {1,2,4,8};
byte leftmasks[4] = {15,14,12,8};
byte rightmasks[4] = {1,3,7,15};
/*
=================
=
= VL_Plot
=
=================
*/
void VL_Plot(int x, int y, int color)
{
*(gfxbuf + 320 * y + x) = color;
}
/*
=================
=
= VL_Hlin
=
=================
*/
void VL_Hlin(unsigned x, unsigned y, unsigned width, unsigned color)
{
memset(gfxbuf + 320 * y + x, color, width);
}
/*
=================
=
= VL_Vlin
=
=================
*/
void VL_Vlin (int x, int y, int height, int color)
{
byte *ptr = gfxbuf + 320 * y + x;
while (height--) {
*ptr = color;
ptr += 320;
}
}
/*
=================
=
= VL_Bar
=
=================
*/
void VL_Bar(int x, int y, int width, int height, int color)
{
byte *ptr = gfxbuf + 320 * y + x;
while (height--) {
memset(ptr, color, width);
ptr += 320;
}
}
/*
============================================================================
MEMORY OPS
============================================================================
*/
/*
=================
=
= VL_MemToScreen
=
= Draws a block of data to the screen.
=
=================
*/
void VL_MemToScreen(byte *source, int width, int height, int x, int y)
{
byte *ptr = gfxbuf + 320 * y + x;
while(height--) {
memcpy(ptr, source, width);
source += width;
ptr += 320;
}
}
void VL_DeModeXize(byte *buf, int width, int height)
{
byte *mem, *ptr, *destline;
int plane, x, y;
if (width & 3) {
printf("Not divisible by 4?\n");
return;
}
mem = malloc(width * height);
ptr = buf;
for (plane = 0; plane < 4; plane++) {
destline = mem;
for (y = 0; y < height; y++) {
for (x = 0; x < width / 4; x++)
*(destline + x*4 + plane) = *ptr++;
destline += width;
}
}
memcpy(buf, mem, width * height);
free(mem);
}
/*
=============================================================================
......@@ -612,3 +1009,8 @@ byte IN_JoyButtons (void)
{
return 0;
}
int main(int argc, char *argv[])
{
return WolfMain(argc, argv);
}
......@@ -1325,9 +1325,3 @@ int WolfMain(int argc, char *argv[])
return 0;
}
int main(int argc, char *argv[])
{
return WolfMain(argc, argv);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment