From 1a80cd10714274b191229dcc13590cb9b7be49b2 Mon Sep 17 00:00:00 2001
From: "ol.sc"
Date: Wed, 17 Oct 2012 20:24:43 +0000
Subject: [PATCH] Added check for disk in drive on chdir().
git-svn-id: svn://svn.cc65.org/cc65/trunk@5859 b7a2c559-68d2-44c3-8de9-860c34a00d81
---
libsrc/cbm/Makefile | 1 +
libsrc/cbm/devicedir.s | 53 +++++++-----------------------------------
libsrc/cbm/diskinit.s | 53 ++++++++++++++++++++++++++++++++++++++++++
libsrc/cbm/syschdir.s | 17 ++++++++++----
4 files changed, 76 insertions(+), 48 deletions(-)
create mode 100644 libsrc/cbm/diskinit.s
diff --git a/libsrc/cbm/Makefile b/libsrc/cbm/Makefile
index 3230ab3b9..99753dd97 100644
--- a/libsrc/cbm/Makefile
+++ b/libsrc/cbm/Makefile
@@ -72,6 +72,7 @@ S_OBJS = c_acptr.o \
devicedir.o \
dir.o \
diskcmd.o \
+ diskinit.o \
exehdr.o \
filedes.o \
filename.o \
diff --git a/libsrc/cbm/devicedir.s b/libsrc/cbm/devicedir.s
index b63a8ebe9..3a4e6d774 100644
--- a/libsrc/cbm/devicedir.s
+++ b/libsrc/cbm/devicedir.s
@@ -5,9 +5,7 @@
;
.export _getdevicedir
- .import opencmdchannel, closecmdchannel
- .import writefndiskcmd, readdiskerror
- .import isdisk, fnunit, fncmd, devicestr
+ .import diskinit, devicestr, fnunit
.import popa, popax
.importzp ptr2, ptr3
@@ -29,63 +27,30 @@
sta ptr2
stx ptr2+1
-; Save device
+; Check device readiness
jsr popa
- sta fnunit
-
-; Check for disk device
-
- tax
- jsr isdisk
- bcs erange
-
-; Open channel
-
- jsr opencmdchannel
- bne oserr
-
-; Write command
-
- lda #'i' ; Init command
- sta fncmd
- jsr writefndiskcmd
- bne close
-
-; Read error
-
- ldx fnunit
- jsr readdiskerror
-
-; Close channel
-
-close: pha
- ldx fnunit
- jsr closecmdchannel
- pla
- bne oserr
+ jsr diskinit
+ beq size
+ jsr __mappederrno
+ bne fail ; Branch always
; Check for sufficient buf size
- lda ptr3+1
+size: lda ptr3+1
bne okay ; Buf >= 256
lda ptr3
cmp #3
bcs okay ; Buf >= 3
-
-erange: lda #