Friday, January 29, 2021

how the atari 2600 merges time and space

"Man, you must have a deep understanding of TIA. I think for a lot of casual atari devs (funny that that's not a contradiction in terms, quite), everything is just there and kind of arbitrary, but you must have some idea of like... how the player 'tripler' flag change circuits."

"As a matter of fact, all sprites on the VCS are represented as counters that increment with the pixel clock (and wrap at 160). These go into a decode matrix that triggers drawing when certain trip points are reached. Changing the number of copies activates different parts of the decode matrix --- if you have three copies, drawing is triggered for tree different counter values."
Me and Christian Speckner, author of the excellent Stellerator Atari 2600 emulator
We're having a cordial conversation about programming (both Atari and modern web) on the Atari Age forums, a spin off of my recent Sisyphus project.

His point blew my mind a little bit... (especially interesting since he gives props to my early 2600 tutorials helping him when he first started out) I've dabbled a bit in Atari and read "Racing the Beam", but never thought about this particular merge of Time and Space: everything that puts a graphic in the right place is fundamentally based on these timers! (The amazingness of this point probably has a pretty small audience, but still...)

Thursday, January 28, 2021

going without a build process

 I like this guy

human-readable sorting of contents in storybook

Storybook slightly undersells its sorting capability... the array you pass to the exported variable parameters.options.storySort.order can be a mix of strings and arrays of [strings or more such arrays], and empircally it seems to work many levels deep. So for example a hierarchy like 

Documentation
	Overview
	Design System Workflow
	Getting Started Guide
		Intro
		Designer Guide
		Developer Guide
Components

can be described as the following:

[
 "Documentation",
 [
  "Overview",
  "Design System Workflow",
  "Getting Started Guide",
  ["Intro","Designer Guide","Developer Guide"]
],
 "Components"
]

But I admit, I didn't quite like that format - the way the contents of a section (like ["Intro, Designer,Developer Guide"]) were at the same level of its "parent" ("Getting Started Guide") seems odd to me, and I thought maybe it would be easier if the Table of Contents were human readable...

So I don't know if I over-engineered it, but I came up with this:

const toc = `
Documentation
 Overview
 Design System Workflow
 Getting Started Guide
  Intro
  Designer Guide
  Developer Guide
Components`;

const tocParse = (lines, ptr, currentDepth, arrayStack) => {
  if(ptr >= lines.length) return;
  const line = lines[ptr];
  const lineDepth = line.search(/\S/); // how many spaces before nonwhite space?
  if(lineDepth === -1) { // if -1 is empty line, skip and move to next
    return tocParse(lines, ptr + 1, currentDepth, arrayStack);
  }
  const title = line.trimLeft().trimRight();
  const currentArray = arrayStack[currentDepth];
  if(lineDepth === currentDepth) { // at this level, add and look to next one
    currentArray.push(title);
    tocParse(lines, ptr + 1, currentDepth, arrayStack);
  } else {
    if(lineDepth > currentDepth) { // deeper, make child array and re-parse line
      const subArray = [];
      currentArray.push(subArray);
      arrayStack.push(subArray);
      tocParse(lines, ptr, currentDepth + 1, arrayStack);
    } else { // more shallow, go up a level and re-parse line
      arrayStack.pop();
      tocParse(lines, ptr, currentDepth - 1, arrayStack );
    }
  }
};

const order = [];
const tocLines = toc.split('\n');
tocParse(tocLines, 0, 0, [order]);

The toc uses spaces not tabs, and so isn't super robust, but still, I think it does a good job having a string that looks like the end result drive the whole process.

Also, as I was building up that little recursive thing, I wanted to test my work - a convenient way of making sure two arrays (containing strings and other nested arrays only) are equal is to just do JSON.stringify() on 'em - unlike objects you don't have keys that might be in a weird order to worry about.

Wednesday, January 27, 2021

this...is....SISYPHUS! (using stellerator to embed playable atari games right in a web page straight from the files)

 I completed my third game for the Atari 2600 - SISYPHUS



More of a philosophical/existential joke than game, to be honest. You, Sisyphus, are condemned by the gods to roll a massive rock up a hill. 

Every time you fail, the rock gets a point.

(I made a mobile friendly web thing that played with the same idea before)

I used several community tools to pull this off - it's written in batari Basic (consulting Random Terrain's extensive documentation page)... I used my own PlayPal 2 and PlayfieldPal-bB for the graphics... my "IDE" was the Atari Dev Studio for Visual Studio Code, I used the Atari 2600 Label Maker for a semi-authentic looking frame (for some art I bought from shutterstock) In some ways the newest/most interesting tool was using the emulator Stellerator to put an in-browser version playable online. 

Christian Speckner, creator of Stellerator, actually uses my first Atari game FlapPing (née JoustPong) as an example embedded demo

Stellerator has detailed instructions, but isn't 100% clear on "how do I just make a simple webpage loading an external .bin ROM". The example demo embeds the ROM as a base64 string, but here is the javascript that includes an XMLHttpRequest to load the byte array from the .bin, my additions in bold.

        <script src="stellerator_embedded.min.js"></script>
        <script>
            {
                
                
                // Shortcut to avoid typing out the namespace
                const Stellerator = $6502.Stellerator;
                // Create the stellerator instance
                const stellerator = new $6502.Stellerator(
                    // The canvas element
                    document.getElementById('stellerator-canvas'),
                    // The URL from which the web worker will be loaded
                    'stellerator_worker.min.js'
                );
                window.addEventListener('resize', () => 
                     stellerator.isFullscreen() || stellerator.resize());
               (async function(){
                    const response = await fetch('../sisyphus.bin');
                    const image = await response.arrayBuffer();
                    const byteArray = new Uint8Array(image);
                    stellerator.run(byteArray, Stellerator.TvMode.ntsc);
               })();
                // Expose the instance for tinkering.
                window.stellerator = stellerator;
            }

                        
        </script>
The .js files are available in a zip file from the github page.
My Sisyphus embed page has minimalist HTML, the FlapPing Demo is a little more robust about resizing and with more instructions.



Monday, January 25, 2021

custom sorting sections in storybook

Aargh, one of those silly "didn't read far enough in the documentation" -- Storybook DOES easily cover 2 levels of hierarchy, so you can have your main Documentation before your per-Component documentation, and then sorted Documentation sections (but if you need finer grained control than that, you're going to have to work harder.)

Assuming you already have a `export const parameters` object, just add this:

  options: {
    storySort: {
      order: ['Documentation', 
               ['Overview','Design System Workflow'], 
             'Components'],    
    },
  },

But before I read low enough on the page to see the previous example, I had the "roll your own sort function" on my mind., even for the simpler sort one level of sections version. This was the code I came up with... I kind of like sorting one array by the contents of another:

const knownSectionsForSorting = ['Documentation', 'Components'];

const positionOfContainingSection = (titlePath: string) => {
  const section = titlePath.substring(0, titlePath.indexOf('/'));
  return knownSectionsForSorting.indexOf(section);
};

export const parameters = {
  options: {
    storySort: (a, b) => {
      // story titles are the "kind" parameter of the second item of the info array
      const diffInSection =
        positionOfContainingSection(a[1].kind) -
        positionOfContainingSection(b[1].kind);
      return diffInSection || a[1].kind.localeCompare(b[1].kind);
    },
  },
};

You'd have to build something like that but more advanced if you need to sort individual files with a subsection of your Documentation section, for example.

And the documentation for doing that is a little light... odd that you have to look at "a[1].kind" to find the Title to sort on...

Saturday, January 23, 2021

problems playing multiplayer with friends in minecraft for switch

 (This is one of those, who knows, maybe it will help someone's google search results)

Online Minecraft on Nintendo Switch seems a little flakey, but even before that there are a few steps you can get wrong, especially if you haven't done much with the online play modes with friend in general...

1. The accounts on the two switches have to be friends (you can youtube up pretty easy instructions to exchange friends codes, it's on each accounts page not general settings)

2. One player creates the world, and they have to make sure multiplayer is turned on for that world

There's still a lot I don't understand (creating realms, which I think means you don't have to have a separate "host" machine so either player can work on the realm when the other is online) and this cross-account thing with Microsoft accounts, but the above were the toughest steps in getting it going. 

(I have both Switches in my posession, which made thing easier... trying to troubleshoot remotely when the other person is not so techie would have been tough!)

Friday, January 22, 2021

super tiny pixel font

For my current Atari 2600 project I may try making a digital clock using big, clunky playfield pixels. Luckily, for an old site I LOVED called Pixel Time (RIP,  here's my loving fan page) I made a font that could make words even on its absurdly limited 45x45 canvas:

(I think Nick had made an All-Caps version that I cribbed from a bit.)

Heh. I think I got my start with hyper-minimal fonts on the old Etcha-a-Sketch Animator, an early digital toy that let you make animations of 12 frames of 40x30 pixels (arranged in longer sequences)