Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: Xeda112358 on January 29, 2013, 06:00:57 pm

Title: Tutor App
Post by: Xeda112358 on January 29, 2013, 06:00:57 pm
EDIT:22 April 2013
This topic is now renamed Tutor App as the project has evolved. An updated version can be found at this post (http://ourl.ca/18259;msg=291846) later in the topic.


(original post)

On TI-BD, there was an idea for simulating keypresses, so I offered my assembly program to simulate a keypress. But then they wanted to simulate a list of keypresses, so I finally started working on that. Currently, whenever the OS looks for keypresses (not while programs are executing), the hook looks for the hacked string 17 (AA11h) and if it contains data, it will read the numbers one at a time, executing the keypresses.

The keypresses are not getKey values. If you have used assembly keycodes (where Enter=9, for example), that is the set you will want to use. To simulate pressing [2nd]+[nobbc], add 56, to simulate [ALPHA]+[nobbc], add 112. So for example, [Graph]=49, [PRGM]=31, [MATH]=47. To open the graph screen, then press [2nd][prgm] and then select 1:ClrDraw, use:
Code: [Select]
"49,87,9
To do that, then select the A:Pen from the draw menu, add an additional 87,159 (159=112+47). Finally, the arrows are 1=down,2=left,3=right,4=up. Combining all this:
Code: [Select]
"49,87,9,87,159,9,2,2,2,2,1,1,1,1,3,3,3,3,4,4,4,4
That will select ClrDraw, then Pen, then it will draw you a box :)
Spoiler For List of Key Codes:
01      Down
02      Left
03      Right
04      Up

09    Enter
10    +
11    -
12    *
13    /
14    ^
15    Clear

