Author Topic: Miscellaneous ASM Questions  (Read 14473 times)

0 Members and 1 Guest are viewing this topic.

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: Miscellaneous ASM Questions
« Reply #15 on: April 22, 2019, 09:34:37 pm »
I'm fairly sure that the parser hook doesn't let you intercept non-function tokens. I could be wrong about that, but I don't think so.

Offline E37

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +23/-0
  • Trial and error is the best teacher
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #16 on: April 23, 2019, 01:43:18 pm »
If you are ok with cheating a bit, there is a somewhat easier way to accomplish it. At a glance, the statistics variables all have their own dedicated ram area. A wild guess, but they are probably in statVars. If you can find the ram area for one of these stat vars, every time your hook runs, you can set the value of that stat var to the value of tau and instead of replacing the pi with a tau, replace it with that stat var. You could install a token hook to change whatever that stat var was to the tau character. It would look just like the tau token and work like it in all cases too. The only problem is that it would mess with the value stored in that variable unless you can find a way to save and restore it.
I'm still around... kind of.

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: Miscellaneous ASM Questions
« Reply #17 on: April 23, 2019, 02:10:19 pm »
Holy heck that is clever! So all you'd need a token hook, RawKeyHook, and parser hook.

Offline E37

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +23/-0
  • Trial and error is the best teacher
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #18 on: April 25, 2019, 01:12:16 pm »
Holy heck that is clever! So all you'd need a token hook, RawKeyHook, and parser hook.
I can't tell if you are being sarcastic. Given how much trouble I always have when trying to use more than one hook at a time, I suspect you are laughing at me.

Why a parser hook? Isn't that for modifying functions? I don't see why you would need one unless you are trying to disable all functions that would modify the hacked stat var's value. Since Sue Doenim has found a way using some hook or other to insert the token, it should be simple to change the stat var to tau's value then to be sure it is the correct value when it runs.
I'm still around... kind of.

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: Miscellaneous ASM Questions
« Reply #19 on: April 25, 2019, 06:34:33 pm »
Oh, good point, I was still stuck on translating the tau tokens at parse time.

I wasn't intending to come off as sarcastic, I just went from point A to C without sharing point B, so to speak. I was thinking context hooks and whatnot, but the hooks I listed are easier to work with. "Only" those hooks seemed like a way easier task to me :P

Your idea(s) are legitimately really clever and I just got really excited when I read it (how I feel whenever I see a really clever implementation or optimization).

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 27
  • Rating: +0/-0
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #20 on: April 28, 2019, 01:46:20 pm »
I was planning on using a finance variable to hold the value, since unlike statistic variables, they are borderline useless. The problem I was running into was that the TIOS doesn't seem to allow writing to variables from a hook. Whenever I copy a float into the RAM area from a hook, the OS sets the variable to 0, and when I use OS routines (stoSysTok), all kinds of junk happens. I can write to the variables from a normal program, but not from the hook. Is there any way to bypass this?

Offline E37

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +23/-0
  • Trial and error is the best teacher
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #21 on: April 30, 2019, 09:12:53 am »
I threw together a quick Axe program and I didn't have any issue with it. I can set finance vars just fine inside a hook. Here is my code:

:.TestApp
:LHook    //Loads the address of the hook into HL
:Asm(DB06)      //In a,(6) - This gets the page we are currently on and loads it into A
:Asm(EFAB4F)    //B_CALL EnableHomescreenHook
:Return
:
:Lbl Hook
:Asm(83)    //Make it a valid hook
:Asm(3d3d)    //dec a, dec a - Decrements A twice so that A is zero if we are in mode 2
:Asm(6F67)    //ld l,a , ld h,a - Load A into H and L
:!If        //If A is zero then HL will be zero and the stuff inside the if statement will run
:Asm(F5C5D5E5)    //Push AF, BC, DE, HL
:37->float{E9055}    //Convert my favorite number into a float and set 0x9055 to its value
:Disp "Test"    //Display some text to verify that the hook actually ran
:Asm(E1D1C1F1)    //Pop HL, DE, BC, AF
:End
:Asm(AF)    //xor a - Set the Z flag before I return
:Return

It worked perfectly well. To run it, you just have to compile it as an app, and run the app once. After that, every time you hit enter on the homescreen the weird 'N' finance var (the one that is kind of bolded) is set to 37. In fact, you can set 'N' to whatever you want, type it in on the homescreen, and it will tell you that 'N' is 37 so it does set the value before the program evaluates the finance var.

I actually wrote a whole response thinking that finance vars worked like the basic letter vars and that they weren't created until used. Since they use a fixed memory area and aren't created dynamically, that answer won't help you but Ill include it here in case some future person finds it useful.
Spoiler For Answer for a different problem:
Let me take a guess: The hook that you are trying to edit it in is the homescreen hook or some other hook that is run while the user is still typing things in. Your problem is that when the user is typing things on the homescreen, the OS opens an edit buffer. That edit buffer takes all of the free ram left so you can't create any new variable since there is no ram to create them in. I had this problem at one point as well. To check if I'm correct, you can use B_CALL MemChk from wherever you are having your problem. It returns the amount of free ram available. If it returns 0, then that's your issue.
Spoiler For (Optional) How edit buffers work:
This is what I've figured out from of trial and error and careful reading of the documentation. I'm pretty sure it is correct but I can't promise it is.
The OS uses edit buffers for a lot of different things. From what I can tell, they are used pretty much any time you type something into a field that has no size limits. So this includes everything you type on the homescreen, when you edit programs, and more. If you aren't familiar with how exactly edit buffers work, from what I understand, they basically expand to take all the free memory so that it doesn't need to resize and create delays while it is running. The memory moves around based on where your cursor is. Its structured so that the at the beginning of the edit buffer is all the data from the start of the edit buffer up to wherever your cursor is. It then has a giant blank gap where there is no data. At the bottom of the buffer is all of the data after the cursor. When you insert things into the buffer, it just inserts that data into the blank space after the cursor and moves it forward, no shifting data around. That also means when you move the cursor, it is moving data to and from the 'behind the cursor' area and the 'after the cursor' area to keep them accurate.
(I created my own program editor a while back and this isn't really a good excuse. Inserting at the top of a giant program and having to shift down all of the data each time a character is added isn't noticeably slower than inserting at the bottom  <_< )
How to fix it (assuming that I guessed your problem correctly)
You can't create any new variables while the homescreen edit buffer is open. I don't think there is any way around that without doing some serious hacks that would be far too much work. What you want to do instead, is just insert your finance variable using whatever trick you are doing normally. Then on your homescreen hook, use mode 2. That is the mode that is called right before it evaluates what is typed in on the homescreen. At that point the edit buffer will be closed. You don't need to take advantage of any of the features of this mode, just create your finance variable, set it to your value and return Z.
I'm still around... kind of.