fix touchscreen errors
[kugel-rb.git] / lib / skin_parser / skin_buffer.c
blob69d9d273bdc6c83af82617dad10c966736afff25
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: skin_buffer.c 25962 2010-05-12 09:31:40Z jdgordon $
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 * Copyright (C) 2009 Jonathan Gordon
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdlib.h>
27 #include "skin_buffer.h"
29 #ifdef ROCKBOX
30 static size_t buf_size;
31 static unsigned char *buffer_start = NULL;
32 static unsigned char *buffer_front = NULL;
33 #endif
35 void skin_buffer_init(char* buffer, size_t size)
37 #if defined(ROCKBOX)
38 buffer_start = buffer_front = buffer;
39 buf_size = size;
40 #endif
43 /* Allocate size bytes from the buffer */
44 void* skin_buffer_alloc(size_t size)
46 void *retval = NULL;
47 #ifdef ROCKBOX
48 if (size > skin_buffer_freespace())
49 return NULL;
50 retval = buffer_front;
51 buffer_front += size;
52 /* 32-bit aligned */
53 buffer_front = (void *)(((unsigned long)buffer_front + 3) & ~3);
54 #else
55 retval = malloc(size);
56 #endif
57 return retval;
61 #ifdef ROCKBOX
62 /* get the number of bytes currently being used */
63 size_t skin_buffer_usage(void)
65 return buffer_front - buffer_start;
67 size_t skin_buffer_freespace(void)
69 return buf_size - skin_buffer_usage();
72 static unsigned char *saved_buffer_pos = NULL;
73 void skin_buffer_save_position(void)
75 saved_buffer_pos = buffer_front;
78 void skin_buffer_restore_position(void)
80 if (saved_buffer_pos)
81 buffer_front = saved_buffer_pos;
83 #endif