added
stringdate
2024-11-18 17:54:19
2024-11-19 03:39:31
created
timestamp[s]date
1970-01-01 00:04:39
2023-09-06 04:41:57
id
stringlengths
40
40
metadata
dict
source
stringclasses
1 value
text
stringlengths
13
8.04M
score
float64
2
4.78
int_score
int64
2
5
2024-11-18T17:59:45.382671+00:00
2018-10-26T03:19:03
c5c7d46e02467a9178c30a6a064556faefb501d7
{ "blob_id": "c5c7d46e02467a9178c30a6a064556faefb501d7", "branch_name": "refs/heads/master", "committer_date": "2018-10-26T03:19:03", "content_id": "e67dcb21c8b2658003c5371f0baa76984ecd2a5a", "detected_licenses": [ "MIT" ], "directory_id": "0e3c919dfcef7c6815e6709faabb474595723546", "extension": "c", "filename": "main.c", "fork_events_count": 0, "gha_created_at": "2018-10-26T03:18:05", "gha_event_created_at": "2018-10-26T03:18:05", "gha_language": null, "gha_license_id": "MIT", "github_id": 154771044, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2203, "license": "MIT", "license_type": "permissive", "path": "/01 - Independent Study/UTAustinX_610/TExaSware/C8_SwitchLED/main.c", "provenance": "stackv2-0000.json.gz:64953", "repo_name": "RyanTruran/EmbeddedSystems.Playground", "revision_date": "2018-10-26T03:19:03", "revision_id": "0374b601ce9138d730d15acd4071275315e316d7", "snapshot_id": "4c00fff3cbb1cfe0cbefd0b1bd53e44f5d28f10a", "src_encoding": "ISO-8859-1", "star_events_count": 0, "url": "https://raw.githubusercontent.com/RyanTruran/EmbeddedSystems.Playground/0374b601ce9138d730d15acd4071275315e316d7/01 - Independent Study/UTAustinX_610/TExaSware/C8_SwitchLED/main.c", "visit_date": "2021-09-25T21:56:03.070406" }
stackv2
/* Runs on TM4C123, Jonathan Valvano 6/17/2013 Module Number: C8 Module Title: Switch controls light Module Statement: Design two systems that include a switch and LED. The analog system includes just the switch and LED, and the digital system includes a microcontroller. The switch controls whether an LED is turned on/off using negative logic. In particular, if the switch is pressed the LED is off, and if the switch is not pressed the LED is on. Learning Objectives: • Understanding basic circuit elements like source, ground, switch, LED and resistors. • Application of Ohm’s Law • Analog circuit design and construction • Interfacing circuit elements to a microcontroller • Programming simple logic. */ // PD3 is an output to LED output, positive logic // PD0 is an input from switch, positive logic // to set the switch in the simulator type this into command window // PORTD = 1 // to release the switch in the simulator type this into command window // PORTD = 0 #define SYSCTL_RCGC2_R (*((volatile unsigned long *)0x400FE108)) #define GPIO_PORTD_DATA_R (*((volatile unsigned long *)0x400073FC)) #define GPIO_PORTD_DIR_R (*((volatile unsigned long *)0x40007400)) #define GPIO_PORTD_AFSEL_R (*((volatile unsigned long *)0x40007420)) #define GPIO_PORTD_DEN_R (*((volatile unsigned long *)0x4000751C)) #define GPIO_PORTD_AMSEL_R (*((volatile unsigned long *)0x40007528)) #define GPIO_PORTD_PCTL_R (*((volatile unsigned long *)0x4000752C)) unsigned long in,out; int main(void){ unsigned long volatile delay; SYSCTL_RCGC2_R |= 0x08; // Port D clock delay = SYSCTL_RCGC2_R; // wait 3-5 bus cycles GPIO_PORTD_DIR_R |= 0x08; // PD3 output GPIO_PORTD_DIR_R &= ~0x01; // PD0 input GPIO_PORTD_AFSEL_R &= ~0x09; // not alternative GPIO_PORTD_AMSEL_R &= ~0x09; // no analog GPIO_PORTD_PCTL_R &= ~0x0000F00F; // bits for PD3, PD0 GPIO_PORTD_DEN_R |= 0x09; // enable PD3, PD0 while(1){ in = (GPIO_PORTD_DATA_R&0x01); // in 0 if not pressed, 1 if pressed out = (in^0x01)<<3; // out 8 if not pressed, 0 if switch pressed GPIO_PORTD_DATA_R = out; } }
2.890625
3
2024-11-18T17:59:45.841807+00:00
2021-02-17T00:20:24
7b52d9ad341f3fcbe2668fecc9e742585cdf8975
{ "blob_id": "7b52d9ad341f3fcbe2668fecc9e742585cdf8975", "branch_name": "refs/heads/master", "committer_date": "2021-02-17T00:20:24", "content_id": "fac9494869fda0aa3c1c52c5801fd4206f3bfde2", "detected_licenses": [ "Apache-2.0" ], "directory_id": "30e028fe05e6f72639c9c67e628179c4bb113d41", "extension": "c", "filename": "macroexpand.C", "fork_events_count": 0, "gha_created_at": "2018-07-16T18:38:17", "gha_event_created_at": "2021-01-18T03:43:04", "gha_language": "C", "gha_license_id": "Apache-2.0", "github_id": 141178870, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 5202, "license": "Apache-2.0", "license_type": "permissive", "path": "/lib/hobbes/lang/macroexpand.C", "provenance": "stackv2-0000.json.gz:65081", "repo_name": "smunix/hobbes", "revision_date": "2021-02-17T00:20:24", "revision_id": "f0dff6e0d0c38aee704b2cb1812097a24511d009", "snapshot_id": "a9410f99c8317cd8fe94a968b550576cda4dbc1c", "src_encoding": "UTF-8", "star_events_count": 1, "url": "https://raw.githubusercontent.com/smunix/hobbes/f0dff6e0d0c38aee704b2cb1812097a24511d009/lib/hobbes/lang/macroexpand.C", "visit_date": "2021-08-01T23:54:34.080921" }
stackv2
#include <hobbes/lang/macroexpand.H> #include <hobbes/lang/tylift.H> namespace hobbes { // walk the expression tree, find all macro references, and expand them // (because this should be called after type inference, we need to preserve explicit type annotations) struct macroExpandF : public switchExprC<ExprPtr> { static ExprPtr mk(const QualTypePtr& qty, Expr* out) { out->type(qty); return ExprPtr(out); } static ExprPtr mk(const MonoTypePtr& mty, Expr* out) { return mk(qualtype(mty), out); } static ExprPtr mk(const Expr* src, Expr* out) { return mk(src->type(), out); } ExprPtr withConst(const Expr* v) const { return mk(v, v->clone()); } ExprPtr with(const Fn* v) const { return mk(v, new Fn(v->varNames(), switchOf(v->body(), *this), v->la())); } ExprPtr with(const MkArray* v) const { return mk(v, new MkArray(switchOf(v->values(), *this), v->la())); } ExprPtr with(const MkVariant* v) const { return mk(v, new MkVariant(v->label(), switchOf(v->value(), *this), v->la())); } ExprPtr with(const MkRecord* v) const { return mk(v, new MkRecord(switchOf(v->fields(), *this), v->la())); } ExprPtr with(const AIndex* v) const { return mk(v, new AIndex(switchOf(v->array(), *this), switchOf(v->index(), *this), v->la())); } ExprPtr with(const Proj* v) const { return mk(v, new Proj(switchOf(v->record(), *this), v->field(), v->la())); } ExprPtr with(const Assump* v) const { return mk(v, new Assump(switchOf(v->expr(), *this), v->ty(), v->la())); } ExprPtr with(const Case* v) const { ExprPtr de = v->defaultExpr(); if (de.get()) { de = switchOf(de, *this); } return mk(v, new Case(switchOf(v->variant(), *this), switchOf(v->bindings(), *this), de, v->la())); } ExprPtr with(const Switch* v) const { ExprPtr de = v->defaultExpr(); if (de) { de = switchOf(de, *this); } return mk(v, new Switch(switchOf(v->expr(), *this), switchOf(v->bindings(), *this), de, v->la())); } ExprPtr with(const Var* v) const { if (v->value() == "and") { return macroEtaLiftAnd(v->la()); } else if (v->value() == "or") { return macroEtaLiftOr(v->la()); } else { return mk(v, v->clone()); } } ExprPtr with(const Let* v) const { return mk(v, new Let(v->var(), switchOf(v->varExpr(), *this), switchOf(v->bodyExpr(), *this), v->la())); } ExprPtr with(const LetRec* v) const { LetRec::Bindings bs; for (const auto& b : v->bindings()) { bs.push_back(LetRec::Binding(b.first, switchOf(b.second, *this))); } return mk(v, new LetRec(bs, switchOf(v->bodyExpr(), *this), v->la())); } ExprPtr with(const App* v) const { Var* fn = is<Var>(v->fn()); if (fn && fn->value() == "and") { return macroExpandAnd(switchOf(v->args(), *this), v->la()); } else if (fn && fn->value() == "or") { return macroExpandOr(switchOf(v->args(), *this), v->la()); } else { return mk(v, new App(switchOf(v->fn(), *this), switchOf(v->args(), *this), v->la())); } } ExprPtr with(const Assign* v) const { return mk(v, new Assign(switchOf(v->left(), *this), switchOf(v->right(), *this), v->la())); } ExprPtr with(const Pack* v) const { return mk(v, new Pack(switchOf(v->expr(), *this), v->la())); } ExprPtr with(const Unpack* v) const { return mk(v, new Unpack(v->varName(), switchOf(v->package(), *this), switchOf(v->expr(), *this), v->la())); } // x and y = if x then y else false static ExprPtr macroExpandAnd(const Exprs& es, const LexicalAnnotation& la) { MonoTypePtr tbool = MonoTypePtr(Prim::make("bool")); QualTypePtr tbfn = qualtype(Func::make(tuplety(list(tbool, tbool, tbool)), tbool)); return mk(tbool, new App(mk(tbfn, new Var("if", la)), list(es[0], es[1], mk(tbool, new Bool(false, la))), la)); } // and => \(x,y).x and y static ExprPtr macroEtaLiftAnd(const LexicalAnnotation& la) { MonoTypePtr tbool = MonoTypePtr(Prim::make("bool")); QualTypePtr tafn = qualtype(Func::make(tuplety(list(tbool, tbool)), tbool)); return mk(tafn, new Fn(list<std::string>("x", "y"), macroExpandAnd(list(mk(tbool, new Var("x", la)), mk(tbool, new Var("y", la))), la), la)); } // x or y = if x then true else y static ExprPtr macroExpandOr(const Exprs& es, const LexicalAnnotation& la) { MonoTypePtr tbool = MonoTypePtr(Prim::make("bool")); QualTypePtr tbfn = qualtype(Func::make(tuplety(list(tbool, tbool, tbool)), tbool)); return mk(tbool, new App(mk(tbfn, new Var("if", la)), list(es[0], mk(tbool, new Bool(true, la)), es[1]), la)); } // or => \(x,y).x or y static ExprPtr macroEtaLiftOr(const LexicalAnnotation& la) { MonoTypePtr tbool = MonoTypePtr(Prim::make("bool")); QualTypePtr tafn = qualtype(Func::make(tuplety(list(tbool, tbool)), tbool)); return mk(tafn, new Fn(list<std::string>("x", "y"), macroExpandOr(list(mk(tbool, new Var("x", la)), mk(tbool, new Var("y", la))), la), la)); } }; ExprPtr macroExpand(const ExprPtr& e) { return switchOf(e, macroExpandF()); } void initMacroEnvironment(const TEnvPtr& tenv) { tenv->bind("and", prim<bool(bool,bool)>()); tenv->bind("or", prim<bool(bool,bool)>()); } }
2.171875
2
2024-11-18T17:59:45.921353+00:00
2019-01-23T15:06:00
6876d9197d7b19644ccb99e46586273d1aa1add8
{ "blob_id": "6876d9197d7b19644ccb99e46586273d1aa1add8", "branch_name": "refs/heads/master", "committer_date": "2019-01-23T15:06:00", "content_id": "d215f6d0cae9785c5dffbf3ce9f5758046683382", "detected_licenses": [ "MIT" ], "directory_id": "4ab196d49cdeeca362d394464adc7572f3e9f0ea", "extension": "c", "filename": "wait.c", "fork_events_count": 3, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 162658011, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1726, "license": "MIT", "license_type": "permissive", "path": "/Assignments/PA0/CSC501-PA0/csc501-lab0/TMP/wait.c", "provenance": "stackv2-0000.json.gz:65209", "repo_name": "jubeenshah/CSC501-Operating-System", "revision_date": "2019-01-23T15:06:00", "revision_id": "9e6fdf6bdcf2a462f6fe6d0fa48b1b77f74b0ff0", "snapshot_id": "60875bf379540eff378a924116c69ed375bc610d", "src_encoding": "UTF-8", "star_events_count": 1, "url": "https://raw.githubusercontent.com/jubeenshah/CSC501-Operating-System/9e6fdf6bdcf2a462f6fe6d0fa48b1b77f74b0ff0/Assignments/PA0/CSC501-PA0/csc501-lab0/TMP/wait.c", "visit_date": "2020-04-12T17:48:36.918892" }
stackv2
/* wait.c - wait */ #include <conf.h> #include <kernel.h> #include <proc.h> #include <q.h> #include <sem.h> #include <stdio.h> #include "lab0.h" extern int summarizeProcess; /*------------------------------------------------------------------------ * wait -- make current process wait on a semaphore *------------------------------------------------------------------------ */ SYSCALL wait(int sem) { STATWORD ps; struct sentry *sptr; struct pentry *pptr; unsigned int timeTaken; unsigned int startTime = ctr1000; if(!summarizeProcess) { globalTableSystemCall[currpid][WAIT].systemCallName = "sys_wait"; globalTableSystemCall[currpid][WAIT].systemCallFrequency = globalTableSystemCall[currpid][WAIT].systemCallFrequency + 1; } disable(ps); if (isbadsem(sem) || (sptr= &semaph[sem])->sstate==SFREE) { restore(ps); timeTaken = ctr1000 - startTime; globalTableSystemCall[currpid][WAIT].systemCallAverageExecTime = globalTableSystemCall[currpid][WAIT].systemCallAverageExecTime + timeTaken; return(SYSERR); } if (--(sptr->semcnt) < 0) { (pptr = &proctab[currpid])->pstate = PRWAIT; pptr->psem = sem; enqueue(currpid,sptr->sqtail); pptr->pwaitret = OK; resched(); restore(ps); timeTaken = ctr1000 - startTime; globalTableSystemCall[currpid][WAIT].systemCallAverageExecTime = globalTableSystemCall[currpid][WAIT].systemCallAverageExecTime + timeTaken; return pptr->pwaitret; } restore(ps); timeTaken = ctr1000 - startTime; globalTableSystemCall[currpid][WAIT].systemCallAverageExecTime = globalTableSystemCall[currpid][WAIT].systemCallAverageExecTime + timeTaken; return(OK); }
2.390625
2
2024-11-18T19:30:25.939406+00:00
2018-12-10T14:51:58
071eb1496330973268412f256571397a45f08fa8
{ "blob_id": "071eb1496330973268412f256571397a45f08fa8", "branch_name": "refs/heads/master", "committer_date": "2018-12-10T15:56:35", "content_id": "c2f473c4909e61bf456aa21a392e5cd9ffae5319", "detected_licenses": [ "BSD-2-Clause", "BSD-3-Clause" ], "directory_id": "293b19349d4bed21bcb15a7894dac8134494321b", "extension": "h", "filename": "advent.h", "fork_events_count": 2, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 163318031, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 11205, "license": "BSD-2-Clause,BSD-3-Clause", "license_type": "permissive", "path": "/advent.h", "provenance": "stackv2-0003.json.gz:159291", "repo_name": "AaronTraas/open-adventure", "revision_date": "2018-12-10T14:51:58", "revision_id": "8c6593ad0c06b58c2343869b7e1394645caa474a", "snapshot_id": "d7c4044193d1c14bd9a21e2dac89d4f566e65278", "src_encoding": "UTF-8", "star_events_count": 7, "url": "https://raw.githubusercontent.com/AaronTraas/open-adventure/8c6593ad0c06b58c2343869b7e1394645caa474a/advent.h", "visit_date": "2020-04-13T16:19:07.180265" }
stackv2
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <stdarg.h> #include <inttypes.h> #include "dungeon.h" /* LCG PRNG parameters tested against * Knuth vol. 2. by the original authors */ #define LCG_A 1093L #define LCG_C 221587L #define LCG_M 1048576L #define LINESIZE 1024 #define TOKLEN 5 // № sigificant characters in a token */ #define NDWARVES 6 // number of dwarves #define PIRATE NDWARVES // must be NDWARVES-1 when zero-origin #define DALTLC LOC_NUGGET // alternate dwarf location #define INVLIMIT 7 // inverntory limit (№ of objects) #define INTRANSITIVE -1 // illegal object number #define GAMELIMIT 330 // base limit of turns #define NOVICELIMIT 1000 // limit of turns for novice #define WARNTIME 30 // late game starts at game.limit-this #define FLASHTIME 50 // turns from first warning till blinding flash #define PANICTIME 15 // time left after closing #define BATTERYLIFE 2500 // turn limit increment from batteries #define WORD_NOT_FOUND -1 // "Word not found" flag value for the vocab hash functions. #define WORD_EMPTY 0 // "Word empty" flag value for the vocab hash functions #define CARRIED -1 // Player is toting it #define READ_MODE "rb" // b is not needed for POSIX but harmless #define WRITE_MODE "wb" // b is not needed for POSIX but harmless /* Special object-state values - integers > 0 are object-specific */ #define STATE_NOTFOUND -1 // 'Not found" state of treasures */ #define STATE_FOUND 0 // After discovered, before messed with #define STATE_IN_CAVITY 1 // State value common to all gemstones /* Special fixed object-state values - integers > 0 are location */ #define IS_FIXED -1 #define IS_FREE 0 /* Map a state property value to a negative range, where the object cannot be * picked up but the value can be recovered later. Avoid colliding with -1, * which has its own meaning. */ #define STASHED(obj) (-1 - game.prop[obj]) /* * DESTROY(N) = Get rid of an item by putting it in LOC_NOWHERE * MOD(N,M) = Arithmetic modulus * TOTING(OBJ) = true if the OBJ is being carried * AT(OBJ) = true if on either side of two-placed object * HERE(OBJ) = true if the OBJ is at "LOC" (or is being carried) * CNDBIT(L,N) = true if COND(L) has bit n set (bit 0 is units bit) * LIQUID() = object number of liquid in bottle * LIQLOC(LOC) = object number of liquid (if any) at LOC * FORCED(LOC) = true if LOC moves without asking for input (COND=2) * DARK(LOC) = true if location "LOC" is dark * PCT(N) = true N% of the time (N integer from 0 to 100) * GSTONE(OBJ) = true if OBJ is a gemstone * FOREST(LOC) = true if LOC is part of the forest * OUTSID(LOC) = true if locaiton not in the cave * INSIDE(LOC) = true if locaiton is in the cave or the building at the beginning of the game * INDEEP(LOC) = true if locaiton is in the Hall of Mists or deeper * BUG(X) = report bug and exit */ #define DESTROY(N) move(N, LOC_NOWHERE) #define MOD(N,M) ((N) % (M)) #define TOTING(OBJ) (game.place[OBJ] == CARRIED) #define AT(OBJ) (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc) #define HERE(OBJ) (AT(OBJ) || TOTING(OBJ)) #define CNDBIT(L,N) (tstbit(conditions[L],N)) #define LIQUID() (game.prop[BOTTLE] == WATER_BOTTLE? WATER : game.prop[BOTTLE] == OIL_BOTTLE ? OIL : NO_OBJECT ) #define LIQLOC(LOC) (CNDBIT((LOC),COND_FLUID)? CNDBIT((LOC),COND_OILY) ? OIL : WATER : NO_OBJECT) #define FORCED(LOC) CNDBIT(LOC, COND_FORCED) #define DARK(DUMMY) (!CNDBIT(game.loc,COND_LIT) && (game.prop[LAMP] == LAMP_DARK || !HERE(LAMP))) #define PCT(N) (randrange(100) < (N)) #define GSTONE(OBJ) ((OBJ) == EMERALD || (OBJ) == RUBY || (OBJ) == AMBER || (OBJ) == SAPPH) #define FOREST(LOC) CNDBIT(LOC, COND_FOREST) #define OUTSID(LOC) (CNDBIT(LOC, COND_ABOVE) || FOREST(LOC)) #define INSIDE(LOC) (!OUTSID(LOC) || LOC == LOC_BUILDING) #define INDEEP(LOC) ((LOC) >= LOC_MISTHALL && !OUTSID(LOC)) #define BUG(x) bug(x, #x) enum bugtype { SPECIAL_TRAVEL_500_GT_L_GT_300_EXCEEDS_GOTO_LIST, VOCABULARY_TYPE_N_OVER_1000_NOT_BETWEEN_0_AND_3, INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST, TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST, CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION, LOCATION_HAS_NO_TRAVEL_ENTRIES, HINT_NUMBER_EXCEEDS_GOTO_LIST, SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN, ACTION_RETURNED_PHASE_CODE_BEYOND_END_OF_SWITCH, }; enum speaktype {touch, look, hear, study, change}; enum termination {endgame, quitgame, scoregame}; enum speechpart {unknown, intransitive, transitive}; typedef enum {NO_WORD_TYPE, MOTION, OBJECT, ACTION, NUMERIC} word_type_t; typedef enum scorebonus {none, splatter, defeat, victory} score_t; /* Phase codes for action returns. * These were at one time FORTRAN line numbers. * The values don't matter, but perturb their order at your peril. */ typedef enum { GO_TERMINATE, GO_MOVE, GO_TOP, GO_CLEAROBJ, GO_CHECKHINT, GO_WORD2, GO_UNKNOWN, GO_DWARFWAKE, } phase_codes_t; typedef long vocab_t; // index into a vocabulary array */ typedef long verb_t; // index into an actions array */ typedef long obj_t; // index into the object array */ typedef long loc_t; // index into the locations array */ typedef long turn_t; // turn counter or threshold */ struct game_t { int32_t lcg_x; long abbnum; // How often to print long descriptions score_t bonus; // What kind of finishing bonus we are getting loc_t chloc; // pirate chest location loc_t chloc2; // pirate chest alternate location turn_t clock1; // # turns from finding last treasure to close turn_t clock2; // # turns from warning till blinding flash bool clshnt; // has player read the clue in the endgame? bool closed; // whether we're all the way closed bool closng; // whether it's closing time yet bool lmwarn; // has player been warned about lamp going dim? bool novice; // asked for instructions at start-up? bool panic; // has player found out he's trapped? bool wzdark; // whether the loc he's leaving was dark bool blooded; // has player drunk of dragon's blood? long conds; // min value for cond[loc] if loc has any hints long detail; // level of detail in descriptions /* dflag controls the level of activation of dwarves: * 0 No dwarf stuff yet (wait until reaches Hall Of Mists) * 1 Reached Hall Of Mists, but hasn't met first dwarf * 2 Met first dwarf, others start moving, no knives thrown yet * 3 A knife has been thrown (first set always misses) * 3+ Dwarves are mad (increases their accuracy) */ long dflag; long dkill; // dwarves killed long dtotal; // total dwarves (including pirate) in loc long foobar; // progress in saying "FEE FIE FOE FOO". long holdng; // number of objects being carried long igo; // # uses of "go" instead of a direction long iwest; // # times he's said "west" instead of "w" long knfloc; // knife location; 0 if none, -1 after caveat turn_t limit; // lifetime of lamp loc_t loc; // where player is now loc_t newloc; // where player is going turn_t numdie; // number of times killed so far loc_t oldloc; // where player was loc_t oldlc2; // where player was two moves ago obj_t oldobj; // last object player handled long saved; // point penalty for saves long tally; // count of treasures gained long thresh; // current threshold for endgame scoring tier turn_t trndex; // FIXME: not used, remove on next format bump turn_t trnluz; // # points lost so far due to turns used turn_t turns; // counts commands given (ignores yes/no) char zzword[TOKLEN + 1]; // randomly generated magic word from bird long abbrev[NLOCATIONS + 1]; // has location been seen? long atloc[NLOCATIONS + 1]; // head of object linked list per location long dseen[NDWARVES + 1]; // true if dwarf has seen him loc_t dloc[NDWARVES + 1]; // location of dwarves, initially hard-wired in loc_t odloc[NDWARVES + 1]; // prior loc of each dwarf, initially garbage loc_t fixed[NOBJECTS + 1]; // fixed location of object (if not IS_FREE) obj_t link[NOBJECTS * 2 + 1]; // object-list links loc_t place[NOBJECTS + 1]; // location of object long hinted[NHINTS]; // hinted[i] = true iff hint i has been used. long hintlc[NHINTS]; // hintlc[i] = how long at LOC with cond bit i long prop[NOBJECTS + 1]; // object state array */ }; /* * Game application settings - settings, but not state of the game, per se. * This data is not saved in a saved game. */ struct settings_t { FILE *logfp; bool oldstyle; bool prompt; }; typedef struct { char raw[LINESIZE]; vocab_t id; word_type_t type; } command_word_t; typedef enum {EMPTY, RAW, TOKENIZED, GIVEN, PREPROCESSED, PROCESSING, EXECUTED} command_state_t; typedef struct { enum speechpart part; command_word_t word[2]; verb_t verb; obj_t obj; command_state_t state; } command_t; extern struct game_t game; extern struct settings_t settings; extern bool get_command_input(command_t *); extern void clear_command(command_t *); extern void speak(const char*, ...); extern void sspeak(int msg, ...); extern void pspeak(vocab_t, enum speaktype, bool, int, ...); extern void rspeak(vocab_t, ...); extern void echo_input(FILE*, const char*, const char*); extern bool silent_yes(void); extern bool yes(const char*, const char*, const char*); extern void juggle(obj_t); extern void move(obj_t, loc_t); extern loc_t put(obj_t, long, long); extern void carry(obj_t, loc_t); extern void drop(obj_t, loc_t); extern int atdwrf(loc_t); extern long setbit(int); extern bool tstbit(long, int); extern void set_seed(int32_t); extern int32_t randrange(int32_t); extern long score(enum termination); extern void terminate(enum termination) __attribute__((noreturn)); extern int savefile(FILE *, int32_t); extern int suspend(void); extern int resume(void); extern int restore(FILE *); extern long initialise(void); extern phase_codes_t action(command_t); extern void state_change(obj_t, int); extern bool is_valid(struct game_t); void bug(enum bugtype, const char *) __attribute__((__noreturn__)); /* represent an empty command word */ static const command_word_t empty_command_word = { .raw = "", .id = WORD_EMPTY, .type = NO_WORD_TYPE, }; /* end */
2.015625
2
2024-11-18T19:30:26.377139+00:00
2020-06-08T20:55:15
96df20f442b25daae66a082e362715a6de4b86fb
{ "blob_id": "96df20f442b25daae66a082e362715a6de4b86fb", "branch_name": "refs/heads/master", "committer_date": "2020-06-08T20:55:15", "content_id": "cad2f4b43fdebf4f9a4509413b9d37a6a8327feb", "detected_licenses": [ "MIT" ], "directory_id": "5e30b5d1b1178e058aeffb0344f2c54a5c1e1561", "extension": "c", "filename": "uart.c", "fork_events_count": 1, "gha_created_at": "2020-01-09T19:09:51", "gha_event_created_at": "2020-01-09T19:09:51", "gha_language": null, "gha_license_id": "MIT", "github_id": 232884384, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1055, "license": "MIT", "license_type": "permissive", "path": "/uart.c", "provenance": "stackv2-0003.json.gz:159547", "repo_name": "wieker/nrf52-cmake-blinky", "revision_date": "2020-06-08T20:55:15", "revision_id": "798986a88f42122507b259349e767c5fe886bd72", "snapshot_id": "ec2b95a01f2a7e2616eb867f8e078717ca1f44fa", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/wieker/nrf52-cmake-blinky/798986a88f42122507b259349e767c5fe886bd72/uart.c", "visit_date": "2020-12-08T04:27:00.866701" }
stackv2
// // Created by wieker on 1/17/20. // #include <legacy/nrf_drv_uart.h> #include <sdk_config.h> #include <nrf_delay.h> nrf_drv_uart_t m_uart = NRF_DRV_UART_INSTANCE(0); void uart_init() { nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG; config.pseltxd = 13; config.pselrxd = NRF_UART_PSEL_DISCONNECTED; config.pselcts = NRF_UART_PSEL_DISCONNECTED; config.pselrts = NRF_UART_PSEL_DISCONNECTED; config.baudrate = (nrf_uart_baudrate_t)NRF_LOG_BACKEND_UART_BAUDRATE; nrfx_uart_init(&m_uart.uart, (nrfx_uart_config_t const *)&config, NULL); } int main() { NRF_P0->DIRSET = 1 << 20 | 1 << 18 | 1 << 26 | 1 << 27; uart_init(); while (1) { NRF_P0->OUTSET = 1 << 20 | 1 << 18; NRF_P0->OUTCLR = 1 << 26 | 1 << 27; nrf_delay_ms(3000); NRF_P0->OUTSET = 1 << 26 | 1 << 27; NRF_P0->OUTCLR = 1 << 20 | 1 << 18; nrf_delay_ms(3000); nrfx_uart_tx(&m_uart.uart, (uint8_t *) "ok \r\n", 5); } }
2.09375
2
2024-11-18T19:30:26.554335+00:00
2017-05-08T15:19:17
07ae29750c1f685c1be4f75e2b5b2772b2395cc4
{ "blob_id": "07ae29750c1f685c1be4f75e2b5b2772b2395cc4", "branch_name": "refs/heads/master", "committer_date": "2017-05-08T15:19:17", "content_id": "e923ab3a610c48ddc436cc0d6af4242a2351bd9e", "detected_licenses": [ "ISC" ], "directory_id": "ad5fd7bb38a230bc98f76eefb065c66877a33d5c", "extension": "c", "filename": "main.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 30546105, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 7796, "license": "ISC", "license_type": "permissive", "path": "/src/sysbin/init/main.c", "provenance": "stackv2-0003.json.gz:159803", "repo_name": "Alexis211/kogata", "revision_date": "2017-05-08T15:19:17", "revision_id": "d1aed44edf1bd6ab9cc11d7c8796051a5ae8e79d", "snapshot_id": "a0b0a367384c4a4021fa9e71807fbc66d45f131e", "src_encoding": "UTF-8", "star_events_count": 2, "url": "https://raw.githubusercontent.com/Alexis211/kogata/d1aed44edf1bd6ab9cc11d7c8796051a5ae8e79d/src/sysbin/init/main.c", "visit_date": "2021-06-13T20:00:57.119319" }
stackv2
#include <string.h> #include <stdlib.h> #include <proto/launch.h> #include <kogata/syscall.h> #include <kogata/debug.h> #include <kogata/printf.h> #include <kogata/btree.h> bool loop_exec = true; pid_t giosrv_pid = 0, login_pid = 0, lx_init_pid = 0; void _parse_cmdline_iter(void* a, void* b) { dbg_printf(" '%s' -> '%s'\n", a, b); } btree_t *parse_cmdline(const char* x) { btree_t *ret = create_btree(str_key_cmp_fun, free_key_val); ASSERT(ret != 0); x = strchr(x, ' '); if (x == 0) return ret; while ((*x) != 0) { while (*x == ' ') x++; char* eq = strchr(x, '='); char* sep = strchr(x, ' '); if (sep == 0) { if (eq == 0) { btree_add(ret, strdup(x), strdup(x)); } else { btree_add(ret, strndup(x, eq - x), strdup(eq + 1)); } break; } else { if (eq == 0 || eq > sep) { btree_add(ret, strndup(x, sep - x), strndup(x, sep - x)); } else { btree_add(ret, strndup(x, eq - x), strndup(eq + 1, sep - eq - 1)); } x = sep + 1; } } btree_iter(ret, _parse_cmdline_iter); return ret; } btree_t* read_cmdline() { char cmdline_buf[256]; fd_t f = sc_open("io:/cmdline", FM_READ); if (f == 0) return 0; size_t len = sc_read(f, 0, 255, cmdline_buf); cmdline_buf[len] = 0; sc_close(f); return parse_cmdline(cmdline_buf); } void setup_sys() { fd_t sysdir_cfg = sc_open("config:/sysdir", FM_READ); if (sysdir_cfg == 0) PANIC("[init] Could not read config:/sysdir"); char buf[256]; size_t l = sc_read(sysdir_cfg, 0, 255, buf); buf[l] = 0; sc_close(sysdir_cfg); char* eol = strchr(buf, '\n'); if (eol) *eol = 0; dbg_printf("[init] Using system directory %s\n", buf); bool ok; char* sep = strchr(buf, ':'); if (sep == 0) { ok = sc_fs_subfs("sys", "root", buf, FM_READ | FM_MMAP | FM_READDIR); } else { *sep = 0; ok = sc_fs_subfs("sys", buf, sep +1, FM_READ | FM_MMAP | FM_READDIR); } if (!ok) PANIC("[init] Could not bind root:/sys to sys:/"); } void launch_giosrv(fd_pair_t *root_gip_chan) { if (giosrv_pid != 0) return; giosrv_pid = sc_new_proc(); if (giosrv_pid == 0) { PANIC("[init] Could not create process for giosrv"); } dbg_printf("[init] Setting up giosrv, pid: %d\n", giosrv_pid); bool ok; ok = sc_bind_fs(giosrv_pid, "io", "io"); if (!ok) PANIC("[init] Could not bind io:/ to giosrv"); ok = sc_bind_fs(giosrv_pid, "sys", "sys"); if (!ok) PANIC("[init] Could not bind sys:/ to giosrv"); ok = sc_bind_fs(giosrv_pid, "config", "config"); if (!ok) PANIC("[init] Could not bind config:/ to giosrv"); ok = sc_bind_fd(giosrv_pid, STD_FD_GIOSRV, root_gip_chan->a); if (!ok) PANIC("[init] Could not bind root GIP channel FD to giosrv"); ok = sc_proc_exec(giosrv_pid, "sys:/bin/giosrv.bin"); if (!ok) PANIC("[init] Could not run giosrv.bin"); dbg_printf("[init] giosrv started.\n"); } void launch_login(fd_pair_t *root_gip_chan) { if (login_pid != 0) return; login_pid = sc_new_proc(); if (login_pid == 0) { PANIC("[init] Could not create process for login"); } dbg_printf("[init] Setting up login, pid: %d\n", login_pid); bool ok; ok = sc_bind_fs(login_pid, "root", "root"); if (!ok) PANIC("[init] Could not bind root:/ to login"); ok = sc_bind_fs(login_pid, "sys", "sys"); if (!ok) PANIC("[init] Could not bind sys:/ to login"); ok = sc_bind_fs(login_pid, "config", "config"); if (!ok) PANIC("[init] Could not bind config:/ to login"); ok = sc_bind_fd(login_pid, STD_FD_GIP, root_gip_chan->b); if (!ok) PANIC("[init] Could not bind root GIP channel FD to login"); ok = sc_proc_exec(login_pid, "sys:/bin/login.bin"); if (!ok) PANIC("[init] Could not run login.bin"); dbg_printf("[init] login started.\n"); } void launch_lx_init(const char* lx_init_app, fd_pair_t *io_chan) { if (lx_init_pid != 0) return; lx_init_pid = sc_new_proc(); if (lx_init_pid == 0) { PANIC("[init] Could not create process for lx_init"); } dbg_printf("[init] Setting up lx_init, pid: %d\n", lx_init_pid); bool ok; ok = sc_bind_fs(lx_init_pid, "io", "io"); if (!ok) PANIC("[init] Could not bind io:/ to lx_init"); ok = sc_bind_fs(lx_init_pid, "root", "root"); if (!ok) PANIC("[init] Could not bind root:/ to lx_init"); ok = sc_bind_fs(lx_init_pid, "sys", "sys"); if (!ok) PANIC("[init] Could not bind sys:/ to lx_init"); ok = sc_bind_fs(lx_init_pid, "config", "config"); if (!ok) PANIC("[init] Could not bind config:/ to lx_init"); char app_path[256]; snprintf(app_path, 256, "/app/%s", lx_init_app); ok = sc_bind_subfs(lx_init_pid, "app", "sys", app_path, FM_ALL_MODES); if (!ok) PANIC("[init] Could not bind app:/ to lx_init"); ok = sc_bind_fd(lx_init_pid, STD_FD_STDOUT, io_chan->b); if (!ok) PANIC("[init] Could not bind stdout channel to lx_init"); ok = sc_bind_fd(lx_init_pid, STD_FD_STDERR, io_chan->b); if (!ok) PANIC("[init] Could not bind stderr channel to lx_init"); ok = sc_proc_exec(lx_init_pid, "sys:/bin/lx.bin"); if (!ok) PANIC("[init] Could not run lx.bin"); dbg_printf("[init] lx_init started\n"); } void dump_all(fd_t fd) { char buf[256]; while(true){ int n = sc_read(fd, 0, 255, buf); if (n > 0) { buf[n] = 0; sc_dbg_print(buf); } else { break; } } } int run_lua(const char* lx_init_app) { // Setup a channel for stdout/stderr printing fd_pair_t io_chan; io_chan = sc_make_channel(false); if (io_chan.a == 0 || io_chan.b == 0) { PANIC("[init] Could not create Lua emergency I/O channel."); } launch_lx_init(lx_init_app, &io_chan); while(true) { dump_all(io_chan.a); proc_status_t s; sc_proc_wait(0, false, &s); if (s.pid != 0) { if (s.pid == lx_init_pid) { if (!loop_exec) { dump_all(io_chan.a); PANIC("[init] lx_init died!\n"); } lx_init_pid = 0; dbg_printf("[init] lx_init_app died, restarting.\n"); launch_lx_init(lx_init_app, &io_chan); } else { ASSERT(false); } } sc_usleep(100000); } } int run_no_lua() { fd_pair_t root_gip_chan; // Setup GIP channel for communication between giosrv and login root_gip_chan = sc_make_channel(false); if (root_gip_chan.a == 0 || root_gip_chan.b == 0) { PANIC("[init] Could not create root GIP channel."); } // Launch giosrv && login launch_giosrv(&root_gip_chan); launch_login(&root_gip_chan); // Make sure no one dies while(true) { proc_status_t s; sc_proc_wait(0, false, &s); if (s.pid != 0) { if (s.pid == giosrv_pid) { if (!loop_exec) PANIC("[init] giosrv died!\n"); giosrv_pid = 0; dbg_printf("[init] giosrv died, restarting.\n"); launch_giosrv(&root_gip_chan); } else if (s.pid == login_pid) { if (!loop_exec) PANIC("[init] login died!\n"); login_pid = 0; dbg_printf("[init] login died, restarting.\n"); launch_login(&root_gip_chan); } else { ASSERT(false); } } sc_usleep(1000000); } } int main(int argc, char **argv) { dbg_print("[init] Starting up!\n"); // Read kernel cmdline btree_t *cmdline = read_cmdline(); if (cmdline == 0) PANIC("[init] Could not parse cmdline"); // setup config: if (btree_find(cmdline, "config") == 0) { PANIC("[init] No config=xxx option specified on command line"); } else { char* config = (char*)btree_find(cmdline, "config"); dbg_printf("[init] Loading system configuration: %s\n", config); ASSERT(strlen(config) < 30); char buf[50]; snprintf(buf, 50, "/config/%s", config); bool ok = sc_fs_subfs("config", "root", buf, FM_READ | FM_WRITE | FM_MMAP | FM_READDIR); if (!ok) PANIC("[init] Could not setup config:"); } // Setup sys: setup_sys(); if (btree_find(cmdline, "loop_exec") && strcmp(btree_find(cmdline, "loop_exec"), "true")) loop_exec = false; if (btree_find(cmdline, "lx_init_app")) { run_lua(btree_find(cmdline, "lx_init_app")); } else { run_no_lua(); } return 0; } /* vim: set ts=4 sw=4 tw=0 noet :*/
2.109375
2
2024-11-18T18:09:46.654755+00:00
2020-06-27T14:20:47
249fdaba9d0240359cffadbe930df2e406a38b75
{ "blob_id": "249fdaba9d0240359cffadbe930df2e406a38b75", "branch_name": "refs/heads/master", "committer_date": "2020-06-27T14:20:47", "content_id": "4154a1c7cff68b7767e0bb7d549c8e8fb3916864", "detected_licenses": [ "Unlicense" ], "directory_id": "f79574d2c4a625df0188ad5399649126b136ad7c", "extension": "h", "filename": "helpers.h", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 260780556, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1354, "license": "Unlicense", "license_type": "permissive", "path": "/src/helpers.h", "provenance": "stackv2-0003.json.gz:313552", "repo_name": "sgstechnical/portpopper", "revision_date": "2020-06-27T14:20:47", "revision_id": "4c3a8c929708029f673509984a850cd2804a194a", "snapshot_id": "70d556ea7400c44b01f504239f12dc5db7299016", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/sgstechnical/portpopper/4c3a8c929708029f673509984a850cd2804a194a/src/helpers.h", "visit_date": "2022-11-09T01:03:07.475272" }
stackv2
#ifndef _HELPERS_H_ #define _HELPERS_H_ #define GLOBAL_VARIABLE static #define INTERNAL static #define LOCAL_VARIABLE static #define INLINE inline #define KB(x) ((x)*1024) #define MB(x) ((x)*1024*1024) typedef uint32_t b32; typedef float f32; #define SETBUF() setvbuf(stdout, NULL, _IONBF, BUFSIZ) #if DEBUG_ENABLED #define DEBUG(...) printf(__VA_ARGS__) #else #define DEBUG(...) #endif #define TEMP_BUFF_SIZE(x,s) char x[s]; x[0] = 0x00 #define TEMP_BUFF(b) TEMP_BUFF_SIZE(b,1024) #define TEMP_PATH_BUFF(b) TEMP_BUFF_SIZE(b,MAX_PATH) #define EXPAND_TEMP_BUFF(b) b,(sizeof(b)) #define create_string(b,...) snprintf(b,sizeof(b),__VA_ARGS__) #define ARRAY_COUNT(x) (sizeof(x)/sizeof(x[0])) #define clearStruct(s) memory_clear((void*)&s,sizeof(s)) //############################################################################## //@ String helpers //############################################################################## void string_clear(char* str); size_t string_copy(char* d, const char* s, size_t destMax); size_t string_length(const char* string); //############################################################################## //@ Memory helpers //############################################################################## void memory_clear(void*p,size_t s); void memory_copy(void* dest, void* src, int64_t length); #endif
2.0625
2
2024-11-18T18:09:46.746201+00:00
2023-08-07T20:22:46
9facea0eae08b52fc9d5dd274179947a512d04f3
{ "blob_id": "9facea0eae08b52fc9d5dd274179947a512d04f3", "branch_name": "refs/heads/main", "committer_date": "2023-08-07T20:22:46", "content_id": "046eaac4e11e421f0e474fcc14b03d98f53874cf", "detected_licenses": [ "Zlib" ], "directory_id": "d9ea45dbc964799991b9191ae620d2f150652a3d", "extension": "h", "filename": "commandlist.c.h", "fork_events_count": 249, "gha_created_at": "2013-05-23T22:22:58", "gha_event_created_at": "2023-08-26T12:27:36", "gha_language": "C", "gha_license_id": "Zlib", "github_id": 10254751, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 14949, "license": "Zlib", "license_type": "permissive", "path": "/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/commandlist.c.h", "provenance": "stackv2-0003.json.gz:313683", "repo_name": "Kode/Kinc", "revision_date": "2023-08-07T20:22:46", "revision_id": "d90b7478b192c8270e0ee32c0c3ee18977becd7a", "snapshot_id": "6ebb1cfa11c6e9ed0e153c486f573f1d7dca5664", "src_encoding": "UTF-8", "star_events_count": 283, "url": "https://raw.githubusercontent.com/Kode/Kinc/d90b7478b192c8270e0ee32c0c3ee18977becd7a/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/commandlist.c.h", "visit_date": "2023-08-08T16:50:01.534587" }
stackv2
#include <kinc/graphics4/graphics.h> #include <kinc/graphics5/commandlist.h> #include <kinc/graphics5/constantbuffer.h> #include <kinc/graphics5/indexbuffer.h> #include <kinc/graphics5/pipeline.h> #include <kinc/graphics5/vertexbuffer.h> #include <kinc/log.h> #include <assert.h> #include <string.h> #ifdef KORE_MICROSOFT #include <malloc.h> #endif #define WRITE(type, value) \ if (list->impl.commandIndex + sizeof(type) > KINC_G5ONG4_COMMANDS_SIZE) { \ kinc_log(KINC_LOG_LEVEL_ERROR, "Trying to write too many commands to the command list."); \ return; \ } \ *(type *)(&list->impl.commands[list->impl.commandIndex]) = value; \ list->impl.commandIndex += sizeof(type); #define READ(type, var) \ if (index + sizeof(type) > KINC_G5ONG4_COMMANDS_SIZE) { \ kinc_log(KINC_LOG_LEVEL_ERROR, "Trying to read beyond the end of the command list?"); \ return; \ } \ type var = *(type *)(&list->impl.commands[index]); \ index += sizeof(type); typedef enum command { Clear, Draw, SetViewport, SetScissor, SetPipeline, SetVertexBuffers, SetIndexBuffer, SetRenderTargets, SetRenderTargetFace, DrawInstanced, SetSampler, SetTexture, SetImageTexture, SetTextureFromRenderTarget, SetTextureFromRenderTargetDepth, SetVertexConstantBuffer, SetFragmentConstantBuffer, SetBlendConstant, } command_t; void kinc_g4_pipeline_get_constant_locations(kinc_g4_pipeline_t *state, kinc_g4_constant_location_t *vertex_locations, kinc_g4_constant_location_t *fragment_locations, int *vertex_sizes, int *fragment_sizes, int *max_vertex, int *max_fragment); void kinc_g5_command_list_init(kinc_g5_command_list_t *list) {} void kinc_g5_command_list_destroy(kinc_g5_command_list_t *list) {} void kinc_g5_command_list_begin(kinc_g5_command_list_t *list) { list->impl.commandIndex = 0; } void kinc_g5_command_list_end(kinc_g5_command_list_t *list) {} void kinc_g5_command_list_clear(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget, unsigned flags, unsigned color, float depth, int stencil) { WRITE(command_t, Clear); WRITE(unsigned, flags); WRITE(unsigned, color); WRITE(float, depth); WRITE(int, stencil); } void kinc_g5_command_list_render_target_to_framebuffer_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget) {} void kinc_g5_command_list_framebuffer_to_render_target_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget) {} void kinc_g5_command_list_texture_to_render_target_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget) {} void kinc_g5_command_list_render_target_to_texture_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget) {} void kinc_g5_command_list_draw_indexed_vertices(kinc_g5_command_list_t *list) { kinc_g5_command_list_draw_indexed_vertices_from_to(list, 0, list->impl._indexCount); } void kinc_g5_command_list_draw_indexed_vertices_from_to(kinc_g5_command_list_t *list, int start, int count) { WRITE(command_t, Draw); WRITE(int, start); WRITE(int, count); } void kinc_g5_command_list_draw_indexed_vertices_instanced(kinc_g5_command_list_t *list, int instanceCount) { kinc_g5_command_list_draw_indexed_vertices_instanced_from_to(list, instanceCount, 0, list->impl._indexCount); } void kinc_g5_command_list_draw_indexed_vertices_instanced_from_to(kinc_g5_command_list_t *list, int instanceCount, int start, int count) { WRITE(command_t, DrawInstanced); WRITE(int, instanceCount); WRITE(int, start); WRITE(int, count); } void kinc_g5_command_list_viewport(kinc_g5_command_list_t *list, int x, int y, int width, int height) { WRITE(command_t, SetViewport); WRITE(int, x); WRITE(int, y); WRITE(int, width); WRITE(int, height); } void kinc_g5_command_list_scissor(kinc_g5_command_list_t *list, int x, int y, int width, int height) { WRITE(command_t, SetScissor); WRITE(int, x); WRITE(int, y); WRITE(int, width); WRITE(int, height); } void kinc_g5_command_list_disable_scissor(kinc_g5_command_list_t *list) {} void kinc_g5_command_list_set_pipeline(kinc_g5_command_list_t *list, struct kinc_g5_pipeline *pipeline) { WRITE(command_t, SetPipeline); WRITE(kinc_g5_pipeline_t *, pipeline); } void kinc_g5_command_list_set_blend_constant(kinc_g5_command_list_t *list, float r, float g, float b, float a) { WRITE(command_t, SetBlendConstant); WRITE(float, r); WRITE(float, g); WRITE(float, b); WRITE(float, a); } void kinc_g5_command_list_set_vertex_buffers(kinc_g5_command_list_t *list, struct kinc_g5_vertex_buffer **buffers, int *offsets, int count) { WRITE(command_t, SetVertexBuffers); WRITE(int, count); for (int i = 0; i < count; ++i) { WRITE(kinc_g5_vertex_buffer_t *, buffers[i]); if (offsets[i] != 0) { kinc_log(KINC_LOG_LEVEL_ERROR, "kinc_g5_command_list_set_vertex_buffers: offsets not supported"); } } } void kinc_g5_command_list_set_index_buffer(kinc_g5_command_list_t *list, struct kinc_g5_index_buffer *buffer) { WRITE(command_t, SetIndexBuffer); WRITE(kinc_g5_index_buffer_t *, buffer); list->impl._indexCount = buffer->impl.myCount; } void kinc_g5_command_list_set_render_targets(kinc_g5_command_list_t *list, struct kinc_g5_render_target **targets, int count) { WRITE(command_t, SetRenderTargets); WRITE(int, count); for (int i = 0; i < count; ++i) { WRITE(kinc_g5_render_target_t *, targets[i]); } } void kinc_g5_command_list_upload_index_buffer(kinc_g5_command_list_t *list, struct kinc_g5_index_buffer *buffer) {} void kinc_g5_command_list_upload_vertex_buffer(kinc_g5_command_list_t *list, struct kinc_g5_vertex_buffer *buffer) {} void kinc_g5_command_list_upload_texture(kinc_g5_command_list_t *list, struct kinc_g5_texture *texture) {} void kinc_g5_command_list_set_vertex_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size) { WRITE(command_t, SetVertexConstantBuffer); WRITE(kinc_g5_constant_buffer_t *, buffer); } void kinc_g5_command_list_set_fragment_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size) { WRITE(command_t, SetFragmentConstantBuffer); WRITE(kinc_g5_constant_buffer_t *, buffer); } void kinc_g5_command_list_execute(kinc_g5_command_list_t *list) { kinc_g5_pipeline_t *current_pipeline = NULL; int index = 0; while (index < list->impl.commandIndex) { READ(command_t, command); switch (command) { case Clear: { READ(unsigned, flags); READ(unsigned, color); READ(float, depth); READ(int, stencil); kinc_g4_clear(flags, color, depth, stencil); break; } case Draw: { READ(int, start); READ(int, count); kinc_g4_draw_indexed_vertices_from_to(start, count); break; } case SetViewport: { READ(int, x); READ(int, y); READ(int, width); READ(int, height); kinc_g4_viewport(x, y, width, height); break; } case SetScissor: { READ(int, x); READ(int, y); READ(int, width); READ(int, height); kinc_g4_scissor(x, y, width, height); break; } case SetPipeline: { READ(kinc_g5_pipeline_t *, pipeline); current_pipeline = pipeline; kinc_g4_set_pipeline(&pipeline->impl.pipe); break; } case SetVertexBuffers: { READ(int, count); #ifdef KORE_MICROSOFT kinc_g4_vertex_buffer_t **buffers = (kinc_g4_vertex_buffer_t **)alloca(sizeof(kinc_g4_vertex_buffer_t *) * count); #else kinc_g4_vertex_buffer_t *buffers[count]; #endif for (int i = 0; i < count; ++i) { READ(kinc_g5_vertex_buffer_t *, buffer); buffers[i] = &buffer->impl.buffer; } kinc_g4_set_vertex_buffers(buffers, count); break; } case SetIndexBuffer: { READ(kinc_g5_index_buffer_t *, buffer); kinc_g4_set_index_buffer(&buffer->impl.buffer); break; } case SetRenderTargets: { READ(int, count); #ifdef KORE_MICROSOFT kinc_g4_render_target_t **buffers = (kinc_g4_render_target_t **)alloca(sizeof(kinc_g4_render_target_t *) * count); #else kinc_g4_render_target_t *buffers[count]; #endif int first_framebuffer_index = -1; for (int i = 0; i < count; ++i) { READ(kinc_g5_render_target_t *, buffer); if (i == 0) { first_framebuffer_index = buffer->framebuffer_index; } buffers[i] = &buffer->impl.target; } if (first_framebuffer_index >= 0) { if (count > 1) { kinc_log(KINC_LOG_LEVEL_ERROR, "Rendering to backbuffer and render targets at the same time is not supported"); } kinc_g4_restore_render_target(); } else { kinc_g4_set_render_targets(buffers, count); } break; } case SetRenderTargetFace: { READ(kinc_g5_render_target_t *, target); READ(int, face); kinc_g4_set_render_target_face(&target->impl.target, face); break; } case DrawInstanced: { READ(int, instanceCount); READ(int, start); READ(int, count); kinc_g4_draw_indexed_vertices_instanced_from_to(instanceCount, start, count); break; } case SetSampler: { assert(false); // TODO break; } case SetTexture: { READ(kinc_g5_texture_unit_t, unit); READ(kinc_g5_texture_t *, texture); assert(KINC_G4_SHADER_TYPE_COUNT == KINC_G5_SHADER_TYPE_COUNT); kinc_g4_texture_unit_t g4_unit; memcpy(&g4_unit.stages[0], &unit.stages[0], KINC_G4_SHADER_TYPE_COUNT * sizeof(int)); kinc_g4_set_texture(g4_unit, &texture->impl.texture); break; } case SetImageTexture: { READ(kinc_g5_texture_unit_t, unit); READ(kinc_g5_texture_t *, texture); assert(KINC_G4_SHADER_TYPE_COUNT == KINC_G5_SHADER_TYPE_COUNT); kinc_g4_texture_unit_t g4_unit; memcpy(&g4_unit.stages[0], &unit.stages[0], KINC_G4_SHADER_TYPE_COUNT * sizeof(int)); kinc_g4_set_image_texture(g4_unit, &texture->impl.texture); break; } case SetTextureFromRenderTarget: { assert(false); // TODO break; } case SetTextureFromRenderTargetDepth: { assert(false); // TODO break; } case SetVertexConstantBuffer: { READ(kinc_g5_constant_buffer_t *, buffer); (void)buffer; (void)current_pipeline; kinc_log(KINC_LOG_LEVEL_ERROR, "Constant buffers are not supported on G5onG4 at the moment."); // if(current_pipeline == NULL) { // kinc_log(KINC_LOG_LEVEL_ERROR, "Please set the pipeline before setting constant buffers."); // } else { // kinc_g4_constant_location_t *constant_locations = current_pipeline->impl.pipe.vertex_locations; // int *sizes = current_pipeline->impl.pipe.vertex_sizes; // char *data = buffer->data; // for(int i = 0; i < current_pipeline->impl.pipe.vertex_count; ++i) { // // kinc_g4_set // // kinc_g4_set_vertex_constant_buffer(constant_locations[i], sizes[i], data); // data += sizes[i]; // } // } break; } case SetFragmentConstantBuffer: { READ(kinc_g5_constant_buffer_t *, buffer); (void)buffer; kinc_log(KINC_LOG_LEVEL_ERROR, "Constant buffers are not supported on G5onG4 at the moment."); break; } case SetBlendConstant: { READ(float, r); READ(float, g); READ(float, b); READ(float, a); kinc_g4_set_blend_constant(r, g, b, a); } default: kinc_log(KINC_LOG_LEVEL_ERROR, "Unknown command %i\n", command); return; } } } void kinc_g5_command_list_wait_for_execution_to_finish(kinc_g5_command_list_t *list) { kinc_g4_flush(); } void kinc_g5_command_list_get_render_target_pixels(kinc_g5_command_list_t *list, struct kinc_g5_render_target *render_target, uint8_t *data) { kinc_log(KINC_LOG_LEVEL_ERROR, "kinc_g5_command_list_get_render_target_pixels not implemented"); } void kinc_g5_command_list_set_render_target_face(kinc_g5_command_list_t *list, kinc_g5_render_target_t *texture, int face) { WRITE(command_t, SetRenderTargetFace); WRITE(kinc_g5_render_target_t *, texture); WRITE(int, face); } void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) { WRITE(command_t, SetTexture); WRITE(kinc_g5_texture_unit_t, unit); WRITE(kinc_g5_texture_t *, texture); } void kinc_g5_command_list_set_sampler(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_sampler_t *sampler) { WRITE(command_t, SetSampler); } void kinc_g5_command_list_set_texture_from_render_target(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_render_target_t *render_target) { WRITE(command_t, SetTextureFromRenderTarget); } void kinc_g5_command_list_set_texture_from_render_target_depth(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_render_target_t *render_target) { WRITE(command_t, SetTextureFromRenderTargetDepth); } void kinc_g5_command_list_set_image_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) { WRITE(command_t, SetImageTexture); WRITE(kinc_g5_texture_unit_t, unit); WRITE(kinc_g5_texture_t *, texture); } bool kinc_g5_command_list_init_occlusion_query(kinc_g5_command_list_t *list, unsigned *occlusionQuery) { return false; } void kinc_g5_command_list_delete_occlusion_query(kinc_g5_command_list_t *list, unsigned occlusionQuery) {} void kinc_g5_command_list_render_occlusion_query(kinc_g5_command_list_t *list, unsigned occlusionQuery, int triangles) {} bool kinc_g5_command_list_are_query_results_available(kinc_g5_command_list_t *list, unsigned occlusionQuery) { return false; } void kinc_g5_command_list_get_query_result(kinc_g5_command_list_t *list, unsigned occlusionQuery, unsigned *pixelCount) {}
2.125
2
2024-11-18T18:09:47.174766+00:00
2020-12-20T17:32:53
f1031ef481df2bdfce46cd7052bc07426e88877a
{ "blob_id": "f1031ef481df2bdfce46cd7052bc07426e88877a", "branch_name": "refs/heads/master", "committer_date": "2020-12-20T17:32:53", "content_id": "cb7f081cbb2d77398cad86b2d81dcb259f94d41f", "detected_licenses": [ "MIT" ], "directory_id": "c5f70ba06763419829e756c1a97afe46e2ccd215", "extension": "c", "filename": "ulong.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 189241832, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 5390, "license": "MIT", "license_type": "permissive", "path": "/samples/non_fatal_assert_type_operator/ulong.c", "provenance": "stackv2-0003.json.gz:314325", "repo_name": "aenachescu/nbp_old", "revision_date": "2020-12-20T17:32:53", "revision_id": "70eda61b598c4229d12c92020578da3fddd45015", "snapshot_id": "69a3848aa5b43b1f35ed9599e95a33d9833055bc", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/aenachescu/nbp_old/70eda61b598c4229d12c92020578da3fddd45015/samples/non_fatal_assert_type_operator/ulong.c", "visit_date": "2023-02-02T15:48:26.355866" }
stackv2
/* No Bugs in Production (NBP) https://github.com/aenachescu/nbp Licensed under the MIT License <http://opensource.org/licenses/MIT>. SPDX-License-Identifier: MIT Copyright (c) 2019-2020 Alin Enachescu <https://github.com/aenachescu> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include <nbp.h> #include "../sample_utils.h" #include <limits.h> unsigned long int get_ulong() { return 2UL; } volatile unsigned long int ulong_min = 0; volatile unsigned long int ulong_max = ULONG_MAX; volatile unsigned long int ulong_ = 2UL; NBP_TEST(non_fatal_assert_ulong_eq) { SAMPLE_SLEEP(); NBP_ASSERT_ULONG_EQ( get_ulong(), ulong_ ); NBP_ASSERT_ULONG_EQ( get_ulong(), ulong_, NBP_ASSERT_FAILURE_MESSAGE("non fatal assert failed") ); NBP_ASSERT_ULONG_EQ( get_ulong(), ulong_, NBP_ASSERT_SUCCESS_MESSAGE("non fatal assert passed") ); NBP_ASSERT_ULONG_EQ( get_ulong(), ulong_, NBP_ASSERT_FAILURE_MESSAGE("non fatal assert failed"), NBP_ASSERT_SUCCESS_MESSAGE("non fatal assert passed") ); } NBP_TEST(non_fatal_assert_ulong_ne) { SAMPLE_SLEEP(); NBP_ASSERT_ULONG_NE( get_ulong(), ulong_min ); NBP_ASSERT_ULONG_NE( get_ulong(), ulong_min, NBP_ASSERT_FAILURE_MESSAGE("non fatal assert failed") ); NBP_ASSERT_ULONG_NE( get_ulong(), ulong_min, NBP_ASSERT_SUCCESS_MESSAGE("non fatal assert passed") ); NBP_ASSERT_ULONG_NE( get_ulong(), ulong_min, NBP_ASSERT_FAILURE_MESSAGE("non fatal assert failed"), NBP_ASSERT_SUCCESS_MESSAGE("non fatal assert passed") ); } NBP_TEST(non_fatal_assert_ulong_gt) { SAMPLE_SLEEP(); NBP_ASSERT_ULONG_GT( get_ulong(), ulong_min ); NBP_ASSERT_ULONG_GT( get_ulong(), ulong_min, NBP_ASSERT_FAILURE_MESSAGE("non fatal assert failed") ); NBP_ASSERT_ULONG_GT( get_ulong(), ulong_min, NBP_ASSERT_SUCCESS_MESSAGE("non fatal assert passed") ); NBP_ASSERT_ULONG_GT( get_ulong(), ulong_min, NBP_ASSERT_FAILURE_MESSAGE("non fatal assert failed"), NBP_ASSERT_SUCCESS_MESSAGE("non fatal assert passed") ); } NBP_TEST(non_fatal_assert_ulong_ge) { SAMPLE_SLEEP(); NBP_ASSERT_ULONG_GE( get_ulong(), ulong_min ); NBP_ASSERT_ULONG_GE( get_ulong(), ulong_, NBP_ASSERT_FAILURE_MESSAGE("non fatal assert failed") ); NBP_ASSERT_ULONG_GE( get_ulong(), ulong_min, NBP_ASSERT_SUCCESS_MESSAGE("non fatal assert passed") ); NBP_ASSERT_ULONG_GE( get_ulong(), ulong_, NBP_ASSERT_FAILURE_MESSAGE("non fatal assert failed"), NBP_ASSERT_SUCCESS_MESSAGE("non fatal assert passed") ); } NBP_TEST(non_fatal_assert_ulong_lt) { SAMPLE_SLEEP(); NBP_ASSERT_ULONG_LT( get_ulong(), ulong_max ); NBP_ASSERT_ULONG_LT( get_ulong(), ulong_max, NBP_ASSERT_FAILURE_MESSAGE("non fatal assert failed") ); NBP_ASSERT_ULONG_LT( get_ulong(), ulong_max, NBP_ASSERT_SUCCESS_MESSAGE("non fatal assert passed") ); NBP_ASSERT_ULONG_LT( get_ulong(), ulong_max, NBP_ASSERT_FAILURE_MESSAGE("non fatal assert failed"), NBP_ASSERT_SUCCESS_MESSAGE("non fatal assert passed") ); } NBP_TEST(non_fatal_assert_ulong_le) { SAMPLE_SLEEP(); NBP_ASSERT_ULONG_LE( get_ulong(), ulong_max ); NBP_ASSERT_ULONG_LE( get_ulong(), ulong_, NBP_ASSERT_FAILURE_MESSAGE("non fatal assert failed") ); NBP_ASSERT_ULONG_LE( get_ulong(), ulong_max, NBP_ASSERT_SUCCESS_MESSAGE("non fatal assert passed") ); NBP_ASSERT_ULONG_LE( get_ulong(), ulong_, NBP_ASSERT_FAILURE_MESSAGE("non fatal assert failed"), NBP_ASSERT_SUCCESS_MESSAGE("non fatal assert passed") ); } NBP_MODULE(non_fatal_assert_ulong) { NBP_TEST_RUN(non_fatal_assert_ulong_eq); NBP_TEST_RUN(non_fatal_assert_ulong_ne); NBP_TEST_RUN(non_fatal_assert_ulong_gt); NBP_TEST_RUN(non_fatal_assert_ulong_ge); NBP_TEST_RUN(non_fatal_assert_ulong_lt); NBP_TEST_RUN(non_fatal_assert_ulong_le); }
2.078125
2
2024-11-18T18:09:47.525849+00:00
2019-03-01T05:16:46
f5a8a0c1fc2d845384820ed93d74d518f7e044b6
{ "blob_id": "f5a8a0c1fc2d845384820ed93d74d518f7e044b6", "branch_name": "refs/heads/master", "committer_date": "2019-03-01T05:16:46", "content_id": "5cfa1d3a02ad0a868f09856ee2c0e75364b6bf02", "detected_licenses": [ "MIT" ], "directory_id": "5a17a3d150c4773318d397a46878d2fd74c0671f", "extension": "c", "filename": "shenghuo-ling.c", "fork_events_count": 0, "gha_created_at": "2018-12-26T11:38:10", "gha_event_created_at": "2018-12-26T11:38:10", "gha_language": null, "gha_license_id": "MIT", "github_id": 163173406, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1304, "license": "MIT", "license_type": "permissive", "path": "/nitan/clone/book/shenghuo-ling.c", "provenance": "stackv2-0003.json.gz:314584", "repo_name": "cantona/NT6", "revision_date": "2019-03-01T05:16:46", "revision_id": "073f4d491b3cfe6bfbe02fbad12db8983c1b9201", "snapshot_id": "e9adc7308619b614990fa64456c294fad5f07d61", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/cantona/NT6/073f4d491b3cfe6bfbe02fbad12db8983c1b9201/nitan/clone/book/shenghuo-ling.c", "visit_date": "2020-04-15T21:16:28.817947" }
stackv2
// shenghuo-ling 聖火令 #include <weapon.h> #include <ansi.h> inherit SWORD; void create() { set_name("聖火令",({ "shenghuo ling", "shenghuo", "ling" }) ); set_weight(1000); if( clonep() ) set_default_object(__FILE__); else { set("unit", "把"); set("value", 10000); set("material", "steel"); set("no_drop", "1"); set("long", "這是一柄兩尺來長的黑牌,非金非鐵。質地堅硬無比,\n" "似透明,令中隱隱似有火焰飛騰,實則是令質映光,顏\n" "色變幻。令上刻得有不少波斯文字。 \n"); set("wield_msg", HIY "$N“唰”的一聲,從腰間抽出一片黑黝的鐵牌握在手中。\n"); set("unwield_msg", HIY "$N將聖火令插回腰間。\n" NOR); } set("skill", ([ "name" : "shenghuo-ling", "exp_required": 50000, "family_name" : "明教", "jing_cost" : 40, "difficulty" : 30, "max_skill" : 200, "min_skill" : 100 ]) ); init_sword(50); setup(); }
2
2
2024-11-18T18:09:47.619618+00:00
2021-03-28T07:27:07
5fe71d831ffb33666eaaab8d13b589491f1df646
{ "blob_id": "5fe71d831ffb33666eaaab8d13b589491f1df646", "branch_name": "refs/heads/main", "committer_date": "2021-03-28T07:27:07", "content_id": "d722dc4c9346a77b4aeae66daee9d1156d795c1c", "detected_licenses": [ "Apache-2.0" ], "directory_id": "8717b4036064ce0abb764958bea682e2f4d406d4", "extension": "h", "filename": "mem_heap.h", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 352254136, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1172, "license": "Apache-2.0", "license_type": "permissive", "path": "/mem_heap.h", "provenance": "stackv2-0003.json.gz:314712", "repo_name": "meilanli/mem_heap", "revision_date": "2021-03-28T07:27:07", "revision_id": "b8307e1cc36c548a9d8ccbee327488b1e804d077", "snapshot_id": "b0e4d09c6f4127bb68b4299b5057071e1dd99e75", "src_encoding": "GB18030", "star_events_count": 0, "url": "https://raw.githubusercontent.com/meilanli/mem_heap/b8307e1cc36c548a9d8ccbee327488b1e804d077/mem_heap.h", "visit_date": "2023-03-31T23:27:38.880065" }
stackv2
#ifndef __MEM_HEAP_H #define __MEM_HEAP_H #include "stdint.h" //以下为了方便MDK环境下自动获取剩余RAM起始地址 //其它平台,自行定义MEM_HEAP_BEGIN,MEM_HEAP_END即可 #define RAM_SIZE 48 //RAM内存总KB #define RAM_BEGIN 0x20000000 //内存起始地址 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) #define __CLANG_ARM #endif #if defined(__CC_ARM) || defined(__CLANG_ARM) extern int Image$$RW_IRAM1$$ZI$$Limit; #define MEM_HEAP_BEGIN (&Image$$RW_IRAM1$$ZI$$Limit) #elif __ICCARM__ #pragma section="HEAP" #define MEM_HEAP_BEGIN (__segment_end("HEAP")) #else extern int __bss_end; #define MEM_HEAP_BEGIN (&__bss_end) #endif #ifdef __ICCARM__ // Use *.icf ram symbal, to avoid hardcode. extern char __ICFEDIT_region_RAM_end__; #define MEM_SRAM_END &__ICFEDIT_region_RAM_end__ #else #define MEM_HEAP_END (RAM_BEGIN + RAM_SIZE * 1024) #endif struct MemHeapInfo { uint32_t used_num; uint32_t used_size; uint32_t total_size; }; void *heap_malloc(uint32_t size); void heap_free(void *free); struct MemHeapInfo *heap_get_info(void); #endif
2.125
2
2024-11-18T18:09:48.101756+00:00
2015-01-05T12:31:35
99a65f88c44f2becc11b1b0860051af579a61a91
{ "blob_id": "99a65f88c44f2becc11b1b0860051af579a61a91", "branch_name": "refs/heads/master", "committer_date": "2015-01-05T12:31:35", "content_id": "67564ea993ba49e3516267f78b69258b71a23ccc", "detected_licenses": [ "MIT" ], "directory_id": "a8ccfc3047ae314995569ad06cc757dfa60c1ae1", "extension": "c", "filename": "alternate_cmd.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 13755007, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 15848, "license": "MIT", "license_type": "permissive", "path": "/src/cli/alternate_cmd.c", "provenance": "stackv2-0003.json.gz:315228", "repo_name": "bfontaine/Dazibao", "revision_date": "2015-01-05T12:31:35", "revision_id": "76dbf14474d213eb7437f0e7ca0b8d65d8e9bebd", "snapshot_id": "e8201472e338f2943c2fa573a787f1f8f6c62e9b", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/bfontaine/Dazibao/76dbf14474d213eb7437f0e7ca0b8d65d8e9bebd/src/cli/alternate_cmd.c", "visit_date": "2021-01-23T08:56:29.962703" }
stackv2
#include <limits.h> #include <locale.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <string.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> #include "utils.h" #include "mdazibao.h" #include "alternate_cmd.h" /** @file */ /** buffer size used in various functions */ #define BUFFSIZE 512 int check_option_add(int argc, char **argv, int *date_idx, int *compound_idx, int *dz_idx, int *type_idx, int *input_idx) { int idx = 0, args_count = 0; for (int i = 0; i < argc; i++) { if (!strcmp(argv[i], "--type")) { *type_idx = idx; } else if ((strcmp(argv[i], "--date") == 0)) { if (*date_idx < 0) { *date_idx = idx; } } else if (strcmp(argv[i], "--dazibao") == 0) { if (*dz_idx < 0) { *dz_idx = idx; } } else if (strcmp(argv[i], "--compound") == 0) { if (*compound_idx < 0) { *compound_idx = idx; } } else if (strcmp(argv[i], "-") == 0) { if (*input_idx < 0) { *input_idx = idx; argv[idx] = argv[i]; idx++; args_count++; } } else { /* if the current parameter is not an option */ argv[idx] = argv[i]; idx++; args_count++; } } return args_count; } int check_type_args(int argc, char *type_args, char *op_type, int f_dz) { char * delim = ","; char *tmp = strtok(op_type, delim); int i = 0; while (tmp != NULL) { int tmp_type = tlv_str2type(tmp); if (tmp_type == (char) -1) { printf("unrecognized type %s\n", tmp); return -1; } else { type_args[i] = tmp_type; } tmp = strtok(NULL, delim); i++; } if (i != (argc + (f_dz >= 0 ? -1 : 0))) { printf("args to option type too large\n"); return -1; } return 0; } int check_args(int argc, char **argv, int *f_dz, int *f_co, int *f_d) { int date_size = 0, compound_size = 0, tmp_size = 0, i; for (i = 0; i < argc; i++) { if (strcmp(argv[i],"-") == 0) { continue; } else if ( i == *f_dz) { if ((tmp_size = check_dz_path(argv[i], R_OK)) < 0) { printf("check dz arg failed :%s\n", argv[i]); return -1; } } else if ( i >= *f_co) { if ((tmp_size = check_tlv_path(argv[i], R_OK)) < 0) { printf("check path arg failed :%s\n", argv[i]); return -1; } compound_size += tmp_size; } else { tmp_size = check_tlv_path(argv[i], R_OK); if (tmp_size < 0) { printf("check arg failed :%s\n", argv[i]); return -1; } } /* check size file for tlv */ if ((*f_d <= *f_co) && (i >= *f_co)) { date_size += compound_size + TLV_SIZEOF_HEADER + TLV_SIZEOF_DATE; } else { date_size += tmp_size; } if (tmp_size > TLV_MAX_VALUE_SIZE) { printf("tlv too large, %s\n",argv[i]); return -1; } else if (date_size > TLV_MAX_VALUE_SIZE) { printf("tlv date too large, %s\n",argv[i]); return -1; } else if (compound_size > TLV_MAX_VALUE_SIZE) { printf("tlv compound too large, %s\n",argv[i]); return -1; } tmp_size = 0; date_size = 0; } return 0; } int cmd_add(int argc, char **argv, char * daz) { int f_date = -1, f_compound = -1, f_dz = -1, f_type = -1, f_input = -1; char *type_args = NULL; if (argc < 0) { printf("error no args for add\n"); return -1; } argc = check_option_add(argc, argv, &f_date, &f_compound, &f_dz, &f_type, &f_input); if (f_type >= 0) { type_args = (char *) malloc(sizeof(*type_args)* argc); char *tmp = argv[f_type]; if (f_type < (argc -1)) { /* deleted type args in argv*/ int i; for (i = (f_type + 1); i < (argc); i++) { argv[i-1] = argv[i]; } /* shift flag if it after type args */ f_date = (f_date > f_type ? f_date -1 : f_date); f_compound = (f_compound > f_type ? f_compound-1 : f_compound); f_input = (f_input > f_type ? f_input-1 : f_input); f_dz = (f_dz > f_type ? f_dz-1 : f_dz); } argc--; if (check_type_args(argc, type_args, tmp, f_dz) < 0) { printf("check_args_no_op failed\n"); free(type_args); return -1; } } else if ( argc > (f_dz >= 0 ? 1:0) + (f_input >= 0 ? 1:0)) { printf("check_type_args failed\n"); return -1; } if (check_args(argc, argv, &f_dz, &f_compound, &f_date)) { printf("check path args failed\n"); return -1; } if (action_add(argc, argv, f_compound, f_dz, f_date, f_input, type_args, daz) == -1) { printf("error action add\n"); return -1; } if (f_type >= 0) { free(type_args); } return 0; } int action_add(int argc, char **argv, int f_co, int f_dz, int f_d, int f_in, char *type, char *daz) { dz_t daz_buf; unsigned int buff_size_co = 0; tlv_t tlv = NULL; tlv_t buff_co = NULL; tlv_t buff_d = NULL; int i,j = 0; if (dz_open(&daz_buf, daz, O_RDWR) < 0) { fprintf(stderr, "failed open the dazibao\n"); return -1; } f_d = (f_d == -1 ? argc : f_d); f_co = (f_co == -1 ? argc : f_co); for (i = 0; i < argc; i++) { int tlv_size = 0; /* inizialized tlv */ if (tlv_init(&tlv) < 0) { printf("error to init tlv\n"); return -1; } /* different possibility to create a standard tlv*/ if (i == f_in) { tlv_size = tlv_create_input(&tlv, &type[j]); j++; } else if (i == f_dz) { tlv_size = dz2tlv(argv[i], &tlv); } else { tlv_size = tlv_create_path(argv[i], &tlv, &type[j]); j++; } /* if not tlv as create error */ if (tlv_size < 0) { printf("error to create tlv with path %s\n", argv[i]); return -1; } /* other option who use tlv created */ if ( i >= f_co ) { /* if tlv to insert to compound it type dated*/ if ((i >= f_d) && (f_d > f_co)) { if (tlv_init(&buff_d) < 0) { printf("error to init tlv compound"); return -1; } tlv_size = tlv_create_date(&buff_d, &tlv, tlv_size); if (tlv_size < 0) { printf("error to create tlv dated" "%s\n", argv[i]); return -1; } tlv_destroy(&tlv); tlv = buff_d; buff_d = NULL; } unsigned int size_realloc = TLV_SIZEOF_HEADER; if ((f_co == i) && (tlv_init(&buff_co) < 0)) { printf("error to init tlv compound\n"); return -1; } size_realloc += buff_size_co + tlv_size; buff_co = (tlv_t) safe_realloc(buff_co, sizeof(*buff_co) * size_realloc); if (buff_co == NULL) { ERROR("realloc", -1); } memcpy(buff_co + buff_size_co, tlv, tlv_size); buff_size_co += tlv_size; tlv_destroy(&tlv); /*when all tlv is insert, create tlv compound*/ if (i == argc -1) { if (tlv_init(&tlv) < 0) { printf(" error to init tlv"); return -1; } tlv_size = tlv_create_compound(&tlv, &buff_co, buff_size_co); if (tlv_size < 0) { printf(" error to create compound" " %s\n", argv[i]); return -1; } tlv_destroy(&buff_co); } else { continue; } } if ((i >= f_d) && (f_d <= f_co)) { if (tlv_init(&buff_d) < 0) { printf(" error to init tlv dated\n"); return -1; } tlv_size = tlv_create_date(&buff_d, &tlv, tlv_size); if (tlv_size < 0) { printf(" error to create tlv dated" "%s\n", argv[i]); return -1; } tlv_destroy(&tlv); tlv = buff_d; buff_d = NULL; } if (tlv_size > 0) { if (dz_add_tlv(&daz_buf, &tlv) == -1) { fprintf(stderr, "failed adding the tlv\n"); tlv_destroy(&tlv); return -1; } tlv_destroy(&tlv); } } if (dz_close(&daz_buf) < 0) { fprintf(stderr, "failed closing the dazibao\n"); return -1; } return 0; } int choose_tlv_extract(dz_t *dz, tlv_t *tlv, long off) { if (dz_tlv_at(dz, tlv, off) < 0) { printf("error to read type and length tlv\n"); dz_close(dz); tlv_destroy(tlv); return -1; } if (tlv_get_type(tlv) == TLV_DATED) { off = off + TLV_SIZEOF_HEADER + TLV_SIZEOF_DATE; return choose_tlv_extract(dz,tlv,off); } if (dz_read_tlv(dz, tlv, off) < 0) { printf("error to read value tlv\n"); dz_close(dz); tlv_destroy(tlv); return -1; } return 0; } int cmd_extract(int argc , char **argv, char *dz_path) { dz_t dz; tlv_t tlv; long off; int fd; size_t real_size; char *data; char *path; if (argc != 2) { fprintf(stderr, "cmd extract : <offset> <path> <dazibao>\n"); return DZ_ARGS_ERROR; } /* If the offset doesn't start with a character between '0' and '9', it * must be wrong. */ if (argv[0][0] < 48 || argv[0][0] > 57) { fprintf(stderr, "Usage:\n extract <offset> <file> <dazibao>\n"); return DZ_ARGS_ERROR; } off = str2dec_positive(argv[0]); if (off < DAZIBAO_HEADER_SIZE) { fprintf(stderr, "wrong offset\n"); return DZ_OFFSET_ERROR; } if (dz_open(&dz, dz_path, O_RDWR) < 0) { fprintf(stderr, "Error while opening the dazibao\n"); return -1; } if (dz_check_tlv_at(&dz, off, -1,NULL) <= 0) { fprintf(stderr, "no such TLV\n"); dz_close(&dz); return DZ_OFFSET_ERROR; } if (tlv_init(&tlv) < 0) { printf("error to init tlv\n"); dz_close(&dz); return -1; } if (choose_tlv_extract(&dz,&tlv,off) < 0) { printf("error to init tlv\n"); tlv_destroy(&tlv); dz_close(&dz); return -1; } if (dz_close(&dz) < 0) { fprintf(stderr, "Error while closing the dazibao\n"); tlv_destroy(&tlv); return -1; } if (tlv_get_type(&tlv) == TLV_COMPOUND) { real_size = (size_t)tlv_get_length(&tlv) + DAZIBAO_HEADER_SIZE; } else { real_size = (size_t)tlv_get_length(&tlv); } path = argv[1]; fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644); if (fd == -1) { tlv_destroy(&tlv); ERROR("open", -1); } if (ftruncate(fd, real_size) < 0) { fprintf(stderr, "Error while ftruncate path"); close(fd); return -1; } data = (char*)mmap(NULL, real_size, PROT_WRITE, MAP_SHARED, fd, 0); if (data == MAP_FAILED) { fprintf(stderr, "Error while mmap "); close(fd); tlv_destroy(&tlv); return -1; } if (tlv_get_type(&tlv) == TLV_COMPOUND) { data[0] = MAGIC_NUMBER; memset(data + 1, 0, DAZIBAO_HEADER_SIZE - 1); real_size = real_size - DAZIBAO_HEADER_SIZE; memcpy(data + DAZIBAO_HEADER_SIZE, tlv_get_value_ptr(&tlv), real_size); } else { memcpy(data , tlv_get_value_ptr(&tlv), real_size); } tlv_destroy(&tlv); close(fd); return 0; }
2.109375
2
2024-11-18T18:09:48.527688+00:00
2019-01-06T17:21:50
66fd6dc0db9cf6dc785f1888df5e4305b40786c1
{ "blob_id": "66fd6dc0db9cf6dc785f1888df5e4305b40786c1", "branch_name": "refs/heads/master", "committer_date": "2019-01-06T17:21:50", "content_id": "9dc9f1773a0360e1b0d9f39f24dcd5c3ed1b78b2", "detected_licenses": [ "NCSA" ], "directory_id": "971c5ae1d87cdfbb97723485c3d76c17395b82b0", "extension": "c", "filename": "mzero5.c", "fork_events_count": 0, "gha_created_at": "2019-01-12T01:42:16", "gha_event_created_at": "2019-01-12T01:42:16", "gha_language": null, "gha_license_id": "NOASSERTION", "github_id": 165334058, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 507, "license": "NCSA", "license_type": "permissive", "path": "/x86-semantics/tests/gcc.c-torture/ieee/src/mzero5.c", "provenance": "stackv2-0003.json.gz:315740", "repo_name": "mewbak/binary-decompilation", "revision_date": "2019-01-06T17:21:50", "revision_id": "f58da4c53cd823edc4bbbad6b647dbcefd7e64f8", "snapshot_id": "7d0bf64d6cd01bfa5f5fc912d74a85ce81124959", "src_encoding": "UTF-8", "star_events_count": 1, "url": "https://raw.githubusercontent.com/mewbak/binary-decompilation/f58da4c53cd823edc4bbbad6b647dbcefd7e64f8/x86-semantics/tests/gcc.c-torture/ieee/src/mzero5.c", "visit_date": "2020-04-16T06:08:14.983946" }
stackv2
#include "mini_string.h" #include "mini_stdlib.h" /* Test gcse handling of IEEE 0/-0 rules. */ static double zero = 0.0; int negzero_check (double d) { if (d == 0) return !!memcmp ((void *)&zero, (void *)&d, sizeof (double)); return 0; } int xsub (double d, double e) { if (d == 0.0 && e == 0.0 && negzero_check (d) == 0 && negzero_check (e) == 0) return 1; else return 0; } int main (void) { double minus_zero = -0.0; if (xsub (minus_zero, 0)) abort (); return 0; }
2.515625
3
2024-11-18T18:09:48.617710+00:00
2019-12-19T00:03:48
c08b46a27c8f6b4162ae22faeecc1e59eb17d9b0
{ "blob_id": "c08b46a27c8f6b4162ae22faeecc1e59eb17d9b0", "branch_name": "refs/heads/master", "committer_date": "2019-12-19T00:03:48", "content_id": "2f1b77bc2f2aadf6307e26eef2e4542c189572db", "detected_licenses": [ "MIT" ], "directory_id": "03ae399c214cdb071298ce680f05ff01028070d3", "extension": "c", "filename": "sender.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": null, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 4903, "license": "MIT", "license_type": "permissive", "path": "/csi-device-manager/src/sender.c", "provenance": "stackv2-0003.json.gz:315868", "repo_name": "Hive10/csi-monitor", "revision_date": "2019-12-19T00:03:48", "revision_id": "bb89cd50688f48d3f236d9654be7d845b8ba873c", "snapshot_id": "7c110de31f44f1429eb995065c5ecbb670978d5c", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/Hive10/csi-monitor/bb89cd50688f48d3f236d9654be7d845b8ba873c/csi-device-manager/src/sender.c", "visit_date": "2022-03-24T21:16:40.987766" }
stackv2
#include <arpa/inet.h> #include <linux/if_packet.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <termios.h> #include <net/if.h> #include <netinet/ether.h> #include <unistd.h> #include "sender.h" int rawsock; int start_send = FALSE; int packets_per_second = 0; int num_seconds = 0; PACKET packet_to_send; void *create_packets_sender(void *vargp) { rawsock = create_raw_socket(); int wait_time, packets_sent, i; while(TRUE) { // Wait until start command while(!start_send) sleep(1); printf("Sending packets %d for %d seconds...\n", packets_per_second, num_seconds); wait_time = 1000000/packets_per_second; packets_sent = 0; for(; num_seconds > 0; num_seconds--) { // Cancel send if stop is called if(!start_send) break; for(i = 0; i < packets_per_second; i++) { usleep(wait_time); sendto(rawsock, packet_to_send.send_buffer, packet_to_send.len, 0, (struct sockaddr*)&packet_to_send.socket_address, sizeof(struct sockaddr_ll)); packets_sent++; } } printf("%d packets sent!\n", packets_sent); start_send = FALSE; num_seconds = 0; packets_per_second = 0; } } struct ifreq get_interface_index(int rawsock, char *if_name) { struct ifreq if_idx; memset(&if_idx, 0, sizeof(struct ifreq)); strncpy(if_idx.ifr_name, if_name, IFNAMSIZ-1); if(ioctl(rawsock, SIOCGIFINDEX, &if_idx) < 0) { printf("Could not get raw socket interface\n"); } return if_idx; } struct ifreq get_interface_mac_address(int rawsock, char *if_name) { struct ifreq if_mac; memset(&if_mac, 0, sizeof(struct ifreq)); strncpy(if_mac.ifr_name, if_name, IFNAMSIZ-1); if(ioctl(rawsock, SIOCGIFHWADDR, &if_mac) < 0) { printf("Could not get raw socket source mac\n"); } return if_mac; } int create_raw_socket() { int rawsock; /* Open RAW socket to send on */ if((rawsock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) == -1) { printf("Could not create raw socket\n"); return -1; } return rawsock; } PACKET create_packet(struct ifreq if_idx, struct ifreq if_mac, unsigned int dst_addr[6]) { PACKET new_packet; new_packet.len = 0; new_packet.eh = (struct ether_header *) new_packet.send_buffer; /* Construct the Ethernet header */ memset(new_packet.send_buffer, 0, BUF_SIZE); /* Ethernet header */ new_packet.eh->ether_shost[0] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[0]; new_packet.eh->ether_shost[1] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[1]; new_packet.eh->ether_shost[2] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[2]; new_packet.eh->ether_shost[3] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[3]; new_packet.eh->ether_shost[4] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[4]; new_packet.eh->ether_shost[5] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[5]; new_packet.eh->ether_dhost[0] = dst_addr[0]; new_packet.eh->ether_dhost[1] = dst_addr[1]; new_packet.eh->ether_dhost[2] = dst_addr[2]; new_packet.eh->ether_dhost[3] = dst_addr[3]; new_packet.eh->ether_dhost[4] = dst_addr[4]; new_packet.eh->ether_dhost[5] = dst_addr[5]; new_packet.eh->ether_type = htons(ETH_P_IP); new_packet.len += sizeof(struct ether_header); /* Packet data * We just set it to 0xaa you send arbitrary payload you like*/ int i; for(i = 1; i <= 1000; i++) { new_packet.send_buffer[new_packet.len++] = 0xaa; } new_packet.iph = (struct iphdr *) (new_packet.send_buffer + sizeof(struct ether_header)); new_packet.socket_address.sll_ifindex = if_idx.ifr_ifindex; new_packet.socket_address.sll_family = PF_PACKET; new_packet.socket_address.sll_protocol = htons(ETH_P_IP); new_packet.socket_address.sll_hatype = ARPHRD_ETHER; new_packet.socket_address.sll_pkttype = PACKET_OTHERHOST; new_packet.socket_address.sll_halen = ETH_ALEN; new_packet.socket_address.sll_addr[0] = dst_addr[0]; new_packet.socket_address.sll_addr[1] = dst_addr[1]; new_packet.socket_address.sll_addr[2] = dst_addr[2]; new_packet.socket_address.sll_addr[3] = dst_addr[3]; new_packet.socket_address.sll_addr[4] = dst_addr[4]; new_packet.socket_address.sll_addr[5] = dst_addr[5]; return new_packet; } void send_packets(unsigned int DstAddr[6], unsigned int quantity_of_packets, unsigned int until_seconds, char ifName[IFNAMSIZ]) { packet_to_send = create_packet(get_interface_index(rawsock, ifName), get_interface_mac_address(rawsock, ifName), DstAddr); packets_per_second = quantity_of_packets; num_seconds = until_seconds; start_send = TRUE; } void stop_sending() { printf("Stopping the sender...\n"); start_send = FALSE; }
2.390625
2
2024-11-18T18:09:48.880362+00:00
2020-08-06T16:53:36
6fb96f5908e8c9e31fb5ae5c23ef175a61d5bfae
{ "blob_id": "6fb96f5908e8c9e31fb5ae5c23ef175a61d5bfae", "branch_name": "refs/heads/master", "committer_date": "2020-08-06T16:53:36", "content_id": "3799b1cf0ead32c97152cdf63513472faec26369", "detected_licenses": [ "MIT" ], "directory_id": "8b7a272ae43c04ac490056635219be066aa6f2a1", "extension": "c", "filename": "write_mp_ack_frame.c", "fork_events_count": 1, "gha_created_at": "2020-08-10T07:59:28", "gha_event_created_at": "2020-08-10T07:59:29", "gha_language": null, "gha_license_id": "MIT", "github_id": 286412983, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 6562, "license": "MIT", "license_type": "permissive", "path": "/plugins/multipath/write_mp_ack_frame.c", "provenance": "stackv2-0003.json.gz:316254", "repo_name": "Ysurac/pquic", "revision_date": "2020-08-06T16:53:36", "revision_id": "2bd9737291f61f5f5286de6e758613f49237a0c6", "snapshot_id": "b80c1649688a9a79c5430bffa0ac4d0022b52339", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/Ysurac/pquic/2bd9737291f61f5f5286de6e758613f49237a0c6/plugins/multipath/write_mp_ack_frame.c", "visit_date": "2022-11-28T17:10:29.023840" }
stackv2
#include "bpf.h" /** * See PROTOOP_PARAM_WRITE_FRAME */ protoop_arg_t write_mp_ack_frame(picoquic_cnx_t *cnx) { uint8_t* bytes = (uint8_t *) get_cnx(cnx, AK_CNX_INPUT, 0); const uint8_t *bytes_max = (const uint8_t *) get_cnx(cnx, AK_CNX_INPUT, 1); mp_ack_ctx_t *mac = (mp_ack_ctx_t *) get_cnx(cnx, AK_CNX_INPUT, 2); size_t consumed = 0; uint64_t current_time = picoquic_current_time(); picoquic_path_t *path_x = mac->path_x; picoquic_packet_context_enum pc = mac->pc; int ret = 0; size_t byte_index = 0; uint64_t num_block = 0; size_t l_frame_id = 0; size_t l_uniflow_id = 0; size_t l_largest = 0; size_t l_delay = 0; size_t l_first_range = 0; picoquic_packet_context_t * pkt_ctx = (picoquic_packet_context_t *) get_path(path_x, AK_PATH_PKT_CTX, pc); picoquic_sack_item_t* first_sack = (picoquic_sack_item_t *) get_pkt_ctx(pkt_ctx, AK_PKTCTX_FIRST_SACK_ITEM); picoquic_sack_item_t* next_sack = (picoquic_sack_item_t *) get_sack_item(first_sack, AK_SACKITEM_NEXT_SACK); uint64_t ack_delay = 0; uint64_t ack_range = 0; uint64_t ack_gap = 0; uint64_t lowest_acknowledged = 0; size_t num_block_index = 0; bpf_data *bpfd = get_bpf_data(cnx); uniflow_data_t *ud = mp_get_receiving_uniflow_data(bpfd, path_x); /* Check that there is enough room in the packet, and something to acknowledge */ uint64_t first_sack_start_range = (uint64_t) get_sack_item(first_sack, AK_SACKITEM_START_RANGE); if (first_sack_start_range == (uint64_t)((int64_t)-1)) { consumed = 0; } else if (bytes_max - bytes < 14) { /* A valid ACK, with our encoding, uses at least 13 bytes. * If there is not enough space, don't attempt to encode it. */ consumed = 0; ret = PICOQUIC_ERROR_FRAME_BUFFER_TOO_SMALL; } else { /* Encode the frame ID */ l_frame_id = picoquic_varint_encode(bytes + byte_index, (size_t) (bytes_max - bytes) - byte_index, MP_ACK_TYPE); byte_index += l_frame_id; /* Encode the uniflow ID */ if (byte_index < bytes_max - bytes) { l_uniflow_id = picoquic_varint_encode(bytes + byte_index, (size_t) (bytes_max - bytes) - byte_index, ud->uniflow_id); byte_index += l_uniflow_id; } /* Encode the largest seen */ uint64_t first_sack_end_range = (uint64_t) get_sack_item(first_sack, AK_SACKITEM_END_RANGE); if (byte_index < bytes_max - bytes) { l_largest = picoquic_varint_encode(bytes + byte_index, (size_t) (bytes_max - bytes) - byte_index, first_sack_end_range); byte_index += l_largest; } /* Encode the ack delay */ if (byte_index < bytes_max - bytes) { uint64_t time_stamp_largest_received = (uint64_t) get_pkt_ctx(pkt_ctx, AK_PKTCTX_TIME_STAMP_LARGEST_RECEIVED); if (current_time > time_stamp_largest_received) { ack_delay = current_time - time_stamp_largest_received; ack_delay >>= (uint8_t) get_cnx(cnx, AK_CNX_LOCAL_PARAMETER, TRANSPORT_PARAMETER_ACK_DELAY_EXPONENT); } l_delay = picoquic_varint_encode(bytes + byte_index, (size_t) (bytes_max - bytes) - byte_index, ack_delay); byte_index += l_delay; } if (ret == 0) { /* Reserve one byte for the number of blocks */ num_block_index = byte_index; byte_index++; /* Encode the size of the first ack range */ if (byte_index < bytes_max - bytes) { ack_range = first_sack_end_range - first_sack_start_range; l_first_range = picoquic_varint_encode(bytes + byte_index, (size_t) (bytes_max - bytes) - byte_index, ack_range); byte_index += l_first_range; } } if (l_uniflow_id == 0 || l_delay == 0 || l_largest == 0 || l_first_range == 0 || byte_index > (size_t) (bytes_max - bytes)) { /* not enough space */ consumed = 0; ret = PICOQUIC_ERROR_FRAME_BUFFER_TOO_SMALL; } else if (ret == 0) { /* Set the lowest acknowledged */ lowest_acknowledged = first_sack_start_range; /* Encode the ack blocks that fit in the allocated space */ while (num_block < 63 && next_sack != NULL) { size_t l_gap = 0; size_t l_range = 0; uint64_t next_sack_end_range = (uint64_t) get_sack_item(next_sack, AK_SACKITEM_END_RANGE); uint64_t next_sack_start_range = (uint64_t) get_sack_item(next_sack, AK_SACKITEM_START_RANGE); if (byte_index < (size_t) (bytes_max - bytes)) { ack_gap = lowest_acknowledged - next_sack_end_range - 2; /* per spec */ l_gap = picoquic_varint_encode(bytes + byte_index, (size_t) (bytes_max - bytes) - byte_index, ack_gap); } if (byte_index + l_gap < (size_t) (bytes_max - bytes)) { ack_range = next_sack_end_range - next_sack_start_range; l_range = picoquic_varint_encode(bytes + byte_index + l_gap, (size_t) (bytes_max - bytes) - byte_index - l_gap, ack_range); } if (l_gap == 0 || l_range == 0) { /* Not enough space to encode this gap. */ break; } else { byte_index += l_gap + l_range; lowest_acknowledged = next_sack_start_range; next_sack = (picoquic_sack_item_t *) get_sack_item(next_sack, AK_SACKITEM_NEXT_SACK); num_block++; } } /* When numbers are lower than 64, varint encoding fits on one byte */ my_memset(&bytes[num_block_index], (uint8_t)num_block, 1); /* Remember the ACK value and time */ set_pkt_ctx(pkt_ctx, AK_PKTCTX_HIGHEST_ACK_SENT, first_sack_end_range); set_pkt_ctx(pkt_ctx, AK_PKTCTX_HIGHEST_ACK_TIME, current_time); consumed = byte_index; } } if (ret == 0) { set_pkt_ctx(pkt_ctx, AK_PKTCTX_ACK_NEEDED, 0); } my_free(cnx, mac); //pd->doing_ack = false; set_cnx(cnx, AK_CNX_OUTPUT, 0, (protoop_arg_t) consumed); set_cnx(cnx, AK_CNX_OUTPUT, 1, (protoop_arg_t) 0); return (protoop_arg_t) ret; }
2.140625
2
2024-11-18T18:09:48.959390+00:00
2015-11-24T09:35:17
c1616d2aa3e3d966229b0a59177f98ec5faa2372
{ "blob_id": "c1616d2aa3e3d966229b0a59177f98ec5faa2372", "branch_name": "refs/heads/master", "committer_date": "2015-11-24T09:35:17", "content_id": "2a2b0438ef077231bf7b95c63864e0b9cd7d4fdb", "detected_licenses": [ "MIT" ], "directory_id": "d531386c1a6fb9be800161aae965b208740d4011", "extension": "c", "filename": "tm.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 46283440, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 3129, "license": "MIT", "license_type": "permissive", "path": "/src/kernel/tm.c", "provenance": "stackv2-0003.json.gz:316382", "repo_name": "shenchi/scos", "revision_date": "2015-11-24T09:35:17", "revision_id": "4109f5a4ce2a97efc0fdee69f9f97aed6df22dd0", "snapshot_id": "baf2594a1d254cc3e899ec7c3326f8601639ea3e", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/shenchi/scos/4109f5a4ce2a97efc0fdee69f9f97aed6df22dd0/src/kernel/tm.c", "visit_date": "2021-01-10T04:19:16.499604" }
stackv2
//======================================================= //Project Name: S.C. Operating System //Version: 0.02 //Auther: Shen Chi //======================================================= #include "tm.h" #include "kernel.h" #include "task.h" #include "fs.h" #include "screen.h" task_info ti[64]; unsigned long cur_task=0; unsigned long cur_vbuf=0xb8000; unsigned long cur_kbuf=0; void init_tm(void){ unsigned long i; for(i=0;i<=64;i++){ ti[i].kbuf_addr=0; ti[i].vbuf_addr=-1; } cur_task=0; } void set_cur_task(unsigned long task_no){ cur_task=task_no; cur_vbuf=ti[cur_task].vbuf_addr; if(cur_vbuf==-1)cur_vbuf=0xb8000; cur_kbuf=ti[cur_task].kbuf_addr; } void set_cur_task_without_task_no(void){ //puts("Set Task To ");puthex(current);puts("\n\r"); cur_task=current; cur_vbuf=ti[cur_task].vbuf_addr; if(cur_vbuf==-1)cur_vbuf=0xb8000; cur_kbuf=ti[cur_task].kbuf_addr; } void set_cur_vbuf(unsigned long addr){ if(current==0)return; unsigned long baseaddr=((current-1)*64+32)*1024*1024; ti[current].vbuf_addr=baseaddr+addr; cur_vbuf=ti[cur_task].vbuf_addr; if(cur_vbuf==-1)cur_vbuf=0xb8000; } void set_cur_kbuf(unsigned long addr){ if(current==0)return; unsigned long baseaddr=((current-1)*64+32)*1024*1024; ti[current].kbuf_addr=baseaddr+addr; cur_kbuf=ti[cur_task].kbuf_addr; } unsigned long read_file_for_ring3(unsigned long filenameaddr,unsigned long addr){ if(current==0)return 0; unsigned long baseaddr=((current-1)*64+32)*1024*1024; unsigned long tmpret; tmpret=read_file((char*)(baseaddr+filenameaddr),baseaddr+addr); return tmpret; } unsigned long create_file_for_ring3(unsigned long filenameaddr,unsigned long addr,unsigned long size){ if(current==0)return 0; unsigned long baseaddr=((current-1)*64+32)*1024*1024; unsigned long tmpret; tmpret=create_file((char*)(baseaddr+filenameaddr), baseaddr+addr, size); return tmpret; } unsigned long create_dir_for_ring3(unsigned long filenameaddr,unsigned long addr,unsigned long size){ if(current==0)return 0; unsigned long baseaddr=((current-1)*64+32)*1024*1024; unsigned long tmpret; tmpret=create_dir((char*)(baseaddr+filenameaddr), baseaddr+addr, size); return tmpret; } unsigned long delete_file_for_ring3(unsigned long filenameaddr){ if(current==0)return 0; unsigned long baseaddr=((current-1)*64+32)*1024*1024; unsigned long tmpret; tmpret=delete_file((char*)(baseaddr+filenameaddr)); return tmpret; } unsigned long change_dir_for_ring3(unsigned long filenameaddr){ if(current==0)return 0; unsigned long baseaddr=((current-1)*64+32)*1024*1024; unsigned long tmpret; tmpret=goto_dic((unsigned char*)(baseaddr+filenameaddr)); return tmpret; } void dir_for_ring3(unsigned long filenameaddr){ if(current==0)return; unsigned long baseaddr=((current-1)*64+32)*1024*1024; dir((unsigned char*)filenameaddr+baseaddr); } void task_list_for_ring3(unsigned long filenameaddr){ if(current==0)return; unsigned long baseaddr=((current-1)*64+32)*1024*1024; task_list((unsigned char*)filenameaddr+baseaddr); }
2.53125
3
2024-11-18T18:09:49.108334+00:00
2019-01-06T17:21:50
457ff06cea5a7e661792f7576923c7c619b829fe
{ "blob_id": "457ff06cea5a7e661792f7576923c7c619b829fe", "branch_name": "refs/heads/master", "committer_date": "2019-01-06T17:21:50", "content_id": "df40c267a4f628aaa7fc4badc4b42d80e4d68f30", "detected_licenses": [ "NCSA" ], "directory_id": "971c5ae1d87cdfbb97723485c3d76c17395b82b0", "extension": "c", "filename": "test.c", "fork_events_count": 0, "gha_created_at": "2019-01-12T01:42:16", "gha_event_created_at": "2019-01-12T01:42:16", "gha_language": null, "gha_license_id": "NOASSERTION", "github_id": 165334058, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 349, "license": "NCSA", "license_type": "permissive", "path": "/x86-semantics/tests/Programs/stdio_fflush/test.c", "provenance": "stackv2-0003.json.gz:316510", "repo_name": "mewbak/binary-decompilation", "revision_date": "2019-01-06T17:21:50", "revision_id": "f58da4c53cd823edc4bbbad6b647dbcefd7e64f8", "snapshot_id": "7d0bf64d6cd01bfa5f5fc912d74a85ce81124959", "src_encoding": "UTF-8", "star_events_count": 1, "url": "https://raw.githubusercontent.com/mewbak/binary-decompilation/f58da4c53cd823edc4bbbad6b647dbcefd7e64f8/x86-semantics/tests/Programs/stdio_fflush/test.c", "visit_date": "2020-04-16T06:08:14.983946" }
stackv2
#include <stdio.h> int main() { char mybuffer[80]; FILE * pFile; pFile = fopen ("example.txt","w"); fputs ("test",pFile); fflush (pFile); // flushing or repositioning required fclose (pFile); pFile = fopen ("example.txt","r"); fgets (mybuffer,80,pFile); puts (mybuffer); fclose (pFile); return 0; }
2.171875
2
2024-11-18T18:09:50.965242+00:00
2018-02-10T00:29:26
5cfed590c7521c3a449a020ec9a6ad8a33f99701
{ "blob_id": "5cfed590c7521c3a449a020ec9a6ad8a33f99701", "branch_name": "refs/heads/master", "committer_date": "2018-02-10T00:29:26", "content_id": "0af2ee6d97f7aa80f4647478eabf7def99a000d4", "detected_licenses": [ "MIT" ], "directory_id": "b7ff102f68c61fa3a4ab31c9a24008d60f709154", "extension": "h", "filename": "mouse.h", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": null, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1546, "license": "MIT", "license_type": "permissive", "path": "/src/mouse.h", "provenance": "stackv2-0003.json.gz:316770", "repo_name": "Rockdell/2LCOM-MOsu", "revision_date": "2018-02-10T00:29:26", "revision_id": "e51c34cce164dcbea06bcde9f7e44604dead36bb", "snapshot_id": "1f0da1c7bf914533d93c19515db45e6ccc9edce7", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/Rockdell/2LCOM-MOsu/e51c34cce164dcbea06bcde9f7e44604dead36bb/src/mouse.h", "visit_date": "2021-04-18T18:35:33.364436" }
stackv2
#ifndef __MOUSE_H #define __MOUSE_H #include <minix/syslib.h> /** @defgroup mouse Mouse * @{ * * Mouse related functions */ /** * @brief Subscribes mouse's interruptions. * @return Returns an ID if successful and -1 otherwise. */ int mouse_subscribe_int(void ); /** * @brief Unsubscribes mouse's interruptions. * @return Returns 0 if successful and 1 otherwise. */ int mouse_unsubscribe_int(); /** * @brief Mouse's interruption handler. * @return Returns 0 if successful and 1 otherwise. */ int mouse_int_handler(); /** * @brief Adds a processed byte to a packet. * @return Returns 0 if successful and 1 otherwise. */ int addBytePacket(unsigned long byte); /** * @brief Gets the counter, which keeps track of the number of bytes processed (up to 3 per packet). * @return Returns the counter of packets. */ int getCounter(); /** * @brief Check if the right button is pressed (right click). * @return Returns 1 if true and 0 otherwise. */ int getRB(); /** * @brief Check if the left button is pressed (left click). * @return Returns 1 if true and 0 otherwise. */ int getLB(); /** * @brief Check X-axis' movement. * @return Returns the X-axis' movement. */ int getX(); /** * @brief Check Y-axis movement. * @return Returns the Y-axis movement. */ int getY(); /** * @brief Prints the last packet processed. */ void printPacket(); /** * @brief Updates the static varibles with the last X-axis' movement and Y-axis' movement. */ void updateCoord(); /** @} end of mouse */ #endif
2.078125
2
2024-11-18T18:09:51.277499+00:00
2020-05-15T15:42:59
085647b3686ec55ecbbebc8c977a8a3373261eb0
{ "blob_id": "085647b3686ec55ecbbebc8c977a8a3373261eb0", "branch_name": "refs/heads/master", "committer_date": "2020-05-15T15:42:59", "content_id": "9f287c7408c9cd16e86f57a63a969fea1aa4a85c", "detected_licenses": [ "MIT" ], "directory_id": "6ee3f3fa19120d7fba5316670aba623c9b9a83c0", "extension": "h", "filename": "Define.h", "fork_events_count": 0, "gha_created_at": "2020-05-01T13:01:39", "gha_event_created_at": "2020-05-01T13:01:40", "gha_language": null, "gha_license_id": "MIT", "github_id": 260460272, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 651, "license": "MIT", "license_type": "permissive", "path": "/Tutorial/05/Define.h", "provenance": "stackv2-0003.json.gz:317157", "repo_name": "overworks/edu_cpp_IOCP", "revision_date": "2020-05-15T15:42:59", "revision_id": "9e272ee10cf6b425ec7ab13db1636143aa74e794", "snapshot_id": "8af7c679d740e3692d5edab4f237d93077b66623", "src_encoding": "UHC", "star_events_count": 0, "url": "https://raw.githubusercontent.com/overworks/edu_cpp_IOCP/9e272ee10cf6b425ec7ab13db1636143aa74e794/Tutorial/05/Define.h", "visit_date": "2022-08-01T15:05:43.170338" }
stackv2
#pragma once #include <winsock2.h> #include <Ws2tcpip.h> const UINT32 MAX_SOCKBUF = 256; // 소켓 버퍼의 크기 const UINT32 MAX_SOCK_SENDBUF = 4096; // 소켓 버퍼의 크기 const UINT32 MAX_WORKERTHREAD = 4; //쓰레드 풀에 넣을 쓰레드 수 enum class IOOperation { RECV, SEND }; //WSAOVERLAPPED구조체를 확장 시켜서 필요한 정보를 더 넣었다. struct stOverlappedEx { WSAOVERLAPPED m_wsaOverlapped; //Overlapped I/O구조체 SOCKET m_socketClient; //클라이언트 소켓 WSABUF m_wsaBuf; //Overlapped I/O작업 버퍼 IOOperation m_eOperation; //작업 동작 종류 };
2.1875
2
2024-11-18T18:09:51.336161+00:00
2021-11-26T08:38:57
6dc5ed6cf730d410761448e61e38a6087e44cf04
{ "blob_id": "6dc5ed6cf730d410761448e61e38a6087e44cf04", "branch_name": "refs/heads/main", "committer_date": "2021-11-26T08:38:57", "content_id": "5ac2145c82d4c655efa0485ab2207978489a37ab", "detected_licenses": [ "BSD-3-Clause", "BSD-2-Clause" ], "directory_id": "a77b595a482fc74260c7cccc50cafa77e0584c67", "extension": "h", "filename": "tinyspritebatch.h", "fork_events_count": 1, "gha_created_at": "2017-02-11T19:39:37", "gha_event_created_at": "2021-11-01T08:16:12", "gha_language": "C", "gha_license_id": null, "github_id": 81677344, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 58480, "license": "BSD-3-Clause,BSD-2-Clause", "license_type": "permissive", "path": "/src/tinyheaders/tinyspritebatch.h", "provenance": "stackv2-0003.json.gz:317285", "repo_name": "meshula/LabRender", "revision_date": "2021-11-26T08:38:57", "revision_id": "690303a3364d726129d63c854e598061f04d1296", "snapshot_id": "80486a10168a2982ef7daaf42b39c787cef1f540", "src_encoding": "UTF-8", "star_events_count": 15, "url": "https://raw.githubusercontent.com/meshula/LabRender/690303a3364d726129d63c854e598061f04d1296/src/tinyheaders/tinyspritebatch.h", "visit_date": "2021-12-24T18:32:04.573476" }
stackv2
/* ------------------------------------------------------------------------------ Licensing information can be found at the end of the file. ------------------------------------------------------------------------------ tinyspritebatch.h - v1.0 To create implementation (the function definitions) #define SPRITEBATCH_IMPLEMENTATION in *one* C/CPP file (translation unit) that includes this file SUMMARY: This header implements a 2D sprite batcher by tracking different textures within a rolling atlas cache. Over time atlases are decayed and recreated when textures stop being used. This header is useful for batching sprites at run-time. This avoids the need to compile texture atlases as a pre-process step, letting the game load images up individually, dramatically simplifying art pipelines. MORE DETAILS: `spritebatch_push` is used to push sprite instances into a buffer. Rendering sprites works by calling `spritebatch_flush`. `spritebatch_flush` will use a user-supplied callback to report sprite batches. This callback is of type `submit_batch_t`. The batches are reported as an array of `spritebatch_sprite_t` sprites, and can be further sorted by the user (for example to sort by depth). Sprites in a batch share the same texture handle (either from the same base image, or from the same internal atlas). tinypsritebatch does not know anything about how to generate texture handles, or destroy them. As such, the user must supply two callbacks for creating handles and destroying them. These can be simple wrappers around, for example, `glGenTextures` and `glDeleteTextures`. Finally, tinyspritebatch will periodically need access to pixels from images. These pixels are used to generate textures, or to build atlases (which in turn generate a texture). tinyspritebatch does not need to know much about your images, other than the pixel stride. The user supplies callback of type `get_pixels_t`, which lets tinypsritebatch retreive the pixels associated with a particular image. The pixels can be stored in RAM and handed to tinyspritebatch whenever requested, or the pixels can be fetched directly from disk and handed to tinyspritebatch. It doesn't matter to tinyspritebatch, and the pointer to the pixels are *not* stored anywhere after the callback returns. Since `get_pixels_t` can be called from `spritebatch_flush` it is recommended to avoid file i/o within the `get_pixels_t` callback, and instead try to already have pixels ready in RAM. The `spritebatch_defrag` function performs atlas creation and texture management. It should be called periodically. It can be called once per game tick (once per render), or optionally called at a different frequency (once ever N game ticks). PROS AND CONS: PROS - Texture atlases are completely hidden behind an api. The api in this header can easily be implemented with different backend sprite batchers. For example on some platforms bindless textures can be utilized in order to avoid texture atlases entirely! Code using this API can have the backend implementation swapped without requiring any user code to change. - Sprites are batched in an effective manner to dramatically reduce draw call counts. - Supporting hotswapping or live-reloading of images can be trivialized due to moving atlas creation out of the art-pipeline and into the run-time. - Since atlases are built at run-time and continually maintained, images are guaranteed to be drawn at the same time on-screen as their atlas neighbors. This is typically not the case for atlas preprocessors, as a *guess* must be made to try and organize images together in atlases that need to be drawn at roughly the same time. CONS - Performance hits in the `spritebatch_defrag` function, and a little as well in the `spritebatch_flush` function. Extra run-time memory usage for bookkeeping, which implies a RAM hit as well as more things to clog the CPU cache. - If each texture comes from a separate image on-disk, opening individual files on disk can be very slow. For example on Windows just performing permissions and related work to open a file is time-consuming. - For large numbers of separate images, some file abstraction is necessary to avoid a large performance hit on opening/closing many individual files. This problem is *not* solved by tinyspritebatch.h, and instead should be solved by some separate file abstraction system. EXAMPLE USAGE: spritebatch_config_t config; spritebatch_set_default_config(&config); config.batch_callback = my_report_batches_function; config.get_pixels_callback = my_get_pixels_function; config.generate_texture_callback = my_make_texture_handle_function; config.delete_texture_callback = my_destroy_texture_handle_function; spritebatch_t batcher; spritebatch_init(&batcher, &config); while (game_is_running) { for (int i = 0; i < sprite_count; ++i) spritebatch_push( &batcher, sprites[i].image_id, sprites[i].image_width_in_pixels, sprites[i].image_height_in_pixels, sprites[i].position_x, sprites[i].poxition_y, sprites[i].scale_x, sprites[i].scale_y, sprites[i].cos_rotation_angle, sprites[i].sin_rotation_angle ); spritebatch_tick(&batcher); spritebatch_defrag(&batcher); spritebatch_flush(&batcher); } CUSTOMIZATION: The following macros can be defined before including this header with the SPRITEBATCH_IMPLEMENTATION symbol defined, in order to customize the internal behavior of tinyspritebatch.h. Search this header to find how each macro is defined and used. Note that MALLOC/FREE functions can optionally take a context parameter for custom allocation. SPRITEBATCH_MALLOC SPRITEBATCH_MEMCPY SPRITEBATCH_MEMSET SPRITEBATCH_ASSERT SPRITEBATCH_ATLAS_FLIP_Y_AXIS_FOR_UV SPRITEBATCH_ATLAS_EMPTY_COLOR SPRITEBATCH_ALLOCA SPRITEBATCH_LOG Revision history: 0.01 (11/20/2017) experimental release 1.00 (04/14/2018) initial release */ #ifndef SPRITEBATCH_H #ifndef SPRITEBATCH_U64 #define SPRITEBATCH_U64 unsigned long long #endif SPRITEBATCH_U64 #ifndef EXTERNC # ifdef __cplusplus # define EXTERNC extern "C" # else # define EXTERNC # endif #endif typedef struct spritebatch_t spritebatch_t; typedef struct spritebatch_config_t spritebatch_config_t; typedef struct spritebatch_sprite_t spritebatch_sprite_t; //@dp EXTERNC spritebatch_t* spritebatch_create(); EXTERNC void spritebatch_destroy(spritebatch_t* sb); // Pushes a sprite onto an internal buffer. Does no other logic. `image_id` must be a unique // identifier for the image a sprite references. `image_w` and image_h` are the width and height // of the image referenced by `image_id`. `x` and `y` are the position of the sprite. `sx` and // `sy` are the scale factors on the x and y axis for the sprite. `c` and `s` are the cosine and // sine of the angle of the sprite, and represent a 2D rotation matrix. EXTERNC int spritebatch_push(spritebatch_t* sb, SPRITEBATCH_U64 image_id, int image_w, int image_h, float x, float y, float sx, float sy, float c, float s, int sort_bits); // Increments internal timestamps on all textures, for use in `spritebatch_defrag`. EXTERNC void spritebatch_tick(spritebatch_t* sb); // Sorts the internal sprites and flushes the buffer built by `spritebatch_push`. Will call // the `submit_batch_t` function for each batch of sprites and return them as an array. Any `image_id` // within the `spritebatch_push` buffer that do not yet have a texture handle will request pixels // from the image via `get_pixels_t` and request a texture handle via `generate_texture_handle_t`. EXTERNC int spritebatch_flush(spritebatch_t* sb); // All textures created so far by `spritebatch_flush` will be considered as candidates for creating // new internal texture atlases. Internal texture atlases compress images together inside of one // texture to dramatically reduce draw calls. When an atlas is created, the most recently used `image_id` // instances are prioritized, to ensure atlases are filled with images all drawn at the same time. // As some textures cease to draw on screen, they "decay" over time. Once enough images in an atlas // decay, the atlas is removed, and any "live" images in the atlas are used to create new atlases. // Can be called every 1/N times `spritebatch_flush` is called. EXTERNC int spritebatch_defrag(spritebatch_t* sb); EXTERNC int spritebatch_init(spritebatch_t* sb, spritebatch_config_t* config); EXTERNC void spritebatch_term(spritebatch_t* sb); // Sprite batches are submit via synchronous callback back to the user. This function is called // from inside `spritebatch_flush`. Each time `submit_batch_t` is called an array of sprites // is handed to the user. The sprites are intended to be further sorted by the user as desired // (for example, additional sorting based on depth). typedef void (*submit_batch_t)(spritebatch_sprite_t* sprites, int count); // tinyspritebatch.h needs to know how to get the pixels of an image, generate textures handles (for // example glGenTextures for OpenGL), and destroy texture handles. These functions are all called // from within the `spritebatch_defrag` function, and sometimes from `spritebatch_flush`. typedef void* (*get_pixels_t)(SPRITEBATCH_U64 image_id); typedef SPRITEBATCH_U64 (*generate_texture_handle_t)(void* pixels, int w, int h); typedef void (*destroy_texture_handle_t)(SPRITEBATCH_U64 texture_id); // Initializes a set of good default paramaters. The users must still set // the four callbacks inside of `config`. EXTERNC void spritebatch_set_default_config(spritebatch_config_t* config); struct spritebatch_config_t { int pixel_stride; int atlas_width_in_pixels; int atlas_height_in_pixels; int ticks_to_decay_texture; // number of ticks it takes for a texture handle to be destroyed via `destroy_texture_handle_t` int lonely_buffer_count_till_flush; // number of unique textures until an atlas is constructed float ratio_to_decay_atlas; // from 0 to 1, once ratio is less than `ratio_to_decay_atlas`, flush active textures in atlas to lonely buffer float ratio_to_merge_atlases; // from 0 to 0.5, attempts to merge atlases with some ratio of empty space submit_batch_t batch_callback; get_pixels_t get_pixels_callback; generate_texture_handle_t generate_texture_callback; destroy_texture_handle_t delete_texture_callback; void* allocator_context; }; struct spritebatch_sprite_t { SPRITEBATCH_U64 texture_id; // User-defined sorting key, see: http://realtimecollisiondetection.net/blog/?p=86 // The first 32-bits store the user's sort bits. The bottom 32-bits are for internal // usage, and are not ever set by the user. Internally sprites are sorted first // based on `sort_bits`, and to break ties they are sorted on `texture_id`. Feel free // to change the sort predicate `spritebatch_internal_instance_pred` in the // implementation section. SPRITEBATCH_U64 sort_bits; float x, y; // x and y position float sx, sy; // scale on x and y axis float c, s; // cosine and sine (represents cos(angle) and sin(angle)) float minx, miny; // u coordinate float maxx, maxy; // v coordinate }; #define SPRITEBATCH_H #endif #ifdef SPRITEBATCH_IMPLEMENTATION #undef SPRITEBATCH_IMPLEMENTATION #ifndef _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS #endif #ifndef _CRT_NONSTDC_NO_DEPRECATE #define _CRT_NONSTDC_NO_DEPRECATE #endif #ifndef SPRITEBATCH_MALLOC #include <stdlib.h> #define SPRITEBATCH_MALLOC(size, ctx) malloc(size) #define SPRITEBATCH_FREE(ptr, ctx) free(ptr) #endif #ifndef SPRITEBATCH_MEMCPY #include <string.h> #define SPRITEBATCH_MEMCPY(dst, src, n) memcpy(dst, src, n) #endif #ifndef SPRITEBATCH_MEMSET #include <string.h> #define SPRITEBATCH_MEMSET(ptr, val, n) memset(ptr, val, n) #endif #ifndef SPRITEBATCH_ASSERT #include <assert.h> #define SPRITEBATCH_ASSERT(condition) assert(condition) #endif // flips output uv coordinate's y. Can be useful to "flip image on load" #ifndef SPRITEBATCH_ATLAS_FLIP_Y_AXIS_FOR_UV #define SPRITEBATCH_ATLAS_FLIP_Y_AXIS_FOR_UV 1 #endif // flips output uv coordinate's y. Can be useful to "flip image on load" #ifndef SPRITEBATCH_LONELY_FLIP_Y_AXIS_FOR_UV #define SPRITEBATCH_LONELY_FLIP_Y_AXIS_FOR_UV 1 #endif #ifndef SPRITEBATCH_ATLAS_EMPTY_COLOR #define SPRITEBATCH_ATLAS_EMPTY_COLOR 0x000000FF #endif #ifndef SPRITEBATCH_ALLOCA #ifdef _WIN32 #include <malloc.h> #else #include <alloca.h> #endif #define SPRITEBATCH_ALLOCA(ctx, size) alloca(size) #endif #ifndef SPRITEBATCH_LOG #if 0 #define SPRITEBATCH_LOG printf #else #define SPRITEBATCH_LOG(...) #endif #endif #define HASHTABLE_MEMSET(ptr, val, n) SPRITEBATCH_MEMSET(ptr, val, n) #define HASHTABLE_MEMCPY(dst, src, n) SPRITEBATCH_MEMCPY(dst, src, n) #define HASHTABLE_MALLOC(ctx, size) SPRITEBATCH_MALLOC(size, ctx) #define HASHTABLE_FREE(ctx, ptr) SPRITEBATCH_FREE(ptr, ctx) // hashtable.h implementation by Mattias Gustavsson // See: http://www.mattiasgustavsson.com/ and https://github.com/mattiasgustavsson/libs/blob/master/hashtable.h // begin hashtable.h #ifndef HASHTABLE_U64 #define HASHTABLE_U64 SPRITEBATCH_U64 #endif #ifndef HASHTABLE_U32 #define HASHTABLE_U32 unsigned int #endif typedef struct hashtable_t hashtable_t; void hashtable_init( hashtable_t* table, int item_size, int initial_capacity, void* memctx ); void hashtable_term( hashtable_t* table ); void* hashtable_insert( hashtable_t* table, HASHTABLE_U64 key, void const* item ); void hashtable_remove( hashtable_t* table, HASHTABLE_U64 key ); void hashtable_clear( hashtable_t* table ); void* hashtable_find( hashtable_t const* table, HASHTABLE_U64 key ); int hashtable_count( hashtable_t const* table ); void* hashtable_items( hashtable_t const* table ); HASHTABLE_U64 const* hashtable_keys( hashtable_t const* table ); void hashtable_swap( hashtable_t* table, int index_a, int index_b ); struct hashtable_internal_slot_t { HASHTABLE_U32 key_hash; int item_index; int base_count; }; struct hashtable_t { void* memctx; int count; int item_size; struct hashtable_internal_slot_t* slots; int slot_capacity; HASHTABLE_U64* items_key; int* items_slot; void* items_data; int item_capacity; void* swap_temp; }; #ifndef HASHTABLE_SIZE_T #include <stddef.h> #define HASHTABLE_SIZE_T size_t #endif #ifndef HASHTABLE_ASSERT #include <assert.h> #define HASHTABLE_ASSERT( x ) assert( x ) #endif static HASHTABLE_U32 hashtable_internal_pow2ceil( HASHTABLE_U32 v ) { --v; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; ++v; v += ( v == 0 ); return v; } void hashtable_init( hashtable_t* table, int item_size, int initial_capacity, void* memctx ) { initial_capacity = (int)hashtable_internal_pow2ceil( initial_capacity >=0 ? (HASHTABLE_U32) initial_capacity : 32U ); table->memctx = memctx; table->count = 0; table->item_size = item_size; table->slot_capacity = (int) hashtable_internal_pow2ceil( (HASHTABLE_U32) ( initial_capacity + initial_capacity / 2 ) ); int slots_size = (int)( table->slot_capacity * sizeof( *table->slots ) ); table->slots = (struct hashtable_internal_slot_t*) HASHTABLE_MALLOC( table->memctx, (HASHTABLE_SIZE_T) slots_size ); HASHTABLE_ASSERT( table->slots ); HASHTABLE_MEMSET( table->slots, 0, (HASHTABLE_SIZE_T) slots_size ); table->item_capacity = (int) hashtable_internal_pow2ceil( (HASHTABLE_U32) initial_capacity ); table->items_key = (HASHTABLE_U64*) HASHTABLE_MALLOC( table->memctx, table->item_capacity * ( sizeof( *table->items_key ) + sizeof( *table->items_slot ) + table->item_size ) + table->item_size ); HASHTABLE_ASSERT( table->items_key ); table->items_slot = (int*)( table->items_key + table->item_capacity ); table->items_data = (void*)( table->items_slot + table->item_capacity ); table->swap_temp = (void*)( ( (uintptr_t) table->items_data ) + table->item_size * table->item_capacity ); } void hashtable_term( hashtable_t* table ) { HASHTABLE_FREE( table->memctx, table->items_key ); HASHTABLE_FREE( table->memctx, table->slots ); } // from https://gist.github.com/badboy/6267743 static HASHTABLE_U32 hashtable_internal_calculate_hash( HASHTABLE_U64 key ) { key = ( ~key ) + ( key << 18 ); key = key ^ ( key >> 31 ); key = key * 21; key = key ^ ( key >> 11 ); key = key + ( key << 6 ); key = key ^ ( key >> 22 ); HASHTABLE_ASSERT( key ); return (HASHTABLE_U32) key; } static int hashtable_internal_find_slot( hashtable_t const* table, HASHTABLE_U64 key ) { int const slot_mask = table->slot_capacity - 1; HASHTABLE_U32 const hash = hashtable_internal_calculate_hash( key ); int const base_slot = (int)( hash & (HASHTABLE_U32)slot_mask ); int base_count = table->slots[ base_slot ].base_count; int slot = base_slot; while( base_count > 0 ) { HASHTABLE_U32 slot_hash = table->slots[ slot ].key_hash; if( slot_hash ) { int slot_base = (int)( slot_hash & (HASHTABLE_U32)slot_mask ); if( slot_base == base_slot ) { HASHTABLE_ASSERT( base_count > 0 ); --base_count; if( slot_hash == hash && table->items_key[ table->slots[ slot ].item_index ] == key ) return slot; } } slot = ( slot + 1 ) & slot_mask; } return -1; } static void hashtable_internal_expand_slots( hashtable_t* table ) { int const old_capacity = table->slot_capacity; struct hashtable_internal_slot_t* old_slots = table->slots; table->slot_capacity *= 2; int const slot_mask = table->slot_capacity - 1; int const size = (int)( table->slot_capacity * sizeof( *table->slots ) ); table->slots = (struct hashtable_internal_slot_t*) HASHTABLE_MALLOC( table->memctx, (HASHTABLE_SIZE_T) size ); HASHTABLE_ASSERT( table->slots ); HASHTABLE_MEMSET( table->slots, 0, (HASHTABLE_SIZE_T) size ); for( int i = 0; i < old_capacity; ++i ) { HASHTABLE_U32 const hash = old_slots[ i ].key_hash; if( hash ) { int const base_slot = (int)( hash & (HASHTABLE_U32)slot_mask ); int slot = base_slot; while( table->slots[ slot ].key_hash ) slot = ( slot + 1 ) & slot_mask; table->slots[ slot ].key_hash = hash; int item_index = old_slots[ i ].item_index; table->slots[ slot ].item_index = item_index; table->items_slot[ item_index ] = slot; ++table->slots[ base_slot ].base_count; } } HASHTABLE_FREE( table->memctx, old_slots ); } static void hashtable_internal_expand_items( hashtable_t* table ) { table->item_capacity *= 2; HASHTABLE_U64* const new_items_key = (HASHTABLE_U64*) HASHTABLE_MALLOC( table->memctx, table->item_capacity * ( sizeof( *table->items_key ) + sizeof( *table->items_slot ) + table->item_size ) + table->item_size); HASHTABLE_ASSERT( new_items_key ); int* const new_items_slot = (int*)( new_items_key + table->item_capacity ); void* const new_items_data = (void*)( new_items_slot + table->item_capacity ); void* const new_swap_temp = (void*)( ( (uintptr_t) new_items_data ) + table->item_size * table->item_capacity ); HASHTABLE_MEMCPY( new_items_key, table->items_key, table->count * sizeof( *table->items_key ) ); HASHTABLE_MEMCPY( new_items_slot, table->items_slot, table->count * sizeof( *table->items_key ) ); HASHTABLE_MEMCPY( new_items_data, table->items_data, (HASHTABLE_SIZE_T) table->count * table->item_size ); HASHTABLE_FREE( table->memctx, table->items_key ); table->items_key = new_items_key; table->items_slot = new_items_slot; table->items_data = new_items_data; table->swap_temp = new_swap_temp; } void* hashtable_insert( hashtable_t* table, HASHTABLE_U64 key, void const* item ) { HASHTABLE_ASSERT( hashtable_internal_find_slot( table, key ) < 0 ); if( table->count >= ( table->slot_capacity - table->slot_capacity / 3 ) ) hashtable_internal_expand_slots( table ); int const slot_mask = table->slot_capacity - 1; HASHTABLE_U32 const hash = hashtable_internal_calculate_hash( key ); int const base_slot = (int)( hash & (HASHTABLE_U32)slot_mask ); int base_count = table->slots[ base_slot ].base_count; int slot = base_slot; int first_free = slot; while( base_count ) { HASHTABLE_U32 const slot_hash = table->slots[ slot ].key_hash; if( slot_hash == 0 && table->slots[ first_free ].key_hash != 0 ) first_free = slot; int slot_base = (int)( slot_hash & (HASHTABLE_U32)slot_mask ); if( slot_base == base_slot ) --base_count; slot = ( slot + 1 ) & slot_mask; } slot = first_free; while( table->slots[ slot ].key_hash ) slot = ( slot + 1 ) & slot_mask; if( table->count >= table->item_capacity ) hashtable_internal_expand_items( table ); HASHTABLE_ASSERT( !table->slots[ slot ].key_hash && ( hash & (HASHTABLE_U32) slot_mask ) == (HASHTABLE_U32) base_slot ); HASHTABLE_ASSERT( hash ); table->slots[ slot ].key_hash = hash; table->slots[ slot ].item_index = table->count; ++table->slots[ base_slot ].base_count; void* dest_item = (void*)( ( (uintptr_t) table->items_data ) + table->count * table->item_size ); memcpy( dest_item, item, (HASHTABLE_SIZE_T) table->item_size ); table->items_key[ table->count ] = key; table->items_slot[ table->count ] = slot; ++table->count; return dest_item; } void hashtable_remove( hashtable_t* table, HASHTABLE_U64 key ) { int const slot = hashtable_internal_find_slot( table, key ); HASHTABLE_ASSERT( slot >= 0 ); int const slot_mask = table->slot_capacity - 1; HASHTABLE_U32 const hash = table->slots[ slot ].key_hash; int const base_slot = (int)( hash & (HASHTABLE_U32) slot_mask ); HASHTABLE_ASSERT( hash ); --table->slots[ base_slot ].base_count; table->slots[ slot ].key_hash = 0; int index = table->slots[ slot ].item_index; int last_index = table->count - 1; if( index != last_index ) { table->items_key[ index ] = table->items_key[ last_index ]; table->items_slot[ index ] = table->items_slot[ last_index ]; void* dst_item = (void*)( ( (uintptr_t) table->items_data ) + index * table->item_size ); void* src_item = (void*)( ( (uintptr_t) table->items_data ) + last_index * table->item_size ); HASHTABLE_MEMCPY( dst_item, src_item, (HASHTABLE_SIZE_T) table->item_size ); table->slots[ table->items_slot[ last_index ] ].item_index = index; } --table->count; } void* hashtable_find( hashtable_t const* table, HASHTABLE_U64 key ) { int const slot = hashtable_internal_find_slot( table, key ); if( slot < 0 ) return 0; int const index = table->slots[ slot ].item_index; void* const item = (void*)( ( (uintptr_t) table->items_data ) + index * table->item_size ); return item; } void hashtable_clear( hashtable_t* table ) { table->count = 0; HASHTABLE_MEMSET( table->slots, 0, table->slot_capacity * sizeof( *table->slots ) ); } int hashtable_count( hashtable_t const* table ) { return table->count; } void* hashtable_items( hashtable_t const* table ) { return table->items_data; } HASHTABLE_U64 const* hashtable_keys( hashtable_t const* table ) { return table->items_key; } void hashtable_swap( hashtable_t* table, int index_a, int index_b ) { if( index_a < 0 || index_a >= table->count || index_b < 0 || index_b >= table->count ) return; int slot_a = table->items_slot[ index_a ]; int slot_b = table->items_slot[ index_b ]; table->items_slot[ index_a ] = slot_b; table->items_slot[ index_b ] = slot_a; HASHTABLE_U64 temp_key = table->items_key[ index_a ]; table->items_key[ index_a ] = table->items_key[ index_b ]; table->items_key[ index_b ] = temp_key; void* item_a = (void*)( ( (uintptr_t) table->items_data ) + index_a * table->item_size ); void* item_b = (void*)( ( (uintptr_t) table->items_data ) + index_b * table->item_size ); HASHTABLE_MEMCPY( table->swap_temp, item_a, table->item_size ); HASHTABLE_MEMCPY( item_a, item_b, table->item_size ); HASHTABLE_MEMCPY( item_b, table->swap_temp, table->item_size ); table->slots[ slot_a ].item_index = index_b; table->slots[ slot_b ].item_index = index_a; } // end of hashtable.h typedef struct { SPRITEBATCH_U64 image_id; SPRITEBATCH_U64 sort_bits; int w; int h; float x, y; float sx, sy; float c, s; } spritebatch_internal_sprite_t; typedef struct { int timestamp; int w, h; float minx, miny; float maxx, maxy; SPRITEBATCH_U64 image_id; } spritebatch_internal_texture_t; typedef struct spritebatch_internal_atlas_t { SPRITEBATCH_U64 texture_id; float volume_ratio; hashtable_t sprites_to_textures; struct spritebatch_internal_atlas_t* next; struct spritebatch_internal_atlas_t* prev; } spritebatch_internal_atlas_t; typedef struct { int timestamp; int w, h; SPRITEBATCH_U64 image_id; SPRITEBATCH_U64 texture_id; } spritebatch_internal_lonely_texture_t; struct spritebatch_t { int input_count; int input_capacity; spritebatch_internal_sprite_t* input_buffer; int sprite_count; int sprite_capacity; spritebatch_sprite_t* sprites; int key_buffer_count; int key_buffer_capacity; SPRITEBATCH_U64* key_buffer; hashtable_t sprites_to_lonely_textures; hashtable_t sprites_to_atlases; spritebatch_internal_atlas_t* atlases; int pixel_stride; int atlas_width_in_pixels; int atlas_height_in_pixels; int ticks_to_decay_texture; int lonely_buffer_count_till_flush; int lonely_buffer_count_till_decay; float ratio_to_decay_atlas; float ratio_to_merge_atlases; submit_batch_t batch_callback; get_pixels_t get_pixels_callback; generate_texture_handle_t generate_texture_callback; destroy_texture_handle_t delete_texture_callback; void* mem_ctx; }; //@dp spritebatch_t* spritebatch_create() { spritebatch_t* batch = (spritebatch_t*)malloc(sizeof(spritebatch_t)); memset(batch, 0, sizeof(spritebatch_t)); return batch; } //@dp void spritebatch_destroy(spritebatch_t* sb) { if (sb) free(sb); } int spritebatch_init(spritebatch_t* sb, spritebatch_config_t* config) { // read config params if (!config | !sb) return 1; sb->pixel_stride = config->pixel_stride; sb->atlas_width_in_pixels = config->atlas_width_in_pixels; sb->atlas_height_in_pixels = config->atlas_height_in_pixels; sb->ticks_to_decay_texture = config->ticks_to_decay_texture; sb->lonely_buffer_count_till_flush = config->lonely_buffer_count_till_flush; sb->lonely_buffer_count_till_decay = sb->lonely_buffer_count_till_flush / 2; if (sb->lonely_buffer_count_till_decay <= 0) sb->lonely_buffer_count_till_decay = 1; sb->ratio_to_decay_atlas = config->ratio_to_decay_atlas; sb->ratio_to_merge_atlases = config->ratio_to_merge_atlases; sb->batch_callback = config->batch_callback; sb->get_pixels_callback = config->get_pixels_callback; sb->generate_texture_callback = config->generate_texture_callback; sb->delete_texture_callback = config->delete_texture_callback; sb->mem_ctx = config->allocator_context; if (sb->atlas_width_in_pixels < 1 || sb->atlas_height_in_pixels < 1) return 1; if (sb->ticks_to_decay_texture < 1) return 1; if (sb->ratio_to_decay_atlas < 0 || sb->ratio_to_decay_atlas > 1.0f) return 1; if (sb->ratio_to_merge_atlases < 0 || sb->ratio_to_merge_atlases > 0.5f) return 1; if (!sb->batch_callback) return 1; if (!sb->get_pixels_callback) return 1; if (!sb->generate_texture_callback) return 1; if (!sb->delete_texture_callback) return 1; // initialize input buffer sb->input_count = 0; sb->input_capacity = 1024; sb->input_buffer = (spritebatch_internal_sprite_t*)SPRITEBATCH_MALLOC(sizeof(spritebatch_internal_sprite_t) * sb->input_capacity, sb->mem_ctx); if (!sb->input_buffer) return 1; // initialize sprite buffer sb->sprite_count = 0; sb->sprite_capacity = 1024; sb->sprites = (spritebatch_sprite_t*)SPRITEBATCH_MALLOC(sizeof(spritebatch_sprite_t) * sb->sprite_capacity, sb->mem_ctx); if (!sb->sprites) return 1; // initialize key buffer (for marking hash table entries for deletion) sb->key_buffer_count = 0; sb->key_buffer_capacity = 1024; sb->key_buffer = (SPRITEBATCH_U64*)SPRITEBATCH_MALLOC(sizeof(SPRITEBATCH_U64) * sb->key_buffer_capacity, sb->mem_ctx); // setup tables hashtable_init(&sb->sprites_to_lonely_textures, sizeof(spritebatch_internal_lonely_texture_t), 1024, sb->mem_ctx); hashtable_init(&sb->sprites_to_atlases, sizeof(spritebatch_internal_atlas_t*), 16, sb->mem_ctx); sb->atlases = 0; return 0; } void spritebatch_term(spritebatch_t* sb) { SPRITEBATCH_FREE(sb->input_buffer, sb->mem_ctx); SPRITEBATCH_FREE(sb->sprites, sb->mem_ctx); SPRITEBATCH_FREE(sb->key_buffer, sb->mem_ctx); hashtable_term(&sb->sprites_to_lonely_textures); hashtable_term(&sb->sprites_to_atlases); if (sb->atlases) { spritebatch_internal_atlas_t* atlas = sb->atlases; spritebatch_internal_atlas_t* sentinel = sb->atlases; do { hashtable_term(&atlas->sprites_to_textures); spritebatch_internal_atlas_t* next = atlas->next; SPRITEBATCH_FREE(atlas, sb->mem_ctx); atlas = next; } while (atlas != sentinel); } SPRITEBATCH_MEMSET(sb, 0, sizeof(spritebatch_t)); } void spritebatch_set_default_config(spritebatch_config_t* config) { config->pixel_stride = sizeof(char) * 4; config->atlas_width_in_pixels = 1024; config->atlas_height_in_pixels = 1024; config->ticks_to_decay_texture = 60 * 30; config->lonely_buffer_count_till_flush = 64; config->ratio_to_decay_atlas = 0.5f; config->ratio_to_merge_atlases = 0.25f; config->batch_callback = 0; config->generate_texture_callback = 0; config->delete_texture_callback = 0; config->allocator_context = 0; } #define SPRITEBATCH_CHECK_BUFFER_GROW(ctx, count, capacity, data, type_size) \ do { \ if (ctx->count == ctx->capacity) \ { \ int new_capacity = ctx->capacity * 2; \ void* new_data = SPRITEBATCH_MALLOC(new_capacity, ctx->mem_ctx); \ if (!new_data) return 0; \ SPRITEBATCH_MEMCPY(new_data, ctx->data, type_size * ctx->count); \ SPRITEBATCH_FREE(ctx->data, ctx->mem_ctx); \ ctx->data = new_data; \ ctx->capacity = new_capacity; \ } \ } while (0) static SPRITEBATCH_U64 spritebatch_make_sort_key(int index, int sort_bits) { return (((SPRITEBATCH_U64)sort_bits) << 32) | ((SPRITEBATCH_U64)index); } int spritebatch_push(spritebatch_t* sb, SPRITEBATCH_U64 image_id, int w, int h, float x, float y, float sx, float sy, float c, float s, int sort_bits) { SPRITEBATCH_CHECK_BUFFER_GROW(sb, input_count, input_capacity, input_buffer, sizeof(spritebatch_internal_sprite_t)); spritebatch_internal_sprite_t sprite; sprite.image_id = image_id; sprite.sort_bits = spritebatch_make_sort_key(sb->input_count, sort_bits); sprite.w = w; sprite.h = h; sprite.x = x; sprite.y = y; sprite.sx = sx; sprite.sy = sy; sprite.c = c; sprite.s = s; sb->input_buffer[sb->input_count++] = sprite; return 1; } static int spritebatch_internal_instance_pred(spritebatch_sprite_t* a, spritebatch_sprite_t* b) { if (a->sort_bits < b->sort_bits) return 1; else if(a->sort_bits == b->sort_bits) return a->texture_id < b->texture_id; else return 0; } static void spritebatch_internal_qsort_sprites(spritebatch_sprite_t* items, int count) { if (count <= 1) return; spritebatch_sprite_t pivot = items[count - 1]; int low = 0; for (int i = 0; i < count - 1; ++i) { if (spritebatch_internal_instance_pred(items + i, &pivot)) { spritebatch_sprite_t tmp = items[i]; items[i] = items[low]; items[low] = tmp; low++; } } items[count - 1] = items[low]; items[low] = pivot; spritebatch_internal_qsort_sprites(items, low); spritebatch_internal_qsort_sprites(items + low + 1, count - 1 - low); } spritebatch_internal_lonely_texture_t* spritebatch_internal_lonelybuffer_push(spritebatch_t* sb, SPRITEBATCH_U64 image_id, int w, int h, int make_tex) { spritebatch_internal_lonely_texture_t texture; texture.timestamp = 0; texture.w = w; texture.h = h; texture.image_id = image_id; texture.texture_id = make_tex ? sb->generate_texture_callback(sb->get_pixels_callback(image_id), w, h) : ~0; return (spritebatch_internal_lonely_texture_t*)hashtable_insert(&sb->sprites_to_lonely_textures, image_id, &texture); } int spritebatch_internal_lonely_sprite(spritebatch_t* sb, spritebatch_internal_sprite_t* s, spritebatch_sprite_t* sprite, int skip_missing_textures) { spritebatch_internal_lonely_texture_t* tex = (spritebatch_internal_lonely_texture_t*)hashtable_find(&sb->sprites_to_lonely_textures, s->image_id); if (skip_missing_textures) { if (!tex) spritebatch_internal_lonelybuffer_push(sb, s->image_id, s->w, s->h, 0); return 1; } else { if (!tex) tex = spritebatch_internal_lonelybuffer_push(sb, s->image_id, s->w, s->h, 1); else if (tex->texture_id == ~0) tex->texture_id = sb->generate_texture_callback(sb->get_pixels_callback(s->image_id), s->w, s->h); tex->timestamp = 0; sprite->texture_id = tex->texture_id; sprite->minx = sprite->miny = 0; sprite->maxx = sprite->maxy = 1.0f; if (SPRITEBATCH_LONELY_FLIP_Y_AXIS_FOR_UV) { float tmp = sprite->miny; sprite->miny = sprite->maxy; sprite->maxy = tmp; } return 0; } } int spritebatch_internal_push_sprite(spritebatch_t* sb, spritebatch_internal_sprite_t* s, int skip_missing_textures) { int skipped_tex = 0; spritebatch_sprite_t sprite; sprite.sort_bits = s->sort_bits; sprite.x = s->x; sprite.y = s->y; sprite.sx = s->sx; sprite.sy = s->sy; sprite.c = s->c; sprite.s = s->s; void* atlas_ptr = hashtable_find(&sb->sprites_to_atlases, s->image_id); if (atlas_ptr) { spritebatch_internal_atlas_t* atlas = *(spritebatch_internal_atlas_t**)atlas_ptr; sprite.texture_id = atlas->texture_id; spritebatch_internal_texture_t* tex = (spritebatch_internal_texture_t*)hashtable_find(&atlas->sprites_to_textures, s->image_id); SPRITEBATCH_ASSERT(tex); tex->timestamp = 0; tex->w = s->w; tex->h = s->h; sprite.minx = tex->minx; sprite.miny = tex->miny; sprite.maxx = tex->maxx; sprite.maxy = tex->maxy; } else skipped_tex = spritebatch_internal_lonely_sprite(sb, s, &sprite, skip_missing_textures); if (!skipped_tex) { SPRITEBATCH_CHECK_BUFFER_GROW(sb, sprite_count, sprite_capacity, sprites, sizeof(spritebatch_sprite_t)); sb->sprites[sb->sprite_count++] = sprite; } return skipped_tex; } void spritebatch_internal_process_input(spritebatch_t* sb, int skip_missing_textures) { int skipped_index = 0; for (int i = 0; i < sb->input_count; ++i) { spritebatch_internal_sprite_t* s = sb->input_buffer + i; int skipped = spritebatch_internal_push_sprite(sb, s, skip_missing_textures); if (skip_missing_textures && skipped) sb->input_buffer[skipped_index++] = *s; } sb->input_count = skipped_index; } void spritebatch_tick(spritebatch_t* sb) { spritebatch_internal_atlas_t* atlas = sb->atlases; if (atlas) { spritebatch_internal_atlas_t* sentinel = atlas; do { int texture_count = hashtable_count(&atlas->sprites_to_textures); spritebatch_internal_texture_t* textures = (spritebatch_internal_texture_t*)hashtable_items(&atlas->sprites_to_textures); for (int i = 0; i < texture_count; ++i) textures[i].timestamp += 1; atlas = atlas->next; } while (atlas != sentinel); } int texture_count = hashtable_count(&sb->sprites_to_lonely_textures); spritebatch_internal_lonely_texture_t* lonely_textures = (spritebatch_internal_lonely_texture_t*)hashtable_items(&sb->sprites_to_lonely_textures); for (int i = 0; i < texture_count; ++i) lonely_textures[i].timestamp += 1; } int spritebatch_flush(spritebatch_t* sb) { // process input buffer, make any necessary lonely textures // convert user sprites to internal format // lookup uv coordinates spritebatch_internal_process_input(sb, 0); // patchup any missing lonely textures that may have come from atlases decaying and whatnot int texture_count = hashtable_count(&sb->sprites_to_lonely_textures); spritebatch_internal_lonely_texture_t* lonely_textures = (spritebatch_internal_lonely_texture_t*)hashtable_items(&sb->sprites_to_lonely_textures); for (int i = 0; i < texture_count; ++i) { spritebatch_internal_lonely_texture_t* lonely = lonely_textures + i; if (lonely->texture_id == ~0) lonely->texture_id = sb->generate_texture_callback(sb->get_pixels_callback(lonely->image_id), lonely->w, lonely->h); } // sort internal sprite buffer and submit batches spritebatch_internal_qsort_sprites(sb->sprites, sb->sprite_count); int min = 0; int max = 0; int done = !sb->sprite_count; int count = 0; while (!done) { SPRITEBATCH_U64 id = sb->sprites[min].texture_id; while (1) { if (max == sb->sprite_count) { done = 1; break; } if (id != sb->sprites[max].texture_id) break; ++max; } int batch_count = max - min; if (batch_count) { sb->batch_callback(sb->sprites + min, batch_count); ++count; } min = max; } sb->sprite_count = 0; return count; } typedef struct { int x; int y; } spritebatch_v2_t; typedef struct { int img_index; spritebatch_v2_t size; spritebatch_v2_t min; spritebatch_v2_t max; int fit; } spritebatch_internal_integer_image_t; static spritebatch_v2_t spritebatch_v2(int x, int y) { spritebatch_v2_t v; v.x = x; v.y = y; return v; } static spritebatch_v2_t spritebatch_sub(spritebatch_v2_t a, spritebatch_v2_t b) { spritebatch_v2_t v; v.x = a.x - b.x; v.y = a.y - b.y; return v; } static spritebatch_v2_t spritebatch_add(spritebatch_v2_t a, spritebatch_v2_t b) { spritebatch_v2_t v; v.x = a.x + b.x; v.y = a.y + b.y; return v; } typedef struct { spritebatch_v2_t size; spritebatch_v2_t min; spritebatch_v2_t max; } spritebatch_internal_atlas_node_t; static spritebatch_internal_atlas_node_t* spritebatch_best_fit(int sp, int w, int h, spritebatch_internal_atlas_node_t* nodes) { int best_volume = INT_MAX; spritebatch_internal_atlas_node_t *best_node = 0; int img_volume = w * h; for ( int i = 0; i < sp; ++i ) { spritebatch_internal_atlas_node_t *node = nodes + i; int can_contain = node->size.x >= w && node->size.y >= h; if ( can_contain ) { int node_volume = node->size.x * node->size.y; if ( node_volume == img_volume ) return node; if ( node_volume < best_volume ) { best_volume = node_volume; best_node = node; } } } return best_node; } static int spritebatch_internal_perimeter_pred(spritebatch_internal_integer_image_t* a, spritebatch_internal_integer_image_t* b) { int perimeterA = 2 * (a->size.x + a->size.y); int perimeterB = 2 * (b->size.x + b->size.y); return perimeterB < perimeterA; } static void spritebatch_internal_image_sort(spritebatch_internal_integer_image_t* items, int count) { if (count <= 1) return; spritebatch_internal_integer_image_t pivot = items[count - 1]; int low = 0; for (int i = 0; i < count - 1; ++i) { if (spritebatch_internal_perimeter_pred(items + i, &pivot)) { spritebatch_internal_integer_image_t tmp = items[i]; items[i] = items[low]; items[low] = tmp; low++; } } items[count - 1] = items[low]; items[low] = pivot; spritebatch_internal_image_sort(items, low); spritebatch_internal_image_sort(items + low + 1, count - 1 - low); } typedef struct { int img_index; // index into the `imgs` array int w, h; // pixel w/h of original image float minx, miny; // u coordinate float maxx, maxy; // v coordinate int fit; // non-zero if image fit and was placed into the atlas } spritebatch_internal_atlas_image_t; #define SPRITEBATCH_CHECK( X, Y ) do { if ( !(X) ) { SPRITEBATCH_LOG(Y); goto sb_err; } } while ( 0 ) void spritebatch_make_atlas(spritebatch_t* sb, spritebatch_internal_atlas_t* atlas_out, const spritebatch_internal_lonely_texture_t* imgs, int img_count) { float w0, h0, div, wTol, hTol; int atlas_image_size, atlas_stride, sp; void* atlas_pixels = 0; int atlas_node_capacity = img_count * 2; spritebatch_internal_integer_image_t* images = 0; spritebatch_internal_atlas_node_t* nodes = 0; int pixel_stride = sb->pixel_stride; int atlas_width = sb->atlas_width_in_pixels; int atlas_height = sb->atlas_height_in_pixels; float volume_used = 0; images = (spritebatch_internal_integer_image_t*)SPRITEBATCH_MALLOC(sizeof(spritebatch_internal_integer_image_t) * img_count, sb->mem_ctx); nodes = (spritebatch_internal_atlas_node_t*)SPRITEBATCH_MALLOC(sizeof(spritebatch_internal_atlas_node_t) * atlas_node_capacity, sb->mem_ctx); SPRITEBATCH_CHECK(images, "out of mem"); SPRITEBATCH_CHECK(nodes, "out of mem"); for (int i = 0; i < img_count; ++i) { const spritebatch_internal_lonely_texture_t* img = imgs + i; spritebatch_internal_integer_image_t* image = images + i; image->fit = 0; image->size = spritebatch_v2(img->w, img->h); image->img_index = i; } // Sort PNGs from largest to smallest spritebatch_internal_image_sort(images, img_count); // stack pointer, the stack is the nodes array which we will // allocate nodes from as necessary. sp = 1; nodes[0].min = spritebatch_v2(0, 0 ); nodes[0].max = spritebatch_v2(atlas_width, atlas_height); nodes[0].size = spritebatch_v2(atlas_width, atlas_height); // Nodes represent empty space in the atlas. Placing a texture into the // atlas involves splitting a node into two smaller pieces (or, if a // perfect fit is found, deleting the node). for (int i = 0; i < img_count; ++i) { spritebatch_internal_integer_image_t* image = images + i; const spritebatch_internal_lonely_texture_t* img = imgs + image->img_index; int width = img->w; int height = img->h; spritebatch_internal_atlas_node_t *best_fit = spritebatch_best_fit(sp, img->w, img->h, nodes); image->min = best_fit->min; image->max = spritebatch_add(image->min, image->size); if (best_fit->size.x == width && best_fit->size.y == height) { spritebatch_internal_atlas_node_t* last_node = nodes + --sp; *best_fit = *last_node; image->fit = 1; continue; } image->fit = 1; if (sp == atlas_node_capacity) { int new_capacity = atlas_node_capacity * 2; spritebatch_internal_atlas_node_t* new_nodes = (spritebatch_internal_atlas_node_t*)SPRITEBATCH_MALLOC(sizeof(spritebatch_internal_atlas_node_t) * new_capacity, mem_ctx); SPRITEBATCH_CHECK(new_nodes, "out of mem"); memcpy(new_nodes, nodes, sizeof(spritebatch_internal_atlas_node_t) * sp); SPRITEBATCH_FREE(nodes, mem_ctx); nodes = new_nodes; atlas_node_capacity = new_capacity; } spritebatch_internal_atlas_node_t* new_node = nodes + sp++; new_node->min = best_fit->min; // Split bestFit along x or y, whichever minimizes // fragmentation of empty space spritebatch_v2_t d = spritebatch_sub(best_fit->size, spritebatch_v2(width, height)); if (d.x < d.y) { new_node->size.x = d.x; new_node->size.y = height; new_node->min.x += width; best_fit->size.y = d.y; best_fit->min.y += height; } else { new_node->size.x = width; new_node->size.y = d.y; new_node->min.y += height; best_fit->size.x = d.x; best_fit->min.x += width; } new_node->max = spritebatch_add(new_node->min, new_node->size); } // Write the final atlas image, use SPRITEBATCH_ATLAS_EMPTY_COLOR as base color atlas_stride = atlas_width * pixel_stride; atlas_image_size = atlas_width * atlas_height * pixel_stride; atlas_pixels = SPRITEBATCH_MALLOC(atlas_image_size, mem_ctx); SPRITEBATCH_CHECK(atlas_image_size, "out of mem"); memset(atlas_pixels, SPRITEBATCH_ATLAS_EMPTY_COLOR, atlas_image_size); for (int i = 0; i < img_count; ++i) { spritebatch_internal_integer_image_t* image = images + i; if (image->fit) { const spritebatch_internal_lonely_texture_t* img = imgs + image->img_index; char* pixels = (char*)sb->get_pixels_callback(img->image_id); spritebatch_v2_t min = image->min; spritebatch_v2_t max = image->max; int atlas_offset = min.x * pixel_stride; int tex_stride = img->w * pixel_stride; for (int row = min.y, y = 0; row < max.y; ++row, ++y) { void* row_ptr = (char*)atlas_pixels + (row * atlas_stride + atlas_offset); SPRITEBATCH_MEMCPY(row_ptr, pixels + y * tex_stride, tex_stride); } } } hashtable_init(&atlas_out->sprites_to_textures, sizeof(spritebatch_internal_texture_t), img_count, sb->mem_ctx); atlas_out->texture_id = sb->generate_texture_callback(atlas_pixels, atlas_width, atlas_height); // squeeze UVs inward by 128th of a pixel // this prevents atlas bleeding. tune as necessary for good results. w0 = 1.0f / (float)(atlas_width); h0 = 1.0f / (float)(atlas_height); div = 1.0f / 128.0f; wTol = w0 * div; hTol = h0 * div; for (int i = 0; i < img_count; ++i) { spritebatch_internal_integer_image_t* img = images + i; if (img->fit) { spritebatch_v2_t min = img->min; spritebatch_v2_t max = img->max; volume_used += img->size.x * img->size.y; float min_x = (float)min.x * w0 + wTol; float min_y = (float)min.y * h0 + hTol; float max_x = (float)max.x * w0 - wTol; float max_y = (float)max.y * h0 - hTol; // flip image on y axis if (SPRITEBATCH_ATLAS_FLIP_Y_AXIS_FOR_UV) { float tmp = min_y; min_y = max_y; max_y = tmp; } spritebatch_internal_texture_t texture; texture.w = img->size.x; texture.h = img->size.y; texture.timestamp = 0; texture.minx = min_x; texture.miny = min_y; texture.maxx = max_x; texture.maxy = max_y; SPRITEBATCH_ASSERT(!(img->size.x < 0)); SPRITEBATCH_ASSERT(!(img->size.y < 0)); SPRITEBATCH_ASSERT(!(min_x < 0)); SPRITEBATCH_ASSERT(!(max_x < 0)); SPRITEBATCH_ASSERT(!(min_y < 0)); SPRITEBATCH_ASSERT(!(max_y < 0)); texture.image_id = imgs[img->img_index].image_id; hashtable_insert(&atlas_out->sprites_to_textures, texture.image_id, &texture); } } // Need to adjust atlas_width and atlas_height in config params, as none of the images for this // atlas actually fit inside of the atlas! Either adjust the config, or stop sending giant images // to the sprite batcher. SPRITEBATCH_ASSERT(volume_used > 0); atlas_out->volume_ratio = volume_used / (atlas_width * atlas_height); sb_err: // no specific error handling needed here (yet) SPRITEBATCH_FREE(atlas_pixels, mem_ctx); SPRITEBATCH_FREE(nodes, mem_ctx); SPRITEBATCH_FREE(images, mem_ctx); return; } static int spritebatch_internal_lonely_pred(spritebatch_internal_lonely_texture_t* a, spritebatch_internal_lonely_texture_t* b) { return a->timestamp < b->timestamp; } static void spritebatch_internal_qsort_lonely(hashtable_t* lonely_table, spritebatch_internal_lonely_texture_t* items, int count) { if (count <= 1) return; spritebatch_internal_lonely_texture_t pivot = items[count - 1]; int low = 0; for (int i = 0; i < count - 1; ++i) { if (spritebatch_internal_lonely_pred(items + i, &pivot)) { hashtable_swap(lonely_table, i, low); low++; } } hashtable_swap(lonely_table, low, count - 1); spritebatch_internal_qsort_lonely(lonely_table, items, low); spritebatch_internal_qsort_lonely(lonely_table, items + low + 1, count - 1 - low); } int spritebatch_internal_buffer_key(spritebatch_t* sb, SPRITEBATCH_U64 key) { SPRITEBATCH_CHECK_BUFFER_GROW(sb, key_buffer_count, key_buffer_capacity, key_buffer, sizeof(SPRITEBATCH_U64)); sb->key_buffer[sb->key_buffer_count++] = key; return 0; } void spritebatch_internal_remove_table_entries(spritebatch_t* sb, hashtable_t* table) { for (int i = 0; i < sb->key_buffer_count; ++i) hashtable_remove(table, sb->key_buffer[i]); sb->key_buffer_count = 0; } void spritebatch_internal_flush_atlas(spritebatch_t* sb, spritebatch_internal_atlas_t* atlas, spritebatch_internal_atlas_t** sentinel, spritebatch_internal_atlas_t** next) { int ticks_to_decay_texture = sb->ticks_to_decay_texture; int texture_count = hashtable_count(&atlas->sprites_to_textures); spritebatch_internal_texture_t* textures = (spritebatch_internal_texture_t*)hashtable_items(&atlas->sprites_to_textures); for (int i = 0; i < texture_count; ++i) { spritebatch_internal_texture_t* atlas_texture = textures + i; if (atlas_texture->timestamp < ticks_to_decay_texture) { spritebatch_internal_lonely_texture_t* lonely_texture = spritebatch_internal_lonelybuffer_push(sb, atlas_texture->image_id, atlas_texture->w, atlas_texture->h, 0); lonely_texture->timestamp = atlas_texture->timestamp; } hashtable_remove(&sb->sprites_to_atlases, atlas_texture->image_id); } if (sb->atlases == atlas) { if (atlas->next == atlas) sb->atlases = 0; else sb->atlases = atlas->prev; } // handle loop end conditions if sentinel was removed from the chain if (sentinel && next) { if (*sentinel == atlas) { SPRITEBATCH_LOG("\t\tsentinel was also atlas: %p\n", *sentinel); if ((*next)->next != *sentinel) { SPRITEBATCH_LOG("\t\t*next = (*next)->next : %p = (*next)->%p\n", *next, (*next)->next); *next = (*next)->next; } SPRITEBATCH_LOG("\t\t*sentinel = *next : %p = %p\n", *sentinel, *next); *sentinel = *next; } } atlas->next->prev = atlas->prev; atlas->prev->next = atlas->next; hashtable_term(&atlas->sprites_to_textures); sb->delete_texture_callback(atlas->texture_id); SPRITEBATCH_FREE(atlas, sb->mem_ctx); } void spritebatch_internal_log_chain(spritebatch_internal_atlas_t* atlas) { if (atlas) { spritebatch_internal_atlas_t* sentinel = atlas; SPRITEBATCH_LOG("sentinel: %p\n", sentinel); do { spritebatch_internal_atlas_t* next = atlas->next; SPRITEBATCH_LOG("\tatlas %p\n", atlas); atlas = next; } while (atlas != sentinel); } } int spritebatch_defrag(spritebatch_t* sb) { // remove decayed atlases and flush them to the lonely buffer // only flush textures that are not decayed int ticks_to_decay_texture = sb->ticks_to_decay_texture; float ratio_to_decay_atlas = sb->ratio_to_decay_atlas; spritebatch_internal_atlas_t* atlas = sb->atlases; if (atlas) { spritebatch_internal_log_chain(atlas); spritebatch_internal_atlas_t* sentinel = atlas; do { spritebatch_internal_atlas_t* next = atlas->next; int texture_count = hashtable_count(&atlas->sprites_to_textures); spritebatch_internal_texture_t* textures = (spritebatch_internal_texture_t*)hashtable_items(&atlas->sprites_to_textures); int decayed_texture_count = 0; for (int i = 0; i < texture_count; ++i) if (textures[i].timestamp >= ticks_to_decay_texture) decayed_texture_count++; float ratio; if (!decayed_texture_count) ratio = 0; else ratio = (float)texture_count / (float)decayed_texture_count; if (ratio > ratio_to_decay_atlas) { SPRITEBATCH_LOG("flushed atlas %p\n", atlas); spritebatch_internal_flush_atlas(sb, atlas, &sentinel, &next); } atlas = next; } while (atlas != sentinel); } // merge mostly empty atlases float ratio_to_merge_atlases = sb->ratio_to_merge_atlases; atlas = sb->atlases; if (atlas) { int sp = 0; spritebatch_internal_atlas_t* merge_stack[2]; spritebatch_internal_atlas_t* sentinel = atlas; do { spritebatch_internal_atlas_t* next = atlas->next; SPRITEBATCH_ASSERT(sp >= 0 && sp <= 2); if (sp == 2) { SPRITEBATCH_LOG("merged 2 atlases\n"); spritebatch_internal_flush_atlas(sb, merge_stack[0], &sentinel, &next); spritebatch_internal_flush_atlas(sb, merge_stack[1], &sentinel, &next); sp = 0; } float ratio = atlas->volume_ratio; if (ratio < ratio_to_merge_atlases) merge_stack[sp++] = atlas; atlas = next; } while (atlas != sentinel); if (sp == 2) { SPRITEBATCH_LOG("merged 2 atlases (out of loop)\n"); spritebatch_internal_flush_atlas(sb, merge_stack[0], 0, 0); spritebatch_internal_flush_atlas(sb, merge_stack[1], 0, 0); } } // remove decayed textures from the lonely buffer int lonely_buffer_count_till_decay = sb->lonely_buffer_count_till_decay; int lonely_count = hashtable_count(&sb->sprites_to_lonely_textures); spritebatch_internal_lonely_texture_t* lonely_textures = (spritebatch_internal_lonely_texture_t*)hashtable_items(&sb->sprites_to_lonely_textures); if (lonely_count >= lonely_buffer_count_till_decay) { spritebatch_internal_qsort_lonely(&sb->sprites_to_lonely_textures, lonely_textures, lonely_count); int index = 0; while (1) { if (index == lonely_count) break; if (lonely_textures[index].timestamp >= ticks_to_decay_texture) break; ++index; } for (int i = index; i < lonely_count; ++i) { SPRITEBATCH_U64 texture_id = lonely_textures[i].texture_id; if (texture_id != ~0) sb->delete_texture_callback(texture_id); spritebatch_internal_buffer_key(sb, lonely_textures[i].image_id); SPRITEBATCH_LOG("lonely texture decayed\n"); } spritebatch_internal_remove_table_entries(sb, &sb->sprites_to_lonely_textures); lonely_count -= lonely_count - index; SPRITEBATCH_ASSERT(lonely_count == hashtable_count(&sb->sprites_to_lonely_textures)); } // process input, but don't make textures just yet spritebatch_internal_process_input(sb, 1); lonely_count = hashtable_count(&sb->sprites_to_lonely_textures); // while greater than lonely_buffer_count_till_flush elements in lonely buffer // grab lonely_buffer_count_till_flush of them and make an atlas int lonely_buffer_count_till_flush = sb->lonely_buffer_count_till_flush; int stuck = 0; while (lonely_count > lonely_buffer_count_till_flush && !stuck) { atlas = (spritebatch_internal_atlas_t*)SPRITEBATCH_MALLOC(sizeof(spritebatch_internal_atlas_t), sb->mem_ctx); if (sb->atlases) { atlas->prev = sb->atlases; atlas->next = sb->atlases->next; sb->atlases->next->prev = atlas; sb->atlases->next = atlas; } else { atlas->next = atlas; atlas->prev = atlas; sb->atlases = atlas; } spritebatch_make_atlas(sb, atlas, lonely_textures, lonely_count); SPRITEBATCH_LOG("making atlas\n"); int tex_count_in_atlas = hashtable_count(&atlas->sprites_to_textures); if (tex_count_in_atlas != lonely_count) { int hit_count = 0; for (int i = 0; i < lonely_count; ++i) { SPRITEBATCH_U64 key = lonely_textures[i].image_id; if (hashtable_find(&atlas->sprites_to_textures, key)) { spritebatch_internal_buffer_key(sb, key); SPRITEBATCH_U64 texture_id = lonely_textures[i].texture_id; if (texture_id != ~0) sb->delete_texture_callback(texture_id); hashtable_insert(&sb->sprites_to_atlases, key, &atlas); SPRITEBATCH_LOG("removing lonely texture for atlas%s\n", texture_id != ~0 ? "" : " (tex was ~0)" ); } else hit_count++; } spritebatch_internal_remove_table_entries(sb, &sb->sprites_to_lonely_textures); if (!hit_count) { // TODO // handle case where none fit in atlas SPRITEBATCH_ASSERT(0); } } else { for (int i = 0; i < lonely_count; ++i) { SPRITEBATCH_U64 key = lonely_textures[i].image_id; SPRITEBATCH_U64 texture_id = lonely_textures[i].texture_id; if (texture_id != ~0) sb->delete_texture_callback(texture_id); hashtable_insert(&sb->sprites_to_atlases, key, &atlas); SPRITEBATCH_LOG("(fast path) removing lonely texture for atlas%s\n", texture_id != ~0 ? "" : " (tex was ~0)" ); } hashtable_clear(&sb->sprites_to_lonely_textures); lonely_count = 0; break; } } return 1; } #endif SPRITEBATCH_IMPLEMENTATION /* ------------------------------------------------------------------------------ This software is available under 2 licenses - you may choose the one you like. ------------------------------------------------------------------------------ ALTERNATIVE A - zlib license Copyright (c) 2017 Randy Gaul http://www.randygaul.net This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. ------------------------------------------------------------------------------ ALTERNATIVE B - Public Domain (www.unlicense.org) This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------ */
2.34375
2
2024-11-18T18:09:51.443283+00:00
2015-07-31T19:33:31
8b09a54421274823a44ae2bfba9813fd720d82f1
{ "blob_id": "8b09a54421274823a44ae2bfba9813fd720d82f1", "branch_name": "refs/heads/master", "committer_date": "2015-07-31T19:33:31", "content_id": "7ec7c2bb46c45518a5f4ba98aec47a9c74ef64e4", "detected_licenses": [ "MIT" ], "directory_id": "2a5268a09ddc1bd8afe53032b3cfabf0f3b2b0a0", "extension": "c", "filename": "main.c", "fork_events_count": 1, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 24499299, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 6303, "license": "MIT", "license_type": "permissive", "path": "/examples/el_example_03.X/main.c", "provenance": "stackv2-0003.json.gz:317413", "repo_name": "jianingchen/epucklib", "revision_date": "2015-07-31T19:33:31", "revision_id": "7020fb11af88926cbafb34d7a60dc964a1e62933", "snapshot_id": "bcb7ca54edb5da08df41fff4d3a90e7e814ab1f6", "src_encoding": "UTF-8", "star_events_count": 2, "url": "https://raw.githubusercontent.com/jianingchen/epucklib/7020fb11af88926cbafb34d7a60dc964a1e62933/examples/el_example_03.X/main.c", "visit_date": "2016-09-06T12:33:19.281929" }
stackv2
/* embedded system library for e-puck - example 3 -------------------------------------------------------------------------------- code distribution: https://github.com/jianingchen/epucklib online documentation: http://jianingchen.github.io/epucklib/html/ -------------------------------------------------------------------------------- This file is released under the terms of the MIT license (see "el.h"). */ #include <el.h> #include <elu.h> void BootingProcedure01_SelectorBarrier(); void TimerCallback_MotionAutoStop(void*arg); void TimerCallback_MeasureCameraFPS(void*arg); void Process_ConsoleLoop(void*arg); el_ir_proximity_data ProximitySensor[8]; volatile el_uint32 CameraFrameCounter; volatile el_int16 CameraFrameRate; el_handle CameraFrameRateTimer; el_handle MotionTimer; int main(void){ el_initialization(); el_calibrate_sensors(); el_uart_use_reset_code(true,128); /* * Put the robot in silence when the selector is in 0~3. */ BootingProcedure01_SelectorBarrier(); /* * The values below are same as the default configurations; they are placed * here just for demonstration. Note, when the automatic mode is used, the * frame rate will be varied depending on the lighting condition of the * environment. */ el_camera_options()->ExposureMode = EL_AUTOMATIC; el_camera_options()->AutoWhiteBalance = true; el_camera_options()->AutoDigitalGain = true; el_camera_options_apply(); el_launch_process(Process_ConsoleLoop,NULL); el_main_loop(); return 0; } void BootingProcedure01_SelectorBarrier(){ while(el_get_selector_value()<4){ el_led_set(EL_LED_RING_5,1); el_sleep(125); el_led_set(EL_LED_RING_5,0); el_sleep(875); } } void Process_ConsoleLoop(void*arg){ const int MOTION_TIME = 600; char c; int i; elu_printf("EL_EXAMPLE_03\n"); el_stepper_motor_options()->UseAcceleration = true; el_stepper_motor_options()->AccelerationRate = 2000; el_config_stepper_motor(el_stepper_motor_options()); el_enable_camera(); el_enable_ir_proximity(); el_enable_stepper_motor(); el_process_wait(500);// wait for 500 ms // setup a timer to measure framerate of the camera CameraFrameRateTimer = el_create_timer(); el_timer_set_callback(CameraFrameRateTimer,TimerCallback_MeasureCameraFPS,NULL); el_timer_start(CameraFrameRateTimer,1000);// 1000 milliseconds // setup a timer to stop moving automatically after last motion command MotionTimer = el_create_timer(); el_timer_set_periodic(MotionTimer,false); el_timer_set_callback(MotionTimer,TimerCallback_MotionAutoStop,NULL); el_uart_flush_char(EL_UART_1); el_led_set(EL_LED_BODY,EL_ON); while(1){ do{ el_process_cooperate(); }while(el_uart_get_char_counter(EL_UART_1)==0); c = el_uart_get_char(EL_UART_1); switch(c){ case 'H': case 'h':// list available commands elu_println("<HELP>"); elu_println("Key\tAction"); elu_println("'1'\ttoggle front led"); elu_println("'2'\ttoggle body led"); elu_println("'r'\treport ir proximity sensor outputs"); elu_println("'y'\treport camera framerate"); elu_println("'t'\ttransmit camera image"); elu_println("'w'\tmove forward"); elu_println("'a'\tspin left"); elu_println("'s'\tmove backward"); elu_println("'d'\tspin right"); elu_println("'q'\tturn left"); elu_println("'e'\tturn right"); elu_println("' '\tstop"); break; case 'f': case '1': el_led_set(EL_LED_FRONT,EL_TOGGLE); break; case '2': el_led_set(EL_LED_BODY,EL_TOGGLE); break; case 'r':// report ir proximity sensor outputs elu_println("<IR>"); el_ir_proximity_get(EL_IR_PROXIMITY_SENSOR_ALL,EL_IR_ALL_3V,(el_int16*)ProximitySensor); elu_printf("AMB:"); for(i=0;i<8;i++){ elu_printf("\t%d",ProximitySensor[i].Ambient); } elu_putchar('\n'); elu_printf("REF:"); for(i=0;i<8;i++){ elu_printf("\t%d",ProximitySensor[i].Reflection); } elu_putchar('\n'); break; case 'y':// report camera framerate elu_println("[CAM]\nFPS:\t%d\tNUM:\t%lu",CameraFrameRate,CameraFrameCounter); break; case 't': el_camera_lock_frame(); elu_print_camera_image(el_camera_frame(),el_camera_get_frame_counter()); el_camera_unlock_frame(); elu_putchar('\n'); break; case 'w': el_set_wheel_speed(800,800); el_timer_start(MotionTimer,MOTION_TIME); break; case 'a': el_set_wheel_speed(-200,200); el_timer_start(MotionTimer,MOTION_TIME); break; case 's': el_set_wheel_speed(-500,-500); el_timer_start(MotionTimer,MOTION_TIME); break; case 'd': el_set_wheel_speed(200,-200); el_timer_start(MotionTimer,MOTION_TIME); break; case 'q': el_set_wheel_speed(500,800); el_timer_start(MotionTimer,MOTION_TIME); break; case 'e': el_set_wheel_speed(800,500); el_timer_start(MotionTimer,MOTION_TIME); break; case ' ': el_set_wheel_speed(0,0); el_timer_start(MotionTimer,MOTION_TIME); break; } } } void TimerCallback_MotionAutoStop(void*arg){ el_set_wheel_speed(0,0); } void TimerCallback_MeasureCameraFPS(void*args){ el_uint32 c = el_camera_get_frame_counter(); el_int16 d = c - CameraFrameCounter; CameraFrameCounter = c; CameraFrameRate = d; }
2.609375
3
2024-11-18T18:09:51.672491+00:00
2023-08-22T19:06:25
42c15a6eda8c965ba1b20608d5841e481c9de1d4
{ "blob_id": "42c15a6eda8c965ba1b20608d5841e481c9de1d4", "branch_name": "refs/heads/master", "committer_date": "2023-08-22T19:06:25", "content_id": "12f7e8e9ecc0e5353d2c6395b72c521910614efa", "detected_licenses": [ "MIT" ], "directory_id": "d153de2407f635bbd2667a6b266354d532e80e85", "extension": "c", "filename": "TestPairedData3.c", "fork_events_count": 13, "gha_created_at": "2021-03-08T16:45:37", "gha_event_created_at": "2023-09-13T23:01:51", "gha_language": "C", "gha_license_id": "MIT", "github_id": 345726079, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 3218, "license": "MIT", "license_type": "permissive", "path": "/test/Dss-C/source/TestPairedData3.c", "provenance": "stackv2-0003.json.gz:317671", "repo_name": "HydrologicEngineeringCenter/hec-dss", "revision_date": "2023-08-22T19:06:25", "revision_id": "8587bd5339ee9aa8519d1d0d17f3625419a63122", "snapshot_id": "195845c6312f2d9fc508032b39179f457849ede1", "src_encoding": "UTF-8", "star_events_count": 26, "url": "https://raw.githubusercontent.com/HydrologicEngineeringCenter/hec-dss/8587bd5339ee9aa8519d1d0d17f3625419a63122/test/Dss-C/source/TestPairedData3.c", "visit_date": "2023-08-30T11:56:27.416514" }
stackv2
#include <stdio.h> #include <string.h> #include "heclib.h" #include "TestDssC.h" int TestPairedData3(long long *ifltab) { zStructPairedData *pds1, *pds2, *pds3, *pds4, *pds5; float fordinates[500], fvalues[10][500]; float *temp; char label[20], labels[100]; int labelLength; char pathname[100]; int numberValues; int status, i, j; // This function tests features not supported in DSS-6 if (zgetVersion(ifltab) == 6) { return 0; } // Gen up some data for (j=0; j<500; j++) { fordinates[j] = (float)(j + 1) * (float)10; for (i=0; i<10; i++) { fvalues[i][j] = ((float)(j + 1) * (float)100.0) + (float)(i + 1); } } stringCopy(pathname, sizeof(pathname), "/Basin/Location/Stage-Damage///PD 3/", _TRUNCATE); pds1 = zstructPdNewFloats(pathname, fordinates, (float *)fvalues, 500, 10, "feet", "linear", "dollars", "linear"); status = zpdStore(ifltab, pds1, 0); if (status != STATUS_OKAY) return status; //zset("mlvl", "", 15); // Now retrieve the data pds2 = zstructPdNew(pathname); status = zpdRetrieve(ifltab, pds2, 0); if (status) return status; // compare status = comparePDs (ifltab, pds1, pds2, "TestPairedData3, Loc 1, floats"); if (status != STATUS_OKAY) return status; // Lets change a block of data within the curves // It's easiest (not effiecent) to retrieve the data, // change and store back. Let's do that for row 5-10, columns 2-5: pds3 = zstructPdNew(pathname); pds3->startingOrdinate = 4; pds3->endingOrdinate = 10; pds3->startingCurve = 2; pds3->endingCurve = 5; status = zpdRetrieve(ifltab, pds3, 1); // We'll just use this as a single array for simplicity, // instead of the doubly dimensioned array, which it really is. numberValues = pds3->numberCurvesInStruct * pds3->numberOrdinatesInStruct; // Let's make the values negative for (i=0; i<numberValues; i++) { pds3->floatValues[i] = -(pds3->floatValues[i]); } status = zpdStore(ifltab, pds3, 0); if (status != STATUS_OKAY) return status; // Now read and print the earlier block pds4 = zstructPdNew(pathname); pds4->startingOrdinate = pds3->startingOrdinate; pds4->endingOrdinate = pds3->endingOrdinate; pds4->startingCurve = pds3->startingCurve; pds4->endingCurve = pds3->endingCurve; status = zpdRetrieve(ifltab, pds4, 0); status = comparePDs (ifltab, pds3, pds4, "TestPairedData3, Loc 10, A segment"); if (status != STATUS_OKAY) return status; // Compare the full data set now // pds2 should be the original pds1, but not what is on disk // Change pds2 to be what should be on disk, read, and compare for (j=pds4->startingOrdinate; j<=pds4->endingOrdinate ; j++) { for (i=pds4->startingCurve; i<=pds4->endingCurve ; i++) { fvalues[i-1][j-1] = -fvalues[i-1][j-1]; } } temp = pds2->floatValues; pds2->floatValues = (float *)fvalues; pds5 = zstructPdNew(pathname); status = zpdRetrieve(ifltab, pds5, 0); // compare status = comparePDs (ifltab, pds2, pds5, "TestPairedData3, Loc 11, floats"); if (status) return status; pds2->floatValues = temp; zstructFree(pds1); zstructFree(pds2); zstructFree(pds3); zstructFree(pds4); zstructFree(pds5); printf("Completed testPairedData3 test successfully!\n"); return 0; }
2.296875
2
2024-11-18T18:09:51.825175+00:00
2021-09-02T06:31:41
ab5785cdef7cbafc2be0701801eaa5dfdff337d8
{ "blob_id": "ab5785cdef7cbafc2be0701801eaa5dfdff337d8", "branch_name": "refs/heads/main", "committer_date": "2021-09-13T15:06:35", "content_id": "a2e6689f99b2a534510fa537c17c3587bb946c07", "detected_licenses": [ "BSD-3-Clause" ], "directory_id": "b5195773daaadd1d99b0c7031620e75c16bfb676", "extension": "c", "filename": "sha.c", "fork_events_count": 0, "gha_created_at": "2023-03-30T19:31:14", "gha_event_created_at": "2023-03-30T19:31:15", "gha_language": null, "gha_license_id": null, "github_id": 621496508, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 17016, "license": "BSD-3-Clause", "license_type": "permissive", "path": "/os_stub/cryptlib_mbedtls/hash/sha.c", "provenance": "stackv2-0003.json.gz:317928", "repo_name": "QPC-github/libspdm", "revision_date": "2021-09-02T06:31:41", "revision_id": "df3db1ba161f4164d5aca21dd394a940411b156b", "snapshot_id": "eceedf00e235544794b41b18485b6af4cd8319bc", "src_encoding": "UTF-8", "star_events_count": 1, "url": "https://raw.githubusercontent.com/QPC-github/libspdm/df3db1ba161f4164d5aca21dd394a940411b156b/os_stub/cryptlib_mbedtls/hash/sha.c", "visit_date": "2023-07-26T19:19:48.689983" }
stackv2
/** Copyright Notice: Copyright 2021 DMTF. All rights reserved. License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ /** @file SHA-256/384/512 digest Wrapper Implementation. **/ #include "internal_crypt_lib.h" #include <mbedtls/sha256.h> #include <mbedtls/sha512.h> /** Allocates and initializes one HASH_CTX context for subsequent SHA256 use. @return Pointer to the HASH_CTX context that has been initialized. If the allocations fails, sha256_new() returns NULL. **/ void *sha256_new(void) { void *hmac_md_ctx; hmac_md_ctx = allocate_zero_pool(sizeof(mbedtls_sha256_context)); if (hmac_md_ctx == NULL) { return NULL; } return hmac_md_ctx; } /** Release the specified HASH_CTX context. @param[in] sha256_ctx Pointer to the HASH_CTX context to be released. **/ void sha256_free(IN void *sha256_ctx) { mbedtls_sha256_free(sha256_ctx); free_pool (sha256_ctx); } /** Initializes user-supplied memory pointed by sha256_context as SHA-256 hash context for subsequent use. If sha256_context is NULL, then return FALSE. @param[out] sha256_context Pointer to SHA-256 context being initialized. @retval TRUE SHA-256 context initialization succeeded. @retval FALSE SHA-256 context initialization failed. **/ boolean sha256_init(OUT void *sha256_context) { int32 ret; if (sha256_context == NULL) { return FALSE; } mbedtls_sha256_init(sha256_context); ret = mbedtls_sha256_starts_ret(sha256_context, FALSE); if (ret != 0) { return FALSE; } return TRUE; } /** Makes a copy of an existing SHA-256 context. If sha256_context is NULL, then return FALSE. If new_sha256_context is NULL, then return FALSE. @param[in] sha256_context Pointer to SHA-256 context being copied. @param[out] new_sha256_context Pointer to new SHA-256 context. @retval TRUE SHA-256 context copy succeeded. @retval FALSE SHA-256 context copy failed. **/ boolean sha256_duplicate(IN const void *sha256_context, OUT void *new_sha256_context) { if (sha256_context == NULL || new_sha256_context == NULL) { return FALSE; } mbedtls_sha256_clone(new_sha256_context, sha256_context); return TRUE; } /** Digests the input data and updates SHA-256 context. This function performs SHA-256 digest on a data buffer of the specified size. It can be called multiple times to compute the digest of long or discontinuous data streams. SHA-256 context should be already correctly initialized by sha256_init(), and should not be finalized by sha256_final(). Behavior with invalid context is undefined. If sha256_context is NULL, then return FALSE. @param[in, out] sha256_context Pointer to the SHA-256 context. @param[in] data Pointer to the buffer containing the data to be hashed. @param[in] data_size size of data buffer in bytes. @retval TRUE SHA-256 data digest succeeded. @retval FALSE SHA-256 data digest failed. **/ boolean sha256_update(IN OUT void *sha256_context, IN const void *data, IN uintn data_size) { int32 ret; if (sha256_context == NULL) { return FALSE; } if (data == NULL && data_size != 0) { return FALSE; } if (data_size > INT_MAX) { return FALSE; } ret = mbedtls_sha256_update_ret(sha256_context, data, data_size); if (ret != 0) { return FALSE; } return TRUE; } /** Completes computation of the SHA-256 digest value. This function completes SHA-256 hash computation and retrieves the digest value into the specified memory. After this function has been called, the SHA-256 context cannot be used again. SHA-256 context should be already correctly initialized by sha256_init(), and should not be finalized by sha256_final(). Behavior with invalid SHA-256 context is undefined. If sha256_context is NULL, then return FALSE. If hash_value is NULL, then return FALSE. @param[in, out] sha256_context Pointer to the SHA-256 context. @param[out] hash_value Pointer to a buffer that receives the SHA-256 digest value (32 bytes). @retval TRUE SHA-256 digest computation succeeded. @retval FALSE SHA-256 digest computation failed. **/ boolean sha256_final(IN OUT void *sha256_context, OUT uint8 *hash_value) { int32 ret; if (sha256_context == NULL || hash_value == NULL) { return FALSE; } ret = mbedtls_sha256_finish_ret(sha256_context, hash_value); mbedtls_sha256_free(sha256_context); if (ret != 0) { return FALSE; } return TRUE; } /** Computes the SHA-256 message digest of a input data buffer. This function performs the SHA-256 message digest of a given data buffer, and places the digest value into the specified memory. If this interface is not supported, then return FALSE. @param[in] data Pointer to the buffer containing the data to be hashed. @param[in] data_size size of data buffer in bytes. @param[out] hash_value Pointer to a buffer that receives the SHA-256 digest value (32 bytes). @retval TRUE SHA-256 digest computation succeeded. @retval FALSE SHA-256 digest computation failed. @retval FALSE This interface is not supported. **/ boolean sha256_hash_all(IN const void *data, IN uintn data_size, OUT uint8 *hash_value) { int32 ret; if (hash_value == NULL) { return FALSE; } if (data == NULL && data_size != 0) { return FALSE; } if (data_size > INT_MAX) { return FALSE; } ret = mbedtls_sha256_ret(data, data_size, hash_value, FALSE); if (ret != 0) { return FALSE; } return TRUE; } /** Allocates and initializes one HASH_CTX context for subsequent SHA384 use. @return Pointer to the HASH_CTX context that has been initialized. If the allocations fails, sha384_new() returns NULL. **/ void *sha384_new(void) { void *hmac_md_ctx; hmac_md_ctx = allocate_zero_pool(sizeof(mbedtls_sha512_context)); if (hmac_md_ctx == NULL) { return NULL; } return hmac_md_ctx; } /** Release the specified HASH_CTX context. @param[in] sha384_ctx Pointer to the HASH_CTX context to be released. **/ void sha384_free(IN void *sha384_ctx) { mbedtls_sha512_free(sha384_ctx); free_pool (sha384_ctx); } /** Initializes user-supplied memory pointed by sha384_context as SHA-384 hash context for subsequent use. If sha384_context is NULL, then return FALSE. @param[out] sha384_context Pointer to SHA-384 context being initialized. @retval TRUE SHA-384 context initialization succeeded. @retval FALSE SHA-384 context initialization failed. **/ boolean sha384_init(OUT void *sha384_context) { int32 ret; if (sha384_context == NULL) { return FALSE; } mbedtls_sha512_init(sha384_context); ret = mbedtls_sha512_starts_ret(sha384_context, TRUE); if (ret != 0) { return FALSE; } return TRUE; } /** Makes a copy of an existing SHA-384 context. If sha384_context is NULL, then return FALSE. If new_sha384_context is NULL, then return FALSE. If this interface is not supported, then return FALSE. @param[in] sha384_context Pointer to SHA-384 context being copied. @param[out] new_sha384_context Pointer to new SHA-384 context. @retval TRUE SHA-384 context copy succeeded. @retval FALSE SHA-384 context copy failed. @retval FALSE This interface is not supported. **/ boolean sha384_duplicate(IN const void *sha384_context, OUT void *new_sha384_context) { if (sha384_context == NULL || new_sha384_context == NULL) { return FALSE; } mbedtls_sha512_clone(new_sha384_context, sha384_context); return TRUE; } /** Digests the input data and updates SHA-384 context. This function performs SHA-384 digest on a data buffer of the specified size. It can be called multiple times to compute the digest of long or discontinuous data streams. SHA-384 context should be already correctly initialized by sha384_init(), and should not be finalized by sha384_final(). Behavior with invalid context is undefined. If sha384_context is NULL, then return FALSE. @param[in, out] sha384_context Pointer to the SHA-384 context. @param[in] data Pointer to the buffer containing the data to be hashed. @param[in] data_size size of data buffer in bytes. @retval TRUE SHA-384 data digest succeeded. @retval FALSE SHA-384 data digest failed. **/ boolean sha384_update(IN OUT void *sha384_context, IN const void *data, IN uintn data_size) { int32 ret; if (sha384_context == NULL) { return FALSE; } if (data == NULL && data_size != 0) { return FALSE; } if (data_size > INT_MAX) { return FALSE; } ret = mbedtls_sha512_update_ret(sha384_context, data, data_size); if (ret != 0) { return FALSE; } return TRUE; } /** Completes computation of the SHA-384 digest value. This function completes SHA-384 hash computation and retrieves the digest value into the specified memory. After this function has been called, the SHA-384 context cannot be used again. SHA-384 context should be already correctly initialized by sha384_init(), and should not be finalized by sha384_final(). Behavior with invalid SHA-384 context is undefined. If sha384_context is NULL, then return FALSE. If hash_value is NULL, then return FALSE. @param[in, out] sha384_context Pointer to the SHA-384 context. @param[out] hash_value Pointer to a buffer that receives the SHA-384 digest value (48 bytes). @retval TRUE SHA-384 digest computation succeeded. @retval FALSE SHA-384 digest computation failed. **/ boolean sha384_final(IN OUT void *sha384_context, OUT uint8 *hash_value) { int32 ret; if (sha384_context == NULL || hash_value == NULL) { return FALSE; } ret = mbedtls_sha512_finish_ret(sha384_context, hash_value); mbedtls_sha512_free(sha384_context); if (ret != 0) { return FALSE; } return TRUE; } /** Computes the SHA-384 message digest of a input data buffer. This function performs the SHA-384 message digest of a given data buffer, and places the digest value into the specified memory. If this interface is not supported, then return FALSE. @param[in] data Pointer to the buffer containing the data to be hashed. @param[in] data_size size of data buffer in bytes. @param[out] hash_value Pointer to a buffer that receives the SHA-384 digest value (48 bytes). @retval TRUE SHA-384 digest computation succeeded. @retval FALSE SHA-384 digest computation failed. @retval FALSE This interface is not supported. **/ boolean sha384_hash_all(IN const void *data, IN uintn data_size, OUT uint8 *hash_value) { int32 ret; if (hash_value == NULL) { return FALSE; } if (data == NULL && data_size != 0) { return FALSE; } if (data_size > INT_MAX) { return FALSE; } ret = mbedtls_sha512_ret(data, data_size, hash_value, TRUE); if (ret != 0) { return FALSE; } return TRUE; } /** Allocates and initializes one HASH_CTX context for subsequent SHA512 use. @return Pointer to the HASH_CTX context that has been initialized. If the allocations fails, sha512_new() returns NULL. **/ void *sha512_new(void) { void *hmac_md_ctx; hmac_md_ctx = allocate_zero_pool(sizeof(mbedtls_sha512_context)); if (hmac_md_ctx == NULL) { return NULL; } return hmac_md_ctx; } /** Release the specified HASH_CTX context. @param[in] sha512_ctx Pointer to the HASH_CTX context to be released. **/ void sha512_free(IN void *sha512_ctx) { mbedtls_sha512_free(sha512_ctx); free_pool (sha512_ctx); } /** Initializes user-supplied memory pointed by sha512_context as SHA-512 hash context for subsequent use. If sha512_context is NULL, then return FALSE. @param[out] sha512_context Pointer to SHA-512 context being initialized. @retval TRUE SHA-512 context initialization succeeded. @retval FALSE SHA-512 context initialization failed. **/ boolean sha512_init(OUT void *sha512_context) { int32 ret; if (sha512_context == NULL) { return FALSE; } mbedtls_sha512_init(sha512_context); ret = mbedtls_sha512_starts_ret(sha512_context, FALSE); if (ret != 0) { return FALSE; } return TRUE; } /** Makes a copy of an existing SHA-512 context. If sha512_context is NULL, then return FALSE. If new_sha512_context is NULL, then return FALSE. If this interface is not supported, then return FALSE. @param[in] sha512_context Pointer to SHA-512 context being copied. @param[out] new_sha512_context Pointer to new SHA-512 context. @retval TRUE SHA-512 context copy succeeded. @retval FALSE SHA-512 context copy failed. @retval FALSE This interface is not supported. **/ boolean sha512_duplicate(IN const void *sha512_context, OUT void *new_sha512_context) { if (sha512_context == NULL || new_sha512_context == NULL) { return FALSE; } mbedtls_sha512_clone(new_sha512_context, sha512_context); return TRUE; } /** Digests the input data and updates SHA-512 context. This function performs SHA-512 digest on a data buffer of the specified size. It can be called multiple times to compute the digest of long or discontinuous data streams. SHA-512 context should be already correctly initialized by sha512_init(), and should not be finalized by sha512_final(). Behavior with invalid context is undefined. If sha512_context is NULL, then return FALSE. @param[in, out] sha512_context Pointer to the SHA-512 context. @param[in] data Pointer to the buffer containing the data to be hashed. @param[in] data_size size of data buffer in bytes. @retval TRUE SHA-512 data digest succeeded. @retval FALSE SHA-512 data digest failed. **/ boolean sha512_update(IN OUT void *sha512_context, IN const void *data, IN uintn data_size) { int32 ret; if (sha512_context == NULL) { return FALSE; } if (data == NULL && data_size != 0) { return FALSE; } if (data_size > INT_MAX) { return FALSE; } ret = mbedtls_sha512_update_ret(sha512_context, data, data_size); if (ret != 0) { return FALSE; } return TRUE; } /** Completes computation of the SHA-512 digest value. This function completes SHA-512 hash computation and retrieves the digest value into the specified memory. After this function has been called, the SHA-512 context cannot be used again. SHA-512 context should be already correctly initialized by sha512_init(), and should not be finalized by sha512_final(). Behavior with invalid SHA-512 context is undefined. If sha512_context is NULL, then return FALSE. If hash_value is NULL, then return FALSE. @param[in, out] sha512_context Pointer to the SHA-512 context. @param[out] hash_value Pointer to a buffer that receives the SHA-512 digest value (64 bytes). @retval TRUE SHA-512 digest computation succeeded. @retval FALSE SHA-512 digest computation failed. **/ boolean sha512_final(IN OUT void *sha512_context, OUT uint8 *hash_value) { int32 ret; if (sha512_context == NULL || hash_value == NULL) { return FALSE; } ret = mbedtls_sha512_finish_ret(sha512_context, hash_value); mbedtls_sha512_free(sha512_context); if (ret != 0) { return FALSE; } return TRUE; } /** Computes the SHA-512 message digest of a input data buffer. This function performs the SHA-512 message digest of a given data buffer, and places the digest value into the specified memory. If this interface is not supported, then return FALSE. @param[in] data Pointer to the buffer containing the data to be hashed. @param[in] data_size size of data buffer in bytes. @param[out] hash_value Pointer to a buffer that receives the SHA-512 digest value (64 bytes). @retval TRUE SHA-512 digest computation succeeded. @retval FALSE SHA-512 digest computation failed. @retval FALSE This interface is not supported. **/ boolean sha512_hash_all(IN const void *data, IN uintn data_size, OUT uint8 *hash_value) { int32 ret; if (hash_value == NULL) { return FALSE; } if (data == NULL && data_size != 0) { return FALSE; } if (data_size > INT_MAX) { return FALSE; } ret = mbedtls_sha512_ret(data, data_size, hash_value, FALSE); if (ret != 0) { return FALSE; } return TRUE; }
2.703125
3
2024-11-18T18:09:52.008308+00:00
2015-06-27T11:56:45
fa46cdc8d1fcbf6fbd2c87b1f475e0bb8710e524
{ "blob_id": "fa46cdc8d1fcbf6fbd2c87b1f475e0bb8710e524", "branch_name": "refs/heads/master", "committer_date": "2015-06-27T11:56:45", "content_id": "0a0b24b1af5024ad1f2d4d8ce6d24d347060b010", "detected_licenses": [ "MIT" ], "directory_id": "95b9f21bdf34b1abe423d43495617371e5a8b06a", "extension": "c", "filename": "http.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 38132483, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2614, "license": "MIT", "license_type": "permissive", "path": "/C/ueb06/http.c", "provenance": "stackv2-0003.json.gz:318186", "repo_name": "hotfix/Studium", "revision_date": "2015-06-27T11:56:45", "revision_id": "9e9142ba4493e4bd99b3da8e0faca90e9094c1cf", "snapshot_id": "12b93b207da9cf7d2a1ce0c0c244790ca92a8b71", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/hotfix/Studium/9e9142ba4493e4bd99b3da8e0faca90e9094c1cf/C/ueb06/http.c", "visit_date": "2016-09-03T07:15:03.547732" }
stackv2
#include <stdio.h> #include <errno.h> #include <string.h> #include <stdlib.h> /* Windows-System */ #ifdef _WIN32 #include <winsock.h> #include <io.h> /* Unix-System */ #else #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <unistd.h> #endif #define HTTP_PORT 80 int main(int argc, char **argv) { int sock; struct sockaddr_in host_addr; struct hostent *hostinfo; char *host, *file; char command[1024]; char buf[1024]; unsigned int bytes_sent, bytes_recv; /* Ist der Aufruf korrekt? */ if (argc != 3) { fprintf (stderr, "Aufruf: httprecv host file\n"); exit (EXIT_FAILURE); } host = argv[1]; file = argv[2]; /* ggf. Winsock initialisieren */ #ifdef _WIN32 WSADATA wsaData; if (WSAStartup (MAKEWORD(1, 1), &wsaData) != 0) { fprintf (stderr, "WSAStartup(): Kann Winsock nicht initialisieren.\n"); exit (EXIT_FAILURE); } #endif /* Socket erzeugen */ sock = socket (AF_INET, SOCK_STREAM, 0); if (sock == -1) { perror ("socket()"); exit (EXIT_FAILURE); } /* Adresse des Servers festlegen */ memset( &host_addr, 0, sizeof (host_addr)); host_addr.sin_family = AF_INET; host_addr.sin_port = htons (HTTP_PORT); host_addr.sin_addr.s_addr = inet_addr (host); if (host_addr.sin_addr.s_addr == INADDR_NONE) { /* Server wurde nicht mit IP sondern mit dem Namen angegeben */ hostinfo = gethostbyname (host); if (hostinfo == NULL) { perror ("gethostbyname()"); exit (EXIT_FAILURE); } memcpy((char*) &host_addr.sin_addr.s_addr, hostinfo->h_addr, hostinfo->h_length); } /* Verbindung aufbauen */ if (connect(sock, (struct sockaddr *) &host_addr, sizeof(struct sockaddr)) == -1) { perror ("connect()"); exit (EXIT_FAILURE); } /* HTTP-GET-Befehl erzeugen */ sprintf (command, "GET %s HTTP/1.0\nHost: %s\n\n", file, host); /* Befehl senden */ bytes_sent = send (sock, command, strlen (command), 0); if (bytes_sent == -1) { perror ("send()"); exit (EXIT_FAILURE); } // Antwort des Servers empfangen und ausgeben */ while ((bytes_recv = recv (sock, buf, sizeof(buf), 0)) > 0) { write (1, buf, bytes_recv); } if (bytes_recv == -1) { perror ("recv()"); exit (EXIT_FAILURE); } printf ("\n"); #ifdef _WIN32 closesocket(sock); WSACleanup(); #else close(sock); #endif return 0; }
2.703125
3
2024-11-18T18:09:52.493527+00:00
2023-08-09T12:19:02
240517d68c63f21bfde0ccc180bb08d06b90db94
{ "blob_id": "240517d68c63f21bfde0ccc180bb08d06b90db94", "branch_name": "refs/heads/master", "committer_date": "2023-08-09T12:19:02", "content_id": "0bf5d9cfd4993affbda3a68fa345eef3ad08db50", "detected_licenses": [ "Unlicense" ], "directory_id": "e60b457a42892430eef7ead48ca55ad0a169b542", "extension": "c", "filename": "camellia-test.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 127428326, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1314, "license": "Unlicense", "license_type": "permissive", "path": "/src/1-symm-national/camellia-test.c", "provenance": "stackv2-0003.json.gz:318956", "repo_name": "dannyniu/MySuiteA", "revision_date": "2023-08-09T12:19:02", "revision_id": "bec4fd480f07f3ab1b960f6e73d1493d2a0cdc33", "snapshot_id": "0d8de4c7ea0b19438c75da52c619433e880c477c", "src_encoding": "UTF-8", "star_events_count": 1, "url": "https://raw.githubusercontent.com/dannyniu/MySuiteA/bec4fd480f07f3ab1b960f6e73d1493d2a0cdc33/src/1-symm-national/camellia-test.c", "visit_date": "2023-08-21T12:08:24.321341" }
stackv2
/* DannyNiu/NJF, 2021-06-23. Public Domain. */ #undef bc #define bc xCamellia128 #include "../1-symm/blockcipher-test.c.h" #undef bc #define bc xCamellia192 #include "../1-symm/blockcipher-test.c.h" #undef bc #define bc xCamellia256 #include "../1-symm/blockcipher-test.c.h" #undef bc #define bc iCamellia128 #include "../1-symm/blockcipher-test.c.h" #undef bc #define bc iCamellia192 #include "../1-symm/blockcipher-test.c.h" #undef bc #define bc iCamellia256 #include "../1-symm/blockcipher-test.c.h" int main(int argc, char *argv[]) { int ret = EXIT_SUCCESS; if( argc < 2 ) return EXIT_FAILURE; if( !strcmp(argv[1], "128") ) { ret = blockcipher_test_xCamellia128() == EXIT_SUCCESS && blockcipher_test_iCamellia128() == EXIT_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE; } if( !strcmp(argv[1], "192") ) { ret = blockcipher_test_xCamellia192() == EXIT_SUCCESS && blockcipher_test_iCamellia192() == EXIT_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE; } if( !strcmp(argv[1], "256") ) { ret = blockcipher_test_xCamellia256() == EXIT_SUCCESS && blockcipher_test_iCamellia256() == EXIT_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE; } return ret; }
2.25
2
2024-11-18T18:09:52.562300+00:00
2020-02-26T11:50:45
e8f2696e701adea9b6ed1e3580eb8d03a71cfe01
{ "blob_id": "e8f2696e701adea9b6ed1e3580eb8d03a71cfe01", "branch_name": "refs/heads/master", "committer_date": "2020-02-26T11:50:45", "content_id": "03b2cb265877b9075b255928a38eb4ae14ecbae6", "detected_licenses": [ "MIT" ], "directory_id": "7b881c20d4a76d91be709e09399c1d96dca791d1", "extension": "c", "filename": "byteio.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": null, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1302, "license": "MIT", "license_type": "permissive", "path": "/src/byteio.c", "provenance": "stackv2-0003.json.gz:319084", "repo_name": "potrepka/synthdef", "revision_date": "2020-02-26T11:50:45", "revision_id": "671937a30319b0a4ee5c00cd759e0c0c157ec2eb", "snapshot_id": "f815c4ea522513bc715aa24a329cbe186873a208", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/potrepka/synthdef/671937a30319b0a4ee5c00cd759e0c0c157ec2eb/src/byteio.c", "visit_date": "2022-04-04T13:17:28.936334" }
stackv2
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "byteio.h" #define IS_LITTLE_ENDIAN (*(uint16_t *)"\0\xff" > 0x100) #define BYTE_IO_DEBUG 1 short swapShort(short v) { return (v << 8) | ((v >> 8) & 0xFF); } int swapInt(int v) { v = ((v << 8) & 0xFF00FF00) | ((v >> 8) & 0xFF00FF); return (v << 16) | ((v >> 16) & 0xFFFF); } int readChar(FILE *fp, char *vp) { return fread((void *)vp, sizeof(*vp), 1, fp); } int writeChar(FILE *fp, char v) { return fwrite((void *)(&v), sizeof(v), 1, fp); } int readShort(FILE *fp, short *vp) { int success = fread((void *)vp, sizeof(*vp), 1, fp); if (success && IS_LITTLE_ENDIAN) *vp = swapShort(*vp); return success; } int writeShort(FILE *fp, short v) { if (IS_LITTLE_ENDIAN) v = swapShort(v); return fwrite((void *)(&v), sizeof(v), 1, fp); } int readInt(FILE *fp, int *vp) { int success = fread((void *)vp, sizeof(*vp), 1, fp); if (success && IS_LITTLE_ENDIAN) *vp = swapInt(*vp); return success; } int writeInt(FILE *fp, int v) { if (IS_LITTLE_ENDIAN) v = swapInt(v); return fwrite((void *)(&v), sizeof(v), 1, fp); } int readFloat(FILE *fp, float *vp) { return fread((void *)vp, sizeof(*vp), 1, fp); } int writeFloat(FILE *fp, float v) { return fwrite((void *)(&v), sizeof(v), 1, fp); }
2.671875
3
2024-11-18T18:09:52.884324+00:00
2014-09-11T07:55:47
7709296b82bc8c46e609c04d0a816bbc9c708422
{ "blob_id": "7709296b82bc8c46e609c04d0a816bbc9c708422", "branch_name": "refs/heads/master", "committer_date": "2014-09-11T07:55:47", "content_id": "e679fbbcd1887339a141fd5117f16d1e3f4232a3", "detected_licenses": [ "NCSA" ], "directory_id": "39afe29d583fc7be4ca43cabfc1c4ada575291aa", "extension": "c", "filename": "l_dot.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 23909090, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 13010, "license": "NCSA", "license_type": "permissive", "path": "/src/Lcode/tools/Ldot/l_dot.c", "provenance": "stackv2-0003.json.gz:319470", "repo_name": "invisibleboy/mycompiler", "revision_date": "2014-09-11T07:55:47", "revision_id": "5736841b2578ec47039620c9df3fae02ecee66d7", "snapshot_id": "1bd198035295ece77508f7676ad2b6effcbeeea4", "src_encoding": "UTF-8", "star_events_count": 1, "url": "https://raw.githubusercontent.com/invisibleboy/mycompiler/5736841b2578ec47039620c9df3fae02ecee66d7/src/Lcode/tools/Ldot/l_dot.c", "visit_date": "2016-09-06T19:12:45.046188" }
stackv2
#include <stdio.h> #include <Lcode/l_dot.h> #include <Lcode/l_code.h> #include <Lcode/l_main.h> #define L_DOT_FONT "Helvetica" static void L_dot_print_file_header(FILE* out, char* graph_name) { char* orientation = "portrait"; double page_w = 8.5; double page_h = 11; double size_w = 10; double size_h = 7.5; fprintf(out, "digraph %s {\n", graph_name); fprintf(out, " graph [ \n"); fprintf(out, " orientation = \"%s\",\n", orientation); fprintf(out, " center = \"true\",\n"); fprintf(out, " page = \"%.2f,%.2f\",\n", page_w, page_h); fprintf(out, " size = \"%.2f,%.2f\" ]\n", size_h, size_w); } static void L_dot_print_file_tail(FILE* out) { fprintf(out, "}\n"); } /** Returns the current date/time as a string; caller must free the string. */ static char* L_dot_get_curr_time() { const int max_str_size = 50; char* timestr = (char*) Lcode_malloc(sizeof(char) * max_str_size); time_t curr_t; struct tm* local_t; curr_t = time(&curr_t); local_t = localtime(&curr_t); strftime(timestr, max_str_size, "%b/%d/%Y %I:%M %p", local_t); return timestr; } static void L_dot_print_branch_cond(FILE* out, L_Oper* op) { if (op->com[1]) { L_print_operand(out, op->src[0], 0); fprintf(out, " "); fprintf(out, "%s ", L_cmp_compl_name(op->com[1])); fprintf(out, " "); L_print_operand(out, op->src[1], 0); } } static void write_tabs(FILE *out, int num_tabs) { int i; for (i = 0; i < num_tabs; i++) fprintf(out, "\t"); } static void write_loop_cluster(FILE *out, Set *cbs_in_loops, int num_tabs, L_Loop *loop) { L_Cb *cb; L_Attr *attr; L_Flow *flow; L_Oper *br_op; int *loop_cb = NULL; int num_loop_cb, i; if (loop == NULL) return; #if 0 /* Optimize child loops *first* so they get included within already_shown. */ write_loop_cluster(out, cbs_in_loops, loop->child_loop); #endif /* Then focus on this loop. */ if ((num_loop_cb = Set_size(loop->loop_cb))) { loop_cb = (int*) alloca(sizeof(int) * num_loop_cb); Set_2array (loop->loop_cb, loop_cb); } write_tabs(out, num_tabs); fprintf(out, "subgraph cluster%d {\n", loop->id); write_tabs(out, num_tabs + 1); fprintf(out, "label=\"Loop %d\";\n", loop->id); /* Write out children within this loop. */ write_loop_cluster(out, cbs_in_loops, num_tabs + 1, loop->child_loop); for (i = 0; i < num_loop_cb; i++) { if (Set_in(*cbs_in_loops, loop_cb[i])) continue; *cbs_in_loops = Set_add(*cbs_in_loops, loop_cb[i]); cb = L_cb_hash_tbl_find(L_fn->cb_hash_tbl, loop_cb[i]); if ( (attr = L_find_attr(cb->attr, "Lthread_loop")) ) { int lthread_id = L_get_int_attr_field(attr, 0); int lthread_iter; attr = L_find_attr(cb->attr, "Lthread_iter"); lthread_iter = L_get_int_attr_field(attr, 0); write_tabs(out, num_tabs + 1); fprintf(out, "cb_%d [fontname=\"%s\", label=\"cb %d\\n(loop %d.%d)\"];\n", cb->id, L_DOT_FONT, cb->id, lthread_id, lthread_iter); } else { write_tabs(out, num_tabs + 1); fprintf(out, "cb_%d [fontname=\"%s\", label=\"cb %d\"];\n", cb->id, L_DOT_FONT, cb->id); } /* * Write out intraloop edges. */ for (flow = cb->dest_flow; flow != NULL; flow = flow->next_flow) { if (!Set_in(loop->loop_cb, flow->dst_cb->id)) continue; /* We don't use the results of this, but the call checks the CFG for * * errors. */ L_find_matching_flow(flow->dst_cb->src_flow, flow); fprintf(out, "\tcb_%d -> cb_%d ", flow->src_cb->id, flow->dst_cb->id); fprintf(out, "[label= \""); br_op = L_find_branch_for_flow(flow->src_cb, flow); if (flow->weight != 0.0) fprintf(out, "%.1f", flow->weight); if (flow->weight != 0.0 && br_op != NULL) fprintf(out, "\\n"); if (br_op != NULL) L_dot_print_branch_cond(out, br_op); fprintf(out, "\"];\n"); } } write_tabs(out, num_tabs); fprintf(out, "}\n"); /* Make sure we also take care of our siblings. */ write_loop_cluster(out, cbs_in_loops, num_tabs, loop->sibling_loop); } static void Ldot_print_loop_graph_loop(FILE *out, int num_tabs, L_Loop *loop) { if (loop == NULL) return; write_tabs(out, num_tabs); fprintf(out, "subgraph cluster%d {\n", loop->id); write_tabs(out, num_tabs + 1); fprintf(out, "label=\"Loop %d\";\n", loop->id); write_tabs(out, num_tabs + 1); fprintf(out, "fakenode_loop%d [color=white,fontname=Courier,label=\"", loop->id); fprintf(out, "num_invocation %f\\n", loop->num_invocation); if (loop->num_invocation > 0.0) fprintf (out, "ave_iter %f\\n", loop->header->weight / loop->num_invocation); if (loop->preheader != NULL) fprintf (out, "preheader %d\\n", loop->preheader->id); if (loop->header != NULL) fprintf (out, "\theader %d\\n", loop->header->id); fprintf (out, "nesting_level %d\\n", loop->nesting_level); fprintf (out, "loop_size (no. cb) %d\\n", Set_size (loop->loop_cb)); #if 0 Set_print (out, "loop_cb", loop->loop_cb); Set_print (out, "back_edge_cb", loop->back_edge_cb); Set_print (out, "exit_cb", loop->exit_cb); Set_print (out, "out_cb", loop->out_cb); Set_print (out, "nested_loops", loop->nested_loops); Set_print (out, "basic_ind_var", loop->basic_ind_var); Set_print (out, "basic_ind_var_op", loop->basic_ind_var_op); #endif fprintf(out, "\"];\n"); /* Write out children within this loop. */ Ldot_print_loop_graph_loop(out, num_tabs + 1, loop->child_loop); write_tabs(out, num_tabs); fprintf(out, "}\n"); /* Now write out any related siblings. */ Ldot_print_loop_graph_loop(out, num_tabs, loop->sibling_loop); } static void Ldot_display_loop_graph(L_Func* fn, char* descr, int interactive) { FILE *out; char* timestr = NULL; const int bufsize = 512; char *filename = (char*) Lcode_malloc(sizeof(char) * bufsize); char *command = NULL; /* * 1. Setup the file. */ if (descr) snprintf(filename, bufsize, "DOT_LOOPGRAPH_%s_%s", fn->name, descr); else snprintf(filename, bufsize, "DOT_LOOPGRAPH_%s", fn->name); if (!(out = fopen(filename, "w"))) L_punt("could not open file for output: %s", filename); L_dot_print_file_header(out, fn->name); timestr = L_dot_get_curr_time(); fprintf(out, "\tthe_caption [fontname=\"%s\", shape=\"box\", ", L_DOT_FONT); if (descr) fprintf(out, "label=\"LOOPGRAPH for %s (%s), %s\"]\n", fn->name, descr, timestr); else fprintf(out, "label=\"LOOPGRAPH for %s, %s\"]\n", fn->name, timestr); /* * 2. Actually print the graph. */ Ldot_print_loop_graph_loop(out, 1, fn->first_loop); /* * 3. Close the file. */ L_dot_print_file_tail(out); fclose(out); if (interactive) { command = (char*) Lcode_malloc(sizeof(char) * bufsize); snprintf(command, bufsize, "dot -Tps %s > %s.ps", filename, filename); system(command); Lcode_free(command); } Lcode_free(filename); Lcode_free(timestr); } extern void Ldot_display_cfg(L_Func* fn, char* descr, int interactive) { const int show_loops = 0; FILE* out; L_Cb* cb; L_Flow* flow; L_Attr* attr; L_Oper* br_op; char* timestr = NULL; Set cbs_in_loops = NULL; const int bufsize = 512; char *filename = (char*) Lcode_malloc(sizeof(char) * bufsize); char *command = NULL; if (descr) snprintf(filename, bufsize, "DOT_CFG_%s_%s", fn->name, descr); else snprintf(filename, bufsize, "DOT_CFG_%s", fn->name); if (!(out = fopen(filename, "w"))) L_punt("could not open file for output: %s", filename); L_dot_print_file_header(out, fn->name); timestr = L_dot_get_curr_time(); fprintf(out, "\tthe_caption [fontname=\"%s\", shape=\"box\", ", L_DOT_FONT); if (descr) fprintf(out, "label=\"CFG for %s (%s), %s\"]\n", fn->name, descr, timestr); else fprintf(out, "label=\"CFG for %s, %s\"]\n", fn->name, timestr); fprintf(out, "\tcompound=true;\n"); /* Assumes that fn->first_loop returns an outermost loop (lowest # nesting * level) and that all loops are reachable by traversing sibling_loop and * child_loop. */ if (show_loops) write_loop_cluster(out, &cbs_in_loops, 1, fn->first_loop); for (cb = fn->first_cb; cb != NULL; cb = cb->next_cb) { if (Set_in(cbs_in_loops, cb->id)) continue; if ( (attr = L_find_attr(cb->attr, "Lthread_loop")) ) { int lthread_id = L_get_int_attr_field(attr, 0); int lthread_iter; attr = L_find_attr(cb->attr, "Lthread_iter"); lthread_iter = L_get_int_attr_field(attr, 0); fprintf(out,"cb_%d [fontname=\"%s\", label=\"cb %d\\n(loop %d.%d) wcet=%d", cb->id, L_DOT_FONT, cb->id, lthread_id, lthread_iter,cb->wcet); if(cb->ILP_is_in_wcet_path) fprintf(out,"#"); fprintf(out,"\"]\n"); } else { fprintf(out, "cb_%d [fontname=\"%s\", label=\"cb %d wcet=%d", cb->id, L_DOT_FONT, cb->id,cb->wcet); if(cb->ILP_is_in_wcet_path) fprintf(out,"#"); fprintf(out,"\"]\n"); } } for (cb = fn->first_cb; cb != NULL; cb = cb->next_cb) { for (flow = cb->dest_flow; flow != NULL; flow = flow->next_flow) { /* We don't use the results of this, but the call checks the CFG for * * errors. */ L_find_matching_flow(flow->dst_cb->src_flow, flow); fprintf(out, "\tcb_%d -> cb_%d ", flow->src_cb->id, flow->dst_cb->id); fprintf(out, "[label= \""); fprintf(out, "wcet=%d ",flow->wcet_weight); br_op = L_find_branch_for_flow(flow->src_cb, flow); if (flow->weight != 0.0) fprintf(out, "%.1f", flow->weight); if (flow->weight != 0.0 && br_op != NULL) fprintf(out, "\\n"); if (br_op != NULL) L_dot_print_branch_cond(out, br_op); fprintf(out, "\"];\n"); } } L_dot_print_file_tail(out); fclose(out); if (interactive) { command = (char*) Lcode_malloc(sizeof(char) * bufsize); snprintf(command, bufsize, "dot -Tps %s > %s.ps", filename, filename); system(command); Lcode_free(command); } Lcode_free(filename); Lcode_free(timestr); } #if 0 extern void Ldot_display_cfg(L_Func* fn, char* descr, int interactive) { FILE* out; L_Cb* cb; L_Flow* flow; L_Attr* attr; L_Oper* br_op; char* timestr = NULL; const int bufsize = 512; char *filename = (char*) Lcode_malloc(sizeof(char) * bufsize); char *command = NULL; if (descr) snprintf(filename, bufsize, "DOT_GRAPH_%s_%s", fn->name, descr); else snprintf(filename, bufsize, "DOT_GRAPH_%s", fn->name); if (!(out = fopen(filename, "w"))) L_punt("could not open file for output: %s", filename); L_dot_print_file_header(out, fn->name); timestr = L_dot_get_curr_time(); fprintf(out, "the_caption [fontname=\"%s\", shape=\"box\", ", L_DOT_FONT); if (descr) fprintf(out, "label=\"CFG for %s (%s), %s\"]\n", fn->name, descr, timestr); else fprintf(out, "label=\"CFG for %s, %s\"]\n", fn->name, timestr); for (cb = fn->first_cb; cb != NULL; cb = cb->next_cb) { if ( (attr = L_find_attr(cb->attr, "Lthread_loop")) ) { int lthread_id = L_get_int_attr_field(attr, 0); int lthread_iter; attr = L_find_attr(cb->attr, "Lthread_iter"); lthread_iter = L_get_int_attr_field(attr, 0); fprintf(out, "cb_%d [fontname=\"%s\", label=\"cb %d\\n(loop %d.%d)\"]\n", cb->id, L_DOT_FONT, cb->id, lthread_id, lthread_iter); } else { fprintf(out, "cb_%d [fontname=\"%s\", label=\"cb %d\"]\n", cb->id, L_DOT_FONT, cb->id); } } for (cb = fn->first_cb; cb != NULL; cb = cb->next_cb) { for (flow = cb->dest_flow; flow != NULL; flow = flow->next_flow) { /* We don't use the results of this, but the call checks the CFG for * * errors. */ L_find_matching_flow(flow->dst_cb->src_flow, flow); fprintf(out, "\tcb_%d -> cb_%d ", flow->src_cb->id, flow->dst_cb->id); fprintf(out, "[label= \""); br_op = L_find_branch_for_flow(flow->src_cb, flow); if (flow->weight != 0.0) fprintf(out, "%.1f", flow->weight); if (flow->weight != 0.0 && br_op != NULL) fprintf(out, "\\n"); if (br_op != NULL) L_dot_print_branch_cond(out, br_op); fprintf(out, "\"];\n"); } } L_dot_print_file_tail(out); fclose(out); if (interactive) { command = (char*) Lcode_malloc(sizeof(char) * bufsize); snprintf(command, bufsize, "dot -Tps %s > %s.ps", filename, filename); system(command); Lcode_free(command); } Lcode_free(filename); Lcode_free(timestr); } #endif extern void Ldot_process(L_Func* fn) { L_do_flow_analysis (fn, DOMINATOR_CB); /* must come before loop detection */ L_loop_detection(fn, 0); Ldot_display_loop_graph(fn, NULL, 1); Ldot_display_cfg(fn, NULL, 1); }
2
2
2024-11-18T18:09:53.080180+00:00
2023-08-09T21:04:51
dfde766a15b0db3b903489f94bb1737c135b1557
{ "blob_id": "dfde766a15b0db3b903489f94bb1737c135b1557", "branch_name": "refs/heads/master", "committer_date": "2023-08-09T21:04:51", "content_id": "d92207d1a5b6a0da6dcfd4ddc84c0f2393456186", "detected_licenses": [ "MIT" ], "directory_id": "060c02561085a494df306deb2f3a8fddb984c73a", "extension": "c", "filename": "gcoflow.c", "fork_events_count": 33, "gha_created_at": "2020-07-13T02:00:09", "gha_event_created_at": "2023-09-13T14:49:28", "gha_language": "C", "gha_license_id": "MIT", "github_id": 279184900, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 4044, "license": "MIT", "license_type": "permissive", "path": "/src/gcoflow.c", "provenance": "stackv2-0003.json.gz:319726", "repo_name": "Interlisp/maiko", "revision_date": "2023-08-09T21:04:51", "revision_id": "7fce08f92c221bcb98e5f6d560aa50cb942e95b3", "snapshot_id": "48631ae6abc9d98d5c3eeb5f5eb736adf400ea8f", "src_encoding": "UTF-8", "star_events_count": 110, "url": "https://raw.githubusercontent.com/Interlisp/maiko/7fce08f92c221bcb98e5f6d560aa50cb942e95b3/src/gcoflow.c", "visit_date": "2023-09-03T12:23:43.081470" }
stackv2
/* $Id: gcoflow.c,v 1.3 1999/05/31 23:35:32 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved */ /************************************************************************/ /* */ /* (C) Copyright 1989-95 Venue. All Rights Reserved. */ /* Manufactured in the United States of America. */ /* */ /*************************************************************************/ /* */ /* File Name : gcpunt.c */ /* */ /*************************************************************************/ /* */ /* Creation Date : July-8-1987 */ /* Written by Tomoru Teruuchi */ /* */ /*************************************************************************/ /* */ /* Functions : gc_handleoverflow(arg); */ /* gcmaptable(arg); */ /* */ /*************************************************************************/ /* Description : */ /* */ /*************************************************************************/ /* \Tomtom */ /*************************************************************************/ #include "version.h" #include "arith.h" // for GetSmalldata #include "gcdata.h" // for htoverflow, REC_GCLOOKUP #include "gcoflowdefs.h" // for gc_handleoverflow, gcmaptable #include "gcrdefs.h" // for doreclaim #include "lispemul.h" // for NIL, DLword, LispPTR #include "lspglob.h" // for Reclaim_cnt_word, HToverflow, MaxTypeNumber_word #include "lsptypes.h" // for dtd, GetDTD, TYPE_LISTP #define Increment_Allocation_Count(n) \ do { \ if (*Reclaim_cnt_word != NIL) { \ if (*Reclaim_cnt_word > (n)) \ (*Reclaim_cnt_word) -= (n); \ else { \ *Reclaim_cnt_word = NIL; \ doreclaim(); \ } \ } \ } while (0) DLword gc_handleoverflow(DLword arg) { struct htoverflow *cell; struct dtd *ptr; LispPTR cellcnt; LispPTR addr; cell = (struct htoverflow *)HToverflow; /* This proc. protected from interrupt */ while ((addr = cell->ptr) != NIL) { REC_GCLOOKUP(addr, cell->pcase); cell->ptr = 0; cell->pcase = 0; ++cell; /* (\ADDBASE CELL WORDSPERCELL) */ } ptr = (struct dtd *)GetDTD(TYPE_LISTP); /* same as "extern struct dtd *ListpDTD" */ if ((cellcnt = ptr->dtd_cnt0) > 1024) { Increment_Allocation_Count(cellcnt); ptr->dtd_oldcnt += cellcnt; ptr->dtd_cnt0 = 0; } return (arg); } DLword gcmaptable(DLword arg) { struct htoverflow *cell; struct dtd *ptr; LispPTR cellcnt; int typnum; LispPTR addr; int maxtypenumber = GetSmalldata(*MaxTypeNumber_word); cell = (struct htoverflow *)HToverflow; /* This proc. protected from interrupt */ while ((addr = cell->ptr) != NIL) { REC_GCLOOKUP(addr, cell->pcase); cell->ptr = 0; cell->pcase = 0; ++cell; /* (\ADDBASE CELL WORDSPERCELL) */ } for (typnum = 1; typnum <= maxtypenumber; ++typnum) /* applied alltype */ { ptr = (struct dtd *)GetDTD(typnum); if ((cellcnt = ptr->dtd_cnt0) != 0) { ptr->dtd_oldcnt += cellcnt; ptr->dtd_cnt0 = 0; Increment_Allocation_Count(cellcnt); } } return (arg); }
2.3125
2
2024-11-18T18:09:53.140119+00:00
2017-10-25T01:47:57
54566196b5b52d650ecbc552f01d8b92ce22c8a6
{ "blob_id": "54566196b5b52d650ecbc552f01d8b92ce22c8a6", "branch_name": "refs/heads/master", "committer_date": "2017-10-25T01:47:57", "content_id": "21942cb4caada76876d3a3abbc50046d5de4ca91", "detected_licenses": [ "MIT" ], "directory_id": "6dee7027bf6361194d5d2230c555121c9ed7209a", "extension": "c", "filename": "119.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 40413417, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2014, "license": "MIT", "license_type": "permissive", "path": "/UVa/UVa119/119.c", "provenance": "stackv2-0003.json.gz:319855", "repo_name": "mythnc/online-judge-solved-lists", "revision_date": "2017-10-25T01:47:57", "revision_id": "c8db91674298f74539312a763ff52c2ba0d9794d", "snapshot_id": "e1838583e95a16f68387977564df01900b4d7ae0", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/mythnc/online-judge-solved-lists/c8db91674298f74539312a763ff52c2ba0d9794d/UVa/UVa119/119.c", "visit_date": "2021-01-18T15:16:36.478995" }
stackv2
/* ACM 119 Greedy Gift Givers * mythnc * 2011/10/25 18:37:46 * run time: 0.004 * same as USACO Greedy Gift Givers (gift1.c) */ #include <stdio.h> #include <string.h> #define LEN 20 #define N 10 typedef struct group { char name[LEN + 1]; int money; } People; int findname(People *, char *); void eatname(int); void printout(People *, int); int main(void) { int n, i, j, k, money, ntake, line; char tmp[LEN + 1]; People person[N]; line = 0; while (scanf("%d", &n) != EOF) { for (i = 0; i < n; i++) { scanf("%s", person[i].name); person[i].money = 0; /* init */ } for (i = 0; i < n; i++) { scanf("%s %d %d", tmp, &money, &ntake); if (money == 0 || ntake == 0) { /* haven't to give money */ if (ntake > 0) eatname(ntake); continue; } j = findname(person, tmp); /* the giver name */ /* giver: the money giver have to pay */ person[j].money += money % ntake - money; for (j = 0; j < ntake; j++) { scanf("%s", tmp); k = findname(person, tmp); /* the taker name */ /* taker: the money taker get */ person[k].money += money / ntake; } } /* output */ if (line == 1) printf("\n"); printout(person, n); line = 1; } return 0; } /* findname: find the tmp name in person, * return the index of that name */ int findname(People *person, char *tmp) { int i; for (i = 0; ; i++) if (strcmp(person[i].name, tmp) == 0) return i; } /* eatname: eat name token */ void eatname(int n) { while (n--) scanf("%*s"); } /* printout: print out the results */ void printout(People *person, int n) { int i; for (i = 0; i < n; i++) printf("%s %d\n", person[i].name, person[i].money); }
3.359375
3
2024-11-18T18:09:53.373802+00:00
2019-02-01T18:53:38
63f73a8e19b52a5727b7066b945103a68a91f010
{ "blob_id": "63f73a8e19b52a5727b7066b945103a68a91f010", "branch_name": "refs/heads/master", "committer_date": "2019-02-01T18:53:38", "content_id": "a035a42992a56e9f34a3b270dd14895bd68d797c", "detected_licenses": [ "MIT" ], "directory_id": "50b8f61cd96254d052884f52abad9f838b84ffaf", "extension": "c", "filename": "USB.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": null, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 3010, "license": "MIT", "license_type": "permissive", "path": "/Software/blinky_mutant_inverter_via_labview_v8/Central Control/Comm/USB.c", "provenance": "stackv2-0003.json.gz:319986", "repo_name": "dongdong-2009/Kirtley_picogrid", "revision_date": "2019-02-01T18:53:38", "revision_id": "3bb52c55e9ed9cb5f91d36e366ab3978a417813a", "snapshot_id": "b107399b7c0e683c26c021a2a5c83b03ab00eb59", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/dongdong-2009/Kirtley_picogrid/3bb52c55e9ed9cb5f91d36e366ab3978a417813a/Software/blinky_mutant_inverter_via_labview_v8/Central Control/Comm/USB.c", "visit_date": "2023-04-01T23:31:05.961336" }
stackv2
#include "F28x_Project.h" #include "Comm.h" #include "../Peripheral/SCI.h" //***********************************************************************// // G l o b a l V a r i a b l e s // //***********************************************************************// Uint16 usb_tx[SIZEOFUSB_TX] = {0}; Uint16 usb_rx[SIZEOFUSB_RX] = {0}; extern Uint16 device_flag[NUMOFDEVICE]; extern Uint16 cast_flag[NUMOFDEVICE]; extern Uint16 RS485_addr[NUMOFDEVICE]; extern Uint16 RS485_tx[NUMOFDEVICE][SIZEOFRS485_TX]; extern Uint16 RS485_rx[NUMOFDEVICE][SIZEOFRS485_RX]; float32 lp[NUMOFDEVICE] = {100.0f, 100.0f, 100.0f}; float32 lq[NUMOFDEVICE] = {100.0f, 100.0f, 100.0f}; //***********************************************************************// // F u n c t i o n s // //***********************************************************************// void USB_TX(void) { SCIA_xmit(BEGIN); Uint16 i; for(i=0;i<SIZEOFUSB_TX;i++) { SCIA_xmit(usb_tx[i]); // usb_tx[i] = 0; //reset USB_TX data } SCIA_xmit(END); } void USB_RX (void) { Uint16 i; for (i = 0; i < SIZEOFUSB_RX; i++) { Uint16 j; j = (SIZEOFUSB_RX - 1) - (SciaRegs.SCIFFRX.bit.RXFFST - 1) % SIZEOFUSB_RX; usb_rx[i] = (j == i)? SciaRegs.SCIRXBUF.all : usb_rx[i]; //If data sequence matches, load the data; otherwises, do nth. } } void USB_TO_RS485Interpreter(void) { //LabView command - 0: command; 1: address; 2: N/A; 3:value Uint16 addr = 0; Uint16 i = 0; addr = usb_rx[1]; // 1: central, 0: all invs, 100: inv0, 101: inv1, 102: inv2 //Matching Address if (addr == ADDR_HOST){ // When addr = 0, labview is commanding central controller if (usb_rx[0] == 191) GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; if (usb_rx[0] == 192) GpioDataRegs.GPASET.bit.GPIO0 = 1; if (usb_rx[0] == 193) GpioDataRegs.GPACLEAR.bit.GPIO1 = 1; if (usb_rx[0] == 194) GpioDataRegs.GPASET.bit.GPIO1 = 1; if (usb_rx[0] == 195) GpioDataRegs.GPACLEAR.bit.GPIO2 = 1; if (usb_rx[0] == 196) GpioDataRegs.GPASET.bit.GPIO2 = 1; if (usb_rx[0] == 181) lp[0] = usb_rx[3]; if (usb_rx[0] == 182) lq[0] = usb_rx[3]; if (usb_rx[0] == 183) lp[1] = usb_rx[3]; if (usb_rx[0] == 184) lq[1] = usb_rx[3]; if (usb_rx[0] == 185) lp[2] = usb_rx[3]; if (usb_rx[0] == 186) lq[2] = usb_rx[3]; if (usb_rx[0] == 107) GpioDataRegs.GPCSET.bit.GPIO79 = 1; // LED 4 ... LEDs: 73,75,77,79,81,83 if (usb_rx[0] == 108) GpioDataRegs.GPCCLEAR.bit.GPIO79 = 1; } else{ for (i = 0; i < NUMOFDEVICE; i++) { if (addr == ADDR_BROADCAST || RS485_addr[i] == addr){ RS485_tx[i][0] = usb_rx[0]; // command RS485_tx[i][1] = usb_rx[3]; // value device_flag[i] = 1; if (addr == ADDR_BROADCAST) cast_flag[i] = 1; } } } }
2.046875
2
2024-11-18T18:09:53.648584+00:00
2018-12-20T07:28:19
de4d4d67bb1a8352a975070378477b8cd4aea4ac
{ "blob_id": "de4d4d67bb1a8352a975070378477b8cd4aea4ac", "branch_name": "refs/heads/master", "committer_date": "2018-12-20T07:28:19", "content_id": "61d3dce02b0bd68699ce4937157f45ae0fac8183", "detected_licenses": [], "directory_id": "d12d28e6a2d73486be55648b33fa173ffc734098", "extension": "c", "filename": "malloc.c", "fork_events_count": 0, "gha_created_at": "2018-03-20T09:11:46", "gha_event_created_at": "2018-03-20T09:16:58", "gha_language": "C", "gha_license_id": "Unlicense", "github_id": 125990541, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 5872, "license": "", "license_type": "permissive", "path": "/malloc/malloc.c", "provenance": "stackv2-0003.json.gz:320373", "repo_name": "wx-csy/linux-utils", "revision_date": "2018-12-20T07:28:19", "revision_id": "f297c6b3ab5f40c8ca4d9895787d25c7a04738e2", "snapshot_id": "9c4d50528601cd31b52b9bdf7e7c306b3a3045f0", "src_encoding": "UTF-8", "star_events_count": 1, "url": "https://raw.githubusercontent.com/wx-csy/linux-utils/f297c6b3ab5f40c8ca4d9895787d25c7a04738e2/malloc/malloc.c", "visit_date": "2021-10-09T02:55:03.990478" }
stackv2
#define _GNU_SOURCE #include "malloc.h" #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <stdarg.h> #include <errno.h> #include <unistd.h> #include <pthread.h> #include <sys/mman.h> //========================================================= // Your implementations HERE //========================================================= static void die(const char *format, ...) { va_list args; va_start(args, format); vfprintf(stderr, format, args); va_end(args); exit(EXIT_FAILURE); } static const size_t page_size = 1024 * 64; #define PAGE_MINI_BLOCK 0 #define PAGE_HUGE_BLOCK 1 //======================================================== // FREE PAGE MANAGEMENT //======================================================== typedef struct free_page { void *next_page; } free_page; static free_page *free_page_head = NULL; static int free_page_count = 0; static pthread_mutex_t fp_mutex = PTHREAD_MUTEX_INITIALIZER; static void release_free_page(free_page *page); static free_page *alloc_free_page() { pthread_mutex_lock(&fp_mutex); free_page *current_page = free_page_head; if (current_page != NULL) { free_page_head = free_page_head->next_page; free_page_count--; pthread_mutex_unlock(&fp_mutex); } else { pthread_mutex_unlock(&fp_mutex); void *page = mmap(NULL, page_size << 1, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (page == NULL) return NULL; size_t margin = ((uintptr_t)page) & (page_size - 1); if (margin == 0) { current_page = page; release_free_page((free_page *)(page + page_size)); } else { current_page = (free_page *)((uint8_t *)(page) + (page_size - margin)); munmap(page, page_size - margin); munmap((uint8_t *)(current_page) + page_size, margin); } } return current_page; } static void release_free_page(free_page *page) { pthread_mutex_lock(&fp_mutex); if (free_page_count >= 32) { pthread_mutex_unlock(&fp_mutex); munmap(page, page_size); } else { page->next_page = free_page_head; free_page_head = page; free_page_count++; pthread_mutex_unlock(&fp_mutex); } } //======================================================== // MINI PAGES //======================================================== typedef struct page_mini_block { uint16_t page_type; uint16_t active; uint32_t used_block; uint32_t freed_block; uint32_t ptr; } page_mini_block; #define NUM_PAGE_MINI_BLOCK 4 page_mini_block *current_page_mini_block[NUM_PAGE_MINI_BLOCK]; static page_mini_block *alloc_page_mini_block() { page_mini_block *page = (page_mini_block *)alloc_free_page(); if (page == NULL) return NULL; page->page_type = PAGE_MINI_BLOCK; page->active = 1; page->used_block = 0; page->freed_block = 0; page->ptr = page_size; return page; } static void free_mini_block(page_mini_block *page); static void *alloc_mini_block(size_t sz) { void *ret; // try to find a page with enough space by atomic xchg operation page_mini_block *page = NULL; for (int i = 0; i < NUM_PAGE_MINI_BLOCK; i++) { page = __atomic_exchange_n(current_page_mini_block + i, page, __ATOMIC_SEQ_CST); if (page != NULL && sizeof(page_mini_block) + sz <= page->ptr) goto alloc_page_succ; } // fail to find a suitable page, allocate a new one page = alloc_page_mini_block(); if (page == NULL) return NULL; alloc_page_succ: ret = (uint8_t *)page + (page->ptr -= sz); page->used_block++; // put back the page into the list void *expected = NULL; for (int i = 0; i < NUM_PAGE_MINI_BLOCK; i++) { if (__atomic_compare_exchange_n(current_page_mini_block + i, &expected, page, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) goto putback_succ; expected = NULL; } // fail to put back the page // add a reference count to avoid atomicity violation page->used_block++; // mark the page inactive; once the page becomes inactive, // the number of used blocks never increases __atomic_store_n(&page->active, 0, __ATOMIC_SEQ_CST); // decrease the reference count free_mini_block(page); putback_succ: return ret; } static void free_mini_block(page_mini_block *page) { uint32_t freed_block = __atomic_add_fetch(&page->freed_block, 1, __ATOMIC_SEQ_CST); if (__atomic_load_n(&page->active, __ATOMIC_SEQ_CST) == 0 && page->used_block == freed_block) release_free_page((free_page *)page); } //================================================ // HUGE PAGES //================================================ typedef struct page_huge_block { uint16_t page_type; uint16_t active; size_t tot_size; } page_huge_block; static void *alloc_huge_block(size_t size) { size_t tot_size = size + sizeof(page_huge_block) + page_size; page_huge_block *page = mmap(NULL, tot_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (page == MAP_FAILED) return NULL; size_t margin = (uintptr_t)page & (page_size - 1); munmap(page, page_size - margin); tot_size -= page_size - margin; page = (page_huge_block *)((uint8_t*)page + (page_size - margin)); page->page_type = PAGE_HUGE_BLOCK; page->active = 1; page->tot_size = tot_size; return page + sizeof(page_huge_block); } static void free_huge_block(page_huge_block *page) { munmap(page, page->tot_size); } void *do_malloc(size_t size) { void *ret; if (size < page_size / 4) { ret = alloc_mini_block(size); } else { ret = alloc_huge_block(size); } return ret; } void do_free(void *ptr) { void *page = (void *)((uintptr_t)(ptr) & (-page_size)); switch (*(uint16_t *)page) { case PAGE_MINI_BLOCK: free_mini_block(page); break; case PAGE_HUGE_BLOCK: free_huge_block(page); break; default: die("free(): Heap corruption detected!\n"); } }
2.75
3
2024-11-18T18:09:54.089438+00:00
2019-08-06T14:24:54
6e95e6d95294548caa5c200620cfb1945f80b7b4
{ "blob_id": "6e95e6d95294548caa5c200620cfb1945f80b7b4", "branch_name": "refs/heads/master", "committer_date": "2019-08-06T14:24:54", "content_id": "edfe821b5c0acf2e61fd6ebd5598f7b1fa211e21", "detected_licenses": [ "BSD-2-Clause" ], "directory_id": "021a3ccdcb91d84629f1de7343981b572840b169", "extension": "c", "filename": "water.c", "fork_events_count": 8, "gha_created_at": "2016-02-22T11:40:41", "gha_event_created_at": "2023-04-11T09:20:08", "gha_language": "C", "gha_license_id": "NOASSERTION", "github_id": 52269402, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 5291, "license": "BSD-2-Clause", "license_type": "permissive", "path": "/src/snes/examples/tutorials/network/water/water.c", "provenance": "stackv2-0003.json.gz:320888", "repo_name": "firedrakeproject/petsc", "revision_date": "2019-08-06T14:24:54", "revision_id": "7afe75c1a0a66862f32d7a0f5c0c5ae5079c4c77", "snapshot_id": "dcf7b32e83bdc88d37099904960d7a4c3c4a89e4", "src_encoding": "UTF-8", "star_events_count": 2, "url": "https://raw.githubusercontent.com/firedrakeproject/petsc/7afe75c1a0a66862f32d7a0f5c0c5ae5079c4c77/src/snes/examples/tutorials/network/water/water.c", "visit_date": "2023-08-31T22:16:45.175956" }
stackv2
static char help[] = "This example demonstrates the use of DMNetwork interface for solving a steady-state water network model.\n\ The water network equations follow those used for the package EPANET\n\ The data file format used is from the EPANET package (https://www.epa.gov/water-research/epanet).\n\ Run this program: mpiexec -n <n> ./water\n\\n"; /* T Concepts: DMNetwork Concepts: PETSc SNES solver */ #include "water.h" #include <petscdmnetwork.h> int main(int argc,char ** argv) { PetscErrorCode ierr; char waterdata_file[PETSC_MAX_PATH_LEN]="sample1.inp"; WATERDATA *waterdata; AppCtx_Water appctx; PetscLogStage stage1,stage2; PetscMPIInt crank; DM networkdm; PetscInt *edgelist = NULL; PetscInt nv,ne,i; const PetscInt *vtx,*edges; Vec X,F; SNES snes; SNESConvergedReason reason; ierr = PetscInitialize(&argc,&argv,"wateroptions",help);if (ierr) return ierr; ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&crank);CHKERRQ(ierr); /* Create an empty network object */ ierr = DMNetworkCreate(PETSC_COMM_WORLD,&networkdm);CHKERRQ(ierr); /* Register the components in the network */ ierr = DMNetworkRegisterComponent(networkdm,"edgestruct",sizeof(struct _p_EDGE_Water),&appctx.compkey_edge);CHKERRQ(ierr); ierr = DMNetworkRegisterComponent(networkdm,"busstruct",sizeof(struct _p_VERTEX_Water),&appctx.compkey_vtx);CHKERRQ(ierr); ierr = PetscLogStageRegister("Read Data",&stage1);CHKERRQ(ierr); PetscLogStagePush(stage1); ierr = PetscNew(&waterdata);CHKERRQ(ierr); /* READ THE DATA */ if (!crank) { /* READ DATA. Only rank 0 reads the data */ ierr = PetscOptionsGetString(NULL,NULL,"-waterdata",waterdata_file,PETSC_MAX_PATH_LEN-1,NULL);CHKERRQ(ierr); ierr = WaterReadData(waterdata,waterdata_file);CHKERRQ(ierr); ierr = PetscCalloc1(2*waterdata->nedge,&edgelist);CHKERRQ(ierr); ierr = GetListofEdges_Water(waterdata,edgelist);CHKERRQ(ierr); } PetscLogStagePop(); ierr = PetscLogStageRegister("Create network",&stage2);CHKERRQ(ierr); PetscLogStagePush(stage2); /* Set numbers of nodes and edges */ ierr = DMNetworkSetSizes(networkdm,1,&waterdata->nvertex,&waterdata->nedge,0,NULL);CHKERRQ(ierr); if (!crank) { ierr = PetscPrintf(PETSC_COMM_SELF,"water nvertices %D, nedges %D\n",waterdata->nvertex,waterdata->nedge);CHKERRQ(ierr); } /* Add edge connectivity */ ierr = DMNetworkSetEdgeList(networkdm,&edgelist,NULL);CHKERRQ(ierr); /* Set up the network layout */ ierr = DMNetworkLayoutSetUp(networkdm);CHKERRQ(ierr); if (!crank) { ierr = PetscFree(edgelist);CHKERRQ(ierr); } /* ADD VARIABLES AND COMPONENTS FOR THE NETWORK */ ierr = DMNetworkGetSubnetworkInfo(networkdm,0,&nv,&ne,&vtx,&edges);CHKERRQ(ierr); for (i = 0; i < ne; i++) { ierr = DMNetworkAddComponent(networkdm,edges[i],appctx.compkey_edge,&waterdata->edge[i]);CHKERRQ(ierr); } for (i = 0; i < nv; i++) { ierr = DMNetworkAddComponent(networkdm,vtx[i],appctx.compkey_vtx,&waterdata->vertex[i]);CHKERRQ(ierr); /* Add number of variables */ ierr = DMNetworkAddNumVariables(networkdm,vtx[i],1);CHKERRQ(ierr); } /* Set up DM for use */ ierr = DMSetUp(networkdm);CHKERRQ(ierr); if (!crank) { ierr = PetscFree(waterdata->vertex);CHKERRQ(ierr); ierr = PetscFree(waterdata->edge);CHKERRQ(ierr); } ierr = PetscFree(waterdata);CHKERRQ(ierr); /* Distribute networkdm to multiple processes */ ierr = DMNetworkDistribute(&networkdm,0);CHKERRQ(ierr); PetscLogStagePop(); ierr = DMCreateGlobalVector(networkdm,&X);CHKERRQ(ierr); ierr = VecDuplicate(X,&F);CHKERRQ(ierr); /* HOOK UP SOLVER */ ierr = SNESCreate(PETSC_COMM_WORLD,&snes);CHKERRQ(ierr); ierr = SNESSetDM(snes,networkdm);CHKERRQ(ierr); ierr = SNESSetOptionsPrefix(snes,"water_");CHKERRQ(ierr); ierr = SNESSetFunction(snes,F,WaterFormFunction,NULL);CHKERRQ(ierr); ierr = SNESSetFromOptions(snes);CHKERRQ(ierr); ierr = WaterSetInitialGuess(networkdm,X);CHKERRQ(ierr); /* ierr = VecView(X,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); */ ierr = SNESSolve(snes,NULL,X);CHKERRQ(ierr); ierr = SNESGetConvergedReason(snes,&reason);CHKERRQ(ierr); if (reason < 0) { SETERRQ(PETSC_COMM_SELF,0,"No solution found for the water network"); } /* ierr = VecView(X,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); */ ierr = VecDestroy(&X);CHKERRQ(ierr); ierr = VecDestroy(&F);CHKERRQ(ierr); ierr = SNESDestroy(&snes);CHKERRQ(ierr); ierr = DMDestroy(&networkdm);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; } /*TEST build: depends: waterreaddata.c waterfunctions.c requires: !complex double define(PETSC_HAVE_ATTRIBUTEALIGNED) test: args: -water_snes_converged_reason -options_left no localrunfiles: wateroptions sample1.inp output_file: output/water.out requires: double !complex define(PETSC_HAVE_ATTRIBUTEALIGNED) test: suffix: 2 nsize: 3 args: -water_snes_converged_reason -options_left no localrunfiles: wateroptions sample1.inp output_file: output/water.out requires: double !complex define(PETSC_HAVE_ATTRIBUTEALIGNED) TEST*/
2.265625
2
2024-11-18T18:09:54.522100+00:00
2015-03-19T01:37:07
dae06f8a17a7cf1d5ebcd20d0c001b0628da3f03
{ "blob_id": "dae06f8a17a7cf1d5ebcd20d0c001b0628da3f03", "branch_name": "refs/heads/master", "committer_date": "2015-03-19T01:37:07", "content_id": "d46adf83fff95565e86e6bf94c7687c92b7b93ea", "detected_licenses": [ "Apache-2.0" ], "directory_id": "d5f639197cfc4c7207c80685ea17fa9440c9dd15", "extension": "c", "filename": "grid.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 16779471, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 6150, "license": "Apache-2.0", "license_type": "permissive", "path": "/compilador2/Lote de pruebas/Nueva carpeta/grid.c", "provenance": "stackv2-0003.json.gz:321275", "repo_name": "TVilaboa/Proyecto-Parser-C", "revision_date": "2015-03-19T01:37:07", "revision_id": "7591853511bf6f05e63df92e9b15c319414d088a", "snapshot_id": "ac4411f6a09e2ee069c1e4b60d228dbf7c622a56", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/TVilaboa/Proyecto-Parser-C/7591853511bf6f05e63df92e9b15c319414d088a/compilador2/Lote de pruebas/Nueva carpeta/grid.c", "visit_date": "2021-01-19T21:51:57.936701" }
stackv2
/* Dia -- an diagram creation/manipulation program * Copyright (C) 1998 Alexander Larsson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include "config.h" #include "intl.h" #include "grid.h" #include "preferences.h" void grid_draw(DDisplay *ddisp, Rectangle *update) { Grid *grid = &ddisp->grid; Renderer *renderer = &ddisp->renderer->renderer; int width = ddisp->renderer->renderer.pixel_width; int height = ddisp->renderer->renderer.pixel_height; if ( (ddisplay_transform_length(ddisp, grid->width_x) <= 1.0) || (ddisplay_transform_length(ddisp, grid->width_y) <= 1.0) ) { return; } if (grid->visible) { real pos; int x,y; (renderer->ops->set_linewidth)(renderer, 0.0); if (prefs.grid.solid) { (renderer->ops->set_linestyle)(renderer, LINESTYLE_SOLID); } else { (renderer->ops->set_dashlength)(renderer, ddisplay_untransform_length(ddisp, 31)); (renderer->ops->set_linestyle)(renderer, LINESTYLE_DOTTED); } /* Vertical lines: */ pos = ceil( update->left / grid->width_x )*grid->width_x; while (pos <= update->right) { ddisplay_transform_coords(ddisp, pos,0,&x,&y); (renderer->interactive_ops->draw_pixel_line)(renderer, x, 0, x, height, &prefs.grid.colour); pos += grid->width_x; } /* Horizontal lines: */ pos = ceil( update->top / grid->width_y )*grid->width_y; while (pos <= update->bottom) { ddisplay_transform_coords(ddisp, 0,pos,&x,&y); (renderer->interactive_ops->draw_pixel_line)(renderer, 0, y, width, y, &prefs.grid.colour); pos += grid->width_y; } } } void snap_to_grid(Grid *grid, coord *x, coord *y) { if (grid->snap) { *x = ROUND((*x) / grid->width_x) * grid->width_x; *y = ROUND((*y) / grid->width_y) * grid->width_y; } } static void grid_x_update(GtkWidget *entry, DDisplay *ddisp) { real size; char buffer[32]; size = atof(gtk_entry_get_text(GTK_ENTRY(entry))); if (size > 0.01) { ddisp->grid.width_x = size; snprintf(buffer, 32, "%.2f", (double) ddisp->grid.width_x); gtk_entry_set_text(GTK_ENTRY(entry), buffer); ddisplay_add_update_all(ddisp); ddisplay_flush(ddisp); } } static gint grid_x_update_event(GtkWidget *entry, GdkEventFocus *ev, DDisplay *ddisp) { grid_x_update(entry, ddisp); return FALSE; } static void grid_y_update(GtkWidget *entry, DDisplay *ddisp) { real size; char buffer[32]; size = atof(gtk_entry_get_text(GTK_ENTRY(entry))); if (size > 0.01) { ddisp->grid.width_y = size; snprintf(buffer, 32, "%.2f", (double) ddisp->grid.width_y); gtk_entry_set_text(GTK_ENTRY(entry), buffer); ddisplay_add_update_all(ddisp); ddisplay_flush(ddisp); } } static gint grid_y_update_event(GtkWidget *entry, GdkEventFocus *ev, DDisplay *ddisp) { grid_y_update(entry, ddisp); return FALSE; } void grid_show_dialog(Grid *grid, DDisplay *ddisp) { if (grid->dialog == NULL) { GtkWidget *dialog; GtkWidget *vbox; GtkWidget *hbox; GtkWidget *label, *entry; char buffer[32]; grid->dialog = dialog = gtk_window_new(GTK_WINDOW_DIALOG); gtk_window_set_title (GTK_WINDOW (dialog), _("Grid options")); gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); gtk_signal_connect (GTK_OBJECT (dialog), "delete_event", GTK_SIGNAL_FUNC(gtk_widget_hide), NULL); vbox = gtk_vbox_new(FALSE, 5); gtk_container_add(GTK_CONTAINER(dialog), vbox); hbox = gtk_hbox_new(FALSE, 5); label = gtk_label_new(_("Grid x size:")); grid->entry_x = entry = gtk_entry_new(); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0); gtk_widget_show(label); gtk_widget_show(entry); gtk_widget_show(hbox); snprintf(buffer, 32, "%.2f", (double) grid->width_x); gtk_entry_set_text(GTK_ENTRY(entry), buffer); grid->handler_x = gtk_signal_connect (GTK_OBJECT (entry), "focus_out_event", GTK_SIGNAL_FUNC (grid_x_update_event), ddisp); gtk_signal_connect (GTK_OBJECT (entry), "activate", GTK_SIGNAL_FUNC (grid_x_update), ddisp); hbox = gtk_hbox_new(FALSE, 5); label = gtk_label_new(_("Grid y size:")); grid->entry_y = entry = gtk_entry_new(); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0); gtk_widget_show(label); gtk_widget_show(entry); gtk_widget_show(hbox); snprintf(buffer, 32, "%.2f", (double) grid->width_y); gtk_entry_set_text(GTK_ENTRY(entry), buffer); grid->handler_y = gtk_signal_connect (GTK_OBJECT (entry), "focus_out_event", GTK_SIGNAL_FUNC (grid_y_update_event), ddisp); gtk_signal_connect (GTK_OBJECT (entry), "activate", GTK_SIGNAL_FUNC (grid_y_update), ddisp); gtk_widget_show(vbox); } gtk_widget_show(grid->dialog); } void grid_destroy_dialog(Grid *grid) { if (grid->dialog) { /* Have to remove these, or will get segfault if they are active: */ gtk_signal_disconnect(GTK_OBJECT(grid->entry_x), grid->handler_x); gtk_signal_disconnect(GTK_OBJECT(grid->entry_y), grid->handler_y); gtk_widget_destroy(grid->dialog); } }
2.328125
2
2024-11-18T18:09:55.640091+00:00
2017-12-23T14:30:50
31c8bb6c54f327ff640841f11ee9d6eb976988a8
{ "blob_id": "31c8bb6c54f327ff640841f11ee9d6eb976988a8", "branch_name": "refs/heads/master", "committer_date": "2017-12-23T14:30:50", "content_id": "9f828867f51a6261d29409e0027638244cebe5c3", "detected_licenses": [ "MIT" ], "directory_id": "32c1cb02fef24306e486f26327ab0c48c71477cd", "extension": "c", "filename": "isNonNegative.c", "fork_events_count": 2, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 55706066, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 622, "license": "MIT", "license_type": "permissive", "path": "/Foundation-of-CS/ics14_lab1-3/lab1/src/puzzles/isNonNegative.c", "provenance": "stackv2-0003.json.gz:321532", "repo_name": "chaohu/Daily-Learning", "revision_date": "2017-12-23T14:30:50", "revision_id": "0e8d14a3497ad319eda20bc4682cec08d5d6fb08", "snapshot_id": "f015cdc8bfa3046780acf5c54ad0604bb82fb8a5", "src_encoding": "UTF-8", "star_events_count": 12, "url": "https://raw.githubusercontent.com/chaohu/Daily-Learning/0e8d14a3497ad319eda20bc4682cec08d5d6fb08/Foundation-of-CS/ics14_lab1-3/lab1/src/puzzles/isNonNegative.c", "visit_date": "2021-01-19T03:00:29.302645" }
stackv2
#ifdef PROTOTYPE int isNonNegative(int); int test_isNonNegative(int); #endif #ifdef DECL {"isNonNegative", (funct_t) isNonNegative, (funct_t) test_isNonNegative, 1, "! ~ & ^ | + << >>", 6, 3, {{TMin, TMax},{TMin,TMax},{TMin,TMax}}}, #endif #ifdef CODE /* * isNonNegative - return 1 if x >= 0, return 0 otherwise * Example: isNonNegative(-1) = 0. isNonNegative(0) = 1. * Legal ops: ! ~ & ^ | + << >> * Max ops: 6 * Rating: 3 */ int isNonNegative(int x) { #ifdef FIX return ((~x)>>31) & 0x1; #else return 2; #endif } #endif #ifdef TEST int test_isNonNegative(int x) { return x >= 0; } #endif
2.765625
3
2024-11-18T18:09:55.711543+00:00
2017-12-23T10:46:07
933e8eb73d0c4ecb3c7bc21543bb120e377cf7ac
{ "blob_id": "933e8eb73d0c4ecb3c7bc21543bb120e377cf7ac", "branch_name": "refs/heads/master", "committer_date": "2017-12-23T10:46:07", "content_id": "b5f608f56e23addf57ef530942c34970a9e97444", "detected_licenses": [ "BSD-3-Clause" ], "directory_id": "2c3d26c50fca18b819c39c42c72ad95de842bb61", "extension": "c", "filename": "main.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 115145967, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 7116, "license": "BSD-3-Clause", "license_type": "permissive", "path": "/avr/newboot-0.4.1/main.c", "provenance": "stackv2-0003.json.gz:321661", "repo_name": "tdididit/a78-sdcart", "revision_date": "2017-12-23T10:46:07", "revision_id": "cb8a14dbedf04ecf08002f1bf0e678929f99aaa8", "snapshot_id": "08b3dfc9cf1bf0e978a44a9ef934a525a9f9302b", "src_encoding": "UTF-8", "star_events_count": 1, "url": "https://raw.githubusercontent.com/tdididit/a78-sdcart/cb8a14dbedf04ecf08002f1bf0e678929f99aaa8/avr/newboot-0.4.1/main.c", "visit_date": "2021-08-31T23:10:51.898032" }
stackv2
/* newboot - an AVR MMC/SD boot loader compatible with HolgerBootloader2 Based on a heavily modified version of ChaN's FatFs library Copyright (C) 2011 Ingo Korb <[email protected]> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. main.c: The actual flash updater */ #include <stdio.h> #include <string.h> #include <avr/boot.h> #include <avr/interrupt.h> #include <avr/pgmspace.h> #include <avr/power.h> #include <avr/wdt.h> #include <util/delay.h> #include <util/crc16.h> #include "config.h" #include "ff.h" #ifdef __AVR_ATmega1284P__ /* fix an issue with the avr-libc from Debian lenny */ # undef SPM_PAGESIZE # define SPM_PAGESIZE 256 #endif /* create alias to the correct progmem read function */ #if BINARY_LENGTH >= 65536 # define flash_read_word(x) pgm_read_word_far(x) #else # define flash_read_word(x) pgm_read_word(x) #endif #define min(a,b) ((a)<(b)?(a):(b)) typedef struct { uint32_t device_id; uint16_t version; uint16_t crc; } bootinfo_t; static FATFS fat; static DIR dh; static FILINFO finfo; static FRESULT fr; static FIL fd; static bootinfo_t file_bi; static uint8_t databuffer[512]; static void flash_file(void) { uint32_t address; uint16_t remain = BINARY_LENGTH/512; uint8_t i,j; uint16_t *ptr; /* reopen file to reset offset */ l_openfile(&fat, &finfo, &fd); address = 0; while (remain--) { /* toggle green LED */ set_green_led(remain & 1); /* read sector */ if (f_read(&fd, databuffer, 512) != FR_OK) break; /* flash sector */ ptr = (uint16_t *)databuffer; for (i=0; i < 512 / SPM_PAGESIZE; i++) { /* erase page */ boot_page_erase(address); boot_spm_busy_wait(); /* copy new contents */ for (j=0; j<SPM_PAGESIZE/2; j++) boot_page_fill(address + j*2, *ptr++); /* write page */ boot_page_write(address); boot_spm_busy_wait(); address += SPM_PAGESIZE; } } boot_rww_enable(); } static uint8_t validate_file(void) { uint8_t *ptr; uint16_t i,crc; uint16_t remain; /* open file, can't fail */ l_openfile(&fat, &finfo, &fd); /* calculate CRC */ remain = BINARY_LENGTH/512; crc = 0xffff; while (remain) { if (f_read(&fd, databuffer, 512) != FR_OK) return 0; remain--; ptr = databuffer; for (i=0; i<512; i++) crc = _crc_ccitt_update(crc, *ptr++); } if (crc != 0) return 0; /* copy bootinfo from buffer*/ memcpy(&file_bi, databuffer+512-sizeof(bootinfo_t), sizeof(bootinfo_t)); /* check bootinfo contents */ if (file_bi.device_id != BOOTLOADER_DEVID) { return 0; } /* dev mode */ if (file_bi.version == 0 && file_bi.crc != flash_read_word(BINARY_LENGTH - sizeof(bootinfo_t) + offsetof(bootinfo_t, crc))) { return 1; } /* check version */ uint16_t flashversion = flash_read_word(BINARY_LENGTH - sizeof(bootinfo_t) + offsetof(bootinfo_t, version)); if (flashversion == 0xffff || file_bi.version > flashversion) { return 1; } return 0; } static void try_update(void) { set_green_led(1); /* mount file system */ fr = f_mount(0, &fat); if (fr != FR_OK) { set_green_led(0); return; } l_openroot(&fat, &dh); while ((f_readdir(&dh, &finfo) == FR_OK) && finfo.fname[0] != 0) { if (finfo.fsize == BINARY_LENGTH) { /* candidate file found - validate and flash if valid */ if (validate_file()) { flash_file(); break; } } } set_green_led(0); } static void __attribute__((noreturn)) (*start_app)(void) = 0; static void try_start_app(void) { uint16_t crc = 0xffff; uint16_t addr; /* check in-flash CRC */ #if BINARY_LENGTH < 64*1024 for (addr=0; addr<BINARY_LENGTH; addr++) crc = _crc_ccitt_update(crc, pgm_read_byte(addr)); #elif BINARY_LENGTH < 128*1024 /* slightly smaller and faster than a 32 bit loop counter */ addr = 0; do { crc = _crc_ccitt_update(crc, pgm_read_byte(addr)); } while (++addr != 0); for (addr=0; addr < BINARY_LENGTH - 65536; addr++) crc = _crc_ccitt_update(crc, pgm_read_byte_far(65536UL + addr)); #else # error FIXME: Devices larger than 128K not supported yet #endif if (crc == 0) { /* deinitialize hardware */ leds_deinit(); SPCR = 0; SPSR = 0; SPI_PORT = 0; SPI_DDR = 0; /* start app */ start_app(); } else { /* blink red LED for two seconds if application is corrupted */ for (uint8_t i=0; i<10;i++) { set_red_led(0); _delay_ms(100); set_red_led(1); _delay_ms(100); } return; } } /* Make sure the watchdog is disabled as soon as possible */ void disable_watchdog(void) \ __attribute__((naked)) \ __attribute__((section(".init3"))); void disable_watchdog(void) { wdt_disable(); } /* backup SPM instruction in case someone wants to write a bootloader-updater */ void __attribute((naked,section(".flash_end"))) spm_instruction(void) { asm volatile("spm\n" "ret\n"); } #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 1) int main(void) __attribute__((OS_main)); #endif int main(void) { /* disable JTAG */ asm volatile("in r24, %0\n" "ori r24, 0x80\n" "out %0, r24\n" "out %0, r24\n" : : "I" (_SFR_IO_ADDR(MCUCR)) : "r24" ); leds_init(); set_red_led(1); set_green_led(0); while (1) { try_update(); try_start_app(); // set_red_led(0); // _delay_ms(100); // set_red_led(1); // _delay_ms(100); } }
2.09375
2
2024-11-18T18:09:55.777412+00:00
2020-03-26T04:02:44
1ebc7a8c7ae01764f0ebe72baa94a1e8639311cd
{ "blob_id": "1ebc7a8c7ae01764f0ebe72baa94a1e8639311cd", "branch_name": "refs/heads/master", "committer_date": "2020-03-26T04:02:44", "content_id": "4e2f0ac7f6e418ade04dc9d2c45c34b08786e703", "detected_licenses": [ "MIT", "BSD-2-Clause" ], "directory_id": "88fd68187a3d4baeedaad69401afaa92321e2947", "extension": "c", "filename": "gdb_bogus_breakpoint.c", "fork_events_count": 0, "gha_created_at": "2020-03-26T04:21:25", "gha_event_created_at": "2020-03-26T04:21:26", "gha_language": null, "gha_license_id": "NOASSERTION", "github_id": 250160049, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 996, "license": "MIT,BSD-2-Clause", "license_type": "permissive", "path": "/src/test/gdb_bogus_breakpoint.c", "provenance": "stackv2-0003.json.gz:321789", "repo_name": "CyrusHashem/rr", "revision_date": "2020-03-26T04:02:44", "revision_id": "53fa20b34f1108362affe57e9314aba1840f2a8a", "snapshot_id": "42d903d209afab8a04e124556c242a2dc93fa0c4", "src_encoding": "UTF-8", "star_events_count": 1, "url": "https://raw.githubusercontent.com/CyrusHashem/rr/53fa20b34f1108362affe57e9314aba1840f2a8a/src/test/gdb_bogus_breakpoint.c", "visit_date": "2022-04-12T21:06:08.172302" }
stackv2
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */ #include "util.h" static char ch = 'E'; static char my_write(int fd, void* buf, size_t size) { long ret; /* Do a write syscall where the address of the buffer is at the top of stack during the syscall. This may trigger gdb to try to set a breakpoint in that buffer. */ #ifdef __x86_64__ asm("push %5\n\t" "syscall\n\t" "nop\n\t" "nop\n\t" "nop\n\t" "pop %5\n\t" "mov (%5),%0\n\t" : "=a"(ret) : "a"(SYS_write), "D"(fd), "S"(buf), "d"(size), "r"(&ch)); #elif __i386__ asm("push %5\n\t" "int $0x80\n\t" "nop\n\t" "nop\n\t" "nop\n\t" "pop %5\n\t" "mov (%5),%0\n\t" : "=a"(ret) : "a"(SYS_write), "b"(fd), "c"(buf), "d"(size), "r"(&ch)); #else #error Unknown architecture #endif return ret; } int main(void) { test_assert('E' == my_write(STDOUT_FILENO, &ch, 1)); atomic_puts("XIT-SUCCESS"); return 0; }
2.546875
3
2024-11-18T18:09:55.943864+00:00
2023-01-15T04:07:57
a02334679d9f8e1eb217c4069b011b4a43023715
{ "blob_id": "a02334679d9f8e1eb217c4069b011b4a43023715", "branch_name": "refs/heads/master", "committer_date": "2023-01-15T04:07:57", "content_id": "1cd79587c64b10aa3f4223cb6e2564f937654086", "detected_licenses": [ "MIT" ], "directory_id": "a4f8c35f3d40fd1cd2b74b4e63bd27e6faaf9964", "extension": "c", "filename": "cstring.c", "fork_events_count": 3, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 243517898, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1085, "license": "MIT", "license_type": "permissive", "path": "/sim/prog12/postbl_prog/cstring.c", "provenance": "stackv2-0003.json.gz:322046", "repo_name": "yutongshen/RISC-V-Simulator", "revision_date": "2023-01-15T04:07:57", "revision_id": "03664f84d7cded1e1080180f237795e124aa25c5", "snapshot_id": "6c5b2c658141aefa71a54850c5d3fc80eb69cd1c", "src_encoding": "UTF-8", "star_events_count": 23, "url": "https://raw.githubusercontent.com/yutongshen/RISC-V-Simulator/03664f84d7cded1e1080180f237795e124aa25c5/sim/prog12/postbl_prog/cstring.c", "visit_date": "2023-01-19T10:29:25.221371" }
stackv2
#include <stddef.h> #include <stdint.h> #include <string.h> size_t strlen(const char *str) { int n = 0; while (*str++ && ++n) ; return n; } int strcmp(const char *a, const char *b) { char c1, c2; while ((c1 = *a++) == (c2 = *b++) && c1); return c1 != c2; } void *memset(void *ptr, int val, size_t len) { uint64_t *dword_ptr = ptr; uint64_t write_dword = (char) val; write_dword |= write_dword << 8; write_dword |= write_dword << 16; write_dword |= write_dword << 32; while (len >= 8) { *dword_ptr++ = write_dword; len -= 8; } char *byte_ptr = (char *) dword_ptr; while (len--) { *byte_ptr++ = val; } return ptr; } void *memcpy(void *ptr, const void *src, size_t len) { uint64_t *dword_ptr = ptr; const uint64_t *dword_src = src; while (len >= 8) { *dword_ptr++ = *dword_src++; len -= 8; } char *byte_ptr = (char *) dword_ptr; char *byte_src = (char *) dword_src; while (len--) { *byte_ptr++ = *byte_src++; } return ptr; }
2.921875
3
2024-11-18T18:09:56.044324+00:00
2021-02-09T02:50:50
91749db6db22f3256851c1613ee418852f766ed3
{ "blob_id": "91749db6db22f3256851c1613ee418852f766ed3", "branch_name": "refs/heads/master", "committer_date": "2021-02-09T02:50:50", "content_id": "3416cae0ff9135a5977c2b38815d3ddf33e05c0c", "detected_licenses": [ "MIT" ], "directory_id": "9d0301c19a8ff97589534ec3bfe8080c1036fc0c", "extension": "h", "filename": "system_stm32f4xx.h", "fork_events_count": 0, "gha_created_at": "2021-02-02T05:36:26", "gha_event_created_at": "2021-02-02T05:36:27", "gha_language": null, "gha_license_id": "MIT", "github_id": 335180460, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1093, "license": "MIT", "license_type": "permissive", "path": "/include/system_stm32f4xx.h", "provenance": "stackv2-0003.json.gz:322176", "repo_name": "forrestzhong/stm32f4-bare-metal", "revision_date": "2021-02-09T02:50:50", "revision_id": "ad9431282d14dc8e7490f4500fd6733b6e2d2171", "snapshot_id": "496abce231223f8970213d8eb478dd84abd6b67b", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/forrestzhong/stm32f4-bare-metal/ad9431282d14dc8e7490f4500fd6733b6e2d2171/include/system_stm32f4xx.h", "visit_date": "2023-03-06T22:57:53.192418" }
stackv2
#ifndef __SYSTEM_STM32F4XX_H #define __SYSTEM_STM32F4XX_H #ifdef __cplusplus extern "C" { #endif #include "stm32f4xx.h" #define HSI_VALUE ((uint32_t)16000000U) // Internal high speed oscillator #define HSE_VALUE ((uint32_t)8000000U) // External high speed oscillator #define LSI_VALUE ((uint32_t)32000U) // Internal low speed oscillator #define LSE_VALUE ((uint32_t)32768U) // External low speed oscillator /* Clock PLLs for 407 chip */ #if defined (STM32F407xx) || defined (STM32F429xx) // Main PLL = N * (source_clock / M) / P // HSE = 8 Mhz // fCLK = N * (8Mhz / M) / P #define PLL_M 8 #define PLL_Q 7 #define PLL_P 2 #endif /* stm32f407 runs at 168Mhz max */ #if defined (STM32F407xx) #define PLL_N 336 #endif /* stm32f429 runs at 180Mhz max */ #if defined (STM32F429xx) #define PLL_N 360 #endif void __init_data(void); void __Reset_Handler(void); void SystemInit(void); void set_sysclk_to_168(void); /* bring main */ extern int main(void); #ifdef __cplusplus } #endif #endif /*__SYSTEM_STM32F4XX_H */
2.140625
2
2024-11-18T18:09:56.367980+00:00
2019-06-15T11:02:49
176de257b509339e761f4cf915c1e19d85e9fd52
{ "blob_id": "176de257b509339e761f4cf915c1e19d85e9fd52", "branch_name": "refs/heads/master", "committer_date": "2019-06-15T11:36:58", "content_id": "8a1d3cee6d84b16f91ece04db0ebe79980046583", "detected_licenses": [ "MIT" ], "directory_id": "c8390b31f98d53e4b1b95b554d3816b3fd7cb5b6", "extension": "h", "filename": "paging.h", "fork_events_count": 1, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 137112374, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2962, "license": "MIT", "license_type": "permissive", "path": "/vivitsa/src/mm/paging/paging.h", "provenance": "stackv2-0003.json.gz:322304", "repo_name": "ragu-manjegowda/vivitsa", "revision_date": "2019-06-15T11:02:49", "revision_id": "1bc8c03d66b24ee12af33266ac86d0b29c9b2e77", "snapshot_id": "a228cb952d2429c673544f4b6a0b1900750e96e8", "src_encoding": "UTF-8", "star_events_count": 6, "url": "https://raw.githubusercontent.com/ragu-manjegowda/vivitsa/1bc8c03d66b24ee12af33266ac86d0b29c9b2e77/vivitsa/src/mm/paging/paging.h", "visit_date": "2021-07-16T00:23:35.918206" }
stackv2
#ifndef INCLUDE_PAGING_H #define INCLUDE_PAGING_H #pragma once #include <types.h> typedef struct page { /* Page is present in memory if set */ uint32_t present : 1; /* Read-only if clear, readwrite if set */ uint32_t rw : 1; /* Supervisor level only if clear */ uint32_t user : 1; /* Page been accessed since last refresh if set */ uint32_t accessed : 1; /* Page been written to since last refresh if set */ uint32_t dirty : 1; /* Amalgamation of unused and reserved bits */ uint32_t unused : 7; /* Frame address (shifted right 12 bits). Since the frames are aligned at 4kb * least 12 bits are always zero. */ uint32_t frame : 20; } page_t; typedef struct page_table { page_t pages[1024]; } page_table_t; typedef struct page_directory { /* Array of pointers to pagetables. */ page_table_t *tables[1024]; /* * Array of pointers to the pagetables above, but gives their *physical* * location, for loading into the CR3 register. */ uint32_t tablesPhysical[1024]; /* Required for cloning page direcotry */ uint32_t physicalAddr; } page_directory_t; /** init_paging: * Sets up the environment, page directories etc and enables paging. * * @param kernelPhysicalEnd Physical address of location where loaded kernel * ends */ void init_paging(uint32_t kernelPhysicalEnd); /** switch_page_directory: * Causes the specified page directory to be loaded into the CR3 register. * * @param new Address of the new page directory to be switched to. */ void switch_page_directory(page_directory_t *new); /** get_page: * Retrieves a pointer to the page required. If make == 1, if the page-table in * which this page should reside isn't created, create it! * * @param address Physical address is for which the virtual page is required * @param make Create page table if not created already. * @param dir Pointer to the page directory */ page_t *get_page(uint32_t address, uint8_t make, page_directory_t *dir); /** alloc_frame: * Marks that the frame is allocated based on the index calculated by page * address. Also sets the page attributes in page table * * @param page Pointer to page address * @param isKernel If set, marks page accesible only in kernel mode * @param isWriteable If not set, markes page as read only */ void alloc_frame(page_t *page, uint32_t isKernel, uint32_t isWriteable); /** free_frame: * Marks the current page frame as not present and removes it from the list of * frames that exist * * @param page Pointer to page address */ void free_frame(page_t *page); /** clone_directory: * Makes copy of current page directory, only non kernel pages are copied! * Kernel pages are linked as it is. * * @param src Pointer to source page directory * @return Pointer to cloned oage directory */ page_directory_t *clone_directory(page_directory_t *src); #endif /* INCLUDE_PAGING_H */
2.65625
3
2024-11-18T18:09:56.426046+00:00
2020-02-19T02:47:53
93ea8eb4118155898a8d8ec1f32a5fcc4acf1bae
{ "blob_id": "93ea8eb4118155898a8d8ec1f32a5fcc4acf1bae", "branch_name": "refs/heads/master", "committer_date": "2020-02-19T02:47:53", "content_id": "0550f3eea49fe23728c4ef31566a3664d99ca6d2", "detected_licenses": [ "MIT" ], "directory_id": "58aa2455286cd4eb4147c5b0c4a9cfc8993f305f", "extension": "c", "filename": "01_writes3.c", "fork_events_count": 0, "gha_created_at": "2020-02-19T02:46:32", "gha_event_created_at": "2020-02-19T02:46:32", "gha_language": null, "gha_license_id": "NOASSERTION", "github_id": 241517292, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 347, "license": "MIT", "license_type": "permissive", "path": "/vcc/Docs/Tutorial/c/01_writes3.c", "provenance": "stackv2-0003.json.gz:322432", "repo_name": "nchong-at-aws/vcc", "revision_date": "2020-02-19T02:47:53", "revision_id": "fd7030f8f9c6d1a2842032464976178cad8b7e34", "snapshot_id": "0d3e82947739ed17e61dbd2d5a62e5f5ded2774c", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/nchong-at-aws/vcc/fd7030f8f9c6d1a2842032464976178cad8b7e34/vcc/Docs/Tutorial/c/01_writes3.c", "visit_date": "2021-01-06T23:48:32.719366" }
stackv2
#include <vcc.h> #define writable(p) 1 // TODO /*{beg}*/ void boundedIncr(int *p) _(writes p) { _(assume writable(p)) // from writes clause _(assert \thread_local(p)) if (*p < 100) { _(assert writable(p)) (*p)++; } _(assert \old(*p) < 100 ==> *p == \old(*p) + 1) // ensures } /*` Verification of boundedIncr succeeded. `*/
2.140625
2
2024-11-18T18:09:56.520829+00:00
2019-06-19T18:13:44
ec9409dbe01225a4641e54887afc01a80d46e989
{ "blob_id": "ec9409dbe01225a4641e54887afc01a80d46e989", "branch_name": "refs/heads/master", "committer_date": "2019-06-19T23:03:30", "content_id": "d64ed13a75b47b48d1d7b550d6c8ede0a38aeba6", "detected_licenses": [ "BSD-3-Clause" ], "directory_id": "98c49475f1093066d8f4aab4a45b11d8a835d727", "extension": "c", "filename": "cmd_update.c", "fork_events_count": 0, "gha_created_at": "2019-06-24T11:41:08", "gha_event_created_at": "2019-06-24T11:41:09", "gha_language": null, "gha_license_id": "NOASSERTION", "github_id": 193494168, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 6637, "license": "BSD-3-Clause", "license_type": "permissive", "path": "/futility/cmd_update.c", "provenance": "stackv2-0003.json.gz:322562", "repo_name": "9elements/vboot", "revision_date": "2019-06-19T18:13:44", "revision_id": "b021a9619722a397de9910bd0422b2e7c6ebb7f0", "snapshot_id": "0a05bf94c6c50ef959933590df52f1f74b0efbba", "src_encoding": "UTF-8", "star_events_count": 2, "url": "https://raw.githubusercontent.com/9elements/vboot/b021a9619722a397de9910bd0422b2e7c6ebb7f0/futility/cmd_update.c", "visit_date": "2020-06-09T19:35:33.947960" }
stackv2
/* * Copyright 2018 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * * The command line tool to invoke firmware updater. */ #include <assert.h> #include <stdio.h> #include <getopt.h> #include "futility.h" #include "updater.h" #include "utility.h" enum { OPT_DUMMY = 0x100, OPT_CCD, OPT_EMULATE, OPT_FACTORY, OPT_FAST, OPT_FORCE, OPT_HOST_ONLY, OPT_MANIFEST, OPT_MODEL, OPT_OUTPUT_DIR, OPT_PD_IMAGE, OPT_QUIRKS, OPT_QUIRKS_LIST, OPT_REPACK, OPT_SIGNATURE, OPT_SYS_PROPS, OPT_UNPACK, OPT_WRITE_PROTECTION, }; /* Command line options */ static struct option const long_opts[] = { /* name has_arg *flag val */ {"help", 0, NULL, 'h'}, {"debug", 0, NULL, 'd'}, {"verbose", 0, NULL, 'v'}, {"image", 1, NULL, 'i'}, {"ec_image", 1, NULL, 'e'}, {"try", 0, NULL, 't'}, {"archive", 1, NULL, 'a'}, {"programmer", 1, NULL, 'p'}, {"mode", 1, NULL, 'm'}, {"ccd", 0, NULL, OPT_CCD}, {"emulate", 1, NULL, OPT_EMULATE}, {"factory", 0, NULL, OPT_FACTORY}, {"fast", 0, NULL, OPT_FAST}, {"force", 0, NULL, OPT_FORCE}, {"host_only", 0, NULL, OPT_HOST_ONLY}, {"list-quirks", 0, NULL, OPT_QUIRKS_LIST}, {"manifest", 0, NULL, OPT_MANIFEST}, {"model", 1, NULL, OPT_MODEL}, {"output_dir", 1, NULL, OPT_OUTPUT_DIR}, {"pd_image", 1, NULL, OPT_PD_IMAGE}, {"quirks", 1, NULL, OPT_QUIRKS}, {"repack", 1, NULL, OPT_REPACK}, {"signature_id", 1, NULL, OPT_SIGNATURE}, {"sys_props", 1, NULL, OPT_SYS_PROPS}, {"unpack", 1, NULL, OPT_UNPACK}, {"wp", 1, NULL, OPT_WRITE_PROTECTION}, /* TODO(hungte) Remove following deprecated options. */ {"noupdate_ec", 0, NULL, OPT_HOST_ONLY}, {"noupdate_pd", 0, NULL, OPT_HOST_ONLY}, {"nocheck_keys", 0, NULL, OPT_FORCE}, {"update_main", 0, NULL, OPT_DUMMY}, {"update_ec", 0, NULL, OPT_DUMMY}, {"update_pd", 0, NULL, OPT_DUMMY}, {"check_keys", 0, NULL, OPT_DUMMY}, {NULL, 0, NULL, 0}, }; static const char * const short_opts = "hdvi:e:ta:m:p:"; static void print_help(int argc, char *argv[]) { printf("\n" "Usage: " MYNAME " %s [OPTIONS]\n" "\n" "-i, --image=FILE \tAP (host) firmware image (image.bin)\n" "-e, --ec_image=FILE \tEC firmware image (i.e, ec.bin)\n" " --pd_image=FILE \tPD firmware image (i.e, pd.bin)\n" "-t, --try \tTry A/B update on reboot if possible\n" "-a, --archive=PATH \tRead resources from archive\n" " --manifest \tPrint out a JSON manifest and exit\n" " --repack=DIR \tUpdates archive from DIR\n" " --unpack=DIR \tExtracts archive to DIR\n" "-p, --programmer=PRG\tChange AP (host) flashrom programmer\n" " --fast \tReduce read cycles and do not verify\n" " --quirks=LIST \tSpecify the quirks to apply\n" " --list-quirks \tPrint all available quirks\n" "\n" "Legacy and compatibility options:\n" "-m, --mode=MODE \tRun updater in given mode\n" " --factory \tAlias for --mode=factory\n" " --force \tForce update (skip checking contents)\n" " --output_dir=DIR\tSpecify the target for --mode=output\n" "\n" "Debugging and testing options:\n" " --wp=1|0 \tSpecify write protection status\n" " --host_only \tUpdate only AP (host) firmware\n" " --emulate=FILE \tEmulate system firmware using file\n" " --model=MODEL \tOverride system model for images\n" " --ccd \tDo fast,force,wp=0,p=raiden_debug_spi\n" " --signature_id=S\tOverride signature ID for key files\n" " --sys_props=LIST\tList of system properties to override\n" "-d, --debug \tPrint debugging messages\n" "-v, --verbose \tPrint verbose messages\n" "", argv[0]); } static int do_update(int argc, char *argv[]) { struct updater_config *cfg; struct updater_config_arguments args = {0}; int i, errorcnt = 0, do_update = 1; cfg = updater_new_config(); assert(cfg); opterr = 0; while ((i = getopt_long(argc, argv, short_opts, long_opts, 0)) != -1) { switch (i) { case 'h': print_help(argc, argv); return !!errorcnt; case 'd': debugging_enabled = 1; args.verbosity++; break; case 'v': args.verbosity++; break; case 'i': args.image = optarg; break; case 'e': args.ec_image = optarg; break; case 't': args.try_update = 1; break; case 'a': args.archive = optarg; break; case 'm': args.mode = optarg; break; case 'p': args.programmer = optarg; break; case OPT_PD_IMAGE: args.pd_image = optarg; break; case OPT_REPACK: args.repack = optarg; break; case OPT_UNPACK: args.unpack = optarg; break; case OPT_QUIRKS: args.quirks = optarg; break; case OPT_QUIRKS_LIST: updater_list_config_quirks(cfg); return 0; case OPT_OUTPUT_DIR: args.output_dir = optarg; break; case OPT_MODEL: args.model = optarg; break; case OPT_SIGNATURE: args.signature_id = optarg; break; case OPT_WRITE_PROTECTION: args.write_protection = optarg; break; case OPT_EMULATE: args.emulation = optarg; break; case OPT_SYS_PROPS: args.sys_props = optarg; break; case OPT_MANIFEST: args.do_manifest = 1; break; case OPT_FACTORY: args.is_factory = 1; break; case OPT_HOST_ONLY: args.host_only = 1; break; case OPT_FORCE: args.force_update = 1; break; case OPT_FAST: args.fast_update = 1; break; case OPT_CCD: args.fast_update = 1; args.force_update = 1; args.write_protection = 0; args.programmer = "raiden_debug_spi"; break; case OPT_DUMMY: break; case '?': errorcnt++; if (optopt) ERROR("Unrecognized option: -%c\n", optopt); else if (argv[optind - 1]) ERROR("Unrecognized option (possibly '%s')\n", argv[optind - 1]); else ERROR("Unrecognized option.\n"); break; default: errorcnt++; ERROR("Failed parsing options.\n"); } } if (optind < argc) { errorcnt++; ERROR("Unexpected arguments.\n"); } if (!errorcnt) errorcnt += updater_setup_config(cfg, &args, &do_update); if (!errorcnt && do_update) { int r; STATUS("Starting firmware updater.\n"); r = update_firmware(cfg); if (r != UPDATE_ERR_DONE) { r = Min(r, UPDATE_ERR_UNKNOWN); ERROR("%s\n", updater_error_messages[r]); errorcnt++; } /* Use stdout for the final result. */ printf(">> %s: Firmware updater %s.\n", errorcnt ? "FAILED": "DONE", errorcnt ? "aborted" : "exits successfully"); } updater_delete_config(cfg); return !!errorcnt; } DECLARE_FUTIL_COMMAND(update, do_update, VBOOT_VERSION_ALL, "Update system firmware");
2.03125
2
2024-11-18T18:09:56.579421+00:00
2020-12-04T10:06:15
bf51c63ebf417b4c6b35edbcdc1a0553cd95823d
{ "blob_id": "bf51c63ebf417b4c6b35edbcdc1a0553cd95823d", "branch_name": "refs/heads/master", "committer_date": "2020-12-04T10:06:15", "content_id": "367094be0511241162cf88a374ecb32a710f9674", "detected_licenses": [ "MIT" ], "directory_id": "b8cec19d1b6dc9862a5ab3d960fb3792805182e3", "extension": "c", "filename": "problem02.c", "fork_events_count": 0, "gha_created_at": "2020-04-13T05:05:30", "gha_event_created_at": "2020-04-28T09:41:12", "gha_language": "HTML", "gha_license_id": "MIT", "github_id": 255235984, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 365, "license": "MIT", "license_type": "permissive", "path": "/CS-282_Unix-Systems-Programming_2019-Spring/lab07/src/problem02.c", "provenance": "stackv2-0003.json.gz:322691", "repo_name": "CraftingGamerTom/wsu-computer-science", "revision_date": "2020-12-04T10:06:15", "revision_id": "aa40fc95a84ac95535284048f6f572def1375f7d", "snapshot_id": "28d1d649949f367db8cb3e19147f9312ba4a4a1a", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/CraftingGamerTom/wsu-computer-science/aa40fc95a84ac95535284048f6f572def1375f7d/CS-282_Unix-Systems-Programming_2019-Spring/lab07/src/problem02.c", "visit_date": "2023-01-20T19:59:58.099211" }
stackv2
/* * problem03.c * * Created on: Feb 5, 2019 * Author: tcrokicki * Description: [ADD DESCRIPTON] */ #include<stdio.h> #include "myflush.h" void execute_problem02() { char str[50], *p; int length = 0; printf("Enter a string: \n"); gets(str); p = str; while (*p != '\0') { length++; p++; } printf("Length of String is: %d \n", length); }
3.0625
3
2024-11-18T18:09:56.658540+00:00
2013-04-17T18:42:40
3f9f9b5f64cb278a410c1bc9e0cc6968fb9366f5
{ "blob_id": "3f9f9b5f64cb278a410c1bc9e0cc6968fb9366f5", "branch_name": "refs/heads/master", "committer_date": "2013-04-17T18:42:40", "content_id": "6495584da74ecab384bc19725b7eedc6038f083c", "detected_licenses": [ "MIT" ], "directory_id": "bb108c3ea7d235e6fee0575181b5988e6b6a64ef", "extension": "c", "filename": "aerofgt.c", "fork_events_count": 8, "gha_created_at": "2012-03-23T04:23:01", "gha_event_created_at": "2013-04-17T18:42:41", "gha_language": "C", "gha_license_id": null, "github_id": 3805274, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 123228, "license": "MIT", "license_type": "permissive", "path": "/mame/src/mame/drivers/aerofgt.c", "provenance": "stackv2-0003.json.gz:322821", "repo_name": "clobber/MAME-OS-X", "revision_date": "2013-04-17T18:42:40", "revision_id": "ca11d0e946636bda042b6db55c82113e5722fc08", "snapshot_id": "3c5e6058b2814754176f3c6dcf1b2963ca804fc3", "src_encoding": "UTF-8", "star_events_count": 15, "url": "https://raw.githubusercontent.com/clobber/MAME-OS-X/ca11d0e946636bda042b6db55c82113e5722fc08/mame/src/mame/drivers/aerofgt.c", "visit_date": "2021-01-20T05:31:15.086981" }
stackv2
/*************************************************************************** Various Video System Co. games using the C7-01 GGA, VS8803, VS8904, VS8905 video chips. C7-01 GGA is used in a lot of games, some of them without sprites. So it either controls tilemaps, or the video signal, or both. I think 8904/8905 handle sprites, don't know about 8803. tail2nos doesn't have the 8904/8905, and indeed it has a different sprite system. Driver by Nicola Salmoria Notes: - Sprite zoom is probably not 100% accurate. In pspikes, the zooming text during attract mode is horrible. pspikes/turbofrc/aerofgtb write to two addresses which look like control registers for a video generator. Maybe they control the display size/position. aerofgt is different, it writes to consecutive memory addresses and the values it writes don't seem to be related to these ones. 00 01 02 03 04 05 08 09 0a 0b 0c 0d ------------------------------------ pspikes 352x240? 57 63 69 71 1f 00 77 79 7b 7f 1f 00 karatblz 352x240 57 63 69 71 1f 00 77 79 7b 7f 1f 00 turbofrc 352x240 57 63 69 71 1f 00 77 79 7b 7f 1f 00 spinlbrk 352x240 57 68 6f 75 ff 01 77 78 7b 7f ff 00 aerofgtb 320x224 4f 5d 63 71 1f 00 6f 70 72 7c 1f 02 tail2nos 320x240 4f 5e 64 71 1f 09 7a 7c 7e 7f 1f 02 f1gp 320x240 4f 5e 64 71 1f 09 7a 7c 7e 7f 1f 02 welltris 352x240 57 63 69 71 1f 00 7a 7b 7e 7f 1f 00 games with 8x4 tiles: pipedrm 352x240 57 63 69 71 1f 00 7a 7b 7e 7f 1f 00 * register 0b also briefly toggled to ff hatris 352x240 57 63 69 71 1f 00 7a 7b 7e 7f 1f 00 * register 0b also briefly toggled to ff idolmj 352x240 57 63 69 71 1f 00 7a 7b 7e 7f 1f 00 mjnatsu 352x240 57 63 69 71 1f 00 7a 7b 7e 7f 1f 00 * register 0b also briefly toggled to ff mfunclub 352x240 57 63 69 71 1f 00 7a 7b 7e 7f 1f 00 * register 0b also briefly toggled to ff daiyogen 352x240 57 63 69 71 1f 00 7a 7b 7e 7f 1f 00 * register 0b also briefly toggled to ff nmsengen 352x240 57 63 69 71 1f 00 7a 7b 7e 7f 1f 00 * register 0b also briefly toggled to ff fromance 352x240 57 63 69 71 1f 00 7a 7b 7e 7f 1f 00 * register 0b also briefly toggled to ff register 00 could be screen width / 4 (hblank start?) register 08 could be screen height / 2 (vblank start?) 2007.08.25: Small note regarding DipSwitches. Locations and values have been verified for: - svolly91 (PCB Infos from the dumper), - aerofgt (manual), - karatblz (US manual), - spinlbrk (US manual), - turbofrc (US manual) Verification still needed for the other PCBs. ***************************************************************************/ #include "emu.h" #include "cpu/m68000/m68000.h" #include "cpu/z80/z80.h" #include "sound/2610intf.h" #include "sound/3812intf.h" #include "sound/okim6295.h" #include "includes/aerofgt.h" static WRITE16_HANDLER( sound_command_w ) { aerofgt_state *state = space->machine().driver_data<aerofgt_state>(); if (ACCESSING_BITS_0_7) { state->m_pending_command = 1; soundlatch_w(space, offset, data & 0xff); device_set_input_line(state->m_audiocpu, INPUT_LINE_NMI, PULSE_LINE); } } static WRITE16_HANDLER( turbofrc_sound_command_w ) { aerofgt_state *state = space->machine().driver_data<aerofgt_state>(); if (ACCESSING_BITS_8_15) { state->m_pending_command = 1; soundlatch_w(space, offset, (data >> 8) & 0xff); device_set_input_line(state->m_audiocpu, INPUT_LINE_NMI, PULSE_LINE); } } static WRITE16_HANDLER( aerfboot_soundlatch_w ) { aerofgt_state *state = space->machine().driver_data<aerofgt_state>(); if(ACCESSING_BITS_8_15) { soundlatch_w(space, 0, (data >> 8) & 0xff); device_set_input_line(state->m_audiocpu, INPUT_LINE_NMI, PULSE_LINE); } } static READ16_HANDLER( pending_command_r ) { aerofgt_state *state = space->machine().driver_data<aerofgt_state>(); return state->m_pending_command; } static WRITE8_HANDLER( pending_command_clear_w ) { aerofgt_state *state = space->machine().driver_data<aerofgt_state>(); state->m_pending_command = 0; } static WRITE8_HANDLER( aerofgt_sh_bankswitch_w ) { memory_set_bank(space->machine(), "bank1", data & 0x03); } static WRITE16_DEVICE_HANDLER( pspikesb_oki_banking_w ) { okim6295_device *oki = downcast<okim6295_device *>(device); oki->set_bank_base(0x40000 * (data & 3)); } /*TODO: sound banking. */ static WRITE16_DEVICE_HANDLER( aerfboo2_okim6295_banking_w ) { // if(ACCESSING_BITS_8_15) // { // okim6295_device *oki = downcast<okim6295_device *>(device); // oki->set_bank_base(0x40000 * ((data & 0xf00)>>8)); // } } static WRITE8_HANDLER( aerfboot_okim6295_banking_w ) { UINT8 *oki = space->machine().region("oki")->base(); /*bit 2 (0x4) setted too?*/ if (data & 0x4) memcpy(&oki[0x20000], &oki[((data & 0x3) * 0x20000) + 0x40000], 0x20000); } static ADDRESS_MAP_START( pspikes_map, AS_PROGRAM, 16 ) AM_RANGE(0x000000, 0x03ffff) AM_ROM AM_RANGE(0x100000, 0x10ffff) AM_RAM /* work RAM */ AM_RANGE(0x200000, 0x203fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram1, m_spriteram1_size) AM_RANGE(0xff8000, 0xff8fff) AM_RAM_WRITE(aerofgt_bg1videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg1videoram) AM_RANGE(0xffc000, 0xffc3ff) AM_WRITEONLY AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram3, m_spriteram3_size) AM_RANGE(0xffd000, 0xffdfff) AM_RAM AM_BASE_MEMBER(aerofgt_state, m_rasterram) /* bg1 scroll registers */ AM_RANGE(0xffe000, 0xffefff) AM_RAM_WRITE(paletteram16_xRRRRRGGGGGBBBBB_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0xfff000, 0xfff001) AM_READ_PORT("IN0") AM_WRITE(pspikes_palette_bank_w) AM_RANGE(0xfff002, 0xfff003) AM_READ_PORT("IN1") AM_WRITE(pspikes_gfxbank_w) AM_RANGE(0xfff004, 0xfff005) AM_READ_PORT("DSW") AM_WRITE(aerofgt_bg1scrolly_w) AM_RANGE(0xfff006, 0xfff007) AM_READWRITE(pending_command_r, sound_command_w) ADDRESS_MAP_END static ADDRESS_MAP_START( pspikesb_map, AS_PROGRAM, 16 ) AM_RANGE(0x000000, 0x03ffff) AM_ROM AM_RANGE(0x100000, 0x10ffff) AM_RAM /* work RAM */ AM_RANGE(0x200000, 0x203fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram1, m_spriteram1_size) AM_RANGE(0xc04000, 0xc04001) AM_WRITENOP AM_RANGE(0xff8000, 0xff8fff) AM_RAM_WRITE(aerofgt_bg1videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg1videoram) AM_RANGE(0xffc000, 0xffcbff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram3, m_spriteram3_size) AM_RANGE(0xffd200, 0xffd201) AM_WRITE(pspikesb_gfxbank_w) AM_RANGE(0xffd000, 0xffdfff) AM_RAM AM_BASE_MEMBER(aerofgt_state, m_rasterram) /* bg1 scroll registers */ AM_RANGE(0xffe000, 0xffefff) AM_RAM_WRITE(paletteram16_xRRRRRGGGGGBBBBB_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0xfff000, 0xfff001) AM_READ_PORT("IN0") AM_RANGE(0xfff002, 0xfff003) AM_READ_PORT("IN1") AM_RANGE(0xfff004, 0xfff005) AM_READ_PORT("DSW") AM_WRITE(aerofgt_bg1scrolly_w) AM_RANGE(0xfff006, 0xfff007) AM_DEVREADWRITE8_MODERN("oki", okim6295_device, read, write, 0x00ff) AM_RANGE(0xfff008, 0xfff009) AM_DEVWRITE("oki", pspikesb_oki_banking_w) ADDRESS_MAP_END static ADDRESS_MAP_START( spikes91_map, AS_PROGRAM, 16 ) AM_RANGE(0x000000, 0x03ffff) AM_ROM AM_RANGE(0x100000, 0x10ffff) AM_RAM /* work RAM */ AM_RANGE(0x200000, 0x203fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram1, m_spriteram1_size) AM_RANGE(0xc04000, 0xc04001) AM_WRITENOP AM_RANGE(0xff8000, 0xff8fff) AM_RAM_WRITE(aerofgt_bg1videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg1videoram) AM_RANGE(0xffa000, 0xffbfff) AM_RAM AM_BASE_MEMBER(aerofgt_state, m_tx_tilemap_ram) AM_RANGE(0xffc000, 0xffcfff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram3, m_spriteram3_size) //AM_RANGE(0xffd200, 0xffd201) AM_WRITE(pspikesb_gfxbank_w) AM_RANGE(0xffd000, 0xffdfff) AM_RAM AM_BASE_MEMBER(aerofgt_state, m_rasterram) /* bg1 scroll registers */ AM_RANGE(0xffe000, 0xffefff) AM_RAM_WRITE(paletteram16_xRRRRRGGGGGBBBBB_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0xfff000, 0xfff001) AM_READ_PORT("IN0") AM_RANGE(0xfff002, 0xfff003) AM_READ_PORT("IN1") AM_WRITE(pspikes_gfxbank_w) AM_RANGE(0xfff004, 0xfff005) AM_READ_PORT("DSW") AM_WRITE(aerofgt_bg1scrolly_w) AM_RANGE(0xfff006, 0xfff007) AM_NOP AM_RANGE(0xfff008, 0xfff009) AM_WRITE(spikes91_lookup_w) ADDRESS_MAP_END static ADDRESS_MAP_START( pspikesc_map, AS_PROGRAM, 16 ) AM_RANGE(0x000000, 0x03ffff) AM_ROM AM_RANGE(0x100000, 0x10ffff) AM_RAM /* work RAM */ AM_RANGE(0x200000, 0x203fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram1, m_spriteram1_size) AM_RANGE(0xff8000, 0xff8fff) AM_RAM_WRITE(aerofgt_bg1videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg1videoram) AM_RANGE(0xffc000, 0xffcbff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram3, m_spriteram3_size) AM_RANGE(0xffd000, 0xffdfff) AM_RAM AM_BASE_MEMBER(aerofgt_state, m_rasterram) /* bg1 scroll registers */ AM_RANGE(0xffe000, 0xffefff) AM_RAM_WRITE(paletteram16_xRRRRRGGGGGBBBBB_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0xfff000, 0xfff001) AM_READ_PORT("IN0") AM_WRITE(pspikes_palette_bank_w) AM_RANGE(0xfff002, 0xfff003) AM_READ_PORT("IN1") AM_WRITE(pspikes_gfxbank_w) AM_RANGE(0xfff004, 0xfff005) AM_READ_PORT("DSW") AM_RANGE(0xfff004, 0xfff005) AM_WRITE(aerofgt_bg1scrolly_w) AM_RANGE(0xfff006, 0xfff007) AM_DEVREADWRITE8_MODERN("oki", okim6295_device, read, write, 0x00ff) ADDRESS_MAP_END static ADDRESS_MAP_START( karatblz_map, AS_PROGRAM, 16 ) ADDRESS_MAP_GLOBAL_MASK(0xfffff) AM_RANGE(0x000000, 0x07ffff) AM_ROM AM_RANGE(0x080000, 0x081fff) AM_RAM_WRITE(aerofgt_bg1videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg1videoram) AM_RANGE(0x082000, 0x083fff) AM_RAM_WRITE(aerofgt_bg2videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg2videoram) AM_RANGE(0x0a0000, 0x0affff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram1, m_spriteram1_size) AM_RANGE(0x0b0000, 0x0bffff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram2, m_spriteram2_size) AM_RANGE(0x0c0000, 0x0cffff) AM_RAM /* work RAM */ AM_RANGE(0x0f8000, 0x0fbfff) AM_RAM /* work RAM */ AM_RANGE(0x0fc000, 0x0fc7ff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram3, m_spriteram3_size) AM_RANGE(0x0fe000, 0x0fe7ff) AM_RAM_WRITE(paletteram16_xRRRRRGGGGGBBBBB_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0x0ff000, 0x0ff001) AM_READ_PORT("IN0") AM_RANGE(0x0ff002, 0x0ff003) AM_READ_PORT("IN1") AM_WRITE(karatblz_gfxbank_w) AM_RANGE(0x0ff004, 0x0ff005) AM_READ_PORT("IN2") AM_RANGE(0x0ff006, 0x0ff007) AM_READ_PORT("IN3") AM_WRITE(sound_command_w) AM_RANGE(0x0ff008, 0x0ff009) AM_READ_PORT("DSW") AM_WRITE(aerofgt_bg1scrollx_w) AM_RANGE(0x0ff00a, 0x0ff00b) AM_READWRITE(pending_command_r, aerofgt_bg1scrolly_w) AM_RANGE(0x0ff00c, 0x0ff00d) AM_WRITE(aerofgt_bg2scrollx_w) AM_RANGE(0x0ff00e, 0x0ff00f) AM_WRITE(aerofgt_bg2scrolly_w) ADDRESS_MAP_END static ADDRESS_MAP_START( spinlbrk_map, AS_PROGRAM, 16 ) AM_RANGE(0x000000, 0x03ffff) AM_ROM AM_RANGE(0x080000, 0x080fff) AM_RAM_WRITE(aerofgt_bg1videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg1videoram) AM_RANGE(0x082000, 0x082fff) AM_RAM_WRITE(aerofgt_bg2videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg2videoram) AM_RANGE(0xff8000, 0xffbfff) AM_RAM /* work RAM */ AM_RANGE(0xffc000, 0xffc7ff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram3, m_spriteram3_size) AM_RANGE(0xffd000, 0xffd1ff) AM_RAM AM_BASE_MEMBER(aerofgt_state, m_rasterram) /* bg1 scroll registers */ AM_RANGE(0xffe000, 0xffe7ff) AM_RAM_WRITE(paletteram16_xRRRRRGGGGGBBBBB_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0xfff000, 0xfff001) AM_READ_PORT("IN0") AM_WRITE(spinlbrk_gfxbank_w) AM_RANGE(0xfff002, 0xfff003) AM_READ_PORT("IN1") AM_WRITE(aerofgt_bg2scrollx_w) AM_RANGE(0xfff004, 0xfff005) AM_READ_PORT("DSW") AM_RANGE(0xfff006, 0xfff007) AM_WRITE(sound_command_w) ADDRESS_MAP_END static ADDRESS_MAP_START( turbofrc_map, AS_PROGRAM, 16 ) ADDRESS_MAP_GLOBAL_MASK(0xfffff) AM_RANGE(0x000000, 0x0bffff) AM_ROM AM_RANGE(0x0c0000, 0x0cffff) AM_RAM /* work RAM */ AM_RANGE(0x0d0000, 0x0d1fff) AM_RAM_WRITE(aerofgt_bg1videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg1videoram) AM_RANGE(0x0d2000, 0x0d3fff) AM_RAM_WRITE(aerofgt_bg2videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg2videoram) AM_RANGE(0x0e0000, 0x0e3fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram1, m_spriteram1_size) AM_RANGE(0x0e4000, 0x0e7fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram2, m_spriteram2_size) AM_RANGE(0x0f8000, 0x0fbfff) AM_RAM /* work RAM */ AM_RANGE(0x0fc000, 0x0fc7ff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram3, m_spriteram3_size) AM_RANGE(0x0fd000, 0x0fdfff) AM_RAM AM_BASE_MEMBER(aerofgt_state, m_rasterram) /* bg1 scroll registers */ AM_RANGE(0x0fe000, 0x0fe7ff) AM_RAM_WRITE(paletteram16_xRRRRRGGGGGBBBBB_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0x0ff000, 0x0ff001) AM_READ_PORT("IN0") AM_RANGE(0x0ff002, 0x0ff003) AM_READ_PORT("IN1") AM_WRITE(aerofgt_bg1scrolly_w) AM_RANGE(0x0ff004, 0x0ff005) AM_READ_PORT("DSW") AM_WRITE(aerofgt_bg2scrollx_w) AM_RANGE(0x0ff006, 0x0ff007) AM_READWRITE(pending_command_r, aerofgt_bg2scrolly_w) AM_RANGE(0x0ff008, 0x0ff009) AM_READ_PORT("IN2") AM_RANGE(0x0ff008, 0x0ff00b) AM_WRITE(turbofrc_gfxbank_w) AM_RANGE(0x0ff00c, 0x0ff00d) AM_WRITENOP /* related to bg2 (written together with the scroll registers) */ AM_RANGE(0x0ff00e, 0x0ff00f) AM_WRITE(turbofrc_sound_command_w) ADDRESS_MAP_END static ADDRESS_MAP_START( aerofgtb_map, AS_PROGRAM, 16 ) AM_RANGE(0x000000, 0x07ffff) AM_ROM AM_RANGE(0x0c0000, 0x0cffff) AM_RAM /* work RAM */ AM_RANGE(0x0d0000, 0x0d1fff) AM_RAM_WRITE(aerofgt_bg1videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg1videoram) AM_RANGE(0x0d2000, 0x0d3fff) AM_RAM_WRITE(aerofgt_bg2videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg2videoram) AM_RANGE(0x0e0000, 0x0e3fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram1, m_spriteram1_size) AM_RANGE(0x0e4000, 0x0e7fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram2, m_spriteram2_size) AM_RANGE(0x0f8000, 0x0fbfff) AM_RAM /* work RAM */ AM_RANGE(0x0fc000, 0x0fc7ff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram3, m_spriteram3_size) AM_RANGE(0x0fd000, 0x0fd7ff) AM_RAM_WRITE(paletteram16_xRRRRRGGGGGBBBBB_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0x0fe000, 0x0fe001) AM_READ_PORT("IN0") AM_RANGE(0x0fe002, 0x0fe003) AM_READ_PORT("IN1") AM_WRITE(aerofgt_bg1scrolly_w) AM_RANGE(0x0fe004, 0x0fe005) AM_READ_PORT("DSW1") AM_WRITE(aerofgt_bg2scrollx_w) AM_RANGE(0x0fe006, 0x0fe007) AM_READWRITE(pending_command_r, aerofgt_bg2scrolly_w) AM_RANGE(0x0fe008, 0x0fe009) AM_READ_PORT("DSW2") AM_RANGE(0x0fe008, 0x0fe00b) AM_WRITE(turbofrc_gfxbank_w) AM_RANGE(0x0fe00e, 0x0fe00f) AM_WRITE(turbofrc_sound_command_w) AM_RANGE(0x0ff000, 0x0fffff) AM_RAM AM_BASE_MEMBER(aerofgt_state, m_rasterram) /* used only for the scroll registers */ ADDRESS_MAP_END static ADDRESS_MAP_START( aerofgt_map, AS_PROGRAM, 16 ) AM_RANGE(0x000000, 0x07ffff) AM_ROM AM_RANGE(0x1a0000, 0x1a07ff) AM_RAM_WRITE(paletteram16_xRRRRRGGGGGBBBBB_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0x1b0000, 0x1b07ff) AM_RAM AM_BASE_MEMBER(aerofgt_state, m_rasterram) /* used only for the scroll registers */ AM_RANGE(0x1b0800, 0x1b0801) AM_NOP /* ??? */ AM_RANGE(0x1b0ff0, 0x1b0fff) AM_RAM /* stack area during boot */ AM_RANGE(0x1b2000, 0x1b3fff) AM_RAM_WRITE(aerofgt_bg1videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg1videoram) AM_RANGE(0x1b4000, 0x1b5fff) AM_RAM_WRITE(aerofgt_bg2videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg2videoram) AM_RANGE(0x1c0000, 0x1c3fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram1, m_spriteram1_size) AM_RANGE(0x1c4000, 0x1c7fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram2, m_spriteram2_size) AM_RANGE(0x1d0000, 0x1d1fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram3, m_spriteram3_size) AM_RANGE(0xfef000, 0xffefff) AM_RAM /* work RAM */ AM_RANGE(0xffff80, 0xffff87) AM_WRITE(aerofgt_gfxbank_w) AM_RANGE(0xffff88, 0xffff89) AM_WRITE(aerofgt_bg1scrolly_w) /* + something else in the top byte */ AM_RANGE(0xffff90, 0xffff91) AM_WRITE(aerofgt_bg2scrolly_w) /* + something else in the top byte */ AM_RANGE(0xffffa0, 0xffffa1) AM_READ_PORT("P1") AM_RANGE(0xffffa2, 0xffffa3) AM_READ_PORT("P2") AM_RANGE(0xffffa4, 0xffffa5) AM_READ_PORT("SYSTEM") AM_RANGE(0xffffa6, 0xffffa7) AM_READ_PORT("DSW1") AM_RANGE(0xffffa8, 0xffffa9) AM_READ_PORT("DSW2") AM_RANGE(0xffffac, 0xffffad) AM_READ(pending_command_r) AM_WRITENOP /* ??? */ AM_RANGE(0xffffae, 0xffffaf) AM_READ_PORT("DSW3") AM_RANGE(0xffffc0, 0xffffc1) AM_WRITE(sound_command_w) ADDRESS_MAP_END static ADDRESS_MAP_START( aerfboot_map, AS_PROGRAM, 16 ) AM_RANGE(0x000000, 0x07ffff) AM_ROM AM_RANGE(0x0c0000, 0x0cffff) AM_RAM /* work RAM */ AM_RANGE(0x0d0000, 0x0d1fff) AM_RAM_WRITE(aerofgt_bg1videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg1videoram) AM_RANGE(0x0d2000, 0x0d3fff) AM_RAM_WRITE(aerofgt_bg2videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg2videoram) AM_RANGE(0x0e0000, 0x0e3fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram1, m_spriteram1_size) AM_RANGE(0x0e4000, 0x0e7fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram2, m_spriteram2_size) AM_RANGE(0x0f8000, 0x0fbfff) AM_RAM /* work RAM */ AM_RANGE(0x0fc000, 0x0fc7ff) AM_RAM //AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram3, m_spriteram3_size) AM_RANGE(0x0fd000, 0x0fd7ff) AM_RAM_WRITE(paletteram16_xRRRRRGGGGGBBBBB_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0x0fe000, 0x0fe001) AM_READ_PORT("IN0") AM_RANGE(0x0fe002, 0x0fe003) AM_READ_PORT("IN1") AM_RANGE(0x0fe004, 0x0fe005) AM_READ_PORT("DSW1") AM_RANGE(0x0fe008, 0x0fe009) AM_READ_PORT("DSW2") AM_RANGE(0x0fe002, 0x0fe003) AM_WRITE(aerofgt_bg1scrolly_w) AM_RANGE(0x0fe004, 0x0fe005) AM_WRITE(aerofgt_bg2scrollx_w) AM_RANGE(0x0fe006, 0x0fe007) AM_WRITE(aerofgt_bg2scrolly_w) AM_RANGE(0x0fe008, 0x0fe00b) AM_WRITE(turbofrc_gfxbank_w) AM_RANGE(0x0fe00e, 0x0fe00f) AM_WRITE(aerfboot_soundlatch_w) AM_RANGE(0x0fe010, 0x0fe011) AM_WRITENOP AM_RANGE(0x0fe012, 0x0fe013) AM_WRITENOP AM_RANGE(0x0fe400, 0x0fe401) AM_WRITENOP AM_RANGE(0x0fe402, 0x0fe403) AM_WRITENOP AM_RANGE(0x0ff000, 0x0fffff) AM_RAM AM_BASE_MEMBER(aerofgt_state, m_rasterram) /* used only for the scroll registers */ AM_RANGE(0x100000, 0x107fff) AM_WRITENOP AM_RANGE(0x108000, 0x10bfff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram3, m_spriteram3_size) AM_RANGE(0x10c000, 0x117fff) AM_WRITENOP ADDRESS_MAP_END static ADDRESS_MAP_START( aerfboo2_map, AS_PROGRAM, 16 ) AM_RANGE(0x000000, 0x07ffff) AM_ROM AM_RANGE(0x0c0000, 0x0cffff) AM_RAM /* work RAM */ AM_RANGE(0x0d0000, 0x0d1fff) AM_RAM_WRITE(aerofgt_bg1videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg1videoram) AM_RANGE(0x0d2000, 0x0d3fff) AM_RAM_WRITE(aerofgt_bg2videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg2videoram) AM_RANGE(0x0e0000, 0x0e3fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram1, m_spriteram1_size) AM_RANGE(0x0e4000, 0x0e7fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram2, m_spriteram2_size) AM_RANGE(0x0f8000, 0x0fbfff) AM_RAM /* work RAM */ AM_RANGE(0x0fc000, 0x0fc7ff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram3, m_spriteram3_size) AM_RANGE(0x0fd000, 0x0fd7ff) AM_RAM_WRITE(paletteram16_xRRRRRGGGGGBBBBB_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0x0fe000, 0x0fe001) AM_READ_PORT("IN0") AM_RANGE(0x0fe002, 0x0fe003) AM_READ_PORT("IN1") AM_RANGE(0x0fe004, 0x0fe005) AM_READ_PORT("DSW1") AM_RANGE(0x0fe008, 0x0fe009) AM_READ_PORT("DSW2") AM_RANGE(0x0fe002, 0x0fe003) AM_WRITE(aerofgt_bg1scrolly_w) AM_RANGE(0x0fe004, 0x0fe005) AM_WRITE(aerofgt_bg2scrollx_w) AM_RANGE(0x0fe006, 0x0fe007) AM_WRITE(aerofgt_bg2scrolly_w) AM_RANGE(0x0fe008, 0x0fe00b) AM_WRITE(turbofrc_gfxbank_w) AM_RANGE(0x0fe006, 0x0fe007) AM_DEVREAD8_MODERN("oki", okim6295_device, read, 0xff00) AM_RANGE(0x0fe00e, 0x0fe00f) AM_DEVWRITE8_MODERN("oki", okim6295_device, write, 0xff00) AM_RANGE(0x0fe01e, 0x0fe01f) AM_DEVWRITE("oki", aerfboo2_okim6295_banking_w) // AM_RANGE(0x0fe010, 0x0fe011) AM_WRITENOP // AM_RANGE(0x0fe012, 0x0fe013) AM_WRITE(aerfboot_soundlatch_w) AM_RANGE(0x0fe400, 0x0fe401) AM_WRITENOP // data for a crtc? AM_RANGE(0x0fe402, 0x0fe403) AM_WRITENOP // address for a crtc? AM_RANGE(0x0ff000, 0x0fffff) AM_RAM AM_BASE_MEMBER(aerofgt_state, m_rasterram) /* used only for the scroll registers */ ADDRESS_MAP_END static ADDRESS_MAP_START( wbbc97_map, AS_PROGRAM, 16 ) AM_RANGE(0x000000, 0x3fffff) AM_ROM AM_RANGE(0x500000, 0x50ffff) AM_RAM /* work RAM */ AM_RANGE(0x600000, 0x605fff) AM_RAM AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram1, m_spriteram1_size) AM_RANGE(0xa00000, 0xa3ffff) AM_RAM AM_BASE_MEMBER(aerofgt_state, m_bitmapram) AM_RANGE(0xff8000, 0xff8fff) AM_RAM_WRITE(aerofgt_bg1videoram_w) AM_BASE_MEMBER(aerofgt_state, m_bg1videoram) AM_RANGE(0xffc000, 0xffc3ff) AM_WRITEONLY AM_BASE_SIZE_MEMBER(aerofgt_state, m_spriteram3, m_spriteram3_size) AM_RANGE(0xffd000, 0xffdfff) AM_RAM AM_BASE_MEMBER(aerofgt_state, m_rasterram) /* bg1 scroll registers */ AM_RANGE(0xffe000, 0xffefff) AM_RAM_WRITE(paletteram16_xRRRRRGGGGGBBBBB_word_w) AM_BASE_GENERIC(paletteram) AM_RANGE(0xfff000, 0xfff001) AM_READ_PORT("IN0") AM_WRITE(pspikes_palette_bank_w) AM_RANGE(0xfff002, 0xfff003) AM_READ_PORT("IN1") AM_WRITE(pspikes_gfxbank_w) AM_RANGE(0xfff004, 0xfff005) AM_READ_PORT("DSW") AM_WRITE(aerofgt_bg1scrolly_w) AM_RANGE(0xfff006, 0xfff007) AM_READNOP AM_WRITE(sound_command_w) AM_RANGE(0xfff00e, 0xfff00f) AM_WRITE(wbbc97_bitmap_enable_w) ADDRESS_MAP_END static ADDRESS_MAP_START( sound_map, AS_PROGRAM, 8 ) AM_RANGE(0x0000, 0x77ff) AM_ROM AM_RANGE(0x7800, 0x7fff) AM_RAM AM_RANGE(0x8000, 0xffff) AM_ROMBANK("bank1") ADDRESS_MAP_END static ADDRESS_MAP_START( turbofrc_sound_portmap, AS_IO, 8 ) ADDRESS_MAP_GLOBAL_MASK(0xff) AM_RANGE(0x00, 0x00) AM_WRITE(aerofgt_sh_bankswitch_w) AM_RANGE(0x14, 0x14) AM_READWRITE(soundlatch_r, pending_command_clear_w) AM_RANGE(0x18, 0x1b) AM_DEVREADWRITE("ymsnd", ym2610_r, ym2610_w) ADDRESS_MAP_END static ADDRESS_MAP_START( aerofgt_sound_portmap, AS_IO, 8 ) ADDRESS_MAP_GLOBAL_MASK(0xff) AM_RANGE(0x00, 0x03) AM_DEVREADWRITE("ymsnd", ym2610_r, ym2610_w) AM_RANGE(0x04, 0x04) AM_WRITE(aerofgt_sh_bankswitch_w) AM_RANGE(0x08, 0x08) AM_WRITE(pending_command_clear_w) AM_RANGE(0x0c, 0x0c) AM_READ(soundlatch_r) ADDRESS_MAP_END static ADDRESS_MAP_START( aerfboot_sound_map, AS_PROGRAM, 8 ) AM_RANGE(0x0000, 0x7fff) AM_ROM AM_RANGE(0x8000, 0x87ff) AM_RAM AM_RANGE(0x9000, 0x9000) AM_WRITE(aerfboot_okim6295_banking_w) AM_RANGE(0x9800, 0x9800) AM_DEVREADWRITE_MODERN("oki", okim6295_device, read, write) AM_RANGE(0xa000, 0xa000) AM_READ(soundlatch_r) ADDRESS_MAP_END static ADDRESS_MAP_START( wbbc97_sound_map, AS_PROGRAM, 8 ) AM_RANGE(0x0000, 0xefff) AM_ROM AM_RANGE(0xf000, 0xf7ff) AM_RAM AM_RANGE(0xf800, 0xf800) AM_DEVREADWRITE_MODERN("oki", okim6295_device, read, write) AM_RANGE(0xf810, 0xf811) AM_DEVWRITE("ymsnd", ym3812_w) AM_RANGE(0xfc00, 0xfc00) AM_NOP AM_RANGE(0xfc20, 0xfc20) AM_READ(soundlatch_r) ADDRESS_MAP_END static INPUT_PORTS_START( pspikes ) PORT_START("IN0") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_START1 ) PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START2 ) PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_START("IN1") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_START("DSW") PORT_DIPNAME( 0x0003, 0x0003, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SW1:1,2") PORT_DIPSETTING( 0x0001, DEF_STR( 3C_1C ) ) PORT_DIPSETTING( 0x0002, DEF_STR( 2C_1C ) ) PORT_DIPSETTING( 0x0003, DEF_STR( 1C_1C ) ) PORT_DIPSETTING( 0x0000, DEF_STR( 1C_2C ) ) PORT_DIPNAME( 0x000c, 0x000c, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("SW1:3,4") PORT_DIPSETTING( 0x0004, DEF_STR( 3C_1C ) ) PORT_DIPSETTING( 0x0008, DEF_STR( 2C_1C ) ) PORT_DIPSETTING( 0x000c, DEF_STR( 1C_1C ) ) PORT_DIPSETTING( 0x0000, DEF_STR( 1C_2C ) ) PORT_DIPUNUSED_DIPLOC( 0x0010, 0x0010, "SW1:5" ) /* Listed as "Unused" */ PORT_DIPUNUSED_DIPLOC( 0x0020, 0x0020, "SW1:6" ) /* Listed as "Unused" */ PORT_DIPNAME( 0x0040, 0x0000, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW1:7") PORT_DIPSETTING( 0x0040, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) PORT_DIPNAME( 0x0080, 0x0080, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SW1:8") PORT_DIPSETTING( 0x0080, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) /* According to Super Volley '91 PCB Infos, here DSW2 starts */ PORT_SERVICE_DIPLOC( 0x0100, IP_ACTIVE_LOW, "SW2:1" ) PORT_DIPNAME( 0x0600, 0x0600, "1 Player Starting Score" ) PORT_DIPLOCATION("SW2:2,3") PORT_DIPSETTING( 0x0600, "12-12" ) PORT_DIPSETTING( 0x0400, "11-11" ) PORT_DIPSETTING( 0x0200, "11-12" ) PORT_DIPSETTING( 0x0000, "10-12" ) PORT_DIPNAME( 0x1800, 0x1800, "2 Players Starting Score" ) PORT_DIPLOCATION("SW2:4,5") PORT_DIPSETTING( 0x1800, "9-9" ) PORT_DIPSETTING( 0x1000, "7-7" ) PORT_DIPSETTING( 0x0800, "5-5" ) PORT_DIPSETTING( 0x0000, "0-0" ) PORT_DIPNAME( 0x2000, 0x2000, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW2:6") PORT_DIPSETTING( 0x2000, DEF_STR( Normal ) ) PORT_DIPSETTING( 0x0000, DEF_STR( Hard ) ) /* When the players continue, only half of the time in SW2:7 is added */ PORT_DIPNAME( 0x4000, 0x4000, "2 Players Time Per Credit" ) PORT_DIPLOCATION("SW2:7") PORT_DIPSETTING( 0x4000, "3 min" ) PORT_DIPSETTING( 0x0000, "2 min" ) /* The next one is reported as 'Must be off' in Super Volley '91 PCB Infos */ PORT_DIPNAME( 0x8000, 0x8000, "Debug" ) PORT_DIPLOCATION("SW2:8") PORT_DIPSETTING( 0x8000, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) INPUT_PORTS_END static INPUT_PORTS_START( pspikesb ) PORT_START("IN0") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_START1 ) PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START2 ) PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_START("IN1") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_START("DSW") /* Dips bank 1 */ PORT_DIPNAME( 0x0003, 0x0003, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SW1:1,2") PORT_DIPSETTING( 0x0001, DEF_STR( 3C_1C ) ) PORT_DIPSETTING( 0x0002, DEF_STR( 2C_1C ) ) PORT_DIPSETTING( 0x0003, DEF_STR( 1C_1C ) ) PORT_DIPSETTING( 0x0000, DEF_STR( 1C_2C ) ) PORT_DIPNAME( 0x000c, 0x000c, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("SW1:3,4") PORT_DIPSETTING( 0x0004, DEF_STR( 3C_1C ) ) PORT_DIPSETTING( 0x0008, DEF_STR( 2C_1C ) ) PORT_DIPSETTING( 0x000c, DEF_STR( 1C_1C ) ) PORT_DIPSETTING( 0x0000, DEF_STR( 1C_2C ) ) PORT_DIPUNUSED_DIPLOC( 0x0010, 0x0010, "SW1:5" ) PORT_DIPUNUSED_DIPLOC( 0x0020, 0x0020, "SW1:6" ) PORT_DIPNAME( 0x0040, 0x0000, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW1:7") PORT_DIPSETTING( 0x0040, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) PORT_DIPUNUSED_DIPLOC( 0x0080, 0x0080, "SW1:8" ) /* Dips bank 2 */ PORT_DIPUNUSED_DIPLOC( 0x0100, 0x0100, "SW2:1" ) PORT_DIPNAME( 0x0600, 0x0600, "1 Player Starting Score" ) PORT_DIPLOCATION("SW2:2,3") PORT_DIPSETTING( 0x0600, "12-12" ) PORT_DIPSETTING( 0x0400, "11-11" ) PORT_DIPSETTING( 0x0200, "11-12" ) PORT_DIPSETTING( 0x0000, "10-12" ) PORT_DIPNAME( 0x1800, 0x1800, "2 Players Starting Score" ) PORT_DIPLOCATION("SW2:4,5") PORT_DIPSETTING( 0x1800, "9-9" ) PORT_DIPSETTING( 0x1000, "7-7" ) PORT_DIPSETTING( 0x0800, "5-5" ) PORT_DIPSETTING( 0x0000, "0-0" ) PORT_DIPNAME( 0x2000, 0x2000, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW2:6") PORT_DIPSETTING( 0x2000, DEF_STR( Normal ) ) PORT_DIPSETTING( 0x0000, DEF_STR( Hard ) ) PORT_DIPNAME( 0x4000, 0x4000, "2 Players Time Per Credit" ) PORT_DIPLOCATION("SW2:7") PORT_DIPSETTING( 0x4000, "3 min" ) PORT_DIPSETTING( 0x0000, "2 min" ) PORT_DIPNAME( 0x8000, 0x8000, "Debug" ) PORT_DIPLOCATION("SW2:8") PORT_DIPSETTING( 0x8000, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) INPUT_PORTS_END static INPUT_PORTS_START( pspikesc ) PORT_INCLUDE( pspikes ) PORT_MODIFY("DSW") PORT_DIPNAME( 0x0030, 0x0030, "Country" ) PORT_DIPLOCATION("SW1:5,6") PORT_DIPSETTING( 0x0030, "China" ) PORT_DIPSETTING( 0x0020, "Taiwan" ) PORT_DIPSETTING( 0x0010, "Hong-Kong" ) PORT_DIPSETTING( 0x0000, "China" ) INPUT_PORTS_END static INPUT_PORTS_START( karatblz ) PORT_START("IN0") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_START1 ) PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START2 ) PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_START("IN1") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) PORT_START("IN2") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(3) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(3) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(3) PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(3) PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(3) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(3) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(3) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(3) PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_COIN3 ) PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_COIN4 ) PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_START3 ) PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START4 ) PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_SERVICE2 ) PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_START("IN3") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(4) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(4) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(4) PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(4) PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(4) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(4) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(4) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(4) PORT_START("DSW") PORT_DIPNAME( 0x0007, 0x0007, DEF_STR( Coinage ) ) PORT_DIPLOCATION("SW1:1,2,3") /* It affects Coin 1, 2, 3 and 4 */ PORT_DIPSETTING( 0x0004, DEF_STR( 4C_1C ) ) PORT_DIPSETTING( 0x0005, DEF_STR( 3C_1C ) ) PORT_DIPSETTING( 0x0006, DEF_STR( 2C_1C ) ) PORT_DIPSETTING( 0x0007, DEF_STR( 1C_1C ) ) PORT_DIPSETTING( 0x0003, DEF_STR( 1C_2C ) ) PORT_DIPSETTING( 0x0002, DEF_STR( 1C_3C ) ) PORT_DIPSETTING( 0x0001, DEF_STR( 1C_5C ) ) PORT_DIPSETTING( 0x0000, DEF_STR( 1C_6C ) ) PORT_DIPNAME( 0x0008, 0x0008, "Continue Coin" ) PORT_DIPLOCATION("SW1:4") PORT_DIPSETTING( 0x0008, "Start 1 Coin/Continue 1 Coin" ) PORT_DIPSETTING( 0x0000, "Start 2 Coin/Continue 1 Coin" ) PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW1:5") PORT_DIPSETTING( 0x0000, "1" ) PORT_DIPSETTING( 0x0010, "2" ) PORT_DIPNAME( 0x0060, 0x0060, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("SW1:6,7") /* Game Type */ PORT_DIPSETTING( 0x0060, "2 Players" ) /* 1 Unit / 2 Players */ PORT_DIPSETTING( 0x0040, "3 Players" ) /* 1 Unit / 3 Players */ PORT_DIPSETTING( 0x0020, "4 Players" ) /* 1 Unit / 4 Players */ PORT_DIPSETTING( 0x0000, "4 Players (Team)" ) /* 2 Units / 4 Players */ /* With 4 player (Team) selected and Same Coin Slot: Coin A & B credit together for use by _only_ player 1 or player 2 Coin C & D credit together for use by _only_ player 3 or player 4 Otherwise with Individual selected, everyone is seperate */ PORT_DIPNAME( 0x0080, 0x0080, "Coin Slot" ) PORT_DIPLOCATION("SW1:8") PORT_DIPSETTING( 0x0080, "Same" ) PORT_DIPSETTING( 0x0000, "Individual" ) /* According to Turbo Force manual, here DSW2 starts */ PORT_SERVICE_DIPLOC( 0x0100, IP_ACTIVE_LOW, "SW2:1" ) /* Default is DEF_STR( Hard ) */ PORT_DIPNAME( 0x0600, 0x0200, "Number of Enemies" ) PORT_DIPLOCATION("SW2:2,3") PORT_DIPSETTING( 0x0400, DEF_STR( Easy ) ) PORT_DIPSETTING( 0x0600, DEF_STR( Normal ) ) PORT_DIPSETTING( 0x0200, DEF_STR( Hard ) ) PORT_DIPSETTING( 0x0000, DEF_STR( Hardest ) ) /* Default is DEF_STR( Hard ) */ PORT_DIPNAME( 0x1800, 0x0800, "Strength of Enemies" ) PORT_DIPLOCATION("SW2:4,5") PORT_DIPSETTING( 0x1000, DEF_STR( Easy ) ) PORT_DIPSETTING( 0x1800, DEF_STR( Normal ) ) PORT_DIPSETTING( 0x0800, DEF_STR( Hard ) ) PORT_DIPSETTING( 0x0000, DEF_STR( Hardest ) ) /* Listed in manual as N.C. (aka No Connection) */ PORT_DIPNAME( 0x2000, 0x2000, "Freeze" ) PORT_DIPLOCATION("SW2:6") PORT_DIPSETTING( 0x2000, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) PORT_DIPNAME( 0x4000, 0x0000, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW2:7") PORT_DIPSETTING( 0x4000, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) PORT_DIPNAME( 0x8000, 0x8000, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SW2:8") PORT_DIPSETTING( 0x8000, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) INPUT_PORTS_END static INPUT_PORTS_START( spinlbrk ) PORT_START("IN0") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(1) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(1) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(1) PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1) PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_START1 ) PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START2 ) PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_START("IN1") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_START("DSW") PORT_DIPNAME( 0x000f, 0x000f, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SW1:1,2,3,4") PORT_DIPSETTING( 0x000f, "1 Credit 1 Health Pack" ) /* I chose "Health Packs" as the actual value can change */ PORT_DIPSETTING( 0x000e, "1 Credit 2 Health Packs" ) /* via dipswitch 2-7 (0x4000) see below */ PORT_DIPSETTING( 0x000d, "1 Credit 3 Health Packs" ) PORT_DIPSETTING( 0x000c, "1 Credit 4 Health Packs" ) PORT_DIPSETTING( 0x000b, "1 Credit 5 Health Packs" ) PORT_DIPSETTING( 0x000a, "1 Credit 6 Health Packs" ) PORT_DIPSETTING( 0x0009, "2 Credits 1 Health Pack" ) PORT_DIPSETTING( 0x0008, "3 Credits 1 Health Pack" ) PORT_DIPSETTING( 0x0007, "4 Credits 1 Health Pack" ) PORT_DIPSETTING( 0x0006, "5 Credits 1 Health Pack" ) PORT_DIPSETTING( 0x0005, "2 Credits 2 Health Packs" ) PORT_DIPSETTING( 0x0004, "2-1-1C 1-1-1 HPs" ) PORT_DIPSETTING( 0x0003, "2-2C 1-2 HPs" ) PORT_DIPSETTING( 0x0002, "1-1-1-1-1C 1-1-1-1-2 HPs" ) PORT_DIPSETTING( 0x0001, "1-1-1-1C 1-1-1-2 HPs" ) PORT_DIPSETTING( 0x0000, "1-1C 1-2 HPs" ) /* The last 5 Coin/Credit selections are cycles: Example: 0x0004 = 2-1-1C 1-1-1 HPs: 2 Credits for the 1st Health Pack, 1 Credit for the 2nd Health Pack, 1 Credit for the 3rd Health Pack... Then back to 2 Credits again for 1 HP, then 1 credit and 1 credit.... on and on. With all Coin/Credit dips set to on, it's 1 Health Pack for odd credits, 2 Health Packs for even credits :p */ PORT_DIPNAME( 0x00f0, 0x00f0, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("SW1:5,6,7,8") PORT_DIPSETTING( 0x00f0, "1 Credit 1 Health Pack" ) PORT_DIPSETTING( 0x00e0, "1 Credit 2 Health Packs" ) PORT_DIPSETTING( 0x00d0, "1 Credit 3 Health Packs" ) PORT_DIPSETTING( 0x00c0, "1 Credit 4 Health Packs" ) PORT_DIPSETTING( 0x00b0, "1 Credit 5 Health Packs" ) PORT_DIPSETTING( 0x00a0, "1 Credit 6 Health Packs" ) PORT_DIPSETTING( 0x0090, "2 Credits 1 Health Pack" ) PORT_DIPSETTING( 0x0080, "3 Credits 1 Health Pack" ) PORT_DIPSETTING( 0x0070, "4 Credits 1 Health Pack" ) PORT_DIPSETTING( 0x0060, "5 Credits 1 Health Pack" ) PORT_DIPSETTING( 0x0050, "2 Credits 2 Health Packs" ) PORT_DIPSETTING( 0x0040, "2-1-1C 1-1-1 HPs" ) PORT_DIPSETTING( 0x0030, "2-2C 1-2 HPs" ) PORT_DIPSETTING( 0x0020, "1-1-1-1-1C 1-1-1-1-2 HPs" ) PORT_DIPSETTING( 0x0010, "1-1-1-1C 1-1-1-2 HPs" ) PORT_DIPSETTING( 0x0000, "1-1C 1-2 HPs" ) /* According to Spinal Breakers manual, here DSW2 starts */ /* Default in US manual is DEF_STR( Hardest ) */ PORT_DIPNAME( 0x0300, 0x0000, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW2:1,2") PORT_DIPSETTING( 0x0300, DEF_STR( Normal ) ) PORT_DIPSETTING( 0x0200, DEF_STR( Easy ) ) PORT_DIPSETTING( 0x0100, DEF_STR( Hard ) ) PORT_DIPSETTING( 0x0000, DEF_STR( Hardest ) ) PORT_DIPNAME( 0x0400, 0x0400, "Credits For Extra Hitpoints" ) PORT_DIPLOCATION("SW2:3") PORT_DIPSETTING( 0x0000, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0400, DEF_STR( On ) ) PORT_DIPNAME( 0x0800, 0x0800, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SW2:4") PORT_DIPSETTING( 0x0800, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) PORT_DIPNAME( 0x1000, 0x1000, "Lever Type" ) PORT_DIPLOCATION("SW2:5") PORT_DIPSETTING( 0x1000, "Digital" ) PORT_DIPSETTING( 0x0000, "Analog" ) /* This setting causes lever error??? */ PORT_SERVICE_DIPLOC( 0x2000, IP_ACTIVE_LOW, "SW2:6" ) PORT_DIPNAME( 0x4000, 0x4000, "Health Pack" ) PORT_DIPLOCATION("SW2:7") PORT_DIPSETTING( 0x4000, "32 Hitpoints" ) PORT_DIPSETTING( 0x0000, "40 Hitpoints" ) /* Default in US manual is "5 points" */ PORT_DIPNAME( 0x8000, 0x0000, "Life Restoration" ) PORT_DIPLOCATION("SW2:8") PORT_DIPSETTING( 0x8000, "10 Points" ) PORT_DIPSETTING( 0x0000, "5 Points" ) INPUT_PORTS_END static INPUT_PORTS_START( spinlbrku ) PORT_INCLUDE(spinlbrk) PORT_MODIFY("DSW") PORT_DIPNAME( 0x4000, 0x4000, "Health Pack" ) PORT_DIPLOCATION("SW2:7") PORT_DIPSETTING( 0x4000, "20 Hitpoints" ) PORT_DIPSETTING( 0x0000, "32 Hitpoints" ) INPUT_PORTS_END static INPUT_PORTS_START( turbofrc ) PORT_START("IN0") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(1) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(1) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(1) PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1) PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) /* COIN1 in service */ PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_START1 ) PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START2 ) PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_SERVICE ) /* "TEST" */ PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_TILT ) PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_COIN3 ) PORT_START("IN1") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) /* START1 */ PORT_START("IN2") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(3) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(3) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(3) PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(3) PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(3) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START3 ) PORT_START("DSW") PORT_DIPNAME( 0x0007, 0x0007, DEF_STR( Coinage ) ) PORT_DIPLOCATION("SW1:1,2,3") /* It affects Coin 1, 2 and 3 */ PORT_DIPSETTING( 0x0004, DEF_STR( 4C_1C ) ) PORT_DIPSETTING( 0x0005, DEF_STR( 3C_1C ) ) PORT_DIPSETTING( 0x0006, DEF_STR( 2C_1C ) ) PORT_DIPSETTING( 0x0007, DEF_STR( 1C_1C ) ) PORT_DIPSETTING( 0x0003, DEF_STR( 1C_2C ) ) PORT_DIPSETTING( 0x0002, DEF_STR( 1C_3C ) ) PORT_DIPSETTING( 0x0001, DEF_STR( 1C_5C ) ) PORT_DIPSETTING( 0x0000, DEF_STR( 1C_6C ) ) PORT_DIPNAME( 0x0008, 0x0008, "Continue Coin" ) PORT_DIPLOCATION("SW1:4") PORT_DIPSETTING( 0x0008, "Start 1 Coin/Continue 1 Coin" ) PORT_DIPSETTING( 0x0000, "Start 2 Coin/Continue 1 Coin" ) PORT_DIPNAME( 0x0010, 0x0000, "Coin Slot" ) PORT_DIPLOCATION("SW1:5") PORT_DIPSETTING( 0x0010, "Same" ) PORT_DIPSETTING( 0x0000, "Individual" ) PORT_DIPNAME( 0x0020, 0x0000, "Play Mode" ) PORT_DIPLOCATION("SW1:6") PORT_DIPSETTING( 0x0020, "2 Players" ) PORT_DIPSETTING( 0x0000, "3 Players" ) PORT_DIPNAME( 0x0040, 0x0000, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW1:7") PORT_DIPSETTING( 0x0040, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) PORT_SERVICE_DIPLOC( 0x0080, IP_ACTIVE_LOW, "SW1:8" ) /* According to Turbo Force manual, here DSW2 starts */ PORT_DIPNAME( 0x0100, 0x0100, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SW2:1") PORT_DIPSETTING( 0x0100, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) PORT_DIPNAME( 0x0e00, 0x0800, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW2:2,3,4") PORT_DIPSETTING( 0x0e00, "1 (Easiest)") PORT_DIPSETTING( 0x0c00, "2" ) PORT_DIPSETTING( 0x0a00, "3" ) PORT_DIPSETTING( 0x0800, "4 (Normal)" ) PORT_DIPSETTING( 0x0600, "5" ) PORT_DIPSETTING( 0x0400, "6" ) PORT_DIPSETTING( 0x0200, "7" ) PORT_DIPSETTING( 0x0000, "8 (Hardest)" ) PORT_DIPNAME( 0x1000, 0x1000, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW2:5") PORT_DIPSETTING( 0x0000, "2" ) PORT_DIPSETTING( 0x1000, "3" ) PORT_DIPNAME( 0x2000, 0x2000, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("SW2:6") PORT_DIPSETTING( 0x2000, "200000" ) PORT_DIPSETTING( 0x0000, "300000" ) /* The following 2 are listed in Turbo Force manual as N.C. (aka No Connection) and "Should be kept on OFF" */ PORT_DIPUNUSED_DIPLOC( 0x4000, 0x4000, "SW2:7" ) /* Listed as "Unused" */ PORT_DIPUNUSED_DIPLOC( 0x8000, 0x8000, "SW2:8" ) /* Listed as "Unused" */ INPUT_PORTS_END static INPUT_PORTS_START( aerofgtb ) PORT_START("IN0") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_START1 ) PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START2 ) PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_START("IN1") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_START("DSW1") /* Dips bank 1 */ /* "Free Play mode: Have SW1:1-8 ON." */ PORT_DIPNAME( 0x0001, 0x0001, "Coin Slot" ) PORT_DIPLOCATION("SW1:1") PORT_DIPSETTING( 0x0001, "Same" ) PORT_DIPSETTING( 0x0000, "Individual" ) PORT_DIPNAME( 0x000e, 0x000e, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SW1:2,3,4") PORT_DIPSETTING( 0x000a, DEF_STR( 3C_1C ) ) PORT_DIPSETTING( 0x000c, DEF_STR( 2C_1C ) ) PORT_DIPSETTING( 0x000e, DEF_STR( 1C_1C ) ) PORT_DIPSETTING( 0x0008, DEF_STR( 1C_2C ) ) PORT_DIPSETTING( 0x0006, DEF_STR( 1C_3C ) ) PORT_DIPSETTING( 0x0004, DEF_STR( 1C_4C ) ) PORT_DIPSETTING( 0x0002, DEF_STR( 1C_5C ) ) PORT_DIPSETTING( 0x0000, DEF_STR( 1C_6C ) ) PORT_DIPNAME( 0x0070, 0x0070, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("SW1:5,6,7") PORT_DIPSETTING( 0x0050, DEF_STR( 3C_1C ) ) PORT_DIPSETTING( 0x0060, DEF_STR( 2C_1C ) ) PORT_DIPSETTING( 0x0070, DEF_STR( 1C_1C ) ) PORT_DIPSETTING( 0x0040, DEF_STR( 1C_2C ) ) PORT_DIPSETTING( 0x0030, DEF_STR( 1C_3C ) ) PORT_DIPSETTING( 0x0020, DEF_STR( 1C_4C ) ) PORT_DIPSETTING( 0x0010, DEF_STR( 1C_5C ) ) PORT_DIPSETTING( 0x0000, DEF_STR( 1C_6C ) ) PORT_DIPNAME( 0x0080, 0x0080, "Continue Coin" ) PORT_DIPLOCATION("SW1:8") /* "When ON SW1:2-7 are disabled." */ PORT_DIPSETTING( 0x0080, "Start 1 Coin/Continue 1 Coin" ) PORT_DIPSETTING( 0x0000, "Start 2 Coin/Continue 1 Coin" ) /* Dips bank 2 */ PORT_DIPNAME( 0x0100, 0x0100, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SW2:1") PORT_DIPSETTING( 0x0100, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) PORT_DIPNAME( 0x0200, 0x0000, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW2:2") PORT_DIPSETTING( 0x0200, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) PORT_DIPNAME( 0x0c00, 0x0c00, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW2:3,4") PORT_DIPSETTING( 0x0800, DEF_STR( Easy ) ) PORT_DIPSETTING( 0x0c00, DEF_STR( Normal ) ) PORT_DIPSETTING( 0x0400, DEF_STR( Hard ) ) PORT_DIPSETTING( 0x0000, DEF_STR( Hardest ) ) PORT_DIPNAME( 0x3000, 0x3000, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW2:5,6") PORT_DIPSETTING( 0x2000, "1" ) PORT_DIPSETTING( 0x1000, "2" ) PORT_DIPSETTING( 0x3000, "3" ) PORT_DIPSETTING( 0x0000, "4" ) PORT_DIPNAME( 0x4000, 0x4000, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("SW2:7") PORT_DIPSETTING( 0x4000, "200000" ) PORT_DIPSETTING( 0x0000, "300000" ) PORT_SERVICE( 0x8000, IP_ACTIVE_LOW ) /* Dips bank 3 (not documented) */ PORT_START("DSW2") PORT_DIPNAME( 0x0001, 0x0000, "Country" ) PORT_DIPLOCATION("SW3:1") PORT_DIPSETTING( 0x0000, DEF_STR( Japan ) ) PORT_DIPSETTING( 0x0001, "Taiwan" ) /* TODO: there are others in the table at 11910 */ /* this port is checked at 1b080 */ INPUT_PORTS_END static INPUT_PORTS_START( aerofgt ) PORT_START("P1") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_START("P2") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_START("SYSTEM") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_START1 ) PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_START2 ) PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_START("DSW1") /* "Free Play mode: Have SW1:1-8 ON." */ PORT_DIPNAME( 0x0001, 0x0001, "Coin Slot" ) PORT_DIPLOCATION("SW1:1") PORT_DIPSETTING( 0x0001, "Same" ) PORT_DIPSETTING( 0x0000, "Individual" ) PORT_DIPNAME( 0x000e, 0x000e, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SW1:2,3,4") PORT_DIPSETTING( 0x000a, DEF_STR( 3C_1C ) ) PORT_DIPSETTING( 0x000c, DEF_STR( 2C_1C ) ) PORT_DIPSETTING( 0x000e, DEF_STR( 1C_1C ) ) PORT_DIPSETTING( 0x0008, DEF_STR( 1C_2C ) ) PORT_DIPSETTING( 0x0006, DEF_STR( 1C_3C ) ) PORT_DIPSETTING( 0x0004, DEF_STR( 1C_4C ) ) PORT_DIPSETTING( 0x0002, DEF_STR( 1C_5C ) ) PORT_DIPSETTING( 0x0000, DEF_STR( 1C_6C ) ) PORT_DIPNAME( 0x0070, 0x0070, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("SW1:5,6,7") PORT_DIPSETTING( 0x0050, DEF_STR( 3C_1C ) ) PORT_DIPSETTING( 0x0060, DEF_STR( 2C_1C ) ) PORT_DIPSETTING( 0x0070, DEF_STR( 1C_1C ) ) PORT_DIPSETTING( 0x0040, DEF_STR( 1C_2C ) ) PORT_DIPSETTING( 0x0030, DEF_STR( 1C_3C ) ) PORT_DIPSETTING( 0x0020, DEF_STR( 1C_4C ) ) PORT_DIPSETTING( 0x0010, DEF_STR( 1C_5C ) ) PORT_DIPSETTING( 0x0000, DEF_STR( 1C_6C ) ) PORT_DIPNAME( 0x0080, 0x0080, "Continue Coin" ) PORT_DIPLOCATION("SW1:8") /* "When ON, SW1:2-7 are disabled." */ PORT_DIPSETTING( 0x0080, "Start 1 Coin/Continue 1 Coin" ) PORT_DIPSETTING( 0x0000, "Start 2 Coin/Continue 1 Coin" ) PORT_START("DSW2") PORT_DIPNAME( 0x0001, 0x0001, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SW2:1") PORT_DIPSETTING( 0x0001, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) PORT_DIPNAME( 0x0002, 0x0000, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW2:2") PORT_DIPSETTING( 0x0002, DEF_STR( Off ) ) PORT_DIPSETTING( 0x0000, DEF_STR( On ) ) PORT_DIPNAME( 0x000c, 0x000c, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW2:3,4") PORT_DIPSETTING( 0x0008, DEF_STR( Easy ) ) PORT_DIPSETTING( 0x000c, DEF_STR( Normal ) ) PORT_DIPSETTING( 0x0004, DEF_STR( Hard ) ) PORT_DIPSETTING( 0x0000, DEF_STR( Hardest ) ) PORT_DIPNAME( 0x0030, 0x0030, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW2:5,6") PORT_DIPSETTING( 0x0020, "1" ) PORT_DIPSETTING( 0x0010, "2" ) PORT_DIPSETTING( 0x0030, "3" ) PORT_DIPSETTING( 0x0000, "4" ) PORT_DIPNAME( 0x0040, 0x0040, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("SW2:7") PORT_DIPSETTING( 0x0040, "200000" ) PORT_DIPSETTING( 0x0000, "300000" ) PORT_SERVICE_DIPLOC( 0x0080, IP_ACTIVE_LOW, "SW2:8" ) /* This DSW3 is not documented in the Aero Fighters manual */ PORT_START("DSW3") PORT_DIPNAME( 0x000f, 0x0000, "Country" ) PORT_DIPSETTING( 0x0000, "Any" ) PORT_DIPSETTING( 0x000f, "USA/Canada" ) PORT_DIPSETTING( 0x000e, "Korea" ) PORT_DIPSETTING( 0x000d, "Hong Kong" ) PORT_DIPSETTING( 0x000b, "Taiwan" ) INPUT_PORTS_END static INPUT_PORTS_START( wbbc97 ) PORT_INCLUDE(pspikes) PORT_MODIFY("IN0") PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_SERVICE1 ) INPUT_PORTS_END static const gfx_layout pspikes_charlayout = { 8,8, RGN_FRAC(1,1), 4, { 0, 1, 2, 3 }, { 1*4, 0*4, 3*4, 2*4, 5*4, 4*4, 7*4, 6*4 }, { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 }, 32*8 }; static const gfx_layout aerofgt_charlayout = { 8,8, RGN_FRAC(1,1), 4, { 0, 1, 2, 3 }, { 2*4, 3*4, 0*4, 1*4, 6*4, 7*4, 4*4, 5*4 }, { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 }, 32*8 }; static const gfx_layout pspikesb_charlayout = { 8,8, RGN_FRAC(1,4), 4, { RGN_FRAC(0,4), RGN_FRAC(1,4), RGN_FRAC(2,4), RGN_FRAC(3,4) }, { 0, 1, 2, 3, 4, 5, 6, 7 }, { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 }, 8*8 }; static const gfx_layout aerfboot_charlayout = { 8,8, RGN_FRAC(1,8), 4, { RGN_FRAC(3,4), RGN_FRAC(2,4), RGN_FRAC(1,4), RGN_FRAC(0,4) }, { 7, 6, 5, 4, 3, 2, 1, 0 }, { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 }, 8*8 }; static const gfx_layout aerfboo2_charlayout = { 8,8, RGN_FRAC(1,2), 4, { 0, 1, 2, 3 }, { 1*4, 0*4, RGN_FRAC(1,2)+1*4, RGN_FRAC(1,2)+0*4, 3*4, 2*4, RGN_FRAC(1,2)+3*4, RGN_FRAC(1,2)+2*4 }, { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 }, 32*4 }; static const gfx_layout pspikes_spritelayout = { 16,16, RGN_FRAC(1,2), 4, { 0, 1, 2, 3 }, { 1*4, 0*4, 3*4, 2*4, RGN_FRAC(1,2)+1*4, RGN_FRAC(1,2)+0*4, RGN_FRAC(1,2)+3*4, RGN_FRAC(1,2)+2*4, 5*4, 4*4, 7*4, 6*4, RGN_FRAC(1,2)+5*4, RGN_FRAC(1,2)+4*4, RGN_FRAC(1,2)+7*4, RGN_FRAC(1,2)+6*4 }, { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32, 8*32, 9*32, 10*32, 11*32, 12*32, 13*32, 14*32, 15*32 }, 64*8 }; static const gfx_layout pspikesb_spritelayout = { 16,16, RGN_FRAC(1,4), 4, { RGN_FRAC(0,4), RGN_FRAC(1,4), RGN_FRAC(2,4), RGN_FRAC(3,4) }, { 0, 1, 2, 3, 4, 5, 6, 7, 16*8+0, 16*8+1, 16*8+2, 16*8+3, 16*8+4, 16*8+5, 16*8+6, 16*8+7 }, { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8, 8*8, 9*8, 10*8, 11*8, 12*8, 13*8, 14*8, 15*8 }, 32*8 }; static const gfx_layout aerofgtb_spritelayout = { 16,16, RGN_FRAC(1,2), 4, { 0, 1, 2, 3 }, { 3*4, 2*4, 1*4, 0*4, RGN_FRAC(1,2)+3*4, RGN_FRAC(1,2)+2*4, RGN_FRAC(1,2)+1*4, RGN_FRAC(1,2)+0*4, 7*4, 6*4, 5*4, 4*4, RGN_FRAC(1,2)+7*4, RGN_FRAC(1,2)+6*4, RGN_FRAC(1,2)+5*4, RGN_FRAC(1,2)+4*4 }, { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32, 8*32, 9*32, 10*32, 11*32, 12*32, 13*32, 14*32, 15*32 }, 64*8 }; static const gfx_layout aerofgt_spritelayout = { 16,16, RGN_FRAC(1,1), 4, { 0, 1, 2, 3 }, { 2*4, 3*4, 0*4, 1*4, 6*4, 7*4, 4*4, 5*4, 10*4, 11*4, 8*4, 9*4, 14*4, 15*4, 12*4, 13*4 }, { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64, 8*64, 9*64, 10*64, 11*64, 12*64, 13*64, 14*64, 15*64 }, 128*8 }; static const gfx_layout spikes91_spritelayout = { 16,16, RGN_FRAC(1,4), 4, { RGN_FRAC(3,4), RGN_FRAC(2,4), RGN_FRAC(1,4), RGN_FRAC(0,4) }, { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16, 8*16, 9*16, 10*16, 11*16, 12*16, 13*16, 14*16, 15*16 }, 16*16 }; static const gfx_layout aerfboot_spritelayout = { 16,16, RGN_FRAC(1,2), 4, { 0, 1, 2, 3 }, { 2*4, 3*4, RGN_FRAC(1,2)+2*4, RGN_FRAC(1,2)+3*4, 0*4, 1*4, RGN_FRAC(1,2)+0*4, RGN_FRAC(1,2)+1*4, 6*4, 7*4, RGN_FRAC(1,2)+6*4, RGN_FRAC(1,2)+7*4, 4*4, 5*4, RGN_FRAC(1,2)+4*4, RGN_FRAC(1,2)+5*4 }, { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32, 8*32, 9*32, 10*32, 11*32, 12*32, 13*32, 14*32, 15*32 }, 64*8 }; static const gfx_layout aerfboo2_spritelayout = { 16,16, RGN_FRAC(1,2), 4, { 0,1,2,3 }, { 28,24,20,16,12,8,4,0,60,56,52,48,44,40,36,32 }, { 0*64,1*64,2*64,3*64,4*64,5*64,6*64,7*64,8*64,9*64,10*64,11*64,12*64,13*64,14*64,15*64 }, 16*64 }; static const gfx_layout wbbc97_spritelayout = { 16,16, RGN_FRAC(1,4), 4, { 0,1,2,3 }, { RGN_FRAC(3,4)+4, RGN_FRAC(3,4)+0, RGN_FRAC(2,4)+4, RGN_FRAC(2,4)+0, RGN_FRAC(1,4)+4, RGN_FRAC(1,4)+0, RGN_FRAC(0,4)+4, RGN_FRAC(0,4)+0, RGN_FRAC(3,4)+12, RGN_FRAC(3,4)+8, RGN_FRAC(2,4)+12, RGN_FRAC(2,4)+8, RGN_FRAC(1,4)+12, RGN_FRAC(1,4)+8, RGN_FRAC(0,4)+12, RGN_FRAC(0,4)+8 }, { 0*8,2*8,4*8,6*8,8*8,10*8,12*8,14*8,16*8,18*8,20*8,22*8,24*8,26*8,28*8,30*8 }, 8*32 }; static GFXDECODE_START( pspikes ) GFXDECODE_ENTRY( "gfx1", 0, pspikes_charlayout, 0, 64 ) /* colors 0-1023 in 8 banks */ GFXDECODE_ENTRY( "gfx2", 0, pspikes_spritelayout, 1024, 64 ) /* colors 1024-2047 in 4 banks */ GFXDECODE_END static GFXDECODE_START( pspikesb ) GFXDECODE_ENTRY( "gfx1", 0, pspikesb_charlayout, 0, 64 ) /* colors 0-1023 in 8 banks */ GFXDECODE_ENTRY( "gfx2", 0, pspikesb_spritelayout, 1024, 64 ) /* colors 1024-2047 in 4 banks */ GFXDECODE_END static GFXDECODE_START( spikes91 ) GFXDECODE_ENTRY( "gfx1", 0, pspikesb_charlayout, 0, 64 ) /* colors 0-1023 in 8 banks */ GFXDECODE_ENTRY( "gfx2", 0, spikes91_spritelayout, 1024, 64 ) /* colors 1024-2047 in 4 banks */ GFXDECODE_END static GFXDECODE_START( turbofrc ) GFXDECODE_ENTRY( "gfx1", 0, pspikes_charlayout, 0, 16 ) GFXDECODE_ENTRY( "gfx2", 0, pspikes_charlayout, 256, 16 ) GFXDECODE_ENTRY( "gfx3", 0, pspikes_spritelayout, 512, 16 ) GFXDECODE_ENTRY( "gfx4", 0, pspikes_spritelayout, 768, 16 ) GFXDECODE_END static GFXDECODE_START( aerofgtb ) GFXDECODE_ENTRY( "gfx1", 0, pspikes_charlayout, 0, 16 ) GFXDECODE_ENTRY( "gfx2", 0, pspikes_charlayout, 256, 16 ) GFXDECODE_ENTRY( "gfx3", 0, aerofgtb_spritelayout, 512, 16 ) GFXDECODE_ENTRY( "gfx4", 0, aerofgtb_spritelayout, 768, 16 ) GFXDECODE_END static GFXDECODE_START( aerofgt ) GFXDECODE_ENTRY( "gfx1", 0, aerofgt_charlayout, 0, 16 ) GFXDECODE_ENTRY( "gfx1", 0, aerofgt_charlayout, 256, 16 ) GFXDECODE_ENTRY( "gfx2", 0, aerofgt_spritelayout, 512, 16 ) GFXDECODE_ENTRY( "gfx3", 0, aerofgt_spritelayout, 768, 16 ) GFXDECODE_END static GFXDECODE_START( aerfboot ) GFXDECODE_ENTRY( "gfx1", 0, aerfboot_charlayout, 0, 16 ) GFXDECODE_ENTRY( "gfx1", 0x20000, aerfboot_charlayout, 256, 16 ) GFXDECODE_ENTRY( "gfx2", 0, aerfboot_spritelayout, 512, 16 ) GFXDECODE_ENTRY( "gfx3", 0, aerfboot_spritelayout, 768, 16 ) GFXDECODE_END static GFXDECODE_START( aerfboo2 ) GFXDECODE_ENTRY( "gfx1", 0, aerfboo2_charlayout, 0, 16 ) GFXDECODE_ENTRY( "gfx2", 0, aerfboo2_charlayout, 256, 16 ) GFXDECODE_ENTRY( "gfx3", 0, aerfboo2_spritelayout, 512, 16 ) GFXDECODE_ENTRY( "gfx3", 0x100000,aerfboo2_spritelayout, 768, 16 ) GFXDECODE_END static GFXDECODE_START( wbbc97 ) GFXDECODE_ENTRY( "gfx1", 0, pspikes_charlayout, 0, 64 ) /* colors 0-1023 in 8 banks */ GFXDECODE_ENTRY( "gfx2", 0, wbbc97_spritelayout, 1024, 64 ) /* colors 1024-2047 in 4 banks */ GFXDECODE_END static void irqhandler( device_t *device, int irq ) { aerofgt_state *state = device->machine().driver_data<aerofgt_state>(); device_set_input_line(state->m_audiocpu, 0, irq ? ASSERT_LINE : CLEAR_LINE); } static const ym2610_interface ym2610_config = { irqhandler }; static const ym3812_interface ym3812_config = { irqhandler /* IRQ Line */ }; static MACHINE_START( common ) { aerofgt_state *state = machine.driver_data<aerofgt_state>(); state->m_audiocpu = machine.device("audiocpu"); state->save_item(NAME(state->m_pending_command)); } static MACHINE_START( aerofgt ) { UINT8 *rom = machine.region("audiocpu")->base(); memory_configure_bank(machine, "bank1", 0, 4, &rom[0x10000], 0x8000); MACHINE_START_CALL(common); } static MACHINE_RESET( common ) { aerofgt_state *state = machine.driver_data<aerofgt_state>(); state->m_pending_command = 0; } static MACHINE_RESET( aerofgt ) { MACHINE_RESET_CALL(common); memory_set_bank(machine, "bank1", 0); /* needed by spinlbrk */ } static MACHINE_CONFIG_START( pspikes, aerofgt_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu",M68000,XTAL_20MHz/2) /* verified on pcb */ MCFG_CPU_PROGRAM_MAP(pspikes_map) MCFG_CPU_VBLANK_INT("screen", irq1_line_hold)/* all irq vectors are the same */ MCFG_CPU_ADD("audiocpu",Z80,XTAL_20MHz/4) /* verified on pcb */ MCFG_CPU_PROGRAM_MAP(sound_map) MCFG_CPU_IO_MAP(turbofrc_sound_portmap) /* IRQs are triggered by the YM2610 */ MCFG_MACHINE_START(aerofgt) MCFG_MACHINE_RESET(aerofgt) /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(61.31) /* verified on pcb */ MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) MCFG_SCREEN_SIZE(64*8, 32*8) MCFG_SCREEN_VISIBLE_AREA(0*8+4, 44*8+4-1, 0*8, 30*8-1) MCFG_SCREEN_UPDATE(pspikes) MCFG_GFXDECODE(pspikes) MCFG_PALETTE_LENGTH(2048) MCFG_VIDEO_START(pspikes) /* sound hardware */ MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") MCFG_SOUND_ADD("ymsnd", YM2610, 8000000) MCFG_SOUND_CONFIG(ym2610_config) MCFG_SOUND_ROUTE(0, "lspeaker", 0.25) MCFG_SOUND_ROUTE(0, "rspeaker", 0.25) MCFG_SOUND_ROUTE(1, "lspeaker", 1.0) MCFG_SOUND_ROUTE(2, "rspeaker", 1.0) MACHINE_CONFIG_END static MACHINE_CONFIG_START( spikes91, aerofgt_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu",M68000,20000000/2) /* 10 MHz (?) */ MCFG_CPU_PROGRAM_MAP(spikes91_map) MCFG_CPU_VBLANK_INT("screen", irq1_line_hold)/* all irq vectors are the same */ /* + Z80 for sound */ MCFG_MACHINE_START(common) MCFG_MACHINE_RESET(common) /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60) MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) MCFG_SCREEN_SIZE(64*8, 32*8) MCFG_SCREEN_VISIBLE_AREA(0*8, 320-1, 0*8+4, 224+4-1) MCFG_SCREEN_UPDATE(spikes91) MCFG_GFXDECODE(spikes91) MCFG_PALETTE_LENGTH(2048) MCFG_VIDEO_START(pspikes) /* sound hardware */ /* the sound hardware is completely different on this: 1x YM2151 (sound)(ic150) 1x OKI M5205 (sound)(ic145) 2x LM324N (sound)(ic152, ic153) */ MACHINE_CONFIG_END static MACHINE_CONFIG_START( pspikesb, aerofgt_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu",M68000,20000000/2) /* 10 MHz (?) */ MCFG_CPU_PROGRAM_MAP(pspikesb_map) MCFG_CPU_VBLANK_INT("screen", irq1_line_hold)/* all irq vectors are the same */ MCFG_MACHINE_START(common) MCFG_MACHINE_RESET(common) /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60) MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) MCFG_SCREEN_SIZE(64*8, 32*8) MCFG_SCREEN_VISIBLE_AREA(0*8+4, 44*8+4-1, 0*8, 30*8-1) MCFG_SCREEN_UPDATE(pspikesb) MCFG_GFXDECODE(pspikesb) MCFG_PALETTE_LENGTH(2048) MCFG_VIDEO_START(pspikes) /* sound hardware */ MCFG_SPEAKER_STANDARD_MONO("mono") MCFG_OKIM6295_ADD("oki", 1056000, OKIM6295_PIN7_HIGH) // clock frequency & pin 7 not verified MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) MACHINE_CONFIG_END static MACHINE_CONFIG_START( pspikesc, aerofgt_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu",M68000,20000000/2) /* 10 MHz (?) */ MCFG_CPU_PROGRAM_MAP(pspikesc_map) MCFG_CPU_VBLANK_INT("screen", irq1_line_hold)/* all irq vectors are the same */ MCFG_MACHINE_START(common) MCFG_MACHINE_RESET(common) /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60) MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) MCFG_SCREEN_SIZE(64*8, 32*8) MCFG_SCREEN_VISIBLE_AREA(0*8+4, 44*8+4-1, 0*8, 30*8-1) MCFG_SCREEN_UPDATE(pspikes) MCFG_GFXDECODE(pspikes) MCFG_PALETTE_LENGTH(2048) MCFG_VIDEO_START(pspikes) /* sound hardware */ MCFG_SPEAKER_STANDARD_MONO("mono") MCFG_OKIM6295_ADD("oki", 1056000, OKIM6295_PIN7_HIGH) // clock frequency & pin 7 not verified MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) MACHINE_CONFIG_END static MACHINE_CONFIG_START( karatblz, aerofgt_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu",M68000,20000000/2) /* 10 MHz (?) */ MCFG_CPU_PROGRAM_MAP(karatblz_map) MCFG_CPU_VBLANK_INT("screen", irq1_line_hold) MCFG_CPU_ADD("audiocpu",Z80,8000000/2) /* 4 MHz ??? */ MCFG_CPU_PROGRAM_MAP(sound_map) MCFG_CPU_IO_MAP(turbofrc_sound_portmap) /* IRQs are triggered by the YM2610 */ MCFG_MACHINE_START(aerofgt) MCFG_MACHINE_RESET(aerofgt) /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60) MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) MCFG_SCREEN_SIZE(64*8, 32*8) MCFG_SCREEN_VISIBLE_AREA(1*8, 45*8-1, 0*8, 30*8-1) MCFG_SCREEN_UPDATE(karatblz) MCFG_GFXDECODE(turbofrc) MCFG_PALETTE_LENGTH(1024) MCFG_VIDEO_START(karatblz) /* sound hardware */ MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") MCFG_SOUND_ADD("ymsnd", YM2610, XTAL_8MHz ) /* verified on pcb */ MCFG_SOUND_CONFIG(ym2610_config) MCFG_SOUND_ROUTE(0, "lspeaker", 0.25) MCFG_SOUND_ROUTE(0, "rspeaker", 0.25) MCFG_SOUND_ROUTE(1, "lspeaker", 1.0) MCFG_SOUND_ROUTE(2, "rspeaker", 1.0) MACHINE_CONFIG_END static MACHINE_CONFIG_START( spinlbrk, aerofgt_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu",M68000,XTAL_20MHz/2) /* verified on pcb */ MCFG_CPU_PROGRAM_MAP(spinlbrk_map) MCFG_CPU_VBLANK_INT("screen", irq1_line_hold)/* there are vectors for 3 and 4 too */ MCFG_CPU_ADD("audiocpu",Z80,XTAL_20MHz/4) /* 5mhz verified on pcb */ MCFG_CPU_PROGRAM_MAP(sound_map) MCFG_CPU_IO_MAP(turbofrc_sound_portmap) /* IRQs are triggered by the YM2610 */ MCFG_MACHINE_START(aerofgt) MCFG_MACHINE_RESET(aerofgt) /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60) MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) MCFG_SCREEN_SIZE(64*8, 32*8) MCFG_SCREEN_VISIBLE_AREA(1*8, 45*8-1, 0*8, 30*8-1) MCFG_SCREEN_UPDATE(spinlbrk) MCFG_GFXDECODE(turbofrc) MCFG_PALETTE_LENGTH(1024) MCFG_VIDEO_START(spinlbrk) /* sound hardware */ MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") MCFG_SOUND_ADD("ymsnd", YM2610, XTAL_8MHz) /* verified on pcb */ MCFG_SOUND_CONFIG(ym2610_config) MCFG_SOUND_ROUTE(0, "lspeaker", 0.25) MCFG_SOUND_ROUTE(0, "rspeaker", 0.25) MCFG_SOUND_ROUTE(1, "lspeaker", 1.0) MCFG_SOUND_ROUTE(2, "rspeaker", 1.0) MACHINE_CONFIG_END static MACHINE_CONFIG_START( turbofrc, aerofgt_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu",M68000,XTAL_20MHz/2) /* verified on pcb */ MCFG_CPU_PROGRAM_MAP(turbofrc_map) MCFG_CPU_VBLANK_INT("screen", irq1_line_hold)/* all irq vectors are the same */ MCFG_CPU_ADD("audiocpu",Z80,XTAL_5MHz) /* verified on pcb */ MCFG_CPU_PROGRAM_MAP(sound_map) MCFG_CPU_IO_MAP(turbofrc_sound_portmap) /* IRQs are triggered by the YM2610 */ MCFG_MACHINE_START(aerofgt) MCFG_MACHINE_RESET(aerofgt) /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(61.31) /* verified on pcb */ MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) MCFG_SCREEN_SIZE(64*8, 32*8) MCFG_SCREEN_VISIBLE_AREA(0*8, 44*8-1, 0*8, 30*8-1) MCFG_SCREEN_UPDATE(turbofrc) MCFG_GFXDECODE(turbofrc) MCFG_PALETTE_LENGTH(1024) MCFG_VIDEO_START(turbofrc) /* sound hardware */ MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") MCFG_SOUND_ADD("ymsnd", YM2610, XTAL_8MHz) /* verified on pcb */ MCFG_SOUND_CONFIG(ym2610_config) MCFG_SOUND_ROUTE(0, "lspeaker", 0.25) MCFG_SOUND_ROUTE(0, "rspeaker", 0.25) MCFG_SOUND_ROUTE(1, "lspeaker", 1.0) MCFG_SOUND_ROUTE(2, "rspeaker", 1.0) MACHINE_CONFIG_END static MACHINE_CONFIG_START( aerofgtb, aerofgt_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu",M68000,20000000/2) /* 10 MHz (?) */ MCFG_CPU_PROGRAM_MAP(aerofgtb_map) MCFG_CPU_VBLANK_INT("screen", irq1_line_hold)/* all irq vectors are the same */ MCFG_CPU_ADD("audiocpu",Z80,8000000/2) /* 4 MHz ??? */ MCFG_CPU_PROGRAM_MAP(sound_map) MCFG_CPU_IO_MAP(aerofgt_sound_portmap) /* IRQs are triggered by the YM2610 */ MCFG_MACHINE_START(aerofgt) MCFG_MACHINE_RESET(aerofgt) /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60) MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(500)) /* wrong but improves sprite-background synchronization */ MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) MCFG_SCREEN_SIZE(64*8, 32*8) MCFG_SCREEN_VISIBLE_AREA(0*8+12, 40*8-1+12, 0*8, 28*8-1) MCFG_SCREEN_UPDATE(turbofrc) MCFG_GFXDECODE(aerofgtb) MCFG_PALETTE_LENGTH(1024) MCFG_VIDEO_START(turbofrc) /* sound hardware */ MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") MCFG_SOUND_ADD("ymsnd", YM2610, 8000000) MCFG_SOUND_CONFIG(ym2610_config) MCFG_SOUND_ROUTE(0, "lspeaker", 0.25) MCFG_SOUND_ROUTE(0, "rspeaker", 0.25) MCFG_SOUND_ROUTE(1, "lspeaker", 1.0) MCFG_SOUND_ROUTE(2, "rspeaker", 1.0) MACHINE_CONFIG_END static MACHINE_CONFIG_START( aerofgt, aerofgt_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu",M68000,XTAL_20MHz/2) /* verified on pcb */ MCFG_CPU_PROGRAM_MAP(aerofgt_map) MCFG_CPU_VBLANK_INT("screen", irq1_line_hold)/* all irq vectors are the same */ MCFG_CPU_ADD("audiocpu",Z80,XTAL_20MHz/4) /* 5 MHz verified on pcb */ MCFG_CPU_PROGRAM_MAP(sound_map) MCFG_CPU_IO_MAP(aerofgt_sound_portmap) /* IRQs are triggered by the YM2610 */ MCFG_MACHINE_START(aerofgt) MCFG_MACHINE_RESET(aerofgt) /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(61.31) /* verified on pcb */ MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(400)) /* wrong but improves sprite-background synchronization */ MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) MCFG_SCREEN_SIZE(64*8, 32*8) MCFG_SCREEN_VISIBLE_AREA(0*8, 40*8-1, 0*8, 28*8-1) MCFG_SCREEN_UPDATE(aerofgt) MCFG_GFXDECODE(aerofgt) MCFG_PALETTE_LENGTH(1024) MCFG_VIDEO_START(turbofrc) /* sound hardware */ MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") MCFG_SOUND_ADD("ymsnd", YM2610, XTAL_8MHz) /* verified on pcb */ MCFG_SOUND_CONFIG(ym2610_config) MCFG_SOUND_ROUTE(0, "lspeaker", 0.25) MCFG_SOUND_ROUTE(0, "rspeaker", 0.25) MCFG_SOUND_ROUTE(1, "lspeaker", 1.0) MCFG_SOUND_ROUTE(2, "rspeaker", 1.0) MACHINE_CONFIG_END static MACHINE_CONFIG_START( aerfboot, aerofgt_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu",M68000,20000000/2) /* 10 MHz (?) */ MCFG_CPU_PROGRAM_MAP(aerfboot_map) MCFG_CPU_VBLANK_INT("screen", irq1_line_hold) MCFG_CPU_ADD("audiocpu",Z80,8000000/2) /* 4 MHz ??? */ MCFG_CPU_PROGRAM_MAP(aerfboot_sound_map) MCFG_MACHINE_START(common) MCFG_MACHINE_RESET(common) /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60) MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(500)) /* wrong but improves sprite-background synchronization */ MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) MCFG_SCREEN_SIZE(64*8, 32*8) MCFG_SCREEN_VISIBLE_AREA(0*8+12, 40*8-1+12, 0*8, 28*8-1) MCFG_SCREEN_UPDATE(aerfboot) MCFG_GFXDECODE(aerfboot) MCFG_PALETTE_LENGTH(1024) MCFG_VIDEO_START(turbofrc) /* sound hardware */ MCFG_SPEAKER_STANDARD_MONO("mono") MCFG_OKIM6295_ADD("oki", 1056000, OKIM6295_PIN7_HIGH) // clock frequency & pin 7 not verified MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) MACHINE_CONFIG_END static MACHINE_CONFIG_START( aerfboo2, aerofgt_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu",M68000,20000000/2) /* 10 MHz (?) */ MCFG_CPU_PROGRAM_MAP(aerfboo2_map) MCFG_CPU_VBLANK_INT("screen", irq2_line_hold) MCFG_MACHINE_START(common) MCFG_MACHINE_RESET(common) /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60) MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(500)) /* wrong but improves sprite-background synchronization */ MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) MCFG_SCREEN_SIZE(64*8, 32*8) MCFG_SCREEN_VISIBLE_AREA(0*8+12, 40*8-1+12, 0*8, 28*8-1) MCFG_SCREEN_UPDATE(aerfboo2) MCFG_GFXDECODE(aerfboo2) MCFG_PALETTE_LENGTH(1024) MCFG_VIDEO_START(turbofrc) /* sound hardware */ MCFG_SPEAKER_STANDARD_MONO("mono") MCFG_OKIM6295_ADD("oki", 1056000, OKIM6295_PIN7_HIGH) // clock frequency & pin 7 not verified MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) MACHINE_CONFIG_END static MACHINE_CONFIG_START( wbbc97, aerofgt_state ) /* basic machine hardware */ MCFG_CPU_ADD("maincpu",M68000,20000000/2) /* 10 MHz (?) */ MCFG_CPU_PROGRAM_MAP(wbbc97_map) MCFG_CPU_VBLANK_INT("screen", irq1_line_hold)/* all irq vectors are the same */ MCFG_CPU_ADD("audiocpu",Z80,8000000/2) /* 4 MHz ??? */ MCFG_CPU_PROGRAM_MAP(wbbc97_sound_map) /* IRQs are triggered by the YM3812 */ MCFG_MACHINE_START(common) MCFG_MACHINE_RESET(common) /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60) MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32) MCFG_SCREEN_SIZE(64*8, 64*8) MCFG_SCREEN_VISIBLE_AREA(0*8+14, 44*8-1+4, 0*8, 30*8-1) MCFG_SCREEN_UPDATE(wbbc97) MCFG_GFXDECODE(wbbc97) MCFG_PALETTE_LENGTH(2048) MCFG_VIDEO_START(wbbc97) /* sound hardware */ MCFG_SPEAKER_STANDARD_MONO("mono") MCFG_SOUND_ADD("ymsnd", YM3812, 3579545) MCFG_SOUND_CONFIG(ym3812_config) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) MCFG_OKIM6295_ADD("oki", 1056000, OKIM6295_PIN7_HIGH) // clock frequency & pin 7 not verified MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) MACHINE_CONFIG_END /*************************************************************************** Game driver(s) ***************************************************************************/ ROM_START( pspikes ) ROM_REGION( 0x40000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_WORD_SWAP( "pspikes2.bin", 0x00000, 0x40000, CRC(ec0c070e) SHA1(4ddcc184e835a2f9d15f01aaa03734fd75fe797e) ) ROM_REGION( 0x30000, "audiocpu", 0 ) /* 64k for the audio CPU + banks */ ROM_LOAD( "19", 0x00000, 0x20000, CRC(7e8ed6e5) SHA1(eeb1a1e1989fad8fc1e741928422efaec0598868) ) ROM_RELOAD( 0x10000, 0x20000 ) ROM_REGION( 0x080000, "gfx1", 0 ) ROM_LOAD( "g7h", 0x000000, 0x80000, CRC(74c23c3d) SHA1(c0ac57d1f05c42556f97154ce1a08f465948546b) ) ROM_REGION( 0x100000, "gfx2", 0 ) ROM_LOAD( "g7j", 0x000000, 0x80000, CRC(0b9e4739) SHA1(64b440a5026735aafe1a7cc2806fe0d78f4a6fba) ) ROM_LOAD( "g7l", 0x080000, 0x80000, CRC(943139ff) SHA1(59065f9c3b3a47159c5968df199bdcb1b4f51f29) ) ROM_REGION( 0x40000, "ymsnd.deltat", 0 ) /* sound samples */ ROM_LOAD( "a47", 0x00000, 0x40000, CRC(c6779dfa) SHA1(ea7adefdb0da02755428aac9a6f86c908fc11253) ) ROM_REGION( 0x100000, "ymsnd", 0 ) /* sound samples */ ROM_LOAD( "o5b", 0x000000, 0x100000, CRC(07d6cbac) SHA1(d3d5778dbaca7b6cdceae959d0847d56df7b5cc1) ) ROM_REGION( 0x0200, "plds", 0 ) ROM_LOAD( "peel18cv8.bin", 0x0000, 0x0155, CRC(af5a83c9) SHA1(e8fd64ff71d1c2dff5a0d307ca3543352e903bbe) ) ROM_END ROM_START( pspikesk ) ROM_REGION( 0x40000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_WORD_SWAP( "20", 0x00000, 0x40000, CRC(75cdcee2) SHA1(272a08c46c1d0989f9fbb156e28e6a7ffa9c0a53) ) ROM_REGION( 0x30000, "audiocpu", 0 ) /* 64k for the audio CPU + banks */ ROM_LOAD( "19", 0x00000, 0x20000, CRC(7e8ed6e5) SHA1(eeb1a1e1989fad8fc1e741928422efaec0598868) ) ROM_RELOAD( 0x10000, 0x20000 ) ROM_REGION( 0x080000, "gfx1", 0 ) ROM_LOAD( "g7h", 0x000000, 0x80000, CRC(74c23c3d) SHA1(c0ac57d1f05c42556f97154ce1a08f465948546b) ) ROM_REGION( 0x100000, "gfx2", 0 ) ROM_LOAD( "g7j", 0x000000, 0x80000, CRC(0b9e4739) SHA1(64b440a5026735aafe1a7cc2806fe0d78f4a6fba) ) ROM_LOAD( "g7l", 0x080000, 0x80000, CRC(943139ff) SHA1(59065f9c3b3a47159c5968df199bdcb1b4f51f29) ) ROM_REGION( 0x40000, "ymsnd.deltat", 0 ) /* sound samples */ ROM_LOAD( "a47", 0x00000, 0x40000, CRC(c6779dfa) SHA1(ea7adefdb0da02755428aac9a6f86c908fc11253) ) ROM_REGION( 0x100000, "ymsnd", 0 ) /* sound samples */ ROM_LOAD( "o5b", 0x000000, 0x100000, CRC(07d6cbac) SHA1(d3d5778dbaca7b6cdceae959d0847d56df7b5cc1) ) ROM_REGION( 0x0400, "plds", 0 ) ROM_LOAD( "peel18cv8-1101a-u15.53", 0x0000, 0x0155, CRC(c05e3bea) SHA1(b42e16f1f41ad9796ff3044c850d5331e7a0f91a) ) ROM_LOAD( "peel18cv8-1103-u112.76", 0x0200, 0x0155, CRC(786da44c) SHA1(02fd63083631abeced42714fb58a11b7d463285b) ) ROM_END ROM_START( svolly91 ) ROM_REGION( 0x40000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_WORD_SWAP( "u11.jpn", 0x00000, 0x40000, CRC(ea2e4c82) SHA1(f9cf9122499d9b1e54221fb8b6ef9c12004ca85e) ) ROM_REGION( 0x30000, "audiocpu", 0 ) /* 64k for the audio CPU + banks */ ROM_LOAD( "19", 0x00000, 0x20000, CRC(7e8ed6e5) SHA1(eeb1a1e1989fad8fc1e741928422efaec0598868) ) ROM_RELOAD( 0x10000, 0x20000 ) ROM_REGION( 0x080000, "gfx1", 0 ) ROM_LOAD( "g7h", 0x000000, 0x80000, CRC(74c23c3d) SHA1(c0ac57d1f05c42556f97154ce1a08f465948546b) ) ROM_REGION( 0x100000, "gfx2", 0 ) ROM_LOAD( "g7j", 0x000000, 0x80000, CRC(0b9e4739) SHA1(64b440a5026735aafe1a7cc2806fe0d78f4a6fba) ) ROM_LOAD( "g7l", 0x080000, 0x80000, CRC(943139ff) SHA1(59065f9c3b3a47159c5968df199bdcb1b4f51f29) ) ROM_REGION( 0x40000, "ymsnd.deltat", 0 ) /* sound samples */ ROM_LOAD( "a47", 0x00000, 0x40000, CRC(c6779dfa) SHA1(ea7adefdb0da02755428aac9a6f86c908fc11253) ) ROM_REGION( 0x100000, "ymsnd", 0 ) /* sound samples */ ROM_LOAD( "o5b", 0x000000, 0x100000, CRC(07d6cbac) SHA1(d3d5778dbaca7b6cdceae959d0847d56df7b5cc1) ) ROM_END ROM_START( pspikesb ) ROM_REGION( 0x40000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_BYTE( "2.ic63", 0x00000, 0x20000, CRC(d25e184c) SHA1(89ad275b03d909a7d16d2927df3ddf12301e4c60) ) ROM_LOAD16_BYTE( "3.ic62", 0x00001, 0x20000, CRC(5add1a34) SHA1(e166d5c76f2f087254f2af442f49251a9885f5bc) ) ROM_REGION( 0x080000, "gfx1", ROMREGION_INVERT ) ROM_LOAD( "4.ic122", 0x00000, 0x20000, CRC(ea1c05a7) SHA1(adfdfeac80df287ffa6f469dc38ea94698817cf4) ) ROM_LOAD( "5.ic120", 0x20000, 0x20000, CRC(bfdc60f4) SHA1(2b1893fac2651ac82f5a05b8f891b20c928ced7e) ) ROM_LOAD( "6.ic118", 0x40000, 0x20000, CRC(96a5c235) SHA1(dad4ef9069d3130f719a402737909bb48225b73c) ) ROM_LOAD( "7.ic116", 0x60000, 0x20000, CRC(a7e00b36) SHA1(2b5e85ec02e8893d7d730aad4d690883b1d236cc) ) ROM_REGION( 0x100000, "gfx2", ROMREGION_INVERT ) ROM_LOAD( "8.ic121", 0x00000, 0x40000, CRC(fc096cfc) SHA1(75af810c97361b6f08767949b90c394a7a03f60b) ) ROM_LOAD( "9.ic119", 0x40000, 0x40000, CRC(a45ec985) SHA1(16357f5df7841e11889ac6fced1e2a9288585a29) ) ROM_LOAD( "10.ic117", 0x80000, 0x40000, CRC(3976b372) SHA1(72feec5a6fe7995f39d4b431dbbf25435359b04d) ) ROM_LOAD( "11.ic115", 0xc0000, 0x40000, CRC(f9249937) SHA1(5993e5ab7295ca2fa5c8f4c05ce23731741f4e97) ) ROM_REGION( 0x080000, "user1", 0 ) /* Samples */ ROM_LOAD( "1.ic21", 0x000000, 0x80000, CRC(1b78ed0b) SHA1(886bfd78709c295839dd51c7f5a13f5c452c0ab3) ) /* $00000-$20000 stays the same in all sound banks, */ /* the second half of the bank is what gets switched */ ROM_REGION( 0x100000, "oki", 0 ) /* Samples */ ROM_COPY( "user1", 0x000000, 0x000000, 0x020000) ROM_COPY( "user1", 0x000000, 0x020000, 0x020000) ROM_COPY( "user1", 0x000000, 0x040000, 0x020000) ROM_COPY( "user1", 0x020000, 0x060000, 0x020000) ROM_COPY( "user1", 0x000000, 0x080000, 0x020000) ROM_COPY( "user1", 0x040000, 0x0a0000, 0x020000) ROM_COPY( "user1", 0x000000, 0x0c0000, 0x020000) ROM_COPY( "user1", 0x060000, 0x0e0000, 0x020000) ROM_END /* 1991 Spikes (Italian bootleg) Anno 1991 Produttore N.revisione PX012-30 CPU 1x MC68000P10 (main)(ic1) 1x Z8400BB1 (sound)(ic139) 1x YM2151 (sound)(ic150) 1x OKI M5205 (sound)(ic145) 2x LM324N (sound)(ic152, ic153) 1x TDA2003 (sound)(ic154) 1x oscillator 20.000 (xtal1) 1x oscillator 24.000 (xtal2) 1x blu crystal POE400B (xtal3)(sound) ROMs 2x AM27C512 (1,2)(sound) 4x M27C1001 (3,4,5,6) 2x D27C010 (7,8) (main prg) 2x D27C512 (9,10) (gfx) 4x AM27C020 (11,12,13,14) (gfx) 1x EP910PC (ic7) 2x GAL16V8 (ic147, ic94)(not dumped) Note 1x 28x2 JAMMA edge connector 1x trimmer (volume) 2x 8 switches dip -------------------------------- This is a clone of "Power Spikes" with Italian language. It was rather famous in Italy -------------------------------- This bootleg is very ugly, for example it has 'bad' looking tiles instead of the video system background on the intro screens. This appears to be correct as the same behavior can be seen on the real PCB and in MAME. Sprite, and sound hardware are also modified when compared to the original game */ ROM_START( spikes91 ) ROM_REGION( 0x40000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_BYTE( "7.ic2", 0x00001, 0x20000, CRC(41e38d7e) SHA1(d0c226a8b61a2311c781ed5747d78b8dbddbc7ef) ) ROM_LOAD16_BYTE( "8.ic3", 0x00000, 0x20000, CRC(9c488daa) SHA1(8336fec855786c6cc6a836d86b74e130d60013b7) ) ROM_REGION( 0x080000, "gfx1", 0 ) ROM_LOAD( "3.ic76", 0x00000, 0x20000, CRC(ab451eee) SHA1(439c5f46b4d8e66610417369bd0b2bf5568936cb) ) ROM_LOAD( "4.ic75", 0x20000, 0x20000, CRC(fe857bbd) SHA1(669151cf28f87cc494883dc537881d86887d08b9) ) ROM_LOAD( "5.ic74", 0x40000, 0x20000, CRC(d7fcd97c) SHA1(eb7c8ac111f5916350aae0ee3edc019207fef654) ) ROM_LOAD( "6.ic73", 0x60000, 0x20000, CRC(e6b9107f) SHA1(aaab2f2dfb85ee764091253c9a4ab89bc51d7518) ) ROM_REGION( 0x100000, "gfx2", ROMREGION_INVERT ) ROM_LOAD( "11.ic118", 0x00000, 0x40000, CRC(6e65b4b2) SHA1(5296e8095ec60f79a5cd3f9db829c7d491670282) ) ROM_LOAD( "12.ic119", 0x40000, 0x40000, CRC(60e0d3e0) SHA1(93efc58b03610e7f18ff076ac985428a446454f9) ) ROM_LOAD( "13.ic120", 0x80000, 0x40000, CRC(89213a8c) SHA1(8524d5c14669d9b03f1fe050c4318d4111bc8ef7) ) ROM_LOAD( "14.ic121", 0xc0000, 0x40000, CRC(468cbf5b) SHA1(60fbc2771e40f8de51a51891b8ddcc14e2b1e52c) ) ROM_REGION( 0x020000, "user1", 0 ) /* lookup tables for the sprites */ ROM_LOAD( "10.ic104", 0x00000, 0x10000, CRC(769ade77) SHA1(9cb581d02592c69f37d4b5a902d3515f40915ec4) ) ROM_LOAD( "9.ic103", 0x10000, 0x10000, CRC(201cb748) SHA1(f78d384e4e9c5996a278f76fb4d5f28812a27de5) ) ROM_REGION( 0x20000, "cpu1", 0 ) /* Z80 Sound CPU + M5205 Samples */ ROM_LOAD( "1.ic140", 0x00000, 0x10000, CRC(e3065b1d) SHA1(c4a3a95ba7f43cdf1b0c574f41de06d007ad2bd8) ) ROM_LOAD( "2.ic141", 0x10000, 0x10000, CRC(5dd8bf22) SHA1(d1a12894fe8ca47e47b4a1e911cabf20dd41eda4) ) ROM_REGION( 0x1000, "user2", 0 ) /* ? */ ROM_LOAD( "ep910pc.ic7", 0x00000, 0x884, CRC(e7a3913a) SHA1(6f18f55ecdc94a416baecd16fe7c6698b1ec9d87) ) ROM_END /* this is a bootleg / chinese hack of power spikes */ ROM_START( pspikesc ) ROM_REGION( 0x40000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_BYTE( "27c010.1", 0x00000, 0x20000, CRC(06a6ed73) SHA1(05bffe8766131a8729115244ed499ecdd872962a) ) ROM_LOAD16_BYTE( "27c010.2", 0x00001, 0x20000, CRC(ff31474e) SHA1(f21d44c15aeffd19e8c7fac49d6b9b239bd41c1b) ) ROM_REGION( 0x080000, "gfx1", 0 ) ROM_LOAD( "vlh30.bin", 0x000000, 0x80000, CRC(74c23c3d) SHA1(c0ac57d1f05c42556f97154ce1a08f465948546b) ) ROM_REGION( 0x100000, "gfx2", 0 ) ROM_LOAD( "vlh10-vh118.bin", 0x000000, 0x80000, CRC(0b9e4739) SHA1(64b440a5026735aafe1a7cc2806fe0d78f4a6fba) ) ROM_LOAD( "vlh20-vh102.bin", 0x080000, 0x80000, CRC(943139ff) SHA1(59065f9c3b3a47159c5968df199bdcb1b4f51f29) ) ROM_REGION( 0x080000, "user1", 0 ) /* Samples */ ROM_LOAD( "vlh40.bin", 0x00000, 0x80000, CRC(27166dd4) SHA1(f32ef1735d1a1aeda5df0337e46d65282dd798ad) ) /* $00000-$20000 stays the same in all sound banks, */ /* the second half of the bank is what gets switched */ ROM_REGION( 0x100000, "oki", 0 ) /* Samples */ ROM_COPY( "user1", 0x000000, 0x000000, 0x020000) ROM_COPY( "user1", 0x000000, 0x020000, 0x020000) ROM_COPY( "user1", 0x000000, 0x040000, 0x020000) ROM_COPY( "user1", 0x020000, 0x060000, 0x020000) ROM_COPY( "user1", 0x000000, 0x080000, 0x020000) ROM_COPY( "user1", 0x040000, 0x0a0000, 0x020000) ROM_COPY( "user1", 0x000000, 0x0c0000, 0x020000) ROM_COPY( "user1", 0x060000, 0x0e0000, 0x020000) ROM_END ROM_START( spinlbrk ) ROM_REGION( 0x60000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_BYTE( "ic98", 0x00000, 0x10000, CRC(36c2bf70) SHA1(f627d0e7dad1760bcc95af4a6346050a1a277048) ) ROM_LOAD16_BYTE( "ic104", 0x00001, 0x10000, CRC(34a7e158) SHA1(5884570c1be38bfedffca3fd38089d0ae3391d4f) ) ROM_LOAD16_BYTE( "ic93", 0x20000, 0x10000, CRC(726f4683) SHA1(65aff0548333571d47a96d4bf5a7857f12399cc7) ) ROM_LOAD16_BYTE( "ic94", 0x20001, 0x10000, CRC(c4385e03) SHA1(6683eed812fa8a5430125b14e8647f8e9024bbdd) ) ROM_REGION( 0x30000, "audiocpu", 0 ) /* 64k for the audio CPU + banks */ ROM_LOAD( "ic117", 0x00000, 0x08000, CRC(625ada41) SHA1(2dd0674c68ea382431115c155afbf880f5b9deb2) ) ROM_LOAD( "ic118", 0x10000, 0x10000, CRC(1025f024) SHA1(3e497c74c950d2cd2a0931cf2ae9b0124d11ca6a) ) ROM_REGION( 0x100000, "gfx1", 0 ) ROM_LOAD( "ic15", 0x000000, 0x80000, CRC(e318cf3a) SHA1(d634001a0029566ce7b8fa30075970919eb5f44e) ) ROM_LOAD( "ic9", 0x080000, 0x80000, CRC(e071f674) SHA1(b6d98d7fcc28516d937d8c655d07305515be8a20) ) ROM_REGION( 0x200000, "gfx2", 0 ) ROM_LOAD( "ic17", 0x000000, 0x80000, CRC(a63d5a55) SHA1(a942651a206a2abe4f60f0717e1d5d8e89b993d4) ) ROM_LOAD( "ic11", 0x080000, 0x80000, CRC(7dcc913d) SHA1(527bae5020581d1ac322ea25c8e0994d54bbc051) ) ROM_LOAD( "ic16", 0x100000, 0x80000, CRC(0d84af7f) SHA1(07356ee61c84c4c4ccb49c8dfe8c468990580041) ) //FIRST AND SECOND HALF IDENTICAL ROM_REGION( 0x100000, "gfx3", 0 ) ROM_LOAD( "ic12", 0x000000, 0x80000, CRC(d63fac4e) SHA1(bb96d2e41334d136b9208dbe7e88a45e3bbc6542) ) ROM_LOAD( "ic18", 0x080000, 0x80000, CRC(5a60444b) SHA1(62c418aedd1087dac82dcb44830cce00278103dd) ) ROM_REGION( 0x200000, "gfx4", 0 ) ROM_LOAD( "ic14", 0x000000, 0x80000, CRC(1befd0f3) SHA1(7ab6fb5bf814ef3ae9a306a0d32d1078ee594461) ) ROM_LOAD( "ic20", 0x080000, 0x80000, CRC(c2f84a61) SHA1(1dce538ced54a61c43ed25e1d71b5ac1c8935cc5) ) ROM_LOAD( "ic35", 0x100000, 0x80000, CRC(eba8e1a3) SHA1(976ef30437df9aba6fa6d5cd11728476f34eb05b) ) ROM_LOAD( "ic40", 0x180000, 0x80000, CRC(5ef5aa7e) SHA1(8d4b0f2348c536c6781c8ba25722301673aca289) ) ROM_REGION16_BE( 0x24000, "gfx5", 0 ) /* hardcoded sprite maps */ ROM_LOAD16_BYTE( "ic19", 0x00000, 0x10000, CRC(db24eeaa) SHA1(300dd1ce81dd258b265bc3a64b8542ed152ed2cf) ) ROM_LOAD16_BYTE( "ic13", 0x00001, 0x10000, CRC(97025bf4) SHA1(0519f0c94f3d417bf8ff0124a3a137035a4013dc) ) /* 20000-23fff empty space, filled in vh_startup */ /* no "ymsnd.deltat" */ ROM_REGION( 0x100000, "ymsnd", 0 ) /* sound samples */ ROM_LOAD( "ic166", 0x000000, 0x80000, CRC(6e0d063a) SHA1(313983e69f9625814de033fef7f6e9564694117a) ) ROM_LOAD( "ic163", 0x080000, 0x80000, CRC(e6621dfb) SHA1(85ee77c4720b7eb20ecf293c16b3105c8dcb1114) ) //FIRST AND SECOND HALF IDENTICAL ROM_REGION( 0x0c00, "plds", 0 ) ROM_LOAD( "epl16p8bp.ic133", 0x0000, 0x0107, NO_DUMP ) /* read protected */ ROM_LOAD( "epl16p8bp.ic127", 0x0200, 0x0107, NO_DUMP ) /* read protected */ ROM_LOAD( "epl16p8bp.ic99", 0x0400, 0x0107, NO_DUMP ) /* read protected */ ROM_LOAD( "epl16p8bp.ic100", 0x0600, 0x0107, NO_DUMP ) /* read protected */ ROM_LOAD( "gal16v8a.ic95", 0x0800, 0x0117, NO_DUMP ) /* read protected */ ROM_LOAD( "gal16v8a.ic114", 0x0a00, 0x0117, NO_DUMP ) /* read protected */ ROM_END ROM_START( spinlbrku ) ROM_REGION( 0x60000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_BYTE( "ic98.u5", 0x00000, 0x10000, CRC(3a0f7667) SHA1(55d5fa1a325c17532ed83d231032bdbe9fb84d85) ) ROM_LOAD16_BYTE( "ic104.u6",0x00001, 0x10000, CRC(a0e0af31) SHA1(21f6c3246bb7be2fd926324fd6d041e319a4e214) ) ROM_LOAD16_BYTE( "ic93.u4", 0x20000, 0x10000, CRC(0cf73029) SHA1(e1346b759a41f9eec9536dc90671778582e595b4) ) ROM_LOAD16_BYTE( "ic94.u3", 0x20001, 0x10000, CRC(5cf7c426) SHA1(b201da40c4511d2845004dff72d36adbb8a4fab9) ) ROM_REGION( 0x30000, "audiocpu", 0 ) /* 64k for the audio CPU + banks */ ROM_LOAD( "ic117", 0x00000, 0x08000, CRC(625ada41) SHA1(2dd0674c68ea382431115c155afbf880f5b9deb2) ) ROM_LOAD( "ic118", 0x10000, 0x10000, CRC(1025f024) SHA1(3e497c74c950d2cd2a0931cf2ae9b0124d11ca6a) ) ROM_REGION( 0x100000, "gfx1", 0 ) ROM_LOAD( "ic15", 0x000000, 0x80000, CRC(e318cf3a) SHA1(d634001a0029566ce7b8fa30075970919eb5f44e) ) ROM_LOAD( "ic9", 0x080000, 0x80000, CRC(e071f674) SHA1(b6d98d7fcc28516d937d8c655d07305515be8a20) ) ROM_REGION( 0x200000, "gfx2", 0 ) ROM_LOAD( "ic17", 0x000000, 0x80000, CRC(a63d5a55) SHA1(a942651a206a2abe4f60f0717e1d5d8e89b993d4) ) ROM_LOAD( "ic11", 0x080000, 0x80000, CRC(7dcc913d) SHA1(527bae5020581d1ac322ea25c8e0994d54bbc051) ) ROM_LOAD( "ic16", 0x100000, 0x80000, CRC(0d84af7f) SHA1(07356ee61c84c4c4ccb49c8dfe8c468990580041) ) //FIRST AND SECOND HALF IDENTICAL ROM_REGION( 0x100000, "gfx3", 0 ) ROM_LOAD( "ic12", 0x000000, 0x80000, CRC(d63fac4e) SHA1(bb96d2e41334d136b9208dbe7e88a45e3bbc6542) ) ROM_LOAD( "ic18", 0x080000, 0x80000, CRC(5a60444b) SHA1(62c418aedd1087dac82dcb44830cce00278103dd) ) ROM_REGION( 0x200000, "gfx4", 0 ) ROM_LOAD( "ic14", 0x000000, 0x80000, CRC(1befd0f3) SHA1(7ab6fb5bf814ef3ae9a306a0d32d1078ee594461) ) ROM_LOAD( "ic20", 0x080000, 0x80000, CRC(c2f84a61) SHA1(1dce538ced54a61c43ed25e1d71b5ac1c8935cc5) ) ROM_LOAD( "ic35", 0x100000, 0x80000, CRC(eba8e1a3) SHA1(976ef30437df9aba6fa6d5cd11728476f34eb05b) ) ROM_LOAD( "ic40", 0x180000, 0x80000, CRC(5ef5aa7e) SHA1(8d4b0f2348c536c6781c8ba25722301673aca289) ) ROM_REGION16_BE( 0x24000, "gfx5", 0 ) /* hardcoded sprite maps */ ROM_LOAD16_BYTE( "ic19", 0x00000, 0x10000, CRC(db24eeaa) SHA1(300dd1ce81dd258b265bc3a64b8542ed152ed2cf) ) ROM_LOAD16_BYTE( "ic13", 0x00001, 0x10000, CRC(97025bf4) SHA1(0519f0c94f3d417bf8ff0124a3a137035a4013dc) ) /* 20000-23fff empty space, filled in vh_startup */ /* no "ymsnd.deltat" */ ROM_REGION( 0x100000, "ymsnd", 0 ) /* sound samples */ ROM_LOAD( "ic166", 0x000000, 0x80000, CRC(6e0d063a) SHA1(313983e69f9625814de033fef7f6e9564694117a) ) ROM_LOAD( "ic163", 0x080000, 0x80000, CRC(e6621dfb) SHA1(85ee77c4720b7eb20ecf293c16b3105c8dcb1114) ) //FIRST AND SECOND HALF IDENTICAL ROM_REGION( 0x0c00, "plds", 0 ) ROM_LOAD( "epl16p8bp.ic133", 0x0000, 0x0107, NO_DUMP ) /* read protected */ ROM_LOAD( "epl16p8bp.ic127", 0x0200, 0x0107, NO_DUMP ) /* read protected */ ROM_LOAD( "epl16p8bp.ic99", 0x0400, 0x0107, NO_DUMP ) /* read protected */ ROM_LOAD( "epl16p8bp.ic100", 0x0600, 0x0107, NO_DUMP ) /* read protected */ ROM_LOAD( "gal16v8a.ic95", 0x0800, 0x0117, NO_DUMP ) /* read protected */ ROM_LOAD( "gal16v8a.ic114", 0x0a00, 0x0117, NO_DUMP ) /* read protected */ ROM_END ROM_START( spinlbrkj ) ROM_REGION( 0x60000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_BYTE( "j5", 0x00000, 0x10000, CRC(6a3d690e) SHA1(4ac1985ea0a73b8fc12105ff75121718595dd171) ) ROM_LOAD16_BYTE( "j6", 0x00001, 0x10000, CRC(869593fa) SHA1(5821b011d42113f247bd100cecf140bbfc1e969c) ) ROM_LOAD16_BYTE( "j4", 0x20000, 0x10000, CRC(33e33912) SHA1(d6d052cd8dbedfd254bdf5e82ad770e4bf241777) ) ROM_LOAD16_BYTE( "j3", 0x20001, 0x10000, CRC(16ca61d0) SHA1(5d99a1261251412c3c758af751997fe31026c0d6) ) ROM_REGION( 0x30000, "audiocpu", 0 ) /* 64k for the audio CPU + banks */ ROM_LOAD( "ic117", 0x00000, 0x08000, CRC(625ada41) SHA1(2dd0674c68ea382431115c155afbf880f5b9deb2) ) ROM_LOAD( "ic118", 0x10000, 0x10000, CRC(1025f024) SHA1(3e497c74c950d2cd2a0931cf2ae9b0124d11ca6a) ) ROM_REGION( 0x100000, "gfx1", 0 ) ROM_LOAD( "ic15", 0x000000, 0x80000, CRC(e318cf3a) SHA1(d634001a0029566ce7b8fa30075970919eb5f44e) ) ROM_LOAD( "ic9", 0x080000, 0x80000, CRC(e071f674) SHA1(b6d98d7fcc28516d937d8c655d07305515be8a20) ) ROM_REGION( 0x200000, "gfx2", 0 ) ROM_LOAD( "ic17", 0x000000, 0x80000, CRC(a63d5a55) SHA1(a942651a206a2abe4f60f0717e1d5d8e89b993d4) ) ROM_LOAD( "ic11", 0x080000, 0x80000, CRC(7dcc913d) SHA1(527bae5020581d1ac322ea25c8e0994d54bbc051) ) ROM_LOAD( "ic16", 0x100000, 0x80000, CRC(0d84af7f) SHA1(07356ee61c84c4c4ccb49c8dfe8c468990580041) ) //FIRST AND SECOND HALF IDENTICAL ROM_REGION( 0x100000, "gfx3", 0 ) ROM_LOAD( "ic12", 0x000000, 0x80000, CRC(d63fac4e) SHA1(bb96d2e41334d136b9208dbe7e88a45e3bbc6542) ) ROM_LOAD( "ic18", 0x080000, 0x80000, CRC(5a60444b) SHA1(62c418aedd1087dac82dcb44830cce00278103dd) ) ROM_REGION( 0x200000, "gfx4", 0 ) ROM_LOAD( "ic14", 0x000000, 0x80000, CRC(1befd0f3) SHA1(7ab6fb5bf814ef3ae9a306a0d32d1078ee594461) ) ROM_LOAD( "ic20", 0x080000, 0x80000, CRC(c2f84a61) SHA1(1dce538ced54a61c43ed25e1d71b5ac1c8935cc5) ) ROM_LOAD( "ic35", 0x100000, 0x80000, CRC(eba8e1a3) SHA1(976ef30437df9aba6fa6d5cd11728476f34eb05b) ) ROM_LOAD( "ic40", 0x180000, 0x80000, CRC(5ef5aa7e) SHA1(8d4b0f2348c536c6781c8ba25722301673aca289) ) ROM_REGION16_BE( 0x24000, "gfx5", 0 ) /* hardcoded sprite maps */ ROM_LOAD16_BYTE( "ic19", 0x00000, 0x10000, CRC(db24eeaa) SHA1(300dd1ce81dd258b265bc3a64b8542ed152ed2cf) ) ROM_LOAD16_BYTE( "ic13", 0x00001, 0x10000, CRC(97025bf4) SHA1(0519f0c94f3d417bf8ff0124a3a137035a4013dc) ) /* 20000-23fff empty space, filled in vh_startup */ /* no "ymsnd.deltat" */ ROM_REGION( 0x100000, "ymsnd", 0 ) /* sound samples */ ROM_LOAD( "ic166", 0x000000, 0x80000, CRC(6e0d063a) SHA1(313983e69f9625814de033fef7f6e9564694117a) ) ROM_LOAD( "ic163", 0x080000, 0x80000, CRC(e6621dfb) SHA1(85ee77c4720b7eb20ecf293c16b3105c8dcb1114) ) //FIRST AND SECOND HALF IDENTICAL ROM_REGION( 0x0c00, "plds", 0 ) ROM_LOAD( "epl16p8bp.ic133", 0x0000, 0x0107, NO_DUMP ) /* read protected */ ROM_LOAD( "epl16p8bp.ic127", 0x0200, 0x0107, NO_DUMP ) /* read protected */ ROM_LOAD( "epl16p8bp.ic99", 0x0400, 0x0107, NO_DUMP ) /* read protected */ ROM_LOAD( "epl16p8bp.ic100", 0x0600, 0x0107, NO_DUMP ) /* read protected */ ROM_LOAD( "gal16v8a.ic95", 0x0800, 0x0117, NO_DUMP ) /* read protected */ ROM_LOAD( "gal16v8a.ic114", 0x0a00, 0x0117, NO_DUMP ) /* read protected */ ROM_END ROM_START( karatblz ) ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_WORD_SWAP( "rom2v3", 0x00000, 0x40000, CRC(01f772e1) SHA1(f87f19a82d75839b5671f23ce14218d7b910eabc) ) ROM_LOAD16_WORD_SWAP( "1.u15", 0x40000, 0x40000, CRC(d16ee21b) SHA1(d454cdf22b72a537b9d7ae73deb8136a4f09da47) ) ROM_REGION( 0x30000, "audiocpu", 0 ) /* 64k for the audio CPU + banks */ ROM_LOAD( "5.u92", 0x00000, 0x20000, CRC(97d67510) SHA1(1ffd419e3dec7de1099cd5819b0309f7dd0df80e) ) ROM_RELOAD( 0x10000, 0x20000 ) ROM_REGION( 0x80000, "gfx1", 0 ) ROM_LOAD( "gha.u55", 0x00000, 0x80000, CRC(3e0cea91) SHA1(bab41715f106d364013b64649441d280bc6893cf) ) ROM_REGION( 0x80000, "gfx2", 0 ) ROM_LOAD( "gh9.u61", 0x00000, 0x80000, CRC(5d1676bd) SHA1(6227d489c9c6259a0ac2bef62821fbf94efca8c6) ) ROM_REGION( 0x400000, "gfx3", 0 ) ROM_LOAD( "u42", 0x000000, 0x100000, CRC(65f0da84) SHA1(0bfbc6f4b87583703246704eb9fa13b1b3e6f90e) ) ROM_LOAD( "3.u44", 0x100000, 0x020000, CRC(34bdead2) SHA1(99f9a8cac807fcd599db55d2dc624ed92a3862ef) ) ROM_LOAD( "u43", 0x200000, 0x100000, CRC(7b349e5d) SHA1(8590a328f403e2c697a8d698c08d4adaf01fff62) ) ROM_LOAD( "4.u45", 0x300000, 0x020000, CRC(be4d487d) SHA1(6d19c91d0498c43017219f0c10f4845a51ccfa7f) ) ROM_REGION( 0x100000, "gfx4", 0 ) ROM_LOAD( "u59.ghb", 0x000000, 0x80000, CRC(158c9cde) SHA1(a2c1b404d40e6c2627691f5c7a3f63484bd5d2de) ) ROM_LOAD( "ghd.u60", 0x080000, 0x80000, CRC(73180ae3) SHA1(e4eaf6693826d9e72032d0a0e25938a23ab7d792) ) ROM_REGION( 0x080000, "ymsnd.deltat", 0 ) /* sound samples */ ROM_LOAD( "u105.gh8", 0x000000, 0x080000, CRC(7a68cb1b) SHA1(1bdd0000c2d68019b9e5bf8f7ad84a6ae1af8443) ) ROM_REGION( 0x100000, "ymsnd", 0 ) /* sound samples */ ROM_LOAD( "u104", 0x000000, 0x100000, CRC(5795e884) SHA1(a4178497ad0a1e60ceb87612b218d77b36d2a11b) ) ROM_END ROM_START( karatblzu ) ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_WORD_SWAP( "2.u14", 0x00000, 0x40000, CRC(202e6220) SHA1(2605511a0574cbc39fdf3d8ae27a0aa9b43345fb) ) ROM_LOAD16_WORD_SWAP( "1.u15", 0x40000, 0x40000, CRC(d16ee21b) SHA1(d454cdf22b72a537b9d7ae73deb8136a4f09da47) ) ROM_REGION( 0x30000, "audiocpu", 0 ) /* 64k for the audio CPU + banks */ ROM_LOAD( "5.u92", 0x00000, 0x20000, CRC(97d67510) SHA1(1ffd419e3dec7de1099cd5819b0309f7dd0df80e) ) ROM_RELOAD( 0x10000, 0x20000 ) ROM_REGION( 0x80000, "gfx1", 0 ) ROM_LOAD( "gha.u55", 0x00000, 0x80000, CRC(3e0cea91) SHA1(bab41715f106d364013b64649441d280bc6893cf) ) ROM_REGION( 0x80000, "gfx2", 0 ) ROM_LOAD( "gh9.u61", 0x00000, 0x80000, CRC(5d1676bd) SHA1(6227d489c9c6259a0ac2bef62821fbf94efca8c6) ) ROM_REGION( 0x400000, "gfx3", 0 ) ROM_LOAD( "u42", 0x000000, 0x100000, CRC(65f0da84) SHA1(0bfbc6f4b87583703246704eb9fa13b1b3e6f90e) ) ROM_LOAD( "3.u44", 0x100000, 0x020000, CRC(34bdead2) SHA1(99f9a8cac807fcd599db55d2dc624ed92a3862ef) ) ROM_LOAD( "u43", 0x200000, 0x100000, CRC(7b349e5d) SHA1(8590a328f403e2c697a8d698c08d4adaf01fff62) ) ROM_LOAD( "4.u45", 0x300000, 0x020000, CRC(be4d487d) SHA1(6d19c91d0498c43017219f0c10f4845a51ccfa7f) ) ROM_REGION( 0x100000, "gfx4", 0 ) ROM_LOAD( "u59.ghb", 0x000000, 0x80000, CRC(158c9cde) SHA1(a2c1b404d40e6c2627691f5c7a3f63484bd5d2de) ) ROM_LOAD( "ghd.u60", 0x080000, 0x80000, CRC(73180ae3) SHA1(e4eaf6693826d9e72032d0a0e25938a23ab7d792) ) ROM_REGION( 0x080000, "ymsnd.deltat", 0 ) /* sound samples */ ROM_LOAD( "u105.gh8", 0x000000, 0x080000, CRC(7a68cb1b) SHA1(1bdd0000c2d68019b9e5bf8f7ad84a6ae1af8443) ) ROM_REGION( 0x100000, "ymsnd", 0 ) /* sound samples */ ROM_LOAD( "u104", 0x000000, 0x100000, CRC(5795e884) SHA1(a4178497ad0a1e60ceb87612b218d77b36d2a11b) ) ROM_END ROM_START( karatblzj ) ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_WORD_SWAP( "2tecmo.u14", 0x00000, 0x40000, CRC(57e52654) SHA1(15939d8f7c693b9248f3dd2b2ad5fbae2c19621f) ) ROM_LOAD16_WORD_SWAP( "1.u15", 0x40000, 0x40000, CRC(d16ee21b) SHA1(d454cdf22b72a537b9d7ae73deb8136a4f09da47) ) ROM_REGION( 0x30000, "audiocpu", 0 ) /* 64k for the audio CPU + banks */ ROM_LOAD( "5.u92", 0x00000, 0x20000, CRC(97d67510) SHA1(1ffd419e3dec7de1099cd5819b0309f7dd0df80e) ) ROM_RELOAD( 0x10000, 0x20000 ) ROM_REGION( 0x80000, "gfx1", 0 ) ROM_LOAD( "gha.u55", 0x00000, 0x80000, CRC(3e0cea91) SHA1(bab41715f106d364013b64649441d280bc6893cf) ) ROM_REGION( 0x80000, "gfx2", 0 ) ROM_LOAD( "gh9.u61", 0x00000, 0x80000, CRC(5d1676bd) SHA1(6227d489c9c6259a0ac2bef62821fbf94efca8c6) ) ROM_REGION( 0x400000, "gfx3", 0 ) ROM_LOAD( "u42", 0x000000, 0x100000, CRC(65f0da84) SHA1(0bfbc6f4b87583703246704eb9fa13b1b3e6f90e) ) ROM_LOAD( "3.u44", 0x100000, 0x020000, CRC(34bdead2) SHA1(99f9a8cac807fcd599db55d2dc624ed92a3862ef) ) ROM_LOAD( "u43", 0x200000, 0x100000, CRC(7b349e5d) SHA1(8590a328f403e2c697a8d698c08d4adaf01fff62) ) ROM_LOAD( "4.u45", 0x300000, 0x020000, CRC(be4d487d) SHA1(6d19c91d0498c43017219f0c10f4845a51ccfa7f) ) ROM_REGION( 0x100000, "gfx4", 0 ) ROM_LOAD( "u59.ghb", 0x000000, 0x80000, CRC(158c9cde) SHA1(a2c1b404d40e6c2627691f5c7a3f63484bd5d2de) ) ROM_LOAD( "ghd.u60", 0x080000, 0x80000, CRC(73180ae3) SHA1(e4eaf6693826d9e72032d0a0e25938a23ab7d792) ) ROM_REGION( 0x080000, "ymsnd.deltat", 0 ) /* sound samples */ ROM_LOAD( "u105.gh8", 0x000000, 0x080000, CRC(7a68cb1b) SHA1(1bdd0000c2d68019b9e5bf8f7ad84a6ae1af8443) ) ROM_REGION( 0x100000, "ymsnd", 0 ) /* sound samples */ ROM_LOAD( "u104", 0x000000, 0x100000, CRC(5795e884) SHA1(a4178497ad0a1e60ceb87612b218d77b36d2a11b) ) ROM_END ROM_START( turbofrc ) ROM_REGION( 0xc0000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_WORD_SWAP( "tfrc2.bin", 0x00000, 0x40000, CRC(721300ee) SHA1(79ab32fdfd377592a0bdbd1c4794cfd529a3eb7b) ) ROM_LOAD16_WORD_SWAP( "tfrc1.bin", 0x40000, 0x40000, CRC(6cd5312b) SHA1(57b109fe268fb963e981c91b6d288667a3c9a665) ) ROM_LOAD16_WORD_SWAP( "tfrc3.bin", 0x80000, 0x40000, CRC(63f50557) SHA1(f8dba8c9ba412c9a67457ec31a804c57593ab20b) ) ROM_REGION( 0x30000, "audiocpu", 0 ) /* 64k for the audio CPU + banks */ ROM_LOAD( "tfrcu166.bin", 0x00000, 0x20000, CRC(2ca14a65) SHA1(95f6e7b4fa7ca26872ff472d7e6fb75fd4f281d5) ) ROM_RELOAD( 0x10000, 0x20000 ) ROM_REGION( 0x0a0000, "gfx1", 0 ) ROM_LOAD( "tfrcu94.bin", 0x000000, 0x80000, CRC(baa53978) SHA1(7f103122dd0bf675226ccf309fba73f645e0c79b) ) ROM_LOAD( "tfrcu95.bin", 0x080000, 0x20000, CRC(71a6c573) SHA1(f14ebca676d85fabcde27631145933abc376dd12) ) ROM_REGION( 0x0a0000, "gfx2", 0 ) ROM_LOAD( "tfrcu105.bin", 0x000000, 0x80000, CRC(4de4e59e) SHA1(571396dadb8aac043319cabe24e629210e442d57) ) ROM_LOAD( "tfrcu106.bin", 0x080000, 0x20000, CRC(c6479eb5) SHA1(47a58f082c73bc9dae3970e760ba46478ce6a190) ) ROM_REGION( 0x200000, "gfx3", 0 ) ROM_LOAD( "tfrcu116.bin", 0x000000, 0x80000, CRC(df210f3b) SHA1(990ac43e4a46fee6b929c5b27d317cdadf179b8b) ) ROM_LOAD( "tfrcu118.bin", 0x080000, 0x40000, CRC(f61d1d79) SHA1(2b8e33912c05c26170afd2fced0ff06cb7a097fa) ) ROM_LOAD( "tfrcu117.bin", 0x100000, 0x80000, CRC(f70812fd) SHA1(1964e1134940825211cd4825fdd3f13b8242192d) ) ROM_LOAD( "tfrcu119.bin", 0x180000, 0x40000, CRC(474ea716) SHA1(67753e96fa4fc8cd689a8bddeb60dbde259cacaa) ) ROM_REGION( 0x100000, "gfx4", 0 ) ROM_LOAD( "tfrcu134.bin", 0x000000, 0x80000, CRC(487330a2) SHA1(0bd36c1f5776ba2773f621e9bcb22f56ed1d84ec) ) ROM_LOAD( "tfrcu135.bin", 0x080000, 0x80000, CRC(3a7e5b6d) SHA1(0079ffaa1bf93a5087c75615c78ec596b28c9a32) ) ROM_REGION( 0x20000, "ymsnd.deltat", 0 ) /* sound samples */ ROM_LOAD( "tfrcu180.bin", 0x00000, 0x20000, CRC(39c7c7d5) SHA1(66ee9f7cbc18ffab2c70f77ab0edead6bb018ca9) ) ROM_REGION( 0x100000, "ymsnd", 0 ) /* sound samples */ ROM_LOAD( "tfrcu179.bin", 0x000000, 0x100000, CRC(60ca0333) SHA1(28b94edc98d360386759780ccd1122d43ffa5279) ) ROM_END ROM_START( aerofgt ) ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_WORD_SWAP( "1.u4", 0x00000, 0x80000, CRC(6fdff0a2) SHA1(7cc9529b426091027aa3e23586cb7d162376c0ff) ) ROM_REGION( 0x30000, "audiocpu", 0 ) /* 64k for the audio CPU + banks */ ROM_LOAD( "2.153", 0x00000, 0x20000, CRC(a1ef64ec) SHA1(fa3e434738bf4e742ad68882c1e914100ce0f761) ) ROM_RELOAD( 0x10000, 0x20000 ) ROM_REGION( 0x100000, "gfx1", 0 ) ROM_LOAD( "538a54.124", 0x000000, 0x80000, CRC(4d2c4df2) SHA1(f51c2b3135f0a921ac1a79e63d6878c03cb6254b) ) ROM_LOAD( "1538a54.124", 0x080000, 0x80000, CRC(286d109e) SHA1(3a5f3d2d89cf58f6ef15e4bd3f570b84e8e695b2) ) ROM_REGION( 0x100000, "gfx2", 0 ) ROM_LOAD( "538a53.u9", 0x000000, 0x100000, CRC(630d8e0b) SHA1(5a0c252ccd53c5199a695909d25ecb4e53dc15b9) ) ROM_REGION( 0x080000, "gfx3", 0 ) ROM_LOAD( "534g8f.u18", 0x000000, 0x80000, CRC(76ce0926) SHA1(5ef4cec215d4dd600d8fcd1bd9a4c09081d59e33) ) ROM_REGION( 0x40000, "ymsnd.deltat", 0 ) /* sound samples */ ROM_LOAD( "it-19-01", 0x00000, 0x40000, CRC(6d42723d) SHA1(57c59234e9925430a4c687733682efed06d7eed1) ) ROM_REGION( 0x100000, "ymsnd", 0 ) /* sound samples */ ROM_LOAD( "it-19-06", 0x000000, 0x100000, CRC(cdbbdb1d) SHA1(067c816545f246ff1fd4c821d70df1e7eb47938c) ) ROM_END ROM_START( aerofgtb ) ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_BYTE( "v2", 0x00000, 0x40000, CRC(5c9de9f0) SHA1(93b62c59f0bc052c6fdbd5aae292a7ab2122dfd1) ) ROM_LOAD16_BYTE( "v1", 0x00001, 0x40000, CRC(89c1dcf4) SHA1(41401d63049c140e4254dc791022d85c44271390) ) ROM_REGION( 0x30000, "audiocpu", 0 ) /* 64k for the audio CPU + banks */ ROM_LOAD( "v3", 0x00000, 0x20000, CRC(cbb18cf4) SHA1(7119a7536cf710660ff06d1e7d2879c79ef12b3d) ) ROM_RELOAD( 0x10000, 0x20000 ) ROM_REGION( 0x080000, "gfx1", 0 ) ROM_LOAD( "it-19-03", 0x000000, 0x80000, CRC(85eba1a4) SHA1(5691a95d6359fdab29be0d615066370c2b856c0a) ) ROM_REGION( 0x080000, "gfx2", 0 ) ROM_LOAD( "it-19-02", 0x000000, 0x80000, CRC(4f57f8ba) SHA1(aaad548e9a7490dfd48a975135716225f416b6f6) ) ROM_REGION( 0x100000, "gfx3", 0 ) ROM_LOAD( "it-19-04", 0x000000, 0x80000, CRC(3b329c1f) SHA1(279cb32d69ce1e71f42cfad93d395794a3e92bc6) ) ROM_LOAD( "it-19-05", 0x080000, 0x80000, CRC(02b525af) SHA1(07f23d15938dfbdc4f0977ba1463a06090569026) ) ROM_REGION( 0x080000, "gfx4", 0 ) ROM_LOAD( "g27", 0x000000, 0x40000, CRC(4d89cbc8) SHA1(93f248f3dc1a15c32d14a147b37d5d660d0e4337) ) ROM_LOAD( "g26", 0x040000, 0x40000, CRC(8072c1d2) SHA1(c14634f5f2686cf616f415d9ea4a0c6490054beb) ) ROM_REGION( 0x40000, "ymsnd.deltat", 0 ) /* sound samples */ ROM_LOAD( "it-19-01", 0x00000, 0x40000, CRC(6d42723d) SHA1(57c59234e9925430a4c687733682efed06d7eed1) ) ROM_REGION( 0x100000, "ymsnd", 0 ) /* sound samples */ ROM_LOAD( "it-19-06", 0x000000, 0x100000, CRC(cdbbdb1d) SHA1(067c816545f246ff1fd4c821d70df1e7eb47938c) ) ROM_END ROM_START( aerofgtc ) ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_BYTE( "v2.149", 0x00000, 0x40000, CRC(f187aec6) SHA1(8905af34f114ae22fbfbd3ae115f19280bdd4fb3) ) ROM_LOAD16_BYTE( "v1.111", 0x00001, 0x40000, CRC(9e684b19) SHA1(b5e1e5b74ed9fd223c9315ee2d548e620224c102) ) ROM_REGION( 0x30000, "audiocpu", 0 ) /* 64k for the audio CPU + banks */ ROM_LOAD( "2.153", 0x00000, 0x20000, CRC(a1ef64ec) SHA1(fa3e434738bf4e742ad68882c1e914100ce0f761) ) ROM_RELOAD( 0x10000, 0x20000 ) /* gfx ROMs were missing in this set, I'm using the aerofgtb ones */ ROM_REGION( 0x080000, "gfx1", 0 ) ROM_LOAD( "it-19-03", 0x000000, 0x80000, CRC(85eba1a4) SHA1(5691a95d6359fdab29be0d615066370c2b856c0a) ) ROM_REGION( 0x080000, "gfx2", 0 ) ROM_LOAD( "it-19-02", 0x000000, 0x80000, CRC(4f57f8ba) SHA1(aaad548e9a7490dfd48a975135716225f416b6f6) ) ROM_REGION( 0x100000, "gfx3", 0 ) ROM_LOAD( "it-19-04", 0x000000, 0x80000, CRC(3b329c1f) SHA1(279cb32d69ce1e71f42cfad93d395794a3e92bc6) ) ROM_LOAD( "it-19-05", 0x080000, 0x80000, CRC(02b525af) SHA1(07f23d15938dfbdc4f0977ba1463a06090569026) ) ROM_REGION( 0x080000, "gfx4", 0 ) ROM_LOAD( "g27", 0x000000, 0x40000, CRC(4d89cbc8) SHA1(93f248f3dc1a15c32d14a147b37d5d660d0e4337) ) ROM_LOAD( "g26", 0x040000, 0x40000, CRC(8072c1d2) SHA1(c14634f5f2686cf616f415d9ea4a0c6490054beb) ) ROM_REGION( 0x40000, "ymsnd.deltat", 0 ) /* sound samples */ ROM_LOAD( "it-19-01", 0x00000, 0x40000, CRC(6d42723d) SHA1(57c59234e9925430a4c687733682efed06d7eed1) ) ROM_REGION( 0x100000, "ymsnd", 0 ) /* sound samples */ ROM_LOAD( "it-19-06", 0x000000, 0x100000, CRC(cdbbdb1d) SHA1(067c816545f246ff1fd4c821d70df1e7eb47938c) ) ROM_END ROM_START( sonicwi ) ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_BYTE( "2.149", 0x00000, 0x40000, CRC(3d1b96ba) SHA1(941be323c0cb15e05c92b897984617b05c5cf676) ) ROM_LOAD16_BYTE( "1.111", 0x00001, 0x40000, CRC(a3d09f94) SHA1(a1064d659488878f5303edc2b8636312ab632a83) ) ROM_REGION( 0x30000, "audiocpu", 0 ) /* 64k for the audio CPU + banks */ ROM_LOAD( "2.153", 0x00000, 0x20000, CRC(a1ef64ec) SHA1(fa3e434738bf4e742ad68882c1e914100ce0f761) ) // 3.156 ROM_RELOAD( 0x10000, 0x20000 ) /* gfx ROMs were missing in this set, I'm using the aerofgtb ones */ ROM_REGION( 0x080000, "gfx1", 0 ) ROM_LOAD( "it-19-03", 0x000000, 0x80000, CRC(85eba1a4) SHA1(5691a95d6359fdab29be0d615066370c2b856c0a) ) ROM_REGION( 0x080000, "gfx2", 0 ) ROM_LOAD( "it-19-02", 0x000000, 0x80000, CRC(4f57f8ba) SHA1(aaad548e9a7490dfd48a975135716225f416b6f6) ) ROM_REGION( 0x100000, "gfx3", 0 ) ROM_LOAD( "it-19-04", 0x000000, 0x80000, CRC(3b329c1f) SHA1(279cb32d69ce1e71f42cfad93d395794a3e92bc6) ) ROM_LOAD( "it-19-05", 0x080000, 0x80000, CRC(02b525af) SHA1(07f23d15938dfbdc4f0977ba1463a06090569026) ) ROM_REGION( 0x080000, "gfx4", 0 ) ROM_LOAD( "g27", 0x000000, 0x40000, CRC(4d89cbc8) SHA1(93f248f3dc1a15c32d14a147b37d5d660d0e4337) ) ROM_LOAD( "g26", 0x040000, 0x40000, CRC(8072c1d2) SHA1(c14634f5f2686cf616f415d9ea4a0c6490054beb) ) ROM_REGION( 0x40000, "ymsnd.deltat", 0 ) /* sound samples */ ROM_LOAD( "it-19-01", 0x00000, 0x40000, CRC(6d42723d) SHA1(57c59234e9925430a4c687733682efed06d7eed1) ) ROM_REGION( 0x100000, "ymsnd", 0 ) /* sound samples */ ROM_LOAD( "it-19-06", 0x000000, 0x100000, CRC(cdbbdb1d) SHA1(067c816545f246ff1fd4c821d70df1e7eb47938c) ) ROM_END ROM_START( aerfboot ) ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_BYTE( "afb_ep2.u3", 0x00000, 0x40000, CRC(2bb9edf7) SHA1(cf0a62070fc0803dd8c473c375f6a2d1884ba2bf) ) ROM_LOAD16_BYTE( "afb_ep3.u2", 0x00001, 0x40000, CRC(475d3df3) SHA1(58bde24e9dea2fb0d7ae4f2a574b06bc1a33a13d) ) ROM_REGION( 0x10000, "audiocpu", 0 ) ROM_LOAD( "afb_ep1.u17", 0x0000, 0x8000, CRC(d41b5ab2) SHA1(17d9b999c9af1f332d67e7ce1a2f71fd08178303) ) ROM_REGION( 0x100000, "gfx1", 0 ) ROM_LOAD( "afb_ep9.hh", 0x000000, 0x40000, CRC(41233923) SHA1(20f2849407ac7bd851d2617ad72fd413775da410) ) ROM_LOAD( "afb_ep8.hi", 0x040000, 0x40000, CRC(97607ad3) SHA1(fb72e7ef0c6f7a736e12a9ff71017460f866195e) ) ROM_LOAD( "afb_ep7.hj", 0x080000, 0x40000, CRC(01dc793e) SHA1(dbd9d22d75f5bcef9102667722cebb75574badd3) ) ROM_LOAD( "afb_ep6.hk", 0x0c0000, 0x40000, CRC(cad7862a) SHA1(bfd729b19ff740ad3dc3b645c4f07f71126c0f3e) ) ROM_REGION( 0x100000, "gfx2", 0 ) ROM_LOAD( "afb_ep12.tc", 0x000000, 0x80000, CRC(1e692065) SHA1(a67da59cd65ec492d6e6ab14b1800fd35480a52d) ) ROM_LOAD( "afb_ep10.ta", 0x080000, 0x80000, CRC(e50db1a7) SHA1(952676879fb6a260c56a120b849abfae75f4cf2b) ) ROM_REGION( 0x080000, "gfx3", 0 ) ROM_LOAD( "afb_ep13.td", 0x000000, 0x40000, CRC(1830f70c) SHA1(1759de9b56e4999defc08b2423eff38ec98c4f17) ) ROM_LOAD( "afb_ep11.tb", 0x040000, 0x40000, CRC(6298c0eb) SHA1(ede63849973742c67637eac0ec9cda95ea2ecebc) ) ROM_REGION( 0xc0000, "oki", ROMREGION_ERASEFF ) /* sound samples */ ROM_LOAD( "afb_ep5.u29", 0x000000, 0x20000, CRC(3559609a) SHA1(6f0b633bf74f41487fc98dcdc43a83eb67f3d14c) ) ROM_LOAD( "afb_ep4.u30", 0x040000, 0x80000, CRC(f9652163) SHA1(d8c1fcf44b350cc65378869e4eb188ea232b4948) ) ROM_END ROM_START( aerfboo2 ) ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_BYTE( "p2", 0x00000, 0x40000, CRC(6c4ec09b) SHA1(cdfb8c59ddd6360487fee017d5093636aa52c5c2) ) ROM_LOAD16_BYTE( "p1", 0x00001, 0x40000, CRC(841c513a) SHA1(819e634f0aec29b1863c9cf0118cc33154d10037) ) /* No z80 on this bootleg */ ROM_REGION( 0x80000, "gfx1", 0 ) ROM_LOAD( "g5" , 0x000000, 0x80000, CRC(1c2bd86c) SHA1(f16d7eba967d76faaaeae5101db43141ef9e2eed) ) ROM_REGION( 0x80000, "gfx2", 0 ) ROM_LOAD( "g6" , 0x000000, 0x80000, CRC(b9b1b9b0) SHA1(c25e1ef8b5ecb4b630fb850fe483d7efb0544a6c) ) ROM_REGION( 0x200000, "gfx3", 0 ) ROM_LOAD32_BYTE( "g2" , 0x000000, 0x80000, CRC(84774dbd) SHA1(731b08a62446ff9cf36a43d42d217f73b4e2437c) ) ROM_LOAD32_BYTE( "g1" , 0x000001, 0x80000, CRC(4ab31e69) SHA1(1c6bf5bf4a887cf21da76c6a874f8ff5d3540e3a) ) ROM_LOAD32_BYTE( "g4" , 0x000002, 0x80000, CRC(97725694) SHA1(59316e4be043e0b7111c6777b36bcfd39c899e72) ) ROM_LOAD32_BYTE( "g3" , 0x000003, 0x80000, CRC(7be8cef0) SHA1(b227252fd288e8eb06507397f3ad625465dc1b0a) ) ROM_REGION( 0x100000, "oki", ROMREGION_ERASEFF ) /* sound samples */ ROM_LOAD( "s2" , 0x00000, 0x80000, CRC(2e316ee8) SHA1(a163dddee6d8cfd1286059ee561e3a01df49381b) ) ROM_LOAD( "s1" , 0x80000, 0x80000, CRC(9e09813d) SHA1(582a36b5a46f4d8eaedca22e583b6949535d24a5) ) ROM_END ROM_START( wbbc97 ) ROM_REGION( 0x400000, "maincpu", 0 ) /* 68000 code */ ROM_LOAD16_BYTE( "03.27c040.ur4.rom", 0x000001, 0x80000, CRC(fb4e48fc) SHA1(cffc75766a9b867ab73597156142aa7c70bf6f20) ) ROM_LOAD16_BYTE( "07.27c040.uo4.rom", 0x000000, 0x80000, CRC(87605dcc) SHA1(c5d05e7c581e02f88fd42c65768f5c8632e571a1) ) ROM_LOAD16_BYTE( "04.27c4000.ur4a.rom",0x100001, 0x80000, CRC(2dd6ff07) SHA1(54724f49d4ca1db16a799704a9e023f6ee407fee) ) ROM_LOAD16_BYTE( "08.27c4000.uo4a.rom",0x100000, 0x80000, CRC(1b96ef5b) SHA1(10bfecfc18c65735ddecf830dd72dd855ecf5ee7) ) ROM_LOAD16_BYTE( "05.27c4000.ur4b.rom",0x200001, 0x80000, CRC(84104886) SHA1(807d4441bde6535b780c0c680773804b1268a024) ) ROM_LOAD16_BYTE( "09.27c4000.uo4b.rom",0x200000, 0x80000, CRC(0367043c) SHA1(a5b77730e17b6223a8b465fe36d9447b60eb51ab) ) ROM_LOAD16_BYTE( "06.27c4000.ur4c.rom",0x300001, 0x80000, CRC(b22d11c4) SHA1(15d2ba97704bbcf9d851b650a9c56a6a668cfe63) ) ROM_LOAD16_BYTE( "10.27c040.uo4c.rom", 0x300000, 0x80000, CRC(fe403e8b) SHA1(5f8202792d9ec3e0404637614277c0375c747f7e) ) ROM_REGION( 0x10000, "audiocpu", 0 ) /* z80 code */ ROM_LOAD( "02.27c512.su11.rom", 0x000000, 0x10000, CRC(f03178e9) SHA1(5b0abee03059109a3cdb08a9341091255d5cb6ae) ) ROM_REGION( 0x40000, "gfx1", 0 ) /* GFX */ ROM_LOAD( "15.27c020.uu10.rom", 0x000000, 0x40000, CRC(965bc99e) SHA1(db72121cfbcd6916f46ac5bd3592681eafa4e5da) ) ROM_REGION( 0x100000, "gfx2", 0 ) /* GFX */ ROM_LOAD( "11.27c020.ue12.rom", 0x000000, 0x40000, CRC(a0b23c8a) SHA1(85ccc5dcc891a352b90f0f3d89f6115bc52face6) ) ROM_LOAD( "12.27c020.ue11.rom", 0x040000, 0x40000, CRC(4e529623) SHA1(b3e1e1ba5e05f7e095c0409f199c89b81297cf40) ) ROM_LOAD( "13.27c020.ue10.rom", 0x080000, 0x40000, CRC(3745f892) SHA1(085986dff9639dedaee3bcecca17a6ea7e4a45f4) ) ROM_LOAD( "14.27c020.ue9.rom", 0x0c0000, 0x40000, CRC(2814f4d2) SHA1(bf459b9ff160d0f18d74224d5e0729b8120261e6) ) ROM_REGION( 0x40000, "oki", 0 ) /* OKIM6295 samples */ ROM_LOAD( "01.27c020.su10.rom", 0x000000, 0x40000, CRC(c024e48c) SHA1(d3caedd22044c1645d96301a93f794db3ff77047) ) ROM_REGION( 0x200, "user1", 0 ) /* ??? */ ROM_LOAD( "82s147a.rom", 0x000000, 0x200, CRC(72cec9d2) SHA1(1c6fe6b47fe24bdbebb51d6bef56bf71c9029e72) ) ROM_END GAME( 1990, spinlbrk, 0, spinlbrk, spinlbrk, 0, ROT0, "V-System Co.", "Spinal Breakers (World)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) GAME( 1990, spinlbrku,spinlbrk, spinlbrk, spinlbrku,0, ROT0, "V-System Co.", "Spinal Breakers (US)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) GAME( 1990, spinlbrkj,spinlbrk, spinlbrk, spinlbrk, 0, ROT0, "V-System Co.", "Spinal Breakers (Japan)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) GAME( 1991, pspikes, 0, pspikes, pspikes, 0, ROT0, "Video System Co.", "Power Spikes (World)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) GAME( 1991, pspikesk, pspikes, pspikes, pspikes, 0, ROT0, "Video System Co.", "Power Spikes (Korea)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) GAME( 1991, svolly91, pspikes, pspikes, pspikes, 0, ROT0, "Video System Co.", "Super Volley '91 (Japan)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) GAME( 1991, pspikesb, pspikes, pspikesb, pspikesb, 0, ROT0, "bootleg", "Power Spikes (bootleg)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) GAME( 1991, spikes91, pspikes, spikes91, pspikes, 0, ROT0, "bootleg", "1991 Spikes (Italian bootleg)", GAME_SUPPORTS_SAVE | GAME_NO_SOUND | GAME_NO_COCKTAIL ) GAME( 1991, pspikesc, pspikes, pspikesc, pspikesc, 0, ROT0, "bootleg", "Power Spikes (China)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL | GAME_IMPERFECT_SOUND ) GAME( 1991, karatblz, 0, karatblz, karatblz, 0, ROT0, "Video System Co.", "Karate Blazers (World)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) GAME( 1991, karatblzu,karatblz, karatblz, karatblz, 0, ROT0, "Video System Co.", "Karate Blazers (US)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) GAME( 1991, karatblzj,karatblz, karatblz, karatblz, 0, ROT0, "Video System Co.", "Karate Blazers (Japan)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) GAME( 1991, turbofrc, 0, turbofrc, turbofrc, 0, ROT270, "Video System Co.", "Turbo Force (old revision)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) // there's also an undumped Turbo Force (new revision). Most notable thing in there is the points value of the rocks in level 6 (5.000 versus 500). GAME( 1992, aerofgt, 0, aerofgt, aerofgt, 0, ROT270, "Video System Co.", "Aero Fighters", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) GAME( 1992, aerofgtb, aerofgt, aerofgtb, aerofgtb, 0, ROT270, "Video System Co.", "Aero Fighters (Turbo Force hardware set 1)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) GAME( 1992, aerofgtc, aerofgt, aerofgtb, aerofgtb, 0, ROT270, "Video System Co.", "Aero Fighters (Turbo Force hardware set 2)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) GAME( 1992, sonicwi, aerofgt, aerofgtb, aerofgtb, 0, ROT270, "Video System Co.", "Sonic Wings (Japan)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL ) GAME( 1992, aerfboot, aerofgt, aerfboot, aerofgtb, 0, ROT270, "bootleg", "Aero Fighters (bootleg set 1)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL | GAME_IMPERFECT_SOUND ) GAME( 1992, aerfboo2, aerofgt, aerfboo2, aerofgtb, 0, ROT270, "bootleg", "Aero Fighters (bootleg set 2)", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL | GAME_IMPERFECT_SOUND ) GAME( 1997, wbbc97, 0, wbbc97, wbbc97, 0, ROT0, "Comad", "Beach Festival World Championship 1997", GAME_SUPPORTS_SAVE | GAME_NO_COCKTAIL )
2.109375
2
2024-11-18T18:09:56.852592+00:00
2021-09-07T02:21:21
86bae52664b888f1c45a50372368134bede01746
{ "blob_id": "86bae52664b888f1c45a50372368134bede01746", "branch_name": "refs/heads/main", "committer_date": "2021-09-07T02:21:21", "content_id": "4d7638788b9f6346022269dcd11383feb35a2aad", "detected_licenses": [ "MIT" ], "directory_id": "ae84a3c284d9977294052e033d6077202cf47ed3", "extension": "c", "filename": "blockchain_destroy.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 388271511, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 281, "license": "MIT", "license_type": "permissive", "path": "/blockchain/v0.2/blockchain_destroy.c", "provenance": "stackv2-0003.json.gz:323079", "repo_name": "gefranco/holbertonschool-blockchain", "revision_date": "2021-09-07T02:21:21", "revision_id": "a8f047fa6108d7f0be4f2ddacfda50d85cca6e7f", "snapshot_id": "d8507857cc94071c78df29a1a0e2d84f471dabd8", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/gefranco/holbertonschool-blockchain/a8f047fa6108d7f0be4f2ddacfda50d85cca6e7f/blockchain/v0.2/blockchain_destroy.c", "visit_date": "2023-08-18T15:23:36.073553" }
stackv2
#include "blockchain.h" #include <stdlib.h> /** * blockchain_destroy - deletes the blockchain * @blockchain: blockchain to delete */ void blockchain_destroy(blockchain_t *blockchain) { if (!blockchain) return; llist_destroy(blockchain->chain, 1, NULL); free(blockchain); }
2.078125
2
2024-11-18T18:09:57.133708+00:00
2016-12-13T03:18:15
5d9aac218d909b8d4ae6a79fe563e8b28c264312
{ "blob_id": "5d9aac218d909b8d4ae6a79fe563e8b28c264312", "branch_name": "refs/heads/master", "committer_date": "2016-12-13T03:18:15", "content_id": "308256571aceac0bf77c3dc026a8a4b528c84b21", "detected_licenses": [ "Apache-2.0" ], "directory_id": "c92fcf091d7bd70dc582969200364be87da1b542", "extension": "c", "filename": "hardwaretiming.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 75442337, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1387, "license": "Apache-2.0", "license_type": "permissive", "path": "/hardwaretiming.c", "provenance": "stackv2-0003.json.gz:323466", "repo_name": "grantg5/RaspberryPiPictureFrame", "revision_date": "2016-12-13T03:18:15", "revision_id": "6bc24634b213fbeda8cdf7802ab7de6e571bed74", "snapshot_id": "c5c7fc0a67c85fc399c144c3a5cc1074026a53f9", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/grantg5/RaspberryPiPictureFrame/6bc24634b213fbeda8cdf7802ab7de6e571bed74/hardwaretiming.c", "visit_date": "2021-01-10T18:49:09.133908" }
stackv2
#include <Python.h> #include "system_timer.h" /* * Handles the timing functionality. Given the delay as a parameter * uses the built-in timing functionality to delay. */ static PyObject *hardwaretiming(PyObject *self, PyObject *args) { uint32_t *delay; //Parses the Python arguments coming in. if (!PyArg_ParseTuple(args, "d", &delay)) return NULL; uint32_t delayUs = 1000000 * (*delay); uint32_t current_time = sys_timer[SYS_TIMER_CLO]; // Next, add the delay to the current count. // and, put that into the C0 timer register. uint32_t target_time = current_time + delayUs; sys_timer[SYS_TIMER_C0] = target_time; // Clear the M0 timer register. sys_timer[SYS_TIMER_CS] |= 1 << 1; // Now we spin until the CS register // has a 1 in the 0 position, then we know // our timer has expired. while ((sys_timer[SYS_TIMER_CS] & 1) != 1) { //NOOP } //Python requires a return statement, so retuning the Python equivlent of none. Py_RETURN_NONE; } /* * Defines the functions in this file for Python. */ static PyMethodDef hardwaretiming_funcs[] = { {"hardwaretiming", (PyCFunction)hardwaretiming, METH_VARARGS, NULL}, {NULL} }; /* * Initializes a Python module in this C file. */ void inithardwaretiming(void) { Py_InitModule4("hardwaretiming", hardwaretiming_funcs, "timing"); }
2.484375
2
2024-11-18T18:10:01.319093+00:00
2021-10-03T17:54:47
fb35ada33cbbf9820caee35d15f2faddb80a195e
{ "blob_id": "fb35ada33cbbf9820caee35d15f2faddb80a195e", "branch_name": "refs/heads/master", "committer_date": "2021-10-03T17:54:47", "content_id": "970931e8cee21435cbc4b4710cd6ab8e503940fc", "detected_licenses": [ "MIT" ], "directory_id": "221102cd59e7a272848c68089241c1eaef6a363e", "extension": "h", "filename": "font.h", "fork_events_count": 0, "gha_created_at": "2020-08-02T02:57:12", "gha_event_created_at": "2020-08-02T02:57:13", "gha_language": null, "gha_license_id": "MIT", "github_id": 284379067, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 4671, "license": "MIT", "license_type": "permissive", "path": "/jo_engine/jo/font.h", "provenance": "stackv2-0003.json.gz:323596", "repo_name": "GSansigolo/joengine", "revision_date": "2021-10-03T17:54:47", "revision_id": "1c2d77d73c33e516f33baac93f0e4fb692fe28d7", "snapshot_id": "8c225f000049818a28bb8c8428c37b566aff61b3", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/GSansigolo/joengine/1c2d77d73c33e516f33baac93f0e4fb692fe28d7/jo_engine/jo/font.h", "visit_date": "2021-10-28T16:45:29.903422" }
stackv2
/* ** Jo Sega Saturn Engine ** Copyright (c) 2012-2020, Johannes Fetz ([email protected]) ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in the ** documentation and/or other materials provided with the distribution. ** * Neither the name of the Johannes Fetz nor the ** names of its contributors may be used to endorse or promote products ** derived from this software without specific prior written permission. ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** @file font.h * @author Johannes Fetz * @bug Some glitch when changing scale in jo_font_printf_centered() * @brief Jo Engine Simple ASCII Font & print support */ #ifndef __JO_FONT_H__ # define __JO_FONT_H__ typedef struct { char start_ascii; char end_ascii; char *lookup_table; char spacing; int z_index; } jo_font; /** @brief Print arguments using a specific font (using top-left screen coordinates) * @param F The font (returned by jo_font_load()) * @param X Horizontal location from the left border of the screen * @param Y Vertical location from the top border of the screen * @param S Font scale */ # define jo_font_printf(F, X, Y, S, ...) do {sprintf(__jo_sprintf_buf, __VA_ARGS__); jo_font_print((F), (X), (Y), (S), __jo_sprintf_buf);} while(0) /** @brief Print arguments using a specific font (using screen center coordinates) * @param F The font (returned by jo_font_load()) * @param X Horizontal location from the center of the screen * @param Y Vertical location from the center of the screen * @param S Font scale */ # define jo_font_printf_centered(F, X, Y, S, ...) do {sprintf(__jo_sprintf_buf, __VA_ARGS__); jo_font_print_centered((F), (X), (Y), (S), __jo_sprintf_buf);} while(0) #ifdef JO_COMPILE_WITH_FS_SUPPORT /** @brief Load a font * @param sub_dir Sub directory name (use JO_ROOT_DIR if the file is on the root directory) * @param filename Filename (upper case and shorter as possible like "FONT.TGA") * @param transparent_color Transparent color (see colors.h). Use JO_COLOR_Transparent by default * @param letter_width Letter width (must be a multiple of 8) * @param letter_height Letter height * @param letter_spacing Letter spacing * @param mapping Image pattern : "0123456789ABCDEFGH..." (use \n to go to the next image line) * @return Font object */ jo_font *jo_font_load(const char * const sub_dir, const char * const filename, const jo_color transparent_color, const int letter_width, const int letter_height, const int letter_spacing, const char * const mapping); #endif /** @brief Print a string using a specific font (using top-left screen coordinates) * @param font The font (returned by jo_font_load()) * @param x Horizontal location from the left border of the screen * @param y Vertical location from the top border of the screen * @param scale Font scale * @param str The string */ void jo_font_print(const jo_font * const font, int x, int y, float scale, char * str); /** @brief Print a string using a specific font (using screen center coordinates) * @param font The font (returned by jo_font_load()) * @param x Horizontal location from the center of the screen * @param y Vertical location from the center of the screen * @param scale Font scale * @param str The string */ void jo_font_print_centered(const jo_font * const font, int x, int y, float scale, char * str); #endif /* !__JO_FONT_H__ */ /* ** END OF FILE */
2.375
2
2024-11-18T18:10:01.547617+00:00
2017-04-05T14:40:52
27fb324bc625edc4784ac230f74898e0bae07183
{ "blob_id": "27fb324bc625edc4784ac230f74898e0bae07183", "branch_name": "refs/heads/master", "committer_date": "2017-04-05T14:40:52", "content_id": "9c27ef7cab39a71ba871373fc903ebb1fa7a5a62", "detected_licenses": [ "Apache-2.0" ], "directory_id": "9306b23a3f4e856b0fb9cdce8bc63825e81d8f4e", "extension": "c", "filename": "myCommand.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 87319745, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 4536, "license": "Apache-2.0", "license_type": "permissive", "path": "/src/myCommand.c", "provenance": "stackv2-0003.json.gz:323982", "repo_name": "revolyw/ftp", "revision_date": "2017-04-05T14:40:52", "revision_id": "3a52db06ef0eb24485f81811b5be1bcde171db0b", "snapshot_id": "2ddf4b17b9810d76fd87417e3bcdfef685ed46c7", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/revolyw/ftp/3a52db06ef0eb24485f81811b5be1bcde171db0b/src/myCommand.c", "visit_date": "2021-01-19T03:29:57.012942" }
stackv2
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <stdint.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/types.h> #include <dirent.h> #include "myCommand.h" #include "mySocket.h" int _pwd(char * const path) { memset(path, 0, strlen(path)); if (getcwd(path, 1024) == NULL) { return -1; } // printf("%s\n", path); return 0; } int _cd(char* const dir) { if (chdir(dir) == -1) return -1; return 0; } int _ls(char * const pBuf) { char buf[1024]; int i = 1; memset(pBuf, 0, strlen(pBuf)); //必须 memset(buf, 0, strlen(buf)); DIR *dp; struct dirent *entry; struct stat statbuf; if ((dp = opendir(".")) == NULL) { printf("ls open error!\n"); return -1; } while ((entry = readdir(dp)) != NULL) { i++; lstat(entry->d_name, &statbuf); if (S_ISDIR(statbuf.st_mode)) { if (strcmp(".", entry->d_name) == 0 || strcmp("..", entry->d_name) == 0) continue; strcat(buf, entry->d_name); if (i == 4) { strcat(buf, "\n"); i = 0; } else strcat(buf, "\t"); } else { strcat(buf, entry->d_name); if (i == 4) { strcat(buf, "\n"); i = 0; } else strcat(buf, "\t"); } } closedir(dp); strcpy(pBuf, buf); // printf("%s\n", pBuf); return 0; } int _mkdir(char *dir) { mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO); chmod(dir, 0777); // chown(dir,1,-1); return 0; } int _download(char* dest, char* filename, int skd) { FILE* fp; MsgData msg; int flag = 0; char buffer[FILE_RECV_BUF]; char crtPath[256]; getcwd(crtPath,256); chdir(dest); //打开文件 if ((fp = fopen(filename, "w")) == NULL) { printf("file open error\n"); exit(1); } bzero(buffer, FILE_RECV_BUF); //接受到来自客户端的文件 while (1) { if(FTP_RecvMessage(skd, &msg)==-1) { printf("recv file data error!!\n"); return -1; } flag++; if (msg._msgHead._bytes < 0) { printf("接收错误\n"); exit(1); } int write_len = fwrite(msg._data, sizeof(char), msg._msgHead._bytes, fp); if (write_len > msg._msgHead._bytes) { printf("file write failed\n"); exit(1); } if (msg._msgHead._bytes < FILE_RECV_BUF) break; } if (flag == 0) return -1; chmod(filename,0777); //关闭文件流 fclose(fp); chdir(crtPath); return 0; } int _slipPutParm(char* dest, char* filename, const char* parm) { int index = 0, i = 0; char c = '\0'; if (parm == NULL || !strcmp(parm, "")) return -1; while ((c = *(parm + index)) != '\040') { *(dest + i++) = c; index++; } *(dest + i) = '\0'; i = 0; index++; while ((c = *(parm + index)) != '\0') { *(filename + i++) = c; index++; } *(filename + i) = '\0'; return 0; } int _put(char* dest, char* filename, int skd) { FILE* fp; MsgData msg; char buffer[FILE_RECV_BUF]; //打开指定文件 if ((fp = fopen(filename, "r")) == NULL) { printf("the file was not opened\n"); return -1; } bzero(buffer, FILE_RECV_BUF); printf("正在传输...\n"); int len = 0; //将文件读入缓冲 while (!feof(fp)) { len = fread(buffer, 1, FILE_RECV_BUF, fp); msg._data = buffer; msg._msgHead._bytes = len; if (FTP_SendMessage(skd, &msg) == -1) { printf("send file error\n"); break; } bzero(buffer, FILE_RECV_BUF); } //关闭流 if (fclose(fp)) { printf("file close error\n"); exit(1); } // close(skd);吓尿了!! return 0; } void _rmdir() { DIR* dp = opendir("."); struct dirent* entry = NULL; struct stat st; if (!dp) { perror("opendir"); exit(1); } while ((entry = readdir(dp)) != NULL) { stat(entry->d_name, &st); if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { continue; } if (S_ISDIR(st.st_mode)) { chdir(entry->d_name); _rmdir(); //这个chdir()是为了在删除了子目录后回来还是他的当前目录。用以保证下次循环时正确 chdir(".."); rmdir(entry->d_name); } else { remove(entry->d_name); } } closedir(dp); } int _rmDefDir(char* filename) { char path[512]; getcwd(path, 512); strcat(path, "/"); strcat(path, filename); struct stat info; stat(filename, &info); if (S_ISDIR(info.st_mode)) { char former_path[100]; getcwd(former_path, 100); if (chdir(path) == -1) { fprintf(stderr, "change dir error"); return -1; } printf("inner function %s\n", path); _rmdir(); chdir(former_path); //删除该目录自身 if (rmdir(path) == 0) { return 0; } else { return -1; } } else { if (remove(filename) == 0) { return 0; } else { return -1; } } }
2.46875
2
2024-11-18T18:10:01.620373+00:00
2023-07-21T05:49:53
7c1daffe40b0e0599b719a3956e69f003d1946c5
{ "blob_id": "7c1daffe40b0e0599b719a3956e69f003d1946c5", "branch_name": "refs/heads/master", "committer_date": "2023-07-21T11:16:09", "content_id": "043a7158b8a8ee2201e5981e856fc86b1838b4a0", "detected_licenses": [ "MIT" ], "directory_id": "cd4eb25911d3e3b092aa97aaa7b8fbba6c3a0704", "extension": "c", "filename": "test_zint.c", "fork_events_count": 1, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 26949326, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1131, "license": "MIT", "license_type": "permissive", "path": "/zeta/num.c/test_zint.c", "provenance": "stackv2-0003.json.gz:324111", "repo_name": "liuyang1/test", "revision_date": "2023-07-21T05:49:53", "revision_id": "9a154e0161a1a33baad53f7223ee72e702532001", "snapshot_id": "29bb142982d2ef0d79b71e8fe5f5e0d51ec5258e", "src_encoding": "UTF-8", "star_events_count": 9, "url": "https://raw.githubusercontent.com/liuyang1/test/9a154e0161a1a33baad53f7223ee72e702532001/zeta/num.c/test_zint.c", "visit_date": "2023-08-05T08:56:50.526414" }
stackv2
#include <stdio.h> #include "zint.h" int test_ctor() { //char s[] = "169024356"; char s[] = "16902"; // char s[] = "1690"; zint_t x = zint_ctor_str(s); zint_debug(x); // zint_show(x); return 0; } int test_add_pos() { uint8_t s0[] = {1, 9, 1}; uint8_t s1[] = {9, 4, 8, 9}; zint_t a = {.sign = 1, .s = s0, .n = sizeof(s0) / sizeof(uint8_t)}; zint_t b = {.sign = 1, .s = s1, .n = sizeof(s1) / sizeof(uint8_t)}; zint_t c = zint_add(a, b); zint_show(a), putchar('+'), zint_show(b), putchar('='), zint_show(c), printf("\n"); zint_free(a), zint_free(b), zint_free(c); return 0; } int test_mul() { uint8_t s0[] = {1, 9, 1}; uint8_t s1[] = {9, 4, 8, 9}; zint_t a = {.sign = 1, .s = s0, .n = sizeof(s0) / sizeof(uint8_t)}; zint_t b = {.sign = 1, .s = s1, .n = sizeof(s1) / sizeof(uint8_t)}; zint_t c = zint_mul(a, b); zint_show(a), putchar('*'), zint_show(b), putchar('='), zint_show(c), printf("\n"); zint_free(a), zint_free(b), zint_free(c); return 0; } int main() { test_ctor(); // test_add_pos(); // test_mul(); return 0; }
2.640625
3
2024-11-18T18:10:01.930892+00:00
2023-04-23T21:47:39
cbbeb9d819d6163bb898911ab8ed9222f0f735aa
{ "blob_id": "cbbeb9d819d6163bb898911ab8ed9222f0f735aa", "branch_name": "refs/heads/main", "committer_date": "2023-04-23T21:47:39", "content_id": "df882148ee8f7bc717f285b54ec01ed3f2121fd3", "detected_licenses": [ "MIT" ], "directory_id": "a949ca9f1f0994d4429267f91b186323a17863ad", "extension": "h", "filename": "substitute_primary_key.h", "fork_events_count": 43, "gha_created_at": "2013-03-31T11:45:45", "gha_event_created_at": "2023-04-18T10:06:24", "gha_language": "C++", "gha_license_id": "MIT", "github_id": 9129496, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2241, "license": "MIT", "license_type": "permissive", "path": "/src/substitute_primary_key.h", "provenance": "stackv2-0003.json.gz:324497", "repo_name": "willbryant/kitchen_sync", "revision_date": "2023-04-23T21:47:39", "revision_id": "c2d7aa3dc66b15da4476b2f53519d83c11a62e49", "snapshot_id": "2fff9a7936064ef284bc7b874635f54eea7dc565", "src_encoding": "UTF-8", "star_events_count": 279, "url": "https://raw.githubusercontent.com/willbryant/kitchen_sync/c2d7aa3dc66b15da4476b2f53519d83c11a62e49/src/substitute_primary_key.h", "visit_date": "2023-05-05T14:54:11.160113" }
stackv2
#ifndef SUBSTITUTE_PRIMARY_KEY_H #define SUBSTITUTE_PRIMARY_KEY_H #include <algorithm> struct ColumnNullableOrReplaced { ColumnNullableOrReplaced(const Table &table): table(table) {} inline bool operator()(const Column &column) { return (column.nullable || !column.filter_expression.empty()); } inline bool operator()(size_t column) { return (*this)(table.columns[column]); } const Table &table; }; inline void choose_primary_key_for(Table &table) { // generally we expect most tables to have a real primary key if (table.primary_key_type == PrimaryKeyType::explicit_primary_key) return; ColumnNullableOrReplaced unusable(table); // if not, we want to find a unique key with no nullable columns to act as a surrogate primary key. // we also need to ensure there's no replace: expression applied as the WHERE conditions would // apply to the actual values, which presumably don't match the replaced values. for (const Key &key : table.keys) { if (key.unique() && none_of(key.columns.begin(), key.columns.end(), unusable)) { table.primary_key_columns = key.columns; table.primary_key_type = PrimaryKeyType::suitable_unique_key; return; } } // if there's no unique key usable as a pseudo-primary key, we can try to treat the whole row as // if it were the primary key and group and count to spot duplicates. that's only possible if // there are no nullable columns, though; otherwise we can't query based on key ranges, since the // comparison operators like > and <= will return NULL for any comparisons involving NULL values. if (none_of(table.columns.begin(), table.columns.end(), unusable)) { // ok, no nullable columns, so in principle we can use the whole row as its own primary key. // but tables like that are potentially very slow to query because the database may not have // any good way to sort the rows, and we can't assume that it will happen to serve them up // in the same order at both ends; look for an index with all the columns in it. for (const Key &key : table.keys) { if (key.columns.size() == table.columns.size()) { table.primary_key_columns = key.columns; table.primary_key_type = PrimaryKeyType::entire_row_as_key; return; } } } } #endif
2.859375
3
2024-11-18T18:10:02.058921+00:00
2017-04-24T10:33:31
402ab53f37dbdc0f9e254078f49d584f4ef465c7
{ "blob_id": "402ab53f37dbdc0f9e254078f49d584f4ef465c7", "branch_name": "refs/heads/master", "committer_date": "2017-04-24T10:33:31", "content_id": "bce4c5c9ec15288393b46f22e4f89cefd11f9f9b", "detected_licenses": [ "MIT" ], "directory_id": "506bf68494142e263543d9a2472e4ae3607cbf5e", "extension": "c", "filename": "run.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 89064532, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 582, "license": "MIT", "license_type": "permissive", "path": "/src/run.c", "provenance": "stackv2-0003.json.gz:324625", "repo_name": "PatrickShaw/linux-cli-example", "revision_date": "2017-04-24T10:33:31", "revision_id": "ad9600fadc5e9fc9f5300deb4e2e35c5654335ab", "snapshot_id": "dbaeb9c0fd49bdaa8209ca64f5f138e5041890cf", "src_encoding": "UTF-8", "star_events_count": 1, "url": "https://raw.githubusercontent.com/PatrickShaw/linux-cli-example/ad9600fadc5e9fc9f5300deb4e2e35c5654335ab/src/run.c", "visit_date": "2021-06-16T10:24:49.729720" }
stackv2
/** @author Patrick Shaw ([email protected]) */ #include "run.h" #include "validation.h" int cmdRun(int argc, char* argv[], int commandArgC, char* commandArgs[]) { if(!validateRangeParams(commandArgC, 1, 1, commandArgs[0])) { return 1; } // Max directory path length is 4096 theoretically + run (4 characters) char runCommand[4100]; strcpy(runCommand, ""); char* killArgs[3]; killArgs[0] = commandArgs[1]; // Directory killArgs[1] = runCommand; killArgs[2] = NULL; execv(killArgs[0], passArgs); return 0; }
2.296875
2
2024-11-18T18:10:02.475093+00:00
2016-06-01T22:40:42
16391986753345e717584f9cf981149acd29f859
{ "blob_id": "16391986753345e717584f9cf981149acd29f859", "branch_name": "refs/heads/master", "committer_date": "2016-06-01T22:40:42", "content_id": "2d5c903cbfa2b1f8b813217010caefa0bd927790", "detected_licenses": [ "MIT" ], "directory_id": "324f2c76e4ea64cefdb5572d78a5194726571509", "extension": "c", "filename": "semaphore.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 56721857, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 913, "license": "MIT", "license_type": "permissive", "path": "/xv6_lab2/semaphore.c", "provenance": "stackv2-0003.json.gz:324882", "repo_name": "pgior001/cs-153", "revision_date": "2016-06-01T22:40:42", "revision_id": "e46e05f0ab4f3b926fc48242cf1f38242b55196a", "snapshot_id": "86a5f44102edabb2d3eff3098cc29fbf0fd86c65", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/pgior001/cs-153/e46e05f0ab4f3b926fc48242cf1f38242b55196a/xv6_lab2/semaphore.c", "visit_date": "2021-05-31T15:49:14.155605" }
stackv2
#include "syscall.h" #include "param.h" #include "semaphore.h" //#include "types.h" //#include "user.h" void initSemaphore(semaphore *s, int size) { s->maxHold = size; s->queueSize = 0; lock_init(&s->lock); } void sem_acquire(semaphore* s) { lock_acquire(&s->lock); if(s->maxHold == 0) { if(s->queueSize == 60) { printf(1, "error acuireing semaphore"); exit(); } else { s->queue[s->queueSize] = getpid(); s->queueSize++; lock_release(&s->lock); tsleep(); } } else { s->maxHold--; lock_release(&s->lock); } } void sem_signal(semaphore *s) { lock_acquire(&s->lock); if(s->queueSize == 0) { s->maxHold++; } else { int tmp = s->queue[0]; int i; for(i = 1; i < s->queueSize; ++i) { s->queue[i - 1] = s->queue[i]; } s->queueSize--; twakeup(tmp); } lock_release(&s->lock); }
2.46875
2
2024-11-18T18:10:02.551035+00:00
2023-06-28T18:00:31
8158f404e9bb8d50be24bd2e49b48c5c97b7b9f2
{ "blob_id": "8158f404e9bb8d50be24bd2e49b48c5c97b7b9f2", "branch_name": "refs/heads/main", "committer_date": "2023-06-28T18:00:31", "content_id": "f10d4f07bcf0be91013facf84e0ea17fc5ffc021", "detected_licenses": [ "MIT" ], "directory_id": "34a2f46aeb01db43c4e04b879c1d096ddc34e8ae", "extension": "c", "filename": "parser.c", "fork_events_count": 30, "gha_created_at": "2016-06-05T04:08:48", "gha_event_created_at": "2023-06-28T18:00:35", "gha_language": "Ruby", "gha_license_id": "MIT", "github_id": 60442615, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 23080, "license": "MIT", "license_type": "permissive", "path": "/ext/better_html_ext/parser.c", "provenance": "stackv2-0003.json.gz:325012", "repo_name": "Shopify/better-html", "revision_date": "2023-06-28T18:00:31", "revision_id": "6bed0a92226c9510515705cae100f088f496d029", "snapshot_id": "abd6b9109eebef76c6f6f14de3a9a2a3cdd688de", "src_encoding": "UTF-8", "star_events_count": 253, "url": "https://raw.githubusercontent.com/Shopify/better-html/6bed0a92226c9510515705cae100f088f496d029/ext/better_html_ext/parser.c", "visit_date": "2023-09-04T19:10:52.184780" }
stackv2
#include <ruby.h> #include <ruby/encoding.h> #include "html_tokenizer.h" #include "parser.h" static VALUE cParser = Qnil; static void parser_mark(void *ptr) {} static void parser_free(void *ptr) { struct parser_t *parser = ptr; size_t i; if(parser) { tokenizer_free_members(&parser->tk); if(parser->doc.data) { DBG_PRINT("parser=%p xfree(parser->doc.data) %p", parser, parser->doc.data); xfree(parser->doc.data); parser->doc.data = NULL; } if(parser->errors_count && parser->errors) { for(i=0; i<parser->errors_count; i++) { if(!parser->errors[i].message) continue; DBG_PRINT("parser=%p xfree(parser->errors.messages[%u]) %p", parser, i, parser->errors[i].message); xfree(parser->errors[i].message); parser->errors[i].message = NULL; } DBG_PRINT("parser=%p xfree(parser->errors.messages) %p", parser, parser->errors); xfree(parser->errors); parser->errors = NULL; parser->errors_count = 0; } DBG_PRINT("parser=%p xfree(parser)", parser); xfree(parser); } } static size_t parser_memsize(const void *ptr) { return ptr ? sizeof(struct parser_t) : 0; } const rb_data_type_t ht_parser_data_type = { "ht_parser_data_type", { parser_mark, parser_free, parser_memsize, }, #if defined(RUBY_TYPED_FREE_IMMEDIATELY) NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY #endif }; static VALUE parser_allocate(VALUE klass) { VALUE obj; struct parser_t *parser = NULL; obj = TypedData_Make_Struct(klass, struct parser_t, &ht_parser_data_type, parser); DBG_PRINT("parser=%p allocate", parser); return obj; } static inline void parser_append_ref(struct token_reference_t *dest, struct token_reference_t *src) { if(dest->type == TOKEN_NONE || dest->type != src->type || (dest->start + dest->length) != src->start) { dest->type = src->type; dest->start = src->start; dest->mb_start = src->mb_start; dest->length = src->length; dest->line_number = src->line_number; dest->column_number = src->column_number; } else { dest->type = src->type; dest->length += src->length; } } static void parser_add_error(struct parser_t *parser, const char *message) { REALLOC_N(parser->errors, struct parser_document_error_t, parser->errors_count + 1); parser->errors[parser->errors_count].message = strdup(message); parser->errors[parser->errors_count].pos = parser->tk.scan.cursor; parser->errors[parser->errors_count].mb_pos = parser->tk.scan.mb_cursor; parser->errors[parser->errors_count].line_number = parser->doc.line_number; parser->errors[parser->errors_count].column_number = parser->doc.column_number; parser->errors_count += 1; return; } static int parse_none(struct parser_t *parser, struct token_reference_t *ref) { if(ref->type == TOKEN_TAG_START) { parser->tag.self_closing = 0; parser->context = PARSER_SOLIDUS_OR_TAG_NAME; parser->tag.name.type = TOKEN_NONE; } else if(ref->type == TOKEN_COMMENT_START) { parser->context = PARSER_COMMENT; parser->comment.text.type = TOKEN_NONE; } else if(ref->type == TOKEN_CDATA_START) { parser->context = PARSER_CDATA; parser->cdata.text.type = TOKEN_NONE; } PARSE_DONE; } static int parse_rawtext(struct parser_t *parser, struct token_reference_t *ref) { if(ref->type == TOKEN_TEXT) { parser_append_ref(&parser->rawtext.text, ref); } else { parser->context = PARSER_NONE; parse_none(parser, ref); } PARSE_DONE; } static int parse_comment(struct parser_t *parser, struct token_reference_t *ref) { if(ref->type == TOKEN_COMMENT_END) { parser->context = PARSER_NONE; } else if(ref->type == TOKEN_TEXT) { parser_append_ref(&parser->comment.text, ref); } PARSE_DONE; } static int parse_cdata(struct parser_t *parser, struct token_reference_t *ref) { if(ref->type == TOKEN_CDATA_END) { parser->context = PARSER_NONE; } else if(ref->type == TOKEN_TEXT) { parser_append_ref(&parser->cdata.text, ref); } PARSE_DONE; } static int parse_solidus_or_tag_name(struct parser_t *parser, struct token_reference_t *ref) { if(ref->type == TOKEN_SOLIDUS) { // ignore solidus before tag name parser->context = PARSER_TAG_NAME; } else if(ref->type == TOKEN_TAG_NAME) { parser->context = PARSER_TAG_NAME; PARSE_AGAIN; } else { parser_add_error(parser, "expected '/' or tag name"); parser->context = PARSER_TAG; PARSE_AGAIN; } PARSE_DONE; } static int parse_tag_name(struct parser_t *parser, struct token_reference_t *ref) { if(ref->type == TOKEN_TAG_NAME) { parser_append_ref(&parser->tag.name, ref); } else if(ref->type == TOKEN_WHITESPACE) { parser->context = PARSER_TAG; } else if(ref->type == TOKEN_TAG_END) { parser->context = PARSER_NONE; } else if(ref->type == TOKEN_SOLIDUS) { parser->context = PARSER_TAG; PARSE_AGAIN; } else { // not reachable rb_raise(rb_eArgError, "expected whitespace, '/' or '>' after tag name"); } PARSE_DONE; } static int parse_tag(struct parser_t *parser, struct token_reference_t *ref) { if(ref->type == TOKEN_TAG_END) { parser->context = PARSER_NONE; } else if(ref->type == TOKEN_WHITESPACE) { // ignore whitespaces } else if(ref->type == TOKEN_SOLIDUS) { parser->context = PARSER_TAG_END; } else if(ref->type == TOKEN_ATTRIBUTE_NAME) { parser->context = PARSER_ATTRIBUTE_NAME; parser->attribute.name.type = TOKEN_NONE; parser->attribute.value.type = TOKEN_NONE; parser->attribute.is_quoted = 0; PARSE_AGAIN; } else if(ref->type == TOKEN_ATTRIBUTE_QUOTED_VALUE_START) { parser->context = PARSER_ATTRIBUTE_QUOTED_VALUE; parser->attribute.name.type = TOKEN_NONE; parser->attribute.value.type = TOKEN_NONE; parser->attribute.is_quoted = 1; } else { // unexpected parser_add_error(parser, "expected whitespace, '>', attribute name or value"); } PARSE_DONE; } static int parse_tag_end(struct parser_t *parser, struct token_reference_t *ref) { if(ref->type == TOKEN_TAG_END) { parser->tag.self_closing = 1; parser->context = PARSER_NONE; } else { parser_add_error(parser, "expected '>' after '/'"); parser->context = PARSER_TAG; PARSE_AGAIN; } PARSE_DONE; } static int parse_attribute_name(struct parser_t *parser, struct token_reference_t *ref) { if(ref->type == TOKEN_ATTRIBUTE_NAME) { parser_append_ref(&parser->attribute.name, ref); } else if(ref->type == TOKEN_TAG_END || ref->type == TOKEN_SOLIDUS) { parser->context = PARSER_TAG; PARSE_AGAIN; } else if(ref->type == TOKEN_WHITESPACE) { parser->context = PARSER_ATTRIBUTE_WHITESPACE_OR_EQUAL; PARSE_AGAIN; } else if(ref->type == TOKEN_EQUAL) { parser->context = PARSER_ATTRIBUTE_WHITESPACE_OR_VALUE; } else { parser_add_error(parser, "expected whitespace, '>' or '=' after attribute name"); parser->context = PARSER_TAG; PARSE_AGAIN; } PARSE_DONE; } static int parse_attribute_whitespace_or_equal(struct parser_t *parser, struct token_reference_t *ref) { if(ref->type == TOKEN_WHITESPACE) { // swallow whitespace after attribute name } else if(ref->type == TOKEN_TAG_END || ref->type == TOKEN_SOLIDUS) { parser->context = PARSER_TAG; PARSE_AGAIN; } else if(ref->type == TOKEN_EQUAL) { parser->context = PARSER_ATTRIBUTE_WHITESPACE_OR_VALUE; } else if(ref->type == TOKEN_ATTRIBUTE_NAME) { // start new attribute after whitespace parser->context = PARSER_TAG; PARSE_AGAIN; } else if(ref->type == TOKEN_ATTRIBUTE_QUOTED_VALUE_START) { // start quoted value after whitespace parser->context = PARSER_TAG; PARSE_AGAIN; } else { parser_add_error(parser, "expected '/', '>', \", ' or '=' after attribute name"); parser->context = PARSER_TAG; PARSE_AGAIN; } PARSE_DONE; } static int parse_attribute_whitespace_or_value(struct parser_t *parser, struct token_reference_t *ref) { if(ref->type == TOKEN_WHITESPACE) { // swallow whitespace after equal sign } else if(ref->type == TOKEN_ATTRIBUTE_QUOTED_VALUE_START) { parser->context = PARSER_ATTRIBUTE_QUOTED_VALUE; parser->attribute.is_quoted = 1; } else if(ref->type == TOKEN_ATTRIBUTE_UNQUOTED_VALUE) { parser->context = PARSER_ATTRIBUTE_UNQUOTED_VALUE; PARSE_AGAIN; } else { parser_add_error(parser, "expected attribute value after '='"); parser->context = PARSER_TAG; PARSE_AGAIN; } PARSE_DONE; } static int parse_attribute_quoted_value(struct parser_t *parser, struct token_reference_t *ref) { if(ref->type == TOKEN_ATTRIBUTE_QUOTED_VALUE) { parser_append_ref(&parser->attribute.value, ref); } else if(ref->type == TOKEN_ATTRIBUTE_QUOTED_VALUE_END) { parser->context = PARSER_SPACE_AFTER_ATTRIBUTE; } else { // not reachable rb_raise(rb_eArgError, "expected end-quote after quoted value"); } PARSE_DONE; } static int parse_space_after_attribute(struct parser_t *parser, struct token_reference_t *ref) { if(ref->type == TOKEN_WHITESPACE) { parser->context = PARSER_TAG; } else if(ref->type == TOKEN_TAG_END || ref->type == TOKEN_SOLIDUS) { parser->context = PARSER_TAG; PARSE_AGAIN; } else { parser_add_error(parser, "expected space after attribute value"); parser->context = PARSER_TAG; PARSE_AGAIN; } PARSE_DONE; } static int parse_attribute_unquoted_value(struct parser_t *parser, struct token_reference_t *ref) { if(ref->type == TOKEN_ATTRIBUTE_UNQUOTED_VALUE) { parser_append_ref(&parser->attribute.value, ref); } else if(ref->type == TOKEN_WHITESPACE) { parser->context = PARSER_TAG; } else if(ref->type == TOKEN_TAG_END || ref->type == TOKEN_SOLIDUS) { parser->context = PARSER_TAG; PARSE_AGAIN; } else { // not reachable rb_raise(rb_eArgError, "expected space or end-of-tag after unquoted value"); } PARSE_DONE; } static inline int rawtext_context(struct parser_t *parser) { enum tokenizer_context ctx = parser->tk.context[parser->tk.current_context]; return (ctx == TOKENIZER_RCDATA || ctx == TOKENIZER_RAWTEXT || ctx == TOKENIZER_SCRIPT_DATA || ctx == TOKENIZER_PLAINTEXT); } static void parser_adjust_line_number(struct parser_t *parser, long unsigned int start, long unsigned int length) { rb_encoding *enc = rb_enc_from_index(parser->doc.enc_index); long unsigned int i; const char *buf, *nextlf; for(i = 0; i < length;) { buf = &parser->doc.data[start + i]; nextlf = memchr(buf, '\n', length - i); if(nextlf) { parser->doc.column_number = 0; parser->doc.line_number += 1; i += (nextlf - buf) + 1; } else { parser->doc.column_number += rb_enc_strlen(buf, buf + length - i, enc); break; } } return; } static void parser_tokenize_callback(struct tokenizer_t *tk, enum token_type type, unsigned long int length, void *data) { struct parser_t *parser = (struct parser_t *)data; struct token_reference_t ref = { .type = type, .start = tk->scan.cursor, .mb_start = tk->scan.mb_cursor, .length = length, .line_number = parser->doc.line_number, .column_number = parser->doc.column_number, }; int parse_again = 1; long unsigned int mb_strlen; rb_encoding *enc; while(parse_again) { switch(parser->context) { case PARSER_NONE: if(rawtext_context(parser)) parse_again = parse_rawtext(parser, &ref); else parse_again = parse_none(parser, &ref); break; case PARSER_SOLIDUS_OR_TAG_NAME: parse_again = parse_solidus_or_tag_name(parser, &ref); break; case PARSER_TAG_NAME: parse_again = parse_tag_name(parser, &ref); break; case PARSER_TAG: parse_again = parse_tag(parser, &ref); break; case PARSER_ATTRIBUTE_NAME: parse_again = parse_attribute_name(parser, &ref); break; case PARSER_ATTRIBUTE_WHITESPACE_OR_EQUAL: parse_again = parse_attribute_whitespace_or_equal(parser, &ref); break; case PARSER_ATTRIBUTE_WHITESPACE_OR_VALUE: parse_again = parse_attribute_whitespace_or_value(parser, &ref); break; case PARSER_ATTRIBUTE_QUOTED_VALUE: parse_again = parse_attribute_quoted_value(parser, &ref); break; case PARSER_SPACE_AFTER_ATTRIBUTE: parse_again = parse_space_after_attribute(parser, &ref); break; case PARSER_ATTRIBUTE_UNQUOTED_VALUE: parse_again = parse_attribute_unquoted_value(parser, &ref); break; case PARSER_TAG_END: parse_again = parse_tag_end(parser, &ref); break; case PARSER_CDATA: parse_again = parse_cdata(parser, &ref); break; case PARSER_COMMENT: parse_again = parse_comment(parser, &ref); break; } } if(rb_block_given_p()) { enc = rb_enc_from_index(parser->doc.enc_index); mb_strlen = rb_enc_strlen(parser->doc.data + ref.start, parser->doc.data + ref.start + ref.length, enc); rb_yield_values(5, token_type_to_symbol(type), INT2NUM(ref.mb_start), INT2NUM(ref.mb_start + mb_strlen), INT2NUM(ref.line_number), INT2NUM(ref.column_number)); } parser_adjust_line_number(parser, ref.start, ref.length); return; } static VALUE parser_initialize_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); DBG_PRINT("parser=%p initialize", parser); memset(parser, 0, sizeof(struct parser_t)); parser->context = PARSER_NONE; tokenizer_init(&parser->tk); parser->tk.callback_data = parser; parser->tk.f_callback = parser_tokenize_callback; parser->doc.length = 0; parser->doc.data = NULL; parser->doc.enc_index = 0; parser->doc.mb_length = 0; parser->doc.line_number = 1; parser->doc.column_number = 0; parser->errors_count = 0; parser->errors = NULL; return Qnil; } static int parser_document_append(struct parser_t *parser, const char *string, unsigned long int length) { void *old = parser->doc.data; unsigned long int mb_length; char *buf; rb_encoding *enc = rb_enc_from_index(parser->doc.enc_index); REALLOC_N(parser->doc.data, char, parser->doc.length + length + 1); DBG_PRINT("parser=%p realloc(parser->doc.data) %p -> %p length=%lu", parser, old, parser->doc.data, parser->doc.length + length + 1); buf = parser->doc.data + parser->doc.length; strcpy(buf, string); mb_length = rb_enc_strlen(buf, buf + length, enc); parser->doc.length += length; parser->doc.mb_length += mb_length; return 1; } static VALUE parser_append_data(VALUE self, VALUE source, int is_placeholder) { struct parser_t *parser = NULL; char *string = NULL; long unsigned int length = 0, cursor = 0, mb_cursor = 0; if(NIL_P(source)) return Qnil; Check_Type(source, T_STRING); Parser_Get_Struct(self, parser); string = StringValueCStr(source); length = strlen(string); cursor = parser->doc.length; mb_cursor = parser->doc.mb_length; if(parser->doc.data == NULL) { parser->doc.enc_index = rb_enc_get_index(source); } else if(parser->doc.enc_index != rb_enc_get_index(source)) { rb_raise(rb_eArgError, "cannot append %s string to %s document", rb_enc_name(rb_enc_get(source)), rb_enc_name(rb_enc_from_index(parser->doc.enc_index))); } if(!parser_document_append(parser, string, length)) { // error return Qnil; } if(is_placeholder) { parser_adjust_line_number(parser, cursor, length); } else { parser->tk.scan.cursor = cursor; tokenizer_set_scan_string(&parser->tk, parser->doc.data, parser->doc.length); parser->tk.scan.enc_index = parser->doc.enc_index; parser->tk.scan.mb_cursor = mb_cursor; tokenizer_scan_all(&parser->tk); tokenizer_free_scan_string(&parser->tk); } return Qtrue; } static VALUE parser_parse_method(VALUE self, VALUE source) { return parser_append_data(self, source, 0); } static VALUE parser_append_placeholder_method(VALUE self, VALUE source) { return parser_append_data(self, source, 1); } static VALUE parser_document_method(VALUE self) { struct parser_t *parser = NULL; rb_encoding *enc; Parser_Get_Struct(self, parser); if(!parser->doc.data) return Qnil; enc = rb_enc_from_index(parser->doc.enc_index); return rb_enc_str_new(parser->doc.data, parser->doc.length, enc); } static VALUE parser_document_length_method(VALUE self) { struct parser_t *parser = NULL; rb_encoding *enc; const char *buf; Parser_Get_Struct(self, parser); if(parser->doc.data == NULL) { return ULONG2NUM(0); } else { buf = parser->doc.data; enc = rb_enc_from_index(parser->doc.enc_index); return ULONG2NUM(rb_enc_strlen(buf, buf + parser->doc.length, enc)); } } static VALUE parser_context_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); switch(parser->context) { case PARSER_NONE: return rawtext_context(parser) ? ID2SYM(rb_intern("rawtext")) : ID2SYM(rb_intern("none")); case PARSER_SOLIDUS_OR_TAG_NAME: return ID2SYM(rb_intern("solidus_or_tag_name")); case PARSER_TAG_NAME: return ID2SYM(rb_intern("tag_name")); case PARSER_TAG: return ID2SYM(rb_intern("tag")); case PARSER_ATTRIBUTE_NAME: return ID2SYM(rb_intern("attribute_name")); case PARSER_ATTRIBUTE_WHITESPACE_OR_EQUAL: return ID2SYM(rb_intern("after_attribute_name")); case PARSER_ATTRIBUTE_WHITESPACE_OR_VALUE: return ID2SYM(rb_intern("after_equal")); case PARSER_ATTRIBUTE_QUOTED_VALUE: return ID2SYM(rb_intern("quoted_value")); case PARSER_SPACE_AFTER_ATTRIBUTE: return ID2SYM(rb_intern("space_after_attribute")); case PARSER_ATTRIBUTE_UNQUOTED_VALUE: return ID2SYM(rb_intern("unquoted_value")); case PARSER_TAG_END: return ID2SYM(rb_intern("tag_end")); case PARSER_COMMENT: return ID2SYM(rb_intern("comment")); case PARSER_CDATA: return ID2SYM(rb_intern("cdata")); } return Qnil; } static inline VALUE ref_to_str(struct parser_t *parser, struct token_reference_t *ref) { rb_encoding *enc = rb_enc_from_index(parser->doc.enc_index); if(ref->type == TOKEN_NONE || parser->doc.data == NULL) return Qnil; return rb_enc_str_new(parser->doc.data+ref->start, ref->length, enc); } static VALUE parser_tag_name_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); return ref_to_str(parser, &parser->tag.name); } static VALUE parser_closing_tag_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); return parser->tk.is_closing_tag ? Qtrue : Qfalse; } static VALUE parser_self_closing_tag_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); return parser->tag.self_closing ? Qtrue : Qfalse; } static VALUE parser_attribute_name_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); return ref_to_str(parser, &parser->attribute.name); } static VALUE parser_attribute_value_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); return ref_to_str(parser, &parser->attribute.value); } static VALUE parser_quote_character_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); return parser->attribute.is_quoted ? rb_str_new(&parser->tk.attribute_value_start, 1) : Qnil; } static VALUE parser_attribute_is_quoted_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); return parser->attribute.is_quoted ? Qtrue : Qfalse; } static VALUE parser_comment_text_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); return ref_to_str(parser, &parser->comment.text); } static VALUE parser_cdata_text_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); return ref_to_str(parser, &parser->cdata.text); } static VALUE parser_rawtext_text_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); return ref_to_str(parser, &parser->rawtext.text); } static VALUE parser_errors_count_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); return INT2NUM(parser->errors_count); } static VALUE create_parser_error(struct parser_document_error_t *error) { VALUE module = rb_const_get(rb_cObject, rb_intern("BetterHtml")); VALUE klass = rb_const_get(module, rb_intern("ParserError")); VALUE args[4] = { rb_str_new2(error->message), ULONG2NUM(error->mb_pos), ULONG2NUM(error->line_number), ULONG2NUM(error->column_number), }; return rb_class_new_instance(4, args, klass); } static VALUE parser_errors_method(VALUE self) { struct parser_t *parser = NULL; VALUE list; size_t i; Parser_Get_Struct(self, parser); list = rb_ary_new(); for(i=0; i<parser->errors_count; i++) { if(parser->errors[i].message) { rb_ary_push(list, create_parser_error(&parser->errors[i])); } } return list; } static VALUE parser_line_number_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); return ULONG2NUM(parser->doc.line_number); } static VALUE parser_column_number_method(VALUE self) { struct parser_t *parser = NULL; Parser_Get_Struct(self, parser); return ULONG2NUM(parser->doc.column_number); } void Init_html_tokenizer_parser(VALUE mHtmlTokenizer) { cParser = rb_define_class_under(mHtmlTokenizer, "Parser", rb_cObject); rb_define_alloc_func(cParser, parser_allocate); rb_define_method(cParser, "initialize", parser_initialize_method, 0); rb_define_method(cParser, "document", parser_document_method, 0); rb_define_method(cParser, "document_length", parser_document_length_method, 0); rb_define_method(cParser, "line_number", parser_line_number_method, 0); rb_define_method(cParser, "column_number", parser_column_number_method, 0); rb_define_method(cParser, "parse", parser_parse_method, 1); rb_define_method(cParser, "append_placeholder", parser_append_placeholder_method, 1); rb_define_method(cParser, "context", parser_context_method, 0); rb_define_method(cParser, "tag_name", parser_tag_name_method, 0); rb_define_method(cParser, "closing_tag?", parser_closing_tag_method, 0); rb_define_method(cParser, "self_closing_tag?", parser_self_closing_tag_method, 0); rb_define_method(cParser, "attribute_name", parser_attribute_name_method, 0); rb_define_method(cParser, "attribute_value", parser_attribute_value_method, 0); rb_define_method(cParser, "quote_character", parser_quote_character_method, 0); rb_define_method(cParser, "attribute_quoted?", parser_attribute_is_quoted_method, 0); rb_define_method(cParser, "comment_text", parser_comment_text_method, 0); rb_define_method(cParser, "cdata_text", parser_cdata_text_method, 0); rb_define_method(cParser, "rawtext_text", parser_rawtext_text_method, 0); rb_define_method(cParser, "errors_count", parser_errors_count_method, 0); rb_define_method(cParser, "errors", parser_errors_method, 0); }
2.046875
2
2024-11-18T18:10:02.621818+00:00
2021-08-06T15:10:50
f934083e4565032853e5d8c3d280dc684637892d
{ "blob_id": "f934083e4565032853e5d8c3d280dc684637892d", "branch_name": "refs/heads/main", "committer_date": "2021-08-06T15:10:50", "content_id": "920855e17184dc80a686874ec5d72b2b40f752a6", "detected_licenses": [ "MIT" ], "directory_id": "ff3cfe3a47c36657792bee4bd05800162e710b3f", "extension": "c", "filename": "Looping.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 393403996, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 225, "license": "MIT", "license_type": "permissive", "path": "/pacote download/Exercícios SENAI/Looping.c", "provenance": "stackv2-0003.json.gz:325140", "repo_name": "mauriciommo/Projetos-em-C-SENAI", "revision_date": "2021-08-06T15:10:50", "revision_id": "95981f4642ccc9c74909fc66e32a9d0f6a4e8317", "snapshot_id": "614bc02b21280ba8c61d16bcec1caccaf3d0df57", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/mauriciommo/Projetos-em-C-SENAI/95981f4642ccc9c74909fc66e32a9d0f6a4e8317/pacote download/Exercícios SENAI/Looping.c", "visit_date": "2023-06-30T09:57:27.699470" }
stackv2
#include<stdio.h> #include<stdlib.h> #include<locale.h> int main() { int contador,num = 0; for (contador = 1; contador<=10; contador++) { num++; printf("%i\n",num); } return(21); }
2.09375
2
2024-11-18T18:10:02.691755+00:00
2015-11-10T07:52:19
8ca973631eebaaa9ffbf717233e7bb3b61aa56cc
{ "blob_id": "8ca973631eebaaa9ffbf717233e7bb3b61aa56cc", "branch_name": "refs/heads/master", "committer_date": "2015-11-10T07:52:19", "content_id": "7b9a1a33551bbefc800dbf30fc91fba5046a6d81", "detected_licenses": [ "BSD-3-Clause" ], "directory_id": "86157e9703f229f486bc33471ff7925c00d4dd72", "extension": "c", "filename": "zencode.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": null, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 3261, "license": "BSD-3-Clause", "license_type": "permissive", "path": "/libsrc/zencode.c", "provenance": "stackv2-0003.json.gz:325268", "repo_name": "zboszor/libphpscrew", "revision_date": "2015-11-10T07:52:19", "revision_id": "df66d1c8cdea548880f61c60057cf7585aeda73b", "snapshot_id": "34995cba518e97c76d67b94ffacdc52c92527ceb", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/zboszor/libphpscrew/df66d1c8cdea548880f61c60057cf7585aeda73b/libsrc/zencode.c", "visit_date": "2021-05-31T00:50:29.237562" }
stackv2
/* * Modified copy of zencode.c from PHP Screw 1.5. License is as below. * * php_screw * (C) 2004, Kunimasa Noda <[email protected]> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <stdio.h> #include <stdlib.h> #include <zlib.h> #include <string.h> #include "php-screw-internal.h" #define OUTBUFSIZ 100000 static char *zcodecom(int mode, char *inbuf, int inbuf_len, int *resultbuf_len) { z_stream z; int count, status; char *outbuf; char *resultbuf; int total_count = 0; outbuf = malloc(OUTBUFSIZ); z.zalloc = Z_NULL; z.zfree = Z_NULL; z.opaque = Z_NULL; z.next_in = Z_NULL; z.avail_in = 0; if (mode == 0) { deflateInit(&z, 1); } else { inflateInit(&z); } z.next_out = outbuf; z.avail_out = OUTBUFSIZ; z.next_in = inbuf; z.avail_in = inbuf_len; resultbuf = malloc(OUTBUFSIZ); while (1) { if (mode == 0) { status = deflate(&z, Z_FINISH); } else { status = inflate(&z, Z_NO_FLUSH); } if (status == Z_STREAM_END) break; if (status != Z_OK) { if (mode == 0) { deflateEnd(&z); } else { inflateEnd(&z); } *resultbuf_len = 0; return(resultbuf); } if (z.avail_out == 0) { resultbuf = realloc(resultbuf, total_count + OUTBUFSIZ); memcpy(resultbuf + total_count, outbuf, OUTBUFSIZ); total_count += OUTBUFSIZ; z.next_out = outbuf; z.avail_out = OUTBUFSIZ; } } if ((count = OUTBUFSIZ - z.avail_out) != 0) { resultbuf = realloc(resultbuf, total_count + OUTBUFSIZ); memcpy(resultbuf + total_count, outbuf, count); total_count += count; } if (mode == 0) { deflateEnd(&z); } else { inflateEnd(&z); } free(outbuf); *resultbuf_len = total_count; return resultbuf; } char *zencode(char *inbuf, int inbuf_len, int *resultbuf_len) { return zcodecom(0, inbuf, inbuf_len, resultbuf_len); } char *zdecode(char *inbuf, int inbuf_len, int *resultbuf_len) { return zcodecom(1, inbuf, inbuf_len, resultbuf_len); }
2.234375
2
2024-11-18T18:10:03.160269+00:00
2014-10-24T14:18:47
cae30e812cbf414679a5f7fa0a9f505945460059
{ "blob_id": "cae30e812cbf414679a5f7fa0a9f505945460059", "branch_name": "refs/heads/master", "committer_date": "2014-10-24T14:18:47", "content_id": "a5297b423b3bbd8e9a8da00b358d814829f08843", "detected_licenses": [ "BSD-3-Clause" ], "directory_id": "830d19615851513ca8b563e2653e8a0d3a1d4074", "extension": "h", "filename": "spinlock_types.h", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": null, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1065, "license": "BSD-3-Clause", "license_type": "permissive", "path": "/drivers/virtio/include/linux/spinlock_types.h", "provenance": "stackv2-0003.json.gz:325396", "repo_name": "objectkuan/osv-dde", "revision_date": "2014-10-24T14:18:47", "revision_id": "295ade6050f3860b7863323b078473e0d11bf323", "snapshot_id": "da950b2a321aaa125c8877a6c63bf4edc9c0ccc3", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/objectkuan/osv-dde/295ade6050f3860b7863323b078473e0d11bf323/drivers/virtio/include/linux/spinlock_types.h", "visit_date": "2021-01-01T05:47:28.018482" }
stackv2
#ifndef __LINUX_SPINLOCK_TYPES_H__ #define __LINUX_SPINLOCK_TYPES_H__ /*0*/ struct raw_spinlock; /*0*/ #include <linux/spinlock_types.h> /*0*/ struct arch_spinlock; /*13*/ #include <asm/spinlock_types.h> /*18*/ #include <linux/lockdep.h> /**32**/ struct raw_spinlock { arch_spinlock_t raw_lock; }; /*32*/ typedef struct raw_spinlock raw_spinlock_t; /*41*/ #define SPIN_DEP_MAP_INIT(lockname) /*50*/ #define SPIN_DEBUG_INIT(lockname) /*53*/ #define __RAW_SPIN_LOCK_INITIALIZER(lockname) { .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, SPIN_DEBUG_INIT(lockname) SPIN_DEP_MAP_INIT(lockname) } /*59*/ #define __RAW_SPIN_LOCK_UNLOCKED(lockname) (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname) /*76*/ typedef struct spinlock spinlock_t; /*76*/ struct spinlock { union { struct raw_spinlock rlock; }; }; /*78*/ #define __SPIN_LOCK_INITIALIZER(lockname) { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } } /*81*/ #define __SPIN_LOCK_UNLOCKED(lockname) __SPIN_LOCK_INITIALIZER(lockname) /*84*/ #define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x) #endif
2.0625
2
2024-11-18T18:10:03.218188+00:00
2023-08-18T12:54:06
8b7630a88a973936045c2882adae94b179e31caa
{ "blob_id": "8b7630a88a973936045c2882adae94b179e31caa", "branch_name": "refs/heads/master", "committer_date": "2023-08-18T12:54:06", "content_id": "9a75d8f7361fc9c015b523dcb8d465f0bc3c96de", "detected_licenses": [ "MIT" ], "directory_id": "22446075c2e71ef96b4a4777fe966714ac96b405", "extension": "c", "filename": "main.c", "fork_events_count": 68, "gha_created_at": "2020-09-30T10:18:15", "gha_event_created_at": "2023-09-08T12:56:11", "gha_language": "C", "gha_license_id": "NOASSERTION", "github_id": 299882138, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2537, "license": "MIT", "license_type": "permissive", "path": "/clicks/brushless2/example/main.c", "provenance": "stackv2-0003.json.gz:325524", "repo_name": "MikroElektronika/mikrosdk_click_v2", "revision_date": "2023-08-18T12:54:06", "revision_id": "49ab937390bef126beb7b703d5345fa8cd6e3555", "snapshot_id": "2cc2987869649a304763b0f9d27c920d42a11c16", "src_encoding": "UTF-8", "star_events_count": 77, "url": "https://raw.githubusercontent.com/MikroElektronika/mikrosdk_click_v2/49ab937390bef126beb7b703d5345fa8cd6e3555/clicks/brushless2/example/main.c", "visit_date": "2023-08-21T22:15:09.036635" }
stackv2
/*! * @file * @brief Brushless2 Click example * * # Description * This application controlled speed motor. * * The demo application is composed of two sections : * * ## Application Init * Initialization driver enable's - GPIO, PWM initialization * * ## Application Task * This is a example which demonstrates the use of Brushless 2 Click board. * Brushless 2 Click communicates with register via PWM interface. * Results are being sent to the Usart Terminal where you can track their changes. * * @author Nikola Peric * */ // ------------------------------------------------------------------- INCLUDES #include "board.h" #include "log.h" #include "brushless2.h" // ------------------------------------------------------------------ VARIABLES static brushless2_t brushless2; static log_t logger; // ------------------------------------------------------ APPLICATION FUNCTIONS void application_init ( void ) { log_cfg_t log_cfg; brushless2_cfg_t cfg; /** * Logger initialization. * Default baud rate: 115200 * Default log level: LOG_LEVEL_DEBUG * @note If USB_UART_RX and USB_UART_TX * are defined as HAL_PIN_NC, you will * need to define them manually for log to work. * See @b LOG_MAP_USB_UART macro definition for detailed explanation. */ LOG_MAP_USB_UART( log_cfg ); log_init( &logger, &log_cfg ); log_info( &logger, "---- Application Init ----" ); // Click initialization. brushless2_cfg_setup( &cfg ); BRUSHLESS2_MAP_MIKROBUS( cfg, MIKROBUS_1 ); brushless2_init( &brushless2, &cfg ); log_printf( &logger, "---------------------- \r\n" ); brushless2_set_duty_cycle ( &brushless2, 0.0 ); brushless2_pwm_start ( &brushless2 ); Delay_ms( 500 ); log_info( &logger, "---- Application Task ----" ); } void application_task ( void ) { static int8_t duty_cnt = 1; static int8_t duty_inc = 1; float duty = duty_cnt / 10.0; brushless2_set_duty_cycle ( &brushless2, duty ); brushless2_clockwise ( &brushless2 ); log_printf( &logger, "> Duty: %d%%\r\n", ( uint16_t )( duty_cnt * 10 ) ); Delay_ms( 500 ); if ( 10 == duty_cnt ) { duty_inc = -1; } else if ( 0 == duty_cnt ) { duty_inc = 1; } duty_cnt += duty_inc; } void main ( void ) { application_init( ); for ( ; ; ) { application_task( ); } } // ------------------------------------------------------------------------ END
2.609375
3
2024-11-18T18:10:03.658890+00:00
2020-09-28T19:44:06
59ebcabc8688692dcba840d43535ba59cc6b648b
{ "blob_id": "59ebcabc8688692dcba840d43535ba59cc6b648b", "branch_name": "refs/heads/master", "committer_date": "2020-09-28T19:44:06", "content_id": "7396d8d11db423f471b23eeae11cfe76b63d8e0f", "detected_licenses": [ "MIT" ], "directory_id": "be11d397b3dcb4720775eafdd0f402670b86de05", "extension": "c", "filename": "mac_address.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 227171224, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 701, "license": "MIT", "license_type": "permissive", "path": "/main/mac_address.c", "provenance": "stackv2-0003.json.gz:326037", "repo_name": "rrooding/rc-excavator", "revision_date": "2020-09-28T19:44:06", "revision_id": "4a41a8a9f2a081b322b0d2aadfc7868e9f2095fa", "snapshot_id": "467cb95d1a02d736d0448840ebde1274048ddc53", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/rrooding/rc-excavator/4a41a8a9f2a081b322b0d2aadfc7868e9f2095fa/main/mac_address.c", "visit_date": "2020-09-30T01:51:44.647666" }
stackv2
#include "esp_log.h" #include "esp_system.h" #define TAG "EX_MAC" void mac_address_print_bt_addr() { uint8_t mac_addr[8] = {0}; esp_err_t ret = ESP_OK; ret = esp_read_mac(mac_addr, ESP_MAC_BT); if (ret != ESP_OK) { ESP_LOGE(TAG, "Failed to get BT MAC address. (%s)", esp_err_to_name(ret)); ESP_LOGE(TAG, "Aborting"); abort(); } char mac_str[18]; snprintf(mac_str, sizeof(mac_str), "%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); ESP_LOGI(TAG, "Bluetooth MAC address: %s", mac_str); } esp_err_t mac_address_set(uint8_t *mac_address) { return esp_base_mac_addr_set(mac_address); }
2.25
2
2024-11-18T18:10:03.793165+00:00
2021-03-24T10:52:19
8098f65a3ffcff725e22e4ca92ba86de519b8402
{ "blob_id": "8098f65a3ffcff725e22e4ca92ba86de519b8402", "branch_name": "refs/heads/main", "committer_date": "2021-03-24T10:52:19", "content_id": "71bcf1feb226df8f3bef3bb5e4ac8257c801855c", "detected_licenses": [ "MIT" ], "directory_id": "a86071e9d92150f5a91d17dd4b65ece6d450825a", "extension": "c", "filename": "mouse.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 351043833, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 894, "license": "MIT", "license_type": "permissive", "path": "/src/mouse.c", "provenance": "stackv2-0003.json.gz:326294", "repo_name": "hubenchang0515/X11Test", "revision_date": "2021-03-24T10:52:19", "revision_id": "51e4fdc8c3cca8dfe1b7ee486bbf56b9872ea4cf", "snapshot_id": "f25090574eab8f3f68eab309d0101db7f2bb175c", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/hubenchang0515/X11Test/51e4fdc8c3cca8dfe1b7ee486bbf56b9872ea4cf/src/mouse.c", "visit_date": "2023-04-03T16:08:20.773633" }
stackv2
#include "log.h" #include "mouse.h" #include "connection.h" #include "window.h" // Lua int x11_test_lua_mouse_move_to(lua_State* L) { x11_test_connection_t* conn = luaL_checkudata(L, 1, X11_TEST_CONNECTION_TYPE_NAME); uint16_t x = luaL_checkinteger(L, 2); uint16_t y = luaL_checkinteger(L, 3); x11_test_mouse_move(conn->c, conn->root, x, y); return 0; } int x11_test_lua_mouse_move(lua_State* L) { x11_test_connection_t* conn = luaL_checkudata(L, 1, X11_TEST_CONNECTION_TYPE_NAME); uint16_t x = luaL_checkinteger(L, 2); uint16_t y = luaL_checkinteger(L, 3); x11_test_mouse_move(conn->c, XCB_NONE, x, y); return 0; } // C void x11_test_mouse_move(xcb_connection_t* c, xcb_window_t relative, uint16_t x, uint16_t y) { X11_TEST_LOG_DEBUG("mouse move to %u %u", x, y); xcb_warp_pointer(c, XCB_NONE, relative, 0, 0, 0, 0, x, y); xcb_flush(c); }
2.03125
2
2024-11-18T18:10:04.186511+00:00
2020-04-21T21:55:38
74c24c4f9481b9769b3d014d899c31eec4dc3f16
{ "blob_id": "74c24c4f9481b9769b3d014d899c31eec4dc3f16", "branch_name": "refs/heads/master", "committer_date": "2020-04-21T21:55:38", "content_id": "e8bb25793f6337685c32b896d35507207ba31f92", "detected_licenses": [ "MIT" ], "directory_id": "7925d9ebc08f24ab7387fe417157398f3fbc497f", "extension": "c", "filename": "chords.c", "fork_events_count": 0, "gha_created_at": "2020-04-21T21:55:10", "gha_event_created_at": "2020-04-21T21:55:11", "gha_language": null, "gha_license_id": null, "github_id": 257724863, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2764, "license": "MIT", "license_type": "permissive", "path": "/firmware/chords-integration.cydsn/chords.c", "provenance": "stackv2-0003.json.gz:326551", "repo_name": "Vivien-A-R/open-storm-workshop", "revision_date": "2020-04-21T21:55:38", "revision_id": "09e1aa96f5a6196eb95ca6c200876266f77ff48e", "snapshot_id": "017dcaebda6230c9b66150a0c56f23b80f28b876", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/Vivien-A-R/open-storm-workshop/09e1aa96f5a6196eb95ca6c200876266f77ff48e/firmware/chords-integration.cydsn/chords.c", "visit_date": "2022-04-23T02:02:14.371469" }
stackv2
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include "modem.h" #include "extern.h" int format_chords_url(char *send_str, char *chords_endpoint, int chords_port, int instrument_id, char *chords_write_key, uint8 write_key_enabled, uint8 is_test){ // Construct chords url sprintf(send_str, "%s%s", send_str, "GET /measurements/url_create?"); // Specify instrument id sprintf(send_str, "%sinstrument_id=%d", send_str, instrument_id); // Add depth and battery voltage measurements sprintf(send_str, "%s&depth_analog=%d", send_str, depth_analog); sprintf(send_str, "%s&depth_digital=%d", send_str, depth_digital); sprintf(send_str, "%s&v_bat=%f", send_str, v_bat); // Add key if needed if (write_key_enabled){ sprintf(send_str, "%s&key=%s", send_str, chords_write_key); } // If this is a test measurement, append "&test" if (is_test){ sprintf(send_str, "%s&test", send_str); } // Construct the full HTTP request // It should look like this: // GET /measurements/url_create?instrument_id=... HTTP/1.1\r\n // Host: your.chords.endpoint.here\r\n // Connection: Close\r\n\r\n // Where "\r\n" is a carriage-return + line feed (essentially a line break) sprintf(send_str, "%s HTTP/1.1\r\n", send_str); sprintf(send_str,"%s%s%s%s%d%s%s", send_str, "Host: ", chords_endpoint, ":", chords_port, "\r\n", "Connection: Close\r\n\r\n"); return 1u; } int format_chords_url_general(char *send_str, char *labels[], float readings[], int nvars, char *chords_endpoint, int chords_port, int instrument_id, char *chords_write_key, uint8 write_key_enabled, uint8 is_test){ int i = 0; // iterator through labels and readings // Construct chords url sprintf(send_str, "%s%s", send_str, "GET measurements/url_create?"); sprintf(send_str, "%sinstrument_id=%d", send_str, instrument_id); for (i = 0; i < nvars; i++){ if (labels[i] && labels[i][0]){ sprintf(send_str, "%s&%s=%f", send_str, labels[i], readings[i]); } } if (write_key_enabled){ sprintf(send_str, "%s&key=%s", send_str, chords_write_key); } // If this is a test measurement, append "&test" if (is_test){ sprintf(send_str, "%s&test", send_str); } sprintf(send_str, "%s HTTP/1.1\r\n", send_str); sprintf(send_str,"%s%s%s%s%d%s%s", send_str, "Host: ", chords_endpoint, ":", chords_port, "\r\n", "Connection: Close\r\n\r\n"); return i; } /* [] END OF FILE */
2.28125
2
2024-11-18T18:10:04.547248+00:00
2020-12-03T06:35:18
c13c8f84da1f3089dbecddac22395bb5baa69404
{ "blob_id": "c13c8f84da1f3089dbecddac22395bb5baa69404", "branch_name": "refs/heads/master", "committer_date": "2020-12-03T06:35:18", "content_id": "230762d9137150b899af401f56e09f4de348a9c5", "detected_licenses": [ "CC0-1.0", "MIT" ], "directory_id": "96f72457cfbc15f467a2217f911858494d5d54a2", "extension": "c", "filename": "vm.c", "fork_events_count": 0, "gha_created_at": "2020-05-14T20:27:14", "gha_event_created_at": "2020-05-14T20:27:14", "gha_language": null, "gha_license_id": null, "github_id": 264017942, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1960, "license": "CC0-1.0,MIT", "license_type": "permissive", "path": "/kernel/arch/x64/vm.c", "provenance": "stackv2-0003.json.gz:327066", "repo_name": "milisarge/resea", "revision_date": "2020-12-03T06:35:18", "revision_id": "b2f8592db638a6d92e6508f163ec5a31f132dc9f", "snapshot_id": "602b93ac30ffc47a50295c2656798a64a74d6d70", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/milisarge/resea/b2f8592db638a6d92e6508f163ec5a31f132dc9f/kernel/arch/x64/vm.c", "visit_date": "2023-01-20T20:41:44.527554" }
stackv2
#include <arch.h> #include <task.h> #include <printk.h> #include <string.h> #include "vm.h" static uint64_t *traverse_page_table(uint64_t pml4, vaddr_t vaddr, paddr_t kpage, uint64_t attrs) { ASSERT(vaddr < KERNEL_BASE_ADDR); ASSERT(IS_ALIGNED(vaddr, PAGE_SIZE)); ASSERT(IS_ALIGNED(kpage, PAGE_SIZE)); uint64_t *table = from_paddr(pml4); for (int level = 4; level > 1; level--) { int index = NTH_LEVEL_INDEX(level, vaddr); if (!table[index]) { if (!attrs) { return NULL; } // The PDPT, PD or PT is not allocated. memset(from_paddr(kpage), 0, PAGE_SIZE); table[index] = kpage; kpage = 0; return NULL; } // Update attributes if given. table[index] = table[index] | attrs; // Go into the next level paging table. table = (uint64_t *) from_paddr(ENTRY_PADDR(table[index])); } return &table[NTH_LEVEL_INDEX(1, vaddr)]; } error_t arch_vm_map(struct task *task, vaddr_t vaddr, paddr_t paddr, paddr_t kpage, unsigned flags) { ASSERT(IS_ALIGNED(paddr, PAGE_SIZE)); uint64_t attrs = (1 << 2) | 1 /* user, present */; attrs |= (flags & MAP_W) ? X64_PAGE_WRITABLE : 0; uint64_t *entry = traverse_page_table(task->arch.pml4, vaddr, kpage, attrs); if (!entry) { return (kpage) ? ERR_TRY_AGAIN : ERR_EMPTY; } *entry = paddr | attrs; asm_invlpg(vaddr); return OK; } error_t arch_vm_unmap(struct task *task, vaddr_t vaddr) { uint64_t *entry = traverse_page_table(task->arch.pml4, vaddr, 0, 0); if (!entry) { return ERR_NOT_FOUND; } *entry = 0; asm_invlpg(vaddr); return OK; } paddr_t vm_resolve(struct task *task, vaddr_t vaddr) { uint64_t *entry = traverse_page_table(task->arch.pml4, vaddr, 0, 0); return (entry) ? ENTRY_PADDR(*entry) : 0; }
2.546875
3
2024-11-18T18:10:05.409558+00:00
2023-08-17T21:51:22
cae3f6684df560542d2a12371a56636972134a1e
{ "blob_id": "cae3f6684df560542d2a12371a56636972134a1e", "branch_name": "refs/heads/master", "committer_date": "2023-08-17T21:51:22", "content_id": "70e888ac773d698ba29e1f2a6a66c20040ed1fc3", "detected_licenses": [ "MIT" ], "directory_id": "80f3b23dce2738ff296d938a16b9f5bc8a7773f2", "extension": "c", "filename": "alocacao_dinamica_estruturas.c", "fork_events_count": 3, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 41948152, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1306, "license": "MIT", "license_type": "permissive", "path": "/2018/Structs/alocacao_dinamica_estruturas.c", "provenance": "stackv2-0003.json.gz:327451", "repo_name": "ed1rac/AulasEstruturasDados", "revision_date": "2023-08-17T21:51:22", "revision_id": "8e656f846f2de4783aa59dbed8ff57b9b4b48c09", "snapshot_id": "32431334fcbf072a5a5a34124ca54f59d69f8eda", "src_encoding": "UTF-8", "star_events_count": 8, "url": "https://raw.githubusercontent.com/ed1rac/AulasEstruturasDados/8e656f846f2de4783aa59dbed8ff57b9b4b48c09/2018/Structs/alocacao_dinamica_estruturas.c", "visit_date": "2023-08-31T22:08:25.222803" }
stackv2
#include <stdio.h> #include <stdlib.h> #include <string.h> //Alocação dinâmica de estruturas typedef struct aluno{ int nmat; char nome[50]; char sobrenome[50]; float nota[3]; float media; }Aluno; int main(){ printf("Aluno tem %d bytes", sizeof(Aluno)); Aluno* pt_aluno; Aluno* alunos; pt_aluno = (Aluno*) malloc(sizeof(Aluno)); alunos = (Aluno*) malloc(10*sizeof(Aluno)); alunos[0].nmat = 321; pt_aluno->nmat = 123; strcpy(pt_aluno->nome,"Matheus"); strcpy(pt_aluno->sobrenome, "Campos"); pt_aluno->nota[0]=8.0; pt_aluno->nota[1]=9.6; pt_aluno->nota[2]=9.0; pt_aluno->media=(pt_aluno->nota[0]+pt_aluno->nota[1]+pt_aluno->nota[2])/3; //exibindo printf("\n\nExibindo a estrutura"); printf("\n===================="); printf("\nMat........:\t%d", pt_aluno->nmat); printf("\nNome.......:\t%s", pt_aluno->nome); printf("\nSobrenome..:\t%s", pt_aluno->sobrenome); printf("\nNota N1.....:\t%.2f", pt_aluno->nota[0]); printf("\nNota N2.....:\t%.2f", pt_aluno->nota[1]); printf("\nNota N3.....:\t%.2f", pt_aluno->nota[2]); printf("\nMédia.......:\t%.2f", pt_aluno->media); printf("\n===================="); //finaliza saindo deste programa getchar(); }
3.171875
3
2024-11-18T18:10:05.919941+00:00
2018-11-12T08:53:58
7087691b7870fff0ad647662d0326a4026a10765
{ "blob_id": "7087691b7870fff0ad647662d0326a4026a10765", "branch_name": "refs/heads/master", "committer_date": "2018-11-12T08:53:58", "content_id": "018ca8612286976b12eb07392c4f71e2072ad5e5", "detected_licenses": [ "MIT" ], "directory_id": "9e3af1bd1d11072faba6069a932050e108a7152d", "extension": "c", "filename": "play.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 148748982, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 3317, "license": "MIT", "license_type": "permissive", "path": "/examples/c/play.c", "provenance": "stackv2-0003.json.gz:328097", "repo_name": "benjineering/sound-io", "revision_date": "2018-11-12T08:53:58", "revision_id": "adfb0ecbbbe5c037f160129ab6019adb7f0e68ce", "snapshot_id": "7121ed0b88c3c11eb1877151c7980722a5f30599", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/benjineering/sound-io/adfb0ecbbbe5c037f160129ab6019adb7f0e68ce/examples/c/play.c", "visit_date": "2020-03-28T16:59:52.268887" }
stackv2
#include <soundio/soundio.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> static const float PI = 3.1415926535f; static float seconds_offset = 0.0f; static void write_callback(struct SoundIoOutStream *outstream, int frame_count_min, int frame_count_max) { const struct SoundIoChannelLayout *layout = &outstream->layout; float float_sample_rate = outstream->sample_rate; float seconds_per_frame = 1.0f / float_sample_rate; struct SoundIoChannelArea *areas; int frames_left = frame_count_max; int err; while (frames_left > 0) { int frame_count = frames_left; if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) { fprintf(stderr, "%s\n", soundio_strerror(err)); exit(1); } if (!frame_count) break; float pitch = 440.0f; float radians_per_second = pitch * 2.0f * PI; for (int frame = 0; frame < frame_count; frame += 1) { float sample = sin((seconds_offset + frame * seconds_per_frame) * radians_per_second); for (int channel = 0; channel < layout->channel_count; channel += 1) { float *ptr = (float*)(areas[channel].ptr + areas[channel].step * frame); *ptr = sample; } } seconds_offset = fmod(seconds_offset + seconds_per_frame * frame_count, 1.0); if ((err = soundio_outstream_end_write(outstream))) { fprintf(stderr, "%s\n", soundio_strerror(err)); exit(1); } frames_left -= frame_count; } } int main(int argc, char **argv) { int err; struct SoundIo *soundio = soundio_create(); if (!soundio) { fprintf(stderr, "out of memory\n"); return 1; } if ((err = soundio_connect(soundio))) { fprintf(stderr, "error connecting: %s\n", soundio_strerror(err)); return 1; } soundio_flush_events(soundio); int default_out_device_index = soundio_default_output_device_index(soundio); if (default_out_device_index < 0) { fprintf(stderr, "no output device found\n"); return 1; } struct SoundIoDevice *device = soundio_get_output_device(soundio, default_out_device_index); if (!device) { fprintf(stderr, "out of memory\n"); return 1; } fprintf(stderr, "Output device: %s\n", device->name); struct SoundIoOutStream *outstream = soundio_outstream_create(device); if (!outstream) { fprintf(stderr, "out of memory\n"); return 1; } outstream->format = SoundIoFormatFloat32NE; outstream->write_callback = write_callback; if ((err = soundio_outstream_open(outstream))) { fprintf(stderr, "unable to open device: %s", soundio_strerror(err)); return 1; } if (outstream->layout_error) fprintf(stderr, "unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error)); if ((err = soundio_outstream_start(outstream))) { fprintf(stderr, "unable to start device: %s\n", soundio_strerror(err)); return 1; } for (;;) soundio_wait_events(soundio); soundio_outstream_destroy(outstream); soundio_device_unref(device); soundio_destroy(soundio); return 0; }
2.59375
3
2024-11-18T18:10:06.387453+00:00
2020-12-25T14:04:04
657eae901130c72264693e2c3277d377fa21b354
{ "blob_id": "657eae901130c72264693e2c3277d377fa21b354", "branch_name": "refs/heads/master", "committer_date": "2020-12-25T14:04:04", "content_id": "c3d02178fe471b4cb431f77a275866783ad97bac", "detected_licenses": [ "MIT" ], "directory_id": "857fc21a40aa32d2a57637de1c723e4ab51062ff", "extension": "c", "filename": "17_02.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 171432914, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2991, "license": "MIT", "license_type": "permissive", "path": "/CChallenge/April/17_02.c", "provenance": "stackv2-0003.json.gz:328354", "repo_name": "YorkFish/git_study", "revision_date": "2020-12-25T14:04:04", "revision_id": "6e023244daaa22e12b24e632e76a13e5066f2947", "snapshot_id": "efa0149f94623d685e005d58dbaef405ab91d541", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/YorkFish/git_study/6e023244daaa22e12b24e632e76a13e5066f2947/CChallenge/April/17_02.c", "visit_date": "2021-06-21T18:46:50.906441" }
stackv2
#include <stdio.h> #include <stdbool.h> const char WATER = '0'; const char LAND = '1'; const char NEW = 'X'; const char USED = 'O'; void drawGrid(char** grid, int NUMBER_OF_ROWS, int NUMBER_OF_COLS) { for (int i = 0; i < NUMBER_OF_ROWS; i++) { for (int j = 0; j < NUMBER_OF_COLS; j++) { printf("%c", grid[i][j]); } printf("\n"); } printf("----------\n"); } void floorFill(char** grid, int NUMBER_OF_ROWS, int NUMBER_OF_COLS, int i, int j) { grid[i][j] = NEW; bool hasNew; do { hasNew = false; for (int y = 0; y < NUMBER_OF_ROWS; y++) { for (int x = 0; x < NUMBER_OF_COLS; x++) { if (grid[y][x] == LAND) { int upX = x; int upY = y-1; if (upY >= 0 && grid[upY][upX] == NEW) { grid[y][x] = NEW; hasNew = true; } int downX = x; int downY = y+1; if (downY < NUMBER_OF_ROWS && grid[downY][downX] == NEW) { grid[y][x] = NEW; hasNew = true; } int leftX = x-1; int leftY = y; if (leftX >= 0 && grid[leftY][leftX] == NEW) { grid[y][x] = NEW; hasNew = true; } int rightX = x+1; int rightY = y; if (rightX < NUMBER_OF_COLS && grid[rightY][rightX] == NEW) { grid[y][x] = NEW; hasNew = true; } } } } } while (hasNew); } int numIslands(char** grid, int gridSize, int* gridColSize) { if (gridSize == 0) return 0; int NUMBER_OF_ROWS = gridSize; int NUMBER_OF_COLS = gridColSize[0]; int numberOfIslands = 0; for (int i = 0; i < NUMBER_OF_ROWS; i++) { for (int j = 0; j < NUMBER_OF_COLS; j++) { if (grid[i][j] == LAND) { floorFill(grid, NUMBER_OF_ROWS, NUMBER_OF_COLS, i, j); for (int y = 0; y < NUMBER_OF_ROWS; y++) { for (int x = 0; x < NUMBER_OF_COLS; x++) { if (grid[y][x] == NEW) { grid[y][x] = USED; } } } numberOfIslands++; } } } return numberOfIslands; } int main() { char temp[][5] = { "11110", "11010", "11000", "00000" }; char* grid[] = {temp[0], temp[1], temp[2], temp[3]}; int gridSize = 4; int gridColSize[] = {5, 5, 5, 5}; drawGrid(grid, gridSize, gridColSize[0]); int result = numIslands(grid, gridSize, gridColSize); printf(">>> result = %d\n", result); drawGrid(grid, gridSize, gridColSize[0]); return 0; }
3.25
3
2024-11-18T18:10:06.588723+00:00
2020-12-30T09:15:17
14d80d200cdc106791578d47de8cfeb231ec1207
{ "blob_id": "14d80d200cdc106791578d47de8cfeb231ec1207", "branch_name": "refs/heads/master", "committer_date": "2020-12-30T09:15:17", "content_id": "8f5c8d4947b86822197baca188b9106f0a5479af", "detected_licenses": [ "MIT" ], "directory_id": "9135087be1626955056f1775e308247088467171", "extension": "c", "filename": "main.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 294295548, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1594, "license": "MIT", "license_type": "permissive", "path": "/src/LCD显示自己名字/Debug/srcc/main.c", "provenance": "stackv2-0003.json.gz:328610", "repo_name": "qiuyeyijian/Embed", "revision_date": "2020-12-30T09:15:17", "revision_id": "ff4b9fca473e66c7624a48256bebc143a980e822", "snapshot_id": "6e4cec18fa1e418c487fbadd1962e809cea5f83f", "src_encoding": "GB18030", "star_events_count": 1, "url": "https://raw.githubusercontent.com/qiuyeyijian/Embed/ff4b9fca473e66c7624a48256bebc143a980e822/src/LCD显示自己名字/Debug/srcc/main.c", "visit_date": "2023-02-09T08:34:52.372741" }
stackv2
//==================================================================== //文件名称:main.c(应用工程主函数) //框架提供:SD-Arm(sumcu.suda.edu.cn) //版本更新:2017.08, 2020.06 //功能描述:见本工程的<01_Doc>文件夹下Readme.txt文件 //==================================================================== #define GLOBLE_VAR #include "includes.h" //包含总头文件 //---------------------------------------------------------------------- //声明使用到的内部函数 //main.c使用的内部函数声明处 //---------------------------------------------------------------------- //主函数,一般情况下可以认为程序从此开始运行(实际上有启动过程见书稿) int main(void) { //(1.2)【不变】关总中断 DISABLE_INTERRUPTS; wdog_stop(); // 初始化发送串口和接收串口 suart_init(SUART_TX, SUART_SEND); suart_init(SUART_RX, SUART_RECEVIE); LCD_Init(); //初始化LCD LCD_ShowString(6, 300, BLUE, GRAY, "Hello, world"); LCD_ShowString(72, 32, BLUE, GRAY, "张龙威"); LCD_DrawPoint_big(30, 30, RED); LCD_DrawLine(50, 50, 50, 150, RED); LCD_DrawRectangle(60, 60, 120, 120, YELLOW); LCD_DrawSurface(70, 70, 140, 140, BLUE); LCD_ShowString(120, 240, BLUE, GRAY, "秋叶依剑"); // 使能串口接收中断 suart_enable_receive_interupt(SUART_RX); //(1.7)【不变】开总中断 ENABLE_INTERRUPTS; //(2)======主循环部分(结尾)======================================== for (;;) { } }
2.140625
2
2024-11-18T18:10:07.122640+00:00
2020-12-13T07:47:33
526e5a36c6794c775cc17be4e4167f9d33b7d49e
{ "blob_id": "526e5a36c6794c775cc17be4e4167f9d33b7d49e", "branch_name": "refs/heads/master", "committer_date": "2020-12-13T07:47:33", "content_id": "3d27d93753694eac178923838fa55d160b5e5357", "detected_licenses": [ "MIT" ], "directory_id": "add533c4e43dc111f18c679626d7e350baa926de", "extension": "c", "filename": "HanoiTower.c", "fork_events_count": 4, "gha_created_at": "2020-08-18T06:50:01", "gha_event_created_at": "2020-12-13T07:47:34", "gha_language": "C", "gha_license_id": "MIT", "github_id": 288378136, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 550, "license": "MIT", "license_type": "permissive", "path": "/Lec3/HanoiTower/HanoiTower.c", "provenance": "stackv2-0003.json.gz:328996", "repo_name": "bluekds/C_Programming_Lv2", "revision_date": "2020-12-13T07:47:33", "revision_id": "7643f9b04c1bd0d72189f8e0fb68b8a13f14b9f2", "snapshot_id": "b21e9df2df84bec87f38395fa6531062c26ac107", "src_encoding": "UTF-8", "star_events_count": 2, "url": "https://raw.githubusercontent.com/bluekds/C_Programming_Lv2/7643f9b04c1bd0d72189f8e0fb68b8a13f14b9f2/Lec3/HanoiTower/HanoiTower.c", "visit_date": "2023-01-29T17:41:20.862633" }
stackv2
#include <stdio.h> // Move n blocks [from] -> [to] void hanoiTower(int numBlocks, char from, char temp, char to); int main(void) { int x = 0; printf("Enter the number of blocks: "); scanf_s("%d", &x); hanoiTower(x, 'A', 'B', 'C'); } void hanoiTower(int numBlocks, char from, char temp, char to) { if (numBlocks == 1) printf("Move the block 1: %c -> %c.\n", from, to); else { hanoiTower(numBlocks - 1, from, to, temp); printf("Move the block %d: %c -> %c.\n", numBlocks, from, to); hanoiTower(numBlocks - 1, temp, from, to); } }
3.875
4
2024-11-18T18:10:07.291687+00:00
2019-10-27T16:39:36
22262401de818c7ad247d0e122ea3bbd138e7383
{ "blob_id": "22262401de818c7ad247d0e122ea3bbd138e7383", "branch_name": "refs/heads/master", "committer_date": "2019-10-27T16:39:36", "content_id": "4ac09ff3314fb860c4ab4502f4c300bc20e6be03", "detected_licenses": [ "Unlicense" ], "directory_id": "661c0d619853a9680cad45edcb81c276583125d4", "extension": "c", "filename": "test_mocks_group_non_empty_context.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 158989241, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 6667, "license": "Unlicense", "license_type": "permissive", "path": "/tests/test_mocks/test_mocks_group_non_empty_context.c", "provenance": "stackv2-0003.json.gz:329254", "repo_name": "xlamsp/atl", "revision_date": "2019-10-27T16:39:36", "revision_id": "d5c2c4b3cd6a0e7ddca68c79b270c7cd0db39b37", "snapshot_id": "59fd220a065e287de7bf49baaf878857a3bda1cd", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/xlamsp/atl/d5c2c4b3cd6a0e7ddca68c79b270c7cd0db39b37/tests/test_mocks/test_mocks_group_non_empty_context.c", "visit_date": "2020-04-08T03:46:48.453588" }
stackv2
#include "mocks.h" #include "unity_fixture.h" static mocks_return_code verify_assert_value; static uint8_t expect_ctx[MOCKS_MAX_CONTEXT_DATA_SIZE]; static uint8_t invoke_ctx[MOCKS_MAX_CONTEXT_DATA_SIZE]; TEST_GROUP(NonEmptyContext); TEST_SETUP(NonEmptyContext) { mocks_init(); } TEST_TEAR_DOWN(NonEmptyContext) { TEST_ASSERT_EQUAL(verify_assert_value, mocks_verify()); } /* * "expect" with non-null ctx and zero size should fail */ TEST(NonEmptyContext, ExpectNonNullCtxZeroSizeFails) { int ctx; TEST_ASSERT_EQUAL(mocks_invalid_ctx_size, mocks_expect(0, &ctx, 0)); verify_assert_value = mocks_invalid_ctx_size; } /* * "expect" with null ctx and non-zero size should fail */ TEST(NonEmptyContext, ExpectNullCtxNonZeroSizeFails) { TEST_ASSERT_EQUAL(mocks_invalid_ctx, mocks_expect(0, NULL, 1)); verify_assert_value = mocks_invalid_ctx; } /* * "expect" with non-null ctx and small non-zero size should succeed */ TEST(NonEmptyContext, ExpectNonNullCtxNonZeroSizeSucceeds) { int ctx; TEST_ASSERT_EQUAL(mocks_success, mocks_expect(0, &ctx, sizeof(ctx))); verify_assert_value = mocks_not_all_expectations_used; } /* * "invoke" with non-null ctx and zero size should fail */ TEST(NonEmptyContext, InvokeNonNullCtxZeroSizeFails) { int ctx; mocks_expect(0, &ctx, sizeof(ctx)); TEST_ASSERT_EQUAL(mocks_invalid_ctx_size, mocks_invoke(0, &ctx, 0)); verify_assert_value = mocks_invalid_ctx_size; } /* * "invoke" with null ctx and non-zero size should fail */ TEST(NonEmptyContext, InvokeNullCtxNonZeroSizeFails) { int ctx; mocks_expect(0, &ctx, sizeof(ctx)); TEST_ASSERT_EQUAL(mocks_invalid_ctx, mocks_invoke(0, NULL, sizeof(ctx))); verify_assert_value = mocks_invalid_ctx; } /* * "invoke" with not matching size should fail */ TEST(NonEmptyContext, InvokeCtxSizeNotMatchFails) { int ctx; mocks_expect(0, &ctx, sizeof(ctx)); TEST_ASSERT_EQUAL(mocks_ctx_size_mismatch, mocks_invoke(0, &ctx, sizeof(ctx) + 1)); verify_assert_value = mocks_ctx_size_mismatch; } /* * "invoke" with non-null ctx and matching non-zero size should succeed */ TEST(NonEmptyContext, InvokeCtxSizeMatchSucceeds) { int ctx; mocks_expect(0, &ctx, sizeof(ctx)); TEST_ASSERT_EQUAL(mocks_success, mocks_invoke(0, &ctx, sizeof(ctx))); verify_assert_value = mocks_success; } /* * "invoke" should return ctx data provided by "expect" */ TEST(NonEmptyContext, InvokeReturnsCtxProvidedByExpect) { int ctx_expect = 1234; int ctx_invoke = 5678; mocks_expect(0, &ctx_expect, sizeof(ctx_expect)); mocks_invoke(0, &ctx_invoke, sizeof(ctx_invoke)); TEST_ASSERT_EQUAL(1234, ctx_invoke); verify_assert_value = mocks_success; } /* * "expect" should make copy of ctx data to protect it from corruption */ TEST(NonEmptyContext, ExpectShouldMakeCopyOfCtxData) { int ctx_expect = 1234; int ctx_invoke = 5678; mocks_expect(0, &ctx_expect, sizeof(ctx_expect)); ctx_expect = 9876; /* corrupt original ctx data */ mocks_invoke(0, &ctx_invoke, sizeof(ctx_invoke)); TEST_ASSERT_EQUAL(1234, ctx_invoke); verify_assert_value = mocks_success; } /* * "expect" with ctx data size up to the maximum context buffer should succeed */ TEST(NonEmptyContext, ExpectWithCtxDataUpToMaxBufferSizeSucceeds) { int i; /* init expected and invoked context data */ for (i = 0; i < MOCKS_MAX_CONTEXT_DATA_SIZE; i++) { expect_ctx[i] = (uint8_t)i; invoke_ctx[i] = (uint8_t)(i + 10); } TEST_ASSERT_EQUAL(mocks_success, mocks_expect(0, &expect_ctx, MOCKS_MAX_CONTEXT_DATA_SIZE)); /* corrupt expected context data */ for (i = 0; i < MOCKS_MAX_CONTEXT_DATA_SIZE; i++) { expect_ctx[i] = (uint8_t)(i + 20); } TEST_ASSERT_EQUAL(mocks_success, mocks_invoke(0, &invoke_ctx, MOCKS_MAX_CONTEXT_DATA_SIZE)); /* verify that invoked context data matches expected context data */ for (i = 0; i < MOCKS_MAX_CONTEXT_DATA_SIZE; i++) { TEST_ASSERT_EQUAL_UINT8(i, invoke_ctx[i]); } verify_assert_value = mocks_success; } /* * "expect" with ctx data size over the maximum context buffer should fail */ TEST(NonEmptyContext, ExpectCtxDataOverMaxBufferSizeFails) { TEST_ASSERT_EQUAL(mocks_no_room_for_ctx_data, mocks_expect(0, &expect_ctx, MOCKS_MAX_CONTEXT_DATA_SIZE + 1)); verify_assert_value = mocks_no_room_for_ctx_data; } /* * "invoke" called twice after "expect" twice should succeed, ctx data should * match */ TEST(NonEmptyContext, ExpectTwiceInvokeTwiceMatchingNonEmptyCtxSucceeds) { int ctx_expect; int ctx_invoke; ctx_expect = 1234; mocks_expect(0, &ctx_expect, sizeof(ctx_expect)); ctx_expect = 5678; TEST_ASSERT_EQUAL(mocks_success, mocks_expect(0, &ctx_expect, sizeof(ctx_expect))); TEST_ASSERT_EQUAL(mocks_success, mocks_invoke(0, &ctx_invoke, sizeof(ctx_invoke))); TEST_ASSERT_EQUAL(1234, ctx_invoke); TEST_ASSERT_EQUAL(mocks_success, mocks_invoke(0, &ctx_invoke, sizeof(ctx_invoke))); TEST_ASSERT_EQUAL(5678, ctx_invoke); verify_assert_value = mocks_success; } /* * "expect" and "invoke" called multiple times with total ctx sizes up to max * contex buffer should succeed */ TEST(NonEmptyContext, MultipleExpectWithCtxDataUpToMaxBufferSizeSucceeds) { int i; unsigned int size; size = MOCKS_MAX_CONTEXT_DATA_SIZE / 3; for (i = 0; i < size; i++) { expect_ctx[i] = (uint8_t)i; } TEST_ASSERT_EQUAL(mocks_success, mocks_expect(0, &expect_ctx, size)); size = MOCKS_MAX_CONTEXT_DATA_SIZE - size; for (i = 0; i < size; i++) { expect_ctx[i] = (uint8_t)(i * 2); } TEST_ASSERT_EQUAL(mocks_success, mocks_expect(0, &expect_ctx, size)); size = MOCKS_MAX_CONTEXT_DATA_SIZE / 3; TEST_ASSERT_EQUAL(mocks_success, mocks_invoke(0, &invoke_ctx, size)); for (i = 0; i < size; i++) { TEST_ASSERT_EQUAL_UINT8(i, invoke_ctx[i]); } size = MOCKS_MAX_CONTEXT_DATA_SIZE - size; TEST_ASSERT_EQUAL(mocks_success, mocks_invoke(0, &invoke_ctx, size)); for (i = 0; i < size; i++) { TEST_ASSERT_EQUAL_UINT8((i * 2), invoke_ctx[i]); } verify_assert_value = mocks_success; } /* * "expect" called multiple times with total ctx sizes over max contex buffer * should fail */ TEST(NonEmptyContext, MultipleExpectWithCtxDataOverMaxBufferFails) { unsigned int size; size = MOCKS_MAX_CONTEXT_DATA_SIZE / 3; TEST_ASSERT_EQUAL(mocks_success, mocks_expect(0, &expect_ctx, size)); size = MOCKS_MAX_CONTEXT_DATA_SIZE - size + 1; TEST_ASSERT_EQUAL(mocks_no_room_for_ctx_data, mocks_expect(0, &expect_ctx, size)); verify_assert_value = mocks_no_room_for_ctx_data; }
2.40625
2
2024-11-18T18:10:07.841976+00:00
2020-07-08T04:56:19
5953bdbe445ed35fbbd57402a57482bfc331a9c5
{ "blob_id": "5953bdbe445ed35fbbd57402a57482bfc331a9c5", "branch_name": "refs/heads/master", "committer_date": "2020-07-08T04:56:19", "content_id": "c86fda4fd29b476884565d8ae72759f336deb6ef", "detected_licenses": [ "MIT" ], "directory_id": "77ae9a6eba3e6b0da2d323ea19e007d6d78bee79", "extension": "h", "filename": "galvani-ni.h", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 257987536, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 3558, "license": "MIT", "license_type": "permissive", "path": "/libgalvani/NI-helloworld/galvani-ni.h", "provenance": "stackv2-0003.json.gz:329639", "repo_name": "YoonGroupUmich/galvani", "revision_date": "2020-07-08T04:56:19", "revision_id": "de99f7bff7a2c1e7dc239e37fe39dfcf4285d3cd", "snapshot_id": "d853cf229cf6585e81229b181d33676db98c4d94", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/YoonGroupUmich/galvani/de99f7bff7a2c1e7dc239e37fe39dfcf4285d3cd/libgalvani/NI-helloworld/galvani-ni.h", "visit_date": "2022-11-15T17:50:05.915730" }
stackv2
#pragma once #include <stdint.h> #include <stdbool.h> #ifdef BUILD_LIBGALVANI #define GALVANI_API __declspec(dllexport) #else #define GALVANI_API #endif #ifdef __cplusplus extern "C" { #endif // The API is organized in 2 levels. // You can use either one set to complete the stimulation task. // ======= High level APIs ======= struct ChannelInfo; struct GalvaniDevice; // Get ChannelInfo from square / trapizoid waveform parameters. amp is represented in control code, and must between 0~255. times are in seconds. GALVANI_API struct ChannelInfo* GetChannelInfoSquare(int64_t n_pulses, double rising_time, double amp, double pulse_width, double period, double falling_time); // Get ChannelInfo from sine-rolloff square waveform parameters. amp is represented in control code, and must between 0~255. times are in seconds. GALVANI_API struct ChannelInfo* GetChannelInfoSine(int64_t n_pulses, double rising_time, double amp, double pulse_width, double period, double falling_time); // Get ChannelInfo from custom waveform. wave is an array of control code. wave_len is the length of wave. sample_rate is in Sa/s GALVANI_API struct ChannelInfo* GetChannelInfoCustom(int64_t n_pulses, const char* wave, size_t wave_len, double sample_rate); // Get GalvaniDevice from NI device name. The device name almost always starts with '/'. // bias is for Galvani. If bias is in 0-126, it is internal bias. If bias is 128, it is external bias. GALVANI_API struct GalvaniDevice* GetGalvaniDevice(const char* dev_name, size_t dev_name_len, uint8_t bias); // Start GalvaniDevice. This should be called first after creating GalvaniDevice, before any other calls with GalvaniDevice. GALVANI_API void StartGalvaniDevice(struct GalvaniDevice* gd); // Stop and free the GalvaniDevice. GalvaniDevice should not be used after this call. GALVANI_API void StopGalvaniDevice(struct GalvaniDevice* gd); // Assign ChannelInfo to channel. The lib will take over the ownership of ChannelInfo, so it should not be used after this call. Use ci=NULL to stop a channel. GALVANI_API void GalvaniDeviceSetChannel(struct GalvaniDevice* gd, int channel, struct ChannelInfo* ci); // Get the status of GalvaniDevice. Status is returned in the bool array. True means the corresponding channel is sending waveform. // This function returns false on success. The bool array contains meaningless value if the function returns true. GALVANI_API bool GalvaniDeviceGetStatus(struct GalvaniDevice* gd, bool buffer[128]); // ======= Low level APIs ======= struct Galvani; // Init Galvani from National Instrument digital output device GALVANI_API struct Galvani* galvani_init_ni(const char* ni_device); // Set Galvani buffer size. This will affect the delay from computer operation to actual waveform output // buffer: buffer size in seconds GALVANI_API void galvani_set_buffer_size(struct Galvani* dev, double buffer); // Get Galvani buffer size in seconds, Returns 0 on fail GALVANI_API double galvani_get_buffer_size(struct Galvani* dev); // Get number of samples of total buffer GALVANI_API uint32_t galvani_get_buffer_size_samples(struct Galvani* dev); // Get number of samples currently in buffer GALVANI_API uint32_t galvani_get_buffer_samples(struct Galvani* dev); // Send binary command to galvani. See comments in main.cpp for command structure. GALVANI_API void galvani_send_command(struct Galvani* dev, const char* command, int32_t command_count); // Free any resorces related to struct Galvani GALVANI_API void galvani_end(struct Galvani* dev); #ifdef __cplusplus } #endif
2.046875
2
2024-11-18T18:10:08.476447+00:00
2016-02-04T10:24:44
4374067f2aa42d1f39da1448adb0eb078f117743
{ "blob_id": "4374067f2aa42d1f39da1448adb0eb078f117743", "branch_name": "refs/heads/master", "committer_date": "2016-02-04T10:24:44", "content_id": "9a52c486646c47a0bcec2892e8da0528be62880c", "detected_licenses": [ "Zlib" ], "directory_id": "7ff53add1a2a71b16c4451a99153003d8a6707de", "extension": "c", "filename": "shortcuts.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 27357680, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 17523, "license": "Zlib", "license_type": "permissive", "path": "/shortcuts.c", "provenance": "stackv2-0003.json.gz:329897", "repo_name": "lluixhi/jumanji", "revision_date": "2016-02-04T10:24:44", "revision_id": "6f45380ac88bff4b977e9f8333e35d8fe325e295", "snapshot_id": "844141591f2b74b25cf727fb4e18d50f6215fe45", "src_encoding": "UTF-8", "star_events_count": 4, "url": "https://raw.githubusercontent.com/lluixhi/jumanji/6f45380ac88bff4b977e9f8333e35d8fe325e295/shortcuts.c", "visit_date": "2021-01-22T01:50:59.686111" }
stackv2
/* See LICENSE file for license and copyright information */ #include <girara/session.h> #include <girara/settings.h> #include <girara/shortcuts.h> #include <girara/datastructures.h> #include <gtk/gtk.h> #include <stdlib.h> #include <string.h> #include "callbacks.h" #include "database.h" #include "jumanji.h" #include "shortcuts.h" bool sc_goto_homepage(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); jumanji_t* jumanji = session->global.data; g_return_val_if_fail(argument != NULL, false); char* homepage = NULL; girara_setting_get(jumanji->ui.session, "homepage", &homepage); char* url = NULL; if (homepage != NULL) { url = jumanji_build_url_from_string(jumanji, homepage); g_free(homepage); } if (argument->n == NEW_TAB) { bool focus_new_tabs; girara_setting_get(jumanji->ui.session, "focus-new-tabs", &focus_new_tabs); jumanji_tab_new(jumanji, url, focus_new_tabs); } else { jumanji_tab_t* tab = jumanji_tab_get_current(jumanji); if (tab != NULL) { jumanji_tab_load_url(tab, url); } } free(url); return false; } bool sc_goto_parent_directory(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); jumanji_t* jumanji = session->global.data; g_return_val_if_fail(argument != NULL, false); jumanji_tab_t* tab = jumanji_tab_get_current(jumanji); if (tab == NULL || tab->web_view == NULL) { return false; } char* url = (char*) webkit_web_view_get_uri(WEBKIT_WEB_VIEW(tab->web_view)); if (url == NULL) { return false; } /* calculate root of the website */ unsigned int offset = strstr(url, "://") - url + 3; unsigned int root_length = offset + 1; char* root_string = url + offset; while(root_string && *root_string != '/') { root_length++; root_string++; } char* root = g_strndup(url, root_length); if (argument->n == DEFAULT) { jumanji_tab_load_url(tab, root); } else { unsigned int count = (t == 0) ? 1 : t; char* directories = g_strndup(url + strlen(root), strlen(url) - strlen(root)); if (directories == NULL || strlen(directories) == 0) { return false; } gchar **tokens = g_strsplit(directories, "/", -1); int length = g_strv_length(tokens); GString* tmp = g_string_new(""); int limit = length - count; for (int i = 0; i < limit; i++) { if (i == 0) { g_string_append(tmp, tokens[i]); } else { g_string_append(tmp, "/"); g_string_append(tmp, tokens[i]); } } char* new_url = g_strconcat(root, tmp->str, NULL); jumanji_tab_load_url(tab, new_url); g_free(new_url); g_string_free(tmp, TRUE); g_strfreev(tokens); g_free(directories); } g_free(root); return false; } bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); jumanji_t* jumanji = session->global.data; g_return_val_if_fail(argument != NULL, false); if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.inputbar)) == FALSE) { gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); } if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.notification_area)) == TRUE) { gtk_widget_hide(GTK_WIDGET(session->gtk.notification_area)); } if (argument->data) { if (argument->n == APPEND_URL) { jumanji_tab_t* tab = jumanji_tab_get_current(jumanji); if (tab != NULL && tab->web_view != NULL) { const char* uri = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(tab->web_view)); char* data = g_strdup_printf("%s%s", (char*) argument->data, uri); gtk_entry_set_text(session->gtk.inputbar_entry, data); g_free(data); } else { gtk_entry_set_text(session->gtk.inputbar_entry, (char*) argument->data); } } else { gtk_entry_set_text(session->gtk.inputbar_entry, (char*) argument->data); } /* save the X clipboard that will be cleared by "grab focus" */ gchar* x_clipboard_text = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY)); gtk_widget_grab_focus(GTK_WIDGET(session->gtk.inputbar_entry)); gtk_editable_set_position(GTK_EDITABLE(session->gtk.inputbar_entry), -1); if (x_clipboard_text != NULL) { /* reset x clipboard */ gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), x_clipboard_text, -1); g_free(x_clipboard_text); } } return false; } bool sc_tab_navigate(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(argument != NULL, false); girara_argument_t arg = { GIRARA_NEXT, argument->data }; if (argument->n == PREVIOUS) { arg.n = GIRARA_PREVIOUS; } return girara_sc_tab_navigate(session, &arg, event, t); } bool sc_navigate_history(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); jumanji_t* jumanji = session->global.data; g_return_val_if_fail(argument != NULL, false); jumanji_tab_t* tab = jumanji_tab_get_current(jumanji); if (tab && tab->web_view) { if (argument->n == NEXT) { webkit_web_view_go_forward(WEBKIT_WEB_VIEW(tab->web_view)); } else { webkit_web_view_go_back(WEBKIT_WEB_VIEW(tab->web_view)); } } return false; } bool sc_put(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); jumanji_t* jumanji = session->global.data; g_return_val_if_fail(argument != NULL, false); GtkClipboard* clipboard; char* default_clipboard = NULL; girara_setting_get(session, "default-clipboard", &default_clipboard); if (g_strcmp0(default_clipboard, "secondary") == 0) { clipboard = gtk_clipboard_get(GDK_SELECTION_SECONDARY); } else if (g_strcmp0(default_clipboard, "clipboard") == 0) { clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); } else { clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); } if (clipboard == NULL) { return false; } char* text = gtk_clipboard_wait_for_text(clipboard); char* url = jumanji_build_url_from_string(jumanji, text); if (url == NULL) { return false; } if (argument->n == NEW_TAB) { bool focus_new_tabs; girara_setting_get(jumanji->ui.session, "focus-new-tabs", &focus_new_tabs); jumanji_tab_new(jumanji, url, focus_new_tabs); } else { jumanji_tab_t* tab = jumanji_tab_get_current(jumanji); if (tab != NULL) { jumanji_tab_load_url(tab, url); } } g_free(url); g_free(text); return false; } bool sc_quit(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); girara_argument_t arg = { GIRARA_HIDE, NULL }; girara_isc_completion(session, &arg, NULL, 0); cb_destroy(NULL, NULL); gtk_main_quit(); return false; } bool sc_scroll(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); jumanji_t* jumanji = session->global.data; g_return_val_if_fail(argument != NULL, false); jumanji_tab_t* tab = jumanji_tab_get_current(jumanji); if (tab == NULL) { return false; } GtkAdjustment* adjustment = NULL; if ( (argument->n == LEFT) || (argument->n == RIGHT) || (argument->n == BEGIN) || (argument->n == END) ) adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(tab->scrolled_window)); else adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(tab->scrolled_window)); gdouble view_size = gtk_adjustment_get_page_size(adjustment); gdouble value = gtk_adjustment_get_value(adjustment); gdouble max = gtk_adjustment_get_upper(adjustment) - view_size; int scroll_step = 40; girara_setting_get(jumanji->ui.session, "scroll-step", &scroll_step); gdouble new_value; switch(argument->n) { case FULL_UP: new_value = (value - view_size) < 0 ? 0 : (value - view_size); break; case FULL_DOWN: new_value = (value + view_size) > max ? max : (value + view_size); break; case HALF_UP: new_value = (value - (view_size / 2)) < 0 ? 0 : (value - (view_size / 2)); break; case HALF_DOWN: new_value = (value + (view_size / 2)) > max ? max : (value + (view_size / 2)); break; case LEFT: case UP: new_value = (value - scroll_step) < 0 ? 0 : (value - scroll_step); break; case RIGHT: case DOWN: new_value = (value + scroll_step) > max ? max : (value + scroll_step); break; case BEGIN: case TOP: new_value = 0; break; case END: case BOTTOM: new_value = max; break; default: new_value = 0; } gtk_adjustment_set_value(adjustment, new_value); if (new_value == max || new_value == 0) { return false; } else { return true; } } bool sc_search(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); jumanji_t* jumanji = session->global.data; g_return_val_if_fail(argument != NULL, false); jumanji_tab_t* tab = jumanji_tab_get_current(jumanji); if (tab == NULL || tab->web_view == NULL) { return false; } if (jumanji->search.item == NULL) { return false; } gboolean direction = (argument->n == BACKWARDS) ? FALSE : TRUE; webkit_web_view_search_text(WEBKIT_WEB_VIEW(tab->web_view), jumanji->search.item, FALSE, direction, TRUE); return true; } bool sc_reload(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); jumanji_t* jumanji = session->global.data; g_return_val_if_fail(argument != NULL, false); jumanji_tab_t* tab = jumanji_tab_get_current(jumanji); if (tab != NULL && tab->web_view != NULL) { if (argument->n == BYPASS_CACHE) { webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(tab->web_view)); } else { webkit_web_view_reload(WEBKIT_WEB_VIEW(tab->web_view)); } } return false; } bool sc_restore(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); jumanji_t* jumanji = session->global.data; if (jumanji->global.last_closed == NULL || girara_list_size(jumanji->global.last_closed) == 0) { return false; } char* uri = girara_list_nth(jumanji->global.last_closed, 0); if (uri == NULL) { return false; } bool focus_new_tabs; girara_setting_get(jumanji->ui.session, "focus-new-tabs", &focus_new_tabs); jumanji_tab_new(jumanji, uri, focus_new_tabs); girara_list_remove(jumanji->global.last_closed, uri); return true; } bool sc_toggle_bookmark(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); jumanji_t* jumanji = session->global.data; g_return_val_if_fail(argument != NULL, false); jumanji_tab_t* tab = jumanji_tab_get_current(jumanji); if (tab == NULL || tab->web_view == NULL || jumanji->database== NULL) { return false; } const char* url = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(tab->web_view)); const char* title = webkit_web_view_get_title(WEBKIT_WEB_VIEW(tab->web_view)); if (url == NULL) { return false; } gchar* escaped_url = g_markup_escape_text(url, -1); girara_list_t* results = jumanji_db_bookmark_find(jumanji->database, url); if (results && girara_list_size(results) > 0) { jumanji_db_bookmark_remove(jumanji->database, url); girara_notify(session, GIRARA_INFO, "Removed bookmark: %s", escaped_url); } else { jumanji_db_bookmark_add(jumanji->database, url, title); girara_notify(session, GIRARA_INFO, "Added bookmark: %s", escaped_url); } girara_list_free(results); g_free(escaped_url); return false; } bool sc_toggle_proxy(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); return cb_statusbar_proxy(NULL, NULL, session); } bool sc_toggle_plugins(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); bool value = true; girara_setting_get(session, "enable-plugins", &value); value = !value; girara_setting_set(session, "enable-plugins", &value); return false; } bool sc_toggle_source_mode(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); jumanji_t* jumanji = session->global.data; g_return_val_if_fail(argument != NULL, false); jumanji_tab_t* tab = jumanji_tab_get_current(jumanji); if (tab == NULL || tab->web_view == NULL) { return false; } char* url = (char*) webkit_web_view_get_uri(WEBKIT_WEB_VIEW(tab->web_view)); if(webkit_web_view_get_view_source_mode(WEBKIT_WEB_VIEW(tab->web_view))) { webkit_web_view_set_view_source_mode(WEBKIT_WEB_VIEW(tab->web_view), FALSE); } else { webkit_web_view_set_view_source_mode(WEBKIT_WEB_VIEW(tab->web_view), TRUE); } jumanji_tab_load_url(tab, url); return false; } bool sc_yank(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); jumanji_t* jumanji = session->global.data; g_return_val_if_fail(argument != NULL, false); jumanji_tab_t* tab = jumanji_tab_get_current(jumanji); if (tab == NULL) { return false; } char* url = (char*) webkit_web_view_get_uri(WEBKIT_WEB_VIEW(tab->web_view)); GtkClipboard* clipboard; char* default_clipboard = NULL; girara_setting_get(session, "default-clipboard", &default_clipboard); if (g_strcmp0(default_clipboard, "secondary") == 0) { clipboard = gtk_clipboard_get(GDK_SELECTION_SECONDARY); } else if (g_strcmp0(default_clipboard, "clipboard") == 0) { clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); } else { clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); } if (clipboard != NULL) { gchar* escaped_url = g_markup_escape_text(url, -1); gtk_clipboard_set_text(clipboard, url, -1); girara_notify(session, GIRARA_INFO, "Yanked: %s", escaped_url); g_free(escaped_url); } return false; } bool sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); jumanji_t* jumanji = session->global.data; g_return_val_if_fail(argument != NULL, false); jumanji_tab_t* tab = jumanji_tab_get_current(jumanji); if (tab == NULL) { return false; } int zoom_step = 10; girara_setting_get(jumanji->ui.session, "zoom-step", &zoom_step); const float zoom_level = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(tab->web_view)); const float step = zoom_step / 100.0f; if(argument->n == ZOOM_IN) { webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(tab->web_view), zoom_level + step); } else if(argument->n == ZOOM_OUT) { webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(tab->web_view), zoom_level - step); } else if(argument->n == DEFAULT) { webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(tab->web_view), 1.0f); } else if(argument->n == ZOOM_SPECIFIC) { webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(tab->web_view), t / 100.0f); } return false; } bool sc_toggle_stylesheet(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { jumanji_t* jumanji = session->global.data; g_return_val_if_fail(session != NULL, false); gchar* user_stylesheet_uri = NULL; girara_setting_get(session, "user-stylesheet-uri", &user_stylesheet_uri); gchar* empty_string = ""; if (g_strcmp0(user_stylesheet_uri, empty_string) == 0) { girara_setting_set(session, "user-stylesheet-uri", jumanji->global.user_stylesheet_uri); } else if (g_strcmp0(user_stylesheet_uri, jumanji->global.user_stylesheet_uri) == 0) { girara_setting_set(session, "user-stylesheet-uri", empty_string); } else { g_free(jumanji->global.user_stylesheet_uri); jumanji->global.user_stylesheet_uri = g_strdup(user_stylesheet_uri); girara_setting_set(session, "user-stylesheet-uri", empty_string); } return false; }
2.265625
2
2024-11-18T18:10:09.062717+00:00
2017-03-06T16:23:40
52bf27d9a1bf89db2ebe443b2ffaa4dfe35393c7
{ "blob_id": "52bf27d9a1bf89db2ebe443b2ffaa4dfe35393c7", "branch_name": "refs/heads/master", "committer_date": "2017-03-06T16:23:40", "content_id": "356870d9589d5594d79b63217bca662953d7034e", "detected_licenses": [ "MIT" ], "directory_id": "1030ae28cb4169c6e715caf36855e58a5e1ebb29", "extension": "c", "filename": "parser_room.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 84093936, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2571, "license": "MIT", "license_type": "permissive", "path": "/src/parser_room.c", "provenance": "stackv2-0003.json.gz:330412", "repo_name": "jde-maga/lem-in", "revision_date": "2017-03-06T16:23:40", "revision_id": "acc0aa697cda14c3e9d323c997a1d8a7c4b0c7eb", "snapshot_id": "0351685d37ae4c773f835edd22ea9123f2fd9558", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/jde-maga/lem-in/acc0aa697cda14c3e9d323c997a1d8a7c4b0c7eb/src/parser_room.c", "visit_date": "2021-01-17T14:36:48.687165" }
stackv2
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* parser_room.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jde-maga <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/05/27 14:09:44 by jde-maga #+# #+# */ /* Updated: 2016/07/21 18:57:41 by jde-maga ### ########.fr */ /* */ /* ************************************************************************** */ #include <lemin.h> static void room_first_letter(t_room **room) { int i; i = 0; while (room[i] != NULL) { if (ft_strchr(room[i]->name, '-') || room[i]->name[0] == 'L' || room[i]->name[0] == '#') lemin_error("A room name is invalid"); i++; } } void room_error(t_room **room, t_linkid *linkid) { int i; int j; room_first_letter(room); i = 0; while (room[i] != NULL) { j = i + 1; while (room[j] != NULL) { if (room[i]->coord_x == room[j]->coord_x && room[i]->coord_y == room[j]->coord_y) lemin_error("2 rooms have the same coordinates"); if (!ft_strcmp(room[i]->name, room[j]->name)) lemin_error("2 rooms have the same name"); j++; } i++; } if (linkid->start_id < 0 || linkid->end_id < 0) lemin_error("start / end not properly defined"); } static void room_init_handle(char **line, t_room **room, int id) { int i; char *buf; i = 0; room_syntax_error(*line); while ((*line)[i] != ' ') i++; *room = lemin_room_init(); (*room)->id = id; (*room)->name = ft_strnew(i + 1); (*room)->name = ft_strncpy((*room)->name, *line, i); *line += i + 1; i = 0; while ((*line)[i] != ' ') i++; buf = ft_strnew(i); ft_strncpy(buf, *line, i); (*room)->coord_x = ft_atoi(buf); *line += i + 1; i = 0; free(buf); } t_room *room_parser(char *line, t_linkid *linkid) { t_room *room; static int id; int i; char *buf; id++; if (linkid->start_id == -2) linkid->start_id = id; if (linkid->end_id == -2) linkid->end_id = id; room_init_handle(&line, &room, id); i = 0; while (line[i]) i++; buf = ft_strnew(i); ft_strncpy(buf, line, i); room->coord_y = ft_atoi(buf); free(buf); return (room); }
2.6875
3
2024-11-18T18:10:09.457222+00:00
2016-11-12T05:40:24
c28f4461c898d9ecab89c936b3fb36a166d5ea89
{ "blob_id": "c28f4461c898d9ecab89c936b3fb36a166d5ea89", "branch_name": "refs/heads/master", "committer_date": "2016-11-12T05:40:24", "content_id": "b425aa5e9fe028e5941c63f3b6e7836bdcc5784f", "detected_licenses": [ "MIT" ], "directory_id": "f187b959d110987af04d685dc503c87cfcb08242", "extension": "c", "filename": "AttachMause.c", "fork_events_count": 1, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 67371023, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1416, "license": "MIT", "license_type": "permissive", "path": "/PC/AttachMause.c", "provenance": "stackv2-0003.json.gz:330796", "repo_name": "jphacks/NG_1603", "revision_date": "2016-11-12T05:40:24", "revision_id": "47f30932cd5035a4f58f1b6864ae49702cec408b", "snapshot_id": "5c17b96acf350b766a4d8294b0668881e34e82f6", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/jphacks/NG_1603/47f30932cd5035a4f58f1b6864ae49702cec408b/PC/AttachMause.c", "visit_date": "2020-01-23T21:29:22.116261" }
stackv2
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <windows.h> int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char buf[256],str[256],date[256]; FILE *fp; int x,y,X,Y,L=0,R=0,Lb,Rb,PC_MAX_X,PC_MAX_Y,D_MAX_X,D_MAX_Y,LEN=26,flag=0; double CO_X,CO_Y; PC_MAX_X=GetSystemMetrics(SM_CXSCREEN); PC_MAX_Y=GetSystemMetrics(SM_CYSCREEN); while(1) { fp = fopen ("teraterm.log", "r"); if(fgets(buf,256,fp)!=NULL&&flag==0) { if(strlen(buf)>=LEN-4) { sscanf(buf,"%d,%d",&D_MAX_X,&D_MAX_Y); CO_X=(double)PC_MAX_X/D_MAX_Y; CO_Y=(double)PC_MAX_Y/D_MAX_X; flag=1; printf("D_MAX_X %d\nD_MAX_Y %d\nCO_X %.20lf\nCO_Y %.20lf\n",D_MAX_X,D_MAX_Y, CO_X,CO_Y); } } while (fgets(buf,256,fp) != NULL) { strcpy(date,str); strcpy(str,buf); } //printf("%s",date); if(strlen(date)>=LEN-4) { sscanf(date,"%d,%d,%d,%d",&X,&Y,&L,&R); x=round(1280-Y*CO_X); y=round(X*CO_Y); SetCursorPos(x,y); if(L==1&&Lb==0) mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); else if(L==0&&Lb==1) mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); else if(R==1&&Rb==0) mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0); else if(R==0&&Rb==1) mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0); Lb=L; Rb=R; } fclose( fp ); } return 0; }
2.21875
2
2024-11-18T18:10:09.898174+00:00
2021-09-18T17:50:04
a307aadde8141065d8bb90925af549be2f77f708
{ "blob_id": "a307aadde8141065d8bb90925af549be2f77f708", "branch_name": "refs/heads/master", "committer_date": "2021-09-18T17:50:04", "content_id": "6ea19f5ffe66366044f08a5e9565f068b02b2778", "detected_licenses": [ "MIT" ], "directory_id": "f1a6ded5deef14c7af683ac21579bcc46369d947", "extension": "c", "filename": "example.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": null, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 227, "license": "MIT", "license_type": "permissive", "path": "/optional-overflow-exercises/bof/example.c", "provenance": "stackv2-0003.json.gz:331052", "repo_name": "mfranzil-unitn/unitn-m-st", "revision_date": "2021-09-18T17:50:04", "revision_id": "7d32acee2d3bea658cec4cd3b0eda22e82c8ecad", "snapshot_id": "79e9fbd658257a45bbc9cbd0da6b17c8634b3289", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/mfranzil-unitn/unitn-m-st/7d32acee2d3bea658cec4cd3b0eda22e82c8ecad/optional-overflow-exercises/bof/example.c", "visit_date": "2023-08-04T06:01:41.765976" }
stackv2
#include <stdio.h> #include <string.h> int foo() { char a = 'a'; char buf[3]; char password[] = "hi"; strcpy(buf, password); printf("%s", buf); \\printf("\n%c", a); return 0; } int main() { foo(); return 0; }
2.5625
3
2024-11-18T18:22:45.282617+00:00
2020-01-26T10:24:35
c29498085d21220ba48237541784fc22630d4f82
{ "blob_id": "c29498085d21220ba48237541784fc22630d4f82", "branch_name": "refs/heads/master", "committer_date": "2020-01-26T10:24:35", "content_id": "1a680bcd895d05df318a7a23d2785f8443b80957", "detected_licenses": [ "MIT" ], "directory_id": "d7f444a7110f4b8e2b86e1b5348d77afea6817c9", "extension": "c", "filename": "serializer.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": null, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 10552, "license": "MIT", "license_type": "permissive", "path": "/src/serializer.c", "provenance": "stackv2-0003.json.gz:380121", "repo_name": "veeso/liboctopipes", "revision_date": "2020-01-26T10:24:35", "revision_id": "a9833c10046d8d8fd312101c5273b6bec5da8c53", "snapshot_id": "f58c9fe0d7f0824e92f027f45e5e502d9e4f2097", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/veeso/liboctopipes/a9833c10046d8d8fd312101c5273b6bec5da8c53/src/serializer.c", "visit_date": "2022-04-04T17:43:38.940404" }
stackv2
/** * Octopipes * Developed by Christian Visintin * * MIT License * Copyright (c) 2019-2020 Christian Visintin * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. **/ #include <octopipes/serializer.h> #include <string.h> #define SOH 0x01 #define STX 0x02 #define ETX 0x03 /** * @brief decode an octopipe message * @param uint8_t* data read from FIFO * @param size_t data size * @param OctopipesMessage** * @return OctopipesError */ OctopipesError octopipes_decode(const uint8_t* data, const size_t data_size, OctopipesMessage** message) { (*message) = (OctopipesMessage*) malloc(sizeof(OctopipesMessage)); size_t current_minimum_size = 17; //Minimum packet size counting static sizes size_t data_ptr = 0; OctopipesMessage* message_ptr = *message; if (message_ptr == NULL) { return OCTOPIPES_ERROR_BAD_ALLOC; } message_ptr->data = NULL; message_ptr->origin = NULL; message_ptr->remote = NULL; if (data_size < current_minimum_size || data == NULL) { //Minimum packet size goto decode_bad_packet; } if (data[0] != SOH || data[data_size - 1] != ETX) { //Check first and last byte goto decode_bad_packet; } message_ptr->version = (OctopipesVersion) data[1]; if (message_ptr->version == OCTOPIPES_VERSION_1) { //Octopipes version 1 //Origin and remote message_ptr->origin_size = data[2]; current_minimum_size += message_ptr->origin_size; //Check size for origin if (data_size < current_minimum_size) { goto decode_bad_packet; } //Allocate origin size data_ptr = 3; //next position after SOH + VERSION + LNS if (message_ptr->origin_size > 0) { message_ptr->origin = (char*) malloc(sizeof(char) * message_ptr->origin_size + 1); //+1 null terminator if (message_ptr->origin == NULL) { goto decode_bad_alloc; } memcpy(message_ptr->origin, data + data_ptr, message_ptr->origin_size); message_ptr->origin[message_ptr->origin_size] = 0x00; data_ptr += message_ptr->origin_size; } else { message_ptr->origin = NULL; } //Remote message_ptr->remote_size = data[data_ptr]; current_minimum_size += message_ptr->remote_size; if (data_size < current_minimum_size) { goto decode_bad_packet; } data_ptr++; if (message_ptr->remote_size > 0) { message_ptr->remote = (char*) malloc(sizeof(char) * message_ptr->remote_size + 1); if (message_ptr->remote == NULL) { goto decode_bad_alloc; } memcpy(message_ptr->remote, data + data_ptr, message_ptr->remote_size); message_ptr->remote[message_ptr->remote_size] = 0x00; } else { message_ptr->remote = NULL; } data_ptr += message_ptr->remote_size; //TTL message_ptr->ttl = data[data_ptr++]; //Data size message_ptr->data_size = data[data_ptr++]; // 0 message_ptr->data_size = message_ptr->data_size << 8; message_ptr->data_size += data[data_ptr++]; // 1 message_ptr->data_size = message_ptr->data_size << 8; message_ptr->data_size += data[data_ptr++]; // 2 message_ptr->data_size = message_ptr->data_size << 8; message_ptr->data_size += data[data_ptr++]; // 3 message_ptr->data_size = message_ptr->data_size << 8; message_ptr->data_size += data[data_ptr++]; // 4 message_ptr->data_size = message_ptr->data_size << 8; message_ptr->data_size += data[data_ptr++]; // 5 message_ptr->data_size = message_ptr->data_size << 8; message_ptr->data_size += data[data_ptr++]; // 6 message_ptr->data_size = message_ptr->data_size << 8; message_ptr->data_size += data[data_ptr++]; // 7 //Options message_ptr->options = data[data_ptr++]; //Checksum message_ptr->checksum = data[data_ptr++]; //Verify STX if (data[data_ptr++] != STX) { goto decode_bad_packet; } //Read data current_minimum_size += message_ptr->data_size; if (data_size < message_ptr->data_size) { goto decode_bad_packet; } if (message_ptr->data_size > 0) { message_ptr->data = (uint8_t*) malloc(sizeof(uint8_t) * message_ptr->data_size); if (message_ptr->data == NULL) { goto decode_bad_alloc; } memcpy(message_ptr->data, data + data_ptr, message_ptr->data_size); } //Verify checksum if required if ((message_ptr->options & OCTOPIPES_OPTIONS_IGNORE_CHECKSUM) == 0) { uint8_t verification_checksum = calculate_checksum(message_ptr); if (verification_checksum != message_ptr->checksum) { goto decode_bad_checksum; } } //@! Decoding OK } else { //Unsupported protocol version free(message_ptr); return OCTOPIPES_ERROR_UNSUPPORTED_VERSION; } return OCTOPIPES_ERROR_SUCCESS; decode_bad_packet: if (message_ptr->origin != NULL) { free(message_ptr->origin); } if (message_ptr->remote != NULL) { free(message_ptr->remote); } if (message_ptr->data != NULL) { free(message_ptr->data); } free(message_ptr); return OCTOPIPES_ERROR_BAD_PACKET; decode_bad_alloc: if (message_ptr->origin != NULL) { free(message_ptr->origin); } if (message_ptr->remote != NULL) { free(message_ptr->remote); } if (message_ptr->data != NULL) { free(message_ptr->data); } free(message_ptr); return OCTOPIPES_ERROR_BAD_ALLOC; decode_bad_checksum: if (message_ptr->origin != NULL) { free(message_ptr->origin); } if (message_ptr->remote != NULL) { free(message_ptr->remote); } if (message_ptr->data != NULL) { free(message_ptr->data); } free(message_ptr); return OCTOPIPES_ERROR_BAD_CHECKSUM; } /** * @brief encode an OctopipeMessage structure into the buffer to write to the FIFO * @param OctopipesMessage* message structure * @param size_t* data size of out buffer * @return uint8_t* */ OctopipesError octopipes_encode(OctopipesMessage* message, uint8_t** data, size_t* data_size) { //Prepare encoding uint8_t* out_data; if (message->version == OCTOPIPES_VERSION_1) { //Calculate required size *data_size = 17; //Minimum size *data_size += message->remote_size; *data_size += message->origin_size; *data_size += message->data_size; out_data = (uint8_t*) malloc(sizeof(uint8_t) * *data_size); if (out_data == NULL) { return OCTOPIPES_ERROR_BAD_ALLOC; } size_t data_ptr = 0; //SOH out_data[data_ptr++] = SOH; //Version out_data[data_ptr++] = message->version; //Origin / origin_size out_data[data_ptr++] = message->origin_size; memcpy(out_data + data_ptr, message->origin, message->origin_size); data_ptr += message->origin_size; //Remote / remote size out_data[data_ptr++] = message->remote_size; memcpy(out_data + data_ptr, message->remote, message->remote_size); data_ptr += message->remote_size; //TTL out_data[data_ptr++] = message->ttl; //Data size out_data[data_ptr++] = (message->data_size >> 56) & 0xFF; out_data[data_ptr++] = (message->data_size >> 48) & 0xFF; out_data[data_ptr++] = (message->data_size >> 40) & 0xFF; out_data[data_ptr++] = (message->data_size >> 32) & 0xFF; out_data[data_ptr++] = (message->data_size >> 24) & 0xFF; out_data[data_ptr++] = (message->data_size >> 16) & 0xFF; out_data[data_ptr++] = (message->data_size >> 8) & 0xFF; out_data[data_ptr++] = message->data_size & 0xFF; //Options out_data[data_ptr++] = message->options; //Keep position of checksum, and go ahead size_t checksum_ptr = data_ptr; data_ptr++; //STX out_data[data_ptr++] = STX; //Write data memcpy(out_data + data_ptr, message->data, message->data_size); data_ptr += message->data_size; //Write ETX out_data[data_ptr++] = ETX; //Checksum as last thing message->checksum = 0; if ((message->options & OCTOPIPES_OPTIONS_IGNORE_CHECKSUM) == 0) { message->checksum = calculate_checksum(message); } out_data[checksum_ptr] = message->checksum; } else { return OCTOPIPES_ERROR_UNSUPPORTED_VERSION; } //Assign out data to data *data = out_data; return OCTOPIPES_ERROR_SUCCESS; } /** * @brief calculate checksum for message * @param OctopipesMessage* * @return uint8_t checksum */ uint8_t calculate_checksum(const OctopipesMessage* message) { uint8_t checksum = SOH; //Start with SOH if (message->version == OCTOPIPES_VERSION_1) { checksum = checksum ^ message->version; checksum = checksum ^ message->origin_size; for (size_t i = 0; i < message->origin_size; i++) { checksum = checksum ^ message->origin[i]; } checksum = checksum ^ message->remote_size; for (size_t i = 0; i < message->remote_size; i++) { checksum = checksum ^ message->remote[i]; } checksum = checksum ^ message->ttl; //Data size checksum = checksum ^ ((message->data_size >> 56) & 0xFF); checksum = checksum ^ ((message->data_size >> 48) & 0xFF); checksum = checksum ^ ((message->data_size >> 40) & 0xFF); checksum = checksum ^ ((message->data_size >> 32) & 0xFF); checksum = checksum ^ ((message->data_size >> 24) & 0xFF); checksum = checksum ^ ((message->data_size >> 16) & 0xFF); checksum = checksum ^ ((message->data_size >> 8) & 0xFF); checksum = checksum ^ (message->data_size & 0xFF); checksum = checksum ^ message->options; checksum = checksum ^ STX; for (size_t i = 0; i < message->data_size; i++) { checksum = checksum ^ message->data[i]; } } checksum = checksum ^ ETX; //Eventually xor with etx return checksum; }
2.546875
3
2024-11-18T18:22:45.611048+00:00
2018-06-09T16:43:47
d490d92a437bb4c1e68cf8a505ab5d07fb33c222
{ "blob_id": "d490d92a437bb4c1e68cf8a505ab5d07fb33c222", "branch_name": "refs/heads/master", "committer_date": "2018-06-09T16:43:47", "content_id": "317fe0d9c31249daabce3f5f570c2cedacf100af", "detected_licenses": [ "MIT" ], "directory_id": "2535610eeb6f34504b092649a7297a693cbe4f13", "extension": "h", "filename": "queuelib.h", "fork_events_count": 0, "gha_created_at": "2018-07-09T13:47:42", "gha_event_created_at": "2018-07-09T13:47:42", "gha_language": null, "gha_license_id": "MIT", "github_id": 140291913, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1302, "license": "MIT", "license_type": "permissive", "path": "/headers/queuelib.h", "provenance": "stackv2-0003.json.gz:380636", "repo_name": "Micky992/LabASD", "revision_date": "2018-06-09T16:43:47", "revision_id": "57383077cfcef6a9eafe06c44e9bc7a66bf1e378", "snapshot_id": "3e05c49d2ac50049a5b227609a56b21edbeb307b", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/Micky992/LabASD/57383077cfcef6a9eafe06c44e9bc7a66bf1e378/headers/queuelib.h", "visit_date": "2020-03-22T15:57:22.579742" }
stackv2
#ifndef QUEUELIB_H #define QUEUELIB_H typedef struct queue queue; /*la queue e' una struttura dati FIFO, il primo intero inserito sara' il primo estratto gestita attraverso un puntatore a queue*/ queue *creaQueue(int dim_max); /*alloca memoria per una nuova queue di massimo dim_max elementi ritorna un puntatore all'area di memoria*/ queue *eliminaQueue(queue *Q); /*dato un puntatore a queue libera la memoria occupata dalla queue ritorna NULL se l'operazione e' andata a buon fine*/ int queueEmpty(queue *Q); /*dato un puntatore a queue ritorna un intero diverso da 0 se la queue e' vuota, 0 se e' presente almeno un elemento l'utilizzo su puntatori NULL e' WIP*/ int queueFull(queue *Q); /*dato un puntatore a queue ritorna un intero diverso da 0 se la queue e' piena, 0 se ha almeno un posto vuoto l'utilizzo su puntatori NULL e' WIP*/ void enqueue(queue *Q, int da_inserire); /*dato un puntatore a queue e un intero da_inserire inserisce l'intero nella queue l'utilizzo su puntatori NULL e' WIP*/ int dequeue(queue *Q); /*dato un puntatore a queue, estrae il prossimo intero restituisce l'intero estratto l'utilizzo su puntatori NULL e' WIP*/ void stampaQueue(queue *Q); /*dato un puntatore a queue stampa gli elementi separati da uno spazio l'utilizzo su puntatori NULL e' WIP*/ #endif
2.609375
3
2024-11-18T18:22:47.168912+00:00
2018-06-26T11:02:32
fe05ef9a7d7dbd798c7fc7cb1ca5d3a0cf2723a1
{ "blob_id": "fe05ef9a7d7dbd798c7fc7cb1ca5d3a0cf2723a1", "branch_name": "refs/heads/master", "committer_date": "2018-06-26T11:02:32", "content_id": "4d836ede1a878d98a0357cbb85c09efd293b9bc2", "detected_licenses": [ "MIT" ], "directory_id": "d4b1063f8146b6a0d1ac50288bc0c46a5e911464", "extension": "c", "filename": "Zadanie-1.4.8.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 137848663, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 390, "license": "MIT", "license_type": "permissive", "path": "/Krzaczkowski/#Rozdzial 01-27.05.18/Zadanie-1.4.8.c", "provenance": "stackv2-0003.json.gz:381795", "repo_name": "antonitomaszewski/Jezyk-C-", "revision_date": "2018-06-26T11:02:32", "revision_id": "596b5f3add6698ffee3a485a727db3b6e3cf5b0a", "snapshot_id": "426d69c2a0365e1f9c6c62b498d2274c03d56123", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/antonitomaszewski/Jezyk-C-/596b5f3add6698ffee3a485a727db3b6e3cf5b0a/Krzaczkowski/#Rozdzial 01-27.05.18/Zadanie-1.4.8.c", "visit_date": "2020-03-20T23:29:12.044907" }
stackv2
#include <stdio.h> int main() { int n, i, fib_1 = 1, fib_2 = 1, pom; printf ("Podaj liczbę całkowitą n:"); scanf("%d", &n); for (i = 2; i <= n; i++) { pom = fib_1; fib_1 = fib_1 + fib_2; fib_2 = pom; } printf("Elem ciągu Fibonacciego o indeksie %d to %d\n", n, fib_1); return 0; }
3.21875
3
2024-11-18T18:22:48.104331+00:00
2020-10-20T13:48:32
2bab4a859012dc53ae6a2dd17c58d3008ef85895
{ "blob_id": "2bab4a859012dc53ae6a2dd17c58d3008ef85895", "branch_name": "refs/heads/master", "committer_date": "2020-10-20T13:48:32", "content_id": "c5bb397f08181ad4244674d898ece394d150d8bd", "detected_licenses": [ "MIT" ], "directory_id": "13e65d48f1ff67004238be955919d48bec25f848", "extension": "h", "filename": "fluid_atomic.h", "fork_events_count": 2, "gha_created_at": "2020-09-12T10:23:49", "gha_event_created_at": "2020-10-17T07:44:12", "gha_language": "C", "gha_license_id": "MIT", "github_id": 294920353, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2925, "license": "MIT", "license_type": "permissive", "path": "/android/src/main/jni/fluidsynth/src/utils/fluid_atomic.h", "provenance": "stackv2-0003.json.gz:382311", "repo_name": "FYLSunghwan/react-native-piano-sampler", "revision_date": "2020-10-20T13:48:32", "revision_id": "b9fe5416c42afa4808bc66ed85a9bd38f9b0c9f6", "snapshot_id": "9fc19d3b5a6b0dbbb6ee4471df3e41206c01da5f", "src_encoding": "UTF-8", "star_events_count": 10, "url": "https://raw.githubusercontent.com/FYLSunghwan/react-native-piano-sampler/b9fe5416c42afa4808bc66ed85a9bd38f9b0c9f6/android/src/main/jni/fluidsynth/src/utils/fluid_atomic.h", "visit_date": "2023-01-02T07:35:48.764685" }
stackv2
#ifndef _FLUID_ATOMIC_H #define _FLUID_ATOMIC_H #include <stdbool.h> #ifndef STATIC_ASSERT #if __STDC_VERSION__ >= 201112L #define STATIC_ASSERT _Static_assert #else #define STATIC_ASSERT(expr, msg) typedef char __static_assertion_ ## __COUNTER__[(expr) ? 1 : -1] #endif #endif //STATIC_ASSERT #ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 #define fluid_atomic_int_add(atomic, val) __extension__ ({ \ STATIC_ASSERT(sizeof((atomic)->value) == sizeof(int), \ "Atomic must be the size of an int"); \ __sync_fetch_and_add(&(atomic)->value, (val));}) #define fluid_atomic_int_get(atomic) __extension__ ({ \ STATIC_ASSERT(sizeof((atomic)->value) == sizeof(int), \ "Atomic must be the size of an int"); \ __sync_synchronize(); \ (atomic)->value;}) #define fluid_atomic_int_set(atomic, newval) __extension__ ({ \ STATIC_ASSERT(sizeof((atomic)->value) == sizeof(int), \ "Atomic must be the size of an int"); \ (atomic)->value = (newval); \ __sync_synchronize();}) #define fluid_atomic_int_inc(atomic) __extension__ ({ \ STATIC_ASSERT(sizeof((atomic)->value) == sizeof(int), \ "Atomic must be the size of an int"); \ __sync_synchronize(); \ __sync_fetch_and_add(&(atomic)->value, 1);}) #define fluid_atomic_int_compare_and_exchange(atomic, oldval, newval) __extension__ ({ \ STATIC_ASSERT(sizeof((atomic)->value) == sizeof(int), \ "Atomic must be the size of an int"); \ __sync_bool_compare_and_swap(&(atomic)->value, (oldval), (newval));}) #define fluid_atomic_int_exchange_and_add(atomic, add) __extension__ ({ \ STATIC_ASSERT(sizeof((atomic)->value) == sizeof(int), \ "Atomic must be the size of an int"); \ __sync_synchronize(); \ __sync_fetch_and_add(&(atomic)->value, add);}) #define fluid_atomic_float_get(atomic) __extension__ ({ \ STATIC_ASSERT(sizeof((atomic)->value) == sizeof(float), \ "Atomic must be the size of a float"); \ __sync_synchronize(); \ (atomic)->value;}) #define fluid_atomic_float_set(atomic, val) __extension__ ({ \ STATIC_ASSERT(sizeof((atomic)->value) == sizeof(float), \ "Atomic must be the size of a float"); \ (atomic)->value = (val); \ __sync_synchronize();}) #else #error "GCC builtins missings for atomic operations" #endif #endif /* _FLUID_ATOMIC_H */
2.4375
2
2024-11-18T18:22:48.263574+00:00
2022-02-10T17:59:28
d3f9b3d52afa1360dc11671212efb5392afe1044
{ "blob_id": "d3f9b3d52afa1360dc11671212efb5392afe1044", "branch_name": "refs/heads/main", "committer_date": "2022-02-10T17:59:28", "content_id": "14bc447672d62bf6d0a6879f9910cd9bf71b38cb", "detected_licenses": [ "MIT" ], "directory_id": "20a00b0a1f2dc921b2362f76593c0dd6b17d771e", "extension": "c", "filename": "ssp.c", "fork_events_count": 5, "gha_created_at": "2018-09-21T00:34:38", "gha_event_created_at": "2023-01-26T19:54:16", "gha_language": "Python", "gha_license_id": "MIT", "github_id": 149687515, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1288, "license": "MIT", "license_type": "permissive", "path": "/vice/src/objects/ssp.c", "provenance": "stackv2-0003.json.gz:382568", "repo_name": "giganano/VICE", "revision_date": "2022-02-10T17:59:28", "revision_id": "627821b1c0bc974bea49451d57aa1313c1d24d3e", "snapshot_id": "0414742acdf7ad5475220f7e18e3ab2c29008ce0", "src_encoding": "UTF-8", "star_events_count": 27, "url": "https://raw.githubusercontent.com/giganano/VICE/627821b1c0bc974bea49451d57aa1313c1d24d3e/vice/src/objects/ssp.c", "visit_date": "2023-04-17T02:01:12.347578" }
stackv2
/* * This file implements memory management for the SSP object. */ #include <stdlib.h> #include "../ssp.h" #include "objects.h" #include "ssp.h" /* * Allocate memory for and return a pointer to an SSP struct. Automatically * sets both crf and msmf to NULL. Allocates memory for a 100-element char * * IMF specifier. * * header: ssp.h */ extern SSP *ssp_initialize(void) { /* * The imf object is initialized with the default lower and upper mass * limits. They will be modified by the python wrapper in VICE anyway. * This keeps the implementation simpler in that now singlezone_initialize * does not need to take arguments for the mass limits. */ SSP *ssp = (SSP *) malloc (sizeof(SSP)); ssp -> imf = imf_initialize( SSP_IMF_DEFAULT_M_LOWER, SSP_IMF_DEFAULT_M_UPPER ); ssp -> crf = NULL; ssp -> msmf = NULL; return ssp; } /* * Free up the memory stored in an SSP struct. * * header: ssp.h */ extern void ssp_free(SSP *ssp) { if (ssp != NULL) { if ((*ssp).crf != NULL) { free(ssp -> crf); ssp -> crf = NULL; } else {} if ((*ssp).msmf != NULL) { free(ssp -> msmf); ssp -> msmf = NULL; } else {} if ((*ssp).imf != NULL) { imf_free(ssp -> imf); ssp -> imf = NULL; } else {} free(ssp); ssp = NULL; } else {} }
2.390625
2
2024-11-18T18:22:48.346041+00:00
2019-04-03T19:18:13
b942e8b8b89050f7f6083d964f557ff6ab5a7033
{ "blob_id": "b942e8b8b89050f7f6083d964f557ff6ab5a7033", "branch_name": "refs/heads/master", "committer_date": "2019-04-03T19:18:13", "content_id": "b2da216474847c6e7d3d4bcc5e21d2e146abfd7c", "detected_licenses": [ "ISC", "Zlib", "CC0-1.0" ], "directory_id": "bb4b967732337945dc96a899a1a0463f10db42d1", "extension": "c", "filename": "runtime.c", "fork_events_count": 1, "gha_created_at": "2019-04-04T02:08:54", "gha_event_created_at": "2019-04-04T02:08:54", "gha_language": null, "gha_license_id": "NOASSERTION", "github_id": 179403950, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 6966, "license": "ISC,Zlib,CC0-1.0", "license_type": "permissive", "path": "/crypto/libsodium/runtime.c", "provenance": "stackv2-0003.json.gz:382697", "repo_name": "killvxk/loki-network", "revision_date": "2019-04-03T19:18:13", "revision_id": "3715c28616fac132f622a80d5d0e8e794166315a", "snapshot_id": "b5d5dc9ff6ac8488b39528edcb71e622f546dea2", "src_encoding": "UTF-8", "star_events_count": 1, "url": "https://raw.githubusercontent.com/killvxk/loki-network/3715c28616fac132f622a80d5d0e8e794166315a/crypto/libsodium/runtime.c", "visit_date": "2020-05-04T19:41:57.347351" }
stackv2
#include <stddef.h> #include <stdint.h> #ifdef HAVE_ANDROID_GETCPUFEATURES #include <cpu-features.h> #endif #include <sodium/private/common.h> #include <sodium/runtime.h> typedef struct CPUFeatures_ { int initialized; int has_neon; int has_sse2; int has_sse3; int has_ssse3; int has_sse41; int has_avx; int has_avx2; int has_avx512f; int has_pclmul; int has_aesni; int has_rdrand; } CPUFeatures; static CPUFeatures _cpu_features; #define CPUID_EBX_AVX2 0x00000020 #define CPUID_EBX_AVX512F 0x00010000 #define CPUID_ECX_SSE3 0x00000001 #define CPUID_ECX_PCLMUL 0x00000002 #define CPUID_ECX_SSSE3 0x00000200 #define CPUID_ECX_SSE41 0x00080000 #define CPUID_ECX_AESNI 0x02000000 #define CPUID_ECX_XSAVE 0x04000000 #define CPUID_ECX_OSXSAVE 0x08000000 #define CPUID_ECX_AVX 0x10000000 #define CPUID_ECX_RDRAND 0x40000000 #define CPUID_EDX_SSE2 0x04000000 #define XCR0_SSE 0x00000002 #define XCR0_AVX 0x00000004 static int _sodium_runtime_arm_cpu_features(CPUFeatures *const cpu_features) { #ifndef __arm__ cpu_features->has_neon = 0; return -1; #else #ifdef __APPLE__ #ifdef __ARM_NEON__ cpu_features->has_neon = 1; #else cpu_features->has_neon = 0; #endif #elif defined(HAVE_ANDROID_GETCPUFEATURES) \ && defined(ANDROID_CPU_ARM_FEATURE_NEON) cpu_features->has_neon = (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0x0; #else cpu_features->has_neon = 0; #endif return 0; #endif } static void _cpuid(unsigned int cpu_info[4U], const unsigned int cpu_info_type) { #if defined(_MSC_VER) \ && (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86)) __cpuid((int *)cpu_info, cpu_info_type); #elif defined(HAVE_CPUID) cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0; #ifdef __i386__ __asm__ __volatile__( "pushfl; pushfl; " "popl %0; " "movl %0, %1; xorl %2, %0; " "pushl %0; " "popfl; pushfl; popl %0; popfl" : "=&r"(cpu_info[0]), "=&r"(cpu_info[1]) : "i"(0x200000)); if(((cpu_info[0] ^ cpu_info[1]) & 0x200000) == 0x0) { return; /* LCOV_EXCL_LINE */ } #endif #ifdef __i386__ __asm__ __volatile__("xchgl %%ebx, %k1; cpuid; xchgl %%ebx, %k1" : "=a"(cpu_info[0]), "=&r"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) : "0"(cpu_info_type), "2"(0U)); #elif defined(__x86_64__) __asm__ __volatile__("xchgq %%rbx, %q1; cpuid; xchgq %%rbx, %q1" : "=a"(cpu_info[0]), "=&r"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) : "0"(cpu_info_type), "2"(0U)); #else __asm__ __volatile__("cpuid" : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) : "0"(cpu_info_type), "2"(0U)); #endif #else (void)cpu_info_type; cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0; #endif } static int _sodium_runtime_intel_cpu_features(CPUFeatures *const cpu_features) { unsigned int cpu_info[4]; unsigned int id; _cpuid(cpu_info, 0x0); if((id = cpu_info[0]) == 0U) { return -1; /* LCOV_EXCL_LINE */ } _cpuid(cpu_info, 0x00000001); #ifdef HAVE_EMMINTRIN_H cpu_features->has_sse2 = ((cpu_info[3] & CPUID_EDX_SSE2) != 0x0); #else cpu_features->has_sse2 = 0; #endif #ifdef HAVE_PMMINTRIN_H cpu_features->has_sse3 = ((cpu_info[2] & CPUID_ECX_SSE3) != 0x0); #else cpu_features->has_sse3 = 0; #endif #ifdef HAVE_TMMINTRIN_H cpu_features->has_ssse3 = ((cpu_info[2] & CPUID_ECX_SSSE3) != 0x0); #else cpu_features->has_ssse3 = 0; #endif #ifdef HAVE_SMMINTRIN_H cpu_features->has_sse41 = ((cpu_info[2] & CPUID_ECX_SSE41) != 0x0); #else cpu_features->has_sse41 = 0; #endif cpu_features->has_avx = 0; #ifdef HAVE_AVXINTRIN_H if((cpu_info[2] & (CPUID_ECX_AVX | CPUID_ECX_XSAVE | CPUID_ECX_OSXSAVE)) == (CPUID_ECX_AVX | CPUID_ECX_XSAVE | CPUID_ECX_OSXSAVE)) { uint32_t xcr0 = 0U; #if defined(HAVE__XGETBV) \ || (defined(_MSC_VER) && defined(_XCR_XFEATURE_ENABLED_MASK) \ && _MSC_FULL_VER >= 160040219) xcr0 = (uint32_t)_xgetbv(0); #elif defined(_MSC_VER) && defined(_M_IX86) /* * Visual Studio documentation states that eax/ecx/edx don't need to * be preserved in inline assembly code. But that doesn't seem to * always hold true on Visual Studio 2010. */ __asm { push eax push ecx push edx xor ecx, ecx _asm _emit 0x0f _asm _emit 0x01 _asm _emit 0xd0 mov xcr0, eax pop edx pop ecx pop eax } #elif defined(HAVE_AVX_ASM) __asm__ __volatile__(".byte 0x0f, 0x01, 0xd0" /* XGETBV */ : "=a"(xcr0) : "c"((uint32_t)0U) : "%edx"); #endif if((xcr0 & (XCR0_SSE | XCR0_AVX)) == (XCR0_SSE | XCR0_AVX)) { cpu_features->has_avx = 1; } } #endif cpu_features->has_avx2 = 0; #ifdef HAVE_AVX2INTRIN_H if(cpu_features->has_avx) { unsigned int cpu_info7[4]; _cpuid(cpu_info7, 0x00000007); cpu_features->has_avx2 = ((cpu_info7[1] & CPUID_EBX_AVX2) != 0x0); } #endif cpu_features->has_avx512f = 0; #ifdef HAVE_AVX512FINTRIN_H if(cpu_features->has_avx2) { unsigned int cpu_info7[4]; _cpuid(cpu_info7, 0x00000007); cpu_features->has_avx512f = ((cpu_info7[1] & CPUID_EBX_AVX512F) != 0x0); } #endif #ifdef HAVE_WMMINTRIN_H cpu_features->has_pclmul = ((cpu_info[2] & CPUID_ECX_PCLMUL) != 0x0); cpu_features->has_aesni = ((cpu_info[2] & CPUID_ECX_AESNI) != 0x0); #else cpu_features->has_pclmul = 0; cpu_features->has_aesni = 0; #endif #ifdef HAVE_RDRAND cpu_features->has_rdrand = ((cpu_info[2] & CPUID_ECX_RDRAND) != 0x0); #else cpu_features->has_rdrand = 0; #endif return 0; } int _sodium_runtime_get_cpu_features(void) { int ret = -1; ret &= _sodium_runtime_arm_cpu_features(&_cpu_features); ret &= _sodium_runtime_intel_cpu_features(&_cpu_features); _cpu_features.initialized = 1; return ret; } int sodium_runtime_has_neon(void) { return _cpu_features.has_neon; } int sodium_runtime_has_sse2(void) { return _cpu_features.has_sse2; } int sodium_runtime_has_sse3(void) { return _cpu_features.has_sse3; } int sodium_runtime_has_ssse3(void) { return _cpu_features.has_ssse3; } int sodium_runtime_has_sse41(void) { return _cpu_features.has_sse41; } int sodium_runtime_has_avx(void) { return _cpu_features.has_avx; } int sodium_runtime_has_avx2(void) { return _cpu_features.has_avx2; } int sodium_runtime_has_avx512f(void) { return _cpu_features.has_avx512f; } int sodium_runtime_has_pclmul(void) { return _cpu_features.has_pclmul; } int sodium_runtime_has_aesni(void) { return _cpu_features.has_aesni; } int sodium_runtime_has_rdrand(void) { return _cpu_features.has_rdrand; }
2.03125
2
2024-11-18T18:22:48.784114+00:00
2023-08-30T16:07:24
0003c9117ada761b2679c5c857b0335fd8f18577
{ "blob_id": "0003c9117ada761b2679c5c857b0335fd8f18577", "branch_name": "refs/heads/master", "committer_date": "2023-08-30T16:07:24", "content_id": "ca9fc3ab1a7fffad85d3edf332719e77e8eb7fa9", "detected_licenses": [ "Apache-2.0" ], "directory_id": "331640994b1b6f66c1639278571ddbdc6c8c0751", "extension": "c", "filename": "nxt_cgo_lib.c", "fork_events_count": 452, "gha_created_at": "2017-09-06T15:45:30", "gha_event_created_at": "2023-09-12T01:28:22", "gha_language": "C", "gha_license_id": "Apache-2.0", "github_id": 102627638, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2314, "license": "Apache-2.0", "license_type": "permissive", "path": "/go/nxt_cgo_lib.c", "provenance": "stackv2-0003.json.gz:382957", "repo_name": "nginx/unit", "revision_date": "2023-08-30T16:07:24", "revision_id": "9b22b6957bc87b3df002d0bc691fdae6a20abdac", "snapshot_id": "eabcd067eaa60f4bdcf0cfaffe7d9932add2c66a", "src_encoding": "UTF-8", "star_events_count": 4649, "url": "https://raw.githubusercontent.com/nginx/unit/9b22b6957bc87b3df002d0bc691fdae6a20abdac/go/nxt_cgo_lib.c", "visit_date": "2023-09-04T02:02:13.581700" }
stackv2
/* * Copyright (C) Max Romanov * Copyright (C) NGINX, Inc. */ #include "_cgo_export.h" #include <nxt_unit.h> #include <nxt_unit_request.h> static ssize_t nxt_cgo_port_send(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port, const void *buf, size_t buf_size, const void *oob, size_t oob_size); static ssize_t nxt_cgo_port_recv(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port, void *buf, size_t buf_size, void *oob, size_t *oob_size); int nxt_cgo_run(uintptr_t handler) { int rc; nxt_unit_ctx_t *ctx; nxt_unit_init_t init; memset(&init, 0, sizeof(init)); init.callbacks.request_handler = nxt_go_request_handler; init.callbacks.add_port = nxt_go_add_port; init.callbacks.remove_port = nxt_go_remove_port; init.callbacks.port_send = nxt_cgo_port_send; init.callbacks.port_recv = nxt_cgo_port_recv; init.callbacks.shm_ack_handler = nxt_go_shm_ack_handler; init.callbacks.ready_handler = nxt_go_ready; init.data = (void *) handler; ctx = nxt_unit_init(&init); if (ctx == NULL) { return NXT_UNIT_ERROR; } rc = nxt_unit_run_ctx(ctx); nxt_unit_done(ctx); return rc; } static ssize_t nxt_cgo_port_send(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port, const void *buf, size_t buf_size, const void *oob, size_t oob_size) { return nxt_go_port_send(port->id.pid, port->id.id, (void *) buf, buf_size, (void *) oob, oob_size); } static ssize_t nxt_cgo_port_recv(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port, void *buf, size_t buf_size, void *oob, size_t *oob_size) { return nxt_go_port_recv(port->id.pid, port->id.id, buf, buf_size, oob, oob_size); } ssize_t nxt_cgo_response_write(nxt_unit_request_info_t *req, uintptr_t start, uint32_t len) { return nxt_unit_response_write_nb(req, (void *) start, len, 0); } ssize_t nxt_cgo_request_read(nxt_unit_request_info_t *req, uintptr_t dst, uint32_t dst_len) { return nxt_unit_request_read(req, (void *) dst, dst_len); } void nxt_cgo_warn(const char *msg, uint32_t msg_len) { nxt_unit_warn(NULL, "%.*s", (int) msg_len, (char *) msg); } void nxt_cgo_alert(const char *msg, uint32_t msg_len) { nxt_unit_alert(NULL, "%.*s", (int) msg_len, (char *) msg); }
2.34375
2
2024-11-18T18:22:48.853962+00:00
2021-10-14T14:01:11
8952ad551ec745fe26d1c8c364219ffe42f5b72c
{ "blob_id": "8952ad551ec745fe26d1c8c364219ffe42f5b72c", "branch_name": "refs/heads/main", "committer_date": "2021-10-14T14:01:11", "content_id": "dec0d44aaaf27644ad7f31d0bf66f2f35f8f0ce2", "detected_licenses": [ "MIT" ], "directory_id": "e2dc918184186a314579d33ae5d637fe1f5dfe01", "extension": "c", "filename": "tb_rx671_main.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 307851053, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 4004, "license": "MIT", "license_type": "permissive", "path": "/60_I2C_Master/tb_rx671/src/tb_rx671_main.c", "provenance": "stackv2-0003.json.gz:383085", "repo_name": "NoMaY-jp/RX_SmartConfigurator_examples_RXTB_CSplus", "revision_date": "2021-10-14T14:01:11", "revision_id": "ccc1265dbc2a612482fba4a39c9553fa0c676dca", "snapshot_id": "a78642bb4007802486886aeb33b27f7224e3f02a", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/NoMaY-jp/RX_SmartConfigurator_examples_RXTB_CSplus/ccc1265dbc2a612482fba4a39c9553fa0c676dca/60_I2C_Master/tb_rx671/src/tb_rx671_main.c", "visit_date": "2023-08-13T23:36:46.412933" }
stackv2
/*********************************************************************** * * FILE : tb_rx671_main.cpp * DATE : 2021-09-28 * DESCRIPTION : Main Program * * NOTE:THIS IS A TYPICAL EXAMPLE. * ***********************************************************************/ #include "r_smc_entry.h" #include "tbrx671def.h" #include <string.h> // Note // 1. This example uses MCU's SCI5 (SSCL5/SSDA5 = Pmod's Pin3/Pin4) // 2. HS3001 data sheet's I2C command format needs modification of Config_SCI5.c U_CONFIG_I2C_MASTER_IMPL( SCI5 ); #if 1 int main(void) /* The following code is checked to be built and run */ { /* HS3001 data sheet: https://www.renesas.com/document/dst/hs300x-datasheet */ uint8_t adr7_HS3001 = 0x44; /* The 7-bits address of the device */ uint8_t ret_data[4]; uint16_t status_bits, humidity_raw, temperature_raw; float humidity, temperature; U_Config_I2C_Master_Start( SCI5 ); for (;;) { /* Measurement Requests */ U_Config_I2C_Master_Send_Ex( SCI5, adr7_HS3001, NULL, 0, MD_WAIT_FINISH ); /* Wait for the completion of measurement (the wait value is more than the minimal time) */ R_BSP_SoftwareDelay( 100, BSP_DELAY_MILLISECS ); /* Data Fetch */ memset( ret_data, 0x00, sizeof(ret_data) ); /* Just clear before reception */ U_Config_I2C_Master_Receive_Ex( SCI5, adr7_HS3001, ret_data, 4, MD_WAIT_FINISH ); /* Get the result of measurement */ status_bits = (ret_data[0] & 0xC0) >> 6; humidity_raw = ((ret_data[0] << 8) | ret_data[1]) & 0x3FFF; temperature_raw = ((ret_data[2] << 8) | ret_data[3]) >> 2; printf( "status bits = %1X\r\n", status_bits ); printf( "humidity raw = 0x%04X\r\n", humidity_raw ); printf( "temperature raw = 0x%04X\r\n", temperature_raw ); /* Calculate the result of measurement */ humidity = (float)humidity_raw / (16384 - 1) * 100; temperature = (float)temperature_raw / (16384 -1) * 165 - 40; printf( "humidity = %5.1f%%\r\n", humidity ); printf( "temperature = %5.1f\"C" "\r\n", temperature ); R_BSP_SoftwareDelay( 3000, BSP_DELAY_MILLISECS ); printf( "\r\n" ); } } #else /* #if 1 */ int main(void) /* The following code is checked to be built only */ { /* ISL29034 data sheet: https://www.renesas.com/document/dst/isl29034-datasheet */ uint8_t adr7_ISL29034 = 0x44; /* The 7-bits address of the device */ uint8_t cmd_read_ID[1] = { 0x0F /* Address of the ID register */ }; uint8_t cmd_clr_BOUT[2] = { 0x0F, /* Address of the ID register */ 0x00 /* Write data (the BOUT bit is the bit7 of the ID register) */ }; uint8_t ret_data1[1] = { 0x00 }; /* Just clear before reception */ uint8_t ret_data2[1] = { 0x00 }; /* Just clear before reception */ printf( "Hit 'Enter' key to proceed the operation.\r\n" ); getchar(); U_Config_I2C_Master_Start( SCI5 ); U_Config_I2C_Master_Send_Ex( SCI5, adr7_ISL29034, cmd_read_ID, sizeof(cmd_read_ID), MD_WAIT_FINISH ); U_Config_I2C_Master_Receive_Ex( SCI5, adr7_ISL29034, ret_data1, sizeof(ret_data1), MD_WAIT_FINISH ); printf( "Read the initial value of the ID register: " ); printf( "(val & 0xA8) = 0x%02X (expected: 0xA8)\r\n\r\n", ret_data1[0] & 0xA8 ); U_Config_I2C_Master_Send_Ex( SCI5, adr7_ISL29034, cmd_clr_BOUT, sizeof(cmd_clr_BOUT), MD_WAIT_FINISH ); printf( "Clear the BOUT bit (the bit7 of the ID register).\r\n\r\n" ); U_Config_I2C_Master_Send_Ex( SCI5, adr7_ISL29034, cmd_read_ID, sizeof(cmd_read_ID), MD_WAIT_FINISH ); U_Config_I2C_Master_Receive_Ex( SCI5, adr7_ISL29034, ret_data2, sizeof(ret_data2), MD_WAIT_FINISH ); printf( "Read again the value of the ID register: " ); printf( "(val & 0xA8) = 0x%02X (expected: 0x28)\r\n\r\n", ret_data2[0] & 0xA8 ); printf( "Done.\r\n" ); for (;;) { } } #endif /* #if 1 */
2.40625
2
2024-11-18T18:22:48.912988+00:00
2020-08-19T15:21:53
767403d18e957511cd99e3ba3134b206bd256ce7
{ "blob_id": "767403d18e957511cd99e3ba3134b206bd256ce7", "branch_name": "refs/heads/master", "committer_date": "2020-08-19T15:21:53", "content_id": "53018a683805a89fbc30c53eab7cb73f249b6475", "detected_licenses": [ "MIT" ], "directory_id": "4fa1e0711c3023a94035b58f6a66c9acd4a7f424", "extension": "c", "filename": "BLNKDLL.C", "fork_events_count": 2, "gha_created_at": "2012-02-13T03:05:18", "gha_event_created_at": "2023-05-31T18:56:36", "gha_language": "C", "gha_license_id": null, "github_id": 3426737, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2802, "license": "MIT", "license_type": "permissive", "path": "/CONSULT/WERNER/LEXIS.25/LPM/LEXBLNK/BLNKDLL.C", "provenance": "stackv2-0003.json.gz:383214", "repo_name": "tig/Tigger", "revision_date": "2020-08-19T15:21:53", "revision_id": "8e06d117a5b520c5fc9e37a710bf17aa51a9958c", "snapshot_id": "4d1f5a2088468c75a7c21b103705445a93ec571c", "src_encoding": "UTF-8", "star_events_count": 1, "url": "https://raw.githubusercontent.com/tig/Tigger/8e06d117a5b520c5fc9e37a710bf17aa51a9958c/CONSULT/WERNER/LEXIS.25/LPM/LEXBLNK/BLNKDLL.C", "visit_date": "2023-06-09T01:59:43.167371" }
stackv2
/************************************************************************ * * Copyright (C) 1990 Werner Associates. All Rights Reserved. * *----------------------------------------------------------------------- * * Project: CMNDLL, Common DLL for Werner Apps * * Module: cmndll.c * * Author(s): Bryan A. Woodruff (baw) * Charles E. Kindel, Jr. (cek) * * * Remarks: * * Revisions: * * ************************************************************************/ #define WINDLL #include <windows.h> #include <wdb.h> #include "blnkdll.h" //------------------------------------------------------------ // Exported variables //------------------------------------------------------------ HANDLE hInst ; short nCurTime ; FARPROC lpfnOldKbdHook ; BOOL fHooked = FALSE ; int FAR PASCAL LibMain( HANDLE hModule, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine ) { nCurTime = 0 ; return TRUE ; } void FAR PASCAL blnkSetHook( void ) { if (lpfnOldKbdHook || fHooked) { D(ODS("Hook already set!\n\r" )) ; return ; } D(ODS( "Setting windows hook...\n\r" )) ; lpfnOldKbdHook = SetWindowsHook( WH_KEYBOARD, (FARPROC)fnKbdFilter ) ; fHooked = TRUE ; if (!lpfnOldKbdHook) { D(ODS( " lpnfOldKbdHook == 0\n\r" )) ; } } void FAR PASCAL blnkUnhookHook( void ) { BOOL b = 0; D(ODS( "Unhooking hook\n\r" )); if (lpfnOldKbdHook && fHooked) { b = UnhookWindowsHook( WH_KEYBOARD, (FARPROC)fnKbdFilter ) ; // lpfnOldKbdHook = NULL ; fHooked = FALSE ; } else { D(ODS( " attempted to unhook the hook but it wasn't hooked!\n\r" )); } } short FAR PASCAL blnkIncTime( short n ) { short cur ; cur = nCurTime ; nCurTime += n ; return cur ; } short FAR PASCAL blnkResetTime( void ) { nCurTime = 0 ; return TRUE ; } int FAR PASCAL fnKbdFilter( int nCode, WORD wParam, DWORD lParam ) { D(ODS( "fnKbdfilter\n\r" )) ; nCurTime = 0 ; if (lpfnOldKbdHook) return DefHookProc( nCode, wParam, lParam, (FARPROC FAR *)&lpfnOldKbdHook ) ; else { D(ODS( " lpfnOldKbdHook was NULL!!!\n\r" )) ; return FALSE ; } } int FAR PASCAL WEP( int bSystemExit ) { D(ODS( "WEP\n\r" )) ; if (fHooked) blnkUnhookHook() ; fHooked = FALSE ; return 1 ; } /************************************************************************ * End of File: cmndll.c ************************************************************************/
2.015625
2
2024-11-18T18:22:49.827178+00:00
2019-10-27T00:19:30
493cd14b24dae42d474dde2799af0829ce585e3b
{ "blob_id": "493cd14b24dae42d474dde2799af0829ce585e3b", "branch_name": "refs/heads/master", "committer_date": "2019-10-27T00:19:30", "content_id": "cce1af1ae00e19886cbb922021bace4d95c432bd", "detected_licenses": [ "MIT" ], "directory_id": "b7328ab7f0e183d8beb034cefcd5a0ec2016347c", "extension": "c", "filename": "gp calc.c", "fork_events_count": 0, "gha_created_at": "2019-10-18T15:40:34", "gha_event_created_at": "2019-10-27T00:19:31", "gha_language": "C", "gha_license_id": "MIT", "github_id": 216056794, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 6359, "license": "MIT", "license_type": "permissive", "path": "/gp calc.c", "provenance": "stackv2-0003.json.gz:383343", "repo_name": "Damianson/c", "revision_date": "2019-10-27T00:19:30", "revision_id": "78bb040f90ceb43fc6fee8e79859c0037dcfb291", "snapshot_id": "fa90446e9831683b73370da226716d94ea19b6b6", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/Damianson/c/78bb040f90ceb43fc6fee8e79859c0037dcfb291/gp calc.c", "visit_date": "2020-08-20T19:02:53.575125" }
stackv2
/* Author: Uchegbu Damianson-Wisdom Onyekachi with snippets from Sir Bhatt; C Programming Beast * Description: Calculates total GPA for a semester */ #include <stdio.h> #include <string.h> #define MAX_COURSE 10 //total number of courses enum grades { A,B,C,D,E,F } grade_t; /* name: name of the course (Course code) limit 10 Characters credits: credit load of the course grade: grade allocated to the course... if you know what i mean..lol */ struct course { char name[10]; int credits; float grade; }; /* Display courses... c'mon this thing has to look fine abi? courses: courses entered size: number of courses */ void displayCourses(struct course courses[], int size){ int i; puts("++++++++++++++++++++++++++++++++++++++++++++++++++++++"); // 54 puts("+ Courses | Grades +"); puts("+----------------------------------------------------+"); for (i = 0; i < size; i++){ //puts("+ +"); printf("%d). %s\t\tCredits: %d\t Grade: %.3f\n",i+1,courses[i].name, courses[i].credits, courses[i].grade); //puts("+ +"); puts("+----------------------------------------------------+"); } } /* This is the real deal.... where all the calculation is done */ void calculateGPA(const struct course courses[], int size, float grade_points, int units, float *tgpa, float *sgpa){ float points = grade_points; int cred = units; int i; for (i = 0; i < size; i++){ points += courses[i].credits * courses[i].grade; // add to the total points cred += courses[i].credits; // add to the total credits } // GPA = Grade Points / Number of Credits *tgpa = points/cred; // total GPA *sgpa = (points - grade_points)/(cred - units); // Semester GPA } /* Here comes the part where we assign values to the grades, eh hen.... i heard that E has been added to our grading system now so */ float getGradeValue(int grade){ switch (grade){ case A : return 5; case B : return 4; case C : return 3; case D : return 2; case E : return 1.; case F : return 0.; } return -1; } /* Yeah i added a grade menu.... for those people that dont know the points associated to the grades.. */ void displayGradeMenu() { puts("\t\t(0) A\t(5)\n\t\t(1) B\t(4)\n\t\t(2) C\t(3)\n\t\t(3) D\t(2)\n\t\t(4) E\t(1)\n\t\t(5) F\t(0)\n"); return; } // Where we enter our couses.. finally! void getCourses(struct course courses[], int *size){ struct course c; // temporary struct to store current entered course int grade; int credit; char stop = 'y'; // if not y then stop int i = 0; int result; //temp variable for detecting success of user input char temp[50]; // temp variable to get user input from stdin while((stop == 'y') && (i < MAX_COURSE)){ // if user did not press y or if MAX_COURSE courses have been added, break // Get course name printf("\n"); printf("\tDetails for Course %d\n\n", i+1); puts("\t[A]\tEnter course name:"); printf("\t\t"); fgets(c.name, 50, stdin); // Get number of credits printf("\n"); puts("\t[B]\tEnter number of credits:"); printf("\t\t"); fgets(temp, 50, stdin); result = sscanf(temp, "%2d", &credit); // format user input while (result != 1){ //Prompt user if invalid puts("\t\tRead failed. Please enter a valid number:"); printf("\t\t"); fgets(temp, 50, stdin); result = sscanf(temp, "%2d", &credit); } c.credits = credit; // store credit into temp variable // Get estimated grade printf("\n"); puts("\t[C]\tSelect grade (type the number shown at the right hand side of the grade):"); displayGradeMenu(); // display options printf("\t\t"); fgets(temp, 50, stdin); result = sscanf(temp,"%1d", &grade); // format user input while (result != 1){ // Prompt user if invalid puts("\t\tRead failed. Please enter a valid number:"); printf("\t\t"); fgets(temp, 50, stdin); result = sscanf(temp,"%1d", &grade); } c.grade = getGradeValue(grade);// store grade into temp variable // Store temp struct course into courses array strcpy(courses[i].name, c.name); courses[i].credits = c.credits; courses[i].grade = c.grade; i++; // Add 1 to the number of courses added //Prompt user to enter another course if MAX_COURSE courses have not been added if (i >= MAX_COURSE){ puts("\n\tCourses stored!\n\n\tMaximum number of courses have been entered.\n\tPress enter to get results.\n\n"); getchar(); }else{ printf("\n\tCourse Added!\n\n[%d]\tTo add another course press (y).\n\tOtherwise press enter to exit course addition.\n", i+1); printf("\t"); stop = getchar(); // get user input if (stop == 'y'){ getchar(); //clear buffer of Enter } } } *size = i; // store number of courses for return } /* * main * * Carries out the main flow for user. Prompts user to input data to calculate GPA */ int main (int argc, char ** argv){ float grade_points; // total number of grade points int result; // temp variable for detecting success of user input int units; // number of credits taken int numCourses = 0; // number of courses struct course courses[MAX_COURSE]; // list of courses float gpa; //total GPA float semester_gpa; // semester GPA char c; // used to detect whether courses are needed to be entered char temp[50]; // temp variable to get user input from stdin puts("[1]\tPress 'y' to enter courses to calculate your estimated GPA.\n\tOtherwise press enter.\n"); printf("\t"); c = getchar(); if( c == 'y') { // if yes (c='y') then add courses getchar(); // clear input getCourses(courses, &numCourses); // get courses displayCourses(courses, numCourses); // display entered courses calculateGPA(courses, numCourses, grade_points, units, &gpa, &semester_gpa); // calculate new gpa printf("\nYour estimated semester GPA:\t%.3f\n\n", semester_gpa); // echo estimated semester gpa round to 3 decimal places printf("Your estimated total GPA:\t%.3f\n\n\n", gpa); // echo estimated gpa round to 3 decimal places } puts("Press Enter to Exit..."); // Prompt user to press enter before exiting so they can view results getchar(); return 0; }
3.21875
3
2024-11-18T18:22:50.301369+00:00
2019-11-18T05:11:44
7bfb9941355fbd2e27c77c5b3654a4752c03be00
{ "blob_id": "7bfb9941355fbd2e27c77c5b3654a4752c03be00", "branch_name": "refs/heads/master", "committer_date": "2019-11-18T05:11:44", "content_id": "12bf4f47ffc2c9c89b2ec167b02c88e44cd8ff29", "detected_licenses": [ "MIT" ], "directory_id": "124b98880576428939d56f334a95b7f7fbfdd3ed", "extension": "c", "filename": "resolve.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 161961185, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 886, "license": "MIT", "license_type": "permissive", "path": "/SysLang/Lib/source/resolve/resolve.c", "provenance": "stackv2-0003.json.gz:383861", "repo_name": "redagito/MyBitwise", "revision_date": "2019-11-18T05:11:44", "revision_id": "41745887e8f12f12e79e877b4d001f1501d5fa0d", "snapshot_id": "d182dae28c9037cfc11c98b4f3f5c40d93b0748c", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/redagito/MyBitwise/41745887e8f12f12e79e877b4d001f1501d5fa0d/SysLang/Lib/source/resolve/resolve.c", "visit_date": "2020-04-11T17:26:38.782978" }
stackv2
#include "syl/resolve/resolve.h" #include "syl/common/map.h" #include "syl/type.h" static void complete_type(type_t* type) { } // Actually part of type.h/c // Moved to resolve to avoid cyclic dependency // Maps base pointer to type to same type with const qualifier static map_t cached_const_types; /** * Returns const type of base type */ static type_t* type_const(type_t* base) { if (base->type == TYPE_CONST) { // Base already has const qualifier return base; } // Same type as base with const qualifier may already be cached type_t* type = map_get(&cached_const_types, base); if (type == NULL) { // Build new type with const qualifier complete_type(base); type = type_alloc(TYPE_CONST); type->non_modifiable = true; type->size = base->size; type->align = base->align; type->base = base; map_put(&cached_const_types, base, type); } return type; }
2.578125
3
2024-11-18T18:22:50.385294+00:00
2016-08-23T01:26:45
cd60c57c869ed7bdd873f759a1f2512d9a58f390
{ "blob_id": "cd60c57c869ed7bdd873f759a1f2512d9a58f390", "branch_name": "refs/heads/master", "committer_date": "2016-08-25T04:58:21", "content_id": "be899243d32a1f3c936980efd73cdd64791d0f7d", "detected_licenses": [ "MIT", "BSD-3-Clause" ], "directory_id": "2538a4cda5d9d536a3fb3bda1666a3e8636ff7ab", "extension": "h", "filename": "interrupt_event.h", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 66531120, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1318, "license": "MIT,BSD-3-Clause", "license_type": "permissive", "path": "/kernel/dev/interrupt/include/dev/interrupt_event.h", "provenance": "stackv2-0003.json.gz:383989", "repo_name": "ilibx/magenta-os", "revision_date": "2016-08-23T01:26:45", "revision_id": "b96c578566fa02f8436862a4e1e24858f4af3677", "snapshot_id": "93b2fe99421f0c6ac298b1b5d69f39827665f24d", "src_encoding": "UTF-8", "star_events_count": 5, "url": "https://raw.githubusercontent.com/ilibx/magenta-os/b96c578566fa02f8436862a4e1e24858f4af3677/kernel/dev/interrupt/include/dev/interrupt_event.h", "visit_date": "2021-01-15T08:59:59.014610" }
stackv2
// Copyright 2016 The Fuchsia Authors // // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT #pragma once #include <compiler.h> #include <err.h> #include <sys/types.h> __BEGIN_CDECLS typedef void* interrupt_event_t; /* Interrupt events are raised by hardware and can be waited upon by one or more threads. * Rules: * - An interrupt is unmasked when create_interrupt_event() is called for it for the first time * - All threads that are waiting are woken up when an interrupt is raised. * - Each thread must call interrupt_event_complete() before waiting again. * - The interrupt is masked until all woken threads call interrupt_event_complete(). */ // Creates an interrupt event if there is none for this vector. #define INTERRUPT_EVENT_FLAG_REMAP_IRQ (0x1) status_t interrupt_event_create(unsigned int vector, uint32_t flags, interrupt_event_t* ie); // Waits for an interrupt event. If there is a pending interrupt, this returns immediately. // Otherwise, the thread is blocked until the next interrupt. status_t interrupt_event_wait(interrupt_event_t ie); // Notifies the kernel that the interrupt has been processed by the calling thread. void interrupt_event_complete(interrupt_event_t ie); __END_CDECLS
2.359375
2
2024-11-18T18:22:52.208643+00:00
2016-03-21T20:29:03
6398a378cc71215a37f9c3f86f09d53c30e2da99
{ "blob_id": "6398a378cc71215a37f9c3f86f09d53c30e2da99", "branch_name": "refs/heads/master", "committer_date": "2016-03-21T20:29:03", "content_id": "95971d9100088e1826b482571f42f43d25e76265", "detected_licenses": [ "MIT" ], "directory_id": "1b6f40a09002d3e20c0ac047abca2dd89cda6335", "extension": "h", "filename": "processing.h", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 54419698, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2199, "license": "MIT", "license_type": "permissive", "path": "/histogram/processing.h", "provenance": "stackv2-0003.json.gz:384118", "repo_name": "AndrejGajdos/C-assignments", "revision_date": "2016-03-21T20:29:03", "revision_id": "6fa3cdafacbb5e6a5bea8ccf8464f2d275d08d16", "snapshot_id": "f961cfa1aa31d6446fda9f6513d65b32dabfdf86", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/AndrejGajdos/C-assignments/6fa3cdafacbb5e6a5bea8ccf8464f2d275d08d16/histogram/processing.h", "visit_date": "2016-09-01T12:23:17.002489" }
stackv2
/** @file processing.h*/ /** * Compute histogram of the given image * * @param [out] hist histogram to compute * @param [in] img input image * @param [in] histSize histogram size * @param [in] imgSize image size * @return nothing */ void ComputeHistogram(unsigned int *hist, const unsigned char *img, size_t histSize, size_t imgSize); /** * Compute cumulative histogram from the given histogram * * @param [out] cumulative histogram to compute * @param [in] hist input histogram * @param [in] histSize histogram size * @return nothing */ void ComputeCumulative(unsigned int *cumulative, const unsigned int *hist, size_t histSize); /** * Equalize the given image based on the cumulative histogram * * @param [out] output image after equalization * @param [in] input input image * @param [in] cumulative cumulative histogram of the input image * @param [in] imgSize image size * @param [in] maxVal maximal value of the image type * @return nothing */ void Equalize(unsigned char *output, const unsigned char *input, const unsigned int *cumulative, size_t imgSize, size_t maxVal); /** * Compute binary image from the given image by thresholding * * @param [out] bin computed binary image * @param [in] img input image * @param [in] imgSize image size * @param [in] thresh threshold value to use * @return nothing */ void Threshold(unsigned char *bin, const unsigned char *img, size_t imgSize, unsigned char thresh); /** * Prints the given histogram * * @param [in] hist histogram to print * @param [in] histSize histogram size * @return nothing */ void PrintHistogram(const unsigned int *hist, size_t histSize); /** * Prints the binary image * * @param [in] img binary image to print * @param [in] sizeX size of the image in the x-dimension * @param [in] sizeY size of the image in the y-dimension * @return nothing */ void PrintBinaryImage(const unsigned char *img, size_t sizeX, size_t sizeY);
2.6875
3
2024-11-18T18:22:52.501833+00:00
2023-03-25T20:00:21
ef058f80e500ab74f5ba77aab80e26e698d5053d
{ "blob_id": "ef058f80e500ab74f5ba77aab80e26e698d5053d", "branch_name": "refs/heads/master", "committer_date": "2023-03-25T20:00:21", "content_id": "d628564151140fe2fe12d186da3196dcfb7d759e", "detected_licenses": [ "BSD-3-Clause" ], "directory_id": "2230fed63c69f87bb90ed41d17b8229828d2961d", "extension": "c", "filename": "seq_list.c", "fork_events_count": 4, "gha_created_at": "2019-10-06T12:16:06", "gha_event_created_at": "2023-03-25T20:00:22", "gha_language": "C", "gha_license_id": "BSD-3-Clause", "github_id": 213162722, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2900, "license": "BSD-3-Clause", "license_type": "permissive", "path": "/src/seq_list.c", "provenance": "stackv2-0003.json.gz:384376", "repo_name": "Benardi/sibylline", "revision_date": "2023-03-25T20:00:21", "revision_id": "f032af478ab070b35e978311cefdea56b299f02e", "snapshot_id": "578629d024c045e859f139f897355627f37155d6", "src_encoding": "UTF-8", "star_events_count": 12, "url": "https://raw.githubusercontent.com/Benardi/sibylline/f032af478ab070b35e978311cefdea56b299f02e/src/seq_list.c", "visit_date": "2023-04-06T18:13:36.606723" }
stackv2
#include <malloc.h> #include <seq_list.h> #include <stdio.h> void init_seq_list(SeqList* sl, int max_n_elems) { sl->n_elems = 0; sl->max_n_elems = max_n_elems; sl->array = malloc((max_n_elems + 1) * sizeof(Register)); } void reinit_seq_list(SeqList* sl) { sl->n_elems = 0; } int size(SeqList* sl) { return sl->n_elems; } int seq_search(SeqList* sl, union Key key, int (*compare)(union Key, union Key)) { int i = 0; while (i < sl->n_elems) { if (compare(key, sl->array[i].key) == 0) { return i; } else { i++; } } return -1; } int sentinel_search(SeqList* sl, union Key k, int (*compare)(union Key, union Key)) { int i = 0; sl->array[sl->n_elems].key = k; while (compare(sl->array[i].key, k) != 0) { i++; } if (i == sl->n_elems) { return -1; } else { return i; } } bool insert_sorted(SeqList* sl, Register reg, int (*compare)(union Key, union Key)) { int pos; if (sl->n_elems >= sl->max_n_elems) { return false; } pos = sl->n_elems; while (pos > 0 && compare(sl->array[pos - 1].key, reg.key) == 1) { sl->array[pos] = sl->array[pos - 1]; pos--; } sl->array[pos] = reg; sl->n_elems++; return true; } int binary_search(SeqList* sl, union Key k, int (*compare)(union Key, union Key)) { int left, right, middle; left = 0; right = sl->n_elems - 1; while (left <= right) { middle = (left + right) / 2; if (compare(sl->array[middle].key, k) == 0) { return middle; } else { if (compare(sl->array[middle].key, k) == -1) { left = middle + 1; } else { right = middle - 1; } } } return -1; } bool insert_elem(SeqList* sl, Register reg, int i) { int j; if (sl->n_elems == sl->max_n_elems || i < 0 || i > sl->n_elems) { return false; } else { for (j = sl->n_elems; j > i; j--) { sl->array[j] = sl->array[j - 1]; } sl->array[i] = reg; sl->n_elems++; return true; } } bool remove_elem(SeqList* sl, union Key key, int (*compare)(union Key, union Key)) { int pos, j; pos = seq_search(sl, key, compare); if (pos == -1) { return false; } else { for (j = pos; j < sl->n_elems - 1; j++) { sl->array[j] = sl->array[j + 1]; } sl->n_elems--; return true; } } void show_list(SeqList* sl) { int i; printf("List: \""); for (i = 0; i < sl->n_elems - 1; i++) printf("%i ", sl->array[i].key.i); /* Last element isn't followed by blank space */ printf("%i", sl->array[sl->n_elems - 1].key.i); printf("\"\n"); }
3.28125
3
2024-11-18T18:22:52.741188+00:00
2019-07-28T03:30:20
8c5b6e0c9bf861a06cf1c34d4160053a2b9014b3
{ "blob_id": "8c5b6e0c9bf861a06cf1c34d4160053a2b9014b3", "branch_name": "refs/heads/master", "committer_date": "2019-07-28T03:30:20", "content_id": "938ba6cc1217d8746bf68979b4b4f695a12878bf", "detected_licenses": [ "Apache-2.0" ], "directory_id": "4589ae122e67c8df33ec67600461d01056cdf2c5", "extension": "c", "filename": "t2.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 198782338, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 786, "license": "Apache-2.0", "license_type": "permissive", "path": "/t2.c", "provenance": "stackv2-0003.json.gz:384765", "repo_name": "xmgcc/89c52", "revision_date": "2019-07-28T03:30:20", "revision_id": "e29e3e720e866b4931b2e4cd1d5a48757bacffd8", "snapshot_id": "8e87168d336c9b8a18067b5173e408a19895dc6f", "src_encoding": "GB18030", "star_events_count": 0, "url": "https://raw.githubusercontent.com/xmgcc/89c52/e29e3e720e866b4931b2e4cd1d5a48757bacffd8/t2.c", "visit_date": "2020-06-23T23:18:17.093939" }
stackv2
#include "reg52.h" typedef unsigned char u8; #define BAUD 115200 #define FOSC 11059200 void t2_init_115200() { // 配置T2用于波特率发生器 T2CON = 0x34; // 使用16位定时器,TH2、TL2同时使用 // 后续从 TH2 = RCAP2H;TL2 = RCAP2L; TH2 = RCAP2H = 0XFF;// 65536 - (FOSC/32/BAUD); TL2 = RCAP2L = 0XFD;//(65536 - (FOSC/32/BAUD)) >> 8; // 启动定时器2 TR2 = 1; } void send_u8(u8 ch) { SBUF=ch; while (!TI); TI = 0; } void uart_init() { // 串口允许发送、接收 SCON=0x50; } void uart_srv() interrupt 4 { if (RI) { RI = 0; send_u8(SBUF); } } void interrupt_init() { // 开启串口中断 ES=1; // 开启总中断 EA=1; } void main() { uart_init(); t2_init_115200(); interrupt_init(); send_u8('c'); while (1) { } }
2.546875
3
2024-11-18T18:22:52.865134+00:00
2020-07-02T21:05:38
ea311459c3cbad82686408e18eed3e69828e8fc3
{ "blob_id": "ea311459c3cbad82686408e18eed3e69828e8fc3", "branch_name": "refs/heads/master", "committer_date": "2020-07-02T21:05:38", "content_id": "ee70ba07ed5d09bcf8a2b18c585a7af7618df0aa", "detected_licenses": [ "MIT" ], "directory_id": "3a724dbca0d6c8109617df3ccc887a78653b1c24", "extension": "c", "filename": "leaf.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 276738939, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1141, "license": "MIT", "license_type": "permissive", "path": "/leaf/leaf/Src/leaf.c", "provenance": "stackv2-0003.json.gz:384893", "repo_name": "spiricom/Drumbox", "revision_date": "2020-07-02T21:05:38", "revision_id": "bc3e841414dcc2cbb24b05a90d3d028c49a2de9b", "snapshot_id": "b3b0f04b4559925313f968ec02bcf35184681977", "src_encoding": "UTF-8", "star_events_count": 1, "url": "https://raw.githubusercontent.com/spiricom/Drumbox/bc3e841414dcc2cbb24b05a90d3d028c49a2de9b/leaf/leaf/Src/leaf.c", "visit_date": "2022-11-11T10:10:31.780512" }
stackv2
/* ============================================================================== LEAFCore.c Created: 20 Jan 2017 12:08:14pm Author: Michael R Mulshine ============================================================================== */ #if _WIN32 || _WIN64 #include "..\leaf.h" #else #include "../leaf.h" #endif LEAF leaf; void LEAF_init(float sr, int blocksize, char* memory, size_t memorysize, float(*random)(void)) { leaf_pool_init(memory, memorysize); leaf.sampleRate = sr; leaf.blockSize = blocksize; leaf.invSampleRate = 1.0f/sr; leaf.twoPiTimesInvSampleRate = leaf.invSampleRate * TWO_PI; leaf.random = random; leaf.clearOnAllocation = 0; } #define LEAFSampleRateChanged(THIS) leaf.THIS.sampleRateChanged(&leaf.THIS) void LEAF_setSampleRate(float sampleRate) { leaf.sampleRate = sampleRate; leaf.invSampleRate = 1.0f/sampleRate; } float LEAF_getSampleRate() { return leaf.sampleRate; } //implement a function called this in your user code to catch errors //__attribute__((weak)) uint8_t LEAF_error(uint8_t whichone) { return whichone; }
2.140625
2
2024-11-18T18:22:52.926659+00:00
2020-05-18T21:36:49
205d6af18759eeb0711f6924ad36519c04f83242
{ "blob_id": "205d6af18759eeb0711f6924ad36519c04f83242", "branch_name": "refs/heads/master", "committer_date": "2020-05-18T21:36:49", "content_id": "fbb5844899e7d62fad09bf2850bfd1054c8f2c73", "detected_licenses": [ "MIT" ], "directory_id": "55251056eb51b5d2feb2d1a2177469bddd5cff4c", "extension": "c", "filename": "ionhash.c", "fork_events_count": 0, "gha_created_at": "2020-04-28T16:15:11", "gha_event_created_at": "2020-07-22T15:35:38", "gha_language": "Elixir", "gha_license_id": "MIT", "github_id": 259688960, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1633, "license": "MIT", "license_type": "permissive", "path": "/c_src/qldbex/ionhash.c", "provenance": "stackv2-0003.json.gz:385022", "repo_name": "Astrocoders/qldbex", "revision_date": "2020-05-18T21:36:49", "revision_id": "c0a13030d3c96c716681681fb20e5656d1bb1498", "snapshot_id": "4524c8cc876d349963159f5fef768495a4b1aa72", "src_encoding": "UTF-8", "star_events_count": 2, "url": "https://raw.githubusercontent.com/Astrocoders/qldbex/c0a13030d3c96c716681681fb20e5656d1bb1498/c_src/qldbex/ionhash.c", "visit_date": "2022-11-24T04:11:51.021116" }
stackv2
#define PY_SSIZE_T_CLEAN #include "./ionhash.h" void initialize_python() { if (!Py_IsInitialized()) Py_Initialize(); PyRun_SimpleString("import sys; import os; sys.path.append(os.path.abspath(os.getcwd()) + '/priv/python/');"); } void generate_ion_hash(char *value, char *output) { PyObject *module_name = PyUnicode_FromString((char *)"__ion_hash__"); PyObject *module = PyImport_Import(module_name); PyObject *to_qldb_hash_function = PyObject_GetAttrString(module, (char *)"to_ion_hash"); PyObject *args = PyTuple_Pack(1, PyUnicode_FromString(value)); PyObject *result = PyObject_CallObject(to_qldb_hash_function, args); const char *function_result = PyUnicode_AsUTF8(result); output = malloc(sizeof(char) * strlen(function_result)); strcpy(output, function_result); } #define HASH_SIZE 32 int hash_comparator(char *first, char *last) { for (int i = HASH_SIZE - 1; i >= 0; i--) { int diff = first[i] - last[i]; if (diff != 0) return diff; } return 0; } void *dot(char *first, char *last, unsigned char *output) { size_t len_first = strlen(first); size_t len_last = strlen(last); size_t concat_size = len_first + len_last + 1; char *concat = malloc(concat_size); if (len_first == 0) { strcpy(concat, last); } else if (len_last == 0) { strcpy(concat, first); } else { if (hash_comparator(first, last) < 0) { strcpy(concat, first); strcat(concat, last); } else { strcpy(concat, last); strcat(concat, first); } } SHA256((unsigned char *)concat, strlen(concat), output); free(concat); }
2.328125
2
2024-11-18T18:22:53.208141+00:00
2023-01-11T23:43:12
a8caba61c63725bc4f6e7bbc44d4d6a9cd10f7fd
{ "blob_id": "a8caba61c63725bc4f6e7bbc44d4d6a9cd10f7fd", "branch_name": "refs/heads/master", "committer_date": "2023-01-11T23:43:12", "content_id": "a49402272206afcd9fc16cd4c6f0b18abf4b104e", "detected_licenses": [ "ISC" ], "directory_id": "f806c29d2ee80cc730300b36a7e7fbdfe42ed14e", "extension": "c", "filename": "nbspcat.c", "fork_events_count": 4, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 7613062, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 6083, "license": "ISC", "license_type": "permissive", "path": "/filters/filterlib/c/nbspcat.c", "provenance": "stackv2-0003.json.gz:385150", "repo_name": "noaaport/nbsp", "revision_date": "2023-01-11T23:43:12", "revision_id": "39ae50d2445df016cf69d54527d83dc1ac172338", "snapshot_id": "3095cfcac6a8c39a67cc9b2fd42005587945f67d", "src_encoding": "UTF-8", "star_events_count": 6, "url": "https://raw.githubusercontent.com/noaaport/nbsp/39ae50d2445df016cf69d54527d83dc1ac172338/filters/filterlib/c/nbspcat.c", "visit_date": "2023-08-14T03:47:01.348920" }
stackv2
/* * Copyright (c) 2005-2016 Jose F. Nieves <[email protected]> * * See LICENSE * * $Id$ */ /* * This tool provides the essential functionality of nbspfile and nbsppipe, * but it takes the command line arguments from stdin. The purpose is to * be able to "|open" it once, from a tcl script, and then write the * commands to the file descriptor. The program is invoked as * * char *usage = "nbspcat [-h] [-b]"; * * and each command line must have the syntax * * char *usage = "nbspcat [-c ccbsize] [-g] [-n] [-o output [-a]] [-s N] file"; * * The options are similar to those in nbsppipe. */ #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <stdlib.h> #include <ctype.h> #include <libgen.h> #include <fcntl.h> #include <string.h> #include "err.h" #include "util.h" #include "io.h" #include "const.h" #include "strsplit.h" #include "config.h" /* optreset */ #define DUMMY_SEQNUM 90000 #define PAGE_SIZE 65536 #define CMD_LINE_BUFFER_SIZE 1024 struct { int opt_background; char *opt_input_fname; char *opt_output_fname; unsigned int opt_seqnum; int opt_append; /* [-a] outputfile in append mode */ int opt_noccb; /* [-n] file saved without ccb [24 byte] header */ int opt_header; /* [-g] add gempak-like header and trailer */ int opt_ccbsize; /* [-c] specify a different (ccb) size to cut */ /* variables */ FILE *input_fp; FILE *output_fp; struct strsplit_st *strp; char page[PAGE_SIZE]; int page_size; } g = {0, NULL, NULL, DUMMY_SEQNUM, 0, 0, 0, CCB_SIZE, NULL, NULL, NULL, {0}, PAGE_SIZE}; static void process_input(void); static void process_cmd(int argc, char **argv); static void process_file(void); static void close_files(void); static void cleanup(void); int main(int argc, char **argv){ char *optstr = "bh"; char *usage = "nbspcat [-h] [-b]"; int c; int status = 0; set_progname(basename(argv[0])); while((status == 0) && ((c = getopt(argc, argv, optstr)) != -1)){ switch(c){ case 'b': g.opt_background = 1; break; case 'h': default: status = 1; log_errx(1, usage); break; } } if(optind <= argc - 1) log_errx(1, "Too many arguments."); if(g.opt_background == 1) set_usesyslog(); atexit(cleanup); process_input(); return(0); } static void process_input(void){ char line[CMD_LINE_BUFFER_SIZE]; int line_max_size = CMD_LINE_BUFFER_SIZE; int line_size; int lineno = 0; while(fgets(line, line_max_size, stdin) != NULL){ ++lineno; line_size = strlen(line); if(line[line_size - 1] != '\n'){ log_errx(1, "Line %d exceeds maximum size %d.", lineno, line_max_size); break; } line[line_size - 1] = '\0'; g.strp = strsplit_recreate(line, " ", STRSPLIT_FLAG_IGNEMPTY, g.strp); if(g.strp == NULL) log_err(1, "Error in strplit_create()"); process_cmd(g.strp->argc, g.strp->argv); } } static void process_cmd(int argc, char **argv){ int status = 0; int c; unsigned int seqnum; uint16_t ccbsize; char *optstr = "abc:gno:s:"; char *usage = "nbspcat [-c ccbsize] [-g] [-n] [-o output [-a]] [-s N] file"; /* Reset defauts */ g.opt_input_fname = NULL; g.opt_output_fname = NULL; g.opt_seqnum = DUMMY_SEQNUM; g.opt_append = 0; g.opt_noccb = 0; g.opt_header = 0; g.opt_ccbsize = CCB_SIZE; optind = 1; #ifdef HAVE_OPTRESET optreset = 1; #endif while((status == 0) && ((c = getopt(argc, argv, optstr)) != -1)){ switch(c){ case 'a': g.opt_append = 1; break; case 'c': status = strto_u16(optarg, &ccbsize); if(status != 0) log_errx(1, "Illegal value for [-c]."); else{ g.opt_ccbsize = ccbsize; } break; case 'g': g.opt_header = 1; /* add header and trailer */ break; case 'n': g.opt_noccb = 1; /* the file was saved without the ccb */ break; case 'o': g.opt_output_fname = optarg; break; case 's': status = strto_uint(optarg, &seqnum); if(status != 0) log_warnx("Invalid value for [-s]."); else{ g.opt_seqnum = seqnum; } break; case 'h': default: status = 1; log_warnx(usage); break; } } if(status != 0) return; if(optind < argc - 1){ status = 1; log_warnx("Too many arguments."); }else if(optind == argc){ status = 1; log_warnx(usage); }else g.opt_input_fname = argv[optind]; if(status == 0){ process_file(); close_files(); } } static void cleanup(void){ close_files(); strsplit_delete(g.strp); } static void close_files(void){ if(g.input_fp != NULL){ fclose(g.input_fp); g.input_fp = NULL; } if((g.output_fp != NULL) && (g.opt_output_fname != NULL)){ fclose(g.output_fp); g.output_fp = NULL; } } static void process_file(void){ int ccb_size = g.opt_ccbsize; int nread, nwrite; int data_start; g.input_fp = fopen_input(g.opt_input_fname); if(g.input_fp == NULL){ log_errn_open(g.opt_input_fname); return; } if(g.opt_output_fname != NULL){ if(g.opt_append == 0) g.output_fp = fopen_output(g.opt_output_fname, "w"); else g.output_fp = fopen_output(g.opt_output_fname, "a"); if(g.output_fp == NULL){ log_errn_open(g.opt_output_fname); return; } }else g.output_fp = stdout; if(g.opt_noccb == 1) ccb_size = 0; if(g.opt_header == 1) fprintf(g.output_fp, GMPK_HEADER_FMT, (int)(g.opt_seqnum % 1000)); nread = read_page(g.input_fp, g.page, g.page_size); if(nread <= ccb_size){ log_warnx("Corrupted data file."); return; } data_start = ccb_size; while(nread > 0){ nwrite = write_page(g.output_fp, &g.page[data_start], nread - data_start); /* * write_page() handles the error already (exits the program) */ if(nwrite == -1) log_err(1, "%s", "write_page() error"); nread = read_page(g.input_fp, g.page, g.page_size); data_start = 0; } if(g.opt_header == 1) fprintf(g.output_fp, GMPK_TRAILER_STR); }
2.46875
2
2024-11-18T18:22:53.468587+00:00
2018-07-26T16:08:16
15aa97c5d1ecb7d349dacc0a5f8fcdbd7f381df3
{ "blob_id": "15aa97c5d1ecb7d349dacc0a5f8fcdbd7f381df3", "branch_name": "refs/heads/master", "committer_date": "2018-07-26T16:08:16", "content_id": "f4afe896203f7bb1e14b56c71f7b384f0b0532e1", "detected_licenses": [ "MIT" ], "directory_id": "e1506f25a13b1b7191b5946d768dba8bafba268e", "extension": "c", "filename": "robot.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 141303825, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 3884, "license": "MIT", "license_type": "permissive", "path": "/robot.c", "provenance": "stackv2-0003.json.gz:385535", "repo_name": "Shany545/FPWebsite", "revision_date": "2018-07-26T16:08:16", "revision_id": "9f2e34b756be715562554cc4d5f54bf91a45056c", "snapshot_id": "a81411b0ee35cd579a2eba30372e329f74fb6553", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/Shany545/FPWebsite/9f2e34b756be715562554cc4d5f54bf91a45056c/robot.c", "visit_date": "2020-03-23T08:01:16.370799" }
stackv2
#include <Servo.h> Servo servoLeft; Servo servoRight; int PIEZOPIN = 2; int LedPIN = 3; void setup() { tone(4, 3000, 1000); // Play tone for 1 second delay(1000); // Delay to finish tone pinMode(7, INPUT); // Set right whisker pin to input pinMode(4, INPUT); // Set left whisker pin to input Serial.begin(9600); servoLeft.attach(13); servoRight.attach(12); servoLeft.writeMicroseconds(1500); servoRight.writeMicroseconds(1500); } void clockwise() { servoLeft.writeMicroseconds(1200); servoRight.writeMicroseconds(1200); delay (1000); Sensor(); } void right() { servoLeft.writeMicroseconds(1200); servoRight.writeMicroseconds(1700); delay (1000); Sensor(); } void counter_clockwise() { servoLeft.writeMicroseconds(1300); servoRight.writeMicroseconds(1200); delay (1000); Sensor(); } void forward () { servoLeft.writeMicroseconds(1300); servoRight.writeMicroseconds(1700); delay (1000); right (); Sensor (); } void backward() { servoLeft.writeMicroseconds(1700); servoRight.writeMicroseconds(1300); delay (1000); Sensor(); } void H() { digitalWrite (3, HIGH); delay (2000); digitalWrite (3, LOW); delay (1000); digitalWrite (3, HIGH); delay (2000); digitalWrite (3, LOW); delay (1000); digitalWrite (3, HIGH); delay (2000); digitalWrite (3, LOW); delay (1000); digitalWrite (3, HIGH); delay (2000); digitalWrite (3, LOW); delay (1000); } void E() { digitalWrite (3,HIGH); delay (2000); digitalWrite (3, LOW); delay (1000); } void L() { digitalWrite (3, HIGH); delay (2000); digitalWrite (3, LOW); delay (1000); digitalWrite (3, HIGH); delay (3000); digitalWrite (3, LOW); delay (1000); digitalWrite (3, HIGH); delay (2000); digitalWrite (3, LOW); delay (1000); digitalWrite (3, HIGH); delay (2000); digitalWrite (3, LOW); delay (1000); } void P() { digitalWrite (3, HIGH); delay (2000); digitalWrite (3, LOW); delay (1000); digitalWrite (3, HIGH); delay (3000); digitalWrite (3, LOW); delay (1000); digitalWrite (3, HIGH); delay (3000); digitalWrite (3, LOW); delay (1000); digitalWrite (3, HIGH); delay (2000); digitalWrite (3, LOW); delay (1000); } void Speaker () { EMT(); delay (1000); H(); delay (1000); EMT(); delay (1000); E(); delay (1000); EMT(); delay (1000); L(); delay (1000); EMT(); delay (1000); P(); delay (1000); } void EMT() { for(int hz = 440; hz < 1000; hz++){ tone(2, hz, 50); delay(5); } noTone(2); // Whoop down for(int hz = 1000; hz > 440; hz--){ tone(2, hz, 50); delay(5); } noTone(2); for(int hz = 440; hz < 1000; hz++){ tone(2, hz, 50); delay(5); } noTone(2); // Whoop down for(int hz = 1000; hz > 440; hz--){ tone(2, hz, 50); delay(5); } noTone(2); for(int hz = 440; hz < 1000; hz++){ tone(2, hz, 50); delay(5); } noTone(2); // Whoop down for(int hz = 1000; hz > 440; hz--){ tone(2, hz, 50); delay(5); } noTone(2); } void Help() { H(); delay (1000); E(); delay (1000); L(); delay (2000); P(); delay (1000); } void Sensor() { byte wLeft = digitalRead(4); // Copy left result to wLeft byte wRight = digitalRead(7); // Copy right result to wRight if(wLeft==0 && wRight ==0){ Serial.print(wLeft); // Display left whisker state Serial.println(wRight);// Display right whisker state Speaker(); delay(50); } } void loop() { forward(); }
2.21875
2
2024-11-18T18:22:53.545625+00:00
2020-07-05T23:30:26
fb8ed7f2860ef031b8bfee7c16fc03c613115a82
{ "blob_id": "fb8ed7f2860ef031b8bfee7c16fc03c613115a82", "branch_name": "refs/heads/master", "committer_date": "2020-07-05T23:30:26", "content_id": "361cfb837b33c703d7e2c86a1b6d62dbfda02f1f", "detected_licenses": [ "MIT" ], "directory_id": "e9cb9f7b28e0b2112565feebf8cb39818095d08e", "extension": "c", "filename": "main.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 277400846, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2572, "license": "MIT", "license_type": "permissive", "path": "/trabalho_exercicio01_v01/main.c", "provenance": "stackv2-0003.json.gz:385663", "repo_name": "OtavioPinheiro/TrabalhoFinalLPFatec", "revision_date": "2020-07-05T23:30:26", "revision_id": "7424a4c1e37d4be423d7e03ba7316a2ed48b5bb9", "snapshot_id": "a4e673b834dc3d7c543450c0fd24a58ff08a6646", "src_encoding": "ISO-8859-1", "star_events_count": 0, "url": "https://raw.githubusercontent.com/OtavioPinheiro/TrabalhoFinalLPFatec/7424a4c1e37d4be423d7e03ba7316a2ed48b5bb9/trabalho_exercicio01_v01/main.c", "visit_date": "2022-11-13T06:49:59.773415" }
stackv2
#include <stdio.h> #include <stdlib.h> #define NUM_RSP 50 #define NUM_CNDT 5 int pontuacao(int i, int j, char **respostas_candidatos, char *gabarito); void imprimir(int i, char **matricula_candidato, int pontos[NUM_CNDT]); void ordenar(int i, int j, int menor, int pontos[NUM_CNDT], char **ordem, char **matricula_candidato); //Inicialização. Declaro as variáveis char *p_tabela[NUM_CNDT][2] = {NULL}; char *matricula_candidato[] = {"12134", "12131", "12233", "13311", "14411"}; char *respostas_candidato[] = { "bcdadceeaabdeaeaabcdadceeadeaeaabcdaceeeababceabceda", "cbabcadeacbaeabdeaeaabcdaeeaabdaabdeaeaabcedaaabdeae", "abdeaeaabcdaeeaabdaabdeaeadeaeaabcdaeeaabdaabdeaeaaa", "cbabcadeacbaeabdeaeaabcdaeeaabdaabdeaeaabcedaaabdeae", "eabdeaeaabcdaeeaabdaaeaabcdaeeaaeaeaabcdaeeaabdaabde" }; char *gabarito = {"bcdadceeadeaeaabcdaceeeababceabdeaeaabcdaeeaabdabced"}; int pontos[NUM_CNDT] = {0}; int i, j, menor =0; char *ordem[1] = {NULL}; int main() { for(i = 0; i<NUM_CNDT; i++) { p_tabela[i][0] = matricula_candidato[i]; p_tabela[i][1] = respostas_candidato[i]; printf("%s - %s\n", p_tabela[i][0], p_tabela[i][1]); } //Pontuação pontuacao(i, j, respostas_candidato, gabarito); //Imprimir antes de ordenar imprimir(i, matricula_candidato, pontos); //Ordenar ordenar(i, j, menor, pontos, ordem, matricula_candidato); printf("\n"); //Imprimir imprimir(i, matricula_candidato, pontos); return 0; } int pontuacao(int i, int j, char **respostas_candidatos, char *gabarito) { for(i = 0; i < NUM_CNDT; i++) { for(j = 0; j < NUM_RSP; j++) { if(respostas_candidato[i][j] == gabarito[i]) { pontos[i]++; } } } return *pontos; } void imprimir(int i, char **matricula_candidato, int pontos[NUM_CNDT]) { for(i = 0; i < NUM_CNDT; i++) { printf("\n%s - %d", matricula_candidato[i], pontos[i]); } } void ordenar(int i, int j, int menor, int pontos[NUM_CNDT], char **ordem, char **matricula_candidato) { for(i = 0; i < NUM_CNDT; i++) { for(j = 0; j < NUM_CNDT; j++) { if(pontos[i] >= pontos[j]) { menor = pontos[i]; pontos[i] = pontos[j]; pontos[j] = menor; ordem[0] = matricula_candidato[i]; matricula_candidato[i] = matricula_candidato[j]; matricula_candidato[j] = ordem[0]; } } } }
3.125
3
2024-11-18T18:23:00.474558+00:00
2021-03-09T04:45:22
9760c35522689a16ba7d70fa951d3a9f83a600cd
{ "blob_id": "9760c35522689a16ba7d70fa951d3a9f83a600cd", "branch_name": "refs/heads/main", "committer_date": "2021-03-09T04:45:22", "content_id": "3995564831ba818fc460a48d532cc006bf88e24f", "detected_licenses": [ "MIT" ], "directory_id": "36d99b1a25c2b52d4332b4dccebe5d24622bae70", "extension": "c", "filename": "serverNetworkMethods.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 343586468, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2023, "license": "MIT", "license_type": "permissive", "path": "/serverNetworkMethods/serverNetworkMethods.c", "provenance": "stackv2-0003.json.gz:385919", "repo_name": "pabloturati/CS344-Assignment5", "revision_date": "2021-03-09T04:45:22", "revision_id": "217ff466a7d40835dd22d5eb8270e0d975e8c649", "snapshot_id": "c6b1b7a62e8c7a93416c37d25919dd722dc60041", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/pabloturati/CS344-Assignment5/217ff466a7d40835dd22d5eb8270e0d975e8c649/serverNetworkMethods/serverNetworkMethods.c", "visit_date": "2023-03-23T12:50:58.313162" }
stackv2
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <netinet/in.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include "../sharedMethods/sharedMethods.h" #include "../constants/constants.h" // Set up the address struct for the server socket void setupServerAddressStruct(struct sockaddr_in *address, int portNumber) { // Clear out the address struct memset((char *)address, END_STRING_CHARACTER, sizeof(*address)); // The address should be network capable address->sin_family = AF_INET; // Store the port number address->sin_port = htons(portNumber); // Allow a client at any address to connect to this server address->sin_addr.s_addr = INADDR_ANY; } int createServerSocketAndListenForConnections(int portNumber) { struct sockaddr_in serverAddress; // Create the socket that will listen for connections int listenSocket = socket(AF_INET, SOCK_STREAM, 0); if (listenSocket < 0) exitWithError(SERVER_OPEN_SOCKET_ERROR_MSG, DEFAULT_ERROR_EXIT_CODE); // Set up the address struct for the server socket setupServerAddressStruct(&serverAddress, portNumber); // Associate the socket to the port if (bind(listenSocket, (struct sockaddr *)&serverAddress, sizeof(serverAddress)) < 0) exitWithError(SERVER_BINDING_ERROR_MSG, DEFAULT_ERROR_EXIT_CODE); // Start listening for connetions. Allow up to a max number of connections to queue up listen(listenSocket, MAX_NUM_OF_CONNECTIONS); return listenSocket; } int acceptClientConnection(int listenSocket) { struct sockaddr_in clientAddress; socklen_t sizeOfClientInfo = sizeof(clientAddress); // Accept the connection request which creates a connection socket int connectionSocket = accept(listenSocket, (struct sockaddr *)&clientAddress, &sizeOfClientInfo); if (connectionSocket < 0) fprintf(stderr, "%s", SERVER_ACCEPT_CONNECTION_ERROR_MSG); return connectionSocket; }
2.984375
3
2024-11-18T18:23:00.686532+00:00
2018-01-18T11:22:08
6b7f65c6ee85da4fea88e63aa03f4feb2497ac29
{ "blob_id": "6b7f65c6ee85da4fea88e63aa03f4feb2497ac29", "branch_name": "refs/heads/master", "committer_date": "2018-01-18T11:22:08", "content_id": "113fa271d5ee3e91de4fb63d7fd5ae69fc5aea08", "detected_licenses": [ "MIT" ], "directory_id": "f753c390f4b64737377e235faca37415229a5774", "extension": "c", "filename": "utils_parse.c", "fork_events_count": 2, "gha_created_at": "2017-10-01T20:50:23", "gha_event_created_at": "2017-10-22T17:15:24", "gha_language": "C", "gha_license_id": null, "github_id": 105473489, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 11878, "license": "MIT", "license_type": "permissive", "path": "/utils_parse.c", "provenance": "stackv2-0003.json.gz:386177", "repo_name": "florianeidner/isoident", "revision_date": "2018-01-18T11:22:08", "revision_id": "0ab94791c1fb76183ae27fdb242f2ab1b1159913", "snapshot_id": "118a07e1ef9d1b004f1a815695f265de0ba6d996", "src_encoding": "UTF-8", "star_events_count": 6, "url": "https://raw.githubusercontent.com/florianeidner/isoident/0ab94791c1fb76183ae27fdb242f2ab1b1159913/utils_parse.c", "visit_date": "2021-09-04T11:42:28.462400" }
stackv2
/** /file utils_parse.c * /brief Parsing the keys for manufacturer, pgn ,spn and function * * This module takes the adress-claimed message (PGN 60928) and uses * the NAME from the CAN Data field to retrieve manufacturer, function * and class of the sender from the iso 11783 NAME list. * * /author Florian Eidner */ #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <inttypes.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <string.h> #include "utils_general.h" /* * \brief Create bitmasks * * To extract certain bits from a 64bit integer, * a bitmask is used. The mask is returned by this function. */ u_int64_t create_mask(int start_bit, int end_bit) { u_int64_t mask = 0; int i; if (start_bit <= end_bit) { for (i = start_bit; i <= end_bit; i++) { mask |= 1 << i; } } else { mask = 0; } return mask; } /* * \brief Extract Manufacturer key * * Extracting the manufacturer key from the data field of a NAME claim */ int parse_get_manufac_id(u_int64_t can_data) { int manufac_id; u_int64_t mask = create_mask(0,10); manufac_id = mask & (can_data >> 21); fprintf(stdout,"mask: 0x%" PRIx64 " - manufac_id: %d\n",mask, manufac_id ); return manufac_id; } /* * \brief Create UUID * * Extracting the manufacturer key and device id and use it as UUID * Consisting of the first 32bit of the data field. */ int parse_get_device_uuid(u_int64_t can_data) { int device_uuid; // u_int64_t mask = create_mask(0,20); // Instead of device ID, create UUID from // manufacturer ID and this device ID: u_int64_t mask = create_mask(0,31); device_uuid = can_data & mask; fprintf(stdout,"mask: 0x%" PRIx64 " - device_id: %d\n",mask, device_uuid ); return device_uuid; } /* * \brief Extract function key * * Extracting the manufacturer key from the * data field of a NAME claim. */ int parse_get_function_id(u_int64_t can_data) { int function_id; u_int64_t mask = create_mask(0,7); function_id = mask & (can_data >> 40); fprintf(stdout,"mask: 0x%" PRIx64 " - function_id: %d\n",mask, function_id ); return function_id; } /* * \brief Extract industry key * * Extracting the manufacturer key from the * data field of a NAME claim. */ int parse_get_industry_id(u_int64_t can_data) { int industry_id; u_int64_t mask = create_mask(0,2); industry_id = mask & (can_data >> 60); fprintf(stdout,"mask: 0x%" PRIx64 " - industry_id: %d\n",mask, industry_id ); return industry_id; } /* * \brief Extract class key * * Extracting the manufacturer key from the * data field of a NAME claim. */ int parse_get_class_id(u_int64_t can_data) { int class_id; u_int64_t mask = create_mask(0,6); class_id = mask & (can_data >> 49); fprintf(stdout,"mask: 0x%" PRIx64 " - class_id: %d\n",mask, class_id ); return class_id; } /* * \brief Parse manufacturer name * * Looking up manufacturer key in file and get the name of the manufacturer. */ int parse_get_manufacturer(u_int64_t can_data,char* man_name) { int man_id = parse_get_manufac_id(can_data); //fprintf(stdout,"Manufacturer ID: %d\n",man_id); FILE *file; char* path = concat(datasets_path,"manufacturers.CSV"); if ((file = load_file(path)) == NULL) { free(path); return EXIT_FAILURE; } free(path); char * line = NULL; size_t len = 0; ssize_t read; int lineID; short match = 0; if (file == NULL) exit(0); if (file){ while (((read =getline(&line, &len, file)) != -1)) { char *line2 = line; int lineID = (int)strtol((strtok(line2, ";")),((char **)NULL),10); //fprintf(stdout,"lineID: %d\n", lineID); if (lineID == man_id){ char* man_name_update = strtok(NULL,"\n"); strcpy(man_name,man_name_update); //This is important, strtok changes the pointer! match=1; break; } } if (match == 0){ strcpy(man_name,"unknown"); fprintf(stdout,"Manufacturer not found.\n"); } else { fprintf(stdout,"Manufacturer: %s \n",man_name); } } else{ fprintf(stderr,"File could not be opened."); } free(line); fclose(file); return 0; } /* * \brief Parse function name * * Looking up function key in file and get the name of the function. */ int parse_get_function(u_int64_t can_data, char* func_name) { int func_id = parse_get_function_id(can_data); if (func_id > 127) { char* industry_id = int_to_string(parse_get_industry_id(can_data)); char* class_id =int_to_string(parse_get_class_id(can_data)); char* function_id = int_to_string(func_id); char* concat1 = concat(industry_id,class_id); char* concat2 = concat(concat1,function_id); func_id = str_to_int(concat2); free (industry_id); free (class_id); free (function_id); free (concat1); free (concat2); } //fprintf(stdout,"Function ID: %d\n",func_id); FILE *file; char* path = concat(datasets_path,"functions.CSV"); if ((file = load_file(path)) == NULL) { free(path); return EXIT_FAILURE; } free(path); char * line = NULL; size_t len = 0; ssize_t read; int lineID; short match=0; if (file == NULL) exit(0); if (file){ while (((read =getline(&line, &len, file)) != -1)) { char *line2 = line; int lineID = (int)strtol((strtok(line2, ";")),((char **)NULL),10); //fprintf(stdout,"lineID: %d\n", lineID); if (lineID == func_id) { char* func_name_update = strtok(NULL,"\n"); strcpy(func_name,func_name_update); match=1; break; } } if (match == 0){ strcpy(func_name,"unknown"); fprintf(stdout,"Function not found.\n"); } else { fprintf(stdout,"Function: %s \n",func_name); } } else{ fprintf(stderr,"File could not be opened."); } free(line); fclose(file); return 0; } /* * \brief Parse class and industry names * */ int parse_get_class_industry(u_int64_t can_data, char* class_name, char* industry_name) { int class_id = parse_get_class_id(can_data); int industry_id = parse_get_industry_id(can_data); //fprintf(stdout,"Function ID: %d\n",func_id); FILE *file; char* path = concat(datasets_path,"industry_class.CSV"); if ((file = load_file(path)) == NULL) { free(path); return EXIT_FAILURE; } free(path); char * line = NULL; size_t len = 0; ssize_t read; int lineID; short industry_match=0; short class_match=0; if (file == NULL) exit(0); if (file){ while (((read =getline(&line, &len, file)) != -1)) { char* line2 = line; int lineID = (int)strtol((strtok(line2, ";")),((char **)NULL),10); //fprintf(stdout,"lineID: %d\n", lineID); if (lineID == industry_id) { int lineID2 = (int)strtol((strtok(NULL, ";")),((char **)NULL),10); char* industry_name_update = strtok(NULL,";"); strcpy(industry_name,industry_name_update); industry_match=1; if (lineID2 == class_id) { char* class_name_update = strtok(NULL,"\n\r\t"); strcpy(class_name,class_name_update); class_match=1; fprintf(stdout, "Found class match - ID: %d, Name: %s\n",class_id,class_name); break; } } } if (industry_match == 0){ strcpy(industry_name,"unknown"); fprintf(stdout,"Industry not found.\n"); } else { fprintf(stdout,"Industry: %s \n",industry_name); } if (class_match == 0){ strcpy(class_name,"unknown"); fprintf(stdout,"Class not found.\n"); } } else{ fprintf(stderr,"File could not be opened."); } free(line); fclose(file); return 0; } /* * \brief Get PGN * * Extracting the PGN from the CAN identifier */ int parse_get_pgn(u_int32_t can_id) { int PGN; //clear lower 3 bits from canID, because its a 29bit identifier and can_id = (can_id & create_mask(0,28)); //GET PF (PDU Format) from Identifier if PF<= 239 -> PDU1, else PDU2 int PF = (can_id >> 16) & create_mask(0,7); if (PF < 240) { PGN = ((can_id >> 16)<<8) & create_mask(0,17); } else { PGN = (can_id >> 8) & create_mask(0,17); } //fprintf(stdout,"PF is: %d - PGN is: %d\n",PF, PGN ); return PGN; } /* * \brief Parse PGN name * * Looking up PGN in file and get the name of the PGN. */ int parse_get_pgn_name(int pgn_id, char* pgn_name) { FILE *file; char* path = concat(datasets_path,"parametergroups.CSV"); if ((file = load_file(path)) == NULL) { free(path); return EXIT_FAILURE; } free(path); char * line = NULL; size_t len = 0; ssize_t read; short match = 0; int lineID; int pgn_type = 0; //0 = Unknown, 1= ISO11783, 2=J1939, 3=NMEA2000 if (file == NULL) exit(0); if (file){ while (((read =getline(&line, &len, file)) != -1)) { char* line2 = line; int lineID = (int)strtol((strtok(line, ";")),((char **)NULL),10); //fprintf(stdout,"lineID: %d\n", lineID); if (lineID == pgn_id){ char* pgn_name_update = strtok(NULL,";"); char* pgn_type_c = strtok(NULL,"\n"); fprintf(stdout,"FIRST CHAR: %c\n", pgn_type_c[0]); if (pgn_type_c != NULL) { switch (pgn_type_c[0]) { case 'I': pgn_type = 1; break; case 'J': pgn_type = 2; break; case 'N': pgn_type = 3; break; default: pgn_type = 0; break; } } else { fprintf(stderr, "Error in structure of parametergroups.csv\n"); } strcpy(pgn_name,pgn_name_update); fprintf(stdout,"Found PGN Name: "); match = 1; break; } } if (match == 0){ pgn_name="unknown"; fprintf(stdout,"PGN name not found.\n"); } else { fprintf(stdout,"%s \n",pgn_name); } } else{ fprintf(stdout,"File could not be opened."); } free(line); fclose(file); return pgn_type; } /* * \brief Retrieve SPNs * * Take a PGN and look up all the SPNs known. */ int parse_get_signals(int pgn_id, short round, signal_t* signal_spn) { fprintf(stdout,"Extracting Signals for PGN\n"); FILE *file; char* path = concat(datasets_path,"signals.CSV"); if ((file = load_file(path)) == NULL) { free(path); return EXIT_FAILURE; } free(path); char * line = NULL; int lineID; size_t len = 0; ssize_t read; short counter = 0; if (file == NULL) exit(0); if (file){ signal_spn->spn = 0; while (((read =getline(&line, &len, file)) != -1)) { char* line2 = line; int lineID = (int)strtol((strtok(line, ";")),((char **)NULL),10); //fprintf(stdout,"lineID: %d\n", lineID); if (lineID == pgn_id){ counter += 1; if (counter == round) { fprintf(stdout, "Here1\n"); signal_spn->spn = str_to_int(strtok(NULL, ";")); fprintf(stdout, "Here2 - spn: %d\n",signal_spn->spn); strcpy(signal_spn->name,strtok(NULL,";")); fprintf(stdout, "Here3 - name: %s\n",signal_spn->name); signal_spn->start_bit = str_to_int((strtok(NULL,";"))); fprintf(stdout, "Here4 - start: %d\n",signal_spn->start_bit); signal_spn->len = str_to_int((strtok(NULL,";"))); fprintf(stdout, "Here5 - len: %d\n",signal_spn->len); strcpy(signal_spn->unit, strtok(NULL,";")); fprintf(stdout, "Here6 - unit: %s\n",signal_spn->unit); signal_spn->offset = str_to_int((strtok(NULL,";"))); fprintf(stdout, "Here7 - offset: %d\n",signal_spn->offset); signal_spn->factor = str_to_int((strtok(NULL,";"))); fprintf(stdout, "Here8 - factor: %d\n",signal_spn->factor); signal_spn->range_min = str_to_int((strtok(NULL,";"))); fprintf(stdout, "Here9 - range_min: %d\n",signal_spn->range_min); signal_spn->range_max = str_to_int((strtok(NULL, "\n"))); fprintf(stdout, "Here10\n"); fprintf(stdout,"Signal SPN: %s found.\n", signal_spn->name); break; } } } } else{ fprintf(stderr,"File could not be opened."); } free(line); fclose(file); return signal_spn->spn; }
2.59375
3
2024-11-18T18:23:00.801665+00:00
2018-04-23T21:23:41
3850301ac12f022f3e727b2e4a1a2d559598eb1b
{ "blob_id": "3850301ac12f022f3e727b2e4a1a2d559598eb1b", "branch_name": "refs/heads/develop", "committer_date": "2018-04-23T21:23:41", "content_id": "da0050f7e5f8873eba90cf21fb38cd188c64f117", "detected_licenses": [ "BSL-1.0" ], "directory_id": "d8860eb725a51fd0ef814bebfb8abaa8a807996d", "extension": "c", "filename": "strasear.c", "fork_events_count": 0, "gha_created_at": "2013-12-31T23:10:07", "gha_event_created_at": "2018-04-23T21:52:16", "gha_language": "C", "gha_license_id": null, "github_id": 15558048, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 11459, "license": "BSL-1.0", "license_type": "permissive", "path": "/strfuncs/source/strasear.c", "provenance": "stackv2-0003.json.gz:386306", "repo_name": "mlbrock/MlbDevOld", "revision_date": "2018-04-23T21:23:41", "revision_id": "d31005dbe8ec05f59557e189e7194ee952ab64ff", "snapshot_id": "31c9809c8cbf8a2066c139d712a5ff0f758bbc39", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/mlbrock/MlbDevOld/d31005dbe8ec05f59557e189e7194ee952ab64ff/strfuncs/source/strasear.c", "visit_date": "2021-01-20T03:53:21.763387" }
stackv2
/* *********************************************************************** */ /* *********************************************************************** */ /* STRFUNCS String and Memory Functions Library Module */ /* *********************************************************************** */ /* File Name : %M% File Version : %I% Last Extracted : %D% %T% Last Updated : %E% %U% File Description : Searchs an array by key, inserting the key if not found. Revision History : 1991-09-08 --- Creation Michael L. Brock Copyright Michael L. Brock 1991 - 2018. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ /* *********************************************************************** */ /* *********************************************************************** */ /* *********************************************************************** */ /* Include necessary header files . . . */ /* *********************************************************************** */ #include "strfunci.h" /* *********************************************************************** */ /* *********************************************************************** */ /* *********************************************************************** */ /* BOH NAME : STR_ARRAY_search SYNOPSIS : return_code = STR_ARRAY_search(data_count, data_list, key_data, data_length, found_index, compare_function, insert_function); int return_code; unsigned int *data_count; void **data_list; const void *key_data; size_t data_length; unsigned int *found_index; int (*compare_function)(void *, const void *, const void *, size_t); int (*insert_function)(unsigned int *, void **, const void *, size_t, unsigned int); DESCRIPTION : Performs a binary search in the array ``data_list`` for the element ``key_data`` using the comparison function ``compare_function``. If ``key_data`` is found, its index in ``data_list`` is placed into the unsigned int to which ``found_index`` points. If ``key_data`` is not found, this function will attempt to add it to the array ``data_list`` in sorted order using the insertion function ``insert_function``. PARAMETERS : Parameters to this function are as follow: (.) ``data_count`` points to an ``unsigned int`` which contains the number of elements in the array to which ``data_list`` points. (-) If the function succeeds in inserting ``key_data`` then that integer will have added to it the number of elements inserted (that it, is will be incremented). (.) ``data_list`` points to a pointer to ``void`` which contains the array. If the function succeeds in inserting an element then the memory pointed to by ``data_list`` will be re-allocated to hold the new size of the array. (.) ``key_data`` points to the data for which the search is to occur. (.) ``data_length`` is the length of the array elements in ``data_list``. (.) ``found_index`` points to an unsigned integer into which the index of ``key_data`` in ``data_list`` will be placed, if found. (-) If ``key_data`` is not found, the unsigned int to which ``found_index`` points will be set to the index at which ``key_data`` will be inserted. (-) Note, however, that ``found_index`` will not be de-referenced if it is ''NULL''. (.) ``compare_function`` is a pointer to the function which will determine equivalence of ``key_data`` ``vis-a-vis`` the elements in ``data_list``. The function to which ``compare_function`` points should accept the arguments indicated in the SYNOPSIS and return an integral result as follows: (..) negative if the first element is less than second. (..) positive if the first element is greater than second. (..) zero if the elements are equal. (.) ``insert_function`` is a pointer to the function which will insert ``key_data`` into the array ``data_list``. The function to which ``insert_function`` points should accept the arguments indicated in the SYNOPSIS and return one of the two values: (..) ''STRFUNCS_FAILURE'' if an error occurs. (..) ''STRFUNCS_SUCCESS'' if it successfully inserts ``key_data``. RETURNS : Returns from this function are as follow: (.) ''STRFUNCS_FAILURE'' if an error occurs. (.) ''STRFUNCS_ITEM_FOUND'' if ``key_data`` is found in the array ``data_list``. In this case, the unsigned int to which the ``found_index`` parameter points will be set to the index of that element in the array. (.) ''STRFUNCS_ITEM_NOT_FOUND'' if ``key_data`` is not found in the array ``data_list``. In this case, the unsigned int to which the ``found_index`` parameter points will be set to the index within ``data_list`` at which ``key_data`` was inserted by this function. NOTES : CAVEATS : The results of invoking this function with an ``data_list`` not in sorted order using the same criteria as the function ``compare_function`` are undefined. SEE ALSO : STR_ARRAY_bsearch STR_LIST_search EXAMPLES : AUTHOR : Michael L. Brock COPYRIGHT : Copyright 1991 - 2018 Michael L. Brock OUTPUT INDEX: STR_ARRAY_search Memory Array Functions:STR_ARRAY_search STRFUNCS:Memory Array Functions:STR_ARRAY_search String Functions:See STRFUNCS PUBLISH XREF: STR_ARRAY_search PUBLISH NAME: STR_ARRAY_search ENTRY CLASS : Memory Array Functions EOH */ /* *********************************************************************** */ #ifndef NARGS int STR_ARRAY_search(unsigned int *data_count, void **data_list, const void *key_data, size_t data_length, unsigned int *found_index, int (*compare_function)(void *, const void *, const void *, size_t), int (*insert_function)(unsigned int *, void **, const void *, size_t, unsigned int)) #else int STR_ARRAY_search(data_count, data_list, key_data, data_length, found_index, compare_function, insert_function) unsigned int *data_count; void **data_list; const void *key_data; size_t data_length; unsigned int *found_index; int (*compare_function)(); int (*insert_function)(); #endif /* #ifndef NARGS */ { int return_code; unsigned int tmp_found_index; found_index = (found_index != NULL) ? found_index : &tmp_found_index; if ((return_code = STR_ARRAY_bsearch(NULL, *data_count, *data_list, key_data, data_length, found_index, STRFUNCS_DIRECTION_TOP, compare_function)) == STRFUNCS_ITEM_NOT_FOUND) { if ((*insert_function)(data_count, data_list, key_data, data_length, *found_index) == STRFUNCS_FAILURE) return_code = STRFUNCS_FAILURE; } return(return_code); } /* *********************************************************************** */ #ifdef TEST_MAIN #include <stdio.h> #include <string.h> COMPAT_FN_DECL(int main, (void)); /* *********************************************************************** */ /* *********************************************************************** */ /* *********************************************************************** */ int main() { int return_code = 0; unsigned int count_1; unsigned int line_count = 0; unsigned int test_count = 0; unsigned int saved_count = 0; unsigned int found_index; char *test_list = NULL; char *saved_list = NULL; char buffer[512]; fprintf(stderr, "Test of function 'STR_ARRAY_search()'\n"); fprintf(stderr, "---- -- -------- --------------------\n\n"); while ((!feof(stdin)) && (!ferror(stdin))) { *buffer = '\0'; while (!(*buffer)) { fgets(buffer, sizeof(buffer) - 1, stdin); while (strlen(buffer) && (buffer[strlen(buffer) - 1] == '\n')) buffer[strlen(buffer) - 1] = '\0'; line_count++; } if (!STRFUNCS_stricmp(buffer, "LIST")) { fprintf(stderr, "[HEAD] ---> [%08p]\n", test_list); for (count_1 = 0; count_1 < test_count; count_1++) fprintf(stderr, "[%05u][%08p] ---> [%s]\n", count_1, test_list + (count_1 * sizeof(buffer)), test_list + (count_1 * sizeof(buffer))); } else if ((!STRFUNCS_stricmp(buffer, "END")) || (!STRFUNCS_stricmp(buffer, "QUIT")) || (!STRFUNCS_stricmp(buffer, "EXIT"))) break; else if ((return_code = STR_ARRAY_search(&test_count, ((void **) &test_list), ((const void *) buffer), sizeof(buffer), &found_index, ((int (*)(void *, const void *, const void *, size_t)) STR_strcmp), mema_insert)) == STRFUNCS_FAILURE) { fprintf(stderr, "\nERROR ON ATTEMPT TO ADD STRING\n\n"); break; } else if (return_code == STRFUNCS_ITEM_FOUND) fprintf(stderr, "STRING ALREADY IN LIST (INDEX = %u)\n", found_index); else if ((return_code = mema_append(&saved_count, ((void **) &saved_list), buffer, sizeof(buffer))) == STRFUNCS_FAILURE) { fprintf(stderr, "UNABLE TO SAVE BACK-UP COPY OF STRING\n"); break; } fprintf(stderr, "%05u / %05u ----------------------------------\n", line_count, test_count); return_code = 0; } fprintf(stderr, "%05u / %05u ==================================\n", line_count, test_count); if (!return_code) { if (test_count != saved_count) { fprintf(stderr, "%s (%u) %s (%u).\n", "The number of strings added to the list", test_count, "is not equal to the number of saved string copies", saved_count); return_code = -1; } else { fprintf(stderr, "Sorting . . ."); #ifndef NARGS STR_ARRAY_qsort(NULL, saved_count, saved_list, sizeof(buffer), ((int (*)(void *, const void *, const void *, size_t)) STR_strcmp)); #else STR_ARRAY_qsort(NULL, saved_count, saved_list, sizeof(buffer), STR_strcmp); #endif /* #ifndef NARGS */ fprintf(stderr, "\nChecking . . ."); for (count_1 = 0; count_1 < saved_count; count_1++) { #ifndef NARGS if ((return_code = STR_ARRAY_find(test_count, test_list, saved_list + (count_1 * sizeof(buffer)), sizeof(buffer), &found_index, ((int (*)(void *, const void *, const void *, size_t)) STR_strcmp))) == STRFUNCS_FAILURE) { #else if ((return_code = STR_ARRAY_find(test_count, test_list, saved_list + (count_1 * sizeof(buffer)), sizeof(buffer), &found_index, STR_strcmp)) == STRFUNCS_FAILURE) { #endif /* #ifndef NARGS */ fprintf(stderr, "\nERROR ON ATTEMPT TO FIND STRING %u (%s).\n", count_1, saved_list + (count_1 * sizeof(buffer))); break; } else if (return_code == STRFUNCS_ITEM_NOT_FOUND) { fprintf(stderr, "\nUNABLE TO FIND STRING %s.\n", saved_list + (count_1 * sizeof(buffer))); break; } else if (found_index != count_1) { fprintf(stderr, "\n%s (SORTED SAVED ITEM %u, FOUND ITEM %u).\n", "FIND ATTEMPT YIELDED UNEXPECTED RESULT:", count_1, found_index); return_code = -1; break; } return_code = 0; } fprintf(stderr, "\n"); } } return(return_code); } /* *********************************************************************** */ #endif /* #ifdef TEST_MAIN */
2.6875
3
2024-11-18T18:23:00.888612+00:00
2015-12-22T23:58:16
b499e6c85477bd6c60526038b7dd06ed3f37d80b
{ "blob_id": "b499e6c85477bd6c60526038b7dd06ed3f37d80b", "branch_name": "refs/heads/master", "committer_date": "2015-12-22T23:58:16", "content_id": "fbfe67390ae96038d682df82775ef0c26e218de8", "detected_licenses": [ "Unlicense" ], "directory_id": "6e2b1975815abfd8b6d8fb6b70511360d09a5a29", "extension": "c", "filename": "thread_storage_no.c", "fork_events_count": 0, "gha_created_at": null, "gha_event_created_at": null, "gha_language": null, "gha_license_id": null, "github_id": 48000131, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 980, "license": "Unlicense", "license_type": "permissive", "path": "/src/thread_storage_no.c", "provenance": "stackv2-0003.json.gz:386438", "repo_name": "souryogurt/sourkode", "revision_date": "2015-12-22T23:58:16", "revision_id": "dcf3e04a0ada64a75b7d6776e764071b6ad599df", "snapshot_id": "869338e2d2e13457ec955f7fd678b8f106091107", "src_encoding": "UTF-8", "star_events_count": 2, "url": "https://raw.githubusercontent.com/souryogurt/sourkode/dcf3e04a0ada64a75b7d6776e764071b6ad599df/src/thread_storage_no.c", "visit_date": "2021-01-10T03:35:05.960855" }
stackv2
#include <KD/KHR_thread_storage.h> #ifndef KHR_THREAD_STORAGE_SIZE #define KHR_THREAD_STORAGE_SIZE 1024 #endif typedef struct TLSItem { const void *id; void *data; } TLSItem; static TLSItem thread_storage_items[KHR_THREAD_STORAGE_SIZE] = {KD_NULL}; KD_API KDThreadStorageKeyKHR KD_APIENTRY kdMapThreadStorageKHR (const void *id) { KDThreadStorageKeyKHR key; for (key = 1; key < KHR_THREAD_STORAGE_SIZE; key++) { if (thread_storage_items[key].id == id) { return key; } else if (thread_storage_items[key].id == KD_NULL) { thread_storage_items[key].id = id; return key; } } kdSetError (KD_ENOMEM); return 0; } KD_API KDint KD_APIENTRY kdSetThreadStorageKHR (KDThreadStorageKeyKHR key, void *data) { thread_storage_items[key].data = data; return 0; } KD_API void *KD_APIENTRY kdGetThreadStorageKHR (KDThreadStorageKeyKHR key) { return thread_storage_items[key].data; }
2.578125
3
2024-11-18T18:23:01.399806+00:00
2023-08-25T08:03:33
5708bf82dd46d0521c5244a12a2ea86feb8242a6
{ "blob_id": "5708bf82dd46d0521c5244a12a2ea86feb8242a6", "branch_name": "refs/heads/master", "committer_date": "2023-08-25T08:03:33", "content_id": "d6df4474cd0ea9ca9e101706549ecff767e957c5", "detected_licenses": [ "BSD-2-Clause" ], "directory_id": "df90ed23a49dba79f61e5a28366424f0ecec60de", "extension": "c", "filename": "main.c", "fork_events_count": 12, "gha_created_at": "2016-07-29T20:43:25", "gha_event_created_at": "2021-02-03T17:18:22", "gha_language": "C++", "gha_license_id": "NOASSERTION", "github_id": 64509332, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 5829, "license": "BSD-2-Clause", "license_type": "permissive", "path": "/examples/programs/mergeconf/src/main.c", "provenance": "stackv2-0003.json.gz:386953", "repo_name": "Damdoshi/LibLapin", "revision_date": "2023-08-25T08:03:33", "revision_id": "41491d3d3926b8e42e3aec8d1621340501841aae", "snapshot_id": "306e8ae8be70be9e4de93db60913c4f092a714a7", "src_encoding": "UTF-8", "star_events_count": 39, "url": "https://raw.githubusercontent.com/Damdoshi/LibLapin/41491d3d3926b8e42e3aec8d1621340501841aae/examples/programs/mergeconf/src/main.c", "visit_date": "2023-09-03T10:11:06.743172" }
stackv2
/* ** Jason Brillante "Damdoshi" ** Hanged Bunny Studio 2014-2020 ** ** MergeConf (UniConf 2.0) ** ** stdin / -i [files]+ ** stdout / -o [outfile]+ */ #include <stdio.h> #include <lapin.h> #include <string.h> bool load_all_files(const char *prg, t_bunny_configuration_type format, t_bunny_configuration *cnf, const char **inputs, size_t len) { if (len) { for (size_t i = 0; i < len; ++i) if (bunny_open_configuration(inputs[i], cnf) == NULL) { fprintf(stderr, "%s: Cannot load file %s.\n", prg, inputs[i]); return (false); } } else { char buffer[1024 * 1024]; ssize_t z, s; z = s = 0; do { if ((s = read(STDIN_FILENO, &buffer[z], sizeof(buffer) - z - 1)) == -1) { fprintf(stderr, "%s: Cannot read from stdin: %s.\n", prg, strerror(errno)); return (false); } z += s; } while (s == 0 && z != sizeof(buffer) - 1); buffer[z] = '\0'; if (bunny_read_configuration(format, &buffer[0], cnf) == NULL) return (false); } return (true); } bool write_all_files(const char *prg, t_bunny_configuration_type format, t_bunny_configuration *cnf, const char **outputs, size_t len) { if (len) { for (size_t i = 0; i < len; ++i) if (bunny_save_configuration (bunny_which_format(outputs[i]), outputs[i], cnf) == false) { fprintf(stderr, "%s: Cannot write file %s.\n", prg, outputs[i]); return (false); } } else if (bunny_save_configuration(format, "/dev/stdout", cnf) == false) { fprintf(stderr, "%s: Cannot write configuration.\n", prg); return (false); } return (true); } int main(int argc, char **argv) { t_bunny_configuration *cnf; const char *inputs[argc]; const char *outputs[argc]; size_t nbr_inputs = 0; size_t nbr_outputs = 0; t_bunny_configuration_type iformat = BC_CUSTOM; t_bunny_configuration_type oformat = BC_CUSTOM; bool resolve = false; bunny_set_log_mode(false); bunny_set_error_descriptor(2); bunny_set_log_filter("system,ressource,syntax"); for (int i = 1; i < argc; ++i) { if (strcmp("--resolve", argv[i]) == 0) resolve = true; else if (!strcmp("-i", argv[i])) { if (iformat != BC_CUSTOM) { fprintf(stderr, "%s: Cannot mix option '-if' with option '-i'.\n", *argv); return (EXIT_FAILURE); } for (i += 1; i < argc && argv[i][0] != '-'; ++i) inputs[nbr_inputs++] = argv[i]; if (i < argc && argv[i][0] == '-') i -= 1; } else if (!strcmp("-if", argv[i])) { if (iformat != BC_CUSTOM) { fprintf(stderr, "%s: Input format is set twice.\n", *argv); return (EXIT_FAILURE); } if (nbr_inputs != 0) { fprintf(stderr, "%s: Cannot mix option '-if' with option '-i'.\n", *argv); return (EXIT_FAILURE); } i += 1; if (i >= argc) { fprintf(stderr, "%s: -if option takes a parameter.\n", *argv); return (EXIT_FAILURE); } if ((iformat = bunny_which_format(argv[i])) == BC_CUSTOM) { fprintf(stderr, "%s: Unknown format %s.\n", *argv, argv[i]); return (EXIT_FAILURE); } } else if (!strcmp("-o", argv[i])) { if (oformat != BC_CUSTOM) { fprintf(stderr, "%s: Cannot mix option '-of' with option '-o'.\n", *argv); return (EXIT_FAILURE); } for (i += 1; i < argc && argv[i][0] != '-'; ++i) outputs[nbr_outputs++] = argv[i]; if (i < argc && argv[i][0] == '-') i -= 1; } else if (!strcmp("-of", argv[i])) { if (oformat != BC_CUSTOM) { fprintf(stderr, "%s: Output format is set twice.\n", *argv); return (EXIT_FAILURE); } if (nbr_outputs != 0) { fprintf(stderr, "%s: Cannot mix option '-of' with option '-o'.\n", *argv); return (EXIT_FAILURE); } i += 1; if (i >= argc) { fprintf(stderr, "%s: -of option takes a parameter.\n", *argv); return (EXIT_FAILURE); } if ((oformat = bunny_which_format(argv[i])) == BC_CUSTOM) { fprintf(stderr, "%s: Unknown format %s.\n", *argv, argv[i]); return (EXIT_FAILURE); } } } if (oformat == BC_CUSTOM) oformat = BC_DABSIC; if (argc == 1 || (iformat == BC_CUSTOM && nbr_inputs == 0)) { fprintf (stderr, "Usage is:\n" "\n" " -if [format]\tSpecify the input format when using stdin\n" " -of [format]\tSpecify the output format when using stdout. Default is Dabsic.\n" " -i [files]+ \tSpecify input files. Cannot combine with if.\n" " -o [files]+ \tSpecify output files. Cannot combine with of.\n" "\n" "Supported formats are:\n" "\n" " .ini \tINI format\n" " .xml \tXML format\n" " .tmx \tXML format\n" " .lua \tLUA data format\n" " .json \tJSON format\n" " .lisp \tLISP format\n" " .el \tLISP format\n" " .csv \tCSV format\n" " .expr \tMathematic expression\n" " .dab \tDabsic format\n" " .sic \tDabsic format\n" " .dabsic\tDabsic format\n" " .dabseq\tDabsic sequence format\n" " .dabfun\tDabsic function format\n" "\n" ); return (EXIT_FAILURE); } if ((cnf = bunny_new_configuration()) == NULL) { fprintf(stderr, "%s: Cannot allocate memory for configuration merging.\n", argv[0]); return (EXIT_FAILURE); } if (load_all_files(*argv, iformat, cnf, inputs, nbr_inputs) == false) return (EXIT_FAILURE); if (resolve) if (bunny_configuration_resolve(cnf) == false) fprintf(stderr, "%s: Cannot resolve all operations! Operation will be rendered as it.", argv[0]); if (write_all_files(*argv, oformat, cnf, outputs, nbr_outputs) == false) return (EXIT_FAILURE); return (EXIT_SUCCESS); }
2.515625
3
2024-11-18T18:23:01.571633+00:00
2020-10-21T15:38:54
c51aaaf01838c1338c588dfba6989243d6170e2b
{ "blob_id": "c51aaaf01838c1338c588dfba6989243d6170e2b", "branch_name": "refs/heads/master", "committer_date": "2020-10-21T15:38:54", "content_id": "7d3acf059d9f1617cedcdbf1f32b1c8c9e2d8d4f", "detected_licenses": [ "MIT" ], "directory_id": "646d7124cbd340c6b1606cd222164241e7b2e722", "extension": "h", "filename": "bct.h", "fork_events_count": 0, "gha_created_at": "2020-10-20T14:35:53", "gha_event_created_at": "2020-10-20T20:48:25", "gha_language": "C", "gha_license_id": "MIT", "github_id": 305737127, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 1378, "license": "MIT", "license_type": "permissive", "path": "/src/bct.h", "provenance": "stackv2-0003.json.gz:387211", "repo_name": "aaronfox/branch-predictor-simulator", "revision_date": "2020-10-21T15:38:54", "revision_id": "af61c36964f6dd62fd074bdd84aec3be6f63a174", "snapshot_id": "9ef83e79700d50ee63614f1cbaa0b111a2787691", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/aaronfox/branch-predictor-simulator/af61c36964f6dd62fd074bdd84aec3be6f63a174/src/bct.h", "visit_date": "2023-01-01T15:50:33.280390" }
stackv2
/* * branch chooser table */ #pragma once #ifndef BCT_H_ #define BCT_H_ #define STRONGLY_GSHARE 3 #define WEAKLY_GSHARE 2 #define WEAKLY_BIMODAL 1 #define STRONGLY_BIMODAL 0 typedef enum Two_Bit_Chooser { strongly_bimodal = STRONGLY_BIMODAL, weakly_bimodal = WEAKLY_BIMODAL, weakly_gshare = WEAKLY_GSHARE, strongly_gshare = STRONGLY_GSHARE } Two_Bit_Chooser; typedef struct BCT_Attributes { uint32_t chooser_num; uint32_t index_width; }BCT_Attributes; typedef struct BCT { Two_Bit_Chooser* chooser; BCT_Attributes attributes; }BCT; /* * Inital the branch chooser table * input : * index_width : the width of index in PC addr to index the branch choose table * (hybrid) i_C */ void BCT_Initial(BCT* BranchChooserTable, uint32_t index_width); /* * Search the BranchChooserTable for PC "addr" and make prediction * input : * addr : PC * return : * the prediction on which predictor is chosen */ Predictor BCT_Predict(BCT* BranchChooserTable, uint32_t addr); /* * Update the BranchChooserTable * input : * addr : PC * result : struct "Result", the prediction and actual result */ void BCT_Update(BCT* BranchChooserTable, uint32_t addr, Result result); /* * Print the content of BranchChooserTable to file *fp */ void BCT_fprintf(BCT* BranchChooserTable, FILE *fp); #endif
2.59375
3
2024-11-18T18:23:01.794256+00:00
2017-04-26T12:26:31
1259ff7f1e9a9ba29a879b7cf6477427f380c35f
{ "blob_id": "1259ff7f1e9a9ba29a879b7cf6477427f380c35f", "branch_name": "refs/heads/master", "committer_date": "2017-04-26T12:26:31", "content_id": "bc00f50c9b96b5e99eb503aaa4227499368cc315", "detected_licenses": [ "MIT" ], "directory_id": "547246b03860043fa65a2542fc789b2705352550", "extension": "c", "filename": "main.c", "fork_events_count": 1, "gha_created_at": "2016-02-29T23:15:56", "gha_event_created_at": "2016-03-01T01:14:16", "gha_language": null, "gha_license_id": null, "github_id": 52831966, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 7818, "license": "MIT", "license_type": "permissive", "path": "/main.c", "provenance": "stackv2-0003.json.gz:387341", "repo_name": "Mkchouk/MiRCA", "revision_date": "2017-04-26T12:26:31", "revision_id": "0eab1443a125ccd88ee8a383772e271ea91785eb", "snapshot_id": "3e097cbc9b3c1c2a0c2361109ba149724df36b19", "src_encoding": "UTF-8", "star_events_count": 5, "url": "https://raw.githubusercontent.com/Mkchouk/MiRCA/0eab1443a125ccd88ee8a383772e271ea91785eb/main.c", "visit_date": "2021-01-10T16:26:29.636367" }
stackv2
// Mkchouk Copyright // Default Mode #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <assert.h> #include <stdbool.h> #include <unistd.h> typedef struct { char *qid; char *sid; int posin; int posend; char *qseq; char *sseq; }ligne; bool get_ligne(FILE* f, ligne* pr) { pr->posin = 0; pr->posend = 0; pr->qid = malloc(55 * sizeof(char*)); pr->sid = malloc(55 * sizeof(char*)); pr->qseq = malloc(60000 * sizeof(char*)); pr->sseq = malloc(60000 * sizeof(char*)); /* int n = fscanf(f, "%s,contig%d,%d,%d,%[^\n]\n", &pr->seq_id, &pr->ch_id, &pr->pos_id, &pr->end_id, pr->data);*/ char *chaine = NULL; // Chaîne vide de taille TAILLE_MAX chaine = malloc(sizeof(char*) * 200005); int TAILLE_MAX=200005;int n=0; fgets(chaine,TAILLE_MAX,f); // printf("chaine= %s\n",chaine); n = sscanf(chaine,"%[^,],%[^,],%d,%d,%[^,],%[^\n]",pr->qid,pr->sid,&pr->posin,&pr->posend,pr->qseq,pr->sseq); return n == 6 ? true : false; } void print_ligne(ligne r, int cpt) {if(r.posend<r.posin){ printf("\nligne[%d]= %s ",cpt,r.qid); printf("posIN= %d ",r.posin); printf("posEND= %d",r.posend); printf("ERROR!");} else{ printf("\nligne[%d]= %s \t",cpt,r.qid); printf("posIN= %d ",r.posin); printf("posEND= %d",r.posend); printf(" lenght qseq= %d\t",strlen(r.qseq)); printf(" lenght Sseq= %d",strlen(r.sseq)); // printf("qseq= %s\n",r.qseq); // printf("sseq= %s",r.sseq); } } ligne* table_trier(ligne table[], int n){ int i,permutation = 1;ligne temp; if(n>1){ while (permutation == 1){ permutation = 0; for (i=0; i<n-1; i++){ if (table[i].posin > table[i+1].posin){ /* Il y a eu permutation */ temp = table[i]; table[i]= table[i+1]; table[i+1] = temp; permutation = 1; } /* if */ if((table[i].posin == table[i+1].posin)&&(table[i].posend<table[i+1].posend)){ temp = table[i]; table[i]= table[i+1]; table[i+1] = temp; permutation = 1; } }//FOR } /* while */ }/* IF*/ // for (j = 0; j < n; j++){print_ligne(table[j],j);} return table; } char *sequence_replace(char *s, int start, int lenght, char *ct) { char *new_s = NULL; new_s=malloc(250000*sizeof(char)); if (s != NULL && start >= 0) { int size = strlen (s); // new_s = malloc (sizeof (*new_s) * (size - lenght + strlen (ct) + 1)); if (new_s != NULL) { memcpy (new_s, s, start); res=start+lenght; if (res>=size) { memcpy (&new_s[start], ct, strlen (ct)); } else{ memcpy (&new_s[start], ct, strlen (ct)); memcpy (&new_s[start + strlen (ct)], &s[start + lenght], size - lenght - start + 1); } } } else { fprintf (stderr, "Insufficient memory\n"); printf ("Insufficient memory\n"); exit (EXIT_FAILURE); } return new_s; } ligne* inverse_table(ligne table[], int n) { int i = 0; ligne tmp; for(i=0 ; i < n/2 ; i++) { tmp = table[i]; table[i] = table[n-i-1]; table[n-i-1] = tmp; } return table; } ligne* eliminer_sequence(ligne table[], int n) { int i = 0;int len=0;int j=0;int cpp=0; char tirer='-'; for (i = 0; i < n; i++) {cpp=0; len = table[i].posend-table[i].posin; for (j=0;j<len;j++) { if(table[i].qseq[j]==tirer) {cpp++;} } table[i].qseq[len+cpp]='\0'; table[i].sseq[len+cpp]='\0'; } return table; } ligne* eliminer_chevauchement(ligne table[],int n){ int i; //if(n>1){ for (i = 1; i < n; i++) { if (table[i-1].posend >= table[i].posin) {table[i-1].posend = table[i].posin - 1;} } table=inverse_table(table,n); // } table=eliminer_sequence(table,n); //int t=0; for (t = 0; t < n; t++){print_ligne(table[t],t);} return table; } void table_optimiser(ligne table[], int n,FILE* f1,FILE* f2){ int i=0;int j=0;int k=0; for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(table[i].posin<=table[j].posin && table[i].posend>=table[j].posend) { for (k=j;k<n;k++) { table[k]=table[k+1]; } n--; j=j-1; } } } table= eliminer_chevauchement(table,n); char *chaine1 = NULL; char *chaine2=NULL; char *chaine3=NULL; void rewind(FILE* f1); int t=0;int c=0; chaine1 = malloc(sizeof(char) * 200000);int TAILLE_MAX=200005; chaine2 = malloc(sizeof(char) * 250000); chaine3 = malloc(sizeof(char)* 250000); char *delim=NULL; delim = malloc(sizeof(char) * 250); while(fgets(chaine1,TAILLE_MAX, f1)!= NULL){ int p=0; if(strlen(chaine1)<150 && chaine1[0]=='>') { delim=chaine1; delim[strlen(chaine1) - 1] = '\0'; p=1;} //if(strlen(chaine1)>17 && strlen(chaine1)<300 && chaine1[0]=='>'){delim=strtok(chaine1," ");p=1;} if(p==1){ for(c=0;c<strlen(delim);c++){ delim[c]=delim[c+1]; } delim[strlen(delim)]='\0';} if(strcmp(table[0].qid,delim)==0) { //fprintf(f2,">%s_Corrected\n",delim); fgets(chaine3,TAILLE_MAX, f1); printf("len chaine: %d\n",strlen(chaine3)); int lencouv=0;int percent=0; for (t = 0; t < n; t++){ lencouv=(table[t].posend-table[t].posin)+lencouv; } printf("len table: %d\n",lencouv); percent=(lencouv*100)/strlen(chaine3); printf("Pourcentage: %d \n\n",percent); chaine2=chaine3; for (t = 0; t < n; t++) { chaine2=sequence_replace(chaine2,table[t].posin,table[t].posend-table[t].posin,table[t].sseq); } j=0; for(i=0;i<strlen(chaine2);i++){ if(chaine2[i]!='-'){ chaine2[j]=chaine2[i]; j++; } } chaine2[j]='\0'; if (percent>90){ fprintf(f2,">%s_Corrected\n",delim); fprintf(f2,"%s",chaine2);} break; } }//WHILE fgets() } int main() //main { ligne* Tligne; FILE* fichier = NULL; int i = 0; Tligne=malloc(25000*sizeof(ligne)); char *precedent; precedent = NULL; ligne l; fichier = fopen("alignResults","r"); // alignment results from BLAST+ (the file of Blast Result) FILE* fichier1 = NULL; fichier1 = fopen("LongReads.fasta","r"); //The long reads File(chage this with your long read file) FILE* fichier2 = NULL; fichier2 = fopen("ReadsCorrected.fasta","w"); // Corrected Long Reads int j = 0; if (fichier == NULL) { // On affiche un message d'erreur si on veut printf("File not found"); // perror(msg); } if (fichier1 == NULL) { // On affiche un message d'erreur si on veut printf("File not found"); // perror(msg); } i = 0;int cpp=0;int nbligneResultat8=0; while (get_ligne(fichier, &l)) {nbligneResultat8++; if (precedent != NULL && strcmp(l.qid, precedent)!= 0) { cpp++; Tligne= table_trier(Tligne,i); table_optimiser(Tligne,i,fichier1,fichier2); i = 0; } Tligne[i] = l; precedent = l.qid; i++; } Tligne= table_trier(Tligne,i); table_optimiser(Tligne,i,fichier1,fichier2); printf("CPP derniere= %d\n",cpp+1); printf("nb ligne Resultat8= %d\n",nbligneResultat8); fclose(fichier); fclose(fichier1); fclose(fichier2); return 0; }
2.84375
3
2024-11-18T18:23:02.157279+00:00
2018-09-27T03:10:50
89ab5e1074f2d6f849fe10737d454bcafd3fac55
{ "blob_id": "89ab5e1074f2d6f849fe10737d454bcafd3fac55", "branch_name": "refs/heads/practice", "committer_date": "2018-09-27T03:10:50", "content_id": "9a27fa4de9edf5c50d58d79aaa14022d959cf85b", "detected_licenses": [ "MIT" ], "directory_id": "964760748343973b95f98027a0f20c0e4b7bac27", "extension": "c", "filename": "3-22_Process_Injection-1_injector.c", "fork_events_count": 3, "gha_created_at": "2018-01-07T12:59:29", "gha_event_created_at": "2018-07-17T02:49:32", "gha_language": "C", "gha_license_id": "MIT", "github_id": 116565709, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 16706, "license": "MIT", "license_type": "permissive", "path": "/3-Internals/3-22_Process_Injection-1_injector.c", "provenance": "stackv2-0003.json.gz:387598", "repo_name": "hark130/Latissimus_Dorsi", "revision_date": "2018-09-27T03:10:50", "revision_id": "60c9e1f2a57ed3540f5693e14ac3651c47c081e8", "snapshot_id": "18b00ffe2bc3d44910fe182e901a10862908445b", "src_encoding": "UTF-8", "star_events_count": 2, "url": "https://raw.githubusercontent.com/hark130/Latissimus_Dorsi/60c9e1f2a57ed3540f5693e14ac3651c47c081e8/3-Internals/3-22_Process_Injection-1_injector.c", "visit_date": "2021-07-13T22:22:10.320418" }
stackv2
/* This code will serve as the "glue" that brings together all of the necessary functionality to inject code into a running process. CURRENT PLAN: 1. Attach to the 'victim' process 2. Backup the current state of the processor registers 3. Parse /proc/PID/maps to get some "r-xp" memory 4. Backup the memory section 5. Overwrite executable memory section 6. Update RIP to point to the injected code 7. Resume execution 8. Wait until the injected code finishes running and hits a SIGTRAP 9. Restore the process back to its original state NECESSARY PREPARATION: "ptrace() returned errno: Operation not permitted" This is due to kernel hardening in Linux disable this behavior by: `echo 0 > /proc/sys/kernel/yama/ptrace_scope` modifying /etc/sysctl.d/10-ptrace.conf */ #include <errno.h> // errno #include "Fileroad.h" // os_path_join(), fread_a_file() #include "Harklerror.h" // HARKLE_ERROR #include "Harkleproc.h" // is_it_a_PID(), make_PID_into_proc() #include "Harkletrace.h" // htrace_write_data() #include "Map_Memory.h" // mapMem_ptr #include "Memoroad.h" // release_a_string() #include <sys/mman.h> // mmap() #include "pmparser.h" // pmStruct_ptr #include <signal.h> // signals #include <stdbool.h> // bool, true, false #include <stdio.h> // fprintf() #include <string.h> // strcmp() #include <sys/ptrace.h> // ptrace() #include <sys/syscall.h> // syscall #include <sys/user.h> // struct user_regs_struct #include <sys/wait.h> // waitpid() int main(int argc, char* argv[]) { // LOCAL VARIABLES bool success = true; // Make this false if anything fails long ptRetVal = 0; // ptrace() return value int errNum = 0; // Store errno here pidDetails_ptr* procPIDStructs = parse_proc_PID_structs(); pidDetails_ptr* temp_arr = procPIDStructs; pidDetails_ptr vicPID = NULL; // Store the struct pointer for argv[1] here char* userProcPID = NULL; // Will hold char* holding /proc/<PID>/ built from user's choice struct user_regs_struct oldRegs; // Store the state of the registers here struct user_regs_struct newRegs; // Modify the registers here pmStruct_ptr procMaps_ptr = NULL; // /proc/PID/maps for argv[1] pmStruct_ptr tmpPM_ptr = NULL; // Temporary variable to print out certain mappings struct iovec* localBackup = NULL; // Local backup of the PIDs executable memory map char* payloadFilename = NULL; // Store the payload absolute or relative filename here char* payloadContents = NULL; // Store the contents of the payload here off_t payloadSize = 0; // Store the length of the payload here int tempRetVal = 0; // Store int return values here char code[] = { 0xEB, 0x11, 0x48, 0x31, 0xC0, 0xB0, 0x01, 0x48, 0x89, 0xC7, 0x5E, 0x48, 0x31, 0xD2, 0xB2, 0x29, \ 0x0F, 0x05, 0xCC, 0xE8, 0xEA, 0xFF, 0xFF, 0xFF, 0x54, 0x68, 0x61, 0x74, 0x20, 0x77, 0x65, 0x61, \ 0x76, 0x65, 0x20, 0x67, 0x6F, 0x74, 0x74, 0x61, 0x20, 0x67, 0x6F, 0x2E, 0x20, 0x50, 0x69, 0x6E, \ 0x6B, 0x20, 0x73, 0x6C, 0x69, 0x70, 0x2E, 0x20, 0x2D, 0x43, 0x61, 0x72, 0x64, 0x69, 0x20, 0x42, \ 0x0A, 0x00 }; char spinCode[5] = { 0x90, 0x90, 0x90, 0xEB, 0xFE }; void* codeStart = NULL; // Pointer to the beginning of the executable shell code size_t codeStartOffset = 0; // Store the payload's offset of the nopnopnop here char nopCanary[3] = { 0x90, 0x90, 0x90 }; // Look for this nop slide in the shellcode mapMem_ptr mappedPayload = NULL; struct sigaction sigact; // Used to specify actions for specific signals int sigNum = 1; // Signal numbers to iterate through bool modifiedPerms = false; // Set this to true if memory segment permissions were changed // INPUT VALIDATION // procPIDStructs if (!procPIDStructs) { HARKLE_ERROR(injector, main, parse_proc_PID_structs failed); success = false; } // Arguments if (argc < 2) { fprintf(stderr, "\nToo few arguments!\nusage: injector.exe <PID>\n\n"); success = false; } else if (argc > 2) { fprintf(stderr, "\nToo many arguments!\nusage: injector.exe <PID>\n\n"); success = false; } else if (false == is_it_a_PID(argv[1])) { fprintf(stderr, "\nInvalid PID!\nusage: injector.exe <PID>\nexample: injector.exe 1234\n\n"); success = false; } else { // Create absolute path of PID userProcPID = make_PID_into_proc(argv[1]); if (!userProcPID) { HARKLE_ERROR(injector, main, make_PID_into_proc failed); success = false; } else { success = false; // Set to true when PID match is found while (*temp_arr && success == false) { if (0 == strcmp((*temp_arr)->pidName, userProcPID) && (*temp_arr)->stillExists == true) { success = true; vicPID = *temp_arr; fprintf(stdout, "\nParsing %s (%s)\n", (*temp_arr)->pidName, (*temp_arr)->pidCmdline); } else { temp_arr++; } } if (success == false) { fprintf(stderr, "\nUnable to locate %s.\n\n", userProcPID); } else { fprintf(stdout, "[*] Located /proc/PID/\n"); // DEBUGGING } } } // SIGNAL HANDLER == IGNORE if (success == true) { sigemptyset(&sigact.sa_mask); // Zeroize the mask of signals which should be blocked sigact.sa_flags = 0; // Can't think of any good flags to add for what I'm doing sigact.sa_handler = SIG_IGN; // Apparently, instead of handling the SIGNALS, we'll just ignore them // Set the action // rt_sigaction() doesn't work as (barely) documented // Reading sigaction() source code leads me to believe that rt_sigaction wants // SIGRTMAX / 8 as the fourth argument (NOT sizeof(sigset_t) like the man page says). // It works. For more details, read: // https://github.com/hark130/Latissimus_Dorsi/blob/practice/Research_Documents/3-4-1-rt_sigaction.txt if (-1 == syscall(SYS_rt_sigaction, SIGINT, &sigact, NULL, SIGRTMAX / 8)) { errNum = errno; HARKLE_ERROR(nosig, main, syscall failed); HARKLE_ERRNO(nosig, SYS_rt_sigaction, errNum); success = false; } } // INJECTOR // 1. Attach to the 'victim' process if (true == success) { ptRetVal = ptrace(PTRACE_ATTACH, vicPID->pidNum, NULL, NULL); if (-1 == ptRetVal) { errNum = errno; HARKLE_ERROR(injector, main, PTRACE_ATTACH failed); HARKLE_ERRNO(injector, ptrace, errNum); success = false; } else { // Wait for PID to stop if (-1 == waitpid(vicPID->pidNum, &errNum, WUNTRACED)) { errNum = errno; HARKLE_ERROR(injector, main, waitpid failed); HARKLE_ERRNO(injector, waitpid, errNum); success = false; } else { fprintf(stdout, "[*] Attched to PID\n"); // DEBUGGING } } } // 2. Backup the current state of the processor registers if (true == success) { ptRetVal = ptrace(PTRACE_GETREGS, vicPID->pidNum, NULL, &oldRegs); if (-1 == ptRetVal) { errNum = errno; HARKLE_ERROR(injector, main, PTRACE_GETREGS failed); HARKLE_ERRNO(injector, ptrace, errNum); success = false; } else { fprintf(stdout, "[*] Backed up PID's processor registers\n"); // DEBUGGING newRegs = oldRegs; // Starting point for new register values } } // 3. Parse /proc/PID/maps to get some "r-xp" memory if (true == success) { // 3.1. /proc/PID/maps procMaps_ptr = pmparser_parse(vicPID->pidNum); if (!procMaps_ptr) { HARKLE_ERROR(injector, main, pmparser_parse failed); success = false; } else { tmpPM_ptr = procMaps_ptr; tempRetVal = 0; // TEST OTHER MEMORY SECTIONS while (tmpPM_ptr) { if (1 == tmpPM_ptr->is_x) { if (!tempRetVal) { fprintf(stdout, "[*] Found r-xp PID memory\n"); // DEBUGGING break; // Found one } else { tempRetVal--; } } tmpPM_ptr = tmpPM_ptr->next; } } } // 4. Backup the memory section if (true == success) { localBackup = copy_remote_to_local(vicPID->pidNum, \ tmpPM_ptr->addr_start, \ (size_t)tmpPM_ptr->length); if (!localBackup) { HARKLE_ERROR(injector, main, copy_remote_to_local failed); success = false; } else { fprintf(stdout, "[*] Successfully backed up PID memory\n"); // DEBUGGING } } // 5. Read in the payload if (true == success) { // 5.1 Determine payload location payloadFilename = os_path_join("./3-22-1_Payloads", "payload_64_write_1.o", true); if (!payloadFilename) { HARKLE_ERROR(injector, main, os_path_join failed); success = false; } else { // 5.2. Size the payload // ↓↓↓ COMMENTED OUT BECAUSE OF A BUG IN os_path_join() ↓↓↓ // payloadSize = size_a_file(payloadFilename, &tempRetVal); payloadSize = size_a_file("./3-22-1_Payloads/payload_64_write_1.o", &tempRetVal); if (-1 == payloadSize) { HARKLE_ERROR(injector, main, size_a_file failed); fprintf(stderr, "size_a_file() returned errno:\t%s\n", strerror(tempRetVal)); success = false; } else { // 5.3. Read the payload in // ↓↓↓ COMMENTED OUT BECAUSE OF A BUG IN os_path_join() ↓↓↓ // payloadContents = fread_a_file(payloadFilename); payloadContents = fread_a_file("./3-22-1_Payloads/payload_64_write_1.o"); if (!payloadContents) { HARKLE_ERROR(injector, main, fread_a_file failed); success = false; } } } } // 6. Modify memory section permissions if (true == success) { // 6.1. Change the permissions on the memory // Current working theory... some Linux OSs won't permit mapped memory space // to be rwxp. If this is true, I'll have to flip permissions on the PID's // memory space depending on what I want to do in that moment. // tempRetVal = change_mmap_prot(tmpPM_ptr->addr_start, tmpPM_ptr->length, \ // MROAD_PROT_READ | MROAD_PROT_WRITE | MROAD_PROT_EXEC); // It's possible that some Linux implementations won't allow mapped memory space // to contain both write *AND* execute permissions at the same time. tempRetVal = 0; // tempRetVal = change_mmap_prot(tmpPM_ptr->addr_start, tmpPM_ptr->length, \ // MROAD_PROT_READ | MROAD_PROT_WRITE); // modifiedPerms = true; // This will allow the "restore permissions" code block to execute } // 7. Overwrite memory section if (true == success) { tempRetVal = htrace_write_data(vicPID->pidNum, tmpPM_ptr->addr_start, payloadContents, payloadSize); if (tempRetVal) { HARKLE_ERRNO(injector, htrace_write_data, tempRetVal); success = false; } else { fprintf(stdout, "[*] Overwrote PID memory space\n"); // DEBUGGING } } // 8. Restore memory section permissions if (true == success && true == modifiedPerms) { // Change the permissions on the memory back to r-xp tempRetVal = change_mmap_prot(tmpPM_ptr->addr_start, tmpPM_ptr->length, \ MROAD_PROT_READ | MROAD_PROT_EXEC); if (tempRetVal) { HARKLE_ERROR(injector, main, change_mmap_prot failed); HARKLE_ERRNO(injector, change_mmap_prot, tempRetVal); success = false; } else { fprintf(stdout, "[*] Restored mapped memory permissions (r-xp)\n"); // DEBUGGING } } // 9. Update RIP to point to the injected code if (true == success) { // 9.1. Find nopnopnop slide in the opcode codeStart = NULL; // For safety codeStartOffset = pid_mem_hunt(vicPID->pidNum, (void*)tmpPM_ptr->addr_start, (void*)nopCanary, tmpPM_ptr->length, sizeof(nopCanary) / sizeof(*nopCanary)); if (-1 == codeStartOffset) { HARKLE_ERROR(injector, main, pid_mem_hunt failed to find the nop slide); success = false; } else if (-2 == codeStartOffset) { HARKLE_ERROR(injector, main, pid_mem_hunt failed); success = false; } else if (codeStartOffset < 0) { HARKLE_ERROR(injector, main, pid_mem_hunt claimed success but returned a negative offset); success = false; } else { codeStart = tmpPM_ptr->addr_start + codeStartOffset; } if (!codeStart) { HARKLE_ERROR(injector, main, Failed to find the beginning of the shellcode); success = false; } else { // 9.2. Modify existing registers to reflect the new RIP newRegs.rip = (unsigned long long)codeStart + 2; // Is RIP being decremented upon resume?! // newRegs.rip = (unsigned long long)codeStart; // 9.3. Update the victim PID's process registers ptRetVal = ptrace(PTRACE_SETREGS, vicPID->pidNum, NULL, &newRegs); if (-1 == ptRetVal) { errNum = errno; HARKLE_ERROR(injector, main, PTRACE_SETREGS failed); HARKLE_ERRNO(injector, ptrace, errNum); success = false; } else { fprintf(stdout, "[*] Successfully updated RIP\n"); // DEBUGGING } } } // 10. Resume execution if (true == success) { ptRetVal = ptrace(PTRACE_CONT, vicPID->pidNum, NULL, NULL); if (-1 == ptRetVal) { errNum = errno; HARKLE_ERROR(injector, main, PTRACE_SETREGS failed); HARKLE_ERRNO(injector, ptrace, errNum); success = false; } else { fprintf(stdout, "[*] PID's execution resumed\n"); // DEBUGGING } } // 11. Wait until the injected code finishes running and hits a SIGTRAP if (true == success) { if (-1 == waitpid(vicPID->pidNum, &errNum, WUNTRACED)) { errNum = errno; HARKLE_ERROR(injector, main, waitpid failed); HARKLE_ERRNO(injector, waitpid, errNum); success = false; } else { fprintf(stdout, "[*] PID terminated\n"); // DEBUGGING if (WIFSTOPPED(errNum) && WSTOPSIG(errNum) == SIGTRAP) { fprintf(stdout, "[*] PID reached the SIGTRAP\n"); // DEBUGGING } else { HARKLE_ERROR(injector, main, SIGTRAP not found); } } } // 12. Restore the process back to its original state if (true == success) { // 12.1. Restore the registers ptRetVal = ptrace(PTRACE_SETREGS, vicPID->pidNum, NULL, &oldRegs); if (-1 == ptRetVal) { errNum = errno; HARKLE_ERROR(injector, main, PTRACE_SETREGS failed); HARKLE_ERRNO(injector, ptrace, errNum); success = false; } else { fprintf(stdout, "[*] Successfully restored registers\n"); // DEBUGGING } // 12.2. Change memory to write permissions if (true == success && true == modifiedPerms) { tempRetVal = change_mmap_prot(tmpPM_ptr->addr_start, tmpPM_ptr->length, \ MROAD_PROT_READ | MROAD_PROT_WRITE); if (tempRetVal) { HARKLE_ERROR(injector, main, change_mmap_prot failed); HARKLE_ERRNO(injector, change_mmap_prot, tempRetVal); success = false; } else { fprintf(stdout, "[*] REmodified mapped memory permissions (rw-p)\n"); // DEBUGGING } } // 12.3. Restore the mapped memory if (true == success) { htrace_write_data(vicPID->pidNum, (void*)tmpPM_ptr->addr_start, (void*)localBackup->iov_base, (int)localBackup->iov_len); } // 12.4. Change the permissions on the memory back to r-xp if (true == success && true == modifiedPerms) { tempRetVal = change_mmap_prot(tmpPM_ptr->addr_start, tmpPM_ptr->length, \ MROAD_PROT_READ | MROAD_PROT_EXEC); if (tempRetVal) { HARKLE_ERROR(injector, main, change_mmap_prot failed); HARKLE_ERRNO(injector, change_mmap_prot, tempRetVal); success = false; } else { fprintf(stdout, "[*] Restored mapped memory permissions post-restoral (r-xp)\n"); // DEBUGGING } } // 12.4. Detach from the process to resume execution ptRetVal = ptrace(PTRACE_DETACH, vicPID->pidNum, NULL, NULL); if (-1 == ptRetVal) { errNum = errno; HARKLE_ERROR(injector, main, PTRACE_DETACH failed); HARKLE_ERRNO(injector, ptrace, errNum); success = false; } else { fprintf(stdout, "[*] PID detached\n"); // DEBUGGING } } // CLEAN UP // 1. procPIDStructs if (procPIDStructs) { if (false == free_PID_struct_arr(&procPIDStructs)) { HARKLE_ERROR(injector, main, free_PID_struct_arr failed); } } temp_arr = NULL; // 2. userProcPID if (userProcPID) { if (false == release_a_string(&userProcPID)) { HARKLE_ERROR(injector, main, release_a_string failed); } } // 3. if (procMaps_ptr) { pmparser_free(procMaps_ptr); procMaps_ptr = NULL; } // 4. localBackup if (localBackup) { if (false == free_iovec_struct(&localBackup, true)) { HARKLE_ERROR(injector, main, free_iovec_struct failed); } } // 5. payloadFilename if (payloadFilename) { if (false == release_a_string(&payloadFilename)) { HARKLE_ERROR(injector, main, release_a_string failed); } } // 6. payloadContents if (payloadContents) { if (false == release_a_string(&payloadContents)) { HARKLE_ERROR(injector, main, release_a_string failed); } } // 7. mappedPayload if (mappedPayload) { free_struct(&mappedPayload); } // DONE return 0; }
2.359375
2
2024-11-18T18:23:02.257023+00:00
2019-11-19T02:07:42
b10297622c1b31f350d87cd0d0c48efe51c789d2
{ "blob_id": "b10297622c1b31f350d87cd0d0c48efe51c789d2", "branch_name": "refs/heads/master", "committer_date": "2019-11-19T02:07:42", "content_id": "63fcaeb28487677631765b2bc032a295b07fe0b8", "detected_licenses": [ "Unlicense" ], "directory_id": "0034b7b98cf59600d0294ac6b6e834015588b6b0", "extension": "c", "filename": "pthread.c", "fork_events_count": 1, "gha_created_at": "2019-08-21T01:50:02", "gha_event_created_at": "2019-10-13T13:52:12", "gha_language": "C", "gha_license_id": "Unlicense", "github_id": 203484986, "is_generated": false, "is_vendor": false, "language": "C", "length_bytes": 2934, "license": "Unlicense", "license_type": "permissive", "path": "/pthread.c", "provenance": "stackv2-0003.json.gz:387727", "repo_name": "MarcioMed07/Parallel-Game-of-Life", "revision_date": "2019-11-19T02:07:42", "revision_id": "5738b1937286dd55372eeaea9e838e1cda6a7dfb", "snapshot_id": "36824c5d73b13e7a60f2ab685a03e3d324a38db3", "src_encoding": "UTF-8", "star_events_count": 0, "url": "https://raw.githubusercontent.com/MarcioMed07/Parallel-Game-of-Life/5738b1937286dd55372eeaea9e838e1cda6a7dfb/pthread.c", "visit_date": "2020-07-07T21:45:35.827530" }
stackv2
/****************************** * Created by: Márcio Medeiros * * in: 20/08/2019 * ******************************/ #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <time.h> // variaveis globais int iterations, itt; int height, width; int *life, *lifeN, *aux; int rows_thread, rows_last_thread; // divisao de linhas por thread int num_threads; pthread_barrier_t barrier; // prototype int* createBoard(int height, int width); void freeBoard(int *board); int* createInitBoard(char *file_name, int *height, int *width); void showBoard(int *board, int height, int width); void core(int *life, int *lifeN, int row_start, int row_end, int height, int width); void run(int row_start, int row_end, int id); void* gameOfLife(void* arg); void run(int row_start, int row_end, int id) { while (itt < iterations) { core(life, lifeN, row_start, row_end, height, width); // wait for all threads pthread_barrier_wait(&barrier); // copy boards if (id == 0) { aux = lifeN; lifeN = life; life = aux; itt++; } // wait for all threads pthread_barrier_wait(&barrier); } pthread_exit(NULL); } void* gameOfLife(void* arg) { int id = *(int*) arg; // thread id int row_start = id * rows_thread; int row_end = row_start + rows_thread; if (id == num_threads - 1) row_end += rows_last_thread; run(row_start, row_end, id); return NULL; } //Executes the Game of Life Algorithim showing the initial and final boards // arg 1 = number of iterations // arg 2 = file input board // arg 3 = number of threads int main(int argc, char **argv) { if (argc < 4) exit(0); clock_t ti, tf; iterations = atoi(argv[1]); itt = 0; char *file_name = argv[2]; num_threads = atoi(argv[3]); pthread_t threads[num_threads]; int *id; int flag, i; life = createInitBoard(file_name, &height, &width); lifeN = createBoard(height, width); // divisão das linhas por thread rows_thread = height / num_threads; rows_last_thread = height % num_threads; //linhas para ultima thread pthread_barrier_init(&barrier, NULL, num_threads); ti = clock(); for (i = 0; i < num_threads; i++) { id = malloc(sizeof(int)); *id = i; flag = pthread_create(&threads[i], NULL, gameOfLife, id); if (flag!=0) printf("Erro na criacao da thread\n"); } for(i = 0; i < num_threads; i++) pthread_join(threads[i], NULL); /*uniao das threads */ tf = clock(); // showBoard(life, height, width); // printf("Pthread\n%d threads\n%dx%d board\n%d iteracoes\n", num_threads, height, width, iterations); printf("%lf\n", ((double)tf-ti) / CLOCKS_PER_SEC); pthread_barrier_destroy(&barrier); freeBoard(life); freeBoard(lifeN); return 0; }
3.296875
3