add zmskit example for zsmkit v2

This commit is contained in:
Irmen de Jong 2024-11-28 23:31:01 +01:00
parent 189399d5f8
commit 53558f5c1d
18 changed files with 134 additions and 15 deletions

View File

@ -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",

View File

@ -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)
...

View File

@ -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.

Binary file not shown.

View File

@ -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.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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
}
}

View File

@ -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
}