; cli processes are not promoted
; wb specified tasks will be not promoted
; last modified 08 Apr 2004

    XDEF           _existopts
    XDEF           _tasklist

AllocRaster:     ; d0->width, d1->height
              MOVEM.L        D5/D6/A6,-(A7)
              MOVE.L         PExecBase(pc),A6
              MOVE.L         D1,D6
              MOVEQ          #$f,D1         ;bytesize=RASSIZE(width,height)
              ADD.W          D1,D0          ;
              ASR.W          #3,D0          ;
              ANDI.W         #$fffe,D0      ;
              MULU.W         D0,D6          ;d6 contains bytesize
              MOVEQ.L        #0,D5
              move.l         ThisTask(a6),a0
              tst.l          pr_CLI(a0)  ; cli processes alloc to chip
               bne.b          AllocRasterChip
              TST.W          _existopts(pc)
              BEQ.B          AllocRasterFast           ; if there are no prefs then alloc to fast memory
tasklistscan:
              MOVE.L         _tasklist(pc),A0       ;a0->char *inbuffer
              LEA            namebuffer(pc),A1  ;a1->char *outbuffer
              moveq          #0,d1
              BSR.b          ReadTaskName
nextname:
              JSR            _LVOFindTask(A6)
              CMP.L          ThisTask(a6),d0                    ;(taskname==thistask)
              BEQ.B          AllocRasterChip
              tst.w          d5
              bne.b tasklistscan
AllocRasterFast: MOVE.L         D6,D0
              MOVEQ          #MEMF_FAST|MEMF_PUBLIC,D1
              jsr _LVOAllocMem(a6)
              movem.l (a7)+,d5/d6/a6
            rts

AllocRasterChip: MOVE.L         D6,D0
              MOVEQ          #MEMF_CHIP|MEMF_PUBLIC,D1
              JSR            _LVOAllocMem(A6)
              MOVEM.L        (A7)+,D5/D6/A6
              RTS

ReadTaskName:  ;a1 -> outbuffer, a0 -> inbuffer
              MOVE.B         (A0,D5.L),(A1,D1.L)  ;outbuffer[conta]=inbuffer[i]
              ADDQ.w         #1,D1                   ;conta++
              ADDQ.w         #1,D5                   ;i++
ReadTaskName3:
              MOVE.B         (A0,D5.L),D0
              CMP.B          #'\n',D0                 ;(inbuffer[i] != '\n')
              BEQ.B          exitwhile
              TST.B          D0                    ;(inbuffer[i] != '\0')
              BNE.B          ReadTaskName
exitwhile:
              CLR.B          (A1,D1.L)              ;outbuffer[conta]='\0'
              TST.B          (A0,D5.L)              ;(inbuffer[i])
              BEQ.B          finelista
              ADDQ.w         #1,D5                   ;return(i+1)
              rts

finelista:                                      ;return(0)
              MOVEQ          #0,D5
              RTS

namebuffer: ds.b 32   ;task name longer than 32 chars does not work


_existopts:    dc.w     0

 cnop 0,4

_tasklist:    dc.l      0
              

