#include "test_support.h" u16 test_pixels[WIDTH * HEIGHT + 2]; unsigned char test_save[32]; void save_from_menu(void) { assert(!save_menu_input(0, 1)); assert(save_menu_input(START, 1) && save_menu.phase == SAVE_MENU_OPTIONS); assert(!save_menu_input(0, 1)); assert(save_menu_input(A, 1) && save_menu.phase == SAVE_MENU_SAVED); assert(!save_menu_input(0, 1)); assert(save_menu_input(B, 1) && save_menu.phase == SAVE_MENU_CLOSED); assert(!save_menu_input(0, 1)); } void render_scene(int x, int y) { draw_scene(x, y); } int reachable(int start_x, int start_y, int end_x, int end_y) { static unsigned char visited[HEIGHT][WIDTH]; static int queue[WIDTH * HEIGHT][2]; static const int directions[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; memset(visited, 0, sizeof(visited)); int head = 0, tail = 1; queue[0][0] = start_x; queue[0][1] = start_y; visited[start_y][start_x] = 1; while (head < tail) { int x = queue[head][0], y = queue[head][1]; ++head; if (x == end_x && y == end_y) return 1; for (int direction = 0; direction < 4; ++direction) { int nx = x + directions[direction][0], ny = y + directions[direction][1]; if (nx < 0 || nx >= WIDTH || ny < 0 || ny >= HEIGHT) continue; if (visited[ny][nx] || !can_walk(nx, ny)) continue; visited[ny][nx] = 1; queue[tail][0] = nx; queue[tail][1] = ny; ++tail; } } return 0; } void check_art(const char *const *art, int rows, int colors) { for (int row = 0; row < rows; ++row) { assert(strlen(art[row]) == 16); for (const char *p = art[row]; *p; ++p) { if (*p == '.') continue; int index = *p <= '9' ? *p - '0' : *p - 'A' + 10; assert(index > 0 && index < colors); } } } void write_preview(const char *path) { FILE *file = fopen(path, "wb"); assert(file); fprintf(file, "P6\n%d %d\n255\n", WIDTH, HEIGHT); for (int i = 0; i < WIDTH * HEIGHT; ++i) { u16 color = SCREEN[i]; fputc((color & 31) * 255 / 31, file); fputc(((color >> 5) & 31) * 255 / 31, file); fputc(((color >> 10) & 31) * 255 / 31, file); } assert(fclose(file) == 0); } /* Simulate the same row copies as hardware DMA, into a separate display. */ int pending_pixels(void) { int total = 0; for (int y = 0; y < HEIGHT; ++y) { assert(dirty_first[y] <= WIDTH && dirty_end[y] <= WIDTH); if (dirty_first[y] < dirty_end[y]) total += dirty_end[y] - dirty_first[y]; } return total; } void copy_pending_rows(u16 *visible) { for (int y = 0; y < HEIGHT; ++y) { int first = dirty_first[y], end = dirty_end[y]; if (first < end) memcpy(&visible[y * WIDTH + first], &SCREEN[y * WIDTH + first], (size_t)(end - first) * sizeof(u16)); } reset_dirty_rows(); }