You should limit the IRQs to something like every 8th rasterline. That way you have enough time to finish the IRQ before the next one will start and avoid a lot of problems. And yes, the C64 is very slow :)
SpriteIRQ inc $d019 sta _areg+1.w stx _xreg+1.w sty _yreg+1.w ldx SpriteRasterIndex _loop ldy SpriteHWAssign.w,X lda SpriteSortedFlags.w,X sta $d027,Y ;Color lda SpriteSortedTileNmr.w,X sta $7f8,Y ;Tile number tya asl A tay lda SpritePosXL.w,X sta $d000,Y lda SpriteSortedPosY.w,X sta $d001,Y lda D010Buffer.w,X sta $d010 lda D017Buffer.w,X sta $d017 lda D01dBuffer.w,X sta $d01d lda D01bBuffer.w,X ;Copy all flags sta $d01b lda D01cBuffer.w,X sta $d01c lda D015Buffer.w,X sta $d015 - inx lda InterruptLine,X beq - ;If raster line is 0, we should ignore it sta $d012 cmp #$ff beq _lastInt ;If value is $ff, then it's the last interrupt of the frame sbc #$02 ;If a new interrupt should occur in less than 3 scanlines cmp $d012 ;Do it straight away bcc _loop stx SpriteRasterIndex ;Copy valid index and rasterline bcs + _lastInt lda #<IRQ sta $fffe ; lda #>IRQ ; sta $ffff + _areg lda #$00 _xreg ldx #$00 _yreg ldy #$00 rti
if (>IRQ != >SpriteIRQ) lda #>IRQ sta $ffff endif
sbc #3-1
Also how many scanlines am I supposed to set my IRQ before the sprite ? I guess 3 is the bare minimum, but in the worst case where I have to rewrinte all 8 sprites on the same line, it would need about 16-24 scanlines before so that I have time to rewrite all 8 ! This sounds like an enormous amount. Having a big margin like that may remove some bugs when many sprites are on the same line, but add other bugs as sprites are much more likely to overlap and to be rejected as there is more than 8 on a line.