-
Notifications
You must be signed in to change notification settings - Fork 0
/
avr-misc.cpp
54 lines (54 loc) · 1.49 KB
/
avr-misc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//-----------------------------------------------------------------------------
#include <stdlib.h>
#include "avr-misc.h"
//-----------------------------------------------------------------------------
unsigned char _sreg;
//-----------------------------------------------------------------------------
BYTEstack::BYTEstack()
{
m_count = 0;
m_buf = NULL;
}
//-----------------------------------------------------------------------------
BYTEstack::~BYTEstack()
{
if(m_buf)
{
free(m_buf);
m_buf = NULL;
}
}
//-----------------------------------------------------------------------------
void BYTEstack::push(BYTE value)
{
m_buf = (BYTE*) realloc(m_buf, m_count + 1);
if(!m_buf)
{
// not enough memory space to enlarge stack
halt();
}
m_buf[m_count++] = value;
}
//-----------------------------------------------------------------------------
BYTE BYTEstack::pop()
{
BYTE value = m_buf[--m_count];
m_buf = (BYTE*) realloc(m_buf, m_count);
return value;
}
//-----------------------------------------------------------------------------
BYTE BYTEstack::size()
{
return m_count;
}
//-----------------------------------------------------------------------------
BYTE BYTEstack::top()
{
return m_buf[m_count - 1];
}
//-----------------------------------------------------------------------------
BYTE BYTEstack::operator [](const int i)
{
return m_buf[i];
}
//-----------------------------------------------------------------------------