Theoretically I/O and Interrupts 100% implemented

This commit is contained in:
Luxdragon 2024-01-14 20:45:36 +01:00
parent b0536826aa
commit a0e7a72ca6

View file

@ -6,6 +6,7 @@
// gcc emulator_shell.c `pkg-config --cflags --libs gtk+-3.0` -o emulator
#define FREQUENCY 500
//===== GTK SETUP =====
@ -81,6 +82,7 @@ static gboolean on_key_release(GtkWidget *widget, GdkEventKey *event, gpointer u
//===== EMULATOR SETUP =====
uint8_t in_port; //GLOBALLY DECLARED
char which_interrupt = 1; //GLOBALLY DECLARED
typedef struct ConditionCodes {
//bitfields for condition codes
@ -972,10 +974,26 @@ void keyUp( uint8_t key)
}
}
void simulateNanoseconds(unsigned int numNanoseconds)
{
struct timespec sleepTime;
sleepTime.tv_sec = 0;
sleepTime.tv_nsec = numNanoseconds;
// Pause the program execution for the specified duration
nanosleep(&sleepTime, NULL);
}
int main (int argc, char *argv[]) {
// GTK INIT
gtk_init(&argc, &argv);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_print("Test\n");
g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL);
g_signal_connect(window, "key-release-event", G_CALLBACK(on_key_release), NULL);
gtk_widget_show(window);
// EMULATOR INIT
@ -994,33 +1012,31 @@ int main (int argc, char *argv[]) {
read_Space_Invaders_ROM(state, "ROM/invaders.f", 0x1000);
read_Space_Invaders_ROM(state, "ROM/invaders.e", 0x1800);
// GTK INIT
gtk_init(&argc, &argv);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_print("Test\n");
g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL);
g_signal_connect(window, "key-release-event", G_CALLBACK(on_key_release), NULL);
gtk_widget_show(window);
int i = 0;
char done = 0;
int counter;
int total_count = 0;
while (!done) {
counter = emulate8080(state);
i++;
sleep(0.00001);
if ( time() - lastInterrupt > 1.0/60.0) //1/60 second has elapsed
{
//only do an interrupt if they are enabled
if (state->int_enable)
{
GenerateInterrupt(state, 2); //interrupt 2
total_count += counter;
//Save the time we did this
lastInterrupt = time();
}
}
i++;
simulateNanoseconds(FREQUENCY * counter); // EMULATION OF THE PROCESSOR ŠPEED
if ((total_count > 10000000) && (state->int_enable)) //1/60 second has elapsed
{
if (which_interrupt == 2) {
generateInterrupt(state, 2); //interrupt 2
total_count = 0;
which_interrupt = 1;
} else {
generateInterrupt(state, 1); //interrupt 0
total_count = 0;
which_interrupt = 2;
}
}
}
gtk_main();
free(state->memory);