
byte* line_cursor = $0400;
byte* char_cursor = line_cursor;

// Print a zero-terminated string
void print_str(byte* str) {
    while(*str!='@') {
        *(char_cursor++) = *(str++);
    }
}

// Print a newline
void print_ln() {
    do {
        line_cursor = line_cursor + $28;
    } while (line_cursor<char_cursor);
    char_cursor = line_cursor;
}

// Print a signed word as HEX
void print_sword(signed word w) {
    if(w<0) {
        print_char('-');
        w = -w;
    }
    print_word((word)w);
}

// Print a signed byte as HEX
void print_sbyte(signed byte b) {
    if(b<0) {
        print_char('-');
        b = -b;
    }
    print_byte((byte)b);
}

// Print a word as HEX
void print_word(word w) {
    print_byte(>w);
    print_byte(<w);
}

// Print a byte as HEX
void print_byte(byte b) {
    // Table of hexadecimal digits
    const byte[] hextab = "0123456789abcdef";
    print_char(hextab[b>>4]);
    print_char(hextab[b&$f]);
}

// Print a single char
void print_char(byte ch) {
    *(char_cursor++) = ch;
}

// Clear the screen
void print_cls() {
    for(byte* sc=$0400; sc!=$0400+1000; sc++) {
        *sc = ' ';
    }
}


