Skip to content

Commit

Permalink
Support Write Protect in Disk2 load dialog, etc
Browse files Browse the repository at this point in the history
Also fixes a crashing bug in cg.c, and various other bits.
  • Loading branch information
buserror committed Feb 14, 2024
1 parent 01619cf commit 5650323
Show file tree
Hide file tree
Showing 21 changed files with 444 additions and 51 deletions.
6 changes: 5 additions & 1 deletion contrib/mii-icon-64.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* this file is auto-generated by icon-convert-tcc.c */
static const unsigned long mii_icon64[] = {
#define MII_ICON64_SIZE 4098
extern const unsigned long mii_icon64[MII_ICON64_SIZE];
#ifdef MII_ICON64_DEFINE
const unsigned long mii_icon64[MII_ICON64_SIZE] = {
64,64,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
Expand Down Expand Up @@ -578,3 +581,4 @@ static const unsigned long mii_icon64[] = {
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,

};
#endif
1 change: 1 addition & 0 deletions libmui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ $(LIB)/ui_tests.so : $(OBJ)/mii_mui_slots.o
$(LIB)/ui_tests.so : $(OBJ)/mii_mui_loadbin.o
$(LIB)/ui_tests.so : $(OBJ)/mii_mui_1mb.o
$(LIB)/ui_tests.so : $(OBJ)/mii_mui_2dsk.o
$(LIB)/ui_tests.so : $(OBJ)/mii_mui_about.o

# use a .temp file, otherwise the playground tries to reload before the file
# is fully written, and it fails.
Expand Down
29 changes: 28 additions & 1 deletion libmui/mui/cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ static struct cg_rle_t * cg_rle_intersection(struct cg_rle_t * a, struct cg_rle_
struct cg_span_t * a_end = a_spans + a->spans.size;
struct cg_span_t * b_spans = b->spans.data;
struct cg_span_t * b_end = b_spans + b->spans.size;
int overflow = 0;
while((a_spans < a_end) && (b_spans < b_end))
{
if(b_spans->y > a_spans->y)
Expand Down Expand Up @@ -1040,6 +1041,24 @@ static struct cg_rle_t * cg_rle_intersection(struct cg_rle_t * a, struct cg_rle_
if(len)
{
struct cg_span_t * span = result->spans.data + result->spans.size;
if (result->spans.size >= result->spans.capacity)
{
/* This is a workaround, I've had a case where the size
overflows by quite a bit. See note at the end of this
function. In any case this doesn't hurt, and it prevents
a crash in this situation.
Not familiar enough with the codebase to know if this
is a bug or not. */
#if 0
printf("cg_array_ensure detected overflow!!\na:%d b:%d r:%d/%d (len %d)\n",
a->spans.size, b->spans.size,
result->spans.size,
result->spans.capacity, len);
#endif
cg_array_ensure(result->spans, result->spans.size + 1);
span = result->spans.data + result->spans.size;
overflow = 1;
}
span->x = x;
span->len = len;
span->y = a_spans->y;
Expand Down Expand Up @@ -1079,7 +1098,15 @@ static struct cg_rle_t * cg_rle_intersection(struct cg_rle_t * a, struct cg_rle_
result->y = y1;
result->w = x2 - x1;
result->h = y2 - y1 + 1;

if (overflow) {
/* I have a case which displays this
cg_rle_intersection detected overflow!!
a:960 b:524 r:1098/4096
printf("cg_rle_intersection detected overflow!!\n\ta:%d b:%d r:%d/%d\n",
a->spans.size, b->spans.size,
result->spans.size, result->spans.capacity);
*/
}
return result;
}

Expand Down
11 changes: 10 additions & 1 deletion libmui/mui/mui.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ mui_font_textbox(
mui_color_t color,
uint16_t flags );

DECLARE_C_ARRAY(stb_ttc_g*, mui_glyph_array, 8, int x, y, w; );
DECLARE_C_ARRAY(unsigned int, mui_glyph_array, 8, int x, y, w; );
DECLARE_C_ARRAY(mui_glyph_array_t, mui_glyph_line_array, 8);

/*
Expand Down Expand Up @@ -522,6 +522,15 @@ typedef struct mui_window_t {
/*
* Window related
*/
/*
* This is the main function to create a window. The
* * 'wdef' is the window definition (or NULL for a default window).
* see mui_wdef_p for the callback definition.
* * 'layer' layer to put it in (default to zero for normal windows)
* * 'instance_size' zero (for default) or the size of the window instance
* object that is returned, you can therefore have your own custom field
* attached to a window.
*/
mui_window_t *
mui_window_create(
struct mui_t * ui,
Expand Down
4 changes: 3 additions & 1 deletion libmui/mui/mui_cdef_buttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ mui_check_rad_draw(
}
mui_font_textbox(main, dr,
title, c->title, 0,
mui_control_color[0].text,
c->state == MUI_CONTROL_STATE_DISABLED ?
mui_control_color[c->state].text :
mui_control_color[0].text,
MUI_TEXT_ALIGN_MIDDLE);
mui_drawable_clip_pop(dr);
}
Expand Down
9 changes: 5 additions & 4 deletions libmui/mui/mui_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mui_font_from_mem(
f->size = size;
stb_ttc_LoadFont(&f->ttc, font_data, font_size);
TAILQ_INSERT_TAIL(&ui->fonts, f, self);
printf("%s: Loaded font %s:%d\n", __func__, name, size);
// printf("%s: Loaded font %s:%d\n", __func__, name, size);

return f;
}
Expand All @@ -73,7 +73,7 @@ void
mui_font_init(
mui_t *ui)
{
printf("%s: Loading fonts\n", __func__);
// printf("%s: Loading fonts\n", __func__);
mui_font_from_mem(ui, "main", 28,
mui_main_font_data, mui_main_font_size);
mui_font_from_mem(ui, "icon_large", 96,
Expand Down Expand Up @@ -241,7 +241,7 @@ mui_font_measure(
break;
}
line->w += gc->advance;
mui_glyph_array_push(line, gc);
mui_glyph_array_push(line, gc->index);
};
} while (text[ch] && ch < text_len);
int bh = 0;
Expand Down Expand Up @@ -308,7 +308,8 @@ mui_font_measure_draw(
mui_glyph_array_t * line = &lines->e[li];
int xpos = 0;//where.x / scale;
for (int ci = 0; ci < (int)line->count; ci++) {
stb_ttc_g *gc = line->e[ci];
unsigned int cache_index = line->e[ci];
stb_ttc_g *gc = &ttc->glyph[cache_index];
// int pxpos = gc->x0 + ((xpos + gc->lsb) * scale);
int pxpos = gc->x0 + ((xpos + 0) * scale);

Expand Down
1 change: 0 additions & 1 deletion libmui/mui/mui_stdfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ _mui_stdfile_window_action(
for (int i = 0; i < (int)std->pop_path.count; i++)
free(std->pop_path.e[i]);
std->pop_path.count = 0;

} break;
}
return 0;
Expand Down
10 changes: 5 additions & 5 deletions libmui/mui/mui_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <execinfo.h>

#include "mui_priv.h"
#include "cg.h"
Expand Down Expand Up @@ -127,7 +128,6 @@ mui_window_create(
TAILQ_INIT(&w->zombies);
STAILQ_INIT(&w->actions);
pixman_region32_init(&w->inval);

TAILQ_INSERT_HEAD(&ui->windows, w, self);
mui_window_select(w); // place it in it's own layer
mui_font_t * main = mui_font_find(ui, "main");
Expand Down Expand Up @@ -351,8 +351,8 @@ mui_window_inval(
pixman_region32_reset(&win->inval, (pixman_box32_t*)&frame);
forward = frame;

mui_window_t * w;
TAILQ_FOREACH(w, &win->ui->windows, self) {
mui_window_t * w, *save;
TAILQ_FOREACH_SAFE(w, &win->ui->windows, self, save) {
if (w == win || !c2_rect_intersect_rect(&w->frame, &forward))
continue;
pixman_region32_union_rect(&w->inval, &w->inval,
Expand Down Expand Up @@ -381,8 +381,8 @@ mui_window_front(
{
if (!ui)
return NULL;
mui_window_t * w;
TAILQ_FOREACH_REVERSE(w, &ui->windows, windows, self) {
mui_window_t * w, *save;
TAILQ_FOREACH_REVERSE_SAFE(w, &ui->windows, windows, self, save) {
if (w->flags.hidden)
continue;
if (w->flags.layer < MUI_WINDOW_MENUBAR_LAYER)
Expand Down
2 changes: 2 additions & 0 deletions libmui/mui/stb_ttc.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef struct stb_ttc_measure {
* scales in one cache.
*/
typedef struct stb_ttc_g {
unsigned int index; // index in global table
unsigned int intscale; // for comparison purpose
float scale;
unsigned int glyph;
Expand Down Expand Up @@ -296,6 +297,7 @@ stb_ttc__ScaledGlyphGetCache(
.glyph = glyph,
.index = ttc->g_count
};
gc.index = ttc->g_count;
ttc->g_count++;

unsigned int hash = glyph + (glyph * gc.intscale);
Expand Down
5 changes: 3 additions & 2 deletions libmui/tests/ui_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,15 @@ _init(
// mii_mui_load_1mbrom(g->ui, &g_machine_conf.slot[0].conf.rom1mb);
// mii_mui_load_2dsk(g->ui,
// &g_machine_conf.slot[0].conf.disk2, MII_2DSK_DISKII);
mii_mui_about(g->ui);
#if 0
mui_alert(ui, C2_PT(0,0),
"Testing one Two",
"Do you really want the printer to catch fire?\n"
"This operation cannot be cancelled.",
MUI_ALERT_WARN);
#endif
#if 1
#if 0
mui_stdfile_get(ui,
C2_PT(0, 0),
"Select image for SmartPort card",
Expand Down Expand Up @@ -233,4 +234,4 @@ mui_plug_t mui_plug = {
.dispose = _dispose,
.draw = _draw,
.event = _event,
};
};
29 changes: 24 additions & 5 deletions src/drivers/mii_disk2.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,39 @@ _mii_disk2_command(
if (param)
*(int *)param = 2;
break;
case MII_SLOT_DRIVE_LOAD ... MII_SLOT_DRIVE_LOAD + 2 - 1:
case MII_SLOT_DRIVE_WP ... MII_SLOT_DRIVE_WP + 2 - 1: {
int drive = cmd - MII_SLOT_DRIVE_WP;
int *wp = param;
if (wp) {
printf("Drive %d WP: 0x%x set %s\n", drive,
c->floppy[drive].write_protected,
*wp ? "ON" : "OFF");
c->floppy[drive].write_protected =
(c->floppy[drive].write_protected &
~(MII_FLOPPY_WP_MANUAL))|
(*wp ? MII_FLOPPY_WP_MANUAL : 0);
}
} break;
case MII_SLOT_DRIVE_LOAD ... MII_SLOT_DRIVE_LOAD + 2 - 1: {
int drive = cmd - MII_SLOT_DRIVE_LOAD;
const char *filename = param;
const char *pathname = param;
mii_dd_file_t *file = NULL;
if (filename && *filename) {
file = mii_dd_file_load(&mii->dd, filename, O_RDWR);
if (pathname && *pathname) {
if (c->drive[drive].file &&
!strcmp(c->drive[drive].file->pathname, pathname)) {
printf("%s D%d Same file, not reloading\n",
__func__, drive);
return 0;
}
file = mii_dd_file_load(&mii->dd, pathname, O_RDWR);
if (!file)
return -1;
}
// reinit all tracks, bits, maps etc
mii_floppy_init(&c->floppy[drive]);
mii_dd_drive_load(&c->drive[drive], file);
mii_floppy_load(&c->floppy[drive], file);
break;
} break;
}
return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions src/format/mii_floppy.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
// track containing random bits
#define MII_FLOPPY_RANDOM_TRACK_ID 35

/*
* Reasons for write protect. Ie checkbox in the UI, or file format
* doesn't support writes, or the file has no write permissions.
*/
enum {
MII_FLOPPY_WP_MANUAL = (1 << 0), // write protect by the user
MII_FLOPPY_WP_RO_FILE = (1 << 1), // file is read only
Expand Down
1 change: 1 addition & 0 deletions src/mii_slot.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ mii_slot_drv_find(
enum {
MII_SLOT_DRIVE_COUNT = 0x01,
MII_SLOT_DRIVE_LOAD = 0x20, // + drive index 0...n
MII_SLOT_DRIVE_WP = 0x30, // + drive index 0...n

MII_SLOT_SSC_SET_TTY = 0x10, // param is a pathname, or NULL for a pty
};
Expand Down
23 changes: 15 additions & 8 deletions ui_gl/mii_emu_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
#include "mii_thread.h"

#include "mii_mui.h"
#include "mii-icon-64.h"
#include "minipt.h"
#include "miigl_counter.h"
#define MII_ICON64_DEFINE
#include "mii-icon-64.h"

/*
* Note: This *assumes* that the GL implementation has support for non-power-of-2
Expand Down Expand Up @@ -348,7 +349,10 @@ mii_x11_init(
}
{
Atom net_wm_icon_atom = XInternAtom(ui->dpy, "_NET_WM_ICON", False);
XChangeProperty(ui->dpy, ui->win, net_wm_icon_atom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)mii_icon64, sizeof(mii_icon64) / sizeof(mii_icon64[0]));
XChangeProperty(ui->dpy, ui->win, net_wm_icon_atom, XA_CARDINAL,
32, PropModeReplace,
(unsigned char *)mii_icon64,
sizeof(mii_icon64) / sizeof(mii_icon64[0]));
XFlush(ui->dpy);
}
XMapWindow(ui->dpy, ui->win);
Expand Down Expand Up @@ -808,12 +812,15 @@ mii_ui_reconfigure_slot(
(void*)config->slot[i].conf.smartport.drive[1].disk);
} break;
case MII_SLOT_DRIVER_DISK2: {
mii_slot_command(mii, slot,
MII_SLOT_DRIVE_LOAD,
(void*)config->slot[i].conf.disk2.drive[0].disk);
mii_slot_command(mii, slot,
MII_SLOT_DRIVE_LOAD + 1,
(void*)config->slot[i].conf.disk2.drive[1].disk);
for (int di = 0; di < 2; di++) {
mii_slot_command(mii, slot,
MII_SLOT_DRIVE_LOAD + di,
(void*)config->slot[i].conf.disk2.drive[di].disk);
int wp = config->slot[i].conf.disk2.drive[di].wp;
mii_slot_command(mii, slot,
MII_SLOT_DRIVE_WP + di,
(void*)&wp);
}
} break;
case MII_SLOT_DRIVER_ROM1MB: {
mii_slot_command(mii, slot,
Expand Down
56 changes: 56 additions & 0 deletions ui_gl/mii_loadbin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* mii_loadbin.c
*
* Copyright (C) 2023 Michel Pollet <[email protected]>
*
* SPDX-License-Identifier: MIT
*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/inotify.h>
#include <pthread.h>

#include "mii.h"
#include "mii_bank.h"
#include "mii_mui_settings.h"


typedef struct mii_loadbin_t {
mii_t * mii;
pthread_t thread;

mii_loadbin_conf_t conf;
} mii_loadbin_t;

static mii_loadbin_t * _mii_loadbin = NULL;

static void *
mii_thread_loadbin(
void *arg)
{

return NULL;
}

mii_loadbin_t *
mii_loadbin_start(
struct mii_t *mii,
struct mii_loadbin_conf_t *conf)
{
mii_loadbin_t * res = NULL;
if (_mii_loadbin) {
return _mii_loadbin;
}
_mii_loadbin = res = calloc(1, sizeof(*res));
res->mii = mii;
res->conf = *conf;

pthread_create(&res->thread, NULL, mii_thread_loadbin, res);

return res;
}
Loading

0 comments on commit 5650323

Please sign in to comment.