1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-17 05:31:45 +00:00

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
This commit is contained in:
mrintsch 2001-03-20 21:06:04 +00:00
parent 83f8ce6f39
commit fb76e97575
16 changed files with 157 additions and 70 deletions

View File

@ -98,17 +98,52 @@
void __fastcall__ cbm_k_setlfs (unsigned char LFN, unsigned char DEV, void __fastcall__ cbm_k_setlfs (unsigned char LFN, unsigned char DEV,
unsigned char SA); unsigned char SA);
void __fastcall__ cbm_k_setnam (const char* Name); void __fastcall__ cbm_k_setnam (const char* Name);
unsigned __fastcall__ cbm_k_load (unsigned char flag, unsigned addr); unsigned char __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_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 */ /* BASIC-like functions */
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);
unsigned int cbm_save(const char* name, char device, /* Loads file "name" from given device to given address or to the load address
unsigned int start, unsigned int end); * 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 */ /* End of cbm.h */
#endif #endif

View File

@ -11,14 +11,14 @@
%.o: %.s %.o: %.s
@$(AS) -g -o $@ $(AFLAGS) $< @$(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\ S_OBJS = ctype.o getenv.o gotoxy.o gotox.o gotoy.o where.o\
clock.o chline.o cvline.o cclear.o revers.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_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_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_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) all: $(C_OBJS) $(S_OBJS)

View File

@ -1,16 +1,11 @@
; ;
; Ullrich von Bassewitz, 03.06.1999 ; Ullrich von Bassewitz, 03.06.1999
; ;
; unsigned char __fastcall__ cbm_basin (void); ; unsigned char __fastcall__ cbm_k_basin (void);
; ;
.include "cbm.inc" .include "cbm.inc"
.export _cbm_basin .export _cbm_k_basin
_cbm_basin:
jsr BASIN
ldx #0
rts
_cbm_k_basin = BASIN

17
libsrc/cbm/c_chkin.s Normal file
View File

@ -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

View File

@ -1,14 +1,14 @@
; ;
; Ullrich von Bassewitz, 03.06.1999 ; 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" .include "cbm.inc"
.export _cbm_ckout .export _cbm_k_ckout
_cbm_ckout: _cbm_k_ckout:
tax tax
jsr CKOUT jsr CKOUT
ldx #0 ldx #0

View File

@ -1,14 +1,14 @@
; ;
; Ullrich von Bassewitz, 03.06.1999 ; Ullrich von Bassewitz, 03.06.1999
; ;
; void __fastcall__ cbm_close (unsigned char FN); ; void __fastcall__ cbm_k_close (unsigned char FN);
; ;
.include "cbm.inc" .include "cbm.inc"
.export _cbm_close .export _cbm_k_close
_cbm_close: _cbm_k_close:
clc clc
jmp CLOSE jmp CLOSE

View File

@ -1,12 +1,12 @@
; ;
; Ullrich von Bassewitz, 03.06.1999 ; Ullrich von Bassewitz, 03.06.1999
; ;
; void __fastcall__ cbm_clrch (void); ; void __fastcall__ cbm_k_clrch (void);
; ;
.include "cbm.inc" .include "cbm.inc"
.export _cbm_clrch .export _cbm_k_clrch
_cbm_clrch = CLRCH _cbm_k_clrch = CLRCH

View File

@ -1,7 +1,7 @@
; ;
; Ullrich von Bassewitz, 03.06.1999 ; 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" .include "cbm.inc"
@ -17,9 +17,7 @@ _cbm_k_load:
ldx ptr1 ldx ptr1
ldy ptr1+1 ldy ptr1+1
jsr LOAD jsr LOAD
ldx #0 bcs @NotOk
bcc @Ok lda #0
inx @NotOk: rts
rts
@Ok: txa
rts

View File

@ -1,19 +1,15 @@
; ;
; Ullrich von Bassewitz, 03.06.1999 ; Ullrich von Bassewitz, 03.06.1999
; ;
; unsigned __fastcall__ cbm_open (void); ; unsigned char __fastcall__ cbm_k_open (void);
; ;
.include "cbm.inc" .include "cbm.inc"
.export _cbm_open .export _cbm_k_open
_cbm_open: _cbm_k_open:
jsr OPEN jsr OPEN
ldx #0 bcs @NotOk
bcc @Ok lda #0
inx @NotOk: rts
rts
@Ok: txa
rts

View File

@ -1,15 +1,11 @@
; ;
; Ullrich von Bassewitz, 03.06.1999 ; Ullrich von Bassewitz, 03.06.1999
; ;
; unsigned __fastcall__ cbm_readst (void); ; unsigned char __fastcall__ cbm_k_readst (void);
; ;
.include "cbm.inc" .include "cbm.inc"
.export _cbm_readst .export _cbm_k_readst
_cbm_readst:
jsr READST
ldx #0
rts
_cbm_k_readst = READST

View File

@ -1,7 +1,7 @@
; ;
; Marc 'BlackJack' Rintsch, 11.06.1999 ; 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" .include "cbm.inc"
@ -20,9 +20,6 @@ _cbm_k_save:
ldx tmp1 ldx tmp1
ldy tmp1+1 ldy tmp1+1
jsr SAVE jsr SAVE
ldx #0 bcs @NotOk
bcc @Ok lda #0
inx @NotOk: rts
rts
@Ok: txa
rts

10
libsrc/cbm/cbm_close.s Normal file
View File

@ -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

View File

@ -1,7 +1,7 @@
/* /*
* Marc 'BlackJack' Rintsch, 06.03.2001 * 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> #include <cbm.h>
@ -9,12 +9,13 @@
/* loads file "name" from given device to given address or to the load address /* 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 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. /* 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) ? 1 : 0)); cbm_k_setlfs(0, device, addr == 0);
cbm_k_setnam(name); cbm_k_setnam(name);
return cbm_k_load(0, addr); return cbm_k_load(0, addr);
} }

16
libsrc/cbm/cbm_open.c Normal file
View File

@ -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 <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();
}

24
libsrc/cbm/cbm_read.c Normal file
View File

@ -0,0 +1,24 @@
#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;
}

View File

@ -1,18 +1,20 @@
/* /*
* Marc 'BlackJack' Rintsch, 11.03.2001 * Marc 'BlackJack' Rintsch, 11.03.2001
* *
* unsigned int cbm_save(const char* name, * unsigned char cbm_save(const char* name,
* char device, * char device,
* unsigned int start, * unsigned int start,
* unsigned int end); * unsigned int end);
*/ */
#include <cbm.h> #include <cbm.h>
unsigned int cbm_save(const char* name, char device, /* saves a memory area from start to end-1 to a file.
unsigned int start, unsigned int end) */
unsigned char cbm_save(const char* name, unsigned char device,
unsigned int start, unsigned int end)
{ {
cbm_k_setlfs(0, device, 0); cbm_k_setlfs(0, device, 0);
cbm_k_setnam(name); cbm_k_setnam(name);
return cbm_k_save(start, end); return cbm_k_save(start, end);
} }