mirror of
https://github.com/cc65/cc65.git
synced 2025-01-14 16:33: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:
parent
2d77e8b35f
commit
b2e0ed603e
@ -104,26 +104,36 @@ unsigned char __fastcall__ cbm_k_open (void);
|
|||||||
void __fastcall__ cbm_k_close (unsigned char FN);
|
void __fastcall__ cbm_k_close (unsigned char FN);
|
||||||
unsigned char __fastcall__ cbm_k_readst (void);
|
unsigned char __fastcall__ cbm_k_readst (void);
|
||||||
unsigned char __fastcall__ cbm_k_chkin (unsigned char FN);
|
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);
|
unsigned char __fastcall__ cbm_k_basin (void);
|
||||||
|
void __fastcall__ cbm_k_bsout (unsigned char C);
|
||||||
void __fastcall__ cbm_k_clrch (void);
|
void __fastcall__ cbm_k_clrch (void);
|
||||||
|
|
||||||
/* BASIC-like functions */
|
/* 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
|
* All cbm_* IO functions set extern unsigned char _oserror in case
|
||||||
* of the file if addr is 0 (like load"name",8,1 in BASIC)
|
* of an error. For the meaning of the errorcode see the table below.
|
||||||
* Returns 0 if loading was successful otherwise an errorcode (see 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 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.
|
/* 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 cbm_open(unsigned char lfn, unsigned char device,
|
||||||
unsigned char sec_addr, const char* name);
|
unsigned char sec_addr, const char* name);
|
||||||
/* Opens a file. Works just like the BASIC command.
|
/* 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);
|
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);
|
int cbm_read(unsigned char lfn, void* buffer, unsigned int size);
|
||||||
/* Reads up to "size" bytes from a file to "buffer".
|
/* 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)
|
* Returns the number of actually read bytes, 0 if there are no bytes left
|
||||||
* or -1 in case of an error. _oserror contains an errorcode then (see table below).
|
* (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:
|
/* Errorcodes of cbm_* I/O functions:
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
%.o: %.s
|
%.o: %.s
|
||||||
@$(AS) -g -o $@ $(AFLAGS) $<
|
@$(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\
|
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\
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
;
|
;
|
||||||
; Ullrich von Bassewitz, 03.06.1999
|
; Ullrich von Bassewitz, 03.06.1999
|
||||||
;
|
;
|
||||||
; void __fastcall__ cbm_bsout (unsigned char C);
|
; void __fastcall__ cbm_k_bsout (unsigned char C);
|
||||||
;
|
;
|
||||||
|
|
||||||
.include "cbm.inc"
|
.include "cbm.inc"
|
||||||
|
|
||||||
.export _cbm_bsout
|
.export _cbm_k_bsout
|
||||||
|
|
||||||
_cbm_bsout = BSOUT
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
_cbm_k_bsout = BSOUT
|
||||||
|
@ -11,14 +11,6 @@
|
|||||||
_cbm_k_ckout:
|
_cbm_k_ckout:
|
||||||
tax
|
tax
|
||||||
jsr CKOUT
|
jsr CKOUT
|
||||||
ldx #0
|
bcs @NotOk
|
||||||
bcc @Ok
|
lda #0
|
||||||
inx
|
@NotOk: rts
|
||||||
rts
|
|
||||||
@Ok: txa
|
|
||||||
rts
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include <cbm.h>
|
#include <cbm.h>
|
||||||
|
|
||||||
|
extern unsigned char _oserror;
|
||||||
|
|
||||||
/* 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
|
||||||
*/
|
*/
|
||||||
@ -13,9 +15,8 @@ unsigned char cbm_load(const char* name, unsigned char device,
|
|||||||
unsigned int addr)
|
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);
|
cbm_k_setlfs(0, device, addr == 0);
|
||||||
cbm_k_setnam(name);
|
cbm_k_setnam(name);
|
||||||
return cbm_k_load(0, addr);
|
return _oserror = cbm_k_load(0, addr);
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,19 @@
|
|||||||
* Marc 'BlackJack' Rintsch, 18.03.2001
|
* Marc 'BlackJack' Rintsch, 18.03.2001
|
||||||
*
|
*
|
||||||
* unsigned char cbm_open(unsigned char lfn, unsigned char device,
|
* 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>
|
#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 cbm_open(unsigned char lfn, unsigned char device,
|
||||||
unsigned char sec_addr, const char* name)
|
unsigned char sec_addr, const char* name)
|
||||||
{
|
{
|
||||||
cbm_k_setlfs(lfn, device, sec_addr);
|
cbm_k_setlfs(lfn, device, sec_addr);
|
||||||
cbm_k_setnam(name);
|
cbm_k_setnam(name);
|
||||||
return cbm_k_open();
|
return _oserror = cbm_k_open();
|
||||||
}
|
}
|
||||||
|
@ -13,17 +13,23 @@ int cbm_read(unsigned char lfn, void* buffer, unsigned int size)
|
|||||||
static unsigned int bytesread;
|
static unsigned int bytesread;
|
||||||
static unsigned char tmp;
|
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;
|
if (_oserror = cbm_k_chkin(lfn)) return -1;
|
||||||
|
|
||||||
bytesread = 0;
|
bytesread = 0;
|
||||||
|
|
||||||
while (bytesread<size && !cbm_k_readst()) {
|
while (bytesread<size && !cbm_k_readst()) {
|
||||||
tmp = cbm_k_basin();
|
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;
|
if (cbm_k_readst() & 0xBF) break;
|
||||||
|
|
||||||
((unsigned char*)buffer)[bytesread++] = tmp;
|
((unsigned char*)buffer)[bytesread++] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
cbm_k_clrch();
|
cbm_k_clrch();
|
||||||
|
|
||||||
return bytesread;
|
return bytesread;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include <cbm.h>
|
#include <cbm.h>
|
||||||
|
|
||||||
|
extern unsigned char _oserror;
|
||||||
|
|
||||||
/* saves a memory area from start to end-1 to a file.
|
/* saves a memory area from start to end-1 to a file.
|
||||||
*/
|
*/
|
||||||
unsigned char cbm_save(const char* name, unsigned char device,
|
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_setlfs(0, device, 0);
|
||||||
cbm_k_setnam(name);
|
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
32
libsrc/cbm/cbm_write.c
Normal 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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user