Skip to content

Commit

Permalink
Change font sizes from short to fix31
Browse files Browse the repository at this point in the history
font->size (short) has been renamed and is now replaced with font->extra.size (fix31).
Many C interfaces are now changed to take fix31 sizes, and to convert back to short when
necessary.

New assembly macros are added for fix31<->short conversions, and to slightly improve
readability. The GNU macros are tested, which also work with PortAsm. The other macro
versions are hopefully correct.

vst_arbpt32() is now supported correctly. Papyrus uses this a lot.
  • Loading branch information
chrisridd authored and mfro0 committed May 13, 2022
1 parent e467056 commit 60934b6
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 82 deletions.
10 changes: 6 additions & 4 deletions fvdi/engine/fonts.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ long DRIVER_EXPORT fixup_font(Fontheader *header, char *buffer, long flip)

if (flip)
{
flip_words(&header->id, (&header->size - &header->id) + 1);
flip_words(&header->id, (&header->dummy - &header->id) + 1);
flip_words(&header->code.low, (&header->flags - &header->code.low) + 1);
flip_longs(&header->table.horizontal,
((long)&header->data - (long)&header->table.horizontal) / sizeof(long) + 1);
Expand All @@ -112,6 +112,7 @@ long DRIVER_EXPORT fixup_font(Fontheader *header, char *buffer, long flip)
header->extra.distance.descent = -top - header->distance.descent;
header->extra.distance.top = 0;

header->extra.size = SHORT_TO_FIX31(header->dummy);
header->extra.format = 0x01; /* 1 - Bitmap, 2 - Speedo etc */

header->extra.unpacked.data = 0; /* No smart formats yet */
Expand Down Expand Up @@ -175,7 +176,8 @@ Fontheader *load_font(const char *name)
long DRIVER_EXPORT insert_font(Fontheader **first_font, Fontheader *new_font)
{
Fontheader *current_font, *last_font, **previous;
int new_id, new_size;
int new_id;
fix31 new_size;

/*
* Find first font with higher or equal ID
Expand Down Expand Up @@ -216,9 +218,9 @@ long DRIVER_EXPORT insert_font(Fontheader **first_font, Fontheader *new_font)
* Find first font with larger or equal size
*/

new_size = new_font->size;
new_size = new_font->extra.size;
last_font = 0;
while (current_font && (current_font->size < new_size))
while (current_font && (current_font->extra.size < new_size))
{
last_font = current_font;
current_font = current_font->extra.next_size;
Expand Down
4 changes: 2 additions & 2 deletions fvdi/engine/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Fontheader *(*external_load_font)(Virtual *vwk, const char *font) = ft2_load_fon
long (*external_vqt_extent)(Virtual *vwk, Fontheader *font, short *text, long length) = ft2_text_width;
long (*external_vqt_width)(Virtual *vwk, Fontheader *font, long ch) = ft2_char_width;
long (*external_vst_effects)(Virtual *vwk, Fontheader *font, long effects) = ft2_set_effects;
Fontheader *(*external_vst_point)(Virtual *vwk, long size, short *sizes) = ft2_vst_point;
Fontheader *(*external_vst_point)(Virtual *vwk, fix31 size, short *sizes) = ft2_vst_point;
long (*external_renderer)(Virtual *vwk, unsigned long coords, short *text, long length) = ft2_text_render_default;
void *(*external_char_bitmap)(Virtual *vwk, Fontheader *font, long ch, short *bitmap_info) = ft2_char_bitmap;
void *(*external_char_advance)(Virtual *vwk, Fontheader *font, long ch, short *advance_info) = ft2_char_advance;
Expand All @@ -54,7 +54,7 @@ Fontheader *(*external_load_font)(Virtual *vwk, const char *font) = 0;
long (*external_vqt_extent)(Virtual *vwk, Fontheader *font, short *text, long length) = 0;
long (*external_vqt_width)(Virtual *vwk, Fontheader *font, long ch) = 0;
long (*external_vst_effects)(Virtual *vwk, Fontheader *font, long effects) = 0;
Fontheader *(*external_vst_point)(Virtual *vwk, long size, short *sizes) = 0;
Fontheader *(*external_vst_point)(Virtual *vwk, fix31 size, short *sizes) = 0;
long (*external_renderer)(Virtual *vwk, unsigned long coords, short *text, long length) = 0;
void *(*external_char_bitmap)(Virtual *vwk, Fontheader *font, long ch, short *bitmap_info) = 0;
void *(*external_char_advance)(Virtual *vwk, Fontheader *font, long ch, short *advance_info) = 0;
Expand Down
39 changes: 27 additions & 12 deletions fvdi/engine/text_sq.s
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ vst_height:
movem.l d0-d2/a0-a2,-(a7)
move.l _vdi_stack_size,-(a7)
move.l #0,-(a7)
ext.l d0
ext.l d0
move.l d0,-(a7)
move.l a0,-(a7) ; VDI struct
jsr (a3)
Expand Down Expand Up @@ -925,9 +925,17 @@ vst_arbpt:
pea 4(a2)
pea 2(a2)
pea 0(a2)
move.l control(a1),a2
cmp.w #2,L_intin(a2) ; 2 = vst_arbpt32(), 1 = vst_arbpt()
move.l intin(a1),a2
bne short_height
move.l (a2),d0
bra got_height
short_height:
move.w (a2),d0
ext.l d0
swap d0
got_height:
move.l d0,-(a7)
move.l a0,-(a7)
jsr _lib_vst_arbpt
Expand All @@ -936,16 +944,24 @@ vst_arbpt:
endc
add.w #6*4,a7
movem.l (a7)+,d2/a1
move.l control(a1),a2
cmp.w #2,L_intin(a2) ; 2 = vst_arbpt32(), 1 = vst_arbpt()
move.l intout(a1),a2
bne short_return
move.l d0,(a2)
bra got_return
short_return:
swap d0
move.w d0,(a2)
got_return:
used_d1
done_return

ifne 0
uses_d1
move.l a3,-(a7)
move.l intin(a1),a2
move.w (a2),d0
short_to_fix31 (a2),d0
move.l vwk_text_current_font(a0),a2

* Some other method should be used for this!
Expand All @@ -963,7 +979,6 @@ vst_arbpt:
movem.l d0-d2/a0-a2,-(a7)
move.l _vdi_stack_size,-(a7)
move.l #0,-(a7)
ext.l d0
move.l d0,-(a7)
move.l a0,-(a7) ; VDI struct
jsr (a3)
Expand Down Expand Up @@ -991,7 +1006,8 @@ vst_arbpt:
move.w font_height(a3),d1
move.w d1,(a2)+ ; Height in pixels
move.l d1,vwk_text_cell(a0) ; Cell w/h in vwk
move.w font_size(a3),(a1)
move.l font_extra_size(a3),d1
fix31_to_short d1,(a1)

.no_external_vst_arbpt:
move.l (a7)+,a3
Expand All @@ -1014,8 +1030,7 @@ vst_point:
pea 2(a2)
pea 0(a2)
move.l intin(a1),a2
move.w (a2),d0
ext.l d0
short_to_fix31 (a2),d0
move.l d0,-(a7)
move.l a0,-(a7)
jsr _lib_vst_point
Expand All @@ -1025,7 +1040,7 @@ vst_point:
add.w #6*4,a7
movem.l (a7)+,d2/a1
move.l intout(a1),a2
move.w d0,(a2)
fix31_to_short d0,(a2)
used_d1
ifne 0
move.l vwk_text_current_font(a0),a0
Expand All @@ -1044,7 +1059,7 @@ vst_point:
uses_d1
move.l a3,-(a7)
move.l intin(a1),a2
move.w (a2),d0
short_to_fix31 (a2),d0
move.l vwk_text_current_font(a0),a2

* Some other method should be used for this!
Expand All @@ -1054,7 +1069,7 @@ vst_point:
move.l font_extra_first_size(a2),a2
move.l a2,a3
label .search,1
cmp.w font_size(a2),d0
cmp.l font_extra_size(a2),d0
lblo .found,2
move.l a2,a3
move.l font_extra_next_size(a2),a2
Expand Down Expand Up @@ -1082,7 +1097,8 @@ vst_point:
move.w font_height(a3),d1
move.w d1,(a2)+ ; Height in pixels
move.l d1,vwk_text_cell(a0) ; Cell w/h in vwk
move.w font_size(a3),(a1)
move.l font_extra_size(a3),d1
fix31_to_short d1,(a1)
move.l (a7)+,a3
used_d1
ifne 0
Expand Down Expand Up @@ -1110,8 +1126,7 @@ vst_point:
movem.l d0-d2/a0-a2,-(a7)
move.l _vdi_stack_size,-(a7)
pea _sizes
ext.l d0
move.l d0,-(a7)
short_to_fix31 d0,-(a7)
move.l a0,-(a7) ; VDI struct
jsr (a3)
add.w #4*4,a7
Expand Down
21 changes: 11 additions & 10 deletions fvdi/engine/textlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ static Fontheader *find_font_by_id(Fontheader *font, long id, long *index)
int lib_vst_font(Virtual *vwk, long fontID)
{
Fontheader *font;
short dummy, size;
short dummy;
fix31 size;

if (!fontID)
fontID = 1;
Expand All @@ -194,9 +195,9 @@ int lib_vst_font(Virtual *vwk, long fontID)
}

if (vwk->text.current_font)
size = vwk->text.current_font->size;
size = vwk->text.current_font->extra.size;
else
size = 10;
size = SHORT_TO_FIX31(10);

vwk->text.font = fontID;
set_current_font(vwk, font);
Expand Down Expand Up @@ -377,7 +378,7 @@ void CDECL lib_vqt_xfntinfo(Virtual *vwk, long flags, long id, long index, XFNT_
font = font->extra.first_size;
while (font)
{
info->pt_sizes[i] = font->size;
info->pt_sizes[i] = FIX31_TO_SHORT(font->extra.size);
i++;
font = font->extra.next_size;
}
Expand Down Expand Up @@ -568,7 +569,7 @@ void CDECL lib_vqt_extent(Virtual *vwk, long length, short *string, short *point
}


int lib_vst_point(Virtual *vwk, long height, short *charw, short *charh, short *cellw, short *cellh)
fix31 lib_vst_point(Virtual *vwk, fix31 height, short *charw, short *charh, short *cellw, short *cellh)
{
Fontheader *font;

Expand All @@ -591,7 +592,7 @@ int lib_vst_point(Virtual *vwk, long height, short *charw, short *charh, short *
{
font = vwk->text.current_font->extra.first_size;

while (font->extra.next_size && (font->extra.next_size->size <= height))
while (font->extra.next_size && (font->extra.next_size->extra.size <= height))
{
font = font->extra.next_size;
}
Expand All @@ -604,11 +605,11 @@ int lib_vst_point(Virtual *vwk, long height, short *charw, short *charh, short *
*cellw = vwk->text.cell.width = font->widest.cell;
*cellh = vwk->text.cell.height = font->height;

return font->size;
return font->extra.size;
}


int CDECL lib_vst_arbpt(Virtual *vwk, long height, short *charw, short *charh, short *cellw, short *cellh)
fix31 CDECL lib_vst_arbpt(Virtual *vwk, fix31 height, short *charw, short *charh, short *cellw, short *cellh)
{
Fontheader *font;

Expand All @@ -631,7 +632,7 @@ int CDECL lib_vst_arbpt(Virtual *vwk, long height, short *charw, short *charh, s
{
font = vwk->text.current_font->extra.first_size;

while (font->extra.next_size && (font->extra.next_size->size <= height))
while (font->extra.next_size && (font->extra.next_size->extra.size <= height))
{
font = font->extra.next_size;
}
Expand All @@ -644,7 +645,7 @@ int CDECL lib_vst_arbpt(Virtual *vwk, long height, short *charw, short *charh, s
*cellw = vwk->text.cell.width = font->widest.cell;
*cellh = vwk->text.cell.height = font->height;

return font->size;
return font->extra.size;
}


Expand Down
6 changes: 3 additions & 3 deletions fvdi/include/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void init_interrupts(void);
void reset_interrupts(void);

int lib_vst_font(Virtual *vwk, long fontID);
int lib_vst_point(Virtual *vwk, long height, short *charw, short *charh, short *cellw, short *cellh);
fix31 lib_vst_point(Virtual *vwk, fix31 height, short *charw, short *charh, short *cellw, short *cellh);
void lib_vrt_cpyfm_nocheck(Virtual *vwk, short mode, short *pxy, MFDB *src, MFDB *dst, short colors[]);
void lib_vro_cpyfm(Virtual *vwk, short mode, short *pxy, MFDB *src, MFDB *dst);
void lib_vs_clip(Virtual *, short, short *);
Expand All @@ -91,7 +91,7 @@ long CDECL lib_vqt_name(Virtual * vwk, long number, short *name);
void CDECL lib_vqt_fontinfo(Virtual *vwk, short *intout, short *ptsout);
void CDECL lib_vqt_xfntinfo(Virtual *vwk, long flags, long id, long index, XFNT_INFO *info);
void CDECL lib_vqt_fontheader(Virtual *vwk, VQT_FHDR *fhdr);
int CDECL lib_vst_arbpt(Virtual *vwk, long height, short *charw, short *charh, short *cellw, short *cellh);
fix31 CDECL lib_vst_arbpt(Virtual *vwk, fix31 height, short *charw, short *charh, short *cellw, short *cellh);
void CDECL lib_vqt_attributes(Virtual * vwk, short *settings);
unsigned short CDECL lib_vqt_char_index(Virtual *vwk, short *intin);
short CDECL lib_vst_charmap(Virtual *vwk, long mode);
Expand All @@ -113,7 +113,7 @@ extern void (*external_term) (void);
extern Fontheader* (*external_load_font)(Virtual *vwk, const char *font);
extern long (*external_vqt_extent)(Virtual *vwk, Fontheader *font, short *text, long length);
extern long (*external_vqt_width)(Virtual *vwk, Fontheader *font, long ch);
extern Fontheader* (*external_vst_point)(Virtual *vwk, long size, short *sizes);
extern Fontheader* (*external_vst_point)(Virtual *vwk, fix31 size, short *sizes);
extern long (*external_renderer)(Virtual *vwk, unsigned long coords,
short *text, long length);
extern void* (*external_char_bitmap)(Virtual *vwk, Fontheader *font, long ch, short *bitmap_info);
Expand Down
7 changes: 6 additions & 1 deletion fvdi/include/fvdi.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ typedef struct DrvLine_ {
long draw_last;
} DrvLine;

typedef long fix31;
#define SHORT_TO_FIX31(X) ((long)(X) << 16)
#define FIX31_TO_SHORT(X) (short)((((long)(X) + 0x8000L) >> 16))

typedef struct Fontcharmap_ {
short id; /* charmap header ('00',01,02,10,11,12,TT,T1) */
short map[224]; /* mapping information d = map[s-32] like */
Expand Down Expand Up @@ -227,6 +231,7 @@ typedef struct Fontextra_ {

short ref_count; /* Reference count (dispose if 0) */

fix31 size; /* Font size */
short format; /* Returned by vqt_xfntinfo() and vqt_ext_name() */

/* Vector fonts */
Expand All @@ -242,7 +247,7 @@ typedef struct Fontextra_ {

typedef struct Fontheader_ {
short id; /* Face identifier */
short size; /* Font size in points */
short dummy; /* See extra.size for the font size */
char name[32]; /* Face name */
struct code_ {
short low; /* Lowest ASCII value in face */
Expand Down
21 changes: 21 additions & 0 deletions fvdi/include/macros.dev
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ done_return macro
endc
endm

* Convert from a 16 bit size to fix31
short_to_fix31 macro
ifc \1,\2
swap \2
clr.w \2
else
moveq #0,\2
move.w \1,\2
swap \2
endc
endm

* Convert from fix31 to a 16 bit size, rounding up
fix31_to_short macro
addi.l #$8000,\1
swap \1
ifnc \1,\2
move.w \1,\2
endc
endm

ijsr macro indirect
ifd mc68000
pea \@
Expand Down
21 changes: 21 additions & 0 deletions fvdi/include/macros.gnu
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@
.endif
.endm

* Convert from a 16 bit size to fix31
.macro short_to_fix31 src dst
.ifc \src,\dst
swap \dst
clr.w \dst
.else
moveq #0,\dst
move.w \src,\dst
swap \dst
.endif
.endm

* Convert from fix31 to a 16 bit size, rounding up
.macro fix31_to_short src dst
addi.l #0x8000,\src
swap \src
.ifnc \src,\dst
move.w \src,\dst
.endif
.endm

.macro ijsr indirect
.if mc68000 == 1
pea ret\@
Expand Down
Loading

0 comments on commit 60934b6

Please sign in to comment.