Restore a blinking block cursor closer to the original one but custom.
authorMatthew Mondor <mmondor@pulsar-zone.net>
Mon, 11 Apr 2022 02:29:23 +0000 (02:29 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Mon, 11 Apr 2022 02:29:23 +0000 (02:29 +0000)
Returns to "on" state when in use, then blinks when idle.  This will reduce
the amount of unnecessary constant animation when testing performance.
Keep the old code around but in a compile-conditional block.  Should
eventually be configurable.

hacks/analogterm.c

index de14d2d..fca88e1 100644 (file)
@@ -16,6 +16,7 @@
 #include <math.h>
 #include "screenhackI.h"
 #include "analogterm.h"
+#include <stdbool.h>
 
 #ifdef HAVE_XSHM_EXTENSION
 #include "xshm.h"
@@ -109,6 +110,40 @@ at_insert(analogterm_state_t *st, int many)
                *mptr = st->mode & TMODE_BGCOLOR;
 }
 
+bool cursor_waitnext = true;
+bool cursor_laststate = false;
+
+void
+at_drawcursor(analogterm_sim_t *sim)
+{
+       analogterm_state_t *st = sim->st;
+       int x, y;
+       signed char *pp;
+
+       if (st->blink && !cursor_waitnext)
+               return;
+       if (cursor_waitnext) {
+               if (cursor_laststate != st->blink)
+                       cursor_waitnext = false;
+       }
+       cursor_laststate = st->blink;
+
+       for (y = 0; y < 8; y++) {
+               pp = &sim->inp->signal[(ANALOGTV_TOP + 3) + (8 * st->cursy) + y]
+                  [(ANALOGTV_PIC_START + 100) + (7 * st->cursx)];
+               for (x = 0; x < 8; x++)
+                       *pp++ ^= 64/*TMODE_NORMAL_LEVEL*/;
+       }
+}
+
+void
+at_resetcursor(void)
+{
+
+       cursor_waitnext = true;
+}
+
+#ifdef PULSECURSOR
 static signed char cursorstate = 127;
 static int cursorstate_timer = 1, cursorstate_add = -1;
 void
@@ -120,8 +155,8 @@ at_drawcursor(analogterm_sim_t *sim)
 
        /* Line cursor */
        /*
-       pp = &sim->inp->signal[(ANALOGTV_TOP+3) + (8 * st->cursy) + 7]
-          [(ANALOGTV_PIC_START+100) + (7 * st->cursx)];
+       pp = &sim->inp->signal[(ANALOGTV_TOP + 3) + (8 * st->cursy) + 7]
+          [(ANALOGTV_PIC_START + 100) + (7 * st->cursx)];
        for (x = 0; x < 8; x++) {
                *pp++ ^= cursorstate;
                if (--cursorstate_timer == 0) {
@@ -138,8 +173,8 @@ at_drawcursor(analogterm_sim_t *sim)
         * - Blinking speed should rely on a configurable timer
         */
        for (y = 0; y < 8; y++) {
-               pp = &sim->inp->signal[(ANALOGTV_TOP+3) + (8 * st->cursy) + y]
-                  [(ANALOGTV_PIC_START+100) + (7 * st->cursx)];
+               pp = &sim->inp->signal[(ANALOGTV_TOP + 3) + (8 * st->cursy) + y]
+                  [(ANALOGTV_PIC_START + 100) + (7 * st->cursx)];
                for (x = 0; x < 8; x++) {
                        *pp++ ^= cursorstate;
                }
@@ -163,6 +198,7 @@ at_resetcursor(void)
        cursorstate = 127;
        cursorstate_add = -1;
 }
+#endif
 
 /*
  * Scroll page by offset (may be negative or positive) and takes in
@@ -464,6 +500,11 @@ analogterm_one_frame (analogterm_sim_t *sim)
     st->blink=((int)blinkphase)&1;
 
 #if 0
+    /*
+     * XXX It's unclear what this was supposed to do.  The entry is
+     * conditional then only internal scope variables appear to be used,
+     * except for reading.
+     */
     if (st->blink!=i && !(st->gr_mode&A2_GR_FULL)) {
       int downcounter=0;
       /* For every row with blinking text, set the changed flag. This basically