Exemplo n.º 1
0
Arquivo: load.c Projeto: juddy/edcde
int
abil_loadmsg_clear(void)
{
	move_string(Current_Object, NULL);
	move_string(Attribute, NULL);
	move_string(Action_Attr, NULL);
	move_string(File, NULL);
	return 0;
}
Exemplo n.º 2
0
void parse_file_work(struct sdp_work *curr, const char *filename, const char *p)
{
	const char *start = p;

	p = move_string(curr->filename, p, sizeof(curr->filename) - 1);
	p = skip(p,':');
	for (;;) {
		const char *q = p;
		if ((!*p) || (*p == '#')  || (*p == '\n') || (*p == 0x0d))
			break;
		if (strncmp(p, "dcd", 3) == 0) {
			p += 3;
			p = skip(p,',');
			curr->dcd = 1;
		}
		if (strncmp(p, "clear_dcd", 9) == 0) {
			p += 9;
			p = skip(p,',');
			curr->clear_dcd = 1;
//			printf("clear_dcd\n");
		}
		if (strncmp(p, "no_clear_boot_data", 18) == 0) {
			p += 18;
			p = skip(p,',');
			curr->no_clear_boot_data = 1;
//			printf("clear_dcd\n");
		}
		if (strncmp(p, "plug", 4) == 0) {
			p += 4;
			p = skip(p,',');
			curr->plug = 1;
//			printf("plug\n");
		}
		if (strncmp(p, "load", 4) == 0) {
			p += 4;
			curr->load_addr = get_val(&p, 16);
			p = skip(p,',');
		}
		if (strncmp(p, "jump", 4) == 0) {
			p += 4;
			curr->jump_mode = J_ADDR;
			curr->jump_addr = get_val(&p, 16);
			if (strncmp(p, "header2", 7) == 0) {
				p += 7;
				p = skip(p,',');
				curr->jump_mode = J_HEADER2;
			} else if (strncmp(p, "header", 6) == 0) {
				p += 6;
				p = skip(p,',');
				curr->jump_mode = J_HEADER;
			}
			p = skip(p,',');
//			printf("jump\n");
		}
		if (q == p) {
			printf("%s: syntax error: %s {%s}\n", filename, p, start);
			break;
		}
	}
}
Exemplo n.º 3
0
/*
 * Parse USB specific machine configuration
 */
static struct mach_id *parse_imx_conf(char const *filename)
{
	unsigned short vid;
	unsigned short pid;
	char line[512];
	struct mach_id *head = NULL;
	struct mach_id *tail = NULL;
	struct mach_id *curr = NULL;
	const char *p;

	FILE* xfile = fopen(filename, "rb" );
	if (!xfile) {
		printf("Could not open file: %s\n", filename);
		return NULL;
	}

