Extended write hooks and debugged sound

This commit is contained in:
Luxferre
2022-07-28 22:55:10 +03:00
parent 1d68fc8d4a
commit 61018ab06d
5 changed files with 82 additions and 30 deletions
+21 -15
View File
@@ -44,13 +44,13 @@ function ESOPExtensions() {
//setup screen renderer
function renderScreen() {
var vram = vm.getram(vramOffset, vramSize),
vdata = ctx.getImageData(0,0,width,height),
vdata = ctx.createImageData(width,height),
ppos, pval, vbval, i, j
for(i=0;i<vRamSize;i++) {
for(i=0;i<vramSize;i++) {
vbval = vram[i]
for(j=0;j<8;j++) { //iterate from highest to lowest
ppos = ((i<<3) + j) << 2
pval = (vbval>>>(7-j))&1 ? 255 : 0
pval = (vbval>>>(7-j))&1 ? 0 : 0xee
vdata.data[ppos] = pval
vdata.data[ppos+1] = pval
vdata.data[ppos+2] = pval
@@ -129,18 +129,24 @@ function ESOPExtensions() {
function setupAudio(vm, actx) {
var osc = null //keep the existing oscillator reference here
vm.setdev(6,0)
vm.setWriteHook(6, function(port, portval) {
if(osc && !portval) { //stop the note
osc.stop()
osc.disconnect()
osc = null
}
else if(portval < sfl) { //start the note
osc = actx.createOscillator()
osc.type = 'square'
osc.frequency = soundFreqs[portval]
osc.connect(actx.destination)
osc.start(0)
vm.setWriteHook(6, function(port, portval, prev) {
if(portval !== prev) {
if(osc && !portval) { //stop the note
osc.stop()
osc.disconnect()
osc = null
}
if(portval && portval < sfl) { //start the note
if(osc)
osc.frequency.value = soundFreqs[portval]
else {
osc = actx.createOscillator()
osc.type = 'square'
osc.connect(actx.destination)
osc.frequency.value = soundFreqs[portval]
osc.start(0)
}
}
}
})
}