Tuesday, 6 June 2017

Gotchas When Porting C++ and OpenGL Applications to the Dreamcast

Over the past month or so I've been steadily working on porting my game engine Simulant to the Dreamcast. While it's not quite ready for prime-time, I did discover a lot of road-bumps along the way, and I thought I should write some of them down so that anyone else porting to the Dreamcast will at least have some results on Google to look at!

Compile the Dreamcast SDK with GCC 4.x

It didn't take very long to compile my code, but when it came to linking all kinds of trouble awaited me. Whenever I tried to link, most of the C++ symbols (things like string and vector) were missing. After several days trying different linker flags I decided the problem must be with the SDK itself. A quick `nm` of libstdc++.a showed up the problem; only a handful of symbols were in there!

I've been using a Docker container to compile my code, which is fortunate because it allowed me to gradually roll back the Fedora version until I hit one that correctly compiled libstdc++. Fedora 21 is where it worked!

The moral of the story is that for some reason, GCC 5.x and above will not correctly compile libstdc++.a from GCC 4.x - so if you're compiling the SDK for C++ code, you're going to need to use an old GCC version.

Don't rely on std::atomic or std::async

The SH4 CPU only has a single limited atomic instruction which rules out support for std::atomic. That by itself wouldn't be so bad, but it turns out that even though the standard defines that std::async can be implemented without atomics, GCC hasn't done that.

In most cases it's trivial enough to build what you need using std::mutex and std::thread - but it is a bit of a hassle.

std::chrono::high_resolution_clock ... er... isn't

This had me confused for a while. I had a sample GL application running; a spinning cube, and it would run at a consistent 1FPS. I know the DC is slow compared to modern machines, but, 1FPS for a cube?!

Turns out that the "high resolution" timer had an accuracy of 1 second! Using the built-in KallistiOS timer functions fixed it.

libGL is still a WIP

The GL port for the DC is a great little library, but it has some rough edges. I recommend that you get your application runnable on both your PC and the DC and focus on targetting GL 1.1. If the graphics in your application don't work on the Dreamcast but do on the PC then investigate and submit a patch!

6 comments:

  1. Although I don't fully understand this post, I'm sure some of my computer science friends will love your blog. Will share with them.

    ReplyDelete
  2. CrownQQ | Domino agent QQ | BandarQ | Domino99 Online Largest

    Who Is The Agent Bandarq, Domino 99, And The Trusted Online Poker City in Asia comes to all of you with exciting game games and exciting bonuses for all of you

    Bonus on CrownQQ:
    * Bonus rolling 0.5%, every week
    * Refferal Bonus 10% + 10%, lifetime
    * Bonus Jackpot, which you can get easily

    Featured Games CrownQQ:
    * Online Poker
    * BandarQ
    * Domino99
    * Bandar Sakong
    * Sakong
    * Bandar66
    * AduQ
    * Sakong

    More Info Visit:
    Website: AGEN BANDARQ CrownQQ
    BBM: 2B382398
    FB: AgentCrownqq
    Twitter: crown_qq

    ReplyDelete
  3. CrownQQ | Agen Domino QQ | BandarQ | Domino99 Online Terbesar

    Yang Merupakan Agen Bandarq, Domino 99, Dan Bandar Poker Online Terpercaya di asia hadir untuk anda semua dengan permainan permainan menarik dan bonus menarik untuk anda semua

    Bonus yang di berikan CrownQQ :
    * Bonus rollingan 0.5%,setiap minggunya
    * Bonus Refferal 10% + 10%,seumur hidup
    * Bonus Jackpot, yang dapat anda dapatkan dengan mudah

    Games Yang di Hadirkan CrownQQ :
    * Poker Online
    * BandarQ
    * Domino99
    * Bandar Sakong
    * Sakong
    * Bandar66
    * AduQ
    * Sakong

    Info Lebih lanjut Kunjungi :
    Website : AGEN BANDARQ CrownQQ
    BBM : 2B382398
    FB : AgenCrownqq
    Twitter : crown_qq

    ReplyDelete
  4. CrownQQ | Agen Domino QQ | BandarQ | Domino99 Online Terbesar

    Yang Merupakan Agen Bandarq, Domino 99, Dan Bandar Poker Online Terpercaya di asia hadir untuk anda semua dengan permainan permainan menarik dan bonus menarik untuk anda semua

    Bonus yang di berikan CrownQQ :
    * Bonus rollingan 0.5%,setiap minggunya
    * Bonus Refferal 10% + 10%,seumur hidup
    * Bonus Jackpot, yang dapat anda dapatkan dengan mudah

    Games Yang di Hadirkan CrownQQ :
    * Poker
    * BandarQ
    * Domino99
    * Bandar Poker
    * Sakong
    * Bandar66
    * AduQ
    * Sakong

    Info Lebih lanjut Kunjungi :
    Website : http://zonaemas.com | http://topiemas.com
    BBM : 2B382398
    FB : AgenCrownqq
    Twitter : crown_qq

    ReplyDelete


  5. Mau menang banyak dengan modal sedikit..
    Ayo gabung di Agen Domino NAGAQQ.
    =>Bonus Refferal 20%
    =>Bonus Turn Over 0,5%
    =>Min Deposit Rp 15.000
    =>1 User ID 4 Games
    Situs yang bisa memberikan kemenangan AGEN BANDARQ TERBAIK
    Raih kemenangan anda segera...
    WHATSAPP : +855967014811
    PIN BB : 2B209F68

    ReplyDelete
  6. Cari Situs Judi BANDAR POKER ONLINE Online yang aman dan terpercaya ?
    Solusinya hanya di CROWNQQ
    Bonus Refferal 20%
    Bonus Turn Over 0,5%
    Hanya dengan minimal deposit 20ribu sudah bisa bermain 8 game sekaligus lohh..
    "NEW AGEN BANDAR 66"
    Ayo daftar dan gabung sekarang juga,,
    WHATSAPP : +855967646513
    PIN BB : 2B382398

    ReplyDelete