home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -serious- / programming / c / awin / awremapinner.asm < prev    next >
Encoding:
Assembly Source File  |  1999-05-17  |  1.6 KB  |  75 lines

  1. ; FILE: GG:src/own/awin/awremapinner.ASM          REV: 1 --- awremap ObtainBestPen loop in 0x0 asm
  2. ; LINK: >LEAVEOBJ>
  3. ; History
  4. ;  0      13th Dec 1998: started because 256 ObtainBestPens take quite a
  5. ;         long time due PPC<->0x0 contextswitches.
  6. ;  1      14th Dec 1998: fixed to do freepens too in same routine.
  7. ;
  8.  
  9. ; a0 = ULONG *rgb (r0, g0, b0, r1, g2, b3, ... r<n>, g<n>, b<n>)
  10. ; a1 = UBYTE *remap (pen0, pen1, ... pen<n>)
  11. ; a2 = UBYTE *penal (free0, free1, ... free<n>)
  12. ; a3 = struct ColorMap *colormap
  13. ; a6 = struct Library *GfxBase
  14. ; d0 = ULONG max
  15. ; d1 = ULONG precision
  16.  
  17. _awremapinner68k:
  18.     movem.l    d2-d7/a2-a6,-(sp)
  19.  
  20.     move.l    d0,d7
  21.  
  22.     move.l    a0,a4
  23.     move.l    a1,a5
  24.  
  25.     clr.l    -(sp)        ; build taglist into stack
  26.     clr.l    -(sp)
  27.     pea    $84000001    ; OBP_FailIdBad
  28.     move.l    d1,-(sp)
  29.     pea    $84000000    ; OBP_Precision
  30.  
  31.     jsr    -$e4(a6)    ; _LVOWaitBlit
  32.  
  33.     moveq    #0,d6
  34. .flop    tst.b    (a2)        ; releasepen this pen?
  35.     beq.b    .fskip        ; nope, skip
  36.     moveq    #0,d0
  37.     move.l    a3,a0        ; colormap
  38.     move.b    (a5),d0        ; pen number
  39.     jsr    -$3b4(a6)    ; _LVOReleasePen
  40. .fskip    clr.b    (a2)+        ; clear releaseflag
  41.     addq.l    #1,a5        ; next pen number
  42.     subq.b    #1,d6        ; loop 256 times
  43.     bne.b    .flop
  44.  
  45.     lea    -256(a2),a2    ; fix pointers
  46.     lea    -256(a5),a5
  47.     moveq    #-1,d4
  48.  
  49. .lop    move.l    a3,a0        ; colormap
  50.     movem.l    (a4)+,d1/d2/d3    ; r/g/b
  51.     move.l    sp,a1        ; taglist
  52.     jsr    -$348(a6)    ; _LVOObtainBestPenA
  53.     move.l    d0,d1
  54.     addq.l    #1,d1
  55.     bne.b    .got
  56.  
  57.     ; a3=colormap
  58.     move.l    -2*4(a4),d1    ; d1=r
  59.     ; d2=g
  60.     ; d3=b
  61.     ; d4=-1
  62.     jsr    -$3f0(a6)    ; _LVOFindColor
  63.     bra.b    .skip
  64. .got
  65.     move.b    #1,(a2)+    ; set releaseflag
  66. .skip    move.b    d0,(a5)+    ; set remap pen number
  67.  
  68.     subq.l    #1,d7
  69.     bne.b    .lop
  70.  
  71.     lea    (5*4,sp),sp    ; pop taglist from stack
  72.     movem.l    (sp)+,d2-d7/a2-a6
  73.     rts
  74.  
  75.