UNDOCUMENTED TRICKS


On this page you can find various tricks which can not be learned from the manual, about both the Warajevo and the Spectrum itself. This page is still in the construction. At this moment, the following topics are avaliable:

Also, some partially documented things may be found in the source files which come with various plug-ins for the Warajevo emulator, and in the short information files supported with the executable snapshot files.


HOW TO DETECT RELEASE OF THE WARAJEVO


Here you will find a method for detecting whether the program is executed on the Warajevo emulator, and on which release (if the Warajevo is detected).

Type in the following BASIC program and run it:

5 LET start=50000: REM You may select any address
10 FOR f=start TO start+19: READ a: POKE f,a: NEXT f
20 DATA 167, 237, 0, 56, 48, 56, 54, 48, 7, 48, 7, 137, 225, 205, 250, 201, 1, 0, 0, 201
30 PRINT USR start


Look the displayed number. If it is 0, the program is not executed on Warajevo or it is executed on Warajevo 1.2 or older. If the displayed number is non-zero, it can determine Warajevo release number and the version of the emulator:

13788: Release 2.51, 48K
14556: Release 2.51, 128K
16700: Release 2.51, TS2068
13756: Release 2.5, 48K
14524: Release 2.5, 128K
16684: Release 2.5, TS2068
13532: Release 2.0, 48K
14284: Release 2.0, 128K
11868: Release 1.5, 48K
12316: Release 1.5, 128K


This program is based on 80x86 escape sequences. Non-Warajevo emulators and a real Spectrum will not recognized them, so the result will be zero (look a dirty code in Z80 assembler produced by 80x86 patches). But, if escape sequences are recognized, they bring up value of PC SP register, which has release-dependent value during execution of escape sequences.

Values in the above table will become DIFFERENT if you compile this program using the ZXCOMP snapshot compiler, but this is not important because if you use ZXCOMP, you surely know WHICH RELEASE you use to compile a snapshot. Later, this snapshot will become a standalone executable file, so it surely can not be executed on different releases of the emulator...


CHANGING OF THE EXECUTION SPEED


You know that it is possible to change execution speed of Warajevo using switch /%. But, somebody asks us is it possible to change speed within the Spectrum program itself, e.g. during execution of the Spectrum program???

Principally, it is very easy, you must only to change two system variables of Warajevo using escape sequences. But, the problem is in fact that location of these variables is release-dependent. The following program tries to locate and patch them in the emulator, and it seems that it is release-independent (starting from 2.0; earlier releases had no possibility of exact changing ot the execution speed):

10 LET start=30000: REM You may select any address
20 RESTORE : FOR f=start TO start+47: READ a: POKE f,a: NEXT f
30 DATA 237, 0, 56, 48, 56, 54, 6, 185, 255, 255, 51, 255, 22, 7, 184, 154, 0, 175, 117, 7, 38, 129, 61, 100, 0, 116, 6, 79, 226, 243, 235, 12, 144, 38, 199, 69, 254, 154, 0, 38, 199, 5, 100, 0, 7, 205, 250, 201
40 INPUT "Speed in % : ";speed
50 LET factor=2*(1+INT (7636/speed+0.5))
60 POKE start+37,factor-256*INT (factor/256): POKE start+38,INT (factor/256)
70 POKE start+42,speed-256*INT (speed/256): POKE start+43,INT (speed/256)
80 RANDOMIZE USR start
90 POKE start+15,PEEK (start+37): POKE start+16,PEEK (start+38)
100 POKE start+23,PEEK (start+42): POKE start+24,PEEK (start+43)
110 BEEP 1,0: REM This is an example...
120 GO TO 40

The machine code in DATA line is, after switching into 80x86 mode:
       push es
       mov  cx,-1
       xor  di,di
       push ss
       pop  es
       mov  ax,OldFactor
SRCH:  scasw
       jne  CONT
       cmp  word ptr es:[di],OldPercent
       jz   FOUND
CONT:  dec  di
       loop SRCH
       jmp  END
FOUND: mov  word ptr es:[di-2],NewFactor
       mov  word ptr es:[di],NewPercent
END:   pop  es
       int  250
Line 50 in the BASIC program calculates time constant named "factor", which is needed for speed compensation loop, and lines 60 and 70 patches constants "NewFactor" and "NewPercent" into the machine code. After calling the machine code, lines 90 and 100 patches constants "OldFactor" and "OldPercent" with "NewFactor" and "NewPercent", else next running of the machine code will not success to locate necessary variables. If you want to change speed only once, these POKE's may be omitted. At last, line 110 is simple demo to see that the execution speed is really changed.

If you want to change speed after again, DO NOT run again this program from the beginning. Instead, use GO TO 40. Else, the BASIC program in line 20 will re-patch the machine code to the initial state, so it will not be able to detect location of changed system variables...


