Skip to content

Commit

Permalink
rc2014 acia - optimisedtx
Browse files Browse the repository at this point in the history
  • Loading branch information
feilipu committed Jan 17, 2017
1 parent 55cb012 commit 1624e45
Show file tree
Hide file tree
Showing 217 changed files with 22,755 additions and 22,745 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
ld a, (aciaControl) ; get the ACIA control echo byte
and ~ACIA_TEI_MASK ; mask out the Tx interrupt bits
or ACIA_TDI_RTS0 ; set RTS low.
ld (aciaControl), a ; write the ACIA control echo byte back
ld (aciaControl), a ; write the ACIA control echo byte back
out (ACIA_CTRL_ADDR), a ; set the ACIA CTRL register
call asm_z80_pop_ei ; critical section end
Expand Down
16 changes: 6 additions & 10 deletions libsrc/_DEVELOPMENT/target/rc2014/device/acia/acia_interrupt.asm
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,28 @@
jr z, tx_check ; if not, go check for bytes to transmit

in a, (ACIA_DATA_ADDR) ; Get the received byte from the ACIA
push af
ld l, a ; Move Rx byte to l

ld a, (aciaRxCount) ; Get the number of bytes in the Rx buffer
cp ACIA_RX_SIZE ; check whether there is space in the buffer
jr c, poke_rx ; not full, so go poke Rx byte
pop af ; buffer full so drop the Rx byte
jr tx_check ; check if we can send something

poke_rx:
jr nc, tx_check ; buffer full, check if we can send something

ld a, l ; get Rx byte from l
ld hl, (aciaRxIn) ; get the pointer to where we poke
pop af ; get Rx byte
ld (hl), a ; write the Rx byte to the aciaRxIn
ld (hl), a ; write the Rx byte to the aciaRxIn address

inc hl ; move the Rx pointer along
ld a, l ; move low byte of the Rx pointer
cp (aciaRxBuffer + ACIA_RX_SIZE) & $FF
jr nz, no_rx_wrap
ld hl, aciaRxBuffer ; we wrapped, so go back to start of buffer

no_rx_wrap:

ld (aciaRxIn), hl ; write where the next byte should be poked

ld hl, aciaRxCount
inc (hl) ; atomically increment Rx count
inc (hl) ; atomically increment Rx buffer count

; now start doing the Tx stuff

Expand Down
22 changes: 18 additions & 4 deletions libsrc/_DEVELOPMENT/target/rc2014/device/acia/acia_putc.asm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

PUBLIC _acia_putc
EXTERN ACIA_TX_SIZE
EXTERN ACIA_TEI_MASK, ACIA_TEI_RTS0, ACIA_CTRL_ADDR
EXTERN ACIA_STATUS_ADDR, ACIA_RDRF, ACIA_DATA_ADDR, ACIA_TX_SIZE
EXTERN ACIA_TDRE, ACIA_TX_SIZE, ACIA_TEI_MASK, ACIA_TEI_RTS0, ACIA_CTRL_ADDR

EXTERN aciaTxCount, aciaTxIn, aciaTxBuffer, aciaControl
EXTERN asm_z80_push_di, asm_z80_pop_ei
Expand All @@ -17,15 +17,29 @@
; carry reset
; modifies : af, hl

ld a, (aciaTxCount) ; Get the number of bytes in the Tx buffer
or a ; check whether the buffer is empty
jr nz, put_buffer_tx ; buffer not empty, so abandon immediate Tx
in a, (ACIA_STATUS_ADDR) ; get the status of the ACIA
and ACIA_TDRE ; check whether a byte can be transmitted
jr z, put_buffer_tx ; if not, so abandon immediate Tx
ld a, l ; Retrieve Tx character
out (ACIA_DATA_ADDR), a ; immediately output the Tx byte to the ACIA

ld l, 0 ; indicate Tx buffer was not full
ret ; and just complete

put_buffer_tx:

ld a, (aciaTxCount) ; Get the number of bytes in the Tx buffer
cp ACIA_TX_SIZE ; check whether there is space in the buffer
ld a,l ; Tx byte

ld l,1
jr nc, clean_up_tx ; buffer full, so drop the Tx byte and clean up

