annotate oxl.c @ 0:0e4f2da58161

Initial import.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 15 Mar 2013 05:00:01 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*** OCSALiB 0.0.1alpha -- see oxl.h ***/
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #include "config.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #if VIDEO==vga
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include "vga.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #if VIDEO==X11
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "X11/Xlib.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include "X11/Xutil.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #if AUDIO
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #include "sys/soundcard.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #include "sys/ioctl.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 #include "stdio.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 #include "stdlib.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 #include "fcntl.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 #include "unistd.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 #include "malloc.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 #include "time.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 #include "sys/time.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 #ifdef __linux__
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 #include "linux/string.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 #else
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 #include "string.h"
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 #define DEMOHZ 100
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 int TIKLGT;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 typedef struct { int r,g,b; } rgb;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 /*** gLOBAL vARS ***/
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 int AUFREQ=OUTFREQ;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 #if AUDIO==1
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 int devdsp;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 char *audiobuf;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 #else
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 int baseclock;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 #if VIDEO==vga
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 int SCRH,SCRW;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 #if VIDEO==X11
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 Display *oxl_disp;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 Visual *oxl_vis;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 GC oxl_gc;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 int oxl_win,oxl_scr;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 Colormap oxl_pal;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 XImage *oxl_im;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 XColor oxl_col[256];
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 void oxl_init_video()
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 {
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 printf("oxl: buffer size = %ix%ix8bit\n",BUFW,BUFH);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 #if VIDEO==vga
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 { int i,fit=0,fitw=9999,fith=9999;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 vga_modeinfo*inf;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 if(vga_init()){printf("oxl: can't init svgalib!\n");exit(0);}
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 /* Finds the best-fitting 256-color videomode */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 for(i=0;i<GLASTMODE;i++){
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 if(vga_hasmode(i)){
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 inf=vga_getmodeinfo(i);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 if((inf->colors==256)&&
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 (inf->width >=BUFW)&&(inf->height>=BUFH)&&
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 (inf->width <=fitw)&&(inf->height<=fith)){
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 fith=SCRH=inf->height;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 fitw=SCRW=inf->width;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 fit=i;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 } } }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 if(!fit){
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 printf("oxl: no suitable modes found.\n");exit(0);}
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 else{
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 printf("oxl: using %s\n",vga_getmodename(fit));
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 vga_setmode(fit);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 #if VIDEO==X11
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 { XSetWindowAttributes att;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 Window rtwin;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 /* get some pointers'n'stuff */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 if(!(oxl_disp=XOpenDisplay(NULL))){
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 perror("oxl: can't open X display!\n");exit(0);}
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 oxl_scr=DefaultScreen(oxl_disp);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 oxl_gc=DefaultGC(oxl_disp,oxl_scr);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 oxl_vis=DefaultVisual(oxl_disp,oxl_scr);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 rtwin=DefaultRootWindow(oxl_disp);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 /* don't store the contents */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 att.backing_store=NotUseful;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 /* allocate a private colormap */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 oxl_pal=XCreateColormap(oxl_disp,rtwin,oxl_vis,AllocAll);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 att.colormap=oxl_pal;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 /* a black emptiness replaces the cursor */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 {XColor blk;Pixmap e;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 blk.red=blk.green=blk.blue=0;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 blk.flags=DoRed+DoGreen+DoBlue;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 e=XCreatePixmap(oxl_disp,rtwin,2,2,1);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 att.cursor=XCreatePixmapCursor(oxl_disp,e,e,&blk,&blk,0,0);}
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 oxl_win=XCreateWindow(
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 oxl_disp,rtwin,
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 0,0,BUFW,BUFH,4,
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 8, /* colordepth */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 InputOutput,
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 oxl_vis,
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 CWBackingStore+CWColormap+CWCursor,&att);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 /* tell the wm you can't resize it */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 {XSizeHints shints;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 shints.min_width= shints.max_width= BUFW;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 shints.min_height=shints.max_height=BUFH;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 shints.flags=PMinSize+PMaxSize;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 /* set the names etc */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 XSetStandardProperties(
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 oxl_disp,oxl_win,
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 WINNAME,WINNAME,
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 None,NULL,0,
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 &shints);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 /* and draw the window */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 XMapWindow(oxl_disp,oxl_win);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 XSync(oxl_disp,False);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 /* create the ximage to be hooked on the frame buffer */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 oxl_im=XCreateImage(oxl_disp,oxl_vis,
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 8,ZPixmap, /* depth, format */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 0,NULL, /* offset, data */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 BUFW,BUFH, /* width, height */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 32,BUFW); /* align bits, bytes per scanline */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 oxl_im->bitmap_unit=32;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 /* some values for the palette */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 {int i;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 for(i=0;i<256;i++){
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 oxl_col[i].flags=DoRed|DoGreen|DoBlue;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 oxl_col[i].pixel=i;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 oxl_col[i].pad=0;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 }}
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 void oxl_init_audio(int rowtix)
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 {
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 #if AUDIO==1
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 int tmp;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 printf("oxl: initing oss..\n");
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 devdsp=open("/dev/dsp",O_WRONLY|O_NDELAY,0);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 ioctl(devdsp,SNDCTL_DSP_SPEED,&AUFREQ);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 tmp=(NUMFRAGS<<16)|FRAGSIZE;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 ioctl(devdsp,SNDCTL_DSP_SETFRAGMENT,&tmp);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 ioctl(devdsp,SNDCTL_DSP_SYNC,0);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 tmp=0;ioctl(devdsp,SNDCTL_DSP_STEREO,&tmp); /* mono */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 tmp=8;ioctl(devdsp,SNDCTL_DSP_SAMPLESIZE,&tmp); /* 8*/
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 audiobuf=malloc((rowtix*AUFREQ/DEMOHZ)*sizeof(char));
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 #if AUDIO==0
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 int klok() /* just an internal clumsie */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 {
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 struct timeval tym;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 gettimeofday(&tym,NULL);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 return (tym.tv_sec*DEMOHZ)+(tym.tv_usec*DEMOHZ/1000000);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 void oxl_init_timer()
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 {
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 #if AUDIO==0
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 baseclock=klok();
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 void oxl_end()
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 {
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 /* These things should be done automatically on exit but
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 let's put them here anyway :) */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 #if AUDIO==1
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 close(devdsp);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 #if VIDEO==vga
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 vga_setmode(TEXT);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 #if VIDEO==X11
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 XCloseDisplay(oxl_disp);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 int oxl_timer()
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 {
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 #if AUDIO==1
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 count_info p;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 ioctl(devdsp,SNDCTL_DSP_GETOPTR,&p);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 return p.bytes/TIKLGT;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 #else
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 return (klok()-baseclock);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 void oxl_doaudio(int*(*player)(void))
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 {
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 #if AUDIO==1
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 audio_buf_info a;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 for(;;){
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 ioctl(devdsp,SNDCTL_DSP_GETOSPACE,&a);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 if(a.fragments<a.fragstotal/2) break;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 {register int i,*s=(*player)(); /* output 8bit */
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 int lgt=*s++;char*d=audiobuf;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 for(i=lgt;i;i--){
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 int x=*s++>>8;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 if(x<0)x=0;else if(x>255)x=255;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 *d++=x;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 write(devdsp,audiobuf,lgt);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 void oxl_setpalette(rgb*pal)
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 {
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 #if VIDEO==vga
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 int *p=(int*)pal,*c;int pp[256*3],i;c=pp;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 for(i=256*3;i;i--)*c++=*p++>>2;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 vga_setpalvec(0,256,pp);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 #if VIDEO==X11
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 { int i;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 rgb*p=pal;XColor *c=oxl_col;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 for(i=256;i;i--){
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 c->red=(p->r<<8);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 c->green=(p->g<<8);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 c->blue=(p->b<<8);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 c++;p++;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 XStoreColors(oxl_disp,oxl_pal,oxl_col,256);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 void oxl_doframe(char *vscr)
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 {
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 #if VIDEO==vga
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 int y0=(SCRH-BUFH)>>1;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 #if VGARETRACE==1
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 vga_waitretrace();
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 if(SCRW==BUFW)
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 vga_drawscansegment(vscr,0,y0,BUFW*BUFH);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 else
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 {
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 int y;char *s=vscr;int x0=(SCRW-BUFW)>>1;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 for(y=y0;y<y0+BUFH;y++){vga_drawscansegment(s,x0,y,BUFW);s+=BUFW;}
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 }
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 #if VIDEO==X11
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 oxl_im->data=vscr;
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 XPutImage(oxl_disp,oxl_win,oxl_gc,oxl_im,-1,-1,0,0,BUFW,BUFH);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 XSync(oxl_disp,False);
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 #endif
0e4f2da58161 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 }