Created
July 8, 2011 15:42
-
-
Save fbstj/1072117 to your computer and use it in GitHub Desktop.
memory operations free of the standard libraries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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