Make CPC version run from ROM

This frees up an extra 11K of RAM for apps.

It is still slightly broken: glitches during start of the ROM, and the
desktop icons are somehow missing. I don't know why yet...
diff --git a/contiki-cpc/Makefile.cpc b/contiki-cpc/Makefile.cpc
index 49b5ce7..d2b3c68 100644
--- a/contiki-cpc/Makefile.cpc
+++ b/contiki-cpc/Makefile.cpc
@@ -102,8 +102,7 @@
 	$(LD) -f arch/contiki.lnk
 	#./bin/make_labels contiki.map arch/contiki_labels.s
 	sed -n "/^_CODE\|^_DATA\|_INITIALIZED/,/^Area/ s/^     \([0-9A-F]*\)  \([^ ]*\) .*/ \2 == 0x\1/p" contiki.map > arch/contiki_labels.s
-	makebin -p -s 65535 < contiki.ihx > contiki.raw
-	dd if=contiki.raw of=contiki.bin bs=256 skip=1
+	makebin -p -s 65536 -o 0xC000 < contiki.ihx > contiki.bin
 	cpcfs contiki.dsk f
 	cpcfs contiki.dsk p contiki.bin,256,256 -b -e
 
diff --git a/contiki-cpc/apps/configedit.c b/contiki-cpc/apps/configedit.c
index ec672f4..f3bb605 100644
--- a/contiki-cpc/apps/configedit.c
+++ b/contiki-cpc/apps/configedit.c
@@ -341,7 +341,7 @@
   
   f = cfs_open("@:config.cfg", CFS_WRITE);
   if(f == -1) {
-    log_message("Could not open config.cfg", "");
+    //log_message("Could not open config.cfg", "");
     return;
   }
   if(cfs[0] != 0) {
diff --git a/contiki-cpc/arch/arch.c b/contiki-cpc/arch/arch.c
index 48facc4..05218ce 100644
--- a/contiki-cpc/arch/arch.c
+++ b/contiki-cpc/arch/arch.c
@@ -1,13 +1,6 @@
 #include "clock.h"
 #include "arch.h"
 
-extern clock_time_t _clock_val;
-
-clock_time_t clock_time()
-{
-	return _clock_val;
-}
-
 int ctk_arch_isprint(char c)
 {
 	return (unsigned char)c > 32;
diff --git a/contiki-cpc/arch/clock.s b/contiki-cpc/arch/clock.s
index f74781e..9fb834f 100644
--- a/contiki-cpc/arch/clock.s
+++ b/contiki-cpc/arch/clock.s
@@ -1,29 +1,10 @@
 	.module clock
-	.area GSINIT
-	call __clock_init
 
-	.globl __clock_val
-	.globl __clock_init
+	.globl _clock_time
 
 	.area _CODE
-__clock_init::
-	ld hl,#event_block
-	ld b,#0x01
-	ld c,#0x00
-	ld de,#event_routine
-	call #0xbce0		;; KL NEW FAST TICKER
+_clock_time::
+	call #0xBD0D		;; KL TIME PLEASE
+	ex DE,HL
 	ret
 
-event_routine::
-	push hl
-	ld hl,(__clock_val)
-	inc hl
-	ld (__clock_val),hl
-	pop hl
-	ret
-
-__clock_val:: .dw 0
-
-event_block::
-	.ds 9
-
diff --git a/contiki-cpc/arch/contiki.lnk b/contiki-cpc/arch/contiki.lnk
index 49240a3..23c458d 100644
--- a/contiki-cpc/arch/contiki.lnk
+++ b/contiki-cpc/arch/contiki.lnk
@@ -1,6 +1,8 @@
 -imwn contiki
+-b _INITIALIZED=0x0100
+-b _CODE=0xc000
+-b _INITIALIZER=0xec00
 -k /system/data/sdcc/lib/z80
--b _CODE=0x0100
 -l z80
 ./arch/crt0.o
 ./arch/key.o
diff --git a/contiki-cpc/arch/crt0.s b/contiki-cpc/arch/crt0.s
index da8bf56..325ef30 100644
--- a/contiki-cpc/arch/crt0.s
+++ b/contiki-cpc/arch/crt0.s
@@ -7,43 +7,44 @@
     .module crt0
 	.globl	_main
 	.globl _progend
-	.area	_HEADER (ABS)
+
 	;; Ordering of segments for the linker.
-	.area	_CODE
-init:
-; This is the program entry point. Execution starts here
-;; Initialise global variables, clear BSS areas, initialize AMSDOS and setup heap.
-    call    gsinit
-; Enter the C main.
-	call	_main
-
-_exit::
-	rst #0
-
-	.area _HOME
-	.area _CODE
+	; Things that go in RAM
 	.area _INITIALIZED
 
 	.area _DATA
-	.area _BSEG
-	.area _BSS (REL)
-    .area _HEAP (REL)
+	.area _BSS
+    .area _HEAP
 _progend::
-	; NOTE - THE IS NOT ROM-FRIENDLY!
-	; We put the initializers for initialized data in the memory that will later
-	; be used for the heap. The gsinit copies it back to the CODE area above.
-	; Then, we can overwrite the now unused initializers with the heap.
-	; In the case of software actually running from ROM, the initializer section
-	; would be in ROM, and GSINIT would copy it to RAM. Of course in that case,
-	; The initializer space can't be reclaimed for the heap...
-	.area _INITIALIZER
-	.area   _GSINIT (REL)
-    .area   _GSFINAL (REL)
-	
-; -----------------------------------------------------------------------------
 
-	.area _GSINIT (REL)
-gsinit::	
+	;; Things that go in ROM
+	.area _HOME
+	.area	_CODE (REL,CON)
+	.area _INITIALIZER (REL,CON)
+	.area   _GSINIT (REL,CON)
+    .area   _GSFINAL (REL,CON)
+
+	.area	_CODE (REL,CON)
+
+	.db #1  ; Background ROM
+	.db #1  ; Version 1.4
+	.db #4
+	.db #0
+	.dw rsx_table
+
+	jp do_nothing
+	jp init
+
+rsx_table:
+
+	.db 'K' + #0x80
+	.ascii "CONTIK"
+	.db 'I' + #0x80
+	.db #0
+
+init:
+; This is the program entry point. Execution starts here
+;; Initialise global variables, clear BSS areas, initialize AMSDOS and setup heap.
 	ld	bc, #l__INITIALIZER
 	ld	a, b
 	or	a, c
@@ -56,7 +57,7 @@
 	ld hl,#s__DATA
 	ld (hl),#0
 	ld de,#s__DATA + #1
-	ld bc,#l__DATA
+	ld bc,#s__DATA + #0x200
 	ldir
 
 ; Initialize disk ROM
@@ -65,6 +66,18 @@
 	ld c,#7
 	call 0xbcce
 
-	.area   _GSFINAL
-	; After the ROMs are initialized, initialize the heap.
-	 jp __sdcc_heap_init
+	; Init the heap. Do it after the disk ROM is ready, because that may change HIMEM
+	call __sdcc_heap_init
+; Enter the C main.
+	jp	_main
+
+do_nothing:
+	LD A, #'K'
+	CALL #0xBB5A
+	scf
+	ret
+
+_exit::
+	rst #0
+
+; -----------------------------------------------------------------------------
diff --git a/contiki-cpc/arch/key.s b/contiki-cpc/arch/key.s
index 592f77c..c75b00c 100644
--- a/contiki-cpc/arch/key.s
+++ b/contiki-cpc/arch/key.s
@@ -29,4 +29,5 @@
 ;;		ld		l,a
 ;;		ret
 
+	.area _BSS
 key:		.db 0
diff --git a/contiki-cpc/arch/main.c b/contiki-cpc/arch/main.c
index f2139ad..a646212 100644
--- a/contiki-cpc/arch/main.c
+++ b/contiki-cpc/arch/main.c
@@ -82,6 +82,8 @@
 	   eventhandler, NULL, NULL);
 /*-----------------------------------------------------------------------------------*/
 #if LOG_CONF_ENABLED
+#define putchar ((void(*)(char))(0xBB5A))
+
 void
 log_message(char *part1, char *part2)
 {