Home » Archimedes archive » Archimedes World » AW-1996-02-Disc2.adf » !Z80Dem_Z80Demo » Docs/FileFormat/XZXformat

Docs/FileFormat/XZXformat

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Archimedes World » AW-1996-02-Disc2.adf » !Z80Dem_Z80Demo
Filename: Docs/FileFormat/XZXformat
Read OK:
File size: 08B2 bytes
Load address: 0000
Exec address: 0000
File contents
Details of the level loading mechanism
--------------------------------------
[for emulator authors, and any Speccy hackers interested in 'porting'
multi-load games]

The idea is that initially, a 48k snapshot - usually in .sna format - is
loaded containing the game. Then, whenever the game would ordinarily load an
extra section from tape, something like this happens;

...
LD HL,address_to_load_data_at
LD A,level_number
DEFB 0EDh
DEFB 0FBh
...

This section will of course take the place of the original load-from-tape
routine. The emulator then traps the opcode ED/FB, and loads a file at the
specified address. Under xzx, the filenames are generated as follows
(described as an sprintf() for clarity):

	sprintf(filename,"%s%d.dat",prefix,level_number);

...with the level_number being the value the A register had when the
emulator trapped the opcode.

In xzx, the prefix is taken from the 'basename' of the last snapshot loaded,
e.g. "wibble.sna" -> "wibble". There is also provision for the re-loading of
game-in-progress snapshots, such that you can directly supply the prefix
used while specifying a snapshot to load, e.g. "game_name,my_game.sna". This
will then read in game_name1.dat, game_name2.dat etc. as appropriate.

If you're looking to 'port' a multi-load game, I find the best way to start
is to load the main (first) part of the game, get a snapshot of that, and
look for LD IX,nnnn. Many loaders use this, not just the ROM one used by the
Basic.

The next task is to find out where the level number is stored. If it isn't,
or you can't find it, you'll need at least to find some way of finding out
when a new game has started, so you can keep your own counter somewhere and
zero it (or assign 1 to it, whatever) when a new game is started. Then you
can put in the LD HL,nnnn, LD A,level etc. as mentioned above.

If you've managed that much, in theory all that remains is to get the level
data across. The ideal way to do that is to rip out the tape loader routine
from your snapshot, and run that several times, saving to disk or whatever
as you go along, then transferring kit + kaboodle later.

This is only a very simplistic guide, but I hope it helps a little.

