Author Topic: Calling one axe program from another  (Read 17087 times)

0 Members and 1 Guest are viewing this topic.

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Calling one axe program from another
« on: February 17, 2012, 04:47:13 pm »
Bet you didn't think you'd see a topic from me.

In any case, we just discussed it on IRC, and there's a pretty simple way to call one axe program from another.

Code: [Select]
Copy("prgmNAME",33912,9
asm(EF7C4E)

This will work as long as prgmNAME is in ram, so if it's not, you'll have to unarchive it first. Hopefully someone has fun with this.

Edit:
   And here's how you do Basic programs.
« Last Edit: February 17, 2012, 04:52:13 pm by thepenguin77 »
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Calling one axe program from another
« Reply #1 on: February 17, 2012, 09:14:00 pm »
Woah, that's pretty nice. I knew that you could do it from an app, but I didn't imagine that it could work from program-to-program.

Incidentally, where is 33912?  Does it corrupt any other data? And would using Return in the called program return to the homescreen or return to the parent program?

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Calling one axe program from another
« Reply #2 on: February 17, 2012, 09:14:58 pm »
Nice, I totally forgot about the BASIC one until it was linked to on IRC earlier. Glad to see an Axe one. Can conflict happen between programs?

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
Re: Calling one axe program from another
« Reply #3 on: February 17, 2012, 09:58:13 pm »
Woah, that's pretty nice. I knew that you could do it from an app, but I didn't imagine that it could work from program-to-program.

Incidentally, where is 33912?  Does it corrupt any other data? And would using Return in the called program return to the homescreen or return to the parent program?

According to thepenguin77, 33912 is the location of OP1

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Calling one axe program from another
« Reply #4 on: February 18, 2012, 12:23:04 pm »
can you call the program within the program that is being called?
Sig wipe!

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Calling one axe program from another
« Reply #5 on: February 20, 2012, 04:02:26 pm »
can you call the program within the program that is being called?

I assume you are asking if a program can call itself? The answer is yes, but only if the program was not run with a shell. If it was run with a shell, you are going to run into problems.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline thydowulays

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 184
  • Rating: +12/-1
  • Don't gimme dat lip
    • View Profile
    • Thy Gaming Forum
Re: Calling one axe program from another
« Reply #6 on: February 20, 2012, 06:40:54 pm »
Does this work with any ASM program or just ones compiled with Axe?
Current Projects:
-Sparta GUI Library: 25% - Alpha Stage
-Grapher - 75% - Beta Stage *on hiatus




Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Calling one axe program from another
« Reply #7 on: February 20, 2012, 06:53:38 pm »
It should work with all Asm programs :) (but you might need to wait for confirmation)

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Calling one axe program from another
« Reply #8 on: February 20, 2012, 07:04:39 pm »
If you want a program to call itself, just put a label at the beginning of the program and call it using a normal subroutine, I'd say.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: Calling one axe program from another
« Reply #9 on: February 24, 2012, 11:44:56 am »
It doesn't work... it always crash.
« Last Edit: February 24, 2012, 11:45:14 am by kindermoumoute »
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
Re: Calling one axe program from another
« Reply #10 on: February 24, 2012, 04:19:17 pm »
It doesn't work... it always crash.
Make sure the Asm program is compiled for No Shell, or else it will crash

Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: Calling one axe program from another
« Reply #11 on: February 24, 2012, 05:18:29 pm »
I'm sure, have you tested it ? Please show me a screen if you think it work, but I tested twice : on my real 83+ and on wabbitemu (84+SE). :/
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%

Offline DrDnar

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 546
  • Rating: +97/-1
    • View Profile
Re: Calling one axe program from another
« Reply #12 on: February 24, 2012, 05:32:48 pm »
Yes, it's OP1. Yes, control is returned the caller. This code just calls the OS routine that runs assembly programs. You can even run unsquished programs this way. (Ignore the last statement if you don't know what a squished program is.)

However, keep in mind a few things:
  • Just like running programs with the Asm( token from the homescreen, you need a quantity of free RAM equal to the size of the program being run.
  • Because the OS has to shuffle RAM around for this to work, it takes a split second for the new program to start. So if you do this a lot, it'll be really slow.
  • If you call yourself like this, the OS will make yet another copy of yourself. Duh.
  • Instant quit will return control to the calling program, not the homescreen or the shell. This is because the error handlers get nested. (The good news is that if the calling program throws an OS error, control is returned to the calling program, but I don't believe any Axe programs use error handlers.)
  • By extension, do not call a shell's instant quit routine, or the memory used by caller won't get freed.
  • Assuming Axe just makes a stub ISR that jumps to the real ISR, you're going to get a crash if you have an interrupt running and you try this, because your ISR just got moved.
  • L1 through L6 will not be modified by the OS, neither during calling nor returning. The OP registers, however, will be corrupted.
« Last Edit: February 24, 2012, 05:40:28 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 kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: Calling one axe program from another
« Reply #13 on: February 24, 2012, 05:54:08 pm »
Have you tested it ? Does it work with your calc ? O_o

Damn, where is the problem on my code ?
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%

Offline DrDnar

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 546
  • Rating: +97/-1
    • View Profile
Re: Calling one axe program from another
« Reply #14 on: February 24, 2012, 06:22:44 pm »
Huh. . . . it looks like you're doing nothing wrong. I wrote a test program myself and found a problem in the disassembly:

prgmA
Code: [Select]
.AAA
Disp "ONE...",i
Copy("prgmAAAA",33912,9
Asm(EF7C4E
Disp "...ONE.",i
Pause 2000

prgmAA
Code: [Select]
.AAAA
Disp "TWO",i

Disassembly:
prgmAAA
Code: [Select]
9D95: ld hl, 9DC3 ; Disp "ONE...",i
bcall(_450A)
bcall(_452E)
ld hl, 9DCAh ; Copy("prgmAAAA",33912,9
push hl ; Load arguments in a complicated fashion
ld hl, 8478h
ld bc, 0009
ex de, hl
pop hl
ldir ; Copy the data
ldir ; Clobber all of RAM
ld c, (hl) ; ???
ld hl, 9DD0h ; Disp "...ONE.",i
bcall(_450A)
bcall(_452E)
ld hl, 07D0h ; Pause 2000
9DBB: djnz 9DBB
dec hl
ld a, l
or h
jr nz, 9DBB
ret ; End of program code
9DC3: .db "ONE...", 0
9DCB: .db ProgObj, "AAAA", 0
9DD0: .db "...ONE.", 0

prgmAAAA
Code: [Select]
9D95: ld hl, 9D9F ; Disp "TWO",i
bcall(_450A)
bcall(_452E)
ret ; End of program code
9D9F: .db "TWO", 0

For some reason, Axe 1.1.2 is inserting the ldir twice, clobbering all of RAM. NOPing one of the ldirs out fixes it.


EDIT: Runer112 has a workaround for you:
Quote
(6:43:18 PM) DrDnar: Runer112: I found an Axe bug, see http://ourl.ca/15239/286978
(6:43:32 PM) Runer112: I saw
(6:43:39 PM) DrDnar: k
(6:43:53 PM) Runer112: I can tell you it's a peephole optimizer problem
(6:44:00 PM) Runer112: so you can fix it by compiling without peephole opts [Use ZOOM---DrDnar]
(6:44:08 PM) Runer112: but I can't tell you why it's happening
(6:44:48 PM) Runer112: I'm sure Quigibo will know it's a peephole optimizer problem too
(6:44:51 PM) Runer112: it's pretty clear
« Last Edit: February 24, 2012, 06:47:51 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