summaryrefslogtreecommitdiffstats
path: root/sw/linux/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sw/linux/src/main.c13
-rw-r--r--sw/linux/src/makefile.am7
-rw-r--r--sw/linux/src/serial.c22
-rw-r--r--sw/linux/src/serial.h17
-rw-r--r--sw/linux/src/ui.c90
-rw-r--r--sw/linux/src/ui.h17
-rw-r--r--sw/linux/src/z80prog.ui222
7 files changed, 388 insertions, 0 deletions
diff --git a/sw/linux/src/main.c b/sw/linux/src/main.c
new file mode 100644
index 0000000..769992a
--- /dev/null
+++ b/sw/linux/src/main.c
@@ -0,0 +1,13 @@
+#include "config.h"
+#include "ui.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+int main(int argc, char *argv[])
+{
+ ui_init(&argc, &argv);
+ return 0;
+}
+
diff --git a/sw/linux/src/makefile.am b/sw/linux/src/makefile.am
new file mode 100644
index 0000000..492c3ec
--- /dev/null
+++ b/sw/linux/src/makefile.am
@@ -0,0 +1,7 @@
+bin_PROGRAMS = z80prog
+z80prog_SOURCES = main.c ui.c serial.c
+
+z80prog_CFLAGS = -Wall -Werror -g $(gtk3_CFLAGS)
+z80prog_LDADD = $(gtk3_LIBS)
+
+CLEANFILES = *~
diff --git a/sw/linux/src/serial.c b/sw/linux/src/serial.c
new file mode 100644
index 0000000..a13ef45
--- /dev/null
+++ b/sw/linux/src/serial.c
@@ -0,0 +1,22 @@
+#include "serial.h"
+
+int serial_connect(const char *devpath, long baudrate)
+{
+ int fd;
+ struct termios tty;
+ // struct termios tty_old;
+
+ // open device
+ if ((fd = open(devpath, O_RDWR | O_NOCTTY)) < 0) {
+ return -1;
+ }
+
+ // set parameters
+ if (tcgetattr(fd, &tty) != 0) {
+ return -1;
+ }
+
+ // cfsetospeed(&tty,
+
+ return fd;
+}
diff --git a/sw/linux/src/serial.h b/sw/linux/src/serial.h
new file mode 100644
index 0000000..6123e42
--- /dev/null
+++ b/sw/linux/src/serial.h
@@ -0,0 +1,17 @@
+#ifndef __Z80PROG_SERIAL_H__
+#define __Z80PROG_SERIAL_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <termios.h>
+
+int serial_connect(const char *devpath, long baudrate);
+void serial_close(int fd);
+
+void serial_program(const char *rompath);
+void serial_read_rom(const char *rom);
+
+#endif
diff --git a/sw/linux/src/ui.c b/sw/linux/src/ui.c
new file mode 100644
index 0000000..b33aa04
--- /dev/null
+++ b/sw/linux/src/ui.c
@@ -0,0 +1,90 @@
+#include "ui.h"
+
+static bool ui_connected, ui_fileset;
+static GtkTextBuffer *ui_logbuf;
+static GtkBuilder *ui_builder;
+
+void ui_init(int *argc, char **argv[])
+{
+ GtkWindow *window;
+ GtkTextView *logview;
+ GtkFileChooserButton *filechoosebtn;
+ GtkButton *connectbtn, *flashbtn;
+
+ /* set ui global variables */
+ ui_connected = ui_fileset = false;
+
+ /* start gtk */
+ gtk_init(argc, argv);
+
+ /* load glade gtk ui */
+ ui_builder = gtk_builder_new();
+ gtk_builder_add_from_file(ui_builder, "gbprog.ui", NULL);
+
+ /* connect logger buffer (extern variable) */
+ ui_logbuf = gtk_text_buffer_new(NULL);
+ logview = GTK_TEXT_VIEW(gtk_builder_get_object(ui_builder, "logview"));
+
+ gtk_text_view_set_buffer(logview, ui_logbuf);
+
+ /* connect objects to function calls */
+ // window
+ window = GTK_WINDOW(gtk_builder_get_object(ui_builder, "window"));
+ g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
+
+ // connectbtn
+ connectbtn = GTK_BUTTON(gtk_builder_get_object(ui_builder, "flashbtn"));
+ g_signal_connect(connectbtn, "clicked",
+ G_CALLBACK(ui_connect_clicked), NULL);
+
+ // flashbtn
+ flashbtn = GTK_BUTTON(gtk_builder_get_object(ui_builder, "flashbtn"));
+ g_signal_connect(flashbtn, "clicked", G_CALLBACK(ui_flash_clicked), NULL);
+
+ // file chooser
+ filechoosebtn = GTK_FILE_CHOOSER_BUTTON(
+ gtk_builder_get_object(ui_builder, "filechoosebtn"));
+ g_signal_connect(filechoosebtn, "file-set", G_CALLBACK(ui_file_set), NULL);
+
+ /* start gtk window */
+ gtk_main();
+}
+
+void ui_log(const char *msg, char type)
+{
+ GtkTextIter end;
+ gchar typech[4] = "[ ] ";
+
+ switch (type) {
+ case 'm': typech[1] = '@'; break; // message
+ case 'w': typech[1] = '#'; break; // warning
+ case 'e': typech[1] = '!'; break; // error
+ }
+
+ gtk_text_buffer_get_end_iter(ui_logbuf, &end);
+ gtk_text_buffer_insert(ui_logbuf, &end, typech, 4);
+ gtk_text_buffer_get_end_iter(ui_logbuf, &end);
+ gtk_text_buffer_insert(ui_logbuf, &end, (const gchar *) msg, strlen(msg));
+}
+
+void ui_file_set(GtkFileChooserButton *btn, gpointer user_data)
+{
+ GtkEntry *filepath =
+ GTK_ENTRY(gtk_builder_get_object(ui_builder, "filepath"));
+
+ gtk_entry_set_text(filepath,
+ gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(btn)));
+
+ ui_log("File set\n", 'm');
+ ui_fileset = true;
+}
+
+void ui_connect_clicked(void)
+{
+
+}
+
+void ui_flash_clicked(void)
+{
+
+}
diff --git a/sw/linux/src/ui.h b/sw/linux/src/ui.h
new file mode 100644
index 0000000..44314d6
--- /dev/null
+++ b/sw/linux/src/ui.h
@@ -0,0 +1,17 @@
+#ifndef __Z80PROG_UI_H__
+#define __Z80PROG_UI_H_
+
+#include <stdbool.h>
+#include <string.h>
+
+#include <gtk/gtk.h>
+
+void ui_init(int *argc, char **argv[]);
+void ui_log(const char *msg, char type);
+
+void ui_file_set(GtkFileChooserButton *btn, gpointer user_data);
+
+void ui_connect_clicked(void);
+void ui_flash_clicked(void);
+
+#endif
diff --git a/sw/linux/src/z80prog.ui b/sw/linux/src/z80prog.ui
new file mode 100644
index 0000000..3735efa
--- /dev/null
+++ b/sw/linux/src/z80prog.ui
@@ -0,0 +1,222 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <object class="GtkAdjustment" id="baudrateadjust">
+ <property name="upper">1000000</property>
+ <property name="value">9600</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
+ <object class="GtkFileFilter" id="gbbinfilter">
+ <patterns>
+ <pattern>*.bin</pattern>
+ <pattern>*.gb</pattern>
+ <pattern>*.gba</pattern>
+ <pattern>*.gbc</pattern>
+ <pattern>*.hex</pattern>
+ </patterns>
+ </object>
+ <object class="GtkWindow" id="window">
+ <property name="width_request">450</property>
+ <property name="height_request">250</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="title" translatable="yes">Z80 ROM Programmer</property>
+ <property name="default_width">450</property>
+ <property name="default_height">200</property>
+ <child>
+ <object class="GtkBox" id="mainbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_left">10</property>
+ <property name="margin_right">10</property>
+ <property name="margin_top">10</property>
+ <property name="margin_bottom">10</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">10</property>
+ <child>
+ <object class="GtkBox" id="devbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">10</property>
+ <child>
+ <object class="GtkEntry" id="devpath">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="placeholder_text" translatable="yes">Enter path</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="devbaudrate">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="width_chars">0</property>
+ <property name="max_width_chars">7</property>
+ <property name="overwrite_mode">True</property>
+ <property name="placeholder_text" translatable="yes">9600</property>
+ <property name="input_purpose">number</property>
+ <property name="adjustment">baudrateadjust</property>
+ <property name="climb_rate">10</property>
+ <property name="snap_to_ticks">True</property>
+ <property name="numeric">True</property>
+ <property name="update_policy">if-valid</property>
+ <property name="value">9600</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="connectbtn">
+ <property name="label">gtk-connect</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="filebox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">10</property>
+ <child>
+ <object class="GtkEntry" id="filepath">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="placeholder_text" translatable="yes">Binary Path</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkFileChooserButton" id="filechoosebtn">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="filter">gbbinfilter</property>
+ <property name="title" translatable="yes"/>
+ </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>
+ <child>
+ <object class="GtkBox" id="flashbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">10</property>
+ <child>
+ <object class="GtkProgressBar" id="flashbar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="show_text">True</property>
+ <property name="ellipsize">start</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="flashbtn">
+ <property name="label" translatable="yes">Flash</property>
+ <property name="visible">True</property>
+ <property name="sensitive">False</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">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">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="logscrolled">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <object class="GtkViewport" id="logviewport">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkExpander" id="logexpander">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="expanded">True</property>
+ <property name="label_fill">True</property>
+ <property name="resize_toplevel">True</property>
+ <child>
+ <object class="GtkTextView" id="logview">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="editable">False</property>
+ <property name="monospace">True</property>
+ </object>
+ </child>
+ <child type="label">
+ <object class="GtkLabel" id="loglabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Logs</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">4</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>