<?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; SimCoupe</title>
	<atom:link href="http://simonowen.com/blog/category/simcoupe/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>ATTRibute port</title>
		<link>http://simonowen.com/blog/2007/08/04/attribute-port/</link>
		<comments>http://simonowen.com/blog/2007/08/04/attribute-port/#comments</comments>
		<pubDate>Sat, 04 Aug 2007 02:29:23 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[SimCoupe]]></category>

		<guid isPermaLink="false">http://simonowen.com/blog/2007/08/04/attribute-port/</guid>
		<description><![CDATA[The attribute port (255) is part of SAM&#8217;s Spectrum compatibility, and implements a quirk of the original hardware. On the Spectrum it returns the last value on the ULA side of the bus &#8212; an attribute byte over the main screen or 255 during the border. A handful of Spectrum titles use it to synchronise [...]]]></description>
			<content:encoded><![CDATA[<p>The attribute port (255) is part of SAM&#8217;s Spectrum compatibility, and implements a quirk of the original hardware.  On the Spectrum it returns the last value on the ULA side of the bus &#8212; an attribute byte over the main screen or 255 during the border.  A handful of Spectrum titles use it to synchronise with the top of the main screen, giving the maximum the amount of time to draw sprites without raster shearing.</p>
<p>To my knowledge no SAM software uses it, so it&#8217;s remained near to the bottom of my SimCoupe ToDo list for many years.  I made do with a dummy implementation, returning zero over the main screen and 255 during the border.  Though a bug in the border test meant even that functionality was broken, so port reads have always returned zero!</p>
<p><a href="http://velesoft.speccy.cz">Velesoft</a> recently released a SAM-mouse enhanced version of the Spectrum title <i><a href="http://www.worldofspectrum.org/infoseekid.cgi?id=0001928">Galactic Gunners</a></i>.  It uses the ATTR port to synchronise drawing with the top of the main screen, and the broken SimCoupe implementation caused sprites in the upper 2/3 of the screen to flicker.  In this case fixing the border test bug cured the flicker, but full ATTR support was needed to ensure other titles behaved correctly.</p>
<p>The <i>SAM Technical Manual</i> contains some details of SAM&#8217;s ATTR port behaviour:</p>
<blockquote><p>This register enables the programmer to read the attributes of the currently displayed character cell in modes 1 and 2, and the third byte in every four displayed in modes 3 and 4.</p></blockquote>
<p>There&#8217;s no mention of what happens in the border, thought a quick test was enough to show it didn&#8217;t match the Spectrum&#8217;s behaviour.  In fact it seemed to only return attribute bytes from the main screen.  Time for a test program!  My usual approach with these tests is to make whatever I&#8217;m probing as visible as possible, so the emulation will only match the real thing once everything is perfect.  In this case I used a tight loop reading from the ATTR port and writing the result to CLUT entry 0:</p>
<p><code><br />
ld hl,loop<br />
ld bc,&#038;00f8<br />
loop:<br />
in a,(255)<br />
out (c),a<br />
jp (hl)<br />
&nbsp;<br />
</code></p>
<p>This code must be run with interrupts disabled, and started from a fixed position in the frame to ensure it&#8217;s the same on each run.  Both are most easily achieved by placing the code at the IM 1 handler address of &#038;0038 and using a HALT to guarantee the current instruction is a fixed 4 tstates when the interrupt handler is invoked.  The 4-cycle rounding from the HALT opcode fetch ensures the test begins on the same frame cycle each time.</p>
<p>To make the most of the test output I created a test pattern containing a range of colours, and interleaved with columns of palette colour 0 where the test colour would show through.  Here&#8217;s what I came up with:</p>
<p><a href='http://simonowen.com/blog/wp-content/uploads/2007/07/attrtest1.png' title='ATTR Pattern'><img src='http://simonowen.com/blog/wp-content/uploads/2007/07/attrtest1_small.png' alt='ATTR Pattern' /></a></p>
<p>And here&#8217;s what it looks like on SAM running in screen mode 1:</p>
<p><a href='http://simonowen.com/blog/wp-content/uploads/2007/07/attrtest2.png' title='ATTR Test'><img src='http://simonowen.com/blog/wp-content/uploads/2007/07/attrtest2_small.png' alt='ATTR Test' /></a></p>
<p>The time between the port read and the palette write causes the output to be shifted a few screen blocks to the right of the main screen position, reaching into the right border area.  The screens above were taken with the SimCoupe border area set to <i>Complete</i>, to show what would be seen if the ASIC generated the display over the full frame.  This doesn&#8217;t happen on a real machine but is useful to see video changes outside the visible TV area.</p>
<p>The stripes on the main screen and the jagged edges in the lower border are caused by the loop timing not being an exact multiple of the 384 tstates per display line.  The actual timing is complicated by the display memory fetches, mode 1 contention delays, and ASIC port I/O delays, but if you look closely you can see three repeating line end positions.</p>
<p>If SAM&#8217;s border behaviour matched the Spectrum, the border colour should be bright white (colour 127, since the top bit is not used) everywhere except to the right of the main screen where the colour bleeds from the main screen.  To the left of the main screen the colour is actually off-white (colour 120), which matches the right-most attribute on the scanline &#8212; bright white paper with black ink  is 01111000 binary, 120 decimal.</p>
<p>To test the right-most attribute observation with the lower border I added a bright white paper with white ink (01111000 binary, 127 decimal) block to the bottom right of the screen.  As expected this caused the lower and upper border to be coloured bright white.  So during the border areas SAM was returning the last attribute value fetched to draw the main screen area.</p>
<p>As a further test I coloured the screen attributes red, set the screen-off bit to disable the display, coloured the screen attributes green, then read from the ATTR port.  As expected the port returned the red colour, since that was the last screen byte the ASIC read when drawing the display.  Here&#8217;s the BASIC code for the test:<br />
<code><br />
10 PAPER 2 : BORDER 2 : MODE 4<br />
20 BORDER 4 : OUT 254,132 : PAPER 4 : CLS<br />
30 PAUSE 5 : PRINT IN 255 : REM should be 34 for red<br />
40 BORDER 0<br />
&nbsp;<br />
</code></p>
<p>Once the port behaviour was understood the SimCoupe implementation could be enhanced.  When the port is read it uses the current raster position to determine the last on-screen location that the ASIC would have read, and the memory address of the screen data (which depends on the current screen mode).  The existing mode-change ASIC artefact implementation did a lot of this already so the same code could be re-used.</p>
<p>An additional complication is the value returned when the display is disabled, which may no longer be part of the current display.  It requires the ATTR value to be determined when the screen goes from enabled to disabled, giving a value to return for as long as the screen remains disabled.</p>
<p>The test program and source code are available for <a href='http://simonowen.com/blog/wp-content/uploads/2007/08/attrtest.zip' title='ATTR Test disk image'>download</a> (9K).  Pressing the NMI button returns you to basic, allowing the screen mode/contents to be changed to see different patterns.  Don&#8217;t forget that it won&#8217;t work in SimCoupe until the next release!</p>
]]></content:encoded>
			<wfw:commentRss>http://simonowen.com/blog/2007/08/04/attribute-port/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Atom Lite CF support</title>
		<link>http://simonowen.com/blog/2007/06/25/atom-lite-cf-support/</link>
		<comments>http://simonowen.com/blog/2007/06/25/atom-lite-cf-support/#comments</comments>
		<pubDate>Mon, 25 Jun 2007 23:44:11 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[SamDisk]]></category>
		<category><![CDATA[SimCoupe]]></category>

		<guid isPermaLink="false">http://simonowen.com/blog/2007/06/25/atom-lite-cf-support/</guid>
		<description><![CDATA[With Edwin&#8217;s help, I&#8217;ve just finished adding Atom Lite 1.x support to both SimCoupe and SamDisk. The new interface is a simplified version of the original Atom HDD interface, and is now primarily for Compact Flash use. The Atom Lite uses an ATA feature for 8-bit data accesses, rather than normal 16-bit IDE mode, avoiding [...]]]></description>
			<content:encoded><![CDATA[<p>With Edwin&#8217;s help, I&#8217;ve just finished adding Atom Lite 1.x support to both SimCoupe and SamDisk.</p>
<p>The new interface is a simplified version of the original Atom HDD interface, and is now primarily for Compact Flash use.  The Atom Lite uses an ATA feature for 8-bit data accesses, rather than normal 16-bit IDE mode, avoiding the need for half the data to be latched inside the interface.  The change simplifies the design and allows faster data transfers &#8211; the next data byte is now fetched with a single IN, rather than having to select the high or (latched) low address first.  Streamed media playback anyone?</p>
<p>The new interface requires updated B-DOS and HD-BOOT ROM versions to select 8-bit mode, but once set it&#8217;s software compatible with the original interface.  Data can be read from both &#038;F6 and &#038;F7 ports as before, despite no latching being involved this time.  However, the change does means the byte order of the Atom Lite media is reversed (or perhaps un-reversed!) compared to the Atom, which returned the high byte first.  Fear not, existing Atom media can be converted to use Atom Lite byte-order using SamDisk!</p>
<p>The changes to SimCoupe were mainly to the ATA emulation, with enhancements to support 8-bit data mode and 28-bit LBA sector addressing.  The latter allows support for devices beyond the 8GB CHS limit (16383 cylinders, 16 heads, 63 sectors), extending the maximum size to a whopping 137GB.  Even an 8GB card would contain almost 10,000 B-DOS records, which could easily contain every SAM software title ever written!  The Atom Lite implementation is just a cut-down version of the existing Atom C++ class, which has been further simplified as part of the same changes.</p>
<p>The SamDisk changes were also fairly trivial, especially as there&#8217;s no ATA emulation to worry about.  The byte order of the media is determined by examining the <i>BDOS</i> signature at offset 0xe8 in the first record (which follows the boot sector and record list).  With the original Atom (seen as &#8220;DBSO&#8221;) data accesses must be byte-swapped after reads and before writes.  This allows all record-level commands to work transparently on both media.  A new command-line option (/bs) forces byte-swapping of entire images, used for the Atom <-> Atom Lite conversion mentioned above.  Simply read the device to an HDF image using the byte-swap option, then write the converted image back to the original device.</p>
<p>The Atom Lite 2.x boards are expected to include a Dallas clock chip, with registers access through the same floppy 2 ports.  SimCoupe support will be added once the details have been confirmed&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://simonowen.com/blog/2007/06/25/atom-lite-cf-support/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>AVI recording</title>
		<link>http://simonowen.com/blog/2007/04/24/avi-recording/</link>
		<comments>http://simonowen.com/blog/2007/04/24/avi-recording/#comments</comments>
		<pubDate>Tue, 24 Apr 2007 21:35:51 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[SimCoupe]]></category>

		<guid isPermaLink="false">http://blog.simonowen.com/2007/04/24/avi-recording/</guid>
		<description><![CDATA[I&#8217;ve now done the bulk of the work needed for SimCoupe&#8217;s AVI recording feature, using 8-bit MS RLE encoding as planned. It gives lossless video and (optionally) audio recording at up to full framerate, and should be no problem for most systems to handle in parallel to the emulation. The encoder was written from scratch, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve now done the bulk of the work needed for SimCoupe&#8217;s AVI recording feature, using 8-bit <a href="http://wiki.multimedia.cx/index.php?title=Microsoft_RLE">MS RLE</a> encoding as planned.  It gives lossless video and (optionally) audio recording at up to full framerate, and should be no problem for most systems to handle in parallel to the emulation.  The encoder was written from scratch, meaning it&#8217;s available on all platforms without additional library dependencies, as well as being tuned for emulator use.</p>
<p>Video is recorded in either half size or full size modes, with the latter needed to preserve mode 3 hi-res pixels.  Half size mode defaults to storing the odd pixels for the best quality in SAM BASIC, but even pixels can optionally be used instead.  Full size mode also respects the scanline option and intensity, so it should look the same as when using the emulator.  Only the 5:4 mode is ignored, as AVI doesn&#8217;t support aspect ratios, and proper smooth scaling of the image can&#8217;t be done due to the limited 8-bit video format.</p>
<p>Audio is stored in the same 44.1KHz 16-bit PCM format as the separate sound recording feature.  Unfortunately there aren&#8217;t any widely supported lossless codecs I can rely on, so the sound data remains uncompressed.  This requires 3528 bytes per frame, adding a steady 172K/s to the recording.  Of course, post-processing the audio stream into MP3 format reduced the file size without impacting the video quality.</p>
<p>The recording framerate uses a simple 1:n method to decide which frames to store, giving framerates of 50fps, 25fps, 16.67fps, &#8230; down to 1fps.  Key frames are stored every 5 seconds to give faster seeking during video playback, and allow catch-up if the decoder is struggling to keep up (possible with full-size 50fps videos on slower systems).</p>
<p>As with GIF, only the differences are stored between most frames.  MS RLE includes a &#8220;00 02 xx yy&#8221; GOTO sequence to skip up to 255 pixels on both horizontal and vertical directions, to position at the next change point.  Identical frames are stored as a 2-byte 00 01 sequence, adding 10 bytes to the recording including chunk headers.  Not as effecient as GIF but much better than most traditional video codecs.</p>
<p>Here&#8217;s a 2.4MB sample video of the first level of <i>Manic Miner</i>.  It was recorded in full resolution (576&#215;480) at 25fps, with sound post-processed into 192Kbps MP3 using <a href="http://virtualdub.sourceforge.net/">VirtuaDub</a>:</p>
<p><a href='http://simonowen.com/blog/wp-content/uploads/2007/04/manicminer.avi' title='Sample Video'><img src='http://simonowen.com/blog/wp-content/uploads/2007/04/manicminer.png' alt='Sample Video' /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://simonowen.com/blog/2007/04/24/avi-recording/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://simonowen.com/blog/wp-content/uploads/2007/04/manicminer.avi" length="2611146" type="video/avi" />
		</item>
		<item>
		<title>Sound and video recording</title>
		<link>http://simonowen.com/blog/2007/01/21/sound-and-video-recording/</link>
		<comments>http://simonowen.com/blog/2007/01/21/sound-and-video-recording/#comments</comments>
		<pubDate>Sun, 21 Jan 2007 03:04:21 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[SimCoupe]]></category>

		<guid isPermaLink="false">http://blog.simonowen.com/2007/01/21/sound-and-video-recording/</guid>
		<description><![CDATA[I&#8217;ve spent most of last week looking at recording features in SimCoupe, with initial support for sound/video and future support for input recording (more on that one in a future posting): Sound recording This was very easy to do as the data is already in PCM format ready to be written to a wave file. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent most of last week looking at recording features in SimCoupe, with initial support for sound/video and future support for input recording (more on that one in a future posting):</p>
<ol>
<li><strong>Sound recording</strong>
<p>This was very easy to do as the data is already in PCM format ready to be written to a wave file.  I simply write the RIFF/WAV header, append each new frame of PCM data, then seek back and write the final block+data lengths in the header before closing the file.</p>
<p>Wave files were the obvious choice for export as they&#8217;re universally supported and can always be converted/compressed for other uses.  It would also be relatively easy to export through a codec under Windows, to write directly in a different format, but that&#8217;s something for a future version.</p>
<p>I currently record only the SAA 1099 sound output, as that&#8217;s the only readily available source of sound chip data.  SimCoupe use hardware mixing (if available), so I don&#8217;t have access to the fully mixed stream (SAA, beeper, DACs and tape).  The core is being changed to use software mixing instead, and full recording support will be available once that is done.</p>
<p>Sound recordings can optionally have silence trimmed from the start and end, as that&#8217;s something users will typically want.  Another option allows recordings to be split into separate files, if there&#8217;s a enough (user-definable) silence between them.</p>
<p>Here&#8217;s a <a id="p47" href="http://blog.simonowen.com/wp-content/uploads/2007/01/sophistry.mp3">sample recording</a> of the <em>Sophistry</em> music, converted to MP3.
</li>
<li><strong>Video recording</strong>
<p>The plan is to write AVI files with a hand-coded MRLE encoder, using Microsoft&#8217;s Run-Length Encoding format.  It&#8217;s a simple format, and seems reasonably well supported on different platforms.  MRLE supports up to 256 colours (we need only 128), and the run-length encoding is very well suited to the our simple images.</p>
<p>That <emi>is</em> still the plan, but I got side-tracked before I completely finished it!  I was inspired by the animated GIF recording in the <i>SPIN</i> Spectrum emulator and decided to implement that in SimCoupe before AVI.  GIF is ideal for use on web pages, and the LZW compression is again well suited to our clean images.</p>
<p>GIF supports sub-image updates, so only the smallest change rectangle needs to be drawn between similar frames.  Transparency allows the re-use of colours from the same position in the previous frame, cutting the size down even further.  However, care does need to be taken when deciding between transparency and a solid colour, to maximise the run lengths for LZW to compress.</p>
<p>Before each frame image is a block defining how long the frame should remain visible.  As well as controlling the overall animation speed, this allows us to store neighbouring identical frames for free.  You simply increase the delay by 20ms for each identical display frame.</p>
<p>For smooth animation the recordings should ideally use full (50 fps) or half (25 fps) framerate.  Firefox plays these perfectly, but Internet Explorer and Opera limit the animation speed to around 15 fps.  Faster animations are simply played in slow motion, rather than skipping frames to maintain full speed.  For this reason I&#8217;ve included an option to set the framerate, so 16.66 fps (1 in 3 frames) can be used when IE support is needed.</p>
<p>I&#8217;ve also included a feature that can help record repeated sections, to be played over and over with the GIF loop feature.  Recording starts after the <em>next</em> change of image, and continues until the changed image is seen for a second time.  It&#8217;s perfect for preserving the flash attribute (see reset screen below), or repeating sections in games or demos (see the SAM Juggler image below).</p>
<p>The output GIF sizes are very respectable, but a decent GIF optimiser should be able to squeeze them down further.  The images I create include a full SAM palette of 128 colours, as I&#8217;ve no idea which colours will be used during the recording.  The palette in optimised images will typically include only used colours, reducing the LZW token count and the final compressed size.  However, forcing the optimiser to use the original palette may give a larger file than my original! <img src='http://simonowen.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The following GIF animations were recorded by SimCoupe.  The first shows a few lines of BASIC being entered, the second is the first 3 levels of Manic Miner, and the final one is a looped section from SAM Juggler.  As they are all recorded at 25 fps, I&#8217;d recommend viewing them using Firefox:</p>
<p><a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2007/01/hello.gif" title="Hello World"><img id="image46" src="http://blog.simonowen.com/wp-content/uploads/2007/01/hello.thumbnail.gif" alt="Hello World" /></a> <a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2007/01/manicminer.gif" title="Manic Miner"><img id="image43" src="http://blog.simonowen.com/wp-content/uploads/2007/01/manicminer.thumbnail.gif" alt="Manic Miner" /></a> <a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2007/01/samjuggler.gif" title="SAM Juggler"><img id="image44" src="http://blog.simonowen.com/wp-content/uploads/2007/01/samjuggler.thumbnail.gif" alt="SAM Juggler" /></a> </p>
<p>The final sample is what you see when holding in the SAM reset button.  It&#8217;s a mode 1 view of RAM page 0, which is where the system variables are stored.  The Spectrum-style flashing attributes alternate every 16 frames (320ms), which is perfect for a simple 2-frame looping animation.  And at only 3.125 fps even IE can manage to display it at the correct speed!</p>
<p><img id="image45" src="http://blog.simonowen.com/wp-content/uploads/2007/01/samreset.gif" alt="SAM Reset" />
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://simonowen.com/blog/2007/01/21/sound-and-video-recording/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://blog.simonowen.com/wp-content/uploads/2007/01/sophistry.mp3" length="1660133" type="audio/mpeg" />
		</item>
		<item>
		<title>SimCoupe tape support</title>
		<link>http://simonowen.com/blog/2007/01/11/simcoupe-tape-support/</link>
		<comments>http://simonowen.com/blog/2007/01/11/simcoupe-tape-support/#comments</comments>
		<pubDate>Thu, 11 Jan 2007 22:21:53 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[SimCoupe]]></category>

		<guid isPermaLink="false">http://blog.simonowen.com/2007/01/11/simcoupe-tape-support/</guid>
		<description><![CDATA[It&#8217;s been close to the bottom of my ToDo list for years, but I&#8217;ve finally added preliminary support for loading from tape. It was painless in the end too, largely thanks to Philip Kendall&#8217;s libspectrum library, which does all the hard work. It supports TZX, TAP and CSW tape images, which between them can represent [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been close to the bottom of my ToDo list for years, but I&#8217;ve finally added preliminary support for loading from tape.  It was painless in the end too, largely thanks to Philip Kendall&#8217;s <a href="http://fuse-emulator.sourceforge.net/libspectrum.php">libspectrum</a> library, which does all the hard work.  It supports TZX, TAP and CSW tape images, which between them can represent the content of any SAM tape.</p>
<p>I first had to build libspectrum for Win32, which isn&#8217;t an officially supported target platform.  Building with Cygwin did work, but the stand-alone DLL was over 600K!  A few code tweaks later I managed to build it as a Visual Studio 6 project, resulting in a much more respectable 49K DLL (UPX-compressed).</p>
<p>The SimCoupe side of the implementation is only a couple of hundred lines of code.  The libspectrum library supplies t-state timing information on when the next ear pulse is due, which is scheduled as a SimCoupe CPU event in the same way as interrupts.  When the event fires I toggle the ear bit of port #FE, ready to be picked up by the loader edge detection.  The timings do need an cycle-accurate machine emulation to work correctly, but we&#8217;ve had that for some time.  The rest of the implementation is just tape image management, so the user can insert/eject images.</p>
<p>I&#8217;ve had a run through the dozen or so tape SAM tape images I&#8217;ve had on my HDD for years, and most work fine.  The working ones include a couple of titles not yet available on <a href="http://www.worldofsam.org/">World of Sam</a>, which I&#8217;ll upload soon.  The non-working ones are simply bad dumps, converted from poor quality VOC samples &#8211; I&#8217;ll redump these from my own tapes.  I&#8217;ll also post a sam-users list request for other tape images, or for people to create images from any undumped titles.</p>
<p>The tape support is still pretty basic, with insert/eject/play/stop functions, and auto-play if the tape is inserted at the startup screen (exactly like auto-boot for disks, but pressing F7 instead of F9).  I&#8217;ll add a tape block browser soon, so you can select where to play the tape from on compilation images.  There&#8217;s probably not much demand/use for save support, so that will be completed last.</p>
<p>I&#8217;ve not looked at accelerated loading yet, but most (if not all) loaders call the edge routines in uncontended ROM, so a single solution should fit almost every SAM title.  In the meantime you can use SimCoupe&#8217;s turbo feature to zip through the slow loaders (unless you&#8217;re like me and enjoy watching them!).</p>
<p>Perhaps a bigger reason to add tape support is the mass of Spectrum software that exists in the format.  SimCoupe has no problem using Spectrum tape images, but I&#8217;m a little worried at how well they&#8217;ll work.  If you were a SAM owner in early 1990s you&#8217;ll remember the problem of loading Spectrum titles on the SAM.  Even if the timing values in the loaders were adjusted for the CPU speed difference, the fully contended RAM would break most custom loaders, with turbo loaders suffering most.</p>
<p>The Spectrum Emulator utility on the original SAM demo tape/disk was able to handle a selection of specific Spectrum loading schemes, and that should work just as well in SimCoupe.  I&#8217;m also hoping that the exact timings on the tape images will give more reliable loading than using a cheap tape recorder back in 1990, to improve reliability.  There&#8217;s also some scope for applying a compatibility scaling to the t-state tape timings, to better match SAM CPU speed.</p>
<p>I&#8217;m considering adding support for native loading of Spectrum snapshots (z80/sna/szx/etc.), as libspectrum provides support for those too.  Unlike the old Spectrum support in SimCoupe, it would be done in a 100% faithful SAM way without pretending to be a Spectrum emulator.  This would probably involve loading a Spectrum or skeleton ROM at address 65536, with the 48K snapshot following it, and resuming it using the CALL MODE 1 mechanism.</p>
<p>Just for fun, here are a few screenshots of the loading in action:</p>
<p><a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2007/01/dote.png" title="Defenders of the Earth"><img id="image38" src="http://blog.simonowen.com/wp-content/uploads/2007/01/dote.thumbnail.png" alt="Defenders of the Earth" /></a> <a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2007/01/pipemania.png" title="Pipemania"><img id="image39" src="http://blog.simonowen.com/wp-content/uploads/2007/01/pipemania.thumbnail.png" alt="Pipemania" /></a> <a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2007/01/f16combatpilot.png" title="F-16 Combat Pilot"><img id="image41" src="http://blog.simonowen.com/wp-content/uploads/2007/01/f16combatpilot.thumbnail.png" alt="F-16 Combat Pilot" /></a> <a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2007/01/shanghai.png" title="Shanghai"><img id="image40" src="http://blog.simonowen.com/wp-content/uploads/2007/01/shanghai.thumbnail.png" alt="Shanghai" /></a></p>
<p>Defenders of the Earth is a mammoth 21 minutes and 51 seconds long, which certainly makes you appreciate the disk version! <img src='http://simonowen.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://simonowen.com/blog/2007/01/11/simcoupe-tape-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vista icon update</title>
		<link>http://simonowen.com/blog/2006/12/17/vista-icon-update/</link>
		<comments>http://simonowen.com/blog/2006/12/17/vista-icon-update/#comments</comments>
		<pubDate>Sun, 17 Dec 2006 03:11:45 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[SimCoupe]]></category>
		<category><![CDATA[Vista]]></category>

		<guid isPermaLink="false">http://blog.simonowen.com/2006/12/17/vista-icon-update/</guid>
		<description><![CDATA[Vista includes support for 32-bit colour icons up to 256&#215;256 pixels in size &#8211; something Mac OS X has enjoyed for a while. They&#8217;re designed for high-DPI displays so they look too big on normal 96 dpi displays, but they do scale well to give quality smaller icons for normal use. The Mac version of [...]]]></description>
			<content:encoded><![CDATA[<p>Vista includes support for 32-bit colour icons up to 256&#215;256 pixels in size &#8211; something Mac OS X has enjoyed for a while.  They&#8217;re designed for high-DPI displays so they look too big on normal 96 dpi displays, but they do scale well to give quality smaller icons for normal use.</p>
<p>The Mac version of SimCoupe started with the 48&#215;48 Windows XP icon scaled up to 256&#215;256, which looked very out of place along side the 3D icons used by other applications.  I wanted a decent new icon for the SimCoupe 1.0 release but didn&#8217;t have the artistic talent to draw my own.  Rendering a 3D version seemed the way to go, so I downloaded the free <a href="http://www.blender.org/">Blender</a> package and got started.</p>
<p>Creating the basic robot shape wasn&#8217;t too difficult, with simple hemispheres for the head, body and feet.  The eyes and aerial were bezier curves pulled into shape and then filled.  I was lucky enough to find a hand model in an animation tutorial, which saved me a lot of work creating my own.</p>
<p>The neck, arms and legs were created using the <a href="http://www.blender.org/documentation/htmlI/x3040.html">screw</a> tool.  However, the arm segments were straight and needed to hang out from the body and round to the hands.  Getting them to curve took weeks of experimentation, but was eventually solved using armatures.  Inserting bones into the arms meant I could bend them to the shape I wanted in pose mode, with inverse kinematics (IK) doing all the work.  It&#8217;s not perfect, with a few kinks visible if you look closely, but it&#8217;s good enough!</p>
<p>To ensure the robot was symmetrical I built only the left half, with the right half created by cloning and mirroring it.  The images below show the left half as wireframe and filled, and the completed robot in wireframe mode. (click for full size):</p>
<p><a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2006/12/vista_mirroricon2.png" title="Half Robot Wireframe"><img id="image19" src="http://blog.simonowen.com/wp-content/uploads/2006/12/vista_mirroricon2.thumbnail.png" alt="Half Robot Wireframe" /></a> <a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2006/12/vista_mirroricon.png" title="Half Robot Solid"><img id="image20" src="http://blog.simonowen.com/wp-content/uploads/2006/12/vista_mirroricon.thumbnail.png" alt="Half Robot Solid" /></a> <a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2006/12/sam_wireframe.png" title="Wireframe Robot"><img id="image22" src="http://blog.simonowen.com/wp-content/uploads/2006/12/sam_wireframe.thumbnail.png" alt="Wireframe Robot" /></a></p>
<p>The final step was lighting, and I found another tutorial to help with that.  I used standard positions to evenly light the scene, knowing they could easily be changed later to fit any user interface guidelines for icon lighting.  The render took only a couple of seconds, and was saved out as a PNG image, preserving transparency where needed.  </p>
<p>Here&#8217;s the final 256&#215;256 image:</p>
<p><img id="image21" src="http://blog.simonowen.com/wp-content/uploads/2006/12/sam_256x256.png" alt="256x256 Render" /></p>
<p>At this point I created the Mac icon, importing directly from the PNG render to create the .icns file.  For the Vista version I needed to merge the new icon into the existing SimCoupe icon file, so the OS could choose which one to use.  XP wouldn&#8217;t recognise the new format and fall back to using the original smaller versions, which was perfect.</p>
<p>Rather surprisingly Vista uses the PNG format to store the new icon images in the file, and for a 256&#215;256 32-bit image that meant a huge space saving compared to the old format.  This downside was that none of the existing tools would recognise the new icon format, and that included the resource compiler used to build the SimCoupe executable! A 3rd party tool (<a href="http://www.rw-designer.com/compile-vista-icon">ReplaceVistaIcon</a>) came to the rescue, allowing the new icon to be injected into the executable after the build.</p>
<p>Here&#8217;s how the new icon compares to the original 48&#215;48 XP icon, using Vista&#8217;s large-icon view (click for full size):</p>
<p><a class="imagelink" href="http://blog.simonowen.com/wp-content/uploads/2006/12/vista_largeicon.png" title="SimCoupe Vista Icon"><img id="image16" src="http://blog.simonowen.com/wp-content/uploads/2006/12/vista_largeicon.thumbnail.png" alt="SimCoupe Vista Icon" /></a></p>
<p>Vista doesn&#8217;t use the new icon for everything though, falling back on the old icon in some situations (including the task list).  Hopefully that&#8217;s something I can improve as I learn more.</p>
]]></content:encoded>
			<wfw:commentRss>http://simonowen.com/blog/2006/12/17/vista-icon-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vista tweaks</title>
		<link>http://simonowen.com/blog/2006/12/16/vista-tweaks/</link>
		<comments>http://simonowen.com/blog/2006/12/16/vista-tweaks/#comments</comments>
		<pubDate>Sat, 16 Dec 2006 00:12:53 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[SimCoupe]]></category>
		<category><![CDATA[Vista]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.simonowen.com/2006/12/16/vista-tweaks/</guid>
		<description><![CDATA[I&#8217;ve had my eye on Vista since the beta versions were released earlier this year. So far only the SimCoupe 1.0 release in July has included Vista-specific changes. These were: Avoiding touching the primary display surface SimCoupe uses a video overlay surface for the SAM display by default, which gives the best performance on old [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had my eye on Vista since the beta versions were released earlier this year.  So far only the SimCoupe 1.0 release in July has included Vista-specific changes.  These were:</p>
<ol>
<li><strong>Avoiding touching the primary display surface</strong>
<p>SimCoupe uses a video overlay surface for the SAM display by default, which gives the best performance on old video cards.  For this I must determine a colour-key value where overlay pixels should show through to the display, like green-screen special effects used on TV.  This meant locking the primary surface to peek a pixel value, and that&#8217;s something Vista wasn&#8217;t happy with me doing.</p>
<p>In previous versions of Windows the primary display surface was what you saw on your screen, and where most objects were drawn directly.  Vista&#8217;s Aero interface uses off-screen compositing for its fancy scaling and transparency effects.  The visible display is managed by the compositing engine and is off-limits to direct manipulation.  Any attempts to do so disables the Desktop Window Manager (DWM), returning the display to a compatibility mode.  As part of this it also rather unhelpfully reports: &#8220;<em>This program is not compatible with Windows</em>&#8220;!</p>
<p>Video card overlays don&#8217;t really fit into the new composite world anyway.  They <em>can</em> be scaled, but they can&#8217;t be rotated or skewed, and don&#8217;t support transparency.  The DWM can&#8217;t make any use of them, so there&#8217;s little point in us trying to use them &#8211; problem solved!</p>
<p>SimCoupe no longer attempts to create a video overlay on Vista, and to avoid any confusion I also grey the setting in the options used to toggle it on and off.</li>
<li><strong>Avoid querying the capabilities of the primary display surface</strong>
<p>This is related to the first issue, but shouldn&#8217;t have been a problem at all.  I found that simply querying the capabilities of the primary surface (using <em>GetSurfaceDesc()</em>) was enough to disable the DWM.</p>
<p>This was confirmed to be a Windows bug in beta 1, scheduled to be fixed in beta 2.  In the meantime I changed my code to work around it, using the required capabilities from the back surface instead.</li>
<li><strong>Double-checking the main window is the correct size</strong>
<p>The partial scanlines on the boot screen were showing a banding effect, which happens if the main window is resized to non-multiple of the natural display size.  Further investigation showed the main window size (as set using <em>AdjustWindowRect()</em>) was slightly too small.</p>
<p>This was yet another Windows bug, and not one I found documented anywhere!  The size calculations didn&#8217;t seem to be including all the extra window decoration and the larger Vista borders were throwing it out.  This just required a second size adjustment in SimCoupe if the first one was found to be wrong.  This problem affected other programs that required an exact display size, which was mainly other emulators.</li>
</ol>
<p>These changes were the bare minimum needed to run the program correctly under Vista.  True Vista support will require additional changes, almost all related to the tightened security model.  More about those in a future update.</p>
]]></content:encoded>
			<wfw:commentRss>http://simonowen.com/blog/2006/12/16/vista-tweaks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project status update</title>
		<link>http://simonowen.com/blog/2006/12/15/project-status-update/</link>
		<comments>http://simonowen.com/blog/2006/12/15/project-status-update/#comments</comments>
		<pubDate>Fri, 15 Dec 2006 21:31:05 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[SamDisk]]></category>
		<category><![CDATA[SimCoupe]]></category>
		<category><![CDATA[fdrawcmd.sys]]></category>

		<guid isPermaLink="false">http://blog.simonowen.com/2006/12/15/project-status-update/</guid>
		<description><![CDATA[As this is my first entry, I thought it best to report where things are with the main projects: fdrawcmd.sys is almost unchanged since the 1.0.1.9 release in May, as there&#8217;s been nothing much to do. I&#8217;ve no outstanding issues to fix, and only a minor enhancement that wasn&#8217;t worth a new release. I&#8217;ve been [...]]]></description>
			<content:encoded><![CDATA[<p>As this is my first entry, I thought it best to report where things are with the main projects:</p>
<ol>
<li><a href="http://simonowen.com/fdrawcmd/"><strong>fdrawcmd.sys</strong></a> is almost unchanged since the 1.0.1.9 release in May, as there&#8217;s been nothing much to do.  I&#8217;ve no outstanding issues to fix, and only a minor enhancement that wasn&#8217;t worth a new release.
<p>I&#8217;ve been working on improving the driver installer, which will use the same NSIS setup as SimCoupe instead of my small custom installer.  This will give a more traditional install/uninstall process and include both  32-bit and 64-bit drivers in one download.  I&#8217;ll release a new version once it is complete, even if the embedded drivers don&#8217;t get updated from the previous release.</li>
<li><a href="http://www.simcoupe.org/"><strong>SimCoupe</strong></a> is also due a refresh build in the next month, mainly to improve Vista support.  I&#8217;ve done some minor enhancements and fixes to the main code branch, but only enough to make it version 1.01 rather than 1.1.
<p>I&#8217;ve made a start to bigger changes in a code branch, which largely involves separating the emulation+sound from the UI+video processing.  This should hopefully eliminate the occasional sound glitches from moving things over the main window, etc.  It should also do more to spread the workload on multi-core CPUs.  I also have some fragments of other features, including movie and sound recording.</li>
<li><a href="http://simonowen.com/sam/samdisk/"><strong>SamDisk</strong></a> has been neglected for a few months, despite having been close to a release for a while!  I&#8217;m happy with the core functionality, which does an excellent job with copy-protected and custom formatted disks (right to the limit of the PC controller&#8217;s ability).  I&#8217;ve still not decided on the list of disk image formats for the initial version, but it&#8217;ll certainly include EDSK, MGT, TRD, D81 and BPB (for normal PC disks).</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://simonowen.com/blog/2006/12/15/project-status-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
