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

📄 13506blt.c

📁 epson13506 bitblt demo program
💻 C
📖 第 1 页 / 共 3 页
字号:
#pragma warning(disable:4001)   // Disable the 'single line comment' warning.

//-----------------------------------------------------------------------------
//
// 13506BLT.C - S1D13506 Blt Demo Program.
//
// Copyright(c) 1998, 2001 Epson Research and Development, Inc.  
// All rights reserved.
//
//-----------------------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <memory.h>
#include <math.h>

#define INTEL_W32
#define ESC       0x1B

#include "hal.h"
#include "appcfg.h"

typedef struct 
    {
    long  TotalVmem;        // Total video memory on the card.
    int   Width;            // Width (in pixels) of the mode.
    int   Height;           // Height (in pixels) of the mode.
    int   ColorDepth;       // Bits per pixel.
    int   Stride;           // Number of bytes from one line to the next.
    WORD  BytesPerPixel;    // 1,2 for 8BPP,15/16BPP
    } CONTROL_INFO,*LPCONTROL_INFO;

//---------------------------------------------------------------------------
//
//  BLT Info
//
//  The structure sent as an argument to all Blt routines.
//
//---------------------------------------------------------------------------
typedef struct 
    {
    int   ROP;
    int   SrcTop;
    int   SrcLeft;
    int   SrcWidth;
    int   SrcHeight;
    int   DstTop;
    int   DstLeft;
    int   DstWidth;
    int   DstHeight;
    int   PatternX,PatternY;

    int   Attribute;
    DWORD ColorBg;
    DWORD ColorFg;

    } BLT_INFO,*LPBLT_INFO;

#define Transparent 0x0001

//---------------------------------------------------------------------------
// Version Information 
//---------------------------------------------------------------------------

char szVersion[] = "1.01";

//---------------------------------------------------------------------------
// Function declaration 
//---------------------------------------------------------------------------
static void InitModeInfo(LPCONTROL_INFO lpInfo);
static void CalcFillBltParams(LPBLT_INFO lpBlt);
static void WaitForBltEnd(void);
static void RandomBltValues(LPBLT_INFO lpBlt);
static void ShowSolidFillBlt(void);
static void ShowPatternFillBlt(void);
static void ShowColorExpandBlt(void);
static void ShowMoveBlt(void);
static void ShowTransparentColorExpandBlt(void);
static void ShowTransparentMoveBlt(void);
static void ShowReadWriteBlt(void);
static BOOL CreateMonoBitmap(char *str,WORD **wpt,int *stridout);
static int  GetCharacterByte(int c,int line);
static BOOL EscPressed(void);
static void ClearVideoMemory(void);
static BOOL RectOverlap(LPBLT_INFO lpBlt);
static void ShowMenu(void);
static void DrawRect(int x,int y,int width,int height,DWORD color);
static DWORD CreateRandomPattern(LPBLT_INFO lpBlt);

//---------------------------------------------------------------------------
// Function declaration : Functions that contain the Blt code itself.
//---------------------------------------------------------------------------
static void ColorExpandBlt(LPBLT_INFO lpBlt,WORD *src,int srcstride);
static void PatternFillBlt(LPBLT_INFO lpBlt,DWORD PatStart);
static void MoveBlt(LPBLT_INFO lpBlt);
static void ReadBlt(LPBLT_INFO lpBlt,DWORD memaddress);
static void WriteBlt(LPBLT_INFO lpBlt, DWORD memaddress);
static void SolidFillBlt(LPBLT_INFO lpBlt);

extern char CharSet16[];
 
//---------------------------------------------------------------------------
// Global variables used by all Blt routines.
//---------------------------------------------------------------------------
DWORD gLinBufAddr;
DWORD gLinBltAddr;
DWORD gOffscreenOffset;
CONTROL_INFO Control;

//---------------------------------------------------------------------------
// DisplayCopyright()
//---------------------------------------------------------------------------
//
//  Purpose:    Displays the copyright message.
//              
//  Params:     szVersion be a pointer to the current version string.
//
//---------------------------------------------------------------------------
static void DisplayCopyright(const char * szVersion)
    {
    printf("\n13506BLTSAMPLE - version %s", szVersion);
    printf("\nCopyright(c) 1999, 2001 Epson Research and Development, Inc.");
    printf("\nAll rights reserved.");
    }

//---------------------------------------------------------------------------
//
// main()
//
//---------------------------------------------------------------------------
int main(int argc, char * argv[])
    {
    DisplayCopyright(szVersion);

    switch (seRegisterDevice(&HalInfo))
        {
        case ERR_OK:
            break;

        case ERR_UNKNOWN_DEVICE:
            printf("ERROR: Did not find a 13506 device.\n");
            return 1;

        default:
            printf("ERROR: Could not register S1D13506 device.\n");
            return 1;
        }

    if (seInitReg(0, 0) != ERR_OK)
        {
        printf("ERROR: Could not initialize device.\n");
        exit(1);
        }

    InitModeInfo(&Control);

    gLinBufAddr = seGetLinearDisplayAddress();
    gLinBltAddr = 0x100000 + seGetLinearRegAddress();
    gOffscreenOffset = Control.Height * Control.Stride;

    ClearVideoMemory();

    seWriteRegWord(0x46, Control.Stride/2); //LCD
    seWriteRegWord(0x66, Control.Stride/2); //CRT

    ShowMenu();
    return 0;
    }

