axx で、Z80のハンドリング hello world

axx で、Z80のハンドリングをします。

Z80のISAをフルカバーしたパターンファイルを付けておきます。

```z80.axx
/*
/* z80.axx z80 patternfile
/*
DEC	IY			::				0xfd,0x2b
DEC	IX	     	::				0xdd,0x2b
INC	IY			::				0xfd,0x23
INC	IX			::				0xdd,0x23

.setsym ::BC:: 0
.setsym ::DE::0x10
.setsym ::HL::0x20
.setsym ::SP:: 0x30
INC	r			::				0x03|r
DEC	r			::              0xb|r

.setsym	::B	::0
.setsym	::C	::1
.setsym	::D	::2
.setsym	::E	::3
.setsym	::H	::4
.setsym	::L	::5
.setsym	::A	::7
INC x               ::          0x04|x<<3
DEC x               ::          0x15|x<<3

INC (HL)            ::          0x34
DEC (HL)            ::          0x35

DEC	(IY[[+!d]])		::		    0xfd,0x35,d
INC	(IY[[+!d]])		::		    0xfd,0x34,d
DEC	(IX[[+!d]])		::		    0xdd,0x35,d
INC	(IX[[+!d]])		::		    0xdd,0x34,d


.setsym	::BC::	0
.setsym	::DE::	1
.setsym	::HL::	2
.setsym	::SP::	3
.setsym	::AF::	3
ADD	HL,s			::			s<<4|0x09
ADC	HL,s			::  		0xed,s<<4|0x4a
SBC	HL,s			::			0xed,s<<4|0x42
ADD	IX,s			::			0xdd,0x09|s<<4
ADD	IY,s			::			0xfd,0x09|s<<4
INC	s				::			s<<4|0x03
DEC	s				::			s<<4|0x0b

LD	(IY[[+!d]]),s  	::		0xfd,s|0x70,d
LD	(IX[[+!d]]),s	::		0xdd,s|0x70,d
LD	s,(IX[[+!d]])    ::	   	0xdd,0x46|(s<<3),d
LD	s,(IY[[+!d]])	::	    0xfd,0x46|(s<<3),d
LD	(HL),s			:: 		s|0x70
LD	s,(HL)			::     	(s<<3)|0x46

LD	(HL),!d	    	::		0x36,d
LD	(IY[[+!e]]),!d	::		0xfd,0x36,e,d
LD	(IX[[+!e]]),!d	::		0xdd,0x36,e,d

LD	A,(BC)			::		        0xa
LD	A,(DE)			::		0x1A
LD	(BC),A			::		0x02
LD	(DE),A			::		0x12
LD	A,(!n)			::               0x3a,n&0xff,n>>8
LD	(!n),A			::			    0x32,n&0xff,n>>8


LD	HL,(!d)			::	    0x2a,d&0xff,d>>8
LD	IX,(!d)			::		0xdd,0x2a,d&0xff,d>>8
LD	IY,(!d)			::		0xfd,0x2a,d&0xff,d>>8

LD	(!d),HL			::		0x22,d&0xff,d>>8
LD	(!d),IX			::		0xdd,0x22,d&0xff,d>>8
LD	(!d),IY			::		0xfd,0x22,d&0xff,d>>8

LD	SP,HL			::			0xf9
LD	SP,IX			::			0xdd,0xf9
LD	SP,IY			::			0xfd,0xf9
LD	A,I				::		0xed,0x57
LD	A,R				::		0xed,0x5f
LD	I,A				::		0xed,0x47
LD	R,A				::		0xed,0x4f
LD	IX,!d			::		0xdd,0x21,d&0xff,d>>8
LD	IY,!d			::		0xfd,0x21,d&0xff,d>>8
LD	HL,!d			::		0x21,d&0xff,d>>8
LD	DE,!d			::		0x11,d&0xff,d>>8
LD	BC,!d			::		0x01,d&0xff,d>>8
LD	SP,!d			::		0x31,d&0xff,d>>8
LD	HL,!d			::		0x21,d&0xff,d>>8
LD  s,t				::		0x40|(s<<3)|t
LD  s,!d			::		(s<<3)|0x6,d

PUSH	s			::		0xc5|(s<<4)
PUSH	IX			::		0xdd,0xe5
PUSH	IY			::		0xfd,0xe5
POP	s				::		0xc1|(s<<4)
POP	IX 				::  	0xdd,0xe1
POP	IY				::		0xfd,0xe1

ADD	A,(HL)			::		0x86
ADD	A,(IX[[+!d]])	::	    0xdd,0x86,d
ADD	A,(IY[[+!d]])	::	    0xfd,0x86,d
ADD	A,s				::  	0x80|s
ADD	A,!d			::  	0xc6,d

ADC	A,(HL)			::		0x8e
ADC	A,(IX[[+!d]])	::	    0xdd,0x8e,d
ADC	A,(IY[[+!d]])	::	    0xfd,0x8e,d
ADC A,s             ::      0x88|s
ADC A,!d            ::      0xce,d

SUB	A,(HL)			::   	0x96
SUB	A,(IX[[+!n]])	::	    0xdd,0x96,n
SUB	A,(IY[[+!n]])	::	    0xfd,0x96,n
SUB	A,s				::  	0x90|s
SUB    A,!d         ::      0xd6,d

SBC	A,(HL)			::   	0x9e
SBC	A,(IX[[+!n]])	::		0xdd,0x9e,n
SBC	A,(IY[[+!n]])	::		0xfd,0x9e,n
SBC	A,s				::  	0x98|s
SBC	A,!d			::  	0xde,d

AND	A,(HL)		    ::		0xa6
AND	A,(IX[[+!n]])	::	    0xdd,0xa6,n
AND	A,(IY[[+!n]])	::	    0xfd,0xa6,n
AND A,s             ::      0x10|s
AND	A,!d			::  	0xe6|d

OR	A,(HL)		    ::		0xb6
OR	A,(IX[[+!n]])   ::		0xdd,0xb6,n
OR	A,(IY[[+!n]])	::	    0xfd,0xb6,n
OR  A,s             ::      0xb0|s
OR	A,!d			::		0xf6,d

XOR	A,(HL)			::	    0xae
XOR	A,(IX[[+!n]])	::	    0xdd,0xae,n
XOR	A,(IY[[+!n]])	::    	0xfd,0xae,n
XOR    A,s          ::      0x18|s
XOR	A,!d			::  	0xee,d

CP	A,(HL)  		::	    0xbe
CP	A,(IX[[+!n]])	::      0xdd,0xbe,n
CP	A,(IY[[+!n]])   ::	    0xfd,0xbe,n
CP  A,s             ::      0xb8|s
CP	A,!d		    ::		0xfe,d

BIT !x,s			::	    0xcb,0x40|x<<3|s
BIT	!x,(HL)			::	    0xcb,0x46|x<<3
BIT	!x,(IX[[+!d]])	::      0xdd,0xcb,d,0x46|x<<3
BIT	!x,(IY[[+!d]])	::	    0xfd,0xcb,d,0x46|x<<3

SET	!x,s			::	    0xcb,0xc0|x<<3|s
SET	!x,(HL)		    :: 	    0xcb,0xc6|x<<3
SET	!x,(IX[[+!d]])	::       0xdd,0xcb,d,0xc6|x<<3
SET	!x,(IY[[+!d]])	::	    0xfd,0xcb,d,0xc6|x<<3

RES	!x,s			::		0xcb,0x80|x<<3|s
RES	!x,(HL)			::	        0xcb,0x86|x<<3
RES	!x,(IX[[+!d]])	::	        0xdd,0xcb,d,0x86|x<<3
RES	!x,(IY[[+!d]])	::	        0xfd,0xcb,d,0x86|x<<3

RLCA				::			0x07
RLA					::			0x17
RRCA				::			0x0f
RRA					::			0x1f

RLC	(HL)			::			0xcb,0x06
RLC	(IX[[+!d]])		::			0xdd,0xcb,d,0x06
RLC	(IY[[+!d]])		::			0xfd,0xcb,0x00,0x06
RLC	s				::			0xcb,s

RL	(HL)			::    		0xcb,0x10
RL	(IX[[+!d]])		::			0xdd,0xcb,d,0x10
RL	(IY[[+!d]])		::			0xfd,0xcb,d,0x10
RL		s			::			0xcb,0x10|s

RRC	(HL)			::			0xcb,0xe
RRC	(IX[[+!d]])		::			0xdd,0xcb,d,0x0e
RRC	(IY[[+!d]])		::			0xfd,0xcb,d,0x0e
RRC	s				::			0xcb,0x08|s

RR		(HL)		::			0xcb,0x1e
RR		(IX[[+!d]])	::		    0xdd,0xcb,d,0x1e
RR		(IY[[+!d]])	::			0xfd,0xcb,d,0x1e
RR		s			::			0xcb,0x18|s

SLA		(HL)		::			0xcb,0x26
SLA		(IX[[+!d]])	::		    0xdd,0xcb,d,0x26
SLA		(IY[[+!d]])	::			0xfd,0xcb,d,0x26
SLA		s			::			0xcb,0x20|s

SRA		(HL)		::			0xcb,0x2e
SRA		(IX[[+!d]])	::		    0xdd,0xcb,d,0x2e
SRA		(IY[[+!d]])	::			0xfd,0xcb,d,0x2e
SRA		s			::			0xcb,0x28|s

SRL		(HL)		::			0xcb,0x3e
SRL		(IX[[+!d]])	::		    0xdd,0xcb,d,0x3e
SRL		(IY[[+!d]]) ::			0xfd,0xcb,d,0x3e
SRL     s           ::          0xcb,0x38|s

DAA					::			0x27
CPL					::			0x2f
NEG					::			0xed,0x44
CCF					::			0x3f
SCF					::			0x37
NOP					::			0x00
HALT				::			0x76
DI					::		0xf3
EI					::		0xfb
IM		0			::			0xed,0x46
IM		1			::			0xed,0x56
IM		2			::			0xed,0x5e

EX		DE,HL		::			0xeb
EX		AF,AF'		::			0x08
EXX					::			0xd9
EX		(SP),HL		::	    0xe3
EX		(SP),IX		::	    0xdd,0xe3
EX		(SP),IY		::	    0xfd,0xe3

LDI				::				0xed,0xa0
LDIR			::				0xed,0xb0
LDD				::				0xed,0xa8
LDDR			::				0xed,0xb8
CPI				::				0xed,0xa1
CPIR			::				0xed,0xb1
CPD				::			    0xed,0xa9
CPDR			::				0xed,0xb9

RLD				::				0xed,0x6f
RRD				::				0xed,0x67

IN	A,(!n)		::				0xdb,n
IN	s,(C)		::				0xed,0x40|s<<3
INI				::				0xed,0xa2
INIR			::				0xed,0xb2
IND				::				0xed,0xaa
INDR			::				0xed,0xba
OUT	(!n),A		::		        0xd3,n
OUT	\(C\),s		::			    0xed,0x41|s<<3
OUTI			::				0xed,0xa3
OTIR			::				0xed,0xb3
OUTD			::				0xed,0xab
OTDR			::				0xed,0xbb


.setsym	::NZ::	    0
.setsym	::Z	::  	1
.setsym	::NC::	    2
.setsym	::C	::  	3
.setsym	::PO::	    4
.setsym	::PE::  	5
.setsym	::P	::	    6
.setsym	::M	::	    7

JP		(HL)	::				0xe9
JP		(IX)	::				0xdd,0xe9
JP		(IY)	::				0xfd,0xe9
JP		s,!d	::	    		0xc2|s<<3,d&0xff,d>>8
JP		!d		::				0xc3,d&0xff,d>>8
JR		NZ,!e	::				0x20,e-2
JR		Z,!e	::	     		0x28,e-2
JR		NC,!e	::				0x30,e-2
JR	    C,!e	::	         	0x38,e-2
JR		!e		::				0x18,e-2
DJNZ	!e		::				0x10,e-2

CALL	s,!d	::			0xc4|s<<3,d&0xff,d>>8
CALL	!d		::				0xcd,d&0xff,d>>8
RET	s			::			0xc0|s<<3
RET				::			0xc9
RETI			::				0xed,0x4d
RETN			::				0xed,0x45
RST	!d			::		    0xc7|(d//8)<<3

```

