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

@ -137,12 +137,9 @@ static void scroll_up(void) {
}
/**
* Prints the character and advances the cursor. Handles newlines.
* Print a single newline.
*/
void print_char(uint8_t c) {
uint8_t *loc = cursor_pos();
if (c == '\n') {
void print_newline(void) {
if (g_cursor_y == SCREEN_HEIGHT - 1) {
// Scroll.
hide_cursor();
@ -151,11 +148,27 @@ void print_char(uint8_t c) {
} else {
move_cursor(0, g_cursor_y + 1);
}
}
/**
* Prints the character and advances the cursor. Handles newlines.
*/
void print_char(uint8_t c) {
uint8_t *loc = cursor_pos();
if (c == '\n') {
print_newline();
} else {
// Print character.
*loc = c | 0x80;
// 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,12 +236,13 @@ void syntax_error_in_line(uint16_t line_number) {
* Switch to graphics mode.
*/
void gr_statement(void) {
if (!g_gr_mode) {
int i;
// Mixed text and lo-res graphics mode.
uint8_t *p = (uint8_t *) 49235U;
hide_cursor();
// Mixed text and lo-res graphics mode.
*p = 0;
// Clear the graphics area.
@ -249,20 +256,23 @@ void gr_statement(void) {
}
g_gr_mode = 1;
}
}
/**
* Switch to text mode.
*/
void text_statement(void) {
if (g_gr_mode) {
// Text mode.
uint8_t *p = (uint8_t *) 49233U;
hide_cursor();
// Mixed text and lo-res graphics mode.
*p = 0;
g_gr_mode = 0;
}
}
/**