Galaksija demo

27.06.2007 0:49

Here'a a short assembly program (around 180 bytes of code) that demonstrates a small part of Galaksija's considerable graphics abilities :).

Some screenshots (it actually looks quite nice in motion if you're looking from far enough):

Posted by Tomaž | Categories: Code | Comments »

Wikipedia on steam cars

26.06.2007 15:16

I usually recommend using Wikipedia. However today I found an example why you should still be skeptical when reading its articles:

While Gasoline-powered ICE cars have a fuel efficiency of 30%, steam engines are capable of 90% efficiency.

Well, I guess that's why all cars today are powered by steam engines, right?

Here's another gem from the talk page (some people there expressed doubt in the these figures on grounds of laws of thermodynamics):

I won't enter into this arcane "efficiency" debate, a time-honoured red herring that does not begin to explain why steam cars have always given a very good account of themselves when compared with internal combustion as regards fuel consumption, and emissions-wise have generally proved far superior. Surely this begs more searching questions as to why this should be in spite of all this "received theory"

There's also this British steam powered car that requires a 4 MW engine to reach 320 km/h. I think that says enough about efficiency of steam engines.

Posted by Tomaž | Categories: Life | Comments »

Manic Miner

21.06.2007 23:50

Manic Miner was one of the first computer games I played. It was also the first game I tried on my newly repaired Spectrum. Out of curiosity I did some googling around for technical information about this game. It turns out there's plenty floating around the Internet.

I was quite amazed that besides being one of the most popular games on the Spectrum it was also very well designed. The author (Matthew Smith) pushed a lot game's complexity from code into data: there's a pretty simple game engine taking the bottom 12 kB of Spectrum's 48kB RAM. The rest is available for data describing maps, sprites, etc. Within engine's limits you can make your own monster-infested levels simply by manipulating the data structures with no need to modify (or even understand) the engine's machine code. This made it possible for other people to make completely new games (I guess people would call them mods today) using his engine: there are several tens of them listed at World of Spectrum. This was made even simpler by the fact that the original Manic Miner release didn't employ any copy protection schemes or fancy loaders - you could push BREAK after the first part of the game's code loaded and do some simple modifications directly from Spectrum's BASIC, without needing some extra software.

It's also interesting how the engine development progressed over time: With Manic Miner's engine you could load at most 20 levels into Spectrum's memory (in addition to the engine) with each level taking 1024 bytes. It supported conveyor belts, crumbling floors and two types of monsters per level. The next version of the engine (used in the sequel Jet Set Willy) on the other hand supported 60 levels (256 bytes each) and added swinging ropes, stairways, more monsters per level and ability to connect different levels so that the player can freely walk between them instead of just passing from the first to the last level like in Manic Miner.

All this reminds me of for example more recent ID software's games like Doom and Quake. They are also written in much the same way: a compact, simple engine and a larger WAD file, containing data about the levels. Not surprisingly these game engines were also used in a large number of other games.

Here some further technical reading: Jet Set Willy and Manic Miner internals.

Posted by Tomaž | Categories: Code | Comments »

Lolcode

20.06.2007 12:47

If you think C supports some funny syntax, how about this:

HAI
CAN HAS STDIO?
PLZ OPEN FILE "LOLCATS.TXT"?
	AWSUM THX
		VISIBLE FILE
	O NOES
		INVISIBLE "ERROR!"
KTHXBYE

Lolcode is a new Turing-complete language that will probably end up along such legends as Whitespace and Brainfuck. They even have a book cover ready:

LOLCODE, The Comprehensive Guide, on Flickr

Posted by Tomaž | Categories: Code | Comments »

Another ZX Spectrum's near-death experience

19.06.2007 22:23

Approximately one year ago I got two Sinclair ZX Spectrums (48kB versions) from Cyberpipe's computer museum to repair. I was quickly able to put together an undamaged circuit board and a working keyboard into one working machine which was then on display in the museum for some time. After that I was left with enough parts for another Spectrum which I declared unrepairable because it seemed that every imaginable component was burned out.

However after tinkering with it every once in a while when I found some free time I got it back to a perfectly working condition. Looking back it was quite an amazing experience. Here's a list of all things that needed repair in the order I repaired them:

There was a big hole in the 5V regulator. Replacing that was the easy part.

Seriously burned out 7805

The ferrite core of the little transformer on the circuit board was also shattered, probably because of over heating. The wiring also appeared to be damaged. When I couldn't find a similar new core I ended up gluing back together the original core piece by piece with epoxy resin and then making new windings.

Continuing with the obvious stuff, there was also a resistor with a crack along it's body. Perhaps the transformer core shattered because of a mechanical not thermal shock after all?

Since the transformer of the DC-to-DC converter was obviously shorted at one time it was easy to guess that the switching transistor TR4 (ZTX 650) was also burned out. Getting a replacement however wasn't that easy because this NPN transistor has to withstand 2A of pulse current but also has to be in small a TO-92 or TO-18 case in order to comfortably fit on the circuit board and under the keyboard. I tried a bunch of transistors from a basic 2N2222 to a fancy 400V ST13001 I got from an old fluorescent lamp. They all eventually burned out (with ST13001 holding a record at several hours of operation). I only found a satisfactory replacement two weeks ago when I noticed that one of the local electronic component shops had an old stock of ZTX 651 transistors.

2N2222 on its way to destruction

Now it was finally time to fully power up the computer and see how extensive was the damage to the digital part. As expected the first time only four characteristic black and white vertical bars appeared on the screen. I suspected that the low 16 kB of RAM was to blame and it took me a couple of months to find a supply of chips that could be used to replace the original 4116 ICs (4164 ICs by the way and I only got four for quite an outrageous price). After experimenting a bit with RAM chips however I couldn't find specific chips that were bad.

Suspecting the CPU, I took the Spectrum to my Faculty's lab and removed all the big chips from the circuit board and put them into sockets. Replacing the CPU with a known-good chip however didn't help. After having some wacky ideas how to diagnose this problem I got some good advice from Winston on the World of Spectrum forum to suspect the ROM.

After confirming that the ROM chip was certainly acting strangely (I definitely wouldn't suspect it myself, thinking that a mask ROM was the most robust IC in the Spectrum) I've found an old 27C128 EPROM, programmed the original ROM contents in it and modified the circuit to accommodate an EPROM instead of ROM.

Those wires look dangerously close to the coil

Success! Spectrum now boots to the "Copyright by Sinclair" screen, however the keys don't work. As usual the keyboard membrane broke in several places. I first tried to repair it, but soon gave up (there's a funny story here about how the membrane worked properly each time I tested it on the table but was dead when I connected to the machine).

Luckily these guys offer cheap new (manufactured in 2007!) replacement membranes. Now it was just a matter of undoing all my previous keyboard-related modifications.

Keys now work, but there's no familiar clicking sound from the speaker. Interestingly one last component needed replacement - the protection diode on the audio output pin of the ULA chip. This also made me wonder if the damage to this board was made by connecting the power supply with a wrong polarity. This diode would form a direct short circuit in that case and I can't imagine any other fault which would damage it.

The
final result

So, now I have two Spectrums in a working condition. Maybe there's a game that supports multiplayer on two connected machines?

A
bunch of Spectrums

Posted by Tomaž | Categories: Digital | Comments »

z80dasm 1.0.0

18.06.2007 13:55

Here's the first release of z80dasm, my fork of the dz80 disassembler.

Some basic information about it can be found here. More details in the README file and the included man page.

Enjoy.

Posted by Tomaž | Categories: Code | Comments »

Assemble, disassemble, assemble, ...

14.06.2007 23:50

I'm getting tired of hunting Z80 assembler and disassembler bugs each time I want to focus on researching Galaksija's operating system.

Today I wanted to squash all those bugs once and for all, so I turned z80asm (a nice Z80 macro assembler) against its bitter rival z80dasm (my soon-to-be-released fork of dz80 Z80 disassembler).

After a long debugging session of z80dasm, I finally got the desired result (interestingly I found no new bugs in z80asm):

$ stress
Final results of stress testing
===============================

Tested: 2000
Failed: 0
$

(In each iteration this script copies 16kB of data from /dev/urandom, disassembles and assembles it and compares the result with the original)

Posted by Tomaž | Categories: Code | Comments »

IPv6 connectivity in Debian

11.06.2007 11:55

Hruške wrote about how to get IPv6 connectivity in Debian.

A few days ago I found out by accident that there is a simpler way: just install the tspc package (Some web site said to me "you are using IPv6" and I said "Wow. When did I configure that?" then remembered I installed some IPv6-related package a while ago to read its documentation). No configuration necessary and it works from behind a NAT.

It is a different kind of connectivity though (point-to-point tunnel versus 6to4), but it's good enough for just poking around the 128 bit address space and trying out a few pings.

Posted by Tomaž | Categories: Code | Comments »

A bunch of EPROMs

10.06.2007 20:51

Here's a nice picture showing how die sizes of EPROMs were shrinking over time. All chips here can store 64 kB of data (except one in the center which is 32 kB).

Compare the die sizes

Posted by Tomaž | Categories: Digital | Comments »

GPL 3

07.06.2007 20:11

The new version of GNU General Public License is getting close (final draft was released by the FSF one week ago). There is quite a lot of discussion going on, so here are my two cents:

Since I read the first draft I've put all free software I released specifically under the GPL v2 (without that "or any later version" sentence - I hold the copyright so I can change the version later anyway if I change my mind). The reason for this is quite simple: I don't want to use a license if my understanding of it is based only on other people's interpretation. I want to read it and understand it myself.

Now, maybe my reading comprehension of legal documents is below average, but at around 5600 words the GPL v3 draft is too heavy for me. I understand some parts but I don't see the whole picture. On the other hand I have a feeling that I understand 2900 words of GPL v2 and that I know exactly under what set of conditions I allow redistribution of my code.

Posted by Tomaž | Categories: Life | Comments »

PVM over firewalls and the Internet

06.06.2007 23:06

PVM was designed to connect different machines into a cluster over low-latency high-speed LANs. Some applications however do not need good connectivity between cluster nodes in order to work efficiently.

Now imagine you have a four-way Opteron machine at your disposal and the only thing that prevents you from adding it to your virtual machine is the fact that it is 30 km away and the only route to it leads through two firewalls and a block of public Internet.

PVM uses a combination of TCP and UDP connections for communication between nodes so you can't use SSH port forwarding. However there is a way to tunnel any kind of traffic over SSH and make a simple virtual private network using a combination of SSH and PPP daemons (see VPN HOWTO) which will also support PVM traffic.

The complete installation described in the HOW-TO is too complicated for one time use. So here are simple step-by-step instructions:

  1. Make sure you can make an SSH connection from master to opteron with a single command and without entering a password (e.g. by using RSA or DSA authentication). To traverse firewalls you can use SSH port forwarding for this connection (since you only need one standard TCP connection from master to opteron to achieve this - in my case it was SSH-over-SSH-over-SSH)
  2. Download and install pty-redir on master. It's only 100 lines of code, so it's easy to audit if you're worried about security.
  3. Install pppd on both master (the local host that runs the pvm console and controls the cluster) and opteron (the remote host you want to add to the cluster). Pray that both machines have ppp support enabled in kernel.
  4. Put the following into /etc/ppp/options on master:
  5. noauth
    
  6. Put the following into /etc/ppp/options on opteron:
  7. ipcp-accept-local
    ipcp-accept-remote
    proxyarp
    noauth
    
  8. Run ./pty-redir /usr/bin/ssh -C -c blowfish -t -e none -o 'Batchmode yes' -i path-to-your-rsa-key opteron-host-name /usr/sbin/pppd on master.
  9. Run pppd /dev/ttyp0 192.168.X.1:192.168.X.2 on master (replace /dev/ttyp0 with the device name that is printed by the previous command) Choose X so that these two IPs do not conflict with any other networks master and opteron are connected to. 192.168.X.1 becomes master's IP and 192.168.X.2 becomes opteron's IP in this little VPN.
  10. Write a PVM hostfile like this:
  11. 192.168.X.1 sp=1000
    192.168.X.2 sp=10000
    ...and any other local machines in your cluster
    
  12. Start PVM on master: pvm -n192.168.X.1 hostfile
  13. Enjoy :)
Posted by Tomaž | Categories: Code | Comments »

Old transistors

05.06.2007 14:08

Yesterday I found these transistors manufactured in former Yugoslavia while repairing an old EPROM programator:

BC212 equivalent in TO-92 package, from Ei Niš.

2N2907 equivalent in TO-18 package, from Radio industrija Zagreb.

Nothing special actually, except that I didn't know that they were making transistors at all.

Posted by Tomaž | Categories: Analog | Comments »