Monday, 6 December 2010


This is just a short - scruffy post about Televisors. A friend of mine pointed me to the MUTR website which is selling minature Televisors and it set me thinking about variations on the theme. But first some information on the Televisor frame format.

Frame Format

There are variations on the Televisor format, but here's a summary of the MUTR one.

Frame rate is 12.5Hz.
There's 32 vertical scans so each scan is 400Hz.
The original doc specifying the minature Televisor specc'd the pixels frequency at 80 pixels per scan, so each pixel is at 25.6KHz.
Voltages are similar to composite TV: 1V peak-to-peak is normal. Sync is at 0V, black is at 0.3V, white is at 1.0V.
Frame sync is the entire 32nd scan - so the 32nd hole on the disc is used to check frame sync.
Line sync (here vertical sync) uses the bottom 7.5% of each scan, the bottom 6 pixels. So, there are 74 video pixels available.

That about sums it up, now for the ideas:


It should be possible, just using nearly the lowest MCU available ( e.g a PIC 12F509) running at 4MHz to implement pong, producing televisor video output. Here the PIC generates up to 78 pixels per scan; that's 32 clocks/pixel with 5.8 sync pixels. I worked out a basic output routine:

btfcc TMR0,0 ;(btfcs for odd pixels).
goto .-1
movf gGpio,w
btfsc 0x10+(pix/8),7-(pix&7)
addlw 1 ;bit 0=video signal.
movwf GPIO

Which takes 6+3n where n is the number of wait loops, so we have up to 26 c for computation; about 1872 overall. There's up to 10% jitter on pixel output. There's also 196 cycles available during sync.

Digital Televisor

Similarly a more highly-specced MCU, e.g. an AtTiny25 should be able to sample incoming Televisor video and control a real Televisor disc and output video onto it. This would greatly reduce the part count and the MCU would also be able to do automatic line and frame sync.

Televisor Simulation

You don't need a 75MHz Pentium to simulate a Televisor - a ZX Spectrum with an analog in would (just) be able to keep up with converting Televisor input onto its screen, my draft routine uses 75% of CPU converting samples into dithered bitmaps, here's the core of it:

in a,(sampler) ;10c?

out (sampleTrig),a ;start next sample (data is irrelevant). 21

add a

ld e,a

ld a,(de) ;first conversion sample.

inc e

ld (hl),a

inc h

ld a,(de) ;second conv sample.

ld (hl),a

inc h

I've been trying to think about how a VIC-20 could keep pace; running it in 16 chars x 20 lines with 4x2 VIC-20 pixels per real pixel, but my best basic routine so far would take 38cycles, about 20% too slow.

Monday, 20 September 2010

NSXMLParserDelegate fix for different iPhone iOS versions

This is a short blog providing a better fix than I've yet seen for supporting consistent NSXMLParserDelegate code across different versions of iOS.

The problem occurs because the NSXMLParser class was changed between iOS 3.0 and 4.0. Originally it informally declared some delegate methods and this was turned into a formal delegate protocol: NSXMLParserDelegate.

This means that you'd need to fake the delegate class with:

@protocol NSXMLParserDelegate

if you're compiling for a iOS 3.0 target, but this will generate a duplicate @protocol declaration warning if you then compile for after 4.x. So, really you want the protocol declaration only for versions of iOS below 4.0.

The easiest way to do this is simply to wrap the protocol declaration with:

#ifndef __iphone_4_0
@protocol nsxmlparserdelegate

That's how you test for the current SDK version - in any particular sdk there's a #define for each version up until the current version, so version 4.1 has __IPHONE_

-cheers from julz

Friday, 27 August 2010

British Christian Doctors aren't killing enough patients

In one of the strangest BBC articles I've seen in ages, the BMA has complained that Christians are more likely to prolong the life of their patients by suggesting pallative care - and that's a BAD thing, because everyone should be a functional Atheist at work.

In this weird and rambling article, the BBC claims (conflictingly) both that Christian doctors should leave their principles at the surgery door, and work in a purely dispassionate, objective way and also that they should have their patients interests at heart.

I thought doctors were supposed to be following the hypocratic oath, which is primarily concerned with doing good and at the least, not harming the patient.

