Skip to content

Commit 1a9410a

Browse files
authored
fixed bus value ttl
1 parent 4186c99 commit 1a9410a

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

Source/SKpico.c

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
SKpico.c
99
1010
SIDKick pico - SID-replacement with dual-SID emulation using a RPi pico and reSID 0.16 by Dag Lem
11-
Copyright (c) 2023 Carsten Dachsbacher <[email protected]>
11+
Copyright (c) 2023, 2024 Carsten Dachsbacher <[email protected]>
1212
1313
This program is free software: you can redistribute it and/or modify
1414
it under the terms of the GNU General Public License as published by
@@ -58,6 +58,10 @@
5858
#include "hardware/pio.h"
5959
#include "hardware/clocks.h"
6060

61+
#include "hardware/watchdog.h"
62+
#include "hardware/structs/watchdog.h"
63+
#include "hardware/structs/psm.h"
64+
6165
#ifdef USE_RGB_LED
6266
#undef FLASH_LED
6367
#include "ws2812.pio.h"
@@ -79,9 +83,9 @@ uint8_t sidDACMode = SID_DAC_OFF;
7983
#define VERSION_STR_SIZE 36
8084
static const unsigned char VERSION_STR[ VERSION_STR_SIZE ] = {
8185
#ifdef USE_DAC
82-
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '1', '2', '/', 0x44, 0x41, 0x43, '6', '4', 0, 0, 0, 0, // version string to show
86+
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '1', '3', '/', 0x44, 0x41, 0x43, '6', '4', 0, 0, 0, 0, // version string to show
8387
#else
84-
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '1', '2', '/', 0x50, 0x57, 0x4d, '6', '4', 0, 0, 0, 0, // version string to show
88+
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, '0', '.', '1', '3', '/', 0x50, 0x57, 0x4d, '6', '4', 0, 0, 0, 0, // version string to show
8589
#endif
8690
0x53, 0x4b, 0x10, 0x09, 0x03, 0x0f, 0x00, 0x00, // signature + extension version 0
8791
0, 12, // firmware version with stepping = 0.12
@@ -127,6 +131,7 @@ extern void readRegs( uint8_t *p1, uint8_t *p2 );
127131
#define READ_ACCESS( g ) ( ( (g) & bRW ) )
128132
#define SID_ACCESS( g ) ( !( (g) & bSID ) )
129133
#define SID_ADDRESS( g ) ( ( (g) >> A0 ) & 0x1f )
134+
#define SID_RESET( g ) ( !( (g) & bRESET ) )
130135

131136
#define WAIT_FOR_VIC_HALF_CYCLE { do { g = *gpioInAddr; } while ( !( VIC_HALF_CYCLE( g ) ) ); }
132137
#define WAIT_FOR_CPU_HALF_CYCLE { do { g = *gpioInAddr; } while ( !( CPU_HALF_CYCLE( g ) ) ); }
@@ -168,7 +173,7 @@ void initGPIOs()
168173
gpio_set_pulls( 12, false, false );
169174
gpio_set_pulls( 13, false, false );
170175
gpio_set_pulls( A8, true, false );
171-
176+
172177
gpio_set_dir_all_bits( bOE | bPWN_POT | ( 1 << LED_BUILTIN ) );
173178
}
174179

@@ -221,13 +226,14 @@ uint8_t *outRegisters_2 = &outRegisters[ 34 ];
221226
#define REG_AUTO_DETECT_STEP 32
222227
#define REG_MODEL_DETECT_VALUE 33
223228

224-
uint8_t busValue = 0;
229+
uint8_t busValue = 0;
230+
int32_t busValueTTL = 0;
225231

226-
uint16_t SID_CMD = 0xffff;
232+
uint16_t SID_CMD = 0xfffe;
227233

228234
#define RING_SIZE 256
229235
uint16_t ringBuf[ RING_SIZE ];
230-
uint32_t ringTime[ RING_SIZE ];
236+
uint64_t ringTime[ RING_SIZE ];
231237
uint8_t ringWrite = 0;
232238
uint8_t ringRead = 0;
233239

@@ -273,6 +279,7 @@ extern uint8_t POT_FILTER_global;
273279
uint8_t paddleFilterMode = 0;
274280
uint8_t SID2_IOx;
275281
uint8_t potXExtrema[ 2 ], potYExtrema[ 2 ];
282+
volatile uint8_t doReset = 0;
276283

277284
void updateEmulationParameters()
278285
{
@@ -296,7 +303,7 @@ void updateEmulationParameters()
296303

297304
static inline void put_pixel(uint32_t pixel_grb)
298305
{
299-
pio_sm_put_blocking(pio0, 0, pixel_grb << 8u);
306+
pio_sm_put_blocking( pio0, 0, pixel_grb << 8u );
300307
}
301308

302309
#define RGB24( r, g, b ) ( ( (uint32_t)(r)<<8 ) | ( (uint32_t)(g)<<16 ) | (uint32_t)(b) )
@@ -417,7 +424,7 @@ void runEmulation()
417424
if ( ringRead == 33 )
418425
writeReSID( 0x18, 15 );
419426
}
420-
427+
421428
#ifdef USE_RGB_LED
422429
if ( reg == 0x18 )
423430
{
@@ -856,6 +863,12 @@ void handleBus()
856863
newSample = 0xfffe;
857864
}
858865

866+
if ( busValueTTL <= 0 )
867+
{
868+
busValue = 0;
869+
} else
870+
busValueTTL --;
871+
859872
// perform some parts of paddle/mouse-smoothing during VIC-cycle
860873
if ( paddleFilterMode >= 1 && !( newPotCounter & 4 ) )
861874
{
@@ -1030,7 +1043,6 @@ void handleBus()
10301043
ringTime[ ringWrite ] = c64CycleCounter;
10311044
ringBuf[ ringWrite ++ ] = SID_CMD;
10321045

1033-
10341046
if ( REG_AUTO_DETECT_STEP[ reg ] == 0 &&
10351047
0x12[ reg ] == 0xff &&
10361048
0x0e[ reg ] == 0xff &&
@@ -1041,10 +1053,16 @@ void handleBus()
10411053
}
10421054
reg[ A ] = D;
10431055
}
1044-
disableDataLines = 1;
1056+
//disableDataLines = 1;
1057+
busValue = D;
1058+
if ( outRegisters[ REG_MODEL_DETECT_VALUE ] == SID_MODEL_DETECT_VALUE_8580 )
1059+
busValueTTL = 0xa2000; else
1060+
busValueTTL = 0x1d00;
10451061
}
10461062
}
10471063

1064+
1065+
10481066
/* __ __ ___ ___ ___ __ ___ ___ ___ __
10491067
|__) / \ | |__ |\ | | | / \ |\/| |__ | |__ |__)
10501068
| \__/ | |___ | \| | | \__/ | | |___ | |___ | \
@@ -1380,7 +1398,6 @@ void readConfiguration()
13801398
void writeConfiguration()
13811399
{
13821400
SET_CLOCK_125MHZ
1383-
//sleep_ms( 2 );
13841401
DELAY_Nx3p2_CYCLES( 85000 );
13851402
flash_range_erase( FLASH_CONFIG_OFFSET, FLASH_SECTOR_SIZE );
13861403

0 commit comments

Comments
 (0)