Subscribe to Personal Log via RSS and find other blogs to read in my blogroll.

Introducing TR-8

Over the years I have been playing with the idea of writing interpreters and compilers, and I say idea on purpose, because I haven’t been very successful at it. Something similar happens with operating systems and virtual machines, although I have been a bit better with the latter, I had many projects started over the years without results.

Considering that I have been doing game development consistently for almost 10 years now, the idea of a fantasy console is so perfect if you want to write those, that I would say it was almost inevitable I made one.

And that’s why the TR-8 fantasy console came about.

It is all very work in progress and, instead of spending a lot of time planing and designing without getting to make anything, I decided to start implementing and put together things as I go. And you can tell when you look at the design of the 8-bit CPU.

Without getting in too much detail, an example program:

.org 0

; address of the frame interrupt vector
.equ INT_VECT 0xff00

    ; setup an int handler so we
    ; can use the frame int to sync
    ld a, >INT_VECT
    ld x, <INT_VECT
    ld b, <int_handler
    ld [a : x], b
    inc x
    ld b, >int_handler
    ld [a : x], b

    ; enable interrupts
    cif

    ; loop filling the screen with one
    ; colour cycling the whole palette
    ld b, 0
loop:
    call fill
    inc b
    and b, 15

    ; wait 1 second
    ld x, 60
wait_loop:
    halt
    dec x
    bnz
    jmp wait_loop

    jmp loop

    ; fill frame-buffer with a color in reg b
fill:
    ld a, 0xbf
    ld x, 0
    ld y, 0x40
fill_loop:
    ld [a : x], b
    inc x
    bno
    jmp fill_loop
    inc a
    dec y
    bnz
    jmp fill_loop
    ret

int_handler:
    iret

That may give a bit of a taste of what is TR-8.

At the moment I’m working on three essential components:

  • a virtual machine for the CPU
  • an assembler
  • a “player” that uses the virtual machine and provides the other bits of that make it “a console”

All written in C –hopefully portable–, with SDL2 for the player.

As I say, it is a work in progress, but this is what I have decided so far:

  • Display: 128 x 128 pixels 16 colors (using the default EGA palette for now)
  • Memory: 64K
  • CPU: TR-8, 8-bit, 8M instr/sec (for now, likely make it slower when I add the hardware blitter)
  • Sound: TBD, likely to be either a PSG or perhaps FM (OPL3?)
  • Programming: ASM

The TR-8 CPU is inspired by the 8-bit CPUs I have programmed: the Z80 and the 6502; but also the MIPS (specially on how I’m encoding the instructions). This is not about a good design but about having some fun.

The main features of the CPU are:

  • 16-bit registers: stack pointer (SP) and program counter (PC)
  • 8-bit registers: 4 general purpose registers (a, b, x, y), flags register (F)
  • frame interrupt (60Hz)
  • port based IO (very Z80)
  • a frame buffer (16K of RAM as video RAM; I thought about implementing a VDP but then I realised I was copying the MSX!)

I don’t know how far I’m going to get. I guess I will implement enough to feel satisfied, perhaps making a game for it, and that’s probably it. I don’t expect anybody using this, when you can make games for actual 8-bit machines –or more user-friendly fantasy consoles like the Pico-8 or the Tic-80–.

Recently

I think this is my first ever recently type of post, let’s see how it goes!

Trip to Spain

We spent a bit over a week in “Arenales del Sol”, in Alicante (Spain). Visiting family, enjoying the good weather, the beach, and resting. It was pretty good.

The beach

Not a great pic, the day was too bright

The less good part was that I couldn’t met old friends that I haven’t met in in years, because Arenales is kind of isolated and we had limited access to a car. Next time!

I didn’t write a single line of code on that period, at least on a computer. I wrote some ideas for a fantasy console, but all with pen and paper, so it doesn’t count!

IRC is the new IRC

I have been using IRC since February. I’m surprised because it doesn’t feel like was that long, but weechat logs don’t lie.

I started using it by the time I stopped using Telegram. We decided some time ago to only use Signal for the family communications –and a couple of old friends that happen to have my phone number–, or I should say my sister decided because she moved my parents from Google’s Hang out (or Meet or whatever is called this week!).

Closing my Telegram account wasn’t easy, because I had a few friends there that I don’t think I will talk by other means –people don’t do email any more–; but I don’t trust Telegram. Too big and freemium, not fully open source, and an unclear business model are a few of the reasons. Signal is not perfect, but is better.

