vic.html

<!DOCTYPE HTML>
<html>
 <head>
  <meta charset="utf-8">
  <title>VIC-II experiments</title>
  <link href="../css/candy.css" rel="stylesheet">  
  <link href="../style.css" rel="stylesheet">
 </head>
 <body class="candy greasy-green">

  <h1>VIC-II experiments</h1>

  <canvas class="c64" width="404" height="284" style="width: 100%; border: 1px solid gray">
No soup for you :-(
  </canvas>

  <script>
    var memory = new Uint8Array(0x10000)

    var C64 = {
        memory: memory
    }

    // foreground and background colors
    memory[0xd020] = 14
    memory[0xd021] = 6

    for(var i = 0; i < 256; i++) {
        memory[0x0400 + i] = i
    }

    // color ram
    memory[0xd800 + 12 * 40 + 17] = 1
    memory[0xd800 + 12 * 40 + 22] = 1

    // sprite at 100,100
    memory[0xd000] = 100
    memory[0xd001] = 100
    memory[0xd016] = 1                // sprite enable
    memory[0x400 + 1016] = 255        // sprite pointer (255 * 64 = address 16320)
    memory[16320] = 0x55              // dots
  </script>

  <details open>
   <summary title="Click to open/close">Log messages</summary>
   <pre class="log"><tt></tt></pre>
  </details>

  <script src="log.js"></script>
  <script src="vic.js"></script>

  <script>
    var request = new XMLHttpRequest()
    request.open('GET', '../roms/chargen', true)
    request.responseType = 'arraybuffer'
    request.onload = function() {
        if(this.status == 200) {
           var program = new Uint8Array(this.response)
           C64.memory.set(program, 0x1000)
 
           // charset
           memory[0x1000] = parseInt('00111100', 2)
           memory[0x1001] = parseInt('01000010', 2)
           memory[0x1002] = parseInt('10100101', 2)
           memory[0x1003] = parseInt('10000001', 2)
           memory[0x1004] = parseInt('10100101', 2)
           memory[0x1005] = parseInt('10011001', 2)
           memory[0x1006] = parseInt('01000010', 2)
           memory[0x1007] = parseInt('00111100', 2)

           var start = performance.now()

           while(!C64.vic.tick()) {
                memory[0xd020] = memory[0xd012] % 16
           }
           C64.vic.draw()

           Log.writeline('frame rendered in ', (performance.now() - start).toFixed(1), ' ms')
        }
    }
    request.send()
  </script>

  </body>
</html>