Post Reply 
Entering the 'Edit Integer' window
01-08-2024, 11:43 PM (This post was last modified: 01-08-2024 11:55 PM by komame.)
Post: #21
RE: Entering the 'Edit Integer' window
(01-08-2024 10:49 PM)matalog Wrote:  Something in the line

h:=CHAR(EXECON("hc[&1+1]",CONVERT(value,"base",16)));

Seems to be crashing the program as soon as it is run on my calcualtor.

The problem stemmed from the fact that the EXECON instruction did not work correctly with the local variable "hc" (it probably requires a global variable). I had a variable "hc" with the same content also declared in HOME, which is why it accidentally worked correctly on my device. After removing this variable from HOME, the problem indeed occurred. Then, when I replaced the "hc" variable in the program with the global list "L1", everything worked correctly. The lack of support for local variables in EXECON seems to be a bug, but I need to investigate it more thoroughly. Below is the working version based on the list L1.

Code:
KEY KS_Minus()
BEGIN
  local white=16777215;
  local wd, wh, key, keys=MAKELIST(-1,X,0,50), value;
  keys:=REPLACE(keys,32,{7,8,9,-1,-1,4,5,6,-1,-1,1,2,3,-1,-1,0});
  keys:=REPLACE(keys,14,{10,11,12,13,14,99,15});
  keys[0]:=20;
  keys[1]:=21;
  keys[30]:=100;
  local s,h,i,he=0,ov;
  L1:=ASC("0123456789ABCDEF");
  RECT_P(80,80,240,146,0,white);
  BLIT_P(80,61,241,81,G0,0,0,1,20);
  TEXTOUT_P("Edit Integer",123,62,3,white);
  TEXTOUT_P("DEC:",88,86,2,0); TEXTOUT_P("HEX:",88,100,2,0);
  TEXTOUT_P("APPS => base, ENTER => OK",88,130,1);

  REPEAT
    wd:=TEXTOUT_P(STRING(value,1),115,86,2,0,144,white);
    h:=CHAR(EXECON("L1[&1+1]",CONVERT(value,"base",16)));

    RECT_P(wd,81,239,97); // clear the space after DEC
    wh:=TEXTOUT_P(h,115,100,2,0,144,white);
    RECT_P(wh,100,239,111); // clear the space after HEX

    IF value = 0 THEN
      115▶wd▶wh;
    END;
    IF he THEN
      RECT_P(wh,100,wh+6,111,0);
    ELSE
      RECT_P(wd,86,wd+6,97,0);
    END;
    key:=keys[WAIT(0)];
    CASE
      IF key=100 THEN
        RETURN "#"+h+"h";
      END;
      IF key >= 0 AND key < 10+he*9 or key=99 THEN
        ov:=value;
        value:=IFTE(key=99,IP(value/(10+6*he)),value*(10+6*he)+key);
        IF value>999999999999 THEN
          value:=ov;
        END;
      END;
      IF key=20 THEN // Apps changes the base
        he:=NOT he; //RECT_P(115,86,239,111); // unnecessary
      END;
      IF key=21 THEN   // Symb Key sets value to 0
        value:=0;
      END;
    END;
  UNTIL ISKEYDOWN(4);  //ESC will exit

  RETURN 46;  //one way to exit program with no apparent consequences
END;

EDIT:
Another solution is to declare the variable "hc" as EXPORT in the header:
Code:
EXPORT hc:="0123456789ABCDEF";
then it will also work correctly with EXECON.
Find all posts by this user
Quote this message in a reply
01-09-2024, 12:13 AM
Post: #22
RE: Entering the 'Edit Integer' window
I've found another solution that doesn't require the use of any variables in EXECON and it works correctly.

Code:
KEY KS_Minus()
BEGIN
  local white=16777215;
  local wd, wh, key, keys=MAKELIST(-1,X,0,50), value;
  keys:=REPLACE(keys,32,{7,8,9,-1,-1,4,5,6,-1,-1,1,2,3,-1,-1,0});
  keys:=REPLACE(keys,14,{10,11,12,13,14,99,15});
  keys[0]:=20;
  keys[1]:=21;
  keys[30]:=100;
  local s,h,i,he=0,ov;
  RECT_P(80,80,240,146,0,white);
  BLIT_P(80,61,241,81,G0,0,0,1,20);
  TEXTOUT_P("Edit Integer",123,62,3,white);
  TEXTOUT_P("DEC:",88,86,2,0); TEXTOUT_P("HEX:",88,100,2,0);
  TEXTOUT_P("APPS => base, ENTER => OK",88,130,1);

  REPEAT
    wd:=TEXTOUT_P(STRING(value,1),115,86,2,0,144,white);
    h:=CHAR(EXECON("GET(hex(&1),3)",CONVERT(value,"base",16)));

    RECT_P(wd,81,239,97); // clear the space after DEC
    wh:=TEXTOUT_P(h,115,100,2,0,144,white);
    RECT_P(wh,100,239,111); // clear the space after HEX

    IF value = 0 THEN
      115▶wd▶wh;
    END;
    IF he THEN
      RECT_P(wh,100,wh+6,111,0);
    ELSE
      RECT_P(wd,86,wd+6,97,0);
    END;
    key:=keys[WAIT(0)];
    CASE
      IF key=100 THEN
        RETURN "#"+h+"h";
      END;
      IF key >= 0 AND key < 10+he*9 or key=99 THEN
        ov:=value;
        value:=IFTE(key=99,IP(value/(10+6*he)),value*(10+6*he)+key);
        IF value>999999999999 THEN
          value:=ov;
        END;
      END;
      IF key=20 THEN // Apps changes the base
        he:=NOT he; //RECT_P(115,86,239,111); // unnecessary
      END;
      IF key=21 THEN   // Symb Key sets value to 0
        value:=0;
      END;
    END;
  UNTIL ISKEYDOWN(4);  //ESC will exit

  RETURN 46;  //one way to exit program with no apparent consequences
END;
Find all posts by this user
Quote this message in a reply
01-10-2024, 05:09 PM (This post was last modified: 01-10-2024 08:10 PM by komame.)
Post: #23
RE: Entering the 'Edit Integer' window
As promised, I have prepared another solution. This version operates on values from 0 to FFFFFFFFFFFFFFF (which is significantly larger than before) and it also has cursor control, so you can edit individual digits in DEC and HEX values. The program has become quite complicated due to the implementation of the editor. It may still be possible to simplify it.

Code:
KEY KS_Minus()
BEGIN
  local wd, wh, white=16777215;
  local p=1, key, keys=MAKELIST(-1,X,0,50), value=#0:64d;
  keys:=REPLACE(keys,32,{7,8,9,-1,-1,4,5,6,-1,-1,1,2,3,-1,-1,0});
  keys:=REPLACE(keys,14,{10,11,12,13,14,99,15});
  keys[0]:=20;
  keys[1]:=21;
  keys[7]:=22;
  keys[8]:=23;
  keys[30]:=100;
  local s,dt,i,ht,txd="",txh="",he=#0:1b;
  RECT_P(18,80,246+38+18,146,0,white);
  BLIT_P(18,61,247+38+18,81,G0,0,0,1,20);
  TEXTOUT_P("Edit Integer",123,62,3,white);
  TEXTOUT_P("DEC:",24,86,2,0); TEXTOUT_P("HEX:",24,100,2,0);
  TEXTOUT_P("APPS => base, ENTER => OK",88,130,1);

  Bits:=32;
  REPEAT
    IF value=0 THEN
      ""▶txd▶txh▶dt▶ht
    ELSE
      local sz:=STRING(value,1);
      dt:=MID(sz,2,SIZE(sz)-5);
      sz:=STRING(SETBASE(value,4));
      ht:=MID(sz,2,SIZE(sz)-5);
      txd:=CHAR(ASC(MID(STRING(value,1)▶txd,2,SIZE(txd)-5))+65248);
      txh:=CHAR(ASC(MID(STRING(SETBASE(value,4))▶txh,2,SIZE(txh)-5))+65248);
    END;

    wd:=TEXTOUT_P(txd,51,86,2,0,251,white);
    RECT_P(wd,81,301,97); // clear the space after DEC
    wh:=TEXTOUT_P(txh,51,100,2,0,251,white);
    RECT_P(wh,100,301,111); // clear the space after HEX

    IF value = #0 THEN
      51▶wd▶wh;
    END;
    INVERT_P(42+p*12,IFTE(he,100,86),48+p*12,IFTE(he,111,97));
    key:=keys[WAIT(0)];
    IF key<>-1 THEN
      key:=SETBASE(key,3);
    END;
    CASE
      IF key=100 THEN
        RETURN "#"+ht+"h";
      END;
      IF key=99 THEN
        IF p>1 THEN
          p:=p-1;        
          IF he THEN
            ht:=SUPPRESS(ht,p);
            value:=SETBASE(EXPR("#"+ht+":64h"),3);        
          ELSE
            dt:=SUPPRESS(dt,p);
            value:=EXPR("#"+dt+":64d");
          END;          
          IF(SIZE(STRING(value,1))<p) THEN
            p:=1;
          END;
        END;
      END;
      IF key >= 0 AND key < 10+he*9 THEN
        local ov=value, ot=IFTE(he,ht,dt);
        //value:= IFTE(key=99,value/(#10d+#6d*he),value*(#10d+#6d*he)+key);
        IF key<>99 THEN
          IF p=1 AND key=0 THEN
            CONTINUE;
          END;
          IF he THEN
            local ch:=CHAR(IFTE(key<10,key+48,key+55));
            IF SIZE(ht)<p THEN
              p:=p+1;
              ht:=ht+ch;
            ELSE
              ht[p]:=ch;
              p:=p+1;
            END;
            value:=SETBASE(EXPR("#"+ht+":64h"),3);
          ELSE
            IF SIZE(dt)<p THEN
              p:=p+1;
              dt:=dt+CHAR(key+48);
            ELSE
              dt[p]:=key+48;  
              p:=p+1;
            END;
            value:=EXPR("#"+dt+":64d");
          END;
          IF value > #FFFFFFFFFFFFFFF:64h THEN
            p:=p-1;
            value:=ov;
            IF he THEN
              ht:=ot;
            ELSE
              dt:=ot;
            END; 
          END;
        END;
      END;
      IF key=20 THEN // Apps changes the base
        he:=NOT he;
        IF he AND SIZE(ht)<p THEN
          p:=SIZE(ht)+1;
        END
      END;
      IF key=22 AND p>1 THEN // left
        p:=p-1;
      END;
      IF key=23 THEN // right
        IF he THEN
          IF p<=SIZE(ht) THEN
            p:=p+1;
          END;
        ELSE
          IF p<=SIZE(dt) THEN
            p:=p+1;
          END;
        END;
      END;
      IF key=21 THEN   // Symb Key sets value to 0
        value:=#0:64d;
      END;
    END;
  UNTIL ISKEYDOWN(4);  //ESC will exit

  RETURN 46;  //one way to exit program with no apparent consequences