//---------------------------------------------------------------------------
//
// Selects a blt demo based on  pressed key.
//
//---------------------------------------------------------------------------
void ShowMenu()
    {
    int ch = 0;
    do
        {
        printf("\n\nMenu:");
        printf("\nPress 1 : Solid Fill Demo");
        printf("\nPress 2 : Pattern Fill Demo");
        printf("\nPress 3 : Color Expand Demo");
        printf("\nPress 4 : Transparent Color Expand Demo");
        printf("\nPress 5 : Move Blt Demo");
        printf("\nPress 6 : Transparent Move Blt Demo");
        printf("\nPress 7 : Read/Write Blt Demo");
        printf("\nESC: quit\n");
        ch = getch();
        switch (ch)
            {
            case '1': 
                ShowSolidFillBlt();
                break;
            case '2': 
                ShowPatternFillBlt();
                break;
            case '3':
                ShowColorExpandBlt();
                break;
            case '4':
                ShowTransparentColorExpandBlt();
                break;
            case '5':
                ShowMoveBlt();
                break;
            case '6':
                ShowTransparentMoveBlt();
                break;
            case '7':
                ShowReadWriteBlt();
                break;
            case ESC:
                return;

            }
        } while (TRUE);
    }

//---------------------------------------------------------------------------
//
// Demonstrate Solid Fill Blt.
//
//---------------------------------------------------------------------------
static void ShowSolidFillBlt(void)
    {
    BLT_INFO Blt;

    printf("\nDrawing random rectangles using Solid Fill Blt.");
    printf("\nPress Esc to quit...\n");

    ClearVideoMemory();

    while (!EscPressed())
        {
        RandomBltValues(&Blt);
        SolidFillBlt(&Blt);
        }
    }

//---------------------------------------------------------------------------
//
// Demonstrate Pattern Fill Blt.
//
//---------------------------------------------------------------------------
static void ShowPatternFillBlt(void)
    {
    BLT_INFO Blt;
    DWORD pattaddress;

    printf("\nDrawing random rectangles using Pattern Fill Blt and Pattern");
    printf("\nFill Blt with Transparency.");
    printf("\nPress Esc to quit...\n");

    ClearVideoMemory();

    while (!EscPressed())
        {
        RandomBltValues(&Blt);

        // eliminate cases hardware cannot handle

        if ((Blt.Attribute & Transparent) || Blt.ROP == 0x0c || Blt.ROP == 0x03)
            {
            if (Blt.DstWidth == 1 || (Blt.DstWidth == 2 && Control.BytesPerPixel == 1))
                continue;
            }

        pattaddress = CreateRandomPattern(&Blt);
        PatternFillBlt(&Blt,pattaddress);
        }
    }

//---------------------------------------------------------------------------
//
// Demonstrate Move Blt.
//
//---------------------------------------------------------------------------
static BYTE BlueColor[3]  = {0,0,0xFF};
static BYTE RedColor[3]   = {0xFF,0,0};
static BYTE GreenColor[3] = {0,0xFF,0};

static BYTE InvertedBlueColor[3]  = {0xFF,0xFF,0};
static BYTE InvertedRedColor[3]   = {0,0xFF,0xFF};
static BYTE InvertedGreenColor[3] = {0xFF,0,0xFF};

static void ShowMoveBlt(void)
    {
    BLT_INFO Blt;
    int width,height,i,h,w,cheight,cwidth;
    DWORD red,green,blue;

    printf("\nMoving around a rectangle using Move Blt.");
    printf("\nPress Esc to quit...\n");

    ClearVideoMemory();

    if (Control.BytesPerPixel == 1)
        {
        seWriteLutEntry(0x2,BlueColor);
        seWriteLutEntry(0x3,RedColor);
        seWriteLutEntry(0x4,GreenColor);
        blue  = 2;
        red   = 3;
        green = 4;
        }
    else
        {
        blue  = 0x001F;
        red   = 0xF800;
        green = 0x07E0;
        }

    // Draw something on the screen so we can move it around:

    // Draw a blue rectangle

    width = Control.Width/9;
    height = Control.Height/2;

    DrawRect(0,0,width,height,red);
    DrawRect(1,1,width-2,height-2,blue);

    // Draw a green cross with red boundry
    
    cheight = height/2;
    cwidth = width /2;
    DrawRect(cwidth/2,cheight/2,cwidth,cheight,red);
    DrawRect(4,(height-cwidth)/2,width-8,cwidth,red);

    DrawRect(cwidth/2+1,cheight/2+1,cwidth-2,cheight-2,green);
    DrawRect(4,(height-cwidth)/2+1,width-8,cwidth-2,green);

    // We have a rectangle, the destination coords of the rectangle
    // will be the source coords of all move blt.
    
    Blt.SrcLeft = 0;
    Blt.SrcTop = 0;
    Blt.DstLeft = 0;
    Blt.DstTop = 0;
    Blt.SrcHeight = Blt.DstHeight = height;
    Blt.SrcWidth = Blt.DstWidth = width;
    Blt.Attribute = 0;
    Blt.ROP = 0xC;

    w = Control.Width/4;
    h = Control.Height/7;

    i = 0;
    while (!EscPressed())
        {
        Blt.DstLeft = (int)(sin(-i*0.0121)*w+w*2);
        Blt.DstTop  = (int)(cos(i*0.0121)*h+h*2);
        MoveBlt(&Blt);    
        Blt.SrcLeft = Blt.DstLeft;
        Blt.SrcTop = Blt.DstTop;
        i++;
        }
    }

//---------------------------------------------------------------------------
//
// Demonstrate Transparent Move Blt.
//
//---------------------------------------------------------------------------
static void ShowTransparentMoveBlt(void)
    {
    BLT_INFO Blt;
    int width,height,i,h,w,cheight,cwidth;
    DWORD red,green,blue;

    printf("\nMoving around a rectangle using Transparent Move Blt.");
    printf("\nTransparent color is blue.");
    printf("\nPress Esc to quit...\n");

    ClearVideoMemory();

    if (Control.BytesPerPixel == 1)
        {
        seWriteLutEntry(0x2,BlueColor);
        seWriteLutEntry(0x3,RedColor);
        seWriteLutEntry(0x4,GreenColor);
        blue  = 2;
        red   = 3;
        green = 4;
        }
    else
        {
        blue  = 0x001F;
        red   = 0xF800;
        green = 0x07E0;
        }

    // Draw something on the screen so we can move it around:

    // Draw a blue rectangle

    width = Control.Width/9;
    height = Control.Height/2;

    DrawRect(0,0,width,height,blue);

    // Draw a green cross with red boundry
    
    cheight = height/2;
    cwidth = width /2;
    DrawRect(cwidth/2,cheight/2,cwidth,cheight,red);
    DrawRect(1,(height-cwidth)/2,width-2,cwidth,red);

    DrawRect(cwidth/2+1,cheight/2+1,cwidth-2,cheight-2,green);
    DrawRect(2,(height-cwidth)/2+1,width-4,cwidth-2,green);

    // now we have the source bitmap we want to move around...

    Blt.SrcLeft = 0;
    Blt.SrcTop = 0;
    Blt.DstLeft = 0;
    Blt.DstTop = 0;
    Blt.SrcHeight = Blt.DstHeight = height;
    Blt.SrcWidth = Blt.DstWidth = width;
    Blt.Attribute = Transparent;
    Blt.ColorBg = blue;

    w = Control.Width/4;
    h = Control.Height/7;

    i = 0;
    while (!EscPressed())
        {
        Blt.DstLeft = (int)(sin(-i*0.0121)*w+w*2);
        Blt.DstTop  = (int)(cos(i*0.0121)*h+h*2);
        MoveBlt(&Blt);    
        i++;
        }
    }

//---------------------------------------------------------------------------
//
// Demonstrate Read Blt and Write Blt.
//
//---------------------------------------------------------------------------
static void ShowReadWriteBlt(void)
    {
    BLT_INFO Blt;
    int width,height,i,h,w,cheight,cwidth,nWords;
    DWORD notred,notgreen,notblue,red,green,blue,memaddress;

    printf("\nMoving around a rectangle using Read/Write Blts.");
    printf("\nWrite Blt ROP is set to 3, so the rectangle colors toggle between normal");
    printf("\nand inverted.");
    printf("\nPress Esc to quit...\n");

    ClearVideoMemory();

    if (Control.BytesPerPixel == 1)
        {
        // For 8BPP mode we initilize our favorite colors.

        blue  = 2;  //indeces into LUT
        red   = 3;
        green = 4;

        seWriteLutEntry(blue,BlueColor);
        seWriteLutEntry(red,RedColor);
        seWriteLutEntry(green,GreenColor);
        // For this example, we have to program the LUT also for 
        // "inverted" colors
        notblue  = (~blue) & 0xFF;
        notred   = (~red) & 0xFF;
        notgreen = (~green) & 0xFF;
        seWriteLutEntry(notblue,InvertedBlueColor);
        seWriteLutEntry(notred,InvertedRedColor);
        seWriteLutEntry(notgreen,InvertedGreenColor);
        }
    else
        {
        blue  = 0x001F;
        red   = 0xF800;
        green = 0x07E0;
        }

    // Draw something on the screen so we can move it around:

    // Draw a blue rectangle

    width = Control.Width/9;
    height = Control.Height/2;

    DrawRect(0,0,width,height,red);
    DrawRect(1,1,width-2,height-2,blue);

    // Draw a green cross with red boundry
    
    cheight = height/2;
    cwidth = width /2;
    DrawRect(cwidth/2,cheight/2,cwidth,cheight,red);
    DrawRect(4,(height-cwidth)/2,width-8,cwidth,red);

    DrawRect(cwidth/2+1,cheight/2+1,cwidth-2,cheight-2,green);

⌨️ 快捷键说明

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