int bwputx( int channel, char c ) {
	char chh, chl;

	chh = c2x( c / 16 );
	chl = c2x( c % 16 );
	bwputc( channel, chh );
	return bwputc( channel, chl );
}
void bwputw( int channel, int n, char fc, char *bf ) {
	char ch;
	char *p = bf;

	while( *p++ && n > 0 ) n--;
	while( n-- > 0 ) bwputc( channel, fc );
	while( ( ch = *bf++ ) ) bwputc( channel, ch );
}
Beispiel #3
0
/* Format function for bwprintf */
void 
bwformat ( const char *fmt, va_list va ) {
    char bf[12];
    char ch, lz;
    int w;

	
    while ( ( ch = *(fmt++) ) ) {
	if ( ch != '%' )
	    bwputc( ch );
	else {
	    lz = 0; w = 0;
	    ch = *(fmt++);
	    switch ( ch ) {
	    case '0':
		lz = 1; ch = *(fmt++);
		break;
	    case '1':
	    case '2':
	    case '3':
	    case '4':
	    case '5':
	    case '6':
	    case '7':
	    case '8':
	    case '9':
		ch = bwa2i( ch, &fmt, 10, &w );
		break;
	    }
	    switch( ch ) {
	    case 0: return;
	    case 'c':
		bwputc( va_arg( va, char ) );
		break;
	    case 's':
		bwputw( w, 0, va_arg( va, char* ) );
		break;
	    case 'u':
		bwui2a( va_arg( va, unsigned int ), 10, bf );
		bwputw( w, lz, bf );
		break;
	    case 'd':
		bwi2a( va_arg( va, int ), bf );
		bwputw( w, lz, bf );
		break;
	    case 'x':
	    case 'p':
		bwui2a( va_arg( va, unsigned int ), 16, bf );
		bwputw( w, lz, bf );
		break;
	    case '%':
		bwputc( ch );
		break;
	    }
	}
    }
}
int bwputr( int channel, unsigned int reg ) {
	int byte;
	char *ch = (char *) ®

	for( byte = 3; byte >= 0; byte-- ) bwputx( channel, ch[byte] );
	return bwputc( channel, ' ' );
}
int bwputstr( int channel, char *str ) {
	while( *str ) {
		if( bwputc( channel, *str ) < 0 ) return -1;
		str++;
	}
	return 0;
}
Beispiel #6
0
/* Print a null terminated string */
int 
bwputstr( char *str ) {
    while( *str ) {
	if( bwputc( *str ) < 0 ) return -1;
	str++;
    }
    return 0;
}
int term_init() {
    int i;
    bwcls();

    bwprintf( COM2, "\x1B[10;40r" );
    for( i = 0; i < 100; i++ ){
        bwputc( COM2, '\n' );
    }

    bwsavecur();
    term_switchtable();
    bwloadcur();

    return 0;
}
Beispiel #8
0
void rps_server () {

    RegisterAs("RPSServer");

    RPSMessage msg, reply;
    tid_t tid;

    unsigned int num_matches = MAX_TASKS/2 + 1;

    RPSMatch matches[num_matches];

    unsigned int i;
    for (i = 0; i < num_matches; ++i) {
        reset_match_spot(&matches[i]);
    }

    struct circular_queue waiting_for_match;
    circular_queue_initialize(&waiting_for_match);


    RPSMatch *match;

    while (1) {
//        bwprintf(COM2, "RPS Server waiting for message\n");

        // Receive a request and process it
        Receive(&tid, (char *) &msg, sizeof(msg));

        switch (msg.type) {
        case SIGNUP:
 //           bwprintf(COM2, "RPS Server got a signup from %d\n", tid);
            // Put the task on the queue
            circular_queue_push(&waiting_for_match, (void *) tid);
            // If there are two tasks on the queue, pop them off to create a pair
            if (2 == circular_queue_size(&waiting_for_match)) {
                RPSMatch *match = find_free_match_spot(matches, num_matches);
                match->task1 = (tid_t) circular_queue_pop(&waiting_for_match);
                match->task2 = (tid_t) circular_queue_pop(&waiting_for_match);
                reply.type = GOAHEAD;
                Reply(match->task1, (char *) &reply, sizeof(reply));
                Reply(match->task2, (char *) &reply, sizeof(reply));
            }
            break;
        case PLAY:
//            bwprintf(COM2, "RPS Server got a play of %d from %d\n", msg.move, tid);
            // Check that the task is in a pair and we're expecting a play
            match = find_match_containing_tid(matches, num_matches, tid);
            // Register the play
            if (tid == match->task1) {
                match->t1Move = msg.move;
            } else {
                match->t2Move = msg.move;
            }

//            bwprintf(COM2, "\n\n\nStored Moves Are: \n");
//            bwprintf(COM2, "%d Move: %d and %d Move: %d\n\n\n", match->task1, match->t1Move, match->task2, match->t2Move);
            // If both tasks in the pair have played, reply with the result
            if (match->t1Move != NONE && match->t2Move != NONE) {
                RPSMessage t1Reply;
                RPSMessage t2Reply;

                t1Reply.type = t2Reply.type = RESULT;

                if (match->t1Move == FORFEIT) {
                    t2Reply.result = FORFEIT;
                    Reply(match->task2, (char *) &t2Reply, sizeof(t2Reply));
                    reset_match_spot(match);
                    break;
                } else if (match->t2Move == FORFEIT) {
                    t1Reply.result = FORFEIT;
                    Reply(match->task1, (char *) &t1Reply, sizeof(t1Reply));
                    reset_match_spot(match);
                    break;
                }

                unsigned int winner = 0;
                if (ROCK == match->t1Move) {
                    if (ROCK == match->t2Move) {
                        winner = 0;
                    }
                    else if (PAPER == match->t2Move) {
                        winner = 2;
                    } else if (SCISSORS == match->t2Move) {
                        winner = 1;
                    }
                } else if (PAPER == match->t1Move) {
                    if (ROCK == match->t2Move) {
                        winner = 1;
                    }
                    else if (PAPER == match->t2Move) {
                        winner = 0;
                    } else if (SCISSORS == match->t2Move) {
                        winner = 2;
                    }
                } else if (SCISSORS == match->t1Move) {
                    if (ROCK == match->t2Move) {
                        winner = 2;
                    }
                    else if (PAPER == match->t2Move) {
                        winner = 1;
                    } else if (SCISSORS == match->t2Move) {
                        winner = 0;
                    }
                }

                switch (winner) {
                case 0:
                    t1Reply.result = t2Reply.result = DRAW;
                    break;
                case 1:
                    t1Reply.result = WIN;
                    t2Reply.result = LOSE;
                    break;
                case 2:
                    t1Reply.result = LOSE;
                    t2Reply.result = WIN;
                    break;
                }
                bwprintf (COM2,
                          "Round ended with %d playing %s and %d playing %s\n",
                          match->task1,
                          MOVE_STRINGS[match->t1Move],
                          match->task2,
                          MOVE_STRINGS[match->t2Move]);
                bwprintf (COM2,
                          "Press any key to continue ");
                bwgetc(COM2);
                bwputc(COM2, '\n');
                match->t1Move = match->t2Move = NONE;
                Reply(match->task1, (char *) &t1Reply, sizeof(t1Reply));
                Reply(match->task2, (char *) &t2Reply, sizeof(t2Reply));
            }
            break;
        case QUIT:
            //bwprintf(COM2, "RPS Server got a QUIT from %d\n", tid);
            match = find_match_containing_tid(matches, num_matches, tid);
            if (match->task1 == tid) {
                match->t1Move = FORFEIT;
                if (match->t2Move == FORFEIT) {
                    reset_match_spot(match);
                }
            } else {
                match->t2Move = FORFEIT;
                if (match->t1Move == FORFEIT) {
                    reset_match_spot(match);
                }
            }
            reply.type = QUIT;
            Reply(tid, (char*) &reply, sizeof(reply));
            break;
        default:
            // Error or something
            break;
        }
    }

    Exit();
}
Beispiel #9
0
void turnOnTrainSet() {
    bwputc(TRAIN, TRAIN_AUX_GO);
}