From fb76e97575be53a5e540b224b059c04aa2390075 Mon Sep 17 00:00:00 2001 From: mrintsch Date: Tue, 20 Mar 2001 21:06:04 +0000 Subject: [PATCH] Added comments to cbm.h. 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 --- include/cbm.h | 51 +++++++++++++++++++++++++++++++++++------- libsrc/cbm/Makefile | 4 ++-- libsrc/cbm/c_basin.s | 11 +++------ libsrc/cbm/c_chkin.s | 17 ++++++++++++++ libsrc/cbm/c_ckout.s | 6 ++--- libsrc/cbm/c_close.s | 6 ++--- libsrc/cbm/c_clrch.s | 6 ++--- libsrc/cbm/c_load.s | 12 +++++----- libsrc/cbm/c_open.s | 16 +++++-------- libsrc/cbm/c_readst.s | 10 +++------ libsrc/cbm/c_save.s | 11 ++++----- libsrc/cbm/cbm_close.s | 10 +++++++++ libsrc/cbm/cbm_load.c | 7 +++--- libsrc/cbm/cbm_open.c | 16 +++++++++++++ libsrc/cbm/cbm_read.c | 24 ++++++++++++++++++++ libsrc/cbm/cbm_save.c | 20 +++++++++-------- 16 files changed, 157 insertions(+), 70 deletions(-) create mode 100644 libsrc/cbm/c_chkin.s create mode 100644 libsrc/cbm/cbm_close.s create mode 100644 libsrc/cbm/cbm_open.c create mode 100644 libsrc/cbm/cbm_read.c diff --git a/include/cbm.h b/include/cbm.h index bc787241f..80ad0de0b 100644 --- a/include/cbm.h +++ b/include/cbm.h @@ -98,17 +98,52 @@ 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 - - - diff --git a/libsrc/cbm/Makefile b/libsrc/cbm/Makefile index 410ab112d..3a184fe70 100644 --- a/libsrc/cbm/Makefile +++ b/libsrc/cbm/Makefile @@ -11,14 +11,14 @@ %.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) diff --git a/libsrc/cbm/c_basin.s b/libsrc/cbm/c_basin.s index 281f433ef..a852b6c5b 100644 --- a/libsrc/cbm/c_basin.s +++ b/libsrc/cbm/c_basin.s @@ -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 index 000000000..4febff74c --- /dev/null +++ b/libsrc/cbm/c_chkin.s @@ -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 + diff --git a/libsrc/cbm/c_ckout.s b/libsrc/cbm/c_ckout.s index 7fffe9f70..f239727cb 100644 --- a/libsrc/cbm/c_ckout.s +++ b/libsrc/cbm/c_ckout.s @@ -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 diff --git a/libsrc/cbm/c_close.s b/libsrc/cbm/c_close.s index 72cbded77..e2a559cc4 100644 --- a/libsrc/cbm/c_close.s +++ b/libsrc/cbm/c_close.s @@ -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 diff --git a/libsrc/cbm/c_clrch.s b/libsrc/cbm/c_clrch.s index ba76b588a..632a9e2b2 100644 --- a/libsrc/cbm/c_clrch.s +++ b/libsrc/cbm/c_clrch.s @@ -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 diff --git a/libsrc/cbm/c_load.s b/libsrc/cbm/c_load.s index 14b92917c..4a767eab4 100644 --- a/libsrc/cbm/c_load.s +++ b/libsrc/cbm/c_load.s @@ -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 + diff --git a/libsrc/cbm/c_open.s b/libsrc/cbm/c_open.s index 559f90771..c6c9d9270 100644 --- a/libsrc/cbm/c_open.s +++ b/libsrc/cbm/c_open.s @@ -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 diff --git a/libsrc/cbm/c_readst.s b/libsrc/cbm/c_readst.s index bb1b42a3d..4854ae25d 100644 --- a/libsrc/cbm/c_readst.s +++ b/libsrc/cbm/c_readst.s @@ -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 diff --git a/libsrc/cbm/c_save.s b/libsrc/cbm/c_save.s index 901d1cd1a..ec896d29a 100644 --- a/libsrc/cbm/c_save.s +++ b/libsrc/cbm/c_save.s @@ -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 index 000000000..b00a5c7a5 --- /dev/null +++ b/libsrc/cbm/cbm_close.s @@ -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 diff --git a/libsrc/cbm/cbm_load.c b/libsrc/cbm/cbm_load.c index 8dbd5b245..755074631 100644 --- a/libsrc/cbm/cbm_load.c +++ b/libsrc/cbm/cbm_load.c @@ -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 @@ -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 index 000000000..c47ecf267 --- /dev/null +++ b/libsrc/cbm/cbm_open.c @@ -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 + +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 index 000000000..ce83bc91e --- /dev/null +++ b/libsrc/cbm/cbm_read.c @@ -0,0 +1,24 @@ + +#include + +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 -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); } -- 2.39.5