HP48S support

This commit is contained in:
shagrath 2012-11-10 19:06:51 +01:00
parent 6993128372
commit d4eef6723c
11 changed files with 115 additions and 34 deletions

BIN
assets/hp48s Normal file

Binary file not shown.

BIN
assets/rams Normal file

Binary file not shown.

BIN
assets/roms Normal file

Binary file not shown.

View file

@ -242,6 +242,12 @@ typedef struct saturn_t {
#define NIBBLES_PER_ROW 0x22
extern char rom_filename [256];
extern char ram_filename [256];
extern char conf_filename [256];
extern char port1_filename [256];
extern char port2_filename [256];
extern int got_alarm;
extern int set_t1;

View file

@ -1063,7 +1063,7 @@ const char *fname;
{
int ram_size;
if (!read_rom_file(romFileName, &saturn.rom, &rom_size))
if (!read_rom_file(fname, &saturn.rom, &rom_size))
return 0;
dev_memory_init();
@ -1171,7 +1171,7 @@ read_files()
strcpy(fnam, path);
strcat(fnam, "rom");
strcat(fnam, rom_filename);
if (!read_rom_file(fnam, &saturn.rom, &rom_size))
@ -1180,7 +1180,7 @@ read_files()
rom_is_new = 0;
strcpy(fnam, path);
strcat(fnam, "hp48");
strcat(fnam, conf_filename);
if (NULL == (fp = fopen(fnam, "r")))
{
if (!quiet)
@ -1329,7 +1329,7 @@ read_files()
}
strcpy(fnam, path);
strcat(fnam, "ram");
strcat(fnam, ram_filename);
if ((fp = fopen(fnam, "r")) == NULL) {
if (!quiet)
LOGE( "%s: can\'t open %s\n", progname, fnam);
@ -1346,7 +1346,7 @@ read_files()
saturn.port1 = (unsigned char *)0;
strcpy(fnam, path);
strcat(fnam, "port1");
strcat(fnam, port1_filename);
if (stat(fnam, &st) >= 0)
{
port1_size = 2 * st.st_size;
@ -1388,7 +1388,7 @@ read_files()
saturn.port2 = (unsigned char *)0;
strcpy(fnam, path);
strcat(fnam, "port2");
strcat(fnam, port2_filename);
if (stat(fnam, &st) >= 0)
{
port2_size = 2 * st.st_size;
@ -1665,7 +1665,7 @@ write_files()
//strcat(path, "/");
strcpy(fnam, path);
strcat(fnam, "hp48");
strcat(fnam, conf_filename);
LOGI("trying to save: %s", fnam);
@ -1761,7 +1761,7 @@ LOGI("trying to save: %s", fnam);
if (rom_is_new)
{
strcpy(fnam, path);
strcat(fnam, "rom");
strcat(fnam, rom_filename);
if (!write_mem_file(fnam, saturn.rom, rom_size))
return 0;
}
@ -1772,14 +1772,14 @@ LOGI("trying to save: %s", fnam);
ram_size = RAM_SIZE_SX;
strcpy(fnam, path);
strcat(fnam, "ram");
strcat(fnam, ram_filename);
if (!write_mem_file(fnam, saturn.ram, ram_size))
return 0;
if ((port1_size > 0) && port1_is_ram)
{
strcpy(fnam, path);
strcat(fnam, "port1");
strcat(fnam, port1_filename);
if (!write_mem_file(fnam, saturn.port1, port1_size))
return 0;
}
@ -1787,7 +1787,7 @@ LOGI("trying to save: %s", fnam);
if ((port2_size > 0) && port2_is_ram)
{
strcpy(fnam, path);
strcat(fnam, "port2");
strcat(fnam, port2_filename);
if (!write_mem_file(fnam, saturn.port2, port2_size))
return 0;
}
@ -1811,7 +1811,21 @@ init_emulator()
}
init_saturn();
if (!read_rom(romFileName))
char path[1024];
FILE *sd;
if (NULL == (sd = fopen("/sdcard/.hp48/", "rw"))) {
strcpy(path, "/data/data/org.ab.x48/");
}
else
strcpy(path, "/sdcard/.hp48/");
strcat(path, rom_filename);
if (!read_rom(path))
exit(1);
return 0;

View file

@ -245,13 +245,44 @@ printf("%s\n", nl_langinfo(CODESET));*/
return 0;
}
char rom_filename [256];
char ram_filename [256];
char conf_filename [256];
char port1_filename [256];
char port2_filename [256];
void
Java_org_ab_x48_X48_registerClass( JNIEnv* env, jobject caller, jobject callback )
Java_org_ab_x48_X48_registerClass( JNIEnv* env, jobject caller, jobject callback, jstring rom, jstring ram, jstring conf,
jstring port1, jstring port2 )
{
LOGI("--registerClass--");
android_env = env;
android_callback = (*android_env)->NewGlobalRef(env, callback);
const char * fp = (*android_env)->GetStringUTFChars(env, rom, NULL);
strcpy(rom_filename, fp);
(*android_env)->ReleaseStringUTFChars(env, rom, fp);
fp = (*android_env)->GetStringUTFChars(env, ram, NULL);
strcpy(ram_filename, fp);
(*android_env)->ReleaseStringUTFChars(env, ram, fp);
fp = (*android_env)->GetStringUTFChars(env, conf, NULL);
strcpy(conf_filename, fp);
(*android_env)->ReleaseStringUTFChars(env, conf, fp);
fp = (*android_env)->GetStringUTFChars(env, port1, NULL);
strcpy(port1_filename, fp);
(*android_env)->ReleaseStringUTFChars(env, port1, fp);
fp = (*android_env)->GetStringUTFChars(env, port2, NULL);
strcpy(port2_filename, fp);
(*android_env)->ReleaseStringUTFChars(env, port2, fp);
/*strcpy(rom_filename , "roms");
strcpy(ram_filename, "rams");
strcpy(conf_filename , "hp48s");*/
jclass x48 = (*android_env)->GetObjectClass(env, android_callback);
LOGI("--x48 registered--");
refreshMainScreen = (*android_env)->GetMethodID(android_env, x48, "refreshMainScreen", "([S)V");
@ -262,28 +293,28 @@ Java_org_ab_x48_X48_registerClass( JNIEnv* env, jobject caller, jobject callback
LOGI("--methods registered--");
}
jstring
void
Java_org_ab_x48_X48_stopHPEmulator( JNIEnv* env, jobject thiz )
{
exit (0);
//exit_state = 0;
}
jstring
void
Java_org_ab_x48_X48_saveState( JNIEnv* env, jobject thiz )
{
LOGI("save_state");
write_files();
}
jstring
void
Java_org_ab_x48_X48_resetHPEmulator( JNIEnv* env, jobject thiz )
{
do_reset();
}
jstring
void
Java_org_ab_x48_X48_startHPEmulator( JNIEnv* env, jobject thiz )
{
@ -359,7 +390,7 @@ sigset_t set;
} while (exit_state);
LOGI("exit loop");
return (*env)->NewStringUTF(env, "Hello from JNI !");
}
jint

View file

@ -54,4 +54,6 @@
<string name="disableLite_summary">Prevents lite controls to show up when touching LCD</string>
<string name="sound">Enable sound</string>
<string name="sound_summary">EXPERIMENTAL: system beeps ok, so far</string>
<string name="hp48s">HP48 S</string>
<string name="hp48s_summary">Emulate an HP48S (Need App Restart !)</string>
</resources>

View file

@ -6,14 +6,15 @@ import java.io.IOException;
import java.io.InputStream;
import android.content.res.AssetManager;
import android.os.Environment;
import android.util.Log;
public class AssetUtil {
public static void copyAsset(AssetManager am, boolean force) {
File sd = new File("/sdcard");
File sd = Environment.getExternalStorageDirectory();
if (sd.exists() && sd.isDirectory()) {
File hpDir = new File("/sdcard/.hp48");
File hpDir = new File(sd, ".hp48");
copyAsset(am, hpDir.exists() || hpDir.mkdir(), force);
} else {
copyAsset(am, false, force);
@ -21,7 +22,7 @@ public class AssetUtil {
}
public static File getSDDir() {
File hpDir = new File("/sdcard/.hp48");
File hpDir = new File(Environment.getExternalStorageDirectory(), ".hp48");
if (hpDir.exists())
return hpDir;
return null;
@ -32,17 +33,24 @@ public class AssetUtil {
String assets[] = am.list( "" );
for( int i = 0 ; i < assets.length ; i++ ) {
boolean hp48 = assets[i].equals("hp48");
boolean hp48s = assets[i].equals("hp48s");
boolean ram = assets[i].equals("ram");
boolean rom = assets[i].equals("rom");
boolean rams = assets[i].equals("rams");
boolean roms = assets[i].equals("roms");
int required = 0;
if (ram)
required = 131072;
else if (rams)
required = 32768;
else if (rom)
required = 524288;
else if (roms)
required = 262144;
//boolean SKUNK = assets[i].equals("SKUNK");
if (hp48 || rom || ram) {
String rep = sd?"/sdcard/.hp48/":"/data/data/org.ab.x48/";
File fout = new File(rep + assets[i]);
if (hp48 || rom || ram || hp48s || roms || rams) {
File rep = sd?new File(Environment.getExternalStorageDirectory(), ".hp48"):Environment.getDataDirectory();
File fout = new File(rep, assets[i]);
if (!fout.exists() || fout.length() == 0 || (required > 0 && fout.length() != required) || force) {
Log.i("x48", "Overwriting " + assets[i]);
FileOutputStream out = new FileOutputStream(fout);
@ -63,9 +71,9 @@ public class AssetUtil {
}
public static boolean isFilesReady() {
File hpDir = new File("/sdcard/.hp48");
File hpDir = new File(Environment.getExternalStorageDirectory(), ".hp48");
if (!hpDir.exists() || !hpDir.isDirectory()) {
hpDir = new File("/data/data/org.ab.x48/");
hpDir = Environment.getDataDirectory();
if (!hpDir.exists() || !hpDir.isDirectory())
return false;
}

View file

@ -11,7 +11,7 @@ public class EmulatorThread extends Thread {
}
public void run() {
x48.registerClass(x48);
x48.registerClass();
x48.startHPEmulator();
}

View file

@ -24,6 +24,13 @@ public class Settings extends PreferenceActivity {
inlinePrefCat.setTitle(R.string.general_preferences);
root.addPreference(inlinePrefCat);
CheckBoxPreference h48Pref = new CheckBoxPreference(this);
h48Pref.setKey("hp48s");
h48Pref.setDefaultValue(false);
h48Pref.setTitle(R.string.hp48s);
h48Pref.setSummary(R.string.hp48s_summary);
inlinePrefCat.addPreference(h48Pref);
CheckBoxPreference savePref = new CheckBoxPreference(this);
savePref.setKey("saveOnExit");
savePref.setTitle(R.string.saveonexit_msgbox);

View file

@ -72,6 +72,7 @@ public class X48 extends Activity {
setContentView(R.layout.main);
mainView = (HPView) findViewById(R.id.hpview);
hp48s = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("hp48s", false);
checkPrefs();
}
@ -121,13 +122,13 @@ public class X48 extends Activity {
mainView.refreshIcons(i);
}
public native String startHPEmulator();
public native String resetHPEmulator();
public native String saveState();
public native String stopHPEmulator();
public native void startHPEmulator();
public native void resetHPEmulator();
public native void saveState();
public native void stopHPEmulator();
public native int buttonPressed(int code);
public native int buttonReleased(int code);
public native void registerClass(X48 instance);
public native void registerClass(X48 instance, String rom_filename, String ram_filename, String conf_filename, String port1_filename, String port2_filename);
public native int fillAudioData(short data []);
public native int fillScreenData(short data []);
public native void flipScreen();
@ -332,8 +333,14 @@ public class X48 extends Activity {
}
private boolean saveonExit;
private void managePort(int number, String value) {
private boolean hp48s;
public boolean isHp48s() {
return hp48s;
}
private void managePort(int number, String value) {
int size = Integer.parseInt(value);
File f = AssetUtil.getSDDir();
if (f != null) {
@ -417,4 +424,10 @@ public class X48 extends Activity {
super.onConfigurationChanged(newConfig);
}
public void registerClass() {
registerClass(this, hp48s?"roms":"rom", hp48s?"rams":"ram", hp48s?"hp48s":"hp48",
hp48s?"port1s":"port1", hp48s?"port2s":"port2");
}
}