📄 bmp.c
字号:
/**==========================================================================\
*** BMP.C - Demo program to show all colors & patterns on all modes
*** Copyright (c) 1997, 2001 Epson Research and Development, Inc.
*** All rights reserved.
\*==========================================================================*/
#include <fcntl.h>
#include <io.h>
#include <math.h>
#include <malloc.h>
#if !defined(__GNUC__)
#pragma warning(disable:4032) // disable warning: formal parameter 1 has different type when promoted
#include <conio.h>
#elif !defined(strcmpi)
#define strcmpi stricmp
#endif
#if defined(__GNUC__) && defined(INTEL_DOS)
#include <conio.h>
#include <unistd.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "hal.h"
#include "BMP.h"
#include "appcfg.h"
/*-------------------------------------------------external functions------*/
/* Rotate90 Mode bit has moved in the 13506, so define a value so we don't have to */
/* search and replace again */
#define ROTATE90_MODE_BIT 0x40
/*
** The following definitions are for CalcDisplaySurfaceCombination()
*/
enum
{
SURFACE_NONE = -1,
SURFACE_LCD0_CRTTV1 = 0,
SURFACE_LCD0,
SURFACE_CRTTV0,
SURFACE_LCDCRTTV0,
MAX_SURFACE_COMBINATIONS
};
/*-------------------------------------------------external functions------*/
static const char Revision[] = "BMP.C=$Revision: 19 $";
/*----------------------------------------------------------variables------*/
/* ======= global variables ======== */
BYTE ImgBuf[2048];
int gbInitRegisters;
int gbImgCompress;
unsigned nBitsPerPixel[MAX_DISP_SURFACE];
unsigned SurfaceDisplayMode[MAX_DISP_SURFACE];
int LcdOrientation;
int DisplaySurfaceCombination;
int Orientation[MAX_DISP_SURFACE];
static int VerboseMode = FALSE;
int NumberOfSurfaces;
int CommonMemoryBlockForAllDisplays;
int ActiveSurfaceNumber;
char *filename[MAX_DISP_SURFACE];
int BmpCount;
/* ======== static variables ======== */
const char szVersion[] = "2.06";
/* ======== static functions ======== */
void PrintUsage(void);
unsigned Show13506(char *fname);
void CheckBpp(unsigned bpp);
void GetBMPInfo(char *fname, unsigned *width, unsigned*height, unsigned *BitsPerPixel);
unsigned ShowBMP(char *fname, unsigned DstX, unsigned DstY);
void seLineBlt( BYTE far *pImgBuf, unsigned ImgWidth, unsigned DstX, unsigned Y, unsigned VirtualWidth, unsigned PhysicalWidth, unsigned Bpp );
unsigned ShowCompressed( int ff, unsigned DstX, unsigned DstY, unsigned ImgH, unsigned ImgW, unsigned VirtualW, unsigned VirtualH, unsigned PhysicalWidth, unsigned Bpp );
unsigned ShowUncompressed( int ff, unsigned DstX, unsigned DstY, unsigned ImgH, unsigned ImgW, unsigned VirtualW, unsigned VirtualH, unsigned PhysicalWidth, unsigned Bpp );
void Translate( BYTE far *pImgBuf, unsigned LineWidth, unsigned Bpp );
void DisplaySurfaceHelp(void);
/*=========================================================main()=========*/
void DisplayBlank(BOOL activate)
{
switch (seReadRegByte(REG_DISPLAY_MODE) & 0x07)
{
default:
case LCD:
seDisplayLcdBlank(activate);
break;
case CRT:
seDisplayCrtBlank(activate);
break;
case TV:
case TV | CRT:
seDisplayTvBlank(activate);
break;
case LCD | CRT:
seDisplayLcdBlank(activate);
seDisplayCrtBlank(activate);
break;
case LCD | TV:
case LCD | TV | CRT:
seDisplayLcdBlank(activate);
seDisplayTvBlank(activate);
break;
}
}
/*-------------------------------------------------------------------------*/
void WriteLut(unsigned surface, BYTE *pLut, int count)
{
unsigned regDisplayMode;
regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);
switch (CalcDisplaySurfaceCombination())
{
case SURFACE_NONE:
break;
case SURFACE_LCD0:
if (surface == 0)
seWriteLcdLut(pLut, count);
break;
case SURFACE_CRTTV0:
if (surface == 0)
{
if (regDisplayMode & TV)
seWriteTvLut(pLut, count);
else
seWriteCrtLut(pLut, count);
}
break;
case SURFACE_LCD0_CRTTV1:
if (surface == 0)
seWriteLcdLut(pLut, count);
else if (surface == 1)
{
if (regDisplayMode & TV)
seWriteTvLut(pLut, count);
else
seWriteCrtLut(pLut, count);
}
break;
case SURFACE_LCDCRTTV0:
if (surface == 0)
{
seWriteLcdLut(pLut, count);
seWriteCrtLut(pLut, count);
}
break;
}
}
/*-------------------------------------------------------------------------*/
void DisplayResolution(void)
{
unsigned x, y;
unsigned regDisplayMode;
regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);
switch (CalcDisplaySurfaceCombination())
{
case SURFACE_NONE:
break;
case SURFACE_LCD0:
seGetLcdResolution(&x, &y);
printf("LCD: %d * %d * %d Bpp\n", x, y, seGetLcdBitsPerPixel());
break;
case SURFACE_CRTTV0:
seGetCrtResolution(&x, &y);
printf("CRT/TV: %d * %d * %d Bpp\n", x, y, seGetCrtBitsPerPixel());
break;
case SURFACE_LCD0_CRTTV1:
case SURFACE_LCDCRTTV0:
seGetLcdResolution(&x, &y);
printf("LCD: %d * %d * %d Bpp\n", x, y, seGetLcdBitsPerPixel());
seGetCrtResolution(&x, &y);
printf("CRT/TV: %d * %d * %d Bpp\n", x, y, seGetCrtBitsPerPixel());
break;
}
}
/*-------------------------------------------------------------------------*/
void FailBpp(int bpp)
{
printf("\nERROR: Could not change to %d bits-per-pixel.\n", bpp);
printf( " Check if there is sufficient memory for image(s).\n");
exit(1);
}
/*-------------------------------------------------------------------------*/
void FailVirtual(void)
{
printf("ERROR: Could not change to ");
switch (LcdOrientation)
{
case LANDSCAPE:
default:
printf("LANDSCAPE\n");
break;
case ROTATE90:
printf("SWIVELVIEW 90 DEGREES\n");
break;
case ROTATE180:
printf("SWIVELVIEW 180 DEGREES\n");
break;
case ROTATE270:
printf("SWIVELVIEW 270 DEGREES\n");
break;
}
exit(1);
}
/*-------------------------------------------------------------------------*/
//
// bpp0=bits-per-pixel for first surface
// bpp1=bits-per-pixel for second surface
//
void SetBitsPerPixel(void)
{
unsigned regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);
DWORD addr;
unsigned bpp0, bpp1;
unsigned width, height;
unsigned LcdWidth, LcdHeight;
unsigned CrtTvWidth, CrtTvHeight;
unsigned ImgWidth, ImgHeight;
switch (CalcDisplaySurfaceCombination())
{
case SURFACE_NONE:
break;
case SURFACE_LCD0:
GetBMPInfo(filename[0], &ImgWidth, &ImgHeight, &bpp0);
if (bpp0 == 24)
bpp0 = 16;
addr = seSetLcdBitsPerPixel(bpp0);
#ifdef INTEL_DOS
if (addr == -1)
FailBpp(bpp0);
#else
if (addr == 0)
FailBpp(bpp0);
#endif
if (LcdOrientation & ROTATE90)
{
seWriteRegByte(REG_DISPLAY_MODE, seReadRegByte(REG_DISPLAY_MODE) | 0x40);
seGetLcdResolution(&LcdWidth, &LcdHeight);
if (seLcdVirtInit(LcdWidth, LcdHeight) != ERR_OK)
FailVirtual();
}
break;
case SURFACE_CRTTV0:
GetBMPInfo(filename[0], &ImgWidth, &ImgHeight, &bpp0);
if (bpp0 == 24)
bpp0 = 16;
if (regDisplayMode & TV)
addr = seSetTvBitsPerPixel(bpp0);
else
addr = seSetCrtBitsPerPixel(bpp0);
#ifdef INTEL_DOS
if (addr == -1)
FailBpp(bpp0);
#else
if (addr == 0)
FailBpp(bpp0);
#endif
break;
case SURFACE_LCD0_CRTTV1:
GetBMPInfo(filename[0], &ImgWidth, &ImgHeight, &bpp0);
if (bpp0 == 24)
bpp0 = 16;
addr = seSetLcdBitsPerPixel(bpp0);
#ifdef INTEL_DOS
if (addr == -1)
FailBpp(bpp0);
#else
if (addr == 0)
FailBpp(bpp0);
#endif
if (LcdOrientation & ROTATE90)
{
seWriteRegByte(REG_DISPLAY_MODE, seReadRegByte(REG_DISPLAY_MODE) | 0x40);
seGetLcdResolution(&LcdWidth, &LcdHeight);
if (seLcdVirtInit(LcdWidth, LcdHeight) != ERR_OK)
FailVirtual();
}
if (BmpCount > 1)
{
GetBMPInfo(filename[1], &ImgWidth, &ImgHeight, &bpp1);
if (bpp1 == 24)
bpp1 = 16;
}
else
bpp1 = bpp0;
if (regDisplayMode & TV)
addr = seSetTvBitsPerPixel(bpp1);
else
addr = seSetCrtBitsPerPixel(bpp1);
#ifdef INTEL_DOS
if (addr == -1)
FailBpp(bpp1);
#else
if (addr == 0)
FailBpp(bpp1);
#endif
break;
case SURFACE_LCDCRTTV0:
GetBMPInfo(filename[0], &ImgWidth, &ImgHeight, &bpp0);
if (bpp0 == 24)
bpp0 = 16;
addr = seSetLcdCrtBitsPerPixel(bpp0);
#ifdef INTEL_DOS
if (addr == -1)
FailBpp(bpp0);
#else
if (addr == 0)
FailBpp(bpp0);
#endif
//
// Create virtual space which is the larger of the two displays.
//
seWriteRegByte(REG_DISPLAY_MODE, seReadRegByte(REG_DISPLAY_MODE) & ~0x40);
seGetLcdResolution(&LcdWidth, &LcdHeight);
seGetCrtResolution(&CrtTvWidth, &CrtTvHeight);
if (LcdWidth >= CrtTvWidth)
width = LcdWidth;
else
width = CrtTvWidth;
if (LcdHeight >= CrtTvHeight)
height = LcdHeight;
else
height = CrtTvHeight;
if (seLcdCrtVirtInit(width, height) != ERR_OK)
FailVirtual();
break;
}
}
/*-------------------------------------------------------------------------*/
char *strDisplayArray[] = { "NONE", "LCD", "CRT", "LCD&CRT", "TV", "LCD&TV", "CRT/TV", "LCD&CRT/TV" };
char *GetCurrentDisplay(void)
{
return strDisplayArray[seGetSurfaceDisplayMode() & 0x07];
}
/*-------------------------------------------------------------------------*/
int VirtInit(unsigned surface, DWORD width, DWORD height)
{
unsigned regDisplayMode;
regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);
switch (CalcDisplaySurfaceCombination())
{
case SURFACE_NONE:
break;
case SURFACE_LCD0:
if (surface == 0)
return seLcdVirtInit(width, height);
break;
case SURFACE_CRTTV0:
if (surface == 0)
{
if (regDisplayMode & TV)
return seTvVirtInit(width, height);
else
return seCrtVirtInit(width, height);
}
break;
case SURFACE_LCD0_CRTTV1:
if (surface == 0)
return seLcdVirtInit(width, height);
else if (surface == 1)
{
if (regDisplayMode & TV)
return seTvVirtInit(width, height);
else
return seCrtVirtInit(width, height);
}
break;
case SURFACE_LCDCRTTV0:
if ((surface == 0) || (surface == 1))
return seLcdCrtVirtInit(width, height);
break;
}
return ERR_FAILED;
}
/*-------------------------------------------------------------------------*/
void DisplaySurfaceHelp(void)
{
printf("\n"
"\niDisplay | Surface 0 Surface 1"
"\n---------------------------------"
"\n 0 | LCD ---"
"\n 1 | CRT ---"
"\n 2 | TV ---"
"\n 3 | LCD & CRT ---"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -