Spectrum-48 against a pack of cigarettes, porridge from an ax or what can STM32F103C8T6 + video (update)

It all started with another attempt to quit smoking. After waking up my internal “toad” in search of support, I say to her: “Look, a pack of my cigarettes stands today like a pocket retro computer with a screen, that is, about $ 10, and once long ago, we’ve been paid for the entire month’s salary and more than a month spent on assembly and debugging. She: "You men are goats and liars, prove it!" I had to work.

So, the initial consumables:

  1. "Blue pill": STM32F103C8T6 - 20K ram 64K flash $ 2.06
  2. Arduino Display: ILI9341 2.8 "320x240 with touch screen and card slot $ 7.72
  3. Squeaker $ 0.18
  4. A few buttons (7 pieces) $ 0.2
  5. A bit of wire $ 0.1
  6. 64 mega flash card (from an ancient camera), not included in the calculation
  7. The ST-LINK programmer is not consumed and is not included in the calculation, but it also costs a couple of dollars
  8. A pack of cigarettes - consumed too quickly and every day - $ 8.37



The wonderful “blue pill” of Chinese production is good for everyone, except for the amount of RAM, only 20K (though there is also little constant, only 64K). Spectrum-48K need 48K (coincidence? I don’t think) of RAM and 16K constant. Let's borrow the operative memory at the screen, because the resolution of the spessi is 256x192 + border, while the ILI9341 has a resolution of 320x240 18 bits per dot. That is, you can use the middle of the screen for drawing, and everything else - for the actual “swap area” (swap area?). The most common (LRU algorithm) used by the emulator of the Z80 processor is the memory cached in the STM32 RAM, the rest is stored in the on-screen memory ILI9341, with slow (SPI) access.

About 25 years ago, I wrote the Z80 emulator on the 80286 platform, they are not very distant relatives with the Z80, both originated from 8080, which made it possible to get very fast code using the wonderful Borland TACM and C ++, but then there was no need for such detailed emulation ( The code was written for both sides: a notebook with a dictionary and its emulator for windows 3.1 for debugging).

It was too lazy to write from scratch to Arm, so I asked Google: “Tell Google, how are you today with a neat Z80 emulation?”. Google gave me a couple of thousand two suitable projects: Based on the STM32F4, by Gorien and the most advanced and debugged Fuse-emulator . When I first assembled the code from Gorien, I got about 100K executable code, which is clearly more available on the subject. I had to tinker a bit with shoving an elephant in the fridge . For example, calls to local variables are compiled into a more compact code than the global ones; all extended commands of registers IX and IY are the same, up to the replacement of variables, the character generator table can be replaced by a reference to the Spectrum character generator, etc. We also needed to overclock the processor to 112 MHz ( thanks to xedas for the idea ).

The result: a working (tried about a dozen games while everyone is working) an emulator ZX spectrum-48 with a screen the size of a pack of cigarettes (already pockets into the pocket, but the wires stick out), reading dumps (icon + memory image + ~ 50K registers) of games with FAT32 format flash cards (a few more kilobytes of code) and with a total consumption of ~ 50mA (that is, about 50 hours from a typical 18650 battery at 2500mAh!), a turn-on time of less than a second and a total cost of around parts less than $ 10.

Disadvantages:

  1. Still a little slower than the original.
  2. The screen shows the code of the downloaded program, in color.
  3. Need joystick, or buttons softer. And a fee. And a box. And straight arms. And ...


In the approximate plans: reducing consumption (tearing the LEDs off the board), add screen brightness modulation, clock mode with the screen off, solder a normal keyboard with a joystick, adjust delays for correct sound and tape recorder (do you need it?), PC file format converter dump, shrink some more code to host the user interface. Try to cheapen the platform using a 2.4 inch screen. It is true, well, very small, but for 5 ... It is clear that the interest is purely sporting, although if you take into account the speed of disassembly of any electronics for unusable parts by grandchildren, the price still matters.

Actually current working code on Gitkhab

And more pictures for fans, the game R-type, on the edges around the main screen swap area:



Other side:



Atic-Atac game:



PS: I didn’t keep up with the cost of a pack of cigarettes, so my “toad” will have to suffer my bad habits, but I’m already 55, so I have already spent most of it ... To be continued.
Video, no sound, sorry:

Source: https://habr.com/ru/post/412325/


All Articles