<?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/"
	>

<channel>
	<title>So What Software</title>
	<atom:link href="http://sowhatsoftware.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://sowhatsoftware.com</link>
	<description>Advancing the ART of Assembly</description>
	<pubDate>Sun, 07 Feb 2010 22:26:28 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>UTF8 Encode/Decode Problems</title>
		<link>http://sowhatsoftware.com/?p=428</link>
		<comments>http://sowhatsoftware.com/?p=428#comments</comments>
		<pubDate>Sun, 07 Feb 2010 22:19:06 +0000</pubDate>
		<dc:creator>sowhat</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[ajax]]></category>

		<category><![CDATA[cookie]]></category>

		<category><![CDATA[decode]]></category>

		<category><![CDATA[endode]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[UTF8]]></category>

		<guid isPermaLink="false">http://sowhatsoftware.com/?p=428</guid>
		<description><![CDATA[I decided a bit late to make my new PHP project language aware. After designing a language system which consisted of a central text dispatcher and of course, language specific text files, or as was at first MySQL databases tables. (I switched to arrays instead of database tables to avoid &#8220;too many connections&#8221; errors.) It [...]]]></description>
			<content:encoded><![CDATA[<p>I decided a bit late to make my new PHP project language aware. After designing a language system which consisted of a central text dispatcher and of course, language specific text files, or as was at first MySQL databases tables. (I switched to arrays instead of database tables to avoid &#8220;too many connections&#8221; errors.) It works by basically maintaining a cookie with the desired language code and using that information to point to or more exactly, require the proper text array when text is needed in the webpage. All text data files are keyed by the language code: (mytextfile_en.php) for english etc… Most everything worked fine but not everything. Seems I had encoding problems with UTF8 in languages that use diacriticals and whatnot. I eventually solved this problem with two distinct alterations.</p>
<p>1. I went through the code and made sure each and every charset= declaration was utf8 (charset=utf8). This includes any ajax handlers both up and down paths. I was amazed at the various charset&#8217;s that were in my code, few if any were already utf8. iso-8859-1 and tis-620 were all over the place and are not really Unicode compatible. Once I got that all straightened out everything worked perfect… well almost perfect.</p>
<p>2. This brings us to solution #2. In situations where an ajax handler generated a pop-up list or even straight text from an array there was still an encode/decode problem. I fixed this by implicitly doing a utf8_encode() on the values in these arrays. In my code it looked like this: utf8_encode(getTxt(&#8217;TX1234&#8242;))… the TX1234 is an example of my own index code for the various text elements and the getTxt() is my text dispatcher. I did not have to do this force for any other method of text passing, only the ajax array generated text. Don&#8217;t really know exactly why this is, but it is, so there you are, and that&#8217;s it!</p>
]]></content:encoded>
			<wfw:commentRss>http://sowhatsoftware.com/?feed=rss2&amp;p=428</wfw:commentRss>
		</item>
		<item>
		<title>ZoomyDiv&#8230;</title>
		<link>http://sowhatsoftware.com/?p=407</link>
		<comments>http://sowhatsoftware.com/?p=407#comments</comments>
		<pubDate>Sun, 06 Dec 2009 09:00:12 +0000</pubDate>
		<dc:creator>sowhat</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[AutoCad]]></category>

		<category><![CDATA[CSS]]></category>

		<category><![CDATA[DOM]]></category>

		<category><![CDATA[HTML]]></category>

		<category><![CDATA[Illustrator]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[jQuery]]></category>

		<category><![CDATA[Photoshop]]></category>

		<category><![CDATA[W3C]]></category>

		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://sowhatsoftware.com/?p=407</guid>
		<description><![CDATA[ZoomyDiv is an image displayer for webpages that zooms images up to fit within the browser window. This is a stand-alone javascript/css program that does not require modules like Scriptalicious, Prototype, MooTools or other systems that have a very large footprint (byte count).
The software is pretty simple and well commented so the user can make [...]]]></description>
			<content:encoded><![CDATA[<p>ZoomyDiv is an image displayer for webpages that zooms images up to fit within the browser window. This is a stand-alone javascript/css program that does not require modules like Scriptalicious, Prototype, MooTools or other systems that have a very large footprint (byte count).</p>
<p>The software is pretty simple and well commented so the user can make custom modifications to suit their needs without too much fumbling around.</p>
<p><a href="http://sowhatsoftware.com/zoomydiv/index.html" target="_blank">Click here</a> to checkout the demo and download the code.</p>
]]></content:encoded>
			<wfw:commentRss>http://sowhatsoftware.com/?feed=rss2&amp;p=407</wfw:commentRss>
		</item>
		<item>
		<title>Chapter 3: Actual Disassembly (continued)</title>
		<link>http://sowhatsoftware.com/?p=368</link>
		<comments>http://sowhatsoftware.com/?p=368#comments</comments>
		<pubDate>Sun, 21 Jun 2009 22:00:56 +0000</pubDate>
		<dc:creator>sowhat</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://sowhatsoftware.com/?p=368</guid>
		<description><![CDATA[In the previous section of this chapter we examined the process of preparing relocatable code for disassembly. This section deals with the actual disassembly process.
For this discourse we are using a generic 65816 disassembler called D816 which does not know anything about the Apple IIgs. There are some special data structures unique to the Apple [...]]]></description>
			<content:encoded><![CDATA[<p>In the previous section of this chapter we examined the process of preparing relocatable code for disassembly. This section deals with the actual disassembly process.</p>
<p>For this discourse we are using a generic 65816 disassembler called D816 which does not know anything about the Apple IIgs. There are some special data structures unique to the Apple IIgs which need to be identified and formatted in order for the disassembled code to read correctly. These structures are the ProDOS, Prodos16 and GS/OS command calls.</p>
<p>Before we get to those, the other compensations you need to resolve is the register size directives, namely REP and SEP. In D816 this is handled by the insertion of REG tags which are invisible. At the very beginning of your disassembly you should insert a REG 00 which sets the disassembler to interpret 16 bit accumulator and 16 bit index registers (X and Y) or as is referred to as native mode . As REP&#8217;s or SEP&#8217;s come up in your disassembly you should set the appropriate REG insertions to make sure the following code interprets the proper size registers&#8230; this is very important!!! Once you have the REP&#8217;s and SEP&#8217;s defined you can go to the other funny structures of ProDOS8, ProDOS16 and GS/OS.</p>
<p><a href="http://sowhatsoftware.com/wp-content/uploads/2009/06/p8.gif"><img class="alignleft size-medium wp-image-379" style="margin: 10px;" title="p8" src="http://sowhatsoftware.com/wp-content/uploads/2009/06/p8-300x187.gif" alt="p8" width="300" height="187" /></a>The image to the left shows 4 panels the first of which shows an example of what the disassembler will output for a ProDOS8 command call. You need to identify these calls and give the trailing parameters (3 bytes) some tags to make the following disassembly read correctly as shown in panel 2. Panel 3 shows how the monitor displays the code. The monitor is savvy to these calls and formats it&#8217;s output to compensate for this inline data. Panel 4 shows how the final interpretation of this code should look for APW/ORCA.</p>
<p>ProDOS16 and GS/OS have the same inline structure and are similar to the ProDOS8 format but have 2 bytes for the command code and 4 bytes for the parameter table location (6 bytes in all).</p>
<p>The D816 disassembler has a little bug in where it does not discern between JSR (Jump to subroutine) and JSL (jump to subroutine long). All JSx commands are output as JSR, this is another little gotcha you will have to compensate for when disassembling AppleIIgs assembly code. ProDOS16 and GS/OS are identified by a JSL $E100A8 which is the main P16/GSOS dispatcher location. This will be followed by 6 bytes defining the call number and parameter table location.</p>
<p>Carefully start at the beginning of the code and make the needed tags for these commands as they appear one by one and your disassembly output will make more and more sense as you proceed.</p>
<p>Once you have all this stuff in order there will still be areas which look like nonsense in your output. This is pure data and can take any form depending on how the original programmer decided to place this stuff. Here&#8217;s where a little detective work comes in. You can check the Dos parameter table locations previously defined to begin to eliminate some of these areas by tagging the appropriate addresses as defined by the parameter table descriptions for the particular calls. This will eliminate the ambiguoity of some of this code but the remaining areas will need further analysis.</p>
<p>There are many parameter table structures in AppleIIgs code which can be Window or Dialog templates, color tables, lookup tables and so on. Finding Window or Dialog templates can be done by finding toolbox calls in you code which use these tables as input data line NewWindow or NewModalDialog ans as such. The data being pushed on the stack prior to these calls will indicate the location of these parameter tables. This is where the ProDOS/GSOS and Toolbox reference manuals become vital to successful disassembley.</p>
<p>After you have exhausted this analysis there will still be some remaining undefined locations. These will be local and global variables defined by the original programmer and you will have to tackle these one by on through reverse osmisis and intuition. I realize this sounds vague but that&#8217;s the nature of the beast which you can defeat with some careful dilligence and time. This is where you get into the naming of things which is all important in assembly. You may very well never get the same names as the original code had but this is not really important, what is important is the relationship between tags and addresses and not the actual name.</p>
<p>Once you have completely readable source code output in the disassembler it&#8217;s time to copy it out into TextMate where the real beautification and macroization takes place&#8230; we&#8217;re getting close now.</p>
<p>Next Post: Chapter 3:  Final Disassembly</p>
]]></content:encoded>
			<wfw:commentRss>http://sowhatsoftware.com/?feed=rss2&amp;p=368</wfw:commentRss>
		</item>
		<item>
		<title>APW-ORCA/M Framework for MacOSX</title>
		<link>http://sowhatsoftware.com/?p=326</link>
		<comments>http://sowhatsoftware.com/?p=326#comments</comments>
		<pubDate>Fri, 29 May 2009 23:03:16 +0000</pubDate>
		<dc:creator>sowhat</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[APW]]></category>

		<category><![CDATA[FrameWork]]></category>

		<category><![CDATA[Macros]]></category>

		<category><![CDATA[ORCA/M]]></category>

		<category><![CDATA[TextMate]]></category>

		<guid isPermaLink="false">http://sowhatsoftware.com/?p=326</guid>
		<description><![CDATA[
While dealing with editing my code in TextMate and uploading that to the GS emulator, certain things just begged for automation. Nothing too fancy, just some helpful utilities I have bundled into a framework of sorts. I call it the APW-ORCA/M Framework for MacOSX. It creates and manages projects written in ORCA/M assembly tailored for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sowhatsoftware.com/wp-content/uploads/2009/05/frameworkpic.gif"><img class="alignright size-medium wp-image-335" title="frameworkpic" src="http://sowhatsoftware.com/wp-content/uploads/2009/05/frameworkpic-300x225.gif" alt="frameworkpic" width="300" height="225" /></a></p>
<p>While dealing with editing my code in TextMate and uploading that to the GS emulator, certain things just begged for automation. Nothing too fancy, just some helpful utilities I have bundled into a framework of sorts. I call it the APW-ORCA/M Framework for MacOSX. It creates and manages projects written in ORCA/M assembly tailored for the AppleIIgs on MacOSX.</p>
<p>Download it: <a href="http://sowhatsoftware.com/downloads/APWFrameWork1.1.tar.gz"><span style="color: #ffff00;">(AWPFrameWork1.1.tar.gz)</span></a>.</p>
<p>I have apw_projects designated as my Apple IIgs assembly language folder so I would put APWFrameWork1.1.tar.gz in that folder, then change directory to that folder and issue a &#8220;tar -xzf APWFrameWork1.1.tar.gz&#8221;. This will install the framework. You can then delete the tar file &#8220;rm APWFrameWork1.1.tar.gz&#8221; to save space.</p>
<p>You&#8217;re ready to go, first thing is to read the _README file. That will show you how to use the framework properly.</p>
<p>Additionally __LIBRARY/APW-ORCA:M.tmbundle is provided, Click to install this assembly language environment bundle to TextMate. It provides color coded syntax which makes editing APW sourcecode much easier.</p>
<p><strong>Suggested TextMate settings:</strong></p>
<p>Choose &#8220;Sunset&#8221; theme.<br />
Set TAB SIZE = 15<br />
Set Preferences/Advanced:LineEndings to CR (Mac OS Classic).</p>
<p>The macro generator in the framework is especially handy for generating the macro files and way easier to use than the MACGEN method provided in APW. The libraries are as up to date as possible, including macros for Marinetti. Included as well are some program templates that make the most basic desktop application. Additional tricky or painful templates for popular functions will be included in future releases.</p>
<p>This framework is written in Perl because I am old school and I have been writing  in Perl for more than 15 years. I could have made it in PHP or Ruby but I&#8217;m better and quicker writing Perl&#8230; the results all wind up the same no matter which high level language you use. By the way&#8230; The underlying same-ness of languages is best viewed and understood from the assembly side of things.</p>
<p>I use this framework exclusively for all my IIgs programming projects and have found no bugs, but I&#8217;m sure someone out there will find some, it always happens.</p>
<p>As a final thought&#8230; If you have been reading along in these postings so far and don&#8217;t have APW or ORCA/M, squeeze out a couple bucks and get it here: <a href="https://store.syndicomm.com/"><span style="color: #ffff00;">(https://store.syndicomm.com/)</span></a> I&#8217;m sure &#8220;Sheppy&#8221; will be thrilled to send you a copy. You can get all the manuals there as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://sowhatsoftware.com/?feed=rss2&amp;p=326</wfw:commentRss>
		</item>
		<item>
		<title>Chapter 3: Disassembly, decoding OMF2 &amp; ExpressLoad</title>
		<link>http://sowhatsoftware.com/?p=277</link>
		<comments>http://sowhatsoftware.com/?p=277#comments</comments>
		<pubDate>Mon, 27 Apr 2009 05:43:18 +0000</pubDate>
		<dc:creator>sowhat</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Add new tag]]></category>

		<category><![CDATA[disassembly]]></category>

		<category><![CDATA[ExpressLoad]]></category>

		<category><![CDATA[GS/OS]]></category>

		<category><![CDATA[OMF2]]></category>

		<category><![CDATA[ProDOS16]]></category>

		<category><![CDATA[ProDOS8]]></category>

		<category><![CDATA[TextEdit]]></category>

		<category><![CDATA[TextMate]]></category>

		<guid isPermaLink="false">http://sowhatsoftware.com/?p=277</guid>
		<description><![CDATA[Although you probably want to create programs anew, and I&#8217;m with you there, knowing how to disassemble code is really important today with such an old system.
Much of the wisdom and the &#8220;knowing of things&#8221; is lost to time, it&#8217;s amazing how much gets discarded. The only real record is in the actual code itself, [...]]]></description>
			<content:encoded><![CDATA[<p>Although you probably want to create programs anew, and I&#8217;m with you there, knowing how to disassemble code is really important today with such an old system.</p>
<p>Much of the wisdom and the &#8220;knowing of things&#8221; is lost to time, it&#8217;s amazing how much gets discarded. The only real record is in the actual code itself, but you have to decode and decipher to regain that lost wisdom. Even with the most complete documentation library, many things are not still clear and having a good old working example goes miles to filling in those little what the hey&#8217;s.</p>
<p>Disassembly is the practice of decoding binary file images and producing a sourcefile. You could do this by hand, reading byte for byte and looking up the meaning of the byte as interpreted at the particular location in the code and translating that to the proper assembly syntax, and of course that would take &#8220;deep time&#8221; as the cosmologists would say.</p>
<p>A quicker way is to use a disassembler.</p>
<p>These come in all flavors, from the mundane to the sublime. I think I used to have a beta of the ORCA disassembler but that&#8217;s long gone, all I have left is the DISASM.data listing from it. I looked around the Internet and the only thing I could find was a Windows based disassembler for the 65816 called D816.</p>
<p>Now, D816 don&#8217;t know anything about Apple firmware, software and the like. It&#8217;s a generic 65816 disassembler knowing only the microprocessor opcodes and modes but we&#8217;re getting ahead of ourselves a bit here.</p>
<p>Let&#8217;s backup a notch and deal with the file some more.</p>
<p>The file you want to disassemble will be a <span style="color: #ccffcc;">ProDOS 8</span> binary file or relocatable <span style="color: #ccffcc;">OMF</span> type. Determining which is which will be vital to successful disassembly.</p>
<p>A <span style="color: #ccffcc;">ProDOS8</span> binary is filetype <span style="color: #ccffcc;">BIN($06)</span> but relocatables can be of several filetypes:</p>
<p><span style="color: #ccffcc;">GS/OS or ProDOS 16 application S16($B3)<br />
Shell application EXE($B5)<br />
Permanent initialization PIF($B6)<br />
Temporary initialization TIF($B7)<br />
New desk accessory NDA($B8)<br />
Classic desk accessory CDA($B9)<br />
Tool set files TOL($BA)<br />
Apple IIgs device drivers DVR($BB)<br />
Generic loadfile LDF($BC)<br />
GS/OS file system translator FST($BD)</span></p>
<p>If you want to disassemble a <span style="color: #ccffcc;">ProDOS8 BIN($06)</span> file then you can go straight to the disassembler, but if you want to do a relocatable filetype (<em>most likely</em>) you need to do some pre decoding, or de-OMFing.</p>
<p>Oh yeah, <span style="color: #ccffcc;">OMF</span> stands for Object Module Format which is basically how relocatable code it&#8217;s still done today, only the specifics have changed, the principle remains the same. All computer code must run at a specific location, it&#8217;s <span style="color: #ccffcc;">ORG</span>. In short, code needs to be relocatable when a robot such as the Toolboxes Memory Manager is in control. It relentlessly works to dole out and keep track of blocks of memory in the IIgs usually at the next most convenient location. It also compacts memory (<em>move things around to create larger available spaces</em>).</p>
<p>Because it chooses where a program will be initially loaded, the code needs to be installed at and re-written for that location.</p>
<p>Because it moves blocks of code around, the code in them has to be re-written to operate correctly at their new location.</p>
<p>That&#8217;s why a relocation scheme is necessary, in the case of the AppleIIgs that&#8217;s <span style="color: #ccffcc;">OMF2</span>.</p>
<p>Many of these filetypes can be stripped of <span style="color: #ccffcc;">OMF</span> segmentation by using the <span style="color: #ccffcc;">MAKEBIN</span> utility in <span style="color: #ccffcc;">APW</span> as long as you change the filetype to <span style="color: #ccffcc;">EXE($B5)</span>. If they are multi-segment or  <span style="color: #ccffcc;">ExpressLoad</span> type however, this trick will not work and <span style="color: #ccffcc;">MAKEBIN</span> will let you know. One thing about <span style="color: #ccffcc;">MAKEBIN</span> is that it will <span style="color: #ccffcc;">ORG</span> the code at <span style="color: #ccffcc;">$2000</span> instead of the normal disassembler <span style="color: #ccffcc;">ORG of $0</span>. Remember this difference for later on.</p>
<p>In tough cases what you need to do is a little hex editing of the file to remove and expand the necessary parts of the code. Many applications use just a few segment types while a few can use the entire list. You need to learn how to read <span style="color: #ccffcc;">OMF</span>, it&#8217;s not that bad but you will need a reference with the <span style="color: #ccffcc;">OMF</span> segments and headers described. I know this documentation exists in the <span style="color: #ccffcc;">GS/OS</span> Reference Manual and the <span style="color: #ccffcc;">APW</span> Reference Manual. It may also appear elsewhere.</p>
<div id="attachment_281" class="wp-caption alignleft" style="width: 160px"><a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm1.gif"><img class="size-medium wp-image-281" style="margin: 10px;" title="Figure#3.1" src="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm1-300x215.gif" alt="Figure#1" width="150" height="100" /></a><p class="wp-caption-text">Figure#3.1</p></div>
<p><a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm1.gif"><span style="color: #ffff00;">Figure#3.1</span></a> shows two HexEdit windows where the left one contains a straight <span style="color: #ccffcc;">OMF2</span> file and the right one contains an <span style="color: #ccffcc;">ExpressLoad</span> OMF type of file. The most noticeable difference is that the <span style="color: #ccffcc;">ExpressLoad</span> header is bigger&#8230; it even has the word <span style="color: #ccffcc;">ExpressLoad</span> in it&#8217;s header. De-OMFing either is done the same, it&#8217;s just that the header is different, the segment codes however are exactly the same.</p>
<p>I have highlighted the headers in blue for clarity this is Photoshop magic, although HexEdit can do this, it looks better when dolled up in Photoshop for web publication.</p>
<div id="attachment_286" class="wp-caption alignleft" style="width: 160px"><a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm2.gif"><img class="size-medium wp-image-286" style="margin: 10px;" title="Figure#3.2" src="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm2-300x215.gif" alt="Figure#2" width="150" height="100" /></a><p class="wp-caption-text">Figure#3.2</p></div>
<p>We&#8217;ll do the easier of the two by doing the <span style="color: #ccffcc;">OMF2</span> file on the left, CB.PRELAUNCH. After loading this file into HexEdit I open up a TextEdit window and make some zeroes&#8230; several lines of 32 zeroes each this corresponds to each line having 16 bytes ($10). These will be used for type <span style="color: #ccffcc;">$F1 (DS)</span> segments. See <a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm2.gif"><span style="color: #ffff00;">Figure#3.2</span></a>.<br />
.<br />
.<br />
.<br />
.<br />
.</p>
<div id="attachment_289" class="wp-caption alignleft" style="width: 160px"><a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm3.gif"><img class="size-medium wp-image-289" style="margin: 10px;" title="Figure#3.3" src="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm3-300x215.gif" alt="Figure#3" width="150" height="100" /></a><p class="wp-caption-text">Figure#3.3</p></div>
<p>Now that I am setup for decoding OMF lets take a look at exactly what we are up against. <a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm3.gif"><span style="color: #ffff00;">Figure#3.3</span></a> shows CB.PRELAUNCH with all important regions color coded. <span style="color: #00ffff;">Blue </span>is the <span style="color: #ccffcc;">header</span> and trailing zeroes, <span style="color: #00ff00;">Green</span> is <span style="color: #ccffcc;">LCONST</span> segment headers, <span style="color: #ff6600;">Orange</span> is <span style="color: #ccffcc;">DS</span> segment headers, <span style="color: #ff00ff;">Purple</span> is the <span style="color: #ccffcc;">relocation dictionary</span> and <span style="color: #ffff00;">yellow</span> is <span style="color: #ccffcc;">static code</span> bytes (<em>what we are after here</em>). I picked this file because it is simple and also because it will fit on one screen, most programs are a bit bigger than this one.</p>
<p>The key skill involved with this in my opinion is &#8220;pattern recognition&#8221;, much like as is dramatized in the movie &#8220;A Beautiful Mind&#8221;. Just remember to never interact with those imaginary people!</p>
<p>The first 64($40) bytes are the header, it has a lot of 00 and 20&#8217;s (<em>spaces</em>) all that information means something but for our purposes only one bit is of interest. 8 bytes in there is the pattern <span style="color: #ccffcc;">&#8220;7C 02 00 00&#8243;</span>. This is the finished length of the file contained, make a note of this. If you are new to the IIgs, numbers are stored in memory in reverse order what is really being represented is a 4 byte value (<em>long</em>) <span style="color: #ccffcc;">&#8220;00 00 02 7C&#8221;</span> or just plain <span style="color: #ccffcc;">&#8220;27C&#8221;</span> ignoring the leading zeroes. That&#8217;s a number represented in hexidecimal and after a quick tap on the calculator the file will be <span style="color: #ccffcc;">636</span> decimal bytes long. You could of course do this conversion in your head if you were painfully smart. Personaly, I need my calculator set to programmer.</p>
<div id="attachment_312" class="wp-caption alignleft" style="width: 160px"><a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm41.gif"><img class="size-medium wp-image-312" style="margin: 10px;" title="Figure#3.4" src="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm41-300x215.gif" alt="Figure#3.4" width="150" height="100" /></a><p class="wp-caption-text">Figure#3.4</p></div>
<p>After the header there is another pattern <span style="color: #ccffcc;">&#8220;F2 A2 01 00 00&#8243;</span>&#8230; a five byte pattern. This is an <span style="color: #ccffcc;">LCONST($F2)</span> segment header. Once again make note of the last four bytes, they are the length of bytes to follow that contain static program code.  Here we go&#8230; Select the first <span style="color: #ccffcc;">69($45)</span> bytes which is the header and this segment header and delete them!</p>
<p>Now, index in <span style="color: #ccffcc;">$1A2</span> bytes and you will find another pattern: <span style="color: #ccffcc;">&#8220;F1 9A 00 00 00&#8243;</span> immediately followed by another pattern <span style="color: #ccffcc;">&#8220;F2 40 00 00 00&#8243;</span>. This is a <span style="color: #ccffcc;">DS</span> segment header followed by another <span style="color: #ccffcc;">LCONST </span>segment header. The <span style="color: #ccffcc;">DS</span> header says to insert <span style="color: #ccffcc;">$9A(154)</span> zeroes at that point in the code. Go to the TextEdit window with the zeroes and highlight <span style="color: #ccffcc;">$9A</span> of them, hit</p>
<div id="attachment_314" class="wp-caption alignleft" style="width: 160px"><a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm5.gif"><img class="size-medium wp-image-314" style="margin: 10px;" title="Figure#3.5" src="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm5-300x215.gif" alt="Figure#3.5" width="150" height="100" /></a><p class="wp-caption-text">Figure#3.5</p></div>
<p>copy and then highlight both of these headers in HexEdit (<em>10 bytes</em>) and hit paste. See <a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm4.gif"><span style="color: #ffff00;">Figure#3.4</span></a> and <a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm5.gif"><span style="color: #ffff00;">Figure#3.5</span></a>.</p>
<p>Now we&#8217;re nearly there, see&#8230; I told you it would not be real hard. The last thing to do because we are all out of construction segments is to highlight and remove the relocation dictionary and trailing spaces <a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm6.gif"><span style="color: #ffff00;">Figure#3.6</span></a>. On most code, that&#8217;s all there is to it except for their being more <span style="color: #ccffcc;">DS</span> followed by <span style="color: #ccffcc;">LCONST</span> headers in the code, do them one by one in sequence and you will not have any problems.</p>
<p>.</p>
<div id="attachment_317" class="wp-caption alignleft" style="width: 160px"><a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm6.gif"><img class="size-medium wp-image-317" style="margin: 10px;" title="Figure#3.6" src="http://sowhatsoftware.com/wp-content/uploads/2009/04/disasm6-300x215.gif" alt="Figure#3.6" width="150" height="100" /></a><p class="wp-caption-text">Figure#3.6</p></div>
<p><span style="color: #ccffcc;">INTERSEG</span> headers can appear when the program is broken down into multiple load segments where each segment has it&#8217;s own relocation dictionary, you will come across <span style="color: #ccffcc;">INTERSEG</span> headers and special relocation headers which have to be dealt with differently. Read up about these segments and it will all become clear. Now you have a properly constructed binary image of the file <span style="color: #ccffcc;">ORG</span>ed at <span style="color: #ccffcc;">$0</span>&#8230; perfect! Save this away to disk as <span style="color: #ccffcc;">CBPRE.BIN</span> and get ready to stick it in the disassembler.</p>
<p>The next chapter will be a continuation of this chapter but it will actually deal with authentic disassembly, the meat and potatoes of the process, until then try this out a bit and get a feel for relocatable architecture.</p>
<p>As a side note here, if you have the ORCA disassembler then you really don&#8217;t need to do any of this stuff because ORCA knows how to read OMF along with a bunch of other stuff and does all this cutting and pasting for you automatically. I just though it would be good background on what&#8217;s really happening when you load a relocatable file by telling you this at the end of this section rather than before where you might tend to skip over this vital information.</p>
<p>Next Post: Chapter 3 (<em>cont.</em>): Actual disassembly</p>
]]></content:encoded>
			<wfw:commentRss>http://sowhatsoftware.com/?feed=rss2&amp;p=277</wfw:commentRss>
		</item>
		<item>
		<title>Slight interruption&#8230;</title>
		<link>http://sowhatsoftware.com/?p=260</link>
		<comments>http://sowhatsoftware.com/?p=260#comments</comments>
		<pubDate>Wed, 22 Apr 2009 02:35:53 +0000</pubDate>
		<dc:creator>sowhat</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Assembly Language]]></category>

		<category><![CDATA[CallBox]]></category>

		<category><![CDATA[Macros]]></category>

		<guid isPermaLink="false">http://sowhatsoftware.com/?p=260</guid>
		<description><![CDATA[I know we&#8217;re talking assembly language here and something has come to light and needs to be disseminated to the Apple IIgs user base post haste. Back in 1990 when So What Software closed it&#8217;s doors, we were unaware of GS/OS version 6 because it was not out yet. It appears to make our flagship [...]]]></description>
			<content:encoded><![CDATA[<p>I know we&#8217;re talking assembly language here and something has come to light and needs to be disseminated to the Apple IIgs user base post haste. Back in 1990 when So What Software closed it&#8217;s doors, we were unaware of GS/OS version 6 because it was not out yet. It appears to make our flagship software product &#8220;Call Box&#8221; crash!!! After a bit of digging, disassembling and help from key old timers such as Dave Lyons I have found the problem, which in reality is a big one, but fixable. It all has to do with Memory Manager master pointer records and tools and the way I abuse them in that software. I quickly made a patch which will allow Call Box version 2.0 to operate under GS/OS version 6.xx.</p>
<p>Seeing that this is a discourse on assembly language and toolbox programming I have posted the sourcecode and macros for the patch so that you can get some APW time right off the bat with pre-debugged source. Just some simple copying, pasting, assembling and linking.</p>
<p>I realize that you can count the number of 65816 programmers on one hand these days so I have included the compiled patch as well. This image also includes the file BASIC.LAUNCHER which Apple cleverly removed from the 6.0.X release of the System Disk. This file is necessary for launching Call Box BASIC programs from the Call Box Launching Shell.</p>
<p><span style="color: #ffff00;"><a href="http://sowhatsoftware.com/downloads/FIXCB.img"><span style="color: #ffff00;">Download: FIXCB.img</span></a></span></p>
<p><strong>Sourcecode:</strong></p>
<pre><span style="color: #00ff00;">               <span style="color: #3366ff;">GEN ON</span>
               <span style="color: #ffff00;">LIST ON
               SYMBOL ON
               ABSADDR ON</span>
               <span style="color: #3366ff;">MCOPY</span> <span style="color: #ffffff;">fixcb.mac</span>
               <span style="color: #ffff00;">KEEP</span> <span style="color: #ffffff;">fixcb</span>
               <span style="color: #ffff00;">ORG</span> <span style="color: #cc99ff;">$2000</span>
<em><span style="color: #999999;">;------------------------------------------------
; This patch is for Call Box Version 2.0 only!!!!
;
; This patch fixes the Master Pointer Block Bug
; found when operating CB 2.0 under GS/OS V6.XX
;
; This patch is quite fragile and is intended as
; a temporary fix until the new version 3.0 is
; released later in 2009.
;
; By William Stephens 04.10.2009
;------------------------------------------------</span></em>

<span style="color: #ffffff;">PatchLocation</span> <span style="color: #ffff00;">gequ</span> <span style="color: #cc99ff;">$84   </span>               <em><span style="color: #999999;">;V2.0 specific</span></em>
<span style="color: #ffffff;">PatchValue</span>    <span style="color: #ffff00;">gequ</span> <span style="color: #cc99ff;">$CC</span>                  <em><span style="color: #999999;">;New value, original is 0600</span></em>
<span style="color: #ffffff;">PatchValue1</span>   <span style="color: #ffff00;">gequ</span> <span style="color: #cc99ff;">$13</span>                  <em><span style="color: #999999;">;VERY HARDWIRED *** DANGER ***</span></em>
<span style="color: #ffffff;">FileLength</span>    <span style="color: #ffff00;">gequ</span> <span style="color: #cc99ff;">$602A</span>                <em><span style="color: #999999;">;V2.0 specific</span></em>
<span style="color: #ffffff;">OpenBuf</span>       <span style="color: #ffff00;">gequ</span> <span style="color: #cc99ff;">$1C00</span>                <em><span style="color: #999999;">;4 page DOS buffer</span></em>
<span style="color: #ffffff;">HexOut</span>        <span style="color: #ffff00;">gequ</span> <span style="color: #ff00ff;"><span style="color: #cc99ff;">$FDDA</span> </span>               <em><span style="color: #999999;">;Print a hex byte</span></em>
<span style="color: #ffffff;">C</span>             <span style="color: #ffff00;">gequ</span> <span style="color: #cc99ff;">$43 </span>                 <em><span style="color: #999999;">;ASCII "C"</span></em>
<span style="color: #ffffff;">B</span>             <span style="color: #ffff00;">gequ</span> <span style="color: #cc99ff;">$42 </span>                 <em><span style="color: #999999;">;ASCII "B"</span></em>
<span style="color: #ffffff;">Indexer</span>       <span style="color: #ffff00;">gequ</span> <span style="color: #cc99ff;">$F8</span>                  <em><span style="color: #999999;">;Zero page indexer</span></em>

<span style="color: #ffffff;">Begin</span>         <span style="color: #ffff00;">START</span>
              <span style="color: #ffff00;">OBJ</span> <span style="color: #cc99ff;">$2000</span>
              <span style="color: #ff9900;">sec</span>
              <span style="color: #ff9900;">xce</span>
              <span style="color: #ff9900;">sep</span> <span style="color: #00ccff;">#$30</span>
              <span style="color: #ffff00;">longa</span> <span style="color: #ffff00;">off</span>
              <span style="color: #ffff00;">longi</span> <span style="color: #ffff00;">off</span>

<em><span style="color: #999999;">;-- Make the full pathname ----------------------</span></em>
              <span style="color: #3366ff;">_P8:Get_Prefix</span> <span style="color: #ffffff;">GetPrefixPrm</span>
              <span style="color: #ff9900;">tax</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#0</span>
              <span style="color: #ff0000;">bcs</span> <span style="color: #ffffff;">errnxt</span>

              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#PathBuf</span>
              <span style="color: #ff9900;">sta</span> <span style="color: #ffffff;">Indexer</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#&gt;Pathbuf</span>
              <span style="color: #ff9900;">sta</span> <span style="color: #ffffff;">Indexer+1</span>
              <span style="color: #ff9900;">ldy</span> <span style="color: #ffffff;">PathLen</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#C</span>
              <span style="color: #ff9900;">sta</span> <span style="color: #ffffff;">(Indexer),y</span>
              <span style="color: #ff9900;">iny</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#B</span>
              <span style="color: #ff9900;">sta</span> <span style="color: #ffffff;">(Indexer),y</span>
              <span style="color: #ff9900;">iny</span>
              <span style="color: #ff9900;">sty</span> <span style="color: #ffffff;">PathLen</span>

<em><span style="color: #999999;">;-- Fix the file access bits --------------------</span></em>
              <span style="color: #3366ff;">_P8:Get_File_Info</span> <span style="color: #ffffff;">FilePrm</span>
              <span style="color: #ff9900;">tax</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#1</span>
              <span style="color: #ff0000;">bcs</span> <span style="color: #ffffff;">error</span>

              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#35</span>                  <em><span style="color: #999999;">;Set to __BWR</span></em>
              <span style="color: #ff9900;">sta</span> <span style="color: #ffffff;">FileAccess</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#7</span>
              <span style="color: #ff9900;">sta</span> <span style="color: #ffffff;">FilePrm</span>
              <span style="color: #3366ff;">_P8:Set_File_Info</span> <span style="color: #ffffff;">FilePrm</span>
              <span style="color: #ff9900;">tax</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#2</span>
<span style="color: #ffffff;">errnxt</span>        <span style="color: #ff0000;">bcs</span> <span style="color: #ffffff;">error</span>

<em><span style="color: #999999;">;-- Open the file -------------------------------</span></em>
              <span style="color: #3366ff;">_P8:Open</span> <span style="color: #ffffff;">OpenPrm</span>
              <span style="color: #ff9900;">tax</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#3</span>
              <span style="color: #ff0000;">bcs</span> <span style="color: #ffffff;">error</span>

<em><span style="color: #999999;">;-- Pass the reference number -------------------</span></em>
              <span style="color: #ff9900;">lda</span> <span style="color: #ffffff;">Orefnum</span>
              <span style="color: #ff9900;">sta</span> <span style="color: #ffffff;">Crefnum</span>
              <span style="color: #ff9900;">sta</span> <span style="color: #ffffff;">Rrefnum</span>
              <span style="color: #ff9900;">sta</span> <span style="color: #ffffff;">SMrefnum</span>

<em><span style="color: #999999;">;-- Read the file into the buffer ---------------</span></em>
              <span style="color: #3366ff;">_P8:Read</span> <span style="color: #ffffff;">ReadPrm</span>
              <span style="color: #ff9900;">tax</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#4</span>
              <span style="color: #ff0000;">bcs</span> <span style="color: #ffffff;">error</span>

<em><span style="color: #999999;">;-- Do the patch --------------------------------</span></em>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#Image</span>
              <span style="color: #ff9900;">sta</span> <span style="color: #ffffff;">Indexer</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#&gt;Image</span>
              <span style="color: #ff9900;">sta</span> <span style="color: #ffffff;">Indexer+1</span>
              <span style="color: #ff9900;">ldy</span> <span style="color: #00ccff;">#PatchLocation</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#PatchValue</span>
              <span style="color: #ff9900;">sta</span> <span style="color: #ffffff;">(Indexer),y</span>
              <span style="color: #ff9900;">iny</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#PatchValue1</span>
              <span style="color: #ff9900;">sta</span> <span style="color: #ffffff;">(Indexer),y</span>

<em><span style="color: #999999;">;-- Reposition to the start of file -------------</span></em>
              <span style="color: #3366ff;">_P8:Set_Mark</span> <span style="color: #ffffff;">SetMarkPrm</span>
              <span style="color: #ff9900;">txa</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#5</span>
              <span style="color: #ff0000;">bcs</span> <span style="color: #ffffff;">error</span>

<em><span style="color: #999999;">;-- Write the file back to itself ---------------</span></em>
              <span style="color: #3366ff;">_P8:Write</span> <span style="color: #ffffff;">ReadPrm</span>
              <span style="color: #ff9900;">tax</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#6</span>
              <span style="color: #ff0000;">bcs</span> <span style="color: #ffffff;">error</span>

<em><span style="color: #999999;">;-- Close the file ------------------------------</span></em>
              <span style="color: #3366ff;">_P8:Close</span> <span style="color: #ffffff;">ClosePrm</span>

<em><span style="color: #999999;">;-- Fix the file access bits --------------------</span></em>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#33</span>                 <em><span style="color: #999999;">;Set to __B_R</span></em>
              <span style="color: #ff9900;">sta</span> <span style="color: #ffffff;">FileAccess</span>
              <span style="color: #3366ff;">_P8:Set_File_Info</span> <span style="color: #ffffff;">FilePrm</span>
              <span style="color: #ff9900;">tax</span>
              <span style="color: #ff9900;">lda</span> <span style="color: #00ccff;">#7</span>
              <span style="color: #ff0000;">bcs</span> <span style="color: #ffffff;">error</span>

<em><span style="color: #999999;">;-- Patching finished ---------------------------</span></em>
              <span style="color: #ff0000;">rts</span>

<em><span style="color: #999999;">;-- Error handler -------------------------------</span></em>
<span style="color: #ffffff;">error</span>         <span style="color: #ff0000;">jsr</span> <span style="color: #ffffff;">HexOut</span>                <em><span style="color: #999999;">;Display command#/error#</span></em>
              <span style="color: #ff9900;">txa</span>
              <span style="color: #ff0000;">jsr</span> <span style="color: #ffffff;">HexOut</span>
              <span style="color: #ff0000;">rts</span>

<em><span style="color: #999999;">;-- Parameter tables and data -------------------</span></em>
<span style="color: #ffffff;">SetMarkPrm</span>    <span style="color: #ffff00;">dc i1</span>'2'
<span style="color: #ffffff;">SMrefnum</span>      <span style="color: #ffff00;">dc i1</span>'0'
              <span style="color: #ffff00;">dc i3</span>'0'

<span style="color: #ffffff;">FilePrm</span>       <span style="color: #ffff00;">dc i1</span>'10'
              <span style="color: #ffff00;">dc i</span>'PathLen'
<span style="color: #ffffff;">FileAccess</span>    <span style="color: #ffff00;">dc i1</span>'0'
              <span style="color: #ffff00;">dc i1</span>'0'
              <span style="color: #ffff00;">dc i</span>'0'
              <span style="color: #ffff00;">dc i1</span>'0'
              <span style="color: #ffff00;">dc i</span>'0'
              <span style="color: #ffff00;">dc i</span>'0'
              <span style="color: #ffff00;">dc i</span>'0'
              <span style="color: #ffff00;">dc i</span>'0'
              <span style="color: #ffff00;">dc i</span>'0'

<span style="color: #ffffff;">OpenPrm</span>       <span style="color: #ffff00;">dc i1</span>'3'
              <span style="color: #ffff00;">dc i</span>'PathLen'
              <span style="color: #ffff00;">dc i</span>'OpenBuf'
<span style="color: #ffffff;">Orefnum</span>       <span style="color: #ffff00;">dc i1</span>'0'

<span style="color: #ffffff;">ClosePrm</span>      <span style="color: #ffff00;">dc i1</span>'1'
<span style="color: #ffffff;">Crefnum</span>       <span style="color: #ffff00;">dc i1</span>'0'

<span style="color: #ffffff;">GetPrefixPrm</span>  <span style="color: #ffff00;">dc i1</span>'1'
              <span style="color: #ffff00;">dc i</span>'PathLen'

<span style="color: #ffffff;">ReadPrm</span>       <span style="color: #ffff00;">dc i1</span>'4'
<span style="color: #ffffff;">Rrefnum</span>       <span style="color: #ffff00;">dc i1</span>'0'
              <span style="color: #ffff00;">dc i</span>'Image'
              <span style="color: #ffff00;">dc i</span>'FileLength'
              <span style="color: #ffff00;">dc i</span>'0'

<span style="color: #ffffff;">PathLen</span>       <span style="color: #ffff00;">dc i1</span>'0'
<span style="color: #ffffff;">PathBuf</span>       <span style="color: #ffff00;">ds</span> <span style="color: #ffffff;">63</span>

<span style="color: #ffffff;">Image</span>         <span style="color: #ffff00;">ds</span> <span style="color: #ffffff;">FileLength</span>

              <span style="color: #ffff00;">END</span></span></pre>
<p><strong>Macros:</strong></p>
<pre><span style="color: #00ff00;"> MACRO
&amp;lab _P8:Get_Prefix &amp;params
&amp;lab jsr $BF00
 dc i1"$C7"
 dc i2"&amp;params"
 MEND
 MACRO
&amp;lab _P8:Get_File_Info &amp;params
&amp;lab jsr $BF00
 dc i1"$C4"
 dc i2"&amp;params"
 MEND
 MACRO
&amp;lab _P8:Set_File_Info &amp;params
&amp;lab jsr $BF00
 dc i1"$C3"
 dc i2"&amp;params"
 MEND
 MACRO
&amp;lab _P8:Open &amp;params
&amp;lab jsr $BF00
 dc i1"$C8"
 dc i2"&amp;params"
 MEND
 MACRO
&amp;lab _P8:Read &amp;params
&amp;lab jsr $BF00
 dc i1"$CA"
 dc i2"&amp;params"
 MEND
MACRO
&amp;lab _P8:Set_Mark &amp;params
&amp;lab jsr $BF00
 dc i1"$CE"
 dc i2"&amp;params"
 MEND
 MACRO
&amp;lab _P8:Write &amp;params
&amp;lab jsr $BF00
 dc i1"$CB"
 dc i2"&amp;params"
 MEND
 MACRO
&amp;lab _P8:Close &amp;params
&amp;lab jsr $BF00
 dc i1"$CC"
 dc i2"&amp;params"
 MEND</span></pre>
<p>Once you have this assembled and linked as a P8 binary file named &#8220;FIXCB&#8221;, put it in the directory with the file CB (the Call Box BASIC engine) and type BRUN FIXCB. Also, put the file BASIC.LAUNCHER in you root directory.</p>
<p>That should fix up your Call Box installation for now.</p>
<p>Call Box version 2.0 is freely downloadable from this site, simply visit <a href="http://sowhatsoftware.com/?page_id=80">The Call Box TPS page</a>. There you will find the 2.0 installation set, Programmers association disks and the all important manual.</p>
<p>&#8211;William Stephens</p>
<p>Chapter 3 will be posted soon&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://sowhatsoftware.com/?feed=rss2&amp;p=260</wfw:commentRss>
		</item>
		<item>
		<title>Chapter 2: Dealing with files</title>
		<link>http://sowhatsoftware.com/?p=214</link>
		<comments>http://sowhatsoftware.com/?p=214#comments</comments>
		<pubDate>Wed, 08 Apr 2009 23:55:17 +0000</pubDate>
		<dc:creator>sowhat</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Disk Utility]]></category>

		<category><![CDATA[HFS]]></category>

		<category><![CDATA[Transfer]]></category>

		<guid isPermaLink="false">http://sowhatsoftware.com/?p=214</guid>
		<description><![CDATA[Using an emulation development enviroment for the Apple IIgs presents some unique problems when dealing with files.
Transfer Disk
First things first, you&#8217;ll want a transfer disk to get things from the Mac to the IIgs emulator and back again. This can be simply done by going to Applications/Utilities/Disk Uility on you Mac and click &#8220;New Image&#8221;. [...]]]></description>
			<content:encoded><![CDATA[<p>Using an emulation development enviroment for the Apple IIgs presents some unique problems when dealing with files.</p>
<div id="attachment_245" class="wp-caption alignleft" style="width: 160px"><a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/diskutil.png"><img class="size-medium wp-image-245" style="margin: 4px 10px;" title="Figure#2.1" src="http://sowhatsoftware.com/wp-content/uploads/2009/04/diskutil-300x258.png" alt="diskutil" width="150" height="100" /></a><p class="wp-caption-text">Figure#2.1</p></div>
<p><strong>Transfer Disk</strong><br />
First things first, you&#8217;ll want a transfer disk to get things from the Mac to the IIgs emulator and back again. This can be simply done by going to Applications/Utilities/Disk Uility on you Mac and click &#8220;New Image&#8221;. Make the &#8220;Save as&#8221; and &#8220;Volume name&#8221; the same thing as in this example &#8220;transfer&#8221;. Use a volume size of 100Meg.. nice round figure. Volume Format should be Mac OS Extended (journaled). Encryption: none, Partitions: single partition and Image format: read/write disk image. Once these settings are made click &#8220;Create&#8221; and a transfer.dmg will be created in the location you specified by setting the &#8220;Save as&#8221;. If that image got mounted somehow,  unmount it.</p>
<div id="attachment_242" class="wp-caption alignright" style="width: 160px"><a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/transfer.png"><img class="size-medium wp-image-242" style="margin: 4px 10px;" title="Figure#2.2" src="http://sowhatsoftware.com/wp-content/uploads/2009/04/transfer-300x197.png" alt="transfer" width="150" height="100" /></a><p class="wp-caption-text">Figure#2.2</p></div>
<p>You&#8217;re done with this phase so close down Disk Utility and open up your emulator, mount your GSOS, start it up and mount the transfer.dmg you just created. GSOS will complain that it can not read the disk and it want&#8217;s to format it. Select HFS and Format the disk. It will now appear as a 3.5&#8243; disk on the GSOS desktop even though it&#8217;s 100meg.</p>
<p>You can now drag and drop files to it or from it in either GSOS or OSX as long as only one of the OS&#8217;s have it mounted and any given time. Having both GSOS and OSX mount the dmg at the same time causes havoc!</p>
<p><strong>Source to TextMate, TextMate to Source</strong><br />
TextMate is the main text editor used in this configuration and a few simple things need to be addressed. On the GS/OS side of things we are using APW/ORCA for the generation of binaries and executables used by the Apple IIgs.</p>
<p>The first transfer (<em>Source to TextMate</em>) is pretty simple, From the AppleIIgs, mount the transfer disk and drag and drop the sourcefile(s) into it, drag the disk to the AppleIIgs trash to eject (unmount) the disk. From the Mac, mount the transfer disk and drag and drop the sourcefile to your working directory. That&#8217;s about it, you can now open this file with TextMate and edit away.</p>
<p>The second transfer (<em>TextMate to Source</em>) is a little more complicated. The default Line ending in TextMate is a line feed (LF - $0A), APW/ORCA on the other hand uses carriage returns (CR - $0D). If you attempt to open up a line feed version with the APW Editor it thinks it&#8217;s a single long string of characters and will fail. In TextMate, select &#8220;TextMate/Preferences/Advanced&#8221; and in this dialog you will see a selector for &#8220;Line Endings&#8221;. Set this selector to &#8220;CR (Mac OS Classic)&#8221;. This will solve this little problem. To make sure this is happening you can open up the file in HexEdit, look for the $0A or $0D at the end of text lines. If you find $0A then you can search for $0A and replace with $0D globally to fix the difference.</p>
<div id="attachment_258" class="wp-caption alignleft" style="width: 160px"><a href="http://sowhatsoftware.com/wp-content/uploads/2009/04/fileutil2.png"><img class="size-medium wp-image-258" style="margin: 4px 10px;" title="Figure#2.3" src="http://sowhatsoftware.com/wp-content/uploads/2009/04/fileutil2-300x187.png" alt="fileutil2" width="150" height="100" /></a><p class="wp-caption-text">Figure#2.3</p></div>
<p>In the Mac, mount the transfer disk and drag and drop the source file in it, then unmount the transfer disk then from the AppleIIgs, mount the transfer disk and drag and drop the file to the APW sourcecode folder. At this point you would think your all done but this is not the case. This file is not a filetype $B0(SRC), auxtype $0003(ASM65816) identified file and APW will not recognize it. You need to change the filetype and auxtype on the file before it&#8217;s official. I use the File Utility in Call Box to accomplish this, there are other file utilities and byte zappers that can do this as well, that&#8217;s up to you.</p>
<p>A simpler but much slower method is to copy the source in TextMate (<em>select all</em>) and with Sweet16 up and running the APW Editor, with a new blank document named the same as the sourcefile, you can use the File/Paste function of Sweet16 to write the file into the blank document. Once the APW Editor saves this file, the type and subtype will be the correct kinds and you will not have to worry about the line feeds and carriage returns.</p>
<p>You can also use the Sweet16 paste command to great advantage with Applesoft code. Copy the Applesoft code you have in TextMate and have the emulator up and running. Goto Applesoft BASIC environment (once again I use the Call Box Launchung Shell for this purpose). From the ProDOS8 command line type &#8220;NEW&#8221; and then use the Sweet16 paste command to write the Applesoft into the interpreter. Once done, &#8220;SAVE&#8221; the file and that&#8217;s it!</p>
<p>Going the other way however is not as easy. Applesoft is a tokenized language where all it&#8217;s commands are not the text of the command but are instead single byte values (the tokens) not to mention the linked list bytes. A straight binary copy as I have been discussing so far will result in a whacky, mostly unreadable file in TextMate. This is because you would be looking at the encoded version that only Applesoft interpreters can read. Sweet16 has a command that can overcome this conundrum. It&#8217;s the &#8220;Capture Text Screen&#8221; command in the File menu. What you do is LIST the file on the screen, Capture the text and then paster into TextMate. This is easier to say than it is in practice.</p>
<p>What gets pasted into TextMate is the characters that make up the screen display of the IIgs including all the trailing spaces and whatnot, a rectangle of characters. You need to carefully use the LIST command to limit what&#8217;s displayed because even modest Applesoft programs are more than the screen height and scroll by if LISTed without limits. In textMate you will need to remove all those trailing spaces but TextMate is good at things like that.</p>
<p>Next post - Chapter 3: Disassembly</p>
]]></content:encoded>
			<wfw:commentRss>http://sowhatsoftware.com/?feed=rss2&amp;p=214</wfw:commentRss>
		</item>
		<item>
		<title>Chapter 1: The programming environment</title>
		<link>http://sowhatsoftware.com/?p=177</link>
		<comments>http://sowhatsoftware.com/?p=177#comments</comments>
		<pubDate>Thu, 26 Mar 2009 21:43:33 +0000</pubDate>
		<dc:creator>sowhat</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[AppleworksGS]]></category>

		<category><![CDATA[APW]]></category>

		<category><![CDATA[D816]]></category>

		<category><![CDATA[HexEdit]]></category>

		<category><![CDATA[ORCA]]></category>

		<category><![CDATA[Parallels]]></category>

		<category><![CDATA[Sweet16]]></category>

		<category><![CDATA[TextMate]]></category>

		<guid isPermaLink="false">http://sowhatsoftware.com/?p=177</guid>
		<description><![CDATA[Where do we start&#8230; Probably the best place is the tools and information you would need to start programming. You could blow the dust off your old IIgs and start there but you&#8217;re a modern homo sapien and probably have a gig or better machine sitting in front of you. The IIgs mainly ran at [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-13" title="appleiigs" src="http://sowhatsoftware.com/wp-content/uploads/2009/03/appleiigs-281x300.png" alt="appleiigs" width="281" height="300" />Where do we start&#8230; Probably the best place is the tools and information you would need to start programming. You could blow the dust off your old IIgs and start there but you&#8217;re a modern homo sapien and probably have a gig or better machine sitting in front of you. The IIgs mainly ran at 1 megaherts, 2.8 tops and frankly is a bit slow for this type of task. I do my assembly language programming on a modern Mac mini, more than fast enough for the task. Back in the day much work on the IIgs was actually done on the Mac, you will find the two very similar in many ways.</p>
<p>I use the <a title="Sweet16" href="http://www.sheppyware.net/software-mac/sweet16/index.html">Sweet16</a> Apple IIgs emulator by Eric Shepard for the IIgs portion of things. This emulator has no drawbacks as far as I can see and is really a brilliant implementation. I use the <a href="http://syndicomm.com">Apple IIgs Programmers Workshop</a> (APW) and AppleworksGS in the emulator. No other IIgs software is really needed and AppleworksGS is only used for graphics. All other software is either Mac or Windows based. I have not found a place where you can buy a copy of AppleworksGS, I use my original copy purchased in 1988.</p>
<p>On the Mac I have the Sweet16 emulator installed as well as <a href="http://www.parallels.com">Parallels</a> which runs Window XP. The only thing I use Windows for is to run a 65816 disassembler I found on the web called <a href="http://www.programmersheaven.com/download/1121/Download.aspx">D816</a>. It&#8217;s not the best one I have ever seen but with some coaxing, it produces useable source code segments. There are basically two Mac applications I use in my process, <a href="http://macromates.com">TextMate</a> and <a href="http://hexedit.sourceforge.net">HexEdit</a>. <a href="http://www.sowhatsoftware.com/Tables/table1.html">Click here</a> for a complete listing of the programming environment.</p>
<p>You may have noticed that I have disassembler capabilities in the environment which usually is not needed for regular programming but, in working with an old system like the Apple IIgs many times I want to upgrade existing software and I don&#8217;t have or have lost the source code. The techniques for disassembly are probably just as important for me as is straight forward programming.</p>
<p>With all the hardware in place it&#8217;s on to the reference documentation which should be as comprehensive as possible. Most of the documentation is still available from <a href="http://www.syndicomm.com">syndicomm.com</a> but be prepared to get some 3 ring binders because the reference manuals are only available in 3 hole punched, 2 sided xerox copy form these days. Finding some real old manuals on <a href="http://www.ebay.com">eBay</a> or <a href="http://www.amazon.com">Amazon</a> may be preferable or digging through an old timers documentation stash if you know one.</p>
<p>Although this development environment is on modern systems using emulation, you still should have a real Apple IIgs on hand for operational confirmation. There&#8217;s nothing like seeing your work running on the real deal. I have a couple machines on hand for these purposes, all Woz&#8217;s and they are just too cool for words. It makes people do double takes when they visit seeing an array of computers, some my development machines and some my play machines and some LINUX and Windows machines. Having the odd Apple II, +, C or E is fun too. Fortunately I never throw things out and over the past 30 years I have accumulated a virtual museum of great old equipment.</p>
<p>That&#8217;s about all for the preparation so next time we will get down to actually doing something with all this stuff.</p>
<p>Next post - Chapter 2: Dealing with files</p>
]]></content:encoded>
			<wfw:commentRss>http://sowhatsoftware.com/?feed=rss2&amp;p=177</wfw:commentRss>
		</item>
		<item>
		<title>Introduction: In the beginning there was assembly&#8230;</title>
		<link>http://sowhatsoftware.com/?p=1</link>
		<comments>http://sowhatsoftware.com/?p=1#comments</comments>
		<pubDate>Thu, 19 Mar 2009 23:13:13 +0000</pubDate>
		<dc:creator>sowhat</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[AppleIIgs]]></category>

		<category><![CDATA[Assembly]]></category>

		<category><![CDATA[C]]></category>

		<category><![CDATA[Pascal]]></category>

		<guid isPermaLink="false">http://sowhatsoftware.com/?p=1</guid>
		<description><![CDATA[Although many high level languages are in use today, they all have their roots in assembly language which up until the late 80&#8217;s was the way it was done.
Almost all software written for the AppleIIgs was written in assembly language. Sure, C and Pascal and some compiler based BASIC&#8217;s were in use but the late  [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-13" title="appleiigs" src="http://sowhatsoftware.com/wp-content/uploads/2009/03/appleiigs-281x300.png" alt="appleiigs" width="281" height="300" />Although many high level languages are in use today, they all have their roots in <a href="http://en.wikipedia.org/wiki/Assembly_language">assembly language</a> which up until the late 80&#8217;s was the way it was done.</p>
<p>Almost all software written for the <a href="http://en.wikipedia.org/wiki/Apple_IIgs">AppleIIgs</a> was written in assembly language. Sure, <a href="http://en.wikipedia.org/wiki/C_(programming_language)">C</a> and <a href="http://en.wikipedia.org/wiki/Pascal_(programming_language)">Pascal</a> and some compiler based <a href="http://en.wikipedia.org/wiki/BASIC">BASIC</a>&#8217;s were in use but the late  80&#8217;s was more a transition period for languages with these higher level implementations still virtually in their infancy, at least that&#8217;s how I remember it.</p>
<p>By the perceived  standards of today, assembly language programming is the grunting of primitive humanoids thrashing around in their caves. I find this view so short sighted as to be ludicrous. Assembly language is the secret that makes everything possible although most young programmers fail to see this.</p>
<p>As you can well guess, I love assembly language. I actually program in over a dozen languages but my all time favorite is assembly. I will be using this forum to expound upon the methods and madness of assembly language centered around the ultimate assembly language machine, the Apple IIgs. You may have a different opinion on this and I welcome any comments and/or suggestions which you can post here for all the world to see.</p>
<p>Technically, this is a blog (this site is built in <a href="http://en.wikipedia.org/wiki/Wordpress">WordPress</a>) where readers can comment and the like. I am treating this blog however like the chapters in a book because what I will present here is instructional, informative stuff. Each posting will be a new chapter in the book so to speak, so scroll down to the bottom for the beginning and work your way back up. I know this is backwards from how things usually are but this is a brave new world with brave new ways!</p>
<p>Next post - Chapter 1:  The programming environment</p>
]]></content:encoded>
			<wfw:commentRss>http://sowhatsoftware.com/?feed=rss2&amp;p=1</wfw:commentRss>
		</item>
	</channel>
</rss>
