Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
frntc authored Aug 19, 2024
1 parent 8c131f7 commit 965c935
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 20 deletions.
145 changes: 134 additions & 11 deletions Source/SKpico.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
______/ _____/ _____/ / _/ / /
_/ / / / / _/ / ______/ / _/ ____/ / ______/ ____/
___/ / / / ___/ / / __/ _/ / / / /
_/ _/ _/ _/ / _/ / _/ / _/ _____/ / _/ _/ _/
______/ _____/ _____/ / _/ / /
_/ / / / / _/ / ______/ / _/ ____/ / ______/ ____/
___/ / / / ___/ / / __/ _/ / / / /
_/ _/ _/ _/ / _/ / _/ / _/ _____/ / _/ _/ _/
______/ _____/ ______/ _/ _/ _/ _____/ _/ _/ _/ _/ _____/ ____/
SKpico.c
Expand Down Expand Up @@ -98,15 +98,15 @@ uint8_t sidDACMode = SID_DAC_OFF;
#define VERSION_STR_SIZE 36
static const __not_in_flash( "mydata" ) unsigned char VERSION_STR[ VERSION_STR_SIZE ] = {
#if defined( USE_SPDIF )
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '2', '0', '/', 0x53, 0x50, 0x44, 0x49, 0x46, 0, 0, 0, 0, // version string to show
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '2', '1', '/', 0x53, 0x50, 0x44, 0x49, 0x46, 0, 0, 0, 0, // version string to show
#endif
#if defined( USE_DAC )
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '2', '0', '/', 0x44, 0x41, 0x43, '6', '4', 0, 0, 0, 0, // version string to show
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '2', '1', '/', 0x44, 0x41, 0x43, '6', '4', 0, 0, 0, 0, // version string to show
#elif defined( OUTPUT_VIA_PWM )
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '2', '0', '/', 0x50, 0x57, 0x4d, '6', '4', 0, 0, 0, 0, // version string to show
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '2', '1', '/', 0x50, 0x57, 0x4d, '6', '4', 0, 0, 0, 0, // version string to show
#endif
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, 0x00, 0x00, // signature + extension version 0
0, 14, // firmware version with stepping = 0.12
0, 21, // firmware version with stepping = 0.12
#ifdef SID_DAC_MODE_SUPPORT // support DAC modes? which?
SID_DAC_MONO8 | SID_DAC_STEREO8,
#else
Expand Down Expand Up @@ -135,9 +135,11 @@ extern void readRegs( uint8_t *p1, uint8_t *p2 );
#define PHI 12
#define AUDIO_PIN 13
#define SID 21
#define RESET 22
#define LED_BUILTIN 25
#define POTX ( 10 )
#define POTY ( 11 )
#define bRESET ( 1 << RESET )
#define bSID ( 1 << SID )
#define bPHI ( 1 << PHI )
#define bRW ( 1 << RW )
Expand Down Expand Up @@ -293,6 +295,11 @@ uint32_t ringTime[ RING_SIZE ];
uint8_t ringWrite = 0;
uint8_t ringRead = 0;

void resetEverything()
{
ringRead = ringWrite = 0;
}

uint8_t stateGoingTowardsTransferMode = 0;

typedef enum {
Expand Down Expand Up @@ -597,8 +604,6 @@ void runEmulation()
{
writeReSID2( ( cmd >> 8 ) & 0x1f, cmd & 255 );
}
//pio_sm_put_blocking( pio0, 1, 0xffffff );
//while ( 1 ) {}
} else
{
uint8_t reg = cmd >> 8;
Expand Down Expand Up @@ -1293,6 +1298,33 @@ void handleBus()
{
skipSmoothing = 0;

#define max( a, b ) ( (a)>(b)?(a):(b) )
#define min( a, b ) ( (a)<(b)?(a):(b) )
#ifdef DIAGROM_HACK
if ( DIAGROM_THRESHOLD >= 80 )
{
if ( abs( newPotXCandidate - newPotYCandidate ) < 10 && newPotXCandidate >= 50 && newPotXCandidate < DIAGROM_THRESHOLD )
{
if ( presumablyFixedResistor < 40000 )
presumablyFixedResistor ++;
} else
{
if ( presumablyFixedResistor )
presumablyFixedResistor --;
}
if ( presumablyFixedResistor > 1000 )
diagROM_PaddleOffset = min( DIAGROM_THRESHOLD - newPotXCandidate, ( presumablyFixedResistor - 1000 ) / 1000 ); else
diagROM_PaddleOffset = 0;
newPotXCandidate = min( 255, (int)newPotXCandidate + (int)diagROM_PaddleOffset );
newPotYCandidate = min( 255, (int)newPotYCandidate + (int)diagROM_PaddleOffset );
} else
if ( DIAGROM_THRESHOLD > 1 )
{
newPotXCandidate = min( 255, (int)newPotXCandidate + (int)DIAGROM_THRESHOLD );
newPotYCandidate = min( 255, (int)newPotYCandidate + (int)DIAGROM_THRESHOLD );
}
#endif

if ( !paddleFilterMode )
{
outRegisters[ 25 ] = newPotXCandidate;
Expand Down Expand Up @@ -1446,6 +1478,7 @@ void handleBus()
\__, \__/ | \| | | \__> |__) \__/ .__/ | | /~~\ | \| |__/ |___ | | \| \__>
*/
uint8_t busTimingTestValue = 0;
uint8_t transferPRGSlot = 0;
while ( true )
{
//
Expand Down Expand Up @@ -1574,6 +1607,97 @@ void handleBus()
prgLaunch = 1;
stateInConfigMode = 0;
} else
if ( A == 0x14 || A == 0x15 ) // start bus timing banging: value #1 and #2
{
transferPRGSlot = 254 - 0x14 + A;
transferPayload = prgCode;
stateInConfigMode = CONFIG_MODE_CYCLES;
} else
if ( A == 0x1a ) // start PRG upload
{
transferPRGSlot = D;
transferPayload = prgCode;
stateInConfigMode = CONFIG_MODE_CYCLES;
} else
if ( A == 0x19 ) // set PRG upload page
{
transferPayload = prgCode + D * 256;
stateInConfigMode = CONFIG_MODE_CYCLES;
} else
if ( A == 0x16 ) // upload one PRG byte
{
*transferPayload = D;
transferPayload ++;
stateInConfigMode = CONFIG_MODE_CYCLES;
} else
if ( A == 0x17 ) // end PRG upload, or end of bus timing banging!
{
SET_CLOCK_125MHZ
DELAY_Nx3p2_CYCLES( 85000 );

if ( transferPRGSlot >= 254 )
{
int *histo = (int*)&prgCode[ 16384 ];
memset( histo, 0, 256 * sizeof( int ) );
int sz = transferPayload - prgCode;
for ( int i = 0; i < sz; i++ )
histo[ prgCode[ i ] ] ++;
int maxV = histo[ 0 ], maxIdx = 0;
for ( int i = 1; i < sz; i++ )
if ( histo[ i ] > maxV )
{
maxV = histo[ i ];
maxIdx = i;
}

if ( transferPRGSlot == 254 )
{
DELAY_READ_BUS = maxIdx;
}else
{
DELAY_PHI2 = maxIdx;

unsigned char *tmp = &prgCode[ 16384 + 1024 ];
{
#define FLASH_BUSTIMING_OFFSET ((uint32_t)&busTimings[ 0 ] - XIP_BASE)
memcpy( tmp, (void*)FLASH_BUSTIMING_OFFSET, FLASH_SECTOR_SIZE );
DELAY_READ_BUS_local = tmp[ 0 ] = DELAY_READ_BUS;
DELAY_PHI2_local = tmp[ 1 ] = DELAY_PHI2;

flash_range_erase ( FLASH_BUSTIMING_OFFSET, FLASH_SECTOR_SIZE );
flash_range_program( FLASH_BUSTIMING_OFFSET, tmp, FLASH_SECTOR_SIZE );
}
}
} else
{
int sz = transferPayload - prgCode - 18; // -18 because menu entry is 18 byte (string null-terminated)

uint8_t *dirEntry = &prgDirectory[ transferPRGSlot * 24 ];

memcpy( dirEntry, prgCode + sz, 18 );
dirEntry[ 18 ] = 0;
dirEntry[ 19 ] = 0;
dirEntry[ 20 ] = transferPRGSlot;
dirEntry[ 21 ] = 0;
dirEntry[ 22 ] = sz & 255;
dirEntry[ 23 ] = sz >> 8;

#define FLASH_DIR_OFFSET ((uint32_t)&prgDirectory_Flash[ 0 ] - XIP_BASE)
flash_range_erase ( FLASH_DIR_OFFSET, FLASH_SECTOR_SIZE );
flash_range_program( FLASH_DIR_OFFSET, prgDirectory, FLASH_SECTOR_SIZE );

prgCode[ 0 ] = 1;
prgCode[ 1 ] = 8;

#define FLASH_PRG_OFFSET ((uint32_t)&prgRepository[ transferPRGSlot * 65536 ] - XIP_BASE)
flash_range_erase ( FLASH_PRG_OFFSET, 65536 );
flash_range_program( FLASH_PRG_OFFSET, prgCode, 65536 );
}
SET_CLOCK_FAST
prgLaunch = 0;
currentPRG = 254;
stateInConfigMode = 0;
} else
if ( A == 0x10 )
{
SET_CLOCK_125MHZ
Expand Down Expand Up @@ -1646,7 +1770,6 @@ void writeConfiguration()
config[ 63 ] = c >> 8;

flash_range_program( FLASH_CONFIG_OFFSET, config, FLASH_PAGE_SIZE );
SET_CLOCK_FAST

SET_CLOCK_125MHZ
DELAY_Nx3p2_CYCLES( 85000 );
Expand Down
5 changes: 3 additions & 2 deletions Source/prgslots.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
*/

#include "pico/stdlib.h"
#include "hardware/flash.h"

uint8_t prgDirectory[ 16 * 24 + 1 ];

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

const volatile uint8_t __in_flash( "PRGData" ) prgRepository[ 1024 * 1024 ] =
const volatile uint8_t __in_flash( "PRGData" ) prgRepository[ 1024 * 1024 ] __attribute__((aligned(FLASH_SECTOR_SIZE))) =
{ 'S', 'I', 'D', 'K', 'I', 'C', 'K', ' ', 'R', 'E', 'P', 'O', 0, 0, 0, 0, 0, 0, 0, 0 };
19 changes: 12 additions & 7 deletions Source/reSIDWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,16 @@ extern "C"
{
int32_t sid1 = sid16->output();

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

*left = L >> 16;
*right = R >> 16;
L >>= 16; R >>= 16;
if ( L > 32767 ) L = 32767;
if ( R > 32767 ) R = 32767;
if ( L < -32767 ) L = -32767;
if ( R < -32767 ) R = -32767;
*left = L;
*right = R;

#ifdef USE_RGB_LED
// SID #1 voices map to red, green, blue
Expand Down Expand Up @@ -344,9 +349,9 @@ extern "C"
for ( int i = 0; i < 9; i++ )
{
extern int32_t outputCh[ 9 ];
voiceOutAcc[ 0 ] += ( colorMap[ i ][ 0 ] * outputCh[ i ] ) >> 2;
voiceOutAcc[ 1 ] += ( colorMap[ i ][ 1 ] * outputCh[ i ] ) >> 2;
voiceOutAcc[ 2 ] += ( colorMap[ i ][ 2 ] * outputCh[ i ] ) >> 2;
voiceOutAcc[ 0 ] += ( colorMap[ i ][ 0 ] * outputCh[ i ] ) >> 1;
voiceOutAcc[ 1 ] += ( colorMap[ i ][ 1 ] * outputCh[ i ] ) >> 1;
voiceOutAcc[ 2 ] += ( colorMap[ i ][ 2 ] * outputCh[ i ] ) >> 1;
}
nSamplesAcc ++;
#endif
Expand Down

0 comments on commit 965c935

Please sign in to comment.