Skip to content

Commit

Permalink
New about box. Also some fixes for some WOZ1 files
Browse files Browse the repository at this point in the history
AppleGalaxian failed to load because of a sparse track map.

Signed-off-by: Michel Pollet <[email protected]>
  • Loading branch information
buserror committed Feb 14, 2024
1 parent 5650323 commit d399b12
Show file tree
Hide file tree
Showing 10 changed files with 316 additions and 27 deletions.
2 changes: 2 additions & 0 deletions libmui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ $(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

$(OBJ)/mii_mui_about.o : CPPFLAGS+=-DMII_ICON64_DEFINE

# use a .temp file, otherwise the playground tries to reload before the file
# is fully written, and it fails.
# the ${filter} are there to make the sure object files are linked before the .a
Expand Down
Binary file added libmui/fonts/Geneva.ttf
Binary file not shown.
9 changes: 7 additions & 2 deletions libmui/mui/mui.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,20 @@ mui_timer_reset(
if (id >= MUI_TIMER_COUNT)
return 0;
if (!(ui->timer.map & (1 << id)) ||
ui->timer.timers[id].cb != cb)
ui->timer.timers[id].cb != cb) {
printf("%s: timer %d not active\n", __func__, id);
return 0;
}
mui_time_t res = 0;
uint64_t now = mui_get_time();
if (ui->timer.timers[id].when > now)
res = ui->timer.timers[id].when - now;
ui->timer.timers[id].when = now + delay;
if (delay == 0)
if (delay == 0) {
ui->timer.map &= ~(1 << id);
printf("%s: timer %d removed\n", __func__, id);
}

return res;
}

Expand Down
24 changes: 23 additions & 1 deletion libmui/mui/mui.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,16 @@ typedef struct mui_drawable_t {
struct cg_ctx_t * cg;
union pixman_image * pixman; // (try) not to use these directly
unsigned int pixman_clip_dirty: 1,
cg_clip_dirty : 1;
cg_clip_dirty : 1,
dispose_pixels : 1;
// (default) position in destination when drawing
c2_pt_t origin;
mui_clip_stack_t clip;
} mui_drawable_t;

// Use IMPLEMENT_C_ARRAY(mui_drawable_array); if you need this
DECLARE_C_ARRAY(mui_drawable_t *, mui_drawable_array, 4);

/*
* Drawable related
*/
Expand Down Expand Up @@ -425,6 +431,13 @@ mui_font_t *
mui_font_find(
struct mui_t * ui,
const char * name);
mui_font_t *
mui_font_from_mem(
struct mui_t * ui,
const char *name,
unsigned int size,
const void *font_data,
unsigned int font_size );
void
mui_font_text_draw(
mui_font_t * font,
Expand Down Expand Up @@ -473,6 +486,15 @@ mui_font_measure(
unsigned int text_len,
mui_glyph_line_array_t *lines,
uint16_t flags);
// to be used exclusively with mui_font_measure
void
mui_font_measure_draw(
mui_font_t *font,
mui_drawable_t *dr,
c2_rect_t bbox,
mui_glyph_line_array_t *lines,
mui_color_t color,
uint16_t flags);
// clear all the lines, and glyph lists. Use it after mui_font_measure
void
mui_font_measure_clear(
Expand Down
2 changes: 2 additions & 0 deletions libmui/mui/mui_drawable.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ mui_drawable_clear(
for (int i = 0; i < (int)dr->clip.count; i++)
pixman_region32_fini(&dr->clip.e[i]);
mui_clip_stack_clear(&dr->clip);
if (dr->pix.pixels && dr->dispose_pixels)
free(dr->pix.pixels);
dr->_pix_hash = NULL;
}

Expand Down
1 change: 1 addition & 0 deletions libmui/mui/mui_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
INCBIN(main_font, "fonts/Charcoal_mui.ttf");
INCBIN(icon_font, "fonts/typicon.ttf");
INCBIN(dingbat_font, "fonts/Dingbat.ttf");
INCBIN(geneva_font, "fonts/Geneva.ttf");

#include "mui.h"

Expand Down
9 changes: 4 additions & 5 deletions libmui/tests/ui_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,10 @@ _init(
m_cpu_menu);

// mii_mui_configure_slots(g->ui, &g_machine_conf);
// mii_mui_load_binary(g->ui, &g_loadbin_conf);
mii_mui_load_binary(g->ui, &g_loadbin_conf);
// 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);
// 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",
Expand Down Expand Up @@ -234,4 +233,4 @@ mui_plug_t mui_plug = {
.dispose = _dispose,
.draw = _draw,
.event = _event,
};
};
42 changes: 32 additions & 10 deletions src/format/mii_floppy.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,24 @@ mii_floppy_write_track_woz(
return 0;
}

static uint64_t
mii_floppy_woz_load_tmap(
mii_floppy_t *f,
mii_woz_tmap_t *tmap )
{
uint64_t used_tracks = 0;
int tmap_size = le32toh(tmap->chunk.size_le);
for (int ti = 0; ti < (int)sizeof(f->track_id) && ti < tmap_size; ti++) {
if (tmap->track_id[ti] == 0xff) {
f->track_id[ti] = MII_FLOPPY_RANDOM_TRACK_ID;
continue;
}
f->track_id[ti] = tmap->track_id[ti];
used_tracks |= 1L << f->track_id[ti];
}
return used_tracks;
}

static int
mii_floppy_load_woz(
mii_floppy_t *f,
Expand All @@ -221,12 +239,15 @@ mii_floppy_load_woz(
}
version += !strncmp((char*)header, "WOZ2", 4);
mii_woz_tmap_t *tmap = NULL;
uint64_t used_tracks = 0;

if (version == 1) {
mii_woz1_info_t *info = (mii_woz1_info_t *)(header + 1);
tmap = (mii_woz_tmap_t *)((uint8_t *)info +
le32toh(info->chunk.size_le) + sizeof(mii_woz_chunk_t));
mii_woz1_trks_t *trks = (mii_woz1_trks_t *)((uint8_t *)tmap +
le32toh(tmap->chunk.size_le) + sizeof(mii_woz_chunk_t));
used_tracks = mii_floppy_woz_load_tmap(f, tmap);
#if 1
printf("WOZ: version %d, type %d\n",
info->version, info->disk_type );
Expand All @@ -237,8 +258,13 @@ mii_floppy_load_woz(
printf("WOZ: Track chunk %4.4s size %d\n",
(char*)&trks->chunk.id_le, le32toh(trks->chunk.size_le));
#endif
for (int i = 0; i < 35; i++) {
int max_track = le32toh(trks->chunk.size_le) / sizeof(trks->track[0]);
for (int i = 0; i < 35 && i < max_track; i++) {
uint8_t *track = trks->track[i].bits;
if (!(used_tracks & (1L << i))) {
// printf("WOZ: Track %d not used\n", i);
continue;
}
memcpy(f->tracks[i].data, track, le16toh(trks->track[i].byte_count_le));
f->tracks[i].bit_count = le32toh(trks->track[i].bit_count_le);
}
Expand All @@ -248,6 +274,7 @@ mii_floppy_load_woz(
le32toh(info->chunk.size_le) + sizeof(mii_woz_chunk_t));
mii_woz2_trks_t *trks = (mii_woz2_trks_t *)((uint8_t *)tmap +
le32toh(tmap->chunk.size_le) + sizeof(mii_woz_chunk_t));
used_tracks = mii_floppy_woz_load_tmap(f, tmap);
#if 1
printf("WOZ: version %d, type %d, sides %d, largest track %d, optimal bit timing: %d\n",
info->version, info->disk_type, info->sides,
Expand All @@ -263,22 +290,17 @@ mii_floppy_load_woz(
/* TODO: this doesn't work yet... */
// f->bit_timing = info->optimal_bit_timing;
for (int i = 0; i < 35; i++) {
if (!(used_tracks & (1L << i))) {
// printf("WOZ: Track %d not used\n", i);
continue;
}
uint8_t *track = file->map +
(le16toh(trks->track[i].start_block_le) << 9);
uint32_t byte_count = (le32toh(trks->track[i].bit_count_le) + 7) >> 3;
memcpy(f->tracks[i].data, track, byte_count);
f->tracks[i].bit_count = le32toh(trks->track[i].bit_count_le);
}
}
// copy the track map from the file to the floppy
for (int ti = 0; ti < (int)sizeof(f->track_id); ti++) {
f->track_id[ti] = tmap->track_id[ti] == 0xff ?
MII_FLOPPY_RANDOM_TRACK_ID : tmap->track_id[ti];
if (f->tracks[f->track_id[ti]].bit_count == 0) {
printf("%s Invalid qtrack %d (points to track %d) has zero bits!\n",
__func__, ti, f->track_id[ti]);
}
}
return version;
}

Expand Down
Loading

0 comments on commit d399b12

Please sign in to comment.