Leaked source code of windows server 2003
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.

632 lines
19 KiB

  1. ;---------------------------Module-Header------------------------------;
  2. ; Module Name: srccopy.asm
  3. ;
  4. ; Copyright (c) 1993 Microsoft Corporation
  5. ;-----------------------------------------------------------------------;
  6. ;-----------------------------------------------------------------------;
  7. ; VOID vSrcCopy8bpp(ppdev, psoSrc, prclDst, pptlSrc, lSrcDelta, pvSrcStart);
  8. ;
  9. ; Input:
  10. ;
  11. ; ppdev - screen pdev
  12. ; psoSrc - source surface
  13. ; prcldest - pointer to destination rectangle
  14. ; pptlsrc - pointer to source upper left corner
  15. ; lSrcDelta - offset from start of one scan to next in source
  16. ; pvSrcStart - pointer to start of bitmap
  17. ;
  18. ; Performs 8bpp SRCCOPY memory-to-screen blts.
  19. ;
  20. ;-----------------------------------------------------------------------;
  21. ; NOTE: Assumes all rectangles have positive heights and widths. Will
  22. ; not work properly if this is not the case.
  23. ;-----------------------------------------------------------------------;
  24. ;-----------------------------------------------------------------------;
  25. .386
  26. .model small,c
  27. assume cs:FLAT,ds:FLAT,es:FLAT,ss:FLAT
  28. assume fs:nothing,gs:nothing
  29. .xlist
  30. include stdcall.inc ;calling convention cmacros
  31. include i386\strucs.inc
  32. include i386\driver.inc
  33. include i386\egavga.inc
  34. .list
  35. ;-----------------------------------------------------------------------;
  36. .data
  37. ;-----------------------------------------------------------------------;
  38. .code
  39. ;-----------------------------------------------------------------------;
  40. cProc vSrcCopy8bpp,20,< \
  41. uses esi edi ebx, \
  42. ppdev: ptr PDEV, \
  43. prclDst: ptr RECTL, \
  44. pptlSrc: ptr POINTL, \
  45. lSrcDelta: dword, \
  46. pvSrcStart: ptr >
  47. local culMiddle: dword ;# of dwords in middle
  48. local cyToGo: dword ;# of scans to copy after the current bank
  49. local pfnLoopVector:ptr ;vector to appropriate copying loop
  50. local pvSrc: ptr ;source pointer
  51. mov esi,prclDst ;esi = prclDest
  52. mov ebx,ppdev ;ebx = ppdev
  53. mov edi,[esi].yTop
  54. cmp edi,[ebx].pdev_rcl1WindowClip.yTop
  55. jl short src8_map_init_bank
  56. mov edx,[ebx].pdev_rcl1WindowClip.yBottom
  57. ;edx = ppdev->rcl1WindowClip.bottom
  58. cmp edi,edx
  59. jl short src8_init_bank_mapped
  60. src8_map_init_bank:
  61. ptrCall <dword ptr [ebx].pdev_pfnBankControl>, \
  62. <ebx,edi,JustifyTop>
  63. mov edx,[ebx].pdev_rcl1WindowClip.yBottom
  64. src8_init_bank_mapped:
  65. mov eax,[esi].yBottom
  66. sub eax,edx
  67. mov cyToGo,eax ;eax = # scans to do after this bank
  68. sbb ecx,ecx
  69. and ecx,eax
  70. add edx,ecx ;edx = min(prclDst->bottom,
  71. ; ppdev->rcl1WindowClip.bottom)
  72. sub edx,edi ;edx = # of scans to do in this bank
  73. ; ebx = ppdev
  74. ; edx = # of scans to do in this bank
  75. ; esi = prclDst
  76. mov eax,[esi].xLeft
  77. add eax,3
  78. and eax,not 3 ;eax = xLeft aligned to next dword
  79. mov edi,pptlSrc ;edi = pptlSrc
  80. mov ecx,lSrcDelta
  81. imul ecx,[edi].ptl_y
  82. add ecx,[edi].ptl_x
  83. add ecx,eax
  84. sub ecx,[esi].xLeft
  85. add ecx,pvSrcStart
  86. mov pvSrc,ecx ;pvSrc = pptlSrc->y * lSrcDelta +
  87. ; pptlSrc->x + dest alignment +
  88. ; pvSrcStart
  89. mov edi,[ebx].pdev_lNextScan
  90. imul edi,[esi].yTop
  91. add edi,eax
  92. add edi,[ebx].pdev_pvBitmapStart
  93. ;edi = prclDst->top * ppdev->lNextScan +
  94. ; aligned left + ppdev->pvBitmapStart
  95. ; (the aligned destination address)
  96. ; eax = prclDst->left aligned to dword
  97. ; ebx = ppdev
  98. ; edx = # of scans to do in this bank
  99. ; esi = prclDst
  100. ; edi = destination address
  101. mov ecx,[esi].xRight ;esi = prclDst->right
  102. sub ecx,eax ;ecx = length in bytes from first full
  103. ; dword to last byte
  104. jl short src8_one_dword ;special case if the destination
  105. ; starts and ends in the same dword
  106. mov eax,ecx
  107. and ecx,not 3 ;ecx = length of middle dwords in bytes
  108. sub eax,ecx ;eax = (right & 3)
  109. mov esi,[esi].xLeft
  110. and esi,3 ;esi = (left & 3)
  111. shl eax,2
  112. or esi,eax ;esi = ((right & 3) << 2) | (left & 3)
  113. ; (look-up index for loop vectors)
  114. mov ebx,[ebx].pdev_lNextScan
  115. sub ebx,ecx ;ebx = ppdev->lNextScan
  116. ; - (culMiddle << 2)
  117. ; (destination delta)
  118. mov eax,lSrcDelta
  119. sub eax,ecx ;eax = lSrcDelta - (culMiddle << 2)
  120. ; (source delta)
  121. shr ecx,2
  122. mov culMiddle,ecx ;culMiddle = number of middle dwords
  123. ; eax = source delta
  124. ; ebx = destination delta
  125. ; ecx =
  126. ; edx = # scans to do
  127. ; esi = flags
  128. ; edi = destination pointer
  129. ; Set up for loop entry
  130. mov ecx,gapfnMasterCopyTable[esi*4] ;every loop vector is a dword
  131. mov esi,pvSrc
  132. mov pfnLoopVector,ecx ;save loop vector for next bank
  133. jmp ecx
  134. ;-----------------------------------------------------------------------;
  135. ; Here we handle cases where copy starts and ends in same dword:
  136. public src8_one_dword
  137. src8_one_dword::
  138. sub eax,[esi].xLeft ;eax = # of bytes from left edge to
  139. ; first dword
  140. add ecx,eax ;ecx = # of bytes to do
  141. sub edi,eax ;adjust back to start byte
  142. sub pvSrc,eax ;adjust accordingly
  143. mov ebx,[ebx].pdev_lNextScan;ebx = ppdev->lNextScan
  144. ; (destination delta)
  145. mov eax,lSrcDelta ;eax = lSrcDelta
  146. ; (source delta)
  147. ; eax = source delta
  148. ; ebx = destination delta
  149. ; esi =
  150. ; edx = # scans to do
  151. ; ecx = flags
  152. ; edi = destination pointer
  153. ; Set up for loop entry
  154. dec ecx ;adjust for table (no zero entry)
  155. mov ecx,gapfnOneDwordCopyTable[ecx*4]
  156. mov esi,pvSrc
  157. mov pfnLoopVector,ecx ;save loop vector for next bank
  158. jmp ecx
  159. ;-----------------------------------------------------------------------;
  160. ; We have following variables set before calling loops:
  161. ;
  162. ; eax = source delta (from end of dwords to start of dwords on next scan)
  163. ; ebx = destination delta
  164. ; edx = # of scans
  165. ; esi = source pointer
  166. ; edi = destination pointer
  167. ; culMiddle = number of dwords to copy
  168. ;-----------------------------------------------------------------------;
  169. ; See if done. If not, get next bank.
  170. public src8_done
  171. src8_done::
  172. cmp cyToGo,0
  173. jg short src8_next_bank
  174. cRet vSrcCopy8bpp
  175. src8_next_bank:
  176. push esi
  177. push ebx ;save some registers
  178. mov ebx,ppdev
  179. push eax
  180. mov esi,[ebx].pdev_rcl1WindowClip.yBottom
  181. sub edi,[ebx].pdev_pvBitmapStart
  182. ptrCall <dword ptr [ebx].pdev_pfnBankControl>, \
  183. <ebx,esi,JustifyTop>
  184. add edi,[ebx].pdev_pvBitmapStart
  185. mov edx,[ebx].pdev_rcl1WindowClip.yBottom
  186. sub edx,esi ;edx = # scans can do in this bank
  187. mov eax,cyToGo
  188. sub eax,edx
  189. mov cyToGo,eax ;eax = # scans to do after this bank
  190. sbb ecx,ecx
  191. and ecx,eax
  192. add edx,ecx ;edx = min(# of scans can do in bank,
  193. ; # of scans to go)
  194. pop eax ;restore those registers
  195. pop ebx
  196. pop esi
  197. jmp pfnLoopVector
  198. ;-----------------------------------------------------------------------;
  199. ; We organize the tables as follows so that it's easy to index into them:
  200. ;
  201. ; Bits 2 and 3 = # of trailing bytes
  202. ; Bits 0 and 1 = # of leading bytes to skip in first dword
  203. align 4
  204. gapfnMasterCopyTable label dword
  205. dd copy_wide_w_00_loop
  206. dd copy_wide_w_30_loop
  207. dd copy_wide_w_20_loop
  208. dd copy_wide_w_10_loop
  209. dd copy_wide_w_01_loop
  210. dd copy_wide_w_31_loop
  211. dd copy_wide_w_21_loop
  212. dd copy_wide_w_11_loop
  213. dd copy_wide_w_02_loop
  214. dd copy_wide_w_32_loop
  215. dd copy_wide_w_22_loop
  216. dd copy_wide_w_12_loop
  217. dd copy_wide_w_03_loop
  218. dd copy_wide_w_33_loop
  219. dd copy_wide_w_23_loop
  220. dd copy_wide_w_13_loop
  221. align 4
  222. gapfnOneDwordCopyTable label dword
  223. dd copy_thin_t_1_loop
  224. dd copy_thin_t_2_loop
  225. dd copy_thin_t_3_loop
  226. ;-----------------------------------------------------------------------;
  227. ; Copy n dwords, 0 leading bytes, 0 trailing bytes, then advance to next
  228. ; scan line.
  229. copy_wide_w_00_loop::
  230. mov ecx,culMiddle
  231. rep movsd
  232. add esi,eax
  233. add edi,ebx
  234. dec edx
  235. jnz copy_wide_w_00_loop
  236. jmp src8_done
  237. ;-----------------------------------------------------------------------;
  238. ; Copy n dwords, 0 leading bytes, 1 trailing bytes, then advance to next
  239. ; scan line.
  240. copy_wide_w_01_loop::
  241. mov ecx,culMiddle
  242. rep movsd
  243. mov cl,[esi]
  244. mov [edi],cl
  245. add esi,eax
  246. add edi,ebx
  247. dec edx
  248. jnz copy_wide_w_01_loop
  249. jmp src8_done
  250. ;-----------------------------------------------------------------------;
  251. ; Copy n dwords, 0 leading bytes, 2 trailing bytes, then advance to next
  252. ; scan line.
  253. copy_wide_w_02_loop::
  254. mov ecx,culMiddle
  255. rep movsd
  256. mov cx,[esi]
  257. mov [edi],cx
  258. add esi,eax
  259. add edi,ebx
  260. dec edx
  261. jnz copy_wide_w_02_loop
  262. jmp src8_done
  263. ;-----------------------------------------------------------------------;
  264. ; Copy n dwords, 0 leading bytes, 3 trailing bytes, then advance to next
  265. ; scan line.
  266. copy_wide_w_03_loop::
  267. mov ecx,culMiddle
  268. rep movsd
  269. mov cx,[esi]
  270. mov [edi],cx
  271. mov cl,[esi+2]
  272. mov [edi+2],cl
  273. add esi,eax
  274. add edi,ebx
  275. dec edx
  276. jnz copy_wide_w_03_loop
  277. jmp src8_done
  278. ;-----------------------------------------------------------------------;
  279. ; Copy n dwords, 1 leading byte, 0 trailing bytes, then advance to next
  280. ; scan line.
  281. copy_wide_w_10_loop::
  282. mov cl,[esi-1]
  283. mov [edi-1],cl
  284. mov ecx,culMiddle
  285. rep movsd
  286. add esi,eax
  287. add edi,ebx
  288. dec edx
  289. jnz copy_wide_w_10_loop
  290. jmp src8_done
  291. ;-----------------------------------------------------------------------;
  292. ; Copy n dwords, 1 leading byte, 1 trailing bytes, then advance to next
  293. ; scan line.
  294. copy_wide_w_11_loop::
  295. mov cl,[esi-1]
  296. mov [edi-1],cl
  297. mov ecx,culMiddle
  298. rep movsd
  299. mov cl,[esi]
  300. mov [edi],cl
  301. add esi,eax
  302. add edi,ebx
  303. dec edx
  304. jnz copy_wide_w_11_loop
  305. jmp src8_done
  306. ;-----------------------------------------------------------------------;
  307. ; Copy n dwords, 1 leading byte, 2 trailing bytes, then advance to next
  308. ; scan line.
  309. copy_wide_w_12_loop::
  310. mov cl,[esi-1]
  311. mov [edi-1],cl
  312. mov ecx,culMiddle
  313. rep movsd
  314. mov cx,[esi]
  315. mov [edi],cx
  316. add esi,eax
  317. add edi,ebx
  318. dec edx
  319. jnz copy_wide_w_12_loop
  320. jmp src8_done
  321. ;-----------------------------------------------------------------------;
  322. ; Copy n dwords, 1 leading byte, 3 trailing bytes, then advance to next
  323. ; scan line.
  324. copy_wide_w_13_loop::
  325. mov cl,[esi-1]
  326. mov [edi-1],cl
  327. mov ecx,culMiddle
  328. rep movsd
  329. mov cx,[esi]
  330. mov [edi],cx
  331. mov cl,[esi+2]
  332. mov [edi+2],cl
  333. add esi,eax
  334. add edi,ebx
  335. dec edx
  336. jnz copy_wide_w_13_loop
  337. jmp src8_done
  338. ;-----------------------------------------------------------------------;
  339. ; Copy n dwords, 2 leading bytes, 0 trailing bytes, then advance to next
  340. ; scan line.
  341. copy_wide_w_20_loop::
  342. mov cx,[esi-2]
  343. mov [edi-2],cx
  344. mov ecx,culMiddle
  345. rep movsd
  346. add esi,eax
  347. add edi,ebx
  348. dec edx
  349. jnz copy_wide_w_20_loop
  350. jmp src8_done
  351. ;-----------------------------------------------------------------------;
  352. ; Copy n dwords, 2 leading bytes, 1 trailing bytes, then advance to next
  353. ; scan line.
  354. copy_wide_w_21_loop::
  355. mov cx,[esi-2]
  356. mov [edi-2],cx
  357. mov ecx,culMiddle
  358. rep movsd
  359. mov cl,[esi]
  360. mov [edi],cl
  361. add esi,eax
  362. add edi,ebx
  363. dec edx
  364. jnz copy_wide_w_21_loop
  365. jmp src8_done
  366. ;-----------------------------------------------------------------------;
  367. ; Copy n dwords, 2 leading bytes, 2 trailing bytes, then advance to next
  368. ; scan line.
  369. copy_wide_w_22_loop::
  370. mov cx,[esi-2]
  371. mov [edi-2],cx
  372. mov ecx,culMiddle
  373. rep movsd
  374. mov cx,[esi]
  375. mov [edi],cx
  376. add esi,eax
  377. add edi,ebx
  378. dec edx
  379. jnz copy_wide_w_22_loop
  380. jmp src8_done
  381. ;-----------------------------------------------------------------------;
  382. ; Copy n dwords, 2 leading bytes, 3 trailing bytes, then advance to next
  383. ; scan line.
  384. copy_wide_w_23_loop::
  385. mov cx,[esi-2]
  386. mov [edi-2],cx
  387. mov ecx,culMiddle
  388. rep movsd
  389. mov cx,[esi]
  390. mov [edi],cx
  391. mov cl,[esi+2]
  392. mov [edi+2],cl
  393. add esi,eax
  394. add edi,ebx
  395. dec edx
  396. jnz copy_wide_w_23_loop
  397. jmp src8_done
  398. ;-----------------------------------------------------------------------;
  399. ; Copy n dwords, 3 leading bytes, 0 trailing bytes, then advance to next
  400. ; scan line.
  401. copy_wide_w_30_loop::
  402. mov cl,[esi-3]
  403. mov [edi-3],cl
  404. mov cx,[esi-2]
  405. mov [edi-2],cx
  406. mov ecx,culMiddle
  407. rep movsd
  408. add esi,eax
  409. add edi,ebx
  410. dec edx
  411. jnz copy_wide_w_30_loop
  412. jmp src8_done
  413. ;-----------------------------------------------------------------------;
  414. ; Copy n dwords, 3 leading bytes, 1 trailing bytes, then advance to next
  415. ; scan line.
  416. copy_wide_w_31_loop::
  417. mov cl,[esi-3]
  418. mov [edi-3],cl
  419. mov cx,[esi-2]
  420. mov [edi-2],cx
  421. mov ecx,culMiddle
  422. rep movsd
  423. mov cl,[esi]
  424. mov [edi],cl
  425. add esi,eax
  426. add edi,ebx
  427. dec edx
  428. jnz copy_wide_w_31_loop
  429. jmp src8_done
  430. ;-----------------------------------------------------------------------;
  431. ; Copy n dwords, 3 leading bytes, 2 trailing bytes, then advance to next
  432. ; scan line.
  433. copy_wide_w_32_loop::
  434. mov cl,[esi-3]
  435. mov [edi-3],cl
  436. mov cx,[esi-2]
  437. mov [edi-2],cx
  438. mov ecx,culMiddle
  439. rep movsd
  440. mov cx,[esi]
  441. mov [edi],cx
  442. add esi,eax
  443. add edi,ebx
  444. dec edx
  445. jnz copy_wide_w_32_loop
  446. jmp src8_done
  447. ;-----------------------------------------------------------------------;
  448. ; Copy n dwords, 3 leading bytes, 3 trailing bytes, then advance to next
  449. ; scan line.
  450. copy_wide_w_33_loop::
  451. mov cl,[esi-3]
  452. mov [edi-3],cl
  453. mov cx,[esi-2]
  454. mov [edi-2],cx
  455. mov ecx,culMiddle
  456. rep movsd
  457. mov cx,[esi]
  458. mov [edi],cx
  459. mov cl,[esi+2]
  460. mov [edi+2],cl
  461. add esi,eax
  462. add edi,ebx
  463. dec edx
  464. jnz copy_wide_w_33_loop
  465. jmp src8_done
  466. ;-----------------------------------------------------------------------;
  467. ; Copy 1 byte, then advance to next scan line.
  468. copy_thin_t_1_loop::
  469. mov cl,[esi]
  470. mov [edi],cl
  471. add esi,eax
  472. add edi,ebx
  473. dec edx
  474. jnz copy_thin_t_1_loop
  475. jmp src8_done
  476. ;-----------------------------------------------------------------------;
  477. ; Copy 2 bytes, then advance to next scan line.
  478. copy_thin_t_2_loop::
  479. mov cx,[esi]
  480. mov [edi],cx
  481. add esi,eax
  482. add edi,ebx
  483. dec edx
  484. jnz copy_thin_t_2_loop
  485. jmp src8_done
  486. ;-----------------------------------------------------------------------;
  487. ; Copy 3 bytes, then advance to next scan line.
  488. copy_thin_t_3_loop::
  489. mov cx,[esi]
  490. mov [edi],cx
  491. mov cl,[esi+2]
  492. mov [edi+2],cl
  493. add esi,eax
  494. add edi,ebx
  495. dec edx
  496. jnz copy_thin_t_3_loop
  497. jmp src8_done
  498. public copy_wide_w_00_loop
  499. public copy_wide_w_01_loop
  500. public copy_wide_w_02_loop
  501. public copy_wide_w_03_loop
  502. public copy_wide_w_10_loop
  503. public copy_wide_w_11_loop
  504. public copy_wide_w_12_loop
  505. public copy_wide_w_13_loop
  506. public copy_wide_w_20_loop
  507. public copy_wide_w_21_loop
  508. public copy_wide_w_22_loop
  509. public copy_wide_w_23_loop
  510. public copy_wide_w_30_loop
  511. public copy_wide_w_31_loop
  512. public copy_wide_w_32_loop
  513. public copy_wide_w_33_loop
  514. public copy_thin_t_1_loop
  515. public copy_thin_t_2_loop
  516. public copy_thin_t_3_loop
  517. endProc vSrcCopy8bpp
  518. end