This does rather all smack of secular propaganda, for example, it's an article attacking religious people, but no viewpoints of Christians are offered, so there's no balance. It does however put forward 'Dying with dignity' agenda across, a pro-euthanasia organisation. It also uses the way in which the secular industry's pro-death media campaign has shifted public opinion over the decades (by publicizing a number of cases of people who want to die) to then put the pressure on Christian doctors.

The reality is that one's beliefs (or lack of them) actually do influence a person's professional conduct, because they influence one's ideas and goals. This is true for religious people and secular people. There's no neutral setting and defining oneself as being neutral doesn't change that.

Sunday, 15 August 2010

Climate Change Weather Index

One of the biggest issues with assessing climate change is how we link climate with weather. We know that climate change ought to produce a corresponding change in weather patterns, but we can't demonstrate that individual weather events are a product of climate change and in the minds of most people weather is what we see (natch), not climate.

Global Heat anomoly So, although the Russian president attributed the recent heatwave to climate change, even New Scientist are far more cautious in doing so.

I think the way to resolve this is not to look for demonstrations of extreme events, but to relate all weather events to climate change. This is how:

Essentially, if climate change is being driven by global warming then what we're saying is that there's more energy present in the earth's system, because heat is a measure of energy and temperature is: ÂșC = J/(Kg * SpecificHeatCapacityOfAtmosphere).

Extreme weather events are powered by the extra energy in the system. So in a sense all we have to do to relate weather events to climate change is calculate (even roughly) the energy in any particular weather event and add it all up. We can then provide a total and a probability that this total thus far lies within the natural variance. We make these two figures part of normal weather forecasts.

This technique will work well for relatively local weather as well as global weather and as weather events add up to a convincing argument for climate change people will want to see the Climate Change Weather Index falling - they'll want to do what it takes to reduce flooding, heatstrokes, air-conditioning and blizzards.

Friday, 4 June 2010

Death Throes In The Arctic

Be prepared to be shocked, the Arctic is seriously likely to reach a record-breaking low extent this summer. I thought I'd write a short blog on why; and why I think the arctic is in its death throws.

This year's Arctic record low will be easy to understand. We're predicted to have a record-breaking ground and sea temperature; we've had record breaking increases in CO2 (3ppm in a year, during a recession I might add); the ice volume anomaly has already broken records by about 100% (compared with 2007). The ice-extent itself declined from a near 1979-2000 average in early April to below the record low for this time of the year (which occured in 2006) so if it tracks at the same rate it'll take until July at the earliest before 2007 catches up. However, it will almost certainly accelerate.

So far so bad, but actually it's much worse. Climate Scientists have been predicting imminent new record lows since 2007, because the 2008 and onwards Winter ice has been thin and therefore prone to melting - so the ice extent over the past few years has been deceptive. In fact summer 2008 and 2009 were almost as bad as 2007 and it should have been newsworthy even though it wasn't terribly surprising.

The real killer though isn't the thin ice, but that so much of the Arctic ice is no longer solid, but broken regions of ice held together by refreezing - rotten ice. There are numerous first hand reports confirming this; that is, detailed satellite picture analysis and fly overs. I think we should now consider the Arctic to really be basically a mass of loosely connected ice-floes primed to float south at the slightest provocation. This 'ice-mass' is moving quickly as some Arctic explorers recently found out.

That's the problem - the Arctic ice no longer even needs to melt as such, it can just drift into oblivion.

Tuesday, 4 May 2010

Someone beat us to it!

Did anyone ever tell you what happened to the great ancient library of Alexandria? It was like a major wonder of the world and held so many classic texts that its destruction precipitated the half-millenium long Dark Ages. I've spent roughly 22 years under the unhappy impression a mob of brutal, ignorant Christians burnt it to the ground for the crime of being heretical. It turns out someone beat us to it.

By centuries.

You can read the entire story here. The point of this blog isn't really to shift the blame though, but my story of this story - how I kept coming across this myth and how different & more complex a more accurate history is.

This is how it goes. In my middle childhood to mid-teens I embraced Atheism, consciously understanding what it was about and genuinely valuing how science and reason had helped humanity progress beyond religion (as I understood it then). Part of this meant I was really into popular science literature and this is where I came across the story via the otherwise brilliant book Connections by James Burke. I've summarised it above, but the basic idea is that the late 4th century Christians, being opposed to reason and knowledge burnt it down in a riotous act of wanton vandalism, because esp, the Librarian was female.

At the time that made sense to me and I guess I internalised its point, but by the time I was doing my PGCE in 1990/1991 I'd become a Christian and forgotten it all; so I was quite shaken when a rather angry Atheist on my course launched into a tirade on the concrete walkways of UEA, using this an a prime example of why he really couldn't stand Christianity and Christians.

OK I thought, well Christians are perfectly capable of messing up badly. So the (indirect) shame stuck with me for about 10 years until I found myself on the Anvil Workshop course in 2001. Here I got a slightly different version of the story where the riot was caused because the female Librarian had moved the Library to a pagan temple (which the Christians wouldn't visit).

And that's still pretty bad and yet on this course I learned a few things that didn't quite add up. Firstly, many of the early Christian leaders had had their theological training at Alexandria and so were well versed in Classic literature. Secondly, the Septuagint (an ancient Greek translation of the Old Testament often quoted from by the writers of the New Testament) was translated at Alexandria too
. It doesn't make quite so much sense for these types of people to want to burn it all down.

I should have started questioning the story a few years later when I found out that the Christianisation of Ireland beginning with St. Patrick (a real person, who never drank Guiness ;-) ) resulted in generations of Irish Christians who made the acquisition, preservation (and reading) of ancient literature a high priority. These amazing people were responsible for maintaining the majority of all such texts Europe had access to until the influx of books from the middle east after the Crusades.

I kinda just assumed they'd got them from elsewhere. It turns out that the history is both simpler and more subtly complex. To put it simply: Christians didn't burn the Library, it's a myth. More subtly, they couldn't have, because Alexandria had multiple libraries.

It's actually a conflation of stories. Alexandria had been burned down in ancient times, but not by Christians - Julius Caesar had accidentally done it in 48BC during an attack on the port. What the Christians did burn in AD391 were the Pagan temples by decree of Emperor Theodosius and although one of the temples had been used as part of a library there's no record of whether there were any books left in it by then.

So, our predecessors appear to be innocent on this particular count - jolly good :-) ! So what happened to all its books during the Dark Ages? Come to think of it, what happened to the Dark Ages? - I've heard contemporary historians figure that's a myth too ;-)

Wednesday, 17 February 2010

Typewriter Hacking

There's been some recent interest in typewriter hacking. Some guys figured out how to hack a Brother SX-4000 electronic typewriter so that you can turn it into a printer. They do it by simulating key presses on the keyboard matrix using a microcontroller.

I think I can go one better with the Smith Corona SL470. The SL470 was an early 90s electronic typewriter with some facilities for tabs, word wrap and word correction. It's based on a daisywheel printhead which made me think that it might be possible to turn it into a simple printer. SL470s can often be found on ebay.

But why? Well, the major reason is because of my interest in retro-hardware. Libby8 for example will be a computer with only 26Kb of usable RAM so hooking up a printer (if I ever did) would mean hooking up a simple printer, because I wouldn't be able to fit in a driver for a modern USB printer.

I opened up the typewriter. The hardware is amazingly simple and the circuit is fairly minimal. Basically it's all controlled via an Intel 80C52 Microcontroller (the big chip on the left) and a few buffers. The cables at the top control the various LEDs; carriage and daisywheel print mechanism.

The keyboard ribbon is on the right and I spent a bit of time trying to map it. It looks like it'll be a normal matrix keyboard, but it's not. After 30+ mins of work I only managed to figure out the left-hand side. The other side (which certainly works) isn't so straight-forward it seems.

The 80C5x series were very popular MCUs from the 1980s and 1990s. Like many MCUs they have terribly awkward architectures, but hey - you can get them to do some work. This one has 8Kb of ROM and an internal 256b of RAM - which is why its word-processing features weren't that great (no RAM to store more than one line of text in).

I had a hunch that if I'd built the typewriter I'd use the same circuit for both a simple typewriter and a typewriter/printer. In fact when you open the case it looks like there's a gap on the left for a suitable expansion circuit. The 80C52 has a built-in serial port, so when I downloaded the 80C52 manual I took a look at its serial pins; which are pins 10 (RXD) and 11 (TXD). I found out that these lines had special tracks on the PCB that lead to pins marked H5 and H6 which aren't connected to anything.

It looks to me like my hunch might be correct to some degree. The SL470's serial port might be used for something... :-)