
; last modified 17 September 2004

FreeRaster: add.w #15,d0
            asr.w #3,d0
            and.w #-2,d0
            mulu d1,d0
            movea.l a0,a1
            movea.l PExecBase(pc),a6
             jsr _LVOFreeMem(a6)
            movea.l PGfxBase(pc),a6
           rts
 cnop 0,4

AllocRaster:     ; d0->width, d1->height
              MOVEM.L        D5/D6/A6,-(A7)
              MOVE.L         PExecBase(pc),A6
              ADD.W          #15,D0         ; bytesize=RASSIZE(width,height)
              ASR.W          #3,D0          ;
              ANDI.W         #-2,D0
              MULU.W         D1,D0
              move.l         d0,d6          ; d6 contains bytesize
              MOVEQ.L        #0,D5
              TST.W          _existopts(pc)
               BEQ.B          AllocRasterFast           ; if there are no prefs then alloc everything to fast memory
              movea.l        ThisTask(a6),a0
              move.l         pr_CLI(a0),d0  ; cli processes can not be identified via LN_NAME
               bne.b         cliprocess ; so use different routine
              movea.l        LN_NAME(a0),a0      ;this task name
              movea.l        processname(pc),a1
              move.l         (a0)+,(a1)+
              move.l         (a0)+,(a1)+
              move.l         (a0)+,(a1)+
              move.l         (a0)+,(a1)+
              move.l         (a0)+,(a1)+
              move.l         (a0)+,(a1)+
              move.l         (a0)+,(a1)+
              move.l         (a0)+,(a1)+
tasklistscan:
              movea.l        _tasklist(pc),A0       ;a0->char *tasklist
              movea.l        namebuffer(pc),A1    ;a1->char *taskname
              moveq          #0,d1
               bsr.w          ReadTaskName
              movea.l        processname(pc),a0
               bsr.b          comparestring
              tst.l          d0
               BEQ.B          AllocRasterChip
              tst.w          d5
               bne.b          tasklistscan
AllocRasterFast: MOVE.L         D6,D0
              MOVEQ          #MEMF_ANY|MEMF_PUBLIC,D1
              jsr _LVOAllocMem(a6)
              movem.l (a7)+,d5/d6/a6
            rts
 cnop 0,4


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

 cnop 0,4

cliprocess:                                       ; BCPL pointer to CommandLineInterface
              asl.l           #2,d0               ; convert to conventional pointer
              movea.l         d0,a0
              move.l          cli_CommandName(a0),d0
              asl.l           #2,d0
              movea.l         d0,a0
              move.b          (a0)+,d0             ;this is the string size
              ext.w           d0
              movea.l         processname(pc),a1
              move.l          (a0)+,(a1)+
              move.l          (a0)+,(a1)+
              move.l          (a0)+,(a1)+
              move.l          (a0)+,(a1)+
              move.l          (a0)+,(a1)+
              move.l          (a0)+,(a1)+
              move.l          (a0)+,(a1)+
              move.l          (a0)+,(a1)+
              movea.l         processname(pc),a1
              clr.b           (a1,d0.w)
             bra.b           tasklistscan
  cnop 0,4
; a0 -> nome del processo , a1 -> nome task nelle prefs
comparecicle: tst.b -1(a0)
            beq.b ok
comparestring: cmp.b (a0)+,(a1)+
             beq.b comparecicle
no:         moveq.l #1,d0
            rts

ok:         moveq.l #0,d0
            rts
   cnop 0,4

ReadTaskName:  ;a1 -> namebuffer, a0 -> tasklist
              MOVE.B         (A0,D5.w),(A1,D1.w)
              ADDQ.w         #1,D1
              ADDQ.w         #1,D5
              MOVE.B         (A0,D5.w),D0
              CMP.B          #10,D0
              BEQ.B          exitwhile
              TST.B          D0
              BNE.B          ReadTaskName
exitwhile:
              CLR.B          (A1,D1.w)
              TST.B          d0
              BEQ.B          finelista
              ADDQ.w         #1,D5
              rts
 cnop 0,4


finelista:
              MOVEQ          #0,D5
              RTS
 cnop 0,4


namebuffer: dc.l 0   ;task name longer than 32 chars does not work
processname:    dc.l 0
_tasklist:    dc.l      0

_existopts:    dc.w     0



