 So, welcome to an introduction to the basic engine. My name is Ulrich Hecht, I'm a freelance software engineer and I write Linux drivers for a living. And sometimes I do stuff with small and retro systems. This is my website in case you need any Linux kernel stuff. Who knows. What is the basic engine? Here's a picture. The basic engine is a low-cost single board computer. It's programmable in basic. It has advanced 2D color graphics and sound. What that means, I'll show you later. And you can build it at home for less than 10 euros. And if you decide to mass produce it, it's way cheaper than that. Some hardware specs. It has a 32-bit RISC CPU, runs at 160 MHz and 4 MB of flash memory. 128 kilobytes of video RAM. It can produce PAL or NTSC analog composite video. It emits 5-bit PCM sound samples. It has a microSD card slot for storage, but you can also use the 4 MB of flash memory for storage or other 3 MB thereof. It has a PS2 and USB keyboard interface. The USB has an asterisk. That's because it actually is also a PS2 interface. It takes advantage of the fact that many USB keyboards have a PS2 compatibility mode. And if you speak PS2 to them, they will just speak PS2 back. Unfortunately, that only works for about 50% of keyboards. So if you want to stay on the safe side, use a PS2 keyboard. And it has a PlayStation controller port, the old style that the one from the PlayStation 1 and 2. And it has 16 GPIOs and an I2C bus and a spy bus and an expansion connector. So, many events, graphics and sound. This is obviously the focus of the system. It has 256 color graphics in a variety of resolutions, a bit more on PAL than on NTSC. You have... shit, it doesn't work. You're supposed to see the title's background graphics here. Yeah, how did I do that? Basically, you can think of it as a scrolling screen with background tiles and you can pan about it. Like a typical 1990s video game, early 90s. It has up to four layers. It's so bad that this doesn't work now. So you can do parallax scrolling. It has up to 32 sprites. That works. It can play music in MML format. It has a synthesizer, a wave table synthesizer and you can also do sound effects. Probably couldn't hear that because the mixing is not so great. And yeah, it's so bad that this doesn't work. I so hate it. Okay, the origins of the system is I wanted a computer that connects to a TV and a keyboard. And it should have been possible to program it in basic and it should be self-hosted. That is to say, you should not need another computer to program the computer. So it's not like an embedded system or a games console or something like that. It has to be colorful and noisy otherwise it's boring. And it should be possible to make it at home. It should be cheap and you should not need obsolete parts. Like when you have to rely that somebody in China still has a box of a certain kind of chip, in there that's not good. And why did I want that? I really don't have, absolutely don't have the time to get into that right here. I did a write-up of that and you can find it on the basic engine website. And now you would think somebody must have done that already. And the short answer is no. The slightly longer answer is almost. Somebody came very close. This is the Toyoski TinyBasic system. It is, yeah, what is it? It's basically an STM32 microcontroller development board. A so-called blue pill board. That's the blue thing in the middle. And it has a battery and a couple of connectors for keyboard, SD card and video. And that's it. Nothing else. So this is basically just a development board that costs 1 euro and 40 cents on Aliexpress and some metal and plastic. So that is a design I can get behind with. The video is generated by software and it's blown out the spy bus. And if you know how an Atari VCS works, that's kind of like it. Like every line you have to prepare the line and then it will be sent out to the video port. And it runs TinyBasic, a dialect of TinyBasic that, unfortunately I forgot the name of the guy, wrote a Japanese gentleman for the Arduino. And like I said, it costs virtually nothing. Now, if everything were great, then I wouldn't have to make my own system. So there are a few problems with that from my point of view. It only has monochrome video. It has no free memory worth speaking of because the microcontroller from the outside only comes with 16 kilobytes of memory. And if you reduce or if you subtract the memory in it for the basic interpreter or for the frame buffer, for the graphics, then you have like 11k around about left. That is not a lot. And this is a fun aspect. The firmware may or may not fit the device because it's around 64 kilobytes. This microcontroller has 64 kilobytes of flash. So if you add anything, it will sometimes work because sometimes these microcontrollers secretly come with more memory, probably because they had a good day at STM, at ST. But usually it probably won't fit. So this is not so great. Can we do something about that? I try to add hardware, like simple hardware that doesn't cost much to generate color. That is unfortunately a bit tricky with analog video. You need to basically mix a high frequency color burst signal on top of the monochrome signal. And I used all sorts of tricks and some of the timers of the STM32 chip. It has very capable hardware, but that consumes a lot of resources. The obvious ones are it consumes a lot of hardware and needs all these timers. You don't have timers for your system anymore, so you have to do a lot of stuff that would be way easier otherwise. But the way more important thing is I only thought of that once it was almost finished is that color graphics need more memory and we don't have that. So if you have like eight colors, three bits, that uses three times as much memory as the monochrome graphics, which leaves you with nothing left. And there is also no way to expand memory with any sort of performance because that is not something that you usually need with a microcontroller. These are made for industrial applications and they don't have any fast memory buses. Interesting. What happened? I haven't given a presentation in like more than ten years, so please bear with me here. And of course STM32 has better controllers, but they are super expensive. We are talking like several euros, but it's like you can't do that. So I decided I had to make my own system. That's a prototype that you can see here. And you of course want to keep the good stuff. It's cheap and simple. That is like the baseline. It has to run basic because I like that. And it has a text system with a screen editor. And those last two things are things that the Toyoshiki Tiny basic system already had and that's all software. I just took that whole sale. For those who don't know what a screen editor is, if you have programmed Commodore basic, you know how that works. It's basically not like a command line where you type your stuff at the bottom and then whatever is printed scrolls up and you're always in your line at the bottom but you can move the cursor around the screen like in a text editor and whenever you press enter whatever is under the cursor will be executed. Very chaotic, very fun to use. And then of course it's supposed to be better than the other system. So it needs color. No chrom is depressing. I cannot say that often enough. It needs to have more memory of course. It needs to have better sound. Actually I forgot to mention that the Toyoshiki Tiny basic system has a buzzer. So that's not. And then battery. I mean come on. No battery. If you need the time you have a watch. So you need something that executes code if you want to make a computer because if you look for a cheap microcontroller with a lot of memory the first thing that comes up is this. This is the Espressif ESP8266. So what's that? It's a superlocos microcontroller for IoT stuff and it's basically the go-to solution for makers who want to connect random hardware to the internet. It has lots of power for all this bloated networking stuff. You need to do all the cryptography and the bloated file formats and all that stuff. But that's just mandatory. You cannot get around that. So it needs to be able to do that. But not much more than that because once you are connected to the internet what do you do? You read a sensor, read the temperature. You switch the lights on and off. If you're a very privileged ESP8266 you get to decode an mp3 stream from the internet. But that's the best life you can have. When you program that thing it feels a bit sluggish. You write hello world, it uploads 220 kilobytes of code over the serial port. And then it boots. And that takes a while because it has to set up the network hardware. Not fun. So the question is why use it then? We don't really need all that network stuff. It was not on the slide before. And if you drop that then you have something that is really fast, really cheap and it has a better price performance ratio than any other microcontrollers you can get. So go for it. So now you have something that executes code. You still don't have anything that displays stuff on the screen. We could do that in software again but not so great. And also we need more memory because the ESP8266 has like a grand total of 160 kilobytes of which you can actually use 80 kilobytes for your program of which a lot goes for various administrative purposes. What you effectively are free is about 61 kilobytes. You don't want to use that up for a frame buffer that uses 64 kilobytes especially because you can't. So what is this thing? It is an SRAM chip. It's a static RAM chip with 180 kilobytes of memory and it has a spy interface so it's easily connected to any sort of microcontroller. But it also has a video controller. That is an unusual feature for an SRAM if you're not used to that kind of stuff. And what it does, it turns the contents of its memory into composite video. You don't have to do anything. You set up about 2 million registers it just moves that stuff out of the video port and you don't have to do anything other than write it out over this spy bus. And it has a blitter. That's really cool. Because it's too bad that this thing wouldn't work before. And because that makes it very easy to make these scrolling backgrounds, the tiled backgrounds because you can easily compose your screen out of various tiles 60 times a second and you can make full screen animations and stuff like that. It's relatively easy. It has a ton of bugs but it works. It is also the cheapest analog video controller available as the risk again. Because it is very cheap if you buy a lot of them like a real or two. Then it's 1 euro and 70 cents per piece. If you buy 10 you pay 390 per piece. So not so great but it's the only analog video controller available. Nobody makes a chip like that anymore. What comes next? You need something to run on that. The basic engine runs engine basic. Obviously it's derived from tiny basic as mentioned before. It's a traditional basic interpreter. So code looks like that with line numbers and stuff. It does have some improvements that I've added. It has some structured programming constructs, pre and post tested loops if then else blocks. If you have programmed a traditional basic interpreter before you know that if you have a block of code that you want to execute conditionally you invert that condition and then you jump over it. So that's already very unreadable but if you have an if then else construct you have to invert the condition then jump over it and in the conditional block you have to jump over the other the else block. It's like even describing it is already confusing. And this takes care of that. So you write it like in more than programming languages. It has labels and name procedures with local variables and arguments. So you have the line numbers but you don't have to use them if you don't like it. This presentation is written in that style. It's in fact written in a mixed style because like this 10 print go to 10 that's actually part of the presentation. The numbers are double precision floating point because benchmarks suggest that it doesn't make a difference really and 32-bit floating point is super inaccurate and only having interest is also not so great so double. I've also added string and numeric list types because basic is traditionally bad at complex data structures and at least that's a little useful. And there are escape codes for print. They are similar to the control characters in Commodore basic or you can think of VT100 escape codes. So you can easily change color, move around the screen and stuff like that. You don't have to do write verbose commands for that kind of purpose. And there are asynchronous event handlers for sprite collision, for end of music, for errors obviously, for game control input. There should be one for vertical sync. I think I must have forgotten that. But that would be easy to implement if I actually forgot it. I very often have to consult my own manual to find out what I've actually implemented. Now of course you want to build one. Do the following. Go to this web page, read it, buy the parts and the very reasonably priced tools. If you have nothing at all at home for building electronic stuff, it will set you back I would say 150 to 200 euros for building parts for 10 basic engines. So I'd say it's reasonable. Then you can watch a video, one hour very boring video made by me. No voiceover or anything where I just put this thing together in the most basic way. And the technique that I use there, you don't need any skills, you don't need a steady hand, you don't need practice, you don't need anything. You just need these tools and you can do it. Believe you me, you can. And yeah, do that. Don't listen to people claiming SMD soldering is hard. I find it in fact much easier than through-hole stuff. And do not use solder paste, that's my personal gripe because it's really for manual stuff, it doesn't work. Now you've already built a basic engine. You can build 10 of them, that's even better. Write a demo, there are a couple of those. One is funnily enough Sokoban. And it has also been ported from a text-only display, so I don't know, we've been thinking like that. There is also Tetris, there is a shoot-em-up game that I ported from C. Once you write the demo, you will find bugs. Please report them. And don't forget to include a test case. The basic engine has a test suite, like really old stuff from the 60s. Super great because it uses absurd stuff. Fix the bug. There are not many bugs reported yet for some reason, but again, you will find them. Don't forget to run the test suite before you submit anything. Okay, what's the time anyway? Ooh, that was very fast. So, not yet, because I have some bonus content here, in case I talk too fast, or the demo doesn't work or stuff like that. I showed you the basic engine before, right at the beginning. This is a secret second model of the basic engine. I call it the basic engine shuttle. It is faster, smaller, cheaper. It has more memory, it's easier to build and it doesn't need the VS23 SO10, which is some people find difficult to get because it's only available from the manufacturer and from one distributor in Poland who has constantly sold out since I released this thing. I don't know if that's good or bad. There is a catch though, because otherwise that would have been the successor. It doesn't work on every TV. And the reason is that it uses a software method to create the video signal that somebody came up with. Very ingenious, but relies on the fact that certain frequencies in this ESP32 processor or in this module as it uses this processor are almost integral ratios of frequencies in the PAL color carrier and that's why it works. But it's not 100% match. So I have 40 Vs at home that I use for testing this stuff. It works with two of them. Not so great. And it's probably not fixable because this approach really pushes the hardware to the absolute limit. There is no wiggle room. If you're not deterred by that, you can try it out. In fact, I learned some lessons from building the first one so this is easier to assemble. So if you really, really, really think you cannot build the other one, you can try this. Some more fun stuff. You can do this. It runs in for context adventures because completely pointless feature but I just couldn't help myself there. Somebody ported Jzip to the Arduino and I thought if an Arduino can do that then the basic engine should be able to do that as well and you can just return to basic after you're done. Like a Bosch key. What else? Something I implemented recently is Lua. Lua is a, I'm sorry, I can't really competently explain the features of Lua but it's a very nice programming engine that's almost as simple as basic and it's much better at handling complex data structures i.e. does have support for complex data structures at all. It is not bloated or restricted or otherwise crap I'm sorry most other languages are. That's why I chose basic basically. What is implemented so far is the standard IOS stuff, file access and things like that and print and clear screen and locate which moves the cursor. Not implemented everything else because that's like from two weeks ago or something. Your chance to help out implements bindings for all the great features of the basic engine for Lua. This is another thing that never works. In the simulator it works on the real thing I swear. Speech synthesizer, reverse engineered from C64 somebody made an Arduino library and it has had to add that. I really tried not to but it didn't work. It's your Stephen Hawking for pedestrians. I don't know if anybody heard that but at least it worked this time. So, I really speak too fast. Does anybody want me to try to run the demo again because maybe it works a second time. Let's try that again. Just reload it. Let's see. This is how it's supposed to look like and now you can see the background layers and now you can see the sprites. Thank you, thank you. Pardon? Can we file a bug? Yeah you can file a bug because that shouldn't happen. I don't know why it does. I think it doesn't happen on the real thing. This simulator is some bugs that the actual device doesn't have. So, let's get back to this one. So, any questions? Because I'm out of material already. Please. Why can't you make this machine work with digital output instead of analog? Because it's very hard to find analog models. Yeah, that is true. Yeah, let me repeat the question. Is it possible to get a digital output because analog video inputs are occasionally hard to find? Not a really digital output. This hardware you can't because the chip only produces composite video. VLSI has made a new chip that is basically four of these concatenated and with this you could produce a VGA signal. So that is probably the best you can do with this kind of stuff. I'm currently looking into FPGAs because some FPGAs that are capable enough to contain a system like that are also cheap enough so it wouldn't get more expensive and then you could do it. So that would be a possibility because you can just synthesize whatever IP you want in there. So it would need a new hardware. With this one, as it currently stands, you can't. You can't have a digital output. Anything else? Have you seen that Minimite machine? Yes, I have. Yeah, the Minimite. It doesn't have the kind of graphics that I'm looking for. That's basically why I disregard this. It's also a bit on the expensive side. Yes, please. Does the PS controller support analog controls? It does not at this time but that's a relatively minor issue in the software. You could implement that. If anybody needs to make an enhancement request in the backtracker, it can be added. It would work. Do you consider the possibility of adding an LCD driver so that we can connect directly to LCD? Because if we are doing the hardware, we could just connect an LCD driver. Would it be possible to add an LCD driver to the hardware? Yeah, that's what I just did. Not as it stands, not with this graphics hardware. You would need a new graphics driver. I guess it would be possible. But you would also run into a scarcity of resources on the microcontroller. It doesn't have a lot of I.O. So that might be a problem. Possibly with an LCD controller, it also attaches to SPI that might be possible. But again, you have to change the hardware for that. But in principle, yes, please. What kind of features does the Blitzer have? Sorry, what was that? The Blitzer. What can you do with it? Basically, you can just copy rectangular pieces of... What kind of features does the Blitzer have? Not many. You can basically only copy rectangular areas of graphics memory from A to B. So what is usually done, what you would see in that demo, is that you have a tile set in off-screen memory and it would be composed into a background screen. But it doesn't have transparency or anything like that. So it's very basic. It's also very buggy. Yes? Quite a while. If you include the predecessor to this project since 2013 or something like that, this particular version... I don't know, 2017 or something like that. Something like that. Quite true, but that order of magnitude. Yes? What are you talking about soldering is simple with this indeed? What's that about? The thing is, when you... I basically... So sorry, yeah. What am I talking about when I say soldering isn't difficult? That's what I'm saying. Yeah, so it's just soldering. Yeah, it actually isn't very difficult because you just... When you look in YouTube, I get basically all my information from YouTube about soldering and stuff like that. Anything visual like a PCB design or anything. It's from YouTube. And when you look there, people always mock about with solder paste and with all that kind of stuff, or they have like 15 years of training and can really like... drag solder you a gigantic FPGA. That is not something that works unless you want to dedicate your life to soldering. Which I don't. So I just came up with a technique. I originally didn't want to use this chip because it has the fine pitch, because I thought I could not do it. And then I just thought, do away with this mucky solder paste and just use solid solder and just coat it and put the thing on top and put some flux and then heat it. And that worked the first time. So this is okay? Yes, yes, you are allowed to use that. There is in fact one guy who uses flux only with HASL boards. That's... I wouldn't rely on that. Even I wouldn't. So put a little bit of solder on the pads and that will do. Yeah. Anything else? Yes. Did you write an emulator for the machine as well? That's not really an emulator. It's a simulator. It's a graphics chip because I wanted to debug something. But it's really just the code of the firmware compiled for a PC. So it has basically a thin Arduino compatibility layer if you want to call it that. And I mostly wrote that to use Valgrind and GDB and also to make videos for YouTube which I haven't gotten around to yet because don't use this with frame grabbers. They are all crap. Like even the expensive ones. It looks way worse than on a TV. So I really like the videos that I put up now on YouTube. They have been filmed off my TV. The good one. Yeah. How would you compare it to these very cheap educational computers like the code bug and the BBC micro bit? So how would I compare it to other educational systems like that? Unfortunately... That was the idea. I'm not familiar with those specific models. But mostly, I would say, I put an emphasis on graphics and sound. That's really what I was going for. Yes. Can you compare it with the decoyed idea? Yes, I have. In fact, that's where I got the lure idea from, actually. I only recently learned about that because I was looking for something else. I don't want to speak badly about other systems. But the thing is, for those of you who don't know, the Pico 8 is basically a virtual system. It doesn't exist in actual hardware. It's basically something like this only. Not the real device. And to me, that always feels kind of fake. It's not a real system. I just don't feel good about developing for that. It's like a more powerful system masquerading as a weaker system. That's fake to me. Not for me, but the lure idea is great, and that's why I did lure recently. Yes? So you used ESP, microcontroller. I guess you wrote everything in bare metal on that, basically. Almost. It's Arduino, so it's in C++. Because that's what the tiny basic system originally was, and I just lifted all that thing wholesale because it has all these text display systems, and that's all stuff that I really don't like to do. And so I just could use it even as a Japanese input method because of its Japanese heritage. So I left that in. So it's C++ basically. Anything? Okay. Then thank you for your time.