📄 swivel.c
字号:
//----------------------------------------------------------------------------
//
// SWIVEL.C - A test program for S1D13506
//
// Copyright (c) Seiko Epson Corp. 1999, 2001 All rights reserved.
//
//----------------------------------------------------------------------------
//
// $Header: /13506/swivel/swivel.c 7 2/14/01 2:45p Roy $
//
// $Revision: 7 $
//
//----------------------------------------------------------------------------
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <hal.h>
#include "appcfg.h"
//----------------------------------------------------------------------------
//
//
//----------------------------------------------------------------------------
void DisplayCopyright(void);
void ShowChar(int c);
void ShowString(char *str);
void DoRotations(void);
void DrawPicture(void);
void ClearScreen(void);
void ProgramLUT(void);
//----------------------------------------------------------------------------
//
//
//----------------------------------------------------------------------------
char szVersion[] = "1.03";
#define ESC 0x1b
extern char CharSet16[16*256];
DWORD gLinBufAddr;
typedef struct
{
int x,y;
int maxx,maxy;
int FgColor,BgColor;
}CURPOSST;
CURPOSST CurPos;
int gPanelWidth,gPanelHeight,gScanBytes,gBPP;
//----------------------------------------------------------------------------
//
//
//----------------------------------------------------------------------------
int main(int argc, char *argv[])
{
unsigned byte40;
DisplayCopyright();
if (argc != 1)
return 1;
switch (seRegisterDevice(&HalInfo))
{
case ERR_OK:
break;
case ERR_UNKNOWN_DEVICE:
printf("ERROR: Did not find a 13506 device.\n");
exit(1);
default:
printf("ERROR: Could not register S1D13506 device.\n");
exit(1);
}
if (seInitReg(0, 0) != ERR_OK)
{
printf("ERROR: Could not initialize device.\n");
exit(1);
}
gLinBufAddr = seGetLinearDisplayAddress();
// crack the panel dimensions...
gPanelWidth = (seReadRegByte(0x32) + 1) *8; //width of the panel in pixels
gPanelHeight = (seReadRegByte(0x38) + (seReadRegByte(0x39) << 8)) + 1;
byte40 = seReadRegByte(0x40) & 0x7;
if (byte40 == 0x4 || byte40 == 0x5) //15BPP or 16BPP
gBPP = 16;
else // if we are not in 8BPP mode, we'll force it
{
gBPP = 8;
// as we are in 8BPP mode, program LUT entries we're going to use...
ProgramLUT();
byte40 = 3; //force 8BPP mode
}
seWriteRegByte(0x40, byte40);
DoRotations();
return 0;
}
//--------------------------------------------------------------------------
//
//
//--------------------------------------------------------------------------
void DoRotations(void)
{
int rot;
unsigned byte1fc,byte40,sa;
byte40 = seReadRegByte(0x40);
byte1fc = seReadRegByte(0x1fc);
// Swivel supported only on LCD panels
if ((byte1fc & 0x7) != 0x01) //LCD only reqired
{
printf("\nERROR: Swivelview supported for LCD only!");
return;
}
rot = 0;
do
{
ClearScreen();
// Based ot the desired rotation, calculate new start address and
// "swivel" bits
switch (rot)
{
case 0:
if (gBPP == 8)
gScanBytes = gPanelWidth;
else
gScanBytes = gPanelWidth*2;
byte1fc &= ~0x40;
byte40 &= ~0x10;
sa = 0;
break;
case 90:
byte1fc |= 0x40;
byte40 &= ~0x10;
if (gBPP == 8)
{
gScanBytes = 1024;
sa = (1024 - gPanelWidth)/2;
}
else
{
gScanBytes = 2048;
sa = (1024 - gPanelWidth);
}
break;
case 180:
byte1fc &= ~0x40;
byte40 |= 0x10;
// the formula for start address can be simplified
// if scanbytes == panel width...
if (gBPP == 8)
{
gScanBytes = gPanelWidth;
sa = (gScanBytes*gPanelHeight-(gScanBytes-gPanelWidth))/2 -1;
}
else
{
gScanBytes = gPanelWidth*2;
sa = (gScanBytes*gPanelHeight-(gScanBytes-2*gPanelWidth))/2 -1;
}
break;
case 270:
if (gBPP == 8)
gScanBytes = 1024;
else
gScanBytes = 2048;
byte1fc |= 0x40;
byte40 |= 0x10;
sa = (gScanBytes*gPanelHeight)/2 -1;
break;
}
// Program the stride in WORDS
seWriteRegWord(0x46, gScanBytes/2);
// Change the start address...
seWriteRegByte(0x42,sa);
seWriteRegByte(0x43,sa >> 8);
seWriteRegByte(0x44,sa >>16);
// Program the new "swivel" bits
seWriteRegByte(0x40,byte40);
seWriteRegByte(0x1fc,byte1fc);
// recalc the max cursor positions
if (byte1fc & 0x40)
{
CurPos.maxx = gPanelHeight/8;
CurPos.maxy = gPanelWidth/16;
}
else
{
CurPos.maxx = gPanelWidth/8;
CurPos.maxy = gPanelHeight/16;
}
printf("Picture rotated %d degrees\n",rot);
printf("...press ESC to quit, any other key to continue...\n");
DrawPicture();
rot += 90;
rot = rot % 360;
} while (getch() != ESC);
}
//--------------------------------------------------------------------------
//
// Clear the screen...
// We'll clear 1M of memory. Also, we'll make sure we clear it "unrotated".
//
//--------------------------------------------------------------------------
void ClearScreen(void)
{
DWORD *ptr;
unsigned byte1fc,byte40;
int i;
#define MEMORY_DWORDS ((1024*1024)/4)
byte40 = seReadRegByte(0x40);
byte1fc = seReadRegByte(0x1fc);
seWriteRegByte(0x40,((byte40 & ~0x10)| 0x80));
seWriteRegByte(0x1fc,(byte1fc & ~0x40));
ptr = (DWORD*) gLinBufAddr;
for (i = 0; i < MEMORY_DWORDS; i++)
*ptr++ = 0;
seWriteRegByte(0x40,byte40);
seWriteRegByte(0x1fc,byte1fc);
}
//--------------------------------------------------------------------------
//
// DrawPicture : this routine is blissfully unaware of the display rotation...
//
//--------------------------------------------------------------------------
void DrawPicture(void)
{
char tmp[80];
CurPos.x = CurPos.y = 0;
while (CurPos.y < CurPos.maxy)
{
CurPos.x = 0;
sprintf(tmp,"Line %d ...",CurPos.y);
ShowString(tmp);
CurPos.y++;
}
}
//--------------------------------------------------------------------------
//
//
//--------------------------------------------------------------------------
void ShowChar8BPP(int c)
{
BYTE *bpt;
BYTE *ppt,*pt;
int i,j,k;
bpt = CharSet16+c*16;
pt = (BYTE*)gLinBufAddr + CurPos.y*16*gScanBytes + CurPos.x*8;
// Draw a character 16 x 8 pixels
for (i = 0; i < 16; i++)
{
k = *bpt++;
ppt = pt;
for (j = 0; j < 8; j++, k = (k << 1), ppt++)
{
if (k & 0x80)
*ppt = CurPos.FgColor;
else
*ppt = CurPos.BgColor;
}
pt += gScanBytes;
}
// bump the cursor position
CurPos.x++;
if (CurPos.x >= CurPos.maxx)
{
CurPos.x = 0;
CurPos.y++;
}
}
//--------------------------------------------------------------------------
//
//
//--------------------------------------------------------------------------
void ShowChar16BPP(int c)
{
BYTE *bpt;
WORD *ppt,*pt;
int i,j,k;
bpt = CharSet16+c*16;
pt = (WORD*)(gLinBufAddr + CurPos.y*16*gScanBytes + CurPos.x*16);
// Draw a character 16 x 8 pixels
for (i = 0; i < 16; i++)
{
k = *bpt++;
ppt = pt;
for (j = 0; j < 8; j++, k = (k << 1), ppt++)
{
if (k & 0x80)
*ppt = CurPos.FgColor;
else
*ppt = CurPos.BgColor;
}
pt += gScanBytes/2; //word arithmetic
}
// bump the cursor position
CurPos.x++;
if (CurPos.x >= CurPos.maxx)
{
CurPos.x = 0;
CurPos.y++;
}
}
//--------------------------------------------------------------------------
//
//
//--------------------------------------------------------------------------
void ShowString(char *str)
{
int c;
CurPos.FgColor = 0xFFFF;
CurPos.BgColor = 0x0000;
if (gBPP == 8)
{
while (c = *str++)
ShowChar8BPP(c);
}
else
{
while (c = *str++)
ShowChar16BPP(c);
}
}
//--------------------------------------------------------------------------
//
//
//--------------------------------------------------------------------------
void DisplayCopyright(void)
{
const char *szHalVer;
const char *szHalStatus;
const char *szHalStatusRev;
seGetHalVersion(&szHalVer, &szHalStatus, &szHalStatusRev);
printf("13506SWIVEL.EXE - Test Display Rotation - Version %s [HAL %s%s%s]\n", szVersion, szHalVer, szHalStatus, szHalStatusRev);
printf("Copyright (c) 1999, 2001 Epson Research and Development, Inc.\n");
printf("All Rights Reserved.\n\n");
printf("Register Start Addr: ");
if (HalInfo.dwRegisterAddress == 0)
printf("Configured by system\n");
else
printf("%08lX\n", HalInfo.dwRegisterAddress);
printf("Display Memory Start Addr: ");
if (HalInfo.dwDisplayMemoryAddress == 0)
printf("Configured by system\n");
else
printf("%08lX\n", HalInfo.dwDisplayMemoryAddress);
}
//----------------------------------------------------------------------------
//
//
//----------------------------------------------------------------------------
typedef struct
{
BYTE rgb[3]; //3 bytes: Red,Green,Blue
} RGBST;
//----------------------------------------------------------------------------
//
//
//----------------------------------------------------------------------------
void WriteLUT(int index, RGBST *ptr)
{
seWriteRegByte(0x1e2,index);
seWriteRegByte(0x1e4,ptr->rgb[0]);
seWriteRegByte(0x1e4,ptr->rgb[1]);
seWriteRegByte(0x1e4,ptr->rgb[2]);
}
//----------------------------------------------------------------------------
//
//
//----------------------------------------------------------------------------
RGBST LutVals[] =
{
{0x00,0x00,0x00}, //black
{0xFF,0xFF,0xFF}, //white
};
void ProgramLUT(void)
{
WriteLUT(0x00, &LutVals[0]);
WriteLUT(0xFF, &LutVals[1]);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -