Dies ist eine alte Version des Dokuments!


Small Device C-Compiler (SDCC)

Der Small Device C-Compiler ist ein Cross-Compiler, der unter verschiedenen Betriebssystemen (Windows, Max, Linux) läuft und Programme für unterschiedliche Prozessoren generieren kann. Da der die Zilog Z80 CPU von ihm unterstützt wird, kann er auch für den Amstrad CPC eingesetzt werden. Durch seine Flexibilität können normale Programme sowie ROMs generiert werden. Im Gegensatz zu Z88dk generiert er mittlerweile besseren und schnelleren Code als Z88dk.

Ein englischsprachiges Tutorial, wie man einfache Programme mit SDCC für den Amstrad CPC entwickelt, findet man auf CPCMania.

crt0.s

Da der SDCC standardmäßig seinen Code ab 0x0000 ablegt und auch der Startup Code ab dieser Stelle läuft, muss beim Compilieren eines Programmes vorher eine angepasste Version der crt0.s erstellt werden, die dann über den Kommandozeilenparameter –no-std-crt0 eingebunden wird. Die crt0.s muss vorher aber noch ein Objektcode umgewandelt werden, was mit dem Programm sdasz80 erledigt wird. Der Aufruf lautet

sdasz80 -o crt0.s

Danach liegt im gleichen Verzeichnis die Datei crt0.rel, die vom SDCC Compiler beim Kompilieren automatisch eingebunden wird.

crt0.s für ROMs

Um ein ROM mit SDCC zu erstellen wird eine angepasste crt0.s benötigt. Sie stellt den ROM Header zur Verfügung, initialisiert das ROM, stellt RSX Befehle zur Verfügung, um das ROM in BASIC einzubinden und legt die Bereiche für den Linker fest. Nachfolgend ist eine Beispieldatei, die an die eigenen Wünsche angepasst werden sollte. Der SDCC muss dazu mit –no-std-crt0, –code-loc 0xC100 und –data-loc 0x0100 aufgerufen werden.

1
;; FILE: crt0.s
;; adapted for Amstrad CPC ROM creation 2013 by Tim Riemann / Octoate
 
    .module crt0
    .globl  _main
 
    .area _HEADER (ABS)
 
    .org 0xC000
 
    .db 0x01                       ; background ROM
    .db 0, 0, 1                 ; version 0.0.1
 
    .dw rsx_name_table          ; link to the RSX command table
 
    ; RSX jump block
    jp init_rom                 ; initialisation routine
    jp run_game                 ; first RSX command (see table)
 
rsx_name_table:                 ; NOTE: the "ascis" directive sets the highest bit of the last character
    .ascis "Init ROM"           ; initialisation routine - executed when CPC during boot process
                                ; use a name, which you can't execute from BASIC here
    .ascis "GAME"               ; to start the game, you type "|GAME" in BASIC
    .db 0                       ; end of the RSX command table
 
init_rom:                       ; show ROM initialisation message
    push hl
    ld hl, #init_msg
    call show_message
    pop hl
    scf                         ; tell the firmware, that initialisation was successful
    ret
 
init_msg:
    .db 0x0F, 2
    .ascii " Project"
    .db 0x0F, 3
    .ascii " Alpha"
    .db 0x0F, 1
    .ascii " ("
    .db 0x7C
    .ascii "GAME) "
    .db 0xA4
    .ascii "2013"
 
    .db 0x0F, 3
    .ascii " You"
    .db 0x0F, 1, 7, 10, 13, 0xFF
 
run_game:
    ; Get the ROM number
    call 0xB912                 ; KL_CURR_SELECTION (A = ROM select address for our rom)
    ld (0x4000), a              ; Save the rom number in a variable in ram
 
    ld hl, #game_message
    call show_message
 
    ;; Stack at the top of memory.
    ;;ld sp,(0xC000 - 1)
 
    call gsinit
    call _main
 
    ret                         ; end of the execution -> reset the CPC
 
game_message:
    .ascii "Hello CPC World!"
    .db 10, 13, 0xFF
 
show_message:
    ld a, (hl)
loop_show_message:
    call 0xBB5A                 ; TXT_OUTPUT
    inc hl
    ld a, (hl)
    cp #0xFF
    jr nz, loop_show_message
    ret
 
_putchar::
_putchar_rr_s::
     ld hl,#2
     add hl,sp
 
     ld a,(hl)
     call 0xBB5A
     ret
 
_putchar_rr_dbs::
     ld a,e
     call 0xBB5A
     ret
 
__clock::
    ret
 
_exit::
    ret
 
    .area _GSINIT
gsinit::
    .area _GSFINAL
    ret
 
;; Ordering of segments for the linker.
    .area _HOME
    .area _CODE
    .area _GSINIT
    .area _GSFINAL
 
    .area _DATA
    .area _BSS
    .area _HEAP
 
    .area _CODE
amstradcpc/sdcc.1357422225.txt.gz · Zuletzt geändert: 2013/01/05 22:43 von octoate
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0