35 #define min(x, y) ((x<y) ? x : y) 36 #define max(x, y) ((x>y) ? x : y) 38 #define CENTERX (COLS/2) 39 #define CENTERY (ROWS/2) 54 #define VGA_ENABLE_PIN 15 56 unsigned char framebuffer[ROWS*COLS];
72 #define BALLCOLOR White 76 #define SCOREX (CENTERX-40) 78 #define SCORECOLOR Blue 83 #define RPADDLEX (COLS-LPADDLEX) 84 #define PADDLECOLOR Green 86 _COGMEM
int ballx = CENTERX, bally = CENTERY;
87 _COGMEM
int vx = 1, vy = 1;
89 _COGMEM
int lscore, rscore;
90 _COGMEM
int lpaddley = (ROWS-PADDLEH)/2;
91 _COGMEM
int rpaddley = (ROWS-PADDLEH)/2;
93 _COGMEM
int pauseframes = 0;
94 _COGMEM
int needreset = 0;
101 vline(
unsigned char *frame,
int x,
int y,
int h,
unsigned char color)
104 frame += (y*COLS) + x;
107 for (i = 0; i < h; i++) {
118 box(
unsigned char *frame,
int x,
int y,
int w,
int h,
unsigned char color)
123 for (i = 0; i < w; i++) {
124 vline(frame, x, y, h, color);
132 printdigit(
unsigned char *frame,
int n,
int x,
int y,
unsigned char color)
134 static unsigned char digits[] = {
135 0xf, 0x9, 0x9, 0x9, 0xf,
136 0x1, 0x1, 0x1, 0x1, 0x1,
137 0xf, 0x1, 0xf, 0x8, 0xf,
138 0xf, 0x1, 0xf, 0x1, 0xf,
139 0x9, 0x9, 0xf, 0x1, 0x1,
141 0xf, 0x8, 0xf, 0x1, 0xf,
142 0xf, 0x8, 0xf, 0x9, 0xf,
143 0xf, 0x1, 0x1, 0x1, 0x1,
144 0xf, 0x9, 0xf, 0x9, 0xf,
145 0xf, 0x9, 0xf, 0x1, 0xf,
148 unsigned char *ptr = digits + n*5;
153 for (j = 0; j < 5; j++) {
155 if (c & 0x8) frame[0] = color;
156 if (c & 0x4) frame[1] = color;
157 if (c & 0x2) frame[2] = color;
158 if (c & 0x1) frame[3] = color;
165 printscore(
unsigned char *frame,
int number,
int x,
int y,
unsigned char color)
170 while (number >= 10) {
174 printdigit(frame, tens, x, y, color);
175 printdigit(frame, number, x+5, y, color);
196 lpaddley = rpaddley = CENTERY - (PADDLEH/2);
212 if (center & (1<<LPINDN))
214 else if (center & (1<<LPINUP))
217 center = lpaddley + PADDLEH/2;
223 lpaddley = max(lpaddley, 0);
224 lpaddley = min(lpaddley, ROWS - PADDLEH);
228 if (center & (1<<RPINDN))
230 else if (center & (1<<RPINUP))
233 center = rpaddley + PADDLEH/2;
239 rpaddley = max(rpaddley, 0);
240 rpaddley = min(rpaddley, ROWS - PADDLEH);
254 draw(
int i,
int erase)
256 static unsigned char fgcolor[] = {
257 SCORECOLOR, SCORECOLOR,
258 PADDLECOLOR, PADDLECOLOR,
270 printscore(framebuffer, lscore, SCOREX, SCOREY, color);
274 printscore(framebuffer, rscore, COLS-(SCOREX+16), SCOREY, color);
278 box(framebuffer, LPADDLEX, lpaddley, PADDLEW, PADDLEH, color);
282 box(framebuffer, RPADDLEX, rpaddley, PADDLEW, PADDLEH, color);
286 box(framebuffer, ballx, bally, BALLW, BALLH, color);
311 }
else if (bally + BALLH > ROWS) {
312 bally = ROWS - BALLH;
316 if (ballx <= LPADDLEX+PADDLEW) {
317 if (ballx >= LPADDLEX - BALLW
318 && bally >= lpaddley && bally < lpaddley + PADDLEH)
329 }
else if (ballx >= RPADDLEX-BALLW) {
330 if (ballx <= RPADDLEX
331 && bally >= rpaddley && bally < rpaddley + PADDLEH)
335 else if (ballx + BALLW > COLS)
337 ballx = COLS - BALLW;
347 unsigned int frequency, i, testval;
348 unsigned int clkfreq = _CLKFREQ;
351 box(framebuffer, 0, 0, COLS, ROWS, BGCOLOR);
357 #if defined(VGA_ENABLE_PIN) 358 _DIRA = (1<<VGA_ENABLE_PIN);
364 _VCFG = 0x300000FF | (PINGROUP<<9);
365 testval = (25175000 + 1600) / 4;
367 for (i = 0; i < 32; i++) {
368 testval = testval << 1;
369 frequency = (frequency << 1) | (frequency >> 31);
370 if (testval >= clkfreq) {
384 #define DISPLAY_WIDTH_LONGS (COLS/4) 385 #define LINEREPEAT (480/ROWS) 387 static const uint32_t invisibleScale = (16 << 12) + 160;
389 static const uint32_t visibleScale = ((640/COLS)<<12) + (4*640/COLS);
390 static const uint32_t blankPixels = 640;
391 static const uint32_t syncPixels = 0x3FFC;
392 static const uint32_t HSyncColors = 0x01030103;
393 static const uint32_t VSyncColors = 0x00020002;
394 static const uint32_t HVSyncColors = 0x03030303;
396 static _COGMEM uint32_t *displayPtr;
399 #define ConstPixels 0xE4 404 videoLine(uint32_t *lineptr)
409 _VSCL = visibleScale;
410 for (i = 0; i < DISPLAY_WIDTH_LONGS; i++)
413 __builtin_propeller_waitvid(pixels, ConstPixels);
415 _VSCL = invisibleScale;
416 __builtin_propeller_waitvid(HSyncColors, syncPixels);
422 blankLines(
int n, uint32_t thisSyncColor)
425 for (i = 0; i < n; i++) {
427 __builtin_propeller_waitvid(thisSyncColor, 0);
428 _VSCL = invisibleScale;
429 __builtin_propeller_waitvid(thisSyncColor, syncPixels);
440 draw(side, (pauseframes>>4)&1);
460 displayPtr = (uint32_t *)framebuffer;
462 for (i = 0; i < ROWS; i++) {
464 for (j = 0; j < LINEREPEAT; j++) {
465 videoLine(displayPtr);
467 displayPtr += DISPLAY_WIDTH_LONGS;
472 if (pauseframes > 0) {
477 for (i = 0; i < 11; i++) {
479 __builtin_propeller_waitvid(HSyncColors, 0);
484 if (lscore == MAX_SCORE) {
486 }
else if (rscore == MAX_SCORE) {
497 _VSCL = invisibleScale;
498 __builtin_propeller_waitvid(HSyncColors, syncPixels);
502 blankLines(4, VSyncColors);
505 blankLines(32, HSyncColors);
508 _DIRA |= (0xff << (8*PINGROUP));