From b33ebdfd1087bd1de038e23fd256ad5cc6576cfd Mon Sep 17 00:00:00 2001 From: Väinö Kauppila Date: Mon, 20 Apr 2026 15:11:08 +0300 Subject: 4K progmem --- fw/snake.c | 60 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 27 deletions(-) (limited to 'fw/snake.c') diff --git a/fw/snake.c b/fw/snake.c index a57d241..550bee2 100644 --- a/fw/snake.c +++ b/fw/snake.c @@ -8,7 +8,7 @@ __sfr __at(0x72) UART_STATUS; #define GRID_W 20 #define GRID_H 10 -#define MAX_LEN 20 +#define MAX_LEN 10 #define OVF_PER_FRAME 60 #define DIR_UP 0 @@ -16,14 +16,14 @@ __sfr __at(0x72) UART_STATUS; #define DIR_LEFT 2 #define DIR_RIGHT 3 -static uint8_t snake_x[MAX_LEN]; -static uint8_t snake_y[MAX_LEN]; -static uint8_t snake_len; -static uint8_t direction; -static uint8_t food_x; -static uint8_t food_y; -static uint8_t score; -static volatile uint8_t ovf_count; +static __near uint8_t snake_x[MAX_LEN]; +static __near uint8_t snake_y[MAX_LEN]; +static __near uint8_t snake_len; +static __near uint8_t direction; +static __near uint8_t food_x; +static __near uint8_t food_y; +static __near uint8_t score; +static volatile __near uint8_t ovf_count; void isr(void) __interrupt(0) { if (INTCON & 0x04) { @@ -65,21 +65,27 @@ static void handle_input(void) { } static void place_food(void) { - food_x = (ovf_count * 7 + 3) % GRID_W; - food_y = (ovf_count * 5 + 1) % GRID_H; + uint8_t x = ovf_count; + uint8_t y = ovf_count; + x += x; x += x; x += x; x -= ovf_count; x += 3; /* x = ovf*7 + 3 */ + y += y; y += y; y += ovf_count; y += 1; /* y = ovf*5 + 1 */ + while (x >= GRID_W) x -= GRID_W; + while (y >= GRID_H) y -= GRID_H; + food_x = x; + food_y = y; } -static void print_uint8(uint8_t v) { - uint8_t started = 0; - if (v >= 200) { uart_send('2'); v -= 200; started = 1; } - else if (v >= 100) { uart_send('1'); v -= 100; started = 1; } - { - uint8_t t = '0'; - while (v >= 10) { v -= 10; t++; } - if (started || t != '0') uart_send(t); - } - uart_send(v + '0'); -} +/* static void print_uint8(uint8_t v) { */ +/* uint8_t started = 0; */ +/* if (v >= 200) { uart_send('2'); v -= 200; started = 1; } */ +/* else if (v >= 100) { uart_send('1'); v -= 100; started = 1; } */ +/* { */ +/* uint8_t t = '0'; */ +/* while (v >= 10) { v -= 10; t++; } */ +/* if (started || t != '0') uart_send(t); */ +/* } */ +/* uart_send(v + '0'); */ +/* } */ static void render(void) { uint8_t x, y, i; @@ -115,8 +121,8 @@ static void render(void) { for (x = 0; x < GRID_W; x++) uart_send('-'); uart_puts("+\r\n"); - uart_puts("Score: "); - print_uint8(score); + /* uart_puts("Score: "); */ + /* print_uint8(score); */ uart_puts(" \r\n"); } @@ -186,9 +192,9 @@ void main(void) { } uart_puts("\x1B[2J\x1B[H"); - uart_puts("GAME OVER score: "); - print_uint8(score); - uart_puts("\r\npress any key\r\n"); + /* uart_puts("GAME OVER score: "); */ + /* print_uint8(score); */ + /* uart_puts("\r\npress any key\r\n"); */ uart_getc(); } } -- cgit v1.3