17    (-)
18    3
19    6
20    9
21    )
22    tan(
23    vars

25    .
26    2
27    5
28    8
29    (
30    cos(
31    prgm
32    Stat
33    0
34    1
35    4
36    7
37    ,
38    sin(
39    APPS
40    XTON

42    sto>
43    ln(
44    log(
45    X^2
46    X^-1
47    Math
48    Alpha
49    graph
50    trace
51    zoom
52    window
53    Y=
54    2nd
55    mode
56      delete

255    [2nd][On]
254    [prgm][enter] displays prgmA (Even if it doesn't exist)
253    [2nd][Stat]
252    Displays LA (list A)
251    Disp If
250    [Graph]
249    Catalog
248    nothing
247    Same as FE
246    RAM Clear
Spoiler For How To Make Hacked Strings:
There are several "easy" ways, but they involve getting the hacked string name in a string, then use Rcl Ans in a program to paste the name their. They typically have funky names, so don't be alarmed if your string is named something like GDB1-- it is because the OS doesn't have real names for them, so it uses what it has. Anyways:
  • Xtravar Beta (http://www.ticalc.org/archives/files/fileinfo/391/39138.html) provides an easy way to select hacked variables. In this case, find the Strings, and search for String 17 (11h) it will have a name 'sigma'x.
  • You can use Celtic 3 to do det(17,"AA11
  • You can use BatLib to do dim(5,"AA11
  • Xtra (http://www.ticalc.org/archives/files/fileinfo/425/42505.html) will take a list input to create a hacked var token. This has an included opcode.
Title: Re: Simulated Keypresses
Post by: shmibs on January 29, 2013, 06:12:17 pm
wow, that's pretty cool =D
how long is the delay between keypresses? does it just execute every single time the hook is called?
Title: Re: Simulated Keypresses
Post by: Xeda112358 on January 29, 2013, 06:18:17 pm
Thanks, and yes, there is no delay between keypresses. It can even press non-repeating keys multiple times in a row :)
Title: Re: Simulated Keypresses
Post by: Sorunome on January 29, 2013, 06:38:38 pm
Sounds awesome, as always :P
Title: Re: Simulated Keypresses
Post by: Xeda112358 on January 30, 2013, 06:43:56 am
I need to adjust the program a bit because I realised that I made a silly mistake. (Warning: This is complicated ASMy stuff): Since the keyhook automatically deletes the first element from the string once it is read, I ran into a problem when I made a key sequence to create and edit a program or equation. I realised this last night which is why I tested it and it is because the edit buffer is still open. I think that what I will do is if the edit buffer is open, I will just fill the bytes with 00 and treat those as null bytes, then when the edit buffer is closed, I will delete all the appropriate stuff.

Now, stuff I have been thinking of adding:
EDIT: To give an idea of the syntax for *, I am thinking something like 3*7 will simulate pressing right 7 times. I already have the code planned for this, so if I have time today, I will try to have it implemented :)
Title: Re: Simulated Keypresses
Post by: Xeda112358 on January 30, 2013, 01:55:36 pm
Yay, I finished something on my lunch break! Now you can do *[num] to execute a key press [num] times in a row. As well, I fixed the issue with modifiying the string while the edit buffer was open, so you can now use this program to create programs and modify them!

EDIT: I have attached an updated version. The new version allows you to set a delay for reading each key press. Now you can actually see what is going on making this program possibly an excellent tool for on-calc tutorials.
Title: Re: Simulated Keypresses
Post by: Sorunome on January 30, 2013, 07:12:06 pm
This sure is amazing
Title: Re: Simulated Keypresses
Post by: Xeda112358 on January 30, 2013, 07:16:46 pm
Hehe, I already started an idea on TI-Basic Developer about maybe creating an on-calc BASIC tutorial that steps users through the process of creating programs and how to use each command (like CtlgHelp, but much more involved). I have even started an idea for adding annotations so that you can inform the user what is happening at each step. I estimate that it would take one page to cover all of the commands and we could use a second page for the programming tutorials.

EDIT: I started making an app with some simple scripty commands so that non-assembly programmers can contribute code. I plan to add in menus, but for now it automatically installs the Hello World example walkthrough thingy. The code looks like:
Code: [Select]
ex_helloworld:
     Delay(30)
;     Text(56,0,"New Program")
     Key(skprgm)
     Key(skright)
     Key(skright)
     Key(skenter)
     Key(skpower)      ;H
     Key(sksquared)     ;I
     Key(skminus)      ;W
     Key(sk7)          ;O
     Key(sktimes)      ;R
     Key(skrparen)     ;L
     Key(skinverse)    ;D
     Key(skEnter)
     Key(skClear)
     Key(skprgm)
     Key(skright)
     Repeat(skdown,7)
     Key(skEnter)

     Key(skEnter)
     Key(skprgm)
     Key(skright)
     Repeat(skdown,2)
     Key(skEnter)
     Key(sk2nd)
     Key(skAlpha)
     Key(skplus)
     Key(skH-112)
     Key(skE-112)
     Key(skL-112)
     Key(skL-112)
     Key(skO-112)
     Key(skSpace-112)
     Key(skW-112)
     Key(skO-112)
     Key(skR-112)
     Key(skL-112)
     Key(skD-112)
     Key(skAlpha)
     Key(skMath)
     Repeat(skRight,3)
     Repeat(skDown,3)
     Key(skEnter)
     Key(sk2nd)
     Key(skMode)

     Key(skPrgmToken)
     Key(sk2nd)
     Key(skAlpha)
     Key(skpower)      ;H
     Key(sksquared)    ;I
     Key(skminus)      ;W
     Key(sk7)          ;O
     Key(sktimes)      ;R
     Key(skRParen)     ;L
     Key(skinverse)    ;D
     Key(skEnter)
     ExitTutor()
It is 65 bytes, by the way.
Title: Re: Simulated Keypresses
Post by: chickendude on January 31, 2013, 12:22:59 pm
That's really cool, Xeda.  On-calc tutorials would be neat :)
Title: Re: Simulated Keypresses
Post by: Xeda112358 on January 31, 2013, 10:00:20 pm
Thanks! I finished up the main functions for the keyhook, now I need to add in a menu for the app to access the tutorials.
Code: (Current Supported Functions) [Select]
/=====================\
|    Key(val)         | 1 byte
\=====================/
  This is the main command. This tells the engine which key to
simulate. For example, to simulate [ENTER], use Key(skEnter).
/=====================\
|    Delay(val)       | 2 bytes
\=====================/
  This sets the delay between simulated key presses. I find 30
to work well.
/=====================\
|    Text(y,x,string) | 4 bytes + length of string
\=====================/
  This is how you communicate to the user. This is like the
BASIC command, except it draws over whatever is on the LCD, not
just the graph screen. For the worried, this does not affect the
contents of the graph screen. So for example:
     Text(56,0,"Hello World!")
/=====================\
|    WaitForKey(key)  | 2 bytes
\=====================/
  This waits for the user to press the appropriate key. When the
user presses the key, it will be registered. No other keys
respond while waiting.
/=====================\
|    Repeat(key,num)  | 3 bytes
\=====================/
  This will simulate a key press a number of times in a row.
This is useful for navigating menus to get to an item.
/=====================\
|    ExitTutor()      | 1 byte
\=====================/
  This ends the tutorial and normal OS stuff resumes.

  These commands should be enough for most tasks. However, if
there are more commands for the adventurous:
/=====================\
|    SetAns(num)      |
\=====================/
  This will set the "Ans" variable to the specified value. Note
that this whole program works with 1-byte values, 0 to 255.
/=====================\
|    TestAnsEqu(num)  |
\=====================/
  If 'Ans' is equal to 'num', then 'Ans' is set to 1, else it
is set to 0.
/=====================\
|    GetKey(num)      |
\=====================/
  Stores the user's keypress to Ans. This isn't as responsive
as it could be, yet, but it works.
/=============================\
|    JumpIfAnsEqu(num,label)  |  4 bytes
\=============================/
  This will jump to a label if Ans=num. Note that the label must
be on the same flash page.
/=====================\
|    PushAns()        |
\=====================/
  This pushes Ans onto a stack for later retrieval with
PopAns(). The stack is currently 240 bytes, but it may be
smaller in the future.
/=====================\
|    PopAns()         |
\=====================/
  This removes the last value on the stack and stores it to
'Ans'.
I think once I add in the menu the process will be much easier. I am glad I added in the ability to use Text() today because it makes it much more interactive :) The code that is used for the "tutorial" in the screenie is:
Code: [Select]
ex_helloworld:
     Key(skClear)
     Delay(30)
     Text(44,0,"First, we need to make")
     Text(50,0,"a new program. Press PRGM,")
     Text(56,0,"and the Tutor will do the rest.")
     WaitForKey(skPRGM)
     Key(skright)
     Key(skright)
     Key(skenter)
     Text(56,0,"Enter the program name")
     Key(skpower)      ;H
     Key(sksquared)     ;I
     Key(skminus)      ;W
     Key(sk7)          ;O
     Key(sktimes)      ;R
     Key(skrparen)     ;L
     Key(skinverse)    ;D
     Key(skEnter)
     Key(skClear)
     Key(skprgm)
     Key(skright)
     Repeat(skdown,7)
     Key(skEnter)
     Text(50,0,"Press ENTER to go to the")
     Text(56,0,"next line of code.")
     WaitForKey(skEnter)
     Key(skprgm)
     Key(skright)
     Repeat(skdown,2)
     Key(skEnter)
     Key(sk2nd)
     Key(skAlpha)
     Key(skplus)
     Key(skH-112)
     Key(skE-112)
     Key(skL-112)
     Key(skL-112)
     Key(skO-112)
     Key(skSpace-112)
     Key(skW-112)
     Key(skO-112)
     Key(skR-112)
     Key(skL-112)
     Key(skD-112)
     Key(skAlpha)
     Key(skMath)
     Repeat(skRight,3)
     Repeat(skDown,3)
     Key(skEnter)
     Key(sk2nd)
     Key(skMode)

     Key(skClear)
     Text(50,0,"Enter the program name,")
     Text(56,0,"then press ENTER to run it.")
     Key(skNULL)
     Key(skPrgmToken)
     Key(sk2nd)
     Key(skAlpha)
     Key(skpower)      ;H
     Key(sksquared)    ;I
     Key(skminus)      ;W
     Key(sk7)          ;O
     Key(sktimes)      ;R
     Key(skrparen)     ;L
     Key(skinverse)    ;D
     WaitForKey(skEnter)
     ExitTutor()
Title: Re: Simulated Keypresses
Post by: chickendude on February 01, 2013, 06:05:19 am
Wow, that's just incredible! The text feature is a really nice touch.

What do you have in mind for the menus?
Title: Re: On-Calc Tutorials
Post by: Xeda112358 on February 01, 2013, 06:43:33 am
Thanks! In code, I currently have this but I want to change it:
Code: [Select]
MainMenu:
     Menu("Command Index",cmdindex)
     Menu("Math Tutorials",mathtutorials)
     Menu("Programming Tutorials",programming)
     .db 0
programming:
     Item("Hello World",ex_helloworld,0)
cmdindex:
mathtutorials:
     .db 0
Anything labeled as a Menu() will open a new menu when it is selected and anything labeled as Item() well set it as the tutorial to use. I think I will make it a simple list that the user can scroll through and I think that I will change the format, too. This way the menu or item name is part of the data and there can be several organisation options. For example, a command that falls under several categories might be like this:
Code: [Select]
MainMenu:
     Menu(cmdindex)
     Menu(mathtutorials)
     Menu(probstattutorials)
     .db 0
cmdindex:
     .db "Command Index",0
     Item(cmd_nCr)
     .db 0

mathtutorials:
     .db "Math",0
     Item(cmd_nCr)
     .db 0

probstatstutorials:
     .db "Probability/Statistics",0
     Item(cmd_nCr)
     .db 0
cmd_nCr:
     .db "nCr",0
     .db tut_nCr
And now each menu is just an LUT of 3-byte elements. 1 byte is for the Menu/Item and 2 bytes for the pointer to the item data.
Title: Re: Simulated Keypresses
Post by: TIfanx1999 on February 12, 2013, 04:17:52 pm
Congratulations. If I'm understanding this correctly, it looks like you've made something similar to batch files to automate processes. Very cool! ^^
Title: Re: Simulated Keypresses
Post by: tr1p1ea on February 12, 2013, 05:25:18 pm
Wow cool project! "Possessed calculators" :P.

It would be cool to use this in conjunction with compatible games for a walkthrough or 'replay' function.
Title: Re: Simulated Keypresses
Post by: Xeda112358 on February 12, 2013, 07:31:49 pm
Yeah, I am not exactly sure what it is that I made. I know Runer said it was a macro and an IRL friend said it was like a macro that you would use in excel.

@tr1p1ea: I was thinking about that, but the OS doesn't let these hooks work during program execution unless you are at a Pause, Input, Menu( or something similar :[ It would be pretty awesome if it did, though.
Title: Re: Tutor App
Post by: Xeda112358 on April 22, 2013, 09:02:55 pm
I finally worked on this a little last night and today since it might actually be useful to other students and professors on campus. I scrapped my original menu idea for a much simpler version. Now you can scroll through the tutorials and I made the setup relatively easy for adding new tutorials. There is also a filter option to view tutorials by category.

So some documentation since I haven't updated the readme:

There are two types of items that can be selected from the menus-- Tutorials and Menu Links. Menus have the following syntax:
Code: [Select]
Menu_0:
     .db "Menu name",0
     .dw number_of_items
     .dw Item_pointer_0
     .dw Item_pointer_1
     .dw Item_pointer_2
...
The item pointers point to an item of the types named above. Tutorials have the following syntax:
Code: [Select]
Tuto_0:
     .db "Item Name",0,0
     ;Tutorial data
     ExitTutor()       ;also .db 0
Menu Links have the following format:
Code: [Select]
MenuLink_0:
     .db "Item Name",0,1
     .dw MenuPtr

I also added a new tutorial function called Routine() which allows you to call tutorial code as subroutine. I made this because as I was adding some of the Linear Algebra commands, there was a bunch of duplicate code. Subroutines end the same way as tutorials, with ExitTutor(). Code will then resume after the point of the call.

Finally, I am also trying to keep in mind the goal of having external tutorials and a multipage app. Some of the source code is currently unoptimised since it is a one-page app, but once page boundaries have to be worried about, it will be useful.

EDIT: The original download had the wrong version of the app (correct source, though). It is corrected with an updated version.
Title: Re: Tutor App
Post by: Dapianokid on April 22, 2013, 09:06:34 pm
wuts PM 1.2?
Title: Re: Tutor App
Post by: Xeda112358 on April 22, 2013, 09:08:24 pm
Oh, that is an app that was causing trouble for somebody on TI-BD that I was investigating. I am actually supposed to delete that now that the problem is resolved :P
Title: Re: Tutor App
Post by: Dapianokid on April 23, 2013, 04:41:47 pm
I can't find it anywhere..
Anyways, can you write a similar application that just allows us to give it a "keypress" macro, hidden in interrupts? OMG that would rock.. and for Nspires!
Title: Re: Tutor App
Post by: Xeda112358 on April 23, 2013, 09:19:55 pm
Oh, the app is not for public use, that is why (the PM 1.2 app).

Anyways, I figured out that the file I uploaded was the wrong version, so sorry about the crash to the two people that downloaded it :[ I updated it with the new version which has a few more tutorials and menu options. The current tutorials are:

Binomial CDF
Binomial PDF
Determinant
Integral
Matrix Inverse
Derivative
Normal CDF
Reduced Row Echelon
Hello World programming example
Title: Re: Tutor App
Post by: DJ Omnimaga on April 24, 2013, 03:06:32 am
Wow that is great! At first I was worried at how fast that other screenshot went through keypresses, but then you slowed it down. It should definitively be a nice learning tool :)
Title: Re: Tutor App
Post by: mdr1 on May 12, 2013, 06:31:50 pm
It is such a good idea !

Error : Selecting the "Determinant" tutorial, and pressed 2nd, then ON, the calculator was turned off and when I turned it on, I was forced to follow the key sequence and to be on a loop of incorrect calculation.
Title: Re: Tutor App
Post by: Joshuasm32 on May 12, 2013, 06:33:52 pm
The concept would be quite useful in many scenarios (i.e., it would make an AWESOME setup tutorial for a shell).   :thumbsup:
Title: Re: Tutor App
Post by: Sorunome on May 12, 2013, 06:34:42 pm
wow, that looks pretty awesome, nice work xeda!
(btw, nice new avatar)
Title: Re: Tutor App
Post by: Xeda112358 on May 12, 2013, 07:57:41 pm
@mdr1: Thanks for letting me know that, I never even thought about that possible error. I will have to allow 2nd+ON to exit the tutorial, too (currently ON allows you to exit early).