Created
January 16, 2016 23:03
-
-
Save Denton-L/2001008725782283389c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define PADDLEHEIGHT 5 | |
#define BALLSIZE 3 | |
short *PA = 0x8000; | |
short *PB = 0x8001; | |
short *DDRA = 0x8002; | |
short *DDRB = 0x8003; | |
short pbbuff; | |
short paddle; | |
short ballx; | |
short bally; | |
short dx; | |
short dy; | |
short score; | |
short i; | |
short j; | |
short k; | |
short buff[128][64]; | |
void senddisp() { | |
*PB = pbbuff & 0xFE; | |
*PB = pbbuff | 0xFF; | |
} | |
void cls() { | |
for (i = 0; i < 128; ++i) { | |
for (j = 0; j < 64; ++j) { | |
buff[i][j] = 0; | |
} | |
} | |
} | |
void writedisp() { | |
short bytebuff; | |
for (k = 0; k < 8; ++k) { | |
bytebuff = 0; | |
bytebuff |= buff[j][i*8 + k] << k; | |
} | |
*PA = bytebuff; | |
senddisp(); | |
} | |
void animate() { | |
cls(); | |
//write the paddle to the buff | |
for (i = 0; i < PADDLEHEIGHT; ++i) | |
buff[0][paddle + i] = 1; | |
//write the ball to the buff | |
for (i = 0; i < BALLSIZE; ++i) | |
for (j = 0; j < BALLSIZE; ++j) | |
buff[ballx+i][bally+j] = 1; | |
//write the score to the buff | |
for (i = 0; i < score; ++i) | |
buff[127-score/64][63-score%64] = 1; | |
//write from the buff to the display | |
for (i = 0; i < 8; ++i) { | |
pbbuff = 0x47; | |
*PA = 0xB8 | i; | |
senddisp(); | |
*PA = 0x40; | |
senddisp(); | |
pbbuff = 0x43; | |
for (j = 0; j < 64; ++j) { | |
writedisp(); | |
} | |
pbbuff = 0x45; | |
for (j = 64; j < 128; ++j) { | |
writedisp(); | |
} | |
} | |
} | |
void reset() { | |
bally = paddle = 32; | |
ballx = 64; | |
dy = dx = 1; | |
score = 0; | |
} | |
void step() { | |
//check for x collision | |
if (bally <= 0) | |
dy = 1; | |
else if (bally + BALLSIZE - 1 >= 63) | |
dy = -1; | |
//check for y collision | |
if (ballx < 0) { | |
reset(); | |
return; | |
} else if (ballx + BALLSIZE - 1 >= 127) | |
ballx = -1; | |
else if ((ballx == 1) && (bally >= paddle - BALLSIZE + 1) && (bally <= paddle + PADDLEHEIGHT - 1)) { | |
dx = 1; | |
++score; | |
} | |
//move the paddles | |
if ((*PB & 0x30) == 0x10) | |
paddle = (--paddle < 0 ? 0 : paddle); | |
else if ((*PB & 0x30) == 0x30) | |
paddle = (++paddle + PADDLEHEIGHT > 64 ? 64 - PADDLEHEIGHT : paddle); | |
//animate the stuff | |
bally += dy; | |
ballx += dx; | |
animate(); | |
} | |
void delay() { | |
for (i = 0; i < 0xFF; ++i) | |
for (j = 0; j < 0xFF; ++j) | |
for (k = 0; k < 0xFF; ++k) | |
; | |
} | |
void main() { | |
*DDRA = 0xFF; | |
*DDRB = 0xCF; | |
pbbuff = 0x47; | |
*PA = 0x3F; | |
senddisp(); | |
*PA = 0xC0; | |
senddisp(); | |
reset(); | |
loop: | |
step(); | |
delay(); | |
goto loop; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment