Skip to content

Draft: Commodore 128 port #478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- DEFINE assigns HERE to a word in the word list and begins compilation.
- DEFCODE does the same as DEFINE, but begins a CODE: segment instead.
- V commands: A, R, +, -, HOME, e, C, D, s, S, H, L, M, ^w, f, F
- Native support for Commodore 128
- Split V and GFX code into common and platform-specific components
- PLATFORM identifies whether durexForth is running on a Commodore 64 or 128
### Fixed
- SP-X! had bug in most significant bit
- GFX: PEEK fetched bitmap pixels from ROM instead of RAM
Expand Down
116 changes: 78 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,55 +1,95 @@
C1541 = c1541
AS = acme
TAG = `git describe --tags --abbrev=0 || svnversion --no-newline`
TAG_DEPLOY_DOT = `git describe --tags --abbrev=0 --dirty=-M`
TAG_DEPLOY = `git describe --tags --abbrev=0 --dirty=_M | tr _. -_`
ASFLAGS :=

C1541 = c1541
AS = acme $(ASFLAGS)
TAG = $(shell git describe --tags --abbrev=0 || svnversion --no-newline)
TAG_DEPLOY_DOT = $(shell git describe --tags --abbrev=0 --dirty=-M)
TAG_DEPLOY = $(shell git describe --tags --abbrev=0 --dirty=_M | tr _. -_)

