Inferno #07
31 мая 2005

For Coderz - How a large Flexible Program.

<b>For Coderz</b> - How a large Flexible Program.
         Transferability of programs



   Since large programs are not kept
on some JR, yes and, moreover, have re
variables, then tell you how to make a big
relocatable program. For example, it is at
changes to program the cache: one
the same fragment works in one case
in Cache, and in another - in the ordinary RAM.

1. With the creation of tables in the semi-manual mode


   Applies, for example, in Pro Tracker'e
when compiling the music player. PT storage
nit player, originally otassemblirovanny
at # c000. To make it work
tal to the right address, the contents of some
its cells (which refer to the address
procedures and variables) pereschityvayutsya.Ad
rez themselves are calculated cells are stored
in a special table. More precisely, instead of Adre
owls kept there distance from the previous
ing cells are calculated to the next
(So ​​decided to save the first author of Pro
Tracker'a, because the table is constantly
lies in the memory).



        LD A, (SNGST +1); A = high byte,

                ; Address to which we

                      ; Compile player

        LD IX, TRELOC; address table

                   ; Displacement (relocation)

         LD HL, plaer; where the player is

        LD D, # C0; byte address to

                   , Which last time

                      ; Compiled Player

         LD ($ -1), A

         LD E, A

        LD B, L
 REL0 LD C, (IX)

         LD A, C

         AND A

        RET Z; code 0 - end of the table

         INC IX

         ADD HL, BC

        INC A

        JR Z, REL0; code 255

         LD A, (HL)

         SUB D

         ADD A, E

         LD (HL), A

        JR REL0

Code 255, as we see, particularly - he misses
255 bytes, if the cell to the next higher
255 bytes (not exactly 255 bytes).

   Relocation table compiled by
comparison of two player options: one
compiled under # c000, and the other - under the
# C100. Here sravnivalka:



        ORG # A000
 P1 INCBIN "PLYC0"; player,

              , Compiled by # C000
 E1

        ORG # C100
 P2 INCLUDE "playFAST", # C4; same

                             ; Player, will be

                 ; Compiled under # C100
 module; module address = address end player.

      , Then the module address in this instance

        ; Player will be moved to # 100 bytes

        , Compared with an instance of "PLYC0"

         ORG # 6000

         LD IX, TAB

         LD HL, P1

         LD DE, P2

        LD C, 0
 CP0 LD A, (DE)

         SUB (HL)

         JR Z, CPOK; bytes differ?

         DEC A; bytes differ by 1?

        JR NZ, ERR; NO ???-> out by mistake

         LD (IX), C

         INC IX

        LD C, 0
 CPOK INC HL

         INC DE

         INC C

         JR NZ, CPNOFF

         LD (IX), 255

         INC IX

        LD C, 1
 CPNOFF LD A, L

         CP E1

         JR NZ, CP0

         LD A, H

         CP 'E1

         JR NZ, CP0

         LD (IX), 0

         INC IX

        RET
; Out by mistake: we slipped significantly
; Different files players
 ERR LD HL, 0

         LD DE, # 5800

         LD BC, 768

         LDIR

        RET
TAB = # 7000

The procedure should be run from the STS. Address
end of the table will see the register IX.


   2. With the creation of tables automatically


   In PT Util for compiling the table when
changes more convenient method, in which
assemble necessary not 2-3, but only
1. Here's how.

   Player for PT Util sits in a separate
source code, which when it INCLUDE'inge
main program is assembled as Oba
esidual player. But if his attempt Otas
semblirovat as an independent program
 Therefore, we:

  1. Avtoopredelyaetsya: address compilation pa
Veins # 8000, therefore, need to make
compilation to create peremeschalnoy Table
 Litsa.

   2. Player is assembled as a macro

                 MACRO pp
(All completely driven into the macro), PA
mashing is not placed. (The same occurs
 leads and referred INCLUDE'inge.)

  3. Macro player assembled on-us
toyaschemu with local labels, under the address
# 8000. (But this is not at INCLUDE'inge
 occurs.)

  4. Macro player assembled on-us
toyaschemu again, not with the local label
mi, under the address # C000. (And if INCLUDE'inge -
under an address that was current at the time
 Team INCLUDE.)

  5. Sravnivalka assembled. Address for
start-up programs - go to sravnivalku.
Ie: run on RUN - compiled
table. You can save it manually. Later
I learned protsedurku SAVEOBJ, it is the month
then apply here - then on the RUN table
not only the composition but also to continue. AND
if all - the table is already possible to use
in the main program by INCBIN. In about
cedure SAVEOBJ piece of initialization
program (more precisely, of implied
as such - for example, from our sravnivalki)
You can go through JP nenado. I mean
my version SAVEOBJ, rather than the one distributed Capry.


         3. Through macros j, c, l


   In ZXRar I realized even more convenient
way: the table movement is based directly
at the stage of assembling the main program
We, ourselves alasmom. However, no INCBIN
do not need.

   For such a method is required to determine
following macros:



       MACRO rg
 CurCa = $

         ORG RelCa

        DW CurCa +

 RelCa = $

         ORG CurCa

       ENDM



        MACRO j

         2 rg

        IFN? J1-2, there is the 2 nd option

                                  ; Macro?

         JP
, 1, if there is, such a JP

         ELSE

         JP

      And if not, then edakii

         ENDIF

       ENDM



        MACRO c

         2 rg

         IFN? J1-2

         CALL
1

         ELSE

         CALL


         ENDIF

       ENDM



        MACRO l

         LD
1

         rg 0-1; just -1 in the old alasmah

               And it was impossible, since in a macro

                ; Rg would be obtained CurCa + -1.

                      ; In the new can.

       ENDM

And they are used in movable fragments
those commands instead of JP [cc,] nn, CALL [cc,] nn,
LD (...), rp, LD rp ,(...).

   But you first need to specify the starting address,
from which to build the table:

RelCa = # C000


   As we see here each relotsiruemy
address has 2 bytes in the table (and not
1, as was the Pro Tracker'e). Here savings
memory to anything - because you need a table
lko at the launch stage ZXRar'a.

   Here's the place the initialization procedure in
ZXRar, which is responsible for throwing
moved fragment ZXRar in the cache (before
preliminarily find out whether the computer
 cache):

         DI

         IN A, (# FB)

         LD H, 0

         LD A, (HL)

         INC (HL)

         CP (HL)

         JR Z, ncach

         LD HL, End; here lies the table.

                                ; Relocation.

                   ; Why here - see below!

         LD B, RelSz; length of the table. relocation.

              ; How it feels - see below
 Rel0 LD E, (HL)

         INC HL

         LD D, (HL)

         INC HL

         LD A, (DE)

         SUB 'cachecode

         LD (DE), A

         DJNZ Rel0

         LD HL, cachecode

         LD D, B, E, L; low byte address

              , Not me, but the senior will be 0

         LD B, 'cachelen +1; instead

                          ; LD BC, cachelen

                          ; (Win = 1 byte)

        LDIR
ncach


   Before autobuild ZXRar'a table Reuleaux
cation must, of course, throw in the tail
program to get a code
block. Here's how to do drawn after
dnie line source code ZXRar'a:

DISPLAY "reloc tab end =", RelCa
End = end
RelSz = RelCa-# C000 / 2
 end = RelSz * 2 + end

        INCLUDE "mrip *", # C0; avtosborschik

                                ; (See IG # 5)

         ORG $

         LD HL, # C000

         LD DE, End

         LD BC, RelSz * 2

         LDIR

        JP nenado


   With nenado the same focus that was the case
SAVEOBJ. This transition to sohranyalku (if
withheld Caps Shift) or launch prog
FRAMEWORK at GO (If Caps Shift otpu
Puppy).

A. Coder




Other articles:

Classics - Almanashnik. Alexander Pushkin.

For Coderz - Recognition and computation of arithmetic expressions on their character record.

Inferno - The authors of the magazine.

For Coderz - the discipline to create large projects.

Interview - Questions Konstantin Sviridov (Conan) on the site zxnext.narod.ru.

Likbez - The principles of converting graphics PC-ZX.

For Coderz - Programming disc changer / drive in Scorpio.

Softinka - DNA_OS v0.431 - package of utilities for working with hard drives, RAM-drives and floppy disks.

For Coderz - Programming under DNA_OS ZET-9, a package of tools to work with storage devices.

Softinka - The problems and shortcomings package of tools to work with storage devices DNA_OS.

Likbez - details about disk formats that are FAT.

Inferno - Entered from the editor.

Inferno - Errors in the previous numbers.

For Coderz - Small programmers' tricks.

Gameland - On the new games: Oneyroid, Dizzy forever, Dridlock.

For Coderz - Writing archive. Practical principles LZ packaging.

Gameland - Passage of new shipments for the game "Black Crow".

For Coderz - Programming for the video mode 384x304.

Inferno - Letters to the Editor.

Sound - Eden Megus'a about the tracker for the AY / YM.

Inferno - On the shell.

For Coderz - Fundamentals of optimization for the processor Z80.

Likbez - The location of partitions on your hard drive.

Gamedev - 3D projection of the floor / road in the games.

Sound - Wild ideas for AY trackers.

Advertising - Ads by Roman Chuunin.

Advertising - Ads by V. Bogdanovich

For Coderz - How a large Flexible Program.

Repair - Faults Pentagon 128 + and their repair.

Inferno - Content.

Miscellaneous - Thoughts on the contest for the best software.

Others - Transfer software on ZX Spectrum with a PC.

Video - On packaging for a video ZX Spectrum.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
History of the PC - The Origin of PCs.
SWAP'A Basics - information for beginners as well as a few sly misrepresent, which You can crank the mail.
begging - Serve on kleyrasil, please!
Advertising - Advertisements and announcements ...

В этот день...   29 April