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

📄 hal_virt.c

📁 epson 13506 driver code
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
**===========================================================================
** HAL_VIRT.C
**---------------------------------------------------------------------------
** Copyright (c) 1997, 2001 Epson Research and Development, Inc.
** All Rights Reserved.
**===========================================================================
*/

#include <stdlib.h>

#if defined(INTEL_W32) || defined(INTEL_DOS)
#include <stdio.h>
#endif

#include <string.h>

#include "hal.h"
#include "assert.h"
#include "nonsefns.h"

/*-------------------------------------------------------------------------*/

static const char Revision[] = "HAL_VIRT.C=$Revision: 19 $";

/*-------------------------------------------------------------------------*/

int seVirtInit(DWORD width, DWORD height)
   {
   unsigned nVirtWPS;    // Words Per Scanline
   unsigned nPhysWidth;
   unsigned nPhysLines;
   unsigned nBPP;
   unsigned nMaxWidth;
   unsigned regDisplayMode;
   unsigned orientation;
   DWORD lLength;

   /*
   ** Get out of rotate90 mode (temporarily)
   */
   regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);
   seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode & ~0x40);

   seGetResolution(&nPhysWidth, &nPhysLines);

   nBPP = seGetBitsPerPixel();

   /*
   ** Restore original mode (rotate90 or landscape)
   */
   seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode);


   if (nBPP == 15)  /* 15 and 16 bpp are treated the same */
      nBPP = 16;

   /*
   ** 0x7ff is the maximum memory address offset in words
   */
   nMaxWidth = (0x7ff * 16 / nBPP);


   /*
   ** Check if virtual width is greater than physical width of display
   ** and less than maximum width permitted.
   */
   if (_ActiveImageSurface->DisplayMode & LCD)
      orientation = seGetLcdOrientation();
   else
      orientation = LANDSCAPE;

   if (!(orientation & ROTATE90))
      {
      if ((width > nMaxWidth) || (width < nPhysWidth))
         return ERR_HAL_BAD_ARG;
      }
   else
      {
      /*
      ** In rotate90 mode, the virtual height (physical width) is
      ** always 1024 pixels.
      */
      height = 1024;
      }


   /*
   ** Allocate memory for virtual mode.
   */
   lLength = width * height * 2 * nBPP / 16;  /* length in bytes */

   seVmemFree(_ActiveImageSurface->LinearAddress);

   _ActiveImageSurface->LinearAddress = seVmemAlloc(lLength);

#ifdef INTEL_DOS
   if (_ActiveImageSurface->LinearAddress == -1)
      return ERR_NOT_ENOUGH_MEMORY;
#else
   if (_ActiveImageSurface->LinearAddress == 0)
      return ERR_NOT_ENOUGH_MEMORY;
#endif

   _ActiveImageSurface->OffsetAddress = _ActiveImageSurface->LinearAddress - _DispLinearAddress;
   _ActiveImageSurface->DisplayMemorySize = lLength;

   _ActiveImageSurface->VirtWidth = width;
   _ActiveImageSurface->VirtHeight = height;

   if (!(orientation & ROTATE90))
      nVirtWPS = width / (16/nBPP);
   else
      nVirtWPS = 1024 / (16/nBPP);

   if (_ActiveImageSurface->DisplayMode & LCD)
      seWriteRegWord(REG_LCD_MEM_ADDR_OFFSET0, nVirtWPS);

   if (_ActiveImageSurface->DisplayMode & (CRT | TV))
      seWriteRegWord(REG_CRTTV_MEM_ADDR_OFFSET0, nVirtWPS);

   seVirtPanScroll(0, 0);

   return ERR_OK;
   }

/*-------------------------------------------------------------------------*/

int seLcdVirtInit(DWORD width, DWORD height)
   {
   unsigned nVirtWPS;    // Words Per Scanline
   unsigned nPhysWidth;
   unsigned nPhysLines;
   unsigned nBPP;
   unsigned nMaxWidth;
   unsigned regDisplayMode;
   unsigned orientation;
   DWORD lLength;

   /*
   ** Get out of rotate90 mode (temporarily)
   */
   regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);
   seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode & ~0x40);

   seGetLcdResolution(&nPhysWidth, &nPhysLines);

   nBPP = seGetLcdBitsPerPixel();

   /*
   ** Restore original mode (rotate90 or landscape)
   */
   seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode);


   if (nBPP == 15)  /* 15 and 16 bpp are treated the same */
      nBPP = 16;

   /*
   ** 0x7ff is the maximum memory address offset in words
   */
   nMaxWidth = (0x7ff * 16 / nBPP);


   orientation = seGetLcdOrientation();

   if (!(orientation & ROTATE90))
      {
      if ((width > nMaxWidth) || (width < nPhysWidth))
         return ERR_HAL_BAD_ARG;
      }
   else
      {
      /*
      ** In rotate90 mode, the virtual height (physical width) is
      ** always 1024 pixels.
      */
      height = 1024;
      }


   /*
   ** Allocate memory for virtual mode.
   */
   lLength = width * height * 2 * nBPP / 16;  /* length in bytes */

   seVmemFree(_LcdSurface.LinearAddress);

   _LcdSurface.LinearAddress = seVmemAlloc(lLength);

#ifdef INTEL_DOS
   if (_LcdSurface.LinearAddress == -1)
      return ERR_NOT_ENOUGH_MEMORY;
#else
   if (_LcdSurface.LinearAddress == 0)
      return ERR_NOT_ENOUGH_MEMORY;
#endif

   _LcdSurface.OffsetAddress = _LcdSurface.LinearAddress - _DispLinearAddress;
   _LcdSurface.DisplayMemorySize = lLength;

   _LcdSurface.VirtWidth = width;
   _LcdSurface.VirtHeight = height;

   if (!(orientation & ROTATE90))
      nVirtWPS = width / (16/nBPP);
   else
      nVirtWPS = 1024 / (16/nBPP);

   seWriteRegWord(REG_LCD_MEM_ADDR_OFFSET0, nVirtWPS);

   seLcdVirtPanScroll(0, 0);

   return ERR_OK;
   }

/*-------------------------------------------------------------------------*/

int seCrtVirtInit(DWORD width, DWORD height)
   {
   unsigned nVirtWPS;    // Words Per Scanline
   unsigned nPhysWidth;
   unsigned nPhysLines;
   unsigned nBPP;
   unsigned nMaxWidth;
   DWORD lLength;

   seGetCrtResolution(&nPhysWidth, &nPhysLines);
   nBPP = seGetCrtBitsPerPixel();

   if (nBPP == 15)  /* 15 and 16 bpp are treated the same */
      nBPP = 16;

   /*
   ** 0x7ff is the maximum memory address offset in words
   */
   nMaxWidth = (0x7ff * 16 / nBPP);

   /*
   ** Allocate memory for virtual mode.
   */
   lLength = width * height * 2 * nBPP / 16;  /* length in bytes */

   seVmemFree(_CrtTvSurface.LinearAddress);

   _CrtTvSurface.LinearAddress = seVmemAlloc(lLength);

#ifdef INTEL_DOS
   if (_CrtTvSurface.LinearAddress == -1)
      return ERR_NOT_ENOUGH_MEMORY;
#else
   if (_CrtTvSurface.LinearAddress == 0)
      return ERR_NOT_ENOUGH_MEMORY;
#endif

   _CrtTvSurface.OffsetAddress = _CrtTvSurface.LinearAddress - _DispLinearAddress;
   _CrtTvSurface.DisplayMemorySize = lLength;

   _CrtTvSurface.VirtWidth = width;
   _CrtTvSurface.VirtHeight = height;

   nVirtWPS = width / (16/nBPP);

   seWriteRegWord(REG_CRTTV_MEM_ADDR_OFFSET0, nVirtWPS);

   seCrtVirtPanScroll(0, 0);

   return ERR_OK;
   }

/*-------------------------------------------------------------------------*/

int seTvVirtInit(DWORD width, DWORD height)
{
   int err;

   err = seCrtVirtInit(width, height);
   _CrtTvSurface.DisplayMode = TV;
   return err;
}

/*-------------------------------------------------------------------------*/

int seLcdCrtVirtInit(DWORD width, DWORD height)
   {
   unsigned nVirtWPS;    // Words Per Scanline
   unsigned nPhysWidth;
   unsigned nPhysLines;
   unsigned nBPP;
   unsigned nMaxWidth;
   unsigned regDisplayMode;
   unsigned orientation;
   DWORD lLength;

   /*
   ** Get out of rotate90 mode (temporarily)
   */
   regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);
   seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode & ~0x40);

   seGetLcdResolution(&nPhysWidth, &nPhysLines);
   nBPP = seGetLcdBitsPerPixel();

   /*
   ** Restore original mode (rotate90 or landscape)
   */
   seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode);


   if (nBPP == 15)  /* 15 and 16 bpp are treated the same */
      nBPP = 16;

   /*
   ** 0x7ff is the maximum memory address offset in words
   */
   nMaxWidth = (0x7ff * 16 / nBPP);


   /*
   ** Check if virtual width is greater than physical width of display
   ** and less than maximum width permitted.
   */
   if (_ActiveImageSurface->DisplayMode & LCD)
      orientation = seGetLcdOrientation();
   else
      orientation = LANDSCAPE;

   if (!(orientation & ROTATE90))
      {
      if ((width > nMaxWidth) || (width < nPhysWidth))
         return ERR_HAL_BAD_ARG;
      }
   else
      {
      /*
      ** In rotate90 mode, the virtual height (physical width) is
      ** always 1024 pixels.
      */
      height = 1024;

⌨️ 快捷键说明

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