put_poke_tx:

ld hl, (aciaTxIn) ; get the pointer to where we poke
ld (hl), a ; write the Tx byte to the aciaTxIn
inc hl ; move the Tx pointer along
Expand Down
80 changes: 40 additions & 40 deletions libsrc/fcntl/gen_rnd/close.c
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
/*
* Close a file
* Stefano Bodrato - 2013
*
* int close(int handle)
* (write the current block and the control block amd free memory)
*
* $Id: close.c,v 1.2 2014-01-20 09:15:31 stefano Exp $
*/

#include <fcntl.h>
#include <malloc.h>

int close(int handle)
{
struct RND_FILE *myfile;

myfile = (char *) handle;
//if (!(myfile)->blockptr) return -1;

if ((myfile)->mode!=O_RDONLY) {

if ((myfile)->name_prefix=='_')
return (-1);

rnd_saveblock(&(myfile)->name_prefix, (myfile)->blockptr, (myfile)->blocksize);
// We could check the result for rnd_saveblock, but perhaps it'd be too late
// Let's just save the control block (hoping we won't run out of space :S)
(myfile)->name_prefix='_';
rnd_saveblock(&(myfile)->name_prefix, myfile, sizeof(struct RND_FILE));
}

free((myfile)->blockptr);
//(myfile)->blockptr=0;
free(myfile);

return 0;

}
/*
* Close a file
* Stefano Bodrato - 2013
*
* int close(int handle)
* (write the current block and the control block amd free memory)
*
* $Id: close.c,v 1.2 2014-01-20 09:15:31 stefano Exp $
*/

#include <fcntl.h>
#include <malloc.h>

int close(int handle)
{
struct RND_FILE *myfile;

myfile = (char *) handle;
//if (!(myfile)->blockptr) return -1;

if ((myfile)->mode!=O_RDONLY) {

if ((myfile)->name_prefix=='_')
return (-1);

rnd_saveblock(&(myfile)->name_prefix, (myfile)->blockptr, (myfile)->blocksize);
// We could check the result for rnd_saveblock, but perhaps it'd be too late
// Let's just save the control block (hoping we won't run out of space :S)
(myfile)->name_prefix='_';
rnd_saveblock(&(myfile)->name_prefix, myfile, sizeof(struct RND_FILE));
}

free((myfile)->blockptr);
//(myfile)->blockptr=0;
free(myfile);

return 0;

}

220 changes: 110 additions & 110 deletions libsrc/fcntl/gen_rnd/open.c
Original file line number Diff line number Diff line change
@@ -1,110 +1,110 @@
/*
* Open a file - create the control block in a memory structure,
* allocate its temporary buffer and eventually write a first empty
* block on disk. A file holding the control block plus
* other files will form the virtual sectors of the same rnd_file
*
* Stefano Bodrato - 2013
*
* int open(char *name, int flags, mode_t mode)
* returns handle to file
*
*
* Access is either
*
* O_RDONLY = 0
* (O_RDWR .. does not mean much at the)
* O_WRONLY = 1 Starts afresh?!?!?
* O_APPEND = 256
*
* $Id: open.c,v 1.3 2016-06-13 19:55:47 dom Exp $
*/

#include <fcntl.h>
// "stdio.h" contains definition for EOF
#define __HAVESEED
#include <stdio.h>

#include <string.h>
#include <malloc.h>


int open(char *name, int flags, mode_t mode)
{
struct RND_FILE *myfile;
int myfile_missing;

myfile = malloc(sizeof(struct RND_FILE));
strcpy(myfile->name,name);
(myfile)->name_prefix='_';

myfile_missing = rnd_loadblock(&(myfile)->name_prefix, myfile, sizeof(struct RND_FILE));

if (myfile_missing) {
(myfile)->size=0L;
(myfile)->blocksize=RND_BLOCKSIZE;
}

(myfile)->position=0L;
(myfile)->blockptr=malloc((myfile)->blocksize+1);
//(myfile)->flags=flags;
(myfile)->mode=flags;
(myfile)->name_prefix='0';
(myfile)->pos_in_block=0;


switch (flags) {
case O_RDONLY:
if (myfile_missing) {
// FILE NOT FOUND
free((myfile)->blockptr);
free(myfile);
return(-1);
}
if (!rnd_loadblock(&(myfile)->name_prefix, (myfile)->blockptr, (myfile)->blocksize)) {
return(myfile); }
else
return(-1);
break;

case O_APPEND:
if (myfile_missing) {
// FILE NOT FOUND
free((myfile)->blockptr);
free(myfile);
return(-1);
}
if (lseek(myfile,0L,SEEK_END)==EOF) {
free((myfile)->blockptr);
free(myfile);
return(-1);
}
return(myfile);
break;


case O_WRONLY:
// TODO: delete file to overwrite
case O_RDWR:
if (myfile_missing) {
// create the first datablock: "0<filename>" to verify
// we have space on disk and disk can be written
if (rnd_saveblock(&(myfile)->name_prefix, (myfile)->blockptr, (myfile)->blocksize)) {
// FILE CREATION ERROR
free((myfile)->blockptr);
free(myfile);
return(-1);
}
// The control block creation ("_<filename>) is in "close.c"
} else if (lseek(myfile,0L,SEEK_SET)==EOF) {
free((myfile)->blockptr);
free(myfile);
return(-1);
}
return(myfile);
break;

}
return(-1);
}
/*
* Open a file - create the control block in a memory structure,
* allocate its temporary buffer and eventually write a first empty
* block on disk. A file holding the control block plus
* other files will form the virtual sectors of the same rnd_file
*
* Stefano Bodrato - 2013
*
* int open(char *name, int flags, mode_t mode)
* returns handle to file
*
*
* Access is either
*
* O_RDONLY = 0
* (O_RDWR .. does not mean much at the)
* O_WRONLY = 1 Starts afresh?!?!?
* O_APPEND = 256
*
* $Id: open.c,v 1.3 2016-06-13 19:55:47 dom Exp $
*/

#include <fcntl.h>
// "stdio.h" contains definition for EOF
#define __HAVESEED
#include <stdio.h>

#include <string.h>
#include <malloc.h>


int open(char *name, int flags, mode_t mode)
{
struct RND_FILE *myfile;
int myfile_missing;

myfile = malloc(sizeof(struct RND_FILE));
strcpy(myfile->name,name);
(myfile)->name_prefix='_';

myfile_missing = rnd_loadblock(&(myfile)->name_prefix, myfile, sizeof(struct RND_FILE));

if (myfile_missing) {
(myfile)->size=0L;
(myfile)->blocksize=RND_BLOCKSIZE;
}

(myfile)->position=0L;
(myfile)->blockptr=malloc((myfile)->blocksize+1);
//(myfile)->flags=flags;
(myfile)->mode=flags;
(myfile)->name_prefix='0';
(myfile)->pos_in_block=0;


switch (flags) {
case O_RDONLY:
if (myfile_missing) {
// FILE NOT FOUND
free((myfile)->blockptr);
free(myfile);
return(-1);
}
if (!rnd_loadblock(&(myfile)->name_prefix, (myfile)->blockptr, (myfile)->blocksize)) {
return(myfile); }
else
return(-1);
break;

case O_APPEND:
if (myfile_missing) {
// FILE NOT FOUND
free((myfile)->blockptr);
free(myfile);
return(-1);
}
if (lseek(myfile,0L,SEEK_END)==EOF) {
free((myfile)->blockptr);
free(myfile);
return(-1);
}
return(myfile);
break;


case O_WRONLY:
// TODO: delete file to overwrite
case O_RDWR:
if (myfile_missing) {
// create the first datablock: "0<filename>" to verify
// we have space on disk and disk can be written
if (rnd_saveblock(&(myfile)->name_prefix, (myfile)->blockptr, (myfile)->blocksize)) {
// FILE CREATION ERROR
free((myfile)->blockptr);
free(myfile);
return(-1);
}
// The control block creation ("_<filename>) is in "close.c"
} else if (lseek(myfile,0L,SEEK_SET)==EOF) {
free((myfile)->blockptr);
free(myfile);
return(-1);
}
return(myfile);
break;

}
return(-1);
}

Loading

0 comments on commit 1624e45

Please sign in to comment.