// A raster IRQ that opens the top/bottom border.
import "c64.kc"

const byte* GHOST_BYTE = $3fff;

void main() {
    *GHOST_BYTE = 0;
    asm { sei }
    // Disable CIA 1 Timer IRQ
    *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR;
    // Set raster line to $fa
    *VIC_CONTROL &=$7f;
    *RASTER = $fa;
    // Enable Raster Interrupt
    *IRQ_ENABLE = IRQ_RASTER;
    // Set the IRQ routine
    *KERNEL_IRQ = &irq_bottom_1;
    asm { cli }
}

// Interrupt Routine 1
interrupt(kernel_min) void irq_bottom_1() {
    *BORDERCOL = WHITE;
    // Set screen height to 24 lines - this is done after the border should have started drawing - so it wont start
    *VIC_CONTROL &= ($ff^VIC_RSEL);
    // Acknowledge the IRQ
    *IRQ_STATUS = IRQ_RASTER;
    // Trigger IRQ 2 at line $fd
    *RASTER = $fd;
    *KERNEL_IRQ = &irq_bottom_2;
    *BORDERCOL = RED;
}

// Interrupt Routine 2
interrupt(kernel_keyboard) void irq_bottom_2() {
    *BORDERCOL = WHITE;
    // Set screen height back to 25 lines (preparing for the next screen)
    *VIC_CONTROL |= VIC_RSEL;
    // Acknowledge the IRQ
    *IRQ_STATUS = IRQ_RASTER;
    // Trigger IRQ 1 at line $fa
    *RASTER = $fa;
    *KERNEL_IRQ = &irq_bottom_1;
    *BORDERCOL = RED;
}