Skip to content

Debugging libpinmame

Jason Millard edited this page Feb 1, 2021 · 2 revisions
  • Install Visual Studio Code
  • Install C/C++, CMake, and CMake Tools Visual Studio Code Extensions
  • From the command line:
mkdir pinmame-debug
cd pinmame-debug
git clone https://github.com/jsm174/pinmame-dotnet
cd pinmame-dotnet
cd pinmame
cp CMakeLists_<version>.txt CMakeLists.txt
cmake -DCMAKE_BUILD_TYPE=Debug .
cmake --build .
cd ..
cd ..
mkdir test
cd test
  • Make a new CMakeLists.txt file in the test directory:
cmake_minimum_required(VERSION 3.14)
project(pinmame_test VERSION 0.1.0)

include_directories(../pinmame-dotnet/pinmame/_deps/pinmamesrc-src/src/dll)

add_executable(pinmame_test main.cpp)

find_library(LIB pinmame
   HINTS ../pinmame-dotnet/pinmame/lib
)

target_link_libraries(pinmame_test PRIVATE "${LIB}")
  • Make a new main.cpp file in test directory:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "libpinmame.h"

void clear() {
    #if defined(__linux__) || defined(__unix__) || defined(__APPLE__)
        system("clear");
    #endif

    #if defined(_WIN32) || defined(_WIN64)
        system("cls");
    #endif
}

int main(int, char**) {
    unsigned char* buffer ;

    SetVPMPath("~/.pinmame/");

    StartThreadedGame("mm_109c", true);

    while(true) {
        if (IsGameReady()) {
            if (NeedsDMDUpdate()) {
                int height = GetRawDMDHeight();
                int width = GetRawDMDWidth();

                if (!buffer) {
                    buffer = (unsigned char*) malloc((height * width) * sizeof(unsigned char));
                }

                clear();

                GetRawDMDPixels(buffer);

                for (int y = 0; y < height; y++) {
                    for (int x = 0; x < width; x++) {
                        unsigned char pixel = buffer[y * width + x];

                        switch (buffer[y * width + x]) {
                            case 0x00:
                                printf(" ");
                                break;
                            case 0x14:
                                printf("░");
                                break;
                            case 0x21:
                                printf("▒");
                                break;
                            case 0x43:
                                printf("▓");
                                break;
                            case 0x64:
                                printf("▓");
                                break;
                        }
                    }

                    printf("\n");
                }
            }
        }

        usleep(10);
    }
}
  • Open Visual Studio Code and open test folder: File -> Open Folder

  • Open main.cpp and set a breakpoint on

StartThreadedGame("mm_109c", true);
  • In the Visual Studio Code status bar, select the appropriate debug kit - GCC for x86_linux-gnu 7.5.0 or Clang

  • In the Visual Studio Code status bar, click the debug button

Clone this wiki locally