From 22a89970f8496ac180a291f499448f049b4c5f3e Mon Sep 17 00:00:00 2001 From: g012 Date: Sat, 23 Dec 2017 23:58:42 +0100 Subject: [PATCH] Allowed free positioning of referenced-by-string using charset of CHR data, by delaying evaluation of charset value. --- 6502.lua | 2 +- samples/nes_hello.l65 | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/6502.lua b/6502.lua index 5b4f1a1..8c51a46 100644 --- a/6502.lua +++ b/6502.lua @@ -658,7 +658,7 @@ M.charset = function(s, f) if not f then f = function(v) return v end elseif type(f) == 'number' then f = function(v) return v + f end end local t,i={},0 - for c in s:gmatch'.' do t[c]=f(i) i=i+1 end + for c in s:gmatch'.' do local v=i t[c]=function() return f(v) end i=i+1 end M.cs=t return t end diff --git a/samples/nes_hello.l65 b/samples/nes_hello.l65 index a88fd06..82cb5d9 100644 --- a/samples/nes_hello.l65 +++ b/samples/nes_hello.l65 @@ -4,7 +4,7 @@ mappers.NROM() location(chrrom0) -local font = section{"font", org=chrrom0.start} +local font = section("font") dc.b 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 -- dc.b 0x38,0x38,0x2c,0x64,0x7e,0x46,0xce,0x00,0x38,0x38,0x2c,0x64,0x7e,0x46,0xce,0x00 -- A dc.b 0xfc,0x62,0x66,0x7c,0x62,0x66,0xfc,0x00,0xfc,0x62,0x66,0x7c,0x62,0x66,0xfc,0x00 -- B @@ -37,8 +37,7 @@ location(prgrom) @@nmi rti @@irq rti -local font_start = (font.org - chrrom0.start) // 16 -charset(" abcdefghijklmnopqrstuvwxyz", \x(x+font_start)) +charset(" abcdefghijklmnopqrstuvwxyz", \x(x + (font.org - font.location.start) // 16)) local hello = "hello world" @@text byte(hello)