6
6
import java .io .IOException ;
7
7
8
8
public class DisplayPanel extends JPanel implements ActionListener , KeyListener {
9
- Timer t ;
9
+ Timer frameTimer = new javax .swing .Timer (16 , this );;
10
+ Timer clocksPerSecondCheckTimer = new Timer (150 ,this );
10
11
int ramPage = 0 ;
11
12
int romPage = 0 ;
12
13
@@ -23,8 +24,8 @@ public class DisplayPanel extends JPanel implements ActionListener, KeyListener
23
24
public DisplayPanel () {
24
25
super (null );
25
26
26
- t = new javax . swing . Timer ( 16 , this );
27
- t .start ();
27
+ clocksPerSecondCheckTimer . start ( );
28
+ frameTimer .start ();
28
29
setBackground (bgColor );
29
30
setPreferredSize (new Dimension (1936 , 966 ));
30
31
@@ -123,12 +124,19 @@ public void paintComponent(Graphics g) {
123
124
g .drawString (" IER: " +ROMLoader .padStringWithZeroes (Integer .toBinaryString (Byte .toUnsignedInt (EaterEmulator .via .IER )), 8 )+" (" +ROMLoader .byteToHexString (EaterEmulator .via .IER )+")" , 35 , 700 );
124
125
125
126
//Controls
126
- g .drawString ("Controls:" , 50 , 750 );
127
- g .drawString ("C - Toggle Clock" , 35 , 780 );
128
- g .drawString ("Space - Pulse Clock" , 35 , 810 );
129
- g .drawString ("R - Reset" , 35 , 840 );
130
- g .drawString ("S - Toggle Slower Clock" , 35 , 870 );
131
- g .drawString ("I - Trigger VIA CA1" , 35 , 900 );
127
+
128
+ if (!EaterEmulator .keyboardMode ) {
129
+ g .drawString ("Controls:" , 50 , 750 );
130
+ g .drawString ("C - Toggle Clock" , 35 , 780 );
131
+ g .drawString ("Space - Pulse Clock" , 35 , 810 );
132
+ g .drawString ("R - Reset" , 35 , 840 );
133
+ g .drawString ("S - Toggle Slower Clock" , 35 , 870 );
134
+ g .drawString ("I - Trigger VIA CA1" , 35 , 900 );
135
+ } else {
136
+ g .drawString ("Keyboard Mode Controls:" , 50 , 750 );
137
+ g .drawString ("Typing a key will write that key code to the memory location " +EaterEmulator .options .KeyboardLocationHexLabel .getText ().substring (3 ), 35 , 780 );
138
+ g .drawString (" and trigger an interrupt." , 35 , 810 );
139
+ }
132
140
}
133
141
134
142
public static void drawString (Graphics g , String text , int x , int y ) {
@@ -144,22 +152,29 @@ public void resetGraphics() {
144
152
145
153
@ Override
146
154
public void actionPerformed (ActionEvent e ) {
147
- if (e .getSource ().equals (t )) {
148
- EaterEmulator .running = true ;
155
+ if (e .getSource ().equals (frameTimer )) {
149
156
150
- EaterEmulator .cpu .cycles = 0 ;
151
-
157
+ EaterEmulator .running = true ;
152
158
153
159
ramPageString = EaterEmulator .ram .RAMString .substring (ramPage *960 ,(ramPage +1 )*960 );
154
160
EaterEmulator .ROMopenButton .setBounds (rightAlignHelper -150 , 15 , 125 , 25 );
155
161
EaterEmulator .RAMopenButton .setBounds (rightAlignHelper -150 , 45 , 125 , 25 );
156
162
EaterEmulator .ShowLCDButton .setBounds (rightAlignHelper -300 , 15 , 125 , 25 );
157
163
EaterEmulator .ShowGPUButton .setBounds (rightAlignHelper -300 , 45 , 125 , 25 );
158
- EaterEmulator .optionsButton .setBounds (rightAlignHelper -450 , 15 , 125 , 55 );
164
+ EaterEmulator .optionsButton .setBounds (rightAlignHelper -450 , 15 , 125 , 25 );
165
+ EaterEmulator .keyboardButton .setBounds (rightAlignHelper -450 , 45 , 125 , 25 );
159
166
this .repaint ();
160
167
161
168
if (!EaterEmulator .options .isVisible ())
162
169
this .requestFocus ();
170
+ } else if (e .getSource ().equals (clocksPerSecondCheckTimer )) {
171
+ EaterEmulator .cpu .timeDelta = System .nanoTime ()-EaterEmulator .cpu .lastTime ;
172
+ EaterEmulator .cpu .lastTime = System .nanoTime ();
173
+
174
+ EaterEmulator .cpu .clockDelta = EaterEmulator .clocks - EaterEmulator .cpu .lastClocks ;
175
+ EaterEmulator .cpu .lastClocks = EaterEmulator .clocks ;
176
+
177
+ EaterEmulator .cpu .ClocksPerSecond = Math .round (EaterEmulator .cpu .clockDelta /((double )EaterEmulator .cpu .timeDelta /1000000000.0 ));
163
178
}
164
179
}
165
180
@@ -175,54 +190,70 @@ public void keyReleased(KeyEvent arg0) {
175
190
176
191
@ Override
177
192
public void keyTyped (KeyEvent arg0 ) {
178
- switch (arg0 .getKeyChar ()) {
179
- case 'l' :
180
- if (romPage < 0x80 ) {
181
- romPage +=1 ;
182
- romPageString = EaterEmulator .rom .ROMString .substring (romPage *960 ,(romPage +1 )*960 );
183
- }
184
- break ;
185
- case 'k' :
186
- if (romPage > 0 ) {
187
- romPage -=1 ;
188
- romPageString = EaterEmulator .rom .ROMString .substring (romPage *960 ,(romPage +1 )*960 );
189
- }
190
- break ;
191
- case 'j' :
192
- if (ramPage < 0x80 ) {
193
- ramPage +=1 ;
194
- ramPageString = EaterEmulator .ram .RAMString .substring (ramPage *960 ,(ramPage +1 )*960 );
195
- }
196
- break ;
197
- case 'h' :
198
- if (ramPage > 0 ) {
199
- ramPage -=1 ;
193
+ if (!EaterEmulator .keyboardMode ) {
194
+ //Control Keyboard Mode
195
+ switch (arg0 .getKeyChar ()) {
196
+ case 'l' :
197
+ if (romPage < 0x7f ) {
198
+ romPage +=1 ;
199
+ romPageString = EaterEmulator .rom .ROMString .substring (romPage *960 ,(romPage +1 )*960 );
200
+ } else {
201
+ if (romPage > 0x7f ) {
202
+ romPage = 0x7f ;
203
+ romPageString = EaterEmulator .rom .ROMString .substring (romPage *960 ,(romPage +1 )*960 );
204
+ }
205
+ }
206
+ break ;
207
+ case 'k' :
208
+ if (romPage > 0 ) {
209
+ romPage -=1 ;
210
+ romPageString = EaterEmulator .rom .ROMString .substring (romPage *960 ,(romPage +1 )*960 );
211
+ }
212
+ break ;
213
+ case 'j' :
214
+ if (ramPage < 0x7f ) {
215
+ ramPage +=1 ;
216
+ ramPageString = EaterEmulator .ram .RAMString .substring (ramPage *960 ,(ramPage +1 )*960 );
217
+ if (ramPage > 0x7f ) {
218
+ ramPage = 0x7f ;
219
+ ramPageString = EaterEmulator .ram .RAMString .substring (ramPage *960 ,(ramPage +1 )*960 );
220
+ }
221
+ }
222
+ break ;
223
+ case 'h' :
224
+ if (ramPage > 0 ) {
225
+ ramPage -=1 ;
226
+ ramPageString = EaterEmulator .ram .RAMString .substring (ramPage *960 ,(ramPage +1 )*960 );
227
+ }
228
+ break ;
229
+ case 'r' :
230
+ EaterEmulator .cpu .reset ();
231
+ EaterEmulator .lcd .reset ();
232
+ EaterEmulator .via = new VIA ();
233
+ EaterEmulator .ram = new RAM ();
234
+ EaterEmulator .gpu .setRAM (EaterEmulator .ram );
200
235
ramPageString = EaterEmulator .ram .RAMString .substring (ramPage *960 ,(ramPage +1 )*960 );
201
- }
202
- break ;
203
- case 'r' :
204
- EaterEmulator .cpu .reset ();
205
- EaterEmulator .lcd .reset ();
206
- EaterEmulator .via = new VIA ();
207
- EaterEmulator .ram = new RAM ();
208
- EaterEmulator .gpu .setRAM (EaterEmulator .ram );
209
- ramPageString = EaterEmulator .ram .RAMString .substring (ramPage *960 ,(ramPage +1 )*960 );
210
236
211
- if (EaterEmulator .debug )
212
- System .out .println ("Size: " +this .getWidth ()+" x " +this .getHeight ());
213
- break ;
214
- case ' ' :
215
- EaterEmulator .cpu .clock ();
216
- break ;
217
- case 'c' :
218
- EaterEmulator .clockState = !EaterEmulator .clockState ;
219
- break ;
220
- case 's' :
221
- EaterEmulator .slowerClock = !EaterEmulator .slowerClock ;
222
- break ;
223
- case 'i' :
224
- EaterEmulator .via .CA1 ();
225
- break ;
237
+ if (EaterEmulator .debug )
238
+ System .out .println ("Size: " +this .getWidth ()+" x " +this .getHeight ());
239
+ break ;
240
+ case ' ' :
241
+ EaterEmulator .cpu .clock ();
242
+ break ;
243
+ case 'c' :
244
+ EaterEmulator .clockState = !EaterEmulator .clockState ;
245
+ break ;
246
+ case 's' :
247
+ EaterEmulator .slowerClock = !EaterEmulator .slowerClock ;
248
+ break ;
249
+ case 'i' :
250
+ EaterEmulator .via .CA1 ();
251
+ break ;
252
+ }
253
+ } else {
254
+ //Typing Keyboard Mode
255
+ Bus .write ((short )EaterEmulator .options .data .keyboardLocation , (byte )arg0 .getKeyChar ());
256
+ EaterEmulator .via .CA1 ();
226
257
}
227
258
}
228
259
}
0 commit comments