2
0
Fork 0

Added basic build system

This commit is contained in:
Willem 2018-11-29 22:18:47 +01:00
parent 11eef7bd83
commit b3f6e6d954
8 changed files with 596 additions and 31 deletions

46
.gitignore vendored
View file

@ -1,34 +1,18 @@
# ---> C syntax: glob
# Object files
*.o
*.ko
*.obj
*.elf
# Precompiled Headers # Project ignores
*.gch bin
*.pch bin/**
old
old/**
build/local.inc.mk
# Libraries # IDE ignores
*.lib .project
*.a .vs/
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
# File ignores
*.log
*.bak
*.zip
*.tar.gz

56
Makefile Normal file
View file

@ -0,0 +1,56 @@
#
# Single top level makefile
#
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
MODULES := $(call rwildcard, src, */0module.mk)
MODULES_LIB := $(call rwildcard, src, */0module.lib.mk)
-include build/local.inc.mk
include build/env.inc.mk
include $(MODULES_LIB)
include $(MODULES)
.PHONY: all
all:
@echo TODO: All is build.
.PHONY: test
test:
@echo TODO: Testing
.PHONY: clean
clean:
@echo === Cleaning
@test $(PATH_BIN) && $(RM) -r $(PATH_BIN);
define mod_mkdir
@echo === Create module build folder.
$(MKDIR) $(1)
endef
define mod_compile_asm
@echo === Compile module asm.
$(SDASM) $(SDASM_FLAGS) -I$(LIBASM_SRC)/include $(1) $(2)
endef
define mod_link_asm_lib
@echo === Link module asm lib.
$(SDAR) $(SDAR_FLAGS) $(1) $(2)
endef
define mod_link_asm_dos
@echo === Link module asm dos.
$(SDCC) $(SDCC_FLAG_CPU) --no-std-crt0 --code-loc 0x0100 -o $(1) $(2)
endef
#-l$(LIBASM_LINK)
define mod_hex2com
@echo === Convert to binary
cd $(dir $(1)) && $(H2B) -e com $(notdir $(1));
@sha1sum $(2);
@echo === Done $(notdir $(2))
endef

36
build/env.inc.mk Normal file
View file

@ -0,0 +1,36 @@
# Fill in all paths
PATH_SRC ?= src
PATH_BIN ?= bin
PATH_HEX2BIN ?= /usr/bin
PATH_SDCC ?= /usr/bin
PATH_CURRENT ?= $(dir $(lastword $(MAKEFILE_LIST)))
# Build tools
H2B ?= $(PATH_HEX2BIN)/hex2bin
SDCC ?= $(PATH_SDCC)/sdcc
SDASM ?= $(PATH_SDCC)/sdasz80
SDAR ?= $(PATH_SDCC)/sdar
SDCC_FLAG_CPU ?= -mz80
SDCC_FLAG_LD ?= --nostdinc
SDASM_FLAGS ?= -g -l -c -o
SDAR_FLAGS ?= -rc
# OS cmds
ifeq ($(OS),Windows_NT)
RM = del /F /Q
RMDIR = -RMDIR /S /Q
MKDIR = -mkdir
ERRIGNORE = 2>NUL || true
SEP=\\
else
RM = rm -rf
RMDIR = rm -rf
MKDIR = mkdir -p
ERRIGNORE = 2>/dev/null
SEP=/
endif
# Remove space after separator
PSEP = $(strip $(SEP))

View file

@ -0,0 +1,9 @@
# Local env included makefile
# This file should be ignored in version control
# note: the ?= is so you can override those again in cmdline.
#
# Change to local installations.
#PATH_SDCC ?= /usr/bin
#PATH_HEX2BIN ?= /usr/bin

28
src/dist-run/0module.mk Normal file
View file

