Author Topic: Evaluating Ti-Basic expressions using the Parser  (Read 4828 times)

0 Members and 3 Guests are viewing this topic.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Evaluating Ti-Basic expressions using the Parser
« on: November 17, 2010, 01:57:02 am »
This is for Correlation, for those of you who were going to ask  8)

Let's say HL points to the token currently being read by the Parser.  So if the Token is Output(, I increase HL to evaluate what the Row for the text will be.  Assuming the expression isn't just a number (it could be something like A + 1), how do I easily evaluate the expression?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Evaluating Ti-Basic expressions using the Parser
« Reply #1 on: November 17, 2010, 01:58:39 am »
Are you using the parser hook? (I forget)

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Evaluating Ti-Basic expressions using the Parser
« Reply #2 on: November 17, 2010, 01:59:27 am »
Are you using the parser hook? (I forget)

Yes, I'm using the parser hook

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Evaluating Ti-Basic expressions using the Parser
« Reply #3 on: November 17, 2010, 02:00:10 am »
well then all you need to do is use pop real, I believe.
Or something to do with the FPS

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Evaluating Ti-Basic expressions using the Parser
« Reply #4 on: November 17, 2010, 02:02:08 am »
Does HL point to the numerical data itself or the token data?
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Evaluating Ti-Basic expressions using the Parser
« Reply #5 on: November 17, 2010, 02:05:16 am »
Does HL point to the numerical data itself or the token data?

It could be anything.  HL points to the beginning of the expression for the Row of where to place the text.  The expression could be 3 + 6, it could be A, it could be sin(60), or it could be 5.

For example:

