Calculator Community > ASM

Miscellaneous ASM Questions

<< < (5/5)

Sue Doenim:
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?

E37:
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.

Navigation

[0] Message Index

[*] Previous page

Go to full version