1 ;-----------------------------------------------------------
\r
3 ; MXOT.ASM - Text functions
\r
4 ; Copyright (c) 1994 by Alessandro Scotti
\r
6 ;-----------------------------------------------------------
\r
8 NOWARN RES ; We use the reserved name 'WIDTH'
\r
14 PUBLIC mxSetTextColor
\r
15 PUBLIC mxGetTextStep
\r
16 PUBLIC mxSetTextStep
\r
18 MAX_WIDTH EQU 16 ; Must be <= 16
\r
21 MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE'
\r
22 ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING
\r
24 EXTRN mx_CodeSegment : WORD
\r
25 EXTRN mxPutImage : FAR
\r
31 ; Table of system fonts
\r
32 tbl_SystemFont LABEL WORD
\r
33 DW fnt_Default, 8, 8
\r
35 MX_MAXSYSFONT EQU ($-OFFSET tbl_SystemFont) SHR 2
\r
37 mx_FontPtr DW OFFSET fnt_Default, SEG MX_TEXT
\r
38 mx_FontWidth DW 8 ; Font width in pixels
\r
39 mx_FontHeight DW 8 ; Font height in pixels
\r
40 mx_FontCharSize DW 8 ; Size in bytes of a font character
\r
41 mx_FontColor DW 00FFh ; Color: foreground + background*256
\r
42 mx_FontOp DW OP_MOVE ; Raster op
\r
43 mx_DeltaX DW 8 ; Horizontal step
\r
44 mx_DeltaY DW 0 ; Vertical step
\r
46 ;-----------------------------------------------------------
\r
48 ; Sets the current font.
\r
51 ; Font = pointer to font data
\r
52 ; Width = width of font character in pixels
\r
53 ; Height = height of font character in pixels
\r
55 ; AX = 0 on success, else invalid parameters
\r
57 ; Note: when the high word of Font (i.e. the segment) is zero, the low
\r
58 ; word is used to select one of the system fonts.
\r
63 Font:DWORD = ARG_SIZE
\r
67 mov ds, [mx_CodeSegment]
\r
70 mov ax, WORD PTR Font[2] ; Get font segment
\r
71 test ax, ax ; Null segment?
\r
72 jnz @@UserFont ; No, install user font
\r
74 ; Install system font
\r
75 mov ax, WORD PTR Font[0] ; Get font number
\r
76 cmp ax, MX_MAXSYSFONT ; Check range
\r
78 xor ax, ax ; Out of range, use default font
\r
83 mov ax, tbl_SystemFont[bx] ; Get font offset
\r
84 mov WORD PTR mx_FontPtr[0], ax
\r
85 mov WORD PTR mx_FontPtr[2], cs
\r
86 mov al, BYTE PTR tbl_SystemFont[bx+2]
\r
88 mov [mx_FontWidth], ax
\r
90 mov dl, BYTE PTR tbl_SystemFont[bx+3]
\r
92 mov [mx_FontHeight], dx
\r
94 mov [mx_FontCharSize], ax
\r
100 ; Install user font
\r
102 mov ax, -1 ; Assume an error
\r
105 ja @@Exit ; Invalid character width
\r
108 ja @@Exit ; Invalid character height
\r
109 mov [mx_FontWidth], bx
\r
110 mov [mx_FontHeight], dx
\r
115 mov [mx_FontCharSize], ax
\r
116 mov ax, WORD PTR Font[0]
\r
117 mov WORD PTR mx_FontPtr[0], ax
\r
118 mov ax, WORD PTR Font[2]
\r
119 mov WORD PTR mx_FontPtr[2], ax
\r
128 ;-----------------------------------------------------------
\r
130 ; Sets the text color and raster op.
\r
133 ; Color = text color (foreground + background*256)
\r
138 mxSetTextColor PROC FAR
\r
140 Color:WORD = ARG_SIZE
\r
144 mov ds, [mx_CodeSegment]
\r
148 mov [mx_FontColor], ax
\r
150 mov [mx_FontOp], ax
\r
156 mxSetTextColor ENDP
\r
158 ;-----------------------------------------------------------
\r
160 ; Writes a character using the current font and attributes.
\r
163 ; X, Y = video coordinates
\r
164 ; C = character to print
\r
172 LOCAL Image:BYTE:MAX_WIDTH*MAX_HEIGHT, \
\r
173 Count:WORD = AUTO_SIZE
\r
175 .push ds, si, es, di
\r
178 ; Gets the pointer to font data for the selected character
\r
179 lds si, DWORD PTR [mx_FontPtr]
\r
182 mul [mx_FontCharSize] ; Offset into font
\r
183 add si, ax ; DS:SI -> font data for character
\r
185 ; Converts font data into a 256-color linear image
\r
189 mov dx, [mx_FontColor]
\r
190 mov ax, [mx_FontHeight]
\r
193 mov cx, [mx_FontWidth]
\r
195 inc si ; Get a byte from font data
\r
197 jbe @@WidthLoop ; Ok for width <= 8
\r
198 mov bl, ds:[si] ; Get another byte
\r
201 mov al, dl ; Assume foreground color
\r
202 shl bx, 1 ; Is font bit set?
\r
203 jc @@1 ; Yes, foreground is just great
\r
204 mov al, dh ; Get background color
\r
206 mov es:[di], al ; Put pixel into image
\r
213 ; Now pass image to mx_PutImage
\r
216 push ax ; Pointer to image
\r
218 push [Y] ; Image coordinates
\r
219 push [mx_FontWidth]
\r
220 push [mx_FontHeight] ; Image size
\r
221 push [mx_FontOp] ; Raster op
\r
222 call mxPutImage ; Write character
\r
225 .pop ds, si, es, di
\r
229 ;-----------------------------------------------------------
\r
231 ; Writes a string at the coordinates specified.
\r
234 ; X, Y = text coordinates
\r
235 ; S = pointer to ASCIIZ string
\r
250 test al, al ; End of string?
\r
251 jz @@Exit ; Yes, exit
\r
253 push [X] ; Display character
\r
257 mov ax, [mx_DeltaX]
\r
258 add [X], ax ; Bump X coordinate
\r
259 mov ax, [mx_DeltaY]
\r
260 add [Y], ax ; Bump Y coordinate
\r
271 ;-----------------------------------------------------------
\r
273 ; Sets the distance between characters.
\r
276 ; DeltaX = horizontal distance in pixels
\r
277 ; DeltaY = vertical distance in pixels
\r
281 ; Note: this function may be used to set the text direction.
\r
283 mxSetTextStep PROC FAR
\r
285 DeltaX:WORD = ARG_SIZE
\r
289 mov ds, [mx_CodeSegment]
\r
293 mov [mx_DeltaX], ax
\r
295 mov [mx_DeltaY], ax
\r
301 ;-----------------------------------------------------------
\r
303 ; Gets the current distance between characters.
\r
306 ; DeltaX = pointer to horizontal distance in pixels (integer)
\r
307 ; DeltaY = pointer to vertical distance in pixels (integer)
\r
311 mxGetTextStep PROC FAR
\r
312 ARG DeltaY:DWORD, \
\r
313 DeltaX:DWORD = ARG_SIZE
\r
318 mov ax, [mx_DeltaX]
\r
321 mov ax, [mx_DeltaY]
\r