Author Topic: Miscellaneous ASM Questions  (Read 2788 times)

0 Members and 1 Guest are viewing this topic.

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 20
  • Rating: +0/-0
    • View Profile
Miscellaneous ASM Questions
« on: February 16, 2019, 05:07:27 pm »
I have a few small questions that I'm not sure about, but I don't want to make a separate thread for each of them, so I'm combining them all in here.
1) What RAM pages can I use within programs without having any bad consequences?
2) When an appvar is less than 16kb and is archived, will it all be on the same ROM page?
3) Can you interface with headphones beyond simply sending them signals with the ring and the tip? If so, how?
If anyone can answer these questions, or refer me to a source that as answers, I would greatly appreciate it.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4571
  • Rating: +716/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #1 on: February 16, 2019, 06:44:13 pm »
1) What RAM pages can I use within programs without having any bad consequences?
Even numbered pages are execution protected by default, so executing code here will crash your calc. That said, you can definitely store data. On the calcs with USBs, page 83h has some data that should be preserved or restored in the first 128 bytes. Just remember that any OS routines that interact with memory or variables expect the right pages to be there.

Ram Pages (WikiTI)

2) When an appvar is less than 16kb and is archived, will it all be on the same ROM page?
No, you can't expect this. Variables won't cross sector boundaries (groups of four RAM pages), but they may cross pages.

3) Can you interface with headphones beyond simply sending them signals with the ring and the tip? If so, how?
I don't know what you mean by this, sorry :| If you want to use headphones, you have to interact directly with port 0.

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 20
  • Rating: +0/-0
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #2 on: February 16, 2019, 09:31:54 pm »
Thanks for the answers! I have just a couple more follow ups.
1) What RAM pages can I use within programs without having any bad consequences?
Even numbered pages are execution protected by default, so executing code here will crash your calc. That said, you can definitely store data. On the calcs with USBs, page 83h has some data that should be preserved or restored in the first 128 bytes. Just remember that any OS routines that interact with memory or variables expect the right pages to be there.

Ram Pages (WikiTI)
If you overwrite the data at the start of page $83, will bcall(_fillAppBaseTable) fix that?
3) Can you interface with headphones beyond simply sending them signals with the ring and the tip? If so, how?
I don't know what you mean by this, sorry :| If you want to use headphones, you have to interact directly with port 0.
I looked for a while, and the most info I could find/understand on output to headphones was that you have to use bits 0 and 1 of port 0 (the tip and the ring), and switch them between set and reset at a desired note's frequency (e.g. 440Hz for A4). I thought that for more high quality sound than simply beeps, you send a full byte at a time to the headphones, but after looking at the source code for TruSound, I realize that that was wrong.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4571
  • Rating: +716/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #3 on: February 16, 2019, 09:33:05 pm »
Yes, bcall(_fillAppBaseTable) should be sufficient.

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 20
  • Rating: +0/-0
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #4 on: April 04, 2019, 09:09:31 pm »
Where is the edit buffer for the homescreen stored? What general guidelines should I follow when editing it?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4571
  • Rating: +716/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #5 on: April 04, 2019, 09:26:42 pm »
What do you mean by the edit buffer? Edit buffers can be fairly complicated to work with.

The home screen does have a 128 byte buffer reserved as a copy for each char on it (16*8) called textShadow. There is another, similar buffer called cmdShadow that is intended for programs to use to back up that data.

For those two 128-byte buffers, you can do whatever you want with them. Worst case is that the home screen displays garbage. You can just fill it with spaces manually or preferably through one of the bcalls (I believe bcall 0x4546 is the bcall, but I forgot the name and I'm on mobile so it's a pain to search).

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 20
  • Rating: +0/-0
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #6 on: April 04, 2019, 10:35:47 pm »
What do you mean by the edit buffer? Edit buffers can be fairly complicated to work with.
I don't mean the text shadow, but the place the tokens that you type in are stored.  I want to work with hooks to change things.  My current plan is to make an app that supports double-clicking of certain keys to access the [2nd] function of that key (e.g. double clicking [^] puts the pi token).

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4571
  • Rating: +716/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #7 on: April 04, 2019, 10:57:31 pm »
Oh, you probably don't want to work with an edit buffer for a task like that!