Output(A + 5, 3, "TEXT")

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Evaluating Ti-Basic expressions using the Parser
« Reply #6 on: November 17, 2010, 09:43:03 pm »
Sorry, it might take a while for me to get alll the info. I had a folder named Parser Notes, but it didn't have my actual notes in it. Right now I am figuring everything out all over again... And I have to convert all the hex *groan* :D
Here is the start of the hook I have. All it does is change int( into a getKey-ish thing:
Code: [Select]
;this first section is only if you are going to run it as a program. It stores the hook in
;AppBackUpScreen and sets it up as well.
 ld de,9972h      ;117299        this is a appbackupscreen+256
 ld a,(de)          ;1A              This will store the byte into a
 cp 83h            ;FE83            if a=83h, the hook might be active, so disable it...
 jr nz,3             ;2003            ...and quit
   xor a               ;AF               this sets a to 0
   ld (de),a          ;12               this disables the hook by overwriting the 83
   ret                  ;C9
 ld hl,9DB0h       ;21B09D         This is the location of the hook data
 ld bc,512         ;010002          number of bytes left in appbackupscreen
 push DE           ;D5
 ldir                  ;EDB0             this copies the hook data to 9972
 pop HL             ;E1                this points to the start of the hook in appbackupscreen
 in a,(6)            ;DB06             this checks the current page..
 B_Call(5026h)   ;EF2650           sets up the hook using HL=pointer to hook and a=page in memory
 ret                  ;C9

HOOK:
 add a,e            ;83            necessary to start a hook
 or a                 ;B7            like cp 0. if A=0, z flag is set
 ret z                ;C8
 push hl             ;E5            will need this later, but also need hl
 ld hl,B1B1h        ;21B1B1      B1 is the int( token
 sbc hl,bc          ;ED42         BC= the token, so if it is int(, HL-BC=0 and sets the Z flag
 pop hl              ;E1
 jr z,2                ;2802         so if it is the right token, skip 2 bytes
 xor a                ;AF            this is to set the z flag I think
 ret                   ; C9
;And this is where the code gets creative. HL is the number of arguments passed and OP1 has the last argument. the arguments are stored reverse in the FPS, so it can be confusing. To pass a value, just store it to OP1 and do FE01C9... So here goes...
 ld a,(843Fh)       ;3A3F84     this is the key press... it is used in my quickkeys program
 B_Call(478Ch)     ;EF8C47     this is SetXXOP1
 cp 1                  ;FE01        does something flag-wise to let it exit the hook with modified Ans
 ret                    ;C9

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Evaluating Ti-Basic expressions using the Parser
« Reply #7 on: November 18, 2010, 01:10:02 am »
Sorry, it might take a while for me to get alll the info. I had a folder named Parser Notes, but it didn't have my actual notes in it. Right now I am figuring everything out all over again... And I have to convert all the hex *groan* :D
Here is the start of the hook I have. All it does is change int( into a getKey-ish thing:
Code: [Select]
;this first section is only if you are going to run it as a program. It stores the hook in
;AppBackUpScreen and sets it up as well.
 ld de,9972h      ;117299        this is a appbackupscreen+256
 ld a,(de)          ;1A              This will store the byte into a
 cp 83h            ;FE83            if a=83h, the hook might be active, so disable it...
 jr nz,3             ;2003            ...and quit
   xor a               ;AF               this sets a to 0
   ld (de),a          ;12               this disables the hook by overwriting the 83
   ret                  ;C9
 ld hl,9DB0h       ;21B09D         This is the location of the hook data
 ld bc,512         ;010002          number of bytes left in appbackupscreen
 push DE           ;D5
 ldir                  ;EDB0             this copies the hook data to 9972
 pop HL             ;E1                this points to the start of the hook in appbackupscreen
 in a,(6)            ;DB06             this checks the current page..
 B_Call(5026h)   ;EF2650           sets up the hook using HL=pointer to hook and a=page in memory
 ret                  ;C9

HOOK:
 add a,e            ;83            necessary to start a hook
 or a                 ;B7            like cp 0. if A=0, z flag is set
 ret z                ;C8
 push hl             ;E5            will need this later, but also need hl
 ld hl,B1B1h        ;21B1B1      B1 is the int( token
 sbc hl,bc          ;ED42         BC= the token, so if it is int(, HL-BC=0 and sets the Z flag
 pop hl              ;E1
 jr z,2                ;2802         so if it is the right token, skip 2 bytes
 xor a                ;AF            this is to set the z flag I think
 ret                   ; C9
;And this is where the code gets creative. HL is the number of arguments passed and OP1 has the last argument. the arguments are stored reverse in the FPS, so it can be confusing. To pass a value, just store it to OP1 and do FE01C9... So here goes...
 ld a,(843Fh)       ;3A3F84     this is the key press... it is used in my quickkeys program
 B_Call(478Ch)     ;EF8C47     this is SetXXOP1
 cp 1                  ;FE01        does something flag-wise to let it exit the hook with modified Ans
 ret                    ;C9

Awesome, although I managed to do just that successfully.  What I'm trying to do is take care of arguments.  Here's my code, as well as where I'm stuck:

Code: [Select]

ParserHook:

relocate(appbackupscreen)




        .db 83h             ; Required for all hooks



;Check to see if the command is one of the following:

;Output to display the normal 6x8 routine.  This is
;for compatability in case a user wants to update
;his program to do a different font


;


        or a            ;Which condition?
;If an instruction is being
;read, we don't
;waste time seeing what
;instruction it is
        ret z


;For Text(), Output(), the value of register A will
;be equal to 2.  We can then check the value of the
;token being used.

cp 1
jr z, _
cp 2
jr nz, Not_2


_

ld hl, ($965D) ;HL now points
;to the instruction
;being read.

;Decrease hl to check for two byte token.  HL
;usually points to the second byte of a two byte token,
;if it is a two byte one

dec hl

ld a, (hl)
inc hl

cp $BB
jr z, Check_Instruction_Two_Byte_Token


;Is this the Output() statement?

cp $E0
jr z, CorrelationOutput



So, CorrelationOutput is run.  How do I solve something like A + 1 in Output(A+1, 2, "A")?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Evaluating Ti-Basic expressions using the Parser
« Reply #8 on: November 18, 2010, 01:18:11 am »
Okay, from there you will want to check the floating point stack, but I am not sure exactly where that is (there are a few bytes in RAM that point to various points). If you used Output(Y,X,<<String>> it will put a pointer to the temporary string in OP1, X at the top of the FPS, and then Y. I am not sure if PopReal or PopRealO1 might be useful B_Calls for you??? I am not sure if they work in hooks, though.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Evaluating Ti-Basic expressions using the Parser
« Reply #9 on: November 18, 2010, 01:00:26 pm »
Okay, from there you will want to check the floating point stack, but I am not sure exactly where that is (there are a few bytes in RAM that point to various points). If you used Output(Y,X,<<String>> it will put a pointer to the temporary string in OP1, X at the top of the FPS, and then Y. I am not sure if PopReal or PopRealO1 might be useful B_Calls for you??? I am not sure if they work in hooks, though.

I tried all this, to no avail.  I think it's because Output() is a class 2 function.  For example, I did Output(1,1, "AAAAAAAA"), and I could not find "AAAAAAAA" in OP1.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Evaluating Ti-Basic expressions using the Parser
« Reply #10 on: November 18, 2010, 02:03:26 pm »
What do you mean by class 2? Sorry, I have only ever used the int( command in my parser hooks.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Evaluating Ti-Basic expressions using the Parser
« Reply #11 on: November 18, 2010, 02:31:13 pm »
What do you mean by class 2? Sorry, I have only ever used the int( command in my parser hooks.

http://wikiti.brandonw.net/index.php?title=83Plus:Hooks:9BAC.  Int( is, I'm pretty sure, a class 1 function.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Evaluating Ti-Basic expressions using the Parser
« Reply #12 on: November 18, 2010, 03:08:51 pm »
Oh, no. Now I know what you mean. Class 2 are functions like If, Repeat, While and things like that. If a function has a "(" then it is class 1. Output( is class 1, just like int(. Output isn't part of that "most programming commands" thing.

EDIT: Unless it is Class 3...