Return-Path: <gooseman@on.ON-Luebeck.DE>
Received: from on.ON-Luebeck.DE (on.ON-Luebeck.DE [193.29.188.2])
          by hugin.oden.se (8.8.4/8.8.4) with ESMTP
	  id PAA05311 for <dlanor@oden.se>; Sun, 29 Dec 1996 15:21:31 +0100
Received: (from majordomo@localhost)
          by on.ON-Luebeck.DE (8.8.4/8.8.4)
	  id OAA22439 for stik-outgoing; Sun, 29 Dec 1996 14:52:58 +0100
Date: Sun, 29 Dec 1996 14:52:19 +0100
Message-Id: <199612291352.OAA18986@mail.kd.qd.se>
To: <stik@on-luebeck.de>
Subject: STIK: The New STiK
From: Christian Andersson <faltrion@mail.kd.qd.se>
X-Mailer: Ant-Mail Version 0.7.9 (Atari) 
Sender: stik@on-luebeck.de
Precedence: bulk
Reply-To: stik@on-luebeck.de
X-UIDL: 1d0840acd57fb45e733d74432c838a89


Hi all! I recently came across this little peace of code on ftp.cnam.fr
nad according to the 0n0.txt (index file of Cnam with the newewst files 
only) this source somehow gives the program an ability to use threads (On a 
Sibgle-Tasking enviroment with a 68000 Processor)
If this is true, AND it is FAST could this be something to be used with STiK
it would I think solve some of the things that the g_ calls was used to.

Anyway, here it is! :) there is Little Comments in this, and those that are
are In French.


	OPT	O+

	 SECTION TEXT

	MOVE.L	A7,A5
	MOVE.L	4(A5),A5
	MOVE.L	$C(A5),D0
	ADD.L	$14(A5),D0
	ADD.L	$1C(A5),D0
	ADD.L	#$1000,D0
	MOVE.L	D0,-(SP)
	MOVE.L	A5,-(SP)
	CLR.W	-(SP)
	MOVE.W	#$4A,-(SP)
	TRAP	#1
	LEA	12(SP),SP
	TST.W	D0
	BNE.S	INIT_ERROR
	
	CLR.L	-(SP)
	MOVE.W	#32,-(SP)
	TRAP	#1
	ADDQ.L	#6,SP
	MOVE.L	D0,-(SP)

	BSR	T_INSTALL

	LEA	TEST,A0
	BSR	T_ADD

KK1:	BSR	T_SCHEDULE
	CMPI.B	#$39,$fffffc02.w
	BNE.S	KK1
KK2:	CMPI.B	#$39+$80,$fffffc02.w
	BNE.S	KK2

	BSR	T_REMOVE

	MOVE.W	#32,-(SP)
	TRAP	#1
	ADDQ.L	#6,SP

INIT_ERROR:	CLR.W	-(SP)
	TRAP	#1

	RTS

TEST:	MOVE.W	#7,D0
..TEST_B:	MOVE.W	D0,-(SP)

	MOVE.L	#TEXT,D0
	BSR	PRINT
	
	LEA	TEST1,A0
	BSR	T_ADD

	LEA	TEST2,A0
	BSR	T_ADD

	LEA	TEST3,A0
	BSR	T_ADD

	MOVE.W	(SP)+,D0
	DBRA.W	D0,.TEST_B
	RTS


TEST1:	MOVE.L	#TEXT1,D0
	BSR	PRINT
	RTS

TEST2:	MOVE.L	#TEXT2,D0
	BSR	PRINT
	RTS

TEST3:	MOVE.L	#TEXT3,D0
	BSR	PRINT
	RTS

*******************************************************************************
* SI VOUS UTILISER CES CODES POUR UN PROGRAMME, PRECISEZ-LE DANS LA
* DOCUMENTATION ET DANS L'EXECUTABLE.
* ET SURTOUT CONTACTER-MOI:
*   Simon  VOLANT
*  2, rue de Mƒcon
*    51100 REIMS
*******************************************************************************

*******************************************************************************
*
* MK68 (MICRO-KERNEL 68000) LE MULTITACHE SUR 68000!!!
* (C)1996 SIMON VOLANT
*
* PARTIE NOYAU:
* TOUT POUR FAIRE DU MULTITACHE SUR 68000.
* ATTENTION AVEC L'UTILISATION DES APPELS SYSTEMS (TRAP #1).
* LE TOS N'EST PAS FAIT POUR TOURNER EN MULTI-THREAD.
*
* STRUCTURE DE LA ZONE THREAD:
******************************
* NOM    * OFFSET  * TAILLE * DESCRIPTION
* STACK  *       0 *      4 * POINTEUR DE PILE SP
* KILL   *       4 *      2 * ON DETRUIT LE THREAD LORSQUE KILL EST NEGATIF.
*******************************************************************************
STACK	EQU	0
KILL	EQU	4
MAX_THREAD	EQU	64+1
LOF_THREAD	EQU	1024
KILL_IT	EQU	-1
* TO SCHEDULE:	TRAP	#8
*******************************************************************************
***** INSTALLATION DU NOYAU MULTITACHE
***** TIMER A POUR GERER LA PERMUTATION DES TACHES
***** TRAP #8 POUR PROVOQUER LE SCHEDULER
T_INSTALL:
	PEA	TXT_INSTALL
	MOVE.W	#9,-(SP)
	TRAP	#1
	ADDQ.L	#6,SP
* ON RESERVE DE LA MEMOIRE POUR LE THREAD NUMERO 1:
* IL SE CREE LUI-MEME
	PEA	LOF_THREAD.L
	MOVE.W	#$48,-(SP)
	TRAP	#1
	ADDQ.L	#6,SP
	LEA	P_LIST,A0
	MOVE.L	D0,(A0)
	MOVE.L	#P_LIST,E_LIST
* ON INSTALLE LE TIMER A ET LA TRAP #8
* VOUS POUVEZ VOUS-MEME VARIER LA FREQUENCE
	MOVE.W	#$2700,SR
	MOVE.L	#SCHEDULER,$0A0.W
	MOVE.L	#SCHEDULER,$134.W
	BSET	#5,$FFFFFA07.W
	BSET	#5,$FFFFFA13.W
	MOVE.B	#0,$FFFFFA1F.W
	MOVE.B	#7,$FFFFFA19.W
* ON CONTINUE A CREER LE THREAD PERE
	MOVE.L	(SP)+,A1
	MOVE.L	SP,EX_SP
	MOVE.L	E_LIST,A0
	MOVE.L	(A0),A0
	LEA	LOF_THREAD(A0),SP
	CLR.W	KILL(A0)
	MOVE.L	A1,-(SP)
	MOVE.W	#-1,MUSTEK
	MOVE.W	#$2300,SR
* A PARTIR D'ICI, LE PROGRAMME PEUT-ETRE PREEMPTE!!!
	RTS
TXT_INSTALL:	DC.B	"ALIVE! MK68 IS ALIVE!",13,10,0
	EVEN
*******************************************************************************
***** DESINITIALISATION
T_REMOVE:
	MOVE.W	#$2700,SR
* ON STOPPE LE TIMER A
	BCLR	#5,$FFFFFA07.W
	BCLR	#5,$FFFFFA13.W
	MOVE.B	#0,$FFFFFA19.W
	MOVE.B	#0,$FFFFFA1F.W
* ON REINSTALLE L'ANCIENNE PILE
	MOVE.L	(SP)+,A1
	MOVE.L	EX_SP,SP
	MOVE.L	A1,-(SP)
	MOVE.W	#$2300,SR
	PEA	TXT_REMOVE
	MOVE.W	#9,-(SP)
	TRAP	#1
	ADDQ.L	#6,SP
	RTS
TXT_REMOVE:	DC.B	"DEAD! MK68 IS DEAD!",13,10,0
	EVEN
*******************************************************************************
***** INTERRUPT LE SCHEDULER EN LUI-MEME
SCHEDULER:	NOT.L	$FFFF9800.W
	CLR.B	$FFFFFA19.W
* LE THREAD REFUSE DE SE FAIRE INTERROMPRE
	TST.W	MUSTEK
	BEQ.S	.FIN1
* ON SAUVE LE PROCESSUS
..NORMAL:	MOVEM.L	D0-A7,-(SP)
	MOVE.L	E_LIST,A0
	MOVE.L	A0,A1
	MOVE.L	(A1),A1
	MOVE.L	SP,(A1)
* ON PREND LE SUIVANT SUR LA LISTE
..NEXT1:	ADDQ.L	#4,A0
..RETEST:	TST.L	(A0)
	BNE.S	.CONT1
	LEA	P_LIST,A0
* ON TESTE SI ON DOIT LE TUER:
* SUICIDE OU MEUTRE
..CONT1:	MOVE.L	(A0),A1
	TST.W	KILL(A1)
	BPL.S	.CONT2
* SUICIDE OU MEUTRE
..KILL_IT:	MOVE.L	A0,A1
..NEXT2:	ADDQ.L	#4,A1	* ON REMPLACE LA TACHE A TUER
	TST.L	(A1)	* PAR LA DERNIERE DE LA LISTE
	BNE.S	.NEXT2	* OU LE NULL DE FIN DE LISTE
	SUBQ.L	#4,A1
	CLR.L	(A0)
	MOVE.L	(A1),(A0)
	CLR.L	(A1)
	BRA.S	.RETEST
* ICI, ON LANCE LE NOUVEAU PROCESSUS
..CONT2:	MOVE.L	A0,E_LIST
	MOVE.L	(A0),A0
	MOVE.L	(A0),SP
	MOVEM.L	(SP)+,D0-A7
..FIN1:	BTST	#3,$FFFFFA17.W
	BEQ.S	.CT
	MOVE.B	#%11011111,$FFFFFA0F.W
..CT:	NOT.L	$FFFF9800.W
	MOVE.B	#7,$FFFFFA19.W
	RTE
*******************************************************************************
***** INSTALLER UN NOUVEAU THREAD
* ENTREE: A0 QUI CONTIENT LE POINTEUR SUR LE CODE A EXECUTER PC
* SORTIE: D0 ADRESSE DE LA ZONE DE DONNEES INTERNE
* LORS DE LA RENCONTRE DU RTS, LE PROCESSUS SE SUICIDE
T_ADD:	MOVE.L	A0,A6
* ON ALLOUE DE LA MEMOIRE
	MOVE.L	#LOF_THREAD,D0
	BSR	MALLOC
	MOVE.L	D0,D6
* ON COUPE TOUTE LES ITS
	MOVE.W	MUSTEK,-(SP)
	CLR.W	MUSTEK
* ON AJOUTE LA STRUCTURE A LA LISTE
	LEA	P_LIST,A0
..RETRY:	TST.L	(A0)+
	BNE.S	.RETRY
	SUBQ.L	#4,A0
	MOVE.L	D6,(A0)
* ON CREE LA PILE PAR DEFAUT
	ADD.L	#LOF_THREAD,D6
	MOVE.L	D6,A5
	MOVE.L	#T_SUICIDE,-(A5)
	MOVE.W	#0134,-(A5)
	MOVE.L	A6,-(A5)
	MOVE.W	SR,-(A5)
	MOVEM.L	D0-A7,-(A5)
* ON CREE L'ENTETE
	MOVE.L	(A0),A0
	MOVE.L	A5,(A0)	* STOCK STACK
	CLR.W	KILL(A0)	* NO KILL
* ON REMET LE MUSTEK (JETON SYSTEM)
	MOVE.W	(SP)+,MUSTEK
	RTS
*******************************************************************************
***** MEURTRE D'UN THREAD
* ENTREE: A0 ADRESSE DE LA ZONE DE DONNEES INTERNE
T_KILL:	MOVE.W	#KILL_IT,KILL(A0)
	BSR.S	T_SCHEDULE
	RTS
