Author Topic: I need help with program creating a program!!  (Read 3044 times)

0 Members and 1 Guest are viewing this topic.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
I need help with program creating a program!!
« on: August 10, 2012, 07:46:45 pm »
So i want to make a program that MAKES a program from the Basic string in str9.
Please Details! :D

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: I need help with program creating a program!!
« Reply #1 on: August 10, 2012, 08:56:18 pm »
I'm not sure how exactly you want your program to work, but I'll give you a few basic details that should provide most of what you need.

To get a pointer to an OS variable in RAM:
GetCalc("var_name")

To find the size of an OS equation, program, appvar, or string:
{pointer_to_var-2}?

To create an OS variable and get a pointer to it:
GetCalc("var_name",size)

To copy data from one memory location to another:
Copy(copy_from,copy_to,size)

Using these pieces of information, you should be able to create a simple Axe program that creates a program and copies the contents of Str9 into it. :)



If you'd like to see a simple Axe program to do this, I'll put two such Axe programs in spoilers. The first will be the normal version, which should be a bit simpler to understand, and the second will be the optimized version. But I feel confident that you won't need to peek to figure it out. :)

Spoiler For Normal Axe program:
.STR9PROG

.       This   v   is the Str9 token
!If GetCalc("Str9")?S
  .This   v   is Str9 spelled out
  Disp "Str9 was not found!"
  getKey?
  Return
End

{S-2}??Z
!If GetCalc("prgmTEMP",Z)?P
  Disp "Not enough RAM!"
  getKey?
  Return
End

Copy(S,P,Z)
Disp "Success!"
getKey?
Return

Spoiler For Optimized Axe program:
.STR9PROG

Copy(Find(),Make(),Z)
("Success!")

Lbl Out
Disp
getKey?
Return?

Lbl Find
.       This   v   is the Str9 token
ReturnIf GetCalc("Str9")?S
.   v   This is Str9 spelled out
("Str9 was not found!")
Goto Out

Lbl Make
ReturnIf GetCalc("prgmTEMP",{S-2}??Z)
("Not enough RAM!")
Goto Out




EDIT

So apparently I completely misunderstood the request. It was how to create a program whose name is in Str9, which makes a lot more sense. As an added detail, TiAddict added in IRC that he wanted the program to be created with a size specified by the OS variable L. Here's how I would do it. And don't worry about that hexadecimal number, that's just a free memory location that's well-sized for what we need and shouldn't be used by anything else, which I got from thepenguin77's excellent list.

.STR9PROG
?9D8A?°Name
'prgm'?Name
GetCalc("Str9")?S
Copy(S,°Name+1,{S+2}??Z)
 and 0?{Z+°Name+1}
GetCalc(°Name,float{GetCalc("varL")})
« Last Edit: August 11, 2012, 01:35:54 am by Runer112 »

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: I need help with program creating a program!!
« Reply #2 on: August 11, 2012, 09:52:07 am »
Already tried to do that, too, but always forgot that thing with the pointer! :P
*insert supercool signature*

Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: I need help with program creating a program!!
« Reply #3 on: August 11, 2012, 12:33:03 pm »
.STR9PROG
ᴇ9D8A→°Name
'prgm'→Name
GetCalc("Str9")→S
Copy(S,°Name+1,{S+2}ʳ→Z)
 and 0→{Z+°Name+1}
GetCalc(°Name,float{GetCalc("varL")})


Optimized :
.STR9PROG
ᴇ9D8A→°Name+1→°Name1
'prgm'→Name
GetCalc("Str9")→S
Copy(,°Name1,{S+2}ʳ→Z)
 and 0→{Z+°Name1}
GetCalc(°Name,float{GetCalc("varL")})


-5 bytes
 :w00t:
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 Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: I need help with program creating a program!!
« Reply #4 on: August 11, 2012, 05:31:47 pm »
.STR9PROG
ᴇ9D8A→°Name
'prgm'→Name
GetCalc("Str9")→S
Copy(S,°Name+1,{S+2}ʳ→Z)
 and 0→{Z+°Name+1}
GetCalc(°Name,float{GetCalc("varL")})


Optimized :
.STR9PROG
ᴇ9D8A→°Name+1→°Name1
'prgm'→NameGetCalc("Str9")→S
Copy(,°Name1,{S+2}ʳ→Z)
 and 0→{Z+°Name1}
GetCalc(°Name,float{GetCalc("varL")})


-5 bytes
 :w00t:

Actually they're the same size, and I'll tell you why. :P

It looks like you tried to save 2 bytes by making the °Name1 constant to get rid of the two +1's later in the code. But wherever a constant addition or subtraction immediately follows another constant, the operation is performed at compile time and the two constants are combined into one, so °Name+1 is treated just like a constant.

The final 3 bytes you tried to save by removing S as the first argument in the Copy() command, which is a perfectly valid optimization because the value of S was already in HL from the line before. However, this optimization is now performed automatically by the peephole optimizer, so I chose to let the peephole optimizer handle it in favor of slightly improved readability. :)
« Last Edit: August 11, 2012, 05:35:37 pm by Runer112 »

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: I need help with program creating a program!!
« Reply #5 on: August 11, 2012, 05:39:24 pm »
Thank you all for helping me with this, but whenever i run it, (im sure i typed it right, i checked 5 times now) it's not creating the program!!
maybe my calc is being stupid :P
« Last Edit: August 11, 2012, 05:41:16 pm by TiAddict »

Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: I need help with program creating a program!!
« Reply #6 on: August 11, 2012, 05:54:29 pm »
*kindermoumoute runs
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 Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: I need help with program creating a program!!
« Reply #7 on: August 11, 2012, 05:55:38 pm »
Hmm, it seemed to work in my tests. :-\ The only reasons I can think of why it wouldn't work are bad name input (Str9), size input too large (L), the code being copied incorrectly, or a bad/old version of Axe.

If you can post the source 8xp and tell me what version of Axe you're using, or if you can post the compiled 8xp, I should be able to tell you if the problem is either of the latter two possibilities. The former two possibilities you could check. Alternatively, if you're testing this on your calculator and can't easily transfer files to a computer, if you've made no changes to my code and could tell me the size of the compiled program STR9PRGM in the memory management menu and your version of Axe, I may be able to tell you if the problem is one of the latter two possibilities, although I couldn't pinpoint a copying error.
« Last Edit: August 11, 2012, 05:56:47 pm by Runer112 »