unsigned char __fastcall__ getnextdevice (unsigned char device);
 
+unsigned char getcurrentdevice (void);
+
 char* __fastcall__ getdevicedir (unsigned char device, char* buf, size_t size);
 
 
 
        cputc.o         \
        crt0.o          \
        ctype.o         \
+       curdevice.o     \
        cvline.o        \
        devicedir.o     \
        dioclose.o      \
 
--- /dev/null
+;
+; Oliver Schmidt, 2012-10-21
+;
+; unsigned char getcurrentdevice (void);
+;
+
+        .export         _getcurrentdevice
+        .import         __dos_type
+
+        .include        "mli.inc"
+
+_getcurrentdevice:
+
+        ; Use unit number of most recent accessed device
+        lda     DEVNUM
+        lsr
+        lsr
+        lsr
+        lsr
+
+        ; Check for ProDOS 8
+        ldx     __dos_type
+        bne     :+
+        lda     #$FF            ; INVALID_DEVICE
+
+:       ldx     #$00
+        rts
 
        cputc.o         \
        crt0.o          \
        ctype.o         \
+       curdevice.o     \
        cvline.o        \
        devicedir.o     \
        dioclose.o      \
 
                close.o         \
                closedir.o      \
                ctype.o         \
+               curdevice.o     \
                cvline.o        \
                devicedir.o     \
                dir.o           \
 
--- /dev/null
+;
+; Oliver Schmidt, 2012-10-21
+;
+; unsigned char getcurrentdevice (void);
+;
+
+        .export         _getcurrentdevice
+        .import         curunit
+
+;------------------------------------------------------------------------------
+; _getcurrentdevice
+
+.proc   _getcurrentdevice
+
+        lda     curunit
+        ldx     #$00
+        rts
+
+.endproc