	while (fgets(line, sizeof(line), xfile) != NULL) {
		p = line;
		while (*p==' ') p++;
		if (p[0] == '#')
			continue;
		vid = get_val(&p, 16);
		if (p[0] != ':') {
			printf("Syntax error(missing ':'): %s [%s]\n", p, line);
			continue;
		}
		p++;
		pid = get_val(&p, 16);
		if (p[0] != ',') {
			printf("Syntax error(missing ','): %s [%s]\n", p, line);
			continue;
		}
		p++;
		while (*p==' ') p++;
		if (!(vid && pid)) {
			printf("vid/pid cannot be 0: %s [%s]\n", p, line);
			continue;
		}
		curr = (struct mach_id *)malloc(sizeof(struct mach_id));
		curr->next = NULL;
		curr->vid = vid;
		curr->pid = pid;
		move_string(curr->file_name, p, sizeof(curr->file_name) - 1);
		if (!head)
			head = curr;
		if (tail)
			tail->next = curr;
		tail = curr;
		printf("vid=0x%04x pid=0x%04x file_name=%s\n", curr->vid, curr->pid, curr->file_name);
	}
	fclose(xfile);
	return head;
}
Exemplo n.º 4
0
bool TextConsole::feed(int key) {
    // interprets a keycode and perform the action (or write a letter)

    RowPtr r;
    LinkList<Row> &list = rows;
    LinkList<Row>::iterator it = std::find(list.begin(), list.end(), cur_row);
    switch(key) {

    case KEY_NEWLINE:
    case KEY_ENTER:

        r = MakeShared<Row>();
        if(it != list.end()) ++it;
        list.insert(it, r);

        if(cur_row->pos < cur_row->len) {
            // if cursor is not at the end of the row

            move_string(r, cur_row, cur_row->len - cur_row->pos);

        }

        cur_y++;

        // scrolling
        if(cur_y>h) {
            it = std::find(list.begin(), list.end(), vis_row_in);
            if(it != list.end() && (++it) != list.end()) {
                vis_row_in = *it;
            } else {
                vis_row_in = NULL;
            }
            cur_y = h;

        } // else  refresh_below();

        cur_row = r;
        cur_x = 0;

        refresh();

        break;

    case KEY_CTRL_L:
        refresh();
        break;

    case KEY_BACKSPACE_ASCII:
    case KEY_BACKSPACE:
    case KEY_BACKSPACE_APPLE:
    case KEY_BACKSPACE_SOMETIMES:
        cur_row->backspace();

        if(cur_x > 0) {

            cur_x--; // backwards with cursor
            refresh_current();

        } else // backspace at the beginning of a row
        if(it != list.begin()) { // there is an upper row
            r = *(--it);

            // upper row is empty, just delete it
            if(r->len <1) {
                list.erase(it);
                cur_y--;

                // upper row is not empty, append to end
            } else {
                r->pos = r->len;
                move_string(r, cur_row, cur_row->len);
                // delete current row (now empty)
                list.erase(++it);
                cur_y--;

                cur_row = r;
            }

            if(cur_y <1) { // we are up in the screen

                vis_row_in = cur_row;
                cur_y = 0;
                refresh();

            } else { // or there is more up

                // so delete a row
                // cur_row->rem();
                // delete cur_row;

                // move cursor up one line
                //	cur_y--;
                // refresh_below();
                refresh();

            }

            cur_x = r->pos;
        }

        break;

    case KEY_TAB:
        if(cur_x < w) cur_x += 8;
        if(cur_x > w) cur_x = w;
        break;

    case KEY_LEFT:
        if(cur_x<=0) break;
        cur_x--;
        cur_row->pos--;
        break;

    case KEY_RIGHT:
        if(cur_x >= w) break;
        if(cur_row->pos >= cur_row->len) break;
        cur_x++;
        cur_row->pos++;
        break;

    case KEY_UP:
        if(cur_y>0) {

            cur_y--;
            cur_row = *(--it);
            if(cur_x > cur_row->len)
                cur_x = cur_row->len;
            cur_row->pos = cur_x;

        } else { // scroll

            if(it == list.begin()) break;
            vis_row_in = cur_row = *(--it);
            refresh();

        }
        break;

    case KEY_DOWN:
        if(cur_y<h) {

            if(it != list.end() && (++it) != list.end()) {
                cur_y++;
                cur_row = *it;
                // cursor positioning
                if(cur_x > cur_row->len)
                    cur_x = cur_row->len;
                cur_row->pos = cur_x;
                //
            }

        } else { // scrolling

            if(it == list.end() || (++it) == list.end()) break;
            cur_row = *it;
            // scroll down the pointer to upper row
            it = std::find(list.begin(), list.end(), vis_row_in);
            vis_row_in = *(++it);
            refresh();

        }
        break;


    default: // insert a new char

        // fits in widget width?
        if(cur_x < w) {

            cur_row->insert_char(key);

            refresh_current();

            cur_x++;

        } // else wrap to next line (TODO)

        break;
    }

    return true;
}
Exemplo n.º 5
0
struct sdp_dev *parse_conf(const char *filename)
{
	char line[512];
	FILE *xfile;
	const char *p;
	struct sdp_work *tail = NULL;
	struct sdp_work *curr = NULL;
	struct sdp_dev *usb = (struct sdp_dev *)malloc(sizeof(struct sdp_dev));
	if (!usb)
		return NULL;
	memset(usb, 0, sizeof(struct sdp_dev));

	xfile = fopen(filename, "rb" );
	if (!xfile) {
		printf("Could not open file: {%s}\n", filename);
		free(usb);
		return NULL;
	}
	printf("parse %s\n", filename);

