DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦bd949a861⟧ TextFile

    Length: 2698 (0xa8a)
    Types: TextFile
    Notes: UNIX file
    Names: »dopen.c«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦2d53db1df⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »hr/src/desk/dopen.c« 

TextFile

#include "desk.h"

uint	dskHptop;			/* 1st free word of heap	*/
uint	dskHeap[HEAP];			/* the heap itself		*/

/*
**   D_Open(r) -
**
**	Open a "window" on the screen within the given physical rectangle.
**	The underlying bitmap is saved on the heap and the rectangle is cleared.
**	Nothing is opened if the heap is too full.
**
**	Exit: -1, if bad, else old top-of-heap marker
*/
int D_Open(r)
RECT *r;
{
	register uint	*sip, *dip;
	register uint	trx;
	register uint	rx, ry;
	uint	sx, n;

	sx = words_between(XMIN, XMAX);
	rx = words_between(r->origin.x, r->corner.x);
	ry = r->corner.y - r->origin.y;
	n  = rx*ry;
	if ( !n )
		return dskHptop;
	if ( HEAP - dskHptop < n )
	{
		printf("OUT OF HEAP\n");
		return -1;
	}

	/* Turn mouse off */
#ifdef DEBUG
printf("D_OPEN:\trect (%d,%d)(%d,%d), dskHptop %d, wwide %d, wdown %d\n",*r, dskHptop, rx, ry);
#endif
	ioctl(myfd, CIOMSEOFF);

	/*
	 *	Save the bitmap
	 */
	dip = &dskHeap[dskHptop];
	if ( r->origin.y >= YSPLIT )
		sip = addptr(SEG1, (r->origin.y - YSPLIT) * sx * sizeof(int));
	else
		sip = addptr(SEG0, r->origin.y * sx * sizeof(int));
	sip = addptr(sip, r->origin.x >> SBPW << 1);
	while ( ry-- )
	{
#ifdef DEBUG
printf("\tscr 0x%lx, hp 0x%lx\n", sip, dip);
#endif
		for ( trx=rx ; trx ; trx-- )
		{
			*dip++ = *sip;
			sip = addptr(sip, sizeof(int));
		}
		sip = addptr(sip, (sx - rx) * sizeof(int));
	}

	ClearRect(r);

	/* Turn the mouse back on */
	ioctl(myfd, CIOMSEON);

	/*
	 *	Adjust new top of heap marker.
	 *	Return old marker.
	 */
	trx = dskHptop;
	dskHptop += n;
	return (trx);
}


/*
**  D_Close(r, oheap) -
**
**	Restore the old bitmap to rectangle *r. The old bitmap is
**	saved at index "oheap" on the heap.  The heap is pooped to
**	this level afterward.
*/
D_Close(r, oheap)
RECT	*r;
int	oheap;
{
	register int	*sip, *dip;
	register int	trx;
	register int	dx, rx, ry;

	dskHptop = oheap;
	dx = words_between(XMIN, XMAX);
	rx = words_between(r->origin.x, r->corner.x);
	ry = r->corner.y - r->origin.y;
	if ( !rx || !ry )
		return;

	/* Turn mouse off */
#ifdef DEBUG
printf("D_CLOSE:\trect (%d,%d)(%d,%d), oheap %d\n", *r, oheap);
#endif
	ioctl(myfd, CIOMSEOFF, NULL);

	/*
	 *	Restore the bitmap
	 */
	sip = &dskHeap[dskHptop];
	if ( r->origin.y >= YSPLIT )
		dip = addptr(SEG1, (r->origin.y - YSPLIT) * dx * sizeof(int));
	else
		dip = addptr(SEG0, r->origin.y * dx * sizeof(int));
	dip = addptr(dip, r->origin.x >> SBPW << 1);
	while ( ry-- )
	{
#ifdef DEBUG
printf("\tscr 0x%lx, hp 0x%lx\n", dip, sip);
#endif
		for ( trx=rx ; trx ; trx-- )
		{
			*dip = *sip++;
			dip = addptr(dip, sizeof(int));
		}
		dip = addptr(dip, (dx - rx) * sizeof(int));
	}

	/* Turn the mouse back on */
	ioctl(myfd, CIOMSEON, NULL);
}