#ifndef __buf_h__ #define __buf_h__ #include "common.h" /* * Note that all of these constants should be powers of two or * their corresponding AND-masks in order for the code to work * as intended, and that certain ratios must be preservered * for example, produce size must be at least as great as * consume size */ #define BUF_SIZE 16384 // external SRAM size #define BUF_MASK 0x3FFF // buffer size mask for fast modulus //#define BUF_ADDR 0x0260 // for 8515 (with 512b internal RAM) #define BUF_ADDR 0x1000 // for mega103 (with 4kb internal RAM) char * buf = BUF_ADDR; WORD producer = 0; WORD consumer = 0; // circular buffer functions /* These routines have been replaced by the macros below for speed. char canProduce(); char canConsume(); void produce(char c); char consume(); */ void clear(); // high-efficiency alternative to byte-level is a block-level model #define BUF_BLOCK_SIZE 2048 // buffer block size (sector size is a good choice) //is it safe to read from the buffer and play some data #define SAFE_TO_PRODUCE (((producer + BUF_BLOCK_SIZE) & BUF_MASK) != consumer) //is it safe to read some data from the buf and output it to the STA013? #define SAFE_TO_CONSUME (producer != consumer) //indicate that some data has been read from the CDROM #define MULTI_PRODUCE producer = ((producer + BUF_BLOCK_SIZE) & BUF_MASK) //indicate that some data has been written to the STA013 #define MULTI_CONSUME consumer = ((consumer + BUF_BLOCK_SIZE) & BUF_MASK) #endif