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

Copyright (C) 2003-2004
Hirohisa MORI <joshua@nichibun.ac.jp>
Tomohito Nakajima <nakajima@zeta.co.jp>

This program is free software; you can redistribute it
and/or modify it under the terms of the GLOBALBASE
Library General Public License (G-LGPL) as published by

http://www.globalbase.org/

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.

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

#include "machine/gb_windows.h"
#include "machine/msequence.h"
#include "pri_level.h"
#include "task.h"

#include	<stdio.h>

extern MS_INFO *order_ms;

void new_v_loop()
{
	static int debug=0;
	
	MSG msg;
	while(TRUE){
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
			if(msg.message == WM_QUIT)
				break;
			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}
		else{
			/* If nothing to do ordinary task, pickup and execute function put by ms_loop */
			if(order_ms){
				order_ms->result = (*order_ms->func)(order_ms->arg);
				order_ms = NULL;
				wakeup_task((unsigned int)&user_interface_task_id);
			}
		}
	}
}

void v_loop(){
	create_task(ms_loop, 0, PRI_USER_INTERFACE);
	new_v_loop();
}

