Skip to content

Commit

Permalink
Merge branch 'master' into cms
Browse files Browse the repository at this point in the history
# Conflicts:
#	drivers/vga-nextgen/vga.c
  • Loading branch information
xrip committed Dec 13, 2023
2 parents 035d9b3 + 13c3618 commit 246b1ff
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 36 deletions.
39 changes: 28 additions & 11 deletions drivers/vga-nextgen/vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,41 @@ extern volatile bool manager_started;
#include <hardware/pwm.h>
#define PWM_PIN0 (26)
#define PWM_PIN1 (27)
volatile uint32_t sound_cycles_per_vga = 0;
// регистр "защёлка" для примитивного ковокса без буфера
volatile uint16_t true_covox = 0;

int16_t sn76489_sample();
int16_t dss_sample();
void cms_samples(int16_t out[2]);
static int16_t last_dss_sample = 0;
int16_t adlibgensample();

void __not_in_flash_func(sound_callback)(repeating_timer_t *rt) {
sound_cycles_per_vga+=10;
inline static void sound_callback() {
static uint32_t dss_cycles_per_vga = 0;
static int16_t last_dss_sample = 0;
static uint32_t adlib_cycles_per_vga = 0;
static int16_t last_adlib_sample = 0;
static int32_t sum_adlib_samples = 0;

dss_cycles_per_vga += 10;
adlib_cycles_per_vga += 1;
int16_t outs[0] = { 0 };
#if SOUND_BLASTER || ADLIB
out += adlibgensample() >> 3;
//sum_adlib_samples += adlibgensample_ch(adlib_cycles_per_vga);
if (adlib_cycles_per_vga >= 9) { // TODO: adjust rate
adlib_cycles_per_vga = 0;
last_adlib_sample = adlibgensample(); // << 16 too mach, but i32 to i16...
sum_adlib_samples = 0;
}
out += last_adlib_sample;
#endif
#if SOUND_BLASTER
tickBlaster();
out += getBlasterSample();
#endif
#if DSS
if (sound_cycles_per_vga >= 70) { // about 7-8kHz, TODO: divide by 4.5
if (dss_cycles_per_vga >= 70) { // about 7-8kHz, TODO: divide by 4.5
last_dss_sample = dss_sample();
sound_cycles_per_vga = 0;
dss_cycles_per_vga = 0;
}
outs[0] += last_dss_sample;
outs[0] += true_covox; // on LPT2
Expand All @@ -116,10 +128,7 @@ void __not_in_flash_func(sound_callback)(repeating_timer_t *rt) {
}
#endif

void __not_in_flash_func(dma_handler_VGA)() {
#ifdef SOUND_SYSTEM
sound_callback(0);
#endif
inline static void dma_handler_VGA_impl() {
dma_hw->ints0 = 1u << dma_chan_ctrl;
static uint32_t frame_number = 0;
static uint32_t screen_line = 0;
Expand Down Expand Up @@ -380,6 +389,14 @@ void __not_in_flash_func(dma_handler_VGA)() {
dma_channel_set_read_addr(dma_chan_ctrl, output_buffer, false);
}

// to start sound later
void __not_in_flash_func(dma_handler_VGA)() {
dma_handler_VGA_impl();
#ifdef SOUND_SYSTEM
sound_callback();
#endif
}

enum graphics_mode_t graphics_set_mode(enum graphics_mode_t mode) {
switch (mode) {
case TEXTMODE_40x30:
Expand Down
45 changes: 27 additions & 18 deletions src/audio/adlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ uint8_t inadlib ( uint16_t portnum )
}


static uint16_t adlibfreq ( uint8_t chan )
static inline uint16_t adlibfreq ( uint8_t chan )
{
uint16_t tmpfreq;
if (!adlibch[chan].keyon)
Expand Down Expand Up @@ -193,20 +193,18 @@ static uint16_t adlibfreq ( uint8_t chan )
return tmpfreq;
}


static uint64_t fullstep, adlibstep[9];
static double adlibenv[9], adlibdecay[9], adlibattack[9];
static uint8_t adlibdidattack[9];


static int32_t adlibsample ( uint8_t curchan )
inline static int32_t adlibsample ( uint8_t curchan )
{
int32_t tempsample;
double tempstep;
if (adlibpercussion && (curchan >= 6) && (curchan <= 8))
return 0;
// FIXME: 7100
fullstep = 11000/adlibfreq(curchan);
fullstep = 5000/adlibfreq(curchan);
tempsample = (int32_t)oplwave[adlibch[curchan].wavesel][(uint8_t)((double)adlibstep[curchan] / ((double)fullstep / (double)256))];
tempstep = adlibenv[curchan];
if (tempstep > 1.0)
Expand All @@ -218,32 +216,43 @@ static int32_t adlibsample ( uint8_t curchan )
return tempsample;
}


static inline void tickadlib_ch ( uint16_t curchan )
{
if (adlibfreq(curchan) != 0) {
if (adlibdidattack[curchan]) {
adlibenv[curchan] *= adlibdecay[curchan];
} else {
adlibenv[curchan] *= adlibattack[curchan];
if (adlibenv[curchan] >= 1.0)
adlibdidattack[curchan] = 1;
}
}
}

void tickadlib ( void )
{
for (int curchan = 0; curchan < 9; curchan++) {
if (adlibfreq(curchan) !=0) {
if (adlibdidattack[curchan]) {
adlibenv[curchan] *= adlibdecay[curchan];
} else {
adlibenv[curchan] *= adlibattack[curchan];
if (adlibenv[curchan] >= 1.0)
adlibdidattack[curchan] = 1;
}
}
tickadlib_ch(curchan);
}
}

int32_t adlibgensample_ch(int16_t ch) {
tickadlib_ch(ch);
if (adlibfreq(ch) != 0) {
return adlibsample(ch);
}
return 0;
}

int16_t adlibgensample ( void )
{
tickadlib();
int16_t adlibaccum = 0;
for (int curchan = 0; curchan < 9; curchan++) {
if (adlibfreq(curchan) !=0) {
adlibaccum += (int16_t)adlibsample(curchan);
if (adlibfreq(curchan) != 0) {
adlibaccum += adlibsample(curchan);
}
}
return adlibaccum;
return (adlibaccum >> 4)+128;
}

2 changes: 1 addition & 1 deletion src/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static bool a20_line_open = false;

void notify_a20_line_state_changed(bool v) {
// Tandy hack
write86(0xFC000, 0x21);
write86(0xFC000, 0x21); // write to ROM? it is req. to tune up rom-shatow to work this way
a20_line_open = v;
if (v) {
map_hma_ram_pages();
Expand Down
3 changes: 1 addition & 2 deletions src/emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,14 @@ uint8_t dss_in(uint16_t portnum);

int16_t dss_sample();

extern int16_t adlibgensample(void);

extern uint8_t inadlib(uint16_t portnum);

extern void initadlib(uint16_t baseport);

extern void outadlib(uint16_t portnum, uint8_t value);

extern void tickadlib(void);
extern int16_t adlibgensample(void);


extern int16_t getBlasterSample(void);
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static void fill_audio(void* udata, uint8_t* stream, int len) { // for SDL mode
int16_t outs[2] = { 0 };
int16_t out = 0;
#if SOUND_BLASTER || ADLIB
out += (adlibgensample() >> 3);
out += adlibgensample();
#endif
#if SOUND_BLASTER
tickBlaster();
Expand Down
8 changes: 5 additions & 3 deletions src/ports.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ static uint8_t vga_palette_index = 0;
static uint8_t vga_color_index = 0;
static uint8_t dac_state = 0;
static uint8_t latchReadRGB = 0, latchReadPal = 0;

extern volatile uint16_t true_covox;
#if PICO_ON_DEVICE
extern
#endif
volatile uint16_t true_covox;

uint32_t ega_plane_offset = 0;
bool vga_planar_mode = false;
Expand Down Expand Up @@ -463,7 +465,7 @@ uint16_t portin(uint16_t portnum) {
case 0x378: return port378;
case 0x379: // ssStatus
return dss_in(portnum);
case 0x3BE: // LPT2 status (covox is always ready)
case 0x27A: // LPT2 status (covox is always ready)
return 0;
#endif
#if SOUND_BLASTER || ADLIB
Expand Down

0 comments on commit 246b1ff

Please sign in to comment.