Wrap text at screen edge; double input buffer.

This commit is contained in:
Lawrence Kesteloot 2018-08-03 22:39:23 -07:00
parent c4613c6a08
commit 23fa9e4e01
2 changed files with 48 additions and 41 deletions

7
main.c
View File

@ -124,7 +124,7 @@ static uint8_t *TOKEN[] = {
};
static int16_t TOKEN_COUNT = sizeof(TOKEN)/sizeof(TOKEN[0]);
uint8_t g_input_buffer[40];
uint8_t g_input_buffer[80];
int16_t g_input_buffer_length = 0;
// Compiled binary.
@ -1087,10 +1087,7 @@ int16_t main(void)
g_input_buffer_length = 0;
} else {
if (g_input_buffer_length < sizeof(g_input_buffer) - 1) {
uint8_t *loc = cursor_pos();
*loc = key | 0x80;
move_cursor(g_cursor_x + 1, g_cursor_y);
print_char(key);
g_input_buffer[g_input_buffer_length++] = key;
}
}

View File

@ -136,6 +136,20 @@ static void scroll_up(void) {
memset(previous_line, CLEAR_CHAR, SCREEN_WIDTH);
}
/**
* Print a single newline.
*/
void print_newline(void) {
if (g_cursor_y == SCREEN_HEIGHT - 1) {
// Scroll.
hide_cursor();
scroll_up();
move_cursor(0, g_cursor_y);
} else {
move_cursor(0, g_cursor_y + 1);
}
}
/**
* Prints the character and advances the cursor. Handles newlines.
*/
@ -143,18 +157,17 @@ void print_char(uint8_t c) {
uint8_t *loc = cursor_pos();
if (c == '\n') {
if (g_cursor_y == SCREEN_HEIGHT - 1) {
// Scroll.
hide_cursor();
scroll_up();
move_cursor(0, g_cursor_y);
} else {
move_cursor(0, g_cursor_y + 1);
}
print_newline();
} else {
// Print character.
*loc = c | 0x80;
move_cursor(g_cursor_x + 1, g_cursor_y);
// Advance cursor or wrap.
if (g_cursor_x == SCREEN_WIDTH - 1) {
print_newline();
} else {
move_cursor(g_cursor_x + 1, g_cursor_y);
}
}
}
@ -201,13 +214,6 @@ void print_int(uint16_t i) {
print_char('0' + i);
}
/**
* Print a single newline.
*/
void print_newline(void) {
print_char('\n');
}
/**
* Display a syntax error message.
*/
@ -230,39 +236,43 @@ void syntax_error_in_line(uint16_t line_number) {
* Switch to graphics mode.
*/
void gr_statement(void) {
int i;
uint8_t *p = (uint8_t *) 49235U;
if (!g_gr_mode) {
int i;
// Mixed text and lo-res graphics mode.
uint8_t *p = (uint8_t *) 49235U;
hide_cursor();
hide_cursor();
// Mixed text and lo-res graphics mode.
*p = 0;
*p = 0;
// Clear the graphics area.
for (i = 0; i < MIXED_GRAPHICS_HEIGHT; i++) {
memset(screen_pos(0, i), 0, SCREEN_WIDTH);
// Clear the graphics area.
for (i = 0; i < MIXED_GRAPHICS_HEIGHT; i++) {
memset(screen_pos(0, i), 0, SCREEN_WIDTH);
}
// Move the cursor to the text window.
if (g_cursor_y < MIXED_GRAPHICS_HEIGHT) {
move_cursor(0, MIXED_GRAPHICS_HEIGHT);
}
g_gr_mode = 1;
}
// Move the cursor to the text window.
if (g_cursor_y < MIXED_GRAPHICS_HEIGHT) {
move_cursor(0, MIXED_GRAPHICS_HEIGHT);
}
g_gr_mode = 1;
}
/**
* Switch to text mode.
*/
void text_statement(void) {
uint8_t *p = (uint8_t *) 49233U;
if (g_gr_mode) {
// Text mode.
uint8_t *p = (uint8_t *) 49233U;
hide_cursor();
hide_cursor();
// Mixed text and lo-res graphics mode.
*p = 0;
*p = 0;
g_gr_mode = 0;
g_gr_mode = 0;
}
}
/**