![]() |
|
![]() www.icons8.com |
This script shows how to automate the setup and start of a program, so only a click is needed to run everything how it's needed.
This is the "Tutorial00" included in the Tutorial-Download.
The OnLoad() method is called when you load the script. This is a good place
to setup the emulator as needed for the C64 program.
Also loading and starting can be done here with a few lines of code.
Just have a look at the steps in the OnLoad() method:
Here we set the view-mode to the C64 full screen, set the emulator to PAL mode
and configure the joystick port 1 to be used with the number-block of the
keyboard.
Then we load our "game" from the same path as our script file.
Normally we could send now a keyboard command directly, because we just loaded a
prg file, which is directly in memory - but when loading a file from a floppy
disc image, this would take some time and then we need to delay our "RUN"
command.
The delay we accomplish using a timer (SetTimer), which will calls the OnTimer()
function after the given time (in this case 120 frames ~2.2s).
In the OnTimer() we just send an ASCII text to the keyboard. To send keyboard
commands or key combination that are not possible with SendASCII(),
SendCbmKeys(() could be used.
const int startProgramTimerId = 1;
// This is called, when we loaded the script-file
void OnLoad(bool reloaded)
{
// Get the path of our script
string scriptPath = APP.GetScriptPath();
// Directly set the C64 full screen view
APP.ViewMode = ViewMode::Screen2D;
// Set PAL mode for our "game"
APP.SetPAL();
// Set the joystick port the game will use
APP.SetJoystick(1, Joystick::NumberBlock);
if (!reloaded)
{
// Load a program, which is the same
path as our script
APP.Load(scriptPath +
"Sprites.prg", 0);
// Set a timer with 120 frame delay,
which will send "RUN" to the keyboard
SetTimer(startProgramTimerId, 120,
false);
}
// Just show a message on the screen
GUI.ShowInfoMessage("Tutorial 00");
}
// This is called, when a timer fires an event
void OnTimer(int timerId)
{
if (timerId == startProgramTimerId)
{
APP.SendASCII("RUN\n");
// send "RUN" to the keyboard and also press 'Enter'
}
}