Skip to content

Commit

Permalink
initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
boert committed Jul 31, 2024
1 parent 7d0568b commit 834a8b1
Show file tree
Hide file tree
Showing 31 changed files with 2,524 additions and 0 deletions.
Binary file added HELLO.kcc
Binary file not shown.
65 changes: 65 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
TARGET = HELLO

# alle C-Quelldateien
SRC_C = $(wildcard *.c)
OBJ_C = $(SRC_C:%.c=%.rel)

# alle Assemblerquellen
SRC_ASM = $(wildcard *.s)
OBJ_ASM = $(SRC_ASM:%.s=%.rel)

LIBS = caos.lib
LIBS += printf.lib

# -l ergänzen für Compiler
LIBSLIST = $(patsubst %, -l %,$(LIBS))


all: libs $(TARGET).kcc

libs: $(LIBS)

%.rel: %.s
@echo -n "Assemble: "
sdasz80 -plsgff -o $@ $<

%.rel: %.asm
@echo -n "Assemble: "
sdasz80 -plsgff -o $@ $<

%.asm: %.c
@echo -n "Compile: "
sdcc -mz80 --fomit-frame-pointer -Wall -S $< -o $@


$(TARGET).ihx: $(OBJ_ASM) $(OBJ_C)
@echo -n "Link: "
sdldz80 -mjwx -b _KCC_HEADER=0x180 -b _CODE=0x200 $(LIBSLIST) -i $@ $^

$(TARGET).kcc: $(TARGET).ihx
sdobjcopy -I ihex -O binary $< $@
python3 fix_kcc_length.py $@


printf.lib:
make --directory lib_printf

caos.lib:
make --directory lib_caos


clean:
rm -f *.sym
rm -f *.lst
rm -f *.rel
rm -f $(TARGET).ihx
rm -f $(TARGET).lk
rm -f $(TARGET).map
rm -f $(TARGET).noi


dist-clean: clean
rm -f $(LIBS)
rm -f caos.h
make clean --directory lib_printf
make clean --directory lib_caos
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
# KC85_SDCC_Hello_World
"Hello World"-Beispiel für KC85/4 mit dem Small Device C Compiler (SDCC)


Das Projekt zeigt den Einsatz des SDCC-Compilers um KCC-Dateien für die Kleincomputer aus Mühlhausen (KC85/3, KC85/4, KC85/5) zu erzeugen.
Dazu sind einige Anpassungen nötig (crt0.s, header.s, menuentry.s).
Außerdem gibt es eine Bibliothek, die ein angepasste printf-Funktion zur Verfügung stellt und eine Bibliothek, die Zugriff auf einige Unterprogramme des Betriebsystems CAOS erlaubt.

## Buildsystem
Um das Programm zu übersetzen werden folgende Werkzeuge benötigt:
- make
- sdcc
- python3


## Dateien

| Datei | Typ | Erläuterung
| --- | --- | ---
| Makefile | Makefile | Projektautomatisierung
| hello.c | C-Program | Hauptprogramm
| crt0.s | Assembler | C-Runtime, Start- und Endcode angepasdt für CAOS
| header.s | Assembler | enthält den KCC-Header
| menuentry.s | Assembler | enthält Eintrag für CAOS-Menüsystem
| caos.h | C-Header | für Funktionen aus caos.lib
| caos.lib | Bibliothek | zur Nutzung der CAOS-Unterprogamme
| printf.lib | Bibliothek | enthält printf-Funktion für CAOS
| fix_kcc_length.py | Python-Skript | erweitert die Länge der KCC-Datei auf Vielfache von 128 Byte
| HELLO.kcc | Programm | Programmdatei


## Zusätzliche Bibliotheken
| Vezeichnis | Erläuterung
| --- | ---
| lib_caos | Bibliothek zur Nutzung der CAOS-Unterprogamme
| lib_printf | printf-Funktion für CAOS


# Hilfreiche Links

- KC85/5 Systemhandbuch
http://www.kc85.info/index.php/download-topmenu/download/32-handbuecher/401-kc85-5-systemhandbuch.html

- SDCC - Small Device C Compiler
https://sdcc.sourceforge.net/

- Gihub-Seite von Andreas Ziermann
https://github.com/anchorz/sdcc-z1013-kc85

- JKCEMU, Emulator (u.a. KC85) von Jens Müller
http://www.jens-mueller.org/jkcemu/

109 changes: 109 additions & 0 deletions crt0.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
;--------------------------------------------------------------------------
; crt0.s - adopted for a KC85(5)
;
; Copyright (C) 2014, Andreas Ziermann (Z1013)
; 2015, Bert Lange
;
; This library is free software; you can redistribute it and/or modify it
; under the terms of the GNU General Public License as published by the
; Free Software Foundation; either version 2, or (at your option) any
; later version.
;
; This library is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this library; see the file COPYING. If not, write to the
; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
; MA 02110-1301, USA.
;
; As a special exception, if you link this library with other files,
; some of which are compiled with SDCC, to produce an executable,
; this library does not by itself cause the resulting executable to
; be covered by the GNU General Public License. This exception does
; not however invalidate any other reasons why the executable file
; might be covered by the GNU General Public License.
;--------------------------------------------------------------------------

