Skip to content

Commit

Permalink
Latest 16 bit fixes (long div) and some design fixes. #672
Browse files Browse the repository at this point in the history
  • Loading branch information
Falk Rehwagen committed Oct 29, 2024
1 parent dd96d53 commit dd70c32
Show file tree
Hide file tree
Showing 14 changed files with 395 additions and 26 deletions.
6 changes: 4 additions & 2 deletions Appl/Saver/LastWords/lastwords.goc
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,10 @@ LWTimerStart(optr oself)
***********************************************************************/
@method LWApplicationClass, MSG_LW_APP_DRAW
{
LWDraw(oself);
LWTimerStart(oself);
if(pself->LWCI_randomToken != 0) {
LWDraw(oself);
LWTimerStart(oself);
}
}


Expand Down
27 changes: 25 additions & 2 deletions Driver/Font/TrueType/Adapter/ttcharmapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,15 @@ CharMapEntry geosCharMap[] =
* ---- ---- -----------
* 30.09.24 JK Initial Revision
*******************************************************************/

#pragma code_seg("Resident2")
word GeosCharToUnicode( const word geosChar )
{
if( geosChar < MIN_GEOS_CHAR || geosChar > MAX_GEOS_CHAR )
return 0;

return geosCharMap[ GEOS_CHAR_INDEX( geosChar ) ].unicode;
}
#pragma code_seg()


/********************************************************************
Expand All @@ -326,13 +327,15 @@ word GeosCharToUnicode( const word geosChar )
* 30.09.24 JK Initial Revision
*******************************************************************/

#pragma code_seg("Resident2")
CharMapFlags GeosCharMapFlag( const word geosChar )
{
if( geosChar < MIN_GEOS_CHAR || geosChar > MAX_GEOS_CHAR )
return 0;

return geosCharMap[ GEOS_CHAR_INDEX( geosChar ) ].flags;
}
#pragma code_seg()


/********************************************************************
Expand Down Expand Up @@ -437,7 +440,25 @@ EC( ECCheckBounds( lookupTable ) );
lookupTable[i].geoscode = (char)i + C_SPACE;
}

qsort( lookupTable, NUM_CHARMAPENTRIES, sizeof( LookupEntry ), compareLookupEntries );
//qsort( lookupTable, NUM_CHARMAPENTRIES, sizeof( LookupEntry ), compareLookupEntries );
{
int a = 0;
while(a < NUM_CHARMAPENTRIES) {

int b = 0;
while(b < NUM_CHARMAPENTRIES) {

if(compareLookupEntries(&lookupTable[a], &lookupTable[b]) < 0) {

LookupEntry temp = lookupTable[a];
lookupTable[a] = lookupTable[b];
lookupTable[b] = temp;
}
b++;
}
a++;
}
}

MemUnlock( memHandle );
return memHandle;
Expand Down Expand Up @@ -479,6 +500,7 @@ static int _pascal compareLookupEntries( const void *a, const void *b )
* ---- ---- -----------
* 30.09.24 JK Initial Revision
*******************************************************************/
#pragma code_seg("Resident2")

word GetGEOSCharForIndex( const LookupEntry* lookupTable, const word index )
{
Expand All @@ -499,3 +521,4 @@ word GetGEOSCharForIndex( const LookupEntry* lookupTable, const word index )
return 0;
}

#pragma code_seg()
6 changes: 3 additions & 3 deletions Driver/Font/TrueType/Adapter/ttwidths.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ static void FillKerningFlags( FontHeader* fontHeader, FontBuf* fontBuf )
word indexLeftChar = kernPair[i].KP_charLeft - fontHeader->FH_firstChar;
word indexRightChar = kernPair[i].KP_charRight - fontHeader->FH_firstChar;

charTableEntry[indexLeftChar].CTE_flags |= CTF_IS_FIRST_KERN;
charTableEntry[indexRightChar].CTE_flags |= CTF_IS_SECOND_KERN;
//charTableEntry[indexLeftChar].CTE_flags |= CTF_IS_FIRST_KERN;
//charTableEntry[indexRightChar].CTE_flags |= CTF_IS_SECOND_KERN;
}
}

Expand Down Expand Up @@ -429,7 +429,7 @@ EC( ECCheckBounds( (void*)kernValue ) );
if( TT_Get_Kerning_Directory( FACE, &kerningDir ) )
return;

if( kerningDir.nTables == 0 )
if( (kerningDir.nTables == 0 ) || (kernPair == fontBuf) || (kernValue == fontBuf) )
return;

/* get pointer to lookup table */
Expand Down
2 changes: 1 addition & 1 deletion Driver/Font/TrueType/FreeType/ft_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
/* emerged recently on the FreeType lists. We still do not have Apple's */
/* opinion on the subject and will change this as soon as we have. */

//#define TT_CONFIG_OPTION_NO_INTERPRETER
#define TT_CONFIG_OPTION_NO_INTERPRETER


/*************************************************************************/
Expand Down
185 changes: 177 additions & 8 deletions Driver/Font/TrueType/Main/ansic_runtime.asm
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ ttcalc_TEXT SEGMENT BYTE PUBLIC 'CODE'
;
; Note: This is a temporary implementation. This function must be reimplemented in 8086 assembler instructions.

.386
;.386
__U4D proc far

if 0
shl edx, 16 ;edx <- high dividend
mov dx, ax ;dx <- low dividend

Expand All @@ -102,8 +102,136 @@ ttcalc_TEXT SEGMENT BYTE PUBLIC 'CODE'

mov edx, eax ;ax <- low qoutient
shr edx, 16 ;dx <- high qoutient
ret
endif
or cx,cx ; check for easy case
jne noteasy ; easy if divisor is 16 bit
dec bx ; decrement divisor
jz done ; if not dividing by 1
inc bx ; - put divisor back
cmp bx, dx ; - if quotient will be >= 64K
jg lowpart
;
; 12-aug-88, added thanks to Eric Christensen from Fox Software
; divisor < 64K, dividend >= 64K, quotient will be >= 64K
;
; *note* this sequence is used in ltoa's #pragmas; any bug fixes
; should be reflected in ltoa's code bursts
;
mov cx, ax ; - - save low word of dividend
mov ax, dx ; - - get high word of dividend
sub dx, dx ; - - zero high part
div bx ; - - divide bx into high part of dividend
xchg ax, cx ; - - swap high part of quot,low word of dvdnd

lowpart:
div bx ; - calculate low part
mov bx, dx ; - get remainder
mov dx, cx ; - get high part of quotient
sub cx, cx ; - zero high part of remainder

ret ; return


noteasy: ; have to work to do division
;
; check for divisor > dividend
;
cmp cx, dx ; - quit if divisor <= dividend
jb smaller
jne notequal
cmp bx, ax ; - - compare the lower order words
ja notequal ; - - if divisor <= dividend
sub ax, bx ; - - - calulate remainder
mov bx, ax ; - - - ...
sub cx, cx ; - - - ...
sub dx, dx ; - - - quotient = 1
mov ax, 1 ; - - - ...
ret ; - - - return

notequal:
sub cx,cx ; - set divisor = 0 (this will be quotient)
sub bx,bx ; - ...
xchg ax,bx ; - return remainder = dividend
xchg dx,cx ; - and quotient = 0
ret ; - return

smaller:
; SJHowe 24-01-2000
;
; At this point here what is known is that cx > 0 and dx > cx. At the very
; least cx is 1 and dx 2.
;
; Consider the quotient
;
; The maximum it can be is when division is
;
; FFFF:FFFF / 0001:0000
;
; The minimum it can be is when division is
;
; 0002:0000 / 0001:FFFF
;
; Doing the division reveals the quotient lies 1 between FFFF. It cannot
; exceed FFFF. Therefore there is no need to keep track of the quotient's
; high word, it is always 0.
;
; Accordingly register DI has been eliminated below
;
; Should make algoritm a little faster.
;
; SJHowe 24-01-2000

push bp ; save work registers
push si ; ...
sub si, si ; zero quotient
mov bp, si ; and shift count
moveup: ; loop until divisor > dividend
shl bx, 1 ; - divisor *= 2
rcl cx, 1 ; - ...

jc backup ; - know its bigger if carry out
inc bp ; - increment shift count
cmp cx, dx ; - check if its bigger yet
jb moveup ; - no, keep going
ja divlup ; - if below, know we're done
cmp bx, ax ; - check low parts (high parts equal)
jbe moveup ; until divisor > dividend
divlup: ; division loop
clc ; clear carry for rotate below
loop1: ; loop
rcl si, 1 ; - - shift bit into quotient
dec bp ; - - quif( -- shift < 0 ) NB carry not changed
js donediv ; - - ...
backup: ; - - entry to remove last shift
rcr cx, 1 ; - - divisor /= 2 (NB also used by 'backup')
rcr bx, 1 ; - - ...
sub ax, bx ; - - dividend -= divisor
sbb dx, cx ; - - c=1 iff it won't go
cmc ; - - c=1 iff it will go
jc loop1 ; - until it won't go
loop2:
shl si, 1 ; - - shift 0 into quotient
dec bp ; - - going to add, check if done
js toomuch ; - - if done, we subtracted to much
shr cx, 1 ; - - divisor /= 2
rcr bx, 1 ; - - ...
add ax, bx ; - - dividend += divisor
adc dx, cx ; - - c = 1 iff bit of quotient should be 1
jnc loop2 ; - until divisor will go into dividend
jmp loop1
toomuch: ; we subtracted too much
add ax, bx ; dividend += divison
adc dx, cx ; ...
donediv: ; now quotient in si, remainder in dx;ax
mov bx, ax ; move remainder to cx;bx
mov cx, dx ; ...
mov ax, si ; move quotient to dx;ax
xor dx, dx ; ...
pop si ; restore registers
pop bp ; ...
done:
ret ; Return
__U4D endp

; __I4D
Expand All @@ -119,10 +247,9 @@ ttcalc_TEXT SEGMENT BYTE PUBLIC 'CODE'
; cx:bx remainder
;
; Note: This is an implementation with 80386.
.386
; .386
__I4D proc far

if 0
shl edx, 16 ;edx <- high dividend
mov dx, ax ;dx <- low dividend

Expand All @@ -140,7 +267,49 @@ ttcalc_TEXT SEGMENT BYTE PUBLIC 'CODE'

mov edx, eax ;ax <- low qoutient
shr edx, 16 ;dx <- high qoutient
endif
or dx, dx ; check sign of dividend
js divneg ; handle case where dividend < 0
or cx, cx ; check sign of divisor
jns __U4D ; jump if positive 24-jan-00

; dividend >= 0, divisor < 0
notU4D: neg cx ; take positive value of divisor
neg bx ; ...
sbb cx, 0 ; ...
call __U4D ; do unsigned division
neg dx ; negate quotient
neg ax ; ...
sbb dx, 0 ; ...
ret ; and return

divneg: ; dividend is negative
neg dx ; take absolute value of dividend
neg ax ; ...
sbb dx, 0 ; ...
or cx, cx ; check sign of divisor
jns negres ; negative result if divisor > 0

; dividend < 0, divisor < 0
neg cx ; negate divisor too
neg bx ; ...
sbb cx, 0 ; ...
call __U4D ; and do unsigned division
neg cx ; negate remainder
neg bx ; ...
sbb cx, 0 ; ...
ret ; and return

; dividend < 0, divisor >= 0
negres: call __U4D ; do unsigned division
neg cx ; negate remainder
neg bx ; ...
sbb cx, 0 ; ...
neg dx ; negate quotient
neg ax ; ...
sbb dx, 0 ; ...
ret ; Return

ret
__I4D endp

Expand Down
2 changes: 1 addition & 1 deletion Driver/Font/TrueType/Main/truetypeConstant.def
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ SCRIPT_SAFETY_SIZE = 10

TRUETYPE_BLOCK_SIZE equ 1024 ;initial block size

FONT_C_CODE_STACK_SPACE = 1000
FONT_C_CODE_STACK_SPACE = 1200


;----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Driver/Font/TrueType/Main/truetypeWidths.asm
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TrueTypeGenWidths proc far
.enter

xchg di, ax
mov di, 800
mov di, 1400
call ThreadBorrowStackSpace
push di

Expand Down
4 changes: 4 additions & 0 deletions Driver/Font/TrueType/truetype.gp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ usernotes "#FreeGEOS font driver to render TrueType fonts."
# Define resources other than standard discardable code
#
resource Resident fixed code read-only shared
resource Resident2 fixed code read-only shared
resource ttcmap_TEXT fixed code read-only shared
resource ttmemory_TEXT fixed code read-only shared
resource ttcalc_TEXT fixed code read-only shared
resource InitMod code read-only shared discard-only


Expand Down
2 changes: 2 additions & 0 deletions Include/geos.def
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,8 @@ if <useReg> ne <> ;and \
; the latter case, we assume the programmer knows what s/he is doing)
mov useReg, sourceSeg
mov destSeg, useReg
elseif <destSeg> eq <ax>
mov destSeg, sourceSeg
else
push ax
mov ax, sourceSeg
Expand Down
Loading

0 comments on commit dd70c32

Please sign in to comment.