Skip to content

Commit 512e4dc

Browse files
committed
Jason's interrupt handling improvements
1 parent 0472fc9 commit 512e4dc

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

src/main.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@
110110
//#define PICO_CLOCK_PLL 1512000000 // 302.4MHz - standard voltage
111111
//#define PICO_CLOCK_PLL_DIV1 5
112112

113-
//#define PICO_CLOCK_PLL 1308000000 // 327MHz - 1.15v
114-
//#define PICO_CLOCK_PLL_DIV1 4
113+
#define PICO_CLOCK_PLL 1308000000 // 327MHz - 1.15v
114+
#define PICO_CLOCK_PLL_DIV1 4
115115

116116
//#define PICO_CLOCK_PLL 984000000 // 328MHz - 1.15v
117117
//#define PICO_CLOCK_PLL_DIV1 3
118118

119119
//#define PICO_CLOCK_PLL 1056000000 // 352MHz - 1.3v
120120
//#define PICO_CLOCK_PLL_DIV1 3
121121

122-
#define PICO_CLOCK_PLL 1128000000 // 376MHz - 1.3v
123-
#define PICO_CLOCK_PLL_DIV1 3
122+
//#define PICO_CLOCK_PLL 1128000000 // 376MHz - 1.3v
123+
//#define PICO_CLOCK_PLL_DIV1 3
124124

125125
//#define PICO_CLOCK_PLL 1512000000 // 378MHz - 1.3v
126126
//#define PICO_CLOCK_PLL_DIV1 4
@@ -160,9 +160,9 @@ static uint8_t nextValue = 0; /* TMS9918A read-ahead value */
160160
static bool currentInt = false; /* current interrupt state */
161161
static uint8_t currentStatus = 0x1f; /* current status register value */
162162

163-
static __attribute__((section(".scratch_y.buffer"))) uint32_t __aligned(4) bg;
163+
static __attribute__((section(".scratch_y.buffer"))) uint32_t bg;
164164

165-
static __attribute__((section(".scratch_x.buffer"))) uint8_t __aligned(4) tmsScanlineBuffer[TMS9918_PIXELS_X + 8];
165+
static __attribute__((section(".scratch_x.buffer"))) uint8_t __aligned(8) tmsScanlineBuffer[TMS9918_PIXELS_X + 8];
166166

167167
const uint tmsWriteSm = 0;
168168
const uint tmsReadSm = 1;
@@ -210,7 +210,6 @@ void __not_in_flash_func(pio_irq_handler)()
210210
else if ((TMS_PIO->fstat & (1u << (PIO_FSTAT_RXEMPTY_LSB + tmsReadSm))) == 0) // read?
211211
{
212212
uint32_t readVal = TMS_PIO->rxf[tmsReadSm];
213-
uint32_t readDat = TMS_PIO->rxf[tmsReadSm]; // What was read?
214213

215214
if ((readVal & 0x04) == 0) // read data
216215
{
@@ -219,18 +218,25 @@ void __not_in_flash_func(pio_irq_handler)()
219218
}
220219
else // read status
221220
{
221+
readVal >>= (3 + 16); // What status was read?
222222
tms9918->regWriteStage = 0;
223223
switch (tms9918->registers [0x0F] & 0x0F)
224224
{
225225
case 0:
226-
currentStatus &= ~(readDat >> 16); // Switch off any 3 high bits which have just been read
227-
currentStatus |= 0x1f;
226+
readVal &= (STATUS_INT | STATUS_5S | STATUS_COL);
227+
currentStatus &= ~readVal; // Switch off any 3 high bits which have just been read
228+
if (readVal & STATUS_5S) // Was 5th Sprite read?
229+
currentStatus |= 0x1f;
228230
vrEmuTms9918SetStatusImpl(currentStatus);
229-
currentInt = false;
230-
gpio_put(GPIO_INT, !currentInt);
231+
if (readVal & STATUS_INT) // Was Interrupt read?
232+
{
233+
currentInt = false;
234+
gpio_put(GPIO_INT, !currentInt);
235+
}
231236
break;
232237
case 1:
233-
tms9918->status [0x01] &= ~0x01;
238+
if ((readVal << 31) >> 31) // & 0x01
239+
tms9918->status [0x01] &= ~0x01;
234240
break;
235241
}
236242
}
@@ -266,11 +272,13 @@ void __not_in_flash_func(gpioIrqHandler)()
266272
disableTmsPioInterrupts();
267273
vrEmuTms9918Reset();
268274

275+
*((io_rw_32*)(PPB_BASE + M0PLUS_NVIC_ICPR_OFFSET)) = 1u << TMS_IRQ;
269276
pio_sm_clear_fifos(TMS_PIO, tmsReadSm);
270277
pio_sm_clear_fifos(TMS_PIO, tmsWriteSm);
271278

272279
nextValue = 0;
273280
currentStatus = 0x1f;
281+
vrEmuTms9918SetStatusImpl(currentStatus);
274282
currentInt = false;
275283
doneInt = true;
276284
updateTmsReadAhead();

src/tms9918.pio

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
.define public CSR_PIN 26
3131

3232
pull block
33-
mov x, osr ; ensure we have a valid fifio value in x
33+
mov x, osr ; ensure we have a valid fifo value in x
3434

3535
.wrap_target
3636
wait 1 gpio CSR_PIN ; wait for CSR to go high (inactive)
@@ -53,11 +53,10 @@ readData:
5353
readStatus:
5454
out null, 8 ; skip data bits
5555
out pins, 8 ; output the status byte
56+
mov isr, x ; make this status value available
5657
endPart:
5758
in pins, 3 ; push CSR, CSW and MODE back through fifo
5859
push ; push ^^^ back to cpu to process
59-
mov isr, x
60-
push
6160
.wrap
6261

6362
; -----------------------------------------------------------------------------

submodules/vrEmuTms9918

0 commit comments

Comments
 (0)