Skip to content

Small Device C Compiler – Still Trying

September 11, 2015

SDCC is a very nice C compiler which I am attempting to adapt for the ZMC.

To try to get away from the overwrites, I took the reset vector code out of the crt0 module and put an explicit org statement in. Still no joy, I couldn’t get it to behave rationally under the monitor or the front panel.

I commented out the line that resets the stack pointer thinking it might be interfering with the monitor. but STILL no joy. I’ve emailed the fellow who did the monitor looking for help.

;  crt0.s - Generic crt0.s for a Z80
;  Copyright (C) 2000, Michael Hope
;  This library is free software; you can redistribute it and/or modify it
;  under the terms of the GNU General Public License as published by the
;  Free Software Foundation; either version 2, or (at your option) any
;  later version.
;  This library is distributed in the hope that it will be useful,
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;  GNU General Public License for more details.
;  You should have received a copy of the GNU General Public License 
;  along with this library; see the file COPYING. If not, write to the
;  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
;   MA 02110-1301, USA.
;  As a special exception, if you link this library with other files,
;  some of which are compiled with SDCC, to produce an executable,
;  this library does not by itself cause the resulting executable to
;  be covered by the GNU General Public License. This exception does
;  not however invalidate any other reasons why the executable file
;   might be covered by the GNU General Public License.
;; module crt0 from SDCC
;;first try for the Z80 Membership Card and ZMC 1.1 monitor
	.module crt0
	.globl	_main

	.area	_HEADER (ABS)
	;; Reset vector
	.org 	0x8000	;RAM starts at 32K
	jp	init
;15-09-11 try removing reset vectors
;	.org	0x08
;	reti
;	.org	0x10
;	reti
;	.org	0x18
;	reti
;	.org	0x20
;	reti
;	.org	0x28
;	reti
;	.org	0x30
;	reti
;	.org	0x38
;	reti

	.org	0x8100
	;; Set stack pointer directly above top of memory.
;	ld	sp,#0x0000	;***NOT SETTING STACK***

	;; Initialise global variables
	call	gsinit
	call	_main
	jp	_exit

	;; Ordering of segments for the linker.
	.area	_HOME
	.area	_CODE
	.area   _GSINIT
	.area   _GSFINAL

	.area	_DATA
	.area	_BSEG
	.area   _BSS
	.area   _HEAP

	.area   _CODE
	ld	a,#2
	rst	0x08

	;; Exit - special code to the emulator
	ld	a,#0
	rst	0x08
	jr	1$

;	.area   _GSINIT ;wjr
	ld	bc, #l__INITIALIZER
	ld	a, b
	or	a, c
	jr	Z, gsinit_next
	ld	de, #s__INITIALIZED
	ld	hl, #s__INITIALIZER

;	.area   _GSFINAL ;wjr

The hex file now seems to have no overlaps

:0A 9000 003E48F533CD24903318FEEE
:03 8000 00C3008139
:09 8100 00CD1490CD0090C30E9047
:10 900A 003E02CFC93E00CF7618FD01000078B12894
:10 901A 0008110080210080EDB0C9210200397ECDFF
:08 902A 00E90FC97BCDE90FC974
:00 0000 01FF

But it still goes wonky in execution:

Main Menu >d 8000  8003
M8000  C3 00 81 00                                     ; ....
Main Menu >d 8100  8102
M8100  CD 14 90                                        ; ...
Main Menu >d 9014  901f
M9014              01 00 00 78 B1 28 08 11 00 80 21 00 ;     ...x.(....!.
Main Menu >r PC=8000=8000
Main Menu >s
Step 0E
AF=0044  BC=0000  DE=0100  HL=1115  AF'=8E8B  BC'=EDEF  DE'=BFFF  HL'=7FFF
IX=FFFF  IY=9889  IR=0043  PC=FF01  SP=0000
Main Menu >

UPDATE: Josh says the code sequence executes


From → Olduino/Z

Leave a Comment

Leave a Reply

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

You are commenting using your 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: