cbm_load.s
-cbm_open.s
-cbm_read.s
cbm_save.s
cbm_write.s
%.o: %.s
@$(AS) -g -o $@ $(AFLAGS) $<
-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\
- 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 cbm_close.o c_chkin.o
+C_OBJS = cbm_load.o \
+ cbm_save.o \
+ cbm_write.o
+
+S_OBJS = c_acptr.o \
+ c_basin.o \
+ c_bsout.o \
+ c_chkin.o \
+ c_ciout.o \
+ c_ckout.o \
+ c_clall.o \
+ c_close.o \
+ c_clrch.o \
+ c_iobase.o \
+ c_listen.o \
+ c_load.o \
+ c_open.o \
+ c_readst.o \
+ c_save.o \
+ c_setlfs.o \
+ c_setnam.o \
+ c_talk.o \
+ c_unlsn.o \
+ c_untlk.o \
+ cbm_close.o \
+ cbm_open.o \
+ cbm_read.o \
+ cclear.o \
+ chline.o \
+ clock.o \
+ ctype.o \
+ cvline.o \
+ getenv.o \
+ gotox.o \
+ gotoxy.o \
+ gotoy.o \
+ oserror.o \
+ revers.o \
+ where.o
all: $(C_OBJS) $(S_OBJS)
jsr OPEN
bcs @NotOk
lda #0
-@NotOk: rts
+@NotOk: ldx #0 ; Clear high byte
+ rts
+++ /dev/null
-/*
- * 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>
-#include <errno.h>
-
-/* 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 _oserror = cbm_k_open();
-}
--- /dev/null
+;
+; Ullrich von Bassewitz, 22.06.2002
+;
+; Original C code by Marc 'BlackJack' Rintsch, 18.03.2001
+;
+; unsigned char __fastcall__ 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).
+; */
+; {
+; cbm_k_setlfs(lfn, device, sec_addr);
+; cbm_k_setnam(name);
+; return _oserror = cbm_k_open();
+; }
+;
+
+ .export _cbm_open
+ .import popa
+ .import _cbm_k_setlfs, _cbm_k_setnam, _cbm_k_open
+ .import __oserror
+
+_cbm_open:
+ pha
+ txa
+ pha ; Save name
+
+ jsr popa ; Get sec_addr
+ jsr _cbm_k_setlfs ; Call SETLFS, pop all args
+
+ pla
+ tax
+ pla ; Get name
+ jsr _cbm_k_setnam
+
+ jsr _cbm_k_open
+ sta __oserror
+
+ rts
+
+
+++ /dev/null
-/*
- * Marc 'BlackJack' Rintsch, 19.03.2001
- *
- * int cbm_read(unsigned char lfn, void* buffer, unsigned int size);
- */
-
-#include <cbm.h>
-#include <errno.h>
-
-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;
-}
--- /dev/null
+;
+; Ullrich von Bassewitz, 22.06.2002
+;
+; Original C code by Marc 'BlackJack' Rintsch, 19.03.2001
+;
+; int __fastcall__ 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).
+; */
+; {
+; 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;
+; }
+;
+
+ .include "cbm.inc"
+
+ .export _cbm_read
+ .importzp ptr1, ptr2, ptr3, tmp1
+ .import popax, popa
+ .import __oserror
+
+_cbm_read:
+ eor #$FF
+ sta ptr1
+ txa
+ eor #$FF
+ sta ptr1+1 ; Save -size-1
+
+ jsr popax
+ sta ptr2
+ stx ptr2+1 ; Save buffer
+
+ jsr popa
+ tax
+ jsr CHKIN
+ bcs @E1 ; Branch on error
+
+; bytesread = 0;
+
+ lda #$00
+ sta ptr3
+ sta ptr3+1
+ beq @L3 ; Branch always
+
+; Loop
+
+@L1: jsr READST
+ cmp #0 ; Status ok?
+ bne @L4
+
+ jsr BASIN ; Read next char from file
+ sta tmp1 ; Save it for later
+
+ jsr READST
+ and #$BF
+ bne @L4
+
+ lda tmp1
+ ldy #0
+ sta (ptr2),y ; Save read byte
+
+ inc ptr2
+ bne @L2
+ inc ptr2+1 ; ++buffer;
+
+@L2: inc ptr3
+ bne @L3
+ inc ptr3+1 ; ++bytesread;
+
+@L3: inc ptr1
+ bne @L1
+ inc ptr1+1
+ bne @L1
+
+@L4: jsr CLRCH
+
+ lda ptr3
+ ldx ptr3+1 ; return bytesread;
+
+ rts
+
+; CHKIN failed
+
+@E1: sta __oserror
+ lda #$FF
+ tax
+ rts ; return -1
+