Skip to content

Commit 965c935

Browse files
authored
Add files via upload
1 parent 8c131f7 commit 965c935

File tree

3 files changed

+149
-20
lines changed

3 files changed

+149
-20
lines changed

Source/SKpico.c

Lines changed: 134 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
______/ _____/ _____/ / _/ / /
3-
_/ / / / / _/ / ______/ / _/ ____/ / ______/ ____/
4-
___/ / / / ___/ / / __/ _/ / / / /
5-
_/ _/ _/ _/ / _/ / _/ / _/ _____/ / _/ _/ _/
2+
______/ _____/ _____/ / _/ / /
3+
_/ / / / / _/ / ______/ / _/ ____/ / ______/ ____/
4+
___/ / / / ___/ / / __/ _/ / / / /
5+
_/ _/ _/ _/ / _/ / _/ / _/ _____/ / _/ _/ _/
66
______/ _____/ ______/ _/ _/ _/ _____/ _/ _/ _/ _/ _____/ ____/
77
88
SKpico.c
@@ -98,15 +98,15 @@ uint8_t sidDACMode = SID_DAC_OFF;
9898
#define VERSION_STR_SIZE 36
9999
static const __not_in_flash( "mydata" ) unsigned char VERSION_STR[ VERSION_STR_SIZE ] = {
100100
#if defined( USE_SPDIF )
101-
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '2', '0', '/', 0x53, 0x50, 0x44, 0x49, 0x46, 0, 0, 0, 0, // version string to show
101+
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '2', '1', '/', 0x53, 0x50, 0x44, 0x49, 0x46, 0, 0, 0, 0, // version string to show
102102
#endif
103103
#if defined( USE_DAC )
104-
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '2', '0', '/', 0x44, 0x41, 0x43, '6', '4', 0, 0, 0, 0, // version string to show
104+
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '2', '1', '/', 0x44, 0x41, 0x43, '6', '4', 0, 0, 0, 0, // version string to show
105105
#elif defined( OUTPUT_VIA_PWM )
106-
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '2', '0', '/', 0x50, 0x57, 0x4d, '6', '4', 0, 0, 0, 0, // version string to show
106+
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '2', '1', '/', 0x50, 0x57, 0x4d, '6', '4', 0, 0, 0, 0, // version string to show
107107
#endif
108108
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, 0x00, 0x00, // signature + extension version 0
109-
0, 14, // firmware version with stepping = 0.12
109+
0, 21, // firmware version with stepping = 0.12
110110
#ifdef SID_DAC_MODE_SUPPORT // support DAC modes? which?
111111
SID_DAC_MONO8 | SID_DAC_STEREO8,
112112
#else
@@ -135,9 +135,11 @@ extern void readRegs( uint8_t *p1, uint8_t *p2 );
135135
#define PHI 12
136136
#define AUDIO_PIN 13
137137
#define SID 21
138+
#define RESET 22
138139
#define LED_BUILTIN 25
139140
#define POTX ( 10 )
140141
#define POTY ( 11 )
142+
#define bRESET ( 1 << RESET )
141143
#define bSID ( 1 << SID )
142144
#define bPHI ( 1 << PHI )
143145
#define bRW ( 1 << RW )
@@ -293,6 +295,11 @@ uint32_t ringTime[ RING_SIZE ];
293295
uint8_t ringWrite = 0;
294296
uint8_t ringRead = 0;
295297

298+
void resetEverything()
299+
{
300+
ringRead = ringWrite = 0;
301+
}
302+
296303
uint8_t stateGoingTowardsTransferMode = 0;
297304

298305
typedef enum {
@@ -597,8 +604,6 @@ void runEmulation()
597604
{
598605
writeReSID2( ( cmd >> 8 ) & 0x1f, cmd & 255 );
599606
}
600-
//pio_sm_put_blocking( pio0, 1, 0xffffff );
601-
//while ( 1 ) {}
602607
} else
603608
{
604609
uint8_t reg = cmd >> 8;
@@ -1293,6 +1298,33 @@ void handleBus()
12931298
{
12941299
skipSmoothing = 0;
12951300

1301+
#define max( a, b ) ( (a)>(b)?(a):(b) )
1302+
#define min( a, b ) ( (a)<(b)?(a):(b) )
1303+
#ifdef DIAGROM_HACK
1304+
if ( DIAGROM_THRESHOLD >= 80 )
1305+
{
1306+
if ( abs( newPotXCandidate - newPotYCandidate ) < 10 && newPotXCandidate >= 50 && newPotXCandidate < DIAGROM_THRESHOLD )
1307+
{
1308+
if ( presumablyFixedResistor < 40000 )
1309+
presumablyFixedResistor ++;
1310+
} else
1311+
{
1312+
if ( presumablyFixedResistor )
1313+
presumablyFixedResistor --;
1314+
}
1315+
if ( presumablyFixedResistor > 1000 )
1316+
diagROM_PaddleOffset = min( DIAGROM_THRESHOLD - newPotXCandidate, ( presumablyFixedResistor - 1000 ) / 1000 ); else
1317+
diagROM_PaddleOffset = 0;
1318+
newPotXCandidate = min( 255, (int)newPotXCandidate + (int)diagROM_PaddleOffset );
1319+
newPotYCandidate = min( 255, (int)newPotYCandidate + (int)diagROM_PaddleOffset );
1320+
} else
1321+
if ( DIAGROM_THRESHOLD > 1 )
1322+
{
1323+
newPotXCandidate = min( 255, (int)newPotXCandidate + (int)DIAGROM_THRESHOLD );
1324+
newPotYCandidate = min( 255, (int)newPotYCandidate + (int)DIAGROM_THRESHOLD );
1325+
}
1326+
#endif
1327+
12961328
if ( !paddleFilterMode )
12971329
{
12981330
outRegisters[ 25 ] = newPotXCandidate;
@@ -1446,6 +1478,7 @@ void handleBus()
14461478
\__, \__/ | \| | | \__> |__) \__/ .__/ | | /~~\ | \| |__/ |___ | | \| \__>
14471479
*/
14481480
uint8_t busTimingTestValue = 0;
1481+
uint8_t transferPRGSlot = 0;
14491482
while ( true )
14501483
{
14511484
//
@@ -1574,6 +1607,97 @@ void handleBus()
15741607
prgLaunch = 1;
15751608
stateInConfigMode = 0;
15761609
} else
1610+
if ( A == 0x14 || A == 0x15 ) // start bus timing banging: value #1 and #2
1611+
{
1612+
transferPRGSlot = 254 - 0x14 + A;
1613+
transferPayload = prgCode;
1614+
stateInConfigMode = CONFIG_MODE_CYCLES;
1615+
} else
1616+
if ( A == 0x1a ) // start PRG upload
1617+
{
1618+
transferPRGSlot = D;
1619+
transferPayload = prgCode;
1620+
stateInConfigMode = CONFIG_MODE_CYCLES;
1621+
} else
1622+
if ( A == 0x19 ) // set PRG upload page
1623+
{
1624+
transferPayload = prgCode + D * 256;
1625+
stateInConfigMode = CONFIG_MODE_CYCLES;
1626+
} else
1627+
if ( A == 0x16 ) // upload one PRG byte
1628+
{
1629+
*transferPayload = D;
1630+
transferPayload ++;
1631+
stateInConfigMode = CONFIG_MODE_CYCLES;
1632+
} else
1633+
if ( A == 0x17 ) // end PRG upload, or end of bus timing banging!
1634+
{
1635+
SET_CLOCK_125MHZ
1636+
DELAY_Nx3p2_CYCLES( 85000 );
1637+
1638+
if ( transferPRGSlot >= 254 )
1639+
{
1640+
int *histo = (int*)&prgCode[ 16384 ];
1641+
memset( histo, 0, 256 * sizeof( int ) );
1642+
int sz = transferPayload - prgCode;
1643+
for ( int i = 0; i < sz; i++ )
1644+
histo[ prgCode[ i ] ] ++;
1645+
int maxV = histo[ 0 ], maxIdx = 0;
1646+
for ( int i = 1; i < sz; i++ )
1647+
if ( histo[ i ] > maxV )
1648+
{
1649+
maxV = histo[ i ];
1650+
maxIdx = i;
1651+
}
1652+
1653+
if ( transferPRGSlot == 254 )
1654+
{
1655+
DELAY_READ_BUS = maxIdx;
1656+
}else
1657+
{
1658+
DELAY_PHI2 = maxIdx;
1659+
1660+
unsigned char *tmp = &prgCode[ 16384 + 1024 ];
1661+
{
1662+
#define FLASH_BUSTIMING_OFFSET ((uint32_t)&busTimings[ 0 ] - XIP_BASE)
1663+
memcpy( tmp, (void*)FLASH_BUSTIMING_OFFSET, FLASH_SECTOR_SIZE );
1664+
DELAY_READ_BUS_local = tmp[ 0 ] = DELAY_READ_BUS;
1665+
DELAY_PHI2_local = tmp[ 1 ] = DELAY_PHI2;
1666+
1667+
flash_range_erase ( FLASH_BUSTIMING_OFFSET, FLASH_SECTOR_SIZE );
1668+
flash_range_program( FLASH_BUSTIMING_OFFSET, tmp, FLASH_SECTOR_SIZE );
1669+
}
1670+
}
1671+
} else
1672+
{
1673+
int sz = transferPayload - prgCode - 18; // -18 because menu entry is 18 byte (string null-terminated)
1674+
1675+
uint8_t *dirEntry = &prgDirectory[ transferPRGSlot * 24 ];
1676+
1677+
memcpy( dirEntry, prgCode + sz, 18 );
1678+
dirEntry[ 18 ] = 0;
1679+
dirEntry[ 19 ] = 0;
1680+
dirEntry[ 20 ] = transferPRGSlot;
1681+
dirEntry[ 21 ] = 0;
1682+
dirEntry[ 22 ] = sz & 255;
1683+
dirEntry[ 23 ] = sz >> 8;
1684+
1685+
#define FLASH_DIR_OFFSET ((uint32_t)&prgDirectory_Flash[ 0 ] - XIP_BASE)
1686+
flash_range_erase ( FLASH_DIR_OFFSET, FLASH_SECTOR_SIZE );
1687+
flash_range_program( FLASH_DIR_OFFSET, prgDirectory, FLASH_SECTOR_SIZE );
1688+
1689+
prgCode[ 0 ] = 1;
1690+
prgCode[ 1 ] = 8;
1691+
1692+
#define FLASH_PRG_OFFSET ((uint32_t)&prgRepository[ transferPRGSlot * 65536 ] - XIP_BASE)
1693+
flash_range_erase ( FLASH_PRG_OFFSET, 65536 );
1694+
flash_range_program( FLASH_PRG_OFFSET, prgCode, 65536 );
1695+
}
1696+
SET_CLOCK_FAST
1697+
prgLaunch = 0;
1698+
currentPRG = 254;
1699+
stateInConfigMode = 0;
1700+
} else
15771701
if ( A == 0x10 )
15781702
{
15791703
SET_CLOCK_125MHZ
@@ -1646,7 +1770,6 @@ void writeConfiguration()
16461770
config[ 63 ] = c >> 8;
16471771

16481772
flash_range_program( FLASH_CONFIG_OFFSET, config, FLASH_PAGE_SIZE );
1649-
SET_CLOCK_FAST
16501773

16511774
SET_CLOCK_125MHZ
16521775
DELAY_Nx3p2_CYCLES( 85000 );

Source/prgslots.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
*/
2626

2727
#include "pico/stdlib.h"
28+
#include "hardware/flash.h"
2829

2930
uint8_t prgDirectory[ 16 * 24 + 1 ];
3031

31-
const volatile uint8_t __in_flash( "PRGDirectory" ) prgDirectory_Flash[ 16 * 24 + 1 ] =
32+
const volatile uint8_t __in_flash( "PRGDirectory" ) prgDirectory_Flash[ 16 * 24 + 1 ] __attribute__((aligned(FLASH_SECTOR_SIZE))) =
3233
{
3334
// 18 byte name (string null-terminated), 4 byte ofs, 2 byte length
3435
'E', 'M', 'P', 'T', 'Y', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -50,5 +51,5 @@ const volatile uint8_t __in_flash( "PRGDirectory" ) prgDirectory_Flash[ 16 * 24
5051
0xff
5152
};
5253

53-
const volatile uint8_t __in_flash( "PRGData" ) prgRepository[ 1024 * 1024 ] =
54+
const volatile uint8_t __in_flash( "PRGData" ) prgRepository[ 1024 * 1024 ] __attribute__((aligned(FLASH_SECTOR_SIZE))) =
5455
{ 'S', 'I', 'D', 'K', 'I', 'C', 'K', ' ', 'R', 'E', 'P', 'O', 0, 0, 0, 0, 0, 0, 0, 0 };

Source/reSIDWrapper.cc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,16 @@ extern "C"
309309
{
310310
int32_t sid1 = sid16->output();
311311

312-
int32_t L = sid1 * actVolSID1_Left + fm * actVolSID2_Left;
313-
int32_t R = sid1 * actVolSID1_Right + fm * actVolSID2_Right;
312+
int32_t L = sid1 * actVolSID1_Left + (fm * actVolSID2_Left * 2);
313+
int32_t R = sid1 * actVolSID1_Right + (fm * actVolSID2_Right * 2);
314314

315-
*left = L >> 16;
316-
*right = R >> 16;
315+
L >>= 16; R >>= 16;
316+
if ( L > 32767 ) L = 32767;
317+
if ( R > 32767 ) R = 32767;
318+
if ( L < -32767 ) L = -32767;
319+
if ( R < -32767 ) R = -32767;
320+
*left = L;
321+
*right = R;
317322

318323
#ifdef USE_RGB_LED
319324
// SID #1 voices map to red, green, blue
@@ -344,9 +349,9 @@ extern "C"
344349
for ( int i = 0; i < 9; i++ )
345350
{
346351
extern int32_t outputCh[ 9 ];
347-
voiceOutAcc[ 0 ] += ( colorMap[ i ][ 0 ] * outputCh[ i ] ) >> 2;
348-
voiceOutAcc[ 1 ] += ( colorMap[ i ][ 1 ] * outputCh[ i ] ) >> 2;
349-
voiceOutAcc[ 2 ] += ( colorMap[ i ][ 2 ] * outputCh[ i ] ) >> 2;
352+
voiceOutAcc[ 0 ] += ( colorMap[ i ][ 0 ] * outputCh[ i ] ) >> 1;
353+
voiceOutAcc[ 1 ] += ( colorMap[ i ][ 1 ] * outputCh[ i ] ) >> 1;
354+
voiceOutAcc[ 2 ] += ( colorMap[ i ][ 2 ] * outputCh[ i ] ) >> 1;
350355
}
351356
nSamplesAcc ++;
352357
#endif

0 commit comments

Comments
 (0)