Skip to content

Z88dk IS IN the Game!

January 9, 2016


Thanks to a ton of help from Alvin on the Z88dk forum, I have a Z88dk working with SDCC to generate code for the Olduino/Z.

Z88dk is quite sophisticated so there’s a good bit of prep work to do. I’m using an “embedded” target definition which Alvin helped me simplify so i could follow the code. Z88dk probably generates better code but more importantly it generates a single binary file without any fuss and does constant initialization at compile time which saves a lot of space.

The video just shows the edit/compile/load/blink sequence.  The program is using the membership card parallel output port bit 6 to blink the LED while using Josh’s serial routine to send ascii to the PC.

#pragma output CRT_ORG_CODE = 32768
#include "..\include\cpuz80spd4port40.h"
#include "olduino.h"
void main()
{
	while(1)
	{
		putchar('\n');putchar('H');putchar('W');
		digitalWrite(6,HIGH);
		delay(1000);
		digitalWrite(6,LOW);
		delay(1000);
	}
}
#include "olduino.c"
177   0000              ; Function main
178   0000              ; ---------------------------------
179   0000              _main:
180   0000              l_main_00102:
181   0000  2E 0A       	ld	l,0x0A
182   0002  CD B0 00    	call	_putchar
183   0005  2E 48       	ld	l,0x48

Z80 Module Assembler 2.8.2, (c) InterLogic 1993-2009, Paulo Custodio 2011-2015                    Sat Jan 09 16:21:43 2016
Page 004                                                                                                   'testembed.lst'

184   0007  CD B0 00    	call	_putchar
185   000A  2E 57       	ld	l,0x57
186   000C  CD B0 00    	call	_putchar
187   000F  21 06 01    	ld	hl,0x0106
188   0012  E5          	push	hl
189   0013  CD 5B 00    	call	_digitalWrite
190   0016  21 E8 03    	ld	hl,0x03E8
191   0019  E3          	ex	(sp),hl
192   001A  CD 2E 00    	call	_delay
193   001D  21 06 00    	ld	hl,0x0006
194   0020  E3          	ex	(sp),hl
195   0021  CD 5B 00    	call	_digitalWrite
196   0024  21 E8 03    	ld	hl,0x03E8
197   0027  E3          	ex	(sp),hl
198   0028  CD 2E 00    	call	_delay
199   002B  F1          	pop	af
200   002C  18 D2       	jr	l_main_00102
201   002E              ;	---------------------------------
202   002E              ; Function delay
203   002E              ; ---------------------------------
204   002E              _delay:
205   002E  DD E5       	push	ix
206   0030  DD 21 00 00 	ld	ix,0
207   0034  DD 39       	add	ix,sp
208   0036  21 F0 FF    	ld	hl,_TicCnt
209   0039  7E          	ld	a,(hl)
210   003A  DD 86 04    	add	a,(ix+4)
211   003D  57          	ld	d,a
212   003E  23          	inc	hl
213   003F  7E          	ld	a,(hl)
214   0040  DD 8E 05    	adc	a,(ix+5)
215   0043  5F          	ld	e,a
216   0044  4E          	ld	c,(hl)
217   0045  2B          	dec	hl
218   0046  46          	ld	b,(hl)
219   0047              l_delay_00101:
220   0047  78          	ld	a,b
221   0048  92          	sub	a, d
222   0049  79          	ld	a,c
223   004A  9B          	sbc	a, e
224   004B  30 07       	jr	NC,l_delay_00104
225   004D  2A F0 FF    	ld	hl,(_TicCnt)
226   0050  45          	ld	b,l
227   0051  4C          	ld	c,h
228   0052  18 F3       	jr	l_delay_00101
229   0054              l_delay_00104:
230   0054  DD E1       	pop	ix
231   0056  C9          	ret
232   0057              ;	---------------------------------
233   0057              ; Function millis
234   0057              ; ---------------------------------
235   0057              _millis:
236   0057  2A F0 FF    	ld	hl,(_TicCnt)
237   005A  C9          	ret
238   005B              ;	---------------------------------
239   005B              ; Function digitalWrite
240   005B              ; ---------------------------------
241   005B              _digitalWrite:
242   005B  DD E5       	push	ix
243   005D  DD 21 00 00 	ld	ix,0
244   0061  DD 39       	add	ix,sp

Z80 Module Assembler 2.8.2, (c) InterLogic 1993-2009, Paulo Custodio 2011-2015                    Sat Jan 09 16:21:43 2016
Page 005                                                                                                   'testembed.lst'

