home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 3 / FREEWARE.BIN / towns_os / tvi / tvi_src.lzh / ASM / PALCALC.ASM < prev    next >
Assembly Source File  |  1990-11-01  |  4KB  |  142 lines

  1.     PAGE 255,132
  2. ;*****************************************************************************
  3. ;$Header: palcalc.asv  1.8  90/11/01 16:30:28  Nam  Rel $
  4. ;*****************************************************************************
  5.  
  6.     extrn    tbl_expand:word
  7.     extrn    tbl_compless:byte
  8.  
  9.     .386p
  10. code    segment dword public use32 'code'
  11.     assume cs:code
  12.  
  13. ;************************************************************
  14. ;    palet 最適化
  15. ;************************************************************
  16. ;*** get min-distination ***
  17. ; void calc_palet(int dword)
  18. ;                    ↑テーブルオフセットadd(dword)
  19.  
  20.     public    calc_palet
  21.     db    'calc_palet',10
  22.     align    4
  23. calc_palet    proc near
  24.     cli                    ;割り込み禁止
  25.     mov    eax,dword ptr [esp+4]        ;eax=(short *)tbl_col_dist
  26.     push    ebx
  27.     push    ebp
  28.     push    esi
  29.     push    edi
  30.     push    es
  31.     mov    edi,eax                ;edi=(short *)tbl_col_dist
  32.     mov    ebp,dword ptr ds:[tbl_compless]    ;ebp=(char  *)tbl_compless
  33.     xor    ecx,ecx                ;ecx=0 ※'90.10.27
  34.     mov    eax,dword ptr ds:[tbl_expand]    ;(short *)tbl_expand
  35.     push    eax                ;[esp]=(short *)tbl_expand
  36.     mov    ax,ds
  37.     mov    es,ax                ;es=ds
  38.     cld                    ;loopはincで
  39.  
  40.     align    4                ;高速化のため境界整合
  41. calc_palet_loop_1:
  42.         mov    esi,[esp]        ;esi=(short *)tbl_expand
  43.         xor    dx,dx            ;(※'90.10.27)
  44.         dec    dx            ;dx=0ffffh(※c_value_min初期化)
  45.         mov    ax,cx
  46.         and    ax,7c00h        ;'90.10.26(shift桁合わせ省略)
  47.         push    ax            ;col_green
  48.         mov    ax,cx
  49.         and    ax,03e0h
  50.         push    ax            ;col_red
  51.         mov    ax,cx
  52.         and    ax,001fh
  53.         push    ax            ;col_blue
  54.         shl    ecx,16            ;上位16bitへ / cx=0
  55.  
  56.     align    4                    ;高速化のため境界整合
  57. calc_palet_loop_2:
  58.             mov    ax,word ptr ds:[esi]    ;***green
  59.             and    ax,7c00h        ;'90.10.26
  60.             sub    ax,word ptr [esp+4]    ;col_g (※'90.10.27)
  61.             jnc short    set_green
  62.             neg    ax            ;結果が負なら反転
  63. set_green:
  64.             movzx    ebx,ax            ;bx上位16bit=0
  65.             mov    ax,word ptr ds:[esi]    ;***red
  66.             and    ax,03e0h
  67.             sub    ax,word ptr [esp+2]    ;col_r (※'90.10.27)
  68.             jnc short    set_red
  69.             neg    ax            ;結果が負なら反転
  70. set_red:
  71.             or    bx,ax
  72.             lodsw                ;ax=blue/esi+=2 (10/27)
  73.             and    ax,001fh
  74.             sub    ax,word ptr [esp]    ;col_b (※'90.10.27)
  75.             jnc short    set_blue
  76.             neg    ax            ;結果が負なら反転
  77. set_blue:
  78.             or    bx,ax
  79.  
  80.             mov    ax,word ptr es:[edi+ebx*2]    ;'90.10.26
  81.                 ;≒shl ebx,1 / mov ax,word ptr es:[edi+ebx]
  82.             cmp    ax,dx            ;c_value_minと比較
  83.             jae short    set_min_color    ;上位or等しければjmp
  84.             mov    dx,ax            ;save min_color_value
  85.             mov    byte ptr ds:[ebp],cl    ;color[ebp]=min_colorNo
  86. set_min_color:
  87.             inc    cx            ;color[k++]
  88.             cmp    cx,255            ;0~255までのループ
  89.             jna short    calc_palet_loop_2
  90.         add    esp,6                ;≒(pop ax)*3
  91.         inc    ebp                ;ebp++
  92.         shr    ecx,16                ;上位16bit取り出し
  93.         inc    cx                ;i++
  94.         cmp    cx,32768            ;※0~32767までのループ
  95.         jna    calc_palet_loop_1
  96.         pop    esi                ;esi=(short*)tbl_expand
  97.     pop    es
  98.     pop    edi
  99.     pop    esi
  100.     pop    ebp
  101.     pop    ebx
  102.     sti                        ;割り込み許可
  103.     ret
  104. calc_palet    endp
  105.  
  106. code    ends
  107.  
  108. data    segment dword public use32 'data'
  109.     assume    ds:data
  110.  
  111. min_colNo    dw    0
  112.  
  113. data    ends
  114.     end
  115. ;*****************************************************************************
  116. ;$Log: RCS/palcalc.asv $
  117. ; Revision 1.8  90/11/01 16:30:28  Nam
  118. ; Release at V0.0 L18d
  119. ; Revision 1.7  90/11/01 16:30:28  Nam
  120. ; Rel V0.0L17 at '90.11.2 for FPICS.
  121. ; Revision 1.6  90/11/01 16:30:28  Nam
  122. ; '1-32766' -> '0-32767'
  123. ; Revision 1.5  90/10/27 22:51:06  Nam
  124. ; faster 1:30->1:15 (data area cut)
  125. ; Revision 1.4  90/10/27 17:26:52  Nam
  126. ; a littele faster
  127. ; Revision 1.3  90/10/26 19:44:44  Nam
  128. ; a little faster
  129. ; Revision 1.2  90/10/24 20:02:04  Nam
  130. ; separate a vector-table-object from main routine
  131. ; Revision 1.1  90/10/10 18:37:28  Nam
  132. ; Initial revision
  133. ;*****************************************************************************
  134.