SDCC crt0.s for floppy bload

Página 1/3
| 2 | 3

Por Emily82

Resident (53)

imagem de Emily82

06-02-2017, 05:11

Hi guys, i noticed around there isn't any info on how to make bloadable bin (floppy), using sdcc / sdasz80
After working hard on it, i could create a functional custom crt0.s header and i would like to share it on the web, hoping this will bring more info to make easier msx development in C.

This is the crt0dsk.s code

;	BLOADABLE .BIN HEADER (floppy disk)
.globl	_main

.area	_HEADER (ABS)
.org	0x8000

.db 	0xfe
.dw 	init
.dw		_end
.dw 	init

init:
	jp	_main
	
.area	_GSFINIAL
_end:
	halt

And this is my bash script for linux

#!/bin/sh
rm -f myhello.rom
rm -f *.bin
rm -f *.rel
rm -f *.sym
rm -f *.mem
rm -f 16kmem.*
rm -f *.ihx
rm -f *.lst
rm -f *.map
rm -f *.noi
rm -f *.asm
rm -f *.lk

sdasz80 -o io.s
sdasz80 -o crt0dsk.s
sdcc -I include/ -mz80 -c -o conio.rel conio.c

sdcc -I include/ --out-fmt-ihx --data-loc 0xc000 --code-loc 0x8020 -mz80 --no-std-crt0 crt0dsk.rel io.rel conio.rel main.c

objcopy -Iihex -Obinary main.ihx myhello.bin

I hope this example will be useful for all. Wink

Entrar ou registrar-se para comentar

Por Emily82

Resident (53)

imagem de Emily82

06-02-2017, 18:22

However there is an issue. _GSFINAL will put the end: label at DATA section.
In this example DATA section is 16K ahead of _CODE area and i will have 16K binary size!

I need to get the end address of _CODE area, without setting it manually.

Por sd_snatcher

Prophet (3675)

imagem de sd_snatcher

06-02-2017, 22:51

Thank you Emily82! And be very welcome to the MSX community! BTW, What kind of software are you working on? Any game or utility?

Side note: I think you probably have the best profile picture here on MRC. Wink

Por Emily82

Resident (53)

imagem de Emily82

06-02-2017, 22:56

Thanks for the answer snatcher Smile
I simply created an hello and integer number print. I fixed the problem, to get the end address for (bload) header
use this crt0dsk.s as header for the C app

;	BLOADABLE .BIN HEADER (floppy disk)
.globl	_main

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

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

.area	_HEADER (ABS)
.org	0x8000

.db 	0xfe
.dw 	init
.dw		_end
.dw 	init

init:
	call	_main

.area   _GSINIT
_end:
	ret

Por Emily82

Resident (53)

imagem de Emily82

07-02-2017, 05:44

Sorry for code spam, but i had another problem and i improved the crt0 code, to fix this.
With the previous code, global variables in C didn't work.
Using this code globals work fine Wink

;	BLOADABLE .BIN HEADER (floppy disk)
.module	crt0dsk
.globl	_main
.globl l__INITIALIZER
.globl s__INITIALIZED
.globl s__INITIALIZER

;; Floppy disk BASIC bload Header
.db 	0xfe
.dw 	init
.dw		end
.dw 	init

init:
	call 	gsinit
	jp		__pre_main
	
;; Ordering of segments for the linker.
.area _HOME
.area _CODE
.area _INITIALIZER
.area _GSINIT
.area _GSFINAL

.area _DATA
_heap_top::
	.dw 0
.area _INITIALIZED
.area _BSEG
.area _BSS
.area _HEAP

.area _CODE
	
__pre_main:
	push de
	ld de,#_HEAP_start
	ld (_heap_top),de
	pop de
	call	_main
	ret

.area   _GSINIT
gsinit::
	ld bc, #l__INITIALIZER
	ld a, b
	or a, c
	jr Z, gsinit_next
	ld de, #s__INITIALIZED
	ld hl, #s__INITIALIZER
	ldir
gsinit_next:
end:

.area   _GSFINAL
ret
	
.area	_HEAP

_HEAP_start::

I couldn't share code not working properly Wink

Por Wolverine_nl

Paragon (1160)

imagem de Wolverine_nl

07-02-2017, 09:41

Hi and welcome to MRC,
Most of us that program in C on the MSX or with a cross compiler, always use a DOS version to execute the program, but this requires the user to have a DOS1/2 version at least, which in MSX, isn't userfriendly. This is greatly appreciated, also for later projects to find something on this. Smile

Por Emily82

Resident (53)

imagem de Emily82

07-02-2017, 12:18

Yes, i did this especially because i own two real msx (JVC hc7-e and philips NMS8280) but i don't have sunrise ide and other stuff for Dos. So in this way i can port my C code not only to emulators Smile
If you want to save C software to cassette, using openmsx, simply type
bload"myprog.bin" without "r" option then
bsave"cas:myprog",start address, end address

You will have the .wav in openmsx ready to be written to a real cassette using audacity for example Smile

Note: the start address should not include initial 7 bytes header. BSAVE encapsulates cassette header by its own.
So if you load your program at address &h8000, start address should be &h8007 and end address the same.

Por akumajo

Resident (43)

imagem de akumajo

25-09-2019, 15:54

Emily, are you still here ?

My current problem is that I do not manage to obtain a code generated by SDCC which places in ROM the copying function of the initialized global variables.
It's a crt0 code and/or linking order problem, I guess...

When I compile and link with this crt0 for a 16kb ROM @ 04000h and RAM @ 08000h :

.module crt0

.globl _main
.globl l__INITIALIZER
.globl s__INITIALIZED
.globl s__INITIALIZER

.area _HEADER (ABS)
; Reset vector
	.org 0x4000
	.db  0x41
	.db  0x42
	.dw  init
	.dw  0x0000
	.dw  0x0000
	.dw  0x0000
	.dw  0x0000
	.dw  0x0000
	.dw  0x0000

init:
	call 	gsinit
	jp		__pre_main

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

.area _DATA
_heap_top::
	.dw 0
.area _INITIALIZED
.area _BSEG
.area _BSS
.area _HEAP

.area _CODE

__pre_main:
	push de
	ld de,#_HEAP_start
	ld (_heap_top),de
	pop de
	call	_main
	ret

.area   _GSINIT
gsinit::
	ld bc, #l__INITIALIZER
	ld a, b
	or a, c
	ret z
	ld de, #s__INITIALIZED
	ld hl, #s__INITIALIZER
	ldir
gsinit_next:
end:
.area   _GSFINAL
ret

.area	_HEAP

_HEAP_start::

I get :

     000000A4  l__INITIALIZED                  
     000000A4  l__INITIALIZER                  
     00000287  l__CODE                         
     00004016  s__CODE                         
     00008000  s__DATA                         
     0000800E  s__INITIALIZED                  
     000080B2  s__GSINIT                       
     000080B2  s__HOME                         
     000080C0  s__GSFINAL                      
     000080C1  s__INITIALIZER                  
     00008165  s__BSEG                         
     00008165  s__BSS                          
     00008165  s__HEAP                         

Why INITIALIZED and GSINIT are in RAM ?
how to make SDCC set INITIALIZER in ROM and GSINIT after main code, in ROM as well?

Por ducasp

Paladin (712)

imagem de ducasp

25-09-2019, 17:49

akumajo wrote:

Emily, are you still here ?

My current problem is that I do not manage to obtain a code generated by SDCC which places in ROM the copying function of the initialized global variables.
It's a crt0 code and/or linking order problem, I guess...

When I compile and link with this crt0 for a 16kb ROM @ 04000h and RAM @ 08000h :

.module crt0

.globl _main
.globl l__INITIALIZER
.globl s__INITIALIZED
.globl s__INITIALIZER

.area _HEADER (ABS)
; Reset vector
	.org 0x4000
	.db  0x41
	.db  0x42
	.dw  init
	.dw  0x0000
	.dw  0x0000
	.dw  0x0000
	.dw  0x0000
	.dw  0x0000
	.dw  0x0000

init:
	call 	gsinit
	jp		__pre_main

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

.area _DATA
_heap_top::
	.dw 0
.area _INITIALIZED
.area _BSEG
.area _BSS
.area _HEAP

.area _CODE

__pre_main:
	push de
	ld de,#_HEAP_start
	ld (_heap_top),de
	pop de
	call	_main
	ret

.area   _GSINIT
gsinit::
	ld bc, #l__INITIALIZER
	ld a, b
	or a, c
	ret z
	ld de, #s__INITIALIZED
	ld hl, #s__INITIALIZER
	ldir
gsinit_next:
end:
.area   _GSFINAL
ret

.area	_HEAP

_HEAP_start::

I get :

     000000A4  l__INITIALIZED                  
     000000A4  l__INITIALIZER                  
     00000287  l__CODE                         
     00004016  s__CODE                         
     00008000  s__DATA                         
     0000800E  s__INITIALIZED                  
     000080B2  s__GSINIT                       
     000080B2  s__HOME                         
     000080C0  s__GSFINAL                      
     000080C1  s__INITIALIZER                  
     00008165  s__BSEG                         
     00008165  s__BSS                          
     00008165  s__HEAP                         

Why INITIALIZED and GSINIT are in RAM ?
how to make SDCC set INITIALIZER in ROM and GSINIT after main code, in ROM as well?

I think her crt is for files you load in Basic through bload, not for ROM files... For rom files, try fusion-c, it has a crt for that...
https://github.com/ericb59/Fusion-C-v1.2

Por akumajo

Resident (43)

imagem de akumajo

25-09-2019, 18:21

ducasp wrote:

I think her crt is for files you load in Basic through bload, not for ROM files... For rom files, try fusion-c, it has a crt for that...
https://github.com/ericb59/Fusion-C-v1.2

Unfortunately Fusion-C does not offer crt0 source for ROM (Fusion-C generates MSX-DOS programs).
I think that, for SDCC, a CRT0 for ROM is almost the same than CRT0 for BIN, only header is different.

Por ducasp

Paladin (712)

imagem de ducasp

25-09-2019, 21:29

You can always talk to EricB to ask source if you want it

Página 1/3
| 2 | 3