Skip to content

Instantly share code, notes, and snippets.

@andrzejsliwa
Last active December 10, 2017 16:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrzejsliwa/c966269aa0cd2c6ce082 to your computer and use it in GitHub Desktop.
Save andrzejsliwa/c966269aa0cd2c6ce082 to your computer and use it in GitHub Desktop.
simple project for cross development with KICK ASSEMBLER for C64
DISK_NAME ?= $(notdir $(shell pwd))
DISK_NEW ?= true
VICE_OPTS ?=
VICE_PATH ?= x64
DEFAULT_TARGET ?=
ifdef VICE_REMOTE_MONITOR
ifeq ($(VICE_REMOTE_MONITOR),true)
VICE_OPTS += -remotemonitor -remotemonitoraddress localhost:6510
endif
endif
ifdef VICE_REU
VICE_REU_FILE ?= .reuimage
VICE_REU_SIZE ?= 16384
ifeq ($(VICE_REU),true)
VICE_OPTS += -reu -reusize $(VICE_REU_SIZE) -reuimage $(VICE_REU_FILE) -reuimagerw
endif
endif
ifdef VICE_CARTRR
VICE_OPTS += -cartrr $(VICE_CARTRR)
endif
SOURCE_DIR = src
BUILD_DIR = build
BACKUP_DIR = backup
DISK ?= $(BUILD_DIR)/$(DISK_NAME).d64
ASM_FILES = $(wildcard $(SOURCE_DIR)/*.s)
ASM_INCS = $(wildcard $(SOURCE_DIR)/*.i)
ASM_PRGS = $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_FILES:.s=.prg)))
ASM_SOURCES = $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_FILES:.s=.s)))
ASM_INCLUDES = $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_INCS:.i=.i)))
BAS_FILES = $(wildcard $(SOURCE_DIR)/*.bas)
BAS_PRGS = $(addprefix $(BUILD_DIR)/,$(notdir $(BAS_FILES:.bas=.prg)))
all:
make start $(DEFAULT_PRG)
.PHONY : disk start stop
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/%.prg: $(SOURCE_DIR)/%.s
java -jar kickass.jar \
$< \
-o $@ \
-afo \
-aom \
-showmem \
-vicesymbols \
-symbolfile \
-symbolfiledir $(BUILD_DIR)
$(BUILD_DIR)/%.prg: $(SOURCE_DIR)/%.bas
petcat -w2 -o $@ -- $<
clean:
@rm -r $(BUILD_DIR)
$(BACKUP_DIR):
mkdir -p $(BACKUP_DIR)
disk_backup: $(BACKUP_DIR)
$(shell mv $(DISK) $(BACKUP_DIR)/$(DISK_NAME)_$$(date '+%Y%m%d%H%M%S').d64)
disk_prepare: disk_backup $(BUILD_DIR)
c1541 -format $(DISK_NAME),DF d64 $(DISK)
define write_file_on_disk
c1541 -attach $(1) -write $(2) $(patsubst build/%.prg,%,$(2))
endef
define write_seq_file_on_disk
c1541 -attach $(1) -write $(2) "$(patsubst build/%,%,$(2)),s"
endef
compile: $(BUILD_DIR) $(ASM_PRGS)
convert: $(BUILD_DIR) $(BAS_PRGS)
ifeq ($(DISK_NEW),true)
disk: disk_prepare compile convert
else
disk: compile convert
endif
@$(foreach prg,$(ASM_PRGS),$(call write_file_on_disk,$(DISK),$(prg));)
@$(foreach prg,$(BAS_PRGS),$(call write_file_on_disk,$(DISK),$(prg));)
ifeq (start,$(firstword $(MAKECMDGOALS)))
# use the rest as arguments for "start"
START_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn argument to starting config
ifneq ($(START_ARGS),)
APP_NAME := $(firstword $(START_ARGS))
START_APP := $(DISK):$(APP_NAME)
endif
$(eval $(START_ARGS):;@:)
endif
start: stop disk run
run:
@$(VICE_PATH) $(VICE_OPTS) \
-moncommands $(BUILD_DIR)/breakpoints.txt \
-8 $(DISK) $(START_APP)
stop:
killall -TERM x64 || true
help::
@printf "%s\n" \
"c64_tmpx targets:" \
" compile - compile KICK ASSEMBLER source files (src/*.s) " \
" convert - convert BASIC source files (src/*.bas) " \
" disk - compile, convert, create disk file d64" \
" start - compile, convert, build disk image and start emulator" \
" start PROGNAME - compile, convert, build disk image and start emulator with PROGNAME " \
" stop - stop VICE emulator " \
" clean - clean build directory "
VICE_REMOTE_MONITOR = true
VICE_REU = true
VICE_CARTRR = cartridge/rr38p-tmp12reu.bin
VICE_PATH = /Applications/x64.app/Contents/MacOS/x64
VICE_OPTS = +confirmexit -rrbioswrite
DEFAULT_PRG = learning
include c64_kickass.mk

Usage

Targets

$ make help

c64_kickass targets:
  compile          - compile KICK ASSEMBLER source files (src/*.s)
  convert          - convert BASIC source files (src/*.bas)
  disk             - compile, convert, create disk file d64
  start            - compile, convert, build disk image and start emulator
  start PROGNAME   - compile, convert, build disk image and start emulator with PROGNAME
  stop             - stop VICE emulator
  clean            - clean build directory

Files

  • create files src/*.s for Kick Assembler
  • create files src/*.bas for BASIC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment