-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatari.c
More file actions
299 lines (263 loc) · 7.18 KB
/
Copy pathatari.c
File metadata and controls
299 lines (263 loc) · 7.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#include <stdio.h>
#include <osbind.h>
#include "tv.h"
#include "rules.h"
#include "midi.h"
#define NEXT_MIDI (unsigned char)Bconin(3)&0xFF
unsigned long _STACK = 20*1024;
short work_in[12],
work_out[57];
short mouse_button, screen_handle;
short mouse_x, mouse_y;
void
cls(void)
{
printf("\033E\nTabula Vigilans:\n");
}
TICK
current_time()
{
register void *savessp = Super(NULL);
register unsigned long timevalue = (unsigned long)*((TICK*)0x4ba);
Super(savessp);
return timevalue;
}
void
gem_init(void)
{
short i;
appl_init();
for (i=1; i<10; work_in[i++]=1);
work_in[0] = Getrez() + 2; /* opens driver for current resolution */
work_in[10]=2; /* choose raster coordinates */
v_opnvwk(work_in, &screen_handle, work_out);
}
void
get_mouse_coords()
{
vq_mouse(screen_handle, &mouse_button, &mouse_x, &mouse_y);
}
unsigned char
get_next_midi(int type, int *valid)
/* type: Return immediately, or stay? */
/* valid: Indicates whether returned with a valid byte */
{
unsigned char inmidi;
do {
if(type == IMMEDIATE) {
if(Bconstat(3)) { /* Only get a byte if it's there */
inmidi = NEXT_MIDI; /* collect next MIDI byte */
}
else { /* No more MIDI in buffer */
inmidi = 0; /* To break out of loop */
*valid = 0; /* Inform calling function not to use 'inmidi' */
}
}
else {
inmidi = NEXT_MIDI; /* STAY for next byte */
}
} while((inmidi & 0xF8) == 0xF8); /* REAL-TIME */
return(inmidi);
}
int
midiin(struct statement *s, struct cell *locals, void **dp)
{
struct exprlist *data = s->el;
static unsigned char last_status = 0;
unsigned char midibyte;
int note_received = NOTHING;
int more_to_get = 1;
int valid = 1;
while(more_to_get) {
if(Bconstat(3)) { /* If there's MIDI present */
midibyte = get_next_midi(IMMEDIATE,&valid); /* Fetch the byte */
if(valid) { /* If there's still a valid byte there */
if(midibyte >= 128) { /* It's a STATUS byte */
last_status = midibyte;
if((midibyte&0xE0) == 0x80) { /* Note Event */
note_received = NOTE_EVENT;
LGVAR(data->e,locals)->u.d = (double)(midibyte&0x0F);
data = data->next;
LGVAR(data->e,locals)->u.d = (double)get_next_midi(STAY,&valid);
data = data->next;
LGVAR(data->e,locals)->u.d = (double)get_next_midi(STAY,&valid);
}
else if((midibyte&0xF0) == 0xD0) { /* Aftertouch */
note_received = AFTERTOUCH;
LGVAR(data->e,locals)->u.d = (double)(midibyte&0x0F);
data = data->next;
LGVAR(data->e,locals)->u.d = (double)get_next_midi(STAY,&valid);
}
else if((midibyte&0xF0) == 0xB0) { /* Controller Info */
note_received = CONTROLLER;
LGVAR(data->e,locals)->u.d = (double)(midibyte&0x0F);
data = data->next;
LGVAR(data->e,locals)->u.d = (double)get_next_midi(STAY,&valid);
data = data->next;
LGVAR(data->e,locals)->u.d = (double)get_next_midi(STAY,&valid);
}
}
else { /* This is a DATA BYTE */
if((last_status&0xE0) == 0x80) { /* Last Status was Note Event */
note_received = NOTE_EVENT;
LGVAR(data->e,locals)->u.d = (double)(last_status&0x0F);
data = data->next;
LGVAR(data->e,locals)->u.d = (double)midibyte;
data = data->next;
LGVAR(data->e,locals)->u.d = (double)get_next_midi(STAY,&valid);
}
else if((last_status&0xF0) == 0xD0) {/* Last Status was Aftertouch */
note_received = AFTERTOUCH;
LGVAR(data->e,locals)->u.d = (double)(last_status&0x0F);
data = data->next;
LGVAR(data->e,locals)->u.d = (double)midibyte;
}
else if((last_status&0xF0) == 0xB0) { /* Last Status was Controller */
note_received = CONTROLLER;
LGVAR(data->e,locals)->u.d = (double)(last_status&0x0F);
data = data->next;
LGVAR(data->e,locals)->u.d = (double)midibyte;
data = data->next;
LGVAR(data->e,locals)->u.d = (double)get_next_midi(STAY,&valid);
}
}
}
if(note_received != NOTHING) { /* If event received */
more_to_get = 0; /* Stop now - we've got a note event */
if((last_status&0xF0) == 0x80) { /* If 'twas a Note */
data = data->next;
data = data->next;
LGVAR(data->e,locals)->u.d = (double)0.;
/* Turn any note OFF's into velocity 0 */
}
}
}
else more_to_get = 0; /* Stop now, as there's no more MIDI */
}
return note_received;
}
void
perf_time(int report) /* stores time of performance */
{
double secs;
unsigned long mins = 0L, hours = 0L, days = 0L;
register unsigned long timevalue = current_time();
static short first = TRUE;
static unsigned long start_systime;
if(first) {
start_systime = timevalue;
first = FALSE;
}
if(report) {
secs = (double)(timevalue - start_systime)/(double)TICKSPERSEC;
mins = 0.5 + (long)(secs/60.0);
secs -= mins * 60;
if(mins > 60) {
hours = mins/60;
mins %= 60;
}
if(hours > 24) {
days = hours/24;
hours %= 24;
}
if(days) {
if(days == 1) {
if(hours == 1)
printf("\nPerformance Time: %3ld day, %2ld hr. %2ld' %.2lf\"\n",
days, hours, mins, secs);
else printf("\nPerformance Time: %3ld day, %2ld hrs. %2ld' %.2lf\"\n",
days, hours, mins, secs);
} else {
if(hours == 1)
printf("\nPerformance Time: %3ld days, %2ld hr. %2ld' %.2lf\"\n",
days, hours, mins, secs);
else printf("\nPerformance Time: %3ld days, %2ld hrs. %2ld' %.2lf\"\n",
days, hours, mins, secs);
}
}
else if(hours) {
if(hours == 1)
printf("\nPerformance Time: %2ld hr. %2ld' %.2lf\"\n",
hours, mins, secs);
else printf("\nPerformance Time: %2ld hrs. %2ld' %.2lf\"\n",
hours, mins, secs);
}
else if(mins)
printf("\nPerformance Time: %2ld' %.2lf\"\n",
mins, secs);
else
printf("\nPerformance Time: %.2lf\"\n", secs);
}
}
void
inits(void)
{
Cursconf(0,0);
gem_init();
while(Bconstat(2))Bconin(2);
/* Clear keyboard buffer of any previously typed characters */
srand48(Gettime());
}
void
mach_cleanup()
{
Cursconf(1, 1);
}
/*
* midi support routines
*/
void
control_out(int channel, int data1, int data2)
{
unsigned char buf[3];
buf[0] = 0xB0 + (unsigned char)channel;
buf[1] = (unsigned char)data1;
buf[2] = (unsigned char)data2;
Midiws(2, buf);
}
void
midiopen()
{
while(Bconstat(3))Bconin(3);
/* Clear MIDI buffer of any spurious notes */
/* nothing else to do on the Atari */
}
void
midiclose()
{
unsigned char buf[3];
int i;
for(i = 0; i < 16; i++)
{
buf[0] = 0xB0 + i; /* ALL NOTES OFF */
buf[1] = 0x7B;
buf[2] = 0;
Midiws(2, buf);
}
}
void
midiout(struct midi_event *m)
{
unsigned char buf[3];
buf[0] = 0x90 + m->channel;
buf[1] = m->note;
buf[2] = m->velocity;
Midiws(2, buf);
}
void
midiset(int channel, int instr)
{
unsigned char buf[2];
buf[0] = 0xc0 + (unsigned char)channel;
buf[1] = (unsigned char)instr;
Midiws(1, buf);
}
void
pitchbend(int channel, int bend)
{
unsigned char buf[3];
buf[0] = 0xE0 + (unsigned char)channel;
buf[1] = (unsigned char)0;
buf[2] = (unsigned char)bend;
Midiws(2, buf);
}