You are on page 1of 65

COE2009-24

Z80 CPU(Java)

493041143-4
493041147-6

Project Report No. COE2009-24

Z80 Simulator (Java)

By
Mr. Worapot Sommool
Mr. Sasawat Paresrisakul

I.D. 493041143-4
I.D. 493041147-6

This is the report of fourth year project assignment submitted in partial


fulfillment of the requirement for the degree of Bachelor of Engineering.

Department of Computer Engineering


Faculty of Engineering Khon Kaen University

Z80 CPU(Java)

493041143-4
493041147-6

.......................................
(. )

1. ........................................
(. )
2. ........................................
(. )

17 2553

Z80 CPU Z80


User Interface Platform ( Windows, Linux ,Mac Os )
simulator, assembler, disassembler, system call and I/O port
Z80 8 bits Zilog

Abstract
Z80 Simulator is java-base application that allows Z80 educators and developers with
user-interface environment for multi-platforms (Linux, Window, Mac OS) with integrated
simulator, assembler, disassembler, system call and I/O port for Zilog Z80 8 bits
microprocessor.

Abstract

1
1.1
1.2
1.3
1.4
1.4.1
1.4.2
1.4.3
1.4.4 Z80 simulator (java)
1.4.5
1.5
2 CPU Z80
2.1 CPU Z80
2.2 CPU Z80
2.3 Z80
2.3.1 (Main Register)
2.3.2 (Alternative Register)
2.3.3
2.4 CPU Z80
2.4.1
2.4.2
2.4.3
2.4.4
2.4.5

1
1
1
2
2
2
2
2
2
2
2
3
3
5
6
6
7
7
9
9
9
9
9
10


2.4.6
2.5 Z80
2.6 Z80 Addressing Modes
2.7 Z80 CPU Z80
2.7.1 INPUT
2.7.2 OUTPUT
2.7.3 MEMORY
2.7.4
3 CPU Z80
3.1
3.2
3.2.1
3.2.2
3.2.3
3.2.4
3.2.5
3.2.6
3.3
3.3.1
3.3.2
3.3.3
3.3.4
3.4
3.4.1 SCANK
3.4.2 SCANC
3.4.3 DSEC
3.4.4 INIT_LCD
3.4.5 CLDCMD
3.4.6 GOTO_ADDR
3.4.7 WRLCD
3.4.8 LCDHEX

10
10
11
12
12
12
13
13
14
14
14
14
15
16
17
18
18
20
20
23
24
24
24
25
25
25
26
26
26
26
26


3.4.9 WR_LCD_MSG
3.4.10 CLR_LCD
3.4.11 CUR_ON
3.4.12 CUR_OFF
3.4.13 HBEEP
3.4.14 LBEEP
3.4.15 TITLE
3.5
3.5.1 Keyboard
3.5.2 LED array
3.5.3 7segment
3.5.4 speaker
3.5.1 LCD
4
4.1
4.1.1
4.1.2
4.1.3
4.2
4.2.1 light
4.2.2 test condition
4.2.3 light2
4.2.4 lcd moving
5
5.1
5.2
5.3
5.4

26
26
26
26
27
27
27
27
27
28
28
28
28
29
29
29
29
30
30
30
31
32
33
35
35
35
36
36
37
38
53

2.1 ET -BOARD V4 Z80 CPU


2.2 Z80 CPU
2.3 Z80 CPU
2.4 Keyboard Z80 ET -BOARD V4
2.5 LCD Z80 ET -BOARD V4
2.6 7segment Z80 ET -BOARD V4
2.7 LED array Z80 ET -BOARD V4
2.8 Speaker Z80 ET -BOARD V4
2.9 RS232 connector Z80 ET -BOARD V4
2.10 34 pin 40 pin I/O port Z80 ET -BOARD V4
3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8
3.9
3.10
3.11
3.12
3.13
3.14 SCANK
3.15 SCANC
3.16 DSEC
3.17 LBEEP
3.18 window key board
3.19 GUI led array

3
5
6
12
12
12
12
13
13
13
14
15
16
17
20
21
22
22
22
23
23
24
24
25
25
25
27
27
28


