www.cpcalive.com
Cliquer ici pour la documentation française
Pulsar aquí para la documentación en español

* CpcAlive V1.09M *
DOCUMENTATION (V0.2)




notes:
- This documentation relates about information necessary to use the CpcAlive emulator. Documentations about Cpc exploitation are available on the internet site: www.cpcalive.com
- This documentation uses two types of hexadecimal values notation. The first notation adds the sign "&" in front of the value, ex:&3F. The second notation adds the letter "h" behind the value, ex:3Fh.


TABLE OF CONTENTS

I - 
Presentation of the emulator CpcAlive

II - Files recognized by the emulator
        II - 1 - Virtual diskettes files (.DSK)
        II - 2 - Cpc roms files
        II - 3 - Intel hex files
        II - 4 - Assembler source files
        II - 5 - CpcAlive commands files
        II - 6 - Text files
       
II - 7 - Binary files
III - CpcAlive commands from the Cpc basic interpreter
IV - CpcAlive commands from the Dos command line
    CpcAlive [input_files[:X]] [CpcAlive commands] [Cpc commands] [>output_file]
V - Accentued characters
VI - Bios and Dos interruptions access trough Z80
VII - X86 environment
VIII - Utility softwares
    - 1 - CreaDisc: create a virgin virtual diskette usable by the emulator (data formatted).
    - 2 - Extract: extract files from virtual diskettes



                                                                                                                                                                                                                      

I - Presentation of the emulator CpcAlive

CpcAlive is a programmation environment Amstrad CPC compatible.

CpcAlive Specificities:
* screen resolutions 160*200*16, 320*200*256 and 640*200*16
* X86 programmation environment (16Mo)
* Bios and Dos interruptions access trough instructions added to the Z80
* outputs screens in BMP images
* programmable BASIC
* possibility to treat from the Cpc BASIC interpreter any file present on the hard drive or another support.
* create executable environment safeguards.
* include a Z80 assembler and debugger
management of files created with the compiler C PhrozenC
 

II - Files recognized by the emulator

Files recognized by the emulator are:

Virtual diskette with format DSK     (see chapter II-1-)
Cpc rom files                                 (see chapter II-2-)
Intel hex files                                 (see chapter II-3-)
Assembler source files                    (see chapter II-4-)
CpcAlive command files                 (see chapter II-5-)
Text documents                             (see chapter II-6-)
Binary files                                    (see chapter II-7-)

To load a file from the Dos command line:
CpcAlive filename[:X]
It is also possible to use the syntax: ! filename[:X]

The letter represented by the character "X" is optional, it depends on the type of file to load. It will be called "marker".
Note: don't put spaces betwen the file name and the marker.

To load a file from a CpcAlive command file:
filename[:X]

To load
a file from the Cpc BASIC interpreter:
|INPUT,"filename[:X]"[,@er%]

