📄 crtc6845-80×25.c
字号:
/* $id:Color256LCD176x220_wd2.c V1.0 2005/03/16 */
/******************************************************************************
* This source code has been made available to you by CORETEK on
* AS-IS.Anyone receiving this source is licensed under
* CORETEK copyrights to use it in any way he or she deems fit,including
* copying it,modifying it,compiling it,and redistributing it either with
* or without modifictions.
*
*
* Any person who transfers this source code or any derivative work must
* include the CORETEK copyright notice, this paragraph,and the preceding
* two paragraphs in the transferred software.
*
*
* COPYRIGHT CORETEK CORPORATION 2001
* LICENSED MATERIAL - PROGRAM PROPERTY OF CORETEK
*****************************************************************************/
/******************************************************************************
*
* FILE: CRTC6845-80×25.c
*
* MODULE: DRIVER
*
* PURPOSE: driver for display text.
*
* AUTHOR(S):zhengyh
*
* GROUP:Sys Dept.
*
* DATE CREATED:2005/04/13
*
* REFERENCE DOCUMENT ID:
*
* MODIFICATIONS:
* Date user Name Description
* 2005/04/13 zhengyh Create this file
*
*********************************************************************************/
#include "sysTypes.h"
//#include "arch.h"
#include "driver/ucbsp.h"
#define CRT_WHITE 0x7 // White on Black background color.
#define CRT_VGA_FB 0xb8000
#define CRT_VGA_NUM_ROWS 25
#define CRT_VGA_NUM_COLS 80
#define CRT_DISPLAY_CELL_COUNT (CRT_VGA_NUM_ROWS * CRT_VGA_NUM_COLS) // Number of display cells.
#define CRT_TABSIZE 4 // Number of spaces for TAB (\t) char.
#define CRT_BLANK (' ' | (CRT_WHITE << 8)) // Blank character.
static void screen_init(void);
static void scrollUp(T_UBYTE lines);
static void setHardwareCursorPos(T_UHWORD videoCursor);
static void printCHAR(T_BYTE c);
static void printLF(void);
static void printESC(void);
static void printCR(void);
static void printHT(void);
static void printBS(void);
static void disp_char(T_BYTE character);
static void updateVideoRamPtr(void);
#define i386_outport_byte( _port, _value ) \
do { register unsigned short __port = _port; \
register unsigned char __value = _value; \
\
asm volatile ( "outb %0,%1" : : "a" (__value), "d" (__port) ); \
} while (0)
#define BSP_OutByte( _port, _value ) i386_outport_byte( _port, _value )
/********************************************************************
* FUNCTION: BSP_DisplayInit
*
* PURPOSE: Init screen to be selected mode.
*
* PARAMETERS:
*
* Input: mode - screen display mode.
* Output:None
* InOut: None
*
* Return value: None
*
* Reentrant: No
********************************************************************/
volatile T_VOID BSP_DisplayInit()
{
static int inited=0x0;
if (inited)
{
return;
}
screen_init();
inited++;
}
/********************************************************************
* FUNCTION: BSP_DisplayOutch
*
* PURPOSE: Higher level (console) interface to with processing
* of special character and automatic scroll screen.
* PARAMETERS:
*
* Input: c - character to write to screen.
* Output:None
* InOut: None
*
* Return value: None
*
* Reentrant: No
********************************************************************/
volatile T_VOID BSP_DisplayOutch(T_BYTE ch)
{
disp_char(ch);
}
//---------------------------------------------------------------------------------------
#define CRT_VGA_WRITE_CRTC(reg, val) \
BSP_OutByte(0x3d4, reg); \
BSP_OutByte(0x3d5, val)
static T_UHWORD *videoRam = (T_UHWORD *)CRT_VGA_FB; // Physical address of start of video text memory.
static T_UHWORD *videoRamPtr = (T_UHWORD *)CRT_VGA_FB; // Pointer for current output position in display.
static T_UBYTE videoRows = CRT_VGA_NUM_ROWS; // Number of rows in display.
static T_UBYTE videoCols = CRT_VGA_NUM_COLS; // Number of columns in display.
static T_UBYTE cursRow = 0; // Current cursor row.
static T_UBYTE cursCol = 0; // Current cursor column.
/***********************************************************
* MODULE: screen_init
*
* PURPOSE:
* This function is used to init VGA screen.
*
* PARAMETERS
* Input: NULL
* Output: NULL
* Return value: NULL
*
***********************************************************/
static void screen_init(void)
{
/// Clear entire screen
scrollUp(videoRows);
/// Cursor at upper left corner
setHardwareCursorPos(0);
/// Crt cursor start
CRT_VGA_WRITE_CRTC(0x0a, 0x0e);
return;
}
/***********************************************************
* MODULE: scrollUp
*
* PURPOSE:
* This function is used to scroll display up n lines.
*
* PARAMETERS
* Input:
* lines
* Output: NULL
* Return value: NULL
*
***********************************************************/
static void scrollUp(T_UBYTE lines)
{
T_UHWORD blankCount; // Number of blank display cells on bottom of window.
T_UHWORD *ptrDst; // destination pointers for memory copy operations.
T_UHWORD *ptrSrc; // source pointers for memory copy operations.
/// Move window's contents up.
if (lines < videoRows)
{
T_UHWORD nonBlankCount; // Number of non-blank cells on upper part of display (total - blank).
blankCount = lines * videoCols;
nonBlankCount = CRT_DISPLAY_CELL_COUNT - blankCount;
ptrSrc = videoRam + blankCount;
ptrDst = videoRam;
while (nonBlankCount--)
{
*ptrDst++ = *ptrSrc++;
}
}
else
{
/// Clear the whole display.
blankCount = CRT_DISPLAY_CELL_COUNT;
ptrDst = videoRam;
}
/// Fill bottom with blanks.
while (blankCount-- > 0)
{
*ptrDst++ = CRT_BLANK;
}
return;
}
/***********************************************************
* MODULE: setHardwareCursorPos
*
* PURPOSE:
* This function is used to set hardware video cursor at
* given offset into video RAM.
*
* PARAMETERS
* Input:
* videoCursor
* Output: NULL
* Return value: NULL
*
***********************************************************/
static void setHardwareCursorPos(T_UHWORD videoCursor)
{
CRT_VGA_WRITE_CRTC(0x0e, (videoCursor >> 8) & 0xff);
CRT_VGA_WRITE_CRTC(0x0f, videoCursor & 0xff);
return;
}
/***********************************************************
* MODULE: disp_char
*
* PURPOSE:
* This function is used to Print character to display.
*
* PARAMETERS
* Input:
* character
* Output: NULL
* Return value: NULL
*
***********************************************************/
static void disp_char(T_BYTE character)
{
switch (character)
{
case '\b':
printBS();
break;
case '\t':
printHT();
break;
case '\n':
printLF();
break;
case '\r' :
printCR();
break;
case '\e' :
printESC();
break;
case 7:
/// Bell code must be inserted here
break;
default:
printCHAR(character);
}
setHardwareCursorPos(videoRamPtr - videoRam);
return;
}
/***********************************************************
* MODULE: printCHAR
*
* PURPOSE:
* This function is used to print printable character to
* display given offset into video RAM.
*
* PARAMETERS
* Input:
* character
* Output: NULL
* Return value: NULL
*
***********************************************************/
static void printCHAR(T_BYTE character)
{
*videoRamPtr++ = (CRT_WHITE <<8) | character;
cursCol++;
if(cursCol == videoCols)
{
cursCol = 0;
cursRow++;
if(cursRow == videoRows)
{
cursRow--;
scrollUp(1);
videoRamPtr -= videoCols;
}
}
return;
}
/***********************************************************
* MODULE: printLF
*
* PURPOSE:
* This function is used to Print LF (Line Feed - '\n')
* character to display.
*
* PARAMETERS
* Input: NULL
* Output: NULL
* Return value: NULL
*
***********************************************************/
static void printLF(void)
{
cursRow++;
if (cursRow == videoRows)
{
cursRow--;
scrollUp(1);
}
cursCol = 0;
updateVideoRamPtr();
return;
}
/***********************************************************
* MODULE: printCR
*
* PURPOSE:
* This function is used to Print CR (Carriage Return-'\r')
* character to display.
*
* PARAMETERS
* Input: NULL
* Output: NULL
* Return value: NULL
*
***********************************************************/
static void printCR(void)
{
cursCol = 0;
updateVideoRamPtr();
return;
}
/***********************************************************
* MODULE: printHT
*
* PURPOSE:
* This function is used to Print HT (Horizontal Tab - '\t')
* character to display.
*
* PARAMETERS
* Input: NULL
* Output: NULL
* Return value: NULL
*
***********************************************************/
static void printHT(void)
{
do
{
printCHAR(' ');
} while (cursCol % CRT_TABSIZE);
return;
}
/***********************************************************
* MODULE: printESC
*
* PURPOSE:
* This function is used to Print ESC (Horizontal Tab - '\e')
* clear a line.
*
* PARAMETERS
* Input: NULL
* Output: NULL
* Return value: NULL
*
***********************************************************/
static void printESC(void)
{
printLF();
printCR();
return;
}
/***********************************************************
* MODULE: printBS
*
* PURPOSE:
* This function is used to Print HT (BackSpace - '\b')
* character to display.
*
* PARAMETERS
* Input: NULL
* Output: NULL
* Return value: NULL
*
***********************************************************/
static void printBS(void)
{
/// Move cursor back one cell.
if (cursCol > 0)
{
cursCol--;
/// Write a whitespace.
*(--videoRamPtr) = CRT_BLANK;
}
return;
}
/***********************************************************
* MODULE: updateVideoRamPtr
*
* PURPOSE:
* This function is used to updates value of global variable
* - videoRamPtr based on current window's cursor position
* given offset into video RAM.
*
* PARAMETERS
* Input: NULL
* Output: NULL
* Return value: NULL
*
***********************************************************/
static void updateVideoRamPtr(void)
{
videoRamPtr = videoRam + cursRow * videoCols + cursCol;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -