Programming - Optimizing programs or writing a bootloader in code.

MSD #09


                   Program optimization
               or write a bootloader in code.

MAX SNAKE / MSD


     Surely you have a favorite game, I have it too,
This is Sim City. When loading it frequently, I noticed
Please note that I have to wait a long time for it to finish
downloads. In the good old days it would never have occurred to me
see how many files this masterpiece consists of, but times
are changing. Now my soul will not rest until I
know that the program takes up minimal disk space.
     So I wanted to make a program that took less
disk space and preferably taking up the space of one
file in the directory. You can do all this, and in big ways.
You may not have the knowledge. For those who want to learn assembly language
This article will not be superfluous. The article is divided into steps for simplicity
understanding.


 Step 1, look at the directory, we see:


    File start length

   SIMCITY .B - - ┐
   SIMCITY1.C 28350 3825 ├ Total volume 108 sectors
   SIMCITY2.C 24500 19059 │
   SIMCITYЗ.С 16384 4128 ┘


Note: The file attributes may be different in your version,
The loader file "SIMCITY .B" occupies 1 sector.
Now you need to figure out the boot sequence
files, look at the bootloader. This can be done using
doctor built into Conver Commander v4.x. Or programs
Best View. We write down the main ones, i.e. important information for you.
 Setting screen attributes is also important, especially if they
different from black.


Step 2, look at the bootloader:


  CLEAR 24499 ; Setting the stack minus one
  LOAD "SIMCITY1" CODE 4E4 ; Uploading 1st file
  RANDOMIZE USR 4E4 ; Running the first file
  LOAD "SIMCITY2" CODE ; Uploading 2nd file
  INK 0 ; Black ink
  PAPER 0 ; Paper is the same
  CLS ; Clearing the screen with "blackness" because...
  LOAD "SIMCITYЗ" CODE ; loading 3rd file into screen
  RANDOMIZE USR 24500 ; Start unpacking the 2nd file
  RANDOMIZE USR 20480 ; Starting the game


Note: Don't think that this is a loader from a tape recorder,
It’s just that the sequence of operation of the bootloader itself is shown here.
For the same reason, line numbering is omitted.


      Now let's try to understand the basic concepts. Stack
goes down so as not to load a file on it when entering
in basic its value is 6SSxx, if I'm not mistaken. 1st file
is a packed splash image with a relocatable
start address (i.e.can work in any address). To
there was no visible “dirt” on the screen from the 3rd file, previously
The screen is cleaned with black ink and paper. penultimate
launch, this is most likely unpacking.
      All. Now we know all the addresses of the bootloader,
It's time to start packing the files. Also
this process can be called "compression", but do not confuse it with
"archiving" is a slightly different "compression".
      For this process you can use MS_PACK, but it is already inferior
by speed and compression results. It's better to take advantage
program "HRUMЗ.5i", correcting the depacker address to 23296 (!!!),
Also one of the best is HRUST v1.3 & v2.1.


Step 3, compress the files:


    Name Type Address setting Received Old
   autostart packer file length length

SIMCITY1.With MSP v1.7 - 3115 3825
SIMCITY2.C HRUM v3.5i 24500 14060 19059
SIMCITYZ.C HRUM v3.5i 20480 3227 4128


Note: We extracted the first image file and packaged it with special
al screen compressor "Maxsoft Screen Packer v1.7".
In the 3rd autostart is the start of the game. The length difference could be
and more, let me remind you, because we are compressing what is already compressed.


      Well, they packed all this stuff.Now based on
We will write everything recorded about the work of the original loader
bootloader in codes. You need to compose the files in that sequence -
the degree in which they are loaded, i.e. just as they stand.
The bootloader will occupy 1 sector (i.e. length up to 256 b.). B
BASIC bootloader we will insert the loading procedure in the codes.


Step 4, prepare the basic part of the bootloader:
We write in BASIC:


  10 REM ...................
............................
............................
........................!
  20 RANDOMIZE USR VAL "23874"

Exit to TR-DOS (RANDOMIZE USR 15616) and type:
SAVE "LOADER" LINE 0


Note: In the 10th line, in place of the dots, we will write the code
part of the bootloader, but for now we are writing there 80-odd something
signs. On line 20, the code loader launch address is
the address immediately following the operator "REM" + 2. When uploading a file
We’ll take an arbitrary name and then rename it. "LINE 0" - defines
autostart line of the BASIC loader. (“LINE 10” is the same).


      Here we wrote a basic bootloader. To write code
Let's take STSv 4.x or higher for the bootloader, lower is also possible. In STS
key "l" - LOAD, "s" - SAVE, to type something you need
stand in the desired column and press "ENTER". To convert to ten
Typical system press ss+3. Loaded, click
"l", type the name"LOADER B", press "ENTER" 2 times.
We successfully go to the address column and type “23874”.


Step 5, write the bootloader in code.


 We stand in the 3rd column and start typing from address 23874:

  XOR A ; ┐ Cleaning the curb
  OUT(254),A ; ┘
  LDHL,22528; ┐ Clear the screen with black.
  LD DE,22529 ; ├
  LD BC,767 ; │
  LD (HL),0 ; │
  LDIR; ┘

  LD SP,24499 ;     stack installation

  LDHL,32768; ┐ loading 1st file,
  LD B,13; ├ in "HL" - download address,
  CALL TR ; │ in "B" - length of the 1st file in sectors
  CALL 32768; ┘ and unpacking.

  LD HL,24500 ; ┐ loading the 2nd file,
  LD B,55; ├ in "HL" - download address,
  CALL TR ; │ in "B" - length of the 2nd file in sectors
  CALL 24500; ┘ and unpacking.

  XOR A ; ┐
  LDHL,22528; │ Clear the screen with black again.
  LD DE,22529 ; ├ because The 3rd file is loaded into the screen, and
  LD BC,767 ; │ we have a splash screen on our screen.
  LD (HL),0 ; │ Dirt through the attributes of the screensaver will
  LDIR; ┘ looks “not good”. But who cares!

  LD HL,24500 ; ┐ loading the 3rd file,
  LD B,13; ├ in "HL" - download address,
  CALL TR ; │ in "B" - length of the 3rd file in sectors
  CALL 16384; ┘ and unpacking and autostart at 20480

                ; JP 20480 Starting the game

TR LD DE,(#5CFЧ) ;  ┐ Subroutinecall 5th function
    LD C,5;  ├ TR-DOS, she needs:
    CALL #3D13 ;  │ HL - download address
    RET ;  ┘ DE - we take the track/sector from the variables
                  ;     nal TR-DOS, (current head value)
                  ;     B - number of sectors read in a row
                  ;     с - function number (5)



Note: instead of "TR" dial "0" and then when
If you know the value of "TR", substitute it instead of "0". In the 5th
functions in the "DE" register take the value from the variable
TR-DOS with address #5CFЧ, where the current coordinates are stored
drive heads. That is, three files will be read in a row,
it is enough to know only their length in sectors.


      Please check your writing carefully. If everything
ok, then you can save, key "S" - save. After
saving file loader will have the parameter start in the directory
equal to 23867. That is, STS saved it as a code file with
extension "B". Which of course needs to be fixed. Download
loader file with the "LOAD" command from TR-DOS, and right there, without leaving
in BASIC, save it with the command "SAVE" with "LINE 0". That's it, now
it will start. The last thing left.


Step 6, compose the files sequentially after downloading.


            Length in
  File sectors

SIM_CITY+.B 1 ┐
SIMCITY1.C 13│
SIMCITY2 .C 55 ├ Total 82 sectors versus 108.
SIMCITYЗ .С 13 ┘


Note: The bootloader file name is your modified
bootloader, here the name is chosen arbitrarily. For normal
run between files there should be no deleted files themselves
guess why.


      Let's try to launch it. If it doesn't work, check everything again.
It turned out great, now you can merge the files into one.
This can be done with the program "Conver Commander v4.x". Flag
files (4 pcs.) and select the "Merge files" function. In the end you
get a bootloader file 80 sectors long.
      That's it, the optimization is over. Here's how to do it:
so that the game saves to disk? Very interesting question
I'm not yet competent enough to teach others,
maybe later. . .



                                   MAX SNAKE / MSD / 12/1/1999



Share your thoughts about the article