Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gyrovorbis/dc-emu-detect

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
10 Commits
 
 

Repository files navigation

/* emu_detect.c
   Sega Dreamcast Emulator Detection Routine for KOS-based Apps.
   Copyright (C) 2025 Falco Girgis

   This little bastard simply leverages the fact that no emulator that I am
   aware of is emulating the SH4's watchdog timer peripheral, as no commercial
   game or SDK ever made use of it... UNTIL NOW. 
*/

#include <stdbool.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

// Include my KOS WDT driver, which nobody is emulating, lulz.
#include <dc/wdt.h>

/* Callback function that gets called upon WDT timeouts.

   Simply setting an atomic boolean to true, to signify that the WDT
   peripheral fired its timeout interrrupt properly.
*/
static void wdt_timeout(void *user_data) {
    atomic_bool *fired = (atomic_bool *)user_data;
    *fired = true;
}

/* Returns true if the program is running on an emulator,
   returns false if it's running on real HW.
*/
bool detect_emulator(void) {
    // Initialize our flag for whether the WDT has fired to false.
    atomic_bool fired = false;

    /* Enable the WDT in interval timer mode, with an initial counter valuoe of 0,
       counting up to 1 millisecond before calling our callback routine with a maximum
       IRQ priority value of 15, passing our flag to the callback routine to toggle it.
    */
    wdt_enable_timer(0, 1, 15, wdt_timeout, &fired); 

    // Wait for 2 ms before checking whether the WDT IRQ has fired (plenty of fuckin' time!)
    usleep(2000);

    // If it never fired, we're on an emulator...
    return !fired;
}

// Program entry-point.
int main(int argc, const char* argv[]) {
    // Give her a shot!
    if(detect_emulator())
        printf("I see you're running on an emulator!\n");
    else
        printf("I see you're running on actual Dreamcast HW!\n");

    return EXIT_SUCCESS;
}

About

Quick way to detect whether a KOS-based Sega Dreamcast app is running on an emulator or physical HW.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.