*******************************************************************************
***** SUICIDE D'UN THREAD
T_SUICIDE:	MOVE.L	E_LIST,A0
	MOVE.L	(A0),A0
	MOVE.W	#KILL_IT,KILL(A0)
	BSR.S	T_SCHEDULE
	BRA.S	T_SUICIDE
*******************************************************************************
***** ON PROVOQUE LA PREEMPTION (PAS BESOIN DE PRENDRE PLUS DE CPU)
T_SCHEDULE:	TRAP	#8
	RTS
*******************************************************************************


*******************************************************************************
*
* MK68 (MICRO-KERNEL 68000) LE MULTITACHE SUR 68000!!!
* (C)1996 SIMON VOLANT
*
* PARTIE INTERFACE SYSTEM:
* PERMET DE GERER LES APPELS AVEC LE TOS.
* A UTILISER LORSQUE MK68 EST ACTIF!!!!
*
*******************************************************************************
* PRISE DU JETON
* ON MONOPOLISE LE CPU  (POUR PAS QUE QUELQU'UN D'AUTRE NE LE PRENDRE
* ENTRE 2 TESTS). QUE L'ON PEUT RENDRE ENSUITE.
GET_MSYS:	CLR.W	MUSTEK
	TST.W	M_SYSTEM
	BNE.S	.GET_IT
	MOVE.W	#-1,MUSTEK
	BSR.S	T_SCHEDULE
	BRA.S	GET_MSYS
..GET_IT:	CLR.W	M_SYSTEM
	MOVE.W	#-1,MUSTEK
	RTS
*******************************************************************************
* RENDRE LE JETON
PUT_MSYS:	MOVE.W	#-1,M_SYSTEM
	RTS
*******************************************************************************
* FONCTION MALLOC
* D0: NOMBRE D'OCTETS A RESERVER
* INTERFACE AVEC LE SYSTEM
MALLOC:	BSR.S	GET_MSYS
	MOVE.L	D0,-(SP)
	MOVE.W	#$48,-(SP)
	TRAP	#1
	ADDQ.L	#6,SP
	BSR.S	PUT_MSYS
	*BSR.S	T_SCHEDULE
	RTS
*******************************************************************************
* FONCTION PRINT
* D0: TEXT A IMPRIMER
* INTERFACE AVEC LE SYSTEM
PRINT:	BSR.S	GET_MSYS
	MOVE.L	D0,-(SP)
	MOVE.W	#$9,-(SP)
	TRAP	#1
	ADDQ.L	#6,SP
	BSR.S	PUT_MSYS
	BSR.S	T_SCHEDULE
	RTS
*******************************************************************************
* FONCTION WAIT_A_KEY
* INTERFACE AVEC LE SYSTEM
WAIT_A_KEY:	BSR.S	GET_MSYS
	MOVE.W	#7,-(SP)
	TRAP	#1
	ADDQ.L	#2,SP
	BSR.S	PUT_MSYS
	BSR.S	T_SCHEDULE
	RTS
*******************************************************************************
M_SYSTEM:	DC.W	-1
*******************************************************************************


	 SECTION DATA
TEXT1:	DC.B	"1",13,10,0
	EVEN
TEXT2:	DC.B	"2",13,10,0
	EVEN
TEXT3:	DC.B	"3",13,10,0
	EVEN
TEXT:	DC.B	" 5 THREADS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",13,10,0
	EVEN

	 SECTION BSS
EX_SP:	DS.L	1
MUSTEK:	DS.W	1
E_LIST:	DS.L	1
P_LIST:	DS.L	MAX_THREAD
	EVEN
-- 
Christian Andersson              FireSTorm Atari Center
MAIL: faltrion@mail.kd.qd.se     WWW: http://www.kd.qd.se/~faltrion
IRC : faltrion @ #Atari          Current Projects:
BBS : +46 54 834731              - FireNews: News-reader for STIK
FAX : +46 45 834731              - FireCall: Caller ID utility

.
