
*
*   c2p1.s - "c2p" for the simple bitplane MacIntosh mode
*   Copyright (C) 1997 Aki Laukkanen
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation; either version 2 of the License, or
*   (at your option) any later version.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with this program; if not, write to the Free Software Foundation,
*   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*

	include "exec/types.i"
	include "lvo/exec_lib.i"
	include "mmu.i"
	include "evd_context.i"

	XDEF    _c2p1
	XDEF    @c2p1
	XDEF    _c2p1_reloc
	XDEF    @c2p1_reloc
	XDEF    _c2p1_deinit
	XDEF    @c2p1_deinit

	cnop    0,16

; relocation not needed

_c2p1_reloc
@c2p1_reloc
	lea     (_c2p1,pc),a0
	move.l  a0,d0
	rts

	cnop    0,16

; nothing to free

_c2p1_deinit
@c2p1_deinit
	rts

	cnop    0,16

; basically we copy only the changed longs

_c2p1
@c2p1
	movem.l d7/a2-a6,-(sp)
	move.l  (ct_ChunkyBuffer,a0),a1
	move.l  a1,a2
	add.l   (ct_Size,a0),a2
	move.l  (ct_DeltaBuffer,a0),a3
	move.l  (ct_PageDesc,a0),a4
	move.l  (bm_Planes+ct_BitMap,a0),a0
	move.l  #4096,d7
	move.l  a1,a5
.loop
	add.l   d7,a5
	cmp.l   a2,a5
	bls     .skip_move
	move.l  a2,a5
.skip_move
	move.l  (a4)+,a6
	move.l  (a6),d0
	btst    #PDB_M,d0
	bne     .skip
	adda.l  d7,a1
	adda.l  d7,a0
	adda.l  d7,a3
	cmp.l   a2,a1
	bcs     .loop
	movem.l (sp)+,d7/a2-a6
	rts
	cnop    0,16
.skip
	bclr    #PDB_M,d0
	move.l  d0,(a6)
.iloop
	cmp.l   (a1)+,(a3)+
	beq.s   .ohi
	move.l  (-4,a1),(-4,a3)
	move.l  (-4,a1),(a0)
.ohi
	addq.l  #4,a0
	cmp.l   a5,a1
	bcs     .iloop
	cmp.l   a2,a1
	bcs     .loop
	movem.l (sp)+,d7/a2-a6
	rts
