home *** CD-ROM | disk | FTP | other *** search
/ CD-X 1 / cdx_01.iso / demodisc / basq / source / 3dvektor / dxf23dv / extras.rt < prev    next >
Encoding:
Text File  |  1994-10-29  |  18.8 KB  |  856 lines

  1.         public _setbuf
  2.         public _putdosmsg
  3.         public _strhtn
  4.         public _strlen
  5.         public _strltu
  6.         public _get_float32
  7.         public _strhtn
  8.         public _strlen
  9.         public _strltu
  10.         public _vct32
  11.         public _vct16
  12.         public _cv32
  13.         public _cv16
  14.         public _imul32
  15.         public _idiv32
  16.         public _dos_float32
  17.         public _dos_dec16
  18.         public _dos_hex8
  19.         public _dos_hex16
  20.         public _dos_hex32
  21.         public _dos_ret
  22.         public _dos_string4
  23.         public _write_null
  24.         public _write_string4
  25.         public _write_dec16
  26.         public _write_ret
  27.  
  28. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  29. ; write a return to DOS
  30. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  31. _dos_ret:
  32.         mov eax,00240a0dh
  33.  
  34. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  35. ; write eax to dos
  36. ; eg eax = "$!ih"  outputs hi!
  37. ;    eax = "NHOJ"  outputs JOHN
  38. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  39.  
  40. _dos_string4:
  41.         mov fv,eax
  42.         mov edx,offset fv
  43.         jmp _putdosmsg
  44.  
  45. fv      dd 0
  46.         db "$"
  47.  
  48. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  49. ; write eax as 32bit hex
  50. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  51. _dos_hex32:
  52.         call _cv32
  53.         push ebp
  54.         call _dos_string4
  55.         pop eax
  56.         jmp _dos_string4
  57.  
  58. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  59. ; write ax as 16bit hex
  60. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  61. _dos_hex16:
  62.         call _cv32
  63.         jmp _dos_string4
  64.  
  65. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  66. ; write ax as 8bit hex
  67. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  68. _dos_hex8:
  69.         call _cv32
  70.         push ax
  71.         mov eax,00240000h
  72.         pop ax
  73.         jmp _dos_string4
  74.  
  75. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  76. ; write ax as a decimal number, hex to decimal conversion
  77. ; eg ax=4a2eh outputs 18990
  78. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  79. _dos_dec16:
  80.         call _cv16
  81.  
  82.         mov xq,0
  83.         mov vc,eax
  84.  
  85.         shr eax,16
  86.         call dropchar2
  87.         shr eax,12
  88.         call dropchar2
  89.         shr eax,8
  90.         call dropchar2
  91.         shr eax,4
  92.         call dropchar2
  93.         mov xq,1
  94.         call dropchar2
  95.         ret
  96.  
  97. chars   db "0123456789abcdef"
  98. byte2   db "0$"
  99. vc      dd 0
  100. xq      dw 0
  101.  
  102. dropchar2:
  103.         and ax,0fh
  104.         cmp ax,0
  105.         jne jo0
  106.         cmp xq,0
  107.         je nxq
  108. jo0:
  109.         mov xq,1
  110.         and ax,0fh
  111.         movzx esi,ax
  112.         mov bl,chars[esi]
  113.         mov byte2,bl
  114.         mov edx, offset byte2
  115.         call _putdosmsg
  116. nxq:
  117.         mov eax,vc
  118.         ret
  119.  
  120. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  121. ; output eax as psuedo floating point number to DOS
  122. ;
  123. ; eg eax = 12347a6ch outputs 4660.47821
  124. ;          ^^^^
  125. ; whole portion
  126. ;              ^^^^ fractional portion
  127. ;
  128. ; Listen, its late and I dont really care if the routine is sloppy OK!
  129. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  130.  
  131.  precision = 4      ; eg 91.8874
  132. ;precision = 5      ; eg 91.88743   <- 3 is questionable!
  133.  
  134. _dos_float32:
  135.         push eax
  136.         test eax,80000000h
  137.         jz nonegit
  138.         neg eax
  139.         pop ebx
  140.         push eax
  141.         mov eax,"$-"
  142.         call _dos_string4
  143. nonegit:
  144.         pop eax
  145.         push eax
  146.         shr eax,16
  147.         call _dos_dec16
  148.  
  149.         pop eax
  150.         and eax,0000ffffh
  151.         jz outahere
  152.  
  153.         imul eax,10000
  154.         cdq
  155.         mov ebx,65536
  156.         idiv ebx
  157.  
  158.         push edx
  159.  
  160.         call _cv16
  161.  
  162.         mov vc,0
  163.         mov xq,ax
  164.  
  165.         call dropchar3
  166.         shl vc,8
  167.         shr eax,4
  168.         call dropchar3
  169.         shl vc,8
  170.         shr eax,8
  171.         call dropchar3
  172.         shl vc,8
  173.         shr eax,12
  174.         call dropchar3
  175.  
  176.         pop eax
  177.  
  178.         if precision eq 5
  179.         cdq                ; this calcs the last decimal
  180.         imul eax,10
  181.         shr eax,16
  182.  
  183.         cmp al,0           ; check if decimal is nulls
  184.         jne etoutall
  185.         endif
  186.  
  187.         cmp vc,"0000"
  188.         je outahere
  189. etoutall:
  190.  
  191.         if precision eq 5
  192.         push eax
  193.         cmp al,0
  194.         jne etggo
  195.         endif
  196.  
  197.         cmp byte ptr [vc+3],"0"
  198.         jne etggo
  199.         mov byte ptr [vc+3],"$"
  200.         cmp byte ptr [vc+2],"0"
  201.         jne etggo
  202.         mov byte ptr [vc+2],"$"
  203.         cmp byte ptr [vc+1],"0"
  204.         jne etggo
  205.         mov byte ptr [vc+1],"$"
  206.  
  207. etggo:
  208.         mov eax,"$."
  209.         call _dos_string4
  210.         mov eax,vc
  211.         call _dos_string4
  212.  
  213.         if precision eq 5
  214.         pop eax
  215.         cmp al,0
  216.         je outahere
  217.         call _dos_dec16 ; this outputs the last decimal
  218.         endif
  219.  
  220. outahere:
  221.         ret
  222.  
  223. dropchar3:
  224.         and eax,0fh
  225.         mov bl,chars[eax]
  226.         or  byte ptr vc,bl
  227.         mov ax,xq
  228.         ret
  229.  
  230. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  231. ; convert ax from dec number to eax as string
  232. ; eg ax=51324 decimal returns eax=51324h
  233. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  234. _cv16:
  235.         xor ecx,ecx
  236.         xor dx,dx
  237.         mov bx,10000
  238.         div bx
  239.         or cl,al
  240.         shl ecx,4
  241.         mov ax,dx
  242.         xor dx,dx
  243.         mov bx,1000
  244.         div bx
  245.         or cl,al
  246.         shl ecx,4
  247.         mov ax,dx
  248.         xor dx,dx
  249.         mov bx,100
  250.         div bx
  251.         or cl,al
  252.         shl ecx,4
  253.         mov ax,dx
  254.         xor dx,dx
  255.         mov bx,10
  256.         div bx
  257.         or cl,al
  258.         shl ecx,4
  259.         or cl,dl
  260.         mov eax,ecx
  261.         ret
  262.  
  263. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  264. ; convert eax = 12345678h  to eax = "4321"  ebp = "8765"
  265. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  266. _cv32:
  267.         mov cl,28
  268.         mov edx,8
  269.         mov esi,eax
  270. cvxl:
  271.         shrd eax,ebp,8
  272.         shr ebp,8
  273.         mov edi,esi
  274.         shr edi,cl
  275.         and edi,0fh
  276.         mov bl,chars[edi]
  277.         shl ebx,24
  278.         or ebp,ebx
  279.         sub cl,4
  280.         dec edx
  281.         jnz cvxl
  282.  
  283.         ret
  284.  
  285. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  286. ; multiply eax by ebx 16bt fixed point
  287. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  288. _imul32:
  289.         imul ebx
  290.         shrd eax,edx,16
  291.         ret
  292.  
  293. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  294. ; divide eax by ebx 16bt fixed point
  295. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  296. _idiv32:
  297.         cdq
  298.         shld edx,eax,16
  299.         shl eax,16
  300.         idiv ebx
  301.         ret
  302.  
  303. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  304. ; simple routine to convert eax = 0087654h -> eax = 87654 decimal (15666h)
  305. ; i guess i should have done this in a loop...
  306. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  307.  
  308. _vct32:
  309.         push eax
  310.         shr eax,28
  311.         mov ebx,10000000
  312.         and eax,0fh
  313.         mul ebx
  314.         mov ecx,eax
  315.         pop eax
  316.  
  317.         push eax
  318.         shr eax,24
  319.         mov ebx,1000000
  320.         and eax,0fh
  321.         mul ebx
  322.         mov ecx,eax
  323.         pop eax
  324.  
  325.         push eax
  326.         shr eax,20
  327.         mov ebx,100000
  328.         and eax,0fh
  329.         mul ebx
  330.         mov ecx,eax
  331.         pop eax
  332. _vct16:
  333.         push eax
  334.         shr eax,16
  335.         mov ebx,10000
  336.         and eax,0fh
  337.         mul ebx
  338.         mov ecx,eax
  339.         pop eax
  340.  
  341.         push eax
  342.         shr eax,12
  343.         mov ebx,1000
  344.         and eax,0fh
  345.         mul ebx
  346.         add ecx,eax
  347.         pop eax
  348.  
  349.         push eax
  350.         shr eax,8
  351.         mov ebx,100
  352.         and eax,0fh
  353.         mul ebx
  354.         add ecx,eax
  355.         pop eax
  356.  
  357.         push eax
  358.         shr eax,4
  359.         mov ebx,10
  360.         and eax,0fh
  361.         mul ebx
  362.         add ecx,eax
  363.         pop eax
  364.  
  365.         and eax,0fh
  366.         add eax,ecx
  367.  
  368.         ret
  369.  
  370. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  371. ; Make all lower case letters in string uppercase
  372. ; In:
  373. ;   EDX -> string
  374. ; Out:
  375. ;   None
  376. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  377. _strltu:
  378.         push ax
  379.         push edx
  380. strltuml:
  381.         mov al,[edx]
  382.         or al,al
  383.         jz short strltumld
  384.         cmp al,'a'
  385.         jb short strltumlf0
  386.         cmp al,'z'
  387.         ja short strltumlf0
  388.         sub al,'a'-'A'
  389.         mov [edx],al
  390. strltumlf0:
  391.         inc edx
  392.         jmp strltuml
  393. strltumld:
  394.         pop edx
  395.         pop ax
  396.         ret
  397.  
  398. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  399. ; Get length of ASCIIZ string
  400. ; In:
  401. ;   EDX -> string
  402. ; Out:
  403. ;   EAX - length
  404. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  405. _strlen:
  406.         push ecx
  407.         push edi
  408.         mov edi,edx
  409.         mov ecx,-1
  410.         xor al,al
  411.         repnz scasb
  412.         mov eax,-2
  413.         sub eax,ecx
  414.         pop edi
  415.         pop ecx
  416.         ret
  417.  
  418. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  419. ; Get number from mem
  420. ; In:
  421. ;   EDX -> ASCIIZ hex number string
  422. ; Out:
  423. ;   EAX - number
  424. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  425. _strhtn:
  426.         push bx
  427.         push edx
  428.         xor eax,eax
  429. strhtnml:
  430.         mov bl,[edx]
  431.         inc edx
  432.         sub bl,'0'
  433.         jc short strhtnmld
  434.         cmp bl,0ah
  435.         jb short strhtnmlc
  436.         sub bl,('A'-'0')-10
  437. strhtnmlc:
  438.         shl eax,4
  439.         or al,bl
  440.         jmp strhtnml
  441. strhtnmld:
  442.         pop edx
  443.         pop bx
  444.         ret
  445.  
  446. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  447. ; Get psuedo floating point number from mem
  448. ; In:
  449. ;   EDX -> ASCIIZ hex number string
  450. ; Out:
  451. ;   EAX - number
  452. ;         where high word is whole portion
  453. ;         and low word is fractional portion
  454. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  455.  
  456. _get_float32:
  457.         mov getsx,0
  458.         cmp byte ptr [edx],"-"
  459.         jne getnonegd
  460.         inc edx
  461.         inc getsx
  462. getnonegd:
  463.         push edx
  464.         call _strhtn
  465.         call _vct16
  466.         pop edx
  467.  
  468.         push eax      ; save whole portion
  469. getfinddotq:
  470.         mov al,[edx]
  471.         cmp al,"."
  472.         je getokdotq
  473.         cmp al,"0"
  474.         jb getnodotq
  475.         cmp al,"9"
  476.         ja getnodotq
  477.         inc edx
  478.         jmp getfinddotq
  479. getnodotq:
  480.         pop eax
  481.         shl eax,16
  482. getckneg:
  483.         mov esi,eax
  484.         cmp al,0           ; test to see if round up should occur
  485.         je getff
  486.  
  487.         test eax,80000000h
  488.         jz nonegitq
  489.         neg eax
  490. nonegitq:
  491.         and eax,0000ffffh
  492.         imul eax,10000
  493.         cdq
  494.         mov ebx,65536
  495.         idiv ebx
  496.  
  497.         mov eax,edx
  498.         cdq                ; this calcs the last decimal
  499.         imul eax,10
  500.         shr eax,16
  501.  
  502.         cmp al,0           ; check if decimal is nulls
  503.         je getff
  504.         inc esi ; rounds 99.99999 to 100, also, 92.7 is 92.6999, this fixes that!
  505. getff:
  506.         mov eax,esi
  507.         cmp getsx,0
  508.         jz getouthq
  509.         neg eax
  510. getouthq:
  511.         ret
  512.  
  513. getsx   db 0
  514.  
  515. getokdotq:
  516.         inc edx
  517.         xor eax,eax
  518.  
  519.         call getkk
  520.         jc getnot
  521.         shl ebx,16
  522.         or eax,ebx
  523.         call getkk
  524.         jc getnot
  525.         shl ebx,12
  526.         or eax,ebx
  527.         call getkk
  528.         jc getnot
  529.         shl ebx,8
  530.         or eax,ebx
  531.         call getkk
  532.         jc getnot
  533.         shl ebx,4
  534.         or eax,ebx
  535.         call getkk
  536.         jc getnot
  537.         or eax,ebx
  538. getnot:
  539.         call _vct32
  540.         cdq
  541.         shld edx,eax,16
  542.         shl eax,16
  543.         mov ebx,100000
  544.         idiv ebx
  545.         pop ebx
  546.         shl ebx,16
  547.         or eax,ebx
  548.         jmp getckneg
  549.  
  550. getkk:
  551.         xor ebx,ebx
  552.         mov bl,[edx]
  553.         inc edx
  554.         sub bl,'0'
  555.         jc short gstrhtnmld
  556.         cmp bl,0ah
  557.         ja short gstrhtnmld
  558.         clc
  559.         ret
  560.  
  561. gstrhtnmld:
  562.         stc
  563.         ret
  564.  
  565. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  566. ; Put '$' terminated message to DOS
  567. ; In:
  568. ;   EDX -> message in low mem
  569. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  570. _putdosmsg:
  571.         push ax edx
  572.         add edx,_code32a
  573.         mov al,dl
  574.         and ax,0fh
  575.         shr edx,4
  576.         mov v86r_ds,dx
  577.         mov v86r_dx,ax
  578.         mov v86r_ah,9
  579.         mov al,21h
  580.         int 33h
  581.         pop edx ax
  582.         ret
  583.  
  584. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  585. ; Initialize file buffer
  586. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  587. _setbuf:
  588.         mov eax,_lomembase
  589.         mov _filebufloc,eax
  590.         mov _filebuflen,4000h
  591.         add _lomembase,4000h
  592.         ret
  593.  
  594. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  595. ; write a return to file
  596. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  597. _write_ret:
  598.         mov eax,00000a0dh
  599.  
  600. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  601. ; Write eax=string4 to file
  602. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  603. _write_string4:
  604.         mov tempx,eax
  605.         mov edx,offset tempx
  606.  
  607. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  608. ; Write null terminated string to file
  609. ; EDX = ASCIIZ string
  610. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  611. _write_null:
  612.         call _strlen
  613.         mov ecx,eax
  614.         jmp  _writefile
  615.  
  616. tempx   dd 0
  617.         db 0
  618.  
  619. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  620. ; write ax as a decimal number to file, hex to decimal conversion
  621. ; eg ax=4a2eh outputs 18990
  622. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  623. _write_dec16:
  624.         call _cv16
  625.  
  626.         mov xqx,0
  627.         mov vcx,eax
  628.  
  629.         shr eax,16
  630.         call dropchar4
  631.         shr eax,12
  632.         call dropchar4
  633.         shr eax,8
  634.         call dropchar4
  635.         shr eax,4
  636.         call dropchar4
  637.         mov xqx,1
  638.         call dropchar4
  639.         ret
  640.  
  641. charsx  db "0123456789abcdef"
  642. vcx     dd 0
  643. xqx     dw 0
  644.  
  645. dropchar4:
  646.         and ax,0fh
  647.         cmp ax,0
  648.         jne jo4
  649.         cmp xqx,0
  650.         je nx4
  651. jo4:
  652.         mov xqx,1
  653.         and ax,0fh
  654.         movzx esi,ax
  655.         mov bl,charsx[esi]
  656.         mov al,bl
  657.         xor ah,ah
  658.         call _write_string4
  659. nx4:
  660.         mov eax,vcx
  661.         ret
  662.  
  663. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  664. ; output eax as psuedo floating point number to FILE
  665. ;
  666. ; eg eax = 12347a6ch outputs 4660.47821
  667. ;          ^^^^
  668. ; whole portion
  669. ;              ^^^^ fractional portion
  670. ;
  671. ; Listen, its late and I dont really care if the routine is sloppy OK!
  672. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  673.  
  674.  precision = 4      ; eg 91.8874
  675. ;precision = 5      ; eg 91.88743   <- 3 is questionable!
  676.  
  677. _write_float32:
  678.         push eax
  679.         test eax,80000000h
  680.         jz wnonegit
  681.         neg eax
  682.         pop ebx
  683.         push eax
  684.         mov eax,"-"
  685.         call _write_string4
  686. wnonegit:
  687.         pop eax
  688.         push eax
  689.         shr eax,16
  690.         call _write_dec16
  691.  
  692.         pop eax
  693.         and eax,0000ffffh
  694.         jz woutahere
  695.  
  696.         imul eax,10000
  697.         cdq
  698.         mov ebx,65536
  699.         idiv ebx
  700.  
  701.         push edx
  702.  
  703.         call _cv16
  704.  
  705.         mov vc,0
  706.         mov xq,ax
  707.  
  708.         call wdropchar3
  709.         shl vc,8
  710.         shr eax,4
  711.         call wdropchar3
  712.         shl vc,8
  713.         shr eax,8
  714.         call wdropchar3
  715.         shl vc,8
  716.         shr eax,12
  717.         call wdropchar3
  718.  
  719.         pop eax
  720.  
  721.         if precision eq 5
  722.         cdq                ; this calcs the last decimal
  723.         imul eax,10
  724.         shr eax,16
  725.  
  726.         cmp al,0           ; check if decimal is nulls
  727.         jne wetoutall
  728.         endif
  729.  
  730.         cmp vc,"0000"
  731.         je woutahere
  732. wetoutall:
  733.  
  734.         if precision eq 5
  735.         push eax
  736.         cmp al,0
  737.         jne wetggo
  738.         endif
  739.  
  740.         cmp byte ptr [vc+3],"0"
  741.         jne wetggo
  742.         mov byte ptr [vc+3],"$"
  743.         cmp byte ptr [vc+2],"0"
  744.         jne wetggo
  745.         mov byte ptr [vc+2],"$"
  746.         cmp byte ptr [vc+1],"0"
  747.         jne wetggo
  748.         mov byte ptr [vc+1],"$"
  749.  
  750. wetggo:
  751.         mov eax,"."
  752.         call _write_string4
  753.         mov eax,vc
  754.         call _write_string4
  755.  
  756.         if precision eq 5
  757.         pop eax
  758.         cmp al,0
  759.         je woutahere
  760.         call _write_dec16 ; this outputs the last decimal
  761.         endif
  762.  
  763. woutahere:
  764.         ret
  765.  
  766. wdropchar3:
  767.         and eax,0fh
  768.         mov bl,chars[eax]
  769.         or  byte ptr vc,bl
  770.         mov ax,xq
  771.         ret
  772.  
  773. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  774. ; write ax as a decimal number to memory at EDX
  775. ; with sign extension, right justified, and zero terminated
  776. ; eg ax=f79fh outputs -2145
  777. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  778. _write_neg16:
  779.         push eax
  780.         xor al,al
  781.         mov edi,edx
  782.         mov ecx,7
  783.         rep stosb
  784.         pop eax
  785.  
  786.         mov vvq,edx
  787.         mov vvc,edx
  788.         test eax,8000h
  789.         jz wnonegiq
  790.         neg eax
  791.         mov byte ptr [edx],"-"
  792.         inc vvq
  793. wnonegiq:
  794.         call _cv16
  795.  
  796.         mov xqq,0
  797.         mov vcq,eax
  798.  
  799.         shr eax,16
  800.         call dropchar5
  801.         shr eax,12
  802.         call dropchar5
  803.         shr eax,8
  804.         call dropchar5
  805.         shr eax,4
  806.         call dropchar5
  807.         mov xqq,1
  808.         call dropchar5
  809.  
  810.         mov ecx,vvq
  811.         sub ecx,vvc
  812.         mov edi,vvc
  813.         add edi,6
  814.         mov esi,vvq
  815.         inc ecx
  816. dp_loop:
  817.         mov al,[esi]
  818.         mov [edi],al
  819.         dec edi
  820.         dec esi
  821.         loop dp_loop
  822. dp_ss:
  823.         cmp edi,vvc
  824.         jb dp_out
  825.         mov byte ptr [edi]," "
  826.         dec edi
  827.         jmp dp_ss
  828. dp_out:
  829.         mov edx,vvc
  830.         ret
  831.  
  832. charsq  db "0123456789abcdef"
  833. vcq     dd 0
  834. xqq     dw 0
  835. vvq     dd 0
  836. vvc     dd 0
  837.  
  838. dropchar5:
  839.         and ax,0fh
  840.         cmp ax,0
  841.         jne jo5
  842.         cmp xqq,0
  843.         je nx5
  844. jo5:
  845.         mov xqq,1
  846.         and ax,0fh
  847.         movzx esi,ax
  848.         mov bl,charsx[esi]
  849.         mov edx,vvq
  850.         mov [edx],bl
  851.         inc vvq
  852. nx5:
  853.         mov eax,vcq
  854.         ret
  855.  
  856.