	while (fgets(line, sizeof(line), xfile) != NULL) {
		p = line;
		while (*p==' ') p++;
		if (p[0] == '#')
			continue;
		if (p[0] == 0)
			continue;
		if (p[0] == '\n')
			continue;
		if (p[0] == 0x0d)
			continue;
		if (!usb->name[0]) {
			p = move_string(usb->name, p, sizeof(usb->name) - 1);
			continue;
		}
		if (!usb->max_transfer) {
			parse_transfer_type(usb, filename, p);
			continue;
		}
		/*
		 * #file:dcd,plug,load nnn,jump [nnn/header/header2]
		 */
		if (!curr) {
			curr = (struct sdp_work *)malloc(sizeof(struct sdp_work));
			if (!curr)
				break;
			memset(curr, 0, sizeof(struct sdp_work));
			if (!usb->work)
				usb->work = curr;
			if (tail)
				tail->next = curr;
			tail = curr;
			curr->load_addr = usb->ram[0].start + 0x03f00000;	/* default */
		}

		if (p[0] == ':') {
			parse_mem_work(curr, filename, p);
		} else {
			parse_file_work(curr, filename, p);
			curr = NULL;
		}
	}
	return usb;
}
Exemplo n.º 6
0
//Main program
int main() {
	
	/* Initialize SDL's video system and check for errors */
	if (SDL_Init(SDL_INIT_VIDEO) != 0) {

		printf("Unable to initialize SDL: %s\n", SDL_GetError());
		return 1;
	}
	
	/* Make sure SDL_Quit gets called when the program exits! */
	atexit(SDL_Quit);
	
	/*set window title*/
	SDL_WM_SetCaption("Space Invaders", "P");
	
	/* Attempt to set a 800x600 8 bit color video mode */
	screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 8, SDL_DOUBLEBUF );
	
	if (screen == NULL) {
		
		printf("Unable to set video mode: %s\n", SDL_GetError());
		return 1;
	}

	//load images
	load_image("cmap.bmp", &cmap);

	Uint32 next_game_tick = SDL_GetTicks();
	int sleep = 0;
	int quit = 0;
	SDL_Event event;

	/* Animate */
	while (quit == 0) {
		
		/* Grab a snapshot of the keyboard. */
		
		while (SDL_PollEvent(&event)) {

			switch(event.type) {
				
				case SDL_KEYDOWN:
					
					switch( event.key.keysym.sym ) {
					
						//exit out of game loop if escape is pressed
						case SDLK_ESCAPE:
							
							quit = 1;
						break;
						
						default:
						break;
					}
				break;
			}
		}
	
		draw_background();

		char s[] = "Well well well here it is finally a sine scroller, funny how easy it all is. and that its taken me so looooooooooooooooooooong";
		draw_string(s, sx, sy);
		move_string(s);
		
		/* Ask SDL to update the entire screen. */
		SDL_Flip(screen);

		next_game_tick += 1000 / 30;
		sleep = next_game_tick - SDL_GetTicks();
	
		if( sleep >= 0 ) {

            		SDL_Delay(sleep);
        	}
	}
	
	return 0;
}
Exemplo n.º 7
0
Arquivo: load.c Projeto: juddy/edcde
int
abil_loadmsg_set_file(STRING filename)
{
	return move_string(File, filename);
}
Exemplo n.º 8
0
Arquivo: load.c Projeto: juddy/edcde
int
abil_loadmsg_set_action_att(STRING actattname)
{
	return move_string(Action_Attr, actattname);
}
Exemplo n.º 9
0
Arquivo: load.c Projeto: juddy/edcde
int
abil_loadmsg_set_att(STRING attname)
{
	return move_string(Attribute, attname);
}
Exemplo n.º 10
0
Arquivo: load.c Projeto: juddy/edcde
int
abil_loadmsg_set_object(STRING objname)
{
	return move_string(Current_Object, objname);
}
Exemplo n.º 11
0
static struct usb_id *parse_conf(struct mach_id *mach)
{
	char line[512];
	FILE *xfile;
	char *p;
	char *q;
	int i;
	struct usb_work *tail = NULL;
	struct usb_work *curr = NULL;
	struct usb_id *usb = (struct usb_id *)malloc(sizeof(struct usb_id));
	if (!usb)
		return NULL;
	memset(usb, 0, sizeof(struct usb_id));

