From 4f417d714e5234be7306c56fe2d3dbd2b620edf4 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Sun, 23 Aug 2020 15:43:04 +0200 Subject: [PATCH] added protection against DOS memory damage --- src/dos_m65/,aliases_dos.s | 9 ++++++--- src/dos_m65/dos_chkunit.s | 25 +++++++++++++++++++++++++ src/dos_m65/dos_init.s | 18 ++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/dos_m65/,aliases_dos.s b/src/dos_m65/,aliases_dos.s index c9578fa7..f182d3ce 100644 --- a/src/dos_m65/,aliases_dos.s +++ b/src/dos_m65/,aliases_dos.s @@ -6,6 +6,9 @@ // Page 0 // - .label UNIT_SDCARD = $00 - .label UNIT_FLOPPY = $01 - .label UNIT_RAMDISK = $02 + .label MAGICSTR = $00 // magic string; if not matching, DOS considered non-functional + + .label UNIT_SDCARD = $05 + .label UNIT_FLOPPY = $06 + .label UNIT_RAMDISK = $07 + diff --git a/src/dos_m65/dos_chkunit.s b/src/dos_m65/dos_chkunit.s index 94088238..e813e930 100644 --- a/src/dos_m65/dos_chkunit.s +++ b/src/dos_m65/dos_chkunit.s @@ -6,6 +6,24 @@ dos_CHKUNIT: + // Check for magic string + + pha + phx + + ldx #$04 +!: + lda MAGICSTR, x + cmp dos_magicstr, x + bne dos_CHKUNIT_mem_fail + dex + bpl !- + + plx + pla + + // Check for unit + cmp UNIT_SDCARD beq dos_CHKUNIT_sdcard cmp UNIT_FLOPPY @@ -36,3 +54,10 @@ dos_CHKUNIT_ramdisk: clc rts + +dos_CHKUNIT_mem_fail: + + plx + pla + sec + rts diff --git a/src/dos_m65/dos_init.s b/src/dos_m65/dos_init.s index 82471370..25ed5e7d 100644 --- a/src/dos_m65/dos_init.s +++ b/src/dos_m65/dos_init.s @@ -5,6 +5,20 @@ dos_INIT: + // Set the magic string 'CBDOS' + + phx + ldx #$04 +!: + lda dos_magicstr, x + sta MAGICSTR, x + dex + bpl !- + + plx + + // Set default device numbers + lda #CONFIG_UNIT_SDCARD sta UNIT_SDCARD lda #CONFIG_UNIT_FLOPPY @@ -15,3 +29,7 @@ dos_INIT: // XXX initialize drivers, etc. rts + +dos_magicstr: // 'CBDOS' + + .byte $43, $42, $44, $4F, $53