]> 4ch.mooo.com Git - 16.git/blob - 16/xw_/mxot_.asm
more
[16.git] / 16 / xw_ / mxot_.asm
1 ;-----------------------------------------------------------\r
2 ;\r
3 ; MXOT.ASM - Text functions\r
4 ; Copyright (c) 1994 by Alessandro Scotti\r
5 ;\r
6 ;-----------------------------------------------------------\r
7 ;WARN    PRO\r
8 ;NOWARN  RES                             ; We use the reserved name 'WIDTH'\r
9 INCLUDE MODEX.DEF\r
10 \r
11 PUBLIC  mxOutChar\r
12 PUBLIC  mxOutText\r
13 PUBLIC  mxSetFont\r
14 PUBLIC  mxSetTextColor\r
15 PUBLIC  mxGetTextStep\r
16 PUBLIC  mxSetTextStep\r
17 \r
18 MAX_WIDTH       EQU     16              ; Must be <= 16\r
19 MAX_HEIGHT      EQU     32\r
20 \r
21 MX_TEXT         SEGMENT USE16 PARA PUBLIC 'CODE'\r
22                 ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING\r
23 \r
24 EXTRN   mx_CodeSegment  : WORD\r
25 EXTRN   mxPutImage      : FAR\r
26 \r
27 ; Default 8x8 font\r
28 fnt_Default     LABEL   BYTE\r
29         INCLUDE DEFAULT.FNT\r
30 \r
31 ; Table of system fonts\r
32 tbl_SystemFont   LABEL   WORD\r
33         DW      fnt_Default, 8, 8\r
34 \r
35 MX_MAXSYSFONT   EQU     ($-OFFSET tbl_SystemFont) SHR 2\r
36 \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
45 \r
46 ;-----------------------------------------------------------\r
47 ;\r
48 ; Sets the current font.\r
49 ;\r
50 ; Input:\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
54 ; Output:\r
55 ;       AX = 0 on success, else invalid parameters\r
56 ;\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
59 ;\r
60 mxSetFont       PROC FAR\r
61         push            bp\r
62         mov             bp,sp\r
63         sub             sp,0\r
64         push            ds\r
65         .enter  0\r
66         .push   ds\r
67 \r
68         mov     ds, [mx_CodeSegment]\r
69         ASSUME  ds:MX_TEXT\r
70 \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
74 \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
78         jb      @@SystemFont\r
79         xor     ax, ax                  ; Out of range, use default font\r
80 @@SystemFont:\r
81         shl     ax, 1\r
82         shl     ax, 1\r
83         mov     bx, ax\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
88         xor     ah, ah\r
89         mov     [mx_FontWidth], ax\r
90         mov     [mx_DeltaX], ax\r
91         mov     dl, BYTE PTR tbl_SystemFont[bx+3]\r
92         xor     dh, dh\r
93         mov     [mx_FontHeight], dx\r
94         mul     dx\r
95         mov     [mx_FontCharSize], ax\r
96         mov     [mx_DeltaX], ax\r
97         xor     ax, ax\r
98         mov     [mx_DeltaY], ax\r
99         jmp     @@Exit\r
100 \r
101 ; Install user font\r
102 @@UserFont:\r
103         mov     ax, -1                  ; Assume an error\r
104         mov     bx, [bp+8]\r
105         cmp     bx, MAX_WIDTH\r
106         ja      @@Exit                  ; Invalid character width\r
107         mov     dx, [bp+4]\r
108         cmp     dx, MAX_HEIGHT\r
109         ja      @@Exit                  ; Invalid character height\r
110         mov     [mx_FontWidth], bx\r
111         mov     [mx_FontHeight], dx\r
112         mov     ax, bx\r
113         add     ax, 7\r
114         shr    ax, 1\r
115         shr    ax, 1\r
116         shr    ax, 1\r
117         mul     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
123         xor     ax, ax\r
124 \r
125 @@Exit:\r
126         .pop    ds\r
127         ASSUME  ds:NOTHING\r
128         ;.leave  ARG_SIZE\r
129 mxSetFont       ENDP\r
130 \r
131 ;-----------------------------------------------------------\r
132 ;\r
133 ; Sets the text color and raster op.\r
134 ;\r
135 ; Input:\r
136 ;       Color   = text color (foreground + background*256)\r
137 ;       Op      = raster op\r
138 ; Output:\r
139 ;       none\r
140 ;\r
141 mxSetTextColor  PROC FAR\r
142         ARG     Op:WORD,        \\r
143                 Color:WORD      = ARG_SIZE\r
144         .enter  0\r
145         .push   ds\r
146 \r
147         mov     ds, [mx_CodeSegment]\r
148         ASSUME  ds:MX_TEXT\r
149 \r
150         mov     ax, [Color]\r
151         mov     [mx_FontColor], ax\r
152         mov     ax, [Op]\r
153         mov     [mx_FontOp], ax\r
154 \r
155         xor     ax, ax\r
156         .pop    ds\r
157         ASSUME  ds:NOTHING\r
158         .leave  ARG_SIZE\r
159 mxSetTextColor  ENDP\r
160 \r
161 ;-----------------------------------------------------------\r
162 ;\r
163 ; Writes a character using the current font and attributes.\r
164 ;\r
165 ; Input:\r
166 ;       X, Y    = video coordinates\r
167 ;       C       = character to print\r
168 ; Output:\r
169 ;       none\r
170 ;\r
171 mxOutChar       PROC FAR\r
172         ARG     C:BYTE:2,       \\r
173                 Y:WORD,         \\r
174                 X:WORD          = ARG_SIZE\r
175         LOCAL   Image:BYTE:MAX_WIDTH*MAX_HEIGHT,        \\r
176                 Count:WORD                              = AUTO_SIZE\r
177         .enter  AUTO_SIZE\r
178         .push   ds, si, es, di\r
179         ASSUME  ds:NOTHING\r
180 \r
181 ; Gets the pointer to font data for the selected character\r
182         lds     si, DWORD PTR [mx_FontPtr]\r
183         mov     al, [C]\r
184         xor     ah, ah\r
185         mul     [mx_FontCharSize]       ; Offset into font\r
186         add     si, ax                  ; DS:SI -> font data for character\r
187 \r
188 ; Converts font data into a 256-color linear image\r
189         mov     ax, ss\r
190         mov     es, ax\r
191         lea     di, [Image]\r
192         mov     dx, [mx_FontColor]\r
193         mov     ax, [mx_FontHeight]\r
194         mov     [Count], ax\r
195 @@HeightLoop:\r
196         mov     cx, [mx_FontWidth]\r
197         mov     bh, ds:[si]\r
198         inc     si                      ; Get a byte from font data\r
199         cmp     cx, 8\r
200         jbe     @@WidthLoop             ; Ok for width <= 8\r
201         mov     bl, ds:[si]             ; Get another byte\r
202         inc     si\r
203 @@WidthLoop:\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
208 @@1:\r
209         mov     es:[di], al             ; Put pixel into image\r
210         inc     di\r
211         dec     cx\r
212         jnz     @@WidthLoop\r
213         dec     [Count]\r
214         jnz     @@HeightLoop\r
215 \r
216 ; Now pass image to mx_PutImage\r
217         lea     ax, [Image]\r
218         push    es\r
219         push    ax                      ; Pointer to image\r
220         push    [X]\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
226 \r
227         xor     ax, ax\r
228         .pop    ds, si, es, di\r
229         .leave  ARG_SIZE\r
230 mxOutChar       ENDP\r
231 \r
232 ;-----------------------------------------------------------\r
233 ;\r
234 ; Writes a string at the coordinates specified.\r
235 ;\r
236 ; Input:\r
237 ;       X, Y    = text coordinates\r
238 ;       S       = pointer to ASCIIZ string\r
239 ; Output:\r
240 ;       none\r
241 ;\r
242 mxOutText       PROC FAR\r
243         ARG     S:DWORD,        \\r
244                 Y:WORD,         \\r
245                 X:WORD          = ARG_SIZE\r
246         .enter  0\r
247         .push   ds, si\r
248         ASSUME  ds:NOTHING\r
249 \r
250         lds     si, [S]\r
251 @@Loop:\r
252         mov     al, ds:[si]\r
253         test    al, al                  ; End of string?\r
254         jz      @@Exit                  ; Yes, exit\r
255         inc     si\r
256         push    [X]                     ; Display character\r
257         push    [Y]\r
258         push    ax\r
259         call    mxOutChar\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
264         dec     [Count]\r
265         jnz     @@Loop\r
266 \r
267 @@Exit:\r
268         xor     ax, ax\r
269         .pop    ds, si\r
270         .leave  ARG_SIZE\r
271         ret\r
272 mxOutText       ENDP\r
273 \r
274 ;-----------------------------------------------------------\r
275 ;\r
276 ; Sets the distance between characters.\r
277 ;\r
278 ; Input:\r
279 ;       DeltaX  = horizontal distance in pixels\r
280 ;       DeltaY  = vertical distance in pixels\r
281 ; Output:\r
282 ;       none\r
283 ;\r
284 ; Note: this function may be used to set the text direction.\r
285 ;\r
286 mxSetTextStep   PROC FAR\r
287         ARG     DeltaY:WORD,    \\r
288                 DeltaX:WORD     = ARG_SIZE\r
289         .enter  0\r
290         .push   ds\r
291 \r
292         mov     ds, [mx_CodeSegment]\r
293         ASSUME  ds:MX_TEXT\r
294 \r
295         mov     ax, [DeltaX]\r
296         mov     [mx_DeltaX], ax\r
297         mov     ax, [DeltaY]\r
298         mov     [mx_DeltaY], ax\r
299 \r
300         .pop    ds\r
301         .leave  ARG_SIZE\r
302 mxSetTextStep   ENDP\r
303 \r
304 ;-----------------------------------------------------------\r
305 ;\r
306 ; Gets the current distance between characters.\r
307 ;\r
308 ; Input:\r
309 ;       DeltaX  = pointer to horizontal distance in pixels (integer)\r
310 ;       DeltaY  = pointer to vertical distance in pixels (integer)\r
311 ; Output:\r
312 ;       none\r
313 ;\r
314 mxGetTextStep   PROC FAR\r
315         ARG     DeltaY:DWORD,   \\r
316                 DeltaX:DWORD    = ARG_SIZE\r
317         .enter  0\r
318         .push   ds, si\r
319         ASSUME  ds:NOTHING\r
320 \r
321         mov     ax, [mx_DeltaX]\r
322         lds     si, [DeltaX]\r
323         mov     ds:[si], ax\r
324         mov     ax, [mx_DeltaY]\r
325         lds     si, [DeltaY]\r
326         mov     ds:[si], ax\r
327 \r
328         .pop    ds, si\r
329         .leave  ARG_SIZE\r
330 mxGetTextStep   ENDP\r
331 \r
332 MX_TEXT         ENDS\r
333 END\r