Skip to content

Commit

Permalink
Templates, Template menu, More formats
Browse files Browse the repository at this point in the history
The template is selected using a popup menu invoked when the fish is
clicked in the text entry box.

Added a dedicated format for Partner 01.01 because it seems to want
faster recording speed.

Hello world templates for RK-like computers added.
  • Loading branch information
svofski committed Jul 18, 2017
1 parent 8ce3662 commit 0910d7f
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 48 deletions.
28 changes: 1 addition & 27 deletions assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,9 @@
//

importScripts('encodings.js');
importScripts('util.js');
importScripts('tape.js');

function Util() {
}

Util.char8 = function(val) {
if (val > 32 && val < 127) return String.fromCharCode(val);
return '.';
};

Util.hex8 = function(val) {
if (val < 0 || val > 255) return "??";

var hexstr = "0123456789ABCDEF";
return hexstr[(val & 0xf0) >> 4] + hexstr[val & 0x0f];
};

Util.hex16 = function(val) {
return Util.hex8((val & 0xff00) >> 8) + Util.hex8(val & 0x00ff);
};

Util.isWhitespace = function(c) {
return c=='\t' || c == ' ';// this is too slow c.match(/\s/);
};

Util.toTargetEncoding = function(str, encoding) {
return toEncoding(str, encoding);
};

function Assembler() {
this.debug = false;
this.binFileName = 'test.com';
Expand Down
15 changes: 15 additions & 0 deletions hello-apogee.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; 🐟 для Апогея БК-01
.tape rk-bin
.binfile helloapogee
.org 0
prompt equ 0F875h
puts equ 0F818h

lxi hl, msg
call puts
jmp prompt

msg:
db 1fh,'priwet, mir!',0dh,0ah,0


15 changes: 15 additions & 0 deletions hello-micro80.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; 🐟 для Микро-80
.tape rk-bin
.binfile hellom80
.org 0
prompt equ 0F82Dh
puts equ 0F818h

lxi hl, msg
call puts
jmp prompt

msg:
db 1fh,'priwet, mir!',0dh,0ah,0


15 changes: 15 additions & 0 deletions hello-microsha.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; 🐟 для Микроши
.tape microsha-bin
.binfile hellomicrosha
.org 0
prompt equ 0F89Dh
puts equ 0F818h

lxi hl, msg
call puts
jmp prompt

msg:
db 1fh,'priwet, mir!',0dh,0ah,0


15 changes: 15 additions & 0 deletions hello-partner.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; 🐟 для Партнёра 01.01
.tape partner-bin
.binfile hellopartner
.org 0
prompt equ 0F8C9h
puts equ 0F818h

lxi hl, msg
call puts
jmp prompt

msg:
db 1fh,'priwet, mir!',0dh,0ah,0


15 changes: 15 additions & 0 deletions hello-rk.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; 🐟 для Радио-86РК
.tape rk-bin
.binfile hellork
.org 0
prompt equ 0F86Ch
puts equ 0F818h

lxi hl, msg
call puts
jmp prompt

msg:
db 1fh,'priwet, mir!',0dh,0ah,0


6 changes: 6 additions & 0 deletions hello-spec.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; 🐟 для Специалиста
.tape spec-bin
.binfile hellospec
.org 0x100
db 'wtf'

6 changes: 6 additions & 0 deletions hello-v06c.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; 🐟 для Вектора-06ц
.tape v06c-rom
.binfile hellov06c
.org 0x100
db 'wtf'

4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Pretty 8080 Assembler</title>
<script type="text/javascript" src="encodings.js"></script>
<script type="text/javascript" src="util.js"></script>
<script type="text/javascript" src="makewav.js"></script>
<script type="text/javascript" src="tape.js"></script>
<script type="text/javascript" src="main.js"></script>
Expand Down Expand Up @@ -66,6 +67,7 @@
<textarea id="source" rows="30" cols="80"
onkeydown="return keydown(event);"
onkeypress="keypress(event);return true;">
; 🐟 (try me)
; 8080 assembler code
.hexfile test.hex
.binfile test.com
Expand Down Expand Up @@ -110,7 +112,7 @@
</div>
<div style="height:0.5ex"><br/></div>
<div id="buttbr" class="hordiv"></div>
<div>
<div id="buttons-below">
<input type="text" id="hex" name="hex" style="display:none;"/>
<input type="text" id="formbinname" name="formbinname" style="display:none;"/>
<input type="text" id="formhexname" name="formhexname" style="display:none;"/>
Expand Down
20 changes: 20 additions & 0 deletions list-online.css
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,23 @@ span#wav-dl:hover {
#sounds {
cursor:default;
}

.ryba-item {
cursor: pointer;
}

#ryba-popup {
border:5px solid #ffff7d;
background:#ffff7d;
font-size:90%;
font-family:Monaco, Lucida Console, monospace;
opacity:0.9;
max-width:30em;
overflow:hidden;
position:fixed;
}

.ryba-item:hover {
background-color: red;
}

106 changes: 104 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,17 +968,117 @@ var languages =
// Persian translation by Ali Asadzadeh, thanks Ali!
"fa":["یک اسمبلر جالب برای 8080","کامپایل کردن این کد زیبا"]
};
// 🐟
var rybas =
{
"rk": ["Радио-86РК", "hello-rk.asm"],

"microsha": ["Микроша", "hello-microsha.asm"],

"apogee": ["Апогей БК-01", "hello-apogee.asm"],

"partner": ["Партнер 01.01", "hello-partner.asm"],

"mikro80": ["Микро-80", "hello-micro80.asm"],

"vector06c": ["Вектор-06ц", "hello-v06c.asm"],

"krista": ["Криста", "hello-krista.asm"],

"specialist": ["Специалист", "hello-spec.asm"],
};

function load_ryba(url)
{
console.log("Trying to load ", url);

var oReq = new XMLHttpRequest();
oReq.open("GET", url, true);
oReq.responseType = "text";

oReq.onload = function(oEvent) {
//console.log(oReq.response);
let status = oReq.status;
if (status >= 200 && status < 300 || status === 304) {
document.getElementById('source').value = oReq.response;
assemble();
}
};
oReq.onerror = function(oEvent) {
console.log("XMLHttpRequest error", oEvent);
};

oReq.send();
}

function create_ryba_menu()
{
var menu = document.createElement("div");
menu.setAttribute("id", "ryba-popup");
for (var k in rybas) {
console.log("ryba ", k, rybas[k][0], rybas[k][1]);
var item = document.createElement("div");
//item.class = "ryba-item";
item.setAttribute("class", "ryba-item");
item.innerText = rybas[k][0];
(function(href) {
item.onclick = function() {
menu.parentElement.removeChild(menu);
load_ryba(href);
};
})(rybas[k][1]);
menu.onmouseleave = function() {
menu.parentElement.removeChild(menu);
};

menu.appendChild(item);
}

var text = document.getElementById("source");
(function(text, menu) {
text.onclick = function(e) {
console.log("onclick in text", text, text.selectionStart,
text.selectionEnd, e);
var s = text.selectionStart;
var p = s - 2;
var r1 = text.value.substring(s, s+2);
var r2 = text.value.substring(p, p+2)
if (r1 === "🐟" || r2 === "🐟") {
var parnt = document.getElementById("textinput");
parnt && parnt.appendChild(menu);

menu.style.left = (e.clientX - 25) + "px";
menu.style.top = (e.clientY - 25) + "px";
}
};
})(text, menu);
}

function i18n() {
var lang = navigator.language;
if (lang !== undefined) lang = lang.split('-')[0];

var explang = document.URL.split('?')[1];
var messages = languages[lang];
var ryba;
if (explang) {
var params = explang.split(',');
for (var i = 0; i < params.length; ++i) {
var forcedlang = languages[params[i]];
if (forcedlang) {
messages = forcedlang;
}
ryba = rybas[params[i]];
}
}
if (explang !== undefined) lang = explang;
if (!messages) messages = languages["en"];

var messages = languages[lang];
if (messages === undefined) messages = languages["en"];
if (ryba) {
load_ryba(document.URL.split('?')[0] + ryba[1]);
}

//var m_header = "🐟" + messages[0];
var m_header = messages[0];
var m_button = messages[1];

Expand All @@ -996,4 +1096,6 @@ function i18n() {
document.getElementById('ta').style.cssFloat = 'right';
document.getElementById('list').style.cssFloat = 'left';
}

create_ryba_menu();
}
32 changes: 14 additions & 18 deletions tape.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
function TapeFormat(fmt) {
this.format = null;
this.variant = null;
this.speed = 12;
switch (fmt) {
case 'rk-bin':
case 'rk86-bin':
case '86rk-bin':
this.format = TapeFormat.prototype.nekrosha;
this.variant = 'rk';
this.speed = 12;
break;
case 'mikrosha-bin':
case 'microsha-bin':
Expand All @@ -19,27 +21,21 @@ function TapeFormat(fmt) {
case 'nekro-bin':
this.format = TapeFormat.prototype.nekrosha;
this.variant = 'mikrosha';
this.speed = 12;
break;
case 'partner-bin':
this.format = TapeFormat.prototype.nekrosha;
this.variant = 'rk';
this.speed = 8;
break;
case 'v06c-rom':
this.format = TapeFormat.prototype.v06c_rom;
this.speed = 8;
break;
}
return this;
}

function Outil() {}

Outil.hex8 = function(val) {
if (val < 0 || val > 255) return "??";

var hexstr = "0123456789ABCDEF";
return hexstr[(val & 0xf0) >> 4] + hexstr[val & 0x0f];
};

Outil.hex16 = function(val) {
return Outil.hex8((val & 0xff00) >> 8) + Outil.hex8(val & 0x00ff);
};

/*
* Элемент Размер, байт
* Ракорд (нулевые байты) 256
Expand Down Expand Up @@ -90,9 +86,9 @@ TapeFormat.prototype.nekrosha = function(mem, org, name) {
}
}

console.log('checksum rk=', Outil.hex8(cs_hi&0377), Outil.hex8(cs_lo&0377));
console.log('checksum microsha=', Outil.hex8(csm_hi&0377),
Outil.hex8(csm_lo&0377));
console.log('checksum rk=', Util.hex8(cs_hi&0377), Util.hex8(cs_lo&0377));
console.log('checksum microsha=', Util.hex8(csm_hi&0377),
Util.hex8(csm_lo&0377));

if (this.variant === 'mikrosha') {
data[dptr++] = csm_hi & 0377;
Expand All @@ -112,7 +108,7 @@ TapeFormat.prototype.nekrosha = function(mem, org, name) {
data[dptr++] = 0;
data[dptr++] = 0;

var encoded = TapeFormat.prototype.biphase(data, 12);
var encoded = TapeFormat.prototype.biphase(data, this.speed || 12);
var params = {sampleRate:22050, channels: 1};
wav = new Wav(params);
wav.setBuffer(encoded);
Expand Down Expand Up @@ -210,7 +206,7 @@ TapeFormat.prototype.v06c_rom = function(mem, org, name) {
}
}

var encoded = TapeFormat.prototype.biphase(data, 8);
var encoded = TapeFormat.prototype.biphase(data, this.speed || 8);
var params = {sampleRate:22050, channels: 1};
wav = new Wav(params);
wav.setBuffer(encoded);
Expand Down
Loading

0 comments on commit 0910d7f

Please sign in to comment.