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

📄 vidfunc.cpp

📁 这个是延伸mame的在wince平台下的游戏模拟器的代码
💻 CPP
字号:
/* PocketCultMAME - MAME Emulator for PocketPC
   (c) Copyright 2006 Manuel Castrillo Mart韓ez

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
#include <windows.h>

#include "vidsys.h"
#include "vidfunc.h"

#include "font.cpp"
#include "resource.h"

extern "C"{
	extern VidSysInfo VideoInfo;
}

extern HINSTANCE g_hInstance;

unsigned short *ptrFont8 = NULL;
unsigned short *ptrFont16 = NULL;


void blitBitmap( unsigned short *source, int longx, int longy, int posx, int posy )
{

	unsigned short *dest;

	dest = ((unsigned short *)VideoInfo.pBitmap) + ( posx * ( VideoInfo.xIncrementation ) ) + ( posy * ( VideoInfo.yIncrementation ) );

	for( int yloop = 0; yloop < longy; yloop++ )
	{
		for( int xloop = 0; xloop < longx; xloop++ )
		{
			dest[ xloop * ( VideoInfo.xIncrementation ) ] = *source++;
		}
		dest = dest + VideoInfo.yIncrementation;
	}

}



void blitBMP( unsigned short *source, int posx, int posy )
{

	unsigned int longx, longy;

	// Get the size of the bitmap and skip the header
	longx = *(source + 2);
	longy = (unsigned int)(0xFFFF - (*(source + 4)));
	source += 34;

	// blit the bitmap
	blitBitmap( source, longx, longy, posx, posy );

}



void print(int x, int y, char *pchStr, int VGAFont )
{

	int iLen, iIdx, charSizex, charSizey;
	unsigned short *ptrFont;
	unsigned char *ptrFontCharSize;

	// Using VGA fonts?
	if( VideoInfo.displayVGA && VGAFont )
	{
		if( ptrFont16 == NULL )
		{
			ptrFont16 = GetPtrToResourceBitmap( IDB_Font_HI );
			ptrFont16 +=34;
		}
		ptrFont = ptrFont16;
		ptrFontCharSize = &sFontCharSize16[0];
		charSizex = 16;
		charSizey = 17;
	}
	else	// QVGA fonts
	{
		if( ptrFont8 == NULL )
		{
			ptrFont8 = GetPtrToResourceBitmap( IDB_Font );
			ptrFont8 +=34;
		}
		ptrFont = ptrFont8;
		ptrFontCharSize = &sFontCharSize8[0];
		charSizex = 8;
		charSizey = 11;
	}

	// print stuff
	iLen = strlen(pchStr); // number of characters to process
	for (int n = 0; n < iLen; n++) {
		iIdx = (int)pchStr[n]; // get the ASCII value
		if ((iIdx < 32) || (iIdx > 0x7d)) { // limit it to the range of chars in the font
			iIdx = 32;
		}
		iIdx -= 32; // zero base the index

		// print the character
		blitBitmap( ptrFont + ((charSizex*charSizey) * iIdx), charSizex, charSizey, x, y); 

		// increment x pos by the size of the character
		x+=ptrFontCharSize[iIdx];

	 }
}



// Calculates the text size in pixels

int printSize(char *pchStr, int VGAFont )
{

	int iLen, iIdx;
	unsigned char *ptrFontCharSize;

	int size = 0;

	// Using VGA fonts?
	if( VideoInfo.displayVGA && VGAFont )
		ptrFontCharSize = &sFontCharSize16[0];
	else	// QVGA fonts
		ptrFontCharSize = &sFontCharSize8[0];

	// print stuff
	iLen = strlen(pchStr); // number of characters to process
	for (int n = 0; n < iLen; n++) {
		iIdx = (int)pchStr[n]; // get the ASCII value
		if ((iIdx < 32) || (iIdx > 0x7d)) { // limit it to the range of chars in the font
			iIdx = 32;
		}
		iIdx -= 32; // zero base the index

		// increment x pos by the size of the character
		size+=ptrFontCharSize[iIdx];
	}

	return(size);
}



// Calculates the proportional position of a point using 240x320 as reference
void porportionalPosition( int &x, int &y )
{
	x = int((x * VideoInfo.xPixelsResolution) / 240);
	y = int((y * VideoInfo.yPixelsResolution) / 320);
}



// Rotates a point from 0 rotation to specified rotation
void rotateFrom0( int pointRotation, int &x, int &y )
{
	int tempx = x;

	switch( pointRotation )
	{
		case ROTATION_0 :
			x = x;
			y = y;
			break;

		case ROTATION_CW90 :
			x = VideoInfo.xPixelsResolution - y;	// X resolution in landscape mode is Y in portrait!
			y = tempx;
			break;

		case ROTATION_ACW90 :
			x = y;
			y = VideoInfo.yPixelsResolution - tempx;
			break;
	}
}

void cls(void)
{
	unsigned short *dest;
	dest = (unsigned short *)VideoInfo.pOrigin;

	for( int t = 0; t < VideoInfo.xPixelsResolution*VideoInfo.yPixelsResolution ; t++ )
    {
		*dest++= 0xFFFF;
    }

}

void HalfTone( int lines )
{

	unsigned short r, g, b;
    unsigned short *screenptr;

	screenptr = (unsigned short *)VideoInfo.pBitmap;

	for( int y = 0; y < lines; y++ )
	{
		for( int x = 0; x <= VideoInfo.xPixelsResolution; x++ )
		{
    		r = (screenptr[x] & 0xF800 ) >> 1;
    		g = (screenptr[x] & 0x7E0) >> 1;
    		b = (screenptr[x] & 0x1F) >> 1;
    		screenptr[x] = ( (r&0xF800) | (g&0x7E0) | b );
		}
		screenptr = screenptr + VideoInfo.yIncrementation;
	}

}


unsigned short * GetPtrToResourceBitmap( unsigned short ResourceName )
{

    HRSRC hResInfo;
    HGLOBAL hResource;
    
    unsigned short *BitmapPtr;

    hResInfo = FindResource(g_hInstance, MAKEINTRESOURCE( ResourceName ), RT_BITMAP);
    hResource = LoadResource(g_hInstance, hResInfo);
    BitmapPtr = ( unsigned short * )LockResource(hResource);
    
    return( BitmapPtr );
    
}

⌨️ 快捷键说明

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