unsigned char __fastcall__ getnextdevice (unsigned char device);
+char* __fastcall__ getdevicedir (unsigned char device, char* buf, size_t size);
+
/* End of device.h */
--- /dev/null
+;
+; 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
--- /dev/null
+;
+; 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
;
.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