void main(){ vdp_init(); port_init(); psg_init(); scene_type = SCENE_DEMO; while(373){ stage = 0; /* リセットしないとデモでぷんぷん丸が滑り続ける */ current_player = 0; while(373){ scene_type = SCENE_DEMO; title_init(); title_main(); if(scene_type == SCENE_LOAD) break; if(scene_type == SCENE_SOUND_TEST){ sound_test_init(); sound_test_main(); scene_type = SCENE_DEMO; }else{ intro_main(); } } intro_main(); score_init(); level = 0; /* cheat */ if(ports[0].button & BUTTON_UP) stage = 1; if(ports[0].button & BUTTON_LEFT) stage = 2; if(ports[0].button & BUTTON_RIGHT) stage = 3; if(ports[0].button & BUTTON_DOWN){ scene_type = SCENE_ALL_CLEAR; }else{ while(373){ game_init(); map_show(); game_set_bgm(); game_main(); game_swap_players(); psg_init(); /* game over when there is no players */ if((players_continue[0] == 0) && (players_continue[1] == 0)){ break; } } } if(scene_type == SCENE_ALL_CLEAR){ stage = 0; /* リセットしないとデモでぷんぷん丸が滑り続ける */ current_player = 0; intro_ending_main(); /* intro loop */ ending_main(); /* ending loop */ } gameover_main("- GAME OVER -"); } }
void ux_init() { IOCON_PIO1_4 = 0x000000d0; GPIO1DIR &= ~(1 << 4); IOCON_PIO1_5 = 0x000000d0; GPIO1DIR &= ~(1 << 5); psg_init(); }
int main(int argc, char ** argv) { set_exe_str(argv[0]); data_block *blocks = NULL; data_block *seek_block = NULL; uint32_t seek_offset; uint32_t block_offset; uint32_t fps = 60; config = load_config(argv[0]); render_init(320, 240, "vgm play", 60, 0); uint32_t opts = 0; if (argc >= 3 && !strcmp(argv[2], "-y")) { opts |= YM_OPT_WAVE_LOG; } ym2612_context y_context; ym_init(&y_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_YM, render_audio_buffer(), opts); psg_context p_context; psg_init(&p_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_PSG, render_audio_buffer()); FILE * f = fopen(argv[1], "rb"); vgm_header header; fread(&header, sizeof(header), 1, f); if (header.version < 0x150 || !header.data_offset) { header.data_offset = 0xC; } fseek(f, header.data_offset + 0x34, SEEK_SET); uint32_t data_size = header.eof_offset + 4 - (header.data_offset + 0x34); uint8_t * data = malloc(data_size); fread(data, 1, data_size, f); fclose(f); uint32_t mclks_sample = MCLKS_NTSC / 44100; uint32_t loop_count = 2; uint8_t * end = data + data_size; uint8_t * cur = data; uint32_t current_cycle = 0; while (cur < end) { uint8_t cmd = *(cur++); switch(cmd) { case CMD_PSG_STEREO: //ignore for now cur++; break; case CMD_PSG: psg_write(&p_context, *(cur++)); break; case CMD_YM2612_0: ym_address_write_part1(&y_context, *(cur++)); ym_data_write(&y_context, *(cur++)); break; case CMD_YM2612_1: ym_address_write_part2(&y_context, *(cur++)); ym_data_write(&y_context, *(cur++)); break; case CMD_WAIT: { uint32_t wait_time = *(cur++); wait_time |= *(cur++) << 8; wait_time *= mclks_sample; vgm_wait(&y_context, &p_context, ¤t_cycle, wait_time); break; } case CMD_WAIT_60: vgm_wait(&y_context, &p_context, ¤t_cycle, 735 * mclks_sample); break; case CMD_WAIT_50: vgm_wait(&y_context, &p_context, ¤t_cycle, 882 * mclks_sample); break; case CMD_END: if (header.loop_offset && --loop_count) { cur = data + header.loop_offset + 0x1C - (header.data_offset + 0x34); } else { //TODO: fade out return 0; } break; case CMD_DATA: { cur++; //skip compat command uint8_t data_type = *(cur++); uint32_t data_size = *(cur++); data_size |= *(cur++) << 8; data_size |= *(cur++) << 16; data_size |= *(cur++) << 24; if (data_type == DATA_YM2612_PCM) { data_block ** curblock = &blocks; while(*curblock) { curblock = &((*curblock)->next); } *curblock = malloc(sizeof(data_block)); (*curblock)->size = data_size; (*curblock)->type = data_type; (*curblock)->data = cur; (*curblock)->next = NULL; } else { fprintf(stderr, "Skipping data block with unrecognized type %X\n", data_type); } cur += data_size; break; } case CMD_DATA_SEEK: { uint32_t new_offset = *(cur++); new_offset |= *(cur++) << 8; new_offset |= *(cur++) << 16; new_offset |= *(cur++) << 24; if (!seek_block || new_offset < seek_offset) { seek_block = blocks; seek_offset = 0; block_offset = 0; } while (seek_block && (seek_offset - block_offset + seek_block->size) < new_offset) { seek_offset += seek_block->size - block_offset; seek_block = seek_block->next; block_offset = 0; } block_offset += new_offset-seek_offset; seek_offset = new_offset; break; } default: if (cmd >= CMD_WAIT_SHORT && cmd < (CMD_WAIT_SHORT + 0x10)) { uint32_t wait_time = (cmd & 0xF) + 1; wait_time *= mclks_sample; vgm_wait(&y_context, &p_context, ¤t_cycle, wait_time); } else if (cmd >= CMD_YM2612_DAC && cmd < CMD_DAC_STREAM_SETUP) { if (seek_block) { ym_address_write_part1(&y_context, 0x2A); ym_data_write(&y_context, seek_block->data[block_offset++]); seek_offset++; if (block_offset > seek_block->size) { seek_block = seek_block->next; block_offset = 0; } } else { fputs("Encountered DAC write command but data seek pointer is invalid!\n", stderr); } uint32_t wait_time = (cmd & 0xF); if (wait_time) { wait_time *= mclks_sample; vgm_wait(&y_context, &p_context, ¤t_cycle, wait_time); } } else { fatal_error("unimplemented command: %X at offset %X\n", cmd, (unsigned int)(cur - data - 1)); } } } return 0; }
int main(int argc, char *argv[]) { int c; struct state *state = NULL; #if TEST_BUILD struct test_case *test_case; #endif prefs_init(); while(1) { int option_index = 0; static struct option long_options[] = { {"cart", required_argument, 0, OPT_CART }, {"force-extreme-disasm", no_argument, 0, OPT_FORCE_EXTREME_DISASM }, {"crop-screen", no_argument, 0, OPT_CROP_SCREEN }, {"loglevels" , required_argument, 0, OPT_LOGLEVELS }, {"audio-device" , required_argument, 0, OPT_AUDIO_DEVICE }, #if TEST_BUILD {"test-case", required_argument, 0, OPT_TEST_MODE}, #endif {0, 0, 0, 0 } }; c = getopt_long(argc, argv, "a:b:c:t:s:hdpyVAMvq", long_options, &option_index); if(c == -1) break; switch(c) { case 'a': prefs_set("diskimage", optarg); break; case 'b': prefs_set("diskimage2", optarg); break; case 'c': prefs_set("hdimage", optarg); break; case 't': prefs_set("tosimage", optarg); break; case 's': prefs_set("stateimage", optarg); break; case OPT_CART: prefs_set("cartimage", optarg); break; case OPT_FORCE_EXTREME_DISASM: cprint_all = 1; break; case OPT_CROP_SCREEN: crop_screen = 1; break; case OPT_LOGLEVELS: diag_set_module_levels(optarg); break; case OPT_AUDIO_DEVICE: if(!strncmp("list", optarg, 4)) { audio_device = -1; } else { audio_device = atoi(optarg); } break; #if TEST_BUILD case OPT_TEST_MODE: test_case_name = xstrdup(optarg); test_mode = 1; break; #endif case 'd': debugger = 1; break; case 'p': ppmoutput = 1; break; case 'y': psgoutput = 1; break; case 'v': verbosity++; break; case 'q': verbosity = MAX(1, verbosity-1); break; case 'V': vsync_delay = 1; break; case 'A': play_audio = 1; break; case 'M': monitor_sm124 = 1; break; case 'h': default: printf("Usage: %s [-AdMpqvVy] [-a diskimage1] [-b diskimage2] [-c hdimage] [-t tosimage] [-s stateimage]\n", argv[0]); exit(-1); break; } } /* Do not crop screen while debugging */ if(debugger) { crop_screen = 0; } if((prefs.diskimage == NULL) && (argv[optind] != NULL)) prefs_set("diskimage", argv[optind]); SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK|SDL_INIT_AUDIO); #if TEST_BUILD if(test_mode) { test_case = test_init(test_case_name); if(test_case) { if(test_case->cartridge_name) { prefs_set("cartimage", test_case->cartridge_name); } if(test_case->floppy_name) { prefs_set("diskimage", test_case->floppy_name); } } else { printf("DEBUG: Could not load test case %s\n", test_case_name); exit(-3); } } #endif /* Must run before hardware module inits */ mmu_init(); /* This must also be run before hardware modules. It gives a dummy area for some memory regions to not cause bus errors */ mmu_fallback_init(); /* Actual hardware */ ram_init(); rom_init(); cpu_init(); if(prefs.cartimage) { cartridge_init(prefs.cartimage); } else { cartridge_init(NULL); } psg_init(); midi_init(); acia_init(); ikbd_init(); #if INCLUDE_RTC rtc_init(); #endif dma_init(); fdc_init(); hdc_init(prefs.hdimage); mfp_init(); screen_disable(0); glue_init(); shifter_init(); if(debugger) { debug_init(); cpu_halt_for_debug(); } screen_init(); floppy_init(prefs.diskimage, prefs.diskimage2); if(prefs.stateimage) { state = state_load(prefs.stateimage); } if(state != NULL) state_restore(state); memset(&reset, 0, sizeof reset); reset.sa_sigaction = reset_action; sigaction(SIGHUP, &reset, NULL); while(cpu_run(CPU_RUN)); return 0; }