hexsha
stringlengths 40
40
| repo
stringlengths 5
105
| path
stringlengths 3
173
| license
sequence | language
stringclasses 1
value | identifier
stringlengths 1
438
| return_type
stringlengths 1
106
⌀ | original_string
stringlengths 21
40.7k
| original_docstring
stringlengths 18
13.4k
| docstring
stringlengths 11
3.24k
| docstring_tokens
sequence | code
stringlengths 14
20.4k
| code_tokens
sequence | short_docstring
stringlengths 0
4.36k
| short_docstring_tokens
sequence | comment
sequence | parameters
list | docstring_params
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
be9a609005eb490cb070ebef949295c8c030aa58 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/ui.c | [
"Unlicense"
] | C | handler_messagebox | UINT32 | static UINT32 handler_messagebox(running_machine *machine, UINT32 state)
{
ui_draw_text_box(astring_c(messagebox_text), JUSTIFY_LEFT, 0.5f, 0.5f, messagebox_backcolor);
return 0;
} | /*-------------------------------------------------
handler_messagebox - displays the current
messagebox_text string but handles no input
-------------------------------------------------*/ | displays the current
messagebox_text string but handles no input | [
"displays",
"the",
"current",
"messagebox_text",
"string",
"but",
"handles",
"no",
"input"
] | static UINT32 handler_messagebox(running_machine *machine, UINT32 state)
{
ui_draw_text_box(astring_c(messagebox_text), JUSTIFY_LEFT, 0.5f, 0.5f, messagebox_backcolor);
return 0;
} | [
"static",
"UINT32",
"handler_messagebox",
"(",
"running_machine",
"*",
"machine",
",",
"UINT32",
"state",
")",
"{",
"ui_draw_text_box",
"(",
"astring_c",
"(",
"messagebox_text",
")",
",",
"JUSTIFY_LEFT",
",",
"0.5f",
",",
"0.5f",
",",
"messagebox_backcolor",
")",
";",
"return",
"0",
";",
"}"
] | handler_messagebox - displays the current
messagebox_text string but handles no input | [
"handler_messagebox",
"-",
"displays",
"the",
"current",
"messagebox_text",
"string",
"but",
"handles",
"no",
"input"
] | [] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "state",
"type": "UINT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "state",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
be9a609005eb490cb070ebef949295c8c030aa58 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/ui.c | [
"Unlicense"
] | C | handler_messagebox_ok | UINT32 | static UINT32 handler_messagebox_ok(running_machine *machine, UINT32 state)
{
/* draw a standard message window */
ui_draw_text_box(astring_c(messagebox_text), JUSTIFY_LEFT, 0.5f, 0.5f, messagebox_backcolor);
/* an 'O' or left joystick kicks us to the next state */
if (state == 0 && (input_code_pressed_once(machine, KEYCODE_O) || ui_input_pressed(machine, IPT_UI_LEFT)))
state++;
/* a 'K' or right joystick exits the state */
else if (state == 1 && (input_code_pressed_once(machine, KEYCODE_K) || ui_input_pressed(machine, IPT_UI_RIGHT)))
state = UI_HANDLER_CANCEL;
/* if the user cancels, exit out completely */
else if (ui_input_pressed(machine, IPT_UI_CANCEL))
{
mame_schedule_exit(machine);
state = UI_HANDLER_CANCEL;
}
return state;
} | /*-------------------------------------------------
handler_messagebox_ok - displays the current
messagebox_text string and waits for an OK
-------------------------------------------------*/ | displays the current
messagebox_text string and waits for an OK | [
"displays",
"the",
"current",
"messagebox_text",
"string",
"and",
"waits",
"for",
"an",
"OK"
] | static UINT32 handler_messagebox_ok(running_machine *machine, UINT32 state)
{
ui_draw_text_box(astring_c(messagebox_text), JUSTIFY_LEFT, 0.5f, 0.5f, messagebox_backcolor);
if (state == 0 && (input_code_pressed_once(machine, KEYCODE_O) || ui_input_pressed(machine, IPT_UI_LEFT)))
state++;
else if (state == 1 && (input_code_pressed_once(machine, KEYCODE_K) || ui_input_pressed(machine, IPT_UI_RIGHT)))
state = UI_HANDLER_CANCEL;
else if (ui_input_pressed(machine, IPT_UI_CANCEL))
{
mame_schedule_exit(machine);
state = UI_HANDLER_CANCEL;
}
return state;
} | [
"static",
"UINT32",
"handler_messagebox_ok",
"(",
"running_machine",
"*",
"machine",
",",
"UINT32",
"state",
")",
"{",
"ui_draw_text_box",
"(",
"astring_c",
"(",
"messagebox_text",
")",
",",
"JUSTIFY_LEFT",
",",
"0.5f",
",",
"0.5f",
",",
"messagebox_backcolor",
")",
";",
"if",
"(",
"state",
"==",
"0",
"&&",
"(",
"input_code_pressed_once",
"(",
"machine",
",",
"KEYCODE_O",
")",
"||",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_LEFT",
")",
")",
")",
"state",
"++",
";",
"else",
"if",
"(",
"state",
"==",
"1",
"&&",
"(",
"input_code_pressed_once",
"(",
"machine",
",",
"KEYCODE_K",
")",
"||",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_RIGHT",
")",
")",
")",
"state",
"=",
"UI_HANDLER_CANCEL",
";",
"else",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_CANCEL",
")",
")",
"{",
"mame_schedule_exit",
"(",
"machine",
")",
";",
"state",
"=",
"UI_HANDLER_CANCEL",
";",
"}",
"return",
"state",
";",
"}"
] | handler_messagebox_ok - displays the current
messagebox_text string and waits for an OK | [
"handler_messagebox_ok",
"-",
"displays",
"the",
"current",
"messagebox_text",
"string",
"and",
"waits",
"for",
"an",
"OK"
] | [
"/* draw a standard message window */",
"/* an 'O' or left joystick kicks us to the next state */",
"/* a 'K' or right joystick exits the state */",
"/* if the user cancels, exit out completely */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "state",
"type": "UINT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "state",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
be9a609005eb490cb070ebef949295c8c030aa58 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/ui.c | [
"Unlicense"
] | C | handler_messagebox_anykey | UINT32 | static UINT32 handler_messagebox_anykey(running_machine *machine, UINT32 state)
{
/* draw a standard message window */
ui_draw_text_box(astring_c(messagebox_text), JUSTIFY_LEFT, 0.5f, 0.5f, messagebox_backcolor);
/* if the user cancels, exit out completely */
if (ui_input_pressed(machine, IPT_UI_CANCEL))
{
mame_schedule_exit(machine);
state = UI_HANDLER_CANCEL;
}
/* if any key is pressed, just exit */
else if (input_code_poll_switches(machine, FALSE) != INPUT_CODE_INVALID)
state = UI_HANDLER_CANCEL;
return state;
} | /*-------------------------------------------------
handler_messagebox_anykey - displays the
current messagebox_text string and waits for
any keypress
-------------------------------------------------*/ | displays the
current messagebox_text string and waits for
any keypress | [
"displays",
"the",
"current",
"messagebox_text",
"string",
"and",
"waits",
"for",
"any",
"keypress"
] | static UINT32 handler_messagebox_anykey(running_machine *machine, UINT32 state)
{
ui_draw_text_box(astring_c(messagebox_text), JUSTIFY_LEFT, 0.5f, 0.5f, messagebox_backcolor);
if (ui_input_pressed(machine, IPT_UI_CANCEL))
{
mame_schedule_exit(machine);
state = UI_HANDLER_CANCEL;
}
else if (input_code_poll_switches(machine, FALSE) != INPUT_CODE_INVALID)
state = UI_HANDLER_CANCEL;
return state;
} | [
"static",
"UINT32",
"handler_messagebox_anykey",
"(",
"running_machine",
"*",
"machine",
",",
"UINT32",
"state",
")",
"{",
"ui_draw_text_box",
"(",
"astring_c",
"(",
"messagebox_text",
")",
",",
"JUSTIFY_LEFT",
",",
"0.5f",
",",
"0.5f",
",",
"messagebox_backcolor",
")",
";",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_CANCEL",
")",
")",
"{",
"mame_schedule_exit",
"(",
"machine",
")",
";",
"state",
"=",
"UI_HANDLER_CANCEL",
";",
"}",
"else",
"if",
"(",
"input_code_poll_switches",
"(",
"machine",
",",
"FALSE",
")",
"!=",
"INPUT_CODE_INVALID",
")",
"state",
"=",
"UI_HANDLER_CANCEL",
";",
"return",
"state",
";",
"}"
] | handler_messagebox_anykey - displays the
current messagebox_text string and waits for
any keypress | [
"handler_messagebox_anykey",
"-",
"displays",
"the",
"current",
"messagebox_text",
"string",
"and",
"waits",
"for",
"any",
"keypress"
] | [
"/* draw a standard message window */",
"/* if the user cancels, exit out completely */",
"/* if any key is pressed, just exit */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "state",
"type": "UINT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "state",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
be9a609005eb490cb070ebef949295c8c030aa58 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/ui.c | [
"Unlicense"
] | C | handler_ingame | UINT32 | static UINT32 handler_ingame(running_machine *machine, UINT32 state)
{
int is_paused = mame_is_paused(machine);
/* first draw the FPS counter */
if (showfps || myosd_fps || osd_ticks() < showfps_end)
{
ui_draw_text_full(video_get_speed_text(machine), 0.0f, 0.0f, 1.0f,
JUSTIFY_RIGHT, WRAP_WORD, DRAW_OPAQUE, ARGB_WHITE, ARGB_BLACK, NULL, NULL);
}
else
showfps_end = 0;
/* draw the profiler if visible */
if (show_profiler)
{
astring *profilertext = profiler_get_text(machine, astring_alloc());
ui_draw_text_full(astring_c(profilertext), 0.0f, 0.0f, 1.0f, JUSTIFY_LEFT, WRAP_WORD, DRAW_OPAQUE, ARGB_WHITE, ARGB_BLACK, NULL, NULL);
astring_free(profilertext);
}
/* if we're single-stepping, pause now */
if (single_step)
{
mame_pause(machine, TRUE);
single_step = FALSE;
}
#ifdef MESS
if (ui_mess_handler_ingame(machine))
return 0;
#endif /* MESS */
/* if the user pressed ESC, stop the emulation */
if (ui_input_pressed(machine, IPT_UI_CANCEL))
mame_schedule_exit(machine);
/* turn on menus if requested */
if (ui_input_pressed(machine, IPT_UI_CONFIGURE))
return ui_set_handler(ui_menu_ui_handler, 0);
/* if the on-screen display isn't up and the user has toggled it, turn it on */
if ((machine->debug_flags & DEBUG_FLAG_ENABLED) == 0 && ui_input_pressed(machine, IPT_UI_ON_SCREEN_DISPLAY))
return ui_set_handler(ui_slider_ui_handler, 1);
/* handle a reset request */
if (ui_input_pressed(machine, IPT_UI_RESET_MACHINE))
mame_schedule_hard_reset(machine);
if (ui_input_pressed(machine, IPT_UI_SOFT_RESET))
mame_schedule_soft_reset(machine);
/* handle a request to display graphics/palette */
if (ui_input_pressed(machine, IPT_UI_SHOW_GFX))
{
if (!is_paused)
mame_pause(machine, TRUE);
return ui_set_handler(ui_gfx_ui_handler, is_paused);
}
/* handle a save state request */
if (ui_input_pressed(machine, IPT_UI_SAVE_STATE))
{
mame_pause(machine, TRUE);
return ui_set_handler(handler_load_save, LOADSAVE_SAVE);
}
/* handle a load state request */
if (ui_input_pressed(machine, IPT_UI_LOAD_STATE))
{
mame_pause(machine, TRUE);
return ui_set_handler(handler_load_save, LOADSAVE_LOAD);
}
/* handle a save snapshot request */
if (ui_input_pressed(machine, IPT_UI_SNAPSHOT))
video_save_active_screen_snapshots(machine);
/* toggle pause */
if (ui_input_pressed(machine, IPT_UI_PAUSE))
{
/* with a shift key, it is single step */
if (is_paused && (input_code_pressed(machine, KEYCODE_LSHIFT) || input_code_pressed(machine, KEYCODE_RSHIFT)))
{
single_step = TRUE;
mame_pause(machine, FALSE);
}
else
mame_pause(machine, !mame_is_paused(machine));
}
/* handle a toggle cheats request */
if (ui_input_pressed(machine, IPT_UI_TOGGLE_CHEAT))
cheat_set_global_enable(machine, !cheat_get_global_enable(machine));
/* toggle movie recording */
if (ui_input_pressed(machine, IPT_UI_RECORD_MOVIE))
{
if (!video_mng_is_movie_active(machine))
{
video_mng_begin_recording(machine, NULL);
popmessage("REC START");
}
else
{
video_mng_end_recording(machine);
popmessage("REC STOP");
}
}
/* toggle profiler display */
if (ui_input_pressed(machine, IPT_UI_SHOW_PROFILER))
ui_set_show_profiler(!ui_get_show_profiler());
/* toggle FPS display */
if (ui_input_pressed(machine, IPT_UI_SHOW_FPS))
ui_set_show_fps(!ui_get_show_fps());
/* increment frameskip? */
if (ui_input_pressed(machine, IPT_UI_FRAMESKIP_INC))
{
/* get the current value and increment it */
int newframeskip = video_get_frameskip() + 1;
if (newframeskip > MAX_FRAMESKIP)
newframeskip = -1;
video_set_frameskip(newframeskip);
/* display the FPS counter for 2 seconds */
ui_show_fps_temp(2.0);
}
/* decrement frameskip? */
if (ui_input_pressed(machine, IPT_UI_FRAMESKIP_DEC))
{
/* get the current value and decrement it */
int newframeskip = video_get_frameskip() - 1;
if (newframeskip < -1)
newframeskip = MAX_FRAMESKIP;
video_set_frameskip(newframeskip);
/* display the FPS counter for 2 seconds */
ui_show_fps_temp(2.0);
}
/* toggle throttle? */
if (ui_input_pressed(machine, IPT_UI_THROTTLE))
video_set_throttle(!video_get_throttle());
/* check for fast forward */
if (input_type_pressed(machine, IPT_UI_FAST_FORWARD, 0))
{
video_set_fastforward(TRUE);
ui_show_fps_temp(0.5);
}
else
video_set_fastforward(FALSE);
return 0;
} | /*-------------------------------------------------
handler_ingame - in-game handler takes care
of the standard keypresses
-------------------------------------------------*/ | in-game handler takes care
of the standard keypresses | [
"in",
"-",
"game",
"handler",
"takes",
"care",
"of",
"the",
"standard",
"keypresses"
] | static UINT32 handler_ingame(running_machine *machine, UINT32 state)
{
int is_paused = mame_is_paused(machine);
if (showfps || myosd_fps || osd_ticks() < showfps_end)
{
ui_draw_text_full(video_get_speed_text(machine), 0.0f, 0.0f, 1.0f,
JUSTIFY_RIGHT, WRAP_WORD, DRAW_OPAQUE, ARGB_WHITE, ARGB_BLACK, NULL, NULL);
}
else
showfps_end = 0;
if (show_profiler)
{
astring *profilertext = profiler_get_text(machine, astring_alloc());
ui_draw_text_full(astring_c(profilertext), 0.0f, 0.0f, 1.0f, JUSTIFY_LEFT, WRAP_WORD, DRAW_OPAQUE, ARGB_WHITE, ARGB_BLACK, NULL, NULL);
astring_free(profilertext);
}
if (single_step)
{
mame_pause(machine, TRUE);
single_step = FALSE;
}
#ifdef MESS
if (ui_mess_handler_ingame(machine))
return 0;
#endif
if (ui_input_pressed(machine, IPT_UI_CANCEL))
mame_schedule_exit(machine);
if (ui_input_pressed(machine, IPT_UI_CONFIGURE))
return ui_set_handler(ui_menu_ui_handler, 0);
if ((machine->debug_flags & DEBUG_FLAG_ENABLED) == 0 && ui_input_pressed(machine, IPT_UI_ON_SCREEN_DISPLAY))
return ui_set_handler(ui_slider_ui_handler, 1);
if (ui_input_pressed(machine, IPT_UI_RESET_MACHINE))
mame_schedule_hard_reset(machine);
if (ui_input_pressed(machine, IPT_UI_SOFT_RESET))
mame_schedule_soft_reset(machine);
if (ui_input_pressed(machine, IPT_UI_SHOW_GFX))
{
if (!is_paused)
mame_pause(machine, TRUE);
return ui_set_handler(ui_gfx_ui_handler, is_paused);
}
if (ui_input_pressed(machine, IPT_UI_SAVE_STATE))
{
mame_pause(machine, TRUE);
return ui_set_handler(handler_load_save, LOADSAVE_SAVE);
}
if (ui_input_pressed(machine, IPT_UI_LOAD_STATE))
{
mame_pause(machine, TRUE);
return ui_set_handler(handler_load_save, LOADSAVE_LOAD);
}
if (ui_input_pressed(machine, IPT_UI_SNAPSHOT))
video_save_active_screen_snapshots(machine);
if (ui_input_pressed(machine, IPT_UI_PAUSE))
{
if (is_paused && (input_code_pressed(machine, KEYCODE_LSHIFT) || input_code_pressed(machine, KEYCODE_RSHIFT)))
{
single_step = TRUE;
mame_pause(machine, FALSE);
}
else
mame_pause(machine, !mame_is_paused(machine));
}
if (ui_input_pressed(machine, IPT_UI_TOGGLE_CHEAT))
cheat_set_global_enable(machine, !cheat_get_global_enable(machine));
if (ui_input_pressed(machine, IPT_UI_RECORD_MOVIE))
{
if (!video_mng_is_movie_active(machine))
{
video_mng_begin_recording(machine, NULL);
popmessage("REC START");
}
else
{
video_mng_end_recording(machine);
popmessage("REC STOP");
}
}
if (ui_input_pressed(machine, IPT_UI_SHOW_PROFILER))
ui_set_show_profiler(!ui_get_show_profiler());
if (ui_input_pressed(machine, IPT_UI_SHOW_FPS))
ui_set_show_fps(!ui_get_show_fps());
if (ui_input_pressed(machine, IPT_UI_FRAMESKIP_INC))
{
int newframeskip = video_get_frameskip() + 1;
if (newframeskip > MAX_FRAMESKIP)
newframeskip = -1;
video_set_frameskip(newframeskip);
ui_show_fps_temp(2.0);
}
if (ui_input_pressed(machine, IPT_UI_FRAMESKIP_DEC))
{
int newframeskip = video_get_frameskip() - 1;
if (newframeskip < -1)
newframeskip = MAX_FRAMESKIP;
video_set_frameskip(newframeskip);
ui_show_fps_temp(2.0);
}
if (ui_input_pressed(machine, IPT_UI_THROTTLE))
video_set_throttle(!video_get_throttle());
if (input_type_pressed(machine, IPT_UI_FAST_FORWARD, 0))
{
video_set_fastforward(TRUE);
ui_show_fps_temp(0.5);
}
else
video_set_fastforward(FALSE);
return 0;
} | [
"static",
"UINT32",
"handler_ingame",
"(",
"running_machine",
"*",
"machine",
",",
"UINT32",
"state",
")",
"{",
"int",
"is_paused",
"=",
"mame_is_paused",
"(",
"machine",
")",
";",
"if",
"(",
"showfps",
"||",
"myosd_fps",
"||",
"osd_ticks",
"(",
")",
"<",
"showfps_end",
")",
"{",
"ui_draw_text_full",
"(",
"video_get_speed_text",
"(",
"machine",
")",
",",
"0.0f",
",",
"0.0f",
",",
"1.0f",
",",
"JUSTIFY_RIGHT",
",",
"WRAP_WORD",
",",
"DRAW_OPAQUE",
",",
"ARGB_WHITE",
",",
"ARGB_BLACK",
",",
"NULL",
",",
"NULL",
")",
";",
"}",
"else",
"showfps_end",
"=",
"0",
";",
"if",
"(",
"show_profiler",
")",
"{",
"astring",
"*",
"profilertext",
"=",
"profiler_get_text",
"(",
"machine",
",",
"astring_alloc",
"(",
")",
")",
";",
"ui_draw_text_full",
"(",
"astring_c",
"(",
"profilertext",
")",
",",
"0.0f",
",",
"0.0f",
",",
"1.0f",
",",
"JUSTIFY_LEFT",
",",
"WRAP_WORD",
",",
"DRAW_OPAQUE",
",",
"ARGB_WHITE",
",",
"ARGB_BLACK",
",",
"NULL",
",",
"NULL",
")",
";",
"astring_free",
"(",
"profilertext",
")",
";",
"}",
"if",
"(",
"single_step",
")",
"{",
"mame_pause",
"(",
"machine",
",",
"TRUE",
")",
";",
"single_step",
"=",
"FALSE",
";",
"}",
"#ifdef",
"MESS",
"if",
"(",
"ui_mess_handler_ingame",
"(",
"machine",
")",
")",
"return",
"0",
";",
"#endif",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_CANCEL",
")",
")",
"mame_schedule_exit",
"(",
"machine",
")",
";",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_CONFIGURE",
")",
")",
"return",
"ui_set_handler",
"(",
"ui_menu_ui_handler",
",",
"0",
")",
";",
"if",
"(",
"(",
"machine",
"->",
"debug_flags",
"&",
"DEBUG_FLAG_ENABLED",
")",
"==",
"0",
"&&",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_ON_SCREEN_DISPLAY",
")",
")",
"return",
"ui_set_handler",
"(",
"ui_slider_ui_handler",
",",
"1",
")",
";",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_RESET_MACHINE",
")",
")",
"mame_schedule_hard_reset",
"(",
"machine",
")",
";",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_SOFT_RESET",
")",
")",
"mame_schedule_soft_reset",
"(",
"machine",
")",
";",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_SHOW_GFX",
")",
")",
"{",
"if",
"(",
"!",
"is_paused",
")",
"mame_pause",
"(",
"machine",
",",
"TRUE",
")",
";",
"return",
"ui_set_handler",
"(",
"ui_gfx_ui_handler",
",",
"is_paused",
")",
";",
"}",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_SAVE_STATE",
")",
")",
"{",
"mame_pause",
"(",
"machine",
",",
"TRUE",
")",
";",
"return",
"ui_set_handler",
"(",
"handler_load_save",
",",
"LOADSAVE_SAVE",
")",
";",
"}",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_LOAD_STATE",
")",
")",
"{",
"mame_pause",
"(",
"machine",
",",
"TRUE",
")",
";",
"return",
"ui_set_handler",
"(",
"handler_load_save",
",",
"LOADSAVE_LOAD",
")",
";",
"}",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_SNAPSHOT",
")",
")",
"video_save_active_screen_snapshots",
"(",
"machine",
")",
";",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_PAUSE",
")",
")",
"{",
"if",
"(",
"is_paused",
"&&",
"(",
"input_code_pressed",
"(",
"machine",
",",
"KEYCODE_LSHIFT",
")",
"||",
"input_code_pressed",
"(",
"machine",
",",
"KEYCODE_RSHIFT",
")",
")",
")",
"{",
"single_step",
"=",
"TRUE",
";",
"mame_pause",
"(",
"machine",
",",
"FALSE",
")",
";",
"}",
"else",
"mame_pause",
"(",
"machine",
",",
"!",
"mame_is_paused",
"(",
"machine",
")",
")",
";",
"}",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_TOGGLE_CHEAT",
")",
")",
"cheat_set_global_enable",
"(",
"machine",
",",
"!",
"cheat_get_global_enable",
"(",
"machine",
")",
")",
";",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_RECORD_MOVIE",
")",
")",
"{",
"if",
"(",
"!",
"video_mng_is_movie_active",
"(",
"machine",
")",
")",
"{",
"video_mng_begin_recording",
"(",
"machine",
",",
"NULL",
")",
";",
"popmessage",
"(",
"\"",
"\"",
")",
";",
"}",
"else",
"{",
"video_mng_end_recording",
"(",
"machine",
")",
";",
"popmessage",
"(",
"\"",
"\"",
")",
";",
"}",
"}",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_SHOW_PROFILER",
")",
")",
"ui_set_show_profiler",
"(",
"!",
"ui_get_show_profiler",
"(",
")",
")",
";",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_SHOW_FPS",
")",
")",
"ui_set_show_fps",
"(",
"!",
"ui_get_show_fps",
"(",
")",
")",
";",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_FRAMESKIP_INC",
")",
")",
"{",
"int",
"newframeskip",
"=",
"video_get_frameskip",
"(",
")",
"+",
"1",
";",
"if",
"(",
"newframeskip",
">",
"MAX_FRAMESKIP",
")",
"newframeskip",
"=",
"-1",
";",
"video_set_frameskip",
"(",
"newframeskip",
")",
";",
"ui_show_fps_temp",
"(",
"2.0",
")",
";",
"}",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_FRAMESKIP_DEC",
")",
")",
"{",
"int",
"newframeskip",
"=",
"video_get_frameskip",
"(",
")",
"-",
"1",
";",
"if",
"(",
"newframeskip",
"<",
"-1",
")",
"newframeskip",
"=",
"MAX_FRAMESKIP",
";",
"video_set_frameskip",
"(",
"newframeskip",
")",
";",
"ui_show_fps_temp",
"(",
"2.0",
")",
";",
"}",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_THROTTLE",
")",
")",
"video_set_throttle",
"(",
"!",
"video_get_throttle",
"(",
")",
")",
";",
"if",
"(",
"input_type_pressed",
"(",
"machine",
",",
"IPT_UI_FAST_FORWARD",
",",
"0",
")",
")",
"{",
"video_set_fastforward",
"(",
"TRUE",
")",
";",
"ui_show_fps_temp",
"(",
"0.5",
")",
";",
"}",
"else",
"video_set_fastforward",
"(",
"FALSE",
")",
";",
"return",
"0",
";",
"}"
] | handler_ingame - in-game handler takes care
of the standard keypresses | [
"handler_ingame",
"-",
"in",
"-",
"game",
"handler",
"takes",
"care",
"of",
"the",
"standard",
"keypresses"
] | [
"/* first draw the FPS counter */",
"/* draw the profiler if visible */",
"/* if we're single-stepping, pause now */",
"/* MESS */",
"/* if the user pressed ESC, stop the emulation */",
"/* turn on menus if requested */",
"/* if the on-screen display isn't up and the user has toggled it, turn it on */",
"/* handle a reset request */",
"/* handle a request to display graphics/palette */",
"/* handle a save state request */",
"/* handle a load state request */",
"/* handle a save snapshot request */",
"/* toggle pause */",
"/* with a shift key, it is single step */",
"/* handle a toggle cheats request */",
"/* toggle movie recording */",
"/* toggle profiler display */",
"/* toggle FPS display */",
"/* increment frameskip? */",
"/* get the current value and increment it */",
"/* display the FPS counter for 2 seconds */",
"/* decrement frameskip? */",
"/* get the current value and decrement it */",
"/* display the FPS counter for 2 seconds */",
"/* toggle throttle? */",
"/* check for fast forward */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "state",
"type": "UINT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "state",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
be9a609005eb490cb070ebef949295c8c030aa58 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/ui.c | [
"Unlicense"
] | C | handler_load_save | UINT32 | static UINT32 handler_load_save(running_machine *machine, UINT32 state)
{
char filename[20];
input_code code;
char file = 0;
/* if we're not in the middle of anything, skip */
if (state == LOADSAVE_NONE)
return 0;
/* okay, we're waiting for a key to select a slot; display a message */
if (state == LOADSAVE_SAVE)
ui_draw_message_window("Select position to save to");
else
ui_draw_message_window("Select position to load from");
/* check for cancel key */
if (ui_input_pressed(machine, IPT_UI_CANCEL))
{
/* display a popup indicating things were cancelled */
if (state == LOADSAVE_SAVE)
popmessage("Save cancelled");
else
popmessage("Load cancelled");
/* reset the state */
mame_pause(machine, FALSE);
return UI_HANDLER_CANCEL;
}
/* check for A-Z or 0-9 */
for (code = KEYCODE_A; code <= (input_code)KEYCODE_Z; code++)
if (input_code_pressed_once(machine, code))
file = code - KEYCODE_A + 'a';
if (file == 0)
for (code = KEYCODE_0; code <= (input_code)KEYCODE_9; code++)
if (input_code_pressed_once(machine, code))
file = code - KEYCODE_0 + '0';
if (file == 0)
for (code = KEYCODE_0_PAD; code <= (input_code)KEYCODE_9_PAD; code++)
if (input_code_pressed_once(machine, code))
file = code - KEYCODE_0_PAD + '0';
if (file == 0)
return state;
/* display a popup indicating that the save will proceed */
sprintf(filename, "%c", file);
if (state == LOADSAVE_SAVE)
{
popmessage("Save to position %c", file);
mame_schedule_save(machine, filename);
}
else
{
popmessage("Load from position %c", file);
mame_schedule_load(machine, filename);
}
/* remove the pause and reset the state */
mame_pause(machine, FALSE);
return UI_HANDLER_CANCEL;
} | /*-------------------------------------------------
handler_load_save - leads the user through
specifying a game to save or load
-------------------------------------------------*/ | leads the user through
specifying a game to save or load | [
"leads",
"the",
"user",
"through",
"specifying",
"a",
"game",
"to",
"save",
"or",
"load"
] | static UINT32 handler_load_save(running_machine *machine, UINT32 state)
{
char filename[20];
input_code code;
char file = 0;
if (state == LOADSAVE_NONE)
return 0;
if (state == LOADSAVE_SAVE)
ui_draw_message_window("Select position to save to");
else
ui_draw_message_window("Select position to load from");
if (ui_input_pressed(machine, IPT_UI_CANCEL))
{
if (state == LOADSAVE_SAVE)
popmessage("Save cancelled");
else
popmessage("Load cancelled");
mame_pause(machine, FALSE);
return UI_HANDLER_CANCEL;
}
for (code = KEYCODE_A; code <= (input_code)KEYCODE_Z; code++)
if (input_code_pressed_once(machine, code))
file = code - KEYCODE_A + 'a';
if (file == 0)
for (code = KEYCODE_0; code <= (input_code)KEYCODE_9; code++)
if (input_code_pressed_once(machine, code))
file = code - KEYCODE_0 + '0';
if (file == 0)
for (code = KEYCODE_0_PAD; code <= (input_code)KEYCODE_9_PAD; code++)
if (input_code_pressed_once(machine, code))
file = code - KEYCODE_0_PAD + '0';
if (file == 0)
return state;
sprintf(filename, "%c", file);
if (state == LOADSAVE_SAVE)
{
popmessage("Save to position %c", file);
mame_schedule_save(machine, filename);
}
else
{
popmessage("Load from position %c", file);
mame_schedule_load(machine, filename);
}
mame_pause(machine, FALSE);
return UI_HANDLER_CANCEL;
} | [
"static",
"UINT32",
"handler_load_save",
"(",
"running_machine",
"*",
"machine",
",",
"UINT32",
"state",
")",
"{",
"char",
"filename",
"[",
"20",
"]",
";",
"input_code",
"code",
";",
"char",
"file",
"=",
"0",
";",
"if",
"(",
"state",
"==",
"LOADSAVE_NONE",
")",
"return",
"0",
";",
"if",
"(",
"state",
"==",
"LOADSAVE_SAVE",
")",
"ui_draw_message_window",
"(",
"\"",
"\"",
")",
";",
"else",
"ui_draw_message_window",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"ui_input_pressed",
"(",
"machine",
",",
"IPT_UI_CANCEL",
")",
")",
"{",
"if",
"(",
"state",
"==",
"LOADSAVE_SAVE",
")",
"popmessage",
"(",
"\"",
"\"",
")",
";",
"else",
"popmessage",
"(",
"\"",
"\"",
")",
";",
"mame_pause",
"(",
"machine",
",",
"FALSE",
")",
";",
"return",
"UI_HANDLER_CANCEL",
";",
"}",
"for",
"(",
"code",
"=",
"KEYCODE_A",
";",
"code",
"<=",
"(",
"input_code",
")",
"KEYCODE_Z",
";",
"code",
"++",
")",
"if",
"(",
"input_code_pressed_once",
"(",
"machine",
",",
"code",
")",
")",
"file",
"=",
"code",
"-",
"KEYCODE_A",
"+",
"'",
"'",
";",
"if",
"(",
"file",
"==",
"0",
")",
"for",
"(",
"code",
"=",
"KEYCODE_0",
";",
"code",
"<=",
"(",
"input_code",
")",
"KEYCODE_9",
";",
"code",
"++",
")",
"if",
"(",
"input_code_pressed_once",
"(",
"machine",
",",
"code",
")",
")",
"file",
"=",
"code",
"-",
"KEYCODE_0",
"+",
"'",
"'",
";",
"if",
"(",
"file",
"==",
"0",
")",
"for",
"(",
"code",
"=",
"KEYCODE_0_PAD",
";",
"code",
"<=",
"(",
"input_code",
")",
"KEYCODE_9_PAD",
";",
"code",
"++",
")",
"if",
"(",
"input_code_pressed_once",
"(",
"machine",
",",
"code",
")",
")",
"file",
"=",
"code",
"-",
"KEYCODE_0_PAD",
"+",
"'",
"'",
";",
"if",
"(",
"file",
"==",
"0",
")",
"return",
"state",
";",
"sprintf",
"(",
"filename",
",",
"\"",
"\"",
",",
"file",
")",
";",
"if",
"(",
"state",
"==",
"LOADSAVE_SAVE",
")",
"{",
"popmessage",
"(",
"\"",
"\"",
",",
"file",
")",
";",
"mame_schedule_save",
"(",
"machine",
",",
"filename",
")",
";",
"}",
"else",
"{",
"popmessage",
"(",
"\"",
"\"",
",",
"file",
")",
";",
"mame_schedule_load",
"(",
"machine",
",",
"filename",
")",
";",
"}",
"mame_pause",
"(",
"machine",
",",
"FALSE",
")",
";",
"return",
"UI_HANDLER_CANCEL",
";",
"}"
] | handler_load_save - leads the user through
specifying a game to save or load | [
"handler_load_save",
"-",
"leads",
"the",
"user",
"through",
"specifying",
"a",
"game",
"to",
"save",
"or",
"load"
] | [
"/* if we're not in the middle of anything, skip */",
"/* okay, we're waiting for a key to select a slot; display a message */",
"/* check for cancel key */",
"/* display a popup indicating things were cancelled */",
"/* reset the state */",
"/* check for A-Z or 0-9 */",
"/* display a popup indicating that the save will proceed */",
"/* remove the pause and reset the state */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "state",
"type": "UINT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "state",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
be9a609005eb490cb070ebef949295c8c030aa58 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/ui.c | [
"Unlicense"
] | C | slider_get_screen_desc | char | static char *slider_get_screen_desc(const device_config *screen)
{
int screen_count = video_screen_count(screen->machine->config);
static char descbuf[256];
if (screen_count > 1)
sprintf(descbuf, "Screen '%s'", screen->tag);
else
strcpy(descbuf, "Screen");
return descbuf;
} | /*-------------------------------------------------
slider_get_screen_desc - returns the
description for a given screen
-------------------------------------------------*/ | returns the
description for a given screen | [
"returns",
"the",
"description",
"for",
"a",
"given",
"screen"
] | static char *slider_get_screen_desc(const device_config *screen)
{
int screen_count = video_screen_count(screen->machine->config);
static char descbuf[256];
if (screen_count > 1)
sprintf(descbuf, "Screen '%s'", screen->tag);
else
strcpy(descbuf, "Screen");
return descbuf;
} | [
"static",
"char",
"*",
"slider_get_screen_desc",
"(",
"const",
"device_config",
"*",
"screen",
")",
"{",
"int",
"screen_count",
"=",
"video_screen_count",
"(",
"screen",
"->",
"machine",
"->",
"config",
")",
";",
"static",
"char",
"descbuf",
"[",
"256",
"]",
";",
"if",
"(",
"screen_count",
">",
"1",
")",
"sprintf",
"(",
"descbuf",
",",
"\"",
"\"",
",",
"screen",
"->",
"tag",
")",
";",
"else",
"strcpy",
"(",
"descbuf",
",",
"\"",
"\"",
")",
";",
"return",
"descbuf",
";",
"}"
] | slider_get_screen_desc - returns the
description for a given screen | [
"slider_get_screen_desc",
"-",
"returns",
"the",
"description",
"for",
"a",
"given",
"screen"
] | [] | [
{
"param": "screen",
"type": "device_config"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "screen",
"type": "device_config",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
be9a609005eb490cb070ebef949295c8c030aa58 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/ui.c | [
"Unlicense"
] | C | slider_get_laserdisc_desc | char | static char *slider_get_laserdisc_desc(const device_config *laserdisc)
{
int ldcount = device_list_items(laserdisc->machine->config->devicelist, LASERDISC);
static char descbuf[256];
if (ldcount > 1)
sprintf(descbuf, "Laserdisc '%s'", laserdisc->tag);
else
strcpy(descbuf, "Laserdisc");
return descbuf;
} | /*-------------------------------------------------
slider_get_laserdisc_desc - returns the
description for a given laseridsc
-------------------------------------------------*/ | returns the
description for a given laseridsc | [
"returns",
"the",
"description",
"for",
"a",
"given",
"laseridsc"
] | static char *slider_get_laserdisc_desc(const device_config *laserdisc)
{
int ldcount = device_list_items(laserdisc->machine->config->devicelist, LASERDISC);
static char descbuf[256];
if (ldcount > 1)
sprintf(descbuf, "Laserdisc '%s'", laserdisc->tag);
else
strcpy(descbuf, "Laserdisc");
return descbuf;
} | [
"static",
"char",
"*",
"slider_get_laserdisc_desc",
"(",
"const",
"device_config",
"*",
"laserdisc",
")",
"{",
"int",
"ldcount",
"=",
"device_list_items",
"(",
"laserdisc",
"->",
"machine",
"->",
"config",
"->",
"devicelist",
",",
"LASERDISC",
")",
";",
"static",
"char",
"descbuf",
"[",
"256",
"]",
";",
"if",
"(",
"ldcount",
">",
"1",
")",
"sprintf",
"(",
"descbuf",
",",
"\"",
"\"",
",",
"laserdisc",
"->",
"tag",
")",
";",
"else",
"strcpy",
"(",
"descbuf",
",",
"\"",
"\"",
")",
";",
"return",
"descbuf",
";",
"}"
] | slider_get_laserdisc_desc - returns the
description for a given laseridsc | [
"slider_get_laserdisc_desc",
"-",
"returns",
"the",
"description",
"for",
"a",
"given",
"laseridsc"
] | [] | [
{
"param": "laserdisc",
"type": "device_config"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "laserdisc",
"type": "device_config",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d0a222117396f5c8f4bcab41c0cd2351128e2419 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/sound.c | [
"Unlicense"
] | C | route_sound | void | static void route_sound(running_machine *machine)
{
astring *tempstring = astring_alloc();
const device_config *curspeak;
const device_config *sound;
int outputnum;
/* first count up the inputs for each speaker */
for (sound = sound_first(machine->config); sound != NULL; sound = sound_next(sound))
{
const sound_config *config = (const sound_config *)sound->inline_config;
int numoutputs = stream_get_device_outputs(sound);
const sound_route *route;
/* iterate over all routes */
for (route = config->routelist; route != NULL; route = route->next)
{
const device_config *target_device = devtag_get_device(machine, route->target);
/* if neither found, it's fatal */
if (target_device == NULL)
fatalerror("Sound route \"%s\" not found!\n", route->target);
/* if we got a speaker, bump its input count */
if (target_device->type == SPEAKER_OUTPUT)
get_safe_token(target_device)->inputs += (route->output == ALL_OUTPUTS) ? numoutputs : 1;
}
}
/* now allocate the mixers and input data */
for (curspeak = speaker_output_first(machine->config); curspeak != NULL; curspeak = speaker_output_next(curspeak))
{
speaker_info *info = get_safe_token(curspeak);
if (info->inputs != 0)
{
info->mixer_stream = stream_create(curspeak, info->inputs, 1, machine->sample_rate, info, mixer_update);
state_save_register_postload(machine, mixer_postload, info->mixer_stream);
info->input = auto_alloc_array(machine, speaker_input, info->inputs);
info->inputs = 0;
}
else
logerror("Warning: speaker \"%s\" has no inputs\n", info->tag);
}
/* iterate again over all the sound chips */
for (sound = sound_first(machine->config); sound != NULL; sound = sound_next(sound))
{
const sound_config *config = (const sound_config *)sound->inline_config;
int numoutputs = stream_get_device_outputs(sound);
const sound_route *route;
/* iterate over all routes */
for (route = config->routelist; route != NULL; route = route->next)
{
const device_config *target_device = devtag_get_device(machine, route->target);
int inputnum = route->input;
sound_stream *stream;
int streamoutput;
/* iterate over all outputs, matching any that apply */
for (outputnum = 0; outputnum < numoutputs; outputnum++)
if (route->output == outputnum || route->output == ALL_OUTPUTS)
{
/* if it's a speaker, set the input */
if (target_device->type == SPEAKER_OUTPUT)
{
speaker_info *speakerinfo = get_safe_token(target_device);
/* generate text for the UI */
astring_printf(tempstring, "Speaker '%s': %s '%s'", target_device->tag, device_get_name(sound), sound->tag);
if (numoutputs > 1)
astring_catprintf(tempstring, " Ch.%d", outputnum);
/* fill in the input data on this speaker */
speakerinfo->input[speakerinfo->inputs].gain = route->gain;
speakerinfo->input[speakerinfo->inputs].default_gain = route->gain;
speakerinfo->input[speakerinfo->inputs].name = auto_strdup(machine, astring_c(tempstring));
/* connect the output to the input */
if (stream_device_output_to_stream_output(sound, outputnum, &stream, &streamoutput))
stream_set_input(speakerinfo->mixer_stream, speakerinfo->inputs++, stream, streamoutput, route->gain);
}
/* otherwise, it's a sound chip */
else
{
sound_stream *inputstream;
int streaminput;
if (stream_device_input_to_stream_input(target_device, inputnum++, &inputstream, &streaminput))
if (stream_device_output_to_stream_output(sound, outputnum, &stream, &streamoutput))
stream_set_input(inputstream, streaminput, stream, streamoutput, route->gain);
}
}
}
}
/* free up our temporary string */
astring_free(tempstring);
} | /*-------------------------------------------------
route_sound - route sound outputs to target
inputs
-------------------------------------------------*/ | route sound outputs to target
inputs | [
"route",
"sound",
"outputs",
"to",
"target",
"inputs"
] | static void route_sound(running_machine *machine)
{
astring *tempstring = astring_alloc();
const device_config *curspeak;
const device_config *sound;
int outputnum;
for (sound = sound_first(machine->config); sound != NULL; sound = sound_next(sound))
{
const sound_config *config = (const sound_config *)sound->inline_config;
int numoutputs = stream_get_device_outputs(sound);
const sound_route *route;
for (route = config->routelist; route != NULL; route = route->next)
{
const device_config *target_device = devtag_get_device(machine, route->target);
if (target_device == NULL)
fatalerror("Sound route \"%s\" not found!\n", route->target);
if (target_device->type == SPEAKER_OUTPUT)
get_safe_token(target_device)->inputs += (route->output == ALL_OUTPUTS) ? numoutputs : 1;
}
}
for (curspeak = speaker_output_first(machine->config); curspeak != NULL; curspeak = speaker_output_next(curspeak))
{
speaker_info *info = get_safe_token(curspeak);
if (info->inputs != 0)
{
info->mixer_stream = stream_create(curspeak, info->inputs, 1, machine->sample_rate, info, mixer_update);
state_save_register_postload(machine, mixer_postload, info->mixer_stream);
info->input = auto_alloc_array(machine, speaker_input, info->inputs);
info->inputs = 0;
}
else
logerror("Warning: speaker \"%s\" has no inputs\n", info->tag);
}
for (sound = sound_first(machine->config); sound != NULL; sound = sound_next(sound))
{
const sound_config *config = (const sound_config *)sound->inline_config;
int numoutputs = stream_get_device_outputs(sound);
const sound_route *route;
for (route = config->routelist; route != NULL; route = route->next)
{
const device_config *target_device = devtag_get_device(machine, route->target);
int inputnum = route->input;
sound_stream *stream;
int streamoutput;
for (outputnum = 0; outputnum < numoutputs; outputnum++)
if (route->output == outputnum || route->output == ALL_OUTPUTS)
{
if (target_device->type == SPEAKER_OUTPUT)
{
speaker_info *speakerinfo = get_safe_token(target_device);
astring_printf(tempstring, "Speaker '%s': %s '%s'", target_device->tag, device_get_name(sound), sound->tag);
if (numoutputs > 1)
astring_catprintf(tempstring, " Ch.%d", outputnum);
speakerinfo->input[speakerinfo->inputs].gain = route->gain;
speakerinfo->input[speakerinfo->inputs].default_gain = route->gain;
speakerinfo->input[speakerinfo->inputs].name = auto_strdup(machine, astring_c(tempstring));
if (stream_device_output_to_stream_output(sound, outputnum, &stream, &streamoutput))
stream_set_input(speakerinfo->mixer_stream, speakerinfo->inputs++, stream, streamoutput, route->gain);
}
else
{
sound_stream *inputstream;
int streaminput;
if (stream_device_input_to_stream_input(target_device, inputnum++, &inputstream, &streaminput))
if (stream_device_output_to_stream_output(sound, outputnum, &stream, &streamoutput))
stream_set_input(inputstream, streaminput, stream, streamoutput, route->gain);
}
}
}
}
astring_free(tempstring);
} | [
"static",
"void",
"route_sound",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"astring",
"*",
"tempstring",
"=",
"astring_alloc",
"(",
")",
";",
"const",
"device_config",
"*",
"curspeak",
";",
"const",
"device_config",
"*",
"sound",
";",
"int",
"outputnum",
";",
"for",
"(",
"sound",
"=",
"sound_first",
"(",
"machine",
"->",
"config",
")",
";",
"sound",
"!=",
"NULL",
";",
"sound",
"=",
"sound_next",
"(",
"sound",
")",
")",
"{",
"const",
"sound_config",
"*",
"config",
"=",
"(",
"const",
"sound_config",
"*",
")",
"sound",
"->",
"inline_config",
";",
"int",
"numoutputs",
"=",
"stream_get_device_outputs",
"(",
"sound",
")",
";",
"const",
"sound_route",
"*",
"route",
";",
"for",
"(",
"route",
"=",
"config",
"->",
"routelist",
";",
"route",
"!=",
"NULL",
";",
"route",
"=",
"route",
"->",
"next",
")",
"{",
"const",
"device_config",
"*",
"target_device",
"=",
"devtag_get_device",
"(",
"machine",
",",
"route",
"->",
"target",
")",
";",
"if",
"(",
"target_device",
"==",
"NULL",
")",
"fatalerror",
"(",
"\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"route",
"->",
"target",
")",
";",
"if",
"(",
"target_device",
"->",
"type",
"==",
"SPEAKER_OUTPUT",
")",
"get_safe_token",
"(",
"target_device",
")",
"->",
"inputs",
"+=",
"(",
"route",
"->",
"output",
"==",
"ALL_OUTPUTS",
")",
"?",
"numoutputs",
":",
"1",
";",
"}",
"}",
"for",
"(",
"curspeak",
"=",
"speaker_output_first",
"(",
"machine",
"->",
"config",
")",
";",
"curspeak",
"!=",
"NULL",
";",
"curspeak",
"=",
"speaker_output_next",
"(",
"curspeak",
")",
")",
"{",
"speaker_info",
"*",
"info",
"=",
"get_safe_token",
"(",
"curspeak",
")",
";",
"if",
"(",
"info",
"->",
"inputs",
"!=",
"0",
")",
"{",
"info",
"->",
"mixer_stream",
"=",
"stream_create",
"(",
"curspeak",
",",
"info",
"->",
"inputs",
",",
"1",
",",
"machine",
"->",
"sample_rate",
",",
"info",
",",
"mixer_update",
")",
";",
"state_save_register_postload",
"(",
"machine",
",",
"mixer_postload",
",",
"info",
"->",
"mixer_stream",
")",
";",
"info",
"->",
"input",
"=",
"auto_alloc_array",
"(",
"machine",
",",
"speaker_input",
",",
"info",
"->",
"inputs",
")",
";",
"info",
"->",
"inputs",
"=",
"0",
";",
"}",
"else",
"logerror",
"(",
"\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"info",
"->",
"tag",
")",
";",
"}",
"for",
"(",
"sound",
"=",
"sound_first",
"(",
"machine",
"->",
"config",
")",
";",
"sound",
"!=",
"NULL",
";",
"sound",
"=",
"sound_next",
"(",
"sound",
")",
")",
"{",
"const",
"sound_config",
"*",
"config",
"=",
"(",
"const",
"sound_config",
"*",
")",
"sound",
"->",
"inline_config",
";",
"int",
"numoutputs",
"=",
"stream_get_device_outputs",
"(",
"sound",
")",
";",
"const",
"sound_route",
"*",
"route",
";",
"for",
"(",
"route",
"=",
"config",
"->",
"routelist",
";",
"route",
"!=",
"NULL",
";",
"route",
"=",
"route",
"->",
"next",
")",
"{",
"const",
"device_config",
"*",
"target_device",
"=",
"devtag_get_device",
"(",
"machine",
",",
"route",
"->",
"target",
")",
";",
"int",
"inputnum",
"=",
"route",
"->",
"input",
";",
"sound_stream",
"*",
"stream",
";",
"int",
"streamoutput",
";",
"for",
"(",
"outputnum",
"=",
"0",
";",
"outputnum",
"<",
"numoutputs",
";",
"outputnum",
"++",
")",
"if",
"(",
"route",
"->",
"output",
"==",
"outputnum",
"||",
"route",
"->",
"output",
"==",
"ALL_OUTPUTS",
")",
"{",
"if",
"(",
"target_device",
"->",
"type",
"==",
"SPEAKER_OUTPUT",
")",
"{",
"speaker_info",
"*",
"speakerinfo",
"=",
"get_safe_token",
"(",
"target_device",
")",
";",
"astring_printf",
"(",
"tempstring",
",",
"\"",
"\"",
",",
"target_device",
"->",
"tag",
",",
"device_get_name",
"(",
"sound",
")",
",",
"sound",
"->",
"tag",
")",
";",
"if",
"(",
"numoutputs",
">",
"1",
")",
"astring_catprintf",
"(",
"tempstring",
",",
"\"",
"\"",
",",
"outputnum",
")",
";",
"speakerinfo",
"->",
"input",
"[",
"speakerinfo",
"->",
"inputs",
"]",
".",
"gain",
"=",
"route",
"->",
"gain",
";",
"speakerinfo",
"->",
"input",
"[",
"speakerinfo",
"->",
"inputs",
"]",
".",
"default_gain",
"=",
"route",
"->",
"gain",
";",
"speakerinfo",
"->",
"input",
"[",
"speakerinfo",
"->",
"inputs",
"]",
".",
"name",
"=",
"auto_strdup",
"(",
"machine",
",",
"astring_c",
"(",
"tempstring",
")",
")",
";",
"if",
"(",
"stream_device_output_to_stream_output",
"(",
"sound",
",",
"outputnum",
",",
"&",
"stream",
",",
"&",
"streamoutput",
")",
")",
"stream_set_input",
"(",
"speakerinfo",
"->",
"mixer_stream",
",",
"speakerinfo",
"->",
"inputs",
"++",
",",
"stream",
",",
"streamoutput",
",",
"route",
"->",
"gain",
")",
";",
"}",
"else",
"{",
"sound_stream",
"*",
"inputstream",
";",
"int",
"streaminput",
";",
"if",
"(",
"stream_device_input_to_stream_input",
"(",
"target_device",
",",
"inputnum",
"++",
",",
"&",
"inputstream",
",",
"&",
"streaminput",
")",
")",
"if",
"(",
"stream_device_output_to_stream_output",
"(",
"sound",
",",
"outputnum",
",",
"&",
"stream",
",",
"&",
"streamoutput",
")",
")",
"stream_set_input",
"(",
"inputstream",
",",
"streaminput",
",",
"stream",
",",
"streamoutput",
",",
"route",
"->",
"gain",
")",
";",
"}",
"}",
"}",
"}",
"astring_free",
"(",
"tempstring",
")",
";",
"}"
] | route_sound - route sound outputs to target
inputs | [
"route_sound",
"-",
"route",
"sound",
"outputs",
"to",
"target",
"inputs"
] | [
"/* first count up the inputs for each speaker */",
"/* iterate over all routes */",
"/* if neither found, it's fatal */",
"/* if we got a speaker, bump its input count */",
"/* now allocate the mixers and input data */",
"/* iterate again over all the sound chips */",
"/* iterate over all routes */",
"/* iterate over all outputs, matching any that apply */",
"/* if it's a speaker, set the input */",
"/* generate text for the UI */",
"/* fill in the input data on this speaker */",
"/* connect the output to the input */",
"/* otherwise, it's a sound chip */",
"/* free up our temporary string */"
] | [
{
"param": "machine",
"type": "running_machine"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d0a222117396f5c8f4bcab41c0cd2351128e2419 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/sound.c | [
"Unlicense"
] | C | sound_set_output_gain | void | void sound_set_output_gain(const device_config *device, int output, float gain)
{
sound_stream *stream;
int outputnum;
if (stream_device_output_to_stream_output(device, output, &stream, &outputnum))
stream_set_output_gain(stream, outputnum, gain);
} | /*-------------------------------------------------
sound_set_output_gain - set the gain of a
particular output
-------------------------------------------------*/ | set the gain of a
particular output | [
"set",
"the",
"gain",
"of",
"a",
"particular",
"output"
] | void sound_set_output_gain(const device_config *device, int output, float gain)
{
sound_stream *stream;
int outputnum;
if (stream_device_output_to_stream_output(device, output, &stream, &outputnum))
stream_set_output_gain(stream, outputnum, gain);
} | [
"void",
"sound_set_output_gain",
"(",
"const",
"device_config",
"*",
"device",
",",
"int",
"output",
",",
"float",
"gain",
")",
"{",
"sound_stream",
"*",
"stream",
";",
"int",
"outputnum",
";",
"if",
"(",
"stream_device_output_to_stream_output",
"(",
"device",
",",
"output",
",",
"&",
"stream",
",",
"&",
"outputnum",
")",
")",
"stream_set_output_gain",
"(",
"stream",
",",
"outputnum",
",",
"gain",
")",
";",
"}"
] | sound_set_output_gain - set the gain of a
particular output | [
"sound_set_output_gain",
"-",
"set",
"the",
"gain",
"of",
"a",
"particular",
"output"
] | [] | [
{
"param": "device",
"type": "device_config"
},
{
"param": "output",
"type": "int"
},
{
"param": "gain",
"type": "float"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "device",
"type": "device_config",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "output",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "gain",
"type": "float",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d0a222117396f5c8f4bcab41c0cd2351128e2419 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/sound.c | [
"Unlicense"
] | C | sound_get_user_gain_count | int | int sound_get_user_gain_count(running_machine *machine)
{
const device_config *curspeak;
int count = 0;
/* count up the number of speaker inputs */
for (curspeak = speaker_output_first(machine->config); curspeak != NULL; curspeak = speaker_output_next(curspeak))
{
speaker_info *info = (speaker_info *)curspeak->token;
count += info->inputs;
}
return count;
} | /*-------------------------------------------------
sound_get_user_gain_count - return the number
of user-controllable gain parameters
-------------------------------------------------*/ | return the number
of user-controllable gain parameters | [
"return",
"the",
"number",
"of",
"user",
"-",
"controllable",
"gain",
"parameters"
] | int sound_get_user_gain_count(running_machine *machine)
{
const device_config *curspeak;
int count = 0;
for (curspeak = speaker_output_first(machine->config); curspeak != NULL; curspeak = speaker_output_next(curspeak))
{
speaker_info *info = (speaker_info *)curspeak->token;
count += info->inputs;
}
return count;
} | [
"int",
"sound_get_user_gain_count",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"const",
"device_config",
"*",
"curspeak",
";",
"int",
"count",
"=",
"0",
";",
"for",
"(",
"curspeak",
"=",
"speaker_output_first",
"(",
"machine",
"->",
"config",
")",
";",
"curspeak",
"!=",
"NULL",
";",
"curspeak",
"=",
"speaker_output_next",
"(",
"curspeak",
")",
")",
"{",
"speaker_info",
"*",
"info",
"=",
"(",
"speaker_info",
"*",
")",
"curspeak",
"->",
"token",
";",
"count",
"+=",
"info",
"->",
"inputs",
";",
"}",
"return",
"count",
";",
"}"
] | sound_get_user_gain_count - return the number
of user-controllable gain parameters | [
"sound_get_user_gain_count",
"-",
"return",
"the",
"number",
"of",
"user",
"-",
"controllable",
"gain",
"parameters"
] | [
"/* count up the number of speaker inputs */"
] | [
{
"param": "machine",
"type": "running_machine"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d0a222117396f5c8f4bcab41c0cd2351128e2419 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/sound.c | [
"Unlicense"
] | C | sound_set_user_gain | void | void sound_set_user_gain(running_machine *machine, int index, float gain)
{
int inputnum;
speaker_info *spk = index_to_input(machine, index, &inputnum);
if (spk != NULL)
{
spk->input[inputnum].gain = gain;
stream_set_input_gain(spk->mixer_stream, inputnum, gain);
}
} | /*-------------------------------------------------
sound_set_user_gain - set the nth user gain
value
-------------------------------------------------*/ | set the nth user gain
value | [
"set",
"the",
"nth",
"user",
"gain",
"value"
] | void sound_set_user_gain(running_machine *machine, int index, float gain)
{
int inputnum;
speaker_info *spk = index_to_input(machine, index, &inputnum);
if (spk != NULL)
{
spk->input[inputnum].gain = gain;
stream_set_input_gain(spk->mixer_stream, inputnum, gain);
}
} | [
"void",
"sound_set_user_gain",
"(",
"running_machine",
"*",
"machine",
",",
"int",
"index",
",",
"float",
"gain",
")",
"{",
"int",
"inputnum",
";",
"speaker_info",
"*",
"spk",
"=",
"index_to_input",
"(",
"machine",
",",
"index",
",",
"&",
"inputnum",
")",
";",
"if",
"(",
"spk",
"!=",
"NULL",
")",
"{",
"spk",
"->",
"input",
"[",
"inputnum",
"]",
".",
"gain",
"=",
"gain",
";",
"stream_set_input_gain",
"(",
"spk",
"->",
"mixer_stream",
",",
"inputnum",
",",
"gain",
")",
";",
"}",
"}"
] | sound_set_user_gain - set the nth user gain
value | [
"sound_set_user_gain",
"-",
"set",
"the",
"nth",
"user",
"gain",
"value"
] | [] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "index",
"type": "int"
},
{
"param": "gain",
"type": "float"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "index",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "gain",
"type": "float",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d0a222117396f5c8f4bcab41c0cd2351128e2419 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/sound.c | [
"Unlicense"
] | C | sound_get_user_gain | float | float sound_get_user_gain(running_machine *machine, int index)
{
int inputnum;
speaker_info *spk = index_to_input(machine, index, &inputnum);
return (spk != NULL) ? spk->input[inputnum].gain : 0;
} | /*-------------------------------------------------
sound_get_user_gain - get the nth user gain
value
-------------------------------------------------*/ | get the nth user gain
value | [
"get",
"the",
"nth",
"user",
"gain",
"value"
] | float sound_get_user_gain(running_machine *machine, int index)
{
int inputnum;
speaker_info *spk = index_to_input(machine, index, &inputnum);
return (spk != NULL) ? spk->input[inputnum].gain : 0;
} | [
"float",
"sound_get_user_gain",
"(",
"running_machine",
"*",
"machine",
",",
"int",
"index",
")",
"{",
"int",
"inputnum",
";",
"speaker_info",
"*",
"spk",
"=",
"index_to_input",
"(",
"machine",
",",
"index",
",",
"&",
"inputnum",
")",
";",
"return",
"(",
"spk",
"!=",
"NULL",
")",
"?",
"spk",
"->",
"input",
"[",
"inputnum",
"]",
".",
"gain",
":",
"0",
";",
"}"
] | sound_get_user_gain - get the nth user gain
value | [
"sound_get_user_gain",
"-",
"get",
"the",
"nth",
"user",
"gain",
"value"
] | [] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "index",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "index",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d0a222117396f5c8f4bcab41c0cd2351128e2419 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/sound.c | [
"Unlicense"
] | C | sound_get_default_gain | float | float sound_get_default_gain(running_machine *machine, int index)
{
int inputnum;
speaker_info *spk = index_to_input(machine, index, &inputnum);
return (spk != NULL) ? spk->input[inputnum].default_gain : 0;
} | /*-------------------------------------------------
sound_get_default_gain - return the default
gain of the nth user value
-------------------------------------------------*/ | return the default
gain of the nth user value | [
"return",
"the",
"default",
"gain",
"of",
"the",
"nth",
"user",
"value"
] | float sound_get_default_gain(running_machine *machine, int index)
{
int inputnum;
speaker_info *spk = index_to_input(machine, index, &inputnum);
return (spk != NULL) ? spk->input[inputnum].default_gain : 0;
} | [
"float",
"sound_get_default_gain",
"(",
"running_machine",
"*",
"machine",
",",
"int",
"index",
")",
"{",
"int",
"inputnum",
";",
"speaker_info",
"*",
"spk",
"=",
"index_to_input",
"(",
"machine",
",",
"index",
",",
"&",
"inputnum",
")",
";",
"return",
"(",
"spk",
"!=",
"NULL",
")",
"?",
"spk",
"->",
"input",
"[",
"inputnum",
"]",
".",
"default_gain",
":",
"0",
";",
"}"
] | sound_get_default_gain - return the default
gain of the nth user value | [
"sound_get_default_gain",
"-",
"return",
"the",
"default",
"gain",
"of",
"the",
"nth",
"user",
"value"
] | [] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "index",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "index",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d0a222117396f5c8f4bcab41c0cd2351128e2419 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/sound.c | [
"Unlicense"
] | C | sound_get_user_gain_name | char | const char *sound_get_user_gain_name(running_machine *machine, int index)
{
int inputnum;
speaker_info *spk = index_to_input(machine, index, &inputnum);
return (spk != NULL) ? spk->input[inputnum].name : NULL;
} | /*-------------------------------------------------
sound_get_user_gain_name - return the name
of the nth user value
-------------------------------------------------*/ | return the name
of the nth user value | [
"return",
"the",
"name",
"of",
"the",
"nth",
"user",
"value"
] | const char *sound_get_user_gain_name(running_machine *machine, int index)
{
int inputnum;
speaker_info *spk = index_to_input(machine, index, &inputnum);
return (spk != NULL) ? spk->input[inputnum].name : NULL;
} | [
"const",
"char",
"*",
"sound_get_user_gain_name",
"(",
"running_machine",
"*",
"machine",
",",
"int",
"index",
")",
"{",
"int",
"inputnum",
";",
"speaker_info",
"*",
"spk",
"=",
"index_to_input",
"(",
"machine",
",",
"index",
",",
"&",
"inputnum",
")",
";",
"return",
"(",
"spk",
"!=",
"NULL",
")",
"?",
"spk",
"->",
"input",
"[",
"inputnum",
"]",
".",
"name",
":",
"NULL",
";",
"}"
] | sound_get_user_gain_name - return the name
of the nth user value | [
"sound_get_user_gain_name",
"-",
"return",
"the",
"name",
"of",
"the",
"nth",
"user",
"value"
] | [] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "index",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "index",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f950675a275872b010f6bf58036788041ede3357 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/cpu/mcs51/mcs51.c | [
"Unlicense"
] | C | check_irqs | void | static void check_irqs(mcs51_state_t *mcs51_state)
{
UINT8 ints = (GET_IE0 | (GET_TF0<<1) | (GET_IE1<<2) | (GET_TF1<<3)
| ((GET_RI|GET_TI)<<4));
UINT8 int_vec = 0;
UINT8 int_mask = 0;
int priority_request = -1;
int i;
//If All Inerrupts Disabled or no pending abort..
int_mask = (GET_EA ? IE : 0x00);
if (mcs51_state->features & FEATURE_I8052)
ints |= ((GET_TF2|GET_EXF2)<<5);
if (mcs51_state->features & FEATURE_DS5002FP)
{
ints |= ((GET_PFW)<<5);
mcs51_state->irq_prio[6] = 3; /* force highest priority */
/* mask out interrupts not enabled */
ints &= ((int_mask & 0x1f) | ((GET_EPFW)<<5));
}
else
{
/* mask out interrupts not enabled */
ints &= int_mask;
}
if (!ints) return;
/* CLear IDL - got enabled interrupt */
if (mcs51_state->features & FEATURE_CMOS)
{
/* any interrupt terminates idle mode */
SET_IDL(0);
/* external interrupt wakes up */
if (ints & (GET_IE0 | GET_IE1))
/* but not the DS5002FP */
if (!(mcs51_state->features & FEATURE_DS5002FP))
SET_PD(0);
}
for (i=0; i<mcs51_state->num_interrupts; i++)
{
if (ints & (1<<i))
{
if (mcs51_state->irq_prio[i] > priority_request)
{
priority_request = mcs51_state->irq_prio[i];
int_vec = (i<<3) | 3;
}
}
}
/* Skip the interrupt request if currently processing interrupt
* and the new request does not have a higher priority
*/
LOG(("Request: %d\n", priority_request));
if (mcs51_state->irq_active && (priority_request <= mcs51_state->cur_irq_prio))
{
LOG(("higher or equal priority irq in progress already, skipping ...\n"));
return;
}
/* also break out of jb int0,<self> loops */
if (ROP(PC) == 0x20 && ROP_ARG(PC+1) == 0xb2 && ROP_ARG(PC+2) == 0xfd)
PC += 3;
//Save current pc to stack, set pc to new interrupt vector
push_pc(mcs51_state);
PC = int_vec;
/* interrupts take 24 cycles */
mcs51_state->inst_cycles += 2;
//Set current Irq & Priority being serviced
mcs51_state->cur_irq_prio = priority_request;
mcs51_state->irq_active |= (1 << priority_request);
LOG(("Take: %d %02x\n", mcs51_state->cur_irq_prio, mcs51_state->irq_active));
//Clear any interrupt flags that should be cleared since we're servicing the irq!
switch(int_vec) {
case V_IE0:
//External Int Flag only cleared when configured as Edge Triggered..
if(GET_IT0) /* for some reason having this, breaks alving dmd games */
SET_IE0(0);
/* indicate we took the external IRQ */
if (mcs51_state->irq_callback != NULL)
(*mcs51_state->irq_callback)(mcs51_state->device, 0);
break;
case V_TF0:
//Timer 0 - Always clear Flag
SET_TF0(0);
break;
case V_IE1:
//External Int Flag only cleared when configured as Edge Triggered..
if(GET_IT1) /* for some reason having this, breaks alving dmd games */
SET_IE1(0);
/* indicate we took the external IRQ */
if (mcs51_state->irq_callback != NULL)
(*mcs51_state->irq_callback)(mcs51_state->device, 1);
break;
case V_TF1:
//Timer 1 - Always clear Flag
SET_TF1(0);
break;
case V_RITI:
/* no flags are cleared, TI and RI remain set until reset by software */
break;
/* I8052 specific */
case V_TF2:
/* no flags are cleared according to manual */
break;
/* DS5002FP specific */
/* case V_PFI:
* no flags are cleared, PFW is reset by software
* This has the same vector as V_TF2.
*/
}
} | /***********************************************************************************
Check for pending Interrupts and process - returns # of cycles used for the int
Note about priority & interrupting interrupts..
1) A high priority interrupt cannot be interrupted by anything!
2) A low priority interrupt can ONLY be interrupted by a high priority interrupt
3) If more than 1 Interrupt Flag is set (ie, 2 simultaneous requests occur),
the following logic works as follows:
1) If two requests come in of different priority levels, the higher one is selected..
2) If the requests are of the same level, an internal order is used:
a) IEO
b) TFO
c) IE1
d) TF1
e) RI+TI
f) TF2+EXF2
**********************************************************************************/ | Check for pending Interrupts and process - returns # of cycles used for the int
Note about priority & interrupting interrupts
1) A high priority interrupt cannot be interrupted by anything.
2) A low priority interrupt can ONLY be interrupted by a high priority interrupt
3) If more than 1 Interrupt Flag is set ,
the following logic works as follows:
1) If two requests come in of different priority levels, the higher one is selected
2) If the requests are of the same level, an internal order is used:
a) IEO
b) TFO
c) IE1
d) TF1
e) RI+TI
f) TF2+EXF2 | [
"Check",
"for",
"pending",
"Interrupts",
"and",
"process",
"-",
"returns",
"#",
"of",
"cycles",
"used",
"for",
"the",
"int",
"Note",
"about",
"priority",
"&",
"interrupting",
"interrupts",
"1",
")",
"A",
"high",
"priority",
"interrupt",
"cannot",
"be",
"interrupted",
"by",
"anything",
".",
"2",
")",
"A",
"low",
"priority",
"interrupt",
"can",
"ONLY",
"be",
"interrupted",
"by",
"a",
"high",
"priority",
"interrupt",
"3",
")",
"If",
"more",
"than",
"1",
"Interrupt",
"Flag",
"is",
"set",
"the",
"following",
"logic",
"works",
"as",
"follows",
":",
"1",
")",
"If",
"two",
"requests",
"come",
"in",
"of",
"different",
"priority",
"levels",
"the",
"higher",
"one",
"is",
"selected",
"2",
")",
"If",
"the",
"requests",
"are",
"of",
"the",
"same",
"level",
"an",
"internal",
"order",
"is",
"used",
":",
"a",
")",
"IEO",
"b",
")",
"TFO",
"c",
")",
"IE1",
"d",
")",
"TF1",
"e",
")",
"RI",
"+",
"TI",
"f",
")",
"TF2",
"+",
"EXF2"
] | static void check_irqs(mcs51_state_t *mcs51_state)
{
UINT8 ints = (GET_IE0 | (GET_TF0<<1) | (GET_IE1<<2) | (GET_TF1<<3)
| ((GET_RI|GET_TI)<<4));
UINT8 int_vec = 0;
UINT8 int_mask = 0;
int priority_request = -1;
int i;
int_mask = (GET_EA ? IE : 0x00);
if (mcs51_state->features & FEATURE_I8052)
ints |= ((GET_TF2|GET_EXF2)<<5);
if (mcs51_state->features & FEATURE_DS5002FP)
{
ints |= ((GET_PFW)<<5);
mcs51_state->irq_prio[6] = 3;
ints &= ((int_mask & 0x1f) | ((GET_EPFW)<<5));
}
else
{
ints &= int_mask;
}
if (!ints) return;
if (mcs51_state->features & FEATURE_CMOS)
{
SET_IDL(0);
if (ints & (GET_IE0 | GET_IE1))
if (!(mcs51_state->features & FEATURE_DS5002FP))
SET_PD(0);
}
for (i=0; i<mcs51_state->num_interrupts; i++)
{
if (ints & (1<<i))
{
if (mcs51_state->irq_prio[i] > priority_request)
{
priority_request = mcs51_state->irq_prio[i];
int_vec = (i<<3) | 3;
}
}
}
LOG(("Request: %d\n", priority_request));
if (mcs51_state->irq_active && (priority_request <= mcs51_state->cur_irq_prio))
{
LOG(("higher or equal priority irq in progress already, skipping ...\n"));
return;
}
if (ROP(PC) == 0x20 && ROP_ARG(PC+1) == 0xb2 && ROP_ARG(PC+2) == 0xfd)
PC += 3;
push_pc(mcs51_state);
PC = int_vec;
mcs51_state->inst_cycles += 2;
mcs51_state->cur_irq_prio = priority_request;
mcs51_state->irq_active |= (1 << priority_request);
LOG(("Take: %d %02x\n", mcs51_state->cur_irq_prio, mcs51_state->irq_active));
switch(int_vec) {
case V_IE0:
if(GET_IT0)
SET_IE0(0);
if (mcs51_state->irq_callback != NULL)
(*mcs51_state->irq_callback)(mcs51_state->device, 0);
break;
case V_TF0:
SET_TF0(0);
break;
case V_IE1:
if(GET_IT1)
SET_IE1(0);
if (mcs51_state->irq_callback != NULL)
(*mcs51_state->irq_callback)(mcs51_state->device, 1);
break;
case V_TF1:
SET_TF1(0);
break;
case V_RITI:
break;
case V_TF2:
break;
}
} | [
"static",
"void",
"check_irqs",
"(",
"mcs51_state_t",
"*",
"mcs51_state",
")",
"{",
"UINT8",
"ints",
"=",
"(",
"GET_IE0",
"|",
"(",
"GET_TF0",
"<<",
"1",
")",
"|",
"(",
"GET_IE1",
"<<",
"2",
")",
"|",
"(",
"GET_TF1",
"<<",
"3",
")",
"|",
"(",
"(",
"GET_RI",
"|",
"GET_TI",
")",
"<<",
"4",
")",
")",
";",
"UINT8",
"int_vec",
"=",
"0",
";",
"UINT8",
"int_mask",
"=",
"0",
";",
"int",
"priority_request",
"=",
"-1",
";",
"int",
"i",
";",
"int_mask",
"=",
"(",
"GET_EA",
"?",
"IE",
":",
"0x00",
")",
";",
"if",
"(",
"mcs51_state",
"->",
"features",
"&",
"FEATURE_I8052",
")",
"ints",
"|=",
"(",
"(",
"GET_TF2",
"|",
"GET_EXF2",
")",
"<<",
"5",
")",
";",
"if",
"(",
"mcs51_state",
"->",
"features",
"&",
"FEATURE_DS5002FP",
")",
"{",
"ints",
"|=",
"(",
"(",
"GET_PFW",
")",
"<<",
"5",
")",
";",
"mcs51_state",
"->",
"irq_prio",
"[",
"6",
"]",
"=",
"3",
";",
"ints",
"&=",
"(",
"(",
"int_mask",
"&",
"0x1f",
")",
"|",
"(",
"(",
"GET_EPFW",
")",
"<<",
"5",
")",
")",
";",
"}",
"else",
"{",
"ints",
"&=",
"int_mask",
";",
"}",
"if",
"(",
"!",
"ints",
")",
"return",
";",
"if",
"(",
"mcs51_state",
"->",
"features",
"&",
"FEATURE_CMOS",
")",
"{",
"SET_IDL",
"(",
"0",
")",
";",
"if",
"(",
"ints",
"&",
"(",
"GET_IE0",
"|",
"GET_IE1",
")",
")",
"if",
"(",
"!",
"(",
"mcs51_state",
"->",
"features",
"&",
"FEATURE_DS5002FP",
")",
")",
"SET_PD",
"(",
"0",
")",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"mcs51_state",
"->",
"num_interrupts",
";",
"i",
"++",
")",
"{",
"if",
"(",
"ints",
"&",
"(",
"1",
"<<",
"i",
")",
")",
"{",
"if",
"(",
"mcs51_state",
"->",
"irq_prio",
"[",
"i",
"]",
">",
"priority_request",
")",
"{",
"priority_request",
"=",
"mcs51_state",
"->",
"irq_prio",
"[",
"i",
"]",
";",
"int_vec",
"=",
"(",
"i",
"<<",
"3",
")",
"|",
"3",
";",
"}",
"}",
"}",
"LOG",
"(",
"(",
"\"",
"\\n",
"\"",
",",
"priority_request",
")",
")",
";",
"if",
"(",
"mcs51_state",
"->",
"irq_active",
"&&",
"(",
"priority_request",
"<=",
"mcs51_state",
"->",
"cur_irq_prio",
")",
")",
"{",
"LOG",
"(",
"(",
"\"",
"\\n",
"\"",
")",
")",
";",
"return",
";",
"}",
"if",
"(",
"ROP",
"(",
"PC",
")",
"==",
"0x20",
"&&",
"ROP_ARG",
"(",
"PC",
"+",
"1",
")",
"==",
"0xb2",
"&&",
"ROP_ARG",
"(",
"PC",
"+",
"2",
")",
"==",
"0xfd",
")",
"PC",
"+=",
"3",
";",
"push_pc",
"(",
"mcs51_state",
")",
";",
"PC",
"=",
"int_vec",
";",
"mcs51_state",
"->",
"inst_cycles",
"+=",
"2",
";",
"mcs51_state",
"->",
"cur_irq_prio",
"=",
"priority_request",
";",
"mcs51_state",
"->",
"irq_active",
"|=",
"(",
"1",
"<<",
"priority_request",
")",
";",
"LOG",
"(",
"(",
"\"",
"\\n",
"\"",
",",
"mcs51_state",
"->",
"cur_irq_prio",
",",
"mcs51_state",
"->",
"irq_active",
")",
")",
";",
"switch",
"(",
"int_vec",
")",
"{",
"case",
"V_IE0",
":",
"if",
"(",
"GET_IT0",
")",
"SET_IE0",
"(",
"0",
")",
";",
"if",
"(",
"mcs51_state",
"->",
"irq_callback",
"!=",
"NULL",
")",
"(",
"*",
"mcs51_state",
"->",
"irq_callback",
")",
"(",
"mcs51_state",
"->",
"device",
",",
"0",
")",
";",
"break",
";",
"case",
"V_TF0",
":",
"SET_TF0",
"(",
"0",
")",
";",
"break",
";",
"case",
"V_IE1",
":",
"if",
"(",
"GET_IT1",
")",
"SET_IE1",
"(",
"0",
")",
";",
"if",
"(",
"mcs51_state",
"->",
"irq_callback",
"!=",
"NULL",
")",
"(",
"*",
"mcs51_state",
"->",
"irq_callback",
")",
"(",
"mcs51_state",
"->",
"device",
",",
"1",
")",
";",
"break",
";",
"case",
"V_TF1",
":",
"SET_TF1",
"(",
"0",
")",
";",
"break",
";",
"case",
"V_RITI",
":",
"break",
";",
"case",
"V_TF2",
":",
"break",
";",
"}",
"}"
] | Check for pending Interrupts and process - returns # of cycles used for the int
Note about priority & interrupting interrupts..
1) A high priority interrupt cannot be interrupted by anything! | [
"Check",
"for",
"pending",
"Interrupts",
"and",
"process",
"-",
"returns",
"#",
"of",
"cycles",
"used",
"for",
"the",
"int",
"Note",
"about",
"priority",
"&",
"interrupting",
"interrupts",
"..",
"1",
")",
"A",
"high",
"priority",
"interrupt",
"cannot",
"be",
"interrupted",
"by",
"anything!"
] | [
"//If All Inerrupts Disabled or no pending abort..",
"/* force highest priority */",
"/* mask out interrupts not enabled */",
"/* mask out interrupts not enabled */",
"/* CLear IDL - got enabled interrupt */",
"/* any interrupt terminates idle mode */",
"/* external interrupt wakes up */",
"/* but not the DS5002FP */",
"/* Skip the interrupt request if currently processing interrupt\n * and the new request does not have a higher priority\n */",
"/* also break out of jb int0,<self> loops */",
"//Save current pc to stack, set pc to new interrupt vector",
"/* interrupts take 24 cycles */",
"//Set current Irq & Priority being serviced",
"//Clear any interrupt flags that should be cleared since we're servicing the irq!",
"//External Int Flag only cleared when configured as Edge Triggered..",
"/* for some reason having this, breaks alving dmd games */",
"/* indicate we took the external IRQ */",
"//Timer 0 - Always clear Flag",
"//External Int Flag only cleared when configured as Edge Triggered..",
"/* for some reason having this, breaks alving dmd games */",
"/* indicate we took the external IRQ */",
"//Timer 1 - Always clear Flag",
"/* no flags are cleared, TI and RI remain set until reset by software */",
"/* I8052 specific */",
"/* no flags are cleared according to manual */",
"/* DS5002FP specific */",
"/* case V_PFI:\n * no flags are cleared, PFW is reset by software\n * This has the same vector as V_TF2.\n */"
] | [
{
"param": "mcs51_state",
"type": "mcs51_state_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mcs51_state",
"type": "mcs51_state_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
be921a7bac971892cabcc1b854d4abb9c848a1ab | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/video/mystwarr.c | [
"Unlicense"
] | C | mystwarr_decode_tiles | void | static void mystwarr_decode_tiles(running_machine *machine)
{
UINT8 *s = memory_region(machine, "gfx1");
int len = memory_region_length(machine, "gfx1");
UINT8 *pFinish = s+len-3;
UINT8 *d, *decoded;
int gfxnum;
for (gfxnum = 0; gfxnum < ARRAY_LENGTH(machine->gfx); gfxnum++)
if (machine->gfx[gfxnum] != NULL && machine->gfx[gfxnum]->srcdata == s)
break;
assert(gfxnum != ARRAY_LENGTH(machine->gfx));
decoded = auto_alloc_array(machine, UINT8, len);
d = decoded;
// now convert the data into a drawable format so we can decode it
while (s < pFinish)
{
/* convert the whole mess to 5bpp planar in System GX's format
(p3 p1 p2 p0 p5)
(the original ROMs are stored as chunky for the first 4 bits
and the 5th bit is planar, which is undecodable as-is) */
int d0 = ((s[0]&0x80) )|((s[0]&0x08)<<3)|((s[1]&0x80)>>2)|((s[1]&0x08)<<1)|
((s[2]&0x80)>>4)|((s[2]&0x08)>>1)|((s[3]&0x80)>>6)|((s[3]&0x08)>>3);
int d1 = ((s[0]&0x40)<<1)|((s[0]&0x04)<<4)|((s[1]&0x40)>>1)|((s[1]&0x04)<<2)|
((s[2]&0x40)>>3)|((s[2]&0x04) )|((s[3]&0x40)>>5)|((s[3]&0x04)>>2);
int d2 = ((s[0]&0x20)<<2)|((s[0]&0x02)<<5)|((s[1]&0x20) )|((s[1]&0x02)<<3)|
((s[2]&0x20)>>2)|((s[2]&0x02)<<1)|((s[3]&0x20)>>4)|((s[3]&0x02)>>1);
int d3 = ((s[0]&0x10)<<3)|((s[0]&0x01)<<6)|((s[1]&0x10)<<1)|((s[1]&0x01)<<4)|
((s[2]&0x10)>>1)|((s[2]&0x01)<<2)|((s[3]&0x10)>>3)|((s[3]&0x01) );
d[0] = d3;
d[1] = d1;
d[2] = d2;
d[3] = d0;
d[4] = s[4];
s += 5;
d += 5;
}
gfx_element_set_source(machine->gfx[gfxnum], decoded);
} | // create a decoding buffer to hold decodable tiles so that the ROM test will pass by
// reading the original raw data | create a decoding buffer to hold decodable tiles so that the ROM test will pass by
reading the original raw data | [
"create",
"a",
"decoding",
"buffer",
"to",
"hold",
"decodable",
"tiles",
"so",
"that",
"the",
"ROM",
"test",
"will",
"pass",
"by",
"reading",
"the",
"original",
"raw",
"data"
] | static void mystwarr_decode_tiles(running_machine *machine)
{
UINT8 *s = memory_region(machine, "gfx1");
int len = memory_region_length(machine, "gfx1");
UINT8 *pFinish = s+len-3;
UINT8 *d, *decoded;
int gfxnum;
for (gfxnum = 0; gfxnum < ARRAY_LENGTH(machine->gfx); gfxnum++)
if (machine->gfx[gfxnum] != NULL && machine->gfx[gfxnum]->srcdata == s)
break;
assert(gfxnum != ARRAY_LENGTH(machine->gfx));
decoded = auto_alloc_array(machine, UINT8, len);
d = decoded;
while (s < pFinish)
{
int d0 = ((s[0]&0x80) )|((s[0]&0x08)<<3)|((s[1]&0x80)>>2)|((s[1]&0x08)<<1)|
((s[2]&0x80)>>4)|((s[2]&0x08)>>1)|((s[3]&0x80)>>6)|((s[3]&0x08)>>3);
int d1 = ((s[0]&0x40)<<1)|((s[0]&0x04)<<4)|((s[1]&0x40)>>1)|((s[1]&0x04)<<2)|
((s[2]&0x40)>>3)|((s[2]&0x04) )|((s[3]&0x40)>>5)|((s[3]&0x04)>>2);
int d2 = ((s[0]&0x20)<<2)|((s[0]&0x02)<<5)|((s[1]&0x20) )|((s[1]&0x02)<<3)|
((s[2]&0x20)>>2)|((s[2]&0x02)<<1)|((s[3]&0x20)>>4)|((s[3]&0x02)>>1);
int d3 = ((s[0]&0x10)<<3)|((s[0]&0x01)<<6)|((s[1]&0x10)<<1)|((s[1]&0x01)<<4)|
((s[2]&0x10)>>1)|((s[2]&0x01)<<2)|((s[3]&0x10)>>3)|((s[3]&0x01) );
d[0] = d3;
d[1] = d1;
d[2] = d2;
d[3] = d0;
d[4] = s[4];
s += 5;
d += 5;
}
gfx_element_set_source(machine->gfx[gfxnum], decoded);
} | [
"static",
"void",
"mystwarr_decode_tiles",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"UINT8",
"*",
"s",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"int",
"len",
"=",
"memory_region_length",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"UINT8",
"*",
"pFinish",
"=",
"s",
"+",
"len",
"-",
"3",
";",
"UINT8",
"*",
"d",
",",
"*",
"decoded",
";",
"int",
"gfxnum",
";",
"for",
"(",
"gfxnum",
"=",
"0",
";",
"gfxnum",
"<",
"ARRAY_LENGTH",
"(",
"machine",
"->",
"gfx",
")",
";",
"gfxnum",
"++",
")",
"if",
"(",
"machine",
"->",
"gfx",
"[",
"gfxnum",
"]",
"!=",
"NULL",
"&&",
"machine",
"->",
"gfx",
"[",
"gfxnum",
"]",
"->",
"srcdata",
"==",
"s",
")",
"break",
";",
"assert",
"(",
"gfxnum",
"!=",
"ARRAY_LENGTH",
"(",
"machine",
"->",
"gfx",
")",
")",
";",
"decoded",
"=",
"auto_alloc_array",
"(",
"machine",
",",
"UINT8",
",",
"len",
")",
";",
"d",
"=",
"decoded",
";",
"while",
"(",
"s",
"<",
"pFinish",
")",
"{",
"int",
"d0",
"=",
"(",
"(",
"s",
"[",
"0",
"]",
"&",
"0x80",
")",
")",
"|",
"(",
"(",
"s",
"[",
"0",
"]",
"&",
"0x08",
")",
"<<",
"3",
")",
"|",
"(",
"(",
"s",
"[",
"1",
"]",
"&",
"0x80",
")",
">>",
"2",
")",
"|",
"(",
"(",
"s",
"[",
"1",
"]",
"&",
"0x08",
")",
"<<",
"1",
")",
"|",
"(",
"(",
"s",
"[",
"2",
"]",
"&",
"0x80",
")",
">>",
"4",
")",
"|",
"(",
"(",
"s",
"[",
"2",
"]",
"&",
"0x08",
")",
">>",
"1",
")",
"|",
"(",
"(",
"s",
"[",
"3",
"]",
"&",
"0x80",
")",
">>",
"6",
")",
"|",
"(",
"(",
"s",
"[",
"3",
"]",
"&",
"0x08",
")",
">>",
"3",
")",
";",
"int",
"d1",
"=",
"(",
"(",
"s",
"[",
"0",
"]",
"&",
"0x40",
")",
"<<",
"1",
")",
"|",
"(",
"(",
"s",
"[",
"0",
"]",
"&",
"0x04",
")",
"<<",
"4",
")",
"|",
"(",
"(",
"s",
"[",
"1",
"]",
"&",
"0x40",
")",
">>",
"1",
")",
"|",
"(",
"(",
"s",
"[",
"1",
"]",
"&",
"0x04",
")",
"<<",
"2",
")",
"|",
"(",
"(",
"s",
"[",
"2",
"]",
"&",
"0x40",
")",
">>",
"3",
")",
"|",
"(",
"(",
"s",
"[",
"2",
"]",
"&",
"0x04",
")",
")",
"|",
"(",
"(",
"s",
"[",
"3",
"]",
"&",
"0x40",
")",
">>",
"5",
")",
"|",
"(",
"(",
"s",
"[",
"3",
"]",
"&",
"0x04",
")",
">>",
"2",
")",
";",
"int",
"d2",
"=",
"(",
"(",
"s",
"[",
"0",
"]",
"&",
"0x20",
")",
"<<",
"2",
")",
"|",
"(",
"(",
"s",
"[",
"0",
"]",
"&",
"0x02",
")",
"<<",
"5",
")",
"|",
"(",
"(",
"s",
"[",
"1",
"]",
"&",
"0x20",
")",
")",
"|",
"(",
"(",
"s",
"[",
"1",
"]",
"&",
"0x02",
")",
"<<",
"3",
")",
"|",
"(",
"(",
"s",
"[",
"2",
"]",
"&",
"0x20",
")",
">>",
"2",
")",
"|",
"(",
"(",
"s",
"[",
"2",
"]",
"&",
"0x02",
")",
"<<",
"1",
")",
"|",
"(",
"(",
"s",
"[",
"3",
"]",
"&",
"0x20",
")",
">>",
"4",
")",
"|",
"(",
"(",
"s",
"[",
"3",
"]",
"&",
"0x02",
")",
">>",
"1",
")",
";",
"int",
"d3",
"=",
"(",
"(",
"s",
"[",
"0",
"]",
"&",
"0x10",
")",
"<<",
"3",
")",
"|",
"(",
"(",
"s",
"[",
"0",
"]",
"&",
"0x01",
")",
"<<",
"6",
")",
"|",
"(",
"(",
"s",
"[",
"1",
"]",
"&",
"0x10",
")",
"<<",
"1",
")",
"|",
"(",
"(",
"s",
"[",
"1",
"]",
"&",
"0x01",
")",
"<<",
"4",
")",
"|",
"(",
"(",
"s",
"[",
"2",
"]",
"&",
"0x10",
")",
">>",
"1",
")",
"|",
"(",
"(",
"s",
"[",
"2",
"]",
"&",
"0x01",
")",
"<<",
"2",
")",
"|",
"(",
"(",
"s",
"[",
"3",
"]",
"&",
"0x10",
")",
">>",
"3",
")",
"|",
"(",
"(",
"s",
"[",
"3",
"]",
"&",
"0x01",
")",
")",
";",
"d",
"[",
"0",
"]",
"=",
"d3",
";",
"d",
"[",
"1",
"]",
"=",
"d1",
";",
"d",
"[",
"2",
"]",
"=",
"d2",
";",
"d",
"[",
"3",
"]",
"=",
"d0",
";",
"d",
"[",
"4",
"]",
"=",
"s",
"[",
"4",
"]",
";",
"s",
"+=",
"5",
";",
"d",
"+=",
"5",
";",
"}",
"gfx_element_set_source",
"(",
"machine",
"->",
"gfx",
"[",
"gfxnum",
"]",
",",
"decoded",
")",
";",
"}"
] | create a decoding buffer to hold decodable tiles so that the ROM test will pass by
reading the original raw data | [
"create",
"a",
"decoding",
"buffer",
"to",
"hold",
"decodable",
"tiles",
"so",
"that",
"the",
"ROM",
"test",
"will",
"pass",
"by",
"reading",
"the",
"original",
"raw",
"data"
] | [
"// now convert the data into a drawable format so we can decode it",
"/* convert the whole mess to 5bpp planar in System GX's format\n (p3 p1 p2 p0 p5)\n (the original ROMs are stored as chunky for the first 4 bits\n and the 5th bit is planar, which is undecodable as-is) */"
] | [
{
"param": "machine",
"type": "running_machine"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
becc0c90e65b198bfd31b9750a7c2e43a97ba218 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/video/midzeus.c | [
"Unlicense"
] | C | zeus_register_update | void | static void zeus_register_update(running_machine *machine, offs_t offset)
{
/* handle the writes; only trigger on low accesses */
switch (offset)
{
case 0x52:
zeusbase[0xb2] = zeusbase[0x52];
break;
case 0x60:
/* invasn writes here to execute a command (?) */
if (zeusbase[0x60] & 1)
{
if ((zeusbase[0x80] & 0xffffff) == 0x22FCFF)
{
// zeusbase[0x00] = color
// zeusbase[0x02] = ??? = 0x000C0000
// zeusbase[0x04] = ??? = 0x00000E01
// zeusbase[0x06] = ??? = 0xFFFF0030
// zeusbase[0x08] = vert[0] = (y0 << 16) | x0
// zeusbase[0x0a] = vert[1] = (y1 << 16) | x1
// zeusbase[0x0c] = vert[2] = (y2 << 16) | x2
// zeusbase[0x0e] = vert[3] = (y3 << 16) | x3
// zeusbase[0x18] = ??? = 0xFFFFFFFF
// zeusbase[0x1a] = ??? = 0xFFFFFFFF
// zeusbase[0x1c] = ??? = 0xFFFFFFFF
// zeusbase[0x1e] = ??? = 0xFFFFFFFF
// zeusbase[0x20] = ??? = 0x00000000
// zeusbase[0x22] = ??? = 0x00000000
// zeusbase[0x24] = ??? = 0x00000000
// zeusbase[0x26] = ??? = 0x00000000
// zeusbase[0x40] = ??? = 0x00000000
// zeusbase[0x42] = ??? = 0x00000000
// zeusbase[0x44] = ??? = 0x00000000
// zeusbase[0x46] = ??? = 0x00000000
// zeusbase[0x4c] = ??? = 0x00808080 (brightness?)
// zeusbase[0x4e] = ??? = 0x00808080 (brightness?)
poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly);
poly_vertex vert[4];
vert[0].x = (INT16)zeusbase[0x08];
vert[0].y = (INT16)(zeusbase[0x08] >> 16);
vert[1].x = (INT16)zeusbase[0x0a];
vert[1].y = (INT16)(zeusbase[0x0a] >> 16);
vert[2].x = (INT16)zeusbase[0x0c];
vert[2].y = (INT16)(zeusbase[0x0c] >> 16);
vert[3].x = (INT16)zeusbase[0x0e];
vert[3].y = (INT16)(zeusbase[0x0e] >> 16);
extra->solidcolor = zeusbase[0x00];
extra->zoffset = 0x7fff;
poly_render_quad(poly, NULL, &zeus_cliprect, render_poly_solid_fixedz, 0, &vert[0], &vert[1], &vert[2], &vert[3]);
poly_wait(poly, "Normal");
}
else
logerror("Execute unknown command\n");
}
break;
case 0x70:
zeus_point[0] = zeusbase[0x70] << 16;
break;
case 0x72:
zeus_point[1] = zeusbase[0x72] << 16;
break;
case 0x74:
zeus_point[2] = zeusbase[0x74] << 16;
break;
case 0x80:
/* this bit enables the "FIFO empty" IRQ; since our virtual FIFO is always empty,
we simply assert immediately if this is enabled. invasn needs this for proper
operations */
if (zeusbase[0x80] & 0x02000000)
cputag_set_input_line(machine, "maincpu", 2, ASSERT_LINE);
else
cputag_set_input_line(machine, "maincpu", 2, CLEAR_LINE);
break;
case 0x84:
/* MK4: Written in tandem with 0xcc */
/* MK4: Writes either 0x80 (and 0x000000 to 0xcc) or 0x00 (and 0x800000 to 0xcc) */
zeus_renderbase = waveram1_ptr_from_expanded_addr(zeusbase[0x84] << 16);
break;
case 0xb0:
case 0xb2:
if ((zeusbase[0xb6] >> 16) != 0)
{
if ((offset == 0xb0 && (zeusbase[0xb6] & 0x02000000) == 0) ||
(offset == 0xb2 && (zeusbase[0xb6] & 0x02000000) != 0))
{
void *dest;
if (zeusbase[0xb6] & 0x80000000)
dest = waveram1_ptr_from_expanded_addr(zeusbase[0xb4]);
else
dest = waveram0_ptr_from_expanded_addr(zeusbase[0xb4]);
if (zeusbase[0xb6] & 0x00100000)
WAVERAM_WRITE16(dest, 0, zeusbase[0xb0]);
if (zeusbase[0xb6] & 0x00200000)
WAVERAM_WRITE16(dest, 1, zeusbase[0xb0] >> 16);
if (zeusbase[0xb6] & 0x00400000)
WAVERAM_WRITE16(dest, 2, zeusbase[0xb2]);
if (zeusbase[0xb6] & 0x00800000)
WAVERAM_WRITE16(dest, 3, zeusbase[0xb2] >> 16);
if (zeusbase[0xb6] & 0x00020000)
zeusbase[0xb4]++;
}
}
break;
case 0xb4:
if (zeusbase[0xb6] & 0x00010000)
{
const UINT32 *src;
if (zeusbase[0xb6] & 0x80000000)
src = (const UINT32 *)waveram1_ptr_from_expanded_addr(zeusbase[0xb4]);
else
src = (const UINT32 *)waveram0_ptr_from_expanded_addr(zeusbase[0xb4]);
poly_wait(poly, "vram_read");
zeusbase[0xb0] = WAVERAM_READ32(src, 0);
zeusbase[0xb2] = WAVERAM_READ32(src, 1);
}
break;
case 0xc0:
case 0xc2:
case 0xc4:
case 0xc6:
case 0xc8:
case 0xca:
video_screen_update_partial(machine->primary_screen, video_screen_get_vpos(machine->primary_screen));
{
int vtotal = zeusbase[0xca] >> 16;
int htotal = zeusbase[0xc6] >> 16;
rectangle visarea;
visarea.min_x = zeusbase[0xc6] & 0xffff;
visarea.max_x = htotal - 3;
visarea.min_y = 0;
visarea.max_y = zeusbase[0xc8] & 0xffff;
if (htotal > 0 && vtotal > 0 && visarea.min_x < visarea.max_x && visarea.max_y < vtotal)
{
video_screen_configure(machine->primary_screen, htotal, vtotal, &visarea, HZ_TO_ATTOSECONDS((double)MIDZEUS_VIDEO_CLOCK / 8.0 / (htotal * vtotal)));
zeus_cliprect = visarea;
zeus_cliprect.max_x -= zeus_cliprect.min_x;
zeus_cliprect.min_x = 0;
}
}
break;
case 0xcc:
video_screen_update_partial(machine->primary_screen, video_screen_get_vpos(machine->primary_screen));
log_fifo = input_code_pressed(machine, KEYCODE_L);
break;
case 0xe0:
zeus_fifo[zeus_fifo_words++] = zeusbase[0xe0];
if (zeus_fifo_process(machine, zeus_fifo, zeus_fifo_words))
zeus_fifo_words = 0;
break;
}
} | /*************************************
*
* Update state after a register write
*
*************************************/ | Update state after a register write | [
"Update",
"state",
"after",
"a",
"register",
"write"
] | static void zeus_register_update(running_machine *machine, offs_t offset)
{
switch (offset)
{
case 0x52:
zeusbase[0xb2] = zeusbase[0x52];
break;
case 0x60:
if (zeusbase[0x60] & 1)
{
if ((zeusbase[0x80] & 0xffffff) == 0x22FCFF)
{
poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly);
poly_vertex vert[4];
vert[0].x = (INT16)zeusbase[0x08];
vert[0].y = (INT16)(zeusbase[0x08] >> 16);
vert[1].x = (INT16)zeusbase[0x0a];
vert[1].y = (INT16)(zeusbase[0x0a] >> 16);
vert[2].x = (INT16)zeusbase[0x0c];
vert[2].y = (INT16)(zeusbase[0x0c] >> 16);
vert[3].x = (INT16)zeusbase[0x0e];
vert[3].y = (INT16)(zeusbase[0x0e] >> 16);
extra->solidcolor = zeusbase[0x00];
extra->zoffset = 0x7fff;
poly_render_quad(poly, NULL, &zeus_cliprect, render_poly_solid_fixedz, 0, &vert[0], &vert[1], &vert[2], &vert[3]);
poly_wait(poly, "Normal");
}
else
logerror("Execute unknown command\n");
}
break;
case 0x70:
zeus_point[0] = zeusbase[0x70] << 16;
break;
case 0x72:
zeus_point[1] = zeusbase[0x72] << 16;
break;
case 0x74:
zeus_point[2] = zeusbase[0x74] << 16;
break;
case 0x80:
if (zeusbase[0x80] & 0x02000000)
cputag_set_input_line(machine, "maincpu", 2, ASSERT_LINE);
else
cputag_set_input_line(machine, "maincpu", 2, CLEAR_LINE);
break;
case 0x84:
zeus_renderbase = waveram1_ptr_from_expanded_addr(zeusbase[0x84] << 16);
break;
case 0xb0:
case 0xb2:
if ((zeusbase[0xb6] >> 16) != 0)
{
if ((offset == 0xb0 && (zeusbase[0xb6] & 0x02000000) == 0) ||
(offset == 0xb2 && (zeusbase[0xb6] & 0x02000000) != 0))
{
void *dest;
if (zeusbase[0xb6] & 0x80000000)
dest = waveram1_ptr_from_expanded_addr(zeusbase[0xb4]);
else
dest = waveram0_ptr_from_expanded_addr(zeusbase[0xb4]);
if (zeusbase[0xb6] & 0x00100000)
WAVERAM_WRITE16(dest, 0, zeusbase[0xb0]);
if (zeusbase[0xb6] & 0x00200000)
WAVERAM_WRITE16(dest, 1, zeusbase[0xb0] >> 16);
if (zeusbase[0xb6] & 0x00400000)
WAVERAM_WRITE16(dest, 2, zeusbase[0xb2]);
if (zeusbase[0xb6] & 0x00800000)
WAVERAM_WRITE16(dest, 3, zeusbase[0xb2] >> 16);
if (zeusbase[0xb6] & 0x00020000)
zeusbase[0xb4]++;
}
}
break;
case 0xb4:
if (zeusbase[0xb6] & 0x00010000)
{
const UINT32 *src;
if (zeusbase[0xb6] & 0x80000000)
src = (const UINT32 *)waveram1_ptr_from_expanded_addr(zeusbase[0xb4]);
else
src = (const UINT32 *)waveram0_ptr_from_expanded_addr(zeusbase[0xb4]);
poly_wait(poly, "vram_read");
zeusbase[0xb0] = WAVERAM_READ32(src, 0);
zeusbase[0xb2] = WAVERAM_READ32(src, 1);
}
break;
case 0xc0:
case 0xc2:
case 0xc4:
case 0xc6:
case 0xc8:
case 0xca:
video_screen_update_partial(machine->primary_screen, video_screen_get_vpos(machine->primary_screen));
{
int vtotal = zeusbase[0xca] >> 16;
int htotal = zeusbase[0xc6] >> 16;
rectangle visarea;
visarea.min_x = zeusbase[0xc6] & 0xffff;
visarea.max_x = htotal - 3;
visarea.min_y = 0;
visarea.max_y = zeusbase[0xc8] & 0xffff;
if (htotal > 0 && vtotal > 0 && visarea.min_x < visarea.max_x && visarea.max_y < vtotal)
{
video_screen_configure(machine->primary_screen, htotal, vtotal, &visarea, HZ_TO_ATTOSECONDS((double)MIDZEUS_VIDEO_CLOCK / 8.0 / (htotal * vtotal)));
zeus_cliprect = visarea;
zeus_cliprect.max_x -= zeus_cliprect.min_x;
zeus_cliprect.min_x = 0;
}
}
break;
case 0xcc:
video_screen_update_partial(machine->primary_screen, video_screen_get_vpos(machine->primary_screen));
log_fifo = input_code_pressed(machine, KEYCODE_L);
break;
case 0xe0:
zeus_fifo[zeus_fifo_words++] = zeusbase[0xe0];
if (zeus_fifo_process(machine, zeus_fifo, zeus_fifo_words))
zeus_fifo_words = 0;
break;
}
} | [
"static",
"void",
"zeus_register_update",
"(",
"running_machine",
"*",
"machine",
",",
"offs_t",
"offset",
")",
"{",
"switch",
"(",
"offset",
")",
"{",
"case",
"0x52",
":",
"zeusbase",
"[",
"0xb2",
"]",
"=",
"zeusbase",
"[",
"0x52",
"]",
";",
"break",
";",
"case",
"0x60",
":",
"if",
"(",
"zeusbase",
"[",
"0x60",
"]",
"&",
"1",
")",
"{",
"if",
"(",
"(",
"zeusbase",
"[",
"0x80",
"]",
"&",
"0xffffff",
")",
"==",
"0x22FCFF",
")",
"{",
"poly_extra_data",
"*",
"extra",
"=",
"(",
"poly_extra_data",
"*",
")",
"poly_get_extra_data",
"(",
"poly",
")",
";",
"poly_vertex",
"vert",
"[",
"4",
"]",
";",
"vert",
"[",
"0",
"]",
".",
"x",
"=",
"(",
"INT16",
")",
"zeusbase",
"[",
"0x08",
"]",
";",
"vert",
"[",
"0",
"]",
".",
"y",
"=",
"(",
"INT16",
")",
"(",
"zeusbase",
"[",
"0x08",
"]",
">>",
"16",
")",
";",
"vert",
"[",
"1",
"]",
".",
"x",
"=",
"(",
"INT16",
")",
"zeusbase",
"[",
"0x0a",
"]",
";",
"vert",
"[",
"1",
"]",
".",
"y",
"=",
"(",
"INT16",
")",
"(",
"zeusbase",
"[",
"0x0a",
"]",
">>",
"16",
")",
";",
"vert",
"[",
"2",
"]",
".",
"x",
"=",
"(",
"INT16",
")",
"zeusbase",
"[",
"0x0c",
"]",
";",
"vert",
"[",
"2",
"]",
".",
"y",
"=",
"(",
"INT16",
")",
"(",
"zeusbase",
"[",
"0x0c",
"]",
">>",
"16",
")",
";",
"vert",
"[",
"3",
"]",
".",
"x",
"=",
"(",
"INT16",
")",
"zeusbase",
"[",
"0x0e",
"]",
";",
"vert",
"[",
"3",
"]",
".",
"y",
"=",
"(",
"INT16",
")",
"(",
"zeusbase",
"[",
"0x0e",
"]",
">>",
"16",
")",
";",
"extra",
"->",
"solidcolor",
"=",
"zeusbase",
"[",
"0x00",
"]",
";",
"extra",
"->",
"zoffset",
"=",
"0x7fff",
";",
"poly_render_quad",
"(",
"poly",
",",
"NULL",
",",
"&",
"zeus_cliprect",
",",
"render_poly_solid_fixedz",
",",
"0",
",",
"&",
"vert",
"[",
"0",
"]",
",",
"&",
"vert",
"[",
"1",
"]",
",",
"&",
"vert",
"[",
"2",
"]",
",",
"&",
"vert",
"[",
"3",
"]",
")",
";",
"poly_wait",
"(",
"poly",
",",
"\"",
"\"",
")",
";",
"}",
"else",
"logerror",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"break",
";",
"case",
"0x70",
":",
"zeus_point",
"[",
"0",
"]",
"=",
"zeusbase",
"[",
"0x70",
"]",
"<<",
"16",
";",
"break",
";",
"case",
"0x72",
":",
"zeus_point",
"[",
"1",
"]",
"=",
"zeusbase",
"[",
"0x72",
"]",
"<<",
"16",
";",
"break",
";",
"case",
"0x74",
":",
"zeus_point",
"[",
"2",
"]",
"=",
"zeusbase",
"[",
"0x74",
"]",
"<<",
"16",
";",
"break",
";",
"case",
"0x80",
":",
"if",
"(",
"zeusbase",
"[",
"0x80",
"]",
"&",
"0x02000000",
")",
"cputag_set_input_line",
"(",
"machine",
",",
"\"",
"\"",
",",
"2",
",",
"ASSERT_LINE",
")",
";",
"else",
"cputag_set_input_line",
"(",
"machine",
",",
"\"",
"\"",
",",
"2",
",",
"CLEAR_LINE",
")",
";",
"break",
";",
"case",
"0x84",
":",
"zeus_renderbase",
"=",
"waveram1_ptr_from_expanded_addr",
"(",
"zeusbase",
"[",
"0x84",
"]",
"<<",
"16",
")",
";",
"break",
";",
"case",
"0xb0",
":",
"case",
"0xb2",
":",
"if",
"(",
"(",
"zeusbase",
"[",
"0xb6",
"]",
">>",
"16",
")",
"!=",
"0",
")",
"{",
"if",
"(",
"(",
"offset",
"==",
"0xb0",
"&&",
"(",
"zeusbase",
"[",
"0xb6",
"]",
"&",
"0x02000000",
")",
"==",
"0",
")",
"||",
"(",
"offset",
"==",
"0xb2",
"&&",
"(",
"zeusbase",
"[",
"0xb6",
"]",
"&",
"0x02000000",
")",
"!=",
"0",
")",
")",
"{",
"void",
"*",
"dest",
";",
"if",
"(",
"zeusbase",
"[",
"0xb6",
"]",
"&",
"0x80000000",
")",
"dest",
"=",
"waveram1_ptr_from_expanded_addr",
"(",
"zeusbase",
"[",
"0xb4",
"]",
")",
";",
"else",
"dest",
"=",
"waveram0_ptr_from_expanded_addr",
"(",
"zeusbase",
"[",
"0xb4",
"]",
")",
";",
"if",
"(",
"zeusbase",
"[",
"0xb6",
"]",
"&",
"0x00100000",
")",
"WAVERAM_WRITE16",
"(",
"dest",
",",
"0",
",",
"zeusbase",
"[",
"0xb0",
"]",
")",
";",
"if",
"(",
"zeusbase",
"[",
"0xb6",
"]",
"&",
"0x00200000",
")",
"WAVERAM_WRITE16",
"(",
"dest",
",",
"1",
",",
"zeusbase",
"[",
"0xb0",
"]",
">>",
"16",
")",
";",
"if",
"(",
"zeusbase",
"[",
"0xb6",
"]",
"&",
"0x00400000",
")",
"WAVERAM_WRITE16",
"(",
"dest",
",",
"2",
",",
"zeusbase",
"[",
"0xb2",
"]",
")",
";",
"if",
"(",
"zeusbase",
"[",
"0xb6",
"]",
"&",
"0x00800000",
")",
"WAVERAM_WRITE16",
"(",
"dest",
",",
"3",
",",
"zeusbase",
"[",
"0xb2",
"]",
">>",
"16",
")",
";",
"if",
"(",
"zeusbase",
"[",
"0xb6",
"]",
"&",
"0x00020000",
")",
"zeusbase",
"[",
"0xb4",
"]",
"++",
";",
"}",
"}",
"break",
";",
"case",
"0xb4",
":",
"if",
"(",
"zeusbase",
"[",
"0xb6",
"]",
"&",
"0x00010000",
")",
"{",
"const",
"UINT32",
"*",
"src",
";",
"if",
"(",
"zeusbase",
"[",
"0xb6",
"]",
"&",
"0x80000000",
")",
"src",
"=",
"(",
"const",
"UINT32",
"*",
")",
"waveram1_ptr_from_expanded_addr",
"(",
"zeusbase",
"[",
"0xb4",
"]",
")",
";",
"else",
"src",
"=",
"(",
"const",
"UINT32",
"*",
")",
"waveram0_ptr_from_expanded_addr",
"(",
"zeusbase",
"[",
"0xb4",
"]",
")",
";",
"poly_wait",
"(",
"poly",
",",
"\"",
"\"",
")",
";",
"zeusbase",
"[",
"0xb0",
"]",
"=",
"WAVERAM_READ32",
"(",
"src",
",",
"0",
")",
";",
"zeusbase",
"[",
"0xb2",
"]",
"=",
"WAVERAM_READ32",
"(",
"src",
",",
"1",
")",
";",
"}",
"break",
";",
"case",
"0xc0",
":",
"case",
"0xc2",
":",
"case",
"0xc4",
":",
"case",
"0xc6",
":",
"case",
"0xc8",
":",
"case",
"0xca",
":",
"video_screen_update_partial",
"(",
"machine",
"->",
"primary_screen",
",",
"video_screen_get_vpos",
"(",
"machine",
"->",
"primary_screen",
")",
")",
";",
"{",
"int",
"vtotal",
"=",
"zeusbase",
"[",
"0xca",
"]",
">>",
"16",
";",
"int",
"htotal",
"=",
"zeusbase",
"[",
"0xc6",
"]",
">>",
"16",
";",
"rectangle",
"visarea",
";",
"visarea",
".",
"min_x",
"=",
"zeusbase",
"[",
"0xc6",
"]",
"&",
"0xffff",
";",
"visarea",
".",
"max_x",
"=",
"htotal",
"-",
"3",
";",
"visarea",
".",
"min_y",
"=",
"0",
";",
"visarea",
".",
"max_y",
"=",
"zeusbase",
"[",
"0xc8",
"]",
"&",
"0xffff",
";",
"if",
"(",
"htotal",
">",
"0",
"&&",
"vtotal",
">",
"0",
"&&",
"visarea",
".",
"min_x",
"<",
"visarea",
".",
"max_x",
"&&",
"visarea",
".",
"max_y",
"<",
"vtotal",
")",
"{",
"video_screen_configure",
"(",
"machine",
"->",
"primary_screen",
",",
"htotal",
",",
"vtotal",
",",
"&",
"visarea",
",",
"HZ_TO_ATTOSECONDS",
"(",
"(",
"double",
")",
"MIDZEUS_VIDEO_CLOCK",
"/",
"8.0",
"/",
"(",
"htotal",
"*",
"vtotal",
")",
")",
")",
";",
"zeus_cliprect",
"=",
"visarea",
";",
"zeus_cliprect",
".",
"max_x",
"-=",
"zeus_cliprect",
".",
"min_x",
";",
"zeus_cliprect",
".",
"min_x",
"=",
"0",
";",
"}",
"}",
"break",
";",
"case",
"0xcc",
":",
"video_screen_update_partial",
"(",
"machine",
"->",
"primary_screen",
",",
"video_screen_get_vpos",
"(",
"machine",
"->",
"primary_screen",
")",
")",
";",
"log_fifo",
"=",
"input_code_pressed",
"(",
"machine",
",",
"KEYCODE_L",
")",
";",
"break",
";",
"case",
"0xe0",
":",
"zeus_fifo",
"[",
"zeus_fifo_words",
"++",
"]",
"=",
"zeusbase",
"[",
"0xe0",
"]",
";",
"if",
"(",
"zeus_fifo_process",
"(",
"machine",
",",
"zeus_fifo",
",",
"zeus_fifo_words",
")",
")",
"zeus_fifo_words",
"=",
"0",
";",
"break",
";",
"}",
"}"
] | Update state after a register write | [
"Update",
"state",
"after",
"a",
"register",
"write"
] | [
"/* handle the writes; only trigger on low accesses */",
"/* invasn writes here to execute a command (?) */",
"// zeusbase[0x00] = color",
"// zeusbase[0x02] = ??? = 0x000C0000",
"// zeusbase[0x04] = ??? = 0x00000E01",
"// zeusbase[0x06] = ??? = 0xFFFF0030",
"// zeusbase[0x08] = vert[0] = (y0 << 16) | x0",
"// zeusbase[0x0a] = vert[1] = (y1 << 16) | x1",
"// zeusbase[0x0c] = vert[2] = (y2 << 16) | x2",
"// zeusbase[0x0e] = vert[3] = (y3 << 16) | x3",
"// zeusbase[0x18] = ??? = 0xFFFFFFFF",
"// zeusbase[0x1a] = ??? = 0xFFFFFFFF",
"// zeusbase[0x1c] = ??? = 0xFFFFFFFF",
"// zeusbase[0x1e] = ??? = 0xFFFFFFFF",
"// zeusbase[0x20] = ??? = 0x00000000",
"// zeusbase[0x22] = ??? = 0x00000000",
"// zeusbase[0x24] = ??? = 0x00000000",
"// zeusbase[0x26] = ??? = 0x00000000",
"// zeusbase[0x40] = ??? = 0x00000000",
"// zeusbase[0x42] = ??? = 0x00000000",
"// zeusbase[0x44] = ??? = 0x00000000",
"// zeusbase[0x46] = ??? = 0x00000000",
"// zeusbase[0x4c] = ??? = 0x00808080 (brightness?)",
"// zeusbase[0x4e] = ??? = 0x00808080 (brightness?)",
"/* this bit enables the \"FIFO empty\" IRQ; since our virtual FIFO is always empty,\n we simply assert immediately if this is enabled. invasn needs this for proper\n operations */",
"/* MK4: Written in tandem with 0xcc */",
"/* MK4: Writes either 0x80 (and 0x000000 to 0xcc) or 0x00 (and 0x800000 to 0xcc) */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "offset",
"type": "offs_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "offset",
"type": "offs_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
087e3eec2c6408f395ffd9fb1f1dbbe1eda098c7 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/drivers/deco156.c | [
"Unlicense"
] | C | draw_sprites | void | static void draw_sprites(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect)
{
int offs;
flip_screen_set_no_update(machine, 1);
for (offs = (0x1400/4)-4;offs >= 0;offs -= 4) // 0x1400 for charlien
{
int x,y,sprite,colour,multi,fx,fy,inc,flash,mult, pri;
sprite = spriteram32[offs+1]&0xffff;
y = spriteram32[offs]&0xffff;
flash=y&0x1000;
if (flash && (video_screen_get_frame_number(machine->primary_screen) & 1)) continue;
x = spriteram32[offs+2]&0xffff;
colour = (x >>9) & 0x1f;
pri = (x&0xc000); // 2 bits or 1?
switch (pri&0xc000) {
case 0x0000: pri=0; break;
case 0x4000: pri=0xf0; break;
case 0x8000: pri=0xf0|0xcc; break;
case 0xc000: pri=0xf0|0xcc; break; /* or 0xf0|0xcc|0xaa ? */
}
fx = y & 0x2000;
fy = y & 0x4000;
multi = (1 << ((y & 0x0600) >> 9)) - 1; /* 1x, 2x, 4x, 8x height */
x = x & 0x01ff;
y = y & 0x01ff;
if (x >= 320) x -= 512;
if (y >= 256) y -= 512;
y = 240 - y;
x = 304 - x;
if (x>320) continue;
sprite &= ~multi;
if (fy)
inc = -1;
else
{
sprite += multi;
inc = 1;
}
if (flip_screen_x_get(machine))
{
y=240-y;
x=304-x;
if (fx) fx=0; else fx=1;
if (fy) fy=0; else fy=1;
mult=16;
}
else mult=-16;
while (multi >= 0)
{
pdrawgfx_transpen(bitmap,cliprect,machine->gfx[2],
sprite - multi * inc,
colour,
fx,fy,
x,y + mult * multi,
machine->priority_bitmap,pri,0);
multi--;
}
}
} | /* spriteram is really 16-bit.. this can be changed to use 16-bit ram like the tilemaps
its the same sprite chip Data East used on many, many 16-bit era titles */ | spriteram is really 16-bit.. this can be changed to use 16-bit ram like the tilemaps
its the same sprite chip Data East used on many, many 16-bit era titles | [
"spriteram",
"is",
"really",
"16",
"-",
"bit",
"..",
"this",
"can",
"be",
"changed",
"to",
"use",
"16",
"-",
"bit",
"ram",
"like",
"the",
"tilemaps",
"its",
"the",
"same",
"sprite",
"chip",
"Data",
"East",
"used",
"on",
"many",
"many",
"16",
"-",
"bit",
"era",
"titles"
] | static void draw_sprites(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect)
{
int offs;
flip_screen_set_no_update(machine, 1);
for (offs = (0x1400/4)-4;offs >= 0;offs -= 4)
{
int x,y,sprite,colour,multi,fx,fy,inc,flash,mult, pri;
sprite = spriteram32[offs+1]&0xffff;
y = spriteram32[offs]&0xffff;
flash=y&0x1000;
if (flash && (video_screen_get_frame_number(machine->primary_screen) & 1)) continue;
x = spriteram32[offs+2]&0xffff;
colour = (x >>9) & 0x1f;
pri = (x&0xc000);
switch (pri&0xc000) {
case 0x0000: pri=0; break;
case 0x4000: pri=0xf0; break;
case 0x8000: pri=0xf0|0xcc; break;
case 0xc000: pri=0xf0|0xcc; break;
}
fx = y & 0x2000;
fy = y & 0x4000;
multi = (1 << ((y & 0x0600) >> 9)) - 1;
x = x & 0x01ff;
y = y & 0x01ff;
if (x >= 320) x -= 512;
if (y >= 256) y -= 512;
y = 240 - y;
x = 304 - x;
if (x>320) continue;
sprite &= ~multi;
if (fy)
inc = -1;
else
{
sprite += multi;
inc = 1;
}
if (flip_screen_x_get(machine))
{
y=240-y;
x=304-x;
if (fx) fx=0; else fx=1;
if (fy) fy=0; else fy=1;
mult=16;
}
else mult=-16;
while (multi >= 0)
{
pdrawgfx_transpen(bitmap,cliprect,machine->gfx[2],
sprite - multi * inc,
colour,
fx,fy,
x,y + mult * multi,
machine->priority_bitmap,pri,0);
multi--;
}
}
} | [
"static",
"void",
"draw_sprites",
"(",
"running_machine",
"*",
"machine",
",",
"bitmap_t",
"*",
"bitmap",
",",
"const",
"rectangle",
"*",
"cliprect",
")",
"{",
"int",
"offs",
";",
"flip_screen_set_no_update",
"(",
"machine",
",",
"1",
")",
";",
"for",
"(",
"offs",
"=",
"(",
"0x1400",
"/",
"4",
")",
"-",
"4",
";",
"offs",
">=",
"0",
";",
"offs",
"-=",
"4",
")",
"{",
"int",
"x",
",",
"y",
",",
"sprite",
",",
"colour",
",",
"multi",
",",
"fx",
",",
"fy",
",",
"inc",
",",
"flash",
",",
"mult",
",",
"pri",
";",
"sprite",
"=",
"spriteram32",
"[",
"offs",
"+",
"1",
"]",
"&",
"0xffff",
";",
"y",
"=",
"spriteram32",
"[",
"offs",
"]",
"&",
"0xffff",
";",
"flash",
"=",
"y",
"&",
"0x1000",
";",
"if",
"(",
"flash",
"&&",
"(",
"video_screen_get_frame_number",
"(",
"machine",
"->",
"primary_screen",
")",
"&",
"1",
")",
")",
"continue",
";",
"x",
"=",
"spriteram32",
"[",
"offs",
"+",
"2",
"]",
"&",
"0xffff",
";",
"colour",
"=",
"(",
"x",
">>",
"9",
")",
"&",
"0x1f",
";",
"pri",
"=",
"(",
"x",
"&",
"0xc000",
")",
";",
"switch",
"(",
"pri",
"&",
"0xc000",
")",
"{",
"case",
"0x0000",
":",
"pri",
"=",
"0",
";",
"break",
";",
"case",
"0x4000",
":",
"pri",
"=",
"0xf0",
";",
"break",
";",
"case",
"0x8000",
":",
"pri",
"=",
"0xf0",
"|",
"0xcc",
";",
"break",
";",
"case",
"0xc000",
":",
"pri",
"=",
"0xf0",
"|",
"0xcc",
";",
"break",
";",
"}",
"fx",
"=",
"y",
"&",
"0x2000",
";",
"fy",
"=",
"y",
"&",
"0x4000",
";",
"multi",
"=",
"(",
"1",
"<<",
"(",
"(",
"y",
"&",
"0x0600",
")",
">>",
"9",
")",
")",
"-",
"1",
";",
"x",
"=",
"x",
"&",
"0x01ff",
";",
"y",
"=",
"y",
"&",
"0x01ff",
";",
"if",
"(",
"x",
">=",
"320",
")",
"x",
"-=",
"512",
";",
"if",
"(",
"y",
">=",
"256",
")",
"y",
"-=",
"512",
";",
"y",
"=",
"240",
"-",
"y",
";",
"x",
"=",
"304",
"-",
"x",
";",
"if",
"(",
"x",
">",
"320",
")",
"continue",
";",
"sprite",
"&=",
"~",
"multi",
";",
"if",
"(",
"fy",
")",
"inc",
"=",
"-1",
";",
"else",
"{",
"sprite",
"+=",
"multi",
";",
"inc",
"=",
"1",
";",
"}",
"if",
"(",
"flip_screen_x_get",
"(",
"machine",
")",
")",
"{",
"y",
"=",
"240",
"-",
"y",
";",
"x",
"=",
"304",
"-",
"x",
";",
"if",
"(",
"fx",
")",
"fx",
"=",
"0",
";",
"else",
"fx",
"=",
"1",
";",
"if",
"(",
"fy",
")",
"fy",
"=",
"0",
";",
"else",
"fy",
"=",
"1",
";",
"mult",
"=",
"16",
";",
"}",
"else",
"mult",
"=",
"-16",
";",
"while",
"(",
"multi",
">=",
"0",
")",
"{",
"pdrawgfx_transpen",
"(",
"bitmap",
",",
"cliprect",
",",
"machine",
"->",
"gfx",
"[",
"2",
"]",
",",
"sprite",
"-",
"multi",
"*",
"inc",
",",
"colour",
",",
"fx",
",",
"fy",
",",
"x",
",",
"y",
"+",
"mult",
"*",
"multi",
",",
"machine",
"->",
"priority_bitmap",
",",
"pri",
",",
"0",
")",
";",
"multi",
"--",
";",
"}",
"}",
"}"
] | spriteram is really 16-bit.. this can be changed to use 16-bit ram like the tilemaps
its the same sprite chip Data East used on many, many 16-bit era titles | [
"spriteram",
"is",
"really",
"16",
"-",
"bit",
"..",
"this",
"can",
"be",
"changed",
"to",
"use",
"16",
"-",
"bit",
"ram",
"like",
"the",
"tilemaps",
"its",
"the",
"same",
"sprite",
"chip",
"Data",
"East",
"used",
"on",
"many",
"many",
"16",
"-",
"bit",
"era",
"titles"
] | [
"// 0x1400 for charlien",
"// 2 bits or 1?",
"/* or 0xf0|0xcc|0xaa ? */",
"/* 1x, 2x, 4x, 8x height */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "bitmap",
"type": "bitmap_t"
},
{
"param": "cliprect",
"type": "rectangle"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "bitmap",
"type": "bitmap_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cliprect",
"type": "rectangle",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
086da6442afe70fc7b1e58c0b2151f2aab2a1a2f | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/video/othunder.c | [
"Unlicense"
] | C | draw_sprites | void | static void draw_sprites(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,const int *primasks,int y_offs)
{
UINT16 *spritemap = (UINT16 *)memory_region(machine, "user1");
UINT16 tile_mask = (machine->gfx[0]->total_elements) - 1;
int offs, data, tilenum, color, flipx, flipy;
int x, y, priority, curx, cury;
int sprites_flipscreen = 0;
int zoomx, zoomy, zx, zy;
int sprite_chunk,map_offset,code,j,k,px,py;
int bad_chunks;
/* pdrawgfx() needs us to draw sprites front to back, so we have to build a list
while processing sprite ram and then draw them all at the end */
struct tempsprite *sprite_ptr = spritelist;
for (offs = (spriteram_size/2)-4;offs >=0;offs -= 4)
{
data = spriteram16[offs+0];
zoomy = (data & 0xfe00) >> 9;
y = data & 0x1ff;
data = spriteram16[offs+1];
flipx = (data & 0x4000) >> 14;
priority = (data & 0x8000) >> 15;
x = data & 0x1ff;
data = spriteram16[offs+2];
color = (data & 0xff00) >> 8;
zoomx = (data & 0x7f);
data = spriteram16[offs+3];
tilenum = data & 0x1fff; // $80000 spritemap rom maps up to $2000 64x64 sprites
flipy = (data & 0x8000) >> 15;
if (!tilenum) continue;
map_offset = tilenum << 5;
zoomx += 1;
zoomy += 1;
y += y_offs;
/* treat coords as signed */
if (x>0x140) x -= 0x200;
if (y>0x140) y -= 0x200;
bad_chunks = 0;
for (sprite_chunk=0;sprite_chunk<32;sprite_chunk++)
{
k = sprite_chunk % 4; /* 4 chunks per row */
j = sprite_chunk / 4; /* 8 rows */
px = k;
py = j;
if (flipx) px = 3-k; /* pick tiles back to front for x and y flips */
if (flipy) py = 7-j;
code = spritemap[map_offset + px + (py<<2)] &tile_mask;
if (code==0xffff)
{
bad_chunks += 1;
continue;
}
curx = x + ((k*zoomx)/4);
cury = y + ((j*zoomy)/8);
zx= x + (((k+1)*zoomx)/4) - curx;
zy= y + (((j+1)*zoomy)/8) - cury;
if (sprites_flipscreen)
{
/* -zx/y is there to fix zoomed sprite coords in screenflip.
drawgfxzoom does not know to draw from flip-side of sprites when
screen is flipped; so we must correct the coords ourselves. */
curx = 320 - curx - zx;
cury = 256 - cury - zy;
flipx = !flipx;
flipy = !flipy;
}
sprite_ptr->code = code;
sprite_ptr->color = color;
sprite_ptr->flipx = flipx;
sprite_ptr->flipy = flipy;
sprite_ptr->x = curx;
sprite_ptr->y = cury;
sprite_ptr->zoomx = zx << 12;
sprite_ptr->zoomy = zy << 13;
if (primasks)
{
sprite_ptr->primask = primasks[priority];
sprite_ptr++;
}
else
{
drawgfxzoom_transpen(bitmap,cliprect,machine->gfx[0],
sprite_ptr->code,
sprite_ptr->color,
sprite_ptr->flipx,sprite_ptr->flipy,
sprite_ptr->x,sprite_ptr->y,
sprite_ptr->zoomx,sprite_ptr->zoomy,0);
}
}
if (bad_chunks)
logerror("Sprite number %04x had %02x invalid chunks\n",tilenum,bad_chunks);
}
/* this happens only if primsks != NULL */
while (sprite_ptr != spritelist)
{
sprite_ptr--;
pdrawgfxzoom_transpen(bitmap,cliprect,machine->gfx[0],
sprite_ptr->code,
sprite_ptr->color,
sprite_ptr->flipx,sprite_ptr->flipy,
sprite_ptr->x,sprite_ptr->y,
sprite_ptr->zoomx,sprite_ptr->zoomy,
machine->priority_bitmap,sprite_ptr->primask,0);
}
} | /************************************************************
SPRITE DRAW ROUTINE
It draws a series of small tiles ("chunks") together to
create a big sprite. The spritemap rom provides the lookup
table for this. We look up the 16x8 sprite chunks from
the spritemap rom, creating each 64x64 sprite as follows:
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19
20 21 22 23
24 25 26 27
28 29 30 31
The game makes heavy use of sprite zooming.
***
NB: unused portions of the spritemap rom contain hex FF's.
It is a useful coding check to warn in the log if these
are being accessed. [They can be inadvertently while
spriteram is being tested, take no notice of that.]
Othunder (modified table from Raine)
Byte | Bit(s) | Description
-----+76543210+-------------------------------------
0 |xxxxxxx.| ZoomY (0 min, 63 max - msb unused as sprites are 64x64)
0 |.......x| Y position (High)
1 |xxxxxxxx| Y position (Low)
2 |x.......| Sprite/BG Priority (0=sprites high)
2 |.x......| Flip X
2 |..?????.| unknown/unused ?
2 |.......x| X position (High)
3 |xxxxxxxx| X position (Low)
4 |xxxxxxxx| Palette bank
5 |?.......| unknown/unused ?
5 |.xxxxxxx| ZoomX (0 min, 63 max - msb unused as sprites are 64x64)
6 |x.......| Flip Y
6 |.??.....| unknown/unused ?
6 |...xxxxx| Sprite Tile high (2 msbs unused - 3/4 of spritemap rom empty)
7 |xxxxxxxx| Sprite Tile low
********************************************************/ | SPRITE DRAW ROUTINE
It draws a series of small tiles ("chunks") together to
create a big sprite. The spritemap rom provides the lookup
table for this. We look up the 16x8 sprite chunks from
the spritemap rom, creating each 64x64 sprite as follows.
The game makes heavy use of sprite zooming.
unused portions of the spritemap rom contain hex FF's.
It is a useful coding check to warn in the log if these
are being accessed. [They can be inadvertently while
spriteram is being tested, take no notice of that.]
Othunder (modified table from Raine)
| [
"SPRITE",
"DRAW",
"ROUTINE",
"It",
"draws",
"a",
"series",
"of",
"small",
"tiles",
"(",
"\"",
"chunks",
"\"",
")",
"together",
"to",
"create",
"a",
"big",
"sprite",
".",
"The",
"spritemap",
"rom",
"provides",
"the",
"lookup",
"table",
"for",
"this",
".",
"We",
"look",
"up",
"the",
"16x8",
"sprite",
"chunks",
"from",
"the",
"spritemap",
"rom",
"creating",
"each",
"64x64",
"sprite",
"as",
"follows",
".",
"The",
"game",
"makes",
"heavy",
"use",
"of",
"sprite",
"zooming",
".",
"unused",
"portions",
"of",
"the",
"spritemap",
"rom",
"contain",
"hex",
"FF",
"'",
"s",
".",
"It",
"is",
"a",
"useful",
"coding",
"check",
"to",
"warn",
"in",
"the",
"log",
"if",
"these",
"are",
"being",
"accessed",
".",
"[",
"They",
"can",
"be",
"inadvertently",
"while",
"spriteram",
"is",
"being",
"tested",
"take",
"no",
"notice",
"of",
"that",
".",
"]",
"Othunder",
"(",
"modified",
"table",
"from",
"Raine",
")"
] | static void draw_sprites(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,const int *primasks,int y_offs)
{
UINT16 *spritemap = (UINT16 *)memory_region(machine, "user1");
UINT16 tile_mask = (machine->gfx[0]->total_elements) - 1;
int offs, data, tilenum, color, flipx, flipy;
int x, y, priority, curx, cury;
int sprites_flipscreen = 0;
int zoomx, zoomy, zx, zy;
int sprite_chunk,map_offset,code,j,k,px,py;
int bad_chunks;
struct tempsprite *sprite_ptr = spritelist;
for (offs = (spriteram_size/2)-4;offs >=0;offs -= 4)
{
data = spriteram16[offs+0];
zoomy = (data & 0xfe00) >> 9;
y = data & 0x1ff;
data = spriteram16[offs+1];
flipx = (data & 0x4000) >> 14;
priority = (data & 0x8000) >> 15;
x = data & 0x1ff;
data = spriteram16[offs+2];
color = (data & 0xff00) >> 8;
zoomx = (data & 0x7f);
data = spriteram16[offs+3];
tilenum = data & 0x1fff;
flipy = (data & 0x8000) >> 15;
if (!tilenum) continue;
map_offset = tilenum << 5;
zoomx += 1;
zoomy += 1;
y += y_offs;
if (x>0x140) x -= 0x200;
if (y>0x140) y -= 0x200;
bad_chunks = 0;
for (sprite_chunk=0;sprite_chunk<32;sprite_chunk++)
{
k = sprite_chunk % 4;
j = sprite_chunk / 4;
px = k;
py = j;
if (flipx) px = 3-k;
if (flipy) py = 7-j;
code = spritemap[map_offset + px + (py<<2)] &tile_mask;
if (code==0xffff)
{
bad_chunks += 1;
continue;
}
curx = x + ((k*zoomx)/4);
cury = y + ((j*zoomy)/8);
zx= x + (((k+1)*zoomx)/4) - curx;
zy= y + (((j+1)*zoomy)/8) - cury;
if (sprites_flipscreen)
{
curx = 320 - curx - zx;
cury = 256 - cury - zy;
flipx = !flipx;
flipy = !flipy;
}
sprite_ptr->code = code;
sprite_ptr->color = color;
sprite_ptr->flipx = flipx;
sprite_ptr->flipy = flipy;
sprite_ptr->x = curx;
sprite_ptr->y = cury;
sprite_ptr->zoomx = zx << 12;
sprite_ptr->zoomy = zy << 13;
if (primasks)
{
sprite_ptr->primask = primasks[priority];
sprite_ptr++;
}
else
{
drawgfxzoom_transpen(bitmap,cliprect,machine->gfx[0],
sprite_ptr->code,
sprite_ptr->color,
sprite_ptr->flipx,sprite_ptr->flipy,
sprite_ptr->x,sprite_ptr->y,
sprite_ptr->zoomx,sprite_ptr->zoomy,0);
}
}
if (bad_chunks)
logerror("Sprite number %04x had %02x invalid chunks\n",tilenum,bad_chunks);
}
while (sprite_ptr != spritelist)
{
sprite_ptr--;
pdrawgfxzoom_transpen(bitmap,cliprect,machine->gfx[0],
sprite_ptr->code,
sprite_ptr->color,
sprite_ptr->flipx,sprite_ptr->flipy,
sprite_ptr->x,sprite_ptr->y,
sprite_ptr->zoomx,sprite_ptr->zoomy,
machine->priority_bitmap,sprite_ptr->primask,0);
}
} | [
"static",
"void",
"draw_sprites",
"(",
"running_machine",
"*",
"machine",
",",
"bitmap_t",
"*",
"bitmap",
",",
"const",
"rectangle",
"*",
"cliprect",
",",
"const",
"int",
"*",
"primasks",
",",
"int",
"y_offs",
")",
"{",
"UINT16",
"*",
"spritemap",
"=",
"(",
"UINT16",
"*",
")",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"UINT16",
"tile_mask",
"=",
"(",
"machine",
"->",
"gfx",
"[",
"0",
"]",
"->",
"total_elements",
")",
"-",
"1",
";",
"int",
"offs",
",",
"data",
",",
"tilenum",
",",
"color",
",",
"flipx",
",",
"flipy",
";",
"int",
"x",
",",
"y",
",",
"priority",
",",
"curx",
",",
"cury",
";",
"int",
"sprites_flipscreen",
"=",
"0",
";",
"int",
"zoomx",
",",
"zoomy",
",",
"zx",
",",
"zy",
";",
"int",
"sprite_chunk",
",",
"map_offset",
",",
"code",
",",
"j",
",",
"k",
",",
"px",
",",
"py",
";",
"int",
"bad_chunks",
";",
"struct",
"tempsprite",
"*",
"sprite_ptr",
"=",
"spritelist",
";",
"for",
"(",
"offs",
"=",
"(",
"spriteram_size",
"/",
"2",
")",
"-",
"4",
";",
"offs",
">=",
"0",
";",
"offs",
"-=",
"4",
")",
"{",
"data",
"=",
"spriteram16",
"[",
"offs",
"+",
"0",
"]",
";",
"zoomy",
"=",
"(",
"data",
"&",
"0xfe00",
")",
">>",
"9",
";",
"y",
"=",
"data",
"&",
"0x1ff",
";",
"data",
"=",
"spriteram16",
"[",
"offs",
"+",
"1",
"]",
";",
"flipx",
"=",
"(",
"data",
"&",
"0x4000",
")",
">>",
"14",
";",
"priority",
"=",
"(",
"data",
"&",
"0x8000",
")",
">>",
"15",
";",
"x",
"=",
"data",
"&",
"0x1ff",
";",
"data",
"=",
"spriteram16",
"[",
"offs",
"+",
"2",
"]",
";",
"color",
"=",
"(",
"data",
"&",
"0xff00",
")",
">>",
"8",
";",
"zoomx",
"=",
"(",
"data",
"&",
"0x7f",
")",
";",
"data",
"=",
"spriteram16",
"[",
"offs",
"+",
"3",
"]",
";",
"tilenum",
"=",
"data",
"&",
"0x1fff",
";",
"flipy",
"=",
"(",
"data",
"&",
"0x8000",
")",
">>",
"15",
";",
"if",
"(",
"!",
"tilenum",
")",
"continue",
";",
"map_offset",
"=",
"tilenum",
"<<",
"5",
";",
"zoomx",
"+=",
"1",
";",
"zoomy",
"+=",
"1",
";",
"y",
"+=",
"y_offs",
";",
"if",
"(",
"x",
">",
"0x140",
")",
"x",
"-=",
"0x200",
";",
"if",
"(",
"y",
">",
"0x140",
")",
"y",
"-=",
"0x200",
";",
"bad_chunks",
"=",
"0",
";",
"for",
"(",
"sprite_chunk",
"=",
"0",
";",
"sprite_chunk",
"<",
"32",
";",
"sprite_chunk",
"++",
")",
"{",
"k",
"=",
"sprite_chunk",
"%",
"4",
";",
"j",
"=",
"sprite_chunk",
"/",
"4",
";",
"px",
"=",
"k",
";",
"py",
"=",
"j",
";",
"if",
"(",
"flipx",
")",
"px",
"=",
"3",
"-",
"k",
";",
"if",
"(",
"flipy",
")",
"py",
"=",
"7",
"-",
"j",
";",
"code",
"=",
"spritemap",
"[",
"map_offset",
"+",
"px",
"+",
"(",
"py",
"<<",
"2",
")",
"]",
"&",
"tile_mask",
";",
"if",
"(",
"code",
"==",
"0xffff",
")",
"{",
"bad_chunks",
"+=",
"1",
";",
"continue",
";",
"}",
"curx",
"=",
"x",
"+",
"(",
"(",
"k",
"*",
"zoomx",
")",
"/",
"4",
")",
";",
"cury",
"=",
"y",
"+",
"(",
"(",
"j",
"*",
"zoomy",
")",
"/",
"8",
")",
";",
"zx",
"=",
"x",
"+",
"(",
"(",
"(",
"k",
"+",
"1",
")",
"*",
"zoomx",
")",
"/",
"4",
")",
"-",
"curx",
";",
"zy",
"=",
"y",
"+",
"(",
"(",
"(",
"j",
"+",
"1",
")",
"*",
"zoomy",
")",
"/",
"8",
")",
"-",
"cury",
";",
"if",
"(",
"sprites_flipscreen",
")",
"{",
"curx",
"=",
"320",
"-",
"curx",
"-",
"zx",
";",
"cury",
"=",
"256",
"-",
"cury",
"-",
"zy",
";",
"flipx",
"=",
"!",
"flipx",
";",
"flipy",
"=",
"!",
"flipy",
";",
"}",
"sprite_ptr",
"->",
"code",
"=",
"code",
";",
"sprite_ptr",
"->",
"color",
"=",
"color",
";",
"sprite_ptr",
"->",
"flipx",
"=",
"flipx",
";",
"sprite_ptr",
"->",
"flipy",
"=",
"flipy",
";",
"sprite_ptr",
"->",
"x",
"=",
"curx",
";",
"sprite_ptr",
"->",
"y",
"=",
"cury",
";",
"sprite_ptr",
"->",
"zoomx",
"=",
"zx",
"<<",
"12",
";",
"sprite_ptr",
"->",
"zoomy",
"=",
"zy",
"<<",
"13",
";",
"if",
"(",
"primasks",
")",
"{",
"sprite_ptr",
"->",
"primask",
"=",
"primasks",
"[",
"priority",
"]",
";",
"sprite_ptr",
"++",
";",
"}",
"else",
"{",
"drawgfxzoom_transpen",
"(",
"bitmap",
",",
"cliprect",
",",
"machine",
"->",
"gfx",
"[",
"0",
"]",
",",
"sprite_ptr",
"->",
"code",
",",
"sprite_ptr",
"->",
"color",
",",
"sprite_ptr",
"->",
"flipx",
",",
"sprite_ptr",
"->",
"flipy",
",",
"sprite_ptr",
"->",
"x",
",",
"sprite_ptr",
"->",
"y",
",",
"sprite_ptr",
"->",
"zoomx",
",",
"sprite_ptr",
"->",
"zoomy",
",",
"0",
")",
";",
"}",
"}",
"if",
"(",
"bad_chunks",
")",
"logerror",
"(",
"\"",
"\\n",
"\"",
",",
"tilenum",
",",
"bad_chunks",
")",
";",
"}",
"while",
"(",
"sprite_ptr",
"!=",
"spritelist",
")",
"{",
"sprite_ptr",
"--",
";",
"pdrawgfxzoom_transpen",
"(",
"bitmap",
",",
"cliprect",
",",
"machine",
"->",
"gfx",
"[",
"0",
"]",
",",
"sprite_ptr",
"->",
"code",
",",
"sprite_ptr",
"->",
"color",
",",
"sprite_ptr",
"->",
"flipx",
",",
"sprite_ptr",
"->",
"flipy",
",",
"sprite_ptr",
"->",
"x",
",",
"sprite_ptr",
"->",
"y",
",",
"sprite_ptr",
"->",
"zoomx",
",",
"sprite_ptr",
"->",
"zoomy",
",",
"machine",
"->",
"priority_bitmap",
",",
"sprite_ptr",
"->",
"primask",
",",
"0",
")",
";",
"}",
"}"
] | SPRITE DRAW ROUTINE
It draws a series of small tiles ("chunks") together to
create a big sprite. | [
"SPRITE",
"DRAW",
"ROUTINE",
"It",
"draws",
"a",
"series",
"of",
"small",
"tiles",
"(",
"\"",
"chunks",
"\"",
")",
"together",
"to",
"create",
"a",
"big",
"sprite",
"."
] | [
"/* pdrawgfx() needs us to draw sprites front to back, so we have to build a list\n while processing sprite ram and then draw them all at the end */",
"// $80000 spritemap rom maps up to $2000 64x64 sprites",
"/* treat coords as signed */",
"/* 4 chunks per row */",
"/* 8 rows */",
"/* pick tiles back to front for x and y flips */",
"/* -zx/y is there to fix zoomed sprite coords in screenflip.\n drawgfxzoom does not know to draw from flip-side of sprites when\n screen is flipped; so we must correct the coords ourselves. */",
"/* this happens only if primsks != NULL */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "bitmap",
"type": "bitmap_t"
},
{
"param": "cliprect",
"type": "rectangle"
},
{
"param": "primasks",
"type": "int"
},
{
"param": "y_offs",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "bitmap",
"type": "bitmap_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cliprect",
"type": "rectangle",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "primasks",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "y_offs",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | add_frame_callback | void | void add_frame_callback(running_machine *machine, void (*callback)(running_machine *))
{
mame_private *mame = machine->mame_data;
callback_item *cb, **cur;
assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_frame_callback at init time!");
/* allocate memory */
cb = alloc_or_die(callback_item);
/* add us to the end of the list */
cb->func.frame = callback;
cb->next = NULL;
for (cur = &mame->frame_callback_list; *cur; cur = &(*cur)->next) ;
*cur = cb;
} | /*-------------------------------------------------
add_frame_callback - request a callback on
frame update
-------------------------------------------------*/ | request a callback on
frame update | [
"request",
"a",
"callback",
"on",
"frame",
"update"
] | void add_frame_callback(running_machine *machine, void (*callback)(running_machine *))
{
mame_private *mame = machine->mame_data;
callback_item *cb, **cur;
assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_frame_callback at init time!");
cb = alloc_or_die(callback_item);
cb->func.frame = callback;
cb->next = NULL;
for (cur = &mame->frame_callback_list; *cur; cur = &(*cur)->next) ;
*cur = cb;
} | [
"void",
"add_frame_callback",
"(",
"running_machine",
"*",
"machine",
",",
"void",
"(",
"*",
"callback",
")",
"(",
"running_machine",
"*",
")",
")",
"{",
"mame_private",
"*",
"mame",
"=",
"machine",
"->",
"mame_data",
";",
"callback_item",
"*",
"cb",
",",
"*",
"*",
"cur",
";",
"assert_always",
"(",
"mame_get_phase",
"(",
"machine",
")",
"==",
"MAME_PHASE_INIT",
",",
"\"",
"\"",
")",
";",
"cb",
"=",
"alloc_or_die",
"(",
"callback_item",
")",
";",
"cb",
"->",
"func",
".",
"frame",
"=",
"callback",
";",
"cb",
"->",
"next",
"=",
"NULL",
";",
"for",
"(",
"cur",
"=",
"&",
"mame",
"->",
"frame_callback_list",
";",
"*",
"cur",
";",
"cur",
"=",
"&",
"(",
"*",
"cur",
")",
"->",
"next",
")",
";",
"*",
"cur",
"=",
"cb",
";",
"}"
] | add_frame_callback - request a callback on
frame update | [
"add_frame_callback",
"-",
"request",
"a",
"callback",
"on",
"frame",
"update"
] | [
"/* allocate memory */",
"/* add us to the end of the list */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "callback",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "callback",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | mame_schedule_hard_reset | void | void mame_schedule_hard_reset(running_machine *machine)
{
mame_private *mame = machine->mame_data;
mame->hard_reset_pending = TRUE;
/* if we're executing, abort out immediately */
eat_all_cpu_cycles(machine);
} | /*-------------------------------------------------
mame_schedule_hard_reset - schedule a hard-
reset of the system
-------------------------------------------------*/ | schedule a hard
reset of the system | [
"schedule",
"a",
"hard",
"reset",
"of",
"the",
"system"
] | void mame_schedule_hard_reset(running_machine *machine)
{
mame_private *mame = machine->mame_data;
mame->hard_reset_pending = TRUE;
eat_all_cpu_cycles(machine);
} | [
"void",
"mame_schedule_hard_reset",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"mame_private",
"*",
"mame",
"=",
"machine",
"->",
"mame_data",
";",
"mame",
"->",
"hard_reset_pending",
"=",
"TRUE",
";",
"eat_all_cpu_cycles",
"(",
"machine",
")",
";",
"}"
] | mame_schedule_hard_reset - schedule a hard
reset of the system | [
"mame_schedule_hard_reset",
"-",
"schedule",
"a",
"hard",
"reset",
"of",
"the",
"system"
] | [
"/* if we're executing, abort out immediately */"
] | [
{
"param": "machine",
"type": "running_machine"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | mame_schedule_soft_reset | void | void mame_schedule_soft_reset(running_machine *machine)
{
mame_private *mame = machine->mame_data;
timer_adjust_oneshot(mame->soft_reset_timer, attotime_zero, 0);
/* we can't be paused since the timer needs to fire */
mame_pause(machine, FALSE);
/* if we're executing, abort out immediately */
eat_all_cpu_cycles(machine);
} | /*-------------------------------------------------
mame_schedule_soft_reset - schedule a soft-
reset of the system
-------------------------------------------------*/ | schedule a soft
reset of the system | [
"schedule",
"a",
"soft",
"reset",
"of",
"the",
"system"
] | void mame_schedule_soft_reset(running_machine *machine)
{
mame_private *mame = machine->mame_data;
timer_adjust_oneshot(mame->soft_reset_timer, attotime_zero, 0);
mame_pause(machine, FALSE);
eat_all_cpu_cycles(machine);
} | [
"void",
"mame_schedule_soft_reset",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"mame_private",
"*",
"mame",
"=",
"machine",
"->",
"mame_data",
";",
"timer_adjust_oneshot",
"(",
"mame",
"->",
"soft_reset_timer",
",",
"attotime_zero",
",",
"0",
")",
";",
"mame_pause",
"(",
"machine",
",",
"FALSE",
")",
";",
"eat_all_cpu_cycles",
"(",
"machine",
")",
";",
"}"
] | mame_schedule_soft_reset - schedule a soft
reset of the system | [
"mame_schedule_soft_reset",
"-",
"schedule",
"a",
"soft",
"reset",
"of",
"the",
"system"
] | [
"/* we can't be paused since the timer needs to fire */",
"/* if we're executing, abort out immediately */"
] | [
{
"param": "machine",
"type": "running_machine"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | mame_schedule_new_driver | void | void mame_schedule_new_driver(running_machine *machine, const game_driver *driver)
{
mame_private *mame = machine->mame_data;
mame->hard_reset_pending = TRUE;
mame->new_driver_pending = driver;
/* if we're executing, abort out immediately */
eat_all_cpu_cycles(machine);
} | /*-------------------------------------------------
mame_schedule_new_driver - schedule a new game
to be loaded
-------------------------------------------------*/ | schedule a new game
to be loaded | [
"schedule",
"a",
"new",
"game",
"to",
"be",
"loaded"
] | void mame_schedule_new_driver(running_machine *machine, const game_driver *driver)
{
mame_private *mame = machine->mame_data;
mame->hard_reset_pending = TRUE;
mame->new_driver_pending = driver;
eat_all_cpu_cycles(machine);
} | [
"void",
"mame_schedule_new_driver",
"(",
"running_machine",
"*",
"machine",
",",
"const",
"game_driver",
"*",
"driver",
")",
"{",
"mame_private",
"*",
"mame",
"=",
"machine",
"->",
"mame_data",
";",
"mame",
"->",
"hard_reset_pending",
"=",
"TRUE",
";",
"mame",
"->",
"new_driver_pending",
"=",
"driver",
";",
"eat_all_cpu_cycles",
"(",
"machine",
")",
";",
"}"
] | mame_schedule_new_driver - schedule a new game
to be loaded | [
"mame_schedule_new_driver",
"-",
"schedule",
"a",
"new",
"game",
"to",
"be",
"loaded"
] | [
"/* if we're executing, abort out immediately */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "driver",
"type": "game_driver"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "driver",
"type": "game_driver",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | mame_schedule_save | void | void mame_schedule_save(running_machine *machine, const char *filename)
{
mame_private *mame = machine->mame_data;
/* specify the filename to save or load */
set_saveload_filename(machine, filename);
/* note the start time and set a timer for the next timeslice to actually schedule it */
mame->saveload_schedule_callback = handle_save;
mame->saveload_schedule_time = timer_get_time(machine);
/* we can't be paused since we need to clear out anonymous timers */
mame_pause(machine, FALSE);
} | /*-------------------------------------------------
mame_schedule_save - schedule a save to
occur as soon as possible
-------------------------------------------------*/ | schedule a save to
occur as soon as possible | [
"schedule",
"a",
"save",
"to",
"occur",
"as",
"soon",
"as",
"possible"
] | void mame_schedule_save(running_machine *machine, const char *filename)
{
mame_private *mame = machine->mame_data;
set_saveload_filename(machine, filename);
mame->saveload_schedule_callback = handle_save;
mame->saveload_schedule_time = timer_get_time(machine);
mame_pause(machine, FALSE);
} | [
"void",
"mame_schedule_save",
"(",
"running_machine",
"*",
"machine",
",",
"const",
"char",
"*",
"filename",
")",
"{",
"mame_private",
"*",
"mame",
"=",
"machine",
"->",
"mame_data",
";",
"set_saveload_filename",
"(",
"machine",
",",
"filename",
")",
";",
"mame",
"->",
"saveload_schedule_callback",
"=",
"handle_save",
";",
"mame",
"->",
"saveload_schedule_time",
"=",
"timer_get_time",
"(",
"machine",
")",
";",
"mame_pause",
"(",
"machine",
",",
"FALSE",
")",
";",
"}"
] | mame_schedule_save - schedule a save to
occur as soon as possible | [
"mame_schedule_save",
"-",
"schedule",
"a",
"save",
"to",
"occur",
"as",
"soon",
"as",
"possible"
] | [
"/* specify the filename to save or load */",
"/* note the start time and set a timer for the next timeslice to actually schedule it */",
"/* we can't be paused since we need to clear out anonymous timers */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "filename",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "filename",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | mame_schedule_load | void | void mame_schedule_load(running_machine *machine, const char *filename)
{
mame_private *mame = machine->mame_data;
/* specify the filename to save or load */
set_saveload_filename(machine, filename);
/* note the start time and set a timer for the next timeslice to actually schedule it */
mame->saveload_schedule_callback = handle_load;
mame->saveload_schedule_time = timer_get_time(machine);
/* we can't be paused since we need to clear out anonymous timers */
mame_pause(machine, FALSE);
} | /*-------------------------------------------------
mame_schedule_load - schedule a load to
occur as soon as possible
-------------------------------------------------*/ | schedule a load to
occur as soon as possible | [
"schedule",
"a",
"load",
"to",
"occur",
"as",
"soon",
"as",
"possible"
] | void mame_schedule_load(running_machine *machine, const char *filename)
{
mame_private *mame = machine->mame_data;
set_saveload_filename(machine, filename);
mame->saveload_schedule_callback = handle_load;
mame->saveload_schedule_time = timer_get_time(machine);
mame_pause(machine, FALSE);
} | [
"void",
"mame_schedule_load",
"(",
"running_machine",
"*",
"machine",
",",
"const",
"char",
"*",
"filename",
")",
"{",
"mame_private",
"*",
"mame",
"=",
"machine",
"->",
"mame_data",
";",
"set_saveload_filename",
"(",
"machine",
",",
"filename",
")",
";",
"mame",
"->",
"saveload_schedule_callback",
"=",
"handle_load",
";",
"mame",
"->",
"saveload_schedule_time",
"=",
"timer_get_time",
"(",
"machine",
")",
";",
"mame_pause",
"(",
"machine",
",",
"FALSE",
")",
";",
"}"
] | mame_schedule_load - schedule a load to
occur as soon as possible | [
"mame_schedule_load",
"-",
"schedule",
"a",
"load",
"to",
"occur",
"as",
"soon",
"as",
"possible"
] | [
"/* specify the filename to save or load */",
"/* note the start time and set a timer for the next timeslice to actually schedule it */",
"/* we can't be paused since we need to clear out anonymous timers */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "filename",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "filename",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | memory_region | UINT8 | UINT8 *memory_region(running_machine *machine, const char *name)
{
mame_private *mame = machine->mame_data;
region_info *info;
/* NULL tag always fails */
if (name == NULL)
return NULL;
/* make sure we don't have a region of the same name */
for (info = mame->regions; info != NULL; info = info->next)
if (astring_cmpc(info->name, name) == 0)
return info->base;
return NULL;
} | /*-------------------------------------------------
memory_region - returns pointer to a memory
region
-------------------------------------------------*/ | returns pointer to a memory
region | [
"returns",
"pointer",
"to",
"a",
"memory",
"region"
] | UINT8 *memory_region(running_machine *machine, const char *name)
{
mame_private *mame = machine->mame_data;
region_info *info;
if (name == NULL)
return NULL;
for (info = mame->regions; info != NULL; info = info->next)
if (astring_cmpc(info->name, name) == 0)
return info->base;
return NULL;
} | [
"UINT8",
"*",
"memory_region",
"(",
"running_machine",
"*",
"machine",
",",
"const",
"char",
"*",
"name",
")",
"{",
"mame_private",
"*",
"mame",
"=",
"machine",
"->",
"mame_data",
";",
"region_info",
"*",
"info",
";",
"if",
"(",
"name",
"==",
"NULL",
")",
"return",
"NULL",
";",
"for",
"(",
"info",
"=",
"mame",
"->",
"regions",
";",
"info",
"!=",
"NULL",
";",
"info",
"=",
"info",
"->",
"next",
")",
"if",
"(",
"astring_cmpc",
"(",
"info",
"->",
"name",
",",
"name",
")",
"==",
"0",
")",
"return",
"info",
"->",
"base",
";",
"return",
"NULL",
";",
"}"
] | memory_region - returns pointer to a memory
region | [
"memory_region",
"-",
"returns",
"pointer",
"to",
"a",
"memory",
"region"
] | [
"/* NULL tag always fails */",
"/* make sure we don't have a region of the same name */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "name",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "name",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | memory_region_length | UINT32 | UINT32 memory_region_length(running_machine *machine, const char *name)
{
mame_private *mame = machine->mame_data;
region_info *info;
/* NULL tag always fails */
if (name == NULL)
return 0;
/* make sure we don't have a region of the same name */
for (info = mame->regions; info != NULL; info = info->next)
if (astring_cmpc(info->name, name) == 0)
return info->length;
return 0;
} | /*-------------------------------------------------
memory_region_length - returns length of a
memory region
-------------------------------------------------*/ | returns length of a
memory region | [
"returns",
"length",
"of",
"a",
"memory",
"region"
] | UINT32 memory_region_length(running_machine *machine, const char *name)
{
mame_private *mame = machine->mame_data;
region_info *info;
if (name == NULL)
return 0;
for (info = mame->regions; info != NULL; info = info->next)
if (astring_cmpc(info->name, name) == 0)
return info->length;
return 0;
} | [
"UINT32",
"memory_region_length",
"(",
"running_machine",
"*",
"machine",
",",
"const",
"char",
"*",
"name",
")",
"{",
"mame_private",
"*",
"mame",
"=",
"machine",
"->",
"mame_data",
";",
"region_info",
"*",
"info",
";",
"if",
"(",
"name",
"==",
"NULL",
")",
"return",
"0",
";",
"for",
"(",
"info",
"=",
"mame",
"->",
"regions",
";",
"info",
"!=",
"NULL",
";",
"info",
"=",
"info",
"->",
"next",
")",
"if",
"(",
"astring_cmpc",
"(",
"info",
"->",
"name",
",",
"name",
")",
"==",
"0",
")",
"return",
"info",
"->",
"length",
";",
"return",
"0",
";",
"}"
] | memory_region_length - returns length of a
memory region | [
"memory_region_length",
"-",
"returns",
"length",
"of",
"a",
"memory",
"region"
] | [
"/* NULL tag always fails */",
"/* make sure we don't have a region of the same name */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "name",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "name",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | memory_region_flags | UINT32 | UINT32 memory_region_flags(running_machine *machine, const char *name)
{
mame_private *mame = machine->mame_data;
region_info *info;
/* NULL tag always fails */
if (name == NULL)
return 0;
/* make sure we don't have a region of the same name */
for (info = mame->regions; info != NULL; info = info->next)
if (astring_cmpc(info->name, name) == 0)
return info->flags;
return 0;
} | /*-------------------------------------------------
memory_region_flags - returns flags for a
memory region
-------------------------------------------------*/ | returns flags for a
memory region | [
"returns",
"flags",
"for",
"a",
"memory",
"region"
] | UINT32 memory_region_flags(running_machine *machine, const char *name)
{
mame_private *mame = machine->mame_data;
region_info *info;
if (name == NULL)
return 0;
for (info = mame->regions; info != NULL; info = info->next)
if (astring_cmpc(info->name, name) == 0)
return info->flags;
return 0;
} | [
"UINT32",
"memory_region_flags",
"(",
"running_machine",
"*",
"machine",
",",
"const",
"char",
"*",
"name",
")",
"{",
"mame_private",
"*",
"mame",
"=",
"machine",
"->",
"mame_data",
";",
"region_info",
"*",
"info",
";",
"if",
"(",
"name",
"==",
"NULL",
")",
"return",
"0",
";",
"for",
"(",
"info",
"=",
"mame",
"->",
"regions",
";",
"info",
"!=",
"NULL",
";",
"info",
"=",
"info",
"->",
"next",
")",
"if",
"(",
"astring_cmpc",
"(",
"info",
"->",
"name",
",",
"name",
")",
"==",
"0",
")",
"return",
"info",
"->",
"flags",
";",
"return",
"0",
";",
"}"
] | memory_region_flags - returns flags for a
memory region | [
"memory_region_flags",
"-",
"returns",
"flags",
"for",
"a",
"memory",
"region"
] | [
"/* NULL tag always fails */",
"/* make sure we don't have a region of the same name */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "name",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "name",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | memory_region_next | char | const char *memory_region_next(running_machine *machine, const char *name)
{
mame_private *mame = machine->mame_data;
region_info *info;
/* if there's nothing in this class, fail immediately */
info = mame->regions;
if (info == NULL)
return NULL;
/* NULL means return the first */
if (name == NULL)
return astring_c(info->name);
/* make sure we don't have a region of the same name */
for ( ; info != NULL; info = info->next)
if (astring_cmpc(info->name, name) == 0)
return (info->next != NULL) ? astring_c(info->next->name) : NULL;
return NULL;
} | /*-------------------------------------------------
memory_region_next - the name of the next
memory region (or the first if name == NULL)
-------------------------------------------------*/ | the name of the next
memory region (or the first if name == NULL) | [
"the",
"name",
"of",
"the",
"next",
"memory",
"region",
"(",
"or",
"the",
"first",
"if",
"name",
"==",
"NULL",
")"
] | const char *memory_region_next(running_machine *machine, const char *name)
{
mame_private *mame = machine->mame_data;
region_info *info;
info = mame->regions;
if (info == NULL)
return NULL;
if (name == NULL)
return astring_c(info->name);
for ( ; info != NULL; info = info->next)
if (astring_cmpc(info->name, name) == 0)
return (info->next != NULL) ? astring_c(info->next->name) : NULL;
return NULL;
} | [
"const",
"char",
"*",
"memory_region_next",
"(",
"running_machine",
"*",
"machine",
",",
"const",
"char",
"*",
"name",
")",
"{",
"mame_private",
"*",
"mame",
"=",
"machine",
"->",
"mame_data",
";",
"region_info",
"*",
"info",
";",
"info",
"=",
"mame",
"->",
"regions",
";",
"if",
"(",
"info",
"==",
"NULL",
")",
"return",
"NULL",
";",
"if",
"(",
"name",
"==",
"NULL",
")",
"return",
"astring_c",
"(",
"info",
"->",
"name",
")",
";",
"for",
"(",
";",
"info",
"!=",
"NULL",
";",
"info",
"=",
"info",
"->",
"next",
")",
"if",
"(",
"astring_cmpc",
"(",
"info",
"->",
"name",
",",
"name",
")",
"==",
"0",
")",
"return",
"(",
"info",
"->",
"next",
"!=",
"NULL",
")",
"?",
"astring_c",
"(",
"info",
"->",
"next",
"->",
"name",
")",
":",
"NULL",
";",
"return",
"NULL",
";",
"}"
] | memory_region_next - the name of the next
memory region (or the first if name == NULL) | [
"memory_region_next",
"-",
"the",
"name",
"of",
"the",
"next",
"memory",
"region",
"(",
"or",
"the",
"first",
"if",
"name",
"==",
"NULL",
")"
] | [
"/* if there's nothing in this class, fail immediately */",
"/* NULL means return the first */",
"/* make sure we don't have a region of the same name */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "name",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "name",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | mame_printf_info | void | void mame_printf_info(const char *format, ...)
{
va_list argptr;
#ifdef ANDROID
char buffer[1024];
va_start(argptr, format);
vsprintf (buffer,format,argptr );
va_end(argptr);
__android_log_print(ANDROID_LOG_INFO, "MAME","%s",buffer);
#else
/* by default, we go to stdout */
if (output_cb[OUTPUT_CHANNEL_INFO] == NULL)
{
output_cb[OUTPUT_CHANNEL_INFO] = mame_file_output_callback;
output_cb_param[OUTPUT_CHANNEL_INFO] = stdout;
}
/* do the output */
va_start(argptr, format);
(*output_cb[OUTPUT_CHANNEL_INFO])(output_cb_param[OUTPUT_CHANNEL_INFO], format, argptr);
va_end(argptr);
#endif
} | /*-------------------------------------------------
mame_printf_info - output info text to the
appropriate callback
-------------------------------------------------*/ | output info text to the
appropriate callback | [
"output",
"info",
"text",
"to",
"the",
"appropriate",
"callback"
] | void mame_printf_info(const char *format, ...)
{
va_list argptr;
#ifdef ANDROID
char buffer[1024];
va_start(argptr, format);
vsprintf (buffer,format,argptr );
va_end(argptr);
__android_log_print(ANDROID_LOG_INFO, "MAME","%s",buffer);
#else
if (output_cb[OUTPUT_CHANNEL_INFO] == NULL)
{
output_cb[OUTPUT_CHANNEL_INFO] = mame_file_output_callback;
output_cb_param[OUTPUT_CHANNEL_INFO] = stdout;
}
va_start(argptr, format);
(*output_cb[OUTPUT_CHANNEL_INFO])(output_cb_param[OUTPUT_CHANNEL_INFO], format, argptr);
va_end(argptr);
#endif
} | [
"void",
"mame_printf_info",
"(",
"const",
"char",
"*",
"format",
",",
"...",
")",
"{",
"va_list",
"argptr",
";",
"#ifdef",
"ANDROID",
"char",
"buffer",
"[",
"1024",
"]",
";",
"va_start",
"(",
"argptr",
",",
"format",
")",
";",
"vsprintf",
"(",
"buffer",
",",
"format",
",",
"argptr",
")",
";",
"va_end",
"(",
"argptr",
")",
";",
"__android_log_print",
"(",
"ANDROID_LOG_INFO",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"buffer",
")",
";",
"#else",
"if",
"(",
"output_cb",
"[",
"OUTPUT_CHANNEL_INFO",
"]",
"==",
"NULL",
")",
"{",
"output_cb",
"[",
"OUTPUT_CHANNEL_INFO",
"]",
"=",
"mame_file_output_callback",
";",
"output_cb_param",
"[",
"OUTPUT_CHANNEL_INFO",
"]",
"=",
"stdout",
";",
"}",
"va_start",
"(",
"argptr",
",",
"format",
")",
";",
"(",
"*",
"output_cb",
"[",
"OUTPUT_CHANNEL_INFO",
"]",
")",
"(",
"output_cb_param",
"[",
"OUTPUT_CHANNEL_INFO",
"]",
",",
"format",
",",
"argptr",
")",
";",
"va_end",
"(",
"argptr",
")",
";",
"#endif",
"}"
] | mame_printf_info - output info text to the
appropriate callback | [
"mame_printf_info",
"-",
"output",
"info",
"text",
"to",
"the",
"appropriate",
"callback"
] | [
"/* by default, we go to stdout */",
"/* do the output */"
] | [
{
"param": "format",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "format",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | mame_printf_verbose | void | void mame_printf_verbose(const char *format, ...)
{
va_list argptr;
#ifdef ANDROID
char buffer[1024];
va_start(argptr, format);
vsprintf (buffer,format,argptr );
va_end(argptr);
__android_log_print(ANDROID_LOG_INFO, "MAME","%s",buffer);
#else
char buffer[1024];
va_start(argptr, format);
vsprintf (buffer,format,argptr );
va_end(argptr);
printf("--> %s",buffer);
#endif
/* if we're not verbose, skip it */
if (mame_opts == NULL || !options_get_bool(mame_options(), OPTION_VERBOSE))
return;
/* by default, we go to stdout */
if (output_cb[OUTPUT_CHANNEL_VERBOSE] == NULL)
{
output_cb[OUTPUT_CHANNEL_VERBOSE] = mame_file_output_callback;
output_cb_param[OUTPUT_CHANNEL_VERBOSE] = stdout;
}
/* do the output */
va_start(argptr, format);
(*output_cb[OUTPUT_CHANNEL_VERBOSE])(output_cb_param[OUTPUT_CHANNEL_VERBOSE], format, argptr);
va_end(argptr);
} | /*-------------------------------------------------
mame_printf_verbose - output verbose text to
the appropriate callback
-------------------------------------------------*/ | output verbose text to
the appropriate callback | [
"output",
"verbose",
"text",
"to",
"the",
"appropriate",
"callback"
] | void mame_printf_verbose(const char *format, ...)
{
va_list argptr;
#ifdef ANDROID
char buffer[1024];
va_start(argptr, format);
vsprintf (buffer,format,argptr );
va_end(argptr);
__android_log_print(ANDROID_LOG_INFO, "MAME","%s",buffer);
#else
char buffer[1024];
va_start(argptr, format);
vsprintf (buffer,format,argptr );
va_end(argptr);
printf("--> %s",buffer);
#endif
if (mame_opts == NULL || !options_get_bool(mame_options(), OPTION_VERBOSE))
return;
if (output_cb[OUTPUT_CHANNEL_VERBOSE] == NULL)
{
output_cb[OUTPUT_CHANNEL_VERBOSE] = mame_file_output_callback;
output_cb_param[OUTPUT_CHANNEL_VERBOSE] = stdout;
}
va_start(argptr, format);
(*output_cb[OUTPUT_CHANNEL_VERBOSE])(output_cb_param[OUTPUT_CHANNEL_VERBOSE], format, argptr);
va_end(argptr);
} | [
"void",
"mame_printf_verbose",
"(",
"const",
"char",
"*",
"format",
",",
"...",
")",
"{",
"va_list",
"argptr",
";",
"#ifdef",
"ANDROID",
"char",
"buffer",
"[",
"1024",
"]",
";",
"va_start",
"(",
"argptr",
",",
"format",
")",
";",
"vsprintf",
"(",
"buffer",
",",
"format",
",",
"argptr",
")",
";",
"va_end",
"(",
"argptr",
")",
";",
"__android_log_print",
"(",
"ANDROID_LOG_INFO",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"buffer",
")",
";",
"#else",
"char",
"buffer",
"[",
"1024",
"]",
";",
"va_start",
"(",
"argptr",
",",
"format",
")",
";",
"vsprintf",
"(",
"buffer",
",",
"format",
",",
"argptr",
")",
";",
"va_end",
"(",
"argptr",
")",
";",
"printf",
"(",
"\"",
"\"",
",",
"buffer",
")",
";",
"#endif",
"if",
"(",
"mame_opts",
"==",
"NULL",
"||",
"!",
"options_get_bool",
"(",
"mame_options",
"(",
")",
",",
"OPTION_VERBOSE",
")",
")",
"return",
";",
"if",
"(",
"output_cb",
"[",
"OUTPUT_CHANNEL_VERBOSE",
"]",
"==",
"NULL",
")",
"{",
"output_cb",
"[",
"OUTPUT_CHANNEL_VERBOSE",
"]",
"=",
"mame_file_output_callback",
";",
"output_cb_param",
"[",
"OUTPUT_CHANNEL_VERBOSE",
"]",
"=",
"stdout",
";",
"}",
"va_start",
"(",
"argptr",
",",
"format",
")",
";",
"(",
"*",
"output_cb",
"[",
"OUTPUT_CHANNEL_VERBOSE",
"]",
")",
"(",
"output_cb_param",
"[",
"OUTPUT_CHANNEL_VERBOSE",
"]",
",",
"format",
",",
"argptr",
")",
";",
"va_end",
"(",
"argptr",
")",
";",
"}"
] | mame_printf_verbose - output verbose text to
the appropriate callback | [
"mame_printf_verbose",
"-",
"output",
"verbose",
"text",
"to",
"the",
"appropriate",
"callback"
] | [
"/* if we're not verbose, skip it */",
"/* by default, we go to stdout */",
"/* do the output */"
] | [
{
"param": "format",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "format",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | add_logerror_callback | void | void add_logerror_callback(running_machine *machine, void (*callback)(running_machine *, const char *))
{
mame_private *mame = machine->mame_data;
callback_item *cb, **cur;
assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_logerror_callback at init time!");
cb = auto_alloc(machine, callback_item);
cb->func.log = callback;
cb->next = NULL;
for (cur = &mame->logerror_callback_list; *cur; cur = &(*cur)->next) ;
*cur = cb;
} | /*-------------------------------------------------
add_logerror_callback - adds a callback to be
called on logerror()
-------------------------------------------------*/ | adds a callback to be
called on logerror() | [
"adds",
"a",
"callback",
"to",
"be",
"called",
"on",
"logerror",
"()"
] | void add_logerror_callback(running_machine *machine, void (*callback)(running_machine *, const char *))
{
mame_private *mame = machine->mame_data;
callback_item *cb, **cur;
assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_logerror_callback at init time!");
cb = auto_alloc(machine, callback_item);
cb->func.log = callback;
cb->next = NULL;
for (cur = &mame->logerror_callback_list; *cur; cur = &(*cur)->next) ;
*cur = cb;
} | [
"void",
"add_logerror_callback",
"(",
"running_machine",
"*",
"machine",
",",
"void",
"(",
"*",
"callback",
")",
"(",
"running_machine",
"*",
",",
"const",
"char",
"*",
")",
")",
"{",
"mame_private",
"*",
"mame",
"=",
"machine",
"->",
"mame_data",
";",
"callback_item",
"*",
"cb",
",",
"*",
"*",
"cur",
";",
"assert_always",
"(",
"mame_get_phase",
"(",
"machine",
")",
"==",
"MAME_PHASE_INIT",
",",
"\"",
"\"",
")",
";",
"cb",
"=",
"auto_alloc",
"(",
"machine",
",",
"callback_item",
")",
";",
"cb",
"->",
"func",
".",
"log",
"=",
"callback",
";",
"cb",
"->",
"next",
"=",
"NULL",
";",
"for",
"(",
"cur",
"=",
"&",
"mame",
"->",
"logerror_callback_list",
";",
"*",
"cur",
";",
"cur",
"=",
"&",
"(",
"*",
"cur",
")",
"->",
"next",
")",
";",
"*",
"cur",
"=",
"cb",
";",
"}"
] | add_logerror_callback - adds a callback to be
called on logerror() | [
"add_logerror_callback",
"-",
"adds",
"a",
"callback",
"to",
"be",
"called",
"on",
"logerror",
"()"
] | [] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "callback",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "callback",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | create_machine | running_machine | static running_machine *create_machine(const game_driver *driver)
{
running_machine *machine;
/* allocate memory for the machine */
machine = (running_machine *)malloc(sizeof(*machine));
if (machine == NULL)
goto error;
memset(machine, 0, sizeof(*machine));
/* allocate memory for the internal mame_data */
machine->mame_data = (mame_private *)malloc(sizeof(*machine->mame_data));
if (machine->mame_data == NULL)
goto error;
memset(machine->mame_data, 0, sizeof(*machine->mame_data));
/* initialize the driver-related variables in the machine */
machine->gamedrv = driver;
machine->basename = mame_strdup(driver->name);
machine->config = machine_config_alloc(driver->machine_config);
/* allocate the driver data */
if (machine->config->driver_data_size != 0)
{
machine->driver_data = malloc(machine->config->driver_data_size);
if (machine->driver_data == NULL)
goto error;
memset(machine->driver_data, 0, machine->config->driver_data_size);
}
/* find devices */
machine->firstcpu = cpu_first(machine->config);
machine->primary_screen = video_screen_first(machine->config);
/* attach this machine to all the devices in the configuration */
device_list_attach_machine(machine);
/* fetch core options */
machine->sample_rate = options_get_int(mame_options(), OPTION_SAMPLERATE);
machine->debug_flags = options_get_bool(mame_options(), OPTION_DEBUG) ? (DEBUG_FLAG_ENABLED | DEBUG_FLAG_CALL_HOOK) : 0;
return machine;
error:
if (machine->driver_data != NULL)
free(machine->driver_data);
if (machine->config != NULL)
machine_config_free((machine_config *)machine->config);
if (machine->mame_data != NULL)
free(machine->mame_data);
if (machine != NULL)
free(machine);
return NULL;
} | /*-------------------------------------------------
create_machine - create the running machine
object and initialize it based on options
-------------------------------------------------*/ | create the running machine
object and initialize it based on options | [
"create",
"the",
"running",
"machine",
"object",
"and",
"initialize",
"it",
"based",
"on",
"options"
] | static running_machine *create_machine(const game_driver *driver)
{
running_machine *machine;
machine = (running_machine *)malloc(sizeof(*machine));
if (machine == NULL)
goto error;
memset(machine, 0, sizeof(*machine));
machine->mame_data = (mame_private *)malloc(sizeof(*machine->mame_data));
if (machine->mame_data == NULL)
goto error;
memset(machine->mame_data, 0, sizeof(*machine->mame_data));
machine->gamedrv = driver;
machine->basename = mame_strdup(driver->name);
machine->config = machine_config_alloc(driver->machine_config);
if (machine->config->driver_data_size != 0)
{
machine->driver_data = malloc(machine->config->driver_data_size);
if (machine->driver_data == NULL)
goto error;
memset(machine->driver_data, 0, machine->config->driver_data_size);
}
machine->firstcpu = cpu_first(machine->config);
machine->primary_screen = video_screen_first(machine->config);
device_list_attach_machine(machine);
machine->sample_rate = options_get_int(mame_options(), OPTION_SAMPLERATE);
machine->debug_flags = options_get_bool(mame_options(), OPTION_DEBUG) ? (DEBUG_FLAG_ENABLED | DEBUG_FLAG_CALL_HOOK) : 0;
return machine;
error:
if (machine->driver_data != NULL)
free(machine->driver_data);
if (machine->config != NULL)
machine_config_free((machine_config *)machine->config);
if (machine->mame_data != NULL)
free(machine->mame_data);
if (machine != NULL)
free(machine);
return NULL;
} | [
"static",
"running_machine",
"*",
"create_machine",
"(",
"const",
"game_driver",
"*",
"driver",
")",
"{",
"running_machine",
"*",
"machine",
";",
"machine",
"=",
"(",
"running_machine",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"*",
"machine",
")",
")",
";",
"if",
"(",
"machine",
"==",
"NULL",
")",
"goto",
"error",
";",
"memset",
"(",
"machine",
",",
"0",
",",
"sizeof",
"(",
"*",
"machine",
")",
")",
";",
"machine",
"->",
"mame_data",
"=",
"(",
"mame_private",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"*",
"machine",
"->",
"mame_data",
")",
")",
";",
"if",
"(",
"machine",
"->",
"mame_data",
"==",
"NULL",
")",
"goto",
"error",
";",
"memset",
"(",
"machine",
"->",
"mame_data",
",",
"0",
",",
"sizeof",
"(",
"*",
"machine",
"->",
"mame_data",
")",
")",
";",
"machine",
"->",
"gamedrv",
"=",
"driver",
";",
"machine",
"->",
"basename",
"=",
"mame_strdup",
"(",
"driver",
"->",
"name",
")",
";",
"machine",
"->",
"config",
"=",
"machine_config_alloc",
"(",
"driver",
"->",
"machine_config",
")",
";",
"if",
"(",
"machine",
"->",
"config",
"->",
"driver_data_size",
"!=",
"0",
")",
"{",
"machine",
"->",
"driver_data",
"=",
"malloc",
"(",
"machine",
"->",
"config",
"->",
"driver_data_size",
")",
";",
"if",
"(",
"machine",
"->",
"driver_data",
"==",
"NULL",
")",
"goto",
"error",
";",
"memset",
"(",
"machine",
"->",
"driver_data",
",",
"0",
",",
"machine",
"->",
"config",
"->",
"driver_data_size",
")",
";",
"}",
"machine",
"->",
"firstcpu",
"=",
"cpu_first",
"(",
"machine",
"->",
"config",
")",
";",
"machine",
"->",
"primary_screen",
"=",
"video_screen_first",
"(",
"machine",
"->",
"config",
")",
";",
"device_list_attach_machine",
"(",
"machine",
")",
";",
"machine",
"->",
"sample_rate",
"=",
"options_get_int",
"(",
"mame_options",
"(",
")",
",",
"OPTION_SAMPLERATE",
")",
";",
"machine",
"->",
"debug_flags",
"=",
"options_get_bool",
"(",
"mame_options",
"(",
")",
",",
"OPTION_DEBUG",
")",
"?",
"(",
"DEBUG_FLAG_ENABLED",
"|",
"DEBUG_FLAG_CALL_HOOK",
")",
":",
"0",
";",
"return",
"machine",
";",
"error",
":",
"if",
"(",
"machine",
"->",
"driver_data",
"!=",
"NULL",
")",
"free",
"(",
"machine",
"->",
"driver_data",
")",
";",
"if",
"(",
"machine",
"->",
"config",
"!=",
"NULL",
")",
"machine_config_free",
"(",
"(",
"machine_config",
"*",
")",
"machine",
"->",
"config",
")",
";",
"if",
"(",
"machine",
"->",
"mame_data",
"!=",
"NULL",
")",
"free",
"(",
"machine",
"->",
"mame_data",
")",
";",
"if",
"(",
"machine",
"!=",
"NULL",
")",
"free",
"(",
"machine",
")",
";",
"return",
"NULL",
";",
"}"
] | create_machine - create the running machine
object and initialize it based on options | [
"create_machine",
"-",
"create",
"the",
"running",
"machine",
"object",
"and",
"initialize",
"it",
"based",
"on",
"options"
] | [
"/* allocate memory for the machine */",
"/* allocate memory for the internal mame_data */",
"/* initialize the driver-related variables in the machine */",
"/* allocate the driver data */",
"/* find devices */",
"/* attach this machine to all the devices in the configuration */",
"/* fetch core options */"
] | [
{
"param": "driver",
"type": "game_driver"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "driver",
"type": "game_driver",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f930c8d1c21ee32655042175720e02120c55d3c3 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/mame.c | [
"Unlicense"
] | C | mame_get_current_datetime | void | void mame_get_current_datetime(running_machine *machine, mame_system_time *systime)
{
mame_private *mame = machine->mame_data;
fill_systime(systime, mame->base_time + timer_get_time(machine).seconds);
} | /*-------------------------------------------------
mame_get_current_datetime - retrieve the current
time (offsetted by the baes); useful for RTC
implementations
-------------------------------------------------*/ | retrieve the current
time (offsetted by the baes); useful for RTC
implementations | [
"retrieve",
"the",
"current",
"time",
"(",
"offsetted",
"by",
"the",
"baes",
")",
";",
"useful",
"for",
"RTC",
"implementations"
] | void mame_get_current_datetime(running_machine *machine, mame_system_time *systime)
{
mame_private *mame = machine->mame_data;
fill_systime(systime, mame->base_time + timer_get_time(machine).seconds);
} | [
"void",
"mame_get_current_datetime",
"(",
"running_machine",
"*",
"machine",
",",
"mame_system_time",
"*",
"systime",
")",
"{",
"mame_private",
"*",
"mame",
"=",
"machine",
"->",
"mame_data",
";",
"fill_systime",
"(",
"systime",
",",
"mame",
"->",
"base_time",
"+",
"timer_get_time",
"(",
"machine",
")",
".",
"seconds",
")",
";",
"}"
] | mame_get_current_datetime - retrieve the current
time (offsetted by the baes); useful for RTC
implementations | [
"mame_get_current_datetime",
"-",
"retrieve",
"the",
"current",
"time",
"(",
"offsetted",
"by",
"the",
"baes",
")",
";",
"useful",
"for",
"RTC",
"implementations"
] | [] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "systime",
"type": "mame_system_time"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "systime",
"type": "mame_system_time",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
be0b55b463a626740175b166378b8ac928405beb | lofunz/mieme | Reloaded/trunk/src/mame/audio/snes_snd.c | [
"Unlicense"
] | C | advance_envelope | int | static int advance_envelope( running_device *device, int v )
{
snes_sound_state *spc700 = get_safe_token(device);
int envx;
int cnt;
int adsr1;
int t;
envx = spc700->voice_state[v].envx;
if (spc700->voice_state[v].envstate == RELEASE)
{
/* Docs: "When in the state of "key off". the "click" sound is prevented
by the addition of the fixed value 1/256" WTF??? Alright, I'm going
to choose to interpret that this way: When a note is keyed off, start
the RELEASE state, which subtracts 1/256th each sample period (32kHz).
Note there's no need for a count because it always happens every
update. */
envx -= 0x8; /* 0x8 / 0x800 = 1/256th */
if (envx <= 0)
{
envx = 0;
spc700->keys &= ~(1 << v);
return -1;
}
spc700->voice_state[v].envx = envx;
spc700->dsp_regs[(v << 4) + 8] = envx >> 8;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=RELEASE\n", v, envx);
#endif
return envx;
}
cnt = spc700->voice_state[v].envcnt;
adsr1 = spc700->dsp_regs[(v << 4) + 5];
if (adsr1 & 0x80)
{
switch (spc700->voice_state[v].envstate)
{
case ATTACK:
/* Docs are very confusing. "AR is multiplied by the fixed value
1/64..." I believe it means to add 1/64th to ENVX once every
time ATTACK is updated, and that's what I'm going to implement. */
t = adsr1 & 0x0f;
if (t == 0x0f)
{
#ifdef DBG_ENV
logerror("ENV voice %d: instant attack\n", v);
#endif
envx += 0x400;
}
else
{
cnt -= ENVCNT[(t << 1) + 1];
if (cnt > 0)
break;
envx += 0x20; /* 0x020 / 0x800 = 1/64 */
cnt = CNT_INIT;
}
if (envx > 0x7ff)
{
envx = 0x7ff;
spc700->voice_state[v].envstate = DECAY;
}
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=ATTACK\n", v, envx);
#endif
spc700->voice_state[v].envx = envx;
break;
case DECAY:
/* Docs: "DR... [is multiplied] by the fixed value 1-1/256."
Well, at least that makes some sense. Multiplying ENVX by
255/256 every time DECAY is updated. */
cnt -= ENVCNT[((adsr1 >> 3) & 0x0e) + 0x10];
if (cnt <= 0)
{
cnt = CNT_INIT;
envx -= ((envx - 1) >> 8) + 1;
spc700->voice_state[v].envx = envx;
}
if (envx <= 0x100 * (SL(v) + 1))
spc700->voice_state[v].envstate = SUSTAIN;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=DECAY\n", v, envx);
#endif
break;
case SUSTAIN:
/* Docs: "SR [is multiplied] by the fixed value 1-1/256."
Multiplying ENVX by 255/256 every time SUSTAIN is updated. */
#ifdef DBG_ENV
if (ENVCNT[SR(v)] == 0)
logerror("ENV voice %d: envx=%03X, state=SUSTAIN, zero rate\n", v, envx);
#endif
cnt -= ENVCNT[SR(v)];
if (cnt > 0)
break;
cnt = CNT_INIT;
envx -= ((envx - 1) >> 8) + 1;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=SUSTAIN\n", v, envx);
#endif
spc700->voice_state[v].envx = envx;
/* Note: no way out of this state except by explicit KEY OFF (or switch to GAIN). */
break;
case RELEASE: /* Handled earlier to prevent GAIN mode from stopping KEY OFF events */
break;
}
}
else
{
/* GAIN mode is set
Note: if the game switches between ADSR and GAIN modes partway
through, should the count be reset, or should it continue from
where it was? Does the DSP actually watch for that bit to
change, or does it just go along with whatever it sees when it
performs the update? I'm going to assume the latter and not
update the count, unless I see a game that obviously wants the
other behavior. The effect would be pretty subtle, in any case.
*/
t = spc700->dsp_regs[(v << 4) + 7];
if (t < 0x80)
{
envx = t << 4;
spc700->voice_state[v].envx = envx;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=DIRECT\n", v, envx);
#endif
}
else
{
switch (t >> 5)
{
case 4:
/* Docs: "Decrease (linear): Subtraction of the fixed value 1/64." */
cnt -= ENVCNT[t & 0x1f];
if (cnt > 0)
break;
cnt = CNT_INIT;
envx -= 0x020; /* 0x020 / 0x800 = 1/64th */
if (envx < 0)
envx = 0;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=DECREASE\n", v, envx);
#endif
spc700->voice_state[v].envx = envx;
break;
case 5:
/* Docs: "Drecrease <sic> (exponential): Multiplication by the fixed value 1-1/256." */
cnt -= ENVCNT[t & 0x1f];
if (cnt > 0)
break;
cnt = CNT_INIT;
envx -= ((envx - 1) >> 8) + 1;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=EXP\n", v, envx);
#endif
spc700->voice_state[v].envx = envx;
break;
case 6:
/* Docs: "Increase (linear): Addition of the fixed value 1/64." */
cnt -= ENVCNT[t & 0x1f];
if (cnt > 0)
break;
cnt = CNT_INIT;
envx += 0x020; /* 0x020 / 0x800 = 1/64th */
if (envx > 0x7ff)
envx = 0x7ff;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=INCREASE\n", v, envx);
#endif
spc700->voice_state[v].envx = envx;
break;
case 7:
/* Docs: "Increase (bent line): Addition of the constant
1/64 up to .75 of the constaint <sic> 1/256 from .75 to 1." */
cnt -= ENVCNT[t & 0x1f];
if (cnt > 0)
break;
cnt = CNT_INIT;
if (envx < 0x600) /* 0x600 / 0x800 = .75 */
envx += 0x020; /* 0x020 / 0x800 = 1/64 */
else
envx += 0x008; /* 0x008 / 0x800 = 1/256 */
if (envx > 0x7ff)
envx=0x7ff;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=INCREASE\n", v, envx);
#endif
spc700->voice_state[v].envx = envx;
break;
}
}
}
spc700->voice_state[v].envcnt = cnt;
spc700->dsp_regs[(v << 4) + 8] = envx >> 4;
return envx;
} | /*-------------------------------------------------
advance_envelope
Run envelope step & return ENVX. v is the voice
to process envelope for.
-------------------------------------------------*/ | advance_envelope
Run envelope step & return ENVX. v is the voice
to process envelope for. | [
"advance_envelope",
"Run",
"envelope",
"step",
"&",
"return",
"ENVX",
".",
"v",
"is",
"the",
"voice",
"to",
"process",
"envelope",
"for",
"."
] | static int advance_envelope( running_device *device, int v )
{
snes_sound_state *spc700 = get_safe_token(device);
int envx;
int cnt;
int adsr1;
int t;
envx = spc700->voice_state[v].envx;
if (spc700->voice_state[v].envstate == RELEASE)
{
envx -= 0x8;
if (envx <= 0)
{
envx = 0;
spc700->keys &= ~(1 << v);
return -1;
}
spc700->voice_state[v].envx = envx;
spc700->dsp_regs[(v << 4) + 8] = envx >> 8;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=RELEASE\n", v, envx);
#endif
return envx;
}
cnt = spc700->voice_state[v].envcnt;
adsr1 = spc700->dsp_regs[(v << 4) + 5];
if (adsr1 & 0x80)
{
switch (spc700->voice_state[v].envstate)
{
case ATTACK:
t = adsr1 & 0x0f;
if (t == 0x0f)
{
#ifdef DBG_ENV
logerror("ENV voice %d: instant attack\n", v);
#endif
envx += 0x400;
}
else
{
cnt -= ENVCNT[(t << 1) + 1];
if (cnt > 0)
break;
envx += 0x20;
cnt = CNT_INIT;
}
if (envx > 0x7ff)
{
envx = 0x7ff;
spc700->voice_state[v].envstate = DECAY;
}
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=ATTACK\n", v, envx);
#endif
spc700->voice_state[v].envx = envx;
break;
case DECAY:
cnt -= ENVCNT[((adsr1 >> 3) & 0x0e) + 0x10];
if (cnt <= 0)
{
cnt = CNT_INIT;
envx -= ((envx - 1) >> 8) + 1;
spc700->voice_state[v].envx = envx;
}
if (envx <= 0x100 * (SL(v) + 1))
spc700->voice_state[v].envstate = SUSTAIN;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=DECAY\n", v, envx);
#endif
break;
case SUSTAIN:
#ifdef DBG_ENV
if (ENVCNT[SR(v)] == 0)
logerror("ENV voice %d: envx=%03X, state=SUSTAIN, zero rate\n", v, envx);
#endif
cnt -= ENVCNT[SR(v)];
if (cnt > 0)
break;
cnt = CNT_INIT;
envx -= ((envx - 1) >> 8) + 1;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=SUSTAIN\n", v, envx);
#endif
spc700->voice_state[v].envx = envx;
break;
case RELEASE:
break;
}
}
else
{
t = spc700->dsp_regs[(v << 4) + 7];
if (t < 0x80)
{
envx = t << 4;
spc700->voice_state[v].envx = envx;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=DIRECT\n", v, envx);
#endif
}
else
{
switch (t >> 5)
{
case 4:
cnt -= ENVCNT[t & 0x1f];
if (cnt > 0)
break;
cnt = CNT_INIT;
envx -= 0x020;
if (envx < 0)
envx = 0;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=DECREASE\n", v, envx);
#endif
spc700->voice_state[v].envx = envx;
break;
case 5:
cnt -= ENVCNT[t & 0x1f];
if (cnt > 0)
break;
cnt = CNT_INIT;
envx -= ((envx - 1) >> 8) + 1;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=EXP\n", v, envx);
#endif
spc700->voice_state[v].envx = envx;
break;
case 6:
cnt -= ENVCNT[t & 0x1f];
if (cnt > 0)
break;
cnt = CNT_INIT;
envx += 0x020;
if (envx > 0x7ff)
envx = 0x7ff;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=INCREASE\n", v, envx);
#endif
spc700->voice_state[v].envx = envx;
break;
case 7:
cnt -= ENVCNT[t & 0x1f];
if (cnt > 0)
break;
cnt = CNT_INIT;
if (envx < 0x600)
envx += 0x020;
else
envx += 0x008;
if (envx > 0x7ff)
envx=0x7ff;
#ifdef DBG_ENV
logerror("ENV voice %d: envx=%03X, state=INCREASE\n", v, envx);
#endif
spc700->voice_state[v].envx = envx;
break;
}
}
}
spc700->voice_state[v].envcnt = cnt;
spc700->dsp_regs[(v << 4) + 8] = envx >> 4;
return envx;
} | [
"static",
"int",
"advance_envelope",
"(",
"running_device",
"*",
"device",
",",
"int",
"v",
")",
"{",
"snes_sound_state",
"*",
"spc700",
"=",
"get_safe_token",
"(",
"device",
")",
";",
"int",
"envx",
";",
"int",
"cnt",
";",
"int",
"adsr1",
";",
"int",
"t",
";",
"envx",
"=",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envx",
";",
"if",
"(",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envstate",
"==",
"RELEASE",
")",
"{",
"envx",
"-=",
"0x8",
";",
"if",
"(",
"envx",
"<=",
"0",
")",
"{",
"envx",
"=",
"0",
";",
"spc700",
"->",
"keys",
"&=",
"~",
"(",
"1",
"<<",
"v",
")",
";",
"return",
"-1",
";",
"}",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envx",
"=",
"envx",
";",
"spc700",
"->",
"dsp_regs",
"[",
"(",
"v",
"<<",
"4",
")",
"+",
"8",
"]",
"=",
"envx",
">>",
"8",
";",
"#ifdef",
"DBG_ENV",
"logerror",
"(",
"\"",
"\\n",
"\"",
",",
"v",
",",
"envx",
")",
";",
"#endif",
"return",
"envx",
";",
"}",
"cnt",
"=",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envcnt",
";",
"adsr1",
"=",
"spc700",
"->",
"dsp_regs",
"[",
"(",
"v",
"<<",
"4",
")",
"+",
"5",
"]",
";",
"if",
"(",
"adsr1",
"&",
"0x80",
")",
"{",
"switch",
"(",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envstate",
")",
"{",
"case",
"ATTACK",
":",
"t",
"=",
"adsr1",
"&",
"0x0f",
";",
"if",
"(",
"t",
"==",
"0x0f",
")",
"{",
"#ifdef",
"DBG_ENV",
"logerror",
"(",
"\"",
"\\n",
"\"",
",",
"v",
")",
";",
"#endif",
"envx",
"+=",
"0x400",
";",
"}",
"else",
"{",
"cnt",
"-=",
"ENVCNT",
"[",
"(",
"t",
"<<",
"1",
")",
"+",
"1",
"]",
";",
"if",
"(",
"cnt",
">",
"0",
")",
"break",
";",
"envx",
"+=",
"0x20",
";",
"cnt",
"=",
"CNT_INIT",
";",
"}",
"if",
"(",
"envx",
">",
"0x7ff",
")",
"{",
"envx",
"=",
"0x7ff",
";",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envstate",
"=",
"DECAY",
";",
"}",
"#ifdef",
"DBG_ENV",
"logerror",
"(",
"\"",
"\\n",
"\"",
",",
"v",
",",
"envx",
")",
";",
"#endif",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envx",
"=",
"envx",
";",
"break",
";",
"case",
"DECAY",
":",
"cnt",
"-=",
"ENVCNT",
"[",
"(",
"(",
"adsr1",
">>",
"3",
")",
"&",
"0x0e",
")",
"+",
"0x10",
"]",
";",
"if",
"(",
"cnt",
"<=",
"0",
")",
"{",
"cnt",
"=",
"CNT_INIT",
";",
"envx",
"-=",
"(",
"(",
"envx",
"-",
"1",
")",
">>",
"8",
")",
"+",
"1",
";",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envx",
"=",
"envx",
";",
"}",
"if",
"(",
"envx",
"<=",
"0x100",
"*",
"(",
"SL",
"(",
"v",
")",
"+",
"1",
")",
")",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envstate",
"=",
"SUSTAIN",
";",
"#ifdef",
"DBG_ENV",
"logerror",
"(",
"\"",
"\\n",
"\"",
",",
"v",
",",
"envx",
")",
";",
"#endif",
"break",
";",
"case",
"SUSTAIN",
":",
"#ifdef",
"DBG_ENV",
"if",
"(",
"ENVCNT",
"[",
"SR",
"(",
"v",
")",
"]",
"==",
"0",
")",
"logerror",
"(",
"\"",
"\\n",
"\"",
",",
"v",
",",
"envx",
")",
";",
"#endif",
"cnt",
"-=",
"ENVCNT",
"[",
"SR",
"(",
"v",
")",
"]",
";",
"if",
"(",
"cnt",
">",
"0",
")",
"break",
";",
"cnt",
"=",
"CNT_INIT",
";",
"envx",
"-=",
"(",
"(",
"envx",
"-",
"1",
")",
">>",
"8",
")",
"+",
"1",
";",
"#ifdef",
"DBG_ENV",
"logerror",
"(",
"\"",
"\\n",
"\"",
",",
"v",
",",
"envx",
")",
";",
"#endif",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envx",
"=",
"envx",
";",
"break",
";",
"case",
"RELEASE",
":",
"break",
";",
"}",
"}",
"else",
"{",
"t",
"=",
"spc700",
"->",
"dsp_regs",
"[",
"(",
"v",
"<<",
"4",
")",
"+",
"7",
"]",
";",
"if",
"(",
"t",
"<",
"0x80",
")",
"{",
"envx",
"=",
"t",
"<<",
"4",
";",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envx",
"=",
"envx",
";",
"#ifdef",
"DBG_ENV",
"logerror",
"(",
"\"",
"\\n",
"\"",
",",
"v",
",",
"envx",
")",
";",
"#endif",
"}",
"else",
"{",
"switch",
"(",
"t",
">>",
"5",
")",
"{",
"case",
"4",
":",
"cnt",
"-=",
"ENVCNT",
"[",
"t",
"&",
"0x1f",
"]",
";",
"if",
"(",
"cnt",
">",
"0",
")",
"break",
";",
"cnt",
"=",
"CNT_INIT",
";",
"envx",
"-=",
"0x020",
";",
"if",
"(",
"envx",
"<",
"0",
")",
"envx",
"=",
"0",
";",
"#ifdef",
"DBG_ENV",
"logerror",
"(",
"\"",
"\\n",
"\"",
",",
"v",
",",
"envx",
")",
";",
"#endif",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envx",
"=",
"envx",
";",
"break",
";",
"case",
"5",
":",
"cnt",
"-=",
"ENVCNT",
"[",
"t",
"&",
"0x1f",
"]",
";",
"if",
"(",
"cnt",
">",
"0",
")",
"break",
";",
"cnt",
"=",
"CNT_INIT",
";",
"envx",
"-=",
"(",
"(",
"envx",
"-",
"1",
")",
">>",
"8",
")",
"+",
"1",
";",
"#ifdef",
"DBG_ENV",
"logerror",
"(",
"\"",
"\\n",
"\"",
",",
"v",
",",
"envx",
")",
";",
"#endif",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envx",
"=",
"envx",
";",
"break",
";",
"case",
"6",
":",
"cnt",
"-=",
"ENVCNT",
"[",
"t",
"&",
"0x1f",
"]",
";",
"if",
"(",
"cnt",
">",
"0",
")",
"break",
";",
"cnt",
"=",
"CNT_INIT",
";",
"envx",
"+=",
"0x020",
";",
"if",
"(",
"envx",
">",
"0x7ff",
")",
"envx",
"=",
"0x7ff",
";",
"#ifdef",
"DBG_ENV",
"logerror",
"(",
"\"",
"\\n",
"\"",
",",
"v",
",",
"envx",
")",
";",
"#endif",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envx",
"=",
"envx",
";",
"break",
";",
"case",
"7",
":",
"cnt",
"-=",
"ENVCNT",
"[",
"t",
"&",
"0x1f",
"]",
";",
"if",
"(",
"cnt",
">",
"0",
")",
"break",
";",
"cnt",
"=",
"CNT_INIT",
";",
"if",
"(",
"envx",
"<",
"0x600",
")",
"envx",
"+=",
"0x020",
";",
"else",
"envx",
"+=",
"0x008",
";",
"if",
"(",
"envx",
">",
"0x7ff",
")",
"envx",
"=",
"0x7ff",
";",
"#ifdef",
"DBG_ENV",
"logerror",
"(",
"\"",
"\\n",
"\"",
",",
"v",
",",
"envx",
")",
";",
"#endif",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envx",
"=",
"envx",
";",
"break",
";",
"}",
"}",
"}",
"spc700",
"->",
"voice_state",
"[",
"v",
"]",
".",
"envcnt",
"=",
"cnt",
";",
"spc700",
"->",
"dsp_regs",
"[",
"(",
"v",
"<<",
"4",
")",
"+",
"8",
"]",
"=",
"envx",
">>",
"4",
";",
"return",
"envx",
";",
"}"
] | advance_envelope
Run envelope step & return ENVX. | [
"advance_envelope",
"Run",
"envelope",
"step",
"&",
"return",
"ENVX",
"."
] | [
"/* Docs: \"When in the state of \"key off\". the \"click\" sound is prevented\r\n by the addition of the fixed value 1/256\" WTF??? Alright, I'm going\r\n to choose to interpret that this way: When a note is keyed off, start\r\n the RELEASE state, which subtracts 1/256th each sample period (32kHz).\r\n Note there's no need for a count because it always happens every\r\n update. */",
"/* 0x8 / 0x800 = 1/256th */",
"/* Docs are very confusing. \"AR is multiplied by the fixed value\r\n 1/64...\" I believe it means to add 1/64th to ENVX once every\r\n time ATTACK is updated, and that's what I'm going to implement. */",
"/* 0x020 / 0x800 = 1/64 */",
"/* Docs: \"DR... [is multiplied] by the fixed value 1-1/256.\"\r\n Well, at least that makes some sense. Multiplying ENVX by\r\n 255/256 every time DECAY is updated. */",
"/* Docs: \"SR [is multiplied] by the fixed value 1-1/256.\"\r\n Multiplying ENVX by 255/256 every time SUSTAIN is updated. */",
"/* Note: no way out of this state except by explicit KEY OFF (or switch to GAIN). */",
"/* Handled earlier to prevent GAIN mode from stopping KEY OFF events */",
"/* GAIN mode is set\r\n Note: if the game switches between ADSR and GAIN modes partway\r\n through, should the count be reset, or should it continue from\r\n where it was? Does the DSP actually watch for that bit to\r\n change, or does it just go along with whatever it sees when it\r\n performs the update? I'm going to assume the latter and not\r\n update the count, unless I see a game that obviously wants the\r\n other behavior. The effect would be pretty subtle, in any case.\r\n */",
"/* Docs: \"Decrease (linear): Subtraction of the fixed value 1/64.\" */",
"/* 0x020 / 0x800 = 1/64th */",
"/* Docs: \"Drecrease <sic> (exponential): Multiplication by the fixed value 1-1/256.\" */",
"/* Docs: \"Increase (linear): Addition of the fixed value 1/64.\" */",
"/* 0x020 / 0x800 = 1/64th */",
"/* Docs: \"Increase (bent line): Addition of the constant\r\n 1/64 up to .75 of the constaint <sic> 1/256 from .75 to 1.\" */",
"/* 0x600 / 0x800 = .75 */",
"/* 0x020 / 0x800 = 1/64 */",
"/* 0x008 / 0x800 = 1/256 */"
] | [
{
"param": "device",
"type": "running_device"
},
{
"param": "v",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "device",
"type": "running_device",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "v",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
be2b5eee8bfec15668474426234249bffa85be43 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/drivers/missb2.c | [
"Unlicense"
] | C | irqhandler | void | static void irqhandler(const device_config *device, int irq)
{
logerror("YM3526 firing an IRQ\n");
// cputag_set_input_line(device->machine, "audiocpu", 0, irq ? ASSERT_LINE : CLEAR_LINE);
} | // Handler called by the 3526 emulator when the internal timers cause an IRQ | Handler called by the 3526 emulator when the internal timers cause an IRQ | [
"Handler",
"called",
"by",
"the",
"3526",
"emulator",
"when",
"the",
"internal",
"timers",
"cause",
"an",
"IRQ"
] | static void irqhandler(const device_config *device, int irq)
{
logerror("YM3526 firing an IRQ\n");
} | [
"static",
"void",
"irqhandler",
"(",
"const",
"device_config",
"*",
"device",
",",
"int",
"irq",
")",
"{",
"logerror",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}"
] | Handler called by the 3526 emulator when the internal timers cause an IRQ | [
"Handler",
"called",
"by",
"the",
"3526",
"emulator",
"when",
"the",
"internal",
"timers",
"cause",
"an",
"IRQ"
] | [
"// cputag_set_input_line(device->machine, \"audiocpu\", 0, irq ? ASSERT_LINE : CLEAR_LINE);"
] | [
{
"param": "device",
"type": "device_config"
},
{
"param": "irq",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "device",
"type": "device_config",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "irq",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d0ae7e665f848a26c6d7b1ec07d407a14800ddda | weiszd/SegAlign | common/cuda_utils.h | [
"MIT"
] | C | check_cuda_setDevice | void | static inline void check_cuda_setDevice(int device_id, const char* tag) {
cudaError_t err = cudaSetDevice(device_id);
if (err != cudaSuccess) {
fprintf(stderr, "Error: cudaSetDevice failed for device %d in %s failed with error \" %s \" \n", device_id, tag, cudaGetErrorString(err));
exit(11);
}
} | // wrap of cudaSetDevice error checking in one place. | wrap of cudaSetDevice error checking in one place. | [
"wrap",
"of",
"cudaSetDevice",
"error",
"checking",
"in",
"one",
"place",
"."
] | static inline void check_cuda_setDevice(int device_id, const char* tag) {
cudaError_t err = cudaSetDevice(device_id);
if (err != cudaSuccess) {
fprintf(stderr, "Error: cudaSetDevice failed for device %d in %s failed with error \" %s \" \n", device_id, tag, cudaGetErrorString(err));
exit(11);
}
} | [
"static",
"inline",
"void",
"check_cuda_setDevice",
"(",
"int",
"device_id",
",",
"const",
"char",
"*",
"tag",
")",
"{",
"cudaError_t",
"err",
"=",
"cudaSetDevice",
"(",
"device_id",
")",
";",
"if",
"(",
"err",
"!=",
"cudaSuccess",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"device_id",
",",
"tag",
",",
"cudaGetErrorString",
"(",
"err",
")",
")",
";",
"exit",
"(",
"11",
")",
";",
"}",
"}"
] | wrap of cudaSetDevice error checking in one place. | [
"wrap",
"of",
"cudaSetDevice",
"error",
"checking",
"in",
"one",
"place",
"."
] | [] | [
{
"param": "device_id",
"type": "int"
},
{
"param": "tag",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "device_id",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tag",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d0ae7e665f848a26c6d7b1ec07d407a14800ddda | weiszd/SegAlign | common/cuda_utils.h | [
"MIT"
] | C | check_cuda_malloc | void | static inline void check_cuda_malloc(void** buf, size_t bytes, const char* tag) {
cudaError_t err = cudaMalloc(buf, bytes);
if (err != cudaSuccess) {
fprintf(stderr, "Error: cudaMalloc of %lu bytes for %s failed with error \" %s \" \n", bytes, tag, cudaGetErrorString(err));
exit(12);
}
} | // wrap of cudaMalloc error checking in one place. | wrap of cudaMalloc error checking in one place. | [
"wrap",
"of",
"cudaMalloc",
"error",
"checking",
"in",
"one",
"place",
"."
] | static inline void check_cuda_malloc(void** buf, size_t bytes, const char* tag) {
cudaError_t err = cudaMalloc(buf, bytes);
if (err != cudaSuccess) {
fprintf(stderr, "Error: cudaMalloc of %lu bytes for %s failed with error \" %s \" \n", bytes, tag, cudaGetErrorString(err));
exit(12);
}
} | [
"static",
"inline",
"void",
"check_cuda_malloc",
"(",
"void",
"*",
"*",
"buf",
",",
"size_t",
"bytes",
",",
"const",
"char",
"*",
"tag",
")",
"{",
"cudaError_t",
"err",
"=",
"cudaMalloc",
"(",
"buf",
",",
"bytes",
")",
";",
"if",
"(",
"err",
"!=",
"cudaSuccess",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"bytes",
",",
"tag",
",",
"cudaGetErrorString",
"(",
"err",
")",
")",
";",
"exit",
"(",
"12",
")",
";",
"}",
"}"
] | wrap of cudaMalloc error checking in one place. | [
"wrap",
"of",
"cudaMalloc",
"error",
"checking",
"in",
"one",
"place",
"."
] | [] | [
{
"param": "buf",
"type": "void"
},
{
"param": "bytes",
"type": "size_t"
},
{
"param": "tag",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "buf",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "bytes",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tag",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d0ae7e665f848a26c6d7b1ec07d407a14800ddda | weiszd/SegAlign | common/cuda_utils.h | [
"MIT"
] | C | check_cuda_memcpy | void | static inline void check_cuda_memcpy(void* dst_buf, void* src_buf, size_t bytes, cudaMemcpyKind kind, const char* tag) {
cudaError_t err = cudaMemcpy(dst_buf, src_buf, bytes, kind);
if (err != cudaSuccess) {
fprintf(stderr, "Error: cudaMemcpy of %lu bytes for %s failed with error \" %s \" \n", bytes, tag, cudaGetErrorString(err));
exit(13);
}
} | // wrap of cudaMemcpy error checking in one place. | wrap of cudaMemcpy error checking in one place. | [
"wrap",
"of",
"cudaMemcpy",
"error",
"checking",
"in",
"one",
"place",
"."
] | static inline void check_cuda_memcpy(void* dst_buf, void* src_buf, size_t bytes, cudaMemcpyKind kind, const char* tag) {
cudaError_t err = cudaMemcpy(dst_buf, src_buf, bytes, kind);
if (err != cudaSuccess) {
fprintf(stderr, "Error: cudaMemcpy of %lu bytes for %s failed with error \" %s \" \n", bytes, tag, cudaGetErrorString(err));
exit(13);
}
} | [
"static",
"inline",
"void",
"check_cuda_memcpy",
"(",
"void",
"*",
"dst_buf",
",",
"void",
"*",
"src_buf",
",",
"size_t",
"bytes",
",",
"cudaMemcpyKind",
"kind",
",",
"const",
"char",
"*",
"tag",
")",
"{",
"cudaError_t",
"err",
"=",
"cudaMemcpy",
"(",
"dst_buf",
",",
"src_buf",
",",
"bytes",
",",
"kind",
")",
";",
"if",
"(",
"err",
"!=",
"cudaSuccess",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"bytes",
",",
"tag",
",",
"cudaGetErrorString",
"(",
"err",
")",
")",
";",
"exit",
"(",
"13",
")",
";",
"}",
"}"
] | wrap of cudaMemcpy error checking in one place. | [
"wrap",
"of",
"cudaMemcpy",
"error",
"checking",
"in",
"one",
"place",
"."
] | [] | [
{
"param": "dst_buf",
"type": "void"
},
{
"param": "src_buf",
"type": "void"
},
{
"param": "bytes",
"type": "size_t"
},
{
"param": "kind",
"type": "cudaMemcpyKind"
},
{
"param": "tag",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "dst_buf",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "src_buf",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "bytes",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "kind",
"type": "cudaMemcpyKind",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tag",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d0ae7e665f848a26c6d7b1ec07d407a14800ddda | weiszd/SegAlign | common/cuda_utils.h | [
"MIT"
] | C | check_cuda_free | void | static inline void check_cuda_free(void* buf, const char* tag) {
cudaError_t err = cudaFree(buf);
if (err != cudaSuccess) {
fprintf(stderr, "Error: cudaFree for %s failed with error \" %s \" \n", tag, cudaGetErrorString(err));
exit(14);
}
} | // wrap of cudaFree error checking in one place. | wrap of cudaFree error checking in one place. | [
"wrap",
"of",
"cudaFree",
"error",
"checking",
"in",
"one",
"place",
"."
] | static inline void check_cuda_free(void* buf, const char* tag) {
cudaError_t err = cudaFree(buf);
if (err != cudaSuccess) {
fprintf(stderr, "Error: cudaFree for %s failed with error \" %s \" \n", tag, cudaGetErrorString(err));
exit(14);
}
} | [
"static",
"inline",
"void",
"check_cuda_free",
"(",
"void",
"*",
"buf",
",",
"const",
"char",
"*",
"tag",
")",
"{",
"cudaError_t",
"err",
"=",
"cudaFree",
"(",
"buf",
")",
";",
"if",
"(",
"err",
"!=",
"cudaSuccess",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"tag",
",",
"cudaGetErrorString",
"(",
"err",
")",
")",
";",
"exit",
"(",
"14",
")",
";",
"}",
"}"
] | wrap of cudaFree error checking in one place. | [
"wrap",
"of",
"cudaFree",
"error",
"checking",
"in",
"one",
"place",
"."
] | [] | [
{
"param": "buf",
"type": "void"
},
{
"param": "tag",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "buf",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tag",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f4ccdc91f6d92223dd32b50481da8d116bf13110 | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/tests/perf_realloc.c | [
"Apache-2.0"
] | C | realloc_by_amount | void | static void
realloc_by_amount(const char *base_metric_name, size_t size, ssize_t amount,
bool amount_is_random)
{
if (amount_is_random) {
snprintf(name, MAX_NAME_SIZE, amount >= 0 ?
"%s_from_%llu_up_random" : "%s_from_%llu_down_random",
base_metric_name, (uint64_t)size);
} else {
snprintf(name, MAX_NAME_SIZE, amount >= 0 ?
"%s_from_%llu_up_%ld" : "%s_from_%llu_down_%ld",
base_metric_name, (uint64_t)size, labs(amount));
}
uint64_t total_time = 0;
int count = 0;
dt_stat_time_t s = dt_stat_time_create(name);
dt_stat_set_variable((dt_stat_t)s, "size (bytes)", (unsigned int)size);
dt_stat_set_variable((dt_stat_t)s, "amount (bytes)", (int)amount);
// rdar://problem/40417821: disable thresholds for now.
//dt_stat_set_variable((dt_stat_t)s, kPCFailureThresholdPctVar,
// PERFCHECK_THRESHOLD_PCT);
dt_stat_token now = dt_stat_time_begin(s);
for (;;) {
void *ptr = malloc(size);
T_QUIET; T_ASSERT_NOTNULL(ptr, "malloc for size %llu failed", (uint64_t)size);
dt_stat_token start = dt_stat_time_begin(s);
ptr = realloc(ptr, size + amount);
dt_stat_token end = dt_stat_time_begin(s);
T_QUIET; T_ASSERT_NOTNULL(ptr,
"realloc from size %llu to size %llu failed", (uint64_t)size,
(uint64_t)(size + amount));
total_time += end - start;
free(ptr);
if (++count >= NUMBER_OF_SAMPLES_FOR_BATCH(s)) {
// Discard outliers or the test won't converge -- this should
// be done in libdarwintest
if (total_time/count < OUTLIER_TIME) {
dt_stat_mach_time_add_batch(s, count, total_time);
}
total_time = 0;
count = 0;
if (dt_stat_stable(s)) {
break;
}
}
}
dt_stat_finalize(s);
} | // Measures the time required to realloc a block of memory of given size
// by a specified amount. | Measures the time required to realloc a block of memory of given size
by a specified amount. | [
"Measures",
"the",
"time",
"required",
"to",
"realloc",
"a",
"block",
"of",
"memory",
"of",
"given",
"size",
"by",
"a",
"specified",
"amount",
"."
] | static void
realloc_by_amount(const char *base_metric_name, size_t size, ssize_t amount,
bool amount_is_random)
{
if (amount_is_random) {
snprintf(name, MAX_NAME_SIZE, amount >= 0 ?
"%s_from_%llu_up_random" : "%s_from_%llu_down_random",
base_metric_name, (uint64_t)size);
} else {
snprintf(name, MAX_NAME_SIZE, amount >= 0 ?
"%s_from_%llu_up_%ld" : "%s_from_%llu_down_%ld",
base_metric_name, (uint64_t)size, labs(amount));
}
uint64_t total_time = 0;
int count = 0;
dt_stat_time_t s = dt_stat_time_create(name);
dt_stat_set_variable((dt_stat_t)s, "size (bytes)", (unsigned int)size);
dt_stat_set_variable((dt_stat_t)s, "amount (bytes)", (int)amount);
dt_stat_token now = dt_stat_time_begin(s);
for (;;) {
void *ptr = malloc(size);
T_QUIET; T_ASSERT_NOTNULL(ptr, "malloc for size %llu failed", (uint64_t)size);
dt_stat_token start = dt_stat_time_begin(s);
ptr = realloc(ptr, size + amount);
dt_stat_token end = dt_stat_time_begin(s);
T_QUIET; T_ASSERT_NOTNULL(ptr,
"realloc from size %llu to size %llu failed", (uint64_t)size,
(uint64_t)(size + amount));
total_time += end - start;
free(ptr);
if (++count >= NUMBER_OF_SAMPLES_FOR_BATCH(s)) {
if (total_time/count < OUTLIER_TIME) {
dt_stat_mach_time_add_batch(s, count, total_time);
}
total_time = 0;
count = 0;
if (dt_stat_stable(s)) {
break;
}
}
}
dt_stat_finalize(s);
} | [
"static",
"void",
"realloc_by_amount",
"(",
"const",
"char",
"*",
"base_metric_name",
",",
"size_t",
"size",
",",
"ssize_t",
"amount",
",",
"bool",
"amount_is_random",
")",
"{",
"if",
"(",
"amount_is_random",
")",
"{",
"snprintf",
"(",
"name",
",",
"MAX_NAME_SIZE",
",",
"amount",
">=",
"0",
"?",
"\"",
"\"",
":",
"\"",
"\"",
",",
"base_metric_name",
",",
"(",
"uint64_t",
")",
"size",
")",
";",
"}",
"else",
"{",
"snprintf",
"(",
"name",
",",
"MAX_NAME_SIZE",
",",
"amount",
">=",
"0",
"?",
"\"",
"\"",
":",
"\"",
"\"",
",",
"base_metric_name",
",",
"(",
"uint64_t",
")",
"size",
",",
"labs",
"(",
"amount",
")",
")",
";",
"}",
"uint64_t",
"total_time",
"=",
"0",
";",
"int",
"count",
"=",
"0",
";",
"dt_stat_time_t",
"s",
"=",
"dt_stat_time_create",
"(",
"name",
")",
";",
"dt_stat_set_variable",
"(",
"(",
"dt_stat_t",
")",
"s",
",",
"\"",
"\"",
",",
"(",
"unsigned",
"int",
")",
"size",
")",
";",
"dt_stat_set_variable",
"(",
"(",
"dt_stat_t",
")",
"s",
",",
"\"",
"\"",
",",
"(",
"int",
")",
"amount",
")",
";",
"dt_stat_token",
"now",
"=",
"dt_stat_time_begin",
"(",
"s",
")",
";",
"for",
"(",
";",
";",
")",
"{",
"void",
"*",
"ptr",
"=",
"malloc",
"(",
"size",
")",
";",
"T_QUIET",
";",
"T_ASSERT_NOTNULL",
"(",
"ptr",
",",
"\"",
"\"",
",",
"(",
"uint64_t",
")",
"size",
")",
";",
"dt_stat_token",
"start",
"=",
"dt_stat_time_begin",
"(",
"s",
")",
";",
"ptr",
"=",
"realloc",
"(",
"ptr",
",",
"size",
"+",
"amount",
")",
";",
"dt_stat_token",
"end",
"=",
"dt_stat_time_begin",
"(",
"s",
")",
";",
"T_QUIET",
";",
"T_ASSERT_NOTNULL",
"(",
"ptr",
",",
"\"",
"\"",
",",
"(",
"uint64_t",
")",
"size",
",",
"(",
"uint64_t",
")",
"(",
"size",
"+",
"amount",
")",
")",
";",
"total_time",
"+=",
"end",
"-",
"start",
";",
"free",
"(",
"ptr",
")",
";",
"if",
"(",
"++",
"count",
">=",
"NUMBER_OF_SAMPLES_FOR_BATCH",
"(",
"s",
")",
")",
"{",
"if",
"(",
"total_time",
"/",
"count",
"<",
"OUTLIER_TIME",
")",
"{",
"dt_stat_mach_time_add_batch",
"(",
"s",
",",
"count",
",",
"total_time",
")",
";",
"}",
"total_time",
"=",
"0",
";",
"count",
"=",
"0",
";",
"if",
"(",
"dt_stat_stable",
"(",
"s",
")",
")",
"{",
"break",
";",
"}",
"}",
"}",
"dt_stat_finalize",
"(",
"s",
")",
";",
"}"
] | Measures the time required to realloc a block of memory of given size
by a specified amount. | [
"Measures",
"the",
"time",
"required",
"to",
"realloc",
"a",
"block",
"of",
"memory",
"of",
"given",
"size",
"by",
"a",
"specified",
"amount",
"."
] | [
"// rdar://problem/40417821: disable thresholds for now.",
"//dt_stat_set_variable((dt_stat_t)s, kPCFailureThresholdPctVar,",
"//\t\tPERFCHECK_THRESHOLD_PCT);",
"// Discard outliers or the test won't converge -- this should",
"// be done in libdarwintest"
] | [
{
"param": "base_metric_name",
"type": "char"
},
{
"param": "size",
"type": "size_t"
},
{
"param": "amount",
"type": "ssize_t"
},
{
"param": "amount_is_random",
"type": "bool"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "base_metric_name",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "size",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "amount",
"type": "ssize_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "amount_is_random",
"type": "bool",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
c1a58b090a5ad196563645c3fe7f6644d085ec1d | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/src/radix_tree_internal.h | [
"Apache-2.0"
] | C | keybits | null | static inline
unsigned
keybits(uint64_t key, int labelBits, int keyshift)
{
uint64_t mask = (1 << labelBits) - 1;
return (unsigned) (key >> (64 - labelBits - keyshift)) & mask;
} | /*
* Read the most significant labelBits out of (key << keyshift)
*/ | Read the most significant labelBits out of (key << keyshift) | [
"Read",
"the",
"most",
"significant",
"labelBits",
"out",
"of",
"(",
"key",
"<<",
"keyshift",
")"
] | static inline
unsigned
keybits(uint64_t key, int labelBits, int keyshift)
{
uint64_t mask = (1 << labelBits) - 1;
return (unsigned) (key >> (64 - labelBits - keyshift)) & mask;
} | [
"static",
"inline",
"unsigned",
"keybits",
"(",
"uint64_t",
"key",
",",
"int",
"labelBits",
",",
"int",
"keyshift",
")",
"{",
"uint64_t",
"mask",
"=",
"(",
"1",
"<<",
"labelBits",
")",
"-",
"1",
";",
"return",
"(",
"unsigned",
")",
"(",
"key",
">>",
"(",
"64",
"-",
"labelBits",
"-",
"keyshift",
")",
")",
"&",
"mask",
";",
"}"
] | Read the most significant labelBits out of (key << keyshift) | [
"Read",
"the",
"most",
"significant",
"labelBits",
"out",
"of",
"(",
"key",
"<<",
"keyshift",
")"
] | [] | [
{
"param": "key",
"type": "uint64_t"
},
{
"param": "labelBits",
"type": "int"
},
{
"param": "keyshift",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "key",
"type": "uint64_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "labelBits",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "keyshift",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
c1a58b090a5ad196563645c3fe7f6644d085ec1d | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/src/radix_tree_internal.h | [
"Apache-2.0"
] | C | edge_matches | bool | static inline
bool
edge_matches(struct radix_edge *edge, uint64_t key, int keyshift)
{
if (!edge_valid(edge)) {
return false;
}
return keybits(key, edge->labelBits, keyshift) == edge->label;
} | /*
* Return true if exact radix tree traversal should follow this edge.
* That is, return true if the edge label matches the key bits exactly.
*/ | Return true if exact radix tree traversal should follow this edge.
That is, return true if the edge label matches the key bits exactly. | [
"Return",
"true",
"if",
"exact",
"radix",
"tree",
"traversal",
"should",
"follow",
"this",
"edge",
".",
"That",
"is",
"return",
"true",
"if",
"the",
"edge",
"label",
"matches",
"the",
"key",
"bits",
"exactly",
"."
] | static inline
bool
edge_matches(struct radix_edge *edge, uint64_t key, int keyshift)
{
if (!edge_valid(edge)) {
return false;
}
return keybits(key, edge->labelBits, keyshift) == edge->label;
} | [
"static",
"inline",
"bool",
"edge_matches",
"(",
"struct",
"radix_edge",
"*",
"edge",
",",
"uint64_t",
"key",
",",
"int",
"keyshift",
")",
"{",
"if",
"(",
"!",
"edge_valid",
"(",
"edge",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"keybits",
"(",
"key",
",",
"edge",
"->",
"labelBits",
",",
"keyshift",
")",
"==",
"edge",
"->",
"label",
";",
"}"
] | Return true if exact radix tree traversal should follow this edge. | [
"Return",
"true",
"if",
"exact",
"radix",
"tree",
"traversal",
"should",
"follow",
"this",
"edge",
"."
] | [] | [
{
"param": "edge",
"type": "struct radix_edge"
},
{
"param": "key",
"type": "uint64_t"
},
{
"param": "keyshift",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "edge",
"type": "struct radix_edge",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "key",
"type": "uint64_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "keyshift",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
c1a58b090a5ad196563645c3fe7f6644d085ec1d | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/src/radix_tree_internal.h | [
"Apache-2.0"
] | C | count_matching_bits | int | static inline
int
count_matching_bits(struct radix_edge *edge, uint64_t key, int keyshift)
{
int labelBits = edge->labelBits;
uint64_t label = edge->label;
while (labelBits) {
if (keybits(key, labelBits, keyshift) == label) {
return labelBits;
}
labelBits--;
label >>= 1;
}
return 0;
} | /*
* Count the number of most-significant bits that (key << keyshift) has in
* common with edge.
*/ | Count the number of most-significant bits that (key << keyshift) has in
common with edge. | [
"Count",
"the",
"number",
"of",
"most",
"-",
"significant",
"bits",
"that",
"(",
"key",
"<<",
"keyshift",
")",
"has",
"in",
"common",
"with",
"edge",
"."
] | static inline
int
count_matching_bits(struct radix_edge *edge, uint64_t key, int keyshift)
{
int labelBits = edge->labelBits;
uint64_t label = edge->label;
while (labelBits) {
if (keybits(key, labelBits, keyshift) == label) {
return labelBits;
}
labelBits--;
label >>= 1;
}
return 0;
} | [
"static",
"inline",
"int",
"count_matching_bits",
"(",
"struct",
"radix_edge",
"*",
"edge",
",",
"uint64_t",
"key",
",",
"int",
"keyshift",
")",
"{",
"int",
"labelBits",
"=",
"edge",
"->",
"labelBits",
";",
"uint64_t",
"label",
"=",
"edge",
"->",
"label",
";",
"while",
"(",
"labelBits",
")",
"{",
"if",
"(",
"keybits",
"(",
"key",
",",
"labelBits",
",",
"keyshift",
")",
"==",
"label",
")",
"{",
"return",
"labelBits",
";",
"}",
"labelBits",
"--",
";",
"label",
">>=",
"1",
";",
"}",
"return",
"0",
";",
"}"
] | Count the number of most-significant bits that (key << keyshift) has in
common with edge. | [
"Count",
"the",
"number",
"of",
"most",
"-",
"significant",
"bits",
"that",
"(",
"key",
"<<",
"keyshift",
")",
"has",
"in",
"common",
"with",
"edge",
"."
] | [] | [
{
"param": "edge",
"type": "struct radix_edge"
},
{
"param": "key",
"type": "uint64_t"
},
{
"param": "keyshift",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "edge",
"type": "struct radix_edge",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "key",
"type": "uint64_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "keyshift",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ea867bb9147ed01c8314a05c0e5cee6868e35ca9 | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/src/magazine_small.c | [
"Apache-2.0"
] | C | small_free_list_add_ptr | free_list_t | static free_list_t
small_free_list_add_ptr(rack_t *rack, magazine_t *small_mag_ptr, void *ptr, msize_t msize)
{
grain_t slot = SMALL_FREE_SLOT_FOR_MSIZE(rack, msize);
free_list_t free_head = small_mag_ptr->mag_free_list[slot];
// This will either return the free_list_t for the current pointer, or attempt
// to reserve an OOB entry for us.
free_list_t free_ptr = small_free_list_from_ptr(rack, ptr, msize);
#if DEBUG_MALLOC
if (LOG(szone, ptr)) {
malloc_report(ASL_LEVEL_INFO, "in %s, ptr=%p, msize=%d\n", __FUNCTION__, ptr, msize);
}
if (((uintptr_t)ptr) & (SMALL_QUANTUM - 1)) {
malloc_zone_error(rack->debug_flags, true, "small_free_list_add_ptr: Unaligned ptr %p\n", ptr);
}
#endif
small_free_list_set_previous(rack, free_ptr, (free_list_t){ .p = NULL });
small_free_list_set_next(rack, free_ptr, free_head);
// Set the start and end blocks of the meta header as "free". Marking the last block
// allows coalescing the regions when we free adjacent regions.
small_free_mark_free(rack, free_ptr, msize);
if (small_free_list_get_ptr(rack, free_head)) {
#if DEBUG_MALLOC
if (small_free_list_get_previous(szone, free_head)) {
malloc_zone_error(rack->debug_flags, true, "small_free_list_add_ptr: Internal invariant broken (free_head->previous != NULL)\n"
"ptr=%p slot=%d free_head=%p previous=%p\n", ptr, slot, (void *)free_head, free_head->previous.p);
}
if (!SMALL_PTR_IS_FREE(small_free_list_get_ptr(szone, free_head))) {
malloc_zone_error(rack->debug_flags, true, "small_free_list_add_ptr: Internal invariant broken (free_head is not a free pointer)\n"
"ptr=%p slot=%d free_head=%p\n", ptr, slot, (void *)small_free_list_get_ptr(szone, free_head));
}
#endif
small_free_list_set_previous(rack, free_head, free_ptr);
} else {
BITMAPN_SET(small_mag_ptr->mag_bitmap, slot);
}
small_mag_ptr->mag_free_list[slot] = free_ptr;
return free_ptr;
} | /*
* Adds an item to the proper free list, and also marks the meta-header of the
* block properly.
* Assumes szone has been locked
*/ | Adds an item to the proper free list, and also marks the meta-header of the
block properly.
Assumes szone has been locked | [
"Adds",
"an",
"item",
"to",
"the",
"proper",
"free",
"list",
"and",
"also",
"marks",
"the",
"meta",
"-",
"header",
"of",
"the",
"block",
"properly",
".",
"Assumes",
"szone",
"has",
"been",
"locked"
] | static free_list_t
small_free_list_add_ptr(rack_t *rack, magazine_t *small_mag_ptr, void *ptr, msize_t msize)
{
grain_t slot = SMALL_FREE_SLOT_FOR_MSIZE(rack, msize);
free_list_t free_head = small_mag_ptr->mag_free_list[slot];
free_list_t free_ptr = small_free_list_from_ptr(rack, ptr, msize);
#if DEBUG_MALLOC
if (LOG(szone, ptr)) {
malloc_report(ASL_LEVEL_INFO, "in %s, ptr=%p, msize=%d\n", __FUNCTION__, ptr, msize);
}
if (((uintptr_t)ptr) & (SMALL_QUANTUM - 1)) {
malloc_zone_error(rack->debug_flags, true, "small_free_list_add_ptr: Unaligned ptr %p\n", ptr);
}
#endif
small_free_list_set_previous(rack, free_ptr, (free_list_t){ .p = NULL });
small_free_list_set_next(rack, free_ptr, free_head);
small_free_mark_free(rack, free_ptr, msize);
if (small_free_list_get_ptr(rack, free_head)) {
#if DEBUG_MALLOC
if (small_free_list_get_previous(szone, free_head)) {
malloc_zone_error(rack->debug_flags, true, "small_free_list_add_ptr: Internal invariant broken (free_head->previous != NULL)\n"
"ptr=%p slot=%d free_head=%p previous=%p\n", ptr, slot, (void *)free_head, free_head->previous.p);
}
if (!SMALL_PTR_IS_FREE(small_free_list_get_ptr(szone, free_head))) {
malloc_zone_error(rack->debug_flags, true, "small_free_list_add_ptr: Internal invariant broken (free_head is not a free pointer)\n"
"ptr=%p slot=%d free_head=%p\n", ptr, slot, (void *)small_free_list_get_ptr(szone, free_head));
}
#endif
small_free_list_set_previous(rack, free_head, free_ptr);
} else {
BITMAPN_SET(small_mag_ptr->mag_bitmap, slot);
}
small_mag_ptr->mag_free_list[slot] = free_ptr;
return free_ptr;
} | [
"static",
"free_list_t",
"small_free_list_add_ptr",
"(",
"rack_t",
"*",
"rack",
",",
"magazine_t",
"*",
"small_mag_ptr",
",",
"void",
"*",
"ptr",
",",
"msize_t",
"msize",
")",
"{",
"grain_t",
"slot",
"=",
"SMALL_FREE_SLOT_FOR_MSIZE",
"(",
"rack",
",",
"msize",
")",
";",
"free_list_t",
"free_head",
"=",
"small_mag_ptr",
"->",
"mag_free_list",
"[",
"slot",
"]",
";",
"free_list_t",
"free_ptr",
"=",
"small_free_list_from_ptr",
"(",
"rack",
",",
"ptr",
",",
"msize",
")",
";",
"#if",
"DEBUG_MALLOC",
"\n",
"if",
"(",
"LOG",
"(",
"szone",
",",
"ptr",
")",
")",
"{",
"malloc_report",
"(",
"ASL_LEVEL_INFO",
",",
"\"",
"\\n",
"\"",
",",
"__FUNCTION__",
",",
"ptr",
",",
"msize",
")",
";",
"}",
"if",
"(",
"(",
"(",
"uintptr_t",
")",
"ptr",
")",
"&",
"(",
"SMALL_QUANTUM",
"-",
"1",
")",
")",
"{",
"malloc_zone_error",
"(",
"rack",
"->",
"debug_flags",
",",
"true",
",",
"\"",
"\\n",
"\"",
",",
"ptr",
")",
";",
"}",
"#endif",
"small_free_list_set_previous",
"(",
"rack",
",",
"free_ptr",
",",
"(",
"free_list_t",
")",
"{",
".",
"p",
"=",
"NULL",
"}",
")",
";",
"small_free_list_set_next",
"(",
"rack",
",",
"free_ptr",
",",
"free_head",
")",
";",
"small_free_mark_free",
"(",
"rack",
",",
"free_ptr",
",",
"msize",
")",
";",
"if",
"(",
"small_free_list_get_ptr",
"(",
"rack",
",",
"free_head",
")",
")",
"{",
"#if",
"DEBUG_MALLOC",
"\n",
"if",
"(",
"small_free_list_get_previous",
"(",
"szone",
",",
"free_head",
")",
")",
"{",
"malloc_zone_error",
"(",
"rack",
"->",
"debug_flags",
",",
"true",
",",
"\"",
"\\n",
"\"",
"\"",
"\\n",
"\"",
",",
"ptr",
",",
"slot",
",",
"(",
"void",
"*",
")",
"free_head",
",",
"free_head",
"->",
"previous",
".",
"p",
")",
";",
"}",
"if",
"(",
"!",
"SMALL_PTR_IS_FREE",
"(",
"small_free_list_get_ptr",
"(",
"szone",
",",
"free_head",
")",
")",
")",
"{",
"malloc_zone_error",
"(",
"rack",
"->",
"debug_flags",
",",
"true",
",",
"\"",
"\\n",
"\"",
"\"",
"\\n",
"\"",
",",
"ptr",
",",
"slot",
",",
"(",
"void",
"*",
")",
"small_free_list_get_ptr",
"(",
"szone",
",",
"free_head",
")",
")",
";",
"}",
"#endif",
"small_free_list_set_previous",
"(",
"rack",
",",
"free_head",
",",
"free_ptr",
")",
";",
"}",
"else",
"{",
"BITMAPN_SET",
"(",
"small_mag_ptr",
"->",
"mag_bitmap",
",",
"slot",
")",
";",
"}",
"small_mag_ptr",
"->",
"mag_free_list",
"[",
"slot",
"]",
"=",
"free_ptr",
";",
"return",
"free_ptr",
";",
"}"
] | Adds an item to the proper free list, and also marks the meta-header of the
block properly. | [
"Adds",
"an",
"item",
"to",
"the",
"proper",
"free",
"list",
"and",
"also",
"marks",
"the",
"meta",
"-",
"header",
"of",
"the",
"block",
"properly",
"."
] | [
"// This will either return the free_list_t for the current pointer, or attempt",
"// to reserve an OOB entry for us.",
"// Set the start and end blocks of the meta header as \"free\". Marking the last block",
"// allows coalescing the regions when we free adjacent regions."
] | [
{
"param": "rack",
"type": "rack_t"
},
{
"param": "small_mag_ptr",
"type": "magazine_t"
},
{
"param": "ptr",
"type": "void"
},
{
"param": "msize",
"type": "msize_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rack",
"type": "rack_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "small_mag_ptr",
"type": "magazine_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ptr",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "msize",
"type": "msize_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ea867bb9147ed01c8314a05c0e5cee6868e35ca9 | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/src/magazine_small.c | [
"Apache-2.0"
] | C | small_free_list_remove_ptr_no_clear | void | static void
small_free_list_remove_ptr_no_clear(rack_t *rack, magazine_t *small_mag_ptr, free_list_t entry, msize_t msize)
{
grain_t slot = SMALL_FREE_SLOT_FOR_MSIZE(rack, msize);
free_list_t next, previous;
#if DEBUG_MALLOC
if (LOG(szone, ptr)) {
malloc_report(ASL_LEVEL_INFO, "In %s, ptr=%p, msize=%d\n", __FUNCTION__, ptr, msize);
}
#endif
previous = small_free_list_get_previous(rack, entry);
next = small_free_list_get_next(rack, entry);
if (!small_free_list_get_ptr(rack, previous)) {
// The block to remove is the head of the free list
#if DEBUG_MALLOC
if (small_mag_ptr->mag_free_list[slot] != ptr) {
malloc_zone_error(rack->debug_flags, true,
"small_free_list_remove_ptr_no_clear: Internal invariant broken (small_mag_ptr->mag_free_list[slot])\n"
"ptr=%p slot=%d msize=%d small_mag_ptr->mag_free_list[slot]=%p\n", ptr, slot, msize,
(void *)small_mag_ptr->mag_free_list[slot]);
return;
}
#endif
small_mag_ptr->mag_free_list[slot] = next;
if (!small_free_list_get_ptr(rack, next)) {
BITMAPN_CLR(small_mag_ptr->mag_bitmap, slot);
}
} else {
// Check that the next pointer of "previous" points to "entry".
free_list_t prev_next = small_free_list_get_next(rack, previous);
if (small_free_list_get_ptr(rack, prev_next) != small_free_list_get_ptr(rack, entry)) {
malloc_zone_error(rack->debug_flags, true,
"small_free_list_remove_ptr_no_clear: Internal invariant broken (next ptr of prev) for %p, prev_next=%p\n",
small_free_list_get_ptr(rack, entry), small_free_list_get_ptr(rack, prev_next));
__builtin_unreachable(); // Always crashes in malloc_zone_error().
}
small_free_list_set_next(rack, previous, next);
}
if (small_free_list_get_ptr(rack, next)) {
// Check that the previous pointer of "next" points to "entry".
free_list_t next_prev = small_free_list_get_previous(rack, next);
if (small_free_list_get_ptr(rack, next_prev) != small_free_list_get_ptr(rack, entry)) {
malloc_zone_error(rack->debug_flags, true,
"small_free_list_remove_ptr_no_clear: Internal invariant broken (prev ptr of next) for %p, next_prev=%p\n",
small_free_list_get_ptr(rack, entry), small_free_list_get_ptr(rack, next_prev));
__builtin_unreachable(); // Always crashes in malloc_zone_error().
}
small_free_list_set_previous(rack, next, previous);
}
if (small_is_oob_free_entry(entry)) {
small_oob_free_entry_set_free(entry.oob);
}
} | /*
* Removes the item pointed to by ptr in the proper free list.
* Assumes szone has been locked
*/ | Removes the item pointed to by ptr in the proper free list.
Assumes szone has been locked | [
"Removes",
"the",
"item",
"pointed",
"to",
"by",
"ptr",
"in",
"the",
"proper",
"free",
"list",
".",
"Assumes",
"szone",
"has",
"been",
"locked"
] | static void
small_free_list_remove_ptr_no_clear(rack_t *rack, magazine_t *small_mag_ptr, free_list_t entry, msize_t msize)
{
grain_t slot = SMALL_FREE_SLOT_FOR_MSIZE(rack, msize);
free_list_t next, previous;
#if DEBUG_MALLOC
if (LOG(szone, ptr)) {
malloc_report(ASL_LEVEL_INFO, "In %s, ptr=%p, msize=%d\n", __FUNCTION__, ptr, msize);
}
#endif
previous = small_free_list_get_previous(rack, entry);
next = small_free_list_get_next(rack, entry);
if (!small_free_list_get_ptr(rack, previous)) {
#if DEBUG_MALLOC
if (small_mag_ptr->mag_free_list[slot] != ptr) {
malloc_zone_error(rack->debug_flags, true,
"small_free_list_remove_ptr_no_clear: Internal invariant broken (small_mag_ptr->mag_free_list[slot])\n"
"ptr=%p slot=%d msize=%d small_mag_ptr->mag_free_list[slot]=%p\n", ptr, slot, msize,
(void *)small_mag_ptr->mag_free_list[slot]);
return;
}
#endif
small_mag_ptr->mag_free_list[slot] = next;
if (!small_free_list_get_ptr(rack, next)) {
BITMAPN_CLR(small_mag_ptr->mag_bitmap, slot);
}
} else {
free_list_t prev_next = small_free_list_get_next(rack, previous);
if (small_free_list_get_ptr(rack, prev_next) != small_free_list_get_ptr(rack, entry)) {
malloc_zone_error(rack->debug_flags, true,
"small_free_list_remove_ptr_no_clear: Internal invariant broken (next ptr of prev) for %p, prev_next=%p\n",
small_free_list_get_ptr(rack, entry), small_free_list_get_ptr(rack, prev_next));
__builtin_unreachable();
}
small_free_list_set_next(rack, previous, next);
}
if (small_free_list_get_ptr(rack, next)) {
free_list_t next_prev = small_free_list_get_previous(rack, next);
if (small_free_list_get_ptr(rack, next_prev) != small_free_list_get_ptr(rack, entry)) {
malloc_zone_error(rack->debug_flags, true,
"small_free_list_remove_ptr_no_clear: Internal invariant broken (prev ptr of next) for %p, next_prev=%p\n",
small_free_list_get_ptr(rack, entry), small_free_list_get_ptr(rack, next_prev));
__builtin_unreachable();
}
small_free_list_set_previous(rack, next, previous);
}
if (small_is_oob_free_entry(entry)) {
small_oob_free_entry_set_free(entry.oob);
}
} | [
"static",
"void",
"small_free_list_remove_ptr_no_clear",
"(",
"rack_t",
"*",
"rack",
",",
"magazine_t",
"*",
"small_mag_ptr",
",",
"free_list_t",
"entry",
",",
"msize_t",
"msize",
")",
"{",
"grain_t",
"slot",
"=",
"SMALL_FREE_SLOT_FOR_MSIZE",
"(",
"rack",
",",
"msize",
")",
";",
"free_list_t",
"next",
",",
"previous",
";",
"#if",
"DEBUG_MALLOC",
"\n",
"if",
"(",
"LOG",
"(",
"szone",
",",
"ptr",
")",
")",
"{",
"malloc_report",
"(",
"ASL_LEVEL_INFO",
",",
"\"",
"\\n",
"\"",
",",
"__FUNCTION__",
",",
"ptr",
",",
"msize",
")",
";",
"}",
"#endif",
"previous",
"=",
"small_free_list_get_previous",
"(",
"rack",
",",
"entry",
")",
";",
"next",
"=",
"small_free_list_get_next",
"(",
"rack",
",",
"entry",
")",
";",
"if",
"(",
"!",
"small_free_list_get_ptr",
"(",
"rack",
",",
"previous",
")",
")",
"{",
"#if",
"DEBUG_MALLOC",
"\n",
"if",
"(",
"small_mag_ptr",
"->",
"mag_free_list",
"[",
"slot",
"]",
"!=",
"ptr",
")",
"{",
"malloc_zone_error",
"(",
"rack",
"->",
"debug_flags",
",",
"true",
",",
"\"",
"\\n",
"\"",
"\"",
"\\n",
"\"",
",",
"ptr",
",",
"slot",
",",
"msize",
",",
"(",
"void",
"*",
")",
"small_mag_ptr",
"->",
"mag_free_list",
"[",
"slot",
"]",
")",
";",
"return",
";",
"}",
"#endif",
"small_mag_ptr",
"->",
"mag_free_list",
"[",
"slot",
"]",
"=",
"next",
";",
"if",
"(",
"!",
"small_free_list_get_ptr",
"(",
"rack",
",",
"next",
")",
")",
"{",
"BITMAPN_CLR",
"(",
"small_mag_ptr",
"->",
"mag_bitmap",
",",
"slot",
")",
";",
"}",
"}",
"else",
"{",
"free_list_t",
"prev_next",
"=",
"small_free_list_get_next",
"(",
"rack",
",",
"previous",
")",
";",
"if",
"(",
"small_free_list_get_ptr",
"(",
"rack",
",",
"prev_next",
")",
"!=",
"small_free_list_get_ptr",
"(",
"rack",
",",
"entry",
")",
")",
"{",
"malloc_zone_error",
"(",
"rack",
"->",
"debug_flags",
",",
"true",
",",
"\"",
"\\n",
"\"",
",",
"small_free_list_get_ptr",
"(",
"rack",
",",
"entry",
")",
",",
"small_free_list_get_ptr",
"(",
"rack",
",",
"prev_next",
")",
")",
";",
"__builtin_unreachable",
"(",
")",
";",
"}",
"small_free_list_set_next",
"(",
"rack",
",",
"previous",
",",
"next",
")",
";",
"}",
"if",
"(",
"small_free_list_get_ptr",
"(",
"rack",
",",
"next",
")",
")",
"{",
"free_list_t",
"next_prev",
"=",
"small_free_list_get_previous",
"(",
"rack",
",",
"next",
")",
";",
"if",
"(",
"small_free_list_get_ptr",
"(",
"rack",
",",
"next_prev",
")",
"!=",
"small_free_list_get_ptr",
"(",
"rack",
",",
"entry",
")",
")",
"{",
"malloc_zone_error",
"(",
"rack",
"->",
"debug_flags",
",",
"true",
",",
"\"",
"\\n",
"\"",
",",
"small_free_list_get_ptr",
"(",
"rack",
",",
"entry",
")",
",",
"small_free_list_get_ptr",
"(",
"rack",
",",
"next_prev",
")",
")",
";",
"__builtin_unreachable",
"(",
")",
";",
"}",
"small_free_list_set_previous",
"(",
"rack",
",",
"next",
",",
"previous",
")",
";",
"}",
"if",
"(",
"small_is_oob_free_entry",
"(",
"entry",
")",
")",
"{",
"small_oob_free_entry_set_free",
"(",
"entry",
".",
"oob",
")",
";",
"}",
"}"
] | Removes the item pointed to by ptr in the proper free list. | [
"Removes",
"the",
"item",
"pointed",
"to",
"by",
"ptr",
"in",
"the",
"proper",
"free",
"list",
"."
] | [
"// The block to remove is the head of the free list",
"// Check that the next pointer of \"previous\" points to \"entry\".",
"// Always crashes in malloc_zone_error().",
"// Check that the previous pointer of \"next\" points to \"entry\".",
"// Always crashes in malloc_zone_error()."
] | [
{
"param": "rack",
"type": "rack_t"
},
{
"param": "small_mag_ptr",
"type": "magazine_t"
},
{
"param": "entry",
"type": "free_list_t"
},
{
"param": "msize",
"type": "msize_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rack",
"type": "rack_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "small_mag_ptr",
"type": "magazine_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "entry",
"type": "free_list_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "msize",
"type": "msize_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ea867bb9147ed01c8314a05c0e5cee6868e35ca9 | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/src/magazine_small.c | [
"Apache-2.0"
] | C | small_free_list_find_by_ptr | free_list_t | static free_list_t
small_free_list_find_by_ptr(rack_t *rack, magazine_t *small_mag_ptr, void *ptr, msize_t msize)
{
if (*SMALL_METADATA_FOR_PTR(ptr) == (SMALL_IS_FREE | msize)) {
// If the block is marked free, and of size `msize`, then we first must check
// if the alignment+size is such that we could have use an OOB-entry.
if (small_needs_oob_free_entry(ptr, msize)) {
// Scan the OOB entries looking for this address.
small_region_t region = SMALL_REGION_FOR_PTR(ptr);
for (int i=0; i<SMALL_OOB_COUNT; i++) {
if (!region->small_oob_free_entries[i].ptr) {
continue;
}
if (small_oob_free_entry_get_ptr(®ion->small_oob_free_entries[i]) == ptr) {
return (free_list_t){ .oob = ®ion->small_oob_free_entries[i] };
}
}
}
// Otherwise, the freed pointer will be in place.
return (free_list_t){ .p = ptr };
}
malloc_zone_error(rack->debug_flags, true,
"small_free_list_find_by_ptr: ptr is not free (ptr metadata !SMALL_IS_FREE), "
"ptr=%p msize=%d metadata=0x%x\n", ptr, msize, *SMALL_METADATA_FOR_PTR(ptr));
__builtin_trap();
} | // Find a free list entry by its pointer address. This should only really be used
// by small_finalize_region, or similar, where the free_list_t entry of a known
// pointer is desired. Otherwise it is cheaper to always pull off the free lists. | Find a free list entry by its pointer address. This should only really be used
by small_finalize_region, or similar, where the free_list_t entry of a known
pointer is desired. Otherwise it is cheaper to always pull off the free lists. | [
"Find",
"a",
"free",
"list",
"entry",
"by",
"its",
"pointer",
"address",
".",
"This",
"should",
"only",
"really",
"be",
"used",
"by",
"small_finalize_region",
"or",
"similar",
"where",
"the",
"free_list_t",
"entry",
"of",
"a",
"known",
"pointer",
"is",
"desired",
".",
"Otherwise",
"it",
"is",
"cheaper",
"to",
"always",
"pull",
"off",
"the",
"free",
"lists",
"."
] | static free_list_t
small_free_list_find_by_ptr(rack_t *rack, magazine_t *small_mag_ptr, void *ptr, msize_t msize)
{
if (*SMALL_METADATA_FOR_PTR(ptr) == (SMALL_IS_FREE | msize)) {
if (small_needs_oob_free_entry(ptr, msize)) {
small_region_t region = SMALL_REGION_FOR_PTR(ptr);
for (int i=0; i<SMALL_OOB_COUNT; i++) {
if (!region->small_oob_free_entries[i].ptr) {
continue;
}
if (small_oob_free_entry_get_ptr(®ion->small_oob_free_entries[i]) == ptr) {
return (free_list_t){ .oob = ®ion->small_oob_free_entries[i] };
}
}
}
return (free_list_t){ .p = ptr };
}
malloc_zone_error(rack->debug_flags, true,
"small_free_list_find_by_ptr: ptr is not free (ptr metadata !SMALL_IS_FREE), "
"ptr=%p msize=%d metadata=0x%x\n", ptr, msize, *SMALL_METADATA_FOR_PTR(ptr));
__builtin_trap();
} | [
"static",
"free_list_t",
"small_free_list_find_by_ptr",
"(",
"rack_t",
"*",
"rack",
",",
"magazine_t",
"*",
"small_mag_ptr",
",",
"void",
"*",
"ptr",
",",
"msize_t",
"msize",
")",
"{",
"if",
"(",
"*",
"SMALL_METADATA_FOR_PTR",
"(",
"ptr",
")",
"==",
"(",
"SMALL_IS_FREE",
"|",
"msize",
")",
")",
"{",
"if",
"(",
"small_needs_oob_free_entry",
"(",
"ptr",
",",
"msize",
")",
")",
"{",
"small_region_t",
"region",
"=",
"SMALL_REGION_FOR_PTR",
"(",
"ptr",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"SMALL_OOB_COUNT",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"region",
"->",
"small_oob_free_entries",
"[",
"i",
"]",
".",
"ptr",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"small_oob_free_entry_get_ptr",
"(",
"&",
"region",
"->",
"small_oob_free_entries",
"[",
"i",
"]",
")",
"==",
"ptr",
")",
"{",
"return",
"(",
"free_list_t",
")",
"{",
".",
"oob",
"=",
"&",
"region",
"->",
"small_oob_free_entries",
"[",
"i",
"]",
"}",
";",
"}",
"}",
"}",
"return",
"(",
"free_list_t",
")",
"{",
".",
"p",
"=",
"ptr",
"}",
";",
"}",
"malloc_zone_error",
"(",
"rack",
"->",
"debug_flags",
",",
"true",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"ptr",
",",
"msize",
",",
"*",
"SMALL_METADATA_FOR_PTR",
"(",
"ptr",
")",
")",
";",
"__builtin_trap",
"(",
")",
";",
"}"
] | Find a free list entry by its pointer address. | [
"Find",
"a",
"free",
"list",
"entry",
"by",
"its",
"pointer",
"address",
"."
] | [
"// If the block is marked free, and of size `msize`, then we first must check",
"// if the alignment+size is such that we could have use an OOB-entry.",
"// Scan the OOB entries looking for this address.",
"// Otherwise, the freed pointer will be in place."
] | [
{
"param": "rack",
"type": "rack_t"
},
{
"param": "small_mag_ptr",
"type": "magazine_t"
},
{
"param": "ptr",
"type": "void"
},
{
"param": "msize",
"type": "msize_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rack",
"type": "rack_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "small_mag_ptr",
"type": "magazine_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ptr",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "msize",
"type": "msize_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ea867bb9147ed01c8314a05c0e5cee6868e35ca9 | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/src/magazine_small.c | [
"Apache-2.0"
] | C | small_malloc_from_region_no_lock | void | static void *
small_malloc_from_region_no_lock(rack_t *rack,
magazine_t *small_mag_ptr,
mag_index_t mag_index,
msize_t msize,
void *aligned_address)
{
void *ptr;
// Before anything we transform the mag_bytes_free_at_end or mag_bytes_free_at_start - if any - to a regular free block
/* FIXME: last_block needs to be coalesced with previous entry if free, <rdar://5462322> */
if (small_mag_ptr->mag_bytes_free_at_end || small_mag_ptr->mag_bytes_free_at_start) {
small_finalize_region(rack, small_mag_ptr);
}
// Tag the region at "aligned_address" as belonging to us,
// and so put it under the protection of the magazine lock we are holding.
// Do this before advertising "aligned_address" on the hash ring(!)
MAGAZINE_INDEX_FOR_SMALL_REGION(aligned_address) = mag_index;
// Insert the new region into the hash ring
rack_region_insert(rack, (region_t)aligned_address);
small_mag_ptr->mag_last_region = aligned_address;
BYTES_USED_FOR_SMALL_REGION(aligned_address) = SMALL_BYTES_FOR_MSIZE(msize);
#if CONFIG_ASLR_INTERNAL
int offset_msize = malloc_entropy[1] & SMALL_ENTROPY_MASK;
#if DEBUG_MALLOC
if (getenv("MallocASLRForce")) {
offset_msize = strtol(getenv("MallocASLRForce"), NULL, 0) & SMALL_ENTROPY_MASK;
}
if (getenv("MallocASLRPrint")) {
malloc_report(ASL_LEVEL_INFO, "Region: %p offset: %d\n", aligned_address, offset_msize);
}
#endif
#else
int offset_msize = 0;
#endif
ptr = (void *)((uintptr_t)aligned_address + SMALL_BYTES_FOR_MSIZE(offset_msize));
small_meta_header_set_in_use(SMALL_META_HEADER_FOR_PTR(ptr), offset_msize, msize);
small_mag_ptr->mag_num_objects++;
small_mag_ptr->mag_num_bytes_in_objects += SMALL_BYTES_FOR_MSIZE(msize);
small_mag_ptr->num_bytes_in_magazine += SMALL_REGION_PAYLOAD_BYTES;
// add a big free block at the end
small_meta_header_set_in_use(SMALL_META_HEADER_FOR_PTR(ptr), offset_msize + msize, NUM_SMALL_BLOCKS - msize - offset_msize);
small_mag_ptr->mag_bytes_free_at_end = SMALL_BYTES_FOR_MSIZE(NUM_SMALL_BLOCKS - msize - offset_msize);
#if CONFIG_ASLR_INTERNAL
// add a big free block at the start
small_mag_ptr->mag_bytes_free_at_start = SMALL_BYTES_FOR_MSIZE(offset_msize);
if (offset_msize) {
small_meta_header_set_in_use(SMALL_META_HEADER_FOR_PTR(ptr), 0, offset_msize);
}
#else
small_mag_ptr->mag_bytes_free_at_start = 0;
#endif
// connect to magazine as last node
recirc_list_splice_last(rack, small_mag_ptr, REGION_TRAILER_FOR_SMALL_REGION(aligned_address));
return ptr;
} | // Allocates from the last region or a freshly allocated region | Allocates from the last region or a freshly allocated region | [
"Allocates",
"from",
"the",
"last",
"region",
"or",
"a",
"freshly",
"allocated",
"region"
] | static void *
small_malloc_from_region_no_lock(rack_t *rack,
magazine_t *small_mag_ptr,
mag_index_t mag_index,
msize_t msize,
void *aligned_address)
{
void *ptr;
if (small_mag_ptr->mag_bytes_free_at_end || small_mag_ptr->mag_bytes_free_at_start) {
small_finalize_region(rack, small_mag_ptr);
}
MAGAZINE_INDEX_FOR_SMALL_REGION(aligned_address) = mag_index;
rack_region_insert(rack, (region_t)aligned_address);
small_mag_ptr->mag_last_region = aligned_address;
BYTES_USED_FOR_SMALL_REGION(aligned_address) = SMALL_BYTES_FOR_MSIZE(msize);
#if CONFIG_ASLR_INTERNAL
int offset_msize = malloc_entropy[1] & SMALL_ENTROPY_MASK;
#if DEBUG_MALLOC
if (getenv("MallocASLRForce")) {
offset_msize = strtol(getenv("MallocASLRForce"), NULL, 0) & SMALL_ENTROPY_MASK;
}
if (getenv("MallocASLRPrint")) {
malloc_report(ASL_LEVEL_INFO, "Region: %p offset: %d\n", aligned_address, offset_msize);
}
#endif
#else
int offset_msize = 0;
#endif
ptr = (void *)((uintptr_t)aligned_address + SMALL_BYTES_FOR_MSIZE(offset_msize));
small_meta_header_set_in_use(SMALL_META_HEADER_FOR_PTR(ptr), offset_msize, msize);
small_mag_ptr->mag_num_objects++;
small_mag_ptr->mag_num_bytes_in_objects += SMALL_BYTES_FOR_MSIZE(msize);
small_mag_ptr->num_bytes_in_magazine += SMALL_REGION_PAYLOAD_BYTES;
small_meta_header_set_in_use(SMALL_META_HEADER_FOR_PTR(ptr), offset_msize + msize, NUM_SMALL_BLOCKS - msize - offset_msize);
small_mag_ptr->mag_bytes_free_at_end = SMALL_BYTES_FOR_MSIZE(NUM_SMALL_BLOCKS - msize - offset_msize);
#if CONFIG_ASLR_INTERNAL
small_mag_ptr->mag_bytes_free_at_start = SMALL_BYTES_FOR_MSIZE(offset_msize);
if (offset_msize) {
small_meta_header_set_in_use(SMALL_META_HEADER_FOR_PTR(ptr), 0, offset_msize);
}
#else
small_mag_ptr->mag_bytes_free_at_start = 0;
#endif
recirc_list_splice_last(rack, small_mag_ptr, REGION_TRAILER_FOR_SMALL_REGION(aligned_address));
return ptr;
} | [
"static",
"void",
"*",
"small_malloc_from_region_no_lock",
"(",
"rack_t",
"*",
"rack",
",",
"magazine_t",
"*",
"small_mag_ptr",
",",
"mag_index_t",
"mag_index",
",",
"msize_t",
"msize",
",",
"void",
"*",
"aligned_address",
")",
"{",
"void",
"*",
"ptr",
";",
"if",
"(",
"small_mag_ptr",
"->",
"mag_bytes_free_at_end",
"||",
"small_mag_ptr",
"->",
"mag_bytes_free_at_start",
")",
"{",
"small_finalize_region",
"(",
"rack",
",",
"small_mag_ptr",
")",
";",
"}",
"MAGAZINE_INDEX_FOR_SMALL_REGION",
"(",
"aligned_address",
")",
"=",
"mag_index",
";",
"rack_region_insert",
"(",
"rack",
",",
"(",
"region_t",
")",
"aligned_address",
")",
";",
"small_mag_ptr",
"->",
"mag_last_region",
"=",
"aligned_address",
";",
"BYTES_USED_FOR_SMALL_REGION",
"(",
"aligned_address",
")",
"=",
"SMALL_BYTES_FOR_MSIZE",
"(",
"msize",
")",
";",
"#if",
"CONFIG_ASLR_INTERNAL",
"\n",
"int",
"offset_msize",
"=",
"malloc_entropy",
"[",
"1",
"]",
"&",
"SMALL_ENTROPY_MASK",
";",
"#if",
"DEBUG_MALLOC",
"\n",
"if",
"(",
"getenv",
"(",
"\"",
"\"",
")",
")",
"{",
"offset_msize",
"=",
"strtol",
"(",
"getenv",
"(",
"\"",
"\"",
")",
",",
"NULL",
",",
"0",
")",
"&",
"SMALL_ENTROPY_MASK",
";",
"}",
"if",
"(",
"getenv",
"(",
"\"",
"\"",
")",
")",
"{",
"malloc_report",
"(",
"ASL_LEVEL_INFO",
",",
"\"",
"\\n",
"\"",
",",
"aligned_address",
",",
"offset_msize",
")",
";",
"}",
"#endif",
"#else",
"int",
"offset_msize",
"=",
"0",
";",
"#endif",
"ptr",
"=",
"(",
"void",
"*",
")",
"(",
"(",
"uintptr_t",
")",
"aligned_address",
"+",
"SMALL_BYTES_FOR_MSIZE",
"(",
"offset_msize",
")",
")",
";",
"small_meta_header_set_in_use",
"(",
"SMALL_META_HEADER_FOR_PTR",
"(",
"ptr",
")",
",",
"offset_msize",
",",
"msize",
")",
";",
"small_mag_ptr",
"->",
"mag_num_objects",
"++",
";",
"small_mag_ptr",
"->",
"mag_num_bytes_in_objects",
"+=",
"SMALL_BYTES_FOR_MSIZE",
"(",
"msize",
")",
";",
"small_mag_ptr",
"->",
"num_bytes_in_magazine",
"+=",
"SMALL_REGION_PAYLOAD_BYTES",
";",
"small_meta_header_set_in_use",
"(",
"SMALL_META_HEADER_FOR_PTR",
"(",
"ptr",
")",
",",
"offset_msize",
"+",
"msize",
",",
"NUM_SMALL_BLOCKS",
"-",
"msize",
"-",
"offset_msize",
")",
";",
"small_mag_ptr",
"->",
"mag_bytes_free_at_end",
"=",
"SMALL_BYTES_FOR_MSIZE",
"(",
"NUM_SMALL_BLOCKS",
"-",
"msize",
"-",
"offset_msize",
")",
";",
"#if",
"CONFIG_ASLR_INTERNAL",
"\n",
"small_mag_ptr",
"->",
"mag_bytes_free_at_start",
"=",
"SMALL_BYTES_FOR_MSIZE",
"(",
"offset_msize",
")",
";",
"if",
"(",
"offset_msize",
")",
"{",
"small_meta_header_set_in_use",
"(",
"SMALL_META_HEADER_FOR_PTR",
"(",
"ptr",
")",
",",
"0",
",",
"offset_msize",
")",
";",
"}",
"#else",
"small_mag_ptr",
"->",
"mag_bytes_free_at_start",
"=",
"0",
";",
"#endif",
"recirc_list_splice_last",
"(",
"rack",
",",
"small_mag_ptr",
",",
"REGION_TRAILER_FOR_SMALL_REGION",
"(",
"aligned_address",
")",
")",
";",
"return",
"ptr",
";",
"}"
] | Allocates from the last region or a freshly allocated region | [
"Allocates",
"from",
"the",
"last",
"region",
"or",
"a",
"freshly",
"allocated",
"region"
] | [
"// Before anything we transform the mag_bytes_free_at_end or mag_bytes_free_at_start - if any - to a regular free block",
"/* FIXME: last_block needs to be coalesced with previous entry if free, <rdar://5462322> */",
"// Tag the region at \"aligned_address\" as belonging to us,",
"// and so put it under the protection of the magazine lock we are holding.",
"// Do this before advertising \"aligned_address\" on the hash ring(!)",
"// Insert the new region into the hash ring",
"// add a big free block at the end",
"// add a big free block at the start",
"// connect to magazine as last node"
] | [
{
"param": "rack",
"type": "rack_t"
},
{
"param": "small_mag_ptr",
"type": "magazine_t"
},
{
"param": "mag_index",
"type": "mag_index_t"
},
{
"param": "msize",
"type": "msize_t"
},
{
"param": "aligned_address",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rack",
"type": "rack_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "small_mag_ptr",
"type": "magazine_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "mag_index",
"type": "mag_index_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "msize",
"type": "msize_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "aligned_address",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a9328c8add803014c7c5be9f5f4fbe2ee57d9292 | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/tests/stress_test.c | [
"Apache-2.0"
] | C | sig_handler | void | void
sig_handler(int signo)
{
signal_happened = signo;
return;
} | /* gets set to signal# if one happens */ | gets set to signal# if one happens | [
"gets",
"set",
"to",
"signal#",
"if",
"one",
"happens"
] | void
sig_handler(int signo)
{
signal_happened = signo;
return;
} | [
"void",
"sig_handler",
"(",
"int",
"signo",
")",
"{",
"signal_happened",
"=",
"signo",
";",
"return",
";",
"}"
] | gets set to signal# if one happens | [
"gets",
"set",
"to",
"signal#",
"if",
"one",
"happens"
] | [] | [
{
"param": "signo",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "signo",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a9328c8add803014c7c5be9f5f4fbe2ee57d9292 | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/tests/stress_test.c | [
"Apache-2.0"
] | C | usage | void | void
usage()
{
printf("\nusage: malloc_stress [options...]\n");
printf("Default: Allocate up to %d buffers, with a %d percent free() chance.\n", MAX_MALLOC_INFO, free_pct);
printf(" Buffer sizes range from %d to %d bytes.\n", min_bytes, max_bytes);
printf("\nOptions:\n");
printf(" -min #bytes Minimum buffer size to allocate (at least 1).\n");
printf(" -max #bytes Maximum buffer size (up to 2gb allowed).\n");
printf(" -mem #bytes Stop when total allocations surpasses this.\n");
printf(" -free # Percent chance to free a buffer.\n");
printf(" -calls # Maximum allocations to do, then stop.\n");
printf(" -seed # Set the random seed to this number.\n");
printf(" -dbg Produce some debugging outputs.\n");
exit(99);
} | /* Display a brief usage message and exit with status 99 */ | Display a brief usage message and exit with status 99 | [
"Display",
"a",
"brief",
"usage",
"message",
"and",
"exit",
"with",
"status",
"99"
] | void
usage()
{
printf("\nusage: malloc_stress [options...]\n");
printf("Default: Allocate up to %d buffers, with a %d percent free() chance.\n", MAX_MALLOC_INFO, free_pct);
printf(" Buffer sizes range from %d to %d bytes.\n", min_bytes, max_bytes);
printf("\nOptions:\n");
printf(" -min #bytes Minimum buffer size to allocate (at least 1).\n");
printf(" -max #bytes Maximum buffer size (up to 2gb allowed).\n");
printf(" -mem #bytes Stop when total allocations surpasses this.\n");
printf(" -free # Percent chance to free a buffer.\n");
printf(" -calls # Maximum allocations to do, then stop.\n");
printf(" -seed # Set the random seed to this number.\n");
printf(" -dbg Produce some debugging outputs.\n");
exit(99);
} | [
"void",
"usage",
"(",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"MAX_MALLOC_INFO",
",",
"free_pct",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"min_bytes",
",",
"max_bytes",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"exit",
"(",
"99",
")",
";",
"}"
] | Display a brief usage message and exit with status 99 | [
"Display",
"a",
"brief",
"usage",
"message",
"and",
"exit",
"with",
"status",
"99"
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
a9328c8add803014c7c5be9f5f4fbe2ee57d9292 | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/tests/stress_test.c | [
"Apache-2.0"
] | C | summarize | void | void
summarize()
{
int mx;
printf("INFO: %d total malloc() calls made.\n", malloc_calls_made);
printf("INFO: %d total free() calls made during testing.\n", malloc_calls_made - malloc_bufs);
printf("INFO: Total memory allocated: %lld bytes\n", mem_allocated);
if (debug_dump) {
for (mx = 0; mx < malloc_calls_made; mx++) {
printf("Buffer index %d: Address = 0x%llx, Size=%d, Fill=%d ", mx, (unsigned long long)(minfo_array[mx].buf_ptr),
minfo_array[mx].buf_size, minfo_array[mx].set_val);
if (minfo_array[mx].this_buffer_freed) {
printf("[freed]");
}
printf("\n");
}
}
printf("INFO: Random seed value = %d\n", rseed);
return;
} | /*
* summarize(): Give a brief synopsis of the number of malloc() calls made,
* free() calls made, total memory allocated.
*/ | Give a brief synopsis of the number of malloc() calls made,
free() calls made, total memory allocated. | [
"Give",
"a",
"brief",
"synopsis",
"of",
"the",
"number",
"of",
"malloc",
"()",
"calls",
"made",
"free",
"()",
"calls",
"made",
"total",
"memory",
"allocated",
"."
] | void
summarize()
{
int mx;
printf("INFO: %d total malloc() calls made.\n", malloc_calls_made);
printf("INFO: %d total free() calls made during testing.\n", malloc_calls_made - malloc_bufs);
printf("INFO: Total memory allocated: %lld bytes\n", mem_allocated);
if (debug_dump) {
for (mx = 0; mx < malloc_calls_made; mx++) {
printf("Buffer index %d: Address = 0x%llx, Size=%d, Fill=%d ", mx, (unsigned long long)(minfo_array[mx].buf_ptr),
minfo_array[mx].buf_size, minfo_array[mx].set_val);
if (minfo_array[mx].this_buffer_freed) {
printf("[freed]");
}
printf("\n");
}
}
printf("INFO: Random seed value = %d\n", rseed);
return;
} | [
"void",
"summarize",
"(",
")",
"{",
"int",
"mx",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"malloc_calls_made",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"malloc_calls_made",
"-",
"malloc_bufs",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"mem_allocated",
")",
";",
"if",
"(",
"debug_dump",
")",
"{",
"for",
"(",
"mx",
"=",
"0",
";",
"mx",
"<",
"malloc_calls_made",
";",
"mx",
"++",
")",
"{",
"printf",
"(",
"\"",
"\"",
",",
"mx",
",",
"(",
"unsigned",
"long",
"long",
")",
"(",
"minfo_array",
"[",
"mx",
"]",
".",
"buf_ptr",
")",
",",
"minfo_array",
"[",
"mx",
"]",
".",
"buf_size",
",",
"minfo_array",
"[",
"mx",
"]",
".",
"set_val",
")",
";",
"if",
"(",
"minfo_array",
"[",
"mx",
"]",
".",
"this_buffer_freed",
")",
"{",
"printf",
"(",
"\"",
"\"",
")",
";",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"rseed",
")",
";",
"return",
";",
"}"
] | summarize(): Give a brief synopsis of the number of malloc() calls made,
free() calls made, total memory allocated. | [
"summarize",
"()",
":",
"Give",
"a",
"brief",
"synopsis",
"of",
"the",
"number",
"of",
"malloc",
"()",
"calls",
"made",
"free",
"()",
"calls",
"made",
"total",
"memory",
"allocated",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
a9328c8add803014c7c5be9f5f4fbe2ee57d9292 | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/tests/stress_test.c | [
"Apache-2.0"
] | C | cleanup | void | void
cleanup()
{
int mx;
#ifndef DARWINTEST
printf("Cleanup: Started.\n");
printf("Cleanup: Every allocated buffer should be free-able.\n");
#endif
for (mx = 0; mx < malloc_calls_made; mx++) {
if (!(minfo_array[mx].this_buffer_freed)) {
free(minfo_array[mx].buf_ptr);
if (signal_happened) {
#if DARWINTEST
T_FAIL("Signal %d occurred during free(0x%llx)", signal_happened, (unsigned long long)(minfo_array[mx].buf_ptr));
#else
printf("FAIL: Signal %d occurred during free(0x%llx)\n", signal_happened,
(unsigned long long)(minfo_array[mx].buf_ptr));
exit(1);
#endif
}
}
}
return;
} | /*
* When we hit an end condition, every allocated buffer should be free()-able.
*/ | When we hit an end condition, every allocated buffer should be free()-able. | [
"When",
"we",
"hit",
"an",
"end",
"condition",
"every",
"allocated",
"buffer",
"should",
"be",
"free",
"()",
"-",
"able",
"."
] | void
cleanup()
{
int mx;
#ifndef DARWINTEST
printf("Cleanup: Started.\n");
printf("Cleanup: Every allocated buffer should be free-able.\n");
#endif
for (mx = 0; mx < malloc_calls_made; mx++) {
if (!(minfo_array[mx].this_buffer_freed)) {
free(minfo_array[mx].buf_ptr);
if (signal_happened) {
#if DARWINTEST
T_FAIL("Signal %d occurred during free(0x%llx)", signal_happened, (unsigned long long)(minfo_array[mx].buf_ptr));
#else
printf("FAIL: Signal %d occurred during free(0x%llx)\n", signal_happened,
(unsigned long long)(minfo_array[mx].buf_ptr));
exit(1);
#endif
}
}
}
return;
} | [
"void",
"cleanup",
"(",
")",
"{",
"int",
"mx",
";",
"#ifndef",
"DARWINTEST",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"#endif",
"for",
"(",
"mx",
"=",
"0",
";",
"mx",
"<",
"malloc_calls_made",
";",
"mx",
"++",
")",
"{",
"if",
"(",
"!",
"(",
"minfo_array",
"[",
"mx",
"]",
".",
"this_buffer_freed",
")",
")",
"{",
"free",
"(",
"minfo_array",
"[",
"mx",
"]",
".",
"buf_ptr",
")",
";",
"if",
"(",
"signal_happened",
")",
"{",
"#if",
"DARWINTEST",
"\n",
"T_FAIL",
"(",
"\"",
"\"",
",",
"signal_happened",
",",
"(",
"unsigned",
"long",
"long",
")",
"(",
"minfo_array",
"[",
"mx",
"]",
".",
"buf_ptr",
")",
")",
";",
"#else",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"signal_happened",
",",
"(",
"unsigned",
"long",
"long",
")",
"(",
"minfo_array",
"[",
"mx",
"]",
".",
"buf_ptr",
")",
")",
";",
"exit",
"(",
"1",
")",
";",
"#endif",
"}",
"}",
"}",
"return",
";",
"}"
] | When we hit an end condition, every allocated buffer should be free()-able. | [
"When",
"we",
"hit",
"an",
"end",
"condition",
"every",
"allocated",
"buffer",
"should",
"be",
"free",
"()",
"-",
"able",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
a9328c8add803014c7c5be9f5f4fbe2ee57d9292 | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/tests/stress_test.c | [
"Apache-2.0"
] | C | check_overlap | int | int
check_overlap(void *p1, int len1, void *p2, int len2)
{
unsigned long long bob1, eob1, bob2, eob2;
/* make begin and end ptrs in an integer form for easier comparison */
bob1 = (unsigned long long)p1;
eob1 = bob1 + (unsigned long long)len1 - 1LL;
bob2 = (unsigned long long)p2;
eob2 = bob2 + (unsigned long long)len2 - 1LL;
/*
* The begin and end points of one buffer should not be contained
* between the begin and end points of the other buffer.
*/
if ((bob1 >= bob2 && bob1 <= eob2) || (eob1 >= bob2 && eob1 <= eob2) || (bob2 >= bob1 && bob2 <= eob1) ||
(eob2 >= bob1 && eob2 <= eob1)) {
#ifdef DARWINTEST
T_FAIL("Buffers overlap: Buffer 1 (0x%llx, %d bytes), Buffer 2 (0x%llx, %d bytes)", bob1, len1, bob2, len2);
#else
printf("FAIL: Buffers overlap: Buffer 1 (0x%llx, %d bytes), Buffer 2 (0x%llx, %d bytes)\n", bob1, len1, bob2, len2);
#endif
return 1; /* Indicate buffers overlap */
}
return 0; /* buffers do not overlap */
} | /*
* Take a ptr and size, and another ptr and size, and verify they do not
* overlap. Return 0 if they are disjoint, or 1 if they overlap.
*/ | Take a ptr and size, and another ptr and size, and verify they do not
overlap. Return 0 if they are disjoint, or 1 if they overlap. | [
"Take",
"a",
"ptr",
"and",
"size",
"and",
"another",
"ptr",
"and",
"size",
"and",
"verify",
"they",
"do",
"not",
"overlap",
".",
"Return",
"0",
"if",
"they",
"are",
"disjoint",
"or",
"1",
"if",
"they",
"overlap",
"."
] | int
check_overlap(void *p1, int len1, void *p2, int len2)
{
unsigned long long bob1, eob1, bob2, eob2;
bob1 = (unsigned long long)p1;
eob1 = bob1 + (unsigned long long)len1 - 1LL;
bob2 = (unsigned long long)p2;
eob2 = bob2 + (unsigned long long)len2 - 1LL;
if ((bob1 >= bob2 && bob1 <= eob2) || (eob1 >= bob2 && eob1 <= eob2) || (bob2 >= bob1 && bob2 <= eob1) ||
(eob2 >= bob1 && eob2 <= eob1)) {
#ifdef DARWINTEST
T_FAIL("Buffers overlap: Buffer 1 (0x%llx, %d bytes), Buffer 2 (0x%llx, %d bytes)", bob1, len1, bob2, len2);
#else
printf("FAIL: Buffers overlap: Buffer 1 (0x%llx, %d bytes), Buffer 2 (0x%llx, %d bytes)\n", bob1, len1, bob2, len2);
#endif
return 1;
}
return 0;
} | [
"int",
"check_overlap",
"(",
"void",
"*",
"p1",
",",
"int",
"len1",
",",
"void",
"*",
"p2",
",",
"int",
"len2",
")",
"{",
"unsigned",
"long",
"long",
"bob1",
",",
"eob1",
",",
"bob2",
",",
"eob2",
";",
"bob1",
"=",
"(",
"unsigned",
"long",
"long",
")",
"p1",
";",
"eob1",
"=",
"bob1",
"+",
"(",
"unsigned",
"long",
"long",
")",
"len1",
"-",
"1LL",
";",
"bob2",
"=",
"(",
"unsigned",
"long",
"long",
")",
"p2",
";",
"eob2",
"=",
"bob2",
"+",
"(",
"unsigned",
"long",
"long",
")",
"len2",
"-",
"1LL",
";",
"if",
"(",
"(",
"bob1",
">=",
"bob2",
"&&",
"bob1",
"<=",
"eob2",
")",
"||",
"(",
"eob1",
">=",
"bob2",
"&&",
"eob1",
"<=",
"eob2",
")",
"||",
"(",
"bob2",
">=",
"bob1",
"&&",
"bob2",
"<=",
"eob1",
")",
"||",
"(",
"eob2",
">=",
"bob1",
"&&",
"eob2",
"<=",
"eob1",
")",
")",
"{",
"#ifdef",
"DARWINTEST",
"T_FAIL",
"(",
"\"",
"\"",
",",
"bob1",
",",
"len1",
",",
"bob2",
",",
"len2",
")",
";",
"#else",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"bob1",
",",
"len1",
",",
"bob2",
",",
"len2",
")",
";",
"#endif",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}"
] | Take a ptr and size, and another ptr and size, and verify they do not
overlap. | [
"Take",
"a",
"ptr",
"and",
"size",
"and",
"another",
"ptr",
"and",
"size",
"and",
"verify",
"they",
"do",
"not",
"overlap",
"."
] | [
"/* make begin and end ptrs in an integer form for easier comparison */",
"/*\n\t * The begin and end points of one buffer should not be contained\n\t * between the begin and end points of the other buffer.\n\t */",
"/* Indicate buffers overlap */",
"/* buffers do not overlap */"
] | [
{
"param": "p1",
"type": "void"
},
{
"param": "len1",
"type": "int"
},
{
"param": "p2",
"type": "void"
},
{
"param": "len2",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "p1",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "len1",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "p2",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "len2",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
bfa12172acb88c6d600e6e22ea869c6c26b98e3f | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/src/magazine_tiny.c | [
"Apache-2.0"
] | C | tiny_free_list_add_ptr | void | static void
tiny_free_list_add_ptr(rack_t *rack, magazine_t *tiny_mag_ptr, void *ptr, msize_t msize)
{
grain_t slot = (!msize || (msize >= NUM_TINY_SLOTS)) ? NUM_TINY_SLOTS - 1 : msize - 1;
tiny_free_list_t *free_ptr = ptr;
tiny_free_list_t *free_head = tiny_mag_ptr->mag_free_list[slot].p;
#if DEBUG_MALLOC
if (LOG(szone, ptr)) {
malloc_report(ASL_LEVEL_INFO, "in %s, ptr=%p, msize=%d\n", __FUNCTION__, ptr, msize);
}
if (((uintptr_t)ptr) & (TINY_QUANTUM - 1)) {
malloc_zone_error(rack->debug_flags, true, "tiny_free_list_add_ptr: Unaligned ptr: %p\n", ptr);
}
#endif
set_tiny_meta_header_free(ptr, msize);
if (free_head) {
#if DEBUG_MALLOC
if (free_list_unchecksum_ptr(szone, &free_head->previous)) {
malloc_zone_error(rack->debug_flags, true,
"tiny_free_list_add_ptr: Internal invariant broken (free_head->previous): "
"ptr=%p slot=%d free_head=%p previous=%p\n", ptr, slot, (void *)free_head, free_head->previous.p);
}
if (!tiny_meta_header_is_free(free_head)) {
malloc_zone_error(rack->debug_flags, true,
"tiny_free_list_add_ptr: Internal invariant broken (free_head is not a free pointer): "
"ptr=%p slot=%d free_head=%p\n", ptr, slot, (void *)free_head);
}
#endif
free_head->previous.u = free_list_checksum_ptr(rack, free_ptr);
} else {
BITMAPV_SET(tiny_mag_ptr->mag_bitmap, slot);
}
free_ptr->previous.u = free_list_checksum_ptr(rack, NULL);
free_ptr->next.u = free_list_checksum_ptr(rack, free_head);
tiny_mag_ptr->mag_free_list[slot].p = free_ptr;
} | /*
* Adds an item to the proper free list, and also marks the meta-header of the
* block properly.
* Assumes szone has been locked
*/ | Adds an item to the proper free list, and also marks the meta-header of the
block properly.
Assumes szone has been locked | [
"Adds",
"an",
"item",
"to",
"the",
"proper",
"free",
"list",
"and",
"also",
"marks",
"the",
"meta",
"-",
"header",
"of",
"the",
"block",
"properly",
".",
"Assumes",
"szone",
"has",
"been",
"locked"
] | static void
tiny_free_list_add_ptr(rack_t *rack, magazine_t *tiny_mag_ptr, void *ptr, msize_t msize)
{
grain_t slot = (!msize || (msize >= NUM_TINY_SLOTS)) ? NUM_TINY_SLOTS - 1 : msize - 1;
tiny_free_list_t *free_ptr = ptr;
tiny_free_list_t *free_head = tiny_mag_ptr->mag_free_list[slot].p;
#if DEBUG_MALLOC
if (LOG(szone, ptr)) {
malloc_report(ASL_LEVEL_INFO, "in %s, ptr=%p, msize=%d\n", __FUNCTION__, ptr, msize);
}
if (((uintptr_t)ptr) & (TINY_QUANTUM - 1)) {
malloc_zone_error(rack->debug_flags, true, "tiny_free_list_add_ptr: Unaligned ptr: %p\n", ptr);
}
#endif
set_tiny_meta_header_free(ptr, msize);
if (free_head) {
#if DEBUG_MALLOC
if (free_list_unchecksum_ptr(szone, &free_head->previous)) {
malloc_zone_error(rack->debug_flags, true,
"tiny_free_list_add_ptr: Internal invariant broken (free_head->previous): "
"ptr=%p slot=%d free_head=%p previous=%p\n", ptr, slot, (void *)free_head, free_head->previous.p);
}
if (!tiny_meta_header_is_free(free_head)) {
malloc_zone_error(rack->debug_flags, true,
"tiny_free_list_add_ptr: Internal invariant broken (free_head is not a free pointer): "
"ptr=%p slot=%d free_head=%p\n", ptr, slot, (void *)free_head);
}
#endif
free_head->previous.u = free_list_checksum_ptr(rack, free_ptr);
} else {
BITMAPV_SET(tiny_mag_ptr->mag_bitmap, slot);
}
free_ptr->previous.u = free_list_checksum_ptr(rack, NULL);
free_ptr->next.u = free_list_checksum_ptr(rack, free_head);
tiny_mag_ptr->mag_free_list[slot].p = free_ptr;
} | [
"static",
"void",
"tiny_free_list_add_ptr",
"(",
"rack_t",
"*",
"rack",
",",
"magazine_t",
"*",
"tiny_mag_ptr",
",",
"void",
"*",
"ptr",
",",
"msize_t",
"msize",
")",
"{",
"grain_t",
"slot",
"=",
"(",
"!",
"msize",
"||",
"(",
"msize",
">=",
"NUM_TINY_SLOTS",
")",
")",
"?",
"NUM_TINY_SLOTS",
"-",
"1",
":",
"msize",
"-",
"1",
";",
"tiny_free_list_t",
"*",
"free_ptr",
"=",
"ptr",
";",
"tiny_free_list_t",
"*",
"free_head",
"=",
"tiny_mag_ptr",
"->",
"mag_free_list",
"[",
"slot",
"]",
".",
"p",
";",
"#if",
"DEBUG_MALLOC",
"\n",
"if",
"(",
"LOG",
"(",
"szone",
",",
"ptr",
")",
")",
"{",
"malloc_report",
"(",
"ASL_LEVEL_INFO",
",",
"\"",
"\\n",
"\"",
",",
"__FUNCTION__",
",",
"ptr",
",",
"msize",
")",
";",
"}",
"if",
"(",
"(",
"(",
"uintptr_t",
")",
"ptr",
")",
"&",
"(",
"TINY_QUANTUM",
"-",
"1",
")",
")",
"{",
"malloc_zone_error",
"(",
"rack",
"->",
"debug_flags",
",",
"true",
",",
"\"",
"\\n",
"\"",
",",
"ptr",
")",
";",
"}",
"#endif",
"set_tiny_meta_header_free",
"(",
"ptr",
",",
"msize",
")",
";",
"if",
"(",
"free_head",
")",
"{",
"#if",
"DEBUG_MALLOC",
"\n",
"if",
"(",
"free_list_unchecksum_ptr",
"(",
"szone",
",",
"&",
"free_head",
"->",
"previous",
")",
")",
"{",
"malloc_zone_error",
"(",
"rack",
"->",
"debug_flags",
",",
"true",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"ptr",
",",
"slot",
",",
"(",
"void",
"*",
")",
"free_head",
",",
"free_head",
"->",
"previous",
".",
"p",
")",
";",
"}",
"if",
"(",
"!",
"tiny_meta_header_is_free",
"(",
"free_head",
")",
")",
"{",
"malloc_zone_error",
"(",
"rack",
"->",
"debug_flags",
",",
"true",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"ptr",
",",
"slot",
",",
"(",
"void",
"*",
")",
"free_head",
")",
";",
"}",
"#endif",
"free_head",
"->",
"previous",
".",
"u",
"=",
"free_list_checksum_ptr",
"(",
"rack",
",",
"free_ptr",
")",
";",
"}",
"else",
"{",
"BITMAPV_SET",
"(",
"tiny_mag_ptr",
"->",
"mag_bitmap",
",",
"slot",
")",
";",
"}",
"free_ptr",
"->",
"previous",
".",
"u",
"=",
"free_list_checksum_ptr",
"(",
"rack",
",",
"NULL",
")",
";",
"free_ptr",
"->",
"next",
".",
"u",
"=",
"free_list_checksum_ptr",
"(",
"rack",
",",
"free_head",
")",
";",
"tiny_mag_ptr",
"->",
"mag_free_list",
"[",
"slot",
"]",
".",
"p",
"=",
"free_ptr",
";",
"}"
] | Adds an item to the proper free list, and also marks the meta-header of the
block properly. | [
"Adds",
"an",
"item",
"to",
"the",
"proper",
"free",
"list",
"and",
"also",
"marks",
"the",
"meta",
"-",
"header",
"of",
"the",
"block",
"properly",
"."
] | [] | [
{
"param": "rack",
"type": "rack_t"
},
{
"param": "tiny_mag_ptr",
"type": "magazine_t"
},
{
"param": "ptr",
"type": "void"
},
{
"param": "msize",
"type": "msize_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rack",
"type": "rack_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tiny_mag_ptr",
"type": "magazine_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ptr",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "msize",
"type": "msize_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
bfa12172acb88c6d600e6e22ea869c6c26b98e3f | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/src/magazine_tiny.c | [
"Apache-2.0"
] | C | tiny_free_list_remove_ptr | void | static void
tiny_free_list_remove_ptr(rack_t *rack, magazine_t *tiny_mag_ptr, void *ptr, msize_t msize)
{
grain_t slot = (!msize || (msize >= NUM_TINY_SLOTS)) ? NUM_TINY_SLOTS - 1 : msize - 1;
tiny_free_list_t *free_ptr = ptr, *next, *previous;
next = free_list_unchecksum_ptr(rack, &free_ptr->next);
previous = free_list_unchecksum_ptr(rack, &free_ptr->previous);
#if DEBUG_MALLOC
if (LOG(szone, ptr)) {
malloc_report(ASL_LEVEL_INFO, "In %s, ptr=%p, msize=%d\n", __FUNCTION__, ptr, msize);
}
#endif
if (!previous) {
// The block to remove is the head of the free list
#if DEBUG_MALLOC
if (tiny_mag_ptr->mag_free_list[slot] != ptr) {
malloc_zone_error(rack->debug_flags, true,
"tiny_free_list_remove_ptr: Internal invariant broken (tiny_mag_ptr->mag_free_list[slot]): "
"ptr=%p slot=%d msize=%d tiny_mag_ptr->mag_free_list[slot]=%p\n", ptr, slot, msize,
(void *)tiny_mag_ptr->mag_free_list[slot]);
return;
}
#endif
tiny_mag_ptr->mag_free_list[slot].p = next;
if (!next) {
BITMAPV_CLR(tiny_mag_ptr->mag_bitmap, slot);
}
} else {
// Check that the next pointer of "previous" points to free_ptr.
tiny_free_list_t *prev_next = free_list_unchecksum_ptr(rack, &previous->next);
if (prev_next != free_ptr) {
malloc_zone_error(rack->debug_flags, true,
"tiny_free_list_remove_ptr: Internal invariant broken (next ptr of prev): "
"ptr=%p, prev_next=%p\n", ptr, prev_next);
__builtin_unreachable(); // Always crashes in malloc_zone_error().
}
// We know free_ptr is already checksummed, so we don't need to do it
// again.
previous->next = free_ptr->next;
}
if (next) {
// Check that the previous pointer of "next" points to free_ptr.
tiny_free_list_t *next_prev = free_list_unchecksum_ptr(rack, &next->previous);
if (next_prev != free_ptr) {
malloc_zone_error(rack->debug_flags, true,
"tiny_free_list_remove_ptr: Internal invariant broken (prev ptr of next): "
"ptr=%p, next_prev=%p\n", ptr, next_prev);
__builtin_unreachable(); // Always crashes in malloc_zone_error().
}
// We know free_ptr is already checksummed, so we don't need to do it
// again.
next->previous = free_ptr->previous;
}
} | /*
* Removes the item pointed to by ptr in the proper free list.
* Assumes szone has been locked
*/ | Removes the item pointed to by ptr in the proper free list.
Assumes szone has been locked | [
"Removes",
"the",
"item",
"pointed",
"to",
"by",
"ptr",
"in",
"the",
"proper",
"free",
"list",
".",
"Assumes",
"szone",
"has",
"been",
"locked"
] | static void
tiny_free_list_remove_ptr(rack_t *rack, magazine_t *tiny_mag_ptr, void *ptr, msize_t msize)
{
grain_t slot = (!msize || (msize >= NUM_TINY_SLOTS)) ? NUM_TINY_SLOTS - 1 : msize - 1;
tiny_free_list_t *free_ptr = ptr, *next, *previous;
next = free_list_unchecksum_ptr(rack, &free_ptr->next);
previous = free_list_unchecksum_ptr(rack, &free_ptr->previous);
#if DEBUG_MALLOC
if (LOG(szone, ptr)) {
malloc_report(ASL_LEVEL_INFO, "In %s, ptr=%p, msize=%d\n", __FUNCTION__, ptr, msize);
}
#endif
if (!previous) {
#if DEBUG_MALLOC
if (tiny_mag_ptr->mag_free_list[slot] != ptr) {
malloc_zone_error(rack->debug_flags, true,
"tiny_free_list_remove_ptr: Internal invariant broken (tiny_mag_ptr->mag_free_list[slot]): "
"ptr=%p slot=%d msize=%d tiny_mag_ptr->mag_free_list[slot]=%p\n", ptr, slot, msize,
(void *)tiny_mag_ptr->mag_free_list[slot]);
return;
}
#endif
tiny_mag_ptr->mag_free_list[slot].p = next;
if (!next) {
BITMAPV_CLR(tiny_mag_ptr->mag_bitmap, slot);
}
} else {
tiny_free_list_t *prev_next = free_list_unchecksum_ptr(rack, &previous->next);
if (prev_next != free_ptr) {
malloc_zone_error(rack->debug_flags, true,
"tiny_free_list_remove_ptr: Internal invariant broken (next ptr of prev): "
"ptr=%p, prev_next=%p\n", ptr, prev_next);
__builtin_unreachable();
}
previous->next = free_ptr->next;
}
if (next) {
tiny_free_list_t *next_prev = free_list_unchecksum_ptr(rack, &next->previous);
if (next_prev != free_ptr) {
malloc_zone_error(rack->debug_flags, true,
"tiny_free_list_remove_ptr: Internal invariant broken (prev ptr of next): "
"ptr=%p, next_prev=%p\n", ptr, next_prev);
__builtin_unreachable();
}
next->previous = free_ptr->previous;
}
} | [
"static",
"void",
"tiny_free_list_remove_ptr",
"(",
"rack_t",
"*",
"rack",
",",
"magazine_t",
"*",
"tiny_mag_ptr",
",",
"void",
"*",
"ptr",
",",
"msize_t",
"msize",
")",
"{",
"grain_t",
"slot",
"=",
"(",
"!",
"msize",
"||",
"(",
"msize",
">=",
"NUM_TINY_SLOTS",
")",
")",
"?",
"NUM_TINY_SLOTS",
"-",
"1",
":",
"msize",
"-",
"1",
";",
"tiny_free_list_t",
"*",
"free_ptr",
"=",
"ptr",
",",
"*",
"next",
",",
"*",
"previous",
";",
"next",
"=",
"free_list_unchecksum_ptr",
"(",
"rack",
",",
"&",
"free_ptr",
"->",
"next",
")",
";",
"previous",
"=",
"free_list_unchecksum_ptr",
"(",
"rack",
",",
"&",
"free_ptr",
"->",
"previous",
")",
";",
"#if",
"DEBUG_MALLOC",
"\n",
"if",
"(",
"LOG",
"(",
"szone",
",",
"ptr",
")",
")",
"{",
"malloc_report",
"(",
"ASL_LEVEL_INFO",
",",
"\"",
"\\n",
"\"",
",",
"__FUNCTION__",
",",
"ptr",
",",
"msize",
")",
";",
"}",
"#endif",
"if",
"(",
"!",
"previous",
")",
"{",
"#if",
"DEBUG_MALLOC",
"\n",
"if",
"(",
"tiny_mag_ptr",
"->",
"mag_free_list",
"[",
"slot",
"]",
"!=",
"ptr",
")",
"{",
"malloc_zone_error",
"(",
"rack",
"->",
"debug_flags",
",",
"true",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"ptr",
",",
"slot",
",",
"msize",
",",
"(",
"void",
"*",
")",
"tiny_mag_ptr",
"->",
"mag_free_list",
"[",
"slot",
"]",
")",
";",
"return",
";",
"}",
"#endif",
"tiny_mag_ptr",
"->",
"mag_free_list",
"[",
"slot",
"]",
".",
"p",
"=",
"next",
";",
"if",
"(",
"!",
"next",
")",
"{",
"BITMAPV_CLR",
"(",
"tiny_mag_ptr",
"->",
"mag_bitmap",
",",
"slot",
")",
";",
"}",
"}",
"else",
"{",
"tiny_free_list_t",
"*",
"prev_next",
"=",
"free_list_unchecksum_ptr",
"(",
"rack",
",",
"&",
"previous",
"->",
"next",
")",
";",
"if",
"(",
"prev_next",
"!=",
"free_ptr",
")",
"{",
"malloc_zone_error",
"(",
"rack",
"->",
"debug_flags",
",",
"true",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"ptr",
",",
"prev_next",
")",
";",
"__builtin_unreachable",
"(",
")",
";",
"}",
"previous",
"->",
"next",
"=",
"free_ptr",
"->",
"next",
";",
"}",
"if",
"(",
"next",
")",
"{",
"tiny_free_list_t",
"*",
"next_prev",
"=",
"free_list_unchecksum_ptr",
"(",
"rack",
",",
"&",
"next",
"->",
"previous",
")",
";",
"if",
"(",
"next_prev",
"!=",
"free_ptr",
")",
"{",
"malloc_zone_error",
"(",
"rack",
"->",
"debug_flags",
",",
"true",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"ptr",
",",
"next_prev",
")",
";",
"__builtin_unreachable",
"(",
")",
";",
"}",
"next",
"->",
"previous",
"=",
"free_ptr",
"->",
"previous",
";",
"}",
"}"
] | Removes the item pointed to by ptr in the proper free list. | [
"Removes",
"the",
"item",
"pointed",
"to",
"by",
"ptr",
"in",
"the",
"proper",
"free",
"list",
"."
] | [
"// The block to remove is the head of the free list",
"// Check that the next pointer of \"previous\" points to free_ptr.",
"// Always crashes in malloc_zone_error().",
"// We know free_ptr is already checksummed, so we don't need to do it",
"// again.",
"// Check that the previous pointer of \"next\" points to free_ptr.",
"// Always crashes in malloc_zone_error().",
"// We know free_ptr is already checksummed, so we don't need to do it",
"// again."
] | [
{
"param": "rack",
"type": "rack_t"
},
{
"param": "tiny_mag_ptr",
"type": "magazine_t"
},
{
"param": "ptr",
"type": "void"
},
{
"param": "msize",
"type": "msize_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rack",
"type": "rack_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tiny_mag_ptr",
"type": "magazine_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ptr",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "msize",
"type": "msize_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
bfa12172acb88c6d600e6e22ea869c6c26b98e3f | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/src/magazine_tiny.c | [
"Apache-2.0"
] | C | tiny_malloc_from_region_no_lock | void | static void *
tiny_malloc_from_region_no_lock(rack_t *rack,
magazine_t *tiny_mag_ptr,
mag_index_t mag_index,
msize_t msize,
void *aligned_address)
{
void *ptr;
// Deal with unclaimed memory -- mag_bytes_free_at_end or mag_bytes_free_at_start
if (tiny_mag_ptr->mag_bytes_free_at_end || tiny_mag_ptr->mag_bytes_free_at_start) {
tiny_finalize_region(rack, tiny_mag_ptr);
}
// We set the unused bits of the header in the last pair to be all ones, and those of the inuse to zeroes.
#if NUM_TINY_BLOCKS & 31
const uint32_t header = 0xFFFFFFFFU << (NUM_TINY_BLOCKS & 31);
#else
const uint32_t header = 0;
#endif
((tiny_region_t)aligned_address)->pairs[CEIL_NUM_TINY_BLOCKS_WORDS - 1].header = header;
((tiny_region_t)aligned_address)->pairs[CEIL_NUM_TINY_BLOCKS_WORDS - 1].inuse = 0;
// Tag the region at "aligned_address" as belonging to us,
// and so put it under the protection of the magazine lock we are holding.
// Do this before advertising "aligned_address" on the hash ring(!)
MAGAZINE_INDEX_FOR_TINY_REGION(aligned_address) = mag_index;
// Insert the new region into the hash ring
rack_region_insert(rack, (region_t)aligned_address);
tiny_mag_ptr->mag_last_region = aligned_address;
BYTES_USED_FOR_TINY_REGION(aligned_address) = TINY_BYTES_FOR_MSIZE(msize);
#if CONFIG_ASLR_INTERNAL
int offset_msize = malloc_entropy[0] & TINY_ENTROPY_MASK;
#if DEBUG_MALLOC
if (getenv("MallocASLRForce")) {
offset_msize = strtol(getenv("MallocASLRForce"), NULL, 0) & TINY_ENTROPY_MASK;
}
if (getenv("MallocASLRPrint")) {
malloc_report(ASL_LEVEL_INFO, "Region: %p offset: %d\n", aligned_address, offset_msize);
}
#endif
#else
int offset_msize = 0;
#endif
ptr = (void *)((uintptr_t)aligned_address + TINY_BYTES_FOR_MSIZE(offset_msize));
set_tiny_meta_header_in_use(ptr, msize);
tiny_mag_ptr->mag_num_objects++;
tiny_mag_ptr->mag_num_bytes_in_objects += TINY_BYTES_FOR_MSIZE(msize);
tiny_mag_ptr->num_bytes_in_magazine += TINY_REGION_PAYLOAD_BYTES;
// We put a header on the last block so that it appears in use (for coalescing, etc...)
set_tiny_meta_header_in_use_1((void *)((uintptr_t)ptr + TINY_BYTES_FOR_MSIZE(msize)));
tiny_mag_ptr->mag_bytes_free_at_end = TINY_BYTES_FOR_MSIZE(NUM_TINY_BLOCKS - msize - offset_msize);
#if CONFIG_ASLR_INTERNAL
// Put a header on the previous block for same reason
tiny_mag_ptr->mag_bytes_free_at_start = TINY_BYTES_FOR_MSIZE(offset_msize);
if (offset_msize) {
set_tiny_meta_header_in_use_1((void *)((uintptr_t)ptr - TINY_QUANTUM));
}
#else
tiny_mag_ptr->mag_bytes_free_at_start = 0;
#endif
// connect to magazine as last node
recirc_list_splice_last(rack, tiny_mag_ptr, REGION_TRAILER_FOR_TINY_REGION(aligned_address));
#if DEBUG_MALLOC
if (LOG(szone, ptr)) {
malloc_report(ASL_LEVEL_INFO, "in tiny_malloc_from_region_no_lock(), ptr=%p, msize=%d\n", ptr, msize);
}
#endif
return ptr;
} | // Allocates from the last region or a freshly allocated region | Allocates from the last region or a freshly allocated region | [
"Allocates",
"from",
"the",
"last",
"region",
"or",
"a",
"freshly",
"allocated",
"region"
] | static void *
tiny_malloc_from_region_no_lock(rack_t *rack,
magazine_t *tiny_mag_ptr,
mag_index_t mag_index,
msize_t msize,
void *aligned_address)
{
void *ptr;
if (tiny_mag_ptr->mag_bytes_free_at_end || tiny_mag_ptr->mag_bytes_free_at_start) {
tiny_finalize_region(rack, tiny_mag_ptr);
}
#if NUM_TINY_BLOCKS & 31
const uint32_t header = 0xFFFFFFFFU << (NUM_TINY_BLOCKS & 31);
#else
const uint32_t header = 0;
#endif
((tiny_region_t)aligned_address)->pairs[CEIL_NUM_TINY_BLOCKS_WORDS - 1].header = header;
((tiny_region_t)aligned_address)->pairs[CEIL_NUM_TINY_BLOCKS_WORDS - 1].inuse = 0;
MAGAZINE_INDEX_FOR_TINY_REGION(aligned_address) = mag_index;
rack_region_insert(rack, (region_t)aligned_address);
tiny_mag_ptr->mag_last_region = aligned_address;
BYTES_USED_FOR_TINY_REGION(aligned_address) = TINY_BYTES_FOR_MSIZE(msize);
#if CONFIG_ASLR_INTERNAL
int offset_msize = malloc_entropy[0] & TINY_ENTROPY_MASK;
#if DEBUG_MALLOC
if (getenv("MallocASLRForce")) {
offset_msize = strtol(getenv("MallocASLRForce"), NULL, 0) & TINY_ENTROPY_MASK;
}
if (getenv("MallocASLRPrint")) {
malloc_report(ASL_LEVEL_INFO, "Region: %p offset: %d\n", aligned_address, offset_msize);
}
#endif
#else
int offset_msize = 0;
#endif
ptr = (void *)((uintptr_t)aligned_address + TINY_BYTES_FOR_MSIZE(offset_msize));
set_tiny_meta_header_in_use(ptr, msize);
tiny_mag_ptr->mag_num_objects++;
tiny_mag_ptr->mag_num_bytes_in_objects += TINY_BYTES_FOR_MSIZE(msize);
tiny_mag_ptr->num_bytes_in_magazine += TINY_REGION_PAYLOAD_BYTES;
set_tiny_meta_header_in_use_1((void *)((uintptr_t)ptr + TINY_BYTES_FOR_MSIZE(msize)));
tiny_mag_ptr->mag_bytes_free_at_end = TINY_BYTES_FOR_MSIZE(NUM_TINY_BLOCKS - msize - offset_msize);
#if CONFIG_ASLR_INTERNAL
tiny_mag_ptr->mag_bytes_free_at_start = TINY_BYTES_FOR_MSIZE(offset_msize);
if (offset_msize) {
set_tiny_meta_header_in_use_1((void *)((uintptr_t)ptr - TINY_QUANTUM));
}
#else
tiny_mag_ptr->mag_bytes_free_at_start = 0;
#endif
recirc_list_splice_last(rack, tiny_mag_ptr, REGION_TRAILER_FOR_TINY_REGION(aligned_address));
#if DEBUG_MALLOC
if (LOG(szone, ptr)) {
malloc_report(ASL_LEVEL_INFO, "in tiny_malloc_from_region_no_lock(), ptr=%p, msize=%d\n", ptr, msize);
}
#endif
return ptr;
} | [
"static",
"void",
"*",
"tiny_malloc_from_region_no_lock",
"(",
"rack_t",
"*",
"rack",
",",
"magazine_t",
"*",
"tiny_mag_ptr",
",",
"mag_index_t",
"mag_index",
",",
"msize_t",
"msize",
",",
"void",
"*",
"aligned_address",
")",
"{",
"void",
"*",
"ptr",
";",
"if",
"(",
"tiny_mag_ptr",
"->",
"mag_bytes_free_at_end",
"||",
"tiny_mag_ptr",
"->",
"mag_bytes_free_at_start",
")",
"{",
"tiny_finalize_region",
"(",
"rack",
",",
"tiny_mag_ptr",
")",
";",
"}",
"#if",
"NUM_TINY_BLOCKS",
"&",
"31",
"\n",
"const",
"uint32_t",
"header",
"=",
"0xFFFFFFFFU",
"<<",
"(",
"NUM_TINY_BLOCKS",
"&",
"31",
")",
";",
"#else",
"const",
"uint32_t",
"header",
"=",
"0",
";",
"#endif",
"(",
"(",
"tiny_region_t",
")",
"aligned_address",
")",
"->",
"pairs",
"[",
"CEIL_NUM_TINY_BLOCKS_WORDS",
"-",
"1",
"]",
".",
"header",
"=",
"header",
";",
"(",
"(",
"tiny_region_t",
")",
"aligned_address",
")",
"->",
"pairs",
"[",
"CEIL_NUM_TINY_BLOCKS_WORDS",
"-",
"1",
"]",
".",
"inuse",
"=",
"0",
";",
"MAGAZINE_INDEX_FOR_TINY_REGION",
"(",
"aligned_address",
")",
"=",
"mag_index",
";",
"rack_region_insert",
"(",
"rack",
",",
"(",
"region_t",
")",
"aligned_address",
")",
";",
"tiny_mag_ptr",
"->",
"mag_last_region",
"=",
"aligned_address",
";",
"BYTES_USED_FOR_TINY_REGION",
"(",
"aligned_address",
")",
"=",
"TINY_BYTES_FOR_MSIZE",
"(",
"msize",
")",
";",
"#if",
"CONFIG_ASLR_INTERNAL",
"\n",
"int",
"offset_msize",
"=",
"malloc_entropy",
"[",
"0",
"]",
"&",
"TINY_ENTROPY_MASK",
";",
"#if",
"DEBUG_MALLOC",
"\n",
"if",
"(",
"getenv",
"(",
"\"",
"\"",
")",
")",
"{",
"offset_msize",
"=",
"strtol",
"(",
"getenv",
"(",
"\"",
"\"",
")",
",",
"NULL",
",",
"0",
")",
"&",
"TINY_ENTROPY_MASK",
";",
"}",
"if",
"(",
"getenv",
"(",
"\"",
"\"",
")",
")",
"{",
"malloc_report",
"(",
"ASL_LEVEL_INFO",
",",
"\"",
"\\n",
"\"",
",",
"aligned_address",
",",
"offset_msize",
")",
";",
"}",
"#endif",
"#else",
"int",
"offset_msize",
"=",
"0",
";",
"#endif",
"ptr",
"=",
"(",
"void",
"*",
")",
"(",
"(",
"uintptr_t",
")",
"aligned_address",
"+",
"TINY_BYTES_FOR_MSIZE",
"(",
"offset_msize",
")",
")",
";",
"set_tiny_meta_header_in_use",
"(",
"ptr",
",",
"msize",
")",
";",
"tiny_mag_ptr",
"->",
"mag_num_objects",
"++",
";",
"tiny_mag_ptr",
"->",
"mag_num_bytes_in_objects",
"+=",
"TINY_BYTES_FOR_MSIZE",
"(",
"msize",
")",
";",
"tiny_mag_ptr",
"->",
"num_bytes_in_magazine",
"+=",
"TINY_REGION_PAYLOAD_BYTES",
";",
"set_tiny_meta_header_in_use_1",
"(",
"(",
"void",
"*",
")",
"(",
"(",
"uintptr_t",
")",
"ptr",
"+",
"TINY_BYTES_FOR_MSIZE",
"(",
"msize",
")",
")",
")",
";",
"tiny_mag_ptr",
"->",
"mag_bytes_free_at_end",
"=",
"TINY_BYTES_FOR_MSIZE",
"(",
"NUM_TINY_BLOCKS",
"-",
"msize",
"-",
"offset_msize",
")",
";",
"#if",
"CONFIG_ASLR_INTERNAL",
"\n",
"tiny_mag_ptr",
"->",
"mag_bytes_free_at_start",
"=",
"TINY_BYTES_FOR_MSIZE",
"(",
"offset_msize",
")",
";",
"if",
"(",
"offset_msize",
")",
"{",
"set_tiny_meta_header_in_use_1",
"(",
"(",
"void",
"*",
")",
"(",
"(",
"uintptr_t",
")",
"ptr",
"-",
"TINY_QUANTUM",
")",
")",
";",
"}",
"#else",
"tiny_mag_ptr",
"->",
"mag_bytes_free_at_start",
"=",
"0",
";",
"#endif",
"recirc_list_splice_last",
"(",
"rack",
",",
"tiny_mag_ptr",
",",
"REGION_TRAILER_FOR_TINY_REGION",
"(",
"aligned_address",
")",
")",
";",
"#if",
"DEBUG_MALLOC",
"\n",
"if",
"(",
"LOG",
"(",
"szone",
",",
"ptr",
")",
")",
"{",
"malloc_report",
"(",
"ASL_LEVEL_INFO",
",",
"\"",
"\\n",
"\"",
",",
"ptr",
",",
"msize",
")",
";",
"}",
"#endif",
"return",
"ptr",
";",
"}"
] | Allocates from the last region or a freshly allocated region | [
"Allocates",
"from",
"the",
"last",
"region",
"or",
"a",
"freshly",
"allocated",
"region"
] | [
"// Deal with unclaimed memory -- mag_bytes_free_at_end or mag_bytes_free_at_start",
"// We set the unused bits of the header in the last pair to be all ones, and those of the inuse to zeroes.",
"// Tag the region at \"aligned_address\" as belonging to us,",
"// and so put it under the protection of the magazine lock we are holding.",
"// Do this before advertising \"aligned_address\" on the hash ring(!)",
"// Insert the new region into the hash ring",
"// We put a header on the last block so that it appears in use (for coalescing, etc...)",
"// Put a header on the previous block for same reason",
"// connect to magazine as last node"
] | [
{
"param": "rack",
"type": "rack_t"
},
{
"param": "tiny_mag_ptr",
"type": "magazine_t"
},
{
"param": "mag_index",
"type": "mag_index_t"
},
{
"param": "msize",
"type": "msize_t"
},
{
"param": "aligned_address",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rack",
"type": "rack_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tiny_mag_ptr",
"type": "magazine_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "mag_index",
"type": "mag_index_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "msize",
"type": "msize_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "aligned_address",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f528200df1299b705077294bf6843f2779910f5b | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/src/magazine_lite.c | [
"Apache-2.0"
] | C | stack_logging_lite_realloc | void | static void *
stack_logging_lite_realloc(malloc_zone_t *zone, void *ptr, size_t new_size)
{
szone_t *szone = (szone_t *) zone;
void *new_ptr = NULL;
size_t old_size = szone_size(szone, ptr);
// if we own the ptr and lite enabled do our thing
if (old_size && stack_logging_lite_enabled) {
// need to get the old stackid and decrement
malloc_stack_id stack_id = get_stack_id_from_ptr(ptr, old_size);
new_ptr = szone_realloc(szone, ptr, new_size + sizeof(malloc_stack_id));
if (new_ptr) {
__decrement_table_slot_refcount(stack_id, old_size);
add_stack_to_ptr(szone, new_size, new_ptr);
}
} else if (!old_size && !stack_logging_lite_enabled) {
// we don't own the pointer and lite mode is disabled, so just pass the realloc on to the helper zone
return szone->helper_zone->basic_zone.realloc((malloc_zone_t *) szone->helper_zone, ptr, new_size);
} else {
// otherwise perform the realloc by hand:
// 1. malloc new ptr
// 2. copy existing data to new ptr
// 3. free old ptr
// this will add the stack id if needed
new_ptr = stack_logging_lite_malloc(zone, new_size);
if (new_ptr) {
size_t old_size = malloc_size(ptr);
size_t new_size = malloc_size(new_ptr);
// copy as much old data as possible
size_t copy_size = MIN(old_size, new_size);
memcpy(new_ptr, ptr, copy_size);
}
stack_logging_lite_free(zone, ptr);
}
return new_ptr;
} | // Three paths:
// 1. do a szone_realloc with padding and add stack id
// 2. do a szone_realloc on the helper zone
// 3. do a manual free / malloc | Three paths:
1. do a szone_realloc with padding and add stack id
2. do a szone_realloc on the helper zone
3. do a manual free / malloc | [
"Three",
"paths",
":",
"1",
".",
"do",
"a",
"szone_realloc",
"with",
"padding",
"and",
"add",
"stack",
"id",
"2",
".",
"do",
"a",
"szone_realloc",
"on",
"the",
"helper",
"zone",
"3",
".",
"do",
"a",
"manual",
"free",
"/",
"malloc"
] | static void *
stack_logging_lite_realloc(malloc_zone_t *zone, void *ptr, size_t new_size)
{
szone_t *szone = (szone_t *) zone;
void *new_ptr = NULL;
size_t old_size = szone_size(szone, ptr);
if (old_size && stack_logging_lite_enabled) {
malloc_stack_id stack_id = get_stack_id_from_ptr(ptr, old_size);
new_ptr = szone_realloc(szone, ptr, new_size + sizeof(malloc_stack_id));
if (new_ptr) {
__decrement_table_slot_refcount(stack_id, old_size);
add_stack_to_ptr(szone, new_size, new_ptr);
}
} else if (!old_size && !stack_logging_lite_enabled) {
return szone->helper_zone->basic_zone.realloc((malloc_zone_t *) szone->helper_zone, ptr, new_size);
} else {
new_ptr = stack_logging_lite_malloc(zone, new_size);
if (new_ptr) {
size_t old_size = malloc_size(ptr);
size_t new_size = malloc_size(new_ptr);
size_t copy_size = MIN(old_size, new_size);
memcpy(new_ptr, ptr, copy_size);
}
stack_logging_lite_free(zone, ptr);
}
return new_ptr;
} | [
"static",
"void",
"*",
"stack_logging_lite_realloc",
"(",
"malloc_zone_t",
"*",
"zone",
",",
"void",
"*",
"ptr",
",",
"size_t",
"new_size",
")",
"{",
"szone_t",
"*",
"szone",
"=",
"(",
"szone_t",
"*",
")",
"zone",
";",
"void",
"*",
"new_ptr",
"=",
"NULL",
";",
"size_t",
"old_size",
"=",
"szone_size",
"(",
"szone",
",",
"ptr",
")",
";",
"if",
"(",
"old_size",
"&&",
"stack_logging_lite_enabled",
")",
"{",
"malloc_stack_id",
"stack_id",
"=",
"get_stack_id_from_ptr",
"(",
"ptr",
",",
"old_size",
")",
";",
"new_ptr",
"=",
"szone_realloc",
"(",
"szone",
",",
"ptr",
",",
"new_size",
"+",
"sizeof",
"(",
"malloc_stack_id",
")",
")",
";",
"if",
"(",
"new_ptr",
")",
"{",
"__decrement_table_slot_refcount",
"(",
"stack_id",
",",
"old_size",
")",
";",
"add_stack_to_ptr",
"(",
"szone",
",",
"new_size",
",",
"new_ptr",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"old_size",
"&&",
"!",
"stack_logging_lite_enabled",
")",
"{",
"return",
"szone",
"->",
"helper_zone",
"->",
"basic_zone",
".",
"realloc",
"(",
"(",
"malloc_zone_t",
"*",
")",
"szone",
"->",
"helper_zone",
",",
"ptr",
",",
"new_size",
")",
";",
"}",
"else",
"{",
"new_ptr",
"=",
"stack_logging_lite_malloc",
"(",
"zone",
",",
"new_size",
")",
";",
"if",
"(",
"new_ptr",
")",
"{",
"size_t",
"old_size",
"=",
"malloc_size",
"(",
"ptr",
")",
";",
"size_t",
"new_size",
"=",
"malloc_size",
"(",
"new_ptr",
")",
";",
"size_t",
"copy_size",
"=",
"MIN",
"(",
"old_size",
",",
"new_size",
")",
";",
"memcpy",
"(",
"new_ptr",
",",
"ptr",
",",
"copy_size",
")",
";",
"}",
"stack_logging_lite_free",
"(",
"zone",
",",
"ptr",
")",
";",
"}",
"return",
"new_ptr",
";",
"}"
] | Three paths:
1. do a szone_realloc with padding and add stack id
2. do a szone_realloc on the helper zone
3. do a manual free / malloc | [
"Three",
"paths",
":",
"1",
".",
"do",
"a",
"szone_realloc",
"with",
"padding",
"and",
"add",
"stack",
"id",
"2",
".",
"do",
"a",
"szone_realloc",
"on",
"the",
"helper",
"zone",
"3",
".",
"do",
"a",
"manual",
"free",
"/",
"malloc"
] | [
"// if we own the ptr and lite enabled do our thing",
"// need to get the old stackid and decrement",
"// we don't own the pointer and lite mode is disabled, so just pass the realloc on to the helper zone",
"// otherwise perform the realloc by hand:",
"// 1. malloc new ptr",
"// 2. copy existing data to new ptr",
"// 3. free old ptr",
"// this will add the stack id if needed",
"// copy as much old data as possible"
] | [
{
"param": "zone",
"type": "malloc_zone_t"
},
{
"param": "ptr",
"type": "void"
},
{
"param": "new_size",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "zone",
"type": "malloc_zone_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ptr",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "new_size",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
be1ae6183dd072926e48d8a2077a1c9fa9733d2d | miniLV/MNAlertView | InterView-obj-isa-class/libmalloc-166.220.1/src/frozen_malloc.c | [
"Apache-2.0"
] | C | malloc_freezedry | uintptr_t | uintptr_t
malloc_freezedry(void)
{
extern unsigned malloc_num_zones;
extern malloc_zone_t **malloc_zones;
malloc_frozen *data;
unsigned i;
/* Allocate space in which to store the freezedry state. */
data = (malloc_frozen *)malloc(sizeof(malloc_frozen));
/* Set freezedry version number so that malloc_jumpstart() can check for compatibility. */
data->version = MALLOC_FREEZEDRY_VERSION;
/* Allocate the array of szone pointers. */
data->nszones = malloc_num_zones;
data->szones = (szone_t *)calloc(malloc_num_zones, sizeof(szone_t));
/*
* Fill in the array of szone structures. They are copied rather than
* referenced, since the originals are likely to be clobbered during malloc
* initialization.
*/
for (i = 0; i < malloc_num_zones; i++) {
if (strcmp(malloc_zones[i]->zone_name, "DefaultMallocZone")) {
/* Unknown zone type. */
free(data->szones);
free(data);
return 0;
}
memcpy(&data->szones[i], malloc_zones[i], sizeof(szone_t));
}
return ((uintptr_t)data);
} | /*
* malloc_freezedry() records all of the szones in use, so that they can be
* partially reconstituted by malloc_jumpstart(). Due to the differences
* between reconstituted memory regions and those created by the szone code,
* care is taken not to reallocate from the freezedried memory, except in the
* case of a non-growing realloc().
*
* Due to the flexibility provided by the zone registration mechanism, it is
* impossible to implement generic freezedrying for any zone type. This code
* only handles applications that use the szone allocator, so malloc_freezedry()
* returns 0 (error) if any non-szone zones are encountered.
*/ | malloc_freezedry() records all of the szones in use, so that they can be
partially reconstituted by malloc_jumpstart(). Due to the differences
between reconstituted memory regions and those created by the szone code,
care is taken not to reallocate from the freezedried memory, except in the
case of a non-growing realloc().
Due to the flexibility provided by the zone registration mechanism, it is
impossible to implement generic freezedrying for any zone type. This code
only handles applications that use the szone allocator, so malloc_freezedry()
returns 0 (error) if any non-szone zones are encountered. | [
"malloc_freezedry",
"()",
"records",
"all",
"of",
"the",
"szones",
"in",
"use",
"so",
"that",
"they",
"can",
"be",
"partially",
"reconstituted",
"by",
"malloc_jumpstart",
"()",
".",
"Due",
"to",
"the",
"differences",
"between",
"reconstituted",
"memory",
"regions",
"and",
"those",
"created",
"by",
"the",
"szone",
"code",
"care",
"is",
"taken",
"not",
"to",
"reallocate",
"from",
"the",
"freezedried",
"memory",
"except",
"in",
"the",
"case",
"of",
"a",
"non",
"-",
"growing",
"realloc",
"()",
".",
"Due",
"to",
"the",
"flexibility",
"provided",
"by",
"the",
"zone",
"registration",
"mechanism",
"it",
"is",
"impossible",
"to",
"implement",
"generic",
"freezedrying",
"for",
"any",
"zone",
"type",
".",
"This",
"code",
"only",
"handles",
"applications",
"that",
"use",
"the",
"szone",
"allocator",
"so",
"malloc_freezedry",
"()",
"returns",
"0",
"(",
"error",
")",
"if",
"any",
"non",
"-",
"szone",
"zones",
"are",
"encountered",
"."
] | uintptr_t
malloc_freezedry(void)
{
extern unsigned malloc_num_zones;
extern malloc_zone_t **malloc_zones;
malloc_frozen *data;
unsigned i;
data = (malloc_frozen *)malloc(sizeof(malloc_frozen));
data->version = MALLOC_FREEZEDRY_VERSION;
data->nszones = malloc_num_zones;
data->szones = (szone_t *)calloc(malloc_num_zones, sizeof(szone_t));
for (i = 0; i < malloc_num_zones; i++) {
if (strcmp(malloc_zones[i]->zone_name, "DefaultMallocZone")) {
free(data->szones);
free(data);
return 0;
}
memcpy(&data->szones[i], malloc_zones[i], sizeof(szone_t));
}
return ((uintptr_t)data);
} | [
"uintptr_t",
"malloc_freezedry",
"(",
"void",
")",
"{",
"extern",
"unsigned",
"malloc_num_zones",
";",
"extern",
"malloc_zone_t",
"*",
"*",
"malloc_zones",
";",
"malloc_frozen",
"*",
"data",
";",
"unsigned",
"i",
";",
"data",
"=",
"(",
"malloc_frozen",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"malloc_frozen",
")",
")",
";",
"data",
"->",
"version",
"=",
"MALLOC_FREEZEDRY_VERSION",
";",
"data",
"->",
"nszones",
"=",
"malloc_num_zones",
";",
"data",
"->",
"szones",
"=",
"(",
"szone_t",
"*",
")",
"calloc",
"(",
"malloc_num_zones",
",",
"sizeof",
"(",
"szone_t",
")",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"malloc_num_zones",
";",
"i",
"++",
")",
"{",
"if",
"(",
"strcmp",
"(",
"malloc_zones",
"[",
"i",
"]",
"->",
"zone_name",
",",
"\"",
"\"",
")",
")",
"{",
"free",
"(",
"data",
"->",
"szones",
")",
";",
"free",
"(",
"data",
")",
";",
"return",
"0",
";",
"}",
"memcpy",
"(",
"&",
"data",
"->",
"szones",
"[",
"i",
"]",
",",
"malloc_zones",
"[",
"i",
"]",
",",
"sizeof",
"(",
"szone_t",
")",
")",
";",
"}",
"return",
"(",
"(",
"uintptr_t",
")",
"data",
")",
";",
"}"
] | malloc_freezedry() records all of the szones in use, so that they can be
partially reconstituted by malloc_jumpstart(). | [
"malloc_freezedry",
"()",
"records",
"all",
"of",
"the",
"szones",
"in",
"use",
"so",
"that",
"they",
"can",
"be",
"partially",
"reconstituted",
"by",
"malloc_jumpstart",
"()",
"."
] | [
"/* Allocate space in which to store the freezedry state. */",
"/* Set freezedry version number so that malloc_jumpstart() can check for compatibility. */",
"/* Allocate the array of szone pointers. */",
"/*\n\t * Fill in the array of szone structures. They are copied rather than\n\t * referenced, since the originals are likely to be clobbered during malloc\n\t * initialization.\n\t */",
"/* Unknown zone type. */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
5a7852299cde10af096f6001cad1e98ae62897fb | catensia/SP_Project | sp20161634_proj4/Phase3/myshell.c | [
"MIT"
] | C | eval | void | void eval(char *cmdline)
{
char *argv[MAXARGS]; /* Argument list execve() */
char buf[MAXLINE]; /* Holds modified command line */
int bg; /* Should the job run in bg or fg? */
int fds[2];
int argn;
char carg[MAXLINE];
MEMSET(carg);
int job_fd[2], in_fd, out_fd;
int p;
if(p=pipe(job_fd)){
printf("pipe error\n");
exit(0);
}
if((p=pipe(fds))==-1){
printf("pipe error\n");
exit(0);
}
strcpy(buf, cmdline);
bg = parseline(buf, argv);
argn=argnum(argv); //calculate argnum
if (argv[0] == NULL) {
return; /* Ignore empty lines */
}
if (!builtin_command(argv)) {
Sigprocmask(SIG_BLOCK, &mask_one, &prev_one); //Blocks SIGCHLD
if (!bg){
int status;
//Temporarily blocks child process signals since foreground jobs must end before receiving commands
cur_pid=Fork();
Sigprocmask(SIG_SETMASK, &prev_one, NULL);
switch(cur_pid){
case -1: PERROR_EXIT("FORK ERROR\n");
case 0:
tcsetpgrp(0, getpgrp());
printf("NOTBG) pid:%d pgid:%d\n", getpid(), getpgrp());
pipe_execute(0, argv, STDIN_FILENO, argn, 0);
}
wait(&status); //should wait for foreground process to terminate
}
else{
cur_pid=Fork();
Sigprocmask(SIG_SETMASK, &prev_one, NULL);
setpgid(0,0);
int pid;
switch(cur_pid){
case -1: PERROR_EXIT("FORK ERROR\n");
case 0:
pid=getpid();
printf("FORK: %d\n", pid);
Write(job_fd[1], &pid, sizeof(pid));
pipe_execute(0, argv, STDIN_FILENO, argn, 0);
exit(0);
}
}
Sigprocmask(SIG_BLOCK, &mask_all, NULL);
int job_pid;
Read(job_fd[0], &job_pid, sizeof(job_pid));
struct job new_job;
new_job.pid=job_pid;
strcpy(new_job.cmd, cmdline);
new_job.status=1;
add_job(new_job);
close(job_fd[0]);
close(job_fd[1]);
Sigprocmask(SIG_SETMASK, &prev_one, NULL);
}
return;
} | /* $begin eval */
/* eval - Evaluate a command line */ | $begin eval
eval - Evaluate a command line | [
"$begin",
"eval",
"eval",
"-",
"Evaluate",
"a",
"command",
"line"
] | void eval(char *cmdline)
{
char *argv[MAXARGS];
char buf[MAXLINE];
int bg;
int fds[2];
int argn;
char carg[MAXLINE];
MEMSET(carg);
int job_fd[2], in_fd, out_fd;
int p;
if(p=pipe(job_fd)){
printf("pipe error\n");
exit(0);
}
if((p=pipe(fds))==-1){
printf("pipe error\n");
exit(0);
}
strcpy(buf, cmdline);
bg = parseline(buf, argv);
argn=argnum(argv);
if (argv[0] == NULL) {
return;
}
if (!builtin_command(argv)) {
Sigprocmask(SIG_BLOCK, &mask_one, &prev_one);
if (!bg){
int status;
cur_pid=Fork();
Sigprocmask(SIG_SETMASK, &prev_one, NULL);
switch(cur_pid){
case -1: PERROR_EXIT("FORK ERROR\n");
case 0:
tcsetpgrp(0, getpgrp());
printf("NOTBG) pid:%d pgid:%d\n", getpid(), getpgrp());
pipe_execute(0, argv, STDIN_FILENO, argn, 0);
}
wait(&status);
}
else{
cur_pid=Fork();
Sigprocmask(SIG_SETMASK, &prev_one, NULL);
setpgid(0,0);
int pid;
switch(cur_pid){
case -1: PERROR_EXIT("FORK ERROR\n");
case 0:
pid=getpid();
printf("FORK: %d\n", pid);
Write(job_fd[1], &pid, sizeof(pid));
pipe_execute(0, argv, STDIN_FILENO, argn, 0);
exit(0);
}
}
Sigprocmask(SIG_BLOCK, &mask_all, NULL);
int job_pid;
Read(job_fd[0], &job_pid, sizeof(job_pid));
struct job new_job;
new_job.pid=job_pid;
strcpy(new_job.cmd, cmdline);
new_job.status=1;
add_job(new_job);
close(job_fd[0]);
close(job_fd[1]);
Sigprocmask(SIG_SETMASK, &prev_one, NULL);
}
return;
} | [
"void",
"eval",
"(",
"char",
"*",
"cmdline",
")",
"{",
"char",
"*",
"argv",
"[",
"MAXARGS",
"]",
";",
"char",
"buf",
"[",
"MAXLINE",
"]",
";",
"int",
"bg",
";",
"int",
"fds",
"[",
"2",
"]",
";",
"int",
"argn",
";",
"char",
"carg",
"[",
"MAXLINE",
"]",
";",
"MEMSET",
"(",
"carg",
")",
";",
"int",
"job_fd",
"[",
"2",
"]",
",",
"in_fd",
",",
"out_fd",
";",
"int",
"p",
";",
"if",
"(",
"p",
"=",
"pipe",
"(",
"job_fd",
")",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"exit",
"(",
"0",
")",
";",
"}",
"if",
"(",
"(",
"p",
"=",
"pipe",
"(",
"fds",
")",
")",
"==",
"-1",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"exit",
"(",
"0",
")",
";",
"}",
"strcpy",
"(",
"buf",
",",
"cmdline",
")",
";",
"bg",
"=",
"parseline",
"(",
"buf",
",",
"argv",
")",
";",
"argn",
"=",
"argnum",
"(",
"argv",
")",
";",
"if",
"(",
"argv",
"[",
"0",
"]",
"==",
"NULL",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"builtin_command",
"(",
"argv",
")",
")",
"{",
"Sigprocmask",
"(",
"SIG_BLOCK",
",",
"&",
"mask_one",
",",
"&",
"prev_one",
")",
";",
"if",
"(",
"!",
"bg",
")",
"{",
"int",
"status",
";",
"cur_pid",
"=",
"Fork",
"(",
")",
";",
"Sigprocmask",
"(",
"SIG_SETMASK",
",",
"&",
"prev_one",
",",
"NULL",
")",
";",
"switch",
"(",
"cur_pid",
")",
"{",
"case",
"-1",
":",
"PERROR_EXIT",
"(",
"\"",
"\\n",
"\"",
")",
";",
"case",
"0",
":",
"tcsetpgrp",
"(",
"0",
",",
"getpgrp",
"(",
")",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"getpid",
"(",
")",
",",
"getpgrp",
"(",
")",
")",
";",
"pipe_execute",
"(",
"0",
",",
"argv",
",",
"STDIN_FILENO",
",",
"argn",
",",
"0",
")",
";",
"}",
"wait",
"(",
"&",
"status",
")",
";",
"}",
"else",
"{",
"cur_pid",
"=",
"Fork",
"(",
")",
";",
"Sigprocmask",
"(",
"SIG_SETMASK",
",",
"&",
"prev_one",
",",
"NULL",
")",
";",
"setpgid",
"(",
"0",
",",
"0",
")",
";",
"int",
"pid",
";",
"switch",
"(",
"cur_pid",
")",
"{",
"case",
"-1",
":",
"PERROR_EXIT",
"(",
"\"",
"\\n",
"\"",
")",
";",
"case",
"0",
":",
"pid",
"=",
"getpid",
"(",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"pid",
")",
";",
"Write",
"(",
"job_fd",
"[",
"1",
"]",
",",
"&",
"pid",
",",
"sizeof",
"(",
"pid",
")",
")",
";",
"pipe_execute",
"(",
"0",
",",
"argv",
",",
"STDIN_FILENO",
",",
"argn",
",",
"0",
")",
";",
"exit",
"(",
"0",
")",
";",
"}",
"}",
"Sigprocmask",
"(",
"SIG_BLOCK",
",",
"&",
"mask_all",
",",
"NULL",
")",
";",
"int",
"job_pid",
";",
"Read",
"(",
"job_fd",
"[",
"0",
"]",
",",
"&",
"job_pid",
",",
"sizeof",
"(",
"job_pid",
")",
")",
";",
"struct",
"job",
"new_job",
";",
"new_job",
".",
"pid",
"=",
"job_pid",
";",
"strcpy",
"(",
"new_job",
".",
"cmd",
",",
"cmdline",
")",
";",
"new_job",
".",
"status",
"=",
"1",
";",
"add_job",
"(",
"new_job",
")",
";",
"close",
"(",
"job_fd",
"[",
"0",
"]",
")",
";",
"close",
"(",
"job_fd",
"[",
"1",
"]",
")",
";",
"Sigprocmask",
"(",
"SIG_SETMASK",
",",
"&",
"prev_one",
",",
"NULL",
")",
";",
"}",
"return",
";",
"}"
] | $begin eval
eval - Evaluate a command line | [
"$begin",
"eval",
"eval",
"-",
"Evaluate",
"a",
"command",
"line"
] | [
"/* Argument list execve() */",
"/* Holds modified command line */",
"/* Should the job run in bg or fg? */",
"//calculate argnum",
"/* Ignore empty lines */",
"//Blocks SIGCHLD",
"//Temporarily blocks child process signals since foreground jobs must end before receiving commands",
"//should wait for foreground process to terminate "
] | [
{
"param": "cmdline",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cmdline",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5a7852299cde10af096f6001cad1e98ae62897fb | catensia/SP_Project | sp20161634_proj4/Phase3/myshell.c | [
"MIT"
] | C | builtin_command | int | int builtin_command(char **argv)
{
if(!strcmp(argv[0], "jobs")){ /* jobs command */
Sigprocmask(SIG_BLOCK, &mask_one, &prev_one);
print_jobs();
Sigprocmask(SIG_SETMASK, &prev_one, NULL);
return 1;
}
if (!strcmp(argv[0], "quit")) /* quit command */
exit(0);
if(!strcmp(argv[0], "exit")) /* exit command */
exit(0);
if (!strcmp(argv[0], "&")) /* Ignore singleton & */
return 1;
if (!strcmp(argv[0], "cd")){
int chdir_ret;
//only cd
if(argv[1]==NULL){
if((chdir_ret=chdir(getenv("HOME")))==-1){
printf("cd home error\n");
}
return 1;
}
//cd .. cd SP/proj4/
if((chdir_ret=chdir(argv[1]))==-1){
printf("cd error\n");
}
return 1;
}
return 0; /* Not a builtin command */
} | /* If first arg is a builtin command, run it and return true */ | If first arg is a builtin command, run it and return true | [
"If",
"first",
"arg",
"is",
"a",
"builtin",
"command",
"run",
"it",
"and",
"return",
"true"
] | int builtin_command(char **argv)
{
if(!strcmp(argv[0], "jobs")){
Sigprocmask(SIG_BLOCK, &mask_one, &prev_one);
print_jobs();
Sigprocmask(SIG_SETMASK, &prev_one, NULL);
return 1;
}
if (!strcmp(argv[0], "quit"))
exit(0);
if(!strcmp(argv[0], "exit"))
exit(0);
if (!strcmp(argv[0], "&"))
return 1;
if (!strcmp(argv[0], "cd")){
int chdir_ret;
if(argv[1]==NULL){
if((chdir_ret=chdir(getenv("HOME")))==-1){
printf("cd home error\n");
}
return 1;
}
if((chdir_ret=chdir(argv[1]))==-1){
printf("cd error\n");
}
return 1;
}
return 0;
} | [
"int",
"builtin_command",
"(",
"char",
"*",
"*",
"argv",
")",
"{",
"if",
"(",
"!",
"strcmp",
"(",
"argv",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
")",
"{",
"Sigprocmask",
"(",
"SIG_BLOCK",
",",
"&",
"mask_one",
",",
"&",
"prev_one",
")",
";",
"print_jobs",
"(",
")",
";",
"Sigprocmask",
"(",
"SIG_SETMASK",
",",
"&",
"prev_one",
",",
"NULL",
")",
";",
"return",
"1",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"argv",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
")",
"exit",
"(",
"0",
")",
";",
"if",
"(",
"!",
"strcmp",
"(",
"argv",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
")",
"exit",
"(",
"0",
")",
";",
"if",
"(",
"!",
"strcmp",
"(",
"argv",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
")",
"return",
"1",
";",
"if",
"(",
"!",
"strcmp",
"(",
"argv",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
")",
"{",
"int",
"chdir_ret",
";",
"if",
"(",
"argv",
"[",
"1",
"]",
"==",
"NULL",
")",
"{",
"if",
"(",
"(",
"chdir_ret",
"=",
"chdir",
"(",
"getenv",
"(",
"\"",
"\"",
")",
")",
")",
"==",
"-1",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"return",
"1",
";",
"}",
"if",
"(",
"(",
"chdir_ret",
"=",
"chdir",
"(",
"argv",
"[",
"1",
"]",
")",
")",
"==",
"-1",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}"
] | If first arg is a builtin command, run it and return true | [
"If",
"first",
"arg",
"is",
"a",
"builtin",
"command",
"run",
"it",
"and",
"return",
"true"
] | [
"/* jobs command */",
"/* quit command */",
"/* exit command */",
"/* Ignore singleton & */",
"//only cd",
"//cd .. cd SP/proj4/",
"/* Not a builtin command */"
] | [
{
"param": "argv",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "argv",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5a7852299cde10af096f6001cad1e98ae62897fb | catensia/SP_Project | sp20161634_proj4/Phase3/myshell.c | [
"MIT"
] | C | parseline | int | int parseline(char *buf, char **argv)
{
char *delim; /* Points to first space delimiter */
int argc; /* Number of args */
int bg; /* Background job? */
buf[strlen(buf)-1] = ' '; /* Replace trailing '\n' with space */
while (*buf && (*buf == ' ')) /* Ignore leading spaces */
buf++;
/* Build the argv list */
argc = 0;
while ((delim = strchr(buf, ' '))) {
argv[argc++] = buf;
*delim = '\0';
buf = delim + 1;
while (*buf && (*buf == ' ')) /* Ignore spaces */
buf++;
}
argv[argc] = NULL;
if (argc == 0) /* Ignore blank line */
return 1;
/* Should the job run in the background? */
if ((bg = (*argv[argc-1] == '&')) != 0)
argv[--argc] = NULL;
if(argc>0){
int lastlen=(int)strlen(argv[argc-1]);
if(argc>=1 && argv[argc-1][lastlen-1]=='&'){
bg=1;
argv[argc-1][lastlen-1]='\0';
}
}
return bg;
} | /* $begin parseline */
/* parseline - Parse the command line and build the argv array */ | $begin parseline
parseline - Parse the command line and build the argv array | [
"$begin",
"parseline",
"parseline",
"-",
"Parse",
"the",
"command",
"line",
"and",
"build",
"the",
"argv",
"array"
] | int parseline(char *buf, char **argv)
{
char *delim;
int argc;
int bg;
buf[strlen(buf)-1] = ' ';
while (*buf && (*buf == ' '))
buf++;
argc = 0;
while ((delim = strchr(buf, ' '))) {
argv[argc++] = buf;
*delim = '\0';
buf = delim + 1;
while (*buf && (*buf == ' '))
buf++;
}
argv[argc] = NULL;
if (argc == 0)
return 1;
if ((bg = (*argv[argc-1] == '&')) != 0)
argv[--argc] = NULL;
if(argc>0){
int lastlen=(int)strlen(argv[argc-1]);
if(argc>=1 && argv[argc-1][lastlen-1]=='&'){
bg=1;
argv[argc-1][lastlen-1]='\0';
}
}
return bg;
} | [
"int",
"parseline",
"(",
"char",
"*",
"buf",
",",
"char",
"*",
"*",
"argv",
")",
"{",
"char",
"*",
"delim",
";",
"int",
"argc",
";",
"int",
"bg",
";",
"buf",
"[",
"strlen",
"(",
"buf",
")",
"-",
"1",
"]",
"=",
"'",
"'",
";",
"while",
"(",
"*",
"buf",
"&&",
"(",
"*",
"buf",
"==",
"'",
"'",
")",
")",
"buf",
"++",
";",
"argc",
"=",
"0",
";",
"while",
"(",
"(",
"delim",
"=",
"strchr",
"(",
"buf",
",",
"'",
"'",
")",
")",
")",
"{",
"argv",
"[",
"argc",
"++",
"]",
"=",
"buf",
";",
"*",
"delim",
"=",
"'",
"\\0",
"'",
";",
"buf",
"=",
"delim",
"+",
"1",
";",
"while",
"(",
"*",
"buf",
"&&",
"(",
"*",
"buf",
"==",
"'",
"'",
")",
")",
"buf",
"++",
";",
"}",
"argv",
"[",
"argc",
"]",
"=",
"NULL",
";",
"if",
"(",
"argc",
"==",
"0",
")",
"return",
"1",
";",
"if",
"(",
"(",
"bg",
"=",
"(",
"*",
"argv",
"[",
"argc",
"-",
"1",
"]",
"==",
"'",
"'",
")",
")",
"!=",
"0",
")",
"argv",
"[",
"--",
"argc",
"]",
"=",
"NULL",
";",
"if",
"(",
"argc",
">",
"0",
")",
"{",
"int",
"lastlen",
"=",
"(",
"int",
")",
"strlen",
"(",
"argv",
"[",
"argc",
"-",
"1",
"]",
")",
";",
"if",
"(",
"argc",
">=",
"1",
"&&",
"argv",
"[",
"argc",
"-",
"1",
"]",
"[",
"lastlen",
"-",
"1",
"]",
"==",
"'",
"'",
")",
"{",
"bg",
"=",
"1",
";",
"argv",
"[",
"argc",
"-",
"1",
"]",
"[",
"lastlen",
"-",
"1",
"]",
"=",
"'",
"\\0",
"'",
";",
"}",
"}",
"return",
"bg",
";",
"}"
] | $begin parseline
parseline - Parse the command line and build the argv array | [
"$begin",
"parseline",
"parseline",
"-",
"Parse",
"the",
"command",
"line",
"and",
"build",
"the",
"argv",
"array"
] | [
"/* Points to first space delimiter */",
"/* Number of args */",
"/* Background job? */",
"/* Replace trailing '\\n' with space */",
"/* Ignore leading spaces */",
"/* Build the argv list */",
"/* Ignore spaces */",
"/* Ignore blank line */",
"/* Should the job run in the background? */"
] | [
{
"param": "buf",
"type": "char"
},
{
"param": "argv",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "buf",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "argv",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6a6edbc5ea021a1c71d0bbe9634b5fdde515ba3a | catensia/SP_Project | sp20161634_proj3/shell_cmd.c | [
"MIT"
] | C | trim | char | char* trim(char *cmd){
//trims leading and trailing spaces
while(isspace(*cmd))cmd++;
if(*cmd==0) return cmd;
int end=strlen(cmd)-1;
while(isspace(cmd[end])){
end--;
}
cmd[end+1]='\0';
return cmd;
} | /*---------------------------------------------------------------------*/
/*Function: trim*/
/*Purpose: removes leading and trailing spaces in string*/
/*Return: char pointer of trimmed string*/
/*---------------------------------------------------------------------*/ | trim
Purpose: removes leading and trailing spaces in string
Return: char pointer of trimmed string | [
"trim",
"Purpose",
":",
"removes",
"leading",
"and",
"trailing",
"spaces",
"in",
"string",
"Return",
":",
"char",
"pointer",
"of",
"trimmed",
"string"
] | char* trim(char *cmd){
while(isspace(*cmd))cmd++;
if(*cmd==0) return cmd;
int end=strlen(cmd)-1;
while(isspace(cmd[end])){
end--;
}
cmd[end+1]='\0';
return cmd;
} | [
"char",
"*",
"trim",
"(",
"char",
"*",
"cmd",
")",
"{",
"while",
"(",
"isspace",
"(",
"*",
"cmd",
")",
")",
"cmd",
"++",
";",
"if",
"(",
"*",
"cmd",
"==",
"0",
")",
"return",
"cmd",
";",
"int",
"end",
"=",
"strlen",
"(",
"cmd",
")",
"-",
"1",
";",
"while",
"(",
"isspace",
"(",
"cmd",
"[",
"end",
"]",
")",
")",
"{",
"end",
"--",
";",
"}",
"cmd",
"[",
"end",
"+",
"1",
"]",
"=",
"'",
"\\0",
"'",
";",
"return",
"cmd",
";",
"}"
] | Function: trim
Purpose: removes leading and trailing spaces in string
Return: char pointer of trimmed string | [
"Function",
":",
"trim",
"Purpose",
":",
"removes",
"leading",
"and",
"trailing",
"spaces",
"in",
"string",
"Return",
":",
"char",
"pointer",
"of",
"trimmed",
"string"
] | [
"//trims leading and trailing spaces"
] | [
{
"param": "cmd",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cmd",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6a6edbc5ea021a1c71d0bbe9634b5fdde515ba3a | catensia/SP_Project | sp20161634_proj3/shell_cmd.c | [
"MIT"
] | C | checkExe | bool | bool checkExe(const char *name){
struct stat sb;
if (stat(name, &sb) == 0 && sb.st_mode & S_IXUSR){
/* executable */
return true;
}
else return false;
} | /*---------------------------------------------------------------------*/
/*Function: checkExe*/
/*Purpose: checks if given file name is executable*/
/*Return: true if executable, false if not executable */
/*---------------------------------------------------------------------*/ | checkExe
Purpose: checks if given file name is executable
Return: true if executable, false if not executable | [
"checkExe",
"Purpose",
":",
"checks",
"if",
"given",
"file",
"name",
"is",
"executable",
"Return",
":",
"true",
"if",
"executable",
"false",
"if",
"not",
"executable"
] | bool checkExe(const char *name){
struct stat sb;
if (stat(name, &sb) == 0 && sb.st_mode & S_IXUSR){
return true;
}
else return false;
} | [
"bool",
"checkExe",
"(",
"const",
"char",
"*",
"name",
")",
"{",
"struct",
"stat",
"sb",
";",
"if",
"(",
"stat",
"(",
"name",
",",
"&",
"sb",
")",
"==",
"0",
"&&",
"sb",
".",
"st_mode",
"&",
"S_IXUSR",
")",
"{",
"return",
"true",
";",
"}",
"else",
"return",
"false",
";",
"}"
] | Function: checkExe
Purpose: checks if given file name is executable
Return: true if executable, false if not executable | [
"Function",
":",
"checkExe",
"Purpose",
":",
"checks",
"if",
"given",
"file",
"name",
"is",
"executable",
"Return",
":",
"true",
"if",
"executable",
"false",
"if",
"not",
"executable"
] | [
"/* executable */"
] | [
{
"param": "name",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "name",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6a6edbc5ea021a1c71d0bbe9634b5fdde515ba3a | catensia/SP_Project | sp20161634_proj3/shell_cmd.c | [
"MIT"
] | C | checkDir | bool | bool checkDir(const char* name){
//checks if given file name is a directory
struct stat status;
stat(name,&status);
return S_ISDIR(status.st_mode);
} | /*---------------------------------------------------------------------*/
/*Function: checkDir*/
/*Purpose: checks if given file name is directory*/
/*Return: true if directory / false if not directory */
/*---------------------------------------------------------------------*/ | checkDir
Purpose: checks if given file name is directory
Return: true if directory / false if not directory | [
"checkDir",
"Purpose",
":",
"checks",
"if",
"given",
"file",
"name",
"is",
"directory",
"Return",
":",
"true",
"if",
"directory",
"/",
"false",
"if",
"not",
"directory"
] | bool checkDir(const char* name){
struct stat status;
stat(name,&status);
return S_ISDIR(status.st_mode);
} | [
"bool",
"checkDir",
"(",
"const",
"char",
"*",
"name",
")",
"{",
"struct",
"stat",
"status",
";",
"stat",
"(",
"name",
",",
"&",
"status",
")",
";",
"return",
"S_ISDIR",
"(",
"status",
".",
"st_mode",
")",
";",
"}"
] | Function: checkDir
Purpose: checks if given file name is directory
Return: true if directory / false if not directory | [
"Function",
":",
"checkDir",
"Purpose",
":",
"checks",
"if",
"given",
"file",
"name",
"is",
"directory",
"Return",
":",
"true",
"if",
"directory",
"/",
"false",
"if",
"not",
"directory"
] | [
"//checks if given file name is a directory"
] | [
{
"param": "name",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "name",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6a6edbc5ea021a1c71d0bbe9634b5fdde515ba3a | catensia/SP_Project | sp20161634_proj3/shell_cmd.c | [
"MIT"
] | C | shell_help | void | void shell_help(void){
printf("h[elp]\n");
printf("d[ir]\n");
printf("q[uit]\n");
printf("du[mp] [start, end]\n");
printf("e[dit] address, value\n");
printf("f[ill] start, end, value\n");
printf("reset\n");
printf("opcode mnemonic\n");
printf("opcodelist\n");
printf("assemble filename\n");
printf("type filename\n");
printf("symbol\n");
} | /*---------------------------------------------------------------------*/
/*Function: shell_help*/
/*Purpose: Print available commands*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | shell_help
Purpose: Print available commands
Return: none | [
"shell_help",
"Purpose",
":",
"Print",
"available",
"commands",
"Return",
":",
"none"
] | void shell_help(void){
printf("h[elp]\n");
printf("d[ir]\n");
printf("q[uit]\n");
printf("du[mp] [start, end]\n");
printf("e[dit] address, value\n");
printf("f[ill] start, end, value\n");
printf("reset\n");
printf("opcode mnemonic\n");
printf("opcodelist\n");
printf("assemble filename\n");
printf("type filename\n");
printf("symbol\n");
} | [
"void",
"shell_help",
"(",
"void",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}"
] | Function: shell_help
Purpose: Print available commands
Return: none | [
"Function",
":",
"shell_help",
"Purpose",
":",
"Print",
"available",
"commands",
"Return",
":",
"none"
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
6a6edbc5ea021a1c71d0bbe9634b5fdde515ba3a | catensia/SP_Project | sp20161634_proj3/shell_cmd.c | [
"MIT"
] | C | shell_dir | void | void shell_dir(void){
DIR *dir_i=opendir(".");
struct dirent *dir_e;
if(dir_i!=NULL){
while((dir_e=readdir(dir_i))){
char filename[100];
//copy file name
strcpy(filename, dir_e->d_name);
int len=strlen(filename);
//check if execution file (.out)
if(checkExe(dir_e->d_name)){
filename[len]='*';
filename[len+1]='\0';
}
//check if directory
if(checkDir(dir_e->d_name)){
filename[len]='/';
filename[len+1]='\0';
}
printf("%s\n", filename);
}
}
closedir(dir_i);
} | /*---------------------------------------------------------------------*/
/*Function: shell_dir*/
/*Purpose: prints files/directories in current directory*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | shell_dir
Purpose: prints files/directories in current directory
Return: none | [
"shell_dir",
"Purpose",
":",
"prints",
"files",
"/",
"directories",
"in",
"current",
"directory",
"Return",
":",
"none"
] | void shell_dir(void){
DIR *dir_i=opendir(".");
struct dirent *dir_e;
if(dir_i!=NULL){
while((dir_e=readdir(dir_i))){
char filename[100];
strcpy(filename, dir_e->d_name);
int len=strlen(filename);
if(checkExe(dir_e->d_name)){
filename[len]='*';
filename[len+1]='\0';
}
if(checkDir(dir_e->d_name)){
filename[len]='/';
filename[len+1]='\0';
}
printf("%s\n", filename);
}
}
closedir(dir_i);
} | [
"void",
"shell_dir",
"(",
"void",
")",
"{",
"DIR",
"*",
"dir_i",
"=",
"opendir",
"(",
"\"",
"\"",
")",
";",
"struct",
"dirent",
"*",
"dir_e",
";",
"if",
"(",
"dir_i",
"!=",
"NULL",
")",
"{",
"while",
"(",
"(",
"dir_e",
"=",
"readdir",
"(",
"dir_i",
")",
")",
")",
"{",
"char",
"filename",
"[",
"100",
"]",
";",
"strcpy",
"(",
"filename",
",",
"dir_e",
"->",
"d_name",
")",
";",
"int",
"len",
"=",
"strlen",
"(",
"filename",
")",
";",
"if",
"(",
"checkExe",
"(",
"dir_e",
"->",
"d_name",
")",
")",
"{",
"filename",
"[",
"len",
"]",
"=",
"'",
"'",
";",
"filename",
"[",
"len",
"+",
"1",
"]",
"=",
"'",
"\\0",
"'",
";",
"}",
"if",
"(",
"checkDir",
"(",
"dir_e",
"->",
"d_name",
")",
")",
"{",
"filename",
"[",
"len",
"]",
"=",
"'",
"'",
";",
"filename",
"[",
"len",
"+",
"1",
"]",
"=",
"'",
"\\0",
"'",
";",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"filename",
")",
";",
"}",
"}",
"closedir",
"(",
"dir_i",
")",
";",
"}"
] | Function: shell_dir
Purpose: prints files/directories in current directory
Return: none | [
"Function",
":",
"shell_dir",
"Purpose",
":",
"prints",
"files",
"/",
"directories",
"in",
"current",
"directory",
"Return",
":",
"none"
] | [
"//copy file name",
"//check if execution file (.out)",
"//check if directory"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
6a6edbc5ea021a1c71d0bbe9634b5fdde515ba3a | catensia/SP_Project | sp20161634_proj3/shell_cmd.c | [
"MIT"
] | C | history_add | void | void history_add(char* command, struct NODE **head){
struct NODE *newNode=(struct NODE*)malloc(sizeof(struct NODE));
strcpy(newNode->cmd, command);
newNode->next=NULL;
struct NODE *cur;
if(*head==NULL){
*head=newNode; return;
}
else{
for(cur=(*head);cur->next!=NULL;cur=cur->next){}
cur->next=newNode;
}
} | /*---------------------------------------------------------------------*/
/*Function: history_add*/
/*Purpose: adds command to history linked list*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | history_add
Purpose: adds command to history linked list
Return: none | [
"history_add",
"Purpose",
":",
"adds",
"command",
"to",
"history",
"linked",
"list",
"Return",
":",
"none"
] | void history_add(char* command, struct NODE **head){
struct NODE *newNode=(struct NODE*)malloc(sizeof(struct NODE));
strcpy(newNode->cmd, command);
newNode->next=NULL;
struct NODE *cur;
if(*head==NULL){
*head=newNode; return;
}
else{
for(cur=(*head);cur->next!=NULL;cur=cur->next){}
cur->next=newNode;
}
} | [
"void",
"history_add",
"(",
"char",
"*",
"command",
",",
"struct",
"NODE",
"*",
"*",
"head",
")",
"{",
"struct",
"NODE",
"*",
"newNode",
"=",
"(",
"struct",
"NODE",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"struct",
"NODE",
")",
")",
";",
"strcpy",
"(",
"newNode",
"->",
"cmd",
",",
"command",
")",
";",
"newNode",
"->",
"next",
"=",
"NULL",
";",
"struct",
"NODE",
"*",
"cur",
";",
"if",
"(",
"*",
"head",
"==",
"NULL",
")",
"{",
"*",
"head",
"=",
"newNode",
";",
"return",
";",
"}",
"else",
"{",
"for",
"(",
"cur",
"=",
"(",
"*",
"head",
")",
";",
"cur",
"->",
"next",
"!=",
"NULL",
";",
"cur",
"=",
"cur",
"->",
"next",
")",
"{",
"}",
"cur",
"->",
"next",
"=",
"newNode",
";",
"}",
"}"
] | Function: history_add
Purpose: adds command to history linked list
Return: none | [
"Function",
":",
"history_add",
"Purpose",
":",
"adds",
"command",
"to",
"history",
"linked",
"list",
"Return",
":",
"none"
] | [] | [
{
"param": "command",
"type": "char"
},
{
"param": "head",
"type": "struct NODE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "command",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "head",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6a6edbc5ea021a1c71d0bbe9634b5fdde515ba3a | catensia/SP_Project | sp20161634_proj3/shell_cmd.c | [
"MIT"
] | C | history_print | void | void history_print(struct NODE **head){
if(*head==NULL) return;
//prints contents of linked list
int cnt=1;
for(struct NODE *cur=(*head);cur!=NULL;cur=cur->next, cnt++){
printf("%d %s\n", cnt, cur->cmd);
}
} | /*---------------------------------------------------------------------*/
/*Function: history_print*/
/*Purpose: prints contents of linked list */
/*Return: none*/
/*---------------------------------------------------------------------*/ | history_print
Purpose: prints contents of linked list
Return: none | [
"history_print",
"Purpose",
":",
"prints",
"contents",
"of",
"linked",
"list",
"Return",
":",
"none"
] | void history_print(struct NODE **head){
if(*head==NULL) return;
int cnt=1;
for(struct NODE *cur=(*head);cur!=NULL;cur=cur->next, cnt++){
printf("%d %s\n", cnt, cur->cmd);
}
} | [
"void",
"history_print",
"(",
"struct",
"NODE",
"*",
"*",
"head",
")",
"{",
"if",
"(",
"*",
"head",
"==",
"NULL",
")",
"return",
";",
"int",
"cnt",
"=",
"1",
";",
"for",
"(",
"struct",
"NODE",
"*",
"cur",
"=",
"(",
"*",
"head",
")",
";",
"cur",
"!=",
"NULL",
";",
"cur",
"=",
"cur",
"->",
"next",
",",
"cnt",
"++",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"cnt",
",",
"cur",
"->",
"cmd",
")",
";",
"}",
"}"
] | Function: history_print
Purpose: prints contents of linked list
Return: none | [
"Function",
":",
"history_print",
"Purpose",
":",
"prints",
"contents",
"of",
"linked",
"list",
"Return",
":",
"none"
] | [
"//prints contents of linked list"
] | [
{
"param": "head",
"type": "struct NODE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "head",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6a6edbc5ea021a1c71d0bbe9634b5fdde515ba3a | catensia/SP_Project | sp20161634_proj3/shell_cmd.c | [
"MIT"
] | C | type_filename | void | void type_filename(const char *filename, struct NODE **head){
if(checkDir(filename)) {
printf("%s is a directory. Abort\n", filename); return;
}
FILE *fp;
if((fp=fopen(filename, "r"))){
char content=fgetc(fp);
while(content!=EOF){
printf("%c", content);
content=fgetc(fp);
}
printf("\n");
fclose(fp);
char history_string[100];
sprintf(history_string, "type %s", filename);
history_add(history_string, head);
return;
}
printf("File doesn't exist\n"); return;
} | /*---------------------------------------------------------------------*/
/*Function: type_filename*/
/*Purpose: prints contents of file*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | type_filename
Purpose: prints contents of file
Return: none | [
"type_filename",
"Purpose",
":",
"prints",
"contents",
"of",
"file",
"Return",
":",
"none"
] | void type_filename(const char *filename, struct NODE **head){
if(checkDir(filename)) {
printf("%s is a directory. Abort\n", filename); return;
}
FILE *fp;
if((fp=fopen(filename, "r"))){
char content=fgetc(fp);
while(content!=EOF){
printf("%c", content);
content=fgetc(fp);
}
printf("\n");
fclose(fp);
char history_string[100];
sprintf(history_string, "type %s", filename);
history_add(history_string, head);
return;
}
printf("File doesn't exist\n"); return;
} | [
"void",
"type_filename",
"(",
"const",
"char",
"*",
"filename",
",",
"struct",
"NODE",
"*",
"*",
"head",
")",
"{",
"if",
"(",
"checkDir",
"(",
"filename",
")",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"filename",
")",
";",
"return",
";",
"}",
"FILE",
"*",
"fp",
";",
"if",
"(",
"(",
"fp",
"=",
"fopen",
"(",
"filename",
",",
"\"",
"\"",
")",
")",
")",
"{",
"char",
"content",
"=",
"fgetc",
"(",
"fp",
")",
";",
"while",
"(",
"content",
"!=",
"EOF",
")",
"{",
"printf",
"(",
"\"",
"\"",
",",
"content",
")",
";",
"content",
"=",
"fgetc",
"(",
"fp",
")",
";",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"fclose",
"(",
"fp",
")",
";",
"char",
"history_string",
"[",
"100",
"]",
";",
"sprintf",
"(",
"history_string",
",",
"\"",
"\"",
",",
"filename",
")",
";",
"history_add",
"(",
"history_string",
",",
"head",
")",
";",
"return",
";",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"return",
";",
"}"
] | Function: type_filename
Purpose: prints contents of file
Return: none | [
"Function",
":",
"type_filename",
"Purpose",
":",
"prints",
"contents",
"of",
"file",
"Return",
":",
"none"
] | [] | [
{
"param": "filename",
"type": "char"
},
{
"param": "head",
"type": "struct NODE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "filename",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "head",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6a6edbc5ea021a1c71d0bbe9634b5fdde515ba3a | catensia/SP_Project | sp20161634_proj3/shell_cmd.c | [
"MIT"
] | C | symtab_print | void | void symtab_print(struct NODE **head){
if(*head==NULL) return;
for(struct NODE *cur=(*head);cur!=NULL;cur=cur->next){
printf("\t%s\t%04X\n", cur->cmd, cur->num);
}
} | /*---------------------------------------------------------------------*/
/*Function: symbol_print*/
/*Purpose: prints symbol table in lexicographical order*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | symbol_print
Purpose: prints symbol table in lexicographical order
Return: none | [
"symbol_print",
"Purpose",
":",
"prints",
"symbol",
"table",
"in",
"lexicographical",
"order",
"Return",
":",
"none"
] | void symtab_print(struct NODE **head){
if(*head==NULL) return;
for(struct NODE *cur=(*head);cur!=NULL;cur=cur->next){
printf("\t%s\t%04X\n", cur->cmd, cur->num);
}
} | [
"void",
"symtab_print",
"(",
"struct",
"NODE",
"*",
"*",
"head",
")",
"{",
"if",
"(",
"*",
"head",
"==",
"NULL",
")",
"return",
";",
"for",
"(",
"struct",
"NODE",
"*",
"cur",
"=",
"(",
"*",
"head",
")",
";",
"cur",
"!=",
"NULL",
";",
"cur",
"=",
"cur",
"->",
"next",
")",
"{",
"printf",
"(",
"\"",
"\\t",
"\\t",
"\\n",
"\"",
",",
"cur",
"->",
"cmd",
",",
"cur",
"->",
"num",
")",
";",
"}",
"}"
] | Function: symbol_print
Purpose: prints symbol table in lexicographical order
Return: none | [
"Function",
":",
"symbol_print",
"Purpose",
":",
"prints",
"symbol",
"table",
"in",
"lexicographical",
"order",
"Return",
":",
"none"
] | [] | [
{
"param": "head",
"type": "struct NODE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "head",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
83445ef8bf8e300ebe2efcd3e6d1a5d452be124d | catensia/SP_Project | sp20161634_proj3/20161634.c | [
"MIT"
] | C | hex | int | int hex(const char* num){
if(strlen(num)==0) return -1;
for(int i=0;i<strlen(num);i++){
if(!((num[i]>='0' && num[i]<='9') || (num[i]>='a' && num[i]<='f') || (num[i]>='A' && num[i]<='F'))){
return -1;
}
}
int ret;
sscanf(num, "%x", &ret);
return ret;
} | /*---------------------------------------------------------------------*/
/*Function: hex*/
/*Purpose: reads a hexadecimal string and returns positive decimal value*/
/*Return value: if invalid -1 / if valid positive decimal value*/
/*---------------------------------------------------------------------*/ | hex
Purpose: reads a hexadecimal string and returns positive decimal value
Return value: if invalid -1 / if valid positive decimal value | [
"hex",
"Purpose",
":",
"reads",
"a",
"hexadecimal",
"string",
"and",
"returns",
"positive",
"decimal",
"value",
"Return",
"value",
":",
"if",
"invalid",
"-",
"1",
"/",
"if",
"valid",
"positive",
"decimal",
"value"
] | int hex(const char* num){
if(strlen(num)==0) return -1;
for(int i=0;i<strlen(num);i++){
if(!((num[i]>='0' && num[i]<='9') || (num[i]>='a' && num[i]<='f') || (num[i]>='A' && num[i]<='F'))){
return -1;
}
}
int ret;
sscanf(num, "%x", &ret);
return ret;
} | [
"int",
"hex",
"(",
"const",
"char",
"*",
"num",
")",
"{",
"if",
"(",
"strlen",
"(",
"num",
")",
"==",
"0",
")",
"return",
"-1",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"strlen",
"(",
"num",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"(",
"(",
"num",
"[",
"i",
"]",
">=",
"'",
"'",
"&&",
"num",
"[",
"i",
"]",
"<=",
"'",
"'",
")",
"||",
"(",
"num",
"[",
"i",
"]",
">=",
"'",
"'",
"&&",
"num",
"[",
"i",
"]",
"<=",
"'",
"'",
")",
"||",
"(",
"num",
"[",
"i",
"]",
">=",
"'",
"'",
"&&",
"num",
"[",
"i",
"]",
"<=",
"'",
"'",
")",
")",
")",
"{",
"return",
"-1",
";",
"}",
"}",
"int",
"ret",
";",
"sscanf",
"(",
"num",
",",
"\"",
"\"",
",",
"&",
"ret",
")",
";",
"return",
"ret",
";",
"}"
] | Function: hex
Purpose: reads a hexadecimal string and returns positive decimal value
Return value: if invalid -1 / if valid positive decimal value | [
"Function",
":",
"hex",
"Purpose",
":",
"reads",
"a",
"hexadecimal",
"string",
"and",
"returns",
"positive",
"decimal",
"value",
"Return",
"value",
":",
"if",
"invalid",
"-",
"1",
"/",
"if",
"valid",
"positive",
"decimal",
"value"
] | [] | [
{
"param": "num",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "num",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
83445ef8bf8e300ebe2efcd3e6d1a5d452be124d | catensia/SP_Project | sp20161634_proj3/20161634.c | [
"MIT"
] | C | start | void | void start(void){
printf("sicsim>");
char buffer[MAX_INPUT];
if(fgets(buffer, sizeof(buffer), stdin)){
size_t len=strlen(buffer);
if(len>0 && buffer[len-1]=='\n') buffer[len-1]='\0';
}
char *cmd=trim(buffer);
if(strlen(cmd)==0) return;
//one word inputs (trivial) - call appropriate functions
if(!strcmp(cmd, "help") || !strcmp(cmd, "h")){
shell_help();
history_add(cmd, &head); return;
}
if(!strcmp(cmd, "dir") || !strcmp(cmd, "d")){
shell_dir();
history_add(cmd, &head); return;
}
if(!strcmp(cmd, "quit") || !strcmp(cmd, "q")){
exit(0);
}
if(!strcmp(cmd, "history") || !strcmp(cmd, "hi")){
history_add(cmd, &head);
history_print(&head); return;
}
if(!strcmp(cmd, "du")||!strcmp(cmd,"dump")){
dump(m,1, dump_adr); dump_adr+=160;
history_add(cmd, &head); return;
}
if(!strcmp(cmd, "opcodelist")){
history_add(cmd, &head);
op_list(hash); return;
}
if(!strcmp(cmd, "reset")){
history_add(cmd, &head);
reset(m); return;
}
if(!strcmp(cmd, "symbol")){
history_add(cmd, &head);
symtab_print(&last_success_symtab); return;
}
if(!strcmp(cmd, "bp")){
history_add(cmd, &head);
print_bp();
return;
}
if(!strcmp(cmd, "run")){
history_add(cmd, &head);
run();
return;
}
//memory commands with multi word inputs
if(argnum(cmd)==-1){
printf("invalid input\n"); return;
}
} | /*---------------------------------------------------------------------*/
/*Function: start*/
/*Purpose: reads user input and handles single word inputs*/
/*Return: void*/
/*---------------------------------------------------------------------*/ | start
Purpose: reads user input and handles single word inputs
Return: void | [
"start",
"Purpose",
":",
"reads",
"user",
"input",
"and",
"handles",
"single",
"word",
"inputs",
"Return",
":",
"void"
] | void start(void){
printf("sicsim>");
char buffer[MAX_INPUT];
if(fgets(buffer, sizeof(buffer), stdin)){
size_t len=strlen(buffer);
if(len>0 && buffer[len-1]=='\n') buffer[len-1]='\0';
}
char *cmd=trim(buffer);
if(strlen(cmd)==0) return;
if(!strcmp(cmd, "help") || !strcmp(cmd, "h")){
shell_help();
history_add(cmd, &head); return;
}
if(!strcmp(cmd, "dir") || !strcmp(cmd, "d")){
shell_dir();
history_add(cmd, &head); return;
}
if(!strcmp(cmd, "quit") || !strcmp(cmd, "q")){
exit(0);
}
if(!strcmp(cmd, "history") || !strcmp(cmd, "hi")){
history_add(cmd, &head);
history_print(&head); return;
}
if(!strcmp(cmd, "du")||!strcmp(cmd,"dump")){
dump(m,1, dump_adr); dump_adr+=160;
history_add(cmd, &head); return;
}
if(!strcmp(cmd, "opcodelist")){
history_add(cmd, &head);
op_list(hash); return;
}
if(!strcmp(cmd, "reset")){
history_add(cmd, &head);
reset(m); return;
}
if(!strcmp(cmd, "symbol")){
history_add(cmd, &head);
symtab_print(&last_success_symtab); return;
}
if(!strcmp(cmd, "bp")){
history_add(cmd, &head);
print_bp();
return;
}
if(!strcmp(cmd, "run")){
history_add(cmd, &head);
run();
return;
}
if(argnum(cmd)==-1){
printf("invalid input\n"); return;
}
} | [
"void",
"start",
"(",
"void",
")",
"{",
"printf",
"(",
"\"",
"\"",
")",
";",
"char",
"buffer",
"[",
"MAX_INPUT",
"]",
";",
"if",
"(",
"fgets",
"(",
"buffer",
",",
"sizeof",
"(",
"buffer",
")",
",",
"stdin",
")",
")",
"{",
"size_t",
"len",
"=",
"strlen",
"(",
"buffer",
")",
";",
"if",
"(",
"len",
">",
"0",
"&&",
"buffer",
"[",
"len",
"-",
"1",
"]",
"==",
"'",
"\\n",
"'",
")",
"buffer",
"[",
"len",
"-",
"1",
"]",
"=",
"'",
"\\0",
"'",
";",
"}",
"char",
"*",
"cmd",
"=",
"trim",
"(",
"buffer",
")",
";",
"if",
"(",
"strlen",
"(",
"cmd",
")",
"==",
"0",
")",
"return",
";",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
"||",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"shell_help",
"(",
")",
";",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
"||",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"shell_dir",
"(",
")",
";",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
"||",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"exit",
"(",
"0",
")",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
"||",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"history_print",
"(",
"&",
"head",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
"||",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"dump",
"(",
"m",
",",
"1",
",",
"dump_adr",
")",
";",
"dump_adr",
"+=",
"160",
";",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"op_list",
"(",
"hash",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"reset",
"(",
"m",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"symtab_print",
"(",
"&",
"last_success_symtab",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"print_bp",
"(",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"run",
"(",
")",
";",
"return",
";",
"}",
"if",
"(",
"argnum",
"(",
"cmd",
")",
"==",
"-1",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"return",
";",
"}",
"}"
] | Function: start
Purpose: reads user input and handles single word inputs
Return: void | [
"Function",
":",
"start",
"Purpose",
":",
"reads",
"user",
"input",
"and",
"handles",
"single",
"word",
"inputs",
"Return",
":",
"void"
] | [
"//one word inputs (trivial) - call appropriate functions",
"//memory commands with multi word inputs"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
ca98430335eeb9beb795dec79daafa279a0381df | catensia/SP_Project | sp20161634_proj1/20161634.c | [
"MIT"
] | C | argnum | int | int argnum(char* cmd){
char what[100];
//variables for start end value address
int s,e,val, adr;
//variable to check arguments
int args=1;
//checks validity of input
int space=0, comma=0;
//sets flag according to command
bool editflag=false, dumpflag=false, fillflag=false;
bool spaceflag=false;
s=e=val=adr=-1;
//string to add to history list
char history_string[100];
char op[100], mne[100], trash[100]; trash[0]='\0';
int words=sscanf(cmd, "%s %s %s", op, mne, trash);
if(words==2 && trash[0]=='\0' && !strcmp(op, "opcode")){
//ex: opcode add
//special case : need to check whether correct opcode, so add history inside function
op_cmd(mne, hash, &head); return 0;
}
//checks comma numbers
for(int i=0;i<strlen(cmd);i++){
if(!spaceflag && isspace(cmd[i])){
space=i; spaceflag=true;
}
if(cmd[i]==',') comma++;
}
sscanf(cmd, "%s", what);
char *tokenize=cmd;
tokenize+=space;
char *ptr;
//decides command flags
if(!strcmp("e", what)||!strcmp("edit", what)) editflag=true;
if(!strcmp("du", what)||!strcmp("dump", what)) dumpflag=true;
if(!strcmp("f", what)||!strcmp("fill", what)) fillflag=true;
char hexStart[10], hexEnd[10],hexAddress[10], hexValue[10];
//splits command by comma, and does boundary check and argument checks
while((ptr=strsep(&tokenize,","))){
int tempVal=hex(trim(ptr));
//if invalid hexadecimal error
if(tempVal==-1) return -1;
if(editflag){
//edit : check second argument range 00~FF
//edit : first argument should be 00~FFFFF
if(args==1 && 0<=tempVal && tempVal<=0xFFFFF){
adr=tempVal; args++;
strcpy(hexAddress, trim(ptr));
}
else if(args==2 && 0<=tempVal && tempVal<=0xFF){
val=tempVal; args++;
strcpy(hexValue, trim(ptr));
}
else return -1;
}
else if(dumpflag){
//dump : all arguments should be 00~FFFFF
if(0<=tempVal && tempVal<=0xFFFFF){
if(args==1){
s=tempVal; args++;
strcpy(hexStart, trim(ptr));
}
else if(args==2){
e=tempVal; args++;
strcpy(hexEnd, trim(ptr));
}
}
//if else invalid input ex: du 123A
else return -1;
}
else if(fillflag){
//fill : first and second argument (00~FFFFF) third argument (00~FF)
//printf("tempval:%d\n", tempVal);
if(args==1 && 0<=tempVal && tempVal<=0xFFFFF){
s=tempVal; args++;
strcpy(hexStart, trim(ptr));
}
else if(args==2 && 0<=tempVal && tempVal<=0xFFFFF){
e=tempVal; args++;
strcpy(hexEnd, trim(ptr));
}
else if(args==3 && 0<=tempVal && tempVal<=0xFF){
val=tempVal; args++;
strcpy(hexValue, trim(ptr));
}
else return -1;
}
}
//command should be checked
//all s,e,val should never be -1
//comma number and argument number should match
if(comma+2!=args) return -1;
//call functions based on command and append to history list
if(args==2 && (s!=-1) && (!strcmp(what, "du")||!strcmp(what,"dump")) ){
sprintf(history_string, "%s %s", what, hexStart);
history_add(history_string, &head);
dump(m,1,s); return 0;
}
if(args==3 && (s!=-1 && e!=-1) && (!strcmp(what, "du")||!strcmp(what,"dump"))){
sprintf(history_string, "%s %s, %s", what, hexStart,hexEnd);
history_add(history_string, &head);
dump(m,2,s,e); return 0;
}
if(args==4 && (s!=-1 && e!=-1 && val!=-1) && (!strcmp(what, "f")||!strcmp(what,"fill"))){
sprintf(history_string, "%s %s, %s, %s", what, hexStart,hexEnd,hexValue);
history_add(history_string, &head);
fill(m,s,e,val); return 0;
}
if(editflag && args==3 && (adr!=-1 && val!=-1)){
sprintf(history_string, "%s %s, %s", what, hexAddress, hexValue);
history_add(history_string, &head);
edit(m,adr, val); return 0;
}
return -1;
} | /*---------------------------------------------------------------------*/
/*Function: argnum*/
/*Purpose: parses multi-word commands and calls appropriate functions depending on input*/
/*Return value: if invalid -1 / if valid 0 */
/*---------------------------------------------------------------------*/ | argnum
Purpose: parses multi-word commands and calls appropriate functions depending on input
Return value: if invalid -1 / if valid 0 | [
"argnum",
"Purpose",
":",
"parses",
"multi",
"-",
"word",
"commands",
"and",
"calls",
"appropriate",
"functions",
"depending",
"on",
"input",
"Return",
"value",
":",
"if",
"invalid",
"-",
"1",
"/",
"if",
"valid",
"0"
] | int argnum(char* cmd){
char what[100];
int s,e,val, adr;
int args=1;
int space=0, comma=0;
bool editflag=false, dumpflag=false, fillflag=false;
bool spaceflag=false;
s=e=val=adr=-1;
char history_string[100];
char op[100], mne[100], trash[100]; trash[0]='\0';
int words=sscanf(cmd, "%s %s %s", op, mne, trash);
if(words==2 && trash[0]=='\0' && !strcmp(op, "opcode")){
op_cmd(mne, hash, &head); return 0;
}
for(int i=0;i<strlen(cmd);i++){
if(!spaceflag && isspace(cmd[i])){
space=i; spaceflag=true;
}
if(cmd[i]==',') comma++;
}
sscanf(cmd, "%s", what);
char *tokenize=cmd;
tokenize+=space;
char *ptr;
if(!strcmp("e", what)||!strcmp("edit", what)) editflag=true;
if(!strcmp("du", what)||!strcmp("dump", what)) dumpflag=true;
if(!strcmp("f", what)||!strcmp("fill", what)) fillflag=true;
char hexStart[10], hexEnd[10],hexAddress[10], hexValue[10];
while((ptr=strsep(&tokenize,","))){
int tempVal=hex(trim(ptr));
if(tempVal==-1) return -1;
if(editflag){
if(args==1 && 0<=tempVal && tempVal<=0xFFFFF){
adr=tempVal; args++;
strcpy(hexAddress, trim(ptr));
}
else if(args==2 && 0<=tempVal && tempVal<=0xFF){
val=tempVal; args++;
strcpy(hexValue, trim(ptr));
}
else return -1;
}
else if(dumpflag){
if(0<=tempVal && tempVal<=0xFFFFF){
if(args==1){
s=tempVal; args++;
strcpy(hexStart, trim(ptr));
}
else if(args==2){
e=tempVal; args++;
strcpy(hexEnd, trim(ptr));
}
}
else return -1;
}
else if(fillflag){
if(args==1 && 0<=tempVal && tempVal<=0xFFFFF){
s=tempVal; args++;
strcpy(hexStart, trim(ptr));
}
else if(args==2 && 0<=tempVal && tempVal<=0xFFFFF){
e=tempVal; args++;
strcpy(hexEnd, trim(ptr));
}
else if(args==3 && 0<=tempVal && tempVal<=0xFF){
val=tempVal; args++;
strcpy(hexValue, trim(ptr));
}
else return -1;
}
}
if(comma+2!=args) return -1;
if(args==2 && (s!=-1) && (!strcmp(what, "du")||!strcmp(what,"dump")) ){
sprintf(history_string, "%s %s", what, hexStart);
history_add(history_string, &head);
dump(m,1,s); return 0;
}
if(args==3 && (s!=-1 && e!=-1) && (!strcmp(what, "du")||!strcmp(what,"dump"))){
sprintf(history_string, "%s %s, %s", what, hexStart,hexEnd);
history_add(history_string, &head);
dump(m,2,s,e); return 0;
}
if(args==4 && (s!=-1 && e!=-1 && val!=-1) && (!strcmp(what, "f")||!strcmp(what,"fill"))){
sprintf(history_string, "%s %s, %s, %s", what, hexStart,hexEnd,hexValue);
history_add(history_string, &head);
fill(m,s,e,val); return 0;
}
if(editflag && args==3 && (adr!=-1 && val!=-1)){
sprintf(history_string, "%s %s, %s", what, hexAddress, hexValue);
history_add(history_string, &head);
edit(m,adr, val); return 0;
}
return -1;
} | [
"int",
"argnum",
"(",
"char",
"*",
"cmd",
")",
"{",
"char",
"what",
"[",
"100",
"]",
";",
"int",
"s",
",",
"e",
",",
"val",
",",
"adr",
";",
"int",
"args",
"=",
"1",
";",
"int",
"space",
"=",
"0",
",",
"comma",
"=",
"0",
";",
"bool",
"editflag",
"=",
"false",
",",
"dumpflag",
"=",
"false",
",",
"fillflag",
"=",
"false",
";",
"bool",
"spaceflag",
"=",
"false",
";",
"s",
"=",
"e",
"=",
"val",
"=",
"adr",
"=",
"-1",
";",
"char",
"history_string",
"[",
"100",
"]",
";",
"char",
"op",
"[",
"100",
"]",
",",
"mne",
"[",
"100",
"]",
",",
"trash",
"[",
"100",
"]",
";",
"trash",
"[",
"0",
"]",
"=",
"'",
"\\0",
"'",
";",
"int",
"words",
"=",
"sscanf",
"(",
"cmd",
",",
"\"",
"\"",
",",
"op",
",",
"mne",
",",
"trash",
")",
";",
"if",
"(",
"words",
"==",
"2",
"&&",
"trash",
"[",
"0",
"]",
"==",
"'",
"\\0",
"'",
"&&",
"!",
"strcmp",
"(",
"op",
",",
"\"",
"\"",
")",
")",
"{",
"op_cmd",
"(",
"mne",
",",
"hash",
",",
"&",
"head",
")",
";",
"return",
"0",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"strlen",
"(",
"cmd",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"spaceflag",
"&&",
"isspace",
"(",
"cmd",
"[",
"i",
"]",
")",
")",
"{",
"space",
"=",
"i",
";",
"spaceflag",
"=",
"true",
";",
"}",
"if",
"(",
"cmd",
"[",
"i",
"]",
"==",
"'",
"'",
")",
"comma",
"++",
";",
"}",
"sscanf",
"(",
"cmd",
",",
"\"",
"\"",
",",
"what",
")",
";",
"char",
"*",
"tokenize",
"=",
"cmd",
";",
"tokenize",
"+=",
"space",
";",
"char",
"*",
"ptr",
";",
"if",
"(",
"!",
"strcmp",
"(",
"\"",
"\"",
",",
"what",
")",
"||",
"!",
"strcmp",
"(",
"\"",
"\"",
",",
"what",
")",
")",
"editflag",
"=",
"true",
";",
"if",
"(",
"!",
"strcmp",
"(",
"\"",
"\"",
",",
"what",
")",
"||",
"!",
"strcmp",
"(",
"\"",
"\"",
",",
"what",
")",
")",
"dumpflag",
"=",
"true",
";",
"if",
"(",
"!",
"strcmp",
"(",
"\"",
"\"",
",",
"what",
")",
"||",
"!",
"strcmp",
"(",
"\"",
"\"",
",",
"what",
")",
")",
"fillflag",
"=",
"true",
";",
"char",
"hexStart",
"[",
"10",
"]",
",",
"hexEnd",
"[",
"10",
"]",
",",
"hexAddress",
"[",
"10",
"]",
",",
"hexValue",
"[",
"10",
"]",
";",
"while",
"(",
"(",
"ptr",
"=",
"strsep",
"(",
"&",
"tokenize",
",",
"\"",
"\"",
")",
")",
")",
"{",
"int",
"tempVal",
"=",
"hex",
"(",
"trim",
"(",
"ptr",
")",
")",
";",
"if",
"(",
"tempVal",
"==",
"-1",
")",
"return",
"-1",
";",
"if",
"(",
"editflag",
")",
"{",
"if",
"(",
"args",
"==",
"1",
"&&",
"0",
"<=",
"tempVal",
"&&",
"tempVal",
"<=",
"0xFFFFF",
")",
"{",
"adr",
"=",
"tempVal",
";",
"args",
"++",
";",
"strcpy",
"(",
"hexAddress",
",",
"trim",
"(",
"ptr",
")",
")",
";",
"}",
"else",
"if",
"(",
"args",
"==",
"2",
"&&",
"0",
"<=",
"tempVal",
"&&",
"tempVal",
"<=",
"0xFF",
")",
"{",
"val",
"=",
"tempVal",
";",
"args",
"++",
";",
"strcpy",
"(",
"hexValue",
",",
"trim",
"(",
"ptr",
")",
")",
";",
"}",
"else",
"return",
"-1",
";",
"}",
"else",
"if",
"(",
"dumpflag",
")",
"{",
"if",
"(",
"0",
"<=",
"tempVal",
"&&",
"tempVal",
"<=",
"0xFFFFF",
")",
"{",
"if",
"(",
"args",
"==",
"1",
")",
"{",
"s",
"=",
"tempVal",
";",
"args",
"++",
";",
"strcpy",
"(",
"hexStart",
",",
"trim",
"(",
"ptr",
")",
")",
";",
"}",
"else",
"if",
"(",
"args",
"==",
"2",
")",
"{",
"e",
"=",
"tempVal",
";",
"args",
"++",
";",
"strcpy",
"(",
"hexEnd",
",",
"trim",
"(",
"ptr",
")",
")",
";",
"}",
"}",
"else",
"return",
"-1",
";",
"}",
"else",
"if",
"(",
"fillflag",
")",
"{",
"if",
"(",
"args",
"==",
"1",
"&&",
"0",
"<=",
"tempVal",
"&&",
"tempVal",
"<=",
"0xFFFFF",
")",
"{",
"s",
"=",
"tempVal",
";",
"args",
"++",
";",
"strcpy",
"(",
"hexStart",
",",
"trim",
"(",
"ptr",
")",
")",
";",
"}",
"else",
"if",
"(",
"args",
"==",
"2",
"&&",
"0",
"<=",
"tempVal",
"&&",
"tempVal",
"<=",
"0xFFFFF",
")",
"{",
"e",
"=",
"tempVal",
";",
"args",
"++",
";",
"strcpy",
"(",
"hexEnd",
",",
"trim",
"(",
"ptr",
")",
")",
";",
"}",
"else",
"if",
"(",
"args",
"==",
"3",
"&&",
"0",
"<=",
"tempVal",
"&&",
"tempVal",
"<=",
"0xFF",
")",
"{",
"val",
"=",
"tempVal",
";",
"args",
"++",
";",
"strcpy",
"(",
"hexValue",
",",
"trim",
"(",
"ptr",
")",
")",
";",
"}",
"else",
"return",
"-1",
";",
"}",
"}",
"if",
"(",
"comma",
"+",
"2",
"!=",
"args",
")",
"return",
"-1",
";",
"if",
"(",
"args",
"==",
"2",
"&&",
"(",
"s",
"!=",
"-1",
")",
"&&",
"(",
"!",
"strcmp",
"(",
"what",
",",
"\"",
"\"",
")",
"||",
"!",
"strcmp",
"(",
"what",
",",
"\"",
"\"",
")",
")",
")",
"{",
"sprintf",
"(",
"history_string",
",",
"\"",
"\"",
",",
"what",
",",
"hexStart",
")",
";",
"history_add",
"(",
"history_string",
",",
"&",
"head",
")",
";",
"dump",
"(",
"m",
",",
"1",
",",
"s",
")",
";",
"return",
"0",
";",
"}",
"if",
"(",
"args",
"==",
"3",
"&&",
"(",
"s",
"!=",
"-1",
"&&",
"e",
"!=",
"-1",
")",
"&&",
"(",
"!",
"strcmp",
"(",
"what",
",",
"\"",
"\"",
")",
"||",
"!",
"strcmp",
"(",
"what",
",",
"\"",
"\"",
")",
")",
")",
"{",
"sprintf",
"(",
"history_string",
",",
"\"",
"\"",
",",
"what",
",",
"hexStart",
",",
"hexEnd",
")",
";",
"history_add",
"(",
"history_string",
",",
"&",
"head",
")",
";",
"dump",
"(",
"m",
",",
"2",
",",
"s",
",",
"e",
")",
";",
"return",
"0",
";",
"}",
"if",
"(",
"args",
"==",
"4",
"&&",
"(",
"s",
"!=",
"-1",
"&&",
"e",
"!=",
"-1",
"&&",
"val",
"!=",
"-1",
")",
"&&",
"(",
"!",
"strcmp",
"(",
"what",
",",
"\"",
"\"",
")",
"||",
"!",
"strcmp",
"(",
"what",
",",
"\"",
"\"",
")",
")",
")",
"{",
"sprintf",
"(",
"history_string",
",",
"\"",
"\"",
",",
"what",
",",
"hexStart",
",",
"hexEnd",
",",
"hexValue",
")",
";",
"history_add",
"(",
"history_string",
",",
"&",
"head",
")",
";",
"fill",
"(",
"m",
",",
"s",
",",
"e",
",",
"val",
")",
";",
"return",
"0",
";",
"}",
"if",
"(",
"editflag",
"&&",
"args",
"==",
"3",
"&&",
"(",
"adr",
"!=",
"-1",
"&&",
"val",
"!=",
"-1",
")",
")",
"{",
"sprintf",
"(",
"history_string",
",",
"\"",
"\"",
",",
"what",
",",
"hexAddress",
",",
"hexValue",
")",
";",
"history_add",
"(",
"history_string",
",",
"&",
"head",
")",
";",
"edit",
"(",
"m",
",",
"adr",
",",
"val",
")",
";",
"return",
"0",
";",
"}",
"return",
"-1",
";",
"}"
] | Function: argnum
Purpose: parses multi-word commands and calls appropriate functions depending on input
Return value: if invalid -1 / if valid 0 | [
"Function",
":",
"argnum",
"Purpose",
":",
"parses",
"multi",
"-",
"word",
"commands",
"and",
"calls",
"appropriate",
"functions",
"depending",
"on",
"input",
"Return",
"value",
":",
"if",
"invalid",
"-",
"1",
"/",
"if",
"valid",
"0"
] | [
"//variables for start end value address",
"//variable to check arguments",
"//checks validity of input",
"//sets flag according to command",
"//string to add to history list",
"//ex: opcode add",
"//special case : need to check whether correct opcode, so add history inside function",
"//checks comma numbers",
"//decides command flags",
"//splits command by comma, and does boundary check and argument checks",
"//if invalid hexadecimal error",
"//edit : check second argument range 00~FF",
"//edit : first argument should be 00~FFFFF",
"//dump : all arguments should be 00~FFFFF",
"//if else invalid input ex: du 123A",
"//fill : first and second argument (00~FFFFF) third argument (00~FF)",
"//printf(\"tempval:%d\\n\", tempVal);",
"//command should be checked",
"//all s,e,val should never be -1",
"//comma number and argument number should match",
"//call functions based on command and append to history list"
] | [
{
"param": "cmd",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cmd",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ca98430335eeb9beb795dec79daafa279a0381df | catensia/SP_Project | sp20161634_proj1/20161634.c | [
"MIT"
] | C | start | void | void start(void){
printf("sicsim>");
char buffer[MAX_INPUT];
if(fgets(buffer, sizeof(buffer), stdin)){
size_t len=strlen(buffer);
if(len>0 && buffer[len-1]=='\n') buffer[len-1]='\0';
}
char *cmd=trim(buffer);
if(strlen(cmd)==0) return;
//one word inputs (trivial) - call appropriate functions
if(!strcmp(cmd, "help") || !strcmp(cmd, "h")){
shell_help();
history_add(cmd, &head); return;
}
if(!strcmp(cmd, "dir") || !strcmp(cmd, "d")){
shell_dir();
history_add(cmd, &head); return;
}
if(!strcmp(cmd, "quit") || !strcmp(cmd, "q")){
exit(0);
}
if(!strcmp(cmd, "history") || !strcmp(cmd, "hi")){
history_add(cmd, &head);
history_print(&head); return;
}
if(!strcmp(cmd, "du")||!strcmp(cmd,"dump")){
dump(m,1, dump_adr); dump_adr+=160;
history_add(cmd, &head); return;
}
if(!strcmp(cmd, "opcodelist")){
history_add(cmd, &head);
op_list(hash); return;
}
if(!strcmp(cmd, "reset")){
history_add(cmd, &head);
reset(m); return;
}
//memory commands with multi word inputs
if(argnum(cmd)==-1){
printf("invalid input\n"); return;
}
} | /*---------------------------------------------------------------------*/
/*Function: start*/
/*Purpose: reads user input and handles single word inputs*/
/*Return: void*/
/*---------------------------------------------------------------------*/ | start
Purpose: reads user input and handles single word inputs
Return: void | [
"start",
"Purpose",
":",
"reads",
"user",
"input",
"and",
"handles",
"single",
"word",
"inputs",
"Return",
":",
"void"
] | void start(void){
printf("sicsim>");
char buffer[MAX_INPUT];
if(fgets(buffer, sizeof(buffer), stdin)){
size_t len=strlen(buffer);
if(len>0 && buffer[len-1]=='\n') buffer[len-1]='\0';
}
char *cmd=trim(buffer);
if(strlen(cmd)==0) return;
if(!strcmp(cmd, "help") || !strcmp(cmd, "h")){
shell_help();
history_add(cmd, &head); return;
}
if(!strcmp(cmd, "dir") || !strcmp(cmd, "d")){
shell_dir();
history_add(cmd, &head); return;
}
if(!strcmp(cmd, "quit") || !strcmp(cmd, "q")){
exit(0);
}
if(!strcmp(cmd, "history") || !strcmp(cmd, "hi")){
history_add(cmd, &head);
history_print(&head); return;
}
if(!strcmp(cmd, "du")||!strcmp(cmd,"dump")){
dump(m,1, dump_adr); dump_adr+=160;
history_add(cmd, &head); return;
}
if(!strcmp(cmd, "opcodelist")){
history_add(cmd, &head);
op_list(hash); return;
}
if(!strcmp(cmd, "reset")){
history_add(cmd, &head);
reset(m); return;
}
if(argnum(cmd)==-1){
printf("invalid input\n"); return;
}
} | [
"void",
"start",
"(",
"void",
")",
"{",
"printf",
"(",
"\"",
"\"",
")",
";",
"char",
"buffer",
"[",
"MAX_INPUT",
"]",
";",
"if",
"(",
"fgets",
"(",
"buffer",
",",
"sizeof",
"(",
"buffer",
")",
",",
"stdin",
")",
")",
"{",
"size_t",
"len",
"=",
"strlen",
"(",
"buffer",
")",
";",
"if",
"(",
"len",
">",
"0",
"&&",
"buffer",
"[",
"len",
"-",
"1",
"]",
"==",
"'",
"\\n",
"'",
")",
"buffer",
"[",
"len",
"-",
"1",
"]",
"=",
"'",
"\\0",
"'",
";",
"}",
"char",
"*",
"cmd",
"=",
"trim",
"(",
"buffer",
")",
";",
"if",
"(",
"strlen",
"(",
"cmd",
")",
"==",
"0",
")",
"return",
";",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
"||",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"shell_help",
"(",
")",
";",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
"||",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"shell_dir",
"(",
")",
";",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
"||",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"exit",
"(",
"0",
")",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
"||",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"history_print",
"(",
"&",
"head",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
"||",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"dump",
"(",
"m",
",",
"1",
",",
"dump_adr",
")",
";",
"dump_adr",
"+=",
"160",
";",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"op_list",
"(",
"hash",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"strcmp",
"(",
"cmd",
",",
"\"",
"\"",
")",
")",
"{",
"history_add",
"(",
"cmd",
",",
"&",
"head",
")",
";",
"reset",
"(",
"m",
")",
";",
"return",
";",
"}",
"if",
"(",
"argnum",
"(",
"cmd",
")",
"==",
"-1",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"return",
";",
"}",
"}"
] | Function: start
Purpose: reads user input and handles single word inputs
Return: void | [
"Function",
":",
"start",
"Purpose",
":",
"reads",
"user",
"input",
"and",
"handles",
"single",
"word",
"inputs",
"Return",
":",
"void"
] | [
"//one word inputs (trivial) - call appropriate functions",
"//memory commands with multi word inputs"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
79f09471860f3e980db935618568b09fdbfd0ad5 | catensia/SP_Project | sp20161634_proj2/opcode.c | [
"MIT"
] | C | calc_key | int | int calc_key(const char*cmd){
int key=0;
for(int i=0;i<strlen(cmd);i++){
key+=(int)cmd[i];
}
return key%MAX_HASH;
} | /*---------------------------------------------------------------------*/
/*Function: calc_key*/
/*Purpose: calculates hash function*/
/*Return: integer value of hash key*/
/*---------------------------------------------------------------------*/ | calc_key
Purpose: calculates hash function
Return: integer value of hash key | [
"calc_key",
"Purpose",
":",
"calculates",
"hash",
"function",
"Return",
":",
"integer",
"value",
"of",
"hash",
"key"
] | int calc_key(const char*cmd){
int key=0;
for(int i=0;i<strlen(cmd);i++){
key+=(int)cmd[i];
}
return key%MAX_HASH;
} | [
"int",
"calc_key",
"(",
"const",
"char",
"*",
"cmd",
")",
"{",
"int",
"key",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"strlen",
"(",
"cmd",
")",
";",
"i",
"++",
")",
"{",
"key",
"+=",
"(",
"int",
")",
"cmd",
"[",
"i",
"]",
";",
"}",
"return",
"key",
"%",
"MAX_HASH",
";",
"}"
] | Function: calc_key
Purpose: calculates hash function
Return: integer value of hash key | [
"Function",
":",
"calc_key",
"Purpose",
":",
"calculates",
"hash",
"function",
"Return",
":",
"integer",
"value",
"of",
"hash",
"key"
] | [] | [
{
"param": "cmd",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cmd",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
79f09471860f3e980db935618568b09fdbfd0ad5 | catensia/SP_Project | sp20161634_proj2/opcode.c | [
"MIT"
] | C | addHash | void | void addHash(struct NODE *node, struct NODE *hash[]){
int key=calc_key(node->cmd);
if(hash[key]==NULL){
hash[key]=node;
}
else{
node->next=hash[key];
hash[key]=node;
}
} | /*---------------------------------------------------------------------*/
/*Function: addHash*/
/*Purpose: adds a node to hash table*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | addHash
Purpose: adds a node to hash table
Return: none | [
"addHash",
"Purpose",
":",
"adds",
"a",
"node",
"to",
"hash",
"table",
"Return",
":",
"none"
] | void addHash(struct NODE *node, struct NODE *hash[]){
int key=calc_key(node->cmd);
if(hash[key]==NULL){
hash[key]=node;
}
else{
node->next=hash[key];
hash[key]=node;
}
} | [
"void",
"addHash",
"(",
"struct",
"NODE",
"*",
"node",
",",
"struct",
"NODE",
"*",
"hash",
"[",
"]",
")",
"{",
"int",
"key",
"=",
"calc_key",
"(",
"node",
"->",
"cmd",
")",
";",
"if",
"(",
"hash",
"[",
"key",
"]",
"==",
"NULL",
")",
"{",
"hash",
"[",
"key",
"]",
"=",
"node",
";",
"}",
"else",
"{",
"node",
"->",
"next",
"=",
"hash",
"[",
"key",
"]",
";",
"hash",
"[",
"key",
"]",
"=",
"node",
";",
"}",
"}"
] | Function: addHash
Purpose: adds a node to hash table
Return: none | [
"Function",
":",
"addHash",
"Purpose",
":",
"adds",
"a",
"node",
"to",
"hash",
"table",
"Return",
":",
"none"
] | [] | [
{
"param": "node",
"type": "struct NODE"
},
{
"param": "hash",
"type": "struct NODE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "node",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "hash",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
79f09471860f3e980db935618568b09fdbfd0ad5 | catensia/SP_Project | sp20161634_proj2/opcode.c | [
"MIT"
] | C | init_hash | void | void init_hash(struct NODE *hash[]){
FILE *fp = fopen("opcode.txt", "r");
int cmd_num;
char op[10];
char format[10];
while(EOF!=fscanf(fp,"%x %s %s", &cmd_num, op, format)){
struct NODE *newNode=(struct NODE*)malloc(sizeof(struct NODE));
strcpy(newNode->cmd, op);
strcpy(newNode->format, format);
newNode->num=cmd_num;
newNode->next=NULL;
addHash(newNode, hash);
}
} | /*---------------------------------------------------------------------*/
/*Function: init_hash*/
/*Purpose: reads opcode.txt and makes hash table*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | init_hash
Purpose: reads opcode.txt and makes hash table
Return: none | [
"init_hash",
"Purpose",
":",
"reads",
"opcode",
".",
"txt",
"and",
"makes",
"hash",
"table",
"Return",
":",
"none"
] | void init_hash(struct NODE *hash[]){
FILE *fp = fopen("opcode.txt", "r");
int cmd_num;
char op[10];
char format[10];
while(EOF!=fscanf(fp,"%x %s %s", &cmd_num, op, format)){
struct NODE *newNode=(struct NODE*)malloc(sizeof(struct NODE));
strcpy(newNode->cmd, op);
strcpy(newNode->format, format);
newNode->num=cmd_num;
newNode->next=NULL;
addHash(newNode, hash);
}
} | [
"void",
"init_hash",
"(",
"struct",
"NODE",
"*",
"hash",
"[",
"]",
")",
"{",
"FILE",
"*",
"fp",
"=",
"fopen",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"int",
"cmd_num",
";",
"char",
"op",
"[",
"10",
"]",
";",
"char",
"format",
"[",
"10",
"]",
";",
"while",
"(",
"EOF",
"!=",
"fscanf",
"(",
"fp",
",",
"\"",
"\"",
",",
"&",
"cmd_num",
",",
"op",
",",
"format",
")",
")",
"{",
"struct",
"NODE",
"*",
"newNode",
"=",
"(",
"struct",
"NODE",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"struct",
"NODE",
")",
")",
";",
"strcpy",
"(",
"newNode",
"->",
"cmd",
",",
"op",
")",
";",
"strcpy",
"(",
"newNode",
"->",
"format",
",",
"format",
")",
";",
"newNode",
"->",
"num",
"=",
"cmd_num",
";",
"newNode",
"->",
"next",
"=",
"NULL",
";",
"addHash",
"(",
"newNode",
",",
"hash",
")",
";",
"}",
"}"
] | Function: init_hash
Purpose: reads opcode.txt and makes hash table
Return: none | [
"Function",
":",
"init_hash",
"Purpose",
":",
"reads",
"opcode",
".",
"txt",
"and",
"makes",
"hash",
"table",
"Return",
":",
"none"
] | [] | [
{
"param": "hash",
"type": "struct NODE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "hash",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
79f09471860f3e980db935618568b09fdbfd0ad5 | catensia/SP_Project | sp20161634_proj2/opcode.c | [
"MIT"
] | C | op_cmd | void | void op_cmd(char *mnemonic, struct NODE *hash[], struct NODE **head){
int key=calc_key(mnemonic);
char history_string[100];
struct NODE*cur=hash[key];
while(cur!=NULL){
if(!strcmp(cur->cmd, mnemonic)){
sprintf(history_string,"opcode %s", mnemonic);
history_add(history_string, head);
printf("opcode is %X\n", cur->num);
return;
}
cur=cur->next;
}
printf("no such opcode\n"); return;
} | /*---------------------------------------------------------------------*/
/*Function: op_cmd*/
/*Purpose: takes mnemonic input and prints corresponding opcode*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | op_cmd
Purpose: takes mnemonic input and prints corresponding opcode
Return: none | [
"op_cmd",
"Purpose",
":",
"takes",
"mnemonic",
"input",
"and",
"prints",
"corresponding",
"opcode",
"Return",
":",
"none"
] | void op_cmd(char *mnemonic, struct NODE *hash[], struct NODE **head){
int key=calc_key(mnemonic);
char history_string[100];
struct NODE*cur=hash[key];
while(cur!=NULL){
if(!strcmp(cur->cmd, mnemonic)){
sprintf(history_string,"opcode %s", mnemonic);
history_add(history_string, head);
printf("opcode is %X\n", cur->num);
return;
}
cur=cur->next;
}
printf("no such opcode\n"); return;
} | [
"void",
"op_cmd",
"(",
"char",
"*",
"mnemonic",
",",
"struct",
"NODE",
"*",
"hash",
"[",
"]",
",",
"struct",
"NODE",
"*",
"*",
"head",
")",
"{",
"int",
"key",
"=",
"calc_key",
"(",
"mnemonic",
")",
";",
"char",
"history_string",
"[",
"100",
"]",
";",
"struct",
"NODE",
"*",
"cur",
"=",
"hash",
"[",
"key",
"]",
";",
"while",
"(",
"cur",
"!=",
"NULL",
")",
"{",
"if",
"(",
"!",
"strcmp",
"(",
"cur",
"->",
"cmd",
",",
"mnemonic",
")",
")",
"{",
"sprintf",
"(",
"history_string",
",",
"\"",
"\"",
",",
"mnemonic",
")",
";",
"history_add",
"(",
"history_string",
",",
"head",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"cur",
"->",
"num",
")",
";",
"return",
";",
"}",
"cur",
"=",
"cur",
"->",
"next",
";",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"return",
";",
"}"
] | Function: op_cmd
Purpose: takes mnemonic input and prints corresponding opcode
Return: none | [
"Function",
":",
"op_cmd",
"Purpose",
":",
"takes",
"mnemonic",
"input",
"and",
"prints",
"corresponding",
"opcode",
"Return",
":",
"none"
] | [] | [
{
"param": "mnemonic",
"type": "char"
},
{
"param": "hash",
"type": "struct NODE"
},
{
"param": "head",
"type": "struct NODE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mnemonic",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "hash",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "head",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
79f09471860f3e980db935618568b09fdbfd0ad5 | catensia/SP_Project | sp20161634_proj2/opcode.c | [
"MIT"
] | C | op_return | int | int op_return(const char* mnemonic, struct NODE* hash[]){
int key=calc_key(mnemonic);
struct NODE*cur=hash[key];
while(cur!=NULL){
if(!strcmp(cur->cmd, mnemonic)) return cur->num;
cur=cur->next;
}
return -1;
} | /*---------------------------------------------------------------------*/
/*Function: op_ret*/
/*Purpose: get corresponding opcode*/
/*Return: opcode for mnemonic*/
/*---------------------------------------------------------------------*/ | op_ret
Purpose: get corresponding opcode
Return: opcode for mnemonic | [
"op_ret",
"Purpose",
":",
"get",
"corresponding",
"opcode",
"Return",
":",
"opcode",
"for",
"mnemonic"
] | int op_return(const char* mnemonic, struct NODE* hash[]){
int key=calc_key(mnemonic);
struct NODE*cur=hash[key];
while(cur!=NULL){
if(!strcmp(cur->cmd, mnemonic)) return cur->num;
cur=cur->next;
}
return -1;
} | [
"int",
"op_return",
"(",
"const",
"char",
"*",
"mnemonic",
",",
"struct",
"NODE",
"*",
"hash",
"[",
"]",
")",
"{",
"int",
"key",
"=",
"calc_key",
"(",
"mnemonic",
")",
";",
"struct",
"NODE",
"*",
"cur",
"=",
"hash",
"[",
"key",
"]",
";",
"while",
"(",
"cur",
"!=",
"NULL",
")",
"{",
"if",
"(",
"!",
"strcmp",
"(",
"cur",
"->",
"cmd",
",",
"mnemonic",
")",
")",
"return",
"cur",
"->",
"num",
";",
"cur",
"=",
"cur",
"->",
"next",
";",
"}",
"return",
"-1",
";",
"}"
] | Function: op_ret
Purpose: get corresponding opcode
Return: opcode for mnemonic | [
"Function",
":",
"op_ret",
"Purpose",
":",
"get",
"corresponding",
"opcode",
"Return",
":",
"opcode",
"for",
"mnemonic"
] | [] | [
{
"param": "mnemonic",
"type": "char"
},
{
"param": "hash",
"type": "struct NODE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mnemonic",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "hash",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
79f09471860f3e980db935618568b09fdbfd0ad5 | catensia/SP_Project | sp20161634_proj2/opcode.c | [
"MIT"
] | C | op_list | void | void op_list(struct NODE *hash[]){
for(int i=0;i<MAX_HASH;i++){
printf("%2d : ", i);
if(hash[i]!=NULL){
struct NODE *cur=hash[i];
while(cur!=NULL){
printf("[%s, %X] ", cur->cmd, cur->num);
cur=cur->next;
if(cur!=NULL){
printf(" -> ");
}
}
}
printf("\n");
}
} | /*---------------------------------------------------------------------*/
/*Function: op_list*/
/*Purpose: Prints all opcodes in format*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | op_list
Purpose: Prints all opcodes in format
Return: none | [
"op_list",
"Purpose",
":",
"Prints",
"all",
"opcodes",
"in",
"format",
"Return",
":",
"none"
] | void op_list(struct NODE *hash[]){
for(int i=0;i<MAX_HASH;i++){
printf("%2d : ", i);
if(hash[i]!=NULL){
struct NODE *cur=hash[i];
while(cur!=NULL){
printf("[%s, %X] ", cur->cmd, cur->num);
cur=cur->next;
if(cur!=NULL){
printf(" -> ");
}
}
}
printf("\n");
}
} | [
"void",
"op_list",
"(",
"struct",
"NODE",
"*",
"hash",
"[",
"]",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"MAX_HASH",
";",
"i",
"++",
")",
"{",
"printf",
"(",
"\"",
"\"",
",",
"i",
")",
";",
"if",
"(",
"hash",
"[",
"i",
"]",
"!=",
"NULL",
")",
"{",
"struct",
"NODE",
"*",
"cur",
"=",
"hash",
"[",
"i",
"]",
";",
"while",
"(",
"cur",
"!=",
"NULL",
")",
"{",
"printf",
"(",
"\"",
"\"",
",",
"cur",
"->",
"cmd",
",",
"cur",
"->",
"num",
")",
";",
"cur",
"=",
"cur",
"->",
"next",
";",
"if",
"(",
"cur",
"!=",
"NULL",
")",
"{",
"printf",
"(",
"\"",
"\"",
")",
";",
"}",
"}",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"}"
] | Function: op_list
Purpose: Prints all opcodes in format
Return: none | [
"Function",
":",
"op_list",
"Purpose",
":",
"Prints",
"all",
"opcodes",
"in",
"format",
"Return",
":",
"none"
] | [] | [
{
"param": "hash",
"type": "struct NODE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "hash",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5b95f04238fe2cc989eb70fe97d7e441a74740ca | catensia/SP_Project | sp20161634_proj3/assembler.c | [
"MIT"
] | C | file_ext_appender | void | void file_ext_appender(char* filename, const char* extension) {
int flen = strlen(filename);
for (int i = 0; i < 3; i++) {
filename[flen - 1 - i] = '\0';
}
strcat(filename, extension);
} | /*---------------------------------------------------------------------*/
/*Function: file_ext_appender*/
/*Purpose: Get a file name and change the extension format with parameter*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | file_ext_appender
Purpose: Get a file name and change the extension format with parameter
Return: none | [
"file_ext_appender",
"Purpose",
":",
"Get",
"a",
"file",
"name",
"and",
"change",
"the",
"extension",
"format",
"with",
"parameter",
"Return",
":",
"none"
] | void file_ext_appender(char* filename, const char* extension) {
int flen = strlen(filename);
for (int i = 0; i < 3; i++) {
filename[flen - 1 - i] = '\0';
}
strcat(filename, extension);
} | [
"void",
"file_ext_appender",
"(",
"char",
"*",
"filename",
",",
"const",
"char",
"*",
"extension",
")",
"{",
"int",
"flen",
"=",
"strlen",
"(",
"filename",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"3",
";",
"i",
"++",
")",
"{",
"filename",
"[",
"flen",
"-",
"1",
"-",
"i",
"]",
"=",
"'",
"\\0",
"'",
";",
"}",
"strcat",
"(",
"filename",
",",
"extension",
")",
";",
"}"
] | Function: file_ext_appender
Purpose: Get a file name and change the extension format with parameter
Return: none | [
"Function",
":",
"file_ext_appender",
"Purpose",
":",
"Get",
"a",
"file",
"name",
"and",
"change",
"the",
"extension",
"format",
"with",
"parameter",
"Return",
":",
"none"
] | [] | [
{
"param": "filename",
"type": "char"
},
{
"param": "extension",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "filename",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "extension",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5b95f04238fe2cc989eb70fe97d7e441a74740ca | catensia/SP_Project | sp20161634_proj3/assembler.c | [
"MIT"
] | C | symbol_clear | void | void symbol_clear(struct NODE **head){
struct NODE *cur=(*head);
struct NODE* next;
while(cur!=NULL){
next=cur->next;
free(cur);
cur=next;
}
*head=NULL;
} | /*---------------------------------------------------------------------*/
/*Function: symbol_clear*/
/*Purpose: removes symbol table*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | symbol_clear
Purpose: removes symbol table
Return: none | [
"symbol_clear",
"Purpose",
":",
"removes",
"symbol",
"table",
"Return",
":",
"none"
] | void symbol_clear(struct NODE **head){
struct NODE *cur=(*head);
struct NODE* next;
while(cur!=NULL){
next=cur->next;
free(cur);
cur=next;
}
*head=NULL;
} | [
"void",
"symbol_clear",
"(",
"struct",
"NODE",
"*",
"*",
"head",
")",
"{",
"struct",
"NODE",
"*",
"cur",
"=",
"(",
"*",
"head",
")",
";",
"struct",
"NODE",
"*",
"next",
";",
"while",
"(",
"cur",
"!=",
"NULL",
")",
"{",
"next",
"=",
"cur",
"->",
"next",
";",
"free",
"(",
"cur",
")",
";",
"cur",
"=",
"next",
";",
"}",
"*",
"head",
"=",
"NULL",
";",
"}"
] | Function: symbol_clear
Purpose: removes symbol table
Return: none | [
"Function",
":",
"symbol_clear",
"Purpose",
":",
"removes",
"symbol",
"table",
"Return",
":",
"none"
] | [] | [
{
"param": "head",
"type": "struct NODE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "head",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5b95f04238fe2cc989eb70fe97d7e441a74740ca | catensia/SP_Project | sp20161634_proj3/assembler.c | [
"MIT"
] | C | symtab_retval | int | int symtab_retval(const char *label, struct NODE **head){
for(struct NODE *cur=(*head);cur!=NULL;cur=cur->next){
if(!strcmp(label, cur->cmd)){
return cur->num;
}
}
return -1;
} | /*---------------------------------------------------------------------*/
/*Function: symtab_retval*/
/*Purpose: retrieves value from corresponding symbol from symbol table*/
/*Return: symbol data if exists, -1 if doesn't exists*/
/*---------------------------------------------------------------------*/ | symtab_retval
Purpose: retrieves value from corresponding symbol from symbol table
Return: symbol data if exists, -1 if doesn't exists | [
"symtab_retval",
"Purpose",
":",
"retrieves",
"value",
"from",
"corresponding",
"symbol",
"from",
"symbol",
"table",
"Return",
":",
"symbol",
"data",
"if",
"exists",
"-",
"1",
"if",
"doesn",
"'",
"t",
"exists"
] | int symtab_retval(const char *label, struct NODE **head){
for(struct NODE *cur=(*head);cur!=NULL;cur=cur->next){
if(!strcmp(label, cur->cmd)){
return cur->num;
}
}
return -1;
} | [
"int",
"symtab_retval",
"(",
"const",
"char",
"*",
"label",
",",
"struct",
"NODE",
"*",
"*",
"head",
")",
"{",
"for",
"(",
"struct",
"NODE",
"*",
"cur",
"=",
"(",
"*",
"head",
")",
";",
"cur",
"!=",
"NULL",
";",
"cur",
"=",
"cur",
"->",
"next",
")",
"{",
"if",
"(",
"!",
"strcmp",
"(",
"label",
",",
"cur",
"->",
"cmd",
")",
")",
"{",
"return",
"cur",
"->",
"num",
";",
"}",
"}",
"return",
"-1",
";",
"}"
] | Function: symtab_retval
Purpose: retrieves value from corresponding symbol from symbol table
Return: symbol data if exists, -1 if doesn't exists | [
"Function",
":",
"symtab_retval",
"Purpose",
":",
"retrieves",
"value",
"from",
"corresponding",
"symbol",
"from",
"symbol",
"table",
"Return",
":",
"symbol",
"data",
"if",
"exists",
"-",
"1",
"if",
"doesn",
"'",
"t",
"exists"
] | [] | [
{
"param": "label",
"type": "char"
},
{
"param": "head",
"type": "struct NODE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "label",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "head",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5b95f04238fe2cc989eb70fe97d7e441a74740ca | catensia/SP_Project | sp20161634_proj3/assembler.c | [
"MIT"
] | C | symtab_exist | bool | bool symtab_exist(const char *label, struct NODE **head){
for(struct NODE *cur=(*head);cur!=NULL;cur=cur->next){
if(!strcmp(label, cur->cmd)){
return true;
}
}
return false;
} | /*---------------------------------------------------------------------*/
/*Function: symtab_exist*/
/*Purpose: determine whether label exists in symbol table*/
/*Return: true if exists, false if doesn't exists*/
/*---------------------------------------------------------------------*/ | symtab_exist
Purpose: determine whether label exists in symbol table
Return: true if exists, false if doesn't exists | [
"symtab_exist",
"Purpose",
":",
"determine",
"whether",
"label",
"exists",
"in",
"symbol",
"table",
"Return",
":",
"true",
"if",
"exists",
"false",
"if",
"doesn",
"'",
"t",
"exists"
] | bool symtab_exist(const char *label, struct NODE **head){
for(struct NODE *cur=(*head);cur!=NULL;cur=cur->next){
if(!strcmp(label, cur->cmd)){
return true;
}
}
return false;
} | [
"bool",
"symtab_exist",
"(",
"const",
"char",
"*",
"label",
",",
"struct",
"NODE",
"*",
"*",
"head",
")",
"{",
"for",
"(",
"struct",
"NODE",
"*",
"cur",
"=",
"(",
"*",
"head",
")",
";",
"cur",
"!=",
"NULL",
";",
"cur",
"=",
"cur",
"->",
"next",
")",
"{",
"if",
"(",
"!",
"strcmp",
"(",
"label",
",",
"cur",
"->",
"cmd",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Function: symtab_exist
Purpose: determine whether label exists in symbol table
Return: true if exists, false if doesn't exists | [
"Function",
":",
"symtab_exist",
"Purpose",
":",
"determine",
"whether",
"label",
"exists",
"in",
"symbol",
"table",
"Return",
":",
"true",
"if",
"exists",
"false",
"if",
"doesn",
"'",
"t",
"exists"
] | [] | [
{
"param": "label",
"type": "char"
},
{
"param": "head",
"type": "struct NODE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "label",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "head",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5b95f04238fe2cc989eb70fe97d7e441a74740ca | catensia/SP_Project | sp20161634_proj3/assembler.c | [
"MIT"
] | C | symtab_add | void | void symtab_add(const char *label, int locctr, struct NODE **head){
struct NODE *newNode=(struct NODE*)malloc(sizeof(struct NODE));
strcpy(newNode->cmd, label);
newNode->num=locctr;
newNode->next=NULL;
struct NODE *cur=(*head);
if(*head==NULL || strcmp((*head)->cmd, newNode->cmd)>=0){
newNode->next=(*head);
*head=newNode;
}
else{
while(cur->next!=NULL && strcmp(cur->next->cmd,newNode->cmd)<0){
cur=cur->next;
}
newNode->next=cur->next;
cur->next=newNode;
}
} | /*---------------------------------------------------------------------*/
/*Function: symtab_add*/
/*Purpose: add data to symbol table*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | symtab_add
Purpose: add data to symbol table
Return: none | [
"symtab_add",
"Purpose",
":",
"add",
"data",
"to",
"symbol",
"table",
"Return",
":",
"none"
] | void symtab_add(const char *label, int locctr, struct NODE **head){
struct NODE *newNode=(struct NODE*)malloc(sizeof(struct NODE));
strcpy(newNode->cmd, label);
newNode->num=locctr;
newNode->next=NULL;
struct NODE *cur=(*head);
if(*head==NULL || strcmp((*head)->cmd, newNode->cmd)>=0){
newNode->next=(*head);
*head=newNode;
}
else{
while(cur->next!=NULL && strcmp(cur->next->cmd,newNode->cmd)<0){
cur=cur->next;
}
newNode->next=cur->next;
cur->next=newNode;
}
} | [
"void",
"symtab_add",
"(",
"const",
"char",
"*",
"label",
",",
"int",
"locctr",
",",
"struct",
"NODE",
"*",
"*",
"head",
")",
"{",
"struct",
"NODE",
"*",
"newNode",
"=",
"(",
"struct",
"NODE",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"struct",
"NODE",
")",
")",
";",
"strcpy",
"(",
"newNode",
"->",
"cmd",
",",
"label",
")",
";",
"newNode",
"->",
"num",
"=",
"locctr",
";",
"newNode",
"->",
"next",
"=",
"NULL",
";",
"struct",
"NODE",
"*",
"cur",
"=",
"(",
"*",
"head",
")",
";",
"if",
"(",
"*",
"head",
"==",
"NULL",
"||",
"strcmp",
"(",
"(",
"*",
"head",
")",
"->",
"cmd",
",",
"newNode",
"->",
"cmd",
")",
">=",
"0",
")",
"{",
"newNode",
"->",
"next",
"=",
"(",
"*",
"head",
")",
";",
"*",
"head",
"=",
"newNode",
";",
"}",
"else",
"{",
"while",
"(",
"cur",
"->",
"next",
"!=",
"NULL",
"&&",
"strcmp",
"(",
"cur",
"->",
"next",
"->",
"cmd",
",",
"newNode",
"->",
"cmd",
")",
"<",
"0",
")",
"{",
"cur",
"=",
"cur",
"->",
"next",
";",
"}",
"newNode",
"->",
"next",
"=",
"cur",
"->",
"next",
";",
"cur",
"->",
"next",
"=",
"newNode",
";",
"}",
"}"
] | Function: symtab_add
Purpose: add data to symbol table
Return: none | [
"Function",
":",
"symtab_add",
"Purpose",
":",
"add",
"data",
"to",
"symbol",
"table",
"Return",
":",
"none"
] | [] | [
{
"param": "label",
"type": "char"
},
{
"param": "locctr",
"type": "int"
},
{
"param": "head",
"type": "struct NODE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "label",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "locctr",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "head",
"type": "struct NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5b95f04238fe2cc989eb70fe97d7e441a74740ca | catensia/SP_Project | sp20161634_proj3/assembler.c | [
"MIT"
] | C | is_register | int | int is_register(const char *operand){
if(!strcmp(operand,"A")) return 0;
if(!strcmp(operand,"X")) return 1;
if(!strcmp(operand,"L")) return 2;
if(!strcmp(operand,"B")) return 3;
if(!strcmp(operand,"S")) return 4;
if(!strcmp(operand,"T")) return 5;
if(!strcmp(operand,"F")) return 6;
if(!strcmp(operand,"PC")) return 8;
if(!strcmp(operand,"SW")) return 9;
return -1;
} | /*---------------------------------------------------------------------*/
/*Function: is_register*/
/*Purpose: checks if given string is a register*/
/*Return: corresponding register number, -1 if not a register*/
/*---------------------------------------------------------------------*/ | is_register
Purpose: checks if given string is a register
Return: corresponding register number, -1 if not a register | [
"is_register",
"Purpose",
":",
"checks",
"if",
"given",
"string",
"is",
"a",
"register",
"Return",
":",
"corresponding",
"register",
"number",
"-",
"1",
"if",
"not",
"a",
"register"
] | int is_register(const char *operand){
if(!strcmp(operand,"A")) return 0;
if(!strcmp(operand,"X")) return 1;
if(!strcmp(operand,"L")) return 2;
if(!strcmp(operand,"B")) return 3;
if(!strcmp(operand,"S")) return 4;
if(!strcmp(operand,"T")) return 5;
if(!strcmp(operand,"F")) return 6;
if(!strcmp(operand,"PC")) return 8;
if(!strcmp(operand,"SW")) return 9;
return -1;
} | [
"int",
"is_register",
"(",
"const",
"char",
"*",
"operand",
")",
"{",
"if",
"(",
"!",
"strcmp",
"(",
"operand",
",",
"\"",
"\"",
")",
")",
"return",
"0",
";",
"if",
"(",
"!",
"strcmp",
"(",
"operand",
",",
"\"",
"\"",
")",
")",
"return",
"1",
";",
"if",
"(",
"!",
"strcmp",
"(",
"operand",
",",
"\"",
"\"",
")",
")",
"return",
"2",
";",
"if",
"(",
"!",
"strcmp",
"(",
"operand",
",",
"\"",
"\"",
")",
")",
"return",
"3",
";",
"if",
"(",
"!",
"strcmp",
"(",
"operand",
",",
"\"",
"\"",
")",
")",
"return",
"4",
";",
"if",
"(",
"!",
"strcmp",
"(",
"operand",
",",
"\"",
"\"",
")",
")",
"return",
"5",
";",
"if",
"(",
"!",
"strcmp",
"(",
"operand",
",",
"\"",
"\"",
")",
")",
"return",
"6",
";",
"if",
"(",
"!",
"strcmp",
"(",
"operand",
",",
"\"",
"\"",
")",
")",
"return",
"8",
";",
"if",
"(",
"!",
"strcmp",
"(",
"operand",
",",
"\"",
"\"",
")",
")",
"return",
"9",
";",
"return",
"-1",
";",
"}"
] | Function: is_register
Purpose: checks if given string is a register
Return: corresponding register number, -1 if not a register | [
"Function",
":",
"is_register",
"Purpose",
":",
"checks",
"if",
"given",
"string",
"is",
"a",
"register",
"Return",
":",
"corresponding",
"register",
"number",
"-",
"1",
"if",
"not",
"a",
"register"
] | [] | [
{
"param": "operand",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "operand",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5b95f04238fe2cc989eb70fe97d7e441a74740ca | catensia/SP_Project | sp20161634_proj3/assembler.c | [
"MIT"
] | C | appendString | void | void appendString(char *target, int xbpe, int temp, int mode, bool indexed){
char xbpe_str[5];
char OPADR_str[10];
char t[10];
sprintf(xbpe_str, "%X", xbpe);
if(mode==0){
strcat(target, xbpe_str);
if(temp>=0){
sprintf(OPADR_str, "%03X", temp);
strcat(target, OPADR_str);
}
else{
sprintf(t, "%X", temp);
int tlen=strlen(t);
for(int i=0;i<4;i++){
t[i]=t[i+tlen-3];
}
strcat(target, t);
}
}
if(mode==1){
if(temp>=0){
if(!indexed) sprintf(OPADR_str, "1%05X", temp);
else sprintf(OPADR_str, "9%05X", temp);
strcat(target, OPADR_str);
}
else{
sprintf(t, "%X", temp);
int tlen=strlen(t);
for(int i=0;i<6;i++){
t[i]=t[i+tlen-5];
}
strcat(target, t);
}
}
} | /*---------------------------------------------------------------------*/
/*Function: appendString*/
/*Purpose: Makes object code and prints into corresponding files*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | appendString
Purpose: Makes object code and prints into corresponding files
Return: none | [
"appendString",
"Purpose",
":",
"Makes",
"object",
"code",
"and",
"prints",
"into",
"corresponding",
"files",
"Return",
":",
"none"
] | void appendString(char *target, int xbpe, int temp, int mode, bool indexed){
char xbpe_str[5];
char OPADR_str[10];
char t[10];
sprintf(xbpe_str, "%X", xbpe);
if(mode==0){
strcat(target, xbpe_str);
if(temp>=0){
sprintf(OPADR_str, "%03X", temp);
strcat(target, OPADR_str);
}
else{
sprintf(t, "%X", temp);
int tlen=strlen(t);
for(int i=0;i<4;i++){
t[i]=t[i+tlen-3];
}
strcat(target, t);
}
}
if(mode==1){
if(temp>=0){
if(!indexed) sprintf(OPADR_str, "1%05X", temp);
else sprintf(OPADR_str, "9%05X", temp);
strcat(target, OPADR_str);
}
else{
sprintf(t, "%X", temp);
int tlen=strlen(t);
for(int i=0;i<6;i++){
t[i]=t[i+tlen-5];
}
strcat(target, t);
}
}
} | [
"void",
"appendString",
"(",
"char",
"*",
"target",
",",
"int",
"xbpe",
",",
"int",
"temp",
",",
"int",
"mode",
",",
"bool",
"indexed",
")",
"{",
"char",
"xbpe_str",
"[",
"5",
"]",
";",
"char",
"OPADR_str",
"[",
"10",
"]",
";",
"char",
"t",
"[",
"10",
"]",
";",
"sprintf",
"(",
"xbpe_str",
",",
"\"",
"\"",
",",
"xbpe",
")",
";",
"if",
"(",
"mode",
"==",
"0",
")",
"{",
"strcat",
"(",
"target",
",",
"xbpe_str",
")",
";",
"if",
"(",
"temp",
">=",
"0",
")",
"{",
"sprintf",
"(",
"OPADR_str",
",",
"\"",
"\"",
",",
"temp",
")",
";",
"strcat",
"(",
"target",
",",
"OPADR_str",
")",
";",
"}",
"else",
"{",
"sprintf",
"(",
"t",
",",
"\"",
"\"",
",",
"temp",
")",
";",
"int",
"tlen",
"=",
"strlen",
"(",
"t",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
")",
"{",
"t",
"[",
"i",
"]",
"=",
"t",
"[",
"i",
"+",
"tlen",
"-",
"3",
"]",
";",
"}",
"strcat",
"(",
"target",
",",
"t",
")",
";",
"}",
"}",
"if",
"(",
"mode",
"==",
"1",
")",
"{",
"if",
"(",
"temp",
">=",
"0",
")",
"{",
"if",
"(",
"!",
"indexed",
")",
"sprintf",
"(",
"OPADR_str",
",",
"\"",
"\"",
",",
"temp",
")",
";",
"else",
"sprintf",
"(",
"OPADR_str",
",",
"\"",
"\"",
",",
"temp",
")",
";",
"strcat",
"(",
"target",
",",
"OPADR_str",
")",
";",
"}",
"else",
"{",
"sprintf",
"(",
"t",
",",
"\"",
"\"",
",",
"temp",
")",
";",
"int",
"tlen",
"=",
"strlen",
"(",
"t",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"6",
";",
"i",
"++",
")",
"{",
"t",
"[",
"i",
"]",
"=",
"t",
"[",
"i",
"+",
"tlen",
"-",
"5",
"]",
";",
"}",
"strcat",
"(",
"target",
",",
"t",
")",
";",
"}",
"}",
"}"
] | Function: appendString
Purpose: Makes object code and prints into corresponding files
Return: none | [
"Function",
":",
"appendString",
"Purpose",
":",
"Makes",
"object",
"code",
"and",
"prints",
"into",
"corresponding",
"files",
"Return",
":",
"none"
] | [] | [
{
"param": "target",
"type": "char"
},
{
"param": "xbpe",
"type": "int"
},
{
"param": "temp",
"type": "int"
},
{
"param": "mode",
"type": "int"
},
{
"param": "indexed",
"type": "bool"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "target",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "xbpe",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "temp",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "mode",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "indexed",
"type": "bool",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5b95f04238fe2cc989eb70fe97d7e441a74740ca | catensia/SP_Project | sp20161634_proj3/assembler.c | [
"MIT"
] | C | LSTprinter | void | void LSTprinter(int line_number, int LOCCTR, const char *label, const char *opcode, const char *oper, const char*idx, bool index_exists){
printf("%d\t", line_number);
if(LOCCTR!=-1) printf("%04X\t", LOCCTR);
else printf("\t");
if(label[0]!='*') printf("%s\t", label);
else printf("\t");
if(opcode[0]!='*') printf("%s\t", opcode);
else printf("\t");
if(index_exists){
//BUFFER, X
if(strlen(oper)+strlen(idx)>5) printf("%s, %s ", oper, idx);
else printf("%s, %s\t", oper, idx);
}
else{
if(oper[0]!='*') printf("%s\t", oper);
else printf("\t");
}
printf("\t");
} | /*---------------------------------------------------------------------*/
/*Function: LSTprinter*/
/*Purpose: prints to console with format (for debugging)*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | LSTprinter
Purpose: prints to console with format (for debugging)
Return: none | [
"LSTprinter",
"Purpose",
":",
"prints",
"to",
"console",
"with",
"format",
"(",
"for",
"debugging",
")",
"Return",
":",
"none"
] | void LSTprinter(int line_number, int LOCCTR, const char *label, const char *opcode, const char *oper, const char*idx, bool index_exists){
printf("%d\t", line_number);
if(LOCCTR!=-1) printf("%04X\t", LOCCTR);
else printf("\t");
if(label[0]!='*') printf("%s\t", label);
else printf("\t");
if(opcode[0]!='*') printf("%s\t", opcode);
else printf("\t");
if(index_exists){
if(strlen(oper)+strlen(idx)>5) printf("%s, %s ", oper, idx);
else printf("%s, %s\t", oper, idx);
}
else{
if(oper[0]!='*') printf("%s\t", oper);
else printf("\t");
}
printf("\t");
} | [
"void",
"LSTprinter",
"(",
"int",
"line_number",
",",
"int",
"LOCCTR",
",",
"const",
"char",
"*",
"label",
",",
"const",
"char",
"*",
"opcode",
",",
"const",
"char",
"*",
"oper",
",",
"const",
"char",
"*",
"idx",
",",
"bool",
"index_exists",
")",
"{",
"printf",
"(",
"\"",
"\\t",
"\"",
",",
"line_number",
")",
";",
"if",
"(",
"LOCCTR",
"!=",
"-1",
")",
"printf",
"(",
"\"",
"\\t",
"\"",
",",
"LOCCTR",
")",
";",
"else",
"printf",
"(",
"\"",
"\\t",
"\"",
")",
";",
"if",
"(",
"label",
"[",
"0",
"]",
"!=",
"'",
"'",
")",
"printf",
"(",
"\"",
"\\t",
"\"",
",",
"label",
")",
";",
"else",
"printf",
"(",
"\"",
"\\t",
"\"",
")",
";",
"if",
"(",
"opcode",
"[",
"0",
"]",
"!=",
"'",
"'",
")",
"printf",
"(",
"\"",
"\\t",
"\"",
",",
"opcode",
")",
";",
"else",
"printf",
"(",
"\"",
"\\t",
"\"",
")",
";",
"if",
"(",
"index_exists",
")",
"{",
"if",
"(",
"strlen",
"(",
"oper",
")",
"+",
"strlen",
"(",
"idx",
")",
">",
"5",
")",
"printf",
"(",
"\"",
"\"",
",",
"oper",
",",
"idx",
")",
";",
"else",
"printf",
"(",
"\"",
"\\t",
"\"",
",",
"oper",
",",
"idx",
")",
";",
"}",
"else",
"{",
"if",
"(",
"oper",
"[",
"0",
"]",
"!=",
"'",
"'",
")",
"printf",
"(",
"\"",
"\\t",
"\"",
",",
"oper",
")",
";",
"else",
"printf",
"(",
"\"",
"\\t",
"\"",
")",
";",
"}",
"printf",
"(",
"\"",
"\\t",
"\"",
")",
";",
"}"
] | Function: LSTprinter
Purpose: prints to console with format (for debugging)
Return: none | [
"Function",
":",
"LSTprinter",
"Purpose",
":",
"prints",
"to",
"console",
"with",
"format",
"(",
"for",
"debugging",
")",
"Return",
":",
"none"
] | [
"//BUFFER, X "
] | [
{
"param": "line_number",
"type": "int"
},
{
"param": "LOCCTR",
"type": "int"
},
{
"param": "label",
"type": "char"
},
{
"param": "opcode",
"type": "char"
},
{
"param": "oper",
"type": "char"
},
{
"param": "idx",
"type": "char"
},
{
"param": "index_exists",
"type": "bool"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "line_number",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "LOCCTR",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "label",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "opcode",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "oper",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "idx",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "index_exists",
"type": "bool",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5b95f04238fe2cc989eb70fe97d7e441a74740ca | catensia/SP_Project | sp20161634_proj3/assembler.c | [
"MIT"
] | C | LSTfprinter | void | void LSTfprinter(FILE *fp, int line_number, int LOCCTR, const char *label, const char *opcode, const char *oper, const char*idx, bool index_exists){
fprintf(fp, "%d\t", line_number);
if(LOCCTR!=-1) fprintf(fp, "%04X\t", LOCCTR);
else fprintf(fp, "\t");
if(label[0]!='*') fprintf(fp, "%s\t", label);
else fprintf(fp, "\t");
if(opcode[0]!='*') fprintf(fp, "%s\t", opcode);
else fprintf(fp, "\t");
if(index_exists){
//BUFFER, X
if(strlen(oper)+strlen(idx)>5) fprintf(fp, "%s, %s ", oper, idx);
else fprintf(fp, "%s, %s\t", oper, idx);
}
else{
if(oper[0]!='*') fprintf(fp, "%s\t", oper);
else fprintf(fp, "\t");
}
fprintf(fp, "\t");
} | /*---------------------------------------------------------------------*/
/*Function: LSTfprinter*/
/*Purpose: prints to listing file with format*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | LSTfprinter
Purpose: prints to listing file with format
Return: none | [
"LSTfprinter",
"Purpose",
":",
"prints",
"to",
"listing",
"file",
"with",
"format",
"Return",
":",
"none"
] | void LSTfprinter(FILE *fp, int line_number, int LOCCTR, const char *label, const char *opcode, const char *oper, const char*idx, bool index_exists){
fprintf(fp, "%d\t", line_number);
if(LOCCTR!=-1) fprintf(fp, "%04X\t", LOCCTR);
else fprintf(fp, "\t");
if(label[0]!='*') fprintf(fp, "%s\t", label);
else fprintf(fp, "\t");
if(opcode[0]!='*') fprintf(fp, "%s\t", opcode);
else fprintf(fp, "\t");
if(index_exists){
if(strlen(oper)+strlen(idx)>5) fprintf(fp, "%s, %s ", oper, idx);
else fprintf(fp, "%s, %s\t", oper, idx);
}
else{
if(oper[0]!='*') fprintf(fp, "%s\t", oper);
else fprintf(fp, "\t");
}
fprintf(fp, "\t");
} | [
"void",
"LSTfprinter",
"(",
"FILE",
"*",
"fp",
",",
"int",
"line_number",
",",
"int",
"LOCCTR",
",",
"const",
"char",
"*",
"label",
",",
"const",
"char",
"*",
"opcode",
",",
"const",
"char",
"*",
"oper",
",",
"const",
"char",
"*",
"idx",
",",
"bool",
"index_exists",
")",
"{",
"fprintf",
"(",
"fp",
",",
"\"",
"\\t",
"\"",
",",
"line_number",
")",
";",
"if",
"(",
"LOCCTR",
"!=",
"-1",
")",
"fprintf",
"(",
"fp",
",",
"\"",
"\\t",
"\"",
",",
"LOCCTR",
")",
";",
"else",
"fprintf",
"(",
"fp",
",",
"\"",
"\\t",
"\"",
")",
";",
"if",
"(",
"label",
"[",
"0",
"]",
"!=",
"'",
"'",
")",
"fprintf",
"(",
"fp",
",",
"\"",
"\\t",
"\"",
",",
"label",
")",
";",
"else",
"fprintf",
"(",
"fp",
",",
"\"",
"\\t",
"\"",
")",
";",
"if",
"(",
"opcode",
"[",
"0",
"]",
"!=",
"'",
"'",
")",
"fprintf",
"(",
"fp",
",",
"\"",
"\\t",
"\"",
",",
"opcode",
")",
";",
"else",
"fprintf",
"(",
"fp",
",",
"\"",
"\\t",
"\"",
")",
";",
"if",
"(",
"index_exists",
")",
"{",
"if",
"(",
"strlen",
"(",
"oper",
")",
"+",
"strlen",
"(",
"idx",
")",
">",
"5",
")",
"fprintf",
"(",
"fp",
",",
"\"",
"\"",
",",
"oper",
",",
"idx",
")",
";",
"else",
"fprintf",
"(",
"fp",
",",
"\"",
"\\t",
"\"",
",",
"oper",
",",
"idx",
")",
";",
"}",
"else",
"{",
"if",
"(",
"oper",
"[",
"0",
"]",
"!=",
"'",
"'",
")",
"fprintf",
"(",
"fp",
",",
"\"",
"\\t",
"\"",
",",
"oper",
")",
";",
"else",
"fprintf",
"(",
"fp",
",",
"\"",
"\\t",
"\"",
")",
";",
"}",
"fprintf",
"(",
"fp",
",",
"\"",
"\\t",
"\"",
")",
";",
"}"
] | Function: LSTfprinter
Purpose: prints to listing file with format
Return: none | [
"Function",
":",
"LSTfprinter",
"Purpose",
":",
"prints",
"to",
"listing",
"file",
"with",
"format",
"Return",
":",
"none"
] | [
"//BUFFER, X "
] | [
{
"param": "fp",
"type": "FILE"
},
{
"param": "line_number",
"type": "int"
},
{
"param": "LOCCTR",
"type": "int"
},
{
"param": "label",
"type": "char"
},
{
"param": "opcode",
"type": "char"
},
{
"param": "oper",
"type": "char"
},
{
"param": "idx",
"type": "char"
},
{
"param": "index_exists",
"type": "bool"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "fp",
"type": "FILE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "line_number",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "LOCCTR",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "label",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "opcode",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "oper",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "idx",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "index_exists",
"type": "bool",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5b95f04238fe2cc989eb70fe97d7e441a74740ca | catensia/SP_Project | sp20161634_proj3/assembler.c | [
"MIT"
] | C | onlynumber | bool | bool onlynumber(const char *s){
for(int i=0;i<strlen(s);i++){
if(!(s[i]>='0' && s[i]<='9')) return false;
}
return true;
} | /*---------------------------------------------------------------------*/
/*Function: onlynumber*/
/*Purpose: checks if string contains only digits*/
/*Return: true/false*/
/*---------------------------------------------------------------------*/ | onlynumber
Purpose: checks if string contains only digits
Return: true/false | [
"onlynumber",
"Purpose",
":",
"checks",
"if",
"string",
"contains",
"only",
"digits",
"Return",
":",
"true",
"/",
"false"
] | bool onlynumber(const char *s){
for(int i=0;i<strlen(s);i++){
if(!(s[i]>='0' && s[i]<='9')) return false;
}
return true;
} | [
"bool",
"onlynumber",
"(",
"const",
"char",
"*",
"s",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"strlen",
"(",
"s",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"(",
"s",
"[",
"i",
"]",
">=",
"'",
"'",
"&&",
"s",
"[",
"i",
"]",
"<=",
"'",
"'",
")",
")",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Function: onlynumber
Purpose: checks if string contains only digits
Return: true/false | [
"Function",
":",
"onlynumber",
"Purpose",
":",
"checks",
"if",
"string",
"contains",
"only",
"digits",
"Return",
":",
"true",
"/",
"false"
] | [] | [
{
"param": "s",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "s",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5b95f04238fe2cc989eb70fe97d7e441a74740ca | catensia/SP_Project | sp20161634_proj3/assembler.c | [
"MIT"
] | C | myparser | null | struct INST myparser(const char *line, int line_number){
struct INST cur;
cur.comment=false;
cur.line_number=line_number;
cur.format=-1;
int words=0;
char label[30], opcode[30], oper[30], idx[30], trash[30];
//INITIALIZE VALUES
cur.label[0]=cur.opcode[0]=cur.oper[0]=cur.idx[0]=cur.trash[0]='\0';
label[0]=opcode[0]=oper[0]=idx[0]=trash[0]='\0';
words=sscanf(line, "%s %s %s %s %s", label, opcode, oper, idx, trash);
//IF + is in front of OPCODE format 4
if(label[0]=='+'){
for(int i=0;i<strlen(label);i++) label[i]=label[i+1]; cur.format=4;
}
if(opcode[0]=='+'){
for(int i=0;i<strlen(opcode);i++) opcode[i]=opcode[i+1]; cur.format=4;
}
int oper_len=strlen(oper), opcode_len=strlen(opcode);
//assembler directives without labels
if(words==2 && !strcmp(label, "END")){
cur.type=4;
strcpy(oper, opcode);
strcpy(opcode, label);
label[0]='\0';
copy_strings(&cur, label, opcode, oper, idx);
return cur;
}
if(words==2 && !strcmp(label, "BASE")){
cur.type=4;
strcpy(oper, opcode);
strcpy(opcode, label);
label[0]='\0';
copy_strings(&cur, label, opcode, oper, idx);
return cur;
}
if(label[0]=='.'){
//LINE IS COMMENT
cur.comment=true;
return cur;
}
if(words==4 && oper[oper_len-1]==','){
//LABEL OPCODE OPERAND, INDEX
cur.type=1;
oper[oper_len-1]='\0';
copy_strings(&cur, label, opcode, oper, idx);
return cur;
}
else if(words==3 && idx[0]=='\0'){
if(opcode[opcode_len-1]==','){
// OPCODE OPERAND, INDEX
strcpy(idx, oper); strcpy(oper, opcode); strcpy(opcode, label);
oper_len=strlen(oper);
oper[oper_len-1]='\0';
label[0]='\0';
cur.type=2;
copy_strings(&cur, label, opcode, oper, idx);
return cur;
}
else{
// LABEL OPCODE OPERAND
cur.type=3;
copy_strings(&cur, label, opcode, oper, idx);
return cur;
}
}
else if(words==2 && idx[0]=='\0' && oper[0]=='\0'){
if(op_return(label, hash)!=-1){
//OPCODE OPERAND
cur.type=4;
strcpy(oper, opcode); strcpy(opcode, label);
label[0]='\0';
}
else if(op_return(opcode, hash)!=-1){
//LABEL OPCODE
cur.type=5;
}
else{
//NO OPCODE PRESENT (set errorflag)
cur.type=-1;
}
copy_strings(&cur, label, opcode, oper, idx);
return cur;
}
else if(words==1){
cur.type=6;
strcpy(opcode, label);
label[0]='\0';
copy_strings(&cur, label, opcode, oper, idx);
return cur;
}
else{
//CALL DEBUGGER
cur.type=-1;
printf("ERROR AT LINE %d\n", line_number);
return cur;
}
} | /*---------------------------------------------------------------------*/
/*Function: myparser*/
/*Purpose: tokenizes given string*/
/*Return: a struct containing tokenized information*/
/*---------------------------------------------------------------------*/ | myparser
Purpose: tokenizes given string
Return: a struct containing tokenized information | [
"myparser",
"Purpose",
":",
"tokenizes",
"given",
"string",
"Return",
":",
"a",
"struct",
"containing",
"tokenized",
"information"
] | struct INST myparser(const char *line, int line_number){
struct INST cur;
cur.comment=false;
cur.line_number=line_number;
cur.format=-1;
int words=0;
char label[30], opcode[30], oper[30], idx[30], trash[30];
cur.label[0]=cur.opcode[0]=cur.oper[0]=cur.idx[0]=cur.trash[0]='\0';
label[0]=opcode[0]=oper[0]=idx[0]=trash[0]='\0';
words=sscanf(line, "%s %s %s %s %s", label, opcode, oper, idx, trash);
if(label[0]=='+'){
for(int i=0;i<strlen(label);i++) label[i]=label[i+1]; cur.format=4;
}
if(opcode[0]=='+'){
for(int i=0;i<strlen(opcode);i++) opcode[i]=opcode[i+1]; cur.format=4;
}
int oper_len=strlen(oper), opcode_len=strlen(opcode);
if(words==2 && !strcmp(label, "END")){
cur.type=4;
strcpy(oper, opcode);
strcpy(opcode, label);
label[0]='\0';
copy_strings(&cur, label, opcode, oper, idx);
return cur;
}
if(words==2 && !strcmp(label, "BASE")){
cur.type=4;
strcpy(oper, opcode);
strcpy(opcode, label);
label[0]='\0';
copy_strings(&cur, label, opcode, oper, idx);
return cur;
}
if(label[0]=='.'){
cur.comment=true;
return cur;
}
if(words==4 && oper[oper_len-1]==','){
cur.type=1;
oper[oper_len-1]='\0';
copy_strings(&cur, label, opcode, oper, idx);
return cur;
}
else if(words==3 && idx[0]=='\0'){
if(opcode[opcode_len-1]==','){
strcpy(idx, oper); strcpy(oper, opcode); strcpy(opcode, label);
oper_len=strlen(oper);
oper[oper_len-1]='\0';
label[0]='\0';
cur.type=2;
copy_strings(&cur, label, opcode, oper, idx);
return cur;
}
else{
cur.type=3;
copy_strings(&cur, label, opcode, oper, idx);
return cur;
}
}
else if(words==2 && idx[0]=='\0' && oper[0]=='\0'){
if(op_return(label, hash)!=-1){
cur.type=4;
strcpy(oper, opcode); strcpy(opcode, label);
label[0]='\0';
}
else if(op_return(opcode, hash)!=-1){
cur.type=5;
}
else{
cur.type=-1;
}
copy_strings(&cur, label, opcode, oper, idx);
return cur;
}
else if(words==1){
cur.type=6;
strcpy(opcode, label);
label[0]='\0';
copy_strings(&cur, label, opcode, oper, idx);
return cur;
}
else{
cur.type=-1;
printf("ERROR AT LINE %d\n", line_number);
return cur;
}
} | [
"struct",
"INST",
"myparser",
"(",
"const",
"char",
"*",
"line",
",",
"int",
"line_number",
")",
"{",
"struct",
"INST",
"cur",
";",
"cur",
".",
"comment",
"=",
"false",
";",
"cur",
".",
"line_number",
"=",
"line_number",
";",
"cur",
".",
"format",
"=",
"-1",
";",
"int",
"words",
"=",
"0",
";",
"char",
"label",
"[",
"30",
"]",
",",
"opcode",
"[",
"30",
"]",
",",
"oper",
"[",
"30",
"]",
",",
"idx",
"[",
"30",
"]",
",",
"trash",
"[",
"30",
"]",
";",
"cur",
".",
"label",
"[",
"0",
"]",
"=",
"cur",
".",
"opcode",
"[",
"0",
"]",
"=",
"cur",
".",
"oper",
"[",
"0",
"]",
"=",
"cur",
".",
"idx",
"[",
"0",
"]",
"=",
"cur",
".",
"trash",
"[",
"0",
"]",
"=",
"'",
"\\0",
"'",
";",
"label",
"[",
"0",
"]",
"=",
"opcode",
"[",
"0",
"]",
"=",
"oper",
"[",
"0",
"]",
"=",
"idx",
"[",
"0",
"]",
"=",
"trash",
"[",
"0",
"]",
"=",
"'",
"\\0",
"'",
";",
"words",
"=",
"sscanf",
"(",
"line",
",",
"\"",
"\"",
",",
"label",
",",
"opcode",
",",
"oper",
",",
"idx",
",",
"trash",
")",
";",
"if",
"(",
"label",
"[",
"0",
"]",
"==",
"'",
"'",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"strlen",
"(",
"label",
")",
";",
"i",
"++",
")",
"label",
"[",
"i",
"]",
"=",
"label",
"[",
"i",
"+",
"1",
"]",
";",
"cur",
".",
"format",
"=",
"4",
";",
"}",
"if",
"(",
"opcode",
"[",
"0",
"]",
"==",
"'",
"'",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"strlen",
"(",
"opcode",
")",
";",
"i",
"++",
")",
"opcode",
"[",
"i",
"]",
"=",
"opcode",
"[",
"i",
"+",
"1",
"]",
";",
"cur",
".",
"format",
"=",
"4",
";",
"}",
"int",
"oper_len",
"=",
"strlen",
"(",
"oper",
")",
",",
"opcode_len",
"=",
"strlen",
"(",
"opcode",
")",
";",
"if",
"(",
"words",
"==",
"2",
"&&",
"!",
"strcmp",
"(",
"label",
",",
"\"",
"\"",
")",
")",
"{",
"cur",
".",
"type",
"=",
"4",
";",
"strcpy",
"(",
"oper",
",",
"opcode",
")",
";",
"strcpy",
"(",
"opcode",
",",
"label",
")",
";",
"label",
"[",
"0",
"]",
"=",
"'",
"\\0",
"'",
";",
"copy_strings",
"(",
"&",
"cur",
",",
"label",
",",
"opcode",
",",
"oper",
",",
"idx",
")",
";",
"return",
"cur",
";",
"}",
"if",
"(",
"words",
"==",
"2",
"&&",
"!",
"strcmp",
"(",
"label",
",",
"\"",
"\"",
")",
")",
"{",
"cur",
".",
"type",
"=",
"4",
";",
"strcpy",
"(",
"oper",
",",
"opcode",
")",
";",
"strcpy",
"(",
"opcode",
",",
"label",
")",
";",
"label",
"[",
"0",
"]",
"=",
"'",
"\\0",
"'",
";",
"copy_strings",
"(",
"&",
"cur",
",",
"label",
",",
"opcode",
",",
"oper",
",",
"idx",
")",
";",
"return",
"cur",
";",
"}",
"if",
"(",
"label",
"[",
"0",
"]",
"==",
"'",
"'",
")",
"{",
"cur",
".",
"comment",
"=",
"true",
";",
"return",
"cur",
";",
"}",
"if",
"(",
"words",
"==",
"4",
"&&",
"oper",
"[",
"oper_len",
"-",
"1",
"]",
"==",
"'",
"'",
")",
"{",
"cur",
".",
"type",
"=",
"1",
";",
"oper",
"[",
"oper_len",
"-",
"1",
"]",
"=",
"'",
"\\0",
"'",
";",
"copy_strings",
"(",
"&",
"cur",
",",
"label",
",",
"opcode",
",",
"oper",
",",
"idx",
")",
";",
"return",
"cur",
";",
"}",
"else",
"if",
"(",
"words",
"==",
"3",
"&&",
"idx",
"[",
"0",
"]",
"==",
"'",
"\\0",
"'",
")",
"{",
"if",
"(",
"opcode",
"[",
"opcode_len",
"-",
"1",
"]",
"==",
"'",
"'",
")",
"{",
"strcpy",
"(",
"idx",
",",
"oper",
")",
";",
"strcpy",
"(",
"oper",
",",
"opcode",
")",
";",
"strcpy",
"(",
"opcode",
",",
"label",
")",
";",
"oper_len",
"=",
"strlen",
"(",
"oper",
")",
";",
"oper",
"[",
"oper_len",
"-",
"1",
"]",
"=",
"'",
"\\0",
"'",
";",
"label",
"[",
"0",
"]",
"=",
"'",
"\\0",
"'",
";",
"cur",
".",
"type",
"=",
"2",
";",
"copy_strings",
"(",
"&",
"cur",
",",
"label",
",",
"opcode",
",",
"oper",
",",
"idx",
")",
";",
"return",
"cur",
";",
"}",
"else",
"{",
"cur",
".",
"type",
"=",
"3",
";",
"copy_strings",
"(",
"&",
"cur",
",",
"label",
",",
"opcode",
",",
"oper",
",",
"idx",
")",
";",
"return",
"cur",
";",
"}",
"}",
"else",
"if",
"(",
"words",
"==",
"2",
"&&",
"idx",
"[",
"0",
"]",
"==",
"'",
"\\0",
"'",
"&&",
"oper",
"[",
"0",
"]",
"==",
"'",
"\\0",
"'",
")",
"{",
"if",
"(",
"op_return",
"(",
"label",
",",
"hash",
")",
"!=",
"-1",
")",
"{",
"cur",
".",
"type",
"=",
"4",
";",
"strcpy",
"(",
"oper",
",",
"opcode",
")",
";",
"strcpy",
"(",
"opcode",
",",
"label",
")",
";",
"label",
"[",
"0",
"]",
"=",
"'",
"\\0",
"'",
";",
"}",
"else",
"if",
"(",
"op_return",
"(",
"opcode",
",",
"hash",
")",
"!=",
"-1",
")",
"{",
"cur",
".",
"type",
"=",
"5",
";",
"}",
"else",
"{",
"cur",
".",
"type",
"=",
"-1",
";",
"}",
"copy_strings",
"(",
"&",
"cur",
",",
"label",
",",
"opcode",
",",
"oper",
",",
"idx",
")",
";",
"return",
"cur",
";",
"}",
"else",
"if",
"(",
"words",
"==",
"1",
")",
"{",
"cur",
".",
"type",
"=",
"6",
";",
"strcpy",
"(",
"opcode",
",",
"label",
")",
";",
"label",
"[",
"0",
"]",
"=",
"'",
"\\0",
"'",
";",
"copy_strings",
"(",
"&",
"cur",
",",
"label",
",",
"opcode",
",",
"oper",
",",
"idx",
")",
";",
"return",
"cur",
";",
"}",
"else",
"{",
"cur",
".",
"type",
"=",
"-1",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"line_number",
")",
";",
"return",
"cur",
";",
"}",
"}"
] | Function: myparser
Purpose: tokenizes given string
Return: a struct containing tokenized information | [
"Function",
":",
"myparser",
"Purpose",
":",
"tokenizes",
"given",
"string",
"Return",
":",
"a",
"struct",
"containing",
"tokenized",
"information"
] | [
"//INITIALIZE VALUES",
"//IF + is in front of OPCODE format 4",
"//assembler directives without labels",
"//LINE IS COMMENT",
"//LABEL OPCODE OPERAND, INDEX",
"// OPCODE OPERAND, INDEX",
"// LABEL OPCODE OPERAND",
"//OPCODE OPERAND",
"//LABEL OPCODE",
"//NO OPCODE PRESENT (set errorflag)",
"//CALL DEBUGGER"
] | [
{
"param": "line",
"type": "char"
},
{
"param": "line_number",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "line",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "line_number",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
688ebacdd264d0e2bc533bd6050a605532db72d5 | catensia/SP_Project | sp20161634_proj4/Phase2/myshell.c | [
"MIT"
] | C | eval | void | void eval(char *cmdline)
{
char *argv[MAXARGS]; /* Argument list execve() */
char buf[MAXLINE]; /* Holds modified command line */
int bg; /* Should the job run in bg or fg? */
pid_t pid; /* Process id */
int fds[2]; // file descriptors
int argn; // temporary buffer to parse
char carg[MAXLINE];
MEMSET(carg);
int p;
if((p=pipe(fds))==-1){
printf("pipe error\n");
exit(0);
}
strcpy(buf, cmdline);
bg = parseline(buf, argv);
pipe_num=calc_pipe_num(argv);
argn=argnum(argv); //calculate argnum
if (argv[0] == NULL) {
return; /* Ignore empty lines */
}
if (!builtin_command(argv)) { //quit -> exit(0), & -> ignore, other -> run
pid=Fork();
if(pid==-1) PERROR_EXIT("fork error");
else if(pid==0){
//child process
int temp = pipe_execute(0, argv, STDIN_FILENO, argn, 0);
}
/* Parent waits for foreground job to terminate */
if (!bg){
int status;
}
else//when there is backgrount process!
printf("%d %s", pid, cmdline);
}
return;
} | /* $begin eval */
/* eval - Evaluate a command line */ | $begin eval
eval - Evaluate a command line | [
"$begin",
"eval",
"eval",
"-",
"Evaluate",
"a",
"command",
"line"
] | void eval(char *cmdline)
{
char *argv[MAXARGS];
char buf[MAXLINE];
int bg;
pid_t pid;
int fds[2];
int argn;
char carg[MAXLINE];
MEMSET(carg);
int p;
if((p=pipe(fds))==-1){
printf("pipe error\n");
exit(0);
}
strcpy(buf, cmdline);
bg = parseline(buf, argv);
pipe_num=calc_pipe_num(argv);
argn=argnum(argv);
if (argv[0] == NULL) {
return;
}
if (!builtin_command(argv)) {
pid=Fork();
if(pid==-1) PERROR_EXIT("fork error");
else if(pid==0){
int temp = pipe_execute(0, argv, STDIN_FILENO, argn, 0);
}
if (!bg){
int status;
}
else
printf("%d %s", pid, cmdline);
}
return;
} | [
"void",
"eval",
"(",
"char",
"*",
"cmdline",
")",
"{",
"char",
"*",
"argv",
"[",
"MAXARGS",
"]",
";",
"char",
"buf",
"[",
"MAXLINE",
"]",
";",
"int",
"bg",
";",
"pid_t",
"pid",
";",
"int",
"fds",
"[",
"2",
"]",
";",
"int",
"argn",
";",
"char",
"carg",
"[",
"MAXLINE",
"]",
";",
"MEMSET",
"(",
"carg",
")",
";",
"int",
"p",
";",
"if",
"(",
"(",
"p",
"=",
"pipe",
"(",
"fds",
")",
")",
"==",
"-1",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"exit",
"(",
"0",
")",
";",
"}",
"strcpy",
"(",
"buf",
",",
"cmdline",
")",
";",
"bg",
"=",
"parseline",
"(",
"buf",
",",
"argv",
")",
";",
"pipe_num",
"=",
"calc_pipe_num",
"(",
"argv",
")",
";",
"argn",
"=",
"argnum",
"(",
"argv",
")",
";",
"if",
"(",
"argv",
"[",
"0",
"]",
"==",
"NULL",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"builtin_command",
"(",
"argv",
")",
")",
"{",
"pid",
"=",
"Fork",
"(",
")",
";",
"if",
"(",
"pid",
"==",
"-1",
")",
"PERROR_EXIT",
"(",
"\"",
"\"",
")",
";",
"else",
"if",
"(",
"pid",
"==",
"0",
")",
"{",
"int",
"temp",
"=",
"pipe_execute",
"(",
"0",
",",
"argv",
",",
"STDIN_FILENO",
",",
"argn",
",",
"0",
")",
";",
"}",
"if",
"(",
"!",
"bg",
")",
"{",
"int",
"status",
";",
"}",
"else",
"printf",
"(",
"\"",
"\"",
",",
"pid",
",",
"cmdline",
")",
";",
"}",
"return",
";",
"}"
] | $begin eval
eval - Evaluate a command line | [
"$begin",
"eval",
"eval",
"-",
"Evaluate",
"a",
"command",
"line"
] | [
"/* Argument list execve() */",
"/* Holds modified command line */",
"/* Should the job run in bg or fg? */",
"/* Process id */",
"// file descriptors",
"// temporary buffer to parse",
"//calculate argnum",
"/* Ignore empty lines */",
"//quit -> exit(0), & -> ignore, other -> run",
"//child process",
"/* Parent waits for foreground job to terminate */",
"//when there is backgrount process!"
] | [
{
"param": "cmdline",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cmdline",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
688ebacdd264d0e2bc533bd6050a605532db72d5 | catensia/SP_Project | sp20161634_proj4/Phase2/myshell.c | [
"MIT"
] | C | builtin_command | int | int builtin_command(char **argv)
{
if (!strcmp(argv[0], "quit")) /* quit command */
exit(0);
if(!strcmp(argv[0], "exit")) /* exit command */
exit(0);
if (!strcmp(argv[0], "&")) /* Ignore singleton & */
return 1;
if (!strcmp(argv[0], "cd")){
int chdir_ret;
//only cd
if(argv[1]==NULL){
if((chdir_ret=chdir(getenv("HOME")))==-1){
printf("cd home error\n");
}
return 1;
}
//cd .. cd SP/proj4/
if((chdir_ret=chdir(argv[1]))==-1){
printf("cd error\n");
}
return 1;
}
return 0; /* Not a builtin command */
} | /* If first arg is a builtin command, run it and return true */ | If first arg is a builtin command, run it and return true | [
"If",
"first",
"arg",
"is",
"a",
"builtin",
"command",
"run",
"it",
"and",
"return",
"true"
] | int builtin_command(char **argv)
{
if (!strcmp(argv[0], "quit"))
exit(0);
if(!strcmp(argv[0], "exit"))
exit(0);
if (!strcmp(argv[0], "&"))
return 1;
if (!strcmp(argv[0], "cd")){
int chdir_ret;
if(argv[1]==NULL){
if((chdir_ret=chdir(getenv("HOME")))==-1){
printf("cd home error\n");
}
return 1;
}
if((chdir_ret=chdir(argv[1]))==-1){
printf("cd error\n");
}
return 1;
}
return 0;
} | [
"int",
"builtin_command",
"(",
"char",
"*",
"*",
"argv",
")",
"{",
"if",
"(",
"!",
"strcmp",
"(",
"argv",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
")",
"exit",
"(",
"0",
")",
";",
"if",
"(",
"!",
"strcmp",
"(",
"argv",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
")",
"exit",
"(",
"0",
")",
";",
"if",
"(",
"!",
"strcmp",
"(",
"argv",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
")",
"return",
"1",
";",
"if",
"(",
"!",
"strcmp",
"(",
"argv",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
")",
"{",
"int",
"chdir_ret",
";",
"if",
"(",
"argv",
"[",
"1",
"]",
"==",
"NULL",
")",
"{",
"if",
"(",
"(",
"chdir_ret",
"=",
"chdir",
"(",
"getenv",
"(",
"\"",
"\"",
")",
")",
")",
"==",
"-1",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"return",
"1",
";",
"}",
"if",
"(",
"(",
"chdir_ret",
"=",
"chdir",
"(",
"argv",
"[",
"1",
"]",
")",
")",
"==",
"-1",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}"
] | If first arg is a builtin command, run it and return true | [
"If",
"first",
"arg",
"is",
"a",
"builtin",
"command",
"run",
"it",
"and",
"return",
"true"
] | [
"/* quit command */",
"/* exit command */",
"/* Ignore singleton & */",
"//only cd",
"//cd .. cd SP/proj4/",
"/* Not a builtin command */"
] | [
{
"param": "argv",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "argv",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
0e9686cce8b670b3a04dbaddf93fd3c3fe5c78de | catensia/SP_Project | sp20161634_proj1/shell_cmd.c | [
"MIT"
] | C | shell_help | void | void shell_help(void){
printf("h[elp]\n");
printf("d[ir]\n");
printf("q[uit]\n");
printf("du[mp] [start, end]\n");
printf("e[dit] address, value\n");
printf("f[ill] start, end, value\n");
printf("reset\n");
printf("opcode mnemonic\n");
printf("opcodelist\n");
} | /*---------------------------------------------------------------------*/
/*Function: shell_help*/
/*Purpose: Print available commands*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | shell_help
Purpose: Print available commands
Return: none | [
"shell_help",
"Purpose",
":",
"Print",
"available",
"commands",
"Return",
":",
"none"
] | void shell_help(void){
printf("h[elp]\n");
printf("d[ir]\n");
printf("q[uit]\n");
printf("du[mp] [start, end]\n");
printf("e[dit] address, value\n");
printf("f[ill] start, end, value\n");
printf("reset\n");
printf("opcode mnemonic\n");
printf("opcodelist\n");
} | [
"void",
"shell_help",
"(",
"void",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}"
] | Function: shell_help
Purpose: Print available commands
Return: none | [
"Function",
":",
"shell_help",
"Purpose",
":",
"Print",
"available",
"commands",
"Return",
":",
"none"
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
0e9686cce8b670b3a04dbaddf93fd3c3fe5c78de | catensia/SP_Project | sp20161634_proj1/shell_cmd.c | [
"MIT"
] | C | shell_dir | void | void shell_dir(void){
DIR *dir_i=opendir(".");
struct dirent *dir_e;
if(dir_i!=NULL){
while((dir_e=readdir(dir_i))){
char filename[100];
//copy file name
strcpy(filename, dir_e->d_name);
int len=strlen(filename);
//check if directory
if(checkDir(dir_e->d_name)){
filename[len]='/';
filename[len+1]='\0';
}
//check if execution file (.out)
const char *ext=&filename[len-4];
if(!strcmp(".out", ext)){
filename[len]='*';
filename[len+1]='\0';
}
printf("%s\n", filename);
}
}
closedir(dir_i);
} | /*---------------------------------------------------------------------*/
/*Function: shell_dir*/
/*Purpose: prints files/directories in current directory*/
/*Return: none*/
/*---------------------------------------------------------------------*/ | shell_dir
Purpose: prints files/directories in current directory
Return: none | [
"shell_dir",
"Purpose",
":",
"prints",
"files",
"/",
"directories",
"in",
"current",
"directory",
"Return",
":",
"none"
] | void shell_dir(void){
DIR *dir_i=opendir(".");
struct dirent *dir_e;
if(dir_i!=NULL){
while((dir_e=readdir(dir_i))){
char filename[100];
strcpy(filename, dir_e->d_name);
int len=strlen(filename);
if(checkDir(dir_e->d_name)){
filename[len]='/';
filename[len+1]='\0';
}
const char *ext=&filename[len-4];
if(!strcmp(".out", ext)){
filename[len]='*';
filename[len+1]='\0';
}
printf("%s\n", filename);
}
}
closedir(dir_i);
} | [
"void",
"shell_dir",
"(",
"void",
")",
"{",
"DIR",
"*",
"dir_i",
"=",
"opendir",
"(",
"\"",
"\"",
")",
";",
"struct",
"dirent",
"*",
"dir_e",
";",
"if",
"(",
"dir_i",
"!=",
"NULL",
")",
"{",
"while",
"(",
"(",
"dir_e",
"=",
"readdir",
"(",
"dir_i",
")",
")",
")",
"{",
"char",
"filename",
"[",
"100",
"]",
";",
"strcpy",
"(",
"filename",
",",
"dir_e",
"->",
"d_name",
")",
";",
"int",
"len",
"=",
"strlen",
"(",
"filename",
")",
";",
"if",
"(",
"checkDir",
"(",
"dir_e",
"->",
"d_name",
")",
")",
"{",
"filename",
"[",
"len",
"]",
"=",
"'",
"'",
";",
"filename",
"[",
"len",
"+",
"1",
"]",
"=",
"'",
"\\0",
"'",
";",
"}",
"const",
"char",
"*",
"ext",
"=",
"&",
"filename",
"[",
"len",
"-",
"4",
"]",
";",
"if",
"(",
"!",
"strcmp",
"(",
"\"",
"\"",
",",
"ext",
")",
")",
"{",
"filename",
"[",
"len",
"]",
"=",
"'",
"'",
";",
"filename",
"[",
"len",
"+",
"1",
"]",
"=",
"'",
"\\0",
"'",
";",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"filename",
")",
";",
"}",
"}",
"closedir",
"(",
"dir_i",
")",
";",
"}"
] | Function: shell_dir
Purpose: prints files/directories in current directory
Return: none | [
"Function",
":",
"shell_dir",
"Purpose",
":",
"prints",
"files",
"/",
"directories",
"in",
"current",
"directory",
"Return",
":",
"none"
] | [
"//copy file name",
"//check if directory",
"//check if execution file (.out)"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
404394e9503cb8af6d6542c08c62367c0565ee6c | mail-ru-im/im-desktop | core/network/macos/scoped_typeref.h | [
"Apache-2.0"
] | C | initialize_into | element_type | element_type* initialize_into()
{
im_assert(!object_);
return &object_;
} | // This is to be used only to take ownership of objects that are created
// by pass-by-pointer create functions. To enforce this, require that the
// object be reset to NULL before this may be used. | This is to be used only to take ownership of objects that are created
by pass-by-pointer create functions. To enforce this, require that the
object be reset to NULL before this may be used. | [
"This",
"is",
"to",
"be",
"used",
"only",
"to",
"take",
"ownership",
"of",
"objects",
"that",
"are",
"created",
"by",
"pass",
"-",
"by",
"-",
"pointer",
"create",
"functions",
".",
"To",
"enforce",
"this",
"require",
"that",
"the",
"object",
"be",
"reset",
"to",
"NULL",
"before",
"this",
"may",
"be",
"used",
"."
] | element_type* initialize_into()
{
im_assert(!object_);
return &object_;
} | [
"element_type",
"*",
"initialize_into",
"(",
")",
"{",
"im_assert",
"(",
"!",
"object_",
")",
";",
"return",
"&",
"object_",
";",
"}"
] | This is to be used only to take ownership of objects that are created
by pass-by-pointer create functions. | [
"This",
"is",
"to",
"be",
"used",
"only",
"to",
"take",
"ownership",
"of",
"objects",
"that",
"are",
"created",
"by",
"pass",
"-",
"by",
"-",
"pointer",
"create",
"functions",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
6b6d59995a9747b8dcae14958a1e94120277a3c7 | mcai/Archimulator | benchmarks/Olden_Custom1/em3d/ht/util.c | [
"MIT"
] | C | gen_signed_number | int | int gen_signed_number(int range)
{
int temp;
temp = lrand48() % (2*range); /* 0..2*range-1 */
temp = temp-(range);
if (temp >= 0) temp++;
return temp;
} | /* return a random number in [-range,range] but not zero */ | return a random number in [-range,range] but not zero | [
"return",
"a",
"random",
"number",
"in",
"[",
"-",
"range",
"range",
"]",
"but",
"not",
"zero"
] | int gen_signed_number(int range)
{
int temp;
temp = lrand48() % (2*range);
temp = temp-(range);
if (temp >= 0) temp++;
return temp;
} | [
"int",
"gen_signed_number",
"(",
"int",
"range",
")",
"{",
"int",
"temp",
";",
"temp",
"=",
"lrand48",
"(",
")",
"%",
"(",
"2",
"*",
"range",
")",
";",
"temp",
"=",
"temp",
"-",
"(",
"range",
")",
";",
"if",
"(",
"temp",
">=",
"0",
")",
"temp",
"++",
";",
"return",
"temp",
";",
"}"
] | return a random number in [-range,range] but not zero | [
"return",
"a",
"random",
"number",
"in",
"[",
"-",
"range",
"range",
"]",
"but",
"not",
"zero"
] | [
"/* 0..2*range-1 */"
] | [
{
"param": "range",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "range",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
09cf3ddcab8e2a293bd36b5d98521b7fc04437cc | mcai/Archimulator | tools/cross_compiler/mips-unknown-linux-gnu/mips-unknown-linux-gnu/include/asm/bitops.h | [
"MIT"
] | C | __set_bit | void | static inline void __set_bit(unsigned long nr, volatile unsigned long * addr)
{
volatile unsigned long *a = addr;
unsigned long mask;
a += nr >> SZLONG_LOG;
mask = 1 << (nr & SZLONG_MASK);
*a |= mask;
} | /*
* __set_bit - Set a bit in memory
* @nr: the bit to set
* @addr: the address to start counting from
*
* Unlike set_bit(), this function is non-atomic and may be reordered.
* If it's called on the same region of memory simultaneously, the effect
* may be that only one operation succeeds.
*/ | Set a bit in memory
@nr: the bit to set
@addr: the address to start counting from
Unlike set_bit(), this function is non-atomic and may be reordered.
If it's called on the same region of memory simultaneously, the effect
may be that only one operation succeeds. | [
"Set",
"a",
"bit",
"in",
"memory",
"@nr",
":",
"the",
"bit",
"to",
"set",
"@addr",
":",
"the",
"address",
"to",
"start",
"counting",
"from",
"Unlike",
"set_bit",
"()",
"this",
"function",
"is",
"non",
"-",
"atomic",
"and",
"may",
"be",
"reordered",
".",
"If",
"it",
"'",
"s",
"called",
"on",
"the",
"same",
"region",
"of",
"memory",
"simultaneously",
"the",
"effect",
"may",
"be",
"that",
"only",
"one",
"operation",
"succeeds",
"."
] | static inline void __set_bit(unsigned long nr, volatile unsigned long * addr)
{
volatile unsigned long *a = addr;
unsigned long mask;
a += nr >> SZLONG_LOG;
mask = 1 << (nr & SZLONG_MASK);
*a |= mask;
} | [
"static",
"inline",
"void",
"__set_bit",
"(",
"unsigned",
"long",
"nr",
",",
"volatile",
"unsigned",
"long",
"*",
"addr",
")",
"{",
"volatile",
"unsigned",
"long",
"*",
"a",
"=",
"addr",
";",
"unsigned",
"long",
"mask",
";",
"a",
"+=",
"nr",
">>",
"SZLONG_LOG",
";",
"mask",
"=",
"1",
"<<",
"(",
"nr",
"&",
"SZLONG_MASK",
")",
";",
"*",
"a",
"|=",
"mask",
";",
"}"
] | __set_bit - Set a bit in memory
@nr: the bit to set
@addr: the address to start counting from | [
"__set_bit",
"-",
"Set",
"a",
"bit",
"in",
"memory",
"@nr",
":",
"the",
"bit",
"to",
"set",
"@addr",
":",
"the",
"address",
"to",
"start",
"counting",
"from"
] | [] | [
{
"param": "nr",
"type": "unsigned long"
},
{
"param": "addr",
"type": "unsigned long"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "nr",
"type": "unsigned long",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "addr",
"type": "unsigned long",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
09cf3ddcab8e2a293bd36b5d98521b7fc04437cc | mcai/Archimulator | tools/cross_compiler/mips-unknown-linux-gnu/mips-unknown-linux-gnu/include/asm/bitops.h | [
"MIT"
] | C | change_bit | void | static inline void change_bit(unsigned long nr, volatile unsigned long * addr)
{
volatile unsigned long *a = addr;
unsigned long mask;
a += nr >> SZLONG_LOG;
mask = 1 << (nr & SZLONG_MASK);
*a ^= mask;
} | /*
* change_bit - Toggle a bit in memory
* @nr: Bit to change
* @addr: Address to start counting from
*
* change_bit() is atomic and may not be reordered.
* Note that @nr may be almost arbitrarily large; this function is not
* restricted to acting on a single-word quantity.
*/ | Toggle a bit in memory
@nr: Bit to change
@addr: Address to start counting from
change_bit() is atomic and may not be reordered.
Note that @nr may be almost arbitrarily large; this function is not
restricted to acting on a single-word quantity. | [
"Toggle",
"a",
"bit",
"in",
"memory",
"@nr",
":",
"Bit",
"to",
"change",
"@addr",
":",
"Address",
"to",
"start",
"counting",
"from",
"change_bit",
"()",
"is",
"atomic",
"and",
"may",
"not",
"be",
"reordered",
".",
"Note",
"that",
"@nr",
"may",
"be",
"almost",
"arbitrarily",
"large",
";",
"this",
"function",
"is",
"not",
"restricted",
"to",
"acting",
"on",
"a",
"single",
"-",
"word",
"quantity",
"."
] | static inline void change_bit(unsigned long nr, volatile unsigned long * addr)
{
volatile unsigned long *a = addr;
unsigned long mask;
a += nr >> SZLONG_LOG;
mask = 1 << (nr & SZLONG_MASK);
*a ^= mask;
} | [
"static",
"inline",
"void",
"change_bit",
"(",
"unsigned",
"long",
"nr",
",",
"volatile",
"unsigned",
"long",
"*",
"addr",
")",
"{",
"volatile",
"unsigned",
"long",
"*",
"a",
"=",
"addr",
";",
"unsigned",
"long",
"mask",
";",
"a",
"+=",
"nr",
">>",
"SZLONG_LOG",
";",
"mask",
"=",
"1",
"<<",
"(",
"nr",
"&",
"SZLONG_MASK",
")",
";",
"*",
"a",
"^=",
"mask",
";",
"}"
] | change_bit - Toggle a bit in memory
@nr: Bit to change
@addr: Address to start counting from | [
"change_bit",
"-",
"Toggle",
"a",
"bit",
"in",
"memory",
"@nr",
":",
"Bit",
"to",
"change",
"@addr",
":",
"Address",
"to",
"start",
"counting",
"from"
] | [] | [
{
"param": "nr",
"type": "unsigned long"
},
{
"param": "addr",
"type": "unsigned long"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "nr",
"type": "unsigned long",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "addr",
"type": "unsigned long",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
09cf3ddcab8e2a293bd36b5d98521b7fc04437cc | mcai/Archimulator | tools/cross_compiler/mips-unknown-linux-gnu/mips-unknown-linux-gnu/include/asm/bitops.h | [
"MIT"
] | C | ffz | null | static inline unsigned long ffz(unsigned long word)
{
int b = 0, s;
word = ~word;
#if (_MIPS_SZLONG == 32)
s = 16; if (word << 16 != 0) s = 0; b += s; word >>= s;
s = 8; if (word << 24 != 0) s = 0; b += s; word >>= s;
s = 4; if (word << 28 != 0) s = 0; b += s; word >>= s;
s = 2; if (word << 30 != 0) s = 0; b += s; word >>= s;
s = 1; if (word << 31 != 0) s = 0; b += s;
#endif
#if (_MIPS_SZLONG == 64)
s = 32; if (word << 32 != 0) s = 0; b += s; word >>= s;
s = 16; if (word << 48 != 0) s = 0; b += s; word >>= s;
s = 8; if (word << 56 != 0) s = 0; b += s; word >>= s;
s = 4; if (word << 60 != 0) s = 0; b += s; word >>= s;
s = 2; if (word << 62 != 0) s = 0; b += s; word >>= s;
s = 1; if (word << 63 != 0) s = 0; b += s;
#endif
return b;
} | /*
* ffz - find first zero in word.
* @word: The word to search
*
* Undefined if no zero exists, so code should check against ~0UL first.
*/ | find first zero in word.
@word: The word to search
Undefined if no zero exists, so code should check against ~0UL first. | [
"find",
"first",
"zero",
"in",
"word",
".",
"@word",
":",
"The",
"word",
"to",
"search",
"Undefined",
"if",
"no",
"zero",
"exists",
"so",
"code",
"should",
"check",
"against",
"~0UL",
"first",
"."
] | static inline unsigned long ffz(unsigned long word)
{
int b = 0, s;
word = ~word;
#if (_MIPS_SZLONG == 32)
s = 16; if (word << 16 != 0) s = 0; b += s; word >>= s;
s = 8; if (word << 24 != 0) s = 0; b += s; word >>= s;
s = 4; if (word << 28 != 0) s = 0; b += s; word >>= s;
s = 2; if (word << 30 != 0) s = 0; b += s; word >>= s;
s = 1; if (word << 31 != 0) s = 0; b += s;
#endif
#if (_MIPS_SZLONG == 64)
s = 32; if (word << 32 != 0) s = 0; b += s; word >>= s;
s = 16; if (word << 48 != 0) s = 0; b += s; word >>= s;
s = 8; if (word << 56 != 0) s = 0; b += s; word >>= s;
s = 4; if (word << 60 != 0) s = 0; b += s; word >>= s;
s = 2; if (word << 62 != 0) s = 0; b += s; word >>= s;
s = 1; if (word << 63 != 0) s = 0; b += s;
#endif
return b;
} | [
"static",
"inline",
"unsigned",
"long",
"ffz",
"(",
"unsigned",
"long",
"word",
")",
"{",
"int",
"b",
"=",
"0",
",",
"s",
";",
"word",
"=",
"~",
"word",
";",
"#if",
"(",
"_MIPS_SZLONG",
"==",
"32",
")",
"\n",
"s",
"=",
"16",
";",
"if",
"(",
"word",
"<<",
"16",
"!=",
"0",
")",
"s",
"=",
"0",
";",
"b",
"+=",
"s",
";",
"word",
">>=",
"s",
";",
"s",
"=",
"8",
";",
"if",
"(",
"word",
"<<",
"24",
"!=",
"0",
")",
"s",
"=",
"0",
";",
"b",
"+=",
"s",
";",
"word",
">>=",
"s",
";",
"s",
"=",
"4",
";",
"if",
"(",
"word",
"<<",
"28",
"!=",
"0",
")",
"s",
"=",
"0",
";",
"b",
"+=",
"s",
";",
"word",
">>=",
"s",
";",
"s",
"=",
"2",
";",
"if",
"(",
"word",
"<<",
"30",
"!=",
"0",
")",
"s",
"=",
"0",
";",
"b",
"+=",
"s",
";",
"word",
">>=",
"s",
";",
"s",
"=",
"1",
";",
"if",
"(",
"word",
"<<",
"31",
"!=",
"0",
")",
"s",
"=",
"0",
";",
"b",
"+=",
"s",
";",
"#endif",
"#if",
"(",
"_MIPS_SZLONG",
"==",
"64",
")",
"\n",
"s",
"=",
"32",
";",
"if",
"(",
"word",
"<<",
"32",
"!=",
"0",
")",
"s",
"=",
"0",
";",
"b",
"+=",
"s",
";",
"word",
">>=",
"s",
";",
"s",
"=",
"16",
";",
"if",
"(",
"word",
"<<",
"48",
"!=",
"0",
")",
"s",
"=",
"0",
";",
"b",
"+=",
"s",
";",
"word",
">>=",
"s",
";",
"s",
"=",
"8",
";",
"if",
"(",
"word",
"<<",
"56",
"!=",
"0",
")",
"s",
"=",
"0",
";",
"b",
"+=",
"s",
";",
"word",
">>=",
"s",
";",
"s",
"=",
"4",
";",
"if",
"(",
"word",
"<<",
"60",
"!=",
"0",
")",
"s",
"=",
"0",
";",
"b",
"+=",
"s",
";",
"word",
">>=",
"s",
";",
"s",
"=",
"2",
";",
"if",
"(",
"word",
"<<",
"62",
"!=",
"0",
")",
"s",
"=",
"0",
";",
"b",
"+=",
"s",
";",
"word",
">>=",
"s",
";",
"s",
"=",
"1",
";",
"if",
"(",
"word",
"<<",
"63",
"!=",
"0",
")",
"s",
"=",
"0",
";",
"b",
"+=",
"s",
";",
"#endif",
"return",
"b",
";",
"}"
] | ffz - find first zero in word. | [
"ffz",
"-",
"find",
"first",
"zero",
"in",
"word",
"."
] | [] | [
{
"param": "word",
"type": "unsigned long"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "word",
"type": "unsigned long",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |