📄 svgawrap.cpp
字号:
/* svgawrap.cpp SVGA wrapper class This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details, www.gnu.org. Copyright (C) 2000 Simon Harrison (email smh@N_O_S_P_A_M@dr.com)*/#include <fcntl.h>#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <vga.h>#include <vgagl.h>#include <string.h>#include <sys/mman.h>#include <sys/types.h>#include "font5x7.h"#include "svgawrap.h"#include "synvis.h"const int vgaw::KCurLeft=200;const int vgaw::KCurRight=201;const int vgaw::KCurUp=202;const int vgaw::KCurDown=203;const int vgaw::KEnter=204;const int vgaw::KPgDn=205;const int vgaw::KPgUp=206;vgaw::PaletteInit() { #define BOUND(x) ((x) > 255 ? 255 : (x)) #define PEAKIFY(x) BOUND((x) - (x)*(255-(x))/255/2) int i; for(i=0;i<256;i++) setPalette(i,PEAKIFY((i&15*16)), PEAKIFY((i&15)*16+(i&15*16)/4), PEAKIFY((i&15)*16)); }unsigned char statbuffer[320*200];vgaw::vgaw(){ int iRet=0; vscr = NULL; rscr = NULL; scr = NULL; /* do the VGA */ vga_init(); VGAMODE = G320x200x256; /* Default mode. */ if (!vga_hasmode(VGAMODE)) { printf("320x200x256 Mode not available.\n"); exit(1); } else { vga_setmode(VGAMODE); iRet = 1; gl_setcontextvga(VGAMODE); /* Physical screen context. */ gl_setrgbpalette(); /* clear screen and set to colour 0 */ gl_clearscreen(gl_rgbcolor(0,150,0)); font = new font5x7(GetFgCol(),GetBgCol()); /* normal font */ highfont = new font5x7(GetHighCol(),GetBgCol()); /* highlighted font */ warnfont = new font5x7(gl_rgbcolor(255,0,0),GetBgCol()); /* warning font */ gl_setfont( 5, 7, font->GetData() ); } PaletteInit(); vscr = new unsigned char[320*200]; // allocate a virtual screen. rscr = vga_getgraphmem(); gl_setcontextvirtual( 320,200,1,8,vscr ); gl_setwritemode( WRITEMODE_MASKED | FONT_EXPANDED ); //vsfd = open( "/tmp/vis_screen", O_RDWR ); //if (!vsfd) { // printf( "Failed to open shared visualisation file."); // exit(1); //} //scr = (char*)mmap( 0, 320*200, PROT_READ | PROT_WRITE, // MAP_SHARED, vsfd, 0 ); //if (((int)scr)==-1) { // printf( "Unable to open mmap.\n" ); // exit(1); //} scr = GetVisualisationRAM();// scr = statbuffer; // sanity check. if (!vscr) { printf( "No virtual screen.\n" ); exit(1); } if (!scr) { printf( "No visualisation mapping.\n" ); exit(1); } if (!rscr) { printf( "No real screen mapping.\n" ); exit(1); }}vgaw::~vgaw(){ delete vscr; delete font; delete highfont; delete warnfont; //if (scr) munmap( scr, 320*200 ); //if (vsfd) close(vsfd); vga_setmode(TEXT);}void vgaw::spaced_gl_write( int x, int y, char * text ){int i;char buffer[2]; buffer[1]=0; for (i=0;i<strlen(text);i++) { buffer[0] = text[i]; gl_write( x+i*6, y, buffer ); }}int vgaw::getkey()// TODO TODO TODO TODO// There may be other escape sequences I don't trap. If there are // pressing those keys will do wierd things.{int k; int r; // returned key. k=vga_getkey(); if (k==27) { // escape sequence, deal with it. k=vga_getkey(); if (k==91) { k = vga_getkey(); /* Move. */ if (k==68) { // cursor left; r = KCurLeft; } else if (k==67) { // enter r = KEnter; } else if (k==65) { // cursor up r = KCurUp; } else if (k==66) { // cursor down/ r = KCurDown; } else if (k==53) { // page up r = KPgUp; k = vga_getkey(); // 4 chars sent from K.B for PgDn } else if (k==54) { // page down r = KPgDn; k = vga_getkey(); // (4 chars) } else { // unrecognised escape. Let's pretend no key pressed. r = 0; } } else { r = 0; } } else { // assume it's just a normal key, and return it. r = k; } return r;} vgaw::updatevis() { if (!scr) printf( "Null real screen pointer.\n" ); if (!vscr) printf( "Null virtual screen pointer.\n" ); if (scr && vscr) memcpy( vscr, scr, 320*200 );}vgaw::setPalette(int i,int r,int g,int b) { vga_setpalette(i,r/4,g/4,b/4);}vgaw::FontNormal() { gl_setfont( 5,7, font->GetData() ); }vgaw::FontHigh() { gl_setfont( 5,7, highfont->GetData() ); }vgaw::FontWarn() { gl_setfont( 5,7, warnfont->GetData() ); }int vgaw::GetBgCol() { return gl_rgbcolor(0,0,0); }int vgaw::GetFgCol() { return gl_rgbcolor(0,255,0); }int vgaw::GetHighCol() { return gl_rgbcolor(255,255,0); }vgaw::updatereal() { if (!rscr) printf( "NULL real screen pointer.\n" ); if (!vscr) printf( "NULL virtuaL screen pointer.\n" ); if (rscr && vscr) memcpy( rscr, vscr, 320*200); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -