programming

Code miscellanea

Some random pieces of code that may be of use.

Binary definitions: there is no standard format for binary numbers in C, yet they are very commonly used in embedded programming. This file simply defines preprocessor constants of the form b0101, b11110000, etc. Includes 2, 3, 4, and 8 bit constants, and an additional 8 bit set intended for small bitmaps, used in the bitmap font below.
http://files.arklyffe.com/bindefs.h

8x8 bitmap character font: used to display text on graphical LCDs or POV displays. Requires bindefs.h above.
http://files.arklyffe.com/charfont.h

Controllerless Graphical LCDs, part 2

It is useful! As expected, RAM and CPU consumption are major issues. Saving RAM by computing the data to send to the LCD line by line proved to only be possible for text and extremely simple graphics, even with overclocking. The timing requirements are far looser than those involved in generating video signals, but the refresh rate needed to avoid flicker is actually quite high, the LCDs are intended to be driven at 60 Hz. This leaves 260 microseconds to compute each line.

Driving controller-less graphical LCD

Digging around through some old parts recently, I came across an old Epson graphical LCD display that had on-board drivers, but no controller. The LCD is an Epson EG2401, reflective, no backlight, 256x64 pixels. It has drivers...one SED1190 driving the rows and four SED1180s driving the columns...but no on-board controller. The LCD is supposed to be hooked up to a SED1330 controller and SRAM, but since I didn't have such a thing, this LCD sat around in a junk box for years.

Xorshift pseudorandom number generator

In 2003, George Marsaglia published a pseudorandom number generator based on repeated shift and XOR operations, a relative of the linear feedback shift register generators. The basic 3-shift PRNG is:

int xorshift() {
    y ^= (y << a);
    y ^= (y >> b);
    return y ^= (y << c);
}

Xcode for Ruby, pt 2

A second issue with using Xcode for editing Ruby is that it by default does not correctly comment code in Ruby files. This again is easy to fix:
Open the scripts menu, choose Edit User Scripts.
Select Comments: Un/Comment Selection
This will bring up a Perl script that Xcode uses to perform the comment/uncomment function. We need to modify this to recognize Ruby file types:

Replace:

# determine the type of file we have by looking for the #! line at the top
# careful--it might already be commented out!
my $commentString;

Xcode for Ruby

Xcode 3's language support for Ruby is somewhat broken. Fortunately, fixing it only requires a few small modifications.

One major problem, Xcode doesn't know what .erb and .rake files are.
There should be a file:
/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Versions/Current/Resources/Standard file types.pbfilespec

Copy this to /Library/Application Support/Developer/Shared/Xcode/Specifications/, creating that directory if it doesn't exist. Editing the original works, but your changes will be overwritten if you update Xcode, better to just override the standard files.

Xcode language/syntax definition files for POV-Ray

Xcode 3 allows you to specify the syntax of a language with .xclangspec files, which contain information on the structure of the language that is used not only for syntax coloring, but also for populating the symbols menu, showing the currently selected block with the "Focus Follows Selection" feature, selecting the appropriate amount of text on a double-click, etc.

The POV-Ray syntax specification file is a little crude, work still to be done with it, but already a considerable improvement over the other options on the Mac for editing POV-Ray files.

Syndicate content