home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / PMPAL.ZIP / PAL2.ASM < prev    next >
Assembly Source File  |  1989-12-14  |  4KB  |  130 lines

  1.                 .model large,pascal
  2. public  _palette_regs
  3.                 .fardata PALDATA
  4. flag            db      0
  5. _palette_regs   db      16 dup (0) ;0,1,2,3,4,5,6,7
  6.               ; db      38h, 09h, 12h, 1Bh, 24h, 2Dh, 36h, 3Fh
  7.                 assume ds:PALDATA
  8.                 .code  PALETTE
  9.                 .286
  10. readpal:                                ; read out all 16 palette registers
  11.                 mov     cx,10h
  12.                 mov     ax,PALDATA
  13.                 mov     ds,ax
  14.                 lea     di,_palette_regs
  15. nextpalette:
  16.                 mov     dx,3DAh
  17.                 cli
  18.                 in      al,dx
  19.                 push    dx
  20.                 mov     dl,0C0h
  21.                 mov     al,10h  ; 10h-cx
  22.                 sub     al,cl   ; pal register
  23.                 out     dx,al
  24.                 jmp     yyyy
  25. yyyy:
  26.                 inc     dx
  27.                 in      al,dx
  28.                 xor     ah,ah
  29.                 mov     bx,ax
  30.                 pop     dx
  31.                 in      al,dx
  32.                 mov     dl,0C0h
  33.                 mov     al,20h
  34.                 out     dx,al
  35.                 sti
  36.                 mov     byte ptr ds:[di],bl
  37.                 inc     di
  38.                 loop    nextpalette
  39.                 
  40.                 ret
  41.  
  42. public          REMAPALLPALETTE
  43. REMAPALLPALETTE:
  44.  
  45.                 push    bp
  46.                 mov     bp,sp
  47.                 push    ds
  48.                 push    si
  49.                 push    di
  50.  
  51.                 mov     cx,word ptr [bp+10]
  52.                 push    cx
  53.                 push    dx
  54.  
  55.                 test    cx,010h               ; 16 color mode ?
  56.                 jz      color256
  57.                 mov     ax,seg flag
  58.                 mov     ds,ax
  59.                 cmp     byte ptr ds:[flag],0  ; palette table read in ?
  60.                 jnz     color256
  61.                 mov     byte ptr ds:[flag],1  ; set flag
  62.                 call    readpal               ; read 16 palette registers
  63. color256:
  64.                 mov     ax,word ptr [bp+ 8]   ; pointer to color table
  65.                 mov     es,ax
  66.                 mov     di,word ptr [bp+ 6]
  67.  
  68.                 xor     cx,cx
  69.              jmp  okay
  70. loop1:          mov     dx,3DAh
  71.                 in      al,dx
  72.                 and     al,8
  73.                 jnz     okay
  74.                 loop    loop1
  75. okay:
  76.                 pop     dx
  77.                 pop     cx
  78.                 mov     ah,dh
  79.  
  80.                 mov     si,cx
  81.                 mov     bx,cx           ; number of colors
  82.                 dec     bx
  83.                 shl     bx,2            ; four bytes for every color
  84.                 add     di,bx
  85. loop2:
  86.                 mov     al,cl
  87.                 dec     al
  88.                 test    si,0F0h         ; 256 colors mode ?
  89.                 jz      noread
  90.                 lea     bx,_palette_regs
  91.                 xlat    
  92. noread:
  93.                 mov     dx,3C8h         ; palette register
  94.                 pushf
  95.                 cli
  96.                 out     dx,al           ; palette register number
  97.                 inc     dx
  98.                 mov     al,es:[di+2]
  99.                 shr     ax,2
  100.                 out     dx,al           ; update red register
  101.                 mov     al,es:[di+1]
  102.                 shr     ax,2
  103.                 out     dx,al           ; update green register
  104.                 mov     al,es:[di]
  105.                 shr     ax,2
  106.                 out     dx,al           ; update blue register
  107.                 sti
  108.                 popf
  109.                 sub     di,4
  110.                 loop    loop2
  111.  
  112.                 jmp     retrn
  113.  
  114. retrn:
  115.                 xor     ax,ax
  116.                 pop     di
  117.                 pop     si
  118.                 pop     ds
  119.                 pop     bp
  120.                 retf    6
  121.  
  122. if 0
  123.  
  124. int pascal far gpirealizecolortable(HPS hps)
  125. {
  126.    
  127.  
  128. endif
  129.                 end
  130.