@ -6,10 +6,13 @@ import com.simon816.j65el02.device.RPMonitor;
import javax.imageio.ImageIO ;
import javax.swing.* ;
import java.awt.* ;
import java.awt.event.KeyEvent ;
import java.awt.event.KeyListener ;
import java.awt.image.BufferedImage ;
import java.io.File ;
import java.io.IOException ;
import java.net.URISyntaxException ;
import java.util.Objects ;
import static com.simon816.j65el02.device.RPMonitor.HEIGHT ;
@ -18,14 +21,11 @@ import static com.simon816.j65el02.device.RPMonitor.WIDTH;
public class BasicMonitorDriver implements MonitorDriver , KeyListener {
BufferedImage display ;
BufferedImage fontSheet ;
final int width = 8 ;
final int height = 8 ;
int rows = 16 ;
int cols = 16 ;
BufferedImage [ ] sprites = new BufferedImage [ rows * cols ] ;
ImageIcon [ ] characters = new ImageIcon [ rows * cols ] ;
JLabel [ ] [ ] displayArray = new JLabel [ HEIGHT ] [ WIDTH ] ;
JLabel [ ] lines = new JLabel [ HEIGHT ] ;
Machine emu ;
int xoffset = 32 ;
@ -34,22 +34,6 @@ public class BasicMonitorDriver implements MonitorDriver, KeyListener {
this . emu = emu ;
try {
display = ImageIO . read ( Objects . requireNonNull ( getClass ( ) . getResourceAsStream ( "/display.png" ) ) ) ;
fontSheet = ImageIO . read ( Objects . requireNonNull ( getClass ( ) . getResourceAsStream ( "/font.png" ) ) ) ;
for ( int i = 0 ; i < rows ; i + + )
{
for ( int j = 0 ; j < cols ; j + + )
{
sprites [ ( i * cols ) + j ] = fontSheet . getSubimage (
j * width ,
i * height ,
width ,
height
) ;
}
}
for ( int i = 0 ; i < characters . length ; i + + ) {
characters [ i ] = new ImageIcon ( sprites [ i ] ) ;
}
} catch ( IOException e ) {
System . out . print ( "No image!" ) ;
}
@ -59,18 +43,33 @@ public class BasicMonitorDriver implements MonitorDriver, KeyListener {
JFrame frame = new JFrame ( "Monitor" ) ;
frame . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ) ;
for ( int y = 0 ; y < displayArray . length ; y + + ) {
for ( int x = 0 ; x < displayArray [ y ] . length ; x + + ) {
displayArray [ y ] [ x ] = new JLabel ( new ImageIcon ( sprites [ ' ' ] ) ) ;
displayArray [ y ] [ x ] . setBounds ( xoffset + ( x * 8 ) , yoffset + ( y * 8 ) , 8 , 8 ) ;
displayArray [ y ] [ x ] . setVisible ( true ) ;
panel . add ( displayArray [ y ] [ x ] ) ;
}
GraphicsEnvironment ge = GraphicsEnvironment . getLocalGraphicsEnvironment ( ) ;
Font bescii ;
try {
bescii = Font . createFont ( Font . TRUETYPE_FONT , new File ( getClass ( ) . getResource ( "/C64ProMonoMonitor.ttf" ) . toURI ( ) ) ) ;
ge . registerFont ( bescii ) ;
} catch ( FontFormatException e ) {
throw new RuntimeException ( e ) ;
} catch ( IOException e ) {
throw new RuntimeException ( e ) ;
} catch ( URISyntaxException e ) {
throw new RuntimeException ( e ) ;
}
bescii = bescii . deriveFont ( Font . PLAIN , 8f ) ;
for ( int i = 0 ; i < HEIGHT ; i + + ) {
lines [ i ] = new JLabel ( ) ;
lines [ i ] . setFont ( bescii ) ;
lines [ i ] . setBounds ( xoffset , yoffset + i * 8 , 8 * WIDTH , 16 ) ;
lines [ i ] . setForeground ( Color . GREEN ) ;
panel . add ( lines [ i ] ) ;
}
JLabel label = new JLabel ( new ImageIcon ( display . getScaledInstance ( 350 * 2 , 230 * 2 , 0 ) ) ) ;
label . setBounds ( 0 , 0 , 350 * 2 , 230 * 2 ) ;
panel . add ( label ) ;
frame . add ( panel ) ;
frame . addKeyListener ( this ) ;
@ -101,11 +100,13 @@ public class BasicMonitorDriver implements MonitorDriver, KeyListener {
@Override
public void update ( byte [ ] [ ] windowData ) {
for ( int y = 0 ; y < windowData . length ; y + + ) {
for ( int x = 0 ; x < windowData [ y ] . length ; x + + ) {
char chars = ( char ) windowData [ y ] [ x ] ;
displayArray [ y ] [ x ] . setIcon ( characters [ chars % 255 ] ) ;
for ( int y = windowData . length - 1 ; y > = 0 ; y - - ) {
String text = "" ;
for ( int x = 0 ; x < windowData [ y ] . length ; x + + ) {
int temp = Math . floorMod ( windowData [ y ] [ x ] , 256 ) ;
text + = ( char ) ( ( temp + 0xDED0 ) ) ;
}
lines [ y ] . setText ( text ) ;
}
}