From: ol.sc
Date: Tue, 16 Oct 2012 21:39:40 +0000 (+0000)
Subject: Implemented __syschdir on CBM. As getcwd returns a cached directory any direct access...
X-Git-Tag: V2.14~217
X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8b26ed2a6993cd428c915adfccf8eb4a12f6d167;p=cc65
Implemented __syschdir on CBM. As getcwd returns a cached directory any direct access to __curunit would cause inconsistencies. Therefore __curunit was renamed to curunit to prohibit user access.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5857 b7a2c559-68d2-44c3-8de9-860c34a00d81
---
diff --git a/include/cbm.h b/include/cbm.h
index 3ca8715e4..5a422806a 100644
--- a/include/cbm.h
+++ b/include/cbm.h
@@ -81,10 +81,9 @@
-/* The file stream implementation and the POSIX I/O functions will use the
- * following variables to determine the file type and the disk unit to use.
+/* The file stream implementation and the POSIX I/O functions will
+ * use the following variable to determine the file type to use.
*/
-extern unsigned char _curunit; /* Defaults to current when program started */
extern char _filetype; /* Defaults to 's' */
diff --git a/libsrc/cbm/Makefile b/libsrc/cbm/Makefile
index 5e3396e13..3230ab3b9 100644
--- a/libsrc/cbm/Makefile
+++ b/libsrc/cbm/Makefile
@@ -19,7 +19,7 @@ CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
#--------------------------------------------------------------------------
# Rules
-%.o: %.c
+%.o: %.c
@$(CC) $(CFLAGS) $<
@$(AS) -o $@ $(AFLAGS) $(*).s
@@ -29,74 +29,75 @@ CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
#--------------------------------------------------------------------------
# Object files
-C_OBJS = cbm_dir.o \
- cbm_load.o \
- cbm_save.o \
- opendir.o \
- readdir.o \
- seekdir.o
+C_OBJS = cbm_dir.o \
+ cbm_load.o \
+ cbm_save.o \
+ opendir.o \
+ readdir.o \
+ seekdir.o
S_OBJS = c_acptr.o \
- c_basin.o \
+ c_basin.o \
c_bsout.o \
c_chkin.o \
- c_ciout.o \
- c_ckout.o \
+ c_ciout.o \
+ c_ckout.o \
c_clall.o \
- c_close.o \
- c_clrch.o \
- c_getin.o \
+ c_close.o \
+ c_clrch.o \
+ c_getin.o \
c_iobase.o \
c_listen.o \
- c_load.o \
- c_open.o \
- c_readst.o \
- c_save.o \
+ c_load.o \
+ c_open.o \
+ c_readst.o \
+ c_save.o \
c_setlfs.o \
c_setnam.o \
- c_talk.o \
+ c_talk.o \
c_unlsn.o \
c_untlk.o \
cbm_close.o \
- cbm_filetype.o \
- cbm_open.o \
- cbm_read.o \
- cbm_write.o \
- cclear.o \
- chline.o \
- clock.o \
- close.o \
- closedir.o \
- ctype.o \
- cvline.o \
- devicedir.o \
- dir.o \
- diskcmd.o \
- exehdr.o \
- filedes.o \
- filename.o \
- filetype.o \
- filevars.o \
- getdevice.o \
+ cbm_filetype.o \
+ cbm_open.o \
+ cbm_read.o \
+ cbm_write.o \
+ cclear.o \
+ chline.o \
+ clock.o \
+ close.o \
+ closedir.o \
+ ctype.o \
+ cvline.o \
+ devicedir.o \
+ dir.o \
+ diskcmd.o \
+ exehdr.o \
+ filedes.o \
+ filename.o \
+ filetype.o \
+ filevars.o \
+ getdevice.o \
gotox.o \
gotoxy.o \
gotoy.o \
- initcwd.o \
- loadaddr.o \
- open.o \
- oserrlist.o \
+ initcwd.o \
+ loadaddr.o \
+ open.o \
+ oserrlist.o \
oserror.o \
- read.o \
- rewinddir.o \
- rwcommon.o \
- scratch.o \
- sysremove.o \
- sysrename.o \
- telldir.o \
- toascii.o \
- wherex.o \
- wherey.o \
- write.o
+ read.o \
+ rewinddir.o \
+ rwcommon.o \
+ scratch.o \
+ syschdir.o \
+ sysremove.o \
+ sysrename.o \
+ telldir.o \
+ toascii.o \
+ wherex.o \
+ wherey.o \
+ write.o
#--------------------------------------------------------------------------
# Targets
@@ -109,4 +110,3 @@ clean:
@$(RM) *~ *.bck $(C_OBJS:.o=.s) $(C_OBJS) $(S_OBJS)
zap: clean
-
diff --git a/libsrc/cbm/filename.s b/libsrc/cbm/filename.s
index 37caef21d..e5884bbdf 100644
--- a/libsrc/cbm/filename.s
+++ b/libsrc/cbm/filename.s
@@ -9,7 +9,7 @@
.export fnunit, fnlen, fnisfile, fncmd, fnbuf
.import SETNAM
- .import __curunit, __filetype
+ .import curunit, __filetype
.importzp ptr1, tmp1
.include "ctype.inc"
@@ -147,7 +147,7 @@ drivedone:
.proc fndefunit
- lda __curunit
+ lda curunit
sta fnunit
rts
diff --git a/libsrc/cbm/filevars.s b/libsrc/cbm/filevars.s
index baaef66a4..316cf2762 100644
--- a/libsrc/cbm/filevars.s
+++ b/libsrc/cbm/filevars.s
@@ -4,14 +4,14 @@
; Variables used for CBM file I/O
;
- .export __curunit
+ .export curunit
.constructor initcurunit, 30
.importzp devnum
.bss
-__curunit:
+curunit:
.res 1
@@ -23,7 +23,7 @@ __curunit:
bne @L0
lda #8 ; Default is disk
sta devnum
-@L0: sta __curunit
+@L0: sta curunit
rts
.endproc
diff --git a/libsrc/cbm/initcwd.s b/libsrc/cbm/initcwd.s
index d5eb7fb90..1289b71dc 100644
--- a/libsrc/cbm/initcwd.s
+++ b/libsrc/cbm/initcwd.s
@@ -5,7 +5,7 @@
;
.export initcwd, devicestr
- .import __curunit, __cwd
+ .import curunit, __cwd
.import pusha0, tosudiva0
.importzp sreg, ptr1, ptr2
@@ -16,7 +16,7 @@ initcwd:
ldx #>__cwd
sta ptr2
stx ptr2+1
- lda __curunit
+ lda curunit
; Fall through
;------------------------------------------------------------------------------
@@ -28,11 +28,11 @@ devicestr:
jsr tosudiva0
ldy #0
lda sreg
- beq :+ ; >=10
+ beq @L0 ; >=10
add #'0'
sta (ptr2),y
iny
-: lda ptr1 ; rem
+@L0: lda ptr1 ; rem
add #'0'
sta (ptr2),y
iny
diff --git a/libsrc/cbm/syschdir.s b/libsrc/cbm/syschdir.s
new file mode 100644
index 000000000..10dbe33ed
--- /dev/null
+++ b/libsrc/cbm/syschdir.s
@@ -0,0 +1,86 @@
+;
+; Oliver Schmidt, 2012-10-16
+;
+; unsigned char __fastcall__ _syschdir (const char* name);
+;
+
+ .export __syschdir
+ .import curunit, initcwd
+ .importzp ptr1, tmp1, tmp2
+
+;--------------------------------------------------------------------------
+; __syschdir
+
+.proc __syschdir
+
+; Save name
+
+ sta ptr1
+ stx ptr1+1
+
+; Process first character
+
+ ldy #0
+ lda (ptr1),y
+ beq err
+ jsr getdigit
+ bcs err
+ tax
+
+; Process second character
+
+ iny
+ lda (ptr1),y
+ beq done
+ jsr getdigit
+ bcs err
+ stx tmp1 ; First digit
+ sta tmp2 ; Second digit
+
+; Multiply first digit by 10
+
+ ldx #8
+@L0: asl
+ asl tmp1
+ bcc @L1
+ clc
+ adc #10
+@L1: dex
+ bne @L0
+
+; Add second digit to product
+
+ clc
+ adc tmp2
+ tax
+
+; Process third character
+
+ iny
+ lda (ptr1),y
+ bne err
+
+; Success, update cwd
+
+done: stx curunit
+ jmp initcwd ; Returns with A = 0
+
+err: lda #9 ; "Ilegal device"
+ rts
+
+.endproc
+
+;--------------------------------------------------------------------------
+; getdigit
+
+.proc getdigit
+
+ sec
+ sbc #'0'
+ bcs @L0
+ sec
+ rts
+@L0: cmp #10
+ rts
+
+.endproc
\ No newline at end of file