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 NDKEY 0x0010
#define KEYLEFT 0x0002
#define KEYRIGHT 0x0008
unsigned long blocks = 0;
char spacing_count = 38, max_spacing = 40, max_spacing_count = 0, platform_row = 4;
char speed = 0;
unsigned char ball_x = 77, ball_y = 50;
unsigned char ball[] = {0x78,0x9C,0xBC,0xFC,0xFC,0x78};
void draw_speed() {
char buffer[5];
sprintf (buffer, "%d", speed);
DrawStr(60, 38, buffer, A_NORMAL);
}
void draw_menu() {
ClrScr();
FontSetSys(F_8x10);
DrawStr(4, 2, "Falldown Impossible", A_NORMAL);
FontSetSys(F_4x6);
DrawStr(135, 12, "v1.0a", A_NORMAL);
FontSetSys(F_6x8);
DrawStr(0, 30, "2nd - Start Game", A_NORMAL);
DrawStr(0, 38, "Speed \x11 \x12", A_NORMAL);
draw_speed();
DrawStr(0, 46, "F1 - Help", A_NORMAL);
}
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() {
if (ball_x <= 0) { return; }
int i;
char *check;
if (ball_x % 8 == 0) {
for (i = 0; i < 6; i++) {
check = LCD_MEM + (LCD_ROW_BYTES * (ball_y + i)) + (ball_x / 8) - 1;
if (*check) { return; }
}
}
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() {
if (ball_x >= 153) { return; }
int i;
char *check;
if (ball_x % 8 == 2) {
for (i = 0; i < 6; i++) {
check = LCD_MEM + (LCD_ROW_BYTES * (ball_y + i)) + (ball_x / 8) + 1;
if (*check) { return; }
}
}
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 | KEYRIGHT)) == (KEYLEFT | KEYRIGHT)) return; // Dont you dare press both at the same time. Im watching you
if (key & KEYLEFT) {
move_left();
}
if (key & KEYRIGHT) {
move_right();
}
}
void _main(void) {
blocks = 0;
spacing_count = 38; max_spacing = 40; max_spacing_count = 0; platform_row = 4;
ball_x = 77; ball_y = 50;
draw_menu();
ngetchx();
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 key;
while (!(_rowread(ARROW_ROW) & NDKEY)) {
key = _rowread(ARROW_ROW);
if (key & KEYLEFT) {
speed -= 2;
draw_speed();
}
if (key & KEYRIGHT) {
speed += 2;
draw_speed();
}
delay(5000);
}
Sprite8(ball_x, ball_y, 6, ball, LCD_MEM, SPRT_XOR);
while (!(_rowread(ESCROW) & ESCKEY) && (ball_y > 0)) {
scroll_up();
draw_platform();
move_ball();
delay(600);
}
SetIntVec(AUTO_INT_1,interrupt1);
SetIntVec(AUTO_INT_5,interrupt5);
while ((key = ngetchx()) != KEY_ESC) {
}
// ngetchx();
ClrScr();
}