Subversion Repositories NaviCtrl

Rev

Rev 153 | Rev 272 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 153 Rev 244
Line 1... Line 1...
1
#include "fifo.h"
1
#include "fifo.h"
Line 2... Line 2...
2
 
2
 
3
u8 fifo_init (fifo_t *f, u8 *buffer, const u16 size)
3
u8 fifo_init (fifo_t* f, u8* buffer, const u16 size, u16 putvicsource, u16 getvicsource)
4
{
4
{
5
        if(f == NULL) return(0);
5
        if(f == NULL) return(0);
6
        f->buffer = buffer;
6
        f->buffer = buffer;
-
 
7
        f->size = size;
-
 
8
        f->putvicsource = putvicsource;
7
        f->size = size;
9
        f->getvicsource = getvicsource;
8
        fifo_purge(f);
10
        fifo_purge(f);
9
        return(1);
11
        return(1);
Line 10... Line 12...
10
}
12
}
11
 
13
 
12
u8 fifo_put (fifo_t *f, const u8 data)
14
u8 fifo_put (fifo_t *f, const u8 data)
13
{
-
 
14
        if (f->count >= f->size) return(0);     // return 0 in case of FIFO overflow.
15
{
15
 
-
 
16
        u8 * pwrite = f->pwrite;
16
        if (f->count >= f->size) return(0);     // return 0 in case of FIFO overflow.
17
 
17
        if(f->putvicsource != NO_ITLine) VIC_ITCmd(f->putvicsource, DISABLE);
18
        *(pwrite++) = data;         // copy data byte to buffer
-
 
19
        if(pwrite >= f->buffer + f->size) pwrite = f->buffer; // start at the begining after reaching the end 
18
        *(f->pwrite++) = data;      // copy data byte to buffer
-
 
19
        if(f->pwrite >= f->buffer + f->size) f->pwrite = f->buffer; // start at the begining after reaching the end 
20
        f->pwrite = pwrite;
20
        f->count++;
21
        f->count++;
21
        if(f->putvicsource != NO_ITLine) VIC_ITCmd(f->putvicsource, ENABLE);
Line 22... Line 22...
22
        return 1;
22
        return(1);
23
}
23
}
24
 
-
 
25
u8 fifo_get (fifo_t *f, u8 *pdata)
24
 
26
{
-
 
27
        if((f == NULL) || (pdata == NULL)) return(0);
25
u8 fifo_get (fifo_t *f, u8 *pdata)
28
        if(!f->count) return(0);
26
{
29
 
27
        if(!f->count) return(0);
30
        u8 *pread = f->pread;
-
 
31
        *pdata = *(pread++);
28
        if(f->getvicsource != NO_ITLine) VIC_ITCmd(f->getvicsource, DISABLE);
-
 
29
        *pdata = *(f->pread++);
32
        if(pread >= f->buffer + f->size) pread = f->buffer; // start at the begining after reaching the end 
30
        if(f->pread >= f->buffer + f->size) f->pread = f->buffer; // start at the begining after reaching the end 
33
        f->pread = pread;
31
        f->count--;
Line 34... Line 32...
34
        f->count--;
32
        if(f->getvicsource != NO_ITLine) VIC_ITCmd(f->getvicsource, ENABLE);
35
        return(1);
33
        return(1);