rendered paste body#include <tigcclib.h>
#define LCD_BYTES_COLS 20
#define LCD_ROW_BYTES 30
#define LCD_BOTTOM_ROW (void *)0x579A
#define ARROW_ROW 0xFFFE
#define ESCROW 0xFFBF // the ESC row on the TI-89 keyboard matrix
#define ESCKEY 0x0001 // the ESC key inside that row
#define KEYLEFT 0x0002
#define KEYRIGHT 0x0008
unsigned long blocks = 0;
char spacing_count = 38, max_spacing = 40, max_spacing_count = 0, platform_row = 4;
unsigned char ball_x = 77, ball_y = 50;
unsigned char ball[] = {0x78,0x9C,0xBC,0xFC,0xFC,0x78};
void delay(int len) {
int i, randnum;
for (i = 0; i < len; i++) {
randnum = random(0xFF);
}
}
void scroll_up() {
memcpy(LCD_MEM, LCD_MEM + LCD_ROW_BYTES, LCD_ROW_BYTES * LCD_HEIGHT);
}
void draw_platform() {
if (platform_row == 4) { // If we have drawn all four lines of a platform
spacing_count++; // Increase our count of the space between each platform
if (spacing_count == max_spacing) { // If it is time to draw a new block...
platform_row = 0;
randomize();
blocks = ((long)random(0xFFFF) << 16) | ((long)random(0xFFFF)); // Generate a new random platform
spacing_count = 0; // Reset the spacing count
max_spacing_count++; // And add one to max spacing count
if (max_spacing_count == 6) { // Its time to decrease the spacing between platforms
max_spacing -= 2;
if (max_spacing <= 8) { // Unless the spacing is too thin, then dont change it
max_spacing = 8;
}
max_spacing_count = 0;
}
}
} else {
int i;
unsigned long bits = 0x00080000;
char *lcd = LCD_BOTTOM_ROW;
for (i = 0; i < 20; i++){
if (blocks & bits) {
if (platform_row == 0 || platform_row == 3) {
lcd[i] = 0xFF; // Fill ones with lines
} else {
lcd[i] = random(0xFF); // or with randomness
}
}
bits >>= 1;
}
platform_row++;
}
}
void move_up() {
ball_y--;
}
void move_down() {
Sprite8(ball_x, ball_y - 1, 6, ball, LCD_MEM, SPRT_XOR);
if (ball_y < 94) {
ball_y++;
}
Sprite8(ball_x, ball_y, 6, ball, LCD_MEM, SPRT_XOR);
}
void move_left() {
Sprite8(ball_x, ball_y, 6, ball, LCD_MEM, SPRT_XOR);
ball_x--;
Sprite8(ball_x, ball_y, 6, ball, LCD_MEM, SPRT_XOR);
}
void move_right() {
Sprite8(ball_x, ball_y, 6, ball, LCD_MEM, SPRT_XOR);
ball_x++;
Sprite8(ball_x, ball_y, 6, ball, LCD_MEM, SPRT_XOR);
}
void move_ball() {
// Gravitty
unsigned char *check = LCD_MEM + (LCD_ROW_BYTES * (ball_y + 5)) + (ball_x / 8);
// *check = 0x02;
if (ball_x % 8 < 3) {
if (!*check) {
move_down();
} else {
move_up();
}
} else {
if (!(check[0] | check[1])) {
move_down();
} else {
move_up();
}
}
int key;
//Left and right
key = _rowread(ARROW_ROW);
if (key & KEYLEFT) {
move_left();
}
if (key & KEYRIGHT) {
move_right();
}
}
void _main(void) {
ClrScr();
// for (i = 0; i < 100; i++) {
// scroll_up();
// }
Sprite8(ball_x, ball_y, 6, ball, LCD_MEM, SPRT_XOR);
// unsigned char *check = 0x550F;
// *check = 0x02;
INT_HANDLER interrupt1 = GetIntVec(AUTO_INT_1); // save auto-interrupt 1
INT_HANDLER interrupt5 = GetIntVec(AUTO_INT_5); // save auto-interrupt 5
SetIntVec(AUTO_INT_1,DUMMY_HANDLER);
SetIntVec(AUTO_INT_5,DUMMY_HANDLER);
int i;
// for (i = 0; i < 150; i++) {
while (!(_rowread(ESCROW) & ESCKEY)) {
scroll_up();
draw_platform();
move_ball();
if (ball_y == 0) { DrawStr(0, 50, "LOSER", A_NORMAL); i = 150; }
delay(500);
}
SetIntVec(AUTO_INT_1,interrupt1);
SetIntVec(AUTO_INT_5,interrupt5);
ngetchx();
ClrScr();
}