gotoy.o         \
         home.o          \
        initcwd.o       \
+       iobuf.o         \
         joy_stddrv.o    \
        kbhit.o         \
         mainargs.o      \
 
--- /dev/null
+;
+; Oliver Schmidt, 10.9.2009
+;
+; Default ProDOS 8 I/O buffer management
+; 
+
+        .export                iobuf_alloc, iobuf_free
+        .export                iobuf_init,  iobuf_done
+        .import                iobuf_nop
+        .import                _posix_memalign, _free
+
+iobuf_alloc := _posix_memalign
+iobuf_free  := _free
+iobuf_init  := iobuf_nop
+iobuf_done  := iobuf_nop
 
 ;
 
         .import         __dos_type
+        .import         iobuf_init, iobuf_done
+        .export         iobuf_nop
 
         .include        "mli.inc"
 
         beq     oserr
 
         ; Call MLI and return
+        jsr     iobuf_init
         jsr     ENTRY
 call:   .byte   $00
         .addr   mliparam
-        rts
+        jmp     iobuf_done
 
         ; Load oserror code and return
 oserr:  lda     #$01           ; "Invalid MLI function code number"
         sec
-        rts
\ No newline at end of file
+        ; Fall through
+
+iobuf_nop:
+        rts
 
 
         .import                pushname, popname
         .import        errnoexit, oserrexit
-        .import                _posix_memalign, _free
+        .import                iobuf_alloc, iobuf_free
         .import        addysp, incsp4, incaxy, pushax, popax
 
         .include       "zeropage.inc"
         ldx    #>$0100
         jsr    pushax          ; Preserves A
         ldx    #>$0400
-        jsr    _posix_memalign
+        jsr    iobuf_alloc
        tay                     ; Save errno code
 
         ; Restore fdtab slot
         ; Free I/O buffer
         lda    #$00
         ldx    fdtab + FD::BUFFER+1,y
-        jmp    _free
+        jmp    iobuf_free
 
 closeallfiles:
         ; All open files
 
        gotoy.o         \
         home.o          \
        initcwd.o       \
+       iobuf.o         \
         joy_stddrv.o    \
        kbhit.o         \
         mainargs.o      \