void move_cursor(WINDOW* wnd, int x, int y) { assert(x >= 0 && x < wnd->width && y >= 0 && y < wnd->height); // assert(0) causes always failure wnd->cursor_x = x; wnd->cursor_y = y; if (wnd->cursor_x >= wnd->width) { wnd->cursor_x = 0; wnd->cursor_y++; } if (wnd->cursor_y >= wnd->height) { int x_len = wnd->x + wnd->width; int y_len = wnd->y + wnd->height; int i, j, offset_1, offset_2; for (i = wnd->x; i < x_len; i++) { for (j = wnd->y; j < y_len; j++) { offset_1 = j * (80 * 2) + i * 2; offset_2 = (j + 1) * (80 * 2) + i * 2; poke_w(0xb8000 + offset_1, peek_b(0xb8000 + offset_2) | 0x0f00); poke_w(0xb8000 + offset_2, 0x0020); } } wnd->cursor_y--; } }
void output_string(WINDOW* wnd, const char *str){ volatile int saved_if; DISABLE_INTR(saved_if); short tempchar; int len, i = 0; len = k_strlen(str); while(i < len){ tempchar = (0x0f << 8) | str[i]; if(str[i] != '\n'){ poke_w(0xb8000 + ((wnd->x + wnd->cursor_x)*2) + ((wnd->y + wnd->cursor_y)*160) , tempchar); } if(wnd->cursor_x+1 >= wnd->width || str[i] == '\n'){ if(wnd->cursor_y +1 >= wnd->height){ scroll(wnd); } else{wnd->cursor_y++;} wnd->cursor_x =0; } else{ wnd->cursor_x++; } i++; } ENABLE_INTR(saved_if); }
void show_cursor(WINDOW* wnd){ volatile int saved_if; DISABLE_INTR(saved_if); short cursor = (0x82 << 8) | wnd->cursor_char; poke_w(0xb8000 + ((wnd->x + wnd->cursor_x)*2) + ((wnd->y + wnd->cursor_y)*160) , cursor); ENABLE_INTR(saved_if); }
void clear_window(WINDOW* wnd) { int i; MEM_ADDR offset = wnd->y * (79 * 2) + wnd->x * 2; for (i = 0; i < wnd->width * wnd->height; i++) poke_w(0xb8000 + offset + i * 2, 0); wnd->cursor_x = 0; wnd->cursor_y = 0; show_cursor(wnd); }
void output_char(WINDOW* wnd, unsigned char c) { remove_cursor(wnd); MEM_ADDR offset = (wnd->cursor_y + wnd->y) * (80 * 2) + (wnd->x + wnd->cursor_x) * 2; if (c == '\n') { move_cursor(wnd, 0, wnd->cursor_y + 1); } else { poke_w(0xb8000 + offset, c | 0x0f00); move_cursor(wnd, wnd->cursor_x + 1, wnd->cursor_y); } show_cursor(wnd); }
void clear_window(WINDOW* wnd){ volatile int saved_if; DISABLE_INTR(saved_if); int w, h; for(h=0; h < wnd->height; h++){ for(w=0; w < wnd->width; w++){ poke_w(0xb8000 + ((wnd->x + w)*2) + ((wnd->y + h)*160) ,0); } } wnd->cursor_x = 0; wnd->cursor_y = 0; ENABLE_INTR(saved_if); }
void move_ghost(GHOST *ghost) { int x, y; WORD *cl; volatile int saved_if; DISABLE_INTR(saved_if); while (1) { x = (random() % 4) - 1; y = 0; if ((x % 2) == 0) { y = x - 1; x = 0; } if (maze[ghost->y + y][ghost->x + x] == ' ') { break; } } /* save ghost locations in maze */ /* add/remove characters from pacman_wnd directly as only 1 cursor per window */ maze[ghost->y][ghost->x] = ' '; cl = (WORD*)WINDOW_BASE_ADDR + WINDOW_OFFSET(pacman_wnd, ghost->x, ghost->y); poke_w((MEM_ADDR)cl, ' ' | 0x0F00); ghost->x += x; ghost->y += y; maze[ghost->y][ghost->x] = GHOST_CHAR; cl = (WORD*)WINDOW_BASE_ADDR + WINDOW_OFFSET(pacman_wnd, ghost->x, ghost->y); poke_w((MEM_ADDR)cl, GHOST_CHAR | 0x0F00); ENABLE_INTR(saved_if); }
void output_char(WINDOW* wnd, unsigned char c){ volatile int saved_if; DISABLE_INTR(saved_if); short tempchar = (0x0f << 8) | c; if(c != '\n'){ poke_w(0xb8000 + ((wnd->x + wnd->cursor_x)*2) + ((wnd->y + wnd->cursor_y)*160) , tempchar); } if(wnd->cursor_x+1 >= wnd->width || c == '\n'){ if(wnd->cursor_y +1 >= wnd->height){ scroll(wnd); } else{wnd->cursor_y++;} wnd->cursor_x =0; } else{ wnd->cursor_x++; } ENABLE_INTR(saved_if); }
void poke_screen(int x, int y, WORD ch) { poke_w(SCREEN_BASE_ADDR + y * SCREEN_WIDTH * 2 + x * 2, ch); }
void poke_screen(int x, int y, WORD ch) { poke_w(DISP_START_ADDR + y * DISP_WIDTH * 2 + x * 2, ch); }
void remove_cursor(WINDOW* wnd){ volatile int saved_if; DISABLE_INTR(saved_if); poke_w(0xb8000 + ((wnd->x + wnd->cursor_x)*2) + ((wnd->y + wnd->cursor_y)*160) , 0); ENABLE_INTR(saved_if); }
void show_cursor(WINDOW* wnd) { MEM_ADDR offset = (wnd->cursor_y + wnd->y) * (80 * 2) + (wnd->x + wnd->cursor_x) * 2; // wnd->cursor_char = 0x5f; poke_w(0xb8000 + offset, wnd->cursor_char | 0x0f00); }
void remove_cursor(WINDOW* wnd) { MEM_ADDR offset = (wnd->cursor_y + wnd->y) * (80 * 2) + (wnd->x + wnd->cursor_x) * 2; poke_w(0xb8000 + offset, 0x0020); }