Skip to content

Script Debugger

Waldemar Pawlaszek edited this page Dec 18, 2023 · 11 revisions

Felix can run lua scripts accompanied with *.lnx, *.lyx or *.o file with additional .lua suffix (i.e. test.o should have test.o.lua file). It must define some variables and can use some predefined ones.

Predefined variables

cpu.pc

CPU registers that can read

cpu.a, cpu.x, cpu.y

CPU registers that can be read or written

ram, rom, mikey, suzy

When used from callback while emulator is running it acts as array of emulated RAM, ROM, Mikey registers and Suzy registers respectively. Can be read and written.

ram.r, ram.w, ram.x, rom.r, rom.w, rom.x, mikey.r, mikey.w, suzy.r, suzy.w

Can be used during initial script run to register callbacks to trap read (r), write (w) and execute (x) of memory location given as array index. Prototype of trap function is

function trap( value, address )
 return value
end
  • Read trap is called after reading value from memory location address and before loading it to CPU
  • Write trap is called when CPU is about to writing value to memory location address
  • Execute trap is called after reading opcode value from memory location address and before fetching it by CPU

Return value from trap function is obligatory and is either fed to CPU or written to destination, so value must be returned if trap function wish not to modify execution.

Functions callable from callback

traceOn()

Turns tracing on from current instruction

traceOff()

Turns tracing off including current instruction

traceCurrent()

Writes to log only instruction that triggered current callback

traceNextCount( count )

Writes to log next count instructions from the instruction that triggered current callback

trap() / brk()

Breaks execution

Examples

Enable logging from address 0x200

log = "trace.log";

ram.x[0x200] = function( value )
  traceOn();
  return value;
end

Inverting colors:

function invert( value )
  return 255 - value;
end

for i = 0xa0,0xbf,1 do
  mikey.w[i] = invert;
end