12 #include "propeller.h"
18 #define bitsPerPixel 1
19 #define horizontalScaling 1
20 #define horizontalPixels 640
25 extern int8_t vga_array[];
27 uint8_t tilemap1[30*40];
28 uint8_t *tilemap0 = (uint8_t *)vga_array;
29 uint8_t *tilemap = (uint8_t *)vga_array;
30 uint32_t tiles[256*16];
34 volatile int syncIndicator = 0;
35 int pixelColors = 0xfc3c000c;
38 uint32_t directionState;
40 uint32_t frequencyState;
41 uint32_t verticalScaling;
42 uint32_t verticalPixels;
43 uint32_t visibleScale;
44 uint32_t invisibleScale;
45 uint32_t horizontalLongs;
46 uint32_t *colortable1;
48 uint32_t *pixelColorsAddress;
49 uint32_t *syncIndicatorAddress;
55 char *ptr = malloc(100);
56 printf(
"%8.8x %8.8x %d\n", ptr, &ptr, ((
int)&ptr) - (
int)ptr);
68 void VgaStart(
int pinGroup,
int verticalResolution,
int *newDisplayPointer,
69 int *colortable,
int *pixelColors,
int *syncIndicator)
76 printf(
"%8.8x %8.8x %8.8x %8.8x %8.8x %8.8x\n",
77 newDisplayPointer, colortable, pixelColors, syncIndicator, vga_array, &vga);
80 vga.directionState = 0xff << (8 * pinGroup);
81 vga.videoState = 0x200000ff | (pinGroup << 9) | (bitsPerPixel << 28);
82 temp = (25175000 + 1600) / 4;
84 for (i = 0; i < 32; i++)
88 if (i == 31) frequencyState++;
95 vga.frequencyState = frequencyState;
96 vga.verticalScaling = 480 / verticalResolution;
97 vga.verticalPixels = 480 / vga.verticalScaling;
98 vga.visibleScale = (horizontalScaling << 12) + ((640 * 32) >> bitsPerPixel) / horizontalPixels;
99 vga.invisibleScale = ((8 << bitsPerPixel) << 12) + 160;
100 vga.horizontalLongs = horizontalPixels / (32 >> bitsPerPixel);
101 vga.buffer1 = newDisplayPointer;
102 vga.colortable1 = colortable;
103 vga.pixelColorsAddress = pixelColors;
104 vga.syncIndicatorAddress = syncIndicator;
106 memcpy(vga_array + 4, &vga,
sizeof(
VgaVarT));
123 void CheckInnerWallCollisions(
ObjectT *obj,
int leftcol,
int rightcol,
int hole)
125 leftcol -= obj->width;
127 if (hole && obj->row >= HOLE_TOP && obj->row + obj->height - 1 < HOLE_BOT)
return;
129 if (obj->col < rightcol && obj->prevcol >= rightcol)
131 obj->col = (rightcol << 1) - obj->col;
132 obj->delcol = -obj->delcol;
134 else if (obj->col >= leftcol && obj->prevcol < leftcol)
136 obj->col = (leftcol << 1) - obj->col;
137 obj->delcol = -obj->delcol;
144 else if (obj->col >= leftcol && obj->col <= rightcol)
146 int prevrow = obj->row - obj->delrow;
148 if (hole && prevrow >= HOLE_TOP && prevrow < HOLE_BOT)
150 if (obj->row < HOLE_TOP)
151 obj->row = (HOLE_TOP << 1) - obj->row;
153 obj->row = ((HOLE_BOT - obj->height) << 1) - obj->row;
154 obj->delrow = -obj->delrow;
158 if (obj->prevcol < obj->col)
160 obj->col = (leftcol << 1) - obj->col;
166 obj->delcol = -obj->delcol;
170 obj->col = (rightcol << 1) - obj->col;
171 obj->delcol = -obj->delcol;
177 void CheckWallCollisions(
ObjectT *obj,
int mincol,
int maxcol,
int minrow,
int maxrow)
179 maxcol -= obj->width;
180 maxrow -= obj->height;
182 if (obj->col < mincol)
184 obj->col = (mincol << 1) - obj->col;
185 obj->delcol = -obj->delcol;
187 else if (obj->col >= maxcol)
189 obj->col = (maxcol << 1) - obj->col;
190 obj->delcol = -obj->delcol;
193 if (obj->row < minrow)
195 obj->row = (minrow << 1) - obj->row;
196 obj->delrow = -obj->delrow;
198 else if (obj->row >= maxrow)
200 obj->row = (maxrow << 1) - obj->row;
201 obj->delrow = -obj->delrow;
209 int coldiff = obj1->col + (obj1->width>>1) - obj2->col - (obj2->width>>1);
210 int rowdiff = obj1->row + (obj1->height>>1) - obj2->row - (obj2->height>>1);
212 if (coldiff < 0) coldiff = -coldiff;
213 if (rowdiff < 0) rowdiff = -rowdiff;
216 if ((coldiff << 1) > obj1->width + obj2->width ||
217 (rowdiff << 1) > obj1->height + obj2->height)
221 diff = (coldiff * coldiff) + (rowdiff * rowdiff);
223 if (4 * diff > (obj1->width * obj1->height) + (obj2->width * obj2->height))
226 obj1->delcol = -obj1->delcol;
227 obj2->delcol = -obj2->delcol;
228 obj1->delrow = -obj1->delrow;
229 obj2->delrow = -obj2->delrow;
239 int syncIndicatorPrev;
241 uint32_t object1[64] = {
242 0xa0000000, 0x0000000a, 0xaaa00000, 0x00000aaa, 0xaaaa0000, 0x0000aaaa,
243 0xaaaa8000, 0x0002aaaa, 0xaaaaa800, 0x002aaaaa, 0xaaaaaa00, 0x00aaaaaa,
244 0xaaaaaa00, 0x00aaaaaa, 0xaaaaaa80, 0x02aaaaaa, 0xaaaaaaa0, 0x0aaaaaaa,
245 0xaaaaaaa0, 0x0aaaaaaa, 0xaaaaaaa8, 0x2aaaaaaa, 0xaaaaaaa8, 0x2aaaaaaa,
246 0xaaaaaaa8, 0x2aaaaaaa, 0xaaaaaaa8, 0x2aaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
247 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
248 0xaaaaaaa8, 0x2aaaaaaa, 0xaaaaaaa8, 0x2aaaaaaa, 0xaaaaaaa8, 0x2aaaaaaa,
249 0xaaaaaaa8, 0x2aaaaaaa, 0xaaaaaaa0, 0x0aaaaaaa, 0xaaaaaaa0, 0x0aaaaaaa,
250 0xaaaaaa80, 0x02aaaaaa, 0xaaaaaa00, 0x00aaaaaa, 0xaaaaaa00, 0x00aaaaaa,
251 0xaaaaa800, 0x002aaaaa, 0xaaaa8000, 0x0002aaaa, 0xaaaa0000, 0x0000aaaa,
252 0xaaa00000, 0x00000aaa, 0xa0000000, 0x0000000a};
254 uint32_t object2[64] = {
255 0x05500000, 0x00000000, 0x55554000, 0x00000001, 0x55555400, 0x00000015,
256 0x55555500, 0x00000055, 0x55555540, 0x00000155, 0x55555550, 0x00000555,
257 0x55555550, 0x00000555, 0x55555554, 0x00001555, 0x55555554, 0x00001555,
258 0x55555554, 0x00001555, 0x55555555, 0x00005555, 0x55555555, 0x00005555,
259 0x55555555, 0x00005555, 0x55555555, 0x00005555, 0x55555554, 0x00001555,
260 0x55555554, 0x00001555, 0x55555554, 0x00001555, 0x55555550, 0x00000555,
261 0x55555550, 0x00000555, 0x55555540, 0x00000155, 0x55555500, 0x00000055,
262 0x55555400, 0x00000015, 0x55554000, 0x00000001, 0x05500000, 0x00000000};
264 uint32_t object3[64] = {
265 0x000ff000, 0x00ffff00, 0x0ffffff0, 0x0ffffff0, 0x3ffffffc, 0x3ffffffc,
266 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x3ffffffc, 0x3ffffffc,
267 0x0ffffff0, 0x0ffffff0, 0x00ffff00, 0x000ff000};
270 100, 100, 200, 1, 1, (uint32_t *)object1, 32, 32, 64,
271 200, 200, 300, 3, 5, (uint32_t *)object2, 24, 24, 27,
272 300, 300, 400, -2, 8, (uint32_t *)object3, 16, 16, 8,
273 100, 100, 250, 7, 2, (uint32_t *)object1, 32, 32, 64,
274 200, 200, 350, 2,-5, (uint32_t *)object2, 24, 24, 27,
275 300, 300, 450, -5, 3, (uint32_t *)object3, 16, 16, 8,
276 100, 100, 200, 1, 1, (uint32_t *)object1, 32, 32, 64,
277 200, 200, 300, 3, 5, (uint32_t *)object2, 24, 24, 27,
278 300, 300, 400, -2, 8, (uint32_t *)object3, 16, 16, 8,
279 100, 100, 250, 7, 2, (uint32_t *)object1, 32, 32, 64,
280 200, 200, 350, 2,-5, (uint32_t *)object2, 24, 24, 27,
281 300, 300, 450, -5, 3, (uint32_t *)object3, 16, 16, 8,
282 100, 100, 200, 1, 1, (uint32_t *)object1, 32, 32, 64,
283 200, 200, 300, 3, 5, (uint32_t *)object2, 24, 24, 27,
284 300, 300, 400, -2, 8, (uint32_t *)object3, 16, 16, 8,
285 100, 100, 250, 7, 2, (uint32_t *)object1, 32, 32, 64,
286 200, 200, 350, 2,-5, (uint32_t *)object2, 24, 24, 27,
287 300, 300, 450, -5, 3, (uint32_t *)object3, 16, 16, 8,
288 100, 100, 200, 1, 1, (uint32_t *)object1, 32, 32, 64,
289 200, 200, 300, 3, 5, (uint32_t *)object2, 24, 24, 27,
290 300, 300, 400, -2, 8, (uint32_t *)object3, 16, 16, 8,
291 100, 100, 250, 7, 2, (uint32_t *)object1, 32, 32, 64,
292 200, 200, 350, 2,-5, (uint32_t *)object2, 24, 24, 27,
293 300, 300, 450, -5, 3, (uint32_t *)object3, 16, 16, 8};
296 int leftwall = 640 - 16;
303 pixelColors = 0x0c30c000;
305 memset(tilemap, 0, 40*30);
306 memset(&tiles[16], 0xdd, 4);
307 memset(&tiles[17], 0x77, 4);
308 memcpy(&tiles[18], &tiles[16], 8);
309 memcpy(&tiles[20], &tiles[16], 16);
310 memcpy(&tiles[24], &tiles[16], 32);
311 tilemap[0] = ++lastindex;
312 drawline( 0, 0, 0, 15, 3);
313 drawline(15, 0, 15, 15, 3);
314 drawline(0, 0, 15, 0, 3);
315 drawline(0, 15, 15, 15, 3);
316 drawline(0, 7, 15, 7, 3);
317 drawline(0, 8, 15, 8, 3);
318 memcpy(&tiles[32], &tiles[16], 32);
319 memset(&tiles[40], 0, 32);
320 memset(&tiles[48], 0, 32);
321 memcpy(&tiles[56], &tiles[16], 32);
322 memset(&tiles[4<<4], 0, 64);
323 memcpy(&tiles[5<<4], &tiles[1<<4], 64);
325 PutStringImage(16, 3,
"GRAVITY ON", 1, 0, 1);
326 lockindex1 = lockindex = lastindex;
328 for (i = 0; i < 2500; i++)
333 for (j = 0; j < numobj; j++)
336 obj->prevcol = obj->col;
337 obj->col += obj->delcol;
338 obj->row += obj->delrow;
343 for (j = 0; j < numobj-1; j++)
345 for (k = j + 1; k < numobj; k++)
346 CheckCollision(&objects[j], &objects[k]);
359 rightwall = leftwall + 15;
366 for (j = 0; j < numobj; j++)
368 CheckInnerWallCollisions(&objects[j], leftwall, rightwall, hole);
374 for (j = 0; j < numobj; j++)
375 CheckWallCollisions(&objects[j], 16, 623, 8, 471);
378 if (i > 400 && i < 700)
380 for (j = 0; j < numobj; j++)
381 objects[j].delrow += 1;
385 drawobject(leftwall, 8, &tiles[1<<4], 16, 8);
386 drawobject(leftwall, 480 - 16, &tiles[1<<4], 16, 8);
387 drawobject(leftwall, 16, &tiles[1<<4], 16, 16);
388 lockindex = lastindex;
389 k = (leftwall >> 4) + (2 * 40);
392 for (j = 2; j < 29; j++, k += 40)
394 if (!hole || j < (HOLE_TOP >> 4) || j >= (HOLE_BOT >> 4))
396 tilemap[k] = lastindex - 1;
397 tilemap[k+1] = lastindex;
403 for (j = 2; j < 29; j++, k += 40)
405 if (!hole || j < (HOLE_TOP >> 4) || j >= (HOLE_BOT >> 4))
407 tilemap[k] = lastindex;
413 for (j = 0; j < numobj; j++)
416 drawobject(obj->col, obj->row, obj->object, obj->width, obj->height);
419 memcpy(tilemap0, tilemap, 30*40);
420 memset(tilemap, 0, 30*40);
421 memset(tilemap, 2, 40);
422 memset(&tilemap[29*40], 3, 40);
424 for (j = 0, l = 0; l < 30; j += 40, l++)
426 tilemap[j] = tilemap[j+39] = 1;
428 if (i > 400 && i < 700 && (i%25) < 13)
430 for (j = 0; j < 5; j++)
431 tilemap[82 + j] = lockindex1 - 4 + j;
436 lastindex = (256 + lockindex1) >> 1;
440 lastindex = lockindex1;
442 if (i == 700) numobj = 12;
443 if (i == 800) numobj = 18;
453 cflag = angle & 0x0800;
454 zflag = angle & 0x1000;
455 if (cflag) angle = -angle;
457 angle |= 0xe000 >> 1;
459 angle = *(uint16_t *)angle;
460 if (zflag) angle = -angle;
469 pixelColors = 0xfcc0000c;
471 pixelColors = 0x000c28a8;
472 for (i = 0; i < 15; i++) tiles[i] = 0x40000000;
473 tiles[15] = 0x55555555;
475 PutStringImage2(250, 20,
"Log Table", 1, 0, 2);
476 sptr = (uint16_t *)0xc000;
477 for (i = 0; i < 512; i++)
479 drawdot(i+64, 400 - (sptr[i*4]/200), 2);
482 drawline(64, 400, 576, 400, 3);
483 drawline(64, 400 - 65536/200, 576, 400 - 65536/200, 3);
484 drawline(64, 400, 64, 400 - 65536/200, 3);
485 drawline(576, 400, 576, 400 - 65536/200, 3);
486 PutStringImage(290, 420,
"X-Axis", 1, 0, 2);
487 PutStringImage(34, 250,
"Y-Axis", 1, 1, 2);
491 void PlotAntiLog(
void)
497 PutStringImage2(220, 20,
"Anti-log Table", 1, 0, 0);
498 sptr = (uint16_t *)0xd000;
499 for (i = 0; i < 512; i++)
501 drawdot(i+64, 400 - (sptr[i*4]/200), 2);
504 drawline(64, 400, 576, 400, 1);
505 drawline(64, 400 - 65536/200, 576, 400 - 65536/200, 1);
506 drawline(64, 400, 64, 400 - 65536/200, 1);
507 drawline(576, 400, 576, 400 - 65536/200, 1);
517 PutStringImage2(250, 20,
"Sine Table", 1, 0, 0);
518 pixelColors = 0x3cc0110c;
519 sptr = (uint16_t *)0xe000;
520 for (i = 0; i <= 512; i++)
522 drawdot(i+64, 400 - (sptr[i*4]/200), 2);
524 drawline(64, 400, 576, 400, 1);
525 drawline(64, 400 - 65536/200, 576, 400 - 65536/200, 1);
526 drawline(64, 400, 64, 400 - 65536/200, 1);
527 drawline(576, 400, 576, 400 - 65536/200, 1);
535 int col1, col2, row1, row2;
536 uint32_t hole[64] = {
537 0x000ff000, 0x00ffff00, 0x0ffffff0, 0x0ffffff0, 0x3ffffffc, 0x3ffffffc,
538 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x3ffffffc, 0x3ffffffc,
539 0x0ffffff0, 0x0ffffff0, 0x00ffff00, 0x000ff000};
542 pixelColors = 0x0028a00c;
543 tiles[15] = 0xaaaaaaaa;
544 drawobject(16, 64, hole, 16, 16);
545 drawobject(16, 416, hole, 16, 16);
546 drawline(64, 0, 64, 479, 3);
547 PutStringImage2(250, 20,
"Sinewave", 1, 0, 0);
550 for (i = 0; i <= 512; i += 4)
553 row2 = 236 - (sine(i*32) / 500);
554 drawline(col1, row1, col2, row2, 0);
558 drawline(64, 236, 576, 236, 3);
569 pixelColors = 0xfcc0000c;
570 PutStringImage(236, row,
"This is the 8x11 font", 1, 0, 1);
572 PutStringImage(32, row,
"This is the 8x11 font in double size", 2, 0, 2);
574 PutStringImage2(72, row,
"This is the Parallax 16x32 font", 1, 0, 0);
576 PutStringImage(100, row,
"Now is the time for all good men", 1, 0, 1);
578 PutStringImage(100, row,
"to come to the aid of their party", 1, 0, 1);
580 PutStringImage(100, row,
"The quick brown fox jumps over", 1, 0, 2);
582 PutStringImage(100, row,
"the lazy dog", 1, 0, 2);
588 void DisplayRawRomFont(
void)
592 pixelColors = 0xfc3c000c;
594 memcpy(tiles, (
void *)0x8000, 256*16*4);
596 for (i = 0; i < 1200; i++)
598 if ((i%80) == 40) k = k - 80 + 1;
599 else if ((i%80) == 0) k = k - 1;
600 tilemap[i] = (k & 255);
607 int vga_text_col = 0;
608 int vga_text_row = 0;
613 int index = vga_text_col + 80 * vga_text_row;
622 tilemap[index] = val;
623 tilemap[index+40] = val+1;
626 if (vga_text_col >= 40)
630 if (vga_text_row >= 15)
632 for (i = 0; i < 40*28; i += 80)
633 memcpy(&tilemap[i], &tilemap[i+80], 80);
634 memset(&tilemap[40*28],
' ' << 1, 80);
640 void vga_str(
char *str)
646 void vga_tx2(
int val)
649 int index = vga_text_col + 40 * vga_text_row;
657 tilemap[index] = val;
660 if (vga_text_col >= 40)
664 if (vga_text_row >= 30)
666 for (i = 0; i < 40*29; i += 40)
667 memcpy(&tilemap[i], &tilemap[i+40], 40);
668 memset(&tilemap[40*29],
' ', 40);
674 void vga_str2(
char *str)
680 void DisplayRomFont(
void)
687 pixelColors = 0xfc3c000c;
688 memcpy(tiles, (
void *)0x8000, 256*16*4);
690 ptr2 = (uint32_t *)0x8000;
691 for (i = 0; i < 64; i++)
693 for (j = 0; j < 32; j++)
695 temp = ptr2[j] & 0x55555555;
696 *ptr1++ = temp | (temp << 1);
698 for (j = 0; j < 32; j++)
700 temp = ptr2[j] & 0xaaaaaaaa;
701 *ptr1++ = temp | (temp >> 1);
706 memset(tilemap,
' ' << 1, 40*30);
707 for (i = 0; i < 200; i++)
709 sprintf(outstr,
"This is a test %3d\n", i);
715 void DisplayRomFont2(
void)
722 pixelColors = 0xfc3c000c;
723 memcpy(tiles, (
void *)0x8000, 256*16*4);
725 ptr2 = (uint32_t *)0x8000;
726 for (i = 0; i < 128; i++)
728 for (j = 0; j < 32; j += 2)
730 temp = (ptr2[j] | ptr2[j+1]) & 0x55555555;
731 *ptr1++ = temp | (temp << 1);
733 for (j = 0; j < 32; j += 2)
735 temp = (ptr2[j] | ptr2[j+1]) & 0xaaaaaaaa;
736 *ptr1++ = temp | (temp >> 1);
740 for (i = 0; i < 1200; i++)
742 tilemap[i] = (i & 255);
745 memset(tilemap,
' ', 40*30);
746 for (i = 0; i < 200; i++)
748 sprintf(outstr,
"This is a test %3d\n", i);
759 VgaStart(2, 30, (
int *)tilemap, tiles, &pixelColors, (
int *)&syncIndicator);