The Nintaco NES/Famicom emulator provides a Go API that enables externally running programs to control the emulator at a very granular level. This example captures gameplay screenshots.
- Start Nintaco and launch a game.
- Open the Start Program Server window via Tools | Start Program Server...
- Press Start Server.
- From the command-line, launch this Go program.
- Press the Select gamepad button at any time to capture a screenshot. By default, Select is mapped to the apostrophe key.
This example demonstrates how to use API.GetPixels
, which captures the emulator's screen into a provided array. When API.GetPixels
is invoked within a FrameListener
receiver, the pixels values will be from the frame that is about to be displayed. If it is inovked prior to the listener callback, some of the values could be from a prior frame.
API.GetPixels
obtains 9-bit extended palette indices. The lower 6 bits represent one of the 64 colors and the upper 3 bits describe if and how that color is emphasized. Usually there is no emphasis (the upper 3 bits will all be 0). This example uses a table to convert the extended palette indices into RGBA's.
A bot controlling Nintaco could potentially call API.GetPixels
on every frame and analyze the image returned to determine what actions to carry out. However, it's usually far more practical and efficient to obtain the game state by reading CPU memory directly. But that technique requires researching how the game objects are represented in memory.