start . me .
Directory path . web .

HTML Document File : copyjump.html

<!doctype html>
<html lang="en">
<head>
<title>copyjump</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>

<style>
button { padding: 1em; margin-top: 1em; margin-right: 1em; }
#log  { margin-top: 1em; }
</style>

<button onclick="program_setup('integer_counter')">count to 255</button>
<button onclick="program_setup('integer_sum')">sum of 2 bytes</button>
<button onclick="program_setup('not')">NOT of 1 bit</button>
<button onclick="program_setup('or')">OR of 2 bits</button>
<button onclick="program_setup('sum1')">sum of 2 bits</button>

<div id="log">Log.</div>

<script>
function log_write(text){
	document.all.log.innerHTML+=text
}

function io_read_bit_from_input_port(){
  html="<div>input bit: "
  + "<button onclick='read_bit(this, 0)'>0</button>"
  + "<button onclick='read_bit(this, 1)'>1</button>"
  + " (select which bit!)  </div>"
	log_write(html)
}

read_bit = function(source, value){
  bit_data=value
  source.parentElement.innerHTML=" input bit: " + value + ". "
  data_input = true
  timeout=setTimeout(step,0)
}

function bits_to_integer(bits){
    var accumulator = 0
    for(entry of bits.entries()){
        accumulator += entry[1] * 2**entry[0]
    }
    return accumulator
}

var byte_accumulator = []
function io_write_bit_to_output_port(bit_data){
	log_write("<div> emitted bit: "+bit_data+". </div>")

    byte_accumulator.push(bit_data)
    if(byte_accumulator.length==8){
        log_write("<div> emitted number: "+bits_to_integer(byte_accumulator)+". emitted bits: ["+ byte_accumulator.join('') +"]. </div>")
        byte_accumulator = []
    }
}

program_not=[

["DESTINATION_PATH_SELECTOR_BIT", "ORIGIN_INPUT_PORT", 1,2],

["DESTINATION_OUTPUT_PORT", "ORIGIN_CONSTANT_ONE", "INSTRUCTION_EXIT","INSTRUCTION_EXIT"],

["DESTINATION_OUTPUT_PORT", "ORIGIN_CONSTANT_ZERO", "INSTRUCTION_EXIT","INSTRUCTION_EXIT"],

]

program_or=[
["DESTINATION_PATH_SELECTOR_BIT", "ORIGIN_INPUT_PORT", 1,2],
["DESTINATION_PATH_SELECTOR_BIT", "ORIGIN_INPUT_PORT", 3,4],
["DESTINATION_PATH_SELECTOR_BIT", "ORIGIN_INPUT_PORT", 4,4],


["DESTINATION_OUTPUT_PORT", "ORIGIN_CONSTANT_ZERO", "INSTRUCTION_EXIT","INSTRUCTION_EXIT"],

["DESTINATION_OUTPUT_PORT", "ORIGIN_CONSTANT_ONE", "INSTRUCTION_EXIT","INSTRUCTION_EXIT"],

]

program_sum1=[
["DESTINATION_PATH_SELECTOR_BIT", "ORIGIN_INPUT_PORT", 1,2],
["DESTINATION_PATH_SELECTOR_BIT", "ORIGIN_INPUT_PORT", 3, 5],
["DESTINATION_PATH_SELECTOR_BIT", "ORIGIN_INPUT_PORT", 7, 9],

["DESTINATION_OUTPUT_PORT", "ORIGIN_CONSTANT_ZERO", 4,4],
["DESTINATION_OUTPUT_PORT", "ORIGIN_CONSTANT_ZERO", "INSTRUCTION_EXIT","INSTRUCTION_EXIT"],

["DESTINATION_OUTPUT_PORT", "ORIGIN_CONSTANT_ONE", 6,6],
["DESTINATION_OUTPUT_PORT", "ORIGIN_CONSTANT_ZERO", "INSTRUCTION_EXIT","INSTRUCTION_EXIT"],

["DESTINATION_OUTPUT_PORT", "ORIGIN_CONSTANT_ONE", 8,8],
["DESTINATION_OUTPUT_PORT", "ORIGIN_CONSTANT_ZERO", "INSTRUCTION_EXIT","INSTRUCTION_EXIT"],

["DESTINATION_OUTPUT_PORT", "ORIGIN_CONSTANT_ZERO", 10,10],
["DESTINATION_OUTPUT_PORT", "ORIGIN_CONSTANT_ONE", "INSTRUCTION_EXIT","INSTRUCTION_EXIT"],

]

