~dajolly/dmg

A lightweight Gameboy emulator, written in C.

8b49a51 restrict pixel width build flag

~dajolly pushed to ~dajolly/dmg git

13 hours ago

b21a599 code cleanup

~dajolly pushed to ~dajolly/dmg git

13 hours ago

License: MIT Build Status

DMG

#Features

  • Support for common cartridge mappers (see supported Mappers below)
  • Support for various color palettes (see supported Palettes below)
  • Support for serial connectivity through a virtual link cable (experimental)

#Work-in-progress

  • Support for audio rendering

#Install

git clone https://git.sr.ht/~dajolly/dmg
cd dmg
make
sudo make install
# The default installation directory is `/usr/local`. To use a different directory, redefine `PREFIX`:
sudo make install PREFIX=/your/path

#Usage

#Launcher

#Usage
Usage: dmg [options] file

Options:
   -d, --debug       Enter debug prompt
   -f, --fullscreen  Set window fullscreen
   -h, --help        Show help information
   -l, --link        Set virtual link client
   -p, --palette     Set window palette
   -s, --scale       Set window scaling
   -v, --version     Show version information
#Examples
# To launch with a file, run the following command
dmg file.gb

# To launch with debug prompt, run the following command
dmg -d file.gb

# To launch with window fullscreen, run the following command
dmg -f file.gb

# To launch with virtual linked client, run the following command
dmg -l [link] file.gb

# To launch with window palette, run the following command
dmg -p [palette] file.gb

# To launch with window scaling, run the following command
dmg -s [scale] file.gb
#Keybindings
Button Key
A L
B K
Select Left-Alt
Start Space
Right D
Left A
Up W
Down S
Palette P
#Palettes
Id Palette Description
0 Grey Grey
1 Green Green
2 Blue Blue
3 Red Red
4 LCD LCD

#Shared Library

#Interface
#include <dmg.h>

/* Send action to the library. */
dmg_error_e dmg_action(const dmg_action_t *const request, dmg_action_t *const response);

/* Retrieve the error message associated with the last operation. */
const char *dmg_error(void);

/* Initialize the library. */
dmg_error_e dmg_initialize(dmg_context_t *const context);

/* Uninitialize the library. */
void dmg_uninitialize(void);

/* Retrieve the library version information. */
const dmg_version_t *dmg_version(void);
#Example
#include <stdio.h>
#include <stdlib.h>
#include <dmg.h>

int main(void)
{
   int result = EXIT_FAILURE;

   dmg_context_t context =
   {
      /* Setup the client callbacks, ROM/RAM banks */
   };

   /* Initialize the library */
   if (dmg_initialize(&context) == DMG_SUCCESS)
   {
      /* Setup the RUN action request */
      dmg_action_t request =
      {
         /* Set the request type to RUN */
         .type = DMG_ACTION_RUN,
         /* Set the breakpoint */
         .address = 0xFFFF
      }, response = {};

      /* Execute the RUN action request */
      if (dmg_action(&request, &response) == DMG_SUCCESS)
      {
         result = EXIT_SUCCESS;
      }
   }

   if (result != EXIT_SUCCESS)
   {
      /* On error, trace the error string */
      fprintf(stderr, "%s", dmg_error());
   }

   /* Uninitialize the library */
   dmg_uninitialize();

   return result;
}
# Build with the following command
cc main.c -ldmg
#Mappers
Id Mapper Description
0,8-9 MBC0 32KB ROM/8KB RAM
1-3 MBC1 2MB ROM/32KB RAM
5-6 MBC2 256KB ROM/512B RAM
15-19 MBC3 2MB ROM/32KB RAM/RTC
25-30 MBC5 8MB ROM/128KB RAM

#License

Copyright (C) 2023-2024 David Jolly. Released under the MIT License.