Author Topic: Caboose: Automatically Append "Ans" to Applicable Entries  (Read 7147 times)

0 Members and 1 Guest are viewing this topic.

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 27
  • Rating: +0/-0
    • View Profile
Caboose: Automatically Append "Ans" to Applicable Entries
« on: January 04, 2021, 11:10:09 am »
Here's an app that I made that sets a hook to check every entry and to add "Ans" whenever it makes sense, such as when it ends in "-", "sin(", or an empty entry box. It's a pretty simple program, but it's a pretty solid time saver.
https://github.com/joeldemars/caboose

EDIT: Changed link to reflect updated username.
« Last Edit: February 07, 2021, 12:47:42 am by Sue Doenim »

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6266
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Caboose: Automatically Append "Ans" to Applicable Entries
« Reply #1 on: January 04, 2021, 11:39:57 am »
That's pretty cool!
/e

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 346
  • Rating: +47/-0
    • View Profile
Re: Caboose: Automatically Append "Ans" to Applicable Entries
« Reply #2 on: January 04, 2021, 08:48:32 pm »
Useful indeed =]
I might have a fix for you, tVarStrng ($AA) appears to be missing from the list of word tokens.
Cheers.

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 27
  • Rating: +0/-0
    • View Profile
Re: Caboose: Automatically Append "Ans" to Applicable Entries
« Reply #3 on: January 04, 2021, 10:51:58 pm »
Useful indeed =]
I might have a fix for you, tVarStrng ($AA) appears to be missing from the list of word tokens.
Cheers.
Awesome, thanks! And nice catch! It's fixed now.

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 346
  • Rating: +47/-0
    • View Profile
Re: Caboose: Automatically Append "Ans" to Applicable Entries
« Reply #4 on: January 08, 2021, 12:00:13 am »
You're welcome.

Switching to max CPU speed could be significant, at the very beginning of the app & hook codes.
Don't forget to backup af before that if needed, of course :
in a,(2)
rlca
and 1
out (32),a

Disabling interrupts is also a thing, and i would even recommend it after each bcall aswell.

Cheers.
« Last Edit: January 08, 2021, 12:09:46 am by the_mad_joob »

Offline Geekboy1011

  • The Oneironaut
  • Donator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2031
  • Rating: +119/-2
  • Dream that Awakening dream
    • View Profile
Re: Caboose: Automatically Append "Ans" to Applicable Entries
« Reply #5 on: January 08, 2021, 09:34:38 am »
The amount of time this would have saved me.....
nice work!

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 27
  • Rating: +0/-0
    • View Profile
Re: Caboose: Automatically Append "Ans" to Applicable Entries
« Reply #6 on: January 10, 2021, 01:36:33 pm »
You're welcome.

Switching to max CPU speed could be significant, at the very beginning of the app & hook codes.
Don't forget to backup af before that if needed, of course :
in a,(2)
rlca
and 1
out (32),a

Disabling interrupts is also a thing, and i would even recommend it after each bcall aswell.

Cheers.
There are for sure a lot of optimizations (especially hackish ones) I could make. Probably the easiest thing to do for a pretty good speedup would be to check the tokens in order of most common to least common, instead of just from lowest to highest value. Since it's a flash app, size isn't much of a concern, so if I really wanted to, I could replace `CPIR` with an unholy chain of `CP XX \ JR Z, appendAns`. I couldn't tell that there was any noticable lag as it is though, so I decided to prioritize readability over raw speed. I might decide to change that. I think the more pressing issue is the lack of any sort of UI, so I think I'll tackle that first.

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 27
  • Rating: +0/-0
    • View Profile
Re: Caboose: Automatically Append "Ans" to Applicable Entries
« Reply #7 on: January 14, 2021, 12:53:05 am »
I ran across a pretty significant bug where Caboose is still active when using the up arrow to go through previous entries, so an extra Ans sometimes gets inserted when you press enter to recall one. To fix this, I tried switching to using the homescreen hook condition where A = 2 (waiting for an expression to be entered) instead of listening for the enter key. My plan was to go in and add Ans to the end of prgm# before it gets evaluated, but the problem is that Ans is never written to the screen. Is there any kind of "update homescreen" bcall that I can use to make sure it does get displayed? I don't think dealing with it manually using PutS is viable, since MathPrint potentially screws it all up. Are there any other ways around it? Would reopening the edit buffer then adding Ans work? Or should I go back to the older way of listening for enter and find some way to tell whether something is being recalled from previous entries?

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 346
  • Rating: +47/-0
    • View Profile
Re: Caboose: Automatically Append "Ans" to Applicable Entries
« Reply #8 on: January 14, 2021, 03:29:54 am »
Is there any kind of "update homescreen" bcall that I can use to make sure it does get displayed?
I might have the code you need, but it's not just a bcall.
It was originally designed to fully restore home after returning from an asm prgm (no matter the split and mathprint settings).
I tested it as an updater from a homescreen hook just to see, and it seems a few adjustments are needed.
Will post the code later today as an edit of this post, so stay tuned.

EDIT :

Great news, i managed to adapt my code.
Note that it's designed to work for a homescreen hook with a=2, i haven't fully tested it with the other contexts.
Also, though it works as expected (everything properly displayed after a _clrlcdfull), it might not solve your problem, cause i believe it's not a display issue, more like the fact that the Ans you add should also be added to the list of mp home entries on RAM page 3.
Anyway, that will be a good way to tell if i'm right about that.
Code: [Select]
.db $83

di
ld c,a
in a,($02)

rla
jr nc,hook_max_speed

ld a,$01
out ($20),a

hook_max_speed

