From 7f0119599e77ebb26a95947e7c3a78a2e32d8b46 Mon Sep 17 00:00:00 2001 From: Andrew Alderwick Date: Mon, 8 Nov 2021 18:31:33 +0000 Subject: [PATCH] Check ROM is valid before loading. --- projects/library/check-rom.tal | 15 +++++++++++++++ projects/library/load-rom.tal | 8 -------- projects/software/boot.tal | 6 ++++++ 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 projects/library/check-rom.tal diff --git a/projects/library/check-rom.tal b/projects/library/check-rom.tal new file mode 100644 index 0000000..141cf8f --- /dev/null +++ b/projects/library/check-rom.tal @@ -0,0 +1,15 @@ +@check-rom ( filename* -- 00 if the file doesn't exist or not a valid ROM + OR 01 if the ROM seems to be valid ) + .File/name DEO2 + #0001 .File/length DEO2 + ;&first-char .File/read DEO2 + + ( did the file read okay? ) + .File/success DEI2 ORA + + ( is the first character a LIT, LIT2, LITk or LIT2k? ) + LIT &first-char $1 #9f AND #80 EQU + + AND + JMP2r + diff --git a/projects/library/load-rom.tal b/projects/library/load-rom.tal index e2dedb3..fa21a0a 100644 --- a/projects/library/load-rom.tal +++ b/projects/library/load-rom.tal @@ -12,14 +12,6 @@ .File/name DEO2 - ( return if file can't be found, or zero length ) - #0001 .File/length DEO2 - ;&tmp .File/read DEO2 - .File/success DEI2 ORA JMP JMP2r - - ( close the file so the next read starts at the beginning ) - .File/name DEI2k ROT DEO2 - ( clear wst ) #ab &wst-loop diff --git a/projects/software/boot.tal b/projects/software/boot.tal index 5e72e49..dda1f8c 100644 --- a/projects/software/boot.tal +++ b/projects/software/boot.tal @@ -182,6 +182,11 @@ RTN DUP2 INC2 ;close-path JSR2 #0006 ++ DUP2 ;print-string JSR2 #0a .Console/write DEO + + DUP2 ;check-rom JSR2 ,&valid JCN + POP2 RTN + + &valid ;load-rom JSR2 RTN @@ -394,6 +399,7 @@ RTN 2729 2b2e 3032 3537 3a3d 3f42 4547 4a4d 5053 5659 5c5f 6265 686b 6e71 7477 7a7d +include projects/library/check-rom.tal include projects/library/load-rom.tal include projects/assets/logo05x05.tal