Assembly code to generate a crt0 for Doors CS programs with SDCC (should be assembled with sdasz80):
Code:
Build with
Code:
And an example C program (using the ti83p.lib library provided by TISDCC):
Code:
Build it with the following command line (allocates variables at AppBackupScreen = 0x9872):
Code:
(wabbit is wabbitsign, makebin comes with sdcc, and cutbin is a little python script I just wrote).
Source for cutbin:
Code:
Code:
;; Generic crt0.s for a Z80
.module crt0
.globl _main
.globl _Description
.globl _Icon
.globl _ALE
.area _HEADER (ABS)
.org 0x9D93
.db 0xBB, 0x6D
xor d
ret
jr init
.dw _Description
.db #0x07,#0x00
.dw _Icon
.dw _ALE
init:
ld (saved_sp), sp ; save stack pointer
di
;; 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 _BSS
.area _HEAP
.area _CODE
__clock::
; ld a,#2
; rst 0x08
ret
_exit::
ld sp, (saved_sp) ;restore stack pointer
ld iy, #0x89F0
ei
ret
saved_sp:
.ds 2
.area _GSINIT
gsinit::
.area _GSFINAL
ret
Build with
Code:
sdasz80 -o -s ti83p_dcs.s
And an example C program (using the ti83p.lib library provided by TISDCC):
Code:
#include <ti83p.h>
#define NULL 0x0000
__at NULL const int ALE;
volatile const char Description[9] = "TestProg";
volatile const char Icon[32] = {0xFF,0xFF,0x80,0x01,
0x80,0x01,0x80,0x01,
0x80,0x01,0x80,0x01,
0x80,0x01,0x80,0x01,
0x80,0x01,0x80,0x01,
0x80,0x01,0x80,0x01,
0x80,0x01,0x80,0x01,
0x80,0x01,0xFF,0xFF};
void main(void) {
unsigned char c;
ClrScrnFull();
while((c=GetKey()) != GkEnter) {
DispInt(c);
NewLine();
}
ClrScrnFull();
HomeUp();
PutS("Hello World");
NewLine();
}
Build it with the following command line (allocates variables at AppBackupScreen = 0x9872):
Code:
sdcc -mz80 --no-std-crt0 --code-loc 0x9DAE --data-loc 0x9872 -L ../lib -I ../include -DTI83P -DION -Wl../startup/ti83p_dcs.rel ti83p.lib test_dcs.c && makebin -p -s 65536 test_dcs.ihx test_dcs.bin && cutbin test_dcs.bin 0x9d93 test_dcs_small.bin && wabbit test_dcs_small.bin TESTDCS.8xp
(wabbit is wabbitsign, makebin comes with sdcc, and cutbin is a little python script I just wrote).
Source for cutbin:
Code:
#!/usr/bin/env python
import sys
datah = open(sys.argv[1],'r')
ba = bytearray(datah.read())
datah.close()
ba = ba[int(sys.argv[2],16):]
datah = open(sys.argv[3],'w')
datah.write(ba)
datah.close()