<?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>sozobon &#8211; Virtually Fun</title>
	<atom:link href="https://virtuallyfun.com/category/sozobon/feed/" rel="self" type="application/rss+xml" />
	<link>https://virtuallyfun.com</link>
	<description>Fun with Virtualization</description>
	<lastBuildDate>Mon, 29 Jul 2019 01:02:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>
	<item>
		<title>Cross compiling to the Amiga with Sozobon</title>
		<link>https://virtuallyfun.com/2016/11/07/cross-compiling-amiga-sozobon/</link>
					<comments>https://virtuallyfun.com/2016/11/07/cross-compiling-amiga-sozobon/#respond</comments>
		
		<dc:creator><![CDATA[neozeed]]></dc:creator>
		<pubDate>Sun, 06 Nov 2016 17:53:48 +0000</pubDate>
				<category><![CDATA[68000]]></category>
		<category><![CDATA[Amiga]]></category>
		<category><![CDATA[cross compiler]]></category>
		<category><![CDATA[sozobon]]></category>
		<guid isPermaLink="false">https://virtuallyfun.com/?p=6588</guid>

					<description><![CDATA[To start this fun voyage, I used HCC, the first usable port of Sozobon C to the Amiga I could track down. &#160;From it&#8217;s description: Amiga port of Sozobon, Limited&#8217;s C Compiler. Can completely compile itself, supports 32 bit ints, &#8230; <a href="https://virtuallyfun.com/2016/11/07/cross-compiling-amiga-sozobon/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">

To start this fun voyage, I used <a href="http://aminet.net/package/dev/c/HCC">HCC</a>, the first usable port of <a href="http://www.atari-wiki.com/index.php/Sozobon_C">Sozobon C</a> to the Amiga I could track down. &nbsp;From it&#8217;s description:

</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p> Amiga port of Sozobon, Limited&#8217;s C Compiler. Can completely compile itself, supports 32 bit ints, and optimizer can &#8216;registerize&#8217; variables. Includes compiler, optimizer, tool for creating interface code for Amiga system calls, startup code, C library, include files, and library routines that work with Motorola FFP format. Uses assembler A68k, linker BLink, and provided run-time shared C library CClib.library. </p><cite>From the readme</cite></blockquote>



<p class="wp-block-paragraph"> And isn&#8217;t that great? Â It even supports 32 bit integers! Â I had to massage things in Visual C++, as there was some weird instances of return codes missing, and the optimizer not actually mallocing it&#8217;s memory, but just blindly using pointers. Â As always if you can see what is going on in a debugger it&#8217;s not too hard to make some wild guesses and get it running, and if you get lucky it may even work too&#8230; </p>



<h1 class="wp-block-heading">Running the compiler</h1>



<p class="wp-block-paragraph"> With the compiler and optimizer running (it is actually needed to run to further massage the assembly output into something the Amiga a68k assembler can read), it was time to look at an assembler. Â For the heck of it, I did try <a href="http://aminet.net/package/dev/asm/A68kGibbs">a68k</a>, and to my amazement it did actually work, once I had updated the file output call. </p>



<pre class="wp-block-preformatted">hcc\hcc -L hanoi.c
hcc: version 2.0 Copyright (c) 1988,1989,1991 by Sozobon, Limited.
Amiga Version 1.1 by Detlef WÂ³rkner.
hanoi.c:

top\top -v hanoi.s h2.s
top Version 2.00 Copyright (c) 1988-1991 by Sozobon, Limited.
Amiga Version 1.1 by Detlef WÂ³rkner.
hanoi.s:
Peephole changes (1): 8
Peephole changes (2): 1
Peephole changes (3): 0
Instructions deleted: 3
Variables registered: 0
Loop rotations : 0
Branch reversals : 0
Branches removed : 4

a68k\a68k -q100 h2.s
68000 Assembler - version 2.61 (January 11, 1990)
Copyright 1985 by Brian R. Anderson
AmigaDOS conversion copyright 1989 by Charlie Gibbs.

Assembling h2.s
PASS 1 line 59
PASS 2 line 59
End of assembly - no errors were found.
Heap usage: -w2047,80
Total hunk sizes: 94 code, 10 data, 0 BSS</pre>



<h2 class="wp-block-heading">linking</h2>



<p class="wp-block-paragraph"> Wow wasn&#8217;t that fun! I haven&#8217;t seen the source code to the BLINK linker, so I just end up using a native linker, BLINK. </p>



<figure class="wp-block-image"><img decoding="async" src="https://virtuallyfun.com/wp-content/uploads/2016/11/towers-of-hanoi.png" alt="" class="wp-image-6589"/><figcaption>Towers of Hanoi</figcaption></figure>



<p class="wp-block-paragraph">

Much to my amazement, the a68k assembler functions just fine as a cross assembler, and I only had to copy the object file into the emulator, and I could happily link.

</p>



<p class="wp-block-paragraph">

The syntax for BLINK was a little strange, mostly because I really don&#8217;t know what I&#8217;m doing.

</p>



<pre class="wp-block-preformatted">BLink LIB:HCC.o+hanoi.o LIB LIB:HCC.lib+LIB:stubs.lib TO hanoi SC SD VERBOSE</pre>



<p class="wp-block-paragraph">

Now to try something bigger, like the <a href="https://virtuallyfun.com/2014/12/15/tracking-down-the-infotaskforce-from-1987/">ancient 1987 vintage InfoTaskForce</a>. &nbsp;I had to add in the include files from the <a href="https://virtuallyfun.com/2013/01/11/dice-c-compiler-for-the-amiga/">DICE compiler</a>, and surprisingly, in no time, it was&nbsp;all compiled, and assembled the only step remaining was to run the BLINK linker. &nbsp;This time it was slightly different as now we had a bunch of object files:

</p>



<pre class="wp-block-preformatted">BLink LIB:HCC.o+fileo.o+funcso.o+infocomo.o+inito.o+inputo.o+interpo.o+ioo.o+jumpo.o+objecto.o+optionso.o+pageo.o+printo.o+propertyo.o+supporto.o+variableo.o LIB LIB:HCC.lib+LIB:stubs.lib TO infocom SC SD VERBOSE</pre>



<p class="wp-block-paragraph"> Running that as a single line (or better in a command file) got me my executable.</p>



<figure class="wp-block-image"><img decoding="async" src="https://virtuallyfun.com/wp-content/uploads/2016/11/linking-infotaskforce.png" alt="" class="wp-image-6597"/><figcaption>Linking</figcaption></figure>



<p class="wp-block-paragraph">

And it linked without any unresolved externals.

</p>



<figure class="wp-block-image"><img decoding="async" src="https://virtuallyfun.com/wp-content/uploads/2016/11/infocom-interpreter.png" alt="" class="wp-image-6590"/><figcaption>InfoTaskForce cross compiled on Windows, linked on AmigaDOS 2.0</figcaption></figure>



<h4 class="wp-block-heading">Running under WinUAE</h4>



<p class="wp-block-paragraph">And even better, it worked. Here it is running <a href="https://en.wikipedia.org/wiki/Planetfall">Planetfall</a>!</p>



<p class="wp-block-paragraph"> I can&#8217;t imagine it being all that useful for anyone, as Sozobon C is K&amp;R C, and well this is for the Commodore Amiga, not exactly a mainstay in this day &amp; age.</p>



<p class="wp-block-paragraph"><a href="https://sourceforge.net/projects/sozobon/files/Amiga/HCC_Sozobon_win32cross.7z/download">HCC_Sozobon_win32cross.7z</a>&nbsp;This link will take you to the sourceforge page, and the archive contains both source, and executables. &nbsp;As mentioned I didn&#8217;t see any Amiga linker that has source code, it seems everyone use BLINK, and the team that write BLINK went on to re-write all the &#8216;c&#8217; commands in AmigaDOS from BCPL/asm into C.</p>



<p class="wp-block-paragraph"><strong>***</strong></p>



<h5 class="wp-block-heading">Addendum</h5>



<p class="wp-block-paragraph">

I just discovered <a href="http://sun.hasenbraten.de/vlink/">vlink</a> after writing this, and now I can link a working executable under Windows 10! Since I made zero changes to vlink, and I&#8217;m not charging money, I am free to redistribute this so I&#8217;ve updated my archive, and included it.

</p>
]]></content:encoded>
					
					<wfw:commentRss>https://virtuallyfun.com/2016/11/07/cross-compiling-amiga-sozobon/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>easy68k &#038; sozobon</title>
		<link>https://virtuallyfun.com/2009/03/09/easy68k-sozobon/</link>
					<comments>https://virtuallyfun.com/2009/03/09/easy68k-sozobon/#respond</comments>
		
		<dc:creator><![CDATA[neozeed]]></dc:creator>
		<pubDate>Mon, 09 Mar 2009 20:46:00 +0000</pubDate>
				<category><![CDATA[assembly]]></category>
		<category><![CDATA[cross compiler]]></category>
		<category><![CDATA[m68k]]></category>
		<category><![CDATA[sozobon]]></category>
		<guid isPermaLink="false">https://virtuallyfun.com/?p=97</guid>

					<description><![CDATA[Easy68k I know this is a little weird to follow, but I thought it was somewhat interesting. Anyways I&#8217;ve been reading up on some CP/M stuff, and found some interesting m68k stuff. There is this really cool m68k simulator/test environment &#8230; <a href="https://virtuallyfun.com/2009/03/09/easy68k-sozobon/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<h1>Easy68k</h1>
<p>I know this is a little weird to follow, but I thought it was somewhat interesting. Anyways I&#8217;ve been reading up on some CP/M stuff, and found some interesting m68k stuff. There is this really cool m68k simulator/test environment called easy68k. Ok so the 68000 isn&#8217;t exactly the hottest chip, but for anyone that&#8217;s used a Mac, Amiga, Atari ST, SEGA Genesis, or old SUN the m68000 was the end all be all CPU. Anyways you can download the easy68k simulator from here:</p>
<p><a href="http://www.easy68k.com/">http://www.easy68k.com/</a></p>
<p>Now I&#8217;ve never been really all that good with assembly. I know one day I should learn, but until then, there is higher level languages, and of course theÂ best &#8216;medium&#8217; level language C. Back in the day the &#8216;sozobon&#8217; compiler was somewhat portable, and a good &amp; easy 16 bit C compiler. Now as far as I knowÂ there really hasn&#8217;t been any activity on this since 1991, so it&#8217;s getting hard to find, and of course the archived copies I found needed LZH.. You can findÂ some archived copies here:</p>
<p><a href="http://umich.edu/~archive/atari/Languages/Sozo2/">http://umich.edu/~archive/atari/Languages/Sozo2/</a></p>
<p>Since I didn&#8217;t want to go thru a big ordeal, I found an extracted copy of the sources here:</p>
<p><a href="http://cd.textfiles.com/crawlycrypt1/program/compiler/sozobon/">http://cd.textfiles.com/crawlycrypt1/program/compiler/sozobon/</a></p>
<h1>Building the sozobon compiler</h1>
<p>Using wget I pulled down the source code. It&#8217;s worth noting that unlike GCC this is SMALL&#8230; although it only targets the 68000 cpu. The only source thatÂ I&#8217;m using is the actual C compiler. I suppose if I were better I could map the simulator, and setup the assembler &amp; linker to target the environment all theÂ way&#8230; However for now I&#8217;m just interested in showing the relationship between a compiler, to the assembler.Â Now the source is old enough that it uses the reserved word inline in gunk.c I simply changed it to Xinline. I&#8217;ve attached a diff for those who like diff&#8217;sÂ however as you can see it&#8217;s really simple, I just renamed them, so they don&#8217;t conflict.</p>
<p><code><br />
--- gunk.c Fri Feb 22 05:33:34 1991<br />
+++ gunk-fix.c Mon Mar 9 14:35:33 2009<br />
@@ -37,7 +37,7 @@<br />
int (<em>rewri)(); /</em> rewrite function */<br />
};</p>
<p>-int m_unfold(), unfold(), m_cast(), cast(), m_inline(), inline();<br />
+int m_unfold(), unfold(), m_cast(), cast(), m_inline(), Xinline();<br />
int m_hardas(), hardas(), m_fcmp(), fcmp(), m_md_shf(), md_shf();<br />
int m_eident(), eident(), m_incdec(), incdec(), m_fldas(), fldas();</p>
<p>@@ -48,7 +48,7 @@<br />
{m_eident, eident},<br />
{m_incdec, incdec},<br />
{m_hardas, hardas},<br />
- {m_inline, inline}, /* must cast before inline <em>/<br />
+ {m_inline, Xinline}, /</em> must cast before inline */<br />
{m_fcmp, fcmp},<br />
{m_fldas, fldas},<br />
{0}<br />
@@ -424,7 +424,7 @@<br />
return 0;<br />
}</p>
<p>-inline(np)<br />
+Xinline(np)<br />
NODEP np;<br />
{<br />
register NODEP nmp, cmap;<br />
@@ -782,7 +782,7 @@<br />
register NODEP tp;</p>
<p>spar1 = "%fpcmp";<br />
- inline(np);<br />
+ Xinline(np);</p>
<p>tp = copyone(np);<br />
tp->n_left = np->n_left;<br />
</code></p>
<p>Now with that out of the way, you should be able to build with the make.unx</p>
<p><code><br />
% make -f make.unx<br />
gcc -DUNIX -O -c d2.c<br />
gcc -DUNIX -O -c decl.c<br />
gcc -DUNIX -O -c expr.c<br />
gcc -DUNIX -O -c fix.c<br />
gcc -DUNIX -O -c fun.c<br />
gcc -DUNIX -O -c g2.c<br />
gcc -DUNIX -O -c gen.c<br />
gcc -DUNIX -O -c gsub.c<br />
gcc -DUNIX -O -c gunk.c<br />
gcc -DUNIX -O -c main.c<br />
main.c:424: warning: 'optnl' was declared implicitly 'extern' and later 'static'<br />
main.c:417: warning: previous declaration of 'optnl'<br />
gcc -DUNIX -O -c md.c<br />
gcc -DUNIX -O -c nodes.c<br />
gcc -DUNIX -O -c out_st.c<br />
gcc -DUNIX -O -c p2.c<br />
gcc -DUNIX -O -c pre.c<br />
gcc -DUNIX -O -c tok.c<br />
gcc -DUNIX -O -c subs_c.c<br />
gcc -o xhcc d2.o decl.o expr.o fix.o fun.o g2.o gen.o gsub.o gunk.o main.o md.o nodes.o out_st.o p2.o pre.o tok.o subs_c.o<br />
</code></p>
<h1>Writing hello world!</h1>
<p>OK, with the compiler built, let&#8217;s write a simple C program. I&#8217;ve setup a simple main, and calls to a &#8216;putc&#8217; and an &#8216;exit&#8217; that currently don&#8217;t doÂ anything. We will have to fix that in theÂ assemblyÂ source.. but for now it&#8217;s nice as it sets up a place holder.</p>
<hr />
<p><code><br />
char MESSAGE[]="this is a message";<br />
void putc(c)<br />
char *c;<br />
{</p>
<p>}<br />
void exit()<br />
{}</p>
<p>void main()<br />
{<br />
int j;<br />
j=0;<br />
putc(MESSAGE);<br />
exit();<br />
}<br />
</code><br />
Now we can compile the source file (x.c) and use the -S flag, so it only outputs an assembly source, that we can then massage to work with easy68k.</p>
<p><code><br />
% ./xhcc -S x.c ; cat x.s<br />
.data<br />
.globl _MESSAGE<br />
_MESSAGE:<br />
.dc.b $74,$68,$69,$73,$20,$69,$73,$20,$61,$20,$6d<br />
.dc.b $65,$73,$73,$61,$67,$65<br />
.dc.b 0<br />
.text<br />
.globl _putc<br />
_putc:<br />
bra L1<br />
L0:<br />
;var 4 8 _c<br />
L2:<br />
unlk a6<br />
rts<br />
L1:<br />
link a6,#-0<br />
bra L0<br />
.globl _exit<br />
_exit:<br />
bra L4<br />
L3:<br />
L5:<br />
unlk a6<br />
rts<br />
L4:<br />
link a6,#-0<br />
bra L3<br />
.globl _main<br />
_main:<br />
bra L7<br />
L6:<br />
;var 2 -2 _j<br />
clr.w -2(a6)<br />
move.l #_MESSAGE,-(sp)<br />
jsr _putc<br />
add.w #4,sp<br />
jsr _exit<br />
L8:<br />
unlk a6<br />
rts<br />
L7:<br />
link a6,#-2<br />
bra L6<br />
.data<br />
</code></p>
<p>As you can see from the source below the following changes were made:</p>
<p>-Added the ORG $1000<br />
-Changed the formatting of the _MESSAGE into a format that easy68k&#8217;s assembler likes.<br />
-Removed all the .globl statements.<br />
-Renamed the _main section to START &amp; and add the end start tags.<br />
-Populated the exit procedure with the &#8216;exit&#8217; code from easy68k&#8217;s example<br />
-Changed putc to use the d0 register instead of d6, and added the print string code from easy68k.</p>
<p><code><br />
ORG $1000</p>
<p>_MESSAGE dc.b $74,$68,$69,$73,$20,$69,$73,$20,$61,$20,$6d<br />
dc.b $65,$73,$73,$61,$67,$65<br />
dc.b 0</p>
<p>_putc:<br />
bra L1<br />
L0:<br />
;var 4 8 _c<br />
move.b #14,d0<br />
trap #15</p>
<p>L2:<br />
unlk a0<br />
rts<br />
L1:<br />
link a0,#-0<br />
bra L0</p>
<p>_exit:<br />
bra L4<br />
L3:<br />
L5:<br />
unlk a6<br />
rts<br />
L4:<br />
move.b #9,d0<br />
trap #15<br />
link a6,#-0<br />
bra L3</p>
<p>START:<br />
bra L7<br />
L6:<br />
;var 2 -2 _j<br />
clr.w -2(a6)<br />
move.l #_MESSAGE,-(sp)<br />
jsr _putc<br />
add.w #4,sp<br />
jsr _exit<br />
L8:<br />
unlk a6<br />
rts<br />
L7:<br />
link a6,#-2<br />
bra L6<br />
end start<br />
</code></p>
<h1>conclusion</h1>
<p>Now you can run the code in the simulator, and watch it enter the &#8216;start&#8217; section, call the putc with the address of _MESSAGE, return to the main, and thenÂ call the _exit procedure, which calls the sim68k exit program interrupt.Â I&#8217;ll leave this as an exerciseÂ to the read for any real value&#8230;. I just thought it was cool, that without really learning any assembly I was able to writeÂ a basic &#8216;hello world&#8217; type program in an hour&#8230;.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://virtuallyfun.com/2009/03/09/easy68k-sozobon/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
