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

@@ -19,7 +19,7 @@ CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# Rules # Rules
%.o: %.c %.o: %.c
@$(CC) $(CFLAGS) $< @$(CC) $(CFLAGS) $<
@$(AS) -o $@ $(AFLAGS) $(*).s @$(AS) -o $@ $(AFLAGS) $(*).s
@@ -29,74 +29,75 @@ CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# Object files # Object files
C_OBJS = cbm_dir.o \ C_OBJS = cbm_dir.o \
cbm_load.o \ cbm_load.o \
cbm_save.o \ cbm_save.o \
opendir.o \ opendir.o \
readdir.o \ readdir.o \
seekdir.o seekdir.o
S_OBJS = c_acptr.o \ S_OBJS = c_acptr.o \
c_basin.o \ c_basin.o \
c_bsout.o \ c_bsout.o \
c_chkin.o \ c_chkin.o \
c_ciout.o \ c_ciout.o \
c_ckout.o \ c_ckout.o \
c_clall.o \ c_clall.o \
c_close.o \ c_close.o \
c_clrch.o \ c_clrch.o \
c_getin.o \ c_getin.o \
c_iobase.o \ c_iobase.o \
c_listen.o \ c_listen.o \
c_load.o \ c_load.o \
c_open.o \ c_open.o \
c_readst.o \ c_readst.o \
c_save.o \ c_save.o \
c_setlfs.o \ c_setlfs.o \
c_setnam.o \ c_setnam.o \
c_talk.o \ c_talk.o \
c_unlsn.o \ c_unlsn.o \
c_untlk.o \ c_untlk.o \
cbm_close.o \ cbm_close.o \
cbm_filetype.o \ cbm_filetype.o \
cbm_open.o \ cbm_open.o \
cbm_read.o \ cbm_read.o \
cbm_write.o \ cbm_write.o \
cclear.o \ cclear.o \
chline.o \ chline.o \
clock.o \ clock.o \
close.o \ close.o \
closedir.o \ closedir.o \
ctype.o \ ctype.o \
cvline.o \ cvline.o \
devicedir.o \ devicedir.o \
dir.o \ dir.o \
diskcmd.o \ diskcmd.o \
exehdr.o \ exehdr.o \
filedes.o \ filedes.o \
filename.o \ filename.o \
filetype.o \ filetype.o \
filevars.o \ filevars.o \
getdevice.o \ getdevice.o \
gotox.o \ gotox.o \
gotoxy.o \ gotoxy.o \
gotoy.o \ gotoy.o \
initcwd.o \ initcwd.o \
loadaddr.o \ loadaddr.o \
open.o \ open.o \
oserrlist.o \ oserrlist.o \
oserror.o \ oserror.o \
read.o \ read.o \
rewinddir.o \ rewinddir.o \
rwcommon.o \ rwcommon.o \
scratch.o \ scratch.o \
sysremove.o \ syschdir.o \
sysrename.o \ sysremove.o \
telldir.o \ sysrename.o \
toascii.o \ telldir.o \
wherex.o \ toascii.o \
wherey.o \ wherex.o \
write.o wherey.o \
write.o
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# Targets # Targets
@@ -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