-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtiles-to-forth.lua
More file actions
executable file
·58 lines (48 loc) · 1.25 KB
/
tiles-to-forth.lua
File metadata and controls
executable file
·58 lines (48 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/lua
local name = arg[1]
local palFile = assert(io.open(arg[2], "rb"))
local tileFile = assert(io.open(arg[3], "rb"))
local segment = arg[4] or "UNSIZED"
function toWords(str)
local wordStrings = {}
for i = 1, #str, 2 do
table.insert(wordStrings, string.format("$%04X", (string.byte(str, i + 1) << 8) | string.byte(str, i)))
end
return wordStrings
end
function toWordRows(str)
local wordStrings = toWords(str)
local rowWords = {}
local rows = {}
for k, v in ipairs(wordStrings) do
if #rowWords >= 8 then
table.insert(rows, " .WORD " .. table.concat(rowWords, ", "))
rowWords = {}
end
table.insert(rowWords, v)
end
table.insert(rows, " .WORD " .. table.concat(rowWords, ", "))
return table.concat(rows, "\n")
end
function makeDataWords(name, label, data)
return string.format([[
CODE %s
lda #.LOWORD(%s_DATA)
PUSH_A
rts
.pushseg
.segment "%s"
%s_DATA:
%s
.popseg
END-CODE
0x%04X CONSTANT %s-BYTES
CODE %s-BANK
lda #.BANKBYTE(%s_DATA)
PUSH_A
rts
END-CODE
]], name, label, segment, label, toWordRows(data), #data, name, name, label)
end
print(makeDataWords(name .. "-PAL", name .. "_PAL", palFile:read("*all")))
print(makeDataWords(name .. "-TILES", name .. "_TILES", tileFile:read("*all")))