1
0
mirror of https://github.com/raphnet/gc_n64_usb-v3 synced 2024-11-13 20:55:03 -05:00

Add read n64 mempak support

This commit is contained in:
Raphael Assenat 2015-11-02 21:53:35 -05:00
parent 5a698b7f57
commit 452e324d07
3 changed files with 137 additions and 5 deletions

View File

@ -666,6 +666,7 @@ Author: Raphaël Assénat
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="read_n64_pak" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
@ -1056,4 +1057,84 @@ Author: Raphaël Assénat
</object>
</child>
</object>
<object class="GtkDialog" id="mempak_io_dialog">
<property name="can_focus">False</property>
<property name="modal">True</property>
<property name="type_hint">dialog</property>
<property name="attached_to">win_mempak_edit</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox2">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area2">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="mempak_io_stop">
<property name="label">gtk-stop</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="xalign">0.49000000953674316</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="mempak_io_stop" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box9">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="mempak_op_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Mempak operation in progress...</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkProgressBar" id="mempak_io_progress">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="vexpand">True</property>
<property name="show_text">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -4,8 +4,10 @@
#include <string.h>
#include "../requests.h"
#include "ihex.h"
#include "mempak.h"
#include "gcn64ctl_gui.h"
#include "mempak_gcn64usb.h"
#include "gcn64lib.h"
static void updateGuiFromAdapter(struct application *app);
gboolean rebuild_device_list_store(gpointer data);
@ -566,6 +568,56 @@ G_MODULE_EXPORT void onFileRescan(GtkWidget *wid, gpointer data)
rebuild_device_list_store(data);
}
static void mempak_io_progress_cb(int progress, void *ctx)
{
struct application *app = ctx;
GET_UI_ELEMENT(GtkProgressBar, mempak_io_progress);
gdouble fract;
fract = progress/MEMPAK_BLOCK_SIZE;
gtk_progress_bar_set_fraction(mempak_io_progress, progress/((gdouble)MEMPAK_MEM_SIZE));
while (gtk_events_pending()) {
gtk_main_iteration_do(FALSE);
}
}
G_MODULE_EXPORT void read_n64_pak(GtkWidget *wid, gpointer data)
{
struct application *app = data;
GET_UI_ELEMENT(GtkWindow, win_mempak_edit);
GET_UI_ELEMENT(GtkDialog, mempak_io_dialog);
GET_UI_ELEMENT(GtkLabel, mempak_op_label);
mempak_structure_t *mpk;
int res;
printf("N64 read mempak\n");
if (!app->current_adapter_handle)
return;
gtk_widget_show(GTK_WIDGET(mempak_io_dialog));
gtk_label_set_text(mempak_op_label, "Reading memory pack...");
res = gcn64lib_mempak_download(app->current_adapter_handle, 0, &mpk, mempak_io_progress_cb, app);
gtk_widget_hide(GTK_WIDGET(mempak_io_dialog));
if (res != 0) {
switch(res)
{
case -1: errorPopop(app, "No mempak detected"); break;
case -2: errorPopop(app, "I/O error reading mempak"); break;
default:
case -3: errorPopop(app, "Error reading mempak"); break;
}
}
else {
mpke_replaceMpk(app, mpk, NULL);
gtk_widget_show(GTK_WIDGET(win_mempak_edit));
}
}
int
main( int argc,
char **argv )
@ -597,9 +649,6 @@ main( int argc,
/* Connect signals */
gtk_builder_connect_signals( app.builder, &app );
/* Destroy builder, since we don't need it anymore */
// g_object_unref( G_OBJECT( builder ) );
/* Show window. All other widgets are automatically shown by GtkBuilder */
gtk_widget_show( GTK_WIDGET(window) );
@ -610,4 +659,3 @@ main( int argc,
return( 0 );
}

View File

@ -1,10 +1,13 @@
#ifndef gcn64ctl_gui_mpkedit_h__
#define gcn64ctl_gui_mpkedit_h__
#include "mempak.h"
struct mpkedit_data;
struct application;
struct mpkedit_data *mpkedit_new(struct application *app);
void mpkedit_free(struct mpkedit_data *mpke);
void mpke_replaceMpk(struct application *app, mempak_structure_t *mpk, char *filename);
#endif