From 28edd14e63bf05e41af6c170523b929303a6c132 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Sat, 10 Jul 2021 14:42:01 -0700 Subject: [PATCH] Consolidated #defines for NEDsim. --- hacks/NEDsim/NEDsim.c | 113 ++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 53 deletions(-) diff --git a/hacks/NEDsim/NEDsim.c b/hacks/NEDsim/NEDsim.c index 71e4b99..e40d839 100644 --- a/hacks/NEDsim/NEDsim.c +++ b/hacks/NEDsim/NEDsim.c @@ -4,6 +4,66 @@ #include "screenhack.h" #include "simulator.h" +/* -------------------------------------------------------------------------- */ +/* Front Panel Layout */ +/* -------------------------------------------------------------------------- */ + +// All of these values are in units of 'cells', not 'pixels'. Where applicable, +// coordinates refer to the upper-left corner of a cell. See the files +// `layout_reference.*` for details. + +#define OVERALL_WIDTH_IN_CELLS 70 +#define HEADER_HEIGHT_IN_CELLS 14 +#define FOOTER_HEIGHT_IN_CELLS 2 + +#define LOGO_X_OFFSET 2 +#define LOGO_Y_OFFSET 2 +#define LOGO_WIDTH 20 +#define LOGO_NAME_HEIGHT 6 +#define LOGO_WEBSITE_HEIGHT 2 + +#define HALT_X_OFFSET 26 +#define HALT_Y_OFFSET 2 +#define HALT_WIDTH 6 +#define HALT_LIGHT_HEIGHT 6 +#define HALT_LABEL_HEIGHT 2 + +#define WORDLINE_BITS_PER_STRIPE 4 +#define WORDLINE_WIDTH 32 +#define WORDLINE_HEIGHT 1 + +#define PC_X_OFFSET 36 +#define PC_Y_OFFSET 7 +#define PC_WIDTH 32 +#define PC_LABEL_HEIGHT 2 +#define PC_LIGHT_HEIGHT 1 + +#define SC_X_OFFSET 42 +#define SC_Y_OFFSET 2 +#define SC_WIDTH 5 +#define SC_LABEL_HEIGHT 2 +#define SC_LIGHT_HEIGHT 1 + +#define PSW_N_X_OFFSET 51 +#define PSW_Z_X_OFFSET 58 +#define PSW_Y_OFFSET 2 +#define PSW_LABEL_WIDTH 3 +#define PSW_LABEL_HEIGHT 2 +#define PSW_LIGHT_WIDTH 1 +#define PSW_LIGHT_HEIGHT 1 + +#define STACK_X_OFFSET 2 +#define STACK_Y_OFFSET 12 +#define STACK_WIDTH 32 +#define STACK_LABEL_HEIGHT 2 +#define STACK_LIGHT_HEIGHT 1 + +#define HEAP_X_OFFSET 36 +#define HEAP_Y_OFFSET 12 +#define HEAP_WIDTH 32 +#define HEAP_LABEL_HEIGHT 2 +#define HEAP_LIGHT_HEIGHT 1 + /* -------------------------------------------------------------------------- */ /* Data Structures */ /* -------------------------------------------------------------------------- */ @@ -277,11 +337,6 @@ draw_circular_area(struct NEDsim * nedsim, size_t x, size_t y, double diameter) static void draw_panel(struct NEDsim * nedsim) { -// TODO: Collect all relevant #defines somewhere. -#define OVERALL_WIDTH_IN_CELLS 70 -#define HEADER_HEIGHT_IN_CELLS 14 -#define FOOTER_HEIGHT_IN_CELLS 2 - // Draw background color over entire window. set_color(nedsim, &color_list[nedsim->color_index].panel_bg); XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc, 0, 0, nedsim->dpy_width, nedsim->dpy_height); @@ -353,12 +408,6 @@ draw_panel(struct NEDsim * nedsim) static void draw_logo(struct NEDsim * nedsim) { -#define LOGO_X_OFFSET 2 -#define LOGO_Y_OFFSET 2 -#define LOGO_WIDTH 20 -#define LOGO_NAME_HEIGHT 6 -#define LOGO_WEBSITE_HEIGHT 2 - // First draw the two colored boxes that comprise the logo area. set_color(nedsim, &color_list[nedsim->color_index].primary); draw_rect_area(nedsim, LOGO_X_OFFSET, LOGO_Y_OFFSET, LOGO_WIDTH, LOGO_NAME_HEIGHT, True, True, False, False); @@ -388,12 +437,6 @@ draw_logo(struct NEDsim * nedsim) static void draw_halt(struct NEDsim * nedsim) { -#define HALT_X_OFFSET 26 -#define HALT_Y_OFFSET 2 -#define HALT_WIDTH 6 -#define HALT_LIGHT_HEIGHT 6 -#define HALT_LABEL_HEIGHT 2 - // First draw the two colored boxes that comprise the halt area. set_color(nedsim, &color_list[nedsim->color_index].tertiary); draw_rect_area(nedsim, HALT_X_OFFSET, HALT_Y_OFFSET, HALT_WIDTH, HALT_LIGHT_HEIGHT, True, True, False, False); @@ -414,10 +457,6 @@ draw_halt(struct NEDsim * nedsim) static void draw_wordline_lights(struct NEDsim * nedsim, uint32_t word, int x, int y) { -#define WORDLINE_BITS_PER_STRIPE 4 -#define WORDLINE_WIDTH 32 -#define WORDLINE_HEIGHT 1 - 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); @@ -452,13 +491,6 @@ draw_wordline(struct NEDsim * nedsim, int x, int y) static void draw_pc(struct NEDsim * nedsim) { -// TODO: Note that all #defines use units of 'cells', not 'pixels', etc. -#define PC_X_OFFSET 36 -#define PC_Y_OFFSET 7 -#define PC_WIDTH 32 -#define PC_LABEL_HEIGHT 2 -#define PC_LIGHT_HEIGHT 1 - // First draw the two colored boxes that comprise the PC area. set_color(nedsim, &color_list[nedsim->color_index].tertiary); draw_rect_area(nedsim, PC_X_OFFSET, PC_Y_OFFSET, PC_WIDTH, PC_LABEL_HEIGHT, True, True, False, False); @@ -478,12 +510,6 @@ draw_pc(struct NEDsim * nedsim) static void draw_sc(struct NEDsim * nedsim) { -#define SC_X_OFFSET 42 -#define SC_Y_OFFSET 2 -#define SC_WIDTH 5 -#define SC_LABEL_HEIGHT 2 -#define SC_LIGHT_HEIGHT 1 - // First draw the two colored boxes that comprise the SC area. set_color(nedsim, &color_list[nedsim->color_index].secondary); draw_rect_area(nedsim, SC_X_OFFSET, SC_Y_OFFSET, SC_WIDTH, SC_LABEL_HEIGHT, True, True, False, False); @@ -504,14 +530,6 @@ draw_sc(struct NEDsim * nedsim) static void draw_psw(struct NEDsim * nedsim) { -#define PSW_N_X_OFFSET 51 -#define PSW_Z_X_OFFSET 58 -#define PSW_Y_OFFSET 2 -#define PSW_LABEL_WIDTH 3 -#define PSW_LABEL_HEIGHT 2 -#define PSW_LIGHT_WIDTH 1 -#define PSW_LIGHT_HEIGHT 1 - // First draw the four colored boxes that comprise the two PSW areas. set_color(nedsim, &color_list[nedsim->color_index].secondary); draw_rect_area(nedsim, PSW_N_X_OFFSET, PSW_Y_OFFSET, PSW_LABEL_WIDTH, PSW_LABEL_HEIGHT, True, True, False, False); @@ -544,12 +562,6 @@ draw_psw(struct NEDsim * nedsim) static void draw_stack(struct NEDsim * nedsim) { -#define STACK_X_OFFSET 2 -#define STACK_Y_OFFSET 12 -#define STACK_WIDTH 32 -#define STACK_LABEL_HEIGHT 2 -#define STACK_LIGHT_HEIGHT 1 - // First draw the two colored boxes that comprise the stack area. set_color(nedsim, &color_list[nedsim->color_index].tertiary); draw_rect_area(nedsim, STACK_X_OFFSET, STACK_Y_OFFSET, STACK_WIDTH, STACK_LABEL_HEIGHT, True, True, False, False); @@ -570,11 +582,6 @@ draw_stack(struct NEDsim * nedsim) static void draw_heap(struct NEDsim * nedsim) { -#define HEAP_X_OFFSET 36 -#define HEAP_Y_OFFSET 12 -#define HEAP_WIDTH 32 -#define HEAP_LABEL_HEIGHT 2 -#define HEAP_LIGHT_HEIGHT 1 // TODO: What should I do about this define? I would like to be able to specify the address so I can do things like display the code itself if nothign interesting happens in RAM. #define HEAP_START_ADDRESS 0x20000000 -- 2.20.1