📄 show.c
字号:
/*
**===========================================================================
** SHOW.C - Source to the SHOW demo program. This program sets all
** available display modes and draws a pattern in each.
**---------------------------------------------------------------------------
** Copyright (c) 2000, 2001 Epson Research and Development, Inc.
** All Rights Reserved.
**===========================================================================
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include "hal.h"
#include "appcfg.h"
#include "assert.h"
#include "show.h"
#ifdef INCLUDE_CONIO_H // Check if it's OK to include conio.h
#include <conio.h>
#endif
/*============================ global variables ===========================*/
/****************************/
char szVersion[] = "1.03";
/****************************/
/*-----------------------------------------------------------------------*/
static const char Revision[] = "SHOW.C=$Revision: 10 $";
/*-----------------------------------------------------------------------*/
int gnAutoRun;
int gnUseVertical;
int gnContinualScrnRead;
int gnContinualScrnWrite;
int gnInitRegisters;
int gnShowGrid;
int gnUpdateDisplayMemory;
int LcdOrientation;
int ShowAllBppModes;
int CmdLineBitsPerPixel;
int UseBigMemory;
int CheckForValidSwivelViewClocks;
int NumberOfSurfaces;
int CommonMemoryBlockForAllDisplays;
unsigned SurfaceDisplayMode[MAX_DISP_SURFACE];
int GridColor;
char szModeFailed[] = "ERROR: Not enough memory for %s in %d bits-per-pixel.\n";
/*=============================== functions ===============================*/
void DisplayCopyright( void );
void DisplayUsage( void );
int ShowOneMode( int surface, int BitsPerPixel, char *str );
void UpdateScreen( unsigned BitsPerPixel );
unsigned GetNextColor( unsigned Color, unsigned Bpp );
int CalcDisplaySurfaceCombination(void);
/*================================== code =================================*/
int main( int argc, char *argv[] )
{
int AvailableBpp[] = { 16, 8, 4, 2, 1 };
int surface;
int MaxBitsPerPixel;
int error = 0;
int *bpp;
int BppSize;
int k;
int ch;
char *szPressKey = "Press any key to continue...\n";
char *pStr;
bpp = AvailableBpp;
BppSize = sizeof(AvailableBpp) / sizeof(AvailableBpp[0]);
/*-------------------*/
InitializeGlobalVariables();
/*-------------------*/
DisplayCopyright();
if ((error = ParseCommandLine(argc, argv)) != 0)
return error;
if (gnContinualScrnRead)
{
if (gnAutoRun)
{
DisplayUsage( );
printf( "ERROR: Continual screen read will not work with the /a switch.\n" );
return 1;
}
}
if (gnContinualScrnWrite)
{
if (gnAutoRun)
{
DisplayUsage( );
printf( "ERROR: Continual screen write will not work with the /a switch.\n" );
return 1;
}
}
if ((error = RegisterDevice(&HalInfo)) != 0)
return error;
if ((CmdLineBitsPerPixel != 0) && !gnInitRegisters)
{
printf("ERROR: b= option cannot be used with /noinit.\n");
exit(1);
}
if (gnInitRegisters)
{
if ((error = InitRegisters()) != 0)
return error;
}
if (!UpdateLcdOrientation())
return 1;
if ((error = HandleSelectedSurface()) != 0)
return error;
SetActiveSurfaceNumber(0);
MaxBitsPerPixel = seGetBitsPerPixel();
if (ShowAllBppModes)
{
for (k = 0; k < BppSize; ++k)
{
/*
** Don't show a BPP which is greater than what was set
** by the configuration program.
*/
for (surface = 0; surface < NumberOfSurfaces; ++surface)
{
if (!gnAutoRun && (surface == (NumberOfSurfaces - 1)))
{
if (bpp[k] > 1)
pStr = szPressKey;
else
pStr = NULL;
}
else
{
pStr = NULL;
if (bpp[k] > MaxBitsPerPixel)
break;
}
if (ShowOneMode(surface, bpp[k], pStr) == ERR_FAILED)
continue;
if ((NumberOfSurfaces == 1) ||
(((NumberOfSurfaces > 1) && (surface > 0))))
{
if (!gnAutoRun)
{
if (bpp[k] > 1) // don't wait for last bpp mode
{
ch = getch( );
if ((0x03 == ch) || (0x1B == ch))
return 0;
}
}
#ifdef INCLUDE_TIME_H
else
{
seDelay(5);
}
#endif
}
}
}
}
else
{
for (surface = 0; surface < NumberOfSurfaces; ++surface)
{
if (ShowOneMode( surface, CmdLineBitsPerPixel, NULL ) == ERR_FAILED)
break;
}
}
return 0;
}
/*-------------------------------------------------------------------------*/
int ShowOneMode( int surface, int BitsPerPixel, char *str )
{
unsigned width;
unsigned height;
DWORD lSize;
DWORD addr = 0;
DWORD dwVal = 0;
unsigned x, y;
DWORD xOffset;
#ifdef LINEAR_ADDRESSES_SUPPORTED
volatile DWORD *dwPtr = 0;
volatile DWORD *dwStartPtr = 0;
#endif
#ifdef INCLUDE_CONIO_H
int ch;
#endif
SetActiveSurfaceNumber(surface);
lSize = DISPLAY_BUFFER_SIZE;
if (lSize > 0)
--lSize;
if (gnInitRegisters)
{
//
// First check if valid clocks for given mode
//
if (!CheckSwivelViewClocks(BitsPerPixel, seGetSwivelViewMode()))
return ERR_FAILED;
if (seSetMode(BitsPerPixel) != ERR_OK)
{
DisplayErrorNotEnoughMemory(BitsPerPixel);
return ERR_FAILED;
}
}
if (CalcDisplaySurfaceCombination() == SURFACE_MAIN_AND_SUB_WIN0)
surface = SURFACE_MAIN_WIN0;
SetActiveSurfaceNumber(surface);
seGetResolution(&width, &height);
width = seGetBytesPerScanline() * 8 / seGetBitsPerPixel();
switch (VirtInit(surface, width, height))
{
case ERR_NOT_ENOUGH_MEMORY:
printf("ERROR: Not enough memory for virtual display of surface %d.\n", surface);
DisplayResolution();
return ERR_FAILED;
break;
case ERR_OK:
break;
default:
printf("ERROR: Could not initialize virtual display for surface %d.\n", surface);
DisplayResolution();
return ERR_FAILED;
}
seGetResolution(&x, &y);
xOffset = (seGetBytesPerScanline() * 8 / BitsPerPixel) - x;
seVirtPanScroll(xOffset, 0);
/*
** It was decided that the 13706 HAL would not refuse an attempt to set
** a color depth greater than can be supported by display memory. So...
** we have to check for ourselves whether we can fit into memory.
*/
if (seGetResolution(&width, &height) == ERR_OK)
{
width = seGetBytesPerScanline() * 8 / seGetBitsPerPixel();
if ((((DWORD) width * height * 2 * BitsPerPixel) / 16) > lSize)
return ERR_FAILED;
}
if (gnUpdateDisplayMemory)
UpdateScreen( BitsPerPixel );
seDisplayBlank(FALSE);
if (str != NULL)
printf("%s", str);
#ifdef LINEAR_ADDRESSES_SUPPORTED
if (gnContinualScrnRead)
{
dwStartPtr = (DWORD *) seGetSurfaceLinearAddress();
printf("Continual DWORD read from %08lXh...\n", (DWORD) dwPtr);
}
seDelay(1);
while (gnContinualScrnRead)
{
dwPtr = dwStartPtr;
seBeginHighPriority();
for (addr = 0; addr < lSize; addr += 4, ++dwPtr)
dwVal = *dwPtr;
seEndHighPriority();
#ifdef INCLUDE_CONIO_H
if (kbhit())
{
ch = getch( );
if ((0x03 == ch) || (0x1B == ch))
return 0;
}
#endif
}
#else
while (gnContinualScrnRead)
{
for (addr = 0; addr < lSize; addr += 4)
dwVal = seReadDisplayDword(addr);
if (kbhit())
{
ch = getch( );
if ((0x03 == ch) || (0x1B == ch))
return 0;
}
}
#endif
if (gnContinualScrnWrite)
{
addr = seGetAvailableMemorySize();
if (addr > 2)
addr -= 2;
addr &= ~0x01; // word align
printf("Continually writing 0x1234 to %06lX...\n", addr);
}
seBeginHighPriority();
while (gnContinualScrnWrite)
seWriteDisplayWords(addr, 0x1234, 1);
seEndHighPriority();
return ERR_OK;
}
/*-------------------------------------------------------------------------*/
void UpdateScreen( unsigned BitsPerPixel )
{
int RepeatC;
int x, y, i, j;
long x_step, y_step;
int Cx1, Cx2, Cy1, Cy2;
int Last_Cx2, Last_Cy2;
unsigned Color, White, Black;
int DisplayMode, count;
DWORD xOffset;
#define BPP_FACTOR ( 1000000L )
#define BPP_ROUNDUP ( BPP_FACTOR/2 )
Color = 0x00;
White = 0xFFFF;
Black = 0x0000;
DisplayMode = GetSurfaceDisplayMode(GetActiveSurfaceNumber());
count = 0;
if (DisplayMode & MAIN_WIN)
{
printf("MAIN WINDOW");
++count;
}
if (DisplayMode & SUB_WIN)
{
if (count > 0)
printf(" & ");
printf("SUB-WINDOW ");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -