1 // Copyright (C) 2010 Dave Griffiths
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
main(int argc,char * argv[])7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 
17 // #include <nds.h>
18 #include "instructions.h"
19 // #include "sound.h"
20 
21 #ifndef BB_THREAD
22 #define BB_THREAD
23 
24 static const u8 STACK_SIZE=8;
25 
26 class machine;
27 
28 class thread
29 {
30 public:
31 	thread();
32 	~thread();
33 
34 	// relative to start
35 	u8 peek(machine *m, u8 addr) const;
36 	void poke(machine *m, u8 addr, u8 data);
37     void set_start(u8 s) { m_start=s; }
38     void set_pc(u8 s) { m_pc=s; }
39 	u8 get_pc() const { return m_pc+m_start; }
40 	u8 get_start() const { return m_start; }
41 	void run(machine *m);
42     const u8* get_stack() const { return m_stack; }
43 	void dump() const;
44     const int get_stack_pos() const { return m_stack_pos; }
45     bool is_active() const { return m_active; }
46 
47 	void set_active(bool s) { m_active=s; }
48 
49 	u8 top() const;
50 	u8 at(u8 pos) const;
51 
52 	u8 m_pc;
53 
54 	u8 m_stack[STACK_SIZE];
55 	int m_stack_pos;
56 
57 
58 private:
59 
60 	void push(u8 data);
61 	u8 pop();
62 
63 	bool m_active;
64 	u8 m_start;
65 };
66 
67 #endif
68