From: mrintsch Date: Wed, 10 Oct 2001 20:35:07 +0000 (+0000) Subject: Changed the parameters of cbm_load and cbm_save to a more "C-like" way. X-Git-Tag: V2.12.0~2573 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=babcf84f17fc6d99113ee2bc2ed96b2bd4153174;p=cc65 Changed the parameters of cbm_load and cbm_save to a more "C-like" way. The API should be stable now. git-svn-id: svn://svn.cc65.org/cc65/trunk@1018 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/include/cbm.h b/include/cbm.h index c2ed28303..faff57db9 100644 --- a/include/cbm.h +++ b/include/cbm.h @@ -83,13 +83,19 @@ #define CH_INS 148 #define CH_ESC 95 - +/* constants to use with cbm_open() for opening a file for reading or + * writing without the need to append ",r" or ",w" to the filename. + * + * e.g.: cbm_open(2, 8, CBM_READ, "data,s"); + */ +#define CBM_READ 0 +#define CBM_WRITE 1 /* Kernel level functions */ void __fastcall__ cbm_k_setlfs (unsigned char LFN, unsigned char DEV, unsigned char SA); void __fastcall__ cbm_k_setnam (const char* Name); -unsigned char __fastcall__ cbm_k_load(unsigned char flag, unsigned addr); +unsigned int __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); @@ -110,17 +116,18 @@ void __fastcall__ cbm_k_clrch (void); -unsigned char cbm_load(const char* name, unsigned char device, - unsigned int addr); +unsigned int cbm_load(const char* name, unsigned char device, + const char* data); /* 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). + * address of the file if "data" is the null pointer (like load"name",8,1 + * in BASIC). + * Returns number of bytes that where loaded if loading was successful + * otherwise 0. "_oserror" contains an errorcode then (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. + unsigned char* data, unsigned int size); +/* Saves "size" bytes starting at "data" to a file. * Returns 0 if saving was successful, otherwise an errorcode (see table * below). */ diff --git a/libsrc/cbm/c_load.s b/libsrc/cbm/c_load.s index 4a767eab4..3424722db 100644 --- a/libsrc/cbm/c_load.s +++ b/libsrc/cbm/c_load.s @@ -1,12 +1,13 @@ ; ; Ullrich von Bassewitz, 03.06.1999 ; -; unsigned char __fastcall__ cbm_k_load (unsigned char flag, unsigned addr); +; unsigned int __fastcall__ cbm_k_load (unsigned char flag, unsigned addr); ; .include "cbm.inc" .export _cbm_k_load + .import __oserror .import popa .importzp ptr1 @@ -17,7 +18,14 @@ _cbm_k_load: ldx ptr1 ldy ptr1+1 jsr LOAD - bcs @NotOk - lda #0 -@NotOk: rts + bcc @Ok + sta __oserror + ldx ptr1 + ldy ptr1+1 +@Ok: txa + pha + tya + tax + pla + rts diff --git a/libsrc/cbm/cbm_load.c b/libsrc/cbm/cbm_load.c index cccc3279e..d136f139f 100644 --- a/libsrc/cbm/cbm_load.c +++ b/libsrc/cbm/cbm_load.c @@ -1,21 +1,22 @@ /* * Marc 'BlackJack' Rintsch, 06.03.2001 * - * unsigned char cbm_load(const char* name, char device, unsigned int addr); + * unsigned int cbm_load(const char* name, + * unsigned char device, + * const unsigned char* data); */ #include -#include /* loads file "name" from given device to given address or to the load address - * of the file if addr is 0 + * of the file if "data" is 0 */ -unsigned char cbm_load(const char* name, unsigned char device, - unsigned int addr) +unsigned int cbm_load(const char* name, unsigned char device, + const char* data) { /* 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); + cbm_k_setlfs(0, device, data == 0); cbm_k_setnam(name); - return _oserror = cbm_k_load(0, addr); + return (cbm_k_load(0, (unsigned int)data) - (unsigned int)data); } diff --git a/libsrc/cbm/cbm_save.c b/libsrc/cbm/cbm_save.c index 211ce41e3..5578dbdbd 100644 --- a/libsrc/cbm/cbm_save.c +++ b/libsrc/cbm/cbm_save.c @@ -3,8 +3,8 @@ * * unsigned char cbm_save(const char* name, * char device, - * unsigned int start, - * unsigned int end); + * unsigned char* data, + * unsigned int size); */ #include @@ -13,9 +13,10 @@ /* 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) + unsigned char* data, unsigned int size) { cbm_k_setlfs(0, device, 0); cbm_k_setnam(name); - return _oserror = cbm_k_save(start, end); + return _oserror = + cbm_k_save((unsigned int)data, ((unsigned int)data) + size); }