3.20 GUI 7segment
3.21 GUI speaker
3.22 GUI LCD
4.1 Pair Programming
4.2
4.3 light
4.4 light
4.5 test condition
4.6 test condition
4.7 light2
4.8 light2
4.9 lcd moving
.1
.2 menu bar
.3 menu bar
.4 menu bar
.5 toolbar
.6 toolbar
.7 toolbar
.8 File menu bar
.9 File
.10 run mode step
.11 run mode slow
.12 run mode fast
.13 run toolbar
.14 run menu bar
.15 pc
.16 break toolbar
.17 break menu bar
.18 reset
.19 SCANK

28
28
28
29
29
30
31
31
32
32
33
33
38
39
39
40
40
41
41
42
42
43
43
43
44
44
44
45
45
46
46


.20 SCANC
.21 DSEC
.22 dump_memory
.23
.24 edit menu bar
.25 edit_register
.26 edit_ memory
.27 LED array
.28 7 segment
.29 LCD
.30 Speaker

47
48
49
49
50
50
51
51
51
52
52

1.1
2.1
2.2
2.3
2.4
2.5
2.6
4.1

Z80 ET-Board V. 4.0


Flag register Z80 CPU
Flag register

16 bit Register Z80 CPU


Addressing Mode Z80 CPU

2
4
7
7
7
9
11
34

1.1
Microprocessor

Microprocessor
Embedded Engineer
Microprocessor
Microprocessor CPU Z80 ET-Board
( 2) programming
execution time machine cycle Z80 simulator
Microprocessor Z80 Z80 simulator DOS
Z80simulator
system call
Graphic User Interface
I/O port
platform
Microprocessor Z80

1.2
1. ET-Board

2. ET-Board
3. user interface
4. system call
I/O port

1.3
Z80 simulator Z80 ET Board
Z80 simulator system call Z80 simulator
I/O port

1.4
1.4.1
Z80 CPU

1.4.2
Engine Z80
CPU
1.4.3
Engine

1.4.4 Z80 simulator (java)

1.4.5

1.1

1.5
Z80 simulator CPU Z80 ET - Board
microprocessor Z80

2
CPU Z80
2.1 CPU Z80
CPU Z80

CPU Z80

memory, lcd, keyboard , rom, clock, speaker, led flag ET -BOARD V4
2.1 CPU CPU
Z80 ET -BOARD V.4 2.1

2.1 ET -BOARD V.4 Z80 CPU

4
2.1 Z80 ET-Board V. 4 [7]

CPU
CLOCK
EPROM
RAM
Expansion
Memory
Expansion
Socket
DISPLAY

ET-Board V.4

Z80A
4MHZ
32K BYTE EPROM MONITOR PROGRAM
8K BYTE RAM ON BOARD(6264)
32K BYTE RAM/EPROM(2764,27128,27256,6264,62286)(OPTION)
RTC(REAL TIME CLOCK) 6242 (OPTION)

LCD MODULE 16 1 7-SEMENT


LED 8 BIT LED FLAG
KEY BOARD 32 KEY 1 KEY RESET, 1 KEY BREAK INTERRUPTS
SERIAL PORT RS232 PORT PC DEBUGGER
COMPUTER
SPEAKER
2 D to A 8
BIT
24 BIT BIDIRECTION PARALLEL I/O(8255)
34 PIN I/O PORT
TTL INPUT/OUTPUT TOOL
32 FUNTION
ASSEMBLY CODE
10 TOOL
10 GAME GAME
REMOTE DEBUGGER PC PORT RS-232

2.2 CPU Z80


Z80 8 8 16
, I/O Z80 64KB (8 = 1
, 1024 = 1 [KB]) I/O 256 (0-255)
Z80[4] 2.2

2.2 Z80 CPU


ALU (Logic) IR
buffer (memory) Shifter
Decode/Control
ALU/Shifter Flag
ALU/Shifter Register CPU

z80 3
1. Fetch IR
2. Decode Z80
Fetch PC

3. Execute Z80
Z80 ALU flag
1 halt Z80

2.3 Z80
(Register)
Z80[4]
208 2 8
18 16 4 3
2.3

2.3 Z80 CPU [6]


2.3.1 (Main Register)
A,B,C,D,E,H,L F 8
AF,BC,DE,HL 16 CPU
2 A ::
Accumulator F :: Flag Register Accumulator A 8
(Arithmetic/ Logic Unit; ALU)
8 ALU
Flag Register F 8 Z80
ALU 6 F set/reset

7
A AF 16 A Flag
F Flag Register
2.2 Flag register Z80 CPU

7 6 5 4 3 2 1 0
Flag register S Z x H x P/V N C

2.3 Flag register [4]


S

sign flag

zero flag

half carry flag

P/V

parity/overflow

add/subtract

carry flag

0 7 0
1 7 1
0 0
1 0
0 / -
1 / -
0 overflow
1 overflow
0 1
1 1
0 add
1 subtract
0 / 7 15
1 / 7 15

sign number

overflow (
signed number)
parity

8 16

2.3.2 (Alternative Register)




8 A, B, C, D, E, H, L F
2.4

A
F
B
C
D
E
H
L

A
F
B
C
D
E
H
L

2.3.3 [6]
Program counter (PC) 16
fetch fetch
CPU
CPU

8
(Jump)

Stack pointer (SP) 16


stack RAM stack
(last in first out) stack push pop CPU
stack interrupt
interrupt stack
interrupt stack
interrupt

Index Register IX,IY CPU Z-80 Index 16 2
(base address) index
addressing index address Index
8
displacement 2s complement
Interrupt page address register (I) Z-80
Z-80

8

Memory refresh register


static dynamic Z-80
R
1 fetch R

R

9
2.5 16 bit Register Z80 CPU[4]
IX
IY
SP
PC
I R

Index Register 1 Memory


Index Register 2
Stack Pointer
Program Counter
R = Refresh Register
I = Interrupt Vector

2.4 CPU Z80


(Instruction Set) Z80 6 [1] 158
8080 (78 )[2][3]
2.4.1
1. 8 16 LD A,10H
A 10H
2. 2 EX DE,HL DE
HL
3. block transfer
LDI
4. IN A,(n)
2.4.2
1. 8
2.
3. 8
4. 16
5. 16
6. A
2.4.3
3 AND, OR, XOR 8
2.4.4
1.
2.
3.

10
2.4.5
1.
2.
3.
2.4.6
2 HALT , NOP

2.5 Z80
(Mnemonic operation code
opcode) (operand)
LD = LOAD SUB = SUBTRACT
OUT(10H),A
A(Accumulator) output port 10H Z80 3
1. byte
2. byte
3. 10H
Z80 4
1-byte instructions
LD A, B
0111 1000 (78H)
2-byte instructions
Byte 1
LD B, 32H
0000 0110 (06H)
Byte 2
0011 0010 (32H)
3-byte instructions
byte 1
LD BC, 2080H
0000 0001 (01H)
byte 2
1000 0000 (80H)
0010 0000 (20H)
byte 3
4-byte instructions
byte 1
LD IX, 2000H
1101 1101 (DDH)
0010 0001 (21H)
byte 2
byte 3
0000 0000 (00H)
byte 4
0010 0000 (20H)

11

2.6 Z80 Addressing Modes


operand z80 Addressing mode
10
2.6 Addressing Mode Z80 CPU
Addressing

Mode
Immediate operand 8

Immediate operand 16
Extended

Register
operand
Implied
operand
Accumulator (A)
Register

Indirect

Extended
16 Jump
Relative
operand displacement 2s complement
Indexed
Index Register
displacement 1 byte
Bit
mode

3 mode(register, register indirect,
indexed)
Page Zero 8 restart one-byte call
byte 00H
byte

LD B, 97H
LD BC, 8045H
LD B, A
AND B
LD B, (HL)
JP 2080H
JR 14H
INC (IX+10H)
SET 7, B

RST 28H

12
2.7 CPU Z80
CPU Z80 CPU Z80

2.7.1 INPUT
INPUT CPU Z80
2.4

2.4 Keyboard Z80 ET -BOARD V4


2.7.2 OUTPUT
CPU Z80 OUTPUT
2.5, 2.6, 2.7,
2.8

2.5 LCD Z80 ET -BOARD V4

2.6 7segment Z80 ET -BOARD V4

2.7 LED array Z80 ET -BOARD V4

13

2.8 Speaker Z80 ET -BOARD V4


2.7.3 MEMORY
MEMORY ROM assembler,system
function, demo RAM load CPU Z80

2.7.4

Z80 ET-BOARD V4 RS232 connector 2.9, 34 pin 40 pin I/O port
2.10

2.9 RS232 connector Z80 ET -BOARD V4

2.10 34 pin 40 pin I/O port Z80 ET -BOARD V4

14

3
CPU Z80
3.1
MICROPROCESSORS AND INTERFACING (178320)
MICROPROCESSORS AND INTERFACING LABORATORY (178321)
microprocessors CPUZ80 ET -BOARD V4 CPUZ80
CPUZ80

3.2

3.2.1
load

memory load
memory register run
register memory 3.1

3.1

15
3.2.2
memory
register , reset

3.2

3.2

16
3.2.3
run
run
memory mode
mode
fast program counter
register
3.3

3.3

17
3.2.4


3.4

3.4

18
3.2.5

1. short A,B,C,D,E,F,H,L,Ap,Bp,Cp,Dp,Ep,Fp,Hp,Lp,I,R,CY;
2. short memory[][] = new short[1][65536];
3. String nemonic[] = new String[65536];
4. short op1=0x0001,op2,op3,op4; 4 byte
5. intIX , IY, SP=0x1000, PC, PC_nemonic, st_pc;

6. int T_state; Tstate


7. byte led,segment; led array 7 segment
8. String lcd00="", lcd01="", lcd02="", lcd03="", lcd04="", lcd05="", lcd06="", lcd07="",
lcd40="", lcd41="", lcd42="",lcd43="",lcd44="",lcd45="",lcd46="",lcd47=""; byte cursor=0;
static boolean cursor_onoff=false; byte speaker=0;
LCD speaker
9. String outputnemonic[] = new String[6000]; String outputhexcode=""; String
inputfill="";
3.2.6

3.2.6.1 Instructions class Instructions 700
Instructions Z80 CPU Instructions 11

1 arithmetic_logical_8bit.java Class Instructions


8 (8 Bit Arithmetic and Logic Group)
2 arithmetic_16bit.java Class Instructions
16 (16 Bit Arithmetic and Logic Group)
3 load_8bit.java Class Instructions 8
(8 Bit Load Group)
4 load_16bit.java Class Instructions 16
(16 Bit Load Group)
5 bit_SetReset_TestG.java Class Instructions
bit

19
6 ex_bt_bs.java Class Instructions

7 rotate_shift.java Class Instructions


bit
8 call_ret.java Class Instructions
9 control.java Class Instructions

10 jump.java ClassInstructions
11 input_output.java Class Instructions
port port
3.2.6.2 Graphic User Interface
8 class 8
1 user_interface.java Class
2 gui_about.java Class
3 gui_dump_memory.java Class dump memory
memory
4 gui_editmemory.java java Class
5 gui_editreg.java java Class
6 gui_input_syscall.javaClass system call scanc scank
7 gui_inputPC.java Class program counter

8 gui_syscall_delay.java Class system call delay



3.2.6.3 Class
1 Main.java Class
Class
2 ReadHex2Memory.java Class load hex
3 runstep.java Class
opcode
4 nemonic.java Class load memory
5 flag.java Class flag register

20

3.3


3.3.1

3.5

3.5
3.5
1. (mnemonic)
2. memory
3. Z80 ET Board
4. CPU Z80
5.

21
3.3.1.1 (mnemonic)
load


3.6

3.6
3.3.1.2
load load
CPUZ80 ET-BOARD V4 load memory

ASCII
2 byte
3.7

22

3.7
3.3.1.3
CPUZ80
ET-BOARD V4 LED array, LCD, 7 segment speaker 3.8

3.8
3.3.1.4

3.9

3.9

23
3.3.1.5
load, run.
break, mode, load demo, edit register, edit memory, reset register help 3.10

3.10
3.3.2
edit register
3.11

3.11

24
3.3.3
program counter
program counter 3.12

3.12
3.3.4

byte
3.13

3.13

3.4

[5] CPUZ80
system call CPUZ80
ET-BOARD V4 system call

25
3.4.1 SCANK
scan key board
key board 2 3.14

3.14 SCANK
3.4.2 SCANC
key board A
3.15

3.15 SCANC
3.4.3 DSEC
delay B delay 1-255
3.16

3.16 DSEC

26
3.4.4 INIT_LCD
LCD
CPUZ80 ET-BOARD V4
CPUZ80 ET-BOARD V4
3.4.5 CLDCMD
set LCD D 2
cursor
3.4.6 GOTO_ADDR
LCD
D
3.4.7 WRLCD
ASCII LCD cursor
D
3.4.8 LCDHEX
16 LCD cursor
D
3.4.9 WR_LCD_MSG
memory HL
LCD
3.4.10 CLR_LCD
LCD cursor

3.4.11 CUR_ON
cursor LCD
3.4.12 CUR_OFF
cursor LCD

27
3.4.13 HBEEP

3.17

3.17 LBEEP
3.4.14 LBEEP

HBEEP
3.4.15 TITLE

HBEEP

3.5
CPU Z80 ET-BOARD V4
CPU Z80
ET-BOARD V4
3.5.1 key board
key board
system call
key board CPU Z80 ET-BOARD V4 mouse
3.18

3.18 window key board

28
3.5.2 LED array
8 port 40 3.19
3.19 GUI led array
3.5.3 7segment
port 60
3.20

3.20 GUI 7segment


3.5.4 speaker

3.21

3.21 GUI speaker


3.5.5 LCD
16
LCD 3.22

3.22 GUI LCD

29

4.1

4.1.1
2 Pair Programming

4.1

4.1 Pair Programming


4.1.2
engine
Graphic User Interface 3.1

4.2

30
4.1.3
1. , (Memory)
2. I/O Port
3. System Call
4. running , step
5. GUI

4.2

(demo)

4.1
4.2.1 light
LED array
bit [5]
4.2.1.1 light
demo File Load_demo
DEMO_0.hex run 4.3

4.3 light

31
4.2.1.2 light
LED array
4.4

4.4 light
4.2.1.3 light
8 bit load group, 16 bit load group, 8 bit
arithmetic and logical group, 16 bit arithmetic and logical group, rotate and shift group, jump
group, call and return group, input and out put group

4.2.2 test condition



[5]
4.2.2.1 test condition
demo File Load_demo
DEMO_1.hex run 4.5

4.5 test condition

32
4.2.2.2 test condition
system call scanc
4 LED
array 4.6

4.6 test condition


4.2.2.3 test condition
8 bit load group, 16 bit load group, 8 bit
arithmetic and logical group, 16 bit arithmetic and logical group, rotate and shift group, jump
group, call and return group, input and out put group
flag register

4.2.3 light2
memory [5]
4.2.3.1 light2
demo File Load_demo
DEMO_2.hex run 4.7

4.7 light2

33
4.2.3.2 light2
LED array
4.8

4.8 light2
4.2.3.3 light2
8 bit load group, 16 bit load group, 8 bit
arithmetic and logical group, 16 bit arithmetic and logical group, rotate and shift group, jump
group, call and return group, input and out put group

4.2.4 lcd moving


LCD
[5]
4.2.4.1 lcd moving
demo File Load_demo
DEMO_2.hex run 4.9

4.9 lcd moving

34
4.2.4.2 lcd moving
LCD
COMPUTER--DESIGNBY ETT-TEAM WORK
4.2.4.3 lcd moving
8 bit load group, 16 bit load group, 8 bit
arithmetic and logical group, 16 bit arithmetic and logical group, rotate and shift group, jump
group, call and return group, input and out put group byte

4.1

light

LED array

test condition LED array LED array

LCD


LCD
systemcall

LED array

light2

LED array

LED array

lcd moving

LCD


LCD

35

5.1
6
(GUI)
Z80 CPU
Z80 CPU
Windows, Linux, Mac OS
Z80 CPU 700 ET-Board
(Memory)
I/O Port 7 segment, LCD, LED Array Speaker mode 3
(Step) (Slow) (Fast)
ET-Board
Z80 CPU
ET-Board

