1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-26 08:32:00 +00:00

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
This commit is contained in:
mrintsch 2001-03-30 18:18:40 +00:00
parent 2d77e8b35f
commit b2e0ed603e
9 changed files with 88 additions and 37 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -6,6 +6,8 @@
#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
*/
@ -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);
}

View File

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

View File

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

View File

@ -9,6 +9,8 @@
#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,
@ -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);
}

32
libsrc/cbm/cbm_write.c Normal file
View File

@ -0,0 +1,32 @@
/*
* 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;
}