⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dos_drvr.c

📁 小型游戏引擎
💻 C
📖 第 1 页 / 共 2 页
字号:
// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman// Ken Silverman's official web site: "http://www.advsys.net/ken"// See the included license file "BUILDLIC.TXT" for license info.// This file has been modified from Ken Silverman's original release// (Actually, most of it was moved here from original BUILD source.)#ifndef PLATFORM_DOS#error Please do not compile this if PLATFORM_DOS is not defined.#endif// !!! check these includes against original engine.c !!!#include <string.h>#include <malloc.h>#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include "pragmas.h"#include <io.h>#include <conio.h>#include <i86.h>#include <dos.h>#include "platform.h"#include "display.h"#include "build.h"#include "cache1d.h"#include "ves2.h"#include "engine.h"static unsigned char tempbuf[MAXWALLS];extern long transarea;extern long totalarea;extern long beforedrawrooms;extern long stereowidth, stereopixelwidth, ostereopixelwidth;extern volatile long stereomode, visualpage, activepage, whiteband, blackband;extern volatile char oa1, o3c2, ortca, ortcb, overtbits, laststereoint;extern char pow2char[8];extern long pow2long[32];extern char kensmessage[128];static short capturecount = 0;static char screenalloctype = 255;static char pcxheader[128] ={        0xa,0x5,0x1,0x8,0x0,0x0,0x0,0x0,0x3f,0x1,0xc7,0x0,        0x40,0x1,0xc8,0x0,0x0,0x0,0x0,0x8,0x8,0x8,0x10,0x10,        0x10,0x18,0x18,0x18,0x20,0x20,0x20,0x28,0x28,0x28,0x30,0x30,        0x30,0x38,0x38,0x38,0x40,0x40,0x40,0x48,0x48,0x48,0x50,0x50,        0x50,0x58,0x58,0x58,0x60,0x60,0x60,0x68,0x68,0x68,0x70,0x70,        0x70,0x78,0x78,0x78,0x0,0x1,0x40,0x1,0x0,0x0,0x0,0x0,        0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,        0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,        0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,        0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,        0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,};static char vgapal16[48] ={        00,00,00,00,00,42,00,42,00,00,42,42,42,00,00,42,00,42,42,21,00,42,42,42,        21,21,21,21,21,63,21,63,21,21,63,63,63,21,21,63,21,63,63,63,21,63,63,63,};static void (__interrupt __far *oldtimerhandler)(void);static void (__interrupt __far *oldkeyhandler)(void);extern long setvlinebpl(long);#pragma aux setvlinebpl parm [eax];void *kkmalloc(size_t size);#pragma aux kkmalloc =\        "call kmalloc",\        parm [eax]\void kkfree(void *buffer);#pragma aux kkfree =\        "call kfree",\        parm [eax]\unsigned char _readlastkeyhit(void){    return(kinp(0x60));} // _readlastkeyhitvoid _uninitengine(void){	long i;	if (vidoption == 1) uninitvesa();	if (stereomode) setstereo(0L);	if (screen != NULL)	{		if (screenalloctype == 0) kkfree((void *)screen);		//if (screenalloctype == 1) suckcache(screen);  //Cache already gone		screen = NULL;	}	for(i=0;i<MAXPALOOKUPS;i++)		if (palookup[i] != NULL) { kkfree(palookup[i]); palookup[i] = NULL; }}long readpixel16(long p){	long mask, dat;	mask = pow2long[(p&7)^7];	if ((qsetmode == 480) && (ydim16 <= 336) && (p >= 640*336))		p -= 640*336;	else		p += pageoffset;	p >>= 3;	koutp(0x3ce,0x4);	koutp(0x3cf,0); dat = ((readpixel(p+0xa0000)&mask)>0);	koutp(0x3cf,1); dat += (((readpixel(p+0xa0000)&mask)>0)<<1);	koutp(0x3cf,2); dat += (((readpixel(p+0xa0000)&mask)>0)<<2);	koutp(0x3cf,3); dat += (((readpixel(p+0xa0000)&mask)>0)<<3);	return(dat);}int screencapture(char *filename, char inverseit){	char *ptr;	long fil, i, bufplc, p, col, ncol, leng, numbytes, xres;	filename[4] = ((capturecount/1000)%10)+48;	filename[5] = ((capturecount/100)%10)+48;	filename[6] = ((capturecount/10)%10)+48;	filename[7] = (capturecount%10)+48;	if ((fil=open(filename,O_BINARY|O_CREAT|O_TRUNC|O_WRONLY,S_IWRITE))==-1)		return(-1);	if (qsetmode == 200)	{		pcxheader[8] = ((xdim-1)&255); pcxheader[9] = (((xdim-1)>>8)&255);		pcxheader[10] = ((ydim-1)&255); pcxheader[11] = (((ydim-1)>>8)&255);		pcxheader[12] = (xdim&255); pcxheader[13] = ((xdim>>8)&255);		pcxheader[14] = (ydim&255); pcxheader[15] = ((ydim>>8)&255);		pcxheader[66] = (xdim&255); pcxheader[67] = ((xdim>>8)&255);	}	else	{		pcxheader[8] = ((640-1)&255); pcxheader[9] = (((640-1)>>8)&255);		pcxheader[10] = ((qsetmode-1)&255); pcxheader[11] = (((qsetmode-1)>>8)&255);		pcxheader[12] = (640&255); pcxheader[13] = ((640>>8)&255);		pcxheader[14] = (qsetmode&255); pcxheader[15] = ((qsetmode>>8)&255);		pcxheader[66] = (640&255); pcxheader[67] = ((640>>8)&255);	}	write(fil,&pcxheader[0],128);	if (qsetmode == 200)	{		ptr = (char *)frameplace;		numbytes = xdim*ydim;		xres = xdim;	}	else	{		numbytes = (mul5(qsetmode)<<7);		xres = 640;	}	bufplc = 0; p = 0;	while (p < numbytes)	{		koutp(97,kinp(97)|3);		if (qsetmode == 200) { col = *ptr; p++; ptr++; }		else		{			col = readpixel16(p);			p++;			if ((inverseit == 1) && (((col&7) == 0) || ((col&7) == 7))) col ^= 15;		}		leng = 1;		if (qsetmode == 200) ncol = *ptr;		else		{			ncol = readpixel16(p);			if ((inverseit == 1) && (((ncol&7) == 0) || ((ncol&7) == 7))) ncol ^= 15;		}		while ((ncol == col) && (p < numbytes) && (leng < 63) && ((p%xres) != 0))		{			leng++;			if (qsetmode == 200) { p++; ptr++; ncol = *ptr; }			else			{				p++;				ncol = readpixel16(p);				if ((inverseit == 1) && (((ncol&7) == 0) || ((ncol&7) == 7))) ncol ^= 15;			}		}		koutp(97,kinp(97)&252);		if ((leng > 1) || (col >= 0xc0))		{			tempbuf[bufplc++] = (leng|0xc0);			if (bufplc == 4096) { bufplc = 0; if (write(fil,&tempbuf[0],4096) < 4096) { close(fil); return(-1); } }		}		tempbuf[bufplc++] = col;		if (bufplc == 4096) { bufplc = 0; if (write(fil,&tempbuf[0],4096) < 4096) { close(fil); return(-1); } }	}	tempbuf[bufplc++] = 0xc;	if (bufplc == 4096) { bufplc = 0; if (write(fil,&tempbuf[0],4096) < 4096) { close(fil); return(-1); } }	if (qsetmode == 200)	{		VBE_getPalette(0,256,&tempbuf[4096]);		for(i=0;i<256;i++)		{			tempbuf[bufplc++] = (tempbuf[(i<<2)+4096+2]<<2);			if (bufplc == 4096) { bufplc = 0; if (write(fil,&tempbuf[0],4096) < 4096) { close(fil); return(-1); } }			tempbuf[bufplc++] = (tempbuf[(i<<2)+4096+1]<<2);			if (bufplc == 4096) { bufplc = 0; if (write(fil,&tempbuf[0],4096) < 4096) { close(fil); return(-1); } }			tempbuf[bufplc++] = (tempbuf[(i<<2)+4096+0]<<2);			if (bufplc == 4096) { bufplc = 0; if (write(fil,&tempbuf[0],4096) < 4096) { close(fil); return(-1); } }		}	}	else	{		for(i=0;i<768;i++)		{			if (i < 48)				tempbuf[bufplc++] = (vgapal16[i]<<2);			else				tempbuf[bufplc++] = 0;			if (bufplc == 4096) { bufplc = 0; if (write(fil,&tempbuf[0],4096) < 4096) { close(fil); return(-1); } }		}	}	if (bufplc > 0)		if (write(fil,&tempbuf[0],bufplc) < bufplc) { close(fil); return(-1); }	close(fil);	capturecount++;	return(0);}void printscreeninterrupt(void){	int5();}void drawline16(long x1, long y1, long x2, long y2, char col){	long i, dx, dy, p, pinc, d;	char lmask, rmask;	dx = x2-x1; dy = y2-y1;	if (dx >= 0)	{		if ((x1 > 639) || (x2 < 0)) return;		if (x1 < 0) { if (dy) y1 += scale(0-x1,dy,dx); x1 = 0; }		if (x2 > 639) { if (dy) y2 += scale(639-x2,dy,dx); x2 = 639; }	}	else	{		if ((x2 > 639) || (x1 < 0)) return;		if (x2 < 0) { if (dy) y2 += scale(0-x2,dy,dx); x2 = 0; }		if (x1 > 639) { if (dy) y1 += scale(639-x1,dy,dx); x1 = 639; }	}	if (dy >= 0)	{		if ((y1 >= ydim16) || (y2 < 0)) return;		if (y1 < 0) { if (dx) x1 += scale(0-y1,dx,dy); y1 = 0; }		if (y2 >= ydim16) { if (dx) x2 += scale(ydim16-1-y2,dx,dy); y2 = ydim16-1; }	}	else	{		if ((y2 >= ydim16) || (y1 < 0)) return;		if (y2 < 0) { if (dx) x2 += scale(0-y2,dx,dy); y2 = 0; }		if (y1 >= ydim16) { if (dx) x1 += scale(ydim16-1-y1,dx,dy); y1 = ydim16-1; }	}	setcolor16((long)col);	if (x1 == x2)	{		if (y2 < y1) i = y1, y1 = y2, y2 = i;		koutpw(0x3ce,0x8+(256<<((x1&7)^7)));  //bit mask		vlin16((((mul5(y1)<<7)+x1+pageoffset)>>3)+0xa0000,y2-y1+1);		return;	}	if (y1 == y2)	{		if (x2 < x1) i = x1, x1 = x2, x2 = i;		lmask = (0x00ff>>(x1&7));		rmask = (0xff80>>(x2&7));		p = (((mul5(y1)<<7)+x1+pageoffset)>>3)+0xa0000;		dx = (x2>>3)-(x1>>3);		if (dx == 0)		{			koutpw(0x3ce,0x8+((lmask&rmask)<<8)); drawpixel(p,readpixel(p));			return;		}		dx--;		koutpw(0x3ce,0x8+(lmask<<8)); drawpixel(p,readpixel(p)); p++;		if (dx > 0) { koutp(0x3cf,0xff); clearbufbyte((void *)p,dx,0L); p += dx; }		koutp(0x3cf,rmask); drawpixel(p,readpixel(p));		return;	}	dx = klabs(x2-x1)+1; dy = klabs(y2-y1)+1;	if (dx >= dy)	{		if (x2 < x1)		{			i = x1; x1 = x2; x2 = i;			i = y1; y1 = y2; y2 = i;		}		p = (mul5(y1)<<7)+x1+pageoffset;		d = 0;		if (y2 > y1) pinc = 640; else pinc = -640;		for(i=dx;i>0;i--)		{			drawpixel16(p);			d += dy;			if (d >= dx) { d -= dx; p += pinc; }			p++;		}		return;	}	if (y2 < y1)	{		i = x1; x1 = x2; x2 = i;		i = y1; y1 = y2; y2 = i;	}	p = (mul5(y1)<<7)+x1+pageoffset;	d = 0;	if (x2 > x1) pinc = 1; else pinc = -1;	for(i=dy;i>0;i--)	{		drawpixel16(p);		d += dx;		if (d >= dy) { d -= dy; p += pinc; }		p += 640;	}}void qsetmode640350(void){	if (qsetmode != 350)	{		stereomode = 0;		setvmode(0x10);		pageoffset = 0;		ydim16 = 350;		koutpw(0x3d4,0xc+((pageoffset>>11)<<8));		koutpw(0x3ce,0x0f00);  //set/reset		koutpw(0x3ce,0x0f01);  //enable set/reset		fillscreen16(0L,0L,640L*350L);	}	qsetmode = 350;}void qsetmode640480(void){	short i;	if (qsetmode != 480)	{		stereomode = 0;		setvmode(0x12);		i = 479-144;		koutpw(0x3d4,0x18+((i&255)<<8));             //line compare		koutp(0x3d4,0x7); koutp(0x3d5,(kinp(0x3d5)&239)|((i&256)>>4));		koutp(0x3d4,0x9); koutp(0x3d5,(kinp(0x3d5)&191)|((i&512)>>3));		pageoffset = 92160;		koutpw(0x3d4,0xc+((pageoffset>>11)<<8));		koutpw(0x3ce,0x0f00);  //set/reset		koutpw(0x3ce,0x0f01);  //enable set/reset		fillscreen16(0L,8L,640L*144L);		fillscreen16((640L*144L)>>3,0L,640L*336L);		pageoffset = 92160; ydim16 = 336;	}	qsetmode = 480;}void printext16(long xpos, long ypos, short col, short backcol, char name[82], char fontsize){	long p, z, zz, charxsiz, daxpos;	char ch, dat, mask, *fontptr;	daxpos = xpos;	koutp(0x3ce,0x5); koutp(0x3cf,(kinp(0x3cf)&(255-3))+2);	koutp(0x3ce,0x8);	if (fontsize == 1)	{		fontptr = smalltextfont;		charxsiz = 4;	}	else	{		fontptr = textfont;		charxsiz = 8;	}	z = 0;	while (name[z] != 0)	{		ch = name[z];		z++;		mask = pow2char[8-(daxpos&7)]-1;		p = ypos*80 + (daxpos>>3)+0xa0000;   //Do not make ylookup!		if ((daxpos&7) == 0)		{			for(zz=0;zz<8;zz++)			{				if (backcol >= 0)				{					koutp(0x3cf,0xff);					if (charxsiz == 4) koutp(0x3cf,0x7c);					readpixel(p), drawpixel(p,(long)backcol);				}				koutp(0x3cf,fontptr[(((long)ch)<<3)+zz]);				if (charxsiz == 4) koutp(0x3cf,0x7c&fontptr[(((long)ch)<<3)+zz]);				readpixel(p), drawpixel(p,col);				p += 80;			}		}		else		{			for(zz=0;zz<8;zz++)			{				if (backcol >= 0)				{					if (charxsiz == 8)					{						koutp(0x3cf,mask);						readpixel(p), drawpixel(p,backcol);						koutp(0x3cf,~mask);						readpixel(p+1), drawpixel(p+1,backcol);					}					else					{						koutp(0x3cf,0x7c>>(daxpos&7));						readpixel(p), drawpixel(p,backcol);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -