{"title":"Nebensinn blog","link":[{"@attributes":{"href":"https:\/\/logout22.github.io\/","rel":"alternate"}},{"@attributes":{"href":"https:\/\/logout22.github.io\/feeds\/all.atom.xml","rel":"self"}}],"id":"https:\/\/logout22.github.io\/","updated":"2022-04-10T19:00:00+02:00","entry":[{"title":"Fill empty drive space in\u00a0Xenix","link":{"@attributes":{"href":"https:\/\/logout22.github.io\/blog\/2022\/04\/10\/fill-empty-drive-space-in-xenix\/","rel":"alternate"}},"published":"2022-04-10T19:00:00+02:00","updated":"2022-04-10T19:00:00+02:00","author":{"name":"Martin Unzner"},"id":"tag:logout22.github.io,2022-04-10:\/blog\/2022\/04\/10\/fill-empty-drive-space-in-xenix\/","summary":"<p>A couple of months ago, <a class=\"reference external\" href=\"https:\/\/twitter.com\/blitzclone\">&#64;blitzclone<\/a> and I\ninstalled Xenix on one of my vintage machines. He documented the process in\n<a class=\"reference external\" href=\"https:\/\/twitter.com\/blitzclone\/status\/1481698790583279619\">a somewhat amusing thread on Twitter<\/a>.\nWhile installing and using Xenix is quite a hassle if you are used to modern Unix systems,\nI find it impressive what <span class=\"caps\">SCO \u2026<\/span><\/p>","content":"<p>A couple of months ago, <a class=\"reference external\" href=\"https:\/\/twitter.com\/blitzclone\">&#64;blitzclone<\/a> and I\ninstalled Xenix on one of my vintage machines. He documented the process in\n<a class=\"reference external\" href=\"https:\/\/twitter.com\/blitzclone\/status\/1481698790583279619\">a somewhat amusing thread on Twitter<\/a>.\nWhile installing and using Xenix is quite a hassle if you are used to modern Unix systems,\nI find it impressive what <span class=\"caps\">SCO<\/span> and Microsoft were able to achieve with the very primitive\nhardware back in the day (remember, on those systems,\n<span class=\"caps\">RAM<\/span> is still measured in Kilobytes, and there is not even a proper <span class=\"caps\">MMU<\/span>).<\/p>\n<p>Still, Xenix never had a chance to succeed in the market: &#8220;Serious&#8221; mainframes ran more versatile Unix distributions,\nusually specific to their vendor, whereas PCs back then often did not meet the high requirements.\nMany of them were still sold without a hard drive, which is a vital thing to have for Unix System V\nand thereby also for Xenix. As we know today, Microsoft decided to focus on <span class=\"caps\">DOS<\/span> development instead,\nand introduced graphical shells for that <span class=\"caps\">OS<\/span> called Windows (you may have heard of that&nbsp;product).<\/p>\n<p>Nevertheless, Xenix was, for a short period of time, the cheapest and hence most installed Unix around.\nThen <span class=\"caps\">BSD<\/span> was open-sourced, and Linux came into being, and Xenix soon faded out of the public eye.\nThe operating system remained fairly common in its niche of point of sales solutions and on-site controller networks\nfor some time. Until a couple of years ago, the last thing to be heard of Xenix was the occasional failing system,\ntucked away somewhere and subsequently forgotten, leaving their administrators hectically searching for replacement\nparts or new solutions. Among those surprised companies was our trustily disorganized\n<a class=\"reference external\" href=\"https:\/\/www.heise.de\/newsticker\/meldung\/Wenn-Computer-Oldies-nicht-mehr-wollen-Update-135968.html\">German Railway<\/a>.\nThese days, though, I guess all productive Xenix system have either been virtualized or&nbsp;decommissioned.<\/p>\n<p>In this article, however, I would like to leave history aside and\nfocus on my getting to know Xenix and talk about the experience of programming on an old Unix.\nIf you would like to know more about Xenix itself, have a look at\nthe <a class=\"reference external\" href=\"https:\/\/gunkies.org\/wiki\/Xenix\">Computer History Wiki&#8217;s<\/a> page on the subject,\nwhich details the various versions of Xenix and quirks&nbsp;thereof.<\/p>\n<p>I will also not go into further\ndetails here explaining how exactly we got Xenix to work,\nas that would probably warrant at least one\nseparate article. You may want to have a look at &#8220;Fun with virtualization&#8221;, where you can find a whole\n<a class=\"reference external\" href=\"https:\/\/virtuallyfun.com\/wordpress\/category\/xenix\/\">article series<\/a> about installing and configuring&nbsp;Xenix.<\/p>\n<div class=\"section\" id=\"motivation\">\n<h2>Motivation<\/h2>\n<p>After I was done with the installation, I created a backup of the hard drive in the computer,\nlargely because I was afraid that I would break the system and then have to start the whole procedure again from scratch.\nFirst, I connected a Raspberry Pi to the machine, using a null modem cable and a <span class=\"caps\">USB<\/span>-to-serial adapter\non the minicomputer.\nI went on to fork <span class=\"caps\">ELKS<\/span>, a Linux kernel derivative designed to support vintage computers from the original <span class=\"caps\">IBM<\/span> <span class=\"caps\">PC<\/span> onwards.\nYou can find my fork and the changes I made on <a class=\"reference external\" href=\"https:\/\/github.com\/Logout22\/elks\/commits\/xenix\">GitHub<\/a>.\nThen, I used a Gotek virtual floppy drive with a custom-built image of my version of <span class=\"caps\">ELKS<\/span>,\nand some scripts on the Raspberry Pi, to create a hard disk image file via <span class=\"caps\">SLIRP<\/span> and <span class=\"caps\">FTP<\/span>.\nI have put the scripts in my <span class=\"caps\">ELKS<\/span> repository as well, in case you are wondering how exactly that&nbsp;worked.<\/p>\n<p>When I analyzed the hard-drive dump using the <tt class=\"docutils literal\">strings<\/tt> command on Linux, in the hopes of finding the hello world program\nthat Julian and I had written, I could still see some plain-text fragments of the previous owner&#8217;s data, e.g. letters\nthat he must have written on the previously installed <span class=\"caps\">DOS<\/span> system.\nI wanted to clean them up, out of fairness, but also because I thought that should be a simple exercise to get to know\nsoftware development on old Unix. Also, as far as I could tell, Xenix has dd, but no \/dev\/zero device,\nso I would have to write the filler program myself, in plain old K&amp;R&nbsp;C.<\/p>\n<p>To better explain the problems that I faced despite the simple task, we will go over the source code piece by piece.\nThe complete source code can be found on <a class=\"reference external\" href=\"https:\/\/codeberg.org\/Logout\/fill-space\">Codeberg<\/a>.<\/p>\n<p>In the sections that follow, I will assume that you have some basic knowledge of the modern C language (i.e. <span class=\"caps\">ANSI<\/span> C and&nbsp;beyond).<\/p>\n<\/div>\n<div class=\"section\" id=\"the-program\">\n<h2>The&nbsp;program<\/h2>\n<p>To start off, I needed to store the data (i.e. zeroes) that I wanted to write to disk somewhere.\nI assumed that old compilers would not reserve very high amounts of stack space (especially on a 286 with its weird segmentation logic),\nso I declared my zero buffer&nbsp;globally:<\/p>\n<div class=\"highlight\"><pre><span><\/span><span class=\"kt\">char<\/span><span class=\"w\"> <\/span><span class=\"n\">zero_buffer<\/span><span class=\"p\">[<\/span><span class=\"n\">BLOCK_SIZE<\/span><span class=\"p\">];<\/span>\n<\/pre><\/div>\n<p>By the way, all constants, like BLOCK_SIZE here, need to be macros declared using #define. That may seem strange\nto you if you are used to modern C++ development for instance, but in C, const values cannot be used for array bounds\nand other statically defined values because they are not, by definition, available at compile&nbsp;time.<\/p>\n<p>While that may take some time to get used to and look a bit ugly, it is still more or less readable code.\nWhat really killed me is the function declaration syntax of ancient&nbsp;C:<\/p>\n<div class=\"highlight\"><pre><span><\/span><span class=\"kt\">void<\/span><span class=\"w\"> <\/span><span class=\"nf\">main<\/span><span class=\"p\">(<\/span><span class=\"n\">argc<\/span><span class=\"p\">,<\/span><span class=\"n\">argv<\/span><span class=\"p\">)<\/span>\n<span class=\"w\">  <\/span><span class=\"kt\">int<\/span><span class=\"w\"> <\/span><span class=\"n\">argc<\/span><span class=\"p\">;<\/span>\n<span class=\"w\">  <\/span><span class=\"kt\">char<\/span><span class=\"o\">**<\/span><span class=\"w\"> <\/span><span class=\"n\">argv<\/span><span class=\"p\">;<\/span>\n<span class=\"p\">{<\/span>\n<\/pre><\/div>\n<p>Why did Kernighan and Ritchie (<span class=\"caps\">RIP<\/span>) have to do it like that? I do not get that. From what I read, it was simply\ntheir convention, and the so-called C++-style declaration which is common nowadays was only introduced with the later <span class=\"caps\">ANSI<\/span> C.\nBut as far as I can see, none of the languages that inspired C, neither <span class=\"caps\">ALGOL<\/span> nor <span class=\"caps\">BCPL<\/span> for example,\nhave such a weird syntax to declare their function headers. Did they simply like it better that way?\nWas it a limitation of the contemporary compilers? If you know more about this, please send me a&nbsp;message!<\/p>\n<p>Something that I already knew, on the other hand, but which also annoys me, is that\nall variables must be declared at the beginning of the function, or you will simply get a syntax error.\nSo here they come,&nbsp;fanfares!<\/p>\n<div class=\"highlight\"><pre><span><\/span><span class=\"kt\">FILE<\/span><span class=\"o\">*<\/span><span class=\"w\"> <\/span><span class=\"n\">filler<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"nb\">NULL<\/span><span class=\"p\">;<\/span>\n<span class=\"kt\">unsigned<\/span><span class=\"w\"> <\/span><span class=\"kt\">long<\/span><span class=\"w\"> <\/span><span class=\"n\">blocks_written<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"n\">blocks_per_iteration<\/span><span class=\"p\">;<\/span>\n<span class=\"kt\">unsigned<\/span><span class=\"w\"> <\/span><span class=\"kt\">long<\/span><span class=\"w\"> <\/span><span class=\"n\">chunk_count<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"n\">remaining_blocks<\/span><span class=\"p\">;<\/span>\n<span class=\"kt\">int<\/span><span class=\"w\"> <\/span><span class=\"n\">i<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"n\">j<\/span><span class=\"p\">;<\/span>\n<span class=\"kt\">char<\/span><span class=\"w\"> <\/span><span class=\"n\">confirm<\/span><span class=\"p\">;<\/span>\n<\/pre><\/div>\n<p>As a matter of fact, no one knows at this point what all of these will be for, and no one cares.\nIf anything, this convention is an invitation to leave half of the variables uninitialized,\nto give them all single-letter names that are easy to remember further down, and to reuse them wherever you can.\nThis suddenly gives you a hint why so many programming anti-patterns came into existence originally.\nI understand that compilers back then were fairly limited, but I cannot imagine that it would have been impossible\nto add a separate pass that searches for all declarations and reserves the required heap space.\nHere, again, one can look at other contemporary languages, like Pascal or <span class=\"caps\">BCPL<\/span>, that did not declare everything&nbsp;upfront.<\/p>\n<p>Next, we do some input value checks. Returning from main() is not well-defined before C99 as far as I know, so\nI opted to use the exit() function to return control flow, which thankfully&nbsp;worked:<\/p>\n<div class=\"highlight\"><pre><span><\/span><span class=\"k\">if<\/span><span class=\"w\"> <\/span><span class=\"p\">(<\/span><span class=\"n\">argc<\/span><span class=\"w\"> <\/span><span class=\"o\">&lt;<\/span><span class=\"w\"> <\/span><span class=\"mi\">2<\/span><span class=\"p\">)<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span>\n<span class=\"w\">    <\/span><span class=\"n\">printf<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;Please supply a block count target.<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span><span class=\"p\">);<\/span>\n<span class=\"w\">    <\/span><span class=\"n\">exit<\/span><span class=\"p\">(<\/span><span class=\"mi\">1<\/span><span class=\"p\">);<\/span>\n<span class=\"p\">}<\/span>\n<\/pre><\/div>\n<p>memset() and atol() also existed, which was a&nbsp;plus!<\/p>\n<div class=\"highlight\"><pre><span><\/span><span class=\"n\">memset<\/span><span class=\"p\">(<\/span><span class=\"n\">zero_buffer<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"mi\">0<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"n\">BLOCK_SIZE<\/span><span class=\"p\">);<\/span>\n<span class=\"n\">remaining_blocks<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">atol<\/span><span class=\"p\">(<\/span><span class=\"n\">argv<\/span><span class=\"p\">[<\/span><span class=\"mi\">1<\/span><span class=\"p\">]);<\/span>\n<\/pre><\/div>\n<p>Next, we are looking at the progress indicator. Such a mechanism is useful to detect hangs in general,\nbut in this particular case, the system is also shared\nthrough the Raspberry Pi gateway that I mentioned earlier.\nLogging in from a different user still gives you the same serial port, so\nproducing some output regularly tells the new user that the serial terminal is still&nbsp;busy.<\/p>\n<p>My first approach was to use <span class=\"caps\">ANSI<\/span> characters for a sort of interactive progress bar,\nand organize the work in threads:\nOne for progress monitoring and one for writing.\nThis idea did not come to fruition because there was no reliable way to wait for a certain time on this system:\nThere was no sleep() defined in the standard library, and when\nI tried select() without sockets, the system call did not wait as I had&nbsp;expected.<\/p>\n<p>As that approach did not work out, I decided\nto split the data to be written into larger chunks, and display a short line indicating progress whenever\none of those blocks was&nbsp;completed.<\/p>\n<p>If you think about it, it also does not really make sense to use threads on a single-core machine.\nStill, it would have been a neat demonstration of Xenix&#8217; scheduling capabilities.\nMaybe I will get around to it in a future&nbsp;project.<\/p>\n<p>While composing the progress line, I realized that printf did not expect more than one parameter to substitute,\nand only printed garbage for the second one. I am pretty sure that this is a toolchain bug,\nbut I would not rule out that early versions of C simply did not iterate further. Hence, e.g. the debug output\nin the end looks like&nbsp;this:<\/p>\n<div class=\"highlight\"><pre><span><\/span><span class=\"n\">printf<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;Wrote %u blocks, &quot;<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"n\">blocks_written<\/span><span class=\"p\">);<\/span>\n<span class=\"n\">printf<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;%u remaining<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"n\">remaining_blocks<\/span><span class=\"p\">);<\/span>\n<\/pre><\/div>\n<p>When trying to compute the necessary data ratios, I discovered the worst issue of all:\nDivision on the required numeric range was broken! I suppose it has to do with 16-bit arithmetic somehow,\nbut ultimately I have no idea why; please enlighten me if you do! In the end, I just let the computer count\nhow often one integer fit into the other, like a schoolchild.\nThinking about how slow division could be on old machines like the 286, though,\nmy method is probably more efficient than one might think.&nbsp;;)<\/p>\n<div class=\"highlight\"><pre><span><\/span><span class=\"k\">for<\/span><span class=\"w\"> <\/span><span class=\"p\">(<\/span><span class=\"n\">i<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"mi\">0<\/span><span class=\"p\">;<\/span><span class=\"w\"> <\/span><span class=\"n\">i<\/span><span class=\"w\"> <\/span><span class=\"o\">&lt;<\/span><span class=\"w\"> <\/span><span class=\"n\">remaining_blocks<\/span><span class=\"p\">;<\/span><span class=\"w\"> <\/span><span class=\"p\">)<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span>\n<span class=\"w\">    <\/span><span class=\"o\">++<\/span><span class=\"n\">chunk_count<\/span><span class=\"p\">;<\/span>\n<span class=\"w\">    <\/span><span class=\"n\">i<\/span><span class=\"w\"> <\/span><span class=\"o\">+=<\/span><span class=\"w\"> <\/span><span class=\"n\">CHUNK_SIZE<\/span><span class=\"p\">;<\/span>\n<span class=\"p\">}<\/span>\n<\/pre><\/div>\n<p>The scanf() function was garbage as well, but to be honest, I never really got the hang of that one anyway.\nHere, though, not even the extremely basic examples from my old C book for <span class=\"caps\">DOS<\/span> worked.\nIn the end, I resorted to plain <span class=\"caps\">UNIX<\/span> read() to get user&nbsp;input:<\/p>\n<div class=\"highlight\"><pre><span><\/span><span class=\"n\">printf<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;OK?<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span><span class=\"p\">);<\/span>\n<span class=\"n\">read<\/span><span class=\"p\">(<\/span><span class=\"mi\">0<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"o\">&amp;<\/span><span class=\"n\">confirm<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"mi\">1<\/span><span class=\"p\">);<\/span>\n<span class=\"k\">if<\/span><span class=\"w\"> <\/span><span class=\"p\">(<\/span><span class=\"n\">confirm<\/span><span class=\"w\"> <\/span><span class=\"o\">!=<\/span><span class=\"w\"> <\/span><span class=\"sc\">&#39;y&#39;<\/span><span class=\"p\">)<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span>\n<span class=\"w\">    <\/span><span class=\"n\">exit<\/span><span class=\"p\">(<\/span><span class=\"mi\">1<\/span><span class=\"p\">);<\/span>\n<span class=\"p\">}<\/span>\n<\/pre><\/div>\n<p>I would have loved to get the input from the same line, i.e. drop the <tt class=\"docutils literal\">\\n<\/tt> from the printf() above,\nbut I did not find a way to flush the output buffer; no flush function to be seen anywhere in the&nbsp;docs!<\/p>\n<p>At that point, I had run into so many obstacles already that I decided not to care if my confirmation looked pretty.\nIt was only there, after all, because I had noticed the division bug I mentioned earlier just floating by\nwhen an earlier version of this program was already running.\nI consequently decided to add a confirmation as a sanity check, in case anything else went&nbsp;haywire.<\/p>\n<p>Now, we have arrived at the main loop, which is at the heart of the&nbsp;program:<\/p>\n<div class=\"highlight\"><pre><span><\/span><span class=\"n\">blocks_written<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"mi\">0<\/span><span class=\"p\">;<\/span>\n<span class=\"n\">blocks_per_iteration<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">CHUNK_SIZE<\/span><span class=\"p\">;<\/span>\n\n<span class=\"n\">filler<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">fopen<\/span><span class=\"p\">(<\/span><span class=\"n\">FILENAME<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s\">&quot;w&quot;<\/span><span class=\"p\">);<\/span>\n<span class=\"k\">for<\/span><span class=\"w\"> <\/span><span class=\"p\">(<\/span><span class=\"n\">i<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"mi\">0<\/span><span class=\"p\">;<\/span><span class=\"w\"> <\/span><span class=\"n\">i<\/span><span class=\"w\"> <\/span><span class=\"o\">&lt;<\/span><span class=\"w\"> <\/span><span class=\"n\">chunk_count<\/span><span class=\"p\">;<\/span><span class=\"w\"> <\/span><span class=\"o\">++<\/span><span class=\"n\">i<\/span><span class=\"p\">)<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span>\n<span class=\"w\">    <\/span><span class=\"k\">if<\/span><span class=\"w\"> <\/span><span class=\"p\">(<\/span><span class=\"n\">remaining_blocks<\/span><span class=\"w\"> <\/span><span class=\"o\">&lt;<\/span><span class=\"w\"> <\/span><span class=\"n\">CHUNK_SIZE<\/span><span class=\"p\">)<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span>\n<span class=\"w\">        <\/span><span class=\"n\">blocks_per_iteration<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">remaining_blocks<\/span><span class=\"p\">;<\/span>\n<span class=\"w\">    <\/span><span class=\"p\">}<\/span>\n<span class=\"w\">    <\/span><span class=\"k\">for<\/span><span class=\"w\"> <\/span><span class=\"p\">(<\/span><span class=\"n\">j<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"mi\">0<\/span><span class=\"p\">;<\/span><span class=\"w\"> <\/span><span class=\"n\">j<\/span><span class=\"w\"> <\/span><span class=\"o\">&lt;<\/span><span class=\"w\"> <\/span><span class=\"n\">blocks_per_iteration<\/span><span class=\"p\">;<\/span><span class=\"w\"> <\/span><span class=\"o\">++<\/span><span class=\"n\">j<\/span><span class=\"p\">)<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span>\n<span class=\"w\">        <\/span><span class=\"n\">fwrite<\/span><span class=\"p\">(<\/span><span class=\"n\">zero_buffer<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"n\">BLOCK_SIZE<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"mi\">1<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"n\">filler<\/span><span class=\"p\">);<\/span>\n<span class=\"w\">    <\/span><span class=\"p\">}<\/span>\n<span class=\"w\">    <\/span><span class=\"n\">blocks_written<\/span><span class=\"w\"> <\/span><span class=\"o\">+=<\/span><span class=\"w\"> <\/span><span class=\"n\">blocks_per_iteration<\/span><span class=\"p\">;<\/span>\n<span class=\"w\">    <\/span><span class=\"n\">remaining_blocks<\/span><span class=\"w\"> <\/span><span class=\"o\">-=<\/span><span class=\"w\"> <\/span><span class=\"n\">blocks_per_iteration<\/span><span class=\"p\">;<\/span>\n<span class=\"w\">    <\/span><span class=\"n\">printf<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;Wrote %u blocks, &quot;<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"n\">blocks_written<\/span><span class=\"p\">);<\/span>\n<span class=\"w\">    <\/span><span class=\"n\">printf<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;%u remaining<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"n\">remaining_blocks<\/span><span class=\"p\">);<\/span>\n<span class=\"p\">}<\/span>\n<\/pre><\/div>\n<p>As you can see, we are using a very basic algorithm.\nYou may have noticed that error handling on the fopen \/ fwrite \/ fclose \/ unlink system calls is missing.\nI would leave that as an exercise for the enthusiastic reader.\nAdding error handling should be easy if you look at\nthe respective function reference pages in the <a class=\"reference external\" href=\"http:\/\/bitsavers.trailing-edge.com\/pdf\/att\/3b1\/999-801-312IS_ATT_UNIX_PC_System_V_Users_Manual_Volume_1.pdf\"><span class=\"caps\">UNIX<\/span> System V manual<\/a>.&nbsp;;)<\/p>\n<p>The <tt class=\"docutils literal\">if<\/tt> statement which caps <tt class=\"docutils literal\">blocks_per_iteration<\/tt> is necessary for the last chunk,\nwhere there are fewer blocks remaining than one chunk size.\nLuckily, my hand-crafted integer division seems to round up <tt class=\"docutils literal\">chunk_count<\/tt> in that case,\nso no correction required&nbsp;there.<\/p>\n<p>I was not sure how long each of these operations would take, so I added more debug&nbsp;output:<\/p>\n<div class=\"highlight\"><pre><span><\/span><span class=\"n\">printf<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;Done, closing file.<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span><span class=\"p\">);<\/span>\n<span class=\"n\">fclose<\/span><span class=\"p\">(<\/span><span class=\"n\">filler<\/span><span class=\"p\">);<\/span>\n<span class=\"n\">printf<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;Deleting file...<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span><span class=\"p\">);<\/span>\n<span class=\"n\">unlink<\/span><span class=\"p\">(<\/span><span class=\"n\">FILENAME<\/span><span class=\"p\">);<\/span>\n<\/pre><\/div>\n<p>Finally, we are&nbsp;done:<\/p>\n<div class=\"highlight\"><pre><span><\/span><span class=\"n\">printf<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;Done, your hard drive should be clean now. :)<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span><span class=\"p\">);<\/span>\n<\/pre><\/div>\n<\/div>\n<div class=\"section\" id=\"did-it-work\">\n<h2>Did it&nbsp;work?<\/h2>\n<p>When I finally tried the program, it ran into a &#8220;no free space&#8221; error a lot earlier than <tt class=\"docutils literal\">df<\/tt>\nhad previously indicated.\nApparently, the hint from the <a class=\"reference external\" href=\"http:\/\/www.nj7p.org\/Manuals\/PDFs\/Intel\/174389-001.pdf\">Xenix System Administrator&#8217;s guide<\/a> that Xenix needs at least 15 % (!)\nof free space is a hard requirement in practice.\nIn the end, I had to kill the program using the Ctrl+\\ hot&nbsp;key.<\/p>\n<p>Ironically, the data was still there when I ran &#8216;strings&#8217; on a subsequently created hard drive image,\nbut again, I could not find my source code.\nI have no idea how Xenix organizes its data storage, but it must be very efficient!\nWell, except for all the available space that is unusable, but you know, something&#8217;s always gotta give.&nbsp;:D<\/p>\n<p>I ended up swallowing the ultimate bitter pill:\nUsing the <span class=\"caps\">ELKS<\/span> floppy, I overwrote all data on the hard drive using classic dd, and subsequently reinstalled Xenix.\nOn a positive note, the installation was a lot easier the second time, and I got far more software to work than before.\nAnd, naturally, I created a (clean) full disk backup immediately after I was&nbsp;done.<\/p>\n<\/div>\n<div class=\"section\" id=\"what-comes-next\">\n<h2>What comes&nbsp;next?<\/h2>\n<p>As that was no success at all, I should look towards other endeavours regarding Linux&#8217; grandpa.\nA simple history function for the shell would be great, maybe even something like a complete command line processor.\nGood, usable shells, like the Korn shell, are limited to Xenix 386, unfortunately, likely due to memory requirements.\nThe supplied C shell supports some rudimentary history in the form of reusable variables, but that is not really what I&nbsp;want.<\/p>\n<p>Some very basic history in the modern sense, with support for the cursor keys, should not be too hard to do, right?\nOn the other hand, that is what I said about this project as well, so let&#8217;s see&nbsp;;)<\/p>\n<\/div>\n<div class=\"section\" id=\"helpful-resources\">\n<h2>Helpful&nbsp;resources<\/h2>\n<p>These resources helped me a lot to write anything usable for Xenix.\nI hope that they will be useful for you, too, should you want to try your luck on this ancient <span class=\"caps\">UNIX<\/span>:<\/p>\n<ul class=\"simple\">\n<li><a class=\"reference external\" href=\"http:\/\/www.nj7p.org\/Manuals\/PDFs\/Intel\/174389-001.pdf\">Xenix System Administrator&#8217;s&nbsp;guide<\/a><\/li>\n<li>The original <a class=\"reference external\" href=\"http:\/\/bitsavers.trailing-edge.com\/pdf\/att\/3b1\/999-801-312IS_ATT_UNIX_PC_System_V_Users_Manual_Volume_1.pdf\"><span class=\"caps\">UNIX<\/span> System V&nbsp;manual<\/a><\/li>\n<\/ul>\n<p>Beware: Both documents trigger a warning in current browsers because they are served via insecure <span class=\"caps\">HTTP<\/span>! From what I can see, they should be safe to open,&nbsp;though.<\/p>\n<ul class=\"simple\">\n<li><a class=\"reference external\" href=\"https:\/\/github.com\/mrquincle\/ancient-c-compilers\">Ancient C compilers repo<\/a>, especially the C files from the first <span class=\"caps\">UNIX<\/span> source code, for getting to know the quirky early C syntax\nand reading some example code on how to use the early versions of the <span class=\"caps\">UNIX<\/span> system&nbsp;calls<\/li>\n<\/ul>\n<\/div>\n","category":{"@attributes":{"term":"blog"}}},{"title":"My article in LOAD\u00a0magazine","link":{"@attributes":{"href":"https:\/\/logout22.github.io\/blog\/2022\/03\/02\/my-article-in-load-magazine\/","rel":"alternate"}},"published":"2022-03-02T21:00:00+01:00","updated":"2022-03-02T21:00:00+01:00","author":{"name":"Martin Unzner"},"id":"tag:logout22.github.io,2022-03-02:\/blog\/2022\/03\/02\/my-article-in-load-magazine\/","summary":"<p>Just a quick note to pass the time until the next full article:\nI made a contribution to last year&#8217;s <span class=\"caps\">LOAD<\/span> magazine.\nYou can find the download link for issue 7&nbsp;here:<\/p>\n<p><a class=\"reference external\" href=\"https:\/\/www.classic-computing.org\/load-online\/\">https:\/\/www.classic-computing.org\/load-online\/<\/a><\/p>\n<p>My article is called &#8220;Do it yourself 80486&#8221; and describes a retro \u2026<\/p>","content":"<p>Just a quick note to pass the time until the next full article:\nI made a contribution to last year&#8217;s <span class=\"caps\">LOAD<\/span> magazine.\nYou can find the download link for issue 7&nbsp;here:<\/p>\n<p><a class=\"reference external\" href=\"https:\/\/www.classic-computing.org\/load-online\/\">https:\/\/www.classic-computing.org\/load-online\/<\/a><\/p>\n<p>My article is called &#8220;Do it yourself 80486&#8221; and describes a retro\nmachine that I assembled for that occasion (and kept afterwards).\nI finished the project about a year ago, but the magazine was not publicly\navailable before mid of last&nbsp;year.<\/p>\n<p>Unfortunately, the article is in German and not very detailed due to space constraints.\nIf you are interested in the topic, though, I can provide you with more information.\nJust send me an&nbsp;email.<\/p>\n<p>An update should be coming soon (sooner than 2.5 years for sure ;)&nbsp;).<\/p>\n<p>See you&nbsp;then!<\/p>\n","category":{"@attributes":{"term":"blog"}}},{"title":"A sandwich case for\u00a0uGame","link":{"@attributes":{"href":"https:\/\/logout22.github.io\/blog\/2019\/06\/22\/a-sandwich-case-for-ugame\/","rel":"alternate"}},"published":"2019-06-22T20:00:00+02:00","updated":"2019-06-22T20:00:00+02:00","author":{"name":"Martin Unzner"},"id":"tag:logout22.github.io,2019-06-22:\/blog\/2019\/06\/22\/a-sandwich-case-for-ugame\/","summary":"<p><strong>tl;dr If you are only interested in how I made my case (haha)\nyou can jump to the next section<\/strong> <a class=\"reference internal\" href=\"#required-parts\">Required&nbsp;parts<\/a><\/p>\n<p>About four months ago I got a <a class=\"reference external\" href=\"https:\/\/hackaday.io\/project\/27629-game\">uGame10<\/a> for my birthday. I had seen a presentation\non the device at <span class=\"caps\">FOSDEM<\/span> a couple of days before and \u2026<\/p>","content":"<p><strong>tl;dr If you are only interested in how I made my case (haha)\nyou can jump to the next section<\/strong> <a class=\"reference internal\" href=\"#required-parts\">Required&nbsp;parts<\/a><\/p>\n<p>About four months ago I got a <a class=\"reference external\" href=\"https:\/\/hackaday.io\/project\/27629-game\">uGame10<\/a> for my birthday. I had seen a presentation\non the device at <span class=\"caps\">FOSDEM<\/span> a couple of days before and was immediately hooked,\nso I decided to put a wish out to my friends. Thanks again guys!&nbsp;:)<\/p>\n<p>When I finally unboxed the chip I was surprised how tiny it was.\nSeeing a device this small, featuring a well-known Nintendo-like\nset of buttons, I was reminded of the small toy alarm clocks\nNintendo used to make under their brand of <a class=\"reference external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Nintendo_Mini_Classics\">Nintendo Mini Classics<\/a>.\nI had a lot of fun with those mini arcade machines as a child and still\nadmire the addictive simplicity with which those games were made. And now I held\na template for such a machine in my hands, and could develop my very own\npocket game machine. How&nbsp;exciting!<\/p>\n<p>It turned on fine when I connected it to a computer and, after a firmware update,\nit ran all two example programs available on the web just fine. However,\nhaving a mobile device connected to a wall outlet or a bulky power bank\nall the time kind of defeats the point. Consequently, uGame was always designed\nto run off battery power. uGame&#8217;s inventor, Radomir Dopieralski, recommends\nto solder a specific Nokia phone battery from the 2000s directly\nto the pads on the device and then hot-glue it to the back of the board\n(see <a class=\"reference external\" href=\"https:\/\/github.com\/python-ugame\/ugame-docs\/blob\/ad676d121e3c583d1658f54e65a392fbcf29861f\/assembly.rst\">uGame manual<\/a>).<\/p>\n<p>If this sounds dangerous to you: It is. Soldering irons, or worse soldering guns,\nget very hot, and the Lithium, which is what the old battery is made of,\ntends to take heat as an invitation to react with everything in its proximity.\nAlso, the contact pads and their insulation were built to a price point,\nand are very thin and brittle. Soldering on them is certainly not easy,\nand it is easy to damage or destroy the insulation, which could have\nall kinds of unintended consequences. But then again,\nRadomir goes to great lengths explaining that the device is a prototype\nfor experienced hobbyists and not a childrens&#8217;&nbsp;toy.<\/p>\n<p>In addition to the risky way of fixing the battery that I did not want to follow,\nI faced the problem\nthat I did not have the specific Nokia battery that was recommended in the manual.\nHence, none of the case designs available online for 3D printing would have\nworked for me (e.g. by <a class=\"reference external\" href=\"https:\/\/www.thingiverse.com\/thing:2971913\">Jovan Maric<\/a> or <a class=\"reference external\" href=\"https:\/\/www.thingiverse.com\/thing:2797538\">davedarko<\/a>).\nI could have bought a used battery online, but you never know\nwhat state you will receive them in.\nI had another Nokia battery from the era handy which I tried, but I had no\nluck attaching wires to the battery&#8217;s pads&nbsp;either.<\/p>\n<p>However, I was able to try if the board worked with a battery at all, and it did.\nI had soldered wires to the uGame, pushed the other end to the battery,\nand the screen was flashing on nice and bright as it did on a wire lead.\nNaturally, the uGame went\noff again when I let go, but after that short experiment I was confident\nthat there was a way to make this work, albeit probably not\nwith this exact&nbsp;battery.<\/p>\n<p>I am a trained computer engineer and I have no idea of materials or 3D printing.\nEven if I asked my friends for help and designed a sophisticated case for &#8220;my&#8221;\nNokia battery,\nincluding spring contacts to hold it in place firmly, a small <span class=\"caps\">PCB<\/span>\nto extract the leads, and a snap-in plastic housing for the uGame,\nthe case would only fit the one Nokia battery that I own.\nIf the battery broke down it would be completely useless.\nAlso, I work an unrelated full-time job, and this is not my only hardware project,\nso time is limited to some degree. Thinking along those lines, I found I best\ntry something I have some experience with, and came up with a custom\n&#8220;sandwich&#8221; case&nbsp;design.<\/p>\n<div class=\"section\" id=\"required-parts\">\n<h2>Required&nbsp;parts<\/h2>\n<ul>\n<li><p class=\"first\">a <a class=\"reference external\" href=\"https:\/\/hackaday.io\/project\/27629-game\">uGame10<\/a> prototype&nbsp;board<\/p>\n<\/li>\n<li><p class=\"first\">two through-hole printed circuit&nbsp;boards<\/p>\n<p>The boards should feature individual soldering points to avoid short circuits\nwhen attaching the battery. Mounting holes for the cable ties (see below)\ncome in handy,&nbsp;too.<\/p>\n<\/li>\n<li><p class=\"first\">a 3.7 volts Lithium battery (e.g. Sony <span class=\"caps\">US18650V3<\/span>) and a matching&nbsp;holder<\/p>\n<\/li>\n<li><p class=\"first\">some wire, ideally two&nbsp;colours<\/p>\n<p>I prefer solid wire, some prefer stranded wire, your choice&nbsp;basically.<\/p>\n<\/li>\n<li><p class=\"first\">about four zip ties to attach the two boards&nbsp;together<\/p>\n<p>I would recommend having more handy,\nas those fiddly beasts tend to get lost easly.\nSometimes you will also need to cut them when\nyou tied the wrong things together, unless you are one\nof those Houdinis who can disassemble zip ties without\nbreaking&nbsp;them.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<div class=\"section\" id=\"assembly\">\n<h2>Assembly<\/h2>\n<p>First, mount the battery holder to one of the boards.\nPut it on the side of the board that does not have soldering points on it,\nso that you will later be able to solder its connectors to the board.\nYou may need to punch or drill small holes in the board to be able to\nfasten the battery holder properly. Make sure the holder does not shake or wobble\nwhen you are done: Lithium batteries are quite heavy\nand require solid&nbsp;fastening.<\/p>\n<img alt=\"The PCB mounted in a vice\" src=\"https:\/\/logout22.github.io\/images\/01_pcb.jpg\" \/>\n<img alt=\"The PCB mounted in a vice with the battery holder attached to its back\" src=\"https:\/\/logout22.github.io\/images\/02_pcb_holder_back.jpg\" \/>\n<img alt=\"The PCB mounted in a vice with the battery holder attached to its front\" src=\"https:\/\/logout22.github.io\/images\/03_pcb_holder_front.jpg\" \/>\n<p>Now solder the battery holder contacts to the circuit board,\nand attach some wire to the solder joints. I recommend red wire for the\nbattery&#8217;s positive end and white for the negative one.\n<strong>Always mind the correct polarity<\/strong>:\nIf polarity is reversed when connecting\nthe battery to the board you may destroy both the battery and the&nbsp;uGame!<\/p>\n<img alt=\"The PCB with the soldered battery holder and wires\" src=\"https:\/\/logout22.github.io\/images\/04_soldered_holder.jpg\" \/>\n<p>Now, solder the other ends of the wires to the back of your uGame board,\nmatching the polarity of the battery,\nand attach the screen to the front of the uGame as described\nin the <a class=\"reference external\" href=\"https:\/\/github.com\/python-ugame\/ugame-docs\/blob\/ad676d121e3c583d1658f54e65a392fbcf29861f\/assembly.rst\">uGame manual<\/a>.\nIf you insert the battery now, you should already be able to turn on the\nuGame using the small up\/down switch on the side.\n<strong>Again, mind the polarity when inserting the battery into the finished circuit!<\/strong>\nAfter turning on the uGame, the whole setup should look somewhat\nlike the picture&nbsp;below.<\/p>\n<img alt=\"The PCB with the soldered battery holder and uGame running\" src=\"https:\/\/logout22.github.io\/images\/05_soldered_ugame.jpg\" \/>\n<p>For the remaining pictures, I turned the uGame off again, because the bright\nlight from the screen can be really disturbing when fiddling with those tiny\ncomponents, but do not worry, it was working all the&nbsp;time.<\/p>\n<p>Now you will need the other circuit board and the zip&nbsp;ties.<\/p>\n<img alt=\"The additional components needed to finish the case, neatly arranged\" src=\"https:\/\/logout22.github.io\/images\/06_required_additional_components.jpg\" \/>\n<p>I know, the arrangement is far from perfect, and I need more training\nbefore I can attend <a class=\"reference external\" href=\"https:\/\/www.youtube.com\/watch?v=QEN5-_93gQg\">Stackenblocken<\/a>.<\/p>\n<p>Now comes the fiddly part: Put all cable ties through the holes\nthat you need to connect. Try to attach as many mounting holes of the\nuGame to the two boards as you can, and connect both boards with all cable\nties to make sure the case stays small and compact and the battery\nis properly secured within. I recommend you put the ugame on the side\nof the second board which is not fit with solder points. Even though\nit is not likely to form a short circuit if you have boards with individual\nsolder joints, you are on the safe side if there is no metal on the board\nunder the uGame&#8217;s back side at&nbsp;all.<\/p>\n<img alt=\"All zip ties pushed through the boards and the uGame, but not zipped\" src=\"https:\/\/logout22.github.io\/images\/07_all_zip_ties.jpg\" \/>\n<p>Now, carefully close the cable ties, going in small steps of few centimeters\non each of them in round robin so that you get a somewhat straightly aligned case.\nYou may need multiple cable ties to attach them in the correct&nbsp;fashion.<\/p>\n<img alt=\"The finished case from the side\" src=\"https:\/\/logout22.github.io\/images\/08_case_side.jpg\" \/>\n<img alt=\"The finished case from the top\" src=\"https:\/\/logout22.github.io\/images\/09_case_top.jpg\" \/>\n<img alt=\"Front view of the finished case\" src=\"https:\/\/logout22.github.io\/images\/10_case_front.jpg\" \/>\n<p>Now, when you connect the finished sandwich to the computer again,\nit should start charging the battery and light the <span class=\"caps\">CHARGE<\/span> indicator <span class=\"caps\">LED<\/span>.<\/p>\n<img alt=\"The running uGame with on the sandwich case with CHARGE LED on\" src=\"https:\/\/logout22.github.io\/images\/11_charging.jpg\" \/>\n<p>I hope this blog post was somewhat useful to you. If you have any questions\nor remarks feel free to send me a message (see <a class=\"reference external\" href=\"\/about\/\">About<\/a>).<\/p>\n<p>Thanks for&nbsp;reading!<\/p>\n<p>P.S.: I read just now, shortly before uploading, that\nuGame has been discontinued in favour of a new board by Adafruit\ncalled <a class=\"reference external\" href=\"https:\/\/www.adafruit.com\/product\/4200\">PyBadge<\/a> (see <a class=\"reference external\" href=\"https:\/\/hackaday.io\/project\/27629-game\/log\/164355-the-last-game\">The Last uGame<\/a>). If all of this sounded very tinkery\nto you and scared you off the very interesting field of Python\non the microcontroller, you may want to try out the Adafruit board instead\nwhich is certainly more mature.\nPersonally, I have no intention of buying one, as I am quite content with my uGame\n(I hope you could tell :)&nbsp;).<\/p>\n<\/div>\n","category":{"@attributes":{"term":"blog"}}},{"title":"Welcome!","link":{"@attributes":{"href":"https:\/\/logout22.github.io\/blog\/2019\/03\/24\/welcome\/","rel":"alternate"}},"published":"2019-03-24T23:55:00+02:00","updated":"2019-03-24T23:55:00+02:00","author":{"name":"Martin Unzner"},"id":"tag:logout22.github.io,2019-03-24:\/blog\/2019\/03\/24\/welcome\/","summary":"<p>Welcome to my new blog, where I will be posting updates on technology\nthat cannot be expressed as source code&nbsp;diffs.<\/p>\n<p>I will mostly talk about projects revolving around the retro computers\nthat I own, the bulk of which are electronic helper modules\nconnecting the old machines to the modern \u2026<\/p>","content":"<p>Welcome to my new blog, where I will be posting updates on technology\nthat cannot be expressed as source code&nbsp;diffs.<\/p>\n<p>I will mostly talk about projects revolving around the retro computers\nthat I own, the bulk of which are electronic helper modules\nconnecting the old machines to the modern ones,\nthereby making my life as an administrator a lot easier.\nOccasionally, I will also present new technology that I acquired\nand tell you why I got it and what I intend to do with&nbsp;it.<\/p>\n<p>I hope that these articles will be useful as references for me\n(e.g. in case something breaks and I need to redo it),\nbut also help others to build similar things while\nideally cutting short on the research and avoiding the mistakes that I&nbsp;made.<\/p>\n<p>Enjoy!&nbsp;:)<\/p>\n","category":{"@attributes":{"term":"blog"}}}]}