From 574ac2393b3c0704e573dfcfd361ca408b235471 Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 22 Jun 2002 10:58:24 +0000 Subject: [PATCH] Rewrote cbm_open and cbm_read in assembler saving about 80 bytes total. git-svn-id: svn://svn.cc65.org/cc65/trunk@1318 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/cbm/.cvsignore | 2 - libsrc/cbm/Makefile | 47 +++++++++++++++--- libsrc/cbm/c_open.s | 3 +- libsrc/cbm/cbm_open.c | 19 -------- libsrc/cbm/cbm_open.s | 44 +++++++++++++++++ libsrc/cbm/cbm_read.c | 34 ------------- libsrc/cbm/cbm_read.s | 111 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 196 insertions(+), 64 deletions(-) delete mode 100644 libsrc/cbm/cbm_open.c create mode 100644 libsrc/cbm/cbm_open.s delete mode 100644 libsrc/cbm/cbm_read.c create mode 100644 libsrc/cbm/cbm_read.s diff --git a/libsrc/cbm/.cvsignore b/libsrc/cbm/.cvsignore index 1de83fbdb..47de2da60 100644 --- a/libsrc/cbm/.cvsignore +++ b/libsrc/cbm/.cvsignore @@ -1,5 +1,3 @@ cbm_load.s -cbm_open.s -cbm_read.s cbm_save.s cbm_write.s diff --git a/libsrc/cbm/Makefile b/libsrc/cbm/Makefile index a4222f2d6..316f06da5 100644 --- a/libsrc/cbm/Makefile +++ b/libsrc/cbm/Makefile @@ -11,14 +11,45 @@ %.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) diff --git a/libsrc/cbm/c_open.s b/libsrc/cbm/c_open.s index c6c9d9270..23577f9d4 100644 --- a/libsrc/cbm/c_open.s +++ b/libsrc/cbm/c_open.s @@ -12,4 +12,5 @@ _cbm_k_open: jsr OPEN bcs @NotOk lda #0 -@NotOk: rts +@NotOk: ldx #0 ; Clear high byte + rts diff --git a/libsrc/cbm/cbm_open.c b/libsrc/cbm/cbm_open.c deleted file mode 100644 index 242628ee1..000000000 --- a/libsrc/cbm/cbm_open.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Marc 'BlackJack' Rintsch, 18.03.2001 - * - * unsigned char cbm_open(unsigned char lfn, unsigned char device, - * unsigned char sec_addr, const char* name); - */ - -#include -#include - -/* 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(); -} diff --git a/libsrc/cbm/cbm_open.s b/libsrc/cbm/cbm_open.s new file mode 100644 index 000000000..055df9b42 --- /dev/null +++ b/libsrc/cbm/cbm_open.s @@ -0,0 +1,44 @@ +; +; 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 + + diff --git a/libsrc/cbm/cbm_read.c b/libsrc/cbm/cbm_read.c deleted file mode 100644 index f0011284b..000000000 --- a/libsrc/cbm/cbm_read.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Marc 'BlackJack' Rintsch, 19.03.2001 - * - * int cbm_read(unsigned char lfn, void* buffer, unsigned int size); - */ - -#include -#include - -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