diff --git a/c64/kernal/cint.s b/c64/kernal/cint.s index 3d2ae602..1fa22258 100644 --- a/c64/kernal/cint.s +++ b/c64/kernal/cint.s @@ -14,7 +14,10 @@ cint: cint_brk: ; entry for BRK and STOP+RESTORE - XXX, where should it start? jsr setup_vicii - jsr setup_pal_ntsc + + ;; According to [CM64], this routine also checks for PAL/NTSC - this must be a mistake, + ;; it's too late (IOINIT already needs this information), besides - POKE something + ;; to address 678 on a real C64, press STOP+RESTORE - the value won't change ;; Initialise cursor blink flags (Compute's Mapping the 64 p215) lda #$00 diff --git a/c64/kernal/fda3.ioinit.s b/c64/kernal/fda3.ioinit.s index fb4a159c..3f1a3ba9 100644 --- a/c64/kernal/fda3.ioinit.s +++ b/c64/kernal/fda3.ioinit.s @@ -34,6 +34,33 @@ ioinit: cpy #$80 ; $20 * amount of chips to silence, $80 to silence 4 chips bne - + ;; Detect video system (PAL/NTSC), use Graham's method, as it's short and reliable + ;; see here: https://codebase64.org/doku.php?id=base:detect_pal_ntsc + +ioinit_w0: + lda VIC_RASTER +ioinit_w1: + cmp VIC_RASTER + beq ioinit_w1 + bmi ioinit_w0 + + ;; Result in A, if no interrupt happened during the test: + ;; #$37 -> 312 rasterlines, PAL, VIC 6569 + ;; #$06 -> 263 rasterlines, NTSC, VIC 6567R8 + ;; #$05 -> 262 rasterlines, NTSC, VIC 6567R56A + + cmp #$07 + bcs ioinit_pal + +ioinit_ntsc: + lda #$00 + beq + + +ioinit_pal: + lda #$01 +* + sta PALNTSC + ;; XXX: calibrate TOD for both CIA's, see here: https://codebase64.org/doku.php?id=base:efficient_tod_initialisation ;; Enable CIA1 IRQ and ~50Hz timer (https://csdb.dk/forums/?roomid=11&topicid=69037) @@ -41,7 +68,6 @@ ioinit: sta CIA1_ICR ; disable all ;; Set timer interval to ~1/60th of a second - jsr setup_pal_ntsc ;; (This value was calculated by running a custom IRQ handler on a C64 ;; with original KERNAL, and writing the values of $DC04/5 to the screen diff --git a/c64/kernal/reset_entry.s b/c64/kernal/reset_entry.s index fbddb4d3..8a6ccabc 100644 --- a/c64/kernal/reset_entry.s +++ b/c64/kernal/reset_entry.s @@ -11,26 +11,36 @@ reset_entry: txs sei + ; The following routine is based on reading the public KERNAL jumptable routine + ; list, and making unimaginative assumptions about what should be done on reset. + + ; According to example here: https://codebase64.org/doku.php?id=base:assembling_your_own_cart_rom_image + ; the cartridge does not call RAMTAS - despite it's obviously required. So, call RAMTAS + ; before the cartridge check/takeover + + ; Setting up the screen and testing ram is obviously required + ; also affirmed by p269 of c64 prg + jsr RAMTAS + ; C64 PRG p269 jsr cartridge_check bcc + jmp (ICART_COLD_START) * - ; The following routine is based on reading the public KERNAL jumptable routine - ; list, and making unimaginative assumptions about what should be done on reset. - ; Initialising IO is obviously required. also indicated by c64 prg p269. - jsr ioinit - ; Setting up the screen and testing ram is obviously required - ; also affirmed by p269 of c64 prg - jsr ramtas + ; Initialising IO is obviously required. Also indicated by c64 prg p269. + ; Has to be after ther RAMTAS, as it clears memory, including the PAL/NTSC flag, + ; which is set by IOINIT + jsr IOINIT + ; Resetting IO vectors is obviously required, if we want interrupts to run ; also affirmed by c64 prg p269 - jsr restor + jsr RESTOR + ;; "Compute's Mapping the 64" p236 - jsr cint + jsr CINT ; What do we do when finished? A C64 jumps into the BASIC ROM cli ; Allow interrupts to happen ; c64 prg p269 - jmp ($a000) + jmp (IBASIC_COLD_START) diff --git a/c64/kernal/setup_pal_ntsc.s b/c64/kernal/setup_pal_ntsc.s deleted file mode 100644 index f0cdd3a0..00000000 --- a/c64/kernal/setup_pal_ntsc.s +++ /dev/null @@ -1,31 +0,0 @@ - -;; -;; Detect video system (PAL/NTSC), use Graham's method, as it's short and reliable -;; see here: https://codebase64.org/doku.php?id=base:detect_pal_ntsc -;; - -setup_pal_ntsc: - - lda VIC_RASTER -setup_pal_ntsc_w1: - cmp VIC_RASTER - beq setup_pal_ntsc_w1 - bmi setup_pal_ntsc - - ;; Result in A, if no interrupt happened during the test: - ;; #$37 -> 312 rasterlines, PAL, VIC 6569 - ;; #$06 -> 263 rasterlines, NTSC, VIC 6567R8 - ;; #$05 -> 262 rasterlines, NTSC, VIC 6567R56A - - cmp #$07 - bcs setup_pal - -setup_ntsc: - lda #$00 - beq + - -setup_pal: - lda #$01 -* - sta PALNTSC - rts