Skip to content

Instantly share code, notes, and snippets.

@fbstj
Created July 8, 2011 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbstj/1072117 to your computer and use it in GitHub Desktop.
Save fbstj/1072117 to your computer and use it in GitHub Desktop.
memory operations free of the standard libraries
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long LONG;
BYTE BYTE_get(BYTE **buf_ptr) { return *(*buf_ptr)++; }
void BYTE_put(BYTE **buf_ptr, BYTE value) { *(*buf_ptr)++ = value; }
void WORD_put(BYTE **buf_ptr, WORD value)
{
BYTE_put(buf_ptr, value >> 8);
BYTE_put(buf_ptr, value & 0x00ff);
}
void LONG_put(BYTE **buf_ptr, LONG value)
{
WORD_put(buf_ptr, value >> 16);
WORD_put(buf_ptr, value);
}
WORD WORD_get(BYTE **buf_ptr)
{
return BYTE_get(buf_ptr) << 8 | BYTE_get(buf_ptr);
}
LONG LONG_get(BYTE **buf_ptr)
{
return WORD_get(buf_ptr) << 16 | WORD_get(buf_ptr);
}
#define g_STR_buf_len 100
static BYTE STR_buf[g_STR_buf_len];
BYTE *STR_get(BYTE **buf_ptr)
{
BYTE *ptr = STR_buf;
while(**buf_ptr)
*ptr++ = *(*buf_ptr)++;
*ptr = 0;
return STR_buf;
}
void STR_put(BYTE **buf_ptr, BYTE *str)
{
while(*str)
*(*buf_ptr)++ = *str++;
}
void BUF_get(BYTE **buf_ptr, BYTE *buf, LONG len)
{
while(len--)
*buf++ = *(*buf_ptr)++;
}
void BUF_put(BYTE **buf_ptr, BYTE *buf, LONG len)
{
while(len--)
*(*buf_ptr)++ = *buf++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment