Last night was a sort of a continuation of
a dream.
I was with Mum and Dad and waiting to go somewhere and we saw the
entrance to an old train station. Mum wanted to go in there, so we
walked over the road through the archway to the station. It was disused,
as it had been before, but there were people around living in the
building next door - not where I had been. In this version of the dream,
the group hadn't just been held there, but the place had been set on
fire and they had - presumably - burned. I'd got away in that version.
The fake foam wall had been bricked up, and a proper door placed beside
it. I went inside and began looking through things. Although the place
looked scorched there wasn't an damage to the boxes of papers. I found
some of the papers I was looking for previously (seemingly in this
revisionist version, I was looking for something too). There were no
bodies, no charred remains of people, and no sign of Jane at all. I left
and looked at some of the writing on the wall - people had carved or
penned poems in to the wall outside the building. Taking the papers, we
left.
That was about it; it was quite sad and lonely really.
A couple of weeks back (ish - it seems like an eternity, but then things
have gone really slowly recently) someone pointed me at a RISC OS
'Invaders' application. The author has very nicely left the source up in
text format which is great when you don't actually have a RISC OS
machine to see the BASIC in. As I do reviews every day at work, I
thought I might have a look at it and see whether there was anything
useful I could say. What I found has bemused me since then in ways I
haven't seen in a long time...
I wasn't looking at it in much detail, but memory allocators are always
good to look at and give a good indication of what's going on. If you
spin to the end of the
code there's a section of functions prefixed with 'ash' which
comprise the memory allocator.
FNash_alloc allocates code from the heap (and we'll ignore the fact that the
return from this routine as failing is not handled by most of the code - my
own BASIC is far worse in this respect). To do this is uses the OS_Heap
routines - well I'm assuming it's OS_Heap; you can't really tell. It
actually calls FNswi_get(13). There's a magic number that should have been a
constant really. But we'll overlook this because it gets crazier the deeper
we go...
I had assumed that FNswi_get was a SWI number lookup. But I follow it, and
find that this is just a wrappers for FNcore_get looking up to a special
array that has a magic '108' value. This in itself searches, *linearly*
through an array to find the number associated with the value that was being
searched for (13 in this case). It turns out that the 108 value is the
message number of the error to use on failure. On finding the value in the
table (this is effectively a hash-lookup implemented as an linear search of
an array), we have a string.
Not just any string, oh no. It's encrypted. Using an Exclusive OR of every
character with 131.
This string then, is the the SWI name to call. So the OS_Heap is finally
called. If we look, momentarily, at the initialisation of this hash lookup,
we find that it's held in a file, which is loaded by PROCstring_load. This
file contains a magic key to ensure that it's not written badly, followed by
the number-string tuples.
Basic file I/O writes out strings in a PASCAL-ish format - type, length,
string-bytes-in-reverse-order.
So what we have here is compete insanity.
We have a magic value being used to look up a hash key by a linear search of
an array, to find an encoded string which was originally stored backwards on
disc. All in order to find the system call name. Which BASIC will then go
and lookup through the OS to get a number to call.
Wouldn't it have been easier to have defined 'SWI_OS_Heap = &1D' and
used that variable in the code in the first place ?
I had a little bit of a discussion with the author about this, and
apparently it's ok to do things this way, because it's just example
code. And as we know, inefficient, perverse, encrypted strings are just
what you want in your examples because you want people to do that kind
of thing. Oh yes.
Julian's also been helping me understand some things about how to read
accounts and things to look for. He's obviously far better placed to do
this
. So, I'm still not understanding a lot of stuff, but I have
a better idea about other things.
Tonight was also going to be the penultimate stage in diagnosing the
external drive box resetting problems I've been having recently. But I
got distracted by Caroline calling, so I didn't get around to that. I'll
probably do it tomorrow after tea.
Still not sleeping all that well. Waking up a lot, and the occassions
that I dream are now far less common. Plus I've also got less nails,
from not eating enough and being stressed over stuff.
Disclaimer: By submitting comments through this form you are implicitly agreeing to allow its reproduction in the diary. I say this not because I'm going to ruthlessly attack comments in the diary, but just so that nobody can say "Well, I didn't say you could quote me on that".