mirror of
https://github.com/bradgrantham/apple2a.git
synced 2024-06-09 18:29:33 +00:00
Wrap text at screen edge; double input buffer.
This commit is contained in:
parent
c4613c6a08
commit
23fa9e4e01
7
main.c
7
main.c
|
@ -124,7 +124,7 @@ static uint8_t *TOKEN[] = {
|
||||||
};
|
};
|
||||||
static int16_t TOKEN_COUNT = sizeof(TOKEN)/sizeof(TOKEN[0]);
|
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;
|
int16_t g_input_buffer_length = 0;
|
||||||
|
|
||||||
// Compiled binary.
|
// Compiled binary.
|
||||||
|
@ -1087,10 +1087,7 @@ int16_t main(void)
|
||||||
g_input_buffer_length = 0;
|
g_input_buffer_length = 0;
|
||||||
} else {
|
} else {
|
||||||
if (g_input_buffer_length < sizeof(g_input_buffer) - 1) {
|
if (g_input_buffer_length < sizeof(g_input_buffer) - 1) {
|
||||||
uint8_t *loc = cursor_pos();
|
print_char(key);
|
||||||
*loc = key | 0x80;
|
|
||||||
move_cursor(g_cursor_x + 1, g_cursor_y);
|
|
||||||
|
|
||||||
g_input_buffer[g_input_buffer_length++] = key;
|
g_input_buffer[g_input_buffer_length++] = key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
82
runtime.c
82
runtime.c
|
@ -136,6 +136,20 @@ static void scroll_up(void) {
|
||||||
memset(previous_line, CLEAR_CHAR, SCREEN_WIDTH);
|
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.
|
* Prints the character and advances the cursor. Handles newlines.
|
||||||
*/
|
*/
|
||||||
|
@ -143,18 +157,17 @@ void print_char(uint8_t c) {
|
||||||
uint8_t *loc = cursor_pos();
|
uint8_t *loc = cursor_pos();
|
||||||
|
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
if (g_cursor_y == SCREEN_HEIGHT - 1) {
|
print_newline();
|
||||||
// Scroll.
|
|
||||||
hide_cursor();
|
|
||||||
scroll_up();
|
|
||||||
move_cursor(0, g_cursor_y);
|
|
||||||
} else {
|
|
||||||
move_cursor(0, g_cursor_y + 1);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Print character.
|
// Print character.
|
||||||
*loc = c | 0x80;
|
*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_char('0' + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Print a single newline.
|
|
||||||
*/
|
|
||||||
void print_newline(void) {
|
|
||||||
print_char('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a syntax error message.
|
* Display a syntax error message.
|
||||||
*/
|
*/
|
||||||
|
@ -230,39 +236,43 @@ void syntax_error_in_line(uint16_t line_number) {
|
||||||
* Switch to graphics mode.
|
* Switch to graphics mode.
|
||||||
*/
|
*/
|
||||||
void gr_statement(void) {
|
void gr_statement(void) {
|
||||||
int i;
|
if (!g_gr_mode) {
|
||||||
uint8_t *p = (uint8_t *) 49235U;
|
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.
|
// Clear the graphics area.
|
||||||
for (i = 0; i < MIXED_GRAPHICS_HEIGHT; i++) {
|
for (i = 0; i < MIXED_GRAPHICS_HEIGHT; i++) {
|
||||||
memset(screen_pos(0, i), 0, SCREEN_WIDTH);
|
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.
|
* Switch to text mode.
|
||||||
*/
|
*/
|
||||||
void text_statement(void) {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user