The data is stored in the program named !. (That's an exclamation point). Just locate the variable, get its size and locate the end if the program.

Just remember that if you replace a 1-byte token with a 2-byte token, you'll need to increase the size of the var (use InsertMem and manually update the var's size bytes) and vice versa.

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #8 on: April 04, 2019, 11:03:16 pm »
... except you have to work with an edit buffer for that, because home screen input works by having that program open in an edit buffer.

Offline E37

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 258
  • Rating: +17/-0
  • Trial and error is the best teacher
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #9 on: April 18, 2019, 12:49:39 pm »
I know that I'm 2 weeks late to the party (and several months if you count it from the original post) but I actually did something pretty similar to what you are trying to do a while ago. If you want to mess around with the homescreen input, you should use a homescreen hook. (http://wikiti.brandonw.net/index.php?title=83Plus:Hooks:9B8C) Since you mentioned hooks already, I assume that you already know how to use them. If you use the mode when A=2, then you don't have to worry about edit buffers and you can just open prgm! and edit it like anything else without worrying about edit buffers and such. If you want to change what a key sends on a double press by using the mode where A=1, you are in for something much trickier. It is simple to change B to the keypress that produces the token that you want. If I recall correctly, you should change keyExtend to the second byte if it is a two byte keypress.
The problem is with removing the previous token. There is an edit buffer command to shift the cursor one token to the left (BufLeft) so that might work, and then you could call BufReplace to replace that token that was previously typed in with the one you want to change it to and then return nz to ignore the keypress since you handled it manually. I don't know how this would work when the user is in insert mode.
I'm still around... kind of.

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 20
  • Rating: +0/-0
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #10 on: April 19, 2019, 11:53:00 am »
I don't think I'll keep trying to make that program. I like the idea, but there are just some logistical issues. Things like "sin(arcsin(" would get messed up a bunch, and I don't see a nice way to fix that problem. I decided to work on another similar but probably simpler thing. My friend is a tau enthusiast, and he would like the pi keypress to be replaced with a functional tau keypress. (In case you don't know, τ=2π.) I was thinking I would set a raw key hook, and whenever pi is pressed, I would add tau to prgm!. Then I'd install a homescreen hook to allow the tau token to signify its value. What I'm not sure about is what prgm# is. Wikiti says "To retreive the expression to be evaluated use prgm#," but does that mean I edit prgm# to change the answer? Does prgm# hold a copy of prgm!, or what? My plan was to insert "(6.28[etc.])" Where ever a tau was.
« Last Edit: April 19, 2019, 12:26:52 pm by Sue Doenim »

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4571
  • Rating: +716/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #11 on: April 19, 2019, 12:04:45 pm »
Oh, you might actually be able to do that relatively easily. If there is a getKey code for the tau token (you'd have to look it up, there might not be), then you could use a getKey hook to override a [PI] keypress.

Then you also have a parser hook that replaces all of the tau tokens with 2pi before passing it back to the OS parser. The nice thing is that 2pi takes 2 bytes and tau is a 2-byte token, so you don't even need to resize. I don't think the parser hook has a mode for when a program ends, so you won't be able to re-replace the 2pis as taus that way, but you could probably make your getKey hook do it!

EDIT: there is in fact a ktau in the ti83plus.inc ! You'll want to use the RawKeyHook and the Parser hook.

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 20
  • Rating: +0/-0
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #12 on: April 20, 2019, 11:23:59 pm »
I got the Raw Key Hook to work, so now pi keypresses put a tau token. I'm not sure about the Parser hook. I think I understand it pretty well. Replacing all of the tau tokens with 2pi wouldn't always work, though, would it? If you have 3tau, wouldn't that become 32pi?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4571
  • Rating: +716/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #13 on: April 21, 2019, 03:35:41 pm »
Oh, you are right about that. That would be a little more difficult as you would have to resize variables.
When the parser hook triggers mode 0, the name of the program being parsed is in basic_prog. You could first scan for all tau tokens that can be directly replaced (and replace them), while counting all of the ones that need extra work. Then verify there is enough memory to insert an additional two bytes for each remaining entry. Use InsertMem at the end of the program, but remember to adjust the variable's size bytes as well as basic_end. Finally, replace the remaining tau tokens with "(2pi)".

It is a complicated process, so good luck!

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 20
  • Rating: +0/-0
    • View Profile
Re: Miscellaneous ASM Questions
« Reply #14 on: April 22, 2019, 09:31:44 pm »
You wouldn't be able to modify the function of the tau token using the other modes of the parser hook, would you? That seems like it would be a cleaner, if more difficult solution.