dec c

dec c
jr z,hook_evaluate

cp a

ret

hook_evaluate

bit 5,(iy+$44)
jr z,hook_core

ld a,$03
ld b,64
ld hl,$DA7E
out ($05),a

bcall(_savedisp)

di
xor a
out ($05),a

hook_core

;here goes the code that alters the homescreen entry

bit 5,(iy+$44)
jr nz,hook_update_mp

ld a,(currow)
push af

bcall(_rstrshadow)

di
pop af
ld (currow),a

ret

hook_update_mp

ld a,$03
ld b,64
ld hl,$DA7E
out ($05),a

bcall(_restoredisp)

di
xor a
out ($05),a

ret
« Last Edit: January 14, 2021, 08:50:18 am by the_mad_joob »

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 27
  • Rating: +0/-0
    • View Profile
Re: Caboose: Automatically Append "Ans" to Applicable Entries
« Reply #9 on: January 14, 2021, 01:46:20 pm »
Great news, i managed to adapt my code.
Note that it's designed to work for a homescreen hook with a=2, i haven't fully tested it with the other contexts.
Also, though it works as expected (everything properly displayed after a _clrlcdfull), it might not solve your problem, cause i believe it's not a display issue, more like the fact that the Ans you add should also be added to the list of mp home entries on RAM page 3.
Anyway, that will be a good way to tell if i'm right about that.
Looks like you're right. I totally forgot to mention that there was crashing that I couldn't explain with my new version. I assumed that it was because of some mistake I made, but it looks like it was from issues with the entry buffer/RAM page/MathPrint. Using the code that you wrote doesn't change the behavior, as far as I can tell. Ans still doesn't show up, and it still crashes after a few entries. It helps a ton to know that it's an issue with the buffer. That explains why bcall _BufReplace only writes Ans to the screen when MathPrint is on. After seeing what a nightmare retroactively dealing with the entry buffer would be, I think it would be easier to go back to listening for enter and just find a way to check if it's going back through entries.

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 346
  • Rating: +47/-0
    • View Profile
Re: Caboose: Automatically Append "Ans" to Applicable Entries
« Reply #10 on: January 14, 2021, 06:55:06 pm »
I believe i found how to solve everything, and i even discovered an undocumented mathprint flag on my way =]
This code simulates ans+enter in a very clean way.
By clean i mean exactly as if you did it manually, which means you don't have to deal with adding the entry internally at all.
In short, the homescreen hook replaces enter by ans, and right after that, a getcsc hook automatically simulates enter.
That also means you don't have to check if there is enough memory for ans, in which case only enter is processed.
Also, it appears you don't need to check if a menu is open at all.
Note that though the homescreen hook is permanent, the getcsc hook is temporary, and properly restores any older one if there was one.
Enjoy :
Code: [Select]
hook_home

.db $83

di
ld c,a
in a,($02)

rla
jr nc,hook_home_max_speed

ld a,$01
out ($20),a

hook_home_max_speed

dec c
jr nz,hook_home_exit

ld a,b

cp kenter
jr z,hook_home_enter

hook_home_exit

cp a

ret

hook_home_enter

bit 3,(iy+$49)
jr nz,hook_home_exit

;Here is where you check if you want to add Ans or not.
;If yes, jump to hook_home_ans_enter, otherwise return.

hook_home_ans_enter

ld de,appbackupscreen
ld hl,flags+hookflags2
ld a,(hl)
ld (de),a
or %00000001
ld (hl),a
ld bc,3
inc de
ld hl,getkeyhookptr
ldir
ld hl,hook_keyboard
ld (getkeyhookptr),hl
in a,($06)
ld (getkeyhookptr+2),a
ld b,kans
cp a

ret

hook_keyboard

.db $83

di
in a,($02)

rla
jr nc,hook_keyboard_max_speed

ld a,$01
out ($20),a

hook_keyboard_max_speed

ld de,flags+hookflags2
ld hl,appbackupscreen
ldi
ld bc,3
ld de,getkeyhookptr
ldir
ld a,kenter
cp a

ret
« Last Edit: January 14, 2021, 07:00:55 pm by the_mad_joob »

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 27
  • Rating: +0/-0
    • View Profile
Re: Caboose: Automatically Append "Ans" to Applicable Entries
« Reply #11 on: January 15, 2021, 12:17:00 am »
 O.O
Holy cow, that's awesome! That flag is perfect, and that temporary hook thing is crazy! That's definitely the best way to go. I'll for sure use that. I won't be able to use the flag on pre-MathPrint OSes/calculators, but those weren't ever an issue, so I'll just be able to fall back to the older checks. Once again, thanks so much for helping me along with the program! This is the first programming project that I've taken the time to fully work through and publish online, and it's so cool for me to experience the open-source ideology first-hand with you helping me out.

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 346
  • Rating: +47/-0
    • View Profile
Re: Caboose: Automatically Append "Ans" to Applicable Entries
« Reply #12 on: January 15, 2021, 03:40:46 am »
Glad i could be of help.
And about flag 3,(iy+$49), it's luckily retro-compatible, so the code works on older systems aswell =]
Except of course if some user code modifies it, but i highly doubt anybody ever takes the risk to use the system flags area for storage.

EDIT :

In case you need it for another project, there is also 4,(iy+$49), that tells what is highlighted (0=entry | 1=answer).
Of course, you have to check 3,(iy+$49) first to see if something is actually highlighted, cause its state seems unstable if that's not the case.
Bits 6 seems to have a function aswell, but i didn't manage to accurately discover which.
« Last Edit: January 15, 2021, 04:14:46 am by the_mad_joob »