Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

675 lines
13 KiB

  1. ;/* GDIMACRO.INC - GDI macros
  2. LMHLockCnt equ byte ptr 3
  3. wptr equ word ptr
  4. bptr equ byte ptr
  5. PtoLMH macro r1,r2
  6. ifnb <r2>
  7. mov r1,[r2 - 2]
  8. else
  9. mov r1,[r1 - 2]
  10. endif
  11. endm
  12. LMHtoP macro r1,r2 ;; Local Movable Handle to pointer
  13. ifnb <r2>
  14. mov r1,[r2]
  15. else
  16. mov r1,[r1]
  17. endif
  18. endm
  19. LMHtoPES macro r1,r2 ;; Local Movable Handle to ptr, deref vi ES
  20. ifnb <r2>
  21. mov r1,es:[r2]
  22. else
  23. mov r1,es:[r1]
  24. endif
  25. endm
  26. LMPsize macro r1,r2 ;; Local Movable pointer size
  27. mov r1,-4[r2]
  28. endm
  29. LockDataSegment macro
  30. endm
  31. UnlockDataSegment macro
  32. endm
  33. farLockDataSegment macro
  34. endm
  35. farUnlockDataSegment macro
  36. endm
  37. ; NOTE: The lock/unlock macros are not going to check
  38. ; for under/overflow. Its highly unlikely that
  39. ; it will occur, and if it does, we'll be hosed
  40. ; anyway....
  41. LLock macro r
  42. inc LMHLockCnt[r] ;;Increment ref count
  43. endm
  44. LUnlock macro r
  45. dec LMHLockCnt[r] ;;Decrement reference count
  46. endm
  47. LLocked? macro r
  48. cmp LMHLockCnt[r],0 ;; is the handle locked?
  49. endm
  50. LLockES macro r
  51. inc es:LMHLockCnt[r] ;;Increment ref count
  52. endm
  53. LUnlockES macro r
  54. dec es:LMHLockCnt[r] ;;Decrement reference count
  55. endm
  56. LLockedES? macro r
  57. cmp es:LMHLockCnt[r],0 ;; is the handle locked?
  58. endm
  59. ; The jmpnext macro and associated symbols are used to generate
  60. ; the fall-through chain and generate the labels required for
  61. ; error checking.
  62. ??ji = 0 ;;Initial index value
  63. jmpnext macro e
  64. jn %??ji,%(??ji+1),e ;;Set next label
  65. endm
  66. jn macro i,j,e
  67. .sall
  68. ??ji&i:
  69. .xall
  70. ifb <e> ;;If not the end of the chain
  71. db 03dh ;;mov bx, next two bytes
  72. errn$ ??ji&j,+2 ;;mext lable must be two bytes away
  73. endif
  74. ??ji=j ;;increment counter
  75. endm
  76. ifdef DEBUG
  77. ifndef ?HELPER
  78. ExternFP ValidateHandle
  79. endif
  80. endif
  81. ;*
  82. ;* Valid? macro Handle,Error_exit,LowLimit,UpLimit
  83. ;*
  84. ;* Validate an object handle. A valid handle must 1)not be NULL 2)be for
  85. ;* an object of the specified type.
  86. ;*
  87. ;*
  88. ;* Macro Arguments:
  89. ;*
  90. ;* Handle - object handle
  91. ;* Error_exit - the next instruction to execute if an invalid obj
  92. ;* LowLimit, UpLimit - Range of the possible object type
  93. ;*
  94. ;* Return:
  95. ;* DS:BX - pointer to the object
  96. ;*
  97. ;* Trashes:
  98. ;* AX,BX,CX,DX
  99. ;*
  100. Valid? macro Handle,Error_exit,LowLimit,UpLimit
  101. local ValidHandle,Invalidexit
  102. ifdef DISABLE
  103. ifdef DEBUG
  104. ;******************************************************************************
  105. ;
  106. ; Object handle validation in a debug version
  107. ;
  108. ;******************************************************************************
  109. push dx
  110. mov bx, LowLimit
  111. ifnb <UpLimit>
  112. mov dx, UpLimit
  113. else
  114. mov dx, LowLimit
  115. endif
  116. cCall <far ptr ValidateHandle>,<Handle,bx,dx>
  117. pop dx
  118. or ax,ax
  119. jnz ValidHandle
  120. jmp Error_exit
  121. else
  122. ;******************************************************************************
  123. ;
  124. ; Object handle validation in a retail version
  125. ;
  126. ;******************************************************************************
  127. mov bx,Handle ; NULL handle validation
  128. or bx,bx
  129. jz Invalidexit
  130. LMHtoP bx ; dereference for object pointer
  131. mov ax,ilObjType[bx] ; Validate the object type
  132. irp stock_type,<OBJ_PEN,OBJ_BRUSH,OBJ_FONT,OBJ_BITMAP,OBJ_PALETTE>
  133. ife stock_type-LowLimit
  134. and ax,NOT OBJ_FLAGS ; mask only for possible stock obj
  135. endif
  136. endm
  137. ifnb <UpLimit>
  138. cmp ax,LowLimit ; Check object type range
  139. jl Invalidexit
  140. cmp ax,UpLimit
  141. jle ValidHandle
  142. else
  143. cmp ax,LowLimit ; Check a particular object type
  144. je ValidHandle
  145. endif
  146. Invalidexit:
  147. xor ax,ax
  148. jmp Error_exit ; it is not a valid handle
  149. endif
  150. ValidHandle:
  151. else ; !DISABLE
  152. mov bx,Handle
  153. LMHtoP bx
  154. endif ; !DISABLE
  155. endm
  156. ValidDebug? macro Handle,LowLimit,UpLimit
  157. ifdef DEBUG
  158. push bx
  159. push dx
  160. mov bx, LowLimit
  161. ifnb <UpLimit>
  162. mov dx, UpLimit
  163. else
  164. mov dx, LowLimit
  165. endif
  166. cCall <far ptr ValidateHandle>,<Handle,bx,dx>
  167. pop dx
  168. pop bx
  169. endif
  170. endm
  171. ;*
  172. ;* Notify? macro
  173. ;*
  174. ;* Tests if the given dc is hooked, and if it is, calls off to
  175. ;* send a notification to whomever is hooked into the dc notification
  176. ;* hook.
  177. ;*
  178. ;* Macro Arguments:
  179. ;*
  180. ;* hDC - the actual DC handle
  181. ;* lParam - the notification code to send via the hook
  182. ;* errLbl - optional parameter, which gives label to
  183. ;* jump to if notification returns 0
  184. ;*
  185. ;* Trashes:
  186. ;* AX,BX,flags
  187. ;*
  188. ifdef LATER
  189. ifndef ?LVB
  190. ExternFP SendDCNotify
  191. ExternFP SendInvalidVisRgn
  192. endif
  193. Notify? macro hDC,code,param1,param2,errLbl
  194. mov bx,hDC
  195. mov bx,[bx]
  196. mov ax,word ptr lpNotifyProc[bx]
  197. or ax,word ptr lpNotifyProc+2[bx]
  198. jz @F
  199. push hDC
  200. mov ax,code
  201. push ax
  202. mov ax,param1
  203. push ax
  204. mov ax,param2
  205. push ax
  206. cCall <far ptr SendDCNotify>
  207. ifnb <errLbl>
  208. or ax,ax
  209. endif
  210. ifnb <errLbl>
  211. jnz @F
  212. jmp errLbl
  213. endif
  214. @@:
  215. endm
  216. ;* VNotify?
  217. ;*
  218. ;* Tests if the given dc is hooked and has an invalid visrgn. If
  219. ;* it does, then a notification is sent to the dc hook.
  220. ;*
  221. ;* Warning:
  222. ;* if we call the call-back, the gdi heap can be compacted,
  223. ;* so no dereferenced handles can be relied on after making
  224. ;* this call.
  225. ;*
  226. ;* Entry:
  227. ;* hDC - handle to dc to check and send notifications
  228. ;* reg - scratch register to use
  229. ;*
  230. ;* Exit:
  231. ;* reg - trashed
  232. ;* flags - trashed
  233. ;*
  234. VNotify? macro hDC,reg
  235. mov reg,hDC
  236. LMHtoP reg
  237. test byte ptr DCFlags[reg],BadVisRgn
  238. jz @F
  239. cCall <far ptr SendInvalidVisRgn>,<hDC>
  240. @@:
  241. endm
  242. VNotifyPtr? macro reg,hDC
  243. test byte ptr DCFlags[reg],BadVisRgn
  244. jz @F
  245. cCall <far ptr SendInvalidVisRgn>,<hDC>
  246. @@:
  247. endm
  248. endif
  249. ;-----------------------------------------------------------------------
  250. ; cProcVDO - cProc "Validate Debug Only"
  251. ;
  252. ; Same as cProc, except used for "Validate in Debug Only" entry points.
  253. ; Declares Iname if debug, name if retail.
  254. ;
  255. cProcVDO macro name,opts,savelist
  256. ifdef DEBUG
  257. cProc <I&name>,<opts>,<savelist>
  258. else
  259. LabelFP <PUBLIC, I&name>
  260. cProc <name>,<opts>,<savelist>
  261. endif
  262. endm
  263. GDIGLOBALLOCK macro Handle,segRegister,offsetRegister
  264. .lall
  265. ifndef GlobalLock
  266. ExternFP GlobalLock
  267. endif
  268. cCall <far ptr GlobalLock>,<Handle>
  269. ifnb <segRegister>
  270. mov segRegister,dx
  271. endif
  272. ifnb <offsetRegister>
  273. mov offsetRegister,ax
  274. endif
  275. .sall
  276. endm
  277. GDIGLOBALUNLOCK macro Handle
  278. ifndef GlobalUnlock
  279. ExternFP GlobalUnlock
  280. endif
  281. cCall <far ptr GlobalUnlock>,<Handle>
  282. endm
  283. GDIRequestSem macro
  284. endm
  285. GDIClearSem macro
  286. endm
  287. ; setlbl generates a macro which will declare labels public
  288. ; if "debug" has been defined. The symbol generated will
  289. ; be of the form:
  290. ;
  291. ; filename_label
  292. ;
  293. ; where
  294. ;
  295. ; filename is the parameter given to the setlbl macro,
  296. ; and label is the first parameter given to the lbl macro
  297. ; which is generated by setlbl.
  298. ;
  299. ;
  300. ; lbl is the macro which will define the given label and
  301. ; if "debug" is defined, declare it public.
  302. ;
  303. ;
  304. ; lbl foo,<opt1>,opt2
  305. ;
  306. ; where
  307. ;
  308. ; foo is the name of the label
  309. ; opt1 is an optional second parameter. If present,
  310. ; it must be some combination of
  311. ; proc, label, near, far, byte, word, dword
  312. ; opt2 is an optional third parameter which if present
  313. ; must be "public". It forces the declaration of
  314. ; "foo" to be public.
  315. setlbl macro filename
  316. lbl &macro n,opt1,opt2
  317. .sall
  318. ifnb <opt1>
  319. n opt1
  320. ifdef debug
  321. filename&&_&&n equ n
  322. public filename&&_&&n
  323. endif
  324. else
  325. n:
  326. ifdef debug
  327. filename&&_&&n:
  328. public filename&&_&&n
  329. endif
  330. endif
  331. ifnb <opt2>
  332. public n
  333. endif
  334. .xall
  335. &endm
  336. endm
  337. smov macro segreg1,segreg2
  338. push segreg2
  339. pop segreg1
  340. endm
  341. jmps macro there
  342. jmp short there
  343. endm
  344. ; structure to allow easy access to components of DWORD.
  345. HILO struc
  346. lo dw ?
  347. hi dw ?
  348. HILO ends
  349. ; structure to allow easy access to components of LP.
  350. OFFSEL struc
  351. off dw ?
  352. sel dw ?
  353. OFFSEL ends
  354. ;--------------------------------------------------------------------------;
  355. ; ABS
  356. ; Maps the signed integer in AX to a positive signed integer to be
  357. ; returned in AX. If FOO is blank then 8000h is mapped to 7fffh.
  358. ; Since GDI defines MININT as 8000h, we should deal with this case.
  359. ; If FOO is non-blank, 8000h is mapped to 8000h. (Usually bad!)
  360. ; All other integers behave as one would expect with Absolute Value.
  361. ; Entry:
  362. ; AX = signed integer (8000h to 7fffh)
  363. ; Returns:
  364. ; AX = ABS(AX)
  365. ; Trashes:
  366. ; DX, FLAGS
  367. ;
  368. ; History:
  369. ; Tue 29 October 1991 -by- Raymond E. Endres [rayen]
  370. ; Wrote it.
  371. ;--------------------------------------------------------------------------;
  372. ABS macro FOO ;NOTE: default FOO is blank!
  373. cwd
  374. xor ax,dx
  375. sub ax,dx
  376. ifb <FOO> ;if FOO is blank
  377. cwd ;remove the 8000h case
  378. xor ax,dx
  379. endif
  380. endm
  381. ;--------------------------------------------------------------------------;
  382. ; min_ax
  383. ; returns min of AX and REG
  384. ; Entry:
  385. ; AX = integer
  386. ; REG = general purpose register containing an integer
  387. ; Returns:
  388. ; AX = min(AX,REG)
  389. ; Error Returns:
  390. ; none
  391. ; Registers Destroyed:
  392. ; DX,FLAGS
  393. ; Registers Preserved:
  394. ; BX,CX,SI,DI,DS,ES,BP
  395. ; Calls:
  396. ; none
  397. ; History:
  398. ; Sat Mar 07, 1987 08:39:04p -by- Tony Pisculli [tonyp]
  399. ; wrote it
  400. ;--------------------------------------------------------------------------;
  401. min_ax macro REG
  402. sub ax,REG
  403. cwd
  404. and ax,dx
  405. add ax,REG
  406. endm
  407. ;--------------------------------------------------------------------------;
  408. ; max_ax
  409. ; returns max of AX and REG
  410. ; Entry:
  411. ; AX = integer
  412. ; REG = general purpose register containing an integer
  413. ; Returns:
  414. ; AX = max(AX, REG)
  415. ; Error Returns:
  416. ; none
  417. ; Registers Destroyed:
  418. ; DX,FLAGS
  419. ; Registers Preserved:
  420. ; BX,CX,SI,DI,DS,ES,BP
  421. ; Calls:
  422. ; none
  423. ; History:
  424. ; Sat Mar 07, 1987 08:41:38p -by- Tony Pisculli [tonyp]
  425. ; wrote it
  426. ;--------------------------------------------------------------------------;
  427. maxintoax macro mem1,mem2
  428. mov ax,mem1
  429. max_ax mem2
  430. endm
  431. max_ax macro REG
  432. sub ax,REG
  433. cwd
  434. not dx
  435. and ax,dx
  436. add ax,REG
  437. endm
  438. ; The following equates are used for defining the target
  439. ; processor to the shift macros.
  440. GENERIC equ 0
  441. ;CPU equ GENERIC
  442. ;CPU equ 88
  443. ;CPU equ 86
  444. ;CPU equ 186
  445. CPU equ 286
  446. ;CPU equ 386
  447. ;--------------------------------------------------------------------------;
  448. ; shiftl
  449. ;
  450. ; shiftl is used to implement the advanced shift left immediate
  451. ; (SHL dest,count) functionality of the 286 and 386.
  452. ;
  453. ; Entry:
  454. ; DEST = var to shift
  455. ; COUNT = number to shift by
  456. ; Returns:
  457. ; DEST = DEST shl COUNT
  458. ; Error Returns:
  459. ; none
  460. ; Registers Destroyed:
  461. ; none
  462. ; Registers Preserved:
  463. ; all
  464. ; Calls:
  465. ; none
  466. ; History:
  467. ; Sat Mar 07, 1987 08:44:30p -by- Tony Pisculli [tonyp]
  468. ; wrote it
  469. ;--------------------------------------------------------------------------;
  470. shiftl macro DEST,COUNT
  471. if (CPU eq 286) or (CPU eq 386)
  472. shl DEST,COUNT
  473. else
  474. REPT COUNT
  475. shl DEST,1
  476. ENDM
  477. endif
  478. endm
  479. ;--------------------------------------------------------------------------;
  480. ; shiftr
  481. ;
  482. ; shiftr is used to implement the advanced shift right immediate
  483. ; (SHR dest,count) functionality of the 286 and 386.
  484. ;
  485. ; Entry:
  486. ; DEST = var to shift
  487. ; COUNT = number to shift by
  488. ; Returns:
  489. ; DEST = DEST shr COUNT
  490. ; Error Returns:
  491. ; none
  492. ; Registers Destroyed:
  493. ; none
  494. ; Registers Preserved:
  495. ; all
  496. ; Calls:
  497. ; none
  498. ; History:
  499. ; Sat Mar 07, 1987 08:44:52p -by- Tony Pisculli [tonyp]
  500. ; wrote it
  501. ;--------------------------------------------------------------------------;
  502. shiftr macro DEST,COUNT
  503. if (CPU eq 286) or (CPU eq 386)
  504. shr DEST,COUNT
  505. else
  506. REPT COUNT
  507. shr DEST,1
  508. ENDM
  509. endif
  510. endm
  511. ;--------------------------------------------------------------------------;
  512. ; nop32
  513. ;
  514. ; compensate for bug in the 386 chip and 32-bit string operations.
  515. ;
  516. ;--------------------------------------------------------------------------;
  517. nop32 macro
  518. db 067h
  519. nop
  520. endm
  521. if 0
  522. */
  523. #ifndef DEBUG
  524. #include "igdi.inc"
  525. #endif
  526. #define MAX(a,b) ((a)>(b)?(a):(b))
  527. #define MIN(a,b) ((a)<=(b)?(a):(b))
  528. #define ABS(x) (((x) >= 0) ? (x) : (-(x)))
  529. #define LBYTE(x) ((BYTE)((x)&0xFF))
  530. #define HBYTE(y) ((BYTE)(((y)>>8)&0xFF))
  531. #define LWORD(x) ((short)((x)&0xFFFF))
  532. #define HWORD(y) ((short)(((y)>>16)&0xFFFF))
  533. #define MAKELONG(h,l) ((long)(((WORD)l)|(((long)h)<<16)))
  534. extern far PASCAL ValidateHandle(HANDLE, short, short);
  535. #ifdef DISABLE
  536. #define Valid(Handle, Low, High) ValidateHandle(Handle, Low, High)
  537. #else
  538. #define Valid(Handle, Low, High) TRUE
  539. #endif
  540. #ifdef DEBUG
  541. #define ValidDebug(Handle, Low, High) {if(!ValidateHandle(Handle, Low, High)) return(NULL);}
  542. #else
  543. #define ValidDebug(Handle, Low, High) TRUE
  544. #endif
  545. #define GDIGLOBALLOCK(x) GlobalLock(x)
  546. #define GDIGLOBALUNLOCK(x) GlobalUnlock(x)
  547. #define GDILOCKRESOURCE(x) LockResource(x)
  548. #define GDIENTERCRITSEC()
  549. #define GDIEXITCRITSEC()
  550. #define LockDataSegment()
  551. #define UnlockDataSegment()
  552. #define farLockDataSegment()
  553. #define farUnlockDataSegment()
  554. #define GDIRequestSem()
  555. #define GDIClearSem()
  556. #define LOWORD(l) ((WORD)(l))
  557. #define HIWORD(l) ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
  558. #define SELECTOROF(lp) HIWORD(lp)
  559. #define OFFSETOF(lp) LOWORD(lp)
  560. /*
  561. endif
  562. ;*/
  563. 
  564.