User File #638723763920964939

Upload All User Files

#638723763920964939 - c64 flooder board reader

floodereader.lua
Game: Flooder ( C64, see all files )
5 downloads
Uploaded 4 days ago by Cephla (see all 24)
Reads the board and outputs a text file that can be copied directly into the solver program
local addresses = {
    0x00D926, 0x00D928, 0x00D92A, 0x00D92C, 0x00D92E,
    0x00D94E, 0x00D950, 0x00D952, 0x00D954, 0x00D956,
    0x00D976, 0x00D978, 0x00D97A, 0x00D97C, 0x00D97E,
    0x00D99E, 0x00D9A0, 0x00D9A2, 0x00D9A4, 0x00D9A6,
    0x00D9C6, 0x00D9C8, 0x00D9CA, 0x00D9CC, 0x00D9CE,
    0x00D9EE, 0x00D9F0, 0x00D9F2, 0x00D9F4, 0x00D9F6,
    0x00DA16, 0x00DA18, 0x00DA1A, 0x00DA1C, 0x00DA1E,
    0x00DA3E, 0x00DA40, 0x00DA42, 0x00DA44, 0x00DA46,
    0x00DA66, 0x00DA68, 0x00DA6A, 0x00DA6C, 0x00DA6E,
    0x00DA8E, 0x00DA90, 0x00DA92, 0x00DA94, 0x00DA96
}

local gridWidth = 5
local gridHeight = 10

function readMemoryValues()
    local values = {}
    for i = 1, #addresses do
        local value = memory.readbyte(addresses[i])
        table.insert(values, value)
    end
    return values
end

function writeValuesToFile(values)
    local file = io.open("flooderboard.txt", "w")
    file:write("board = [\n")
    local index = 1
    for y = 1, gridHeight do
        file:write("    [")
        for x = 1, gridWidth do
            local value = values[index]
            if value == 12 then
                value = 8
            elseif value == 10 then
                value = 9
            end
            file:write(value)
            if x < gridWidth then
                file:write(", ")
            end
            index = index + 1
        end
        file:write("],\n")
    end
    file:write("]\n")
    file:close()
end

while true do
    local values = readMemoryValues()
    writeValuesToFile(values)
    emu.frameadvance()
end