mirror of
https://github.com/bradgrantham/apple2a.git
synced 2024-05-29 06:41:31 +00:00
Add printing of negative numbers.
This commit is contained in:
parent
84d9a7ce82
commit
5569b9f58c
2
main.c
2
main.c
|
@ -262,7 +262,7 @@ static void list_statement() {
|
||||||
print_newline();
|
print_newline();
|
||||||
|
|
||||||
while ((next_line = get_next_line(line)) != 0) {
|
while ((next_line = get_next_line(line)) != 0) {
|
||||||
print_int(get_line_number(line));
|
print_uint(get_line_number(line));
|
||||||
print_char(' ');
|
print_char(' ');
|
||||||
print_detokenized(line + 4);
|
print_detokenized(line + 4);
|
||||||
|
|
||||||
|
|
17
runtime.c
17
runtime.c
|
@ -223,11 +223,12 @@ void print(uint8_t *s) {
|
||||||
/**
|
/**
|
||||||
* Print an unsigned integer.
|
* Print an unsigned integer.
|
||||||
*/
|
*/
|
||||||
void print_int(uint16_t i) {
|
void print_uint(uint16_t i) {
|
||||||
// Is this the best way to do this? I've seen it done backwards, where
|
// Is this the best way to do this? I've seen it done backwards, where
|
||||||
// digits are added to a buffer least significant digit first, then reversed,
|
// digits are added to a buffer least significant digit first, then reversed,
|
||||||
// but this seems faster.
|
// but this seems faster.
|
||||||
char printed = 0;
|
char printed = 0;
|
||||||
|
|
||||||
if (i >= 10000) {
|
if (i >= 10000) {
|
||||||
int16_t r = i / 10000;
|
int16_t r = i / 10000;
|
||||||
print_char('0' + r);
|
print_char('0' + r);
|
||||||
|
@ -254,6 +255,18 @@ void print_int(uint16_t i) {
|
||||||
print_char('0' + i);
|
print_char('0' + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print a signed integer.
|
||||||
|
*/
|
||||||
|
void print_int(int16_t i) {
|
||||||
|
if ((i & 0x8000) != 0) {
|
||||||
|
print_char('-');
|
||||||
|
i = -i;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_uint((uint16_t) i);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print an error message, optionally with a line number if it's
|
* Print an error message, optionally with a line number if it's
|
||||||
* not INVALID_LINE_NUMBER.
|
* not INVALID_LINE_NUMBER.
|
||||||
|
@ -264,7 +277,7 @@ static void generic_error_message(uint8_t *message, uint16_t line_number) {
|
||||||
|
|
||||||
if (line_number != INVALID_LINE_NUMBER) {
|
if (line_number != INVALID_LINE_NUMBER) {
|
||||||
print(" IN ");
|
print(" IN ");
|
||||||
print_int(line_number);
|
print_uint(line_number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,8 @@ void home(void);
|
||||||
|
|
||||||
void print(uint8_t *s);
|
void print(uint8_t *s);
|
||||||
void print_char(uint8_t c);
|
void print_char(uint8_t c);
|
||||||
void print_int(uint16_t i);
|
void print_uint(uint16_t i);
|
||||||
|
void print_int(int16_t i);
|
||||||
void print_newline(void);
|
void print_newline(void);
|
||||||
|
|
||||||
void for_statement(uint16_t line_number, uint16_t var_address, int16_t end_value, int16_t step,
|
void for_statement(uint16_t line_number, uint16_t var_address, int16_t end_value, int16_t step,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user