IRC has been OK, I’m on a few channels and most are basically idle, with the exception of #haskell-game and #gamedev. The latter not being too different to some Telegram group chats I used some time ago, focused on a topic related to development, with the good and bad things –specially a lot of people that don’t do any actual development, so they add noise to the channel–.

Looks like everything is on Discord now. I guess if I really wanted the interactions, I would join one of those servers. Or I would still be using Telegram. It is complicated.

Persona 4 has gone cold

I started playing Persona 4 on the PS2 back in January, and I loved it. Well, I still love it, but it has slowed down too much and I find it hard to keep playing.

The downtime between events on the main story, where you are supposed to do the school routine, increase your stats by doing different small quests and interact with different characters, and grind; all got a bit shallow at a times. Like the school camping trip, with some conversations that help building the characters, but it was around 30 minutes of just press X to continue. I don’t want all combat, but it has become a bit dull at this point with not much feeling of progress.

There has been another event now that is part of the main story, so things are going back to be more interesting, but I’m not looking forward to keep playing.

So after 25 hours I’m about a third of the game. It is still an amazing game, and just checking a saved game to write this post and listening to the music it almost makes me want to play it, but it is a long one!

Revived Outpost and Haskell is fun

I mentioned here that I’m working on a game using Haskell and SDL2, and I used the “Outcast” sprites as a reference. So Víctor was wondering what happened to my ZX Spectrum project, and we reviewed what I had and together we completed the design of the remaining puzzles.

There are so many cool things on that game! It would be a total shame if that never gets released, so I have restarted the work on the project and things are progressing nicely.

It won’t be the same game I originally envisioned, but that’s probably for the best to be honest. The project is more focused now and I know exactly what is left to be done, although some of the ideas Víctor suggested are going to be tough to implement. But that’s OK, it is going to feel fresh. Do game design like you are 6 years old!

So there will be a ZX Spectrum 48K release from me in 2023, and the Haskell project keeps going. I have been streaming on my Twitch channel and some of the videos are in my YT channel, and it is a lot of fun –programming Haskell, the videos not that much–. It won’t be a big game. I don’t even know it if will be fun to play, but it will be finished this year –my first PC release in ages!–.

And that’s all that has happened recently.

SpaceMan in Power Outage?

I wrote here about gamedev in Haskell, but I didn’t have much to show. I was still exploring some ideas and I wasn’t sure it was going anywhere.

Now I think the engine is taking shape and there’s a public git repo, but I forgot to mention it here. For some reason, when I talk about these things in a channel, I forgot to do the same in the others.

Currently we have:

  • My Mastodon account, where I tend to update often if I don’t stream, but I always forget to announce when I’m streaming.
  • My Twitch channel, where I stream when I’m in the right mood –and I’m not too tired–. Sometimes I just want to code, and making it publicly requires considerably more energy.
  • My coding sessions on my YouTube channel, where I upload a copy of some of the Twitch stream –Twitch removes the past stream videos after a while–. I don’t like Twitch too much, but I don’t like YT either; I seem to get more views and comments on YT though.

And, of course, there is this blog. So I guess a good way of following this project could be following me in one of those, and probably not this blog, because I’m not consistent enough!

The engine is nothing too special, other than it is written in a functional style, and in Haskell. I haven’t had to do anything hacky to make it work, so for now I’m pleased with the code. However, I’m still learning and I wouldn’t recommend the code specially to anyone willing to learn gamedev in a functional way. Some people with more experience than me have told me that the code is OK, so there is that too.

The original plan was to make a game jam type of game, so I don’t get in one of my “4 to 6 months” projects when I’m still not sure what I’m doing. Besides, it is a game for PC and not an 8-bit system, so there may not be much interest to play it when it is finished, so I didn’t want to invest too much time on it!

But then my boys are excited and suggesting ideas, so we shall see! For now it is a simple “collect them all to get to next stage” type of arcade platformer, and when I have a sufficient game I may just release and leave it there. You can watch a short video of the game –in YoutTube–.

Then all the lessons learned could be used to start an actual special project, with more of a plan and hopefully more chances of completing despite being a larger commitment.

The retro game development bible

Cover of the book

The cover of the book

Some time ago Juhang Park contacted me to say thanks for ubox MSX libs –which is always nice–, show me some work in progress games and ask for my permission to write a book about game development in C for the MSX using my libraries.

That was interesting. I don’t think anybody needs permission for that –even without considering the licence of the libraries–, so that is what I told Juhang. I wished them good luck and kind of forgot about it.

Well, the book has been published now in Korean: The retro game development bible. Which is very cool!

