Anyway, if anyone can tell me if this little program I wrote this afternoon is anything like the very first step in my plan should look like, I'd appreciate it. But I'd appreciate it even more if a few nudges into the right direction could be provided!
Code: Select all
/*
* A simple attempt at having a process running alongside another.
* What I'm working towards is a kernel that runs a 'program' (whether
* the 'program' is coded into the same executable or not) and accepts
* interrupts back.
*
* by Mark Tuson, 18 January 2010.
*/
#include <stdio.h>
#include <math.h>
/*
* 'a' - 'i' are like core, that's why they're global.
*/
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
int g = 0;
int h = 0;
int i = 0;
/*
* 'interrupt' is sort of like an interrupt. It's an array beacuse it makes
* sense that way.
*/
int interrupt [3];
/*
* the jobs.
*/
int job1();
int job2();
int job3();
/*
* Probably the closest thing to a kernel I've ever written, though
* I'm pretty certain it doesn't resemble one in any way at all.
*
* The 'interrupt' that is generally given back is 0, but if it's
* 1, then that job is not done any more; it's aldready finished.
*/
int main() {
for (;;) {
if (interrupt [1] != 1) {
job1(); }
if (interrupt [2] != 1) {
job2(); }
if (interrupt [3] != 1) {
job3(); } }
return 0;}
/*
* A simple job that counts from 10 to 20 and finishes when the result is 20.
*/
int job1() {
if (a == 0) {
a = 1;
b = 10;
c = 1; }
b = (b + c);
printf(" job 1: %d\n",b);
if (b == 20) {
interrupt [1] = 1;
printf("\n\n job 1 finished.\n\n"); }
return interrupt [1]; }
/*
* A simple job that counts down in 10s from 200, to 0. When the results is
* 0, it ends.
*/
int job2() {
if (d == 0) {
d = 2;
e = 200;
f = 10; }
e = (e - f);
printf(" job 2: %d\n",e);
if (e == 0) {
interrupt [2] = 1;
printf("\n\n job 2 finished.\n\n"); }
return interrupt [2]; }
/*
* A simple job that doubles the previous number (starting with 2) until
* the answer is 65536.
*/
int job3() {
if (g == 0) {
g = 1;
h = 2;
i = 2; }
h = (h * i);
printf(" job 3: %d\n",h);
if (h == 65536) {
interrupt [3] = 1;
printf("\n\n job 3 finished.\n\n"); }
return interrupt [3]; }