more Kernal reorganization

This commit is contained in:
FeralChild64 committed 2019-10-15 17:55:56 +02:00
1 parent 076a839f1a
commit 8829ec8090
20 files changed
+2

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
//
// Official Kernal routine, described in:
//
// - [RG64] C64 Programmer's Reference Guide - page 281
// - [CM64] Compute's Mapping the Commodore 64 - page 230
//
// CPU registers that has to be preserved (see [RG64]): .Y
//
clall_real:
// Store .Y register
phy_trash_a
// Original routine probably just sets LDTND to 0, but this is not really safe,
// so we actually close all the channels; at least IDE64 does the same for
// it's channels, see CLALL description in the IDE64 User's Guide
!:
ldy LDTND
beq !+
dey
lda LAT, y
jsr JCLOSE
jmp !-
!:
// Restore .Y register
ply_trash_a
// 'C64 Programmers Reference Guide', page 281, claims it calls CLRCHN too
jsr CLRCHN
// Not sure whether original Kernal does so, but it seems sane to also clear possible errors
jmp kernalstatus_reset
+6
View File
@@ -0,0 +1,6 @@
// Our implementation is longer than the original one,
// placing it here would cause a collision with CLRCHN
CLALL:
jmp clall_real
+8
View File
@@ -0,0 +1,8 @@
All the Kernal routines, for which there are vectors in $0314-$0333, have to be available at their original addresses.
Reason: some autostart software (https://codebase64.org/doku.php?id=base:autostarting_disk_files) override these vectors, so that some point
to new locations (custom IRQ routine, custom STOP routine, etc.), while others points the original Kernal routines. Different techniques modify
different vectors (while resetting others to original C64 locations), some don't change the vectors at all, but might still put the original
C64 Kernal addresses there (for example, if the file overrides keyboard input buffer and screeen memory).
For various cartridges (like IDE64) this just means disabling their extensions; for us that would mean improperly functionning Kernal.
+175
View File
@@ -0,0 +1,175 @@
//
// Helper functions for various LOAD/VERIVY/SAVE routine variants (IEC / U64 / etc.)
//
lvs_send_file_name:
ldy #0
lvs_send_file_name_loop:
cpy FNLEN
beq lvs_send_file_name_done
#if CONFIG_MEMORY_MODEL_60K
ldx #<FNADDR+0
jsr peek_under_roms
#else // CONFIG_MEMORY_MODEL_38K
lda (FNADDR),y
#endif
iny
// Set Carry flag on the last file name character, to mark EOI
cpy FNLEN
clc
bne !+
sec
!:
// Transmit one character
sta TBTCNT
jsr iec_tx_byte
jmp lvs_send_file_name_loop
lvs_send_file_name_done:
jsr UNLSN
rts
lvs_handle_byte_load_verify:
// XXX add VERIFY support
// Save it and advance pointer.
// As with our BASIC, we want to enable LOADing
// anywhere in memory, including over the IO space.
// Thus we have to use a helper routine in low memory
// to do the memory access
#if CONFIG_MEMORY_MODEL_60K
// Save byte under ROMs and IO if required
php
sei
// XXX behavior should depend on address
ldx #$33
stx $01
ldy #0
sta (STAL),y
ldx #$37
stx $01
plp
#else
ldy #0
sta (STAL),y
#endif
rts
lvs_advance_pointer:
// Advance pointer
inc STAL
beq !+
jmp lvs_success_end
!:
inc STAL+1
// If we wrap around to $0000, then this is bad.
bne !+
jmp lvs_error_end
!:
clc
rts
lvs_display_searching_for:
lda MSGFLG
bpl lvs_display_end
ldx #__MSG_KERNAL_SEARCHING_FOR
jsr print_kernal_message
ldy #$00
!:
cpy FNLEN
beq lvs_display_end
#if CONFIG_MEMORY_MODEL_60K
ldx #<FNADDR+0
jsr peek_under_roms
#else // CONFIG_MEMORY_MODEL_38K
lda (FNADDR),y
#endif
jsr JCHROUT
iny
jmp !-
lvs_display_end:
rts
lvs_display_loading_verifying:
// Display LOADING / VERIFYING and start address
lda MSGFLG
bpl lvs_display_end
ldx #__MSG_KERNAL_LOADING
lda VERCKK
beq !+
ldx #__MSG_KERNAL_VERIFYING
!:
jsr print_kernal_message
// FALLTHROUGH
lvs_display_start_addr:
ldx #__MSG_KERNAL_FROM_HEX
!:
jsr print_kernal_message
lda STAL+1
jsr print_hex_byte
lda STAL+0
jmp print_hex_byte
lvs_display_done:
// Display end address
lda MSGFLG
bpl lvs_display_end
ldx #__MSG_KERNAL_TO_HEX
jmp !-
lvs_wrap_around_error:
// This error is probably not even detected by C64 Kernal;
// report BASIC error code that looks the most sane
lda #B_ERR_OVERFLOW
lvs_error_end:
sec
rts
lvs_return_last_address:
// Return last address - Compute's Mapping the 64 says without the '+1',
// checked (short test program) on original ROMs that this is really the case
ldx STAL+0
ldy STAL+1
// FALLTHROUGH
lvs_success_end:
clc
rts
lvs_device_not_found_error:
jsr kernalstatus_DEVICE_NOT_FOUND
jmp kernalerror_DEVICE_NOT_FOUND
lvs_illegal_device_number:
jsr kernalstatus_DEVICE_NOT_FOUND
jmp kernalerror_ILLEGAL_DEVICE_NUMBER
lvs_load_verify_error:
// XXX should we really return BASIC error code here?
lda VERCKK
bne lvs_verify_error
lda #B_ERR_LOAD
bne lvs_error_end
// FALLTHROUGH
lvs_verify_error:
lda #B_ERR_VERIFY
sec
rts
+31
View File
@@ -0,0 +1,31 @@
//
// Official Kernal routine, described in:
//
// - [RG64] C64 Programmer's Reference Guide - page 292
// - [CM64] Compute's Mapping the Commodore 64 - page 239
//
// CPU registers that has to be preserved (see [RG64]): .X, .Y
//
READST:
// Check the current device number
lda FA
cmp #$02
bne !+
// This is RS-232 device - according to 'Compute's Mapping the Commodore 64' page 239
// it reads status from RSSTAT
// XXX 'lda RSSTAT' not possible due to extended scnkey, fix it!
lda #$FF
rts
!:
// According to 'Compute's Mapping the Commodore 64' page 239, it usually retrieves
// status from IOSTATUS
// XXX is it always the case if device is not RS-232 ?
lda IOSTATUS
rts
+20
View File
@@ -0,0 +1,20 @@
//
// Official Kernal routine, described in:
//
// - [RG64] C64 Programmer's Reference Guide - page 297
// - [CM64] Compute's Mapping the Commodore 64 - page 238
//
// CPU registers that has to be preserved (see [RG64]): .A, .X, .Y
//
SETFLS:
// There are 6 sane ways to implement this routine,
// I hope this one won't cause similarity to CBM code
sta LA
sty SA
stx FA
rts
+13
View File
@@ -0,0 +1,13 @@
//
// Official Kernal routine, described in:
//
// - [RG64] C64 Programmer's Reference Guide - page 298
// - [CM64] Compute's Mapping the Commodore 64 - page 239
//
// CPU registers that has to be preserved (see [RG64]): .A, .X, .Y
//
SETMSG:
sta MSGFLG
rts
+20
View File
@@ -0,0 +1,20 @@
//
// Official Kernal routine, described in:
//
// - [RG64] C64 Programmer's Reference Guide - page 298/299
// - [CM64] Compute's Mapping the Commodore 64 - page 238
//
// CPU registers that has to be preserved (see [RG64]): .A, .X, .Y
//
SETNAM:
// There are 6 sane ways to implement this routine,
// I hope this one won't cause similarity to CBM code
sta FNLEN
sty FNADDR + 1
stx FNADDR + 0
rts
+13
View File
@@ -0,0 +1,13 @@
//
// Official Kernal routine, described in:
//
// - [RG64] C64 Programmer's Reference Guide - page 300
// - [CM64] Compute's Mapping the Commodore 64 - page 239
//
// CPU registers that has to be preserved (see [RG64]): .A, .X, .Y
//
SETTMO:
sta TIMOUT
rts