OT: C64, reset and irq implementation question

Bernd
Posts: 3
Joined: Thu Nov 30, 2023 12:39 pm

OT: C64, reset and irq implementation question

Unread post by Bernd »

Hello,

maybe this is a bit off topic for MiSTer, but maybe some experts on the C64 FPGA implementation may help me by finding an answer which is/was also of interest by the FPGA implementation of the great C64 core.
I am currently working on an implementation of the C64 using the neo6502 hardware and I noticed that on RESET, the C64 the Kernal routine at $FCE2 is called. First thing it does is it disables all interrupts (SEI), so no interrupts will be handled. Later in the reset routine, a decision is made about PAL or NTSC and based on this the CIAs are programmed according to the required timing. For this decision a flag is used at $02A6. After this flag has been read out and the CIAs have been programmed, finally the VICII is initialized for the first time setting register $D01A to 0 (value is a lookup table in rom). After that the VIC seems to be programmed to create an IRQ at the 311s line using $d012 and $d011. However, no IRQ should ever occur here because no CLI has been executed after the SEI and in $D01A raster interrupts are still disabled ($D01A is still 0) and I did not find any code in the Kernal where it is enabled again. Furthermore, due to the fact that the VICII is initialized after reading out $02A6, the PAL / NTSC detection should not work at all. Does anybody know why this works or is it simply a don't care bug? Thank you in advance.

rcade
Posts: 101
Joined: Wed May 27, 2020 7:57 pm
Been thanked: 14 times

Re: OT: C64, reset and irq implementation question

Unread post by rcade »

It definitely does a CLI right before jumping to BASIC.

See $FCFE.

https://www.pagetable.com/c64ref/c64disasm/

Bernd
Posts: 3
Joined: Thu Nov 30, 2023 12:39 pm

Re: OT: C64, reset and irq implementation question

Unread post by Bernd »

Thank you for your answer.
Yes, CLI is done right before the jmp($a000) to basic, but as I tried to explain, this is too late because the flag has already been read out at this point and used within the reset routine before. Furthermore, VICII would not signal the IRQ even in case the CLI would have occured earlier because having the VIC signal an IRQ is still not enabled in the $D01A register. But maybe I oversee sth.

Bernd
Posts: 3
Joined: Thu Nov 30, 2023 12:39 pm

Re: OT: C64, reset and irq implementation question

Unread post by Bernd »

Finally got it. No VIC IRQ occurs and it is in fact not necessary for PAL/NTSC detection: When the VIC is asked to signal e.g. rasterline 311, it sets $D019 indicating the rasterline 'irq' to have occured as soon as the line is processed by the VIC. This happens even in case VIC IRQ signalling is switched off. So my misunderstanding was thinking that $D019 would only be set by the VIC in case it's interrupt mask allows signalling the IRQ, But these are two different things. $D019 simply states that the rasterline written to $D011/12 was reached. Having the VIC pull IRQB low as well in this case is optional and handled in fact by $D01A as described.

Post Reply