OpenCores
URL https://opencores.org/ocsvn/thor/thor/trunk

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64/] [software/] [boot/] [BIOSMain.c] - Blame information for rev 54

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 45 robfinch
#define BTNC    16
2
#define BTNU    8
3
#define BTND    4
4
#define BTNL    2
5
#define BTNR    1
6
#define AVIC    ((unsigned __int32 *)0xFFDCC000)
7
 
8
// By declaring the function with the __no_temps attribute it tells the
9
// compiler that the function doesn't use any temporaries. That means
10
// the compiler can omit the code to save / restore temporary registers
11
// across function calls. This makes the code smaller and faster.
12
// This is not usually safe to do unless the function was coded
13
// entirely in assembler where it is known no temporaries are in use.
14
extern int GetRand(register int stream) __attribute__(__no_temps);
15
extern __int32 DBGAttr;
16
extern void DBGClearScreen();
17
extern void DBGHomeCursor();
18
extern void putch(register char);
19
extern int printf(char *, ...);
20
extern pascal int prtflt(register float, register int, register int, register char);
21
extern void ramtest();
22
extern void FloatTest();
23
extern void DBGDisplayString(char *p);
24
extern void puthex(register int num);
25
void SpriteDemo();
26
 
27
extern int randStream;
28
 
29
void interrupt DBERout()
30
{
31
        int nn;
32
 
33
        DBGDisplayString("\r\nDatabus error: ");
34
        puthex(GetEPC());
35
        putch(' ');
36
        puthex(GetBadAddr());
37
        putch(' ');
38
        for (nn = 63; nn >= 0; nn--) {
39
                SetPCHNDX(nn);
40
                puthex(ReadPCHIST());
41
                putch(' ');
42
        }
43
        forever {}
44
}
45
 
46
static naked inline void LEDS(register int n)
47
{
48
        asm {
49
                sh              $a0,$FFDC0600
50
        }
51
}
52
 
53
static naked inline int GetButton()
54
{
55
        asm {
56
                lb              $v0,BUTTONS
57
        }
58
}
59
 
60
void BIOSMain()
61
{
62
        float pi = 3.1415926535897932384626;
63
        // 400921FB54442D18 
64
        float a,b;
65
        int btn;
66
        int seln=0;
67
 
68
        LEDS(1);
69
//      SpriteDemo();
70
        DBGAttr = 0x087FC00;//0b0000_1000_0111_1111_1100_0000_0000;
71
        DBGClearScreen();
72
        DBGHomeCursor();
73
        DBGDisplayString("  FT64 Bios Started\r\n");
74
        DBGDisplayString("  Menu\r\n  up = ramtest\r\n  down = graphics demo\r\n  left = float test\r\n  right=TinyBasic\r\n");
75
        forever {
76
                //0b0000_1000_0111_1111_1100_0000_0000;
77
                //0b1111_1111_1000_0100_0000_0000_0000;
78
                btn = GetButton();
79
                switch(btn) {
80
                case BTND:
81
                        while(GetButton());
82
                        SpriteDemo();
83
                        break;
84
                case BTNU:
85
                        while(GetButton());
86
                        ramtest();
87
                        break;
88
                case BTNL:
89
                        while(GetButton());
90
                        FloatTest();
91
                        break;
92
                case BTNR:
93
                        while(GetButton());
94
                        asm {
95
                                jmp     TinyBasicDSD9
96
                        };
97
                        break;
98
                }
99
        }
100
}
101
 
102
static naked inline int GetEPC()
103
{
104
        asm {
105
                csrrd   $v0,#$40,$r0
106
        }
107
}
108
 
109
static naked inline int GetBadAddr()
110
{
111
        asm {
112
                csrrd   $v0,#7,$r0
113
                sh              $v0,$FFDC0080
114
        }
115
}
116
 
117
static naked inline void SetPCHNDX(register int nn)
118
{
119
        asm {
120
                csrrw   $r0,#$101,$a0
121
        }
122
}
123
 
124
static naked inline int ReadPCHIST()
125
{
126
        asm {
127
                csrrd   $v0,#$100,$r0
128
        }
129
}
130
 
131
void interrupt BTNCIRQHandler()
132
{
133
        int nn;
134
 
135
        asm {
136
                ldi             r1,#30
137
                sh              r1,PIC_ESR
138
        }
139
        DBGDisplayString("\r\nPC History:\r\n");
140
        for (nn = 63; nn >= 0; nn--) {
141
                SetPCHNDX(nn);
142
                puthex(ReadPCHIST());
143
                putch(' ');
144
        }
145
}
146
 
147
void interrupt IBERout()
148
{
149
        int nn;
150
 
151
        DBGDisplayString("\r\nInstruction Bus Error:\r\n");
152
        DBGDisplayString("PC History:\r\n");
153
        for (nn = 63; nn >= 0; nn--) {
154
                SetPCHNDX(nn);
155
                puthex(ReadPCHIST());
156
                putch(' ');
157
        }
158
        forever {}
159
}
160
 
161
 
162
// Wait for num queue entry slots to be available.
163
// Returns:
164
//      r1 = number of entries in queue
165
 
166
int GrWaitQue(register int num)
167
{
168
        asm {
169
                sub             $sp,$sp,#16
170
                sw              $v1,[$sp]
171
                sw              $r6,8[$sp]
172
                ldi             $r6,#$FFDCC000
173
                neg             $v1,$a0
174
                add             $v1,$v1,#1020
175
.0001:
176
                lhu             $v0,$6E8[r6]
177
                bgt             $v0,$v1,.0001
178
                lw              $v1,[$sp]
179
                lw              $r6,8[$sp]
180
                add             $sp,$sp,#16
181
        }
182
}
183
 
184
// GrQueCmd
185
//    Place a command in the graphics command queue.
186
// Parameters:
187
//      val             data for command
188
//      cmd             command number
189
// Returns:
190
//      nothing
191
 
192
void GrQueCmd(register int val, register int cmd)
193
{
194
        asm {
195
                sub             $sp,$sp,#8
196
                sw              $r6,[$sp]
197
                ldi             $r6,#$FFDCC000
198
                sh              $a0,$6E0[$r6]           ; set value
199
                sh              $a1,$6E4[$r6]           ; set command
200
                sh              $r0,$6E8[$r6]           ; queue
201
                lw              $r6,[$sp]
202
                add             $sp,$sp,#8
203
        }
204
}
205
 
206
void GrResetCmdQue()
207
{
208
        GrQueCmd(0,254);
209
}
210
 
211
// Send four NOP commands to the command queue.
212
void GrFlushCmdQue()
213
{
214
        int nn;
215
 
216
        GrWaitQue(4);
217
        for (nn = 0; nn < 4; nn++)
218
                GrQueCmd(0,255);
219
}
220
 
221
// GrPlotPoint
222
//    Plot a point.
223
//
224
// Parameters:
225
//      x               x position as a fixed point 16.16 number
226
//      y               y position as a fixed point number
227
//      color   15 bit RGB555 color
228
//  alpha       16 bit alpha value as fraction of one 0xFFFF = 1, 0x0000 = 0
229
// Returns:
230
//      nothing
231
 
232
void GrPlotPoint(int x, int y, int color, int alpha)
233
{
234
        GrWaitQue(5);
235
        GrQueCmd(color & 0x7fff, 12);   // set pen color
236
        GrQueCmd(alpha & 0xffff, 14);   // set alpha value
237
        GrQueCmd(x,16);                 // set x0 pos
238
        GrQueCmd(y,17);                 // set y0 pos
239
        GrQueCmd(0x10,1);                               // plot point
240
}
241
 
242
void GrDrawLine(int x0, int y0, int x1, int y1, int color, int alpha)
243
{
244
        GrWaitQue(7);
245
        GrQueCmd(color & 0x7fff, 12);   // set pen color
246
        GrQueCmd(alpha & 0xffff, 14);   // set alpha value
247
        GrQueCmd(x0,16);                        // set x0 pos
248
        GrQueCmd(y0,17);                        // set y0 pos
249
        GrQueCmd(x1,19);                        // set x1 pos
250
        GrQueCmd(y1,20);                        // set y1 pos
251
        GrQueCmd(0x10,2);                               // draw line
252
}
253
 
254
// Plot some points on the screen in random colors.
255
 
256
void RandomPoints()
257
{
258
        int nn;
259
        int x, y, color;
260
 
261
        randStream = 0;
262
        for (nn = 0; nn < 10000; nn++) {
263
                color = GetRand(randStream) & 0x7fff;
264
                x = (GetRand(randStream) % 400) + 128;
265
                y = (GetRand(randStream) % 300) + 14;
266
                GrPlotPoint(x<<16,y<<16,color,-1);
267
        }
268
}
269
 
270
void RandomLines()
271
{
272
        int nn;
273
        int x0,y0,x1,y1;
274
        int color;
275
 
276
        randStream = 0;
277
        for (nn = 0; nn < 20000; nn++) {
278
                color = GetRand(randStream) & 0x7fff;
279
                x0 = (GetRand(randStream) % 400) + 128;
280
                y0 = (GetRand(randStream) % 300) + 14;
281
                x1 = (GetRand(randStream) % 400) + 128;
282
                y1 = (GetRand(randStream) % 300) + 14;
283
                GrDrawLine(x0<<16,y0<<16,x1<<16,y1<<16,color,-1);
284
        }
285
}
286
 
287
void GrFillRect(int x0, int y0, int x1, int y1, int color)
288
{
289
        GrWaitQue(6);
290
        GrQueCmd(color & 0x7fff, 13);   // set fill color
291
        GrQueCmd(x0,16);                        // set x0 pos
292
        GrQueCmd(y0,17);                        // set y0 pos
293
        GrQueCmd(x1,19);                        // set x1 pos
294
        GrQueCmd(y1,20);                        // set y1 pos
295
        GrQueCmd(0x10,3);                       // fill rect
296
}
297
 
298
void RandomRects()
299
{
300
        int nn;
301
        int x0, y0, x1, y1, color;
302
 
303
        randStream = 0;
304
        for (nn = 0; nn < 1000; nn++) {
305
                color = GetRand(randStream) & 0x7fff;
306
                x0 = (GetRand(randStream) % 400) + 128;
307
                y0 = (GetRand(randStream) % 300) + 14;
308
                x1 = (GetRand(randStream) % 400) + 128;
309
                y1 = (GetRand(randStream) % 300) + 14;
310
                GrFillRect(x0<<16,y0<<16,x1<<16,y1<<16,color);
311
        }
312
}
313
 
314
void GrDrawChar(int x, int y, int ch)
315
{
316
        GrWaitQue(5);
317
        GrQueCmd(0x7FFF, 12);   // set pen color
318
        GrQueCmd(0x000F, 13);   // set fill color
319
        GrQueCmd(x,16);                 // set x0 pos
320
        GrQueCmd(y,17);                 // set y0 pos
321
        GrQueCmd(ch,0);                  // text blit
322
}
323
 
324
void RandomChars()
325
{
326
        int nn, ch;
327
        int x0, y0;
328
 
329
        randStream = 0;
330
 
331
        y0 = 128;
332
        ch = 'A';
333
        GrWaitQue(2);
334
        GrQueCmd(0x7FFF, 12);   // set pen color
335
        GrQueCmd(0x000F, 13);   // set fill color
336
        for (x0 = 128; x0 < 500; x0 += 10) {
337
                GrWaitQue(3);
338
                GrQueCmd(x0<<16,16);
339
                GrQueCmd(y0<<16,17);
340
                GrQueCmd(ch,0);
341
                ch++;
342
        }
343
        /*
344
        for (nn = 0; nn < 10000; nn++) {
345
                x0 = (GetRand(randStream) % 512) + 128;
346
                y0 = (GetRand(randStream) % 256) + 14;
347
                ch = (GetRand(randStream) % 128);
348
                GrWaitQue(5);
349
                GrQueCmd(0x7FFF, 12);   // set pen color
350
                GrQueCmd(0x000F, 13);   // set fill color
351
                GrQueCmd(x0<<16,16);
352
                GrQueCmd(y0<<16,17);
353
                GrQueCmd(ch,0);
354
//              GrDrawChar(x0<<16,y0<<16,ch);
355
        }
356
        */
357
}
358
 
359
 
360
void GrClearScreen()
361
{
362
        int nn;
363
        __int16 *pScreen = (__int16 *)0x100000;
364
 
365
        for (nn = 0; nn < 480000; nn++)
366
                pScreen[nn] = 0x000f;
367
}
368
 
369
void ColorBandMemory()
370
{
371
        __int16 *pScreen = (__int16 *)0x100000;
372
        int nn;
373
        __int16 color;
374
 
375
        randStream = 0;
376
        for (nn = 0; nn < 480000; nn++) {
377
                if (nn % 1024 == 0)
378
                        color = GetRand(randStream);
379
                pScreen[nn] = color;
380
        }
381
}
382
 
383
void EnableSprite(int spriteno)
384
{
385
        unsigned __int32 *pAVIC = AVIC;
386
        pAVIC[492] = pAVIC[492] | (1 << spriteno);
387
}
388
 
389
void EnableSprites(int sprites)
390
{
391
        unsigned __int32 *pAVIC = AVIC;
392
        pAVIC[492] = pAVIC[492] | sprites;
393
}
394
 
395
void RandomizeSpriteColors()
396
{
397
        int colorno;
398
        unsigned __int32 *pSprite = &AVIC[0];
399
        randStream = 0;
400
        for (colorno = 2; colorno < 256; colorno++) {
401
                pSprite[colorno] = GetRand(randStream) & 0x7fff;
402
        }
403
}
404
 
405
void SetSpritePos(int spriteno, int x, int y)
406
{
407
        __int32 *pSprite = &AVIC[0x100];
408
        pSprite[spriteno*4 + 2] = (__int32)((y << 16) | x);
409
}
410
 
411
void RandomizeSpritePositions()
412
{
413
        int spriteno;
414
        int x,y;
415
        __int32 *pSprite = &AVIC[0x100];
416
        randStream = 0;
417
        for (spriteno = 0; spriteno < 32; spriteno++) {
418
                x = (GetRand(randStream) % 400) + 128;
419
                y = (GetRand(randStream) % 300) + 14;
420
                pSprite[2] = (y << 16) | x;
421
                pSprite += 4;
422
        }
423
}
424
 
425
void SpriteDemo()
426
{
427
        int spriteno;
428
        __int32 xpos[32];
429
        __int32 ypos[32];
430
        __int32 dx[32];
431
        __int32 dy[32];
432
        int n, m;
433
        int btn;
434
        int x,y;
435
 
436
        unsigned __int32 *pSprite = &AVIC[0x100];
437
        unsigned __int32 *pImages = (unsigned __int32 *)0x1E000000;
438
        int n;
439
 
440
        randStream = 0;
441
        LEDS(2);
442
        RandomizeSpriteColors();
443
        EnableSprites(-1);
444
        // Set some random image data
445
        for (n = 0; n < 32 * 32 * 4; n = n + 1)
446
                pImages[n] = GetRand(randStream);
447
        x = 128; y = 64;
448
        for (spriteno = 0; spriteno < 32; spriteno++) {
449
                pSprite[spriteno*4] = (__int32)&pImages[spriteno * 128];
450
                pSprite[spriteno*4+1] = 32*60;
451
                xpos[spriteno] = x;
452
                ypos[spriteno] = y;
453
                SetSpritePos(spriteno, x, y);
454
                x += 20;
455
                if (x >= 500) {
456
                        x = 128;
457
                        y += 64;
458
                }
459
        }
460
        LEDS(0xf7);
461
        forever {
462
                btn = GetButton() & 31;
463
                LEDS(btn);
464
                switch(btn) {
465
                case BTNU:      goto j1;
466
                }
467
        }
468
j1:
469
        while (GetButton() & 31);
470
        for (spriteno = 0; spriteno < 32; spriteno++) {
471
//              xpos[spriteno] = (GetRand(randStream) % 400) + 128;
472
//              ypos[spriteno] = (GetRand(randStream) % 300) + 14;
473
//              SetSpritePos(spriteno, (int)xpos[spriteno], (int)ypos[spriteno]);
474
                dx[spriteno] = (GetRand(randStream) % 16) - 8;
475
                dy[spriteno] = (GetRand(randStream) % 16) - 8;
476
        }
477
        // Set some random image data
478
        for (n = 0; n < 32 * 32 * 2; n = n + 1)
479
                pImages[n] = GetRand(randStream);
480
        forever {
481
                for (m = 0; m < 50000; m++);     // Timing delay
482
                for (spriteno = 0; spriteno < 32; spriteno++) {
483
                        LEDS(spriteno);
484
                        xpos[spriteno] = xpos[spriteno] + dx[spriteno];
485
                        ypos[spriteno] = ypos[spriteno] + dy[spriteno];
486
                        if (xpos[spriteno] < 128) {
487
                                xpos[spriteno] = 128;
488
                                dx[spriteno] = -dx[spriteno];
489
                        }
490
                        if (xpos[spriteno] >= 528) {
491
                                xpos[spriteno] = 528;
492
                                dx[spriteno] = -dx[spriteno];
493
                        }
494
                        if (ypos[spriteno] < 14) {
495
                                ypos[spriteno] = 14;
496
                                dy[spriteno] = -dy[spriteno];
497
                        }
498
                        if (ypos[spriteno] >= 314)
499
                                ypos[spriteno] = 314;
500
                                dy[spriteno] = -dy[spriteno];
501
                        }
502
                        SetSpritePos(spriteno, (int)xpos[spriteno], (int)ypos[spriteno]);
503
                }
504
        }
505
}
506
 
507
void AudioTest()
508
{
509
        unsigned __int32 *pGPIO = (unsigned __int32 *)(0xFFDC0700);
510
        unsigned __int32 *pAVIC = AVIC;
511
 
512
        LEDS(0xf7);
513
        pGPIO[0] = 0xFFFFFFFF;           // turn on audio clocks
514
        pAVIC[404] = 0x0000401F;        // Enable channels and test mode
515
}
516
 
517
void InitAudio()
518
{
519
        unsigned __int32 *pAVIC = AVIC;
520
 
521
        // Channel 0
522
        pAVIC[384] = 0x200000;
523
        pAVIC[385] = 65535;             // buffer length
524
        pAVIC[386] = 0xFFFFF;   // period to max
525
        pAVIC[387] = 0x0000;    // volume = 0, output data = 0
526
 
527
        // Channel 1
528
        pAVIC[388] = 0x210000;
529
        pAVIC[389] = 65535;             // buffer length
530
        pAVIC[390] = 0xFFFFF;   // period to max
531
        pAVIC[391] = 0x0000;    // volume = 0, output data = 0
532
 
533
        // Channel 2
534
        pAVIC[392] = 0x220000;
535
        pAVIC[393] = 65535;             // buffer length
536
        pAVIC[394] = 0xFFFFF;   // period to max
537
        pAVIC[395] = 0x0000;    // volume = 0, output data = 0
538
 
539
        // Channel 3
540
        pAVIC[396] = 0x230000;
541
        pAVIC[397] = 65535;             // buffer length
542
        pAVIC[398] = 0xFFFFF;   // period to max
543
        pAVIC[399] = 0x0000;    // volume = 0, output data = 0
544
 
545
        // Channel I
546
        pAVIC[400] = 0x240000;
547
        pAVIC[401] = 65535;             // buffer length
548
        pAVIC[402] = 0xFFFFF;   // period to max
549
        pAVIC[403] = 0x0000;    // volume = 0, output data = 0
550
 
551
        pAVIC[404] = 0x00001F00;        // Reset
552
        pAVIC[404] = 0x00000000;
553
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.