pulsar/shared/pattern.lua

45 lines
886 B
Lua
Raw Normal View History

2024-03-16 22:21:50 +00:00
pattern=klass()
function pattern:init(p)
self.pflags=pflags:new(p)
self.nflags={}
for i=0,31 do -- because the user could change the length
self.nflags[i]=nflags:new{}
end
end
function pattern:plot(ix, n)
assert_range(ix,0,self.pflags.len,"ix")
self.nflags[ix]=nflags:new(n)
end
function pattern:silent()
for i=0,31 do
if (self.nflags[i].v!=0) return
end
return true
end
function pattern:key()
local key=0
for i=0,self.pflags.len-1 do
key ^= self.nflags[i]:encode()>>(i%16)
end
return key
end
function pattern:eq(other)
if (self.pflags:encode() != other.pflags:encode()) return
for i=0,self.pflags.len-1 do
if (self.nflags[i]:encode()!= other.nflags[i]:encode()) return
end
return true
end
function pattern:map_to(ix)
self.map_ix=ix
local at=0x3200+ix*68
poke4(at+64,self.pflags:encode())
for i=0,31 do
poke2(at+i*2,self.nflags[i]:encode())
end
end