torsdag 15 december 2011

Space invaders High Score list hack - Update

There's a new version of the high score list hack that has been tested on real hardware

Go there

måndag 3 oktober 2011

Mamepanel with Linux

The Mamepanel is great when building an usb arcade controller. It's a customizable (at build time) joystick/keyboard/volume control in one AVR uC. One drawback is that my two joystick setup wasn't recognized as two 8 button joysticks but rather as one joystick with 18 buttons. This is a known problem with using AVRUSB with a Linux-machine.
The only solution i found to the problem was to recompile the Linux usbhid module and mark the Mamepanel as quirky.
This is how I did it on Debian Lenny:
as root:
Get the source
aptitude update
aptitude install linux-source
tar jxvf /usr/src/linux-source-2.6.26.tar.bz2 linux-source-2.6.26/drivers/hid
cd linux-source-2.6.26/drivers/hid
Add these lines where they fit in /usr/src/linux-source-2.6.26/drivers/hid/usbhid/hid-quirks.c. The USB_DEVICE_ID_WIKIDOT_MAMEPANEL32 device id should probably be changed to something else if an ATMEGA8 is used (can be checked with lsusb).
#define USB_VENDOR_ID_VOTI           0x16c0
#define USB_DEVICE_ID_VOTI_MAMEPANEL32       0x05df
{ USB_VENDOR_ID_VOTI, USB_DEVICE_ID_VOTI_MAMEPANEL32, HID_QUIRK_MULTI_INPUT },
Build and load the new module (It's probably a good idea to check that usbhid.ko exists before rmmodding the old one)
make -C /usr/src/linux-headers-$(uname -r) M=$(pwd) modules
cd usbhid/
rmmod usbhid && insmod usbhid.ko
hope for the best.

onsdag 7 september 2011

Space Invaders high score list hack

(edit) Added a new version to the bottom of the post (/edit)

The space invaders high score hack adds a high score list to Space Invaders, the arcade version, when inserted in the original game code.
Two high score list screens are added. One before a demo game begins and one after a player is game over. If the players score is high enough when game over occurs an enter initials screen is shown.

The hack has been developed using a game version using four 2Kbyte roms. 

The time and effort put into this was greatly reduced by using the thorough disassembly comments by Chris Cantrell at http://computerarcheology.com

Screens
Game over screen

High scores shown before demo screen

Enter initials screen


Download
spacehigh000.zip source and patch in hex format. Does NOT contain any roms.
I have only tried this in MAME so there are NO guarantees that it will work on the real hardware.
spacehigh001.zip source and patch in hex format. Does NOT contain any roms.
This version has been successfully tested on real Midway L-shaped hardware strapped for 9316 EPROMs. The f chip was replaced with a ST M2732A.

söndag 9 januari 2011

MobileLCD

Description
MobileLCD is a J2ME (MIDP2.0) implementation of just enough of the commands in the Goldelox MD1 graphical display module command set to make the GOLDELOX driver in serdisplib work. It can be seen as an J2ME serial LCD Emulator.
The application uses the StreamConnection class and has been tested using, but should not be limited to:
  • Serial port
  • Serial port over Bluetooth

Specs
  • Resolutions: 320, 220, 176, 160, 128, 96, 64
  • Implemented commands: 0x42, 0x45, 0x49, 0x55, 0x56, (0x59 returns ACK but doesn't do much)
  • Goldelox MD1 mode
  • Experimental PICASO SGC rev 5 mode
  • No backlight or screensaver control

Usage
Specify serial port
At startup LCDEmu enumerates the serial ports available on the device (not including Bluetooth ports).
  • To open one of the enumerated serial ports use comm:. Example: comm:USB2
  • To make a serial port connection over Bluetooth use btspp://<remote device address> <channel> Example: btspp://001122334455:1
Set resolution
The resolution can be selected using a list of valid values.
Run
When the set up is done press Run.

Using with Linux
USB cable
When connecting a phone to my Debian box using an USB cable three serial ports show up under /dev/ and it's only a matter of pointing serdisplib to the right one
The display can be tested with serdisplibs testserdisp command (make sure you have the correct permissions to use the port:
testserdisp -n GOLDELOX -p "RS232:/dev/ttyACM2" -d 2

Bluetooth
To connect a phone to my Debian box using Bluetooth I use rfcomm (in bluez-utils package?):
# You probably have to pair your phone with the computer before trying this.
# Add a Serial Port Profile to our computer
sdptool add SP
# Wait for phone to connect to channel 1, create /dev/rfcomm2
rfcomm listen 2 1
# Test display
testserdisp -n GOLDELOX -p "RS232:/dev/rfcomm2" -d 2


Lcd4linux talking to MobileLCD running on a Nokia 2760 over Bluetooth:
Lcd4linux talking to MobileLCD running on a SE P990 over USB:

Download

MobileLCD_0.02.jad 

MobileLCD_0.02.jar

söndag 26 december 2010

Open source LPC17xx development

This summer I wanted to try something new in the microcontroller area and decided to advance from 8-bit AVR and PIC to 32-bit ARM. There is a jungle of ARM-based microcontrollers out there and deciding on which one is "the best" isn't very easy. I ended up choosing an NXP LPC17xx Cortex-M3 based micro controller since the price was fairly good and I found MicropendousX, an open hardware dev-board project with free open source schematics and pcb-layout in KiCad (free open source EDA-tool) format.
I used the 1758 version (Seems abandoned in favour for the 1768) but removed ethernet and redrew the layout using more hole-mounted components to make it easier to mount, probe and re-wire.

I will add the schematic and board files someday, hopefully soon...

The result:
Features:
A simple "Wiggler" parallel port programmer and OpenOCD works fine to program and debug the micro controller. I think I used the programmer described here but with a connector that fits my board.

The GNU toolchain I use is the arm-none-eabi lite edition of G++ from Codesourcery.

As an IDE I use Eclipse. Stepping through C and assembler code works like a charm. I think I used these instructions to get it working.

lördag 25 december 2010

Calling Cortex-M3 assembler function in RAM from gcc C

I needed a fast  function written in assembler and run from RAM. I thought the most simple way to do this without adding stuff to the linker script was to change the .text directive to .data (same as initialised variables). But the result of the change was a hard fault when the function got called.
The solution was to tell gcc it is a function with .type logic_sample_fast, %function
So the whole function looks like this:
.syntax unified
.cpu cortex-m3
.thumb
.data
.align 4

#define FIO0PIN                    (0x2009c014)
#define FIO1PIN                    (0x2009c034)
#define LOGIC_IN_FIOPIN_REG        FIO1PIN

.global logic_sample_fast
.type logic_sample_fast, %function
.thumb_func
logic_sample_fast:
    movw r1, :lower16:LOGIC_IN_FIOPIN_REG
    movt r1, :upper16:LOGIC_IN_FIOPIN_REG
    cpsid i
trig0:
    ldrb r2, [r1]
    ands r3, r2, #1
    bne trig0
trig1:
    ldrb r2, [r1]
    ands r3, r2, #1
    beq trig1
    .rept (40*8)
    ldrb r2, [r1]
    strb r2, [r0], #1
    .endr
    cpsie i
    bx lr
And the definition in C like this:
void logic_sample_fast(uint8_t *buffer);

fredag 30 juli 2010

ZRip - extract the Z code text adventure part of a zblorb file

The Z machine is a virtual machine used by Infocom in the 80's-90's so that they more easily could port their different text adventure games to the many different platforms of the time. The Z machine has its own instruction set called Z code. Some versions of the Z machine support images and sound.
IF-Archive contains many Z-code games playable on a Z machine.
The blorb-format is a format developed to collect the Z code, images and sound that were previously in separate files into one single file. (Btw, blorbs can contain code for other interpreters as well, not just Z code)
This is were ZRip comes in.
Blorbs can contain high resolution sound and images and become quite big and not suitable for machines with limited memory capacity. ZRip reads a blorb-file and tries to extract just the Z code.

Here's the source

onsdag 9 juni 2010

OpenOCD Ubuntu 8.10

sudo aptitude install libftdi1
sudo aptitude install libftdi-dev
./configure --enable-parport --with-ftd2xx-lib --enable-usbprog
make
sudo make install

onsdag 6 januari 2010

Computer controlled wall outlets

Got hold of three radio controlled wall outlets on sale. Modified the remote to be able to control the outlets with a pc parallel port (or some other port compatible with a 74xxx05)




The remote contains a sc2262 and is powered by a 12V battery.

After a look under the hood of the remote the conclusion was made that a press of a button connect two pins to ground, totally 5 pins are used giving six buttons (see schematic).
To control this from a computer a 74LS05 (hex inverter with open collector outputs) was used (any 7405 should do but if it's going to be powered by the parallel port it won't hurt using a low power one), connecting the open collector outputs directly to the control chip. The 7405 is powered using bit 5,6 and 7 of the data port, this is enough using the parallel port on my motherboard.


Schematic:




inside (the white wire is the antenna)



To control the parallel port this small (linux) program is used, ppdev module has to be loaded.


Remote.c
//Control of remote to remote controlled wall outlets using the parallel port
//Written for linux
//Written by Mikael Ågren 2009
//
//gcc remote.c -o remote

#include <stdlib.h>
#include <stdio.h>
#include <sys/io.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/ppdev.h>
#include <fcntl.h>

int fd;

//map bits of pp data port
#define PWR    (1<<7)|(1<<6)|(1<<5)    //used to power buffer
#define ROD    1<<0
#define LILA    1<<1
#define GUL    1<<2
#define VIT    1<<3
#define SVART    1<<4

#define ON    ROD
#define OFF    LILA
#define ONE    GUL
#define TWO    VIT
#define THREE    SVART

unsigned char setParPortData(unsigned char data) {
    ioctl(fd, PPDATADIR, 0);
    if(ioctl(fd, PPWDATA, &data)) {
        printf("error writing to port");
        exit(2);
    }
}

delay_enough() {
    char i;
    for(i=0; i<5; i++) {
        delay_1s();
    }
}

delay_1s() {
    time_t t;
    time_t old_t;

    old_t = time(NULL);
    while ((t=time(NULL)) < old_t+1) {
    }
}

void printHelp(char **argv, int exitcode) {
    printf("usage: %s reciever on|off\nreciever = 1, 2 or 3\n", argv[0]);
    exit(exitcode);
}

int main(int argc, char **argv)
{
    if(argc!=3) {
        printHelp(argv, 1);
    }

    printf("Försöker öppna /dev/parport0\n");
    fd = open("/dev/parport0", O_RDONLY);
    if(ioctl(fd, PPCLAIM)) {
        perror ("PPCLAIM");
        close(fd);
        return 1;
    }
    printf("/dev/parport0 öppnad\n");

    unsigned char out=0;
    //which reciever
    if(!strcmp(argv[1], "1"))
        out |= ONE;
    else if(!strcmp(argv[1], "2"))
        out |= TWO;
    else if(!strcmp(argv[1], "3"))
        out |= THREE;
    else
        printHelp(argv, 1);
    //which state
    if(!strcmp(argv[2], "on"))
        out |= ON;
    else if(!strcmp(argv[2], "off"))
        out |= OFF;
    else
        printHelp(argv, 1);
    //keep buffer powered
    out |= PWR;

    printf("%x\n", PWR);    
    setParPortData(PWR);
    delay_enough();    
    printf("%x\n", out);    
    setParPortData(out);
    delay_enough();    
    printf("%x\n", 0);    
    setParPortData(0);

    close(fd);
    return 0;
}

Coffee...
Wrote some simple scripts so i can wake up to the smell and sound of fresh coffee in the morning

kaffeON
remote 3 on

kaffeOFF
remote 3 off

kaffe
if [ "$1" = "" ];
then
        echo "usage:    $0 now"
        echo "  $0 HH:MM"
        exit -1
fi

timeoff=$(date -d "$1 30 min" +%H:%M)
$(echo kaffeOFF | at $timeoff)

if [ "$1" = "now" ];
then
        void=$(kaffeON)
        echo $void
else
        timeon="$1"
        $(echo kaffeON | at $timeon)
fi

söndag 20 september 2009

DIY nop binary wristwatch

For some time i've wanted a binary wrist watch and a couple of days ago when I felt for doing a small project that could be realised fairly quickly i finally came to it.

Here's a list of some basic hardware "features" i strived for:
  • Fit inside a wrist watch
  • Use as few parts as possible
  • Surface mount components where possible
  • Only minute and hour representation is necessary
  • Driven by button cells for "long time" ie months without replacing
  • Leds to represent time
  • 24 hour format
  • As single sided pcb layout as possible since hand connecting vias is a drag

Now, why reinvent the wheel so I fired up my favourite search engine but I couldn't find anything to satisfy my needs. Most of the binary watches were based on the megax8 (which in my taste is way too big and has too many features for a project like this). Finally I chose a between a tiny24 and a tiny25 and the went with the tiny24, mainly because I would have to use all the pins of the tiny25 and therefore making programming of the device problematic. An advantage of using the tiny24 is that it's 16-bit counter's got power consumption characteristics in par with both the tiny25's and the megax8 8-bit counters. This results in that we don't have to wake the CPU as often and thus save power. The datasheets are very scarse on details regarding current consumption when a 32.768kHz crystal is used so this is just an assumption made by looking at frequency=0.1MHz in the Idle Supply Current vs. Low Frequency (0.1-1.0MHz) table. Current consumption values of the timers are found in table Additional Current Consumption (percentage) in Active and Idle mode.


The circuit 

The MCU is a Tiny24 (14 pin).
The leds are charlieplexed.
Q1 is a 32,768kHz crystal
The pushbutton is connected to INT0.

The software
To conserve power the microcontroller is put to sleep as soon as it doesn't do anything useful (TIMER1 has to be active so we use "idle mode").
The timekeeping part of the software is based on using TIMER1 to trigger an interrupt every minute which wakes the CPU and updates the time.
When the button is pressed an INT0 interrupt wakes the CPU and the time is displayed.
binwatch.c
binwatch.h
display2.S
Makefile

The PCB
It's a double sided pcb with microcontroller and leds on the top layer and battery and crystal on the bottom layer.
The battery holder is a low profile battery holder for cr2032 batteries.
The button is smd and placed on the right side of the following pictures.
The PCB is 3 cm in diameter.

 top
 

 bottom






The watch
The donor watch was an old broken lcd watch. I removed the button used to set time and replaced it with a small screw with conical head and it all fit quite nicely.
The leds looks much stronger "irl".




Thoughts
Time representation could be changed from 00:00-23:59 to 00:01-24:00, to avoid wondering about whether watch is broken or just displaying 00:00