Announcing the Commencement of Portable Game Console Project

May 19, 2018, 3:19 p.m. Behind the Scenes Electronics Portable Game Console Programming ilo musi

Photo of the portable game console

If you know me personally, you'd probably heard of this portable game console. I have been working on this project for almost two months! I decided not to blog about this until now because I wasn't confident about the completion of this project. My main concern was the hardware design of my portable game console isn't going to work at all. Now that I've tested and proven that it's possible to do whatever I need to for this project. Therefore, it's now the right time to announce this project in this blog! :)

Introducing Portable Game Console Project! It is a minimalist, low-cost portable game console. It isn't an emulator of existing game console. It's a brand new game console system. It doesn't have a name yet. Until it's getting named, I'll just call it portable game console.

Motivation

It's mostly a "because I can" project. I aim to learn stuffs from this project, including drawing PCB board, electronic design, a little bit mechanic design by drawing the case of the console, embedded programming, etc.

This is an open source project. There're already many existing game consoles. I don't think anyone would be interested in getting this one. Commercialization is out of the question. Instead, upon the completion of this project, I plan to do free giveaway of this console (and hopefully someone would be interested in developing games for this console). Waste all of the time! Lose all of the money! Hooray! :P

Feature

Specs

Development Flow

  1. [Done]Hardware design
  2. [Done]Purchase prototyping material
  3. [Done]Solder a prototype of the circuit on a perfboard
  4. [WIP]Developing the API
  5. Developing Games, mainly for testing the API
  6. Drawing PCB
  7. Making the container case for the game console. Probably by 3D printing
  8. Port the API to PC platforms and possibly browser (Optional)
  9. Small scale production and giveaway

Hardware Wiring

I haven't drawn a schematic diagram. So I'd just write down the wiring of STM32F030F4P6 to other hardware here. It's enough for anyone to reconstruct the circuit

Here's how the connection looks like on the prototype hardware:

Photo of the back of the portable game console, showing the soldering trace on perfboard

Software Development Environment

I've never used most of these tools and software before this project.

OS Design

STM32F030F4P6 is the microcontroller of this portable game console. It's a low-end ARM Cortex-M0 microcontroller.

It has 4kB of RAM and 16kB of Flash. In our design, the flash memory is split into two parts. The first part is the bootloader. The second part is the application (game). The bootloader contains the implementation of the API for accessing the LCD, sound system, buttons and SD card. The game is a playable that calls those API functions to access the hardware function of the game console.

The RAM is also split into two parts. A small part is exclusively used by the API. The other part is available for the application.

In addition to that, the bootloader will show a menu for the user to pick a game stored in the SD card. When the game is chosen, self-flashing will be performed to the application part of the flash memory. Then the BX instruction will be called to set the program counter to the starting point of the application, which will caused the game to be launched. There's, unfortunately, no protection of access. Although there's no API for that, it's technically possible for the application to, says, implement their own function to erase the SD card.

The bootloader will probably take 8kB of flash and very small amount of RAM (like 100 bytes).

Implemented API Calls

The API call can be made by using a software interrupt. There's a fixed-address, 8-bytes storage inside the RAM. The API can be accessed by the application by first manipulating the content of the RAM of that address, then trigger a software interrupt. The interrupt EXTI line 15 is used for software interrupt. This design is inspired by int 80h of unix kernel.

Keys Input System

Three functions are available:

keysSetDebouncePeriod() is used for setting the software debounce period. The longer it is, the slower the reaction time, and less noisy the response is.

For keysGetPressedState() and keysGetJustChangedState(), each bit represent the state of a button.

For keysGetPressedState(), pressed button would have its bit set to 1. The non-pressed one would be 0.

For keysGetJustChangedState(), pressed button that had changed would have its bit set to 1. Otherwise 0. For example, if the keysGetJustChangedState() of a button is 1, and the keysGetPressedState() is 0, that implies that the button was just released. After calling this function, the justChanged state of all buttons would reset to zero.

