Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LINE21 = 0x04C8
- LINENEG1 = 0x04F6
- GAMESTATE = memory.readbyte(0x0048)
- states = { [0] = "copyright", "moving", "locking", "checking", "clearing", "updating", "updating", "updating", "spawning", "x", "x", "x", "x", "x" }
- RNG = memory.read_u16_be(0x0017)
- SPAWNID = memory.readbyte(0x0019)
- SPAWNCOUNT = memory.readbyte(0x001A)
- --the in-game connection between the number at SPAWNID and the shape it gives
- SPAWNTABLE = { [0] = 0x02, 0x07, 0x08, 0x0A, 0x0B, 0x0E, 0x12 }
- --1-7 table of possible pieces
- letters = { "T", "J", "Z", "O", "S", "L", "I" }
- --convert spawn table number to string
- names = { [0x02] = "T", [0x07] = "J", [0x08] = "Z", [0x0A] = "O", [0x0B] = "S", [0x0E] = "L", [0x12] = "I" }
- --convert string to spawn table number
- 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";
- --transparency constants
- transpercent = 75
- trans = math.ceil(0xFF * transpercent/100) * 0x1000000
- --color constants
- lineColor = { [0x7B] = trans + 0x4240fe, [0x7C] = trans + 0x000000, [0x7D] = trans + 0x000000 }
- fillColor = { [0x7B] = trans + 0xffffff, [0x7C] = trans + 0xb53220, [0x7D] = trans + 0x4240fe }
- gui.defaultPixelFont("fceux")
- --Keyboard states last frame and this frame
- prevks = input.get()
- curks = input.get()
- curcheat = 0
- cheatseq = {}
- doubledip = false
- startingSpawnCount = 0
- function update()
- 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
- advanceRNG()
- SPAWNID = memory.readbyte(0x0019)
- SPAWNCOUNT = memory.readbyte(0x001A) + 1
- local index = bit.rshift(RNG,8) + SPAWNCOUNT
- index = index % 8
- if (index ~= 7 and SPAWNTABLE[index] ~= SPAWNID) then
- doubledip = false
- SPAWNID = SPAWNTABLE[index]
- else
- doubledip = true
- advanceRNG()
- index = bit.rshift(RNG,8)
- index = ((index % 8) + SPAWNID) % 7
- SPAWNID = SPAWNTABLE[index]
- end
- RNG = tempRNG
- return SPAWNID
- end
- function weLoaded(branchIndex)
- theBranch = tastudio.getbranches()[branchIndex]
- startingSpawnCount = memory.readbyte(0x001A)
- seqString = theBranch["Text"]
- cheatseq = {}
- for i = 1, string.len(seqString), 2 do
- thePiece = string.char(string.byte(seqString,i))
- --encounter illegal character in the branch name? quit out
- if (ids[thePiece] == null) then
- startingSpawnCount = 0
- return
- end
- cheatseq[#cheatseq+1] = thePiece
- end
- --Forcibly clear the greenzone
- tastudio.submitinsertframes(emu.framecount()-1,1)
- tastudio.submitdeleteframes(emu.framecount()-1,1)
- tastudio.applyinputchanges()
- tastudio.setplayback(emu.framecount()-1)
- end
- tastudio.onbranchload(weLoaded)
- while true do
- curks = input.get()
- update()
- --you can cheat specific pieces by using the keyboard
- for i = 1, #letters do
- if (curks[letters[i]] and not prevks[letters[i]]) then
- if (curcheat == ids[letters[i]]) then curcheat = 0
- else curcheat = ids[letters[i]] end
- end
- end
- if (startingSpawnCount ~= 0) then
- advancedSpawns = SPAWNCOUNT - startingSpawnCount
- if (advancedSpawns+1 <= #cheatseq and advancedSpawns >= 0) then
- curcheat = ids[cheatseq[advancedSpawns+1]]
- else
- curcheat = 0
- end
- end
- if (curcheat ~= 0) then
- memory.writebyte(0x00BF, curcheat)
- gui.pixelText(87, 217, "CHEATING " .. names[curcheat] .. "-PIECE", "red")
- end
- for i = 5, 0, -1 do
- for j = 1, 10 do
- theBlock = memory.readbyte(LINENEG1 - (i*10) + (j-1))
- if (theBlock ~= 0xEF) then
- gui.drawRectangle(95+((j-1)*8),((6-i-1)*8)-1,8,8,lineColor[theBlock],fillColor[theBlock])
- end
- end
- end
- GAMESTATE = memory.readbyte(0x0048)
- --do not run during copyright screen
- if (GAMESTATE ~= 0) then
- color = "lightcoral"
- if (GAMESTATE == 1) then color = "lightgreen" end
- gui.pixelText(185, 190, GAMESTATE .. ": " .. states[GAMESTATE], color,"black")
- gui.pixelText(190, 146, "Next: " .. names[SPAWNID],"white","black")
- gui.drawBox(11,7,84,236,"black","black")
- for i = 0, 24 do
- nextPieceString = (emu.framecount()+i+1) .. ": " .. names[pickPiece()]
- if (doubledip) then nextPieceString = nextPieceString .. " (" .. "2" .. ")" end
- gui.pixelText(12, 8+(9*i), nextPieceString)
- advanceRNG()
- end
- end
- prevks = curks
- emu.frameadvance()
- end
Add Comment
Please, Sign In to add comment