home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / dxf23dv1.zip / DXF23DV.ASM < prev    next >
Assembly Source File  |  1994-05-25  |  60KB  |  2,262 lines

  1. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2. ; DXF to 3DVectors Converter by John McCarthy
  3. ;
  4. ; Current DXF types supported: 3DFACE, PFACE
  5. ;
  6. ; The 3dfaces are between 1 and 4 points where:
  7. ;   1 = single point
  8. ;   2 = line
  9. ;   3 = triangle
  10. ;   4 = quadagon (?)
  11. ;
  12. ; Whereas the PFACE performs the same function but can be a mesh up to:
  13. ; 1 to 100 vertexes     (see maxpolyline below)
  14. ; 1 to 2000 connections (see maxconns below)
  15. ; 1 to 3000 surfaces    (see maxsurfs below)
  16. ;
  17. ;Options:
  18. ;
  19. ;DXF23DV inputname outputname [-s# -x# -y# -z# -mfilename -u# -v# -w# -l -n -q]
  20. ;
  21. ; -x  x translation for object (before scale) - can be floating point, +z = up
  22. ; -y  y translation for object (before scale) - can be floating point, +z = up
  23. ; -z  z translation for object (before scale) - can be floating point, +z = up
  24. ; -s  scale factor                            - can be floating point
  25. ; -u  x translation for object (after scale)  - integer only, +y = down
  26. ; -v  y translation for object (after scale)  - integer only, +y = down
  27. ; -w  z translation for object (after scale)  - integer only, +y = down
  28. ; -m  materials list filename (corresponds to layer names)
  29. ; -l  selective layer processing (only process layers that are found
  30. ;     in materials file)
  31. ; -n  output true calculated surface normal (otherwise 0,0,0), useless option
  32. ; -q  negate Y output axis
  33. ;
  34. ; I you have trouble assigning a material to a line it  may  be  because  the
  35. ; layer that the line is on  has  the  shading  option.  Lines  do  not  have
  36. ; surface  normals  and  therefore   cannot  have  the  shading  option  set.
  37. ; If DXF23DV finds this occurance, it will insert   a  default  texture  that
  38. ; has no shading texture.  eg:  0,0,colour,0
  39. ;
  40. ; If your a total  knumbskull  (like  me)  and  you  get  ACAD's  co-ordinate
  41. ; system messed up (like me) you can use  the  -q  option  to  negate  the  Y
  42. ; axis and reverse the orientation of the polygons.
  43. ;
  44. ; Do not use punctuation in your material names or layer names.
  45. ; A # sign in the materials means a comment
  46. ;
  47. ; Using the PFACE allows ACAD to assign polygons with more  than  4  surfaces.
  48. ; This removes the need for polygon optimization  and  gives  greater  control
  49. ; over the implementation of surfaces.
  50. ;
  51. ; The ACAD layer name is matched up with a materials file to give each surface
  52. ; a seperate surface type/colour/whatever.  Surfaces can be  selected  through
  53. ; AutoCAD to be double sided, shaded, sine waved, or anything the  user  wants
  54. ; simply by nameing a new layer and assigning those  surfaces  to  that layer.
  55. ; The materials file can then be edited/added in order to obtain  the  results
  56. ; the user desires.
  57. ;
  58. ; Sample materials file follows:
  59. ;
  60. ; # This is a comment
  61. ; # There must be 5 fields in each assigned texture!!
  62. ;
  63. ; CONSTANT     0,0,0,colour0,0
  64. ; SHADED       0,shade,0,colour1,0
  65. ; SINE         0,wavey,0,colour2,0
  66. ; BOTHSIDES    both,0,0,colour3,0
  67. ; BOTHSHADE    both,shade,0,colour4,0
  68. ; DOUBLESIDED  double,0,0,colour5a,colour5b
  69. ; DOUBLESHADE  double,shade,shade,colour6a,colour6b
  70. ; 1SHADE2SINE  0,shade,wavey,colour7a,colour7b
  71. ; 1SINE2SHADE  0,wavey,shade,colour8a,colour8b
  72. ; 2SINE        double,wavey,wavey,colour9a,colour9b
  73. ; SAMPLESIDE   this is,an example,of what,you can,do!
  74. ;
  75. ; Make sure your 3DFACEs and PFACEs are entered in Counter-Clockwise order!
  76. ;
  77. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  78.  
  79. ; Link this with PMODE, FILE, and ARGC
  80.  
  81.           .386p
  82.           jumps
  83.  
  84. code32    segment para public use32
  85.           assume cs:code32, ds:code32, ss:code32
  86.  
  87.           include pmode.inc
  88.           include file.inc
  89.           include argc.inc
  90.  
  91.           public  _main
  92.  
  93. matbufsize  = 1500    ; materials list buffer size
  94. yes         = 1
  95. no          = 0
  96.  
  97. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  98. ; Macros
  99. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  100.  
  101. upper     macro regx  ; make register uppercase
  102.           local strl
  103.           cmp regx,"a"
  104.           jb short strl
  105.           cmp regx,"z"
  106.           ja short strl
  107.           sub regx,"a"-"A"
  108. strl:
  109.           endm
  110.  
  111. imul32    macro regx
  112.           imul regx
  113.           shld edx,eax,1
  114.           inc edx
  115.           shr edx,1
  116.           movsx eax,dx
  117.           endm
  118.  
  119. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  120. ; DATA
  121. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  122.  
  123. inputname       db 60 dup (?)
  124. outputname      db 60 dup (?)
  125.  
  126. buffer          db 60 dup (?)
  127.  
  128. nx              dd 0      ; translation of location
  129. ny              dd 0
  130. nz              dd 0
  131. scale           dd 0      ; overall scale done after move
  132. nu              dd 0      ; translation of location after scale
  133. nv              dd 0
  134. nw              dd 0
  135.  
  136. fileloc         dd 0      ; current location in DXF file (offset)
  137.  
  138. dxfo            dd 0      ; start dxf file location
  139. dxfsize         dd 0      ; dxf filesize
  140. mato            dd 0      ; materials file location
  141. matsize         dd 0      ; materials file size
  142. materials       dd 0      ; materials/layer names offset
  143. hugestack       dd 0      ; 4 gig stack location (_himembase)
  144.  
  145. maxpoints       = 3000    ; max number of unique points in any DXF
  146. maxconns        = 2000    ; maximum connections
  147. maxpolyline     = 100     ; maximum pface verticies
  148.  
  149. ox              = 0       ; offsets for points (from conmem)
  150. oy              = ox+maxpoints*4
  151. oz              = oy+maxpoints*4
  152. sd              = oz+maxconns*4 ; polygon number
  153. p1              = sd+maxconns*4 ; point 1
  154. p2              = p1+maxconns*4 ; point 2
  155. wg              = p2+maxconns*4 ; where going
  156. wc              = wg+maxconns*4 ; where came
  157. ea              = wc+maxconns*4 ; a,b,c,d of plane equation
  158. eb              = ea+maxconns*4
  159. ec              = eb+maxconns*4
  160. ed              = ec+maxconns*4
  161. mt              = ed+maxconns*4 ; texture/layer name
  162. sn              = mt+((maxconns+1)*4)/3 ; surface number (for sorting)
  163.  
  164. memoryneeded    = maxpoints*4+oy+oz+sd+p1+p2+wg+wc+ea+eb+ec+ed+mt+sn
  165.  
  166. connmem         dd 0      ; memory for points/connection data
  167. points          dd 0      ; number of points
  168. surfaces        dd 0      ; number of surfaces
  169. connections     dd 0      ; number of connections
  170. thismaterial    dd 0      ; current/working material
  171. iterate         db 0      ; flag to use iteration
  172. layer           db 0      ; flag for selective layer processing
  173. tnormal         db 0      ; flag for true surface normal output
  174. yneg            db 0      ; flag for y negation
  175. temp1           dd 0
  176. temp2           dd 0
  177. temp3           dd 0
  178.  
  179. polyindex       dd maxpolyline dup (0)
  180. start           dd 0
  181. startconn       dd 0
  182. pvertexs        dd 0
  183. pfaces          dd 0
  184.  
  185. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  186. ; CODE
  187. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  188.  
  189. include extras.rt
  190.  
  191. errmsg0         db 10,13,'Missing Filename!',0dh,0ah,"$"
  192. errmsg1         db 10,13,'Not Enough Memory!',0dh,0ah,"$"
  193. errmsg2         db 10,13,'Error Opening File!',0dh,0ah,"$"
  194. errmsg3         db 10,13,'Error Loading Materials File!',0dh,0ah,"$"
  195. errmsg4         db 10,13,'Error:Too Many Points in DXF!',0dh,0ah,"$"
  196. errmsg5         db 10,13,'Error:No 3DFACEs or PFACEs Found in DXF!',0dh,0ah,"$"
  197. errmsg6         db 10,13,'Dont Know How To Handle Parts Of This DXF!',0dh,0ah,"$"
  198. okmsg           db 10,13,"AutoCAD .DXF to 3DVECTORS converter by John McCarthy V0.1"
  199.                 db 10,13,"DXF23DV inputname outputname [-s# -x# -y# -z# -mfilename -u# -v# -w# -l -n -q]",10,13
  200.                 db 10,13," -x  x translation for object (before scale) - can be floating point, +z = up"
  201.                 db 10,13," -y  y translation for object (before scale) - can be floating point, +z = up"
  202.                 db 10,13," -z  z translation for object (before scale) - can be floating point, +z = up"
  203.                 db 10,13," -s  scale factor                            - can be floating point"
  204.                 db 10,13," -u  x translation for object (after scale)  - integer only, +y = down"
  205.                 db 10,13," -v  y translation for object (after scale)  - integer only, +y = down"
  206.                 db 10,13," -w  z translation for object (after scale)  - integer only, +y = down"
  207.                 db 10,13," -m  materials list filename (corresponds to layer names)"
  208.                 db 10,13," -l  selective layer processing (only process layers that are found"
  209.                 db 10,13,"     in materials file)"
  210.                 db 10,13," -n  output true calculated surface normal (otherwise 0,0,0), useless option"
  211.                 db 10,13," -q  negate Y output axis",10,13
  212.                 db 10,13,"Use 3DFACE and PFACE to define your ACAD object."
  213.                 db 10,13,"Enter your 3DFACEs and PFACEs in Counter-Clockwise order."
  214.                 db 10,13,"BRIAN.MCCARTHY@CANREM.COM",10,13,"$"
  215. exiterr0:
  216.         mov edx,offset errmsg0
  217.         call _putdosmsg
  218.         jmp okerr0
  219. exiterr1:
  220.         mov edx,offset errmsg1
  221.         call _putdosmsg
  222.         jmp okerr0
  223. exiterr2:
  224.         mov edx,offset errmsg2
  225.         call _putdosmsg
  226.         jmp okerr0
  227. exiterr3:
  228.         mov edx,offset errmsg3
  229.         call _putdosmsg
  230.         jmp okerr0
  231. exiterr4:
  232.         mov edx,offset errmsg4
  233.         call _putdosmsg
  234.         jmp okerr0
  235. exiterr5:
  236.         mov edx,offset errmsg5
  237.         call _putdosmsg
  238.         jmp okerr0
  239. exiterr6:
  240.         mov edx,offset errmsg6
  241.         call _putdosmsg
  242.         jmp okerr0
  243. okerr0:
  244.         mov edx,offset okmsg
  245.         call _putdosmsg
  246.         jmp _exit
  247.  
  248. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  249. ; Allocate memory
  250. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  251. _main:
  252.         call _setbuf
  253.  
  254.         mov eax,matbufsize  ; allocate memory for materials
  255.         call _getmem
  256.         jc exiterr1
  257.         mov materials,eax
  258.         mov edi,eax
  259.         mov ecx,matbufsize/4 ; wipe materials buffer
  260.         xor eax,eax
  261.         rep stosd
  262.  
  263.         mov eax,memoryneeded
  264.         call _getmem
  265.         jc exiterr1
  266.         mov connmem,eax
  267.         mov edi,eax
  268.         mov ecx,memoryneeded
  269.         xor eax,eax
  270.         rep stosb
  271.  
  272.         mov points,eax
  273.         mov surfaces,eax
  274.         mov connections,eax
  275.  
  276.         mov esi,_himembase  ; 4gig stack!
  277.         mov hugestack,esi
  278.  
  279. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  280. ; Parse and open DXF, allocate memory, load DXF, close file
  281. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  282.  
  283.         xor al,al
  284.         mov edx,offset inputname
  285.         call _cchekstr
  286.         jc exiterr0
  287.         mov edx,offset inputname
  288.         call _openfile
  289.         jc exiterr2
  290.         call _filesize
  291.         mov dxfsize,eax
  292.         call _getlomem
  293.         jc exiterr1
  294.         mov dxfo,eax
  295.         mov edx,eax
  296.         mov ecx,dxfsize
  297.         call _readfile
  298.         jc exiterr2
  299.         call _closefile
  300.         mov edx,dxfo
  301.         mov ecx,dxfsize
  302.         call replace
  303.  
  304. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  305. ; Parse and open materials file, allocate memory, load file, close file
  306. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  307.  
  308.         mov matsize,0
  309.         mov al,"m"                      ; check for filename on commandline
  310.         mov edx,offset buffer
  311.         call _ccheksstr
  312.         jc nomaters
  313.         mov edx,offset buffer
  314.         call _openfile
  315.         jc exiterr3
  316.         call _filesize
  317.         mov matsize,eax
  318.         call _getmem
  319.         jc exiterr1
  320.         mov mato,eax
  321.         mov edx,eax
  322.         mov ecx,matsize
  323.         call _readfile
  324.         jc exiterr3
  325.         call _closefile
  326.         mov edx,mato
  327.         mov ecx,matsize
  328.         call replace
  329. nomaters:
  330.  
  331. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  332. ; Parse and open output filename
  333. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  334.  
  335.         mov al,1                        ; check for filename on commandline
  336.         mov edx,offset outputname
  337.         call _cchekstr
  338.         jc exiterr0
  339.         mov edx,offset outputname
  340.         call _createfile
  341.         jc exiterr0
  342.  
  343. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  344. ; Get scaling factor for points
  345. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  346.  
  347.         mov scale,1*65536
  348.         mov al,"s"
  349.         mov edx,offset buffer
  350.         call _ccheksstr
  351.         jc noscale
  352.         mov edx,offset buffer
  353.         mov eax,dword ptr buffer
  354.         call _get_float32
  355.         mov scale,eax
  356. noscale:
  357.  
  358. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  359. ; Get position offset for points
  360. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  361.  
  362.         mov nx,0
  363.         mov al,"x"
  364.         mov edx,offset buffer
  365.         call _ccheksstr
  366.         jc nox
  367.         mov edx,offset buffer
  368.         call _get_float32
  369.         mov nx,eax
  370. nox:
  371.         mov ny,0
  372.         mov al,"y"
  373.         mov edx,offset buffer
  374.         call _ccheksstr
  375.         jc noy
  376.         mov edx,offset buffer
  377.         call _get_float32
  378.         mov ny,eax
  379. noy:
  380.         mov nz,0
  381.         mov al,"z"
  382.         mov edx,offset buffer
  383.         call _ccheksstr
  384.         jc noz
  385.         mov edx,offset buffer
  386.         call _get_float32
  387.         mov nz,eax
  388. noz:
  389.         mov nu,0
  390.         mov al,"u"
  391.         mov edx,offset buffer
  392.         call _ccheksstr
  393.         jc nou
  394.         mov edx,offset buffer
  395.         call _strhtn
  396.         call _vct32
  397.         mov nu,eax
  398. nou:
  399.         mov nv,0
  400.         mov al,"v"
  401.         mov edx,offset buffer
  402.         call _ccheksstr
  403.         jc nov
  404.         mov edx,offset buffer
  405.         call _strhtn
  406.         call _vct32
  407.         mov nv,eax
  408. nov:
  409.         mov nw,0
  410.         mov al,"w"
  411.         mov edx,offset buffer
  412.         call _ccheksstr
  413.         jc now
  414.         mov edx,offset buffer
  415.         call _strhtn
  416.         call _vct32
  417.         mov nw,eax
  418. now:
  419.  
  420. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  421. ; Hunt for -i iteration option
  422. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  423.  
  424.         mov iterate,no
  425.         mov al,"i"
  426.         call _cchekswitchnc
  427.         jc yesiterate
  428.         mov iterate,yes
  429. yesiterate:
  430.  
  431. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  432. ; Hunt for -l selective layer option
  433. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  434.  
  435.         mov layer,no
  436.         mov al,"l"
  437.         call _cchekswitchnc
  438.         jc yeslayer
  439.         mov layer,yes
  440. yeslayer:
  441.  
  442. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  443. ; Hunt for -q y negation option
  444. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  445.  
  446.         mov yneg,no
  447.         mov al,"q"
  448.         call _cchekswitchnc
  449.         jc yesneg
  450.         mov yneg,yes
  451. yesneg:
  452.  
  453. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  454. ; Hunt for -n normal output
  455. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  456.  
  457.         mov tnormal,no
  458.         mov al,"n"
  459.         call _cchekswitchnc
  460.         jc yesnormal
  461.         mov tnormal,yes
  462. yesnormal:
  463.  
  464. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  465. ; Split DXF into single connection data, calc normals, assign materials
  466. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  467.  
  468.         mov eax,dxfo
  469.         mov fileloc,eax
  470.         call dxf_3dfaces
  471.         mov eax,dxfo
  472.         mov fileloc,eax
  473.         call dxf_polylines
  474.  
  475.         cmp surfaces,0
  476.         jz exiterr5
  477.  
  478.        ;call optimize
  479.         call renumber_surfaces
  480.         call collect_points
  481.        ;call number_them
  482.        ;call wipe_d
  483.        ;call sort_them
  484.         call output_file
  485.  
  486.         call _closefile
  487.         jmp _exit
  488.  
  489. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  490. ; Search for and (if neccessary) build materials list
  491. ;  In:
  492. ;   EDX => materials string (layer name) eg db "OBJECT1 "
  493. ;  Out:
  494. ;   EAX = assigned material number
  495. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  496.  
  497. assign_material:
  498.         mov esi,materials
  499.         mov edi,edx
  500.         xor ebp,ebp
  501. amloopb:
  502.         cmp byte ptr [esi],0 ; test if at end of list => add on to list
  503.         je amaddit
  504. amloop:
  505.         mov al,[esi]         ; check if material is already in list
  506.         mov bl,[edi]
  507.         inc esi
  508.         inc edi
  509.         mov cl,al
  510.         or cl,bl
  511.         jz amout
  512.  
  513.         cmp al,bl
  514.         je amloop
  515. amout:
  516.         dec esi
  517.         cmp al,0
  518.         jne amabort
  519.  
  520.         cmp bl,"0"
  521.         jae amabortx
  522.  
  523.         mov eax,ebp          ; material already present, return number
  524.         ret
  525. amaddit:
  526.         mov al,[edx]         ; material not found at all, add to list
  527.         mov [esi],al
  528.         inc edx
  529.         inc esi
  530.         cmp al,"0"
  531.         jae amaddit
  532.  
  533.         xor al,al
  534.         mov [esi-1],al
  535.         mov eax,ebp
  536.  
  537.         ret
  538. amabort:
  539.         inc esi              ; material not found, continue checking
  540.         cmp byte ptr [esi],0
  541.         jne amabort
  542.  
  543. amabortx:
  544.         inc esi
  545.         inc ebp
  546.         mov edi,edx
  547.         jmp amloopb
  548.  
  549. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  550. ; Find material number ECX
  551. ; In:  ECX = material number to find
  552. ; Out: EDX => location of material name (name only, use this to find material in file)
  553. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  554. find_ecx:
  555.         mov edx,materials
  556.         cmp ecx,0
  557.         je _ret
  558. mcxb:
  559.         inc edx
  560.         cmp byte ptr [edx],0
  561.         jne mcxb
  562.         loop mcxb
  563.  
  564.         inc edx
  565.         ret
  566.  
  567. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  568. ; Unpad string
  569. ; In:  EDX => string eg " , Hello th"
  570. ; Out: EDX => string (after spaces, colons, whatever) eg "Hello th"
  571. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  572. unpad:
  573.         dec edx
  574. upx:
  575.         inc edx
  576.         mov al,[edx]
  577.         cmp al,"-"
  578.         je upretx
  579.         cmp al,"."
  580.         je upretx
  581.         cmp al,"#"
  582.         je upretx
  583.         cmp al,"A"
  584.         jae upretx
  585.         cmp al,"9"
  586.         ja upx
  587.         cmp al,"0"
  588.         jb upx
  589. upretx:
  590.         ret
  591.  
  592. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  593. ; Next string
  594. ; In:  EDX => string eg "Hello there mi"
  595. ; Out: EDX => next string (after spaces, colons, whatever) eg "there mi"
  596. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  597. next:
  598.         call unpad
  599.         dec edx
  600. nxc:
  601.         inc edx
  602.         mov al,[edx]
  603.         cmp al,"-"
  604.         je nxc
  605.         cmp al,"#"
  606.         je nxc
  607.         cmp al,"A"
  608.         jae nxc
  609.         cmp al,"9"
  610.         ja nxretc
  611.         cmp al,"0"
  612.         jae nxc
  613. nxretc:
  614.         jmp unpad
  615.  
  616. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  617. ; Search_string: Find string at EDX in DXF file
  618. ; In:
  619. ;   EDX => ASCIIZ string to search for (DXF)
  620. ;   EDI = location to start search
  621. ;   EBP = location to end search
  622. ; Out:
  623. ;  CF = 1 - not found
  624. ;  CF = 0 - found
  625. ;   EDI = location where found
  626. ; Notes: String at EDI must have a space or zero at end for search tp succeed.
  627. ;  eg:  EDX => "HELLO",0
  628. ;       EDI => "ABCDHELLOEFGI" will FAIL! - but " ABCDHELLO DKJ" will succeed!
  629. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  630.  
  631. search_string:
  632.         mov esi,edx
  633.         mov ecx,edi
  634. ssloop:
  635.         mov al,[esi]
  636.         mov ah,[ecx]
  637.         upper al
  638.         upper ah
  639.         inc esi
  640.         inc ecx
  641.         mov bl,al
  642.         or bl,ah
  643.         jz ssout
  644.  
  645.         cmp al,ah
  646.         je ssloop
  647.  
  648.         cmp al,0
  649.         jne ssabort
  650.  
  651.         cmp ah,"0"
  652.         jae ssabort
  653. ssout:
  654.         clc
  655.         ret
  656. ssabort:
  657.         cmp ecx,ebp
  658.         jae ssretx
  659.  
  660.         inc edi
  661.         jmp search_string
  662. ssretx:
  663.         stc
  664.         ret
  665.  
  666. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  667. ; Search materials file for information on material ECX
  668. ; In:  ECX = material number to look for
  669. ; Out: EDX => string containing surface information (terminated with db 0,0)
  670. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  671.  
  672. find_info:
  673.         cmp matsize,0
  674.         je fidodefault
  675.  
  676.         call find_ecx
  677.         mov esi,edx
  678.         mov edx,mato
  679. filoop:
  680.         call unpad
  681.         xor ebx,ebx
  682. ficx:
  683.         mov al,[esi+ebx]
  684.         mov ah,[edx]
  685.         upper al
  686.         upper ah
  687.         inc ebx
  688.         inc edx
  689.         cmp al,ah
  690.         je ficx
  691.  
  692.         cmp al,0
  693.         je fifoundm
  694.  
  695.         dec edx
  696. fifinddol:
  697.         inc edx
  698.         cmp byte ptr [edx],0
  699.         jne fifinddol
  700.  
  701.         mov eax,mato
  702.         add eax,matsize
  703.         cmp edx,eax
  704.         jb filoop
  705. fidodefault:
  706.         mov edx,offset fidefault
  707.         ret
  708.  
  709. fifoundm:
  710.         dec edx
  711.         mov al,[edx]
  712.         cmp al,"A"
  713.         ja fifinddol
  714.         cmp al,"9"
  715.         ja unpad
  716.         cmp al,"0"
  717.         jae fifinddol
  718.         jmp unpad
  719.  
  720. fidefault db "0,shade,0,colour,0",0   ; for regular faces
  721. fidefaull db "0,0,0,colour,0",0       ; for lines
  722.  
  723. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  724. ; Search line for "shade"
  725. ; In: EDX => string containing surface information (terminated with db 0,0)
  726. ; Out: CF = 0 shade found, CF = 1 shade not found    EDX = ?
  727. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  728. find_shade:
  729.         mov al,[edx]
  730.         cmp al,0
  731.         je fsnoshade
  732.         inc edx
  733.  
  734.         upper al
  735.         cmp al,"S"
  736.         jne find_shade
  737.         mov al,[edx+0]
  738.         upper al
  739.         cmp al,"H"
  740.         jne find_shade
  741.         mov al,[edx+1]
  742.         upper al
  743.         cmp al,"A"
  744.         jne find_shade
  745.         mov al,[edx+2]
  746.         upper al
  747.         cmp al,"D"
  748.         jne find_shade
  749.         mov al,[edx+3]
  750.         upper al
  751.         cmp al,"E"
  752.         jne find_shade
  753.  
  754.         clc
  755.         ret
  756. fsnoshade:
  757.         stc
  758.         ret
  759.  
  760. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  761. ; Replace 13,10 with 0,0
  762. ; In: EDX => start location
  763. ;     ECX = length
  764. ; Out: ?
  765. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  766. replace:
  767.         inc ecx
  768.         push ecx
  769.         mov al,10
  770.         mov edi,edx
  771. re10:
  772.         repnz scasb
  773.         cmp ecx,0
  774.         je re13
  775.         mov byte ptr [edi-1],0
  776.         jmp re10
  777. re13:
  778.         mov al,13
  779.         mov edi,edx
  780.         pop ecx
  781. re13s:
  782.         repnz scasb
  783.         cmp ecx,0
  784.         je _ret
  785.         mov byte ptr [edi-1],0
  786.         jmp re13s
  787.  
  788. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  789. ; Auto calculate normal
  790. ; In:
  791. ;  EBX = point 1
  792. ;  ECX = point 2
  793. ;  EBP = point 3
  794. ; Out:
  795. ;    EBX = finx = x of surface normal of triangle
  796. ;    ECX = finy = y of surface normal of triangle
  797. ;    EBP = finz = z of surface normal of triangle
  798. ;    EAX = D of equation (Ax+By+Cz=D)
  799. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  800. acalc_normal:
  801.         mov esi,connmem
  802.  
  803.         mov eax,[esi+ebx*4+ox]
  804.         mov edx,[esi+ebx*4+oy]
  805.         mov edi,[esi+ebx*4+oz]
  806.         mov lx1,eax
  807.         mov ly1,edx
  808.         mov lz1,edi
  809.  
  810.         mov eax,[esi+ecx*4+ox]
  811.         mov edx,[esi+ecx*4+oy]
  812.         mov edi,[esi+ecx*4+oz]
  813.         mov lx2,eax
  814.         mov ly2,edx
  815.         mov lz2,edi
  816.  
  817.         mov eax,[esi+ebp*4+ox]
  818.         mov edx,[esi+ebp*4+oy]
  819.         mov edi,[esi+ebp*4+oz]
  820.         mov lx3,eax
  821.         mov ly3,edx
  822.         mov lz3,edi
  823.  
  824.         call calc_normal
  825.         call calc_d
  826.         ret
  827.  
  828. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  829. ;
  830. ; Calc_normal: calculate surface normal
  831. ;
  832. ; In:
  833. ;    LX1 - x of point 1 on triangle
  834. ;    LY1 - y of point 1 on triangle
  835. ;    LZ1 - z of point 1 on triangle
  836. ;    LX2 - x of point 2 on triangle
  837. ;    LY2 - y of point 2 on triangle
  838. ;    LZ2 - z of point 2 on triangle
  839. ;    LX3 - x of point 3 on triangle
  840. ;    LY3 - y of point 3 on triangle
  841. ;    LZ3 - z of point 3 on triangle
  842. ;
  843. ; Out:
  844. ;    EBX = finx = x of surface normal of triangle
  845. ;    ECX = finy = y of surface normal of triangle
  846. ;    EBP = finz = z of surface normal of triangle
  847. ;
  848. ; Notes:
  849. ; x2 = x2 - x1
  850. ; y2 = y2 - y1
  851. ; z2 = z2 - z1
  852. ;
  853. ; x3 = x3 - x1
  854. ; y3 = y3 - y1
  855. ; z3 = z3 - z1
  856. ;
  857. ; x = y2 * z3 - z2 * y3
  858. ; y = z2 * x3 - x2 * z3
  859. ; z = x2 * y3 - y2 * x3
  860. ;
  861. ; a = SQR(x ^ 2 + y ^ 2 + z ^ 2)
  862. ;
  863. ; x = INT(x / a * 256 + .5)
  864. ; y = INT(y / a * 256 + .5)
  865. ; z = INT(z / a * 256 + .5)
  866. ;
  867. ; This worked for me on the first try!
  868. ;
  869. ; If you wanted to get the equation of a plane, you could do this after:
  870. ;  d = - x * x1 - y * y1 - z * z1
  871. ;
  872. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  873.  
  874. lx1  dd 0
  875. ly1  dd 0
  876. lz1  dd 0
  877.  
  878. lx2  dd 0
  879. ly2  dd 0
  880. lz2  dd 0
  881.  
  882. lx3  dd 0
  883. ly3  dd 0
  884. lz3  dd 0
  885.  
  886. finx dd 0
  887. finy dd 0
  888. finz dd 0
  889.  
  890. calc_normal:
  891.          mov ebx,lx1
  892.          mov ecx,ly1
  893.          mov ebp,lz1
  894.  
  895.          sub lx2,ebx
  896.          sub ly2,ecx
  897.          sub lz2,ebp
  898.  
  899.          sub lx3,ebx
  900.          sub ly3,ecx
  901.          sub lz3,ebp
  902.  
  903.          mov eax,ly2
  904.          mov ebx,lz3
  905.          imul ebx
  906.          mov ecx,eax
  907.  
  908.          mov eax,lz2
  909.          mov ebx,ly3
  910.          imul ebx
  911.          sub ecx,eax
  912.  
  913.          mov finx,ecx ; save x of normal
  914.  
  915.          mov eax,lz2
  916.          mov ebx,lx3
  917.          imul ebx
  918.          mov ecx,eax
  919.  
  920.          mov eax,lx2
  921.          mov ebx,lz3
  922.          imul ebx
  923.          sub ecx,eax
  924.  
  925.          mov finy,ecx ; save y of normal
  926.  
  927.          mov eax,lx2
  928.          mov ebx,ly3
  929.          imul ebx
  930.          mov ecx,eax
  931.  
  932.          mov eax,ly2
  933.          mov ebx,lx3
  934.          imul ebx
  935.          sub ecx,eax
  936.  
  937.          mov finz,ecx ; save z of normal
  938.  
  939. calc_testloop:
  940.          cmp finx,32768 ; make sure (normal^2)*2 is < 2^32
  941.          jge calc_shrit
  942.          cmp finy,32768
  943.          jge calc_shrit
  944.          cmp finz,32768
  945.          jge calc_shrit
  946.  
  947.          cmp finx,-32768
  948.          jle calc_shrit
  949.          cmp finy,-32768
  950.          jle calc_shrit
  951.          cmp finz,-32768
  952.          jg  ok_2_bite_dust
  953.  
  954. calc_shrit:
  955.          shr finx,1   ; calculations will be too large if squared, div by 2
  956.          test finx,40000000h
  957.          jz no_neg_calc1
  958.          or   finx,80000000h
  959. no_neg_calc1:
  960.          shr finy,1
  961.          test finy,40000000h
  962.          jz no_neg_calc2
  963.          or   finy,80000000h
  964. no_neg_calc2:
  965.          shr finz,1
  966.          test finz,40000000h
  967.          jz no_neg_calc3
  968.          or   finz,80000000h
  969. no_neg_calc3:
  970.          jmp calc_testloop
  971.  
  972. ok_2_bite_dust:
  973.          mov eax,finx ; x^2
  974.          mov edi,eax  ; objects
  975.          imul edi
  976.          mov edi,eax
  977.  
  978.          mov eax,finy ; y^2
  979.          mov esi,eax
  980.          imul esi
  981.          mov esi,eax
  982.  
  983.          mov eax,finz ; z^2
  984.          mov ebp,eax
  985.          imul ebp
  986.  
  987.          add eax,esi
  988.          add eax,edi
  989.  
  990.          call sqrt    ; get square root of number
  991.  
  992.          mov ecx,eax
  993.          cmp ecx,0
  994.          je lam_abort ; should never happen!
  995.  
  996.          mov eax,finx
  997.          cdq
  998.          shld edx,eax,10
  999.          shl eax,10   ; set unit vector to 2^12
  1000.          idiv ecx
  1001.          mov finx,eax
  1002.  
  1003.          mov eax,finy
  1004.          cdq
  1005.          shld edx,eax,10
  1006.          shl eax,10
  1007.          idiv ecx
  1008.          mov finy,eax
  1009.  
  1010.          mov eax,finz
  1011.          cdq
  1012.          shld edx,eax,10
  1013.          shl eax,10
  1014.          idiv ecx
  1015.          mov finz,eax
  1016.  
  1017.          mov ebx,finx
  1018.          mov ecx,finy
  1019.          mov ebp,finz
  1020.  
  1021. lam_abort:
  1022.          ret
  1023.  
  1024. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1025. ; Calc_D: Calculate D portion of equation of a plane
  1026. ; In:
  1027. ;    EBX = x of surface normal of triangle
  1028. ;    ECX = y of surface normal of triangle
  1029. ;    EBP = z of surface normal of triangle
  1030. ;    LX1 - x of point on triangle (any point)
  1031. ;    LY1 - y of point on triangle
  1032. ;    LZ1 - z of point on triangle
  1033. ; Out:
  1034. ;    EAX = D of equation (Ax+By+Cz=D)
  1035. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1036. calc_d:
  1037.          mov eax,lx1
  1038.          imul ebx
  1039.          mov esi,eax
  1040.  
  1041.          mov eax,ly1
  1042.          imul ecx
  1043.          add esi,eax
  1044.  
  1045.          mov eax,lz1
  1046.          imul ebp
  1047.          add eax,esi
  1048.  
  1049.          shr eax,10         ; reduce result to avoid inaccuracy
  1050.          test eax,00200000h
  1051.          jz calc_o
  1052.          or  eax,0ffc00000h
  1053. calc_o:
  1054.          ret
  1055.  
  1056. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1057. ;
  1058. ; Sqrt: Routine courtesy TRAN
  1059. ;
  1060. ; In:
  1061. ;   EAX - number to take root of
  1062. ; Out:
  1063. ;   EAX - root
  1064. ;
  1065. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1066. sqrtbasetbl db 0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,225
  1067. sqrt:
  1068.          pushad
  1069.          mov ebp,eax
  1070.          bsr ebx,eax
  1071.          jnz short sqrtf0
  1072.          xor ebx,ebx
  1073. sqrtf0:
  1074.          shr ebx,3
  1075.          lea eax,[ebx*8]
  1076.          mov cl,32
  1077.          sub cl,al
  1078.          rol ebp,cl
  1079.          mov eax,ebp
  1080.          movzx eax,al
  1081.          mov edi,offset sqrtbasetbl
  1082.          mov ecx,10h
  1083. sqrtl0:
  1084.          scasb
  1085.          je short sqrtl0d
  1086.          jb short sqrtl0d2
  1087.          loop sqrtl0
  1088.          inc edi
  1089. sqrtl0d2:
  1090.          dec edi
  1091.          inc cl
  1092. sqrtl0d:
  1093.          movzx edx,byte ptr [edi-1]
  1094.          dec cl
  1095.          xor cl,0fh
  1096.          mov edi,ecx
  1097.          mov ecx,ebx
  1098.          jecxz short sqrtdone
  1099.          sub eax,edx
  1100. sqrtml:
  1101.          shld eax,ebp,8
  1102.          rol ebp,8
  1103.          mov ebx,edi
  1104.          shl ebx,5
  1105.          xor edx,edx
  1106.          mov esi,eax
  1107.          div ebx
  1108.          rol edi,4
  1109.          add edi,eax
  1110.          add ebx,eax
  1111. sqrtf2:
  1112.          imul eax,ebx
  1113.          mov edx,eax
  1114.          mov eax,esi
  1115.          sub eax,edx
  1116.          jc short sqrtf1
  1117.          loop sqrtml
  1118. sqrtdone:
  1119.          mov [esp+28],edi
  1120.          popad
  1121.          ret
  1122. sqrtf1:
  1123.          dec ebx
  1124.          dec edi
  1125.          movzx eax,bl
  1126.          and al,1fh
  1127.          jmp sqrtf2
  1128.  
  1129. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1130. ; Search and Build points table
  1131. ; In:
  1132. ;    EBX - x of point
  1133. ;    ECX - y of point
  1134. ;    EBP - z of point
  1135. ; Out:
  1136. ;    EAX - assigned point number
  1137. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1138. check_point:
  1139.         mov eax,ebx
  1140.         or eax,ecx
  1141.         or eax,ebp
  1142.         jnz cpnotnull
  1143.         ret
  1144. cpnotnull:
  1145.         mov esi,connmem
  1146.         mov eax,1
  1147. cploop:
  1148.         cmp dword ptr [esi+eax*4+ox],0
  1149.         jne ckdotest
  1150.         cmp dword ptr [esi+eax*4+oy],0
  1151.         jne ckdotest
  1152.         cmp dword ptr [esi+eax*4+oz],0
  1153.         jne ckdotest
  1154.  
  1155.         mov [esi+eax*4+ox],ebx
  1156.         mov [esi+eax*4+oy],ecx
  1157.         mov [esi+eax*4+oz],ebp
  1158.  
  1159.         inc points
  1160.         cmp eax,maxpoints
  1161.         jae exiterr4
  1162.  
  1163.         ret
  1164. ckdotest:
  1165.         cmp [esi+eax*4+ox],ebx
  1166.         jne cknotest
  1167.         cmp [esi+eax*4+oy],ecx
  1168.         jne cknotest
  1169.         cmp [esi+eax*4+oz],ebp
  1170.         jne cknotest
  1171.         ret
  1172. cknotest:
  1173.         inc eax
  1174.         cmp eax,maxpoints
  1175.         jae exiterr4
  1176.  
  1177.         jmp cploop
  1178.  
  1179. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1180. ; Get next number (float) after string EDX
  1181. ; In: EDX => string to search for
  1182. ; Out:EAX = 32bit float number (fake float, you know what I mean)
  1183. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1184. getnumber:
  1185.         mov edi,fileloc
  1186.         mov ebp,dxfo
  1187.         add ebp,dxfsize
  1188.         call search_string
  1189.         jc gn_nf
  1190.         mov edx,edi
  1191.         call next
  1192.         mov fileloc,edx
  1193.         call _get_float32
  1194.         push eax
  1195.         mov edx,fileloc
  1196.         call next
  1197.         mov fileloc,edx
  1198.         pop eax
  1199.         clc
  1200. gn_nf:
  1201.         ret
  1202.  
  1203. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1204. ; Add DXF into connections, points, calculate normals and load materials.
  1205. ;
  1206. ; This adds a DXF file to the already loaded connections (usually empty), but
  1207. ; you could mix more than one DXF file if you really wanted to.
  1208. ;
  1209. ; Psuedo code:
  1210. ;
  1211. ;Variables p= x(p) y(p) z(p)
  1212. ;          c= sd(c) p1(c) p2(c) wg(c) wc(c) a(c) b(c) c(c) d(c) mt(c)
  1213. ; c = connections
  1214. ; p = points
  1215. ; sd = surface number
  1216. ; p1 = point 1 (start of line)
  1217. ; p2 = point 2 (end of line)
  1218. ; wg = where are we going
  1219. ; wc = where did we come from
  1220. ; a,b,c,d = equation of plane
  1221. ; mt = material texture for surface (layer name)
  1222. ;
  1223. ;search "3DFACE" not found => exit
  1224. ; search "8"
  1225. ; call next
  1226. ; assign material
  1227. ;
  1228. ;search "10" => x(p)
  1229. ;search "20" => y(p)
  1230. ;search "30" => z(p)
  1231. ;search "11" => x(p+1)
  1232. ;search "21" => y(p+1)
  1233. ;search "31" => z(p+1)
  1234. ;search "12" => x(p+2)
  1235. ;search "22" => y(p+2)
  1236. ;search "32" => z(p+2)
  1237. ;search "13" => x(p+3)
  1238. ;search "23" => y(p+3)
  1239. ;search "33" => z(p+3)
  1240. ;
  1241. ;    m(c+0)  = material
  1242. ;    p1(c+0) =(p+0)
  1243. ;    p2(c+0) =(p+1)
  1244. ;    wg(c+0) =(c+1)
  1245. ;    wc(c+0) =(c+3)
  1246. ;    m(c+1)  = material
  1247. ;    p1(c+1) =(p+0)
  1248. ;    p2(c+1) =(p+1)
  1249. ;    wg(c+1) =(c+2)
  1250. ;    wc(c+1) =(c+0)
  1251. ;    m(c+2)  = material
  1252. ;    p1(c+2) =(p+0)
  1253. ;    p2(c+2) =(p+1)
  1254. ;    wg(c+2) =(c+3)
  1255. ;    wc(c+2) =(c+1)
  1256. ;    m(c+3)  = material
  1257. ;    p1(c+3) =(p+0)
  1258. ;    p2(c+3) =(p+1)
  1259. ;    wg(c+3) =(c+0)
  1260. ;    wc(c+3) =(c+2)
  1261. ;
  1262. ;  calc normal
  1263. ;  calc D
  1264. ;  d(c+0)=D
  1265. ;  d(c+1)=D
  1266. ;  d(c+2)=D
  1267. ;  d(c+3)=D
  1268. ;
  1269. ;  if 10=40
  1270. ;  if 11=41
  1271. ;  if 12=42
  1272. ;     wg(c+2)=c+0
  1273. ;     wc(c+0)=c+2
  1274. ;     c=c-1
  1275. ;     p=p-1
  1276. ;  p=p+4
  1277. ;  c=c+4
  1278. ; goto search face
  1279. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1280.  
  1281. tag1     db "3DFACE",0
  1282. tag2     db "8",0
  1283. tagx     db "10",0,0
  1284.          db "11",0,0
  1285.          db "12",0,0
  1286.          db "13",0,0
  1287. tagy     db "20",0,0
  1288.          db "21",0,0
  1289.          db "22",0,0
  1290.          db "23",0,0
  1291. tagz     db "30",0,0
  1292.          db "31",0,0
  1293.          db "32",0,0
  1294.          db "33",0,0
  1295.  
  1296. dxf_3dfaces:
  1297.          mov edx,offset tag1
  1298.          mov edi,fileloc
  1299.          mov ebp,dxfo
  1300.          add ebp,dxfsize
  1301.          call search_string
  1302.          jc _ret
  1303.  
  1304.          mov edx,offset tag2
  1305.          mov ebp,dxfsize
  1306.          add ebp,dxfo
  1307.          call search_string
  1308.          jc dxf_3dfaces       ; no layer to surface?
  1309.  
  1310.          mov edx,edi
  1311.          call next
  1312.          mov fileloc,edx
  1313.          call assign_material
  1314.          mov thismaterial,eax
  1315.  
  1316.          cmp layer,no
  1317.          je dxf_nosel
  1318.          mov ecx,eax
  1319.          call find_info
  1320.          cmp edx,offset fidefault
  1321.          je dxf_3dfaces
  1322.  
  1323. dxf_nosel:
  1324.          mov temp1,0
  1325. dxf_lp1:
  1326.          mov ecx,temp1
  1327.          lea edx,[tagx+ecx*4]
  1328.          call getnumber
  1329.          add eax,nx
  1330.          mov ebx,scale
  1331.          imul32 ebx
  1332.          add eax,nu
  1333.          push eax
  1334.  
  1335.          mov ecx,temp1
  1336.          lea edx,[tagy+ecx*4]
  1337.          call getnumber
  1338.          add eax,ny
  1339.          mov ebx,scale
  1340.          imul32 ebx
  1341.          add eax,nw
  1342.          push eax
  1343.  
  1344.          mov ecx,temp1
  1345.          lea edx,[tagz+ecx*4]
  1346.          call getnumber
  1347.          add eax,nz
  1348.          mov ebx,scale
  1349.          imul32 ebx
  1350.          add eax,nv
  1351.          cmp yneg,yes
  1352.          je noyneg
  1353.          neg eax
  1354. noyneg:
  1355.          mov ecx,eax
  1356.          pop ebp
  1357.          pop ebx
  1358.          call check_point
  1359.          push eax
  1360.  
  1361.          inc temp1
  1362.          cmp temp1,4
  1363.          jne dxf_lp1
  1364.  
  1365.          pop edx ; 3
  1366.          pop ecx ; 2
  1367.          pop ebx ; 1
  1368.          pop eax ; 0
  1369.  
  1370.          mov ebp,connections
  1371.          mov esi,connmem
  1372.          mov edi,surfaces
  1373.  
  1374.          cmp eax,ecx    ; check for point: 1,1,1,1
  1375.          je dxf_point
  1376.  
  1377.          cmp eax,ecx    ; check for line: 1,2,1,2  or 1,2,1,1
  1378.          je dxf_line
  1379.  
  1380.          cmp eax,edx    ; check for triangle:  0 1 2 0 or 0 1 2 2
  1381.          je dxf_tri
  1382.          cmp ecx,edx
  1383.          jne dxf_4point ; must be a 4 point surface...
  1384. dxf_tri:
  1385.          mov [esi+(ebp+0)*4+p1],eax  ; p1(ebp)=eax
  1386.          mov [esi+(ebp+0)*4+p2],ebx  ; p2(ebp)=ebx
  1387.          mov [esi+(ebp+1)*4+p1],ebx  ; p1(ebp+1)=ebx
  1388.          mov [esi+(ebp+1)*4+p2],ecx  ; p2(ebp+1)=ecx
  1389.          mov [esi+(ebp+2)*4+p1],ecx  ; p1(ebp+2)=ecx
  1390.          mov [esi+(ebp+2)*4+p2],eax  ; p2(ebp+2)=eax
  1391.  
  1392.          mov [esi+(ebp+0)*4+wc],ebp  ; wc(ebp)=ebp+2
  1393.          mov [esi+(ebp+1)*4+wc],ebp  ; wc(ebp+1)=ebp+0
  1394.          mov [esi+(ebp+2)*4+wc],ebp  ; wc(ebp+2)=ebp+1
  1395.          add dword ptr [esi+(ebp+0)*4+wc],2
  1396.          add dword ptr [esi+(ebp+2)*4+wc],1
  1397.  
  1398.          mov [esi+(ebp+0)*4+wg],ebp  ; wg(ebp)=ebp+1
  1399.          mov [esi+(ebp+1)*4+wg],ebp  ; wg(ebp+1)=ebp+2
  1400.          mov [esi+(ebp+2)*4+wg],ebp  ; wg(ebp+2)=ebp+0
  1401.          add dword ptr [esi+(ebp+0)*4+wg],1
  1402.          add dword ptr [esi+(ebp+1)*4+wg],2
  1403.  
  1404.          mov [esi+(ebp+0)*4+sd],edi  ; sd(ebp)=surface number
  1405.          mov [esi+(ebp+1)*4+sd],edi
  1406.          mov [esi+(ebp+2)*4+sd],edi
  1407.  
  1408.          mov edi,thismaterial
  1409.          mov [esi+(ebp+0)*4+mt],edi  ; set material for surface
  1410.          mov [esi+(ebp+1)*4+mt],edi
  1411.          mov [esi+(ebp+2)*4+mt],edi
  1412.  
  1413.          mov ebp,ecx
  1414.          mov ecx,ebx
  1415.          mov ebx,eax
  1416.          call acalc_normal
  1417.  
  1418.          mov edi,connections
  1419.          mov esi,connmem
  1420.  
  1421.          mov [esi+(edi+0)*4+ea],ebx
  1422.          mov [esi+(edi+0)*4+eb],ecx
  1423.          mov [esi+(edi+0)*4+ec],ebp
  1424.          mov [esi+(edi+0)*4+ed],edx
  1425.          mov [esi+(edi+1)*4+ea],ebx
  1426.          mov [esi+(edi+1)*4+eb],ecx
  1427.          mov [esi+(edi+1)*4+ec],ebp
  1428.          mov [esi+(edi+1)*4+ed],edx
  1429.          mov [esi+(edi+2)*4+ea],ebx
  1430.          mov [esi+(edi+2)*4+eb],ecx
  1431.          mov [esi+(edi+2)*4+ec],ebp
  1432.          mov [esi+(edi+2)*4+ed],edx
  1433.  
  1434.          add surfaces,1
  1435.          add connections,3
  1436.  
  1437.          jmp dxf_3dfaces
  1438.  
  1439. dxf_4point:
  1440.          mov [esi+(ebp+0)*4+p1],eax  ; p1(ebp)=eax
  1441.          mov [esi+(ebp+0)*4+p2],ebx  ; p2(ebp)=ebx
  1442.          mov [esi+(ebp+1)*4+p1],ebx  ; p1(ebp+1)=ebx
  1443.          mov [esi+(ebp+1)*4+p2],ecx  ; p2(ebp+1)=ecx
  1444.          mov [esi+(ebp+2)*4+p1],ecx  ; p1(ebp+2)=ecx
  1445.          mov [esi+(ebp+2)*4+p2],edx  ; p2(ebp+2)=edx
  1446.          mov [esi+(ebp+3)*4+p1],edx  ; p1(ebp+3)=edx
  1447.          mov [esi+(ebp+3)*4+p2],eax  ; p2(ebp+3)=eax
  1448.  
  1449.          mov [esi+(ebp+0)*4+wc],ebp  ; wc(ebp)=ebp+3
  1450.          mov [esi+(ebp+1)*4+wc],ebp  ; wc(ebp+1)=ebp+0
  1451.          mov [esi+(ebp+2)*4+wc],ebp  ; wc(ebp+2)=ebp+1
  1452.          mov [esi+(ebp+3)*4+wc],ebp  ; wc(ebp+3)=ebp+2
  1453.          add dword ptr [esi+(ebp+0)*4+wc],3
  1454.          add dword ptr [esi+(ebp+2)*4+wc],1
  1455.          add dword ptr [esi+(ebp+3)*4+wc],2
  1456.  
  1457.          mov [esi+(ebp+0)*4+wg],ebp  ; wg(ebp)=ebp+1
  1458.          mov [esi+(ebp+1)*4+wg],ebp  ; wg(ebp+1)=ebp+2
  1459.          mov [esi+(ebp+2)*4+wg],ebp  ; wg(ebp+2)=ebp+3
  1460.          mov [esi+(ebp+3)*4+wg],ebp  ; wg(ebp+3)=ebp+0
  1461.          add dword ptr [esi+(ebp+0)*4+wg],1
  1462.          add dword ptr [esi+(ebp+1)*4+wg],2
  1463.          add dword ptr [esi+(ebp+2)*4+wg],3
  1464.  
  1465.          mov [esi+(ebp+0)*4+sd],edi  ; sd(ebp)=surface number
  1466.          mov [esi+(ebp+1)*4+sd],edi
  1467.          mov [esi+(ebp+2)*4+sd],edi
  1468.          mov [esi+(ebp+3)*4+sd],edi
  1469.  
  1470.          mov edi,thismaterial
  1471.          mov [esi+(ebp+0)*4+mt],edi  ; set material for surface
  1472.          mov [esi+(ebp+1)*4+mt],edi
  1473.          mov [esi+(ebp+2)*4+mt],edi
  1474.          mov [esi+(ebp+3)*4+mt],edi
  1475.  
  1476.          mov ebp,ecx
  1477.          mov ecx,ebx
  1478.          mov ebx,eax
  1479.          call acalc_normal
  1480.  
  1481.          mov edi,connections
  1482.          mov esi,connmem
  1483.  
  1484.          mov [esi+(edi+0)*4+ea],ebx
  1485.          mov [esi+(edi+0)*4+eb],ecx
  1486.          mov [esi+(edi+0)*4+ec],ebp
  1487.          mov [esi+(edi+0)*4+ed],edx
  1488.          mov [esi+(edi+1)*4+ea],ebx
  1489.          mov [esi+(edi+1)*4+eb],ecx
  1490.          mov [esi+(edi+1)*4+ec],ebp
  1491.          mov [esi+(edi+1)*4+ed],edx
  1492.          mov [esi+(edi+2)*4+ea],ebx
  1493.          mov [esi+(edi+2)*4+eb],ecx
  1494.          mov [esi+(edi+2)*4+ec],ebp
  1495.          mov [esi+(edi+2)*4+ed],edx
  1496.          mov [esi+(edi+3)*4+ea],ebx
  1497.          mov [esi+(edi+3)*4+eb],ecx
  1498.          mov [esi+(edi+3)*4+ec],ebp
  1499.          mov [esi+(edi+3)*4+ed],edx
  1500.  
  1501.          add surfaces,1
  1502.          add connections,4
  1503.          jmp dxf_3dfaces
  1504. dxf_line:
  1505.          mov [esi+(ebp+0)*4+p1],eax  ; p1(ebp)=eax
  1506.          mov [esi+(ebp+0)*4+p2],ebx  ; p2(ebp)=ebx
  1507.          mov [esi+(ebp+1)*4+p1],ebx  ; p1(ebp+1)=ebx
  1508.          mov [esi+(ebp+1)*4+p2],eax  ; p2(ebp+1)=ecx
  1509.  
  1510.          mov [esi+(ebp+0)*4+wc],ebp  ; wc(ebp)=ebp+1
  1511.          mov [esi+(ebp+1)*4+wc],ebp  ; wc(ebp+1)=ebp+0
  1512.          add dword ptr [esi+(ebp+0)*4+wc],1
  1513.  
  1514.          mov [esi+(ebp+0)*4+wg],ebp  ; wg(ebp)=ebp+1
  1515.          mov [esi+(ebp+1)*4+wg],ebp  ; wg(ebp+1)=ebp+0
  1516.          add dword ptr [esi+(ebp+0)*4+wg],1
  1517.  
  1518.          mov [esi+(ebp+0)*4+sd],edi  ; sd(ebp)=surface number
  1519.          mov [esi+(ebp+1)*4+sd],edi
  1520.  
  1521.          mov edi,thismaterial
  1522.          mov [esi+(ebp+0)*4+mt],edi  ; set material for surface
  1523.          mov [esi+(ebp+1)*4+mt],edi
  1524.  
  1525.          xor eax,eax
  1526.          mov edi,connections
  1527.          mov esi,connmem
  1528.  
  1529.          mov [esi+(edi+0)*4+ea],eax
  1530.          mov [esi+(edi+0)*4+eb],eax
  1531.          mov [esi+(edi+0)*4+ec],eax
  1532.          mov [esi+(edi+0)*4+ed],eax
  1533.          mov [esi+(edi+1)*4+ea],eax
  1534.          mov [esi+(edi+1)*4+eb],eax
  1535.          mov [esi+(edi+1)*4+ec],eax
  1536.          mov [esi+(edi+1)*4+ed],eax
  1537.  
  1538.          add surfaces,1
  1539.          add connections,2
  1540.  
  1541.          jmp dxf_3dfaces
  1542.  
  1543. dxf_point:
  1544.          mov [esi+(ebp+0)*4+p1],eax  ; p1(ebp)=eax
  1545.          mov [esi+(ebp+0)*4+p2],eax  ; p2(ebp)=ebx
  1546.  
  1547.          mov [esi+(ebp+0)*4+wc],ebp  ; wc(ebp)=ebp+0
  1548.          mov [esi+(ebp+0)*4+wc],ebp  ; wc(ebp+1)=ebp+0
  1549.  
  1550.          mov [esi+(ebp+0)*4+wg],ebp  ; wg(ebp)=ebp+0
  1551.          mov [esi+(ebp+1)*4+wg],ebp  ; wg(ebp+1)=ebp+0
  1552.  
  1553.          mov [esi+(ebp+0)*4+sd],edi  ; sd(ebp)=surface number
  1554.  
  1555.          mov edi,thismaterial
  1556.          mov [esi+(ebp+0)*4+mt],edi  ; set material for surface
  1557.  
  1558.          xor eax,eax
  1559.          mov edi,connections
  1560.          mov esi,connmem
  1561.  
  1562.          mov [esi+(edi+0)*4+ea],eax
  1563.          mov [esi+(edi+0)*4+eb],eax
  1564.          mov [esi+(edi+0)*4+ec],eax
  1565.          mov [esi+(edi+0)*4+ed],eax
  1566.  
  1567.          add surfaces,1
  1568.          add connections,1
  1569.  
  1570.          jmp dxf_3dfaces
  1571.  
  1572. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1573. ; Input Polyline PFACEs
  1574. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1575.  
  1576. tag3     db "POLYLINE",0
  1577. tag4     db "VERTEX",0
  1578. tag70    db "70",0
  1579. tag71    db "71",0
  1580. tag72    db "72",0
  1581. tag73    db "73",0
  1582. tag74    db "74",0
  1583.  
  1584. dxf_polylines:
  1585.          mov edx,offset tag3
  1586.          mov edi,fileloc
  1587.          mov ebp,dxfo
  1588.          add ebp,dxfsize
  1589.          call search_string
  1590.          jc _ret
  1591.  
  1592.          mov edx,offset tag2
  1593.          mov ebp,dxfsize
  1594.          add ebp,dxfo
  1595.          call search_string
  1596.          jc dxf_polylines     ; no layer to polyline?
  1597.  
  1598.          mov edx,edi
  1599.          call next
  1600.          mov fileloc,edx
  1601.          call assign_material
  1602.          mov thismaterial,eax
  1603.  
  1604.          cmp layer,no
  1605.          je dxf_pnosel
  1606.          mov ecx,eax
  1607.          call find_info
  1608.          cmp edx,offset fidefault
  1609.          je dxf_polylines
  1610.  
  1611. dxf_pnosel:
  1612.          mov edx,fileloc
  1613.          call next
  1614.          mov edi,edx
  1615.          mov edx,offset tag70
  1616.          mov ebp,dxfsize
  1617.          add ebp,dxfo
  1618.          call search_string
  1619.          jc exiterr6
  1620.  
  1621.          mov edx,edi
  1622.          call next
  1623.          call _strhtn
  1624.          call _vct16
  1625.          cmp eax,64
  1626.          jne dxf_polylines
  1627.  
  1628.          mov edx,fileloc
  1629.          call next
  1630.          mov edi,edx
  1631.          mov edx,offset tag71
  1632.          mov ebp,dxfsize
  1633.          add ebp,dxfo
  1634.          call search_string
  1635.          jc exiterr6
  1636.  
  1637.          mov edx,edi
  1638.          call next
  1639.          call _strhtn
  1640.          call _vct32
  1641.          mov pvertexs,eax
  1642.  
  1643.          mov edx,fileloc
  1644.          call next
  1645.          mov edi,edx
  1646.          mov edx,offset tag72
  1647.          mov ebp,dxfsize
  1648.          add ebp,dxfo
  1649.          call search_string
  1650.          jc exiterr6
  1651.  
  1652.          mov edx,edi
  1653.          call next
  1654.          mov fileloc,edx
  1655.          call _strhtn
  1656.          call _vct32
  1657.          mov pfaces,eax
  1658.          mov temp2,eax
  1659.  
  1660.          mov temp1,1
  1661. dxfpv_load:
  1662.          mov edi,fileloc
  1663.          mov edx,offset tag4
  1664.          mov ebp,dxfsize
  1665.          add ebp,dxfo
  1666.          call search_string
  1667.          jc exiterr6
  1668.  
  1669.          mov fileloc,edi
  1670.          mov edx,offset tagx
  1671.          call getnumber
  1672.          add eax,nx
  1673.          mov ebx,scale
  1674.          imul32 ebx
  1675.          add eax,nu
  1676.          push eax
  1677.  
  1678.          mov edx,offset tagy
  1679.          call getnumber
  1680.          add eax,ny
  1681.          mov ebx,scale
  1682.          imul32 ebx
  1683.          add eax,nw
  1684.          push eax
  1685.  
  1686.          mov edx,offset tagz
  1687.          call getnumber
  1688.          add eax,nz
  1689.          mov ebx,scale
  1690.          imul32 ebx
  1691.          add eax,nv
  1692.          cmp yneg,yes
  1693.          je noynegp
  1694.          neg eax
  1695. noynegp:
  1696.          mov ecx,eax
  1697.          pop ebp
  1698.          pop ebx
  1699.          call check_point
  1700.  
  1701.          mov edi,temp1
  1702.          mov polyindex[edi*4],eax
  1703.          inc temp1
  1704.          mov eax,temp1
  1705.          cmp eax,pvertexs
  1706.          jbe dxfpv_load
  1707. dxf_pmore:
  1708.          mov edi,fileloc       ; now reconstruct polyline into face
  1709.          mov edx,offset tag4
  1710.          mov ebp,dxfsize
  1711.          add ebp,dxfo
  1712.          call search_string
  1713.          jc exiterr6
  1714.  
  1715.          mov edx,offset tag71
  1716.          call getnumber
  1717.          shr eax,16
  1718.  
  1719.          mov start,eax
  1720.          mov ebp,connections    ; set first point in poly
  1721.          mov startconn,ebp
  1722.          mov eax,[polyindex+eax*4]
  1723.          mov esi,connmem
  1724.          mov [esi+ebp*4+p1],eax
  1725.  
  1726.          mov edx,offset tag72
  1727.          call getnumber
  1728.          jc exiterr6
  1729.          shr eax,16
  1730.          movsx eax,ax
  1731.          mov temp3,0
  1732.          cmp eax,0
  1733.          jge pf_kkl
  1734.          neg eax
  1735.          mov temp3,1
  1736. pf_kkl:
  1737.          cmp eax,start
  1738.          je pf_close
  1739.          call addpoint
  1740.          cmp temp3,1
  1741.          je pf_close
  1742.  
  1743.          mov edx,offset tag73
  1744.          call getnumber
  1745.          jc pf_close
  1746.          shr eax,16
  1747.          movsx eax,ax
  1748.          mov temp3,0
  1749.          cmp eax,0
  1750.          jge pf_kkq
  1751.          neg eax
  1752.          mov temp3,1
  1753. pf_kkq:
  1754.          cmp eax,start
  1755.          je pf_close
  1756.          call addpoint
  1757.          cmp temp3,1
  1758.          je pf_close
  1759.  
  1760.          mov edx,offset tag74
  1761.          call getnumber
  1762.          jc pf_close
  1763.          shr eax,16
  1764.          movsx eax,ax
  1765.  
  1766.          mov temp3,0
  1767.          cmp eax,0
  1768.          jge pf_negit
  1769.          neg eax
  1770.          mov temp3,1
  1771. pf_negit:
  1772.          cmp eax,start
  1773.          je pf_close
  1774.          call addpoint
  1775.          cmp temp3,0
  1776.          je pf_close
  1777. pf_multi:
  1778.          mov edi,fileloc
  1779.          mov edx,offset tag4
  1780.          mov ebp,dxfsize
  1781.          add ebp,dxfo
  1782.          call search_string
  1783.          jc exiterr6
  1784.  
  1785.          mov edx,offset tag73
  1786.          call getnumber
  1787.          jc exiterr6
  1788.          shr eax,16
  1789.          movsx eax,ax
  1790.  
  1791.          mov temp3,0
  1792.          cmp eax,0
  1793.          jge pf_negitp
  1794.          neg eax
  1795.          mov temp3,1
  1796. pf_negitp:
  1797.          cmp eax,start
  1798.          je pf_close
  1799.          call addpoint
  1800.          cmp temp3,1
  1801.          je pf_multi
  1802. pf_close:
  1803.          mov eax,startconn
  1804.          mov ebp,connections
  1805.          mov esi,connmem
  1806.          mov [esi+eax*4+wc],ebp
  1807.          mov [esi+ebp*4+wg],eax
  1808.          mov ebx,start
  1809.          mov [esi+ebp*4+p2],ebx
  1810.          mov eax,thismaterial
  1811.          mov [esi+ebp*4+mt],eax
  1812.          mov eax,surfaces
  1813.          mov [esi+ebp*4+sd],eax
  1814.  
  1815.          inc connections
  1816.          inc surfaces
  1817.  
  1818.          dec pfaces
  1819.          jnz dxf_pmore
  1820.  
  1821.          jmp dxf_polylines
  1822. addpoint:
  1823.          mov ebp,connections
  1824.          mov eax,[polyindex+eax*4]
  1825.          mov esi,connmem
  1826.          mov [esi+ebp*4+p2],eax
  1827.          mov [esi+(ebp+1)*4+p1],eax
  1828.          mov [esi+ebp*4+wg],ebp
  1829.          inc dword ptr [esi+ebp*4+wg]
  1830.          mov eax,surfaces
  1831.          mov [esi+ebp*4+sd],eax
  1832.          mov eax,thismaterial
  1833.          mov [esi+ebp*4+mt],eax
  1834.          inc connections
  1835.          ret
  1836.  
  1837. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1838. ; Find opposite connection for line EBP
  1839. ; In:  EBX = connection to find pair for
  1840. ; Out: CF = 1 not found,  CF = 0 connection found at EDI!
  1841. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1842.  
  1843. find_pair:
  1844.          mov esi,connmem
  1845.          mov ecx,[esi+ebp*4+p1]  ; eg have (7,9) look for (9,7)
  1846.          mov edx,[esi+ebp*4+p2]
  1847.          mov eax,ecx
  1848.          or eax,edx
  1849.          jz fpnomatch
  1850.          xor edi,edi
  1851. fploop:
  1852.          mov eax,[esi+edi*4+p2]
  1853.          mov ebx,[esi+edi*4+p1]
  1854.  
  1855.          cmp eax,ecx
  1856.          jne fpnotmatch0
  1857.          cmp ebx,edx
  1858.          jne fpnotmatch0         ; backwards points?
  1859.  
  1860.          mov eax,[esi+ebp*4+ea]  ; yes, test if same plane equation
  1861.          cmp [esi+edi*4+ea],eax
  1862.          jne fpnotmatch1
  1863.          mov eax,[esi+ebp*4+eb]
  1864.          cmp [esi+edi*4+eb],eax
  1865.          jne fpnotmatch1
  1866.          mov eax,[esi+ebp*4+ec]
  1867.          cmp [esi+edi*4+ec],eax
  1868.          jne fpnotmatch1
  1869.          mov eax,[esi+ebp*4+ed]
  1870.          cmp [esi+edi*4+ed],eax
  1871.          jne fpnotmatch1
  1872.          mov eax,[esi+ebp*4+mt]  ; same equation, test if same material
  1873.          cmp [esi+edi*4+mt],eax
  1874.          jne fpnotmatch1
  1875.  
  1876.          clc
  1877.          ret
  1878. fpnotmatch0:
  1879.          or eax,ebx
  1880.          jz fpnomatch
  1881.  
  1882. fpnotmatch1:
  1883.          inc edi
  1884.          cmp edi,maxpoints
  1885.          jl fploop
  1886. fpnomatch:
  1887.          mov edi,-1
  1888.          stc
  1889.          ret
  1890.  
  1891. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1892. ; Renumber surfaces
  1893. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1894. renumber_surfaces:
  1895.          xor ebx,ebx
  1896. rnloop:
  1897.          call rn_lowest
  1898.          jc _ret
  1899.          call rn_eax2ebx
  1900.          inc ebx
  1901.          jmp rnloop
  1902.  
  1903. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1904. ; Search for lowest surface number (but above EBX)
  1905. ; In:  EBX = lowest surface number to test
  1906. ; Out:
  1907. ;  CF = 1, not found.
  1908. ;  CF = 0
  1909. ;   EAX = lowest surface number
  1910. ;   EBP = connection number where found
  1911. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1912.  
  1913. rn_lowest:
  1914.          mov esi,connmem
  1915.          mov ecx,connections
  1916.          mov eax,-1
  1917. rnlloop:
  1918.          mov edx,[esi+(ecx-1)*4+sd]
  1919.          cmp ebx,edx
  1920.          ja rnlnotel
  1921.  
  1922.          cmp eax,edx
  1923.          jb rnlnotel
  1924.  
  1925.          mov eax,edx
  1926.          mov ebp,ecx
  1927.          dec ebp
  1928. rnlnotel:
  1929.          loop rnlloop
  1930.  
  1931.          inc eax
  1932.          sub eax,1
  1933.          ret
  1934.  
  1935. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1936. ; Renumber surfaces EAX to EBX
  1937. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1938.  
  1939. rn_eax2ebx:
  1940.          mov esi,connmem
  1941.          lea edi,[esi+sd]
  1942.          mov ecx,connections
  1943. rn_eaxl:
  1944.          repnz scasd
  1945.  
  1946.          cmp ecx,0
  1947.          jz _ret
  1948.  
  1949.          mov [edi-4],ebx
  1950.          jmp rn_eaxl
  1951.  
  1952. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1953. ; Delete unused points and collect
  1954. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1955. collect_points:
  1956.          mov esi,connmem
  1957.          mov eax,1
  1958. coploop:
  1959.          lea edi,[esi+p1]
  1960.          mov ecx,connections
  1961.          repnz scasd
  1962.          sub ecx,1
  1963.          jnc cpused
  1964.  
  1965.          lea edi,[esi+p2]
  1966.          mov ecx,connections
  1967.          repnz scasd
  1968.          sub ecx,1
  1969.          jnc cpused
  1970.  
  1971.          call cpdeleteit
  1972. cpused:
  1973.          inc eax
  1974.          cmp eax,points
  1975.          jne coploop
  1976.  
  1977.          ret
  1978.  
  1979. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1980. ; Delete point EAX
  1981. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1982. cpdeleteit:
  1983.          mov ebp,points
  1984.          mov esi,connmem
  1985.          lea ecx,[ebp-eax]
  1986.          lea edi,[esi+(eax+0)*4+ox]
  1987.          lea esi,[esi+(eax+1)*4+ox]
  1988.          rep movsd
  1989.  
  1990.          mov esi,connmem
  1991.          lea ecx,[ebp-eax]
  1992.          lea edi,[esi+(eax+0)*4+oy]
  1993.          lea esi,[esi+(eax+1)*4+oy]
  1994.          rep movsd
  1995.  
  1996.          mov esi,connmem
  1997.          lea ecx,[ebp-eax]
  1998.          lea edi,[esi+(eax+0)*4+oz]
  1999.          lea esi,[esi+(eax+1)*4+oz]
  2000.          rep movsd
  2001.  
  2002.          mov esi,connmem
  2003.          mov ecx,connections
  2004.          xor ebp,ebp
  2005. cpdloop:
  2006.          mov ebx,[esi+ebp*4+p1]
  2007.          cmp ebx,eax
  2008.          jb cpskip1
  2009.          dec dword ptr [esi+ebp*4+p1]
  2010. cpskip1:
  2011.          mov ebx,[esi+ebp*4+p2]
  2012.          cmp ebx,eax
  2013.          jb cpskip2
  2014.          dec dword ptr [esi+ebp*4+p2]
  2015. cpskip2:
  2016.          inc ebp
  2017.          loop cpdloop
  2018.  
  2019.          dec points
  2020.          ret
  2021.  
  2022. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2023. ; Number sides in preparation for sort
  2024. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2025. number_them:
  2026.          mov esi,connmem
  2027.          mov ecx,surfaces
  2028.          dec ecx
  2029. tnkl:
  2030.          mov [esi+(ecx)*4+sn],ecx
  2031.          loop tnkl
  2032.  
  2033.          mov [esi+(ecx)*4+sn],ecx
  2034.          ret
  2035.  
  2036. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2037. ; Wipe D value from plane equation if no iteration used
  2038. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2039. wipe_d:
  2040.          cmp iterate,yes
  2041.          je _ret
  2042.          mov esi,connmem
  2043.          mov ecx,connections
  2044.          dec ecx
  2045.          xor edx,edx
  2046. wdkl:
  2047.          mov [esi+(ecx)*4+ed],edx
  2048.          loop wdkl
  2049.  
  2050.          mov [esi+(ecx)*4+ed],edx
  2051.          ret
  2052.  
  2053. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2054. ; Output file - file is opened and ready
  2055. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2056.  
  2057. output_file:
  2058.          mov ecx,8                     ; output header info
  2059.          mov al,"."
  2060.          mov edi,offset outputname
  2061.          repnz scasb
  2062.          mov byte ptr [edi-1],0
  2063.          sub edi,offset outputname
  2064.          push edi
  2065.          push edi
  2066.  
  2067.          mov edx,offset header0
  2068.          call _write_null
  2069.          mov edx,offset header1
  2070.          call _write_null
  2071.          mov edx,offset outputname
  2072.          call _write_null
  2073.          pop ecx
  2074.          mov edx,offset header7
  2075.          add edx,ecx
  2076.          call _write_null
  2077.          mov edx,offset header2
  2078.          call _write_null
  2079.          mov edx,offset outputname
  2080.          call _write_null
  2081.          mov edx,offset header3
  2082.          call _write_null
  2083.          mov edx,offset outputname
  2084.          call _write_null
  2085.          pop ecx
  2086.          mov edx,offset header4
  2087.          add edx,ecx
  2088.          call _write_null
  2089.          mov eax,points
  2090.          call _write_dec16
  2091.          mov eax,","
  2092.          call _write_string4
  2093.          mov eax,surfaces
  2094.          call _write_dec16
  2095.          call _write_ret
  2096.  
  2097.          mov edx,offset header4
  2098.          call _write_null
  2099.          mov edx,offset header5
  2100.          call _write_null
  2101.          call _write_ret
  2102.          call _write_ret
  2103.  
  2104.          mov temp1,1                ; now output points
  2105. of_loop1:
  2106.          mov edx,offset header4
  2107.          call _write_null
  2108.  
  2109.          mov esi,connmem
  2110.          mov ecx,temp1
  2111.          mov eax,[esi+ecx*4+ox]
  2112.          mov edx,offset buffer
  2113.          call _write_neg16
  2114.          call _write_null
  2115.          mov eax,","
  2116.          call _write_string4
  2117.          mov esi,connmem
  2118.          mov ecx,temp1
  2119.          mov eax,[esi+ecx*4+oy]
  2120.          mov edx,offset buffer
  2121.          call _write_neg16
  2122.          call _write_null
  2123.          mov eax,","
  2124.          call _write_string4
  2125.          mov esi,connmem
  2126.          mov ecx,temp1
  2127.          mov eax,[esi+ecx*4+oz]
  2128.          mov edx,offset buffer
  2129.          call _write_neg16
  2130.          call _write_null
  2131.          mov edx,offset header6
  2132.          call _write_null
  2133.          mov eax,temp1
  2134.          call _write_dec16
  2135.          call _write_ret
  2136.          inc temp1
  2137.          mov ecx,temp1
  2138.          cmp ecx,points
  2139.          jbe of_loop1
  2140.          call _write_ret
  2141.  
  2142.          mov temp1,0              ; output surfaces
  2143. dp_sloop:
  2144.          mov ebx,temp1
  2145.          call rn_lowest
  2146.          mov temp2,ebp
  2147.  
  2148.          mov edx,offset header4
  2149.          call _write_null
  2150.          mov esi,connmem
  2151.          mov ecx,temp2
  2152.          mov ecx,[esi+ecx*4+mt]
  2153.          call find_info
  2154.          mov thismaterial,edx
  2155.          mov edx,thismaterial
  2156.          call find_shade
  2157.          jc dp_noshade0
  2158.          mov esi,connmem
  2159.          mov ebp,temp2
  2160.          mov ebp,[esi+ebp*4+wg]
  2161.          mov ebp,[esi+ebp*4+wg]
  2162.          cmp ebp,temp2
  2163.          jne dp_noshade0
  2164.          mov edx,offset fidefaull
  2165.          mov thismaterial,edx
  2166. dp_noshade0:
  2167.          mov edx,thismaterial
  2168.          call _write_null
  2169.          mov eax,","
  2170.          call _write_string4
  2171.  
  2172.          mov ebp,temp2
  2173.          mov esi,connmem
  2174.          mov eax,[esi+ebp*4+p1]
  2175.          call _write_dec16
  2176. dp_cloop:
  2177.          mov temp3,ebp
  2178.          mov eax,","
  2179.          call _write_string4
  2180.          mov esi,connmem
  2181.          mov ebp,temp3
  2182.          mov eax,[esi+ebp*4+p2]
  2183.          call _write_dec16
  2184.          mov esi,connmem
  2185.          mov ebp,temp3
  2186.          mov ebp,[esi+ebp*4+wg]
  2187.          cmp temp2,ebp
  2188.          jne dp_cloop
  2189.  
  2190.          mov edx,thismaterial
  2191.          call find_shade
  2192.          jc dp_noshade
  2193.  
  2194.          mov esi,connmem
  2195.          mov ebp,temp2
  2196.          mov ebp,[esi+ebp*4+wg]
  2197.          mov ebp,[esi+ebp*4+wg]
  2198.          cmp ebp,temp2
  2199.          je dp_noshade
  2200.  
  2201.          cmp tnormal,no
  2202.          je normalnormal
  2203.          mov eax,","
  2204.          call _write_string4
  2205.          mov esi,connmem
  2206.          mov ebp,temp2
  2207.          mov eax,[esi+ebp*4+ea]
  2208.          shr eax,2
  2209.          mov edx,offset buffer
  2210.          call _write_neg16
  2211.          call unpad
  2212.          call _write_null
  2213.          mov eax,","
  2214.          call _write_string4
  2215.          mov esi,connmem
  2216.          mov ebp,temp2
  2217.          mov eax,[esi+ebp*4+eb]
  2218.          shr eax,2
  2219.          mov edx,offset buffer
  2220.          call _write_neg16
  2221.          call unpad
  2222.          call _write_null
  2223.          mov eax,","
  2224.          call _write_string4
  2225.          mov esi,connmem
  2226.          mov ebp,temp2
  2227.          mov eax,[esi+ebp*4+ec]
  2228.          shr eax,2
  2229.          mov edx,offset buffer
  2230.          call _write_neg16
  2231.          call unpad
  2232.          call _write_null
  2233.          jmp dp_noshade
  2234. normalnormal:
  2235.          mov edx,offset header9
  2236.          call _write_null
  2237.  
  2238. dp_noshade:
  2239.          call _write_ret
  2240.  
  2241.          inc temp1
  2242.          mov ecx,temp1
  2243.          cmp ecx,surfaces
  2244.          jne dp_sloop
  2245.  
  2246.          call _write_ret
  2247.          ret
  2248.  
  2249. header0  db ";DXF23DV converter V0.1 - This conversion conforms to version 3DVECT35",13,10,13,10,0
  2250. header1  db "h",0
  2251. header2  db "-1",13,10,"           dd offset o",0
  2252. header3  db " - offset $ - 4",13,10,13,10,"o",0
  2253. header4  db "           dw ",0
  2254. header5  db "25 dup (0)",0
  2255. header6  db "  ; point ",0
  2256. header7  db "           dd ",0
  2257. header8  db " offset o",0
  2258. header9  db ",0,0,0",0
  2259.  
  2260. code32   ends
  2261.          end
  2262.