Skip to content

Commit

Permalink
Merge pull request #92 from mike632t/unstable
Browse files Browse the repository at this point in the history
Fixed segmentation fault in HP12C
  • Loading branch information
mike632t authored Apr 18, 2024
2 parents 333c9e1 + ea54101 commit ec88b9a
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 37 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ for a particular model or apply a patch to the existing firmware.

* Parallel make only works on Linux.

##### HP 11C + HP 12C + HP 15C + HP 16C

Keyboard test is successful but these models do not pass the self-test.

##### HP 29C

* All 30 registers have continuous memory.
Expand Down
18 changes: 4 additions & 14 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ _files = `ls makefile makefile.*.[0-9] $(SRC)/makefile $(SRC)/makefile.common $
_source = `ls $(SRC)/*.c $(SRC)/*.c.[0-9] $(SRC)/*.h $(SRC)/*.h.[0-9] $(SRC)/*.in $(SRC)/*.in.[0-9] 2>/dev/null || true`
_data = `ls $(ROM)/$(PROGRAM)*.rom $(ROM)/$(PROGRAM)*.rom.[0-9] $(PRG)/$(PROGRAM)*.dat $(PRG)/$(PROGRAM)*.dat.[0-9] 2>/dev/null || true`
_images = `ls $(SRC)/*.ico $(SRC)/*.ico.[0-9] $(SRC)/*.png $(SRC)/*.png.[0-9] $(SRC)/*.svg $(SRC)/*.svg.[0-9] $(IMG)/*.png $(IMG)/*.png.[0-9] 2>/dev/null || true`
_other = `ls $(SRC)/make.com $(SRC)/make.com.[0-9] *.md *.md.[0-9] .gitignore .gitattributes 2>/dev/null || true`
_other = `ls $(SRC)/make.com $(SRC)/make.com.[0-9] *.md *.md.[0-9] $(SRC)/*.md $(SRC)/*.md.[0-9] $(IMG)/*.md $(IMG)/*.md.[0-9] .gitignore .gitattributes 2>/dev/null || true`

_date = `date +'%Y%m%d%H%M'`

Expand Down Expand Up @@ -184,10 +184,8 @@ install:
# Note that Tru64 requires both DESTDIR and prefix to be explicitly defined
# when invoking make.
#
# @if [ -z "$${prefix+x}" ]; then echo "'prefix' NOT defined"; else echo "prefix='$(prefix)'"; fi;
# @if [ -z "$${DESTDIR+x}" ]; then echo "'DESTDIR' NOT defined"; else echo "DESTDIR='$(DESTDIR)'"; fi;

@_unset() { if [ -z "$${prefix+x}" ] && [ -z "$(DESTDIR)" ]; then return 0; else return 1; fi;}; \
@_unset() { if [ -z "$(DESTDIR)$(prefix)" ]; then return 0; else return 1; fi;}; \
_desktop="`echo "$(DESKTOP)" | tr '[:lower:]' '[:upper:]' `"; \
if [ -z "$$_desktop" ]; then \
if [ -d "$$HOME/.local" ]; then \
Expand All @@ -211,24 +209,19 @@ install:
_unset && prefix="$$HOME" || true; \
$(MAKE) -s DESTDIR=$(DESTDIR) prefix=$$prefix do_none; \
;; \
"") \
echo "Unable to detect desktop: please specify the DESKTOP (GNOME, KDE, MATE, XFCE, ... or NONE)."; \
;; \
*) \
echo "'DESKTOP=$(DESKTOP)' was not recognised: Try 'make install' instead."; \
;; \
esac;

do_copy: $(BIN)
# No matter what desktop environment we are using (even if it is NONE) we
# need to copy the execuitables to the destination folder
#
# @[ -n "$${VERBOSE+x}" ] && echo "'DESKTOP=$(DESKTOP)' 'DESTDIR=$(DESTDIR)' 'prefix=$(prefix)'"
# need to copy the executable files to the destination folder.
#
@[ -n "$(DESTDIR)" ] || [ -d "$(prefix)" ] || \
{ echo "Please ensure $(prefix) exists (or set DESTDIR for staged install)." >&2; exit 1; }
@mkdir -p "$(DESTDIR)$(prefix)"
@cp $$flags -R $(BIN) "$(DESTDIR)$(prefix)"/ # Fail early if source and destination directories are the same
@cp -R $(BIN) "$(DESTDIR)$(prefix)"/ # Fail early if source and destination directories are the same

do_none: do_copy
# Copy binaries (and saved programs ?) to $(BIN) if no desktop specified.
Expand All @@ -242,7 +235,6 @@ do_none: do_copy
#
@[ -n "$${VERBOSE+x}" ] && echo "No desktop option selected" || true
@[ -n "$${VERBOSE+x}" ] && echo "Installing in $(DESTDIR)$(prefix)" || true
# @[ -n "$${VERBOSE+x}" ] && echo "prefix=$(prefix)" || true
#
# @cp -R $(PRG)/* "$(DESTDIR)$(prefix)/$(BIN)/"

Expand All @@ -255,7 +247,6 @@ do_cde: do_copy
#
@[ -n "$${VERBOSE+x}" ] && echo "Selected CDE desktop environment" || true
@[ -n "$${VERBOSE+x}" ] && echo "Installing in $(DESTDIR)$(prefix)" || true
# @[ -n "$${VERBOSE+x}" ] && echo "prefix=$(prefix)" || true
#
# Add program files
@cp -R $(PRG)/* "$(DESTDIR)/$(prefix)/$(BIN)/"
Expand All @@ -266,7 +257,6 @@ do_env: do_copy $(SRC)/$(PROGRAM).desktop.in $(SRC)/$(PROGRAM).svg
#
@[ -n "$${VERBOSE+x}" ] && echo "Selected $(DESKTOP) environment" || true
@[ -n "$${VERBOSE+x}" ] && echo "Installing in $(DESTDIR)$(prefix)" || true
# @[ -n "$${VERBOSE+x}" ] && echo "prefix=$(prefix)" || true
#
# Copy desktop files
@mkdir -p "$(DESTDIR)$(prefix)"/share/applications;
Expand Down
4 changes: 2 additions & 2 deletions src/makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ PROGRAM = x11-calc-$(MODEL)
BIN = ../bin

# SHARED sources are model-dependant via HP$(MODEL) #define statements
SHARED = x11-calc.c x11-calc-cpu.c x11-calc-display.c x11-calc-digit.c x11-calc-messages.c x11-calc-button.c x11-keyboard.c
COMMON = x11-calc-switch.c x11-calc-label.c x11-calc-colour.c x11-calc-font.c gcc-wait.c gcc-exists.c
SHARED = x11-calc.c x11-calc-cpu.c x11-calc-display.c x11-calc-digit.c x11-calc-messages.c x11-calc-button.c
COMMON = x11-calc-switch.c x11-calc-label.c x11-calc-colour.c x11-calc-font.c x11-keyboard.c gcc-wait.c gcc-exists.c

CC = cc
DEBUG =
Expand Down
5 changes: 3 additions & 2 deletions src/x11-calc-button.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@
#include <X11/Xlib.h> /* XOpenDisplay(), etc. */
#include <X11/Xutil.h> /* XSizeHints etc. */

#include "x11-calc-switch.h"
#include "x11-calc-messages.h"
#include "x11-calc-label.h"
#include "x11-calc-switch.h"
#include "x11-calc-button.h"

#include "x11-calc.h"
Expand Down Expand Up @@ -142,7 +143,7 @@ obutton *h_button_create(int i_index, char c_key,
obutton *h_button; /* Ponter to button. */

/* Attempt to allocate memory for a button. */
if ((h_button = malloc (sizeof(*h_button)))==NULL) v_error(errno, "Memory allocation failed in %s line : %d\n", __FILE__, __LINE__);
if ((h_button = malloc (sizeof(*h_button)))==NULL) v_error(errno, h_err_memmory_alloc, __FILE__, __LINE__);

h_button->index = i_index;
h_button->key = c_key;
Expand Down
3 changes: 1 addition & 2 deletions src/x11-calc-cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,7 @@ oprocessor *h_processor_create(int *h_rom) /* Create a new processor 'object' */
{
oprocessor *h_processor;
int i_count;
if ((h_processor = malloc(sizeof(*h_processor)))==NULL)
v_error(errno, "Memory allocation failed!"); /* Attempt to allocate memory to hold the processor structure */
if ((h_processor = malloc(sizeof(*h_processor)))==NULL) v_error(errno, h_err_memmory_alloc, __FILE__, __LINE__);
for (i_count = 0; i_count < REGISTERS; i_count++)
h_processor->reg[i_count] = h_register_create((i_count + 1) * -1); /* Allocate storage for the registers */
for (i_count = 0; i_count < MEMORY_SIZE; i_count++)
Expand Down
22 changes: 14 additions & 8 deletions src/x11-calc-display.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
* and the current position of the display - MT
* - Finally renamed x11-calc-segment to the more correct
* x11-calc-digit - MT
* 18 Apr 24 - Checks for undefined labels when updating indicators
* on the display (fixed segmentation fault) - MT
*
*/

Expand All @@ -99,10 +101,11 @@
#include <X11/Xlib.h> /* XOpenDisplay(), etc. */
#include <X11/Xutil.h> /* XSizeHints etc. */

#include "x11-calc-font.h"
#include "x11-calc-button.h"
#include "x11-calc-switch.h"
#include "x11-calc-messages.h"
#include "x11-calc-label.h"
#include "x11-calc-switch.h"
#include "x11-calc-button.h"
#include "x11-calc-font.h"

#include "x11-calc.h"

Expand Down Expand Up @@ -133,7 +136,7 @@ odisplay *h_display_create(int i_index, int i_left, int i_top, int i_width, int
int i_count, i_offset, i_size;

/* Attempt to allocate memory for a display. */
if ((h_display = malloc(sizeof(*h_display)))==NULL) v_error(errno, "Memory allocation failed!");
if ((h_display = malloc(sizeof(*h_display)))==NULL) v_error(errno, h_err_memmory_alloc, __FILE__, __LINE__);
h_display->index = i_index;

h_display->bezel_position.x = i_left; /* Set properties */
Expand Down Expand Up @@ -248,7 +251,7 @@ int i_display_draw(Display* x_display, int x_application_window, int i_screen, o

#if defined(HP10c) || defined(HP11c) || defined(HP12c) || defined(HP15c) || defined(HP16c)
for (i_count = 0; i_count < INDECATORS; i_count++)
i_label_draw(x_display, x_application_window, i_screen, h_display->label[i_count]);
if (!(h_display->label[i_count] == NULL)) i_label_draw(x_display, x_application_window, i_screen, h_display->label[i_count]);
#endif

return (True);
Expand Down Expand Up @@ -282,9 +285,12 @@ int i_display_resize(odisplay *h_display, float f_scale) /* Resize display base
#if defined(HP10c) || defined(HP11c) || defined(HP12c) || defined(HP15c) || defined(HP16c)
for (i_count = 0; i_count < INDECATORS; i_count++)
{
h_display->label[i_count]->label_position.x = h_display->label[i_count]->label_position.x * f_scale;
h_display->label[i_count]->label_position.y = h_display->bezel_position.y + h_display->display_position.height - h_small_font->descent;
h_display->label[i_count]->label_position.width = h_display->label[i_count]->label_geometry.width * f_scale;
if (!(h_display->label[i_count] == NULL))
{
h_display->label[i_count]->label_position.x = h_display->label[i_count]->label_position.x * f_scale;
h_display->label[i_count]->label_position.y = h_display->bezel_position.y + h_display->display_position.height - h_small_font->descent;
h_display->label[i_count]->label_position.width = h_display->label[i_count]->label_geometry.width * f_scale;
}
}
#endif
return 0;
Expand Down
3 changes: 2 additions & 1 deletion src/x11-calc-label.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <X11/Xlib.h> /* XOpenDisplay(), etc. */
#include <X11/Xutil.h> /* XSizeHints etc. */

#include "x11-calc-messages.h"
#include "x11-calc-label.h"
#include "x11-calc-switch.h"
#include "x11-calc-button.h"
Expand Down Expand Up @@ -85,7 +86,7 @@ olabel *h_label_create(int i_index, char* s_text, XFontStruct *h_font,
olabel *h_label; /* Ponter to label. */

/* Attempt to allcoate memory for a label. */
if ((h_label = malloc (sizeof(*h_label)))==NULL) v_error(errno, "Memory allocation failed!");
if ((h_label = malloc (sizeof(*h_label)))==NULL) v_error(errno, h_err_memmory_alloc, __FILE__, __LINE__);

h_label->index = i_index;
h_label->text = s_text;
Expand Down
2 changes: 2 additions & 0 deletions src/x11-calc-messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ This is free software: you are free to change and redistribute it.\n\
There is NO WARRANTY, to the extent permitted by law.\n";

const char * h_err_creating_file = "Can't create '%s'.\n";
const char * h_err_memmory_alloc = "Memory allocation failed in %s line : %d\n";
const char * h_err_ROM = "Empty ROM - no firmware loaded.\n";


#if defined(HEXADECIMAL)
const char * h_msg_opcode = "%1x-%03x %03x ";
const char * h_msg_address = "%03x";
Expand Down
8 changes: 5 additions & 3 deletions src/x11-calc-messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ extern char * h_err_invalid_address;
extern char * h_err_invalid_register;
extern char * h_msg_opcode;
extern char * h_msg_address;
const char * h_msg_negative_offset;
const char * h_msg_positive_offset;
const char * h_msg_rom;

extern char * h_msg_negative_offset;
extern char * h_msg_positive_offset;
extern char * h_msg_rom;

extern char * c_msg_usage;
extern char * h_err_invalid_operand;
Expand All @@ -65,4 +66,5 @@ extern char * h_err_display_colour;
extern char * h_err_font;

extern char * h_err_creating_file;
extern char * h_err_memmory_alloc;
extern const char * h_err_ROM;
3 changes: 2 additions & 1 deletion src/x11-calc-switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <X11/Xlib.h> /* XOpenDisplay(), etc. */
#include <X11/Xutil.h> /* XSizeHints etc. */

#include "x11-calc-messages.h"
#include "x11-calc-label.h"
#include "x11-calc-switch.h"
#include "x11-calc-button.h"
Expand Down Expand Up @@ -87,7 +88,7 @@ oswitch *h_switch_create(int i_index, char* s_on, char* s_mid, char* s_off,
oswitch *h_switch; /* Ponter to switch. */

/* Attempt to allcoate memory for a switch. */
if ((h_switch = malloc (sizeof(*h_switch)))==NULL) v_error(errno, "Memory allocation failed!");
if ((h_switch = malloc (sizeof(*h_switch)))==NULL) v_error(errno, h_err_memmory_alloc, __FILE__, __LINE__);

h_switch->index = i_index;
h_switch->on = s_on;
Expand Down
6 changes: 4 additions & 2 deletions src/x11-calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
* ratio - MT
* 14 Apr 24 - Fixed zoom validation and checks that zoom value has
* been specified - MT
* 18 Apr 24 - Checks for undefined labels when updating indicators
* on the display (fixed segmentation fault) - MT
*
* To Do - Fix vertical button shape when zoomed in
* - Parse command line in a separate routine.
Expand All @@ -309,8 +311,8 @@

#define NAME "x11-calc"
#define VERSION "0.14"
#define BUILD "0147"
#define DATE "13 Apr 24"
#define BUILD "0148"
#define DATE "18 Apr 24"
#define AUTHOR "MT"

#define INTERVAL 25 /* Number of ticks to execute before updating the display */
Expand Down
4 changes: 2 additions & 2 deletions src/x11-keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* x11-keyboard.h - An X11 keyboard class.
*
* Copyright(C) 2021 MT
*
*
* A very simple keyboard 'class' to translate keystrokes into basic ASCII
* character codes using the key definitions in keysymdef.h.
* character codes using the key definitions in keysymdef.h.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
Expand Down

0 comments on commit ec88b9a

Please sign in to comment.