Author Topic: Library in an appvar?  (Read 12956 times)

0 Members and 1 Guest are viewing this topic.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Library in an appvar?
« Reply #15 on: October 08, 2012, 02:53:18 pm »
Mmh, it's a pretty interesting thing to try. I think that you can define and call jump tables like that :
Code: [Select]
.your jump table
.the main problem is to make PC $4000, but I'm not sure to understand how apps work
Goto Func1
Goto Func2

Lbl Func1
.code here
Lbl Func2
.same
.etc

.then call your routines
(E4080)(args)
You can still compile your Axe jump table into an app, but the real problem is how to access the resulting app and make the code work. Maybe an axiom using _FindApp (like I did for AxeSh where I use the Axe API using Axe and Axioms, search it in the z80 projects thread).
« Last Edit: October 08, 2012, 02:59:18 pm by Matrefeytontias »

Offline Ki1o

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 119
  • Rating: +5/-2
  • Doing my best...
    • View Profile
Re: Library in an appvar?
« Reply #16 on: October 08, 2012, 04:48:11 pm »
Thanks that idea is interesting. Two things though. 1. what do you mean by "PC $4000" and 2. What does E4080 mean?

Offline DrDnar

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 546
  • Rating: +97/-1
    • View Profile
Re: Library in an appvar?
« Reply #17 on: October 08, 2012, 11:43:59 pm »
That honestly stopped me from writing like 5 different examples he could use.
I was totally thinking of you when I wrote that.

But also myself to a degree. Because I later had the idea that you could use Run Programs to load a program into RAM from an app, and have the app and program exchange pointers to sharable data and code using tables in scrap RAM. Of course, you'd have to jump back into the app from the RAM program, instead of returning normally; and, you'd have to use a bit of assembly (five or so bytes) to keep track of the app page. That introduces some ugliness, either requiring you to keep careful track of the stack, and making instant quit impossible without leaking memory; or, requiring some assembly code to fix up the stack and delete the RAM used, so that instant quit works right. Personally, I think the latter is the better solution, since keeping track of the order to use the code isn't too hard, I think. Does anybody want such an Axiom?

You know, it's actually do-able. You could do it the reverse way, too, using an Axiom to search for the app, and jumping into it instead of calling it from the OS. Because, you know, otherwise there's ugliness arising from the context change and all. . . .


EDIT: Right, so, to answer partially the previous post's question, PC is how the CPU keeps track of where it is in a program. Basically, each part of an Axe program is assigned an address in memory, which is just a simple number. The CPU just keeps incrementing that address, so it executes instructions in order (unless you ask it not to with a loop, conditional, or transfer). Programs are loaded into RAM at the address $9D95, whereas apps are loaded into the pageable space at $4000.

Matrefeytontias's idea of making a jump table is probably sound, but I'm not clear on what he means about changing PC. Axe apps start with PC=$4080, because the first 128 bytes are the header.
« Last Edit: October 08, 2012, 11:54:29 pm by DrDnar »
"No tools will make a man a skilled workman, or master of defense, nor be of any use to him who has not learned how to handle them, and has never bestowed any attention upon them. . . . Yes, [] the tools which would teach men their own use would be beyond price."—Plato's The Republic, circa 380 BC

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Library in an appvar?
« Reply #18 on: October 09, 2012, 01:37:14 am »
Well, let's answer that : I've already done that. Right now, I have a Nostub Axe program using 4 functions I defined in an Axe App. And it works greatly :) I'll open a topic for that in a few minutes, just the time to make screenshots.

So, let's explain.

I have two source codes : one for the API and one for the program using it. With a rapid test (I displayed the value of a label I put as first line of the code of the API), I saw that the first instruction is at $408B.
Code: [Select]
:.AppTest
:.This is at $408B
:Goto Func1
:.This one at $408E
:Goto Func2
...

Now that I have my API, I made an Axiom on the fly including three commands :
  • getCurPage
  • setCurPage(
  • getAppPage(
I used them to access to my API using app pages.

So, now that you know all, I post my code.
Code: [Select]
:.APIUSER
:getCurPage->P
:
:setCurPage(getAppPage("AppTest"))
:
:(E4094)(0,16,[FF818181818181FF])
:(E4097)()
:(E408E)(42)
:(E4091)(0,8,"Over 9000!")
:setCurPage(P
:getKey^r

Code: [Select]
:.AppTest
:Goto Start
:Goto Func1
:Goto Func2
:Goto Func3
:Goto Func4
:
:Lbl Start
:ClrHome
:Text(0,,"This app is an Axe lib
:Text(0,8,"You don't have to launch it.
:Text(0,16,"Press any key to quit
:getKey^r
:Return
:
:Lbl Func1
:Disp >Dec
:Return
:
:Lbl Func2
:Text(r1,r2,r3
:Return
:
:Lbl Func3
:Pt-On(r1,r2,r3
:Return
:
:Lbl Func4
:DispGraph

Like you see, it's nothing complicated :)

I'll post screenies in a new topic, so wait a moment ;)

Offline DrDnar

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 546
  • Rating: +97/-1
    • View Profile
Re: Library in an appvar?
« Reply #19 on: October 09, 2012, 05:25:19 am »
Your way is definitely cleaner. I can imagine there being one reason for wanting to keep your extra code in a program---it lets users start the app, instead of the program. You're not far from writing a shell now.
"No tools will make a man a skilled workman, or master of defense, nor be of any use to him who has not learned how to handle them, and has never bestowed any attention upon them. . . . Yes, [] the tools which would teach men their own use would be beyond price."—Plato's The Republic, circa 380 BC