CODINGANTOINE ★ ASSEMBLEUR Z80 - Les codes spéciaux ★

Z80: Les Codes Speciaux (2/2)Coding Antoine
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

You remember MMPF #5 ? It included a big article about the special instructions offered by the Z80. But the part about the codes beginning with #ED must be updated 'cause l've found some errors in my codes-table. So is there the new codes-table:

01 2 3 4 5 67
4IN B,
(C)
OUT
(C),B
SBC
(ADR),BC
LD
HL,BC
NEGRETNIM 0LD I,A
5IN D,
(C)
OUT
(C),D
SBC
HL,DE
LD
(ADR),DE
*NEG*RETNIM 1LD A,I
6IN H,
(C)
OUT
(C),H
SBC
HL,HL
LD
(ADR),HL
*NEG*RETN*RESETRRD
7*IN F,
(C)
*NOPSBC
HL,SP
LD
(ADR),SP*
NEG*RETN*NOP *NOP
89ABCDEF
4IN C,
(C)
OUT
(C),C
ADC
HL,BC
LD
BC,(ADR)
*NEGRETI*NOP ?LD R,A
5IN E,
(C)
OUT
(C),E
ADC
HL,DE
LD
DE,(ADR)
*NEG*RETIIM 2LD A,R
6IN L,
(C)
OUT
(C),L
ADC
HL,HL
LD
HL,(ADR)
*NEG*RETI*RESETRLD
7IN A,
(C)
OUT
(C),A
ADC
HL,SP
LD
SP,(ADR)
*NEG*RETI*RESET*NOP

The main modification concerns the IO instructions: you can see that there is an instruction named IN F,(C) !! As you can guess, its function is to import a value from the IO port adressed by BC and put it into the Flags register. So you can test some bits without using BIT or AND if this bit is at the position of one of the four testable flags (S,Z,V,C). For example, to wait for VSync, you can make:

LD B,#F5
VBL IN F,(C)
JR NC,VBL

But, you will tell me, what use can be those special codes, except of these garbage-tricks ? Well, it will help you if you wanna build your own protections or... crack (OH !!!) other ones. A typical example is the loader of Super Cauldron (Elmsoft's new game). It begins with:

#2FD1 LD HL,#3000
#2FD4 LD BC,#500
#2FD7 LD IX,#1234
#2FDB DI
#2FDC XOR A
#2FDD LD R,A
#2FDF LOOP *INC IXL
#2FE1 LD A,R
#2FE3 *XOR IXH
#2FE5 XOR (HL)
#2FE6 *DEC IXH
#2FE8 *NEG
#2FEA DEC BC
#2FEB *NEG
#2FED *XOR IXL
#2FEF XOR C
#2FF0 *INC IYL
#2FF2 LD (HL),A
#2FF3 *DEC IYH
#2FF5 INC HL
#2FF6 *INC IYL
#2FF8 LD A,B
#2FF9 *DEC IYH
#2FFB OR C
#2FFC *LD A,IYL
#2FFE JR NZ,LOOP
#3000 ...

If you don't know about the special codes, you can't decode the loader. The technique to decode it is to simulate the variations of the R register with another register (here E is used). In this case you can forget the two NEGs (who act in opposition of each other) and the IY register manipulations 'cause IY has no function in this decoding (except to increase R of 2). The solution to this decoding problem is then:

ORG #A000 ; DEC BC
LD HL,#3000 ; DEFB #DD
LD BC,#500 ; XOR L
LD IX,#1234 ; XOR C
DI ; LD (HL),A
LD E,4 ; INC HL
LOOP DEFB #DD ; LD A,E
INC L ; ADD A,32
LD A,E ; AND #7F
DEFB #DD ; LD E,A
XOR H ; LD A,B
XOR (HL) ; OR C
DEFB #DD ; JR NZ,LOOP
DEC H ; RET

And you can now disassemble the following of the loader... Simple, eh ? To

finish with the non-official Z80 instructions, I would say that you can always

order MMPF #5 to have more precisions... We're going on the assembler serial

with the second part of the arithmetical operations, which is (excuse me, but the rest is in French)...

CB 30 CB 31 CB 32 CB 33 CB 34 CB 35 CB 36 CB 37
SLI B SLI C SLI D SLI E SLI H SLI L SLI (HL) SLI A
DD CB 36 dis FD CB 36 dis et n'oubliez pas que 'dis'
SLI (IX+dis) SLI (IY+dis) est un nombre signé...

Antoine / POW pour MM&PF

★ ANNÉE: ???
★ AUTEUR: ANTOINE

Page précédente : Z80: Les Codes Speciaux (1/2)

★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Coding » Z80: La division
» Coding » Clefs2 50 - Amsdos - Ouverture Fantome d'un Fichier
» Coding » Z80: La Multiplication
» Coding » Cours et Initiation par Antoine / POW
» Coding » Z80: Les Codes Speciaux (1/2)
Je participe au site:

» Vous avez remarqué une erreur dans ce texte ?
» Aidez-nous à améliorer cette page : en nous contactant via le forum ou par email.

CPCrulez[Content Management System] v8.7-desktop/c
Page créée en 291 millisecondes et consultée 2544 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.