From 7f961fee088e25fcefaabd3a8d342528d78a2ace Mon Sep 17 00:00:00 2001 From: Mijo Saftic Date: Tue, 31 Oct 2023 14:39:50 +0100 Subject: [PATCH] initial --- Makefile | 68 ++++++++++++++++++ README.md | 28 ++++++++ VERSION | 2 + src/cardram/cardram.asm | 148 ++++++++++++++++++++++++++++++++++++++++ src/cardram/defs.i | 11 +++ src/cardram/rev.i | 4 ++ 6 files changed, 261 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100644 VERSION create mode 100644 src/cardram/cardram.asm create mode 100644 src/cardram/defs.i create mode 100644 src/cardram/rev.i diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9d916a6 --- /dev/null +++ b/Makefile @@ -0,0 +1,68 @@ +# +# Note: +# Set VERSION and REVISION numbers in VERSION file. The date and version string for the +# reisdent module will be automatically generated. +# +# Build : +# ENVIRONMENT=internal make +# ENVIRONMENT=release make +# +# +# +PROJECT=cardram +VASM=vasmm68k_mot +VLINK=vlink -s +INCLUDE=include_i +SRC=src/$(PROJECT) +BUILD=build/$(PROJECT) +LIB=-Llib +AFLAGS=-DVERSION=$(VERSION) -DREVISION=$(REVISION) -m68000 -kick1hunks -Fhunk +GITHASH := $(shell git rev-parse --short HEAD) +DATESTRING := $(shell date +'%Y%m%d') +DATESTRING_COMMODORE := $(shell date +'%-d.%-m.%y') +VERSION = $(shell grep VERSION VERSION|cut -d= -f2) +REVISION = $(shell grep REVISION VERSION|cut -d= -f2) + + +.PHONY: clean deps builddir check-env + +cardram: deps + @echo "\n\n\n====== [ Build for CD1401 ] =========================================================\n" + $(VASM) -DCD1401 -D$(ENVIRONMENT) $(AFLAGS) -I$(INCLUDE) $(SRC)/$(PROJECT).asm -o $(BUILD)/$(PROJECT)-$(VERSION).$(REVISION)-CD1401-$(ENVIRONMENT).o + + + @echo "\n\n\n====== [ Link for CD1401 ] ==========================================================\n" + $(VLINK) -bamigahunk ${LIB} -lamiga -Bstatic $(BUILD)/$(PROJECT)-$(VERSION).$(REVISION)-CD1401-$(ENVIRONMENT).o -o $(BUILD)/$(PROJECT)-$(VERSION).$(REVISION)-CD1401-$(ENVIRONMENT).ld + + +# build dependencies +deps: check-env createrev builddir + +# make sure all required env vars are set +check-env: +ifndef VERSION + $(error VERSION is undefined) +endif +ifndef REVISION + $(error REVISION is undefined) +endif +ifndef ENVIRONMENT + $(error ENVIRONMENT is undefined) +endif + +# makes sure build dir exists +builddir: + mkdir -p build/$(PROJECT) + +# creates the version string include according to Commodore conventions +createrev: + @echo "\n====== [ Create revision ] " + @echo "VSTRING MACRO" > $(SRC)/rev.i + @echo " dc.b '$(PROJECT) $(VERSION).$(REVISION) ($(DATESTRING_COMMODORE))',13,10,0" >> $(SRC)/rev.i + @echo " CNOP 0,2" >> $(SRC)/rev.i + @echo " ENDM" >> $(SRC)/rev.i + +# delete all build artifacts +clean: + find $(BUILD) -name "*.o" -exec rm {} \; + find $(BUILD) -name "*.ld" -exec rm {} \; diff --git a/README.md b/README.md new file mode 100644 index 0000000..51caef5 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# CDTV cardram resident module + +This repo contains the source code to the CDTV cardram resident module that is part of the _CDTV OS 2.35 for Memory Cards_ update. + +## Background + +This resident module can be placed on a CDTV memory card (CD1401 or CD1405) and will the automatically add all the memory card space after this module to the system pool as Fast RAM. It needs to be loaded onto the memory card and will then automatically be initialized on startup if the CD1000 player is running off of exec.library 34.1001 or 37.201 (these are the CDTV OS ROM specific versions of exec that scan $E00000-$E7FFFF for resident modules) in combination with a Kickstart ROM version that does not exceed the corresponding exec.library in the CDTV OS ROM, i.e. only Kickstart 1.3 + CDTV OS 1.0 or Kickstart 2.x + CDTV OS 2.x is supported. Kickstart 3 is not supported. (See the CDTV OS 2.35 FAQ for more detailed information on why it does not work with Kickstart 3.x). + + +## Important Notes + +- If multiple resident modules are installed on the memory card, then this cardram module MUST be the last one in the list, because all the free memory after it will be used as Fast RAM. + +- If you add this to a a memory card, be sure to also mark the magic word at the beginning of the memoy card, otherwise cardmark.device will wipe your pretty resident module on system startup. Alternatively you can simply add the CDTV Land mcheader resident module at the beginning of your buildlist, which will take care of this for you. + +- Again, this (currently) does not work with Kickstart 3.x (see above). + +## Binary + +The loadable module can be downloaded from the Releases page. Alternatively, you can build and/or modify the module yourself. + +## How to build + +You need vasm and the Amiga NDK. To build the resident module issue the following command: + +```sh +ENVIRONMENT=release make cardram +``` \ No newline at end of file diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..4485dd7 --- /dev/null +++ b/VERSION @@ -0,0 +1,2 @@ +VERSION=1 +REVISION=0 diff --git a/src/cardram/cardram.asm b/src/cardram/cardram.asm new file mode 100644 index 0000000..718983c --- /dev/null +++ b/src/cardram/cardram.asm @@ -0,0 +1,148 @@ + ************************************************************************ + *** *** + *** -= COMMODORE CDTV ROM OPERATING SYSTEM =- *** + *** *** + ************************************************************************ + *** *** + *** CARDRAM - AUTO-ADDMEM CD1401/CD1405 *** + *** Copyright (c) 2023 CDTV Land. Published under GPLv3. *** + *** Written by Captain Future *** + *** *** + ************************************************************************ + + + INCLUDE exec/exec_lib.i + INCLUDE exec/execbase.i + INCLUDE exec/resident.i + INCLUDE exec/memory.i + INCLUDE defs.i + INCLUDE rev.i + + + ; This resident module automatically adds all free memory on the CD1401/CD1405 CDTV + ; memory card to the system RAM pool. It needs to be loaded onto the memory card + ; and will then automatically be initialized on startup if the CD1000 player is + ; running off of exec.library 34.1001 or 37.201 (these are the CDTV OS ROM specific + ; versions of exec that scan $E00000-$E7FFFF for resident modules). + + + ; IMPORTANT NOTE: + + ; If multiple resident modules are installed on the memory card, then this cardram + ; module MUST be the last one in the list! + + +;************************************************************************************************ +;* ROM TAG * +;************************************************************************************************ + +ROMTag: + dc.w RTC_MATCHWORD + dc.l ROMTag + dc.l EndSkip + dc.b RTF_COLDSTART + dc.b VERSION + dc.b NT_UNKNOWN + dc.b 111 ; priority + dc.l Name + dc.l IDString + dc.l Init + +IDString: + VSTRING + COPYRIGHT + + CNOP 0,2 + + +;************************************************************************************************ +;* FUNCTION * +;************************************************************************************************ + +Init: + movem.l a6-a2/d7-d2,-(sp) ; save registers + move.l #CARDBASE,a0 ; this is where cardmem starts + move.l #MAXCARDMEM,d0 ; we support a maximum of 512K + lea 0(a0,d0.l),a1 ; store the limit address + lea.l EndSkip(pc),a2 ; get first free address + move.l a2,d0 ; longword align the address + addq #3,d0 + and.l #$FFFFFFFC,d0 + movea.l d0,a2 ; and save it + bsr.s CheckSize ; determine size of free RAM + + + ; Add available card memory to the system free pool + + movea.l 4.w,a6 ; load ExecBase + move.l #MEMF_PUBLIC|MEMF_FAST,d1 ; set memory attributes + clr.l d2 ; priority + move.l a2,a0 ; base address + lea.l MemoryName(pc),a1 ; memory name + jsr _LVOAddMemList(a6) ; add the memory + movem.l (sp)+,d2-d7/a2-a6 ; restore regs + + rts + + +;************************************************************************************************ +;* FUNCTION * +;************************************************************************************************ + +CheckSize: + + ; A0 = address start + ; A1 = address limit + + ; We check for RAM at 1K intervals, starting from the first K boundary after this + ; resident module's end. This is why cardram needs to be the last resident module + ; on the memcard. Everything after it gets added to system RAM. + + move.l (a0),d2 ; save the first longword + + ; 1K align + + add.l #INTERVAL-1,d0 + and.l #BOUNDARY,d0 + sub.l #INTERVAL,d0 ; set up for loop + move.l d0,a0 + + move.l #TESTPATTERN,d0 ; set our test pattern + +.loop: + lea INTERVAL(a0),a0 ; get first/next address to test + cmp.l a0,a1 ; have we reached the limit? + bls.s .done ; yep, quit + + move.l d0,(a0) ; write test pattern to address + move.l (CARDBASE),d1 ; check for wrap around.. + cmp.l d1,d2 ; ..by checking if first longword is stll unchanged + bne.s .done ; we've wrapped around, we're done + cmp.l (a0),d0 ; check if test pattern was written (RAM checK) + beq.s .loop ; if RAM check OK go to next, else quit + +.done: + move.l d2,(CARDBASE) ; restore long word at base + move.l a0,d0 + lea.l EndSkip(pc),a0 + move.l a0,d1 + sub.l d1,d0 ; total free RAM + + rts + + +;************************************************************************************************ +;* DATA * +;************************************************************************************************ + +Name: + dc.b "cardram",0 + +MemoryName: + dc.b "CDTV Memory Card RAM",0 + + CNOP 0,2 + +EndSkip: + + END \ No newline at end of file diff --git a/src/cardram/defs.i b/src/cardram/defs.i new file mode 100644 index 0000000..6971c6b --- /dev/null +++ b/src/cardram/defs.i @@ -0,0 +1,11 @@ +COPYRIGHT MACRO + dc.b "Copyright (c) 2023 CDTV Land. ",0 + dc.b "Published under GPLv3 license. ",0 + dc.b "Written by Captain Future, CDTV Land.",$a,$d,0 + ENDM + +CARDBASE equ $00E00000 +MAXCARDMEM equ $00080000 +INTERVAL equ $00000400 +BOUNDARY equ (INTERVAL-1)^$FFFFFFFF +TESTPATTERN equ $AAAA5555 diff --git a/src/cardram/rev.i b/src/cardram/rev.i new file mode 100644 index 0000000..84f3e8f --- /dev/null +++ b/src/cardram/rev.i @@ -0,0 +1,4 @@ +VSTRING MACRO + dc.b 'cardram 1.0 (14.8.23)',13,10,0 + CNOP 0,2 + ENDM