Author Topic: [68k] Reducing size of main executable  (Read 4853 times)

0 Members and 1 Guest are viewing this topic.

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
[68k] Reducing size of main executable
« on: June 21, 2012, 11:08:13 am »
As you know, assembly programs on the 68k are limited to 24 KB for AMS 2.05 and up. I am programming a large game, and aside from storing maps and enemy data externally, I need a way to reduce the size of the main program. It's already about 5K right now, and without much in it. I considered putting certain functions in an external file, but I asked: 1. How would functions with arguments be called? and 2. How would I determine the offset for certain functions? I am also considering putting the main game content in chapters and in separate files, but I have no idea how to use global variables from the main program. Any ideas? Thanks in advance!
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの

Offline TravisE

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 182
  • Rating: +33/-0
    • View Profile
    • ticalc.org
Re: [68k] Reducing size of main executable
« Reply #1 on: June 21, 2012, 12:17:07 pm »
Someone will have to answer the other questions. But if you haven't already, you might also consider the optimization options available in TIGCC/GCC4TI, which may help with executable size. http://debrouxl.github.com/gcc4ti/httigcc.html#advanced  There are especially things like FLINE calls/jumps, which trade off speed for size. And, of course, there are the compressed programs (the ones that use Super Start/ttstart/their own launcher), but I haven't made one myself yet, so I don't know much about making those.
ticalc.org staff member—http://www.ticalc.org/

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
Re: [68k] Reducing size of main executable
« Reply #2 on: June 21, 2012, 12:30:26 pm »
Thanks! But since the original TI-Basic program spans about 82 KB in size, I'll need more than these.
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: [68k] Reducing size of main executable
« Reply #3 on: June 21, 2012, 01:03:43 pm »
The size limit for assembly programs is even 8 KB on the earliest AMS 2.xx versions; it was raised to 64 KB (i.e. made completely ineffective, but the code is not suppressed...) for the 89T.
But frankly, nobody bothers with the size limit until the program's size reaches 55-60 KB (at which point it's time for a round of optimization). The "ASAP or Exec string too long" and "Invalid Program Reference" artificial limitations are nullified by:
* PreOS and KerNO;
* by using a compressed program, as TravisE mentioned;
* by using tiosmod+amspatch'ed OS, but that's not very easy, for non-technical (read: legal) reasons.

About optimization: over the years, I've optimized dozens of third-party programs. I've summarized this experience in a tutorial about optimization of TI-68k programs, http://tict.ticalc.org/downloads/S1P9.zip :)

The documentation of GCC4TILIB's system for DLLs (dll.h) and the documentation of PreOS give a number of explanations about the concepts and implementation, and FAT Engine has its own DLL support. GCC4TILIB's sytem is very limited, in that it doesn't support more than one DLL at a time, which is a significant restriction for some use cases. So-called "kernels", namely PreOS, provide a much more powerful system.
I once spent a bit of time making a simple (probably simplistic), fairly rough proof of concept for multiple simultaneous DLLs. Needless to say, the program requires HW2/3Patch, because trying to execute multiple simultaneous DLLs without relying on the RAM execution protection being disabled is insanely complicated and slow. http://tict.ticalc.org/downloads/launchmultiple.tar.bz2 if you're interested in it.

Don't hesitate to ask more questions :)
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
Re: [68k] Reducing size of main executable
« Reply #4 on: June 21, 2012, 01:42:14 pm »
So... the 24K protection is not present on 3.xx?
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: [68k] Reducing size of main executable
« Reply #5 on: June 21, 2012, 01:50:35 pm »
Yup, at least on the 89T. I don't remember about the V200 offhand, and anyway, it doesn't matter: as I wrote, the 8K/24K limit has never been more than a minor annoyance. Don't worry about it ;)
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
Re: [68k] Reducing size of main executable
« Reply #6 on: June 21, 2012, 02:27:27 pm »
Can I at least put some of my code in another program?
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: [68k] Reducing size of main executable
« Reply #7 on: June 21, 2012, 02:45:35 pm »
Sure, that's precisely the purpose of GCC4TILIB's DLL support, and the purpose of the better PreOS DLL support ;)
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
Re: [68k] Reducing size of main executable
« Reply #8 on: June 22, 2012, 02:49:37 pm »
Hmm... It seems that the main program needs to be executed in the ghost space (which doesn't work on the Titanium) for GCC4TI's DLL support, and I don't want to force the user to install PreOS...
« Last Edit: June 22, 2012, 02:51:10 pm by blue_bear_94 »
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: [68k] Reducing size of main executable
« Reply #9 on: June 22, 2012, 04:13:01 pm »
On the 89T, users will have to install HW3Patch (easiest solution), or install PreOS (which disables the RAM execution protection), or use tiosmod+amspatch'ed OS (but nobody does that, because it's not very convenient - for legal reasons, users have to either compile and use the patcher by themselves, or use the provided binary diffs).
If you don't want to rely on PreOS's features, but nevertheless want to use more than one DLL at a time, then you'll have to embed your own custom support into the program...

BTW: splitting the program into pieces has a size cost (and an associated speed cost, though it's very low, unless you're jumping back and forth and the functions' bodies contain very few instructions).
Until you have done more of your program (say, you're reaching ~50 KB), don't bother splitting your program into pieces, but start a bit of optimization on it (e.g. reading and writing files through native, non-standard vat.h functions, rather than standard, non-built-in stdio.h functions, or worse, the pitiful semi-standard, built-in functions from files.h). Around the 50 KB mark, we can optimize the program further; when you're really going to hit the limit fairly soon, then we can start focusing on splitting the program.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.