<commit_before>var mapScale = 2;
var timeScale = 30;
var trace;
var frames = [];

var frameRate = 15;
var microsecsPerFrame = Math.floor(1000000 / frameRate);

var traceGraphics;
var mapGraphics;

function preload() {
  trace = loadStrings('assets/trace_reset.txt');
}

function setup() {
  createCanvas(512, 512);
  traceGraphics = createGraphics(512, 512);
  mapGraphics = createGraphics(512, 512);
  setFrameRate(frameRate);

  printMap();

  processTrace();

  // Uncomment this to save the map to PNG.
  //save('map.png');
}

function processTrace() {
  for (var i=0; i<trace.length; i++) {
    var line = trace[i];
    var tokens = line.split(" ");
    var timestamp = tokens[0];

    var frame = Math.floor(timestamp / microsecsPerFrame * timeScale);
    var reads;
    if (!frames[frame]) {
      reads = [];
      frames[frame] = {
        time: timestamp / 1000000,
        reads: reads
      };
    }
    else {
      reads = frames[frame].reads;
    }

    var addressHex = tokens[1];
    var address = parseInt(addressHex, 16);
    if (reads[address] === undefined) {
      reads[address] = 1;
    }
    else {
      reads[address]++;
    }
  }

  trace = null;
  console.log(frames.length);
}

function printMap() {
  var mg = mapGraphics;
  mg.rect(0, 0, 256, 256);

  function addrBlock(color, desc) {
    return function(x, y, size) {
      x *= mapScale;
      y *= mapScale;
      size *= mapScale;
      mg.fill(color);
      mg.rect(x, y, size, size);

      mg.fill(128);
      mg.textAlign(CENTER, CENTER);
      mg.text(desc, x, y, size, size);
    };
  }
  var ramColor = '#004000';
  var romColor = '#000080';
  var ioColor = '#800000';

  hilbertBlock(8, 0x0000, 0x10000, addrBlock(ramColor, "RAM"))

  hilbertBlock(8, 0x0000, 0x0100, addrBlock(ramColor, "System vars"));
  hilbertBlock(8, 0x0100, 0x0100, addrBlock(ramColor, "Stack"));
  hilbertBlock(8, 0x0200, 0x0100, addrBlock(ramColor, "System vars"));
  hilbertBlock(8, 0x0300, 0x0100, addrBlock(ramColor, "System vars"));
  
  hilbertBlock(8, 0x0400, 0x0400, addrBlock(ramColor, "Video memory"));

  hilbertBlock(8, 0xA000, 0x1000, addrBlock(romColor, "BASIC ROM"))
  hilbertBlock(8, 0xB000, 0x1000, addrBlock(romColor, "BASIC ROM"))
    
  hilbertBlock(8, 0xD000, 0x0400, addrBlock(ioColor, "VIC-II"))
  hilbertBlock(8, 0xD400, 0x0400, addrBlock(ioColor, "SID"))
  hilbertBlock(8, 0xD800, 0x0400, addrBlock(ioColor, "Color RAM"))
  hilbertBlock(8, 0xDC00, 0x0100, addrBlock(ioColor, "CIA #1"))
  hilbertBlock(8, 0xDD00, 0x0100, addrBlock(ioColor, "CIA #2"))
  hilbertBlock(8, 0xDE00, 0x0100, addrBlock(ioColor, "I/O #1"))
  hilbertBlock(8, 0xDF00, 0x0100, addrBlock(ioColor, "I/O #2"))
  
  hilbertBlock(8, 0xE000, 0x1000, addrBlock(romColor, "KERNAL ROM"));
  hilbertBlock(8, 0xF000, 0x1000, addrBlock(romColor, "KERNAL ROM"));
}

function hilbertBlock(maxLevel, location, sizeLinear, callback) {
  var level = Math.log2(sizeLinear) / 2;
  var size = 1 << level;

  var xy = hilbert.d2xy(maxLevel - level, location / sizeLinear);
  var x = xy[0] * size;
  var y = xy[1] * size;

  callback(x, y, size);
}


var frameNum = 50; //jump after memory test cycle
function draw() {
  console.log(frameNum);
  frameNum++;

  var frameData = frames[frameNum];

  background(0);
  image(mapGraphics, 0, 0);
  updateTraceGraphics(frameData);
  blendMode(ADD);
  image(traceGraphics, 0, 0);
  blendMode(BLEND);

  if (frameData) {
    stroke(255);
    fill(255);
    textSize(40);
    textAlign(LEFT, TOP);
    text(frameData.time, 0, 0, 288, 288)
  }
}

function updateTraceGraphics(frameData) {
  var tg = traceGraphics;

  tg.background(0, 64);

  if (!frameData)
    return;

  var reads = frameData.reads;
  console.log("instructions: " + reads.length);

  for (address in reads) {
    var xy = hilbert.d2xy(8, address);
    tg.noStroke();
    tg.fill(255);
    tg.rect(xy[0], xy[1], 1, 1);
  }
}<commit_msg>stop draw on traces finish (save energy)<commit_after>var mapScale = 2;
var timeScale = 30;
var trace;
var frames = [];

