This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
MicroWindows - better eCos application handling
- From: Gary Thomas <gary at mlbassoc dot com>
- To: eCos patches <ecos-patches at sources dot redhat dot com>
- Date: 30 Aug 2003 15:31:55 -0600
- Subject: MicroWindows - better eCos application handling
- Organization: MLB Associates
Changed the basic application to use HAL tables to define which
application [threads] are present. It should be much easier now to
write and adapt MW applications to the eCos environment.
--
Gary Thomas <gary@mlbassoc.com>
MLB Associates
Index: services/gfx/mw/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/services/gfx/mw/current/ChangeLog,v
retrieving revision 1.5
diff -u -5 -p -r1.5 ChangeLog
--- services/gfx/mw/current/ChangeLog 28 Aug 2003 10:30:33 -0000 1.5
+++ services/gfx/mw/current/ChangeLog 30 Aug 2003 21:29:01 -0000
@@ -1,5 +1,23 @@
+2003-08-30 Gary Thomas <gary@mlbassoc.com>
+
+ * src/ecos/world_thread.c:
+ * src/ecos/ntetris_thread.c:
+ * src/ecos/nanox_thread.c:
+ * src/ecos/nanowm_thread.c:
+ * src/ecos/ecos_app.c: Use tables to define threads within
+ the actual application.
+
+ * src/demos/nanox/ntetris.h:
+ * src/demos/nanox/ntetris.c: Adapt to eCos threaded environment.
+
+ * include/microwin/ecos_mw_app.h: New file - define table
+ driven API for plug-in MicroWindows applications under eCos.
+
+ * cdl/microwindows.cdl: Add support for building complete
+ application via CDL. Also better selection of demos to run.
+
2003-08-22 Chris Garry <cgarry@sweeneydesign.co.uk>
* cdl/microwindows.cdl
Added support for VNC server.
Index: services/gfx/mw/current/cdl/microwindows.cdl
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/services/gfx/mw/current/cdl/microwindows.cdl,v
retrieving revision 1.5
diff -u -5 -p -r1.5 microwindows.cdl
--- services/gfx/mw/current/cdl/microwindows.cdl 28 Aug 2003 10:30:34 -0000 1.5
+++ services/gfx/mw/current/cdl/microwindows.cdl 30 Aug 2003 20:59:00 -0000
@@ -133,16 +133,29 @@ cdl_package CYGPKG_MICROWINDOWS {
fonts/winFreeSystem14x16.c \
fonts/X5x7.c \
fonts/X6x13.c
# eCos stuff
- cdl_option CYGBLD_MICROWINDOWS_ECOS {
+ cdl_component CYGBLD_MICROWINDOWS_ECOS {
display "Build MicroWindows eCos support"
default_value 0
# These files are unique to eCos
- compile ecos/ecos_init.c ecos/nanox_thread.c
+ compile ecos/ecos_init.c
+ compile -library=libextras.a ecos/nanox_thread.c
+
+ cdl_option CYGBLD_MICROWINDOWS_ECOS_APP {
+ display "Build complete eCos+MicroWindows application"
+ default_value 0
+ make -priority 320 {
+ <PREFIX>/bin/ecos_mw.elf : $(PREFIX)/lib/target.ld $(PREFIX)/lib/vectors.o $(PREFIX)/lib/libtarget.a $(PREFIX)/lib/libextras.a $(REPOSITORY)/$(PACKAGE)/src/ecos/ecos_app.c
+ @sh -c "mkdir -p $(dir $@)"
+ $(CC) -c $(INCLUDE_PATH) $(CFLAGS) -o $(PREFIX)/lib/ecos_app.o $(REPOSITORY)/$(PACKAGE)/src/ecos/ecos_app.c
+ $(CC) $(LDFLAGS) -L$(PREFIX)/lib -Ttarget.ld -o $@ $(PREFIX)/lib/ecos_app.o
+ }
+
+ }
}
# eCos VNC server drivers
cdl_option CYGBLD_MICROWINDOWS_VNC_DRIVERS {
display "Build MicroWindows VNC server drivers"
@@ -255,18 +268,17 @@ cdl_package CYGPKG_MICROWINDOWS {
# Nano WM
cdl_option CYGBLD_MICROWINDOWS_NANOWM {
display "Build MicroWindows NANOWM"
default_value 0
-
compile \
demos/nanowm/nanowm.c \
demos/nanowm/events.c \
demos/nanowm/wlist.c \
demos/nanowm/clients.c \
- demos/nanowm/actions.c \
- ecos/nanowm_thread.c
+ demos/nanowm/actions.c
+ compile -library=libextras.a ecos/nanowm_thread.c
}
# keyboard
cdl_option CYGBLD_MICROWINDOWS_NXKBD {
display "Build MicroWindows NXKBD"
@@ -280,17 +292,29 @@ cdl_package CYGPKG_MICROWINDOWS {
demos/nxkbd/keyshft.c \
demos/nxkbd/keynum.c
}
# keyboard
- cdl_option CYGBLD_MICROWINDOWS_NANOX_DEMOS {
+ cdl_component CYGBLD_MICROWINDOWS_NANOX_DEMOS {
display "Build MicroWindows NanoX demos"
default_value 0
- compile \
- demos/nanox/world.c demos/nanox/ntetris.c \
- ecos/world_thread.c ecos/ntetris_thread.c
+ cdl_option CYGBLD_MICROWINDOWS_NANOX_DEMOS_WORLD {
+ display "Include 'world' demo"
+ default_value 0
+ no_define
+ compile demos/nanox/world.c
+ compile -library=libextras.a ecos/world_thread.c
+ }
+
+ cdl_option CYGBLD_MICROWINDOWS_NANOX_DEMOS_NTETRIS {
+ display "Include 'nano-tetris' demo"
+ default_value 0
+ no_define
+ compile demos/nanox/ntetris.c
+ compile -library=libextras.a ecos/ntetris_thread.c
+ }
}
cdl_component CYGPKG_MICROWINDOWS_OPTIONS {
display "Build options"
flavor none
Index: services/gfx/mw/current/include/microwin/ecos_mw_app.h
===================================================================
RCS file: services/gfx/mw/current/include/microwin/ecos_mw_app.h
diff -N services/gfx/mw/current/include/microwin/ecos_mw_app.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ services/gfx/mw/current/include/microwin/ecos_mw_app.h 30 Aug 2003 21:18:47 -0000
@@ -0,0 +1,83 @@
+#ifndef CYGONCE_ECOS_MW_APP_H_
+#define CYGONCE_ECOS_MW_APP_H_
+//==========================================================================
+//
+// ecos_mw_app.h
+//
+// API for plug-in MicroWindows applications
+//
+//==========================================================================
+//####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 2003 Gary Thomas
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later version.
+//
+// eCos 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. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with eCos; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or inline functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// License. However the source code for this file must still be made available
+// in accordance with section (3) of the GNU General Public License.
+//
+// This exception does not invalidate any other reasons why a work based on
+// this file might be covered by the GNU General Public License.
+//
+// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+// at http://sources.redhat.com/ecos/ecos-license/
+// -------------------------------------------
+//####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): gthomas
+// Contributors: gthomas
+// Date: 2003-08-30
+// Purpose:
+// Description:
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include <cyg/infra/cyg_type.h>
+#include <cyg/hal/hal_tables.h>
+
+#define STACKSIZE ( 65536 )
+typedef void fun(CYG_ADDRWORD);
+struct _mw_app_entry {
+ char *name;
+ fun *entry;
+ int prio;
+ fun *init;
+ cyg_handle_t t;
+ cyg_thread t_obj;
+ char stack[STACKSIZE];
+} CYG_HAL_TABLE_TYPE;
+
+#define _mw_app(_name_,_id_,_pri_,_init_) \
+externC void _id_##_thread(CYG_ADDRWORD data); \
+struct _mw_app_entry _mw_app_##_pri_##_##_id_ \
+ CYG_HAL_TABLE_QUALIFIED_ENTRY(_mw_apps,_pri_) = \
+ { _name_, _id_##_thread, _pri_, _init_};
+
+#define ECOS_MW_STARTUP_PRIORITY 11
+#define ECOS_MW_NANOX_PRIORITY (ECOS_MW_STARTUP_PRIORITY+1)
+#define ECOS_MW_KND_PRIORITY (ECOS_MW_STARTUP_PRIORITY+2)
+#define ECOS_MW_NANOWM_PRIORITY (ECOS_MW_STARTUP_PRIORITY+4)
+#define ECOS_MW_APP_PRIORITY (ECOS_MW_STARTUP_PRIORITY+5)
+
+#endif // CYGONCE_ECOS_MW_APP_H_
+// ------------------------------------------------------------------------
Index: services/gfx/mw/current/src/demos/nanox/ntetris.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/services/gfx/mw/current/src/demos/nanox/ntetris.c,v
retrieving revision 1.1
diff -u -5 -p -r1.1 ntetris.c
--- services/gfx/mw/current/src/demos/nanox/ntetris.c 20 May 2002 22:25:32 -0000 1.1
+++ services/gfx/mw/current/src/demos/nanox/ntetris.c 30 Aug 2003 21:08:44 -0000
@@ -89,11 +89,11 @@
#define MWINCLUDECOLORS
#include <nano-X.h>
#include "ntetris.h"
-void *my_malloc(size_t size)
+static void *my_malloc(size_t size)
{
void *ret;
if(!(ret = malloc(size))) {
fprintf(stderr, "Out of memory\n");
@@ -102,16 +102,16 @@ void *my_malloc(size_t size)
return ret;
}
#ifdef HAVE_USLEEP
-void msleep(long ms)
+static void msleep(long ms)
{
usleep(ms * 1000);
}
#else
-void msleep(long ms)
+static void msleep(long ms)
{
struct timespec req, rem;
req.tv_sec = ms / 1000000;
req.tv_nsec = (ms % 1000000) * 1000000;
@@ -128,11 +128,11 @@ void msleep(long ms)
}
}
#endif
#ifdef USE_HISCORE_FILE
-void read_hiscore(nstate *state)
+static void read_hiscore(nstate *state)
{
FILE *f;
int i, n;
if(!(f = fopen(HISCORE_FILE, "r"))) {
@@ -151,11 +151,11 @@ void read_hiscore(nstate *state)
}
state->hiscore = state->fhiscore = n;
}
-void write_hiscore(nstate *state)
+static void write_hiscore(nstate *state)
{
FILE *f;
if(state->score > state->hiscore) state->hiscore = state->score;
if(state->hiscore <= state->fhiscore) return;
@@ -170,19 +170,19 @@ void write_hiscore(nstate *state)
}
fclose(f);
}
#else
-void read_hiscore(nstate *state)
+static void read_hiscore(nstate *state)
{
state->hiscore = 0;
}
-void write_hiscore(nstate *state) {}
+static void write_hiscore(nstate *state) {}
#endif
-int will_collide(nstate *state, int x, int y, int orientation)
+static int will_collide(nstate *state, int x, int y, int orientation)
{
int r, c, xx, yy;
char ch = 0;
draw_shape(state, state->current_shape.x, state->current_shape.y, 1);
@@ -207,11 +207,11 @@ int will_collide(nstate *state, int x, i
draw_shape(state, state->current_shape.x, state->current_shape.y, 0);
return 0;
}
-void draw_shape(nstate *state, GR_COORD x, GR_COORD y, int erase)
+static void draw_shape(nstate *state, GR_COORD x, GR_COORD y, int erase)
{
int r, c, yy, xx;
GR_COLOR col;
char ch = 0;
@@ -230,11 +230,11 @@ void draw_shape(nstate *state, GR_COORD
}
}
}
}
-void draw_well(nstate *state, int forcedraw)
+static void draw_well(nstate *state, int forcedraw)
{
int x, y;
for(y = WELL_NOTVISIBLE; y < WELL_HEIGHT; y++) {
for(x = 0; x < WELL_WIDTH; x++) {
@@ -252,11 +252,11 @@ void draw_well(nstate *state, int forced
}
GrFlush();
}
-void draw_score(nstate *state)
+static void draw_score(nstate *state)
{
char buf[32];
GrFillRect(state->score_window, state->scoregcb, 0, 0,
SCORE_WINDOW_WIDTH, SCORE_WINDOW_HEIGHT);
@@ -267,11 +267,11 @@ void draw_score(nstate *state)
sprintf(buf, "%d", state->hiscore);
GrText(state->score_window, state->scoregcf, TEXT_X_POSITION,
TEXT_Y_POSITION, buf, strlen(buf), 0);
}
-void draw_next_shape(nstate *state)
+static void draw_next_shape(nstate *state)
{
int r, c, startx, starty, x, y;
char ch = 0;
GrFillRect(state->next_shape_window, state->nextshapegcb, 0, 0,
@@ -300,64 +300,64 @@ void draw_next_shape(nstate *state)
}
}
}
}
-void draw_new_game_button(nstate *state)
+static void draw_new_game_button(nstate *state)
{
GrFillRect(state->new_game_button, state->buttongcb, 0, 0,
NEW_GAME_BUTTON_WIDTH, NEW_GAME_BUTTON_HEIGHT);
GrText(state->new_game_button, state->buttongcf, TEXT_X_POSITION,
TEXT_Y_POSITION, "New Game", 8, 0);
}
-void draw_anticlockwise_button(nstate *state)
+static void draw_anticlockwise_button(nstate *state)
{
if(!state->running_buttons_mapped) return;
GrFillRect(state->anticlockwise_button, state->buttongcb, 0, 0,
ANTICLOCKWISE_BUTTON_WIDTH, ANTICLOCKWISE_BUTTON_HEIGHT);
GrText(state->anticlockwise_button, state->buttongcf, TEXT_X_POSITION,
TEXT_Y_POSITION, " /", 4, 0);
}
-void draw_clockwise_button(nstate *state)
+static void draw_clockwise_button(nstate *state)
{
if(!state->running_buttons_mapped) return;
GrFillRect(state->clockwise_button, state->buttongcb, 0, 0,
CLOCKWISE_BUTTON_WIDTH, CLOCKWISE_BUTTON_HEIGHT);
GrText(state->clockwise_button, state->buttongcf, TEXT_X_POSITION,
TEXT_Y_POSITION, " \\", 4, 0);
}
-void draw_left_button(nstate *state)
+static void draw_left_button(nstate *state)
{
if(!state->running_buttons_mapped) return;
GrFillRect(state->left_button, state->buttongcb, 0, 0,
LEFT_BUTTON_WIDTH, LEFT_BUTTON_HEIGHT);
GrText(state->left_button, state->buttongcf, TEXT_X_POSITION,
TEXT_Y_POSITION, " <", 3, 0);
}
-void draw_right_button(nstate *state)
+static void draw_right_button(nstate *state)
{
if(!state->running_buttons_mapped) return;
GrFillRect(state->right_button, state->buttongcb, 0, 0,
RIGHT_BUTTON_WIDTH, RIGHT_BUTTON_HEIGHT);
GrText(state->right_button, state->buttongcf, TEXT_X_POSITION,
TEXT_Y_POSITION, " >", 4, 0);
}
-void draw_drop_button(nstate *state)
+static void draw_drop_button(nstate *state)
{
if(!state->running_buttons_mapped) return;
GrFillRect(state->drop_button, state->buttongcb, 0, 0,
DROP_BUTTON_WIDTH, DROP_BUTTON_HEIGHT);
GrText(state->drop_button, state->buttongcf, TEXT_X_POSITION,
TEXT_Y_POSITION, " Drop", 8, 0);
}
-void draw_pause_continue_button(nstate *state)
+static void draw_pause_continue_button(nstate *state)
{
if((state->running_buttons_mapped) && (state->state == STATE_STOPPED)) {
GrUnmapWindow(state->pause_continue_button);
GrUnmapWindow(state->anticlockwise_button);
GrUnmapWindow(state->clockwise_button);
@@ -387,19 +387,19 @@ void draw_pause_continue_button(nstate *
GrText(state->pause_continue_button, state->buttongcf,
TEXT_X_POSITION, TEXT_Y_POSITION, " Pause", 8, 0);
}
}
-int block_is_all_in_well(nstate *state)
+static int block_is_all_in_well(nstate *state)
{
if(state->current_shape.y >= WELL_NOTVISIBLE)
return 1;
return 0;
}
-void delete_line(nstate *state, int line)
+static void delete_line(nstate *state, int line)
{
int x, y;
if(line < WELL_NOTVISIBLE) return;
@@ -408,11 +408,11 @@ void delete_line(nstate *state, int line
state->blocks[0][y + 1][x] = state->blocks[0][y][x];
draw_well(state, 0);
}
-void block_reached_bottom(nstate *state)
+static void block_reached_bottom(nstate *state)
{
int x, y;
if(!block_is_all_in_well(state)) {
state->state = STATE_STOPPED;
@@ -435,11 +435,11 @@ void block_reached_bottom(nstate *state)
choose_new_shape(state);
draw_next_shape(state);
}
-void move_block(nstate *state, int direction)
+static void move_block(nstate *state, int direction)
{
if(direction == 0) {
if(!state->current_shape.x) return;
else {
if(!will_collide(state, (state->current_shape.x - 1),
@@ -465,11 +465,11 @@ void move_block(nstate *state, int direc
draw_well(state, 0);
}
}
}
-void rotate_block(nstate *state, int direction)
+static void rotate_block(nstate *state, int direction)
{
int neworientation = 0;
if(direction == 0) {
if(!state->current_shape.orientation)
@@ -489,11 +489,11 @@ void rotate_block(nstate *state, int dir
state->current_shape.y, 0);
draw_well(state, 0);
}
}
-int drop_block_1(nstate *state)
+static int drop_block_1(nstate *state)
{
if(will_collide(state, state->current_shape.x,
(state->current_shape.y + 1),
state->current_shape.orientation)) {
block_reached_bottom(state);
@@ -507,16 +507,16 @@ int drop_block_1(nstate *state)
draw_well(state, 0);
return 0;
}
-void drop_block(nstate *state)
+static void drop_block(nstate *state)
{
while(!drop_block_1(state)) msleep(DROP_BLOCK_DELAY);
}
-void handle_exposure_event(nstate *state)
+static void handle_exposure_event(nstate *state)
{
GR_EVENT_EXPOSURE *event = &state->event.exposure;
if(event->wid == state->score_window) {
draw_score(state);
@@ -558,11 +558,11 @@ void handle_exposure_event(nstate *state
draw_well(state, 1);
return;
}
}
-void handle_mouse_event(nstate *state)
+static void handle_mouse_event(nstate *state)
{
GR_EVENT_MOUSE *event = &state->event.mouse;
if(event->wid == state->new_game_button) {
state->state = STATE_NEWGAME;
@@ -598,11 +598,11 @@ void handle_mouse_event(nstate *state)
drop_block(state);
return;
}
}
-void handle_keyboard_event(nstate *state)
+static void handle_keyboard_event(nstate *state)
{
GR_EVENT_KEYSTROKE *event = &state->event.keystroke;
switch(event->ch) {
case 'q':
@@ -651,11 +651,11 @@ void handle_keyboard_event(nstate *state
drop_block(state);
break;
}
}
-void handle_event(nstate *state)
+static void handle_event(nstate *state)
{
switch(state->event.type) {
case GR_EVENT_TYPE_EXPOSURE:
handle_exposure_event(state);
break;
@@ -675,11 +675,11 @@ void handle_event(nstate *state)
state->event.type);
break;
}
}
-void clear_well(nstate *state)
+static void clear_well(nstate *state)
{
int x, y;
for(y = 0; y < WELL_HEIGHT; y++)
for(x = 0; x < WELL_WIDTH; x++) {
@@ -687,20 +687,20 @@ void clear_well(nstate *state)
state->blocks[1][y][x] = 0;
}
}
/* Dirty hack alert- this is to avoid using any floating point math */
-int random8(int limit)
+static int random8(int limit)
{
int ret;
do { ret = random() & 7; } while(ret > limit);
return ret;
}
-void choose_new_shape(nstate *state)
+static void choose_new_shape(nstate *state)
{
state->current_shape.type = state->next_shape.type;
state->current_shape.orientation = state->next_shape.orientation;
state->current_shape.colour = state->next_shape.colour;
state->current_shape.x = (WELL_WIDTH / 2) - 2;
@@ -710,11 +710,11 @@ void choose_new_shape(nstate *state)
state->next_shape.type = random8(MAXSHAPES - 1);
state->next_shape.orientation = random8(MAXORIENTATIONS - 1);
state->next_shape.colour = block_colours[random8(MAX_BLOCK_COLOUR)];
}
-void new_game(nstate *state)
+static void new_game(nstate *state)
{
clear_well(state);
if(state->score > state->hiscore) state->hiscore = state->score;
state->score = 0;
state->level = 0;
@@ -723,11 +723,11 @@ void new_game(nstate *state)
draw_next_shape(state);
draw_well(state, 1);
if(state->state == STATE_NEWGAME) state->state = STATE_RUNNING;
}
-void init_game(nstate *state)
+static void init_game(nstate *state)
{
GR_WM_PROPERTIES props;
if(GrOpen() < 0) {
fprintf(stderr, "Couldn't connect to Nano-X server\n");
@@ -873,22 +873,22 @@ void init_game(nstate *state)
choose_new_shape(state);
new_game(state);
}
-void calculate_timeout(nstate *state)
+static void calculate_timeout(nstate *state)
{
struct timeval t;
long u;
gettimeofday(&t, NULL);
u = t.tv_usec + (delays[state->level] * 1000);
state->timeout.tv_sec = t.tv_sec + (u / 1000000);
state->timeout.tv_usec = u % 1000000;
}
-unsigned long timeout_delay(nstate *state)
+static unsigned long timeout_delay(nstate *state)
{
struct timeval t;
signed long s, m, ret;
gettimeofday(&t, NULL);
@@ -908,11 +908,11 @@ unsigned long timeout_delay(nstate *stat
*/
if(ret <= 0) return 1;
else return ret;
}
-void do_update(nstate *state)
+static void do_update(nstate *state)
{
struct timeval t;
gettimeofday(&t, NULL);
@@ -922,21 +922,21 @@ void do_update(nstate *state)
drop_block_1(state);
calculate_timeout(state);
}
}
-void do_pause(nstate *state)
+static void do_pause(nstate *state)
{
draw_pause_continue_button(state);
while(state->state == STATE_PAUSED) {
GrGetNextEvent(&state->event);
handle_event(state);
}
draw_pause_continue_button(state);
}
-void wait_for_start(nstate *state)
+static void wait_for_start(nstate *state)
{
draw_pause_continue_button(state);
while(state->state == STATE_STOPPED) {
GrGetNextEvent(&state->event);
handle_event(state);
@@ -944,34 +944,39 @@ void wait_for_start(nstate *state)
if(state->state == STATE_NEWGAME) state->state = STATE_RUNNING;
draw_pause_continue_button(state);
calculate_timeout(state);
}
-void run_game(nstate *state)
+static void run_game(nstate *state)
{
while(state->state == STATE_RUNNING) {
GrGetNextEventTimeout(&state->event, timeout_delay(state));
handle_event(state);
if(state->state == STATE_PAUSED) do_pause(state);
if(state->state == STATE_RUNNING) do_update(state);
}
}
-void main_game_loop(nstate *state)
+static void main_game_loop(nstate *state)
{
wait_for_start(state);
while(state->state != STATE_EXIT) {
if(state->state == STATE_RUNNING) run_game(state);
if(state->state == STATE_STOPPED) wait_for_start(state);
if(state->state != STATE_EXIT) new_game(state);
}
}
+#ifdef __ECOS
+#define main ntetris_main
+#endif
+
int main(int argc, char *argv[])
{
nstate *state = my_malloc(sizeof(nstate));
+ printf("state = %x\n", state);
init_game(state);
main_game_loop(state);
write_hiscore(state);
Index: services/gfx/mw/current/src/demos/nanox/ntetris.h
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/services/gfx/mw/current/src/demos/nanox/ntetris.h,v
retrieving revision 1.1
diff -u -5 -p -r1.1 ntetris.h
--- services/gfx/mw/current/src/demos/nanox/ntetris.h 20 May 2002 22:25:32 -0000 1.1
+++ services/gfx/mw/current/src/demos/nanox/ntetris.h 30 Aug 2003 21:21:11 -0000
@@ -71,11 +71,11 @@
#define MAIN_WINDOW_Y_POSITION 0
#define MAIN_WINDOW_WIDTH (CONTROL_BAR_WIDTH + (2 * BORDER_WIDTH) + \
(WELL_WIDTH * BLOCK_SIZE))
#define MAIN_WINDOW_HEIGHT ((2 * BORDER_WIDTH) + \
(WELL_VISIBLE_HEIGHT * BLOCK_SIZE))
-#define MAIN_WINDOW_BACKGROUND_COLOUR BLUE
+#define MAIN_WINDOW_BACKGROUND_COLOUR LTBLUE
#define SCORE_WINDOW_WIDTH BUTTON_WIDTH
#define SCORE_WINDOW_HEIGHT 35
#define SCORE_WINDOW_X_POSITION BORDER_WIDTH
#define SCORE_WINDOW_Y_POSITION BORDER_WIDTH
@@ -188,48 +188,48 @@ struct ntetris_state {
GR_EVENT event;
struct timeval timeout;
};
typedef struct ntetris_state nstate;
-void *my_malloc(size_t size);
-void msleep(long ms);
-void read_hiscore(nstate *state);
-void write_hiscore(nstate *state);
-int will_collide(nstate *state, int x, int y, int orientation);
-void draw_shape(nstate *state, GR_COORD x, GR_COORD y, int erase);
-void draw_well(nstate *state, int forcedraw);
-void draw_score(nstate *state);
-void draw_next_shape(nstate *state);
-void draw_new_game_button(nstate *state);
-void draw_anticlockwise_button(nstate *state);
-void draw_clockwise_button(nstate *state);
-void draw_left_button(nstate *state);
-void draw_right_button(nstate *state);
-void draw_drop_button(nstate *state);
-void draw_pause_continue_button(nstate *state);
-int block_is_all_in_well(nstate *state);
-void delete_line(nstate *state, int line);
-void block_reached_bottom(nstate *state);
-void move_block(nstate *state, int direction);
-void rotate_block(nstate *state, int direction);
-void drop_block(nstate *state);
-void handle_exposure_event(nstate *state);
-void handle_mouse_event(nstate *state);
-void handle_keyboard_event(nstate *state);
-void handle_event(nstate *state);
-void clear_well(nstate *state);
-int random8(int limit);
-void choose_new_shape(nstate *state);
-void new_game(nstate *state);
-void init_game(nstate *state);
-void calculate_timeout(nstate *state);
-unsigned long timeout_delay(nstate *state);
-void do_update(nstate *state);
-void do_pause(nstate *state);
-void wait_for_start(nstate *state);
-void run_game(nstate *state);
-void main_game_loop(nstate *state);
+static void *my_malloc(size_t size);
+static void msleep(long ms);
+static void read_hiscore(nstate *state);
+static void write_hiscore(nstate *state);
+static int will_collide(nstate *state, int x, int y, int orientation);
+static void draw_shape(nstate *state, GR_COORD x, GR_COORD y, int erase);
+static void draw_well(nstate *state, int forcedraw);
+static void draw_score(nstate *state);
+static void draw_next_shape(nstate *state);
+static void draw_new_game_button(nstate *state);
+static void draw_anticlockwise_button(nstate *state);
+static void draw_clockwise_button(nstate *state);
+static void draw_left_button(nstate *state);
+static void draw_right_button(nstate *state);
+static void draw_drop_button(nstate *state);
+static void draw_pause_continue_button(nstate *state);
+static int block_is_all_in_well(nstate *state);
+static void delete_line(nstate *state, int line);
+static void block_reached_bottom(nstate *state);
+static void move_block(nstate *state, int direction);
+static void rotate_block(nstate *state, int direction);
+static void drop_block(nstate *state);
+static void handle_exposure_event(nstate *state);
+static void handle_mouse_event(nstate *state);
+static void handle_keyboard_event(nstate *state);
+static void handle_event(nstate *state);
+static void clear_well(nstate *state);
+static int random8(int limit);
+static void choose_new_shape(nstate *state);
+static void new_game(nstate *state);
+static void init_game(nstate *state);
+static void calculate_timeout(nstate *state);
+static unsigned long timeout_delay(nstate *state);
+static void do_update(nstate *state);
+static void do_pause(nstate *state);
+static void wait_for_start(nstate *state);
+static void run_game(nstate *state);
+static void main_game_loop(nstate *state);
#define LEVELS 12
static const int delays[] = {600, 550, 500, 450, 400, 350,
300, 250, 200, 150, 100, 50};
#define MAX_BLOCK_COLOUR 3
Index: services/gfx/mw/current/src/ecos/ecos_app.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/services/gfx/mw/current/src/ecos/ecos_app.c,v
retrieving revision 1.1
diff -u -5 -p -r1.1 ecos_app.c
--- services/gfx/mw/current/src/ecos/ecos_app.c 20 May 2002 22:25:37 -0000 1.1
+++ services/gfx/mw/current/src/ecos/ecos_app.c 30 Aug 2003 21:18:47 -0000
@@ -45,70 +45,21 @@
#include <ctype.h> /* tolower */
#include <cyg/kernel/kapi.h> /* All the kernel specific stuff */
#include <cyg/hal/hal_arch.h> /* CYGNUM_HAL_STACK_SIZE_TYPICAL */
#include <sys/time.h>
#include <network.h> /* init_all_network_interfaces() */
+#include <microwin/ecos_mw_app.h>
-#define STACKSIZE ( 65536 )
+// Define table boundaries
+CYG_HAL_TABLE_BEGIN( __MW_APP_TAB__, _mw_apps );
+CYG_HAL_TABLE_END( __MW_APP_TAB_END__, _mw_apps );
+extern struct _mw_app_entry __MW_APP_TAB__[], __MW_APP_TAB_END__;
+
+static char startup_stack[STACKSIZE];
+cyg_handle_t startup_thread;
+cyg_thread startup_thread_obj;
-extern void ecos_nx_init(CYG_ADDRWORD data);
-extern void nanowm_thread(CYG_ADDRWORD data);
-extern void nanox_thread(CYG_ADDRWORD data);
-#ifdef USE_NXKBD
-extern void nxkbd_thread(CYG_ADDRWORD data);
-#endif
-#ifdef USE_NXSCRIBBLE
-extern void nxscribble_thread(CYG_ADDRWORD data);
-#endif
-#ifdef USE_LANDMINE
-extern void landmine_thread(CYG_ADDRWORD data);
-#endif
-#ifdef USE_NTETRIS
-extern void ntetris_thread(CYG_ADDRWORD data);
-#endif
-#ifdef USE_WORLD
-extern void world_thread(CYG_ADDRWORD data);
-#endif
-#ifdef USE_IMG_DEMO
-extern void img_demo_thread(CYG_ADDRWORD data);
-#endif
-static void startup_thread(CYG_ADDRWORD data);
-
-typedef void fun(CYG_ADDRWORD);
-struct nx_thread {
- char *name;
- fun *entry;
- int prio;
- cyg_handle_t t;
- cyg_thread t_obj;
- char stack[STACKSIZE];
-};
-
-struct nx_thread _threads[] = {
- { "System startup", startup_thread, 11 },
- { "Nano-X server", nanox_thread, 12 },
- { "Nano-WM", nanowm_thread, 14 },
-#ifdef USE_NXKBD
- { "Nano-KBD", nxkbd_thread, 13 },
-#endif
-#ifdef USE_IMG_DEMO
- { "Image demo", img_demo_thread, 20 },
-#endif
-#ifdef USE_NXSCRIBBLE
- { "Scribble", nxscribble_thread, 20 },
-#endif
-#ifdef USE_LANDMINE
- { "Landmine", landmine_thread, 19 },
-#endif
-#ifdef USE_NTETRIS
- { "Nano-Tetris", ntetris_thread, 18 },
-#endif
-#ifdef USE_WORLD
- { "World Map", world_thread, 21 },
-#endif
-};
-#define NUM(x) (sizeof(x)/sizeof(x[0]))
// Functions not provided in eCos by standard...
char *
strdup(char *string) {
char *newbit = malloc(strlen(string)+1);
@@ -135,15 +86,14 @@ strcasecmp(const char *s1, const char *s
return (0);
return ((unsigned char)c1 - (unsigned char)c2);
}
static void
-startup_thread(CYG_ADDRESS data)
+startup(CYG_ADDRESS data)
{
cyg_ucount32 nanox_data_index;
- int i;
- struct nx_thread *nx;
+ struct _mw_app_entry *nx;
printf("SYSTEM INITIALIZATION in progress\n");
printf("NETWORK:\n");
init_all_network_interfaces();
@@ -195,45 +145,39 @@ startup_thread(CYG_ADDRESS data)
// data. That's why there is only one call here.
nanox_data_index = cyg_thread_new_data_index();
printf("data index = %d\n", nanox_data_index);
printf("Creating system threads\n");
- nx = &_threads[1];
- for (i = 1; i < NUM(_threads); i++, nx++) {
+ for (nx = __MW_APP_TAB__; nx != &__MW_APP_TAB_END__; nx++) {
+ printf("Creating %s thread\n", nx->name);
cyg_thread_create(nx->prio,
nx->entry,
(cyg_addrword_t) nanox_data_index,
nx->name,
(void *)nx->stack, STACKSIZE,
&nx->t,
&nx->t_obj);
}
-
printf("Starting threads\n");
- nx = &_threads[1];
- for (i = 1; i < NUM(_threads); i++, nx++) {
+ for (nx = __MW_APP_TAB__; nx != &__MW_APP_TAB_END__; nx++) {
printf("Starting %s\n", nx->name);
cyg_thread_resume(nx->t);
- // Special case - run additional code, specific to this environment
- // only after the server has had a chance to startup
- if (i == 2) {
- ecos_nx_init(nanox_data_index);
+ if (nx->init) {
+ (nx->init)(nanox_data_index);
}
}
printf("SYSTEM THREADS STARTED!\n");
}
void cyg_user_start(void)
{
- struct nx_thread *nx;
-
- nx = &_threads[0];
- cyg_thread_create(nx->prio,
- nx->entry,
+ // Create the initial thread and start it up
+ cyg_thread_create(ECOS_MW_STARTUP_PRIORITY,
+ startup,
(cyg_addrword_t) 0,
- nx->name,
- (void *)nx->stack, STACKSIZE,
- &nx->t,
- &nx->t_obj);
- cyg_thread_resume(nx->t);
+ "System startup",
+ (void *)startup_stack, STACKSIZE,
+ &startup_thread,
+ &startup_thread_obj);
+ cyg_thread_resume(startup_thread);
}
Index: services/gfx/mw/current/src/ecos/nanowm_thread.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/services/gfx/mw/current/src/ecos/nanowm_thread.c,v
retrieving revision 1.1
diff -u -5 -p -r1.1 nanowm_thread.c
--- services/gfx/mw/current/src/ecos/nanowm_thread.c 20 May 2002 22:25:37 -0000 1.1
+++ services/gfx/mw/current/src/ecos/nanowm_thread.c 30 Aug 2003 21:18:41 -0000
@@ -30,18 +30,22 @@
#include <cyg/infra/diag.h>
#define MWINCLUDECOLORS
#include "nano-X.h"
+#include <microwin/ecos_mw_app.h>
+
+extern void ecos_nx_init(CYG_ADDRWORD data);
+_mw_app("Nano-WM", nanowm, ECOS_MW_NANOX_PRIORITY, ecos_nx_init);
//
// Component interfaces
//
externC int nanowm_main(int argc, char *argv[]);
-int
+static void
nanowm_thread(CYG_ADDRWORD data)
{
int argc = 0;
char **argv;
Index: services/gfx/mw/current/src/ecos/nanox_thread.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/services/gfx/mw/current/src/ecos/nanox_thread.c,v
retrieving revision 1.1
diff -u -5 -p -r1.1 nanox_thread.c
--- services/gfx/mw/current/src/ecos/nanox_thread.c 20 May 2002 22:25:37 -0000 1.1
+++ services/gfx/mw/current/src/ecos/nanox_thread.c 30 Aug 2003 21:18:43 -0000
@@ -30,20 +30,23 @@
#include <cyg/infra/diag.h>
#define MWINCLUDECOLORS
#include "nano-X.h"
+#include <microwin/ecos_mw_app.h>
+_mw_app("Nano-X server", nanox, ECOS_MW_NANOX_PRIORITY, 0);
//
// Component interfaces
//
externC int nanox_main(int argc, char *argv[]);
-int
+static void
nanox_thread(CYG_ADDRWORD data)
{
int argc = 0;
char **argv;
+ printf("%s.%d\n", __FUNCTION__, __LINE__);
nanox_main(argc, argv);
}
Index: services/gfx/mw/current/src/ecos/ntetris_thread.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/services/gfx/mw/current/src/ecos/ntetris_thread.c,v
retrieving revision 1.1
diff -u -5 -p -r1.1 ntetris_thread.c
--- services/gfx/mw/current/src/ecos/ntetris_thread.c 20 May 2002 22:25:37 -0000 1.1
+++ services/gfx/mw/current/src/ecos/ntetris_thread.c 30 Aug 2003 21:19:18 -0000
@@ -30,18 +30,20 @@
#include <cyg/infra/diag.h>
#define MWINCLUDECOLORS
#include "nano-X.h"
+#include <microwin/ecos_mw_app.h>
+_mw_app("Nano-tetris demo", ntetris, ECOS_MW_NANOX_PRIORITY, 0);
//
// Component interfaces
//
externC int ntetris_main(int argc, char *argv[]);
-int
+static void
ntetris_thread(CYG_ADDRWORD data)
{
int argc = 1;
char *argv[] = {"ntetris" };
Index: services/gfx/mw/current/src/ecos/world_thread.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/services/gfx/mw/current/src/ecos/world_thread.c,v
retrieving revision 1.1
diff -u -5 -p -r1.1 world_thread.c
--- services/gfx/mw/current/src/ecos/world_thread.c 20 May 2002 22:25:37 -0000 1.1
+++ services/gfx/mw/current/src/ecos/world_thread.c 30 Aug 2003 21:19:05 -0000
@@ -30,18 +30,20 @@
#include <cyg/infra/diag.h>
#define MWINCLUDECOLORS
#include "nano-X.h"
+#include <microwin/ecos_mw_app.h>
+_mw_app("World demo", world, ECOS_MW_APP_PRIORITY, 0);
//
// Component interfaces
//
externC int world_main(int argc, char *argv[]);
-int
+static void
world_thread(CYG_ADDRWORD data)
{
int argc = 1;
char *argv[] = {"world" };