package.path=package.path..";C:\\Users\\micro\\AppData\\Roaming\\com.nesbox.tic\\TIC-80\\rift\\?.lua"	-- jtruk
package.path=package.path..";C:\\Users\\Ronan\\AppData\\Roaming\\com.nesbox.tic\\TIC-80\\rift\\?.lua"	-- Mantratronic

local R={}
require("./sys/sys")(R)
require("./sound/noise")(R)

T=0
function TIC()
	R.tryBreak()
    cls()

    local freq=R.noise.getFreqA()
    local addSemis=(T//40)%12
    freq=R.noise.addFreqSemis(freq,addSemis)

    R.noise.setWaveUs(0,R.noise.makeWaveUTriangle())
    R.noise.setFreq(0,freq)
    R.noise.setVolU(0,1)

    R.noise.setWaveUs(1,R.noise.makeWaveUSin())
    local addSemis=-24+(T//20)%12
    freq=R.noise.addFreqSemis(freq,addSemis)
    R.noise.setFreq(1,freq)
    R.noise.setVolU(1,.5)

    if T%40 < 4 then
        R.noise.setVolU(2,.5)
    end

    if T%4 < 1 then
        R.noise.setWaveUs(3,R.noise.makeWaveUPulse())
        freq=R.noise.getFreqA()
        freq=R.noise.addFreqSemis(freq,math.random(0,12)-12)
        R.noise.setFreq(3,freq)
        R.noise.setVolU(3,0.5)
    end

    for ch=0,3 do
        local wave=R.noise.getWaveUs(ch)
        local vol=R.noise.getVolU(ch)
        local x=ch*60+14
        local y=50
        for i=1,#wave do
            pix(x+i,y+wave[i]*15,12)
        end

        print(string.format("V: %.2f",vol),x,y+20,12)
    end

    print("Backspace to escape this hellscape!",25,129,12)
    T=T+1
end

-- <PALETTE>
-- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
-- </PALETTE>