SRC_DIR = forth_src
SRC_NAMES = base debug v asm gfx gfxdemo rnd sin ls turtle fractals \
sprite doloop sys labels mml mmldemo sid spritedemo test testcore \
testcoreplus tester format require compat timer float viceutil turnkey \
wordlist
SRCS = $(addprefix $(SRC_DIR)/,$(addsuffix .fs,$(SRC_NAMES)))
SRCS_COMMON = $(wildcard $(SRC_DIR)/*.fs)
SRCS_C64 = $(wildcard $(SRC_DIR)/c64/*.fs)
SRCS_C128 = $(wildcard $(SRC_DIR)/c128/*.fs)

PETSRCS_COMMON = $(subst forth_src/,build/,$(SRCS_COMMON:%.fs=%.pet))
PETSRCS_C64 = $(subst forth_src/,build/,$(SRCS_C64:%.fs=%.pet))
PETSRCS_C128 = $(subst forth_src/,build/,$(SRCS_C128:%.fs=%.pet))

PETSRCS_ALL = $(PETSRCS_COMMON) $(PETSRCS_C64) $(PETSRCS_C128)

SRCNAME = $(patsubst %.pet,%,$(notdir $(1)))

EMPTY_FILE = _empty.txt
SEPARATOR_NAME1 = '=-=-=-=-=-=-=-=,s'
SEPARATOR_NAME2 = '=-------------=,s'
SEPARATOR_NAME3 = '=-=---=-=---=-=,s'

all: durexforth.d64
all: durexforth.d64 durexforth128.d64

deploy: durexforth.d64 cart.asm
rm -rf deploy
mkdir deploy
docs:
$(MAKE) -C docs
cp docs/durexforth.pdf deploy/durexforth-$(TAG_DEPLOY).pdf
cp durexforth.d64 deploy/durexforth-$(TAG_DEPLOY).d64
x64 -warp +confirmexit deploy/durexforth-$(TAG_DEPLOY).d64
# make cartridge
c1541 -attach deploy/durexforth-$(TAG_DEPLOY).d64 -read durexforth
mv durexforth build/durexforth
@$(AS) cart.asm

deploy: deploy/durexforth-$(TAG_DEPLOY).pdf deploy/durexforth-$(TAG_DEPLOY).d64 deploy/durexforth-$(TAG_DEPLOY).crt deploy/durexforth128-$(TAG_DEPLOY).d64

.PHONY: all clean docs deploy

deploy/durexforth-$(TAG_DEPLOY).pdf: docs
@mkdir -p deploy
cp docs/durexforth.pdf $@

# Precompile and save a packed Forth for release
deploy/durexforth-$(TAG_DEPLOY).d64: durexforth.d64
@mkdir -p deploy
cp $< $@
x64 -warp +confirmonexit $@

deploy/durexforth128-$(TAG_DEPLOY).d64: durexforth128.d64
@mkdir -p deploy
cp $< $@
x128 -warp +confirmonexit $@

# Build a cartridge image out of the precompiled Forth
deploy/durexforth-$(TAG_DEPLOY).crt: deploy/durexforth-$(TAG_DEPLOY).d64 cart.asm
c1541 -attach deploy/durexforth-$(TAG_DEPLOY).d64 -read durexforth build/durexforth
$(AS) cart.asm
cartconv -t simon -i build/cart.bin -o deploy/durexforth-$(TAG_DEPLOY).crt -n "DUREXFORTH $(TAG_DEPLOY_DOT)"

durexforth.d64: durexforth.prg $(EMPTY_FILE) $(PETSRCS_COMMON) $(PETSRCS_C64)
$(C1541) -format "durexforth,DF" d64 $@ \
-attach $@ -write durexforth.prg durexforth \
-attach $@ -write $(EMPTY_FILE) $(SEPARATOR_NAME1) \
-attach $@ -write $(EMPTY_FILE) $(TAG_DEPLOY_DOT),s \
-attach $@ -write $(EMPTY_FILE) $(SEPARATOR_NAME2) \
$(foreach f,$(PETSRCS_COMMON) $(PETSRCS_C64),-write $f $(call SRCNAME,$f)) \
-attach $@ -write $(EMPTY_FILE) $(SEPARATOR_NAME3)

durexforth128.d64: durexforth128.prg $(EMPTY_FILE) $(PETSRCS_COMMON) $(PETSRCS_C128)
$(C1541) -format "durexforth,DF" d64 $@ \
-attach $@ -write durexforth128.prg durexforth \
-attach $@ -write $(EMPTY_FILE) $(SEPARATOR_NAME1) \
-attach $@ -write $(EMPTY_FILE) $(TAG_DEPLOY_DOT),s \
-attach $@ -write $(EMPTY_FILE) $(SEPARATOR_NAME2) \
$(foreach f,$(PETSRCS_COMMON) $(PETSRCS_C128),-write $f $(call SRCNAME,$f)) \
-attach $@ -write $(EMPTY_FILE) $(SEPARATOR_NAME3)

durexforth.prg: *.asm
@$(AS) durexforth.asm

durexforth.d64: durexforth.prg Makefile ext/petcom $(SRCS)
touch $(EMPTY_FILE)
$(C1541) -format "durexforth,DF" d64 durexforth.d64 # > /dev/null
$(C1541) -attach $@ -write durexforth.prg durexforth # > /dev/null
$(C1541) -attach $@ -write $(EMPTY_FILE) $(SEPARATOR_NAME1) # > /dev/null
$(C1541) -attach $@ -write $(EMPTY_FILE) $(TAG_DEPLOY_DOT),s # > /dev/null
$(C1541) -attach $@ -write $(EMPTY_FILE) $(SEPARATOR_NAME2) # > /dev/null
# $(C1541) -attach $@ -write debug.bak
mkdir -p build
$(AS) -f cbm -DTARGET=64 -o $@ --vicelabels durexforth.lbl --report durexforth.lst durexforth.asm

durexforth128.prg: *.asm
$(AS) -f cbm -DTARGET=128 -o $@ --vicelabels durexforth.lbl --report durexforth.lst durexforth.asm

$(PETSRCS_ALL) : build/%.pet : $(SRC_DIR)/%.fs | build/header ext/petcom
@mkdir -p $(dir $@)
cat build/header $< | ext/petcom - > $@

.INTERMEDIATE: $(EMPTY_FILE) build/header

build/header:
@mkdir -p build
echo -n "aa" > build/header
@for forth in $(SRC_NAMES); do\
cat build/header $(SRC_DIR)/$$forth.fs | ext/petcom - > build/$$forth.pet; \
$(C1541) -attach $@ -write build/$$forth.pet $$forth; \
done;
$(C1541) -attach $@ -write $(EMPTY_FILE) $(SEPARATOR_NAME3) # > /dev/null
rm -f $(EMPTY_FILE)

$(EMPTY_FILE):
touch $@

clean:
$(MAKE) -C docs clean
Expand Down
69 changes: 55 additions & 14 deletions disk.asm
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

; DEVICE OPENW CLOSEW LOADB SAVEB INCLUDED

SETBNK = $f73f
READST = $ffb7
SETLFS = $ffba
SETNAM = $ffbd
UNTALK = $ffab
OPEN = $ffc0
CLOSE = $ffc3
CHKIN = $ffc6
Expand All @@ -39,7 +41,7 @@ SAVE = $ffd8

+BACKLINK "device", 6
lda LSB,x
sta $ba
sta CURRENT_DEVICE
inx
rts

Expand All @@ -62,7 +64,7 @@ _errorchread
tay
JSR SETNAM
LDA #$0F ; file number 15
LDX $BA ; last used device number
LDX CURRENT_DEVICE
BNE +
LDX #$08 ; default to device 8
+ LDY #$0F ; secondary address 15 (error channel)
Expand Down Expand Up @@ -106,6 +108,16 @@ LOADB
txa
pha

!if TARGET = 128 {
lda #0
ldx #0
jsr SETBNK

pla
pha
tax
}

lda MSB, x ; >destination
sta load_binary_laddr_hi
lda LSB, x ; <destination
Expand Down Expand Up @@ -136,9 +148,9 @@ load_binary_status = * + 1
tax
rts
.success:
lda $af
lda LOADSAVE_END+1
sta MSB, x
lda $ae
lda LOADSAVE_END
sta LSB, x
rts

Expand All @@ -164,7 +176,7 @@ load_binary_laddr_hi = *+1

.disk_io_setnamsetlfs ;reused by both loadb and saveb
jsr SETNAM
lda $ba ;last used device number
lda CURRENT_DEVICE
and #3 ;Make 0-3 possible numbers
ora #8 ;Transform to 8-B
tax
Expand All @@ -187,15 +199,23 @@ load_binary_laddr_hi = *+1
SAVEB
stx W

lda $ae
!if TARGET = 128 {
lda #0
ldx #0
jsr SETBNK

ldx W
}

lda LOADSAVE_END
pha
lda $af
lda LOADSAVE_END+1
pha

lda LSB+3, x ; range begin lo
sta $c1
sta LOADSAVE_ADDR
lda MSB+3, x ; range begin hi
sta $c2
sta LOADSAVE_ADDR+1

lda LSB+2, x ; range end lo
sta save_binary_srange_end_lo
Expand All @@ -221,9 +241,9 @@ save_binary_srange_end_hi = *+1
jsr _errorchread

pla
sta $af
sta LOADSAVE_END+1
pla
sta $ae
sta LOADSAVE_END

ldx W
inx
Expand All @@ -235,6 +255,18 @@ save_binary_srange_end_hi = *+1
; OPENW ( strptr strlen file# ) open file for writing
+BACKLINK "openw", 5
OPENW
!if TARGET = 128 {
txa
pha

lda #0
ldx #0
jsr SETBNK

pla
tax
}

lda LSB,x
sta W ; fileno
stx W2
Expand All @@ -248,7 +280,7 @@ OPENW

jsr SETNAM
lda W ; file number
ldx $ba ; last used device#
ldx CURRENT_DEVICE
tay ; secondary address
jsr SETLFS
jsr OPEN
Expand All @@ -266,7 +298,7 @@ OPENW
rts

.close
lda $b8 ; current file
lda CURRENT_LFN
jsr CLOSE
jmp CLRCHN

Expand Down Expand Up @@ -309,6 +341,12 @@ INCLUDED

txa
pha

!if TARGET = 128 {
lda #0
ldx #0
jsr SETBNK
}

.filelen = * + 1
lda #0
Expand All @@ -328,8 +366,11 @@ INCLUDED
tay
sty SOURCE_ID_LSB

ldx $ba ; last used device#
ldx CURRENT_DEVICE
jsr SETLFS

jsr CLRCHN

jsr OPEN
bcc +
jsr .close
Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ all: durexforth.pdf

SECTIONS = release_license.tex \
intro.tex tutorial.tex editor.tex words.tex gfx.tex sid.tex mml.tex \
asm.tex mnemonics.tex memmap.tex anatomy.tex
asm.tex c128.tex mnemonics.tex memmap.tex anatomy.tex
GENERATED = params-g.tex

durexforth.pdf: manual.tex $(SECTIONS)
Expand Down
Loading