From 7089ce05e29c21fcb51b3cf05db0881438bab705 Mon Sep 17 00:00:00 2001 From: oliverschmidt Date: Mon, 5 Apr 2010 14:11:01 +0000 Subject: [PATCH] Added Platform-specific File System (PFS) for the C64 supporting IDE64 fast R/W contributed by Kajtar Zsolt. --- platform/c64/Makefile.c64 | 4 +- platform/c64/README | 5 + platform/c64/lib/pfs.S | 403 +++++++++++++++++++++++++++++++++++ platform/c64/lib/pfs_write.S | 108 ++++++++++ 4 files changed, 519 insertions(+), 1 deletion(-) create mode 100644 platform/c64/lib/pfs.S create mode 100644 platform/c64/lib/pfs_write.S diff --git a/platform/c64/Makefile.c64 b/platform/c64/Makefile.c64 index e04f606c2..7f42cae32 100644 --- a/platform/c64/Makefile.c64 +++ b/platform/c64/Makefile.c64 @@ -30,9 +30,11 @@ # # Author: Oliver Schmidt # -# $Id: Makefile.c64,v 1.11 2010/03/31 06:07:05 oliverschmidt Exp $ +# $Id: Makefile.c64,v 1.12 2010/04/05 14:11:01 oliverschmidt Exp $ # +CONTIKI_SOURCEFILES += pfs.S pfs_write.S + CONTIKI_CPU = $(CONTIKI)/cpu/6502 include $(CONTIKI_CPU)/Makefile.6502 diff --git a/platform/c64/README b/platform/c64/README index c63e94d4b..4d73bd440 100644 --- a/platform/c64/README +++ b/platform/c64/README @@ -13,3 +13,8 @@ The following C64 Ethernet cards are supported: In most cases it is desirable to use an emulator for the development and testing of a Contiki application. VICE is especially well suited as it emulates both the RR-Net and TFE Ethernet cards. It is available at http://www.viceteam.org/. + + +The c64 target supports a PFS that requires less RAM than the POSIX file system +and converts UNIX path names to CMD syntax for CMD drives and IDEDOS 0.90+. Its +primary feature however is support for IDE64 fast read/write. diff --git a/platform/c64/lib/pfs.S b/platform/c64/lib/pfs.S new file mode 100644 index 000000000..03c4e639d --- /dev/null +++ b/platform/c64/lib/pfs.S @@ -0,0 +1,403 @@ +; +; Copyright (c) 2010, Kajtar Zsolt +; All rights reserved. +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; 1. Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; 2. Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. +; 3. Neither the name of the Institute nor the names of its contributors +; may be used to endorse or promote products derived from this software +; without specific prior written permission. +; +; THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND +; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +; ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE +; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +; SUCH DAMAGE. +; +; This file is part of the Contiki operating system. +; +; Author: Kajtar Zsolt +; +;--------------------------------------------------------------------- + .define F_IDE64 1 ; support IDE64, 100 byte only + + .constructor init_pfs + .destructor done_pfs + .importzp ptr1, ptr2, ptr3, sp + .import __curunit, popax, addysp, subysp + .export pfs_rwcommon, pfs_rwsetflags, pfs_rwcommonend + .if F_IDE64 + .export ide64_rwprepare, ide64_rwfinish + .endif + .export _pfs_open, _pfs_read, _pfs_close +;--------------------------------------------------------------------- +F_EOF = $80 +F_NBLK = $40 +F_OPEN = $20 +F_MAXLEN = 80 ;max filename length +ST = $90 ;status +FN = $BB ;filename +FNL = $B7 ;filenamelength +LF = $B8 ;logical file number +SA = $B9 ;secondary address +OPEN = $FFC0 +CLOSE = $FFC3 +CHKIN = $FFC6 +CHKOUT = $FFC9 +CLRCHN = $FFCC +CHRIN = $FFCF +CHROUT = $FFD2 +SETLFS = $FFBA +SETNAM = $FFBD +CLALL = $FFE7 +WRITE = $DEF1 +READ = $DEF4 +;--------------------------------------------------------------------- + .bss + +cmdc: .res 1 +flags: .res 10 +;--------------------------------------------------------------------- + .data + +illchr: .byte $3A, $2A, $3F, $3D ;illegal chars +pw: .byte $2C, $50, $2C, $57 ;,p,w +;--------------------------------------------------------------------- + .segment "INIT" + +init_pfs: + ldy #F_MAXLEN+8 + jsr subysp ;allocate + lda #0 + sta FNL ;no name + ldy #15-1 + jsr open2 ;open command channel + sta cmdc + rts +;--------------------------------------------------------------------- + .code + +error3: jmp error + +_pfs_open: + sta ptr2 + ; Pop and store name + jsr popax + sta FN + stx FN+1 ;filename (kernal) + ldy #F_MAXLEN+8 + jsr subysp ;allocate name + ldy #255 + sty ptr1 +@L10: iny + bmi error3 ;too long... + ldx #4 +@L12: cmp illchr,x + beq error3 ;illegal char? + dex + bpl @L12 + cmp #$2F + bne @L11 + sty ptr1 ;last slash +@L11: lda (FN),y + bne @L10 + sty FNL + + tay + tax + lda #$30 ;this partition + sta (sp),y + iny + inc ptr1 + beq nopath + lda #$2F +@L13: sta (sp),y + iny + lda (FN,x) + inc FN + bne @L14 + inc FN+1 +@L14: cpy ptr1 + bcc @L13 + lda #$2F + sta (sp),y + iny +nopath: lda #$3A +@L16: sta (sp),y + iny + lda (FN,x) + inc FN + bne @L15 + inc FN+1 +@L15: ora #0 + bne @L16 + lsr ptr2 + bcs ro ;read only + ldx #252 +@L20: lda pw-252,x + sta (sp),y ;write + iny + inx + bne @L20 +ro: tya ;name length (kernal) + ldx sp + ldy sp+1 + jsr SETNAM + + lda #0 ;file number + tay ;secondary address +open2: sta ptr2 + sty ptr2+1 + +next: inc ptr2 ;next file number + ldx ptr2 ;file number + cpx #11 + bcs error ;no more files + lda flags-1,x + bne next ;already used + lda ptr2+1 + bne nextsa + inx + stx ptr2+1 +nextsa: inc ptr2+1 ;next channel + lda ptr2 ;file number + ldx __curunit + ldy ptr2+1 ;secondary address + jsr SETLFS + jsr OPEN ;open + bcs oerr + ldx cmdc + beq opok ;error channel open + jsr CHKIN + bcs error + jsr CHRIN + pha + jsr CHRIN + sta ptr1 +@L4: jsr CHRIN + lda ST + beq @L4 + jsr CLRCHN + pla + tax + lsr + cmp #$18 ;no serious error + beq opok + txa + pha + lda ptr2 + jsr CLOSE ;close + pla + cmp #$37 ;no channel? + bne error + lda ptr1 + cmp #$30 + bne error ;not no channel + lda ptr2+1 + cmp #14 + bcc nextsa ;try next channel + bcs error ;give up + +opok: ldx ptr2 + lda #F_OPEN + sta flags-1,x + txa ;ok, return file number + ldx #0 +ret: ldy #F_MAXLEN+8 ; free filename + jmp addysp + +oerr: dec ptr2+1 + cmp #2 ;already open, + beq next ;retry with next + +error: lda #$FF + tax ;failed + bne ret + +.proc _pfs_read + jsr pfs_rwcommon ; pop params, check handle + beq error2 ; not open + + bmi eof + .if F_IDE64 + asl + bmi nblk ; no block operation + + jsr CHKIN + bcs error2 + + ; check support + jsr ide64_rwprepare + bcs norm + + ; read + jsr READ + bcs nosup + jmp ide64_rwfinish + +nosup: lda #F_NBLK + jsr pfs_rwsetflags + .endif + + ; Valid lfn. Make it the input file +nblk: jsr CHKIN + bcs error2 + + ; Decrement the count +norm: ldy #0 +@L3: inc ptr1 + bne @L0 + inc ptr1+1 + beq done ; branch always + + ; Read the next byte +@L0: jsr CHRIN + tax ; save the input byte + + lda ST ; read the IEEE status + cmp #1 ; save it + and #%10111111 ; check anything but the EOI bit + bne error5 ; assume device not present + + ; Store the byte just read + txa + sta (ptr2),y + inc ptr2 + bne @L1 + inc ptr2+1 ; *buf++ = A; + + ; Get the status again and check the EOI bit +@L1: bcc @L3 ; loop if no end of file + + ; Set the EOI flag and bail out + lda #F_EOF + jsr pfs_rwsetflags + + ; Read done, close the input channel +done: jsr CLRCHN ; clrchn + + ; Return the number of chars read +eof: jmp pfs_rwcommonend +.endproc + + ; Error entry, file is not open +done_pfs: + ldx #10 +@L2: ldy flags-1,x ; file open? + beq @L1 + txa + jsr _pfs_close +@L1: dex + bne @L2 + rts + +error5: jsr CLRCHN ; clrchn + +error2: ldx #255 + txa + rts + +_pfs_close: + pha + jsr CLOSE ;close + pla + tax + lda #0 + sta flags-1,x + rts + +.proc pfs_rwcommon + eor #$FF + sta ptr1 + txa + eor #$FF + sta ptr1+1 ; remember -count-1 + + jsr popax ; get buf + sta ptr2 + stx ptr2+1 + + sta ptr3 + stx ptr3+1 ; for length + + jsr popax ; get the handle + sta LF + lda #0 + beq pfs_rwsetflags +.endproc + + .if F_IDE64 +.proc ide64_rwprepare + sec + lda ptr1+1 + eor #255 + beq small ; too small, not worth it + tay + lda ptr1 ; setup registers + eor #255 + tax + lda $031B + eor #$DE + bne noide ; open vector set? + lda $DE60 + eor #$49 + bne noide ; check identification + lda $DE61 + eor #$44 + bne noide + lda $DE62 + eor #$45 + bne noide + clc + lda #ptr2 +small: rts + +noide: lda #F_NBLK + bne pfs_rwsetflags +.endproc + .endif + +.proc pfs_rwsetflags + ldx LF + ora flags-1,x + sta flags-1,x + rts +.endproc + + .if F_IDE64 +.proc ide64_rwfinish + txa + pha + tya + pha + jsr CLRCHN + pla + tax + pla + rts +.endproc + .endif + +.proc pfs_rwcommonend + lda ptr2 + sec + sbc ptr3 + pha + lda ptr2+1 + sbc ptr3+1 + tax + pla + rts +.endproc diff --git a/platform/c64/lib/pfs_write.S b/platform/c64/lib/pfs_write.S new file mode 100644 index 000000000..7e511e513 --- /dev/null +++ b/platform/c64/lib/pfs_write.S @@ -0,0 +1,108 @@ +; +; Copyright (c) 2010, Kajtar Zsolt +; All rights reserved. +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; 1. Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; 2. Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. +; 3. Neither the name of the Institute nor the names of its contributors +; may be used to endorse or promote products derived from this software +; without specific prior written permission. +; +; THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND +; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +; ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE +; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +; SUCH DAMAGE. +; +; This file is part of the Contiki operating system. +; +; Author: Kajtar Zsolt +; +;--------------------------------------------------------------------- + .define F_IDE64 1 ; support IDE64, 100 byte only + + .importzp ptr1, ptr2 + .import pfs_rwcommon, pfs_rwsetflags, pfs_rwcommonend + .if F_IDE64 + .import ide64_rwprepare, ide64_rwfinish + .endif + .export _pfs_write +;--------------------------------------------------------------------- +F_NBLK = $40 +ST = $90 ;status +CHKOUT = $FFC9 +CLRCHN = $FFCC +CHROUT = $FFD2 +WRITE = $DEF1 +;--------------------------------------------------------------------- + .code + +error5: jsr CLRCHN ; clrchn + +error2: ldx #255 + txa + rts + +.proc _pfs_write + jsr pfs_rwcommon ; pop params, check handle + beq error2 ; not open + + .if F_IDE64 + asl + bmi nblk ; no block operation + + jsr CHKOUT + bcs error2 + + ; check support + jsr ide64_rwprepare + bcs norm + + ; write + jsr WRITE + bcs nosup + jmp ide64_rwfinish + +nosup: lda #F_NBLK + jsr pfs_rwsetflags + .endif + + ; Valid lfn. Make it the output file +nblk: jsr CHKOUT + bcs error2 + + ; Output the next character from the buffer +norm: ldy #0 +@L3: inc ptr1 + bne @L0 + inc ptr1+1 + beq @L2 + +@L0: lda (ptr2),y + inc ptr2 + bne @L1 + inc ptr2+1 ; A = *buf++; +@L1: jsr CHROUT + lda ST + beq @L3 + bne error5 ; bail out on errors +@L2: + + ; Wrote all chars, close the output channel + jsr CLRCHN + + ; Return the number of chars written + jmp pfs_rwcommonend +.endproc