Added colour (Final version
This commit is contained in:
parent
105e128092
commit
71cab2023e
2 changed files with 24 additions and 11 deletions
|
@ -1569,6 +1569,7 @@ typedef struct cpu_data {
|
||||||
int total_cycles_count;
|
int total_cycles_count;
|
||||||
GtkWidget* drawing_area;
|
GtkWidget* drawing_area;
|
||||||
State8080 *state;
|
State8080 *state;
|
||||||
|
pthread_t pid;
|
||||||
|
|
||||||
} cpu_data;
|
} 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 x = i; // swap x and y
|
||||||
int y = 255 - (j*8 + p); // flip the y-coordinate
|
int y = 255 - (j*8 + p); // flip the y-coordinate
|
||||||
if (x >= 0 && x < 256 && y >= 0 && y < 256) { // Check bounds
|
if (x >= 0 && x < 256 && y >= 0 && y < 256) { // Check bounds
|
||||||
if (pixel) {
|
if (pixel && (y > 191) && (y < 240)) {
|
||||||
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); // Set color to white
|
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 {
|
} 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);
|
cairo_rectangle(cr, x * upscaleFactor, y * upscaleFactor, upscaleFactor, upscaleFactor);
|
||||||
|
@ -1684,6 +1689,14 @@ gboolean open_screen(gpointer data) {
|
||||||
return FALSE;
|
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[]) {
|
int main (int argc, char *argv[]) {
|
||||||
|
@ -1775,17 +1788,17 @@ int main (int argc, char *argv[]) {
|
||||||
cpu_eco->total_cycles_count = 0;
|
cpu_eco->total_cycles_count = 0;
|
||||||
|
|
||||||
// Pthread
|
// Pthread
|
||||||
pthread_t pid;
|
pthread_create(&(cpu_eco->pid), NULL, cpu, (void*) cpu_eco);
|
||||||
pthread_create(&pid, NULL, cpu, (void*) cpu_eco);
|
g_signal_connect(window, "destroy", G_CALLBACK(on_window_destroy), cpu_eco);
|
||||||
|
|
||||||
|
|
||||||
// Main GTK Loop
|
// Main GTK Loop
|
||||||
g_timeout_add(80, update_ui, drawing_area);
|
g_timeout_add(50, update_ui, drawing_area);
|
||||||
gtk_main();
|
gtk_main();
|
||||||
cpu_eco->done = 1;
|
// cpu_eco->done = 1;
|
||||||
pthread_join(pid, NULL);
|
// pthread_join(pid, NULL);
|
||||||
free(state->memory);
|
// free(state->memory);
|
||||||
free(state);
|
// free(state);
|
||||||
free(cpu_eco);
|
// free(cpu_eco);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
BIN
space.png~
Normal file
BIN
space.png~
Normal file
Binary file not shown.
After Width: | Height: | Size: 1,012 KiB |
Loading…
Reference in a new issue