diff --git a/README.md b/README.md index d994b3b..a167151 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ The Terminal is a Command line shell built into the kernel with an 8 entry comma ### Notepad -A text editor with a blinking cursor, arrow keys, Home, End, Delete, Backspace and Tab. Defaults to editing the file `/notes`. Using the `edit` command in shell allows editing of any file. +A text editor with a blinking cursor, arrow keys, Home, End, Delete, Backspace and Tab. Defaults to editing the file `records/notes`. Using the `edit` command in shell allows editing of any file. ### Files @@ -48,6 +48,10 @@ A simple file browser for navigating the file tree. Click a file to open it in N A simple calculator supporting `-`, `+`, `*`, `/`, and `%`, operated with the keyboard. +### Tetris + +The classic falling blocks game. Left/Right move, Up rotates, Down drops one row, Space drops all the way, `P` pauses and `R` restarts. The game speeds up every 10 rows cleared, and your best score is saved to the file `records/tetris_best` on the storage disk. + ### Hello A small example app demonstrating that apps can be loaded from the storage disk rather than being built into the kernel. @@ -58,7 +62,7 @@ Click an app on the home screen to launch it. The `-` button (or the `Esc` key) ### Builtin vs Loaded Apps -The Terminal is built into the kernel, while Calculator, Files, Hello, and Notepad are compiled separately and installed in the `apps` folder on the persistent storage disk and loaded by the launcher at startup. Loaded apps use the kernel's VIGIL API to access services such as graphics and the filesystem, they are not isolated from the kernel. +The Terminal is built into the kernel, while Calculator, Files, Hello, Tetris and Notepad are compiled separately and installed in the `apps` folder on the persistent storage disk and loaded by the launcher at startup. Loaded apps use the kernel's VIGIL API to access services such as graphics and the filesystem, they are not isolated from the kernel. ## How it works diff --git a/apps/calculator/calculator.h b/apps/calculator/calculator.h deleted file mode 100644 index 275fb21..0000000 --- a/apps/calculator/calculator.h +++ /dev/null @@ -1,13 +0,0 @@ -// apps/calculator/calculator.h - -#ifndef CALCULATOR_H -#define CALCULATOR_H -#include - -void calculator_start(void); -void calculator_redraw(void); - -void calculator_handle_char(char c); -void calculator_handle_click(int32_t x, int32_t y); - -#endif diff --git a/apps/notepad/notepad.c b/apps/notepad/notepad.c index 8c4f0cf..6917697 100644 --- a/apps/notepad/notepad.c +++ b/apps/notepad/notepad.c @@ -14,7 +14,7 @@ static const vigil_api_t* api = 0; // --- settings --- #define NOTEPAD_MAX_BYTES 2048 -#define NOTEPAD_DEFAULT_FILE "notes" +#define NOTEPAD_DEFAULT_FILE FS_RECORDS_FOLDER "/notes" #define NOTEPAD_TOP TITLE_BAR_HEIGHT #define NOTEPAD_BOTTOM TASKBAR_HEIGHT diff --git a/apps/tetris/tetris.c b/apps/tetris/tetris.c new file mode 100644 index 0000000..a607dc1 --- /dev/null +++ b/apps/tetris/tetris.c @@ -0,0 +1,270 @@ +// apps/tetris/tetris.c + +#include "tetris.h" + +// --- pieces --- + +static const int8_t piece_size[TETRIS_PIECE_KINDS] = { 4, 2, 3, 3, 3, 3, 3 }; + +static const int8_t piece_cells[TETRIS_PIECE_KINDS][4][2] = { + { {0, 1}, {1, 1}, {2, 1}, {3, 1} }, // I + { {0, 0}, {1, 0}, {0, 1}, {1, 1} }, // O + { {1, 0}, {0, 1}, {1, 1}, {2, 1} }, // T + { {1, 0}, {2, 0}, {0, 1}, {1, 1} }, // S + { {0, 0}, {1, 0}, {1, 1}, {2, 1} }, // Z + { {0, 0}, {0, 1}, {1, 1}, {2, 1} }, // J + { {2, 0}, {0, 1}, {1, 1}, {2, 1} }, // L +}; + +static const uint32_t line_points[5] = { 0, 100, 300, 500, 800 }; + +// --- state --- + +static uint8_t board[TETRIS_ROWS][TETRIS_COLS]; + +static int current_kind = 0; +static int current_rotation = 0; +static int current_x = 0; +static int current_y = 0; +static int ghost_y = 0; + +static int next_kind = 0; +static int game_over = 0; + +static uint32_t score = 0; +static uint32_t lines = 0; + +static uint32_t rng_state = 1; + +// --- random numbers --- + +static uint32_t next_random(void) { + uint32_t x = rng_state; + x ^= x << 13; + x ^= x >> 17; + x ^= x << 5; + rng_state = x; + return x; +} + +static int random_piece(void) { + return (int) (next_random() % TETRIS_PIECE_KINDS); +} + +// --- piece geometry --- + +static void piece_cell(int kind, int rotation, int index, int* out_x, int* out_y) { + int size = piece_size[kind]; + int x = piece_cells[kind][index][0]; + int y = piece_cells[kind][index][1]; + + for (int turn = 0; turn < rotation; turn++) { + int new_x = size - 1 - y; + int new_y = x; + x = new_x; + y = new_y; + } + + *out_x = x; + *out_y = y; +} + +static int fits(int kind, int rotation, int piece_x, int piece_y) { + for (int i = 0; i < 4; i++) { + int cell_x; + int cell_y; + piece_cell(kind, rotation, i, &cell_x, &cell_y); + + int col = piece_x + cell_x; + int row = piece_y + cell_y; + + if (col < 0 || col >= TETRIS_COLS || row < 0 || row >= TETRIS_ROWS) { + return 0; + } + if (board[row][col] != 0) { + return 0; + } + } + return 1; +} + +static void update_ghost(void) { + ghost_y = current_y; + while (fits(current_kind, current_rotation, current_x, ghost_y + 1)) { + ghost_y++; + } +} + +// --- piece landing --- + +static void spawn_piece(void) { + current_kind = next_kind; + next_kind = random_piece(); + current_rotation = 0; + current_x = (TETRIS_COLS - piece_size[current_kind]) / 2; + current_y = 0; + + if (!fits(current_kind, current_rotation, current_x, current_y)) { + game_over = 1; + } + update_ghost(); +} + +static void lock_piece(void) { + for (int i = 0; i < 4; i++) { + int cell_x; + int cell_y; + piece_cell(current_kind, current_rotation, i, &cell_x, &cell_y); + board[current_y + cell_y][current_x + cell_x] = (uint8_t) (current_kind + 1); + } +} + +static int clear_full_lines(void) { + int cleared = 0; + int row = TETRIS_ROWS - 1; + + while (row >= 0) { + int full = 1; + for (int col = 0; col < TETRIS_COLS; col++) { + if (board[row][col] == 0) { + full = 0; + break; + } + } + + if (!full) { + row--; + continue; + } + + for (int above = row; above > 0; above--) { + for (int col = 0; col < TETRIS_COLS; col++) { + board[above][col] = board[above - 1][col]; + } + } + for (int col = 0; col < TETRIS_COLS; col++) { + board[0][col] = 0; + } + cleared++; + } + + return cleared; +} + +// --- public funcs --- + +void tetris_start(uint32_t seed) { + for (int row = 0; row < TETRIS_ROWS; row++) { + for (int col = 0; col < TETRIS_COLS; col++) { + board[row][col] = 0; + } + } + + rng_state = (seed == 0) ? 1 : seed; + score = 0; + lines = 0; + game_over = 0; + + next_kind = random_piece(); + spawn_piece(); +} + +int tetris_move(int dx) { + if (game_over) { + return 0; + } + if (!fits(current_kind, current_rotation, current_x + dx, current_y)) { + return 0; + } + current_x += dx; + update_ghost(); + return 1; +} + +int tetris_rotate(void) { + if (game_over) { + return 0; + } + + static const int kicks[5] = { 0, -1, 1, -2, 2 }; + int new_rotation = (current_rotation + 1) % 4; + + for (int i = 0; i < 5; i++) { + if (fits(current_kind, new_rotation, current_x + kicks[i], current_y)) { + current_rotation = new_rotation; + current_x += kicks[i]; + update_ghost(); + return 1; + } + } + return 0; +} + +int tetris_step_down(void) { + if (game_over) { + return 0; + } + + if (fits(current_kind, current_rotation, current_x, current_y + 1)) { + current_y++; + return 1; + } + + lock_piece(); + int cleared = clear_full_lines(); + score += line_points[cleared] * tetris_level(); + lines += (uint32_t) cleared; + spawn_piece(); + return 0; +} + +void tetris_hard_drop(void) { + while (tetris_step_down()) { + } +} + +int tetris_cell_at(int col, int row) { + if (col < 0 || col >= TETRIS_COLS || row < 0 || row >= TETRIS_ROWS) { + return 0; + } + if (board[row][col] != 0) { + return board[row][col]; + } + + for (int i = 0; i < 4; i++) { + int cell_x; + int cell_y; + piece_cell(current_kind, current_rotation, i, &cell_x, &cell_y); + if (current_x + cell_x == col && current_y + cell_y == row) { + return current_kind + 1; + } + } + if (!game_over && ghost_y > current_y) { + for (int i = 0; i < 4; i++) { + int cell_x; + int cell_y; + piece_cell(current_kind, current_rotation, i, &cell_x, &cell_y); + if (current_x + cell_x == col && ghost_y + cell_y == row) { + return (current_kind + 1) | TETRIS_GHOST_FLAG; + } + } + } + return 0; +} + +int tetris_preview_cell_at(int col, int row) { + for (int i = 0; i < 4; i++) { + int cell_x; + int cell_y; + piece_cell(next_kind, 0, i, &cell_x, &cell_y); + if (cell_x == col && cell_y == row) { + return next_kind + 1; + } + } + return 0; +} + +int tetris_is_over(void) { return game_over; } +uint32_t tetris_score(void) { return score; } +uint32_t tetris_lines(void) { return lines; } +uint32_t tetris_level(void) { return lines / 10 + 1; } diff --git a/apps/tetris/tetris.h b/apps/tetris/tetris.h new file mode 100644 index 0000000..51143ca --- /dev/null +++ b/apps/tetris/tetris.h @@ -0,0 +1,35 @@ +// apps/tetris/tetris.h + +#ifndef TETRIS_H +#define TETRIS_H +#include + +#define TETRIS_COLS 10 +#define TETRIS_ROWS 20 +#define TETRIS_PIECE_KINDS 7 // I, O, T, S, Z, J, L +#define TETRIS_PREVIEW_SIZE 4 + +#define TETRIS_GHOST_FLAG 0x10 + +// --- game control --- + +void tetris_start(uint32_t seed); +int tetris_move(int dx); + +int tetris_rotate(void); +int tetris_step_down(void); + +void tetris_hard_drop(void); + +// --- reading the game --- + +int tetris_cell_at(int col, int row); + +int tetris_preview_cell_at(int col, int row); + +int tetris_is_over(void); +uint32_t tetris_score(void); +uint32_t tetris_lines(void); +uint32_t tetris_level(void); + +#endif diff --git a/apps/tetris/tetris_app.c b/apps/tetris/tetris_app.c new file mode 100644 index 0000000..62d223a --- /dev/null +++ b/apps/tetris/tetris_app.c @@ -0,0 +1,423 @@ +// apps/tetris/tetris_app.c + +#include "app.h" +#include "api.h" +#include "font.h" +#include "keyboard.h" +#include "title_bar.h" +#include "taskbar.h" +#include "tetris.h" + +// --- api pointer --- + +static const vigil_api_t* api = 0; + +// --- layout (pixels) --- + +#define CELL_SIZE 28 +#define BOARD_W (TETRIS_COLS * CELL_SIZE) +#define BOARD_H (TETRIS_ROWS * CELL_SIZE) + +#define PANEL_GAP 32 +#define PANEL_W 220 +#define TOTAL_W (BOARD_W + PANEL_GAP + PANEL_W) + +#define PREVIEW_PX (TETRIS_PREVIEW_SIZE * CELL_SIZE) + +#define NEXT_LABEL_Y 0 +#define PREVIEW_Y 24 +#define SCORE_LABEL_Y 160 +#define LEVEL_LABEL_Y 216 +#define LINES_LABEL_Y 272 +#define BEST_LABEL_Y 328 +#define VALUE_OFFSET 20 +#define STATUS_Y 384 +#define STATUS_H 56 +#define CONTROLS_Y 448 +#define CONTROLS_LINE_H 18 + +// --- colours --- + +#define LABEL_COLOR ((gfx_color_t){0x90, 0x90, 0x90}) +#define GRID_COLOR ((gfx_color_t){0x24, 0x24, 0x24}) +#define GOLD_COLOR ((gfx_color_t){0xff, 0xd0, 0x40}) + +static const gfx_color_t piece_colors[TETRIS_PIECE_KINDS + 2] = { + { 0x0a, 0x0a, 0x0a }, // 0 = empty square + { 0x00, 0xc8, 0xe0 }, // 1 = I (cyan) + { 0xe8, 0xd8, 0x20 }, // 2 = O (yellow) + { 0xa0, 0x40, 0xd0 }, // 3 = T (purple) + { 0x30, 0xc0, 0x40 }, // 4 = S (green) + { 0xd8, 0x30, 0x30 }, // 5 = Z (red) + { 0x30, 0x50, 0xe0 }, // 6 = J (blue) + { 0xf0, 0x90, 0x20 }, // 7 = L (orange) + + { 0x66, 0x66, 0x66 }, // 8 = ghost block +}; + +// --- speed --- + +#define DROP_START_MS 800 +#define DROP_STEP_MS 70 +#define DROP_MIN_MS 100 + +// --- saved high score --- + +#define BEST_FILE FS_RECORDS_FOLDER "/tetris_best" + +// --- state --- + +static uint32_t origin_x = 0; +static uint32_t origin_y = 0; +static uint32_t panel_x = 0; + +static uint8_t shown[TETRIS_ROWS][TETRIS_COLS]; + +static uint32_t last_drop = 0; +static int paused = 0; + +static uint32_t best_score = 0; +static int over_handled = 0; +static int new_best = 0; +static int save_failed = 0; +static int ghost_enabled = 1; + +// --- saving and loading highscore --- + +static void load_best(void) { + char text[16]; + uint32_t size = 0; + + best_score = 0; + + int result = api->fs_read_file(BEST_FILE, (uint8_t*) text, sizeof(text) - 1, &size); + if (result != FS_OK) { + return; + } + + for (uint32_t i = 0; i < size && i < 9; i++) { + if (text[i] < '0' || text[i] > '9') { + break; + } + best_score = best_score * 10 + (uint32_t) (text[i] - '0'); + } +} + +static void save_best(void) { + char text[12]; + api->kuitoa(best_score, text); + + int result = api->fs_write_file(BEST_FILE, (const uint8_t*) text, api->kstrlen(text)); + save_failed = (result != FS_OK); +} + +static void check_game_over(void) { + if (!tetris_is_over() || over_handled) { + return; + } + over_handled = 1; + + if (tetris_score() > best_score) { + best_score = tetris_score(); + new_best = 1; + save_best(); + } +} + +// --- layout --- + +static uint32_t band_height(void) { + uint32_t used = TITLE_BAR_HEIGHT + TASKBAR_HEIGHT; + if (api->gfx_screen_height() > used) { + return api->gfx_screen_height() - used; + } + return 0; +} + +static void compute_layout(void) { + origin_x = 0; + if (api->gfx_screen_width() > TOTAL_W) { + origin_x = (api->gfx_screen_width() - TOTAL_W) / 2; + } + + origin_y = TITLE_BAR_HEIGHT; + if (band_height() > BOARD_H) { + origin_y += (band_height() - BOARD_H) / 2; + } + + panel_x = origin_x + BOARD_W + PANEL_GAP; +} + +// --- drawing --- + +static void draw_cell(uint32_t x, uint32_t y, int value) { + api->gfx_fill_rect(x, y, CELL_SIZE, CELL_SIZE, GRID_COLOR); + + if (value & TETRIS_GHOST_FLAG) { + api->gfx_fill_rect(x + 1, y + 1, CELL_SIZE - 2, CELL_SIZE - 2, piece_colors[0]); + api->gfx_draw_rect_outline(x + 2, y + 2, CELL_SIZE - 4, CELL_SIZE - 4, piece_colors[8]); + api->gfx_draw_rect_outline(x + 3, y + 3, CELL_SIZE - 6, CELL_SIZE - 6, piece_colors[8]); + return; + } + + api->gfx_fill_rect(x + 1, y + 1, CELL_SIZE - 2, CELL_SIZE - 2, piece_colors[value]); +} + +static void refresh_board(void) { + for (int row = 0; row < TETRIS_ROWS; row++) { + for (int col = 0; col < TETRIS_COLS; col++) { + int value = tetris_cell_at(col, row); + if (!ghost_enabled && (value & TETRIS_GHOST_FLAG)) { + value = 0; + } + if (value == shown[row][col]) { + continue; + } + + draw_cell( + origin_x + (uint32_t) col * CELL_SIZE, + origin_y + (uint32_t) row * CELL_SIZE, + value + ); + shown[row][col] = (uint8_t) value; + } + } +} + +static void draw_preview(void) { + uint32_t box_x = panel_x; + uint32_t box_y = origin_y + PREVIEW_Y; + + api->gfx_fill_rect(box_x, box_y, PREVIEW_PX, PREVIEW_PX, GFX_BLACK); + + for (int row = 0; row < TETRIS_PREVIEW_SIZE; row++) { + for (int col = 0; col < TETRIS_PREVIEW_SIZE; col++) { + int value = tetris_preview_cell_at(col, row); + if (value != 0) { + draw_cell(box_x + (uint32_t) col * CELL_SIZE, box_y + (uint32_t) row * CELL_SIZE, value); + } + } + } +} + +static void draw_number(uint32_t label_y, uint32_t value) { + char number[12]; + uint32_t y = origin_y + label_y + VALUE_OFFSET; + + api->gfx_fill_rect(panel_x, y, PANEL_W, FONT_HEIGHT, GFX_BLACK); + api->kuitoa(value, number); + api->gfx_draw_string(panel_x, y, number, GFX_WHITE); +} + +static void draw_stats(void) { + draw_number(SCORE_LABEL_Y, tetris_score()); + draw_number(LEVEL_LABEL_Y, tetris_level()); + draw_number(LINES_LABEL_Y, tetris_lines()); + draw_number(BEST_LABEL_Y, best_score); +} + +static void draw_status(void) { + uint32_t y = origin_y + STATUS_Y; + api->gfx_fill_rect(panel_x, y, PANEL_W, STATUS_H, GFX_BLACK); + + if (tetris_is_over()) { + api->gfx_draw_string(panel_x, y, "GAME OVER", GFX_RED); + + if (new_best) { + api->gfx_draw_string(panel_x, y + 20, "New best score!", GOLD_COLOR); + } + if (save_failed) { + api->gfx_draw_string(panel_x, y + 38, "Could not save score", GFX_RED); + } else { + api->gfx_draw_string(panel_x, y + 38, "Press R to play again", GFX_WHITE); + } + } else if (paused) { + api->gfx_draw_string(panel_x, y, "PAUSED", GFX_GREEN); + api->gfx_draw_string(panel_x, y + 20, "Press P to resume", GFX_WHITE); + } +} + +static void draw_side_panel(void) { + draw_preview(); + draw_stats(); + draw_status(); +} + +static void draw_labels(void) { + api->gfx_draw_string(panel_x, origin_y + NEXT_LABEL_Y, "NEXT", LABEL_COLOR); + api->gfx_draw_string(panel_x, origin_y + SCORE_LABEL_Y, "SCORE", LABEL_COLOR); + api->gfx_draw_string(panel_x, origin_y + LEVEL_LABEL_Y, "LEVEL", LABEL_COLOR); + api->gfx_draw_string(panel_x, origin_y + LINES_LABEL_Y, "LINES", LABEL_COLOR); + api->gfx_draw_string(panel_x, origin_y + BEST_LABEL_Y, "BEST", LABEL_COLOR); + + static const char* const controls[] = { + "Left/Right: move", + "Up: rotate", + "Down: soft drop", + "Space: hard drop", + "P: pause", + "R: restart", + "G: toggle ghost", + "Esc: minimize", + }; + int count = (int) (sizeof(controls) / sizeof(controls[0])); + + for (int i = 0; i < count; i++) { + api->gfx_draw_string( + panel_x, + origin_y + CONTROLS_Y + (uint32_t) i * CONTROLS_LINE_H, + controls[i], + LABEL_COLOR + ); + } +} + +static void paint(void) { + api->gfx_fill_rect(0, TITLE_BAR_HEIGHT, api->gfx_screen_width(), band_height(), GFX_BLACK); + api->gfx_draw_rect_outline(origin_x - 2, origin_y - 2, BOARD_W + 4, BOARD_H + 4, GFX_WHITE); + + for (int row = 0; row < TETRIS_ROWS; row++) { + for (int col = 0; col < TETRIS_COLS; col++) { + shown[row][col] = 0xff; + } + } + + refresh_board(); + draw_labels(); + draw_side_panel(); +} + +// --- game flow --- + +static uint32_t drop_interval_ticks(void) { + uint32_t speedup = (tetris_level() - 1) * DROP_STEP_MS; + uint32_t ms = DROP_MIN_MS; + if (speedup < DROP_START_MS - DROP_MIN_MS) { + ms = DROP_START_MS - speedup; + } + + uint32_t ticks = (api->timer_get_frequency() * ms) / 1000; + return (ticks == 0) ? 1 : ticks; +} + +static void new_game(void) { + uint32_t now = api->timer_get_ticks(); + + tetris_start(now * 2654435761u + 1); + + paused = 0; + over_handled = 0; + new_best = 0; + save_failed = 0; + last_drop = now; + + paint(); +} + +static void after_step(int moved) { + api->mouse_hide_cursor(); + refresh_board(); + + if (!moved) { + check_game_over(); + draw_side_panel(); + } +} + +static void after_move(int changed) { + if (changed) { + api->mouse_hide_cursor(); + refresh_board(); + } +} + +// --- app_t slots --- + +static void tetris_app_start(void) { + compute_layout(); + load_best(); + new_game(); +} + +static void tetris_app_redraw(void) { + compute_layout(); + last_drop = api->timer_get_ticks(); + paint(); +} + +static void tetris_app_key(char c) { + // R works any time, even after game over + if (c == 'r' || c == 'R') { + api->mouse_hide_cursor(); + new_game(); + return; + } + + if (c == 'g' || c == 'G') { + ghost_enabled = !ghost_enabled; + api->mouse_hide_cursor(); + refresh_board(); + return; + } + + if (tetris_is_over()) { + return; + } + + if (c == 'p' || c == 'P') { + paused = !paused; + last_drop = api->timer_get_ticks(); + api->mouse_hide_cursor(); + draw_status(); + return; + } + + if (paused) { + return; + } + + if (c == KEY_ARROW_LEFT) { + after_move(tetris_move(-1)); + } else if (c == KEY_ARROW_RIGHT) { + after_move(tetris_move(1)); + } else if (c == KEY_ARROW_UP) { + after_move(tetris_rotate()); + } else if (c == KEY_ARROW_DOWN) { + last_drop = api->timer_get_ticks(); + after_step(tetris_step_down()); + } else if (c == ' ') { + tetris_hard_drop(); + last_drop = api->timer_get_ticks(); + after_step(0); + } +} + +static void tetris_app_tick(void) { + if (paused || tetris_is_over()) { + return; + } + + uint32_t now = api->timer_get_ticks(); + if (now - last_drop < drop_interval_ticks()) { + return; + } + + last_drop = now; + after_step(tetris_step_down()); +} + +// --- entry point --- + +int app_entry(const vigil_api_t* kernel_api, app_t* out_app) { + if (kernel_api->version != VIGIL_API_VERSION || kernel_api->struct_size < sizeof(vigil_api_t)) { + return 1; + } + api = kernel_api; + + out_app->name = "Tetris"; + out_app->start = tetris_app_start; + out_app->redraw = tetris_app_redraw; + out_app->on_key = tetris_app_key; + out_app->on_tick = tetris_app_tick; + return 0; +} diff --git a/kernel/fs/fs.h b/kernel/fs/fs.h index 194c7b0..50bb6fd 100644 --- a/kernel/fs/fs.h +++ b/kernel/fs/fs.h @@ -8,6 +8,8 @@ #define FS_MAX_FILES 32 #define FS_MAX_PATH 64 +#define FS_RECORDS_FOLDER "records" + // --- return codes --- #define FS_OK 0 diff --git a/kernel/kernel.c b/kernel/kernel.c index a67fa66..2e41831 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -35,6 +35,7 @@ void kernel_main(void) { mouse_install(); enable_interrupts(); + fs_make_folder(FS_RECORDS_FOLDER); launcher_init(); for (;;) { diff --git a/scripts/build.bat b/scripts/build.bat index f7148bd..f797a13 100644 --- a/scripts/build.bat +++ b/scripts/build.bat @@ -213,6 +213,16 @@ if errorlevel 1 goto :error i686-elf-objcopy -O binary build/notepad.elf build/notepad.vapp if errorlevel 1 goto :error +echo Building app: tetris (slot 4 = 0x500000)... +i686-elf-gcc %APP_CFLAGS% -Iapps/tetris -c apps/tetris/tetris.c -o build/tetris_engine.o +if errorlevel 1 goto :error +i686-elf-gcc %APP_CFLAGS% -Iapps/tetris -c apps/tetris/tetris_app.c -o build/tetris_app.o +if errorlevel 1 goto :error +i686-elf-ld -T apps/sdk/app.ld -Ttext=0x500000 -o build/tetris.elf build/tetris_app.o build/tetris_engine.o +if errorlevel 1 goto :error +i686-elf-objcopy -O binary build/tetris.elf build/tetris.vapp +if errorlevel 1 goto :error + echo. :: link build files using linker script @@ -297,6 +307,8 @@ python tools/install_app.py dist/storage.img build/files.vapp apps/files if errorlevel 1 goto :error python tools/install_app.py dist/storage.img build/notepad.vapp apps/notepad if errorlevel 1 goto :error +python tools/install_app.py dist/storage.img build/tetris.vapp apps/tetris +if errorlevel 1 goto :error echo. :: successful build