1 ;-----------------------------------------------------------
\r
3 ; MXCR.ASM - Clip functions
\r
4 ; Copyright (c) 1993,1994 by Alessandro Scotti
\r
6 ;-----------------------------------------------------------
\r
11 PUBLIC mxSetSysClipRegion
\r
12 PUBLIC mxGetClipRegion
\r
13 PUBLIC mxSetClipRegion
\r
25 MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE'
\r
26 ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING
\r
28 EXTRN mx_CodeSegment : WORD
\r
30 mx_ClipX1 DW ? ; Clip coordinates
\r
35 mx_SysClipX1 DW ? ; System clip coordinates
\r
36 mx_SysClipY1 DW ? ; (active when mx_ClipStatus is FALSE)
\r
40 mx_UserClipX1 DW ? ; User clip coordinates
\r
41 mx_UserClipY1 DW ? ; (active when mx_ClipStatus is TRUE)
\r
47 ;-----------------------------------------------------------
\r
49 ; Toggles clipping between user and system regions.
\r
52 ; ClipStatus = TRUE (FALSE) to enable (disable) clipping
\r
54 ; AX = old clip status
\r
57 ARG ClipStatus:BYTE:2 = ARG_SIZE
\r
61 mov ds, [mx_CodeSegment]
\r
64 mov ax, [mx_UserClipX1]
\r
65 mov bx, [mx_UserClipY1]
\r
66 mov cx, [mx_UserClipX2]
\r
67 mov dx, [mx_UserClipY2]
\r
68 cmp [ClipStatus], TRUE
\r
70 mov ax, [mx_SysClipX1]
\r
71 mov bx, [mx_SysClipY1]
\r
72 mov cx, [mx_SysClipX2]
\r
73 mov dx, [mx_SysClipY2]
\r
80 mov al, [ClipStatus]
\r
81 xchg al, [mx_ClipStatus]
\r
88 ;-----------------------------------------------------------
\r
90 ; Returns the current clipping status.
\r
95 ; TRUE (FALSE) if clipping enabled (disabled)
\r
99 mov al, [mx_ClipStatus]
\r
104 ;-----------------------------------------------------------
\r
106 ; Sets the system clip region and disables user clipping.
\r
109 ; Width = width in pixels of clip region
\r
110 ; Height = height in pixels of clip region
\r
114 mxSetSysClipRegion PROC FAR
\r
116 Width:WORD = ARG_SIZE
\r
120 mov ds, [mx_CodeSegment]
\r
123 xor ax, ax ; Sys clip region always starts at (0,0)
\r
124 mov [mx_SysClipX1], ax
\r
125 mov [mx_SysClipY1], ax
\r
128 mov [mx_SysClipX2], ax
\r
131 mov [mx_SysClipY2], ax
\r
143 mxSetSysClipRegion ENDP
\r
145 ;-----------------------------------------------------------
\r
147 ; Sets the clip region.
\r
150 ; X, Y = coordinates of top left corner of clip region
\r
151 ; Width = width in pixels of clip region
\r
152 ; Height = height in pixels of clip region
\r
154 ; none (no checking on parameters)
\r
156 mxSetClipRegion PROC FAR
\r
164 mov ds, [mx_CodeSegment]
\r
168 mov [mx_UserClipX1], ax
\r
170 mov [mx_UserClipY1], ax
\r
174 mov [mx_UserClipX2], ax
\r
178 mov [mx_UserClipY2], ax
\r
180 mov al, [mx_ClipStatus]
\r
190 mxSetClipRegion ENDP
\r
192 ;-----------------------------------------------------------
\r
194 ; Returns the current user clip region.
\r
197 ; X, Y = pointers to integer coordinates of top left corner
\r
198 ; Width = pointer to word width of clip region
\r
199 ; Height = pointer to word height of clip region
\r
201 ; AX = current clip status
\r
203 mxGetClipRegion PROC FAR
\r
204 ARG Height:DWORD, \
\r
212 mov ax, [mx_UserClipX1]
\r
215 mov ax, [mx_UserClipY1]
\r
219 mov ax, [mx_UserClipX2]
\r
220 sub ax, [mx_UserClipX1]
\r
224 mov ax, [mx_UserClipY2]
\r
225 sub ax, [mx_UserClipY1]
\r
230 mov al, [mx_ClipStatus]
\r
234 mxGetClipRegion ENDP
\r
236 ;-----------------------------------------------------------
\r
238 ; Internal use: checks the coordinates of a rectangle against
\r
239 ; the active clip region.
\r
240 ; This function assumes that a "raw" image has to be clipped,
\r
241 ; so it returns in SI the number of "raw" bytes to skip if
\r
242 ; X, Y were clipped.
\r
245 ; BX, AX = X, Y coordinates of rectangle (signed)
\r
249 ; CF = set if rectangle is full clipped
\r
250 ; BX, AX = new X, Y coordinates of rectangle
\r
251 ; CX, DX = clipped width and height
\r
252 ; SI = number of bytes to skip before copying a buffer
\r
255 subClipImage PROC NEAR
\r
259 ; Check clip height
\r
260 mov di, [mx_ClipY1]
\r
263 sub di, ax ; Number of lines to clip
\r
264 sub dx, di ; New box height
\r
267 mov di, dx ; Save box height into DI
\r
268 mul cx ; DX:AX = number of bytes to skip
\r
270 mov dx, di ; Restore box height
\r
271 mov ax, [mx_ClipY1]
\r
273 mov di, [mx_ClipY2]
\r
279 jge @@DoneHeight ; None, continue
\r
280 add dx, di ; Clip lines
\r
285 mov di, [mx_ClipX1]
\r
288 sub di, bx ; Number of columns to clip left
\r
291 add si, di ; Update skip count
\r
292 mov bx, [mx_ClipX1]
\r
294 mov di, [mx_ClipX2]
\r
300 jge @@DoneWidth ; None, exit
\r
301 add cx, di ; New box width
\r
304 ; Set return flag and exit
\r
313 ;-----------------------------------------------------------
\r
315 ; Internal use: checks the coordinates of a rectangle against
\r
316 ; the active clip region.
\r
319 ; BX, AX = X, Y coordinates of rectangle (signed)
\r
323 ; CF = set if rectangle is full clipped
\r
324 ; BX, AX = new X, Y coordinates of rectangle
\r
325 ; CX, DX = clipped width and height
\r
328 subClipBox PROC NEAR
\r
331 ; Check clip height
\r
332 mov di, [mx_ClipY1]
\r
335 sub di, ax ; Number of lines to clip
\r
336 sub dx, di ; New box height
\r
338 mov ax, [mx_ClipY1]
\r
340 mov di, [mx_ClipY2]
\r
345 sub di, ax ; Clipped some point?
\r
346 jge @@DoneHeight ; No, continue
\r
347 add dx, di ; Clip lines (DI is negative)
\r
352 mov di, [mx_ClipX1]
\r
355 sub di, bx ; Number of columns to clip left
\r
358 mov bx, [mx_ClipX1]
\r
360 mov di, [mx_ClipX2]
\r
365 sub di, cx ; Clipped some point?
\r
366 jge @@DoneWidth ; No, exit
\r
367 add cx, di ; New box width (DI is negative)
\r
370 ; Set return flag and exit
\r