more Kernal reorganization
This commit is contained in:
1 parent
076a839f1a
commit
8829ec8090
20 files changed
+2
No files matched your search
@@ -0,0 +1,13 @@
|
||||
// c64 prg p263
|
||||
|
||||
cartridge_check:
|
||||
ldx #$05
|
||||
cartridge_check_l1:
|
||||
lda CART_SIG-1,x
|
||||
cmp cartridge_signature-1,x
|
||||
bne no_cartridge
|
||||
dex
|
||||
bne cartridge_check_l1
|
||||
// FALLTROUGH
|
||||
no_cartridge:
|
||||
rts
|
||||
@@ -0,0 +1,122 @@
|
||||
|
||||
//
|
||||
// Official Kernal routine, described in:
|
||||
//
|
||||
// - [RG64] C64 Programmer's Reference Guide - page 280
|
||||
// - [CM64] Compute's Mapping the Commodore 64 - page 242
|
||||
//
|
||||
// CPU registers that has to be preserved (see [RG64]): none
|
||||
//
|
||||
|
||||
|
||||
cint_real:
|
||||
|
||||
// According to [CM64], this routine checks for PAL/NTSC. It's definitely not done
|
||||
// within the 'BRK' part, this can be easily checked - POKE something
|
||||
// to address 678 on a real C64, press STOP+RESTORE, the value won't change
|
||||
|
||||
// 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
|
||||
|
||||
lda #$C8 // preparation, as the VIC might be uninitialized
|
||||
sta VIC_SCROLX
|
||||
|
||||
cint_w0:
|
||||
lda VIC_RASTER
|
||||
cint_w1:
|
||||
cmp VIC_RASTER
|
||||
beq cint_w1
|
||||
bmi cint_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 cint_pal
|
||||
|
||||
cint_ntsc:
|
||||
|
||||
// NTSC C64 (https://codebase64.org/doku.php?id=base:cpu_clocking),
|
||||
// is clocked at 1.022727 MHz, so that 1/60s is 17045 CPU cycles
|
||||
|
||||
ldy #<17045
|
||||
ldx #>17045
|
||||
|
||||
sty CIA1_TIMALO
|
||||
stx CIA1_TIMAHI
|
||||
|
||||
lda #$00
|
||||
beq !+
|
||||
|
||||
cint_pal:
|
||||
|
||||
lda #$01
|
||||
!:
|
||||
sta TVSFLG
|
||||
|
||||
// Setup KEYLOG vector - XXX is it proper place?
|
||||
|
||||
lda #<scnkey_set_keytab
|
||||
sta KEYLOG+0
|
||||
lda #>scnkey_set_keytab
|
||||
sta KEYLOG+1
|
||||
|
||||
cint_brk: // entry for BRK and STOP+RESTORE - XXX, where should it start?
|
||||
|
||||
jsr setup_vicii
|
||||
|
||||
// Initialise cursor blink flags (Compute's Mapping the 64 p215)
|
||||
|
||||
lda #$01
|
||||
sta BLNCT
|
||||
sta BLNSW
|
||||
|
||||
// Enable cursor repeat - XXX make it configurable
|
||||
|
||||
#if CONFIG_KEY_REPEAT_DEFAULT && !CONFIG_KEY_REPEAT_ALWAYS
|
||||
|
||||
lda #$80
|
||||
sta RPTFLG
|
||||
|
||||
#endif
|
||||
|
||||
// Set keyboard decode vector (Compute's Mapping the 64 p215)
|
||||
|
||||
#if CONFIG_LEGACY_SCNKEY
|
||||
|
||||
// Set initial variables for our improved keyboard scan routine
|
||||
lda #$FF
|
||||
ldx #6
|
||||
!: sta BufferOld,x
|
||||
dex
|
||||
bpl !-
|
||||
sta BufferQuantity
|
||||
|
||||
#endif
|
||||
|
||||
// Set key repeat delay (Compute's Mapping the 64 p215)
|
||||
// Making some numbers up here: Repeat every ~1/10th sec
|
||||
// But require key to be held for ~1/3sec before
|
||||
// repeating (Compute's Mapping the 64 p58)
|
||||
ldx #22-2 // Fudge factor to match speed
|
||||
stx DELAY
|
||||
|
||||
// Set current colour for text (Compute's Mapping the 64 p215)
|
||||
ldx #$01 // default is light blue ($0E), but we use a different one
|
||||
stx COLOR
|
||||
|
||||
// Set maximum keyboard buffer size (Compute's Mapping the 64 p215)
|
||||
ldx #10
|
||||
stx XMAX
|
||||
|
||||
// Put non-zero value in MODE to enable case switch
|
||||
ldx #$00
|
||||
stx MODE
|
||||
|
||||
// Set default I/O devices (see SCINIT description at http://sta.c64.org/cbm64krnfunc.html)
|
||||
jsr clrchn_reset
|
||||
|
||||
// Fallthrough/jump to screen clear routine (Compute's Mapping the 64 p215)
|
||||
jmp clear_screen
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
setup_vicii:
|
||||
|
||||
// XXX there is more to setup within this routine
|
||||
|
||||
// Set up default IO values (Compute's Mapping the 64 p215)
|
||||
lda #$1B // Enable text mode
|
||||
sta VIC_SCROLY
|
||||
lda #$C8 // 40 column etc
|
||||
sta VIC_SCROLX
|
||||
|
||||
// Compute's Mapping the 64, p156
|
||||
// We use a different colour scheme of white text on all blue
|
||||
lda #$06
|
||||
sta VIC_EXTCOL
|
||||
sta VIC_BGCOL0
|
||||
|
||||
// Turn off sprites (observed hanging around after running programs and resetting)
|
||||
lda #$00
|
||||
sta VIC_SPENA
|
||||
|
||||
rts
|
||||
@@ -0,0 +1,3 @@
|
||||
RRAMTAS is an important startup routine, frequentl called b cartridges - unfortunately, we can't count on them calling it
|
||||
via the jumptable, as even some tutorials on the web advise to call it directly - see for example here:
|
||||
https://codebase64.org/doku.php?id=base:assembling_your_own_cart_rom_image
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
// Our implementation is longer than the original one,
|
||||
// placing it here would cause a collision with OPEN
|
||||
|
||||
RAMTAS:
|
||||
jmp ramtas_real
|
||||
@@ -0,0 +1,121 @@
|
||||
|
||||
//
|
||||
// Official Kernal routine, described in:
|
||||
//
|
||||
// - [RG64] C64 Programmer's Reference Guide - page 285
|
||||
// - [CM64] Compute's Mapping the Commodore 64 - page 238
|
||||
//
|
||||
// CPU registers that has to be preserved (see [RG64]): none
|
||||
//
|
||||
|
||||
IOINIT:
|
||||
|
||||
// Set $00/$01 port mode and value
|
||||
// We want BASIC and KERNAL ROMs mapped, and datasette motor off
|
||||
// (https://www.c64-wiki.com/wiki/Zeropage)
|
||||
// XXX - Work around VICE bug: Writing $00 before $01 results in rubbish in $01
|
||||
// after. https://sourceforge.net/p/vice-emu/bugs/1057/
|
||||
lda #$27
|
||||
ldx #$2F
|
||||
sta CPU_R6510
|
||||
stx CPU_D6510
|
||||
|
||||
// Silence the SID chips, depending on the configuration
|
||||
|
||||
#if !CONFIG_SID_D4XX
|
||||
lda SID_SIGVOL
|
||||
and #$F0
|
||||
sta SID_SIGVOL
|
||||
#endif // !CONFIG_SID_D4XX
|
||||
|
||||
#if CONFIG_SID_D4XX || CONFIG_SID_D5XX
|
||||
ldy #$00
|
||||
!:
|
||||
|
||||
#if CONFIG_SID_D4XX
|
||||
lda SID_SIGVOL, Y
|
||||
and #$F0
|
||||
sta SID_SIGVOL, Y
|
||||
#endif // CONFIG_SID_D4XX
|
||||
|
||||
#if CONFIG_SID_D5XX
|
||||
// SIDs under $D5xx
|
||||
lda SID_SIGVOL + $100, Y
|
||||
and #$F0
|
||||
sta SID_SIGVOL + $100, Y
|
||||
#endif // CONFIG_SID_D4XX
|
||||
|
||||
tya
|
||||
clc
|
||||
adc #$20
|
||||
tay
|
||||
bne !-
|
||||
#endif // CONFIG_SID_D4XX || CONFIG_SID_D5XX
|
||||
|
||||
#if CONFIG_SID_2ND
|
||||
lda SID_SIGVOL - __SID_BASE + CONFIG_SID_2ND_ADDRESS
|
||||
and #$F0
|
||||
sta SID_SIGVOL - __SID_BASE + CONFIG_SID_2ND_ADDRESS
|
||||
#endif // CONFIG_SID_2ND
|
||||
|
||||
#if CONFIG_SID_3RD
|
||||
lda SID_SIGVOL - __SID_BASE + CONFIG_SID_3RD_ADDRESS
|
||||
and #$F0
|
||||
sta SID_SIGVOL - __SID_BASE + CONFIG_SID_3RD_ADDRESS
|
||||
#endif // CONFIG_SID_3RD
|
||||
|
||||
// Initialize CIAs
|
||||
|
||||
// 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)
|
||||
|
||||
// First disable IRQ generation for both CIA's
|
||||
lda #$7F
|
||||
sta CIA2_ICR
|
||||
sta CIA1_ICR
|
||||
|
||||
// Set timer interval to ~1/60th of a second
|
||||
|
||||
// (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
|
||||
// in the IRQ handler to see roughly what value the timers must be set to)
|
||||
// ldy #<16380
|
||||
// ldx #>16380
|
||||
|
||||
// PAL C64 (https://codebase64.org/doku.php?id=base:cpu_clocking),
|
||||
// is clocked at 0.985248 MHz, so that 1/60s is 16421 CPU cycles
|
||||
|
||||
ldy #<16421
|
||||
ldx #>16421
|
||||
|
||||
sty CIA1_TIMALO
|
||||
stx CIA1_TIMAHI
|
||||
|
||||
// Enable timer interrupt
|
||||
lda #$81
|
||||
sta CIA1_ICR
|
||||
|
||||
// Enable timer A to run continuously (http://codebase64.org/doku.php?id=base:timerinterrupts)
|
||||
lda #$11
|
||||
sta CIA1_CRA
|
||||
lda CIA1_ICR
|
||||
|
||||
// Setup the CIA1 for reading the keyboard - 'POKE 56322, 0' on original ROMs proves this
|
||||
// is done during initialization, not during the interrupt
|
||||
|
||||
ldx #$FF
|
||||
stx CIA1_DDRA // output
|
||||
inx // $00
|
||||
stx CIA1_DDRB // input
|
||||
|
||||
// Value checked on original ROM
|
||||
stx CIA2_DDRA
|
||||
|
||||
// Set DDR on CIA2 for IEC bus, VIC-II banking
|
||||
lda #$3F
|
||||
sta CIA2_DDRA
|
||||
|
||||
// Set IEC bus to its initial idle state
|
||||
jmp iec_set_idle
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
// Our implementation is longer than the original one,
|
||||
// placing it here would cause a collision with OPEN
|
||||
|
||||
CINT:
|
||||
jmp cint_real
|
||||
@@ -0,0 +1,4 @@
|
||||
Original Kernal location of the CINT routine.
|
||||
|
||||
Routine moved to original location due to game 'Duotris' calling it instead of using the Kernal jumptable.
|
||||
Starting the game without this patch caused warm reset with 'BRK AT $FF5B' message.
|
||||
Reference in new issue
Block a user