Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local RNG1 = memory.readbyte(0x0017)
- local RNG2 = memory.readbyte(0x0018)
- local RNG = memory.read_u16_be(0x0017)
- local SPAWNID = memory.readbyte(0x0019)
- local SPAWNCOUNT = memory.readbyte(0x001A)
- --the in-game connection between the number at SPAWNID and the shape it gives
- local SPAWNTABLE = { [0] = 0x02, 0x07, 0x08, 0x0A, 0x0B, 0x0E, 0x12 }
- --1-7 table of possible pieces
- local letters = { "T", "J", "Z", "O", "S", "L", "I" }
- --convert spawn table number to string
- local names = { [0x02] = "T", [0x07] = "J", [0x08] = "Z", [0x0A] = "O", [0x0B] = "S", [0x0E] = "L", [0x12] = "I" }
- --convert string to spawn table number
- local ids = { T = 0x02, J = 0x07, Z = 0x08, O = 0x0A, S = 0x0B, L = 0x0E, I = 0x12 }
- --constants for writing sequences in easily
- T = "T"; J = "J"; Z = "Z"; O = "O"; S = "S"; L = "L"; I = "I";
- --ORDER OF PIECES CHEATED WHEN YOU PRESS SPACE for frame timing documentation
- cheatsequence = { I, J, Z, J, I, I }
- --Keyboard states last frame and this frame
- prevks = input.get()
- curks = input.get()
- prevspawncount = memory.readbyte(0x001A)
- curcheat = 0
- curseq = 0
- function update()
- RNG1 = memory.readbyte(0x0017)
- RNG2 = memory.readbyte(0x0018)
- RNG = memory.read_u16_be(0x0017)
- SPAWNID = memory.readbyte(0x0019)
- SPAWNCOUNT = memory.readbyte(0x001A)
- end
- function advanceRNG()
- local temp = 0
- if (bit.check(RNG,1) ~= bit.check(RNG,9)) then temp = 1 end
- if (temp == 1) then RNG = bit.set(RNG,16) end
- RNG = bit.rshift(RNG, 1)
- return RNG
- end
- function pickPiece()
- --RNG = memory.read_u16_be(0x0017)
- tempRNG = RNG
- SPAWNID = memory.readbyte(0x0019)
- SPAWNCOUNT = memory.readbyte(0x001A) + 1
- local index = bit.rshift(RNG,8) + SPAWNCOUNT
- print(RNG)
- print(index)
- index = index % 8
- if (index ~= 7 and SPAWNTABLE[index] ~= SPAWNID) then
- SPAWNID = SPAWNTABLE[index]
- else
- advanceRNG()
- index = bit.rshift(RNG,8)
- index = ((index % 8) + SPAWNID) % 7
- SPAWNID = SPAWNTABLE[index]
- end
- RNG = tempRNG
- return SPAWNID
- end
- while true do
- curks = input.get()
- update()
- for i = 1, #letters do
- if (curks[letters[i]] and not prevks[letters[i]]) then
- curcheat = ids[letters[i]]
- end
- end
- if (curks["Space"] and not prevks["Space"]) then
- if (curseq == 0) then
- curseq = 1
- curcheat = ids[cheatsequence[curseq]]
- prevspawncount = SPAWNCOUNT
- else
- curseq = 0
- curcheat = 0
- end
- end
- if (curseq ~= 0) then
- if (SPAWNCOUNT > prevspawncount) then
- prevspawncount = SPAWNCOUNT
- curseq = curseq + 1
- curcheat = ids[cheatsequence[curseq]]
- if (curseq > #cheatsequence) then
- curseq = 0
- curcheat = 0
- end
- end
- end
- if (curcheat ~= 0) then
- memory.writebyte(0x00BF, curcheat)
- end
- --advanceRNG()
- --print(names[pickPiece()])
- prevks = curks
- emu.frameadvance()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement