Skip to content

wireframe

ArcadeTV edited this page May 22, 2021 · 8 revisions

wireframe

Simple wireframe background animation.


In this example I'll showcase the creation of a symmetric background that animates by changing the tilemap of plane B on vblank. To save memory only one quarter of the gfx are used as tiles in vram and then arranged and flipped in the tilemap:

sourceGFX

To save even more space I could have devided the gfx into rectangles and diagonals and use either of them in plane A or B, but I wanted plane A to be free for other stuff, so the resulting tiledata has 785 tiles.

To create tiledata and a consistant palette across all 16 images I stitched them into one single source image before using ImaGenesis4000 to create optimized tiledata, a tilemap and a palette. See the source image here.

Since the source gfx are 20 tiles wide and 14 tiles high (half of a 320x244 px screen) I used a HexEditor (HxD) to save 16 chucks of 280 words (16 frames in the animation, 20x14 tiles equal 280) and added the remaining flipped entries by setting the corresponding bits in the values:

  • horz.Flip: MapEntry OR 0x800
  • vert.Flip: MapEntry OR 0x1000
  • horz+vert.Flip: MapEntry OR 0x1800

The order of the remaining entries has to be reversed accordingly for symmetry. To create the tilemaps for each each frame easily I wrote this simple PHP scripts that reads the binary tilemap data created with ImaGenesis4000 directly and outputs the completely arranged maps for each frame as ASM:

<pre>
<?php
    function fliph($item){
        return $item|0x800;
    }
    function flipv($item){
        return $item|0x1000;
    }
    function fliphv($item){
        return $item|0x1800;
    }

    function bin2int($item){
        return unpack('n', $item);
    }

    $filepath     = 'map_20x238.bin';
    $handle       = fopen($filepath, "rb");
    $fsize        = filesize($filepath);
    $contents     = fread($handle, $fsize);
    fclose($handle);

    $bin_array   = str_split($contents, 2);
    $int_array   = [];
    $int_arrayH  = [];
    $int_arrayV  = [];
    $int_arrayHV = [];

    foreach($bin_array as $value){
        $tmp = bin2int($value);
        $int_array[]   = $tmp[1];
        $int_arrayH[]  = fliph($tmp[1]);
        $int_arrayV[]  = flipv($tmp[1]);
        $int_arrayHV[] = fliphv($tmp[1]);
    }


    for($i=1; $i<=16; $i++){                             // for each frame
        echo "\t".'; ' .$i."\n";                        // comment with frame no.
        for($y=0;$y<14;$y++){                          // upper half
            echo "\t".'dc.w'."\t"
            .''.implode(',',array_slice($int_array,($i*280)+($y*20),20))
            .','.implode(',',array_reverse(array_slice($int_arrayH,($i*280)+($y*20),20)))
            ."\n";
        }
        for($y=(14-1);$y>=0;$y--){                  // lower half
            echo "\t".'dc.w'."\t"
            .''.implode(',',array_slice($int_arrayV,($i*280)+($y*20),20))
            .','.implode(',',array_reverse(array_slice($int_arrayHV,($i*280)+($y*20),20)))
            ."\n";
        }
    }

?>
</pre>
Clone this wiki locally