	;; Generic crt0.s for a Z80
	.globl	_main

	.area _HEADER (ABS)
	;; Reset vector
        .org    0x4000
        .db     0x41
        .db     0x42 ; "AB" HEADER
        .dw     init
        .dw     0x0000
        .dw     0x0000
        .dw     0x0000
        .dw     0x0000
        .dw     0x0000
        .dw     0x0000

init:
	;; Stack at the top of memory.
        ld      sp,(0xfc4a)        

        ;; Initialise global variables
        call    gsinit
	call	_main
	jp	_exit

	;; Ordering of segments for the linker.
	.area	_CODE
        .area   _GSINIT
        .area   _GSFINAL
        
	.area	_DATA
        .area   _BSS

        .area   _CODE

        ;; Special RLE decoder used for initing global data
;;__initrleblock::
;;        ret

        .area   _GSINIT
gsinit::	

        .area   _GSFINAL
        ret
