Class: ImgToScript::Generators::HexMask::Enhanced

Inherits:
ImgToScript::Generators::HexMask show all
Defined in:
lib/img_to_script/generators/hex_mask/enhanced.rb

Overview

Generates image rendering script using the DRAW/M statement with the ‘enhancements’.

To save space at the MPO-10 cart, it’s possible to replacelong sequences of repeating chunks with a shorter (in terms of number of chars required to store the statement) code, e.g.:

xxDRAWMFFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFF // 43 bytes – 16 x ‘AA’. xxDRAWMFF:FORI=1TO16:DRAWMAA:NEXTI:DRAWMFF // 42 bytes – repeating chunks were replaced with a loop.

Same principle could be applied to eliminate long sequences of white pixels, e.g.: xxDRAWMFF00000000000000000000FF // 31 bytes – 10 x ‘00’. xxDRAWMFF:DRAWOxxx,yy:DRAWMFF // 29 bytes – replaced with a manual shift.

The algorithm is:

  1. apply RLE to the array of hex chunks (DRAW/M arguments);

  2. loop through the array of run-lengths: take an element (a ‘chunk’) and heck if it’s run-length is larger than an estimated value (MIN_REP_CHUNKS or MIN_REP_WH_CHUNKS);

  3. if true: add pending chunks to the BASIC code; then append a FOR-NEXT loop or DRAW/O. Clear pending chunks array and continue to loop through the array of run-lengths.

  4. otherwise: add current chunk to the array of pending chunks;

  5. after the loop: add pending chunks.

Constant Summary collapse

MIN_REP_CHUNKS =
16
MIN_REP_WH_CHUNKS =
9