Skip to content

Commit

Permalink
tweak resid dac leakage. patch by leandro nini
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.code.sf.net/p/vice-emu/code/trunk@45175 379a1393-f5fb-40a0-bcee-ef074d9b53f7
  • Loading branch information
mrdudz committed May 31, 2024
1 parent 9a44be9 commit f52a002
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions vice/src/resid/dac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
namespace reSID
{

// "Even in standard transistors a small amount of current leaks
// even when they are technically switched off."
// https://en.wikipedia.org/wiki/Subthreshold_conduction
static const double MOSFET_LEAKAGE_6581 = 0.0075;
static const double MOSFET_LEAKAGE_8580 = 0.0035;

// ----------------------------------------------------------------------------
// Calculation of lookup tables for SID DACs.
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -73,6 +79,8 @@ void build_dac_table(unsigned short* dac, int bits, double _2R_div_R, bool term)
// double vbit[bits];
double vbit[12];

const double leakage = term ? MOSFET_LEAKAGE_8580 : MOSFET_LEAKAGE_6581;

// Calculate voltage contribution by each individual bit in the R-2R ladder.
for (int set_bit = 0; set_bit < bits; set_bit++) {
int bit;
Expand Down Expand Up @@ -119,10 +127,7 @@ void build_dac_table(unsigned short* dac, int bits, double _2R_div_R, bool term)
int x = i;
double Vo = 0;
for (int j = 0; j < bits; j++) {
// "Even in standard transistors a small amount of current leaks
// even when they are technically switched off."
// https://en.wikipedia.org/wiki/Subthreshold_conduction
Vo += ((x & 0x1) ? 1. : 0.01)*vbit[j];
Vo += ((x & 0x1) ? 1. : leakage)*vbit[j];
x >>= 1;
}

Expand Down

0 comments on commit f52a002

Please sign in to comment.