<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DevBlog &#187; Release</title>
	<atom:link href="http://simonowen.com/blog/category/release/feed/" rel="self" type="application/rss+xml" />
	<link>http://simonowen.com/blog</link>
	<description>Stuff and nonsense</description>
	<lastBuildDate>Thu, 17 Jun 2010 22:39:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Space Invaders emulator</title>
		<link>http://simonowen.com/blog/2009/12/10/space-invaders-emulator/</link>
		<comments>http://simonowen.com/blog/2009/12/10/space-invaders-emulator/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 20:56:18 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Emulator]]></category>
		<category><![CDATA[Release]]></category>
		<category><![CDATA[SAM Coupe]]></category>

		<guid isPermaLink="false">http://simonowen.com/blog/?p=122</guid>
		<description><![CDATA[I thought it was about time I added the Space Invaders &#8220;emulator&#8221; (binary port?) to my website, as I&#8217;d not touched it in over 3 years. Most of the work to get it running was done, with just sound and display rotation left to add. While mulling over the tricky display code I moved on [...]]]></description>
			<content:encoded><![CDATA[<p>I thought it was about time I added the Space Invaders &#8220;emulator&#8221; (binary port?) to my website, as I&#8217;d not touched it in over 3 years.  Most of the work to get it running was done, with just sound and display rotation left to add.  While mulling over the tricky display code I moved on to other projects and it was pretty much forgotten about.</p>
<p>It&#8217;s still unfinished but I&#8217;ve cleaned up the code, prepared a bootable disk, and refreshed myself on the technical details.  It was an interesting contrast to the Pac-Man project I&#8217;d worked on previously.  As before, the challenge was to modify as little of the original ROM as possible, with a virgin copy of the ROM patched at runtime.</p>
<p><strong>CPU</strong></p>
<p>The <em>Space Invaders</em> arcade machine uses an <a href="http://en.wikipedia.org/wiki/Intel_8080">Intel 8080</a> CPU running at just under 2MHz.  The Z80 was released 2 years after the 8080 and was designed to be object-code compatible, so the Invaders code runs on SAM (almost) unmodified.  The Z80 also added many new features, including: IX/IY index registers, alternate registers sets, multiple interrupt modes, CB/ED extended instruction sets, and the relative jump instructions <strong>JR [cc]</strong> and <strong>DJNZ</strong>.</p>
<p>The 8080 has a single interrupt mode equivalent to the Z80&#8242;s IM0, where an instruction is supplied on the bus at interrupt time.  The Invaders hardware supplies both <strong>RST 08</strong> and <strong>RST 10</strong> instructions at a frequency of 60Hz, which drive the overall game logic, including the attract screen.  SAM lacks the extra hardware, but they can both be simulated using IM2 and a line interrupt, without modifying the ROM.</p>
<p>I/O ports 1 to 6 are used for coin and button inputs, as well a hardware bit-shifter circuit.  The shifter takes a 16-bit value (written to port 4 in low/high order), and a left-shift count (written to port 2).  Reading from port 3 returns just the high byte of the result &#8212; more on this later.</p>
<p>As we&#8217;re running the ROM code natively, trapping the I/O requires patching the instructions that make the requests.  The only I/O instructions supported by the 8080 are <strong>IN A,(n)</strong> and <strong>OUT (n),A</strong>, which include the port number as an immediate operand.  This allows us to use a simple loop to find and patch instructions that access ports 1 to 6 (later checked manually to ensure no false-positive matches).  Each occurrence is replaced by a <strong>RST 08</strong> instruction, with the original operand modified to include a flag indicating whether the original instruction was IN or OUT.  We could have used separate RST calls for each, but that requires duplicating the RST handler and modifying more of the original ROM.</p>
<p>Since we&#8217;re simulating the interrupt calls, we have control over how the original <strong>RST 08</strong> and <strong>RST 10</strong> handlers are invoked.  The ROM code for both start with 4 register push instructions, which can be moved to our own interrupt handler, freeing the space for our I/O hook.</p>
<p><strong>DISPLAY</strong></p>
<p>Space Invaders uses a monochrome bitmapped display with a linear layout, similar to SAM&#8217;s mode 2.  The display resolution is 224&#215;256, but like most portrait arcade games the display hardware works in landscape mode.  Fitting the 256&#215;224 (rotated) area on SAM&#8217;s 256&#215;192 screen means we lose 4 character columns from the width of the play area.</p>
<p>As with SAM&#8217;s mode 2 (and the Spectrum), drawing to a non-character aligned position requires bit shifting of data.  Invaders uses this for more control over the vertical position of the invaders, as well as the smooth scrolling of player and invader bullets.  The hardware shifting circuit makes easy work of this, which is a good thing considering the slow CPU speed!  That said, the invader pack does only move one invader at a time, keeping the per-frame drawing to a minimum.</p>
<p>The Invaders display is stored at &#038;2400-3fff, which isn&#8217;t compatible with the 16K boundary requirement for SAM&#8217;s mode 2.  That means redirecting ALL display writes to a suitable upper memory location; something difficult to do from a centralised point in the code.  About the only option is to identify ROM routines accessing the display and provide alternative implementations.</p>
<p>Copying the first 6K of Invaders display to a SAM mode 2 screen in upper memory confirmed the game was running, but revealed another issue &#8212; the bit order within display bytes was reversed compared to SAM, requiring each byte be flipped before writing.  The byte rotation could be avoided by rotating the display in the opposite direction, but that would leave scanline rows in reverse order, requiring a much larger display mapping table to correct.</p>
<p>To map the display accesses to a SAM-compatible location we offset the high byte of the address.  Subtracting an additional 2 from this value also pulls the display up (well, left!) by two columns, centralising the game area on the SAM display.  This clips a character from each side of the title area, and half an invader at the left and right edges, but it&#8217;s only a small difference.  The movement range for the player turret is more limited so it&#8217;s unaffected.</p>
<p>The game now looked great, but play-testing revealed some issues.  When the invader pack reaches the edge of the display it&#8217;s supposed to lower and turn back, but that wasn&#8217;t happening.  Also, player bullets were passing through the invaders without hitting them.  It turned out that collision detection was done by checking the display contents, but it was still reading from the original display location.  Hooking an extra couple of routines to look at the new display area soon fixed that.</p>
<p>A final change was to add a splash of colour to match the original machine.  As the video hardware didn&#8217;t support colour, cellophane strips were added to areas of the monitor: green for lives, bases and player turret, red for the flying saucer at the top.  An equivalent effect can be achieved in the SAM version using blocks of mode 2 attributes, which are unaffected by the display data writes.</p>
<p>Rotating the display to the normal SAM orientation remains a challenge.  My original approach was to apply rotation and scaling to each display write, preserving the original layout.  That meant scaling/masking/combining each byte, so the iconic graphics would suffer some scaling distortion.  A better approach might be to relocate some areas of the display, as I did with the score and fruit areas in my Pac-Man emulator.  It still requires rotation, but only within simple 8 pixel blocks.  Writes from some hook reimplementations could also be optimised for full block writes.</p>
<p><strong>SOUND</strong></p>
<p>The sound effects in the original game are generated using analogue circuits rather than a sound chip, which makes them difficult to emulate in a traditional sense.  Most Space Invaders emulators use sound samples taken from the original machine instead.  I haven&#8217;t implemented the sound yet, but will attempt to create approximate effects with the SAM sound chip.</p>
<p>The source code and bootable disk image are <a href="http://simonowen.com/sam/invaders/">now available</a> on my website, but you&#8217;ll need to provide your own Space Invaders ROM image.</p>
]]></content:encoded>
			<wfw:commentRss>http://simonowen.com/blog/2009/12/10/space-invaders-emulator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apple 1 emulator</title>
		<link>http://simonowen.com/blog/2007/03/19/apple-1-emulator/</link>
		<comments>http://simonowen.com/blog/2007/03/19/apple-1-emulator/#comments</comments>
		<pubDate>Mon, 19 Mar 2007 07:46:17 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Emulator]]></category>
		<category><![CDATA[Release]]></category>
		<category><![CDATA[SAM Coupe]]></category>

		<guid isPermaLink="false">http://blog.simonowen.com/2007/03/19/apple-1-emulator/</guid>
		<description><![CDATA[This will probably be my last emulator for a while so I can return to normal projects. I&#8217;d wanted to emulate the Apple 1 for quite a while, and didn&#8217;t think it should take more than a couple of hours to make a usable emulator. The Apple 1 is a surprisingly simple device, with 1MHz [...]]]></description>
			<content:encoded><![CDATA[<p>This will probably be my last emulator for a while so I can return to normal projects.  I&#8217;d wanted to emulate the <a href="http://en.wikipedia.org/wiki/Apple_1">Apple 1</a> for quite a while, and didn&#8217;t think it should take more than a couple of hours to make a usable emulator.</p>
<p>The Apple 1 is a surprisingly simple device, with 1MHz 6502 CPU, 4K RAM (expandable to 32K) and a tiny 256-byte monitor ROM.  Slots on the main board allowed for add-on ROMs for BASIC, cassette functions, assembler, etc.  The <a href="http://simonowen.com/sam/apple1emu/a1man.pdf">user manual</a> includes comprehensive hardware details plus a <em>fully commented</em> disassembly of the monitor ROM.</p>
<p>There aren&#8217;t many original Apple 1 devices anymore, but there are a few modern replicas available.  Most of them use the 65C02 CPU, so it&#8217;s probably just as well I added support for it recently!  The original ROMs don&#8217;t use the extended instructions but a 3rd party assembler supports for them so it was worth having them covered.</p>
<p>Input and output is via a dumb terminal style interface, supporting only upper-case letters and a slightly cut-down symbol set.  I/O speed is tied to the terminal display, giving a 60 characters/second maximum on the original.  Both input and output have data and control ports, with the latter used to indicate whether the terminal is busy outputting a character or has a key available for input.</p>
<p>For the emulation, the limited terminal output speed means at most 1 character (plus cursor) needs to be drawn each interrupt.  Until that is processed the terminal appears busy and the running program will wait before outputting more.  SAM&#8217;s 50Hz interrupt frequency reduces the output speed slightly, but not by enough to worry about.  Adding a line interrupt in the middle of the frame (312/2-68 = line 88) double this to 100Hz very easily, so Sym-1 and Sym-2 can be used to change the terminal speed.</p>
<p>When a character is written or a key is read, the terminal must update the control ports with the new status.  This must happen as part of the read/write to prevent the running program doing anything further until it has been processed.  The 6502 core was enhanced to trap memory writes for the Orao emulator, so the display could be updated immediately.  The Apple 1 emulation also needs the same enhancement for memory <em>reads</em>, so it can update the input control port.</p>
<p>The output terminal is 40&#215;24 characters, giving a maximum character set size of 6&#215;8 pixels for a 256&#215;192 mode 2 SAM screen mode.  Mode 3 would have allowed up to 12&#215;8 thin pixels, but there wasn&#8217;t really much benefit from the extra resolution, and the 24K display was 4 times slower to scroll.  Perhaps the only drawback in using mode 2 is that Spectrum-style masking and rotating needed to draw each character.</p>
<p>Input is entirely character based, and doesn&#8217;t need support for multiple simultaneous key presses (just Shift for symbols).  For that reason I decided to use SAM&#8217;s ROM keyboard scanner rather than rolling my own version.  All I had to do was page the ROM in and ask for the next key, with the ROM debouncing the input and buffering fast typing.  The returned key symbols are then converted to Apple 1 keys, converting lower-case to upper-case, and mapping a few special keys including Delete, Tab and Escape.</p>
<p>Normal monitor use is 100% speed, as most of the time is spent waiting for key presses.  To test the underlying speed I ran an empty loop in BASIC:  FOR X=1 TO 1000 : NEXT X  which takes 1.2 seconds on the original device and 10 seconds in my emulator.  The 10-15% running speed matches the results for the Orao emulator, and probably applies to anything else that uses my 6502 core.</p>
<p>The completed emulator (plus source code) is <a href="http://simonowen.com/sam/apple1emu/">now available</a> on my website.</p>
]]></content:encoded>
			<wfw:commentRss>http://simonowen.com/blog/2007/03/19/apple-1-emulator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Orao emulator</title>
		<link>http://simonowen.com/blog/2007/03/05/orao-emulator/</link>
		<comments>http://simonowen.com/blog/2007/03/05/orao-emulator/#comments</comments>
		<pubDate>Mon, 05 Mar 2007 23:46:01 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Emulator]]></category>
		<category><![CDATA[Release]]></category>
		<category><![CDATA[SAM Coupe]]></category>

		<guid isPermaLink="false">http://blog.simonowen.com/2007/03/05/orao-emulator/</guid>
		<description><![CDATA[This emulator started as a quick test of my 6502 core, to see if it could run the Orao ROMs. I half expected it to fail due to lack of decimal mode or interrupt support, neither of which were implemented in the SID player core. It took just 20 minutes of hacking the SID player [...]]]></description>
			<content:encoded><![CDATA[<p>This emulator started as a quick test of my 6502 core, to see if it could run the <a href="http://en.wikipedia.org/wiki/Orao_(computer)">Orao</a> ROMs.  I half expected it to fail due to lack of decimal mode or interrupt support, neither of which were implemented in the <a href="http://simonowen.com/sam/sidplay/">SID player</a> core.  It took just 20 minutes of hacking the SID player source code to reach the point where I could see the flashing input cursor, and it would have been a crime not to continue&#8230;</p>
<p>Keyboard input was transplanted from the matrix scanning in the <a href="http://simonowen.com/sam/galemu/">Galaksija emulator</a>, though due to the weird memory mapping layout, the Orao table needs 3-byte (address+value) entries for each key.  The bulk of the addresses were taken from the <a href="http://www.foing.hr/~fng_josip/orao.htm">Windows Orao emulator</a> source, though there were a few minor errors that I&#8217;ve corrected (one of them stopping Up working in Boulder Dash).</p>
<p>I considered updating the display during interrupt processing, but the large (256&#215;256 = 8K) display size was too much to do <em>every</em> frame.  Splitting the frame into 8 or 16 strips to have minor impact on the CPU emulation would have made it too obvious and laggy.  It seemed better to update the display live by catching writes to the display memory.  Unlike native running Z80-based emulators, we have full control of the 6502 CPU and can filter the writes as they happen.</p>
<p>One approach was to modify any instruction that could write to the display, but that would require a lot of duplicate code.  Fortunately, each of the writes formed the target address in HL, where it remained until the point it jumped back to main_loop (next instruction fetch).  I simply had to define a new looping point, and use that instead of main_loop for any display write candidates.  Zero-page writes (&#038;0000-&#038;00ff) couldn&#8217;t affect the display (&#038;6000-&#038;7fff), so they were ignored.</p>
<p>Display writes were filtered using a simple:<br />
<code>LD   A,H<br />
CP   &#038;80<br />
JR   NC,screen_or_up</code><br />
Using JR instead of JP meant the fall through case was only 5 tstates instead of 10 tstates.  The total display write checking overhead was 4+7+5 = 16 tstates (plus contention) for normal RAM writes, which didn&#8217;t seem <em>too</em> bad.  Further address filtering could also be done for sound writes at &#038;8800, without further slowing of the normal RAM write path.  No other addresses were of interest to us, so they were ignored.</p>
<p>At first glance the Orao display seems perfectly suited to SAM&#8217;s mode 2 layout, with both using linear addressing, 32 bytes per line, and 8 pixels per byte.  The biggest difference is Orao&#8217;s 256 line vs SAM&#8217;s 192, where clipping or scaling of the display would be needed.  Unfortunately, the bit order within each Orao display byte is also reversed compared to SAM, ruling out a simple memory copy to update the display.</p>
<p>Lookup tables to the rescue!  Using a 256-byte table for the bit-reversing was a no-brainer, but the display mapping was more awkward.  My first thought was to use a line mapping table, mapping from Orao line to SAM line, with &#038;c0 entries for lines that weren&#8217;t visible.  That still required too much arithmetic to look up an address, then add the line offset from the low 5 bits of the original address.  Whatever I used would be done for <em>every byte</em> written to the display, so it had to be fast.</p>
<p>The 12K needed for the mode 2 display meant there wasn&#8217;t room in the normal 64K address space, so I was already paging to access it.  That left over 16K of spare space in the 32K paging window.  Rather than looking up display lines, I had enough space to map every byte on the Orao display to the final SAM address.  This also gave the flexibility needed to pan any 192-line view of the original 256-line display, and even to scale the original display to fit, without any additional overhead.</p>
<p>As with the 6502 instruction handler addresses, the display table was ordered with address low bytes in the lower half and the address high bytes in the upper half.  That allowed a SET/RES instruction to switch halves during the lookup, which is twice the speed of using add/sub on the high byte instead.  Orao display bytes outside the visible area are mapped to SAM line 192, just beyond the visible display.</p>
<p>Everything seemed perfect at this point, until I realised I needed to preserve the 6502 PC value in DE.  The core also crammed 6502 registers into almost every other Z80 register, leaving little room to juggle paging, the original address and a new address lookup.  The only register-based option to preserve DE was to use IX, at a cost of 16 tstates each way.  That was still 4 tstates faster that pushing DE around the block, once stack memory contention was included.</p>
<p>Here&#8217;s the final screen write code:<br />
<code><br />
ld  ixh,d<br />
ld  ixl,e<br />
ld	e,(hl)<br />
ld	d,rev_table/256<br />
ld	a,screen_page+rom0_off<br />
out	(lmpr),a<br />
ld	a,(de)<br />
ld	d,(hl)<br />
res	5,h<br />
ld	e,(hl)<br />
ld	(de),a<br />
ld	a,low_page+rom0_off<br />
out	(lmpr),a<br />
ld  d,ixh<br />
ld  e,ixl</code></p>
<p>The 6502 core got a few additional upgrades along the way, with the first being a boost to 65C02 support.  This added a new addressing mode, and a handful of new instructions (many sorely lacking from the base 6502).  A side-effect of this was that undocumented instructions were guaranteed NOPs (1 to 3 bytes in length), so I didn&#8217;t have to worry about the hybrid undocumented instructions in the original chip.</p>
<p>Decimal mode was finally added too, in just 20 bytes of extra code.  I simply needed to optionally execute a DAA after the adc/sbc calculations to make the necessary adjustment.  The DAA was patched with a NOP when in normal binary calculation mode, for the non-BCD behaviour.</p>
<p>There were no interrupts to handle for the Orao, but I completed the implementations of BRK (call maskable interrupt handler) and RTI (return from interrupt), so they could be used if anything tried.  As they&#8217;re untested, I set the emulator border colour to green to show it has been used.  This actually happens when running Space Invaders, but due to a suspected corrupt image.  The BRK instruction is &#038;00, so it&#8217;s quite likely to get called if execution jumps to a random memory location.</p>
<p>As a result of the 65C02 change the emulator now runs Manic Miner correctly, a game which crashes under the Windows versions due to incorrect undocumented instruction handling.  The decimal mode addition also fixes the score updating in Manic Miner and the timer count-down in Boulder Dash.  Space Invaders will need redumping from the original tape for it to work correctly.</p>
<p>The final emulation speed is typically 10-15% that of the original machine speed, with slower speed during heavy display writes due to the screen write overhead described above.  The mix of 6502 instructions also makes a difference, with heavy indexing requiring more calculations for the CPU emulation.  It still runs surprisingly quickly considering everything it&#8217;s doing, and on a machine produced only a few years later.</p>
<p>The completed emulator is <a href="http://simonowen.com/sam/oraoemu/">now available</a> on my site, with the source code following soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://simonowen.com/blog/2007/03/05/orao-emulator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Galaksija emulator</title>
		<link>http://simonowen.com/blog/2007/02/21/galaksija-emulator/</link>
		<comments>http://simonowen.com/blog/2007/02/21/galaksija-emulator/#comments</comments>
		<pubDate>Wed, 21 Feb 2007 23:02:36 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Emulator]]></category>
		<category><![CDATA[Release]]></category>
		<category><![CDATA[SAM Coupe]]></category>

		<guid isPermaLink="false">http://blog.simonowen.com/2007/02/21/galaksija-emulator/</guid>
		<description><![CDATA[I&#8217;ve spent most of the last week porting Tomaz Kac&#8217;s Galaksija emulator from Spectrum to SAM, with version 1.0 now available on my site. Basic SAM support was trivial, requiring just an OUT to LMPR to page in the ROMs, and another OUT to VMPR to set video mode 1. The Spectrum key matrix is [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent most of the last week porting Tomaz Kac&#8217;s Galaksija emulator from Spectrum to SAM, with version 1.0 <a href="http://simonowen.com/sam/galemu/">now available</a> on my site.</p>
<p>Basic SAM support was trivial, requiring just an OUT to LMPR to page in the ROMs, and another OUT to VMPR to set video mode 1.  The Spectrum key matrix is compatible so the keyboard worked, and SAM&#8217;s break button could even be used for hard break in Galaksija BASIC too.  Proper SAM support required a number of changes&#8230;</p>
<p>The first was to use mode 2 instead of mode 1, mainly to avoid the <a href="http://simonowen.com/sam/articles/mode1/">mode 1 contention</a> slowdown.  This only gave roughtly a 10% speedup, which was rather disappointing.  A chunk of the extra time was eaten away by needing ADD HL,DE to move between screen lines in the linear layout instead of INC H (for most) on the Spectrum.  In the worst case of drawing all 512 characters it requires an extra 512*11*(12-8) = 45056 tstates!  It <i>is</i> still faster overall, and worth the change from mode 1.</p>
<p>The Galaksija display is a text mode of 32&#215;16 characters, with each character 8&#215;13 pixels in size.  Tomaz had already changed the font to be 8&#215;12 to fit the Spectrum height, which was perfect for SAM use too.  Having 2 characters span 3 vertical blocks made it easier to draw on the Spectrum version, but made no difference to mode 2 on the SAM &#8211; each character could be treated completely separately.</p>
<p>The biggest difference from the Spectrum version was to draw only changed characters between frames.  This gave a huge speed boost in most cases, and even with the extra comparisons it was faster than the old version as long as no more than 80% of the screen was being updated.  Further speedups were made by using a table for character address lookups, rather than tracking the address in a register (which required some arithmetic).  A stack method to access the table allows a simple POP to fetch the next address, or discard it for skipped characters.</p>
<p>The speed gained meant that many games now ran too fast, or they ran with variable speed depending on how much of the display had changed.  That required adding a throttling mechanism to limit the maximum speed, which was implemented by limiting number of unchanged characters that could be skipped during drawing.  This technique worked well for the SAM version, but not so well for the Spectrum.  In some cases <i>adding</i> small delays to the Spectrum drawing code increased the running speed!  This is related to the long interrupt processing and the games own frame synchronisation, but I still don&#8217;t fully understand the details.</p>
<p>In a last minute change I replaced the SAM throttling code to use HPEN to track the number of frames that had elapsed during drawing.  Rather than looping over all 512 characters as 2 blocks of 256, I split it into 4 blocks of 128.  At the end of each block I read HPEN and compare with the previous value, and if it&#8217;s less than the current value I know it&#8217;s spilled over to a new frame.  At the end, if 2+ frames have passed then I&#8217;m running too slow, otherwise there&#8217;s time to spare.  In the latter case I poll HPEN to wait for the raster to reach a specific point, before leaving the interrupt handler and allowing the game to continue.  The actual screen position was determined by trial and error, to ensure that most games ran at the correct speed.</p>
<p>Galaksija software was loaded from tape, and the Spectrum version used the ROM routines at &#038;0556 to load blocks.  The same technique could have been used for the SAM version, but since nobody uses tapes anymore it wouldn&#8217;t have been much use.  Instead I chose to exit to SAM BASIC to handle the loading, which was easier than paging DOS and using hook codes to do it directly.  Adding a simple menu and .GTP tape image parsing was just a few dozen lines of code too.</p>
<p>Full source code and build instructions are included with the disk image download, if you&#8217;re interested in knowing more.</p>
]]></content:encoded>
			<wfw:commentRss>http://simonowen.com/blog/2007/02/21/galaksija-emulator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FdInstall revamped</title>
		<link>http://simonowen.com/blog/2006/12/27/fdinstall-revamped/</link>
		<comments>http://simonowen.com/blog/2006/12/27/fdinstall-revamped/#comments</comments>
		<pubDate>Wed, 27 Dec 2006 02:47:01 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Release]]></category>
		<category><![CDATA[fdrawcmd.sys]]></category>

		<guid isPermaLink="false">http://blog.simonowen.com/2006/12/27/fdinstall-revamped/</guid>
		<description><![CDATA[I&#8217;ve spent the last few days updating FdInstall, which is used to install/uninstall/upgrade fdrawcmd.sys. It needed a few improvements for Vista support, which gave the perfect excuse for a complete revamp. The original installer was designed to have minimal dependencies, be simple to use, and avoid reboots where possible. I went for a single dialog [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent the last few days updating FdInstall, which is used to install/uninstall/upgrade <a href="http://simonowen.com/fdrawcmd/">fdrawcmd.sys</a>.  It needed a few improvements for Vista support, which gave the perfect excuse for a complete revamp.</p>
<p>The original installer was designed to have minimal dependencies, be simple to use, and avoid reboots where possible.  I went for a single dialog design, with dynamic option choices that depended on whether the driver was already installed, and how the version number compared to that of the active installer.</p>
<p>Here&#8217;s what it looked like on first-time installation:</p>
<p><a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2006/12/fdinstall-old.png" title="Old FdInstall"><img id="image23" src="http://blog.simonowen.com/wp-content/uploads/2006/12/fdinstall-old.thumbnail.png" alt="Old FdInstall" /></a></p>
<p>I wanted the new installer to be much more traditional wizard, with an uninstall entry in Add/Remove programs.  I had already used <a href="http://nsis.sourceforge.net/">NSIS</a> for the SimCoupe installer, so I knew it would do the job without being too bloated.</p>
<p>The new installer also addresses the following areas:</p>
<ol>
<li><strong>Single installer for x86 and x64</strong>
<p>32-bit applications are prevented from writing to the <em>Windows\system32</em> directory on 64-bit platforms, which now contains 64-bit system files.  Such requests are redirected into <em>Windows\SysWOW64</em> instead, which is the new location for 32-bit system files.  FdInstall&#8217;s attempts to write <em>fdrawcmd.sys</em> into <em>Windows\system32\drivers</em> ended up in the wrong place, so a 64-bit installer was created as a work-around.</p>
<p>Since then I&#8217;ve discovered the <em>Wow64DisableWow64FsRedirection</em> API function, which turns off the redirection, allowing 32-bit applications access to the 64-bit directories.  The allows a single new 32-bit installer to cover both x86 and x64 platforms.</li>
<li><strong>Vista x64 driver signing</strong>
<p>Starting with the 64-bit version of Vista, Microsoft <a href="http://www.microsoft.com/whdc/winlogo/drvsign/drvsign_perOS.mspx">requires</a> kernel-mode drivers to be digitally signed.  Unsigned drivers are simply not allowed to load on the system, even if you&#8217;re running with Administrator access rights on the current machine!</p>
<p>Here&#8217;s what happens when an unsigned driver is installed:</p>
<p><a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2006/12/vista_fdrawcmd_unsigned.png" title="Unsigned  Driver"><img id="image28" src="http://blog.simonowen.com/wp-content/uploads/2006/12/vista_fdrawcmd_unsigned.thumbnail.png" alt="Unsigned Driver" /></a></p>
<p>This insane decision is being pushed as a security measure, despite user-mode applications generally causing most of the problems on Windows machines.  In fact, the best known kernel rootkit was a music protection system released by Sony, and driver signing certainly wouldn&#8217;t have helped block it!  The signing requirement seems more likely to be a DRM measure to protection the digital media path from copying.</p>
<p>The only free signing work-arounds are to have a debugger attached to the system, or to press F8 during <em>each</em> boot to disable Digital Signature Enforcement.  Neither of these are particularly usable for a production driver, even a free one like mine!  My only real option was to buy a digital certificate, costing from &pound;140 (GlobalSign) to &pound;275 (Verisign) <strong><em>per year</em></strong>.</li>
<li><strong>Known publisher</strong>
<p>When launching downloaded applications from Internet Explorer, or any adminstrative application in Vista, Windows prompts for final confirmation from the user before launching it.  The severity of the confirmation prompt depends on whether the application is digitally signed.</p>
<p>Note the difference between the unsigned and signed applications below:</p>
<p><a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2006/12/simcoupe_unsigned.png" title="Unsigned Application"><img id="image30" src="http://blog.simonowen.com/wp-content/uploads/2006/12/simcoupe_unsigned.thumbnail.png" alt="Unsigned Application" /></a> <a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2006/12/simcoupe_signed.png" title="Signed Application"><img id="image29" src="http://blog.simonowen.com/wp-content/uploads/2006/12/simcoupe_signed.thumbnail.png" alt="Signed Application" /></a></p>
<p>Fortunately, the certificate needed for Vista x64 driver signing was also suitable for signing other modules, including the new installer.</p>
<li><b>Improved Vista support</b>
<p>Microsoft recommends that all applications designed to run on Vista include a manifest resource entry describing their privilege requirements.  This allows each program to indicate whether they should run with the standard users rights, or whether Windows should boost it to run with Administrative rights (prompting if necessary).  FdInstall needs to install a kernel-mode driver, so Admin rights are required.</p>
<p>It just happens that running the original installer under 32-bit Vista would correctly prompt for these rights, despite the lack of manifest entry.  For compatibility reasons, applications with &#8220;install&#8221; or &#8220;setup&#8221; sub-strings in their filenames are assumed to be installers and are boosted automatically.</li>
</ol>
<p>The actual driver installation involves copying the binary to <em>system32\drivers</em>, adding a new service, adding the driver as a lower filter for floppy-class devices, then restarting the devices to activate the driver without a reboot.  Uninstallation requires most of these steps in reverse, but in a slightly different order!</p>
<p>Most of those aren&#8217;t standard NSIS facilities, so I created a small (5K) plug-in DLL to be called from the installer script.  Most of the DLL code was the same as the original installer, so it was simply a copy-and-paste exercise.  A slight complication was the device restarting, which couldn&#8217;t be done from a 32-bit application since it calls 64-bit class installer DLLs (failed with ERROR_IN_WOW64).  That required an additional tiny (3K) x64 application to make the calls, using exactly the same code as the 32-bit version.</p>
<p>The install script is relatively simple compared to most other applications.  The target directory is fixed at <em>system32\drivers</em>, the only installation option is the driver itself, and there is no need to install any icons.</p>
<p>Here are the 3 wizard steps (welcome, license, copy+finish):</p>
<p><a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2006/12/fdinstall-1.png" title="FdInstall Step 1"><img id="image31" src="http://blog.simonowen.com/wp-content/uploads/2006/12/fdinstall-1.thumbnail.png" alt="FdInstall Step 1" /></a> <a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2006/12/fdinstall-2.png" title="FdInstall Step 2"><img id="image32" src="http://blog.simonowen.com/wp-content/uploads/2006/12/fdinstall-2.thumbnail.png" alt="FdInstall Step 2" /></a> <a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2006/12/fdinstall-3.png" title="FdInstall Step 3"><img id="image33" src="http://blog.simonowen.com/wp-content/uploads/2006/12/fdinstall-3.thumbnail.png" alt="FdInstall Step 3" /></a></p>
<p>The final installer size is 96K, a mere 25K larger than the total for the old installers &#8211; not bad considering how much better it looks!</p>
<p>The finished installer is now available from the <a href="http://simonowen.com/fdrawcmd/">fdrawcmd.sys page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://simonowen.com/blog/2006/12/27/fdinstall-revamped/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
