From: mrintsch Date: Fri, 30 Mar 2001 18:18:40 +0000 (+0000) Subject: cbm_write() added X-Git-Tag: V2.12.0~2880 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b2e0ed603efcdc8719d3f73ca6692b22cd31c71d;p=cc65 cbm_write() added changed/added some comments all cbm_* IO functions are using _oserror now git-svn-id: svn://svn.cc65.org/cc65/trunk@682 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/include/cbm.h b/include/cbm.h index b26673e1c..e80145efe 100644 --- a/include/cbm.h +++ b/include/cbm.h @@ -104,26 +104,36 @@ 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_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); @@ -131,8 +141,15 @@ 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: diff --git a/libsrc/cbm/Makefile b/libsrc/cbm/Makefile index 5bc350402..a4222f2d6 100644 --- a/libsrc/cbm/Makefile +++ b/libsrc/cbm/Makefile @@ -11,7 +11,7 @@ %.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\ diff --git a/libsrc/cbm/c_bsout.s b/libsrc/cbm/c_bsout.s index a2c682b1c..9bb0430cd 100644 --- a/libsrc/cbm/c_bsout.s +++ b/libsrc/cbm/c_bsout.s @@ -1,14 +1,11 @@ ; ; 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 diff --git a/libsrc/cbm/c_ckout.s b/libsrc/cbm/c_ckout.s index f239727cb..148619d6b 100644 --- a/libsrc/cbm/c_ckout.s +++ b/libsrc/cbm/c_ckout.s @@ -11,14 +11,6 @@ _cbm_k_ckout: tax jsr CKOUT - ldx #0 - bcc @Ok - inx - rts -@Ok: txa - rts - - - - - + bcs @NotOk + lda #0 +@NotOk: rts diff --git a/libsrc/cbm/cbm_load.c b/libsrc/cbm/cbm_load.c index 755074631..283a4512d 100644 --- a/libsrc/cbm/cbm_load.c +++ b/libsrc/cbm/cbm_load.c @@ -6,6 +6,8 @@ #include +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 */ @@ -13,9 +15,8 @@ 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) - */ + * (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); } diff --git a/libsrc/cbm/cbm_open.c b/libsrc/cbm/cbm_open.c index c47ecf267..c63ac8ab8 100644 --- a/libsrc/cbm/cbm_open.c +++ b/libsrc/cbm/cbm_open.c @@ -2,15 +2,19 @@ * 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 +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(); } diff --git a/libsrc/cbm/cbm_read.c b/libsrc/cbm/cbm_read.c index 1efd203a6..23be7315c 100644 --- a/libsrc/cbm/cbm_read.c +++ b/libsrc/cbm/cbm_read.c @@ -12,18 +12,24 @@ int cbm_read(unsigned char lfn, void* buffer, unsigned int size) { 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 +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, @@ -16,5 +18,5 @@ 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); } diff --git a/libsrc/cbm/cbm_write.c b/libsrc/cbm/cbm_write.c new file mode 100644 index 000000000..b204b68ee --- /dev/null +++ b/libsrc/cbm/cbm_write.c @@ -0,0 +1,32 @@ +/* + * Marc 'BlackJack' Rintsch, 25.03.2001 + * + * int cbm_write(unsigned char lfn, void* buffer, unsigned int size); + */ + +#include + +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