mirror of
https://github.com/trudnai/Steve2.git
synced 2025-01-02 18:32:37 +00:00
- Keyboard 2 Mouse
- FPS set back to 30 - 16 bit PCM - Smoother speaker level fade out - Faster keyboard poll query -- This is for checking only, should be either removed or the entire ioRead should based on binary search, whatever is faster
This commit is contained in:
parent
0aea0b9c84
commit
ab120dc459
@ -14,10 +14,13 @@
|
|||||||
</PersistentStrings>
|
</PersistentStrings>
|
||||||
</ContextState>
|
</ContextState>
|
||||||
<ContextState
|
<ContextState
|
||||||
contextName = "specialized closure #1 in ViewController.Update():ViewController.swift">
|
contextName = "BRA:6502_instr_branch.h">
|
||||||
<PersistentStrings>
|
<PersistentStrings>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "self.HiRes.frame">
|
value = "">
|
||||||
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "RAM[0x346f]">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
</PersistentStrings>
|
</PersistentStrings>
|
||||||
</ContextState>
|
</ContextState>
|
||||||
@ -60,6 +63,14 @@
|
|||||||
</PersistentString>
|
</PersistentString>
|
||||||
</PersistentStrings>
|
</PersistentStrings>
|
||||||
</ContextState>
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "closure #1 in ViewController.Update():ViewController.swift">
|
||||||
|
<PersistentStrings>
|
||||||
|
<PersistentString
|
||||||
|
value = "self.shadowTxt">
|
||||||
|
</PersistentString>
|
||||||
|
</PersistentStrings>
|
||||||
|
</ContextState>
|
||||||
<ContextState
|
<ContextState
|
||||||
contextName = "m6502_Step:6502.c">
|
contextName = "m6502_Step:6502.c">
|
||||||
<PersistentStrings>
|
<PersistentStrings>
|
||||||
@ -175,6 +186,20 @@
|
|||||||
</PersistentString>
|
</PersistentString>
|
||||||
</PersistentStrings>
|
</PersistentStrings>
|
||||||
</ContextState>
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "spkr_update:speaker.c">
|
||||||
|
<PersistentStrings>
|
||||||
|
<PersistentString
|
||||||
|
value = "(uint8_t)spkr_samples[451]">
|
||||||
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "(uint8_t)spkr_samples[452]">
|
||||||
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "(uint8_t)spkr_samples[455]">
|
||||||
|
</PersistentString>
|
||||||
|
</PersistentStrings>
|
||||||
|
</ContextState>
|
||||||
<ContextState
|
<ContextState
|
||||||
contextName = "spkr_playUpd:speaker.c">
|
contextName = "spkr_playUpd:speaker.c">
|
||||||
</ContextState>
|
</ContextState>
|
||||||
@ -216,7 +241,7 @@
|
|||||||
value = "pdl_value[pdl]">
|
value = "pdl_value[pdl]">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "normalized_time >= pdl_value[pdl] ? 255 : 0">
|
value = "normalized_time">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "(3300 * 255/3300)">
|
value = "(3300 * 255/3300)">
|
||||||
@ -228,7 +253,7 @@
|
|||||||
value = "1 * 512 * (1 - ( 3300 / 3300.0 ))">
|
value = "1 * 512 * (1 - ( 3300 / 3300.0 ))">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "normalized_time">
|
value = "normalized_time >= pdl_value[pdl] ? 255 : 0">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
</PersistentStrings>
|
</PersistentStrings>
|
||||||
</ContextState>
|
</ContextState>
|
||||||
@ -245,13 +270,13 @@
|
|||||||
value = "textLines">
|
value = "textLines">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "hires.layer">
|
value = "hires.frame">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "view">
|
value = "view">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "hires.frame">
|
value = "hires.layer">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
</PersistentStrings>
|
</PersistentStrings>
|
||||||
</ContextState>
|
</ContextState>
|
||||||
@ -278,10 +303,10 @@
|
|||||||
contextName = "set_flags_NZC:common.h">
|
contextName = "set_flags_NZC:common.h">
|
||||||
<PersistentStrings>
|
<PersistentStrings>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "(unsigned)test ">
|
value = "(unsigned)0xFF">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "(unsigned)0xFF">
|
value = "(unsigned)test ">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
</PersistentStrings>
|
</PersistentStrings>
|
||||||
</ContextState>
|
</ContextState>
|
||||||
@ -405,19 +430,25 @@
|
|||||||
<PersistentString
|
<PersistentString
|
||||||
value = "(clkfrm / (default_MHz_6502 / spkr_sample_rate))">
|
value = "(clkfrm / (default_MHz_6502 / spkr_sample_rate))">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "spkr_level">
|
||||||
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "spkr_sample_idx">
|
value = "spkr_sample_idx">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "(int16_t)28000 + (int16_t)-32768">
|
||||||
|
</PersistentString>
|
||||||
</PersistentStrings>
|
</PersistentStrings>
|
||||||
</ContextState>
|
</ContextState>
|
||||||
<ContextState
|
<ContextState
|
||||||
contextName = "HiRes.draw(_:):HiRes.swift">
|
contextName = "HiRes.draw(_:):HiRes.swift">
|
||||||
<PersistentStrings>
|
<PersistentStrings>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "linAddr">
|
value = "ctx?.bitsPerComponent">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "shadowScreen">
|
value = "ctx?.data">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "ctx?.width">
|
value = "ctx?.width">
|
||||||
@ -434,21 +465,21 @@
|
|||||||
<PersistentString
|
<PersistentString
|
||||||
value = "ctx?.bitmapInfo">
|
value = "ctx?.bitmapInfo">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "shadowScreen">
|
||||||
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "(blockH7 | ( block & bitMask ))">
|
value = "(blockH7 | ( block & bitMask ))">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "HiRes.blockCols">
|
value = "HiRes.blockCols">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "linAddr">
|
||||||
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "ctx?.height">
|
value = "ctx?.height">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
|
||||||
value = "ctx?.bitsPerComponent">
|
|
||||||
</PersistentString>
|
|
||||||
<PersistentString
|
|
||||||
value = "ctx?.data">
|
|
||||||
</PersistentString>
|
|
||||||
</PersistentStrings>
|
</PersistentStrings>
|
||||||
</ContextState>
|
</ContextState>
|
||||||
<ContextState
|
<ContextState
|
||||||
@ -463,13 +494,13 @@
|
|||||||
contextName = "HiRes.compute():HiRes.swift">
|
contextName = "HiRes.compute():HiRes.swift">
|
||||||
<PersistentStrings>
|
<PersistentStrings>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "computePipelineState.maxTotalThreadsPerThreadgroup">
|
value = "UnsafeRawBufferPointer(result)">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "result[2]">
|
value = "result[2]">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "UnsafeRawBufferPointer(result)">
|
value = "computePipelineState.maxTotalThreadsPerThreadgroup">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
</PersistentStrings>
|
</PersistentStrings>
|
||||||
</ContextState>
|
</ContextState>
|
||||||
@ -491,15 +522,15 @@
|
|||||||
<PersistentString
|
<PersistentString
|
||||||
value = "textLines">
|
value = "textLines">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
|
||||||
value = "clkfrm">
|
|
||||||
</PersistentString>
|
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "mouseLocation">
|
value = "mouseLocation">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "txtArr">
|
value = "txtArr">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "clkfrm">
|
||||||
|
</PersistentString>
|
||||||
</PersistentStrings>
|
</PersistentStrings>
|
||||||
</ContextState>
|
</ContextState>
|
||||||
<ContextState
|
<ContextState
|
||||||
@ -542,10 +573,10 @@
|
|||||||
value = "Apple2_64K_AUX + 0xC600">
|
value = "Apple2_64K_AUX + 0xC600">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "(void*)rom">
|
value = "Apple2_64K_RAM + 0xC600">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "Apple2_64K_RAM + 0xC600">
|
value = "(void*)rom">
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "strlen(fullPath)">
|
value = "strlen(fullPath)">
|
||||||
@ -562,13 +593,10 @@
|
|||||||
contextName = "BNE:6502_instr_branch.h">
|
contextName = "BNE:6502_instr_branch.h">
|
||||||
</ContextState>
|
</ContextState>
|
||||||
<ContextState
|
<ContextState
|
||||||
contextName = "BRA:6502_instr_branch.h">
|
contextName = "specialized closure #1 in ViewController.Update():ViewController.swift">
|
||||||
<PersistentStrings>
|
<PersistentStrings>
|
||||||
<PersistentString
|
<PersistentString
|
||||||
value = "">
|
value = "self.HiRes.frame">
|
||||||
</PersistentString>
|
|
||||||
<PersistentString
|
|
||||||
value = "RAM[0x346f]">
|
|
||||||
</PersistentString>
|
</PersistentString>
|
||||||
</PersistentStrings>
|
</PersistentStrings>
|
||||||
</ContextState>
|
</ContextState>
|
||||||
|
@ -285,20 +285,33 @@ class ViewController: NSViewController {
|
|||||||
switch keyCode {
|
switch keyCode {
|
||||||
case leftArrowKey:
|
case leftArrowKey:
|
||||||
kbdInput(0x08)
|
kbdInput(0x08)
|
||||||
setIO(0xC064, 0);
|
// setIO(0xC064, 0);
|
||||||
print("LEFT", ddd);
|
print("LEFT", ddd);
|
||||||
|
|
||||||
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
||||||
|
pdl_valarr[0] = 0
|
||||||
|
|
||||||
case rightArrowKey:
|
case rightArrowKey:
|
||||||
kbdInput(0x15)
|
kbdInput(0x15)
|
||||||
setIO(0xC064, 255);
|
// setIO(0xC064, 255);
|
||||||
print("RIGHT")
|
print("RIGHT")
|
||||||
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
||||||
|
pdl_valarr[0] = 1
|
||||||
|
|
||||||
case downArrowKey:
|
case downArrowKey:
|
||||||
kbdInput(0x0B)
|
kbdInput(0x0B)
|
||||||
setIO(0xC065, 255);
|
// setIO(0xC065, 255);
|
||||||
print("DOWN")
|
print("DOWN")
|
||||||
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
||||||
|
pdl_valarr[1] = 0
|
||||||
|
|
||||||
case upArrowKey:
|
case upArrowKey:
|
||||||
kbdInput(0x0A)
|
kbdInput(0x0A)
|
||||||
setIO(0xC065, 0);
|
// setIO(0xC065, 0);
|
||||||
print("UP")
|
print("UP")
|
||||||
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
||||||
|
pdl_valarr[1] = 1
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// print("keycode: %d", keyCode)
|
// print("keycode: %d", keyCode)
|
||||||
if let chars = event.characters {
|
if let chars = event.characters {
|
||||||
@ -335,20 +348,32 @@ class ViewController: NSViewController {
|
|||||||
switch keyCode {
|
switch keyCode {
|
||||||
case leftArrowKey:
|
case leftArrowKey:
|
||||||
// kbdInput(0x08)
|
// kbdInput(0x08)
|
||||||
setIO(0xC064, 127);
|
// setIO(0xC064, 127);
|
||||||
print("left")
|
print("left")
|
||||||
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
||||||
|
pdl_valarr[0] = 0.5
|
||||||
|
|
||||||
case rightArrowKey:
|
case rightArrowKey:
|
||||||
// kbdInput(0x15)
|
// kbdInput(0x15)
|
||||||
setIO(0xC064, 128);
|
// setIO(0xC064, 128);
|
||||||
print("right")
|
print("right")
|
||||||
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
||||||
|
pdl_valarr[0] = 0.5
|
||||||
|
|
||||||
case downArrowKey:
|
case downArrowKey:
|
||||||
// kbdInput(0x0B)
|
// kbdInput(0x0B)
|
||||||
setIO(0xC065, 127);
|
// setIO(0xC065, 127);
|
||||||
print("down")
|
print("down")
|
||||||
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
||||||
|
pdl_valarr[1] = 0.5
|
||||||
|
|
||||||
case upArrowKey:
|
case upArrowKey:
|
||||||
// kbdInput(0x0A)
|
// kbdInput(0x0A)
|
||||||
setIO(0xC065, 128);
|
// setIO(0xC065, 128);
|
||||||
print("up")
|
print("up")
|
||||||
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
||||||
|
pdl_valarr[1] = 0.5
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// print("keycode: %d", keyCode)
|
// print("keycode: %d", keyCode)
|
||||||
// if let chars = event.characters {
|
// if let chars = event.characters {
|
||||||
@ -425,6 +450,8 @@ class ViewController: NSViewController {
|
|||||||
|
|
||||||
var mouseLocation = NSPoint.zero
|
var mouseLocation = NSPoint.zero
|
||||||
|
|
||||||
|
var shadowTxt : String = ""
|
||||||
|
|
||||||
func Update() {
|
func Update() {
|
||||||
// clk_6502_per_frm_max = 0
|
// clk_6502_per_frm_max = 0
|
||||||
|
|
||||||
@ -466,9 +493,8 @@ class ViewController: NSViewController {
|
|||||||
// 1. We can update UI elements
|
// 1. We can update UI elements
|
||||||
// 2. it is independent of the simulation, de that is running in the background thread while we are busy with rendering...
|
// 2. it is independent of the simulation, de that is running in the background thread while we are busy with rendering...
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
|
||||||
var txt : String = ""
|
var txt : String = ""
|
||||||
|
|
||||||
var fromLines = 0
|
var fromLines = 0
|
||||||
var toLines = self.textLines
|
var toLines = self.textLines
|
||||||
|
|
||||||
@ -543,7 +569,10 @@ class ViewController: NSViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.display.stringValue = txt
|
if ( self.shadowTxt != txt ) {
|
||||||
|
self.shadowTxt = txt
|
||||||
|
self.display.stringValue = txt
|
||||||
|
}
|
||||||
// self.display.stringValue = "testing\nit\nout"
|
// self.display.stringValue = "testing\nit\nout"
|
||||||
|
|
||||||
if ( (mhz < 1.5) && (mhz != floor(mhz)) ) {
|
if ( (mhz < 1.5) && (mhz != floor(mhz)) ) {
|
||||||
@ -589,16 +618,16 @@ class ViewController: NSViewController {
|
|||||||
#if SPEEDTEST
|
#if SPEEDTEST
|
||||||
#else
|
#else
|
||||||
if ( !halted ) {
|
if ( !halted ) {
|
||||||
// Mouse 2 JoyStick (Game Controller / Paddle)
|
// // Mouse 2 JoyStick (Game Controller / Paddle)
|
||||||
mouseLocation = view.window!.mouseLocationOutsideOfEventStream
|
// mouseLocation = view.window!.mouseLocationOutsideOfEventStream
|
||||||
|
//
|
||||||
pdl_prevarr[0] = pdl_valarr[0]
|
// pdl_prevarr[0] = pdl_valarr[0]
|
||||||
pdl_valarr[0] = Double(mouseLocation.x / (displayField.frame.width) )
|
// pdl_valarr[0] = Double(mouseLocation.x / (displayField.frame.width) )
|
||||||
pdl_diffarr[0] = pdl_valarr[0] - pdl_prevarr[0]
|
// pdl_diffarr[0] = pdl_valarr[0] - pdl_prevarr[0]
|
||||||
|
//
|
||||||
pdl_prevarr[1] = pdl_valarr[1]
|
// pdl_prevarr[1] = pdl_valarr[1]
|
||||||
pdl_valarr[1] = 1 - Double(mouseLocation.y / (displayField.frame.height) )
|
// pdl_valarr[1] = 1 - Double(mouseLocation.y / (displayField.frame.height) )
|
||||||
pdl_diffarr[1] = pdl_valarr[1] - pdl_prevarr[1]
|
// pdl_diffarr[1] = pdl_valarr[1] - pdl_prevarr[1]
|
||||||
|
|
||||||
m6502_Run()
|
m6502_Run()
|
||||||
}
|
}
|
||||||
@ -627,7 +656,6 @@ class ViewController: NSViewController {
|
|||||||
hires.clearScreen();
|
hires.clearScreen();
|
||||||
|
|
||||||
woz_loadFile( Bundle.main.resourcePath, "Apple DOS 3.3 January 1983.woz" )
|
woz_loadFile( Bundle.main.resourcePath, "Apple DOS 3.3 January 1983.woz" )
|
||||||
|
|
||||||
|
|
||||||
let spk_up_path = Bundle.main.path(forResource: "spk_up", ofType:"wav")!
|
let spk_up_path = Bundle.main.path(forResource: "spk_up", ofType:"wav")!
|
||||||
let spk_up_url = URL(fileURLWithPath: spk_up_path)
|
let spk_up_url = URL(fileURLWithPath: spk_up_path)
|
||||||
|
@ -157,7 +157,7 @@ extern double * pdl_diffarr;
|
|||||||
extern double mips;
|
extern double mips;
|
||||||
extern double mhz;
|
extern double mhz;
|
||||||
|
|
||||||
#define fps 60U
|
#define fps 30U
|
||||||
|
|
||||||
extern void rom_loadFile( const char * bundlePath, const char * filename );
|
extern void rom_loadFile( const char * bundlePath, const char * filename );
|
||||||
extern void woz_loadFile( const char * bundlePath, const char * filename );
|
extern void woz_loadFile( const char * bundlePath, const char * filename );
|
||||||
|
@ -70,7 +70,7 @@ const int spkr_seconds = 1;
|
|||||||
const unsigned spkr_sample_rate = 44100;
|
const unsigned spkr_sample_rate = 44100;
|
||||||
unsigned spkr_extra_buf = 780 / fps;
|
unsigned spkr_extra_buf = 780 / fps;
|
||||||
const unsigned spkr_buf_size = spkr_seconds * spkr_sample_rate * 2 / spkr_fps;
|
const unsigned spkr_buf_size = spkr_seconds * spkr_sample_rate * 2 / spkr_fps;
|
||||||
char spkr_samples [ spkr_buf_size * spkr_fps * BUFFER_COUNT * 2]; // stereo
|
int16_t spkr_samples [ spkr_buf_size * spkr_fps * BUFFER_COUNT * 2]; // stereo
|
||||||
unsigned spkr_sample_idx = 0;
|
unsigned spkr_sample_idx = 0;
|
||||||
|
|
||||||
const unsigned spkr_play_timeout = 8;
|
const unsigned spkr_play_timeout = 8;
|
||||||
@ -90,7 +90,7 @@ void spkr_init() {
|
|||||||
alcMakeContextCurrent(ctx);
|
alcMakeContextCurrent(ctx);
|
||||||
|
|
||||||
// Fill buffer with zeros
|
// Fill buffer with zeros
|
||||||
memset( spkr_samples, spkr_level, spkr_buf_size );
|
memset( spkr_samples, spkr_level, spkr_buf_size * sizeof(spkr_samples[0]) );
|
||||||
|
|
||||||
// Create buffer to store samples
|
// Create buffer to store samples
|
||||||
alGenBuffers(BUFFER_COUNT, spkr_buffers);
|
alGenBuffers(BUFFER_COUNT, spkr_buffers);
|
||||||
@ -146,7 +146,7 @@ void spkr_toggle() {
|
|||||||
// (we will play the entire buffer at the end of the frame)
|
// (we will play the entire buffer at the end of the frame)
|
||||||
spkr_sample_idx = (clkfrm / (default_MHz_6502 / spkr_sample_rate)) * 2;
|
spkr_sample_idx = (clkfrm / (default_MHz_6502 / spkr_sample_rate)) * 2;
|
||||||
|
|
||||||
if ( spkr_level > SPKR_LEVEL_MIN ) {
|
if ( spkr_level > SPKR_LEVEL_ZERO ) {
|
||||||
// down edge
|
// down edge
|
||||||
while( (spkr_level = (spkr_level + SPKR_LEVEL_MIN) / 2 ) > SPKR_LEVEL_MIN + 1 ) {
|
while( (spkr_level = (spkr_level + SPKR_LEVEL_MIN) / 2 ) > SPKR_LEVEL_MIN + 1 ) {
|
||||||
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
|
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
|
||||||
@ -163,19 +163,11 @@ void spkr_toggle() {
|
|||||||
spkr_level = SPKR_LEVEL_MAX;
|
spkr_level = SPKR_LEVEL_MAX;
|
||||||
}
|
}
|
||||||
//spkr_samples[sample_idx] = spkr_level;
|
//spkr_samples[sample_idx] = spkr_level;
|
||||||
memset(spkr_samples + spkr_sample_idx, spkr_level, spkr_buf_size);
|
for ( int i = spkr_sample_idx; i < spkr_buf_size + spkr_extra_buf; i++ ) {
|
||||||
|
spkr_samples[i] = spkr_level;
|
||||||
|
}
|
||||||
|
// memset(spkr_samples + spkr_sample_idx, spkr_level, spkr_buf_size * sizeof(spkr_samples[0]));
|
||||||
|
|
||||||
//ViewController_spk_up_play();
|
|
||||||
|
|
||||||
|
|
||||||
// case io_VID_CLR80VID:
|
|
||||||
// videoMode.col80 = 0;
|
|
||||||
// break;
|
|
||||||
//
|
|
||||||
// case io_VID_SET80VID:
|
|
||||||
// videoMode.col80 = 1;
|
|
||||||
// break;
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -186,29 +178,8 @@ ALint freeBuffers = BUFFER_COUNT;
|
|||||||
void spkr_update() {
|
void spkr_update() {
|
||||||
if ( spkr_play_time ) {
|
if ( spkr_play_time ) {
|
||||||
|
|
||||||
// printf("freeBuffers: %d", freeBuffers);
|
|
||||||
|
|
||||||
// if ( spkr_src ) {
|
|
||||||
// alSourceStop(spkr_src);
|
|
||||||
// al_check_error();
|
|
||||||
// alSourcei(spkr_src, AL_BUFFER, 0);
|
|
||||||
// al_check_error();
|
|
||||||
//
|
|
||||||
// spkr_src = 0;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if ( spkr_buf ) {
|
|
||||||
// alDeleteBuffers(1, &spkr_buf);
|
|
||||||
// al_check_error();
|
|
||||||
// spkr_buf = 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ALint queued = 0;
|
|
||||||
ALint processed = 0;
|
ALint processed = 0;
|
||||||
|
|
||||||
// alGetSourcei (spkr_src, AL_BUFFERS_QUEUED, &queued);
|
|
||||||
// alGetSourcei (spkr_src, AL_BUFFERS_PROCESSED, &processed);
|
|
||||||
//
|
|
||||||
// printf("freeBuffers:%d queued:%d processed:%d\n", freeBuffers, queued,processed);
|
// printf("freeBuffers:%d queued:%d processed:%d\n", freeBuffers, queued,processed);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -221,8 +192,6 @@ void spkr_update() {
|
|||||||
freeBuffers += processed;
|
freeBuffers += processed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// usleep(100);
|
|
||||||
// if ( freeBuffers <= 0 ) printf("No Free Buffer\n");
|
|
||||||
} while( freeBuffers <= 0 );
|
} while( freeBuffers <= 0 );
|
||||||
|
|
||||||
freeBuffers = clamp( 1, freeBuffers, BUFFER_COUNT );
|
freeBuffers = clamp( 1, freeBuffers, BUFFER_COUNT );
|
||||||
@ -233,33 +202,33 @@ void spkr_update() {
|
|||||||
alGetSourcei( spkr_src, AL_SOURCE_STATE, &state );
|
alGetSourcei( spkr_src, AL_SOURCE_STATE, &state );
|
||||||
// al_check_error();
|
// al_check_error();
|
||||||
|
|
||||||
// spkr_samples[0] = 0;
|
////////// check if there is no sound generated for long time, and fade out speaker level to avoid pops and crackles
|
||||||
// spkr_samples[1] = 255;
|
|
||||||
// spkr_samples[2] = 0;
|
|
||||||
// spkr_samples[3] = 255;
|
|
||||||
// spkr_samples[4] = 0;
|
|
||||||
|
|
||||||
// Download buffer to OpenAL
|
|
||||||
|
|
||||||
if ( --spkr_play_time == 0 ) {
|
if ( --spkr_play_time == 0 ) {
|
||||||
// we need to soft mute the speaker to eliminate clicking noise
|
// we need to soft mute the speaker to eliminate clicking noise
|
||||||
// simple linear mute
|
// simple linear mute
|
||||||
int step = (SPKR_LEVEL_ZERO - (int)spkr_level) / 128;
|
const int steepness = 64;
|
||||||
|
|
||||||
|
float step = (SPKR_LEVEL_ZERO - (float)spkr_level) / steepness;
|
||||||
|
float fadeLevel = spkr_level - SPKR_LEVEL_ZERO;
|
||||||
|
|
||||||
if ( step != 0 ) {
|
if ( step != 0 ) {
|
||||||
for ( spkr_sample_idx = 0; spkr_level != SPKR_LEVEL_ZERO; spkr_level += step) {
|
spkr_sample_idx = 0;
|
||||||
for ( int i = 0; i < 4; i++ ) {
|
|
||||||
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
|
while ( ( fadeLevel < -1 ) || ( fadeLevel > 1 ) ) {
|
||||||
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
|
spkr_samples[ spkr_sample_idx++ ] = SPKR_LEVEL_ZERO + fadeLevel;
|
||||||
}
|
spkr_samples[ spkr_sample_idx++ ] = SPKR_LEVEL_ZERO + fadeLevel;
|
||||||
|
|
||||||
|
// how smooth we want the speeker to decay, so we will hear no pops and crackles
|
||||||
|
fadeLevel *= 0.999;
|
||||||
}
|
}
|
||||||
spkr_level = SPKR_LEVEL_ZERO;
|
spkr_level = SPKR_LEVEL_ZERO + fadeLevel;
|
||||||
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
|
|
||||||
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
|
|
||||||
//spkr_samples[sample_idx] = spkr_level;
|
//spkr_samples[sample_idx] = spkr_level;
|
||||||
memset(spkr_samples + spkr_sample_idx, spkr_level, spkr_extra_buf);
|
memset(spkr_samples + spkr_sample_idx, SPKR_LEVEL_ZERO, spkr_extra_buf * sizeof(spkr_samples[0]));
|
||||||
|
|
||||||
freeBuffers--;
|
freeBuffers--;
|
||||||
alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO8, spkr_samples, spkr_sample_idx, spkr_sample_rate);
|
alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO16, spkr_samples, spkr_sample_idx * sizeof(spkr_samples[0]), spkr_sample_rate);
|
||||||
al_check_error();
|
al_check_error();
|
||||||
alSourceQueueBuffers(spkr_src, 1, &spkr_buffers[freeBuffers]);
|
alSourceQueueBuffers(spkr_src, 1, &spkr_buffers[freeBuffers]);
|
||||||
al_check_error();
|
al_check_error();
|
||||||
@ -267,7 +236,7 @@ void spkr_update() {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
freeBuffers--;
|
freeBuffers--;
|
||||||
alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO8, spkr_samples, spkr_buf_size + spkr_extra_buf, spkr_sample_rate);
|
alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO16, spkr_samples, (spkr_buf_size + spkr_extra_buf) * sizeof(spkr_samples[0]), spkr_sample_rate);
|
||||||
al_check_error();
|
al_check_error();
|
||||||
alSourceQueueBuffers(spkr_src, 1, &spkr_buffers[freeBuffers]);
|
alSourceQueueBuffers(spkr_src, 1, &spkr_buffers[freeBuffers]);
|
||||||
al_check_error();
|
al_check_error();
|
||||||
@ -289,45 +258,15 @@ void spkr_update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// clear the slack buffer , so we can fill it up by new data
|
// clear the slack buffer , so we can fill it up by new data
|
||||||
memset(spkr_samples, spkr_level, spkr_buf_size + spkr_extra_buf);
|
for ( int i = 0; i < spkr_buf_size + spkr_extra_buf; i++ ) {
|
||||||
|
spkr_samples[i] = spkr_level;
|
||||||
|
}
|
||||||
|
// memset(spkr_samples, spkr_level, (spkr_buf_size + spkr_extra_buf) * sizeof(spkr_samples[0]));
|
||||||
|
|
||||||
// start from the beginning
|
// start from the beginning
|
||||||
spkr_sample_idx = 0;
|
spkr_sample_idx = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// TODO: Need better speaker turn off logic to avoid click noise
|
|
||||||
//// if ( spkr_src ) {
|
|
||||||
//// alSourceStop(spkr_src);
|
|
||||||
//// al_check_error();
|
|
||||||
//// alSourceUnqueueBuffers( spkr_src, BUFFER_COUNT, spkr_buffers);
|
|
||||||
//// al_check_error();
|
|
||||||
//// alSourcei(spkr_src, AL_BUFFER, 0);
|
|
||||||
//// al_check_error();
|
|
||||||
//// spkr_src = 0;
|
|
||||||
//// // clear the buffer
|
|
||||||
//// memset(spkr_samples, spkr_level, spkr_buf_size);
|
|
||||||
//// }
|
|
||||||
//// printf("freeBuffers_nosound: %d\n", freeBuffers);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//void spkr_Update() {
|
|
||||||
// if ( spkr_src && spkr_buf ) {
|
|
||||||
// if ( spkr_src ) {
|
|
||||||
// alSourcePause(spkr_src);
|
|
||||||
// al_check_error();
|
|
||||||
// alSourcei(spkr_src, AL_BUFFER, 0);
|
|
||||||
// al_check_error();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // Download buffer to OpenAL
|
|
||||||
// alBufferData(spkr_buf, AL_FORMAT_MONO8, spkr_samples, spkr_buf_size, spkr_sample_rate);
|
|
||||||
// al_check_error();
|
|
||||||
//
|
|
||||||
// alSourcei( spkr_src, AL_BYTE_OFFSET, 0 );
|
|
||||||
// al_check_error();
|
|
||||||
// alSourcePlay(spkr_src);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
@ -11,15 +11,15 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define SPKR_LEVEL_MIN 32
|
#define SPKR_LEVEL_MIN (-28000)
|
||||||
#define SPKR_LEVEL_MAX 223
|
#define SPKR_LEVEL_MAX (+28000)
|
||||||
#define SPKR_LEVEL_ZERO 128 // as defined in OpenAL documentation for 8bit PCM
|
#define SPKR_LEVEL_ZERO 0 // as defined in OpenAL documentation for 8bit PCM
|
||||||
|
|
||||||
|
|
||||||
extern const unsigned spkr_sample_rate;
|
extern const unsigned spkr_sample_rate;
|
||||||
extern const unsigned spkr_buf_size;
|
extern const unsigned spkr_buf_size;
|
||||||
extern const int spkr_fps;
|
extern const int spkr_fps;
|
||||||
extern char spkr_samples [];
|
extern int16_t spkr_samples [];
|
||||||
extern unsigned spkr_sample_idx;
|
extern unsigned spkr_sample_idx;
|
||||||
extern int spkr_level;
|
extern int spkr_level;
|
||||||
extern int freeBuffers;
|
extern int freeBuffers;
|
||||||
|
@ -407,6 +407,12 @@ INLINE uint8_t ioRead( uint16_t addr ) {
|
|||||||
|
|
||||||
uint8_t currentMagnet = 0;
|
uint8_t currentMagnet = 0;
|
||||||
|
|
||||||
|
// TODO: This is for checking only, should be either removed or the entire ioRead should based on binary search, whatever is faster
|
||||||
|
if ( addr == io_KBD ) {
|
||||||
|
// clk_6502_per_frm_max = clk_6502_per_frm_max > 32768 ? clk_6502_per_frm_max - 32768 : 0; // ECO Mode!
|
||||||
|
return Apple2_64K_RAM[io_KBD];
|
||||||
|
}
|
||||||
|
|
||||||
switch ( (uint8_t)addr ) {
|
switch ( (uint8_t)addr ) {
|
||||||
case (uint8_t)io_KBD:
|
case (uint8_t)io_KBD:
|
||||||
// if ( RAM[io_KBD] > 0x7F ) printf("io_KBD:%04X\n", addr);
|
// if ( RAM[io_KBD] > 0x7F ) printf("io_KBD:%04X\n", addr);
|
||||||
|
Loading…
Reference in New Issue
Block a user