]> git.sur5r.net Git - cc65/commitdiff
Added comments to cbm.h.
authormrintsch <mrintsch@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 20 Mar 2001 21:06:04 +0000 (21:06 +0000)
committermrintsch <mrintsch@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 20 Mar 2001 21:06:04 +0000 (21:06 +0000)
load/save returns oserror code.
Added open/close and read (which is not tested yet).

git-svn-id: svn://svn.cc65.org/cc65/trunk@637 b7a2c559-68d2-44c3-8de9-860c34a00d81

16 files changed:
include/cbm.h
libsrc/cbm/Makefile
libsrc/cbm/c_basin.s
libsrc/cbm/c_chkin.s [new file with mode: 0644]
libsrc/cbm/c_ckout.s
libsrc/cbm/c_close.s
libsrc/cbm/c_clrch.s
libsrc/cbm/c_load.s
libsrc/cbm/c_open.s
libsrc/cbm/c_readst.s
libsrc/cbm/c_save.s
libsrc/cbm/cbm_close.s [new file with mode: 0644]
libsrc/cbm/cbm_load.c
libsrc/cbm/cbm_open.c [new file with mode: 0644]
libsrc/cbm/cbm_read.c [new file with mode: 0644]
libsrc/cbm/cbm_save.c

index bc787241f4510b931f75e28c749bbfd76326177a..80ad0de0bfe921566c9daf7352279bb067358d4e 100644 (file)
 void __fastcall__ cbm_k_setlfs (unsigned char LFN, unsigned char DEV,
                                 unsigned char SA);
 void __fastcall__ cbm_k_setnam (const char* Name);
-unsigned __fastcall__ cbm_k_load (unsigned char flag, unsigned addr);
-unsigned __fastcall__ cbm_k_save(unsigned int start, unsigned int end);
+unsigned char __fastcall__ cbm_k_load(unsigned char flag, unsigned addr);
+unsigned char __fastcall__ cbm_k_save(unsigned int start, unsigned int end);
+unsigned char __fastcall__ cbm_k_open (void);
+void __fastcall__ cbm_k_close (unsigned char FN);
+unsigned char __fastcall__ cbm_k_readst (void);
+unsigned char __fastcall__ cbm_k_chkin (unsigned char FN);
+unsigned char __fastcall__ cbm_k_basin (void);
+void __fastcall__ cbm_k_clrch (void);
 
 /* BASIC-like functions */
-unsigned int cbm_load(const char* name, char device, unsigned int addr);
-unsigned int cbm_save(const char* name, char device,
-                      unsigned int start, unsigned int end);
+unsigned char cbm_load(const char* name, unsigned char device, unsigned int addr);
+/* Loads file "name" from given device to given address or to the load address
+ * of the file if addr is 0 (like load"name",8,1 in BASIC)
+ * Returns 0 if loading was successful otherwise an errorcode (see table below).
+ */
 
+unsigned char cbm_save(const char* name, unsigned char device,
+                      unsigned int start, unsigned int end);
+/* Saves a memory area from start to end-1 to a file.
+ * Returns 0 if saving was successful, otherwise an errorcode (see table below).
+ */
+
+unsigned char cbm_open(unsigned char lfn, unsigned char device,
+                       unsigned char sec_addr, const char* name);
+/* Opens a file. Works just like the BASIC command.
+ * Returns 0 if opening was successful, otherwise an errorcode (see table below).
+ */
+
+void __fastcall__ cbm_close (unsigned char lfn);
+/* Closes a file */
+
+int cbm_read(unsigned char lfn, void* buffer, unsigned int size);
+
+/* Errorcodes of load, save, open functions:
+ *
+ * errorcode   BASIC error
+ *     1   =   too many files
+ *     2   =   file open
+ *     3   =   file not open
+ *     4   =   file not found
+ *     5   =   device not present
+ *     6   =   not input file
+ *     7   =   not output file
+ *     8   =   missing filename
+ *     9   =   illegal device number
+ */
 
 /* End of cbm.h */
 #endif
-
-
-
index 410ab112d38b8439cbd7575827380ac03ce0135a..3a184fe70003840d7b2953d13f291e15ed1f87e3 100644 (file)
 %.o:   %.s
        @$(AS) -g -o $@ $(AFLAGS) $<
 
-C_OBJS = cbm_load.o cbm_save.o
+C_OBJS = cbm_load.o cbm_save.o cbm_open.o cbm_read.o
 
 S_OBJS = ctype.o getenv.o gotoxy.o gotox.o gotoy.o where.o\
         clock.o chline.o cvline.o cclear.o revers.o\
         c_readst.o c_close.o c_open.o c_ckout.o c_clrch.o c_bsout.o\
         c_basin.o c_clall.o c_iobase.o c_setnam.o c_setlfs.o c_acptr.o\
         c_ciout.o c_untlk.o c_unlsn.o c_listen.o c_talk.o c_load.o\
-        c_save.o oserror.o
+        c_save.o oserror.o cbm_close.o c_chkin.o
 
 all:   $(C_OBJS) $(S_OBJS)
 
index 281f433ef85b29cafd508cf145acfd85cb9f7c40..a852b6c5babe8febfe9fecd540381c3d4435ade5 100644 (file)
@@ -1,16 +1,11 @@
 ;
 ; Ullrich von Bassewitz, 03.06.1999
 ;
-; unsigned char __fastcall__ cbm_basin (void);
+; unsigned char __fastcall__ cbm_k_basin (void);
 ;
 
                .include        "cbm.inc"
 
-               .export         _cbm_basin
-
-_cbm_basin:
-       jsr     BASIN
-       ldx     #0
-       rts
-
+               .export         _cbm_k_basin
 
+_cbm_k_basin = BASIN
diff --git a/libsrc/cbm/c_chkin.s b/libsrc/cbm/c_chkin.s
new file mode 100644 (file)
index 0000000..4febff7
--- /dev/null
@@ -0,0 +1,17 @@
+;
+; Marc 'BlackJack' Rintsch, 20.03.2001
+;
+; unsigned char __fastcall__ cbm_k_chkin (unsigned char FN);
+;
+
+               .include        "cbm.inc"
+
+               .export         _cbm_k_chkin
+
+_cbm_k_chkin:
+       tax
+               jsr     CHKIN
+       bcs     @NotOk
+        lda     #0
+@NotOk:        rts
+
index 7fffe9f70bc63515ca0f7f1e5978baa5a52a9291..f239727cb18b907e91cc9f127feebcab67f5c3f6 100644 (file)
@@ -1,14 +1,14 @@
 ;
 ; Ullrich von Bassewitz, 03.06.1999
 ;
-; unsigned __fastcall__ cbm_ckout (unsigned char FN);
+; unsigned char __fastcall__ cbm_k_ckout (unsigned char FN);
 ;
 
                .include        "cbm.inc"
 
-               .export         _cbm_ckout
+               .export         _cbm_k_ckout
 
-_cbm_ckout:
+_cbm_k_ckout:
        tax
                jsr     CKOUT
        ldx     #0
index 72cbded777531e5d1e85af57fd32f54aba13bf8e..e2a559cc4033dc7beafc2090ecf7a2e0a7617da7 100644 (file)
@@ -1,14 +1,14 @@
 ;
 ; Ullrich von Bassewitz, 03.06.1999
 ;
-; void __fastcall__ cbm_close (unsigned char FN);
+; void __fastcall__ cbm_k_close (unsigned char FN);
 ;
 
                .include        "cbm.inc"
 
-               .export         _cbm_close
+               .export         _cbm_k_close
 
-_cbm_close:
+_cbm_k_close:
                clc
                jmp     CLOSE
 
index ba76b588a4c27387544ee9d9e8ee9c883eaeb72e..632a9e2b2611ea7b632937549fe8768d96c05d78 100644 (file)
@@ -1,12 +1,12 @@
 ;
 ; Ullrich von Bassewitz, 03.06.1999
 ;
-; void __fastcall__ cbm_clrch (void);
+; void __fastcall__ cbm_k_clrch (void);
 ;
 
                .include        "cbm.inc"
 
-               .export         _cbm_clrch
+               .export         _cbm_k_clrch
 
-_cbm_clrch = CLRCH
+_cbm_k_clrch = CLRCH
 
index 14b92917c19a87d69896f30283b738c1822144f5..4a767eab4e6cfcd1a701ef5678e7ab6eb2180ad9 100644 (file)
@@ -1,7 +1,7 @@
 ;
 ; Ullrich von Bassewitz, 03.06.1999
 ;
-; unsigned __fastcall__ cbm_k_load (unsigned char flag, unsigned addr);
+; unsigned char __fastcall__ cbm_k_load (unsigned char flag, unsigned addr);
 ;
 
        .include        "cbm.inc"
@@ -17,9 +17,7 @@ _cbm_k_load:
        ldx     ptr1
        ldy     ptr1+1
        jsr     LOAD
-       ldx     #0
-       bcc     @Ok
-       inx
-       rts
-@Ok:   txa
-       rts
+       bcs     @NotOk
+       lda     #0
+@NotOk:        rts
+       
index 559f90771bf9b820eea4b6c4490a4646416a1428..c6c9d9270932f1e3039b7d2048a84718604f0933 100644 (file)
@@ -1,19 +1,15 @@
 ;
 ; Ullrich von Bassewitz, 03.06.1999
 ;
-; unsigned __fastcall__ cbm_open (void);
+; unsigned char __fastcall__ cbm_k_open (void);
 ;
 
        .include        "cbm.inc"
 
-               .export         _cbm_open
+               .export         _cbm_k_open
 
-_cbm_open:
+_cbm_k_open:
        jsr     OPEN
-       ldx     #0
-       bcc     @Ok
-       inx
-       rts
-@Ok:   txa
-       rts
-
+       bcs     @NotOk
+        lda     #0
+@NotOk:        rts
index bb1b42a3df67226120ec9d95ebd468dade78d5e6..4854ae25d36a2e01cf9c15f82fdbbcc6e3b1948d 100644 (file)
@@ -1,15 +1,11 @@
 ;
 ; Ullrich von Bassewitz, 03.06.1999
 ;
-; unsigned __fastcall__ cbm_readst (void);
+; unsigned char __fastcall__ cbm_k_readst (void);
 ;
 
        .include        "cbm.inc"
 
-               .export         _cbm_readst
-
-_cbm_readst:
-       jsr     READST
-       ldx     #0
-       rts
+               .export         _cbm_k_readst
 
+_cbm_k_readst = READST
index 901d1cd1a8998f0ca820013239ea3d9a907aa542..ec896d29a298e8f1e3426b53820ef0b05e437399 100644 (file)
@@ -1,7 +1,7 @@
 ;
 ; Marc 'BlackJack' Rintsch, 11.06.1999
 ;
-; unsigned __fastcall__ cbm_k_save(unsigned int start, unsigned int end);
+; unsigned char __fastcall__ cbm_k_save(unsigned int start, unsigned int end);
 ;
 
         .include        "cbm.inc"
@@ -20,9 +20,6 @@ _cbm_k_save:
         ldx     tmp1
         ldy     tmp1+1
         jsr     SAVE
-        ldx     #0
-        bcc     @Ok
-        inx
-        rts
-@Ok:    txa
-        rts
+       bcs     @NotOk
+        lda     #0
+@NotOk:        rts
diff --git a/libsrc/cbm/cbm_close.s b/libsrc/cbm/cbm_close.s
new file mode 100644 (file)
index 0000000..b00a5c7
--- /dev/null
@@ -0,0 +1,10 @@
+;
+; Marc 'BlackJack' Rintsch, 18.03.2001
+;
+; void __fastcall__ cbm_close (unsigned char lfn);
+;
+
+        .import _cbm_k_close
+        .export _cbm_close
+
+_cbm_close = _cbm_k_close
index 8dbd5b245bb84dc7b197262c3011be3925a14f78..7550746313a95f35bf0859e2cb821ff479239f26 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Marc 'BlackJack' Rintsch, 06.03.2001
  *
