00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "includes.h"
00011
00012 SYSTEM_CGA_CONTROL SystemCgaCtrl;
00013
00014 void SystemCgaInit(void){
00015 SystemCgaCtrl.CursorPosition=0;
00016 SystemCgaCtrl.CharacterAttribute=0x1F;
00017 SystemCgaScreenClean();
00018 SystemCgaCtrl.CharacterAttribute=0x0F;
00019 OutByte(SYSTEM_CGA_ADDRESS_PORT,SYSTEM_CGA_CLLR);
00020 OutByte(SYSTEM_CGA_DATA_PORT,((SystemCgaCtrl.CursorPosition/2)&0xff));
00021 OutByte(SYSTEM_CGA_ADDRESS_PORT,SYSTEM_CGA_CLHR);
00022 OutByte(SYSTEM_CGA_DATA_PORT,(((SystemCgaCtrl.CursorPosition/2)>>8)&0xff));
00023 }
00024
00025 void SystemCgaCursorSet(void){
00026 OutByte(SYSTEM_CGA_ADDRESS_PORT,SYSTEM_CGA_CLLR);
00027 OutByte(SYSTEM_CGA_DATA_PORT,((SystemCgaCtrl.CursorPosition/2)&0xff));
00028 OutByte(SYSTEM_CGA_ADDRESS_PORT,SYSTEM_CGA_CLHR);
00029 OutByte(SYSTEM_CGA_DATA_PORT,(((SystemCgaCtrl.CursorPosition/2)>>8)&0xff));
00030 }
00031
00032 void SystemCgaScrollUp(void){
00033 U32 i;
00034 U8 ByteValue;
00035
00036 for(i=0;i<3840;i++){
00037 ByteValue=SystemCgaByteRead(i+160);
00038 SystemCgaByteWrite(i,ByteValue);
00039 }
00040 for(i=3840;i<4000;i=i+2){
00041 SystemCgaByteWrite(i,' ');
00042 SystemCgaByteWrite(i+1,SystemCgaCtrl.CharacterAttribute);
00043 }
00044 SystemCgaCtrl.CursorPosition=3840;
00045 }
00046
00047 void SystemCgaCharPut(U8 CharValue){
00048 if((CharValue>=0x20)&&(CharValue<=0x7e)){
00049 SystemCgaByteWrite(SystemCgaCtrl.CursorPosition++,CharValue);
00050 SystemCgaByteWrite(SystemCgaCtrl.CursorPosition++,SystemCgaCtrl.CharacterAttribute);
00051 }
00052 else{
00053 SystemCgaByteWrite(SystemCgaCtrl.CursorPosition++,'?');
00054 SystemCgaByteWrite(SystemCgaCtrl.CursorPosition++,SystemCgaCtrl.CharacterAttribute);
00055 }
00056 if(SystemCgaCtrl.CursorPosition==4000) SystemCgaScrollUp();
00057 }
00058
00059 void SystemCgaScreenClean(void){
00060 U32 i;
00061
00062 for(i=0;i<4000;i=i+2){
00063 SystemCgaByteWrite(i,' ');
00064 SystemCgaByteWrite(i+1,SystemCgaCtrl.CharacterAttribute);
00065 }
00066 SystemCgaCtrl.CursorPosition=0;
00067 }
00068
00069 void SystemCgaChangeLine(void){
00070 U8 i;
00071
00072 i=0;
00073 while(SystemCgaCtrl.CursorPosition>160){
00074 SystemCgaCtrl.CursorPosition=SystemCgaCtrl.CursorPosition-160;
00075 i++;
00076 }
00077 SystemCgaCtrl.CursorPosition=(i+1)*160;
00078 if(SystemCgaCtrl.CursorPosition==4000) SystemCgaScrollUp();
00079 }
00080
00081 void SystemCgaStringPrint(U8* pString){
00082 while(*pString!=0){
00083 if(*pString==0x0a) SystemCgaChangeLine();
00084 else if(*pString==0x0d);
00085 else SystemCgaCharPut(*pString);
00086 pString++;
00087 }
00088 SystemCgaCursorSet();
00089 }