gfx.c
15.4 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
/*====================================================================
* gfx.c
*
* Synopsis:
*
* This code implements the application graphics stuff
*
*
*
* Copyright 1993, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
* Inc.; the contents of this file may not be disclosed to third
* parties, copied or duplicated in any form, in whole or in part,
* without the prior written permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights
* in Technical Data and Computer Software clause at DFARS
* 252.227-7013, and/or in similar or successor clauses in the FAR,
* DOD or NASA FAR Supplement. Unpublished - rights reserved under the
* Copyright Laws of the United States.
*====================================================================*/
#include <ultralog.h>
#include <libaudio.h>
#include <string.h>
#include "stats.h"
#include "gfx.h"
extern OSSched sc;
extern OSMesgQueue *sched_cmdQ;
extern OSMesgQueue gfxFrameMsgQ;
extern s16 peaksL[],peaksR[];
extern OSTime rspTimes[];
extern OSTime cpuTimes[];
extern s32 usedVoices[];
extern s32 maxUsedVcs;
extern s16 rspTimeCt,cpuTimeCt,usedVsCt;
extern u32 frameClockFactor;
extern u32 numAudCmds[];
extern u32 numDMAs[];
extern u32 numDMABufs[];
extern u32 numSynUpds[];
extern u32 numSeqEvts[];
extern u32 maxAudCmds;
extern u32 maxDMAs;
extern u32 maxDMABufs;
extern u32 maxSynUpds;
extern u32 maxSeqEvts;
extern ALSeqPlayer seqPlayer;
/*
* graphics globals
*/
GFXInfo gInfo[2];
Gfx *glistp;
void doStats(Dynamic *dynamicp);
void setNumVal(char *str, u32 index, u32 val);
static Gfx * doMeters (Gfx *);
static Gfx * doMeter (Gfx *, int dbPix, char clipped, int l, int t, int r, int b);
static Gfx * frameRectangle (Gfx *, int l, int t, int r, int b);
static int mag2dBpixels (int mag, char * pClip);
#define NUM_TSTRINGS 29
char *messStr[] =
{
"offline",
"cmds 00000 00000",
"DMAs 00000 00000",
"DMA bufs 00000 00000",
"syn upds 00000 00000",
"seq evts 00000 00000",
"RSP",
"CPU",
"Vcs",
"L",
"R",
"48",
"24",
"0",
"1",
".5",
"0",
"1",
".5",
"0",
"00000",
"0", "6", "12", "18", "24", "30", "36", "42"
};
u32 scrn_cood[NUM_TSTRINGS][2] =
{
STATE_STR_LEFT, STATE_STR_TOP,
CMMD_STR_LEFT, CMMD_STR_TOP,
DMAS_STR_LEFT, DMAS_STR_TOP,
DMAB_STR_LEFT, DMAB_STR_TOP,
UPDS_STR_LEFT, UPDS_STR_TOP,
EVTS_STR_LEFT, EVTS_STR_TOP,
RSP_STR_LEFT, RSP_STR_TOP,
CPU_STR_LEFT, CPU_STR_TOP,
VCS_STR_LEFT, VCS_STR_TOP,
L_STR_LEFT, L_STR_TOP,
R_STR_LEFT, R_STR_TOP,
MAX_VX_SCL_LEFT, MAX_VX_SCL_TOP,
MID_VX_SCL_LEFT, MID_VX_SCL_TOP,
MIN_VX_SCL_LEFT, MIN_VX_SCL_TOP,
MAX_RSP_SCL_LEFT, MAX_RSP_SCL_TOP,
MID_RSP_SCL_LEFT, MID_RSP_SCL_TOP,
MIN_RSP_SCL_LEFT, MIN_RSP_SCL_TOP,
MAX_CPU_SCL_LEFT, MAX_CPU_SCL_TOP,
MID_CPU_SCL_LEFT, MID_CPU_SCL_TOP,
MIN_CPU_SCL_LEFT, MIN_CPU_SCL_TOP,
MAX_VCS_STR_LEFT, MAX_VCS_STR_TOP,
SCALE_CENTER+3, SCALE_TOP, /* adjust by 3 for single digit */
SCALE_CENTER+3, SCALE_TOP + SIX_DB_PIX, /* adjust by 3 for single digit */
SCALE_CENTER, SCALE_TOP + 2*SIX_DB_PIX,
SCALE_CENTER, SCALE_TOP + 3*SIX_DB_PIX,
SCALE_CENTER, SCALE_TOP + 4*SIX_DB_PIX,
SCALE_CENTER, SCALE_TOP + 5*SIX_DB_PIX,
SCALE_CENTER, SCALE_TOP + 6*SIX_DB_PIX,
SCALE_CENTER, SCALE_TOP + 7*SIX_DB_PIX
};
void initGFX(void)
{
u32 cfbPtr;
cfbPtr = (u32)cfb_16_a;
cfbPtr = ((cfbPtr + 0x3F) & ~0x3F);
gInfo[0].cfb = (unsigned short*)cfbPtr;
cfbPtr = (u32)cfb_16_b;
cfbPtr = ((cfbPtr + 0x3F) & ~0x3F);
gInfo[1].cfb = (unsigned short*)cfbPtr;
gInfo[1].msg.gen.type = OS_SC_DONE_MSG;
gInfo[0].msg.gen.type = OS_SC_DONE_MSG;
/* The Vi manager was started by scheduler by this point in time */
osViSetSpecialFeatures(OS_VI_DITHER_FILTER_ON);
}
void createGfxTask(GFXInfo *i)
{
static int firsttime = 1;
Dynamic *dynamicp;
OSScTask *t;
/**** pointers to build the display list. ****/
dynamicp = &i->dp;
glistp = i->dp.glist;
/**** Tell RCP where each segment is ****/
gSPSegment(glistp++, 0, 0); /* physical addressing segment */
/**** Graphics pipeline state initialization ****/
gSPDisplayList(glistp++, setup_rspstate);
if (firsttime) {
gSPDisplayList(glistp++, rdpstateinit_dl);
firsttime = 0;
}
gSPDisplayList(glistp++, setup_rdpstate);
/**** clear zbuffer, z = max z, dz = 0 ****/
gDPPipeSync(glistp++);
gDPSetCycleType(glistp++, G_CYC_FILL);
/**** Clear framebuffer cvg = FULL or 1 ****/
gDPPipeSync(glistp++);
gDPSetColorImage(glistp++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WD,
osVirtualToPhysical(i->cfb));
/* clearcolor is 32-bits (2 pixels wide) because fill mode
* does two pixels at a time.
*/
gDPSetFillColor(glistp++, (GPACK_RGBA5551(0, 0, 0, 1) << 16 |
GPACK_RGBA5551(0, 0, 0, 1)));
gDPFillRectangle(glistp++, 0, 0, SCREEN_WD-1, SCREEN_HT-1);
gDPPipeSync(glistp++);
/**** Draw objects */
doStats(dynamicp);
/**** Put an end on the top-level display list ****/
gDPFullSync(glistp++);
gSPEndDisplayList(glistp++);
/* Flush the dynamic segment */
osWritebackDCacheAll();
/* build graphics task */
t = &i->task;
t->list.t.data_ptr = (u64 *) dynamicp->glist;
t->list.t.data_size = (s32)(glistp - dynamicp->glist) * sizeof (Gfx);
t->list.t.type = M_GFXTASK;
t->list.t.flags = 0x0;
t->list.t.ucode_boot = (u64 *)rspbootTextStart;
t->list.t.ucode_boot_size = ((s32) rspbootTextEnd -
(s32) rspbootTextStart);
t->list.t.ucode = (u64 *) gspFast3DTextStart;
t->list.t.ucode_data = (u64 *) gspFast3DDataStart;
t->list.t.ucode_data_size = SP_UCODE_DATA_SIZE;
t->list.t.dram_stack = (u64 *) dram_stack;
t->list.t.dram_stack_size = SP_DRAM_STACK_SIZE8;
t->list.t.output_buff = (u64 *) 0x0;
t->list.t.output_buff_size = (u64 *) 0x0;
t->list.t.yield_data_ptr = (u64 *) gfxYieldBuf;
t->list.t.yield_data_size = OS_YIELD_DATA_SIZE;
t->next = 0; /* paranoia */
t->flags = (OS_SC_NEEDS_RSP | OS_SC_NEEDS_RDP | OS_SC_LAST_TASK |
OS_SC_SWAPBUFFER);
t->msgQ = &gfxFrameMsgQ; /* reply to when finished */
t->msg = (OSMesg)&i->msg; /* reply with this message */
t->framebuffer = (void *)i->cfb;
t->d.gd.endTicks = 0;
t->d.gd.numYields = 0;
osSendMesg(sched_cmdQ, (OSMesg) t, OS_MESG_BLOCK);
}
Gfx setup_font[] = {
gsSPTexture (0x8000, 0x8000, 0, G_TX_RENDERTILE, G_ON),
gsDPPipeSync(),
gsSPClearGeometryMode(G_SHADE | G_SHADING_SMOOTH | G_CULL_BOTH |
G_FOG | G_LIGHTING | G_LOD ),
gsDPSetRenderMode (G_RM_OPA_SURF, G_RM_OPA_SURF2),
gsDPSetCombineMode (G_CC_DECALRGB, G_CC_DECALRGB),
gsDPSetTexturePersp (G_TP_NONE),
gsDPSetTextureFilter (G_TF_POINT),
gsDPPipeSync(),
gsSPEndDisplayList(),
};
#include "font4bI.c"
void doStats(Dynamic *dynamicp)
{
s32 c, left, top, right;
u32 index;
static u32 fct = 0;
u32 mCt;
u8 mChar;
u32 tile_left, tile_top, tile_right, tile_bottom;
u32 scrn_left, scrn_top;
u32 str_scrn_left, str_scrn_top;
u32 s;
u32 messageCt = 0;
char *messageSt;
u32 val;
gDPPipeSync(glistp++);
gDPSetCycleType(glistp++, G_CYC_1CYCLE);
gDPSetPrimColor(glistp++, 0, 0, 120, 120, 120, 255);
gDPSetCombineMode(glistp++, G_CC_PRIMITIVE, G_CC_PRIMITIVE);
gDPSetRenderMode(glistp++, G_RM_OPA_SURF, G_RM_OPA_SURF2);
/* draw rsp and cpu backgrounds */
gDPFillRectangle(glistp++, RSP_LEFT, RSP_TOP, RSP_RIGHT, RSP_BASE);
gDPFillRectangle(glistp++, CPU_LEFT, CPU_TOP, CPU_RIGHT, CPU_BASE);
gDPFillRectangle(glistp++, VOX_LEFT, VOX_TOP, VOX_RIGHT, VOX_BASE);
glistp = doMeters (glistp);
gDPSetPrimColor(glistp++, 0, 0, 0, 240, 0, 255);
index = cpuTimeCt;
for(c = 0; c < NUM_TIMES; c++, index++)
{
if(index == NUM_TIMES)
index = 0;
left = CPU_RIGHT - ( c * BAR_WIDTH ) - BAR_WIDTH;
right = left + BAR_WIDTH;
top = CPU_BASE - ((u32)cpuTimes[index] / frameClockFactor);
gDPFillRectangle(glistp++, left, top, right, CPU_BASE);
}
index = rspTimeCt;
for(c = 0; c < NUM_TIMES; c++, index++)
{
if(index == NUM_TIMES)
index = 0;
left = RSP_RIGHT - ( c * BAR_WIDTH ) - BAR_WIDTH;
right = left + BAR_WIDTH;
top = RSP_BASE - (u32)(rspTimes[index] /frameClockFactor );
gDPFillRectangle(glistp++, left, top, right, RSP_BASE);
}
index = usedVsCt;
for(c = 0; c < NUM_TIMES; c++, index++)
{
if(index == NUM_TIMES)
index = 0;
if(usedVoices[index])
{
left = VOX_RIGHT - ( c * BAR_WIDTH ) - BAR_WIDTH;
right = left + BAR_WIDTH;
top = VOX_BASE - usedVoices[index];
gDPFillRectangle(glistp++, left, top, right, VOX_BASE);
}
}
gSPDisplayList(glistp++, setup_font);
for(s = 0; s < NUM_TSTRINGS; s++)
{
switch(s)
{
case 0:
if (alSeqpGetState (&seqPlayer) == AL_PLAYING)
strcpy(messStr[s], "online");
else
strcpy(messStr[s], "offline");
break;
case 1: /* commands string */
for(val = 0, c = 0; c < MAX_PROF_CT; c++)
if(numAudCmds[c] > val)
val = numAudCmds[c];
if(val > maxAudCmds)
maxAudCmds = val;
setNumVal(messStr[s], 5, val);
setNumVal(messStr[s], 11, maxAudCmds);
break;
case 2: /* number dma's */
for(val = 0, c = 0; c < MAX_PROF_CT; c++)
if(numDMAs[c] > val)
val = numDMAs[c];
if(val > maxDMAs)
maxDMAs = val;
setNumVal(messStr[s], 5, val);
setNumVal(messStr[s], 11, maxDMAs);
break;
case 3: /* number DMA Bufs */
for(val = 0, c = 0; c < MAX_PROF_CT; c++)
if(numDMABufs[c] > val)
val = numDMABufs[c];
if(val > maxDMABufs)
maxDMABufs = val;
setNumVal(messStr[s], 9, val);
setNumVal(messStr[s], 15, maxDMABufs);
break;
case 4: /* number synth updates used */
for(val = 0, c = 0; c < MAX_PROF_CT; c++)
if(numSynUpds[c] > val)
val = numSynUpds[c];
if(val > maxSynUpds)
maxSynUpds = val;
setNumVal(messStr[s], 9, val);
setNumVal(messStr[s], 15, maxSynUpds);
break;
case 5: /* number seq events used */
for(val = 0, c = 0; c < MAX_PROF_CT; c++)
if(numSeqEvts[c] > val)
val = numSeqEvts[c];
if(val > maxSeqEvts)
maxSeqEvts = val;
setNumVal(messStr[s], 9, val);
setNumVal(messStr[s], 15, maxSeqEvts);
break;
case 20: /* maxUsedVcs rectangle and string */
gDPSetPrimColor(glistp++, 0, 0, 0, 0, 0, 255);
gDPFillRectangle(glistp++, MAX_VCS_CT_LEFT, MAX_VCS_CT_TOP,
MAX_VCS_CT_RIGHT, MAX_VCS_CT_BASE);
gDPPipeSync(glistp++);
setNumVal(messStr[s], 0, maxUsedVcs);
break;
}
str_scrn_left = scrn_cood[s][0];
str_scrn_top = scrn_cood[s][1];
messageSt = messStr[s];
for(mCt = 0; messageSt[mCt] != 0; mCt++)
{
mChar = messageSt[mCt];
if(mChar != ' ')
{
mChar -= '!';
tile_left = (mChar%8) * 7;
tile_top = (mChar/8) * 11;
tile_right = tile_left + 7;
tile_bottom = tile_top + 11;
scrn_left = ((mCt%28) * 7) + str_scrn_left;
scrn_top = ((mCt/28) * 11) + str_scrn_top;
gDPLoadTextureTile_4b (glistp++, font_tx, G_IM_FMT_I, 64, 192,
tile_left, tile_top, tile_right, tile_bottom, 0,
G_TX_WRAP | G_TX_NOMIRROR, G_TX_WRAP | G_TX_NOMIRROR,
G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
if(mChar == ('n' - '!'))
tile_left += 1;
gDPLoadSync(glistp++);
gSPTextureRectangle(glistp++, (scrn_left<<2), (scrn_top<<2),
((scrn_left+7)<<2), ((scrn_top+11)<<2),
G_TX_RENDERTILE, (tile_left << 5), (tile_top << 5),
(1 << 10), (1 << 10));
gDPPipeSync(glistp++);
}
}
/* messageCt--; */
}
}
void setNumVal(char *str, u32 index, u32 val)
{
str[index++] = (val / 10000) + '0';
val = val % 10000;
str[index++] = (val / 1000) + '0';
val = val % 1000;
str[index++] = (val / 100) + '0';
val = val % 100;
str[index++] = (val / 10) + '0';
val = val % 10;
str[index++] = val + '0';
}
#define kMeterFramePix 1
#define kLEDSeparaterPix 2
#define kMeterLEDs 14
#define kMeterHeightPix (PEAK_BASE - PEAK_TOP - 2*kMeterFramePix)
#define kLEDHeightPix (kMeterHeightPix/kMeterLEDs - kLEDSeparaterPix)
#define k3DBPix (kMeterHeightPix - kLEDHeightPix)
static Gfx *
doMeters (Gfx * p)
{
s16 peakL = 0, peakR = 0;
char clipL, clipR;
s32 c;
for(c = 0; c < NUM_PEAKS; c++)
{
if(peakL < peaksL[c])
peakL = peaksL[c];
if(peakR < peaksR[c])
peakR = peaksR[c];
}
peakL = mag2dBpixels (peakL, &clipL);
peakR = mag2dBpixels (peakR, &clipR);
p = doMeter (p, peakL, clipL, PEAKL_LEFT, PEAK_TOP, PEAKL_RIGHT, PEAK_BASE);
p = doMeter (p, peakR, clipR, PEAKR_LEFT, PEAK_TOP, PEAKR_RIGHT, PEAK_BASE);
return p;
}
static Gfx *
doMeter (Gfx * p, int dBPix, char clipped,
int meterLeft, int meterTop, int meterRight, int meterBottom)
{
s32 ledBottom, ledTop;
s32 c;
/* the the clip LED (if clipped) */
if (clipped)
{
gDPSetPrimColor (p++, 0, 0, 255, 0, 0, 255);
gDPFillRectangle (p++, meterLeft+1, CLIP_TOP, meterRight-1, CLIP_BOTTOM);
}
/* draw the lighted LEDs in one fill command, then segment into LEDs below */
gDPSetPrimColor (p++, 0, 0, 0, 240, 0, 255);
gDPFillRectangle (p++, meterLeft+1, meterBottom-dBPix,
meterRight-1, meterBottom);
/* draw the 3 dB caution LED */
if (dBPix > k3DBPix)
{
gDPSetPrimColor (p++, 0, 0, 120, 120, 0, 255);
gDPFillRectangle (p++, meterLeft+1, meterBottom-dBPix,
meterRight-1, meterBottom-k3DBPix);
}
/* draw the frame for the meter */
gDPSetPrimColor (p++, 0, 0, 120, 120, 120, 255);
p = frameRectangle (p, meterLeft, meterTop, meterRight, meterBottom);
/* draw the LED separaters */
ledBottom = meterBottom;
for (c=0; c<kMeterLEDs+1; c++)
{
gDPFillRectangle (p++, meterLeft+1, ledBottom-kLEDSeparaterPix,
meterRight-1, ledBottom);
ledBottom -= kLEDHeightPix + kLEDSeparaterPix;
}
return p;
}
static Gfx *
frameRectangle (Gfx * p, int left, int top, int right, int bottom)
{
gDPFillRectangle(p++, left, top, right, top+1);
gDPFillRectangle(p++, left, top, left+1, bottom);
gDPFillRectangle(p++, left, bottom-1, right, bottom);
gDPFillRectangle(p++, right-1, top, right, bottom);
return p;
}
static int
mag2dBpixels (int mag, char * pClip)
{
#define kdBResolution 7 /* 7 bits */
int dBPix, dBInc = kMeterHeightPix/kdBResolution;
unsigned char magByte = mag >> 8;
for (dBPix = 0; dBPix < kMeterHeightPix; dBPix += dBInc)
{
if ((magByte <<= 1) & 0x80)
{
while (dBInc)
{
dBInc >>= 1;
if (!((magByte <<= 1) & 0x80))
dBPix += dBInc;
}
break;
}
}
if (dBPix > kMeterHeightPix)
dBPix = kMeterHeightPix;
dBPix = kMeterHeightPix - dBPix;
#if DEBUG_METER
if (dBPix > 0 && mag > 0)
osSyncPrintf ("mag = %d, dB = %d\n", mag, dBPix);
#endif
/* indicate signal presence by lighting up bottom LED */
if (dBPix < kLEDHeightPix + kLEDSeparaterPix && mag > 0)
dBPix = kLEDHeightPix + kLEDSeparaterPix;
/* indicate signal clipping if all bits are set */
*pClip = FALSE;
if (mag == 0x7fff)
*pClip = TRUE;
return dBPix;
}