var frameRate = 15;
var microsecsPerFrame = Math.floor(1000000 / frameRate);

var traceGraphics;
var mapGraphics;

function preload() {
  trace = loadStrings('assets/trace_reset.txt');
}

function setup() {
  createCanvas(512, 512);
  traceGraphics = createGraphics(512, 512);
  mapGraphics = createGraphics(512, 512);
  setFrameRate(frameRate);

  printMap();

  processTrace();

  // Uncomment this to save the map to PNG.
  //save('map.png');
}

function processTrace() {
  for (var i=0; i<trace.length; i++) {
    var line = trace[i];
    var tokens = line.split(" ");
    var timestamp = tokens[0];

    var frame = Math.floor(timestamp / microsecsPerFrame * timeScale);
    var reads;
    if (!frames[frame]) {
      reads = [];
      frames[frame] = {
        time: timestamp / 1000000,
        reads: reads
      };
    }
    else {
      reads = frames[frame].reads;
    }

    var addressHex = tokens[1];
    var address = parseInt(addressHex, 16);
    if (reads[address] === undefined) {
      reads[address] = 1;
    }
    else {
      reads[address]++;
    }
  }

  trace = null;
  console.log(frames.length);
}

function printMap() {
  var mg = mapGraphics;
  mg.rect(0, 0, 256, 256);

  function addrBlock(color, desc) {
    return function(x, y, size) {
      x *= mapScale;
      y *= mapScale;
      size *= mapScale;
      mg.fill(color);
      mg.rect(x, y, size, size);

      mg.fill(128);
      mg.textAlign(CENTER, CENTER);
      mg.text(desc, x, y, size, size);
    };
  }
  var ramColor = '#004000';
  var romColor = '#000080';
  var ioColor = '#800000';

  hilbertBlock(8, 0x0000, 0x10000, addrBlock(ramColor, "RAM"))

  hilbertBlock(8, 0x0000, 0x0100, addrBlock(ramColor, "System vars"));
  hilbertBlock(8, 0x0100, 0x0100, addrBlock(ramColor, "Stack"));
  hilbertBlock(8, 0x0200, 0x0100, addrBlock(ramColor, "System vars"));
  hilbertBlock(8, 0x0300, 0x0100, addrBlock(ramColor, "System vars"));
  
  hilbertBlock(8, 0x0400, 0x0400, addrBlock(ramColor, "Video memory"));

  hilbertBlock(8, 0xA000, 0x1000, addrBlock(romColor, "BASIC ROM"))
  hilbertBlock(8, 0xB000, 0x1000, addrBlock(romColor, "BASIC ROM"))
    
  hilbertBlock(8, 0xD000, 0x0400, addrBlock(ioColor, "VIC-II"))
  hilbertBlock(8, 0xD400, 0x0400, addrBlock(ioColor, "SID"))
  hilbertBlock(8, 0xD800, 0x0400, addrBlock(ioColor, "Color RAM"))
  hilbertBlock(8, 0xDC00, 0x0100, addrBlock(ioColor, "CIA #1"))
  hilbertBlock(8, 0xDD00, 0x0100, addrBlock(ioColor, "CIA #2"))
  hilbertBlock(8, 0xDE00, 0x0100, addrBlock(ioColor, "I/O #1"))
  hilbertBlock(8, 0xDF00, 0x0100, addrBlock(ioColor, "I/O #2"))
  
  hilbertBlock(8, 0xE000, 0x1000, addrBlock(romColor, "KERNAL ROM"));
  hilbertBlock(8, 0xF000, 0x1000, addrBlock(romColor, "KERNAL ROM"));
}

function hilbertBlock(maxLevel, location, sizeLinear, callback) {
  var level = Math.log2(sizeLinear) / 2;
  var size = 1 << level;

  var xy = hilbert.d2xy(maxLevel - level, location / sizeLinear);
  var x = xy[0] * size;
  var y = xy[1] * size;

  callback(x, y, size);
}


var frameNum = 50; //jump after memory test cycle
function draw() {
  console.log(frameNum);
  frameNum++;

  var frameData = frames[frameNum];

  background(0);
  image(mapGraphics, 0, 0);
  updateTraceGraphics(frameData);
  blendMode(ADD);
  image(traceGraphics, 0, 0);
  blendMode(BLEND);

  if (frameData) {
    stroke(255);
    fill(255);
    textSize(40);
    textAlign(LEFT, TOP);
    text(frameData.time, 0, 0, 288, 288)
  }
  else {
    noLoop(); // stop
  }
}

function updateTraceGraphics(frameData) {
  var tg = traceGraphics;

  tg.background(0, 64);

  if (!frameData)
    return;

  var reads = frameData.reads;
  console.log("instructions: " + reads.length);

  for (address in reads) {
    var xy = hilbert.d2xy(8, address);
    tg.noStroke();
    tg.fill(255);
    tg.rect(xy[0], xy[1], 1, 1);
  }
}
{'fraction_non_alphanumeric': 0.1532669729453803, 'fraction_numerical': 0.07401735579377233, 'mean_word_length': 3.6127133608004707, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1517621', 'n_tokens_mistral': 3381, 'n_tokens_neox': 2912, 'n_words': 683}