From 907452d918dff8421c874a343aac2cd67b94897b Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sat, 30 Nov 2024 13:01:09 +0100 Subject: [PATCH] Fix rirq_sort when called from within interrupt --- include/c64/rasterirq.c | 15 ++++++++++----- include/c64/rasterirq.h | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/c64/rasterirq.c b/include/c64/rasterirq.c index 9807961..2c7a1d5 100644 --- a/include/c64/rasterirq.c +++ b/include/c64/rasterirq.c @@ -591,7 +591,7 @@ void rirq_wait(void) npos++; } -void rirq_sort(void) +void rirq_sort(bool inirq) { #if 1 byte maxr = rasterIRQRows[rasterIRQIndex[1]]; @@ -641,10 +641,15 @@ void rirq_sort(void) #endif npos++; - nextIRQ = 0; - byte yp = rasterIRQNext[nextIRQ]; - if (yp != 0xff) - vic.raster = yp - 1; + if (inirq) + nextIRQ = NUM_IRQS - 1; + else + { + nextIRQ = 0; + byte yp = rasterIRQNext[nextIRQ]; + if (yp != 0xff) + vic.raster = yp - 1; + } } void rirq_start(void) diff --git a/include/c64/rasterirq.h b/include/c64/rasterirq.h index cc78bdc..07c4919 100644 --- a/include/c64/rasterirq.h +++ b/include/c64/rasterirq.h @@ -180,7 +180,8 @@ void rirq_stop(void); // Sort the raster IRQ, must be performed at the end of the frame after changing // the vertical position of one of the interrupt operatins. -void rirq_sort(void); +// Set the inirq flag to true when calling this from an interrupt +void rirq_sort(bool inirq = false); // Wait for the last raster IRQ op to have completed. Must be called before a // sort if the raster IRQ system is active