program_integer_counter=[[3, 4, 1, 1],
[3, 5, 2, 2],
[3, 6, 3, 3],
[3, 7, 4, 4],
[3, 8, 5, 5],
[3, 9, 6, 6],
[3, 10, 7, 7],
[3, 11, 8, 8],
[2, 4, 17, 9],
[2, 5, 17, 10],
[2, 6, 17, 11],
[2, 7, 17, 12],
[2, 8, 17, 13],
[2, 9, 17, 14],
[2, 10, 17, 15],
[2, 11, 17, 16],
[0, 0, 50, 50],
[2, 4, 18, 20],
[4, 1, 19, 19],
[0, 0, 0, 0],
[4, 0, 21, 21],
[2, 5, 22, 24],
[5, 1, 23, 23],
[0, 0, 0, 0],
[5, 0, 25, 25],
[2, 6, 26, 28],
[6, 1, 27, 27],
[0, 0, 0, 0],
[6, 0, 29, 29],
[2, 7, 30, 32],
[7, 1, 31, 31],
[0, 0, 0, 0],
[7, 0, 33, 33],
[2, 8, 34, 36],
[8, 1, 35, 35],
[0, 0, 0, 0],
[8, 0, 37, 37],
[2, 9, 38, 40],
[9, 1, 39, 39],
[0, 0, 0, 0],
[9, 0, 41, 41],
[2, 10, 42, 44],
[10, 1, 43, 43],
[0, 0, 0, 0],
[10, 0, 45, 45],
[2, 11, 46, 48],
[11, 1, 47, 47],
[0, 0, 0, 0],
[11, 0, 49, 49],
[0, 0, 0, 0],
]

program_integer_sum=[[2, 3, 1, 15],
[4, 3, 2, 2],
[5, 0, 3, 3],
[2, 4, 4, 6],
[6, 0, 5, 5],
[0, 0, 8, 8],
[2, 5, 4, 7],
[6, 1, 8, 8],
[2, 4, 9, 10],
[2, 5, 11, 13],
[2, 5, 13, 11],
[3, 0, 12, 12],
[0, 0, 29, 29],
[3, 1, 14, 14],
[0, 0, 29, 29],
[4, 3, 16, 16],
[5, 0, 17, 17],
[2, 4, 18, 19],
[2, 5, 20, 22],
[2, 5, 22, 22],
[6, 0, 21, 21],
[0, 0, 23, 23],
[6, 1, 23, 23],
[2, 4, 24, 25],
[2, 5, 28, 26],
[2, 5, 26, 28],
[3, 0, 27, 27],
[0, 0, 29, 29],
[3, 1, 29, 29],
[2, 3, 30, 44],
[4, 3, 31, 31],
[5, 6, 32, 32],
[2, 4, 33, 35],
[6, 0, 34, 34],
[0, 0, 37, 37],
[2, 5, 33, 36],
[6, 1, 37, 37],
[2, 4, 38, 39],
[2, 5, 40, 42],
[2, 5, 42, 40],
[3, 0, 41, 41],
[0, 0, 58, 58],
[3, 1, 43, 43],
[0, 0, 58, 58],
[4, 3, 45, 45],
[5, 6, 46, 46],
[2, 4, 47, 48],
[2, 5, 49, 51],
[2, 5, 51, 51],
[6, 0, 50, 50],
[0, 0, 52, 52],
[6, 1, 52, 52],
[2, 4, 53, 54],
[2, 5, 57, 55],
[2, 5, 55, 57],
[3, 0, 56, 56],
[0, 0, 58, 58],
[3, 1, 58, 58],
[2, 3, 59, 73],
[4, 3, 60, 60],
[5, 6, 61, 61],
[2, 4, 62, 64],
[6, 0, 63, 63],
[0, 0, 66, 66],
[2, 5, 62, 65],
[6, 1, 66, 66],
[2, 4, 67, 68],
[2, 5, 69, 71],
[2, 5, 71, 69],
[3, 0, 70, 70],
[0, 0, 87, 87],
[3, 1, 72, 72],
[0, 0, 87, 87],
[4, 3, 74, 74],
[5, 6, 75, 75],
[2, 4, 76, 77],
[2, 5, 78, 80],
[2, 5, 80, 80],
[6, 0, 79, 79],
[0, 0, 81, 81],
[6, 1, 81, 81],
[2, 4, 82, 83],
[2, 5, 86, 84],
[2, 5, 84, 86],
[3, 0, 85, 85],
[0, 0, 87, 87],
[3, 1, 87, 87],
[2, 3, 88, 102],
[4, 3, 89, 89],
[5, 6, 90, 90],
[2, 4, 91, 93],
[6, 0, 92, 92],
[0, 0, 95, 95],
[2, 5, 91, 94],
[6, 1, 95, 95],
[2, 4, 96, 97],
[2, 5, 98, 100],
[2, 5, 100, 98],
[3, 0, 99, 99],
[0, 0, 116, 116],
[3, 1, 101, 101],
[0, 0, 116, 116],
[4, 3, 103, 103],
[5, 6, 104, 104],
[2, 4, 105, 106],
[2, 5, 107, 109],
[2, 5, 109, 109],
[6, 0, 108, 108],
[0, 0, 110, 110],
[6, 1, 110, 110],
[2, 4, 111, 112],
[2, 5, 115, 113],
[2, 5, 113, 115],
[3, 0, 114, 114],
[0, 0, 116, 116],
[3, 1, 116, 116],
[2, 3, 117, 131],
[4, 3, 118, 118],
[5, 6, 119, 119],
[2, 4, 120, 122],
[6, 0, 121, 121],
[0, 0, 124, 124],
[2, 5, 120, 123],
[6, 1, 124, 124],
[2, 4, 125, 126],
[2, 5, 127, 129],
[2, 5, 129, 127],
[3, 0, 128, 128],
[0, 0, 145, 145],
[3, 1, 130, 130],
[0, 0, 145, 145],
[4, 3, 132, 132],
[5, 6, 133, 133],
[2, 4, 134, 135],
[2, 5, 136, 138],
[2, 5, 138, 138],
[6, 0, 137, 137],
[0, 0, 139, 139],
[6, 1, 139, 139],
[2, 4, 140, 141],
[2, 5, 144, 142],
[2, 5, 142, 144],
[3, 0, 143, 143],
[0, 0, 145, 145],
[3, 1, 145, 145],
[2, 3, 146, 160],
[4, 3, 147, 147],
[5, 6, 148, 148],
[2, 4, 149, 151],
[6, 0, 150, 150],
[0, 0, 153, 153],
[2, 5, 149, 152],
[6, 1, 153, 153],
[2, 4, 154, 155],
[2, 5, 156, 158],
[2, 5, 158, 156],
[3, 0, 157, 157],
[0, 0, 174, 174],
[3, 1, 159, 159],
[0, 0, 174, 174],
[4, 3, 161, 161],
[5, 6, 162, 162],
[2, 4, 163, 164],
[2, 5, 165, 167],
[2, 5, 167, 167],
[6, 0, 166, 166],
[0, 0, 168, 168],
[6, 1, 168, 168],
[2, 4, 169, 170],
[2, 5, 173, 171],
[2, 5, 171, 173],
[3, 0, 172, 172],
[0, 0, 174, 174],
[3, 1, 174, 174],
[2, 3, 175, 189],
[4, 3, 176, 176],
[5, 6, 177, 177],
[2, 4, 178, 180],
[6, 0, 179, 179],
[0, 0, 182, 182],
[2, 5, 178, 181],
[6, 1, 182, 182],
[2, 4, 183, 184],
[2, 5, 185, 187],
[2, 5, 187, 185],
[3, 0, 186, 186],
[0, 0, 203, 203],
[3, 1, 188, 188],
[0, 0, 203, 203],
[4, 3, 190, 190],
[5, 6, 191, 191],
[2, 4, 192, 193],
[2, 5, 194, 196],
[2, 5, 196, 196],
[6, 0, 195, 195],
[0, 0, 197, 197],
[6, 1, 197, 197],
[2, 4, 198, 199],
[2, 5, 202, 200],
[2, 5, 200, 202],
[3, 0, 201, 201],
[0, 0, 203, 203],
[3, 1, 203, 203],
[2, 3, 204, 218],
[4, 3, 205, 205],
[5, 6, 206, 206],
[2, 4, 207, 209],
[6, 0, 208, 208],
[0, 0, 211, 211],
[2, 5, 207, 210],
[6, 1, 211, 211],
[2, 4, 212, 213],
[2, 5, 214, 216],
[2, 5, 216, 214],
[3, 0, 215, 215],
[0, 0, 232, 232],
[3, 1, 217, 217],
[0, 0, 232, 232],
[4, 3, 219, 219],
[5, 6, 220, 220],
[2, 4, 221, 222],
[2, 5, 223, 225],
[2, 5, 225, 225],
[6, 0, 224, 224],
[0, 0, 226, 226],
[6, 1, 226, 226],
[2, 4, 227, 228],
[2, 5, 231, 229],
[2, 5, 229, 231],
[3, 0, 230, 230],
[0, 0, 232, 232],
[3, 1, 232, 232],
[3, 6, 233, 233],
]

var timeout = null

program_setup=function(program_name){

    if(timeout!=null) clearTimeout(timeout)

	document.all.log.innerHTML="Log.";
	program=window["program_"+program_name]
    current_instruction_index=0
	data_input=false

    memory=[]
    for (var i = 0; i < 999; i++) {
        memory[i]=0
    }
    
    path_selector_bit=0

    byte_accumulator = []

    timeout=setTimeout(step,0)
}

// execution loop
function step(){

// fetch current intruction
current_instruction = program[current_instruction_index]
console.log(current_instruction)

// ---------- bit-copy operation -----------

// 2nd field is for copy-origin
field_origin = current_instruction[1]

if( data_input ) { data_input = false } else
if( field_origin == "ORIGIN_INPUT_PORT" || field_origin == 3) {

	// read 1 bit from the input port
	io_read_bit_from_input_port()
	return

}else if( field_origin == "ORIGIN_CONSTANT_ZERO" || field_origin == 0) {

	// constant 0
	bit_data = 0

} else if( field_origin == "ORIGIN_CONSTANT_ONE" || field_origin == 1){

	// constant 1
	bit_data = 1

} else {

	// read data from memory
	bit_data = memory[field_origin]

}

// write the data that was read

// 1st field is copy-destination
field_destination = current_instruction[0]

if( field_destination == "DESTINATION_PATH_SELECTOR_BIT" || field_destination == 2) {

	path_selector_bit = bit_data

} else if ( field_destination == "DESTINATION_OUTPUT_PORT" || field_destination == 3) {

	io_write_bit_to_output_port( bit_data )

} else {

	// write data to memory
	memory[field_destination] = bit_data

}

//  -------- path selection -------------

if( path_selector_bit == 0 ) {

	field_instruction_for_case_zero = current_instruction[2]
	current_instruction_index = field_instruction_for_case_zero

} else if( path_selector_bit == 1 ) {

	field_instruction_for_case_one = current_instruction[3]
	current_instruction_index = field_instruction_for_case_one
}

if(current_instruction_index!="INSTRUCTION_EXIT" && current_instruction_index<program.length) timeout=setTimeout(step,0)

} // end of execution loop, next instruction
</script>

<script src="show-source.js"></script>

</body>
</html>