minor source formatting issues

This commit is contained in:
Luxferre
2022-07-28 18:59:47 +03:00
parent 708af38819
commit 51a066b7b1
2 changed files with 17 additions and 34 deletions
+17 -32
View File
@@ -19,22 +19,18 @@ function ESOPExtensions() {
vm.devMemOffset = 0xfff8
vm.videoMemOffset = 0xfe00
vm.videoMemSize = 504
//setup RNG
var getRandomByte = ('crypto' in window) ? function() {
return window.crypto.getRandomValues(new Uint8Array(1))[0]
} : function() {return Math.random()*256|0}
vm.tracePort = 0x04 //setup the trace/random port
vm.setReadHook(0x04, function() { //update the random byte port before the program consumes it
vm.setdev(0x04, getRandomByte())
})
//setup status port
vm.setReadHook(0x05, function() {
vm.setdev(0x05, 0xff) //emulate full brightness, full charge and charger plugged in
})
}
//graphics
@@ -45,9 +41,7 @@ function ESOPExtensions() {
vramSize = vm.videoMemSize,
ctx = cnv.getContext('2d', {alpha: false})
ctx.globalAlpha = 1
//setup screen renderer
function renderScreen() {
var vram = vm.getram(vramOffset, vramSize),
vdata = ctx.getImageData(0,0,width,height),
@@ -65,9 +59,7 @@ function ESOPExtensions() {
}
ctx.putImageData(vdata, 0,0)
}
// also, we need to set up the screen vector
var rAF = window.requestAnimationFrame || window.webkitRequestAnimationFrame
rAF(function vecframe() {
vm.triggerVector(0)
@@ -75,43 +67,27 @@ function ESOPExtensions() {
if(vm.active)
rAF(vecframe)
})
}
//keypad input
var livemap = { //map keys to bit values (to be updated in one of 4 ports)
'0': 0x0,
'1': 0x1,
'2': 0x2,
'3': 0x3,
'4': 0x4,
'5': 0x5,
'6': 0x6,
'7': 0x7,
'8': 0x8,
'9': 0x9,
'*': 0xe,
'#': 0xf,
'0': 0x0, '1': 0x1, '2': 0x2, '3': 0x3,
'4': 0x4, '5': 0x5, '6': 0x6, '7': 0x7,
'8': 0x8, '9': 0x9, '*': 0xe, '#': 0xf,
'ArrowUp': 0xa, //A - Advance
'ArrowDown': 0xb, //B - Back
'Backspace': 0xc, //C - Cancel
'Enter': 0xd //D - Do
}
//set KaiOS aliases if necessary
livemap['End'] = livemap['Backspace']
livemap['EndCall'] = livemap['End']
//now remap the keys for PC according to the spec recommendation
//set PC and KaiOS aliases if necessary
livemap['a'] = livemap['ArrowUp']
livemap['b'] = livemap['ArrowDown']
livemap['c'] = livemap['Backspace']
livemap['c'] = livemap['EndCall'] = livemap['End'] = livemap['Backspace']
livemap['d'] = livemap['Enter']
function setupInput(vm) {
function keypress(e) {
var k = e.key
if(k in livemap) {
@@ -134,13 +110,21 @@ function ESOPExtensions() {
window.removeEventListener('keyup', keyrelease)
window.addEventListener('keydown', keypress)
window.addEventListener('keyup', keyrelease)
vm.setdev(2, 0)
vm.setdev(3, 0)
}
//sound
//keep sound frequency matrix for all 87 non-zero sound port values with A4 aligned to 0x30 position
var soundFreqs = [0,29.14,30.87,32.7,34.65,36.71,38.89,41.2,43.65,46.25,49,51.91,55,58.27,61.74,65.41,69.3,73.42,77.78,82.41,87.31,92.5,98,103.83,110,116.54,123.47,130.81,138.59,146.83,155.56,164.81,174.61,185,196,207.65,220,233.08,246.94,261.63,277.18,293.66,311.13,329.63,349.23,369.99,392,415.3,440,466.16,493.88,523.25,554.37,587.33,622.25,659.26,698.46,739.99,783.99,830.61,880,932.33,987.77,1046.5,1108.73,1174.66,1244.51,1318.51,1396.91,1479.98,1567.98,1661.22,1760,1864.66,1975.53,2093,2217.46,2349.32,2489.02,2637.02,2793.83,2959.96,3135.96,3322.44,3520,3729.31,3951.07,4186.01], sfl = soundFreqs.length
var soundFreqs = [
0,29.14,30.87,32.7,34.65,36.71,38.89,41.2,43.65,46.25,49,51.91,55,58.27,61.74,65.41,69.3,73.42,77.78,
82.41,87.31,92.5,98,103.83,110,116.54,123.47,130.81,138.59,146.83,155.56,164.81,174.61,185,196,207.65,
220,233.08,246.94,261.63,277.18,293.66,311.13,329.63,349.23,369.99,392,415.3,440,466.16,493.88,523.25,
554.37,587.33,622.25,659.26,698.46,739.99,783.99,830.61,880,932.33,987.77,1046.5,1108.73,1174.66,1244.51,
1318.51,1396.91,1479.98,1567.98,1661.22,1760,1864.66,1975.53,2093,2217.46,2349.32,2489.02,2637.02,2793.83,
2959.96,3135.96,3322.44,3520,3729.31,3951.07,4186.01
], sfl = soundFreqs.length
function setupAudio(vm, actx) {
var osc = null //keep the existing oscillator reference here
@@ -161,6 +145,8 @@ function ESOPExtensions() {
})
}
//syscalls
function runSyscall(vm, buf) {
var call = buf[0]
if(call === 0x00) //simulate writing a byte to the debug port
@@ -210,4 +196,3 @@ function ESOPExtensions() {
}
}
}
-2
View File
@@ -38,7 +38,6 @@ function UxnCore() {
}
function rel(x) {return x > 0x80 ? x - 256 : x}
function PUSH8(s, x) {if(s.ptr === 255) trapout(2);s.dat[s.ptr++] = x}
function PUSH16(s, x) {PUSH8(s, x>>8);PUSH8(s, x&255)}
function PUSH(s, x) {if(bs) PUSH16(s, x);else PUSH8(s, x)}
@@ -187,5 +186,4 @@ function UxnCore() {
if(targetAddr) uxnstart(targetAddr)
}
}
}