Sound Synth System

The sound system consists of two identical 1-bit synthesizer. One of them is for sound effect (foreground), another of them is for background music. Only one of them can output sound at one time. Depending on the configuration, it's possible to pause the background music while the sound effect is being played, or have the sound effect played during its effective duration, replacing the part of background music.

The sound synth has the following capability:

In addition, a musical playback format is defined for this game console, which enables the application to play music by calling an API function.

Sound Synth System: Frequency

Piano uses a 12-suboctave scale, which means that each octave is divided by 12 notes.

However, in this game console, a 32-suboctave frequency scale is used instead. It means that each octave is divided by 32 notes. This game console is able to generate more fine frequency compared with piano, mainly useful for sounds effects. Since 32 isn't divisible by 12, some of the piano notes has to be substituted with a close enough frequency. Fortunately, this is not a problem because "Humans can notice a difference in pitch of about 5 to 6 cents" according to a paper by Beatus Dominik Loeffler. For a 32-suboctave system, the maximum error compared with piano note would be 64-suboctave, which is 1/64*100=1.5625 cent of error, which is far less than 5~6 cents. I've also personally listened to a piece of music played on the game console. It sounds good. So the frequency error isn't a problem. :)

During frequency sweeping, the 32-suboctave is further subdivided into 16 frequencies, forming 512-suboctaves. Each step of sweep would increase/decrease the frequency by a 512-suboctave until the final frequency is reached.

The frequency of the sound to be played is 2^(5+n/32) Hz, where n can be any value from 0 to 255.

Sound Synth System: Duty Cycle

Generation of tone requires vibration of audio signal. For a 1-bit synth, the duty cycle determines the duration of the signal to be LOW or HIGH. Let's take a 1000Hz sound wave as an example. It takes 1ms to complete a period. If the duty cycle is 50%, 0.5ms would be spent on LOW, and another 0.5ms would be spent on HIGH. If the duty cycle is 75%, the signal would be LOW for 0.25ms, and HIGH for 0.75ms.

Although this synth is 1-bit synth, it's possible to control the volume of the synth by using duty cycle. That's because the duty cycle affects the RMS value of the waveform. The closer the duty cycle to 50%, the louder the sound is.

The duty cycle can be adjusted (1-1/(n^2)) * 100%, where n can be any value from 0 to 15.

Unlike frequency, the duty cycle sweep does not have any subdivide mechanism.

Sound Synth System: Music Format

The format is simple. It's a mix of command and data. Data starts with a non-zero byte. Command starts with a byte of zero. It has 6 modes. They are STOP, DF, DCF, FULL, FULL->DF, FULL->DCF.

To switch mode, set the first byte (duration) to 0, then set the second byte to the command ID. The command ID for STOP is 0, DF is 1 and so on. Here's an example of a piece of music:

uint8_t musicArray[] = {
0, 4,  //Switch to FULL->DF mode
20, 97, 97, 0, 0x11, 0, SYNTH_FREQ_SWEEP_TRIANGLE|SYNTH_DUTY_SWEEP_REPEAT_ENABLE, //Play a sound with full parameters specification and switch to DF mode
20,102, //Now that we're in DF (duration+frequency) mode. We play a sound in DF mode
65,105, //Play another sound in DF mode
20,97, //ditto
20,105, //ditto
45,102, //ditto
100,97, //ditto
0, 0 //Switch to STOP mode. It's like a NULL character for string.
};

Sound Synth System: API Functions

The following functions are available:

Sound Synth System: Demonstration

Here's a piece of recorded music generated with the game console by using the music format:

Unimplemented APIs:

Future

I'll continue be developing this game console. It'll probably be completed some time in 2019. I'll update you guys about any progress! :)


Comments

Sadale
May 20, 2018, 4:11 a.m.

@Kagura I haven't watched that anime. :(

Kagura
May 19, 2018, 4:18 p.m.

So, I got really important question after reading this awesome blog post: who's your favorite gintama character?

View all comments