/branches/tracing/uspace/app/tetris/Makefile |
---|
1,6 → 1,7 |
include ../../Makefile.config |
LIBC_PREFIX = ../../lib/libc |
SOFTINT_PREFIX = ../../lib/softint |
include $(LIBC_PREFIX)/Makefile.toolchain |
LIBS = $(LIBC_PREFIX)/libc.a |
19,7 → 20,7 |
$(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend |
$(OUTPUT): $(OBJECTS) $(LIBS) |
$(LD) -T $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map |
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map |
clean: |
-rm -f $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm Makefile.depend *.o |
/branches/tracing/uspace/app/tetris/input.c |
---|
57,9 → 57,7 |
#include "tetris.h" |
#include <async.h> |
#include <ipc/console.h> |
#include <console.h> |
#include <kbd/kbd.h> |
#include "../../srv/console/console.h" |
/* return true iff the given timeval is positive */ |
#define TV_POS(tv) \ |
113,11 → 111,10 |
s = NULL; |
if (!lastchar) { |
again: |
if (!getchar_inprog) { |
cons_phone = console_open(true); |
cons_phone = get_cons_phone(); |
getchar_inprog = async_send_2(cons_phone, |
CONSOLE_GETKEY, 0, 0, &charcall); |
CONSOLE_GETCHAR, 0, 0, &charcall); |
} |
if (!s) |
async_wait_for(getchar_inprog, &rc); |
130,10 → 127,7 |
if (rc) { |
stop("end of file, help"); |
} |
if (IPC_GET_ARG1(charcall) == KE_RELEASE) |
goto again; |
lastchar = IPC_GET_ARG4(charcall); |
lastchar = IPC_GET_ARG1(charcall); |
} |
if (tvp) { |
/* since there is input, we may not have timed out */ |
/branches/tracing/uspace/app/tetris/scores.c |
---|
55,9 → 55,6 |
#include <stdio.h> |
/* #include <stdlib.h> */ |
#include <string.h> |
#include <kbd/kbd.h> |
#include <kbd/keycode.h> |
#include <stdlib.h> |
/* #include <time.h> */ |
/* #include <term.h> */ |
/* #include <unistd.h> */ |
117,8 → 114,7 |
*/ |
static void copyhiscore(int dest, int src) |
{ |
str_cpy(scores[dest].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, |
scores[src].hs_name); |
strcpy(scores[dest].hs_name, scores[src].hs_name); |
scores[dest].hs_score = scores[src].hs_score; |
scores[dest].hs_level = scores[src].hs_level; |
} |
126,58 → 122,32 |
void insertscore(int score, int level) |
{ |
int i,j; |
size_t off; |
kbd_event_t ev; |
int key; |
clear_screen(); |
moveto(10 , 10); |
puts("Insert your name: "); |
str_cpy(scores[NUMSPOTS - 1].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, |
"Player"); |
i = 6; off = 6; |
strncpy(scores[NUMSPOTS - 1].hs_name, "Player", MAXLOGNAME); |
i = 6; |
moveto(10 , 28); |
printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................"); |
while (1) { |
fflush(stdout); |
if (kbd_get_event(&ev) != EOK) |
exit(1); |
if (ev.type == KE_RELEASE) |
continue; |
if (ev.key == KC_ENTER || ev.key == KC_NENTER) |
break; |
if (ev.key == KC_BACKSPACE) { |
if (i > 0) { |
wchar_t uc; |
--i; |
while (off > 0) { |
--off; |
size_t otmp = off; |
uc = str_decode(scores[NUMSPOTS - 1].hs_name, |
&otmp, STR_BOUNDS(MAXLOGNAME) + 1); |
if (uc != U_SPECIAL) |
break; |
} |
scores[NUMSPOTS - 1].hs_name[off] = '\0'; |
} |
} else if (ev.c != '\0') { |
if (i < (MAXLOGNAME - 1)) { |
if (chr_encode(ev.c, scores[NUMSPOTS - 1].hs_name, |
&off, STR_BOUNDS(MAXLOGNAME) + 1) == EOK) { |
++i; |
} |
scores[NUMSPOTS - 1].hs_name[off] = '\0'; |
} |
key = getchar(); |
while(key != '\n') { |
if (key == '\b') { |
if (i > 0) |
scores[NUMSPOTS - 1].hs_name[--i] = '\0'; |
} else { |
if (i < (MAXLOGNAME - 1)) |
scores[NUMSPOTS - 1].hs_name[i++] = key; |
scores[NUMSPOTS - 1].hs_name[i] = '\0'; |
} |
moveto(10 , 28); |
printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................"); |
key = getchar(); |
} |
scores[NUMSPOTS - 1].hs_score = score; |
197,7 → 167,7 |
{ |
int i; |
for(i = 0; i < NUMSPOTS; i++) { |
str_cpy(scores[i].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, "HelenOS Team"); |
strncpy(scores[i].hs_name, "HelenOS Team", MAXLOGNAME); |
scores[i].hs_score = (NUMSPOTS - i) * 200; |
scores[i].hs_level = (i + 1 > MAXLEVEL?MAXLEVEL:i + 1); |
} |
291,7 → 261,7 |
/* change = 0; */ |
/* me = thisuser(); */ |
/* for (i = 0, sp = &scores[0]; i < nscores; i++, sp++) { */ |
/* if (sp->hs_level != level || str_cmp(sp->hs_name, me) != 0) */ |
/* if (sp->hs_level != level || strcmp(sp->hs_name, me) != 0) */ |
/* continue; */ |
/* if (score > sp->hs_score) { */ |
/* (void)printf("%s bettered %s %d score of %d!\n", */ |
419,7 → 389,7 |
/* * This is O(n^2), but do you think we care? */ |
/* *\/ */ |
/* for (j = 0, pu = count; j < numnames; j++, pu++) */ |
/* if (str_cmp(sp->hs_name, pu->name) == 0) */ |
/* if (strcmp(sp->hs_name, pu->name) == 0) */ |
/* break; */ |
/* if (j == numnames) { */ |
/* /\* */ |
556,7 → 526,7 |
/* if (me != NULL && */ |
/* sp->hs_level == level && */ |
/* sp->hs_score == score && */ |
/* str_cmp(sp->hs_name, me) == 0) { */ |
/* strcmp(sp->hs_name, me) == 0) { */ |
/* putpad(SOstr); */ |
/* highlight = 1; */ |
/* } */ |
/branches/tracing/uspace/app/tetris/tetris.c |
---|
277,7 → 277,7 |
/* classic = 1; */ |
/* break; */ |
/* case 'k': */ |
/* if (str_size(keys = optarg) != 6) */ |
/* if (strlen(keys = optarg) != 6) */ |
/* usage(); */ |
/* break; */ |
/* case 'l': */ |
311,7 → 311,7 |
errx(1, "duplicate command keys specified."); |
} |
if (keys[i] == ' ') |
str_cpy(key_write[i], sizeof key_write[i], "<space>"); |
strncpy(key_write[i], "<space>", sizeof key_write[i]); |
else { |
key_write[i][0] = keys[i]; |
key_write[i][1] = '\0'; |
390,7 → 390,7 |
scr_update(); |
scr_msg(key_msg, 0); |
scr_msg(msg, 1); |
(void) fflush(stdout); |
// (void) fflush(stdout); |
} while (rwait((struct timeval *)NULL) == -1); |
scr_msg(msg, 0); |
scr_msg(key_msg, 1); |
/branches/tracing/uspace/app/tetris/screen.c |
---|
50,12 → 50,13 |
#include <stdlib.h> |
#include <string.h> |
#include <unistd.h> |
#include <console.h> |
#include <io/stream.h> |
#include <async.h> |
#include "screen.h" |
#include "tetris.h" |
#include <ipc/console.h> |
#include "../../srv/console/console.h" |
static cell curscreen[B_SIZE]; /* 1 => standout (or otherwise marked) */ |
static int curscore; |
72,19 → 73,29 |
putchar(*(s++)); |
} |
static int con_phone; |
static void set_style(int fgcolor, int bgcolor) |
{ |
async_msg_2(con_phone, CONSOLE_SET_STYLE, fgcolor, bgcolor); |
} |
static void start_standout(void) |
{ |
console_set_rgb_color(0xf0f0f0, 0); |
set_style(0xf0f0f0, 0); |
} |
static void resume_normal(void) |
{ |
console_set_rgb_color(0, 0xf0f0f0); |
set_style(0, 0xf0f0f0); |
} |
void clear_screen(void) |
{ |
console_clear(); |
async_msg_0(con_phone, CONSOLE_CLEAR); |
moveto(0, 0); |
} |
96,7 → 107,7 |
{ |
resume_normal(); |
console_clear(); |
async_msg_0(con_phone, CONSOLE_CLEAR); |
curscore = -1; |
memset((char *)curscreen, 0, sizeof(curscreen)); |
} |
107,7 → 118,8 |
void |
scr_init(void) |
{ |
console_cursor_visibility(0); |
con_phone = get_cons_phone(); |
async_msg_1(con_phone, CONSOLE_CURSOR_VISIBILITY, 0); |
resume_normal(); |
scr_clear(); |
} |
114,14 → 126,20 |
void moveto(int r, int c) |
{ |
console_goto(r, c); |
async_msg_2(con_phone, CONSOLE_GOTO, r, c); |
} |
static void fflush(void) |
{ |
async_msg_0(con_phone, CONSOLE_FLUSH); |
} |
winsize_t winsize; |
static int get_display_size(winsize_t *ws) |
{ |
return console_get_size(&ws->ws_row, &ws->ws_col); |
return async_req_0_2(con_phone, CONSOLE_GETSIZE, &ws->ws_row, |
&ws->ws_col); |
} |
/* |
269,7 → 287,7 |
} |
if (cur_so) |
resume_normal(); |
fflush(stdout); |
fflush(); |
} |
/* |
280,7 → 298,7 |
scr_msg(char *s, int set) |
{ |
int l = str_size(s); |
int l = strlen(s); |
moveto(Rows - 2, ((Cols - l) >> 1) - 1); |
if (set) |
/branches/tracing/uspace/app/tetris/scores.h |
---|
45,11 → 45,9 |
* Tetris scores. |
*/ |
#include <sys/time.h> |
#include <string.h> |
#define MAXLOGNAME 16 |
struct highscore { |
char hs_name[STR_BOUNDS(MAXLOGNAME) + 1]; /* login name */ |
char hs_name[MAXLOGNAME + 1]; /* login name */ |
int hs_score; /* raw score */ |
int hs_level; /* play level */ |
// time_t hs_time; /* time at game end */ |
/branches/tracing/uspace/app/tetris/screen.h |
---|
49,8 → 49,8 |
#include <async.h> |
typedef struct { |
int ws_row; |
int ws_col; |
ipcarg_t ws_row; |
ipcarg_t ws_col; |
} winsize_t; |
extern winsize_t winsize; |