From c9031ce5a9065c39477d08e6bcc5edbb7dcdd884 Mon Sep 17 00:00:00 2001 From: pancelor Date: Thu, 18 Apr 2024 01:28:34 -0700 Subject: [PATCH] wip sfx groundwork refs #5 --- .info.pod | Bin 888 -> 888 bytes baked/polyfill/sfx.lua | 3 +- main.lua | 2 +- src/import.lua | 72 ++++++++++++++++++++++++++++++++++++++--- src/tool.lua | 9 +++--- 5 files changed, 76 insertions(+), 10 deletions(-) diff --git a/.info.pod b/.info.pod index d88e442023d61a35d4a15a501efcc720a07dec0f..ea8b28ddef8abc60b611581bde276864e6f5fdd0 100644 GIT binary patch delta 13 Vcmeyt_JeK1E+$6P$-9~M0sty31*`x7 delta 13 Vcmeyt_JeK1E+$5k$-9~M0stx}1*-r6 diff --git a/baked/polyfill/sfx.lua b/baked/polyfill/sfx.lua index 1de9fac..b4d72ed 100644 --- a/baked/polyfill/sfx.lua +++ b/baked/polyfill/sfx.lua @@ -1,5 +1,6 @@ --[[pod_format="raw",created="2024-03-20 01:07:36",modified="2024-03-20 01:08:28",revision=2]] -- these functions just call the picotron functions, --- but your sfx/music is not ported (yet? help welcome!) +-- but your sfx/music is not ported yet -- help welcome! +-- see https://github.com/pancelor/p8x8/issues/5 and parse_p8_sfx() (inside p8x8's import.lua) p8env.sfx=sfx p8env.music=music diff --git a/main.lua b/main.lua index 4ac27e8..f8a51cf 100644 --- a/main.lua +++ b/main.lua @@ -26,7 +26,7 @@ include "src/export.lua" function _init() reset_state() --set up the window - pqn("hello!") + menuitem{ id = "clear", label = "\^:0f19392121213f00 Clear", diff --git a/src/import.lua b/src/import.lua index a995806..35d9bca 100644 --- a/src/import.lua +++ b/src/import.lua @@ -107,8 +107,8 @@ function parse_p8_map(filestr) for i=0,#mapdata/2-1 do local x,y = i%w,i\w if x>3 -- 0 or 1 + local volume = dd + local effect = ee + + -- TODO https://github.com/pancelor/p8x8/issues/5 + + -- > volume: 1-7 in pico-8 correspond to 8,10,18,20,28,30,38 in picotron + -- > pitch: octaves 0-5 in pico-8 seem to correspond to 2-7 in picotron + + -- effects: https://www.lexaloffle.com/dl/docs/picotron_synth.html#Effect_Commands + + --[[ + -- picotron .sfx format: + mysfx=fetch"/ram/cart/sfx/0.sfx" + ?type(mysfx) + --userdata + ?qq(mysfx:attribs()) + --196608 1 u8 1 + --196608==0x30000 + --https://www.lexaloffle.com/dl/docs/picotron_synth.html#Memory_Layout + --]] + end + end + end + + return ud +end + +--[[ +x = 0 +for b in bytes(clean[:8]): + cart.rom.set8(mem_sfx_info_addr(y, x), b) + x += 1 +x = 0 +for bph, bpl, bw, bv, be in nybble_groups(clean[8:], 5): + if x < 0x20: + value = bpl | ((bph & 0x3) << 4) | ((bw & 0x7) << 6) | ((bv & 0x7) << 9) | ((be & 0x7) << 12) | ((bw & 0x8) << 12) + cart.rom.set16(mem_sfx_addr(y, x), value) + x += 1 +y += 1 +--]] + + + -- returns the contents of a pico8 file section (e.g. __gfx__) -- returns the entire string, with newlines and all -- returns nil if the section can't be found diff --git a/src/tool.lua b/src/tool.lua index d2f7961..fcf8d63 100644 --- a/src/tool.lua +++ b/src/tool.lua @@ -6,7 +6,7 @@ function test(want,got) end -- 0=>"0", ... 15=>"f", 16=>"g", ... 31=>"v" -local function hex_from_num(val) +function hex_from_num(val) if 0<=val and val<=9 then return string.char(0x30+val) elseif 10<=val and val<=31 then @@ -20,19 +20,20 @@ end --test("h",hex_from_num(17)) -- "0"=>0, ... "f"=>15, "g"=>16, ... "v"=>31 -function num_from_hex(char) - local val = string.byte(char) +function num_from_hex(str, i) + local val = string.byte(str,i) if 0<=val-0x30 and val-0x30<=9 then return val-0x30 elseif 10<=val-97+10 and val-97+10<=31 then return val-97+10 else - assert(nil,"num_from_hex bad input: "..tostr(char)) + assert(nil,"num_from_hex bad input: "..tostr(str).." "..tostr(i)) end end --test(3,num_from_hex("3")) --test(15,num_from_hex("f")) --test(17,num_from_hex("h")) +--test(12,num_from_hex("abc",-1)) function rstrip(str,chars) local book = {}