- * unsigned int cbm_load(const char* name, char device, unsigned int addr);
+ * unsigned char cbm_load(const char* name, char device, unsigned int addr);
  */
 
 #include <cbm.h>
@@ -9,12 +9,13 @@
 /* loads file "name" from given device to given address or to the load address
  * of the file if addr is 0
  */
-unsigned int cbm_load(const char* name, char device, unsigned int addr)
+unsigned char cbm_load(const char* name, unsigned char device,
+                       unsigned int addr)
 {
     /* LFN is set to 0 but it's not needed for loading.
      * (BASIC V2 sets it to the value of the SA for LOAD)
      */
-    cbm_k_setlfs(0, device, ((addr == 0) ? 1 : 0));
+    cbm_k_setlfs(0, device, addr == 0);
     cbm_k_setnam(name);
     return cbm_k_load(0, addr);
 }
diff --git a/libsrc/cbm/cbm_open.c b/libsrc/cbm/cbm_open.c
new file mode 100644 (file)
index 0000000..c47ecf2
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Marc 'BlackJack' Rintsch, 18.03.2001
+ *
+ * unsigned char cbm_open(unsigned char lfn, unsigned char device,
+ *                        unsigned char sec_addr, const char* name)
+ */
+#include <cbm.h>
+
+unsigned char cbm_open(unsigned char lfn, unsigned char device,
+                       unsigned char sec_addr, const char* name)
+{
+    cbm_k_setlfs(lfn, device, sec_addr);
+    cbm_k_setnam(name);
+    return cbm_k_open();
+}
diff --git a/libsrc/cbm/cbm_read.c b/libsrc/cbm/cbm_read.c
new file mode 100644 (file)
index 0000000..ce83bc9
--- /dev/null
@@ -0,0 +1,24 @@
+
+#include <cbm.h>
+
+extern unsigned char _oserror;
+
+int cbm_read(unsigned char lfn, void* buffer, unsigned int size)
+{
+    static unsigned int bytesread;
+    static unsigned char tmp;
+        
+    if (_oserror = cbm_k_chkin(lfn)) return -1;
+    
+    bytesread = 0;
+    
+    while (bytesread<size) {
+        tmp = cbm_k_basin();
+        if (cbm_k_readst()) break;
+        ((unsigned char*)buffer)[bytesread++] = tmp;
+    }
+    
+    cbm_k_clrch();
+    
+    return bytesread;
+}
index 7f756e766d43c18fa1aff2fb2c16c3033d1a9587..13843627efae342e948d833a8c23ea8abd79e1ad 100644 (file)
@@ -1,18 +1,20 @@
 /*
  * Marc 'BlackJack' Rintsch, 11.03.2001
  *
- * unsigned int cbm_save(const char* name,
- *                       char device,
- *                       unsigned int start,
- *                       unsigned int end);
+ * unsigned char cbm_save(const char* name,
+ *                        char device,
+ *                        unsigned int start,
+ *                        unsigned int end);
  */
 
 #include <cbm.h>
 
-unsigned int cbm_save(const char* name, char device,
-                      unsigned int start, unsigned int end)
+/* saves a memory area from start to end-1 to a file.
+ */
+unsigned char cbm_save(const char* name, unsigned char device,
+                       unsigned int start, unsigned int end)
 {
-   cbm_k_setlfs(0, device, 0);
-   cbm_k_setnam(name);
-   return cbm_k_save(start, end);
+    cbm_k_setlfs(0, device, 0);
+    cbm_k_setnam(name);
+    return cbm_k_save(start, end);
 }