WikiPendium :: RecentChanges :: RecentlyCommented :: UserSettings :: You are

TSR Programs

(Terminate and Stay Resident)

Terminate and Stay Resident programs are standard programs that use the special Ptermres() system function when returning to the calling process. This way, they have some part of their code and data that camps in memory and can never be freed again.

TSR programs are very usefull on Atari to hook system calls, implement device drivers or do background jobs (hooking an interrupt vectors such as the VBL?). All TSR programs must put a cookie of their own in the CookieJar to let everyone know they are present. This makes their task easyer when in the need of controlling if they haven't already been launched (indeed, there is no point in hooking an interupt vectors twice, and that applies to most TSR programs).

Example source file


	move.l	4(sp),a0	; Read basepage pointer
	move.l	#256,d0		; Length of basepage
	add.l	12(a0),d0	; Add TEXT length
	add.l	20(a0),d0	; Add DATA length
	add.l	28(a0),d0	; Add BSS length
	move.l	d0,resident_length

	lea	stack,sp	; Set our stack pointer

	; Do whatever initialization stuff needed, then go to init_tsr_ok (if all is ok) or init_tsr_error (if any error)

	; Call Ptermres() to protect our program memory
	clr.w	-(sp)
	move.l	resident_length,-(sp)
	move.w	#49,-(sp)
	trap	#1

	; Should never go there
	bra.s	neverending_loop

	; Any error, quit program as usual
	clr.w	-(sp)	; Pterm()
	trap	#1

resident_length:	ds.l	1

	ds.l	1024
stack:	ds.l	1


See Also

the CookieJar section, and the CookieReference?

Il n'y a pas de commentaire sur cette page. [Afficher commentaires/formulaire]