import agon.buffers
import agon.console
import agon.gpio
import agon.keyboard
import agon.mouse
import agon.vdp

fn draw_frame() {
    vdp.set_logical_coordinates()
    vdp.gcol(vdp.GCOL_SET, vdp.COLOR_CYAN)
    vdp.rectangle(32, 32, 288, 192)
    vdp.gcol(vdp.GCOL_SET, vdp.COLOR_YELLOW)
    vdp.line(32, 32, 288, 192)
    vdp.line(32, 192, 288, 32)
    vdp.gcol(vdp.GCOL_SET, vdp.COLOR_MAGENTA)
    vdp.circle(160, 112, 42)
}

fn show_input_status() {
    console.tab(0, 9)
    console.print("Last key ASCII: ")
    console.write(keyboard.ascii())
    console.newline()
    console.print("Mouse buttons: ")
    console.write('0' + mouse.buttons())
    console.newline()
}

fn pulse_gpio_demo() {
    gpio.set_port_b_direction(gpio.ALL_OUTPUTS)
    gpio.write_port_b(0x01)
    gpio.write_port_b(0x00)
}

fn buffer_demo() {
    buffers.buffer_clear(1)
}

fn main() {
    console.mode(8)
    console.clear()
    console.cursor_enable(0)
    console.color(vdp.COLOR_WHITE)
    console.background(vdp.COLOR_BLUE)
    console.print_line("EZRA Agon SDK showcase")
    console.print_line("Console, VDP, keyboard, mouse, and GPIO wrappers")

    mouse.enable()
    draw_frame()
    show_input_status()
    buffer_demo()
    pulse_gpio_demo()
}
