Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
CC = sdcc
ASM = sdasz80
PLATFORM = -mz80
EMULATOR = /Applications/openMSX.app/Contents/MacOS/openmsx -machine Philips_NMS_8255 -ext msxdos2 -diska emulation/msx-dos2/ -script emulation/boot.tcl -diskb bin/
EMULATOR = openmsx -machine Philips_NMS_8255 -ext msxdos2 -diska emulation/msx-dos2/ -diskb bin/ -script emulation/boot.tcl
#EMULATOR = /Applications/openMSX.app/Contents/MacOS/openmsx -machine C-BIOS_MSX2 -carta
HEXBIN = hex2bin

STARTUPDIR = startups
INCLUDEDIR = includes
LIBDIR = libs
STARTUPDIR = crt0msx
INCLUDEDIR = include
LIBDIR = lib
SRCDIR = src

# See startup files for the correct ADDR_CODE and ADDR_DATA
CRT0 = crt0msx_msxdos_advanced.s
ADDR_CODE = 0x0107
ADDR_CODE = 0x0192
ADDR_DATA = 0

VERBOSE = -V
CCFLAGS = $(VERBOSE) $(PLATFORM) --code-loc $(ADDR_CODE) --data-loc $(ADDR_DATA) \
--no-std-crt0 --opt-code-size --out-fmt-ihx
--no-std-crt0 --opt-code-size --out-fmt-ihx --std-c99
OBJECTS = $(CRT0) putchar.s getchar.s dos.s conio.c
SOURCES = main.c
OUTFILE = main.com
Expand Down Expand Up @@ -48,6 +48,7 @@ $(SOURCES):
build: main.ihx
@echo "Building $(OUTFILE)..."
@$(HEXBIN) main.ihx
mkdir -p bin
@mv main.bin bin/${OUTFILE}
@echo "Done."

Expand All @@ -56,7 +57,7 @@ clean:
rm -f *.asm *.bin *.cdb *.ihx *.lk *.lst *.map *.mem *.omf *.rst *.rel *.sym *.noi *.hex *.lnk *.dep
rm -f bin/$(OUTFILE)

emulator: $(OUTFILE)
emulator:
$(EMULATOR) &
#For ROM use:
#$(EMULATOR) $(OUTFILE) &
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Skeleton C project for MSX
Will create a "hello world" program running on MSX Z80 platform and emulated hardware. Following packages are required:
# Skeleton C project for MSX (SDCC)
Will create a simple program running on MSX Z80 platform and emulated hardware. Following packages are required:

* make
* [hex2bin](http://sourceforge.net/projects/hex2bin/) (1)
Expand All @@ -25,6 +25,8 @@ Check the makefile to select the correct startup file (ROM/COM). Current support
- MSX-DOS COM file (simple main)
- MSX-DOS COM file (main with arguments)

__The "main with arguments" runtime header has been fixed to support stardard C argument ordering. The application name is still not passed in to the application in the first argument. This will have to be fixed. Stay tuned.__

## Thanks
- [Avelino Herrera Morales](http://msx.atlantes.org/index_en.html) for providing the basic files needed to create a MSX-DOS executable.
- [Laurens Holst](http://map.grauw.nl/) for helping with hex2bin.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
;--- crt0.s for MSX-DOS - by Konami Man, 11/2004
; Advanced version: allows "int main(char** argv, int argc)",
; the returned value will be passed to _TERM on DOS 2,
; argv is always 0x100 (the startup code memory is recycled).
; Overhead: 112 bytes.
;
; Compile programs with --code-loc 0x170 --data-loc X
;--- crt0.s for MSX-DOS - by Konami Man, 11/2004
; Modified by algodesigner, 09/2021
;
; Advanced version: allows "int main(int argc, char** argv)",
; the returned value will be passed to _TERM on DOS 2,
; argv is always 0x100 (the startup code memory is recycled).
;
; Compile programs with --code-loc 0x192 --data-loc X
; X=0 -> global vars will be placed immediately after code
; X!=0 -> global vars will be placed at address X
; (make sure that X>0x100+code size)

.globl _main
.globl _main

.area _HEADER (ABS)
.area _HEADER (ABS)

.org 0x0100 ;MSX-DOS .COM programs start address

Expand All @@ -23,12 +24,23 @@ init: call gsinit
; and terminate each parameter with 0.
; MSX-DOS places the command line length at 0x80 (one byte),
; and the command line itself at 0x81 (up to 127 characters).

; Retrieve the full program path, our first parameter

ld hl,#0x100
ld de,#_HEAP_start
ld (hl),e
inc hl
ld (hl),d
ld hl,#envvar
ld bc,#0xff6b
call #5

;* Check if there are any parameters at all
;* Check if there are any command line parameters

ld a,(#0x80)
or a
ld c,#0
ld c,#1 ; c <- number of parameters
jr z,cont

;* Terminate command line with 0
Expand All @@ -51,22 +63,25 @@ init: call gsinit
ld de,#0xC000
ld bc,#parloopend-#parloop
ldir

;* Initialize registers and jump to the loop routine

ld hl,#0x81 ;Command line pointer
ld c,#0 ;Number of params found
ld ix,#0x100 ;Params table pointer

ld c,#1 ;Number of params found
ld ix,#0x102 ;Params table pointer +2 as the first entry
;is taken by the program name
ld de,#cont ;To continue execution at "cont"
push de ;when the routine RETs
jp 0xC000

envvar: .asciz "PROGRAM"

;>>> Command line processing routine begin

;* Loop over the command line: skip spaces

parloop: ld a,(hl)
parloop:
ld a,(hl)
or a ;Command line end found?
ret z

Expand Down Expand Up @@ -111,16 +126,16 @@ parloopend:

cont: ld hl,#0x100
ld b,#0
push bc ;Pass info as parameters to "main"
push hl
push bc ;Pass info as parameters to "main"

;--- Step 3: Call the "main" function
push de
ld de,#_HEAP_start
ld (_heap_top),de
pop de
push de
ld de,#_HEAP_start + 256 ; 256 bytes reserved for the program name
ld (_heap_top),de
pop de

call _main
call _main

;--- Step 4: Program termination.
; Termination code for DOS 2 was returned on L.
Expand All @@ -134,23 +149,23 @@ cont: ld hl,#0x100

;--- Program code and data (global vars) start here

;* Place data after program code, and data init code after data
;* Place data after program code, and data init code after data

.area _CODE
.area _DATA
.area _CODE
.area _DATA
_heap_top::
.dw 0
.dw 0

gsinit: .area _GSINIT

.area _GSFINAL
ret

;* These doesn't seem to be necessary... (?)
;* These doesn't seem to be necessary... (?)

;.area _OVERLAY
;.area _HOME
;.area _HOME
;.area _BSS
.area _HEAP
.area _HEAP

_HEAP_start::
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions libs/conio.c → lib/conio.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "../includes/types.h"
#include "../includes/conio.h"
#include "../include/types.h"
#include "../include/conio.h"


void puts(char *s) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions libs/heap.c → lib/heap.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


#include "../includes/types.h"
#include "../includes/heap.h"
#include "../include/types.h"
#include "../include/heap.h"


void *malloc(uint16_t size) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions libs/mem.c → lib/mem.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


#include "../includes/types.h"
#include "../includes/mem.h"
#include "../include/types.h"
#include "../include/mem.h"


void memcpy(uint8_t *dest, uint8_t *src, uint16_t n) {
Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 13 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#include "conio.h"
#include "dos.h"

void main(void) {
puts("Hello, world :-)\r\n");
void main(int argc, char *args[])
{
puts("argc=");
putdec8(argc);
puts("\r\n");
for (int i = 0; i < argc; i++) {
puts("argument[");
putdec8(i);
puts("]=");
puts(args[i]);
puts("\r\n");
}

exit(0);
}