Wednesday, April 4, 2012

The D40 Commodore Image format

The D40 is an exercise in using my flexible image configuration.  Its goal is to design the largest image possible, which still uses the header block (and only the header block) to store BAM entries.

In other words, this format uses the header block as its primary design limitation.

Header

The most efficient existing Commodore header is used by the D81.  It makes a great place to start out.

The D81's header starts out the same as all others: a two-byte pointer to the first directory sector, then the DOS type, then one byte with $00, for a total of 4 bytes.

The label offset is at 0x04.  All Commodore labels consist of a 16-byte label, two $A0 bytes, two bytes for the Disk ID, one more $A0, two bytes for the DOS Type, and a final $A0 byte, for a total of 24 bytes.

That leaves (256 - 28) = 228 bytes for the BAM.  Now the fun begins.

BAM

The Block Allocation Map (BAM) consists of an array of records, one record for each track on the disk.  The first byte of each record is the "sectors free" count for that track.  The remaining data is a bitmap of the sector allocation for that track: a "1" means that sector is used, while a "0" means the sector is unallocated and free for use.

A little calculation will find several schemes which fits into 228 bytes.  Larger bitmaps tend to be more efficient with the space available.  The layout I select is 25 tracks of 64 sectors each.  The number of bytes needed for the BAM is (25 x (1+64/8)) = 25 x 9 = 225 bytes.

The total capacity of this image would be (25 x 64) blocks = 1600 blocks, or 400k.

Layout

I like to see the header at track 1 -- it's easier for a programmer to get at than at midpoint.  The directory can have the remaining 63 sectors in track 1, for a maximum of 63 * 8 = 504 files, which should be plenty.

The remainder of the disk is usable for file storage, for a total storage space of 400 - 8 = 392k.

Tuesday, April 3, 2012

Commodore Disk Image headers, again

One minor nitpick about Commodore disk images is that they have no signature line.  The only way you can tell what they are is to look at the extension, the file size, and perhaps try to jump to the header sector and "see" if it looks right.  While this is not a major problem, I think there is a simple solution; namely, to add a signature to each disk image.

A signature is a small, initial data set which you can use to determine the nature of the disk unconditionally.  My suggestion is to look for an optional 32 byte signature on all Commodore images; if it proves useful, then over time all such images will have this signature.

Examples.

D64 images will start with "1541 DISK IMAGE ".
D71 images will start with "1571 DISK IMAGE ".
D81 images will start with "1581 DISK IMAGE ".
D82 images will start with "8250 DISK IMAGE ".

...and so on.

The remaining 16 bytes should be used to specify the image configuration as clearly as possible.  For example, the D64 should have a byte for how many tracks are present (i.e. 35, 40, or some other number), and a byte indicating whether or not error bytes are appended to the end of the image.  I would also suggest another byte used to indicate an auxiliary directory track, but that starts to make things complicated.

As I said, this data can be inferred from the image itself, but it is much better to be explicit, and the simplest way to do that is to lead with a short signature block.

Having a "number of tracks" byte could be space-efficient as well, because many images have content  much smaller than the disk's capacity; in these cases it would be possible to publish a smaller D64. Since the 18th track is required, the smallest D64 would be 18 tracks long, or about 95k -- almost half the size of the standard D64.

Wednesday, March 28, 2012

Java to ActionScript (via Perl)

#!/usr/bin/perl

while(<>)
{
   s/\bfinal//;
   s/\b(int|long) (\w+)/ var $2:int/;
   s/\bboolean (\w+)/ var $1:Boolean/;
   s/\bString (\w+)/ var $1:String/;
   s/System.out.println/trace/;

   s/ (void|int|String) (\w+\(.*?\))/ function $2:$1/;


   print;
}


The Commodore 1541 disk drive is a computer, with a 6502 microprocessor and its own RAM.  It talks to the Commodore 64 via a hastily-built proprietary serial variant of the IEEE488 bus.

And it's a pain to emulate.

Luckily, it's a solved problem, more or less, if your chosen programming language is C++ or Java.  If you want to do it in, say, ActionScript, then you are out of luck.

...unless you know Perl.