END;

Piotr
Find all posts by this user
Quote this message in a reply
01-18-2024, 09:47 PM
Post: #24
RE: Entering the 'Edit Integer' window
(12-26-2023 09:38 PM)komame Wrote:  In general, to enter the "Edit Integer" window with the first press of Shift [-], there are two approaches. The first approach involves having an integer value on the history stack (marked with a "#" sign at the beginning) as someone already mentioned in this thread. As for the second approach, the only condition is to be in edit mode (blinking cursor). There doesn't need to be any value on the stack or even in the editing field where the cursor is; you just need to enter the edit mode of anything. For instance, you can go to HOME and press the space, multiplication, or any other key that outputs any character on the screen (then the cursor will appear - edit mode), then press Shift [-] and the "Edit Integer" window will open immediately. Another good example is the PPL editor, which is always in edit mode and pressing Shift [-] always immediately opens "Edit Integer".
If you're not in edit mode, the first press produces "#" and simultaneously switches to edit mode, so the second press opens the "Edit Integer" window and the "#" character here has no impact on the fact of opening this window.
I am convinced that the appearance of the "#" sign after pressing Shift [-] is not only problematic, but it is definitively a bug. This is because if there’s no value on the stack and the first press of Shift [-] causes "#" to appear, and the second press opens the "Edit Integer" window, then after finishing editing the value by clicking "OK" (or pressing Enter), the "#" sign is automatically added, which results in a double "#" sign, such as ##64, in the command line in HOME, which is an incorrect value.
I see no justification for such behavior.
⋮ (other good comments)

Nice analysis! Smile & thank you, Piotr, for adding a ticket for this to the bug tracker I've set up. (The bug got fixed! Big Grin)
Find all posts by this user
Quote this message in a reply
01-19-2024, 08:33 PM
Post: #25
RE: Entering the 'Edit Integer' window
(01-18-2024 09:47 PM)jte Wrote:  Nice analysis! Smile & thank you, Piotr, for adding a ticket for this to the bug tracker I've set up. (The bug got fixed! Big Grin)

Thanks, Jeff, for fixing that. Lately, your increased activity in bug fixing has been noticeable Smile It's inspiring optimism.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)