/** Generated by the FM chip when its programmable timer expires. */ __attribute__((interrupt)) void wpc_sound_firq (void) { m6809_firq_save_regs (); /* Emit 1st byte in DAC sequence */ if (dac_sequence) dac_write (*dac_sequence++); hard_delay (320); /* Emit 2nd byte in DAC sequence */ if (dac_sequence) { dac_write (*dac_sequence++); if (dac_sequence >= dac_sequence_end) { dac_sequence = NULL; } } /* Restart the timer */ fm_write (FM_ADDR_CLOCK_FUNCTIONS, FM_CLOCK_RESET_A+FM_CLOCK_IRQ_A+FM_CLOCK_LOAD_A); /* Restore registers and return */ m6809_firq_restore_regs (); return; }
void wpc_sound_init (void) { U16 i; U8 reg; dac_sequence = dac_sequence_end = NULL; /* Initialize the volume control */ set_volume (72); /* Initialize the FM chip */ for (reg=0; reg <= 0xFE; reg++) fm_write (reg, 0); fm_write (0xFF, 0); fm_write (FM_ADDR_CLOCK_FUNCTIONS, FM_CLOCK_RESET_A+FM_CLOCK_RESET_B); fm_write (FM_ADDR_CLOCK_A1, 0xFD); fm_write (FM_ADDR_CLOCK_A2, 0x02); fm_write (FM_ADDR_CLOCK_FUNCTIONS, FM_CLOCK_RESET_A+FM_CLOCK_IRQ_A+FM_CLOCK_LOAD_A); enable_firq (); /* Emit the 'gong' sound. * 1 sample per 1ms = 1000 samples/sec x 8 bits/sample = 8Khz */ dac_sequence = dac_beep; dac_sequence_end = dac_beep + sizeof (dac_beep); }
void z80_write_byte(unsigned int address, unsigned int data) { switch ((address >> 13) & 3) { case 2: /* YM2612 */ { fm_write(m68k.cycles, address & 3, data); return; } case 3: { switch ((address >> 8) & 0x7F) { case 0x60: /* Bank register */ { gen_zbank_w(data & 1); return; } case 0x7F: /* VDP */ { m68k_lockup_w_8(address, data); return; } default: { m68k_unused_8_w(address, data); return; } } } default: /* ZRAM */ { zram[address & 0x1FFF] = data; m68k.cycles += 2 * 7; /* ZRAM access latency (fixes Pacman 2: New Adventures & Puyo Puyo 2) */ return; } } }
/** save_dispatch_key Saves a base64 encoded key, as well as keeping it for future use. Pass it a key in the form of a null-terminated string. Returns -1 for error, 0 for success. */ int save_dispatch_key(const char *key) { int r; char *pub; if(dispatch != NULL) return 0; /* We have ignored you! */ dispatch = DSA_generate_parameters(DSA_KEYLEN, NULL, 0, NULL, NULL, NULL, NULL); if(dispatch == NULL) { io_debug("%s:%s():%d ", __FILE__, __func__, __LINE__); io_err("Not enough free memory! The walls are closing in!\n"); return -1; } pub = fm_abs(FM_KEY_DISPATCH_PUBLIC); r = !fm_write(FM_KEY_DISPATCH_PUBLIC, key, strlen(key)); r |= load_keys(pub, NULL, &dispatch); free(pub); return r; }
/** maybe_setup Creates the ~/.freenote/probe.team file, based on user input. Assumes that we are /not/ daemonized yet. Returns 0 for success (i.e., successful setup -or- the probe has already been set up), -1 for failure (ex., couldn't write to the file). */ int maybe_setup() { fm_init_base(); if(read_str_opt("auto-setup")) { return set_teamstring(read_str_opt("auto-setup")); } if(read_int_opt("setup") || !(fm_exists(FM_TEAM_INFO) || read_int_opt("no-tokens"))) { try(do_setup()); p_exit(PEXIT_NORMAL); } return 0; } /* do_setup Does the setup. Returns 0 for success, -1 for failure. It doesn't use io_* because it's interactive. */ static int do_setup() { char team[TEAM_MAXLEN], pin[PIN_MAXLEN], *tmp = fm_abs(FM_TEAM_INFO); int r; // It's a little long. printf( "FreeNote Probe Setup:\n" "Please follow the on-screen instructions.\n" "\n" "If you do not have a team, you can visit http://freenote." "petta-tech.com\nto register.\n" "If you don't want to register, you can run the probe with" "the\n'--no-tokens'/'-n' option, " "or add 'no-tokens' to ~/.freenote/rc.\n" "Please enter your team name: "); fgets(team, TEAM_MAXLEN, stdin); chomp(team); printf("Please enter your team's pin code: "); fgets(pin, PIN_MAXLEN, stdin); chomp(pin); printf("Writing the information to %s...\n", tmp); r = set_team_info(team, pin); try(r); printf("Ready to roll! Run the probe again, without --setup.\n"); return r; } /** set_team_info Generates ~/.freenote/probe.team from the two arguments (the team name and the pin code). Returns 0 for success, -1 for failure. */ int set_team_info(const char *team_name, const char *pin_code) { // strlen("team_name:", ";\n", "pin_code:", ";\n\0") = 24 char buffer[TEAM_MAXLEN + PIN_MAXLEN + 24]; sprintf(buffer, "team_name:%s;\npin_code:%s;\n", team_name, pin_code); return fm_write(FM_TEAM_INFO, buffer, strlen(buffer)) - 1; }