1
0
mirror of https://github.com/cc65/cc65.git synced 2025-04-05 13:37:17 +00:00

Introduced getdevicedir() - with implementation for the CBMs.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5840 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
ol.sc 2012-10-07 19:18:56 +00:00
parent 3470f230ae
commit 987c3066a3
5 changed files with 143 additions and 20 deletions

View File

@ -55,6 +55,8 @@ unsigned char getfirstdevice (void);
unsigned char __fastcall__ getnextdevice (unsigned char device);
char* __fastcall__ getdevicedir (unsigned char device, char* buf, size_t size);
/* End of device.h */

View File

@ -69,6 +69,8 @@ S_OBJS = c_acptr.o \
closedir.o \
ctype.o \
cvline.o \
devicedir.o \
devicestr.o \
dir.o \
diskcmd.o \
exehdr.o \

97
libsrc/cbm/devicedir.s Normal file
View File

@ -0,0 +1,97 @@
;
; Oliver Schmidt, 2012-09-10
;
; char* __fastcall__ getdevicedir (unsigned char device, char* buf, size_t size);
;
.export _getdevicedir
.import opencmdchannel, closecmdchannel
.import writefndiskcmd, readdiskerror
.import isdisk, fnunit, fncmd, devicestr
.import popa, popax
.importzp ptr2, ptr3
.include "errno.inc"
;------------------------------------------------------------------------------
; _getdevicedir
.proc _getdevicedir
; Save size
sta ptr3
stx ptr3+1
; Save buf
jsr popax
sta ptr2
stx ptr2+1
; Save device
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
; Check for sufficient buf size
lda ptr3+1
bne okay ; Buf >= 256
lda ptr3
cmp #3
bcs okay ; Buf >= 3
erange: lda #<ERANGE
bne errno ; Branch always
oserr: jsr __osmaperrno
errno: jsr __seterrno ; Returns 0 in A
tax ; Return NULL
rts
; Copy device string representation into buf
okay: lda fnunit
jsr devicestr
; Success, return buf
lda ptr2
ldx ptr2+1
rts
.endproc

35
libsrc/cbm/devicestr.s Normal file
View File

@ -0,0 +1,35 @@
;
; Stefan Haubenthal, 2005-06-08
;
; CBM device to string
;
.export devicestr
.import pusha0, tosudiva0
.importzp sreg, ptr1, ptr2
.macpack generic
;------------------------------------------------------------------------------
; Convert unit number in A into string representation pointed to by ptr2.
.proc devicestr
jsr pusha0
lda #10
jsr tosudiva0
ldy #0
lda sreg
beq :+ ; >=10
add #'0'
sta (ptr2),y
iny
: lda ptr1 ; rem
add #'0'
sta (ptr2),y
iny
lda #0
sta (ptr2),y
rts
.endproc

View File

@ -5,31 +5,18 @@
;
.export initcwd
.import __curunit, __cwd
.import pusha0, tosudiva0
.importzp sreg, ptr1
.macpack generic
.import __curunit, __cwd, devicestr
.importzp ptr2
.segment "INIT"
.proc initcwd
lda #<__cwd
ldx #>__cwd
sta ptr2
stx ptr2+1
lda __curunit
jsr pusha0
lda #10
jsr tosudiva0
ldx #0
lda sreg
beq :+ ; >=10
add #'0'
sta __cwd
inx
: lda ptr1 ; rem
add #'0'
sta __cwd,x
lda #0
sta __cwd+1,x
rts
jmp devicestr
.endproc