summaryrefslogtreecommitdiffstats
path: root/src/kprocessorview.cpp
blob: 0bc27b5c1ea00874100fdc65e823adde330e6e08 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include "kprocessorview.h"

#include <tqlabel.h>
#include <tqlayout.h>
#include <tqscrollview.h>
#include <tqsize.h>
#include <tqmessagebox.h>
#include <tqpopupmenu.h>
#include <tqcursor.h>

MyListView::MyListView(TQWidget *parent) : TDEListView(parent)
{
	connect( this, TQT_SIGNAL( contextMenu( TDEListView *, TQListViewItem *, const TQPoint & ) ),
             TQT_SLOT( slotContextMenu( TDEListView *, TQListViewItem *, const TQPoint & ) ) );
}

MyListView::~MyListView()
{
}

void MyListView::slotContextMenu( TDEListView *, TQListViewItem *, const TQPoint & ) 
{
//	mousePressEvent( NULL ) ;
	emit showPopupMenu() ;
}
/*
void MyListView::mousePressEvent( TQMouseEvent * event )
{
	//TQMessageBox::information( this, "information", "mouse pressed" ) ;
	
//	if ( event->button() == RightButton ) 
		emit showPopupMenu() ;
//	else
//		TDEListView::mousePressEvent( event ) ;
}
*/

TDEProcessorView::TDEProcessorView(TQWidget *parent, const char *name)
 : TDEToolBar(parent)
{
	name = name ; // avoid compiler warning
	
	view = new MyListView( this ) ;
	
	connect( view, TQT_SIGNAL( itemRenamed( TQListViewItem*) ), this, TQT_SLOT( slotItemRenamed(TQListViewItem*) ) ) ;
	connect( view, TQT_SIGNAL( showPopupMenu() ), this, TQT_SLOT( showPopupMenu() ) ) ;

	view->addColumn( "Register" ) ;
	view->addColumn( "Value" ) ;
	view->setRootIsDecorated( true ) ;
	view->setRenameable( 1, true ) ;	// Column 1 is renameable
	view->setRenameable( 0, false ) ;	// Column 1 is renameable
	view->setItemsRenameable( true ) ;
	setWidget( view ) ;
	setResizeEnabled( true ) ;
	
	int i ;
	char str[ 128 ] ;
	
	TQListViewItem *cpu = new TQListViewItem( view ) ;
	cpu->setText( 0, "CPU" ) ;

	TQListViewItem *flags = new TQListViewItem( cpu ) ;
	flags->setText( 0, "Flags" ) ;

	zeroFlag = new TQListViewItem( flags ) ;
	zeroFlag->setText( 0, "Zero" ) ;
	zeroFlag->setText( 1, "0" ) ;
	
	carryFlag = new TQListViewItem( flags ) ;
	carryFlag->setText( 0, "Carry" ) ;
	carryFlag->setText( 1, "0" ) ;
	
	ieFlag = new TQListViewItem( flags ) ;
	ieFlag->setText( 0, "IE" ) ;
	ieFlag->setText( 1, "0" ) ;
	
	TQListViewItem *reg = new TQListViewItem( cpu ) ;
	reg->setText( 0, "Registers" ) ;

	for ( i = 0 ; i < 16 ; i++ ) {
		regs[ i ] = new TQListViewItem( reg ) ;
		sprintf( str, "s%X", i ) ;
		regs[ i ]->setText( 0, str ) ;
		regs[ i ]->setText( 1, "0" ) ;
	}
	
	view->setOpen( cpu, true ) ;
	view->setOpen( flags, true ) ;
	view->setOpen( reg, true ) ;

	m_bHexMode = false ;
}

void TDEProcessorView::slotHexMode()
{
	unsigned char regs[ 16 ] ;

	getRegisterValues(regs) ;
	m_bHexMode = !m_bHexMode ;
	setRegisterValues(regs) ;
}

void TDEProcessorView::showPopupMenu() 
{
	TQPopupMenu *menu = new TQPopupMenu( this ) ;
	menu->insertItem( "Hexadecimal", this, TQT_SLOT( slotHexMode() ), 0, 1 ) ;
	menu->setItemChecked( 1, m_bHexMode ) ;	
	menu->exec( TQCursor::pos() );
}

void TDEProcessorView::slotItemRenamed( TQListViewItem * item )
{
	int i, value, base ;
	bool ok ;
	
	if ( m_bHexMode ) base = 16 ;
	else              base = 10 ;

	if ( !item )
		return ;
	
	for ( i = 0 ; i < 16 ; i++ ) {
		if ( item == regs[ i ] ) {
			value = item->text(1).toInt( &ok, base ) ;
		
			if ( !ok || value < 0 || value > 255 ) {
				TQMessageBox::warning( parentWidget(), "Modify register", "Value should be between 0-255" ) ;
				view->rename( item, 1 ) ;
			} else {
				emit processorRegsChanged() ;
			}
			return ;
		}
	}
	
	if ( zeroFlag == item || carryFlag == item || ieFlag == item ) {
		value = item->text(1).toInt( &ok ) ;
		if ( !ok || value < 0 || value > 1 ) {
			TQMessageBox::warning( parentWidget(), "Modify flag", "Value should be between 0-1" ) ;
		} else
			emit processorFlagsChanged() ;
	}
}

void TDEProcessorView::resizeEvent( TQResizeEvent *event )
{
	event = event ;
//	view->resize( width() - 10, height() - 10 ) ;
}

void TDEProcessorView::getRegisterValues( unsigned char *values )
{
	int i, base ;
	bool ok ;

	if ( m_bHexMode ) base = 16 ;
	else              base = 10 ;

	for ( i = 0 ; i < 16 ; i++ ) {
		values[ i ] = regs[ i ]->text(1).toInt( &ok, base ) ;
	}
}

void TDEProcessorView::setRegisterValues( unsigned char *values )
{
	int i, base ;
		
	if ( m_bHexMode ) base = 16 ;
	else              base = 10 ;

	TQString str; 
	for ( i = 0 ; i < 16 ; i++ ) {
		str.setNum( values[ i ], base ) ;
		regs[ i ]->setText( 1, str ) ;
	}
}
		
void TDEProcessorView::setFlags( unsigned char flags )
{
	if ( flags & 0x01 ) zeroFlag->setText( 1, "1" ) ;
	else                zeroFlag->setText( 1, "0" ) ;
	
	if ( flags & 0x02 ) carryFlag->setText( 1, "1" ) ;
	else                carryFlag->setText( 1, "0" ) ;	
		
	if ( flags & 0x04 ) ieFlag->setText( 1, "1" ) ;
	else                ieFlag->setText( 1, "0" ) ;
} 

unsigned char TDEProcessorView::getFlags() 
{
	unsigned char flags = 0 ;
		
	if ( zeroFlag->text(1).toInt() == 1 )  flags |= 0x01 ;
	if ( carryFlag->text(1).toInt() == 1 ) flags |= 0x02 ;
	if ( ieFlag->text(1).toInt() == 1 )    flags |= 0x04 ;
	
	return flags ;
}

TDEProcessorView::~TDEProcessorView()
{
	delete view ;
}