Author Topic: Program Combination  (Read 10799 times)

0 Members and 1 Guest are viewing this topic.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Program Combination
« on: November 17, 2010, 05:37:59 pm »
This is something i just created like 5 min ago after a brainwave over the problem i have been having with Portal.  A long time ago i envisioned Portal as a large program that copied data around so that it never exceeded the code limit, but this was impossible because of absolute jumps and calls, and because the code was so changing that counting the bytes was impossible. 

But what if the program was page based, and i don't mean like RAM pages, but virtual pages.  Each page would be a separate program, compiled separately so that each one of them was compiled to be executed at $9D95.  Each program page would be the same length as all of the others, and so swapping them would be easy.  The only thing needed is a way for the swap to happen without messing with the current execution.  For this i have created a custom header for every program to be included, as a common space where the swapping happens.  There is also a program that takes multiple programs as input and outputs a program that contains all of the programs compiled into 1.

Any program can switch to any of the other programs at any time.  Simply by following the following syntax. #Goto SWP, where # is the program page they want to jump to.  SWP is a label that is inside of the included header, that performs the swap and execution handling, which is actually quite simple. After the swap happens, execution resumes as normal from the beginning of that page and program.  Return still brings you back to the homescreen, and all OS calls behave the same.  You can have as many pages as can fit in RAM, and they can be any size, as long as each page themselves don't exceed the code limit.

I will release the code in a sec after i create a user friendly generator to combine programs, because as of right now it only works with 2 programs named P1 and P2.

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: Program Combination
« Reply #1 on: November 17, 2010, 06:50:38 pm »
This sounds like a great idea! Especially for programs that can't be under the limit, no matter what. How big would the "pages" be?




Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Program Combination
« Reply #2 on: November 17, 2010, 06:55:07 pm »
They can be whatever size you want, although the max is around 8800 because of the code limit. 

Offline FinaleTI

  • Believe in the pony that believes in you!
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1830
  • Rating: +121/-2
  • Believe in the pony that believes in you!
    • View Profile
    • dmuckerman.tumblr.com
Re: Program Combination
« Reply #3 on: November 17, 2010, 07:04:26 pm »
Sounds pretty cool. I'd certainly like to play around with it.


Spoiler For Projects:

My projects haven't been worked on in a while, so they're all on hiatus for the time being. I do hope to eventually return to them in some form or another...

Spoiler For Pokemon TI:
Axe port of Pokemon Red/Blue to the 83+/84+ family. On hold.

Spoiler For Nostalgia:
My big personal project, an original RPG about dimensional travel and a few heroes tasked with saving the world.
Coding-wise, on hold, but I am re-working the story.

Spoiler For Finale's Super Insane Tunnel Pack of Doom:
I will be combining Blur and Collision Course into a single gamepack. On hold.

Spoiler For Nostalgia Origins: Sky's Story:
Prequel to Nostalgia. On hold, especially while the story is re-worked.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Program Combination
« Reply #4 on: November 17, 2010, 07:16:23 pm »
Alright, so i have created the combining program.  It takes arguments from Ans, Str1, and Str2:

Ans: The size of the pages
Str2: The name of the program to combine into.
Str1: List of all the programs to be combined, in the order to be combined.  Must be padded with spaces up to 8 characters.  Eg: "I_______LOST____THE_____GAME____" If any of the programs have a file size larger than the page size, it will throw an error.  If any of the programs are archived or nonexistant, it will throw an error.  If the String is not a length divisible by 8 it will throw an error.  If neither of the strings exist, it will throw an error.

All the programs being combined must be compiled Axe programs with the included program INC as the first line on the program.  If it is not the first program, it will throw a HEADER error.  To Jump to a page, use #Goto SWP.  Which will swap page # with the current page.  Note that execution always stays on page 0, but by swapping to page 1, page 1 becomes page 0 and page 0 becomes page 1.  To swap *back* to the original page, you would swap with page 1 again.

Included Programs:
ThetaCombine: The assembly combiner program
ZCOmbine: A basic program that sets up and runs the combiner program
P1: A sample Axe code using page swapping
P2: Another Axe source meant to be used with P1
Axe1: Compiled of P1
Axe2: Compiled of P2
Inc: The include program
A: The source to ThetaCombine

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Program Combination
« Reply #5 on: November 17, 2010, 07:20:05 pm »
So, this is to overcome the 8800 byte limit for asm? cool! Axe can still only do single pages, if I remember correctly (or can it do 2 now?) so this would help a lot.

So, do all the pages always have to be in RAM, or can they be archived/unarchived by the current program when not being used?

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Program Combination
« Reply #6 on: November 17, 2010, 07:22:41 pm »
They cannot be archived unfortunately, as they are only virtual pages and actually all part of the same program.  Note that i encountered an error in Wabbit regarding getting header errors but its not happening on my calc.... hmmm

EDIT: Well i can't seem to find the issue, so its probably not working for now, i have to go but i will check back later.

EDIT2: I fixed everything hopefully ^^ Everything works as planned :) But now if you don't put a header you will clear ram ;) You can also put things in front of the header now, just note that when you page swap, you will swap to directly after the header (the INC file)

« Last Edit: November 17, 2010, 08:02:53 pm by Builderboy »

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Program Combination
« Reply #7 on: November 17, 2010, 08:07:35 pm »
The only problem I see with this is that the user would need to have a copy all essential code, data, and subroutines in each program. I know that you came up with this idea for Portal X, which must have a huge engine. You would need to have the engine exist in every program, which would cause a large amount of data redundancy/waste. And I'm sure anyone else pushing the size limit would also have a large amount of essential code, data, and subroutines, that would need to exist in every program.

Also, I'm still a little unclear as to how this works... what's the purpose of creating two separate programs and then combining them into one program (prgmTEST)? Doesn't that defeat the purpose of this?
« Last Edit: November 17, 2010, 08:12:19 pm by Runer112 »

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Program Combination
« Reply #8 on: November 17, 2010, 08:13:54 pm »
Well here is how i am going to use this for PortalX, there will be several pages with several purposes

Page1: Main Menu code, special code for special rooms
Page2: Level Data, Level Loading, Transition Animations
Page3: Engine

It would start on page 1, then jump to page to to load the level, then quickly swap to page 3 while ingame.  If you quit, swap back to page 1 for menu.  If you advance to the next room, swap to page 2 for transition and loading the next level.  You wouldn't need a copy of each piece of code for each page because you can swap to the essential piece of code whenever you need to run it.  

EDIT: And the purpose is because of Absolute jumps.  When you compile a program, it is meant to run at a certain address.  If you try to move it, it will crash rather spectacularly.  Well moving the programs is exactly what this does, so the programs need to be compiled to run at the start address (which is where they are being copied) and the only way to do this is compile them separately.  Does that answer your question?
« Last Edit: November 17, 2010, 08:17:08 pm by Builderboy »

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Program Combination
« Reply #9 on: November 17, 2010, 08:21:04 pm »
My point is, even for special rooms, I would think they would at least need a sizable chunk of the normal game engine.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Program Combination
« Reply #10 on: November 17, 2010, 08:23:22 pm »
EDIT: And the purpose is because of Absolute jumps.  When you compile a program, it is meant to run at a certain address.  If you try to move it, it will crash rather spectacularly.  Well moving the programs is exactly what this does, so the programs need to be compiled to run at the start address (which is where they are being copied) and the only way to do this is compile them separately.  Does that answer your question?
Axe could use a "ReOrg" command. ;D

This looks like a nice alternative Builderboy.  Nice job. :)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Program Combination
« Reply #11 on: November 17, 2010, 08:24:30 pm »
Well for the special rooms, it would set up any variables or intro cutscenes needed and then run the engine code, which doesn't need to change

EDIT: Lol ReOrg would remove the need for recompilation, but you still need to make sure all your pages are the same size ;) or at least you know where they are and how big they are

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Program Combination
« Reply #12 on: November 17, 2010, 08:29:30 pm »
I guess I could see how cutscenes might work, although all the sprites and graphics used in the actual game that are also used in the cutscene would need to be copied into the main page as well. And say you wanted the last level to be like the GLaDOS battle. You're still playing Portal during the battle, so you would need the main engine. But GLaDOS then needs to be able to do it's own thing while you're playing the normal game.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Program Combination
« Reply #13 on: November 17, 2010, 08:32:33 pm »
True it does have its limitations, although you could copy sprite data to a safe RAM area if you needed to, or put all your data on a page that never moves.  I guess its just a tradeoff between a bit of functionality and more execution memory, whichever the programer needs more for their game

Offline FinaleTI

  • Believe in the pony that believes in you!
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1830
  • Rating: +121/-2
  • Believe in the pony that believes in you!
    • View Profile
    • dmuckerman.tumblr.com
Re: Program Combination
« Reply #14 on: November 17, 2010, 09:02:44 pm »
Since you posted this, I've been thinking about it over and over, and with a few routines I'll ask for elsewhere, I could quite possibly use this to rewrite Nostalgia.

The way it's currently set up, I'd need quite a lot of optimization to get it to fit in an app. However, with this, I could theoretically have several archived appvars holding the code for each multi-paged program. Then, I could copy that data to a program and execute it from the app. When I needed something that didn't exist in the pages of the current program, I would jump back to the app and switch the program by copying the code from another appvar.  All my data could remain in appvars like it is now, and I would definitely fit within the executable code limit in the app.

Of course, this is all 100% theoretical, and I haven't tested the idea at all yet, but if I can get a routine to execute a nostub program from an app, I'm gonna test it.


Spoiler For Projects:

My projects haven't been worked on in a while, so they're all on hiatus for the time being. I do hope to eventually return to them in some form or another...

Spoiler For Pokemon TI:
Axe port of Pokemon Red/Blue to the 83+/84+ family. On hold.

Spoiler For Nostalgia:
My big personal project, an original RPG about dimensional travel and a few heroes tasked with saving the world.
Coding-wise, on hold, but I am re-working the story.

Spoiler For Finale's Super Insane Tunnel Pack of Doom:
I will be combining Blur and Collision Course into a single gamepack. On hold.

Spoiler For Nostalgia Origins: Sky's Story:
Prequel to Nostalgia. On hold, especially while the story is re-worked.