diff --git a/emulator_shell.c b/emulator_shell.c index 86757fb..f2a3ee8 100644 --- a/emulator_shell.c +++ b/emulator_shell.c @@ -1569,6 +1569,7 @@ typedef struct cpu_data { int total_cycles_count; GtkWidget* drawing_area; State8080 *state; + pthread_t pid; } cpu_data; @@ -1616,10 +1617,14 @@ static void draw_callback(GtkWidget *widget, cairo_t *cr, gpointer user_data) { int x = i; // swap x and y int y = 255 - (j*8 + p); // flip the y-coordinate if (x >= 0 && x < 256 && y >= 0 && y < 256) { // Check bounds - if (pixel) { - cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); // Set color to white + if (pixel && (y > 191) && (y < 240)) { + cairo_set_source_rgb(cr, 0.1, 1.0, 0.1); // Set colour to green + } else if (pixel && (y < 50) && (y > 32)) { + cairo_set_source_rgb(cr, 1.0, 0.1, 0.1); // Set colour to red + } else if (pixel) { + cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); // Set colour to white } else { - cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); // Set color to black + cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); // Set colour to black } cairo_rectangle(cr, x * upscaleFactor, y * upscaleFactor, upscaleFactor, upscaleFactor); @@ -1684,6 +1689,14 @@ gboolean open_screen(gpointer data) { return FALSE; } +void on_window_destroy(GtkWidget *widget, cpu_data *cpu_eco) { + pthread_cancel(cpu_eco->pid); // Assuming 'pid' is a member of 'cpu_data' + free(cpu_eco->state->memory); + free(cpu_eco->state); + free(cpu_eco); + gtk_main_quit(); +} + int main (int argc, char *argv[]) { @@ -1775,17 +1788,17 @@ int main (int argc, char *argv[]) { cpu_eco->total_cycles_count = 0; // Pthread - pthread_t pid; - pthread_create(&pid, NULL, cpu, (void*) cpu_eco); + pthread_create(&(cpu_eco->pid), NULL, cpu, (void*) cpu_eco); + g_signal_connect(window, "destroy", G_CALLBACK(on_window_destroy), cpu_eco); // Main GTK Loop - g_timeout_add(80, update_ui, drawing_area); + g_timeout_add(50, update_ui, drawing_area); gtk_main(); - cpu_eco->done = 1; - pthread_join(pid, NULL); - free(state->memory); - free(state); - free(cpu_eco); + // cpu_eco->done = 1; + // pthread_join(pid, NULL); + // free(state->memory); + // free(state); + // free(cpu_eco); return 0; } \ No newline at end of file diff --git a/space.png~ b/space.png~ new file mode 100644 index 0000000..27e324f Binary files /dev/null and b/space.png~ differ