245   0063  3E 00       	ld	a,+(_bitval & 0xFF)
246   0065  DD 86 04    	add	a,(ix+4)
247   0068  5F          	ld	e,a
248   0069  3E 00       	ld	a,+(_bitval / 256)
249   006B  CE 00       	adc	a,0x00
250   006D  57          	ld	d,a
251   006E  1A          	ld	a,(de)
252   006F  57          	ld	d,a
253   0070  DD 7E 05    	ld	a,(ix+5)
254   0073  B7          	or	a, a
255   0074  28 08       	jr	Z,l_digitalWrite_00102
256   0076  21 E1 FF    	ld	hl,_PORT40
257   0079  7E          	ld	a,(hl)
258   007A  B2          	or	a, d
259   007B  77          	ld	(hl),a
260   007C  18 09       	jr	l_digitalWrite_00103
261   007E              l_digitalWrite_00102:
262   007E  7A          	ld	a,d
263   007F  2F          	cpl
264   0080  57          	ld	d,a
265   0081  21 E1 FF    	ld	hl,_PORT40
266   0084  7E          	ld	a,(hl)
267   0085  A2          	and	a, d
268   0086  77          	ld	(hl),a
269   0087              l_digitalWrite_00103:
270   0087  3A E1 FF    	ld a,(_PORT40) ;pick up current value
271   008A  D3 40       	out (64),a
272   008C  DD E1       	pop	ix
273   008E  C9          	ret
274   008F              ;	---------------------------------
275   008F              ; Function Serialavailable
276   008F              ; ---------------------------------
277   008F              _Serialavailable:
278   008F  2A BA FF    	ld	hl,(_rxbhead)
279   0092  ED 4B BC FF 	ld	bc,(_rxbtail)
280   0096  AF          	xor	a,a
281   0097  ED 42       	sbc	hl,bc
282   0099  20 03       	jr	NZ,l_Serialavailable_00103
283   009B  AF          	xor	a,a
284   009C  18 02       	jr	l_Serialavailable_00104
285   009E              l_Serialavailable_00103:
286   009E  3E 01       	ld	a,0x01
287   00A0              l_Serialavailable_00104:
288   00A0  6F          	ld	l,a
289   00A1  17          	rla
290   00A2  9F          	sbc	a, a
291   00A3  67          	ld	h,a
292   00A4  C9          	ret
293   00A5              ;	---------------------------------
294   00A5              ; Function raw_chario_shield
295   00A5              ; ---------------------------------
296   00A5              _raw_chario_shield:
297   00A5              	_getcharne:
298   00A5  CD D7 0F    	call 0x0FD7
299   00A8  6F          	ld l,a
300   00A9  C9          	ret
301   00AA              	_putcharncr:
302   00AA              ;does a put_char without adding cr to lf
303   00AA  7D          	ld a,l
304   00AB  CD E9 0F    	call 0x0FE9
305   00AE  C9          	ret

Z80 Module Assembler 2.8.2, (c) InterLogic 1993-2009, Paulo Custodio 2011-2015                    Sat Jan 09 16:21:43 2016
Page 006                                                                                                   'testembed.lst'

306   00AF  C9          	ret
307   00B0              ;	---------------------------------
308   00B0              ; Function putchar
309   00B0              ; ---------------------------------
310   00B0              _putchar:
311   00B0  7D          	ld	a, l
312   00B1  16 00       	ld	d,0x00
313   00B3  D6 0A       	sub	a,0x0A
314   00B5  20 0F       	jr	NZ,l_putchar_00102
315   00B7  B2          	or	a,d
316   00B8  20 0C       	jr	NZ,l_putchar_00102
317   00BA  2E 0A       	ld	l,0x0A
318   00BC  CD AA 00    	call	_putcharncr
319   00BF  2E 0D       	ld	l,0x0D
320   00C1  CD AA 00    	call	_putcharncr
321   00C4  18 03       	jr	l_putchar_00104
322   00C6              l_putchar_00102:
323   00C6  CD AA 00    	call	_putcharncr
324   00C9              l_putchar_00104:
325   00C9  C9          	ret
326   00CA              	SECTION code_compiler
327   00CA              	SECTION data_compiler
328   0000              _bitval:
329   0000  01          	DEFB +0x01	; 1
330   0001  02          	DEFB +0x02	; 2
331   0002  04          	DEFB +0x04	; 4
332   0003  08          	DEFB +0x08	; 8
333   0004  10          	DEFB +0x10	; 16
334   0005  20          	DEFB +0x20	; 32
335   0006  40          	DEFB +0x40	; 64
336   0007  80          	DEFB +0x80	; 128

In the binary below, the first part(underlined red) is the startup code – basically just a call to main. The next part, underlined green is main(), and the rest is my olduino routines – delay, digitalwrite etc.
16-01-09 code.bin

The code compiles and works the same with the stock embedded crt and startup=0 but i’m happy to have something that i can track down to the byte and modify without screwing up the baseline.
That means I have the following extra or modified files provided by Alvin:

h:\apps\z88dk/libsrc/_DEVELOPMENT/target/embedded/startup\
embedded_crt_99.m4 and embedded_crt_99.asm

h:\apps\z88dk/libsrc/_DEVELOPMENT/target/embedded/embedded_crt.asm
and
z88dk/libsrc/_DEVELOPMENT/target/embedded/crt_target_defaults.inc is changed under under __CRTDEF=99

Advertisements

From → Olduino/Z

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: