YACE64 Logo

The Commodore 64 3D and VR Emulator

Home Introduction Features Screenshots Download Links Help About
Commodore 64
www.icons8.com

Overview

The new version of YACE support LUA scripting, but many things can also be automated using the command console and the complex breakpoints to trigger actions.
Script and console command can also be used together, e.g. setting conditional actions or breakpoint from the script or reacting on them in the script.

Description

The scripting language LUA is quite easy, so just see the examples in this chapter for common syntax.

LUA scripts can be loaded from the library or the file dialog. The global part of the script is executed directly on loading.
When starting YACE64 the script sample.lua is loaded automatically, it just contains some samples.

Note: If you are missing a function or callback, please contact me - most things can be added shortly.

YACE64 can call function within the script; currently the following are supported:

Callbacks

onScriptLoad() Script is loaded and the global code was executed
onScriptUnload() Script is about to unload, because an other script is about to load or YACE64 shuts down
 onBreak(PC, device) Emulation is paused
PC is the current program counter (address the CPU is about to execute)
device is either the C64, D8 or D9 object, depending on which device was paused
 onContinue(PC, device) Emulation is continued
 onFrameEnd() The VIC has finished drawing a frame
 onCondition(conditionId, device, data) A script condition was reached.
Condition can be set with the BS command in the console or with the SetCondition() function of the device C64, D8 or D9
conditionId is the identifier for the condition (this id is used to remove, enable, disable a specific condition)
device is either the C64, D8 or D9 object, depending for which device the condition was set
data is the text that was set when creating the condition
 onJoystick(port, contacts) A joystick was moved or fire was pressed
port is either port 1 or port 2
contacts is the binary mask of the joystick contacts (0x01=up 0x02=down 0x04=left 0x08=right 0x10=fire)
 onUser(buttonId) A user button was clicked in the menu (Control/Script)
buttonId is 1 to 5

The are the following object, that are provided by YACE64:

Objects

C64

Pause(pauseState, [comment]) The system is paused or continued
pauseState: true to pause, false to continue
comment: optional text, that is shown is logs
PC() Returns the current program counter address of the CPU
Read(address) Reads and returns the content of the memory as seen by the CPU
XReg Read/Writes the X register of the CPU
YReg Read/Writes the Y register of the CPU
AReg Read/Writes the Accumulator of the CPU
LogInfo(text) Logs an info text to the logging of the system in the global category
SetCondition(conditionId, conditionExprArray, dataString) Sets a condition for the C64
conditionId is the identifier for the condition
conditionExprArray an array (or single) text condition
dataString is a user text, that is provided in the onCondition() callback
ClearCondition(conditionId) Removes a condition
conditionId is the identifier for the condition

D8, D9 (Discdrive 8 or 9)

Pause(pauseState, [comment]) The system is paused or continued
pauseState: true to pause, false to continue
comment: optional text, that is shown is logs
PC() Returns the current program counter address of the CPU
Read(address) Reads and returns the content of the memory as seen by the CPU
XReg Read/Writes the X register of the CPU
YReg Read/Writes the Y register of the CPU
AReg Read/Writes the Accumulator of the CPU
LogInfo(text) Logs an info text to the logging of the system in the global category
SetCondition(conditionId, conditionExprArray, dataString) Sets a condition for the disc drive
conditionId is the identifier for the condition
conditionExprArray an array (or single) text condition
dataString is a user text, that is provided in the onCondition() callback
ClearCondition(conditionId) Removes a condition
conditionId is the identifier for the condition

GUI

ShowInfoMessage(text) Shows an information message on the screen
ShowErrorMessage(text) Shows an error message on the screen
SetButtonTitle(buttonId, title) Sets the text of the user defined script buttons in the menu
buttonId index of the button from 1 to 5

VIC

GetSpritePos(spriteId) Returns the x,y position of the given sprite
spriteId: Index of the hardware sprite from 0 to 7
Rasterline Returns the current drawn rasterline
Read(register address) Reads and returns the value of a VIC register (e.g. Read(53249) returns the sprite 0 y position)

VR

ShowComputer Shows/hides the computer in the VR scene, set to true to show and false to hide
ShowRoom Shows/hides the room in the VR scene, set to true to show and false to hide
Show3D Set to true to show the 3D scene and false show the big screen
SetSpaceColor(r, g, b) Sets the ambient color of the VR scene
r, g, b are the floatingpoint  values for read, green and blue each from 0.0 to 1.0
GetHMDPos() Gets the x, y, z coordinate of the headup device (values are in meter)
SetSceneScale(x, y, z) Sets the x, y, z scaling of the 3D scene (default is each 1.0; y is vertical)
SetScenePosition(x, y, z) Sets the x, y, z position of the 3D scene (default is each 0.0; y is vertical)
SetSceneOrientation(yaw, pitch, roll, [speed]) Sets the yaw, pitch, roll (in degree) orientation of the 3D scene
optional the speed value can be given to define how fast the orientation will be reached; the values will be interpolated (value is stepvalue per second)

Example

sceneYaw = 0.0            -- setup some global variables
sceneRoll = 0.0
scenePitch = 0.0
sceneSpeed = 0.5

relCalibratedPosX = 0.0
relCalibratedPosY = 0.0
relCalibratedPosZ = 0.0

GUI:SetButtonTitle(1, "Show 3D/Screen")        -- Set the titles of the user buttons in the Control/Script menu
GUI:SetButtonTitle(2, "Show/Hide Computer")
GUI:SetButtonTitle(3, "Show/Hide Room")

function onScriptLoad()                        -- when this script is loaded do the following things:
    C64:SetCondition(1, {"VIC.RL>30", "VIC.RL<40"}, "Rasterline 30")  -- set a condition with id 1 that will be triggered, when the VIC draw rasterlines from 31 to 39
end

function onScriptUnload()                       -- when this script is unloaded do the following things:
    C64:ClearCondition(1)                       -- remove the condition created in the onLoad
end

function onBreak(PC, device)                    -- when a system is paused do nothing
end

function onContinue(PC, device)                 -- when a system is continued do nothing
end

function onFrameEnd()                            -- when the VIC has finished drawing a frame the do:
    C64:Pause(true, "Frame ended")               -- Set the C64 into pause mode   

    x1 = VIC:Read(53248)                         -- Read VIC register Sprite 1 X position
    y1 = VIC:Read(53249)                         -- Read VIC register Sprite 1 Y position

    x,y = VIC:GetSpritePos(0)                    -- Get the sprite0 x,y position
    x,y = VIC:GetSpritePos(1)                    -- Get the sprite1 x,y position

    xHMD,yHMD,zHMD = VR:GetHMDPos()              -- Get the current position of the VR headup display
    GUI:ShowInfoMessage(string.format("%f %f %f", xHMD, yHMD, zHMD))   -- Show the current position of the VR headup display as info message
end

function onCondition(conditionId, device, data) -- when a system triggered a condition then do:
    --rl = VIC.Rasterline
    x = C64:Read(0xbc01) + (C64:Read(0xbc02) * 256)     -- read the player postion of a S.E.U.C.K game
    y = C64:Read(0xbc03)
    xd = (x - 150.0) / 120.0                            -- do some calculations
    zd = (y / 55.0) - 3.5
    vert = -0.6 * (1.0-(y / 200.0))
    VR:SetScenePosition(xd + relCalibratedPosX, vert + relCalibratedPosY, zd + relCalibratedPosZ) -- Set the 3D scene position (x, y, z in meter)
    VR:SetSceneOrientation(sceneYaw, scenePitch, sceneRoll, sceneSpeed) -- Set the 3D scene orientation (yaw, pitch, roll in degree)
end

function onJoystick(port, contacts)   -- when the user moves the joystick then do:
    if (contacts & 4) == 4 then       -- moved left ?
        sceneRoll = 10.0
        sceneSpeed = 0.5
    elseif (contacts & 8) == 8 then    -- moved right ?
        sceneRoll = -10.0
        sceneSpeed = 0.5
    else
        sceneRoll = 0.0
        sceneSpeed = 0.8
    end
end

function onUser(buttonId)        -- when the user clicked a user defined menu button (from Control/Script) then do:
    if buttonId == 1 then
        if VR.Show3D == true then        -- toggle 3D/Bigscreen on button 1
            VR.Show3D = false
            VR:SetSpaceColor()
            GUI:SetButtonTitle(1, "Show 3D Scene")
        else
            VR.Show3D = true
            VR:SetSpaceColor(0.0, 0.0, 0.0)
            GUI:SetButtonTitle(1, "Show Big Screen")
        end
    elseif buttonId == 2 then            -- toggle showing the computer on button 2
        if VR.ShowComputer == true then
            VR.ShowComputer = false
            GUI:SetButtonTitle(2, "Show Computer")
        else
            VR.ShowComputer = true
            GUI:SetButtonTitle(2, "Hide Computer")
        end
    elseif buttonId == 3 then        -- toggle showing the room on button 3
        if VR.ShowRoom == true then
            GUI:SetButtonTitle(3, "Show Room")
            VR.ShowRoom = false
        else
            VR.ShowRoom = true
            GUI:SetButtonTitle(3, "Hide Room")
        end
    else
        GUI:ShowInfoMessage(string.format("Button %d", buttonId))    -- Show a message on the screen with the pressed button number
    end
end