Author Topic: Questions about programs and appvars  (Read 5836 times)

0 Members and 1 Guest are viewing this topic.

souvik1997

  • Guest
Questions about programs and appvars
« on: October 22, 2010, 09:45:26 am »

I have 2 questions:


How would I copy an arbitrary number of programs to one giant program?
How would I read from a BASIC string variable?

Thanks in advance

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Questions about programs and appvars
« Reply #1 on: October 22, 2010, 11:55:42 am »

I have 2 questions:


How would I copy an arbitrary number of programs to one giant program?
How would I read from a BASIC string variable?

Thanks in advance

Regarding your first question: are these compiled assembly programs? And would all the names already be listed somewhere in memory, or would program names be called one by one? Also, would all these programs be in RAM, or might some/all be archived?

As for BASIC strings, reading from them is much like reading from strings inside of Axe, except that Axe strings are strings of ASCII characters and BASIC string variables are strings of tokens. To find the pointer to a string variable, you would do something like the following:
Code: [Select]
GetCalc("Str1")→PAnd then you can just treat P like you would a pointer to a normal string in Axe, although taking note of the fact that it's a string of tokens and not ASCII characters.
« Last Edit: October 22, 2010, 12:03:11 pm by Runer112 »

souvik1997

  • Guest
Re: Questions about programs and appvars
« Reply #2 on: October 22, 2010, 07:31:59 pm »
All the programs will be in RAM, and the BASIC string will define which programs to copy.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Questions about programs and appvars
« Reply #3 on: October 22, 2010, 07:54:29 pm »
Since all program names are in uppercase, you won't have to worry about all that token-to-char mess.

Let's say you have a BASIC string that looks like "ABC     PROGRAM TESTPROGMARIO   WHATISIT?" that contains all the program names, padded to eight chars each and ending with a "?" character. In the Axe program, you first find the string with
Code: (Axe) [Select]
:GetCalc("Str1")→P
The pointer to the start of the string would be at P.

Then you would copy the chars in the string individually to someplace (so that you can get rid of the spaces):
Code: (Axe) [Select]
:[]→GDB0
:.Name of program
:"prgm"
:[]→GDB1
:.Start of characters in name of program
:det(9)
:0→N
:.N is the Nth program name in the string, starting with 0
:0→C
:Repeat {N*8+P+C}-175
:.175 is the token code for "?"
:If {N*8+P+C}-20
:.20 is the token code for " "
:{N*8+P+C}→{GDB1+C}
:End
:C+1→C
:End
:0→{GDB1+C}

Then you find the actual program with

Code: (Axe) [Select]
:GetCalc(GDB0)→Q

And now you can play with the data at Q (the program that the string points to) all you want. This is only for the first program in the list, though. To access the others, just change N.

I haven't actually tried it, and there are definitely a lot of optimizations you could do, but see if you can understand how it works.
« Last Edit: October 22, 2010, 07:55:34 pm by Deep Thought »




Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Questions about programs and appvars
« Reply #4 on: October 24, 2010, 06:54:54 am »
Enjoy. :) All the information should be in the source file. I slaved over this for many an hour. ;)

Tell me if it works fine for you. I tested it and it seems to work. If you need the input style changed I can change it for you.


Code: [Select]
..AXE LIBRARY: MERGE

.<DESCRIPTION>
.This routine will merge multiple BASIC programs listed in an OS string into one program
.Author: Runer112
.Date: 10/24/10
.Insert style: Inline
.Parser version designed for: 0.4.5
.Size as of version 0.4.5: 342 bytes

.<INPUTS>
.Str0M1: Name of OS string containing program names
  .Example format of data in OS string: "prgmPRGMNAMEprgmAprgmTEST"
.Str0M2: Output program name

.<OUTPUTS>
.Returns: 0 if failed, non-0 otherwise
.A program, the name of which is determined by Str0M2

.<DESTROYS>
.Last 24 bytes of saveSScreen (last 24 bytes of L₁ as of 10/24/10)

