3
3
import javax .swing .JPanel ;
4
4
import javax .swing .Timer ;
5
5
6
- public class DisplayPanel extends JPanel implements ActionListener , KeyListener , MouseMotionListener {
6
+ public class DisplayPanel extends JPanel implements ActionListener , KeyListener {
7
7
Timer t ;
8
- Point mousePos = new Point (0 ,0 );
9
8
int ramPage = 0 ;
10
9
int romPage = 0 ;
11
10
11
+ String ramPageString = "" ;
12
+ String romPageString = "" ;
13
+
12
14
public DisplayPanel () {
13
15
super (null );
14
16
15
- t = new javax .swing .Timer (100 , this );
17
+ t = new javax .swing .Timer (16 , this );
16
18
t .start ();
17
19
setBackground (Color .blue );
18
20
setPreferredSize (new Dimension (1936 , 966 ));
19
21
22
+ romPageString = EaterEmulator .rom .ROMString .substring (romPage *960 ,(romPage +1 )*960 );
23
+ ramPageString = EaterEmulator .ram .RAMString .substring (ramPage *960 ,(ramPage +1 )*960 );
24
+
20
25
this .setFocusable (true );
21
26
this .requestFocus ();
22
27
this .addKeyListener (this );
23
- this .addMouseMotionListener (this );
24
28
}
25
29
26
30
public void paintComponent (Graphics g ) {
27
31
super .paintComponent (g );
28
-
29
- g .setColor (Color .white );
32
+ g .setColor (Color .white );
33
+ //g.drawString("Render Mode: paintComponent",5,15);
34
+
35
+ // g.setColor(getBackground());
36
+ // g.fillRect(0, 0, EaterEmulator.getWindows()[1].getWidth(), EaterEmulator.getWindows()[1].getHeight());
37
+ // g.setColor(Color.white);
38
+ // g.drawString("Render Mode: fillRect",5,15);
30
39
31
40
//Title
32
41
g .setFont (new Font ("Calibri Bold" , 50 , 50 ));
33
42
g .drawString ("Ben Eater 6502 Emulator" , 40 , 50 );
34
43
35
- //Clocks
44
+ //Version
36
45
g .setFont (new Font ("Courier New Bold" ,20 ,20 ));
37
- g .drawString ("Clocks: " +EaterEmulator .clocks , 40 , 80 );
46
+ g .drawString ("v " +EaterEmulator .versionString , 7 , 1033 );
38
47
39
- //Mouse Position
40
- // g.setFont(new Font("Arial",10,10) );
41
- // g.drawString(mousePos.toString(), 10, 10 );
48
+ //Clocks
49
+ g .drawString ( "Clocks: " + EaterEmulator . clocks , 40 , 80 );
50
+ g .drawString ("Speed: " + EaterEmulator . cpu . ClocksPerSecond + " Hz" +( EaterEmulator . slowerClock ? " (Slow)" : "" ), 40 , 110 );
42
51
43
52
//PAGE INDICATORS
44
- g .setFont (new Font ("Courier New Bold" ,20 ,20 ));
45
53
g .drawString ("(K) <-- " +ROMLoader .byteToHexString ((byte )(romPage +0x80 ))+" --> (L)" , 1600 , 950 );
46
54
g .drawString ("(H) <-- " +ROMLoader .byteToHexString ((byte )ramPage )+" --> (J)" , 1200 , 950 );
47
55
48
56
//ROM
49
57
g .drawString ("ROM" , 1690 , 130 );
50
- drawString (g ,EaterEmulator . rom . toStringWithOffset ( 8 , 0x8000 , true ). substring ( romPage * 960 ,( romPage + 1 )* 960 ) , 1525 , 150 );
58
+ drawString (g ,romPageString , 1525 , 150 );
51
59
52
60
//RAM
53
61
g .drawString ("RAM" , 1280 , 130 );
54
- drawString (g ,EaterEmulator . ram . toString ( 8 , true ). substring ( ramPage * 960 ,( ramPage + 1 )* 960 ) , 1125 , 150 );
62
+ drawString (g ,ramPageString , 1125 , 150 );
55
63
56
64
//CPU
57
- g .drawString ("CPU Registers:" ,50 ,120 );
58
- g .drawString ("A: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .cpu .a )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .cpu .a )+")" , 35 , 150 );
59
- g .drawString ("X: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .cpu .x )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .cpu .x )+")" , 35 , 180 );
60
- g .drawString ("Y: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .cpu .y )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .cpu .y )+")" , 35 , 210 );
61
- g .drawString ("Stack Pointer: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .cpu .stackPointer )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .cpu .stackPointer )+")" , 35 , 240 );
62
- g .drawString ("Program Counter: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Short .toUnsignedInt (EaterEmulator .cpu .programCounter )), 16 )+" (" +ROMLoader .padStringWithZeroes (Integer .toHexString (Short .toUnsignedInt (EaterEmulator .cpu .programCounter )),4 )+")" , 35 , 270 );
63
- g .drawString ("Flags: " , 35 , 300 );
65
+ g .drawString ("CPU Registers:" ,50 ,140 );
66
+ g .drawString ("A: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .cpu .a )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .cpu .a )+")" , 35 , 170 );
67
+ g .drawString ("X: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .cpu .x )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .cpu .x )+")" , 35 , 200 );
68
+ g .drawString ("Y: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .cpu .y )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .cpu .y )+")" , 35 , 230 );
69
+ g .drawString ("Stack Pointer: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .cpu .stackPointer )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .cpu .stackPointer )+")" , 35 , 260 );
70
+ g .drawString ("Program Counter: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Short .toUnsignedInt (EaterEmulator .cpu .programCounter )), 16 )+" (" +ROMLoader .padStringWithZeroes (Integer .toHexString (Short .toUnsignedInt (EaterEmulator .cpu .programCounter )),4 )+")" , 35 , 290 );
71
+ g .drawString ("Flags: " , 35 , 320 );
64
72
65
73
g .drawString ("Absolute Address: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Short .toUnsignedInt (EaterEmulator .cpu .addressAbsolute )), 16 )+" (" +ROMLoader .byteToHexString ((byte )(EaterEmulator .cpu .addressAbsolute /0xFF ))+ROMLoader .byteToHexString ((byte )EaterEmulator .cpu .addressAbsolute )+")" , 35 , 350 );
66
74
g .drawString ("Relative Address: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Short .toUnsignedInt (EaterEmulator .cpu .addressRelative )), 16 )+" (" +ROMLoader .byteToHexString ((byte )(EaterEmulator .cpu .addressRelative /0xFF ))+ROMLoader .byteToHexString ((byte )EaterEmulator .cpu .addressRelative )+")" , 35 , 380 );
67
75
g .drawString ("Opcode: " +EaterEmulator .cpu .lookup [Byte .toUnsignedInt (EaterEmulator .cpu .opcode )]+" (" +ROMLoader .byteToHexString (EaterEmulator .cpu .opcode )+")" , 35 , 410 );
76
+ g .drawString ("Cycles: " +EaterEmulator .cpu .cycles , 35 , 440 );
68
77
69
78
int counter = 0 ;
70
79
String flagsString = "CZIDBUVN" ;
71
80
for (char c : ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .cpu .flags )),8 ).toCharArray ()) {
72
81
g .setColor ((c == '1' ) ? Color .green : Color .red );
73
- g .drawString (String .valueOf (flagsString .charAt (counter )), 120 +15 *counter , 300 );
82
+ g .drawString (String .valueOf (flagsString .charAt (counter )), 120 +15 *counter , 320 );
74
83
counter ++;
75
84
}
76
85
77
86
g .setColor (Color .white );
78
87
//VIA
79
- g .drawString ("VIA Registers:" ,50 ,480 );
80
- g .drawString ("PORT A: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .via .PORTA )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .via .PORTA )+")" , 35 , 510 );
81
- g .drawString ("PORT B: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .via .PORTB )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .via .PORTB )+")" , 35 , 540 );
82
- g .drawString ("DDR A: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .via .DDRA )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .via .DDRA )+")" , 35 , 570 );
83
- g .drawString ("DDR B: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .via .DDRB )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .via .DDRB )+")" , 35 , 600 );
88
+ g .drawString ("VIA Registers:" ,50 ,490 );
89
+ g .drawString ("PORT A: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .via .PORTA )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .via .PORTA )+")" , 35 , 520 );
90
+ g .drawString ("PORT B: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .via .PORTB )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .via .PORTB )+")" , 35 , 550 );
91
+ g .drawString ("DDR A: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .via .DDRA )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .via .DDRA )+")" , 35 , 580 );
92
+ g .drawString ("DDR B: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .via .DDRB )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .via .DDRB )+")" , 35 , 610 );
84
93
94
+ //Controls
95
+ g .drawString ("Controls:" , 50 , 750 );
96
+ g .drawString ("C - Toggle Clock" , 35 , 780 );
97
+ g .drawString ("Space - Pulse Clock" , 35 , 810 );
98
+ g .drawString ("R - Reset" , 35 , 840 );
99
+ g .drawString ("S - Toggle Slower Clock" , 35 , 870 );
85
100
}
86
101
87
102
public static void drawString (Graphics g , String text , int x , int y ) {
@@ -92,6 +107,7 @@ public static void drawString(Graphics g, String text, int x, int y) {
92
107
@ Override
93
108
public void actionPerformed (ActionEvent e ) {
94
109
if (e .getSource ().equals (t )) {
110
+ ramPageString = EaterEmulator .ram .RAMString .substring (ramPage *960 ,(ramPage +1 )*960 );
95
111
this .repaint ();
96
112
}
97
113
}
@@ -112,50 +128,43 @@ public void keyTyped(KeyEvent arg0) {
112
128
case 'l' :
113
129
if (romPage < 0x80 ) {
114
130
romPage +=1 ;
131
+ romPageString = EaterEmulator .rom .ROMString .substring (romPage *960 ,(romPage +1 )*960 );
115
132
}
116
133
break ;
117
134
case 'k' :
118
135
if (romPage > 0 ) {
119
136
romPage -=1 ;
137
+ romPageString = EaterEmulator .rom .ROMString .substring (romPage *960 ,(romPage +1 )*960 );
120
138
}
121
139
break ;
122
140
case 'j' :
123
141
if (ramPage < 0x80 ) {
124
142
ramPage +=1 ;
143
+ ramPageString = EaterEmulator .ram .RAMString .substring (ramPage *960 ,(ramPage +1 )*960 );
125
144
}
126
145
break ;
127
146
case 'h' :
128
147
if (ramPage > 0 ) {
129
148
ramPage -=1 ;
149
+ ramPageString = EaterEmulator .ram .RAMString .substring (ramPage *960 ,(ramPage +1 )*960 );
130
150
}
131
151
break ;
132
152
case 'r' :
133
153
EaterEmulator .cpu .reset ();
134
154
EaterEmulator .lcd .reset ();
135
155
EaterEmulator .via = new VIA ();
136
156
EaterEmulator .ram = new RAM ();
157
+ ramPageString = EaterEmulator .ram .RAMString .substring (ramPage *960 ,(ramPage +1 )*960 );
137
158
break ;
138
159
case ' ' :
139
160
EaterEmulator .cpu .clock ();
140
161
break ;
141
162
case 'c' :
142
- EaterEmulator .haltFlag = !EaterEmulator .haltFlag ;
163
+ EaterEmulator .clockState = !EaterEmulator .clockState ;
164
+ break ;
165
+ case 's' :
166
+ EaterEmulator .slowerClock = !EaterEmulator .slowerClock ;
143
167
break ;
144
168
}
145
- this .repaint ();
146
- }
147
-
148
- @ Override
149
- public void mouseDragged (MouseEvent arg0 ) {
150
-
151
169
}
152
-
153
- @ Override
154
- public void mouseMoved (MouseEvent arg0 ) {
155
- mousePos .setX (arg0 .getX ());
156
- mousePos .setY (arg0 .getY ());
157
-
158
- this .repaint ();
159
- }
160
-
161
170
}
0 commit comments