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_ckout (unsigned char FN);
unsigned char __fastcall__ cbm_k_basin (void);
+void __fastcall__ cbm_k_bsout (unsigned char C);
void __fastcall__ cbm_k_clrch (void);
-/* BASIC-like functions */
-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).
+/* BASIC-like functions
+ *
+ * All cbm_* IO functions set extern unsigned char _oserror in case
+ * of an error. For the meaning of the errorcode see the table below.
+ */
+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);
+ 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).
+ * 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).
+ * Returns 0 if opening was successful, otherwise an errorcode (see table
+ * below).
*/
void __fastcall__ cbm_close (unsigned char lfn);
int cbm_read(unsigned char lfn, void* buffer, unsigned int size);
/* Reads up to "size" bytes from a file to "buffer".
- * Returns the number of actually read bytes, 0 if there are no bytes left (EOF)
- * or -1 in case of an error. _oserror contains an errorcode then (see table below).
+ * Returns the number of actually read bytes, 0 if there are no bytes left
+ * (EOF) or -1 in case of an error. _oserror contains an errorcode then (see
+ * table below).
+ */
+
+int cbm_write(unsigned char lfn, void* buffer, unsigned int size);
+/* Writes up to "size" bytes from "buffer" to a file.
+ * Returns the number of actually written bytes or -1 in case of an error.
+ * _oserror contains an errorcode then (see table below).
*/
/* Errorcodes of cbm_* I/O functions:
%.o: %.s
@$(AS) -g -o $@ $(AFLAGS) $<
-C_OBJS = cbm_load.o cbm_save.o cbm_open.o cbm_read.o
+C_OBJS = cbm_load.o cbm_save.o cbm_open.o cbm_read.o cbm_write.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\
;
; Ullrich von Bassewitz, 03.06.1999
;
-; void __fastcall__ cbm_bsout (unsigned char C);
+; void __fastcall__ cbm_k_bsout (unsigned char C);
;
.include "cbm.inc"
- .export _cbm_bsout
-
-_cbm_bsout = BSOUT
-
-
+ .export _cbm_k_bsout
+_cbm_k_bsout = BSOUT
_cbm_k_ckout:
tax
jsr CKOUT
- ldx #0
- bcc @Ok
- inx
- rts
-@Ok: txa
- rts
-
-
-
-
-
+ bcs @NotOk
+ lda #0
+@NotOk: rts
#include <cbm.h>
+extern unsigned char _oserror;
+
/* loads file "name" from given device to given address or to the load address
* of the file if addr is 0
*/
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)
- */
+ * (BASIC V2 sets it to the value of the SA for LOAD) */
cbm_k_setlfs(0, device, addr == 0);
cbm_k_setnam(name);
- return cbm_k_load(0, addr);
+ return _oserror = cbm_k_load(0, addr);
}
* Marc 'BlackJack' Rintsch, 18.03.2001
*
* unsigned char cbm_open(unsigned char lfn, unsigned char device,
- * unsigned char sec_addr, const char* name)
+ * unsigned char sec_addr, const char* name);
*/
#include <cbm.h>
+extern unsigned char _oserror;
+
+/* It's like BASIC's: OPEN lfn, device, sec_addr, "name"
+ */
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();
+ return _oserror = cbm_k_open();
}
{
static unsigned int bytesread;
static unsigned char tmp;
-
+
+ /* if we can't change to the inputchannel #lfn then return an error */
if (_oserror = cbm_k_chkin(lfn)) return -1;
bytesread = 0;
-
+
while (bytesread<size && !cbm_k_readst()) {
tmp = cbm_k_basin();
+
+ /* the kernal routine BASIN sets ST to EOF if the end of file
+ * is reached the first time, then we have store tmp.
+ * every subsequent call returns EOF and READ ERROR in ST, then
+ * we have to exit the loop here immidiatly. */
if (cbm_k_readst() & 0xBF) break;
+
((unsigned char*)buffer)[bytesread++] = tmp;
}
cbm_k_clrch();
-
return bytesread;
}
#include <cbm.h>
+extern unsigned char _oserror;
+
/* saves a memory area from start to end-1 to a file.
*/
unsigned char cbm_save(const char* name, unsigned char device,
{
cbm_k_setlfs(0, device, 0);
cbm_k_setnam(name);
- return cbm_k_save(start, end);
+ return _oserror = cbm_k_save(start, end);
}
--- /dev/null
+/*
+ * Marc 'BlackJack' Rintsch, 25.03.2001
+ *
+ * int cbm_write(unsigned char lfn, void* buffer, unsigned int size);
+ */
+
+#include <cbm.h>
+
+extern unsigned char _oserror;
+
+int cbm_write(unsigned char lfn, void* buffer, unsigned int size) {
+
+ static unsigned int byteswritten;
+
+ /* if we can't change to the outputchannel #lfn then return an error */
+ if (_oserror = cbm_k_ckout(lfn)) return -1;
+
+ byteswritten = 0;
+
+ while (byteswritten<size && !cbm_k_readst()) {
+ cbm_k_bsout(((unsigned char*)buffer)[byteswritten++]);
+ }
+
+ if (cbm_k_readst()) {
+ _oserror = 5; /* device not present */
+ byteswritten = -1;
+ }
+
+ cbm_k_clrch();
+
+ return byteswritten;
+}