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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
310d0dd465d1871624b075c575c24867293e900b | sentinela-online/nodemcu-firmware | components/modules/http.c | [
"MIT"
] | C | parse_options | void | static void parse_options(lua_State *L, lhttp_context_t *context, esp_http_client_config_t *config)
{
config->timeout_ms = opt_checkint(L, "timeout", 10*1000); // Same default as old http module
config->buffer_size = opt_checkint(L, "bufsz", DEFAULT_HTTP_BUF_SIZE);
int redirects = opt_checkint(L, "max_redirects", -1); // -1 means "not specified" here
if (redirects == 0) {
config->disable_auto_redirect = true;
} else if (redirects > 0) {
config->max_redirection_count = redirects;
}
// Note, config->is_async is always set to false regardless of what we set
// the Async flag to, because of how we configure the tasks we always want
// esp_http_client_perform to run in its 'is_async=false' mode.
context_setflagbool(context, Async, opt_checkbool(L, "async", false));
if (opt_get(L, "cert", LUA_TSTRING)) {
const char *cert = lua_tostring(L, -1);
context_setref(L, context, CertRef);
config->cert_pem = cert;
}
// This function doesn't set headers because we need the connection to be created first
} | // Options assumed to be on top of stack | Options assumed to be on top of stack | [
"Options",
"assumed",
"to",
"be",
"on",
"top",
"of",
"stack"
] | static void parse_options(lua_State *L, lhttp_context_t *context, esp_http_client_config_t *config)
{
config->timeout_ms = opt_checkint(L, "timeout", 10*1000);
config->buffer_size = opt_checkint(L, "bufsz", DEFAULT_HTTP_BUF_SIZE);
int redirects = opt_checkint(L, "max_redirects", -1);
if (redirects == 0) {
config->disable_auto_redirect = true;
} else if (redirects > 0) {
config->max_redirection_count = redirects;
}
context_setflagbool(context, Async, opt_checkbool(L, "async", false));
if (opt_get(L, "cert", LUA_TSTRING)) {
const char *cert = lua_tostring(L, -1);
context_setref(L, context, CertRef);
config->cert_pem = cert;
}
} | [
"static",
"void",
"parse_options",
"(",
"lua_State",
"*",
"L",
",",
"lhttp_context_t",
"*",
"context",
",",
"esp_http_client_config_t",
"*",
"config",
")",
"{",
"config",
"->",
"timeout_ms",
"=",
"opt_checkint",
"(",
"L",
",",
"\"",
"\"",
",",
"10",
"*",
"1000",
")",
";",
"config",
"->",
"buffer_size",
"=",
"opt_checkint",
"(",
"L",
",",
"\"",
"\"",
",",
"DEFAULT_HTTP_BUF_SIZE",
")",
";",
"int",
"redirects",
"=",
"opt_checkint",
"(",
"L",
",",
"\"",
"\"",
",",
"-1",
")",
";",
"if",
"(",
"redirects",
"==",
"0",
")",
"{",
"config",
"->",
"disable_auto_redirect",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"redirects",
">",
"0",
")",
"{",
"config",
"->",
"max_redirection_count",
"=",
"redirects",
";",
"}",
"context_setflagbool",
"(",
"context",
",",
"Async",
",",
"opt_checkbool",
"(",
"L",
",",
"\"",
"\"",
",",
"false",
")",
")",
";",
"if",
"(",
"opt_get",
"(",
"L",
",",
"\"",
"\"",
",",
"LUA_TSTRING",
")",
")",
"{",
"const",
"char",
"*",
"cert",
"=",
"lua_tostring",
"(",
"L",
",",
"-1",
")",
";",
"context_setref",
"(",
"L",
",",
"context",
",",
"CertRef",
")",
";",
"config",
"->",
"cert_pem",
"=",
"cert",
";",
"}",
"}"
] | Options assumed to be on top of stack | [
"Options",
"assumed",
"to",
"be",
"on",
"top",
"of",
"stack"
] | [
"// Same default as old http module",
"// -1 means \"not specified\" here",
"// Note, config->is_async is always set to false regardless of what we set",
"// the Async flag to, because of how we configure the tasks we always want",
"// esp_http_client_perform to run in its 'is_async=false' mode.",
"// This function doesn't set headers because we need the connection to be created first"
] | [
{
"param": "L",
"type": "lua_State"
},
{
"param": "context",
"type": "lhttp_context_t"
},
{
"param": "config",
"type": "esp_http_client_config_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "context",
"type": "lhttp_context_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "config",
"type": "esp_http_client_config_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b9bb9c60a96b134824d76361f124fc9979ac9262 | sentinela-online/nodemcu-firmware | components/modules/i2c_hw_master.c | [
"MIT"
] | C | vTransferTask | void | static void vTransferTask( void *pvParameters )
{
QueueHandle_t xQueue = (QueueHandle_t)pvParameters;
i2c_job_desc_type *job;
for (;;) {
job = (i2c_job_desc_type *)malloc( sizeof( i2c_job_desc_type ) );
if (!job) {
// shut down this task in case of memory shortage
vTaskSuspend( NULL );
}
// get a job descriptor
xQueueReceive( xQueue, job, portMAX_DELAY );
job->err = i2c_master_cmd_begin( job->port, job->cmd,
job->to_ms > 0 ? job->to_ms / portTICK_RATE_MS : portMAX_DELAY );
task_post_medium( i2c_transfer_task_id, (task_param_t)job );
}
} | // Transfer Task, FreeRTOS layer
// This is a fully-fledged FreeRTOS task which runs concurrently and pulls
// jobs off the queue. Jobs are forwarded to i2c_master_cmd_begin() which blocks
// this task throughout the I2C transfer.
// Posts a task to the nodemcu task system to resume.
// | Transfer Task, FreeRTOS layer
This is a fully-fledged FreeRTOS task which runs concurrently and pulls
jobs off the queue. Jobs are forwarded to i2c_master_cmd_begin() which blocks
this task throughout the I2C transfer.
Posts a task to the nodemcu task system to resume. | [
"Transfer",
"Task",
"FreeRTOS",
"layer",
"This",
"is",
"a",
"fully",
"-",
"fledged",
"FreeRTOS",
"task",
"which",
"runs",
"concurrently",
"and",
"pulls",
"jobs",
"off",
"the",
"queue",
".",
"Jobs",
"are",
"forwarded",
"to",
"i2c_master_cmd_begin",
"()",
"which",
"blocks",
"this",
"task",
"throughout",
"the",
"I2C",
"transfer",
".",
"Posts",
"a",
"task",
"to",
"the",
"nodemcu",
"task",
"system",
"to",
"resume",
"."
] | static void vTransferTask( void *pvParameters )
{
QueueHandle_t xQueue = (QueueHandle_t)pvParameters;
i2c_job_desc_type *job;
for (;;) {
job = (i2c_job_desc_type *)malloc( sizeof( i2c_job_desc_type ) );
if (!job) {
vTaskSuspend( NULL );
}
xQueueReceive( xQueue, job, portMAX_DELAY );
job->err = i2c_master_cmd_begin( job->port, job->cmd,
job->to_ms > 0 ? job->to_ms / portTICK_RATE_MS : portMAX_DELAY );
task_post_medium( i2c_transfer_task_id, (task_param_t)job );
}
} | [
"static",
"void",
"vTransferTask",
"(",
"void",
"*",
"pvParameters",
")",
"{",
"QueueHandle_t",
"xQueue",
"=",
"(",
"QueueHandle_t",
")",
"pvParameters",
";",
"i2c_job_desc_type",
"*",
"job",
";",
"for",
"(",
";",
";",
")",
"{",
"job",
"=",
"(",
"i2c_job_desc_type",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"i2c_job_desc_type",
")",
")",
";",
"if",
"(",
"!",
"job",
")",
"{",
"vTaskSuspend",
"(",
"NULL",
")",
";",
"}",
"xQueueReceive",
"(",
"xQueue",
",",
"job",
",",
"portMAX_DELAY",
")",
";",
"job",
"->",
"err",
"=",
"i2c_master_cmd_begin",
"(",
"job",
"->",
"port",
",",
"job",
"->",
"cmd",
",",
"job",
"->",
"to_ms",
">",
"0",
"?",
"job",
"->",
"to_ms",
"/",
"portTICK_RATE_MS",
":",
"portMAX_DELAY",
")",
";",
"task_post_medium",
"(",
"i2c_transfer_task_id",
",",
"(",
"task_param_t",
")",
"job",
")",
";",
"}",
"}"
] | Transfer Task, FreeRTOS layer
This is a fully-fledged FreeRTOS task which runs concurrently and pulls
jobs off the queue. | [
"Transfer",
"Task",
"FreeRTOS",
"layer",
"This",
"is",
"a",
"fully",
"-",
"fledged",
"FreeRTOS",
"task",
"which",
"runs",
"concurrently",
"and",
"pulls",
"jobs",
"off",
"the",
"queue",
"."
] | [
"// shut down this task in case of memory shortage",
"// get a job descriptor"
] | [
{
"param": "pvParameters",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "pvParameters",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b9bb9c60a96b134824d76361f124fc9979ac9262 | sentinela-online/nodemcu-firmware | components/modules/i2c_hw_master.c | [
"MIT"
] | C | free_job_memory | void | static void free_job_memory( lua_State *L, i2c_job_desc_type *job )
{
if (job->result)
luaM_free( L, job->result );
luaL_unref( L, LUA_REGISTRYINDEX, job->cb_ref);
if (job->cmd)
i2c_cmd_link_delete( job->cmd );
} | // Free memory of a job descriptor
// | Free memory of a job descriptor | [
"Free",
"memory",
"of",
"a",
"job",
"descriptor"
] | static void free_job_memory( lua_State *L, i2c_job_desc_type *job )
{
if (job->result)
luaM_free( L, job->result );
luaL_unref( L, LUA_REGISTRYINDEX, job->cb_ref);
if (job->cmd)
i2c_cmd_link_delete( job->cmd );
} | [
"static",
"void",
"free_job_memory",
"(",
"lua_State",
"*",
"L",
",",
"i2c_job_desc_type",
"*",
"job",
")",
"{",
"if",
"(",
"job",
"->",
"result",
")",
"luaM_free",
"(",
"L",
",",
"job",
"->",
"result",
")",
";",
"luaL_unref",
"(",
"L",
",",
"LUA_REGISTRYINDEX",
",",
"job",
"->",
"cb_ref",
")",
";",
"if",
"(",
"job",
"->",
"cmd",
")",
"i2c_cmd_link_delete",
"(",
"job",
"->",
"cmd",
")",
";",
"}"
] | Free memory of a job descriptor | [
"Free",
"memory",
"of",
"a",
"job",
"descriptor"
] | [] | [
{
"param": "L",
"type": "lua_State"
},
{
"param": "job",
"type": "i2c_job_desc_type"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "job",
"type": "i2c_job_desc_type",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b9bb9c60a96b134824d76361f124fc9979ac9262 | sentinela-online/nodemcu-firmware | components/modules/i2c_hw_master.c | [
"MIT"
] | C | i2c_transfer_task | void | static void i2c_transfer_task( task_param_t param, task_prio_t prio )
{
i2c_job_desc_type *job = (i2c_job_desc_type *)param;
lua_State *L = lua_getstate();
if (job->cb_ref != LUA_NOREF) {
lua_rawgeti( L, LUA_REGISTRYINDEX, job->cb_ref );
if (job->result) {
// all fine, deliver read data
lua_pushlstring( L, (char *)job->result->data, job->result->len );
} else {
lua_pushnil( L );
}
lua_pushboolean( L, job->err == ESP_OK );
lua_call(L, 2, 0);
}
// free all memory
free_job_memory( L, job );
free( job );
} | // Transfer Task, NodeMCU layer
// Is posted by the FreeRTOS Transfer Task and triggers the Lua callback with optional
// read result data.
// | Transfer Task, NodeMCU layer
Is posted by the FreeRTOS Transfer Task and triggers the Lua callback with optional
read result data. | [
"Transfer",
"Task",
"NodeMCU",
"layer",
"Is",
"posted",
"by",
"the",
"FreeRTOS",
"Transfer",
"Task",
"and",
"triggers",
"the",
"Lua",
"callback",
"with",
"optional",
"read",
"result",
"data",
"."
] | static void i2c_transfer_task( task_param_t param, task_prio_t prio )
{
i2c_job_desc_type *job = (i2c_job_desc_type *)param;
lua_State *L = lua_getstate();
if (job->cb_ref != LUA_NOREF) {
lua_rawgeti( L, LUA_REGISTRYINDEX, job->cb_ref );
if (job->result) {
lua_pushlstring( L, (char *)job->result->data, job->result->len );
} else {
lua_pushnil( L );
}
lua_pushboolean( L, job->err == ESP_OK );
lua_call(L, 2, 0);
}
free_job_memory( L, job );
free( job );
} | [
"static",
"void",
"i2c_transfer_task",
"(",
"task_param_t",
"param",
",",
"task_prio_t",
"prio",
")",
"{",
"i2c_job_desc_type",
"*",
"job",
"=",
"(",
"i2c_job_desc_type",
"*",
")",
"param",
";",
"lua_State",
"*",
"L",
"=",
"lua_getstate",
"(",
")",
";",
"if",
"(",
"job",
"->",
"cb_ref",
"!=",
"LUA_NOREF",
")",
"{",
"lua_rawgeti",
"(",
"L",
",",
"LUA_REGISTRYINDEX",
",",
"job",
"->",
"cb_ref",
")",
";",
"if",
"(",
"job",
"->",
"result",
")",
"{",
"lua_pushlstring",
"(",
"L",
",",
"(",
"char",
"*",
")",
"job",
"->",
"result",
"->",
"data",
",",
"job",
"->",
"result",
"->",
"len",
")",
";",
"}",
"else",
"{",
"lua_pushnil",
"(",
"L",
")",
";",
"}",
"lua_pushboolean",
"(",
"L",
",",
"job",
"->",
"err",
"==",
"ESP_OK",
")",
";",
"lua_call",
"(",
"L",
",",
"2",
",",
"0",
")",
";",
"}",
"free_job_memory",
"(",
"L",
",",
"job",
")",
";",
"free",
"(",
"job",
")",
";",
"}"
] | Transfer Task, NodeMCU layer
Is posted by the FreeRTOS Transfer Task and triggers the Lua callback with optional
read result data. | [
"Transfer",
"Task",
"NodeMCU",
"layer",
"Is",
"posted",
"by",
"the",
"FreeRTOS",
"Transfer",
"Task",
"and",
"triggers",
"the",
"Lua",
"callback",
"with",
"optional",
"read",
"result",
"data",
"."
] | [
"// all fine, deliver read data",
"// free all memory"
] | [
{
"param": "param",
"type": "task_param_t"
},
{
"param": "prio",
"type": "task_prio_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "param",
"type": "task_param_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "prio",
"type": "task_prio_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b9bb9c60a96b134824d76361f124fc9979ac9262 | sentinela-online/nodemcu-firmware | components/modules/i2c_hw_master.c | [
"MIT"
] | C | i2c_setup_ud_transfer | void | static void i2c_setup_ud_transfer( lua_State *L, i2c_hw_master_ud_type *ud )
{
free_job_memory( L, &(ud->job) );
ud->job.result = NULL;
ud->job.cb_ref = LUA_NOREF;
// set up an empty command link
ud->job.cmd = i2c_cmd_link_create();
} | // Set up userdata for a transfer
// | Set up userdata for a transfer | [
"Set",
"up",
"userdata",
"for",
"a",
"transfer"
] | static void i2c_setup_ud_transfer( lua_State *L, i2c_hw_master_ud_type *ud )
{
free_job_memory( L, &(ud->job) );
ud->job.result = NULL;
ud->job.cb_ref = LUA_NOREF;
ud->job.cmd = i2c_cmd_link_create();
} | [
"static",
"void",
"i2c_setup_ud_transfer",
"(",
"lua_State",
"*",
"L",
",",
"i2c_hw_master_ud_type",
"*",
"ud",
")",
"{",
"free_job_memory",
"(",
"L",
",",
"&",
"(",
"ud",
"->",
"job",
")",
")",
";",
"ud",
"->",
"job",
".",
"result",
"=",
"NULL",
";",
"ud",
"->",
"job",
".",
"cb_ref",
"=",
"LUA_NOREF",
";",
"ud",
"->",
"job",
".",
"cmd",
"=",
"i2c_cmd_link_create",
"(",
")",
";",
"}"
] | Set up userdata for a transfer | [
"Set",
"up",
"userdata",
"for",
"a",
"transfer"
] | [
"// set up an empty command link"
] | [
{
"param": "L",
"type": "lua_State"
},
{
"param": "ud",
"type": "i2c_hw_master_ud_type"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ud",
"type": "i2c_hw_master_ud_type",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b9bb9c60a96b134824d76361f124fc9979ac9262 | sentinela-online/nodemcu-firmware | components/modules/i2c_hw_master.c | [
"MIT"
] | C | li2c_hw_master_setup | int | int li2c_hw_master_setup( lua_State *L, unsigned id, unsigned sda, unsigned scl, uint32_t speed, unsigned stretchfactor )
{
get_udata(L, id);
i2c_config_t cfg;
memset( &cfg, 0, sizeof( cfg ) );
cfg.mode = I2C_MODE_MASTER;
luaL_argcheck( L, GPIO_IS_VALID_OUTPUT_GPIO(sda), 2, "invalid sda pin" );
cfg.sda_io_num = sda;
cfg.sda_pullup_en = GPIO_PULLUP_ENABLE;
luaL_argcheck( L, GPIO_IS_VALID_OUTPUT_GPIO(scl), 3, "invalid scl pin" );
cfg.scl_io_num = scl;
cfg.scl_pullup_en = GPIO_PULLUP_ENABLE;
luaL_argcheck( L, speed > 0 && speed <= 1000000, 4, "invalid speed" );
cfg.master.clk_speed = speed;
// init driver level
i2c_lua_checkerr( L, i2c_param_config( port, &cfg ) );
luaL_argcheck( L, stretchfactor > 0 , 5, "invalid stretch factor" );
int timeoutcycles;
i2c_lua_checkerr( L, i2c_get_timeout( port, &timeoutcycles) );
timeoutcycles = timeoutcycles * stretchfactor;
luaL_argcheck( L, timeoutcycles * stretchfactor <= I2C_TIME_OUT_REG_V, 5, "excessive stretch factor" );
i2c_lua_checkerr( L, i2c_set_timeout( port, timeoutcycles) );
i2c_lua_checkerr( L, i2c_driver_install( port, cfg.mode, 0, 0, 0 ));
job->port = port;
job->cmd = NULL;
job->result = NULL;
job->cb_ref = LUA_NOREF;
i2c_setup_ud_transfer( L, ud );
// kick-start transfer task
if (!setup_rtos_task_and_queue( ud )) {
free_job_memory( L, &(ud->job) );
i2c_driver_delete( port );
luaL_error( L, "rtos task creation failed" );
}
return timeoutcycles;
} | // Set up the HW as master interface
// Cares for I2C driver creation and initialization.
// Prepares an empty job descriptor and triggers setup of FreeRTOS stuff.
// | Set up the HW as master interface
Cares for I2C driver creation and initialization.
Prepares an empty job descriptor and triggers setup of FreeRTOS stuff. | [
"Set",
"up",
"the",
"HW",
"as",
"master",
"interface",
"Cares",
"for",
"I2C",
"driver",
"creation",
"and",
"initialization",
".",
"Prepares",
"an",
"empty",
"job",
"descriptor",
"and",
"triggers",
"setup",
"of",
"FreeRTOS",
"stuff",
"."
] | int li2c_hw_master_setup( lua_State *L, unsigned id, unsigned sda, unsigned scl, uint32_t speed, unsigned stretchfactor )
{
get_udata(L, id);
i2c_config_t cfg;
memset( &cfg, 0, sizeof( cfg ) );
cfg.mode = I2C_MODE_MASTER;
luaL_argcheck( L, GPIO_IS_VALID_OUTPUT_GPIO(sda), 2, "invalid sda pin" );
cfg.sda_io_num = sda;
cfg.sda_pullup_en = GPIO_PULLUP_ENABLE;
luaL_argcheck( L, GPIO_IS_VALID_OUTPUT_GPIO(scl), 3, "invalid scl pin" );
cfg.scl_io_num = scl;
cfg.scl_pullup_en = GPIO_PULLUP_ENABLE;
luaL_argcheck( L, speed > 0 && speed <= 1000000, 4, "invalid speed" );
cfg.master.clk_speed = speed;
i2c_lua_checkerr( L, i2c_param_config( port, &cfg ) );
luaL_argcheck( L, stretchfactor > 0 , 5, "invalid stretch factor" );
int timeoutcycles;
i2c_lua_checkerr( L, i2c_get_timeout( port, &timeoutcycles) );
timeoutcycles = timeoutcycles * stretchfactor;
luaL_argcheck( L, timeoutcycles * stretchfactor <= I2C_TIME_OUT_REG_V, 5, "excessive stretch factor" );
i2c_lua_checkerr( L, i2c_set_timeout( port, timeoutcycles) );
i2c_lua_checkerr( L, i2c_driver_install( port, cfg.mode, 0, 0, 0 ));
job->port = port;
job->cmd = NULL;
job->result = NULL;
job->cb_ref = LUA_NOREF;
i2c_setup_ud_transfer( L, ud );
if (!setup_rtos_task_and_queue( ud )) {
free_job_memory( L, &(ud->job) );
i2c_driver_delete( port );
luaL_error( L, "rtos task creation failed" );
}
return timeoutcycles;
} | [
"int",
"li2c_hw_master_setup",
"(",
"lua_State",
"*",
"L",
",",
"unsigned",
"id",
",",
"unsigned",
"sda",
",",
"unsigned",
"scl",
",",
"uint32_t",
"speed",
",",
"unsigned",
"stretchfactor",
")",
"{",
"get_udata",
"(",
"L",
",",
"id",
")",
";",
"i2c_config_t",
"cfg",
";",
"memset",
"(",
"&",
"cfg",
",",
"0",
",",
"sizeof",
"(",
"cfg",
")",
")",
";",
"cfg",
".",
"mode",
"=",
"I2C_MODE_MASTER",
";",
"luaL_argcheck",
"(",
"L",
",",
"GPIO_IS_VALID_OUTPUT_GPIO",
"(",
"sda",
")",
",",
"2",
",",
"\"",
"\"",
")",
";",
"cfg",
".",
"sda_io_num",
"=",
"sda",
";",
"cfg",
".",
"sda_pullup_en",
"=",
"GPIO_PULLUP_ENABLE",
";",
"luaL_argcheck",
"(",
"L",
",",
"GPIO_IS_VALID_OUTPUT_GPIO",
"(",
"scl",
")",
",",
"3",
",",
"\"",
"\"",
")",
";",
"cfg",
".",
"scl_io_num",
"=",
"scl",
";",
"cfg",
".",
"scl_pullup_en",
"=",
"GPIO_PULLUP_ENABLE",
";",
"luaL_argcheck",
"(",
"L",
",",
"speed",
">",
"0",
"&&",
"speed",
"<=",
"1000000",
",",
"4",
",",
"\"",
"\"",
")",
";",
"cfg",
".",
"master",
".",
"clk_speed",
"=",
"speed",
";",
"i2c_lua_checkerr",
"(",
"L",
",",
"i2c_param_config",
"(",
"port",
",",
"&",
"cfg",
")",
")",
";",
"luaL_argcheck",
"(",
"L",
",",
"stretchfactor",
">",
"0",
",",
"5",
",",
"\"",
"\"",
")",
";",
"int",
"timeoutcycles",
";",
"i2c_lua_checkerr",
"(",
"L",
",",
"i2c_get_timeout",
"(",
"port",
",",
"&",
"timeoutcycles",
")",
")",
";",
"timeoutcycles",
"=",
"timeoutcycles",
"*",
"stretchfactor",
";",
"luaL_argcheck",
"(",
"L",
",",
"timeoutcycles",
"*",
"stretchfactor",
"<=",
"I2C_TIME_OUT_REG_V",
",",
"5",
",",
"\"",
"\"",
")",
";",
"i2c_lua_checkerr",
"(",
"L",
",",
"i2c_set_timeout",
"(",
"port",
",",
"timeoutcycles",
")",
")",
";",
"i2c_lua_checkerr",
"(",
"L",
",",
"i2c_driver_install",
"(",
"port",
",",
"cfg",
".",
"mode",
",",
"0",
",",
"0",
",",
"0",
")",
")",
";",
"job",
"->",
"port",
"=",
"port",
";",
"job",
"->",
"cmd",
"=",
"NULL",
";",
"job",
"->",
"result",
"=",
"NULL",
";",
"job",
"->",
"cb_ref",
"=",
"LUA_NOREF",
";",
"i2c_setup_ud_transfer",
"(",
"L",
",",
"ud",
")",
";",
"if",
"(",
"!",
"setup_rtos_task_and_queue",
"(",
"ud",
")",
")",
"{",
"free_job_memory",
"(",
"L",
",",
"&",
"(",
"ud",
"->",
"job",
")",
")",
";",
"i2c_driver_delete",
"(",
"port",
")",
";",
"luaL_error",
"(",
"L",
",",
"\"",
"\"",
")",
";",
"}",
"return",
"timeoutcycles",
";",
"}"
] | Set up the HW as master interface
Cares for I2C driver creation and initialization. | [
"Set",
"up",
"the",
"HW",
"as",
"master",
"interface",
"Cares",
"for",
"I2C",
"driver",
"creation",
"and",
"initialization",
"."
] | [
"// init driver level",
"// kick-start transfer task"
] | [
{
"param": "L",
"type": "lua_State"
},
{
"param": "id",
"type": "unsigned"
},
{
"param": "sda",
"type": "unsigned"
},
{
"param": "scl",
"type": "unsigned"
},
{
"param": "speed",
"type": "uint32_t"
},
{
"param": "stretchfactor",
"type": "unsigned"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "id",
"type": "unsigned",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "sda",
"type": "unsigned",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "scl",
"type": "unsigned",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "speed",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "stretchfactor",
"type": "unsigned",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b9bb9c60a96b134824d76361f124fc9979ac9262 | sentinela-online/nodemcu-firmware | components/modules/i2c_hw_master.c | [
"MIT"
] | C | li2c_hw_master_transfer | int | int li2c_hw_master_transfer( lua_State *L )
{
int stack = 0;
unsigned id = luaL_checkinteger( L, ++stack );
get_udata(L, id);
if (!job->cmd)
luaL_error( L, "no commands scheduled" );
stack++;
if (lua_isfunction( L, stack ) || lua_islightfunction( L, stack )) {
lua_pushvalue( L, stack ); // copy argument (func) to the top of stack
luaL_unref( L, LUA_REGISTRYINDEX, job->cb_ref );
job->cb_ref = luaL_ref(L, LUA_REGISTRYINDEX);
} else
stack--;
int to_ms = luaL_optint( L, ++stack, 0 );
if (to_ms < 0)
to_ms = 0;
job->to_ms = to_ms;
if (job->cb_ref != LUA_NOREF) {
// asynchronous mode
xQueueSend( ud->xTransferJobQueue, job, portMAX_DELAY );
// the transfer task should be unblocked now
// (i.e. in eReady state since it can receive from the queue)
portYIELD();
// invalidate last job, it's queued now
job->cmd = NULL; // don't delete link! it's used by the transfer task
job->result = NULL; // don't free result memory! it's used by the transfer task
job->cb_ref = LUA_NOREF; // don't unref! it's used by the transfer task
// prepare the next transfer
i2c_setup_ud_transfer( L, ud );
return 0;
} else {
// synchronous mode
// no need to wait for queue to become empty when queue depth is 1
// note that i2c_master_cmd_begin() implements mutual exclusive access
// if it is currently in progress from the transfer task, it will block here until
esp_err_t err = i2c_master_cmd_begin( job->port, job->cmd,
job->to_ms > 0 ? job->to_ms / portTICK_RATE_MS : portMAX_DELAY );
switch (err) {
case ESP_OK:
if (job->result) {
// all fine, deliver read data
lua_pushlstring( L, (char *)job->result->data, job->result->len );
} else {
lua_pushnil( L );
}
lua_pushboolean( L, 1 );
// prepare the next transfer
i2c_setup_ud_transfer( L, ud );
return 2;
case ESP_FAIL:
lua_pushnil( L );
lua_pushboolean( L, 0 );
// prepare the next transfer
i2c_setup_ud_transfer( L, ud );
return 2;
default:
i2c_setup_ud_transfer( L, ud );
return i2c_lua_checkerr( L, err );
}
}
} | // Initiate the I2C transfer
// Depending on the presence of a callback parameter, it will stay in synchronous mode
// or posts the job to the FreeRTOS queue for asynchronous processing.
// | Initiate the I2C transfer
Depending on the presence of a callback parameter, it will stay in synchronous mode
or posts the job to the FreeRTOS queue for asynchronous processing. | [
"Initiate",
"the",
"I2C",
"transfer",
"Depending",
"on",
"the",
"presence",
"of",
"a",
"callback",
"parameter",
"it",
"will",
"stay",
"in",
"synchronous",
"mode",
"or",
"posts",
"the",
"job",
"to",
"the",
"FreeRTOS",
"queue",
"for",
"asynchronous",
"processing",
"."
] | int li2c_hw_master_transfer( lua_State *L )
{
int stack = 0;
unsigned id = luaL_checkinteger( L, ++stack );
get_udata(L, id);
if (!job->cmd)
luaL_error( L, "no commands scheduled" );
stack++;
if (lua_isfunction( L, stack ) || lua_islightfunction( L, stack )) {
lua_pushvalue( L, stack );
luaL_unref( L, LUA_REGISTRYINDEX, job->cb_ref );
job->cb_ref = luaL_ref(L, LUA_REGISTRYINDEX);
} else
stack--;
int to_ms = luaL_optint( L, ++stack, 0 );
if (to_ms < 0)
to_ms = 0;
job->to_ms = to_ms;
if (job->cb_ref != LUA_NOREF) {
xQueueSend( ud->xTransferJobQueue, job, portMAX_DELAY );
portYIELD();
job->cmd = NULL;
job->result = NULL;
job->cb_ref = LUA_NOREF;
i2c_setup_ud_transfer( L, ud );
return 0;
} else {
esp_err_t err = i2c_master_cmd_begin( job->port, job->cmd,
job->to_ms > 0 ? job->to_ms / portTICK_RATE_MS : portMAX_DELAY );
switch (err) {
case ESP_OK:
if (job->result) {
lua_pushlstring( L, (char *)job->result->data, job->result->len );
} else {
lua_pushnil( L );
}
lua_pushboolean( L, 1 );
i2c_setup_ud_transfer( L, ud );
return 2;
case ESP_FAIL:
lua_pushnil( L );
lua_pushboolean( L, 0 );
i2c_setup_ud_transfer( L, ud );
return 2;
default:
i2c_setup_ud_transfer( L, ud );
return i2c_lua_checkerr( L, err );
}
}
} | [
"int",
"li2c_hw_master_transfer",
"(",
"lua_State",
"*",
"L",
")",
"{",
"int",
"stack",
"=",
"0",
";",
"unsigned",
"id",
"=",
"luaL_checkinteger",
"(",
"L",
",",
"++",
"stack",
")",
";",
"get_udata",
"(",
"L",
",",
"id",
")",
";",
"if",
"(",
"!",
"job",
"->",
"cmd",
")",
"luaL_error",
"(",
"L",
",",
"\"",
"\"",
")",
";",
"stack",
"++",
";",
"if",
"(",
"lua_isfunction",
"(",
"L",
",",
"stack",
")",
"||",
"lua_islightfunction",
"(",
"L",
",",
"stack",
")",
")",
"{",
"lua_pushvalue",
"(",
"L",
",",
"stack",
")",
";",
"luaL_unref",
"(",
"L",
",",
"LUA_REGISTRYINDEX",
",",
"job",
"->",
"cb_ref",
")",
";",
"job",
"->",
"cb_ref",
"=",
"luaL_ref",
"(",
"L",
",",
"LUA_REGISTRYINDEX",
")",
";",
"}",
"else",
"stack",
"--",
";",
"int",
"to_ms",
"=",
"luaL_optint",
"(",
"L",
",",
"++",
"stack",
",",
"0",
")",
";",
"if",
"(",
"to_ms",
"<",
"0",
")",
"to_ms",
"=",
"0",
";",
"job",
"->",
"to_ms",
"=",
"to_ms",
";",
"if",
"(",
"job",
"->",
"cb_ref",
"!=",
"LUA_NOREF",
")",
"{",
"xQueueSend",
"(",
"ud",
"->",
"xTransferJobQueue",
",",
"job",
",",
"portMAX_DELAY",
")",
";",
"portYIELD",
"(",
")",
";",
"job",
"->",
"cmd",
"=",
"NULL",
";",
"job",
"->",
"result",
"=",
"NULL",
";",
"job",
"->",
"cb_ref",
"=",
"LUA_NOREF",
";",
"i2c_setup_ud_transfer",
"(",
"L",
",",
"ud",
")",
";",
"return",
"0",
";",
"}",
"else",
"{",
"esp_err_t",
"err",
"=",
"i2c_master_cmd_begin",
"(",
"job",
"->",
"port",
",",
"job",
"->",
"cmd",
",",
"job",
"->",
"to_ms",
">",
"0",
"?",
"job",
"->",
"to_ms",
"/",
"portTICK_RATE_MS",
":",
"portMAX_DELAY",
")",
";",
"switch",
"(",
"err",
")",
"{",
"case",
"ESP_OK",
":",
"if",
"(",
"job",
"->",
"result",
")",
"{",
"lua_pushlstring",
"(",
"L",
",",
"(",
"char",
"*",
")",
"job",
"->",
"result",
"->",
"data",
",",
"job",
"->",
"result",
"->",
"len",
")",
";",
"}",
"else",
"{",
"lua_pushnil",
"(",
"L",
")",
";",
"}",
"lua_pushboolean",
"(",
"L",
",",
"1",
")",
";",
"i2c_setup_ud_transfer",
"(",
"L",
",",
"ud",
")",
";",
"return",
"2",
";",
"case",
"ESP_FAIL",
":",
"lua_pushnil",
"(",
"L",
")",
";",
"lua_pushboolean",
"(",
"L",
",",
"0",
")",
";",
"i2c_setup_ud_transfer",
"(",
"L",
",",
"ud",
")",
";",
"return",
"2",
";",
"default",
":",
"i2c_setup_ud_transfer",
"(",
"L",
",",
"ud",
")",
";",
"return",
"i2c_lua_checkerr",
"(",
"L",
",",
"err",
")",
";",
"}",
"}",
"}"
] | Initiate the I2C transfer
Depending on the presence of a callback parameter, it will stay in synchronous mode
or posts the job to the FreeRTOS queue for asynchronous processing. | [
"Initiate",
"the",
"I2C",
"transfer",
"Depending",
"on",
"the",
"presence",
"of",
"a",
"callback",
"parameter",
"it",
"will",
"stay",
"in",
"synchronous",
"mode",
"or",
"posts",
"the",
"job",
"to",
"the",
"FreeRTOS",
"queue",
"for",
"asynchronous",
"processing",
"."
] | [
"// copy argument (func) to the top of stack",
"// asynchronous mode",
"// the transfer task should be unblocked now",
"// (i.e. in eReady state since it can receive from the queue)",
"// invalidate last job, it's queued now",
"// don't delete link! it's used by the transfer task",
"// don't free result memory! it's used by the transfer task",
"// don't unref! it's used by the transfer task",
"// prepare the next transfer",
"// synchronous mode",
"// no need to wait for queue to become empty when queue depth is 1",
"// note that i2c_master_cmd_begin() implements mutual exclusive access",
"// if it is currently in progress from the transfer task, it will block here until ",
"// all fine, deliver read data",
"// prepare the next transfer",
"// prepare the next transfer"
] | [
{
"param": "L",
"type": "lua_State"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
43e372eeed26307c9d27ab1fa2701fb0031c4a51 | sentinela-online/nodemcu-firmware | components/modules/node.c | [
"MIT"
] | C | redir_write | ssize_t | ssize_t redir_write(int fd, const void *data, size_t size) {
if (serial_debug) // if serial_debug is nonzero, write to uart
fwrite(data, sizeof(char), size, oldstdout);
if (output_redir != LUA_NOREF) { // prepare lua call
lua_State *L = lua_getstate();
lua_rawgeti(L, LUA_REGISTRYINDEX, output_redir); // push function reference
lua_pushlstring(L, (char *)data, size); // push data
lua_pcall(L, 1, 0, 0); // invoke callback
}
return size;
} | // redir_write will be called everytime any code writes to stdout when
// redirection is active | redir_write will be called everytime any code writes to stdout when
redirection is active | [
"redir_write",
"will",
"be",
"called",
"everytime",
"any",
"code",
"writes",
"to",
"stdout",
"when",
"redirection",
"is",
"active"
] | ssize_t redir_write(int fd, const void *data, size_t size) {
if (serial_debug)
fwrite(data, sizeof(char), size, oldstdout);
if (output_redir != LUA_NOREF) {
lua_State *L = lua_getstate();
lua_rawgeti(L, LUA_REGISTRYINDEX, output_redir);
lua_pushlstring(L, (char *)data, size);
lua_pcall(L, 1, 0, 0);
}
return size;
} | [
"ssize_t",
"redir_write",
"(",
"int",
"fd",
",",
"const",
"void",
"*",
"data",
",",
"size_t",
"size",
")",
"{",
"if",
"(",
"serial_debug",
")",
"fwrite",
"(",
"data",
",",
"sizeof",
"(",
"char",
")",
",",
"size",
",",
"oldstdout",
")",
";",
"if",
"(",
"output_redir",
"!=",
"LUA_NOREF",
")",
"{",
"lua_State",
"*",
"L",
"=",
"lua_getstate",
"(",
")",
";",
"lua_rawgeti",
"(",
"L",
",",
"LUA_REGISTRYINDEX",
",",
"output_redir",
")",
";",
"lua_pushlstring",
"(",
"L",
",",
"(",
"char",
"*",
")",
"data",
",",
"size",
")",
";",
"lua_pcall",
"(",
"L",
",",
"1",
",",
"0",
",",
"0",
")",
";",
"}",
"return",
"size",
";",
"}"
] | redir_write will be called everytime any code writes to stdout when
redirection is active | [
"redir_write",
"will",
"be",
"called",
"everytime",
"any",
"code",
"writes",
"to",
"stdout",
"when",
"redirection",
"is",
"active"
] | [
"// if serial_debug is nonzero, write to uart",
"// prepare lua call",
"// push function reference",
"// push data",
"// invoke callback"
] | [
{
"param": "fd",
"type": "int"
},
{
"param": "data",
"type": "void"
},
{
"param": "size",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "fd",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "data",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "size",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
43e372eeed26307c9d27ab1fa2701fb0031c4a51 | sentinela-online/nodemcu-firmware | components/modules/node.c | [
"MIT"
] | C | redir_vprintf | int | int redir_vprintf(const char *fmt, va_list ap)
{
static char data[128];
int size = vsnprintf(data, 128, fmt, ap);
if (os_output_redir != LUA_NOREF) { // prepare lua call
lua_State *L = lua_getstate();
lua_rawgeti(L, LUA_REGISTRYINDEX, os_output_redir); // push function reference
lua_pushlstring(L, (char *)data, size); // push data
lua_pcall(L, 1, 0, 0); // invoke callback
}
return size;
} | // redir_vprintf will be called everytime the OS attempts to print a trace statement | redir_vprintf will be called everytime the OS attempts to print a trace statement | [
"redir_vprintf",
"will",
"be",
"called",
"everytime",
"the",
"OS",
"attempts",
"to",
"print",
"a",
"trace",
"statement"
] | int redir_vprintf(const char *fmt, va_list ap)
{
static char data[128];
int size = vsnprintf(data, 128, fmt, ap);
if (os_output_redir != LUA_NOREF) {
lua_State *L = lua_getstate();
lua_rawgeti(L, LUA_REGISTRYINDEX, os_output_redir);
lua_pushlstring(L, (char *)data, size);
lua_pcall(L, 1, 0, 0);
}
return size;
} | [
"int",
"redir_vprintf",
"(",
"const",
"char",
"*",
"fmt",
",",
"va_list",
"ap",
")",
"{",
"static",
"char",
"data",
"[",
"128",
"]",
";",
"int",
"size",
"=",
"vsnprintf",
"(",
"data",
",",
"128",
",",
"fmt",
",",
"ap",
")",
";",
"if",
"(",
"os_output_redir",
"!=",
"LUA_NOREF",
")",
"{",
"lua_State",
"*",
"L",
"=",
"lua_getstate",
"(",
")",
";",
"lua_rawgeti",
"(",
"L",
",",
"LUA_REGISTRYINDEX",
",",
"os_output_redir",
")",
";",
"lua_pushlstring",
"(",
"L",
",",
"(",
"char",
"*",
")",
"data",
",",
"size",
")",
";",
"lua_pcall",
"(",
"L",
",",
"1",
",",
"0",
",",
"0",
")",
";",
"}",
"return",
"size",
";",
"}"
] | redir_vprintf will be called everytime the OS attempts to print a trace statement | [
"redir_vprintf",
"will",
"be",
"called",
"everytime",
"the",
"OS",
"attempts",
"to",
"print",
"a",
"trace",
"statement"
] | [
"// prepare lua call",
"// push function reference",
"// push data",
"// invoke callback"
] | [
{
"param": "fmt",
"type": "char"
},
{
"param": "ap",
"type": "va_list"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "fmt",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ap",
"type": "va_list",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
43e372eeed26307c9d27ab1fa2701fb0031c4a51 | sentinela-online/nodemcu-firmware | components/modules/node.c | [
"MIT"
] | C | node_compile | int | static int node_compile( lua_State* L )
{
Proto* f;
int file_fd = 0;
size_t len;
const char *fname = luaL_checklstring( L, 1, &len );
const char *basename = vfs_basename( fname );
luaL_argcheck(L, strlen(basename) <= CONFIG_FS_OBJ_NAME_LEN && strlen(fname) == len, 1, "filename invalid");
char *output = luaM_malloc( L, len+1 );
strcpy(output, fname);
// check here that filename end with ".lua".
if (len < 4 || (strcmp( output + len - 4, ".lua") != 0) ) {
luaM_free( L, output );
return luaL_error(L, "not a .lua file");
}
output[strlen(output) - 2] = 'c';
output[strlen(output) - 1] = '\0';
NODE_DBG(output);
NODE_DBG("\n");
if (luaL_loadfsfile(L, fname) != 0) {
luaM_free( L, output );
return luaL_error(L, lua_tostring(L, -1));
}
f = toproto(L, -1);
int stripping = 1; /* strip debug information? */
file_fd = vfs_open(output, "w+");
if (!file_fd)
{
luaM_free( L, output );
return luaL_error(L, "cannot open/write to file");
}
lua_lock(L);
int result = luaU_dump(L, f, writer, &file_fd, stripping);
lua_unlock(L);
if (vfs_flush(file_fd) != VFS_RES_OK) {
// overwrite Lua error, like writer() does in case of a file io error
result = 1;
}
vfs_close(file_fd);
file_fd = 0;
luaM_free( L, output );
if (result == LUA_ERR_CC_INTOVERFLOW) {
return luaL_error(L, "value too big or small for target integer type");
}
if (result == LUA_ERR_CC_NOTINTEGER) {
return luaL_error(L, "target lua_Number is integral but fractional value found");
}
if (result == 1) { // result status generated by writer() or fs_flush() fail
return luaL_error(L, "writing to file failed");
}
return 0;
} | // Lua: compile(filename) -- compile lua file into lua bytecode, and save to .lc | - compile lua file into lua bytecode, and save to .lc | [
"-",
"compile",
"lua",
"file",
"into",
"lua",
"bytecode",
"and",
"save",
"to",
".",
"lc"
] | static int node_compile( lua_State* L )
{
Proto* f;
int file_fd = 0;
size_t len;
const char *fname = luaL_checklstring( L, 1, &len );
const char *basename = vfs_basename( fname );
luaL_argcheck(L, strlen(basename) <= CONFIG_FS_OBJ_NAME_LEN && strlen(fname) == len, 1, "filename invalid");
char *output = luaM_malloc( L, len+1 );
strcpy(output, fname);
if (len < 4 || (strcmp( output + len - 4, ".lua") != 0) ) {
luaM_free( L, output );
return luaL_error(L, "not a .lua file");
}
output[strlen(output) - 2] = 'c';
output[strlen(output) - 1] = '\0';
NODE_DBG(output);
NODE_DBG("\n");
if (luaL_loadfsfile(L, fname) != 0) {
luaM_free( L, output );
return luaL_error(L, lua_tostring(L, -1));
}
f = toproto(L, -1);
int stripping = 1;
file_fd = vfs_open(output, "w+");
if (!file_fd)
{
luaM_free( L, output );
return luaL_error(L, "cannot open/write to file");
}
lua_lock(L);
int result = luaU_dump(L, f, writer, &file_fd, stripping);
lua_unlock(L);
if (vfs_flush(file_fd) != VFS_RES_OK) {
result = 1;
}
vfs_close(file_fd);
file_fd = 0;
luaM_free( L, output );
if (result == LUA_ERR_CC_INTOVERFLOW) {
return luaL_error(L, "value too big or small for target integer type");
}
if (result == LUA_ERR_CC_NOTINTEGER) {
return luaL_error(L, "target lua_Number is integral but fractional value found");
}
if (result == 1) {
return luaL_error(L, "writing to file failed");
}
return 0;
} | [
"static",
"int",
"node_compile",
"(",
"lua_State",
"*",
"L",
")",
"{",
"Proto",
"*",
"f",
";",
"int",
"file_fd",
"=",
"0",
";",
"size_t",
"len",
";",
"const",
"char",
"*",
"fname",
"=",
"luaL_checklstring",
"(",
"L",
",",
"1",
",",
"&",
"len",
")",
";",
"const",
"char",
"*",
"basename",
"=",
"vfs_basename",
"(",
"fname",
")",
";",
"luaL_argcheck",
"(",
"L",
",",
"strlen",
"(",
"basename",
")",
"<=",
"CONFIG_FS_OBJ_NAME_LEN",
"&&",
"strlen",
"(",
"fname",
")",
"==",
"len",
",",
"1",
",",
"\"",
"\"",
")",
";",
"char",
"*",
"output",
"=",
"luaM_malloc",
"(",
"L",
",",
"len",
"+",
"1",
")",
";",
"strcpy",
"(",
"output",
",",
"fname",
")",
";",
"if",
"(",
"len",
"<",
"4",
"||",
"(",
"strcmp",
"(",
"output",
"+",
"len",
"-",
"4",
",",
"\"",
"\"",
")",
"!=",
"0",
")",
")",
"{",
"luaM_free",
"(",
"L",
",",
"output",
")",
";",
"return",
"luaL_error",
"(",
"L",
",",
"\"",
"\"",
")",
";",
"}",
"output",
"[",
"strlen",
"(",
"output",
")",
"-",
"2",
"]",
"=",
"'",
"'",
";",
"output",
"[",
"strlen",
"(",
"output",
")",
"-",
"1",
"]",
"=",
"'",
"\\0",
"'",
";",
"NODE_DBG",
"(",
"output",
")",
";",
"NODE_DBG",
"(",
"\"",
"\\n",
"\"",
")",
";",
"if",
"(",
"luaL_loadfsfile",
"(",
"L",
",",
"fname",
")",
"!=",
"0",
")",
"{",
"luaM_free",
"(",
"L",
",",
"output",
")",
";",
"return",
"luaL_error",
"(",
"L",
",",
"lua_tostring",
"(",
"L",
",",
"-1",
")",
")",
";",
"}",
"f",
"=",
"toproto",
"(",
"L",
",",
"-1",
")",
";",
"int",
"stripping",
"=",
"1",
";",
"file_fd",
"=",
"vfs_open",
"(",
"output",
",",
"\"",
"\"",
")",
";",
"if",
"(",
"!",
"file_fd",
")",
"{",
"luaM_free",
"(",
"L",
",",
"output",
")",
";",
"return",
"luaL_error",
"(",
"L",
",",
"\"",
"\"",
")",
";",
"}",
"lua_lock",
"(",
"L",
")",
";",
"int",
"result",
"=",
"luaU_dump",
"(",
"L",
",",
"f",
",",
"writer",
",",
"&",
"file_fd",
",",
"stripping",
")",
";",
"lua_unlock",
"(",
"L",
")",
";",
"if",
"(",
"vfs_flush",
"(",
"file_fd",
")",
"!=",
"VFS_RES_OK",
")",
"{",
"result",
"=",
"1",
";",
"}",
"vfs_close",
"(",
"file_fd",
")",
";",
"file_fd",
"=",
"0",
";",
"luaM_free",
"(",
"L",
",",
"output",
")",
";",
"if",
"(",
"result",
"==",
"LUA_ERR_CC_INTOVERFLOW",
")",
"{",
"return",
"luaL_error",
"(",
"L",
",",
"\"",
"\"",
")",
";",
"}",
"if",
"(",
"result",
"==",
"LUA_ERR_CC_NOTINTEGER",
")",
"{",
"return",
"luaL_error",
"(",
"L",
",",
"\"",
"\"",
")",
";",
"}",
"if",
"(",
"result",
"==",
"1",
")",
"{",
"return",
"luaL_error",
"(",
"L",
",",
"\"",
"\"",
")",
";",
"}",
"return",
"0",
";",
"}"
] | Lua: compile(filename) -- compile lua file into lua bytecode, and save to .lc | [
"Lua",
":",
"compile",
"(",
"filename",
")",
"--",
"compile",
"lua",
"file",
"into",
"lua",
"bytecode",
"and",
"save",
"to",
".",
"lc"
] | [
"// check here that filename end with \".lua\".",
"/* strip debug information? */",
"// overwrite Lua error, like writer() does in case of a file io error",
"// result status generated by writer() or fs_flush() fail"
] | [
{
"param": "L",
"type": "lua_State"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
273e0803fa42dc9ab1ec705ddc3d164371806746 | sentinela-online/nodemcu-firmware | components/driver_console/console.c | [
"MIT"
] | C | console_read_r | int | static int console_read_r (struct _reent *r, int fd, void *buf, int size, _read_r_fn next)
{
if (fd == STDIN_FILENO)
{
static _lock_t stdin_lock;
_lock_acquire_recursive (&stdin_lock);
char *c = (char *)buf;
int i = 0;
for (; i < size; ++i)
{
if (!console_getc (c++))
break;
}
_lock_release_recursive (&stdin_lock);
return i;
}
else if (next)
return next (r, fd, buf, size);
else
return -1;
} | // --- Syscall support for reading from STDIN_FILENO --------------- | Syscall support for reading from STDIN_FILENO | [
"Syscall",
"support",
"for",
"reading",
"from",
"STDIN_FILENO"
] | static int console_read_r (struct _reent *r, int fd, void *buf, int size, _read_r_fn next)
{
if (fd == STDIN_FILENO)
{
static _lock_t stdin_lock;
_lock_acquire_recursive (&stdin_lock);
char *c = (char *)buf;
int i = 0;
for (; i < size; ++i)
{
if (!console_getc (c++))
break;
}
_lock_release_recursive (&stdin_lock);
return i;
}
else if (next)
return next (r, fd, buf, size);
else
return -1;
} | [
"static",
"int",
"console_read_r",
"(",
"struct",
"_reent",
"*",
"r",
",",
"int",
"fd",
",",
"void",
"*",
"buf",
",",
"int",
"size",
",",
"_read_r_fn",
"next",
")",
"{",
"if",
"(",
"fd",
"==",
"STDIN_FILENO",
")",
"{",
"static",
"_lock_t",
"stdin_lock",
";",
"_lock_acquire_recursive",
"(",
"&",
"stdin_lock",
")",
";",
"char",
"*",
"c",
"=",
"(",
"char",
"*",
")",
"buf",
";",
"int",
"i",
"=",
"0",
";",
"for",
"(",
";",
"i",
"<",
"size",
";",
"++",
"i",
")",
"{",
"if",
"(",
"!",
"console_getc",
"(",
"c",
"++",
")",
")",
"break",
";",
"}",
"_lock_release_recursive",
"(",
"&",
"stdin_lock",
")",
";",
"return",
"i",
";",
"}",
"else",
"if",
"(",
"next",
")",
"return",
"next",
"(",
"r",
",",
"fd",
",",
"buf",
",",
"size",
")",
";",
"else",
"return",
"-1",
";",
"}"
] | Syscall support for reading from STDIN_FILENO | [
"Syscall",
"support",
"for",
"reading",
"from",
"STDIN_FILENO"
] | [] | [
{
"param": "r",
"type": "struct _reent"
},
{
"param": "fd",
"type": "int"
},
{
"param": "buf",
"type": "void"
},
{
"param": "size",
"type": "int"
},
{
"param": "next",
"type": "_read_r_fn"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "r",
"type": "struct _reent",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "fd",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "buf",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "size",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "next",
"type": "_read_r_fn",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
681878c66539615dd83b9e8d7d05214cbc603d48 | sentinela-online/nodemcu-firmware | components/modules/ws2812.c | [
"MIT"
] | C | ws2812_new_buffer | int | static int ws2812_new_buffer(lua_State *L) {
const int leds = luaL_checkint(L, 1);
const int colorsPerLed = luaL_checkint(L, 2);
luaL_argcheck(L, leds > 0, 1, "should be a positive integer");
luaL_argcheck(L, colorsPerLed > 0, 2, "should be a positive integer");
ws2812_buffer * buffer = allocate_buffer(L, leds, colorsPerLed);
memset(buffer->values, 0, colorsPerLed * leds);
return 1;
} | // Handle a buffer where we can store led values | Handle a buffer where we can store led values | [
"Handle",
"a",
"buffer",
"where",
"we",
"can",
"store",
"led",
"values"
] | static int ws2812_new_buffer(lua_State *L) {
const int leds = luaL_checkint(L, 1);
const int colorsPerLed = luaL_checkint(L, 2);
luaL_argcheck(L, leds > 0, 1, "should be a positive integer");
luaL_argcheck(L, colorsPerLed > 0, 2, "should be a positive integer");
ws2812_buffer * buffer = allocate_buffer(L, leds, colorsPerLed);
memset(buffer->values, 0, colorsPerLed * leds);
return 1;
} | [
"static",
"int",
"ws2812_new_buffer",
"(",
"lua_State",
"*",
"L",
")",
"{",
"const",
"int",
"leds",
"=",
"luaL_checkint",
"(",
"L",
",",
"1",
")",
";",
"const",
"int",
"colorsPerLed",
"=",
"luaL_checkint",
"(",
"L",
",",
"2",
")",
";",
"luaL_argcheck",
"(",
"L",
",",
"leds",
">",
"0",
",",
"1",
",",
"\"",
"\"",
")",
";",
"luaL_argcheck",
"(",
"L",
",",
"colorsPerLed",
">",
"0",
",",
"2",
",",
"\"",
"\"",
")",
";",
"ws2812_buffer",
"*",
"buffer",
"=",
"allocate_buffer",
"(",
"L",
",",
"leds",
",",
"colorsPerLed",
")",
";",
"memset",
"(",
"buffer",
"->",
"values",
",",
"0",
",",
"colorsPerLed",
"*",
"leds",
")",
";",
"return",
"1",
";",
"}"
] | Handle a buffer where we can store led values | [
"Handle",
"a",
"buffer",
"where",
"we",
"can",
"store",
"led",
"values"
] | [] | [
{
"param": "L",
"type": "lua_State"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
681878c66539615dd83b9e8d7d05214cbc603d48 | sentinela-online/nodemcu-firmware | components/modules/ws2812.c | [
"MIT"
] | C | ws2812_buffer_power | int | static int ws2812_buffer_power(lua_State* L) {
ws2812_buffer * buffer = (ws2812_buffer*)luaL_checkudata(L, 1, "ws2812.buffer");
size_t cells = buffer->size * buffer->colorsPerLed;
size_t i;
int total = 0;
for (i = 0; i < cells; i++) {
total += buffer->values[i];
}
lua_pushnumber(L, total);
return 1;
} | // Returns the total of all channels | Returns the total of all channels | [
"Returns",
"the",
"total",
"of",
"all",
"channels"
] | static int ws2812_buffer_power(lua_State* L) {
ws2812_buffer * buffer = (ws2812_buffer*)luaL_checkudata(L, 1, "ws2812.buffer");
size_t cells = buffer->size * buffer->colorsPerLed;
size_t i;
int total = 0;
for (i = 0; i < cells; i++) {
total += buffer->values[i];
}
lua_pushnumber(L, total);
return 1;
} | [
"static",
"int",
"ws2812_buffer_power",
"(",
"lua_State",
"*",
"L",
")",
"{",
"ws2812_buffer",
"*",
"buffer",
"=",
"(",
"ws2812_buffer",
"*",
")",
"luaL_checkudata",
"(",
"L",
",",
"1",
",",
"\"",
"\"",
")",
";",
"size_t",
"cells",
"=",
"buffer",
"->",
"size",
"*",
"buffer",
"->",
"colorsPerLed",
";",
"size_t",
"i",
";",
"int",
"total",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"cells",
";",
"i",
"++",
")",
"{",
"total",
"+=",
"buffer",
"->",
"values",
"[",
"i",
"]",
";",
"}",
"lua_pushnumber",
"(",
"L",
",",
"total",
")",
";",
"return",
"1",
";",
"}"
] | Returns the total of all channels | [
"Returns",
"the",
"total",
"of",
"all",
"channels"
] | [] | [
{
"param": "L",
"type": "lua_State"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4e694d5246989d55c32e589ff22297a8c6bed639 | sentinela-online/nodemcu-firmware | components/modules/net.c | [
"MIT"
] | C | lnet_netconn_callback | void | static void lnet_netconn_callback(struct netconn *netconn, enum netconn_evt evt, u16_t len)
{
if (!netconn) return;
switch (evt)
{
case NETCONN_EVT_SENDPLUS:
case NETCONN_EVT_RCVPLUS:
case NETCONN_EVT_ERROR: break;
default: return; // we don't care about minus events
}
netconn_bounce_event_t *nbe = malloc(sizeof(netconn_bounce_event_t));
if (!nbe)
{
ESP_LOGE("net", "out of memory - lost event notification!");
return;
}
nbe->netconn = netconn;
nbe->len = len;
nbe->err = ERR_OK;
task_prio_t prio = TASK_PRIORITY_MEDIUM;
switch (evt)
{
case NETCONN_EVT_SENDPLUS:
nbe->event = (len == 0) ? EVT_CONNECTED : EVT_SENT; break;
case NETCONN_EVT_RCVPLUS:
nbe->event = (len == 0) ? EVT_ZEROREAD : EVT_RECV;
prio = TASK_PRIORITY_HIGH;
break;
case NETCONN_EVT_ERROR:
nbe->event = EVT_ERR;
nbe->err = netconn_err(netconn); // is this safe in this thread?
break;
default: break; // impossible
}
if (!task_post(prio, net_handler, (task_param_t)nbe))
ESP_LOGE("net", "out of task post slots - lost data!");
} | // Caution - these run in a different RTOS thread! | these run in a different RTOS thread! | [
"these",
"run",
"in",
"a",
"different",
"RTOS",
"thread!"
] | static void lnet_netconn_callback(struct netconn *netconn, enum netconn_evt evt, u16_t len)
{
if (!netconn) return;
switch (evt)
{
case NETCONN_EVT_SENDPLUS:
case NETCONN_EVT_RCVPLUS:
case NETCONN_EVT_ERROR: break;
default: return;
}
netconn_bounce_event_t *nbe = malloc(sizeof(netconn_bounce_event_t));
if (!nbe)
{
ESP_LOGE("net", "out of memory - lost event notification!");
return;
}
nbe->netconn = netconn;
nbe->len = len;
nbe->err = ERR_OK;
task_prio_t prio = TASK_PRIORITY_MEDIUM;
switch (evt)
{
case NETCONN_EVT_SENDPLUS:
nbe->event = (len == 0) ? EVT_CONNECTED : EVT_SENT; break;
case NETCONN_EVT_RCVPLUS:
nbe->event = (len == 0) ? EVT_ZEROREAD : EVT_RECV;
prio = TASK_PRIORITY_HIGH;
break;
case NETCONN_EVT_ERROR:
nbe->event = EVT_ERR;
nbe->err = netconn_err(netconn);
break;
default: break;
}
if (!task_post(prio, net_handler, (task_param_t)nbe))
ESP_LOGE("net", "out of task post slots - lost data!");
} | [
"static",
"void",
"lnet_netconn_callback",
"(",
"struct",
"netconn",
"*",
"netconn",
",",
"enum",
"netconn_evt",
"evt",
",",
"u16_t",
"len",
")",
"{",
"if",
"(",
"!",
"netconn",
")",
"return",
";",
"switch",
"(",
"evt",
")",
"{",
"case",
"NETCONN_EVT_SENDPLUS",
":",
"case",
"NETCONN_EVT_RCVPLUS",
":",
"case",
"NETCONN_EVT_ERROR",
":",
"break",
";",
"default",
":",
"return",
";",
"}",
"netconn_bounce_event_t",
"*",
"nbe",
"=",
"malloc",
"(",
"sizeof",
"(",
"netconn_bounce_event_t",
")",
")",
";",
"if",
"(",
"!",
"nbe",
")",
"{",
"ESP_LOGE",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"return",
";",
"}",
"nbe",
"->",
"netconn",
"=",
"netconn",
";",
"nbe",
"->",
"len",
"=",
"len",
";",
"nbe",
"->",
"err",
"=",
"ERR_OK",
";",
"task_prio_t",
"prio",
"=",
"TASK_PRIORITY_MEDIUM",
";",
"switch",
"(",
"evt",
")",
"{",
"case",
"NETCONN_EVT_SENDPLUS",
":",
"nbe",
"->",
"event",
"=",
"(",
"len",
"==",
"0",
")",
"?",
"EVT_CONNECTED",
":",
"EVT_SENT",
";",
"break",
";",
"case",
"NETCONN_EVT_RCVPLUS",
":",
"nbe",
"->",
"event",
"=",
"(",
"len",
"==",
"0",
")",
"?",
"EVT_ZEROREAD",
":",
"EVT_RECV",
";",
"prio",
"=",
"TASK_PRIORITY_HIGH",
";",
"break",
";",
"case",
"NETCONN_EVT_ERROR",
":",
"nbe",
"->",
"event",
"=",
"EVT_ERR",
";",
"nbe",
"->",
"err",
"=",
"netconn_err",
"(",
"netconn",
")",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"if",
"(",
"!",
"task_post",
"(",
"prio",
",",
"net_handler",
",",
"(",
"task_param_t",
")",
"nbe",
")",
")",
"ESP_LOGE",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"}"
] | Caution - these run in a different RTOS thread! | [
"Caution",
"-",
"these",
"run",
"in",
"a",
"different",
"RTOS",
"thread!"
] | [
"// we don't care about minus events",
"// is this safe in this thread?",
"// impossible"
] | [
{
"param": "netconn",
"type": "struct netconn"
},
{
"param": "evt",
"type": "enum netconn_evt"
},
{
"param": "len",
"type": "u16_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "netconn",
"type": "struct netconn",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "evt",
"type": "enum netconn_evt",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "len",
"type": "u16_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4e694d5246989d55c32e589ff22297a8c6bed639 | sentinela-online/nodemcu-firmware | components/modules/net.c | [
"MIT"
] | C | net_dns_cb | void | static void net_dns_cb(const char *name, const ip_addr_t *ipaddr, void *callback_arg) {
dns_event_t *ev = (dns_event_t *)callback_arg;
ev->resolved_ip = ipaddr ? *ipaddr : ip_addr_any;
if (!task_post_medium(dns_handler, (task_param_t)ev))
{
ESP_LOGE("net", "out of task post slots - lost DNS response for %s", name);
// And we also leaked the ev here :(
}
} | // This one may *also* run in the LVM thread | This one may *also* run in the LVM thread | [
"This",
"one",
"may",
"*",
"also",
"*",
"run",
"in",
"the",
"LVM",
"thread"
] | static void net_dns_cb(const char *name, const ip_addr_t *ipaddr, void *callback_arg) {
dns_event_t *ev = (dns_event_t *)callback_arg;
ev->resolved_ip = ipaddr ? *ipaddr : ip_addr_any;
if (!task_post_medium(dns_handler, (task_param_t)ev))
{
ESP_LOGE("net", "out of task post slots - lost DNS response for %s", name);
}
} | [
"static",
"void",
"net_dns_cb",
"(",
"const",
"char",
"*",
"name",
",",
"const",
"ip_addr_t",
"*",
"ipaddr",
",",
"void",
"*",
"callback_arg",
")",
"{",
"dns_event_t",
"*",
"ev",
"=",
"(",
"dns_event_t",
"*",
")",
"callback_arg",
";",
"ev",
"->",
"resolved_ip",
"=",
"ipaddr",
"?",
"*",
"ipaddr",
":",
"ip_addr_any",
";",
"if",
"(",
"!",
"task_post_medium",
"(",
"dns_handler",
",",
"(",
"task_param_t",
")",
"ev",
")",
")",
"{",
"ESP_LOGE",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"name",
")",
";",
"}",
"}"
] | This one may *also* run in the LVM thread | [
"This",
"one",
"may",
"*",
"also",
"*",
"run",
"in",
"the",
"LVM",
"thread"
] | [
"// And we also leaked the ev here :("
] | [
{
"param": "name",
"type": "char"
},
{
"param": "ipaddr",
"type": "ip_addr_t"
},
{
"param": "callback_arg",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "name",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ipaddr",
"type": "ip_addr_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "callback_arg",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
9fde97e44752dc2bf7b5982093e23b49b084fe6b | sentinela-online/nodemcu-firmware | components/modules/bthci.c | [
"MIT"
] | C | send_hci_command | int | static int send_hci_command (lua_State *L, uint8_t *data, unsigned len)
{
if (esp_vhci_host_check_send_available ())
{
uint16_t cmd = (((uint16_t)data[2]) << 8) | data[1];
for (int i = 0; i < MAX_CMD_Q; ++i)
{
if (cmd_q[i].cb_ref == LUA_NOREF)
{
if (lua_gettop (L) > 0 && !lua_isnil (L, -1))
{
cmd_q[i].cmd = cmd;
luaL_checkanyfunction (L, -1);
lua_pushvalue (L, -1);
cmd_q[i].cb_ref = luaL_ref (L, LUA_REGISTRYINDEX);
}
esp_vhci_host_send_packet (data, len);
return 0;
}
}
}
// Nope, couldn't send this command!
lua_pushinteger (L, ERROR_UNSPECIFIED);
lua_pushlstring (L, NULL, 0);
lua_call (L, 2, 0);
return 0;
} | // Expects callback function at top of stack | Expects callback function at top of stack | [
"Expects",
"callback",
"function",
"at",
"top",
"of",
"stack"
] | static int send_hci_command (lua_State *L, uint8_t *data, unsigned len)
{
if (esp_vhci_host_check_send_available ())
{
uint16_t cmd = (((uint16_t)data[2]) << 8) | data[1];
for (int i = 0; i < MAX_CMD_Q; ++i)
{
if (cmd_q[i].cb_ref == LUA_NOREF)
{
if (lua_gettop (L) > 0 && !lua_isnil (L, -1))
{
cmd_q[i].cmd = cmd;
luaL_checkanyfunction (L, -1);
lua_pushvalue (L, -1);
cmd_q[i].cb_ref = luaL_ref (L, LUA_REGISTRYINDEX);
}
esp_vhci_host_send_packet (data, len);
return 0;
}
}
}
lua_pushinteger (L, ERROR_UNSPECIFIED);
lua_pushlstring (L, NULL, 0);
lua_call (L, 2, 0);
return 0;
} | [
"static",
"int",
"send_hci_command",
"(",
"lua_State",
"*",
"L",
",",
"uint8_t",
"*",
"data",
",",
"unsigned",
"len",
")",
"{",
"if",
"(",
"esp_vhci_host_check_send_available",
"(",
")",
")",
"{",
"uint16_t",
"cmd",
"=",
"(",
"(",
"(",
"uint16_t",
")",
"data",
"[",
"2",
"]",
")",
"<<",
"8",
")",
"|",
"data",
"[",
"1",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"MAX_CMD_Q",
";",
"++",
"i",
")",
"{",
"if",
"(",
"cmd_q",
"[",
"i",
"]",
".",
"cb_ref",
"==",
"LUA_NOREF",
")",
"{",
"if",
"(",
"lua_gettop",
"(",
"L",
")",
">",
"0",
"&&",
"!",
"lua_isnil",
"(",
"L",
",",
"-1",
")",
")",
"{",
"cmd_q",
"[",
"i",
"]",
".",
"cmd",
"=",
"cmd",
";",
"luaL_checkanyfunction",
"(",
"L",
",",
"-1",
")",
";",
"lua_pushvalue",
"(",
"L",
",",
"-1",
")",
";",
"cmd_q",
"[",
"i",
"]",
".",
"cb_ref",
"=",
"luaL_ref",
"(",
"L",
",",
"LUA_REGISTRYINDEX",
")",
";",
"}",
"esp_vhci_host_send_packet",
"(",
"data",
",",
"len",
")",
";",
"return",
"0",
";",
"}",
"}",
"}",
"lua_pushinteger",
"(",
"L",
",",
"ERROR_UNSPECIFIED",
")",
";",
"lua_pushlstring",
"(",
"L",
",",
"NULL",
",",
"0",
")",
";",
"lua_call",
"(",
"L",
",",
"2",
",",
"0",
")",
";",
"return",
"0",
";",
"}"
] | Expects callback function at top of stack | [
"Expects",
"callback",
"function",
"at",
"top",
"of",
"stack"
] | [
"// Nope, couldn't send this command!"
] | [
{
"param": "L",
"type": "lua_State"
},
{
"param": "data",
"type": "uint8_t"
},
{
"param": "len",
"type": "unsigned"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "data",
"type": "uint8_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "len",
"type": "unsigned",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8af6c5f55a01b01b443d1b3edad73a9ae9e305e6 | sentinela-online/nodemcu-firmware | components/modules/common.c | [
"MIT"
] | C | opt_get | bool | bool opt_get(lua_State *L, const char *name, int required_type)
{
if (!lua_istable(L, -1)) {
return false;
}
lua_getfield(L, -1, name);
int type = lua_type(L, -1);
if (type == LUA_TNIL) {
// Option not present
lua_pop(L, 1);
return false;
}
if (type != required_type) {
const char* msg = lua_pushfstring(L, "%s expected, got %s",
lua_typename(L, required_type),
lua_typename(L, type));
opt_error(L, name, msg);
}
return true;
} | // Similar to luaL_argcheck() but using the options table rather than a raw index | Similar to luaL_argcheck() but using the options table rather than a raw index | [
"Similar",
"to",
"luaL_argcheck",
"()",
"but",
"using",
"the",
"options",
"table",
"rather",
"than",
"a",
"raw",
"index"
] | bool opt_get(lua_State *L, const char *name, int required_type)
{
if (!lua_istable(L, -1)) {
return false;
}
lua_getfield(L, -1, name);
int type = lua_type(L, -1);
if (type == LUA_TNIL) {
lua_pop(L, 1);
return false;
}
if (type != required_type) {
const char* msg = lua_pushfstring(L, "%s expected, got %s",
lua_typename(L, required_type),
lua_typename(L, type));
opt_error(L, name, msg);
}
return true;
} | [
"bool",
"opt_get",
"(",
"lua_State",
"*",
"L",
",",
"const",
"char",
"*",
"name",
",",
"int",
"required_type",
")",
"{",
"if",
"(",
"!",
"lua_istable",
"(",
"L",
",",
"-1",
")",
")",
"{",
"return",
"false",
";",
"}",
"lua_getfield",
"(",
"L",
",",
"-1",
",",
"name",
")",
";",
"int",
"type",
"=",
"lua_type",
"(",
"L",
",",
"-1",
")",
";",
"if",
"(",
"type",
"==",
"LUA_TNIL",
")",
"{",
"lua_pop",
"(",
"L",
",",
"1",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"type",
"!=",
"required_type",
")",
"{",
"const",
"char",
"*",
"msg",
"=",
"lua_pushfstring",
"(",
"L",
",",
"\"",
"\"",
",",
"lua_typename",
"(",
"L",
",",
"required_type",
")",
",",
"lua_typename",
"(",
"L",
",",
"type",
")",
")",
";",
"opt_error",
"(",
"L",
",",
"name",
",",
"msg",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Similar to luaL_argcheck() but using the options table rather than a raw index | [
"Similar",
"to",
"luaL_argcheck",
"()",
"but",
"using",
"the",
"options",
"table",
"rather",
"than",
"a",
"raw",
"index"
] | [
"// Option not present"
] | [
{
"param": "L",
"type": "lua_State"
},
{
"param": "name",
"type": "char"
},
{
"param": "required_type",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "name",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "required_type",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
2c63f567141490498c31a05db366843269ea8398 | DankPaster/OverdriveCheat | real/overdrive/resistance/utils.h | [
"MIT"
] | C | DetachConsole | void | void DetachConsole()
{
if (_out && _err && _in) {
FreeConsole();
if (_old_out)
SetStdHandle(STD_OUTPUT_HANDLE, _old_out);
if (_old_err)
SetStdHandle(STD_ERROR_HANDLE, _old_err);
if (_old_in)
SetStdHandle(STD_INPUT_HANDLE, _old_in);
}
} | /*
* @brief Detach console
*
* Detach and destroy the attached console
*/ | @brief Detach console
Detach and destroy the attached console | [
"@brief",
"Detach",
"console",
"Detach",
"and",
"destroy",
"the",
"attached",
"console"
] | void DetachConsole()
{
if (_out && _err && _in) {
FreeConsole();
if (_old_out)
SetStdHandle(STD_OUTPUT_HANDLE, _old_out);
if (_old_err)
SetStdHandle(STD_ERROR_HANDLE, _old_err);
if (_old_in)
SetStdHandle(STD_INPUT_HANDLE, _old_in);
}
} | [
"void",
"DetachConsole",
"(",
")",
"{",
"if",
"(",
"_out",
"&&",
"_err",
"&&",
"_in",
")",
"{",
"FreeConsole",
"(",
")",
";",
"if",
"(",
"_old_out",
")",
"SetStdHandle",
"(",
"STD_OUTPUT_HANDLE",
",",
"_old_out",
")",
";",
"if",
"(",
"_old_err",
")",
"SetStdHandle",
"(",
"STD_ERROR_HANDLE",
",",
"_old_err",
")",
";",
"if",
"(",
"_old_in",
")",
"SetStdHandle",
"(",
"STD_INPUT_HANDLE",
",",
"_old_in",
")",
";",
"}",
"}"
] | @brief Detach console
Detach and destroy the attached console | [
"@brief",
"Detach",
"console",
"Detach",
"and",
"destroy",
"the",
"attached",
"console"
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
2c63f567141490498c31a05db366843269ea8398 | DankPaster/OverdriveCheat | real/overdrive/resistance/utils.h | [
"MIT"
] | C | ConsolePrint | bool | bool ConsolePrint(const char* fmt, ...)
{
if (!_out)
return false;
char buf[1024];
va_list va;
va_start(va, fmt);
_vsnprintf_s(buf, 1024, fmt, va);
va_end(va);
return !!WriteConsoleA(_out, buf, static_cast<DWORD>(strlen(buf)), nullptr, nullptr);
} | /*
* @brief Print to console
*
* Replacement to printf that works with the newly created console
*/ | @brief Print to console
Replacement to printf that works with the newly created console | [
"@brief",
"Print",
"to",
"console",
"Replacement",
"to",
"printf",
"that",
"works",
"with",
"the",
"newly",
"created",
"console"
] | bool ConsolePrint(const char* fmt, ...)
{
if (!_out)
return false;
char buf[1024];
va_list va;
va_start(va, fmt);
_vsnprintf_s(buf, 1024, fmt, va);
va_end(va);
return !!WriteConsoleA(_out, buf, static_cast<DWORD>(strlen(buf)), nullptr, nullptr);
} | [
"bool",
"ConsolePrint",
"(",
"const",
"char",
"*",
"fmt",
",",
"...",
")",
"{",
"if",
"(",
"!",
"_out",
")",
"return",
"false",
";",
"char",
"buf",
"[",
"1024",
"]",
";",
"va_list",
"va",
";",
"va_start",
"(",
"va",
",",
"fmt",
")",
";",
"_vsnprintf_s",
"(",
"buf",
",",
"1024",
",",
"fmt",
",",
"va",
")",
";",
"va_end",
"(",
"va",
")",
";",
"return",
"!",
"!",
"WriteConsoleA",
"(",
"_out",
",",
"buf",
",",
"static_cast",
"<",
"DWORD",
">",
"(",
"strlen",
"(",
"buf",
")",
")",
",",
"nullptr",
",",
"nullptr",
")",
";",
"}"
] | @brief Print to console
Replacement to printf that works with the newly created console | [
"@brief",
"Print",
"to",
"console",
"Replacement",
"to",
"printf",
"that",
"works",
"with",
"the",
"newly",
"created",
"console"
] | [] | [
{
"param": "fmt",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "fmt",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
2c63f567141490498c31a05db366843269ea8398 | DankPaster/OverdriveCheat | real/overdrive/resistance/utils.h | [
"MIT"
] | C | SetClantag | void | void SetClantag(const char* tag)
{
static auto fnClantagChanged = (int(__fastcall*)(const char*, const char*))PatternScan(GetModuleHandleW(L"engine.dll"), "53 56 57 8B DA 8B F9 FF 15");
fnClantagChanged(tag, tag);
} | /*
* @brief Set player clantag
*
* @param tag New clantag
*/ | @brief Set player clantag
@param tag New clantag | [
"@brief",
"Set",
"player",
"clantag",
"@param",
"tag",
"New",
"clantag"
] | void SetClantag(const char* tag)
{
static auto fnClantagChanged = (int(__fastcall*)(const char*, const char*))PatternScan(GetModuleHandleW(L"engine.dll"), "53 56 57 8B DA 8B F9 FF 15");
fnClantagChanged(tag, tag);
} | [
"void",
"SetClantag",
"(",
"const",
"char",
"*",
"tag",
")",
"{",
"static",
"auto",
"fnClantagChanged",
"",
"=",
"(",
"int",
"(",
"__fastcall",
"*",
")",
"(",
"const",
"char",
"*",
",",
"const",
"char",
"*",
")",
")",
"PatternScan",
"(",
"GetModuleHandleW",
"(",
"L\"",
"\"",
")",
",",
"\"",
"\"",
")",
";",
"fnClantagChanged",
"(",
"tag",
",",
"tag",
")",
";",
"}"
] | @brief Set player clantag
@param tag New clantag | [
"@brief",
"Set",
"player",
"clantag",
"@param",
"tag",
"New",
"clantag"
] | [] | [
{
"param": "tag",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "tag",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
2c63f567141490498c31a05db366843269ea8398 | DankPaster/OverdriveCheat | real/overdrive/resistance/utils.h | [
"MIT"
] | C | RankRevealAll | void | void RankRevealAll()
{
using ServerRankRevealAll = char(__cdecl*)(int*);
static auto fnServerRankRevealAll = PatternScan(GetModuleHandleW(L"client.dll"), "55 8B EC 8B 0D ? ? ? ? 68");
int v[3] = { 0,0,0 };
reinterpret_cast<ServerRankRevealAll>(fnServerRankRevealAll)(v);
} | /*
* @brief Reveal the ranks of all players on the server
*
*/ | @brief Reveal the ranks of all players on the server | [
"@brief",
"Reveal",
"the",
"ranks",
"of",
"all",
"players",
"on",
"the",
"server"
] | void RankRevealAll()
{
using ServerRankRevealAll = char(__cdecl*)(int*);
static auto fnServerRankRevealAll = PatternScan(GetModuleHandleW(L"client.dll"), "55 8B EC 8B 0D ? ? ? ? 68");
int v[3] = { 0,0,0 };
reinterpret_cast<ServerRankRevealAll>(fnServerRankRevealAll)(v);
} | [
"void",
"RankRevealAll",
"(",
")",
"{",
"using",
"ServerRankRevealAll",
"=",
"char",
"(",
"__cdecl",
"*",
"",
")",
"(",
"int",
"*",
"",
")",
";",
"static",
"auto",
"fnServerRankRevealAll",
"",
"=",
"PatternScan",
"(",
"GetModuleHandleW",
"(",
"L\"",
"\"",
")",
",",
"\"",
"\"",
")",
";",
"int",
"v",
"[",
"3",
"]",
"=",
"{",
"0",
",",
"0",
",",
"0",
"}",
";",
"reinterpret_cast",
"<",
"ServerRankRevealAll",
">",
"(",
"fnServerRankRevealAll",
")",
"(",
"v",
")",
";",
"}"
] | @brief Reveal the ranks of all players on the server | [
"@brief",
"Reveal",
"the",
"ranks",
"of",
"all",
"players",
"on",
"the",
"server"
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
2c63f567141490498c31a05db366843269ea8398 | DankPaster/OverdriveCheat | real/overdrive/resistance/utils.h | [
"MIT"
] | C | SetSky | void | void SetSky(const char* name)
{
static auto LoadNamedSky_Function = (void(__fastcall*)(const char*))(PatternScan(GetModuleHandleW(L"engine.dll"), "55 8B EC 81 EC ? ? ? ? 56 57 8B F9 C7 45"));
LoadNamedSky_Function(name);
} | /*
* @brief Sets the skybox
*
* @param name New skybox name
*/ | @brief Sets the skybox
@param name New skybox name | [
"@brief",
"Sets",
"the",
"skybox",
"@param",
"name",
"New",
"skybox",
"name"
] | void SetSky(const char* name)
{
static auto LoadNamedSky_Function = (void(__fastcall*)(const char*))(PatternScan(GetModuleHandleW(L"engine.dll"), "55 8B EC 81 EC ? ? ? ? 56 57 8B F9 C7 45"));
LoadNamedSky_Function(name);
} | [
"void",
"SetSky",
"(",
"const",
"char",
"*",
"name",
")",
"{",
"static",
"auto",
"LoadNamedSky_Function",
"",
"=",
"(",
"void",
"(",
"__fastcall",
"*",
")",
"(",
"const",
"char",
"*",
")",
")",
"(",
"PatternScan",
"(",
"GetModuleHandleW",
"(",
"L\"",
"\"",
")",
",",
"\"",
"\"",
")",
")",
";",
"LoadNamedSky_Function",
"(",
"name",
")",
";",
"}"
] | @brief Sets the skybox
@param name New skybox name | [
"@brief",
"Sets",
"the",
"skybox",
"@param",
"name",
"New",
"skybox",
"name"
] | [] | [
{
"param": "name",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "name",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
2c63f567141490498c31a05db366843269ea8398 | DankPaster/OverdriveCheat | real/overdrive/resistance/utils.h | [
"MIT"
] | C | LineGoesThroughSmoke | bool | bool LineGoesThroughSmoke(Vector vStartPos, Vector vEndPos)
{
static auto LineGoesThroughSmoke_Function = (bool(__cdecl*)(Vector, Vector))(PatternScan(GetModuleHandleW(L"client.dll"), "55 8B EC 83 EC 08 8B 15 ? ? ? ? 0F 57 C0"));
return LineGoesThroughSmoke_Function(vStartPos, vEndPos);
} | /*
* @brief Tests if a line goes through smoke
*
* @param vStartPos, vEndPos Line start position, Line end position
*/ | @brief Tests if a line goes through smoke
@param vStartPos, vEndPos Line start position, Line end position | [
"@brief",
"Tests",
"if",
"a",
"line",
"goes",
"through",
"smoke",
"@param",
"vStartPos",
"vEndPos",
"Line",
"start",
"position",
"Line",
"end",
"position"
] | bool LineGoesThroughSmoke(Vector vStartPos, Vector vEndPos)
{
static auto LineGoesThroughSmoke_Function = (bool(__cdecl*)(Vector, Vector))(PatternScan(GetModuleHandleW(L"client.dll"), "55 8B EC 83 EC 08 8B 15 ? ? ? ? 0F 57 C0"));
return LineGoesThroughSmoke_Function(vStartPos, vEndPos);
} | [
"bool",
"LineGoesThroughSmoke",
"(",
"Vector",
"vStartPos",
",",
"Vector",
"vEndPos",
")",
"{",
"static",
"auto",
"LineGoesThroughSmoke_Function",
"",
"=",
"(",
"bool",
"(",
"__cdecl",
"*",
")",
"(",
"Vector",
",",
"Vector",
")",
")",
"(",
"PatternScan",
"(",
"GetModuleHandleW",
"(",
"L\"",
"\"",
")",
",",
"\"",
"\"",
")",
")",
";",
"return",
"LineGoesThroughSmoke_Function",
"(",
"vStartPos",
",",
"vEndPos",
")",
";",
"}"
] | @brief Tests if a line goes through smoke
@param vStartPos, vEndPos Line start position, Line end position | [
"@brief",
"Tests",
"if",
"a",
"line",
"goes",
"through",
"smoke",
"@param",
"vStartPos",
"vEndPos",
"Line",
"start",
"position",
"Line",
"end",
"position"
] | [] | [
{
"param": "vStartPos",
"type": "Vector"
},
{
"param": "vEndPos",
"type": "Vector"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "vStartPos",
"type": "Vector",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "vEndPos",
"type": "Vector",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
c151d7ac56267bbaf2d46810d252885a9602ba62 | danielsen/sequential-uuids | sequential_uuids.c | [
"MIT"
] | C | uuid_sequence_nextval | Datum | Datum
uuid_sequence_nextval(PG_FUNCTION_ARGS)
{
int i;
int64 val;
Oid relid = PG_GETARG_OID(0);
int32 block_size = PG_GETARG_INT32(1);
int32 block_count = PG_GETARG_INT32(2);
int64 prefix_bytes;
pg_uuid_t *uuid;
unsigned char *p;
/* some basic sanity checks */
if (block_size < 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("block size must be a positive integer")));
if (block_count < 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("number of blocks must be a positive integer")));
/* count the number of bytes to keep from the sequence value */
prefix_bytes = 0;
while (block_count > 1)
{
block_count /= 256;
prefix_bytes++;
}
/*
* Read the next value from the sequence and get rid of the least
* significant bytes.
*/
val = nextval_internal(relid, true);
val /= block_size;
p = (unsigned char *) &val;
uuid = palloc(sizeof(pg_uuid_t));
/* copy the desired number of (least significant) bytes as prefix */
for (i = 0; i < prefix_bytes; i++)
uuid->data[i] = p[prefix_bytes - 1 - i];
/* generate the remaining bytes as random (use strong generator) */
if(!pg_strong_random(uuid->data + prefix_bytes, UUID_LEN - prefix_bytes))
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("could not generate random values")));
/*
* Set the UUID version flags according to "version 4" (pseudorandom)
* UUID, see http://tools.ietf.org/html/rfc4122#section-4.4
*
* This does reduce the randomness a bit, because it determines the
* value of certain bits, but that should be negligible (certainly
* compared to the reduction due to prefix).
*
* UUID v4 is probably the safest choice here. There is v1 which is
* time-based, but it includes MAC address (which we don't use) and
* works with very special timestamp (starting at 1582 etc.). So we
* just use v4 and claim this is pseudorandom.
*/
uuid->data[6] = (uuid->data[6] & 0x0f) | 0x40; /* time_hi_and_version */
uuid->data[8] = (uuid->data[8] & 0x3f) | 0x80; /* clock_seq_hi_and_reserved */
PG_RETURN_UUID_P(uuid);
} | /*
* uuid_sequence_nextval
* generate sequential UUID using a sequence
*
* The sequence-based sequential UUID generator define the group size
* and group count based on number of UUIDs generated.
*
* The block_size (65546 by default) determines the number of UUIDs with
* the same prefix, and block_count (65536 by default) determines the
* number of blocks before wrapping around to 0. This means that with
* the default values, the generator wraps around every ~2B UUIDs.
*
* You may increase (or rather decrease) the parameters if needed, e.g,
* by lowering the block size to 256, in wich case the cycle interval
* is only 16M values.
*/ | uuid_sequence_nextval
generate sequential UUID using a sequence
The sequence-based sequential UUID generator define the group size
and group count based on number of UUIDs generated.
The block_size (65546 by default) determines the number of UUIDs with
the same prefix, and block_count (65536 by default) determines the
number of blocks before wrapping around to 0. This means that with
the default values, the generator wraps around every ~2B UUIDs.
You may increase (or rather decrease) the parameters if needed, e.g,
by lowering the block size to 256, in wich case the cycle interval
is only 16M values. | [
"uuid_sequence_nextval",
"generate",
"sequential",
"UUID",
"using",
"a",
"sequence",
"The",
"sequence",
"-",
"based",
"sequential",
"UUID",
"generator",
"define",
"the",
"group",
"size",
"and",
"group",
"count",
"based",
"on",
"number",
"of",
"UUIDs",
"generated",
".",
"The",
"block_size",
"(",
"65546",
"by",
"default",
")",
"determines",
"the",
"number",
"of",
"UUIDs",
"with",
"the",
"same",
"prefix",
"and",
"block_count",
"(",
"65536",
"by",
"default",
")",
"determines",
"the",
"number",
"of",
"blocks",
"before",
"wrapping",
"around",
"to",
"0",
".",
"This",
"means",
"that",
"with",
"the",
"default",
"values",
"the",
"generator",
"wraps",
"around",
"every",
"~2B",
"UUIDs",
".",
"You",
"may",
"increase",
"(",
"or",
"rather",
"decrease",
")",
"the",
"parameters",
"if",
"needed",
"e",
".",
"g",
"by",
"lowering",
"the",
"block",
"size",
"to",
"256",
"in",
"wich",
"case",
"the",
"cycle",
"interval",
"is",
"only",
"16M",
"values",
"."
] | Datum
uuid_sequence_nextval(PG_FUNCTION_ARGS)
{
int i;
int64 val;
Oid relid = PG_GETARG_OID(0);
int32 block_size = PG_GETARG_INT32(1);
int32 block_count = PG_GETARG_INT32(2);
int64 prefix_bytes;
pg_uuid_t *uuid;
unsigned char *p;
if (block_size < 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("block size must be a positive integer")));
if (block_count < 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("number of blocks must be a positive integer")));
prefix_bytes = 0;
while (block_count > 1)
{
block_count /= 256;
prefix_bytes++;
}
val = nextval_internal(relid, true);
val /= block_size;
p = (unsigned char *) &val;
uuid = palloc(sizeof(pg_uuid_t));
for (i = 0; i < prefix_bytes; i++)
uuid->data[i] = p[prefix_bytes - 1 - i];
if(!pg_strong_random(uuid->data + prefix_bytes, UUID_LEN - prefix_bytes))
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("could not generate random values")));
uuid->data[6] = (uuid->data[6] & 0x0f) | 0x40;
uuid->data[8] = (uuid->data[8] & 0x3f) | 0x80;
PG_RETURN_UUID_P(uuid);
} | [
"Datum",
"uuid_sequence_nextval",
"(",
"PG_FUNCTION_ARGS",
")",
"{",
"int",
"i",
";",
"int64",
"val",
";",
"Oid",
"relid",
"=",
"PG_GETARG_OID",
"(",
"0",
")",
";",
"int32",
"block_size",
"=",
"PG_GETARG_INT32",
"(",
"1",
")",
";",
"int32",
"block_count",
"=",
"PG_GETARG_INT32",
"(",
"2",
")",
";",
"int64",
"prefix_bytes",
";",
"pg_uuid_t",
"*",
"uuid",
";",
"unsigned",
"char",
"*",
"p",
";",
"if",
"(",
"block_size",
"<",
"0",
")",
"ereport",
"(",
"ERROR",
",",
"(",
"errcode",
"(",
"ERRCODE_INVALID_PARAMETER_VALUE",
")",
",",
"errmsg",
"(",
"\"",
"\"",
")",
")",
")",
";",
"if",
"(",
"block_count",
"<",
"0",
")",
"ereport",
"(",
"ERROR",
",",
"(",
"errcode",
"(",
"ERRCODE_INVALID_PARAMETER_VALUE",
")",
",",
"errmsg",
"(",
"\"",
"\"",
")",
")",
")",
";",
"prefix_bytes",
"=",
"0",
";",
"while",
"(",
"block_count",
">",
"1",
")",
"{",
"block_count",
"/=",
"256",
";",
"prefix_bytes",
"++",
";",
"}",
"val",
"=",
"nextval_internal",
"(",
"relid",
",",
"true",
")",
";",
"val",
"/=",
"block_size",
";",
"p",
"=",
"(",
"unsigned",
"char",
"*",
")",
"&",
"val",
";",
"uuid",
"=",
"palloc",
"(",
"sizeof",
"(",
"pg_uuid_t",
")",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"prefix_bytes",
";",
"i",
"++",
")",
"uuid",
"->",
"data",
"[",
"i",
"]",
"=",
"p",
"[",
"prefix_bytes",
"-",
"1",
"-",
"i",
"]",
";",
"if",
"(",
"!",
"pg_strong_random",
"(",
"uuid",
"->",
"data",
"+",
"prefix_bytes",
",",
"UUID_LEN",
"-",
"prefix_bytes",
")",
")",
"ereport",
"(",
"ERROR",
",",
"(",
"errcode",
"(",
"ERRCODE_INTERNAL_ERROR",
")",
",",
"errmsg",
"(",
"\"",
"\"",
")",
")",
")",
";",
"uuid",
"->",
"data",
"[",
"6",
"]",
"=",
"(",
"uuid",
"->",
"data",
"[",
"6",
"]",
"&",
"0x0f",
")",
"|",
"0x40",
";",
"uuid",
"->",
"data",
"[",
"8",
"]",
"=",
"(",
"uuid",
"->",
"data",
"[",
"8",
"]",
"&",
"0x3f",
")",
"|",
"0x80",
";",
"PG_RETURN_UUID_P",
"(",
"uuid",
")",
";",
"}"
] | uuid_sequence_nextval
generate sequential UUID using a sequence | [
"uuid_sequence_nextval",
"generate",
"sequential",
"UUID",
"using",
"a",
"sequence"
] | [
"/* some basic sanity checks */",
"/* count the number of bytes to keep from the sequence value */",
"/*\n\t * Read the next value from the sequence and get rid of the least\n\t * significant bytes.\n\t */",
"/* copy the desired number of (least significant) bytes as prefix */",
"/* generate the remaining bytes as random (use strong generator) */",
"/*\n\t * Set the UUID version flags according to \"version 4\" (pseudorandom)\n\t * UUID, see http://tools.ietf.org/html/rfc4122#section-4.4\n\t *\n\t * This does reduce the randomness a bit, because it determines the\n\t * value of certain bits, but that should be negligible (certainly\n\t * compared to the reduction due to prefix).\n\t * \n\t * UUID v4 is probably the safest choice here. There is v1 which is\n\t * time-based, but it includes MAC address (which we don't use) and\n\t * works with very special timestamp (starting at 1582 etc.). So we\n\t * just use v4 and claim this is pseudorandom.\n\t */",
"/* time_hi_and_version */",
"/* clock_seq_hi_and_reserved */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
c151d7ac56267bbaf2d46810d252885a9602ba62 | danielsen/sequential-uuids | sequential_uuids.c | [
"MIT"
] | C | uuid_time_nextval | Datum | Datum
uuid_time_nextval(PG_FUNCTION_ARGS)
{
int i;
struct timeval tv;
int64 val;
pg_uuid_t *uuid;
int32 interval_length = PG_GETARG_INT32(0);
int32 interval_count = PG_GETARG_INT32(1);
int64 prefix_bytes;
unsigned char *p;
/* some basic sanity checks */
if (interval_length < 1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("length of interval must be a positive integer")));
if (interval_count < 1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("number of intervals must be a positive integer")));
if (gettimeofday(&tv, NULL) != 0)
elog(ERROR, "gettimeofday call failed");
val = (tv.tv_sec / interval_length);
/* count the number of bytes to keep from the timestamp */
prefix_bytes = 0;
while (interval_count > 1)
{
interval_count /= 256;
prefix_bytes++;
}
p = (unsigned char *) &val;
uuid = palloc(sizeof(pg_uuid_t));
/* copy the desired number of (least significant) bytes as prefix */
for (i = 0; i < prefix_bytes; i++)
uuid->data[i] = p[prefix_bytes - 1 - i];
/* generate the remaining bytes as random (use strong generator) */
if(!pg_strong_random(uuid->data + prefix_bytes, UUID_LEN - prefix_bytes))
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("could not generate random values")));
/*
* Set the UUID version flags according to "version 4" (pseudorandom)
* UUID, see http://tools.ietf.org/html/rfc4122#section-4.4
*
* This does reduce the randomness a bit, because it determines the
* value of certain bits, but that should be negligible (certainly
* compared to the reduction due to prefix).
*
* UUID v4 is probably the safest choice here. There is v1 which is
* time-based, but it includes MAC address (which we don't use) and
* works with very special timestamp (starting at 1582 etc.). So we
* just use v4 and claim this is pseudorandom.
*/
uuid->data[6] = (uuid->data[6] & 0x0f) | 0x40; /* time_hi_and_version */
uuid->data[8] = (uuid->data[8] & 0x3f) | 0x80; /* clock_seq_hi_and_reserved */
PG_RETURN_UUID_P(uuid);
} | /*
* uuid_time_nextval
* generate sequential UUID using current time
*
* The timestamp-based sequential UUID generator define the group size
* and group count based on data extracted from current timestamp.
*
* The interval_length (60 seconds by default) is defined as number of
* seconds where UUIDs share the same prefix). The prefix length is
* determined by the number of intervals (65536 by default, i.e. 2B).
* With these parameters the generator wraps around every ~45 days.
*/ | uuid_time_nextval
generate sequential UUID using current time
The timestamp-based sequential UUID generator define the group size
and group count based on data extracted from current timestamp.
The interval_length (60 seconds by default) is defined as number of
seconds where UUIDs share the same prefix). The prefix length is
determined by the number of intervals (65536 by default, i.e. 2B).
With these parameters the generator wraps around every ~45 days. | [
"uuid_time_nextval",
"generate",
"sequential",
"UUID",
"using",
"current",
"time",
"The",
"timestamp",
"-",
"based",
"sequential",
"UUID",
"generator",
"define",
"the",
"group",
"size",
"and",
"group",
"count",
"based",
"on",
"data",
"extracted",
"from",
"current",
"timestamp",
".",
"The",
"interval_length",
"(",
"60",
"seconds",
"by",
"default",
")",
"is",
"defined",
"as",
"number",
"of",
"seconds",
"where",
"UUIDs",
"share",
"the",
"same",
"prefix",
")",
".",
"The",
"prefix",
"length",
"is",
"determined",
"by",
"the",
"number",
"of",
"intervals",
"(",
"65536",
"by",
"default",
"i",
".",
"e",
".",
"2B",
")",
".",
"With",
"these",
"parameters",
"the",
"generator",
"wraps",
"around",
"every",
"~45",
"days",
"."
] | Datum
uuid_time_nextval(PG_FUNCTION_ARGS)
{
int i;
struct timeval tv;
int64 val;
pg_uuid_t *uuid;
int32 interval_length = PG_GETARG_INT32(0);
int32 interval_count = PG_GETARG_INT32(1);
int64 prefix_bytes;
unsigned char *p;
if (interval_length < 1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("length of interval must be a positive integer")));
if (interval_count < 1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("number of intervals must be a positive integer")));
if (gettimeofday(&tv, NULL) != 0)
elog(ERROR, "gettimeofday call failed");
val = (tv.tv_sec / interval_length);
prefix_bytes = 0;
while (interval_count > 1)
{
interval_count /= 256;
prefix_bytes++;
}
p = (unsigned char *) &val;
uuid = palloc(sizeof(pg_uuid_t));
for (i = 0; i < prefix_bytes; i++)
uuid->data[i] = p[prefix_bytes - 1 - i];
if(!pg_strong_random(uuid->data + prefix_bytes, UUID_LEN - prefix_bytes))
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("could not generate random values")));
uuid->data[6] = (uuid->data[6] & 0x0f) | 0x40;
uuid->data[8] = (uuid->data[8] & 0x3f) | 0x80;
PG_RETURN_UUID_P(uuid);
} | [
"Datum",
"uuid_time_nextval",
"(",
"PG_FUNCTION_ARGS",
")",
"{",
"int",
"i",
";",
"struct",
"timeval",
"tv",
";",
"int64",
"val",
";",
"pg_uuid_t",
"*",
"uuid",
";",
"int32",
"interval_length",
"=",
"PG_GETARG_INT32",
"(",
"0",
")",
";",
"int32",
"interval_count",
"=",
"PG_GETARG_INT32",
"(",
"1",
")",
";",
"int64",
"prefix_bytes",
";",
"unsigned",
"char",
"*",
"p",
";",
"if",
"(",
"interval_length",
"<",
"1",
")",
"ereport",
"(",
"ERROR",
",",
"(",
"errcode",
"(",
"ERRCODE_INVALID_PARAMETER_VALUE",
")",
",",
"errmsg",
"(",
"\"",
"\"",
")",
")",
")",
";",
"if",
"(",
"interval_count",
"<",
"1",
")",
"ereport",
"(",
"ERROR",
",",
"(",
"errcode",
"(",
"ERRCODE_INVALID_PARAMETER_VALUE",
")",
",",
"errmsg",
"(",
"\"",
"\"",
")",
")",
")",
";",
"if",
"(",
"gettimeofday",
"(",
"&",
"tv",
",",
"NULL",
")",
"!=",
"0",
")",
"elog",
"(",
"ERROR",
",",
"\"",
"\"",
")",
";",
"val",
"=",
"(",
"tv",
".",
"tv_sec",
"/",
"interval_length",
")",
";",
"prefix_bytes",
"=",
"0",
";",
"while",
"(",
"interval_count",
">",
"1",
")",
"{",
"interval_count",
"/=",
"256",
";",
"prefix_bytes",
"++",
";",
"}",
"p",
"=",
"(",
"unsigned",
"char",
"*",
")",
"&",
"val",
";",
"uuid",
"=",
"palloc",
"(",
"sizeof",
"(",
"pg_uuid_t",
")",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"prefix_bytes",
";",
"i",
"++",
")",
"uuid",
"->",
"data",
"[",
"i",
"]",
"=",
"p",
"[",
"prefix_bytes",
"-",
"1",
"-",
"i",
"]",
";",
"if",
"(",
"!",
"pg_strong_random",
"(",
"uuid",
"->",
"data",
"+",
"prefix_bytes",
",",
"UUID_LEN",
"-",
"prefix_bytes",
")",
")",
"ereport",
"(",
"ERROR",
",",
"(",
"errcode",
"(",
"ERRCODE_INTERNAL_ERROR",
")",
",",
"errmsg",
"(",
"\"",
"\"",
")",
")",
")",
";",
"uuid",
"->",
"data",
"[",
"6",
"]",
"=",
"(",
"uuid",
"->",
"data",
"[",
"6",
"]",
"&",
"0x0f",
")",
"|",
"0x40",
";",
"uuid",
"->",
"data",
"[",
"8",
"]",
"=",
"(",
"uuid",
"->",
"data",
"[",
"8",
"]",
"&",
"0x3f",
")",
"|",
"0x80",
";",
"PG_RETURN_UUID_P",
"(",
"uuid",
")",
";",
"}"
] | uuid_time_nextval
generate sequential UUID using current time | [
"uuid_time_nextval",
"generate",
"sequential",
"UUID",
"using",
"current",
"time"
] | [
"/* some basic sanity checks */",
"/* count the number of bytes to keep from the timestamp */",
"/* copy the desired number of (least significant) bytes as prefix */",
"/* generate the remaining bytes as random (use strong generator) */",
"/*\n\t * Set the UUID version flags according to \"version 4\" (pseudorandom)\n\t * UUID, see http://tools.ietf.org/html/rfc4122#section-4.4\n\t *\n\t * This does reduce the randomness a bit, because it determines the\n\t * value of certain bits, but that should be negligible (certainly\n\t * compared to the reduction due to prefix).\n\t * \n\t * UUID v4 is probably the safest choice here. There is v1 which is\n\t * time-based, but it includes MAC address (which we don't use) and\n\t * works with very special timestamp (starting at 1582 etc.). So we\n\t * just use v4 and claim this is pseudorandom.\n\t */",
"/* time_hi_and_version */",
"/* clock_seq_hi_and_reserved */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
a7f9d78cfa9d9f8145e3725ddcd3910093efeadb | lkundrak/dhcp | relay/dhcrelay.c | [
"ISC"
] | C | strip_relay_agent_options | int | static int
strip_relay_agent_options(struct interface_info *in,
struct interface_info **out,
struct dhcp_packet *packet,
unsigned length) {
int is_dhcp = 0;
u_int8_t *op, *nextop, *sp, *max;
int good_agent_option = 0;
int status;
/* If we're not adding agent options to packets, we're not taking
them out either. */
if (!add_agent_options)
return (length);
/* If there's no cookie, it's a bootp packet, so we should just
forward it unchanged. */
if (memcmp(packet->options, DHCP_OPTIONS_COOKIE, 4))
return (length);
max = ((u_int8_t *)packet) + length;
sp = op = &packet->options[4];
while (op < max) {
switch(*op) {
/* Skip padding... */
case DHO_PAD:
if (sp != op)
*sp = *op;
++op;
++sp;
continue;
/* If we see a message type, it's a DHCP packet. */
case DHO_DHCP_MESSAGE_TYPE:
is_dhcp = 1;
goto skip;
break;
/* Quit immediately if we hit an End option. */
case DHO_END:
if (sp != op)
*sp++ = *op++;
goto out;
case DHO_DHCP_AGENT_OPTIONS:
/* We shouldn't see a relay agent option in a
packet before we've seen the DHCP packet type,
but if we do, we have to leave it alone. */
if (!is_dhcp)
goto skip;
/* Do not process an agent option if it exceeds the
* buffer. Fail this packet.
*/
nextop = op + op[1] + 2;
if (nextop > max)
return (0);
status = find_interface_by_agent_option(packet,
out, op + 2,
op[1]);
if (status == -1 && drop_agent_mismatches)
return (0);
if (status)
good_agent_option = 1;
op = nextop;
break;
skip:
/* Skip over other options. */
default:
/* Fail if processing this option will exceed the
* buffer(op[1] is malformed).
*/
nextop = op + op[1] + 2;
if (nextop > max)
return (0);
if (sp != op) {
memmove(sp, op, op[1] + 2);
sp += op[1] + 2;
op = nextop;
} else
op = sp = nextop;
break;
}
}
out:
/* If it's not a DHCP packet, we're not supposed to touch it. */
if (!is_dhcp)
return (length);
/* If none of the agent options we found matched, or if we didn't
find any agent options, count this packet as not having any
matching agent options, and if we're relying on agent options
to determine the outgoing interface, drop the packet. */
if (!good_agent_option) {
++missing_agent_option;
if (drop_agent_mismatches)
return (0);
}
/* Adjust the length... */
if (sp != op) {
length = sp -((u_int8_t *)packet);
/* Make sure the packet isn't short(this is unlikely,
but WTH) */
if (length < BOOTP_MIN_LEN) {
memset(sp, DHO_PAD, BOOTP_MIN_LEN - length);
length = BOOTP_MIN_LEN;
}
}
return (length);
} | /* Strip any Relay Agent Information options from the DHCP packet
option buffer. If there is a circuit ID suboption, look up the
outgoing interface based upon it. */ | Strip any Relay Agent Information options from the DHCP packet
option buffer. If there is a circuit ID suboption, look up the
outgoing interface based upon it. | [
"Strip",
"any",
"Relay",
"Agent",
"Information",
"options",
"from",
"the",
"DHCP",
"packet",
"option",
"buffer",
".",
"If",
"there",
"is",
"a",
"circuit",
"ID",
"suboption",
"look",
"up",
"the",
"outgoing",
"interface",
"based",
"upon",
"it",
"."
] | static int
strip_relay_agent_options(struct interface_info *in,
struct interface_info **out,
struct dhcp_packet *packet,
unsigned length) {
int is_dhcp = 0;
u_int8_t *op, *nextop, *sp, *max;
int good_agent_option = 0;
int status;
if (!add_agent_options)
return (length);
if (memcmp(packet->options, DHCP_OPTIONS_COOKIE, 4))
return (length);
max = ((u_int8_t *)packet) + length;
sp = op = &packet->options[4];
while (op < max) {
switch(*op) {
case DHO_PAD:
if (sp != op)
*sp = *op;
++op;
++sp;
continue;
case DHO_DHCP_MESSAGE_TYPE:
is_dhcp = 1;
goto skip;
break;
case DHO_END:
if (sp != op)
*sp++ = *op++;
goto out;
case DHO_DHCP_AGENT_OPTIONS:
if (!is_dhcp)
goto skip;
nextop = op + op[1] + 2;
if (nextop > max)
return (0);
status = find_interface_by_agent_option(packet,
out, op + 2,
op[1]);
if (status == -1 && drop_agent_mismatches)
return (0);
if (status)
good_agent_option = 1;
op = nextop;
break;
skip:
default:
nextop = op + op[1] + 2;
if (nextop > max)
return (0);
if (sp != op) {
memmove(sp, op, op[1] + 2);
sp += op[1] + 2;
op = nextop;
} else
op = sp = nextop;
break;
}
}
out:
if (!is_dhcp)
return (length);
if (!good_agent_option) {
++missing_agent_option;
if (drop_agent_mismatches)
return (0);
}
if (sp != op) {
length = sp -((u_int8_t *)packet);
if (length < BOOTP_MIN_LEN) {
memset(sp, DHO_PAD, BOOTP_MIN_LEN - length);
length = BOOTP_MIN_LEN;
}
}
return (length);
} | [
"static",
"int",
"strip_relay_agent_options",
"(",
"struct",
"interface_info",
"*",
"in",
",",
"struct",
"interface_info",
"*",
"*",
"out",
",",
"struct",
"dhcp_packet",
"*",
"packet",
",",
"unsigned",
"length",
")",
"{",
"int",
"is_dhcp",
"=",
"0",
";",
"u_int8_t",
"*",
"op",
",",
"*",
"nextop",
",",
"*",
"sp",
",",
"*",
"max",
";",
"int",
"good_agent_option",
"=",
"0",
";",
"int",
"status",
";",
"if",
"(",
"!",
"add_agent_options",
")",
"return",
"(",
"length",
")",
";",
"if",
"(",
"memcmp",
"(",
"packet",
"->",
"options",
",",
"DHCP_OPTIONS_COOKIE",
",",
"4",
")",
")",
"return",
"(",
"length",
")",
";",
"max",
"=",
"(",
"(",
"u_int8_t",
"*",
")",
"packet",
")",
"+",
"length",
";",
"sp",
"=",
"op",
"=",
"&",
"packet",
"->",
"options",
"[",
"4",
"]",
";",
"while",
"(",
"op",
"<",
"max",
")",
"{",
"switch",
"(",
"*",
"op",
")",
"{",
"case",
"DHO_PAD",
":",
"if",
"(",
"sp",
"!=",
"op",
")",
"*",
"sp",
"=",
"*",
"op",
";",
"++",
"op",
";",
"++",
"sp",
";",
"continue",
";",
"case",
"DHO_DHCP_MESSAGE_TYPE",
":",
"is_dhcp",
"=",
"1",
";",
"goto",
"skip",
";",
"break",
";",
"case",
"DHO_END",
":",
"if",
"(",
"sp",
"!=",
"op",
")",
"*",
"sp",
"++",
"=",
"*",
"op",
"++",
";",
"goto",
"out",
";",
"case",
"DHO_DHCP_AGENT_OPTIONS",
":",
"if",
"(",
"!",
"is_dhcp",
")",
"goto",
"skip",
";",
"nextop",
"=",
"op",
"+",
"op",
"[",
"1",
"]",
"+",
"2",
";",
"if",
"(",
"nextop",
">",
"max",
")",
"return",
"(",
"0",
")",
";",
"status",
"=",
"find_interface_by_agent_option",
"(",
"packet",
",",
"out",
",",
"op",
"+",
"2",
",",
"op",
"[",
"1",
"]",
")",
";",
"if",
"(",
"status",
"==",
"-1",
"&&",
"drop_agent_mismatches",
")",
"return",
"(",
"0",
")",
";",
"if",
"(",
"status",
")",
"good_agent_option",
"=",
"1",
";",
"op",
"=",
"nextop",
";",
"break",
";",
"skip",
":",
"default",
":",
"nextop",
"=",
"op",
"+",
"op",
"[",
"1",
"]",
"+",
"2",
";",
"if",
"(",
"nextop",
">",
"max",
")",
"return",
"(",
"0",
")",
";",
"if",
"(",
"sp",
"!=",
"op",
")",
"{",
"memmove",
"(",
"sp",
",",
"op",
",",
"op",
"[",
"1",
"]",
"+",
"2",
")",
";",
"sp",
"+=",
"op",
"[",
"1",
"]",
"+",
"2",
";",
"op",
"=",
"nextop",
";",
"}",
"else",
"op",
"=",
"sp",
"=",
"nextop",
";",
"break",
";",
"}",
"}",
"out",
":",
"if",
"(",
"!",
"is_dhcp",
")",
"return",
"(",
"length",
")",
";",
"if",
"(",
"!",
"good_agent_option",
")",
"{",
"++",
"missing_agent_option",
";",
"if",
"(",
"drop_agent_mismatches",
")",
"return",
"(",
"0",
")",
";",
"}",
"if",
"(",
"sp",
"!=",
"op",
")",
"{",
"length",
"=",
"sp",
"-",
"(",
"(",
"u_int8_t",
"*",
")",
"packet",
")",
";",
"if",
"(",
"length",
"<",
"BOOTP_MIN_LEN",
")",
"{",
"memset",
"(",
"sp",
",",
"DHO_PAD",
",",
"BOOTP_MIN_LEN",
"-",
"length",
")",
";",
"length",
"=",
"BOOTP_MIN_LEN",
";",
"}",
"}",
"return",
"(",
"length",
")",
";",
"}"
] | Strip any Relay Agent Information options from the DHCP packet
option buffer. | [
"Strip",
"any",
"Relay",
"Agent",
"Information",
"options",
"from",
"the",
"DHCP",
"packet",
"option",
"buffer",
"."
] | [
"/* If we're not adding agent options to packets, we're not taking\n\t them out either. */",
"/* If there's no cookie, it's a bootp packet, so we should just\n\t forward it unchanged. */",
"/* Skip padding... */",
"/* If we see a message type, it's a DHCP packet. */",
"/* Quit immediately if we hit an End option. */",
"/* We shouldn't see a relay agent option in a\n\t\t\t packet before we've seen the DHCP packet type,\n\t\t\t but if we do, we have to leave it alone. */",
"/* Do not process an agent option if it exceeds the\n\t\t\t * buffer. Fail this packet.\n\t\t\t */",
"/* Skip over other options. */",
"/* Fail if processing this option will exceed the\n\t\t\t * buffer(op[1] is malformed).\n\t\t\t */",
"/* If it's not a DHCP packet, we're not supposed to touch it. */",
"/* If none of the agent options we found matched, or if we didn't\n\t find any agent options, count this packet as not having any\n\t matching agent options, and if we're relying on agent options\n\t to determine the outgoing interface, drop the packet. */",
"/* Adjust the length... */",
"/* Make sure the packet isn't short(this is unlikely,\n\t\t but WTH) */"
] | [
{
"param": "in",
"type": "struct interface_info"
},
{
"param": "out",
"type": "struct interface_info"
},
{
"param": "packet",
"type": "struct dhcp_packet"
},
{
"param": "length",
"type": "unsigned"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "in",
"type": "struct interface_info",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "out",
"type": "struct interface_info",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "packet",
"type": "struct dhcp_packet",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "length",
"type": "unsigned",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a7f9d78cfa9d9f8145e3725ddcd3910093efeadb | lkundrak/dhcp | relay/dhcrelay.c | [
"ISC"
] | C | find_interface_by_agent_option | int | static int
find_interface_by_agent_option(struct dhcp_packet *packet,
struct interface_info **out,
u_int8_t *buf, int len) {
int i = 0;
u_int8_t *circuit_id = 0;
unsigned circuit_id_len = 0;
struct interface_info *ip;
while (i < len) {
/* If the next agent option overflows the end of the
packet, the agent option buffer is corrupt. */
if (i + 1 == len ||
i + buf[i + 1] + 2 > len) {
++corrupt_agent_options;
return (-1);
}
switch(buf[i]) {
/* Remember where the circuit ID is... */
case RAI_CIRCUIT_ID:
circuit_id = &buf[i + 2];
circuit_id_len = buf[i + 1];
i += circuit_id_len + 2;
continue;
default:
i += buf[i + 1] + 2;
break;
}
}
/* If there's no circuit ID, it's not really ours, tell the caller
it's no good. */
if (!circuit_id) {
++missing_circuit_id;
return (-1);
}
/* Scan the interface list looking for an interface whose
name matches the one specified in circuit_id. */
for (ip = interfaces; ip; ip = ip->next) {
if (ip->circuit_id &&
ip->circuit_id_len == circuit_id_len &&
!memcmp(ip->circuit_id, circuit_id, circuit_id_len))
break;
}
/* If we got a match, use it. */
if (ip) {
*out = ip;
return (1);
}
/* If we didn't get a match, the circuit ID was bogus. */
++bad_circuit_id;
return (-1);
} | /* Find an interface that matches the circuit ID specified in the
Relay Agent Information option. If one is found, store it through
the pointer given; otherwise, leave the existing pointer alone.
We actually deviate somewhat from the current specification here:
if the option buffer is corrupt, we suggest that the caller not
respond to this packet. If the circuit ID doesn't match any known
interface, we suggest that the caller to drop the packet. Only if
we find a circuit ID that matches an existing interface do we tell
the caller to go ahead and process the packet. */ | Find an interface that matches the circuit ID specified in the
Relay Agent Information option. If one is found, store it through
the pointer given; otherwise, leave the existing pointer alone.
We actually deviate somewhat from the current specification here:
if the option buffer is corrupt, we suggest that the caller not
respond to this packet. If the circuit ID doesn't match any known
interface, we suggest that the caller to drop the packet. Only if
we find a circuit ID that matches an existing interface do we tell
the caller to go ahead and process the packet. | [
"Find",
"an",
"interface",
"that",
"matches",
"the",
"circuit",
"ID",
"specified",
"in",
"the",
"Relay",
"Agent",
"Information",
"option",
".",
"If",
"one",
"is",
"found",
"store",
"it",
"through",
"the",
"pointer",
"given",
";",
"otherwise",
"leave",
"the",
"existing",
"pointer",
"alone",
".",
"We",
"actually",
"deviate",
"somewhat",
"from",
"the",
"current",
"specification",
"here",
":",
"if",
"the",
"option",
"buffer",
"is",
"corrupt",
"we",
"suggest",
"that",
"the",
"caller",
"not",
"respond",
"to",
"this",
"packet",
".",
"If",
"the",
"circuit",
"ID",
"doesn",
"'",
"t",
"match",
"any",
"known",
"interface",
"we",
"suggest",
"that",
"the",
"caller",
"to",
"drop",
"the",
"packet",
".",
"Only",
"if",
"we",
"find",
"a",
"circuit",
"ID",
"that",
"matches",
"an",
"existing",
"interface",
"do",
"we",
"tell",
"the",
"caller",
"to",
"go",
"ahead",
"and",
"process",
"the",
"packet",
"."
] | static int
find_interface_by_agent_option(struct dhcp_packet *packet,
struct interface_info **out,
u_int8_t *buf, int len) {
int i = 0;
u_int8_t *circuit_id = 0;
unsigned circuit_id_len = 0;
struct interface_info *ip;
while (i < len) {
if (i + 1 == len ||
i + buf[i + 1] + 2 > len) {
++corrupt_agent_options;
return (-1);
}
switch(buf[i]) {
case RAI_CIRCUIT_ID:
circuit_id = &buf[i + 2];
circuit_id_len = buf[i + 1];
i += circuit_id_len + 2;
continue;
default:
i += buf[i + 1] + 2;
break;
}
}
if (!circuit_id) {
++missing_circuit_id;
return (-1);
}
for (ip = interfaces; ip; ip = ip->next) {
if (ip->circuit_id &&
ip->circuit_id_len == circuit_id_len &&
!memcmp(ip->circuit_id, circuit_id, circuit_id_len))
break;
}
if (ip) {
*out = ip;
return (1);
}
++bad_circuit_id;
return (-1);
} | [
"static",
"int",
"find_interface_by_agent_option",
"(",
"struct",
"dhcp_packet",
"*",
"packet",
",",
"struct",
"interface_info",
"*",
"*",
"out",
",",
"u_int8_t",
"*",
"buf",
",",
"int",
"len",
")",
"{",
"int",
"i",
"=",
"0",
";",
"u_int8_t",
"*",
"circuit_id",
"=",
"0",
";",
"unsigned",
"circuit_id_len",
"=",
"0",
";",
"struct",
"interface_info",
"*",
"ip",
";",
"while",
"(",
"i",
"<",
"len",
")",
"{",
"if",
"(",
"i",
"+",
"1",
"==",
"len",
"||",
"i",
"+",
"buf",
"[",
"i",
"+",
"1",
"]",
"+",
"2",
">",
"len",
")",
"{",
"++",
"corrupt_agent_options",
";",
"return",
"(",
"-1",
")",
";",
"}",
"switch",
"(",
"buf",
"[",
"i",
"]",
")",
"{",
"case",
"RAI_CIRCUIT_ID",
":",
"circuit_id",
"=",
"&",
"buf",
"[",
"i",
"+",
"2",
"]",
";",
"circuit_id_len",
"=",
"buf",
"[",
"i",
"+",
"1",
"]",
";",
"i",
"+=",
"circuit_id_len",
"+",
"2",
";",
"continue",
";",
"default",
":",
"i",
"+=",
"buf",
"[",
"i",
"+",
"1",
"]",
"+",
"2",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"circuit_id",
")",
"{",
"++",
"missing_circuit_id",
";",
"return",
"(",
"-1",
")",
";",
"}",
"for",
"(",
"ip",
"=",
"interfaces",
";",
"ip",
";",
"ip",
"=",
"ip",
"->",
"next",
")",
"{",
"if",
"(",
"ip",
"->",
"circuit_id",
"&&",
"ip",
"->",
"circuit_id_len",
"==",
"circuit_id_len",
"&&",
"!",
"memcmp",
"(",
"ip",
"->",
"circuit_id",
",",
"circuit_id",
",",
"circuit_id_len",
")",
")",
"break",
";",
"}",
"if",
"(",
"ip",
")",
"{",
"*",
"out",
"=",
"ip",
";",
"return",
"(",
"1",
")",
";",
"}",
"++",
"bad_circuit_id",
";",
"return",
"(",
"-1",
")",
";",
"}"
] | Find an interface that matches the circuit ID specified in the
Relay Agent Information option. | [
"Find",
"an",
"interface",
"that",
"matches",
"the",
"circuit",
"ID",
"specified",
"in",
"the",
"Relay",
"Agent",
"Information",
"option",
"."
] | [
"/* If the next agent option overflows the end of the\n\t\t packet, the agent option buffer is corrupt. */",
"/* Remember where the circuit ID is... */",
"/* If there's no circuit ID, it's not really ours, tell the caller\n\t it's no good. */",
"/* Scan the interface list looking for an interface whose\n\t name matches the one specified in circuit_id. */",
"/* If we got a match, use it. */",
"/* If we didn't get a match, the circuit ID was bogus. */"
] | [
{
"param": "packet",
"type": "struct dhcp_packet"
},
{
"param": "out",
"type": "struct interface_info"
},
{
"param": "buf",
"type": "u_int8_t"
},
{
"param": "len",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "packet",
"type": "struct dhcp_packet",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "out",
"type": "struct interface_info",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "buf",
"type": "u_int8_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "len",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a7f9d78cfa9d9f8145e3725ddcd3910093efeadb | lkundrak/dhcp | relay/dhcrelay.c | [
"ISC"
] | C | add_relay_agent_options | int | static int
add_relay_agent_options(struct interface_info *ip, struct dhcp_packet *packet,
unsigned length, struct in_addr giaddr) {
int is_dhcp = 0, mms;
unsigned optlen;
u_int8_t *op, *nextop, *sp, *max, *end_pad = NULL;
/* If we're not adding agent options to packets, we can skip
this. */
if (!add_agent_options)
return (length);
/* If there's no cookie, it's a bootp packet, so we should just
forward it unchanged. */
if (memcmp(packet->options, DHCP_OPTIONS_COOKIE, 4))
return (length);
max = ((u_int8_t *)packet) + dhcp_max_agent_option_packet_length;
/* Commence processing after the cookie. */
sp = op = &packet->options[4];
while (op < max) {
switch(*op) {
/* Skip padding... */
case DHO_PAD:
/* Remember the first pad byte so we can commandeer
* padded space.
*
* XXX: Is this really a good idea? Sure, we can
* seemingly reduce the packet while we're looking,
* but if the packet was signed by the client then
* this padding is part of the checksum(RFC3118),
* and its nonpresence would break authentication.
*/
if (end_pad == NULL)
end_pad = sp;
if (sp != op)
*sp++ = *op++;
else
sp = ++op;
continue;
/* If we see a message type, it's a DHCP packet. */
case DHO_DHCP_MESSAGE_TYPE:
is_dhcp = 1;
goto skip;
/*
* If there's a maximum message size option, we
* should pay attention to it
*/
case DHO_DHCP_MAX_MESSAGE_SIZE:
mms = ntohs(*(op + 2));
if (mms < dhcp_max_agent_option_packet_length &&
mms >= DHCP_MTU_MIN)
max = ((u_int8_t *)packet) + mms;
goto skip;
/* Quit immediately if we hit an End option. */
case DHO_END:
goto out;
case DHO_DHCP_AGENT_OPTIONS:
/* We shouldn't see a relay agent option in a
packet before we've seen the DHCP packet type,
but if we do, we have to leave it alone. */
if (!is_dhcp)
goto skip;
end_pad = NULL;
/* There's already a Relay Agent Information option
in this packet. How embarrassing. Decide what
to do based on the mode the user specified. */
switch(agent_relay_mode) {
case forward_and_append:
goto skip;
case forward_untouched:
return (length);
case discard:
return (0);
case forward_and_replace:
default:
break;
}
/* Skip over the agent option and start copying
if we aren't copying already. */
op += op[1] + 2;
break;
skip:
/* Skip over other options. */
default:
/* Fail if processing this option will exceed the
* buffer(op[1] is malformed).
*/
nextop = op + op[1] + 2;
if (nextop > max)
return (0);
end_pad = NULL;
if (sp != op) {
memmove(sp, op, op[1] + 2);
sp += op[1] + 2;
op = nextop;
} else
op = sp = nextop;
break;
}
}
out:
/* If it's not a DHCP packet, we're not supposed to touch it. */
if (!is_dhcp)
return (length);
/* If the packet was padded out, we can store the agent option
at the beginning of the padding. */
if (end_pad != NULL)
sp = end_pad;
/* Remember where the end of the packet was after parsing
it. */
op = sp;
/* Sanity check. Had better not ever happen. */
if ((ip->circuit_id_len > 255) ||(ip->circuit_id_len < 1))
log_fatal("Circuit ID length %d out of range [1-255] on "
"%s\n", ip->circuit_id_len, ip->name);
optlen = ip->circuit_id_len + 2; /* RAI_CIRCUIT_ID + len */
if (ip->remote_id) {
if (ip->remote_id_len > 255 || ip->remote_id_len < 1)
log_fatal("Remote ID length %d out of range [1-255] "
"on %s\n", ip->circuit_id_len, ip->name);
optlen += ip->remote_id_len + 2; /* RAI_REMOTE_ID + len */
}
/* We do not support relay option fragmenting(multiple options to
* support an option data exceeding 255 bytes).
*/
if ((optlen < 3) ||(optlen > 255))
log_fatal("Total agent option length(%u) out of range "
"[3 - 255] on %s\n", optlen, ip->name);
/*
* Is there room for the option, its code+len, and DHO_END?
* If not, forward without adding the option.
*/
if (max - sp >= optlen + 3) {
log_debug("Adding %d-byte relay agent option", optlen + 3);
/* Okay, cons up *our* Relay Agent Information option. */
*sp++ = DHO_DHCP_AGENT_OPTIONS;
*sp++ = optlen;
/* Copy in the circuit id... */
*sp++ = RAI_CIRCUIT_ID;
*sp++ = ip->circuit_id_len;
memcpy(sp, ip->circuit_id, ip->circuit_id_len);
sp += ip->circuit_id_len;
/* Copy in remote ID... */
if (ip->remote_id) {
*sp++ = RAI_REMOTE_ID;
*sp++ = ip->remote_id_len;
memcpy(sp, ip->remote_id, ip->remote_id_len);
sp += ip->remote_id_len;
}
} else {
++agent_option_errors;
log_error("No room in packet (used %d of %d) "
"for %d-byte relay agent option: omitted",
(int) (sp - ((u_int8_t *) packet)),
(int) (max - ((u_int8_t *) packet)),
optlen + 3);
}
/*
* Deposit an END option unless the packet is full (shouldn't
* be possible).
*/
if (sp < max)
*sp++ = DHO_END;
/* Recalculate total packet length. */
length = sp -((u_int8_t *)packet);
/* Make sure the packet isn't short(this is unlikely, but WTH) */
if (length < BOOTP_MIN_LEN) {
memset(sp, DHO_PAD, BOOTP_MIN_LEN - length);
return (BOOTP_MIN_LEN);
}
return (length);
} | /*
* Examine a packet to see if it's a candidate to have a Relay
* Agent Information option tacked onto its tail. If it is, tack
* the option on.
*/ | Examine a packet to see if it's a candidate to have a Relay
Agent Information option tacked onto its tail. If it is, tack
the option on. | [
"Examine",
"a",
"packet",
"to",
"see",
"if",
"it",
"'",
"s",
"a",
"candidate",
"to",
"have",
"a",
"Relay",
"Agent",
"Information",
"option",
"tacked",
"onto",
"its",
"tail",
".",
"If",
"it",
"is",
"tack",
"the",
"option",
"on",
"."
] | static int
add_relay_agent_options(struct interface_info *ip, struct dhcp_packet *packet,
unsigned length, struct in_addr giaddr) {
int is_dhcp = 0, mms;
unsigned optlen;
u_int8_t *op, *nextop, *sp, *max, *end_pad = NULL;
if (!add_agent_options)
return (length);
if (memcmp(packet->options, DHCP_OPTIONS_COOKIE, 4))
return (length);
max = ((u_int8_t *)packet) + dhcp_max_agent_option_packet_length;
sp = op = &packet->options[4];
while (op < max) {
switch(*op) {
case DHO_PAD:
if (end_pad == NULL)
end_pad = sp;
if (sp != op)
*sp++ = *op++;
else
sp = ++op;
continue;
case DHO_DHCP_MESSAGE_TYPE:
is_dhcp = 1;
goto skip;
case DHO_DHCP_MAX_MESSAGE_SIZE:
mms = ntohs(*(op + 2));
if (mms < dhcp_max_agent_option_packet_length &&
mms >= DHCP_MTU_MIN)
max = ((u_int8_t *)packet) + mms;
goto skip;
case DHO_END:
goto out;
case DHO_DHCP_AGENT_OPTIONS:
if (!is_dhcp)
goto skip;
end_pad = NULL;
switch(agent_relay_mode) {
case forward_and_append:
goto skip;
case forward_untouched:
return (length);
case discard:
return (0);
case forward_and_replace:
default:
break;
}
op += op[1] + 2;
break;
skip:
default:
nextop = op + op[1] + 2;
if (nextop > max)
return (0);
end_pad = NULL;
if (sp != op) {
memmove(sp, op, op[1] + 2);
sp += op[1] + 2;
op = nextop;
} else
op = sp = nextop;
break;
}
}
out:
if (!is_dhcp)
return (length);
if (end_pad != NULL)
sp = end_pad;
op = sp;
if ((ip->circuit_id_len > 255) ||(ip->circuit_id_len < 1))
log_fatal("Circuit ID length %d out of range [1-255] on "
"%s\n", ip->circuit_id_len, ip->name);
optlen = ip->circuit_id_len + 2;
if (ip->remote_id) {
if (ip->remote_id_len > 255 || ip->remote_id_len < 1)
log_fatal("Remote ID length %d out of range [1-255] "
"on %s\n", ip->circuit_id_len, ip->name);
optlen += ip->remote_id_len + 2;
}
if ((optlen < 3) ||(optlen > 255))
log_fatal("Total agent option length(%u) out of range "
"[3 - 255] on %s\n", optlen, ip->name);
if (max - sp >= optlen + 3) {
log_debug("Adding %d-byte relay agent option", optlen + 3);
*sp++ = DHO_DHCP_AGENT_OPTIONS;
*sp++ = optlen;
*sp++ = RAI_CIRCUIT_ID;
*sp++ = ip->circuit_id_len;
memcpy(sp, ip->circuit_id, ip->circuit_id_len);
sp += ip->circuit_id_len;
if (ip->remote_id) {
*sp++ = RAI_REMOTE_ID;
*sp++ = ip->remote_id_len;
memcpy(sp, ip->remote_id, ip->remote_id_len);
sp += ip->remote_id_len;
}
} else {
++agent_option_errors;
log_error("No room in packet (used %d of %d) "
"for %d-byte relay agent option: omitted",
(int) (sp - ((u_int8_t *) packet)),
(int) (max - ((u_int8_t *) packet)),
optlen + 3);
}
if (sp < max)
*sp++ = DHO_END;
length = sp -((u_int8_t *)packet);
if (length < BOOTP_MIN_LEN) {
memset(sp, DHO_PAD, BOOTP_MIN_LEN - length);
return (BOOTP_MIN_LEN);
}
return (length);
} | [
"static",
"int",
"add_relay_agent_options",
"(",
"struct",
"interface_info",
"*",
"ip",
",",
"struct",
"dhcp_packet",
"*",
"packet",
",",
"unsigned",
"length",
",",
"struct",
"in_addr",
"giaddr",
")",
"{",
"int",
"is_dhcp",
"=",
"0",
",",
"mms",
";",
"unsigned",
"optlen",
";",
"u_int8_t",
"*",
"op",
",",
"*",
"nextop",
",",
"*",
"sp",
",",
"*",
"max",
",",
"*",
"end_pad",
"=",
"NULL",
";",
"if",
"(",
"!",
"add_agent_options",
")",
"return",
"(",
"length",
")",
";",
"if",
"(",
"memcmp",
"(",
"packet",
"->",
"options",
",",
"DHCP_OPTIONS_COOKIE",
",",
"4",
")",
")",
"return",
"(",
"length",
")",
";",
"max",
"=",
"(",
"(",
"u_int8_t",
"*",
")",
"packet",
")",
"+",
"dhcp_max_agent_option_packet_length",
";",
"sp",
"=",
"op",
"=",
"&",
"packet",
"->",
"options",
"[",
"4",
"]",
";",
"while",
"(",
"op",
"<",
"max",
")",
"{",
"switch",
"(",
"*",
"op",
")",
"{",
"case",
"DHO_PAD",
":",
"if",
"(",
"end_pad",
"==",
"NULL",
")",
"end_pad",
"=",
"sp",
";",
"if",
"(",
"sp",
"!=",
"op",
")",
"*",
"sp",
"++",
"=",
"*",
"op",
"++",
";",
"else",
"sp",
"=",
"++",
"op",
";",
"continue",
";",
"case",
"DHO_DHCP_MESSAGE_TYPE",
":",
"is_dhcp",
"=",
"1",
";",
"goto",
"skip",
";",
"case",
"DHO_DHCP_MAX_MESSAGE_SIZE",
":",
"mms",
"=",
"ntohs",
"(",
"*",
"(",
"op",
"+",
"2",
")",
")",
";",
"if",
"(",
"mms",
"<",
"dhcp_max_agent_option_packet_length",
"&&",
"mms",
">=",
"DHCP_MTU_MIN",
")",
"max",
"=",
"(",
"(",
"u_int8_t",
"*",
")",
"packet",
")",
"+",
"mms",
";",
"goto",
"skip",
";",
"case",
"DHO_END",
":",
"goto",
"out",
";",
"case",
"DHO_DHCP_AGENT_OPTIONS",
":",
"if",
"(",
"!",
"is_dhcp",
")",
"goto",
"skip",
";",
"end_pad",
"=",
"NULL",
";",
"switch",
"(",
"agent_relay_mode",
")",
"{",
"case",
"forward_and_append",
":",
"goto",
"skip",
";",
"case",
"forward_untouched",
":",
"return",
"(",
"length",
")",
";",
"case",
"discard",
":",
"return",
"(",
"0",
")",
";",
"case",
"forward_and_replace",
":",
"default",
":",
"break",
";",
"}",
"op",
"+=",
"op",
"[",
"1",
"]",
"+",
"2",
";",
"break",
";",
"skip",
":",
"default",
":",
"nextop",
"=",
"op",
"+",
"op",
"[",
"1",
"]",
"+",
"2",
";",
"if",
"(",
"nextop",
">",
"max",
")",
"return",
"(",
"0",
")",
";",
"end_pad",
"=",
"NULL",
";",
"if",
"(",
"sp",
"!=",
"op",
")",
"{",
"memmove",
"(",
"sp",
",",
"op",
",",
"op",
"[",
"1",
"]",
"+",
"2",
")",
";",
"sp",
"+=",
"op",
"[",
"1",
"]",
"+",
"2",
";",
"op",
"=",
"nextop",
";",
"}",
"else",
"op",
"=",
"sp",
"=",
"nextop",
";",
"break",
";",
"}",
"}",
"out",
":",
"if",
"(",
"!",
"is_dhcp",
")",
"return",
"(",
"length",
")",
";",
"if",
"(",
"end_pad",
"!=",
"NULL",
")",
"sp",
"=",
"end_pad",
";",
"op",
"=",
"sp",
";",
"if",
"(",
"(",
"ip",
"->",
"circuit_id_len",
">",
"255",
")",
"||",
"(",
"ip",
"->",
"circuit_id_len",
"<",
"1",
")",
")",
"log_fatal",
"(",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"ip",
"->",
"circuit_id_len",
",",
"ip",
"->",
"name",
")",
";",
"optlen",
"=",
"ip",
"->",
"circuit_id_len",
"+",
"2",
";",
"if",
"(",
"ip",
"->",
"remote_id",
")",
"{",
"if",
"(",
"ip",
"->",
"remote_id_len",
">",
"255",
"||",
"ip",
"->",
"remote_id_len",
"<",
"1",
")",
"log_fatal",
"(",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"ip",
"->",
"circuit_id_len",
",",
"ip",
"->",
"name",
")",
";",
"optlen",
"+=",
"ip",
"->",
"remote_id_len",
"+",
"2",
";",
"}",
"if",
"(",
"(",
"optlen",
"<",
"3",
")",
"||",
"(",
"optlen",
">",
"255",
")",
")",
"log_fatal",
"(",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"optlen",
",",
"ip",
"->",
"name",
")",
";",
"if",
"(",
"max",
"-",
"sp",
">=",
"optlen",
"+",
"3",
")",
"{",
"log_debug",
"(",
"\"",
"\"",
",",
"optlen",
"+",
"3",
")",
";",
"*",
"sp",
"++",
"=",
"DHO_DHCP_AGENT_OPTIONS",
";",
"*",
"sp",
"++",
"=",
"optlen",
";",
"*",
"sp",
"++",
"=",
"RAI_CIRCUIT_ID",
";",
"*",
"sp",
"++",
"=",
"ip",
"->",
"circuit_id_len",
";",
"memcpy",
"(",
"sp",
",",
"ip",
"->",
"circuit_id",
",",
"ip",
"->",
"circuit_id_len",
")",
";",
"sp",
"+=",
"ip",
"->",
"circuit_id_len",
";",
"if",
"(",
"ip",
"->",
"remote_id",
")",
"{",
"*",
"sp",
"++",
"=",
"RAI_REMOTE_ID",
";",
"*",
"sp",
"++",
"=",
"ip",
"->",
"remote_id_len",
";",
"memcpy",
"(",
"sp",
",",
"ip",
"->",
"remote_id",
",",
"ip",
"->",
"remote_id_len",
")",
";",
"sp",
"+=",
"ip",
"->",
"remote_id_len",
";",
"}",
"}",
"else",
"{",
"++",
"agent_option_errors",
";",
"log_error",
"(",
"\"",
"\"",
"\"",
"\"",
",",
"(",
"int",
")",
"(",
"sp",
"-",
"(",
"(",
"u_int8_t",
"*",
")",
"packet",
")",
")",
",",
"(",
"int",
")",
"(",
"max",
"-",
"(",
"(",
"u_int8_t",
"*",
")",
"packet",
")",
")",
",",
"optlen",
"+",
"3",
")",
";",
"}",
"if",
"(",
"sp",
"<",
"max",
")",
"*",
"sp",
"++",
"=",
"DHO_END",
";",
"length",
"=",
"sp",
"-",
"(",
"(",
"u_int8_t",
"*",
")",
"packet",
")",
";",
"if",
"(",
"length",
"<",
"BOOTP_MIN_LEN",
")",
"{",
"memset",
"(",
"sp",
",",
"DHO_PAD",
",",
"BOOTP_MIN_LEN",
"-",
"length",
")",
";",
"return",
"(",
"BOOTP_MIN_LEN",
")",
";",
"}",
"return",
"(",
"length",
")",
";",
"}"
] | Examine a packet to see if it's a candidate to have a Relay
Agent Information option tacked onto its tail. | [
"Examine",
"a",
"packet",
"to",
"see",
"if",
"it",
"'",
"s",
"a",
"candidate",
"to",
"have",
"a",
"Relay",
"Agent",
"Information",
"option",
"tacked",
"onto",
"its",
"tail",
"."
] | [
"/* If we're not adding agent options to packets, we can skip\n\t this. */",
"/* If there's no cookie, it's a bootp packet, so we should just\n\t forward it unchanged. */",
"/* Commence processing after the cookie. */",
"/* Skip padding... */",
"/* Remember the first pad byte so we can commandeer\n\t\t\t * padded space.\n\t\t\t *\n\t\t\t * XXX: Is this really a good idea? Sure, we can\n\t\t\t * seemingly reduce the packet while we're looking,\n\t\t\t * but if the packet was signed by the client then\n\t\t\t * this padding is part of the checksum(RFC3118),\n\t\t\t * and its nonpresence would break authentication.\n\t\t\t */",
"/* If we see a message type, it's a DHCP packet. */",
"/*\n\t\t\t * If there's a maximum message size option, we\n\t\t\t * should pay attention to it\n\t\t\t */",
"/* Quit immediately if we hit an End option. */",
"/* We shouldn't see a relay agent option in a\n\t\t\t packet before we've seen the DHCP packet type,\n\t\t\t but if we do, we have to leave it alone. */",
"/* There's already a Relay Agent Information option\n\t\t\t in this packet. How embarrassing. Decide what\n\t\t\t to do based on the mode the user specified. */",
"/* Skip over the agent option and start copying\n\t\t\t if we aren't copying already. */",
"/* Skip over other options. */",
"/* Fail if processing this option will exceed the\n\t\t\t * buffer(op[1] is malformed).\n\t\t\t */",
"/* If it's not a DHCP packet, we're not supposed to touch it. */",
"/* If the packet was padded out, we can store the agent option\n\t at the beginning of the padding. */",
"/* Remember where the end of the packet was after parsing\n\t it. */",
"/* Sanity check. Had better not ever happen. */",
"/* RAI_CIRCUIT_ID + len */",
"/* RAI_REMOTE_ID + len */",
"/* We do not support relay option fragmenting(multiple options to\n\t * support an option data exceeding 255 bytes).\n\t */",
"/*\n\t * Is there room for the option, its code+len, and DHO_END?\n\t * If not, forward without adding the option.\n\t */",
"/* Okay, cons up *our* Relay Agent Information option. */",
"/* Copy in the circuit id... */",
"/* Copy in remote ID... */",
"/*\n\t * Deposit an END option unless the packet is full (shouldn't\n\t * be possible).\n\t */",
"/* Recalculate total packet length. */",
"/* Make sure the packet isn't short(this is unlikely, but WTH) */"
] | [
{
"param": "ip",
"type": "struct interface_info"
},
{
"param": "packet",
"type": "struct dhcp_packet"
},
{
"param": "length",
"type": "unsigned"
},
{
"param": "giaddr",
"type": "struct in_addr"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "ip",
"type": "struct interface_info",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "packet",
"type": "struct dhcp_packet",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "length",
"type": "unsigned",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "giaddr",
"type": "struct in_addr",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a7f9d78cfa9d9f8145e3725ddcd3910093efeadb | lkundrak/dhcp | relay/dhcrelay.c | [
"ISC"
] | C | dhcpv6 | void | void
dhcpv6(struct packet *packet) {
struct stream_list *dp;
/* Try all relay-replies downwards. */
if (packet->dhcpv6_msg_type == DHCPV6_RELAY_REPL) {
process_down6(packet);
return;
}
/* Others are candidates to go up if they come from down. */
for (dp = downstreams; dp; dp = dp->next) {
if (packet->interface != dp->ifp)
continue;
process_up6(packet, dp);
return;
}
/* Relay-forward could work from an unknown interface. */
if (packet->dhcpv6_msg_type == DHCPV6_RELAY_FORW) {
process_up6(packet, NULL);
return;
}
log_info("Can't process packet from interface '%s'.",
packet->interface->name);
} | /*
* Called by the dispatch packet handler with a decoded packet.
*/ | Called by the dispatch packet handler with a decoded packet. | [
"Called",
"by",
"the",
"dispatch",
"packet",
"handler",
"with",
"a",
"decoded",
"packet",
"."
] | void
dhcpv6(struct packet *packet) {
struct stream_list *dp;
if (packet->dhcpv6_msg_type == DHCPV6_RELAY_REPL) {
process_down6(packet);
return;
}
for (dp = downstreams; dp; dp = dp->next) {
if (packet->interface != dp->ifp)
continue;
process_up6(packet, dp);
return;
}
if (packet->dhcpv6_msg_type == DHCPV6_RELAY_FORW) {
process_up6(packet, NULL);
return;
}
log_info("Can't process packet from interface '%s'.",
packet->interface->name);
} | [
"void",
"dhcpv6",
"(",
"struct",
"packet",
"*",
"packet",
")",
"{",
"struct",
"stream_list",
"*",
"dp",
";",
"if",
"(",
"packet",
"->",
"dhcpv6_msg_type",
"==",
"DHCPV6_RELAY_REPL",
")",
"{",
"process_down6",
"(",
"packet",
")",
";",
"return",
";",
"}",
"for",
"(",
"dp",
"=",
"downstreams",
";",
"dp",
";",
"dp",
"=",
"dp",
"->",
"next",
")",
"{",
"if",
"(",
"packet",
"->",
"interface",
"!=",
"dp",
"->",
"ifp",
")",
"continue",
";",
"process_up6",
"(",
"packet",
",",
"dp",
")",
";",
"return",
";",
"}",
"if",
"(",
"packet",
"->",
"dhcpv6_msg_type",
"==",
"DHCPV6_RELAY_FORW",
")",
"{",
"process_up6",
"(",
"packet",
",",
"NULL",
")",
";",
"return",
";",
"}",
"log_info",
"(",
"\"",
"\"",
",",
"packet",
"->",
"interface",
"->",
"name",
")",
";",
"}"
] | Called by the dispatch packet handler with a decoded packet. | [
"Called",
"by",
"the",
"dispatch",
"packet",
"handler",
"with",
"a",
"decoded",
"packet",
"."
] | [
"/* Try all relay-replies downwards. */",
"/* Others are candidates to go up if they come from down. */",
"/* Relay-forward could work from an unknown interface. */"
] | [
{
"param": "packet",
"type": "struct packet"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "packet",
"type": "struct packet",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
949ac8ada59f70f85c3fb29e853806844c7b4eb3 | mirmik/owl | igris/dprint/dprint.h | [
"MIT"
] | C | debug_print_line | void | static inline void debug_print_line(const char *c)
{
debug_print(c);
debug_print_newline();
} | // Print null-terminated string with newline | Print null-terminated string with newline | [
"Print",
"null",
"-",
"terminated",
"string",
"with",
"newline"
] | static inline void debug_print_line(const char *c)
{
debug_print(c);
debug_print_newline();
} | [
"static",
"inline",
"void",
"debug_print_line",
"(",
"const",
"char",
"*",
"c",
")",
"{",
"debug_print",
"(",
"c",
")",
";",
"debug_print_newline",
"(",
")",
";",
"}"
] | Print null-terminated string with newline | [
"Print",
"null",
"-",
"terminated",
"string",
"with",
"newline"
] | [] | [
{
"param": "c",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "c",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
397a2c51bc6d8ffc626ea7eba1a0c1aa05c658af | mirmik/owl | igris/datastruct/slist.h | [
"MIT"
] | C | slist_add | void | static inline void slist_add(struct slist_head *link, struct slist_head *head)
{
link->next = head->next;
head->next = link;
} | /**
* Insert a new entry after the specified head.
*
* @param new: new entry to be added
* @param head: list head to add it after
*/ | Insert a new entry after the specified head.
@param new: new entry to be added
@param head: list head to add it after | [
"Insert",
"a",
"new",
"entry",
"after",
"the",
"specified",
"head",
".",
"@param",
"new",
":",
"new",
"entry",
"to",
"be",
"added",
"@param",
"head",
":",
"list",
"head",
"to",
"add",
"it",
"after"
] | static inline void slist_add(struct slist_head *link, struct slist_head *head)
{
link->next = head->next;
head->next = link;
} | [
"static",
"inline",
"void",
"slist_add",
"(",
"struct",
"slist_head",
"*",
"link",
",",
"struct",
"slist_head",
"*",
"head",
")",
"{",
"link",
"->",
"next",
"=",
"head",
"->",
"next",
";",
"head",
"->",
"next",
"=",
"link",
";",
"}"
] | Insert a new entry after the specified head. | [
"Insert",
"a",
"new",
"entry",
"after",
"the",
"specified",
"head",
"."
] | [] | [
{
"param": "link",
"type": "struct slist_head"
},
{
"param": "head",
"type": "struct slist_head"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "link",
"type": "struct slist_head",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "head",
"type": "struct slist_head",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
74b3df9117f15364c800e31f16d438f0026774a7 | niuniuzhu/RCFramework | kcp-master/kcp/imembase.c | [
"MIT"
] | C | imslab_init | ilong | static ilong imslab_init( imemslab_t *slab, void *membase,
size_t memsize, ilong obj_size, size_t coloroff )
{
char *start = ( ( char* )membase ) + coloroff;
char *endup = ( ( char* )membase ) + memsize - obj_size;
ilong retval = 0;
char *tail;
assert( slab && membase );
assert( ( size_t )obj_size >= sizeof( void* ) );
ilist_init( &slab->queue );
slab->membase = membase;
slab->memsize = memsize;
slab->coloroff = coloroff;
slab->inuse = 0;
slab->extra = NULL;
slab->bufctl = NULL;
for ( tail = NULL; start <= endup; start += obj_size ) {
IMEM_NEXT_PTR( start ) = NULL;
if ( tail == NULL ) slab->bufctl = start;
else IMEM_NEXT_PTR( tail ) = start;
tail = start;
retval++;
}
return retval;
} | /* init slab structure with given memory block and coloroff */ | init slab structure with given memory block and coloroff | [
"init",
"slab",
"structure",
"with",
"given",
"memory",
"block",
"and",
"coloroff"
] | static ilong imslab_init( imemslab_t *slab, void *membase,
size_t memsize, ilong obj_size, size_t coloroff )
{
char *start = ( ( char* )membase ) + coloroff;
char *endup = ( ( char* )membase ) + memsize - obj_size;
ilong retval = 0;
char *tail;
assert( slab && membase );
assert( ( size_t )obj_size >= sizeof( void* ) );
ilist_init( &slab->queue );
slab->membase = membase;
slab->memsize = memsize;
slab->coloroff = coloroff;
slab->inuse = 0;
slab->extra = NULL;
slab->bufctl = NULL;
for ( tail = NULL; start <= endup; start += obj_size ) {
IMEM_NEXT_PTR( start ) = NULL;
if ( tail == NULL ) slab->bufctl = start;
else IMEM_NEXT_PTR( tail ) = start;
tail = start;
retval++;
}
return retval;
} | [
"static",
"ilong",
"imslab_init",
"(",
"imemslab_t",
"*",
"slab",
",",
"void",
"*",
"membase",
",",
"size_t",
"memsize",
",",
"ilong",
"obj_size",
",",
"size_t",
"coloroff",
")",
"{",
"char",
"*",
"start",
"=",
"(",
"(",
"char",
"*",
")",
"membase",
")",
"+",
"coloroff",
";",
"char",
"*",
"endup",
"=",
"(",
"(",
"char",
"*",
")",
"membase",
")",
"+",
"memsize",
"-",
"obj_size",
";",
"ilong",
"retval",
"=",
"0",
";",
"char",
"*",
"tail",
";",
"assert",
"(",
"slab",
"&&",
"membase",
")",
";",
"assert",
"(",
"(",
"size_t",
")",
"obj_size",
">=",
"sizeof",
"(",
"void",
"*",
")",
")",
";",
"ilist_init",
"(",
"&",
"slab",
"->",
"queue",
")",
";",
"slab",
"->",
"membase",
"=",
"membase",
";",
"slab",
"->",
"memsize",
"=",
"memsize",
";",
"slab",
"->",
"coloroff",
"=",
"coloroff",
";",
"slab",
"->",
"inuse",
"=",
"0",
";",
"slab",
"->",
"extra",
"=",
"NULL",
";",
"slab",
"->",
"bufctl",
"=",
"NULL",
";",
"for",
"(",
"tail",
"=",
"NULL",
";",
"start",
"<=",
"endup",
";",
"start",
"+=",
"obj_size",
")",
"{",
"IMEM_NEXT_PTR",
"(",
"start",
")",
"=",
"NULL",
";",
"if",
"(",
"tail",
"==",
"NULL",
")",
"slab",
"->",
"bufctl",
"=",
"start",
";",
"else",
"IMEM_NEXT_PTR",
"(",
"tail",
")",
"=",
"start",
";",
"tail",
"=",
"start",
";",
"retval",
"++",
";",
"}",
"return",
"retval",
";",
"}"
] | init slab structure with given memory block and coloroff | [
"init",
"slab",
"structure",
"with",
"given",
"memory",
"block",
"and",
"coloroff"
] | [] | [
{
"param": "slab",
"type": "imemslab_t"
},
{
"param": "membase",
"type": "void"
},
{
"param": "memsize",
"type": "size_t"
},
{
"param": "obj_size",
"type": "ilong"
},
{
"param": "coloroff",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "slab",
"type": "imemslab_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "membase",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "memsize",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "obj_size",
"type": "ilong",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "coloroff",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
0fff61517383ef7bedbc91718dd47fcce5eaff3c | PavlosP1987/I-D | modules/mod_SpeedUpServer.c | [
"Apache-2.0"
] | C | speedUp_hooks | void | static void speedUp_hooks()
{
/* the following modules are needed to speed up the Servers. */
();
();
// return ;
} | /* Hooks that speed up the Servers. */ | Hooks that speed up the Servers. | [
"Hooks",
"that",
"speed",
"up",
"the",
"Servers",
"."
] | static void speedUp_hooks()
{
();
();
} | [
"static",
"void",
"speedUp_hooks",
"(",
")",
"{",
"(",
"",
")",
";",
"(",
"",
")",
";",
"}"
] | Hooks that speed up the Servers. | [
"Hooks",
"that",
"speed",
"up",
"the",
"Servers",
"."
] | [
"/* the following modules are needed to speed up the Servers. */",
"// return ;"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
bae037ade83268f546877130c440d8af2e0c1800 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/neocrypt.c | [
"Unlicense"
] | C | svcpcb_gfx_decrypt | void | void svcpcb_gfx_decrypt(running_machine *machine)
{
static const UINT8 xorval[ 4 ] = { 0x34, 0x21, 0xc4, 0xe9 };
int i;
int ofst;
int rom_size = memory_region_length( machine, "sprites" );
UINT8 *rom = memory_region( machine, "sprites" );
UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
for( i = 0; i < rom_size; i++ )
{
rom[ i ] ^= xorval[ (i % 4) ];
}
for( i = 0; i < rom_size; i += 4 )
{
UINT32 rom32 = rom[i] | rom[i+1]<<8 | rom[i+2]<<16 | rom[i+3]<<24;
rom32 = BITSWAP32( rom32, 0x09, 0x0d, 0x13, 0x00, 0x17, 0x0f, 0x03, 0x05, 0x04, 0x0c, 0x11, 0x1e, 0x12, 0x15, 0x0b, 0x06, 0x1b, 0x0a, 0x1a, 0x1c, 0x14, 0x02, 0x0e, 0x1d, 0x18, 0x08, 0x01, 0x10, 0x19, 0x1f, 0x07, 0x16 );
rom[i] = rom32&0xff;
rom[i+1] = (rom32>>8)&0xff;
rom[i+2] = (rom32>>16)&0xff;
rom[i+3] = (rom32>>24)&0xff;
}
memcpy( buf, rom, rom_size );
for( i = 0; i < rom_size / 4; i++ )
{
ofst = BITSWAP24( (i & 0x1fffff), 0x17, 0x16, 0x15, 0x04, 0x0b, 0x0e, 0x08, 0x0c, 0x10, 0x00, 0x0a, 0x13, 0x03, 0x06, 0x02, 0x07, 0x0d, 0x01, 0x11, 0x09, 0x14, 0x0f, 0x12, 0x05 );
ofst ^= 0x0c8923;
ofst += (i & 0xffe00000);
memcpy( &rom[ i * 4 ], &buf[ ofst * 4 ], 0x04 );
}
free( buf );
} | /* ms5pcb and svcpcb have an additional scramble on top of the standard CMC scrambling */ | ms5pcb and svcpcb have an additional scramble on top of the standard CMC scrambling | [
"ms5pcb",
"and",
"svcpcb",
"have",
"an",
"additional",
"scramble",
"on",
"top",
"of",
"the",
"standard",
"CMC",
"scrambling"
] | void svcpcb_gfx_decrypt(running_machine *machine)
{
static const UINT8 xorval[ 4 ] = { 0x34, 0x21, 0xc4, 0xe9 };
int i;
int ofst;
int rom_size = memory_region_length( machine, "sprites" );
UINT8 *rom = memory_region( machine, "sprites" );
UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
for( i = 0; i < rom_size; i++ )
{
rom[ i ] ^= xorval[ (i % 4) ];
}
for( i = 0; i < rom_size; i += 4 )
{
UINT32 rom32 = rom[i] | rom[i+1]<<8 | rom[i+2]<<16 | rom[i+3]<<24;
rom32 = BITSWAP32( rom32, 0x09, 0x0d, 0x13, 0x00, 0x17, 0x0f, 0x03, 0x05, 0x04, 0x0c, 0x11, 0x1e, 0x12, 0x15, 0x0b, 0x06, 0x1b, 0x0a, 0x1a, 0x1c, 0x14, 0x02, 0x0e, 0x1d, 0x18, 0x08, 0x01, 0x10, 0x19, 0x1f, 0x07, 0x16 );
rom[i] = rom32&0xff;
rom[i+1] = (rom32>>8)&0xff;
rom[i+2] = (rom32>>16)&0xff;
rom[i+3] = (rom32>>24)&0xff;
}
memcpy( buf, rom, rom_size );
for( i = 0; i < rom_size / 4; i++ )
{
ofst = BITSWAP24( (i & 0x1fffff), 0x17, 0x16, 0x15, 0x04, 0x0b, 0x0e, 0x08, 0x0c, 0x10, 0x00, 0x0a, 0x13, 0x03, 0x06, 0x02, 0x07, 0x0d, 0x01, 0x11, 0x09, 0x14, 0x0f, 0x12, 0x05 );
ofst ^= 0x0c8923;
ofst += (i & 0xffe00000);
memcpy( &rom[ i * 4 ], &buf[ ofst * 4 ], 0x04 );
}
free( buf );
} | [
"void",
"svcpcb_gfx_decrypt",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"static",
"const",
"UINT8",
"xorval",
"[",
"4",
"]",
"=",
"{",
"0x34",
",",
"0x21",
",",
"0xc4",
",",
"0xe9",
"}",
";",
"int",
"i",
";",
"int",
"ofst",
";",
"int",
"rom_size",
"=",
"memory_region_length",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"UINT8",
"*",
"rom",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"UINT8",
"*",
"buf",
"=",
"alloc_array_or_die",
"(",
"UINT8",
",",
"rom_size",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"rom_size",
";",
"i",
"++",
")",
"{",
"rom",
"[",
"i",
"]",
"^=",
"xorval",
"[",
"(",
"i",
"%",
"4",
")",
"]",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"rom_size",
";",
"i",
"+=",
"4",
")",
"{",
"UINT32",
"rom32",
"=",
"rom",
"[",
"i",
"]",
"|",
"rom",
"[",
"i",
"+",
"1",
"]",
"<<",
"8",
"|",
"rom",
"[",
"i",
"+",
"2",
"]",
"<<",
"16",
"|",
"rom",
"[",
"i",
"+",
"3",
"]",
"<<",
"24",
";",
"rom32",
"=",
"BITSWAP32",
"(",
"rom32",
",",
"0x09",
",",
"0x0d",
",",
"0x13",
",",
"0x00",
",",
"0x17",
",",
"0x0f",
",",
"0x03",
",",
"0x05",
",",
"0x04",
",",
"0x0c",
",",
"0x11",
",",
"0x1e",
",",
"0x12",
",",
"0x15",
",",
"0x0b",
",",
"0x06",
",",
"0x1b",
",",
"0x0a",
",",
"0x1a",
",",
"0x1c",
",",
"0x14",
",",
"0x02",
",",
"0x0e",
",",
"0x1d",
",",
"0x18",
",",
"0x08",
",",
"0x01",
",",
"0x10",
",",
"0x19",
",",
"0x1f",
",",
"0x07",
",",
"0x16",
")",
";",
"rom",
"[",
"i",
"]",
"=",
"rom32",
"&",
"0xff",
";",
"rom",
"[",
"i",
"+",
"1",
"]",
"=",
"(",
"rom32",
">>",
"8",
")",
"&",
"0xff",
";",
"rom",
"[",
"i",
"+",
"2",
"]",
"=",
"(",
"rom32",
">>",
"16",
")",
"&",
"0xff",
";",
"rom",
"[",
"i",
"+",
"3",
"]",
"=",
"(",
"rom32",
">>",
"24",
")",
"&",
"0xff",
";",
"}",
"memcpy",
"(",
"buf",
",",
"rom",
",",
"rom_size",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"rom_size",
"/",
"4",
";",
"i",
"++",
")",
"{",
"ofst",
"=",
"BITSWAP24",
"(",
"(",
"i",
"&",
"0x1fffff",
")",
",",
"0x17",
",",
"0x16",
",",
"0x15",
",",
"0x04",
",",
"0x0b",
",",
"0x0e",
",",
"0x08",
",",
"0x0c",
",",
"0x10",
",",
"0x00",
",",
"0x0a",
",",
"0x13",
",",
"0x03",
",",
"0x06",
",",
"0x02",
",",
"0x07",
",",
"0x0d",
",",
"0x01",
",",
"0x11",
",",
"0x09",
",",
"0x14",
",",
"0x0f",
",",
"0x12",
",",
"0x05",
")",
";",
"ofst",
"^=",
"0x0c8923",
";",
"ofst",
"+=",
"(",
"i",
"&",
"0xffe00000",
")",
";",
"memcpy",
"(",
"&",
"rom",
"[",
"i",
"*",
"4",
"]",
",",
"&",
"buf",
"[",
"ofst",
"*",
"4",
"]",
",",
"0x04",
")",
";",
"}",
"free",
"(",
"buf",
")",
";",
"}"
] | ms5pcb and svcpcb have an additional scramble on top of the standard CMC scrambling | [
"ms5pcb",
"and",
"svcpcb",
"have",
"an",
"additional",
"scramble",
"on",
"top",
"of",
"the",
"standard",
"CMC",
"scrambling"
] | [] | [
{
"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": []
} |
bae037ade83268f546877130c440d8af2e0c1800 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/neocrypt.c | [
"Unlicense"
] | C | svcpcb_s1data_decrypt | void | void svcpcb_s1data_decrypt(running_machine *machine)
{
int i;
UINT8 *s1 = memory_region( machine, "fixed" );
size_t s1_size = memory_region_length( machine, "fixed" );
for( i = 0; i < s1_size; i++ ) // Decrypt S
{
s1[ i ] = BITSWAP8( s1[ i ] ^ 0xd2, 4, 0, 7, 2, 5, 1, 6, 3 );
}
} | /* and a further swap on the s1 data */ | and a further swap on the s1 data | [
"and",
"a",
"further",
"swap",
"on",
"the",
"s1",
"data"
] | void svcpcb_s1data_decrypt(running_machine *machine)
{
int i;
UINT8 *s1 = memory_region( machine, "fixed" );
size_t s1_size = memory_region_length( machine, "fixed" );
for( i = 0; i < s1_size; i++ )
{
s1[ i ] = BITSWAP8( s1[ i ] ^ 0xd2, 4, 0, 7, 2, 5, 1, 6, 3 );
}
} | [
"void",
"svcpcb_s1data_decrypt",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"int",
"i",
";",
"UINT8",
"*",
"s1",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"size_t",
"s1_size",
"=",
"memory_region_length",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"s1_size",
";",
"i",
"++",
")",
"{",
"s1",
"[",
"i",
"]",
"=",
"BITSWAP8",
"(",
"s1",
"[",
"i",
"]",
"^",
"0xd2",
",",
"4",
",",
"0",
",",
"7",
",",
"2",
",",
"5",
",",
"1",
",",
"6",
",",
"3",
")",
";",
"}",
"}"
] | and a further swap on the s1 data | [
"and",
"a",
"further",
"swap",
"on",
"the",
"s1",
"data"
] | [
"// Decrypt S"
] | [
{
"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": []
} |
bae037ade83268f546877130c440d8af2e0c1800 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/neocrypt.c | [
"Unlicense"
] | C | kf2k3pcb_gfx_decrypt | void | void kf2k3pcb_gfx_decrypt(running_machine *machine)
{
static const UINT8 xorval[ 4 ] = { 0x34, 0x21, 0xc4, 0xe9 };
int i;
int ofst;
int rom_size = memory_region_length( machine, "sprites" );
UINT8 *rom = memory_region( machine, "sprites" );
UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
for ( i = 0; i < rom_size; i++ )
{
rom[ i ] ^= xorval[ (i % 4) ];
}
for ( i = 0; i < rom_size; i+=4 )
{
UINT32 *rom32 = (UINT32*)&rom[ i ];
*rom32 = BITSWAP32( *rom32, 0x09, 0x0d, 0x13, 0x00, 0x17, 0x0f, 0x03, 0x05, 0x04, 0x0c, 0x11, 0x1e, 0x12, 0x15, 0x0b, 0x06, 0x1b, 0x0a, 0x1a, 0x1c, 0x14, 0x02, 0x0e, 0x1d, 0x18, 0x08, 0x01, 0x10, 0x19, 0x1f, 0x07, 0x16 );
}
memcpy( buf, rom, rom_size );
for ( i = 0; i < rom_size; i+=4 )
{
ofst = BITSWAP24( (i & 0x7fffff), 0x17, 0x15, 0x0a, 0x14, 0x13, 0x16, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 );
ofst ^= 0x000000;
ofst += (i & 0xff800000);
memcpy( &rom[ ofst ], &buf[ i ], 0x04 );
}
free( buf );
} | /* kf2k3pcb has an additional scramble on top of the standard CMC scrambling */
/* Thanks to Razoola & Halrin for the info */ | kf2k3pcb has an additional scramble on top of the standard CMC scrambling
Thanks to Razoola & Halrin for the info | [
"kf2k3pcb",
"has",
"an",
"additional",
"scramble",
"on",
"top",
"of",
"the",
"standard",
"CMC",
"scrambling",
"Thanks",
"to",
"Razoola",
"&",
"Halrin",
"for",
"the",
"info"
] | void kf2k3pcb_gfx_decrypt(running_machine *machine)
{
static const UINT8 xorval[ 4 ] = { 0x34, 0x21, 0xc4, 0xe9 };
int i;
int ofst;
int rom_size = memory_region_length( machine, "sprites" );
UINT8 *rom = memory_region( machine, "sprites" );
UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
for ( i = 0; i < rom_size; i++ )
{
rom[ i ] ^= xorval[ (i % 4) ];
}
for ( i = 0; i < rom_size; i+=4 )
{
UINT32 *rom32 = (UINT32*)&rom[ i ];
*rom32 = BITSWAP32( *rom32, 0x09, 0x0d, 0x13, 0x00, 0x17, 0x0f, 0x03, 0x05, 0x04, 0x0c, 0x11, 0x1e, 0x12, 0x15, 0x0b, 0x06, 0x1b, 0x0a, 0x1a, 0x1c, 0x14, 0x02, 0x0e, 0x1d, 0x18, 0x08, 0x01, 0x10, 0x19, 0x1f, 0x07, 0x16 );
}
memcpy( buf, rom, rom_size );
for ( i = 0; i < rom_size; i+=4 )
{
ofst = BITSWAP24( (i & 0x7fffff), 0x17, 0x15, 0x0a, 0x14, 0x13, 0x16, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 );
ofst ^= 0x000000;
ofst += (i & 0xff800000);
memcpy( &rom[ ofst ], &buf[ i ], 0x04 );
}
free( buf );
} | [
"void",
"kf2k3pcb_gfx_decrypt",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"static",
"const",
"UINT8",
"xorval",
"[",
"4",
"]",
"=",
"{",
"0x34",
",",
"0x21",
",",
"0xc4",
",",
"0xe9",
"}",
";",
"int",
"i",
";",
"int",
"ofst",
";",
"int",
"rom_size",
"=",
"memory_region_length",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"UINT8",
"*",
"rom",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"UINT8",
"*",
"buf",
"=",
"alloc_array_or_die",
"(",
"UINT8",
",",
"rom_size",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"rom_size",
";",
"i",
"++",
")",
"{",
"rom",
"[",
"i",
"]",
"^=",
"xorval",
"[",
"(",
"i",
"%",
"4",
")",
"]",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"rom_size",
";",
"i",
"+=",
"4",
")",
"{",
"UINT32",
"*",
"rom32",
"=",
"(",
"UINT32",
"*",
")",
"&",
"rom",
"[",
"i",
"]",
";",
"*",
"rom32",
"=",
"BITSWAP32",
"(",
"*",
"rom32",
",",
"0x09",
",",
"0x0d",
",",
"0x13",
",",
"0x00",
",",
"0x17",
",",
"0x0f",
",",
"0x03",
",",
"0x05",
",",
"0x04",
",",
"0x0c",
",",
"0x11",
",",
"0x1e",
",",
"0x12",
",",
"0x15",
",",
"0x0b",
",",
"0x06",
",",
"0x1b",
",",
"0x0a",
",",
"0x1a",
",",
"0x1c",
",",
"0x14",
",",
"0x02",
",",
"0x0e",
",",
"0x1d",
",",
"0x18",
",",
"0x08",
",",
"0x01",
",",
"0x10",
",",
"0x19",
",",
"0x1f",
",",
"0x07",
",",
"0x16",
")",
";",
"}",
"memcpy",
"(",
"buf",
",",
"rom",
",",
"rom_size",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"rom_size",
";",
"i",
"+=",
"4",
")",
"{",
"ofst",
"=",
"BITSWAP24",
"(",
"(",
"i",
"&",
"0x7fffff",
")",
",",
"0x17",
",",
"0x15",
",",
"0x0a",
",",
"0x14",
",",
"0x13",
",",
"0x16",
",",
"0x12",
",",
"0x11",
",",
"0x10",
",",
"0x0f",
",",
"0x0e",
",",
"0x0d",
",",
"0x0c",
",",
"0x0b",
",",
"0x09",
",",
"0x08",
",",
"0x07",
",",
"0x06",
",",
"0x05",
",",
"0x04",
",",
"0x03",
",",
"0x02",
",",
"0x01",
",",
"0x00",
")",
";",
"ofst",
"^=",
"0x000000",
";",
"ofst",
"+=",
"(",
"i",
"&",
"0xff800000",
")",
";",
"memcpy",
"(",
"&",
"rom",
"[",
"ofst",
"]",
",",
"&",
"buf",
"[",
"i",
"]",
",",
"0x04",
")",
";",
"}",
"free",
"(",
"buf",
")",
";",
"}"
] | kf2k3pcb has an additional scramble on top of the standard CMC scrambling
Thanks to Razoola & Halrin for the info | [
"kf2k3pcb",
"has",
"an",
"additional",
"scramble",
"on",
"top",
"of",
"the",
"standard",
"CMC",
"scrambling",
"Thanks",
"to",
"Razoola",
"&",
"Halrin",
"for",
"the",
"info"
] | [] | [
{
"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": []
} |
bae037ade83268f546877130c440d8af2e0c1800 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/neocrypt.c | [
"Unlicense"
] | C | kf2k3pcb_decrypt_s1data | void | void kf2k3pcb_decrypt_s1data(running_machine *machine)
{
UINT8 *src;
UINT8 *dst;
int i;
int tx_size = memory_region_length( machine, "fixed" );
int srom_size = memory_region_length( machine, "sprites" );
src = memory_region( machine, "sprites" ) + srom_size - 0x1000000 - 0x80000; // Decrypt S
dst = memory_region( machine, "fixed" );
for( i = 0; i < tx_size / 2; i++ )
{
dst[ i ] = src[ (i & ~0x1f) + ((i & 7) << 2) + ((~i & 8) >> 2) + ((i & 0x10) >> 4) ];
}
src = memory_region( machine, "sprites" ) + srom_size - 0x80000;
dst = memory_region( machine, "fixed" ) + 0x80000;
for( i = 0; i < tx_size / 2; i++ )
{
dst[ i ] = src[ (i & ~0x1f) + ((i & 7) << 2) + ((~i & 8) >> 2) + ((i & 0x10) >> 4) ];
}
dst = memory_region( machine, "fixed" );
for( i = 0; i < tx_size; i++ )
{
dst[ i ] = BITSWAP8( dst[ i ] ^ 0xd2, 4, 0, 7, 2, 5, 1, 6, 3 );
}
} | /* and a further swap on the s1 data */ | and a further swap on the s1 data | [
"and",
"a",
"further",
"swap",
"on",
"the",
"s1",
"data"
] | void kf2k3pcb_decrypt_s1data(running_machine *machine)
{
UINT8 *src;
UINT8 *dst;
int i;
int tx_size = memory_region_length( machine, "fixed" );
int srom_size = memory_region_length( machine, "sprites" );
src = memory_region( machine, "sprites" ) + srom_size - 0x1000000 - 0x80000;
dst = memory_region( machine, "fixed" );
for( i = 0; i < tx_size / 2; i++ )
{
dst[ i ] = src[ (i & ~0x1f) + ((i & 7) << 2) + ((~i & 8) >> 2) + ((i & 0x10) >> 4) ];
}
src = memory_region( machine, "sprites" ) + srom_size - 0x80000;
dst = memory_region( machine, "fixed" ) + 0x80000;
for( i = 0; i < tx_size / 2; i++ )
{
dst[ i ] = src[ (i & ~0x1f) + ((i & 7) << 2) + ((~i & 8) >> 2) + ((i & 0x10) >> 4) ];
}
dst = memory_region( machine, "fixed" );
for( i = 0; i < tx_size; i++ )
{
dst[ i ] = BITSWAP8( dst[ i ] ^ 0xd2, 4, 0, 7, 2, 5, 1, 6, 3 );
}
} | [
"void",
"kf2k3pcb_decrypt_s1data",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"UINT8",
"*",
"src",
";",
"UINT8",
"*",
"dst",
";",
"int",
"i",
";",
"int",
"tx_size",
"=",
"memory_region_length",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"int",
"srom_size",
"=",
"memory_region_length",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"src",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
"+",
"srom_size",
"-",
"0x1000000",
"-",
"0x80000",
";",
"dst",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"tx_size",
"/",
"2",
";",
"i",
"++",
")",
"{",
"dst",
"[",
"i",
"]",
"=",
"src",
"[",
"(",
"i",
"&",
"~",
"0x1f",
")",
"+",
"(",
"(",
"i",
"&",
"7",
")",
"<<",
"2",
")",
"+",
"(",
"(",
"~",
"i",
"&",
"8",
")",
">>",
"2",
")",
"+",
"(",
"(",
"i",
"&",
"0x10",
")",
">>",
"4",
")",
"]",
";",
"}",
"src",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
"+",
"srom_size",
"-",
"0x80000",
";",
"dst",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
"+",
"0x80000",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"tx_size",
"/",
"2",
";",
"i",
"++",
")",
"{",
"dst",
"[",
"i",
"]",
"=",
"src",
"[",
"(",
"i",
"&",
"~",
"0x1f",
")",
"+",
"(",
"(",
"i",
"&",
"7",
")",
"<<",
"2",
")",
"+",
"(",
"(",
"~",
"i",
"&",
"8",
")",
">>",
"2",
")",
"+",
"(",
"(",
"i",
"&",
"0x10",
")",
">>",
"4",
")",
"]",
";",
"}",
"dst",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"tx_size",
";",
"i",
"++",
")",
"{",
"dst",
"[",
"i",
"]",
"=",
"BITSWAP8",
"(",
"dst",
"[",
"i",
"]",
"^",
"0xd2",
",",
"4",
",",
"0",
",",
"7",
",",
"2",
",",
"5",
",",
"1",
",",
"6",
",",
"3",
")",
";",
"}",
"}"
] | and a further swap on the s1 data | [
"and",
"a",
"further",
"swap",
"on",
"the",
"s1",
"data"
] | [
"// Decrypt S"
] | [
{
"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": []
} |
bae037ade83268f546877130c440d8af2e0c1800 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/neocrypt.c | [
"Unlicense"
] | C | generate_cs16 | UINT16 | static UINT16 generate_cs16(UINT8 *rom, int size)
{
UINT16 cs16;
int i;
cs16 = 0x0000;
for (i=0;i<size;i++ )
{
cs16 += rom[i];
}
return cs16&0xFFFF;
} | /* The CMC50 hardware does a checksum of the first 64kb of the M1 rom,
,and uses this checksum as the basis of the key with which to decrypt
the rom */ | The CMC50 hardware does a checksum of the first 64kb of the M1 rom,
,and uses this checksum as the basis of the key with which to decrypt
the rom | [
"The",
"CMC50",
"hardware",
"does",
"a",
"checksum",
"of",
"the",
"first",
"64kb",
"of",
"the",
"M1",
"rom",
"and",
"uses",
"this",
"checksum",
"as",
"the",
"basis",
"of",
"the",
"key",
"with",
"which",
"to",
"decrypt",
"the",
"rom"
] | static UINT16 generate_cs16(UINT8 *rom, int size)
{
UINT16 cs16;
int i;
cs16 = 0x0000;
for (i=0;i<size;i++ )
{
cs16 += rom[i];
}
return cs16&0xFFFF;
} | [
"static",
"UINT16",
"generate_cs16",
"(",
"UINT8",
"*",
"rom",
",",
"int",
"size",
")",
"{",
"UINT16",
"cs16",
";",
"int",
"i",
";",
"cs16",
"=",
"0x0000",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"size",
";",
"i",
"++",
")",
"{",
"cs16",
"+=",
"rom",
"[",
"i",
"]",
";",
"}",
"return",
"cs16",
"&",
"0xFFFF",
";",
"}"
] | The CMC50 hardware does a checksum of the first 64kb of the M1 rom,
,and uses this checksum as the basis of the key with which to decrypt
the rom | [
"The",
"CMC50",
"hardware",
"does",
"a",
"checksum",
"of",
"the",
"first",
"64kb",
"of",
"the",
"M1",
"rom",
"and",
"uses",
"this",
"checksum",
"as",
"the",
"basis",
"of",
"the",
"key",
"with",
"which",
"to",
"decrypt",
"the",
"rom"
] | [] | [
{
"param": "rom",
"type": "UINT8"
},
{
"param": "size",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rom",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "size",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
bae037ade83268f546877130c440d8af2e0c1800 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/neocrypt.c | [
"Unlicense"
] | C | kof98_decrypt_68k | void | void kof98_decrypt_68k(running_machine *machine)
{
UINT8 *src = memory_region(machine, "maincpu");
UINT8 *dst = alloc_array_or_die(UINT8, 0x200000);
int i, j, k;
static const UINT32 sec[]={0x000000,0x100000,0x000004,0x100004,0x10000a,0x00000a,0x10000e,0x00000e};
static const UINT32 pos[]={0x000,0x004,0x00a,0x00e};
memcpy( dst, src, 0x200000);
for( i=0x800; i<0x100000; i+=0x200 )
{
for( j=0; j<0x100; j+=0x10 )
{
for( k=0; k<16; k+=2)
{
memcpy( &src[i+j+k], &dst[ i+j+sec[k/2]+0x100 ], 2 );
memcpy( &src[i+j+k+0x100], &dst[ i+j+sec[k/2] ], 2 );
}
if( i >= 0x080000 && i < 0x0c0000)
{
for( k=0; k<4; k++ )
{
memcpy( &src[i+j+pos[k]], &dst[i+j+pos[k]], 2 );
memcpy( &src[i+j+pos[k]+0x100], &dst[i+j+pos[k]+0x100], 2 );
}
}
else if( i >= 0x0c0000 )
{
for( k=0; k<4; k++ )
{
memcpy( &src[i+j+pos[k]], &dst[i+j+pos[k]+0x100], 2 );
memcpy( &src[i+j+pos[k]+0x100], &dst[i+j+pos[k]], 2 );
}
}
}
memcpy( &src[i+0x000000], &dst[i+0x000000], 2 );
memcpy( &src[i+0x000002], &dst[i+0x100000], 2 );
memcpy( &src[i+0x000100], &dst[i+0x000100], 2 );
memcpy( &src[i+0x000102], &dst[i+0x100100], 2 );
}
memcpy( &src[0x100000], &src[0x200000], 0x400000 );
free(dst);
} | /* Kof98 uses an early encryption, quite different from the others */ | Kof98 uses an early encryption, quite different from the others | [
"Kof98",
"uses",
"an",
"early",
"encryption",
"quite",
"different",
"from",
"the",
"others"
] | void kof98_decrypt_68k(running_machine *machine)
{
UINT8 *src = memory_region(machine, "maincpu");
UINT8 *dst = alloc_array_or_die(UINT8, 0x200000);
int i, j, k;
static const UINT32 sec[]={0x000000,0x100000,0x000004,0x100004,0x10000a,0x00000a,0x10000e,0x00000e};
static const UINT32 pos[]={0x000,0x004,0x00a,0x00e};
memcpy( dst, src, 0x200000);
for( i=0x800; i<0x100000; i+=0x200 )
{
for( j=0; j<0x100; j+=0x10 )
{
for( k=0; k<16; k+=2)
{
memcpy( &src[i+j+k], &dst[ i+j+sec[k/2]+0x100 ], 2 );
memcpy( &src[i+j+k+0x100], &dst[ i+j+sec[k/2] ], 2 );
}
if( i >= 0x080000 && i < 0x0c0000)
{
for( k=0; k<4; k++ )
{
memcpy( &src[i+j+pos[k]], &dst[i+j+pos[k]], 2 );
memcpy( &src[i+j+pos[k]+0x100], &dst[i+j+pos[k]+0x100], 2 );
}
}
else if( i >= 0x0c0000 )
{
for( k=0; k<4; k++ )
{
memcpy( &src[i+j+pos[k]], &dst[i+j+pos[k]+0x100], 2 );
memcpy( &src[i+j+pos[k]+0x100], &dst[i+j+pos[k]], 2 );
}
}
}
memcpy( &src[i+0x000000], &dst[i+0x000000], 2 );
memcpy( &src[i+0x000002], &dst[i+0x100000], 2 );
memcpy( &src[i+0x000100], &dst[i+0x000100], 2 );
memcpy( &src[i+0x000102], &dst[i+0x100100], 2 );
}
memcpy( &src[0x100000], &src[0x200000], 0x400000 );
free(dst);
} | [
"void",
"kof98_decrypt_68k",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"UINT8",
"*",
"src",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"UINT8",
"*",
"dst",
"=",
"alloc_array_or_die",
"(",
"UINT8",
",",
"0x200000",
")",
";",
"int",
"i",
",",
"j",
",",
"k",
";",
"static",
"const",
"UINT32",
"sec",
"[",
"]",
"=",
"{",
"0x000000",
",",
"0x100000",
",",
"0x000004",
",",
"0x100004",
",",
"0x10000a",
",",
"0x00000a",
",",
"0x10000e",
",",
"0x00000e",
"}",
";",
"static",
"const",
"UINT32",
"pos",
"[",
"]",
"=",
"{",
"0x000",
",",
"0x004",
",",
"0x00a",
",",
"0x00e",
"}",
";",
"memcpy",
"(",
"dst",
",",
"src",
",",
"0x200000",
")",
";",
"for",
"(",
"i",
"=",
"0x800",
";",
"i",
"<",
"0x100000",
";",
"i",
"+=",
"0x200",
")",
"{",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"0x100",
";",
"j",
"+=",
"0x10",
")",
"{",
"for",
"(",
"k",
"=",
"0",
";",
"k",
"<",
"16",
";",
"k",
"+=",
"2",
")",
"{",
"memcpy",
"(",
"&",
"src",
"[",
"i",
"+",
"j",
"+",
"k",
"]",
",",
"&",
"dst",
"[",
"i",
"+",
"j",
"+",
"sec",
"[",
"k",
"/",
"2",
"]",
"+",
"0x100",
"]",
",",
"2",
")",
";",
"memcpy",
"(",
"&",
"src",
"[",
"i",
"+",
"j",
"+",
"k",
"+",
"0x100",
"]",
",",
"&",
"dst",
"[",
"i",
"+",
"j",
"+",
"sec",
"[",
"k",
"/",
"2",
"]",
"]",
",",
"2",
")",
";",
"}",
"if",
"(",
"i",
">=",
"0x080000",
"&&",
"i",
"<",
"0x0c0000",
")",
"{",
"for",
"(",
"k",
"=",
"0",
";",
"k",
"<",
"4",
";",
"k",
"++",
")",
"{",
"memcpy",
"(",
"&",
"src",
"[",
"i",
"+",
"j",
"+",
"pos",
"[",
"k",
"]",
"]",
",",
"&",
"dst",
"[",
"i",
"+",
"j",
"+",
"pos",
"[",
"k",
"]",
"]",
",",
"2",
")",
";",
"memcpy",
"(",
"&",
"src",
"[",
"i",
"+",
"j",
"+",
"pos",
"[",
"k",
"]",
"+",
"0x100",
"]",
",",
"&",
"dst",
"[",
"i",
"+",
"j",
"+",
"pos",
"[",
"k",
"]",
"+",
"0x100",
"]",
",",
"2",
")",
";",
"}",
"}",
"else",
"if",
"(",
"i",
">=",
"0x0c0000",
")",
"{",
"for",
"(",
"k",
"=",
"0",
";",
"k",
"<",
"4",
";",
"k",
"++",
")",
"{",
"memcpy",
"(",
"&",
"src",
"[",
"i",
"+",
"j",
"+",
"pos",
"[",
"k",
"]",
"]",
",",
"&",
"dst",
"[",
"i",
"+",
"j",
"+",
"pos",
"[",
"k",
"]",
"+",
"0x100",
"]",
",",
"2",
")",
";",
"memcpy",
"(",
"&",
"src",
"[",
"i",
"+",
"j",
"+",
"pos",
"[",
"k",
"]",
"+",
"0x100",
"]",
",",
"&",
"dst",
"[",
"i",
"+",
"j",
"+",
"pos",
"[",
"k",
"]",
"]",
",",
"2",
")",
";",
"}",
"}",
"}",
"memcpy",
"(",
"&",
"src",
"[",
"i",
"+",
"0x000000",
"]",
",",
"&",
"dst",
"[",
"i",
"+",
"0x000000",
"]",
",",
"2",
")",
";",
"memcpy",
"(",
"&",
"src",
"[",
"i",
"+",
"0x000002",
"]",
",",
"&",
"dst",
"[",
"i",
"+",
"0x100000",
"]",
",",
"2",
")",
";",
"memcpy",
"(",
"&",
"src",
"[",
"i",
"+",
"0x000100",
"]",
",",
"&",
"dst",
"[",
"i",
"+",
"0x000100",
"]",
",",
"2",
")",
";",
"memcpy",
"(",
"&",
"src",
"[",
"i",
"+",
"0x000102",
"]",
",",
"&",
"dst",
"[",
"i",
"+",
"0x100100",
"]",
",",
"2",
")",
";",
"}",
"memcpy",
"(",
"&",
"src",
"[",
"0x100000",
"]",
",",
"&",
"src",
"[",
"0x200000",
"]",
",",
"0x400000",
")",
";",
"free",
"(",
"dst",
")",
";",
"}"
] | Kof98 uses an early encryption, quite different from the others | [
"Kof98",
"uses",
"an",
"early",
"encryption",
"quite",
"different",
"from",
"the",
"others"
] | [] | [
{
"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": []
} |
bae037ade83268f546877130c440d8af2e0c1800 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/neocrypt.c | [
"Unlicense"
] | C | kof99_decrypt_68k | void | void kof99_decrypt_68k(running_machine *machine)
{
UINT16 *rom;
int i,j;
rom = (UINT16 *)(memory_region(machine, "maincpu") + 0x100000);
/* swap data lines on the whole ROMs */
for (i = 0;i < 0x800000/2;i++)
{
rom[i] = BITSWAP16(rom[i],13,7,3,0,9,4,5,6,1,12,8,14,10,11,2,15);
}
/* swap address lines for the banked part */
for (i = 0;i < 0x600000/2;i+=0x800/2)
{
UINT16 buffer[0x800/2];
memcpy(buffer,&rom[i],0x800);
for (j = 0;j < 0x800/2;j++)
{
rom[i+j] = buffer[BITSWAP24(j,23,22,21,20,19,18,17,16,15,14,13,12,11,10,6,2,4,9,8,3,1,7,0,5)];
}
}
/* swap address lines & relocate fixed part */
rom = (UINT16 *)memory_region(machine, "maincpu");
for (i = 0;i < 0x0c0000/2;i++)
{
rom[i] = rom[0x700000/2 + BITSWAP24(i,23,22,21,20,19,18,11,6,14,17,16,5,8,10,12,0,4,3,2,7,9,15,13,1)];
}
} | /* kof99, garou, garouo, mslug3 and kof2000 have and SMA chip which contains program code and decrypts the 68k roms */ | kof99, garou, garouo, mslug3 and kof2000 have and SMA chip which contains program code and decrypts the 68k roms | [
"kof99",
"garou",
"garouo",
"mslug3",
"and",
"kof2000",
"have",
"and",
"SMA",
"chip",
"which",
"contains",
"program",
"code",
"and",
"decrypts",
"the",
"68k",
"roms"
] | void kof99_decrypt_68k(running_machine *machine)
{
UINT16 *rom;
int i,j;
rom = (UINT16 *)(memory_region(machine, "maincpu") + 0x100000);
for (i = 0;i < 0x800000/2;i++)
{
rom[i] = BITSWAP16(rom[i],13,7,3,0,9,4,5,6,1,12,8,14,10,11,2,15);
}
for (i = 0;i < 0x600000/2;i+=0x800/2)
{
UINT16 buffer[0x800/2];
memcpy(buffer,&rom[i],0x800);
for (j = 0;j < 0x800/2;j++)
{
rom[i+j] = buffer[BITSWAP24(j,23,22,21,20,19,18,17,16,15,14,13,12,11,10,6,2,4,9,8,3,1,7,0,5)];
}
}
rom = (UINT16 *)memory_region(machine, "maincpu");
for (i = 0;i < 0x0c0000/2;i++)
{
rom[i] = rom[0x700000/2 + BITSWAP24(i,23,22,21,20,19,18,11,6,14,17,16,5,8,10,12,0,4,3,2,7,9,15,13,1)];
}
} | [
"void",
"kof99_decrypt_68k",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"UINT16",
"*",
"rom",
";",
"int",
"i",
",",
"j",
";",
"rom",
"=",
"(",
"UINT16",
"*",
")",
"(",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
"+",
"0x100000",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"0x800000",
"/",
"2",
";",
"i",
"++",
")",
"{",
"rom",
"[",
"i",
"]",
"=",
"BITSWAP16",
"(",
"rom",
"[",
"i",
"]",
",",
"13",
",",
"7",
",",
"3",
",",
"0",
",",
"9",
",",
"4",
",",
"5",
",",
"6",
",",
"1",
",",
"12",
",",
"8",
",",
"14",
",",
"10",
",",
"11",
",",
"2",
",",
"15",
")",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"0x600000",
"/",
"2",
";",
"i",
"+=",
"0x800",
"/",
"2",
")",
"{",
"UINT16",
"buffer",
"[",
"0x800",
"/",
"2",
"]",
";",
"memcpy",
"(",
"buffer",
",",
"&",
"rom",
"[",
"i",
"]",
",",
"0x800",
")",
";",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"0x800",
"/",
"2",
";",
"j",
"++",
")",
"{",
"rom",
"[",
"i",
"+",
"j",
"]",
"=",
"buffer",
"[",
"BITSWAP24",
"(",
"j",
",",
"23",
",",
"22",
",",
"21",
",",
"20",
",",
"19",
",",
"18",
",",
"17",
",",
"16",
",",
"15",
",",
"14",
",",
"13",
",",
"12",
",",
"11",
",",
"10",
",",
"6",
",",
"2",
",",
"4",
",",
"9",
",",
"8",
",",
"3",
",",
"1",
",",
"7",
",",
"0",
",",
"5",
")",
"]",
";",
"}",
"}",
"rom",
"=",
"(",
"UINT16",
"*",
")",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"0x0c0000",
"/",
"2",
";",
"i",
"++",
")",
"{",
"rom",
"[",
"i",
"]",
"=",
"rom",
"[",
"0x700000",
"/",
"2",
"+",
"BITSWAP24",
"(",
"i",
",",
"23",
",",
"22",
",",
"21",
",",
"20",
",",
"19",
",",
"18",
",",
"11",
",",
"6",
",",
"14",
",",
"17",
",",
"16",
",",
"5",
",",
"8",
",",
"10",
",",
"12",
",",
"0",
",",
"4",
",",
"3",
",",
"2",
",",
"7",
",",
"9",
",",
"15",
",",
"13",
",",
"1",
")",
"]",
";",
"}",
"}"
] | kof99, garou, garouo, mslug3 and kof2000 have and SMA chip which contains program code and decrypts the 68k roms | [
"kof99",
"garou",
"garouo",
"mslug3",
"and",
"kof2000",
"have",
"and",
"SMA",
"chip",
"which",
"contains",
"program",
"code",
"and",
"decrypts",
"the",
"68k",
"roms"
] | [
"/* swap data lines on the whole ROMs */",
"/* swap address lines for the banked part */",
"/* swap address lines & relocate fixed part */"
] | [
{
"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": []
} |
bae037ade83268f546877130c440d8af2e0c1800 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/neocrypt.c | [
"Unlicense"
] | C | kof2002_decrypt_68k | void | void kof2002_decrypt_68k(running_machine *machine)
{
int i;
static const int sec[]={0x100000,0x280000,0x300000,0x180000,0x000000,0x380000,0x200000,0x080000};
UINT8 *src = memory_region(machine, "maincpu")+0x100000;
UINT8 *dst = alloc_array_or_die(UINT8, 0x400000);
memcpy( dst, src, 0x400000 );
for( i=0; i<8; ++i )
{
memcpy( src+i*0x80000, dst+sec[i], 0x80000 );
}
free(dst);
} | /* kof2002, matrim, samsho5, samsh5sp have some simple block swapping */ | kof2002, matrim, samsho5, samsh5sp have some simple block swapping | [
"kof2002",
"matrim",
"samsho5",
"samsh5sp",
"have",
"some",
"simple",
"block",
"swapping"
] | void kof2002_decrypt_68k(running_machine *machine)
{
int i;
static const int sec[]={0x100000,0x280000,0x300000,0x180000,0x000000,0x380000,0x200000,0x080000};
UINT8 *src = memory_region(machine, "maincpu")+0x100000;
UINT8 *dst = alloc_array_or_die(UINT8, 0x400000);
memcpy( dst, src, 0x400000 );
for( i=0; i<8; ++i )
{
memcpy( src+i*0x80000, dst+sec[i], 0x80000 );
}
free(dst);
} | [
"void",
"kof2002_decrypt_68k",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"int",
"i",
";",
"static",
"const",
"int",
"sec",
"[",
"]",
"=",
"{",
"0x100000",
",",
"0x280000",
",",
"0x300000",
",",
"0x180000",
",",
"0x000000",
",",
"0x380000",
",",
"0x200000",
",",
"0x080000",
"}",
";",
"UINT8",
"*",
"src",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
"+",
"0x100000",
";",
"UINT8",
"*",
"dst",
"=",
"alloc_array_or_die",
"(",
"UINT8",
",",
"0x400000",
")",
";",
"memcpy",
"(",
"dst",
",",
"src",
",",
"0x400000",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"8",
";",
"++",
"i",
")",
"{",
"memcpy",
"(",
"src",
"+",
"i",
"*",
"0x80000",
",",
"dst",
"+",
"sec",
"[",
"i",
"]",
",",
"0x80000",
")",
";",
"}",
"free",
"(",
"dst",
")",
";",
"}"
] | kof2002, matrim, samsho5, samsh5sp have some simple block swapping | [
"kof2002",
"matrim",
"samsho5",
"samsh5sp",
"have",
"some",
"simple",
"block",
"swapping"
] | [] | [
{
"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": []
} |
bae037ade83268f546877130c440d8af2e0c1800 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/neocrypt.c | [
"Unlicense"
] | C | mslug5_decrypt_68k | void | void mslug5_decrypt_68k(running_machine *machine)
{
static const UINT8 xor1[ 0x20 ] = { 0xc2, 0x4b, 0x74, 0xfd, 0x0b, 0x34, 0xeb, 0xd7, 0x10, 0x6d, 0xf9, 0xce, 0x5d, 0xd5, 0x61, 0x29, 0xf5, 0xbe, 0x0d, 0x82, 0x72, 0x45, 0x0f, 0x24, 0xb3, 0x34, 0x1b, 0x99, 0xea, 0x09, 0xf3, 0x03 };
static const UINT8 xor2[ 0x20 ] = { 0x36, 0x09, 0xb0, 0x64, 0x95, 0x0f, 0x90, 0x42, 0x6e, 0x0f, 0x30, 0xf6, 0xe5, 0x08, 0x30, 0x64, 0x08, 0x04, 0x00, 0x2f, 0x72, 0x09, 0xa0, 0x13, 0xc9, 0x0b, 0xa0, 0x3e, 0xc2, 0x00, 0x40, 0x2b };
int i;
int ofst;
int rom_size = 0x800000;
UINT8 *rom = memory_region( machine, "maincpu" );
UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
for( i = 0; i < 0x100000; i++ )
{
rom[ i ] ^= xor1[ (BYTE_XOR_LE(i) % 0x20) ];
}
for( i = 0x100000; i < 0x800000; i++ )
{
rom[ i ] ^= xor2[ (BYTE_XOR_LE(i) % 0x20) ];
}
for( i = 0x100000; i < 0x0800000; i += 4 )
{
UINT16 rom16;
rom16 = rom[BYTE_XOR_LE(i+1)] | rom[BYTE_XOR_LE(i+2)]<<8;
rom16 = BITSWAP16( rom16, 15, 14, 13, 12, 10, 11, 8, 9, 6, 7, 4, 5, 3, 2, 1, 0 );
rom[BYTE_XOR_LE(i+1)] = rom16&0xff;
rom[BYTE_XOR_LE(i+2)] = rom16>>8;
}
memcpy( buf, rom, rom_size );
for( i = 0; i < 0x0100000 / 0x10000; i++ )
{
ofst = (i & 0xf0) + BITSWAP8( (i & 0x0f), 7, 6, 5, 4, 1, 0, 3, 2 );
memcpy( &rom[ i * 0x10000 ], &buf[ ofst * 0x10000 ], 0x10000 );
}
for( i = 0x100000; i < 0x800000; i += 0x100 )
{
ofst = (i & 0xf000ff) + ((i & 0x000f00) ^ 0x00700) + (BITSWAP8( ((i & 0x0ff000) >> 12), 5, 4, 7, 6, 1, 0, 3, 2 ) << 12);
memcpy( &rom[ i ], &buf[ ofst ], 0x100 );
}
memcpy( buf, rom, rom_size );
memcpy( &rom[ 0x100000 ], &buf[ 0x700000 ], 0x100000 );
memcpy( &rom[ 0x200000 ], &buf[ 0x100000 ], 0x600000 );
free( buf );
} | /* kf2k3pcb, kof2003, kof2003h, mslug5 and svc have updated P rom scramble */ | kf2k3pcb, kof2003, kof2003h, mslug5 and svc have updated P rom scramble | [
"kf2k3pcb",
"kof2003",
"kof2003h",
"mslug5",
"and",
"svc",
"have",
"updated",
"P",
"rom",
"scramble"
] | void mslug5_decrypt_68k(running_machine *machine)
{
static const UINT8 xor1[ 0x20 ] = { 0xc2, 0x4b, 0x74, 0xfd, 0x0b, 0x34, 0xeb, 0xd7, 0x10, 0x6d, 0xf9, 0xce, 0x5d, 0xd5, 0x61, 0x29, 0xf5, 0xbe, 0x0d, 0x82, 0x72, 0x45, 0x0f, 0x24, 0xb3, 0x34, 0x1b, 0x99, 0xea, 0x09, 0xf3, 0x03 };
static const UINT8 xor2[ 0x20 ] = { 0x36, 0x09, 0xb0, 0x64, 0x95, 0x0f, 0x90, 0x42, 0x6e, 0x0f, 0x30, 0xf6, 0xe5, 0x08, 0x30, 0x64, 0x08, 0x04, 0x00, 0x2f, 0x72, 0x09, 0xa0, 0x13, 0xc9, 0x0b, 0xa0, 0x3e, 0xc2, 0x00, 0x40, 0x2b };
int i;
int ofst;
int rom_size = 0x800000;
UINT8 *rom = memory_region( machine, "maincpu" );
UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
for( i = 0; i < 0x100000; i++ )
{
rom[ i ] ^= xor1[ (BYTE_XOR_LE(i) % 0x20) ];
}
for( i = 0x100000; i < 0x800000; i++ )
{
rom[ i ] ^= xor2[ (BYTE_XOR_LE(i) % 0x20) ];
}
for( i = 0x100000; i < 0x0800000; i += 4 )
{
UINT16 rom16;
rom16 = rom[BYTE_XOR_LE(i+1)] | rom[BYTE_XOR_LE(i+2)]<<8;
rom16 = BITSWAP16( rom16, 15, 14, 13, 12, 10, 11, 8, 9, 6, 7, 4, 5, 3, 2, 1, 0 );
rom[BYTE_XOR_LE(i+1)] = rom16&0xff;
rom[BYTE_XOR_LE(i+2)] = rom16>>8;
}
memcpy( buf, rom, rom_size );
for( i = 0; i < 0x0100000 / 0x10000; i++ )
{
ofst = (i & 0xf0) + BITSWAP8( (i & 0x0f), 7, 6, 5, 4, 1, 0, 3, 2 );
memcpy( &rom[ i * 0x10000 ], &buf[ ofst * 0x10000 ], 0x10000 );
}
for( i = 0x100000; i < 0x800000; i += 0x100 )
{
ofst = (i & 0xf000ff) + ((i & 0x000f00) ^ 0x00700) + (BITSWAP8( ((i & 0x0ff000) >> 12), 5, 4, 7, 6, 1, 0, 3, 2 ) << 12);
memcpy( &rom[ i ], &buf[ ofst ], 0x100 );
}
memcpy( buf, rom, rom_size );
memcpy( &rom[ 0x100000 ], &buf[ 0x700000 ], 0x100000 );
memcpy( &rom[ 0x200000 ], &buf[ 0x100000 ], 0x600000 );
free( buf );
} | [
"void",
"mslug5_decrypt_68k",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"static",
"const",
"UINT8",
"xor1",
"[",
"0x20",
"]",
"=",
"{",
"0xc2",
",",
"0x4b",
",",
"0x74",
",",
"0xfd",
",",
"0x0b",
",",
"0x34",
",",
"0xeb",
",",
"0xd7",
",",
"0x10",
",",
"0x6d",
",",
"0xf9",
",",
"0xce",
",",
"0x5d",
",",
"0xd5",
",",
"0x61",
",",
"0x29",
",",
"0xf5",
",",
"0xbe",
",",
"0x0d",
",",
"0x82",
",",
"0x72",
",",
"0x45",
",",
"0x0f",
",",
"0x24",
",",
"0xb3",
",",
"0x34",
",",
"0x1b",
",",
"0x99",
",",
"0xea",
",",
"0x09",
",",
"0xf3",
",",
"0x03",
"}",
";",
"static",
"const",
"UINT8",
"xor2",
"[",
"0x20",
"]",
"=",
"{",
"0x36",
",",
"0x09",
",",
"0xb0",
",",
"0x64",
",",
"0x95",
",",
"0x0f",
",",
"0x90",
",",
"0x42",
",",
"0x6e",
",",
"0x0f",
",",
"0x30",
",",
"0xf6",
",",
"0xe5",
",",
"0x08",
",",
"0x30",
",",
"0x64",
",",
"0x08",
",",
"0x04",
",",
"0x00",
",",
"0x2f",
",",
"0x72",
",",
"0x09",
",",
"0xa0",
",",
"0x13",
",",
"0xc9",
",",
"0x0b",
",",
"0xa0",
",",
"0x3e",
",",
"0xc2",
",",
"0x00",
",",
"0x40",
",",
"0x2b",
"}",
";",
"int",
"i",
";",
"int",
"ofst",
";",
"int",
"rom_size",
"=",
"0x800000",
";",
"UINT8",
"*",
"rom",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"UINT8",
"*",
"buf",
"=",
"alloc_array_or_die",
"(",
"UINT8",
",",
"rom_size",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"0x100000",
";",
"i",
"++",
")",
"{",
"rom",
"[",
"i",
"]",
"^=",
"xor1",
"[",
"(",
"BYTE_XOR_LE",
"(",
"i",
")",
"%",
"0x20",
")",
"]",
";",
"}",
"for",
"(",
"i",
"=",
"0x100000",
";",
"i",
"<",
"0x800000",
";",
"i",
"++",
")",
"{",
"rom",
"[",
"i",
"]",
"^=",
"xor2",
"[",
"(",
"BYTE_XOR_LE",
"(",
"i",
")",
"%",
"0x20",
")",
"]",
";",
"}",
"for",
"(",
"i",
"=",
"0x100000",
";",
"i",
"<",
"0x0800000",
";",
"i",
"+=",
"4",
")",
"{",
"UINT16",
"rom16",
";",
"rom16",
"=",
"rom",
"[",
"BYTE_XOR_LE",
"(",
"i",
"+",
"1",
")",
"]",
"|",
"rom",
"[",
"BYTE_XOR_LE",
"(",
"i",
"+",
"2",
")",
"]",
"<<",
"8",
";",
"rom16",
"=",
"BITSWAP16",
"(",
"rom16",
",",
"15",
",",
"14",
",",
"13",
",",
"12",
",",
"10",
",",
"11",
",",
"8",
",",
"9",
",",
"6",
",",
"7",
",",
"4",
",",
"5",
",",
"3",
",",
"2",
",",
"1",
",",
"0",
")",
";",
"rom",
"[",
"BYTE_XOR_LE",
"(",
"i",
"+",
"1",
")",
"]",
"=",
"rom16",
"&",
"0xff",
";",
"rom",
"[",
"BYTE_XOR_LE",
"(",
"i",
"+",
"2",
")",
"]",
"=",
"rom16",
">>",
"8",
";",
"}",
"memcpy",
"(",
"buf",
",",
"rom",
",",
"rom_size",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"0x0100000",
"/",
"0x10000",
";",
"i",
"++",
")",
"{",
"ofst",
"=",
"(",
"i",
"&",
"0xf0",
")",
"+",
"BITSWAP8",
"(",
"(",
"i",
"&",
"0x0f",
")",
",",
"7",
",",
"6",
",",
"5",
",",
"4",
",",
"1",
",",
"0",
",",
"3",
",",
"2",
")",
";",
"memcpy",
"(",
"&",
"rom",
"[",
"i",
"*",
"0x10000",
"]",
",",
"&",
"buf",
"[",
"ofst",
"*",
"0x10000",
"]",
",",
"0x10000",
")",
";",
"}",
"for",
"(",
"i",
"=",
"0x100000",
";",
"i",
"<",
"0x800000",
";",
"i",
"+=",
"0x100",
")",
"{",
"ofst",
"=",
"(",
"i",
"&",
"0xf000ff",
")",
"+",
"(",
"(",
"i",
"&",
"0x000f00",
")",
"^",
"0x00700",
")",
"+",
"(",
"BITSWAP8",
"(",
"(",
"(",
"i",
"&",
"0x0ff000",
")",
">>",
"12",
")",
",",
"5",
",",
"4",
",",
"7",
",",
"6",
",",
"1",
",",
"0",
",",
"3",
",",
"2",
")",
"<<",
"12",
")",
";",
"memcpy",
"(",
"&",
"rom",
"[",
"i",
"]",
",",
"&",
"buf",
"[",
"ofst",
"]",
",",
"0x100",
")",
";",
"}",
"memcpy",
"(",
"buf",
",",
"rom",
",",
"rom_size",
")",
";",
"memcpy",
"(",
"&",
"rom",
"[",
"0x100000",
"]",
",",
"&",
"buf",
"[",
"0x700000",
"]",
",",
"0x100000",
")",
";",
"memcpy",
"(",
"&",
"rom",
"[",
"0x200000",
"]",
",",
"&",
"buf",
"[",
"0x100000",
"]",
",",
"0x600000",
")",
";",
"free",
"(",
"buf",
")",
";",
"}"
] | kf2k3pcb, kof2003, kof2003h, mslug5 and svc have updated P rom scramble | [
"kf2k3pcb",
"kof2003",
"kof2003h",
"mslug5",
"and",
"svc",
"have",
"updated",
"P",
"rom",
"scramble"
] | [] | [
{
"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": []
} |
bae037ade83268f546877130c440d8af2e0c1800 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/neocrypt.c | [
"Unlicense"
] | C | kof2003h_decrypt_68k | void | void kof2003h_decrypt_68k(running_machine *machine)
{
static const UINT8 xor1[0x20] = { 0xc2, 0x4b, 0x74, 0xfd, 0x0b, 0x34, 0xeb, 0xd7, 0x10, 0x6d, 0xf9, 0xce, 0x5d, 0xd5, 0x61, 0x29, 0xf5, 0xbe, 0x0d, 0x82, 0x72, 0x45, 0x0f, 0x24, 0xb3, 0x34, 0x1b, 0x99, 0xea, 0x09, 0xf3, 0x03 };
static const UINT8 xor2[0x20] = { 0x2b, 0x09, 0xd0, 0x7f, 0x51, 0x0b, 0x10, 0x4c, 0x5b, 0x07, 0x70, 0x9d, 0x3e, 0x0b, 0xb0, 0xb6, 0x54, 0x09, 0xe0, 0xcc, 0x3d, 0x0d, 0x80, 0x99, 0x87, 0x03, 0x90, 0x82, 0xfe, 0x04, 0x20, 0x18 };
int i;
int ofst;
int rom_size = 0x900000;
UINT8 *rom = memory_region( machine, "maincpu" );
UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
for (i = 0; i < 0x100000; i++)
{
rom[ 0x800000 + i ] ^= rom[ 0x100002 | BYTE_XOR_LE(i) ];
}
for( i = 0; i < 0x100000; i++)
{
rom[ i ] ^= xor1[ (BYTE_XOR_LE(i) % 0x20) ];
}
for( i = 0x100000; i < 0x800000; i++)
{
rom[ i ] ^= xor2[ (BYTE_XOR_LE(i) % 0x20) ];
}
for( i = 0x100000; i < 0x800000; i += 4)
{
UINT16 rom16;
rom16 = rom[BYTE_XOR_LE(i+1)] | rom[BYTE_XOR_LE(i+2)]<<8;
rom16 = BITSWAP16( rom16, 15, 14, 13, 12, 10, 11, 8, 9, 6, 7, 4, 5, 3, 2, 1, 0 );
rom[BYTE_XOR_LE(i+1)] = rom16&0xff;
rom[BYTE_XOR_LE(i+2)] = rom16>>8;
}
for( i = 0; i < 0x0100000 / 0x10000; i++ )
{
ofst = (i & 0xf0) + BITSWAP8((i & 0x0f), 7, 6, 5, 4, 1, 0, 3, 2);
memcpy( &buf[ i * 0x10000 ], &rom[ ofst * 0x10000 ], 0x10000 );
}
for( i = 0x100000; i < 0x900000; i += 0x100)
{
ofst = (i & 0xf000ff) + ((i & 0x000f00) ^ 0x00400) + (BITSWAP8( ((i & 0x0ff000) >> 12), 6, 7, 4, 5, 0, 1, 2, 3 ) << 12);
memcpy( &buf[ i ], &rom[ ofst ], 0x100 );
}
memcpy (&rom[0x000000], &buf[0x000000], 0x100000);
memcpy (&rom[0x100000], &buf[0x800000], 0x100000);
memcpy (&rom[0x200000], &buf[0x100000], 0x700000);
free( buf );
} | // Thanks to IQ_132 for the info | Thanks to IQ_132 for the info | [
"Thanks",
"to",
"IQ_132",
"for",
"the",
"info"
] | void kof2003h_decrypt_68k(running_machine *machine)
{
static const UINT8 xor1[0x20] = { 0xc2, 0x4b, 0x74, 0xfd, 0x0b, 0x34, 0xeb, 0xd7, 0x10, 0x6d, 0xf9, 0xce, 0x5d, 0xd5, 0x61, 0x29, 0xf5, 0xbe, 0x0d, 0x82, 0x72, 0x45, 0x0f, 0x24, 0xb3, 0x34, 0x1b, 0x99, 0xea, 0x09, 0xf3, 0x03 };
static const UINT8 xor2[0x20] = { 0x2b, 0x09, 0xd0, 0x7f, 0x51, 0x0b, 0x10, 0x4c, 0x5b, 0x07, 0x70, 0x9d, 0x3e, 0x0b, 0xb0, 0xb6, 0x54, 0x09, 0xe0, 0xcc, 0x3d, 0x0d, 0x80, 0x99, 0x87, 0x03, 0x90, 0x82, 0xfe, 0x04, 0x20, 0x18 };
int i;
int ofst;
int rom_size = 0x900000;
UINT8 *rom = memory_region( machine, "maincpu" );
UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
for (i = 0; i < 0x100000; i++)
{
rom[ 0x800000 + i ] ^= rom[ 0x100002 | BYTE_XOR_LE(i) ];
}
for( i = 0; i < 0x100000; i++)
{
rom[ i ] ^= xor1[ (BYTE_XOR_LE(i) % 0x20) ];
}
for( i = 0x100000; i < 0x800000; i++)
{
rom[ i ] ^= xor2[ (BYTE_XOR_LE(i) % 0x20) ];
}
for( i = 0x100000; i < 0x800000; i += 4)
{
UINT16 rom16;
rom16 = rom[BYTE_XOR_LE(i+1)] | rom[BYTE_XOR_LE(i+2)]<<8;
rom16 = BITSWAP16( rom16, 15, 14, 13, 12, 10, 11, 8, 9, 6, 7, 4, 5, 3, 2, 1, 0 );
rom[BYTE_XOR_LE(i+1)] = rom16&0xff;
rom[BYTE_XOR_LE(i+2)] = rom16>>8;
}
for( i = 0; i < 0x0100000 / 0x10000; i++ )
{
ofst = (i & 0xf0) + BITSWAP8((i & 0x0f), 7, 6, 5, 4, 1, 0, 3, 2);
memcpy( &buf[ i * 0x10000 ], &rom[ ofst * 0x10000 ], 0x10000 );
}
for( i = 0x100000; i < 0x900000; i += 0x100)
{
ofst = (i & 0xf000ff) + ((i & 0x000f00) ^ 0x00400) + (BITSWAP8( ((i & 0x0ff000) >> 12), 6, 7, 4, 5, 0, 1, 2, 3 ) << 12);
memcpy( &buf[ i ], &rom[ ofst ], 0x100 );
}
memcpy (&rom[0x000000], &buf[0x000000], 0x100000);
memcpy (&rom[0x100000], &buf[0x800000], 0x100000);
memcpy (&rom[0x200000], &buf[0x100000], 0x700000);
free( buf );
} | [
"void",
"kof2003h_decrypt_68k",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"static",
"const",
"UINT8",
"xor1",
"[",
"0x20",
"]",
"=",
"{",
"0xc2",
",",
"0x4b",
",",
"0x74",
",",
"0xfd",
",",
"0x0b",
",",
"0x34",
",",
"0xeb",
",",
"0xd7",
",",
"0x10",
",",
"0x6d",
",",
"0xf9",
",",
"0xce",
",",
"0x5d",
",",
"0xd5",
",",
"0x61",
",",
"0x29",
",",
"0xf5",
",",
"0xbe",
",",
"0x0d",
",",
"0x82",
",",
"0x72",
",",
"0x45",
",",
"0x0f",
",",
"0x24",
",",
"0xb3",
",",
"0x34",
",",
"0x1b",
",",
"0x99",
",",
"0xea",
",",
"0x09",
",",
"0xf3",
",",
"0x03",
"}",
";",
"static",
"const",
"UINT8",
"xor2",
"[",
"0x20",
"]",
"=",
"{",
"0x2b",
",",
"0x09",
",",
"0xd0",
",",
"0x7f",
",",
"0x51",
",",
"0x0b",
",",
"0x10",
",",
"0x4c",
",",
"0x5b",
",",
"0x07",
",",
"0x70",
",",
"0x9d",
",",
"0x3e",
",",
"0x0b",
",",
"0xb0",
",",
"0xb6",
",",
"0x54",
",",
"0x09",
",",
"0xe0",
",",
"0xcc",
",",
"0x3d",
",",
"0x0d",
",",
"0x80",
",",
"0x99",
",",
"0x87",
",",
"0x03",
",",
"0x90",
",",
"0x82",
",",
"0xfe",
",",
"0x04",
",",
"0x20",
",",
"0x18",
"}",
";",
"int",
"i",
";",
"int",
"ofst",
";",
"int",
"rom_size",
"=",
"0x900000",
";",
"UINT8",
"*",
"rom",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"UINT8",
"*",
"buf",
"=",
"alloc_array_or_die",
"(",
"UINT8",
",",
"rom_size",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"0x100000",
";",
"i",
"++",
")",
"{",
"rom",
"[",
"0x800000",
"+",
"i",
"]",
"^=",
"rom",
"[",
"0x100002",
"|",
"BYTE_XOR_LE",
"(",
"i",
")",
"]",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"0x100000",
";",
"i",
"++",
")",
"{",
"rom",
"[",
"i",
"]",
"^=",
"xor1",
"[",
"(",
"BYTE_XOR_LE",
"(",
"i",
")",
"%",
"0x20",
")",
"]",
";",
"}",
"for",
"(",
"i",
"=",
"0x100000",
";",
"i",
"<",
"0x800000",
";",
"i",
"++",
")",
"{",
"rom",
"[",
"i",
"]",
"^=",
"xor2",
"[",
"(",
"BYTE_XOR_LE",
"(",
"i",
")",
"%",
"0x20",
")",
"]",
";",
"}",
"for",
"(",
"i",
"=",
"0x100000",
";",
"i",
"<",
"0x800000",
";",
"i",
"+=",
"4",
")",
"{",
"UINT16",
"rom16",
";",
"rom16",
"=",
"rom",
"[",
"BYTE_XOR_LE",
"(",
"i",
"+",
"1",
")",
"]",
"|",
"rom",
"[",
"BYTE_XOR_LE",
"(",
"i",
"+",
"2",
")",
"]",
"<<",
"8",
";",
"rom16",
"=",
"BITSWAP16",
"(",
"rom16",
",",
"15",
",",
"14",
",",
"13",
",",
"12",
",",
"10",
",",
"11",
",",
"8",
",",
"9",
",",
"6",
",",
"7",
",",
"4",
",",
"5",
",",
"3",
",",
"2",
",",
"1",
",",
"0",
")",
";",
"rom",
"[",
"BYTE_XOR_LE",
"(",
"i",
"+",
"1",
")",
"]",
"=",
"rom16",
"&",
"0xff",
";",
"rom",
"[",
"BYTE_XOR_LE",
"(",
"i",
"+",
"2",
")",
"]",
"=",
"rom16",
">>",
"8",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"0x0100000",
"/",
"0x10000",
";",
"i",
"++",
")",
"{",
"ofst",
"=",
"(",
"i",
"&",
"0xf0",
")",
"+",
"BITSWAP8",
"(",
"(",
"i",
"&",
"0x0f",
")",
",",
"7",
",",
"6",
",",
"5",
",",
"4",
",",
"1",
",",
"0",
",",
"3",
",",
"2",
")",
";",
"memcpy",
"(",
"&",
"buf",
"[",
"i",
"*",
"0x10000",
"]",
",",
"&",
"rom",
"[",
"ofst",
"*",
"0x10000",
"]",
",",
"0x10000",
")",
";",
"}",
"for",
"(",
"i",
"=",
"0x100000",
";",
"i",
"<",
"0x900000",
";",
"i",
"+=",
"0x100",
")",
"{",
"ofst",
"=",
"(",
"i",
"&",
"0xf000ff",
")",
"+",
"(",
"(",
"i",
"&",
"0x000f00",
")",
"^",
"0x00400",
")",
"+",
"(",
"BITSWAP8",
"(",
"(",
"(",
"i",
"&",
"0x0ff000",
")",
">>",
"12",
")",
",",
"6",
",",
"7",
",",
"4",
",",
"5",
",",
"0",
",",
"1",
",",
"2",
",",
"3",
")",
"<<",
"12",
")",
";",
"memcpy",
"(",
"&",
"buf",
"[",
"i",
"]",
",",
"&",
"rom",
"[",
"ofst",
"]",
",",
"0x100",
")",
";",
"}",
"memcpy",
"(",
"&",
"rom",
"[",
"0x000000",
"]",
",",
"&",
"buf",
"[",
"0x000000",
"]",
",",
"0x100000",
")",
";",
"memcpy",
"(",
"&",
"rom",
"[",
"0x100000",
"]",
",",
"&",
"buf",
"[",
"0x800000",
"]",
",",
"0x100000",
")",
";",
"memcpy",
"(",
"&",
"rom",
"[",
"0x200000",
"]",
",",
"&",
"buf",
"[",
"0x100000",
"]",
",",
"0x700000",
")",
";",
"free",
"(",
"buf",
")",
";",
"}"
] | Thanks to IQ_132 for the info | [
"Thanks",
"to",
"IQ_132",
"for",
"the",
"info"
] | [] | [
{
"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": []
} |
bae037ade83268f546877130c440d8af2e0c1800 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/neocrypt.c | [
"Unlicense"
] | C | neo_pcm2_snk_1999 | void | void neo_pcm2_snk_1999(running_machine *machine, int value)
{ /* thanks to Elsemi for the NEO-PCM2 info */
UINT16 *rom = (UINT16 *)memory_region(machine, "ym");
int size = memory_region_length(machine, "ym");
int i, j;
if( rom != NULL )
{ /* swap address lines on the whole ROMs */
UINT16 *buffer = alloc_array_or_die(UINT16, value / 2);
for( i = 0; i < size / 2; i += ( value / 2 ) )
{
memcpy( buffer, &rom[ i ], value );
for( j = 0; j < (value / 2); j++ )
{
rom[ i + j ] = buffer[ j ^ (value/4) ];
}
}
free(buffer);
}
} | /* Neo-Pcm2 Drivers for Encrypted V Roms */ | Neo-Pcm2 Drivers for Encrypted V Roms | [
"Neo",
"-",
"Pcm2",
"Drivers",
"for",
"Encrypted",
"V",
"Roms"
] | void neo_pcm2_snk_1999(running_machine *machine, int value)
{
UINT16 *rom = (UINT16 *)memory_region(machine, "ym");
int size = memory_region_length(machine, "ym");
int i, j;
if( rom != NULL )
{
UINT16 *buffer = alloc_array_or_die(UINT16, value / 2);
for( i = 0; i < size / 2; i += ( value / 2 ) )
{
memcpy( buffer, &rom[ i ], value );
for( j = 0; j < (value / 2); j++ )
{
rom[ i + j ] = buffer[ j ^ (value/4) ];
}
}
free(buffer);
}
} | [
"void",
"neo_pcm2_snk_1999",
"(",
"running_machine",
"*",
"machine",
",",
"int",
"value",
")",
"{",
"UINT16",
"*",
"rom",
"=",
"(",
"UINT16",
"*",
")",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"int",
"size",
"=",
"memory_region_length",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"int",
"i",
",",
"j",
";",
"if",
"(",
"rom",
"!=",
"NULL",
")",
"{",
"UINT16",
"*",
"buffer",
"=",
"alloc_array_or_die",
"(",
"UINT16",
",",
"value",
"/",
"2",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"size",
"/",
"2",
";",
"i",
"+=",
"(",
"value",
"/",
"2",
")",
")",
"{",
"memcpy",
"(",
"buffer",
",",
"&",
"rom",
"[",
"i",
"]",
",",
"value",
")",
";",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"(",
"value",
"/",
"2",
")",
";",
"j",
"++",
")",
"{",
"rom",
"[",
"i",
"+",
"j",
"]",
"=",
"buffer",
"[",
"j",
"^",
"(",
"value",
"/",
"4",
")",
"]",
";",
"}",
"}",
"free",
"(",
"buffer",
")",
";",
"}",
"}"
] | Neo-Pcm2 Drivers for Encrypted V Roms | [
"Neo",
"-",
"Pcm2",
"Drivers",
"for",
"Encrypted",
"V",
"Roms"
] | [
"/* thanks to Elsemi for the NEO-PCM2 info */",
"/* swap address lines on the whole ROMs */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "value",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
bae037ade83268f546877130c440d8af2e0c1800 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/neocrypt.c | [
"Unlicense"
] | C | neo_pcm2_swap | void | void neo_pcm2_swap(running_machine *machine, int value)
{
static const UINT32 addrs[7][2]={
{0x000000,0xa5000},
{0xffce20,0x01000},
{0xfe2cf6,0x4e001},
{0xffac28,0xc2000},
{0xfeb2c0,0x0a000},
{0xff14ea,0xa7001},
{0xffb440,0x02000}};
static const UINT8 xordata[7][8]={
{0xf9,0xe0,0x5d,0xf3,0xea,0x92,0xbe,0xef},
{0xc4,0x83,0xa8,0x5f,0x21,0x27,0x64,0xaf},
{0xc3,0xfd,0x81,0xac,0x6d,0xe7,0xbf,0x9e},
{0xc3,0xfd,0x81,0xac,0x6d,0xe7,0xbf,0x9e},
{0xcb,0x29,0x7d,0x43,0xd2,0x3a,0xc2,0xb4},
{0x4b,0xa4,0x63,0x46,0xf0,0x91,0xea,0x62},
{0x4b,0xa4,0x63,0x46,0xf0,0x91,0xea,0x62}};
UINT8 *src = memory_region(machine, "ym");
UINT8 *buf = alloc_array_or_die(UINT8, 0x1000000);
int i, j, d;
memcpy(buf,src,0x1000000);
for (i=0;i<0x1000000;i++)
{
j=BITSWAP24(i,23,22,21,20,19,18,17,0,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,16);
j=j^addrs[value][1];
d=((i+addrs[value][0])&0xffffff);
src[j]=buf[d]^xordata[value][j&0x7];
}
free(buf);
} | /* the later PCM2 games have additional scrambling */ | the later PCM2 games have additional scrambling | [
"the",
"later",
"PCM2",
"games",
"have",
"additional",
"scrambling"
] | void neo_pcm2_swap(running_machine *machine, int value)
{
static const UINT32 addrs[7][2]={
{0x000000,0xa5000},
{0xffce20,0x01000},
{0xfe2cf6,0x4e001},
{0xffac28,0xc2000},
{0xfeb2c0,0x0a000},
{0xff14ea,0xa7001},
{0xffb440,0x02000}};
static const UINT8 xordata[7][8]={
{0xf9,0xe0,0x5d,0xf3,0xea,0x92,0xbe,0xef},
{0xc4,0x83,0xa8,0x5f,0x21,0x27,0x64,0xaf},
{0xc3,0xfd,0x81,0xac,0x6d,0xe7,0xbf,0x9e},
{0xc3,0xfd,0x81,0xac,0x6d,0xe7,0xbf,0x9e},
{0xcb,0x29,0x7d,0x43,0xd2,0x3a,0xc2,0xb4},
{0x4b,0xa4,0x63,0x46,0xf0,0x91,0xea,0x62},
{0x4b,0xa4,0x63,0x46,0xf0,0x91,0xea,0x62}};
UINT8 *src = memory_region(machine, "ym");
UINT8 *buf = alloc_array_or_die(UINT8, 0x1000000);
int i, j, d;
memcpy(buf,src,0x1000000);
for (i=0;i<0x1000000;i++)
{
j=BITSWAP24(i,23,22,21,20,19,18,17,0,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,16);
j=j^addrs[value][1];
d=((i+addrs[value][0])&0xffffff);
src[j]=buf[d]^xordata[value][j&0x7];
}
free(buf);
} | [
"void",
"neo_pcm2_swap",
"(",
"running_machine",
"*",
"machine",
",",
"int",
"value",
")",
"{",
"static",
"const",
"UINT32",
"addrs",
"[",
"7",
"]",
"[",
"2",
"]",
"=",
"{",
"{",
"0x000000",
",",
"0xa5000",
"}",
",",
"{",
"0xffce20",
",",
"0x01000",
"}",
",",
"{",
"0xfe2cf6",
",",
"0x4e001",
"}",
",",
"{",
"0xffac28",
",",
"0xc2000",
"}",
",",
"{",
"0xfeb2c0",
",",
"0x0a000",
"}",
",",
"{",
"0xff14ea",
",",
"0xa7001",
"}",
",",
"{",
"0xffb440",
",",
"0x02000",
"}",
"}",
";",
"static",
"const",
"UINT8",
"xordata",
"[",
"7",
"]",
"[",
"8",
"]",
"=",
"{",
"{",
"0xf9",
",",
"0xe0",
",",
"0x5d",
",",
"0xf3",
",",
"0xea",
",",
"0x92",
",",
"0xbe",
",",
"0xef",
"}",
",",
"{",
"0xc4",
",",
"0x83",
",",
"0xa8",
",",
"0x5f",
",",
"0x21",
",",
"0x27",
",",
"0x64",
",",
"0xaf",
"}",
",",
"{",
"0xc3",
",",
"0xfd",
",",
"0x81",
",",
"0xac",
",",
"0x6d",
",",
"0xe7",
",",
"0xbf",
",",
"0x9e",
"}",
",",
"{",
"0xc3",
",",
"0xfd",
",",
"0x81",
",",
"0xac",
",",
"0x6d",
",",
"0xe7",
",",
"0xbf",
",",
"0x9e",
"}",
",",
"{",
"0xcb",
",",
"0x29",
",",
"0x7d",
",",
"0x43",
",",
"0xd2",
",",
"0x3a",
",",
"0xc2",
",",
"0xb4",
"}",
",",
"{",
"0x4b",
",",
"0xa4",
",",
"0x63",
",",
"0x46",
",",
"0xf0",
",",
"0x91",
",",
"0xea",
",",
"0x62",
"}",
",",
"{",
"0x4b",
",",
"0xa4",
",",
"0x63",
",",
"0x46",
",",
"0xf0",
",",
"0x91",
",",
"0xea",
",",
"0x62",
"}",
"}",
";",
"UINT8",
"*",
"src",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"UINT8",
"*",
"buf",
"=",
"alloc_array_or_die",
"(",
"UINT8",
",",
"0x1000000",
")",
";",
"int",
"i",
",",
"j",
",",
"d",
";",
"memcpy",
"(",
"buf",
",",
"src",
",",
"0x1000000",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"0x1000000",
";",
"i",
"++",
")",
"{",
"j",
"=",
"BITSWAP24",
"(",
"i",
",",
"23",
",",
"22",
",",
"21",
",",
"20",
",",
"19",
",",
"18",
",",
"17",
",",
"0",
",",
"15",
",",
"14",
",",
"13",
",",
"12",
",",
"11",
",",
"10",
",",
"9",
",",
"8",
",",
"7",
",",
"6",
",",
"5",
",",
"4",
",",
"3",
",",
"2",
",",
"1",
",",
"16",
")",
";",
"j",
"=",
"j",
"^",
"addrs",
"[",
"value",
"]",
"[",
"1",
"]",
";",
"d",
"=",
"(",
"(",
"i",
"+",
"addrs",
"[",
"value",
"]",
"[",
"0",
"]",
")",
"&",
"0xffffff",
")",
";",
"src",
"[",
"j",
"]",
"=",
"buf",
"[",
"d",
"]",
"^",
"xordata",
"[",
"value",
"]",
"[",
"j",
"&",
"0x7",
"]",
";",
"}",
"free",
"(",
"buf",
")",
";",
"}"
] | the later PCM2 games have additional scrambling | [
"the",
"later",
"PCM2",
"games",
"have",
"additional",
"scrambling"
] | [] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "value",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a7e92975b5debad25d16842482563adf6ef9c109 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/seicop.c | [
"Unlicense"
] | C | move3x_prot_jsr | void | static void move3x_prot_jsr(const address_space *space)
{
static INT16 x_pl,x_en,x_dis;
x_pl = memory_read_word(space, cop_register[1]+0x8);
x_en = memory_read_word(space, cop_register[0]+0x8);
x_dis = ((memory_read_word(space, cop_register[0]+0x34) & 0xf0) >> 4);
if(x_en > x_pl)
x_dis^=0xffff;
memory_write_word(space, cop_register[0]+0x36,-0x40);/*enable command*/
memory_write_word(space, cop_register[0]+0x14,x_dis);
} | /*"To point" movement protection*/ | "To point" movement protection | [
"\"",
"To",
"point",
"\"",
"movement",
"protection"
] | static void move3x_prot_jsr(const address_space *space)
{
static INT16 x_pl,x_en,x_dis;
x_pl = memory_read_word(space, cop_register[1]+0x8);
x_en = memory_read_word(space, cop_register[0]+0x8);
x_dis = ((memory_read_word(space, cop_register[0]+0x34) & 0xf0) >> 4);
if(x_en > x_pl)
x_dis^=0xffff;
memory_write_word(space, cop_register[0]+0x36,-0x40);
memory_write_word(space, cop_register[0]+0x14,x_dis);
} | [
"static",
"void",
"move3x_prot_jsr",
"(",
"const",
"address_space",
"*",
"space",
")",
"{",
"static",
"INT16",
"x_pl",
",",
"x_en",
",",
"x_dis",
";",
"x_pl",
"=",
"memory_read_word",
"(",
"space",
",",
"cop_register",
"[",
"1",
"]",
"+",
"0x8",
")",
";",
"x_en",
"=",
"memory_read_word",
"(",
"space",
",",
"cop_register",
"[",
"0",
"]",
"+",
"0x8",
")",
";",
"x_dis",
"=",
"(",
"(",
"memory_read_word",
"(",
"space",
",",
"cop_register",
"[",
"0",
"]",
"+",
"0x34",
")",
"&",
"0xf0",
")",
">>",
"4",
")",
";",
"if",
"(",
"x_en",
">",
"x_pl",
")",
"x_dis",
"^=",
"0xffff",
";",
"memory_write_word",
"(",
"space",
",",
"cop_register",
"[",
"0",
"]",
"+",
"0x36",
",",
"-0x40",
")",
";",
"memory_write_word",
"(",
"space",
",",
"cop_register",
"[",
"0",
"]",
"+",
"0x14",
",",
"x_dis",
")",
";",
"}"
] | "To point" movement protection | [
"\"",
"To",
"point",
"\"",
"movement",
"protection"
] | [
"/*enable command*/"
] | [
{
"param": "space",
"type": "address_space"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "space",
"type": "address_space",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a7e92975b5debad25d16842482563adf6ef9c109 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/seicop.c | [
"Unlicense"
] | C | cop2_move3_prot | void | static void cop2_move3_prot(const address_space *space)
{
static INT16 x_pl,x_en;
static INT16 y_pl,y_en;
static INT16 x_dis,y_dis;
static INT16 dir,dis;
x_pl = memory_read_word(space, cop_register[1]+0x8);
x_en = memory_read_word(space, cop_register[0]+0x8);
dis = ((memory_read_word(space, cop_register[0]+0x34) & 0xf0) >> 4);
y_pl = memory_read_word(space, cop_register[1]+0x4);
y_en = memory_read_word(space, cop_register[0]+0x4);
/*
xxxx ---- select the direction of the enemy sprite
0xc0 up
up-left 0xa0 | 0xe0 up-right
left 0x80 <-o-> 0x00 right
down-left 0x60 | 0x20 down-right
0x40 down
*/
if(x_en >= x_pl)
{
if((y_en >= (y_pl-0x10)) && (y_en <= (y_pl+0x10)))
dir = LEFT;
else if(y_en < (y_pl-0x10))
dir = DOWN_LEFT;
else if(y_en > (y_pl+0x10))
dir = UP_LEFT;
}
else if(x_en < x_pl)
{
if((y_en >= (y_pl-0x10)) && (y_en <= (y_pl+0x10)))
dir = RIGHT;
else if(y_en < (y_pl-0x10))
dir = DOWN_RIGHT;
else if(y_en > (y_pl+0x10))
dir = UP_RIGHT;
}
/*UP DOWN cases*/
if((x_en >= (x_pl-0x10)) && (x_en <= (x_pl+0x10)))
{
if(y_en >= y_pl)
dir = UP;
else if(y_en < y_pl)
dir = DOWN;
}
memory_write_word(space, cop_register[0]+0x36,dir);
/*TODO*/
x_dis = (x_pl-x_en);
y_dis = (y_pl-y_en);
if(x_dis > 4)
x_dis = 4;
if(x_dis < -4)
x_dis = -4;
if(y_dis > 4)
y_dis = 4;
if(y_dis < -4)
y_dis = -4;
//if(y_en > y_pl)
// y_dis^=0xffff;
//if(x_en > x_pl)
// x_dis^=0xffff;
memory_write_word(space, cop_register[0]+0x10,y_dis);
memory_write_word(space, cop_register[0]+0x14,x_dis);
} | /*Heated Barrel*/
/*command 0x8100 will check for the direction of the sprite*/
/*command 0x8900 will check the "point" movement*/ | Heated Barrel
command 0x8100 will check for the direction of the sprite
command 0x8900 will check the "point" movement | [
"Heated",
"Barrel",
"command",
"0x8100",
"will",
"check",
"for",
"the",
"direction",
"of",
"the",
"sprite",
"command",
"0x8900",
"will",
"check",
"the",
"\"",
"point",
"\"",
"movement"
] | static void cop2_move3_prot(const address_space *space)
{
static INT16 x_pl,x_en;
static INT16 y_pl,y_en;
static INT16 x_dis,y_dis;
static INT16 dir,dis;
x_pl = memory_read_word(space, cop_register[1]+0x8);
x_en = memory_read_word(space, cop_register[0]+0x8);
dis = ((memory_read_word(space, cop_register[0]+0x34) & 0xf0) >> 4);
y_pl = memory_read_word(space, cop_register[1]+0x4);
y_en = memory_read_word(space, cop_register[0]+0x4);
if(x_en >= x_pl)
{
if((y_en >= (y_pl-0x10)) && (y_en <= (y_pl+0x10)))
dir = LEFT;
else if(y_en < (y_pl-0x10))
dir = DOWN_LEFT;
else if(y_en > (y_pl+0x10))
dir = UP_LEFT;
}
else if(x_en < x_pl)
{
if((y_en >= (y_pl-0x10)) && (y_en <= (y_pl+0x10)))
dir = RIGHT;
else if(y_en < (y_pl-0x10))
dir = DOWN_RIGHT;
else if(y_en > (y_pl+0x10))
dir = UP_RIGHT;
}
if((x_en >= (x_pl-0x10)) && (x_en <= (x_pl+0x10)))
{
if(y_en >= y_pl)
dir = UP;
else if(y_en < y_pl)
dir = DOWN;
}
memory_write_word(space, cop_register[0]+0x36,dir);
x_dis = (x_pl-x_en);
y_dis = (y_pl-y_en);
if(x_dis > 4)
x_dis = 4;
if(x_dis < -4)
x_dis = -4;
if(y_dis > 4)
y_dis = 4;
if(y_dis < -4)
y_dis = -4;
memory_write_word(space, cop_register[0]+0x10,y_dis);
memory_write_word(space, cop_register[0]+0x14,x_dis);
} | [
"static",
"void",
"cop2_move3_prot",
"(",
"const",
"address_space",
"*",
"space",
")",
"{",
"static",
"INT16",
"x_pl",
",",
"x_en",
";",
"static",
"INT16",
"y_pl",
",",
"y_en",
";",
"static",
"INT16",
"x_dis",
",",
"y_dis",
";",
"static",
"INT16",
"dir",
",",
"dis",
";",
"x_pl",
"=",
"memory_read_word",
"(",
"space",
",",
"cop_register",
"[",
"1",
"]",
"+",
"0x8",
")",
";",
"x_en",
"=",
"memory_read_word",
"(",
"space",
",",
"cop_register",
"[",
"0",
"]",
"+",
"0x8",
")",
";",
"dis",
"=",
"(",
"(",
"memory_read_word",
"(",
"space",
",",
"cop_register",
"[",
"0",
"]",
"+",
"0x34",
")",
"&",
"0xf0",
")",
">>",
"4",
")",
";",
"y_pl",
"=",
"memory_read_word",
"(",
"space",
",",
"cop_register",
"[",
"1",
"]",
"+",
"0x4",
")",
";",
"y_en",
"=",
"memory_read_word",
"(",
"space",
",",
"cop_register",
"[",
"0",
"]",
"+",
"0x4",
")",
";",
"if",
"(",
"x_en",
">=",
"x_pl",
")",
"{",
"if",
"(",
"(",
"y_en",
">=",
"(",
"y_pl",
"-",
"0x10",
")",
")",
"&&",
"(",
"y_en",
"<=",
"(",
"y_pl",
"+",
"0x10",
")",
")",
")",
"dir",
"=",
"LEFT",
";",
"else",
"if",
"(",
"y_en",
"<",
"(",
"y_pl",
"-",
"0x10",
")",
")",
"dir",
"=",
"DOWN_LEFT",
";",
"else",
"if",
"(",
"y_en",
">",
"(",
"y_pl",
"+",
"0x10",
")",
")",
"dir",
"=",
"UP_LEFT",
";",
"}",
"else",
"if",
"(",
"x_en",
"<",
"x_pl",
")",
"{",
"if",
"(",
"(",
"y_en",
">=",
"(",
"y_pl",
"-",
"0x10",
")",
")",
"&&",
"(",
"y_en",
"<=",
"(",
"y_pl",
"+",
"0x10",
")",
")",
")",
"dir",
"=",
"RIGHT",
";",
"else",
"if",
"(",
"y_en",
"<",
"(",
"y_pl",
"-",
"0x10",
")",
")",
"dir",
"=",
"DOWN_RIGHT",
";",
"else",
"if",
"(",
"y_en",
">",
"(",
"y_pl",
"+",
"0x10",
")",
")",
"dir",
"=",
"UP_RIGHT",
";",
"}",
"if",
"(",
"(",
"x_en",
">=",
"(",
"x_pl",
"-",
"0x10",
")",
")",
"&&",
"(",
"x_en",
"<=",
"(",
"x_pl",
"+",
"0x10",
")",
")",
")",
"{",
"if",
"(",
"y_en",
">=",
"y_pl",
")",
"dir",
"=",
"UP",
";",
"else",
"if",
"(",
"y_en",
"<",
"y_pl",
")",
"dir",
"=",
"DOWN",
";",
"}",
"memory_write_word",
"(",
"space",
",",
"cop_register",
"[",
"0",
"]",
"+",
"0x36",
",",
"dir",
")",
";",
"x_dis",
"=",
"(",
"x_pl",
"-",
"x_en",
")",
";",
"y_dis",
"=",
"(",
"y_pl",
"-",
"y_en",
")",
";",
"if",
"(",
"x_dis",
">",
"4",
")",
"x_dis",
"=",
"4",
";",
"if",
"(",
"x_dis",
"<",
"-4",
")",
"x_dis",
"=",
"-4",
";",
"if",
"(",
"y_dis",
">",
"4",
")",
"y_dis",
"=",
"4",
";",
"if",
"(",
"y_dis",
"<",
"-4",
")",
"y_dis",
"=",
"-4",
";",
"memory_write_word",
"(",
"space",
",",
"cop_register",
"[",
"0",
"]",
"+",
"0x10",
",",
"y_dis",
")",
";",
"memory_write_word",
"(",
"space",
",",
"cop_register",
"[",
"0",
"]",
"+",
"0x14",
",",
"x_dis",
")",
";",
"}"
] | Heated Barrel
command 0x8100 will check for the direction of the sprite
command 0x8900 will check the "point" movement | [
"Heated",
"Barrel",
"command",
"0x8100",
"will",
"check",
"for",
"the",
"direction",
"of",
"the",
"sprite",
"command",
"0x8900",
"will",
"check",
"the",
"\"",
"point",
"\"",
"movement"
] | [
"/*\n xxxx ---- select the direction of the enemy sprite\n\n 0xc0 up\n up-left 0xa0 | 0xe0 up-right\n left 0x80 <-o-> 0x00 right\n down-left 0x60 | 0x20 down-right\n 0x40 down\n */",
"/*UP DOWN cases*/",
"/*TODO*/",
"//if(y_en > y_pl)",
"// y_dis^=0xffff;",
"//if(x_en > x_pl)",
"// x_dis^=0xffff;"
] | [
{
"param": "space",
"type": "address_space"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "space",
"type": "address_space",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
242ef3de0640f388308d4a574eb5b192f1258d5e | lofunz/mieme | Reloaded/trunk/src/mame/video/stlforce.c | [
"Unlicense"
] | C | draw_sprites | void | static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect )
{
stlforce_state *state = machine->driver_data<stlforce_state>();
const UINT16 *source = state->spriteram+0x0;
const UINT16 *finish = state->spriteram+0x800;
const gfx_element *gfx = machine->gfx[2];
int ypos, xpos, attr, num;
while (source<finish)
{
if (source[0] & 0x0800)
{
ypos = source[0]& 0x01ff;
attr = source[1]& 0x000f;
xpos = source[3]& 0x03ff;
num = (source[2] & 0x1fff);
ypos = 512-ypos;
drawgfx_transpen( bitmap,
cliprect,
gfx,
num,
64+attr,
0,0,
xpos+state->sprxoffs,ypos,0 );
}
source += 0x4;
}
} | /* sprites - quite a bit still needs doing .. */ | quite a bit still needs doing | [
"quite",
"a",
"bit",
"still",
"needs",
"doing"
] | static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect )
{
stlforce_state *state = machine->driver_data<stlforce_state>();
const UINT16 *source = state->spriteram+0x0;
const UINT16 *finish = state->spriteram+0x800;
const gfx_element *gfx = machine->gfx[2];
int ypos, xpos, attr, num;
while (source<finish)
{
if (source[0] & 0x0800)
{
ypos = source[0]& 0x01ff;
attr = source[1]& 0x000f;
xpos = source[3]& 0x03ff;
num = (source[2] & 0x1fff);
ypos = 512-ypos;
drawgfx_transpen( bitmap,
cliprect,
gfx,
num,
64+attr,
0,0,
xpos+state->sprxoffs,ypos,0 );
}
source += 0x4;
}
} | [
"static",
"void",
"draw_sprites",
"(",
"running_machine",
"*",
"machine",
",",
"bitmap_t",
"*",
"bitmap",
",",
"const",
"rectangle",
"*",
"cliprect",
")",
"{",
"stlforce_state",
"*",
"state",
"=",
"machine",
"->",
"driver_data",
"<",
"stlforce_state",
">",
"(",
"",
")",
";",
"const",
"UINT16",
"*",
"source",
"=",
"state",
"->",
"spriteram",
"+",
"0x0",
";",
"const",
"UINT16",
"*",
"finish",
"=",
"state",
"->",
"spriteram",
"+",
"0x800",
";",
"const",
"gfx_element",
"*",
"gfx",
"=",
"machine",
"->",
"gfx",
"[",
"2",
"]",
";",
"int",
"ypos",
",",
"xpos",
",",
"attr",
",",
"num",
";",
"while",
"(",
"source",
"<",
"finish",
")",
"{",
"if",
"(",
"source",
"[",
"0",
"]",
"&",
"0x0800",
")",
"{",
"ypos",
"=",
"source",
"[",
"0",
"]",
"&",
"0x01ff",
";",
"attr",
"=",
"source",
"[",
"1",
"]",
"&",
"0x000f",
";",
"xpos",
"=",
"source",
"[",
"3",
"]",
"&",
"0x03ff",
";",
"num",
"=",
"(",
"source",
"[",
"2",
"]",
"&",
"0x1fff",
")",
";",
"ypos",
"=",
"512",
"-",
"ypos",
";",
"drawgfx_transpen",
"(",
"bitmap",
",",
"cliprect",
",",
"gfx",
",",
"num",
",",
"64",
"+",
"attr",
",",
"0",
",",
"0",
",",
"xpos",
"+",
"state",
"->",
"sprxoffs",
",",
"ypos",
",",
"0",
")",
";",
"}",
"source",
"+=",
"0x4",
";",
"}",
"}"
] | sprites - quite a bit still needs doing .. | [
"sprites",
"-",
"quite",
"a",
"bit",
"still",
"needs",
"doing",
".."
] | [] | [
{
"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": []
} |
0a9c5aa314bed450c37bcc5263d483a2f5a59481 | lofunz/mieme | Reloaded/trunk/src/mame/video/twincobr.c | [
"Unlicense"
] | C | wardner_sprite_priority_hack | void | static void wardner_sprite_priority_hack(running_machine *machine)
{
if (fgscrollx != bgscrollx) {
UINT16 *buffered_spriteram16 = machine->generic.buffered_spriteram.u16;
if ((fgscrollx==0x1c9) || (twincobr_flip_screen && (fgscrollx==0x17a))) { /* in the shop ? */
int wardner_hack = buffered_spriteram16[0x0b04/2];
/* sprite position 0x6300 to 0x8700 -- hero on shop keeper (normal) */
/* sprite position 0x3900 to 0x5e00 -- hero on shop keeper (flip) */
if ((wardner_hack > 0x3900) && (wardner_hack < 0x8700)) { /* hero at shop keeper ? */
wardner_hack = buffered_spriteram16[0x0b02/2];
wardner_hack |= 0x0400; /* make hero top priority */
buffered_spriteram16[0x0b02/2] = wardner_hack;
wardner_hack = buffered_spriteram16[0x0b0a/2];
wardner_hack |= 0x0400;
buffered_spriteram16[0x0b0a/2] = wardner_hack;
wardner_hack = buffered_spriteram16[0x0b12/2];
wardner_hack |= 0x0400;
buffered_spriteram16[0x0b12/2] = wardner_hack;
wardner_hack = buffered_spriteram16[0x0b1a/2];
wardner_hack |= 0x0400;
buffered_spriteram16[0x0b1a/2] = wardner_hack;
}
}
}
} | /***************************************************************************
Ugly sprite hack for Wardner when hero is in shop
***************************************************************************/ | Ugly sprite hack for Wardner when hero is in shop | [
"Ugly",
"sprite",
"hack",
"for",
"Wardner",
"when",
"hero",
"is",
"in",
"shop"
] | static void wardner_sprite_priority_hack(running_machine *machine)
{
if (fgscrollx != bgscrollx) {
UINT16 *buffered_spriteram16 = machine->generic.buffered_spriteram.u16;
if ((fgscrollx==0x1c9) || (twincobr_flip_screen && (fgscrollx==0x17a))) {
int wardner_hack = buffered_spriteram16[0x0b04/2];
if ((wardner_hack > 0x3900) && (wardner_hack < 0x8700)) {
wardner_hack = buffered_spriteram16[0x0b02/2];
wardner_hack |= 0x0400;
buffered_spriteram16[0x0b02/2] = wardner_hack;
wardner_hack = buffered_spriteram16[0x0b0a/2];
wardner_hack |= 0x0400;
buffered_spriteram16[0x0b0a/2] = wardner_hack;
wardner_hack = buffered_spriteram16[0x0b12/2];
wardner_hack |= 0x0400;
buffered_spriteram16[0x0b12/2] = wardner_hack;
wardner_hack = buffered_spriteram16[0x0b1a/2];
wardner_hack |= 0x0400;
buffered_spriteram16[0x0b1a/2] = wardner_hack;
}
}
}
} | [
"static",
"void",
"wardner_sprite_priority_hack",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"if",
"(",
"fgscrollx",
"!=",
"bgscrollx",
")",
"{",
"UINT16",
"*",
"buffered_spriteram16",
"=",
"machine",
"->",
"generic",
".",
"buffered_spriteram",
".",
"u16",
";",
"if",
"(",
"(",
"fgscrollx",
"==",
"0x1c9",
")",
"||",
"(",
"twincobr_flip_screen",
"&&",
"(",
"fgscrollx",
"==",
"0x17a",
")",
")",
")",
"{",
"int",
"wardner_hack",
"=",
"buffered_spriteram16",
"[",
"0x0b04",
"/",
"2",
"]",
";",
"if",
"(",
"(",
"wardner_hack",
">",
"0x3900",
")",
"&&",
"(",
"wardner_hack",
"<",
"0x8700",
")",
")",
"{",
"wardner_hack",
"=",
"buffered_spriteram16",
"[",
"0x0b02",
"/",
"2",
"]",
";",
"wardner_hack",
"|=",
"0x0400",
";",
"buffered_spriteram16",
"[",
"0x0b02",
"/",
"2",
"]",
"=",
"wardner_hack",
";",
"wardner_hack",
"=",
"buffered_spriteram16",
"[",
"0x0b0a",
"/",
"2",
"]",
";",
"wardner_hack",
"|=",
"0x0400",
";",
"buffered_spriteram16",
"[",
"0x0b0a",
"/",
"2",
"]",
"=",
"wardner_hack",
";",
"wardner_hack",
"=",
"buffered_spriteram16",
"[",
"0x0b12",
"/",
"2",
"]",
";",
"wardner_hack",
"|=",
"0x0400",
";",
"buffered_spriteram16",
"[",
"0x0b12",
"/",
"2",
"]",
"=",
"wardner_hack",
";",
"wardner_hack",
"=",
"buffered_spriteram16",
"[",
"0x0b1a",
"/",
"2",
"]",
";",
"wardner_hack",
"|=",
"0x0400",
";",
"buffered_spriteram16",
"[",
"0x0b1a",
"/",
"2",
"]",
"=",
"wardner_hack",
";",
"}",
"}",
"}",
"}"
] | Ugly sprite hack for Wardner when hero is in shop | [
"Ugly",
"sprite",
"hack",
"for",
"Wardner",
"when",
"hero",
"is",
"in",
"shop"
] | [
"/* in the shop ? */",
"/* sprite position 0x6300 to 0x8700 -- hero on shop keeper (normal) */",
"/* sprite position 0x3900 to 0x5e00 -- hero on shop keeper (flip) */",
"/* hero at shop keeper ? */",
"/* make hero top priority */"
] | [
{
"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": []
} |
e0e44514f65e075fdb1c82e90054c4aed821f99a | lofunz/mieme | Reloaded/trunk/src/mame/video/scotrsht.c | [
"Unlicense"
] | C | draw_sprites | void | static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect )
{
UINT8 *spriteram = machine->generic.spriteram.u8;
int i;
for (i = 0; i < machine->generic.spriteram_size; i += 4)
{
int attr = spriteram[i + 1]; // attributes = ?tyxcccc
int code = spriteram[i] + ((attr & 0x40) << 2);
int color = (attr & 0x0f) + scotrsht_palette_bank * 16;
int flipx = attr & 0x10;
int flipy = attr & 0x20;
int sx = spriteram[i + 2] - ((attr & 0x80) << 1);
int sy = spriteram[i + 3];
if (flip_screen_get(machine))
{
sx = 240 - sx;
sy = 240 - sy;
flipx = !flipx;
flipy = !flipy;
}
drawgfx_transmask(bitmap, cliprect, machine->gfx[1], code, color, flipx, flipy,
sx, sy,
colortable_get_transpen_mask(machine->colortable, machine->gfx[1], color, scotrsht_palette_bank * 16));
}
} | /* Same as Jailbreak + palette bank */ | Same as Jailbreak + palette bank | [
"Same",
"as",
"Jailbreak",
"+",
"palette",
"bank"
] | static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect )
{
UINT8 *spriteram = machine->generic.spriteram.u8;
int i;
for (i = 0; i < machine->generic.spriteram_size; i += 4)
{
int attr = spriteram[i + 1];
int code = spriteram[i] + ((attr & 0x40) << 2);
int color = (attr & 0x0f) + scotrsht_palette_bank * 16;
int flipx = attr & 0x10;
int flipy = attr & 0x20;
int sx = spriteram[i + 2] - ((attr & 0x80) << 1);
int sy = spriteram[i + 3];
if (flip_screen_get(machine))
{
sx = 240 - sx;
sy = 240 - sy;
flipx = !flipx;
flipy = !flipy;
}
drawgfx_transmask(bitmap, cliprect, machine->gfx[1], code, color, flipx, flipy,
sx, sy,
colortable_get_transpen_mask(machine->colortable, machine->gfx[1], color, scotrsht_palette_bank * 16));
}
} | [
"static",
"void",
"draw_sprites",
"(",
"running_machine",
"*",
"machine",
",",
"bitmap_t",
"*",
"bitmap",
",",
"const",
"rectangle",
"*",
"cliprect",
")",
"{",
"UINT8",
"*",
"spriteram",
"=",
"machine",
"->",
"generic",
".",
"spriteram",
".",
"u8",
";",
"int",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"machine",
"->",
"generic",
".",
"spriteram_size",
";",
"i",
"+=",
"4",
")",
"{",
"int",
"attr",
"=",
"spriteram",
"[",
"i",
"+",
"1",
"]",
";",
"int",
"code",
"=",
"spriteram",
"[",
"i",
"]",
"+",
"(",
"(",
"attr",
"&",
"0x40",
")",
"<<",
"2",
")",
";",
"int",
"color",
"=",
"(",
"attr",
"&",
"0x0f",
")",
"+",
"scotrsht_palette_bank",
"*",
"16",
";",
"int",
"flipx",
"=",
"attr",
"&",
"0x10",
";",
"int",
"flipy",
"=",
"attr",
"&",
"0x20",
";",
"int",
"sx",
"=",
"spriteram",
"[",
"i",
"+",
"2",
"]",
"-",
"(",
"(",
"attr",
"&",
"0x80",
")",
"<<",
"1",
")",
";",
"int",
"sy",
"=",
"spriteram",
"[",
"i",
"+",
"3",
"]",
";",
"if",
"(",
"flip_screen_get",
"(",
"machine",
")",
")",
"{",
"sx",
"=",
"240",
"-",
"sx",
";",
"sy",
"=",
"240",
"-",
"sy",
";",
"flipx",
"=",
"!",
"flipx",
";",
"flipy",
"=",
"!",
"flipy",
";",
"}",
"drawgfx_transmask",
"(",
"bitmap",
",",
"cliprect",
",",
"machine",
"->",
"gfx",
"[",
"1",
"]",
",",
"code",
",",
"color",
",",
"flipx",
",",
"flipy",
",",
"sx",
",",
"sy",
",",
"colortable_get_transpen_mask",
"(",
"machine",
"->",
"colortable",
",",
"machine",
"->",
"gfx",
"[",
"1",
"]",
",",
"color",
",",
"scotrsht_palette_bank",
"*",
"16",
")",
")",
";",
"}",
"}"
] | Same as Jailbreak + palette bank | [
"Same",
"as",
"Jailbreak",
"+",
"palette",
"bank"
] | [
"// attributes = ?tyxcccc\r"
] | [
{
"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": []
} |
e07ead8b17b38d2e3608921ed286d7d83f88f6c3 | lofunz/mieme | Reloaded/trunk/src/lib/util/jedparse.c | [
"Unlicense"
] | C | suck_number | UINT32 | static UINT32 suck_number(const UINT8 **psrc)
{
const UINT8 *src = *psrc;
UINT32 value = 0;
/* skip delimiters */
while (isdelim(*src))
src++;
/* loop over and accumulate digits */
while (isdigit(*src))
{
value = value * 10 + *src - '0';
src++;
}
/* return a pointer to the string afterwards */
*psrc = src;
return value;
} | /*-------------------------------------------------
suck_number - read a decimal value from the
character stream
-------------------------------------------------*/ | read a decimal value from the
character stream | [
"read",
"a",
"decimal",
"value",
"from",
"the",
"character",
"stream"
] | static UINT32 suck_number(const UINT8 **psrc)
{
const UINT8 *src = *psrc;
UINT32 value = 0;
while (isdelim(*src))
src++;
while (isdigit(*src))
{
value = value * 10 + *src - '0';
src++;
}
*psrc = src;
return value;
} | [
"static",
"UINT32",
"suck_number",
"(",
"const",
"UINT8",
"*",
"*",
"psrc",
")",
"{",
"const",
"UINT8",
"*",
"src",
"=",
"*",
"psrc",
";",
"UINT32",
"value",
"=",
"0",
";",
"while",
"(",
"isdelim",
"(",
"*",
"src",
")",
")",
"src",
"++",
";",
"while",
"(",
"isdigit",
"(",
"*",
"src",
")",
")",
"{",
"value",
"=",
"value",
"*",
"10",
"+",
"*",
"src",
"-",
"'",
"'",
";",
"src",
"++",
";",
"}",
"*",
"psrc",
"=",
"src",
";",
"return",
"value",
";",
"}"
] | suck_number - read a decimal value from the
character stream | [
"suck_number",
"-",
"read",
"a",
"decimal",
"value",
"from",
"the",
"character",
"stream"
] | [
"/* skip delimiters */",
"/* loop over and accumulate digits */",
"/* return a pointer to the string afterwards */"
] | [
{
"param": "psrc",
"type": "UINT8"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "psrc",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e07ead8b17b38d2e3608921ed286d7d83f88f6c3 | lofunz/mieme | Reloaded/trunk/src/lib/util/jedparse.c | [
"Unlicense"
] | C | jed_parse | int | int jed_parse(const void *data, size_t length, jed_data *result)
{
const UINT8 *cursrc = (const UINT8 *)data;
const UINT8 *srcend = cursrc + length;
const UINT8 *scan;
parse_info pinfo;
UINT16 checksum;
int i;
/* initialize the output and the intermediate info struct */
memset(result, 0, sizeof(*result));
memset(&pinfo, 0, sizeof(pinfo));
/* first scan for the STX character; ignore anything prior */
while (cursrc < srcend && *cursrc != 0x02)
cursrc++;
if (cursrc >= srcend)
return JEDERR_INVALID_DATA;
/* then scan to see if we have an ETX */
scan = cursrc;
checksum = 0;
while (scan < srcend && *scan != 0x03)
checksum += *scan++ & 0x7f;
if (scan >= srcend)
return JEDERR_INVALID_DATA;
/* see if there is a transmission checksum at the end */
checksum += *scan;
if (scan + 4 < srcend && ishex(scan[1]) && ishex(scan[2]) && ishex(scan[3]) && ishex(scan[4]))
{
UINT16 dessum = (hexval(scan[1]) << 12) | (hexval(scan[2]) << 8) | (hexval(scan[3]) << 4) | hexval(scan[4] << 0);
if (dessum != 0 && dessum != checksum)
return JEDERR_BAD_XMIT_SUM;
}
/* the ETX becomes the real srcend */
srcend = scan;
/* blast through the comment field */
cursrc++;
while (cursrc < srcend && *cursrc != '*')
cursrc++;
/* now loop over fields and decide which ones go in the file output */
cursrc++;
while (cursrc < srcend)
{
/* skip over delimiters */
while (cursrc < srcend && isdelim(*cursrc))
cursrc++;
if (cursrc >= srcend)
break;
/* end of field is an asterisk -- find it */
scan = cursrc;
while (scan < srcend && *scan != '*')
scan++;
if (scan >= srcend)
return JEDERR_INVALID_DATA;
/* process the field */
process_field(result, cursrc, scan, &pinfo);
/* advance past it */
cursrc = scan + 1;
}
/* if we got an explicit fuse count, override our computed count */
if (pinfo.explicit_numfuses != 0)
result->numfuses = pinfo.explicit_numfuses;
/* clear out leftover bits */
if (result->numfuses % 8 != 0)
result->fusemap[result->numfuses / 8] &= (1 << (result->numfuses % 8)) - 1;
memset(&result->fusemap[(result->numfuses + 7) / 8], 0, sizeof(result->fusemap) - (result->numfuses + 7) / 8);
/* validate the checksum */
checksum = 0;
for (i = 0; i < (result->numfuses + 7) / 8; i++)
checksum += result->fusemap[i];
if (pinfo.checksum != 0 && checksum != pinfo.checksum)
return JEDERR_BAD_FUSE_SUM;
return JEDERR_NONE;
} | /*-------------------------------------------------
jed_parse - parse a .JED file that has been
loaded raw into memory
-------------------------------------------------*/ | parse a .JED file that has been
loaded raw into memory | [
"parse",
"a",
".",
"JED",
"file",
"that",
"has",
"been",
"loaded",
"raw",
"into",
"memory"
] | int jed_parse(const void *data, size_t length, jed_data *result)
{
const UINT8 *cursrc = (const UINT8 *)data;
const UINT8 *srcend = cursrc + length;
const UINT8 *scan;
parse_info pinfo;
UINT16 checksum;
int i;
memset(result, 0, sizeof(*result));
memset(&pinfo, 0, sizeof(pinfo));
while (cursrc < srcend && *cursrc != 0x02)
cursrc++;
if (cursrc >= srcend)
return JEDERR_INVALID_DATA;
scan = cursrc;
checksum = 0;
while (scan < srcend && *scan != 0x03)
checksum += *scan++ & 0x7f;
if (scan >= srcend)
return JEDERR_INVALID_DATA;
checksum += *scan;
if (scan + 4 < srcend && ishex(scan[1]) && ishex(scan[2]) && ishex(scan[3]) && ishex(scan[4]))
{
UINT16 dessum = (hexval(scan[1]) << 12) | (hexval(scan[2]) << 8) | (hexval(scan[3]) << 4) | hexval(scan[4] << 0);
if (dessum != 0 && dessum != checksum)
return JEDERR_BAD_XMIT_SUM;
}
srcend = scan;
cursrc++;
while (cursrc < srcend && *cursrc != '*')
cursrc++;
cursrc++;
while (cursrc < srcend)
{
while (cursrc < srcend && isdelim(*cursrc))
cursrc++;
if (cursrc >= srcend)
break;
scan = cursrc;
while (scan < srcend && *scan != '*')
scan++;
if (scan >= srcend)
return JEDERR_INVALID_DATA;
process_field(result, cursrc, scan, &pinfo);
cursrc = scan + 1;
}
if (pinfo.explicit_numfuses != 0)
result->numfuses = pinfo.explicit_numfuses;
if (result->numfuses % 8 != 0)
result->fusemap[result->numfuses / 8] &= (1 << (result->numfuses % 8)) - 1;
memset(&result->fusemap[(result->numfuses + 7) / 8], 0, sizeof(result->fusemap) - (result->numfuses + 7) / 8);
checksum = 0;
for (i = 0; i < (result->numfuses + 7) / 8; i++)
checksum += result->fusemap[i];
if (pinfo.checksum != 0 && checksum != pinfo.checksum)
return JEDERR_BAD_FUSE_SUM;
return JEDERR_NONE;
} | [
"int",
"jed_parse",
"(",
"const",
"void",
"*",
"data",
",",
"size_t",
"length",
",",
"jed_data",
"*",
"result",
")",
"{",
"const",
"UINT8",
"*",
"cursrc",
"=",
"(",
"const",
"UINT8",
"*",
")",
"data",
";",
"const",
"UINT8",
"*",
"srcend",
"=",
"cursrc",
"+",
"length",
";",
"const",
"UINT8",
"*",
"scan",
";",
"parse_info",
"pinfo",
";",
"UINT16",
"checksum",
";",
"int",
"i",
";",
"memset",
"(",
"result",
",",
"0",
",",
"sizeof",
"(",
"*",
"result",
")",
")",
";",
"memset",
"(",
"&",
"pinfo",
",",
"0",
",",
"sizeof",
"(",
"pinfo",
")",
")",
";",
"while",
"(",
"cursrc",
"<",
"srcend",
"&&",
"*",
"cursrc",
"!=",
"0x02",
")",
"cursrc",
"++",
";",
"if",
"(",
"cursrc",
">=",
"srcend",
")",
"return",
"JEDERR_INVALID_DATA",
";",
"scan",
"=",
"cursrc",
";",
"checksum",
"=",
"0",
";",
"while",
"(",
"scan",
"<",
"srcend",
"&&",
"*",
"scan",
"!=",
"0x03",
")",
"checksum",
"+=",
"*",
"scan",
"++",
"&",
"0x7f",
";",
"if",
"(",
"scan",
">=",
"srcend",
")",
"return",
"JEDERR_INVALID_DATA",
";",
"checksum",
"+=",
"*",
"scan",
";",
"if",
"(",
"scan",
"+",
"4",
"<",
"srcend",
"&&",
"ishex",
"(",
"scan",
"[",
"1",
"]",
")",
"&&",
"ishex",
"(",
"scan",
"[",
"2",
"]",
")",
"&&",
"ishex",
"(",
"scan",
"[",
"3",
"]",
")",
"&&",
"ishex",
"(",
"scan",
"[",
"4",
"]",
")",
")",
"{",
"UINT16",
"dessum",
"=",
"(",
"hexval",
"(",
"scan",
"[",
"1",
"]",
")",
"<<",
"12",
")",
"|",
"(",
"hexval",
"(",
"scan",
"[",
"2",
"]",
")",
"<<",
"8",
")",
"|",
"(",
"hexval",
"(",
"scan",
"[",
"3",
"]",
")",
"<<",
"4",
")",
"|",
"hexval",
"(",
"scan",
"[",
"4",
"]",
"<<",
"0",
")",
";",
"if",
"(",
"dessum",
"!=",
"0",
"&&",
"dessum",
"!=",
"checksum",
")",
"return",
"JEDERR_BAD_XMIT_SUM",
";",
"}",
"srcend",
"=",
"scan",
";",
"cursrc",
"++",
";",
"while",
"(",
"cursrc",
"<",
"srcend",
"&&",
"*",
"cursrc",
"!=",
"'",
"'",
")",
"cursrc",
"++",
";",
"cursrc",
"++",
";",
"while",
"(",
"cursrc",
"<",
"srcend",
")",
"{",
"while",
"(",
"cursrc",
"<",
"srcend",
"&&",
"isdelim",
"(",
"*",
"cursrc",
")",
")",
"cursrc",
"++",
";",
"if",
"(",
"cursrc",
">=",
"srcend",
")",
"break",
";",
"scan",
"=",
"cursrc",
";",
"while",
"(",
"scan",
"<",
"srcend",
"&&",
"*",
"scan",
"!=",
"'",
"'",
")",
"scan",
"++",
";",
"if",
"(",
"scan",
">=",
"srcend",
")",
"return",
"JEDERR_INVALID_DATA",
";",
"process_field",
"(",
"result",
",",
"cursrc",
",",
"scan",
",",
"&",
"pinfo",
")",
";",
"cursrc",
"=",
"scan",
"+",
"1",
";",
"}",
"if",
"(",
"pinfo",
".",
"explicit_numfuses",
"!=",
"0",
")",
"result",
"->",
"numfuses",
"=",
"pinfo",
".",
"explicit_numfuses",
";",
"if",
"(",
"result",
"->",
"numfuses",
"%",
"8",
"!=",
"0",
")",
"result",
"->",
"fusemap",
"[",
"result",
"->",
"numfuses",
"/",
"8",
"]",
"&=",
"(",
"1",
"<<",
"(",
"result",
"->",
"numfuses",
"%",
"8",
")",
")",
"-",
"1",
";",
"memset",
"(",
"&",
"result",
"->",
"fusemap",
"[",
"(",
"result",
"->",
"numfuses",
"+",
"7",
")",
"/",
"8",
"]",
",",
"0",
",",
"sizeof",
"(",
"result",
"->",
"fusemap",
")",
"-",
"(",
"result",
"->",
"numfuses",
"+",
"7",
")",
"/",
"8",
")",
";",
"checksum",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"(",
"result",
"->",
"numfuses",
"+",
"7",
")",
"/",
"8",
";",
"i",
"++",
")",
"checksum",
"+=",
"result",
"->",
"fusemap",
"[",
"i",
"]",
";",
"if",
"(",
"pinfo",
".",
"checksum",
"!=",
"0",
"&&",
"checksum",
"!=",
"pinfo",
".",
"checksum",
")",
"return",
"JEDERR_BAD_FUSE_SUM",
";",
"return",
"JEDERR_NONE",
";",
"}"
] | jed_parse - parse a .JED file that has been
loaded raw into memory | [
"jed_parse",
"-",
"parse",
"a",
".",
"JED",
"file",
"that",
"has",
"been",
"loaded",
"raw",
"into",
"memory"
] | [
"/* initialize the output and the intermediate info struct */",
"/* first scan for the STX character; ignore anything prior */",
"/* then scan to see if we have an ETX */",
"/* see if there is a transmission checksum at the end */",
"/* the ETX becomes the real srcend */",
"/* blast through the comment field */",
"/* now loop over fields and decide which ones go in the file output */",
"/* skip over delimiters */",
"/* end of field is an asterisk -- find it */",
"/* process the field */",
"/* advance past it */",
"/* if we got an explicit fuse count, override our computed count */",
"/* clear out leftover bits */",
"/* validate the checksum */"
] | [
{
"param": "data",
"type": "void"
},
{
"param": "length",
"type": "size_t"
},
{
"param": "result",
"type": "jed_data"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "data",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "length",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "result",
"type": "jed_data",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e07ead8b17b38d2e3608921ed286d7d83f88f6c3 | lofunz/mieme | Reloaded/trunk/src/lib/util/jedparse.c | [
"Unlicense"
] | C | jed_output | size_t | size_t jed_output(const jed_data *data, void *result, size_t length)
{
UINT8 *curdst = (UINT8 *)result;
UINT8 *dstend = curdst + length;
int i, zeros, ones;
char tempbuf[256];
UINT16 checksum;
UINT8 defbyte;
UINT8 *temp;
/* always start the DST with a standard header and an STX */
tempbuf[0] = 0x02;
sprintf(&tempbuf[1], "JEDEC file generated by jedutil*\n");
if (curdst + strlen(tempbuf) <= dstend)
memcpy(curdst, tempbuf, strlen(tempbuf));
curdst += strlen(tempbuf);
/* append the package information */
sprintf(tempbuf, "QF%d*\n", data->numfuses);
if (curdst + strlen(tempbuf) <= dstend)
memcpy(curdst, tempbuf, strlen(tempbuf));
curdst += strlen(tempbuf);
/* compute the checksum */
checksum = 0;
for (i = 0; i < data->numfuses / 8; i++)
checksum += data->fusemap[i];
if (data->numfuses % 8 != 0)
checksum += data->fusemap[data->numfuses / 8] & ((1 << (data->numfuses % 8)) - 1);
/* determine if we are mostly 0's or mostly 1's */
for (i = zeros = ones = 0; i < data->numfuses / 8; i++)
if (data->fusemap[i] == 0x00)
zeros++;
else if (data->fusemap[i] == 0xff)
ones++;
defbyte = (ones > zeros) ? 0xff : 0x00;
/* output the default fuse state */
sprintf(tempbuf, "F%d*\n", defbyte & 1);
if (curdst + strlen(tempbuf) <= dstend)
memcpy(curdst, tempbuf, strlen(tempbuf));
curdst += strlen(tempbuf);
/* now loop over groups of 32 fuses and output non-default groups */
for (i = 0; i < data->numfuses; i += 32)
if (data->fusemap[i / 8 + 0] != defbyte ||
data->fusemap[i / 8 + 1] != defbyte ||
data->fusemap[i / 8 + 2] != defbyte ||
data->fusemap[i / 8 + 3] != defbyte)
{
int stroffs;
int j;
/* build up a string of 32 fuses */
stroffs = sprintf(tempbuf, "L%05d ", i);
for (j = 0; j < 32 && i+j < data->numfuses; j++)
tempbuf[stroffs++] = '0' + jed_get_fuse(data, i + j);
stroffs += sprintf(&tempbuf[stroffs], "*\n");
/* append to the buffer */
if (curdst + strlen(tempbuf) <= dstend)
memcpy(curdst, tempbuf, strlen(tempbuf));
curdst += strlen(tempbuf);
}
/* write the checksum */
sprintf(tempbuf, "C%04X*\n", checksum);
if (curdst + strlen(tempbuf) <= dstend)
memcpy(curdst, tempbuf, strlen(tempbuf));
curdst += strlen(tempbuf);
/* now compute the transmission checksum */
checksum = 0;
for (temp = (UINT8 *)result; temp < curdst && temp < dstend; temp++)
checksum += *temp & 0x7f;
checksum += 0x03;
/* append the ETX and the transmission checksum */
tempbuf[0] = 0x03;
sprintf(&tempbuf[1], "%04X", checksum);
if (curdst + strlen(tempbuf) <= dstend)
memcpy(curdst, tempbuf, strlen(tempbuf));
curdst += strlen(tempbuf);
/* return the final size */
return curdst - (UINT8 *)result;
} | /*-------------------------------------------------
jed_output - generate a new .JED file based
on the jed_data provided
-------------------------------------------------*/ | generate a new .JED file based
on the jed_data provided | [
"generate",
"a",
"new",
".",
"JED",
"file",
"based",
"on",
"the",
"jed_data",
"provided"
] | size_t jed_output(const jed_data *data, void *result, size_t length)
{
UINT8 *curdst = (UINT8 *)result;
UINT8 *dstend = curdst + length;
int i, zeros, ones;
char tempbuf[256];
UINT16 checksum;
UINT8 defbyte;
UINT8 *temp;
tempbuf[0] = 0x02;
sprintf(&tempbuf[1], "JEDEC file generated by jedutil*\n");
if (curdst + strlen(tempbuf) <= dstend)
memcpy(curdst, tempbuf, strlen(tempbuf));
curdst += strlen(tempbuf);
sprintf(tempbuf, "QF%d*\n", data->numfuses);
if (curdst + strlen(tempbuf) <= dstend)
memcpy(curdst, tempbuf, strlen(tempbuf));
curdst += strlen(tempbuf);
checksum = 0;
for (i = 0; i < data->numfuses / 8; i++)
checksum += data->fusemap[i];
if (data->numfuses % 8 != 0)
checksum += data->fusemap[data->numfuses / 8] & ((1 << (data->numfuses % 8)) - 1);
for (i = zeros = ones = 0; i < data->numfuses / 8; i++)
if (data->fusemap[i] == 0x00)
zeros++;
else if (data->fusemap[i] == 0xff)
ones++;
defbyte = (ones > zeros) ? 0xff : 0x00;
sprintf(tempbuf, "F%d*\n", defbyte & 1);
if (curdst + strlen(tempbuf) <= dstend)
memcpy(curdst, tempbuf, strlen(tempbuf));
curdst += strlen(tempbuf);
for (i = 0; i < data->numfuses; i += 32)
if (data->fusemap[i / 8 + 0] != defbyte ||
data->fusemap[i / 8 + 1] != defbyte ||
data->fusemap[i / 8 + 2] != defbyte ||
data->fusemap[i / 8 + 3] != defbyte)
{
int stroffs;
int j;
stroffs = sprintf(tempbuf, "L%05d ", i);
for (j = 0; j < 32 && i+j < data->numfuses; j++)
tempbuf[stroffs++] = '0' + jed_get_fuse(data, i + j);
stroffs += sprintf(&tempbuf[stroffs], "*\n");
if (curdst + strlen(tempbuf) <= dstend)
memcpy(curdst, tempbuf, strlen(tempbuf));
curdst += strlen(tempbuf);
}
sprintf(tempbuf, "C%04X*\n", checksum);
if (curdst + strlen(tempbuf) <= dstend)
memcpy(curdst, tempbuf, strlen(tempbuf));
curdst += strlen(tempbuf);
checksum = 0;
for (temp = (UINT8 *)result; temp < curdst && temp < dstend; temp++)
checksum += *temp & 0x7f;
checksum += 0x03;
tempbuf[0] = 0x03;
sprintf(&tempbuf[1], "%04X", checksum);
if (curdst + strlen(tempbuf) <= dstend)
memcpy(curdst, tempbuf, strlen(tempbuf));
curdst += strlen(tempbuf);
return curdst - (UINT8 *)result;
} | [
"size_t",
"jed_output",
"(",
"const",
"jed_data",
"*",
"data",
",",
"void",
"*",
"result",
",",
"size_t",
"length",
")",
"{",
"UINT8",
"*",
"curdst",
"=",
"(",
"UINT8",
"*",
")",
"result",
";",
"UINT8",
"*",
"dstend",
"=",
"curdst",
"+",
"length",
";",
"int",
"i",
",",
"zeros",
",",
"ones",
";",
"char",
"tempbuf",
"[",
"256",
"]",
";",
"UINT16",
"checksum",
";",
"UINT8",
"defbyte",
";",
"UINT8",
"*",
"temp",
";",
"tempbuf",
"[",
"0",
"]",
"=",
"0x02",
";",
"sprintf",
"(",
"&",
"tempbuf",
"[",
"1",
"]",
",",
"\"",
"\\n",
"\"",
")",
";",
"if",
"(",
"curdst",
"+",
"strlen",
"(",
"tempbuf",
")",
"<=",
"dstend",
")",
"memcpy",
"(",
"curdst",
",",
"tempbuf",
",",
"strlen",
"(",
"tempbuf",
")",
")",
";",
"curdst",
"+=",
"strlen",
"(",
"tempbuf",
")",
";",
"sprintf",
"(",
"tempbuf",
",",
"\"",
"\\n",
"\"",
",",
"data",
"->",
"numfuses",
")",
";",
"if",
"(",
"curdst",
"+",
"strlen",
"(",
"tempbuf",
")",
"<=",
"dstend",
")",
"memcpy",
"(",
"curdst",
",",
"tempbuf",
",",
"strlen",
"(",
"tempbuf",
")",
")",
";",
"curdst",
"+=",
"strlen",
"(",
"tempbuf",
")",
";",
"checksum",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"data",
"->",
"numfuses",
"/",
"8",
";",
"i",
"++",
")",
"checksum",
"+=",
"data",
"->",
"fusemap",
"[",
"i",
"]",
";",
"if",
"(",
"data",
"->",
"numfuses",
"%",
"8",
"!=",
"0",
")",
"checksum",
"+=",
"data",
"->",
"fusemap",
"[",
"data",
"->",
"numfuses",
"/",
"8",
"]",
"&",
"(",
"(",
"1",
"<<",
"(",
"data",
"->",
"numfuses",
"%",
"8",
")",
")",
"-",
"1",
")",
";",
"for",
"(",
"i",
"=",
"zeros",
"=",
"ones",
"=",
"0",
";",
"i",
"<",
"data",
"->",
"numfuses",
"/",
"8",
";",
"i",
"++",
")",
"if",
"(",
"data",
"->",
"fusemap",
"[",
"i",
"]",
"==",
"0x00",
")",
"zeros",
"++",
";",
"else",
"if",
"(",
"data",
"->",
"fusemap",
"[",
"i",
"]",
"==",
"0xff",
")",
"ones",
"++",
";",
"defbyte",
"=",
"(",
"ones",
">",
"zeros",
")",
"?",
"0xff",
":",
"0x00",
";",
"sprintf",
"(",
"tempbuf",
",",
"\"",
"\\n",
"\"",
",",
"defbyte",
"&",
"1",
")",
";",
"if",
"(",
"curdst",
"+",
"strlen",
"(",
"tempbuf",
")",
"<=",
"dstend",
")",
"memcpy",
"(",
"curdst",
",",
"tempbuf",
",",
"strlen",
"(",
"tempbuf",
")",
")",
";",
"curdst",
"+=",
"strlen",
"(",
"tempbuf",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"data",
"->",
"numfuses",
";",
"i",
"+=",
"32",
")",
"if",
"(",
"data",
"->",
"fusemap",
"[",
"i",
"/",
"8",
"+",
"0",
"]",
"!=",
"defbyte",
"||",
"data",
"->",
"fusemap",
"[",
"i",
"/",
"8",
"+",
"1",
"]",
"!=",
"defbyte",
"||",
"data",
"->",
"fusemap",
"[",
"i",
"/",
"8",
"+",
"2",
"]",
"!=",
"defbyte",
"||",
"data",
"->",
"fusemap",
"[",
"i",
"/",
"8",
"+",
"3",
"]",
"!=",
"defbyte",
")",
"{",
"int",
"stroffs",
";",
"int",
"j",
";",
"stroffs",
"=",
"sprintf",
"(",
"tempbuf",
",",
"\"",
"\"",
",",
"i",
")",
";",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"32",
"&&",
"i",
"+",
"j",
"<",
"data",
"->",
"numfuses",
";",
"j",
"++",
")",
"tempbuf",
"[",
"stroffs",
"++",
"]",
"=",
"'",
"'",
"+",
"jed_get_fuse",
"(",
"data",
",",
"i",
"+",
"j",
")",
";",
"stroffs",
"+=",
"sprintf",
"(",
"&",
"tempbuf",
"[",
"stroffs",
"]",
",",
"\"",
"\\n",
"\"",
")",
";",
"if",
"(",
"curdst",
"+",
"strlen",
"(",
"tempbuf",
")",
"<=",
"dstend",
")",
"memcpy",
"(",
"curdst",
",",
"tempbuf",
",",
"strlen",
"(",
"tempbuf",
")",
")",
";",
"curdst",
"+=",
"strlen",
"(",
"tempbuf",
")",
";",
"}",
"sprintf",
"(",
"tempbuf",
",",
"\"",
"\\n",
"\"",
",",
"checksum",
")",
";",
"if",
"(",
"curdst",
"+",
"strlen",
"(",
"tempbuf",
")",
"<=",
"dstend",
")",
"memcpy",
"(",
"curdst",
",",
"tempbuf",
",",
"strlen",
"(",
"tempbuf",
")",
")",
";",
"curdst",
"+=",
"strlen",
"(",
"tempbuf",
")",
";",
"checksum",
"=",
"0",
";",
"for",
"(",
"temp",
"=",
"(",
"UINT8",
"*",
")",
"result",
";",
"temp",
"<",
"curdst",
"&&",
"temp",
"<",
"dstend",
";",
"temp",
"++",
")",
"checksum",
"+=",
"*",
"temp",
"&",
"0x7f",
";",
"checksum",
"+=",
"0x03",
";",
"tempbuf",
"[",
"0",
"]",
"=",
"0x03",
";",
"sprintf",
"(",
"&",
"tempbuf",
"[",
"1",
"]",
",",
"\"",
"\"",
",",
"checksum",
")",
";",
"if",
"(",
"curdst",
"+",
"strlen",
"(",
"tempbuf",
")",
"<=",
"dstend",
")",
"memcpy",
"(",
"curdst",
",",
"tempbuf",
",",
"strlen",
"(",
"tempbuf",
")",
")",
";",
"curdst",
"+=",
"strlen",
"(",
"tempbuf",
")",
";",
"return",
"curdst",
"-",
"(",
"UINT8",
"*",
")",
"result",
";",
"}"
] | jed_output - generate a new .JED file based
on the jed_data provided | [
"jed_output",
"-",
"generate",
"a",
"new",
".",
"JED",
"file",
"based",
"on",
"the",
"jed_data",
"provided"
] | [
"/* always start the DST with a standard header and an STX */",
"/* append the package information */",
"/* compute the checksum */",
"/* determine if we are mostly 0's or mostly 1's */",
"/* output the default fuse state */",
"/* now loop over groups of 32 fuses and output non-default groups */",
"/* build up a string of 32 fuses */",
"/* append to the buffer */",
"/* write the checksum */",
"/* now compute the transmission checksum */",
"/* append the ETX and the transmission checksum */",
"/* return the final size */"
] | [
{
"param": "data",
"type": "jed_data"
},
{
"param": "result",
"type": "void"
},
{
"param": "length",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "data",
"type": "jed_data",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "result",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "length",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e07ead8b17b38d2e3608921ed286d7d83f88f6c3 | lofunz/mieme | Reloaded/trunk/src/lib/util/jedparse.c | [
"Unlicense"
] | C | jedbin_parse | int | int jedbin_parse(const void *data, size_t length, jed_data *result)
{
const UINT8 *cursrc = (const UINT8 *)data;
/* initialize the output */
memset(result, 0, sizeof(*result));
/* need at least 4 bytes */
if (length < 4)
return JEDERR_INVALID_DATA;
/* first unpack the number of fuses */
result->numfuses = (cursrc[0] << 24) | (cursrc[1] << 16) | (cursrc[2] << 8) | cursrc[3];
cursrc += 4;
if (result->numfuses == 0 || result->numfuses > JED_MAX_FUSES)
return JEDERR_INVALID_DATA;
/* now make sure we have enough data in the source */
if (length < 4 + (result->numfuses + 7) / 8)
return JEDERR_INVALID_DATA;
/* copy in the data */
memcpy(result->fusemap, cursrc, (result->numfuses + 7) / 8);
return JEDERR_NONE;
} | /*-------------------------------------------------
jedbin_parse - parse a binary JED file that
has been loaded raw into memory
-------------------------------------------------*/ | parse a binary JED file that
has been loaded raw into memory | [
"parse",
"a",
"binary",
"JED",
"file",
"that",
"has",
"been",
"loaded",
"raw",
"into",
"memory"
] | int jedbin_parse(const void *data, size_t length, jed_data *result)
{
const UINT8 *cursrc = (const UINT8 *)data;
memset(result, 0, sizeof(*result));
if (length < 4)
return JEDERR_INVALID_DATA;
result->numfuses = (cursrc[0] << 24) | (cursrc[1] << 16) | (cursrc[2] << 8) | cursrc[3];
cursrc += 4;
if (result->numfuses == 0 || result->numfuses > JED_MAX_FUSES)
return JEDERR_INVALID_DATA;
if (length < 4 + (result->numfuses + 7) / 8)
return JEDERR_INVALID_DATA;
memcpy(result->fusemap, cursrc, (result->numfuses + 7) / 8);
return JEDERR_NONE;
} | [
"int",
"jedbin_parse",
"(",
"const",
"void",
"*",
"data",
",",
"size_t",
"length",
",",
"jed_data",
"*",
"result",
")",
"{",
"const",
"UINT8",
"*",
"cursrc",
"=",
"(",
"const",
"UINT8",
"*",
")",
"data",
";",
"memset",
"(",
"result",
",",
"0",
",",
"sizeof",
"(",
"*",
"result",
")",
")",
";",
"if",
"(",
"length",
"<",
"4",
")",
"return",
"JEDERR_INVALID_DATA",
";",
"result",
"->",
"numfuses",
"=",
"(",
"cursrc",
"[",
"0",
"]",
"<<",
"24",
")",
"|",
"(",
"cursrc",
"[",
"1",
"]",
"<<",
"16",
")",
"|",
"(",
"cursrc",
"[",
"2",
"]",
"<<",
"8",
")",
"|",
"cursrc",
"[",
"3",
"]",
";",
"cursrc",
"+=",
"4",
";",
"if",
"(",
"result",
"->",
"numfuses",
"==",
"0",
"||",
"result",
"->",
"numfuses",
">",
"JED_MAX_FUSES",
")",
"return",
"JEDERR_INVALID_DATA",
";",
"if",
"(",
"length",
"<",
"4",
"+",
"(",
"result",
"->",
"numfuses",
"+",
"7",
")",
"/",
"8",
")",
"return",
"JEDERR_INVALID_DATA",
";",
"memcpy",
"(",
"result",
"->",
"fusemap",
",",
"cursrc",
",",
"(",
"result",
"->",
"numfuses",
"+",
"7",
")",
"/",
"8",
")",
";",
"return",
"JEDERR_NONE",
";",
"}"
] | jedbin_parse - parse a binary JED file that
has been loaded raw into memory | [
"jedbin_parse",
"-",
"parse",
"a",
"binary",
"JED",
"file",
"that",
"has",
"been",
"loaded",
"raw",
"into",
"memory"
] | [
"/* initialize the output */",
"/* need at least 4 bytes */",
"/* first unpack the number of fuses */",
"/* now make sure we have enough data in the source */",
"/* copy in the data */"
] | [
{
"param": "data",
"type": "void"
},
{
"param": "length",
"type": "size_t"
},
{
"param": "result",
"type": "jed_data"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "data",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "length",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "result",
"type": "jed_data",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e07ead8b17b38d2e3608921ed286d7d83f88f6c3 | lofunz/mieme | Reloaded/trunk/src/lib/util/jedparse.c | [
"Unlicense"
] | C | jedbin_output | size_t | size_t jedbin_output(const jed_data *data, void *result, size_t length)
{
UINT8 *curdst = (UINT8 *)result;
/* ensure we have enough room */
if (length >= 4 + (data->numfuses + 7) / 8)
{
/* store the number of fuses */
*curdst++ = data->numfuses >> 24;
*curdst++ = data->numfuses >> 16;
*curdst++ = data->numfuses >> 8;
*curdst++ = data->numfuses >> 0;
/* copy in the rest of the data */
memcpy(curdst, data->fusemap, (data->numfuses + 7) / 8);
}
/* return the final size */
return 4 + (data->numfuses + 7) / 8;
} | /*-------------------------------------------------
jedbin_output - generate a new binary JED file
based on the jed_data provided
-------------------------------------------------*/ | generate a new binary JED file
based on the jed_data provided | [
"generate",
"a",
"new",
"binary",
"JED",
"file",
"based",
"on",
"the",
"jed_data",
"provided"
] | size_t jedbin_output(const jed_data *data, void *result, size_t length)
{
UINT8 *curdst = (UINT8 *)result;
if (length >= 4 + (data->numfuses + 7) / 8)
{
*curdst++ = data->numfuses >> 24;
*curdst++ = data->numfuses >> 16;
*curdst++ = data->numfuses >> 8;
*curdst++ = data->numfuses >> 0;
memcpy(curdst, data->fusemap, (data->numfuses + 7) / 8);
}
return 4 + (data->numfuses + 7) / 8;
} | [
"size_t",
"jedbin_output",
"(",
"const",
"jed_data",
"*",
"data",
",",
"void",
"*",
"result",
",",
"size_t",
"length",
")",
"{",
"UINT8",
"*",
"curdst",
"=",
"(",
"UINT8",
"*",
")",
"result",
";",
"if",
"(",
"length",
">=",
"4",
"+",
"(",
"data",
"->",
"numfuses",
"+",
"7",
")",
"/",
"8",
")",
"{",
"*",
"curdst",
"++",
"=",
"data",
"->",
"numfuses",
">>",
"24",
";",
"*",
"curdst",
"++",
"=",
"data",
"->",
"numfuses",
">>",
"16",
";",
"*",
"curdst",
"++",
"=",
"data",
"->",
"numfuses",
">>",
"8",
";",
"*",
"curdst",
"++",
"=",
"data",
"->",
"numfuses",
">>",
"0",
";",
"memcpy",
"(",
"curdst",
",",
"data",
"->",
"fusemap",
",",
"(",
"data",
"->",
"numfuses",
"+",
"7",
")",
"/",
"8",
")",
";",
"}",
"return",
"4",
"+",
"(",
"data",
"->",
"numfuses",
"+",
"7",
")",
"/",
"8",
";",
"}"
] | jedbin_output - generate a new binary JED file
based on the jed_data provided | [
"jedbin_output",
"-",
"generate",
"a",
"new",
"binary",
"JED",
"file",
"based",
"on",
"the",
"jed_data",
"provided"
] | [
"/* ensure we have enough room */",
"/* store the number of fuses */",
"/* copy in the rest of the data */",
"/* return the final size */"
] | [
{
"param": "data",
"type": "jed_data"
},
{
"param": "result",
"type": "void"
},
{
"param": "length",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "data",
"type": "jed_data",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "result",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "length",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
33a9255dedd8faf1e8214b6e22186b4cc7263867 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/video/jalblend.c | [
"Unlicense"
] | C | jal_blend_func | rgb_t | rgb_t jal_blend_func(rgb_t dest, rgb_t addMe, UINT8 alpha)
{
int r, g, b;
int ir, ig, ib;
r = (int)RGB_RED (dest);
g = (int)RGB_GREEN(dest);
b = (int)RGB_BLUE (dest);
ir = (int)RGB_RED (addMe);
ig = (int)RGB_GREEN(addMe);
ib = (int)RGB_BLUE (addMe);
if (alpha & 4)
{ r -= ir; if (r < 0) r = 0; }
else
{ r += ir; if (r > 255) r = 255; }
if (alpha & 2)
{ g -= ig; if (g < 0) g = 0; }
else
{ g += ig; if (g > 255) g = 255; }
if (alpha & 1)
{ b -= ib; if (b < 0) b = 0; }
else
{ b += ib; if (b > 255) b = 255; }
return MAKE_RGB(r,g,b);
} | /* basically an add/subtract function with clamping */ | basically an add/subtract function with clamping | [
"basically",
"an",
"add",
"/",
"subtract",
"function",
"with",
"clamping"
] | rgb_t jal_blend_func(rgb_t dest, rgb_t addMe, UINT8 alpha)
{
int r, g, b;
int ir, ig, ib;
r = (int)RGB_RED (dest);
g = (int)RGB_GREEN(dest);
b = (int)RGB_BLUE (dest);
ir = (int)RGB_RED (addMe);
ig = (int)RGB_GREEN(addMe);
ib = (int)RGB_BLUE (addMe);
if (alpha & 4)
{ r -= ir; if (r < 0) r = 0; }
else
{ r += ir; if (r > 255) r = 255; }
if (alpha & 2)
{ g -= ig; if (g < 0) g = 0; }
else
{ g += ig; if (g > 255) g = 255; }
if (alpha & 1)
{ b -= ib; if (b < 0) b = 0; }
else
{ b += ib; if (b > 255) b = 255; }
return MAKE_RGB(r,g,b);
} | [
"rgb_t",
"jal_blend_func",
"(",
"rgb_t",
"dest",
",",
"rgb_t",
"addMe",
",",
"UINT8",
"alpha",
")",
"{",
"int",
"r",
",",
"g",
",",
"b",
";",
"int",
"ir",
",",
"ig",
",",
"ib",
";",
"r",
"=",
"(",
"int",
")",
"RGB_RED",
"(",
"dest",
")",
";",
"g",
"=",
"(",
"int",
")",
"RGB_GREEN",
"(",
"dest",
")",
";",
"b",
"=",
"(",
"int",
")",
"RGB_BLUE",
"(",
"dest",
")",
";",
"ir",
"=",
"(",
"int",
")",
"RGB_RED",
"(",
"addMe",
")",
";",
"ig",
"=",
"(",
"int",
")",
"RGB_GREEN",
"(",
"addMe",
")",
";",
"ib",
"=",
"(",
"int",
")",
"RGB_BLUE",
"(",
"addMe",
")",
";",
"if",
"(",
"alpha",
"&",
"4",
")",
"{",
"r",
"-=",
"ir",
";",
"if",
"(",
"r",
"<",
"0",
")",
"r",
"=",
"0",
";",
"}",
"else",
"{",
"r",
"+=",
"ir",
";",
"if",
"(",
"r",
">",
"255",
")",
"r",
"=",
"255",
";",
"}",
"if",
"(",
"alpha",
"&",
"2",
")",
"{",
"g",
"-=",
"ig",
";",
"if",
"(",
"g",
"<",
"0",
")",
"g",
"=",
"0",
";",
"}",
"else",
"{",
"g",
"+=",
"ig",
";",
"if",
"(",
"g",
">",
"255",
")",
"g",
"=",
"255",
";",
"}",
"if",
"(",
"alpha",
"&",
"1",
")",
"{",
"b",
"-=",
"ib",
";",
"if",
"(",
"b",
"<",
"0",
")",
"b",
"=",
"0",
";",
"}",
"else",
"{",
"b",
"+=",
"ib",
";",
"if",
"(",
"b",
">",
"255",
")",
"b",
"=",
"255",
";",
"}",
"return",
"MAKE_RGB",
"(",
"r",
",",
"g",
",",
"b",
")",
";",
"}"
] | basically an add/subtract function with clamping | [
"basically",
"an",
"add",
"/",
"subtract",
"function",
"with",
"clamping"
] | [] | [
{
"param": "dest",
"type": "rgb_t"
},
{
"param": "addMe",
"type": "rgb_t"
},
{
"param": "alpha",
"type": "UINT8"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "dest",
"type": "rgb_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "addMe",
"type": "rgb_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "alpha",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
24e8a1db1ef0adbf635f71911cef7cd713f0f5a1 | lofunz/mieme | Reloaded/trunk/src/mame/video/deco16ic.c | [
"Unlicense"
] | C | custom_tilemap_draw | void | static void custom_tilemap_draw(
running_device *device,
bitmap_t *bitmap,
tilemap_t *tilemap0_8x8,
tilemap_t *tilemap0_16x16,
tilemap_t *tilemap1_8x8,
tilemap_t *tilemap1_16x16,
const UINT16 *rowscroll_ptr,
const UINT16 scrollx,
const UINT16 scrolly,
const UINT16 control0,
const UINT16 control1,
int combine_mask,
int combine_shift,
int trans_mask,
int flags,
UINT32 priority)
{
running_machine *machine = device->machine;
tilemap_t *tilemap0 = BIT(control1, 7) ? tilemap0_8x8 : tilemap0_16x16;
tilemap_t *tilemap1 = BIT(control1, 7) ? tilemap1_8x8 : tilemap1_16x16;
const bitmap_t *src_bitmap0 = tilemap0 ? tilemap_get_pixmap(tilemap0) : NULL;
const bitmap_t *src_bitmap1 = tilemap1 ? tilemap_get_pixmap(tilemap1) : NULL;
int width_mask, height_mask, x, y, p;
int column_offset, src_x = 0, src_y = 0;
int row_type = 1 << ((control0 >> 3) & 0xf);
int col_type = 8 << (control0 & 7);
if (!src_bitmap0)
return;
// Playfield disable
if (!BIT(control0, 7))
return;
width_mask = src_bitmap0->width - 1;
height_mask = src_bitmap0->height - 1;
src_y = scrolly + 8;
for (y = 8; y < 248; y++)
{
if (rowscroll_ptr && BIT(control1, 6))
src_x = scrollx + rowscroll_ptr[src_y / row_type];
else
src_x = scrollx;
src_x &= width_mask;
if (bitmap->bpp == 16)
{
for (x = 0; x < 320; x++)
{
if (rowscroll_ptr && BIT(control1, 5))
column_offset = rowscroll_ptr[0x200 + ((src_x & 0x1ff) / col_type)];
else
column_offset = 0;
p = *BITMAP_ADDR16(src_bitmap0, (src_y + column_offset) & height_mask, src_x);
if (src_bitmap1)
p |= (*BITMAP_ADDR16(src_bitmap1, (src_y + column_offset) & height_mask, src_x) & combine_mask) << combine_shift;
src_x = (src_x + 1) & width_mask;
if ((flags & TILEMAP_DRAW_OPAQUE) || (p & trans_mask))
{
*BITMAP_ADDR16(bitmap, y, x) = machine->pens[p];
if (machine->priority_bitmap)
{
UINT8 *pri = BITMAP_ADDR8(machine->priority_bitmap, y, 0);
pri[x] |= priority;
}
}
}
}
else
{
/* boogwing */
for (x = 0; x < 320; x++)
{
if (rowscroll_ptr && BIT(control1, 5))
column_offset = rowscroll_ptr[0x200 + ((src_x & 0x1ff) / col_type)];
else
column_offset = 0;
p = *BITMAP_ADDR16(src_bitmap0, (src_y + column_offset) & height_mask, src_x);
if (src_bitmap1)
p |= (*BITMAP_ADDR16(src_bitmap1, (src_y + column_offset) & height_mask, src_x) & combine_mask) << combine_shift;
src_x = (src_x + 1) & width_mask;
if ((flags & TILEMAP_DRAW_OPAQUE) || (p & trans_mask))
{
*BITMAP_ADDR32(bitmap, y, x) = machine->pens[p];
if (machine->priority_bitmap)
{
UINT8 *pri = BITMAP_ADDR8(machine->priority_bitmap, y, 0);
pri[x] |= priority;
}
}
}
}
src_y = (src_y + 1) & height_mask;
}
} | /*
Consider this the 'reference rasterizer' for the 56/74/141 tilemap chips - it implements
simultaneous row & column scroll which the Mame tilemap core cannot do. It also
implements combining the 4BPP output of two tilemaps into 8BPP output. This function
is automatically called when the tilemap is in a state the cannot be properly rendered
by the Mame core.
*/ | Consider this the 'reference rasterizer' for the 56/74/141 tilemap chips - it implements
simultaneous row & column scroll which the Mame tilemap core cannot do. It also
implements combining the 4BPP output of two tilemaps into 8BPP output. This function
is automatically called when the tilemap is in a state the cannot be properly rendered
by the Mame core. | [
"Consider",
"this",
"the",
"'",
"reference",
"rasterizer",
"'",
"for",
"the",
"56",
"/",
"74",
"/",
"141",
"tilemap",
"chips",
"-",
"it",
"implements",
"simultaneous",
"row",
"&",
"column",
"scroll",
"which",
"the",
"Mame",
"tilemap",
"core",
"cannot",
"do",
".",
"It",
"also",
"implements",
"combining",
"the",
"4BPP",
"output",
"of",
"two",
"tilemaps",
"into",
"8BPP",
"output",
".",
"This",
"function",
"is",
"automatically",
"called",
"when",
"the",
"tilemap",
"is",
"in",
"a",
"state",
"the",
"cannot",
"be",
"properly",
"rendered",
"by",
"the",
"Mame",
"core",
"."
] | static void custom_tilemap_draw(
running_device *device,
bitmap_t *bitmap,
tilemap_t *tilemap0_8x8,
tilemap_t *tilemap0_16x16,
tilemap_t *tilemap1_8x8,
tilemap_t *tilemap1_16x16,
const UINT16 *rowscroll_ptr,
const UINT16 scrollx,
const UINT16 scrolly,
const UINT16 control0,
const UINT16 control1,
int combine_mask,
int combine_shift,
int trans_mask,
int flags,
UINT32 priority)
{
running_machine *machine = device->machine;
tilemap_t *tilemap0 = BIT(control1, 7) ? tilemap0_8x8 : tilemap0_16x16;
tilemap_t *tilemap1 = BIT(control1, 7) ? tilemap1_8x8 : tilemap1_16x16;
const bitmap_t *src_bitmap0 = tilemap0 ? tilemap_get_pixmap(tilemap0) : NULL;
const bitmap_t *src_bitmap1 = tilemap1 ? tilemap_get_pixmap(tilemap1) : NULL;
int width_mask, height_mask, x, y, p;
int column_offset, src_x = 0, src_y = 0;
int row_type = 1 << ((control0 >> 3) & 0xf);
int col_type = 8 << (control0 & 7);
if (!src_bitmap0)
return;
if (!BIT(control0, 7))
return;
width_mask = src_bitmap0->width - 1;
height_mask = src_bitmap0->height - 1;
src_y = scrolly + 8;
for (y = 8; y < 248; y++)
{
if (rowscroll_ptr && BIT(control1, 6))
src_x = scrollx + rowscroll_ptr[src_y / row_type];
else
src_x = scrollx;
src_x &= width_mask;
if (bitmap->bpp == 16)
{
for (x = 0; x < 320; x++)
{
if (rowscroll_ptr && BIT(control1, 5))
column_offset = rowscroll_ptr[0x200 + ((src_x & 0x1ff) / col_type)];
else
column_offset = 0;
p = *BITMAP_ADDR16(src_bitmap0, (src_y + column_offset) & height_mask, src_x);
if (src_bitmap1)
p |= (*BITMAP_ADDR16(src_bitmap1, (src_y + column_offset) & height_mask, src_x) & combine_mask) << combine_shift;
src_x = (src_x + 1) & width_mask;
if ((flags & TILEMAP_DRAW_OPAQUE) || (p & trans_mask))
{
*BITMAP_ADDR16(bitmap, y, x) = machine->pens[p];
if (machine->priority_bitmap)
{
UINT8 *pri = BITMAP_ADDR8(machine->priority_bitmap, y, 0);
pri[x] |= priority;
}
}
}
}
else
{
for (x = 0; x < 320; x++)
{
if (rowscroll_ptr && BIT(control1, 5))
column_offset = rowscroll_ptr[0x200 + ((src_x & 0x1ff) / col_type)];
else
column_offset = 0;
p = *BITMAP_ADDR16(src_bitmap0, (src_y + column_offset) & height_mask, src_x);
if (src_bitmap1)
p |= (*BITMAP_ADDR16(src_bitmap1, (src_y + column_offset) & height_mask, src_x) & combine_mask) << combine_shift;
src_x = (src_x + 1) & width_mask;
if ((flags & TILEMAP_DRAW_OPAQUE) || (p & trans_mask))
{
*BITMAP_ADDR32(bitmap, y, x) = machine->pens[p];
if (machine->priority_bitmap)
{
UINT8 *pri = BITMAP_ADDR8(machine->priority_bitmap, y, 0);
pri[x] |= priority;
}
}
}
}
src_y = (src_y + 1) & height_mask;
}
} | [
"static",
"void",
"custom_tilemap_draw",
"(",
"running_device",
"*",
"device",
",",
"bitmap_t",
"*",
"bitmap",
",",
"tilemap_t",
"*",
"tilemap0_8x8",
",",
"tilemap_t",
"*",
"tilemap0_16x16",
",",
"tilemap_t",
"*",
"tilemap1_8x8",
",",
"tilemap_t",
"*",
"tilemap1_16x16",
",",
"const",
"UINT16",
"*",
"rowscroll_ptr",
",",
"const",
"UINT16",
"scrollx",
",",
"const",
"UINT16",
"scrolly",
",",
"const",
"UINT16",
"control0",
",",
"const",
"UINT16",
"control1",
",",
"int",
"combine_mask",
",",
"int",
"combine_shift",
",",
"int",
"trans_mask",
",",
"int",
"flags",
",",
"UINT32",
"priority",
")",
"{",
"running_machine",
"*",
"machine",
"=",
"device",
"->",
"machine",
";",
"tilemap_t",
"*",
"tilemap0",
"=",
"BIT",
"(",
"control1",
",",
"7",
")",
"?",
"tilemap0_8x8",
":",
"tilemap0_16x16",
";",
"tilemap_t",
"*",
"tilemap1",
"=",
"BIT",
"(",
"control1",
",",
"7",
")",
"?",
"tilemap1_8x8",
":",
"tilemap1_16x16",
";",
"const",
"bitmap_t",
"*",
"src_bitmap0",
"=",
"tilemap0",
"?",
"tilemap_get_pixmap",
"(",
"tilemap0",
")",
":",
"NULL",
";",
"const",
"bitmap_t",
"*",
"src_bitmap1",
"=",
"tilemap1",
"?",
"tilemap_get_pixmap",
"(",
"tilemap1",
")",
":",
"NULL",
";",
"int",
"width_mask",
",",
"height_mask",
",",
"x",
",",
"y",
",",
"p",
";",
"int",
"column_offset",
",",
"src_x",
"=",
"0",
",",
"src_y",
"=",
"0",
";",
"int",
"row_type",
"=",
"1",
"<<",
"(",
"(",
"control0",
">>",
"3",
")",
"&",
"0xf",
")",
";",
"int",
"col_type",
"=",
"8",
"<<",
"(",
"control0",
"&",
"7",
")",
";",
"if",
"(",
"!",
"src_bitmap0",
")",
"return",
";",
"if",
"(",
"!",
"BIT",
"(",
"control0",
",",
"7",
")",
")",
"return",
";",
"width_mask",
"=",
"src_bitmap0",
"->",
"width",
"-",
"1",
";",
"height_mask",
"=",
"src_bitmap0",
"->",
"height",
"-",
"1",
";",
"src_y",
"=",
"scrolly",
"+",
"8",
";",
"for",
"(",
"y",
"=",
"8",
";",
"y",
"<",
"248",
";",
"y",
"++",
")",
"{",
"if",
"(",
"rowscroll_ptr",
"&&",
"BIT",
"(",
"control1",
",",
"6",
")",
")",
"src_x",
"=",
"scrollx",
"+",
"rowscroll_ptr",
"[",
"src_y",
"/",
"row_type",
"]",
";",
"else",
"src_x",
"=",
"scrollx",
";",
"src_x",
"&=",
"width_mask",
";",
"if",
"(",
"bitmap",
"->",
"bpp",
"==",
"16",
")",
"{",
"for",
"(",
"x",
"=",
"0",
";",
"x",
"<",
"320",
";",
"x",
"++",
")",
"{",
"if",
"(",
"rowscroll_ptr",
"&&",
"BIT",
"(",
"control1",
",",
"5",
")",
")",
"column_offset",
"=",
"rowscroll_ptr",
"[",
"0x200",
"+",
"(",
"(",
"src_x",
"&",
"0x1ff",
")",
"/",
"col_type",
")",
"]",
";",
"else",
"column_offset",
"=",
"0",
";",
"p",
"=",
"*",
"BITMAP_ADDR16",
"(",
"src_bitmap0",
",",
"(",
"src_y",
"+",
"column_offset",
")",
"&",
"height_mask",
",",
"src_x",
")",
";",
"if",
"(",
"src_bitmap1",
")",
"p",
"|=",
"(",
"*",
"BITMAP_ADDR16",
"(",
"src_bitmap1",
",",
"(",
"src_y",
"+",
"column_offset",
")",
"&",
"height_mask",
",",
"src_x",
")",
"&",
"combine_mask",
")",
"<<",
"combine_shift",
";",
"src_x",
"=",
"(",
"src_x",
"+",
"1",
")",
"&",
"width_mask",
";",
"if",
"(",
"(",
"flags",
"&",
"TILEMAP_DRAW_OPAQUE",
")",
"||",
"(",
"p",
"&",
"trans_mask",
")",
")",
"{",
"*",
"BITMAP_ADDR16",
"(",
"bitmap",
",",
"y",
",",
"x",
")",
"=",
"machine",
"->",
"pens",
"[",
"p",
"]",
";",
"if",
"(",
"machine",
"->",
"priority_bitmap",
")",
"{",
"UINT8",
"*",
"pri",
"=",
"BITMAP_ADDR8",
"(",
"machine",
"->",
"priority_bitmap",
",",
"y",
",",
"0",
")",
";",
"pri",
"[",
"x",
"]",
"|=",
"priority",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"for",
"(",
"x",
"=",
"0",
";",
"x",
"<",
"320",
";",
"x",
"++",
")",
"{",
"if",
"(",
"rowscroll_ptr",
"&&",
"BIT",
"(",
"control1",
",",
"5",
")",
")",
"column_offset",
"=",
"rowscroll_ptr",
"[",
"0x200",
"+",
"(",
"(",
"src_x",
"&",
"0x1ff",
")",
"/",
"col_type",
")",
"]",
";",
"else",
"column_offset",
"=",
"0",
";",
"p",
"=",
"*",
"BITMAP_ADDR16",
"(",
"src_bitmap0",
",",
"(",
"src_y",
"+",
"column_offset",
")",
"&",
"height_mask",
",",
"src_x",
")",
";",
"if",
"(",
"src_bitmap1",
")",
"p",
"|=",
"(",
"*",
"BITMAP_ADDR16",
"(",
"src_bitmap1",
",",
"(",
"src_y",
"+",
"column_offset",
")",
"&",
"height_mask",
",",
"src_x",
")",
"&",
"combine_mask",
")",
"<<",
"combine_shift",
";",
"src_x",
"=",
"(",
"src_x",
"+",
"1",
")",
"&",
"width_mask",
";",
"if",
"(",
"(",
"flags",
"&",
"TILEMAP_DRAW_OPAQUE",
")",
"||",
"(",
"p",
"&",
"trans_mask",
")",
")",
"{",
"*",
"BITMAP_ADDR32",
"(",
"bitmap",
",",
"y",
",",
"x",
")",
"=",
"machine",
"->",
"pens",
"[",
"p",
"]",
";",
"if",
"(",
"machine",
"->",
"priority_bitmap",
")",
"{",
"UINT8",
"*",
"pri",
"=",
"BITMAP_ADDR8",
"(",
"machine",
"->",
"priority_bitmap",
",",
"y",
",",
"0",
")",
";",
"pri",
"[",
"x",
"]",
"|=",
"priority",
";",
"}",
"}",
"}",
"}",
"src_y",
"=",
"(",
"src_y",
"+",
"1",
")",
"&",
"height_mask",
";",
"}",
"}"
] | Consider this the 'reference rasterizer' for the 56/74/141 tilemap chips - it implements
simultaneous row & column scroll which the Mame tilemap core cannot do. | [
"Consider",
"this",
"the",
"'",
"reference",
"rasterizer",
"'",
"for",
"the",
"56",
"/",
"74",
"/",
"141",
"tilemap",
"chips",
"-",
"it",
"implements",
"simultaneous",
"row",
"&",
"column",
"scroll",
"which",
"the",
"Mame",
"tilemap",
"core",
"cannot",
"do",
"."
] | [
"// Playfield disable\r",
"/* boogwing */"
] | [
{
"param": "device",
"type": "running_device"
},
{
"param": "bitmap",
"type": "bitmap_t"
},
{
"param": "tilemap0_8x8",
"type": "tilemap_t"
},
{
"param": "tilemap0_16x16",
"type": "tilemap_t"
},
{
"param": "tilemap1_8x8",
"type": "tilemap_t"
},
{
"param": "tilemap1_16x16",
"type": "tilemap_t"
},
{
"param": "rowscroll_ptr",
"type": "UINT16"
},
{
"param": "scrollx",
"type": "UINT16"
},
{
"param": "scrolly",
"type": "UINT16"
},
{
"param": "control0",
"type": "UINT16"
},
{
"param": "control1",
"type": "UINT16"
},
{
"param": "combine_mask",
"type": "int"
},
{
"param": "combine_shift",
"type": "int"
},
{
"param": "trans_mask",
"type": "int"
},
{
"param": "flags",
"type": "int"
},
{
"param": "priority",
"type": "UINT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "device",
"type": "running_device",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "bitmap",
"type": "bitmap_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tilemap0_8x8",
"type": "tilemap_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tilemap0_16x16",
"type": "tilemap_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tilemap1_8x8",
"type": "tilemap_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tilemap1_16x16",
"type": "tilemap_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "rowscroll_ptr",
"type": "UINT16",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "scrollx",
"type": "UINT16",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "scrolly",
"type": "UINT16",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "control0",
"type": "UINT16",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "control1",
"type": "UINT16",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "combine_mask",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "combine_shift",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "trans_mask",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "flags",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "priority",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
24e8a1db1ef0adbf635f71911cef7cd713f0f5a1 | lofunz/mieme | Reloaded/trunk/src/mame/video/deco16ic.c | [
"Unlicense"
] | C | deco16ic_set_tilemap_colour_mask | void | void deco16ic_set_tilemap_colour_mask( running_device *device, int tmap, int mask )
{
deco16ic_state *deco16ic = get_safe_token(device);
switch (tmap)
{
case 0: deco16ic->pf1_colourmask = mask; break;
case 1: deco16ic->pf2_colourmask = mask; break;
case 2: deco16ic->pf3_colourmask = mask; break;
case 3: deco16ic->pf4_colourmask = mask; break;
}
} | /* robocop 2 can switch between 2 tilemaps at 4bpp, or 1 at 8bpp */ | robocop 2 can switch between 2 tilemaps at 4bpp, or 1 at 8bpp | [
"robocop",
"2",
"can",
"switch",
"between",
"2",
"tilemaps",
"at",
"4bpp",
"or",
"1",
"at",
"8bpp"
] | void deco16ic_set_tilemap_colour_mask( running_device *device, int tmap, int mask )
{
deco16ic_state *deco16ic = get_safe_token(device);
switch (tmap)
{
case 0: deco16ic->pf1_colourmask = mask; break;
case 1: deco16ic->pf2_colourmask = mask; break;
case 2: deco16ic->pf3_colourmask = mask; break;
case 3: deco16ic->pf4_colourmask = mask; break;
}
} | [
"void",
"deco16ic_set_tilemap_colour_mask",
"(",
"running_device",
"*",
"device",
",",
"int",
"tmap",
",",
"int",
"mask",
")",
"{",
"deco16ic_state",
"*",
"deco16ic",
"=",
"get_safe_token",
"(",
"device",
")",
";",
"switch",
"(",
"tmap",
")",
"{",
"case",
"0",
":",
"deco16ic",
"->",
"pf1_colourmask",
"=",
"mask",
";",
"break",
";",
"case",
"1",
":",
"deco16ic",
"->",
"pf2_colourmask",
"=",
"mask",
";",
"break",
";",
"case",
"2",
":",
"deco16ic",
"->",
"pf3_colourmask",
"=",
"mask",
";",
"break",
";",
"case",
"3",
":",
"deco16ic",
"->",
"pf4_colourmask",
"=",
"mask",
";",
"break",
";",
"}",
"}"
] | robocop 2 can switch between 2 tilemaps at 4bpp, or 1 at 8bpp | [
"robocop",
"2",
"can",
"switch",
"between",
"2",
"tilemaps",
"at",
"4bpp",
"or",
"1",
"at",
"8bpp"
] | [] | [
{
"param": "device",
"type": "running_device"
},
{
"param": "tmap",
"type": "int"
},
{
"param": "mask",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "device",
"type": "running_device",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tmap",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "mask",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
24e8a1db1ef0adbf635f71911cef7cd713f0f5a1 | lofunz/mieme | Reloaded/trunk/src/mame/video/deco16ic.c | [
"Unlicense"
] | C | deco16ic_pdrawgfx | void | void deco16ic_pdrawgfx(
running_device *device,
bitmap_t *dest, const rectangle *clip, const gfx_element *gfx,
UINT32 code, UINT32 color, int flipx, int flipy, int sx, int sy,
int transparent_color, UINT32 pri_mask, UINT32 sprite_mask, UINT8 write_pri, UINT8 alpha)
{
deco16ic_state *deco16ic = get_safe_token(device);
int ox, oy, cx, cy;
int x_index, y_index, x, y;
bitmap_t *priority_bitmap = gfx->machine->priority_bitmap;
const pen_t *pal = &gfx->machine->pens[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
const UINT8 *code_base = gfx_element_get_data(gfx, code % gfx->total_elements);
/* check bounds */
ox = sx;
oy = sy;
if (sx > 319 || sy > 247 || sx < -15 || sy < -7)
return;
if (sy < 0) sy = 0;
if (sx < 0) sx = 0;
if (sx > 319) cx = 319;
else cx = ox + 16;
cy = (sy - oy);
if (flipy) y_index = 15 - cy; else y_index = cy;
for (y = 0; y < 16 - cy; y++)
{
const UINT8 *source = code_base + (y_index * gfx->line_modulo);
UINT32 *destb = BITMAP_ADDR32(dest, sy, 0);
UINT8 *pri = BITMAP_ADDR8(priority_bitmap, sy, 0);
UINT8 *spri = BITMAP_ADDR8(deco16ic->sprite_priority_bitmap, sy, 0);
if (sy >= 0 && sy < 248)
{
if (flipx) { source += 15 - (sx - ox); x_index = -1; }
else { source += (sx - ox); x_index = 1; }
for (x = sx; x < cx; x++)
{
int c = *source;
if (c != transparent_color && x >= 0 && x < 320)
{
if (pri_mask>pri[x] && sprite_mask>spri[x])
{
if (alpha != 0xff)
destb[x] = alpha_blend_r32(destb[x], pal[c], alpha);
else
destb[x] = pal[c];
if (write_pri)
pri[x] |= pri_mask;
}
spri[x] |= sprite_mask;
}
source += x_index;
}
}
sy++;
if (sy > 247)
return;
if (flipy) y_index--; else y_index++;
}
} | /* A special pdrawgfx z-buffered sprite renderer that is needed to properly draw multiple sprite sources with alpha */ | A special pdrawgfx z-buffered sprite renderer that is needed to properly draw multiple sprite sources with alpha | [
"A",
"special",
"pdrawgfx",
"z",
"-",
"buffered",
"sprite",
"renderer",
"that",
"is",
"needed",
"to",
"properly",
"draw",
"multiple",
"sprite",
"sources",
"with",
"alpha"
] | void deco16ic_pdrawgfx(
running_device *device,
bitmap_t *dest, const rectangle *clip, const gfx_element *gfx,
UINT32 code, UINT32 color, int flipx, int flipy, int sx, int sy,
int transparent_color, UINT32 pri_mask, UINT32 sprite_mask, UINT8 write_pri, UINT8 alpha)
{
deco16ic_state *deco16ic = get_safe_token(device);
int ox, oy, cx, cy;
int x_index, y_index, x, y;
bitmap_t *priority_bitmap = gfx->machine->priority_bitmap;
const pen_t *pal = &gfx->machine->pens[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
const UINT8 *code_base = gfx_element_get_data(gfx, code % gfx->total_elements);
ox = sx;
oy = sy;
if (sx > 319 || sy > 247 || sx < -15 || sy < -7)
return;
if (sy < 0) sy = 0;
if (sx < 0) sx = 0;
if (sx > 319) cx = 319;
else cx = ox + 16;
cy = (sy - oy);
if (flipy) y_index = 15 - cy; else y_index = cy;
for (y = 0; y < 16 - cy; y++)
{
const UINT8 *source = code_base + (y_index * gfx->line_modulo);
UINT32 *destb = BITMAP_ADDR32(dest, sy, 0);
UINT8 *pri = BITMAP_ADDR8(priority_bitmap, sy, 0);
UINT8 *spri = BITMAP_ADDR8(deco16ic->sprite_priority_bitmap, sy, 0);
if (sy >= 0 && sy < 248)
{
if (flipx) { source += 15 - (sx - ox); x_index = -1; }
else { source += (sx - ox); x_index = 1; }
for (x = sx; x < cx; x++)
{
int c = *source;
if (c != transparent_color && x >= 0 && x < 320)
{
if (pri_mask>pri[x] && sprite_mask>spri[x])
{
if (alpha != 0xff)
destb[x] = alpha_blend_r32(destb[x], pal[c], alpha);
else
destb[x] = pal[c];
if (write_pri)
pri[x] |= pri_mask;
}
spri[x] |= sprite_mask;
}
source += x_index;
}
}
sy++;
if (sy > 247)
return;
if (flipy) y_index--; else y_index++;
}
} | [
"void",
"deco16ic_pdrawgfx",
"(",
"running_device",
"*",
"device",
",",
"bitmap_t",
"*",
"dest",
",",
"const",
"rectangle",
"*",
"clip",
",",
"const",
"gfx_element",
"*",
"gfx",
",",
"UINT32",
"code",
",",
"UINT32",
"color",
",",
"int",
"flipx",
",",
"int",
"flipy",
",",
"int",
"sx",
",",
"int",
"sy",
",",
"int",
"transparent_color",
",",
"UINT32",
"pri_mask",
",",
"UINT32",
"sprite_mask",
",",
"UINT8",
"write_pri",
",",
"UINT8",
"alpha",
")",
"{",
"deco16ic_state",
"*",
"deco16ic",
"=",
"get_safe_token",
"(",
"device",
")",
";",
"int",
"ox",
",",
"oy",
",",
"cx",
",",
"cy",
";",
"int",
"x_index",
",",
"y_index",
",",
"x",
",",
"y",
";",
"bitmap_t",
"*",
"priority_bitmap",
"=",
"gfx",
"->",
"machine",
"->",
"priority_bitmap",
";",
"const",
"pen_t",
"*",
"pal",
"=",
"&",
"gfx",
"->",
"machine",
"->",
"pens",
"[",
"gfx",
"->",
"color_base",
"+",
"gfx",
"->",
"color_granularity",
"*",
"(",
"color",
"%",
"gfx",
"->",
"total_colors",
")",
"]",
";",
"const",
"UINT8",
"*",
"code_base",
"=",
"gfx_element_get_data",
"(",
"gfx",
",",
"code",
"%",
"gfx",
"->",
"total_elements",
")",
";",
"ox",
"=",
"sx",
";",
"oy",
"=",
"sy",
";",
"if",
"(",
"sx",
">",
"319",
"||",
"sy",
">",
"247",
"||",
"sx",
"<",
"-15",
"||",
"sy",
"<",
"-7",
")",
"return",
";",
"if",
"(",
"sy",
"<",
"0",
")",
"sy",
"=",
"0",
";",
"if",
"(",
"sx",
"<",
"0",
")",
"sx",
"=",
"0",
";",
"if",
"(",
"sx",
">",
"319",
")",
"cx",
"=",
"319",
";",
"else",
"cx",
"=",
"ox",
"+",
"16",
";",
"cy",
"=",
"(",
"sy",
"-",
"oy",
")",
";",
"if",
"(",
"flipy",
")",
"y_index",
"=",
"15",
"-",
"cy",
";",
"else",
"y_index",
"=",
"cy",
";",
"for",
"(",
"y",
"=",
"0",
";",
"y",
"<",
"16",
"-",
"cy",
";",
"y",
"++",
")",
"{",
"const",
"UINT8",
"*",
"source",
"=",
"code_base",
"+",
"(",
"y_index",
"*",
"gfx",
"->",
"line_modulo",
")",
";",
"UINT32",
"*",
"destb",
"=",
"BITMAP_ADDR32",
"(",
"dest",
",",
"sy",
",",
"0",
")",
";",
"UINT8",
"*",
"pri",
"=",
"BITMAP_ADDR8",
"(",
"priority_bitmap",
",",
"sy",
",",
"0",
")",
";",
"UINT8",
"*",
"spri",
"=",
"BITMAP_ADDR8",
"(",
"deco16ic",
"->",
"sprite_priority_bitmap",
",",
"sy",
",",
"0",
")",
";",
"if",
"(",
"sy",
">=",
"0",
"&&",
"sy",
"<",
"248",
")",
"{",
"if",
"(",
"flipx",
")",
"{",
"source",
"+=",
"15",
"-",
"(",
"sx",
"-",
"ox",
")",
";",
"x_index",
"=",
"-1",
";",
"}",
"else",
"{",
"source",
"+=",
"(",
"sx",
"-",
"ox",
")",
";",
"x_index",
"=",
"1",
";",
"}",
"for",
"(",
"x",
"=",
"sx",
";",
"x",
"<",
"cx",
";",
"x",
"++",
")",
"{",
"int",
"c",
"=",
"*",
"source",
";",
"if",
"(",
"c",
"!=",
"transparent_color",
"&&",
"x",
">=",
"0",
"&&",
"x",
"<",
"320",
")",
"{",
"if",
"(",
"pri_mask",
">",
"pri",
"[",
"x",
"]",
"&&",
"sprite_mask",
">",
"spri",
"[",
"x",
"]",
")",
"{",
"if",
"(",
"alpha",
"!=",
"0xff",
")",
"destb",
"[",
"x",
"]",
"=",
"alpha_blend_r32",
"(",
"destb",
"[",
"x",
"]",
",",
"pal",
"[",
"c",
"]",
",",
"alpha",
")",
";",
"else",
"destb",
"[",
"x",
"]",
"=",
"pal",
"[",
"c",
"]",
";",
"if",
"(",
"write_pri",
")",
"pri",
"[",
"x",
"]",
"|=",
"pri_mask",
";",
"}",
"spri",
"[",
"x",
"]",
"|=",
"sprite_mask",
";",
"}",
"source",
"+=",
"x_index",
";",
"}",
"}",
"sy",
"++",
";",
"if",
"(",
"sy",
">",
"247",
")",
"return",
";",
"if",
"(",
"flipy",
")",
"y_index",
"--",
";",
"else",
"y_index",
"++",
";",
"}",
"}"
] | A special pdrawgfx z-buffered sprite renderer that is needed to properly draw multiple sprite sources with alpha | [
"A",
"special",
"pdrawgfx",
"z",
"-",
"buffered",
"sprite",
"renderer",
"that",
"is",
"needed",
"to",
"properly",
"draw",
"multiple",
"sprite",
"sources",
"with",
"alpha"
] | [
"/* check bounds */"
] | [
{
"param": "device",
"type": "running_device"
},
{
"param": "dest",
"type": "bitmap_t"
},
{
"param": "clip",
"type": "rectangle"
},
{
"param": "gfx",
"type": "gfx_element"
},
{
"param": "code",
"type": "UINT32"
},
{
"param": "color",
"type": "UINT32"
},
{
"param": "flipx",
"type": "int"
},
{
"param": "flipy",
"type": "int"
},
{
"param": "sx",
"type": "int"
},
{
"param": "sy",
"type": "int"
},
{
"param": "transparent_color",
"type": "int"
},
{
"param": "pri_mask",
"type": "UINT32"
},
{
"param": "sprite_mask",
"type": "UINT32"
},
{
"param": "write_pri",
"type": "UINT8"
},
{
"param": "alpha",
"type": "UINT8"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "device",
"type": "running_device",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dest",
"type": "bitmap_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "clip",
"type": "rectangle",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "gfx",
"type": "gfx_element",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "code",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "color",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "flipx",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "flipy",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "sx",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "sy",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "transparent_color",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "pri_mask",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "sprite_mask",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "write_pri",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "alpha",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
24e8a1db1ef0adbf635f71911cef7cd713f0f5a1 | lofunz/mieme | Reloaded/trunk/src/mame/video/deco16ic.c | [
"Unlicense"
] | C | deco16ic_tilemap_34_combine_draw | void | void deco16ic_tilemap_34_combine_draw(running_device *device, bitmap_t *bitmap, const rectangle *cliprect, int flags, UINT32 priority)
{
deco16ic_state *deco16ic = get_safe_token(device);
custom_tilemap_draw(device, bitmap, 0, deco16ic->pf3_tilemap_16x16, 0, deco16ic->pf4_tilemap_16x16, deco16ic->pf3_rowscroll_ptr, deco16ic->pf34_control[1], deco16ic->pf34_control[2], deco16ic->pf34_control[5] & 0xff, deco16ic->pf34_control[6] & 0xff, 0xf, 4, 0xff, flags, priority);
} | // Combines the output of two 4BPP tilemaps into an 8BPP tilemap
| Combines the output of two 4BPP tilemaps into an 8BPP tilemap | [
"Combines",
"the",
"output",
"of",
"two",
"4BPP",
"tilemaps",
"into",
"an",
"8BPP",
"tilemap"
] | void deco16ic_tilemap_34_combine_draw(running_device *device, bitmap_t *bitmap, const rectangle *cliprect, int flags, UINT32 priority)
{
deco16ic_state *deco16ic = get_safe_token(device);
custom_tilemap_draw(device, bitmap, 0, deco16ic->pf3_tilemap_16x16, 0, deco16ic->pf4_tilemap_16x16, deco16ic->pf3_rowscroll_ptr, deco16ic->pf34_control[1], deco16ic->pf34_control[2], deco16ic->pf34_control[5] & 0xff, deco16ic->pf34_control[6] & 0xff, 0xf, 4, 0xff, flags, priority);
} | [
"void",
"deco16ic_tilemap_34_combine_draw",
"(",
"running_device",
"*",
"device",
",",
"bitmap_t",
"*",
"bitmap",
",",
"const",
"rectangle",
"*",
"cliprect",
",",
"int",
"flags",
",",
"UINT32",
"priority",
")",
"{",
"deco16ic_state",
"*",
"deco16ic",
"=",
"get_safe_token",
"(",
"device",
")",
";",
"custom_tilemap_draw",
"(",
"device",
",",
"bitmap",
",",
"0",
",",
"deco16ic",
"->",
"pf3_tilemap_16x16",
",",
"0",
",",
"deco16ic",
"->",
"pf4_tilemap_16x16",
",",
"deco16ic",
"->",
"pf3_rowscroll_ptr",
",",
"deco16ic",
"->",
"pf34_control",
"[",
"1",
"]",
",",
"deco16ic",
"->",
"pf34_control",
"[",
"2",
"]",
",",
"deco16ic",
"->",
"pf34_control",
"[",
"5",
"]",
"&",
"0xff",
",",
"deco16ic",
"->",
"pf34_control",
"[",
"6",
"]",
"&",
"0xff",
",",
"0xf",
",",
"4",
",",
"0xff",
",",
"flags",
",",
"priority",
")",
";",
"}"
] | Combines the output of two 4BPP tilemaps into an 8BPP tilemap | [
"Combines",
"the",
"output",
"of",
"two",
"4BPP",
"tilemaps",
"into",
"an",
"8BPP",
"tilemap"
] | [] | [
{
"param": "device",
"type": "running_device"
},
{
"param": "bitmap",
"type": "bitmap_t"
},
{
"param": "cliprect",
"type": "rectangle"
},
{
"param": "flags",
"type": "int"
},
{
"param": "priority",
"type": "UINT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "device",
"type": "running_device",
"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": "flags",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "priority",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a40cc95189bf25d00b69cf1b7ea2ce5337738e8e | lofunz/mieme | Reloaded/trunk/src/mame/drivers/megadriv.c | [
"Unlicense"
] | C | read_next_instruction | UINT16 | static UINT16 read_next_instruction(const address_space *space)
{
static UINT8 recurse = 0;
UINT16 result;
/* Unmapped memory returns the last word on the data bus, which is almost always the opcode */
/* of the next instruction due to prefetch; however, since we may be encrypted, we actually */
/* need to return the encrypted opcode, not the last decrypted data. */
/* Believe it or not, this is actually important for Cotton, which has the following evil */
/* code: btst #0,$7038f7, which tests the low bit of an unmapped address, which thus should */
/* return the prefetched value. */
/* prevent recursion */
if (recurse)
return 0xffff;
/* read original encrypted memory at that address */
recurse = 1;
result = memory_read_word(space, cpu_get_pc(space->cpu));
recurse = 0;
return result;
} | /* taken from segaic16.c */
/* doesn't seem to meet my needs, not used */ | taken from segaic16.c
doesn't seem to meet my needs, not used | [
"taken",
"from",
"segaic16",
".",
"c",
"doesn",
"'",
"t",
"seem",
"to",
"meet",
"my",
"needs",
"not",
"used"
] | static UINT16 read_next_instruction(const address_space *space)
{
static UINT8 recurse = 0;
UINT16 result;
if (recurse)
return 0xffff;
recurse = 1;
result = memory_read_word(space, cpu_get_pc(space->cpu));
recurse = 0;
return result;
} | [
"static",
"UINT16",
"read_next_instruction",
"(",
"const",
"address_space",
"*",
"space",
")",
"{",
"static",
"UINT8",
"recurse",
"=",
"0",
";",
"UINT16",
"result",
";",
"if",
"(",
"recurse",
")",
"return",
"0xffff",
";",
"recurse",
"=",
"1",
";",
"result",
"=",
"memory_read_word",
"(",
"space",
",",
"cpu_get_pc",
"(",
"space",
"->",
"cpu",
")",
")",
";",
"recurse",
"=",
"0",
";",
"return",
"result",
";",
"}"
] | taken from segaic16.c
doesn't seem to meet my needs, not used | [
"taken",
"from",
"segaic16",
".",
"c",
"doesn",
"'",
"t",
"seem",
"to",
"meet",
"my",
"needs",
"not",
"used"
] | [
"/* Unmapped memory returns the last word on the data bus, which is almost always the opcode */",
"/* of the next instruction due to prefetch; however, since we may be encrypted, we actually */",
"/* need to return the encrypted opcode, not the last decrypted data. */",
"/* Believe it or not, this is actually important for Cotton, which has the following evil */",
"/* code: btst #0,$7038f7, which tests the low bit of an unmapped address, which thus should */",
"/* return the prefetched value. */",
"/* prevent recursion */",
"/* read original encrypted memory at that address */"
] | [
{
"param": "space",
"type": "address_space"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "space",
"type": "address_space",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a40cc95189bf25d00b69cf1b7ea2ce5337738e8e | lofunz/mieme | Reloaded/trunk/src/mame/drivers/megadriv.c | [
"Unlicense"
] | C | megadrive_do_insta_68k_to_vram_dma | void | static void megadrive_do_insta_68k_to_vram_dma(running_machine *machine, UINT32 source,int length)
{
int count;
if (length==0x00) length = 0xffff;
/* This is a hack until real DMA timings are implemented */
cpu_spinuntil_time(machine->device("maincpu"), ATTOTIME_IN_NSEC(length * 1000 / 3500));
for (count = 0;count<(length>>1);count++)
{
vdp_vram_write(vdp_get_word_from_68k_mem(machine, source));
source+=2;
if (source>0xffffff) source = 0xe00000;
}
megadrive_vdp_address&=0xffff;
megadrive_vdp_register[0x13] = 0;
megadrive_vdp_register[0x14] = 0;
megadrive_vdp_register[0x15] = (source>>1) & 0xff;
megadrive_vdp_register[0x16] = (source>>9) & 0xff;
megadrive_vdp_register[0x17] = (source>>17) & 0xff;
} | /* Instant, but we pause the 68k a bit */ | Instant, but we pause the 68k a bit | [
"Instant",
"but",
"we",
"pause",
"the",
"68k",
"a",
"bit"
] | static void megadrive_do_insta_68k_to_vram_dma(running_machine *machine, UINT32 source,int length)
{
int count;
if (length==0x00) length = 0xffff;
cpu_spinuntil_time(machine->device("maincpu"), ATTOTIME_IN_NSEC(length * 1000 / 3500));
for (count = 0;count<(length>>1);count++)
{
vdp_vram_write(vdp_get_word_from_68k_mem(machine, source));
source+=2;
if (source>0xffffff) source = 0xe00000;
}
megadrive_vdp_address&=0xffff;
megadrive_vdp_register[0x13] = 0;
megadrive_vdp_register[0x14] = 0;
megadrive_vdp_register[0x15] = (source>>1) & 0xff;
megadrive_vdp_register[0x16] = (source>>9) & 0xff;
megadrive_vdp_register[0x17] = (source>>17) & 0xff;
} | [
"static",
"void",
"megadrive_do_insta_68k_to_vram_dma",
"(",
"running_machine",
"*",
"machine",
",",
"UINT32",
"source",
",",
"int",
"length",
")",
"{",
"int",
"count",
";",
"if",
"(",
"length",
"==",
"0x00",
")",
"length",
"=",
"0xffff",
";",
"cpu_spinuntil_time",
"(",
"machine",
"->",
"device",
"(",
"\"",
"\"",
")",
",",
"ATTOTIME_IN_NSEC",
"(",
"length",
"*",
"1000",
"/",
"3500",
")",
")",
";",
"for",
"(",
"count",
"=",
"0",
";",
"count",
"<",
"(",
"length",
">>",
"1",
")",
";",
"count",
"++",
")",
"{",
"vdp_vram_write",
"(",
"vdp_get_word_from_68k_mem",
"(",
"machine",
",",
"source",
")",
")",
";",
"source",
"+=",
"2",
";",
"if",
"(",
"source",
">",
"0xffffff",
")",
"source",
"=",
"0xe00000",
";",
"}",
"megadrive_vdp_address",
"&=",
"0xffff",
";",
"megadrive_vdp_register",
"[",
"0x13",
"]",
"=",
"0",
";",
"megadrive_vdp_register",
"[",
"0x14",
"]",
"=",
"0",
";",
"megadrive_vdp_register",
"[",
"0x15",
"]",
"=",
"(",
"source",
">>",
"1",
")",
"&",
"0xff",
";",
"megadrive_vdp_register",
"[",
"0x16",
"]",
"=",
"(",
"source",
">>",
"9",
")",
"&",
"0xff",
";",
"megadrive_vdp_register",
"[",
"0x17",
"]",
"=",
"(",
"source",
">>",
"17",
")",
"&",
"0xff",
";",
"}"
] | Instant, but we pause the 68k a bit | [
"Instant",
"but",
"we",
"pause",
"the",
"68k",
"a",
"bit"
] | [
"/* This is a hack until real DMA timings are implemented */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "source",
"type": "UINT32"
},
{
"param": "length",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "source",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "length",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a40cc95189bf25d00b69cf1b7ea2ce5337738e8e | lofunz/mieme | Reloaded/trunk/src/mame/drivers/megadriv.c | [
"Unlicense"
] | C | megatech_bios_port_cc_dc_r | UINT8 | UINT8 megatech_bios_port_cc_dc_r(running_machine *machine, int offset, int ctrl)
{
UINT8 retdata;
if (ctrl == 0x55)
{
/* A keys */
retdata = ((input_port_read(machine, "PAD1") & 0x40) >> 2) |
((input_port_read(machine, "PAD2") & 0x40) >> 4) | 0xeb;
}
else
{
if (offset == 0)
{
retdata = (input_port_read(machine, "PAD1") & 0x3f) | ((input_port_read(machine, "PAD2") & 0x03) << 6);
}
else
{
retdata = ((input_port_read(machine, "PAD2") & 0x3c) >> 2) | 0xf0;
}
}
return retdata;
} | /* used by megatech bios, the test mode accesses the joypad/stick inputs like this */ | used by megatech bios, the test mode accesses the joypad/stick inputs like this | [
"used",
"by",
"megatech",
"bios",
"the",
"test",
"mode",
"accesses",
"the",
"joypad",
"/",
"stick",
"inputs",
"like",
"this"
] | UINT8 megatech_bios_port_cc_dc_r(running_machine *machine, int offset, int ctrl)
{
UINT8 retdata;
if (ctrl == 0x55)
{
retdata = ((input_port_read(machine, "PAD1") & 0x40) >> 2) |
((input_port_read(machine, "PAD2") & 0x40) >> 4) | 0xeb;
}
else
{
if (offset == 0)
{
retdata = (input_port_read(machine, "PAD1") & 0x3f) | ((input_port_read(machine, "PAD2") & 0x03) << 6);
}
else
{
retdata = ((input_port_read(machine, "PAD2") & 0x3c) >> 2) | 0xf0;
}
}
return retdata;
} | [
"UINT8",
"megatech_bios_port_cc_dc_r",
"(",
"running_machine",
"*",
"machine",
",",
"int",
"offset",
",",
"int",
"ctrl",
")",
"{",
"UINT8",
"retdata",
";",
"if",
"(",
"ctrl",
"==",
"0x55",
")",
"{",
"retdata",
"=",
"(",
"(",
"input_port_read",
"(",
"machine",
",",
"\"",
"\"",
")",
"&",
"0x40",
")",
">>",
"2",
")",
"|",
"(",
"(",
"input_port_read",
"(",
"machine",
",",
"\"",
"\"",
")",
"&",
"0x40",
")",
">>",
"4",
")",
"|",
"0xeb",
";",
"}",
"else",
"{",
"if",
"(",
"offset",
"==",
"0",
")",
"{",
"retdata",
"=",
"(",
"input_port_read",
"(",
"machine",
",",
"\"",
"\"",
")",
"&",
"0x3f",
")",
"|",
"(",
"(",
"input_port_read",
"(",
"machine",
",",
"\"",
"\"",
")",
"&",
"0x03",
")",
"<<",
"6",
")",
";",
"}",
"else",
"{",
"retdata",
"=",
"(",
"(",
"input_port_read",
"(",
"machine",
",",
"\"",
"\"",
")",
"&",
"0x3c",
")",
">>",
"2",
")",
"|",
"0xf0",
";",
"}",
"}",
"return",
"retdata",
";",
"}"
] | used by megatech bios, the test mode accesses the joypad/stick inputs like this | [
"used",
"by",
"megatech",
"bios",
"the",
"test",
"mode",
"accesses",
"the",
"joypad",
"/",
"stick",
"inputs",
"like",
"this"
] | [
"/* A keys */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "offset",
"type": "int"
},
{
"param": "ctrl",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "offset",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ctrl",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a40cc95189bf25d00b69cf1b7ea2ce5337738e8e | lofunz/mieme | Reloaded/trunk/src/mame/drivers/megadriv.c | [
"Unlicense"
] | C | genesis_render_videobuffer_to_screenbuffer | void | static void genesis_render_videobuffer_to_screenbuffer(running_machine *machine, int scanline)
{
UINT16*lineptr;
int x;
lineptr = BITMAP_ADDR16(render_bitmap, scanline, 0);
/* render 32x output to a buffer */
if (_32x_is_connected && (_32x_displaymode != 0))
{
if (_32x_displaymode==1)
{
UINT32 lineoffs;
int start;
lineoffs = _32x_display_dram[scanline];
if (_32x_screenshift == 0) start=0;
else start = -1;
for (x=start;x<320;x++)
{
UINT16 coldata;
coldata = _32x_display_dram[lineoffs];
{
if (x>=0)
{
_32x_linerender[x] = _32x_palette_lookup[(coldata & 0xff00)>>8];
}
x++;
if (x>=0)
{
_32x_linerender[x] = _32x_palette_lookup[(coldata & 0x00ff)];
}
}
lineoffs++;
}
}
else if (_32x_displaymode==3) // mode 3 = RLE (used by BRUTAL intro)
{
UINT32 lineoffs;
int start;
lineoffs = _32x_display_dram[scanline];
if (_32x_screenshift == 0) start=0;
else start = -1;
x = start;
while (x<320)
{
UINT16 coldata, length, l;
coldata = _32x_display_dram[lineoffs];
length = ((coldata & 0xff00)>>8)+1;
coldata = (coldata & 0x00ff)>>0;
for (l=0;l<length;l++)
{
if (x>=0)
{
_32x_linerender[x] = _32x_palette_lookup[(coldata)];
}
x++;
}
lineoffs++;
}
}
else // MODE 2 - 15bpp mode, not used by any commercial games?
{
UINT32 lineoffs;
int start;
lineoffs = _32x_display_dram[scanline];
if (_32x_screenshift == 0) start=0;
else start = -1;
x = start;
while (x<320)
{
UINT16 coldata;
coldata = _32x_display_dram[lineoffs&0xffff];
// need to swap red and blue around for MAME
{
int r = ((coldata >> 0) & 0x1f);
int g = ((coldata >> 5) & 0x1f);
int b = ((coldata >> 10) & 0x1f);
int p = ((coldata >> 15) & 0x01); // priority 'through' bit
coldata = (r << 10) | (g << 5) | (b << 0) | (p << 15);
}
if (x>=0)
_32x_linerender[x] = coldata;
x++;
lineoffs++;
}
}
}
if (!MEGADRIVE_REG0C_SHADOW_HIGLIGHT)
{
for (x=0;x<320;x++)
{
UINT32 dat;
dat = video_renderline[x];
if ((dat&0x20000) && (_32x_is_connected) && (_32x_displaymode != 0))
{
if (_32x_linerender[x]&0x8000)
{
if (_32x_videopriority)
{
lineptr[x] = _32x_linerender[x]&0x7fff;
}
else
{
// display md bg?
}
}
else
{
if (_32x_videopriority)
{
// display md bg?
}
else
{
lineptr[x] = _32x_linerender[x]&0x7fff;
}
}
}
else
{
if (dat&0x10000)
lineptr[x] = megadrive_vdp_palette_lookup_sprite[(dat&0x0f) | segac2_sp_pal_lookup[(dat&0x30)>>4]];
else
lineptr[x] = megadrive_vdp_palette_lookup[(dat&0x0f) | segac2_bg_pal_lookup[(dat&0x30)>>4]];
}
}
}
else
{
for (x=0;x<320;x++)
{
UINT32 dat;
dat = video_renderline[x];
if ((dat&0x20000) && (_32x_is_connected) && (_32x_displaymode != 0))
{
if (_32x_linerender[x]&0x8000)
{
if (_32x_videopriority)
{
lineptr[x] = _32x_linerender[x]&0x7fff;
}
else
{
// display md bg?
}
}
else
{
if (_32x_videopriority)
{
// display md bg?
}
else
{
lineptr[x] = _32x_linerender[x]&0x7fff;
}
}
}
else
{
/* Verify my handling.. I'm not sure all cases are correct */
switch (dat&0x1e000)
{
case 0x00000: // low priority, no shadow sprite, no highlight = shadow
case 0x02000: // low priority, shadow sprite, no highlight = shadow
case 0x06000: // normal pri, shadow sprite, no highlight = shadow?
case 0x10000: // (sprite) low priority, no shadow sprite, no highlight = shadow
case 0x12000: // (sprite) low priority, shadow sprite, no highlight = shadow
case 0x16000: // (sprite) normal pri, shadow sprite, no highlight = shadow?
lineptr[x] = megadrive_vdp_palette_lookup_shadow[(dat&0x0f) | segac2_bg_pal_lookup[(dat&0x30)>>4]];
break;
case 0x4000: // normal pri, no shadow sprite, no highlight = normal;
case 0x8000: // low pri, highlight sprite = normal;
lineptr[x] = megadrive_vdp_palette_lookup[(dat&0x0f) | segac2_bg_pal_lookup[(dat&0x30)>>4]];
break;
case 0x14000: // (sprite) normal pri, no shadow sprite, no highlight = normal;
case 0x18000: // (sprite) low pri, highlight sprite = normal;
lineptr[x] = megadrive_vdp_palette_lookup_sprite[(dat&0x0f) | segac2_sp_pal_lookup[(dat&0x30)>>4]];
break;
case 0x0c000: // normal pri, highlight set = highlight?
case 0x1c000: // (sprite) normal pri, highlight set = highlight?
lineptr[x] = megadrive_vdp_palette_lookup_highlight[(dat&0x0f) | segac2_bg_pal_lookup[(dat&0x30)>>4]];
break;
case 0x0a000: // shadow set, highlight set - not possible
case 0x0e000: // shadow set, highlight set, normal set, not possible
case 0x1a000: // (sprite)shadow set, highlight set - not possible
case 0x1e000: // (sprite)shadow set, highlight set, normal set, not possible
default:
lineptr[x] = mame_rand(machine)&0x3f;
break;
}
}
}
}
if (_32x_is_connected && ( _32x_displaymode != 0))
{
for (x=0;x<320;x++)
{
if (_32x_linerender[x]&0x8000)
{
if (_32x_videopriority)
{
// display md screen?
}
else
{
lineptr[x] = _32x_linerender[x]&0x7fff;
}
}
else
{
if (_32x_videopriority)
{
lineptr[x] = _32x_linerender[x]&0x7fff;
}
else
{
// display md screen?
}
}
}
}
} | /* This converts our render buffer to real screen colours */ | This converts our render buffer to real screen colours | [
"This",
"converts",
"our",
"render",
"buffer",
"to",
"real",
"screen",
"colours"
] | static void genesis_render_videobuffer_to_screenbuffer(running_machine *machine, int scanline)
{
UINT16*lineptr;
int x;
lineptr = BITMAP_ADDR16(render_bitmap, scanline, 0);
if (_32x_is_connected && (_32x_displaymode != 0))
{
if (_32x_displaymode==1)
{
UINT32 lineoffs;
int start;
lineoffs = _32x_display_dram[scanline];
if (_32x_screenshift == 0) start=0;
else start = -1;
for (x=start;x<320;x++)
{
UINT16 coldata;
coldata = _32x_display_dram[lineoffs];
{
if (x>=0)
{
_32x_linerender[x] = _32x_palette_lookup[(coldata & 0xff00)>>8];
}
x++;
if (x>=0)
{
_32x_linerender[x] = _32x_palette_lookup[(coldata & 0x00ff)];
}
}
lineoffs++;
}
}
else if (_32x_displaymode==3)
{
UINT32 lineoffs;
int start;
lineoffs = _32x_display_dram[scanline];
if (_32x_screenshift == 0) start=0;
else start = -1;
x = start;
while (x<320)
{
UINT16 coldata, length, l;
coldata = _32x_display_dram[lineoffs];
length = ((coldata & 0xff00)>>8)+1;
coldata = (coldata & 0x00ff)>>0;
for (l=0;l<length;l++)
{
if (x>=0)
{
_32x_linerender[x] = _32x_palette_lookup[(coldata)];
}
x++;
}
lineoffs++;
}
}
else
{
UINT32 lineoffs;
int start;
lineoffs = _32x_display_dram[scanline];
if (_32x_screenshift == 0) start=0;
else start = -1;
x = start;
while (x<320)
{
UINT16 coldata;
coldata = _32x_display_dram[lineoffs&0xffff];
{
int r = ((coldata >> 0) & 0x1f);
int g = ((coldata >> 5) & 0x1f);
int b = ((coldata >> 10) & 0x1f);
int p = ((coldata >> 15) & 0x01);
coldata = (r << 10) | (g << 5) | (b << 0) | (p << 15);
}
if (x>=0)
_32x_linerender[x] = coldata;
x++;
lineoffs++;
}
}
}
if (!MEGADRIVE_REG0C_SHADOW_HIGLIGHT)
{
for (x=0;x<320;x++)
{
UINT32 dat;
dat = video_renderline[x];
if ((dat&0x20000) && (_32x_is_connected) && (_32x_displaymode != 0))
{
if (_32x_linerender[x]&0x8000)
{
if (_32x_videopriority)
{
lineptr[x] = _32x_linerender[x]&0x7fff;
}
else
{
}
}
else
{
if (_32x_videopriority)
{
}
else
{
lineptr[x] = _32x_linerender[x]&0x7fff;
}
}
}
else
{
if (dat&0x10000)
lineptr[x] = megadrive_vdp_palette_lookup_sprite[(dat&0x0f) | segac2_sp_pal_lookup[(dat&0x30)>>4]];
else
lineptr[x] = megadrive_vdp_palette_lookup[(dat&0x0f) | segac2_bg_pal_lookup[(dat&0x30)>>4]];
}
}
}
else
{
for (x=0;x<320;x++)
{
UINT32 dat;
dat = video_renderline[x];
if ((dat&0x20000) && (_32x_is_connected) && (_32x_displaymode != 0))
{
if (_32x_linerender[x]&0x8000)
{
if (_32x_videopriority)
{
lineptr[x] = _32x_linerender[x]&0x7fff;
}
else
{
}
}
else
{
if (_32x_videopriority)
{
}
else
{
lineptr[x] = _32x_linerender[x]&0x7fff;
}
}
}
else
{
switch (dat&0x1e000)
{
case 0x00000:
case 0x02000:
case 0x06000:
case 0x10000:
case 0x12000:
case 0x16000:
lineptr[x] = megadrive_vdp_palette_lookup_shadow[(dat&0x0f) | segac2_bg_pal_lookup[(dat&0x30)>>4]];
break;
case 0x4000:
case 0x8000:
lineptr[x] = megadrive_vdp_palette_lookup[(dat&0x0f) | segac2_bg_pal_lookup[(dat&0x30)>>4]];
break;
case 0x14000:
case 0x18000:
lineptr[x] = megadrive_vdp_palette_lookup_sprite[(dat&0x0f) | segac2_sp_pal_lookup[(dat&0x30)>>4]];
break;
case 0x0c000:
case 0x1c000:
lineptr[x] = megadrive_vdp_palette_lookup_highlight[(dat&0x0f) | segac2_bg_pal_lookup[(dat&0x30)>>4]];
break;
case 0x0a000:
case 0x0e000:
case 0x1a000:
case 0x1e000:
default:
lineptr[x] = mame_rand(machine)&0x3f;
break;
}
}
}
}
if (_32x_is_connected && ( _32x_displaymode != 0))
{
for (x=0;x<320;x++)
{
if (_32x_linerender[x]&0x8000)
{
if (_32x_videopriority)
{
}
else
{
lineptr[x] = _32x_linerender[x]&0x7fff;
}
}
else
{
if (_32x_videopriority)
{
lineptr[x] = _32x_linerender[x]&0x7fff;
}
else
{
}
}
}
}
} | [
"static",
"void",
"genesis_render_videobuffer_to_screenbuffer",
"(",
"running_machine",
"*",
"machine",
",",
"int",
"scanline",
")",
"{",
"UINT16",
"*",
"lineptr",
";",
"int",
"x",
";",
"lineptr",
"=",
"BITMAP_ADDR16",
"(",
"render_bitmap",
",",
"scanline",
",",
"0",
")",
";",
"if",
"(",
"_32x_is_connected",
"&&",
"(",
"_32x_displaymode",
"!=",
"0",
")",
")",
"{",
"if",
"(",
"_32x_displaymode",
"==",
"1",
")",
"{",
"UINT32",
"lineoffs",
";",
"int",
"start",
";",
"lineoffs",
"=",
"_32x_display_dram",
"[",
"scanline",
"]",
";",
"if",
"(",
"_32x_screenshift",
"==",
"0",
")",
"start",
"=",
"0",
";",
"else",
"start",
"=",
"-1",
";",
"for",
"(",
"x",
"=",
"start",
";",
"x",
"<",
"320",
";",
"x",
"++",
")",
"{",
"UINT16",
"coldata",
";",
"coldata",
"=",
"_32x_display_dram",
"[",
"lineoffs",
"]",
";",
"{",
"if",
"(",
"x",
">=",
"0",
")",
"{",
"_32x_linerender",
"[",
"x",
"]",
"=",
"_32x_palette_lookup",
"[",
"(",
"coldata",
"&",
"0xff00",
")",
">>",
"8",
"]",
";",
"}",
"x",
"++",
";",
"if",
"(",
"x",
">=",
"0",
")",
"{",
"_32x_linerender",
"[",
"x",
"]",
"=",
"_32x_palette_lookup",
"[",
"(",
"coldata",
"&",
"0x00ff",
")",
"]",
";",
"}",
"}",
"lineoffs",
"++",
";",
"}",
"}",
"else",
"if",
"(",
"_32x_displaymode",
"==",
"3",
")",
"{",
"UINT32",
"lineoffs",
";",
"int",
"start",
";",
"lineoffs",
"=",
"_32x_display_dram",
"[",
"scanline",
"]",
";",
"if",
"(",
"_32x_screenshift",
"==",
"0",
")",
"start",
"=",
"0",
";",
"else",
"start",
"=",
"-1",
";",
"x",
"=",
"start",
";",
"while",
"(",
"x",
"<",
"320",
")",
"{",
"UINT16",
"coldata",
",",
"length",
",",
"l",
";",
"coldata",
"=",
"_32x_display_dram",
"[",
"lineoffs",
"]",
";",
"length",
"=",
"(",
"(",
"coldata",
"&",
"0xff00",
")",
">>",
"8",
")",
"+",
"1",
";",
"coldata",
"=",
"(",
"coldata",
"&",
"0x00ff",
")",
">>",
"0",
";",
"for",
"(",
"l",
"=",
"0",
";",
"l",
"<",
"length",
";",
"l",
"++",
")",
"{",
"if",
"(",
"x",
">=",
"0",
")",
"{",
"_32x_linerender",
"[",
"x",
"]",
"=",
"_32x_palette_lookup",
"[",
"(",
"coldata",
")",
"]",
";",
"}",
"x",
"++",
";",
"}",
"lineoffs",
"++",
";",
"}",
"}",
"else",
"{",
"UINT32",
"lineoffs",
";",
"int",
"start",
";",
"lineoffs",
"=",
"_32x_display_dram",
"[",
"scanline",
"]",
";",
"if",
"(",
"_32x_screenshift",
"==",
"0",
")",
"start",
"=",
"0",
";",
"else",
"start",
"=",
"-1",
";",
"x",
"=",
"start",
";",
"while",
"(",
"x",
"<",
"320",
")",
"{",
"UINT16",
"coldata",
";",
"coldata",
"=",
"_32x_display_dram",
"[",
"lineoffs",
"&",
"0xffff",
"]",
";",
"{",
"int",
"r",
"=",
"(",
"(",
"coldata",
">>",
"0",
")",
"&",
"0x1f",
")",
";",
"int",
"g",
"=",
"(",
"(",
"coldata",
">>",
"5",
")",
"&",
"0x1f",
")",
";",
"int",
"b",
"=",
"(",
"(",
"coldata",
">>",
"10",
")",
"&",
"0x1f",
")",
";",
"int",
"p",
"=",
"(",
"(",
"coldata",
">>",
"15",
")",
"&",
"0x01",
")",
";",
"coldata",
"=",
"(",
"r",
"<<",
"10",
")",
"|",
"(",
"g",
"<<",
"5",
")",
"|",
"(",
"b",
"<<",
"0",
")",
"|",
"(",
"p",
"<<",
"15",
")",
";",
"}",
"if",
"(",
"x",
">=",
"0",
")",
"_32x_linerender",
"[",
"x",
"]",
"=",
"coldata",
";",
"x",
"++",
";",
"lineoffs",
"++",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"MEGADRIVE_REG0C_SHADOW_HIGLIGHT",
")",
"{",
"for",
"(",
"x",
"=",
"0",
";",
"x",
"<",
"320",
";",
"x",
"++",
")",
"{",
"UINT32",
"dat",
";",
"dat",
"=",
"video_renderline",
"[",
"x",
"]",
";",
"if",
"(",
"(",
"dat",
"&",
"0x20000",
")",
"&&",
"(",
"_32x_is_connected",
")",
"&&",
"(",
"_32x_displaymode",
"!=",
"0",
")",
")",
"{",
"if",
"(",
"_32x_linerender",
"[",
"x",
"]",
"&",
"0x8000",
")",
"{",
"if",
"(",
"_32x_videopriority",
")",
"{",
"lineptr",
"[",
"x",
"]",
"=",
"_32x_linerender",
"[",
"x",
"]",
"&",
"0x7fff",
";",
"}",
"else",
"{",
"}",
"}",
"else",
"{",
"if",
"(",
"_32x_videopriority",
")",
"{",
"}",
"else",
"{",
"lineptr",
"[",
"x",
"]",
"=",
"_32x_linerender",
"[",
"x",
"]",
"&",
"0x7fff",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"dat",
"&",
"0x10000",
")",
"lineptr",
"[",
"x",
"]",
"=",
"megadrive_vdp_palette_lookup_sprite",
"[",
"(",
"dat",
"&",
"0x0f",
")",
"|",
"segac2_sp_pal_lookup",
"[",
"(",
"dat",
"&",
"0x30",
")",
">>",
"4",
"]",
"]",
";",
"else",
"lineptr",
"[",
"x",
"]",
"=",
"megadrive_vdp_palette_lookup",
"[",
"(",
"dat",
"&",
"0x0f",
")",
"|",
"segac2_bg_pal_lookup",
"[",
"(",
"dat",
"&",
"0x30",
")",
">>",
"4",
"]",
"]",
";",
"}",
"}",
"}",
"else",
"{",
"for",
"(",
"x",
"=",
"0",
";",
"x",
"<",
"320",
";",
"x",
"++",
")",
"{",
"UINT32",
"dat",
";",
"dat",
"=",
"video_renderline",
"[",
"x",
"]",
";",
"if",
"(",
"(",
"dat",
"&",
"0x20000",
")",
"&&",
"(",
"_32x_is_connected",
")",
"&&",
"(",
"_32x_displaymode",
"!=",
"0",
")",
")",
"{",
"if",
"(",
"_32x_linerender",
"[",
"x",
"]",
"&",
"0x8000",
")",
"{",
"if",
"(",
"_32x_videopriority",
")",
"{",
"lineptr",
"[",
"x",
"]",
"=",
"_32x_linerender",
"[",
"x",
"]",
"&",
"0x7fff",
";",
"}",
"else",
"{",
"}",
"}",
"else",
"{",
"if",
"(",
"_32x_videopriority",
")",
"{",
"}",
"else",
"{",
"lineptr",
"[",
"x",
"]",
"=",
"_32x_linerender",
"[",
"x",
"]",
"&",
"0x7fff",
";",
"}",
"}",
"}",
"else",
"{",
"switch",
"(",
"dat",
"&",
"0x1e000",
")",
"{",
"case",
"0x00000",
":",
"case",
"0x02000",
":",
"case",
"0x06000",
":",
"case",
"0x10000",
":",
"case",
"0x12000",
":",
"case",
"0x16000",
":",
"lineptr",
"[",
"x",
"]",
"=",
"megadrive_vdp_palette_lookup_shadow",
"[",
"(",
"dat",
"&",
"0x0f",
")",
"|",
"segac2_bg_pal_lookup",
"[",
"(",
"dat",
"&",
"0x30",
")",
">>",
"4",
"]",
"]",
";",
"break",
";",
"case",
"0x4000",
":",
"case",
"0x8000",
":",
"lineptr",
"[",
"x",
"]",
"=",
"megadrive_vdp_palette_lookup",
"[",
"(",
"dat",
"&",
"0x0f",
")",
"|",
"segac2_bg_pal_lookup",
"[",
"(",
"dat",
"&",
"0x30",
")",
">>",
"4",
"]",
"]",
";",
"break",
";",
"case",
"0x14000",
":",
"case",
"0x18000",
":",
"lineptr",
"[",
"x",
"]",
"=",
"megadrive_vdp_palette_lookup_sprite",
"[",
"(",
"dat",
"&",
"0x0f",
")",
"|",
"segac2_sp_pal_lookup",
"[",
"(",
"dat",
"&",
"0x30",
")",
">>",
"4",
"]",
"]",
";",
"break",
";",
"case",
"0x0c000",
":",
"case",
"0x1c000",
":",
"lineptr",
"[",
"x",
"]",
"=",
"megadrive_vdp_palette_lookup_highlight",
"[",
"(",
"dat",
"&",
"0x0f",
")",
"|",
"segac2_bg_pal_lookup",
"[",
"(",
"dat",
"&",
"0x30",
")",
">>",
"4",
"]",
"]",
";",
"break",
";",
"case",
"0x0a000",
":",
"case",
"0x0e000",
":",
"case",
"0x1a000",
":",
"case",
"0x1e000",
":",
"default",
":",
"lineptr",
"[",
"x",
"]",
"=",
"mame_rand",
"(",
"machine",
")",
"&",
"0x3f",
";",
"break",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"_32x_is_connected",
"&&",
"(",
"_32x_displaymode",
"!=",
"0",
")",
")",
"{",
"for",
"(",
"x",
"=",
"0",
";",
"x",
"<",
"320",
";",
"x",
"++",
")",
"{",
"if",
"(",
"_32x_linerender",
"[",
"x",
"]",
"&",
"0x8000",
")",
"{",
"if",
"(",
"_32x_videopriority",
")",
"{",
"}",
"else",
"{",
"lineptr",
"[",
"x",
"]",
"=",
"_32x_linerender",
"[",
"x",
"]",
"&",
"0x7fff",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"_32x_videopriority",
")",
"{",
"lineptr",
"[",
"x",
"]",
"=",
"_32x_linerender",
"[",
"x",
"]",
"&",
"0x7fff",
";",
"}",
"else",
"{",
"}",
"}",
"}",
"}",
"}"
] | This converts our render buffer to real screen colours | [
"This",
"converts",
"our",
"render",
"buffer",
"to",
"real",
"screen",
"colours"
] | [
"/* render 32x output to a buffer */",
"// mode 3 = RLE (used by BRUTAL intro)\r",
"// MODE 2 - 15bpp mode, not used by any commercial games?\r",
"// need to swap red and blue around for MAME\r",
"// priority 'through' bit\r",
"// display md bg?\r",
"// display md bg?\r",
"// display md bg?\r",
"// display md bg?\r",
"/* Verify my handling.. I'm not sure all cases are correct */",
"// low priority, no shadow sprite, no highlight = shadow\r",
"// low priority, shadow sprite, no highlight = shadow\r",
"// normal pri, shadow sprite, no highlight = shadow?\r",
"// (sprite) low priority, no shadow sprite, no highlight = shadow\r",
"// (sprite) low priority, shadow sprite, no highlight = shadow\r",
"// (sprite) normal pri, shadow sprite, no highlight = shadow?\r",
"// normal pri, no shadow sprite, no highlight = normal;\r",
"// low pri, highlight sprite = normal;\r",
"// (sprite) normal pri, no shadow sprite, no highlight = normal;\r",
"// (sprite) low pri, highlight sprite = normal;\r",
"// normal pri, highlight set = highlight?\r",
"// (sprite) normal pri, highlight set = highlight?\r",
"// shadow set, highlight set - not possible\r",
"// shadow set, highlight set, normal set, not possible\r",
"// (sprite)shadow set, highlight set - not possible\r",
"// (sprite)shadow set, highlight set, normal set, not possible\r",
"// display md screen?\r",
"// display md screen?\r"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "scanline",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "scanline",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a40cc95189bf25d00b69cf1b7ea2ce5337738e8e | lofunz/mieme | Reloaded/trunk/src/mame/drivers/megadriv.c | [
"Unlicense"
] | C | megatech_set_megadrive_z80_as_megadrive_z80 | void | void megatech_set_megadrive_z80_as_megadrive_z80(running_machine *machine, const char* tag)
{
running_device *ym = machine->device("ymsnd");
/* INIT THE PORTS *********************************************************************************************/
memory_install_readwrite8_handler(cputag_get_address_space(machine, tag, ADDRESS_SPACE_IO), 0x0000, 0xffff, 0, 0, z80_unmapped_port_r, z80_unmapped_port_w);
/* catch any addresses that don't get mapped */
memory_install_readwrite8_handler(cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x0000, 0xffff, 0, 0, z80_unmapped_r, z80_unmapped_w);
memory_install_readwrite_bank(cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x0000, 0x1fff, 0, 0, "bank1");
memory_set_bankptr(machine, "bank1", genz80.z80_prgram );
memory_install_ram(cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x0000, 0x1fff, 0, 0, genz80.z80_prgram);
// not allowed??
// memory_install_readwrite_bank(cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x2000, 0x3fff, 0, 0, "bank1");
memory_install_readwrite8_device_handler(cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), ym, 0x4000, 0x4003, 0, 0, ym2612_r, ym2612_w);
memory_install_write8_handler (cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x6000, 0x6000, 0, 0, megadriv_z80_z80_bank_w);
memory_install_write8_handler (cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x6001, 0x6001, 0, 0, megadriv_z80_z80_bank_w);
memory_install_read8_handler (cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x6100, 0x7eff, 0, 0, megadriv_z80_unmapped_read);
memory_install_readwrite8_handler(cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x7f00, 0x7fff, 0, 0, megadriv_z80_vdp_read, megadriv_z80_vdp_write);
memory_install_readwrite8_handler(cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, z80_read_68k_banked_data, z80_write_68k_banked_data);
} | /* sets the megadrive z80 to it's normal ports / map */ | sets the megadrive z80 to it's normal ports / map | [
"sets",
"the",
"megadrive",
"z80",
"to",
"it",
"'",
"s",
"normal",
"ports",
"/",
"map"
] | void megatech_set_megadrive_z80_as_megadrive_z80(running_machine *machine, const char* tag)
{
running_device *ym = machine->device("ymsnd");
memory_install_readwrite8_handler(cputag_get_address_space(machine, tag, ADDRESS_SPACE_IO), 0x0000, 0xffff, 0, 0, z80_unmapped_port_r, z80_unmapped_port_w);
memory_install_readwrite8_handler(cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x0000, 0xffff, 0, 0, z80_unmapped_r, z80_unmapped_w);
memory_install_readwrite_bank(cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x0000, 0x1fff, 0, 0, "bank1");
memory_set_bankptr(machine, "bank1", genz80.z80_prgram );
memory_install_ram(cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x0000, 0x1fff, 0, 0, genz80.z80_prgram);
memory_install_readwrite8_device_handler(cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), ym, 0x4000, 0x4003, 0, 0, ym2612_r, ym2612_w);
memory_install_write8_handler (cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x6000, 0x6000, 0, 0, megadriv_z80_z80_bank_w);
memory_install_write8_handler (cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x6001, 0x6001, 0, 0, megadriv_z80_z80_bank_w);
memory_install_read8_handler (cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x6100, 0x7eff, 0, 0, megadriv_z80_unmapped_read);
memory_install_readwrite8_handler(cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x7f00, 0x7fff, 0, 0, megadriv_z80_vdp_read, megadriv_z80_vdp_write);
memory_install_readwrite8_handler(cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, z80_read_68k_banked_data, z80_write_68k_banked_data);
} | [
"void",
"megatech_set_megadrive_z80_as_megadrive_z80",
"(",
"running_machine",
"*",
"machine",
",",
"const",
"char",
"*",
"tag",
")",
"{",
"running_device",
"*",
"ym",
"=",
"machine",
"->",
"device",
"(",
"\"",
"\"",
")",
";",
"memory_install_readwrite8_handler",
"(",
"cputag_get_address_space",
"(",
"machine",
",",
"tag",
",",
"ADDRESS_SPACE_IO",
")",
",",
"0x0000",
",",
"0xffff",
",",
"0",
",",
"0",
",",
"z80_unmapped_port_r",
",",
"z80_unmapped_port_w",
")",
";",
"memory_install_readwrite8_handler",
"(",
"cputag_get_address_space",
"(",
"machine",
",",
"tag",
",",
"ADDRESS_SPACE_PROGRAM",
")",
",",
"0x0000",
",",
"0xffff",
",",
"0",
",",
"0",
",",
"z80_unmapped_r",
",",
"z80_unmapped_w",
")",
";",
"memory_install_readwrite_bank",
"(",
"cputag_get_address_space",
"(",
"machine",
",",
"tag",
",",
"ADDRESS_SPACE_PROGRAM",
")",
",",
"0x0000",
",",
"0x1fff",
",",
"0",
",",
"0",
",",
"\"",
"\"",
")",
";",
"memory_set_bankptr",
"(",
"machine",
",",
"\"",
"\"",
",",
"genz80",
".",
"z80_prgram",
")",
";",
"memory_install_ram",
"(",
"cputag_get_address_space",
"(",
"machine",
",",
"tag",
",",
"ADDRESS_SPACE_PROGRAM",
")",
",",
"0x0000",
",",
"0x1fff",
",",
"0",
",",
"0",
",",
"genz80",
".",
"z80_prgram",
")",
";",
"memory_install_readwrite8_device_handler",
"(",
"cputag_get_address_space",
"(",
"machine",
",",
"tag",
",",
"ADDRESS_SPACE_PROGRAM",
")",
",",
"ym",
",",
"0x4000",
",",
"0x4003",
",",
"0",
",",
"0",
",",
"ym2612_r",
",",
"ym2612_w",
")",
";",
"memory_install_write8_handler",
"(",
"cputag_get_address_space",
"(",
"machine",
",",
"tag",
",",
"ADDRESS_SPACE_PROGRAM",
")",
",",
"0x6000",
",",
"0x6000",
",",
"0",
",",
"0",
",",
"megadriv_z80_z80_bank_w",
")",
";",
"memory_install_write8_handler",
"(",
"cputag_get_address_space",
"(",
"machine",
",",
"tag",
",",
"ADDRESS_SPACE_PROGRAM",
")",
",",
"0x6001",
",",
"0x6001",
",",
"0",
",",
"0",
",",
"megadriv_z80_z80_bank_w",
")",
";",
"memory_install_read8_handler",
"(",
"cputag_get_address_space",
"(",
"machine",
",",
"tag",
",",
"ADDRESS_SPACE_PROGRAM",
")",
",",
"0x6100",
",",
"0x7eff",
",",
"0",
",",
"0",
",",
"megadriv_z80_unmapped_read",
")",
";",
"memory_install_readwrite8_handler",
"(",
"cputag_get_address_space",
"(",
"machine",
",",
"tag",
",",
"ADDRESS_SPACE_PROGRAM",
")",
",",
"0x7f00",
",",
"0x7fff",
",",
"0",
",",
"0",
",",
"megadriv_z80_vdp_read",
",",
"megadriv_z80_vdp_write",
")",
";",
"memory_install_readwrite8_handler",
"(",
"cputag_get_address_space",
"(",
"machine",
",",
"tag",
",",
"ADDRESS_SPACE_PROGRAM",
")",
",",
"0x8000",
",",
"0xffff",
",",
"0",
",",
"0",
",",
"z80_read_68k_banked_data",
",",
"z80_write_68k_banked_data",
")",
";",
"}"
] | sets the megadrive z80 to it's normal ports / map | [
"sets",
"the",
"megadrive",
"z80",
"to",
"it",
"'",
"s",
"normal",
"ports",
"/",
"map"
] | [
"/* INIT THE PORTS *********************************************************************************************/",
"/* catch any addresses that don't get mapped */",
"// not allowed??\r",
"// memory_install_readwrite_bank(cputag_get_address_space(machine, tag, ADDRESS_SPACE_PROGRAM), 0x2000, 0x3fff, 0, 0, \"bank1\");\r"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "tag",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"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": []
} |
240b60e3026321643387a5c4f5cb178b8c8bed05 | lofunz/mieme | Reloaded/trunk/src/mame/drivers/atarisy4.c | [
"Unlicense"
] | C | execute_gpu_command | void | void execute_gpu_command(running_machine *machine)
{
switch (gpu.ecr)
{
case 0x04:
{
gpu.transpose = 0;
break;
}
case 0x05:
{
gpu.transpose = 1;
break;
}
case 0x06:
{
gpu.idr = gpu.gr[0];
break;
}
case 0x07:
{
gpu.icd = gpu.gr[0];
break;
}
case 0x09:
{
gpu.clip_max_x = gpu.gr[0];
gpu.clip_min_x = gpu.gr[1];
gpu.clip_max_y = gpu.gr[2];
gpu.clip_min_y = gpu.gr[3];
break;
}
case 0x0b:
{
// Wait for VBLANK and swap buffers?
gpu.vblank_wait = 1;
break;
}
case 0x16:
{
/*
Copy screen RAM to color RAM
GR0 : Color start X
GR1 : Color start Y
GR2 : Color table offset
GR3 : Size
GR4 : Channels to set (R: 0x10, G: 0x20, B: 0x40)
*/
int i;
int offset = xy_to_screen_addr(gpu.gr[0] - 0x400, gpu.gr[1] - 0x200);
int table_offs = gpu.gr[2];
for (i = 0; i < gpu.gr[3]; ++i)
{
UINT16 val = screen_ram[offset >> 1];
val >>= (~offset & 1) << 3;
if (gpu.gr[4] & 0x10)
r_color_table[table_offs] = val;
if (gpu.gr[4] & 0x20)
g_color_table[table_offs] = val;
if (gpu.gr[4] & 0x40)
b_color_table[table_offs] = val;
/* Update */
palette_set_color(machine, table_offs, MAKE_RGB(r_color_table[table_offs], g_color_table[table_offs], b_color_table[table_offs]));
++table_offs;
++offset;
}
break;
}
case 0x20:
{
image_mem_to_screen(false);
break;
}
case 0x21:
{
image_mem_to_screen(true);
break;
}
case 0x28:
{
gpu.points[0].x = gpu.gr[0] - 0x400;
gpu.points[0].y = gpu.gr[1] - 0x200;
gpu.pt_idx = 0;
break;
}
case 0x29:
{
gpu.points[0].x = gpu.points[gpu.pt_idx].x + gpu.gr[0];
gpu.points[0].y = gpu.points[gpu.pt_idx].y + gpu.gr[1];
gpu.pt_idx = 0;
break;
}
case 0x2a:
{
++gpu.pt_idx;
gpu.points[gpu.pt_idx].x = gpu.gr[0] - 0x400;
gpu.points[gpu.pt_idx].y = gpu.gr[1] - 0x200;
break;
}
case 0x2b:
{
UINT16 x = gpu.points[gpu.pt_idx].x + gpu.gr[0];
UINT16 y = gpu.points[gpu.pt_idx].y + gpu.gr[1];
++gpu.pt_idx;
gpu.points[gpu.pt_idx].x = x;
gpu.points[gpu.pt_idx].y = y;
break;
}
case 0x2c:
{
draw_polygon(gpu.gr[2]);
poly_wait(poly, "Normal");
break;
}
default:
logerror("GPU COMMAND: %x\n", gpu.ecr);
}
} | /*
GPU commands
REXP 0x00 Reset expansion
SEXP 0x01 Set expansion
ROFF 0x02 Reset offset on update
SOFF 0x03 Set offset
RTPS 0x04 Reset transposition
STPS 0x05 Set transposition
SIMD 0x06 Load IDR register
SICD 0x07 Load partial transfer compare value
RCW 0x08 Reset clipping window
SCW 0x09 Set clipping window
WVB 0x0B Wait for VBlank
FXOT 0x10 Fill x offset table
FYOT 0x11 Fill y offset table
FERT 0x14 Fill expansion table
FCT 0x15 Fill color table
SMCT 0x16 Screen memory to color table
ITSN 0x20 Image memory to screen memory transfer
ITSC 0x21 Image memory to screen memory transfer with clip
PPA 0x24 Plot point absolute
PFOA 0x28 Polygon open absolute
PFOR 0x29 Polygon open relative
PFVA 0x2A Polygon vector absolute
PFVR 0x2B Polygon vector relative
PFC 0x2C Polygon close
*/ | GPU commands
REXP 0x00 Reset expansion
SEXP 0x01 Set expansion
ROFF 0x02 Reset offset on update
SOFF 0x03 Set offset
RTPS 0x04 Reset transposition
STPS 0x05 Set transposition
SIMD 0x06 Load IDR register
SICD 0x07 Load partial transfer compare value
RCW 0x08 Reset clipping window
SCW 0x09 Set clipping window
WVB 0x0B Wait for VBlank
FXOT 0x10 Fill x offset table
FYOT 0x11 Fill y offset table
FERT 0x14 Fill expansion table
FCT 0x15 Fill color table
SMCT 0x16 Screen memory to color table
ITSN 0x20 Image memory to screen memory transfer
ITSC 0x21 Image memory to screen memory transfer with clip
PPA 0x24 Plot point absolute
PFOA 0x28 Polygon open absolute
PFOR 0x29 Polygon open relative
PFVA 0x2A Polygon vector absolute
PFVR 0x2B Polygon vector relative
PFC 0x2C Polygon close | [
"GPU",
"commands",
"REXP",
"0x00",
"Reset",
"expansion",
"SEXP",
"0x01",
"Set",
"expansion",
"ROFF",
"0x02",
"Reset",
"offset",
"on",
"update",
"SOFF",
"0x03",
"Set",
"offset",
"RTPS",
"0x04",
"Reset",
"transposition",
"STPS",
"0x05",
"Set",
"transposition",
"SIMD",
"0x06",
"Load",
"IDR",
"register",
"SICD",
"0x07",
"Load",
"partial",
"transfer",
"compare",
"value",
"RCW",
"0x08",
"Reset",
"clipping",
"window",
"SCW",
"0x09",
"Set",
"clipping",
"window",
"WVB",
"0x0B",
"Wait",
"for",
"VBlank",
"FXOT",
"0x10",
"Fill",
"x",
"offset",
"table",
"FYOT",
"0x11",
"Fill",
"y",
"offset",
"table",
"FERT",
"0x14",
"Fill",
"expansion",
"table",
"FCT",
"0x15",
"Fill",
"color",
"table",
"SMCT",
"0x16",
"Screen",
"memory",
"to",
"color",
"table",
"ITSN",
"0x20",
"Image",
"memory",
"to",
"screen",
"memory",
"transfer",
"ITSC",
"0x21",
"Image",
"memory",
"to",
"screen",
"memory",
"transfer",
"with",
"clip",
"PPA",
"0x24",
"Plot",
"point",
"absolute",
"PFOA",
"0x28",
"Polygon",
"open",
"absolute",
"PFOR",
"0x29",
"Polygon",
"open",
"relative",
"PFVA",
"0x2A",
"Polygon",
"vector",
"absolute",
"PFVR",
"0x2B",
"Polygon",
"vector",
"relative",
"PFC",
"0x2C",
"Polygon",
"close"
] | void execute_gpu_command(running_machine *machine)
{
switch (gpu.ecr)
{
case 0x04:
{
gpu.transpose = 0;
break;
}
case 0x05:
{
gpu.transpose = 1;
break;
}
case 0x06:
{
gpu.idr = gpu.gr[0];
break;
}
case 0x07:
{
gpu.icd = gpu.gr[0];
break;
}
case 0x09:
{
gpu.clip_max_x = gpu.gr[0];
gpu.clip_min_x = gpu.gr[1];
gpu.clip_max_y = gpu.gr[2];
gpu.clip_min_y = gpu.gr[3];
break;
}
case 0x0b:
{
gpu.vblank_wait = 1;
break;
}
case 0x16:
{
int i;
int offset = xy_to_screen_addr(gpu.gr[0] - 0x400, gpu.gr[1] - 0x200);
int table_offs = gpu.gr[2];
for (i = 0; i < gpu.gr[3]; ++i)
{
UINT16 val = screen_ram[offset >> 1];
val >>= (~offset & 1) << 3;
if (gpu.gr[4] & 0x10)
r_color_table[table_offs] = val;
if (gpu.gr[4] & 0x20)
g_color_table[table_offs] = val;
if (gpu.gr[4] & 0x40)
b_color_table[table_offs] = val;
palette_set_color(machine, table_offs, MAKE_RGB(r_color_table[table_offs], g_color_table[table_offs], b_color_table[table_offs]));
++table_offs;
++offset;
}
break;
}
case 0x20:
{
image_mem_to_screen(false);
break;
}
case 0x21:
{
image_mem_to_screen(true);
break;
}
case 0x28:
{
gpu.points[0].x = gpu.gr[0] - 0x400;
gpu.points[0].y = gpu.gr[1] - 0x200;
gpu.pt_idx = 0;
break;
}
case 0x29:
{
gpu.points[0].x = gpu.points[gpu.pt_idx].x + gpu.gr[0];
gpu.points[0].y = gpu.points[gpu.pt_idx].y + gpu.gr[1];
gpu.pt_idx = 0;
break;
}
case 0x2a:
{
++gpu.pt_idx;
gpu.points[gpu.pt_idx].x = gpu.gr[0] - 0x400;
gpu.points[gpu.pt_idx].y = gpu.gr[1] - 0x200;
break;
}
case 0x2b:
{
UINT16 x = gpu.points[gpu.pt_idx].x + gpu.gr[0];
UINT16 y = gpu.points[gpu.pt_idx].y + gpu.gr[1];
++gpu.pt_idx;
gpu.points[gpu.pt_idx].x = x;
gpu.points[gpu.pt_idx].y = y;
break;
}
case 0x2c:
{
draw_polygon(gpu.gr[2]);
poly_wait(poly, "Normal");
break;
}
default:
logerror("GPU COMMAND: %x\n", gpu.ecr);
}
} | [
"void",
"execute_gpu_command",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"switch",
"(",
"gpu",
".",
"ecr",
")",
"{",
"case",
"0x04",
":",
"{",
"gpu",
".",
"transpose",
"=",
"0",
";",
"break",
";",
"}",
"case",
"0x05",
":",
"{",
"gpu",
".",
"transpose",
"=",
"1",
";",
"break",
";",
"}",
"case",
"0x06",
":",
"{",
"gpu",
".",
"idr",
"=",
"gpu",
".",
"gr",
"[",
"0",
"]",
";",
"break",
";",
"}",
"case",
"0x07",
":",
"{",
"gpu",
".",
"icd",
"=",
"gpu",
".",
"gr",
"[",
"0",
"]",
";",
"break",
";",
"}",
"case",
"0x09",
":",
"{",
"gpu",
".",
"clip_max_x",
"=",
"gpu",
".",
"gr",
"[",
"0",
"]",
";",
"gpu",
".",
"clip_min_x",
"=",
"gpu",
".",
"gr",
"[",
"1",
"]",
";",
"gpu",
".",
"clip_max_y",
"=",
"gpu",
".",
"gr",
"[",
"2",
"]",
";",
"gpu",
".",
"clip_min_y",
"=",
"gpu",
".",
"gr",
"[",
"3",
"]",
";",
"break",
";",
"}",
"case",
"0x0b",
":",
"{",
"gpu",
".",
"vblank_wait",
"=",
"1",
";",
"break",
";",
"}",
"case",
"0x16",
":",
"{",
"int",
"i",
";",
"int",
"offset",
"=",
"xy_to_screen_addr",
"(",
"gpu",
".",
"gr",
"[",
"0",
"]",
"-",
"0x400",
",",
"gpu",
".",
"gr",
"[",
"1",
"]",
"-",
"0x200",
")",
";",
"int",
"table_offs",
"=",
"gpu",
".",
"gr",
"[",
"2",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"gpu",
".",
"gr",
"[",
"3",
"]",
";",
"++",
"i",
")",
"{",
"UINT16",
"val",
"=",
"screen_ram",
"[",
"offset",
">>",
"1",
"]",
";",
"val",
">>=",
"(",
"~",
"offset",
"&",
"1",
")",
"<<",
"3",
";",
"if",
"(",
"gpu",
".",
"gr",
"[",
"4",
"]",
"&",
"0x10",
")",
"r_color_table",
"[",
"table_offs",
"]",
"=",
"val",
";",
"if",
"(",
"gpu",
".",
"gr",
"[",
"4",
"]",
"&",
"0x20",
")",
"g_color_table",
"[",
"table_offs",
"]",
"=",
"val",
";",
"if",
"(",
"gpu",
".",
"gr",
"[",
"4",
"]",
"&",
"0x40",
")",
"b_color_table",
"[",
"table_offs",
"]",
"=",
"val",
";",
"palette_set_color",
"(",
"machine",
",",
"table_offs",
",",
"MAKE_RGB",
"(",
"r_color_table",
"[",
"table_offs",
"]",
",",
"g_color_table",
"[",
"table_offs",
"]",
",",
"b_color_table",
"[",
"table_offs",
"]",
")",
")",
";",
"++",
"table_offs",
";",
"++",
"offset",
";",
"}",
"break",
";",
"}",
"case",
"0x20",
":",
"{",
"image_mem_to_screen",
"(",
"false",
")",
";",
"break",
";",
"}",
"case",
"0x21",
":",
"{",
"image_mem_to_screen",
"(",
"true",
")",
";",
"break",
";",
"}",
"case",
"0x28",
":",
"{",
"gpu",
".",
"points",
"[",
"0",
"]",
".",
"x",
"=",
"gpu",
".",
"gr",
"[",
"0",
"]",
"-",
"0x400",
";",
"gpu",
".",
"points",
"[",
"0",
"]",
".",
"y",
"=",
"gpu",
".",
"gr",
"[",
"1",
"]",
"-",
"0x200",
";",
"gpu",
".",
"pt_idx",
"=",
"0",
";",
"break",
";",
"}",
"case",
"0x29",
":",
"{",
"gpu",
".",
"points",
"[",
"0",
"]",
".",
"x",
"=",
"gpu",
".",
"points",
"[",
"gpu",
".",
"pt_idx",
"]",
".",
"x",
"+",
"gpu",
".",
"gr",
"[",
"0",
"]",
";",
"gpu",
".",
"points",
"[",
"0",
"]",
".",
"y",
"=",
"gpu",
".",
"points",
"[",
"gpu",
".",
"pt_idx",
"]",
".",
"y",
"+",
"gpu",
".",
"gr",
"[",
"1",
"]",
";",
"gpu",
".",
"pt_idx",
"=",
"0",
";",
"break",
";",
"}",
"case",
"0x2a",
":",
"{",
"++",
"gpu",
".",
"pt_idx",
";",
"gpu",
".",
"points",
"[",
"gpu",
".",
"pt_idx",
"]",
".",
"x",
"=",
"gpu",
".",
"gr",
"[",
"0",
"]",
"-",
"0x400",
";",
"gpu",
".",
"points",
"[",
"gpu",
".",
"pt_idx",
"]",
".",
"y",
"=",
"gpu",
".",
"gr",
"[",
"1",
"]",
"-",
"0x200",
";",
"break",
";",
"}",
"case",
"0x2b",
":",
"{",
"UINT16",
"x",
"=",
"gpu",
".",
"points",
"[",
"gpu",
".",
"pt_idx",
"]",
".",
"x",
"+",
"gpu",
".",
"gr",
"[",
"0",
"]",
";",
"UINT16",
"y",
"=",
"gpu",
".",
"points",
"[",
"gpu",
".",
"pt_idx",
"]",
".",
"y",
"+",
"gpu",
".",
"gr",
"[",
"1",
"]",
";",
"++",
"gpu",
".",
"pt_idx",
";",
"gpu",
".",
"points",
"[",
"gpu",
".",
"pt_idx",
"]",
".",
"x",
"=",
"x",
";",
"gpu",
".",
"points",
"[",
"gpu",
".",
"pt_idx",
"]",
".",
"y",
"=",
"y",
";",
"break",
";",
"}",
"case",
"0x2c",
":",
"{",
"draw_polygon",
"(",
"gpu",
".",
"gr",
"[",
"2",
"]",
")",
";",
"poly_wait",
"(",
"poly",
",",
"\"",
"\"",
")",
";",
"break",
";",
"}",
"default",
":",
"logerror",
"(",
"\"",
"\\n",
"\"",
",",
"gpu",
".",
"ecr",
")",
";",
"}",
"}"
] | GPU commands
REXP 0x00 Reset expansion
SEXP 0x01 Set expansion
ROFF 0x02 Reset offset on update
SOFF 0x03 Set offset
RTPS 0x04 Reset transposition
STPS 0x05 Set transposition
SIMD 0x06 Load IDR register
SICD 0x07 Load partial transfer compare value
RCW 0x08 Reset clipping window
SCW 0x09 Set clipping window
WVB 0x0B Wait for VBlank
FXOT 0x10 Fill x offset table
FYOT 0x11 Fill y offset table
FERT 0x14 Fill expansion table
FCT 0x15 Fill color table
SMCT 0x16 Screen memory to color table
ITSN 0x20 Image memory to screen memory transfer
ITSC 0x21 Image memory to screen memory transfer with clip
PPA 0x24 Plot point absolute
PFOA 0x28 Polygon open absolute
PFOR 0x29 Polygon open relative
PFVA 0x2A Polygon vector absolute
PFVR 0x2B Polygon vector relative
PFC 0x2C Polygon close | [
"GPU",
"commands",
"REXP",
"0x00",
"Reset",
"expansion",
"SEXP",
"0x01",
"Set",
"expansion",
"ROFF",
"0x02",
"Reset",
"offset",
"on",
"update",
"SOFF",
"0x03",
"Set",
"offset",
"RTPS",
"0x04",
"Reset",
"transposition",
"STPS",
"0x05",
"Set",
"transposition",
"SIMD",
"0x06",
"Load",
"IDR",
"register",
"SICD",
"0x07",
"Load",
"partial",
"transfer",
"compare",
"value",
"RCW",
"0x08",
"Reset",
"clipping",
"window",
"SCW",
"0x09",
"Set",
"clipping",
"window",
"WVB",
"0x0B",
"Wait",
"for",
"VBlank",
"FXOT",
"0x10",
"Fill",
"x",
"offset",
"table",
"FYOT",
"0x11",
"Fill",
"y",
"offset",
"table",
"FERT",
"0x14",
"Fill",
"expansion",
"table",
"FCT",
"0x15",
"Fill",
"color",
"table",
"SMCT",
"0x16",
"Screen",
"memory",
"to",
"color",
"table",
"ITSN",
"0x20",
"Image",
"memory",
"to",
"screen",
"memory",
"transfer",
"ITSC",
"0x21",
"Image",
"memory",
"to",
"screen",
"memory",
"transfer",
"with",
"clip",
"PPA",
"0x24",
"Plot",
"point",
"absolute",
"PFOA",
"0x28",
"Polygon",
"open",
"absolute",
"PFOR",
"0x29",
"Polygon",
"open",
"relative",
"PFVA",
"0x2A",
"Polygon",
"vector",
"absolute",
"PFVR",
"0x2B",
"Polygon",
"vector",
"relative",
"PFC",
"0x2C",
"Polygon",
"close"
] | [
"// Wait for VBLANK and swap buffers?\r",
"/*\r\n Copy screen RAM to color RAM\r\n GR0 : Color start X\r\n GR1 : Color start Y\r\n GR2 : Color table offset\r\n GR3 : Size\r\n GR4 : Channels to set (R: 0x10, G: 0x20, B: 0x40)\r\n */",
"/* Update */"
] | [
{
"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": []
} |
240b60e3026321643387a5c4f5cb178b8c8bed05 | lofunz/mieme | Reloaded/trunk/src/mame/drivers/atarisy4.c | [
"Unlicense"
] | C | load_hexfile | void | void load_hexfile(const address_space *space, const UINT8 *file)
{
#define READ_HEX_CHAR() hex_to_ascii(file[i++])
UINT32 i = 0;
UINT32 line = 1;
bool end = false;
while (true)
{
UINT8 len;
UINT8 record;
UINT8 checksum;
UINT8 sum = 0;
UINT8 addr_len;
UINT32 addr = 0;
/* Ignore blank lines */
while (file[i] == '\n') i++;
/* First character of each line should be a '%' */
if (file[i++] != '%')
fatalerror("Error on line %d - invalid line start character", line);
/* Get the line length */
len = READ_HEX_CHAR() << 4;
len |= READ_HEX_CHAR();
sum += len & 0xf;
sum += len >> 4;
/* Get the record type */
record = READ_HEX_CHAR();
sum += record;
/* Record type */
if (record == 8)
{
end = true;
}
else if (record == 3)
{
/* Ignore this type */
i += len - 2;
goto next_line;
}
else if (record != 6)
{
fatalerror("Error on line %d - Invalid record type %d\n", line, record);
}
/* Get the checksum for this line */
checksum = READ_HEX_CHAR() << 4;
checksum |= READ_HEX_CHAR();
/* Get the number of address digits */
addr_len = READ_HEX_CHAR();
sum += addr_len;
len = len - 6 - addr_len;
/* Form the address */
while (addr_len)
{
UINT8 digit;
addr <<= 4;
digit = READ_HEX_CHAR();
sum += digit;
addr |= digit;
--addr_len;
}
/* Now read the data */
while (len)
{
UINT8 data;
data = READ_HEX_CHAR() << 4;
data |= READ_HEX_CHAR();
sum += data >> 4;
sum += data & 0xf;
if (record == 6)
memory_write_byte(space, addr++, data);
len -= 2;
}
/* Eat the carriage return */
++i;
if (sum != checksum)
fatalerror("Checksum mismatch on line %d (Found 0x%.2x but expected 0x%.2x)\n", line, sum, checksum);
next_line:
++line;
if (end == true)
break;
}
} | /* Load memory space with data from a Tektronix-Extended HEX file */ | Load memory space with data from a Tektronix-Extended HEX file | [
"Load",
"memory",
"space",
"with",
"data",
"from",
"a",
"Tektronix",
"-",
"Extended",
"HEX",
"file"
] | void load_hexfile(const address_space *space, const UINT8 *file)
{
#define READ_HEX_CHAR() hex_to_ascii(file[i++])
UINT32 i = 0;
UINT32 line = 1;
bool end = false;
while (true)
{
UINT8 len;
UINT8 record;
UINT8 checksum;
UINT8 sum = 0;
UINT8 addr_len;
UINT32 addr = 0;
while (file[i] == '\n') i++;
if (file[i++] != '%')
fatalerror("Error on line %d - invalid line start character", line);
len = READ_HEX_CHAR() << 4;
len |= READ_HEX_CHAR();
sum += len & 0xf;
sum += len >> 4;
record = READ_HEX_CHAR();
sum += record;
if (record == 8)
{
end = true;
}
else if (record == 3)
{
i += len - 2;
goto next_line;
}
else if (record != 6)
{
fatalerror("Error on line %d - Invalid record type %d\n", line, record);
}
checksum = READ_HEX_CHAR() << 4;
checksum |= READ_HEX_CHAR();
addr_len = READ_HEX_CHAR();
sum += addr_len;
len = len - 6 - addr_len;
while (addr_len)
{
UINT8 digit;
addr <<= 4;
digit = READ_HEX_CHAR();
sum += digit;
addr |= digit;
--addr_len;
}
while (len)
{
UINT8 data;
data = READ_HEX_CHAR() << 4;
data |= READ_HEX_CHAR();
sum += data >> 4;
sum += data & 0xf;
if (record == 6)
memory_write_byte(space, addr++, data);
len -= 2;
}
++i;
if (sum != checksum)
fatalerror("Checksum mismatch on line %d (Found 0x%.2x but expected 0x%.2x)\n", line, sum, checksum);
next_line:
++line;
if (end == true)
break;
}
} | [
"void",
"load_hexfile",
"(",
"const",
"address_space",
"*",
"space",
",",
"const",
"UINT8",
"*",
"file",
")",
"{",
"#define",
"READ_HEX_CHAR",
"(",
")",
"\t\thex_to_ascii(file[i++])\r",
"\n",
"UINT32",
"i",
"=",
"0",
";",
"UINT32",
"line",
"=",
"1",
";",
"bool",
"end",
"=",
"false",
";",
"while",
"(",
"true",
")",
"{",
"UINT8",
"len",
";",
"UINT8",
"record",
";",
"UINT8",
"checksum",
";",
"UINT8",
"sum",
"=",
"0",
";",
"UINT8",
"addr_len",
";",
"UINT32",
"addr",
"=",
"0",
";",
"while",
"(",
"file",
"[",
"i",
"]",
"==",
"'",
"\\n",
"'",
")",
"i",
"++",
";",
"if",
"(",
"file",
"[",
"i",
"++",
"]",
"!=",
"'",
"'",
")",
"fatalerror",
"(",
"\"",
"\"",
",",
"line",
")",
";",
"len",
"=",
"READ_HEX_CHAR",
"(",
")",
"<<",
"4",
";",
"len",
"|=",
"READ_HEX_CHAR",
"(",
")",
";",
"sum",
"+=",
"len",
"&",
"0xf",
";",
"sum",
"+=",
"len",
">>",
"4",
";",
"record",
"=",
"READ_HEX_CHAR",
"(",
")",
";",
"sum",
"+=",
"record",
";",
"if",
"(",
"record",
"==",
"8",
")",
"{",
"end",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"record",
"==",
"3",
")",
"{",
"i",
"+=",
"len",
"-",
"2",
";",
"goto",
"next_line",
";",
"}",
"else",
"if",
"(",
"record",
"!=",
"6",
")",
"{",
"fatalerror",
"(",
"\"",
"\\n",
"\"",
",",
"line",
",",
"record",
")",
";",
"}",
"checksum",
"=",
"READ_HEX_CHAR",
"(",
")",
"<<",
"4",
";",
"checksum",
"|=",
"READ_HEX_CHAR",
"(",
")",
";",
"addr_len",
"=",
"READ_HEX_CHAR",
"(",
")",
";",
"sum",
"+=",
"addr_len",
";",
"len",
"=",
"len",
"-",
"6",
"-",
"addr_len",
";",
"while",
"(",
"addr_len",
")",
"{",
"UINT8",
"digit",
";",
"addr",
"<<=",
"4",
";",
"digit",
"=",
"READ_HEX_CHAR",
"(",
")",
";",
"sum",
"+=",
"digit",
";",
"addr",
"|=",
"digit",
";",
"--",
"addr_len",
";",
"}",
"while",
"(",
"len",
")",
"{",
"UINT8",
"data",
";",
"data",
"=",
"READ_HEX_CHAR",
"(",
")",
"<<",
"4",
";",
"data",
"|=",
"READ_HEX_CHAR",
"(",
")",
";",
"sum",
"+=",
"data",
">>",
"4",
";",
"sum",
"+=",
"data",
"&",
"0xf",
";",
"if",
"(",
"record",
"==",
"6",
")",
"memory_write_byte",
"(",
"space",
",",
"addr",
"++",
",",
"data",
")",
";",
"len",
"-=",
"2",
";",
"}",
"++",
"i",
";",
"if",
"(",
"sum",
"!=",
"checksum",
")",
"fatalerror",
"(",
"\"",
"\\n",
"\"",
",",
"line",
",",
"sum",
",",
"checksum",
")",
";",
"next_line",
":",
"++",
"line",
";",
"if",
"(",
"end",
"==",
"true",
")",
"break",
";",
"}",
"}"
] | Load memory space with data from a Tektronix-Extended HEX file | [
"Load",
"memory",
"space",
"with",
"data",
"from",
"a",
"Tektronix",
"-",
"Extended",
"HEX",
"file"
] | [
"/* Ignore blank lines */",
"/* First character of each line should be a '%' */",
"/* Get the line length */",
"/* Get the record type */",
"/* Record type */",
"/* Ignore this type */",
"/* Get the checksum for this line */",
"/* Get the number of address digits */",
"/* Form the address */",
"/* Now read the data */",
"/* Eat the carriage return */"
] | [
{
"param": "space",
"type": "address_space"
},
{
"param": "file",
"type": "UINT8"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "space",
"type": "address_space",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "file",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
af38991e64c3e431b8a07093b792410158985446 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/video/stvvdp2.c | [
"Unlicense"
] | C | stv_vdp2_is_rotation_applied | UINT8 | static UINT8 stv_vdp2_is_rotation_applied(void)
{
#define _FIXED_1 (0x00010000)
#define _FIXED_0 (0x00000000)
if ( RP.A == _FIXED_1 &&
RP.B == _FIXED_0 &&
RP.C == _FIXED_0 &&
RP.D == _FIXED_0 &&
RP.E == _FIXED_1 &&
RP.F == _FIXED_0 &&
RP.dxst == _FIXED_0 &&
RP.dyst == _FIXED_1 &&
RP.dx == _FIXED_1 &&
RP.dy == _FIXED_0 )
{
return 0;
}
else
{
return 1;
}
} | /* check if RGB layer has rotation applied */ | check if RGB layer has rotation applied | [
"check",
"if",
"RGB",
"layer",
"has",
"rotation",
"applied"
] | static UINT8 stv_vdp2_is_rotation_applied(void)
{
#define _FIXED_1 (0x00010000)
#define _FIXED_0 (0x00000000)
if ( RP.A == _FIXED_1 &&
RP.B == _FIXED_0 &&
RP.C == _FIXED_0 &&
RP.D == _FIXED_0 &&
RP.E == _FIXED_1 &&
RP.F == _FIXED_0 &&
RP.dxst == _FIXED_0 &&
RP.dyst == _FIXED_1 &&
RP.dx == _FIXED_1 &&
RP.dy == _FIXED_0 )
{
return 0;
}
else
{
return 1;
}
} | [
"static",
"UINT8",
"stv_vdp2_is_rotation_applied",
"(",
"void",
")",
"{",
"#define",
"_FIXED_1",
"\t(0x00010000)",
"\n",
"#define",
"_FIXED_0",
"\t(0x00000000)",
"\n\n",
"if",
"(",
"RP",
".",
"A",
"==",
"_FIXED_1",
"&&",
"RP",
".",
"B",
"==",
"_FIXED_0",
"&&",
"RP",
".",
"C",
"==",
"_FIXED_0",
"&&",
"RP",
".",
"D",
"==",
"_FIXED_0",
"&&",
"RP",
".",
"E",
"==",
"_FIXED_1",
"&&",
"RP",
".",
"F",
"==",
"_FIXED_0",
"&&",
"RP",
".",
"dxst",
"==",
"_FIXED_0",
"&&",
"RP",
".",
"dyst",
"==",
"_FIXED_1",
"&&",
"RP",
".",
"dx",
"==",
"_FIXED_1",
"&&",
"RP",
".",
"dy",
"==",
"_FIXED_0",
")",
"{",
"return",
"0",
";",
"}",
"else",
"{",
"return",
"1",
";",
"}",
"}"
] | check if RGB layer has rotation applied | [
"check",
"if",
"RGB",
"layer",
"has",
"rotation",
"applied"
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
af38991e64c3e431b8a07093b792410158985446 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/video/stvvdp2.c | [
"Unlicense"
] | C | stv_vdp2_get_map_page | void | static void stv_vdp2_get_map_page( int x, int y, int *_map, int *_page )
{
int page = 0;
int map = 0;
if ( stv2_current_tilemap.map_count == 4 )
{
if ( stv2_current_tilemap.tile_size == 0 )
{
if ( stv2_current_tilemap.plane_size & 1 )
{
page = ((x >> 6) & 1);
map = (x >> 7) & 1;
}
else
{
map = (x >> 6) & 1;
}
if ( stv2_current_tilemap.plane_size & 2 )
{
page |= ((y >> (6-1)) & 2);
map |= ((y >> (7-1)) & 2);
}
else
{
map |= ((y >> (6-1)) & 2);
}
}
else
{
if ( stv2_current_tilemap.plane_size & 1 )
{
page = ((x >> 5) & 1);
map = (x >> 6) & 1;
}
else
{
map = (x >> 5) & 1;
}
if ( stv2_current_tilemap.plane_size & 2 )
{
page |= ((y >> (5 - 1)) & 2);
map |= ((y >> (6-1)) & 2);
}
else
{
map |= ((y >> (5-1)) & 2);
}
}
}
else //16
{
if ( stv2_current_tilemap.tile_size == 0 )
{
if ( stv2_current_tilemap.plane_size & 1 )
{
page = ((x >> 6) & 1);
map = (x >> 7) & 3;
}
else
{
map = (x >> 6) & 3;
}
if ( stv2_current_tilemap.plane_size & 2 )
{
page |= ((y >> (6-1)) & 2);
map |= ((y >> (7-2)) & 12);
}
else
{
map |= ((y >> (6-2)) & 12);
}
}
else
{
if ( stv2_current_tilemap.plane_size & 1 )
{
page = ((x >> 5) & 1);
map = (x >> 6) & 3;
}
else
{
map = (x >> 5) & 3;
}
if ( stv2_current_tilemap.plane_size & 2 )
{
page |= ((y >> (5 - 1)) & 2);
map |= ((y >> (6-2)) & 12);
}
else
{
map |= ((y >> (5-2)) & 12);
}
}
}
*_page = page;
*_map = map;
} | /*
4.2 Sega's Cell / Character Pattern / Page / Plane / Map system, aka a rather annoying thing that makes optimizations hard
(this is only for the normal tilemaps at the moment, i haven't even thought about the ROZ ones)
Tiles:
Cells are 8x8 gfx stored in video ram, they can be of various colour depths
Character Patterns can be 8x8 or 16x16 (1 hcell x 1 vcell or 2 hcell x 2 vcell)
(a 16x16 character pattern is 4 8x8 cells put together)
A page is made up of 64x64 cells, thats 64x64 character patterns in 8x8 mode or 32x32 character patterns in 16x16 mode.
64 * 8 = 512 (0x200)
32 * 16 = 512 (0x200)
A page is _always_ 512 (0x200) pixels in each direction
in 1 word mode a 32*16 x 32*16 page is 0x0800 bytes
in 1 word mode a 64*8 x 64*8 page is 0x2000 bytes
in 2 word mode a 32*16 x 32*16 page is 0x1000 bytes
in 2 word mode a 64*8 x 64*8 page is 0x4000 bytes
either 1, 2 or 4 pages make each plane depending on the plane size register (per tilemap)
therefore each plane is either
64 * 8 * 1 x 64 * 8 * 1 (512 x 512)
64 * 8 * 2 x 64 * 8 * 1 (1024 x 512)
64 * 8 * 2 x 64 * 8 * 2 (1024 x 1024)
32 * 16 * 1 x 32 * 16 * 1 (512 x 512)
32 * 16 * 2 x 32 * 16 * 1 (1024 x 512)
32 * 16 * 2 x 32 * 16 * 2 (1024 x 1024)
map is always enabled?
map is a 2x2 arrangement of planes, all 4 of the planes can be the same.
*/ | 4.2 Sega's Cell / Character Pattern / Page / Plane / Map system, aka a rather annoying thing that makes optimizations hard
(this is only for the normal tilemaps at the moment, i haven't even thought about the ROZ ones)
Cells are 8x8 gfx stored in video ram, they can be of various colour depths
Character Patterns can be 8x8 or 16x16 (1 hcell x 1 vcell or 2 hcell x 2 vcell)
(a 16x16 character pattern is 4 8x8 cells put together)
A page is made up of 64x64 cells, thats 64x64 character patterns in 8x8 mode or 32x32 character patterns in 16x16 mode.
map is always enabled.
map is a 2x2 arrangement of planes, all 4 of the planes can be the same. | [
"4",
".",
"2",
"Sega",
"'",
"s",
"Cell",
"/",
"Character",
"Pattern",
"/",
"Page",
"/",
"Plane",
"/",
"Map",
"system",
"aka",
"a",
"rather",
"annoying",
"thing",
"that",
"makes",
"optimizations",
"hard",
"(",
"this",
"is",
"only",
"for",
"the",
"normal",
"tilemaps",
"at",
"the",
"moment",
"i",
"haven",
"'",
"t",
"even",
"thought",
"about",
"the",
"ROZ",
"ones",
")",
"Cells",
"are",
"8x8",
"gfx",
"stored",
"in",
"video",
"ram",
"they",
"can",
"be",
"of",
"various",
"colour",
"depths",
"Character",
"Patterns",
"can",
"be",
"8x8",
"or",
"16x16",
"(",
"1",
"hcell",
"x",
"1",
"vcell",
"or",
"2",
"hcell",
"x",
"2",
"vcell",
")",
"(",
"a",
"16x16",
"character",
"pattern",
"is",
"4",
"8x8",
"cells",
"put",
"together",
")",
"A",
"page",
"is",
"made",
"up",
"of",
"64x64",
"cells",
"thats",
"64x64",
"character",
"patterns",
"in",
"8x8",
"mode",
"or",
"32x32",
"character",
"patterns",
"in",
"16x16",
"mode",
".",
"map",
"is",
"always",
"enabled",
".",
"map",
"is",
"a",
"2x2",
"arrangement",
"of",
"planes",
"all",
"4",
"of",
"the",
"planes",
"can",
"be",
"the",
"same",
"."
] | static void stv_vdp2_get_map_page( int x, int y, int *_map, int *_page )
{
int page = 0;
int map = 0;
if ( stv2_current_tilemap.map_count == 4 )
{
if ( stv2_current_tilemap.tile_size == 0 )
{
if ( stv2_current_tilemap.plane_size & 1 )
{
page = ((x >> 6) & 1);
map = (x >> 7) & 1;
}
else
{
map = (x >> 6) & 1;
}
if ( stv2_current_tilemap.plane_size & 2 )
{
page |= ((y >> (6-1)) & 2);
map |= ((y >> (7-1)) & 2);
}
else
{
map |= ((y >> (6-1)) & 2);
}
}
else
{
if ( stv2_current_tilemap.plane_size & 1 )
{
page = ((x >> 5) & 1);
map = (x >> 6) & 1;
}
else
{
map = (x >> 5) & 1;
}
if ( stv2_current_tilemap.plane_size & 2 )
{
page |= ((y >> (5 - 1)) & 2);
map |= ((y >> (6-1)) & 2);
}
else
{
map |= ((y >> (5-1)) & 2);
}
}
}
else
{
if ( stv2_current_tilemap.tile_size == 0 )
{
if ( stv2_current_tilemap.plane_size & 1 )
{
page = ((x >> 6) & 1);
map = (x >> 7) & 3;
}
else
{
map = (x >> 6) & 3;
}
if ( stv2_current_tilemap.plane_size & 2 )
{
page |= ((y >> (6-1)) & 2);
map |= ((y >> (7-2)) & 12);
}
else
{
map |= ((y >> (6-2)) & 12);
}
}
else
{
if ( stv2_current_tilemap.plane_size & 1 )
{
page = ((x >> 5) & 1);
map = (x >> 6) & 3;
}
else
{
map = (x >> 5) & 3;
}
if ( stv2_current_tilemap.plane_size & 2 )
{
page |= ((y >> (5 - 1)) & 2);
map |= ((y >> (6-2)) & 12);
}
else
{
map |= ((y >> (5-2)) & 12);
}
}
}
*_page = page;
*_map = map;
} | [
"static",
"void",
"stv_vdp2_get_map_page",
"(",
"int",
"x",
",",
"int",
"y",
",",
"int",
"*",
"_map",
",",
"int",
"*",
"_page",
")",
"{",
"int",
"page",
"=",
"0",
";",
"int",
"map",
"=",
"0",
";",
"if",
"(",
"stv2_current_tilemap",
".",
"map_count",
"==",
"4",
")",
"{",
"if",
"(",
"stv2_current_tilemap",
".",
"tile_size",
"==",
"0",
")",
"{",
"if",
"(",
"stv2_current_tilemap",
".",
"plane_size",
"&",
"1",
")",
"{",
"page",
"=",
"(",
"(",
"x",
">>",
"6",
")",
"&",
"1",
")",
";",
"map",
"=",
"(",
"x",
">>",
"7",
")",
"&",
"1",
";",
"}",
"else",
"{",
"map",
"=",
"(",
"x",
">>",
"6",
")",
"&",
"1",
";",
"}",
"if",
"(",
"stv2_current_tilemap",
".",
"plane_size",
"&",
"2",
")",
"{",
"page",
"|=",
"(",
"(",
"y",
">>",
"(",
"6",
"-",
"1",
")",
")",
"&",
"2",
")",
";",
"map",
"|=",
"(",
"(",
"y",
">>",
"(",
"7",
"-",
"1",
")",
")",
"&",
"2",
")",
";",
"}",
"else",
"{",
"map",
"|=",
"(",
"(",
"y",
">>",
"(",
"6",
"-",
"1",
")",
")",
"&",
"2",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"stv2_current_tilemap",
".",
"plane_size",
"&",
"1",
")",
"{",
"page",
"=",
"(",
"(",
"x",
">>",
"5",
")",
"&",
"1",
")",
";",
"map",
"=",
"(",
"x",
">>",
"6",
")",
"&",
"1",
";",
"}",
"else",
"{",
"map",
"=",
"(",
"x",
">>",
"5",
")",
"&",
"1",
";",
"}",
"if",
"(",
"stv2_current_tilemap",
".",
"plane_size",
"&",
"2",
")",
"{",
"page",
"|=",
"(",
"(",
"y",
">>",
"(",
"5",
"-",
"1",
")",
")",
"&",
"2",
")",
";",
"map",
"|=",
"(",
"(",
"y",
">>",
"(",
"6",
"-",
"1",
")",
")",
"&",
"2",
")",
";",
"}",
"else",
"{",
"map",
"|=",
"(",
"(",
"y",
">>",
"(",
"5",
"-",
"1",
")",
")",
"&",
"2",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"stv2_current_tilemap",
".",
"tile_size",
"==",
"0",
")",
"{",
"if",
"(",
"stv2_current_tilemap",
".",
"plane_size",
"&",
"1",
")",
"{",
"page",
"=",
"(",
"(",
"x",
">>",
"6",
")",
"&",
"1",
")",
";",
"map",
"=",
"(",
"x",
">>",
"7",
")",
"&",
"3",
";",
"}",
"else",
"{",
"map",
"=",
"(",
"x",
">>",
"6",
")",
"&",
"3",
";",
"}",
"if",
"(",
"stv2_current_tilemap",
".",
"plane_size",
"&",
"2",
")",
"{",
"page",
"|=",
"(",
"(",
"y",
">>",
"(",
"6",
"-",
"1",
")",
")",
"&",
"2",
")",
";",
"map",
"|=",
"(",
"(",
"y",
">>",
"(",
"7",
"-",
"2",
")",
")",
"&",
"12",
")",
";",
"}",
"else",
"{",
"map",
"|=",
"(",
"(",
"y",
">>",
"(",
"6",
"-",
"2",
")",
")",
"&",
"12",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"stv2_current_tilemap",
".",
"plane_size",
"&",
"1",
")",
"{",
"page",
"=",
"(",
"(",
"x",
">>",
"5",
")",
"&",
"1",
")",
";",
"map",
"=",
"(",
"x",
">>",
"6",
")",
"&",
"3",
";",
"}",
"else",
"{",
"map",
"=",
"(",
"x",
">>",
"5",
")",
"&",
"3",
";",
"}",
"if",
"(",
"stv2_current_tilemap",
".",
"plane_size",
"&",
"2",
")",
"{",
"page",
"|=",
"(",
"(",
"y",
">>",
"(",
"5",
"-",
"1",
")",
")",
"&",
"2",
")",
";",
"map",
"|=",
"(",
"(",
"y",
">>",
"(",
"6",
"-",
"2",
")",
")",
"&",
"12",
")",
";",
"}",
"else",
"{",
"map",
"|=",
"(",
"(",
"y",
">>",
"(",
"5",
"-",
"2",
")",
")",
"&",
"12",
")",
";",
"}",
"}",
"}",
"*",
"_page",
"=",
"page",
";",
"*",
"_map",
"=",
"map",
";",
"}"
] | 4.2 Sega's Cell / Character Pattern / Page / Plane / Map system, aka a rather annoying thing that makes optimizations hard
(this is only for the normal tilemaps at the moment, i haven't even thought about the ROZ ones) | [
"4",
".",
"2",
"Sega",
"'",
"s",
"Cell",
"/",
"Character",
"Pattern",
"/",
"Page",
"/",
"Plane",
"/",
"Map",
"system",
"aka",
"a",
"rather",
"annoying",
"thing",
"that",
"makes",
"optimizations",
"hard",
"(",
"this",
"is",
"only",
"for",
"the",
"normal",
"tilemaps",
"at",
"the",
"moment",
"i",
"haven",
"'",
"t",
"even",
"thought",
"about",
"the",
"ROZ",
"ones",
")"
] | [
"//16"
] | [
{
"param": "x",
"type": "int"
},
{
"param": "y",
"type": "int"
},
{
"param": "_map",
"type": "int"
},
{
"param": "_page",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "x",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "y",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "_map",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "_page",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
af38991e64c3e431b8a07093b792410158985446 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/video/stvvdp2.c | [
"Unlicense"
] | C | stv_vdp2_fade_effects | void | static void stv_vdp2_fade_effects(running_machine *machine)
{
/*
Note:We have to use temporary storages because palette_get_color must use
variables setted with unsigned int8
*/
INT16 t_r,t_g,t_b;
UINT8 r,g,b;
rgb_t color;
int i;
//popmessage("%04x %04x",STV_VDP2_CLOFEN,STV_VDP2_CLOFSL);
for(i=0;i<2048;i++)
{
/*Fade A*/
color = palette_get_color(machine, i);
t_r = (STV_VDP2_COAR & 0x100) ? (RGB_RED(color) - (0x100 - (STV_VDP2_COAR & 0xff))) : ((STV_VDP2_COAR & 0xff) + RGB_RED(color));
t_g = (STV_VDP2_COAG & 0x100) ? (RGB_GREEN(color) - (0x100 - (STV_VDP2_COAG & 0xff))) : ((STV_VDP2_COAG & 0xff) + RGB_GREEN(color));
t_b = (STV_VDP2_COAB & 0x100) ? (RGB_BLUE(color) - (0x100 - (STV_VDP2_COAB & 0xff))) : ((STV_VDP2_COAB & 0xff) + RGB_BLUE(color));
if(t_r < 0) { t_r = 0; }
if(t_r > 0xff) { t_r = 0xff; }
if(t_g < 0) { t_g = 0; }
if(t_g > 0xff) { t_g = 0xff; }
if(t_b < 0) { t_b = 0; }
if(t_b > 0xff) { t_b = 0xff; }
r = t_r;
g = t_g;
b = t_b;
palette_set_color(machine,i+(2048*1),MAKE_RGB(r,g,b));
/*Fade B*/
color = palette_get_color(machine, i);
t_r = (STV_VDP2_COBR & 0x100) ? (RGB_RED(color) - (0xff - (STV_VDP2_COBR & 0xff))) : ((STV_VDP2_COBR & 0xff) + RGB_RED(color));
t_g = (STV_VDP2_COBG & 0x100) ? (RGB_GREEN(color) - (0xff - (STV_VDP2_COBG & 0xff))) : ((STV_VDP2_COBG & 0xff) + RGB_GREEN(color));
t_b = (STV_VDP2_COBB & 0x100) ? (RGB_BLUE(color) - (0xff - (STV_VDP2_COBB & 0xff))) : ((STV_VDP2_COBB & 0xff) + RGB_BLUE(color));
if(t_r < 0) { t_r = 0; }
if(t_r > 0xff) { t_r = 0xff; }
if(t_g < 0) { t_g = 0; }
if(t_g > 0xff) { t_g = 0xff; }
if(t_b < 0) { t_b = 0; }
if(t_b > 0xff) { t_b = 0xff; }
r = t_r;
g = t_g;
b = t_b;
palette_set_color(machine,i+(2048*2),MAKE_RGB(r,g,b));
}
//popmessage("%04x %04x %04x %04x %04x %04x",STV_VDP2_COAR,STV_VDP2_COAG,STV_VDP2_COAB,STV_VDP2_COBR,STV_VDP2_COBG,STV_VDP2_COBB);
} | /*This is for calculating the rgb brightness*/
/*TODO: Optimize this...*/ | This is for calculating the rgb brightness
TODO: Optimize this | [
"This",
"is",
"for",
"calculating",
"the",
"rgb",
"brightness",
"TODO",
":",
"Optimize",
"this"
] | static void stv_vdp2_fade_effects(running_machine *machine)
{
INT16 t_r,t_g,t_b;
UINT8 r,g,b;
rgb_t color;
int i;
for(i=0;i<2048;i++)
{
color = palette_get_color(machine, i);
t_r = (STV_VDP2_COAR & 0x100) ? (RGB_RED(color) - (0x100 - (STV_VDP2_COAR & 0xff))) : ((STV_VDP2_COAR & 0xff) + RGB_RED(color));
t_g = (STV_VDP2_COAG & 0x100) ? (RGB_GREEN(color) - (0x100 - (STV_VDP2_COAG & 0xff))) : ((STV_VDP2_COAG & 0xff) + RGB_GREEN(color));
t_b = (STV_VDP2_COAB & 0x100) ? (RGB_BLUE(color) - (0x100 - (STV_VDP2_COAB & 0xff))) : ((STV_VDP2_COAB & 0xff) + RGB_BLUE(color));
if(t_r < 0) { t_r = 0; }
if(t_r > 0xff) { t_r = 0xff; }
if(t_g < 0) { t_g = 0; }
if(t_g > 0xff) { t_g = 0xff; }
if(t_b < 0) { t_b = 0; }
if(t_b > 0xff) { t_b = 0xff; }
r = t_r;
g = t_g;
b = t_b;
palette_set_color(machine,i+(2048*1),MAKE_RGB(r,g,b));
color = palette_get_color(machine, i);
t_r = (STV_VDP2_COBR & 0x100) ? (RGB_RED(color) - (0xff - (STV_VDP2_COBR & 0xff))) : ((STV_VDP2_COBR & 0xff) + RGB_RED(color));
t_g = (STV_VDP2_COBG & 0x100) ? (RGB_GREEN(color) - (0xff - (STV_VDP2_COBG & 0xff))) : ((STV_VDP2_COBG & 0xff) + RGB_GREEN(color));
t_b = (STV_VDP2_COBB & 0x100) ? (RGB_BLUE(color) - (0xff - (STV_VDP2_COBB & 0xff))) : ((STV_VDP2_COBB & 0xff) + RGB_BLUE(color));
if(t_r < 0) { t_r = 0; }
if(t_r > 0xff) { t_r = 0xff; }
if(t_g < 0) { t_g = 0; }
if(t_g > 0xff) { t_g = 0xff; }
if(t_b < 0) { t_b = 0; }
if(t_b > 0xff) { t_b = 0xff; }
r = t_r;
g = t_g;
b = t_b;
palette_set_color(machine,i+(2048*2),MAKE_RGB(r,g,b));
}
} | [
"static",
"void",
"stv_vdp2_fade_effects",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"INT16",
"t_r",
",",
"t_g",
",",
"t_b",
";",
"UINT8",
"r",
",",
"g",
",",
"b",
";",
"rgb_t",
"color",
";",
"int",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"2048",
";",
"i",
"++",
")",
"{",
"color",
"=",
"palette_get_color",
"(",
"machine",
",",
"i",
")",
";",
"t_r",
"=",
"(",
"STV_VDP2_COAR",
"&",
"0x100",
")",
"?",
"(",
"RGB_RED",
"(",
"color",
")",
"-",
"(",
"0x100",
"-",
"(",
"STV_VDP2_COAR",
"&",
"0xff",
")",
")",
")",
":",
"(",
"(",
"STV_VDP2_COAR",
"&",
"0xff",
")",
"+",
"RGB_RED",
"(",
"color",
")",
")",
";",
"t_g",
"=",
"(",
"STV_VDP2_COAG",
"&",
"0x100",
")",
"?",
"(",
"RGB_GREEN",
"(",
"color",
")",
"-",
"(",
"0x100",
"-",
"(",
"STV_VDP2_COAG",
"&",
"0xff",
")",
")",
")",
":",
"(",
"(",
"STV_VDP2_COAG",
"&",
"0xff",
")",
"+",
"RGB_GREEN",
"(",
"color",
")",
")",
";",
"t_b",
"=",
"(",
"STV_VDP2_COAB",
"&",
"0x100",
")",
"?",
"(",
"RGB_BLUE",
"(",
"color",
")",
"-",
"(",
"0x100",
"-",
"(",
"STV_VDP2_COAB",
"&",
"0xff",
")",
")",
")",
":",
"(",
"(",
"STV_VDP2_COAB",
"&",
"0xff",
")",
"+",
"RGB_BLUE",
"(",
"color",
")",
")",
";",
"if",
"(",
"t_r",
"<",
"0",
")",
"{",
"t_r",
"=",
"0",
";",
"}",
"if",
"(",
"t_r",
">",
"0xff",
")",
"{",
"t_r",
"=",
"0xff",
";",
"}",
"if",
"(",
"t_g",
"<",
"0",
")",
"{",
"t_g",
"=",
"0",
";",
"}",
"if",
"(",
"t_g",
">",
"0xff",
")",
"{",
"t_g",
"=",
"0xff",
";",
"}",
"if",
"(",
"t_b",
"<",
"0",
")",
"{",
"t_b",
"=",
"0",
";",
"}",
"if",
"(",
"t_b",
">",
"0xff",
")",
"{",
"t_b",
"=",
"0xff",
";",
"}",
"r",
"=",
"t_r",
";",
"g",
"=",
"t_g",
";",
"b",
"=",
"t_b",
";",
"palette_set_color",
"(",
"machine",
",",
"i",
"+",
"(",
"2048",
"*",
"1",
")",
",",
"MAKE_RGB",
"(",
"r",
",",
"g",
",",
"b",
")",
")",
";",
"color",
"=",
"palette_get_color",
"(",
"machine",
",",
"i",
")",
";",
"t_r",
"=",
"(",
"STV_VDP2_COBR",
"&",
"0x100",
")",
"?",
"(",
"RGB_RED",
"(",
"color",
")",
"-",
"(",
"0xff",
"-",
"(",
"STV_VDP2_COBR",
"&",
"0xff",
")",
")",
")",
":",
"(",
"(",
"STV_VDP2_COBR",
"&",
"0xff",
")",
"+",
"RGB_RED",
"(",
"color",
")",
")",
";",
"t_g",
"=",
"(",
"STV_VDP2_COBG",
"&",
"0x100",
")",
"?",
"(",
"RGB_GREEN",
"(",
"color",
")",
"-",
"(",
"0xff",
"-",
"(",
"STV_VDP2_COBG",
"&",
"0xff",
")",
")",
")",
":",
"(",
"(",
"STV_VDP2_COBG",
"&",
"0xff",
")",
"+",
"RGB_GREEN",
"(",
"color",
")",
")",
";",
"t_b",
"=",
"(",
"STV_VDP2_COBB",
"&",
"0x100",
")",
"?",
"(",
"RGB_BLUE",
"(",
"color",
")",
"-",
"(",
"0xff",
"-",
"(",
"STV_VDP2_COBB",
"&",
"0xff",
")",
")",
")",
":",
"(",
"(",
"STV_VDP2_COBB",
"&",
"0xff",
")",
"+",
"RGB_BLUE",
"(",
"color",
")",
")",
";",
"if",
"(",
"t_r",
"<",
"0",
")",
"{",
"t_r",
"=",
"0",
";",
"}",
"if",
"(",
"t_r",
">",
"0xff",
")",
"{",
"t_r",
"=",
"0xff",
";",
"}",
"if",
"(",
"t_g",
"<",
"0",
")",
"{",
"t_g",
"=",
"0",
";",
"}",
"if",
"(",
"t_g",
">",
"0xff",
")",
"{",
"t_g",
"=",
"0xff",
";",
"}",
"if",
"(",
"t_b",
"<",
"0",
")",
"{",
"t_b",
"=",
"0",
";",
"}",
"if",
"(",
"t_b",
">",
"0xff",
")",
"{",
"t_b",
"=",
"0xff",
";",
"}",
"r",
"=",
"t_r",
";",
"g",
"=",
"t_g",
";",
"b",
"=",
"t_b",
";",
"palette_set_color",
"(",
"machine",
",",
"i",
"+",
"(",
"2048",
"*",
"2",
")",
",",
"MAKE_RGB",
"(",
"r",
",",
"g",
",",
"b",
")",
")",
";",
"}",
"}"
] | This is for calculating the rgb brightness
TODO: Optimize this... | [
"This",
"is",
"for",
"calculating",
"the",
"rgb",
"brightness",
"TODO",
":",
"Optimize",
"this",
"..."
] | [
"/*\n Note:We have to use temporary storages because palette_get_color must use\n variables setted with unsigned int8\n */",
"//popmessage(\"%04x %04x\",STV_VDP2_CLOFEN,STV_VDP2_CLOFSL);",
"/*Fade A*/",
"/*Fade B*/",
"//popmessage(\"%04x %04x %04x %04x %04x %04x\",STV_VDP2_COAR,STV_VDP2_COAG,STV_VDP2_COAB,STV_VDP2_COBR,STV_VDP2_COBG,STV_VDP2_COBB);"
] | [
{
"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": []
} |
243b75515605d34585b2e1523e6070af38eb5c90 | lofunz/mieme | Reloaded/trunk/src/emu/debugger.c | [
"Unlicense"
] | C | debugger_flush_all_traces_on_abnormal_exit | void | void debugger_flush_all_traces_on_abnormal_exit(void)
{
/* clear out the machine list and flush traces on each one */
while (machine_list != NULL)
{
machine_entry *deleteme = machine_list;
debug_cpu_flush_traces(deleteme->machine);
machine_list = deleteme->next;
global_free(deleteme);
}
} | /*-------------------------------------------------
debugger_flush_all_traces_on_abnormal_exit -
flush any traces in the event of an aborted
execution
-------------------------------------------------*/ | debugger_flush_all_traces_on_abnormal_exit
flush any traces in the event of an aborted
execution | [
"debugger_flush_all_traces_on_abnormal_exit",
"flush",
"any",
"traces",
"in",
"the",
"event",
"of",
"an",
"aborted",
"execution"
] | void debugger_flush_all_traces_on_abnormal_exit(void)
{
while (machine_list != NULL)
{
machine_entry *deleteme = machine_list;
debug_cpu_flush_traces(deleteme->machine);
machine_list = deleteme->next;
global_free(deleteme);
}
} | [
"void",
"debugger_flush_all_traces_on_abnormal_exit",
"(",
"void",
")",
"{",
"while",
"(",
"machine_list",
"!=",
"NULL",
")",
"{",
"machine_entry",
"*",
"deleteme",
"=",
"machine_list",
";",
"debug_cpu_flush_traces",
"(",
"deleteme",
"->",
"machine",
")",
";",
"machine_list",
"=",
"deleteme",
"->",
"next",
";",
"global_free",
"(",
"deleteme",
")",
";",
"}",
"}"
] | debugger_flush_all_traces_on_abnormal_exit
flush any traces in the event of an aborted
execution | [
"debugger_flush_all_traces_on_abnormal_exit",
"flush",
"any",
"traces",
"in",
"the",
"event",
"of",
"an",
"aborted",
"execution"
] | [
"/* clear out the machine list and flush traces on each one */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
9143152eccf636be22ad1bb9a9e30b2070243886 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/machine/segacrpt.c | [
"Unlicense"
] | C | sega_decode_317 | void | static void sega_decode_317(running_machine *machine, const char *cputag, int order, int opcode_shift, int data_shift)
{
static const UINT8 xor1_317[1+64] =
{
0x54,
0x14,0x15,0x41,0x14,0x50,0x55,0x05,0x41,0x01,0x10,0x51,0x05,0x11,0x05,0x14,0x55,
0x41,0x05,0x04,0x41,0x14,0x10,0x45,0x50,0x00,0x45,0x00,0x00,0x00,0x45,0x00,0x00,
0x54,0x04,0x15,0x10,0x04,0x05,0x11,0x44,0x04,0x01,0x05,0x00,0x44,0x15,0x40,0x45,
0x10,0x15,0x51,0x50,0x00,0x15,0x51,0x44,0x15,0x04,0x44,0x44,0x50,0x10,0x04,0x04,
};
static const UINT8 xor2_317[2+64] =
{
0x04,
0x44,
0x15,0x51,0x41,0x10,0x15,0x54,0x04,0x51,0x05,0x55,0x05,0x54,0x45,0x04,0x10,0x01,
0x51,0x55,0x45,0x55,0x45,0x04,0x55,0x40,0x11,0x15,0x01,0x40,0x01,0x11,0x45,0x44,
0x40,0x05,0x15,0x15,0x01,0x50,0x00,0x44,0x04,0x50,0x51,0x45,0x50,0x54,0x41,0x40,
0x14,0x40,0x50,0x45,0x10,0x05,0x50,0x01,0x40,0x01,0x50,0x50,0x50,0x44,0x40,0x10,
};
static const int swap1_317[1+64] =
{
7,
1,11,23,17,23, 0,15,19,
20,12,10, 0,18,18, 5,20,
13, 0,18,14, 5, 6,10,21,
1,11, 9, 3,21, 4, 1,17,
5, 7,16,13,19,23,20, 2,
10,23,23,15,10,12, 0,22,
14, 6,15,11,17,15,21, 0,
6, 1, 1,18, 5,15,15,20,
};
static const int swap2_317[2+64] =
{
7,
12,
18, 8,21, 0,22,21,13,21,
20,13,20,14, 6, 3, 5,20,
8,20, 4, 8,17,22, 0, 0,
6,17,17, 9, 0,16,13,21,
3, 2,18, 6,11, 3, 3,18,
18,19, 3, 0, 5, 0,11, 8,
8, 1, 7, 2,10, 8,10, 2,
1, 3,12,16, 0,17,10, 1,
};
if (order)
sega_decode_2( machine, cputag, xor2_317+opcode_shift, swap2_317+opcode_shift, xor1_317+data_shift, swap1_317+data_shift );
else
sega_decode_2( machine, cputag, xor1_317+opcode_shift, swap1_317+opcode_shift, xor2_317+data_shift, swap2_317+data_shift );
} | /******************************************************************************
These games (all 317-xxxx CPUs) use the same algorithm, but the key doesn't
change much - just one or two positions shift in the table.
******************************************************************************/ | These games (all 317-xxxx CPUs) use the same algorithm, but the key doesn't
change much - just one or two positions shift in the table. | [
"These",
"games",
"(",
"all",
"317",
"-",
"xxxx",
"CPUs",
")",
"use",
"the",
"same",
"algorithm",
"but",
"the",
"key",
"doesn",
"'",
"t",
"change",
"much",
"-",
"just",
"one",
"or",
"two",
"positions",
"shift",
"in",
"the",
"table",
"."
] | static void sega_decode_317(running_machine *machine, const char *cputag, int order, int opcode_shift, int data_shift)
{
static const UINT8 xor1_317[1+64] =
{
0x54,
0x14,0x15,0x41,0x14,0x50,0x55,0x05,0x41,0x01,0x10,0x51,0x05,0x11,0x05,0x14,0x55,
0x41,0x05,0x04,0x41,0x14,0x10,0x45,0x50,0x00,0x45,0x00,0x00,0x00,0x45,0x00,0x00,
0x54,0x04,0x15,0x10,0x04,0x05,0x11,0x44,0x04,0x01,0x05,0x00,0x44,0x15,0x40,0x45,
0x10,0x15,0x51,0x50,0x00,0x15,0x51,0x44,0x15,0x04,0x44,0x44,0x50,0x10,0x04,0x04,
};
static const UINT8 xor2_317[2+64] =
{
0x04,
0x44,
0x15,0x51,0x41,0x10,0x15,0x54,0x04,0x51,0x05,0x55,0x05,0x54,0x45,0x04,0x10,0x01,
0x51,0x55,0x45,0x55,0x45,0x04,0x55,0x40,0x11,0x15,0x01,0x40,0x01,0x11,0x45,0x44,
0x40,0x05,0x15,0x15,0x01,0x50,0x00,0x44,0x04,0x50,0x51,0x45,0x50,0x54,0x41,0x40,
0x14,0x40,0x50,0x45,0x10,0x05,0x50,0x01,0x40,0x01,0x50,0x50,0x50,0x44,0x40,0x10,
};
static const int swap1_317[1+64] =
{
7,
1,11,23,17,23, 0,15,19,
20,12,10, 0,18,18, 5,20,
13, 0,18,14, 5, 6,10,21,
1,11, 9, 3,21, 4, 1,17,
5, 7,16,13,19,23,20, 2,
10,23,23,15,10,12, 0,22,
14, 6,15,11,17,15,21, 0,
6, 1, 1,18, 5,15,15,20,
};
static const int swap2_317[2+64] =
{
7,
12,
18, 8,21, 0,22,21,13,21,
20,13,20,14, 6, 3, 5,20,
8,20, 4, 8,17,22, 0, 0,
6,17,17, 9, 0,16,13,21,
3, 2,18, 6,11, 3, 3,18,
18,19, 3, 0, 5, 0,11, 8,
8, 1, 7, 2,10, 8,10, 2,
1, 3,12,16, 0,17,10, 1,
};
if (order)
sega_decode_2( machine, cputag, xor2_317+opcode_shift, swap2_317+opcode_shift, xor1_317+data_shift, swap1_317+data_shift );
else
sega_decode_2( machine, cputag, xor1_317+opcode_shift, swap1_317+opcode_shift, xor2_317+data_shift, swap2_317+data_shift );
} | [
"static",
"void",
"sega_decode_317",
"(",
"running_machine",
"*",
"machine",
",",
"const",
"char",
"*",
"cputag",
",",
"int",
"order",
",",
"int",
"opcode_shift",
",",
"int",
"data_shift",
")",
"{",
"static",
"const",
"UINT8",
"xor1_317",
"[",
"1",
"+",
"64",
"]",
"=",
"{",
"0x54",
",",
"0x14",
",",
"0x15",
",",
"0x41",
",",
"0x14",
",",
"0x50",
",",
"0x55",
",",
"0x05",
",",
"0x41",
",",
"0x01",
",",
"0x10",
",",
"0x51",
",",
"0x05",
",",
"0x11",
",",
"0x05",
",",
"0x14",
",",
"0x55",
",",
"0x41",
",",
"0x05",
",",
"0x04",
",",
"0x41",
",",
"0x14",
",",
"0x10",
",",
"0x45",
",",
"0x50",
",",
"0x00",
",",
"0x45",
",",
"0x00",
",",
"0x00",
",",
"0x00",
",",
"0x45",
",",
"0x00",
",",
"0x00",
",",
"0x54",
",",
"0x04",
",",
"0x15",
",",
"0x10",
",",
"0x04",
",",
"0x05",
",",
"0x11",
",",
"0x44",
",",
"0x04",
",",
"0x01",
",",
"0x05",
",",
"0x00",
",",
"0x44",
",",
"0x15",
",",
"0x40",
",",
"0x45",
",",
"0x10",
",",
"0x15",
",",
"0x51",
",",
"0x50",
",",
"0x00",
",",
"0x15",
",",
"0x51",
",",
"0x44",
",",
"0x15",
",",
"0x04",
",",
"0x44",
",",
"0x44",
",",
"0x50",
",",
"0x10",
",",
"0x04",
",",
"0x04",
",",
"}",
";",
"static",
"const",
"UINT8",
"xor2_317",
"[",
"2",
"+",
"64",
"]",
"=",
"{",
"0x04",
",",
"0x44",
",",
"0x15",
",",
"0x51",
",",
"0x41",
",",
"0x10",
",",
"0x15",
",",
"0x54",
",",
"0x04",
",",
"0x51",
",",
"0x05",
",",
"0x55",
",",
"0x05",
",",
"0x54",
",",
"0x45",
",",
"0x04",
",",
"0x10",
",",
"0x01",
",",
"0x51",
",",
"0x55",
",",
"0x45",
",",
"0x55",
",",
"0x45",
",",
"0x04",
",",
"0x55",
",",
"0x40",
",",
"0x11",
",",
"0x15",
",",
"0x01",
",",
"0x40",
",",
"0x01",
",",
"0x11",
",",
"0x45",
",",
"0x44",
",",
"0x40",
",",
"0x05",
",",
"0x15",
",",
"0x15",
",",
"0x01",
",",
"0x50",
",",
"0x00",
",",
"0x44",
",",
"0x04",
",",
"0x50",
",",
"0x51",
",",
"0x45",
",",
"0x50",
",",
"0x54",
",",
"0x41",
",",
"0x40",
",",
"0x14",
",",
"0x40",
",",
"0x50",
",",
"0x45",
",",
"0x10",
",",
"0x05",
",",
"0x50",
",",
"0x01",
",",
"0x40",
",",
"0x01",
",",
"0x50",
",",
"0x50",
",",
"0x50",
",",
"0x44",
",",
"0x40",
",",
"0x10",
",",
"}",
";",
"static",
"const",
"int",
"swap1_317",
"[",
"1",
"+",
"64",
"]",
"=",
"{",
"7",
",",
"1",
",",
"11",
",",
"23",
",",
"17",
",",
"23",
",",
"0",
",",
"15",
",",
"19",
",",
"20",
",",
"12",
",",
"10",
",",
"0",
",",
"18",
",",
"18",
",",
"5",
",",
"20",
",",
"13",
",",
"0",
",",
"18",
",",
"14",
",",
"5",
",",
"6",
",",
"10",
",",
"21",
",",
"1",
",",
"11",
",",
"9",
",",
"3",
",",
"21",
",",
"4",
",",
"1",
",",
"17",
",",
"5",
",",
"7",
",",
"16",
",",
"13",
",",
"19",
",",
"23",
",",
"20",
",",
"2",
",",
"10",
",",
"23",
",",
"23",
",",
"15",
",",
"10",
",",
"12",
",",
"0",
",",
"22",
",",
"14",
",",
"6",
",",
"15",
",",
"11",
",",
"17",
",",
"15",
",",
"21",
",",
"0",
",",
"6",
",",
"1",
",",
"1",
",",
"18",
",",
"5",
",",
"15",
",",
"15",
",",
"20",
",",
"}",
";",
"static",
"const",
"int",
"swap2_317",
"[",
"2",
"+",
"64",
"]",
"=",
"{",
"7",
",",
"12",
",",
"18",
",",
"8",
",",
"21",
",",
"0",
",",
"22",
",",
"21",
",",
"13",
",",
"21",
",",
"20",
",",
"13",
",",
"20",
",",
"14",
",",
"6",
",",
"3",
",",
"5",
",",
"20",
",",
"8",
",",
"20",
",",
"4",
",",
"8",
",",
"17",
",",
"22",
",",
"0",
",",
"0",
",",
"6",
",",
"17",
",",
"17",
",",
"9",
",",
"0",
",",
"16",
",",
"13",
",",
"21",
",",
"3",
",",
"2",
",",
"18",
",",
"6",
",",
"11",
",",
"3",
",",
"3",
",",
"18",
",",
"18",
",",
"19",
",",
"3",
",",
"0",
",",
"5",
",",
"0",
",",
"11",
",",
"8",
",",
"8",
",",
"1",
",",
"7",
",",
"2",
",",
"10",
",",
"8",
",",
"10",
",",
"2",
",",
"1",
",",
"3",
",",
"12",
",",
"16",
",",
"0",
",",
"17",
",",
"10",
",",
"1",
",",
"}",
";",
"if",
"(",
"order",
")",
"sega_decode_2",
"(",
"machine",
",",
"cputag",
",",
"xor2_317",
"+",
"opcode_shift",
",",
"swap2_317",
"+",
"opcode_shift",
",",
"xor1_317",
"+",
"data_shift",
",",
"swap1_317",
"+",
"data_shift",
")",
";",
"else",
"sega_decode_2",
"(",
"machine",
",",
"cputag",
",",
"xor1_317",
"+",
"opcode_shift",
",",
"swap1_317",
"+",
"opcode_shift",
",",
"xor2_317",
"+",
"data_shift",
",",
"swap2_317",
"+",
"data_shift",
")",
";",
"}"
] | These games (all 317-xxxx CPUs) use the same algorithm, but the key doesn't
change much - just one or two positions shift in the table. | [
"These",
"games",
"(",
"all",
"317",
"-",
"xxxx",
"CPUs",
")",
"use",
"the",
"same",
"algorithm",
"but",
"the",
"key",
"doesn",
"'",
"t",
"change",
"much",
"-",
"just",
"one",
"or",
"two",
"positions",
"shift",
"in",
"the",
"table",
"."
] | [] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "cputag",
"type": "char"
},
{
"param": "order",
"type": "int"
},
{
"param": "opcode_shift",
"type": "int"
},
{
"param": "data_shift",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "machine",
"type": "running_machine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cputag",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "order",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "opcode_shift",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "data_shift",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8723353d609061be4e60232436ac47364a688d78 | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/video/bfm_adr2.c | [
"Unlicense"
] | C | adder2_decode_char_roms | void | void adder2_decode_char_roms(running_machine *machine)
{
UINT8 *p;
p = memory_region(machine, "gfx1");
if ( p )
{
UINT8 *s;
s = alloc_array_or_die(UINT8, 0x40000 );
{
int x, y;
memcpy(s, p, 0x40000);
y = 0;
while ( y < 128 )
{
x = 0;
while ( x < 64 )
{
UINT8 *src = s + (y*256*8)+(x*4);
*p++ = src[0*256+0];*p++ = src[0*256+1];*p++ = src[0*256+2];*p++ = src[0*256+3];
*p++ = src[1*256+0];*p++ = src[1*256+1];*p++ = src[1*256+2];*p++ = src[1*256+3];
*p++ = src[2*256+0];*p++ = src[2*256+1];*p++ = src[2*256+2];*p++ = src[2*256+3];
*p++ = src[3*256+0];*p++ = src[3*256+1];*p++ = src[3*256+2];*p++ = src[3*256+3];
*p++ = src[4*256+0];*p++ = src[4*256+1];*p++ = src[4*256+2];*p++ = src[4*256+3];
*p++ = src[5*256+0];*p++ = src[5*256+1];*p++ = src[5*256+2];*p++ = src[5*256+3];
*p++ = src[6*256+0];*p++ = src[6*256+1];*p++ = src[6*256+2];*p++ = src[6*256+3];
*p++ = src[7*256+0];*p++ = src[7*256+1];*p++ = src[7*256+2];*p++ = src[7*256+3];
x++;
}
y++;
}
free(s);
}
}
} | ////////////////////////////////////////////////////////////////////
// //
// decode character data to a format which can be decoded by MAME //
// //
//////////////////////////////////////////////////////////////////// | decode character data to a format which can be decoded by MAME | [
"decode",
"character",
"data",
"to",
"a",
"format",
"which",
"can",
"be",
"decoded",
"by",
"MAME"
] | void adder2_decode_char_roms(running_machine *machine)
{
UINT8 *p;
p = memory_region(machine, "gfx1");
if ( p )
{
UINT8 *s;
s = alloc_array_or_die(UINT8, 0x40000 );
{
int x, y;
memcpy(s, p, 0x40000);
y = 0;
while ( y < 128 )
{
x = 0;
while ( x < 64 )
{
UINT8 *src = s + (y*256*8)+(x*4);
*p++ = src[0*256+0];*p++ = src[0*256+1];*p++ = src[0*256+2];*p++ = src[0*256+3];
*p++ = src[1*256+0];*p++ = src[1*256+1];*p++ = src[1*256+2];*p++ = src[1*256+3];
*p++ = src[2*256+0];*p++ = src[2*256+1];*p++ = src[2*256+2];*p++ = src[2*256+3];
*p++ = src[3*256+0];*p++ = src[3*256+1];*p++ = src[3*256+2];*p++ = src[3*256+3];
*p++ = src[4*256+0];*p++ = src[4*256+1];*p++ = src[4*256+2];*p++ = src[4*256+3];
*p++ = src[5*256+0];*p++ = src[5*256+1];*p++ = src[5*256+2];*p++ = src[5*256+3];
*p++ = src[6*256+0];*p++ = src[6*256+1];*p++ = src[6*256+2];*p++ = src[6*256+3];
*p++ = src[7*256+0];*p++ = src[7*256+1];*p++ = src[7*256+2];*p++ = src[7*256+3];
x++;
}
y++;
}
free(s);
}
}
} | [
"void",
"adder2_decode_char_roms",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"UINT8",
"*",
"p",
";",
"p",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"if",
"(",
"p",
")",
"{",
"UINT8",
"*",
"s",
";",
"s",
"=",
"alloc_array_or_die",
"(",
"UINT8",
",",
"0x40000",
")",
";",
"{",
"int",
"x",
",",
"y",
";",
"memcpy",
"(",
"s",
",",
"p",
",",
"0x40000",
")",
";",
"y",
"=",
"0",
";",
"while",
"(",
"y",
"<",
"128",
")",
"{",
"x",
"=",
"0",
";",
"while",
"(",
"x",
"<",
"64",
")",
"{",
"UINT8",
"*",
"src",
"=",
"s",
"+",
"(",
"y",
"*",
"256",
"*",
"8",
")",
"+",
"(",
"x",
"*",
"4",
")",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"0",
"*",
"256",
"+",
"0",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"0",
"*",
"256",
"+",
"1",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"0",
"*",
"256",
"+",
"2",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"0",
"*",
"256",
"+",
"3",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"1",
"*",
"256",
"+",
"0",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"1",
"*",
"256",
"+",
"1",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"1",
"*",
"256",
"+",
"2",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"1",
"*",
"256",
"+",
"3",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"2",
"*",
"256",
"+",
"0",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"2",
"*",
"256",
"+",
"1",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"2",
"*",
"256",
"+",
"2",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"2",
"*",
"256",
"+",
"3",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"3",
"*",
"256",
"+",
"0",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"3",
"*",
"256",
"+",
"1",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"3",
"*",
"256",
"+",
"2",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"3",
"*",
"256",
"+",
"3",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"4",
"*",
"256",
"+",
"0",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"4",
"*",
"256",
"+",
"1",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"4",
"*",
"256",
"+",
"2",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"4",
"*",
"256",
"+",
"3",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"5",
"*",
"256",
"+",
"0",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"5",
"*",
"256",
"+",
"1",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"5",
"*",
"256",
"+",
"2",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"5",
"*",
"256",
"+",
"3",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"6",
"*",
"256",
"+",
"0",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"6",
"*",
"256",
"+",
"1",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"6",
"*",
"256",
"+",
"2",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"6",
"*",
"256",
"+",
"3",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"7",
"*",
"256",
"+",
"0",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"7",
"*",
"256",
"+",
"1",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"7",
"*",
"256",
"+",
"2",
"]",
";",
"*",
"p",
"++",
"=",
"src",
"[",
"7",
"*",
"256",
"+",
"3",
"]",
";",
"x",
"++",
";",
"}",
"y",
"++",
";",
"}",
"free",
"(",
"s",
")",
";",
"}",
"}",
"}"
] | decode character data to a format which can be decoded by MAME | [
"decode",
"character",
"data",
"to",
"a",
"format",
"which",
"can",
"be",
"decoded",
"by",
"MAME"
] | [] | [
{
"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": []
} |
8eb7cbd2bbd089ff90112a2cbd34f62ad24c485f | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/lib/util/bitmap.c | [
"Unlicense"
] | C | bitmap_alloc_slop | bitmap_t | bitmap_t *bitmap_alloc_slop(int width, int height, int xslop, int yslop, bitmap_format format)
{
int bpp = bitmap_format_to_bpp(format);
size_t allocbytes;
bitmap_t *bitmap;
int rowpixels;
/* fail if invalid format */
if (bpp == 0)
return NULL;
/* allocate the bitmap itself */
bitmap = (bitmap_t *)malloc(sizeof(*bitmap));
if (bitmap == NULL)
return NULL;
memset(bitmap, 0, sizeof(*bitmap));
/* round the width to a multiple of 8 and add some padding */
rowpixels = (width + 2 * xslop + 7) & ~7;
/* allocate memory for the bitmap itself */
allocbytes = rowpixels * (height + 2 * yslop) * bpp / 8;
bitmap->alloc = malloc(allocbytes);
if (bitmap->alloc == NULL)
{
free(bitmap);
return NULL;
}
/* clear to 0 by default */
memset(bitmap->alloc, 0, allocbytes);
/* fill in the data */
bitmap->format = format;
bitmap->width = width;
bitmap->height = height;
bitmap->bpp = bpp;
bitmap->rowpixels = rowpixels;
bitmap->base = (UINT8 *)bitmap->alloc + (rowpixels * yslop + xslop) * (bpp / 8);
bitmap->cliprect.min_x = 0;
bitmap->cliprect.max_x = width - 1;
bitmap->cliprect.min_y = 0;
bitmap->cliprect.max_y = height - 1;
return bitmap;
} | /*-------------------------------------------------
bitmap_alloc_slop -- allocate a new bitmap with
additional slop on the borders
-------------------------------------------------*/ | - allocate a new bitmap with
additional slop on the borders | [
"-",
"allocate",
"a",
"new",
"bitmap",
"with",
"additional",
"slop",
"on",
"the",
"borders"
] | bitmap_t *bitmap_alloc_slop(int width, int height, int xslop, int yslop, bitmap_format format)
{
int bpp = bitmap_format_to_bpp(format);
size_t allocbytes;
bitmap_t *bitmap;
int rowpixels;
if (bpp == 0)
return NULL;
bitmap = (bitmap_t *)malloc(sizeof(*bitmap));
if (bitmap == NULL)
return NULL;
memset(bitmap, 0, sizeof(*bitmap));
rowpixels = (width + 2 * xslop + 7) & ~7;
allocbytes = rowpixels * (height + 2 * yslop) * bpp / 8;
bitmap->alloc = malloc(allocbytes);
if (bitmap->alloc == NULL)
{
free(bitmap);
return NULL;
}
memset(bitmap->alloc, 0, allocbytes);
bitmap->format = format;
bitmap->width = width;
bitmap->height = height;
bitmap->bpp = bpp;
bitmap->rowpixels = rowpixels;
bitmap->base = (UINT8 *)bitmap->alloc + (rowpixels * yslop + xslop) * (bpp / 8);
bitmap->cliprect.min_x = 0;
bitmap->cliprect.max_x = width - 1;
bitmap->cliprect.min_y = 0;
bitmap->cliprect.max_y = height - 1;
return bitmap;
} | [
"bitmap_t",
"*",
"bitmap_alloc_slop",
"(",
"int",
"width",
",",
"int",
"height",
",",
"int",
"xslop",
",",
"int",
"yslop",
",",
"bitmap_format",
"format",
")",
"{",
"int",
"bpp",
"=",
"bitmap_format_to_bpp",
"(",
"format",
")",
";",
"size_t",
"allocbytes",
";",
"bitmap_t",
"*",
"bitmap",
";",
"int",
"rowpixels",
";",
"if",
"(",
"bpp",
"==",
"0",
")",
"return",
"NULL",
";",
"bitmap",
"=",
"(",
"bitmap_t",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"*",
"bitmap",
")",
")",
";",
"if",
"(",
"bitmap",
"==",
"NULL",
")",
"return",
"NULL",
";",
"memset",
"(",
"bitmap",
",",
"0",
",",
"sizeof",
"(",
"*",
"bitmap",
")",
")",
";",
"rowpixels",
"=",
"(",
"width",
"+",
"2",
"*",
"xslop",
"+",
"7",
")",
"&",
"~",
"7",
";",
"allocbytes",
"=",
"rowpixels",
"*",
"(",
"height",
"+",
"2",
"*",
"yslop",
")",
"*",
"bpp",
"/",
"8",
";",
"bitmap",
"->",
"alloc",
"=",
"malloc",
"(",
"allocbytes",
")",
";",
"if",
"(",
"bitmap",
"->",
"alloc",
"==",
"NULL",
")",
"{",
"free",
"(",
"bitmap",
")",
";",
"return",
"NULL",
";",
"}",
"memset",
"(",
"bitmap",
"->",
"alloc",
",",
"0",
",",
"allocbytes",
")",
";",
"bitmap",
"->",
"format",
"=",
"format",
";",
"bitmap",
"->",
"width",
"=",
"width",
";",
"bitmap",
"->",
"height",
"=",
"height",
";",
"bitmap",
"->",
"bpp",
"=",
"bpp",
";",
"bitmap",
"->",
"rowpixels",
"=",
"rowpixels",
";",
"bitmap",
"->",
"base",
"=",
"(",
"UINT8",
"*",
")",
"bitmap",
"->",
"alloc",
"+",
"(",
"rowpixels",
"*",
"yslop",
"+",
"xslop",
")",
"*",
"(",
"bpp",
"/",
"8",
")",
";",
"bitmap",
"->",
"cliprect",
".",
"min_x",
"=",
"0",
";",
"bitmap",
"->",
"cliprect",
".",
"max_x",
"=",
"width",
"-",
"1",
";",
"bitmap",
"->",
"cliprect",
".",
"min_y",
"=",
"0",
";",
"bitmap",
"->",
"cliprect",
".",
"max_y",
"=",
"height",
"-",
"1",
";",
"return",
"bitmap",
";",
"}"
] | bitmap_alloc_slop -- allocate a new bitmap with
additional slop on the borders | [
"bitmap_alloc_slop",
"--",
"allocate",
"a",
"new",
"bitmap",
"with",
"additional",
"slop",
"on",
"the",
"borders"
] | [
"/* fail if invalid format */",
"/* allocate the bitmap itself */",
"/* round the width to a multiple of 8 and add some padding */",
"/* allocate memory for the bitmap itself */",
"/* clear to 0 by default */",
"/* fill in the data */"
] | [
{
"param": "width",
"type": "int"
},
{
"param": "height",
"type": "int"
},
{
"param": "xslop",
"type": "int"
},
{
"param": "yslop",
"type": "int"
},
{
"param": "format",
"type": "bitmap_format"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "width",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "height",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "xslop",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "yslop",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "format",
"type": "bitmap_format",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8eb7cbd2bbd089ff90112a2cbd34f62ad24c485f | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/lib/util/bitmap.c | [
"Unlicense"
] | C | bitmap_wrap | bitmap_t | bitmap_t *bitmap_wrap(void *base, int width, int height, int rowpixels, bitmap_format format)
{
int bpp = bitmap_format_to_bpp(format);
bitmap_t *bitmap;
/* fail if invalid format */
if (bpp == 0)
return NULL;
/* allocate memory */
bitmap = (bitmap_t *)malloc(sizeof(*bitmap));
if (bitmap == NULL)
return NULL;
memset(bitmap, 0, sizeof(*bitmap));
/* fill in the data */
bitmap->format = format;
bitmap->width = width;
bitmap->height = height;
bitmap->bpp = bpp;
bitmap->rowpixels = rowpixels;
bitmap->base = base;
bitmap->cliprect.min_x = 0;
bitmap->cliprect.max_x = width - 1;
bitmap->cliprect.min_y = 0;
bitmap->cliprect.max_y = height - 1;
return bitmap;
} | /*-------------------------------------------------
bitmap_wrap -- wrap an existing memory buffer
as a bitmap
-------------------------------------------------*/ | - wrap an existing memory buffer
as a bitmap | [
"-",
"wrap",
"an",
"existing",
"memory",
"buffer",
"as",
"a",
"bitmap"
] | bitmap_t *bitmap_wrap(void *base, int width, int height, int rowpixels, bitmap_format format)
{
int bpp = bitmap_format_to_bpp(format);
bitmap_t *bitmap;
if (bpp == 0)
return NULL;
bitmap = (bitmap_t *)malloc(sizeof(*bitmap));
if (bitmap == NULL)
return NULL;
memset(bitmap, 0, sizeof(*bitmap));
bitmap->format = format;
bitmap->width = width;
bitmap->height = height;
bitmap->bpp = bpp;
bitmap->rowpixels = rowpixels;
bitmap->base = base;
bitmap->cliprect.min_x = 0;
bitmap->cliprect.max_x = width - 1;
bitmap->cliprect.min_y = 0;
bitmap->cliprect.max_y = height - 1;
return bitmap;
} | [
"bitmap_t",
"*",
"bitmap_wrap",
"(",
"void",
"*",
"base",
",",
"int",
"width",
",",
"int",
"height",
",",
"int",
"rowpixels",
",",
"bitmap_format",
"format",
")",
"{",
"int",
"bpp",
"=",
"bitmap_format_to_bpp",
"(",
"format",
")",
";",
"bitmap_t",
"*",
"bitmap",
";",
"if",
"(",
"bpp",
"==",
"0",
")",
"return",
"NULL",
";",
"bitmap",
"=",
"(",
"bitmap_t",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"*",
"bitmap",
")",
")",
";",
"if",
"(",
"bitmap",
"==",
"NULL",
")",
"return",
"NULL",
";",
"memset",
"(",
"bitmap",
",",
"0",
",",
"sizeof",
"(",
"*",
"bitmap",
")",
")",
";",
"bitmap",
"->",
"format",
"=",
"format",
";",
"bitmap",
"->",
"width",
"=",
"width",
";",
"bitmap",
"->",
"height",
"=",
"height",
";",
"bitmap",
"->",
"bpp",
"=",
"bpp",
";",
"bitmap",
"->",
"rowpixels",
"=",
"rowpixels",
";",
"bitmap",
"->",
"base",
"=",
"base",
";",
"bitmap",
"->",
"cliprect",
".",
"min_x",
"=",
"0",
";",
"bitmap",
"->",
"cliprect",
".",
"max_x",
"=",
"width",
"-",
"1",
";",
"bitmap",
"->",
"cliprect",
".",
"min_y",
"=",
"0",
";",
"bitmap",
"->",
"cliprect",
".",
"max_y",
"=",
"height",
"-",
"1",
";",
"return",
"bitmap",
";",
"}"
] | bitmap_wrap -- wrap an existing memory buffer
as a bitmap | [
"bitmap_wrap",
"--",
"wrap",
"an",
"existing",
"memory",
"buffer",
"as",
"a",
"bitmap"
] | [
"/* fail if invalid format */",
"/* allocate memory */",
"/* fill in the data */"
] | [
{
"param": "base",
"type": "void"
},
{
"param": "width",
"type": "int"
},
{
"param": "height",
"type": "int"
},
{
"param": "rowpixels",
"type": "int"
},
{
"param": "format",
"type": "bitmap_format"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "base",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "width",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "height",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "rowpixels",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "format",
"type": "bitmap_format",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8eb7cbd2bbd089ff90112a2cbd34f62ad24c485f | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/lib/util/bitmap.c | [
"Unlicense"
] | C | bitmap_fill | void | void bitmap_fill(bitmap_t *dest, const rectangle *cliprect, UINT32 color)
{
rectangle fill = dest->cliprect;
int x, y;
/* if we have a cliprect, intersect with that */
if (cliprect != NULL)
sect_rect(&fill, cliprect);
/* early out if nothing to do */
if (fill.min_x > fill.max_x || fill.min_y > fill.max_y)
return;
/* based on the bpp go from there */
switch (dest->bpp)
{
case 8:
/* 8bpp always uses memset */
for (y = fill.min_y; y <= fill.max_y; y++)
memset(BITMAP_ADDR8(dest, y, fill.min_x), (UINT8)color, fill.max_x + 1 - fill.min_x);
break;
case 16:
/* 16bpp can use memset if the bytes are equal */
if ((UINT8)(color >> 8) == (UINT8)color)
{
for (y = fill.min_y; y <= fill.max_y; y++)
memset(BITMAP_ADDR16(dest, y, fill.min_x), (UINT8)color, (fill.max_x + 1 - fill.min_x) * 2);
}
else
{
UINT16 *destrow, *destrow0;
/* Fill the first line the hard way */
destrow = BITMAP_ADDR16(dest, fill.min_y, 0);
for (x = fill.min_x; x <= fill.max_x; x++)
destrow[x] = (UINT16)color;
/* For the other lines, just copy the first one */
destrow0 = BITMAP_ADDR16(dest, fill.min_y, fill.min_x);
for (y = fill.min_y + 1; y <= fill.max_y; y++)
{
destrow = BITMAP_ADDR16(dest, y, fill.min_x);
memcpy(destrow, destrow0, (fill.max_x + 1 - fill.min_x) * 2);
}
}
break;
case 32:
/* 32bpp can use memset if the bytes are equal */
if ((UINT8)(color >> 8) == (UINT8)color && (UINT16)(color >> 16) == (UINT16)color)
{
for (y = fill.min_y; y <= fill.max_y; y++)
memset(BITMAP_ADDR32(dest, y, fill.min_x), (UINT8)color, (fill.max_x + 1 - fill.min_x) * 4);
}
else
{
UINT32 *destrow, *destrow0;
/* Fill the first line the hard way */
destrow = BITMAP_ADDR32(dest, fill.min_y, 0);
for (x = fill.min_x; x <= fill.max_x; x++)
destrow[x] = (UINT32)color;
/* For the other lines, just copy the first one */
destrow0 = BITMAP_ADDR32(dest, fill.min_y, fill.min_x);
for (y = fill.min_y + 1; y <= fill.max_y; y++)
{
destrow = BITMAP_ADDR32(dest, y, fill.min_x);
memcpy(destrow, destrow0, (fill.max_x + 1 - fill.min_x) * 4);
}
}
break;
case 64:
/* 64bpp can use memset if the bytes are equal */
if ((UINT8)(color >> 8) == (UINT8)color && (UINT16)(color >> 16) == (UINT16)color)
{
for (y = fill.min_y; y <= fill.max_y; y++)
memset(BITMAP_ADDR64(dest, y, fill.min_x), (UINT8)color, (fill.max_x + 1 - fill.min_x) * 4);
}
else
{
UINT64 *destrow, *destrow0;
/* Fill the first line the hard way */
destrow = BITMAP_ADDR64(dest, fill.min_y, 0);
for (x = fill.min_x; x <= fill.max_x; x++)
destrow[x] = (UINT64)color;
/* For the other lines, just copy the first one */
destrow0 = BITMAP_ADDR64(dest, fill.min_y, fill.min_x);
for (y = fill.min_y + 1; y <= fill.max_y; y++)
{
destrow = BITMAP_ADDR64(dest, y, fill.min_x);
memcpy(destrow, destrow0, (fill.max_x + 1 - fill.min_x) * 4);
}
}
break;
}
} | /*-------------------------------------------------
bitmap_fill -- fill a bitmap with a solid
color
-------------------------------------------------*/ | - fill a bitmap with a solid
color | [
"-",
"fill",
"a",
"bitmap",
"with",
"a",
"solid",
"color"
] | void bitmap_fill(bitmap_t *dest, const rectangle *cliprect, UINT32 color)
{
rectangle fill = dest->cliprect;
int x, y;
if (cliprect != NULL)
sect_rect(&fill, cliprect);
if (fill.min_x > fill.max_x || fill.min_y > fill.max_y)
return;
switch (dest->bpp)
{
case 8:
for (y = fill.min_y; y <= fill.max_y; y++)
memset(BITMAP_ADDR8(dest, y, fill.min_x), (UINT8)color, fill.max_x + 1 - fill.min_x);
break;
case 16:
if ((UINT8)(color >> 8) == (UINT8)color)
{
for (y = fill.min_y; y <= fill.max_y; y++)
memset(BITMAP_ADDR16(dest, y, fill.min_x), (UINT8)color, (fill.max_x + 1 - fill.min_x) * 2);
}
else
{
UINT16 *destrow, *destrow0;
destrow = BITMAP_ADDR16(dest, fill.min_y, 0);
for (x = fill.min_x; x <= fill.max_x; x++)
destrow[x] = (UINT16)color;
destrow0 = BITMAP_ADDR16(dest, fill.min_y, fill.min_x);
for (y = fill.min_y + 1; y <= fill.max_y; y++)
{
destrow = BITMAP_ADDR16(dest, y, fill.min_x);
memcpy(destrow, destrow0, (fill.max_x + 1 - fill.min_x) * 2);
}
}
break;
case 32:
if ((UINT8)(color >> 8) == (UINT8)color && (UINT16)(color >> 16) == (UINT16)color)
{
for (y = fill.min_y; y <= fill.max_y; y++)
memset(BITMAP_ADDR32(dest, y, fill.min_x), (UINT8)color, (fill.max_x + 1 - fill.min_x) * 4);
}
else
{
UINT32 *destrow, *destrow0;
destrow = BITMAP_ADDR32(dest, fill.min_y, 0);
for (x = fill.min_x; x <= fill.max_x; x++)
destrow[x] = (UINT32)color;
destrow0 = BITMAP_ADDR32(dest, fill.min_y, fill.min_x);
for (y = fill.min_y + 1; y <= fill.max_y; y++)
{
destrow = BITMAP_ADDR32(dest, y, fill.min_x);
memcpy(destrow, destrow0, (fill.max_x + 1 - fill.min_x) * 4);
}
}
break;
case 64:
if ((UINT8)(color >> 8) == (UINT8)color && (UINT16)(color >> 16) == (UINT16)color)
{
for (y = fill.min_y; y <= fill.max_y; y++)
memset(BITMAP_ADDR64(dest, y, fill.min_x), (UINT8)color, (fill.max_x + 1 - fill.min_x) * 4);
}
else
{
UINT64 *destrow, *destrow0;
destrow = BITMAP_ADDR64(dest, fill.min_y, 0);
for (x = fill.min_x; x <= fill.max_x; x++)
destrow[x] = (UINT64)color;
destrow0 = BITMAP_ADDR64(dest, fill.min_y, fill.min_x);
for (y = fill.min_y + 1; y <= fill.max_y; y++)
{
destrow = BITMAP_ADDR64(dest, y, fill.min_x);
memcpy(destrow, destrow0, (fill.max_x + 1 - fill.min_x) * 4);
}
}
break;
}
} | [
"void",
"bitmap_fill",
"(",
"bitmap_t",
"*",
"dest",
",",
"const",
"rectangle",
"*",
"cliprect",
",",
"UINT32",
"color",
")",
"{",
"rectangle",
"fill",
"=",
"dest",
"->",
"cliprect",
";",
"int",
"x",
",",
"y",
";",
"if",
"(",
"cliprect",
"!=",
"NULL",
")",
"sect_rect",
"(",
"&",
"fill",
",",
"cliprect",
")",
";",
"if",
"(",
"fill",
".",
"min_x",
">",
"fill",
".",
"max_x",
"||",
"fill",
".",
"min_y",
">",
"fill",
".",
"max_y",
")",
"return",
";",
"switch",
"(",
"dest",
"->",
"bpp",
")",
"{",
"case",
"8",
":",
"for",
"(",
"y",
"=",
"fill",
".",
"min_y",
";",
"y",
"<=",
"fill",
".",
"max_y",
";",
"y",
"++",
")",
"memset",
"(",
"BITMAP_ADDR8",
"(",
"dest",
",",
"y",
",",
"fill",
".",
"min_x",
")",
",",
"(",
"UINT8",
")",
"color",
",",
"fill",
".",
"max_x",
"+",
"1",
"-",
"fill",
".",
"min_x",
")",
";",
"break",
";",
"case",
"16",
":",
"if",
"(",
"(",
"UINT8",
")",
"(",
"color",
">>",
"8",
")",
"==",
"(",
"UINT8",
")",
"color",
")",
"{",
"for",
"(",
"y",
"=",
"fill",
".",
"min_y",
";",
"y",
"<=",
"fill",
".",
"max_y",
";",
"y",
"++",
")",
"memset",
"(",
"BITMAP_ADDR16",
"(",
"dest",
",",
"y",
",",
"fill",
".",
"min_x",
")",
",",
"(",
"UINT8",
")",
"color",
",",
"(",
"fill",
".",
"max_x",
"+",
"1",
"-",
"fill",
".",
"min_x",
")",
"*",
"2",
")",
";",
"}",
"else",
"{",
"UINT16",
"*",
"destrow",
",",
"*",
"destrow0",
";",
"destrow",
"=",
"BITMAP_ADDR16",
"(",
"dest",
",",
"fill",
".",
"min_y",
",",
"0",
")",
";",
"for",
"(",
"x",
"=",
"fill",
".",
"min_x",
";",
"x",
"<=",
"fill",
".",
"max_x",
";",
"x",
"++",
")",
"destrow",
"[",
"x",
"]",
"=",
"(",
"UINT16",
")",
"color",
";",
"destrow0",
"=",
"BITMAP_ADDR16",
"(",
"dest",
",",
"fill",
".",
"min_y",
",",
"fill",
".",
"min_x",
")",
";",
"for",
"(",
"y",
"=",
"fill",
".",
"min_y",
"+",
"1",
";",
"y",
"<=",
"fill",
".",
"max_y",
";",
"y",
"++",
")",
"{",
"destrow",
"=",
"BITMAP_ADDR16",
"(",
"dest",
",",
"y",
",",
"fill",
".",
"min_x",
")",
";",
"memcpy",
"(",
"destrow",
",",
"destrow0",
",",
"(",
"fill",
".",
"max_x",
"+",
"1",
"-",
"fill",
".",
"min_x",
")",
"*",
"2",
")",
";",
"}",
"}",
"break",
";",
"case",
"32",
":",
"if",
"(",
"(",
"UINT8",
")",
"(",
"color",
">>",
"8",
")",
"==",
"(",
"UINT8",
")",
"color",
"&&",
"(",
"UINT16",
")",
"(",
"color",
">>",
"16",
")",
"==",
"(",
"UINT16",
")",
"color",
")",
"{",
"for",
"(",
"y",
"=",
"fill",
".",
"min_y",
";",
"y",
"<=",
"fill",
".",
"max_y",
";",
"y",
"++",
")",
"memset",
"(",
"BITMAP_ADDR32",
"(",
"dest",
",",
"y",
",",
"fill",
".",
"min_x",
")",
",",
"(",
"UINT8",
")",
"color",
",",
"(",
"fill",
".",
"max_x",
"+",
"1",
"-",
"fill",
".",
"min_x",
")",
"*",
"4",
")",
";",
"}",
"else",
"{",
"UINT32",
"*",
"destrow",
",",
"*",
"destrow0",
";",
"destrow",
"=",
"BITMAP_ADDR32",
"(",
"dest",
",",
"fill",
".",
"min_y",
",",
"0",
")",
";",
"for",
"(",
"x",
"=",
"fill",
".",
"min_x",
";",
"x",
"<=",
"fill",
".",
"max_x",
";",
"x",
"++",
")",
"destrow",
"[",
"x",
"]",
"=",
"(",
"UINT32",
")",
"color",
";",
"destrow0",
"=",
"BITMAP_ADDR32",
"(",
"dest",
",",
"fill",
".",
"min_y",
",",
"fill",
".",
"min_x",
")",
";",
"for",
"(",
"y",
"=",
"fill",
".",
"min_y",
"+",
"1",
";",
"y",
"<=",
"fill",
".",
"max_y",
";",
"y",
"++",
")",
"{",
"destrow",
"=",
"BITMAP_ADDR32",
"(",
"dest",
",",
"y",
",",
"fill",
".",
"min_x",
")",
";",
"memcpy",
"(",
"destrow",
",",
"destrow0",
",",
"(",
"fill",
".",
"max_x",
"+",
"1",
"-",
"fill",
".",
"min_x",
")",
"*",
"4",
")",
";",
"}",
"}",
"break",
";",
"case",
"64",
":",
"if",
"(",
"(",
"UINT8",
")",
"(",
"color",
">>",
"8",
")",
"==",
"(",
"UINT8",
")",
"color",
"&&",
"(",
"UINT16",
")",
"(",
"color",
">>",
"16",
")",
"==",
"(",
"UINT16",
")",
"color",
")",
"{",
"for",
"(",
"y",
"=",
"fill",
".",
"min_y",
";",
"y",
"<=",
"fill",
".",
"max_y",
";",
"y",
"++",
")",
"memset",
"(",
"BITMAP_ADDR64",
"(",
"dest",
",",
"y",
",",
"fill",
".",
"min_x",
")",
",",
"(",
"UINT8",
")",
"color",
",",
"(",
"fill",
".",
"max_x",
"+",
"1",
"-",
"fill",
".",
"min_x",
")",
"*",
"4",
")",
";",
"}",
"else",
"{",
"UINT64",
"*",
"destrow",
",",
"*",
"destrow0",
";",
"destrow",
"=",
"BITMAP_ADDR64",
"(",
"dest",
",",
"fill",
".",
"min_y",
",",
"0",
")",
";",
"for",
"(",
"x",
"=",
"fill",
".",
"min_x",
";",
"x",
"<=",
"fill",
".",
"max_x",
";",
"x",
"++",
")",
"destrow",
"[",
"x",
"]",
"=",
"(",
"UINT64",
")",
"color",
";",
"destrow0",
"=",
"BITMAP_ADDR64",
"(",
"dest",
",",
"fill",
".",
"min_y",
",",
"fill",
".",
"min_x",
")",
";",
"for",
"(",
"y",
"=",
"fill",
".",
"min_y",
"+",
"1",
";",
"y",
"<=",
"fill",
".",
"max_y",
";",
"y",
"++",
")",
"{",
"destrow",
"=",
"BITMAP_ADDR64",
"(",
"dest",
",",
"y",
",",
"fill",
".",
"min_x",
")",
";",
"memcpy",
"(",
"destrow",
",",
"destrow0",
",",
"(",
"fill",
".",
"max_x",
"+",
"1",
"-",
"fill",
".",
"min_x",
")",
"*",
"4",
")",
";",
"}",
"}",
"break",
";",
"}",
"}"
] | bitmap_fill -- fill a bitmap with a solid
color | [
"bitmap_fill",
"--",
"fill",
"a",
"bitmap",
"with",
"a",
"solid",
"color"
] | [
"/* if we have a cliprect, intersect with that */",
"/* early out if nothing to do */",
"/* based on the bpp go from there */",
"/* 8bpp always uses memset */",
"/* 16bpp can use memset if the bytes are equal */",
"/* Fill the first line the hard way */",
"/* For the other lines, just copy the first one */",
"/* 32bpp can use memset if the bytes are equal */",
"/* Fill the first line the hard way */",
"/* For the other lines, just copy the first one */",
"/* 64bpp can use memset if the bytes are equal */",
"/* Fill the first line the hard way */",
"/* For the other lines, just copy the first one */"
] | [
{
"param": "dest",
"type": "bitmap_t"
},
{
"param": "cliprect",
"type": "rectangle"
},
{
"param": "color",
"type": "UINT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "dest",
"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": "color",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8eb7cbd2bbd089ff90112a2cbd34f62ad24c485f | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/lib/util/bitmap.c | [
"Unlicense"
] | C | bitmap_format_to_bpp | int | int bitmap_format_to_bpp(bitmap_format format)
{
/* choose a depth for the format */
switch (format)
{
case BITMAP_FORMAT_INDEXED8:
return 8;
case BITMAP_FORMAT_INDEXED16:
case BITMAP_FORMAT_RGB15:
case BITMAP_FORMAT_YUY16:
return 16;
case BITMAP_FORMAT_INDEXED32:
case BITMAP_FORMAT_RGB32:
case BITMAP_FORMAT_ARGB32:
return 32;
case BITMAP_FORMAT_INDEXED64:
return 64;
default:
break;
}
return 0;
} | /*-------------------------------------------------
bitmap_format_to_bpp - given a format, return
the bpp
-------------------------------------------------*/ | given a format, return
the bpp | [
"given",
"a",
"format",
"return",
"the",
"bpp"
] | int bitmap_format_to_bpp(bitmap_format format)
{
switch (format)
{
case BITMAP_FORMAT_INDEXED8:
return 8;
case BITMAP_FORMAT_INDEXED16:
case BITMAP_FORMAT_RGB15:
case BITMAP_FORMAT_YUY16:
return 16;
case BITMAP_FORMAT_INDEXED32:
case BITMAP_FORMAT_RGB32:
case BITMAP_FORMAT_ARGB32:
return 32;
case BITMAP_FORMAT_INDEXED64:
return 64;
default:
break;
}
return 0;
} | [
"int",
"bitmap_format_to_bpp",
"(",
"bitmap_format",
"format",
")",
"{",
"switch",
"(",
"format",
")",
"{",
"case",
"BITMAP_FORMAT_INDEXED8",
":",
"return",
"8",
";",
"case",
"BITMAP_FORMAT_INDEXED16",
":",
"case",
"BITMAP_FORMAT_RGB15",
":",
"case",
"BITMAP_FORMAT_YUY16",
":",
"return",
"16",
";",
"case",
"BITMAP_FORMAT_INDEXED32",
":",
"case",
"BITMAP_FORMAT_RGB32",
":",
"case",
"BITMAP_FORMAT_ARGB32",
":",
"return",
"32",
";",
"case",
"BITMAP_FORMAT_INDEXED64",
":",
"return",
"64",
";",
"default",
":",
"break",
";",
"}",
"return",
"0",
";",
"}"
] | bitmap_format_to_bpp - given a format, return
the bpp | [
"bitmap_format_to_bpp",
"-",
"given",
"a",
"format",
"return",
"the",
"bpp"
] | [
"/* choose a depth for the format */"
] | [
{
"param": "format",
"type": "bitmap_format"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "format",
"type": "bitmap_format",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a4395982cc4840ebd74d298952982254f703eaee | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/emu/sound/snkwave.c | [
"Unlicense"
] | C | update_waveform | void | static void update_waveform(snkwave_state *chip, unsigned int offset, UINT8 data)
{
assert(offset < WAVEFORM_LENGTH/4);
chip->waveform[offset * 2] = ((data & 0x38) >> 3) << (12-CLOCK_SHIFT);
chip->waveform[offset * 2 + 1] = ((data & 0x07) >> 0) << (12-CLOCK_SHIFT);
chip->waveform[WAVEFORM_LENGTH-2 - offset * 2] = ~chip->waveform[offset * 2 + 1];
chip->waveform[WAVEFORM_LENGTH-1 - offset * 2] = ~chip->waveform[offset * 2];
} | /* update the decoded waveform data */
/* The programmable waveform consists of 8 3-bit nibbles.
The waveform goes to a 4-bit DAC and is played alternatingly forwards and
backwards.
When going forwards, bit 3 is 1. When going backwards, it's 0.
So the sequence 01234567 will play as
89ABCDEF76543210
*/ | update the decoded waveform data
The programmable waveform consists of 8 3-bit nibbles.
The waveform goes to a 4-bit DAC and is played alternatingly forwards and
backwards.
When going forwards, bit 3 is 1. When going backwards, it's 0. | [
"update",
"the",
"decoded",
"waveform",
"data",
"The",
"programmable",
"waveform",
"consists",
"of",
"8",
"3",
"-",
"bit",
"nibbles",
".",
"The",
"waveform",
"goes",
"to",
"a",
"4",
"-",
"bit",
"DAC",
"and",
"is",
"played",
"alternatingly",
"forwards",
"and",
"backwards",
".",
"When",
"going",
"forwards",
"bit",
"3",
"is",
"1",
".",
"When",
"going",
"backwards",
"it",
"'",
"s",
"0",
"."
] | static void update_waveform(snkwave_state *chip, unsigned int offset, UINT8 data)
{
assert(offset < WAVEFORM_LENGTH/4);
chip->waveform[offset * 2] = ((data & 0x38) >> 3) << (12-CLOCK_SHIFT);
chip->waveform[offset * 2 + 1] = ((data & 0x07) >> 0) << (12-CLOCK_SHIFT);
chip->waveform[WAVEFORM_LENGTH-2 - offset * 2] = ~chip->waveform[offset * 2 + 1];
chip->waveform[WAVEFORM_LENGTH-1 - offset * 2] = ~chip->waveform[offset * 2];
} | [
"static",
"void",
"update_waveform",
"(",
"snkwave_state",
"*",
"chip",
",",
"unsigned",
"int",
"offset",
",",
"UINT8",
"data",
")",
"{",
"assert",
"(",
"offset",
"<",
"WAVEFORM_LENGTH",
"/",
"4",
")",
";",
"chip",
"->",
"waveform",
"[",
"offset",
"*",
"2",
"]",
"=",
"(",
"(",
"data",
"&",
"0x38",
")",
">>",
"3",
")",
"<<",
"(",
"12",
"-",
"CLOCK_SHIFT",
")",
";",
"chip",
"->",
"waveform",
"[",
"offset",
"*",
"2",
"+",
"1",
"]",
"=",
"(",
"(",
"data",
"&",
"0x07",
")",
">>",
"0",
")",
"<<",
"(",
"12",
"-",
"CLOCK_SHIFT",
")",
";",
"chip",
"->",
"waveform",
"[",
"WAVEFORM_LENGTH",
"-",
"2",
"-",
"offset",
"*",
"2",
"]",
"=",
"~",
"chip",
"->",
"waveform",
"[",
"offset",
"*",
"2",
"+",
"1",
"]",
";",
"chip",
"->",
"waveform",
"[",
"WAVEFORM_LENGTH",
"-",
"1",
"-",
"offset",
"*",
"2",
"]",
"=",
"~",
"chip",
"->",
"waveform",
"[",
"offset",
"*",
"2",
"]",
";",
"}"
] | update the decoded waveform data
The programmable waveform consists of 8 3-bit nibbles. | [
"update",
"the",
"decoded",
"waveform",
"data",
"The",
"programmable",
"waveform",
"consists",
"of",
"8",
"3",
"-",
"bit",
"nibbles",
"."
] | [] | [
{
"param": "chip",
"type": "snkwave_state"
},
{
"param": "offset",
"type": "unsigned int"
},
{
"param": "data",
"type": "UINT8"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "chip",
"type": "snkwave_state",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "offset",
"type": "unsigned int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "data",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
cd4be1614b9fcbb56b62f8ddfbf2292d77865e7c | lofunz/mieme | Reloaded/trunk/src/lib/util/avcomp.c | [
"Unlicense"
] | C | avcomp_init | avcomp_state | avcomp_state *avcomp_init(UINT32 maxwidth, UINT32 maxheight, UINT32 maxchannels)
{
huffman_error hufferr;
avcomp_state *state;
/* error if out of range */
if (maxchannels > MAX_CHANNELS)
return NULL;
/* allocate memory for state block */
state = (avcomp_state *)malloc(sizeof(*state));
if (state == NULL)
return NULL;
/* clear the buffers */
memset(state, 0, sizeof(*state));
/* compute the core info */
state->maxwidth = maxwidth;
state->maxheight = maxheight;
state->maxchannels = maxchannels;
/* now allocate data buffers */
state->audiodata = (UINT8 *)malloc(65536 * state->maxchannels * 2);
if (state->audiodata == NULL)
goto cleanup;
/* create huffman contexts */
hufferr = huffman_create_context(&state->ycontext, 16);
if (hufferr != HUFFERR_NONE)
goto cleanup;
hufferr = huffman_create_context(&state->cbcontext, 16);
if (hufferr != HUFFERR_NONE)
goto cleanup;
hufferr = huffman_create_context(&state->crcontext, 16);
if (hufferr != HUFFERR_NONE)
goto cleanup;
hufferr = huffman_create_context(&state->audiohicontext, 16);
if (hufferr != HUFFERR_NONE)
goto cleanup;
hufferr = huffman_create_context(&state->audiolocontext, 16);
if (hufferr != HUFFERR_NONE)
goto cleanup;
return state;
cleanup:
avcomp_free(state);
return NULL;
} | /*-------------------------------------------------
avcomp_init - allocate and initialize a
new state block for compression or
decompression
-------------------------------------------------*/ | allocate and initialize a
new state block for compression or
decompression | [
"allocate",
"and",
"initialize",
"a",
"new",
"state",
"block",
"for",
"compression",
"or",
"decompression"
] | avcomp_state *avcomp_init(UINT32 maxwidth, UINT32 maxheight, UINT32 maxchannels)
{
huffman_error hufferr;
avcomp_state *state;
if (maxchannels > MAX_CHANNELS)
return NULL;
state = (avcomp_state *)malloc(sizeof(*state));
if (state == NULL)
return NULL;
memset(state, 0, sizeof(*state));
state->maxwidth = maxwidth;
state->maxheight = maxheight;
state->maxchannels = maxchannels;
state->audiodata = (UINT8 *)malloc(65536 * state->maxchannels * 2);
if (state->audiodata == NULL)
goto cleanup;
hufferr = huffman_create_context(&state->ycontext, 16);
if (hufferr != HUFFERR_NONE)
goto cleanup;
hufferr = huffman_create_context(&state->cbcontext, 16);
if (hufferr != HUFFERR_NONE)
goto cleanup;
hufferr = huffman_create_context(&state->crcontext, 16);
if (hufferr != HUFFERR_NONE)
goto cleanup;
hufferr = huffman_create_context(&state->audiohicontext, 16);
if (hufferr != HUFFERR_NONE)
goto cleanup;
hufferr = huffman_create_context(&state->audiolocontext, 16);
if (hufferr != HUFFERR_NONE)
goto cleanup;
return state;
cleanup:
avcomp_free(state);
return NULL;
} | [
"avcomp_state",
"*",
"avcomp_init",
"(",
"UINT32",
"maxwidth",
",",
"UINT32",
"maxheight",
",",
"UINT32",
"maxchannels",
")",
"{",
"huffman_error",
"hufferr",
";",
"avcomp_state",
"*",
"state",
";",
"if",
"(",
"maxchannels",
">",
"MAX_CHANNELS",
")",
"return",
"NULL",
";",
"state",
"=",
"(",
"avcomp_state",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"*",
"state",
")",
")",
";",
"if",
"(",
"state",
"==",
"NULL",
")",
"return",
"NULL",
";",
"memset",
"(",
"state",
",",
"0",
",",
"sizeof",
"(",
"*",
"state",
")",
")",
";",
"state",
"->",
"maxwidth",
"=",
"maxwidth",
";",
"state",
"->",
"maxheight",
"=",
"maxheight",
";",
"state",
"->",
"maxchannels",
"=",
"maxchannels",
";",
"state",
"->",
"audiodata",
"=",
"(",
"UINT8",
"*",
")",
"malloc",
"(",
"65536",
"*",
"state",
"->",
"maxchannels",
"*",
"2",
")",
";",
"if",
"(",
"state",
"->",
"audiodata",
"==",
"NULL",
")",
"goto",
"cleanup",
";",
"hufferr",
"=",
"huffman_create_context",
"(",
"&",
"state",
"->",
"ycontext",
",",
"16",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"goto",
"cleanup",
";",
"hufferr",
"=",
"huffman_create_context",
"(",
"&",
"state",
"->",
"cbcontext",
",",
"16",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"goto",
"cleanup",
";",
"hufferr",
"=",
"huffman_create_context",
"(",
"&",
"state",
"->",
"crcontext",
",",
"16",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"goto",
"cleanup",
";",
"hufferr",
"=",
"huffman_create_context",
"(",
"&",
"state",
"->",
"audiohicontext",
",",
"16",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"goto",
"cleanup",
";",
"hufferr",
"=",
"huffman_create_context",
"(",
"&",
"state",
"->",
"audiolocontext",
",",
"16",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"goto",
"cleanup",
";",
"return",
"state",
";",
"cleanup",
":",
"avcomp_free",
"(",
"state",
")",
";",
"return",
"NULL",
";",
"}"
] | avcomp_init - allocate and initialize a
new state block for compression or
decompression | [
"avcomp_init",
"-",
"allocate",
"and",
"initialize",
"a",
"new",
"state",
"block",
"for",
"compression",
"or",
"decompression"
] | [
"/* error if out of range */",
"/* allocate memory for state block */",
"/* clear the buffers */",
"/* compute the core info */",
"/* now allocate data buffers */",
"/* create huffman contexts */"
] | [
{
"param": "maxwidth",
"type": "UINT32"
},
{
"param": "maxheight",
"type": "UINT32"
},
{
"param": "maxchannels",
"type": "UINT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "maxwidth",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "maxheight",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "maxchannels",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
cd4be1614b9fcbb56b62f8ddfbf2292d77865e7c | lofunz/mieme | Reloaded/trunk/src/lib/util/avcomp.c | [
"Unlicense"
] | C | avcomp_encode_data | avcomp_error | avcomp_error avcomp_encode_data(avcomp_state *state, const UINT8 *source, UINT8 *dest, UINT32 *complength)
{
const UINT8 *metastart, *videostart, *audiostart[MAX_CHANNELS];
UINT32 metasize, channels, samples, width, height;
UINT32 audioxor, videoxor, videostride;
avcomp_error err;
UINT32 dstoffs;
int chnum;
/* extract data from source if present */
if (source != NULL)
{
/* validate the header */
if (source[0] != 'c' || source[1] != 'h' || source[2] != 'a' || source[3] != 'v')
return AVCERR_INVALID_DATA;
/* extract info from the header */
metasize = source[4];
channels = source[5];
samples = (source[6] << 8) + source[7];
width = (source[8] << 8) + source[9];
height = (source[10] << 8) + source[11];
/* determine the start of each piece of data */
source += 12;
metastart = source;
source += metasize;
for (chnum = 0; chnum < channels; chnum++)
{
audiostart[chnum] = source;
source += 2 * samples;
}
videostart = source;
/* data is assumed to be big-endian already */
audioxor = videoxor = 0;
videostride = 2 * width;
}
/* otherwise, extract from the state */
else
{
UINT16 betest = 0;
/* extract metadata information */
metastart = state->compress.metadata;
metasize = state->compress.metalength;
if ((metastart == NULL && metasize != 0) || (metastart != NULL && metasize == 0))
return AVCERR_INVALID_CONFIGURATION;
/* extract audio information */
channels = state->compress.channels;
samples = state->compress.samples;
for (chnum = 0; chnum < channels; chnum++)
audiostart[chnum] = (const UINT8 *)state->compress.audio[chnum];
/* extract video information */
videostart = NULL;
videostride = width = height = 0;
if (state->compress.video != NULL)
{
videostart = (const UINT8 *)state->compress.video->base;
videostride = state->compress.video->rowpixels * 2;
width = state->compress.video->width;
height = state->compress.video->height;
}
/* data is assumed to be native-endian */
*(UINT8 *)&betest = 1;
audioxor = videoxor = (betest == 1) ? 1 : 0;
}
/* validate the info from the header */
if (width > state->maxwidth || height > state->maxheight)
return AVCERR_VIDEO_TOO_LARGE;
if (channels > state->maxchannels)
return AVCERR_AUDIO_TOO_LARGE;
/* write the basics to the new header */
dest[0] = metasize;
dest[1] = channels;
dest[2] = samples >> 8;
dest[3] = samples;
dest[4] = width >> 8;
dest[5] = width;
dest[6] = height >> 8;
dest[7] = height;
/* starting offsets */
dstoffs = 10 + 2 * channels;
/* copy the metadata first */
if (metasize > 0)
{
memcpy(dest + dstoffs, metastart, metasize);
dstoffs += metasize;
}
/* encode the audio channels */
if (channels > 0)
{
/* encode the audio */
err = encode_audio(state, channels, samples, audiostart, audioxor, dest + dstoffs, &dest[8]);
if (err != AVCERR_NONE)
return err;
/* advance the pointers past the data */
dstoffs += (dest[8] << 8) + dest[9];
for (chnum = 0; chnum < channels; chnum++)
dstoffs += (dest[10 + 2 * chnum] << 8) + dest[11 + 2 * chnum];
}
/* encode the video data */
if (width > 0 && height > 0)
{
UINT32 vidlength = 0;
/* encode the video */
err = encode_video(state, width, height, videostart, videostride, videoxor, dest + dstoffs, &vidlength);
if (err != AVCERR_NONE)
return err;
/* advance the pointers past the data */
dstoffs += vidlength;
}
/* set the total compression */
*complength = dstoffs;
return AVCERR_NONE;
} | /*-------------------------------------------------
avcomp_encode_data - encode a block of data
into a compressed data stream
-------------------------------------------------*/ | encode a block of data
into a compressed data stream | [
"encode",
"a",
"block",
"of",
"data",
"into",
"a",
"compressed",
"data",
"stream"
] | avcomp_error avcomp_encode_data(avcomp_state *state, const UINT8 *source, UINT8 *dest, UINT32 *complength)
{
const UINT8 *metastart, *videostart, *audiostart[MAX_CHANNELS];
UINT32 metasize, channels, samples, width, height;
UINT32 audioxor, videoxor, videostride;
avcomp_error err;
UINT32 dstoffs;
int chnum;
if (source != NULL)
{
if (source[0] != 'c' || source[1] != 'h' || source[2] != 'a' || source[3] != 'v')
return AVCERR_INVALID_DATA;
metasize = source[4];
channels = source[5];
samples = (source[6] << 8) + source[7];
width = (source[8] << 8) + source[9];
height = (source[10] << 8) + source[11];
source += 12;
metastart = source;
source += metasize;
for (chnum = 0; chnum < channels; chnum++)
{
audiostart[chnum] = source;
source += 2 * samples;
}
videostart = source;
audioxor = videoxor = 0;
videostride = 2 * width;
}
else
{
UINT16 betest = 0;
metastart = state->compress.metadata;
metasize = state->compress.metalength;
if ((metastart == NULL && metasize != 0) || (metastart != NULL && metasize == 0))
return AVCERR_INVALID_CONFIGURATION;
channels = state->compress.channels;
samples = state->compress.samples;
for (chnum = 0; chnum < channels; chnum++)
audiostart[chnum] = (const UINT8 *)state->compress.audio[chnum];
videostart = NULL;
videostride = width = height = 0;
if (state->compress.video != NULL)
{
videostart = (const UINT8 *)state->compress.video->base;
videostride = state->compress.video->rowpixels * 2;
width = state->compress.video->width;
height = state->compress.video->height;
}
*(UINT8 *)&betest = 1;
audioxor = videoxor = (betest == 1) ? 1 : 0;
}
if (width > state->maxwidth || height > state->maxheight)
return AVCERR_VIDEO_TOO_LARGE;
if (channels > state->maxchannels)
return AVCERR_AUDIO_TOO_LARGE;
dest[0] = metasize;
dest[1] = channels;
dest[2] = samples >> 8;
dest[3] = samples;
dest[4] = width >> 8;
dest[5] = width;
dest[6] = height >> 8;
dest[7] = height;
dstoffs = 10 + 2 * channels;
if (metasize > 0)
{
memcpy(dest + dstoffs, metastart, metasize);
dstoffs += metasize;
}
if (channels > 0)
{
err = encode_audio(state, channels, samples, audiostart, audioxor, dest + dstoffs, &dest[8]);
if (err != AVCERR_NONE)
return err;
dstoffs += (dest[8] << 8) + dest[9];
for (chnum = 0; chnum < channels; chnum++)
dstoffs += (dest[10 + 2 * chnum] << 8) + dest[11 + 2 * chnum];
}
if (width > 0 && height > 0)
{
UINT32 vidlength = 0;
err = encode_video(state, width, height, videostart, videostride, videoxor, dest + dstoffs, &vidlength);
if (err != AVCERR_NONE)
return err;
dstoffs += vidlength;
}
*complength = dstoffs;
return AVCERR_NONE;
} | [
"avcomp_error",
"avcomp_encode_data",
"(",
"avcomp_state",
"*",
"state",
",",
"const",
"UINT8",
"*",
"source",
",",
"UINT8",
"*",
"dest",
",",
"UINT32",
"*",
"complength",
")",
"{",
"const",
"UINT8",
"*",
"metastart",
",",
"*",
"videostart",
",",
"*",
"audiostart",
"[",
"MAX_CHANNELS",
"]",
";",
"UINT32",
"metasize",
",",
"channels",
",",
"samples",
",",
"width",
",",
"height",
";",
"UINT32",
"audioxor",
",",
"videoxor",
",",
"videostride",
";",
"avcomp_error",
"err",
";",
"UINT32",
"dstoffs",
";",
"int",
"chnum",
";",
"if",
"(",
"source",
"!=",
"NULL",
")",
"{",
"if",
"(",
"source",
"[",
"0",
"]",
"!=",
"'",
"'",
"||",
"source",
"[",
"1",
"]",
"!=",
"'",
"'",
"||",
"source",
"[",
"2",
"]",
"!=",
"'",
"'",
"||",
"source",
"[",
"3",
"]",
"!=",
"'",
"'",
")",
"return",
"AVCERR_INVALID_DATA",
";",
"metasize",
"=",
"source",
"[",
"4",
"]",
";",
"channels",
"=",
"source",
"[",
"5",
"]",
";",
"samples",
"=",
"(",
"source",
"[",
"6",
"]",
"<<",
"8",
")",
"+",
"source",
"[",
"7",
"]",
";",
"width",
"=",
"(",
"source",
"[",
"8",
"]",
"<<",
"8",
")",
"+",
"source",
"[",
"9",
"]",
";",
"height",
"=",
"(",
"source",
"[",
"10",
"]",
"<<",
"8",
")",
"+",
"source",
"[",
"11",
"]",
";",
"source",
"+=",
"12",
";",
"metastart",
"=",
"source",
";",
"source",
"+=",
"metasize",
";",
"for",
"(",
"chnum",
"=",
"0",
";",
"chnum",
"<",
"channels",
";",
"chnum",
"++",
")",
"{",
"audiostart",
"[",
"chnum",
"]",
"=",
"source",
";",
"source",
"+=",
"2",
"*",
"samples",
";",
"}",
"videostart",
"=",
"source",
";",
"audioxor",
"=",
"videoxor",
"=",
"0",
";",
"videostride",
"=",
"2",
"*",
"width",
";",
"}",
"else",
"{",
"UINT16",
"betest",
"=",
"0",
";",
"metastart",
"=",
"state",
"->",
"compress",
".",
"metadata",
";",
"metasize",
"=",
"state",
"->",
"compress",
".",
"metalength",
";",
"if",
"(",
"(",
"metastart",
"==",
"NULL",
"&&",
"metasize",
"!=",
"0",
")",
"||",
"(",
"metastart",
"!=",
"NULL",
"&&",
"metasize",
"==",
"0",
")",
")",
"return",
"AVCERR_INVALID_CONFIGURATION",
";",
"channels",
"=",
"state",
"->",
"compress",
".",
"channels",
";",
"samples",
"=",
"state",
"->",
"compress",
".",
"samples",
";",
"for",
"(",
"chnum",
"=",
"0",
";",
"chnum",
"<",
"channels",
";",
"chnum",
"++",
")",
"audiostart",
"[",
"chnum",
"]",
"=",
"(",
"const",
"UINT8",
"*",
")",
"state",
"->",
"compress",
".",
"audio",
"[",
"chnum",
"]",
";",
"videostart",
"=",
"NULL",
";",
"videostride",
"=",
"width",
"=",
"height",
"=",
"0",
";",
"if",
"(",
"state",
"->",
"compress",
".",
"video",
"!=",
"NULL",
")",
"{",
"videostart",
"=",
"(",
"const",
"UINT8",
"*",
")",
"state",
"->",
"compress",
".",
"video",
"->",
"base",
";",
"videostride",
"=",
"state",
"->",
"compress",
".",
"video",
"->",
"rowpixels",
"*",
"2",
";",
"width",
"=",
"state",
"->",
"compress",
".",
"video",
"->",
"width",
";",
"height",
"=",
"state",
"->",
"compress",
".",
"video",
"->",
"height",
";",
"}",
"*",
"(",
"UINT8",
"*",
")",
"&",
"betest",
"=",
"1",
";",
"audioxor",
"=",
"videoxor",
"=",
"(",
"betest",
"==",
"1",
")",
"?",
"1",
":",
"0",
";",
"}",
"if",
"(",
"width",
">",
"state",
"->",
"maxwidth",
"||",
"height",
">",
"state",
"->",
"maxheight",
")",
"return",
"AVCERR_VIDEO_TOO_LARGE",
";",
"if",
"(",
"channels",
">",
"state",
"->",
"maxchannels",
")",
"return",
"AVCERR_AUDIO_TOO_LARGE",
";",
"dest",
"[",
"0",
"]",
"=",
"metasize",
";",
"dest",
"[",
"1",
"]",
"=",
"channels",
";",
"dest",
"[",
"2",
"]",
"=",
"samples",
">>",
"8",
";",
"dest",
"[",
"3",
"]",
"=",
"samples",
";",
"dest",
"[",
"4",
"]",
"=",
"width",
">>",
"8",
";",
"dest",
"[",
"5",
"]",
"=",
"width",
";",
"dest",
"[",
"6",
"]",
"=",
"height",
">>",
"8",
";",
"dest",
"[",
"7",
"]",
"=",
"height",
";",
"dstoffs",
"=",
"10",
"+",
"2",
"*",
"channels",
";",
"if",
"(",
"metasize",
">",
"0",
")",
"{",
"memcpy",
"(",
"dest",
"+",
"dstoffs",
",",
"metastart",
",",
"metasize",
")",
";",
"dstoffs",
"+=",
"metasize",
";",
"}",
"if",
"(",
"channels",
">",
"0",
")",
"{",
"err",
"=",
"encode_audio",
"(",
"state",
",",
"channels",
",",
"samples",
",",
"audiostart",
",",
"audioxor",
",",
"dest",
"+",
"dstoffs",
",",
"&",
"dest",
"[",
"8",
"]",
")",
";",
"if",
"(",
"err",
"!=",
"AVCERR_NONE",
")",
"return",
"err",
";",
"dstoffs",
"+=",
"(",
"dest",
"[",
"8",
"]",
"<<",
"8",
")",
"+",
"dest",
"[",
"9",
"]",
";",
"for",
"(",
"chnum",
"=",
"0",
";",
"chnum",
"<",
"channels",
";",
"chnum",
"++",
")",
"dstoffs",
"+=",
"(",
"dest",
"[",
"10",
"+",
"2",
"*",
"chnum",
"]",
"<<",
"8",
")",
"+",
"dest",
"[",
"11",
"+",
"2",
"*",
"chnum",
"]",
";",
"}",
"if",
"(",
"width",
">",
"0",
"&&",
"height",
">",
"0",
")",
"{",
"UINT32",
"vidlength",
"=",
"0",
";",
"err",
"=",
"encode_video",
"(",
"state",
",",
"width",
",",
"height",
",",
"videostart",
",",
"videostride",
",",
"videoxor",
",",
"dest",
"+",
"dstoffs",
",",
"&",
"vidlength",
")",
";",
"if",
"(",
"err",
"!=",
"AVCERR_NONE",
")",
"return",
"err",
";",
"dstoffs",
"+=",
"vidlength",
";",
"}",
"*",
"complength",
"=",
"dstoffs",
";",
"return",
"AVCERR_NONE",
";",
"}"
] | avcomp_encode_data - encode a block of data
into a compressed data stream | [
"avcomp_encode_data",
"-",
"encode",
"a",
"block",
"of",
"data",
"into",
"a",
"compressed",
"data",
"stream"
] | [
"/* extract data from source if present */",
"/* validate the header */",
"/* extract info from the header */",
"/* determine the start of each piece of data */",
"/* data is assumed to be big-endian already */",
"/* otherwise, extract from the state */",
"/* extract metadata information */",
"/* extract audio information */",
"/* extract video information */",
"/* data is assumed to be native-endian */",
"/* validate the info from the header */",
"/* write the basics to the new header */",
"/* starting offsets */",
"/* copy the metadata first */",
"/* encode the audio channels */",
"/* encode the audio */",
"/* advance the pointers past the data */",
"/* encode the video data */",
"/* encode the video */",
"/* advance the pointers past the data */",
"/* set the total compression */"
] | [
{
"param": "state",
"type": "avcomp_state"
},
{
"param": "source",
"type": "UINT8"
},
{
"param": "dest",
"type": "UINT8"
},
{
"param": "complength",
"type": "UINT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "state",
"type": "avcomp_state",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "source",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dest",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "complength",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
cd4be1614b9fcbb56b62f8ddfbf2292d77865e7c | lofunz/mieme | Reloaded/trunk/src/lib/util/avcomp.c | [
"Unlicense"
] | C | avcomp_decode_data | avcomp_error | avcomp_error avcomp_decode_data(avcomp_state *state, const UINT8 *source, UINT32 complength, UINT8 *dest)
{
UINT8 *metastart, *videostart, *audiostart[MAX_CHANNELS];
UINT32 metasize, channels, samples, width, height;
UINT32 audioxor, videoxor, videostride;
UINT32 srcoffs, totalsize;
avcomp_error err;
int chnum;
/* extract info from the header */
if (complength < 8)
return AVCERR_INVALID_DATA;
metasize = source[0];
channels = source[1];
samples = (source[2] << 8) + source[3];
width = (source[4] << 8) + source[5];
height = (source[6] << 8) + source[7];
/* validate the info from the header */
if (width > state->maxwidth || height > state->maxheight)
return AVCERR_VIDEO_TOO_LARGE;
if (channels > state->maxchannels)
return AVCERR_AUDIO_TOO_LARGE;
/* validate that the sizes make sense */
if (complength < 10 + 2 * channels)
return AVCERR_INVALID_DATA;
totalsize = 10 + 2 * channels;
totalsize += (source[8] << 8) | source[9];
for (chnum = 0; chnum < channels; chnum++)
totalsize += (source[10 + 2 * chnum] << 8) | source[11 + 2 * chnum];
if (totalsize >= complength)
return AVCERR_INVALID_DATA;
/* starting offsets */
srcoffs = 10 + 2 * channels;
/* if we are decoding raw, set up the output parameters */
if (dest != NULL)
{
/* create a header */
dest[0] = 'c';
dest[1] = 'h';
dest[2] = 'a';
dest[3] = 'v';
dest[4] = metasize;
dest[5] = channels;
dest[6] = samples >> 8;
dest[7] = samples;
dest[8] = width >> 8;
dest[9] = width;
dest[10] = height >> 8;
dest[11] = height;
/* determine the start of each piece of data */
dest += 12;
metastart = dest;
dest += metasize;
for (chnum = 0; chnum < channels; chnum++)
{
audiostart[chnum] = dest;
dest += 2 * samples;
}
videostart = dest;
/* data is assumed to be big-endian already */
audioxor = videoxor = 0;
videostride = 2 * width;
}
/* otherwise, extract from the state */
else
{
UINT16 betest = 0;
/* determine the start of each piece of data */
metastart = state->decompress.metadata;
for (chnum = 0; chnum < channels; chnum++)
audiostart[chnum] = (UINT8 *)state->decompress.audio[chnum];
videostart = (state->decompress.video != NULL) ? (UINT8 *)state->decompress.video->base : NULL;
videostride = (state->decompress.video != NULL) ? state->decompress.video->rowpixels * 2 : 0;
/* data is assumed to be native-endian */
*(UINT8 *)&betest = 1;
audioxor = videoxor = (betest == 1) ? 1 : 0;
/* verify against sizes */
if (state->decompress.video != NULL && (state->decompress.video->width < width || state->decompress.video->height < height))
return AVCERR_VIDEO_TOO_LARGE;
for (chnum = 0; chnum < channels; chnum++)
if (state->decompress.audio[chnum] != NULL && state->decompress.maxsamples < samples)
return AVCERR_AUDIO_TOO_LARGE;
if (state->decompress.metadata != NULL && state->decompress.maxmetalength < metasize)
return AVCERR_METADATA_TOO_LARGE;
/* set the output values */
if (state->decompress.actsamples != NULL)
*state->decompress.actsamples = samples;
if (state->decompress.actmetalength != NULL)
*state->decompress.actmetalength = metasize;
}
/* copy the metadata first */
if (metasize > 0)
{
if (metastart != NULL)
memcpy(metastart, source + srcoffs, metasize);
srcoffs += metasize;
}
/* decode the audio channels */
if (channels > 0)
{
/* decode the audio */
err = decode_audio(state, channels, samples, source + srcoffs, audiostart, audioxor, &source[8]);
if (err != AVCERR_NONE)
return err;
/* advance the pointers past the data */
srcoffs += (source[8] << 8) + source[9];
for (chnum = 0; chnum < channels; chnum++)
srcoffs += (source[10 + 2 * chnum] << 8) + source[11 + 2 * chnum];
}
/* decode the video data */
if (width > 0 && height > 0 && videostart != NULL)
{
/* decode the video */
err = decode_video(state, width, height, source + srcoffs, complength - srcoffs, videostart, videostride, videoxor);
if (err != AVCERR_NONE)
return err;
}
return AVCERR_NONE;
} | /*-------------------------------------------------
avcomp_decode_data - decode both
audio and video from a raw data stream
-------------------------------------------------*/ | decode both
audio and video from a raw data stream | [
"decode",
"both",
"audio",
"and",
"video",
"from",
"a",
"raw",
"data",
"stream"
] | avcomp_error avcomp_decode_data(avcomp_state *state, const UINT8 *source, UINT32 complength, UINT8 *dest)
{
UINT8 *metastart, *videostart, *audiostart[MAX_CHANNELS];
UINT32 metasize, channels, samples, width, height;
UINT32 audioxor, videoxor, videostride;
UINT32 srcoffs, totalsize;
avcomp_error err;
int chnum;
if (complength < 8)
return AVCERR_INVALID_DATA;
metasize = source[0];
channels = source[1];
samples = (source[2] << 8) + source[3];
width = (source[4] << 8) + source[5];
height = (source[6] << 8) + source[7];
if (width > state->maxwidth || height > state->maxheight)
return AVCERR_VIDEO_TOO_LARGE;
if (channels > state->maxchannels)
return AVCERR_AUDIO_TOO_LARGE;
if (complength < 10 + 2 * channels)
return AVCERR_INVALID_DATA;
totalsize = 10 + 2 * channels;
totalsize += (source[8] << 8) | source[9];
for (chnum = 0; chnum < channels; chnum++)
totalsize += (source[10 + 2 * chnum] << 8) | source[11 + 2 * chnum];
if (totalsize >= complength)
return AVCERR_INVALID_DATA;
srcoffs = 10 + 2 * channels;
if (dest != NULL)
{
dest[0] = 'c';
dest[1] = 'h';
dest[2] = 'a';
dest[3] = 'v';
dest[4] = metasize;
dest[5] = channels;
dest[6] = samples >> 8;
dest[7] = samples;
dest[8] = width >> 8;
dest[9] = width;
dest[10] = height >> 8;
dest[11] = height;
dest += 12;
metastart = dest;
dest += metasize;
for (chnum = 0; chnum < channels; chnum++)
{
audiostart[chnum] = dest;
dest += 2 * samples;
}
videostart = dest;
audioxor = videoxor = 0;
videostride = 2 * width;
}
else
{
UINT16 betest = 0;
metastart = state->decompress.metadata;
for (chnum = 0; chnum < channels; chnum++)
audiostart[chnum] = (UINT8 *)state->decompress.audio[chnum];
videostart = (state->decompress.video != NULL) ? (UINT8 *)state->decompress.video->base : NULL;
videostride = (state->decompress.video != NULL) ? state->decompress.video->rowpixels * 2 : 0;
*(UINT8 *)&betest = 1;
audioxor = videoxor = (betest == 1) ? 1 : 0;
if (state->decompress.video != NULL && (state->decompress.video->width < width || state->decompress.video->height < height))
return AVCERR_VIDEO_TOO_LARGE;
for (chnum = 0; chnum < channels; chnum++)
if (state->decompress.audio[chnum] != NULL && state->decompress.maxsamples < samples)
return AVCERR_AUDIO_TOO_LARGE;
if (state->decompress.metadata != NULL && state->decompress.maxmetalength < metasize)
return AVCERR_METADATA_TOO_LARGE;
if (state->decompress.actsamples != NULL)
*state->decompress.actsamples = samples;
if (state->decompress.actmetalength != NULL)
*state->decompress.actmetalength = metasize;
}
if (metasize > 0)
{
if (metastart != NULL)
memcpy(metastart, source + srcoffs, metasize);
srcoffs += metasize;
}
if (channels > 0)
{
err = decode_audio(state, channels, samples, source + srcoffs, audiostart, audioxor, &source[8]);
if (err != AVCERR_NONE)
return err;
srcoffs += (source[8] << 8) + source[9];
for (chnum = 0; chnum < channels; chnum++)
srcoffs += (source[10 + 2 * chnum] << 8) + source[11 + 2 * chnum];
}
if (width > 0 && height > 0 && videostart != NULL)
{
err = decode_video(state, width, height, source + srcoffs, complength - srcoffs, videostart, videostride, videoxor);
if (err != AVCERR_NONE)
return err;
}
return AVCERR_NONE;
} | [
"avcomp_error",
"avcomp_decode_data",
"(",
"avcomp_state",
"*",
"state",
",",
"const",
"UINT8",
"*",
"source",
",",
"UINT32",
"complength",
",",
"UINT8",
"*",
"dest",
")",
"{",
"UINT8",
"*",
"metastart",
",",
"*",
"videostart",
",",
"*",
"audiostart",
"[",
"MAX_CHANNELS",
"]",
";",
"UINT32",
"metasize",
",",
"channels",
",",
"samples",
",",
"width",
",",
"height",
";",
"UINT32",
"audioxor",
",",
"videoxor",
",",
"videostride",
";",
"UINT32",
"srcoffs",
",",
"totalsize",
";",
"avcomp_error",
"err",
";",
"int",
"chnum",
";",
"if",
"(",
"complength",
"<",
"8",
")",
"return",
"AVCERR_INVALID_DATA",
";",
"metasize",
"=",
"source",
"[",
"0",
"]",
";",
"channels",
"=",
"source",
"[",
"1",
"]",
";",
"samples",
"=",
"(",
"source",
"[",
"2",
"]",
"<<",
"8",
")",
"+",
"source",
"[",
"3",
"]",
";",
"width",
"=",
"(",
"source",
"[",
"4",
"]",
"<<",
"8",
")",
"+",
"source",
"[",
"5",
"]",
";",
"height",
"=",
"(",
"source",
"[",
"6",
"]",
"<<",
"8",
")",
"+",
"source",
"[",
"7",
"]",
";",
"if",
"(",
"width",
">",
"state",
"->",
"maxwidth",
"||",
"height",
">",
"state",
"->",
"maxheight",
")",
"return",
"AVCERR_VIDEO_TOO_LARGE",
";",
"if",
"(",
"channels",
">",
"state",
"->",
"maxchannels",
")",
"return",
"AVCERR_AUDIO_TOO_LARGE",
";",
"if",
"(",
"complength",
"<",
"10",
"+",
"2",
"*",
"channels",
")",
"return",
"AVCERR_INVALID_DATA",
";",
"totalsize",
"=",
"10",
"+",
"2",
"*",
"channels",
";",
"totalsize",
"+=",
"(",
"source",
"[",
"8",
"]",
"<<",
"8",
")",
"|",
"source",
"[",
"9",
"]",
";",
"for",
"(",
"chnum",
"=",
"0",
";",
"chnum",
"<",
"channels",
";",
"chnum",
"++",
")",
"totalsize",
"+=",
"(",
"source",
"[",
"10",
"+",
"2",
"*",
"chnum",
"]",
"<<",
"8",
")",
"|",
"source",
"[",
"11",
"+",
"2",
"*",
"chnum",
"]",
";",
"if",
"(",
"totalsize",
">=",
"complength",
")",
"return",
"AVCERR_INVALID_DATA",
";",
"srcoffs",
"=",
"10",
"+",
"2",
"*",
"channels",
";",
"if",
"(",
"dest",
"!=",
"NULL",
")",
"{",
"dest",
"[",
"0",
"]",
"=",
"'",
"'",
";",
"dest",
"[",
"1",
"]",
"=",
"'",
"'",
";",
"dest",
"[",
"2",
"]",
"=",
"'",
"'",
";",
"dest",
"[",
"3",
"]",
"=",
"'",
"'",
";",
"dest",
"[",
"4",
"]",
"=",
"metasize",
";",
"dest",
"[",
"5",
"]",
"=",
"channels",
";",
"dest",
"[",
"6",
"]",
"=",
"samples",
">>",
"8",
";",
"dest",
"[",
"7",
"]",
"=",
"samples",
";",
"dest",
"[",
"8",
"]",
"=",
"width",
">>",
"8",
";",
"dest",
"[",
"9",
"]",
"=",
"width",
";",
"dest",
"[",
"10",
"]",
"=",
"height",
">>",
"8",
";",
"dest",
"[",
"11",
"]",
"=",
"height",
";",
"dest",
"+=",
"12",
";",
"metastart",
"=",
"dest",
";",
"dest",
"+=",
"metasize",
";",
"for",
"(",
"chnum",
"=",
"0",
";",
"chnum",
"<",
"channels",
";",
"chnum",
"++",
")",
"{",
"audiostart",
"[",
"chnum",
"]",
"=",
"dest",
";",
"dest",
"+=",
"2",
"*",
"samples",
";",
"}",
"videostart",
"=",
"dest",
";",
"audioxor",
"=",
"videoxor",
"=",
"0",
";",
"videostride",
"=",
"2",
"*",
"width",
";",
"}",
"else",
"{",
"UINT16",
"betest",
"=",
"0",
";",
"metastart",
"=",
"state",
"->",
"decompress",
".",
"metadata",
";",
"for",
"(",
"chnum",
"=",
"0",
";",
"chnum",
"<",
"channels",
";",
"chnum",
"++",
")",
"audiostart",
"[",
"chnum",
"]",
"=",
"(",
"UINT8",
"*",
")",
"state",
"->",
"decompress",
".",
"audio",
"[",
"chnum",
"]",
";",
"videostart",
"=",
"(",
"state",
"->",
"decompress",
".",
"video",
"!=",
"NULL",
")",
"?",
"(",
"UINT8",
"*",
")",
"state",
"->",
"decompress",
".",
"video",
"->",
"base",
":",
"NULL",
";",
"videostride",
"=",
"(",
"state",
"->",
"decompress",
".",
"video",
"!=",
"NULL",
")",
"?",
"state",
"->",
"decompress",
".",
"video",
"->",
"rowpixels",
"*",
"2",
":",
"0",
";",
"*",
"(",
"UINT8",
"*",
")",
"&",
"betest",
"=",
"1",
";",
"audioxor",
"=",
"videoxor",
"=",
"(",
"betest",
"==",
"1",
")",
"?",
"1",
":",
"0",
";",
"if",
"(",
"state",
"->",
"decompress",
".",
"video",
"!=",
"NULL",
"&&",
"(",
"state",
"->",
"decompress",
".",
"video",
"->",
"width",
"<",
"width",
"||",
"state",
"->",
"decompress",
".",
"video",
"->",
"height",
"<",
"height",
")",
")",
"return",
"AVCERR_VIDEO_TOO_LARGE",
";",
"for",
"(",
"chnum",
"=",
"0",
";",
"chnum",
"<",
"channels",
";",
"chnum",
"++",
")",
"if",
"(",
"state",
"->",
"decompress",
".",
"audio",
"[",
"chnum",
"]",
"!=",
"NULL",
"&&",
"state",
"->",
"decompress",
".",
"maxsamples",
"<",
"samples",
")",
"return",
"AVCERR_AUDIO_TOO_LARGE",
";",
"if",
"(",
"state",
"->",
"decompress",
".",
"metadata",
"!=",
"NULL",
"&&",
"state",
"->",
"decompress",
".",
"maxmetalength",
"<",
"metasize",
")",
"return",
"AVCERR_METADATA_TOO_LARGE",
";",
"if",
"(",
"state",
"->",
"decompress",
".",
"actsamples",
"!=",
"NULL",
")",
"*",
"state",
"->",
"decompress",
".",
"actsamples",
"=",
"samples",
";",
"if",
"(",
"state",
"->",
"decompress",
".",
"actmetalength",
"!=",
"NULL",
")",
"*",
"state",
"->",
"decompress",
".",
"actmetalength",
"=",
"metasize",
";",
"}",
"if",
"(",
"metasize",
">",
"0",
")",
"{",
"if",
"(",
"metastart",
"!=",
"NULL",
")",
"memcpy",
"(",
"metastart",
",",
"source",
"+",
"srcoffs",
",",
"metasize",
")",
";",
"srcoffs",
"+=",
"metasize",
";",
"}",
"if",
"(",
"channels",
">",
"0",
")",
"{",
"err",
"=",
"decode_audio",
"(",
"state",
",",
"channels",
",",
"samples",
",",
"source",
"+",
"srcoffs",
",",
"audiostart",
",",
"audioxor",
",",
"&",
"source",
"[",
"8",
"]",
")",
";",
"if",
"(",
"err",
"!=",
"AVCERR_NONE",
")",
"return",
"err",
";",
"srcoffs",
"+=",
"(",
"source",
"[",
"8",
"]",
"<<",
"8",
")",
"+",
"source",
"[",
"9",
"]",
";",
"for",
"(",
"chnum",
"=",
"0",
";",
"chnum",
"<",
"channels",
";",
"chnum",
"++",
")",
"srcoffs",
"+=",
"(",
"source",
"[",
"10",
"+",
"2",
"*",
"chnum",
"]",
"<<",
"8",
")",
"+",
"source",
"[",
"11",
"+",
"2",
"*",
"chnum",
"]",
";",
"}",
"if",
"(",
"width",
">",
"0",
"&&",
"height",
">",
"0",
"&&",
"videostart",
"!=",
"NULL",
")",
"{",
"err",
"=",
"decode_video",
"(",
"state",
",",
"width",
",",
"height",
",",
"source",
"+",
"srcoffs",
",",
"complength",
"-",
"srcoffs",
",",
"videostart",
",",
"videostride",
",",
"videoxor",
")",
";",
"if",
"(",
"err",
"!=",
"AVCERR_NONE",
")",
"return",
"err",
";",
"}",
"return",
"AVCERR_NONE",
";",
"}"
] | avcomp_decode_data - decode both
audio and video from a raw data stream | [
"avcomp_decode_data",
"-",
"decode",
"both",
"audio",
"and",
"video",
"from",
"a",
"raw",
"data",
"stream"
] | [
"/* extract info from the header */",
"/* validate the info from the header */",
"/* validate that the sizes make sense */",
"/* starting offsets */",
"/* if we are decoding raw, set up the output parameters */",
"/* create a header */",
"/* determine the start of each piece of data */",
"/* data is assumed to be big-endian already */",
"/* otherwise, extract from the state */",
"/* determine the start of each piece of data */",
"/* data is assumed to be native-endian */",
"/* verify against sizes */",
"/* set the output values */",
"/* copy the metadata first */",
"/* decode the audio channels */",
"/* decode the audio */",
"/* advance the pointers past the data */",
"/* decode the video data */",
"/* decode the video */"
] | [
{
"param": "state",
"type": "avcomp_state"
},
{
"param": "source",
"type": "UINT8"
},
{
"param": "complength",
"type": "UINT32"
},
{
"param": "dest",
"type": "UINT8"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "state",
"type": "avcomp_state",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "source",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "complength",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dest",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
cd4be1614b9fcbb56b62f8ddfbf2292d77865e7c | lofunz/mieme | Reloaded/trunk/src/lib/util/avcomp.c | [
"Unlicense"
] | C | encode_audio | avcomp_error | static avcomp_error encode_audio(avcomp_state *state, int channels, int samples, const UINT8 **source, int sourcexor, UINT8 *dest, UINT8 *sizes)
{
UINT32 size, huffsize, totalsize;
huffman_context *contexts[2];
huffman_error hufferr;
UINT8 *output = dest;
int chnum, sampnum;
UINT8 *deltabuf;
/* iterate over channels to compute deltas */
deltabuf = state->audiodata;
for (chnum = 0; chnum < channels; chnum++)
{
const UINT8 *srcdata = source[chnum];
INT16 prevsample = 0;
/* extract audio data into hi and lo deltas stored in big-endian order */
for (sampnum = 0; sampnum < samples; sampnum++)
{
INT16 newsample = (srcdata[0 ^ sourcexor] << 8) | srcdata[1 ^ sourcexor];
INT16 delta = newsample - prevsample;
prevsample = newsample;
*deltabuf++ = delta >> 8;
*deltabuf++ = delta;
srcdata += 2;
}
}
/* compute the trees */
contexts[0] = state->audiohicontext;
contexts[1] = state->audiolocontext;
hufferr = huffman_compute_tree_interleaved(2, contexts, state->audiodata, samples * 2, channels, samples * 2, 0);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
/* export them to the output */
hufferr = huffman_export_tree(state->audiohicontext, output, 256, &size);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
output += size;
hufferr = huffman_export_tree(state->audiolocontext, output, 256, &size);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
output += size;
/* note the size of the two trees */
huffsize = output - dest;
sizes[0] = huffsize >> 8;
sizes[1] = huffsize;
/* iterate over channels */
totalsize = huffsize;
for (chnum = 0; chnum < channels; chnum++)
{
const UINT8 *input = state->audiodata + chnum * samples * 2;
/* encode the data */
hufferr = huffman_encode_data_interleaved(2, contexts, input, samples * 2, 1, 0, 0, output, samples * 2, &size);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
output += size;
/* store the size of this stream */
totalsize += size;
if (totalsize >= channels * samples * 2)
break;
sizes[chnum * 2 + 2] = size >> 8;
sizes[chnum * 2 + 3] = size;
}
/* if we ran out of room, throw it all away and just store raw */
if (chnum < channels)
{
memcpy(dest, state->audiodata, channels * samples * 2);
size = samples * 2;
sizes[0] = sizes[1] = 0;
for (chnum = 0; chnum < channels; chnum++)
{
sizes[chnum * 2 + 2] = size >> 8;
sizes[chnum * 2 + 3] = size;
}
}
return AVCERR_NONE;
} | /*-------------------------------------------------
encode_audio - encode raw audio data
to the destination
-------------------------------------------------*/ | encode raw audio data
to the destination | [
"encode",
"raw",
"audio",
"data",
"to",
"the",
"destination"
] | static avcomp_error encode_audio(avcomp_state *state, int channels, int samples, const UINT8 **source, int sourcexor, UINT8 *dest, UINT8 *sizes)
{
UINT32 size, huffsize, totalsize;
huffman_context *contexts[2];
huffman_error hufferr;
UINT8 *output = dest;
int chnum, sampnum;
UINT8 *deltabuf;
deltabuf = state->audiodata;
for (chnum = 0; chnum < channels; chnum++)
{
const UINT8 *srcdata = source[chnum];
INT16 prevsample = 0;
for (sampnum = 0; sampnum < samples; sampnum++)
{
INT16 newsample = (srcdata[0 ^ sourcexor] << 8) | srcdata[1 ^ sourcexor];
INT16 delta = newsample - prevsample;
prevsample = newsample;
*deltabuf++ = delta >> 8;
*deltabuf++ = delta;
srcdata += 2;
}
}
contexts[0] = state->audiohicontext;
contexts[1] = state->audiolocontext;
hufferr = huffman_compute_tree_interleaved(2, contexts, state->audiodata, samples * 2, channels, samples * 2, 0);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
hufferr = huffman_export_tree(state->audiohicontext, output, 256, &size);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
output += size;
hufferr = huffman_export_tree(state->audiolocontext, output, 256, &size);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
output += size;
huffsize = output - dest;
sizes[0] = huffsize >> 8;
sizes[1] = huffsize;
totalsize = huffsize;
for (chnum = 0; chnum < channels; chnum++)
{
const UINT8 *input = state->audiodata + chnum * samples * 2;
hufferr = huffman_encode_data_interleaved(2, contexts, input, samples * 2, 1, 0, 0, output, samples * 2, &size);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
output += size;
totalsize += size;
if (totalsize >= channels * samples * 2)
break;
sizes[chnum * 2 + 2] = size >> 8;
sizes[chnum * 2 + 3] = size;
}
if (chnum < channels)
{
memcpy(dest, state->audiodata, channels * samples * 2);
size = samples * 2;
sizes[0] = sizes[1] = 0;
for (chnum = 0; chnum < channels; chnum++)
{
sizes[chnum * 2 + 2] = size >> 8;
sizes[chnum * 2 + 3] = size;
}
}
return AVCERR_NONE;
} | [
"static",
"avcomp_error",
"encode_audio",
"(",
"avcomp_state",
"*",
"state",
",",
"int",
"channels",
",",
"int",
"samples",
",",
"const",
"UINT8",
"*",
"*",
"source",
",",
"int",
"sourcexor",
",",
"UINT8",
"*",
"dest",
",",
"UINT8",
"*",
"sizes",
")",
"{",
"UINT32",
"size",
",",
"huffsize",
",",
"totalsize",
";",
"huffman_context",
"*",
"contexts",
"[",
"2",
"]",
";",
"huffman_error",
"hufferr",
";",
"UINT8",
"*",
"output",
"=",
"dest",
";",
"int",
"chnum",
",",
"sampnum",
";",
"UINT8",
"*",
"deltabuf",
";",
"deltabuf",
"=",
"state",
"->",
"audiodata",
";",
"for",
"(",
"chnum",
"=",
"0",
";",
"chnum",
"<",
"channels",
";",
"chnum",
"++",
")",
"{",
"const",
"UINT8",
"*",
"srcdata",
"=",
"source",
"[",
"chnum",
"]",
";",
"INT16",
"prevsample",
"=",
"0",
";",
"for",
"(",
"sampnum",
"=",
"0",
";",
"sampnum",
"<",
"samples",
";",
"sampnum",
"++",
")",
"{",
"INT16",
"newsample",
"=",
"(",
"srcdata",
"[",
"0",
"^",
"sourcexor",
"]",
"<<",
"8",
")",
"|",
"srcdata",
"[",
"1",
"^",
"sourcexor",
"]",
";",
"INT16",
"delta",
"=",
"newsample",
"-",
"prevsample",
";",
"prevsample",
"=",
"newsample",
";",
"*",
"deltabuf",
"++",
"=",
"delta",
">>",
"8",
";",
"*",
"deltabuf",
"++",
"=",
"delta",
";",
"srcdata",
"+=",
"2",
";",
"}",
"}",
"contexts",
"[",
"0",
"]",
"=",
"state",
"->",
"audiohicontext",
";",
"contexts",
"[",
"1",
"]",
"=",
"state",
"->",
"audiolocontext",
";",
"hufferr",
"=",
"huffman_compute_tree_interleaved",
"(",
"2",
",",
"contexts",
",",
"state",
"->",
"audiodata",
",",
"samples",
"*",
"2",
",",
"channels",
",",
"samples",
"*",
"2",
",",
"0",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_COMPRESSION_ERROR",
";",
"hufferr",
"=",
"huffman_export_tree",
"(",
"state",
"->",
"audiohicontext",
",",
"output",
",",
"256",
",",
"&",
"size",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_COMPRESSION_ERROR",
";",
"output",
"+=",
"size",
";",
"hufferr",
"=",
"huffman_export_tree",
"(",
"state",
"->",
"audiolocontext",
",",
"output",
",",
"256",
",",
"&",
"size",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_COMPRESSION_ERROR",
";",
"output",
"+=",
"size",
";",
"huffsize",
"=",
"output",
"-",
"dest",
";",
"sizes",
"[",
"0",
"]",
"=",
"huffsize",
">>",
"8",
";",
"sizes",
"[",
"1",
"]",
"=",
"huffsize",
";",
"totalsize",
"=",
"huffsize",
";",
"for",
"(",
"chnum",
"=",
"0",
";",
"chnum",
"<",
"channels",
";",
"chnum",
"++",
")",
"{",
"const",
"UINT8",
"*",
"input",
"=",
"state",
"->",
"audiodata",
"+",
"chnum",
"*",
"samples",
"*",
"2",
";",
"hufferr",
"=",
"huffman_encode_data_interleaved",
"(",
"2",
",",
"contexts",
",",
"input",
",",
"samples",
"*",
"2",
",",
"1",
",",
"0",
",",
"0",
",",
"output",
",",
"samples",
"*",
"2",
",",
"&",
"size",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_COMPRESSION_ERROR",
";",
"output",
"+=",
"size",
";",
"totalsize",
"+=",
"size",
";",
"if",
"(",
"totalsize",
">=",
"channels",
"*",
"samples",
"*",
"2",
")",
"break",
";",
"sizes",
"[",
"chnum",
"*",
"2",
"+",
"2",
"]",
"=",
"size",
">>",
"8",
";",
"sizes",
"[",
"chnum",
"*",
"2",
"+",
"3",
"]",
"=",
"size",
";",
"}",
"if",
"(",
"chnum",
"<",
"channels",
")",
"{",
"memcpy",
"(",
"dest",
",",
"state",
"->",
"audiodata",
",",
"channels",
"*",
"samples",
"*",
"2",
")",
";",
"size",
"=",
"samples",
"*",
"2",
";",
"sizes",
"[",
"0",
"]",
"=",
"sizes",
"[",
"1",
"]",
"=",
"0",
";",
"for",
"(",
"chnum",
"=",
"0",
";",
"chnum",
"<",
"channels",
";",
"chnum",
"++",
")",
"{",
"sizes",
"[",
"chnum",
"*",
"2",
"+",
"2",
"]",
"=",
"size",
">>",
"8",
";",
"sizes",
"[",
"chnum",
"*",
"2",
"+",
"3",
"]",
"=",
"size",
";",
"}",
"}",
"return",
"AVCERR_NONE",
";",
"}"
] | encode_audio - encode raw audio data
to the destination | [
"encode_audio",
"-",
"encode",
"raw",
"audio",
"data",
"to",
"the",
"destination"
] | [
"/* iterate over channels to compute deltas */",
"/* extract audio data into hi and lo deltas stored in big-endian order */",
"/* compute the trees */",
"/* export them to the output */",
"/* note the size of the two trees */",
"/* iterate over channels */",
"/* encode the data */",
"/* store the size of this stream */",
"/* if we ran out of room, throw it all away and just store raw */"
] | [
{
"param": "state",
"type": "avcomp_state"
},
{
"param": "channels",
"type": "int"
},
{
"param": "samples",
"type": "int"
},
{
"param": "source",
"type": "UINT8"
},
{
"param": "sourcexor",
"type": "int"
},
{
"param": "dest",
"type": "UINT8"
},
{
"param": "sizes",
"type": "UINT8"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "state",
"type": "avcomp_state",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "channels",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "samples",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "source",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "sourcexor",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dest",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "sizes",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
cd4be1614b9fcbb56b62f8ddfbf2292d77865e7c | lofunz/mieme | Reloaded/trunk/src/lib/util/avcomp.c | [
"Unlicense"
] | C | encode_video | avcomp_error | static avcomp_error encode_video(avcomp_state *state, int width, int height, const UINT8 *source, UINT32 sstride, UINT32 sxor, UINT8 *dest, UINT32 *complength)
{
/* only lossless supported at this time */
return encode_video_lossless(state, width, height, source, sstride, sxor, dest, complength);
} | /*-------------------------------------------------
encode_video - encode raw video data
to the destination
-------------------------------------------------*/ | encode raw video data
to the destination | [
"encode",
"raw",
"video",
"data",
"to",
"the",
"destination"
] | static avcomp_error encode_video(avcomp_state *state, int width, int height, const UINT8 *source, UINT32 sstride, UINT32 sxor, UINT8 *dest, UINT32 *complength)
{
return encode_video_lossless(state, width, height, source, sstride, sxor, dest, complength);
} | [
"static",
"avcomp_error",
"encode_video",
"(",
"avcomp_state",
"*",
"state",
",",
"int",
"width",
",",
"int",
"height",
",",
"const",
"UINT8",
"*",
"source",
",",
"UINT32",
"sstride",
",",
"UINT32",
"sxor",
",",
"UINT8",
"*",
"dest",
",",
"UINT32",
"*",
"complength",
")",
"{",
"return",
"encode_video_lossless",
"(",
"state",
",",
"width",
",",
"height",
",",
"source",
",",
"sstride",
",",
"sxor",
",",
"dest",
",",
"complength",
")",
";",
"}"
] | encode_video - encode raw video data
to the destination | [
"encode_video",
"-",
"encode",
"raw",
"video",
"data",
"to",
"the",
"destination"
] | [
"/* only lossless supported at this time */"
] | [
{
"param": "state",
"type": "avcomp_state"
},
{
"param": "width",
"type": "int"
},
{
"param": "height",
"type": "int"
},
{
"param": "source",
"type": "UINT8"
},
{
"param": "sstride",
"type": "UINT32"
},
{
"param": "sxor",
"type": "UINT32"
},
{
"param": "dest",
"type": "UINT8"
},
{
"param": "complength",
"type": "UINT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "state",
"type": "avcomp_state",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "width",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "height",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "source",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "sstride",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "sxor",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dest",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "complength",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
cd4be1614b9fcbb56b62f8ddfbf2292d77865e7c | lofunz/mieme | Reloaded/trunk/src/lib/util/avcomp.c | [
"Unlicense"
] | C | encode_video_lossless | avcomp_error | static avcomp_error encode_video_lossless(avcomp_state *state, int width, int height, const UINT8 *source, UINT32 sstride, UINT32 sxor, UINT8 *dest, UINT32 *complength)
{
UINT32 srcbytes = width * height * 2;
huffman_context *contexts[4];
huffman_error hufferr;
UINT32 outbytes;
UINT8 *output;
/* set up the output; first byte is 0x80 to indicate lossless encoding */
output = dest;
*output++ = 0x80;
/* now encode to the destination using two trees, one for the Y and one for the Cr/Cb */
contexts[0] = state->ycontext;
contexts[1] = state->cbcontext;
contexts[2] = state->ycontext;
contexts[3] = state->crcontext;
/* compute the histograms for the data */
hufferr = huffman_deltarle_compute_tree_interleaved(4, contexts, source, width * 2, height, sstride, sxor);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
/* export the trees to the data stream */
hufferr = huffman_deltarle_export_tree(state->ycontext, output, 256, &outbytes);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
output += outbytes;
hufferr = huffman_deltarle_export_tree(state->cbcontext, output, 256, &outbytes);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
output += outbytes;
hufferr = huffman_deltarle_export_tree(state->crcontext, output, 256, &outbytes);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
output += outbytes;
/* encode the data using the trees */
hufferr = huffman_deltarle_encode_data_interleaved(4, contexts, source, width * 2, height, sstride, sxor, output, srcbytes, &outbytes);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
output += outbytes;
/* set the final length */
*complength = output - dest;
return AVCERR_NONE;
} | /*-------------------------------------------------
encode_video_lossless - do a lossless video
encoding using deltas and huffman encoding
-------------------------------------------------*/ | do a lossless video
encoding using deltas and huffman encoding | [
"do",
"a",
"lossless",
"video",
"encoding",
"using",
"deltas",
"and",
"huffman",
"encoding"
] | static avcomp_error encode_video_lossless(avcomp_state *state, int width, int height, const UINT8 *source, UINT32 sstride, UINT32 sxor, UINT8 *dest, UINT32 *complength)
{
UINT32 srcbytes = width * height * 2;
huffman_context *contexts[4];
huffman_error hufferr;
UINT32 outbytes;
UINT8 *output;
output = dest;
*output++ = 0x80;
contexts[0] = state->ycontext;
contexts[1] = state->cbcontext;
contexts[2] = state->ycontext;
contexts[3] = state->crcontext;
hufferr = huffman_deltarle_compute_tree_interleaved(4, contexts, source, width * 2, height, sstride, sxor);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
hufferr = huffman_deltarle_export_tree(state->ycontext, output, 256, &outbytes);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
output += outbytes;
hufferr = huffman_deltarle_export_tree(state->cbcontext, output, 256, &outbytes);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
output += outbytes;
hufferr = huffman_deltarle_export_tree(state->crcontext, output, 256, &outbytes);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
output += outbytes;
hufferr = huffman_deltarle_encode_data_interleaved(4, contexts, source, width * 2, height, sstride, sxor, output, srcbytes, &outbytes);
if (hufferr != HUFFERR_NONE)
return AVCERR_COMPRESSION_ERROR;
output += outbytes;
*complength = output - dest;
return AVCERR_NONE;
} | [
"static",
"avcomp_error",
"encode_video_lossless",
"(",
"avcomp_state",
"*",
"state",
",",
"int",
"width",
",",
"int",
"height",
",",
"const",
"UINT8",
"*",
"source",
",",
"UINT32",
"sstride",
",",
"UINT32",
"sxor",
",",
"UINT8",
"*",
"dest",
",",
"UINT32",
"*",
"complength",
")",
"{",
"UINT32",
"srcbytes",
"=",
"width",
"*",
"height",
"*",
"2",
";",
"huffman_context",
"*",
"contexts",
"[",
"4",
"]",
";",
"huffman_error",
"hufferr",
";",
"UINT32",
"outbytes",
";",
"UINT8",
"*",
"output",
";",
"output",
"=",
"dest",
";",
"*",
"output",
"++",
"=",
"0x80",
";",
"contexts",
"[",
"0",
"]",
"=",
"state",
"->",
"ycontext",
";",
"contexts",
"[",
"1",
"]",
"=",
"state",
"->",
"cbcontext",
";",
"contexts",
"[",
"2",
"]",
"=",
"state",
"->",
"ycontext",
";",
"contexts",
"[",
"3",
"]",
"=",
"state",
"->",
"crcontext",
";",
"hufferr",
"=",
"huffman_deltarle_compute_tree_interleaved",
"(",
"4",
",",
"contexts",
",",
"source",
",",
"width",
"*",
"2",
",",
"height",
",",
"sstride",
",",
"sxor",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_COMPRESSION_ERROR",
";",
"hufferr",
"=",
"huffman_deltarle_export_tree",
"(",
"state",
"->",
"ycontext",
",",
"output",
",",
"256",
",",
"&",
"outbytes",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_COMPRESSION_ERROR",
";",
"output",
"+=",
"outbytes",
";",
"hufferr",
"=",
"huffman_deltarle_export_tree",
"(",
"state",
"->",
"cbcontext",
",",
"output",
",",
"256",
",",
"&",
"outbytes",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_COMPRESSION_ERROR",
";",
"output",
"+=",
"outbytes",
";",
"hufferr",
"=",
"huffman_deltarle_export_tree",
"(",
"state",
"->",
"crcontext",
",",
"output",
",",
"256",
",",
"&",
"outbytes",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_COMPRESSION_ERROR",
";",
"output",
"+=",
"outbytes",
";",
"hufferr",
"=",
"huffman_deltarle_encode_data_interleaved",
"(",
"4",
",",
"contexts",
",",
"source",
",",
"width",
"*",
"2",
",",
"height",
",",
"sstride",
",",
"sxor",
",",
"output",
",",
"srcbytes",
",",
"&",
"outbytes",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_COMPRESSION_ERROR",
";",
"output",
"+=",
"outbytes",
";",
"*",
"complength",
"=",
"output",
"-",
"dest",
";",
"return",
"AVCERR_NONE",
";",
"}"
] | encode_video_lossless - do a lossless video
encoding using deltas and huffman encoding | [
"encode_video_lossless",
"-",
"do",
"a",
"lossless",
"video",
"encoding",
"using",
"deltas",
"and",
"huffman",
"encoding"
] | [
"/* set up the output; first byte is 0x80 to indicate lossless encoding */",
"/* now encode to the destination using two trees, one for the Y and one for the Cr/Cb */",
"/* compute the histograms for the data */",
"/* export the trees to the data stream */",
"/* encode the data using the trees */",
"/* set the final length */"
] | [
{
"param": "state",
"type": "avcomp_state"
},
{
"param": "width",
"type": "int"
},
{
"param": "height",
"type": "int"
},
{
"param": "source",
"type": "UINT8"
},
{
"param": "sstride",
"type": "UINT32"
},
{
"param": "sxor",
"type": "UINT32"
},
{
"param": "dest",
"type": "UINT8"
},
{
"param": "complength",
"type": "UINT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "state",
"type": "avcomp_state",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "width",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "height",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "source",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "sstride",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "sxor",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dest",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "complength",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
cd4be1614b9fcbb56b62f8ddfbf2292d77865e7c | lofunz/mieme | Reloaded/trunk/src/lib/util/avcomp.c | [
"Unlicense"
] | C | decode_audio | avcomp_error | static avcomp_error decode_audio(avcomp_state *state, int channels, int samples, const UINT8 *source, UINT8 **dest, UINT32 dxor, const UINT8 *sizes)
{
huffman_context *contexts[2];
UINT32 actsize, huffsize;
huffman_error hufferr;
int chnum, sampnum;
UINT16 size;
/* if no huffman length, just copy the data */
size = (sizes[0] << 8) | sizes[1];
if (size == 0)
{
/* loop over channels */
for (chnum = 0; chnum < channels; chnum++)
{
UINT8 *curdest = dest[chnum];
/* extract the size of this channel */
size = (sizes[chnum * 2 + 2] << 8) | sizes[chnum * 2 + 3];
/* extract data from the deltas */
if (dest[chnum] != NULL)
{
INT16 prevsample = 0;
for (sampnum = 0; sampnum < samples; sampnum++)
{
INT16 delta = (source[0] << 8) | source[1];
INT16 newsample = prevsample + delta;
prevsample = newsample;
curdest[0 ^ dxor] = newsample >> 8;
curdest[1 ^ dxor] = newsample;
source += 2;
curdest += 2;
}
}
else
source += size;
}
return AVCERR_NONE;
}
/* extract the huffman trees */
hufferr = huffman_import_tree(state->audiohicontext, source, size, &actsize);
if (hufferr != HUFFERR_NONE)
return AVCERR_INVALID_DATA;
source += actsize;
huffsize = actsize;
hufferr = huffman_import_tree(state->audiolocontext, source, size, &actsize);
if (hufferr != HUFFERR_NONE)
return AVCERR_INVALID_DATA;
source += actsize;
huffsize += actsize;
if (huffsize != size)
return AVCERR_INVALID_DATA;
/* set up the contexts */
contexts[0] = state->audiohicontext;
contexts[1] = state->audiolocontext;
/* now loop over channels and decode their data */
for (chnum = 0; chnum < channels; chnum++)
{
/* extract the size of this channel */
size = (sizes[chnum * 2 + 2] << 8) | sizes[chnum * 2 + 3];
/* decode the data */
if (dest[chnum] != NULL)
{
UINT8 *deltabuf = state->audiodata + chnum * samples * 2;
hufferr = huffman_decode_data_interleaved(2, contexts, source, size, deltabuf, samples * 2, 1, 0, 0, &actsize);
if (hufferr != HUFFERR_NONE || actsize != size)
return AVCERR_INVALID_DATA;
}
/* advance */
source += size;
}
/* reassemble audio from the deltas */
for (chnum = 0; chnum < channels; chnum++)
if (dest[chnum] != NULL)
{
UINT8 *deltabuf = state->audiodata + chnum * samples * 2;
UINT8 *curdest = dest[chnum];
INT16 prevsample = 0;
for (sampnum = 0; sampnum < samples; sampnum++)
{
INT16 delta = (deltabuf[0] << 8) | deltabuf[1];
INT16 newsample = prevsample + delta;
prevsample = newsample;
curdest[0 ^ dxor] = newsample >> 8;
curdest[1 ^ dxor] = newsample;
deltabuf += 2;
curdest += 2;
}
}
return AVCERR_NONE;
} | /*-------------------------------------------------
decode_audio - decode audio from a
compressed data stream
-------------------------------------------------*/ | decode audio from a
compressed data stream | [
"decode",
"audio",
"from",
"a",
"compressed",
"data",
"stream"
] | static avcomp_error decode_audio(avcomp_state *state, int channels, int samples, const UINT8 *source, UINT8 **dest, UINT32 dxor, const UINT8 *sizes)
{
huffman_context *contexts[2];
UINT32 actsize, huffsize;
huffman_error hufferr;
int chnum, sampnum;
UINT16 size;
size = (sizes[0] << 8) | sizes[1];
if (size == 0)
{
for (chnum = 0; chnum < channels; chnum++)
{
UINT8 *curdest = dest[chnum];
size = (sizes[chnum * 2 + 2] << 8) | sizes[chnum * 2 + 3];
if (dest[chnum] != NULL)
{
INT16 prevsample = 0;
for (sampnum = 0; sampnum < samples; sampnum++)
{
INT16 delta = (source[0] << 8) | source[1];
INT16 newsample = prevsample + delta;
prevsample = newsample;
curdest[0 ^ dxor] = newsample >> 8;
curdest[1 ^ dxor] = newsample;
source += 2;
curdest += 2;
}
}
else
source += size;
}
return AVCERR_NONE;
}
hufferr = huffman_import_tree(state->audiohicontext, source, size, &actsize);
if (hufferr != HUFFERR_NONE)
return AVCERR_INVALID_DATA;
source += actsize;
huffsize = actsize;
hufferr = huffman_import_tree(state->audiolocontext, source, size, &actsize);
if (hufferr != HUFFERR_NONE)
return AVCERR_INVALID_DATA;
source += actsize;
huffsize += actsize;
if (huffsize != size)
return AVCERR_INVALID_DATA;
contexts[0] = state->audiohicontext;
contexts[1] = state->audiolocontext;
for (chnum = 0; chnum < channels; chnum++)
{
size = (sizes[chnum * 2 + 2] << 8) | sizes[chnum * 2 + 3];
if (dest[chnum] != NULL)
{
UINT8 *deltabuf = state->audiodata + chnum * samples * 2;
hufferr = huffman_decode_data_interleaved(2, contexts, source, size, deltabuf, samples * 2, 1, 0, 0, &actsize);
if (hufferr != HUFFERR_NONE || actsize != size)
return AVCERR_INVALID_DATA;
}
source += size;
}
for (chnum = 0; chnum < channels; chnum++)
if (dest[chnum] != NULL)
{
UINT8 *deltabuf = state->audiodata + chnum * samples * 2;
UINT8 *curdest = dest[chnum];
INT16 prevsample = 0;
for (sampnum = 0; sampnum < samples; sampnum++)
{
INT16 delta = (deltabuf[0] << 8) | deltabuf[1];
INT16 newsample = prevsample + delta;
prevsample = newsample;
curdest[0 ^ dxor] = newsample >> 8;
curdest[1 ^ dxor] = newsample;
deltabuf += 2;
curdest += 2;
}
}
return AVCERR_NONE;
} | [
"static",
"avcomp_error",
"decode_audio",
"(",
"avcomp_state",
"*",
"state",
",",
"int",
"channels",
",",
"int",
"samples",
",",
"const",
"UINT8",
"*",
"source",
",",
"UINT8",
"*",
"*",
"dest",
",",
"UINT32",
"dxor",
",",
"const",
"UINT8",
"*",
"sizes",
")",
"{",
"huffman_context",
"*",
"contexts",
"[",
"2",
"]",
";",
"UINT32",
"actsize",
",",
"huffsize",
";",
"huffman_error",
"hufferr",
";",
"int",
"chnum",
",",
"sampnum",
";",
"UINT16",
"size",
";",
"size",
"=",
"(",
"sizes",
"[",
"0",
"]",
"<<",
"8",
")",
"|",
"sizes",
"[",
"1",
"]",
";",
"if",
"(",
"size",
"==",
"0",
")",
"{",
"for",
"(",
"chnum",
"=",
"0",
";",
"chnum",
"<",
"channels",
";",
"chnum",
"++",
")",
"{",
"UINT8",
"*",
"curdest",
"=",
"dest",
"[",
"chnum",
"]",
";",
"size",
"=",
"(",
"sizes",
"[",
"chnum",
"*",
"2",
"+",
"2",
"]",
"<<",
"8",
")",
"|",
"sizes",
"[",
"chnum",
"*",
"2",
"+",
"3",
"]",
";",
"if",
"(",
"dest",
"[",
"chnum",
"]",
"!=",
"NULL",
")",
"{",
"INT16",
"prevsample",
"=",
"0",
";",
"for",
"(",
"sampnum",
"=",
"0",
";",
"sampnum",
"<",
"samples",
";",
"sampnum",
"++",
")",
"{",
"INT16",
"delta",
"=",
"(",
"source",
"[",
"0",
"]",
"<<",
"8",
")",
"|",
"source",
"[",
"1",
"]",
";",
"INT16",
"newsample",
"=",
"prevsample",
"+",
"delta",
";",
"prevsample",
"=",
"newsample",
";",
"curdest",
"[",
"0",
"^",
"dxor",
"]",
"=",
"newsample",
">>",
"8",
";",
"curdest",
"[",
"1",
"^",
"dxor",
"]",
"=",
"newsample",
";",
"source",
"+=",
"2",
";",
"curdest",
"+=",
"2",
";",
"}",
"}",
"else",
"source",
"+=",
"size",
";",
"}",
"return",
"AVCERR_NONE",
";",
"}",
"hufferr",
"=",
"huffman_import_tree",
"(",
"state",
"->",
"audiohicontext",
",",
"source",
",",
"size",
",",
"&",
"actsize",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_INVALID_DATA",
";",
"source",
"+=",
"actsize",
";",
"huffsize",
"=",
"actsize",
";",
"hufferr",
"=",
"huffman_import_tree",
"(",
"state",
"->",
"audiolocontext",
",",
"source",
",",
"size",
",",
"&",
"actsize",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_INVALID_DATA",
";",
"source",
"+=",
"actsize",
";",
"huffsize",
"+=",
"actsize",
";",
"if",
"(",
"huffsize",
"!=",
"size",
")",
"return",
"AVCERR_INVALID_DATA",
";",
"contexts",
"[",
"0",
"]",
"=",
"state",
"->",
"audiohicontext",
";",
"contexts",
"[",
"1",
"]",
"=",
"state",
"->",
"audiolocontext",
";",
"for",
"(",
"chnum",
"=",
"0",
";",
"chnum",
"<",
"channels",
";",
"chnum",
"++",
")",
"{",
"size",
"=",
"(",
"sizes",
"[",
"chnum",
"*",
"2",
"+",
"2",
"]",
"<<",
"8",
")",
"|",
"sizes",
"[",
"chnum",
"*",
"2",
"+",
"3",
"]",
";",
"if",
"(",
"dest",
"[",
"chnum",
"]",
"!=",
"NULL",
")",
"{",
"UINT8",
"*",
"deltabuf",
"=",
"state",
"->",
"audiodata",
"+",
"chnum",
"*",
"samples",
"*",
"2",
";",
"hufferr",
"=",
"huffman_decode_data_interleaved",
"(",
"2",
",",
"contexts",
",",
"source",
",",
"size",
",",
"deltabuf",
",",
"samples",
"*",
"2",
",",
"1",
",",
"0",
",",
"0",
",",
"&",
"actsize",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
"||",
"actsize",
"!=",
"size",
")",
"return",
"AVCERR_INVALID_DATA",
";",
"}",
"source",
"+=",
"size",
";",
"}",
"for",
"(",
"chnum",
"=",
"0",
";",
"chnum",
"<",
"channels",
";",
"chnum",
"++",
")",
"if",
"(",
"dest",
"[",
"chnum",
"]",
"!=",
"NULL",
")",
"{",
"UINT8",
"*",
"deltabuf",
"=",
"state",
"->",
"audiodata",
"+",
"chnum",
"*",
"samples",
"*",
"2",
";",
"UINT8",
"*",
"curdest",
"=",
"dest",
"[",
"chnum",
"]",
";",
"INT16",
"prevsample",
"=",
"0",
";",
"for",
"(",
"sampnum",
"=",
"0",
";",
"sampnum",
"<",
"samples",
";",
"sampnum",
"++",
")",
"{",
"INT16",
"delta",
"=",
"(",
"deltabuf",
"[",
"0",
"]",
"<<",
"8",
")",
"|",
"deltabuf",
"[",
"1",
"]",
";",
"INT16",
"newsample",
"=",
"prevsample",
"+",
"delta",
";",
"prevsample",
"=",
"newsample",
";",
"curdest",
"[",
"0",
"^",
"dxor",
"]",
"=",
"newsample",
">>",
"8",
";",
"curdest",
"[",
"1",
"^",
"dxor",
"]",
"=",
"newsample",
";",
"deltabuf",
"+=",
"2",
";",
"curdest",
"+=",
"2",
";",
"}",
"}",
"return",
"AVCERR_NONE",
";",
"}"
] | decode_audio - decode audio from a
compressed data stream | [
"decode_audio",
"-",
"decode",
"audio",
"from",
"a",
"compressed",
"data",
"stream"
] | [
"/* if no huffman length, just copy the data */",
"/* loop over channels */",
"/* extract the size of this channel */",
"/* extract data from the deltas */",
"/* extract the huffman trees */",
"/* set up the contexts */",
"/* now loop over channels and decode their data */",
"/* extract the size of this channel */",
"/* decode the data */",
"/* advance */",
"/* reassemble audio from the deltas */"
] | [
{
"param": "state",
"type": "avcomp_state"
},
{
"param": "channels",
"type": "int"
},
{
"param": "samples",
"type": "int"
},
{
"param": "source",
"type": "UINT8"
},
{
"param": "dest",
"type": "UINT8"
},
{
"param": "dxor",
"type": "UINT32"
},
{
"param": "sizes",
"type": "UINT8"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "state",
"type": "avcomp_state",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "channels",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "samples",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "source",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dest",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dxor",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "sizes",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
cd4be1614b9fcbb56b62f8ddfbf2292d77865e7c | lofunz/mieme | Reloaded/trunk/src/lib/util/avcomp.c | [
"Unlicense"
] | C | decode_video | avcomp_error | static avcomp_error decode_video(avcomp_state *state, int width, int height, const UINT8 *source, UINT32 complength, UINT8 *dest, UINT32 dstride, UINT32 dxor)
{
/* if the high bit of the first byte is set, we decode losslessly */
if (source[0] & 0x80)
return decode_video_lossless(state, width, height, source, complength, dest, dstride, dxor);
else
return AVCERR_INVALID_DATA;
} | /*-------------------------------------------------
decode_video - decode video from a
compressed data stream
-------------------------------------------------*/ | decode video from a
compressed data stream | [
"decode",
"video",
"from",
"a",
"compressed",
"data",
"stream"
] | static avcomp_error decode_video(avcomp_state *state, int width, int height, const UINT8 *source, UINT32 complength, UINT8 *dest, UINT32 dstride, UINT32 dxor)
{
if (source[0] & 0x80)
return decode_video_lossless(state, width, height, source, complength, dest, dstride, dxor);
else
return AVCERR_INVALID_DATA;
} | [
"static",
"avcomp_error",
"decode_video",
"(",
"avcomp_state",
"*",
"state",
",",
"int",
"width",
",",
"int",
"height",
",",
"const",
"UINT8",
"*",
"source",
",",
"UINT32",
"complength",
",",
"UINT8",
"*",
"dest",
",",
"UINT32",
"dstride",
",",
"UINT32",
"dxor",
")",
"{",
"if",
"(",
"source",
"[",
"0",
"]",
"&",
"0x80",
")",
"return",
"decode_video_lossless",
"(",
"state",
",",
"width",
",",
"height",
",",
"source",
",",
"complength",
",",
"dest",
",",
"dstride",
",",
"dxor",
")",
";",
"else",
"return",
"AVCERR_INVALID_DATA",
";",
"}"
] | decode_video - decode video from a
compressed data stream | [
"decode_video",
"-",
"decode",
"video",
"from",
"a",
"compressed",
"data",
"stream"
] | [
"/* if the high bit of the first byte is set, we decode losslessly */"
] | [
{
"param": "state",
"type": "avcomp_state"
},
{
"param": "width",
"type": "int"
},
{
"param": "height",
"type": "int"
},
{
"param": "source",
"type": "UINT8"
},
{
"param": "complength",
"type": "UINT32"
},
{
"param": "dest",
"type": "UINT8"
},
{
"param": "dstride",
"type": "UINT32"
},
{
"param": "dxor",
"type": "UINT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "state",
"type": "avcomp_state",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "width",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "height",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "source",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "complength",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dest",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dstride",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dxor",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
cd4be1614b9fcbb56b62f8ddfbf2292d77865e7c | lofunz/mieme | Reloaded/trunk/src/lib/util/avcomp.c | [
"Unlicense"
] | C | decode_video_lossless | avcomp_error | static avcomp_error decode_video_lossless(avcomp_state *state, int width, int height, const UINT8 *source, UINT32 complength, UINT8 *dest, UINT32 deststride, UINT32 destxor)
{
const UINT8 *sourceend = source + complength;
huffman_context *contexts[4];
huffman_error hufferr;
UINT32 actsize;
/* skip the first byte */
source++;
/* import the tables */
hufferr = huffman_deltarle_import_tree(state->ycontext, source, sourceend - source, &actsize);
if (hufferr != HUFFERR_NONE)
return AVCERR_INVALID_DATA;
source += actsize;
hufferr = huffman_deltarle_import_tree(state->cbcontext, source, sourceend - source, &actsize);
if (hufferr != HUFFERR_NONE)
return AVCERR_INVALID_DATA;
source += actsize;
hufferr = huffman_deltarle_import_tree(state->crcontext, source, sourceend - source, &actsize);
if (hufferr != HUFFERR_NONE)
return AVCERR_INVALID_DATA;
source += actsize;
/* set up the decoding contexts */
contexts[0] = state->ycontext;
contexts[1] = state->cbcontext;
contexts[2] = state->ycontext;
contexts[3] = state->crcontext;
/* decode to the destination */
hufferr = huffman_deltarle_decode_data_interleaved(4, contexts, source, sourceend - source, dest, width * 2, height, deststride, destxor, &actsize);
if (hufferr != HUFFERR_NONE)
return AVCERR_INVALID_DATA;
if (actsize != sourceend - source)
return AVCERR_INVALID_DATA;
return AVCERR_NONE;
} | /*-------------------------------------------------
decode_video_lossless - do a lossless video
decoding using deltas and huffman encoding
-------------------------------------------------*/ | do a lossless video
decoding using deltas and huffman encoding | [
"do",
"a",
"lossless",
"video",
"decoding",
"using",
"deltas",
"and",
"huffman",
"encoding"
] | static avcomp_error decode_video_lossless(avcomp_state *state, int width, int height, const UINT8 *source, UINT32 complength, UINT8 *dest, UINT32 deststride, UINT32 destxor)
{
const UINT8 *sourceend = source + complength;
huffman_context *contexts[4];
huffman_error hufferr;
UINT32 actsize;
source++;
hufferr = huffman_deltarle_import_tree(state->ycontext, source, sourceend - source, &actsize);
if (hufferr != HUFFERR_NONE)
return AVCERR_INVALID_DATA;
source += actsize;
hufferr = huffman_deltarle_import_tree(state->cbcontext, source, sourceend - source, &actsize);
if (hufferr != HUFFERR_NONE)
return AVCERR_INVALID_DATA;
source += actsize;
hufferr = huffman_deltarle_import_tree(state->crcontext, source, sourceend - source, &actsize);
if (hufferr != HUFFERR_NONE)
return AVCERR_INVALID_DATA;
source += actsize;
contexts[0] = state->ycontext;
contexts[1] = state->cbcontext;
contexts[2] = state->ycontext;
contexts[3] = state->crcontext;
hufferr = huffman_deltarle_decode_data_interleaved(4, contexts, source, sourceend - source, dest, width * 2, height, deststride, destxor, &actsize);
if (hufferr != HUFFERR_NONE)
return AVCERR_INVALID_DATA;
if (actsize != sourceend - source)
return AVCERR_INVALID_DATA;
return AVCERR_NONE;
} | [
"static",
"avcomp_error",
"decode_video_lossless",
"(",
"avcomp_state",
"*",
"state",
",",
"int",
"width",
",",
"int",
"height",
",",
"const",
"UINT8",
"*",
"source",
",",
"UINT32",
"complength",
",",
"UINT8",
"*",
"dest",
",",
"UINT32",
"deststride",
",",
"UINT32",
"destxor",
")",
"{",
"const",
"UINT8",
"*",
"sourceend",
"=",
"source",
"+",
"complength",
";",
"huffman_context",
"*",
"contexts",
"[",
"4",
"]",
";",
"huffman_error",
"hufferr",
";",
"UINT32",
"actsize",
";",
"source",
"++",
";",
"hufferr",
"=",
"huffman_deltarle_import_tree",
"(",
"state",
"->",
"ycontext",
",",
"source",
",",
"sourceend",
"-",
"source",
",",
"&",
"actsize",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_INVALID_DATA",
";",
"source",
"+=",
"actsize",
";",
"hufferr",
"=",
"huffman_deltarle_import_tree",
"(",
"state",
"->",
"cbcontext",
",",
"source",
",",
"sourceend",
"-",
"source",
",",
"&",
"actsize",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_INVALID_DATA",
";",
"source",
"+=",
"actsize",
";",
"hufferr",
"=",
"huffman_deltarle_import_tree",
"(",
"state",
"->",
"crcontext",
",",
"source",
",",
"sourceend",
"-",
"source",
",",
"&",
"actsize",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_INVALID_DATA",
";",
"source",
"+=",
"actsize",
";",
"contexts",
"[",
"0",
"]",
"=",
"state",
"->",
"ycontext",
";",
"contexts",
"[",
"1",
"]",
"=",
"state",
"->",
"cbcontext",
";",
"contexts",
"[",
"2",
"]",
"=",
"state",
"->",
"ycontext",
";",
"contexts",
"[",
"3",
"]",
"=",
"state",
"->",
"crcontext",
";",
"hufferr",
"=",
"huffman_deltarle_decode_data_interleaved",
"(",
"4",
",",
"contexts",
",",
"source",
",",
"sourceend",
"-",
"source",
",",
"dest",
",",
"width",
"*",
"2",
",",
"height",
",",
"deststride",
",",
"destxor",
",",
"&",
"actsize",
")",
";",
"if",
"(",
"hufferr",
"!=",
"HUFFERR_NONE",
")",
"return",
"AVCERR_INVALID_DATA",
";",
"if",
"(",
"actsize",
"!=",
"sourceend",
"-",
"source",
")",
"return",
"AVCERR_INVALID_DATA",
";",
"return",
"AVCERR_NONE",
";",
"}"
] | decode_video_lossless - do a lossless video
decoding using deltas and huffman encoding | [
"decode_video_lossless",
"-",
"do",
"a",
"lossless",
"video",
"decoding",
"using",
"deltas",
"and",
"huffman",
"encoding"
] | [
"/* skip the first byte */",
"/* import the tables */",
"/* set up the decoding contexts */",
"/* decode to the destination */"
] | [
{
"param": "state",
"type": "avcomp_state"
},
{
"param": "width",
"type": "int"
},
{
"param": "height",
"type": "int"
},
{
"param": "source",
"type": "UINT8"
},
{
"param": "complength",
"type": "UINT32"
},
{
"param": "dest",
"type": "UINT8"
},
{
"param": "deststride",
"type": "UINT32"
},
{
"param": "destxor",
"type": "UINT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "state",
"type": "avcomp_state",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "width",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "height",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "source",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "complength",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dest",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "deststride",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "destxor",
"type": "UINT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
31cd9a2c52f1d02ed55d7508c31e912d9baf4658 | lofunz/mieme | Reloaded/trunk/src/mame/machine/model3.c | [
"Unlicense"
] | C | insert_bit | void | static void insert_bit(UINT8 *buf, INT32 bit_num, INT32 bit)
{
INT32 bit_in_byte;
bit_in_byte = 7 - (bit_num & 7);
buf[bit_num / 8] &= ~(1 << bit_in_byte);
buf[bit_num / 8] |= (bit << bit_in_byte);
} | /*
* insert_bit():
*
* Inserts a bit into an arbitrarily long bit field. Bit 0 is assumed to be
* the MSB of the first byte in the buffer.
*/ |
Inserts a bit into an arbitrarily long bit field. Bit 0 is assumed to be
the MSB of the first byte in the buffer. | [
"Inserts",
"a",
"bit",
"into",
"an",
"arbitrarily",
"long",
"bit",
"field",
".",
"Bit",
"0",
"is",
"assumed",
"to",
"be",
"the",
"MSB",
"of",
"the",
"first",
"byte",
"in",
"the",
"buffer",
"."
] | static void insert_bit(UINT8 *buf, INT32 bit_num, INT32 bit)
{
INT32 bit_in_byte;
bit_in_byte = 7 - (bit_num & 7);
buf[bit_num / 8] &= ~(1 << bit_in_byte);
buf[bit_num / 8] |= (bit << bit_in_byte);
} | [
"static",
"void",
"insert_bit",
"(",
"UINT8",
"*",
"buf",
",",
"INT32",
"bit_num",
",",
"INT32",
"bit",
")",
"{",
"INT32",
"bit_in_byte",
";",
"bit_in_byte",
"=",
"7",
"-",
"(",
"bit_num",
"&",
"7",
")",
";",
"buf",
"[",
"bit_num",
"/",
"8",
"]",
"&=",
"~",
"(",
"1",
"<<",
"bit_in_byte",
")",
";",
"buf",
"[",
"bit_num",
"/",
"8",
"]",
"|=",
"(",
"bit",
"<<",
"bit_in_byte",
")",
";",
"}"
] | insert_bit(): | [
"insert_bit",
"()",
":"
] | [] | [
{
"param": "buf",
"type": "UINT8"
},
{
"param": "bit_num",
"type": "INT32"
},
{
"param": "bit",
"type": "INT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "buf",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "bit_num",
"type": "INT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "bit",
"type": "INT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
31cd9a2c52f1d02ed55d7508c31e912d9baf4658 | lofunz/mieme | Reloaded/trunk/src/mame/machine/model3.c | [
"Unlicense"
] | C | shift | int | static int shift(UINT8 *data, INT32 num_bits)
{
INT32 i;
int shift_out, shift_in;
/*
* This loop takes care of all the fully-filled bytes
*/
shift_in = 0;
shift_out = 0;
for (i = 0; i < num_bits / 8; i++)
{
shift_out = data[i] & 1;
data[i] >>= 1;
data[i] |= (shift_in << 7);
shift_in = shift_out; // carry over to next element's MSB
}
/*
* Take care of the last partial byte (if there is one)
*/
if ((num_bits & 7) != 0)
{
shift_out = (data[i] >> (8 - (num_bits & 7))) & 1;
data[i] >>= 1;
data[i] |= (shift_in << 7);
}
return shift_out;
} | /*
* shift():
*
* Shifts the data buffer right (towards LSB at byte 0) by 1 bit. The size of
* the number of bits must be specified. The bit shifted out of the LSB is
* returned.
*/ |
Shifts the data buffer right (towards LSB at byte 0) by 1 bit. The size of
the number of bits must be specified. The bit shifted out of the LSB is
returned. | [
"Shifts",
"the",
"data",
"buffer",
"right",
"(",
"towards",
"LSB",
"at",
"byte",
"0",
")",
"by",
"1",
"bit",
".",
"The",
"size",
"of",
"the",
"number",
"of",
"bits",
"must",
"be",
"specified",
".",
"The",
"bit",
"shifted",
"out",
"of",
"the",
"LSB",
"is",
"returned",
"."
] | static int shift(UINT8 *data, INT32 num_bits)
{
INT32 i;
int shift_out, shift_in;
shift_in = 0;
shift_out = 0;
for (i = 0; i < num_bits / 8; i++)
{
shift_out = data[i] & 1;
data[i] >>= 1;
data[i] |= (shift_in << 7);
shift_in = shift_out;
}
if ((num_bits & 7) != 0)
{
shift_out = (data[i] >> (8 - (num_bits & 7))) & 1;
data[i] >>= 1;
data[i] |= (shift_in << 7);
}
return shift_out;
} | [
"static",
"int",
"shift",
"(",
"UINT8",
"*",
"data",
",",
"INT32",
"num_bits",
")",
"{",
"INT32",
"i",
";",
"int",
"shift_out",
",",
"shift_in",
";",
"shift_in",
"=",
"0",
";",
"shift_out",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"num_bits",
"/",
"8",
";",
"i",
"++",
")",
"{",
"shift_out",
"=",
"data",
"[",
"i",
"]",
"&",
"1",
";",
"data",
"[",
"i",
"]",
">>=",
"1",
";",
"data",
"[",
"i",
"]",
"|=",
"(",
"shift_in",
"<<",
"7",
")",
";",
"shift_in",
"=",
"shift_out",
";",
"}",
"if",
"(",
"(",
"num_bits",
"&",
"7",
")",
"!=",
"0",
")",
"{",
"shift_out",
"=",
"(",
"data",
"[",
"i",
"]",
">>",
"(",
"8",
"-",
"(",
"num_bits",
"&",
"7",
")",
")",
")",
"&",
"1",
";",
"data",
"[",
"i",
"]",
">>=",
"1",
";",
"data",
"[",
"i",
"]",
"|=",
"(",
"shift_in",
"<<",
"7",
")",
";",
"}",
"return",
"shift_out",
";",
"}"
] | shift(): | [
"shift",
"()",
":"
] | [
"/*\r\n * This loop takes care of all the fully-filled bytes\r\n */",
"// carry over to next element's MSB\r",
"/*\r\n * Take care of the last partial byte (if there is one)\r\n */"
] | [
{
"param": "data",
"type": "UINT8"
},
{
"param": "num_bits",
"type": "INT32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "data",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "num_bits",
"type": "INT32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d2a8d1156099b73b7d9900dbe2bf8e84e6b3d19b | lofunz/mieme | Reloaded/tags/MAME4droid.Reloaded.1.0.WIP/src/mame/video/gaelco2.c | [
"Unlicense"
] | C | draw_sprites | void | static void draw_sprites(const device_config *screen, bitmap_t *bitmap, const rectangle *cliprect, int mask, int xoffs)
{
int j, x, y, ex, ey, px, py;
const gfx_element *gfx = screen->machine->gfx[0];
/* get sprite ram start and end offsets */
int start_offset = (gaelco2_vregs[1] & 0x10)*0x100;
int end_offset = start_offset + 0x1000;
/* sprite offset is based on the visible area */
int spr_x_adjust = (video_screen_get_visible_area(screen)->max_x - 320 + 1) - (511 - 320 - 1) - ((gaelco2_vregs[0] >> 4) & 0x01) + xoffs;
for (j = start_offset; j < end_offset; j += 8){
int data = buffered_spriteram16[(j/2) + 0];
int data2 = buffered_spriteram16[(j/2) + 1];
int data3 = buffered_spriteram16[(j/2) + 2];
int data4 = buffered_spriteram16[(j/2) + 3];
int sx = data3 & 0x3ff;
int sy = data2 & 0x1ff;
int xflip = data2 & 0x800;
int yflip = data2 & 0x400;
int xsize = ((data3 >> 12) & 0x0f) + 1;
int ysize = ((data2 >> 12) & 0x0f) + 1;
if (dual_monitor && ((data & 0x8000) != mask)) continue;
/* if it's enabled, draw it */
if ((data2 & 0x0200) != 0){
for (y = 0; y < ysize; y++){
for (x = 0; x < xsize; x++){
/* for each x,y of the sprite, fetch the sprite data */
int data5 = buffered_spriteram16[((data4/2) + (y*xsize + x)) & 0x7fff];
int number = ((data & 0x1ff) << 10) + (data5 & 0x0fff);
int color = ((data >> 9) & 0x7f) + ((data5 >> 12) & 0x0f);
int color_effect = dual_monitor ? ((color & 0x3f) == 0x3f) : (color == 0x7f);
ex = xflip ? (xsize - 1 - x) : x;
ey = yflip ? (ysize - 1 - y) : y;
/* normal sprite, pen 0 transparent */
if (color_effect == 0){
drawgfx_transpen(bitmap, cliprect, gfx, number,
color, xflip, yflip,
((sx + ex*16) & 0x3ff) + spr_x_adjust,
((sy + ey*16) & 0x1ff), 0);
} else { /* last palette entry is reserved for shadows and highlights */
/* get a pointer to the current sprite's gfx data */
const UINT8 *gfx_src = gfx_element_get_data(gfx, number % gfx->total_elements);
for (py = 0; py < gfx->height; py++){
/* get a pointer to the current line in the screen bitmap */
int ypos = ((sy + ey*16 + py) & 0x1ff);
UINT16 *srcy = BITMAP_ADDR16(bitmap, ypos, 0);
int gfx_py = yflip ? (gfx->height - 1 - py) : py;
if ((ypos < cliprect->min_y) || (ypos > cliprect->max_y)) continue;
for (px = 0; px < gfx->width; px++){
/* get current pixel */
int xpos = (((sx + ex*16 + px) & 0x3ff) + spr_x_adjust) & 0x3ff;
UINT16 *pixel = srcy + xpos;
int src_color = *pixel;
int gfx_px = xflip ? (gfx->width - 1 - px) : px;
/* get asociated pen for the current sprite pixel */
int gfx_pen = gfx_src[gfx->line_modulo*gfx_py + gfx_px];
if ((gfx_pen == 0) || (gfx_pen >= 16)) continue;
if ((xpos < cliprect->min_x) || (xpos > cliprect->max_x)) continue;
/* make background color darker or brighter */
*pixel = src_color + 4096*gfx_pen;
}
}
}
}
}
}
}
} | /***************************************************************************
Sprite Format
-------------
Word | Bit(s) | Description
-----+-FEDCBA98-76543210-+--------------------------
0 | -------x xxxxxxxx | sprite bank (sprite number bits 18-10)
0 | xxxxxxx- -------- | sprite color (bits 6-0)
1 | -------x xxxxxxxx | y position
1 | ------x- -------- | sprite enable
1 | -----x-- -------- | flipy
1 | ----x--- -------- | flipx
1 | xxxx---- -------- | sprite y size
2 | ------xx xxxxxxxx | x position
2 | ----xx-- -------- | not used?
2 | xxxx---- -------- | sprite x size
3 | xxxxxxxx xxxxxxxx | pointer to more sprite data
Each sprite entry has a pointer to more sprite data.
The length of data depends on the sprite size (xsize*ysize).
Each entry has the following format:
Word | Bit(s) | Description
-----+-FEDCBA98-76543210-+--------------------------
0 | ----xxxx xxxxxxxx | sprite number offset (sprite number bits 11-0)
0 | xxxx---- -------- | sprite color offset (bits 3-0)
In dual monitor games, the configuration is the same, but MSB of
word 0 is used to select target monitor for the sprite, and the
palette is splitted for each monitor.
Last sprite color entry is used for shadows/highlights
***************************************************************************/ |
Each sprite entry has a pointer to more sprite data.
The length of data depends on the sprite size (xsize*ysize).
Each entry has the following format.
In dual monitor games, the configuration is the same, but MSB of
word 0 is used to select target monitor for the sprite, and the
palette is splitted for each monitor.
Last sprite color entry is used for shadows/highlights | [
"Each",
"sprite",
"entry",
"has",
"a",
"pointer",
"to",
"more",
"sprite",
"data",
".",
"The",
"length",
"of",
"data",
"depends",
"on",
"the",
"sprite",
"size",
"(",
"xsize",
"*",
"ysize",
")",
".",
"Each",
"entry",
"has",
"the",
"following",
"format",
".",
"In",
"dual",
"monitor",
"games",
"the",
"configuration",
"is",
"the",
"same",
"but",
"MSB",
"of",
"word",
"0",
"is",
"used",
"to",
"select",
"target",
"monitor",
"for",
"the",
"sprite",
"and",
"the",
"palette",
"is",
"splitted",
"for",
"each",
"monitor",
".",
"Last",
"sprite",
"color",
"entry",
"is",
"used",
"for",
"shadows",
"/",
"highlights"
] | static void draw_sprites(const device_config *screen, bitmap_t *bitmap, const rectangle *cliprect, int mask, int xoffs)
{
int j, x, y, ex, ey, px, py;
const gfx_element *gfx = screen->machine->gfx[0];
int start_offset = (gaelco2_vregs[1] & 0x10)*0x100;
int end_offset = start_offset + 0x1000;
int spr_x_adjust = (video_screen_get_visible_area(screen)->max_x - 320 + 1) - (511 - 320 - 1) - ((gaelco2_vregs[0] >> 4) & 0x01) + xoffs;
for (j = start_offset; j < end_offset; j += 8){
int data = buffered_spriteram16[(j/2) + 0];
int data2 = buffered_spriteram16[(j/2) + 1];
int data3 = buffered_spriteram16[(j/2) + 2];
int data4 = buffered_spriteram16[(j/2) + 3];
int sx = data3 & 0x3ff;
int sy = data2 & 0x1ff;
int xflip = data2 & 0x800;
int yflip = data2 & 0x400;
int xsize = ((data3 >> 12) & 0x0f) + 1;
int ysize = ((data2 >> 12) & 0x0f) + 1;
if (dual_monitor && ((data & 0x8000) != mask)) continue;
if ((data2 & 0x0200) != 0){
for (y = 0; y < ysize; y++){
for (x = 0; x < xsize; x++){
int data5 = buffered_spriteram16[((data4/2) + (y*xsize + x)) & 0x7fff];
int number = ((data & 0x1ff) << 10) + (data5 & 0x0fff);
int color = ((data >> 9) & 0x7f) + ((data5 >> 12) & 0x0f);
int color_effect = dual_monitor ? ((color & 0x3f) == 0x3f) : (color == 0x7f);
ex = xflip ? (xsize - 1 - x) : x;
ey = yflip ? (ysize - 1 - y) : y;
if (color_effect == 0){
drawgfx_transpen(bitmap, cliprect, gfx, number,
color, xflip, yflip,
((sx + ex*16) & 0x3ff) + spr_x_adjust,
((sy + ey*16) & 0x1ff), 0);
} else {
const UINT8 *gfx_src = gfx_element_get_data(gfx, number % gfx->total_elements);
for (py = 0; py < gfx->height; py++){
int ypos = ((sy + ey*16 + py) & 0x1ff);
UINT16 *srcy = BITMAP_ADDR16(bitmap, ypos, 0);
int gfx_py = yflip ? (gfx->height - 1 - py) : py;
if ((ypos < cliprect->min_y) || (ypos > cliprect->max_y)) continue;
for (px = 0; px < gfx->width; px++){
int xpos = (((sx + ex*16 + px) & 0x3ff) + spr_x_adjust) & 0x3ff;
UINT16 *pixel = srcy + xpos;
int src_color = *pixel;
int gfx_px = xflip ? (gfx->width - 1 - px) : px;
int gfx_pen = gfx_src[gfx->line_modulo*gfx_py + gfx_px];
if ((gfx_pen == 0) || (gfx_pen >= 16)) continue;
if ((xpos < cliprect->min_x) || (xpos > cliprect->max_x)) continue;
*pixel = src_color + 4096*gfx_pen;
}
}
}
}
}
}
}
} | [
"static",
"void",
"draw_sprites",
"(",
"const",
"device_config",
"*",
"screen",
",",
"bitmap_t",
"*",
"bitmap",
",",
"const",
"rectangle",
"*",
"cliprect",
",",
"int",
"mask",
",",
"int",
"xoffs",
")",
"{",
"int",
"j",
",",
"x",
",",
"y",
",",
"ex",
",",
"ey",
",",
"px",
",",
"py",
";",
"const",
"gfx_element",
"*",
"gfx",
"=",
"screen",
"->",
"machine",
"->",
"gfx",
"[",
"0",
"]",
";",
"int",
"start_offset",
"=",
"(",
"gaelco2_vregs",
"[",
"1",
"]",
"&",
"0x10",
")",
"*",
"0x100",
";",
"int",
"end_offset",
"=",
"start_offset",
"+",
"0x1000",
";",
"int",
"spr_x_adjust",
"=",
"(",
"video_screen_get_visible_area",
"(",
"screen",
")",
"->",
"max_x",
"-",
"320",
"+",
"1",
")",
"-",
"(",
"511",
"-",
"320",
"-",
"1",
")",
"-",
"(",
"(",
"gaelco2_vregs",
"[",
"0",
"]",
">>",
"4",
")",
"&",
"0x01",
")",
"+",
"xoffs",
";",
"for",
"(",
"j",
"=",
"start_offset",
";",
"j",
"<",
"end_offset",
";",
"j",
"+=",
"8",
")",
"{",
"int",
"data",
"=",
"buffered_spriteram16",
"[",
"(",
"j",
"/",
"2",
")",
"+",
"0",
"]",
";",
"int",
"data2",
"=",
"buffered_spriteram16",
"[",
"(",
"j",
"/",
"2",
")",
"+",
"1",
"]",
";",
"int",
"data3",
"=",
"buffered_spriteram16",
"[",
"(",
"j",
"/",
"2",
")",
"+",
"2",
"]",
";",
"int",
"data4",
"=",
"buffered_spriteram16",
"[",
"(",
"j",
"/",
"2",
")",
"+",
"3",
"]",
";",
"int",
"sx",
"=",
"data3",
"&",
"0x3ff",
";",
"int",
"sy",
"=",
"data2",
"&",
"0x1ff",
";",
"int",
"xflip",
"=",
"data2",
"&",
"0x800",
";",
"int",
"yflip",
"=",
"data2",
"&",
"0x400",
";",
"int",
"xsize",
"=",
"(",
"(",
"data3",
">>",
"12",
")",
"&",
"0x0f",
")",
"+",
"1",
";",
"int",
"ysize",
"=",
"(",
"(",
"data2",
">>",
"12",
")",
"&",
"0x0f",
")",
"+",
"1",
";",
"if",
"(",
"dual_monitor",
"&&",
"(",
"(",
"data",
"&",
"0x8000",
")",
"!=",
"mask",
")",
")",
"continue",
";",
"if",
"(",
"(",
"data2",
"&",
"0x0200",
")",
"!=",
"0",
")",
"{",
"for",
"(",
"y",
"=",
"0",
";",
"y",
"<",
"ysize",
";",
"y",
"++",
")",
"{",
"for",
"(",
"x",
"=",
"0",
";",
"x",
"<",
"xsize",
";",
"x",
"++",
")",
"{",
"int",
"data5",
"=",
"buffered_spriteram16",
"[",
"(",
"(",
"data4",
"/",
"2",
")",
"+",
"(",
"y",
"*",
"xsize",
"+",
"x",
")",
")",
"&",
"0x7fff",
"]",
";",
"int",
"number",
"=",
"(",
"(",
"data",
"&",
"0x1ff",
")",
"<<",
"10",
")",
"+",
"(",
"data5",
"&",
"0x0fff",
")",
";",
"int",
"color",
"=",
"(",
"(",
"data",
">>",
"9",
")",
"&",
"0x7f",
")",
"+",
"(",
"(",
"data5",
">>",
"12",
")",
"&",
"0x0f",
")",
";",
"int",
"color_effect",
"=",
"dual_monitor",
"?",
"(",
"(",
"color",
"&",
"0x3f",
")",
"==",
"0x3f",
")",
":",
"(",
"color",
"==",
"0x7f",
")",
";",
"ex",
"=",
"xflip",
"?",
"(",
"xsize",
"-",
"1",
"-",
"x",
")",
":",
"x",
";",
"ey",
"=",
"yflip",
"?",
"(",
"ysize",
"-",
"1",
"-",
"y",
")",
":",
"y",
";",
"if",
"(",
"color_effect",
"==",
"0",
")",
"{",
"drawgfx_transpen",
"(",
"bitmap",
",",
"cliprect",
",",
"gfx",
",",
"number",
",",
"color",
",",
"xflip",
",",
"yflip",
",",
"(",
"(",
"sx",
"+",
"ex",
"*",
"16",
")",
"&",
"0x3ff",
")",
"+",
"spr_x_adjust",
",",
"(",
"(",
"sy",
"+",
"ey",
"*",
"16",
")",
"&",
"0x1ff",
")",
",",
"0",
")",
";",
"}",
"else",
"{",
"const",
"UINT8",
"*",
"gfx_src",
"=",
"gfx_element_get_data",
"(",
"gfx",
",",
"number",
"%",
"gfx",
"->",
"total_elements",
")",
";",
"for",
"(",
"py",
"=",
"0",
";",
"py",
"<",
"gfx",
"->",
"height",
";",
"py",
"++",
")",
"{",
"int",
"ypos",
"=",
"(",
"(",
"sy",
"+",
"ey",
"*",
"16",
"+",
"py",
")",
"&",
"0x1ff",
")",
";",
"UINT16",
"*",
"srcy",
"=",
"BITMAP_ADDR16",
"(",
"bitmap",
",",
"ypos",
",",
"0",
")",
";",
"int",
"gfx_py",
"=",
"yflip",
"?",
"(",
"gfx",
"->",
"height",
"-",
"1",
"-",
"py",
")",
":",
"py",
";",
"if",
"(",
"(",
"ypos",
"<",
"cliprect",
"->",
"min_y",
")",
"||",
"(",
"ypos",
">",
"cliprect",
"->",
"max_y",
")",
")",
"continue",
";",
"for",
"(",
"px",
"=",
"0",
";",
"px",
"<",
"gfx",
"->",
"width",
";",
"px",
"++",
")",
"{",
"int",
"xpos",
"=",
"(",
"(",
"(",
"sx",
"+",
"ex",
"*",
"16",
"+",
"px",
")",
"&",
"0x3ff",
")",
"+",
"spr_x_adjust",
")",
"&",
"0x3ff",
";",
"UINT16",
"*",
"pixel",
"=",
"srcy",
"+",
"xpos",
";",
"int",
"src_color",
"=",
"*",
"pixel",
";",
"int",
"gfx_px",
"=",
"xflip",
"?",
"(",
"gfx",
"->",
"width",
"-",
"1",
"-",
"px",
")",
":",
"px",
";",
"int",
"gfx_pen",
"=",
"gfx_src",
"[",
"gfx",
"->",
"line_modulo",
"*",
"gfx_py",
"+",
"gfx_px",
"]",
";",
"if",
"(",
"(",
"gfx_pen",
"==",
"0",
")",
"||",
"(",
"gfx_pen",
">=",
"16",
")",
")",
"continue",
";",
"if",
"(",
"(",
"xpos",
"<",
"cliprect",
"->",
"min_x",
")",
"||",
"(",
"xpos",
">",
"cliprect",
"->",
"max_x",
")",
")",
"continue",
";",
"*",
"pixel",
"=",
"src_color",
"+",
"4096",
"*",
"gfx_pen",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"}",
"}"
] | Sprite Format
Word | Bit(s) | Description
+-FEDCBA98-76543210-+
0 | -------x xxxxxxxx | sprite bank (sprite number bits 18-10)
0 | xxxxxxx- -------- | sprite color (bits 6-0)
1 | -------x xxxxxxxx | y position
1 | ------x- -------- | sprite enable
1 | -----x-- -------- | flipy
1 | ----x--- -------- | flipx
1 | xxxx---- -------- | sprite y size
2 | ------xx xxxxxxxx | x position
2 | ----xx-- -------- | not used? | [
"Sprite",
"Format",
"Word",
"|",
"Bit",
"(",
"s",
")",
"|",
"Description",
"+",
"-",
"FEDCBA98",
"-",
"76543210",
"-",
"+",
"0",
"|",
"-------",
"x",
"xxxxxxxx",
"|",
"sprite",
"bank",
"(",
"sprite",
"number",
"bits",
"18",
"-",
"10",
")",
"0",
"|",
"xxxxxxx",
"-",
"--------",
"|",
"sprite",
"color",
"(",
"bits",
"6",
"-",
"0",
")",
"1",
"|",
"-------",
"x",
"xxxxxxxx",
"|",
"y",
"position",
"1",
"|",
"------",
"x",
"-",
"--------",
"|",
"sprite",
"enable",
"1",
"|",
"-----",
"x",
"--",
"--------",
"|",
"flipy",
"1",
"|",
"----",
"x",
"---",
"--------",
"|",
"flipx",
"1",
"|",
"xxxx",
"----",
"--------",
"|",
"sprite",
"y",
"size",
"2",
"|",
"------",
"xx",
"xxxxxxxx",
"|",
"x",
"position",
"2",
"|",
"----",
"xx",
"--",
"--------",
"|",
"not",
"used?"
] | [
"/* get sprite ram start and end offsets */",
"/* sprite offset is based on the visible area */",
"/* if it's enabled, draw it */",
"/* for each x,y of the sprite, fetch the sprite data */",
"/* normal sprite, pen 0 transparent */",
"/* last palette entry is reserved for shadows and highlights */",
"/* get a pointer to the current sprite's gfx data */",
"/* get a pointer to the current line in the screen bitmap */",
"/* get current pixel */",
"/* get asociated pen for the current sprite pixel */",
"/* make background color darker or brighter */"
] | [
{
"param": "screen",
"type": "device_config"
},
{
"param": "bitmap",
"type": "bitmap_t"
},
{
"param": "cliprect",
"type": "rectangle"
},
{
"param": "mask",
"type": "int"
},
{
"param": "xoffs",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "screen",
"type": "device_config",
"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": "mask",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "xoffs",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d2778f79fb9de35f36e01562ec90025fe6134613 | lofunz/mieme | Reloaded/trunk/src/emu/cpu/dsp56k/dsp56mem.c | [
"Unlicense"
] | C | HCR_set | void | void HCR_set(dsp56k_core* cpustate, UINT16 value)
{
HF3_bit_set (cpustate, (value & 0x0010) >> 4);
HF2_bit_set (cpustate, (value & 0x0008) >> 3);
HCIE_bit_set(cpustate, (value & 0x0004) >> 2);
HTIE_bit_set(cpustate, (value & 0x0002) >> 1);
HRIE_bit_set(cpustate, (value & 0x0001) >> 0);
} | /***************/
/* DSP56k SIDE */
/***************/
/************************************/
/* Host Control Register (HCR) Bits */
/************************************/ | DSP56k SIDE
Host Control Register (HCR) Bits | [
"DSP56k",
"SIDE",
"Host",
"Control",
"Register",
"(",
"HCR",
")",
"Bits"
] | void HCR_set(dsp56k_core* cpustate, UINT16 value)
{
HF3_bit_set (cpustate, (value & 0x0010) >> 4);
HF2_bit_set (cpustate, (value & 0x0008) >> 3);
HCIE_bit_set(cpustate, (value & 0x0004) >> 2);
HTIE_bit_set(cpustate, (value & 0x0002) >> 1);
HRIE_bit_set(cpustate, (value & 0x0001) >> 0);
} | [
"void",
"HCR_set",
"(",
"dsp56k_core",
"*",
"cpustate",
",",
"UINT16",
"value",
")",
"{",
"HF3_bit_set",
"(",
"cpustate",
",",
"(",
"value",
"&",
"0x0010",
")",
">>",
"4",
")",
";",
"HF2_bit_set",
"(",
"cpustate",
",",
"(",
"value",
"&",
"0x0008",
")",
">>",
"3",
")",
";",
"HCIE_bit_set",
"(",
"cpustate",
",",
"(",
"value",
"&",
"0x0004",
")",
">>",
"2",
")",
";",
"HTIE_bit_set",
"(",
"cpustate",
",",
"(",
"value",
"&",
"0x0002",
")",
">>",
"1",
")",
";",
"HRIE_bit_set",
"(",
"cpustate",
",",
"(",
"value",
"&",
"0x0001",
")",
">>",
"0",
")",
";",
"}"
] | DSP56k SIDE
Host Control Register (HCR) Bits | [
"DSP56k",
"SIDE",
"Host",
"Control",
"Register",
"(",
"HCR",
")",
"Bits"
] | [] | [
{
"param": "cpustate",
"type": "dsp56k_core"
},
{
"param": "value",
"type": "UINT16"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cpustate",
"type": "dsp56k_core",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value",
"type": "UINT16",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d2778f79fb9de35f36e01562ec90025fe6134613 | lofunz/mieme | Reloaded/trunk/src/emu/cpu/dsp56k/dsp56mem.c | [
"Unlicense"
] | C | ICR_set | void | void ICR_set(dsp56k_core* cpustate, UINT8 value)
{
HF1_bit_host_set(cpustate, (value & 0x10) >> 4);
HF0_bit_host_set(cpustate, (value & 0x08) >> 3);
TREQ_bit_set(cpustate, (value & 0x02) >> 1);
RREQ_bit_set(cpustate, (value & 0x01) >> 0);
} | /*************/
/* HOST SIDE */
/*************/
/*****************************************/
/* Interrupt Control Register (ICR) Bits */
/*****************************************/ | HOST SIDE
Interrupt Control Register (ICR) Bits | [
"HOST",
"SIDE",
"Interrupt",
"Control",
"Register",
"(",
"ICR",
")",
"Bits"
] | void ICR_set(dsp56k_core* cpustate, UINT8 value)
{
HF1_bit_host_set(cpustate, (value & 0x10) >> 4);
HF0_bit_host_set(cpustate, (value & 0x08) >> 3);
TREQ_bit_set(cpustate, (value & 0x02) >> 1);
RREQ_bit_set(cpustate, (value & 0x01) >> 0);
} | [
"void",
"ICR_set",
"(",
"dsp56k_core",
"*",
"cpustate",
",",
"UINT8",
"value",
")",
"{",
"HF1_bit_host_set",
"(",
"cpustate",
",",
"(",
"value",
"&",
"0x10",
")",
">>",
"4",
")",
";",
"HF0_bit_host_set",
"(",
"cpustate",
",",
"(",
"value",
"&",
"0x08",
")",
">>",
"3",
")",
";",
"TREQ_bit_set",
"(",
"cpustate",
",",
"(",
"value",
"&",
"0x02",
")",
">>",
"1",
")",
";",
"RREQ_bit_set",
"(",
"cpustate",
",",
"(",
"value",
"&",
"0x01",
")",
">>",
"0",
")",
";",
"}"
] | HOST SIDE
Interrupt Control Register (ICR) Bits | [
"HOST",
"SIDE",
"Interrupt",
"Control",
"Register",
"(",
"ICR",
")",
"Bits"
] | [] | [
{
"param": "cpustate",
"type": "dsp56k_core"
},
{
"param": "value",
"type": "UINT8"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cpustate",
"type": "dsp56k_core",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d2778f79fb9de35f36e01562ec90025fe6134613 | lofunz/mieme | Reloaded/trunk/src/emu/cpu/dsp56k/dsp56mem.c | [
"Unlicense"
] | C | PBDDR_set | void | void PBDDR_set(dsp56k_core* cpustate, UINT16 value)
{
if (value & 0x8000)
logerror("Dsp56k : Attempting to set reserved bits in the PBDDR. Ignoring.\n");
value = value & 0x7fff;
PBDDR &= ~(0x7fff);
PBDDR |= (value << 0);
/* TODO: Implement dsp56k io restrictions, etc. */
} | /* Port B Data Direction Register (PBDDR) */ | Port B Data Direction Register (PBDDR) | [
"Port",
"B",
"Data",
"Direction",
"Register",
"(",
"PBDDR",
")"
] | void PBDDR_set(dsp56k_core* cpustate, UINT16 value)
{
if (value & 0x8000)
logerror("Dsp56k : Attempting to set reserved bits in the PBDDR. Ignoring.\n");
value = value & 0x7fff;
PBDDR &= ~(0x7fff);
PBDDR |= (value << 0);
} | [
"void",
"PBDDR_set",
"(",
"dsp56k_core",
"*",
"cpustate",
",",
"UINT16",
"value",
")",
"{",
"if",
"(",
"value",
"&",
"0x8000",
")",
"logerror",
"(",
"\"",
"\\n",
"\"",
")",
";",
"value",
"=",
"value",
"&",
"0x7fff",
";",
"PBDDR",
"&=",
"~",
"(",
"0x7fff",
")",
";",
"PBDDR",
"|=",
"(",
"value",
"<<",
"0",
")",
";",
"}"
] | Port B Data Direction Register (PBDDR) | [
"Port",
"B",
"Data",
"Direction",
"Register",
"(",
"PBDDR",
")"
] | [
"/* TODO: Implement dsp56k io restrictions, etc. */"
] | [
{
"param": "cpustate",
"type": "dsp56k_core"
},
{
"param": "value",
"type": "UINT16"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cpustate",
"type": "dsp56k_core",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value",
"type": "UINT16",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d2778f79fb9de35f36e01562ec90025fe6134613 | lofunz/mieme | Reloaded/trunk/src/emu/cpu/dsp56k/dsp56mem.c | [
"Unlicense"
] | C | PBD_set | void | void PBD_set(dsp56k_core* cpustate, UINT16 value)
{
if (value & 0x8000)
logerror("Dsp56k : Attempting to set reserved bits in the PBD. Ignoring.\n");
value = value & 0x7fff;
PBD &= ~(0x7fff);
PBD |= (value << 0);
/* TODO: Implement dsp56k io restrictions, etc. */
} | /* Port B Data Register (PBD) */ | Port B Data Register (PBD) | [
"Port",
"B",
"Data",
"Register",
"(",
"PBD",
")"
] | void PBD_set(dsp56k_core* cpustate, UINT16 value)
{
if (value & 0x8000)
logerror("Dsp56k : Attempting to set reserved bits in the PBD. Ignoring.\n");
value = value & 0x7fff;
PBD &= ~(0x7fff);
PBD |= (value << 0);
} | [
"void",
"PBD_set",
"(",
"dsp56k_core",
"*",
"cpustate",
",",
"UINT16",
"value",
")",
"{",
"if",
"(",
"value",
"&",
"0x8000",
")",
"logerror",
"(",
"\"",
"\\n",
"\"",
")",
";",
"value",
"=",
"value",
"&",
"0x7fff",
";",
"PBD",
"&=",
"~",
"(",
"0x7fff",
")",
";",
"PBD",
"|=",
"(",
"value",
"<<",
"0",
")",
";",
"}"
] | Port B Data Register (PBD) | [
"Port",
"B",
"Data",
"Register",
"(",
"PBD",
")"
] | [
"/* TODO: Implement dsp56k io restrictions, etc. */"
] | [
{
"param": "cpustate",
"type": "dsp56k_core"
},
{
"param": "value",
"type": "UINT16"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cpustate",
"type": "dsp56k_core",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value",
"type": "UINT16",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d2778f79fb9de35f36e01562ec90025fe6134613 | lofunz/mieme | Reloaded/trunk/src/emu/cpu/dsp56k/dsp56mem.c | [
"Unlicense"
] | C | PCC_set | void | void PCC_set(dsp56k_core* cpustate, UINT16 value)
{
if (value & 0xf000)
logerror("Dsp56k : Attempting to set reserved bits in the PCC. Ignoring.\n");
value = value & 0x0fff;
PCC &= ~(0x0fff);
PCC |= (value << 0);
/* TODO: Implement dsp56k timer and control glue */
} | /* Port C Control Register (PCC) */ | Port C Control Register (PCC) | [
"Port",
"C",
"Control",
"Register",
"(",
"PCC",
")"
] | void PCC_set(dsp56k_core* cpustate, UINT16 value)
{
if (value & 0xf000)
logerror("Dsp56k : Attempting to set reserved bits in the PCC. Ignoring.\n");
value = value & 0x0fff;
PCC &= ~(0x0fff);
PCC |= (value << 0);
} | [
"void",
"PCC_set",
"(",
"dsp56k_core",
"*",
"cpustate",
",",
"UINT16",
"value",
")",
"{",
"if",
"(",
"value",
"&",
"0xf000",
")",
"logerror",
"(",
"\"",
"\\n",
"\"",
")",
";",
"value",
"=",
"value",
"&",
"0x0fff",
";",
"PCC",
"&=",
"~",
"(",
"0x0fff",
")",
";",
"PCC",
"|=",
"(",
"value",
"<<",
"0",
")",
";",
"}"
] | Port C Control Register (PCC) | [
"Port",
"C",
"Control",
"Register",
"(",
"PCC",
")"
] | [
"/* TODO: Implement dsp56k timer and control glue */"
] | [
{
"param": "cpustate",
"type": "dsp56k_core"
},
{
"param": "value",
"type": "UINT16"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cpustate",
"type": "dsp56k_core",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value",
"type": "UINT16",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d2778f79fb9de35f36e01562ec90025fe6134613 | lofunz/mieme | Reloaded/trunk/src/emu/cpu/dsp56k/dsp56mem.c | [
"Unlicense"
] | C | PCDDR_set | void | void PCDDR_set(dsp56k_core* cpustate, UINT16 value)
{
if (value & 0xf000)
logerror("Dsp56k : Attempting to set reserved bits in the PCDDR. Ignoring.\n");
value = value & 0x0fff;
PCDDR &= ~(0x0fff);
PCDDR |= (value << 0);
/* TODO: Implement dsp56k io restrictions, etc. */
} | /* Port C Data Direction Register (PCDDR) */ | Port C Data Direction Register (PCDDR) | [
"Port",
"C",
"Data",
"Direction",
"Register",
"(",
"PCDDR",
")"
] | void PCDDR_set(dsp56k_core* cpustate, UINT16 value)
{
if (value & 0xf000)
logerror("Dsp56k : Attempting to set reserved bits in the PCDDR. Ignoring.\n");
value = value & 0x0fff;
PCDDR &= ~(0x0fff);
PCDDR |= (value << 0);
} | [
"void",
"PCDDR_set",
"(",
"dsp56k_core",
"*",
"cpustate",
",",
"UINT16",
"value",
")",
"{",
"if",
"(",
"value",
"&",
"0xf000",
")",
"logerror",
"(",
"\"",
"\\n",
"\"",
")",
";",
"value",
"=",
"value",
"&",
"0x0fff",
";",
"PCDDR",
"&=",
"~",
"(",
"0x0fff",
")",
";",
"PCDDR",
"|=",
"(",
"value",
"<<",
"0",
")",
";",
"}"
] | Port C Data Direction Register (PCDDR) | [
"Port",
"C",
"Data",
"Direction",
"Register",
"(",
"PCDDR",
")"
] | [
"/* TODO: Implement dsp56k io restrictions, etc. */"
] | [
{
"param": "cpustate",
"type": "dsp56k_core"
},
{
"param": "value",
"type": "UINT16"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cpustate",
"type": "dsp56k_core",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value",
"type": "UINT16",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d2778f79fb9de35f36e01562ec90025fe6134613 | lofunz/mieme | Reloaded/trunk/src/emu/cpu/dsp56k/dsp56mem.c | [
"Unlicense"
] | C | PCD_set | void | void PCD_set(dsp56k_core* cpustate, UINT16 value)
{
if (value & 0xf000)
logerror("Dsp56k : Attempting to set reserved bits in the PCD. Ignoring.\n");
/* TODO: Temporary */
logerror("Dsp56k : Setting general output port C data to 0x%04x\n", value);
value = value & 0x0fff;
PCD &= ~(0x0fff);
PCD |= (value << 0);
} | /* Port C Data Register (PCD) */ | Port C Data Register (PCD) | [
"Port",
"C",
"Data",
"Register",
"(",
"PCD",
")"
] | void PCD_set(dsp56k_core* cpustate, UINT16 value)
{
if (value & 0xf000)
logerror("Dsp56k : Attempting to set reserved bits in the PCD. Ignoring.\n");
logerror("Dsp56k : Setting general output port C data to 0x%04x\n", value);
value = value & 0x0fff;
PCD &= ~(0x0fff);
PCD |= (value << 0);
} | [
"void",
"PCD_set",
"(",
"dsp56k_core",
"*",
"cpustate",
",",
"UINT16",
"value",
")",
"{",
"if",
"(",
"value",
"&",
"0xf000",
")",
"logerror",
"(",
"\"",
"\\n",
"\"",
")",
";",
"logerror",
"(",
"\"",
"\\n",
"\"",
",",
"value",
")",
";",
"value",
"=",
"value",
"&",
"0x0fff",
";",
"PCD",
"&=",
"~",
"(",
"0x0fff",
")",
";",
"PCD",
"|=",
"(",
"value",
"<<",
"0",
")",
";",
"}"
] | Port C Data Register (PCD) | [
"Port",
"C",
"Data",
"Register",
"(",
"PCD",
")"
] | [
"/* TODO: Temporary */"
] | [
{
"param": "cpustate",
"type": "dsp56k_core"
},
{
"param": "value",
"type": "UINT16"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cpustate",
"type": "dsp56k_core",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value",
"type": "UINT16",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
eb144864121117879c056e19428e1dc477339139 | lofunz/mieme | Reloaded/trunk/src/mame/video/combatsc.c | [
"Unlicense"
] | C | bootleg_draw_sprites | void | static void bootleg_draw_sprites( running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, const UINT8 *source, int circuit )
{
const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
const gfx_element *gfx = machine->gfx[circuit + 2];
int limit = circuit ? (memory_read_byte(space, 0xc2) * 256 + memory_read_byte(space, 0xc3)) : (memory_read_byte(space, 0xc0) * 256 + memory_read_byte(space, 0xc1));
const UINT8 *finish;
source += 0x1000;
finish = source;
source += 0x400;
limit = (0x3400 - limit) / 8;
if (limit >= 0)
finish = source - limit * 8;
source -= 8;
while (source > finish)
{
UINT8 attributes = source[3]; /* PBxF ?xxX */
{
int number = source[0];
int x = source[2] - 71 + (attributes & 0x01)*256;
int y = 242 - source[1];
UINT8 color = source[4]; /* CCCC xxBB */
int bank = (color & 0x03) | ((attributes & 0x40) >> 4);
number = ((number & 0x02) << 1) | ((number & 0x04) >> 1) | (number & (~6));
number += 256 * bank;
color = (circuit * 4) * 16 + (color >> 4);
/* hacks to select alternate palettes */
// if(state->vreg == 0x40 && (attributes & 0x40)) color += 1*16;
// if(state->vreg == 0x23 && (attributes & 0x02)) color += 1*16;
// if(state->vreg == 0x66 ) color += 2*16;
drawgfx_transpen( bitmap, cliprect, gfx,
number, color,
attributes & 0x10,0, /* flip */
x,y, 15 );
}
source -= 8;
}
} | /***************************************************************************
bootleg Combat School sprites. Each sprite has 5 bytes:
byte #0: sprite number
byte #1: y position
byte #2: x position
byte #3:
bit 0: x position (bit 0)
bits 1..3: ???
bit 4: flip x
bit 5: unused?
bit 6: sprite bank # (bit 2)
bit 7: ???
byte #4:
bits 0,1: sprite bank # (bits 0 & 1)
bits 2,3: unused?
bits 4..7: sprite color
***************************************************************************/ | bootleg Combat School sprites. Each sprite has 5 bytes.
| [
"bootleg",
"Combat",
"School",
"sprites",
".",
"Each",
"sprite",
"has",
"5",
"bytes",
"."
] | static void bootleg_draw_sprites( running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, const UINT8 *source, int circuit )
{
const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
const gfx_element *gfx = machine->gfx[circuit + 2];
int limit = circuit ? (memory_read_byte(space, 0xc2) * 256 + memory_read_byte(space, 0xc3)) : (memory_read_byte(space, 0xc0) * 256 + memory_read_byte(space, 0xc1));
const UINT8 *finish;
source += 0x1000;
finish = source;
source += 0x400;
limit = (0x3400 - limit) / 8;
if (limit >= 0)
finish = source - limit * 8;
source -= 8;
while (source > finish)
{
UINT8 attributes = source[3];
{
int number = source[0];
int x = source[2] - 71 + (attributes & 0x01)*256;
int y = 242 - source[1];
UINT8 color = source[4];
int bank = (color & 0x03) | ((attributes & 0x40) >> 4);
number = ((number & 0x02) << 1) | ((number & 0x04) >> 1) | (number & (~6));
number += 256 * bank;
color = (circuit * 4) * 16 + (color >> 4);
drawgfx_transpen( bitmap, cliprect, gfx,
number, color,
attributes & 0x10,0,
x,y, 15 );
}
source -= 8;
}
} | [
"static",
"void",
"bootleg_draw_sprites",
"(",
"running_machine",
"*",
"machine",
",",
"bitmap_t",
"*",
"bitmap",
",",
"const",
"rectangle",
"*",
"cliprect",
",",
"const",
"UINT8",
"*",
"source",
",",
"int",
"circuit",
")",
"{",
"const",
"address_space",
"*",
"space",
"=",
"cputag_get_address_space",
"(",
"machine",
",",
"\"",
"\"",
",",
"ADDRESS_SPACE_PROGRAM",
")",
";",
"const",
"gfx_element",
"*",
"gfx",
"=",
"machine",
"->",
"gfx",
"[",
"circuit",
"+",
"2",
"]",
";",
"int",
"limit",
"=",
"circuit",
"?",
"(",
"memory_read_byte",
"(",
"space",
",",
"0xc2",
")",
"*",
"256",
"+",
"memory_read_byte",
"(",
"space",
",",
"0xc3",
")",
")",
":",
"(",
"memory_read_byte",
"(",
"space",
",",
"0xc0",
")",
"*",
"256",
"+",
"memory_read_byte",
"(",
"space",
",",
"0xc1",
")",
")",
";",
"const",
"UINT8",
"*",
"finish",
";",
"source",
"+=",
"0x1000",
";",
"finish",
"=",
"source",
";",
"source",
"+=",
"0x400",
";",
"limit",
"=",
"(",
"0x3400",
"-",
"limit",
")",
"/",
"8",
";",
"if",
"(",
"limit",
">=",
"0",
")",
"finish",
"=",
"source",
"-",
"limit",
"*",
"8",
";",
"source",
"-=",
"8",
";",
"while",
"(",
"source",
">",
"finish",
")",
"{",
"UINT8",
"attributes",
"=",
"source",
"[",
"3",
"]",
";",
"{",
"int",
"number",
"=",
"source",
"[",
"0",
"]",
";",
"int",
"x",
"=",
"source",
"[",
"2",
"]",
"-",
"71",
"+",
"(",
"attributes",
"&",
"0x01",
")",
"*",
"256",
";",
"int",
"y",
"=",
"242",
"-",
"source",
"[",
"1",
"]",
";",
"UINT8",
"color",
"=",
"source",
"[",
"4",
"]",
";",
"int",
"bank",
"=",
"(",
"color",
"&",
"0x03",
")",
"|",
"(",
"(",
"attributes",
"&",
"0x40",
")",
">>",
"4",
")",
";",
"number",
"=",
"(",
"(",
"number",
"&",
"0x02",
")",
"<<",
"1",
")",
"|",
"(",
"(",
"number",
"&",
"0x04",
")",
">>",
"1",
")",
"|",
"(",
"number",
"&",
"(",
"~",
"6",
")",
")",
";",
"number",
"+=",
"256",
"*",
"bank",
";",
"color",
"=",
"(",
"circuit",
"*",
"4",
")",
"*",
"16",
"+",
"(",
"color",
">>",
"4",
")",
";",
"drawgfx_transpen",
"(",
"bitmap",
",",
"cliprect",
",",
"gfx",
",",
"number",
",",
"color",
",",
"attributes",
"&",
"0x10",
",",
"0",
",",
"x",
",",
"y",
",",
"15",
")",
";",
"}",
"source",
"-=",
"8",
";",
"}",
"}"
] | bootleg Combat School sprites. | [
"bootleg",
"Combat",
"School",
"sprites",
"."
] | [
"/* PBxF ?xxX */",
"/* CCCC xxBB */",
"/* hacks to select alternate palettes */",
"// if(state->vreg == 0x40 && (attributes & 0x40)) color += 1*16;\r",
"// if(state->vreg == 0x23 && (attributes & 0x02)) color += 1*16;\r",
"// if(state->vreg == 0x66 ) color += 2*16;\r",
"/* flip */"
] | [
{
"param": "machine",
"type": "running_machine"
},
{
"param": "bitmap",
"type": "bitmap_t"
},
{
"param": "cliprect",
"type": "rectangle"
},
{
"param": "source",
"type": "UINT8"
},
{
"param": "circuit",
"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": "source",
"type": "UINT8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "circuit",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
3b9c8b36e31aa5351db042d88ad0d18f103ccbf6 | lofunz/mieme | Reloaded/trunk/src/mame/drivers/igs017.c | [
"Unlicense"
] | C | expand_sprites | void | static void expand_sprites(running_machine *machine)
{
UINT8 *rom = memory_region(machine, "sprites");
int size = memory_region_length(machine, "sprites");
int i;
sprites_gfx_size = size / 2 * 3;
sprites_gfx = auto_alloc_array(machine, UINT8, sprites_gfx_size);
for (i = 0; i < size / 2 ; i++)
{
UINT16 pens = (rom[i*2+1] << 8) | rom[i*2];
sprites_gfx[i * 3 + 0] = (pens >> 0) & 0x1f;
sprites_gfx[i * 3 + 1] = (pens >> 5) & 0x1f;
sprites_gfx[i * 3 + 2] = (pens >> 10) & 0x1f;
}
} | // Eeach 16 bit word in the sprites gfx roms contains three 5 bit pens: x-22222-11111-00000.
// This routine expands each word into three bytes.
| Eeach 16 bit word in the sprites gfx roms contains three 5 bit pens: x-22222-11111-00000.
This routine expands each word into three bytes. | [
"Eeach",
"16",
"bit",
"word",
"in",
"the",
"sprites",
"gfx",
"roms",
"contains",
"three",
"5",
"bit",
"pens",
":",
"x",
"-",
"22222",
"-",
"11111",
"-",
"00000",
".",
"This",
"routine",
"expands",
"each",
"word",
"into",
"three",
"bytes",
"."
] | static void expand_sprites(running_machine *machine)
{
UINT8 *rom = memory_region(machine, "sprites");
int size = memory_region_length(machine, "sprites");
int i;
sprites_gfx_size = size / 2 * 3;
sprites_gfx = auto_alloc_array(machine, UINT8, sprites_gfx_size);
for (i = 0; i < size / 2 ; i++)
{
UINT16 pens = (rom[i*2+1] << 8) | rom[i*2];
sprites_gfx[i * 3 + 0] = (pens >> 0) & 0x1f;
sprites_gfx[i * 3 + 1] = (pens >> 5) & 0x1f;
sprites_gfx[i * 3 + 2] = (pens >> 10) & 0x1f;
}
} | [
"static",
"void",
"expand_sprites",
"(",
"running_machine",
"*",
"machine",
")",
"{",
"UINT8",
"*",
"rom",
"=",
"memory_region",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"int",
"size",
"=",
"memory_region_length",
"(",
"machine",
",",
"\"",
"\"",
")",
";",
"int",
"i",
";",
"sprites_gfx_size",
"=",
"size",
"/",
"2",
"*",
"3",
";",
"sprites_gfx",
"=",
"auto_alloc_array",
"(",
"machine",
",",
"UINT8",
",",
"sprites_gfx_size",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"size",
"/",
"2",
";",
"i",
"++",
")",
"{",
"UINT16",
"pens",
"=",
"(",
"rom",
"[",
"i",
"*",
"2",
"+",
"1",
"]",
"<<",
"8",
")",
"|",
"rom",
"[",
"i",
"*",
"2",
"]",
";",
"sprites_gfx",
"[",
"i",
"*",
"3",
"+",
"0",
"]",
"=",
"(",
"pens",
">>",
"0",
")",
"&",
"0x1f",
";",
"sprites_gfx",
"[",
"i",
"*",
"3",
"+",
"1",
"]",
"=",
"(",
"pens",
">>",
"5",
")",
"&",
"0x1f",
";",
"sprites_gfx",
"[",
"i",
"*",
"3",
"+",
"2",
"]",
"=",
"(",
"pens",
">>",
"10",
")",
"&",
"0x1f",
";",
"}",
"}"
] | Eeach 16 bit word in the sprites gfx roms contains three 5 bit pens: x-22222-11111-00000. | [
"Eeach",
"16",
"bit",
"word",
"in",
"the",
"sprites",
"gfx",
"roms",
"contains",
"three",
"5",
"bit",
"pens",
":",
"x",
"-",
"22222",
"-",
"11111",
"-",
"00000",
"."
] | [] | [
{
"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": []
} |
3b9c8b36e31aa5351db042d88ad0d18f103ccbf6 | lofunz/mieme | Reloaded/trunk/src/mame/drivers/igs017.c | [
"Unlicense"
] | C | debug_viewer | int | static int debug_viewer(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect)
{
#ifdef MAME_DEBUG
if (input_code_pressed_once(machine, KEYCODE_T)) toggle = 1-toggle;
if (toggle) {
int h = 256, w = debug_width, a = debug_addr;
if (input_code_pressed(machine, KEYCODE_O)) w += 1;
if (input_code_pressed(machine, KEYCODE_I)) w -= 1;
if (input_code_pressed(machine, KEYCODE_U)) w += 8;
if (input_code_pressed(machine, KEYCODE_Y)) w -= 8;
if (input_code_pressed(machine, KEYCODE_RIGHT)) a += 1;
if (input_code_pressed(machine, KEYCODE_LEFT)) a -= 1;
if (input_code_pressed(machine, KEYCODE_DOWN)) a += w;
if (input_code_pressed(machine, KEYCODE_UP)) a -= w;
if (input_code_pressed(machine, KEYCODE_PGDN)) a += w * h;
if (input_code_pressed(machine, KEYCODE_PGUP)) a -= w * h;
if (a < 0) a = 0;
if (a > sprites_gfx_size) a = sprites_gfx_size;
if (w <= 0) w = 0;
if (w > 1024) w = 1024;
bitmap_fill(bitmap,cliprect,0);
draw_sprite(machine, bitmap, cliprect, 0,0, w,h, 0,0, 0, a);
popmessage("a: %08X w: %03X p: %02X-%02x-%02x",a,w,sprites_gfx[a/3*3+0],sprites_gfx[a/3*3+1],sprites_gfx[a/3*3+2]);
debug_addr = a;
debug_width = w;
osd_sleep(200000);
return 1;
}
#endif
return 0;
} | // A simple gfx viewer (toggle with T)
| A simple gfx viewer (toggle with T) | [
"A",
"simple",
"gfx",
"viewer",
"(",
"toggle",
"with",
"T",
")"
] | static int debug_viewer(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect)
{
#ifdef MAME_DEBUG
if (input_code_pressed_once(machine, KEYCODE_T)) toggle = 1-toggle;
if (toggle) {
int h = 256, w = debug_width, a = debug_addr;
if (input_code_pressed(machine, KEYCODE_O)) w += 1;
if (input_code_pressed(machine, KEYCODE_I)) w -= 1;
if (input_code_pressed(machine, KEYCODE_U)) w += 8;
if (input_code_pressed(machine, KEYCODE_Y)) w -= 8;
if (input_code_pressed(machine, KEYCODE_RIGHT)) a += 1;
if (input_code_pressed(machine, KEYCODE_LEFT)) a -= 1;
if (input_code_pressed(machine, KEYCODE_DOWN)) a += w;
if (input_code_pressed(machine, KEYCODE_UP)) a -= w;
if (input_code_pressed(machine, KEYCODE_PGDN)) a += w * h;
if (input_code_pressed(machine, KEYCODE_PGUP)) a -= w * h;
if (a < 0) a = 0;
if (a > sprites_gfx_size) a = sprites_gfx_size;
if (w <= 0) w = 0;
if (w > 1024) w = 1024;
bitmap_fill(bitmap,cliprect,0);
draw_sprite(machine, bitmap, cliprect, 0,0, w,h, 0,0, 0, a);
popmessage("a: %08X w: %03X p: %02X-%02x-%02x",a,w,sprites_gfx[a/3*3+0],sprites_gfx[a/3*3+1],sprites_gfx[a/3*3+2]);
debug_addr = a;
debug_width = w;
osd_sleep(200000);
return 1;
}
#endif
return 0;
} | [
"static",
"int",
"debug_viewer",
"(",
"running_machine",
"*",
"machine",
",",
"bitmap_t",
"*",
"bitmap",
",",
"const",
"rectangle",
"*",
"cliprect",
")",
"{",
"#ifdef",
"MAME_DEBUG",
"if",
"(",
"input_code_pressed_once",
"(",
"machine",
",",
"KEYCODE_T",
")",
")",
"toggle",
"=",
"1",
"-",
"toggle",
";",
"if",
"(",
"toggle",
")",
"{",
"int",
"h",
"=",
"256",
",",
"w",
"=",
"debug_width",
",",
"a",
"=",
"debug_addr",
";",
"if",
"(",
"input_code_pressed",
"(",
"machine",
",",
"KEYCODE_O",
")",
")",
"w",
"+=",
"1",
";",
"if",
"(",
"input_code_pressed",
"(",
"machine",
",",
"KEYCODE_I",
")",
")",
"w",
"-=",
"1",
";",
"if",
"(",
"input_code_pressed",
"(",
"machine",
",",
"KEYCODE_U",
")",
")",
"w",
"+=",
"8",
";",
"if",
"(",
"input_code_pressed",
"(",
"machine",
",",
"KEYCODE_Y",
")",
")",
"w",
"-=",
"8",
";",
"if",
"(",
"input_code_pressed",
"(",
"machine",
",",
"KEYCODE_RIGHT",
")",
")",
"a",
"+=",
"1",
";",
"if",
"(",
"input_code_pressed",
"(",
"machine",
",",
"KEYCODE_LEFT",
")",
")",
"a",
"-=",
"1",
";",
"if",
"(",
"input_code_pressed",
"(",
"machine",
",",
"KEYCODE_DOWN",
")",
")",
"a",
"+=",
"w",
";",
"if",
"(",
"input_code_pressed",
"(",
"machine",
",",
"KEYCODE_UP",
")",
")",
"a",
"-=",
"w",
";",
"if",
"(",
"input_code_pressed",
"(",
"machine",
",",
"KEYCODE_PGDN",
")",
")",
"a",
"+=",
"w",
"*",
"h",
";",
"if",
"(",
"input_code_pressed",
"(",
"machine",
",",
"KEYCODE_PGUP",
")",
")",
"a",
"-=",
"w",
"*",
"h",
";",
"if",
"(",
"a",
"<",
"0",
")",
"a",
"=",
"0",
";",
"if",
"(",
"a",
">",
"sprites_gfx_size",
")",
"a",
"=",
"sprites_gfx_size",
";",
"if",
"(",
"w",
"<=",
"0",
")",
"w",
"=",
"0",
";",
"if",
"(",
"w",
">",
"1024",
")",
"w",
"=",
"1024",
";",
"bitmap_fill",
"(",
"bitmap",
",",
"cliprect",
",",
"0",
")",
";",
"draw_sprite",
"(",
"machine",
",",
"bitmap",
",",
"cliprect",
",",
"0",
",",
"0",
",",
"w",
",",
"h",
",",
"0",
",",
"0",
",",
"0",
",",
"a",
")",
";",
"popmessage",
"(",
"\"",
"\"",
",",
"a",
",",
"w",
",",
"sprites_gfx",
"[",
"a",
"/",
"3",
"*",
"3",
"+",
"0",
"]",
",",
"sprites_gfx",
"[",
"a",
"/",
"3",
"*",
"3",
"+",
"1",
"]",
",",
"sprites_gfx",
"[",
"a",
"/",
"3",
"*",
"3",
"+",
"2",
"]",
")",
";",
"debug_addr",
"=",
"a",
";",
"debug_width",
"=",
"w",
";",
"osd_sleep",
"(",
"200000",
")",
";",
"return",
"1",
";",
"}",
"#endif",
"return",
"0",
";",
"}"
] | A simple gfx viewer (toggle with T) | [
"A",
"simple",
"gfx",
"viewer",
"(",
"toggle",
"with",
"T",
")"
] | [] | [
{
"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": []
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.