Tips and Tricks For The C Pre-Processor

The C pre-processor can help you write more concise, easy to follow code. It can also let you create a tangled ball of macros and #defines. [s1axter] wrote up a guide on how to use the pre-processor and keep your sanity.
Tips and Tricks for the C Pre-processor
We’ve seen some neat hacks with the C pre-processor, such as a full adder implementation, but this focuses on more practical usages. First, [s1axter] explains what the pre-processor does with your code by writing simple macros. Next up is arguments, and usage of ‘##’ directive for metaprogramming. Finally, we get a good explanation of why you need to worry about scope when using macros, and how to safe code by using ‘do {} while()’ statements.

If you’re into embedded programming, this guide will help you understand some of the more complex pre-processor techniques out there. It’s helpful for making your code clearer, and abstracting away hardware dependencies in a few lines of code.
read the rest of article...

Trimming The Fat From AVR GCC

[Ralph] has been working on an extraordinarily tiny bootloader for the ATtiny85, and although coding in assembly does have some merits in this regard, writing in C and using AVR Libc is so much more convenient. Through his trials of slimming down pieces of code to the bare minimum, he’s found a few ways to easily trim a few bytes off code compiled with AVR-GCC.
Trimming The Fat From AVR GCC
To test his ideas out, [Ralph] first coded up a short program that reads the ATtiny85′s internal temperature sensor. Dissassembling the code, he found the a jump to a function called __ctors_end: before the jump to main. According to the ATtiny85 datasheet, this call sets the IO registers to their initial values. These initial values are 0, so that’s 16 bytes that can be saved. This function also sets the stack pointer to its initial value, so another 16 bytes can be optimized out.

If you’re not using interrupts on an ATtiny, you can get rid of 30 bytes of code by getting rid of the interrupt vector table. In the end, [Ralph] was able to take a 274 byte program and trim it down to 190 bytes. Compared to the 8k of Flash on the ‘tiny85, it’s a small amount saved, but if you’re banging your head against the limitations of this micro’s storage, this might be a good place to start.

Now if you want to hear some stories about optimizing code you’ve got to check out the Once Upon Atari documentary. They spent months hand optimizing code to make it fit on the cartridges.
read the rest of article...

3-Sweep: Turning 2D Images into 3D Models

As 3D printing continues to grow, people are developing more and more ways to get 3D models. From the hardware based scanners like the Microsoft Kinect to software based like 123D Catch there are a lot of ways to create a 3D model from a series of images. But what if you could make a 3D model out of a single image? Sound crazy? Maybe not. A team of researchers have created 3-Sweep, an interactive technique for turning objects in 2D images into 3D models that can be manipulated.
3-Sweep: Turning 2D images into 3D models
To be clear, the recognition of 3D components within a single image is a bit out of reach for computer algorithms alone. But by combining the cognitive abilities of a person with the computational accuracy of a computer they have been able to create a very simple tool for extracting 3D models. This is done by outlining the shape similar to how one might model in a CAD package — once the outline is complete, the algorithm takes over and creates a model.



The software was debuted at Siggraph Asia 2013 and has caused quite a stir on the internet. Watch the fascinating video that demonstrates the software process after the break!
read the rest of article...

Writing a FUSE Filesystem in Python

Have you ever thought a particular project could be better if you could just control the file access directly? [Stavros Korokithakis] did, specifically for a backup program he was working on. What followed was the realization that writing a FUSE filesystem, particularly in Python, isn’t as complicated as it may seem. Really, through the power of open source, the heavy lifting has already been done for us. If you’d like to try it yourself, you’ll need to install fusepy. From that point, you simply need to define the filesystem methods you will be using.
Writing a FUSE Filesystem in Python
Python isn’t going to win any speed contests in the filesystem space, but that isn’t really the point. Using this technology opens up a huge opportunity for new ways of accessing data. If you let your mind wander, you can conceive of encrypted filesystems, seamless remote data access, new key-value storage designs, etc. Perhaps even more interesting is the idea of using Python to communicate with a physical device… maybe a proc filesystem to keep track of your robot telemetry? We’d love to hear your ideas in the comments.

We had success using [Stavros'] example script on Linux and OSX. (Fair warning if you’re on a Mac, the pip version of fusepy seems to be linked against fuse4x rather than OSXFUSE, but once you’ve got the prerequisites installed, you’re golden.) We didn’t have a Windows machine to test. Can anyone confirm if the same is possible there?
read the rest of article...

Pokemon Blue Becomes An IDE

With WiFi, Wonder Trade, and new Pokemon that are freakin’ keys, you’d think the latest generation of everyone’s reason to own a Nintendo portable is where all the action is, right? Apparently not, because Pokemon Blue just became a development tool for the Game Boy.
Despite all notions of sanity, this isn’t the first time we’ve seen someone program a Game Boy from inside a first generation Pokemon game. Around this time last year, [bortreb] posted a tool assisted run that deposited and threw away in-game items to write to the Game Boy’s RAM. Using this method, [bortreb] was able to craft a chiptune version of the My Little Pony theme inside Pokemon Yellow.

A year later, [TheZZAZZGlitch] has gone above and beyond what [bortreb] did. Instead of a tool assisted run, [ZZAZZ]‘s hack can be done manually on a real Game Boy. This trick works by using an underflow glitch to obtain item ’8F’ in the player’s inventory. Here’s a great tutorial for doing that. With this 8F item, a few items can be tossed and a ‘programming’ mode is activated where code can be written to RAM by walking to an X Y position on the map, using the 8F item, and writing a program byte by byte.

The maximum amount of code that can be written to the Game Boy RAM is 254 bytes, just large enough for [TheZZAZZGlitch] to write a very, very simple version of Akranoid, Breakout, or one-player Pong. Not much, but very, very impressive.

Video of [ZZAZZ] ‘jailbreaking’ his copy of Pokemon Blue available below.

read the rest of article...