Compare commits

...

3 Commits

Author SHA1 Message Date
tudnai 82100c6bc3 Pixeltrail 2023-05-25 20:29:17 -07:00
tudnai b1e7f620d1 Speaker Fade Slope 2023-05-25 20:28:38 -07:00
tudnai 30917d2b56 Speaker Fade Out 2023-05-25 20:23:41 -07:00
6 changed files with 53 additions and 34 deletions

View File

@ -219,6 +219,8 @@ class HiRes: NSView {
}
}
let usePixelTrail = true
// let pixelTrail = 2 // maybe too fast?
// let pixelTrail = 1.5
@ -275,12 +277,15 @@ class HiRes: NSView {
if shadowScreen[ screenIdx ] != block {
blockChanged[ blockVertIdx + blockHorIdx ] = 0xFF
}
else if ( ViewController.shared?.CRTMonitor ?? false ) {
else if usePixelTrail && ( ViewController.shared?.CRTMonitor ?? false ) {
// slow CRT fade out effect
if (y % HiRes.blockHeight == 0) && (blockChanged[ blockVertIdx + blockHorIdx ] > 0) {
blockChanged[ blockVertIdx + blockHorIdx ] = UInt8( Double(blockChanged[ blockVertIdx + blockHorIdx ]) / pixelTrail )
}
}
else {
blockChanged[ blockVertIdx + blockHorIdx ] = 0
}
shadowScreen[ screenIdx ] = block
@ -296,21 +301,22 @@ class HiRes: NSView {
}
prevColor = monoColor
}
// else if ( ViewController.current?.CRTMonitor ?? false ) {
// var srgb = pixelsSRGB[pixelAddr]
//
// let s = srgb >> 24 & 0xFF
// let r = srgb >> 16 & 0xFF
// let g = srgb >> 8 & 0xFF
// let b = srgb >> 0 & 0xFF
//
// srgb = UInt32(Double(s) / pixelTrail) << 24
// | UInt32(Double(r) / pixelTrail) << 16
// | UInt32(Double(g) / pixelTrail) << 8
// | UInt32(Double(b) / pixelTrail)
//
// pixelsSRGB[pixelAddr] = srgb;
// }
else if usePixelTrail && ( ViewController.shared?.CRTMonitor ?? false ) {
var srgb = pixelsSRGB[pixelAddr + highBit]
let s = srgb >> 24 & 0xFF
let r = srgb >> 16 & 0xFF
let g = srgb >> 8 & 0xFF
let b = srgb >> 0 & 0xFF
srgb = UInt32(Double(s) / pixelTrail) << 24
| UInt32(Double(r) / pixelTrail) << 16
| UInt32(Double(g) / pixelTrail) << 8
| UInt32(Double(b) / pixelTrail)
pixelsSRGB[pixelAddr + highBit] = srgb;
pixelsSRGB[pixelAddr + highBit + 1] = srgb;
}
else {
pixelsSRGB[pixelAddr + highBit] = color_black
pixelsSRGB[pixelAddr + highBit + 1] = color_black
@ -346,7 +352,7 @@ class HiRes: NSView {
case 2: // green
// reducing color bleeding
if (colorAddr > 0) && (pixelsSRGB[colorAddr - 2] != color_black) {
if (colorAddr > 1) && (pixelsSRGB[colorAddr - 2] != color_black) {
pixelsSRGB[colorAddr] = color_green
pixelsSRGB[colorAddr + 1] = color_green
}

View File

@ -1849,6 +1849,7 @@ class ViewController: NSViewController {
fps = DEFAULT_FPS
video_fps_divider = ECO_VIDEO_DIV
spkr_fps_divider = DEF_SPKR_DIV
break
case "Game":
@ -1857,6 +1858,7 @@ class ViewController: NSViewController {
fps = GAME_FPS
video_fps_divider = GAME_VIDEO_DIV
spkr_fps_divider = GAME_SPKR_DIV
break
default:
@ -1865,6 +1867,7 @@ class ViewController: NSViewController {
fps = DEFAULT_FPS
video_fps_divider = DEF_VIDEO_DIV
spkr_fps_divider = DEF_SPKR_DIV
break
}

View File

@ -29,11 +29,13 @@
#include "woz.h"
#ifdef DISASSEMBLER
#define INSTR INLINE static
#else
#define INSTR INLINE static
#endif
//#ifdef DISASSEMBLER
//#define INSTR INLINE static
//#else
//#define INSTR INLINE static
//#endif
#define INSTR static
#define CRYSTAL_MHZ 14.31818 // NTSC version (original)
#define DEFAULT_MHZ_6502 (CRYSTAL_MHZ / 14) // 1.023 MHz
@ -230,13 +232,14 @@ extern double mhz;
#define DEFAULT_FPS 60U
#define DEF_VIDEO_DIV 2U
#define DEF_SPKR_DIV 2U
#define DEF_SPKR_DIV 1U
#define DEF_DRV_LED_DIV 4U
#define ECO_VIDEO_DIV 4U
#define GAME_FPS 60U // 180U // 480U
#define GAME_VIDEO_DIV 1U // (GAME_FPS / DEFAULT_FPS)
#define GAME_FPS 600U // 180U // 480U
#define GAME_VIDEO_DIV 10U // (GAME_FPS / DEFAULT_FPS)
#define GAME_SPKR_DIV 10U
extern unsigned int video_fps_divider;
extern unsigned int fps;

View File

@ -125,7 +125,7 @@ float spkr_vol = 0.5;
unsigned spkr_fps = DEFAULT_FPS;
//unsigned spkr_fps_divider = 1;
unsigned spkr_fps_divider = DEF_SPKR_DIV;
unsigned spkr_frame_cntr = 0;
unsigned spkr_clk = 0;
@ -498,14 +498,17 @@ char spkr_state = 0;
#define _NO_SPKR_EARLY_ZERO_LEVEL 500
const float SPKR_FADE_TRAILING_SLOPE = 0.2;
INLINE void spkr_finish_square(const int new_idx) {
float level = spkr_level;
const float slope = spkr_level >= 0 ? SPKR_FADE_TRAILING_SLOPE : -SPKR_FADE_TRAILING_SLOPE;
// avoid buffer under/over runs
if ( (new_idx < 0) || (new_idx >= SPKR_BUF_SLOT_SIZE(BUFFER_COUNT)) ) {
return;
}
// only fill small enough gaps and larger ones will go back to 0
#ifdef SPKR_EARLY_ZERO_LEVEL
@ -513,6 +516,10 @@ INLINE void spkr_finish_square(const int new_idx) {
#endif
// finish the aquare wave
while ( spkr_sample_last_idx < new_idx ) {
if ( fabs(level) > SPKR_FADE_TRAILING_SLOPE ) {
level -= slope;
spkr_level = level;
}
spkr_samples[ spkr_sample_last_idx++ ] = spkr_level;
spkr_samples[ spkr_sample_last_idx++ ] = spkr_level; // stereo
}
@ -1156,7 +1163,7 @@ void spkr_buffer_with_prebuf(void) {
void spkr_update() {
// if ( ++spkr_frame_cntr >= spkr_fps_divider ) {
if ( ++spkr_frame_cntr >= spkr_fps_divider ) {
spkr_frame_cntr = 0;
// Fix: Unqueue was not working properly some cases, so we need to monitor
@ -1248,10 +1255,10 @@ void spkr_update() {
spkr_clk = 0;
// }
// else {
// spkr_clk += m6502.clkfrm;
// }
}
else {
spkr_clk += m6502.clkfrm;
}
// free up unused buffers
spkr_unqueue( spkr_src[SPKR_SRC_GAME_SFX] );

View File

@ -85,7 +85,7 @@ extern const double spkr_sample_rate;
extern const unsigned spkr_buf_alloc_size;
extern const unsigned spkr_buf_size;
extern unsigned spkr_fps;
//extern unsigned spkr_fps_divider;
extern unsigned spkr_fps_divider;
extern spkr_sample_t * spkr_samples;
extern int spkr_sample_idx;
extern int spkr_level;

View File

@ -32,7 +32,7 @@ uint8_t* HiResBufferPointer = Apple2_64K_MEM + Page1Addr;
uint16_t HiResLineAddrTbl[PixelHeight];
double pixelTrail = 15;
double pixelTrail = 2.0;
typedef enum {