Apparently the book was rejected a few times because it was “only MSX”, so Juhang had to cover more ground by including MS/DOS and other “retro” targets –the site selling the book lists a lot of systems, but I can’t tell how deeply they are covered–. And there is something unexpected: Juhang wrote a translation layer so my API can be used with SDL1, SDL2 or Allegro as backends.

There is a reimplementation of King’s Valley 1 using ubox MSX libs –that I’m guessing it is used in the book–. It can be played on the browser thanks to WebMSX. There is also a repo with some info about the different chapters.

Juhang offered to send me a copy of the book, but I can’t read Korean, and told me that there are two MSX games that hopefully will be released soon: Galkave (a horizontal SHMUP) and Bomberman Special (a Bomberman clone).

Cross-compiling Haskell

It is complicated. May be my games aren’t that good or interesting, but if you can only play them if you compile them from source –and besides, written in Haskell–, that is perhaps too niche even for me.

This weekend I put some time into researching it, and there’s some documentation (for example: Cross Compiling GHC), but things don’t quite work. The most interesting issues I have found:

  • Haskell is written in Haskell, so you need a Haskell compiler. Apparently 9.2.5 won’t compile 9.2.5, or I did something wrong. Using 8.10.7 seems to be OK.
  • The cross-compiler is hosted in Linux and the target is Windows, yet the compilation of stage1 tried to include windows.h; which is not available in Linux. I must confess don’t quite understand what was going on, but I couldn’t get past that.

It is slow to try and repeat. Besides, once things fail, there isn’t much I can do.

So I shifted my focus to a different approach: can I run the Windows binaries in Linux using Wine?

It is possible, and I have put together some docs and scripts in cross-compile-hs-wine.

The first part was easy: getting GHC –the Haskell compiler– and Cabal –one of the Haskell’s tools to build Haskell projects– to run using Wine. I mean, is not trivial, but is not too hard. At least for pure Haskell projects, because if your dependencies need a C compiler, or even worse, are bindings to C libraries –like SDL2 and SDL2_Image–, things get very fiddly.

So at the end I had to get everything running in Wine, which includes:

  • Cabal for Windows.
  • GHC for Windows.
  • MingGW-W64, a port of the GCC compiler suite to run in Windows.
  • SDL2 and SDL2_Image development for MinGW.
  • pkg-config-lite, a version of pkg-config for Windows.

Looking around, seems like installing Haskell on Windows (and SDL2) isn’t that easy.

For the second part, because Cabal is awesome, I only had to write a wrapper for it so it can find everything it needs when running from Wine, and after that it was just a couple of issues to get the sdl2 to compile. First I couldn’t get Cabal to find pkg-config, and second I think it might be a bug in sdl2-image –I will open a bug report–.

The compilation is slower than the native Linux versions, and the generated binary doesn’t quite work in the Wine version shipped by my Debian 11 (stable) –tried with unstable from a container, and Wine 8 runs it perfectly–, but this makes things OK: I can build and distribute binaries for Linux and Windows –even if the Windows part is a bit awkward–.

So now I can stop procrastinating and keep working on the game.

Gamedev in Haskell?

So at the moment I have a couple of 8-bit projects on hold, or what we could call my TODO list, but I also have a couple of ongoing projects in modern systems. As I mentioned, there are some ideas I would like to implement before I can do it in a 8-bit microcomputer (you learn by doing it wrong).

At first I thought about finishing my little Canvas 2D engine that I wrote refreshing my Javascript. And it all was going well, until I met again an old friend: I’m not sure if what I’m doing is correct, and the performance of Canvas 2D in Linux is just not what I was expecting. It uses too much CPU, and after a bit of profiling my code and comparing with other games online, I got to the conclusion that it wasn’t me.

Rendering with Javascript

Using a CC tileset

I probably should release that engine “as is”, although I don’t know why anyone would use it.

I didn’t like the result –that could be an issue in Linux, or a recent regression–, and it didn’t matter if I was using Firefox or Chromium. I tried PixiJS, that is a nice framework that wraps all in a 2D API, so you can use WebGL instead of Canvas 2D, and it didn’t get better.

And to not make it a rant on the state of the web browsers on Linux –or in Debian, for me it doesn’t make a difference if I doesn’t work well enough on my system that means it may be like that or worse in other systems–, I also tried LÖVE, although my experiences with Lua in the past left me a bit cold.

Turns out LÖVE is great, despite spending with it only a couple of days. Good documentation, the poor performance I was experiencing with the web browsers is gone, and if you fancy going functional you have Fennel –which is a lot of fun!–.

