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
This commit is contained in:
ol.sc
2012-10-16 21:39:40 +00:00
parent 6618e08bc3
commit 8b26ed2a69
6 changed files with 151 additions and 66 deletions

View File

@@ -81,10 +81,9 @@
/* The file stream implementation and the POSIX I/O functions will use the /* The file stream implementation and the POSIX I/O functions will
* following variables to determine the file type and the disk unit to use. * 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' */ extern char _filetype; /* Defaults to 's' */

View File

@@ -90,6 +90,7 @@ S_OBJS = c_acptr.o \
rewinddir.o \ rewinddir.o \
rwcommon.o \ rwcommon.o \
scratch.o \ scratch.o \
syschdir.o \
sysremove.o \ sysremove.o \
sysrename.o \ sysrename.o \
telldir.o \ telldir.o \
@@ -109,4 +110,3 @@ clean:
@$(RM) *~ *.bck $(C_OBJS:.o=.s) $(C_OBJS) $(S_OBJS) @$(RM) *~ *.bck $(C_OBJS:.o=.s) $(C_OBJS) $(S_OBJS)
zap: clean zap: clean

View File

@@ -9,7 +9,7 @@
.export fnunit, fnlen, fnisfile, fncmd, fnbuf .export fnunit, fnlen, fnisfile, fncmd, fnbuf
.import SETNAM .import SETNAM
.import __curunit, __filetype .import curunit, __filetype
.importzp ptr1, tmp1 .importzp ptr1, tmp1
.include "ctype.inc" .include "ctype.inc"
@@ -147,7 +147,7 @@ drivedone:
.proc fndefunit .proc fndefunit
lda __curunit lda curunit
sta fnunit sta fnunit
rts rts

View File

@@ -4,14 +4,14 @@
; Variables used for CBM file I/O ; Variables used for CBM file I/O
; ;
.export __curunit .export curunit
.constructor initcurunit, 30 .constructor initcurunit, 30
.importzp devnum .importzp devnum
.bss .bss
__curunit: curunit:
.res 1 .res 1
@@ -23,7 +23,7 @@ __curunit:
bne @L0 bne @L0
lda #8 ; Default is disk lda #8 ; Default is disk
sta devnum sta devnum
@L0: sta __curunit @L0: sta curunit
rts rts
.endproc .endproc

View File

@@ -5,7 +5,7 @@
; ;
.export initcwd, devicestr .export initcwd, devicestr
.import __curunit, __cwd .import curunit, __cwd
.import pusha0, tosudiva0 .import pusha0, tosudiva0
.importzp sreg, ptr1, ptr2 .importzp sreg, ptr1, ptr2
@@ -16,7 +16,7 @@ initcwd:
ldx #>__cwd ldx #>__cwd
sta ptr2 sta ptr2
stx ptr2+1 stx ptr2+1
lda __curunit lda curunit
; Fall through ; Fall through
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
@@ -28,11 +28,11 @@ devicestr:
jsr tosudiva0 jsr tosudiva0
ldy #0 ldy #0
lda sreg lda sreg
beq :+ ; >=10 beq @L0 ; >=10
add #'0' add #'0'
sta (ptr2),y sta (ptr2),y
iny iny
: lda ptr1 ; rem @L0: lda ptr1 ; rem
add #'0' add #'0'
sta (ptr2),y sta (ptr2),y
iny iny

86
libsrc/cbm/syschdir.s Normal file
View File

@@ -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