Dialog Quake
Volume Number: 6
Issue Number: 4
Column Tag: Assembly Lab
Dialog Quake For April Fools 
By Mike Scanlin, Mountain View, CA
It started off much like any other day. By 11 AM it was obvious that today would
be little different. Our accountant, who is annoying to begin with, was being e specially
antagonistic today. There I was peacefully coding away when all of a sudden about 210
little 3-hole punch droppings come floating down to land on my computer, on my desk,
in my open drawers, etc. I turn around and see our accountant standing on tippy-toes
peering over my five foot divider with a manly swoosh and a silly grin on his face
saying “Gotcha, Prophead! Ha, ha, ha” So I say to myself “Looks like Goobs’
immaturity is flaring up this morning. Hope it goes away by noon.” I manage to get in a
couple of serene hours of blissful programming before Goobs’ maturity level nose
dives to the 3rd grade for the second time that day. Just as I was typing in an e specially
efficient arithmetic shift right instruction about 29 triangular pieces of yellow paper
sift through the air and land on their smaller round brothers. And I hear the maniacal
laughter of an obviously sexually frustrated person behind me “Gotcha again, Dweeb.
Heh, heh, heh” I look up the number for Rent-An-Accountant but the line is busy. I
brush the yellow triangles off my keyboard and make an optimization that has to do
with the number three. Like any child not getting the attention it wants, Goobs resorts
to more direct methods of assault. If you’ve ever been in the middle of a tricky piece of
self-modifying, recursive, threaded code while having soccer balls and volleyballs
bounced off your head then you can appreciate the kind of nuisance a bored accountant
can be. I was counting the microseconds until 5 PM. It came. Goobs left. I laughed. I
laughed again. Little did Goobs, the living embodiment of a feeble minded user, realize
that the one thing you don’t want to do in a software company is mess with a hacker.
DIALOG QUAKE
I needed to do something to his system that would be annoying but not render it
useless. I considered installing TMON on his system and turning on heap scramble but
he works with multi-megabyte data files over a network and I figured that would make
his system too unusable. Besides, he’s slow enough anyways that he wouldn’t realize I
had done anything. It had to be more obvious. I thought about remapping his keyboard
but that would definitely make it unusable. After experimenting with patches to
_NewControl and _SizeControl that made all of his scroll bars 6 pixels wide I decided
to go with a patch to _ModalDialog instead (there were problems with some
applications in resizing their controls behind their back -- it did look cool in the
Finder, though). The code that follows is an INIT written in Lightspeed C 3.0 (actually,
Lightspeed Asm 3.0) that patches _ModalDialog. The effect of this patch is that all
modal dialogs will shake around a bit. This patch does not make modal dialogs useless,
but it does make them somewhat difficult to use (How’s your mouse coordination,
Goobs?).
The _ModalDialog patch is a pre-patch and a tail patch. Once the patch has been
installed, a call to _ModalDialog will temporarily patch _GetNextEvent, set up the tail
patch, call the real _ModalDialog, return to the tail patch, remove the _GetNextEvent
patch and exit normally (if anyone can use the word “patch” more times in a sentence,
please let me know). All of the real work is done by the _GetNextEvent patch.
The new _GetNextEvent calls the existing _GetNextEvent and then does some
additional work. It keeps track of a counter so that a random amount of time passes
between calls to _MoveWindow (to give the movement more of a jagged, quake-like
feel). The window is moved by a random amount in both directions in the range -7 to
+7. There is a mildly interesting problem in generating this range of random
numbers. It would be easier to generate the range -8 to +7 because that is the range
that can be expressed with 4 bit signed number. However, I needed a mean of zero in
my randomness so that the window wouldn’t have a tendency to shake itself off the
screen. One solution would be to generate the range 0 to 14 (with a DIVU instruction)
and subtract 7 but like most conscientious programmers, I stay as far away as possible
from 150 cycle instructions. Here’s what I ended up doing (say there are random bits
in D0):
;1
;preserve the sign bit and the low 3 bits
andi #0x8007,D0