But then –and this is my own fault– I decided to look at some libraries for LÖVE, and that didn’t go well. I should have done all myself, and I would have saved time fighting those libraries to get to something that was not really inspiring me. So I run out of energy, but I think LÖVE and Lua are worth revisiting. After all my time doing gamedev in Python struggling with performance, this felt great!

Then I remembered that I had a code base that I prepared to use C and SDL2, but never used it for anything. “This is the time!”, I thought. And that is one of my “projects to learn”, a simple JRPG that is progressing nicely –I’m currently working on some formulas and you could see my JRPG design notes (not anymore)–. I should write a post on how I’m integrating fe –a tiny Lisp-alike scripting language–.

And as I keep writing good old C I was looking for something else to do in Haskell, because I have done a couple of things, but my last project was too big and I was learning too many new things at the same time. So why not a simple gamedev project? That would limit the scope.

I have nothing interesting to show yet, because I’m still struggling to have some graphics or even an idea of what I want to do, but the SDL2 bindings for Haskell are excellent. The API has changed a bit to make it more high-level and closer to Haskell, but it wasn’t too hard to understand those changes –taking into account that I’m not an SDL expert!–.

The idea is to make something simple, closer to what I would produce in a game jam, and make it public to get some reviews and tips from friends.

So far my main struggle was around parsing JSON files –for tiled maps–, which I wouldn’t say is too gamedev, and it was a good learning exercise. At the end it was easier and cleaner than my C code using cJSON –that is pretty good–.

Anyway, I’m looking forward to have that small game ready. I’m using ReaderT + IORef and so far the functional and no variables bit hasn’t bothered me at all!

At the end this post is not that much about the title. Oh, well. As an example, this is how my map renderer looks at the moment.

-- | Renders a map.
render :: SDL.Renderer -> Map -> IO ()
render renderer (Map mapData tex) = do
  mapM_
    ( \layer ->
        mapM_
          ( \(x, y) ->
              renderTile x y $ tlTiles layer !! (x + (y * mWidth mapData))
          )
          index
    )
    (mlayers mapData)
  where
    mw = mWidth mapData
    mh = mHeight mapData
    index = [(x, y) | x <- [0 .. mw - 1], y <- [0 .. mh - 1]]

    firstgid = tsFirstGid (mTileset mapData)
    cols = tsCols (mTileset mapData)
    tileWidth = tsWidth (mTileset mapData)
    tileHeight = tsHeight (mTileset mapData)

    renderTile :: Int -> Int -> Int -> IO ()
    renderTile x y tile
      | tile < firstgid = pure ()
      | otherwise = do
          let tx = (tile - firstgid) `rem` cols
              ty = (tile - firstgid) `div` cols
              src = U.rect (tx * tileWidth) (ty * tileHeight) tileWidth tileHeight
              dst = U.rect (x * tileWidth) (y * tileHeight) tileWidth tileHeight
          SDL.copy renderer tex (Just src) (Just dst)

Considering that it is two functions –plus another one to get the SDL_Rect, but that’s not strictly necessary–, I’m quite happy with it!

Playing Persona 4

This is not my first contact with the Persona series, because I tried “Persona 2: Eternal Punishment” on the PS1, but I didn’t really connect with it. The graphics were cool, for a PS1 game though.

Then this Christmas I remembered that one year ago we were really into Final Fantasy IX and I checked again to confirm that there’s nothing like it in the PS1: the previous entries in 2D didn’t work for us –playing with my sons, lots to read– and the ones starting with 3D on the PS1 look way worse than FF IX (e.g. the models on FF VIII are just LOL).

So, what about the PS2? I have to confess that I had never tried to emulate it, and turns out that –without being perfect– the emulation is pretty good in my modest PC!

I don’t really understand how the emulator can play for example Final Fantasy XII without breaking a sweat, and when I run anything remotely 3D native, it uses a lot of CPU and the fans are on all the time –so my PC doesn’t melt–. Same happens with anything running on the browser, including Canvas 2D.

But then we tried FF X and FF XII on the PS2 and, for different reasons, we didn’t connect. So, what about Persona 4? I recall a friend really enjoying Persona 5 on the PS4.

Nice anime graphics

Discussing with the party

And I have fallen in love! The game is just plainly cool. It has a mix of social simulator and JRPG that is very a appealing –even if sometimes you would prefer to go and fight, but instead you have to go to school and care about social interactions to get your stats up–. The graphics are pretty good, and the voice acting is outstanding!

