Programming Z80

For anything related to sound (YM2612, PSG, Z80, PCM...)

Moderator: BigEvilCorporation

Post Reply
ob1
Very interested
Posts: 463
Joined: Wed Dec 06, 2006 9:01 am
Location: Aix-en-Provence, France

Programming Z80

Post by ob1 » Wed Dec 06, 2006 10:30 am

Hope it helps.
I have managed to run the Z80. sega16 (www.sega-16.com) says EA has done it with LHX and M1 Abrahams. So, here it is.
First of all, you write a program for the Z80, let's say a loop that increment a value 15 times :

Code: Select all

	LD	A,15		; ...
	LD	(402h),A	; int *counter = 0x402;
				; *n = 15;
	JR	Z,18h		; if (zero) goto end
	LD	A,(400h)	; int *value = 0x400;
	INC	A		; *value++;
	LD	(400h),A	; 
	LD	A,(402h)	; 
	DEC	A		; counter--;
	LD	(402h),A
	JP	2h
end:
	HALT
Assemblying it, you get :

Code: Select all

3E0F		; 0000	LD	A,15
320204	; 0002	LD	(402h),A
281800	; 0005	JR	Z,18h
3A0004	; 0008	LD	A,(400h)
3C		; 0011	INC	A
320004	; 0012	LD	(400h),A
3A0204	; 0015	LD	A,(402h)
3D		; 0018	DEC	A
320204	; 0019	LD	(402h),A
C30200	; 0022	JP	2h
76		; 0025	HALT
0
Then, you insert it into your 68k code :

Code: Select all

z80:
	dc.b	$3E,$0F		; 0000	LD	A,15
	dc.b	$32,$02,$04	; 0002	LD	(402h),A
	dc.b	$28,$18,$00	; 0005	JR	Z,18h
	dc.b	$3A,$00,$04	; 0008	LD	A,(400h)
	dc.b	$3C		; 0011	INC	A
	dc.b	$32,$00,$04	; 0012	LD	(400h),A
	dc.b	$3A,$02,$04	; 0015	LD	A,(402h)
	dc.b	$3D		; 0018	DEC	A
	dc.b	$32,$02,$04	; 0019	LD	(402h),A
	dc.b	$C3,$02,$00	; 0022	JP	2h
	dc.b	$76		; 0025	HALT
	dc.b	$0
Our Z80 code is ready. Now, you just got to put a value in the Z80 memory, at address 0x400, and let the good old 8-bit make his job. Wait, cook, hold on. Then, you come back and suprise : the value has been incremented !!! The 68k hasn't made any effort !!!

Here's how to load the program :

Code: Select all

	move.w	#$0100,$A11200	; Stop the RESET Z80 process
	move.w	#$0100,$A11100	; Request the Z80 Bus

	lea	z80,a2		; Load program. label z80 has been declared above
	moveq	#25,d0      ; d0 = program length
	move.l	#$A00000,a3 ; a3 = start of z80 memory
loop_z80:
	move.b	(a2)+,(a3)+ ; copy program
	dbra	d0,loop_z80

	move.w	#$0000,$A11200	; Start the RESET Z80 process
	move.w	$A11200,d0         ; d0 wil watch is the Z80 RESET process is over
wait_z80_reset:
	cmp	#0,d0
	move.w	$A11200,d0
	bne	wait_z80_reset

	move.w	#$0000,$A11100	; Release the Z80 Bus
	move.w	#$0100,$A11200	; Stop the RESET Z80 process
...well that's how it works. I've just recompile my program, and it isn't as accurate as I've expected. Nevertheless, it loads a Z80 program.

What for ?
3D, typically. You can compute a normal to a polygon, determine wheter it is to be rendered, and what should be the color. Meanwhile, the 68k compute every point of that polygon. Actually, it's almost parallel processing !!! Think Saturn !!!

Hope it helps.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Wed Dec 06, 2006 11:21 am

Hi,

Thanks for this contribution, actually i find it very usefull :)
It's true the genesis has 2 processors and it would be good to use their maximum potential !
I think i'll use your code to play a bit with :) Too bad the z80 stays a 8 bits processor, too weak for some 3D processings i guess. Maybe i'll use it for some data transfert :)

ob1
Very interested
Posts: 463
Joined: Wed Dec 06, 2006 9:01 am
Location: Aix-en-Provence, France

Post by ob1 » Wed Dec 06, 2006 11:28 am

I've been thinking on a way 3D processing could be done with parallel processing. I'll post it tomorrow.
Beware of data transfer : I've read that 68k and Z80 can not access 68k memory bus meanwhile. Can someone confirm it ?
The bus arbitrer (IC-4 on schematics, 315-5364) ensure that it's not the case.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Wed Dec 06, 2006 12:25 pm

If you like 3D processing you should have a look here :
http://www.spritesmind.net/_GenDev/foru ... c.php?t=14

It's the link of a mini dev kit i made for Genesis. I included some 3D features (transformations and flat drawing) in the lib . It's still very basic but you can play with them :)


The 68k and Z80 cannot access at the same T time the BUS, generally the Z80 work in BUS cycle steal, that means 68K has priority and Z80 access BUS when 68K doesn't need it anymore. Of course, having Z80 using a lot the main will impact on performance for both CPU.

ob1
Very interested
Posts: 463
Joined: Wed Dec 06, 2006 9:01 am
Location: Aix-en-Provence, France

Post by ob1 » Wed Dec 06, 2006 12:31 pm

Stef wrote:If you like 3D processing you should have a look here :
http://www.spritesmind.net/_GenDev/foru ... c.php?t=14
I currently am !!!
Great lib !!!
Definitively !!

I am writing an ASM routine to plot a pixel.
Last edited by ob1 on Sat Dec 16, 2006 7:55 am, edited 1 time in total.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Wed Dec 06, 2006 12:57 pm

I think you'll like the lib then :)

Post Reply