5.2
1. unsigned

2. (Graphic User Interface)

3. real time JVM (Java Virtual


Machine)
CPU

36

5.3

(Requirement)

5.4
1. IO Port
ET-Board
2. real time
ET-Board
3. System call
4.
ET-Board

37

38

.1

.1
1. (mnemonic)
2. memory
3. Z80 ET Board
4. CPU Z80
5.
** Z80 ET Board

39

Load file
3
1. menu bar File Load
file (.hex) .2

.2 menu bar
file (.hex) file (.hex)
Open Load file Cancel X
.3

.3 menu bar

40
Load file memory
code (.hex) run .4

.4 menu bar
2. toolbar load toolbar load file file
(.hex) .5

.5 toolbar
file (.hex) file (.hex)
Open Load file Cancel X
.6

41

.6 toolbar
Load file memory
code (.hex) run .7

.7 toolbar
3. Flie menu bar File
Load_demo file_demo (.hex)
.8

42

.8 Flie menu bar


file_demo (.hex) file_demo (.hex)
Open Load file Cancel X
.9

.9 Flie

Run
run
run 3

1. Mode Step

43
Fast Step
Step .10

.10 run mode step


2. Mode Slow
run
1 0.5

Slow Slow .11

.11 run mode slow


3. Mode Fast

Fast
Fast
Fast .12

.12 run mode fast

44
run run 2
1. Toolbar .13

.13 run toolbar


2. menu bar .14

.14 run menu bar


run
memory
.15

.15 pc

45

Break

.16 .17

.16 break toolbar

.17 break menu bar


run
Run

Reset
reset run load(.hex)

run Reset_register reset


reset memory .18 run Run

46

.18 reset

System call [5]


System call Z80 ET Board
LCD, speaker, keyboard, delay time
System call
SCANK (02H)
scan keyboard 1 return ASCII register A
return 0FFH scan keyboard 2
.19

.19 SCANK

47
SCANC (03H)
scan keyboard routine
return register A
.20

.20 SCANC
INIT_LCD (0AH)
LCD
CLDCMD (0BH)
set cursor register D
GOTO_ADDR (0DH)

WRLCD (0EH)
ASCII register D LCD
LCDHEX (14H)
HEX register D LCD cursor
WR_LCD_MSG (16H)
LCD memory HL
CLR_LCD (17H)
Clear LCD cursor
CUR_ON (18H)
cursor LCD

48
CUR_OFF (19H)
cursor LCD
DSEC (2FH)
1 255 register B
.21

.21 DSEC
HBEEP (4CH)
BEEP
LBEEP (4DH)
BEEP
TITLE (4EH)
TITLE

Dump memory
dump memory memory

dump_ memory load
dump memory memory load
.22

49

.22 dump_memory
memory dump memory
dump run
dump dump break reset register( memory reset )
halt dump_memory
dump .23

.23

50

Edit
Edit run register memory
edit load run break
edit .24

.24 edit menu bar


edit_register .25

.25 edit_register

51
edit_memory
.26

.26 edit_ memory

I/O Port
I/O Port

LED array
port 40H .27

.27 LED array


7 segment
port 60H .28

.28 7 segment

52
LCD
system call .29

.29 LCD
Speaker
system call .30

.30 Speaker

53

1. Z-80 [] 4 2551
[ 10 2552]
http://www2.ltc.ac.th/microprocessor/theory/instruction_index.html
2. Z-80 [] 30 2551 [ 10 2552]
http://www.cpe.ku.ac.th/~yuen/204323/z80/inst_main.html
3. . . :
; 2548
4. 2 Z80 Z80 [] 20 2543 [ 5
2553] http://www.ett.co.th/article/z80/2000-002-learnz80-002.html
5. ETT. USER S MANUAL ET-BOARD V4.0. ;2535
6. CPU Z80 [] 26 2553 [ 5 2553]
http://web.ku.ac.th/schoolnet/snet1/hardware/z80/z80.html
7. ET-BOARD V.4.0 [] 4 2543 [ 5 2553]
http://www.ett.co.th/product/01A02.html

You might also like