##### z80 hello world

```z80hw.s
    .org 0x100  ; プログラムの開始アドレス

start:
    ld de, message  ; メッセージのアドレスをDEレジスタにロード
    ld c, 9         ; DOS関数9（文字列出力）
    call 5          ; DOSファンクションコール

    ld c, 0         ; DOS関数0（プログラム終了）
    call 5

message:
    .ascii "Hello World!$"  ; 終端文字$付きの文字列

```

##### assemble

```
0000000000000000 z80hw.s 1     .org 0x100  ; プログラムの開始アドレス 
0000000000000100 z80hw.s 2  
0000000000000100 z80hw.s 3 start: 
0000000000000100 z80hw.s 4     ld de, message  ; メッセージのアドレスをDEレジスタにロード  0x11 0x0d 0x01
0000000000000103 z80hw.s 5     ld c, 9         ; DOS関数9（文字列出力）  0x0e 0x09
0000000000000105 z80hw.s 6     call 5          ; DOSファンクションコール  0xcd 0x05 0x00
0000000000000108 z80hw.s 7  
0000000000000108 z80hw.s 8     ld c, 0         ; DOS関数0（プログラム終了）  0x0e 0x00
000000000000010a z80hw.s 9     call 5  0xcd 0x05 0x00
000000000000010d z80hw.s 10  
000000000000010d z80hw.s 11 message: 
000000000000010d z80hw.s 12     .ascii "Hello World!$"  ; 終端文字$付きの文字列  0x48 0x65 0x6c 0x6c 0x6f 0x20 0x57 0x6f 0x72 0x6c 0x64 0x21 0x24
000000000000011a z80hw.s 13  
```