package chip8emu;
/*
This file is part of JavaCHIP8.
Copyright 2004 Kustaa Nyholm / SpareTimeLabs
JavaCHIP8 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
JavaCHIP8 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JavaCHIP8; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import javax.microedition.midlet.*;
import javax.microedition.media.*;
import javax.microedition.lcdui.*;
import java.io.*;
import chip8emu.res.*;
public class Chip8MIDlet
extends MIDlet {
private static String copyright = "Copyright 2004 Kustaa Nyholm / SpareTimeLabs. "
+"JavaCHIP8 is free software; you can redistribute it and/or modify "
+"it under the terms of the GNU General Public License. "
+"JavaCHIP8 is distributed in the hope that it will be fun, "
+"but WITHOUT ANY WARRANTY; without even the implied warranty of "
+"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
+"GNU General Public License for more details.";
private static String helpText = "No real help/instructions are available, sorry! Most of the "
+"games are unusable, but try 'Ivaders' for one that actually works. Keys '4' and '6' move the gun and "
+" '5' fires it." ;
static private Resources resources = new Resources();
public Chip8Screen chip8Screen = new Chip8Screen(this);
private Canvas splashScreen = new SplashScreen(this);
private TextScreen helpScreen = new TextScreen(this,helpText);
private TextScreen copyrightScreen = new TextScreen(this,copyright);;
public Chip8Emu emulator = new Chip8Emu(chip8Screen);
public GamesScreen gameslist = new GamesScreen(this);
public Chip8MIDlet() {
//instance = this;
}
public void quitApplication()
{
destroyApp(false);
notifyDestroyed();
}
public void startApp() {
//System.out.println("Starting....");
//TestScreen test=new TestScreen(this);
//test.test();
//Display.getDisplay(this).setCurrent(test);
gotoSplashScreen();
//emulator.start();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void gotoGamesScreen() {
Display.getDisplay(this).setCurrent(gameslist);
}
public void gotoChip8Screen() {
Display.getDisplay(this).setCurrent(chip8Screen);
}
public void gotoSplashScreen() {
Display.getDisplay(this).setCurrent(splashScreen);
}
public void gotoHelpScreen() {
Display.getDisplay(this).setCurrent(helpScreen);
}
public void gotoCopyrightScreen() {
Display.getDisplay(this).setCurrent(copyrightScreen);
}
public static Image createImage(String filename) {
Image image = null;
try {
InputStream is = resources.getClass().getResourceAsStream(filename);
image = Image.createImage(is);
}
catch (java.io.IOException ex) {
// just let return value be null
}
return image;
}
public static Player createPlayer(String filename, String format) {
Player p = null;
try {
InputStream is = resources.getClass().getResourceAsStream(filename);
System.out.println(is);
p = Manager.createPlayer(is, format);
p.prefetch();
}
catch (IOException ioe) { // ignore
}
catch (MediaException me) { // ignore } return p;
}
return p;
}
public static void startPlayer(Player p) {
if (p != null) {
try {
p.stop();
p.setMediaTime(0L);
p.start();
}
catch (MediaException me) {
// ignore
}
}
}
}
|