INTERP.ASM 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. ;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  2. ;SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  3. ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  4. ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  5. ;IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  6. ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  7. ;FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  8. ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  9. ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  10. ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  11. ;
  12. ; $Source: f:/miner/source/3d/rcs/interp.asm $
  13. ; $Revision: 1.21 $
  14. ; $Author: john $
  15. ; $Date: 1994/10/26 23:57:49 $
  16. ;
  17. ; Polygon object interpreter
  18. ;
  19. ; $Log: interp.asm $
  20. ; Revision 1.21 1994/10/26 23:57:49 john
  21. ; Took out gr_inverse_table
  22. ;
  23. ; Revision 1.20 1994/09/26 14:43:31 matt
  24. ; Put in checks for faces with fewer than 3 vertices
  25. ;
  26. ; Revision 1.19 1994/09/09 14:24:14 matt
  27. ; Added support for glowing textures, to add engine glow to Descent.
  28. ;
  29. ; Revision 1.18 1994/08/26 16:42:03 matt
  30. ; Added check for how many textures used in an object
  31. ;
  32. ; Revision 1.17 1994/07/29 18:29:17 matt
  33. ; Use instance-by-angles code, instead of building matrix here
  34. ;
  35. ; Revision 1.16 1994/07/25 10:58:28 matt
  36. ; Fixed morph effect for new 3d point handling
  37. ;
  38. ; Revision 1.15 1994/07/25 00:00:07 matt
  39. ; Made 3d no longer deal with point numbers, but only with pointers.
  40. ;
  41. ; Revision 1.14 1994/07/22 17:57:59 matt
  42. ; Changed the name of the rod functions, and took out some debugging code
  43. ;
  44. ; Revision 1.13 1994/06/07 16:49:36 matt
  45. ; Made interpreter take lighting value as parm, rather than in global var
  46. ;
  47. ; Revision 1.12 1994/05/31 22:11:52 matt
  48. ; Fixed morphing object lighting
  49. ;
  50. ; Revision 1.11 1994/05/31 18:35:52 matt
  51. ; Added lighting back to polygon objects
  52. ;
  53. ; Revision 1.10 1994/05/31 16:03:55 matt
  54. ; Made uvls right for triangulated faces in morphing objects
  55. ;
  56. ; Revision 1.9 1994/05/30 22:48:34 matt
  57. ; Added support for morph effect
  58. ;
  59. ; Revision 1.8 1994/05/19 23:12:04 matt
  60. ; Support new uvl value ranges
  61. ;
  62. ; Revision 1.7 1994/04/29 15:39:46 matt
  63. ; Use ebx in one place because the assembler seemed to be using it anyway
  64. ; even though I typed just bx.
  65. ;
  66. ; Revision 1.6 1994/04/19 17:02:32 matt
  67. ; Made g3d_interp_outline var accessible by C
  68. ;
  69. ; Revision 1.5 1994/03/30 10:22:40 matt
  70. ; Added outline option for polygon models
  71. ;
  72. ; Revision 1.4 1994/03/25 18:23:51 matt
  73. ; Fixed a couple of subobject problems, and made g3_draw_polygon_model
  74. ; take a pointer to a list of angvecs for subobj animation.
  75. ;
  76. ; Revision 1.3 1994/03/18 16:07:57 matt
  77. ; Added subobject and rod bitmap opcodes
  78. ;
  79. ; Revision 1.2 1994/03/15 21:23:04 matt
  80. ; Added code
  81. ;
  82. ; Revision 1.1 1994/03/14 21:26:56 matt
  83. ; Initial revision
  84. ;
  85. ;
  86. .386
  87. option oldstructs
  88. .nolist
  89. include types.inc
  90. include psmacros.inc
  91. include gr.inc
  92. include 3d.inc
  93. .list
  94. assume cs:_TEXT, ds:_DATA
  95. _DATA segment dword public USE32 'DATA'
  96. rcsid db "$Id: interp.asm 1.21 1994/10/26 23:57:49 john Exp $"
  97. align 4
  98. ;table with address for each opcode
  99. opcode_table dd op_eof ;0 = eof
  100. dd op_defpoints ;1 = defpoints
  101. dd op_flatpoly ;2 = flat-shaded polygon
  102. dd op_tmappoly ;3 = texture-mapped polygon
  103. dd op_sortnorm ;4 = sort by normal
  104. dd op_rodbm ;5 = rod bitmap
  105. dd op_subcall ;6 = call a subobject
  106. dd op_defp_start ;7 = defpoints with start
  107. dd op_glow ;8 = glow value for next poly
  108. n_opcodes = ($-opcode_table)/4
  109. bitmap_ptr dd ?
  110. anim_angles dd ? ;pointer to angle data
  111. morph_points dd ? ;alternate points for morph
  112. ;light value for the next tmap
  113. glow_num dd -1 ;-1 means off
  114. glow_values dd ? ;ptr to array of values
  115. public _highest_texture_num
  116. _highest_texture_num dw 0
  117. zero_angles fixang 0,0,0 ;vms_angvec <0,0,0> ;for if no angles specified
  118. rod_top_p g3s_point <>
  119. rod_bot_p g3s_point <>
  120. ifndef NDEBUG
  121. public g3d_interp_outline,_g3d_interp_outline
  122. _g3d_interp_outline label dword
  123. g3d_interp_outline dd 0
  124. endif
  125. morph_pointlist dd ?,?,?
  126. morph_uvls fix 3 dup (?,?,?)
  127. ;the light for the current model
  128. model_light fix ?
  129. ;ptr to array of points
  130. Interp_point_list dd ?
  131. MAX_POINTS_PER_POLY = 25
  132. point_list dd MAX_POINTS_PER_POLY dup (?)
  133. _DATA ends
  134. _TEXT segment dword public USE32 'CODE'
  135. ;get and jump to next opcode
  136. next macro
  137. xor ebx,ebx
  138. mov bx,[ebp]
  139. ifndef NDEBUG
  140. cmp ebx,n_opcodes
  141. break_if ge,'Invalid opcode'
  142. endif
  143. mov ebx,opcode_table[ebx*4]
  144. jmp ebx
  145. endm
  146. ;get and call the next opcode
  147. call_next macro
  148. xor ebx,ebx
  149. mov bx,[ebp]
  150. ifndef NDEBUG
  151. cmp ebx,n_opcodes
  152. break_if ge,'Invalid opcode'
  153. endif
  154. mov ebx,opcode_table[ebx*4]
  155. call ebx
  156. endm
  157. ;give the interpreter an array of points to use
  158. g3_set_interp_points:
  159. mov Interp_point_list,eax
  160. ret
  161. ;interpreter to draw polygon model
  162. ;takes esi=ptr to object, edi=ptr to array of bitmap pointers,
  163. ;eax=ptr to anim angles, edx=light value, ebx=ptr to array of glow values
  164. g3_draw_polygon_model:
  165. pushm eax,ebx,ecx,edx,esi,edi,ebp
  166. mov ebp,esi ;ebp = interp ptr
  167. mov bitmap_ptr,edi ;save ptr to bitmap array
  168. mov anim_angles,eax
  169. mov model_light,edx
  170. mov glow_values,ebx
  171. mov glow_num,-1
  172. ;;@@ mov depth,0
  173. call_next
  174. popm eax,ebx,ecx,edx,esi,edi,ebp
  175. ret
  176. ;handlers for opcodes
  177. ;end of a model or sub-rountine
  178. op_eof: ret
  179. ;define a list of points
  180. op_defpoints: xor ecx,ecx
  181. mov cx,2[ebp] ;num points
  182. mov edi,Interp_point_list
  183. lea esi,4[ebp]
  184. rotate_loop: call g3_rotate_point
  185. add edi,size g3s_point
  186. add esi,size vms_vector
  187. dec ecx
  188. jnz rotate_loop
  189. mov ebp,esi
  190. next
  191. ;define a list of points, with starting point num specified
  192. op_defp_start: xor ecx,ecx
  193. xor eax,eax
  194. mov ax,w 4[ebp] ;starting point num
  195. imulc eax,size(g3s_point) ;get ofs of point
  196. ;changed the above line from "size g3s_point" to "size(g3s_point)" to make the compiler happy -KRB
  197. add eax,Interp_point_list
  198. mov edi,eax
  199. mov cx,2[ebp] ;num points
  200. lea esi,8[ebp]
  201. jmp rotate_loop
  202. next
  203. ;draw a flat-shaded polygon
  204. op_flatpoly: xor ecx,ecx
  205. mov cx,2[ebp] ;num verts
  206. lea esi,4[ebp] ;point
  207. lea edi,16[ebp] ;vector
  208. call g3_check_normal_facing
  209. jng flat_not_facing
  210. ;polygon is facing, so draw it
  211. xor eax,eax
  212. mov ax,28[ebp] ;get color
  213. call gr_setcolor_ ;set it
  214. lea esi,30[ebp] ;point number list
  215. ;make list of point pointers
  216. ifndef NDEBUG
  217. cmp ecx,MAX_POINTS_PER_POLY
  218. break_if ge,'Too many points in interp poly'
  219. endif
  220. lea edi,point_list
  221. xor ebx,ebx
  222. copy_loop: xor eax,eax
  223. mov ax,w [esi+ebx*2] ;get point number
  224. imulc eax,size(g3s_point);Modified to add Parentheses -KRB
  225. add eax,Interp_point_list
  226. mov [edi+ebx*4],eax
  227. inc ebx
  228. cmp ebx,ecx
  229. jne copy_loop
  230. mov esi,edi
  231. call g3_draw_poly
  232. xor ecx,ecx
  233. mov cx,2[ebp] ;restore count
  234. ifndef NDEBUG
  235. test g3d_interp_outline,-1
  236. jz no_outline
  237. pushm ecx,esi
  238. lea esi,30[ebp]
  239. call draw_outline
  240. popm ecx,esi
  241. no_outline:
  242. endif
  243. ;polygon is not facing (or we've plotted it). jump to next opcode
  244. flat_not_facing: and ecx,0fffffffeh
  245. inc ecx ;adjust for pad
  246. lea ebp,30[ebp+ecx*2]
  247. next
  248. ;set the glow value for the next tmap
  249. op_glow: test glow_values,-1
  250. jz skip_glow
  251. xor eax,eax
  252. mov ax,2[ebp]
  253. mov glow_num,eax
  254. skip_glow: add ebp,4
  255. next
  256. ;draw a texture map
  257. op_tmappoly: xor ecx,ecx
  258. mov cx,2[ebp] ;num verts
  259. lea esi,4[ebp] ;point
  260. lea edi,16[ebp] ;normal
  261. call g3_check_normal_facing
  262. jng tmap_not_facing
  263. ;polygon is facing, so draw it
  264. xor edx,edx
  265. mov dx,28[ebp] ;get bitmap number
  266. mov eax,bitmap_ptr
  267. mov edx,[eax+edx*4]
  268. lea esi,30[ebp] ;point number list
  269. mov eax,ecx
  270. and eax,0fffffffeh
  271. inc eax
  272. lea ebx,30[ebp+eax*2] ;get uvl list
  273. ;calculate light from surface normal
  274. push esi
  275. test glow_num,-1 ;glow override?
  276. js no_glow
  277. ;special glow lighting, which doesn't care about surface normal
  278. mov eax,glow_num
  279. mov esi,glow_values
  280. mov eax,[esi+eax*4]
  281. mov glow_num,-1
  282. jmp got_light_value
  283. no_glow:
  284. lea esi,View_matrix.fvec
  285. lea edi,16[ebp] ;normal
  286. call vm_vec_dotprod
  287. neg eax
  288. ;scale light by model light
  289. push edx
  290. mov edx,eax
  291. add eax,eax
  292. add eax,edx ;eax *= 3
  293. sar eax,2 ;eax *= 3/4
  294. add eax,f1_0/4 ;eax = 1/4 + eax * 3/4
  295. fixmul model_light
  296. pop edx
  297. ;now poke light into l values
  298. got_light_value: pushm ecx,ebx
  299. l_loop: mov 8[ebx],eax
  300. add ebx,12
  301. dec ecx
  302. jnz l_loop
  303. popm ecx,ebx
  304. pop esi
  305. ;now draw it
  306. ;make list of point pointers
  307. ifndef NDEBUG
  308. cmp ecx,MAX_POINTS_PER_POLY
  309. break_if ge,'Too many points in interp poly'
  310. endif
  311. push ebx
  312. lea edi,point_list
  313. xor ebx,ebx
  314. copy_loop2: xor eax,eax
  315. mov ax,w [esi+ebx*2] ;get point number
  316. imulc eax,size(g3s_point);;Modified to add Parentheses -KRB
  317. add eax,Interp_point_list
  318. mov [edi+ebx*4],eax
  319. inc ebx
  320. cmp ebx,ecx
  321. jne copy_loop2
  322. mov esi,edi
  323. pop ebx
  324. call g3_draw_tmap
  325. xor ecx,ecx
  326. mov cx,2[ebp] ;restore count
  327. ifndef NDEBUG
  328. test g3d_interp_outline,-1
  329. jz no_outline2
  330. pushm ecx,esi
  331. lea esi,30[ebp]
  332. call draw_outline
  333. popm ecx,esi
  334. no_outline2:
  335. endif
  336. ;polygon is not facing (or we've plotted it). jump to next opcode
  337. tmap_not_facing: mov ebx,ecx
  338. and ebx,0fffffffeh
  339. inc ebx ;adjust for pad
  340. lea ebp,30[ebp+ebx*2]
  341. mov eax,ecx
  342. sal ecx,1
  343. add ecx,eax
  344. sal ecx,2 ;ecx=ecx*12
  345. add ebp,ecx ;point past uvls
  346. next
  347. ;sort based on surface normal
  348. op_sortnorm: lea esi,16[ebp] ;point
  349. lea edi,4[ebp] ;vector
  350. call g3_check_normal_facing
  351. jng sortnorm_not_facing
  352. ;is facing. draw back then front
  353. push ebp
  354. xor eax,eax
  355. mov ax,30[ebp] ;get back offset
  356. add ebp,eax
  357. call_next
  358. mov ebp,[esp] ;get ebp
  359. xor eax,eax
  360. mov ax,28[ebp] ;get front offset
  361. add ebp,eax
  362. call_next
  363. pop ebp
  364. lea ebp,32[ebp]
  365. next
  366. ;is not facing. draw front then back
  367. sortnorm_not_facing:
  368. push ebp
  369. xor eax,eax
  370. mov ax,28[ebp] ;get back offset
  371. add ebp,eax
  372. call_next
  373. mov ebp,[esp] ;get ebp
  374. xor eax,eax
  375. mov ax,30[ebp] ;get front offset
  376. add ebp,eax
  377. call_next
  378. pop ebp
  379. lea ebp,32[ebp]
  380. next
  381. ;draw a rod bitmap
  382. op_rodbm: lea esi,20[ebp] ;bot point
  383. lea edi,rod_bot_p
  384. call g3_rotate_point
  385. lea esi,4[ebp] ;top point
  386. lea edi,rod_top_p
  387. call g3_rotate_point
  388. lea esi,rod_bot_p ;esi=bot, edi=top
  389. mov eax,16[ebp] ;bot width
  390. mov edx,32[ebp] ;top width
  391. xor ebx,ebx
  392. mov bx,2[ebp] ;get bitmap number
  393. mov ecx,bitmap_ptr
  394. mov ebx,[ecx+ebx*4]
  395. call g3_draw_rod_tmap
  396. lea ebp,36[ebp]
  397. next
  398. ;draw a subobject
  399. op_subcall: xor eax,eax
  400. mov ax,2[ebp] ;get object number
  401. ;get ptr to angles
  402. mov edi,anim_angles
  403. or edi,edi
  404. jnz angles_not_null
  405. ;angles not specified. Use zero angles
  406. lea edi,zero_angles
  407. jmp got_angles
  408. angles_not_null:
  409. imulc eax,size(vms_angvec);Modified to add Parentheses -KRB
  410. add edi,eax
  411. got_angles:
  412. ;angles in edi
  413. lea esi,4[ebp] ;get position
  414. call g3_start_instance_angles
  415. push ebp
  416. xor eax,eax
  417. mov ax,16[ebp]
  418. add ebp,eax ;offset of subobject
  419. call_next ;draw the subobject
  420. pop ebp
  421. call g3_done_instance
  422. lea ebp,20[ebp]
  423. next
  424. ;initialize a polygon object
  425. ;translate colors, scale UV values
  426. ;takes esi=ptr to model
  427. g3_init_polygon_model:
  428. mov _highest_texture_num,-1
  429. pushm eax,ebx,ecx,edx,esi,edi
  430. call init_loop
  431. popm eax,ebx,ecx,edx,esi,edi
  432. ret
  433. init_loop: mov ax,[esi] ;get opcode
  434. cmp ax,0 ;eof
  435. jne not_eof
  436. ret
  437. not_eof:
  438. ;defpoints
  439. cmp ax,1 ;defpoints
  440. jne not_defpoints
  441. xor eax,eax
  442. mov ax,2[esi] ;get count
  443. sal eax,1
  444. add ax,2[esi] ;*3
  445. lea esi,4[esi+eax*4]
  446. jmp init_loop
  447. not_defpoints:
  448. ;flat polygon
  449. cmp ax,2
  450. jne not_flatpoly
  451. ifndef NDEBUG
  452. cmp w 2[esi],3
  453. break_if l,'face must have 3 or more points'
  454. endif
  455. ;NO_INVERSE_TABLE xor ebx,ebx
  456. ;NO_INVERSE_TABLE mov bx,28[esi] ;get color
  457. ;NO_INVERSE_TABLE xor eax,eax
  458. ;NO_INVERSE_TABLE mov al,gr_inverse_table[ebx] ;xlate it
  459. ; The following 3 lines replace the above
  460. xor eax, eax
  461. mov ax,28[esi] ;get color
  462. call gr_find_closest_color_15bpp_
  463. mov 28[esi],ax ;store new color
  464. xor ecx,ecx
  465. mov cx,2[esi] ;get nverts
  466. and ecx,0fffffffeh
  467. inc ecx ;adjust for pad
  468. lea esi,30[esi+ecx*2]
  469. jmp init_loop
  470. not_flatpoly:
  471. ;tmap polygon
  472. cmp ax,3
  473. jne not_tmappoly
  474. ifndef NDEBUG
  475. cmp w 2[esi],3
  476. break_if l,'face must have 3 or more points'
  477. endif
  478. mov ax,28[esi] ;get bitmap number
  479. cmp ax,_highest_texture_num
  480. jle not_new
  481. mov _highest_texture_num,ax
  482. not_new: xor ecx,ecx
  483. mov cx,2[esi] ;get nverts
  484. mov ebx,ecx
  485. and ebx,0fffffffeh
  486. inc ebx ;adjust for pad
  487. lea esi,30[esi+ebx*2] ;point at uvls
  488. imul ecx,12 ;size of uvls
  489. add esi,ecx ;skip them
  490. jmp init_loop
  491. ;;@@init_uv_loop: mov eax,[esi] ;get u
  492. ;;@@ imul eax,64 ;times bitmap w
  493. ;;@@ mov [esi],eax
  494. ;;@@ mov eax,4[esi] ;get v
  495. ;;@@ imul eax,64 ;times bitmap h
  496. ;;@@ mov 4[esi],eax
  497. ;;@@ add esi,12 ;point at next
  498. ;;@@ dec ecx
  499. ;;@@ jnz init_uv_loop
  500. ;;@@ jmp init_loop
  501. not_tmappoly:
  502. ;sort
  503. cmp ax,4 ;sortnorm
  504. jne not_sortnorm
  505. push esi
  506. xor eax,eax
  507. mov ax,28[esi] ;get front offset
  508. add esi,eax
  509. call init_loop
  510. mov esi,[esp]
  511. xor eax,eax
  512. mov ax,30[esi] ;get front offset
  513. add esi,eax
  514. call init_loop
  515. pop esi
  516. lea esi,32[esi]
  517. jmp init_loop
  518. not_sortnorm:
  519. cmp ax,5
  520. jne not_rodbm
  521. add esi,36
  522. jmp init_loop
  523. not_rodbm:
  524. cmp ax,6
  525. jne not_subcall
  526. push esi
  527. xor eax,eax
  528. mov ax,16[esi] ;get subobj offset
  529. add esi,eax
  530. call init_loop
  531. pop esi
  532. add esi,20
  533. jmp init_loop
  534. not_subcall:
  535. cmp ax,7 ;defpoints
  536. jne not_defpoints_st
  537. xor eax,eax
  538. mov ax,2[esi] ;get count
  539. sal eax,1
  540. add ax,2[esi] ;*3
  541. lea esi,8[esi+eax*4]
  542. jmp init_loop
  543. not_defpoints_st:
  544. cmp ax,8
  545. jne not_glow
  546. add esi,4
  547. jmp init_loop
  548. not_glow:
  549. debug_brk "Invalid opcode"
  550. jmp init_loop
  551. ;takes ecx=count, esi=ptr to point list
  552. draw_outline: pushm eax,ebx,ecx,edx,esi,edi
  553. ;NO_INVERSE_TABLE xor eax,eax
  554. ;NO_INVERSE_TABLE mov al,gr_inverse_table[7fffh] ;white
  555. mov eax, 255 ; bright white
  556. call gr_setcolor_
  557. mov ebx,esi
  558. xor eax,eax
  559. mov ax,[ebx] ;get first point
  560. push eax ;save it
  561. outline_loop: xor esi,esi
  562. xor edi,edi
  563. mov si,[ebx]
  564. dec ecx
  565. jz done_loop
  566. mov di,2[ebx]
  567. push ebx
  568. imul esi,size g3s_point
  569. add esi,Interp_point_list
  570. imul edi,size g3s_point
  571. add edi,Interp_point_list
  572. call g3_draw_line
  573. pop ebx
  574. add ebx,2
  575. jmp outline_loop
  576. done_loop: pop edi ;get first point back
  577. imul esi,size g3s_point
  578. add esi,Interp_point_list
  579. imul edi,size g3s_point
  580. add edi,Interp_point_list
  581. call g3_draw_line
  582. popm eax,ebx,ecx,edx,esi,edi
  583. ret
  584. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  585. ;Special code to draw morphing objects
  586. ;define a list of points
  587. morph_defpoints: xor ecx,ecx
  588. mov cx,2[ebp] ;num points
  589. mov edi,Interp_point_list
  590. lea esi,4[ebp]
  591. morph_rotate_list: lea eax,[ecx*2+ecx] ;eax=npoint * 3
  592. lea esi,[esi+eax*4] ;point past points
  593. push esi
  594. mov esi,morph_points ;get alternate points
  595. morph_rotate_loop: call g3_rotate_point
  596. add edi,size g3s_point
  597. add esi,size vms_vector
  598. dec ecx
  599. jnz morph_rotate_loop
  600. pop esi ;restore pointer
  601. mov ebp,esi
  602. next
  603. ;define a list of points, with starting point num specified
  604. morph_defp_start: xor ecx,ecx
  605. xor eax,eax
  606. mov ax,w 4[ebp] ;starting point num
  607. imulc eax,size(g3s_point);Modified to add Parentheses -KRB ;get ofs of point
  608. add eax,Interp_point_list
  609. mov edi,eax
  610. mov cx,2[ebp] ;num points
  611. lea esi,8[ebp]
  612. jmp morph_rotate_list
  613. ;draw a flat-shaded polygon
  614. morph_flatpoly: xor ecx,ecx
  615. mov cx,2[ebp] ;num verts
  616. lea esi,4[ebp] ;point
  617. lea edi,16[ebp] ;vector
  618. ;set color
  619. xor eax,eax
  620. mov ax,28[ebp] ;get color
  621. call gr_setcolor_ ;set it
  622. ;check and draw
  623. lea esi,30[ebp] ;point number list
  624. xor eax,eax
  625. lodsw
  626. imulc eax,size(g3s_point);Modified to add Parentheses -KRB
  627. add eax,Interp_point_list
  628. mov morph_pointlist,eax
  629. xor eax,eax
  630. lodsw
  631. imulc eax,size(g3s_point);Modified to add Parentheses -KRB
  632. add eax,Interp_point_list
  633. mov morph_pointlist+4,eax
  634. xor eax,eax
  635. lodsw
  636. imulc eax,size(g3s_point);Modified to add Parentheses -KRB
  637. add eax,Interp_point_list
  638. mov morph_pointlist+8,eax
  639. cmp ecx,3 ;3 points is good!
  640. je flat_got3
  641. sub ecx,2 ;tri count
  642. flat_tri_loop: xor edi,edi ;no normal, must compute
  643. pushm ecx,esi
  644. mov ecx,3 ;always draw triangle
  645. lea esi,morph_pointlist
  646. call g3_check_and_draw_poly
  647. popm ecx,esi
  648. mov eax,morph_pointlist+8
  649. mov morph_pointlist+4,eax
  650. xor eax,eax
  651. lodsw
  652. imulc eax,size(g3s_point);Modified to add Parentheses -KRB
  653. add eax,Interp_point_list
  654. mov morph_pointlist+8,eax
  655. dec ecx
  656. jnz flat_tri_loop
  657. jmp flat_done_draw
  658. flat_got3:
  659. lea esi,morph_pointlist
  660. xor edi,edi ;no normal, must compute
  661. call g3_check_and_draw_poly
  662. flat_done_draw: xor ecx,ecx
  663. mov cx,2[ebp] ;restore count
  664. and ecx,0fffffffeh
  665. inc ecx ;adjust for pad
  666. lea ebp,30[ebp+ecx*2]
  667. next
  668. ;draw a texture map
  669. morph_tmappoly: xor ecx,ecx
  670. mov cx,2[ebp] ;num verts
  671. lea esi,4[ebp] ;point
  672. lea edi,16[ebp] ;normal
  673. ;get bitmap
  674. xor edx,edx
  675. mov dx,28[ebp] ;get bitmap number
  676. mov eax,bitmap_ptr
  677. mov edx,[eax+edx*4]
  678. lea esi,30[ebp] ;point number list
  679. mov eax,ecx
  680. and eax,0fffffffeh
  681. inc eax
  682. lea ebx,30[ebp+eax*2] ;get uvl list
  683. ;calculate light from surface normal
  684. push esi
  685. lea esi,View_matrix.fvec
  686. lea edi,16[ebp] ;normal
  687. call vm_vec_dotprod
  688. neg eax
  689. ;scale light by model light
  690. push edx
  691. mov edx,eax
  692. add eax,eax
  693. add eax,edx ;eax *= 3
  694. sar eax,2 ;eax *= 3/4
  695. add eax,f1_0/4 ;eax = 1/4 + eax * 3/4
  696. fixmul model_light
  697. or eax,eax
  698. jge not_zero
  699. xor eax,eax
  700. not_zero:
  701. pop edx
  702. pop esi
  703. ;now eax=plane light value
  704. mov morph_uvls+8,eax
  705. mov morph_uvls+20,eax
  706. mov morph_uvls+32,eax
  707. xor eax,eax
  708. lodsw
  709. imulc eax,size(g3s_point);Modified to add Parentheses -KRB
  710. add eax,Interp_point_list
  711. mov morph_pointlist,eax
  712. xor eax,eax
  713. lodsw
  714. imulc eax,size(g3s_point);Modified to add Parentheses -KRB
  715. add eax,Interp_point_list
  716. mov morph_pointlist+4,eax
  717. xor eax,eax
  718. lodsw
  719. imulc eax,size(g3s_point);Modified to add Parentheses -KRB
  720. add eax,Interp_point_list
  721. mov morph_pointlist+8,eax
  722. cmp ecx,3 ;3 points is good!
  723. jl tmap_done_draw ;something is bad, abort
  724. je tmap_got3
  725. sub ecx,2 ;tri count
  726. push edx
  727. mov edx,[ebx]
  728. mov morph_uvls,edx
  729. mov edx,4[ebx]
  730. mov morph_uvls+4,edx
  731. mov edx,12[ebx]
  732. mov morph_uvls+12,edx
  733. mov edx,16[ebx]
  734. mov morph_uvls+16,edx
  735. mov edx,24[ebx]
  736. mov morph_uvls+24,edx
  737. mov edx,28[ebx]
  738. mov morph_uvls+28,edx
  739. add ebx,3*12
  740. pop edx
  741. tmap_tri_loop: xor edi,edi ;no normal, must compute
  742. pushm ebx,edx,ecx,esi
  743. mov ecx,3 ;always draw triangle
  744. lea esi,morph_pointlist
  745. lea ebx,morph_uvls
  746. call g3_check_and_draw_tmap
  747. popm ebx,edx,ecx,esi
  748. mov eax,morph_pointlist+8
  749. mov morph_pointlist+4,eax
  750. xor eax,eax
  751. lodsw
  752. imulc eax,size(g3s_point);Modified to add Parentheses -KRB
  753. add eax,Interp_point_list
  754. mov morph_pointlist+8,eax
  755. push edx
  756. mov edx,morph_uvls+24
  757. mov morph_uvls+12,edx
  758. mov edx,morph_uvls+28
  759. mov morph_uvls+16,edx
  760. mov edx,[ebx]
  761. mov morph_uvls+24,edx
  762. mov edx,4[ebx]
  763. mov morph_uvls+28,edx
  764. add ebx,12
  765. pop edx
  766. dec ecx
  767. jnz tmap_tri_loop
  768. jmp tmap_done_draw
  769. tmap_got3:
  770. ;poke in light values
  771. pusha
  772. tmap_l_loop: mov 8[ebx],eax
  773. add ebx,12
  774. dec ecx
  775. jnz tmap_l_loop
  776. popa
  777. lea esi,morph_pointlist
  778. xor edi,edi ;no normal
  779. call g3_check_and_draw_tmap
  780. tmap_done_draw: xor ecx,ecx
  781. mov cx,2[ebp] ;restore count
  782. ;jump to next opcode
  783. mov ebx,ecx
  784. and ebx,0fffffffeh
  785. inc ebx ;adjust for pad
  786. lea ebp,30[ebp+ebx*2]
  787. mov eax,ecx
  788. sal ecx,1
  789. add ecx,eax
  790. sal ecx,2 ;ecx=ecx*12
  791. add ebp,ecx ;point past uvls
  792. next
  793. ;interpreter to draw polygon model
  794. ;takes esi=ptr to object, edi=ptr to array of bitmap pointers,
  795. ;eax=ptr to anim angles, ebx=alternate points, edx=light value
  796. g3_draw_morphing_model:
  797. pushm eax,ebx,ecx,edx,esi,edi,ebp
  798. mov bitmap_ptr,edi ;save ptr to bitmap array
  799. mov anim_angles,eax
  800. mov morph_points,ebx
  801. mov model_light,edx
  802. mov ebp,esi ;ebp = interp ptr
  803. ;set alternate opcode pointers
  804. push opcode_table[1*4] ;defpoints
  805. push opcode_table[2*4] ;flatpoly
  806. push opcode_table[3*4] ;tmappoly
  807. push opcode_table[7*4] ;defp_start
  808. mov opcode_table[1*4],offset morph_defpoints
  809. mov opcode_table[2*4],offset morph_flatpoly
  810. mov opcode_table[3*4],offset morph_tmappoly
  811. mov opcode_table[7*4],offset morph_defp_start
  812. call_next
  813. pop opcode_table[7*4] ;defp_start
  814. pop opcode_table[3*4] ;tmappoly
  815. pop opcode_table[2*4] ;flatpoly
  816. pop opcode_table[1*4] ;defpoints
  817. popm eax,ebx,ecx,edx,esi,edi,ebp
  818. ret
  819. _TEXT ends
  820. end
  821.