

*-------+++++++ PPC c2p for RTG Master !!!! +++++++-------*
*--------++++++   written by Marcus Tobias  ++++++--------*
*---------+++++    orig c2p by Sam Jordan   +++++---------*
*----------++++       and James McCoull     ++++----------*


;Source for StormC/PowerASM/PhxAss

         include    graphics/gfx.i
         include    rtgmaster/rtgc2p.i
         include    rtgmaster/rtgAMI.i
         include    powerpc/powerpc.i
         include    powerpc_lib.i
         include    exec_lib.i

         xref       _LinkerDB
         xref       ChunkyToPlanar_PPC
         xdef       HiddenBitmap
         xdef       ChunkyBuffer
         xdef       AreaHeight
         xdef       AreaWidth

         xdef       _PowerPCBase


        section  "68k setup",code
        near    a4,-1
        near    code
        mc68020


        XDEF _main
_main
        moveq   #0,d0               ;Header for RTGMaster
        RTS
.s      dc.l    "c2p!"
        dc.l    .s
        dc.l    1
        dc.l    C2pStruct           ;c2p Data (struct c2p_Info* C2pStruct)

;STRUCTURE c2p_Info,0
;     WORD    CI_ColorDepth           ;CI_256, CI_128, CI_64, CI_EHB, CI_32..
;     WORD    CI_CPU                  ;CI_68060, CI_68040, CI_68030....
;     WORD    CI_Needs                ;CI_Aikiko, CI_MMU, CI_FPU...
;     BYTE    CI_Dirty                ;TRUE/FALSE
;     BYTE    CI_Hack                 ;TRUE/FALSE
;     ULONG   CI_PixelSize            ;c2p_1x1...
;     WORD    CI_WidthAlign           ;Width has to be divisible by <number>
;     WORD    CI_HeightAlign          ;Height has to be divisible by <number>
;     WORD    CI_Misc                 ;Different stuff...
;     ULONG   CI_AmiCompatible        ;Is this compatible to RtgScreenAMI ?
;     APTR    CI_Description          ;Pointer to a string
;     APTR    CI_Initialization       ;Pointer to Initialization code
;     APTR    CI_Expunge              ;Pointer to Expunge code
;     APTR    CI_Normal_c2p           ;Pointer to c2p code
;     APTR    CI_Normal_c2p_InterL    ;Pointer to Interleaved c2p
;     APTR    CI_Scrambled_c2p        ;Pointer to Scrambled c2p
;     APTR    CI_Scrambled_c2p_InterL ;Pointer to Scrambled Interleaved c2p
;     BYTE    CI_Asynchrone           ;TRUE/FALSE
;     LABEL   CI_SIZEOF

C2pStruct
        dc.w    CI_256              ;Only 256 colors supported (RTGMaster will expand if less colors used)
        dc.w    CI_68040|CI_68060   ;PPC only !!!
        dc.w    CI_68040N           ;at least 68040
        dc.b    0                   ;No dirty
        dc.b    0                   ;No hack
        dc.l    c2p_1x1             ;Only 1x1 supported
        dc.w    32                  ;Width must be divideble by 32
        dc.w    1                   ;all Heights are supported
        dc.w    0                   ;No Misc flags
        dc.b    "AMI "              ;AmiCompatible
        dc.l    Description
        dc.l    Init                ;Init Code
        dc.l    Done                ;Done Code
        dc.l    Convert_c2p         ;Normal c2p,no interleaved supported,does not scramble
        dc.l    0
        dc.l    0,0
        dc.b    "en"                ;???? only seen in another c2p


;Init all resources

;D0     <-      TRUE if all ok

Init
        movem.l d1-a6,-(a7)
        lea     _LinkerDB,a4        ;A4 -> main Database
        move.l  #0,$2c(a0)          ;Clear c2p data
        bsr.s   InitLibs            ;Open powerpc.library
        tst.l   d0
        beq.s   .nolibs
.correctexit
        moveq   #0,d0
        bra.s   .exit
.nolibs
        moveq   #-1,d0
.exit
        movem.l (a7)+,d1-a6
        RTS

;Free all resources

Done
        movem.l d1-a6,-(a7)
        lea     _LinkerDB,a4        ;A4 -> main Database
        bsr.s   DoneLibs            ;Close powerpc.library
        moveq   #0,d0
        movem.l (a7)+,d1-a6
        RTS


;a0.l = Pointer to the Chunky Data
;a1.l = Pointer to Bitplane 0
;a2.l = Pointer to a Byte containing the "Dirty" Flag (see below)
;a3.l = Pointer to the RtgScreenAMI structure, to which the c2p should be attached
;a4.l = Pointer to a Rectangle, like defined in include:graphics/gfx.i, which
;       specifies, which region of the display the c2p should handle, or 0, if
;       fullscreen c2p was intended.
;d0.l = c2p Modus (see below)
;d1.l = Planesize : (width*height)/8
;d2.l = An exec signal, for asynchrone c2p

Convert_c2p
        movem.l     d1-a6,-(a7)
        lea         _LinkerDB,a4            ;A4 -> main Database
        move.l      a0,ChunkyBuffer         ;Store Chunkybuffer for PPC
        lea         MyBitmap+bm_Planes,a5   ;Init Bitmap struct (see graphics/gfx.i)
        move.l      a1,(a5)+
        add.l       d1,a1
        move.l      a1,(a5)+
        add.l       d1,a1
        move.l      a1,(a5)+
        add.l       d1,a1
        move.l      a1,(a5)+
        add.l       d1,a1
        move.l      a1,(a5)+
        add.l       d1,a1
        move.l      a1,(a5)+
        add.l       d1,a1
        move.l      a1,(a5)+
        add.l       d1,a1
        move.l      a1,(a5)
        move.l      rsAMI_Height(a3),d0     ;Get Height from RtgScreenAMI
        move.w      d0,AreaHeight           ;Store it for PPC
        move.l      rsAMI_Width(a3),d0      ;Get Width from RtgScreenAMI
        move.w      d0,AreaWidth            ;Store it for PPC
        ;WAITFORPPC                         ;U can try async call (dont work on PPC progs like WarpHeretic !!!)
        RUNPOWERPC  ChunkyToPlanar_PPC;,,PPF_ASYNC ;Never test it !!!!
        moveq       #0,d0
        movem.l     (a7)+,d1-a6
        RTS


;Open the powerpc.library

InitLibs
        move.l  4.w,a6
        lea     PowerPCName,a1
        moveq   #0,d0
        jsr     _LVOOpenLibrary(a6)
        move.l  d0,_PowerPCBase
        RTS

;Close the powerpc.library

DoneLibs
        move.l  4.w,a6
        move.l  _PowerPCBase,d0
        beq.s   .noppc
        move.l  d0,a1
        jsr     _LVOCloseLibrary(a6)
.noppc
        RTS

        section "68k&PPC Data",data

_PowerPCBase
        dc.l    0

ChunkyBuffer
        dc.l    0

AreaHeight
        dc.w    0
AreaWidth
        dc.w    0

HiddenBitmap
        dc.l    MyBitmap
MyBitmap
        dc.w    80,0
        dc.b    0,8
        dc.l    0,0,0,0,0,0,0,0

TestChunky
;        dcb.b   320*256
TestBitmap
;        dcb.b   320*256

*************** STRINGS ***********************

PowerPCName
        dc.b    "powerpc.library",0
Description
        dc.b    "RTGoesWarpOS -> fast 8Bit WarpOS C2P",0