- Russell Marks (rm1ajy2@gre.ac.uk)
00000000  44 65 74 61 69 6c 73 20  6f 66 20 74 68 65 20 6c  |Details of the l|
00000010  65 76 65 6c 20 6c 6f 61  64 69 6e 67 20 6d 65 63  |evel loading mec|
00000020  68 61 6e 69 73 6d 0a 2d  2d 2d 2d 2d 2d 2d 2d 2d  |hanism.---------|
00000030  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00000040  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 0a 5b 66  |-------------.[f|
00000050  6f 72 20 65 6d 75 6c 61  74 6f 72 20 61 75 74 68  |or emulator auth|
00000060  6f 72 73 2c 20 61 6e 64  20 61 6e 79 20 53 70 65  |ors, and any Spe|
00000070  63 63 79 20 68 61 63 6b  65 72 73 20 69 6e 74 65  |ccy hackers inte|
00000080  72 65 73 74 65 64 20 69  6e 20 27 70 6f 72 74 69  |rested in 'porti|
00000090  6e 67 27 0a 6d 75 6c 74  69 2d 6c 6f 61 64 20 67  |ng'.multi-load g|
000000a0  61 6d 65 73 5d 0a 0a 54  68 65 20 69 64 65 61 20  |ames]..The idea |
000000b0  69 73 20 74 68 61 74 20  69 6e 69 74 69 61 6c 6c  |is that initiall|
000000c0  79 2c 20 61 20 34 38 6b  20 73 6e 61 70 73 68 6f  |y, a 48k snapsho|
000000d0  74 20 2d 20 75 73 75 61  6c 6c 79 20 69 6e 20 2e  |t - usually in .|
000000e0  73 6e 61 20 66 6f 72 6d  61 74 20 2d 20 69 73 0a  |sna format - is.|
000000f0  6c 6f 61 64 65 64 20 63  6f 6e 74 61 69 6e 69 6e  |loaded containin|
00000100  67 20 74 68 65 20 67 61  6d 65 2e 20 54 68 65 6e  |g the game. Then|
00000110  2c 20 77 68 65 6e 65 76  65 72 20 74 68 65 20 67  |, whenever the g|
00000120  61 6d 65 20 77 6f 75 6c  64 20 6f 72 64 69 6e 61  |ame would ordina|
00000130  72 69 6c 79 20 6c 6f 61  64 20 61 6e 0a 65 78 74  |rily load an.ext|
00000140  72 61 20 73 65 63 74 69  6f 6e 20 66 72 6f 6d 20  |ra section from |
00000150  74 61 70 65 2c 20 73 6f  6d 65 74 68 69 6e 67 20  |tape, something |
00000160  6c 69 6b 65 20 74 68 69  73 20 68 61 70 70 65 6e  |like this happen|
00000170  73 3b 0a 0a 2e 2e 2e 0a  4c 44 20 48 4c 2c 61 64  |s;......LD HL,ad|
00000180  64 72 65 73 73 5f 74 6f  5f 6c 6f 61 64 5f 64 61  |dress_to_load_da|
00000190  74 61 5f 61 74 0a 4c 44  20 41 2c 6c 65 76 65 6c  |ta_at.LD A,level|
000001a0  5f 6e 75 6d 62 65 72 0a  44 45 46 42 20 30 45 44  |_number.DEFB 0ED|
000001b0  68 0a 44 45 46 42 20 30  46 42 68 0a 2e 2e 2e 0a  |h.DEFB 0FBh.....|
000001c0  0a 54 68 69 73 20 73 65  63 74 69 6f 6e 20 77 69  |.This section wi|
000001d0  6c 6c 20 6f 66 20 63 6f  75 72 73 65 20 74 61 6b  |ll of course tak|
000001e0  65 20 74 68 65 20 70 6c  61 63 65 20 6f 66 20 74  |e the place of t|
000001f0  68 65 20 6f 72 69 67 69  6e 61 6c 20 6c 6f 61 64  |he original load|
00000200  2d 66 72 6f 6d 2d 74 61  70 65 0a 72 6f 75 74 69  |-from-tape.routi|
00000210  6e 65 2e 20 54 68 65 20  65 6d 75 6c 61 74 6f 72  |ne. The emulator|
00000220  20 74 68 65 6e 20 74 72  61 70 73 20 74 68 65 20  | then traps the |
00000230  6f 70 63 6f 64 65 20 45  44 2f 46 42 2c 20 61 6e  |opcode ED/FB, an|
00000240  64 20 6c 6f 61 64 73 20  61 20 66 69 6c 65 20 61  |d loads a file a|
00000250  74 20 74 68 65 0a 73 70  65 63 69 66 69 65 64 20  |t the.specified |
00000260  61 64 64 72 65 73 73 2e  20 55 6e 64 65 72 20 78  |address. Under x|
00000270  7a 78 2c 20 74 68 65 20  66 69 6c 65 6e 61 6d 65  |zx, the filename|
00000280  73 20 61 72 65 20 67 65  6e 65 72 61 74 65 64 20  |s are generated |
00000290  61 73 20 66 6f 6c 6c 6f  77 73 0a 28 64 65 73 63  |as follows.(desc|
000002a0  72 69 62 65 64 20 61 73  20 61 6e 20 73 70 72 69  |ribed as an spri|
000002b0  6e 74 66 28 29 20 66 6f  72 20 63 6c 61 72 69 74  |ntf() for clarit|
000002c0  79 29 3a 0a 0a 09 73 70  72 69 6e 74 66 28 66 69  |y):...sprintf(fi|
000002d0  6c 65 6e 61 6d 65 2c 22  25 73 25 64 2e 64 61 74  |lename,"%s%d.dat|
000002e0  22 2c 70 72 65 66 69 78  2c 6c 65 76 65 6c 5f 6e  |",prefix,level_n|
000002f0  75 6d 62 65 72 29 3b 0a  0a 2e 2e 2e 77 69 74 68  |umber);.....with|
00000300  20 74 68 65 20 6c 65 76  65 6c 5f 6e 75 6d 62 65  | the level_numbe|
00000310  72 20 62 65 69 6e 67 20  74 68 65 20 76 61 6c 75  |r being the valu|
00000320  65 20 74 68 65 20 41 20  72 65 67 69 73 74 65 72  |e the A register|
00000330  20 68 61 64 20 77 68 65  6e 20 74 68 65 0a 65 6d  | had when the.em|
00000340  75 6c 61 74 6f 72 20 74  72 61 70 70 65 64 20 74  |ulator trapped t|
00000350  68 65 20 6f 70 63 6f 64  65 2e 0a 0a 49 6e 20 78  |he opcode...In x|
00000360  7a 78 2c 20 74 68 65 20  70 72 65 66 69 78 20 69  |zx, the prefix i|
00000370  73 20 74 61 6b 65 6e 20  66 72 6f 6d 20 74 68 65  |s taken from the|
00000380  20 27 62 61 73 65 6e 61  6d 65 27 20 6f 66 20 74  | 'basename' of t|
00000390  68 65 20 6c 61 73 74 20  73 6e 61 70 73 68 6f 74  |he last snapshot|
000003a0  20 6c 6f 61 64 65 64 2c  0a 65 2e 67 2e 20 22 77  | loaded,.e.g. "w|
000003b0  69 62 62 6c 65 2e 73 6e  61 22 20 2d 3e 20 22 77  |ibble.sna" -> "w|
000003c0  69 62 62 6c 65 22 2e 20  54 68 65 72 65 20 69 73  |ibble". There is|
000003d0  20 61 6c 73 6f 20 70 72  6f 76 69 73 69 6f 6e 20  | also provision |
000003e0  66 6f 72 20 74 68 65 20  72 65 2d 6c 6f 61 64 69  |for the re-loadi|
000003f0  6e 67 20 6f 66 0a 67 61  6d 65 2d 69 6e 2d 70 72  |ng of.game-in-pr|
00000400  6f 67 72 65 73 73 20 73  6e 61 70 73 68 6f 74 73  |ogress snapshots|
00000410  2c 20 73 75 63 68 20 74  68 61 74 20 79 6f 75 20  |, such that you |
00000420  63 61 6e 20 64 69 72 65  63 74 6c 79 20 73 75 70  |can directly sup|
00000430  70 6c 79 20 74 68 65 20  70 72 65 66 69 78 0a 75  |ply the prefix.u|
00000440  73 65 64 20 77 68 69 6c  65 20 73 70 65 63 69 66  |sed while specif|
00000450  79 69 6e 67 20 61 20 73  6e 61 70 73 68 6f 74 20  |ying a snapshot |
00000460  74 6f 20 6c 6f 61 64 2c  20 65 2e 67 2e 20 22 67  |to load, e.g. "g|
00000470  61 6d 65 5f 6e 61 6d 65  2c 6d 79 5f 67 61 6d 65  |ame_name,my_game|
00000480  2e 73 6e 61 22 2e 20 54  68 69 73 0a 77 69 6c 6c  |.sna". This.will|
00000490  20 74 68 65 6e 20 72 65  61 64 20 69 6e 20 67 61  | then read in ga|
000004a0  6d 65 5f 6e 61 6d 65 31  2e 64 61 74 2c 20 67 61  |me_name1.dat, ga|
000004b0  6d 65 5f 6e 61 6d 65 32  2e 64 61 74 20 65 74 63  |me_name2.dat etc|
000004c0  2e 20 61 73 20 61 70 70  72 6f 70 72 69 61 74 65  |. as appropriate|
000004d0  2e 0a 0a 49 66 20 79 6f  75 27 72 65 20 6c 6f 6f  |...If you're loo|
000004e0  6b 69 6e 67 20 74 6f 20  27 70 6f 72 74 27 20 61  |king to 'port' a|
000004f0  20 6d 75 6c 74 69 2d 6c  6f 61 64 20 67 61 6d 65  | multi-load game|
00000500  2c 20 49 20 66 69 6e 64  20 74 68 65 20 62 65 73  |, I find the bes|
00000510  74 20 77 61 79 20 74 6f  20 73 74 61 72 74 0a 69  |t way to start.i|
00000520  73 20 74 6f 20 6c 6f 61  64 20 74 68 65 20 6d 61  |s to load the ma|
00000530  69 6e 20 28 66 69 72 73  74 29 20 70 61 72 74 20  |in (first) part |
00000540  6f 66 20 74 68 65 20 67  61 6d 65 2c 20 67 65 74  |of the game, get|
00000550  20 61 20 73 6e 61 70 73  68 6f 74 20 6f 66 20 74  | a snapshot of t|
00000560  68 61 74 2c 20 61 6e 64  0a 6c 6f 6f 6b 20 66 6f  |hat, and.look fo|
00000570  72 20 4c 44 20 49 58 2c  6e 6e 6e 6e 2e 20 4d 61  |r LD IX,nnnn. Ma|
00000580  6e 79 20 6c 6f 61 64 65  72 73 20 75 73 65 20 74  |ny loaders use t|
00000590  68 69 73 2c 20 6e 6f 74  20 6a 75 73 74 20 74 68  |his, not just th|
000005a0  65 20 52 4f 4d 20 6f 6e  65 20 75 73 65 64 20 62  |e ROM one used b|
000005b0  79 20 74 68 65 0a 42 61  73 69 63 2e 0a 0a 54 68  |y the.Basic...Th|
000005c0  65 20 6e 65 78 74 20 74  61 73 6b 20 69 73 20 74  |e next task is t|
000005d0  6f 20 66 69 6e 64 20 6f  75 74 20 77 68 65 72 65  |o find out where|
000005e0  20 74 68 65 20 6c 65 76  65 6c 20 6e 75 6d 62 65  | the level numbe|
000005f0  72 20 69 73 20 73 74 6f  72 65 64 2e 20 49 66 20  |r is stored. If |
00000600  69 74 20 69 73 6e 27 74  2c 0a 6f 72 20 79 6f 75  |it isn't,.or you|
00000610  20 63 61 6e 27 74 20 66  69 6e 64 20 69 74 2c 20  | can't find it, |
00000620  79 6f 75 27 6c 6c 20 6e  65 65 64 20 61 74 20 6c  |you'll need at l|
00000630  65 61 73 74 20 74 6f 20  66 69 6e 64 20 73 6f 6d  |east to find som|
00000640  65 20 77 61 79 20 6f 66  20 66 69 6e 64 69 6e 67  |e way of finding|
00000650  20 6f 75 74 0a 77 68 65  6e 20 61 20 6e 65 77 20  | out.when a new |
00000660  67 61 6d 65 20 68 61 73  20 73 74 61 72 74 65 64  |game has started|
00000670  2c 20 73 6f 20 79 6f 75  20 63 61 6e 20 6b 65 65  |, so you can kee|
00000680  70 20 79 6f 75 72 20 6f  77 6e 20 63 6f 75 6e 74  |p your own count|
00000690  65 72 20 73 6f 6d 65 77  68 65 72 65 20 61 6e 64  |er somewhere and|
000006a0  0a 7a 65 72 6f 20 69 74  20 28 6f 72 20 61 73 73  |.zero it (or ass|
000006b0  69 67 6e 20 31 20 74 6f  20 69 74 2c 20 77 68 61  |ign 1 to it, wha|
000006c0  74 65 76 65 72 29 20 77  68 65 6e 20 61 20 6e 65  |tever) when a ne|
000006d0  77 20 67 61 6d 65 20 69  73 20 73 74 61 72 74 65  |w game is starte|
000006e0  64 2e 20 54 68 65 6e 20  79 6f 75 0a 63 61 6e 20  |d. Then you.can |
000006f0  70 75 74 20 69 6e 20 74  68 65 20 4c 44 20 48 4c  |put in the LD HL|
00000700  2c 6e 6e 6e 6e 2c 20 4c  44 20 41 2c 6c 65 76 65  |,nnnn, LD A,leve|
00000710  6c 20 65 74 63 2e 20 61  73 20 6d 65 6e 74 69 6f  |l etc. as mentio|
00000720  6e 65 64 20 61 62 6f 76  65 2e 0a 0a 49 66 20 79  |ned above...If y|
00000730  6f 75 27 76 65 20 6d 61  6e 61 67 65 64 20 74 68  |ou've managed th|
00000740  61 74 20 6d 75 63 68 2c  20 69 6e 20 74 68 65 6f  |at much, in theo|
00000750  72 79 20 61 6c 6c 20 74  68 61 74 20 72 65 6d 61  |ry all that rema|
00000760  69 6e 73 20 69 73 20 74  6f 20 67 65 74 20 74 68  |ins is to get th|
00000770  65 20 6c 65 76 65 6c 0a  64 61 74 61 20 61 63 72  |e level.data acr|
00000780  6f 73 73 2e 20 54 68 65  20 69 64 65 61 6c 20 77  |oss. The ideal w|
00000790  61 79 20 74 6f 20 64 6f  20 74 68 61 74 20 69 73  |ay to do that is|
000007a0  20 74 6f 20 72 69 70 20  6f 75 74 20 74 68 65 20  | to rip out the |
000007b0  74 61 70 65 20 6c 6f 61  64 65 72 20 72 6f 75 74  |tape loader rout|
000007c0  69 6e 65 0a 66 72 6f 6d  20 79 6f 75 72 20 73 6e  |ine.from your sn|
000007d0  61 70 73 68 6f 74 2c 20  61 6e 64 20 72 75 6e 20  |apshot, and run |
000007e0  74 68 61 74 20 73 65 76  65 72 61 6c 20 74 69 6d  |that several tim|
000007f0  65 73 2c 20 73 61 76 69  6e 67 20 74 6f 20 64 69  |es, saving to di|
00000800  73 6b 20 6f 72 20 77 68  61 74 65 76 65 72 0a 61  |sk or whatever.a|
00000810  73 20 79 6f 75 20 67 6f  20 61 6c 6f 6e 67 2c 20  |s you go along, |
00000820  74 68 65 6e 20 74 72 61  6e 73 66 65 72 72 69 6e  |then transferrin|
00000830  67 20 6b 69 74 20 2b 20  6b 61 62 6f 6f 64 6c 65  |g kit + kaboodle|
00000840  20 6c 61 74 65 72 2e 0a  0a 54 68 69 73 20 69 73  | later...This is|
00000850  20 6f 6e 6c 79 20 61 20  76 65 72 79 20 73 69 6d  | only a very sim|
00000860  70 6c 69 73 74 69 63 20  67 75 69 64 65 2c 20 62  |plistic guide, b|
00000870  75 74 20 49 20 68 6f 70  65 20 69 74 20 68 65 6c  |ut I hope it hel|
00000880  70 73 20 61 20 6c 69 74  74 6c 65 2e 0a 0a 2d 20  |ps a little...- |
00000890  52 75 73 73 65 6c 6c 20  4d 61 72 6b 73 20 28 72  |Russell Marks (r|
000008a0  6d 31 61 6a 79 32 40 67  72 65 2e 61 63 2e 75 6b  |m1ajy2@gre.ac.uk|
000008b0  29 0a                                             |).|
000008b2