
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "interrupt.h"


/* In SDCC i/o ports are treated as SFR (Special Funcion Registers, like the MCS51 architecture ones) */
sfr at 0xAA keyboard_line_w;
sfr at 0xA9 keyboard_column_r;
/* test counter */
int counter;



/* Mi own ISR */
/* The "interrupt" keyword is only accepted for Z80 port in the latest SDCC snapshots */
/* SDCC 2.4.0 does not support it */
void my_isr(void) interrupt {
	DI;
	READ_VDP_STATUS;
	counter++;
	EI;
}


void main(void) {
	printf("Interrupt test.\n\r");
	counter = 0;
	install_isr(my_isr);
	printf("Infinite loop. Press 'X' to break.\n\r");
	while (1) {
		/* 'X' key */
		keyboard_line_w = 0x55;
		if (keyboard_column_r == 0xDF)
			break;
	}
	uninstall_isr();
	printf("Counter = %d\n\r", counter);
	return;
	}