.module crt0

.globl _main

.area _HEADER (ABS)
.org 0x200


;; Ordering of segments for the linker.
.area _HOME
.area _CODE
.area _INITIALIZER
.area _GSINIT
.area _GSFINAL
.area _GSEXIT
.area _GSEXITFINAL
.area _DATA
.area _INITIALIZED
.area _BSEG
.area _BSS
.area _STACK
.area _HEAP
.area _CODE


.globl init

init:

;; Initialise global variables
call gsinit
call _main

;call gsexit
; use call LOOP instead of ret, works also
; with direct load+start on simulator
call #0xF003
.db #0x12

.area _GSINIT
gsinit::
; copy initialized variables to 'RAM'
ld bc, #l__INITIALIZER
ld a, b
or a, c
jr Z, gsinit_zero
ld de, #s__INITIALIZED
ld hl, #s__INITIALIZER
ldir

gsinit_zero:
; did we have data to zero?
ld bc, #l__DATA
ld a, b
or a, c
;jr Z, gsinit_next
ret Z

; zero uninitialized stuff
xor a ; clear a and carry
ld bc, #l__DATA ; ram size left
ld hl, #s__DATA
ld de, #s__DATA+1
ld ( hl), a
ldir

gsinit_next:

.area _GSFINAL
ret

.area _GSEXIT
gsexit::

.area _GSEXITFINAL
;ret


.area _STACK
; stack is usally located at 0x01c4
27 changes: 27 additions & 0 deletions fix_kcc_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#! /usr/bin/env python3

"""
KCC-Dateien sollten eine Länge haben, die durch 128 teilbar ist
(= ganze 128 Byte-Blöcke)
"""

import sys

filename = sys.argv[1]

# einlesen
with open( filename, 'rb') as f_in:
data = bytearray( f_in.read())

# ergänzen
count = 0
while( len( data) % 128 != 0):
data.append( 0xff)
count += 1


# ausgeben
with open( filename, 'wb') as f_out:
f_out.write( bytes( data))

print( "%s: %s enhanced by %d bytes." % ( sys.argv[0], filename, count))
47 changes: 47 additions & 0 deletions header.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
;--------------------------------------------------------------------------
; header.s
;
; Copyright (C) 2016, Andreas Ziermann
;
; This library is free software; you can redistribute it and/or modify it
; under the terms of the GNU General Public License as published by the
; Free Software Foundation; either version 2, or (at your option) any
; later version.
;
; This library is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this library; see the file COPYING. If not, write to the
; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
; MA 02110-1301, USA.
;
; As a special exception, if you link this library with other files,
; some of which are compiled with SDCC, to produce an executable,
; this library does not by itself cause the resulting executable to
; be covered by the GNU General Public License. This exception does
; not however invalidate any other reasons why the executable file
; might be covered by the GNU General Public License.
;--------------------------------------------------------------------------

; specific header to automatic generate KCC format
; (which is used by simulator, disk, tape, USB, etc...)

.module header

.globl init
.globl s__CODE
.globl s__DATA

.area _KCC_HEADER (abs)

;.ascii ' ' ; name (placeholder 8 chars)
.ascii 'HELLO ' ; name (placeholder 8 chars)
.ascii 'KCC' ; extension
.ds 5 ; reserved
.db 0x03 ; 0x02 = load, 0x03 = autostart
.dw s__CODE ; load address
.dw s__DATA ; end address + 1
.dw init ; start address
18 changes: 18 additions & 0 deletions hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
*--------------------------------------------------------------------------
* hello.c - hello world for KC85/4 (/3 or /5) with SDCC
*
* Copyright (c) 2024 boert, CC BY-SA 2.0 de
*--------------------------------------------------------------------------
*/

#include <stdio.h> // printf
#include "caos.h" // crt


// Hauptprogramm
void main( void)
{
crt( CLS);
printf( "Hello User of KC85...\n");
}
32 changes: 32 additions & 0 deletions lib_caos/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
SRC_C = $(wildcard *.c)
OBJ_C = $(SRC_C:%.c=%.rel)

SRC_ASM = $(wildcard *.s)
OBJ_ASM = $(SRC_ASM:%.s=%.rel)


all: caos.lib
cp $< ..
cp caos.h ..

%.rel: %.s
@echo -n "Assemble: "
sdasz80 -plsgff -o $@ $<

%.rel: %.asm
@echo -n "Assemble: "
sdasz80 -plsgff -o $@ $<

%.asm: %.c
@echo -n "Compile: "
sdcc -mz80 --fomit-frame-pointer -Wall -S $< -o $@

%.lib: $(OBJ_ASM) $(OBJ_C)
@echo -n "Library: "
sdar -rc $@ $^


clean:
rm -f *.sym
rm -f *.lst
rm -f *.rel
Loading

0 comments on commit 834a8b1

Please sign in to comment.