The error return parameter @er% is facultatif. If it is put, the significance of the values recovered in the variable er% are:
0 = ok
1 = error number parameters
2 = way not found
(don't forget initialize er% at the program beginning or before the command)

         ex:    10 er%=0
                 20 |INPUT,"Disc.dsk:A",@er%
                 30 if er%<>0 then PRINT"ERROR":STOP

It is possible to put several file names at the continuation. They must be separated by a space character. In this case, the error code er% will relate to the last file mentioned.
It is also possible to obtain informations about the last file loaded with the following command:

info$=string$(12,"X"):|INFO,@info$:PRINT info$


II - 1 - Loading virtual diskettes files (.DSK
) -
Make follow the file name of the
":A" or ":B" markers to choose the Cpc drive destination.(drive A by defect)

example from the Dos command line:

! disc.dsk:A
example from a CpcAlive command file:
disc.dsk:A
example from the Cpc BASIC interpreter:
|input,"disc.dsk:A"

This command load the virtual diskette "disc.dsk" in the drive A of the emulator.


II - 2 - Loading  Cpc roms files -

There is three 16Kb roms blocks in the Cpc 6128 (48Ko). One of these blocks contains the operating system which is connected in zone 0 to 03FFFh (low rom). The two other blocks (BASIC and disc system) are connected in the zone 0C000h to 0FFFFh (high roms). The system can exploit in this zone 252 blocks of 16Ko each one. An interesting characteristic of these roms is that they can receive BASIC programmable instructions 
(Resident System eXtension).

To load a rom file in the emulator, make follow the file name by the ":R" marker. CpcAlive will seek the first area available. The file can be binary or intel hex formated.

Loading from the Dos command line:
! Z80ROM.ROM:R
Loading from a CpcAlive command file:
Z80ROM.ROM:R
Loading from the Cpc BASIC interpreter:
|INPUT, "Z80ROM
.ROM:R":call 0

The rom site number can be obtained with the following way:
info$=string$(16,"X"):|INFO,@info$:RomPlace=val("&"+mid$(info$,15,2)):PRINT RomPlace
If it is necessary to have a fixed area number, you can replace the letter "R" with an area number. (Allowed values: 0 to 191)
example from the Dos command line:  ! Z80ROM.ROM:10

Roms will be recognized by the Cpc system only after a rebootstrapping for example with a CALL 0 or by actuating keys 
[Ctrl][Alt][Home] in the same time. The emulator takes RSX instructions with all highers roms. The areas numbers used by the Cpc system are 0 for BASIC rom and 7 for DISC rom. The X86 modules (see chapter "X86 Environment") with mnemonics use also Z80 roms sites. The highers roms with a specific site number must be loaded before the X86 modules. The best way is to indicate them at the beginning of the command file ROM.INI located in the principal repertory.

note: For CD versions, the file autoexec.bat copy the file ROM.INI located in the directory INI towards the
principal repertory of the emulator. It is this file which will be used to start. For USB flash drive or floppy versions, this file is located in the CpcIni repertory.

When a program is executed in ROM, CpcAlive redirects by defect the Z80 writing accesses into the RAM. The command |UNLOCK,-rom site number- authorizes the writing accesses of the Z80 microprocessor in the specified ROM. The ROM works then similarly than a RAM.

Sample coding of an Amstrad Cpc Rom containing programmable basic instructions (Resident System eXtension)


II - 3 - Loading intel hex files  -

The Intel Hex Object Format is line oriented and uses only printable ASCII characters.

Intel Hex line:
:LLAAAA00DDDD...CC  ; ':' = start character (colon)
                                       ; LL = block size (2 hex digits)
                                       ; AAAA = starting adress (4 hex digits)
                                       ; 00 = record type (00)
                                       ; DDDD = data bytes (a pair of hex digits for each byte of data)
                                       ; CC=
check sum (2 hex digits)

file example:
:18A600000109A62111A6C3D1BC15A6C31EA6C335A6000000004F5049A2
:18A61800D8495049D800DD5603DD5E02DD4605DD4E043E0C4052DD7E97
:18A6300000404810C9D5DD5603DD5E02DD4605DD4E043E0D40524048AD
:07A6480010D11213AF12C97B
:00000001FF

In this example, the first line contains 018h data bytes (01h,09h,0A6h... 049h) which will be loaded starting from the address 0A600h. The 
check sum of the line is equal to 0A2h. The check sum normally present at the end of a standard intel hex line is not obligatory with CpcAlive. Note the record type equal to 1 indicating the last line of the file. This line is not necessary with files loaded by the emulator.

Loading in rom:

To load an intel hex file in rom, make follow the file name by the ":X" marker where X represent the rom recipient number.

Example for loading in rom number 10:
from the Dos command line:
!  FILENAME.HEX:10
from a CpcAlive command file:
FILENAME.HEX:10     for loading in rom number 10
from the Cpc BASIC interpreter:
|input,"FILENAME.HEX:10"

If the destination rom does not exist, CpcAlive create it. It is also possible to use the :R marker (see chapter "Loading Cpc roms files")


Loading in ram:

The 6128 has a 128 KB memory (RAM) divided into eight blocks of 16 KB each one, numbered from 0 to 7. Only four blocks can beings connected simultaneously.

Table showing ram blocks positioning in foncion of the configuration type:
Value on port &7F    blocks position
                &C0            0,1,2,3           
<= standard Cpc configuration memory
                &C1            0,1,2,7
                &C2            4,5,6,7
                &C3            0,3,2,7
                &C4            0,4,2,3
                &C5            0,5,2,3
                &C6            0,6,2,3
                &C7            0,7,2,3
Allowed values added to the emulator:
                &C8            0,8,2,3
                &C9            0,9,2,3
                ...
                &FF            0,&3F,2,3

The Cpc system exploits only the first configuration. In this configuration block 0 occupies memory space 0 to 03FFFh, block 1 space 04000h to 07FFFh, block 2 space 08000h to 0BFFFh and block 3 space 0C000h to 0FFFFh. The screen exploits block 3. The higher part of block 2 contains the system variables. The lower part of block 0 is used by the system. BASIC programs are loaded by the system starting from the address 0170h. The binary data can beings loaded starting from the address defined using the Basic instruction "MEMORY". If they are executable programs, they could be called with the instruction "CALL".

To load an intel hex file in ram, make follow the file name by the ":X" marker where X represents the ram recipient configuration type. Valids hexadecimal values for loading in RAM go from 0C0h to 0FFh. By defect, the loading is done in RAM with 0C0h configuration.

example from the Cpc BASIC interpreter
|input,"FILENAME.HEX"
In this case, the file "file.hex" is loaded with the standard Cpc configuration memory.


notes:
- It is possible to see the Cpc memory with CpcAlive with the command |DEBUG,&f from the BASIC interpreter.
- Put values in RAM blocks 0,1,2 ou 3 before the Cpc system initialization is useless because this blocks are cleared with starting. To put values in RAM from the Dos command line, the system could be launched and put in sleeping mode previously.
- The Z80 assembler "tasm" generates intel hex files.


II - 4 - Loading assembler source files  -

The emulator uses the sequence "org &" in small letters on the first line of the file to determine that is an assembler source created with the compiler C PhrozenC. For other sources, the emulator will seek the sequence ".org" or "org " in small or capital letters on the four first letters of the file.

The internal compiler uses the following standard words:
DB, DW, DS, END, EQU, ORG
and:
LISTHEX: list the program in Intel Hex form in the output file.
NOLIST: stop the listing.
DEBUG: start the debugger. (BreakPoint)


It is possible to define macros-instructions in this form:
Ex:
MACRO ADD(X, Y)
LD HL, X
LD DE, Y
ADD HL,DE
ENDM

The internal compiler recognizes the directives Tasm (8bits) following:
.BYTE, .DB, .DW, .DS, .END, .EQU, .FILL,.ORG, .WORD, #INCLUDE, #DEFINE & #DEFCONT
and the following operators: =, +, -, *,/, |, &

The internal compiler manages the operations in a very simplified way and does not support the brackets in those and does not manage the mathematical priorities.

For assembly a Z80 source file in Ram memory, make follow the file name with the marker :X where X represents the Ram memory configuration type recipient followed by the loading address. By defect, the loading is done in memory with the configuration 0C0h to the address indicated by the command ORG. (see Loading in Ram memory to see the various 
Ram memory configurations)

Loading in Ram memory with standard configuration:

from the Dos command line:
! FILENAME.ASM
from a CpcAlive command file:
FILENAME.ASM
from the Cpc BASIC interpreter:
|INPUT,"FILENAME.ASM
|RUN,"FILENAME.ASM

The command |RUN launches the program automatically and is effective only if the file is loaded with standard Ram configuration. The command |RUN, "FILENAME.ASM:0C0h, 02000h" load the file in address 02000h and launches the program. It is possible to obtain the address memory following the loaded block like this:
info$=string$(20,"X"):|INFO,@info$:EndBloc=val("&"+mid$(info$,17,4)):?hex$(EndBloc)

For assembly a Z80 source file in rom, make follow the file name by the ":R" marker. CpcAlive will seek the first area available.
Loading from the Dos command line:

!
FILENAME.ASM:R
Loading from a CpcAlive command file:
FILENAME.ASM:R
Loading from the Cpc BASIC interpreter:
|INPUT, "
FILENAME.ASM:R"

The rom site number can be obtained with the following way:
info$=string$(16,"X"):|INFO,@info$:RomPlace=val("&"+mid$(info$,15,2)):PRINT RomPlace
If it is necessary to have a fixed area number, you can replace the letter "R" with an area number. (Allowed values: 0 to 191)
example from the Dos command line:  ! Z80ROM.ROM:10
The address memory following the loaded block can be obtained in the same way that for loading in RAM. It is also possible to choose the load address by indicating this one in second parameter.


II - 5 - Loading command files

The intern emulator valid commands from the Dos command line or a CpcAlive command file are:

CpuFast set maximum speed                              - [F12]
CpuSlow set speed of the original Cpc computer   - [F11]
Sleep put the emulator on sleeping state           - [AltGr][S]
Exit to leave the emulator                             - [Ctrl][Alt][End]
ROM=X select ROM X (256 for the Cpc bios)
RAM=X select RAM X configuration
see chapter "Loading in ram"
for ram configuration values.
:LLAAAA00DDDD... loading data. (Intel Hex line)
Cont continue a file created with the command |MAKE
Debug start the debugger
Z80 going from the "Commands" mode to the "Z80 compiler" mode. The interpretation
of the file will be restored in mode "Commands" with the End or .End instruction.
PhrozencOrg=ADR ADR=loading adress per defect of the sources files generated by the compiler C PhrozenC.
End indicate the end of a command file.
Text going from the "Commands" mode to the "Text" mode. After this command, the file will
not be interpreted any more like a command file but like a text file .
Use the keyword
|Command
or |CMD to go back in "Commands" mode. The commands "End" and "Text"
restore the memory configuration if this one were modified with the commands "Rom" or "Ram".


example from the Dos command line
To select the BIOS rom and poke the value 2 in 0B13h adress (screen mode of starting) and select slow speed emulation:

! ROM=256 :010B130002 CpuSlow

Don't forget spaces between commands.

If a CpcAlive command is not reconized, this command and the rest of the line is interpreted like a Cpc command. You can by this way adding one or more Cpc commands at the end of the line. (Only from the Dos interpreter. From CpcAlive commands files, use the "Text" command).

example:

! ROM=256 :010B130002 CpuSlow PRINT"OK"

note:
- put values in RAM blocks 0,1,2 ou 3 before the Cpc 
initialization is useless because this blocks are cleared by the system. To put values in RAM from the Dos command line, the system could be launched and put in sleeping mode previously.


CpcAlive command files:

These files are intended, as their name indicates it, to command the emulator from a file. This file must start with 
"CMD:" sequence without guillemets (header).

Loading from the Dos command line:
FILENAME.CMD
Loading from a CpcAlive command file:
FILENAME.CMD
Loading from the Cpc BASIC interpreter:
|INPUT, "FILENAME
.CMD"
                  
example 1:
Select the BIOS rom and poke the value 2 in 0B13h adress (screen mode of starting) and select slow speed:

CMD:               ; header
ROM=256        ; select rom bios
:010B130002    ; poke the value 2 in 0B13h adress (screen mode of starting)
CpuSlow          ; speed selection
End                  ; close the command file

example 2:
CMD:               ; header
ROM=256        ; select rom bios
:010B130002    ; poke the value 2 in 0B13h adress (screen mode of starting)
CpuSlow          ; speed selection
Text                 ; swap in text mode
PRINT"OK"

example 3:
PRINT"OK1"
|CMD               ;
going from the TEXT mode to the COMMAND mode.
ROM=256        ; select rom bios
:010B130002    ; poke the value 2 in 0B13h adress (screen mode of starting)
CpuSlow          ; speed selection
Text                ; swap in text mode
PRINT"OK2 "


It is also possible to load from a CpcAlive command file the following types of files:
virtual diskettes with format DSK , Cpc rom files , intel hex files , command files , text documents and binary files . The command files overlap is authorized with the limits of 15 files maximum (text files included). A good example is the ROM.INI file which is a command file intended for the emulator initialization. It is from this one that for example the Cpc roms are loaded. Note the separator ';' for comments. (!do not use the  "Text" mode in the file ROM.INI).The command file CPC.INI located in the CpcAlive repertory is a user file which can receive configuration commands


II - 6 - Loading text files

If the file type is not recognized by CpcAlive as being one of files detailed higher, CpcAlive considers that it is a text file. CpcAlive treats these files like this: each character of the document is read and sent to the Cpc keyboard manager. You can thus, for example, transmit by this function a BASIC file text formated or pilot a software running into the emulator.

Loading from the Dos command line:
! example.bas
Loading from a CpcAlive command file:
example.bas
Loading from the Cpc BASIC interpreter:
|input,"example.bas"

These commands load the text named "exemple.bas" through the Cpc keyboard manager. This file must be in text format. In this example it must be in the CpcAlive directory
. If the file does not exist, the chain "exemple.bas" will be transmitted to the Cpc keyboard manager and will probably cause a "Syntax error" message.

example from the Cpc BASIC interpreter:
mode 2
10 |Input,"FILE_ID.DIZ"
20 line input a$:if a$="" then |STOP:end else goto 20
run

This example load the document "FILE_ID.DIZ" until it meet one blank line. The command |STOP close the file.

The text files overlap is authorized with the limits of 15 files maximum (command files included).
It is also possible to load texts in the CpcAlive emulator with the
Windows XP copy/paste function. See instructions.


II - 7 - Loading binary files

It is possible to use the marker ":D" (like 'D'atas) to load data in the Cpc memory by using the following syntax:

from the Cpc BASIC interpreter:
|INPUT,"filename:D,block lenght,address block in file,load address in cpc memory"

from a CpcAlive command file:
filename:D,block lenght,address block in file,load address in cpc memory

Think to protect the loaded block with the command: MEMORY load_address - 1. The real size of the block loaded can be obtained with the following way:
info$=string$(16,"X"):|INFO,@info$:BlockLenght=val("&"+mid$(info$,13,4))

It is thus possible to treat any type of file. The example below load an image BMP (option OS/2 format, 16 colors, 320*200 max.) and posts it on the Cpc screen.

10 MEMORY &1FFF:adr=&2000
20 ximg=0:yimg=0:nameimg$="IMAGE.BMP":' <<<< X,Y,NOM IMAGE
30 |INPUT,nameimg$+":D,&8400,0,&2000"
40 IF PEEK(adr+&E)+256*PEEK(adr+&F)<>12 THEN MODE 2:PRINT"OS/2 format only accepted":END
50 x=PEEK(adr+&18)+256*PEEK(adr+&19)
60 largeur=PEEK(adr+&12)+256*PEEK(adr+&13)
70 hauteur=PEEK(adr+&14)+256*PEEK(adr+&15)
80 adrimg=adr+PEEK(adr+&A)+256*PEEK(adr+&B):'adresse image dans fichier
100 IF x<>4 THEN MODE 2:PRINT"16 colors in image only accepted.":END
120 MODE 1:GOSUB 190:x=0:FOR i=0 TO 15*3 STEP 3:|INK,x,PEEK(adr+&1C+i),PEEK(adr+&1B+i),PEEK(adr+&1A+i):x=x+1:NEXT
130 reste=largeur MOD 2:x=INT(largeur/2)+reste:WHILE x MOD 4 <> 0:x=x+1:WEND:larbloc=x
140 FOR i=0 TO hauteur*2 STEP 2:x=0
150 FOR j=adrimg TO adrimg+INT(largeur/2)
160 pencil=(PEEK(j) AND &F0)/16:PLOT ximg+x,yimg+i,pencil:x=x+2
170 pencil=PEEK(j) AND &F:PLOT ximg+x,yimg+i,pencil:x=x+2
180 NEXT j:adrimg=adrimg+larbloc:NEXT i:END
190 FOR i=0 TO 15:INK i,i:NEXT:RETURN:'cpc inks ordering
run


The ":D" marker alone following the file name indicates to the emulator that it must transmit the value in decimal format of each byte of the file through the Cpc keyboard manager.This function has been developed to easily treat datas from a file with the Cpc BASIC interpreter.

Here, a small program whose function is reading some bytes of ROM.INI file and print them in hexadecimal format:

10 mode 2:window#0,1,80,2,25:window#1,1,80,1,1
20 |Input,"ROM.INI:D"
30 for i=0 to 100
40 input#1,a:Print hex$(a,2)" ";
50 next i
60 |STOP
run


The command |GO, "numerical chain"[,@er% ] move the file pointer.
In this case, "
numerical chain" represent the displacement value compared to the beginning of the file. The error return parameter @er% is facultatif. If it is put, the values significance recovered in the variable er% are:
0 = ok
1 = error
(don't forget to initialize er% before the command)

example from the Cpc BASIC interpreter:
|GO,"&100"

Moves the file pointer to the position &100. The maximum value is &FFFFFFFF. The file pointer position can be write with the decimal form.



III - CpcAlive commands  from the Cpc basic interpreter:

The CpcAlive commands from BASIC interpreter must be preceded by the vertical bar " | "


|CpuFast maximum speed - [F12]
|CpuSlow speed of the Cpc computer - [F11]
|CpuSlow,speed change speed for |CpuSlow (0<speed<&FFFF)
|Sleep put the emulator on sleeping mode - [AltGr][S]
|Sleep,"message" set sleeping mode with message
|Exit leave the emulator - [Ctrl][Alt][End]
|Exit,"message" leave the emulator with message
|Command or |CMD going from the TEXT mode to the COMMAND mode.
see chapter II - 5 - Loading command files
|INPUT,
"file_name[:X]"[,@er% ]
see chapter II - Files recognized by the emulator
|RUN,
"
file_name[:X][,ADR]"[,@er%]
see chapter II - 4 - Loading assembler source files
|INFO,@info$ load the information block of the last entered file with the function |INPUT or via a CpcAlive command file. ex: |INPUT,"Disk.dsk":info$=string$(12,"X"):|INFO,@info$:PRINT info$
|UNLOCK,-rom_site_number- authorizes the writing accesses of the Z80 microprocessor in the specified ROM.
see chapter II - 2 - Loading Cpc roms files
|EJECT,"A" eject the virtual diskette present in drive A
|EJECT,"B" eject the virtual diskette present in drive B
|STOP stop the loading of a text file (see chapter II - 6 - Loading text files)
|GO,
"numerical_chain"[,@er%]
move a binary file pointer (see chapter II - 7 - Loading binary files)
|OUTPUT, "output_file"[,@er% ] change the output file name (see chapter IV)
|OUTASCDOS see chapter V - Accentued characters
|OUTASCWIN see chapter V - Accentued characters
|OUTASCOFF see chapter V - Accentued characters
|PRINT, "chains" output a character string towards the output_file.
(Command equivalent to the command PRINT#8,"chains";)
|LPRINT, "chains" output a character string towards the output_file (with carriadge return)
(Command equivalent to the command PRINT#8,"chains")
|INK,PEN,R,G,B change PEN color. Letters R,G,B représents Red,Green and Blue values (0 to 255)
ex: |INK,0,0,255,0 (change PAPER color)
ex: |INK,1,255,0,0 (change PEN 1 color)
|INKRESTORE restore originals Cpc inks.
|INKCPC standard cpc inks
|INKSOFT CpcAlive inks (inks by defect). The pallet is the same as the standard pallet Cpc but with less luminosity and values PAPER and PEN 1 are modified.
|OBMP, "filename.BMP"[,@er% ] create a file image of the Cpc screen (BMP format).
- see |OUTPUT command for error codes significance.
|DEBUG,adresse start the debugger when the Z80 processor meet the specified adress. (ram)
|DEBUG,rom,adresse start the debugger when the Z80 processor meet the specified adress. (high roms)
|DEBUGSYS,adresse do the same thing but for the Cpc bios (low rom).
|DEBUGOFF stop the debugger
|DUMP,adress initialize the dump memory first address of the debuggor
|NODEBUG prohibit the debugger
|NOSLEEP prohibit the "sleep" mode
|MAKE,
"filename.EXE"[,@er%]
create an executable environment safeguard.
(Safeguard the environment by leaving the emulator)
- see |OUTPUT command for error codes significance.
|MAKEMOVIE,
"filename.EXE"[,@er%]
create executables graphics animations.
(Safeguard the environment by leaving the emulator)
- any keyboard movement puts an end to the execution of the produced file

- see |OUTPUT command for error codes significance.
CALL 0 initialize the Cpc system - [Ctrl][Alt][Home]


notes:
- files created with commands |MAKE or |MAKEMOVIE cannot be renamed with the Dos function "rename". To rename these files, use their own intern function from the Dos system line: file_name.EXE rename:new_name or file_name.EXE ren:new_name
- to launch a file .EXE created with |MAKE or |MAKEMOVIE with Windows XP, click on the name of the program with the mouse right button and choose <properties><memory><Ems memory auto>



IV - CpcAlive commands from the Dos command line

CpcAlive [input_files[:X]] [CpcAlive commands] [Cpc commands] [>output_file]
or
! [input_files[:X]] [CpcAlive commands] [Cpc commands] [>output_file]

The Cpc commands must be placed to the end of the command line.

ex: ! PRINT"ok"
Launch the emulator with the command PRINT"ok"

Particular case:
The character  is a Dos command. CpcAlive uses thus a substitution character which is the '§' than you can obtained with the [ALT][245] keyboard sequence from the Dos command line. If you obtain another character than '§' on your screen it is not important. The most important is the [ALT][245] keyboard sequence to obtain the ascii character number 245 in the Dos command line. ex: ! §DISC launch the emulator with the command |DISC
The character  is used by Dos too. You can use the character ² or [Alt][253] to replace it. ex: ! POKE ²C000,²FF launch the emulator with the command POKE &C000,&FF
There are other reserved characters by Dos like < or > which cannot be used with Cpc commands from the Dos command line. 

By defect the Cpc printing output is done in file CPC.PRN located in CpcAlive directory. It is possible to change the name of the output file from the Dos command line by adding the character '>' to the end of the line followed the desired file name.

example:
! PRINT#8, "OK"                 output the word "OK" in the file
Cpc.prn
! PRINT#8, "OK">test.prn    output the word" OK "in the file test.prn

Only one character ' > ' before the output file name indicates to the Dos system that if the output file
name already exists, this file will be recreate virgin before receiving datas. (the old one output file with the same name being delete without notice... warning). Two characters ' > > ' before the output file indicates to the Dos system that it must preserve the file and put new data to be followed. (There does not exist at time equivalent CpcAlive command from the Cpc BASIC interpreter)

example:
! PRINT#8, "OK1":§Exit>test.prn         
output the word "OK1" in the file test.prn
! PRINT#8, "OK2":§Exit>>test.prn       
output the word "OK2" follow in the file test.prn

The result in the file test.prn gives:
OK1
OK2


It is possible to change the output file name from the Cpc Basic interpreter by typing the following command:  |OUTPUT, "FILENAME"[,@er% ]

The error return parameter @er% is facultatif. If it is put, the significance of the values recovered in the variable er% are:
0 = ok
1 = error number of parameters
3 = way not found
4 = no more handle available
5 = refused access
(don't forget to initialize er% before the command)

A small program which redirect the CATalogue output towards the output file:
10 POKE &BB5C,PEEK(&BD2D):POKE &BB5B,PEEK(&BD2C)
20 CAT
30 CALL &BD37:|DISC
RUN

note: The file CPC.PRN is cleared after each launching of the emulator by the first printing output.



V -
ACCENTUED CHARACTERS

See french or spanish documentation


VI -
BIOS AND DOS INTERRUPTIONS ACCESS TROUGH Z80

Bios and Dos interruptions are accessible with CpcAlive specifics opcodes through the emulated Z80 microprocessor and a correspondence between the Z80 and X86 registers. The table below indicates the registers correspondence established between the two processors:
Z80 registers      X86 registers
F                 >   Flags
A                 >   AL
BC               >   CX
DE               >   DX
HL               >   BX
IX                >   SI
IY                >   DI

CpcAlive adds to the Z80 new opcodes and registers named AH, BP, DS and ES corresponding to the X86 processors registers.

Example:
opcode:             mnemonics:     function:

040h, 052h        LD AH, A
          load the value of the Z80 register A in the X86 register AH
040h, 05Bh        LD A, AH          load the value of the X86 register AH in the Z80 register A
040h, 048h, xx    INT(xx)             call interruption number xx

example of macros (here for the assembler 8 bits tasm)
# define LD_AH_A         db 040h \ db 052h
# define LD_A_AH         db 040h \ db 05Bh
# define INT(xx)             db 040h \ db 048h \ db xx

example:
; ** OUTPUT PIXEL THROUGH INT 010H **
OutPix:     ld de, 12                 ; coordinate Y
                ld bc, 24                 ; coordinate X
                ld a, 0Ch                 ; FUNCTION 0CH = WRITE A GRAPHIC POINT
                LD_AH_A              ; load the value of the Z80 register A in the X86
register AH
                ld a,3                      ; color requested
                INT(010h)              ; CALL INTERRUPTION BIOS 010H
                ret

notes:
- The
Z80-X86 correspondence registers is respected with the return of the interruption.
- The standard output peripheral is always the screen.
- The cpc memory is located in the EMS memory segment.
- The Bios interruption INT 10H accept only the functions:

Function 02h // Set cursor position //
Function 03h // Read cursor position //
Function 09h // Write character with color at cursor //
Function 0Ah // Write character with color at cursor //
Function 0Bh // Set color palette //
Function 0Ch // Write graphics pixel at coordinate //
Function 0Dh // Read graphics pixel at coordinate //
Function 0Eh // Write text in teletype mode //
Function 10h - 00h // set individual palette register //
Function 10h - 02h // set all palette registers and border //
Function 10h - 07h // read palette register //
Function 10h - 09h // read palette registers and border //
Function 10h - 10h // set DAC color register //
Function 10h - 12h // set block of DAC color registers //
Function 10h - 15h // read DAC color register //
Function 10h - 17h // read block of DAC color registers //
Function 10h - 1Bh // sum color values to shades of gray //
Function
13h // Write string //

The palette registers correspond to the 16 Cpc pens. (W
ith CpcAlive, the border always correspond to the Pen 0).

The file Z80IOPix.bas located in the "EX" directory is an example using Bios interruptions. This file is a text file wich can be read with a text editor. Explanations and listing are included.
command from the Dos command line:       ! EX\Z80IOPix.bas
command from the Cpc BASIC interpreter:     |input, "EX\Z80IOPix.bas"
These commands generate functions |OPIX,X,Y,PEN and |IPIX,X,Y,@pen which respectively write and read a graphic point on the screen to the coordinates X and Y.

List of instructions available added to the Z80:

#define LD_HL_CPCSEG .db 040h\ .db 047h              ; RETURN SEGMENT ADRESS OF CPC MEMORY
#define INT(xx)                  .db 040h\ .db 048h\ .db xx   ; CALL BIOS/DOS INTERRUPTION XX
#define IN_A_DE               .db 040h\ .db 04Ah              ; IN A,(DE)  (DE refer to I/O PC system)
#define OUT_DE_A           .db 040h\ .db 04Bh              ; OUT (DE),A (DE refer to I/O PC system)
#define LD_AH_A             .db 040h\ .db 052h               ; LD AH,A
#define LD_A_AH              .db 040h\ .db 05Bh              ; LD A,AH
#define LD_BP_HL            .db 040h\ .db 05Ch              ; LD BP,HL
#define LD_HL_BP            .db 040h\ .db 05Dh              ; LD HL,BP
#define LD_DS_HL            .db 040h\ .db 05Eh              ; LD DS,HL
#define LD_HL_DS            .db 040h\ .db 05Fh              ; LD HL,DS
#define LD_ES_HL             .db 040h\ .db 060h              ; LD ES,HL
#define LD_HL_ES             .db 040h\ .db 061h              ; LD HL,ES
#define PUSHA                    .db 040h\ .db 071h              ; PUSH A,AH,BC,DE,HL,BP,IX,IY
#define POPA                       .db 040h\ .db 072h              ; POP IY,IX,BP,HL,DE,BC,AH,A


BP, DS, ES and AH correspond to the X86 processor registers. By defect registers DS and ES address the Cpc memory (Ems segment).



VII - X86 ENVIRONMENT

It is possible to program the CpcAlive emulator with X86 instructions. CpcAlive accept 256 X86 modules. A module is a .EXE or .COM program containing an installation table located to the address 0200h in the program code and a table being able to contain 128 X86 call vectors. The X86 vectors can be called from the Cpc basic interpreter or from Z80 opcodes. The maximum size of a X86 module is 64K. The installation table of a X86 module must be made up like this:

org 0200h
                db ' X86CPC'               ; 0200h mark
                dw 1                             ; 0206h version
                dw offset X86Vec          ; 0208h entry vectors table
                dw 0                             ; 020Ah reserved
                dw 0                             ; 020Ch reserved
                dw 0                             ; 020Eh reserved
                dw offset MnemoTb      ; 0210h offset names table for calls with Basic
                db -1                             ; 0212h
(*) receipt the X86 module area number
                db -1                             ; 0213h 
module complement number or bank Cpc block number
                db -1                             ; 0214h (*) reçeipt the Z80 rom number associated
                db -1                             ; 0215h indicator for Cpc banks or modules complements connection
                dw -1                             ; 0216h (*) reçeipt the first Cpc accessible adress (0=no adress accessible)
                db 0                               ; 0218h reserved
                dw 0                              ; 0219h (*) receipt the ems handle associated to the module
                dw 0                              ; 021Bh
(*) receipt the logical number of the first 16K page of the module
                db 0                               ; 021Dh
(*) receipt the number of 16K pages allocated to the module
                dw 0                              ; 021Eh adress called when the emulator exit (0=no call)
                dw 0                              ; 0220h
adress called when the emulator is put in "sleep mode" (0=no call)
                dw 0                              ; 0222h
adress called when the emulator return from "sleep mode" (0=no call)
                db 0100h-024h dup (0)   ; 0224h reserved

(*) = value generated by the system

; entry vectors table
X86Vec    dw offset program1           ; 00 1st program
                dw offset program2           ; 01 2nd program
                ;... 128 vectors maximum

; names table (mnemonics)
MnemoTb db "PROGRAM","1" or 080h          ; |PROGRAM1
                db "PROGRAM","2" or 080h          ; |PROGRAM2
                db 0


; X86 programs must be declared in "far"
program1 proc far    ; ** CALLED BY THE BASIC INSTRUCTION |PROGRAM1 **
                ;... code X86
                retf
program1 endp
program2 proc far    ; ** CALLED BY THE BASIC INSTRUCTION |PROGRAM2 **
                ;... code X86
                retf
program2 endp

Operation: With the MnemoTb vector presence to the address 0210h, the emulator generates a Z80 rom interpretable with the Cpc system integrating the names table (MnemoTb) with its X86 call vectors. The first vector of the table "X86Vec" corresponding to the first name is the initialization vector which is called with each initialization of the Cpc system. Each name corresponds to a vector of this table (in order). The end of each name is indicated with the bit 7 on the last letter of the name. The table should not exceed 128 names and must be finished by a null byte. To use a command, it will be enough to type the name preceded with the sign "vertical bar | " from the Cpc BASIC interpreter.

It is also possible also to call the X86 routines from the Cpc memory through Z80 opcodes (see below). If names are not necessary, replace the vector "MnemoTb" with a null word (address 0210h).

To call a X86 program from the Z80 memory:

The call of a X86 program from the Cpc memory is done using the opcode 049h followed module
area number, then vector number. For example if you want to call "program2" (vector number 1) in the example above, considering that the system has load the X86 module in the area 010h, that will give the Z80 opcode: 049h, 010h, 001h.

The module area number can be obtained like Z80 Roms loading:

info$=string$(16,"X"):|INFO,@info$:RomPlace=val("&"+mid$(info$,15,2)):PRINT RomPlace

This number is also indicated in the byte of address 0212h of the X86 installation table. The vector number must be between 0 and 127. If the bit 7 is set, a "RET" will be simulated after the instruction. The instruction operate then similarly than a jump instruction (JP).


The Z80 registers values are retransmitted to the X86 programs like this:
Z80 registers      X86 registers
  F                  >   Flags
  A                 >   AL
  BC               >   CX
  DE               >   DX
  HL               >   BX
  IX                >   SI
  IY                >   DI

The X86 registers describe in the preceding chapter are also transferred.
. FS and GS registers are undefined. X86 registers values returned by the program will be retransmitted to the Z80 with the same way.

Loading a module from the Dos command line: ! MODULE.COM
Loading
a module from a CpcAlive command file: MODULE.COM
Loading
a module from the Cpc BASIC interpreter: |INPUT, "MODULE.COM":call 0


Cpc memory access from X86 environment:
The Cpc computer use 128Ko of memory divided into two banks of 64Ko each one called bank 0 and bank 1. Bank 0 is consisted with four blocks of 16Ko numbered from 0 to 3. Bank 1 uses the blocks numbers 4 to 7. The emulator supplements these two banks with 248 additional blocks available thus numbered from 8 to 255. The Cpc memory access depends of the module size. Indeed, the modules are loaded and executed in the same area as the Cpc memory (Ems segment). The first accessible Cpc address 
is indicated to the address 0216h of the X86 installation table. In the case of a module using four blocks, value 0 indicates that no address are accessible.

Note: The number of blocks used by the last module loaded can be obtained with the following BASIC command:

info$=string$(18,"X"):|INFO,@info$:NbrBlocs=val("&"+mid$(info$,17,2)):PRINT NbrBlocs

It is possible to choose the bank to connect with the module using the byte
located to the address 0215h of the X86 installation table. Value -1 keeps the blocks wich was connected when the module has been called, value 0 connects bank 0 of Cpc in the blocks available, value 1 connects bank 1 of Cpc in the blocks available. For example, if we want to connect bank 1 following the module by putting value 1 in the byte located to the address 0215h of the X86 installation table, and if the first accessible Cpc address indicated is 04000h, the last three blocks of bank 1 will be connected following the module, with the next call of the module.

Value 2 in the byte located to the address 0215h of the X86 installation table connects the banks following the module by indicating the number of the first block of the bank to be connected in the byte located to the address 0213h of the X86 installation table. For example if one puts value 3 in the byte located to the address 0213h of the X86 installation table and if the first accessible Cpc address indicated is 04000h, blocks 3,4 and 5 of the banks 0 and 1 will be connected following the module. Value 7 in the byte located to the address 0213h of the X86 installation will connect the last block of bank 1 follow-up of the blocks 8 an 9 of the additional Ram

Value -2 in 
the byte located to the address 0215h of the X86 installation table connects the blocks of another module if this module size is higher than the size of the appealing module. The higher blocks will then be connected following the appealing module. It is enough for that to indicate the complementary module number through the byte located to the address 0213h of the X86 installation.

The emulator treats with a particular way the management of bank 0 because amongst other things the Cpc screen management. It is thus better to use the Dos system interruption 018H reprogrammed for this purpose for the writing accesses. Through this interruption, read/write accesses are possible in the totality of the memory, independently of the size of the connected module.

The AH values to transmit to acced of the various functions of this interruption are:
0 = Read the byte pointed by SI and put it in AL
1 = Write the value of the register AL in the byte pointed by DI
2 = Read the value pointed by SI and put it in the register indicated by AL:

Register to load AH BL BH CL CH DL DH AX BX CX DX SI DI BP
AL value 0 1 2 3 4 5 6 7 8 9 10 11 12 13

3 = Write the value of the register indicated by AL in the zone pointed by DI:

Register to write - BL BH CL CH DL DH - BX CX DX SI - BP
AL value - 1 2 3 4 5 6 - 8 9 10 11 - 13



The file X86IOPix.asm located in the directory "EX" is a complete example. It has generate the module X86IOPix.com in the same directory but it can also be compilated in .EXE format
.
command from the Dos command line:
       ! EX\X86IOPix.com
This command generates functions |OPIX,X,Y,PEN and |IPIX,X,Y,@PEN which respectively write and read a graphic point on the screen with coordinates X and Y. The file X86IOPix.bas located in the same repertory is an example wich use this module functions.


notes:
- The Bios interruption INT 10H accept only the functions described in the preceding chapter.
- The standard output peripheral is always the screen.
- If it is not necessary that the module be initialized by its first vector when the Cpc system start, it is possible to use the marker ":W" (Waggon) following the module name. The emulator will then load vectors and mnemonics of the module in the Z80 rom generated by the preceding module. One will use less Z80 roms areas. (if there was no module loaded previously, the emulator created a first vector "without effect" in the Z80 Rom associated).



VIII - UTILITY SOFTWARES

- 1 - CreaDisc: create a virgin virtual diskette (data formatted).

Command from the Dos command line:
 ! CreaDisc

- 2 - Extract: extract files from virtual diskettes.

Command from the Dos command line: Extract [diskette_name] [file_name]




* People who wish to take part can post their work here: or make a free gift here (French Handicaped People Christian Office). Thank you.