Exemple #1
0
void write_io(const uint16_t address, const uint8_t value, Gameboy* const gb)
{
	debug_printf("Hardware I/O: write $%X to $%X\n", value, address);

	if (address >= 0xFF10 && address <= 0xFF3F) {
		write_apu_register(address, value, &gb->apu);
		return;
	}

	switch (address) {
	case 0xFF00: write_joypad(value, &gb->joypad); break;
	case 0xFF04: write_div(value, &gb->hwstate); break;
	case 0xFF05: gb->hwstate.tima = value; break;
	case 0xFF06: gb->hwstate.tma = value; break;
	case 0xFF07: write_tac(value, &gb->hwstate); break;
	case 0xFF0F: gb->hwstate.int_flags = value&0x1F; break;
	case 0xFF40: write_lcdc(value, &gb->ppu, &gb->hwstate); break;
	case 0xFF41: write_stat(value, &gb->ppu); break;
	case 0xFF42: gb->ppu.scy = value; break;
	case 0xFF43: gb->ppu.scx = value; break;
	case 0xFF44: gb->ppu.ly = 0x00; break;
	case 0xFF45: gb->ppu.lyc = value; break;
	case 0xFF46: dma_transfer(value, gb); break;
	case 0xFF47: write_palette(value, &gb->ppu.bgp); break;
	case 0xFF48: write_palette(value, &gb->ppu.obp0); break;
	case 0xFF49: write_palette(value, &gb->ppu.obp1); break;
	case 0xFF4A: gb->ppu.wy = value; break;
	case 0xFF4B: gb->ppu.wx = value; break;
	default: break;
	}
}
int statement()
{
	int es = 0;
	if (es == 0 && strcmp(token, "if") == 0) es = if_stat();//<IF语句>
	if (es == 0 && strcmp(token, "while") == 0) es = while_stat();//<while语句>
	if (es == 0 && strcmp(token, "for") == 0) es = for_stat();//<for语句>
	//可在此处添加do语句调用
	if (es == 0 && strcmp(token, "read") == 0) es = read_stat();//<read语句>
	if (es == 0 && strcmp(token, "write") == 0) es = write_stat();//<write语句>
	if (es == 0 && strcmp(token, "{") == 0) es = compound_stat();//<复合语句>
	if (es == 0 && (strcmp(token, "ID") == 0 || strcmp(token, "NUM") == 0 || strcmp(token, "(") == 0)) es = expression_stat();//<表达式语句>
	return(es);
}
Exemple #3
0
void stat(){
	if (lookahead == INTEGER || lookahead == STRING || lookahead == BOOLEAN || lookahead == TABLE)
		def_stat();
	else if (lookahead == ID)
		assign_stat();
	else if (lookahead == IF)
		if_stat();
	else if (lookahead == WHILE)
		while_stat();
	else if (lookahead == READ)
		read_stat();
	else //(lookahead == WRITE)
		write_stat();
}
Exemple #4
0
static void
do_fstat(os_emul_data *emul,
	 unsigned call,
	 const int arg0,
	 cpu *processor,
	 unsigned_word cia)
{
  int fd = cpu_registers(processor)->gpr[arg0];
  unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
  struct stat buf;
  int status;
  SYS(fstat);
  /* Can't combine these statements, cuz fstat sets errno. */
  status = fstat(fd, &buf);
  emul_write_status(processor, status, errno);
  write_stat(stat_buf_addr, buf, processor, cia);
}
Exemple #5
0
static void
do_lstat(os_emul_data *emul,
	 unsigned call,
	 const int arg0,
	 cpu *processor,
	 unsigned_word cia)
{
  char path_buf[PATH_MAX];
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
  struct stat buf;
  int status;
  SYS(lstat);
  /* Can't combine these statements, cuz lstat sets errno. */
  status = lstat(path, &buf);
  emul_write_status(processor, status, errno);
  write_stat(stat_buf_addr, buf, processor, cia);
}
Exemple #6
0
static void
do_stat(os_emul_data *emul,
	unsigned call,
	const int arg0,
	cpu *processor,
	unsigned_word cia)
{
  char path_buf[PATH_MAX];
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  struct stat buf;
  int status;
  SYS(stat);
  status = stat(path, &buf);
  emul_write_status(processor, status, errno);
  if (status == 0)
    write_stat(stat_buf_addr, buf, processor, cia);
}
Exemple #7
0
/*Genera il codice per il nodo stat_list e crea lo scope del programma*/
Code stat_list(Pnode stat_list_node){
	//Definisco la variabile che contiene il codice da ritornare
	Code stat_list_code;
	stat_list_code.head = NULL;
	stat_list_code.tail = NULL;
	stat_list_code.size = 0;

	//Creo l'ambiente del programma
	push_environment();
	
	//Punto al primo stat
	Pnode stat_node = stat_list_node->child;
	//Ciclo lungo tutti gli stat_node
	while (stat_node!=NULL){
		//Creo il codice dello stat_node
		Code stat_code;
		switch (stat_node->type){
			case(N_DEF_STAT): 	stat_code = def_stat(stat_node);break;
			case(N_ASSIGN_STAT): 	stat_code = assign_stat(stat_node);break;
			case(N_IF_STAT): 	stat_code = if_stat(stat_node);break;
			case(N_WHILE_STAT): 	stat_code = while_stat(stat_node);break;
			case(N_READ_STAT): 	stat_code = read_stat(stat_node);break;
			case(N_WRITE_STAT): 	stat_code = write_stat(stat_node);break;
		}
		
		//Appendo il codice a stat_list_code
		stat_list_code = appcode(stat_list_code,stat_code);

		//Punto al fratello successivo
		stat_node = stat_node->brother;
	}
	
	//Appendo il codice per fare il pop dell'environment a stat_list_code
	if(numobj_in_current_env()!=0)
		stat_list_code = appcode(stat_list_code,makecode1(T_POP,numobj_in_current_env()));

	//elimino l'ambiente creato (elimina già le variabili dall'ambiente)
	pop_environment();

	return stat_list_code;
}
Exemple #8
0
Code stat(Pnode p)
{
    switch (p->type)
    {
        case N_DEF_STAT:
            return def_stat(p);
        case N_ASSIGN_STAT:
            return assign_stat(p);
        case N_IF_STAT:
            return if_stat(p);
        case N_WHILE_STAT:
            return while_stat(p);
        case N_READ_STAT:
            return read_stat(p);
        case N_WRITE_STAT:
            return write_stat(p);
        default:
            noderror(p);
    }
    return endcode();
}