It is a long game and I’m not sure how far I’ll stay hooked, because I have other things to do in my free time and the game is not always OK to play with the boys around.

The combat is fun

Chie is my favourite character so far

The story is complicated, as you may expect on a JRPG, and after enjoying watching Summer Time Rendering early this year –that quickly jumped to my top 5 anime series ever–, this “Persona 4” reminds me of the mood perfectly.

I’m about 13 hours in, and its depth is sometimes a bit overwhelming. Fortunately it includes some “quality of life” features that I would have loved in FF IX –for example: it has contextual help for all the items, so no more using items in combat to see what happens–.

The game has been OK so far, we will see when things get more challenging!

Hyperdrive is out!

Yesterday I finally released Hyperdrive, with very good reception.

So far there are a few short YouTube videos with a bit of gameplay, which was expected: getting to understand the game and get further of the first boss requires some time. Hopefully later on we will see longer videos with people completing the game.

The YouTuber Xyphoe featured the game in his AMSTREAM last night, and it was very fun to watch and participate on the chat. Some takeaways:

  • People like the game, appreciating the technical part.
  • In general, they expect a regular shot’em up and the chain base power-up system is a bit confusing at first.
  • Once it clicked for Xyphoe, he got hooked.
  • When the weapon is not powerful enough –until level 3 or so–, is better to use “precision” by pressing fire when needed; later is OK to keep pressing fire and use a more “burst” approach.
  • When a life is lost, the weapon is downgraded; if the player doesn’t go back to “precision”, the game ends pretty quickly!
  • Xyphoe collected bombs, but he never remembered that he could use them to save tricky situations –probably because getting chains requires a lot of focus–.

In a way, this feels quite a lot like play-testing, although it is happening once the game is finished.

Other than that, I have fixed a small bug related to timing in the menu screen. I have three reports, including myself, of people playing the game on a real CPC not experiencing any issues –I’m assuming that CRTs can be quite permissive–, but the person reporting the issue explained it with a lot of detail and I agree that there was a problem (I was generating 304 lines instead of the expected 312 in a 50Hz output). Anyway, it is fixed now and version 1.0.1 is available to download.

My notes

I was commenting recently the idea of digital gardens, and a bit after that I realised how easy would be to have my own.

This site is already some markdown files on a directory, so I added a sub-directory and some templates to make Hugo render them pretty –with a table of contents, for example–, and that was it.

So you can go to the notes section, and see how it looks. Currently there are a couple of things over there:

So is not that different to what I had when I was using vim-wiki –although I ended not using that one–, with the main difference being that when I update this website, the notes are made public.

The core idea behind a digital garden is learning in public, but in my case I think it is going to be more like an easy and quick way of publishing some work in progress content –a bit like a personal wiki–, or for those things where a blog post is not really the best format.

Time will tell if I keep using it!

Digital gardens

From Digital Gardening Tools and Resources, what is “digital gardening”?

A garden is something inbetween [sic] a personal blog and a wiki. It’s a collection of evolving notes, essays, and ideas that aren’t strictly organised by their publication date. They’re inherently exploratory – posts are linked through contextual associations. They aren’t refined or complete - posts can be published as half-finished thoughts that will grow and evolve over time. They’re less rigid, less performative, and less perfect than the personal “blogs” we’re used to encountering on the web.

I have read about this a few times already, and every single time I find it interesting and makes a lot of sense.

I have always had a personal website. I started around 1998, so for me is pretty much always. Recently I celebrated 20 years of usebox.net, in a way my last personal website. And it kind of felt like that already.

If a wiki is a self-editable website where anybody can contribute, a digital garden could be just a wiki where the owner is the only one editing it, perhaps? I don’t feel like the focus should be in the lack of publication date but in the fact that the content is a work in progress that may be finished at some point, or abandoned in current state.

I like the blog to dump ideas or comment on things that I find interesting, because that helps me to solidify my thoughts –like I’m doing right now–, but it is true that the blog posts eventually disappear to never be seen again –down deep the archive–. There are tags that can help to find content that is related, but there is no further refinement: things get published and are final.

Let’s look for example to my post on bank switching. I think it is a blog post in which the date when it was published is not important and instead refinement of the content would be better –that’s why I transcribed the content to CPC Wiki, so it doesn’t get lost–.

I was looking at mkdocs last night, because I like it and this was the perfect excuse to put something together, but I woke up today undecided. I already have this website, and it could work as well to keep my notes –call it work in progress or digital garden–, I just need to find a way to make that information accessible.

Further info: