1 /* Synaesthesia - program to display sound graphically
2 Copyright (C) 1997 Paul Francis Harrison
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 675 Mass Ave, Cambridge, MA 02139, USA.
18 The author may be contacted at:
19 pfh@yoyo.cc.monash.edu.au
21 27 Bond St., Mt. Waverley, 3149, Melbourne, Australia
35 static unsigned char *scr
;
36 static int keyboardDevice
;
38 static void setOnePalette(int i
,int r
,int g
,int b
) {
39 vga_setpalette(i
,r
/4,g
/4,b
/4);
42 bool SvgaScreen::init(int xHint
,int yHint
,int widthHint
,int heightHint
,bool fullscreen
) {
43 attempt(vga_init(),"initializing svgalib");
44 if (!vga_hasmode(G320x200x256
))
45 error("requesting 320x200 graphics mode");
47 attempt(vga_setmode(G320x200x256
),"entering 320x200 graphics mode");
49 scr
= vga_getgraphmem();
53 attemptNoDie(mouse_init("/dev/mouse",
54 vga_getmousetype(),MOUSE_DEFAULTSAMPLERATE
),"initializing mouse");
55 mouse_setxrange(-1,321);
56 mouse_setyrange(-1,201);
57 mouse_setposition(160,34);
60 /*#define BOUND(x) ((x) > 255 ? 255 : (x))
61 #define PEAKIFY(x) BOUND((x) - (x)*(255-(x))/255/2)
64 setPalette(i,PEAKIFY((i&15*16)),
65 PEAKIFY((i&15)*16+(i&15*16)/4),
69 /* Get keyboard input descriptor */
73 //Ok, we're getting piped input, so we can't use stdin.
74 //Find out where stdout is going and read from it.
80 keyboardDevice
= open(tty
, O_RDONLY
);
82 if (keyboardDevice
!= -1) {
84 tcgetattr(keyboardDevice
, &term
);
86 tcsetattr(keyboardDevice
, TCSANOW
, &term
);
92 if (keyboardDevice
!= -1)
93 fcntl(keyboardDevice
,F_SETFL
,O_NONBLOCK
);
98 void SvgaScreen::setPalette(unsigned char *palette
) {
101 setOnePalette(i
,palette
[i
*3],palette
[i
*3+1],palette
[i
*3+2]);
104 void SvgaScreen::end() {
105 if (keyboardDevice
> 0)
106 close(keyboardDevice
);
112 void SvgaScreen::inputUpdate(int &mouseX
,int &mouseY
,int &mouseButtons
,char &keyHit
) {
114 mouseX
= mouse_getx();
115 mouseY
= mouse_gety();
116 mouseButtons
= mouse_getbutton();
118 if (keyboardDevice
== -1 || read(keyboardDevice
, &keyHit
, 1) != 1)
122 void SvgaScreen::show(void) {
123 register uint32_t *ptr2
= (uint32_t*)output
;
124 uint32_t *ptr1
= (uint32_t*)scr
;
125 int i
= 320*200/sizeof(uint32_t);
126 // Asger Alstrup Nielsen's (alstrup@diku.dk)
127 // optimized 32 bit screen loop
129 //Original bytewize version:
130 //unsigned char v = (*(ptr2++)&15*16);
131 //*(ptr1++) = v|(*(ptr2++)>>4);
132 register uint32_t const r1
= *(ptr2
++);
133 register uint32_t const r2
= *(ptr2
++);
135 //Fade will continue even after value > 16
136 //thus black pixel will be written when values just > 0
137 //thus no need to write true black
140 register uint32_t const v
=
141 ((r1
& 0x000000f0ul
) >> 4)
142 | ((r1
& 0x0000f000ul
) >> 8)
143 | ((r1
& 0x00f00000ul
) >> 12)
144 | ((r1
& 0xf0000000ul
) >> 16);
146 ( ((r2
& 0x000000f0ul
) << 12)
147 | ((r2
& 0x0000f000ul
) << 8)
148 | ((r2
& 0x00f00000ul
) << 4)
149 | ((r2
& 0xf0000000ul
)));
151 register uint32_t const v
=
152 ((r2
& 0x000000f0ul
) >> 4)
153 | ((r2
& 0x0000f000ul
) >> 8)
154 | ((r2
& 0x00f00000ul
) >> 12)
155 | ((r2
& 0xf0000000ul
) >> 16);
157 ( ((r1
& 0x000000f0ul
) << 12)
158 | ((r1
& 0x0000f000ul
) << 8)
159 | ((r1
& 0x00f00000ul
) << 4)
160 | ((r1
& 0xf0000000ul
)));