Skip to content

Introduce Lua Support#148

Merged
st3fan merged 1 commit intomasterfrom
lua
Sep 19, 2017
Merged

Introduce Lua Support#148
st3fan merged 1 commit intomasterfrom
lua

Conversation

@st3fan
Copy link
Copy Markdown
Owner

@st3fan st3fan commented Sep 16, 2017

This patch lays the foundation for Lua support. It pulls in Lua 5.2 and adds a --script argument to two.

It also exposes a cpu global with onBeforeExecuteInstruction and onAfterExecuteInstruction functions. These allow you to register callbacks around individual instruction execution. The same object also has properties like a, x, y, s, sp and pc - which can all be set/changed too.

Example of a small Lua script:

--
-- Intercept JSR COUT calls and turn A-Z into inverse. The key code is
-- in the accumulator so we can simply see if it is in the range we
-- are interested in and then shift it to the inverse character range.
--

JSR = 0x20
COUT = 0xfded

cpu:onBeforeExecuteInstruction(JSR, function(cpu, opcode, operand)
  if operand == COUT then
     if cpu.a >= 0xc1 and cpu.a <= 0xda then
        cpu.a = cpu.a - 0xC0
     end
  end
end)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant