+/* -------------------------------------------------------------------------- */
+/* Dynamic Panel Functions */
+/* -------------------------------------------------------------------------- */
+
+// Draw the 32 lights corresponding to 'word' at coordinates ('x','y').
+// Note that this function ONLY draws the lights and is used each frame for
+// updating the panel. To draw the wordline area itself, use draw_wordline().
+static void
+draw_wordline_lights(struct NEDsim * nedsim, uint32_t word, int x, int y)
+{
+ for (int i = 0; i < WORDLINE_WIDTH; i++) {
+ if (word & (1<<(WORDLINE_WIDTH-1-i))) {
+ set_color(nedsim, COLOR(light_on));
+ } else {
+ set_color(nedsim, COLOR(light_off));
+ }
+ draw_circular_area(nedsim, x+i, y, WORDLINE_HEIGHT);
+ }
+}
+
+// After the static front panel has been drawn at least once, this function
+// updates all the dynamic parts of the panel (lights + text values) and is
+// called every frame.
+static void
+update_display(struct NEDsim * nedsim)
+{
+ // Draw the halt indicator.
+ if (nedsim->nedstate->halted) {
+ set_color(nedsim, COLOR(error_on));
+ } else {
+ 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(light_on));
+ } else {
+ 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(light_on));
+ } else {
+ set_color(nedsim, COLOR(light_off));
+ }
+ draw_circular_area(nedsim,
+ PSW_Z_X_OFFSET+1, PSW_Y_OFFSET+PSW_LABEL_HEIGHT, PSW_LIGHT_HEIGHT
+ );
+
+
+ // Draw the SC.
+ for (int i = 0; i < SC_WIDTH; i++) {
+ if ((SC_WIDTH-1-i) == nedsim->nedstate->active_thread->sc) {
+ set_color(nedsim, COLOR(light_on));
+ } else {
+ 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 PC.
+ draw_wordline_lights(nedsim, nedsim->nedstate->active_thread->pc,
+ PC_X_OFFSET, PC_Y_OFFSET+PC_LABEL_HEIGHT
+ );
+
+ // Draw the stack lights.
+ int64_t top_of_stack = ((int64_t)nedsim->nedstate->active_thread->sp) - 1;
+ for (int i = 0; i < nedsim->num_data_rows; i++) {
+ if ((top_of_stack-i) >= 0) {
+ draw_wordline_lights(nedsim,
+ nedsim->nedstate->active_thread->stack[top_of_stack-i],
+ STACK_X_OFFSET, STACK_Y_OFFSET+STACK_LABEL_HEIGHT+i
+ );
+ } else {
+ draw_wordline_lights(nedsim, 0,
+ STACK_X_OFFSET, STACK_Y_OFFSET+STACK_LABEL_HEIGHT+i
+ );
+ }
+ }
+
+ // Draw the stack size in text.
+ 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
+ );
+
+ // Draw the heap lights.
+ for (int i = 0; i < nedsim->num_data_rows; i++) {
+ draw_wordline_lights(nedsim,
+ ram_r_word(nedsim->nedstate, nedsim->heap_window_offset+(i*BPW)),
+ HEAP_X_OFFSET, HEAP_Y_OFFSET+HEAP_LABEL_HEIGHT+i
+ );
+ }
+}
+
+/* -------------------------------------------------------------------------- */
+/* Static Panel Functions */
+/* -------------------------------------------------------------------------- */
+