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
28 fnt_Default LABEL BYTE
\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
68 mov ds, [mx_CodeSegment]
\r
71 mov ax, WORD PTR Font[2] ; Get font segment
\r
72 test ax, ax ; Null segment?
\r
73 jnz @@UserFont ; No, install user font
\r
75 ; Install system font
\r
76 mov ax, WORD PTR Font[0] ; Get font number
\r
77 cmp ax, MX_MAXSYSFONT ; Check range
\r
79 xor ax, ax ; Out of range, use default font
\r
84 mov ax, tbl_SystemFont[bx] ; Get font offset
\r
85 mov WORD PTR mx_FontPtr[0], ax
\r
86 mov WORD PTR mx_FontPtr[2], cs
\r
87 mov al, BYTE PTR tbl_SystemFont[bx+2]
\r
89 mov [mx_FontWidth], ax
\r
91 mov dl, BYTE PTR tbl_SystemFont[bx+3]
\r
93 mov [mx_FontHeight], dx
\r
95 mov [mx_FontCharSize], ax
\r
101 ; Install user font
\r
103 mov ax, -1 ; Assume an error
\r
106 ja @@Exit ; Invalid character width
\r
109 ja @@Exit ; Invalid character height
\r
110 mov [mx_FontWidth], bx
\r
111 mov [mx_FontHeight], dx
\r
118 mov [mx_FontCharSize], ax
\r
119 mov ax, WORD PTR Font[0]
\r
120 mov WORD PTR mx_FontPtr[0], ax
\r
121 mov ax, WORD PTR Font[2]
\r
122 mov WORD PTR mx_FontPtr[2], ax
\r
131 ;-----------------------------------------------------------
\r
133 ; Sets the text color and raster op.
\r
136 ; Color = text color (foreground + background*256)
\r
141 mxSetTextColor PROC FAR
\r
143 Color:WORD = ARG_SIZE
\r
147 mov ds, [mx_CodeSegment]
\r
151 mov [mx_FontColor], ax
\r
153 mov [mx_FontOp], ax
\r
159 mxSetTextColor ENDP
\r
161 ;-----------------------------------------------------------
\r
163 ; Writes a character using the current font and attributes.
\r
166 ; X, Y = video coordinates
\r
167 ; C = character to print
\r
175 LOCAL Image:BYTE:MAX_WIDTH*MAX_HEIGHT, \
\r
176 Count:WORD = AUTO_SIZE
\r
178 .push ds, si, es, di
\r
181 ; Gets the pointer to font data for the selected character
\r
182 lds si, DWORD PTR [mx_FontPtr]
\r
185 mul [mx_FontCharSize] ; Offset into font
\r
186 add si, ax ; DS:SI -> font data for character
\r
188 ; Converts font data into a 256-color linear image
\r
192 mov dx, [mx_FontColor]
\r
193 mov ax, [mx_FontHeight]
\r
196 mov cx, [mx_FontWidth]
\r
198 inc si ; Get a byte from font data
\r
200 jbe @@WidthLoop ; Ok for width <= 8
\r
201 mov bl, ds:[si] ; Get another byte
\r
204 mov al, dl ; Assume foreground color
\r
205 shl bx, 1 ; Is font bit set?
\r
206 jc @@1 ; Yes, foreground is just great
\r
207 mov al, dh ; Get background color
\r
209 mov es:[di], al ; Put pixel into image
\r
216 ; Now pass image to mx_PutImage
\r
219 push ax ; Pointer to image
\r
221 push [Y] ; Image coordinates
\r
222 push [mx_FontWidth]
\r
223 push [mx_FontHeight] ; Image size
\r
224 push [mx_FontOp] ; Raster op
\r
225 call mxPutImage ; Write character
\r
228 .pop ds, si, es, di
\r
232 ;-----------------------------------------------------------
\r
234 ; Writes a string at the coordinates specified.
\r
237 ; X, Y = text coordinates
\r
238 ; S = pointer to ASCIIZ string
\r
253 test al, al ; End of string?
\r
254 jz @@Exit ; Yes, exit
\r
256 push [X] ; Display character
\r
260 mov ax, [mx_DeltaX]
\r
261 add [X], ax ; Bump X coordinate
\r
262 mov ax, [mx_DeltaY]
\r
263 add [Y], ax ; Bump Y coordinate
\r
274 ;-----------------------------------------------------------
\r
276 ; Sets the distance between characters.
\r
279 ; DeltaX = horizontal distance in pixels
\r
280 ; DeltaY = vertical distance in pixels
\r
284 ; Note: this function may be used to set the text direction.
\r
286 mxSetTextStep PROC FAR
\r
288 DeltaX:WORD = ARG_SIZE
\r
292 mov ds, [mx_CodeSegment]
\r
296 mov [mx_DeltaX], ax
\r
298 mov [mx_DeltaY], ax
\r
304 ;-----------------------------------------------------------
\r
306 ; Gets the current distance between characters.
\r
309 ; DeltaX = pointer to horizontal distance in pixels (integer)
\r
310 ; DeltaY = pointer to vertical distance in pixels (integer)
\r
314 mxGetTextStep PROC FAR
\r
315 ARG DeltaY:DWORD, \
\r
316 DeltaX:DWORD = ARG_SIZE
\r
321 mov ax, [mx_DeltaX]
\r
324 mov ax, [mx_DeltaY]
\r