#include <TVout.h>
#include <TVoutfonts/fontALL.h>

TVout TV;

uint8_t curkey = 0;

extern "C" {
    uint16_t getpc();
    uint8_t getop();
    void exec6502(int32_t tickcount);
    int reset6502();

    void serout(uint8_t val) {
        TV.write(val);
    }

    uint8_t getkey() {
        uint8_t key = curkey;
        curkey = 0;
        return key;
    }
}

void setup () {
    Serial.begin(115200);
    Serial.print("[emu6502] ");
    Serial.print(reset6502());
    Serial.println(" bytes");

    TV.begin(PAL);
    TV.select_font(font8x8);
    TV.clear_screen();    
}

void loop () {
    exec6502(1000);
    if (curkey == 0 && Serial.available())
        curkey = Serial.read() & 0x7F;
}