📄 synsvga.cpp
字号:
/* Synaesthesia - program to display sound graphically Copyright (C) 1997 Paul Francis Harrison 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. The author may be contacted at: pfh@yoyo.cc.monash.edu.au or 27 Bond St., Mt. Waverley, 3149, Melbourne, Australia*/#include <stdio.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/mman.h>#include <fcntl.h>#include <termios.h>#include <errno.h>#include "syna.h"#include "synvis.h"static unsigned char scr[320*200];static int mmfile;void screenInit(int xHint,int yHint,int widthHint,int heightHint) { // SMH: Write to a virtual buffer in a memmapped file. //mmfile = open( "/tmp/vis_screen", O_RDWR | O_CREAT ); //if (mmfile!=-1) { // scr = (unsigned char*)mmap( 0, 320*200, PROT_READ | PROT_WRITE, MAP_SHARED, mmfile,0); // if (((int)scr)>0) { // printf( "Visualisation module mapped.\n" ); // } else { // perror( "Failed to map visualisation module" ); // exit(1); // } //} else { // scr = NULL; // perror( "Error opening /tmp/vis_screen" ); //} outWidth = 320; outHeight = 200;}unsigned char* GetVisualisationRAM(){ return scr;}void screenClose(){ //delete [] scr; //int r = munmap( scr, 320*200 ); //if (r!=0) { // printf( "error closing memory mapping for visualisation.\n" ); //} //if (mmfile) close( mmfile );}int sizeUpdate() { return 0;}void screenShow(void) { if (!scr) return; register unsigned long *ptr2 = (unsigned long*)output; unsigned long *ptr1 = (unsigned long*)scr; int i = 320*200/4; // Asger Alstrup Nielsen's (alstrup@diku.dk) // optimized 32 bit screen loop do { //Original bytewize version: //unsigned char v = (*(ptr2++)&15*16); //*(ptr1++) = v|(*(ptr2++)>>4); register unsigned int const r1 = *(ptr2++); register unsigned int const r2 = *(ptr2++); //Fade will continue even after value > 16 //thus black pixel will be written when values just > 0 //thus no need to write true black //if (r1 || r2) {#ifdef LITTLEENDIAN register unsigned int const v = ((r1 & 0x000000f0ul) >> 4) | ((r1 & 0x0000f000ul) >> 8) | ((r1 & 0x00f00000ul) >> 12) | ((r1 & 0xf0000000ul) >> 16); *(ptr1++) = v | ( ((r2 & 0x000000f0ul) << 12) | ((r2 & 0x0000f000ul) << 8) | ((r2 & 0x00f00000ul) << 4) | ((r2 & 0xf0000000ul)));#else register unsigned int const v = ((r2 & 0x000000f0ul) >> 4) | ((r2 & 0x0000f000ul) >> 8) | ((r2 & 0x00f00000ul) >> 12) | ((r2 & 0xf0000000ul) >> 16); *(ptr1++) = v | ( ((r1 & 0x000000f0ul) << 12) | ((r1 & 0x0000f000ul) << 8) | ((r1 & 0x00f00000ul) << 4) | ((r1 & 0xf0000000ul)));#endif //} else { // ptr1++; //} } while (--i); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -