Skip to content

Commit

Permalink
- in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
DnCraptor committed Dec 14, 2023
1 parent 973edea commit 75e16b4
Show file tree
Hide file tree
Showing 3 changed files with 298 additions and 28 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ To swap floppy drives A <-> B use: Left Ctrl + Tab + Backspace
To turn on/off
Digital Sound Source on LPT1, use Ctrl + Tab + D. Default value - it is ON
COVOX on LPT2, use Ctrl + Tab + C. Default value - it is ON
Tandy 3-voise music device emulation, use Ctrl + Tab + T. Default value - it is ON
Tandy 3-voices music device emulation, use Ctrl + Tab + T. Default value - it is ON
Game Blaster (Creative Music System) device emulation, use Ctrl + Tab + G. Default value - it is OFF
AdLib emulation, use Ctrl + Tab + A. Default value - it is OFF (experimental, not recomended)
Whole sound emulation subsystem, use Ctrl + Tab + S. Default value - it is ON
Etended Memory Manager (XMS, use Ctrl + Tab + X). Default value - it is OFF (have some issues with Wolf 3D)
Epanded Memory Manager (EMS, use Ctrl + Tab + E). Default value - it is ON
Upper Memory Blocks Manager (UMB, use Ctrl + Tab + U). Default value - it is ON
Hight Memory Address Manager (HMA, use Ctrl + Tab + H). Default value - it is ON
// Experimental: use before DOS (while BIOS test RAM)
Etended Memory Manager (XMS), use Ctrl + Tab + X. Default value - it is OFF (have some issues with Wolf 3D)
Epanded Memory Manager (EMS), use Ctrl + Tab + E. Default value - it is ON
Upper Memory Blocks Manager (UMB), use Ctrl + Tab + U. Default value - it is ON
Hight Memory Address Manager (HMA), use Ctrl + Tab + H. Default value - it is ON
// TODO: save state to config file

To decrease or increase appropriated sound device volume, press related button and numpad "+" / "-",
for example "D" + "-" will decrease DSS volume, "S" + "+" - increase whole sound system volume.
Expand Down
39 changes: 27 additions & 12 deletions drivers/vga-nextgen/vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,18 @@ extern volatile bool is_game_balaster_on;
extern volatile bool is_tandy3v_on;
extern volatile bool is_dss_on;
extern volatile bool is_sound_on;
extern volatile uint8_t snd_divider;
extern volatile uint8_t cms_divider;
extern volatile uint8_t dss_divider;
extern volatile uint8_t adlib_divider;
extern volatile uint8_t tandy3v_divider;
extern volatile uint8_t covox_divider;

inline static void sound_callback() {
static uint32_t dss_cycles_per_vga = 0;
static uint8_t last_dss_sample = 0;
static uint32_t adlib_cycles_per_vga = 0;
static int16_t last_adlib_sample = 0;
static int16_t sum_adlib_samples = 0;
static int sum_adlib_samples = 0;

dss_cycles_per_vga += 10;
adlib_cycles_per_vga += 1;
Expand All @@ -109,10 +114,12 @@ inline static void sound_callback() {
if (is_adlib_on) {
if (adlib_cycles_per_vga > 9) { // TODO: adjust rate
adlib_cycles_per_vga = 0;
}
sum_adlib_samples += adlibgensample_ch(adlib_cycles_per_vga);
out += (int16_t)(sum_adlib_samples >> adlib_divider);
if (adlib_cycles_per_vga == 0) {
sum_adlib_samples = 0;
}
sum_adlib_samples += (int16_t)(adlibgensample_ch(adlib_cycles_per_vga) >> 5);
out += last_adlib_sample;
}
#endif
#if SOUND_BLASTER
Expand All @@ -125,23 +132,29 @@ inline static void sound_callback() {
last_dss_sample = dss_sample();
dss_cycles_per_vga = 0;
}
out += ((int16_t)last_dss_sample - (int16_t)0x0080) << 7; // 8 unsigned on LPT1 mix to signed 16
out += dss_divider > 8 ?
((int16_t)last_dss_sample - (int16_t)0x0080) >> (dss_divider - 8):
((int16_t)last_dss_sample - (int16_t)0x0080) << (dss_divider + 8); // 8 unsigned on LPT1 mix to signed 16
}
#endif
#ifdef COVOX
if (is_covox_on) {
out += ((int16_t)true_covox - (int16_t)0x0080) << 7; // 8 unsigned on LPT2 mix to signed 18
out += covox_divider > 8 ?
((int16_t)true_covox - (int16_t)0x0080) >> (dss_divider - 8):
((int16_t)true_covox - (int16_t)0x0080) << (dss_divider + 8); // 8 unsigned on LPT2 mix to signed 16
}
#endif
#ifdef TANDY3V
if (is_tandy3v_on)
out += sn76489_sample(); // already signed 16
if (is_tandy3v_on) {
out += sn76489_sample() >> tandy3v_divider; // already signed 16
}
#endif
#ifdef CMS
if (is_game_balaster_on) {
cms_samples(&out_l, &out_r);
out_l = out + (out_l >> 12); // mix it with decrease volume
out_r = out + (out_r >> 12);
register uint8_t d = cms_divider;
out_l = out + (out_l >> d); // mix it with decrease volume
out_r = out + (out_r >> d);
} else {
out_l = out;
out_r = out;
Expand All @@ -150,8 +163,10 @@ inline static void sound_callback() {
out_l = out;
out_r = out;
#endif
pwm_set_gpio_level(PWM_PIN0,(int16_t)((int32_t)out_r + 0x8000)); // Право signed 16 to unsigned 16
pwm_set_gpio_level(PWM_PIN1,(int16_t)((int32_t)out_l + 0x8000)); // Лево signed 16 to unsigned 16
register uint8_t r_rivider = snd_divider; // TODO: tume up divider per channel
register uint8_t l_rivider = snd_divider;
pwm_set_gpio_level(PWM_PIN0,(int16_t)((int32_t)out_r + 0x8000L) >> r_rivider); // Право signed 16 to unsigned 16
pwm_set_gpio_level(PWM_PIN1,(int16_t)((int32_t)out_l + 0x8000L) >> l_rivider); // Лево signed 16 to unsigned 16
}
#endif

Expand Down
Loading

0 comments on commit 75e16b4

Please sign in to comment.