Since draw_rect_area() changes the foreground color anyway, added foreground color...
authorAaron Taylor <ataylor@subgeniuskitty.com>
Sun, 11 Jul 2021 00:57:03 +0000 (17:57 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Sun, 11 Jul 2021 00:57:03 +0000 (17:57 -0700)
hacks/NEDsim/NEDsim.c

index ad2baaa..7192cce 100644 (file)
@@ -279,7 +279,8 @@ get_text_size(struct NEDsim * nedsim, const char * text, int * x_size, int * y_s
 // in units of 'cells'.  Also, be aware that this function alters the
 // foreground color.
 static void
 // in units of 'cells'.  Also, be aware that this function alters the
 // foreground color.
 static void
-draw_rect_area(struct NEDsim * nedsim, size_t x_origin, size_t y_origin, size_t x_size, size_t y_size,
+draw_rect_area(struct NEDsim * nedsim, struct color_rgb * color,
+               size_t x_origin, size_t y_origin, size_t x_size, size_t y_size,
                Bool bord_top, Bool bord_bottom, Bool bord_left, Bool bord_right)
 {
     // First fill in the rectangular area...
                Bool bord_top, Bool bord_bottom, Bool bord_left, Bool bord_right)
 {
     // First fill in the rectangular area...
@@ -289,6 +290,7 @@ draw_rect_area(struct NEDsim * nedsim, size_t x_origin, size_t y_origin, size_t
     y_origin += nedsim->origin_y_offset;
     x_size *= nedsim->cell_size;
     y_size *= nedsim->cell_size;
     y_origin += nedsim->origin_y_offset;
     x_size *= nedsim->cell_size;
     y_size *= nedsim->cell_size;
+    set_color(nedsim, color);
     XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc, x_origin, y_origin, x_size, y_size);
 
     // ...then give it a border, if requested.
     XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc, x_origin, y_origin, x_size, y_size);
 
     // ...then give it a border, if requested.
@@ -437,10 +439,8 @@ static void
 draw_logo(struct NEDsim * nedsim)
 {
     // First draw the two colored boxes that comprise the logo area.
 draw_logo(struct NEDsim * nedsim)
 {
     // First draw the two colored boxes that comprise the logo area.
-    set_color(nedsim, COLOR(primary));
-    draw_rect_area(nedsim, LOGO_X_OFFSET, LOGO_Y_OFFSET, LOGO_WIDTH, LOGO_NAME_HEIGHT, True, True, False, False);
-    set_color(nedsim, COLOR(tertiary));
-    draw_rect_area(nedsim, LOGO_X_OFFSET, LOGO_Y_OFFSET+LOGO_NAME_HEIGHT, LOGO_WIDTH, LOGO_WEBSITE_HEIGHT, False, True, False, False);
+    draw_rect_area(nedsim, COLOR(primary), LOGO_X_OFFSET, LOGO_Y_OFFSET, LOGO_WIDTH, LOGO_NAME_HEIGHT, True, True, False, False);
+    draw_rect_area(nedsim, COLOR(tertiary), LOGO_X_OFFSET, LOGO_Y_OFFSET+LOGO_NAME_HEIGHT, LOGO_WIDTH, LOGO_WEBSITE_HEIGHT, False, True, False, False);
 
     // Now draw the 'NED' text in the top box.
     set_font_size(nedsim, LOGO_NAME_HEIGHT);
 
     // Now draw the 'NED' text in the top box.
     set_font_size(nedsim, LOGO_NAME_HEIGHT);
@@ -456,10 +456,8 @@ static void
 draw_halt(struct NEDsim * nedsim)
 {
     // First draw the two colored boxes that comprise the halt area.
 draw_halt(struct NEDsim * nedsim)
 {
     // First draw the two colored boxes that comprise the halt area.
-    set_color(nedsim, COLOR(tertiary));
-    draw_rect_area(nedsim, HALT_X_OFFSET, HALT_Y_OFFSET, HALT_WIDTH, HALT_LIGHT_HEIGHT, True, True, False, False);
-    set_color(nedsim, COLOR(secondary));
-    draw_rect_area(nedsim, HALT_X_OFFSET, HALT_Y_OFFSET+HALT_LIGHT_HEIGHT, HALT_WIDTH, HALT_LABEL_HEIGHT, False, True, False, False);
+    draw_rect_area(nedsim, COLOR(tertiary), HALT_X_OFFSET, HALT_Y_OFFSET, HALT_WIDTH, HALT_LIGHT_HEIGHT, True, True, False, False);
+    draw_rect_area(nedsim, COLOR(secondary), HALT_X_OFFSET, HALT_Y_OFFSET+HALT_LIGHT_HEIGHT, HALT_WIDTH, HALT_LABEL_HEIGHT, False, True, False, False);
 
     // And finally, draw the label.
     draw_text(nedsim, "HALT", HALT_X_OFFSET, HALT_Y_OFFSET+HALT_LIGHT_HEIGHT, HALT_WIDTH, HALT_LABEL_HEIGHT, True);
 
     // And finally, draw the label.
     draw_text(nedsim, "HALT", HALT_X_OFFSET, HALT_Y_OFFSET+HALT_LIGHT_HEIGHT, HALT_WIDTH, HALT_LABEL_HEIGHT, True);
@@ -489,13 +487,11 @@ static void
 draw_wordline(struct NEDsim * nedsim, int x, int y)
 {
     // First, draw a solid box in the primary color over the entire wordline area.
 draw_wordline(struct NEDsim * nedsim, int x, int y)
 {
     // First, draw a solid box in the primary color over the entire wordline area.
-    set_color(nedsim, COLOR(primary));
-    draw_rect_area(nedsim, x, y, WORDLINE_WIDTH, WORDLINE_HEIGHT, False, True, False, False);
+    draw_rect_area(nedsim, COLOR(primary), x, y, WORDLINE_WIDTH, WORDLINE_HEIGHT, False, True, False, False);
 
     // Now, draw stripes in the secondary color.
     for (int i = 0; i < (WORDLINE_WIDTH/(2*WORDLINE_BITS_PER_STRIPE)); i++) {
 
     // Now, draw stripes in the secondary color.
     for (int i = 0; i < (WORDLINE_WIDTH/(2*WORDLINE_BITS_PER_STRIPE)); i++) {
-        set_color(nedsim, COLOR(secondary));
-        draw_rect_area(nedsim, (x+(i*(WORDLINE_WIDTH/WORDLINE_BITS_PER_STRIPE))), y,
+        draw_rect_area(nedsim, COLOR(secondary), (x+(i*(WORDLINE_WIDTH/WORDLINE_BITS_PER_STRIPE))), y,
                 WORDLINE_BITS_PER_STRIPE, WORDLINE_HEIGHT, False, True, False, False);
     }
 }
                 WORDLINE_BITS_PER_STRIPE, WORDLINE_HEIGHT, False, True, False, False);
     }
 }
@@ -505,8 +501,7 @@ static void
 draw_pc(struct NEDsim * nedsim)
 {
     // First draw the two colored boxes that comprise the PC area.
 draw_pc(struct NEDsim * nedsim)
 {
     // First draw the two colored boxes that comprise the PC area.
-    set_color(nedsim, COLOR(tertiary));
-    draw_rect_area(nedsim, PC_X_OFFSET, PC_Y_OFFSET, PC_WIDTH, PC_LABEL_HEIGHT, True, True, False, False);
+    draw_rect_area(nedsim, COLOR(tertiary), PC_X_OFFSET, PC_Y_OFFSET, PC_WIDTH, PC_LABEL_HEIGHT, True, True, False, False);
     draw_wordline(nedsim, PC_X_OFFSET, PC_Y_OFFSET+PC_LABEL_HEIGHT);
 
     // Now draw the label text "PC".
     draw_wordline(nedsim, PC_X_OFFSET, PC_Y_OFFSET+PC_LABEL_HEIGHT);
 
     // Now draw the label text "PC".
@@ -518,10 +513,8 @@ static void
 draw_sc(struct NEDsim * nedsim)
 {
     // First draw the two colored boxes that comprise the SC area.
 draw_sc(struct NEDsim * nedsim)
 {
     // First draw the two colored boxes that comprise the SC area.
-    set_color(nedsim, COLOR(secondary));
-    draw_rect_area(nedsim, SC_X_OFFSET, SC_Y_OFFSET, SC_WIDTH, SC_LABEL_HEIGHT, True, True, False, False);
-    set_color(nedsim, COLOR(tertiary));
-    draw_rect_area(nedsim, SC_X_OFFSET, SC_Y_OFFSET+SC_LABEL_HEIGHT, SC_WIDTH, SC_LIGHT_HEIGHT, False, True, False, False);
+    draw_rect_area(nedsim, COLOR(secondary), SC_X_OFFSET, SC_Y_OFFSET, SC_WIDTH, SC_LABEL_HEIGHT, True, True, False, False);
+    draw_rect_area(nedsim, COLOR(tertiary), SC_X_OFFSET, SC_Y_OFFSET+SC_LABEL_HEIGHT, SC_WIDTH, SC_LIGHT_HEIGHT, False, True, False, False);
 
     // Now draw the label text "SC".
     draw_text(nedsim, "SC", SC_X_OFFSET, SC_Y_OFFSET, SC_WIDTH, SC_LABEL_HEIGHT, True);
 
     // Now draw the label text "SC".
     draw_text(nedsim, "SC", SC_X_OFFSET, SC_Y_OFFSET, SC_WIDTH, SC_LABEL_HEIGHT, True);
@@ -532,14 +525,10 @@ static void
 draw_psw(struct NEDsim * nedsim)
 {
     // First draw the four colored boxes that comprise the two PSW areas.
 draw_psw(struct NEDsim * nedsim)
 {
     // First draw the four colored boxes that comprise the two PSW areas.
-    set_color(nedsim, COLOR(secondary));
-    draw_rect_area(nedsim, PSW_N_X_OFFSET, PSW_Y_OFFSET, PSW_LABEL_WIDTH, PSW_LABEL_HEIGHT, True, True, False, False);
-    set_color(nedsim, COLOR(secondary));
-    draw_rect_area(nedsim, PSW_Z_X_OFFSET, PSW_Y_OFFSET, PSW_LABEL_WIDTH, PSW_LABEL_HEIGHT, True, True, False, False);
-    set_color(nedsim, COLOR(tertiary));
-    draw_rect_area(nedsim, (PSW_N_X_OFFSET + 1), PSW_Y_OFFSET+PSW_LABEL_HEIGHT, PSW_LIGHT_WIDTH, PSW_LIGHT_HEIGHT, False, True, False, False);
-    set_color(nedsim, COLOR(tertiary));
-    draw_rect_area(nedsim, (PSW_Z_X_OFFSET + 1), PSW_Y_OFFSET+PSW_LABEL_HEIGHT, PSW_LIGHT_WIDTH, PSW_LIGHT_HEIGHT, False, True, False, False);
+    draw_rect_area(nedsim, COLOR(secondary), PSW_N_X_OFFSET, PSW_Y_OFFSET, PSW_LABEL_WIDTH, PSW_LABEL_HEIGHT, True, True, False, False);
+    draw_rect_area(nedsim, COLOR(secondary), PSW_Z_X_OFFSET, PSW_Y_OFFSET, PSW_LABEL_WIDTH, PSW_LABEL_HEIGHT, True, True, False, False);
+    draw_rect_area(nedsim, COLOR(tertiary), (PSW_N_X_OFFSET + 1), PSW_Y_OFFSET+PSW_LABEL_HEIGHT, PSW_LIGHT_WIDTH, PSW_LIGHT_HEIGHT, False, True, False, False);
+    draw_rect_area(nedsim, COLOR(tertiary), (PSW_Z_X_OFFSET + 1), PSW_Y_OFFSET+PSW_LABEL_HEIGHT, PSW_LIGHT_WIDTH, PSW_LIGHT_HEIGHT, False, True, False, False);
 
     // Now draw the label text.
     draw_text(nedsim, "N", PSW_N_X_OFFSET, PSW_Y_OFFSET, PSW_LABEL_WIDTH, PSW_LABEL_HEIGHT, True);
 
     // Now draw the label text.
     draw_text(nedsim, "N", PSW_N_X_OFFSET, PSW_Y_OFFSET, PSW_LABEL_WIDTH, PSW_LABEL_HEIGHT, True);
@@ -551,8 +540,7 @@ static void
 draw_stack(struct NEDsim * nedsim)
 {
     // First draw the two colored boxes that comprise the stack area.
 draw_stack(struct NEDsim * nedsim)
 {
     // First draw the two colored boxes that comprise the stack area.
-    set_color(nedsim, COLOR(tertiary));
-    draw_rect_area(nedsim, STACK_X_OFFSET, STACK_Y_OFFSET, STACK_WIDTH, STACK_LABEL_HEIGHT, True, True, False, False);
+    draw_rect_area(nedsim, COLOR(tertiary), STACK_X_OFFSET, STACK_Y_OFFSET, STACK_WIDTH, STACK_LABEL_HEIGHT, True, True, False, False);
     for (int i = 0; i < nedsim->num_data_rows; i++) {
         draw_wordline(nedsim, STACK_X_OFFSET, STACK_Y_OFFSET+STACK_LABEL_HEIGHT+i);
     }
     for (int i = 0; i < nedsim->num_data_rows; i++) {
         draw_wordline(nedsim, STACK_X_OFFSET, STACK_Y_OFFSET+STACK_LABEL_HEIGHT+i);
     }
@@ -569,8 +557,7 @@ draw_heap(struct NEDsim * nedsim)
 #define HEAP_START_ADDRESS 0x20000000
 
     // First draw the two colored boxes that comprise the heap area.
 #define HEAP_START_ADDRESS 0x20000000
 
     // First draw the two colored boxes that comprise the heap area.
-    set_color(nedsim, COLOR(tertiary));
-    draw_rect_area(nedsim, HEAP_X_OFFSET, HEAP_Y_OFFSET, HEAP_WIDTH, HEAP_LABEL_HEIGHT, True, True, False, False);
+    draw_rect_area(nedsim, COLOR(tertiary), HEAP_X_OFFSET, HEAP_Y_OFFSET, HEAP_WIDTH, HEAP_LABEL_HEIGHT, True, True, False, False);
     for (int i = 0; i < nedsim->num_data_rows; i++) {
         draw_wordline(nedsim, HEAP_X_OFFSET, HEAP_Y_OFFSET+HEAP_LABEL_HEIGHT+i);
     }
     for (int i = 0; i < nedsim->num_data_rows; i++) {
         draw_wordline(nedsim, HEAP_X_OFFSET, HEAP_Y_OFFSET+HEAP_LABEL_HEIGHT+i);
     }
@@ -639,8 +626,7 @@ update_display(struct NEDsim * nedsim)
     }
 
     // Draw the stack size in text.
     }
 
     // Draw the stack size in text.
-    set_color(nedsim, COLOR(tertiary));
-    draw_rect_area(nedsim, STACK_X_OFFSET+(STACK_WIDTH/2), STACK_Y_OFFSET, STACK_WIDTH/2, STACK_LABEL_HEIGHT, True, True, False, False);
+    draw_rect_area(nedsim, COLOR(tertiary), STACK_X_OFFSET+(STACK_WIDTH/2), STACK_Y_OFFSET, STACK_WIDTH/2, STACK_LABEL_HEIGHT, True, True, False, False);
     char stack_size[11];
     snprintf(stack_size, sizeof(stack_size), "0x%08X", nedsim->nedstate->active_thread->sp);
     draw_text(nedsim, stack_size, (STACK_X_OFFSET+(STACK_WIDTH/2)+1), STACK_Y_OFFSET, STACK_WIDTH, STACK_LABEL_HEIGHT, False);
     char stack_size[11];
     snprintf(stack_size, sizeof(stack_size), "0x%08X", nedsim->nedstate->active_thread->sp);
     draw_text(nedsim, stack_size, (STACK_X_OFFSET+(STACK_WIDTH/2)+1), STACK_Y_OFFSET, STACK_WIDTH, STACK_LABEL_HEIGHT, False);