LOADING SNAPSHOTS INTO THE ROM


Warajevo emulator does not support snapshots which can be loaded into the ROM (in opposite to the Spectrum emulator by Pedro R. M. Salas). We did not allow this, due to some potential problems which may happen if the ROM is changed. However, if you have various ROM files, it will be tedious to rename ZX48.ROM into something other, and something other into ZX48.ROM, to execute the emulator with changed ROM. Here we will explain how you can make Warajevo snapshots which will be loaded into the ROM however...

This trick is based on a bug into the Warajevo which is not removed (and will not be removed), because it does not affect "normal" snapshots. Below, a program is given (in Turbo Pascal) which convert a ROM file into a Z80 file which will be loaded over the normal Spectrum ROM:

var f1,f2:text;
    i:word;
    c:char;
    s:string;

begin
    write('Filename: '); readln(s);
    assign(f1,s+'.rom'); reset(f1);
    assign(f2,s+'.z80'); rewrite(f2);
    write(f2,#0#0#0#0#0#0#1#0#0#0#0#0);
    write(f2,#32#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0);
    for i:=1 to 192 do
        write(f2,#237#237#255#0);
    write(f2,#237#237#192#0);
    for i:=1 to 16384 do begin
        read(f1,c); write(f2,c)
    end;
    close(f1); close(f2)
end.

We will not explain how it works. Look the description of the Z80 file format, and try to understand how by yourself!


POKING ROM IN THE WARAJEVO


Maybe the most frequent usage of the Warajevo escape sequences is to patch the ROM addresses from some program. For those which don't know 80x86 assembler, here is a sequence which simulates Z80 instruction LD (HL),A but without address checking (e.g. which can poke a byte into the ROM):

DB 237,0,56,48,56,54,136,5,205,250

Insert this instead of LD (HL),A in your program if you want to poke the ROM.


ACCESSING MEMORY ABOVE 1 MB WITHOUT DOS EXTENDERS


Option "Sample from tape" in the Warajevo environment looks very misterious for many programers, and they wonder how we success to access memory above 1 MB from real-mode DOS without DOS extenders. Basically, in the protected mode, the size of segments need not to be 64K, it is user definable. But, if someone enters into the protected mode, break segment limits by increasing size to max 4GB, and then returns back into real mode, the segment size will retain broken, e.g. without limitation to 64K :-). Daniele Paccaloni from Italy made a simple program (UNREAL10.EXE) which breaks segment limits, and it may be found on the internet. But, Zeljko Juric also made very similar program (MYUNREAL.COM), but much shorter (only 200 bytes). Click here to download it. This program displays OK if the installation of broken segments is OK, else displays ERROR (note that it is not a TSR program). A source file is included, in assembler, with a lot of comments. Read this to try to understand how it works. This program may very easy be embeded into other programs (in fact, this is done in the Warajevo environment), you need only to make minor modifications in the source...


INTERNAL ORGANIZATION OF ZXCOMP-ED SNAPSHOTS


Sometimes it is necessary to know roughly the internal organization of PC executables created by ZXCOMP (this was necessary, for example, to produce a monolite version of executable R-TYPE, which can be found on this site in the section about executable snapshots). So, the brief organization of ZXCOMP-ed files is given here.

48K ZXCOMP-ed snapshots have 4 parts: 128K ZXCOMP-ed snapshots have 6 parts: Maybe the organization seems strange, but we have strong reasons for such organization. Note that ZXCOMP-ed program always expect that the last 132 bytes of it contain system informations, so you must not append anything at the end of the program. However, you can insert without any problems any data between the P-code and the last 132 bytes, you only need to update the pointer to the P-code (because it is measured from the END of the file).

Another note is a fact that the P-code is release independent, and it has 1:1 corespodence with the source snapshot, so it is possible to make a release independent ZXCOMP decompiler, which convert PC executables back into snapshots. This is useful if you want to made some patches in an executable snapshot (for example, to make infinite lives) and recompile patched snapshot back, or if you want to re-compile a game which is compiled with some very old release of ZXCOMP with a new one...


TRANSFERING PROGRAMS FROM 48K MODE TO 128K MODE ON REAL SPECTRUM 128


Not very undocumented, but some peoples ask us how to transfer programs from 48K mode to 128K mode on real Spectrum 128. This is not so easy, but it is possible if you entered 48K mode using USR 0 (if you entered using '48 Basic' on the menu, or using SPECTRUM command, the transfer is impossible, because MMU is locked in this case; however, on the Warajevo emulator, you can unlock it using Y command in the built-in monitor). For the transfer, it is necessary to restore the main system variables related to 128K mode, and jump into the 128K ROM at the appropriate place. This may be done, for example, using the following machine code:
di
ld   a,7        ; Enable Derby ROM i RAM 7
ld   bc,32765
out  (c),a
ld   (23388),a
ld   de,23296   ; Restore paging subroutines
ld   hl,107
ld   bc,88
ldir
ld   a,207      ; Restore RAMRST
ld   (23389),a
ld   a,16       ; b4=1 in 23611 => 128K mode
ld   (23611),a
jp   519        ; Jump into the main 128K entry point

The command A128 in the built-in monitor does similar thing. Do not put this routine above address 49152 (due to paging), nor into the printer buffer!

Transfering into 128K mode is very hard if the program poked something into the printer buffer (because 128K mode system variables are stored there). This routine is not perfect (this is only an example), it does not restore system variables related to the printer and the RAM disc, so usage of them in 128K mode after transfering will not work, or will cause a crash...


THE LONGEST SPECTRUM FILE NAME


Strictly, this is not an undocumented feature, but it is really fun. You probably know that the Spectrum allows tokens into a filenames, and every token will be counted as one char. The first such file which we seen was OLYMPIMANIA (it seems that it has 11 chars, but PI is a token) produced by Automata. The commercial programs with long file names are, for example:

PAPER AEROPLANE
BRIGHT NEW COPY TO LOAD AND RUN
BRIGHT NEW CODE TO LOAD AND PLAY


Zeljko used the following file names in your Spectrum programs:

DRAW OVER BORDER
TO FORMAT UDG CODE
FORMAT 64 CHR$ IN LINE

And, we made an adventure game for Spectrum named:

NOT A NEW IN BALCAN

Of course, the longest Spectrum file name is:

RANDOMIZE RANDOMIZE RANDOMIZE RANDOMIZE RANDOMIZE RANDOMIZE RANDOMIZE RANDOMIZE RANDOMIZE RANDOMIZE

but, unfortunately, it has no sence. So, Samir tried to discover which is the longest Spectrum file name which has a sence. He tried with:

I PRINT RANDOMIZE CODE IN CIRCLE PAPER AND DRAW OUT

and started a discussion on DejaNews. Sorry, we are not experts in English language, so this sentence still has no sence. A list with various file names suggested at DejaNews follows:

CONTINUE TO DRAW BORDER LINE AND CIRCLE IN BRIGHT INK
RANDOMIZE CODE IN NEW DATA FORMAT THEN SAVE AND VERIFY
PAUSE FOR NEW INPUT THEN CONTINUE TO PRINT IN INVERSE
IF DATA IN CODE THEN POINT NEXT INPUT AT CAT
RUN TO SAVE INK FOR PAPER BORDER
FORMAT BORDER AND MOVE BRIGHT INPUT FOR READ OR RETURN
GO TO COPY AND RESTORE FOR NEW LIST THEN DRAW OVER
RUN AND PAUSE THEN CONTINUE CLEAR PRINT OUT FOR RETURN
MOVE CAT OUT AND RANDOMIZE DATA TO CONTINUE THEN CIRCLE
MORE INVERSE POINT OVER SCREEN$ THEN ERASE LINE AND CONTINUE
READ SIN IN CODE THEN PAPER OVER BRIGHT INVERSE PRINT
PRINT AND BIN INPUT THEN PLOT TO RUN IN CIRCLE

Some filenames which can be used only at Spectrum 128 due to usage of tokens SPECTRUM and PLAY:

PLAY AT SPECTRUM IN OPEN # OR IN CIRCLE
RANDOMIZE SPECTRUM DATA FORMAT AND THEN RETURN DIM INPUT LINE

This file name will be a really long, but it is ugly and incorrect without punctuation marks (commas):

GO TO BORDER RANDOMIZE CODE PAUSE AND THEN CONTINUE TO FLASH

With commas, the file names like following are suggested:

RANDOMIZE, RANDOMIZE, RANDOMIZE, RANDOMIZE AND RANDOMIZE
RANDOMIZE BORDER, RANDOMIZE INK, RANDOMIZE CODE AND FLASH

Samir still try to find the longest one, and his last try was:

RETURN CAT OVER BORDER THEN CONTINUE TO RANDOMIZE INPUT FORMAT

But, someone suggested following:

RETURN DATA TO RANDOMIZE INPUT FORMAT THEN CONTINUE BORDER MERGE
RETURN INPUT TO RANDOMIZE DATA FORMAT THEN CONTINUE BORDER MERGE

The discusion is still open.

If someone thought that "the longest" may mean the longest in sence of the distance, not in sence of the number of characters, the "longest" sugested file name is:

TeraParsec

"Tera" means 10^12. But, as we know, a prefixes "Peta" (10^15) and "Eksa" (10^18) also exist. We don't now how the prefix "Eksa" is correctly written on English (maybe "Exa"), it is in Bosnian. But, if "Eksa" is correct, the longest file name in sence of the distance will be:

EksaParsec

Silly, but fun...



BACK TO THE WARAJEVO MAIN PAGE