A handheld computer made on a piece of prototyping board running a Tetris clone

Tetris Clone Uses 1000 Lines Of Code, And Nothing Else

If you’re programming on a modern computer, you typically make use of lots of work done by other people. There’s operating systems to abstract away the complexities of modern hardware, standard libraries to implement common tasks, and tons of third-party libraries that prevent you from having to reinvent the wheel all the time: you’re definitely not the first one trying to draw graphics onto a screen or store data in a file.

But if it’s the wheels you’re most interested in, then there’s nothing wrong with inventing new ones now and then. [Michal Zalewski], for instance, has made a beautiful Tetris clone in just 1000 lines of C, without using anyone else’s code.

The purpose of this exercise is to show that it’s possible to make a game with graphics comparable to modern, complex computing systems, without relying on operating systems or third-party libraries. The hardware consists of not much more than an ARM Cortex-M7 MCU, a 240×320 LCD screen and a few buttons soldered onto a piece of prototyping board, all powered by a set of AAA batteries.

The software is similarly spartan: just pure C code running directly on the CPU core. Graphic elements, some generated by AI and others hand-drawn, are stored in memory as plain bitmaps. They are manipulated by 150 lines of code that shuffles sprites around the display at a speed high enough to generate smooth motion. Game mechanics take up about 250 lines, while sound consists of simple square-wave chiptunes written in just 50 lines of code.

[Michal]’s code is very well documented, and his blog post gives even more details about all the problems he had to solve. One example is the length of keypresses: when do you interpret a keypress as a single “press”, and when does it become “press and hold”? Apparently, waiting 250 ms after the first press and 100 ms after subsequent ones does the trick. [Michal] is a bit of an expert on bare-bones game programming by now: he has previously pushed several 8-bit micros to their very limits. Third-party libraries can make your programming life a lot easier, but it’s good to reflect on the dangers of relying too much on other people’s code.

Continue reading Tetris Clone Uses 1000 Lines Of Code, And Nothing Else”

Processes, Threads, And… Fibers?

You’ve probably heard of multithreaded programs where a single process can have multiple threads of execution. But here is yet another layer of creating multitasking programs known as a fiber. [A Graphics Guy] lays it out in a lengthy but well-done post. There are examples for both x64 and arm64, although the post mainly focuses on x64 for Windows. However, the ideas will apply anywhere.

In the old days, there was a CPU and when your program ran on it, it was in control. But that’s wasteful, so software quickly moved to where many programs could share the CPU simultaneously. Then, as that got overloaded, computers got more CPUs. Most operating systems have the idea of a process, which is a program that thinks it is in complete control, but it is really sharing the CPU with other processes. The problem arises when you want to have multiple “little” programs that cooperate. Processes are not really supposed to know about one another and, if they do, there’s usually some heavy-weight communication mechanism allowing them to talk.

Continue reading “Processes, Threads, And… Fibers?”

A software-defined radio system in a 3D-printed case with a 7" display and an array of knobs and switches

Hackaday Prize 2023: A Software-Defined Radio With Real Knobs And Switches

When cheap digital TV dongles enabled radio enthusiasts to set up software defined radio (SDR) systems at almost zero cost, it caused a revolution in the amateur radio world: now anyone could tune in to any frequency, with any modulation type, by just pointing and clicking in a computer program. While this undoubtably made exploring the radio waves much more accessible, we can imagine that some people miss the feeling of manipulating physical buttons on a radio while hunting for that one faint signal in a sea of noise. If you’re one of those people, you’re in luck: [Kaushlesh C.] has built a portable, self-contained SDR system with real knobs and switches, called SDR Dock 1.0. Continue reading “Hackaday Prize 2023: A Software-Defined Radio With Real Knobs And Switches”

Carbon Fiber With 3D Printing

[Thomas Sanladerer] wanted to make 3D prints using carbon fiber and was surprised that it was fairly inexpensive and worked well, although he mentions that the process is a bit intense. You can learn what he found out in the video below.

He used an advanced PLA that can endure more temperature than normal PLA. That’s important because the process uses heat and the carbon fiber resin will produce heat as it cures. The first step was to print a mold and, other than the material, that was pretty straightforward.

Continue reading “Carbon Fiber With 3D Printing”

The Reverse Oscilloscope

Usually, an oscilloscope lets you visualize what a signal looks like. [Mitxela]’s reverse oscilloscope lets you set what you want an audio waveform to look like, and it will produce it. You can see the box in the video below.

According to [Mitxela] part of the difficulty in building something like this is making the controls manageable for mere mortals. We really like the slider approach, which seems pretty obvious, but some other controls are a bit more subtle. For example, the interpolation control can create a squarish wave or a smooth waveform, or anything in between.