@ -0,0 +1,28 @@
DIST_RUN_NAME := dist-run
DIST_RUN_BIN := $(PATH_BIN)/$(DIST_RUN_NAME)
DIST_RUN_SRC := $(PATH_SRC)/$(DIST_RUN_NAME)
DIST_RUN_INC := autoexec.bat COMMAND.COM MSXDOS.SYS
DIST_RUN_INC_BIN := $(patsubst %,$(DIST_RUN_BIN)/%,$(DIST_RUN_INC))
DIST_RUN_INC_SRC := $(patsubst %,$(DIST_RUN_SRC)/%,$(DIST_RUN_INC))
DIST_RUN_DEP_TAR := $(PATH_BIN)/dist.tar.gz
DIST_RUN_DEP := $(DIST_RUN_BIN)/tara.com
$(DIST_RUN_BIN):
$(call mod_mkdir,$(DIST_RUN_BIN))
$(DIST_RUN_BIN)/autoexec.bat: $(DIST_RUN_SRC)/autoexec.bat | $(DIST_RUN_BIN)
unix2dos -n $< $@;
$(DIST_RUN_BIN)/COMMAND.COM: $(DIST_RUN_SRC)/COMMAND.COM | $(DIST_RUN_BIN)
cp $< $@;
$(DIST_RUN_BIN)/MSXDOS.SYS: $(DIST_RUN_SRC)/MSXDOS.SYS | $(DIST_RUN_BIN)
cp $< $@;
$(DIST_RUN_DEP): $(DIST_RUN_DEP_TAR) | $(DIST_RUN_BIN)
cp $(PATH_BIN)/dist/* $(DIST_RUN_BIN);
$(DIST_RUN_NAME): $(DIST_RUN_INC_BIN) $(DIST_RUN_DEP)
openmsx -machine Philips_NMS_8250 -ext video9000 -ext ram4mb -ext ide -diska $(DIST_RUN_BIN);

33
src/dist/0module.mk vendored Normal file
View file

@ -0,0 +1,33 @@
DIST_NAME := dist
DIST_SRC := $(PATH_SRC)/$(DIST_NAME)
DIST_BIN := $(PATH_BIN)/$(DIST_NAME)
DIST_OUT := $(PATH_BIN)/$(DIST_NAME).tar.gz
DIST_INC := ALL.SR8 ASCII.SR8 readme.txt VELD.SR8 VELDBACK.4BP
DIST_INC_BIN := $(patsubst %,$(DIST_BIN)/%,$(DIST_INC))
DIST_INC_SRC := $(patsubst %,$(DIST_SRC)/%,$(DIST_INC))
DIST_TARA_BIN := $(DIST_BIN)/tara.com
DIST_TARA_SRC := $(PATH_BIN)/tara/tara.com
$(DIST_BIN):
$(call mod_mkdir,$(DIST_BIN))
$(DIST_BIN)/ALL.SR8: $(DIST_SRC)/ALL.SR8 | $(DIST_BIN)
cp $< $@;
$(DIST_BIN)/ASCII.SR8: $(DIST_SRC)/ASCII.SR8 | $(DIST_BIN)
cp $< $@;
$(DIST_BIN)/VELD.SR8: $(DIST_SRC)/VELD.SR8 | $(DIST_BIN)
cp $< $@;
$(DIST_BIN)/VELDBACK.4BP: $(DIST_SRC)/VELDBACK.4BP | $(DIST_BIN)
cp $< $@;
$(DIST_BIN)/readme.txt: $(DIST_SRC)/readme.txt | $(DIST_BIN)
cp $< $@;
#$(DIST_INC_BIN): $(DIST_INC_SRC) | $(DIST_BIN)
# cp $< $@;
$(DIST_TARA_BIN): $(DIST_TARA_SRC) | $(DIST_BIN)
cp $< $@;
$(DIST_OUT): $(DIST_INC_BIN) $(DIST_TARA_BIN)
cd $(DIST_BIN) && tar -czvf ../../$(DIST_OUT) *;

20
src/makelib/0module.mk Normal file
View file

@ -0,0 +1,20 @@
MAKELIB_NAME := makelib
MAKELIB_SRC := $(PATH_SRC)/$(MAKELIB_NAME)
MAKELIB_BIN := $(PATH_BIN)/$(MAKELIB_NAME)
MAKELIB_HEX := $(MAKELIB_BIN)/$(MAKELIB_NAME).hex
MAKELIB_COM := $(MAKELIB_BIN)/$(MAKELIB_NAME).com
MAKELIB_RELS := $(MAKELIB_BIN)/$(MAKELIB_NAME).rel
MAKELIB_CODE := $(MAKELIB_SRC)/$(MAKELIB_NAME).asm
$(MAKELIB_BIN):
$(call mod_mkdir,$(MAKELIB_BIN))
$(MAKELIB_BIN)/%.rel: $(MAKELIB_SRC)/%.asm | $(MAKELIB_BIN)
$(call mod_compile_asm,$@,$<)
$(MAKELIB_HEX): $(MAKELIB_RELS)
$(call mod_link_asm_dos,$(MAKELIB_HEX),$(MAKELIB_RELS))
$(MAKELIB_COM): $(MAKELIB_HEX)
$(call mod_hex2com,$(MAKELIB_HEX),$(MAKELIB_COM))

399
src/makelib/makelib.asm Normal file
View file

@ -0,0 +1,399 @@
; Maak een LIBrary aan van files
; org #0100
bdos .equ #05
setdta .equ 26 ; zet lees/schrijf-adres
open_file .equ 15 ; open file
close_file .equ 16 ; sluit file
create_file .equ 22 ; maak file aan
read_block .equ 39 ; laad van disk
write_block .equ 38 ; schrijf naar disk
entry_length .equ 11 + 2 + 3
.area _CODE
call count_files ; tel aantal files
ld (files),bc
call calc_length ; bereken lengte
; directory
ld (dir_length),hl
call make_dir ; maak directory
call save_dir ; bewaar directory
call store_files ; bewaar files
ld de,#fcb2
ld c,#close_file
call bdos ; klaar!
ret
; Tel aantal files
; In: -
; Uit: BC: aantal files
; Verandert: AF,BC,DE,HL
count_files: ld hl,#file_names
ld bc,#0
ld de,#11
count_files1: ld a,(hl)
or a
ret z
inc bc
add hl,de
jr count_files1
; Bereken lengte directory
; In: BC: aantal files
; Uit: HL: lengte directory
; Verandert: AF, BC, DE, HL
calc_length: ld hl,#3
ld de,#entry_length
calc_length1: ld a,b
or c
ret z
add hl,de
dec bc
jr calc_length1
; Maak directory
; In: HL: lengte directory
; Uit: -
; Verandert: alles
make_dir: ld (getal1),hl
ld hl,#0
ld (getal1+2),hl
ld hl,#file_names
ld de,#directory
ld bc,(files)
make_dir1: push bc
push hl
push de
ld bc,#11
ld de,#fname1
ldir ; filenaam naar FCB
pop de
pop hl
ld bc,#11
ldir ; filenaam naar directory
push hl
push de
ld de,#fcb1
ld c,#open_file
call bdos
ld de,#fcb1
ld c,#close_file
call bdos
pop de
ld hl,(length1)
ld a,l
ld (de),a
inc de
ld a,h
ld (de),a
inc de
ld ix,#getal1 ; bewaar positie in file
ld a,(IX)
ld (de),a
inc de
ld a,(IX)
ld (de),a
inc de
ld a,(IX)
ld (de),a
inc de
push de
ld iy,#getal2
ld (IY),l
ld (IY),h
ld ix,#getal1
call add_32bit
pop de
pop hl
pop bc
dec bc
ld a,b
or c
jp nz,make_dir1
xor a
ld (de),a
ret
; Bewaar directory
; In: -
; Uit: -
; Verandert: alles
save_dir: ld hl,#lib_name
ld de,#fname2
ld bc,#11
ldir
ld de,#fcb2
ld c,#create_file
call bdos ; cre er file
call intfcb2
ld de,#files
ld c,#setdta
call bdos
ld de,#fcb2
ld c,#write_block
ld hl,(dir_length)
call bdos ; schrijf directory weg
ret
; Bewaar files in .LIB-file
; In: -
; Uit: -
; Verandert: AF, BC, DE, HL
store_files: ld bc,(files)
ld hl,#file_names
store_files1: push bc
ld bc,#11
ld de,#fname1
ldir
PUSH HL
LD HL,#fname1
LD B,#11
CALL PUT_TXT
LD HL,#RETTXT
LD B,#2
CALL PUT_TXT
POP HL
PUSH HL
call clrfcb1
ld c,#open_file
ld de,#fcb1
call bdos
call intfcb1
ld hl,(length1)
call copy_file ; kopieer file
ld de,#fcb1
ld c,#close_file
call bdos
pop hl
pop bc
dec bc
ld a,b
or c
jp nz,store_files1
ret
; Copieer file naar .LIB-file
; In: HL: lengte file
; Uit: -
; Verandert: AF, BC, DE, HL
copy_file: push hl
ld c,#setdta
ld de,#directory
call bdos
pop hl
copy_file1: ld de,#32768
xor a
sbc hl,de ; file >32768 bytes?
jp c,copy_file2 ; Nee, copieer rest
push hl
ld hl,#32768
ld de,#fcb1
ld c,#read_block
call bdos
ld hl,#32768
ld de,#fcb2
ld c,#write_block
call bdos
pop hl
jp copy_file1
copy_file2: add hl,de
push hl
ld de,#fcb1
ld c,#read_block
call bdos
pop hl
ld de,#fcb2
ld c,#write_block
call bdos
ret
; Tel twee 32-bits getallen op
; In: IX: adres getal 1
; IY: adres getal 2
; Uit: getal 1 gevuld met resultaat
; Verandert: BC,DE,HL
add_32bit: ld l,(IX)
ld h,(IX)
ld e,(IY)
ld d,(IY)
ld c,(IX)
ld b,(IX)
add hl,de
jr nc,add_32bit1
inc bc
add_32bit1: ld (IX),l
ld (IX),h
ld l,(IY)
ld h,(IY)
add hl,bc
ld (IX),l
ld (IX),h
ret
; Maak FCB 1 schoon
; In: -
; Uit: -
; Verandert: AF, BC, DE, HL
clrfcb1: ld hl,#fcbdat1
ld bc,#25
xor a
ld (hl),a
ld de,#fcbdat1 + 1
ldir
ret
; Initialiseer FCB 1
; In: -
; Uit: -
; Verandert: AF, HL
intfcb1: ld hl,#0
ld (fcb1 + 12),hl
ld (fcb1 + 33),hl
ld (fcb1 + 35),hl
xor a
ld (fcb1 + 32),a
inc hl
ld (fcb1 + 14),hl
ret
; Initialiseer FCB 2
; In: -
; Uit: -
; Verandert: AF, HL
intfcb2: ld hl,#0
ld (fcb2 + 12),hl
ld (fcb2 + 33),hl
ld (fcb2 + 35),hl
xor a
ld (fcb2 + 32),a
inc hl
ld (fcb2 + 14),hl
ret
; HL=TXT
; B=LENGHTE
PUT_TXT:
LD A,(HL)
LD E,A
LD C,#2
PUSH HL
PUSH BC
CALL bdos
POP BC
POP HL
INC HL
DJNZ PUT_TXT
RET
RETTXT: .db 0x0A,0x0D
getal1: .dw 0,0 ; opslagplaats voor de twee
getal2: .dw 0,0 ; 32-bits getallen
dir_length: .dw 0 ; lengte van directory
; Het eerste FCB
fcb1: .db 0 ; drive (0=default, 1 = A:)
fname1: .str " "
fcbdat1: .db 0,0,0,0
length1: .db 0,0,0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0,0,0
; Het tweede FCB
fcb2: .db 0 ; drive (0=default, 2 = B:)
fname2: .str " "
.db 0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0
; Naam van de te maken .LIB-file
lib_name: .str "DOME 000"
; Lijst met files die in de .LIB-file moeten
file_names:
.str "BIOS DAT"
.str "LOADER DAT"
.str "WAVEDRV COM"
.str "PARAGON ZOP"
.str "PRESENTSZOP"
.str "DOME ZOP"
.str "MMENU DAT"
.str "ST_MENU1ZOP" ; GFX START MENU
.str "ST_MENU2ZOP" ; GFX START MENU_ROOD
.str "UNITTOT ZOP" ; GFX UNITS
.str "PAGE5 ZOP" ; GFX BUILDINGS
.str "BLAKEN4 ZOP" ; GFX ACHTERGROND
.str "DOME DAT" ; DOME ENGINE
.str "MENU DAT" ; DOME_MENU_CALL CODE
.str "MENU ZOP" ; DOME_MENU_CALL GFX
;DB "CHOOSE DAT" ; LEVEL CHOOSER CODE
;DB "CHOOSE1 ZOP" ; LEVEL CHOOSEE GFX1
;DB "CHOOSE2 ZOP" ; LEVEL CHOOSER GFX2
.str "BRIEF ZOP"
.str "VELD 001"
.str "TANKTAB 001"
.str "CODE 001" ; MAXIMAAL 999 VELDEN
.str "VELD 002"
.str "TANKTAB 002"
.str "CODE 002"
.db 0
; 0 = laatste gehad
files: .dw 0 ; bewaarplaats aantal files
directory: nop
.area _DATA