ActionScript, as you may know, has a fuzzy relationship with Java.  Its compiler is written in Java.  Its VM may very well be based on the JVM.  So it is no surprise that ActionScript source is in many ways a cipher of Java.

I wrote a very small Perl script to convert Java source to ActionScript source.  It doesn't do a 100% job, but in all things the best is the enemy of the good, and the Burrito Principle holds (80% of the meat is in 20% of the burrito).  So this gets me most of the way there, leaving small scraps to deal with (instead of facing a complete and more tedious rewrite).

Saturday, March 24, 2012

I like Objective C

So far.  I'm not sure if it's as accessible as ActionScript, but I really appreciate its strict adherence to Design Patterns.  Just a few lessons in, and we've already done MVC and Delegates.

And, of course, I always loved the Smalltalk syntax.

Friday, March 2, 2012

Time for a new internet browser

Time to be an old grump for a moment.

I've said it before, I'll say it again.  It's time to rewrite the browser.  Invent, create, realize a new way of browsing the internet.

Forget HTML, JavaScript, FlashPlayer et al.  Computers are powerful; why aren't browsers?  Why can't you develop on the browser the same way you develop directly onto the operating system?  Why isn't there a virtual machine to which you may directly target compilers?  That way, you have your cake and can eat it, too.

I'm not saying the browser should be an operating system; it's an application.  However, it should integrate with operating systems.  For example, security is an OS problem; it should not be an application's problem.  Why solve the same problem over and over again?  There are realtime impacts to this: HTTP and HTTPS are heavy compared to TFTP.

I am saying that HTML is annoying.  I don't think HTML5 will solve that problem - at least, it won't solve it anytime soon.  HTML is to the browser like Java is to the OS: it's a language, a display and layout language.  It defines the View.

Thursday, February 23, 2012

CargoCult, part one

This is a post about my dream language, which I've named CargoCult.  It's a mashup of Perl, Objective-C, JavaScript, Shell, and other things.


It does NOT eschew the use of shifted characters -- it just requires that they be important, with a value greater than the extra effort of typing shift + something.


Object Notation

CargoCult is a dynamic object language.  This means you have type-able structures, potentially dynamic, which have attributes and methods.

Core language features -- arrays, hashes, variables -- are objects.  For example, the implicit array type is an object, so you can do things like this:

    return [d1, d2, d3].sort.reverse.pop; 


Hashes and arrays use the grouping notation of braces. An array is a comma-separated list of scalars.  A hash is a comma-separated list of assignments.

     my array = 1, 2, 3, 'four';  # also [ 1, 2, 3, 'four' ]
     my hash  = [year = 2012, month = two, day = 23];


Hash and array accesses are object calls.

    my value = hash.year;
    my other_value = array.0;


Method Calling with Parameters

When we write methods in any language, we typically name formal parameters.  For example:

string myFunction( foo, bar )
{
   foo + ': ' + bar;
}

foo and bar are formal parameters, i.e. the names used in the method.

When calling a method, parameters are passed in by name.  In other words, the parameters are more or less a hash.

my str = myObj myFunction .foo 'hello' .bar 'world';


When you have to nest the call, use the backslash to indicate a method call (rather than a new array), and then braces for grouping.

           my str = myObj myFunction .foo \[myObj myFunction .foo 'hello' .bar 'world'] .bar '!';






Thursday, October 13, 2011

YSON is a Structured Object Notation

Here's my proposed structure.  I want to keep the quotes to a minimum.

records:
[
    !record record:
    {
      !game &001 game:
      {
        date: 'March 2, 1962',
        versus: New York
      },
      notes: Awesome!,
      number: 100,
      !player &002 player:
      {
        name: Wilt Chamberlain,
        team: Philadelphia
      },
      record: Most points single game
    },
    
    !record record:
    {
        game: *001,
        number: 59,
        player: *002,
        record: 'Most points, one half'
    }
]


object
    hash

hash
    {}
    { pairs }

pairs
    key: value
    key: value, ...

key:
    string
    &id string
    !type string
    !type &id string
    
list
    []
    [ elements ]

elements
    value
    value, elements

value
    key
    string
    number
    object
    hash
    list
    true
    false
    null