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
-
-
-
%.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)
;
; 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
--- /dev/null
+;
+; 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
+
;
; 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
;
; 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
;
; 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
;
; 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"
ldx ptr1
ldy ptr1+1
jsr LOAD
- ldx #0
- bcc @Ok
- inx
- rts
-@Ok: txa
- rts
+ bcs @NotOk
+ lda #0
+@NotOk: rts
+
;
; 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
;
; 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
;
; 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"
ldx tmp1
ldy tmp1+1
jsr SAVE
- ldx #0
- bcc @Ok
- inx
- rts
-@Ok: txa
- rts
+ bcs @NotOk
+ lda #0
+@NotOk: rts
--- /dev/null
+;
+; 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
/*
* 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>
/* 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);
}
--- /dev/null
+/*
+ * 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();
+}
--- /dev/null
+
+#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;
+}
/*
* 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);
}