[Smipl-devel] SF.net SVN: smipl:[42] smipl-devel/src
Brought to you by:
the_student
From: <the...@us...> - 2009-08-22 11:31:12
|
Revision: 42 http://smipl.svn.sourceforge.net/smipl/?rev=42&view=rev Author: the_student Date: 2009-08-22 11:30:57 +0000 (Sat, 22 Aug 2009) Log Message: ----------- * Added Scheduler * Added ModuleSystem * Some bugs fixed Modified Paths: -------------- smipl-devel/src/Console.h smipl-devel/src/Init.h smipl-devel/src/MDS.h smipl-devel/src/SIA/SIA.h smipl-devel/src/SIA/SIASOUND.h smipl-devel/src/SMIPL-header.h smipl-devel/src/SVM.h Added Paths: ----------- smipl-devel/src/ModuleSystem/ smipl-devel/src/ModuleSystem/modload.cpp smipl-devel/src/Scheduler.h smipl-devel/src/log.h Modified: smipl-devel/src/Console.h =================================================================== --- smipl-devel/src/Console.h 2009-08-16 19:29:42 UTC (rev 41) +++ smipl-devel/src/Console.h 2009-08-22 11:30:57 UTC (rev 42) @@ -21,7 +21,7 @@ if(cmd_is("")) continue; if(cmd_is("QUIT")) break; if(cmd_is("EXIT")) break; - if(cmd_is("DUMP")) {DumpStack();cout<<endl;DumpMDS();continue;} + if(cmd_is("DUMP")) {DumpStack();cout<<endl;DumpMDS();cout<<endl;DumpSearchPath();cout<<endl;DumpRoot();continue;} if(cmd_is("CATALOG")) { if(cmd.argc==1) Catalog("/"); if(cmd.argc>=2) for(a=1;a<cmd.argc;a++) Catalog(cmd.argv[a]); @@ -32,7 +32,9 @@ for(a=0;a<=10000;a++) { cout<<a<<" "; getstr(Program[a], 80); - if(!stricmp(Program[a], "PROGRAM END")) break; + strcpy(cmd.str,Program[a]); + cmd.Split(); + if((!stricmp(cmd.argv[0],"PROGRAM"))&&(stricmp(cmd.argv[0], "END"))) break; } } continue; @@ -54,9 +56,10 @@ str2=strdup(str, "_START"); MDS_Set(str2, Lib_start); for(a=0;a<=10000;a++) { - cout<<a<<" "; if(library_file->getline(Program[a], 80)==0) {strcpy(Program[a], "PROGRAM END");break;} - if(!stricmp(Program[a], "PROGRAM END")) break; + strcpy(cmd.str,Program[a]); + cmd.Split(); + if((!stricmp(cmd.argv[0],"PROGRAM"))&&(stricmp(cmd.argv[0], "END"))) break; } VM0.Run(&Lib_start); delete[]str2; @@ -111,7 +114,10 @@ a=0; do{ *the_file<<Program[a]<<endl; - }while(strcasecmp(Program[a++], "PROGRAM END")); + strcpy(cmd.str,Program[a]); + cmd.Split(); + a++; + }while((strcasecmp(cmd.argv[0], "PROGRAM"))||(strcasecmp(cmd.argv[0], "END"))); cout<<"OK"<<endl; delete[]str; delete the_file; @@ -132,7 +138,10 @@ a=0; do{ the_file->getline(Program[a], 80); - }while(strcmp(Program[a++], "PROGRAM END")); + strcpy(cmd.str,Program[a]); + cmd.Split(); + a++; + }while((strcasecmp(cmd.argv[0], "PROGRAM"))||(strcasecmp(cmd.argv[0], "END"))); cout<<"OK"<<endl; } else cout<<"FAIL"<<endl; Modified: smipl-devel/src/Init.h =================================================================== --- smipl-devel/src/Init.h 2009-08-16 19:29:42 UTC (rev 41) +++ smipl-devel/src/Init.h 2009-08-22 11:30:57 UTC (rev 42) @@ -1,53 +1,54 @@ +void LateInit(void*) { + MDS_Set("/Global/com.smipl.version.major", 3); + MDS_Set("/Global/com.smipl.version.minor", 50); + MDS_Set("/Global/com.smipl.version.patchlevel", 0); + MDS_Set("/Global/com.smipl.mds.version.major", 2); + MDS_Set("/Global/com.smipl.mds.version.minor", 0); + MDS_Set("/Global/com.smipl.mds.version.patchlevel", 0); + MDS_Set("/Global/com.smipl.sia.version.major", 2); + MDS_Set("/Global/com.smipl.sia.version.minor", 0); + MDS_Set("/Global/com.smipl.sia.version.patchlevel", 0); + MDS_Set("/Global/com.smipl.siasound.version.major", 2); + MDS_Set("/Global/com.smipl.siasound.version.minor", 0); + MDS_Set("/Global/com.smipl.siasound.version.patchlevel", 0); + MDS_Set("/Global/com.smipl.fs.version.major", 2); + MDS_Set("/Global/com.smipl.fs.version.minor", 0); + MDS_Set("/Global/com.smipl.fs.version.patchlevel", 0); + MDS_Set("/Global/compiler.isGCC", false); + #ifdef __GNUC__ + MDS_Set("/Global/compiler.isGCC", true); + MDS_Set("/Global/compiler.version.major", __GNUC__); + MDS_Set("/Global/compiler.version.minor", __GNUC_MINOR__); + MDS_Set("/Global/compiler.version.patchlevel",__GNUC_PATCHLEVEL__); + #endif + MDS_Set("/Global/com.smipl.sia.sound.midi.enable",false); + MDS_Set("/Global/com.smipl.sia.sound.midi.inited",false); + #ifdef EnableMIDI + MDS_Set("/Global/com.smipl.sia.sound.midi.enable",true); + #endif + #ifdef AutoInitMIDI + MIDI_Init(); + #endif +} bool Init(int argc, char **argv) { try{ - SetLastSysError(""); - strcpy(Program[0],"PROGRAM END"); - VM0.isVM0=true; - VM0.JailAddress=strdup("/VM0/"); - cout<<"Initializing PhysicsFS"<<endl; - if(!PHYSFS_init(argv[0])) {SetLastSysError((char*)PHYSFS_getLastError());return false;} - cout<<"Initializing FileSystem Structure"<<endl; - if(!FS_init())return false; - - cout<<"Initializing version globals"<<endl; - MDS_Set("/Global/com.smipl.version.major", 3); - MDS_Set("/Global/com.smipl.version.minor", 50); - MDS_Set("/Global/com.smipl.version.patchlevel", 0); - MDS_Set("/Global/com.smipl.mds.version.major", 2); - MDS_Set("/Global/com.smipl.mds.version.minor", 0); - MDS_Set("/Global/com.smipl.mds.version.patchlevel", 0); - MDS_Set("/Global/com.smipl.sia.version.major", 2); - MDS_Set("/Global/com.smipl.sia.version.minor", 0); - MDS_Set("/Global/com.smipl.sia.version.patchlevel", 0); - MDS_Set("/Global/com.smipl.siasound.version.major", 2); - MDS_Set("/Global/com.smipl.siasound.version.minor", 0); - MDS_Set("/Global/com.smipl.siasound.version.patchlevel", 0); - MDS_Set("/Global/com.smipl.fs.version.major", 2); - MDS_Set("/Global/com.smipl.fs.version.minor", 0); - MDS_Set("/Global/com.smipl.fs.version.patchlevel", 0); - - cout<<"Initializing compile-time globals"<<endl; - MDS_Set("/Global/compiler.isGCC", false); - #ifdef __GNUC__ - MDS_Set("/Global/compiler.isGCC", true); - MDS_Set("/Global/compiler.version.major", __GNUC__); - MDS_Set("/Global/compiler.version.minor", __GNUC_MINOR__); - MDS_Set("/Global/compiler.version.patchlevel",__GNUC_PATCHLEVEL__); - #endif - - cout<<"Initing SIASOUND"<<endl; - MDS_Set("/Global/com.smipl.sia.sound.midi.enable",false); - MDS_Set("/Global/com.smipl.sia.sound.midi.inited",false); - #ifdef EnableMIDI - MDS_Set("/Global/com.smipl.sia.sound.midi.enable",true); - #endif - #ifdef AutoInitMIDI - MIDI_Init(); - #endif - } + SetLastSysError(""); + strcpy(Program[0],"PROGRAM END"); + VM0.isVM0=true; + VM0.JailAddress=strdup("/VM0/"); + cout<<"Initializing PhysicsFS"<<endl; + if(!PHYSFS_init(argv[0])) {SetLastSysError((char*)PHYSFS_getLastError());return false;} + cout<<"Initializing FileSystem Structure"<<endl; + if(!FS_init())return false; + #ifndef SMIPL_TaskScheduler + LateInit(NULL); + #else + AddTask(LateInit, NULL, 0); + pthread_create(&Scheduler_task, NULL, Scheduler, NULL); + #endif + } catch(...) {SetLastSysError("EXCEPTION");return false;} - - return true; + return true; } bool DeInit() { if(!PHYSFS_deinit()){SetLastSysError((char*)PHYSFS_getLastError());return false;} Modified: smipl-devel/src/MDS.h =================================================================== --- smipl-devel/src/MDS.h 2009-08-16 19:29:42 UTC (rev 41) +++ smipl-devel/src/MDS.h 2009-08-22 11:30:57 UTC (rev 42) @@ -57,7 +57,7 @@ cout<<"DUMPING MDS..."<<endl; MDS_Piece *current=MDS_0.Next; while(current!=NULL) { - cout<<"\""<<current->Name<<"\":"<<current->Value<<endl; + cout<<"\""<<current->Name<<"\" = "<<current->Value<<endl; current=current->Next; } pthread_mutex_unlock(&MDS); Added: smipl-devel/src/ModuleSystem/modload.cpp =================================================================== --- smipl-devel/src/ModuleSystem/modload.cpp (rev 0) +++ smipl-devel/src/ModuleSystem/modload.cpp 2009-08-22 11:30:57 UTC (rev 42) @@ -0,0 +1,24 @@ +#ifdef system_is_ms_windows +void GetAddress(void* Module, char* funcname, void *func) { + func=(void*)GetProcAddress((HMODULE)Module, (LPSTR)funcname); +} +void OpenModule(char *fn) { + char str[255], str2[255]; + sprintf(str, "/Library/%s/Address"); + sprintf(str2, "%s.dll",fn); + MDS_Set(str, *(value_t*)LoadLibrary(str2)); +} +#endif + +#ifdef system_is_posix +#include <dlfcn.h> +void GetAddress(void* Module, char* funcname, void *func) + *func=(void)*dlsym(handle, funcname); +} +void OpenModule(char*fn) { + char str[255], str2[255]; + sprintf(str, "/Library/%s/Address"); + sprintf(str2, "%s.so",fn); + MDS_Set(str, (double)*dlopen(fn, RTLD_LAZY)); +} +#endif Modified: smipl-devel/src/SIA/SIA.h =================================================================== --- smipl-devel/src/SIA/SIA.h 2009-08-16 19:29:42 UTC (rev 41) +++ smipl-devel/src/SIA/SIA.h 2009-08-22 11:30:57 UTC (rev 42) @@ -4,6 +4,7 @@ void sys_sleep(int time) {usleep(time);} void sys_clearscreen(){system("clear");} #endif + #ifdef system_is_ms_windows #include <windows.h> void sys_sleep(int time) {Sleep(time);} Modified: smipl-devel/src/SIA/SIASOUND.h =================================================================== --- smipl-devel/src/SIA/SIASOUND.h 2009-08-16 19:29:42 UTC (rev 41) +++ smipl-devel/src/SIA/SIASOUND.h 2009-08-22 11:30:57 UTC (rev 42) @@ -26,7 +26,7 @@ void MIDI_Init() { pthread_mutex_lock(&SIA_SOUND); if (midiOutOpen(&MIDI_Out, 0, 0, 0, CALLBACK_NULL) != MMSYSERR_NOERROR) { - printf("Error opening MIDI Output.\n"); + LogWrite("SIASOUND","Error opening MIDI Output"); goto end; } MIDI_OUT_INITED=true; @@ -38,7 +38,7 @@ pthread_mutex_lock(&SIA_SOUND); if(MIDI_OUT_INITED) { if(midiOutShortMsg(MIDI_Out, Melding.word) != MMSYSERR_NOERROR) { - cout<<"MIDI ERROR"<<endl; + LogWrite("SIASOUND", "MIDI ERROR"); } } pthread_mutex_unlock(&SIA_SOUND); Modified: smipl-devel/src/SMIPL-header.h =================================================================== --- smipl-devel/src/SMIPL-header.h 2009-08-16 19:29:42 UTC (rev 41) +++ smipl-devel/src/SMIPL-header.h 2009-08-22 11:30:57 UTC (rev 42) @@ -1,8 +1,8 @@ //C libraries -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <math.h> +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <cmath> //IO streams #include <iostream> #include <fstream> @@ -11,19 +11,29 @@ #include <pthread.h> #include <physfs.h> #include "FS/physfs_stream.cpp" -//SMIPL Core systems + +//SMIPL #define cmd_is(c) !strcasecmp(cmd.argv[0],c) bool Init(int,char**); bool DeInit(); + +//SMIPL Basic Services #include "Config.h" #include "String.h" +#include "Log.h" +#include "Scheduler.h" +#include "Error.h" +#include "FS/FS.h" #include "MDS.h" + +//SMIPL Extended Services #include "SIA/SIA.h" #include "SIA/SIASOUND.h" -#include "Error.h" -#include "FS/FS.h" //SMIPL UI #include "SVM.h" #include "Console.h" + +//SMIPL ModuleLoading +#include "ModuleSystem/modload.cpp" //SMIPL Init #include "Init.h" Modified: smipl-devel/src/SVM.h =================================================================== --- smipl-devel/src/SVM.h 2009-08-16 19:29:42 UTC (rev 41) +++ smipl-devel/src/SVM.h 2009-08-22 11:30:57 UTC (rev 42) @@ -88,7 +88,7 @@ if(cmd_is("NEWLINE")){cout<<endl;continue;} //MIDI if(cmd_is("MIDI")) { - if(!MIDI_OUT_INITED){MIDI_Init();if(!MIDI_OUT_INITED) cout<<"MIDI FAILURE\n";} + if(!MIDI_OUT_INITED){MIDI_Init();if(!MIDI_OUT_INITED) LogWrite("SVM","Unable to initialize MIDI");} MIDI_Melding.data[0] = 0x90; // MIDI note-on message (requires to data bytes) MIDI_Melding.data[1] = 60; // MIDI note-on message: Key number (60 = middle C) MIDI_Melding.data[2] = 100; // MIDI note-on message: Key velocity (100 = loud) @@ -108,6 +108,6 @@ continue; } cout<<"Unknown "<<cmd.argv[0]<<endl; - break; + break; } } Added: smipl-devel/src/Scheduler.h =================================================================== --- smipl-devel/src/Scheduler.h (rev 0) +++ smipl-devel/src/Scheduler.h 2009-08-22 11:30:57 UTC (rev 42) @@ -0,0 +1,50 @@ +pthread_t Scheduler_task; +struct Task{ + void (*func)(void*); + void*arg; + clock_t scheduled_at; + Task* Next; + Task() {scheduled_at=0;Next=NULL;arg=NULL;} + Task(void (func)(void*), void* arg, clock_t at) { + this->func=func; + scheduled_at=at; + this->arg=arg; + Next=NULL; + } +}Task_0; +Task *LastTask() { + Task *Current=&Task_0; + while(Current->Next!=NULL) Current=Current->Next; + return Current; +} +void AddTask(void (*func)(void*), void *args, clock_t scheduled_in) { + LastTask()->Next=new Task(func, args, scheduled_in+clock()); +} +void RemoveTask(Task* removethis) { + Task *Current=&Task_0, *Previous=&Task_0; + while(Current!=removethis) { + Previous=Current; + Current=Current->Next; + } + Previous->Next=Current->Next; + delete Current; +} +void* Scheduler(void*) { + clock_t current_clock; + for(;;) { + current_clock=clock(); + Task* Current=&Task_0; + while(1) { + Task*Next=Current->Next; + if(Current!=&Task_0) { + if(Current->scheduled_at<=current_clock) { + Current->func(Current->arg); + RemoveTask(Current); + } + + } + if(Next!=NULL) Current=Next; + else break; + } + } +} Added: smipl-devel/src/log.h =================================================================== --- smipl-devel/src/log.h (rev 0) +++ smipl-devel/src/log.h 2009-08-22 11:30:57 UTC (rev 42) @@ -0,0 +1 @@ +void LogWrite(char*,char*){ }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |