diff --git a/compiler/test/TestCompilerOnExamples.kt b/compiler/test/TestCompilerOnExamples.kt index 81bea10e6..ba33343c3 100644 --- a/compiler/test/TestCompilerOnExamples.kt +++ b/compiler/test/TestCompilerOnExamples.kt @@ -114,8 +114,9 @@ class TestCompilerOnExamplesCx16: FunSpec({ "pcmaudio/vumeter", "sprites/dragon", "sprites/dragons", - "zsmkit/demo1", - "zsmkit/demo2", + "zsmkit_v1/demo1", + "zsmkit_v1/demo2", + "zsmkit_v2/demo", "banking/program", "amiga", "audioroutines", diff --git a/docs/source/todo.rst b/docs/source/todo.rst index df7dbbeca..6bde558f6 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -5,13 +5,11 @@ document the @R0 - @R15 register support for normal subroutine parameters (footg make a compiler switch to disable footgun warnings -upgrade zmskit example to use zsmkit v2 - what to do with bankof(): keep it? add another syntax like \`value or ^value to get the bank byte? --> added unary ^ operator as alternative to bankof() --> added unary << operator as alternative to addr() / lsb(x>>16) / lsw() -> added msw() and lsw() . note: msw() on a 24 bits constant can ALSO be used to get the bank byte because the value, while a word type, will be <=255 --> TODO document whatever remains of those! (and add to syntax files) +-> added unary ^ operator as alternative to bankof() +-> added unary << operator as alternative to lsw() / lsb(x>>16) +-> TODO document whatever remains of these! (and add to syntax files) ... diff --git a/examples/cx16/zsmkit/lib/zsmkit-0830.bin b/examples/cx16/zsmkit/lib/zsmkit-0830.bin deleted file mode 100644 index 7a4a97221..000000000 Binary files a/examples/cx16/zsmkit/lib/zsmkit-0830.bin and /dev/null differ diff --git a/examples/cx16/zsmkit/lib/zsmkit-8c00.bin b/examples/cx16/zsmkit/lib/zsmkit-8c00.bin deleted file mode 100644 index a272612cf..000000000 Binary files a/examples/cx16/zsmkit/lib/zsmkit-8c00.bin and /dev/null differ diff --git a/examples/cx16/zsmkit/README.txt b/examples/cx16/zsmkit_v1/README.txt similarity index 74% rename from examples/cx16/zsmkit/README.txt rename to examples/cx16/zsmkit_v1/README.txt index ae8ae2252..768985bcd 100644 --- a/examples/cx16/zsmkit/README.txt +++ b/examples/cx16/zsmkit_v1/README.txt @@ -1,8 +1,9 @@ -Prog8 ZSMKIT music player library integration ---------------------------------------------- +Prog8 ZSMKIT (v1) music player library integration +-------------------------------------------------- -ZSMKIT: https://github.com/mooinglemur/zsmkit +ZSMKIT V1: https://github.com/mooinglemur/zsmkit/tree/v1 (evolution of Zerobyte's ZSOUND, by MooingLemur). Read the README there! +Note: the current version of Zsmkit is V2. See below. DEMO1: LOW-RAM ZSMKIT + STREAMING @@ -37,8 +38,10 @@ streaming support or change the load address you'll have to build one yourself. See the "alternative builds" chapter. -FUTURE: ZSMKIT V2 ------------------ -If all goes well, there will be a zsmkit v2 in the future that has some important changes -that will make it much easier to integrate it into prog8 programs. Less RAM usage and -a fixed jump table location, among other changes. +ZSMKIT V2 +--------- +Zsmkit v2 is current and has some important changes that will make it much easier +to integrate it into prog8 programs. Less RAM usage and a fixed jump table location, +among other changes. However, it requires the ZSM to be loaded in Ram completely +because it has no streaming support anymore. So Zsmkit v1 might still have some uses. + diff --git a/examples/cx16/zsmkit/demo1.p8 b/examples/cx16/zsmkit_v1/demo1.p8 similarity index 100% rename from examples/cx16/zsmkit/demo1.p8 rename to examples/cx16/zsmkit_v1/demo1.p8 diff --git a/examples/cx16/zsmkit/demo2.p8 b/examples/cx16/zsmkit_v1/demo2.p8 similarity index 100% rename from examples/cx16/zsmkit/demo2.p8 rename to examples/cx16/zsmkit_v1/demo2.p8 diff --git a/examples/cx16/zsmkit/music/MUSIC.ZSM b/examples/cx16/zsmkit_v1/music/MUSIC.ZSM similarity index 100% rename from examples/cx16/zsmkit/music/MUSIC.ZSM rename to examples/cx16/zsmkit_v1/music/MUSIC.ZSM diff --git a/examples/cx16/zsmkit/music/PAUSE.ZSM b/examples/cx16/zsmkit_v1/music/PAUSE.ZSM similarity index 100% rename from examples/cx16/zsmkit/music/PAUSE.ZSM rename to examples/cx16/zsmkit_v1/music/PAUSE.ZSM diff --git a/examples/cx16/zsmkit/zsmkit_high.p8 b/examples/cx16/zsmkit_v1/zsmkit_high.p8 similarity index 100% rename from examples/cx16/zsmkit/zsmkit_high.p8 rename to examples/cx16/zsmkit_v1/zsmkit_high.p8 diff --git a/examples/cx16/zsmkit/zsmkit_low.p8 b/examples/cx16/zsmkit_v1/zsmkit_low.p8 similarity index 100% rename from examples/cx16/zsmkit/zsmkit_low.p8 rename to examples/cx16/zsmkit_v1/zsmkit_low.p8 diff --git a/examples/cx16/zsmkit_v2/MUSIC.ZSM b/examples/cx16/zsmkit_v2/MUSIC.ZSM new file mode 100644 index 000000000..8f5eb4272 Binary files /dev/null and b/examples/cx16/zsmkit_v2/MUSIC.ZSM differ diff --git a/examples/cx16/zsmkit_v2/README.txt b/examples/cx16/zsmkit_v2/README.txt new file mode 100644 index 000000000..26f05d97b --- /dev/null +++ b/examples/cx16/zsmkit_v2/README.txt @@ -0,0 +1,14 @@ +Prog8 ZSMKIT (v2) music player library integration +-------------------------------------------------- + +ZSMKIT V2: https://github.com/mooinglemur/zsmkit +Advanced music and sound effects engine for the Commander X16 +Evolution of Zerobyte's ZSOUND, by MooingLemur. Read the README there! + + +DEMO PROGRAM +------------ +The demo program loads the zsmkit player program in HiRAM bank 1. +The ZSM music file is read into memory too starting from bank 2. +The zmskit library routines are defined in zsmkit.p8 as extsubs, +using prog8's automatic ram banking mechanism. diff --git a/examples/cx16/zsmkit_v2/SONG1.ZSM b/examples/cx16/zsmkit_v2/SONG1.ZSM new file mode 100644 index 000000000..c37db7f7e Binary files /dev/null and b/examples/cx16/zsmkit_v2/SONG1.ZSM differ diff --git a/examples/cx16/zsmkit_v2/SONG2.ZSM b/examples/cx16/zsmkit_v2/SONG2.ZSM new file mode 100644 index 000000000..37cc196d8 Binary files /dev/null and b/examples/cx16/zsmkit_v2/SONG2.ZSM differ diff --git a/examples/cx16/zsmkit_v2/ZSMKIT-A000.BIN b/examples/cx16/zsmkit_v2/ZSMKIT-A000.BIN new file mode 100644 index 000000000..eacb09bbb Binary files /dev/null and b/examples/cx16/zsmkit_v2/ZSMKIT-A000.BIN differ diff --git a/examples/cx16/zsmkit_v2/demo.p8 b/examples/cx16/zsmkit_v2/demo.p8 new file mode 100644 index 000000000..6d4dc04ad --- /dev/null +++ b/examples/cx16/zsmkit_v2/demo.p8 @@ -0,0 +1,66 @@ +%import textio +%import diskio +%import palette +%import zsmkit +%zeropage basicsafe + +;; Proof Of Concept ZSM player using zsmkit v2 by MooingLemur +;; zsmkit bank is hardcoded in the module import above +main { + ubyte[255] zsmkit_lowram + + sub start() { + ; load zsmkit in bank 1 and the music starting from bank 2 onwards. + cx16.rambank(zsmkit.ZSMKitBank) + void diskio.load_raw("zsmkit-a000.bin",$A000) + cx16.rambank(2) + void diskio.load_raw("music.zsm",$A000) + ;;void diskio.load_raw("song2.zsm",$A000) + + zsmkit.zsm_init_engine(&zsmkit_lowram) + + setup_isr() + play_music() + } + + sub setup_isr() { + ;; You could use zsmkit.zsmkit_setisr() and be done with it + ;; but here's an example of a custom ISR. + ;; Note that jsrfar is unsafe to call in a handler, so the ISR + ;; uses zsmkit.zsm_tick_isr() with a manual bank change + sys.set_irq(&irq.handler) + } + + sub play_music() { + uword zsmptr + ubyte zsmbank + + txt.cls() + + zsmkit.zsm_setbank(0, 2) + zsmkit.zsm_setmem(0, $A000) + + zsmkit.zsm_play(0) + repeat { + sys.waitvsync() + void, zsmptr, zsmbank = zsmkit.zsm_getptr(0) + txt.home() + txt.print_ubhex(zsmbank, true) + txt.print(":") + txt.print_uwhex(zsmptr, false) + } + } +} + +irq { + sub handler() -> bool { + ubyte savebank + + savebank = cx16.getrambank() + cx16.rambank(zsmkit.ZSMKitBank) + zsmkit.zsm_tick_isr(0) ; NOTE that zsm_tick() is not allowed in a handler + cx16.rambank(savebank) + + return true + } +} diff --git a/examples/cx16/zsmkit_v2/zsmkit.p8 b/examples/cx16/zsmkit_v2/zsmkit.p8 new file mode 100644 index 000000000..59952fca6 --- /dev/null +++ b/examples/cx16/zsmkit_v2/zsmkit.p8 @@ -0,0 +1,37 @@ +zsmkit { + const ubyte ZSMKitBank = 1 + extsub @bank ZSMKitBank $A000 = zsm_init_engine(uword lowram @XY) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A003 = zsm_tick(ubyte type @A) clobbers(A, X, Y) + extsub $A003 = zsm_tick_isr(ubyte type @A) clobbers(A, X, Y) + + extsub @bank ZSMKitBank $A006 = zsm_play(ubyte prio @X) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A009 = zsm_stop(ubyte prio @X) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A00C = zsm_rewind(ubyte prio @X) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A00F = zsm_close(ubyte prio @X) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A012 = zsm_getloop(ubyte prio @X) -> bool @Pc, uword @XY, ubyte @A + extsub @bank ZSMKitBank $A015 = zsm_getptr(ubyte prio @X) -> bool @Pc, uword @XY, ubyte @A + extsub @bank ZSMKitBank $A018 = zsm_getksptr(ubyte prio @X) clobbers(A) -> uword @XY + extsub @bank ZSMKitBank $A01B = zsm_setbank(ubyte prio @X, ubyte bank @A) + extsub @bank ZSMKitBank $A01E = zsm_setmem(ubyte prio @X, uword data_ptr @AY) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A021 = zsm_setatten(ubyte prio @X, ubyte value @A) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A024 = zsm_setcb(ubyte prio @X, uword func_ptr @AY) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A027 = zsm_clearcb(ubyte prio @X) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A02A = zsm_getstate(ubyte prio @X) clobbers(X) -> bool @Pc, bool @Pz, uword @AY + extsub @bank ZSMKitBank $A02D = zsm_setrate(ubyte prio @X, uword rate @AY) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A030 = zsm_getrate(ubyte prio @X) clobbers() -> uword @AY + extsub @bank ZSMKitBank $A033 = zsm_setloop(ubyte prio @X, bool loop @Pc) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A036 = zsm_opmatten(ubyte prio @X, ubyte channel @Y, ubyte value @A) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A039 = zsm_psgatten(ubyte prio @X, ubyte channel @Y, ubyte value @A) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A03C = zsm_pcmatten(ubyte prio @X, ubyte value @A) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A03F = zsm_set_int_rate(ubyte value @A, ubyte frac @Y) clobbers(A, X, Y) + extsub @bank ZSMKitBank $A042 = zsm_getosptr(ubyte prio @X) clobbers(A) -> uword @XY + extsub @bank ZSMKitBank $A045 = zsm_getpsptr(ubyte prio @X) clobbers(A) -> uword @XY + extsub @bank ZSMKitBank $A048 = zcm_setbank(ubyte slot @X, ubyte bank @A) + extsub @bank ZSMKitBank $A04B = zcm_setmem(ubyte slot @X, uword data_ptr @AY) clobbers(A) + extsub @bank ZSMKitBank $A04E = zcm_play(ubyte slot @X, ubyte volume @A) clobbers(A, X) + extsub @bank ZSMKitBank $A051 = zcm_stop() clobbers(A) + + extsub @bank ZSMKitBank $A054 = zsmkit_setisr() clobbers(A) + extsub @bank ZSMKitBank $A057 = zsmkit_clearisr() clobbers(A) + extsub @bank ZSMKitBank $A05A = zsmkit_version() -> ubyte @A, ubyte @X +}