-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCHARWDTH.ASM
executable file
·173 lines (142 loc) · 4.15 KB
/
CHARWDTH.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
page ,132
;-----------------------------Module-Header-----------------------------;
; Module Name: CHARWDTH.ASM
;
; This module contains the function GetCharWidth which returns the
; widths of a range of characters in a font
;
; Created: Thu 30-Apr-1987
; Author: **** ***** [*****]
;
; Copyright (c) 1987 Microsoft Corporation
;
; Exported Functions: GetCharWidth
;
; Public Functions: None
;
; Public Data: None
;
; General Description:
;
; Restrictions:
;
;-----------------------------------------------------------------------;
.xlist
include cmacros.inc
include gdidefs.inc
include macros.mac
include fontseg.inc
.list
createSeg _TEXTSTUFF,TextSeg,word,public,CODE
sBegin TextSeg
assumes cs,TextSeg
page
;--------------------------Exported-Routine-----------------------------;
; GetCharWidth
;
; Get Widths of a Range of Character
;
; The widths of characters within the given range are returned to
; the caller. Characters outside of the font's range will be given
; the width of the default character.
;
;
; Entry:
; None
; Returns:
; AX = 1 if success
; Error Returns:
; AX = 0 if error
; Registers Preserved:
; SI,DI,DS,BP
; Registers Destroyed:
; AX,BX,CX,DX,ES,FLAGS
; Calls:
; None
; History:
; Thu 30-Apr-1987 20:40:21 -by- **** ***** [*****]
; Created.
;-----------------------------------------------------------------------;
;------------------------------Pseudo-Code------------------------------;
; {
; }
;-----------------------------------------------------------------------;
assumes ds,Data
assumes es,nothing
cProc GetCharWidth,<FAR,PUBLIC,WIN,PASCAL>,<si,di>
parmD lp_device
parmD lp_buffer
parmW first_char
parmW last_char
parmD lp_phys_font
parmD lp_draw_mode
parmD lp_font_trans
cBegin
xor cx,cx ;0 = error return code
mov si,first_char ;Keep first character in si
mov ax,last_char ;Compute number of widths to return
sub ax,si
jl exit_get_widths ;Negative range, treat as an error
inc ax ;Inclusive of the last character
cld
les di,lp_buffer ;Widths will be returned here
assumes es,nothing
mov ds,seg_lp_phys_font ;Width table is here
assumes ds,FontSeg
mov cx,fsPixWidth ;If width field is non-zero, then
jcxz get_prop_widths ; this is a fixed pitch font
xchg ax,cx ;CX = # widths, AX = width
jmp short rep_store_and_exit
get_prop_widths:
xor bx,bx ;Get the width of the default character
mov bl,fsDefaultChar
shiftl bx,2 ;Width table consists of dwords
mov cx,wptr fsCharOffset[bx][0]
xchg ax,bx ;Save buffer size/count in BX
; Compute the number of characters outside the range of the first
; character and return the default character's width for them.
first_default_widths:
xor ax,ax
mov al,fsFirstChar ;If caller is asking for characters
sub si,ax ; before first valid character, then
jge proceess_valid_chars ; give him that many default widths
xor ax,ax ;First real char will be index 0
xchg ax,si ;Get number of default widths to
neg ax ; return
min_ax bx
sub bx,ax ;Update room left in buffer
xchg ax,cx ;AX = default width, CX = count
rep stosw
xchg ax,cx ;CX = default width
; Compute the number of characters which reside in the font
; that are to be returned to the caller, and return them.
proceess_valid_chars:
xor ax,ax ;The number of valid widths is
mov al,fsLastChar ; whatever remains in the font or
sub ax,si ; however much room is left in the
jl last_default_widths ; buffer
inc ax ;Inclusive of last character
min_ax bx
sub bx,ax ;Set number of last defaults
xchg ax,cx ;CX = # to move, AX = default width
jcxz done_with_valid_widths
shiftl si,2
add si,offset fsCharOffset
get_widths_loop:
movsw ;Move next width
inc si ;Skip the bits offset
inc si
loop get_widths_loop
done_with_valid_widths:
xchg ax,cx
last_default_widths:
xchg ax,cx ;AX = default width
mov cx,bx ;Set remaining buffer slots
rep_store_and_exit:
rep stosw ;Leaves CX = 0
inc cx ;CX = 1 to show success
exit_get_widths:
xchg ax,cx ;Return code was in CX
cEnd
sEnd TextStuff
end