Introduced mass-storage device enumaration - with implementation for C64 and C128.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5820 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
ol.sc
2012-09-09 12:14:45 +00:00
parent 640460deb5
commit b586d5ef69
5 changed files with 197 additions and 0 deletions

View File

@@ -56,6 +56,7 @@ OBJS = _scrsize.o \
devnum.o \
fast.o \
get_tv.o \
getdevice.o \
joy_stddrv.o \
kbhit.o \
kernal.o \

67
libsrc/c128/getdevice.s Normal file
View File

@@ -0,0 +1,67 @@
;
; Oliver Schmidt, 2012-09-04
;
; unsigned char getfirstdevice (void);
; unsigned char __fastcall__ getnextdevice (unsigned char device);
;
.export _getfirstdevice
.export _getnextdevice
.import isdisk
.import opencmdchannel
.import closecmdchannel
.importzp tmp2
.include "c128.inc"
;------------------------------------------------------------------------------
; _getfirstdevice
_getfirstdevice:
lda #$FF
; Fall through
;------------------------------------------------------------------------------
; _getnextdevice
_getnextdevice:
tax
next: inx
cpx #$FF
beq done
; [open|close]cmdchannel already call isdisk internally but they
; interpret a non-disk as a no-op while we need to interpret it
; as an error here
jsr isdisk
bcs next
; [open|close]cmdchannel don't call into the Kernal at all if they
; only [in|de]crement the reference count of the shared cmdchannel
; so we need to explicitly initialize ST here
lda #$00
sta ST
stx tmp2
jsr opencmdchannel
ldx tmp2
jsr closecmdchannel
ldx tmp2
; As we had to reference ST above anyway we can as well do so
; here too (instead of calling READST)
lda ST
; Either the Kernal calls above were successfull or there was
; already a cmdchannel to the device open - which is a pretty
; good indication of its existence ;-)
bmi next
done: txa
ldx #$00
rts

View File

@@ -55,6 +55,7 @@ OBJS = _scrsize.o \
devnum.o \
get_ostype.o \
get_tv.o \
getdevice.o \
joy_stddrv.o \
kbhit.o \
kernal.o \

67
libsrc/c64/getdevice.s Normal file
View File

@@ -0,0 +1,67 @@
;
; Oliver Schmidt, 2012-09-04
;
; unsigned char getfirstdevice (void);
; unsigned char __fastcall__ getnextdevice (unsigned char device);
;
.export _getfirstdevice
.export _getnextdevice
.import isdisk
.import opencmdchannel
.import closecmdchannel
.importzp tmp2
.include "c64.inc"
;------------------------------------------------------------------------------
; _getfirstdevice
_getfirstdevice:
lda #$FF
; Fall through
;------------------------------------------------------------------------------
; _getnextdevice
_getnextdevice:
tax
next: inx
cpx #$FF
beq done
; [open|close]cmdchannel already call isdisk internally but they
; interpret a non-disk as a no-op while we need to interpret it
; as an error here
jsr isdisk
bcs next
; [open|close]cmdchannel don't call into the Kernal at all if they
; only [in|de]crement the reference count of the shared cmdchannel
; so we need to explicitly initialize ST here
lda #$00
sta ST
stx tmp2
jsr opencmdchannel
ldx tmp2
jsr closecmdchannel
ldx tmp2
; As we had to reference ST above anyway we can as well do so
; here too (instead of calling READST)
lda ST
; Either the Kernal calls above were successfull or there was
; already a cmdchannel to the device open - which is a pretty
; good indication of its existence ;-)
bmi next
done: txa
ldx #$00
rts