From 890558213abc9ccc8f71e03c695f547b6eeea054 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Sat, 12 Oct 2019 19:13:56 +0200 Subject: [PATCH] initial concept of ROM versioning, still needs quite some work --- c64/,,config_generic.s | 2 + c64/,,config_mega65.s | 2 + c64/,,config_ultimate64.s | 2 + c64/aliases/,aliases_cpu.s | 11 ++++ c64/basic/,imports.s | 3 + c64/basic/basic_cold_start.s | 14 +++++ c64/basic/bf52.interop | 2 + c64/basic/bf52.rom_revision_basic.s | 25 ++++++++ c64/basic/e422.initmsg.jmp.s | 11 ++++ c64/basic/{e422.initmsg.s => initmsg_real.s} | 20 ++++--- c64/kernal/assets/kernal_messages.s | 15 ++++- c64/kernal/{ => iec}/acptr.s | 0 c64/kernal/{ => iec}/listen.s | 0 c64/kernal/{ => iec}/second.s | 0 c64/kernal/{ => iec}/talk.s | 0 c64/kernal/{ => iec}/tksa.s | 0 c64/kernal/{ => iec}/unlsn.s | 0 c64/kernal/{ => iec}/untlk.s | 0 c64/kernal/panic.s | 61 ++++++++++++++++++++ c64/kernal/xxxx.rom_revision_kernal.s | 34 +++++++++++ 20 files changed, 191 insertions(+), 11 deletions(-) create mode 100644 c64/basic/bf52.interop create mode 100644 c64/basic/bf52.rom_revision_basic.s create mode 100644 c64/basic/e422.initmsg.jmp.s rename c64/basic/{e422.initmsg.s => initmsg_real.s} (67%) rename c64/kernal/{ => iec}/acptr.s (100%) rename c64/kernal/{ => iec}/listen.s (100%) rename c64/kernal/{ => iec}/second.s (100%) rename c64/kernal/{ => iec}/talk.s (100%) rename c64/kernal/{ => iec}/tksa.s (100%) rename c64/kernal/{ => iec}/unlsn.s (100%) rename c64/kernal/{ => iec}/untlk.s (100%) create mode 100644 c64/kernal/panic.s create mode 100644 c64/kernal/xxxx.rom_revision_kernal.s diff --git a/c64/,,config_generic.s b/c64/,,config_generic.s index f6ffe41c..a351b1ff 100644 --- a/c64/,,config_generic.s +++ b/c64/,,config_generic.s @@ -1,4 +1,6 @@ +.const CONFIG_ID = $00 // should be 1 byte, different for each config file! + // // Please read CONFIG.md before modifying this file! // diff --git a/c64/,,config_mega65.s b/c64/,,config_mega65.s index c187323b..10e621a7 100644 --- a/c64/,,config_mega65.s +++ b/c64/,,config_mega65.s @@ -1,4 +1,6 @@ +.const CONFIG_ID = $01 // should be 1 byte, different for each config file! + // // Please read CONFIG.md before modifying this file! // diff --git a/c64/,,config_ultimate64.s b/c64/,,config_ultimate64.s index 4efd86e3..0f371bbd 100644 --- a/c64/,,config_ultimate64.s +++ b/c64/,,config_ultimate64.s @@ -1,4 +1,6 @@ +.const CONFIG_ID = $02 // should be 1 byte, different for each config file! + // // Please read CONFIG.md before modifying this file! // diff --git a/c64/aliases/,aliases_cpu.s b/c64/aliases/,aliases_cpu.s index 7a61c8aa..1f6137bf 100644 --- a/c64/aliases/,aliases_cpu.s +++ b/c64/aliases/,aliases_cpu.s @@ -3,6 +3,17 @@ // +// +// This one is not for optimization - but to encourage proper usage of panic screen +// + +.pseudocommand panic code +{ + lda code + jmp (panic_vector) +} + + // // Stack manipulation - some CPUs will leave .A unchanged, some will use it as temporary storage, so consider .A trashed // diff --git a/c64/basic/,imports.s b/c64/basic/,imports.s index 2f230d67..38527744 100644 --- a/c64/basic/,imports.s +++ b/c64/basic/,imports.s @@ -4,6 +4,9 @@ #import "KERNAL_combined.sym" +.label panic_vector = KERNAL.panic_vector +.label rom_revision_kernal = KERNAL.rom_revision_kernal + #if CONFIG_DBG_PRINTF .label printf = KERNAL.printf #endif diff --git a/c64/basic/basic_cold_start.s b/c64/basic/basic_cold_start.s index 5f8d27e3..b58bc453 100644 --- a/c64/basic/basic_cold_start.s +++ b/c64/basic/basic_cold_start.s @@ -3,6 +3,16 @@ basic_cold_start: + // Before doing anything, check if we have a compatible Kernal + + ldy #(__rom_revision_basic_end - rom_revision_basic - 1) +!: + lda rom_revision_basic, y + cmp rom_revision_kernal, y + bne basic_cold_start_rom_mismatch + dey + bpl !- + // Setup vectors at $300 ldy #$0B !: @@ -32,3 +42,7 @@ basic_cold_start: // jump into warm start loop jmp basic_warm_start + +basic_cold_start_rom_mismatch: + + panic #$01 diff --git a/c64/basic/bf52.interop b/c64/basic/bf52.interop new file mode 100644 index 00000000..b2a62a7b --- /dev/null +++ b/c64/basic/bf52.interop @@ -0,0 +1,2 @@ + +Special case - we need a constant memory location where we can put an ID and a revision string. According to Compute's Mapping the Commodore 64 (page 117) this area is unused - so a perfect place. diff --git a/c64/basic/bf52.rom_revision_basic.s b/c64/basic/bf52.rom_revision_basic.s new file mode 100644 index 00000000..28940329 --- /dev/null +++ b/c64/basic/bf52.rom_revision_basic.s @@ -0,0 +1,25 @@ + +// +// !!! PROPOSAL ONLY !!! PROPOSAL ONLY !!! NOT FOR USING EXTERNALLY YET !!! +// +// +// Do not change! Locations of the following data should be constant - now and forever! +// +// If you want to integrate Open ROMs support in your emulator, FPGA ccomputer, etc. - this +// is the official way to recognize the ROM and it's revision. +// + + +rom_revision_basic: + + // $BF52 + + .text "OR" // Magic string, after "Open ROMs" + .byte CONFIG_ID // Config file ID, might change between revisions + +rom_revision_basic_string: + + .text "DEVEL SNAPSHOT" // Actual ROM revision string + .byte $00 + +__rom_revision_basic_end: diff --git a/c64/basic/e422.initmsg.jmp.s b/c64/basic/e422.initmsg.jmp.s new file mode 100644 index 00000000..5bb33656 --- /dev/null +++ b/c64/basic/e422.initmsg.jmp.s @@ -0,0 +1,11 @@ + +// +// Well-known BASIC routine, described in: +// +// - [CM64] Compute's Mapping the Commodore 64 - page 212 +// +// Prints the start-up messages +// + +INITMSG: + jmp initmsg_real diff --git a/c64/basic/e422.initmsg.s b/c64/basic/initmsg_real.s similarity index 67% rename from c64/basic/e422.initmsg.s rename to c64/basic/initmsg_real.s index 6c2cd302..f79e316f 100644 --- a/c64/basic/e422.initmsg.s +++ b/c64/basic/initmsg_real.s @@ -1,13 +1,8 @@ -// -// Well-known BASIC routine, described in: -// -// - [CM64] Compute's Mapping the Commodore 64 - page 212 -// -// Prints the start-up messages -// +// Routine is too long to fit in the original location -INITMSG: + +initmsg_real: // Print startup banner, up to 255 characters ldx #$00 @@ -19,6 +14,10 @@ INITMSG: bne !- !: + // Print ROM revision + lda #rom_revision_basic_string + jsr STROUT // Print PAL/NTSC, if configured @@ -26,6 +25,9 @@ INITMSG: jsr print_pal_ntsc #endif + jsr initmsg_double_return + jsr print_return + // Work out free bytes, display them jsr basic_do_new sec @@ -41,6 +43,6 @@ INITMSG: ldx #34 jsr print_packed_message - // XXX put them into packed message +initmsg_double_return: jsr print_return jmp print_return diff --git a/c64/kernal/assets/kernal_messages.s b/c64/kernal/assets/kernal_messages.s index 8827bf91..2e3c9a13 100644 --- a/c64/kernal/assets/kernal_messages.s +++ b/c64/kernal/assets/kernal_messages.s @@ -17,6 +17,9 @@ .label __MSG_KERNAL_NTSC = __kernal_message_ntsc - __kernal_messages_start #endif +.label __MSG_KERNAL_PANIC = __kernal_message_panic - __kernal_messages_start +.label __MSG_KERNAL_PANIC_VERSION = __kernal_message_panic_version - __kernal_messages_start + __kernal_messages_start: @@ -51,11 +54,19 @@ __kernal_message_to_hex: #if CONFIG_BANNER_PAL_NTSC __kernal_message_pal: - .text "PAL," + .text ", PAL" .byte $80 + $20 // end of string mark + space __kernal_message_ntsc: - .text "NTSC," + .text ", NTSC" .byte $80 + $20 // end of string mark + space #endif // CONFIG_BANNER_PAL_NTSC + +__kernal_message_panic: + .text "KERNAL PANI" + .byte $80 + $43 // end of string mark + 'C' + +__kernal_message_panic_version: + .text " - ROM MISMATC" + .byte $80 + $48 // end of string mark + 'H' diff --git a/c64/kernal/acptr.s b/c64/kernal/iec/acptr.s similarity index 100% rename from c64/kernal/acptr.s rename to c64/kernal/iec/acptr.s diff --git a/c64/kernal/listen.s b/c64/kernal/iec/listen.s similarity index 100% rename from c64/kernal/listen.s rename to c64/kernal/iec/listen.s diff --git a/c64/kernal/second.s b/c64/kernal/iec/second.s similarity index 100% rename from c64/kernal/second.s rename to c64/kernal/iec/second.s diff --git a/c64/kernal/talk.s b/c64/kernal/iec/talk.s similarity index 100% rename from c64/kernal/talk.s rename to c64/kernal/iec/talk.s diff --git a/c64/kernal/tksa.s b/c64/kernal/iec/tksa.s similarity index 100% rename from c64/kernal/tksa.s rename to c64/kernal/iec/tksa.s diff --git a/c64/kernal/unlsn.s b/c64/kernal/iec/unlsn.s similarity index 100% rename from c64/kernal/unlsn.s rename to c64/kernal/iec/unlsn.s diff --git a/c64/kernal/untlk.s b/c64/kernal/iec/untlk.s similarity index 100% rename from c64/kernal/untlk.s rename to c64/kernal/iec/untlk.s diff --git a/c64/kernal/panic.s b/c64/kernal/panic.s new file mode 100644 index 00000000..bb67d4b2 --- /dev/null +++ b/c64/kernal/panic.s @@ -0,0 +1,61 @@ + +// +// Something terrible happened - show the panic screen +// + +// .A = 0 - just panic, no extra message +// .A = 1 - ROM version mismatch + +panic: + + sei + pha + + jsr IOINIT + jsr setup_vicii + jsr clear_screen + + // XXX disable NMIs + + ldx #$14 + ldy #$0E + jsr plot_set + + ldx #__MSG_KERNAL_PANIC + jsr print_kernal_message + + pla + beq kernal_panic_infinite_loop + pha + + ldx #$02 + ldy #$02 + jsr plot_set + + pla + pha + jsr print_hex_byte + + pla + cmp #$01 + bne kernal_panic_infinite_loop + + ldx #__MSG_KERNAL_PANIC_VERSION + jsr print_kernal_message + +kernal_panic_infinite_loop: + ldx #$00 + stx VIC_EXTCOL + + ldx #$80 +!: + dex + bne !- + + ldx #$06 + stx VIC_EXTCOL +!: + dex + bne !- + + beq kernal_panic_infinite_loop // branch always diff --git a/c64/kernal/xxxx.rom_revision_kernal.s b/c64/kernal/xxxx.rom_revision_kernal.s new file mode 100644 index 00000000..cbd215a0 --- /dev/null +++ b/c64/kernal/xxxx.rom_revision_kernal.s @@ -0,0 +1,34 @@ + +// +// !!! PROPOSAL ONLY !!! PROPOSAL ONLY !!! NOT FOR USING EXTERNALLY YET !!! +// +// +// Do not change! Locations of the following data should be constant - now and forever! +// +// If you want to integrate Open ROMs support in your emulator, FPGA ccomputer, etc. - this +// is the official way to recognize the ROM and it's revision. +// + + +// XXX we need to find a safe address within $E4D3-$FFFF range, we need 20 bytes + + +panic_vector: + + // This vector is to be used by non-Kernal ROMs, if they want to complain + // about incompatible ROM releases - jump via this vector with .A set to 1 + + .byte panic + +rom_revision_kernal: + + .text "OR" // Magic string, after "Open ROMs" + .byte CONFIG_ID // Config file ID, might change between revisions + +rom_revision_kernal_string: + + .text "DEVEL SNAPSHOT" // Actual ROM revision string + .byte $00 + +__rom_revision_kernal_end: