/* Helper Functions */
/* -------------------------------------------------------------------------- */
+// Fill in boilerplate when selecting colors.
+#define COLOR(X) &color_list[nedsim->color_index].X
+
// Set foreground color for the current graphics context.
static void
set_color(struct NEDsim * nedsim, struct color_rgb * color)
XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc, x_origin, y_origin, x_size, y_size);
// ...then give it a border, if requested.
- set_color(nedsim, &color_list[nedsim->color_index].border);
+ set_color(nedsim, COLOR(border));
if (bord_top) {
XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc,
x_origin, y_origin, x_size, nedsim->border_size);
static void
draw_text(struct NEDsim * nedsim, const char * text, int x_origin, int y_origin, int x_size, int y_size, Bool horizontally_center)
{
- set_color(nedsim, &color_list[nedsim->color_index].text);
+ set_color(nedsim, COLOR(text));
int text_x_size, text_y_size;
get_text_size(nedsim, text, &text_x_size, &text_y_size);
draw_panel(struct NEDsim * nedsim)
{
// Draw background color over entire window.
- set_color(nedsim, &color_list[nedsim->color_index].panel_bg);
+ set_color(nedsim, COLOR(panel_bg));
XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc, 0, 0, nedsim->dpy_width, nedsim->dpy_height);
// Draw NED panel in foreground color.
- set_color(nedsim, &color_list[nedsim->color_index].panel_fg);
+ set_color(nedsim, COLOR(panel_fg));
XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc,
nedsim->origin_x_offset,
nedsim->origin_y_offset,
);
// Give the panel rounded corners by first deleting the four right-angle corners...
- set_color(nedsim, &color_list[nedsim->color_index].panel_bg);
+ set_color(nedsim, COLOR(panel_bg));
XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc,
nedsim->origin_x_offset,
nedsim->origin_y_offset,
nedsim->cell_size
);
// ...and then replacing them with filled arcs, forming rounded corners.
- set_color(nedsim, &color_list[nedsim->color_index].panel_fg);
+ set_color(nedsim, COLOR(panel_fg));
XFillArc(nedsim->dpy, nedsim->panel, nedsim->gc,
nedsim->origin_x_offset,
nedsim->origin_y_offset,
draw_logo(struct NEDsim * nedsim)
{
// First draw the two colored boxes that comprise the logo area.
- set_color(nedsim, &color_list[nedsim->color_index].primary);
+ 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_list[nedsim->color_index].tertiary);
+ 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);
// Now draw the 'NED' text in the top box.
draw_halt(struct NEDsim * nedsim)
{
// First draw the two colored boxes that comprise the halt area.
- set_color(nedsim, &color_list[nedsim->color_index].tertiary);
+ 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_list[nedsim->color_index].secondary);
+ 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);
// And finally, draw the label.
{
for (int i = 0; i < WORDLINE_WIDTH; i++) {
if (word & (1<<(WORDLINE_WIDTH-1-i))) {
- set_color(nedsim, &color_list[nedsim->color_index].light_on);
+ set_color(nedsim, COLOR(light_on));
} else {
- set_color(nedsim, &color_list[nedsim->color_index].light_off);
+ set_color(nedsim, COLOR(light_off));
}
draw_circular_area(nedsim, x+i, y, WORDLINE_HEIGHT);
}
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_list[nedsim->color_index].primary);
+ set_color(nedsim, COLOR(primary));
draw_rect_area(nedsim, x, y, WORDLINE_WIDTH, WORDLINE_HEIGHT, False, True, False, False);
// Now, draw stripes in the secondary color.
int i;
for (i = 0; i < (WORDLINE_WIDTH/(2*WORDLINE_BITS_PER_STRIPE)); i++) {
- set_color(nedsim, &color_list[nedsim->color_index].secondary);
+ set_color(nedsim, COLOR(secondary));
draw_rect_area(nedsim, (x+(i*(WORDLINE_WIDTH/WORDLINE_BITS_PER_STRIPE))), y,
WORDLINE_BITS_PER_STRIPE, WORDLINE_HEIGHT, False, True, False, False);
}
draw_pc(struct NEDsim * nedsim)
{
// First draw the two colored boxes that comprise the PC area.
- set_color(nedsim, &color_list[nedsim->color_index].tertiary);
+ 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_wordline(nedsim, PC_X_OFFSET, PC_Y_OFFSET+PC_LABEL_HEIGHT);
draw_sc(struct NEDsim * nedsim)
{
// First draw the two colored boxes that comprise the SC area.
- set_color(nedsim, &color_list[nedsim->color_index].secondary);
+ 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_list[nedsim->color_index].tertiary);
+ 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);
// Now draw the label text "SC".
draw_psw(struct NEDsim * nedsim)
{
// First draw the four colored boxes that comprise the two PSW areas.
- set_color(nedsim, &color_list[nedsim->color_index].secondary);
+ 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_list[nedsim->color_index].secondary);
+ 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_list[nedsim->color_index].tertiary);
+ 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_list[nedsim->color_index].tertiary);
+ 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);
// Now draw the label text.
draw_stack(struct NEDsim * nedsim)
{
// First draw the two colored boxes that comprise the stack area.
- set_color(nedsim, &color_list[nedsim->color_index].tertiary);
+ set_color(nedsim, COLOR(tertiary));
draw_rect_area(nedsim, 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);
#define HEAP_START_ADDRESS 0x20000000
// First draw the two colored boxes that comprise the heap area.
- set_color(nedsim, &color_list[nedsim->color_index].tertiary);
+ set_color(nedsim, COLOR(tertiary));
draw_rect_area(nedsim, 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);
{
// Draw the halt indicator.
if (nedsim->nedstate->halted) {
- set_color(nedsim, &color_list[nedsim->color_index].error_on);
+ set_color(nedsim, COLOR(error_on));
} else {
- set_color(nedsim, &color_list[nedsim->color_index].error_off);
+ set_color(nedsim, COLOR(error_off));
}
draw_circular_area(nedsim, HALT_X_OFFSET, HALT_Y_OFFSET, HALT_WIDTH);
// Draw the PSW "N" light.
if (nedsim->nedstate->active_thread->psw->negative) {
- set_color(nedsim, &color_list[nedsim->color_index].light_on);
+ set_color(nedsim, COLOR(light_on));
} else {
- set_color(nedsim, &color_list[nedsim->color_index].light_off);
+ set_color(nedsim, COLOR(light_off));
}
draw_circular_area(nedsim, PSW_N_X_OFFSET+1, PSW_Y_OFFSET+PSW_LABEL_HEIGHT, PSW_LIGHT_HEIGHT);
// Draw the PSW "Z" light.
if (nedsim->nedstate->active_thread->psw->zero) {
- set_color(nedsim, &color_list[nedsim->color_index].light_on);
+ set_color(nedsim, COLOR(light_on));
} else {
- set_color(nedsim, &color_list[nedsim->color_index].light_off);
+ set_color(nedsim, COLOR(light_off));
}
draw_circular_area(nedsim, PSW_Z_X_OFFSET+1, PSW_Y_OFFSET+PSW_LABEL_HEIGHT, PSW_LIGHT_HEIGHT);
int i;
for (i = 0; i < SC_WIDTH; i++) {
if ((SC_WIDTH-1-i) == nedsim->nedstate->active_thread->sc) {
- set_color(nedsim, &color_list[nedsim->color_index].light_on);
+ set_color(nedsim, COLOR(light_on));
} else {
- set_color(nedsim, &color_list[nedsim->color_index].light_off);
+ set_color(nedsim, COLOR(light_off));
}
draw_circular_area(nedsim, SC_X_OFFSET+i, SC_Y_OFFSET+SC_LABEL_HEIGHT, SC_LIGHT_HEIGHT);
}
}
// Draw the stack size in text.
- set_color(nedsim, &color_list[nedsim->color_index].tertiary);
+ 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);
char stack_size[11];
snprintf(stack_size, sizeof(stack_size), "0x%08X", nedsim->nedstate->active_thread->sp);
nedsim->nedstate = run_simulator(nedsim->nedstate);
update_display(nedsim);
} else {
- set_color(nedsim, &color_list[nedsim->color_index].error_on);
+ set_color(nedsim, COLOR(error_on));
XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc, 0, 0, nedsim->dpy_width, nedsim->dpy_height);
}