This is sort of an artistic take on an arbitrary waveform generator but with a discrete-panel user interface. The device contains a Teensy, a Raspberry PI Pico, a 16-bit ADC, and an external DAC. The Pico is little more than an I/O controller, reading the user interface and transmitting it on a serial port.

The outside construction looks excellent (we assume the tape is temporary). The inside is a bit messier, but still nicely done. There are many photos of the construction and details of problems along the way with 12-bit ADCs and power supply experiments.

Of course, if you don’t need the user interface, you can go crazy with waveform generation. We did our own similar project, but you could draw your waveforms on the PC instead of sliders.

Continue reading “The Reverse Oscilloscope”

Dark Trace CRTs, Almost The E-Ink Of Their Time

When you’ve been a fact-sponge for electronics trivia for over four decades, it’s not often that an entire class of parts escapes your attention. But have you seen the Skiatron? It’s a CRT that looks like a normal mid-20th-century tube, until it’s switched on. Then its secret is revealed; instead of the glowing phosphor trace we’d expect, the paper-white screen displays a daylight-readable and persistent black trace. They’re invariably seen in videos of radar installations, with the 360 degree scans projected onto large table-top screens which show the action like a map. It’s like e-ink, but from the 1940s. What’s going on?

Two photos of the same crystalline rock, the top one is white, the bottom one is purple.
The tenebrescent mineral Hackmanite, before and after UV exposure. Leland Green…, CC BY-SA 2.0 and CC BY-SA 2.0.

The phosphor coating on a traditional CRT screen is replaced by a halide salt, and the property on which the display relies is called tenebrescence, changing colour under the influence of radiation. This seems most associated online with UV treatment of some minerals and gemstones to give them a prettier look, and its use a s a display technology is sadly forgotten.

A high-school physics understanding of the phenomenon is that energy from the UV light or the electron beam in the case of the tube, places some electrons in the crystal into higher energy levels, at which they absorb some visible light wavelengths. This is reversible through heat, in some substances requiring the application of heat while in others the heat of room temperature being enough. Of course here at Hackaday we’re hands-on people, so into the EPROM eraser went a small amount of table salt in a makeshift dish made of paper, but sadly not to be rewarded by a colour change.

On a real dark-trace CRT the dark trace would be illuminated from behind by a ring light round the glass neck of the tube. An interesting aside is that, unlike phosphor CRTs, they were more suitable for vertical mounting. It seems that small amounts of phosphor could detach themselves from a vertically mounted screen and drop into the electron gun, something that wasn’t a problem for tenebrescent coatings.

This display tech has shuffled off into the graveyard of obsolescence, we’re guessing because CRT technology became a lot better over the 1950s, and radar technologies moved towards a computerised future in which the persistence of the display wasn’t the only thing keeping the information on the screen. It seems at first sight to be a surprise that tenebrescent coatings have never resurfaced in other displays for their persistence, but perhaps there was always a better alternative whether it was ultra-low-power LCDs or more recently e-ink style devices.

For more bleeding-edge 1950s radar displays, we’ve previously brought you Volscan, a radar with an early form of GUI, which no doubt was one of those which consigned dark-trace CRTs to history.

Keebin’ With Kristina Hack Chat

Join us on Wednesday, September 27 at noon Pacific for the Keebin’ with Kristina Hack Chat with our own Kristina Panos!

When you think about it, wiggling your fingers over a bunch of magic chiclets is a pretty strange gateway to the written word. And yet, here we sit a hundred-odd years after someone first decided that the same basic interface used to run pianos and harpsichords for centuries would be a fantastic model for mechanizing the whole writing thing. Just because it makes perfect sense thanks to the outsized portion of our brains dedicated to the motor and sensory functions of our wonderfully complex and versatile hands doesn’t mean it’s not weird.

join-hack-chatStill and all, it seems like there could be some room for improvement in the basic design of keyboards. We could probably do with something that makes typing easier, results in less repetitive strain, or is just more fun to do. Pushing back on the traditional and boring designs of the past is where we find the strange breed of keyboard builders and modders that our very own Kristina Panos counts herself part of. You know here from her popular “Keebin’ with Kristina” series, and now we’ve coaxed her into checking into the Hack Chat to talk to all the rest of us keyboard-minded individuals. If you’ve ever thought that there has to be a better way to enter text, or even just something a little bit different, you’ll want to come along and join the conversation.

Our Hack Chats are live community events in the Hackaday.io Hack Chat group messaging. This week we’ll be sitting down on Wednesday, September 27 at 12:00 PM Pacific time. If time zones have you tied up, we have a handy time zone converter.