1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-12-23 03:29:39 +00:00

zx: added crt0

This commit is contained in:
Steven Hugg 2020-07-20 12:00:25 -05:00
parent 101f605c6c
commit f05fde8f47
7 changed files with 212 additions and 30 deletions

View File

@ -2,18 +2,6 @@
#include <stdio.h>
#include "bios.h"
#ifdef __MAIN__
void main(void);
void startup(void) __naked {
__asm
jp _main
__endasm;
}
#endif
// http://www.users.globalnet.co.uk/~jg27paw4/pourri/rom-routines.txt
void init_stdio(void) {

View File

@ -9,23 +9,6 @@
#include "bios.h"
//#link "bios.c"
void main(void);
void startup(void) __naked {
__asm
; copy initialized data
LD BC, #l__INITIALIZER
LD A, B
LD DE, #s__INITIALIZED
LD HL, #s__INITIALIZER
LDIR
; disable interrupts
DI
; start main routine
jp _main
__endasm;
}
// type aliases for byte/signed byte/unsigned 16-bit
typedef unsigned char byte;
typedef signed char sbyte;

View File

@ -0,0 +1,75 @@
ASxxxx Assembler V02.00 + NoICE + SDCC mods (Zilog Z80 / Hitachi HD64180), page 1.
Hexadecimal [16-Bits]
1 ; crt0.s for ZX Spectrum
2
3 .module crt0
4 .globl _main
5 .globl ___sdcc_call_hl
6
7 ; Ordering of segments for the linker - copied from sdcc crt0.s
8 .area _CODE
9 .area _INITIALIZER
10 .area _HOME
11 .area _GSINIT
12 .area _GSFINAL
13 .area _DATA
14 .area _INITIALIZED
15 .area _BSEG
16 .area _BSS
17 .area _HEAP
18
19 .area _CODE
20
0000 21 _Start:
0000 F3 [ 4] 22 di
0001 ED 56 [ 8] 23 im 1
24 ; stack pointer already set by BIOS
0003 CD 00 00 [17] 25 call gsinit ; Initialize global and static variables.
0006 CD 00 00 [17] 26 call _main
0009 C7 [11] 27 rst 0x0 ; Restart when main() returns.
28
29 .area _GSINIT
0000 30 gsinit::
31
32 ; Implicitly zeroed global and static variables.
0000 01 00 00 [10] 33 ld bc, #l__DATA
0003 78 [ 4] 34 ld a, b
0004 B1 [ 4] 35 or a, c
0005 28 0F [12] 36 jr Z, zeroed_data
0007 21 00 00 [10] 37 ld hl, #s__DATA
000A 36 00 [10] 38 ld (hl), #0x00
000C 0B [ 6] 39 dec bc
000D 78 [ 4] 40 ld a, b
000E B1 [ 4] 41 or a, c
000F 28 05 [12] 42 jr Z, zeroed_data
0011 5D [ 4] 43 ld e, l
0012 54 [ 4] 44 ld d, h
0013 13 [ 6] 45 inc de
0014 ED B0 [21] 46 ldir
0016 47 zeroed_data:
48
49 ; Explicitly initialized global variables.
0016 01 00 00 [10] 50 ld bc, #l__INITIALIZER
0019 78 [ 4] 51 ld a, b
001A B1 [ 4] 52 or a, c
001B 28 08 [12] 53 jr Z, gsinit_static
001D 11 00 00 [10] 54 ld de, #s__INITIALIZED
0020 21 00 00 [10] 55 ld hl, #s__INITIALIZER
ASxxxx Assembler V02.00 + NoICE + SDCC mods (Zilog Z80 / Hitachi HD64180), page 2.
Hexadecimal [16-Bits]
0023 ED B0 [21] 56 ldir
57
0025 58 gsinit_static:
59 ; Explicitly initialized static variables inserted by compiler here.
60
61 .area _GSFINAL
0000 C9 [10] 62 ret
63
64 .area _HOME
65

View File

@ -0,0 +1,42 @@
XL2
H A areas 9 global symbols
M crt0
S l__DATA Ref0000
S _main Ref0000
S s__DATA Ref0000
S .__.ABS. Def0000
S s__INITIALIZED Ref0000
S ___sdcc_call_hl Ref0000
S l__INITIALIZER Ref0000
S s__INITIALIZER Ref0000
A _CODE size A flags 0 addr 0
A _INITIALIZER size 0 flags 0 addr 0
A _HOME size 0 flags 0 addr 0
A _GSINIT size 25 flags 0 addr 0
S gsinit Def0000
A _GSFINAL size 1 flags 0 addr 0
A _DATA size 0 flags 0 addr 0
A _INITIALIZED size 0 flags 0 addr 0
A _BSEG size 0 flags 0 addr 0
A _BSS size 0 flags 0 addr 0
A _HEAP size 0 flags 0 addr 0
T 00 00
R 00 00 00 00
T 00 00 F3 ED 56 CD 00 00 CD 00 00 C7
R 00 00 00 00 00 06 03 00 02 09 01 00
T 00 00
R 00 00 03 00
T 00 00 01 00 00 78 B1 28 0F 21 00 00 36 00 0B 78
R 00 00 03 00 02 03 00 00 02 0A 02 00
T 0E 00 B1 28 05 5D 54 13 ED B0
R 00 00 03 00
T 16 00
R 00 00 03 00
T 16 00 01 00 00 78 B1 28 08 11 00 00 21 00 00 ED
R 00 00 03 00 02 03 06 00 02 0A 04 00 02 0D 07 00
T 24 00 B0
R 00 00 03 00
T 25 00
R 00 00 03 00
T 00 00 C9
R 00 00 04 00

View File

@ -0,0 +1,65 @@
; crt0.s for ZX Spectrum
.module crt0
.globl _main
.globl ___sdcc_call_hl
; Ordering of segments for the linker - copied from sdcc crt0.s
.area _CODE
.area _INITIALIZER
.area _HOME
.area _GSINIT
.area _GSFINAL
.area _DATA
.area _INITIALIZED
.area _BSEG
.area _BSS
.area _HEAP
.area _CODE
_Start:
di
im 1
; stack pointer already set by BIOS
call gsinit ; Initialize global and static variables.
call _main
rst 0x0 ; Restart when main() returns.
.area _GSINIT
gsinit::
; Implicitly zeroed global and static variables.
ld bc, #l__DATA
ld a, b
or a, c
jr Z, zeroed_data
ld hl, #s__DATA
ld (hl), #0x00
dec bc
ld a, b
or a, c
jr Z, zeroed_data
ld e, l
ld d, h
inc de
ldir
zeroed_data:
; Explicitly initialized global variables.
ld bc, #l__INITIALIZER
ld a, b
or a, c
jr Z, gsinit_static
ld de, #s__INITIALIZED
ld hl, #s__INITIALIZER
ldir
gsinit_static:
; Explicitly initialized static variables inserted by compiler here.
.area _GSFINAL
ret
.area _HOME

View File

@ -0,0 +1,27 @@
ASxxxx Assembler V02.00 + NoICE + SDCC mods (Zilog Z80 / Hitachi HD64180), page 1.
Hexadecimal [16-Bits]
Symbol Table
.__.$$$.= 2710 L | .__.ABS.= 0000 G | .__.CPU.= 0000 L
.__.H$L.= 0000 L | 0 _Start 0000 R | ___sdcc_ **** GX
_main **** GX | 3 gsinit 0000 GR | 3 gsinit_s 0025 R
l__DATA **** GX | l__INITI **** GX | s__DATA **** GX
s__INITI **** GX | s__INITI **** GX | 3 zeroed_d 0016 R
ASxxxx Assembler V02.00 + NoICE + SDCC mods (Zilog Z80 / Hitachi HD64180), page 2.
Hexadecimal [16-Bits]
Area Table
0 _CODE size A flags 0
1 _INITIAL size 0 flags 0
2 _HOME size 0 flags 0
3 _GSINIT size 25 flags 0
4 _GSFINAL size 1 flags 0
5 _DATA size 0 flags 0
6 _INITIAL size 0 flags 0
7 _BSEG size 0 flags 0
8 _BSS size 0 flags 0
9 _HEAP size 0 flags 0

View File

@ -265,7 +265,9 @@ var PLATFORM_PARAMS = {
data_start: 0xf000,
data_size: 0xfe00-0xf000,
stack_end: 0xff58,
},
extra_link_args: ['crt0-zx.rel'],
extra_link_files: ['crt0-zx.rel', 'crt0-zx.lst'],
},
};
PLATFORM_PARAMS['sms-sms-libcv'] = PLATFORM_PARAMS['sms-sg1000-libcv'];