	xfile = fopen(mach->file_name, "rb" );
	if (!xfile) {
		printf("Could not open file: {%s}\n", mach->file_name);
		free(usb);
		return NULL;
	}
	printf("parse %s\n", mach->file_name);

	usb->vid = mach->vid;
	usb->pid = mach->pid;
	while (fgets(line, sizeof(line), xfile) != NULL) {
		p = line;
		while (*p==' ') p++;
		if (p[0] == '#')
			continue;
		if (p[0] == 0)
			continue;
		if (p[0] == '\n')
			continue;
		if (p[0] == 0x0d)
			continue;
		if (!usb->name[0]) {
			p = move_string(usb->name, p, sizeof(usb->name) - 1);
			continue;
		}
		if (!usb->max_transfer) {
			/*
			 * #hid/bulk,[old_header,]max packet size, {ram start, ram size}(repeat valid ram areas)
			 *hid,1024,0x10000000,1G,0x00907000,0x31000
			 *
			 */
			if (strncmp(p, "hid", 3) == 0) {
				p += 3;
				p = skip(p,',');
				usb->mode = MODE_HID;
			} else if (strncmp(p, "bulk", 4) == 0) {
				p += 4;
				p = skip(p,',');
				usb->mode = MODE_BULK;
			} else {
				printf("%s: hid/bulk expected\n", mach->file_name);
			}
			if (strncmp(p, "old_header", 10) == 0) {
				p += 10;
				p = skip(p,',');
				usb->header_type = HDR_MX51;
			} else {
				usb->header_type = HDR_MX53;
			}
			usb->max_transfer = get_val(&p, 10);
			p = skip(p,',');
			for (i = 0; i < 8; i++) {
				usb->ram[i].start = get_val(&p, 10);
				p = skip(p,',');
				usb->ram[i].size = get_val(&p, 10);
				if ((*p == 'G') || (*p == 'g')) {
					usb->ram[i].size <<= 30;
					p++;
				} else if ((*p == 'M') || (*p == 'm')) {
					usb->ram[i].size <<= 20;
					p++;
				} else if ((*p == 'K') || (*p == 'k')) {
					usb->ram[i].size <<= 10;
					p++;
				}
				p = skip(p,',');
				if ((*p == '#') || (*p == '\n') || (!*p))
					break;
			}
			continue;
		}
		/*
		 * #file:dcd,plug,load nnn,jump [nnn/header/header2]
		 */
		curr = (struct usb_work *)malloc(sizeof(struct usb_work));
		if (!curr)
			break;
		memset(curr, 0, sizeof(struct usb_work));
		curr->load_addr = usb->ram[0].start + 0x03f00000;	/* default */

		p = move_string(curr->filename, p, sizeof(curr->filename) - 1);
		p = skip(p,':');
		for (;;) {
			q = p;
			if ((!*p) || (*p == '#')  || (*p == '\n') || (*p == 0x0d))
					break;
			if (strncmp(p, "dcd", 3) == 0) {
				p += 3;
				p = skip(p,',');
				curr->dcd = 1;
			}
			if (strncmp(p, "clear_dcd", 9) == 0) {
				p += 9;
				p = skip(p,',');
				curr->clear_dcd = 1;
//				printf("clear_dcd\n");
			}
			if (strncmp(p, "plug", 4) == 0) {
				p += 4;
				p = skip(p,',');
				curr->plug = 1;
//				printf("plug\n");
			}
			if (strncmp(p, "load", 4) == 0) {
				p += 4;
				curr->load_addr = get_val(&p, 16);
				p = skip(p,',');
			}
			if (strncmp(p, "jump", 4) == 0) {
				p += 4;
				curr->jump_mode = J_ADDR;
				curr->jump_addr = get_val(&p, 16);
				if (strncmp(p, "header2", 7) == 0) {
					p += 7;
					p = skip(p,',');
					curr->jump_mode = J_HEADER2;
				} else if (strncmp(p, "header", 6) == 0) {
					p += 6;
					p = skip(p,',');
					curr->jump_mode = J_HEADER;
				}
				p = skip(p,',');
//				printf("jump\n");
			}
			if (q == p) {
				printf("%s: syntax error: %s {%s}\n", mach->file_name, p, line);
				break;
			}
		}
		if (!usb->work)
			usb->work = curr;
		if (tail) {
			tail->next = curr;
		}
		tail = curr;
	}
	return usb;
}
Exemplo n.º 12
0
bool TextConsole::feed(int key) {
  // interprets a keycode and perform the action (or write a letter)
  
  Row *r;
  
  switch(key) {
    
  case KEY_NEWLINE:
  case KEY_ENTER:
    
    r = new Row();
    
    rows.insert_after(r, cur_row);
    
    if(cur_row->pos < cur_row->len) {
      // if cursor is not at the end of the row
      
      move_string(r, cur_row,
		  cur_row->len - cur_row->pos);
      
    }
    
    cur_y++;
    
    // scrolling
    if(cur_y>h) {
      
      vis_row_in = (Row*) vis_row_in->next;
      cur_y = h;
      
    } // else  refresh_below();
    
    cur_row = r;
    cur_x = 0;

    refresh();
    
    break;
    
  case KEY_CTRL_L:
    refresh();
    break;
    
  case KEY_BACKSPACE_ASCII:
  case KEY_BACKSPACE:
  case KEY_BACKSPACE_APPLE:
  case KEY_BACKSPACE_SOMETIMES:
    
    cur_row->backspace();
    
    if(cur_x > 0) {
      
      cur_x--; // backwards with cursor
      refresh_current();
      
    } else // backspace at the beginning of a row
      if(cur_row->prev) { // there is an upper row
	
	r = (Row*) cur_row->prev; 
	
	// upper row is empty, just delete it
	if(r->len <1) {
	  
	  r->rem();
	  delete r;
	  cur_y--;
	  
	  // upper row is not empty, append to end
	} else {
	  
	  r->pos = r->len;
	  move_string(r, cur_row, cur_row->len);
	  // delete current row (now empty)
	  cur_row->rem();
	  delete cur_row;
	  cur_y--;
	  
	  cur_row = r;
	}
	
	if(cur_y <1) { // we are up in the screen
	  
	  vis_row_in = cur_row;
	  cur_y = 0;
	  refresh();
	  
	} else { // or there is more up
	  
	  // so delete a row
	  // cur_row->rem();
	  // delete cur_row;
	  
	  // move cursor up one line
	  //	cur_y--;
	  // refresh_below();
	  refresh();
	  
	}
	
	cur_x = r->pos;
      }
    
    break;
    
  case KEY_TAB:
    if(cur_x < w) cur_x += 8;
    if(cur_x > w) cur_x = w;
    break;
    
  case KEY_LEFT:
    if(cur_x<=0) break;
    cur_x--;
    cur_row->pos--;
    break;
    
  case KEY_RIGHT:
    if(cur_x >= w) break;
    if(cur_row->pos >= cur_row->len) break;
    cur_x++;
    cur_row->pos++;
    break;
    
  case KEY_UP:
    if(cur_y>0) {
      
      cur_y--;
      cur_row = (Row*) cur_row->prev;
      if(cur_x > cur_row->len)
	cur_x = cur_row->len;
      cur_row->pos = cur_x;
      
    } else { // scroll
      
      if(!cur_row->prev) break;
      vis_row_in = cur_row = (Row*) cur_row->prev;
      refresh();
      
    }
    break;
    
  case KEY_DOWN:
    if(cur_y<h) {
      
      if(cur_row->next) {
	
	cur_y++;
	cur_row = (Row*) cur_row->next;
	// cursor positioning
	if(cur_x > cur_row->len)
	  cur_x = cur_row->len;
	cur_row->pos = cur_x;
	//
      } 
      
    } else { // scrolling
      
      if(!cur_row->next) break;
      cur_row = (Row*) cur_row->next;
      // scroll down the pointer to upper row
      vis_row_in = (Row*) vis_row_in->next;
      refresh();
      
    }
    break;
    
    
  default: // insert a new char
    
    // fits in widget width?
    if(cur_x < w) {
      
      cur_row->insert_char(key);
      
      refresh_current();
      
      cur_x++;
      
    } // else wrap to next line (TODO)
    
    break;
  }
  
  return true;
}