Newer
Older
uBix-Retro / dump / oa-2.0.9 / oldlib / zmem.a65
/****************************************************************************
   
    OS/A65 Version 2.0.0
    Multitasking Operating System for 6502 Computers

    Copyright (C) 1989-1998 Andre Fachat 

    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., 675 Mass Ave, Cambridge, MA 02139, USA.

****************************************************************************/

	.(

	.data
zmem	.dsb 64		; each four byte have an owner
	.text

/*
 * yr = first available zeropage address 
 */

+zinit	.(
	php
	sei
	lda #<-1	; all in use
	tax
	inx
l0	sta zmem,x
	inx
	cpx #64
	bcc l0

	tya
	clc
	adc #3
	lsr
	lsr
	tay
	
	lda #0		; free
l1	sta zmem,y
	iny
	cpy #64
	bcc l1

	plp
	clc
	rts
	.)


/*
 * a = length of needed zeropage area in byte
 * returns a= address of zeropage area with c=0
 * or c=1 when no area found
 *
 */
&zalloc	.(
	clc
	adc #3
	lsr
	lsr

	tay
	jsr GETPID
	inx
	txa
	pha
	tya

	sei
	ldy #0
l1
	pha
	tax
l2
	lda zmem,y
	bne notfree
	dex
	beq found
	iny 
	cpy #64
	bcc l2
	pla
	pla
	cli
	rts

notfree	iny
	pla
	cpy #64
	bcc l1
	pla
	cli
	rts

found
	pla
	tax
	pla
	iny
l3
	dey
	sta zmem,y
	dex
	bne l3

	tya
	asl
	asl
	clc
	cli
	rts
	.)

/*
 * a = address of area to free. All consecutive zeropage addresses
 * belonging to this task from a on are free'd.
 */
&zfree	.(
	clc
	adc #3
	lsr
	lsr
	tay
	jsr GETPID
	inx
	sei
l0	txa
	cmp zmem,y
	bne ende
	lda #0
	sta zmem,y
	iny
	cpy #64
	bcc l0
ende
	clc
	cli
	rts
	.)

	.)