Skip to content

Commit

Permalink
+ use register for shifter
Browse files Browse the repository at this point in the history
  • Loading branch information
DnCraptor committed Dec 14, 2023
1 parent 682176c commit 7b95f3e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
30 changes: 17 additions & 13 deletions drivers/vga-nextgen/vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ inline static void sound_callback() {
adlib_cycles_per_vga = 0;
}
sum_adlib_samples += adlibgensample_ch(adlib_cycles_per_vga);
out += (int16_t)(sum_adlib_samples >> adlib_divider);
register uint8_t d = adlib_divider;
out += (int16_t)(sum_adlib_samples >> d);
if (adlib_cycles_per_vga == 0) {
sum_adlib_samples = 0;
}
Expand All @@ -132,21 +133,24 @@ inline static void sound_callback() {
last_dss_sample = dss_sample();
dss_cycles_per_vga = 0;
}
out += dss_divider > 8 ?
((int16_t)last_dss_sample - (int16_t)0x0080) >> (dss_divider - 8):
((int16_t)last_dss_sample - (int16_t)0x0080) << (8 - dss_divider); // 8 unsigned on LPT1 mix to signed 16
register uint8_t d = dss_divider;
out += d > 8 ?
((int16_t)last_dss_sample - (int16_t)0x0080) >> (d - 8):
((int16_t)last_dss_sample - (int16_t)0x0080) << (8 - d); // 8 unsigned on LPT1 mix to signed 16
}
#endif
#ifdef COVOX
if (is_covox_on) {
out += covox_divider > 8 ?
((int16_t)true_covox - (int16_t)0x0080) >> (covox_divider - 8):
((int16_t)true_covox - (int16_t)0x0080) << (8 - covox_divider); // 8 unsigned on LPT2 mix to signed 16
if (is_covox_on && true_covox) {
register uint8_t d = covox_divider;
out += d > 8 ?
((int16_t)true_covox - (int16_t)0x0080) >> (d - 8):
((int16_t)true_covox - (int16_t)0x0080) << (8 - d); // 8 unsigned on LPT2 mix to signed 16
}
#endif
#ifdef TANDY3V
if (is_tandy3v_on) {
out += sn76489_sample() >> tandy3v_divider; // already signed 16
register uint8_t d = tandy3v_divider;
out += sn76489_sample() >> d; // already signed 16
}
#endif
#ifdef CMS
Expand All @@ -163,10 +167,10 @@ inline static void sound_callback() {
out_l = out;
out_r = out;
#endif
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
register uint8_t r_divider = snd_divider; // TODO: tume up divider per channel
register uint8_t l_divider = snd_divider;
pwm_set_gpio_level(PWM_PIN0,(uint16_t)((int32_t)out_r + 0x8000L) >> r_divider); // Право signed 16 to unsigned 16
pwm_set_gpio_level(PWM_PIN1,(uint16_t)((int32_t)out_l + 0x8000L) >> l_divider); // Лево signed 16 to unsigned 16
}
#endif

Expand Down
6 changes: 5 additions & 1 deletion src/audio/adlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <stdint.h>
#include <stdio.h>

#include <stdbool.h>

//static double samprateadjust = 1.0;
//static uint8_t optable[0x16] = { 0, 0, 0, 1, 1, 1, 255, 255, 0, 0, 0, 1, 1, 1, 255, 255, 0, 0, 0, 1, 1, 1 };
Expand Down Expand Up @@ -106,9 +106,11 @@ static uint8_t adlibdidattack[9], adlibpercussion = 0, adlibstatus = 0;

static uint16_t adlibport = 0x388;

extern volatile bool is_adlib_on;

void outadlib ( uint16_t portnum, uint8_t value )
{
if (!is_adlib_on) return;
if (portnum == adlibport) {
adlibaddr = value;
return;
Expand Down Expand Up @@ -153,6 +155,7 @@ void outadlib ( uint16_t portnum, uint8_t value )

uint8_t inadlib ( uint16_t portnum )
{
if (!is_adlib_on) return 0;
if (!adlibregmem[4])
adlibstatus = 0;
else
Expand Down Expand Up @@ -231,6 +234,7 @@ static inline void tickadlib_ch ( uint16_t curchan )

void tickadlib ( void )
{
if (!is_adlib_on) return;
for (int curchan = 0; curchan < 9; curchan++) {
tickadlib_ch(curchan);
}
Expand Down
2 changes: 1 addition & 1 deletion src/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ volatile uint8_t cms_divider = 12;
volatile uint8_t dss_divider = 0;
volatile uint8_t adlib_divider = 0;
volatile uint8_t tandy3v_divider = 0;
volatile uint8_t covox_divider = 9;
volatile uint8_t covox_divider = 0;

volatile bool is_xms_on = false;
volatile bool is_ems_on = true;
Expand Down

0 comments on commit 7b95f3e

Please sign in to comment.