.<ROUTINE>
.Temporary program name storage (last 10 bytes of saveSScreen)
ᴇ05→{ᴇ89EC-10}r
Fill(ᴇ89EC-9,8)
.{ᴇ89EC-12}r = merge loop iteration/pointer to merged program, {ᴇ89EC-14}r = total length of merged program in first iteration, current position in merged program in second iteration
0→{ᴇ89EC-12}r→{ᴇ89EC-14}r

.Merge loop
Lbl 0ML
.Check that OS string exists, {ᴇ89EC-16}r = pointer to string, {ᴇ89EC-18}r = current position in string
If GetCalc(Str0M1)→{ᴇ89EC-16}r→{ᴇ89EC-18}r
  .Repeat while position is not outside of string
  While sub(0MC)
    .{ᴇ89EC-20}r = current offset in temporary program name
    0→{ᴇ89EC-20}r
    .Repeat until current token = prgm (0x5F)
    While {{{ᴇ89EC-18}r+1→{ᴇ89EC-18}r}→{{ᴇ89EC-20}r+1→{ᴇ89EC-20}r+ᴇ89EC-10}}-ᴇ5F
      .If position is outside of string
      !If sub(0MC)
        .Break
        Goto 0MD
      End
    End
    .Done copying name
    Lbl 0MD
    .Replace last byte with 0
    0→{{ᴇ89EC-20}r+ᴇ89EC-10}r
    .Check that program to copy exists, {ᴇ89EC-20}r = pointer to program, {ᴇ89EC-22}r = length of program
    If {GetCalc(ᴇ89EC-10)→{ᴇ89EC-20}r-2}r→{ᴇ89EC-22}r
      .If second iteration
      If {ᴇ89EC-12}r
        .Copy program to merged program
        conj({ᴇ89EC-20}r,{ᴇ89EC-14}r,{ᴇ89EC-22}r)
        .If not last program to copy, {ᴇ89EC-24}r = backup of length of merged program
        If {ᴇ89EC-12}r+{ᴇ89EC-24}r-sub(0MM)
          .Append new line token
          ᴇ3F→{sub(0MM)-1}
        End
      End
      .Add length of current program (plus 1 for a new line token) to length of merged program
      sub(0MM)→{ᴇ89EC-14}r
    End
  End
  .If first iteration
  !If {ᴇ89EC-12}r
    .Attempt to create merged program and increase iteration count
    !If GetCalc(Str0M2,{ᴇ89EC-14}r→{ᴇ89EC-24}r-1)→{ᴇ89EC-12}r→{ᴇ89EC-14}r→{ᴇ89EC-12}r
      .Program creation failed, go to end
      Goto 0ME
    End
    Goto 0ML
  End
End
.Go to end
Goto 0ME

.Merge position check
Lbl 0MC
  {{ᴇ89EC-16}r-2}r+{ᴇ89EC-16}r-{ᴇ89EC-18}r
Return

.Merge math
Lbl 0MM
  {ᴇ89EC-14}r+{ᴇ89EC-22}r+1
Return

.Merge end
Lbl 0ME
« Last Edit: October 24, 2010, 07:00:38 am by Runer112 »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Questions about programs and appvars
« Reply #5 on: October 24, 2010, 08:32:21 pm »
Mhmm nice routine, I assume the code of the 2nd program just appear below the 1st and just the end of the first program and the header of the 2nd program are removed to make it one, right?

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Questions about programs and appvars
« Reply #6 on: October 24, 2010, 10:04:37 pm »
This is designed to combine multiple non-assembly programs into one. The reason I say non-assembly is because it should work for any programs that can be edited in the program editor, such as BASIC programs or Axe source code. It copies all the lines in the specified programs into one large program, adding new lines between the end and start of programs as necessary.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Questions about programs and appvars
« Reply #7 on: October 24, 2010, 10:55:10 pm »
Ah ok :D

For asm I guess it migth be a bit hard since the data has to be at the bottom and the rest at the top, right?

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Questions about programs and appvars
« Reply #8 on: October 25, 2010, 07:25:20 pm »
And addresses would be all messed up. So no Axe executables, either :P




souvik1997

  • Guest
Re: Questions about programs and appvars
« Reply #9 on: October 29, 2010, 10:29:21 pm »
Thanks Runer, that is exactly what I needed. :)