id
int64 15.5k
16.3M
| file_name
stringlengths 3
43
| file_path
stringlengths 22
137
| content
stringlengths 21
332k
| size
int64 21
332k
| language
stringclasses 1
value | extension
stringclasses 2
values | total_lines
int64 4
7.88k
| avg_line_length
float64 1.1
84.2
| max_line_length
int64 2
3.13k
| alphanum_fraction
float64 0.16
1
| repo_name
stringlengths 9
45
| repo_stars
int64 2
10.4k
| repo_forks
int64 0
1.2k
| repo_open_issues
int64 0
220
| repo_license
stringclasses 6
values | repo_extraction_date
stringlengths 39
40
| exact_duplicates_stackv2
bool 2
classes | exact_duplicates_stackv1
bool 2
classes | exact_duplicates_redpajama
bool 2
classes | exact_duplicates_githubcode
bool 1
class | near_duplicates_stackv2
bool 2
classes | near_duplicates_stackv1
bool 2
classes | near_duplicates_redpajama
bool 2
classes | near_duplicates_githubcode
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
15,458 | out.input008.c | DoctorWkt_acwj/44_Fold_Optimisation/tests/out.input008.c | 1
2
3
4
5
6
7
8
9
10
| 21 | C | .c | 10 | 1.1 | 2 | 1 | DoctorWkt/acwj | 10,392 | 1,007 | 26 | GPL-3.0 | 9/7/2024, 9:40:14 AM (Europe/Amsterdam) | true | false | false | true | true | false | false | false |
39,850 | input.h | universal-ctags_ctags/Units/parser-cxx.r/bug639644.cpp.d/input.h | /*
Date: Sun, 17 Nov 2002 04:57:43 -0800
Subject: [ ctags-Bugs-639644 ] anonymous namespaces in headers
Bugs item #639644, was opened at 2002-11-17 13:57
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=106556&aid=639644&group_id=6556
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Matthias S. Benkmann (mbenkmann)
Assigned to: Nobody/Anonymous (nobody)
Summary: anonymous namespaces in headers
Initial Comment:
--------------------temp3.h----------------
*/
namespace
{
int foo;
}
/*
---------------------------------------------
> ctags -f - temp3.h
foo temp3.h /^ int foo;$/;" m namespace:
That last field should be "namespace:<anonymous>"
and the kind field should be variable, not member.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=106556&aid=639644&group_id=6556
*/
| 977 | C | .h | 31 | 30.064516 | 81 | 0.639957 | universal-ctags/ctags | 6,474 | 620 | 220 | GPL-2.0 | 9/7/2024, 9:40:14 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
116,469 | daemonise.c | WiringPi_WiringPi/wiringPiD/daemonise.c | /*
* daemonise.c:
* Fairly generic "Turn the current process into a daemon" code.
*
* Copyright (c) 2016-2017 Gordon Henderson.
*********************************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
#include <signal.h>
#include <sys/stat.h>
#include "daemonise.h"
void daemonise (const char *pidFile)
{
pid_t pid ;
int i ;
FILE *fd ;
syslog (LOG_DAEMON | LOG_INFO, "Becoming daemon") ;
// Fork from the parent
if ((pid = fork ()) < 0)
{
syslog (LOG_DAEMON | LOG_ALERT, "Fork no. 1 failed: %m") ;
exit (EXIT_FAILURE) ;
}
if (pid > 0) // Parent - terminate
exit (EXIT_SUCCESS) ;
// Now running on the child - become session leader
if (setsid() < 0)
{
syslog (LOG_DAEMON | LOG_ALERT, "setsid failed: %m") ;
exit (EXIT_FAILURE) ;
}
// Ignore a few signals
signal (SIGCHLD, SIG_IGN) ;
signal (SIGHUP, SIG_IGN) ;
// Fork again
if ((pid = fork ()) < 0)
{
syslog (LOG_DAEMON | LOG_ALERT, "Fork no. 2 failed: %m") ;
exit (EXIT_FAILURE) ;
}
if (pid > 0) // parent - terminate
exit (EXIT_SUCCESS) ;
// Tidying up - reset umask, change to / and close all files
umask (0) ;
chdir ("/") ;
for (i = 0 ; i < sysconf (_SC_OPEN_MAX) ; ++i)
close (i) ;
// Write PID into /var/run
if (pidFile != NULL)
{
if ((fd = fopen (pidFile, "w")) == NULL)
{
syslog (LOG_DAEMON | LOG_ALERT, "Unable to write PID file: %m") ;
exit (EXIT_FAILURE) ;
}
fprintf (fd, "%d\n", getpid ()) ;
fclose (fd) ;
}
}
| 1,607 | C | .c | 62 | 22.66129 | 82 | 0.569836 | WiringPi/WiringPi | 2,627 | 1,197 | 20 | LGPL-3.0 | 9/7/2024, 9:40:14 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
261,207 | helpers.c | HVML_PurC/Source/Executables/purc/util/helpers.c | /*
* helpers.c - Implementation of useful helpers.
*
* Copyright (C) 2023 FMSoft <https://www.fmsoft.cn>
*
* Author: Vincent Wei <https://github.com/VincentWei>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "helpers.h"
| 925 | C | .c | 20 | 44.25 | 75 | 0.770764 | HVML/PurC | 1,057 | 54 | 13 | LGPL-3.0 | 9/7/2024, 9:40:15 AM (Europe/Amsterdam) | true | false | false | true | true | false | false | false |
297,749 | g_sphere.c | kondrak_vkQuake2/rogue/g_sphere.c | // g_sphere.c
// pmack
// april 1998
// defender - actively finds and shoots at enemies
// hunter - waits until < 25% health and vore ball tracks person who hurt you
// vengeance - kills person who killed you.
#include "g_local.h"
#define DEFENDER_LIFESPAN 30
#define HUNTER_LIFESPAN 30
#define VENGEANCE_LIFESPAN 30
#define MINIMUM_FLY_TIME 15
//#define MINIMUM_FLY_TIME 30
// FIXME - do we need to be calling ED_NewString at all?
extern char *ED_NewString (char *string);
void LookAtKiller (edict_t *self, edict_t *inflictor, edict_t *attacker);
void defender_think (edict_t *self);
void hunter_think (edict_t *self);
void vengeance_think (edict_t *self);
void vengeance_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf);
void hunter_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf);
// *************************
// General Sphere Code
// *************************
// =================
// =================
void sphere_think_explode (edict_t *self)
{
if(self->owner && self->owner->client && !(self->spawnflags & SPHERE_DOPPLEGANGER))
{
self->owner->client->owned_sphere = NULL;
}
BecomeExplosion1 (self);
}
// =================
// sphere_explode
// =================
void sphere_explode (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
// if(self->owner && self->owner->client)
// gi.cprintf(self->owner, PRINT_HIGH, "Sphere timed out\n");
// gi.dprintf("player died, blowing up\n");
sphere_think_explode (self);
}
// =================
// sphere_if_idle_die - if the sphere is not currently attacking, blow up.
// =================
void sphere_if_idle_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
if(!self->enemy)
{
// gi.dprintf("player died, blowing up\n");
sphere_think_explode(self);
}
}
// *************************
// Sphere Movement
// *************************
// =================
// =================
void sphere_fly (edict_t *self)
{
vec3_t dest;
vec3_t dir;
if(level.time >= self->wait)
{
// gi.dprintf("fly: timed out\n");
sphere_think_explode(self);
return;
}
VectorCopy (self->owner->s.origin, dest);
dest[2] = self->owner->absmax[2] + 4;
if(level.time == (float)(int)level.time)
{
if(!visible(self, self->owner))
{
VectorCopy(dest, self->s.origin);
gi.linkentity(self);
return;
}
}
VectorSubtract (dest, self->s.origin, dir);
VectorScale (dir, 5, self->velocity);
}
// =================
// =================
void sphere_chase (edict_t *self, int stupidChase)
{
vec3_t dest;
vec3_t dir;
float dist;
if(level.time >= self->wait || (self->enemy && self->enemy->health < 1))
{
sphere_think_explode(self);
return;
}
VectorCopy (self->enemy->s.origin, dest);
if(self->enemy->client)
dest[2] += self->enemy->viewheight;
if(visible(self, self->enemy) || stupidChase)
{
// if moving, hunter sphere uses active sound
if(!stupidChase)
self->s.sound = gi.soundindex ("spheres/h_active.wav");
VectorSubtract (dest, self->s.origin, dir);
VectorNormalize (dir);
vectoangles2(dir, self->s.angles);
VectorScale (dir, 500, self->velocity);
VectorCopy(dest, self->monsterinfo.saved_goal);
}
else if (VectorCompare (self->monsterinfo.saved_goal, vec3_origin))
{
VectorSubtract(self->enemy->s.origin, self->s.origin, dir);
dist = VectorNormalize(dir);
vectoangles2(dir, self->s.angles);
// if lurking, hunter sphere uses lurking sound
self->s.sound = gi.soundindex ("spheres/h_lurk.wav");
VectorClear (self->velocity);
}
else
{
VectorSubtract(self->monsterinfo.saved_goal, self->s.origin, dir);
dist = VectorNormalize(dir);
if(dist > 1)
{
vectoangles2(dir, self->s.angles);
if(dist > 500)
VectorScale(dir, 500, self->velocity);
else if (dist < 20)
VectorScale(dir, (dist / FRAMETIME), self->velocity);
else
VectorScale(dir, dist, self->velocity);
// if moving, hunter sphere uses active sound
if(!stupidChase)
self->s.sound = gi.soundindex ("spheres/h_active.wav");
}
else
{
VectorSubtract(self->enemy->s.origin, self->s.origin, dir);
dist = VectorNormalize(dir);
vectoangles2(dir, self->s.angles);
// if not moving, hunter sphere uses lurk sound
if(!stupidChase)
self->s.sound = gi.soundindex ("spheres/h_lurk.wav");
VectorClear(self->velocity);
}
}
}
// *************************
// Attack related stuff
// *************************
// =================
// =================
void sphere_fire (edict_t *self, edict_t *enemy)
{
vec3_t dest;
vec3_t dir;
if(level.time >= self->wait || !enemy)
{
sphere_think_explode(self);
return;
}
VectorCopy (enemy->s.origin, dest);
self->s.effects |= EF_ROCKET;
VectorSubtract (dest, self->s.origin, dir);
VectorNormalize (dir);
vectoangles2 ( dir, self->s.angles );
VectorScale (dir, 1000, self->velocity);
self->touch = vengeance_touch;
self->think = sphere_think_explode;
self->nextthink = self->wait;
}
// =================
// =================
void sphere_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf, int mod)
{
if(self->spawnflags & SPHERE_DOPPLEGANGER)
{
if (other == self->teammaster)
return;
self->takedamage = DAMAGE_NO;
self->owner = self->teammaster;
self->teammaster = NULL;
}
else
{
if (other == self->owner)
return;
// PMM - don't blow up on bodies
if (!strcmp(other->classname, "bodyque"))
return;
}
if (surf && (surf->flags & SURF_SKY))
{
G_FreeEdict (self);
return;
}
if (other->takedamage)
{
T_Damage (other, self, self->owner, self->velocity, self->s.origin, plane->normal,
10000, 1, DAMAGE_DESTROY_ARMOR, mod);
}
else
{
T_RadiusDamage (self, self->owner, 512, self->owner, 256, mod);
}
sphere_think_explode (self);
}
// =================
// =================
void vengeance_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if(self->spawnflags & SPHERE_DOPPLEGANGER)
sphere_touch (self, other, plane, surf, MOD_DOPPLE_VENGEANCE);
else
sphere_touch (self, other, plane, surf, MOD_VENGEANCE_SPHERE);
}
// =================
// =================
void hunter_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
edict_t *owner;
// don't blow up if you hit the world.... sheesh.
if(other==world)
return;
if(self->owner)
{
// if owner is flying with us, make sure they stop too.
owner=self->owner;
if(owner->flags & FL_SAM_RAIMI)
{
VectorClear(owner->velocity);
owner->movetype = MOVETYPE_NONE;
gi.linkentity(owner);
}
}
if(self->spawnflags & SPHERE_DOPPLEGANGER)
sphere_touch (self, other, plane, surf, MOD_DOPPLE_HUNTER);
else
sphere_touch (self, other, plane, surf, MOD_HUNTER_SPHERE);
}
// =================
// =================
void defender_shoot (edict_t *self, edict_t *enemy)
{
vec3_t dir;
vec3_t start;
if(!(enemy->inuse) || enemy->health <= 0)
return;
if(enemy == self->owner)
return;
VectorSubtract (enemy->s.origin, self->s.origin, dir);
VectorNormalize (dir);
if(self->monsterinfo.attack_finished > level.time)
return;
if(!visible(self, self->enemy))
return;
VectorCopy(self->s.origin, start);
start[2] += 2;
fire_blaster2 (self->owner, start, dir, 10, 1000, EF_BLASTER, 0);
self->monsterinfo.attack_finished = level.time + 0.4;
}
// *************************
// Activation Related Stuff
// *************************
// =================
// =================
void body_gib (edict_t *self)
{
int n;
gi.sound (self, CHAN_BODY, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
for (n= 0; n < 4; n++)
ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", 50, GIB_ORGANIC);
ThrowGib (self, "models/objects/gibs/skull/tris.md2", 50, GIB_ORGANIC);
}
// =================
// =================
void hunter_pain (edict_t *self, edict_t *other, float kick, int damage)
{
edict_t *owner;
float dist;
vec3_t dir;
if(self->enemy)
return;
owner = self->owner;
if(!(self->spawnflags & SPHERE_DOPPLEGANGER))
{
if(owner && (owner->health > 0))
return;
//PMM
if(other == owner)
{
// if ((g_showlogic) && (g_showlogic->value))
// gi.dprintf ("hunter: won't get mad at my owner!\n");
return;
}
//pmm
}
else
{
// if fired by a doppleganger, set it to 10 second timeout
self->wait = level.time + MINIMUM_FLY_TIME;
}
if((self->wait - level.time) < MINIMUM_FLY_TIME)
self->wait = level.time + MINIMUM_FLY_TIME;
self->s.effects |= EF_BLASTER | EF_TRACKER;
self->touch = hunter_touch;
self->enemy = other;
// if(g_showlogic && g_showlogic->value)
// gi.dprintf("hunter_pain: mad at %s\n", other->classname);
// if we're not owned by a player, no sam raimi
// if we're spawned by a doppleganger, no sam raimi
if((self->spawnflags & SPHERE_DOPPLEGANGER) || !(owner && owner->client))
return;
// sam raimi cam is disabled if FORCE_RESPAWN is set.
// sam raimi cam is also disabled if huntercam->value is 0.
if(!((int)dmflags->value & DF_FORCE_RESPAWN) && (huntercam && (huntercam->value)))
{
VectorSubtract(other->s.origin, self->s.origin, dir);
dist=VectorLength(dir);
if(owner && (dist >= 192))
{
// detach owner from body and send him flying
owner->movetype = MOVETYPE_FLYMISSILE;
// gib like we just died, even though we didn't, really.
body_gib(owner);
// move the sphere to the owner's current viewpoint.
// we know it's a valid spot (or will be momentarily)
VectorCopy(owner->s.origin, self->s.origin);
self->s.origin[2] += owner->viewheight;
// move the player's origin to the sphere's new origin
VectorCopy(self->s.origin, owner->s.origin);
VectorCopy(self->s.angles, owner->s.angles);
VectorCopy(self->s.angles, owner->client->v_angle);
VectorClear(owner->mins);
VectorClear(owner->maxs);
VectorSet(owner->mins, -5, -5, -5);
VectorSet(owner->maxs, 5, 5, 5);
owner->client->ps.fov = 140;
owner->s.modelindex = 0;
owner->s.modelindex2 = 0;
owner->viewheight = 8;
owner->solid = SOLID_NOT;
owner->flags |= FL_SAM_RAIMI;
gi.linkentity(owner);
// PMM - set bounding box so we don't clip out of world
// VectorSet(self->mins, -5, -5, -5);
// VectorSet(self->maxs, 5, 5, 5);
self->solid = SOLID_BBOX;
gi.linkentity (self);
}
// else
// gi.dprintf("too close for sam raimi cam\n");
}
}
// =================
// =================
void defender_pain (edict_t *self, edict_t *other, float kick, int damage)
{
//PMM
if(other == self->owner)
{
// if ((g_showlogic) && (g_showlogic->value))
// gi.dprintf ("defender: won't get mad at my owner!\n");
return;
}
//pmm
self->enemy = other;
}
// =================
// =================
void vengeance_pain (edict_t *self, edict_t *other, float kick, int damage)
{
if(self->enemy)
return;
if(!(self->spawnflags & SPHERE_DOPPLEGANGER))
{
if(self->owner->health >= 25)
return;
//PMM
if(other == self->owner)
{
// if ((g_showlogic) && (g_showlogic->value))
// gi.dprintf ("vengeance: won't get mad at my owner!\n");
return;
}
//pmm
}
else
{
self->wait = level.time + MINIMUM_FLY_TIME;
}
if((self->wait - level.time) < MINIMUM_FLY_TIME)
self->wait = level.time + MINIMUM_FLY_TIME;
self->s.effects |= EF_ROCKET;
self->touch = vengeance_touch;
self->enemy = other;
}
// *************************
// Think Functions
// *************************
// ===================
// ===================
void defender_think (edict_t *self)
{
if(!self->owner)
{
// gi.dprintf("think: no owner\n");
G_FreeEdict(self);
return;
}
// if we've exited the level, just remove ourselves.
if (level.intermissiontime)
{
sphere_think_explode(self);
return;
}
if(self->owner->health <=0)
{
sphere_think_explode(self);
return;
}
// if(level.time - self->timestamp > 1)
// {
// gi.sound (self, CHAN_VOICE, gi.soundindex ("powerup/dsphere.wav"), 0.6, ATTN_NORM, 0);
// self->timestamp = level.time;
// }
self->s.frame++;
if(self->s.frame>19)
self->s.frame = 0;
if(self->enemy)
{
if(self->enemy->health > 0)
{
// gi.dprintf( "shooting at %s\n", self->enemy->classname);
defender_shoot (self, self->enemy);
}
else
self->enemy = NULL;
}
// else
// {
// self->ideal_yaw+=3;
// M_ChangeYaw (self);
// }
sphere_fly (self);
if(self->inuse)
self->nextthink = level.time + 0.1;
}
// =================
// =================
void hunter_think (edict_t *self)
{
edict_t *owner;
vec3_t dir, ang;
// if we've exited the level, just remove ourselves.
if (level.intermissiontime)
{
sphere_think_explode(self);
return;
}
owner = self->owner;
if(!owner && !(self->spawnflags & SPHERE_DOPPLEGANGER))
{
// gi.dprintf("think: no owner\n");
G_FreeEdict(self);
return;
}
if(owner)
self->ideal_yaw = owner->s.angles[YAW];
else if(self->enemy) // fired by doppleganger
{
VectorSubtract(self->enemy->s.origin, self->s.origin, dir);
vectoangles2(dir, ang);
self->ideal_yaw = ang[YAW];
}
M_ChangeYaw(self);
// if(level.time - self->timestamp > 1)
// {
// gi.sound (self, CHAN_VOICE, gi.soundindex ("powerup/hsphere.wav"), 0.5, ATTN_NORM, 0);
// self->timestamp = level.time;
// }
if(self->enemy)
{
sphere_chase (self, 0);
// deal with sam raimi cam
if(owner && (owner->flags & FL_SAM_RAIMI))
{
if(self->inuse)
{
owner->movetype = MOVETYPE_FLYMISSILE;
// VectorCopy(self->s.angles, owner->s.angles);
// VectorCopy(self->s.angles, owner->client->v_angle);
LookAtKiller (owner, self, self->enemy);
// owner->viewheight = 22;
// owner->client->v_angle[YAW]+=5;
// owner is flying with us, move him too
owner->movetype = MOVETYPE_FLYMISSILE;
owner->viewheight = self->s.origin[2] - owner->s.origin[2];
// VectorCopy(self->s.angles, owner->s.angles);
// VectorCopy(self->s.angles, owner->client->v_angle);
VectorCopy(self->s.origin, owner->s.origin);
VectorCopy(self->velocity, owner->velocity);
VectorClear(owner->mins);
VectorClear(owner->maxs);
gi.linkentity(owner);
}
else // sphere timed out
{
VectorClear(owner->velocity);
owner->movetype = MOVETYPE_NONE;
gi.linkentity(owner);
}
}
}
else
{
// self->ideal_yaw+=3;
// M_ChangeYaw (self);
sphere_fly (self);
}
if(self->inuse)
self->nextthink = level.time + 0.1;
}
// =================
// =================
void vengeance_think (edict_t *self)
{
// if we've exited the level, just remove ourselves.
if (level.intermissiontime)
{
sphere_think_explode(self);
return;
}
if(!(self->owner) && !(self->spawnflags & SPHERE_DOPPLEGANGER))
{
// gi.dprintf("think: no owner\n");
G_FreeEdict(self);
return;
}
// if(level.time - self->timestamp > 1)
// {
// gi.sound (self, CHAN_VOICE, gi.soundindex ("powerup/vsphere.wav"), 0.5, ATTN_NORM, 0);
// self->timestamp = level.time;
// }
if(self->enemy)
{
// sphere_fire (self, self->owner->enemy);
sphere_chase (self, 1);
}
else
sphere_fly (self);
if(self->inuse)
self->nextthink = level.time + 0.1;
}
// *************************
// Spawning / Creation
// *************************
// monsterinfo_t
// =================
// =================
edict_t *Sphere_Spawn (edict_t *owner, int spawnflags)
{
edict_t *sphere;
sphere = G_Spawn();
VectorCopy(owner->s.origin, sphere->s.origin);
sphere->s.origin[2] = owner->absmax[2];
sphere->s.angles[YAW] = owner->s.angles[YAW];
sphere->solid = SOLID_BBOX;
sphere->clipmask = MASK_SHOT;
sphere->s.renderfx = RF_FULLBRIGHT | RF_IR_VISIBLE;
sphere->movetype = MOVETYPE_FLYMISSILE;
if(spawnflags & SPHERE_DOPPLEGANGER)
sphere->teammaster = owner->teammaster;
else
sphere->owner = owner;
sphere->classname = "sphere";
sphere->yaw_speed = 40;
sphere->monsterinfo.attack_finished = 0;
sphere->spawnflags = spawnflags; // need this for the HUD to recognize sphere
//PMM
sphere->takedamage = DAMAGE_NO;
switch(spawnflags & SPHERE_TYPE)
{
case SPHERE_DEFENDER:
sphere->s.modelindex = gi.modelindex("models/items/defender/tris.md2");
// PMM - this doesn't work, causes problems with other stuff
// sphere->s.modelindex2 = gi.modelindex("models/items/shell/tris.md2") | 0x80;
sphere->s.modelindex2 = gi.modelindex("models/items/shell/tris.md2");
sphere->s.sound = gi.soundindex ("spheres/d_idle.wav");
sphere->pain = defender_pain;
sphere->wait = level.time + DEFENDER_LIFESPAN;
sphere->die = sphere_explode;
sphere->think = defender_think;
break;
case SPHERE_HUNTER:
sphere->s.modelindex = gi.modelindex("models/items/hunter/tris.md2");
sphere->s.sound = gi.soundindex ("spheres/h_idle.wav");
sphere->wait = level.time + HUNTER_LIFESPAN;
sphere->pain = hunter_pain;
sphere->die = sphere_if_idle_die;
sphere->think = hunter_think;
break;
case SPHERE_VENGEANCE:
sphere->s.modelindex = gi.modelindex("models/items/vengnce/tris.md2");
sphere->s.sound = gi.soundindex ("spheres/v_idle.wav");
sphere->wait = level.time + VENGEANCE_LIFESPAN;
sphere->pain = vengeance_pain;
sphere->die = sphere_if_idle_die;
sphere->think = vengeance_think;
VectorSet (sphere->avelocity, 30, 30, 0);
break;
default:
gi.dprintf("Tried to create an invalid sphere\n");
G_FreeEdict(sphere);
return NULL;
}
sphere->nextthink = level.time + 0.1;
gi.linkentity (sphere);
return sphere;
}
// =================
// Own_Sphere - attach the sphere to the client so we can
// directly access it later
// =================
void Own_Sphere (edict_t *self, edict_t *sphere)
{
if(!sphere)
return;
// ownership only for players
if(self->client)
{
// if they don't have one
if(!(self->client->owned_sphere))
{
self->client->owned_sphere = sphere;
}
// they already have one, take care of the old one
else
{
if(self->client->owned_sphere->inuse)
{
G_FreeEdict(self->client->owned_sphere);
self->client->owned_sphere = sphere;
}
else
{
self->client->owned_sphere = sphere;
}
}
}
}
// =================
// =================
void Defender_Launch (edict_t *self)
{
edict_t *sphere;
sphere = Sphere_Spawn (self, SPHERE_DEFENDER);
Own_Sphere (self, sphere);
}
// =================
// =================
void Hunter_Launch (edict_t *self)
{
edict_t *sphere;
sphere = Sphere_Spawn (self, SPHERE_HUNTER);
Own_Sphere (self, sphere);
}
// =================
// =================
void Vengeance_Launch (edict_t *self)
{
edict_t *sphere;
sphere = Sphere_Spawn (self, SPHERE_VENGEANCE);
Own_Sphere (self, sphere);
}
| 18,537 | C | .c | 675 | 24.98963 | 104 | 0.635749 | kondrak/vkQuake2 | 897 | 91 | 1 | GPL-2.0 | 9/7/2024, 9:40:22 AM (Europe/Amsterdam) | false | false | false | true | true | false | false | false |
297,772 | g_newtarg.c | kondrak_vkQuake2/rogue/g_newtarg.c | #include "g_local.h"
//==========================================================
/*QUAKED target_steam (1 0 0) (-8 -8 -8) (8 8 8)
Creates a steam effect (particles w/ velocity in a line).
speed = velocity of particles (default 50)
count = number of particles (default 32)
sounds = color of particles (default 8 for steam)
the color range is from this color to this color + 6
wait = seconds to run before stopping (overrides default
value derived from func_timer)
best way to use this is to tie it to a func_timer that "pokes"
it every second (or however long you set the wait time, above)
note that the width of the base is proportional to the speed
good colors to use:
6-9 - varying whites (darker to brighter)
224 - sparks
176 - blue water
80 - brown water
208 - slime
232 - blood
*/
void use_target_steam (edict_t *self, edict_t *other, edict_t *activator)
{
// FIXME - this needs to be a global
static int nextid;
vec3_t point;
if (nextid > 20000)
nextid = nextid %20000;
nextid++;
// automagically set wait from func_timer unless they set it already, or
// default to 1000 if not called by a func_timer (eek!)
if (!self->wait)
if (other)
self->wait = other->wait * 1000;
else
self->wait = 1000;
if (self->enemy)
{
VectorMA (self->enemy->absmin, 0.5, self->enemy->size, point);
VectorSubtract (point, self->s.origin, self->movedir);
VectorNormalize (self->movedir);
}
VectorMA (self->s.origin, self->plat2flags*0.5, self->movedir, point);
if (self->wait > 100)
{
gi.WriteByte (svc_temp_entity);
gi.WriteByte (TE_STEAM);
gi.WriteShort (nextid);
gi.WriteByte (self->count);
gi.WritePosition (self->s.origin);
gi.WriteDir (self->movedir);
gi.WriteByte (self->sounds&0xff);
gi.WriteShort ( (short int)(self->plat2flags) );
gi.WriteLong ( (int)(self->wait) );
gi.multicast (self->s.origin, MULTICAST_PVS);
}
else
{
gi.WriteByte (svc_temp_entity);
gi.WriteByte (TE_STEAM);
gi.WriteShort ((short int)-1);
gi.WriteByte (self->count);
gi.WritePosition (self->s.origin);
gi.WriteDir (self->movedir);
gi.WriteByte (self->sounds&0xff);
gi.WriteShort ( (short int)(self->plat2flags) );
gi.multicast (self->s.origin, MULTICAST_PVS);
}
}
void target_steam_start (edict_t *self)
{
edict_t *ent;
self->use = use_target_steam;
if (self->target)
{
ent = G_Find (NULL, FOFS(targetname), self->target);
if (!ent)
gi.dprintf ("%s at %s: %s is a bad target\n", self->classname, vtos(self->s.origin), self->target);
self->enemy = ent;
}
else
{
G_SetMovedir (self->s.angles, self->movedir);
}
if (!self->count)
self->count = 32;
if (!self->plat2flags)
self->plat2flags = 75;
if (!self->sounds)
self->sounds = 8;
if (self->wait)
self->wait *= 1000; // we want it in milliseconds, not seconds
// paranoia is good
self->sounds &= 0xff;
self->count &= 0xff;
self->svflags = SVF_NOCLIENT;
gi.linkentity (self);
}
void SP_target_steam (edict_t *self)
{
self->plat2flags = self->speed;
if (self->target)
{
self->think = target_steam_start;
self->nextthink = level.time + 1;
}
else
target_steam_start (self);
}
//==========================================================
// target_anger
//==========================================================
void target_anger_use (edict_t *self, edict_t *other, edict_t *activator)
{
edict_t *target;
edict_t *t;
t = NULL;
target = G_Find (t, FOFS(targetname), self->killtarget);
if (target && self->target)
{
// Make whatever a "good guy" so the monster will try to kill it!
target->monsterinfo.aiflags |= AI_GOOD_GUY;
target->svflags |= SVF_MONSTER;
target->health = 300;
t = NULL;
while ((t = G_Find (t, FOFS(targetname), self->target)))
{
if (t == self)
{
gi.dprintf ("WARNING: entity used itself.\n");
}
else
{
if (t->use)
{
if (t->health < 0)
{
// if ((g_showlogic) && (g_showlogic->value))
// gi.dprintf ("target_anger with dead monster!\n");
return;
}
t->enemy = target;
t->monsterinfo.aiflags |= AI_TARGET_ANGER;
FoundTarget (t);
}
}
if (!self->inuse)
{
gi.dprintf("entity was removed while using targets\n");
return;
}
}
}
}
/*QUAKED target_anger (1 0 0) (-8 -8 -8) (8 8 8)
This trigger will cause an entity to be angry at another entity when a player touches it. Target the
entity you want to anger, and killtarget the entity you want it to be angry at.
target - entity to piss off
killtarget - entity to be pissed off at
*/
void SP_target_anger (edict_t *self)
{
if (!self->target)
{
gi.dprintf("target_anger without target!\n");
G_FreeEdict (self);
return;
}
if (!self->killtarget)
{
gi.dprintf("target_anger without killtarget!\n");
G_FreeEdict (self);
return;
}
self->use = target_anger_use;
self->svflags = SVF_NOCLIENT;
}
// ================
// target_spawn
// ================
/*
extern edict_t *CreateMonster(vec3_t origin, vec3_t angles, char *classname);
void target_spawn_use (edict_t *self, edict_t *other, edict_t *activator)
{
edict_t *newEnt;
newEnt = CreateMonster (self->s.origin, self->s.angles, "monster_infantry");
if(newEnt)
newEnt->enemy = other;
}
*/
/*Q U AKED target_spawn (1 0 0) (-32 -32 -24) (32 32 72)
*/
/*
void SP_target_spawn (edict_t *self)
{
self->use = target_spawn_use;
self->svflags = SVF_NOCLIENT;
}
*/
// ***********************************
// target_killplayers
// ***********************************
void target_killplayers_use (edict_t *self, edict_t *other, edict_t *activator)
{
int i;
edict_t *ent, *player;
// kill the players
for (i=0 ; i<game.maxclients ; i++)
{
player = &g_edicts[1+i];
if (!player->inuse)
continue;
// nail it
T_Damage (player, self, self, vec3_origin, self->s.origin, vec3_origin, 100000, 0, DAMAGE_NO_PROTECTION, MOD_TELEFRAG);
}
// kill any visible monsters
for (ent = g_edicts; ent < &g_edicts[globals.num_edicts] ; ent++)
{
if (!ent->inuse)
continue;
if (ent->health < 1)
continue;
if (!ent->takedamage)
continue;
for(i=0;i<game.maxclients ; i++)
{
player = &g_edicts[1+i];
if(!player->inuse)
continue;
if(visible(player, ent))
{
T_Damage (ent, self, self, vec3_origin, ent->s.origin, vec3_origin,
ent->health, 0, DAMAGE_NO_PROTECTION, MOD_TELEFRAG);
break;
}
}
}
}
/*QUAKED target_killplayers (1 0 0) (-8 -8 -8) (8 8 8)
When triggered, this will kill all the players on the map.
*/
void SP_target_killplayers (edict_t *self)
{
self->use = target_killplayers_use;
self->svflags = SVF_NOCLIENT;
}
/*QUAKED target_blacklight (1 0 1) (-16 -16 -24) (16 16 24)
Pulsing black light with sphere in the center
*/
void blacklight_think (edict_t *self)
{
self->s.angles[0] = rand()%360;
self->s.angles[1] = rand()%360;
self->s.angles[2] = rand()%360;
self->nextthink = level.time + 0.1;
}
void SP_target_blacklight(edict_t *ent)
{
if (deathmatch->value)
{ // auto-remove for deathmatch
G_FreeEdict (ent);
return;
}
VectorClear (ent->mins);
VectorClear (ent->maxs);
ent->s.effects |= (EF_TRACKERTRAIL|EF_TRACKER);
ent->think = blacklight_think;
ent->s.modelindex = gi.modelindex ("models/items/spawngro2/tris.md2");
ent->s.frame = 1;
ent->nextthink = level.time + 0.1;
gi.linkentity (ent);
}
/*QUAKED target_orb (1 0 1) (-16 -16 -24) (16 16 24)
Translucent pulsing orb with speckles
*/
void orb_think (edict_t *self)
{
self->s.angles[0] = rand()%360;
self->s.angles[1] = rand()%360;
self->s.angles[2] = rand()%360;
// self->s.effects |= (EF_TRACKERTRAIL|EF_DOUBLE);
self->nextthink = level.time + 0.1;
}
void SP_target_orb(edict_t *ent)
{
if (deathmatch->value)
{ // auto-remove for deathmatch
G_FreeEdict (ent);
return;
}
VectorClear (ent->mins);
VectorClear (ent->maxs);
// ent->s.effects |= EF_TRACKERTRAIL;
ent->think = orb_think;
ent->nextthink = level.time + 0.1;
ent->s.modelindex = gi.modelindex ("models/items/spawngro2/tris.md2");
ent->s.frame = 2;
ent->s.effects |= EF_SPHERETRANS;
gi.linkentity (ent);
}
| 8,094 | C | .c | 300 | 24.396667 | 121 | 0.648656 | kondrak/vkQuake2 | 897 | 91 | 1 | GPL-2.0 | 9/7/2024, 9:40:22 AM (Europe/Amsterdam) | false | false | false | true | true | false | false | false |
490,461 | fifo_map.h | autobleem_AutoBleem/libs/nlohmann/fifo_map.h | /*
The code is licensed under the MIT License <http://opensource.org/licenses/MIT>:
Copyright (c) 2015-2017 Niels Lohmann.
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.
*/
#ifndef NLOHMANN_FIFO_MAP_HPP
#define NLOHMANN_FIFO_MAP_HPP
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <unordered_map>
#include <utility>
#include <vector>
/*!
@brief namespace for Niels Lohmann
@see https://github.com/nlohmann
*/
namespace nlohmann
{
template<class Key>
class fifo_map_compare
{
public:
/// constructor given a pointer to a key storage
fifo_map_compare(
std::unordered_map<Key, std::size_t>* keys,
std::size_t timestamp = 1)
:
m_timestamp(timestamp),
m_keys(keys)
{}
/*!
This function compares two keys with respect to the order in which they
were added to the container. For this, the mapping keys is used.
*/
bool operator()(const Key& lhs, const Key& rhs) const
{
// look up timestamps for both keys
const auto timestamp_lhs = m_keys->find(lhs);
const auto timestamp_rhs = m_keys->find(rhs);
if (timestamp_lhs == m_keys->end())
{
// timestamp for lhs not found - cannot be smaller than for rhs
return false;
}
if (timestamp_rhs == m_keys->end())
{
// timestamp for rhs not found - timestamp for lhs is smaller
return true;
}
// compare timestamps
return timestamp_lhs->second < timestamp_rhs->second;
}
void add_key(const Key& key)
{
m_keys->insert({key, m_timestamp++});
}
void remove_key(const Key& key)
{
m_keys->erase(key);
}
private:
/// helper to access m_timestamp from fifo_map copy ctor,
/// must have same number of template args as fifo_map
template <
class MapKey,
class MapT,
class MapCompare,
class MapAllocator
> friend class fifo_map;
private:
/// the next valid insertion timestamp
std::size_t m_timestamp = 1;
/// pointer to a mapping from keys to insertion timestamps
std::unordered_map<Key, std::size_t>* m_keys = nullptr;
};
template <
class Key,
class T,
class Compare = fifo_map_compare<Key>,
class Allocator = std::allocator<std::pair<const Key, T>>
> class fifo_map
{
public:
using key_type = Key;
using mapped_type = T;
using value_type = std::pair<const Key, T>;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
using key_compare = Compare;
using allocator_type = Allocator;
using reference = value_type&;
using const_reference = const value_type&;
using pointer = typename std::allocator_traits<Allocator>::pointer;
using const_pointer = typename std::allocator_traits<Allocator>::const_pointer;
using internal_map_type = std::map<Key, T, Compare, Allocator>;
using iterator = typename internal_map_type::iterator;
using const_iterator = typename internal_map_type::const_iterator;
using reverse_iterator = typename internal_map_type::reverse_iterator;
using const_reverse_iterator = typename internal_map_type::const_reverse_iterator;
public:
/// default constructor
fifo_map() : m_keys(), m_compare(&m_keys), m_map(m_compare) {}
/// copy constructor
fifo_map(const fifo_map &f) : m_keys(f.m_keys), m_compare(&m_keys, f.m_compare.m_timestamp), m_map(f.m_map.begin(), f.m_map.end(), m_compare) {}
/// constructor for a range of elements
template<class InputIterator>
fifo_map(InputIterator first, InputIterator last)
: m_keys(), m_compare(&m_keys), m_map(m_compare)
{
for (auto it = first; it != last; ++it)
{
insert(*it);
}
}
/// constructor for a list of elements
fifo_map(std::initializer_list<value_type> init) : fifo_map()
{
for (auto x : init)
{
insert(x);
}
}
/*
* Element access
*/
/// access specified element with bounds checking
T& at(const Key& key)
{
return m_map.at(key);
}
/// access specified element with bounds checking
const T& at(const Key& key) const
{
return m_map.at(key);
}
/// access specified element
T& operator[](const Key& key)
{
m_compare.add_key(key);
return m_map[key];
}
/// access specified element
T& operator[](Key&& key)
{
m_compare.add_key(key);
return m_map[key];
}
/*
* Iterators
*/
/// returns an iterator to the beginning
iterator begin() noexcept
{
return m_map.begin();
}
/// returns an iterator to the end
iterator end() noexcept
{
return m_map.end();
}
/// returns an iterator to the beginning
const_iterator begin() const noexcept
{
return m_map.begin();
}
/// returns an iterator to the end
const_iterator end() const noexcept
{
return m_map.end();
}
/// returns an iterator to the beginning
const_iterator cbegin() const noexcept
{
return m_map.cbegin();
}
/// returns an iterator to the end
const_iterator cend() const noexcept
{
return m_map.cend();
}
/// returns a reverse iterator to the beginning
reverse_iterator rbegin() noexcept
{
return m_map.rbegin();
}
/// returns a reverse iterator to the end
reverse_iterator rend() noexcept
{
return m_map.rend();
}
/// returns a reverse iterator to the beginning
const_reverse_iterator rbegin() const noexcept
{
return m_map.rbegin();
}
/// returns a reverse iterator to the end
const_reverse_iterator rend() const noexcept
{
return m_map.rend();
}
/// returns a reverse iterator to the beginning
const_reverse_iterator crbegin() const noexcept
{
return m_map.crbegin();
}
/// returns a reverse iterator to the end
const_reverse_iterator crend() const noexcept
{
return m_map.crend();
}
/*
* Capacity
*/
/// checks whether the container is empty
bool empty() const noexcept
{
return m_map.empty();
}
/// returns the number of elements
size_type size() const noexcept
{
return m_map.size();
}
/// returns the maximum possible number of elements
size_type max_size() const noexcept
{
return m_map.max_size();
}
/*
* Modifiers
*/
/// clears the contents
void clear() noexcept
{
m_map.clear();
m_keys.clear();
}
/// insert value
std::pair<iterator, bool> insert(const value_type& value)
{
m_compare.add_key(value.first);
return m_map.insert(value);
}
/// insert value
template<class P>
std::pair<iterator, bool> insert( P&& value )
{
m_compare.add_key(value.first);
return m_map.insert(value);
}
/// insert value with hint
iterator insert(const_iterator hint, const value_type& value)
{
m_compare.add_key(value.first);
return m_map.insert(hint, value);
}
/// insert value with hint
iterator insert(const_iterator hint, value_type&& value)
{
m_compare.add_key(value.first);
return m_map.insert(hint, value);
}
/// insert value range
template<class InputIt>
void insert(InputIt first, InputIt last)
{
for (const_iterator it = first; it != last; ++it)
{
m_compare.add_key(it->first);
}
m_map.insert(first, last);
}
/// insert value list
void insert(std::initializer_list<value_type> ilist)
{
for (auto value : ilist)
{
m_compare.add_key(value.first);
}
m_map.insert(ilist);
}
/// constructs element in-place
template<class... Args>
std::pair<iterator, bool> emplace(Args&& ... args)
{
typename fifo_map::value_type value(std::forward<Args>(args)...);
m_compare.add_key(value.first);
return m_map.emplace(std::move(value));
}
/// constructs element in-place with hint
template<class... Args>
iterator emplace_hint(const_iterator hint, Args&& ... args)
{
typename fifo_map::value_type value(std::forward<Args>(args)...);
m_compare.add_key(value.first);
return m_map.emplace_hint(hint, std::move(value));
}
/// remove element at position
iterator erase(const_iterator pos)
{
m_compare.remove_key(pos->first);
return m_map.erase(pos);
}
/// remove elements in range
iterator erase(const_iterator first, const_iterator last)
{
for (const_iterator it = first; it != last; ++it)
{
m_compare.remove_key(it->first);
}
return m_map.erase(first, last);
}
/// remove elements with key
size_type erase(const key_type& key)
{
size_type res = m_map.erase(key);
if (res > 0)
{
m_compare.remove_key(key);
}
return res;
}
/// swaps the contents
void swap(fifo_map& other)
{
std::swap(m_map, other.m_map);
std::swap(m_compare, other.m_compare);
std::swap(m_keys, other.m_keys);
}
/*
* Lookup
*/
/// returns the number of elements matching specific key
size_type count(const Key& key) const
{
return m_map.count(key);
}
/// finds element with specific key
iterator find(const Key& key)
{
return m_map.find(key);
}
/// finds element with specific key
const_iterator find(const Key& key) const
{
return m_map.find(key);
}
/// returns range of elements matching a specific key
std::pair<iterator, iterator> equal_range(const Key& key)
{
return m_map.equal_range(key);
}
/// returns range of elements matching a specific key
std::pair<const_iterator, const_iterator> equal_range(const Key& key) const
{
return m_map.equal_range(key);
}
/// returns an iterator to the first element not less than the given key
iterator lower_bound(const Key& key)
{
return m_map.lower_bound(key);
}
/// returns an iterator to the first element not less than the given key
const_iterator lower_bound(const Key& key) const
{
return m_map.lower_bound(key);
}
/// returns an iterator to the first element greater than the given key
iterator upper_bound(const Key& key)
{
return m_map.upper_bound(key);
}
/// returns an iterator to the first element greater than the given key
const_iterator upper_bound(const Key& key) const
{
return m_map.upper_bound(key);
}
/*
* Observers
*/
/// returns the function that compares keys
key_compare key_comp() const
{
return m_compare;
}
/*
* Non-member functions
*/
friend bool operator==(const fifo_map& lhs, const fifo_map& rhs)
{
return lhs.m_map == rhs.m_map;
}
friend bool operator!=(const fifo_map& lhs, const fifo_map& rhs)
{
return lhs.m_map != rhs.m_map;
}
friend bool operator<(const fifo_map& lhs, const fifo_map& rhs)
{
return lhs.m_map < rhs.m_map;
}
friend bool operator<=(const fifo_map& lhs, const fifo_map& rhs)
{
return lhs.m_map <= rhs.m_map;
}
friend bool operator>(const fifo_map& lhs, const fifo_map& rhs)
{
return lhs.m_map > rhs.m_map;
}
friend bool operator>=(const fifo_map& lhs, const fifo_map& rhs)
{
return lhs.m_map >= rhs.m_map;
}
private:
/// the keys
std::unordered_map<Key, std::size_t> m_keys;
/// the comparison object
Compare m_compare;
/// the internal data structure
internal_map_type m_map;
};
}
// specialization of std::swap
namespace std
{
template <class Key, class T, class Compare, class Allocator>
inline void swap(nlohmann::fifo_map<Key, T, Compare, Allocator>& m1,
nlohmann::fifo_map<Key, T, Compare, Allocator>& m2)
{
m1.swap(m2);
}
}
#endif | 15,056 | C | .h | 451 | 23.81153 | 152 | 0.559132 | autobleem/AutoBleem | 499 | 72 | 111 | GPL-3.0 | 9/7/2024, 9:41:26 AM (Europe/Amsterdam) | false | false | true | true | false | true | false | false |
806,991 | demo2.c | DIVGAMES_DIV-Games-Studio/dll/demo2.c | #include <math.h>
#include <stdio.h>
#define GLOBALS
#include "div.h"
// Importante: Para cada funci¢n se debe indicar el retval(int), y hacer
// siempre un getparm() por cada par metro de llamada (el retval() es
// imprescindible incluso si la funci¢n no necesita devolver un valor).
void addsqrt() { // Funci¢n tonta, que devuelve la raiz cuadrada de una suma
int a=getparm();
int b=getparm();
int c=sqrt(a+b);
retval(c);
}
void __export divlibrary(LIBRARY_PARAMS) {
COM_export("ADDSQRT",addsqrt,2); // Se indica el nombre que tendr la funci¢n
// en el lenguaje, el puntero a la misma y
// el n£mero de par metros que tiene.
}
void __export divmain(COMMON_PARAMS) {
GLOBAL_IMPORT();
}
| 778 | C | .c | 21 | 31.761905 | 79 | 0.654206 | DIVGAMES/DIV-Games-Studio | 235 | 30 | 16 | GPL-3.0 | 9/7/2024, 9:42:46 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
807,000 | demo1.c | DIVGAMES_DIV-Games-Studio/dll/demo1.c | #include <stdio.h>
#define GLOBALS
#include "div.h"
// Los posibles puntos de ruptura se ven en DIV.H (Buscar Entry-Points)
void post_process_buffer(void) {
// Ejemplo de un punto de ruptura, DIV llamar a esta funci¢n para que
// pueda operar sobre el buffer de v¡deo antes de cada volcado.
}
void __export divmain(COMMON_PARAMS)
{
AutoLoad();
GLOBAL_IMPORT();
DIV_export("post_process_buffer",post_process_buffer);
}
void __export divend(COMMON_PARAMS){}
| 475 | C | .c | 15 | 29.466667 | 72 | 0.743363 | DIVGAMES/DIV-Games-Studio | 235 | 30 | 16 | GPL-3.0 | 9/7/2024, 9:42:46 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,201,388 | 175.c | libretro_libretro-fceumm/src/boards/175.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 reg, delay, mirr;
static SFORMAT StateRegs[] =
{
{ ®, 1, "REG" },
{ &mirr, 1, "MIRR" },
{ 0 }
};
static void Sync(void) {
setchr8(reg);
if (!delay) {
setprg16(0x8000, reg);
setprg8(0xC000, reg << 1);
}
setprg8(0xE000, (reg << 1) + 1);
setmirror(((mirr & 4) >> 2) ^ 1);
}
static DECLFW(M175Write1) {
mirr = V;
delay = 1;
Sync();
}
static DECLFW(M175Write2) {
reg = V & 0x0F;
delay = 1;
Sync();
}
static DECLFR(M175Read) {
if (A == 0xFFFC) {
delay = 0;
Sync();
}
return CartBR(A);
}
static void M175Power(void) {
reg = mirr = delay = 0;
SetReadHandler(0x8000, 0xFFFF, M175Read);
SetWriteHandler(0x8000, 0x8000, M175Write1);
SetWriteHandler(0xA000, 0xA000, M175Write2);
Sync();
}
static void StateRestore(int version) {
Sync();
}
void Mapper175_Init(CartInfo *info) {
info->Power = M175Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 1,769 | C | .c | 68 | 24.088235 | 81 | 0.712426 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
1,201,406 | 183.c | libretro_libretro-fceumm/src/boards/183.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Gimmick Bootleg (VRC4 mapper)
*/
#include "mapinc.h"
static uint8 prg[4], chr[8], mirr;
static uint8 IRQCount;
static uint8 IRQPre;
static uint8 IRQa;
static SFORMAT StateRegs[] =
{
{ prg, 4, "PRG" },
{ chr, 8, "CHR" },
{ &mirr, 1, "MIRR" },
{ &IRQCount, 1, "IRQC" },
{ &IRQPre, 1, "IRQP" },
{ &IRQa, 1, "IRQA" },
{ 0 }
};
static void SyncPrg(void) {
setprg8(0x6000, prg[3]);
setprg8(0x8000, prg[0]);
setprg8(0xA000, prg[1]);
setprg8(0xC000, prg[2]);
setprg8(0xE000, ~0);
}
static void SyncMirr(void) {
switch (mirr) {
case 0: setmirror(MI_V); break;
case 1: setmirror(MI_H); break;
case 2: setmirror(MI_0); break;
case 3: setmirror(MI_1); break;
}
}
static void SyncChr(void) {
int i;
for (i = 0; i < 8; i++)
setchr1(i << 10, chr[i]);
}
static void StateRestore(int version) {
SyncPrg();
SyncChr();
SyncMirr();
}
static DECLFW(M183Write) {
if ((A & 0xF800) == 0x6800) {
prg[3] = A & 0x3F;
SyncPrg();
} else if (((A & 0xF80C) >= 0xB000) && ((A & 0xF80C) <= 0xE00C)) {
int index = (((A >> 11) - 6) | (A >> 3)) & 7;
chr[index] = (chr[index] & (0xF0 >> (A & 4))) | ((V & 0x0F) << (A & 4));
SyncChr();
} else switch (A & 0xF80C) {
case 0x8800: prg[0] = V; SyncPrg(); break;
case 0xA800: prg[1] = V; SyncPrg(); break;
case 0xA000: prg[2] = V; SyncPrg(); break;
case 0x9800: mirr = V & 3; SyncMirr(); break;
case 0xF000: IRQCount = ((IRQCount & 0xF0) | (V & 0xF)); break;
case 0xF004: IRQCount = ((IRQCount & 0x0F) | ((V & 0xF) << 4)); break;
case 0xF008: IRQa = V; if (!V) IRQPre = 0; X6502_IRQEnd(FCEU_IQEXT); break;
case 0xF00C: IRQPre = 16; break;
}
}
static void M183IRQCounter(void) {
if (IRQa) {
IRQCount++;
if ((IRQCount - IRQPre) == 238)
X6502_IRQBegin(FCEU_IQEXT);
}
}
static void M183Power(void) {
IRQPre = IRQCount = IRQa = 0;
SetReadHandler(0x6000, 0xFFFF, CartBR);
SetWriteHandler(0x6000, 0xFFFF, M183Write);
SyncPrg();
SyncChr();
}
void Mapper183_Init(CartInfo *info) {
info->Power = M183Power;
GameHBIRQHook = M183IRQCounter;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 2,922 | C | .c | 100 | 27.17 | 81 | 0.667022 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
1,201,409 | 151.c | libretro_libretro-fceumm/src/boards/151.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2012 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 regs[8];
static SFORMAT StateRegs[] =
{
{ regs, 8, "REGS" },
{ 0 }
};
static void Sync(void) {
setprg8(0x8000, regs[0]);
setprg8(0xA000, regs[2]);
setprg8(0xC000, regs[4]);
setprg8(0xE000, ~0);
setchr4(0x0000, regs[6]);
setchr4(0x1000, regs[7]);
}
static DECLFW(M151Write) {
regs[(A >> 12) & 7] = V;
Sync();
}
static void M151Power(void) {
Sync();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, M151Write);
}
static void StateRestore(int version) {
Sync();
}
void Mapper151_Init(CartInfo *info) {
info->Power = M151Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 1,503 | C | .c | 51 | 27.627451 | 81 | 0.734765 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
1,201,412 | 228.c | libretro_libretro-fceumm/src/boards/228.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2012 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 mram[4], vreg;
static uint16 areg;
static SFORMAT StateRegs[] =
{
{ mram, 4, "MRAM" },
{ &areg, 2, "AREG" },
{ &vreg, 1, "VREG" },
{ 0 }
};
static void Sync(void) {
uint32 prgl, prgh, page = (areg >> 7) & 0x3F;
if ((page & 0x30) == 0x30)
page -= 0x10;
prgl = prgh = (page << 1) + (((areg >> 6) & 1) & ((areg >> 5) & 1));
prgh += ((areg >> 5) & 1) ^ 1;
setmirror(((areg >> 13) & 1) ^ 1);
setprg16(0x8000, prgl);
setprg16(0xc000, prgh);
setchr8(((vreg & 0x3) | ((areg & 0xF) << 2)));
}
static DECLFW(M228RamWrite) {
mram[A & 3] = V & 0x0F;
}
static DECLFR(M228RamRead) {
return mram[A & 3];
}
static DECLFW(M228Write) {
areg = A;
vreg = V;
Sync();
}
static void M228Reset(void) {
areg = 0x8000;
vreg = 0;
memset(mram, 0, sizeof(mram));
Sync();
}
static void M228Power(void) {
M228Reset();
SetReadHandler(0x5000, 0x5FFF, M228RamRead);
SetWriteHandler(0x5000, 0x5FFF, M228RamWrite);
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, M228Write);
}
static void StateRestore(int version) {
Sync();
}
void Mapper228_Init(CartInfo *info) {
info->Reset = M228Reset;
info->Power = M228Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 2,079 | C | .c | 73 | 26.616438 | 81 | 0.696088 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
1,201,415 | t-262.c | libretro_libretro-fceumm/src/boards/t-262.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 bank, base, lock, mirr, mode;
static SFORMAT StateRegs[] =
{
{ &bank, 1, "BANK" },
{ &base, 1, "BASE" },
{ &lock, 1, "LOCK" },
{ &mirr, 1, "MIRR" },
{ &mode, 1, "MODE" },
{ 0 }
};
static void Sync(void) {
setchr8(0);
setprg16(0x8000, base | bank);
setprg16(0xC000, base | (mode ? bank : 7));
setmirror(mirr);
}
static DECLFW(BMCT262Write) {
if (!lock) {
base = ((A & 0x60) >> 2) | ((A & 0x100) >> 3);
mode = A & 0x80;
mirr = ((A & 2) >> 1) ^ 1;
lock = (A & 0x2000) >> 13;
}
bank = V & 7;
Sync();
}
static void BMCT262Power(void) {
lock = bank = base = mode = 0;
Sync();
SetWriteHandler(0x8000, 0xFFFF, BMCT262Write);
SetReadHandler(0x8000, 0xFFFF, CartBR);
}
static void BMCT262Reset(void) {
lock = bank = base = mode = 0;
Sync();
}
static void BMCT262Restore(int version) {
Sync();
}
void BMCT262_Init(CartInfo *info) {
info->Power = BMCT262Power;
info->Reset = BMCT262Reset;
GameStateRestore = BMCT262Restore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 1,851 | C | .c | 65 | 26.569231 | 81 | 0.690101 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
1,201,430 | 244.c | libretro_libretro-fceumm/src/boards/244.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2012 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 preg, creg;
static SFORMAT StateRegs[] =
{
{ &preg, 1, "PREG" },
{ &creg, 1, "CREG" },
{ 0 }
};
static uint8 prg_perm[4][4] = {
{ 0, 1, 2, 3, },
{ 3, 2, 1, 0, },
{ 0, 2, 1, 3, },
{ 3, 1, 2, 0, },
};
static uint8 chr_perm[8][8] = {
{ 0, 1, 2, 3, 4, 5, 6, 7, },
{ 0, 2, 1, 3, 4, 6, 5, 7, },
{ 0, 1, 4, 5, 2, 3, 6, 7, },
{ 0, 4, 1, 5, 2, 6, 3, 7, },
{ 0, 4, 2, 6, 1, 5, 3, 7, },
{ 0, 2, 4, 6, 1, 3, 5, 7, },
{ 7, 6, 5, 4, 3, 2, 1, 0, },
{ 7, 6, 5, 4, 3, 2, 1, 0, },
};
static void Sync(void) {
setprg32(0x8000, preg);
setchr8(creg);
}
static DECLFW(M244Write) {
if (V & 8)
creg = chr_perm[(V >> 4) & 7][V & 7];
else
preg = prg_perm[(V >> 4) & 3][V & 3];
Sync();
}
static void M244Power(void) {
preg = creg = 0;
Sync();
SetWriteHandler(0x8000, 0xFFFF, M244Write);
SetReadHandler(0x8000, 0xFFFF, CartBR);
}
static void StateRestore(int version) {
Sync();
}
void Mapper244_Init(CartInfo *info) {
info->Power = M244Power;
AddExState(&StateRegs, ~0, 0, 0);
GameStateRestore = StateRestore;
}
| 1,887 | C | .c | 68 | 25.882353 | 81 | 0.639779 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
1,201,437 | karaoke.c | libretro_libretro-fceumm/src/boards/karaoke.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
extern uint32 ROM_size;
static uint8 latche;
static void Sync(void) {
if (latche) {
if (latche & 0x10)
setprg16(0x8000, (latche & 7));
else
setprg16(0x8000, (latche & 7) | 8);
} else
setprg16(0x8000, 7 + (ROM_size >> 4));
}
static DECLFW(M188Write) {
latche = V;
Sync();
}
static DECLFR(ExtDev) {
return(3);
}
static void Power(void) {
latche = 0;
Sync();
setchr8(0);
setprg16(0xc000, 0x7);
SetReadHandler(0x6000, 0x7FFF, ExtDev);
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, M188Write);
}
static void StateRestore(int version) {
Sync();
}
void Mapper188_Init(CartInfo *info) {
info->Power = Power;
GameStateRestore = StateRestore;
AddExState(&latche, 1, 0, "LATC");
}
| 1,583 | C | .c | 55 | 26.8 | 81 | 0.736842 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
1,201,462 | 234.c | libretro_libretro-fceumm/src/boards/234.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2012 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 bank, preg;
static SFORMAT StateRegs[] =
{
{ &bank, 1, "BANK" },
{ &preg, 1, "PREG" },
{ 0 }
};
static void Sync(void) {
if (bank & 0x40) {
setprg32(0x8000, (bank & 0xE) | (preg & 1));
setchr8(((bank & 0xE) << 2) | ((preg >> 4) & 7));
} else {
setprg32(0x8000, bank & 0xF);
setchr8(((bank & 0xF) << 2) | ((preg >> 4) & 3));
}
setmirror((bank >> 7) ^ 1);
}
DECLFR(M234ReadBank) {
uint8 r = CartBR(A);
if (!bank) {
bank = r;
Sync();
}
return r;
}
DECLFR(M234ReadPreg) {
uint8 r = CartBR(A);
preg = r;
Sync();
return r;
}
static void M234Reset(void) {
bank = preg = 0;
Sync();
}
static void M234Power(void) {
M234Reset();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetReadHandler(0xFF80, 0xFF9F, M234ReadBank);
SetReadHandler(0xFFE8, 0xFFF7, M234ReadPreg);
}
static void StateRestore(int version) {
Sync();
}
void Mapper234_Init(CartInfo *info) {
info->Power = M234Power;
info->Reset = M234Reset;
AddExState(&StateRegs, ~0, 0, 0);
GameStateRestore = StateRestore;
}
| 1,869 | C | .c | 70 | 24.771429 | 81 | 0.699441 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
1,201,467 | 41.c | libretro_libretro-fceumm/src/boards/41.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2012 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 mainreg, chrreg, mirror;
static SFORMAT StateRegs[] =
{
{ &mainreg, 1, "MREG" },
{ &chrreg, 1, "CREG" },
{ &mirror, 1, "MIRR" },
{ 0 }
};
static void Sync(void) {
setprg32(0x8000, mainreg & 7);
setchr8(chrreg);
setmirror(mirror);
}
static DECLFW(M41Write0) {
mainreg = A & 0xFF;
mirror = ((A >> 5) & 1) ^ 1;
chrreg = (chrreg & 3) | ((A >> 1) & 0xC);
Sync();
}
static DECLFW(M41Write1) {
if (mainreg & 0x4) {
chrreg = (chrreg & 0xC) | (A & 3);
Sync();
}
}
static void M41Power(void) {
mainreg = chrreg = 0;
Sync();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x6000, 0x67FF, M41Write0);
SetWriteHandler(0x8000, 0xFFFF, M41Write1);
}
static void StateRestore(int version) {
Sync();
}
void Mapper41_Init(CartInfo *info) {
info->Power = M41Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 1,721 | C | .c | 60 | 26.8 | 81 | 0.713075 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,201,469 | novel.c | libretro_libretro-fceumm/src/boards/novel.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 latch;
static void DoNovel(void) {
setprg32(0x8000, latch & 3);
setchr8(latch & 7);
}
static DECLFW(NovelWrite) {
latch = A & 0xFF;
DoNovel();
}
static void NovelReset(void) {
SetWriteHandler(0x8000, 0xFFFF, NovelWrite);
SetReadHandler(0x8000, 0xFFFF, CartBR);
setprg32(0x8000, 0);
setchr8(0);
}
static void NovelRestore(int version) {
DoNovel();
}
void Novel_Init(CartInfo *info) {
AddExState(&latch, 1, 0, "L1");
info->Power = NovelReset;
GameStateRestore = NovelRestore;
}
| 1,359 | C | .c | 43 | 29.744186 | 81 | 0.753247 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | true | false | false | true | true | false | false | false |
1,201,499 | dream.c | libretro_libretro-fceumm/src/boards/dream.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 latche;
static void Sync(void) {
setprg16(0x8000, latche);
setprg16(0xC000, 8);
}
static DECLFW(DREAMWrite) {
latche = V & 7;
Sync();
}
static void DREAMPower(void) {
latche = 0;
Sync();
setchr8(0);
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x5020, 0x5020, DREAMWrite);
}
static void Restore(int version) {
Sync();
}
void DreamTech01_Init(CartInfo *info) {
GameStateRestore = Restore;
info->Power = DREAMPower;
AddExState(&latche, 1, 0, "LATC");
}
| 1,344 | C | .c | 44 | 28.681818 | 81 | 0.750967 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,201,500 | 46.c | libretro_libretro-fceumm/src/boards/46.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2012 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 reg0, reg1;
static SFORMAT StateRegs[] =
{
{ ®0, 1, "REG0" },
{ ®1, 1, "REG1" },
{ 0 }
};
static void Sync(void) {
setprg32(0x8000, (reg1 & 1) + ((reg0 & 0xF) << 1));
setchr8(((reg1 >> 4) & 7) + ((reg0 & 0xF0) >> 1));
}
static DECLFW(M46Write0) {
reg0 = V;
Sync();
}
static DECLFW(M46Write1) {
reg1 = V;
Sync();
}
static void M46Power(void) {
reg0 = reg1 = 0;
Sync();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x6000, 0x7FFF, M46Write0);
SetWriteHandler(0x8000, 0xFFFF, M46Write1);
}
static void M46Reset(void) {
reg0 = reg1 = 0;
Sync();
}
static void StateRestore(int version) {
Sync();
}
void Mapper46_Init(CartInfo *info) {
info->Power = M46Power;
info->Reset = M46Reset;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 1,657 | C | .c | 59 | 26.254237 | 81 | 0.716625 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
1,201,518 | 230.c | libretro_libretro-fceumm/src/boards/230.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
* Copyright (C) 2009 qeed
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* 22 + Contra Reset based custom mapper...
*
*/
#include "mapinc.h"
static uint8 latche, reset;
static SFORMAT StateRegs[] =
{
{ &reset, 1, "RST" },
{ &latche, 1, "LATC" },
{ 0 }
};
static void Sync(void) {
if (reset) {
setprg16(0x8000, latche & 7);
setprg16(0xC000, 7);
setmirror(MI_V);
} else {
uint32 bank = (latche & 0x1F) + 8;
if (latche & 0x20) {
setprg16(0x8000, bank);
setprg16(0xC000, bank);
} else
setprg32(0x8000, bank >> 1);
setmirror((latche >> 6) & 1);
}
setchr8(0);
}
static DECLFW(M230Write) {
latche = V;
Sync();
}
static void M230Reset(void) {
reset ^= 1;
Sync();
}
static void M230Power(void) {
latche = reset = 0;
Sync();
SetWriteHandler(0x8000, 0xFFFF, M230Write);
SetReadHandler(0x8000, 0xFFFF, CartBR);
}
static void StateRestore(int version) {
Sync();
}
void Mapper230_Init(CartInfo *info) {
info->Power = M230Power;
info->Reset = M230Reset;
AddExState(&StateRegs, ~0, 0, 0);
GameStateRestore = StateRestore;
}
| 1,845 | C | .c | 70 | 24.314286 | 81 | 0.712507 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
1,201,550 | bs-5.c | libretro_libretro-fceumm/src/boards/bs-5.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 reg_prg[4];
static uint8 reg_chr[4];
static uint8 dip_switch;
static SFORMAT StateRegs[] =
{
{ reg_prg, 4, "PREG" },
{ reg_chr, 4, "CREG" },
{ 0 }
};
static void Sync(void) {
setprg8(0x8000, reg_prg[0]);
setprg8(0xa000, reg_prg[1]);
setprg8(0xc000, reg_prg[2]);
setprg8(0xe000, reg_prg[3]);
setchr2(0x0000, reg_chr[0]);
setchr2(0x0800, reg_chr[1]);
setchr2(0x1000, reg_chr[2]);
setchr2(0x1800, reg_chr[3]);
setmirror(MI_V);
}
static DECLFW(MBS5Write) {
int bank_sel = (A & 0xC00) >> 10;
switch (A & 0xF000) {
case 0x8000:
reg_chr[bank_sel] = A & 0x1F;
break;
case 0xA000:
if (A & (1 << (dip_switch + 4)))
reg_prg[bank_sel] = A & 0x0F;
break;
}
Sync();
}
static void MBS5Reset(void) {
dip_switch++;
dip_switch &= 3;
reg_prg[0] = reg_prg[1] = reg_prg[2] = reg_prg[3] = ~0;
Sync();
}
static void MBS5Power(void) {
dip_switch = 0;
reg_prg[0] = reg_prg[1] = reg_prg[2] = reg_prg[3] = ~0;
Sync();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, MBS5Write);
}
static void StateRestore(int version) {
Sync();
}
void BMCBS5_Init(CartInfo *info) {
info->Power = MBS5Power;
info->Reset = MBS5Reset;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 2,095 | C | .c | 75 | 26 | 81 | 0.702636 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
1,201,562 | 62.c | libretro_libretro-fceumm/src/boards/62.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2012 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 bank;
static uint16 mode;
static SFORMAT StateRegs[] =
{
{ &bank, 1, "BANK" },
{ &mode, 2, "MODE" },
{ 0 }
};
static void Sync(void) {
setchr8(((mode & 0x1F) << 2) | (bank & 0x03));
if (mode & 0x20) {
setprg16(0x8000, (mode & 0x40) | ((mode >> 8) & 0x3F));
setprg16(0xc000, (mode & 0x40) | ((mode >> 8) & 0x3F));
} else
setprg32(0x8000, ((mode & 0x40) | ((mode >> 8) & 0x3F)) >> 1);
setmirror(((mode >> 7) & 1) ^ 1);
}
static DECLFW(M62Write) {
mode = A & 0x3FFF;
bank = V & 3;
Sync();
}
static void M62Power(void) {
bank = mode = 0;
Sync();
SetWriteHandler(0x8000, 0xFFFF, M62Write);
SetReadHandler(0x8000, 0xFFFF, CartBR);
}
static void M62Reset(void) {
bank = mode = 0;
Sync();
}
static void StateRestore(int version) {
Sync();
}
void Mapper62_Init(CartInfo *info) {
info->Power = M62Power;
info->Reset = M62Reset;
AddExState(&StateRegs, ~0, 0, 0);
GameStateRestore = StateRestore;
}
| 1,784 | C | .c | 61 | 27.377049 | 81 | 0.695627 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
1,201,582 | subor.c | libretro_libretro-fceumm/src/boards/subor.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 is167, regs[4];
static SFORMAT StateRegs[] =
{
{ regs, 4, "DREG" },
{ 0 }
};
static void Sync(void) {
int base, bank;
base = ((regs[0] ^ regs[1]) & 0x10) << 1;
bank = (regs[2] ^ regs[3]) & 0x1f;
if (regs[1] & 0x08) {
bank &= 0xFE;
if (is167) {
setprg16(0x8000, base + bank + 1);
setprg16(0xC000, base + bank + 0);
} else {
setprg16(0x8000, base + bank + 0);
setprg16(0xC000, base + bank + 1);
}
} else {
if (regs[1] & 0x04) {
setprg16(0x8000, 0x1F);
setprg16(0xC000, base + bank);
} else {
setprg16(0x8000, base + bank);
if (is167)
setprg16(0xC000, 0x20);
else
setprg16(0xC000, 0x07);
}
}
setchr8(0);
}
static DECLFW(M166Write) {
regs[(A >> 13) & 0x03] = V;
Sync();
}
static void M166Power(void) {
regs[0] = regs[1] = regs[2] = regs[3] = 0;
Sync();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, M166Write);
}
static void StateRestore(int version) {
Sync();
}
void Mapper166_Init(CartInfo *info) {
is167 = 0;
info->Power = M166Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
void Mapper167_Init(CartInfo *info) {
is167 = 1;
info->Power = M166Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 2,116 | C | .c | 78 | 24.833333 | 81 | 0.690828 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
1,201,584 | 170.c | libretro_libretro-fceumm/src/boards/170.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2011 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 reg;
static SFORMAT StateRegs[] =
{
{ ®, 1, "REGS" },
{ 0 }
};
static void Sync(void) {
setprg16(0x8000, 0);
setprg16(0xc000, ~0);
setchr8(0);
}
static DECLFW(M170ProtW) {
reg = V << 1 & 0x80;
}
static DECLFR(M170ProtR) {
return reg | (X.DB & 0x7F);
}
static void M170Power(void) {
Sync();
SetWriteHandler(0x6502, 0x6502, M170ProtW);
SetWriteHandler(0x7000, 0x7000, M170ProtW);
SetReadHandler(0x7001, 0x7001, M170ProtR);
SetReadHandler(0x7777, 0x7777, M170ProtR);
SetReadHandler(0x8000, 0xFFFF, CartBR);
}
static void StateRestore(int version) {
Sync();
}
void Mapper170_Init(CartInfo *info) {
info->Power = M170Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 1,579 | C | .c | 53 | 27.962264 | 81 | 0.74555 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
1,201,596 | 51.c | libretro_libretro-fceumm/src/boards/51.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2012 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 bank, mode;
static SFORMAT StateRegs[] =
{
{ &bank, 1, "BANK" },
{ &mode, 1, "MODE" },
{ 0 }
};
static void Sync(void) {
if (mode & 2) {
setprg8(0x6000, ((bank & 7) << 2) | 0x23);
setprg16(0x8000, (bank << 1) | 0);
setprg16(0xC000, (bank << 1) | 1);
} else {
setprg8(0x6000, ((bank & 4) << 2) | 0x2F);
setprg16(0x8000, (bank << 1) | (mode >> 4));
setprg16(0xC000, ((bank & 0xC) << 1) | 7);
}
if (mode == 0x12)
setmirror(MI_H);
else
setmirror(MI_V);
setchr8(0);
}
static DECLFW(M51WriteMode) {
mode = V & 0x12;
Sync();
}
static DECLFW(M51WriteBank) {
bank = V & 0x0F;
if (A & 0x4000)
mode = (mode & 2) | (V & 0x10);
Sync();
}
static void M51Power(void) {
bank = 0;
mode = 2;
Sync();
SetWriteHandler(0x6000, 0x7FFF, M51WriteMode);
SetWriteHandler(0x8000, 0xFFFF, M51WriteBank);
SetReadHandler(0x6000, 0xFFFF, CartBR);
}
static void M51Reset(void) {
bank = 0;
mode = 2;
Sync();
}
static void StateRestore(int version) {
Sync();
}
void Mapper51_Init(CartInfo *info) {
info->Power = M51Power;
info->Reset = M51Reset;
AddExState(&StateRegs, ~0, 0, 0);
GameStateRestore = StateRestore;
}
| 1,998 | C | .c | 75 | 24.666667 | 81 | 0.691745 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
1,201,600 | 33.c | libretro_libretro-fceumm/src/boards/33.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2012 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 is48;
static uint8 regs[8], mirr;
static uint8 IRQa;
static int16 IRQCount, IRQLatch;
static SFORMAT StateRegs[] =
{
{ regs, 8, "PREG" },
{ &mirr, 1, "MIRR" },
{ &IRQa, 1, "IRQA" },
{ &IRQCount, 2, "IRQC" },
{ &IRQLatch, 2, "IRQL" },
{ 0 }
};
static void Sync(void) {
setmirror(mirr);
setprg8(0x8000, regs[0]);
setprg8(0xA000, regs[1]);
setprg8(0xC000, ~1);
setprg8(0xE000, ~0);
setchr2(0x0000, regs[2]);
setchr2(0x0800, regs[3]);
setchr1(0x1000, regs[4]);
setchr1(0x1400, regs[5]);
setchr1(0x1800, regs[6]);
setchr1(0x1C00, regs[7]);
}
static DECLFW(M33Write) {
A &= 0xF003;
switch (A) {
case 0x8000: regs[0] = V & 0x3F; if (!is48) mirr = ((V >> 6) & 1) ^ 1; Sync(); break;
case 0x8001: regs[1] = V & 0x3F; Sync(); break;
case 0x8002: regs[2] = V; Sync(); break;
case 0x8003: regs[3] = V; Sync(); break;
case 0xA000: regs[4] = V; Sync(); break;
case 0xA001: regs[5] = V; Sync(); break;
case 0xA002: regs[6] = V; Sync(); break;
case 0xA003: regs[7] = V; Sync(); break;
}
}
static DECLFW(M48Write) {
switch (A & 0xF003) {
case 0xC000: IRQLatch = V; break;
case 0xC001: IRQCount = IRQLatch; break;
case 0xC003: IRQa = 0; X6502_IRQEnd(FCEU_IQEXT); break;
case 0xC002: IRQa = 1; break;
case 0xE000: mirr = ((V >> 6) & 1) ^ 1; Sync(); break;
}
}
static void M33Power(void) {
Sync();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, M33Write);
}
static void M48Power(void) {
Sync();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xBFFF, M33Write);
SetWriteHandler(0xC000, 0xFFFF, M48Write);
}
static void M48IRQ(void) {
if (IRQa) {
IRQCount++;
if (IRQCount == 0x100) {
X6502_IRQBegin(FCEU_IQEXT);
IRQa = 0;
}
}
}
static void StateRestore(int version) {
Sync();
}
void Mapper33_Init(CartInfo *info) {
is48 = 0;
info->Power = M33Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
void Mapper48_Init(CartInfo *info) {
is48 = 1;
info->Power = M48Power;
GameHBIRQHook = M48IRQ;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 2,943 | C | .c | 104 | 26.365385 | 86 | 0.696391 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
1,201,610 | vrc7p.c | libretro_libretro-fceumm/src/boards/vrc7p.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2009 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* YOKO Mortal Kombat V Pro, VRC7 pirate clone
*/
#include "mapinc.h"
static uint8 prg[3], chr[8], mirr;
static uint8 IRQLatch, IRQa, IRQd;
static int32 IRQCount, CycleCount;
static SFORMAT StateRegs[] =
{
{ prg, 3, "PRG" },
{ chr, 8, "CHR" },
{ &mirr, 1, "MIRR" },
{ &IRQa, 1, "IRQA" },
{ &IRQd, 1, "IRQD" },
{ &IRQLatch, 1, "IRQL" },
{ &IRQCount, 4, "IRQC" },
{ &CycleCount, 4, "CYCC" },
{ 0 }
};
static void Sync(void) {
uint8 i;
setprg8(0x8000, prg[0]);
setprg8(0xa000, prg[1]);
setprg8(0xc000, prg[2]);
setprg8(0xe000, ~0);
for (i = 0; i < 8; i++)
setchr1(i << 10, chr[i]);
switch (mirr & 3) {
case 0: setmirror(MI_V); break;
case 1: setmirror(MI_H); break;
case 2: setmirror(MI_0); break;
case 3: setmirror(MI_1); break;
}
}
static DECLFW(UNLVRC7Write) {
switch (A & 0xF008) {
case 0x8000: prg[0] = V; Sync(); break;
case 0x8008: prg[1] = V; Sync(); break;
case 0x9000: prg[2] = V; Sync(); break;
case 0xa000: chr[0] = V; Sync(); break;
case 0xa008: chr[1] = V; Sync(); break;
case 0xb000: chr[2] = V; Sync(); break;
case 0xb008: chr[3] = V; Sync(); break;
case 0xc000: chr[4] = V; Sync(); break;
case 0xc008: chr[5] = V; Sync(); break;
case 0xd000: chr[6] = V; Sync(); break;
case 0xd008: chr[7] = V; Sync(); break;
case 0xe000: mirr = V; Sync(); break;
case 0xe008: IRQLatch = V; X6502_IRQEnd(FCEU_IQEXT); break;
case 0xf000:
IRQa = V & 2;
IRQd = V & 1;
if (V & 2)
IRQCount = IRQLatch;
CycleCount = 0;
X6502_IRQEnd(FCEU_IQEXT);
break;
case 0xf008:
if (IRQd)
IRQa = 1;
else
IRQa = 0;
X6502_IRQEnd(FCEU_IQEXT);
break;
}
}
static void UNLVRC7Power(void) {
Sync();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, UNLVRC7Write);
}
static void UNLVRC7IRQHook(int a) {
if (IRQa) {
CycleCount += a * 3;
while (CycleCount >= 341) {
CycleCount -= 341;
IRQCount++;
if (IRQCount == 248) {
IRQCount = IRQLatch;
X6502_IRQBegin(FCEU_IQEXT);
}
}
}
}
static void StateRestore(int version) {
Sync();
}
void UNLVRC7_Init(CartInfo *info) {
info->Power = UNLVRC7Power;
MapIRQHook = UNLVRC7IRQHook;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 3,021 | C | .c | 111 | 25.009009 | 81 | 0.673906 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
1,201,622 | vrc1.c | libretro_libretro-fceumm/src/boards/vrc1.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2012 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* VRC-1
*
*/
#include "mapinc.h"
static uint8 preg[3], creg[2], mode;
static SFORMAT StateRegs[] =
{
{ &mode, 1, "MODE" },
{ creg, 2, "CREG" },
{ preg, 3, "PREG" },
{ 0 }
};
static void Sync(void) {
setprg8(0x8000, preg[0]);
setprg8(0xA000, preg[1]);
setprg8(0xC000, preg[2]);
setprg8(0xE000, ~0);
setchr4(0x0000, creg[0] | ((mode & 2) << 3));
setchr4(0x1000, creg[1] | ((mode & 4) << 2));
setmirror((mode & 1) ^ 1);
}
static DECLFW(M75Write) {
switch (A & 0xF000) {
case 0x8000: preg[0] = V; Sync(); break;
case 0x9000: mode = V; Sync(); break;
case 0xA000: preg[1] = V; Sync(); break;
case 0xC000: preg[2] = V; Sync(); break;
case 0xE000: creg[0] = V & 0xF; Sync(); break;
case 0xF000: creg[1] = V & 0xF; Sync(); break;
}
}
static void M75Power(void) {
Sync();
SetWriteHandler(0x8000, 0xFFFF, M75Write);
SetReadHandler(0x8000, 0xFFFF, CartBR);
}
static void StateRestore(int version) {
Sync();
}
void Mapper75_Init(CartInfo *info) {
info->Power = M75Power;
AddExState(&StateRegs, ~0, 0, 0);
GameStateRestore = StateRestore;
}
| 1,892 | C | .c | 63 | 28.174603 | 81 | 0.696487 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
1,201,624 | 88.c | libretro_libretro-fceumm/src/boards/88.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 reg[8];
static uint8 mirror, cmd, is154;
static SFORMAT StateRegs[] =
{
{ &cmd, 1, "CMD" },
{ &mirror, 1, "MIRR" },
{ reg, 8, "REGS" },
{ 0 }
};
static void Sync(void) {
setchr2(0x0000, reg[0] >> 1);
setchr2(0x0800, reg[1] >> 1);
setchr1(0x1000, reg[2] | 0x40);
setchr1(0x1400, reg[3] | 0x40);
setchr1(0x1800, reg[4] | 0x40);
setchr1(0x1C00, reg[5] | 0x40);
setprg8(0x8000, reg[6]);
setprg8(0xA000, reg[7]);
setprg8(0xC000, ~1);
setprg8(0xE000, ~0);
}
static void MSync(void) {
if (is154) setmirror(MI_0 + (mirror & 1));
}
static DECLFW(M88Write) {
switch (A & 0x8001) {
case 0x8000: cmd = V & 7; mirror = V >> 6; MSync(); break;
case 0x8001: reg[cmd] = V; Sync(); break;
}
}
static void M88Power(void) {
reg[0] = reg[1] = reg[2] = reg[3] = reg[4] = reg[5] = reg[6] = reg[7] = 0;
Sync();
MSync();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, M88Write);
}
static void StateRestore(int version) {
Sync();
MSync();
}
void Mapper88_Init(CartInfo *info) {
is154 = 0;
info->Power = M88Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
void Mapper154_Init(CartInfo *info) {
is154 = 1;
info->Power = M88Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 2,130 | C | .c | 73 | 27.328767 | 81 | 0.698583 | libretro/libretro-fceumm | 125 | 113 | 40 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
1,292,859 | blittable.c | libretro_libretro-uae/sources/src/blittable.c | #include "sysconfig.h"
#include "sysdeps.h"
#include "options.h"
#include "custom.h"
#include "memory.h"
#include "blitter.h"
#include "blitfunc.h"
blitter_func * const blitfunc_dofast[256] = {
blitdofast_0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_a, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_2a, 0, 0, 0, 0, 0,
blitdofast_30, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_3a, 0, blitdofast_3c, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_4a, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_6a, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_8a, 0, blitdofast_8c, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_9a, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
blitdofast_a8, 0, blitdofast_aa, 0, 0, 0, 0, 0,
0, blitdofast_b1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_ca, 0, blitdofast_cc, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
blitdofast_d8, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_e2, 0, 0, 0, 0, 0,
0, 0, blitdofast_ea, 0, 0, 0, 0, 0,
blitdofast_f0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_fa, 0, blitdofast_fc, 0, 0, 0
};
blitter_func * const blitfunc_dofast_desc[256] = {
blitdofast_desc_0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_desc_a, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_desc_2a, 0, 0, 0, 0, 0,
blitdofast_desc_30, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_desc_3a, 0, blitdofast_desc_3c, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_desc_4a, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_desc_6a, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_desc_8a, 0, blitdofast_desc_8c, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_desc_9a, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
blitdofast_desc_a8, 0, blitdofast_desc_aa, 0, 0, 0, 0, 0,
0, blitdofast_desc_b1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_desc_ca, 0, blitdofast_desc_cc, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
blitdofast_desc_d8, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_desc_e2, 0, 0, 0, 0, 0,
0, 0, blitdofast_desc_ea, 0, 0, 0, 0, 0,
blitdofast_desc_f0, 0, 0, 0, 0, 0, 0, 0,
0, 0, blitdofast_desc_fa, 0, blitdofast_desc_fc, 0, 0, 0
};
| 2,560 | C | .c | 75 | 31.253333 | 59 | 0.506247 | libretro/libretro-uae | 112 | 60 | 28 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | false | false | true | true | false | false | false |
1,292,891 | def_icons.c | libretro_libretro-uae/sources/src/def_icons.c | unsigned char def_drawer[] = {
0xe3, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x19,
0x00, 0x05, 0x00, 0x03, 0x00, 0x01, 0x10, 0x12, 0x15, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00,
0x00, 0x00, 0x10, 0x25, 0xa6, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32,
0x00, 0x32, 0x01, 0x90, 0x00, 0x64, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x02, 0x7f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x28, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x18, 0x00, 0x01,
0x00, 0x06, 0xfc, 0x4c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xf0, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xf0, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x39, 0xff, 0xff, 0xff, 0xff, 0xff,
0xfe, 0x70, 0x39, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x70, 0x39, 0xff, 0xff, 0xff, 0xff, 0xff,
0xfe, 0x70, 0x39, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x70, 0x39, 0xff, 0xff, 0x9f, 0xe7, 0xff,
0xfe, 0x70, 0x39, 0xff, 0xff, 0x9f, 0xe7, 0xff, 0xfe, 0x70, 0x39, 0xff, 0xff, 0x80, 0x07, 0xff,
0xfe, 0x70, 0x39, 0xff, 0xff, 0x80, 0x07, 0xff, 0xfe, 0x70, 0x39, 0xff, 0xff, 0xff, 0xff, 0xff,
0xfe, 0x70, 0x39, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x70, 0x39, 0xff, 0xff, 0xff, 0xff, 0xff,
0xfe, 0x70, 0x39, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x70, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x70, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xf0, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
unsigned int def_drawer_len = 352;
unsigned char def_tool[] = {
0xe3, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x00, 0x17,
0x00, 0x04, 0x00, 0x01, 0x00, 0x01, 0x10, 0x12, 0xdc, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x33, 0x00, 0x16, 0x00, 0x02, 0x00, 0x06, 0xe8, 0xf8, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
0x80, 0x00, 0x3c, 0x0f, 0xf0, 0x00, 0x1f, 0xff, 0x80, 0x00, 0x3d, 0xf7, 0xcf, 0xff, 0xe3, 0xff,
0x80, 0x00, 0x3d, 0xf8, 0x3f, 0xff, 0xfc, 0x7f, 0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xff, 0x9f,
0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xef, 0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xf7,
0x80, 0x00, 0x3d, 0xf8, 0x3f, 0xff, 0xe0, 0x07, 0x80, 0x00, 0x3d, 0xf7, 0xdf, 0xff, 0xdf, 0xff,
0x80, 0x00, 0x3c, 0x0f, 0xe7, 0xff, 0x3f, 0xff, 0x80, 0x00, 0x3f, 0xff, 0xf9, 0xfc, 0xff, 0xff,
0x80, 0x00, 0x3f, 0xff, 0xfd, 0xfd, 0xff, 0xff, 0x80, 0x00, 0x3f, 0xff, 0xfd, 0xfd, 0xff, 0xff,
0x80, 0x00, 0x3f, 0xff, 0xfd, 0xfd, 0xff, 0xff, 0x80, 0x00, 0x3f, 0xff, 0xfc, 0x01, 0xff, 0xff,
0x80, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00
};
unsigned int def_tool_len = 450;
unsigned char def_project[] = {
0xe3, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x00, 0x15,
0x00, 0x04, 0x00, 0x01, 0x00, 0x01, 0x10, 0x14, 0x47, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x31, 0x00, 0x14, 0x00, 0x01, 0x00, 0x03, 0x61, 0x34, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
0x80, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xfe, 0xbf,
0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xfe, 0xdf, 0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xfe, 0xef,
0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xfe, 0x07, 0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xf7,
0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xf7, 0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xf7,
0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xf7, 0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xf7,
0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xf7, 0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xf7,
0x80, 0x00, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xf7, 0x80, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x07,
0x80, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
0x80, 0x00
};
unsigned int def_project_len = 258;
| 6,629 | C | .c | 77 | 84.220779 | 96 | 0.66855 | libretro/libretro-uae | 112 | 60 | 28 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,292,915 | gencpu_mini.c | libretro_libretro-uae/sources/src/gencpu_mini.c | /*
* UAE - The Un*x Amiga Emulator
*
* MC68000 emulation generator
*
* This is a fairly stupid program that generates a lot of case labels that
* can be #included in a switch statement.
* As an alternative, it can generate functions that handle specific
* MC68000 instructions, plus a prototype header file and a function pointer
* array to look up the function for an opcode.
* Error checking is bad, an illegal table68k file will cause the program to
* call abort().
* The generated code is sometimes sub-optimal, an optimizing compiler should
* take care of this.
*
* The source for the insn timings is Markt & Technik's Amiga Magazin 8/1992.
*
* Copyright 1995, 1996, 1997, 1998, 1999, 2000 Bernd Schmidt
*/
#include "sysconfig.h"
#include "sysdeps.h"
#include <ctype.h>
#include "readcpu.h"
#define BOOL_TYPE "int"
static FILE *headerfile;
static FILE *stblfile;
static int using_prefetch;
static int using_exception_3;
static int cpu_level;
/* For the current opcode, the next lower level that will have different code.
* Initialized to -1 for each opcode. If it remains unchanged, indicates we
* are done with that opcode. */
static int next_cpu_level;
static int *opcode_map;
static int *opcode_next_clev;
static int *opcode_last_postfix;
static unsigned long *counts;
static void read_counts (void)
{
FILE *file;
unsigned long opcode, count, total;
char name[20];
int nr = 0;
memset (counts, 0, 65536 * sizeof *counts);
file = fopen ("frequent.68k", "r");
if (file) {
fscanf (file, "Total: %lu\n", &total);
while (fscanf (file, "%lx: %lu %s\n", &opcode, &count, name) == 3) {
opcode_next_clev[nr] = 5;
opcode_last_postfix[nr] = -1;
opcode_map[nr++] = opcode;
counts[opcode] = count;
}
fclose (file);
}
if (nr == nr_cpuop_funcs)
return;
for (opcode = 0; opcode < 0x10000; opcode++) {
if (table68k[opcode].handler == -1 && table68k[opcode].mnemo != i_ILLG
&& counts[opcode] == 0)
{
opcode_next_clev[nr] = 5;
opcode_last_postfix[nr] = -1;
opcode_map[nr++] = opcode;
counts[opcode] = count;
}
}
if (nr != nr_cpuop_funcs)
abort ();
}
static char endlabelstr[80];
static int endlabelno = 0;
static int need_endlabel;
static int n_braces = 0;
static int m68k_pc_offset = 0;
static void start_brace (void)
{
n_braces++;
printf ("{");
}
static void close_brace (void)
{
assert (n_braces > 0);
n_braces--;
printf ("}");
}
static void finish_braces (void)
{
while (n_braces > 0)
close_brace ();
}
static void pop_braces (int to)
{
while (n_braces > to)
close_brace ();
}
static int bit_size (int size)
{
switch (size) {
case sz_byte: return 8;
case sz_word: return 16;
case sz_long: return 32;
default: abort ();
}
return 0;
}
static const char *bit_mask (int size)
{
switch (size) {
case sz_byte: return "0xff";
case sz_word: return "0xffff";
case sz_long: return "0xffffffff";
default: abort ();
}
return 0;
}
static const char *gen_nextilong (void)
{
static char buffer[80];
int r = m68k_pc_offset;
m68k_pc_offset += 4;
sprintf (buffer, "xget_ilong (%d)", r);
return buffer;
}
static const char *gen_nextiword (void)
{
static char buffer[80];
int r = m68k_pc_offset;
m68k_pc_offset += 2;
sprintf (buffer, "xget_iword (%d)", r);
return buffer;
}
static const char *gen_nextibyte (void)
{
static char buffer[80];
int r = m68k_pc_offset;
m68k_pc_offset += 2;
sprintf (buffer, "xget_ibyte (%d)", r);
return buffer;
}
static void sync_m68k_pc (void)
{
if (m68k_pc_offset == 0)
return;
printf ("xm68k_incpc(%d);\n", m68k_pc_offset);
m68k_pc_offset = 0;
}
/* getv == 1: fetch data; getv != 0: check for odd address. If movem != 0,
* the calling routine handles Apdi and Aipi modes.
* gb-- movem == 2 means the same thing but for a MOVE16 instruction */
static void genamode (amodes mode, char *reg, wordsizes size, char *name, int getv, int movem)
{
start_brace ();
switch (mode) {
case Dreg:
if (movem)
abort ();
if (getv == 1)
switch (size) {
case sz_byte:
#if defined(AMIGA) && !defined(WARPUP)
/* sam: I don't know why gcc.2.7.2.1 produces a code worse */
/* if it is not done like that: */
printf ("\tuae_s8 %s = ((uae_u8*)&m68k_dreg (regs, %s))[3];\n", name, reg);
#else
printf ("\tuae_s8 %s = xm68k_dreg (%s);\n", name, reg);
#endif
break;
case sz_word:
#if defined(AMIGA) && !defined(WARPUP)
printf ("\tuae_s16 %s = ((uae_s16*)&m68k_dreg (regs, %s))[1];\n", name, reg);
#else
printf ("\tuae_s16 %s = xm68k_dreg (%s);\n", name, reg);
#endif
break;
case sz_long:
printf ("\tuae_s32 %s = xm68k_dreg (%s);\n", name, reg);
break;
default:
abort ();
}
return;
case Areg:
if (movem)
abort ();
if (getv == 1)
switch (size) {
case sz_word:
printf ("\tuae_s16 %s = xm68k_areg (%s);\n", name, reg);
break;
case sz_long:
printf ("\tuae_s32 %s = xm68k_areg (%s);\n", name, reg);
break;
default:
abort ();
}
return;
case Aind:
printf ("\tuaecptr %sa = xm68k_areg (%s);\n", name, reg);
break;
case Aipi:
printf ("\tuaecptr %sa = xm68k_areg (%s);\n", name, reg);
break;
case Apdi:
switch (size) {
case sz_byte:
if (movem)
printf ("\tuaecptr %sa = xm68k_areg (%s);\n", name, reg);
else
printf ("\tuaecptr %sa = xm68k_areg (%s) - xareg_byteinc[%s];\n", name, reg, reg);
break;
case sz_word:
printf ("\tuaecptr %sa = xm68k_areg (%s) - %d;\n", name, reg, movem ? 0 : 2);
break;
case sz_long:
printf ("\tuaecptr %sa = xm68k_areg (%s) - %d;\n", name, reg, movem ? 0 : 4);
break;
default:
abort ();
}
break;
case Ad16:
printf ("\tuaecptr %sa = xm68k_areg (%s) + (uae_s32)(uae_s16)%s;\n", name, reg, gen_nextiword ());
break;
case Ad8r:
if (cpu_level > 1) {
if (next_cpu_level < 1)
next_cpu_level = 1;
sync_m68k_pc ();
start_brace ();
/* This would ordinarily be done in gen_nextiword, which we bypass. */
printf ("\tuaecptr %sa = xget_disp_ea_020 (xm68k_areg (%s), xnext_iword ());\n", name, reg);
} else
printf ("\tuaecptr %sa = xget_disp_ea_000 (xm68k_areg (%s), %s);\n", name, reg, gen_nextiword ());
break;
case PC16:
printf ("\tuaecptr %sa = xm68k_getpc () + %d;\n", name, m68k_pc_offset);
printf ("\t%sa += (uae_s32)(uae_s16)%s;\n", name, gen_nextiword ());
break;
case PC8r:
if (cpu_level > 1) {
if (next_cpu_level < 1)
next_cpu_level = 1;
sync_m68k_pc ();
start_brace ();
/* This would ordinarily be done in gen_nextiword, which we bypass. */
printf ("\tuaecptr tmppc = xm68k_getpc ();\n");
printf ("\tuaecptr %sa = xget_disp_ea_020(tmppc, xnext_iword ());\n", name);
} else {
printf ("\tuaecptr tmppc = xm68k_getpc () + %d;\n", m68k_pc_offset);
printf ("\tuaecptr %sa = xget_disp_ea_000 (tmppc, %s);\n", name, gen_nextiword ());
}
break;
case absw:
printf ("\tuaecptr %sa = (uae_s32)(uae_s16)%s;\n", name, gen_nextiword ());
break;
case absl:
printf ("\tuaecptr %sa = %s;\n", name, gen_nextilong ());
break;
case imm:
if (getv != 1)
abort ();
switch (size) {
case sz_byte:
printf ("\tuae_s8 %s = %s;\n", name, gen_nextibyte ());
break;
case sz_word:
printf ("\tuae_s16 %s = %s;\n", name, gen_nextiword ());
break;
case sz_long:
printf ("\tuae_s32 %s = %s;\n", name, gen_nextilong ());
break;
default:
abort ();
}
return;
case imm0:
if (getv != 1)
abort ();
printf ("\tuae_s8 %s = %s;\n", name, gen_nextibyte ());
return;
case imm1:
if (getv != 1)
abort ();
printf ("\tuae_s16 %s = %s;\n", name, gen_nextiword ());
return;
case imm2:
if (getv != 1)
abort ();
printf ("\tuae_s32 %s = %s;\n", name, gen_nextilong ());
return;
case immi:
if (getv != 1)
abort ();
printf ("\tuae_u32 %s = %s;\n", name, reg);
return;
default:
abort ();
}
if (getv == 1) {
start_brace ();
switch (size) {
case sz_byte: printf ("\tuae_s8 %s = xget_byte (%sa);\n", name, name); break;
case sz_word: printf ("\tuae_s16 %s = xget_word (%sa);\n", name, name); break;
case sz_long: printf ("\tuae_s32 %s = xget_long (%sa);\n", name, name); break;
default: abort ();
}
}
/* We now might have to fix up the register for pre-dec or post-inc
* addressing modes. */
if (!movem)
switch (mode) {
case Aipi:
switch (size) {
case sz_byte:
printf ("\txm68k_areg (%s) += xareg_byteinc[%s];\n", reg, reg);
break;
case sz_word:
printf ("\txm68k_areg (%s) += 2;\n", reg);
break;
case sz_long:
printf ("\txm68k_areg (%s) += 4;\n", reg);
break;
default:
abort ();
}
break;
case Apdi:
printf ("\txm68k_areg (%s) = %sa;\n", reg, name);
break;
default:
break;
}
}
static void genastore (char *from, amodes mode, char *reg, wordsizes size, char *to)
{
switch (mode) {
case Dreg:
switch (size) {
case sz_byte:
printf ("\txm68k_dreg (%s) = (xm68k_dreg (%s) & ~0xff) | ((%s) & 0xff);\n", reg, reg, from);
break;
case sz_word:
printf ("\txm68k_dreg (%s) = (xm68k_dreg (%s) & ~0xffff) | ((%s) & 0xffff);\n", reg, reg, from);
break;
case sz_long:
printf ("\txm68k_dreg (%s) = (%s);\n", reg, from);
break;
default:
abort ();
}
break;
case Areg:
switch (size) {
case sz_word:
printf ("\txm68k_areg (%s) = (uae_s32)(uae_s16)(%s);\n", reg, from);
break;
case sz_long:
printf ("\txm68k_areg (%s) = (%s);\n", reg, from);
break;
default:
abort ();
}
break;
case Aind:
case Aipi:
case Apdi:
case Ad16:
case Ad8r:
case absw:
case absl:
case PC16:
case PC8r:
if (using_prefetch)
sync_m68k_pc ();
switch (size) {
case sz_byte:
printf ("\txput_byte (%sa,%s);\n", to, from);
break;
case sz_word:
if (cpu_level < 2 && (mode == PC16 || mode == PC8r))
abort ();
printf ("\txput_word (%sa,%s);\n", to, from);
break;
case sz_long:
if (cpu_level < 2 && (mode == PC16 || mode == PC8r))
abort ();
printf ("\txput_long (%sa,%s);\n", to, from);
break;
default:
abort ();
}
break;
case imm:
case imm0:
case imm1:
case imm2:
case immi:
abort ();
break;
default:
abort ();
}
}
static void genmovemel (uae_u16 opcode)
{
char getcode[100];
int size = table68k[opcode].size == sz_long ? 4 : 2;
if (table68k[opcode].size == sz_long) {
strcpy (getcode, "xget_long (srca)");
} else {
strcpy (getcode, "(uae_s32)(uae_s16)xget_word (srca)");
}
printf ("\tuae_u16 mask = %s;\n", gen_nextiword ());
printf ("\tunsigned int dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n");
genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1);
start_brace ();
printf ("\twhile (dmask) { xm68k_dreg (xmovem_index1[dmask]) = %s; srca += %d; dmask = xmovem_next[dmask]; }\n",
getcode, size);
printf ("\twhile (amask) { xm68k_areg (xmovem_index1[amask]) = %s; srca += %d; amask = xmovem_next[amask]; }\n",
getcode, size);
if (table68k[opcode].dmode == Aipi)
printf ("\txm68k_areg (dstreg) = srca;\n");
}
static void genmovemle (uae_u16 opcode)
{
char putcode[100];
int size = table68k[opcode].size == sz_long ? 4 : 2;
if (table68k[opcode].size == sz_long) {
strcpy (putcode, "xput_long (srca,");
} else {
strcpy (putcode, "xput_word (srca,");
}
printf ("\tuae_u16 mask = %s;\n", gen_nextiword ());
genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1);
if (using_prefetch)
sync_m68k_pc ();
start_brace ();
if (table68k[opcode].dmode == Apdi) {
printf ("\tuae_u16 amask = mask & 0xff, dmask = (mask >> 8) & 0xff;\n");
printf ("\twhile (amask) { srca -= %d; %s xm68k_areg (xmovem_index2[amask])); amask = xmovem_next[amask]; }\n",
size, putcode);
printf ("\twhile (dmask) { srca -= %d; %s xm68k_dreg (xmovem_index2[dmask])); dmask = xmovem_next[dmask]; }\n",
size, putcode);
printf ("\txm68k_areg (dstreg) = srca;\n");
} else {
printf ("\tuae_u16 dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n");
printf ("\twhile (dmask) { %s xm68k_dreg (xmovem_index1[dmask])); srca += %d; dmask = xmovem_next[dmask]; }\n",
putcode, size);
printf ("\twhile (amask) { %s xm68k_areg (xmovem_index1[amask])); srca += %d; amask = xmovem_next[amask]; }\n",
putcode, size);
}
}
static void duplicate_carry (void)
{
printf ("\tXCOPY_CARRY;\n");
}
typedef enum
{
flag_logical_noclobber, flag_logical, flag_add, flag_sub, flag_cmp, flag_addx, flag_subx, flag_zn,
flag_av, flag_sv
}
flagtypes;
static void genflags_normal (flagtypes type, wordsizes size, char *value, char *src, char *dst)
{
char vstr[100], sstr[100], dstr[100];
char usstr[100], udstr[100];
char unsstr[100], undstr[100];
switch (size) {
case sz_byte:
strcpy (vstr, "((uae_s8)(");
strcpy (usstr, "((uae_u8)(");
break;
case sz_word:
strcpy (vstr, "((uae_s16)(");
strcpy (usstr, "((uae_u16)(");
break;
case sz_long:
strcpy (vstr, "((uae_s32)(");
strcpy (usstr, "((uae_u32)(");
break;
default:
abort ();
}
strcpy (unsstr, usstr);
strcpy (sstr, vstr);
strcpy (dstr, vstr);
strcat (vstr, value);
strcat (vstr, "))");
strcat (dstr, dst);
strcat (dstr, "))");
strcat (sstr, src);
strcat (sstr, "))");
strcpy (udstr, usstr);
strcat (udstr, dst);
strcat (udstr, "))");
strcat (usstr, src);
strcat (usstr, "))");
strcpy (undstr, unsstr);
strcat (unsstr, "-");
strcat (undstr, "~");
strcat (undstr, dst);
strcat (undstr, "))");
strcat (unsstr, src);
strcat (unsstr, "))");
switch (type) {
case flag_logical_noclobber:
case flag_logical:
case flag_zn:
case flag_av:
case flag_sv:
case flag_addx:
case flag_subx:
break;
case flag_add:
start_brace ();
printf ("uae_u32 %s = %s + %s;\n", value, dstr, sstr);
break;
case flag_sub:
case flag_cmp:
start_brace ();
printf ("uae_u32 %s = %s - %s;\n", value, dstr, sstr);
break;
}
switch (type) {
case flag_logical_noclobber:
case flag_logical:
case flag_zn:
break;
case flag_add:
case flag_sub:
case flag_addx:
case flag_subx:
case flag_cmp:
case flag_av:
case flag_sv:
start_brace ();
printf ("\t" BOOL_TYPE " flgs = %s < 0;\n", sstr);
printf ("\t" BOOL_TYPE " flgo = %s < 0;\n", dstr);
printf ("\t" BOOL_TYPE " flgn = %s < 0;\n", vstr);
break;
}
switch (type) {
case flag_logical:
printf ("\tXCLEAR_CZNV;\n");
printf ("\tXSET_ZFLG (%s == 0);\n", vstr);
printf ("\tXSET_NFLG (%s < 0);\n", vstr);
break;
case flag_logical_noclobber:
printf ("\tXSET_ZFLG (%s == 0);\n", vstr);
printf ("\tXSET_NFLG (%s < 0);\n", vstr);
break;
case flag_av:
printf ("\tXSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n");
break;
case flag_sv:
printf ("\tXSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n");
break;
case flag_zn:
printf ("\tXSET_ZFLG (XGET_ZFLG & (%s == 0));\n", vstr);
printf ("\tXSET_NFLG (%s < 0);\n", vstr);
break;
case flag_add:
printf ("\tXSET_ZFLG (%s == 0);\n", vstr);
printf ("\tXSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n");
printf ("\tXSET_CFLG (%s < %s);\n", undstr, usstr);
duplicate_carry ();
printf ("\tXSET_NFLG (flgn != 0);\n");
break;
case flag_sub:
printf ("\tXSET_ZFLG (%s == 0);\n", vstr);
printf ("\tXSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n");
printf ("\tXSET_CFLG (%s > %s);\n", usstr, udstr);
duplicate_carry ();
printf ("\tXSET_NFLG (flgn != 0);\n");
break;
case flag_addx:
printf ("\tXSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n"); /* minterm SON: 0x42 */
printf ("\tXSET_CFLG (flgs ^ ((flgs ^ flgo) & (flgo ^ flgn)));\n"); /* minterm SON: 0xD4 */
duplicate_carry ();
break;
case flag_subx:
printf ("\tXSET_VFLG ((flgs ^ flgo) & (flgo ^ flgn));\n"); /* minterm SON: 0x24 */
printf ("\tXSET_CFLG (flgs ^ ((flgs ^ flgn) & (flgo ^ flgn)));\n"); /* minterm SON: 0xB2 */
duplicate_carry ();
break;
case flag_cmp:
printf ("\tXSET_ZFLG (%s == 0);\n", vstr);
printf ("\tXSET_VFLG ((flgs != flgo) && (flgn != flgo));\n");
printf ("\tXSET_CFLG (%s > %s);\n", usstr, udstr);
printf ("\tXSET_NFLG (flgn != 0);\n");
break;
}
}
static void genflags (flagtypes type, wordsizes size, char *value, char *src, char *dst)
{
/* Temporarily deleted 68k/ARM flag optimizations. I'd prefer to have
them in the appropriate m68k.h files and use just one copy of this
code here. The API can be changed if necessary. */
#ifdef OPTIMIZED_FLAGS
switch (type) {
case flag_add:
case flag_sub:
start_brace ();
printf ("\tuae_u32 %s;\n", value);
break;
default:
break;
}
/* At least some of those casts are fairly important! */
switch (type) {
case flag_logical_noclobber:
printf ("\t{uae_u32 oldcznv = GET_CZNV & ~(FLAGVAL_Z | FLAGVAL_N);\n");
if (strcmp (value, "0") == 0) {
printf ("\tSET_CZNV (olcznv | FLAGVAL_Z);\n");
} else {
switch (size) {
case sz_byte: printf ("\toptflag_testb ((uae_s8)(%s));\n", value); break;
case sz_word: printf ("\toptflag_testw ((uae_s16)(%s));\n", value); break;
case sz_long: printf ("\toptflag_testl ((uae_s32)(%s));\n", value); break;
}
printf ("\tIOR_CZNV (oldcznv);\n");
}
printf ("\t}\n");
return;
case flag_logical:
if (strcmp (value, "0") == 0) {
printf ("\tSET_CZNV (FLAGVAL_Z);\n");
} else {
switch (size) {
case sz_byte: printf ("\toptflag_testb ((uae_s8)(%s));\n", value); break;
case sz_word: printf ("\toptflag_testw ((uae_s16)(%s));\n", value); break;
case sz_long: printf ("\toptflag_testl ((uae_s32)(%s));\n", value); break;
}
}
return;
case flag_add:
switch (size) {
case sz_byte: printf ("\toptflag_addb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break;
case sz_word: printf ("\toptflag_addw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break;
case sz_long: printf ("\toptflag_addl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break;
}
return;
case flag_sub:
switch (size) {
case sz_byte: printf ("\toptflag_subb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break;
case sz_word: printf ("\toptflag_subw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break;
case sz_long: printf ("\toptflag_subl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break;
}
return;
case flag_cmp:
switch (size) {
case sz_byte: printf ("\toptflag_cmpb ((uae_s8)(%s), (uae_s8)(%s));\n", src, dst); break;
case sz_word: printf ("\toptflag_cmpw ((uae_s16)(%s), (uae_s16)(%s));\n", src, dst); break;
case sz_long: printf ("\toptflag_cmpl ((uae_s32)(%s), (uae_s32)(%s));\n", src, dst); break;
}
return;
default:
break;
}
#endif
genflags_normal (type, size, value, src, dst);
}
static void force_range_for_rox (const char *var, wordsizes size)
{
/* Could do a modulo operation here... which one is faster? */
switch (size) {
case sz_long:
printf ("\tif (%s >= 33) %s -= 33;\n", var, var);
break;
case sz_word:
printf ("\tif (%s >= 34) %s -= 34;\n", var, var);
printf ("\tif (%s >= 17) %s -= 17;\n", var, var);
break;
case sz_byte:
printf ("\tif (%s >= 36) %s -= 36;\n", var, var);
printf ("\tif (%s >= 18) %s -= 18;\n", var, var);
printf ("\tif (%s >= 9) %s -= 9;\n", var, var);
break;
}
}
static const char *cmask (wordsizes size)
{
switch (size) {
case sz_byte: return "0x80";
case sz_word: return "0x8000";
case sz_long: return "0x80000000";
default: abort ();
}
}
static int source_is_imm1_8 (struct instr *i)
{
return i->stype == 3;
}
static void gen_opcode (unsigned long int opcode)
{
struct instr *curi = table68k + opcode;
switch (curi->plev) {
case 0: /* not privileged */
break;
case 1: /* unprivileged only on 68000 */
if (cpu_level == 0)
break;
if (next_cpu_level < 0)
next_cpu_level = 0;
/* fall through */
case 2:
case 3:
return;
}
m68k_pc_offset = 2;
start_brace ();
switch (curi->mnemo) {
case i_OR:
case i_AND:
case i_EOR:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
printf ("\tsrc %c= dst;\n", curi->mnemo == i_OR ? '|' : curi->mnemo == i_AND ? '&' : '^');
genflags (flag_logical, curi->size, "src", "", "");
genastore ("src", curi->dmode, "dstreg", curi->size, "dst");
break;
case i_SUB:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
start_brace ();
genflags (flag_sub, curi->size, "newv", "src", "dst");
genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
break;
case i_SUBA:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
start_brace ();
printf ("\tuae_u32 newv = dst - src;\n");
genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
break;
case i_SUBX:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
start_brace ();
printf ("\tuae_u32 newv = dst - src - (XGET_XFLG ? 1 : 0);\n");
genflags (flag_subx, curi->size, "newv", "src", "dst");
genflags (flag_zn, curi->size, "newv", "", "");
genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
break;
case i_SBCD:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
start_brace ();
printf ("\tuae_u16 newv_lo = (dst & 0xF) - (src & 0xF) - (XGET_XFLG ? 1 : 0);\n");
printf ("\tuae_u16 newv_hi = (dst & 0xF0) - (src & 0xF0);\n");
printf ("\tuae_u16 newv, tmp_newv;\n");
printf ("\tint bcd = 0;\n");
printf ("\tnewv = tmp_newv = newv_hi + newv_lo;\n");
printf ("\tif (newv_lo & 0xF0) { newv -= 6; bcd = 6; };\n");
printf ("\tif ((((dst & 0xFF) - (src & 0xFF) - (XGET_XFLG ? 1 : 0)) & 0x100) > 0xFF) { newv -= 0x60; }\n");
printf ("\tXSET_CFLG ((((dst & 0xFF) - (src & 0xFF) - bcd - (XGET_XFLG ? 1 : 0)) & 0x300) > 0xFF);\n");
duplicate_carry ();
genflags (flag_zn, curi->size, "newv", "", "");
printf ("\tXSET_VFLG ((tmp_newv & 0x80) != 0 && (newv & 0x80) == 0);\n");
genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
break;
case i_ADD:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
start_brace ();
genflags (flag_add, curi->size, "newv", "src", "dst");
genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
break;
case i_ADDA:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
start_brace ();
printf ("\tuae_u32 newv = dst + src;\n");
genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
break;
case i_ADDX:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
start_brace ();
printf ("\tuae_u32 newv = dst + src + (XGET_XFLG ? 1 : 0);\n");
genflags (flag_addx, curi->size, "newv", "src", "dst");
genflags (flag_zn, curi->size, "newv", "", "");
genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
break;
case i_ABCD:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
start_brace ();
printf ("\tuae_u16 newv_lo = (src & 0xF) + (dst & 0xF) + (XGET_XFLG ? 1 : 0);\n");
printf ("\tuae_u16 newv_hi = (src & 0xF0) + (dst & 0xF0);\n");
printf ("\tuae_u16 newv, tmp_newv;\n");
printf ("\tint cflg;\n");
printf ("\tnewv = tmp_newv = newv_hi + newv_lo;");
printf ("\tif (newv_lo > 9) { newv += 6; }\n");
printf ("\tcflg = (newv & 0x3F0) > 0x90;\n");
printf ("\tif (cflg) newv += 0x60;\n");
printf ("\tXSET_CFLG (cflg);\n");
duplicate_carry ();
genflags (flag_zn, curi->size, "newv", "", "");
printf ("\tXSET_VFLG ((tmp_newv & 0x80) == 0 && (newv & 0x80) != 0);\n");
genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
break;
case i_NEG:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
start_brace ();
genflags (flag_sub, curi->size, "dst", "src", "0");
genastore ("dst", curi->smode, "srcreg", curi->size, "src");
break;
case i_NEGX:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
start_brace ();
printf ("\tuae_u32 newv = 0 - src - (XGET_XFLG ? 1 : 0);\n");
genflags (flag_subx, curi->size, "newv", "src", "0");
genflags (flag_zn, curi->size, "newv", "", "");
genastore ("newv", curi->smode, "srcreg", curi->size, "src");
break;
case i_NBCD:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
start_brace ();
printf ("\tuae_u16 newv_lo = - (src & 0xF) - (XGET_XFLG ? 1 : 0);\n");
printf ("\tuae_u16 newv_hi = - (src & 0xF0);\n");
printf ("\tuae_u16 newv;\n");
printf ("\tint cflg;\n");
printf ("\tif (newv_lo > 9) { newv_lo -= 6; }\n");
printf ("\tnewv = newv_hi + newv_lo;");
printf ("\tcflg = (newv & 0x1F0) > 0x90;\n");
printf ("\tif (cflg) newv -= 0x60;\n");
printf ("\tXSET_CFLG (cflg);\n");
duplicate_carry();
genflags (flag_zn, curi->size, "newv", "", "");
genastore ("newv", curi->smode, "srcreg", curi->size, "src");
break;
case i_CLR:
genamode (curi->smode, "srcreg", curi->size, "src", 2, 0);
genflags (flag_logical, curi->size, "0", "", "");
genastore ("0", curi->smode, "srcreg", curi->size, "src");
break;
case i_NOT:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
start_brace ();
printf ("\tuae_u32 dst = ~src;\n");
genflags (flag_logical, curi->size, "dst", "", "");
genastore ("dst", curi->smode, "srcreg", curi->size, "src");
break;
case i_TST:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genflags (flag_logical, curi->size, "src", "", "");
break;
case i_BTST:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
if (curi->size == sz_byte)
printf ("\tsrc &= 7;\n");
else
printf ("\tsrc &= 31;\n");
printf ("\tXSET_ZFLG (1 ^ ((dst >> src) & 1));\n");
break;
case i_BCHG:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
if (curi->size == sz_byte)
printf ("\tsrc &= 7;\n");
else
printf ("\tsrc &= 31;\n");
printf ("\tdst ^= (1 << src);\n");
printf ("\tXSET_ZFLG (((uae_u32)dst & (1 << src)) >> src);\n");
genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
break;
case i_BCLR:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
if (curi->size == sz_byte)
printf ("\tsrc &= 7;\n");
else
printf ("\tsrc &= 31;\n");
printf ("\tXSET_ZFLG (1 ^ ((dst >> src) & 1));\n");
printf ("\tdst &= ~(1 << src);\n");
genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
break;
case i_BSET:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
if (curi->size == sz_byte)
printf ("\tsrc &= 7;\n");
else
printf ("\tsrc &= 31;\n");
printf ("\tXSET_ZFLG (1 ^ ((dst >> src) & 1));\n");
printf ("\tdst |= (1 << src);\n");
genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
break;
case i_CMPM:
case i_CMP:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
start_brace ();
genflags (flag_cmp, curi->size, "newv", "src", "dst");
break;
case i_CMPA:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
start_brace ();
genflags (flag_cmp, sz_long, "newv", "src", "dst");
break;
/* The next two are coded a little unconventional, but they are doing
* weird things... */
case i_MVPRM:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
printf ("\tuaecptr memp = xm68k_areg (dstreg) + (uae_s32)(uae_s16)%s;\n", gen_nextiword ());
if (curi->size == sz_word) {
printf ("\txput_byte (memp, src >> 8); xput_byte (memp + 2, src);\n");
} else {
printf ("\txput_byte (memp, src >> 24); xput_byte (memp + 2, src >> 16);\n");
printf ("\txput_byte (memp + 4, src >> 8); xput_byte (memp + 6, src);\n");
}
break;
case i_MVPMR:
printf ("\tuaecptr memp = xm68k_areg (srcreg) + (uae_s32)(uae_s16)%s;\n", gen_nextiword ());
genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
if (curi->size == sz_word) {
printf ("\tuae_u16 val = (xget_byte (memp) << 8) + xget_byte (memp + 2);\n");
} else {
printf ("\tuae_u32 val = (xget_byte (memp) << 24) + (xget_byte (memp + 2) << 16)\n");
printf (" + (xget_byte (memp + 4) << 8) + xget_byte (memp + 6);\n");
}
genastore ("val", curi->dmode, "dstreg", curi->size, "dst");
break;
case i_MOVE:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
genflags (flag_logical, curi->size, "src", "", "");
genastore ("src", curi->dmode, "dstreg", curi->size, "dst");
break;
case i_MOVEA:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
if (curi->size == sz_word) {
printf ("\tuae_u32 val = (uae_s32)(uae_s16)src;\n");
} else {
printf ("\tuae_u32 val = src;\n");
}
genastore ("val", curi->dmode, "dstreg", sz_long, "dst");
break;
case i_SWAP:
genamode (curi->smode, "srcreg", sz_long, "src", 1, 0);
start_brace ();
printf ("\tuae_u32 dst = ((src >> 16)&0xFFFF) | ((src&0xFFFF)<<16);\n");
genflags (flag_logical, sz_long, "dst", "", "");
genastore ("dst", curi->smode, "srcreg", sz_long, "src");
break;
case i_EXG:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
genastore ("dst", curi->smode, "srcreg", curi->size, "src");
genastore ("src", curi->dmode, "dstreg", curi->size, "dst");
break;
case i_EXT:
genamode (curi->smode, "srcreg", sz_long, "src", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u32 dst = (uae_s32)(uae_s8)src;\n"); break;
case sz_word: printf ("\tuae_u16 dst = (uae_s16)(uae_s8)src;\n"); break;
case sz_long: printf ("\tuae_u32 dst = (uae_s32)(uae_s16)src;\n"); break;
default: abort ();
}
genflags (flag_logical,
curi->size == sz_word ? sz_word : sz_long, "dst", "", "");
genastore ("dst", curi->smode, "srcreg",
curi->size == sz_word ? sz_word : sz_long, "src");
break;
case i_MVMEL:
genmovemel (opcode);
break;
case i_MVMLE:
genmovemle (opcode);
break;
case i_NOP:
break;
case i_LINK:
genamode (Apdi, "7", sz_long, "old", 2, 0);
genamode (curi->smode, "srcreg", sz_long, "src", 1, 0);
genastore ("src", Apdi, "7", sz_long, "old");
genastore ("xm68k_areg (7)", curi->smode, "srcreg", sz_long, "src");
genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0);
printf ("\txm68k_areg (7) += offs;\n");
break;
case i_UNLK:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
printf ("\txm68k_areg (7) = src;\n");
genamode (Aipi, "7", sz_long, "old", 1, 0);
genastore ("old", curi->smode, "srcreg", curi->size, "src");
break;
case i_RTS:
printf ("\txm68k_setpc (xget_long (xm68k_areg (7)));\n");
printf ("\txm68k_areg (7) += 4;\n");
m68k_pc_offset = 0;
break;
case i_JSR:
genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
printf ("\txm68k_areg (7) -= 4;\n");
printf ("\txput_long (xm68k_areg (7), xm68k_getpc () + %d);\n", m68k_pc_offset);
printf ("\txm68k_setpc (srca);\n");
m68k_pc_offset = 0;
break;
case i_JMP:
genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
printf ("\txm68k_setpc (srca);\n");
m68k_pc_offset = 0;
break;
case i_BSR:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
printf ("\tuae_s32 s = (uae_s32)src + 2;\n");
printf ("\txm68k_areg (7) -= 4;\n");
printf ("\txput_long (xm68k_areg (7), xm68k_getpc () + %d);\n", m68k_pc_offset);
printf ("\txm68k_incpc(s);\n");
m68k_pc_offset = 0;
break;
case i_Bcc:
if (curi->size == sz_long) {
if (next_cpu_level < 1)
next_cpu_level = 1;
}
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
printf ("\tif (!xcctrue(%d)) goto didnt_jump;\n", curi->cc);
printf ("\txm68k_incpc ((uae_s32)src + 2);\n");
printf ("\treturn;\n");
printf ("didnt_jump:;\n");
need_endlabel = 1;
break;
case i_LEA:
genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
genastore ("srca", curi->dmode, "dstreg", curi->size, "dst");
break;
case i_PEA:
genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
genamode (Apdi, "7", sz_long, "dst", 2, 0);
genastore ("srca", Apdi, "7", sz_long, "dst");
break;
case i_DBcc:
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0);
printf ("\tif (!xcctrue(%d)) {\n", curi->cc);
genastore ("(src-1)", curi->smode, "srcreg", curi->size, "src");
printf ("\t\tif (src) {\n");
printf ("\t\t\txm68k_incpc((uae_s32)offs + 2);\n");
printf ("\t\t}\n");
printf ("\t}\n");
need_endlabel = 1;
break;
case i_Scc:
genamode (curi->smode, "srcreg", curi->size, "src", 2, 0);
start_brace ();
printf ("\tint val = xcctrue(%d) ? 0xff : 0;\n", curi->cc);
genastore ("val", curi->smode, "srcreg", curi->size, "src");
break;
case i_DIVU:
printf ("\tuaecptr oldpc = xm68k_getpc ();\n");
genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
sync_m68k_pc ();
start_brace ();
/* Clear V flag when dividing by zero - Alcatraz Odyssey demo depends
* on this (actually, it's doing a DIVS). */
printf ("\tuae_u32 newv = (uae_u32)dst / (uae_u32)(uae_u16)src;\n");
printf ("\tuae_u32 rem = (uae_u32)dst %% (uae_u32)(uae_u16)src;\n");
/* The N flag appears to be set each time there is an overflow.
* Weird. */
printf ("\tif (newv > 0xffff) { XSET_VFLG (1); XSET_NFLG (1); XSET_CFLG (0); } else\n\t{\n");
genflags (flag_logical, sz_word, "newv", "", "");
printf ("\tnewv = (newv & 0xffff) | ((uae_u32)rem << 16);\n");
genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
printf ("\t}\n");
need_endlabel = 1;
break;
case i_DIVS:
printf ("\tuaecptr oldpc = xm68k_getpc ();\n");
genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
sync_m68k_pc ();
start_brace ();
printf ("\tuae_s32 newv = (uae_s32)dst / (uae_s32)(uae_s16)src;\n");
printf ("\tuae_u16 rem = (uae_s32)dst %% (uae_s32)(uae_s16)src;\n");
printf ("\tif ((newv & 0xffff8000) != 0 && (newv & 0xffff8000) != 0xffff8000) { XSET_VFLG (1); XSET_NFLG (1); XSET_CFLG (0); } else\n\t{\n");
printf ("\tif (((uae_s16)rem < 0) != ((uae_s32)dst < 0)) rem = -rem;\n");
genflags (flag_logical, sz_word, "newv", "", "");
printf ("\tnewv = (newv & 0xffff) | ((uae_u32)rem << 16);\n");
genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
printf ("\t}\n");
need_endlabel = 1;
break;
case i_MULU:
genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
genamode (curi->dmode, "dstreg", sz_word, "dst", 1, 0);
start_brace ();
printf ("\tuae_u32 newv = (uae_u32)(uae_u16)dst * (uae_u32)(uae_u16)src;\n");
genflags (flag_logical, sz_long, "newv", "", "");
genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
break;
case i_MULS:
genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
genamode (curi->dmode, "dstreg", sz_word, "dst", 1, 0);
start_brace ();
printf ("\tuae_u32 newv = (uae_s32)(uae_s16)dst * (uae_s32)(uae_s16)src;\n");
genflags (flag_logical, sz_long, "newv", "", "");
genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
break;
case i_ASR:
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tuae_u32 sign = (%s & val) >> %d;\n", cmask (curi->size), bit_size (curi->size) - 1);
printf ("\tcnt &= 63;\n");
printf ("\tXCLEAR_CZNV;\n");
printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
printf ("\t\tval = %s & (uae_u32)-sign;\n", bit_mask (curi->size));
printf ("\t\tXSET_CFLG (sign);\n");
duplicate_carry ();
if (source_is_imm1_8 (curi))
printf ("\t} else {\n");
else
printf ("\t} else if (cnt > 0) {\n");
printf ("\t\tval >>= cnt - 1;\n");
printf ("\t\tXSET_CFLG (val & 1);\n");
duplicate_carry ();
printf ("\t\tval >>= 1;\n");
printf ("\t\tval |= (%s << (%d - cnt)) & (uae_u32)-sign;\n",
bit_mask (curi->size),
bit_size (curi->size));
printf ("\t\tval &= %s;\n", bit_mask (curi->size));
printf ("\t}\n");
genflags (flag_logical_noclobber, curi->size, "val", "", "");
genastore ("val", curi->dmode, "dstreg", curi->size, "data");
break;
case i_ASL:
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tcnt &= 63;\n");
printf ("\tXCLEAR_CZNV;\n");
printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
printf ("\t\tXSET_VFLG (val != 0);\n");
printf ("\t\tXSET_CFLG (cnt == %d ? val & 1 : 0);\n",
bit_size (curi->size));
duplicate_carry ();
printf ("\t\tval = 0;\n");
if (source_is_imm1_8 (curi))
printf ("\t} else {\n");
else
printf ("\t} else if (cnt > 0) {\n");
printf ("\t\tuae_u32 mask = (%s << (%d - cnt)) & %s;\n",
bit_mask (curi->size),
bit_size (curi->size) - 1,
bit_mask (curi->size));
printf ("\t\tXSET_VFLG ((val & mask) != mask && (val & mask) != 0);\n");
printf ("\t\tval <<= cnt - 1;\n");
printf ("\t\tXSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
duplicate_carry ();
printf ("\t\tval <<= 1;\n");
printf ("\t\tval &= %s;\n", bit_mask (curi->size));
printf ("\t}\n");
genflags (flag_logical_noclobber, curi->size, "val", "", "");
genastore ("val", curi->dmode, "dstreg", curi->size, "data");
break;
case i_LSR:
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tcnt &= 63;\n");
printf ("\tXCLEAR_CZNV;\n");
printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
printf ("\t\tXSET_CFLG ((cnt == %d) & (val >> %d));\n",
bit_size (curi->size), bit_size (curi->size) - 1);
duplicate_carry ();
printf ("\t\tval = 0;\n");
if (source_is_imm1_8 (curi))
printf ("\t} else {\n");
else
printf ("\t} else if (cnt > 0) {\n");
printf ("\t\tval >>= cnt - 1;\n");
printf ("\t\tXSET_CFLG (val & 1);\n");
duplicate_carry ();
printf ("\t\tval >>= 1;\n");
printf ("\t}\n");
genflags (flag_logical_noclobber, curi->size, "val", "", "");
genastore ("val", curi->dmode, "dstreg", curi->size, "data");
break;
case i_LSL:
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tcnt &= 63;\n");
printf ("\tXCLEAR_CZNV;\n");
printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
printf ("\t\tXSET_CFLG (cnt == %d ? val & 1 : 0);\n",
bit_size (curi->size));
duplicate_carry ();
printf ("\t\tval = 0;\n");
if (source_is_imm1_8 (curi))
printf ("\t} else {\n");
else
printf ("\t} else if (cnt > 0) {\n");
printf ("\t\tval <<= (cnt - 1);\n");
printf ("\t\tXSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
duplicate_carry ();
printf ("\t\tval <<= 1;\n");
printf ("\tval &= %s;\n", bit_mask (curi->size));
printf ("\t}\n");
genflags (flag_logical_noclobber, curi->size, "val", "", "");
genastore ("val", curi->dmode, "dstreg", curi->size, "data");
break;
case i_ROL:
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tcnt &= 63;\n");
printf ("\tXCLEAR_CZNV;\n");
if (source_is_imm1_8 (curi))
printf ("{");
else
printf ("\tif (cnt > 0) {\n");
printf ("\tuae_u32 loval;\n");
printf ("\tcnt &= %d;\n", bit_size (curi->size) - 1);
printf ("\tloval = val >> (%d - cnt);\n", bit_size (curi->size));
printf ("\tval <<= cnt;\n");
printf ("\tval |= loval;\n");
printf ("\tval &= %s;\n", bit_mask (curi->size));
printf ("\tXSET_CFLG (val & 1);\n");
printf ("}\n");
genflags (flag_logical_noclobber, curi->size, "val", "", "");
genastore ("val", curi->dmode, "dstreg", curi->size, "data");
break;
case i_ROR:
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tcnt &= 63;\n");
printf ("\tXCLEAR_CZNV;\n");
if (source_is_imm1_8 (curi))
printf ("{");
else
printf ("\tif (cnt > 0) {");
printf ("\tuae_u32 hival;\n");
printf ("\tcnt &= %d;\n", bit_size (curi->size) - 1);
printf ("\thival = val << (%d - cnt);\n", bit_size (curi->size));
printf ("\tval >>= cnt;\n");
printf ("\tval |= hival;\n");
printf ("\tval &= %s;\n", bit_mask (curi->size));
printf ("\tXSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
printf ("\t}\n");
genflags (flag_logical_noclobber, curi->size, "val", "", "");
genastore ("val", curi->dmode, "dstreg", curi->size, "data");
break;
case i_ROXL:
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tcnt &= 63;\n");
printf ("\tXCLEAR_CZNV;\n");
if (source_is_imm1_8 (curi))
printf ("{");
else {
force_range_for_rox ("cnt", curi->size);
printf ("\tif (cnt > 0) {\n");
}
printf ("\tcnt--;\n");
printf ("\t{\n\tuae_u32 carry;\n");
printf ("\tuae_u32 loval = val >> (%d - cnt);\n", bit_size (curi->size) - 1);
printf ("\tcarry = loval & 1;\n");
printf ("\tval = (((val << 1) | XGET_XFLG) << cnt) | (loval >> 1);\n");
printf ("\tXSET_XFLG (carry);\n");
printf ("\tval &= %s;\n", bit_mask (curi->size));
printf ("\t} }\n");
printf ("\tXSET_CFLG (XGET_XFLG);\n");
genflags (flag_logical_noclobber, curi->size, "val", "", "");
genastore ("val", curi->dmode, "dstreg", curi->size, "data");
break;
case i_ROXR:
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tcnt &= 63;\n");
printf ("\tXCLEAR_CZNV;\n");
if (source_is_imm1_8 (curi))
printf ("{");
else {
force_range_for_rox ("cnt", curi->size);
printf ("\tif (cnt > 0) {\n");
}
printf ("\tcnt--;\n");
printf ("\t{\n\tuae_u32 carry;\n");
printf ("\tuae_u32 hival = (val << 1) | XGET_XFLG;\n");
printf ("\thival <<= (%d - cnt);\n", bit_size (curi->size) - 1);
printf ("\tval >>= cnt;\n");
printf ("\tcarry = val & 1;\n");
printf ("\tval >>= 1;\n");
printf ("\tval |= hival;\n");
printf ("\tXSET_XFLG (carry);\n");
printf ("\tval &= %s;\n", bit_mask (curi->size));
printf ("\t} }\n");
printf ("\tXSET_CFLG (XGET_XFLG);\n");
genflags (flag_logical_noclobber, curi->size, "val", "", "");
genastore ("val", curi->dmode, "dstreg", curi->size, "data");
break;
case i_ASRW:
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tuae_u32 sign = %s & val;\n", cmask (curi->size));
printf ("\tuae_u32 cflg = val & 1;\n");
printf ("\tval = (val >> 1) | sign;\n");
genflags (flag_logical, curi->size, "val", "", "");
printf ("\tXSET_CFLG (cflg);\n");
duplicate_carry ();
genastore ("val", curi->smode, "srcreg", curi->size, "data");
break;
case i_ASLW:
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tuae_u32 sign = %s & val;\n", cmask (curi->size));
printf ("\tuae_u32 sign2;\n");
printf ("\tval <<= 1;\n");
genflags (flag_logical, curi->size, "val", "", "");
printf ("\tsign2 = %s & val;\n", cmask (curi->size));
printf ("\tXSET_CFLG (sign != 0);\n");
duplicate_carry ();
printf ("\tXSET_VFLG (XGET_VFLG | (sign2 != sign));\n");
genastore ("val", curi->smode, "srcreg", curi->size, "data");
break;
case i_LSRW:
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tuae_u32 carry = val & 1;\n");
printf ("\tval >>= 1;\n");
genflags (flag_logical, curi->size, "val", "", "");
printf ("XSET_CFLG (carry);\n");
duplicate_carry ();
genastore ("val", curi->smode, "srcreg", curi->size, "data");
break;
case i_LSLW:
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
case sz_word: printf ("\tuae_u16 val = data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size));
printf ("\tval <<= 1;\n");
genflags (flag_logical, curi->size, "val", "", "");
printf ("XSET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1);
duplicate_carry ();
genastore ("val", curi->smode, "srcreg", curi->size, "data");
break;
case i_ROLW:
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
case sz_word: printf ("\tuae_u16 val = data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size));
printf ("\tval <<= 1;\n");
printf ("\tif (carry) val |= 1;\n");
genflags (flag_logical, curi->size, "val", "", "");
printf ("XSET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1);
genastore ("val", curi->smode, "srcreg", curi->size, "data");
break;
case i_RORW:
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
case sz_word: printf ("\tuae_u16 val = data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tuae_u32 carry = val & 1;\n");
printf ("\tval >>= 1;\n");
printf ("\tif (carry) val |= %s;\n", cmask (curi->size));
genflags (flag_logical, curi->size, "val", "", "");
printf ("XSET_CFLG (carry);\n");
genastore ("val", curi->smode, "srcreg", curi->size, "data");
break;
case i_ROXLW:
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
case sz_word: printf ("\tuae_u16 val = data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size));
printf ("\tval <<= 1;\n");
printf ("\tif (XGET_XFLG) val |= 1;\n");
genflags (flag_logical, curi->size, "val", "", "");
printf ("XSET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1);
duplicate_carry ();
genastore ("val", curi->smode, "srcreg", curi->size, "data");
break;
case i_ROXRW:
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
start_brace ();
switch (curi->size) {
case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
case sz_word: printf ("\tuae_u16 val = data;\n"); break;
case sz_long: printf ("\tuae_u32 val = data;\n"); break;
default: abort ();
}
printf ("\tuae_u32 carry = val & 1;\n");
printf ("\tval >>= 1;\n");
printf ("\tif (XGET_XFLG) val |= %s;\n", cmask (curi->size));
genflags (flag_logical, curi->size, "val", "", "");
printf ("XSET_CFLG (carry);\n");
duplicate_carry ();
genastore ("val", curi->smode, "srcreg", curi->size, "data");
break;
default:
m68k_pc_offset = 0;
break;
}
finish_braces ();
sync_m68k_pc ();
}
static int postfix;
static void generate_one_opcode (int rp)
{
int i;
uae_u16 smsk, dmsk;
long int opcode = opcode_map[rp];
if (table68k[opcode].mnemo == i_ILLG
|| table68k[opcode].clev > cpu_level)
return;
for (i = 0; lookuptab[i].name[0]; i++) {
if (table68k[opcode].mnemo == lookuptab[i].mnemo)
break;
}
if (table68k[opcode].handler != -1)
return;
if (opcode_next_clev[rp] != cpu_level) {
fprintf (stblfile, "{ xop_%lx_%d, %ld }, /* %s */\n", opcode, opcode_last_postfix[rp],
opcode, lookuptab[i].name);
return;
}
fprintf (stblfile, "{ xop_%lx_%d, %ld }, /* %s */\n", opcode, postfix, opcode, lookuptab[i].name);
fprintf (headerfile, "extern xcpuop_func xop_%lx_%d;\n", opcode, postfix);
printf ("void xop_%lx_%d(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name);
switch (table68k[opcode].stype) {
case 0: smsk = 7; break;
case 1: smsk = 255; break;
case 2: smsk = 15; break;
case 3: smsk = 7; break;
case 4: smsk = 7; break;
case 5: smsk = 63; break;
case 7: smsk = 3; break;
default: abort ();
}
dmsk = 7;
next_cpu_level = -1;
if (table68k[opcode].suse
&& table68k[opcode].smode != imm && table68k[opcode].smode != imm0
&& table68k[opcode].smode != imm1 && table68k[opcode].smode != imm2
&& table68k[opcode].smode != absw && table68k[opcode].smode != absl
&& table68k[opcode].smode != PC8r && table68k[opcode].smode != PC16)
{
if (table68k[opcode].spos == -1) {
if (((int) table68k[opcode].sreg) >= 128)
printf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%d;\n", (int) table68k[opcode].sreg);
else
printf ("\tuae_u32 srcreg = %d;\n", (int) table68k[opcode].sreg);
} else {
char source[100];
int pos = table68k[opcode].spos;
if (pos)
sprintf (source, "((opcode >> %d) & %d)", pos, smsk);
else
sprintf (source, "(opcode & %d)", smsk);
if (table68k[opcode].stype == 3)
printf ("\tuae_u32 srcreg = ximm8_table[%s];\n", source);
else if (table68k[opcode].stype == 1)
printf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%s;\n", source);
else
printf ("\tuae_u32 srcreg = %s;\n", source);
}
}
if (table68k[opcode].duse
/* Yes, the dmode can be imm, in case of LINK or DBcc */
&& table68k[opcode].dmode != imm && table68k[opcode].dmode != imm0
&& table68k[opcode].dmode != imm1 && table68k[opcode].dmode != imm2
&& table68k[opcode].dmode != absw && table68k[opcode].dmode != absl)
{
if (table68k[opcode].dpos == -1) {
if (((int) table68k[opcode].dreg) >= 128)
printf ("\tuae_u32 dstreg = (uae_s32)(uae_s8)%d;\n", (int) table68k[opcode].dreg);
else
printf ("\tuae_u32 dstreg = %d;\n", (int) table68k[opcode].dreg);
} else {
int pos = table68k[opcode].dpos;
#if 0
/* Check that we can do the little endian optimization safely. */
if (pos < 8 && (dmsk >> (8 - pos)) != 0)
abort ();
#endif
if (pos)
printf ("\tuae_u32 dstreg = (opcode >> %d) & %d;\n",
pos, dmsk);
else
printf ("\tuae_u32 dstreg = opcode & %d;\n", dmsk);
}
}
need_endlabel = 0;
endlabelno++;
sprintf (endlabelstr, "endlabel%d", endlabelno);
gen_opcode (opcode);
if (need_endlabel)
printf ("%s: ;\n", endlabelstr);
printf ("}\n");
opcode_next_clev[rp] = next_cpu_level;
opcode_last_postfix[rp] = postfix;
}
static void generate_func (void)
{
int i, j, rp;
using_prefetch = 0;
using_exception_3 = 0;
for (i = 0; i <= 0; i++) {
cpu_level = 5;
postfix = i;
fprintf (stblfile, "struct xcputbl xop_smalltbl_%d[] = {\n", postfix);
rp = 0;
for(j=1;j<=8;++j) {
int k = (j*nr_cpuop_funcs)/8;
for (; rp < k; rp++)
generate_one_opcode (rp);
}
fprintf (stblfile, "{ 0, 0 }};\n");
}
}
static void generate_includes (FILE * f)
{
fprintf (f, "#include \"cpu_small.h\"\n");
fprintf (f, "#include \"cputbl_small.h\"\n");
}
int main (int argc, char **argv)
{
read_table68k ();
do_merges ();
opcode_map = (int *) xmalloc (sizeof (int) * nr_cpuop_funcs);
opcode_last_postfix = (int *) xmalloc (sizeof (int) * nr_cpuop_funcs);
opcode_next_clev = (int *) xmalloc (sizeof (int) * nr_cpuop_funcs);
counts = (unsigned long *) xmalloc (65536 * sizeof (unsigned long));
read_counts ();
/* It would be a lot nicer to put all in one file (we'd also get rid of
* cputbl.h that way), but cpuopti can't cope. That could be fixed, but
* I don't dare to touch the 68k version. */
headerfile = fopen ("cputbl_small.h", "wb");
stblfile = fopen ("cpustbl_small.c", "wb");
generate_includes (stblfile);
freopen ("cpuemu_small.c", "wb", stdout);
generate_includes (stdout);
generate_func ();
free (table68k);
return 0;
}
| 55,396 | C | .c | 1,633 | 30.778934 | 142 | 0.58875 | libretro/libretro-uae | 112 | 60 | 28 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | false | false | true | true | false | false | false |
1,292,957 | tinyxml2.c | libretro_libretro-uae/sources/src/tinyxml2.c | /*
Original code by Lee Thomason (www.grinninglizard.com)
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.
*/
#include "tinyxml2.h"
#include <new> // yes, this one new style header, is in the Android SDK.
#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
# include <stddef.h>
# include <stdarg.h>
#else
# include <cstddef>
# include <cstdarg>
#endif
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
// Microsoft Visual Studio, version 2005 and higher. Not WinCE.
/*int _snprintf_s(
char *buffer,
size_t sizeOfBuffer,
size_t count,
const char *format [,
argument] ...
);*/
static inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
{
va_list va;
va_start( va, format );
const int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
va_end( va );
return result;
}
static inline int TIXML_VSNPRINTF( char* buffer, size_t size, const char* format, va_list va )
{
const int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
return result;
}
#define TIXML_VSCPRINTF _vscprintf
#define TIXML_SSCANF sscanf_s
#elif defined _MSC_VER
// Microsoft Visual Studio 2003 and earlier or WinCE
#define TIXML_SNPRINTF _snprintf
#define TIXML_VSNPRINTF _vsnprintf
#define TIXML_SSCANF sscanf
#if (_MSC_VER < 1400 ) && (!defined WINCE)
// Microsoft Visual Studio 2003 and not WinCE.
#define TIXML_VSCPRINTF _vscprintf // VS2003's C runtime has this, but VC6 C runtime or WinCE SDK doesn't have.
#else
// Microsoft Visual Studio 2003 and earlier or WinCE.
static inline int TIXML_VSCPRINTF( const char* format, va_list va )
{
int len = 512;
for (;;) {
len = len*2;
char* str = new char[len]();
const int required = _vsnprintf(str, len, format, va);
delete[] str;
if ( required != -1 ) {
TIXMLASSERT( required >= 0 );
len = required;
break;
}
}
TIXMLASSERT( len >= 0 );
return len;
}
#endif
#else
// GCC version 3 and higher
//#warning( "Using sn* functions." )
#define TIXML_SNPRINTF snprintf
#define TIXML_VSNPRINTF vsnprintf
static inline int TIXML_VSCPRINTF( const char* format, va_list va )
{
int len = vsnprintf( 0, 0, format, va );
TIXMLASSERT( len >= 0 );
return len;
}
#define TIXML_SSCANF sscanf
#endif
#if defined(_WIN64)
#define TIXML_FSEEK _fseeki64
#define TIXML_FTELL _ftelli64
#elif defined(__APPLE__) || (__FreeBSD__)
#define TIXML_FSEEK fseeko
#define TIXML_FTELL ftello
#elif defined(__unix__) && defined(__x86_64__)
#define TIXML_FSEEK fseeko64
#define TIXML_FTELL ftello64
#else
#define TIXML_FSEEK fseek
#define TIXML_FTELL ftell
#endif
static const char LINE_FEED = static_cast<char>(0x0a); // all line endings are normalized to LF
static const char LF = LINE_FEED;
static const char CARRIAGE_RETURN = static_cast<char>(0x0d); // CR gets filtered out
static const char CR = CARRIAGE_RETURN;
static const char SINGLE_QUOTE = '\'';
static const char DOUBLE_QUOTE = '\"';
// Bunch of unicode info at:
// http://www.unicode.org/faq/utf_bom.html
// ef bb bf (Microsoft "lead bytes") - designates UTF-8
static const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
static const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
namespace tinyxml2
{
struct Entity {
const char* pattern;
int length;
char value;
};
static const int NUM_ENTITIES = 5;
static const Entity entities[NUM_ENTITIES] = {
{ "quot", 4, DOUBLE_QUOTE },
{ "amp", 3, '&' },
{ "apos", 4, SINGLE_QUOTE },
{ "lt", 2, '<' },
{ "gt", 2, '>' }
};
StrPair::~StrPair()
{
Reset();
}
void StrPair::TransferTo( StrPair* other )
{
if ( this == other ) {
return;
}
// This in effect implements the assignment operator by "moving"
// ownership (as in auto_ptr).
TIXMLASSERT( other != 0 );
TIXMLASSERT( other->_flags == 0 );
TIXMLASSERT( other->_start == 0 );
TIXMLASSERT( other->_end == 0 );
other->Reset();
other->_flags = _flags;
other->_start = _start;
other->_end = _end;
_flags = 0;
_start = 0;
_end = 0;
}
void StrPair::Reset()
{
if ( _flags & NEEDS_DELETE ) {
delete [] _start;
}
_flags = 0;
_start = 0;
_end = 0;
}
void StrPair::SetStr( const char* str, int flags )
{
TIXMLASSERT( str );
Reset();
size_t len = strlen( str );
TIXMLASSERT( _start == 0 );
_start = new char[ len+1 ];
memcpy( _start, str, len+1 );
_end = _start + len;
_flags = flags | NEEDS_DELETE;
}
char* StrPair::ParseText( char* p, const char* endTag, int strFlags, int* curLineNumPtr )
{
TIXMLASSERT( p );
TIXMLASSERT( endTag && *endTag );
TIXMLASSERT(curLineNumPtr);
char* start = p;
const char endChar = *endTag;
size_t length = strlen( endTag );
// Inner loop of text parsing.
while ( *p ) {
if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) {
Set( start, p, strFlags );
return p + length;
} else if (*p == '\n') {
++(*curLineNumPtr);
}
++p;
TIXMLASSERT( p );
}
return 0;
}
char* StrPair::ParseName( char* p )
{
if ( !p || !(*p) ) {
return 0;
}
if ( !XMLUtil::IsNameStartChar( (unsigned char) *p ) ) {
return 0;
}
char* const start = p;
++p;
while ( *p && XMLUtil::IsNameChar( (unsigned char) *p ) ) {
++p;
}
Set( start, p, 0 );
return p;
}
void StrPair::CollapseWhitespace()
{
// Adjusting _start would cause undefined behavior on delete[]
TIXMLASSERT( ( _flags & NEEDS_DELETE ) == 0 );
// Trim leading space.
_start = XMLUtil::SkipWhiteSpace( _start, 0 );
if ( *_start ) {
const char* p = _start; // the read pointer
char* q = _start; // the write pointer
while( *p ) {
if ( XMLUtil::IsWhiteSpace( *p )) {
p = XMLUtil::SkipWhiteSpace( p, 0 );
if ( *p == 0 ) {
break; // don't write to q; this trims the trailing space.
}
*q = ' ';
++q;
}
*q = *p;
++q;
++p;
}
*q = 0;
}
}
const char* StrPair::GetStr()
{
TIXMLASSERT( _start );
TIXMLASSERT( _end );
if ( _flags & NEEDS_FLUSH ) {
*_end = 0;
_flags ^= NEEDS_FLUSH;
if ( _flags ) {
const char* p = _start; // the read pointer
char* q = _start; // the write pointer
while( p < _end ) {
if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) {
// CR-LF pair becomes LF
// CR alone becomes LF
// LF-CR becomes LF
if ( *(p+1) == LF ) {
p += 2;
}
else {
++p;
}
*q = LF;
++q;
}
else if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) {
if ( *(p+1) == CR ) {
p += 2;
}
else {
++p;
}
*q = LF;
++q;
}
else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) {
// Entities handled by tinyXML2:
// - special entities in the entity table [in/out]
// - numeric character reference [in]
// 中 or 中
if ( *(p+1) == '#' ) {
const int buflen = 10;
char buf[buflen] = { 0 };
int len = 0;
const char* adjusted = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );
if ( adjusted == 0 ) {
*q = *p;
++p;
++q;
}
else {
TIXMLASSERT( 0 <= len && len <= buflen );
TIXMLASSERT( q + len <= adjusted );
p = adjusted;
memcpy( q, buf, len );
q += len;
}
}
else {
bool entityFound = false;
for( int i = 0; i < NUM_ENTITIES; ++i ) {
const Entity& entity = entities[i];
if ( strncmp( p + 1, entity.pattern, entity.length ) == 0
&& *( p + entity.length + 1 ) == ';' ) {
// Found an entity - convert.
*q = entity.value;
++q;
p += entity.length + 2;
entityFound = true;
break;
}
}
if ( !entityFound ) {
// fixme: treat as error?
++p;
++q;
}
}
}
else {
*q = *p;
++p;
++q;
}
}
*q = 0;
}
// The loop below has plenty going on, and this
// is a less useful mode. Break it out.
if ( _flags & NEEDS_WHITESPACE_COLLAPSING ) {
CollapseWhitespace();
}
_flags = (_flags & NEEDS_DELETE);
}
TIXMLASSERT( _start );
return _start;
}
// --------- XMLUtil ----------- //
const char* XMLUtil::writeBoolTrue = "true";
const char* XMLUtil::writeBoolFalse = "false";
void XMLUtil::SetBoolSerialization(const char* writeTrue, const char* writeFalse)
{
static const char* defTrue = "true";
static const char* defFalse = "false";
writeBoolTrue = (writeTrue) ? writeTrue : defTrue;
writeBoolFalse = (writeFalse) ? writeFalse : defFalse;
}
const char* XMLUtil::ReadBOM( const char* p, bool* bom )
{
TIXMLASSERT( p );
TIXMLASSERT( bom );
*bom = false;
const unsigned char* pu = reinterpret_cast<const unsigned char*>(p);
// Check for BOM:
if ( *(pu+0) == TIXML_UTF_LEAD_0
&& *(pu+1) == TIXML_UTF_LEAD_1
&& *(pu+2) == TIXML_UTF_LEAD_2 ) {
*bom = true;
p += 3;
}
TIXMLASSERT( p );
return p;
}
void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length )
{
const unsigned long BYTE_MASK = 0xBF;
const unsigned long BYTE_MARK = 0x80;
const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
if (input < 0x80) {
*length = 1;
}
else if ( input < 0x800 ) {
*length = 2;
}
else if ( input < 0x10000 ) {
*length = 3;
}
else if ( input < 0x200000 ) {
*length = 4;
}
else {
*length = 0; // This code won't convert this correctly anyway.
return;
}
output += *length;
// Scary scary fall throughs are annotated with carefully designed comments
// to suppress compiler warnings such as -Wimplicit-fallthrough in gcc
switch (*length) {
case 4:
--output;
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
input >>= 6;
//fall through
case 3:
--output;
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
input >>= 6;
//fall through
case 2:
--output;
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
input >>= 6;
//fall through
case 1:
--output;
*output = static_cast<char>(input | FIRST_BYTE_MARK[*length]);
break;
default:
TIXMLASSERT( false );
}
}
const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
{
// Presume an entity, and pull it out.
*length = 0;
if ( *(p+1) == '#' && *(p+2) ) {
unsigned long ucs = 0;
TIXMLASSERT( sizeof( ucs ) >= 4 );
ptrdiff_t delta = 0;
unsigned mult = 1;
static const char SEMICOLON = ';';
if ( *(p+2) == 'x' ) {
// Hexadecimal.
const char* q = p+3;
if ( !(*q) ) {
return 0;
}
q = strchr( q, SEMICOLON );
if ( !q ) {
return 0;
}
TIXMLASSERT( *q == SEMICOLON );
delta = q-p;
--q;
while ( *q != 'x' ) {
unsigned int digit = 0;
if ( *q >= '0' && *q <= '9' ) {
digit = *q - '0';
}
else if ( *q >= 'a' && *q <= 'f' ) {
digit = *q - 'a' + 10;
}
else if ( *q >= 'A' && *q <= 'F' ) {
digit = *q - 'A' + 10;
}
else {
return 0;
}
TIXMLASSERT( digit < 16 );
TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
const unsigned int digitScaled = mult * digit;
TIXMLASSERT( ucs <= ULONG_MAX - digitScaled );
ucs += digitScaled;
TIXMLASSERT( mult <= UINT_MAX / 16 );
mult *= 16;
--q;
}
}
else {
// Decimal.
const char* q = p+2;
if ( !(*q) ) {
return 0;
}
q = strchr( q, SEMICOLON );
if ( !q ) {
return 0;
}
TIXMLASSERT( *q == SEMICOLON );
delta = q-p;
--q;
while ( *q != '#' ) {
if ( *q >= '0' && *q <= '9' ) {
const unsigned int digit = *q - '0';
TIXMLASSERT( digit < 10 );
TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
const unsigned int digitScaled = mult * digit;
TIXMLASSERT( ucs <= ULONG_MAX - digitScaled );
ucs += digitScaled;
}
else {
return 0;
}
TIXMLASSERT( mult <= UINT_MAX / 10 );
mult *= 10;
--q;
}
}
// convert the UCS to UTF-8
ConvertUTF32ToUTF8( ucs, value, length );
return p + delta + 1;
}
return p+1;
}
void XMLUtil::ToStr( int v, char* buffer, int bufferSize )
{
TIXML_SNPRINTF( buffer, bufferSize, "%d", v );
}
void XMLUtil::ToStr( unsigned v, char* buffer, int bufferSize )
{
TIXML_SNPRINTF( buffer, bufferSize, "%u", v );
}
void XMLUtil::ToStr( bool v, char* buffer, int bufferSize )
{
TIXML_SNPRINTF( buffer, bufferSize, "%s", v ? writeBoolTrue : writeBoolFalse);
}
/*
ToStr() of a number is a very tricky topic.
https://github.com/leethomason/tinyxml2/issues/106
*/
void XMLUtil::ToStr( float v, char* buffer, int bufferSize )
{
TIXML_SNPRINTF( buffer, bufferSize, "%.8g", v );
}
void XMLUtil::ToStr( double v, char* buffer, int bufferSize )
{
TIXML_SNPRINTF( buffer, bufferSize, "%.17g", v );
}
void XMLUtil::ToStr( int64_t v, char* buffer, int bufferSize )
{
// horrible syntax trick to make the compiler happy about %lld
TIXML_SNPRINTF(buffer, bufferSize, "%lld", static_cast<long long>(v));
}
void XMLUtil::ToStr( uint64_t v, char* buffer, int bufferSize )
{
// horrible syntax trick to make the compiler happy about %llu
TIXML_SNPRINTF(buffer, bufferSize, "%llu", (long long)v);
}
bool XMLUtil::ToInt(const char* str, int* value)
{
if (TIXML_SSCANF(str, IsPrefixHex(str) ? "%x" : "%d", value) == 1) {
return true;
}
return false;
}
bool XMLUtil::ToUnsigned(const char* str, unsigned* value)
{
if (TIXML_SSCANF(str, IsPrefixHex(str) ? "%x" : "%u", value) == 1) {
return true;
}
return false;
}
bool XMLUtil::ToBool( const char* str, bool* value )
{
int ival = 0;
if ( ToInt( str, &ival )) {
*value = (ival==0) ? false : true;
return true;
}
static const char* TRUE_VALS[] = { "true", "True", "TRUE", 0 };
static const char* FALSE_VALS[] = { "false", "False", "FALSE", 0 };
for (int i = 0; TRUE_VALS[i]; ++i) {
if (StringEqual(str, TRUE_VALS[i])) {
*value = true;
return true;
}
}
for (int i = 0; FALSE_VALS[i]; ++i) {
if (StringEqual(str, FALSE_VALS[i])) {
*value = false;
return true;
}
}
return false;
}
bool XMLUtil::ToFloat( const char* str, float* value )
{
if ( TIXML_SSCANF( str, "%f", value ) == 1 ) {
return true;
}
return false;
}
bool XMLUtil::ToDouble( const char* str, double* value )
{
if ( TIXML_SSCANF( str, "%lf", value ) == 1 ) {
return true;
}
return false;
}
bool XMLUtil::ToInt64(const char* str, int64_t* value)
{
long long v = 0; // horrible syntax trick to make the compiler happy about %lld
if (TIXML_SSCANF(str, IsPrefixHex(str) ? "%llx" : "%lld", &v) == 1) {
*value = static_cast<int64_t>(v);
return true;
}
return false;
}
bool XMLUtil::ToUnsigned64(const char* str, uint64_t* value) {
unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llu
if(TIXML_SSCANF(str, IsPrefixHex(str) ? "%llx" : "%llu", &v) == 1) {
*value = (uint64_t)v;
return true;
}
return false;
}
char* XMLDocument::Identify( char* p, XMLNode** node )
{
TIXMLASSERT( node );
TIXMLASSERT( p );
char* const start = p;
int const startLine = _parseCurLineNum;
p = XMLUtil::SkipWhiteSpace( p, &_parseCurLineNum );
if( !*p ) {
*node = 0;
TIXMLASSERT( p );
return p;
}
// These strings define the matching patterns:
static const char* xmlHeader = { "<?" };
static const char* commentHeader = { "<!--" };
static const char* cdataHeader = { "<![CDATA[" };
static const char* dtdHeader = { "<!" };
static const char* elementHeader = { "<" }; // and a header for everything else; check last.
static const int xmlHeaderLen = 2;
static const int commentHeaderLen = 4;
static const int cdataHeaderLen = 9;
static const int dtdHeaderLen = 2;
static const int elementHeaderLen = 1;
TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) ); // use same memory pool
TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool
XMLNode* returnNode = 0;
if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) {
returnNode = CreateUnlinkedNode<XMLDeclaration>( _commentPool );
returnNode->_parseLineNum = _parseCurLineNum;
p += xmlHeaderLen;
}
else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) {
returnNode = CreateUnlinkedNode<XMLComment>( _commentPool );
returnNode->_parseLineNum = _parseCurLineNum;
p += commentHeaderLen;
}
else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) {
XMLText* text = CreateUnlinkedNode<XMLText>( _textPool );
returnNode = text;
returnNode->_parseLineNum = _parseCurLineNum;
p += cdataHeaderLen;
text->SetCData( true );
}
else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) {
returnNode = CreateUnlinkedNode<XMLUnknown>( _commentPool );
returnNode->_parseLineNum = _parseCurLineNum;
p += dtdHeaderLen;
}
else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) {
returnNode = CreateUnlinkedNode<XMLElement>( _elementPool );
returnNode->_parseLineNum = _parseCurLineNum;
p += elementHeaderLen;
}
else {
returnNode = CreateUnlinkedNode<XMLText>( _textPool );
returnNode->_parseLineNum = _parseCurLineNum; // Report line of first non-whitespace character
p = start; // Back it up, all the text counts.
_parseCurLineNum = startLine;
}
TIXMLASSERT( returnNode );
TIXMLASSERT( p );
*node = returnNode;
return p;
}
bool XMLDocument::Accept( XMLVisitor* visitor ) const
{
TIXMLASSERT( visitor );
if ( visitor->VisitEnter( *this ) ) {
for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) {
if ( !node->Accept( visitor ) ) {
break;
}
}
}
return visitor->VisitExit( *this );
}
// --------- XMLNode ----------- //
XMLNode::XMLNode( XMLDocument* doc ) :
_document( doc ),
_parent( 0 ),
_value(),
_parseLineNum( 0 ),
_firstChild( 0 ), _lastChild( 0 ),
_prev( 0 ), _next( 0 ),
_userData( 0 ),
_memPool( 0 )
{
}
XMLNode::~XMLNode()
{
DeleteChildren();
if ( _parent ) {
_parent->Unlink( this );
}
}
const char* XMLNode::Value() const
{
// Edge case: XMLDocuments don't have a Value. Return null.
if ( this->ToDocument() )
return 0;
return _value.GetStr();
}
void XMLNode::SetValue( const char* str, bool staticMem )
{
if ( staticMem ) {
_value.SetInternedStr( str );
}
else {
_value.SetStr( str );
}
}
XMLNode* XMLNode::DeepClone(XMLDocument* target) const
{
XMLNode* clone = this->ShallowClone(target);
if (!clone) return 0;
for (const XMLNode* child = this->FirstChild(); child; child = child->NextSibling()) {
XMLNode* childClone = child->DeepClone(target);
TIXMLASSERT(childClone);
clone->InsertEndChild(childClone);
}
return clone;
}
void XMLNode::DeleteChildren()
{
while( _firstChild ) {
TIXMLASSERT( _lastChild );
DeleteChild( _firstChild );
}
_firstChild = _lastChild = 0;
}
void XMLNode::Unlink( XMLNode* child )
{
TIXMLASSERT( child );
TIXMLASSERT( child->_document == _document );
TIXMLASSERT( child->_parent == this );
if ( child == _firstChild ) {
_firstChild = _firstChild->_next;
}
if ( child == _lastChild ) {
_lastChild = _lastChild->_prev;
}
if ( child->_prev ) {
child->_prev->_next = child->_next;
}
if ( child->_next ) {
child->_next->_prev = child->_prev;
}
child->_next = 0;
child->_prev = 0;
child->_parent = 0;
}
void XMLNode::DeleteChild( XMLNode* node )
{
TIXMLASSERT( node );
TIXMLASSERT( node->_document == _document );
TIXMLASSERT( node->_parent == this );
Unlink( node );
TIXMLASSERT(node->_prev == 0);
TIXMLASSERT(node->_next == 0);
TIXMLASSERT(node->_parent == 0);
DeleteNode( node );
}
XMLNode* XMLNode::InsertEndChild( XMLNode* addThis )
{
TIXMLASSERT( addThis );
if ( addThis->_document != _document ) {
TIXMLASSERT( false );
return 0;
}
InsertChildPreamble( addThis );
if ( _lastChild ) {
TIXMLASSERT( _firstChild );
TIXMLASSERT( _lastChild->_next == 0 );
_lastChild->_next = addThis;
addThis->_prev = _lastChild;
_lastChild = addThis;
addThis->_next = 0;
}
else {
TIXMLASSERT( _firstChild == 0 );
_firstChild = _lastChild = addThis;
addThis->_prev = 0;
addThis->_next = 0;
}
addThis->_parent = this;
return addThis;
}
XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis )
{
TIXMLASSERT( addThis );
if ( addThis->_document != _document ) {
TIXMLASSERT( false );
return 0;
}
InsertChildPreamble( addThis );
if ( _firstChild ) {
TIXMLASSERT( _lastChild );
TIXMLASSERT( _firstChild->_prev == 0 );
_firstChild->_prev = addThis;
addThis->_next = _firstChild;
_firstChild = addThis;
addThis->_prev = 0;
}
else {
TIXMLASSERT( _lastChild == 0 );
_firstChild = _lastChild = addThis;
addThis->_prev = 0;
addThis->_next = 0;
}
addThis->_parent = this;
return addThis;
}
XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis )
{
TIXMLASSERT( addThis );
if ( addThis->_document != _document ) {
TIXMLASSERT( false );
return 0;
}
TIXMLASSERT( afterThis );
if ( afterThis->_parent != this ) {
TIXMLASSERT( false );
return 0;
}
if ( afterThis == addThis ) {
// Current state: BeforeThis -> AddThis -> OneAfterAddThis
// Now AddThis must disappear from it's location and then
// reappear between BeforeThis and OneAfterAddThis.
// So just leave it where it is.
return addThis;
}
if ( afterThis->_next == 0 ) {
// The last node or the only node.
return InsertEndChild( addThis );
}
InsertChildPreamble( addThis );
addThis->_prev = afterThis;
addThis->_next = afterThis->_next;
afterThis->_next->_prev = addThis;
afterThis->_next = addThis;
addThis->_parent = this;
return addThis;
}
const XMLElement* XMLNode::FirstChildElement( const char* name ) const
{
for( const XMLNode* node = _firstChild; node; node = node->_next ) {
const XMLElement* element = node->ToElementWithName( name );
if ( element ) {
return element;
}
}
return 0;
}
const XMLElement* XMLNode::LastChildElement( const char* name ) const
{
for( const XMLNode* node = _lastChild; node; node = node->_prev ) {
const XMLElement* element = node->ToElementWithName( name );
if ( element ) {
return element;
}
}
return 0;
}
const XMLElement* XMLNode::NextSiblingElement( const char* name ) const
{
for( const XMLNode* node = _next; node; node = node->_next ) {
const XMLElement* element = node->ToElementWithName( name );
if ( element ) {
return element;
}
}
return 0;
}
const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const
{
for( const XMLNode* node = _prev; node; node = node->_prev ) {
const XMLElement* element = node->ToElementWithName( name );
if ( element ) {
return element;
}
}
return 0;
}
char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
{
// This is a recursive method, but thinking about it "at the current level"
// it is a pretty simple flat list:
// <foo/>
// <!-- comment -->
//
// With a special case:
// <foo>
// </foo>
// <!-- comment -->
//
// Where the closing element (/foo) *must* be the next thing after the opening
// element, and the names must match. BUT the tricky bit is that the closing
// element will be read by the child.
//
// 'endTag' is the end tag for this node, it is returned by a call to a child.
// 'parentEnd' is the end tag for the parent, which is filled in and returned.
XMLDocument::DepthTracker tracker(_document);
if (_document->Error())
return 0;
while( p && *p ) {
XMLNode* node = 0;
p = _document->Identify( p, &node );
TIXMLASSERT( p );
if ( node == 0 ) {
break;
}
const int initialLineNum = node->_parseLineNum;
StrPair endTag;
p = node->ParseDeep( p, &endTag, curLineNumPtr );
if ( !p ) {
DeleteNode( node );
if ( !_document->Error() ) {
_document->SetError( XML_ERROR_PARSING, initialLineNum, 0);
}
break;
}
const XMLDeclaration* const decl = node->ToDeclaration();
if ( decl ) {
// Declarations are only allowed at document level
//
// Multiple declarations are allowed but all declarations
// must occur before anything else.
//
// Optimized due to a security test case. If the first node is
// a declaration, and the last node is a declaration, then only
// declarations have so far been added.
bool wellLocated = false;
if (ToDocument()) {
if (FirstChild()) {
wellLocated =
FirstChild() &&
FirstChild()->ToDeclaration() &&
LastChild() &&
LastChild()->ToDeclaration();
}
else {
wellLocated = true;
}
}
if ( !wellLocated ) {
_document->SetError( XML_ERROR_PARSING_DECLARATION, initialLineNum, "XMLDeclaration value=%s", decl->Value());
DeleteNode( node );
break;
}
}
XMLElement* ele = node->ToElement();
if ( ele ) {
// We read the end tag. Return it to the parent.
if ( ele->ClosingType() == XMLElement::CLOSING ) {
if ( parentEndTag ) {
ele->_value.TransferTo( parentEndTag );
}
node->_memPool->SetTracked(); // created and then immediately deleted.
DeleteNode( node );
return p;
}
// Handle an end tag returned to this level.
// And handle a bunch of annoying errors.
bool mismatch = false;
if ( endTag.Empty() ) {
if ( ele->ClosingType() == XMLElement::OPEN ) {
mismatch = true;
}
}
else {
if ( ele->ClosingType() != XMLElement::OPEN ) {
mismatch = true;
}
else if ( !XMLUtil::StringEqual( endTag.GetStr(), ele->Name() ) ) {
mismatch = true;
}
}
if ( mismatch ) {
_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, "XMLElement name=%s", ele->Name());
DeleteNode( node );
break;
}
}
InsertEndChild( node );
}
return 0;
}
/*static*/ void XMLNode::DeleteNode( XMLNode* node )
{
if ( node == 0 ) {
return;
}
TIXMLASSERT(node->_document);
if (!node->ToDocument()) {
node->_document->MarkInUse(node);
}
MemPool* pool = node->_memPool;
node->~XMLNode();
pool->Free( node );
}
void XMLNode::InsertChildPreamble( XMLNode* insertThis ) const
{
TIXMLASSERT( insertThis );
TIXMLASSERT( insertThis->_document == _document );
if (insertThis->_parent) {
insertThis->_parent->Unlink( insertThis );
}
else {
insertThis->_document->MarkInUse(insertThis);
insertThis->_memPool->SetTracked();
}
}
const XMLElement* XMLNode::ToElementWithName( const char* name ) const
{
const XMLElement* element = this->ToElement();
if ( element == 0 ) {
return 0;
}
if ( name == 0 ) {
return element;
}
if ( XMLUtil::StringEqual( element->Name(), name ) ) {
return element;
}
return 0;
}
// --------- XMLText ---------- //
char* XMLText::ParseDeep( char* p, StrPair*, int* curLineNumPtr )
{
if ( this->CData() ) {
p = _value.ParseText( p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr );
if ( !p ) {
_document->SetError( XML_ERROR_PARSING_CDATA, _parseLineNum, 0 );
}
return p;
}
else {
int flags = _document->ProcessEntities() ? StrPair::TEXT_ELEMENT : StrPair::TEXT_ELEMENT_LEAVE_ENTITIES;
if ( _document->WhitespaceMode() == COLLAPSE_WHITESPACE ) {
flags |= StrPair::NEEDS_WHITESPACE_COLLAPSING;
}
p = _value.ParseText( p, "<", flags, curLineNumPtr );
if ( p && *p ) {
return p-1;
}
if ( !p ) {
_document->SetError( XML_ERROR_PARSING_TEXT, _parseLineNum, 0 );
}
}
return 0;
}
XMLNode* XMLText::ShallowClone( XMLDocument* doc ) const
{
if ( !doc ) {
doc = _document;
}
XMLText* text = doc->NewText( Value() ); // fixme: this will always allocate memory. Intern?
text->SetCData( this->CData() );
return text;
}
bool XMLText::ShallowEqual( const XMLNode* compare ) const
{
TIXMLASSERT( compare );
const XMLText* text = compare->ToText();
return ( text && XMLUtil::StringEqual( text->Value(), Value() ) );
}
bool XMLText::Accept( XMLVisitor* visitor ) const
{
TIXMLASSERT( visitor );
return visitor->Visit( *this );
}
// --------- XMLComment ---------- //
XMLComment::XMLComment( XMLDocument* doc ) : XMLNode( doc )
{
}
XMLComment::~XMLComment()
{
}
char* XMLComment::ParseDeep( char* p, StrPair*, int* curLineNumPtr )
{
// Comment parses as text.
p = _value.ParseText( p, "-->", StrPair::COMMENT, curLineNumPtr );
if ( p == 0 ) {
_document->SetError( XML_ERROR_PARSING_COMMENT, _parseLineNum, 0 );
}
return p;
}
XMLNode* XMLComment::ShallowClone( XMLDocument* doc ) const
{
if ( !doc ) {
doc = _document;
}
XMLComment* comment = doc->NewComment( Value() ); // fixme: this will always allocate memory. Intern?
return comment;
}
bool XMLComment::ShallowEqual( const XMLNode* compare ) const
{
TIXMLASSERT( compare );
const XMLComment* comment = compare->ToComment();
return ( comment && XMLUtil::StringEqual( comment->Value(), Value() ));
}
bool XMLComment::Accept( XMLVisitor* visitor ) const
{
TIXMLASSERT( visitor );
return visitor->Visit( *this );
}
// --------- XMLDeclaration ---------- //
XMLDeclaration::XMLDeclaration( XMLDocument* doc ) : XMLNode( doc )
{
}
XMLDeclaration::~XMLDeclaration()
{
//printf( "~XMLDeclaration\n" );
}
char* XMLDeclaration::ParseDeep( char* p, StrPair*, int* curLineNumPtr )
{
// Declaration parses as text.
p = _value.ParseText( p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr );
if ( p == 0 ) {
_document->SetError( XML_ERROR_PARSING_DECLARATION, _parseLineNum, 0 );
}
return p;
}
XMLNode* XMLDeclaration::ShallowClone( XMLDocument* doc ) const
{
if ( !doc ) {
doc = _document;
}
XMLDeclaration* dec = doc->NewDeclaration( Value() ); // fixme: this will always allocate memory. Intern?
return dec;
}
bool XMLDeclaration::ShallowEqual( const XMLNode* compare ) const
{
TIXMLASSERT( compare );
const XMLDeclaration* declaration = compare->ToDeclaration();
return ( declaration && XMLUtil::StringEqual( declaration->Value(), Value() ));
}
bool XMLDeclaration::Accept( XMLVisitor* visitor ) const
{
TIXMLASSERT( visitor );
return visitor->Visit( *this );
}
// --------- XMLUnknown ---------- //
XMLUnknown::XMLUnknown( XMLDocument* doc ) : XMLNode( doc )
{
}
XMLUnknown::~XMLUnknown()
{
}
char* XMLUnknown::ParseDeep( char* p, StrPair*, int* curLineNumPtr )
{
// Unknown parses as text.
p = _value.ParseText( p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr );
if ( !p ) {
_document->SetError( XML_ERROR_PARSING_UNKNOWN, _parseLineNum, 0 );
}
return p;
}
XMLNode* XMLUnknown::ShallowClone( XMLDocument* doc ) const
{
if ( !doc ) {
doc = _document;
}
XMLUnknown* text = doc->NewUnknown( Value() ); // fixme: this will always allocate memory. Intern?
return text;
}
bool XMLUnknown::ShallowEqual( const XMLNode* compare ) const
{
TIXMLASSERT( compare );
const XMLUnknown* unknown = compare->ToUnknown();
return ( unknown && XMLUtil::StringEqual( unknown->Value(), Value() ));
}
bool XMLUnknown::Accept( XMLVisitor* visitor ) const
{
TIXMLASSERT( visitor );
return visitor->Visit( *this );
}
// --------- XMLAttribute ---------- //
const char* XMLAttribute::Name() const
{
return _name.GetStr();
}
const char* XMLAttribute::Value() const
{
return _value.GetStr();
}
char* XMLAttribute::ParseDeep( char* p, bool processEntities, int* curLineNumPtr )
{
// Parse using the name rules: bug fix, was using ParseText before
p = _name.ParseName( p );
if ( !p || !*p ) {
return 0;
}
// Skip white space before =
p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr );
if ( *p != '=' ) {
return 0;
}
++p; // move up to opening quote
p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr );
if ( *p != '\"' && *p != '\'' ) {
return 0;
}
const char endTag[2] = { *p, 0 };
++p; // move past opening quote
p = _value.ParseText( p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES, curLineNumPtr );
return p;
}
void XMLAttribute::SetName( const char* n )
{
_name.SetStr( n );
}
XMLError XMLAttribute::QueryIntValue( int* value ) const
{
if ( XMLUtil::ToInt( Value(), value )) {
return XML_SUCCESS;
}
return XML_WRONG_ATTRIBUTE_TYPE;
}
XMLError XMLAttribute::QueryUnsignedValue( unsigned int* value ) const
{
if ( XMLUtil::ToUnsigned( Value(), value )) {
return XML_SUCCESS;
}
return XML_WRONG_ATTRIBUTE_TYPE;
}
XMLError XMLAttribute::QueryInt64Value(int64_t* value) const
{
if (XMLUtil::ToInt64(Value(), value)) {
return XML_SUCCESS;
}
return XML_WRONG_ATTRIBUTE_TYPE;
}
XMLError XMLAttribute::QueryUnsigned64Value(uint64_t* value) const
{
if(XMLUtil::ToUnsigned64(Value(), value)) {
return XML_SUCCESS;
}
return XML_WRONG_ATTRIBUTE_TYPE;
}
XMLError XMLAttribute::QueryBoolValue( bool* value ) const
{
if ( XMLUtil::ToBool( Value(), value )) {
return XML_SUCCESS;
}
return XML_WRONG_ATTRIBUTE_TYPE;
}
XMLError XMLAttribute::QueryFloatValue( float* value ) const
{
if ( XMLUtil::ToFloat( Value(), value )) {
return XML_SUCCESS;
}
return XML_WRONG_ATTRIBUTE_TYPE;
}
XMLError XMLAttribute::QueryDoubleValue( double* value ) const
{
if ( XMLUtil::ToDouble( Value(), value )) {
return XML_SUCCESS;
}
return XML_WRONG_ATTRIBUTE_TYPE;
}
void XMLAttribute::SetAttribute( const char* v )
{
_value.SetStr( v );
}
void XMLAttribute::SetAttribute( int v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
_value.SetStr( buf );
}
void XMLAttribute::SetAttribute( unsigned v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
_value.SetStr( buf );
}
void XMLAttribute::SetAttribute(int64_t v)
{
char buf[BUF_SIZE];
XMLUtil::ToStr(v, buf, BUF_SIZE);
_value.SetStr(buf);
}
void XMLAttribute::SetAttribute(uint64_t v)
{
char buf[BUF_SIZE];
XMLUtil::ToStr(v, buf, BUF_SIZE);
_value.SetStr(buf);
}
void XMLAttribute::SetAttribute( bool v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
_value.SetStr( buf );
}
void XMLAttribute::SetAttribute( double v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
_value.SetStr( buf );
}
void XMLAttribute::SetAttribute( float v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
_value.SetStr( buf );
}
// --------- XMLElement ---------- //
XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ),
_closingType( OPEN ),
_rootAttribute( 0 )
{
}
XMLElement::~XMLElement()
{
while( _rootAttribute ) {
XMLAttribute* next = _rootAttribute->_next;
DeleteAttribute( _rootAttribute );
_rootAttribute = next;
}
}
const XMLAttribute* XMLElement::FindAttribute( const char* name ) const
{
for( XMLAttribute* a = _rootAttribute; a; a = a->_next ) {
if ( XMLUtil::StringEqual( a->Name(), name ) ) {
return a;
}
}
return 0;
}
const char* XMLElement::Attribute( const char* name, const char* value ) const
{
const XMLAttribute* a = FindAttribute( name );
if ( !a ) {
return 0;
}
if ( !value || XMLUtil::StringEqual( a->Value(), value )) {
return a->Value();
}
return 0;
}
int XMLElement::IntAttribute(const char* name, int defaultValue) const
{
int i = defaultValue;
QueryIntAttribute(name, &i);
return i;
}
unsigned XMLElement::UnsignedAttribute(const char* name, unsigned defaultValue) const
{
unsigned i = defaultValue;
QueryUnsignedAttribute(name, &i);
return i;
}
int64_t XMLElement::Int64Attribute(const char* name, int64_t defaultValue) const
{
int64_t i = defaultValue;
QueryInt64Attribute(name, &i);
return i;
}
uint64_t XMLElement::Unsigned64Attribute(const char* name, uint64_t defaultValue) const
{
uint64_t i = defaultValue;
QueryUnsigned64Attribute(name, &i);
return i;
}
bool XMLElement::BoolAttribute(const char* name, bool defaultValue) const
{
bool b = defaultValue;
QueryBoolAttribute(name, &b);
return b;
}
double XMLElement::DoubleAttribute(const char* name, double defaultValue) const
{
double d = defaultValue;
QueryDoubleAttribute(name, &d);
return d;
}
float XMLElement::FloatAttribute(const char* name, float defaultValue) const
{
float f = defaultValue;
QueryFloatAttribute(name, &f);
return f;
}
const char* XMLElement::GetText() const
{
if ( FirstChild() && FirstChild()->ToText() ) {
return FirstChild()->Value();
}
return 0;
}
void XMLElement::SetText( const char* inText )
{
if ( FirstChild() && FirstChild()->ToText() )
FirstChild()->SetValue( inText );
else {
XMLText* theText = GetDocument()->NewText( inText );
InsertFirstChild( theText );
}
}
void XMLElement::SetText( int v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
SetText( buf );
}
void XMLElement::SetText( unsigned v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
SetText( buf );
}
void XMLElement::SetText(int64_t v)
{
char buf[BUF_SIZE];
XMLUtil::ToStr(v, buf, BUF_SIZE);
SetText(buf);
}
void XMLElement::SetText(uint64_t v) {
char buf[BUF_SIZE];
XMLUtil::ToStr(v, buf, BUF_SIZE);
SetText(buf);
}
void XMLElement::SetText( bool v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
SetText( buf );
}
void XMLElement::SetText( float v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
SetText( buf );
}
void XMLElement::SetText( double v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
SetText( buf );
}
XMLError XMLElement::QueryIntText( int* ival ) const
{
if ( FirstChild() && FirstChild()->ToText() ) {
const char* t = FirstChild()->Value();
if ( XMLUtil::ToInt( t, ival ) ) {
return XML_SUCCESS;
}
return XML_CAN_NOT_CONVERT_TEXT;
}
return XML_NO_TEXT_NODE;
}
XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const
{
if ( FirstChild() && FirstChild()->ToText() ) {
const char* t = FirstChild()->Value();
if ( XMLUtil::ToUnsigned( t, uval ) ) {
return XML_SUCCESS;
}
return XML_CAN_NOT_CONVERT_TEXT;
}
return XML_NO_TEXT_NODE;
}
XMLError XMLElement::QueryInt64Text(int64_t* ival) const
{
if (FirstChild() && FirstChild()->ToText()) {
const char* t = FirstChild()->Value();
if (XMLUtil::ToInt64(t, ival)) {
return XML_SUCCESS;
}
return XML_CAN_NOT_CONVERT_TEXT;
}
return XML_NO_TEXT_NODE;
}
XMLError XMLElement::QueryUnsigned64Text(uint64_t* ival) const
{
if(FirstChild() && FirstChild()->ToText()) {
const char* t = FirstChild()->Value();
if(XMLUtil::ToUnsigned64(t, ival)) {
return XML_SUCCESS;
}
return XML_CAN_NOT_CONVERT_TEXT;
}
return XML_NO_TEXT_NODE;
}
XMLError XMLElement::QueryBoolText( bool* bval ) const
{
if ( FirstChild() && FirstChild()->ToText() ) {
const char* t = FirstChild()->Value();
if ( XMLUtil::ToBool( t, bval ) ) {
return XML_SUCCESS;
}
return XML_CAN_NOT_CONVERT_TEXT;
}
return XML_NO_TEXT_NODE;
}
XMLError XMLElement::QueryDoubleText( double* dval ) const
{
if ( FirstChild() && FirstChild()->ToText() ) {
const char* t = FirstChild()->Value();
if ( XMLUtil::ToDouble( t, dval ) ) {
return XML_SUCCESS;
}
return XML_CAN_NOT_CONVERT_TEXT;
}
return XML_NO_TEXT_NODE;
}
XMLError XMLElement::QueryFloatText( float* fval ) const
{
if ( FirstChild() && FirstChild()->ToText() ) {
const char* t = FirstChild()->Value();
if ( XMLUtil::ToFloat( t, fval ) ) {
return XML_SUCCESS;
}
return XML_CAN_NOT_CONVERT_TEXT;
}
return XML_NO_TEXT_NODE;
}
int XMLElement::IntText(int defaultValue) const
{
int i = defaultValue;
QueryIntText(&i);
return i;
}
unsigned XMLElement::UnsignedText(unsigned defaultValue) const
{
unsigned i = defaultValue;
QueryUnsignedText(&i);
return i;
}
int64_t XMLElement::Int64Text(int64_t defaultValue) const
{
int64_t i = defaultValue;
QueryInt64Text(&i);
return i;
}
uint64_t XMLElement::Unsigned64Text(uint64_t defaultValue) const
{
uint64_t i = defaultValue;
QueryUnsigned64Text(&i);
return i;
}
bool XMLElement::BoolText(bool defaultValue) const
{
bool b = defaultValue;
QueryBoolText(&b);
return b;
}
double XMLElement::DoubleText(double defaultValue) const
{
double d = defaultValue;
QueryDoubleText(&d);
return d;
}
float XMLElement::FloatText(float defaultValue) const
{
float f = defaultValue;
QueryFloatText(&f);
return f;
}
XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name )
{
XMLAttribute* last = 0;
XMLAttribute* attrib = 0;
for( attrib = _rootAttribute;
attrib;
last = attrib, attrib = attrib->_next ) {
if ( XMLUtil::StringEqual( attrib->Name(), name ) ) {
break;
}
}
if ( !attrib ) {
attrib = CreateAttribute();
TIXMLASSERT( attrib );
if ( last ) {
TIXMLASSERT( last->_next == 0 );
last->_next = attrib;
}
else {
TIXMLASSERT( _rootAttribute == 0 );
_rootAttribute = attrib;
}
attrib->SetName( name );
}
return attrib;
}
void XMLElement::DeleteAttribute( const char* name )
{
XMLAttribute* prev = 0;
for( XMLAttribute* a=_rootAttribute; a; a=a->_next ) {
if ( XMLUtil::StringEqual( name, a->Name() ) ) {
if ( prev ) {
prev->_next = a->_next;
}
else {
_rootAttribute = a->_next;
}
DeleteAttribute( a );
break;
}
prev = a;
}
}
char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr )
{
XMLAttribute* prevAttribute = 0;
// Read the attributes.
while( p ) {
p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr );
if ( !(*p) ) {
_document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, "XMLElement name=%s", Name() );
return 0;
}
// attribute.
if (XMLUtil::IsNameStartChar( (unsigned char) *p ) ) {
XMLAttribute* attrib = CreateAttribute();
TIXMLASSERT( attrib );
attrib->_parseLineNum = _document->_parseCurLineNum;
const int attrLineNum = attrib->_parseLineNum;
p = attrib->ParseDeep( p, _document->ProcessEntities(), curLineNumPtr );
if ( !p || Attribute( attrib->Name() ) ) {
DeleteAttribute( attrib );
_document->SetError( XML_ERROR_PARSING_ATTRIBUTE, attrLineNum, "XMLElement name=%s", Name() );
return 0;
}
// There is a minor bug here: if the attribute in the source xml
// document is duplicated, it will not be detected and the
// attribute will be doubly added. However, tracking the 'prevAttribute'
// avoids re-scanning the attribute list. Preferring performance for
// now, may reconsider in the future.
if ( prevAttribute ) {
TIXMLASSERT( prevAttribute->_next == 0 );
prevAttribute->_next = attrib;
}
else {
TIXMLASSERT( _rootAttribute == 0 );
_rootAttribute = attrib;
}
prevAttribute = attrib;
}
// end of the tag
else if ( *p == '>' ) {
++p;
break;
}
// end of the tag
else if ( *p == '/' && *(p+1) == '>' ) {
_closingType = CLOSED;
return p+2; // done; sealed element.
}
else {
_document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, 0 );
return 0;
}
}
return p;
}
void XMLElement::DeleteAttribute( XMLAttribute* attribute )
{
if ( attribute == 0 ) {
return;
}
MemPool* pool = attribute->_memPool;
attribute->~XMLAttribute();
pool->Free( attribute );
}
XMLAttribute* XMLElement::CreateAttribute()
{
TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() );
XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
TIXMLASSERT( attrib );
attrib->_memPool = &_document->_attributePool;
attrib->_memPool->SetTracked();
return attrib;
}
XMLElement* XMLElement::InsertNewChildElement(const char* name)
{
XMLElement* node = _document->NewElement(name);
return InsertEndChild(node) ? node : 0;
}
XMLComment* XMLElement::InsertNewComment(const char* comment)
{
XMLComment* node = _document->NewComment(comment);
return InsertEndChild(node) ? node : 0;
}
XMLText* XMLElement::InsertNewText(const char* text)
{
XMLText* node = _document->NewText(text);
return InsertEndChild(node) ? node : 0;
}
XMLDeclaration* XMLElement::InsertNewDeclaration(const char* text)
{
XMLDeclaration* node = _document->NewDeclaration(text);
return InsertEndChild(node) ? node : 0;
}
XMLUnknown* XMLElement::InsertNewUnknown(const char* text)
{
XMLUnknown* node = _document->NewUnknown(text);
return InsertEndChild(node) ? node : 0;
}
//
// <ele></ele>
// <ele>foo<b>bar</b></ele>
//
char* XMLElement::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
{
// Read the element name.
p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr );
// The closing element is the </element> form. It is
// parsed just like a regular element then deleted from
// the DOM.
if ( *p == '/' ) {
_closingType = CLOSING;
++p;
}
p = _value.ParseName( p );
if ( _value.Empty() ) {
return 0;
}
p = ParseAttributes( p, curLineNumPtr );
if ( !p || !*p || _closingType != OPEN ) {
return p;
}
p = XMLNode::ParseDeep( p, parentEndTag, curLineNumPtr );
return p;
}
XMLNode* XMLElement::ShallowClone( XMLDocument* doc ) const
{
if ( !doc ) {
doc = _document;
}
XMLElement* element = doc->NewElement( Value() ); // fixme: this will always allocate memory. Intern?
for( const XMLAttribute* a=FirstAttribute(); a; a=a->Next() ) {
element->SetAttribute( a->Name(), a->Value() ); // fixme: this will always allocate memory. Intern?
}
return element;
}
bool XMLElement::ShallowEqual( const XMLNode* compare ) const
{
TIXMLASSERT( compare );
const XMLElement* other = compare->ToElement();
if ( other && XMLUtil::StringEqual( other->Name(), Name() )) {
const XMLAttribute* a=FirstAttribute();
const XMLAttribute* b=other->FirstAttribute();
while ( a && b ) {
if ( !XMLUtil::StringEqual( a->Value(), b->Value() ) ) {
return false;
}
a = a->Next();
b = b->Next();
}
if ( a || b ) {
// different count
return false;
}
return true;
}
return false;
}
bool XMLElement::Accept( XMLVisitor* visitor ) const
{
TIXMLASSERT( visitor );
if ( visitor->VisitEnter( *this, _rootAttribute ) ) {
for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) {
if ( !node->Accept( visitor ) ) {
break;
}
}
}
return visitor->VisitExit( *this );
}
// --------- XMLDocument ----------- //
// Warning: List must match 'enum XMLError'
const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = {
"XML_SUCCESS",
"XML_NO_ATTRIBUTE",
"XML_WRONG_ATTRIBUTE_TYPE",
"XML_ERROR_FILE_NOT_FOUND",
"XML_ERROR_FILE_COULD_NOT_BE_OPENED",
"XML_ERROR_FILE_READ_ERROR",
"XML_ERROR_PARSING_ELEMENT",
"XML_ERROR_PARSING_ATTRIBUTE",
"XML_ERROR_PARSING_TEXT",
"XML_ERROR_PARSING_CDATA",
"XML_ERROR_PARSING_COMMENT",
"XML_ERROR_PARSING_DECLARATION",
"XML_ERROR_PARSING_UNKNOWN",
"XML_ERROR_EMPTY_DOCUMENT",
"XML_ERROR_MISMATCHED_ELEMENT",
"XML_ERROR_PARSING",
"XML_CAN_NOT_CONVERT_TEXT",
"XML_NO_TEXT_NODE",
"XML_ELEMENT_DEPTH_EXCEEDED"
};
XMLDocument::XMLDocument( bool processEntities, Whitespace whitespaceMode ) :
XMLNode( 0 ),
_writeBOM( false ),
_processEntities( processEntities ),
_errorID(XML_SUCCESS),
_whitespaceMode( whitespaceMode ),
_errorStr(),
_errorLineNum( 0 ),
_charBuffer( 0 ),
_parseCurLineNum( 0 ),
_parsingDepth(0),
_unlinked(),
_elementPool(),
_attributePool(),
_textPool(),
_commentPool()
{
// avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+)
_document = this;
}
XMLDocument::~XMLDocument()
{
Clear();
}
void XMLDocument::MarkInUse(const XMLNode* const node)
{
TIXMLASSERT(node);
TIXMLASSERT(node->_parent == 0);
for (int i = 0; i < _unlinked.Size(); ++i) {
if (node == _unlinked[i]) {
_unlinked.SwapRemove(i);
break;
}
}
}
void XMLDocument::Clear()
{
DeleteChildren();
while( _unlinked.Size()) {
DeleteNode(_unlinked[0]); // Will remove from _unlinked as part of delete.
}
#ifdef TINYXML2_DEBUG
const bool hadError = Error();
#endif
ClearError();
delete [] _charBuffer;
_charBuffer = 0;
_parsingDepth = 0;
#if 0
_textPool.Trace( "text" );
_elementPool.Trace( "element" );
_commentPool.Trace( "comment" );
_attributePool.Trace( "attribute" );
#endif
#ifdef TINYXML2_DEBUG
if ( !hadError ) {
TIXMLASSERT( _elementPool.CurrentAllocs() == _elementPool.Untracked() );
TIXMLASSERT( _attributePool.CurrentAllocs() == _attributePool.Untracked() );
TIXMLASSERT( _textPool.CurrentAllocs() == _textPool.Untracked() );
TIXMLASSERT( _commentPool.CurrentAllocs() == _commentPool.Untracked() );
}
#endif
}
void XMLDocument::DeepCopy(XMLDocument* target) const
{
TIXMLASSERT(target);
if (target == this) {
return; // technically success - a no-op.
}
target->Clear();
for (const XMLNode* node = this->FirstChild(); node; node = node->NextSibling()) {
target->InsertEndChild(node->DeepClone(target));
}
}
XMLElement* XMLDocument::NewElement( const char* name )
{
XMLElement* ele = CreateUnlinkedNode<XMLElement>( _elementPool );
ele->SetName( name );
return ele;
}
XMLComment* XMLDocument::NewComment( const char* str )
{
XMLComment* comment = CreateUnlinkedNode<XMLComment>( _commentPool );
comment->SetValue( str );
return comment;
}
XMLText* XMLDocument::NewText( const char* str )
{
XMLText* text = CreateUnlinkedNode<XMLText>( _textPool );
text->SetValue( str );
return text;
}
XMLDeclaration* XMLDocument::NewDeclaration( const char* str )
{
XMLDeclaration* dec = CreateUnlinkedNode<XMLDeclaration>( _commentPool );
dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" );
return dec;
}
XMLUnknown* XMLDocument::NewUnknown( const char* str )
{
XMLUnknown* unk = CreateUnlinkedNode<XMLUnknown>( _commentPool );
unk->SetValue( str );
return unk;
}
static FILE* callfopen( const char* filepath, const char* mode )
{
TIXMLASSERT( filepath );
TIXMLASSERT( mode );
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
FILE* fp = 0;
const errno_t err = fopen_s( &fp, filepath, mode );
if ( err ) {
return 0;
}
#else
FILE* fp = fopen( filepath, mode );
#endif
return fp;
}
void XMLDocument::DeleteNode( XMLNode* node ) {
TIXMLASSERT( node );
TIXMLASSERT(node->_document == this );
if (node->_parent) {
node->_parent->DeleteChild( node );
}
else {
// Isn't in the tree.
// Use the parent delete.
// Also, we need to mark it tracked: we 'know'
// it was never used.
node->_memPool->SetTracked();
// Call the static XMLNode version:
XMLNode::DeleteNode(node);
}
}
XMLError XMLDocument::LoadFile( const char* filename )
{
if ( !filename ) {
TIXMLASSERT( false );
SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=<null>" );
return _errorID;
}
Clear();
FILE* fp = callfopen( filename, "rb" );
if ( !fp ) {
SetError( XML_ERROR_FILE_NOT_FOUND, 0, "filename=%s", filename );
return _errorID;
}
LoadFile( fp );
fclose( fp );
return _errorID;
}
XMLError XMLDocument::LoadFile( FILE* fp )
{
Clear();
TIXML_FSEEK( fp, 0, SEEK_SET );
if ( fgetc( fp ) == EOF && ferror( fp ) != 0 ) {
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
return _errorID;
}
TIXML_FSEEK( fp, 0, SEEK_END );
unsigned long long filelength;
{
const long long fileLengthSigned = TIXML_FTELL( fp );
TIXML_FSEEK( fp, 0, SEEK_SET );
if ( fileLengthSigned == -1L ) {
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
return _errorID;
}
TIXMLASSERT( fileLengthSigned >= 0 );
filelength = static_cast<unsigned long long>(fileLengthSigned);
}
const size_t maxSizeT = static_cast<size_t>(-1);
// We'll do the comparison as an unsigned long long, because that's guaranteed to be at
// least 8 bytes, even on a 32-bit platform.
if ( filelength >= static_cast<unsigned long long>(maxSizeT) ) {
// Cannot handle files which won't fit in buffer together with null terminator
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
return _errorID;
}
if ( filelength == 0 ) {
SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
return _errorID;
}
const size_t size = static_cast<size_t>(filelength);
TIXMLASSERT( _charBuffer == 0 );
_charBuffer = new char[size+1];
const size_t read = fread( _charBuffer, 1, size, fp );
if ( read != size ) {
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
return _errorID;
}
_charBuffer[size] = 0;
Parse();
return _errorID;
}
XMLError XMLDocument::SaveFile( const char* filename, bool compact )
{
if ( !filename ) {
TIXMLASSERT( false );
SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=<null>" );
return _errorID;
}
FILE* fp = callfopen( filename, "w" );
if ( !fp ) {
SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=%s", filename );
return _errorID;
}
SaveFile(fp, compact);
fclose( fp );
return _errorID;
}
XMLError XMLDocument::SaveFile( FILE* fp, bool compact )
{
// Clear any error from the last save, otherwise it will get reported
// for *this* call.
ClearError();
XMLPrinter stream( fp, compact );
Print( &stream );
return _errorID;
}
XMLError XMLDocument::Parse( const char* p, size_t len )
{
Clear();
if ( len == 0 || !p || !*p ) {
SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
return _errorID;
}
if ( len == static_cast<size_t>(-1) ) {
len = strlen( p );
}
TIXMLASSERT( _charBuffer == 0 );
_charBuffer = new char[ len+1 ];
memcpy( _charBuffer, p, len );
_charBuffer[len] = 0;
Parse();
if ( Error() ) {
// clean up now essentially dangling memory.
// and the parse fail can put objects in the
// pools that are dead and inaccessible.
DeleteChildren();
_elementPool.Clear();
_attributePool.Clear();
_textPool.Clear();
_commentPool.Clear();
}
return _errorID;
}
void XMLDocument::Print( XMLPrinter* streamer ) const
{
if ( streamer ) {
Accept( streamer );
}
else {
XMLPrinter stdoutStreamer( stdout );
Accept( &stdoutStreamer );
}
}
void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... )
{
TIXMLASSERT( error >= 0 && error < XML_ERROR_COUNT );
_errorID = error;
_errorLineNum = lineNum;
_errorStr.Reset();
const size_t BUFFER_SIZE = 1000;
char* buffer = new char[BUFFER_SIZE];
TIXMLASSERT(sizeof(error) <= sizeof(int));
TIXML_SNPRINTF(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d (0x%x) Line number=%d", ErrorIDToName(error), int(error), int(error), lineNum);
if (format) {
size_t len = strlen(buffer);
TIXML_SNPRINTF(buffer + len, BUFFER_SIZE - len, ": ");
len = strlen(buffer);
va_list va;
va_start(va, format);
TIXML_VSNPRINTF(buffer + len, BUFFER_SIZE - len, format, va);
va_end(va);
}
_errorStr.SetStr(buffer);
delete[] buffer;
}
/*static*/ const char* XMLDocument::ErrorIDToName(XMLError errorID)
{
TIXMLASSERT( errorID >= 0 && errorID < XML_ERROR_COUNT );
const char* errorName = _errorNames[errorID];
TIXMLASSERT( errorName && errorName[0] );
return errorName;
}
const char* XMLDocument::ErrorStr() const
{
return _errorStr.Empty() ? "" : _errorStr.GetStr();
}
void XMLDocument::PrintError() const
{
printf("%s\n", ErrorStr());
}
const char* XMLDocument::ErrorName() const
{
return ErrorIDToName(_errorID);
}
void XMLDocument::Parse()
{
TIXMLASSERT( NoChildren() ); // Clear() must have been called previously
TIXMLASSERT( _charBuffer );
_parseCurLineNum = 1;
_parseLineNum = 1;
char* p = _charBuffer;
p = XMLUtil::SkipWhiteSpace( p, &_parseCurLineNum );
p = const_cast<char*>( XMLUtil::ReadBOM( p, &_writeBOM ) );
if ( !*p ) {
SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
return;
}
ParseDeep(p, 0, &_parseCurLineNum );
}
void XMLDocument::PushDepth()
{
_parsingDepth++;
if (_parsingDepth == TINYXML2_MAX_ELEMENT_DEPTH) {
SetError(XML_ELEMENT_DEPTH_EXCEEDED, _parseCurLineNum, "Element nesting is too deep." );
}
}
void XMLDocument::PopDepth()
{
TIXMLASSERT(_parsingDepth > 0);
--_parsingDepth;
}
XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) :
_elementJustOpened( false ),
_stack(),
_firstElement( true ),
_fp( file ),
_depth( depth ),
_textDepth( -1 ),
_processEntities( true ),
_compactMode( compact ),
_buffer()
{
for( int i=0; i<ENTITY_RANGE; ++i ) {
_entityFlag[i] = false;
_restrictedEntityFlag[i] = false;
}
for( int i=0; i<NUM_ENTITIES; ++i ) {
const char entityValue = entities[i].value;
const unsigned char flagIndex = static_cast<unsigned char>(entityValue);
TIXMLASSERT( flagIndex < ENTITY_RANGE );
_entityFlag[flagIndex] = true;
}
_restrictedEntityFlag[static_cast<unsigned char>('&')] = true;
_restrictedEntityFlag[static_cast<unsigned char>('<')] = true;
_restrictedEntityFlag[static_cast<unsigned char>('>')] = true; // not required, but consistency is nice
_buffer.Push( 0 );
}
void XMLPrinter::Print( const char* format, ... )
{
va_list va;
va_start( va, format );
if ( _fp ) {
vfprintf( _fp, format, va );
}
else {
const int len = TIXML_VSCPRINTF( format, va );
// Close out and re-start the va-args
va_end( va );
TIXMLASSERT( len >= 0 );
va_start( va, format );
TIXMLASSERT( _buffer.Size() > 0 && _buffer[_buffer.Size() - 1] == 0 );
char* p = _buffer.PushArr( len ) - 1; // back up over the null terminator.
TIXML_VSNPRINTF( p, len+1, format, va );
}
va_end( va );
}
void XMLPrinter::Write( const char* data, size_t size )
{
if ( _fp ) {
fwrite ( data , sizeof(char), size, _fp);
}
else {
char* p = _buffer.PushArr( static_cast<int>(size) ) - 1; // back up over the null terminator.
memcpy( p, data, size );
p[size] = 0;
}
}
void XMLPrinter::Putc( char ch )
{
if ( _fp ) {
fputc ( ch, _fp);
}
else {
char* p = _buffer.PushArr( sizeof(char) ) - 1; // back up over the null terminator.
p[0] = ch;
p[1] = 0;
}
}
void XMLPrinter::PrintSpace( int depth )
{
for( int i=0; i<depth; ++i ) {
Write( " " );
}
}
void XMLPrinter::PrintString( const char* p, bool restricted )
{
// Look for runs of bytes between entities to print.
const char* q = p;
if ( _processEntities ) {
const bool* flag = restricted ? _restrictedEntityFlag : _entityFlag;
while ( *q ) {
TIXMLASSERT( p <= q );
// Remember, char is sometimes signed. (How many times has that bitten me?)
if ( *q > 0 && *q < ENTITY_RANGE ) {
// Check for entities. If one is found, flush
// the stream up until the entity, write the
// entity, and keep looking.
if ( flag[static_cast<unsigned char>(*q)] ) {
while ( p < q ) {
const size_t delta = q - p;
const int toPrint = ( INT_MAX < delta ) ? INT_MAX : static_cast<int>(delta);
Write( p, toPrint );
p += toPrint;
}
bool entityPatternPrinted = false;
for( int i=0; i<NUM_ENTITIES; ++i ) {
if ( entities[i].value == *q ) {
Putc( '&' );
Write( entities[i].pattern, entities[i].length );
Putc( ';' );
entityPatternPrinted = true;
break;
}
}
if ( !entityPatternPrinted ) {
// TIXMLASSERT( entityPatternPrinted ) causes gcc -Wunused-but-set-variable in release
TIXMLASSERT( false );
}
++p;
}
}
++q;
TIXMLASSERT( p <= q );
}
// Flush the remaining string. This will be the entire
// string if an entity wasn't found.
if ( p < q ) {
const size_t delta = q - p;
const int toPrint = ( INT_MAX < delta ) ? INT_MAX : static_cast<int>(delta);
Write( p, toPrint );
}
}
else {
Write( p );
}
}
void XMLPrinter::PushHeader( bool writeBOM, bool writeDec )
{
if ( writeBOM ) {
static const unsigned char bom[] = { TIXML_UTF_LEAD_0, TIXML_UTF_LEAD_1, TIXML_UTF_LEAD_2, 0 };
Write( reinterpret_cast< const char* >( bom ) );
}
if ( writeDec ) {
PushDeclaration( "xml version=\"1.0\"" );
}
}
void XMLPrinter::PrepareForNewNode( bool compactMode )
{
SealElementIfJustOpened();
if ( compactMode ) {
return;
}
if ( _firstElement ) {
PrintSpace (_depth);
} else if ( _textDepth < 0) {
Putc( '\n' );
PrintSpace( _depth );
}
_firstElement = false;
}
void XMLPrinter::OpenElement( const char* name, bool compactMode )
{
PrepareForNewNode( compactMode );
_stack.Push( name );
Write ( "<" );
Write ( name );
_elementJustOpened = true;
++_depth;
}
void XMLPrinter::PushAttribute( const char* name, const char* value )
{
TIXMLASSERT( _elementJustOpened );
Putc ( ' ' );
Write( name );
Write( "=\"" );
PrintString( value, false );
Putc ( '\"' );
}
void XMLPrinter::PushAttribute( const char* name, int v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
PushAttribute( name, buf );
}
void XMLPrinter::PushAttribute( const char* name, unsigned v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
PushAttribute( name, buf );
}
void XMLPrinter::PushAttribute(const char* name, int64_t v)
{
char buf[BUF_SIZE];
XMLUtil::ToStr(v, buf, BUF_SIZE);
PushAttribute(name, buf);
}
void XMLPrinter::PushAttribute(const char* name, uint64_t v)
{
char buf[BUF_SIZE];
XMLUtil::ToStr(v, buf, BUF_SIZE);
PushAttribute(name, buf);
}
void XMLPrinter::PushAttribute( const char* name, bool v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
PushAttribute( name, buf );
}
void XMLPrinter::PushAttribute( const char* name, double v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
PushAttribute( name, buf );
}
void XMLPrinter::CloseElement( bool compactMode )
{
--_depth;
const char* name = _stack.Pop();
if ( _elementJustOpened ) {
Write( "/>" );
}
else {
if ( _textDepth < 0 && !compactMode) {
Putc( '\n' );
PrintSpace( _depth );
}
Write ( "</" );
Write ( name );
Write ( ">" );
}
if ( _textDepth == _depth ) {
_textDepth = -1;
}
if ( _depth == 0 && !compactMode) {
Putc( '\n' );
}
_elementJustOpened = false;
}
void XMLPrinter::SealElementIfJustOpened()
{
if ( !_elementJustOpened ) {
return;
}
_elementJustOpened = false;
Putc( '>' );
}
void XMLPrinter::PushText( const char* text, bool cdata )
{
_textDepth = _depth-1;
SealElementIfJustOpened();
if ( cdata ) {
Write( "<![CDATA[" );
Write( text );
Write( "]]>" );
}
else {
PrintString( text, true );
}
}
void XMLPrinter::PushText( int64_t value )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( value, buf, BUF_SIZE );
PushText( buf, false );
}
void XMLPrinter::PushText( uint64_t value )
{
char buf[BUF_SIZE];
XMLUtil::ToStr(value, buf, BUF_SIZE);
PushText(buf, false);
}
void XMLPrinter::PushText( int value )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( value, buf, BUF_SIZE );
PushText( buf, false );
}
void XMLPrinter::PushText( unsigned value )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( value, buf, BUF_SIZE );
PushText( buf, false );
}
void XMLPrinter::PushText( bool value )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( value, buf, BUF_SIZE );
PushText( buf, false );
}
void XMLPrinter::PushText( float value )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( value, buf, BUF_SIZE );
PushText( buf, false );
}
void XMLPrinter::PushText( double value )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( value, buf, BUF_SIZE );
PushText( buf, false );
}
void XMLPrinter::PushComment( const char* comment )
{
PrepareForNewNode( _compactMode );
Write( "<!--" );
Write( comment );
Write( "-->" );
}
void XMLPrinter::PushDeclaration( const char* value )
{
PrepareForNewNode( _compactMode );
Write( "<?" );
Write( value );
Write( "?>" );
}
void XMLPrinter::PushUnknown( const char* value )
{
PrepareForNewNode( _compactMode );
Write( "<!" );
Write( value );
Putc( '>' );
}
bool XMLPrinter::VisitEnter( const XMLDocument& doc )
{
_processEntities = doc.ProcessEntities();
if ( doc.HasBOM() ) {
PushHeader( true, false );
}
return true;
}
bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute )
{
const XMLElement* parentElem = 0;
if ( element.Parent() ) {
parentElem = element.Parent()->ToElement();
}
const bool compactMode = parentElem ? CompactMode( *parentElem ) : _compactMode;
OpenElement( element.Name(), compactMode );
while ( attribute ) {
PushAttribute( attribute->Name(), attribute->Value() );
attribute = attribute->Next();
}
return true;
}
bool XMLPrinter::VisitExit( const XMLElement& element )
{
CloseElement( CompactMode(element) );
return true;
}
bool XMLPrinter::Visit( const XMLText& text )
{
PushText( text.Value(), text.CData() );
return true;
}
bool XMLPrinter::Visit( const XMLComment& comment )
{
PushComment( comment.Value() );
return true;
}
bool XMLPrinter::Visit( const XMLDeclaration& declaration )
{
PushDeclaration( declaration.Value() );
return true;
}
bool XMLPrinter::Visit( const XMLUnknown& unknown )
{
PushUnknown( unknown.Value() );
return true;
}
} // namespace tinyxml2
| 73,878 | C | .c | 2,469 | 23.674767 | 140 | 0.583262 | libretro/libretro-uae | 112 | 60 | 28 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | false | false | true | true | false | false | false |
1,292,965 | genp2c.c | libretro_libretro-uae/sources/src/genp2c.c | /*
* UAE - The Un*x Amiga Emulator
*
* Generator for planar to chunky conversions
*
* Copyright 1997 Bernd Schmidt
*/
#include <stdio.h>
#include "sysconfig.h"
#include "sysdeps.h"
/* We can't include custom.h here. */
#define MAX_WORDS_PER_LINE 50
static char *gen_ind (char *a, int b)
{
char buf[200];
sprintf (buf, "%d(%s)", b, a);
return strdup (buf);
}
static char *gen_indx (char *a, int b, char *c, int d)
{
char buf[200];
sprintf (buf, "%d(%s,%s,%d)", b, a, c, d);
return strdup (buf);
}
static char *gen_indsx (char *a, char *sym, int b, char *c, int d)
{
char buf[200];
sprintf (buf, "%s+%d(%s,%s,%d)", sym, b, a, c, d);
return strdup (buf);
}
#define reg(a) "%" a
#define ind(a,b) #b"("a")"
#define imm(a) "$"#a
#ifdef USE_UNDERSCORE
#define sym(a) "_"#a
#else
#define sym(a) #a
#endif
#define indx(a,b,c,d) #b"("a","c","#d")"
#define indsx(a,s,b,c,d) s"+"#b"("a","c","#d")"
static int labelno = 0;
static int get_label (void)
{
return labelno++;
}
static void declare_label (int nr)
{
printf (".L%d:\n", nr);
}
static int new_label (void)
{
int nr = get_label ();
declare_label (nr);
return nr;
}
static void gen_label (int nr) { printf (".L%d", nr); }
static void jnz (int nr) { printf ("\tjnz "); gen_label (nr); printf ("\n"); }
static void jnc (int nr) { printf ("\tjnc "); gen_label (nr); printf ("\n"); }
static void jc (int nr) { printf ("\tjc "); gen_label (nr); printf ("\n"); }
static void jmp (int nr) { printf ("\tjmp "); gen_label (nr); printf ("\n"); }
static void movl (char *src, char *dst) { printf ("\tmovl %s,%s\n", src, dst); }
static void movw (char *src, char *dst) { printf ("\tmovl %s,%s\n", src, dst); }
static void movb (char *src, char *dst) { printf ("\tmovl %s,%s\n", src, dst); }
static void movzbl (char *src, char *dst) { printf ("\tmovzbl %s,%s\n", src, dst); }
static void leal (char *src, char *dst) { printf ("\tleal %s,%s\n", src, dst); }
static void addl (char *src, char *dst) { printf ("\taddl %s,%s\n", src, dst); }
static void subl (char *src, char *dst) { printf ("\tsubl %s,%s\n", src, dst); }
static void cmpl (char *src, char *dst) { printf ("\tcmpl %s,%s\n", src, dst); }
static void andl (unsigned long mask, char *dst) { printf ("\tandl $0x%0lx,%s\n", mask, dst); }
static void orl (char *src, char *dst) { printf ("\torl %s,%s\n", src, dst); }
static void imull (unsigned long val, char *dst) { printf ("\timull $0x%08lx,%s\n", val, dst); }
static void decl (char *dst) { printf ("\tdecl %s\n", dst); }
static void incl (char *dst) { printf ("\tincl %s\n", dst); }
static void bswapl (char *dst) { printf ("\tbswap %s\n", dst); }
static void shrl (int count, char *dst) { printf ("\tshrl $%d,%s\n", count, dst); }
static void shll (int count, char *dst) { printf ("\tshll $%d,%s\n", count, dst); }
static void pushl (char *src) { printf ("\tpushl %s\n", src); }
static void popl (char *dst) { printf ("\tpopl %s\n", dst); }
static void ret (void) { printf ("\tret\n"); }
static void align (int a) { printf ("\t.p2align %d,0x90\n", a); }
static void shiftleftl (int count, char *dst)
{
if (count == 0)
return;
if (count < 0)
shrl (-count, dst);
else {
char *indb0;
switch (count) {
case 1:
addl (dst, dst);
break;
case 2: case 3:
indb0 = gen_indx ("", 0, dst, 1 << count);
leal (indb0, dst);
free (indb0);
break;
default:
shll (count, dst);
}
}
}
static void declare_fn (char *name)
{
printf ("\t.globl %s\n", name);
/* printf ("\t.type %s,@function\n", name); */
align (5);
printf ("%s:\n", name);
}
#define esi reg("esi")
#define edi reg("edi")
#define ebp reg("ebp")
#define esp reg("esp")
#define eax reg("eax")
#define ebx reg("ebx")
#define ecx reg("ecx")
#define edx reg("edx")
/* Modes:
* 0: normal
* 1: only generate every second plane, set memory
* 2: only generate every second plane, starting at second plane, or to memory
*/
/* Normal code: one pixel per bit */
static void gen_x86_set_hires_h_toobad_k6_too_slow_someone_try_this_with_a_ppro (int pl, int mode)
{
int plmul = mode == 0 ? 1 : 2;
int ploff = mode == 2 ? 1 : 0;
int i;
int loop;
char buf[40];
char *indb0;
sprintf (buf, sym (set_hires_h_%d_%d), pl, mode);
declare_fn (buf);
pushl (ebp);
pushl (esi);
pushl (edi);
pushl (ebx);
if (pl == 0) {
movl (ind (esp, 20), ebp);
movl (ind (esp, 24), esi);
}
movl (imm (0), edi);
loop = get_label ();
jmp (loop);
align (5);
declare_label (loop);
if (pl > 0)
movl (ind (esp, 24), esi);
if (mode == 2) {
if (pl > 0)
movl (ind (esp, 20), ebp);
movl (indx (ebp, 0, edi, 8), ecx);
movl (indx (ebp, 4, edi, 8), ebx);
}
for (i = 0; i <= pl; i+=2) {
int realpl = i * plmul + ploff;
char *data1 = (i == 0 && mode != 2 ? ecx : edx);
char *data2 = (i == 0 && mode != 2 ? ebx : eax);
if (i < pl) {
indb0 = gen_indx (esi, (realpl + plmul)*MAX_WORDS_PER_LINE*2, edi, 1);
movzbl (indb0, ebp);
free (indb0);
imull (0x08040201, ebp);
}
indb0 = gen_indx (esi, realpl*MAX_WORDS_PER_LINE*2, edi, 1);
movzbl (indb0, data2);
free (indb0);
if (i == pl || i == pl - 1)
incl (edi);
imull (0x08040201, data2);
if (i < pl) {
movl (ebp, esi);
andl (0x08080808, ebp);
shiftleftl (realpl + plmul - 7, esi);
}
movl (data2, data1);
andl (0x08080808, data2);
shiftleftl (realpl - 7, data1);
if (i < pl) {
andl (0x01010101 << (realpl + plmul), esi);
}
andl (0x01010101 << realpl, data1);
shiftleftl (realpl - 3, data2);
if (i < pl) {
shiftleftl (realpl + plmul - 3, ebp);
}
if (i < pl) {
orl (esi, ecx);
movl (ind (esp, 24), esi);
orl (ebp, ebx);
}
if (i > 0 || mode == 2) {
orl (edx, ecx);
orl (eax, ebx);
}
}
if (pl > 0)
movl (ind (esp, 20), ebp);
cmpl (ind (esp, 28), edi);
movl (ecx, indx (ebp, -8, edi, 8));
movl (ebx, indx (ebp, -4, edi, 8));
jc (loop);
popl (reg ("ebx"));
popl (reg ("edi"));
popl (reg ("esi"));
popl (reg ("ebp"));
ret ();
printf ("\n\n");
}
static void gen_x86_set_hires_h (int pl, int mode)
{
int plmul = mode == 0 ? 1 : 2;
int ploff = mode == 2 ? 1 : 0;
int i;
int loop;
char buf[40];
char *indb0;
sprintf (buf, sym (set_hires_h_%d_%d), pl, mode);
declare_fn (buf);
pushl (ebp);
pushl (esi);
pushl (edi);
pushl (ebx);
if (pl == 0) {
movl (ind (esp, 20), ebp);
movl (ind (esp, 24), esi);
}
movl (imm (0), edi);
loop = get_label ();
jmp (loop);
align (5);
declare_label (loop);
if (pl > 0)
movl (ind (esp, 24), esi);
if (mode == 2) {
if (pl > 0)
movl (ind (esp, 20), ebp);
movl (indx (ebp, 0, edi, 8), ecx);
movl (indx (ebp, 4, edi, 8), ebx);
}
for (i = 0; i <= pl; i+=2) {
int realpl = i * plmul + ploff;
char *data1 = (i == 0 && mode != 2 ? ecx : edx);
char *data2 = (i == 0 && mode != 2 ? ebx : eax);
if (i < pl) {
indb0 = gen_indx (esi, (realpl + plmul)*MAX_WORDS_PER_LINE*2, edi, 1);
movzbl (indb0, ebp);
free (indb0);
}
indb0 = gen_indx (esi, realpl*MAX_WORDS_PER_LINE*2, edi, 1);
movzbl (indb0, data2);
free (indb0);
if (i < pl) {
indb0 = gen_indsx ("", sym (hirestab_h), 0, ebp, 8);
movl (indb0, esi);
free (indb0);
indb0 = gen_indsx ("", sym (hirestab_h), 4, ebp, 8);
movl (indb0, ebp);
free (indb0);
}
if (i == pl || i == pl - 1)
incl (edi);
indb0 = gen_indsx ("", sym (hirestab_h), 0, data2, 8);
movl (indb0, data1);
free (indb0);
indb0 = gen_indsx ("", sym (hirestab_h), 4, data2, 8);
movl (indb0, data2);
free (indb0);
switch (realpl) {
case 0:
if (i < pl) {
addl (esi, esi);
addl (ebp, ebp);
if (plmul == 2) {
addl (esi, esi);
addl (ebp, ebp);
}
}
break;
case 1:
if (i < pl) {
indb0 = gen_indx ("", 0, esi, 4*plmul);
leal (indb0, esi);
free (indb0);
indb0 = gen_indx ("", 0, ebp, 4*plmul);
leal (indb0, ebp);
free (indb0);
}
addl (data1, data1);
addl (data2, data2);
break;
case 2:
if (i < pl) {
if (plmul == 1)
leal (indx ("", 0, esi, 8), esi);
else
shll (4, esi);
}
addl (data1, data1);
addl (data2, data2);
if (i < pl) {
if (plmul == 1)
leal (indx ("", 0, ebp, 8), ebp);
else
shll (4, ebp);
}
addl (data1, data1);
addl (data2, data2);
break;
case 3:
if (i < pl)
shll (3 + plmul, esi);
indb0 = gen_indx ("", 0, data1, 8);
leal (indb0, data1);
free (indb0);
if (i < pl)
shll (3 + plmul, ebp);
indb0 = gen_indx ("", 0, data2, 8);
leal (indb0, data2);
free (indb0);
break;
case 4: case 5: case 6: case 7:
shll (realpl, data1);
shll (realpl, data2);
if (i < pl) {
shll (realpl+plmul, esi);
shll (realpl+plmul, ebp);
}
break;
}
if (i < pl) {
orl (esi, ecx);
orl (ebp, ebx);
if (i + 2 <= pl)
movl (ind (esp, 24), esi);
}
if (i + 2 > pl && pl > 0)
movl (ind (esp, 20), ebp);
if (i > 0 || mode == 2) {
orl (data1, ecx);
orl (data2, ebx);
}
}
cmpl (ind (esp, 28), edi);
movl (ecx, indx (ebp, -8, edi, 8));
movl (ebx, indx (ebp, -4, edi, 8));
jc (loop);
popl (reg ("ebx"));
popl (reg ("edi"));
popl (reg ("esi"));
popl (reg ("ebp"));
ret ();
printf ("\n\n");
}
/* Squeeze: every second bit does not generate a pixel
Not optimized, this mode isn't useful. */
static void gen_x86_set_hires_l (int pl, int mode)
{
int plmul = mode == 0 ? 1 : 2;
int ploff = mode == 2 ? 1 : 0;
int i;
int loop;
char buf[40];
sprintf (buf, sym (set_hires_l_%d_%d), pl, mode);
declare_fn (buf);
pushl (ebp);
pushl (esi);
pushl (edi);
pushl (ebx);
movl (ind (esp, 20), ebp);
movl (ind (esp, 24), esi);
movl (imm (0), edi);
align (5);
loop = new_label ();
if (mode == 2) {
movl (indx (ebp, 0, edi, 1), ecx);
}
for (i = 0; i <= pl; i++) {
int realpl = i * plmul + ploff;
char *data1 = (i == 0 && mode != 2 ? ecx : edx);
char *indb0;
indb0 = gen_indx (esi, realpl*MAX_WORDS_PER_LINE*2, edi, 1);
movzbl (indb0, data1);
free (indb0);
indb0 = gen_indsx ("", sym (hirestab_l), 0, data1, 4);
movl (indb0, data1);
free (indb0);
if (i == pl)
incl (edi);
shiftleftl (realpl, data1);
if (i > 0 || mode == 2) {
orl (data1, ecx);
}
}
cmpl (ind (esp, 28), edi);
movl (ecx, indx (ebp, -4, edi, 4));
jc (loop);
popl (reg ("ebx"));
popl (reg ("edi"));
popl (reg ("esi"));
popl (reg ("ebp"));
ret ();
printf ("\n\n");
}
/* Stretch: two pixels per bit */
static void gen_x86_set_lores_h (int pl, int mode)
{
int plmul = mode == 0 ? 1 : 2;
int ploff = mode == 2 ? 1 : 0;
int i, j;
int loop;
char buf[40];
sprintf (buf, sym (set_lores_h_%d_%d), pl, mode);
declare_fn (buf);
pushl (ebp);
pushl (esi);
pushl (edi);
pushl (ebx);
movl (ind (esp, 20), ebp);
movl (ind (esp, 24), esi);
movl (imm (0), edi);
align (5);
loop = new_label ();
for (j = 0; j < 2; j++) {
if (mode == 2) {
movl (j ? ind (ebp, 8) : ind (ebp, 0), ecx);
movl (j ? ind (ebp, 12) : ind (ebp, 4), ebx);
}
for (i = 0; i <= pl; i++) {
int realpl = i * plmul + ploff;
char *data1 = (i == 0 && mode != 2 ? ecx : edx);
char *data2 = (i == 0 && mode != 2 ? ebx : eax);
char *indb0;
indb0 = gen_indx (esi, realpl*MAX_WORDS_PER_LINE*2, edi, 1);
movzbl (indb0, data2);
free (indb0);
addl (data2, data2);
indb0 = gen_indsx ("", sym (lorestab_h), 0 + j*8, data2, 8);
movl (indb0, data1);
free (indb0);
indb0 = gen_indsx ("", sym (lorestab_h), 4 + j*8, data2, 8);
movl (indb0, data2);
free (indb0);
shiftleftl (realpl, data1);
shiftleftl (realpl, data2);
if (i > 0 || mode == 2) {
orl (data1, ecx);
orl (data2, ebx);
}
}
movl (ecx, j ? ind (ebp, 8) : ind (ebp, 0));
movl (ebx, j ? ind (ebp, 12) : ind (ebp, 4));
}
incl (edi);
cmpl (ind (esp, 28), edi);
leal (ind (ebp, 16), ebp);
jc (loop);
popl (reg ("ebx"));
popl (reg ("edi"));
popl (reg ("esi"));
popl (reg ("ebp"));
ret ();
printf ("\n\n");
}
/* Normal code: one pixel per bit */
static void gen_c_set_hires_h (int pl, int mode, int header)
{
int plmul = mode == 0 ? 1 : 2;
int ploff = mode == 2 ? 1 : 0;
int i;
if (header)
printf("extern ");
printf ("void set_hires_h_%d_%d (uae_u32 *app, uae_u8 *ptr, int len)", pl, mode);
if (header) {
printf (";\n");
return;
}
printf ("\n\{\n\tint i;\n\tfor (i = 0; i < len; i++) {\n\t\tuae_u32 v1, v2;\n");
if (mode == 2) {
printf ("\t\tv1 = app[i*2 + 0]; v2 = app[i*2 + 1];\n");
}
for (i = 0; i <= pl; i++) {
int realpl = i * plmul + ploff;
char *asgn = (i == 0 && mode != 2 ? "=" : "|=");
printf ("\t\t{\n");
printf ("\t\t\tunsigned int data = *(ptr + i + %d);\n", MAX_WORDS_PER_LINE*2*realpl);
printf ("\t\t\tv1 %s hirestab_h[data][0] << %d;\n", asgn, realpl);
printf ("\t\t\tv2 %s hirestab_h[data][1] << %d;\n", asgn, realpl);
printf ("\t\t}\n");
}
printf ("\t\tapp[i*2 + 0] = v1;\n");
printf ("\t\tapp[i*2 + 1] = v2;\n");
printf ("\t}\n");
printf ("}\n\n");
}
/* Squeeze: every second bit does not generate a pixel
Not optimized, this mode isn't useful. */
static void gen_c_set_hires_l (int pl, int mode, int header)
{
int plmul = mode == 0 ? 1 : 2;
int ploff = mode == 2 ? 1 : 0;
int i;
if (header)
printf("extern ");
printf ("void set_hires_l_%d_%d (uae_u32 *app, uae_u8 *ptr, int len)", pl, mode);
if (header) {
printf (";\n");
return;
}
printf ("\n\{\n\tint i;\n\tfor (i = 0; i < len; i++) {\n\t\tuae_u32 v1;\n");
if (mode == 2) {
printf ("\t\tv1 = app[i];\n");
}
for (i = 0; i <= pl; i++) {
int realpl = i * plmul + ploff;
char *asgn = (i == 0 && mode != 2 ? "=" : "|=");
printf ("\t\t{\n");
printf ("\t\t\tunsigned int data = *(ptr + i + %d);\n", MAX_WORDS_PER_LINE*2*realpl);
printf ("\t\t\tv1 %s hirestab_l[data][0] << %d;\n", asgn, realpl);
printf ("\t\t}\n");
}
printf ("\t\tapp[i] = v1;\n");
printf ("\t}\n");
printf ("}\n\n");
}
/* Stretch: two pixels per bit */
static void gen_c_set_lores_h (int pl, int mode, int header)
{
int plmul = mode == 0 ? 1 : 2;
int ploff = mode == 2 ? 1 : 0;
int i;
if (header)
printf("extern ");
printf ("void set_lores_h_%d_%d (uae_u32 *app, uae_u8 *ptr, int len)", pl, mode);
if (header) {
printf (";\n");
return;
}
printf ("\n\{\n\tint i;\n\tfor (i = 0; i < len; i++) {\n\t\tuae_u32 v1, v2, v3, v4;\n");
if (mode == 2) {
printf ("\t\tv1 = app[i*4 + 0]; v2 = app[i*4 + 1]; v3 = app[i*4 + 2]; v4 = app[i*4 + 3];\n");
}
for (i = 0; i <= pl; i++) {
int realpl = i * plmul + ploff;
char *asgn = (i == 0 && mode != 2 ? "=" : "|=");
printf ("\t\t{\n");
printf ("\t\t\tunsigned int data = *(ptr + i + %d);\n", MAX_WORDS_PER_LINE*2*realpl);
printf ("\t\t\tv1 %s lorestab_h[data][0] << %d;\n", asgn, realpl);
printf ("\t\t\tv2 %s lorestab_h[data][1] << %d;\n", asgn, realpl);
printf ("\t\t\tv3 %s lorestab_h[data][2] << %d;\n", asgn, realpl);
printf ("\t\t\tv4 %s lorestab_h[data][3] << %d;\n", asgn, realpl);
printf ("\t\t}\n");
}
printf ("\t\tapp[i*4 + 0] = v1;\n");
printf ("\t\tapp[i*4 + 1] = v2;\n");
printf ("\t\tapp[i*4 + 2] = v3;\n");
printf ("\t\tapp[i*4 + 3] = v4;\n");
printf ("\t}\n");
printf ("}\n\n");
}
int main(int argc, char **argv)
{
int pl;
int outmode;
if (argc != 2)
return 1;
if (strcmp (argv[1], "C") == 0)
outmode = 0;
else if (strcmp (argv[1], "H") == 0)
outmode = 1;
else if (strcmp (argv[1], "x86") == 0)
outmode = 2;
else
return 1;
switch (outmode) {
case 0:
printf ("#include \"sysconfig.h\"\n");
printf ("#include \"sysdeps.h\"\n");
printf ("#include \"custom.h\"\n");
printf ("#include \"p2c.h\"\n");
break;
case 1:
printf ("#define MAX_WORDS_PER_LINE %d\n", MAX_WORDS_PER_LINE);
break;
case 2:
printf ("#define MAX_WORDS_PER_LINE %d\n", MAX_WORDS_PER_LINE);
printf (".text\n");
break;
}
for (pl = 0; pl < 8; pl++) {
int j;
for (j = 0; j < (pl < 4 ? 3 : 1); j++) {
switch (outmode) {
case 0: case 1:
gen_c_set_hires_h (pl, j, outmode);
gen_c_set_hires_l (pl, j, outmode);
gen_c_set_lores_h (pl, j, outmode);
break;
case 2:
gen_x86_set_hires_h (pl, j);
gen_x86_set_hires_l (pl, j);
gen_x86_set_lores_h (pl, j);
break;
}
}
}
return 0;
}
| 16,795 | C | .c | 608 | 23.814145 | 98 | 0.533619 | libretro/libretro-uae | 112 | 60 | 28 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,292,967 | nogui.c | libretro_libretro-uae/sources/src/nogui.c | /*
* UAE - The Un*x Amiga Emulator
*
* Interface to the Tcl/Tk GUI
*
* Copyright 1996 Bernd Schmidt
*/
#include "sysconfig.h"
#include "sysdeps.h"
#include "config.h"
#include "options.h"
#include "gui.h"
static void sigchldhandler(int foo)
{
}
int gui_init (void)
{
return 0;
}
int gui_update (void)
{
return 0;
}
void gui_exit (void)
{
}
void gui_fps (int x)
{
}
void gui_led (int led, int on)
{
}
void gui_hd_led (int led)
{
}
void gui_cd_led (int led)
{
}
void gui_filename (int num, const char *name)
{
}
static void getline (char *p)
{
}
void gui_handle_events (void)
{
}
void gui_changesettings (void)
{
}
void gui_update_gfx (void)
{
}
void gui_lock (void)
{
}
void gui_unlock (void)
{
}
void gui_message (const char *format,...)
{
char msg[2048];
va_list parms;
va_start (parms,format);
vsprintf ( msg, format, parms);
va_end (parms);
write_log (msg);
}
| 946 | C | .c | 68 | 11.691176 | 45 | 0.66317 | libretro/libretro-uae | 112 | 60 | 28 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,292,975 | logging.c | libretro_libretro-uae/sources/src/logging.c | #include "uae/log.h"
#include <stdio.h>
#include <stdarg.h>
void UAECALL uae_log(const char *format, ...)
{
/* Redirect UAE_LOG_VA_ARGS_FULL to use write_log instead */
#define uae_log write_log
UAE_LOG_VA_ARGS_FULL(format);
#undef uae_log
}
| 245 | C | .c | 10 | 23.2 | 61 | 0.726496 | libretro/libretro-uae | 112 | 60 | 28 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,293,000 | gtkui.c | libretro_libretro-uae/sources/src/gtkui.c | /*
* UAE - the Un*x Amiga Emulator
*
* Yet Another User Interface for the X11 version
*
* Copyright 1997, 1998 Bernd Schmidt
* Copyright 1998 Michael Krause
*
* The Tk GUI doesn't work.
* The X Forms Library isn't available as source, and there aren't any
* binaries compiled against glibc
*
* So let's try this...
*/
#include "sysconfig.h"
#include "sysdeps.h"
#include "config.h"
#include "options.h"
#include "uae.h"
#include "memory.h"
#include "custom.h"
#include "gui.h"
#include "newcpu.h"
#include "autoconf.h"
#include "threaddep/thread.h"
#include "sounddep/sound.h"
#include "savestate.h"
#include "compemu.h"
#include <gtk/gtk.h>
#include <gdk/gdk.h>
/* One of the 1.1.6 "features" is a gratuitous name change */
#ifndef HAVE_GTK_FEATURES_1_1_6
#define gtk_container_set_border_width gtk_container_border_width
#endif
/* Likewise for 1.1.8. */
#ifndef HAVE_GTK_FEATURES_1_1_8
#define gtk_label_set_text gtk_label_set
#endif
/* This is beginning to suck... */
#ifndef HAVE_GTK_FEATURES_1_1_13
#define gtk_toggle_button_set_active gtk_toggle_button_set_state
#endif
static int gui_active;
static GtkWidget *gui_window;
static GtkWidget *pause_uae_widget, *snap_save_widget, *snap_load_widget;
static GtkWidget *chipsize_widget[5];
static GtkWidget *bogosize_widget[4];
static GtkWidget *fastsize_widget[5];
static GtkWidget *z3size_widget[10];
static GtkWidget *p96size_widget[7];
static GtkWidget *rom_text_widget, *key_text_widget;
static GtkWidget *rom_change_widget, *key_change_widget;
static GtkWidget *disk_insert_widget[4], *disk_eject_widget[4], *disk_text_widget[4];
static char *new_disk_string[4];
static GtkAdjustment *cpuspeed_adj;
static GtkWidget *cpuspeed_widgets[4], *cpuspeed_scale;
static GtkWidget *cpu_widget[5], *a24m_widget, *ccpu_widget;
static GtkWidget *sound_widget[4], *sound_bits_widget[2], *sound_freq_widget[3], *sound_ch_widget[3];
static GtkWidget *coll_widget[4], *cslevel_widget[4];
static GtkWidget *fcop_widget;
static GtkAdjustment *framerate_adj;
static GtkWidget *bimm_widget, *b32_widget, *afscr_widget, *pfscr_widget;
static GtkWidget *compbyte_widget[4], *compword_widget[4], *complong_widget[4];
static GtkWidget *compaddr_widget[4], *compnf_widget[2], *comp_midopt_widget[2];
static GtkWidget *comp_lowopt_widget[2], *compfpu_widget[2], *comp_hardflush_widget[2];
static GtkWidget *comp_constjump_widget[2];
static GtkAdjustment *cachesize_adj;
static GtkWidget *joy_widget[2][6];
static GtkWidget *led_widgets[5];
static GdkColor led_on[5], led_off[5];
static unsigned int prevledstate;
static GtkWidget *hdlist_widget;
static int selected_hd_row;
static GtkWidget *hdchange_button, *hddel_button;
static GtkWidget *volname_entry, *path_entry;
static GtkWidget *dirdlg;
static char dirdlg_volname[256], dirdlg_path[256];
static smp_comm_pipe to_gui_pipe, from_gui_pipe;
static uae_sem_t gui_sem, gui_init_sem, gui_quit_sem; /* gui_sem protects the DFx fields */
static volatile int quit_gui = 0, quitted_gui = 0;
static void save_config (void)
{
FILE *f;
char tmp[257];
/* Backup the options file. */
strcpy (tmp, optionsfile);
strcat (tmp, "~");
rename (optionsfile, tmp);
f = fopen (optionsfile, "w");
if (f == NULL) {
write_log ("Error saving options file!\n");
return;
}
save_options (f, &currprefs);
fclose (f);
}
static int nr_for_led (GtkWidget *led)
{
int i;
i = 0;
while (led_widgets[i] != led)
i++;
return i;
}
static void enable_disk_buttons (int enable)
{
int i;
for (i = 0; i < 4; i++) {
gtk_widget_set_sensitive (disk_insert_widget[i], enable);
gtk_widget_set_sensitive (disk_eject_widget[i], enable);
}
}
static void enable_snap_buttons (int enable)
{
gtk_widget_set_sensitive (snap_save_widget, enable);
gtk_widget_set_sensitive (snap_load_widget, enable);
}
static void set_cpu_state (void)
{
int i;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (a24m_widget), changed_prefs.address_space_24 != 0);
gtk_widget_set_sensitive (a24m_widget, changed_prefs.cpu_level > 1 && changed_prefs.cpu_level < 4);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ccpu_widget), changed_prefs.cpu_compatible != 0);
gtk_widget_set_sensitive (ccpu_widget, changed_prefs.cpu_level == 0);
gtk_widget_set_sensitive (cpuspeed_scale, changed_prefs.m68k_speed > 0);
for (i = 0; i < 10; i++)
gtk_widget_set_sensitive (z3size_widget[i],
changed_prefs.cpu_level >= 2 && ! changed_prefs.address_space_24);
}
static void set_cpu_widget (void)
{
int nr = changed_prefs.cpu_level;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cpu_widget[nr]), TRUE);
nr = currprefs.m68k_speed + 1 < 3 ? currprefs.m68k_speed + 1 : 2;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cpuspeed_widgets[nr]), TRUE);
}
static void set_gfx_state (void)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bimm_widget), currprefs.immediate_blits != 0);
#if 0
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (b32_widget), currprefs.blits_32bit_enabled != 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (afscr_widget), currprefs.gfx_afullscreen != 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pfscr_widget), currprefs.gfx_pfullscreen != 0);
#endif
}
static void set_chipset_state (void)
{
int t0 = 0;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (coll_widget[currprefs.collision_level]), TRUE);
if (currprefs.chipset_mask & CSMASK_AGA)
t0 = 3;
else if (currprefs.chipset_mask & CSMASK_ECS_DENISE)
t0 = 2;
else if (currprefs.chipset_mask & CSMASK_ECS_AGNUS)
t0 = 1;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cslevel_widget[t0]), TRUE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fcop_widget), currprefs.fast_copper != 0);
}
static void set_sound_state (void)
{
int stereo = currprefs.stereo + currprefs.mixed_stereo;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sound_widget[currprefs.produce_sound]), 1);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sound_ch_widget[stereo]), 1);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sound_bits_widget[currprefs.sound_bits == 16]), 1);
}
static void set_mem_state (void)
{
int t, t2;
t = 0;
t2 = currprefs.chipmem_size;
while (t < 4 && t2 > 0x80000)
t++, t2 >>= 1;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chipsize_widget[t]), 1);
t = 0;
t2 = currprefs.bogomem_size;
while (t < 3 && t2 >= 0x80000)
t++, t2 >>= 1;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bogosize_widget[t]), 1);
t = 0;
t2 = currprefs.fastmem_size;
while (t < 4 && t2 >= 0x100000)
t++, t2 >>= 1;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fastsize_widget[t]), 1);
t = 0;
t2 = currprefs.z3fastmem_size;
while (t < 9 && t2 >= 0x100000)
t++, t2 >>= 1;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (z3size_widget[t]), 1);
t = 0;
t2 = currprefs.gfxmem_size;
while (t < 6 && t2 >= 0x100000)
t++, t2 >>= 1;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (p96size_widget[t]), 1);
gtk_label_set_text (GTK_LABEL (rom_text_widget), currprefs.romfile);
gtk_label_set_text (GTK_LABEL (key_text_widget), currprefs.keyfile);
}
static void set_comp_state (void)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (compbyte_widget[currprefs.comptrustbyte]), 1);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (compword_widget[currprefs.comptrustword]), 1);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (complong_widget[currprefs.comptrustlong]), 1);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (compaddr_widget[currprefs.comptrustnaddr]), 1);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (compnf_widget[currprefs.compnf]), 1);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (comp_hardflush_widget[currprefs.comp_hardflush]), 1);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (comp_constjump_widget[currprefs.comp_constjump]), 1);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (compfpu_widget[currprefs.compfpu]), 1);
#if USE_OPTIMIZER
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (comp_midopt_widget[currprefs.comp_midopt]), 1);
#endif
#if USE_LOW_OPTIMIZER
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (comp_lowopt_widget[currprefs.comp_lowopt]), 1);
#endif
}
static void set_joy_state (void)
{
int j0t = changed_prefs.jport0;
int j1t = changed_prefs.jport1;
int i;
if (j0t == j1t) {
/* Can't happen */
j0t++;
j0t %= 6;
}
for (i = 0; i < 6; i++) {
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (joy_widget[0][i]), j0t == i);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (joy_widget[1][i]), j1t == i);
gtk_widget_set_sensitive (joy_widget[0][i], j1t != i);
gtk_widget_set_sensitive (joy_widget[1][i], j0t != i);
}
}
static void set_hd_state (void)
{
char texts[9][256];
char *tptrs[] = { texts[0], texts[1], texts[2], texts[3], texts[4], texts[5], texts[6], texts[7], texts[8] };
int nr = nr_units (currprefs.mountinfo);
int i;
gtk_clist_freeze (GTK_CLIST (hdlist_widget));
gtk_clist_clear (GTK_CLIST (hdlist_widget));
for (i = 0; i < nr; i++) {
int secspertrack, surfaces, reserved, blocksize, size;
int cylinders, readonly;
char *volname, *rootdir;
char *failure;
/* We always use currprefs.mountinfo for the GUI. The filesystem
code makes a private copy which is updated every reset. */
failure = get_filesys_unit (currprefs.mountinfo, i,
&volname, &rootdir, &readonly,
&secspertrack, &surfaces, &reserved,
&cylinders, &size, &blocksize);
if (is_hardfile (currprefs.mountinfo, i)) {
sprintf (texts[0], "DH%d", i );
sprintf (texts[3], "%d", surfaces);
sprintf (texts[4], "%d", cylinders);
sprintf (texts[5], "%d", secspertrack);
sprintf (texts[6], "%d", reserved);
sprintf (texts[7], "%d", size);
sprintf (texts[8], "%d", blocksize);
} else {
strcpy (texts[0], volname);
strcpy (texts[3], "n/a");
strcpy (texts[4], "n/a");
strcpy (texts[5], "n/a");
strcpy (texts[6], "n/a");
strcpy (texts[7], "n/a");
strcpy (texts[8], "n/a");
}
strcpy (texts[1], rootdir);
strcpy (texts[2], readonly ? "y" : "n");
gtk_clist_append (GTK_CLIST (hdlist_widget), tptrs);
}
gtk_clist_thaw (GTK_CLIST (hdlist_widget));
gtk_widget_set_sensitive (hdchange_button, FALSE);
gtk_widget_set_sensitive (hddel_button, FALSE);
}
static void draw_led (int nr)
{
GtkWidget *thing = led_widgets[nr];
GdkWindow *window = thing->window;
GdkGC *gc = gdk_gc_new (window);
GdkColor *col;
if (gui_ledstate & (1 << nr))
col = led_on + nr;
else
col = led_off + nr;
gdk_gc_set_foreground (gc, col);
gdk_draw_rectangle (window, gc, 1, 0, 0, -1, -1);
gdk_gc_destroy (gc);
}
static int my_idle (void)
{
unsigned int leds = gui_ledstate;
int i;
if (quit_gui) {
gtk_main_quit ();
goto out;
}
while (comm_pipe_has_data (&to_gui_pipe)) {
int cmd = read_comm_pipe_int_blocking (&to_gui_pipe);
int n;
switch (cmd) {
case 0:
n = read_comm_pipe_int_blocking (&to_gui_pipe);
gtk_label_set_text (GTK_LABEL (disk_text_widget[n]), currprefs.df[n]);
break;
case 1:
/* Initialization. */
set_cpu_widget ();
set_cpu_state ();
set_gfx_state ();
set_joy_state ();
set_sound_state ();
set_comp_state ();
set_mem_state ();
set_hd_state ();
set_chipset_state ();
gtk_widget_show (gui_window);
uae_sem_post (&gui_init_sem);
gui_active = 1;
break;
}
}
for (i = 0; i < 5; i++) {
unsigned int mask = 1 << i;
unsigned int on = leds & mask;
if (on == (prevledstate & mask))
continue;
/* printf(": %d %d\n", i, on);*/
draw_led (i);
}
prevledstate = leds;
out:
return 1;
}
static int find_current_toggle (GtkWidget **widgets, int count)
{
int i;
for (i = 0; i < count; i++)
if (GTK_TOGGLE_BUTTON (*widgets++)->active)
return i;
write_log ("GTKUI: Can't happen!\n");
return -1;
}
static void joy_changed (void)
{
if (! gui_active)
return;
changed_prefs.jport0 = find_current_toggle (joy_widget[0], 6);
changed_prefs.jport1 = find_current_toggle (joy_widget[1], 6);
set_joy_state ();
}
static void coll_changed (void)
{
changed_prefs.collision_level = find_current_toggle (coll_widget, 4);
}
static void cslevel_changed (void)
{
int t = find_current_toggle (cslevel_widget, 4);
int t1 = 0;
if (t > 0)
t1 |= CSMASK_ECS_AGNUS;
if (t > 1)
t1 |= CSMASK_ECS_DENISE;
if (t > 2)
t1 |= CSMASK_AGA;
changed_prefs.chipset_mask = t1;
}
static void custom_changed (void)
{
changed_prefs.gfx_framerate = framerate_adj->value;
changed_prefs.immediate_blits = GTK_TOGGLE_BUTTON (bimm_widget)->active;
changed_prefs.fast_copper = GTK_TOGGLE_BUTTON (fcop_widget)->active;
#if 0
changed_prefs.blits_32bit_enabled = GTK_TOGGLE_BUTTON (b32_widget)->active;
changed_prefs.gfx_afullscreen = GTK_TOGGLE_BUTTON (afscr_widget)->active;
changed_prefs.gfx_pfullscreen = GTK_TOGGLE_BUTTON (pfscr_widget)->active;
#endif
}
static void cpuspeed_changed (void)
{
int which = find_current_toggle (cpuspeed_widgets, 3);
changed_prefs.m68k_speed = (which == 0 ? -1
: which == 1 ? 0
: cpuspeed_adj->value);
set_cpu_state ();
}
static void cputype_changed (void)
{
int i, oldcl;
if (! gui_active)
return;
oldcl = changed_prefs.cpu_level;
changed_prefs.cpu_level = find_current_toggle (cpu_widget, 5);
changed_prefs.cpu_compatible = GTK_TOGGLE_BUTTON (ccpu_widget)->active;
changed_prefs.address_space_24 = GTK_TOGGLE_BUTTON (a24m_widget)->active;
if (changed_prefs.cpu_level != 0)
changed_prefs.cpu_compatible = 0;
/* 68000/68010 always have a 24 bit address space. */
if (changed_prefs.cpu_level < 2)
changed_prefs.address_space_24 = 1;
/* Changing from 68000/68010 to 68020 should set a sane default. */
else if (oldcl < 2)
changed_prefs.address_space_24 = 0;
set_cpu_state ();
}
static void chipsize_changed (void)
{
int t = find_current_toggle (chipsize_widget, 5);
changed_prefs.chipmem_size = 0x80000 << t;
for (t = 0; t < 5; t++)
gtk_widget_set_sensitive (fastsize_widget[t], changed_prefs.chipmem_size <= 0x200000);
if (changed_prefs.chipmem_size > 0x200000) {
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fastsize_widget[0]), 1);
changed_prefs.fastmem_size = 0;
}
}
static void bogosize_changed (void)
{
int t = find_current_toggle (bogosize_widget, 4);
changed_prefs.bogomem_size = (0x40000 << t) & ~0x40000;
}
static void fastsize_changed (void)
{
int t = find_current_toggle (fastsize_widget, 5);
changed_prefs.fastmem_size = (0x80000 << t) & ~0x80000;
}
static void z3size_changed (void)
{
int t = find_current_toggle (z3size_widget, 10);
changed_prefs.z3fastmem_size = (0x80000 << t) & ~0x80000;
}
static void p96size_changed (void)
{
int t = find_current_toggle (p96size_widget, 7);
changed_prefs.gfxmem_size = (0x80000 << t) & ~0x80000;
}
static void sound_changed (void)
{
changed_prefs.produce_sound = find_current_toggle (sound_widget, 4);
changed_prefs.stereo = find_current_toggle (sound_ch_widget, 3);
changed_prefs.mixed_stereo = 0;
if (changed_prefs.stereo == 2)
changed_prefs.mixed_stereo = changed_prefs.stereo = 1;
changed_prefs.sound_bits = (find_current_toggle (sound_bits_widget, 2) + 1) * 8;
}
static void comp_changed (void)
{
changed_prefs.cachesize=cachesize_adj->value;
changed_prefs.comptrustbyte = find_current_toggle (compbyte_widget, 4);
changed_prefs.comptrustword = find_current_toggle (compword_widget, 4);
changed_prefs.comptrustlong = find_current_toggle (complong_widget, 4);
changed_prefs.comptrustnaddr = find_current_toggle (compaddr_widget, 4);
changed_prefs.compnf = find_current_toggle (compnf_widget, 2);
changed_prefs.comp_hardflush = find_current_toggle (comp_hardflush_widget, 2);
changed_prefs.comp_constjump = find_current_toggle (comp_constjump_widget, 2);
changed_prefs.compfpu= find_current_toggle (compfpu_widget, 2);
#if USE_OPTIMIZER
changed_prefs.comp_midopt = find_current_toggle (comp_midopt_widget, 2);
#endif
#if USE_LOW_OPTIMIZER
changed_prefs.comp_lowopt = find_current_toggle (comp_lowopt_widget, 2);
#endif
}
static void did_reset (void)
{
if (quit_gui)
return;
write_comm_pipe_int (&from_gui_pipe, 2, 1);
}
static void did_debug (void)
{
if (quit_gui)
return;
write_comm_pipe_int (&from_gui_pipe, 3, 1);
}
static void did_quit (void)
{
if (quit_gui)
return;
write_comm_pipe_int (&from_gui_pipe, 4, 1);
}
static void did_eject (GtkWidget *w, gpointer data)
{
if (quit_gui)
return;
write_comm_pipe_int (&from_gui_pipe, 0, 0);
write_comm_pipe_int (&from_gui_pipe, (int)data, 1);
}
static void pause_uae (GtkWidget *widget, gpointer data)
{
if (quit_gui)
return;
write_comm_pipe_int (&from_gui_pipe, GTK_TOGGLE_BUTTON (widget)->active ? 5 : 6, 1);
}
static void end_pause_uae (void)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pause_uae_widget), FALSE);
}
static int filesel_active = -1;
static GtkWidget *disk_selector;
static int snapsel_active = -1;
static char *gui_snapname, *gui_romname, *gui_keyname;
static void did_close_insert (gpointer data)
{
filesel_active = -1;
enable_disk_buttons (1);
}
static void did_insert_select (GtkObject *o)
{
char *s = gtk_file_selection_get_filename (GTK_FILE_SELECTION (disk_selector));
printf ("%d %s\n", filesel_active, s);
if (quit_gui)
return;
uae_sem_wait (&gui_sem);
if (new_disk_string[filesel_active] != 0)
free (new_disk_string[filesel_active]);
new_disk_string[filesel_active] = strdup (s);
uae_sem_post (&gui_sem);
write_comm_pipe_int (&from_gui_pipe, 1, 0);
write_comm_pipe_int (&from_gui_pipe, filesel_active, 1);
filesel_active = -1;
enable_disk_buttons (1);
gtk_widget_destroy (disk_selector);
}
static char fsbuffer[100];
static GtkWidget *make_file_selector (const char *title,
void (*insertfunc)(GtkObject *),
void (*closefunc)(gpointer))
{
GtkWidget *p = gtk_file_selection_new (title);
gtk_signal_connect (GTK_OBJECT (p), "destroy", (GtkSignalFunc) closefunc, p);
gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (p)->ok_button),
"clicked", (GtkSignalFunc) insertfunc,
GTK_OBJECT (p));
gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (p)->cancel_button),
"clicked", (GtkSignalFunc) gtk_widget_destroy,
GTK_OBJECT (p));
#if 0
gtk_window_set_title (GTK_WINDOW (p), title);
#endif
gtk_widget_show (p);
return p;
}
static void filesel_set_path (GtkWidget *p, const char *path)
{
size_t len = strlen (path);
if (len > 0 && ! access (path, R_OK)) {
char *tmp = xmalloc (len + 2);
strcpy (tmp, path);
strcat (tmp, "/");
gtk_file_selection_set_filename (GTK_FILE_SELECTION (p),
tmp);
}
}
static void did_insert (GtkWidget *w, gpointer data)
{
int n = (int)data;
if (filesel_active != -1)
return;
filesel_active = n;
enable_disk_buttons (0);
sprintf (fsbuffer, "Select a disk image file for DF%d", n);
disk_selector = make_file_selector (fsbuffer, did_insert_select, did_close_insert);
filesel_set_path (disk_selector, currprefs.path_floppy);
}
static gint driveled_event (GtkWidget *thing, GdkEvent *event)
{
int lednr = nr_for_led (thing);
switch (event->type) {
case GDK_MAP:
draw_led (lednr);
break;
case GDK_EXPOSE:
draw_led (lednr);
break;
default:
break;
}
return 0;
}
static GtkWidget *snap_selector;
static void did_close_snap (gpointer gdata)
{
snapsel_active = -1;
enable_snap_buttons (1);
}
static void did_snap_select (GtkObject *o)
{
char *s = gtk_file_selection_get_filename (GTK_FILE_SELECTION (snap_selector));
if (quit_gui)
return;
uae_sem_wait (&gui_sem);
gui_snapname = strdup (s);
uae_sem_post (&gui_sem);
write_comm_pipe_int (&from_gui_pipe, 7, 0);
write_comm_pipe_int (&from_gui_pipe, snapsel_active, 1);
snapsel_active = -1;
enable_snap_buttons (1);
gtk_widget_destroy (snap_selector);
}
static void did_loadstate (void)
{
if (snapsel_active != -1)
return;
snapsel_active = STATE_DORESTORE;
enable_snap_buttons (0);
snap_selector = make_file_selector ("Select a state file to restore",
did_snap_select, did_close_snap);
}
static void did_savestate (void)
{
if (snapsel_active != -1)
return;
snapsel_active = STATE_DOSAVE;
enable_snap_buttons (0);
snap_selector = make_file_selector ("Select a filename for the state file",
did_snap_select, did_close_snap);
}
static GtkWidget *rom_selector;
static void did_close_rom (gpointer gdata)
{
gtk_widget_set_sensitive (rom_change_widget, 1);
}
static void did_rom_select (GtkObject *o)
{
char *s = gtk_file_selection_get_filename (GTK_FILE_SELECTION (rom_selector));
if (quit_gui)
return;
gtk_widget_set_sensitive (rom_change_widget, 1);
uae_sem_wait (&gui_sem);
gui_romname = strdup (s);
uae_sem_post (&gui_sem);
write_comm_pipe_int (&from_gui_pipe, 8, 0);
gtk_label_set_text (GTK_LABEL (rom_text_widget), gui_romname);
gtk_widget_destroy (rom_selector);
}
static void did_romchange (GtkWidget *w, gpointer data)
{
gtk_widget_set_sensitive (rom_change_widget, 0);
rom_selector = make_file_selector ("Select a ROM file",
did_rom_select, did_close_rom);
filesel_set_path (rom_selector, currprefs.path_rom);
}
static GtkWidget *key_selector;
static void did_close_key (gpointer gdata)
{
gtk_widget_set_sensitive (key_change_widget, 1);
}
static void did_key_select (GtkObject *o)
{
char *s = gtk_file_selection_get_filename (GTK_FILE_SELECTION (key_selector));
if (quit_gui)
return;
gtk_widget_set_sensitive (key_change_widget, 1);
uae_sem_wait (&gui_sem);
gui_keyname = strdup (s);
uae_sem_post (&gui_sem);
write_comm_pipe_int (&from_gui_pipe, 9, 0);
gtk_label_set_text (GTK_LABEL (key_text_widget), gui_keyname);
gtk_widget_destroy (key_selector);
}
static void did_keychange (GtkWidget *w, gpointer data)
{
gtk_widget_set_sensitive (key_change_widget, 0);
key_selector = make_file_selector ("Select a Kickstart key file",
did_key_select, did_close_key);
filesel_set_path (key_selector, currprefs.path_rom);
}
static void add_empty_vbox (GtkWidget *tobox)
{
GtkWidget *thing = gtk_vbox_new (FALSE, 0);
gtk_widget_show (thing);
gtk_box_pack_start (GTK_BOX (tobox), thing, TRUE, TRUE, 0);
}
static void add_empty_hbox (GtkWidget *tobox)
{
GtkWidget *thing = gtk_hbox_new (FALSE, 0);
gtk_widget_show (thing);
gtk_box_pack_start (GTK_BOX (tobox), thing, TRUE, TRUE, 0);
}
static void add_centered_to_vbox (GtkWidget *vbox, GtkWidget *w)
{
GtkWidget *hbox = gtk_hbox_new (TRUE, 0);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
}
static GtkWidget *make_labelled_widget (const char *str, GtkWidget *thing)
{
GtkWidget *label = gtk_label_new (str);
GtkWidget *hbox2 = gtk_hbox_new (FALSE, 4);
gtk_widget_show (label);
gtk_widget_show (thing);
gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox2), thing, FALSE, TRUE, 0);
return hbox2;
}
static GtkWidget *add_labelled_widget_centered (const char *str, GtkWidget *thing, GtkWidget *vbox)
{
GtkWidget *w = make_labelled_widget (str, thing);
gtk_widget_show (w);
add_centered_to_vbox (vbox, w);
return w;
}
static int make_radio_group (const char **labels, GtkWidget *tobox,
GtkWidget **saveptr, gint t1, gint t2,
void (*sigfunc) (void), int count, GSList *group)
{
int t = 0;
while (*labels && (count == -1 || count-- > 0)) {
GtkWidget *thing = gtk_radio_button_new_with_label (group, *labels++);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (thing));
*saveptr++ = thing;
gtk_widget_show (thing);
gtk_box_pack_start (GTK_BOX (tobox), thing, t1, t2, 0);
gtk_signal_connect (GTK_OBJECT (thing), "clicked", (GtkSignalFunc) sigfunc, NULL);
t++;
}
return t;
}
static GtkWidget *make_radio_group_box (const char *title, const char **labels,
GtkWidget **saveptr, int horiz,
void (*sigfunc) (void))
{
GtkWidget *frame, *newbox;
frame = gtk_frame_new (title);
newbox = (horiz ? gtk_hbox_new : gtk_vbox_new) (FALSE, 4);
gtk_widget_show (newbox);
gtk_container_set_border_width (GTK_CONTAINER (newbox), 4);
gtk_container_add (GTK_CONTAINER (frame), newbox);
make_radio_group (labels, newbox, saveptr, horiz, !horiz, sigfunc, -1, NULL);
return frame;
}
static GtkWidget *make_radio_group_box_1 (const char *title, const char **labels,
GtkWidget **saveptr, int horiz,
void (*sigfunc) (void), int elts_per_column)
{
GtkWidget *frame, *newbox;
GtkWidget *column;
GSList *group = 0;
frame = gtk_frame_new (title);
column = (horiz ? gtk_vbox_new : gtk_hbox_new) (FALSE, 4);
gtk_container_add (GTK_CONTAINER (frame), column);
gtk_widget_show (column);
while (*labels) {
int count;
newbox = (horiz ? gtk_hbox_new : gtk_vbox_new) (FALSE, 4);
gtk_widget_show (newbox);
gtk_container_set_border_width (GTK_CONTAINER (newbox), 4);
gtk_container_add (GTK_CONTAINER (column), newbox);
count = make_radio_group (labels, newbox, saveptr, horiz, !horiz, sigfunc, elts_per_column, group);
labels += count;
saveptr += count;
group = gtk_radio_button_group (GTK_RADIO_BUTTON (saveptr[-1]));
}
return frame;
}
static GtkWidget *make_led (int nr)
{
GtkWidget *subframe, *the_led, *thing;
GdkColormap *colormap;
the_led = gtk_vbox_new (FALSE, 0);
gtk_widget_show (the_led);
thing = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_box_pack_start (GTK_BOX (the_led), thing, TRUE, TRUE, 0);
gtk_widget_show (thing);
subframe = gtk_frame_new (NULL);
gtk_box_pack_start (GTK_BOX (the_led), subframe, TRUE, TRUE, 0);
gtk_widget_show (subframe);
thing = gtk_drawing_area_new ();
gtk_drawing_area_size (GTK_DRAWING_AREA (thing), 20, 5);
gtk_widget_set_events (thing, GDK_EXPOSURE_MASK);
gtk_container_add (GTK_CONTAINER (subframe), thing);
colormap = gtk_widget_get_colormap (thing);
led_on[nr].red = nr == 0 ? 0xEEEE : 0xCCCC;
led_on[nr].green = nr == 0 ? 0: 0xFFFF;
led_on[nr].blue = 0;
led_on[nr].pixel = 0;
led_off[nr].red = 0;
led_off[nr].green = 0;
led_off[nr].blue = 0;
led_off[nr].pixel = 0;
gdk_color_alloc (colormap, led_on + nr);
gdk_color_alloc (colormap, led_off + nr);
led_widgets[nr] = thing;
gtk_signal_connect (GTK_OBJECT (thing), "event",
(GtkSignalFunc) driveled_event, (gpointer) thing);
gtk_widget_show (thing);
thing = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_box_pack_start (GTK_BOX (the_led), thing, TRUE, TRUE, 0);
gtk_widget_show (thing);
return the_led;
}
static GtkWidget *make_file_container (const char *title, GtkWidget *vbox)
{
GtkWidget *thing = gtk_frame_new (title);
GtkWidget *buttonbox = gtk_hbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (buttonbox), 4);
gtk_container_add (GTK_CONTAINER (thing), buttonbox);
gtk_box_pack_start (GTK_BOX (vbox), thing, FALSE, TRUE, 0);
gtk_widget_show (buttonbox);
gtk_widget_show (thing);
return buttonbox;
}
static GtkWidget *make_file_widget (GtkWidget *buttonbox)
{
GtkWidget *thing, *subthing;
GtkWidget *subframe = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (subframe), GTK_SHADOW_ETCHED_OUT);
gtk_box_pack_start (GTK_BOX (buttonbox), subframe, TRUE, TRUE, 0);
gtk_widget_show (subframe);
subthing = gtk_vbox_new (FALSE, 0);
gtk_widget_show (subthing);
gtk_container_add (GTK_CONTAINER (subframe), subthing);
thing = gtk_label_new ("");
gtk_widget_show (thing);
gtk_box_pack_start (GTK_BOX (subthing), thing, TRUE, TRUE, 0);
return thing;
}
static void make_floppy_disks (GtkWidget *vbox)
{
GtkWidget *thing, *subthing, *subframe, *buttonbox;
char buf[5];
int i;
add_empty_vbox (vbox);
for (i = 0; i < 4; i++) {
/* Frame with an hbox and the "DFx:" title */
sprintf (buf, "DF%d:", i);
buttonbox = make_file_container (buf, vbox);
/* LED */
subthing = make_led (i + 1);
gtk_box_pack_start (GTK_BOX (buttonbox), subthing, FALSE, TRUE, 0);
/* Current file display */
disk_text_widget[i] = make_file_widget (buttonbox);
/* Now, the buttons. */
thing = gtk_button_new_with_label ("Eject");
gtk_box_pack_start (GTK_BOX (buttonbox), thing, FALSE, TRUE, 0);
gtk_widget_show (thing);
disk_eject_widget[i] = thing;
gtk_signal_connect (GTK_OBJECT (thing), "clicked", (GtkSignalFunc) did_eject, (gpointer) i);
thing = gtk_button_new_with_label ("Insert");
gtk_box_pack_start (GTK_BOX (buttonbox), thing, FALSE, TRUE, 0);
gtk_widget_show (thing);
disk_insert_widget[i] = thing;
gtk_signal_connect (GTK_OBJECT (thing), "clicked", (GtkSignalFunc) did_insert, (gpointer) i);
}
add_empty_vbox (vbox);
}
static GtkWidget *make_cpu_speed_sel (void)
{
int t;
static const char *labels[] = {
"Optimize for host CPU speed","Approximate 68000/7MHz speed", "Adjustable",
NULL
};
GtkWidget *frame, *newbox;
frame = gtk_frame_new ("CPU speed");
newbox = gtk_vbox_new (FALSE, 4);
gtk_widget_show (newbox);
gtk_container_set_border_width (GTK_CONTAINER (newbox), 4);
gtk_container_add (GTK_CONTAINER (frame), newbox);
make_radio_group (labels, newbox, cpuspeed_widgets, 0, 1, cpuspeed_changed, -1, NULL);
t = currprefs.m68k_speed > 0 ? currprefs.m68k_speed : 4 * CYCLE_UNIT;
cpuspeed_adj = GTK_ADJUSTMENT (gtk_adjustment_new (t, 1.0, 5120.0, 1.0, 1.0, 1.0));
gtk_signal_connect (GTK_OBJECT (cpuspeed_adj), "value_changed",
GTK_SIGNAL_FUNC (cpuspeed_changed), NULL);
cpuspeed_scale = gtk_hscale_new (cpuspeed_adj);
gtk_range_set_update_policy (GTK_RANGE (cpuspeed_scale), GTK_UPDATE_DELAYED);
gtk_scale_set_digits (GTK_SCALE (cpuspeed_scale), 0);
gtk_scale_set_value_pos (GTK_SCALE (cpuspeed_scale), GTK_POS_RIGHT);
cpuspeed_scale = add_labelled_widget_centered ("Cycles per instruction:", cpuspeed_scale, newbox);
return frame;
}
static void make_cpu_widgets (GtkWidget *vbox)
{
int i;
GtkWidget *newbox, *hbox, *frame;
GtkWidget *thing;
static const char *radiolabels[] = {
"68000", "68010", "68020", "68020+68881", "68040",
NULL
};
add_empty_vbox (vbox);
hbox = gtk_hbox_new (FALSE, 0);
add_empty_vbox (hbox);
newbox = make_radio_group_box ("CPU type", radiolabels, cpu_widget, 0, cputype_changed);
gtk_widget_show (newbox);
gtk_box_pack_start (GTK_BOX (hbox), newbox, FALSE, FALSE, 0);
newbox = make_cpu_speed_sel ();
gtk_widget_show (newbox);
gtk_box_pack_start (GTK_BOX (hbox), newbox, FALSE, FALSE, 0);
add_empty_vbox (hbox);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
frame = gtk_frame_new ("CPU flags");
add_centered_to_vbox (vbox, frame);
gtk_widget_show (frame);
newbox = gtk_vbox_new (FALSE, 4);
gtk_widget_show (newbox);
gtk_container_set_border_width (GTK_CONTAINER (newbox), 4);
gtk_container_add (GTK_CONTAINER (frame), newbox);
a24m_widget = gtk_check_button_new_with_label ("24 bit address space");
add_centered_to_vbox (newbox, a24m_widget);
gtk_widget_show (a24m_widget);
ccpu_widget = gtk_check_button_new_with_label ("Slow but compatible");
add_centered_to_vbox (newbox, ccpu_widget);
gtk_widget_show (ccpu_widget);
add_empty_vbox (vbox);
gtk_signal_connect (GTK_OBJECT (ccpu_widget), "clicked",
(GtkSignalFunc) cputype_changed, NULL);
gtk_signal_connect (GTK_OBJECT (a24m_widget), "clicked",
(GtkSignalFunc) cputype_changed, NULL);
}
static void make_gfx_widgets (GtkWidget *vbox)
{
GtkWidget *thing, *frame, *newbox, *hbox;
static const char *p96labels[] = {
"None", "1 MB", "2 MB", "4 MB", "8 MB", "16 MB", "32 MB", NULL
};
add_empty_vbox (vbox);
hbox = gtk_hbox_new (FALSE, 10);
gtk_widget_show (hbox);
add_centered_to_vbox (vbox, hbox);
frame = make_radio_group_box_1 ("P96 RAM", p96labels, p96size_widget, 0, p96size_changed, 4);
gtk_widget_show (frame);
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, TRUE, 0);
frame = gtk_frame_new ("Miscellaneous");
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
newbox = gtk_vbox_new (FALSE, 4);
gtk_widget_show (newbox);
gtk_container_set_border_width (GTK_CONTAINER (newbox), 4);
gtk_container_add (GTK_CONTAINER (frame), newbox);
framerate_adj = GTK_ADJUSTMENT (gtk_adjustment_new (currprefs.gfx_framerate, 1.0, 21.0, 1.0, 1.0, 1.0));
gtk_signal_connect (GTK_OBJECT (framerate_adj), "value_changed",
GTK_SIGNAL_FUNC (custom_changed), NULL);
thing = gtk_hscale_new (framerate_adj);
gtk_range_set_update_policy (GTK_RANGE (thing), GTK_UPDATE_DELAYED);
gtk_scale_set_digits (GTK_SCALE (thing), 0);
gtk_scale_set_value_pos (GTK_SCALE (thing), GTK_POS_RIGHT);
add_labelled_widget_centered ("Framerate:", thing, newbox);
b32_widget = gtk_check_button_new_with_label ("32 bit blitter");
add_centered_to_vbox (newbox, b32_widget);
#if 0
gtk_widget_show (b32_widget);
#endif
bimm_widget = gtk_check_button_new_with_label ("Immediate blits");
add_centered_to_vbox (newbox, bimm_widget);
gtk_widget_show (bimm_widget);
afscr_widget = gtk_check_button_new_with_label ("Amiga modes fullscreen");
add_centered_to_vbox (newbox, afscr_widget);
#if 0
gtk_widget_show (afscr_widget);
#endif
pfscr_widget = gtk_check_button_new_with_label ("Picasso modes fullscreen");
add_centered_to_vbox (newbox, pfscr_widget);
#if 0
gtk_widget_show (pfscr_widget);
#endif
add_empty_vbox (vbox);
gtk_signal_connect (GTK_OBJECT (bimm_widget), "clicked",
(GtkSignalFunc) custom_changed, NULL);
#if 0
gtk_signal_connect (GTK_OBJECT (b32_widget), "clicked",
(GtkSignalFunc) custom_changed, NULL);
gtk_signal_connect (GTK_OBJECT (afscr_widget), "clicked",
(GtkSignalFunc) custom_changed, NULL);
gtk_signal_connect (GTK_OBJECT (pfscr_widget), "clicked",
(GtkSignalFunc) custom_changed, NULL);
#endif
}
static void make_chipset_widgets (GtkWidget *vbox)
{
GtkWidget *frame, *newbox, *hbox;
static const char *colllabels[] = {
"None (fastest)", "Sprites only", "Sprites & playfields", "Full (very slow)",
NULL
};
static const char *cslevellabels[] = {
"OCS", "ECS Agnus", "Full ECS", "AGA", NULL
};
add_empty_vbox (vbox);
hbox = gtk_hbox_new (FALSE, 10);
gtk_widget_show (hbox);
add_centered_to_vbox (vbox, hbox);
newbox = make_radio_group_box ("Sprite collisions", colllabels, coll_widget, 0, coll_changed);
gtk_widget_show (newbox);
gtk_box_pack_start (GTK_BOX (hbox), newbox, FALSE, TRUE, 0);
newbox = make_radio_group_box ("Chipset", cslevellabels, cslevel_widget, 0, cslevel_changed);
gtk_widget_show (newbox);
gtk_box_pack_start (GTK_BOX (hbox), newbox, FALSE, TRUE, 0);
fcop_widget = gtk_check_button_new_with_label ("Enable copper speedup code");
add_centered_to_vbox (vbox, fcop_widget);
gtk_widget_show (fcop_widget);
gtk_signal_connect (GTK_OBJECT (fcop_widget), "clicked",
(GtkSignalFunc) custom_changed, NULL);
add_empty_vbox (vbox);
}
static void make_sound_widgets (GtkWidget *vbox)
{
GtkWidget *frame, *newbox;
int i;
GtkWidget *hbox;
static const char *soundlabels1[] = {
"None", "No output", "Normal", "Accurate",
NULL
}, *soundlabels2[] = {
"8 bit", "16 bit",
NULL
}, *soundlabels3[] = {
"Mono", "Stereo", "Mixed",
NULL
};
add_empty_vbox (vbox);
newbox = make_radio_group_box ("Mode", soundlabels1, sound_widget, 1, sound_changed);
gtk_widget_show (newbox);
add_centered_to_vbox (vbox, newbox);
hbox = gtk_hbox_new (FALSE, 10);
gtk_widget_show (hbox);
add_centered_to_vbox (vbox, hbox);
newbox = make_radio_group_box ("Channels", soundlabels3, sound_ch_widget, 1, sound_changed);
gtk_widget_show (newbox);
gtk_box_pack_start (GTK_BOX (hbox), newbox, FALSE, TRUE, 0);
newbox = make_radio_group_box ("Resolution", soundlabels2, sound_bits_widget, 1, sound_changed);
gtk_widget_show (newbox);
gtk_box_pack_start (GTK_BOX (hbox), newbox, FALSE, TRUE, 0);
add_empty_vbox (vbox);
}
static void make_mem_widgets (GtkWidget *vbox)
{
GtkWidget *hbox = gtk_hbox_new (FALSE, 10);
GtkWidget *label, *frame;
static const char *chiplabels[] = {
"512 KB", "1 MB", "2 MB", "4 MB", "8 MB", NULL
};
static const char *bogolabels[] = {
"None", "512 KB", "1 MB", "1.8 MB", NULL
};
static const char *fastlabels[] = {
"None", "1 MB", "2 MB", "4 MB", "8 MB", NULL
};
static const char *z3labels[] = {
"None", "1 MB", "2 MB", "4 MB", "8 MB",
"16 MB", "32 MB", "64 MB", "128 MB", "256 MB",
NULL
};
add_empty_vbox (vbox);
{
GtkWidget *buttonbox = make_file_container ("Kickstart ROM file:", vbox);
GtkWidget *thing = gtk_button_new_with_label ("Change");
/* Current file display */
rom_text_widget = make_file_widget (buttonbox);
gtk_box_pack_start (GTK_BOX (buttonbox), thing, FALSE, TRUE, 0);
gtk_widget_show (thing);
rom_change_widget = thing;
gtk_signal_connect (GTK_OBJECT (thing), "clicked", (GtkSignalFunc) did_romchange, 0);
}
{
GtkWidget *buttonbox = make_file_container ("ROM key file for Cloanto Amiga Forever:", vbox);
GtkWidget *thing = gtk_button_new_with_label ("Change");
/* Current file display */
key_text_widget = make_file_widget (buttonbox);
gtk_box_pack_start (GTK_BOX (buttonbox), thing, FALSE, TRUE, 0);
gtk_widget_show (thing);
key_change_widget = thing;
gtk_signal_connect (GTK_OBJECT (thing), "clicked", (GtkSignalFunc) did_keychange, 0);
}
gtk_widget_show (hbox);
add_centered_to_vbox (vbox, hbox);
add_empty_vbox (vbox);
label = gtk_label_new ("These settings take effect after the next reset.");
gtk_widget_show (label);
add_centered_to_vbox (vbox, label);
frame = make_radio_group_box ("Chip Mem", chiplabels, chipsize_widget, 0, chipsize_changed);
gtk_widget_show (frame);
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, TRUE, 0);
frame = make_radio_group_box ("Slow Mem", bogolabels, bogosize_widget, 0, bogosize_changed);
gtk_widget_show (frame);
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, TRUE, 0);
frame = make_radio_group_box ("Fast Mem", fastlabels, fastsize_widget, 0, fastsize_changed);
gtk_widget_show (frame);
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, TRUE, 0);
frame = make_radio_group_box_1 ("Z3 Mem", z3labels, z3size_widget, 0, z3size_changed, 5);
gtk_widget_show (frame);
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, TRUE, 0);
}
static void make_comp_widgets (GtkWidget *vbox)
{
GtkWidget *frame, *newbox;
int i;
GtkWidget *hbox;
static const char *complabels1[] = {
"Direct", "Indirect", "Indirect for KS", "Direct after Picasso",
NULL
},*complabels2[] = {
"Direct", "Indirect", "Indirect for KS", "Direct after Picasso",
NULL
},*complabels3[] = {
"Direct", "Indirect", "Indirect for KS", "Direct after Picasso",
NULL
},*complabels3a[] = {
"Direct", "Indirect", "Indirect for KS", "Direct after Picasso",
NULL
}, *complabels4[] = {
"Always generate", "Only generate when needed",
NULL
}, *complabels5[] = {
"Disable", "Enable",
NULL
}, *complabels6[] = {
"Disable", "Enable",
NULL
}, *complabels7[] = {
"Disable", "Enable",
NULL
}, *complabels8[] = {
"Soft", "Hard",
NULL
}, *complabels9[] = {
"Disable", "Enable",
NULL
};
GtkWidget *thing;
add_empty_vbox (vbox);
newbox = make_radio_group_box ("Byte access", complabels1, compbyte_widget, 1, comp_changed);
gtk_widget_show (newbox);
add_centered_to_vbox (vbox, newbox);
newbox = make_radio_group_box ("Word access", complabels2, compword_widget, 1, comp_changed);
gtk_widget_show (newbox);
add_centered_to_vbox (vbox, newbox);
newbox = make_radio_group_box ("Long access", complabels3, complong_widget, 1, comp_changed);
gtk_widget_show (newbox);
add_centered_to_vbox (vbox, newbox);
newbox = make_radio_group_box ("Address lookup", complabels3a, compaddr_widget, 1, comp_changed);
gtk_widget_show (newbox);
add_centered_to_vbox (vbox, newbox);
newbox = make_radio_group_box ("Flags", complabels4, compnf_widget, 1, comp_changed);
gtk_widget_show (newbox);
add_centered_to_vbox (vbox, newbox);
newbox = make_radio_group_box ("Icache flushes", complabels8, comp_hardflush_widget, 1, comp_changed);
gtk_widget_show (newbox);
add_centered_to_vbox (vbox, newbox);
newbox = make_radio_group_box ("Compile through uncond branch", complabels9, comp_constjump_widget, 1, comp_changed);
gtk_widget_show (newbox);
add_centered_to_vbox (vbox, newbox);
newbox = make_radio_group_box ("JIT FPU compiler", complabels7, compfpu_widget, 1, comp_changed);
gtk_widget_show (newbox);
add_centered_to_vbox (vbox, newbox);
#if USE_OPTIMIZER
newbox = make_radio_group_box ("Mid Level Optimizer", complabels5, comp_midopt_widget, 1, comp_changed);
gtk_widget_show (newbox);
add_centered_to_vbox (vbox, newbox);
#endif
#if USE_LOW_OPTIMIZER
newbox = make_radio_group_box ("Low Level Optimizer", complabels6, comp_lowopt_widget, 1, comp_changed);
gtk_widget_show (newbox);
add_centered_to_vbox (vbox, newbox);
#endif
cachesize_adj = GTK_ADJUSTMENT (gtk_adjustment_new (currprefs.cachesize, 0.0, 16384.0, 1.0, 1.0, 1.0));
gtk_signal_connect (GTK_OBJECT (cachesize_adj), "value_changed",
GTK_SIGNAL_FUNC (comp_changed), NULL);
thing = gtk_hscale_new (cachesize_adj);
gtk_range_set_update_policy (GTK_RANGE (thing), GTK_UPDATE_DELAYED);
gtk_scale_set_digits (GTK_SCALE (thing), 0);
gtk_scale_set_value_pos (GTK_SCALE (thing), GTK_POS_RIGHT);
add_labelled_widget_centered ("Translation buffer(kB):", thing, vbox);
add_empty_vbox (vbox);
}
static void make_joy_widgets (GtkWidget *dvbox)
{
int i;
GtkWidget *hbox = gtk_hbox_new (FALSE, 10);
static const char *joylabels[] = {
"Joystick 0", "Joystick 1", "Mouse", "Numeric pad",
"Cursor keys/Right Ctrl", "T/F/H/B/Left Alt",
NULL
};
add_empty_vbox (dvbox);
gtk_widget_show (hbox);
add_centered_to_vbox (dvbox, hbox);
for (i = 0; i < 2; i++) {
GtkWidget *vbox, *frame;
GtkWidget *thing;
char buffer[20];
int j;
sprintf (buffer, "Port %d", i);
frame = make_radio_group_box (buffer, joylabels, joy_widget[i], 0, joy_changed);
gtk_widget_show (frame);
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, TRUE, 0);
}
add_empty_vbox (dvbox);
}
static int hd_change_mode;
static void newdir_ok (void)
{
int n;
strcpy (dirdlg_volname, gtk_entry_get_text (GTK_ENTRY (volname_entry)));
strcpy (dirdlg_path, gtk_entry_get_text (GTK_ENTRY (path_entry)));
n = strlen (dirdlg_volname);
/* Strip colons from the end. */
if (n > 0) {
if (dirdlg_volname[n - 1] == ':')
dirdlg_volname[n - 1] = '\0';
}
if (strlen (dirdlg_volname) == 0 || strlen (dirdlg_path) == 0) {
/* Uh, no messageboxes in gtk? */
} else if (hd_change_mode) {
set_filesys_unit (currprefs.mountinfo, selected_hd_row, dirdlg_volname, dirdlg_path,
0, 0, 0, 0, 0);
set_hd_state ();
} else {
add_filesys_unit (currprefs.mountinfo, dirdlg_volname, dirdlg_path,
0, 0, 0, 0, 0);
set_hd_state ();
}
gtk_widget_destroy (dirdlg);
}
static GtkWidget *create_dirdlg (const char *title)
{
GtkWidget *vbox, *hbox, *thing, *label1, *button;
dirdlg = gtk_dialog_new ();
gtk_window_set_title (GTK_WINDOW (dirdlg), title);
gtk_window_set_position (GTK_WINDOW (dirdlg), GTK_WIN_POS_MOUSE);
gtk_window_set_modal (GTK_WINDOW (dirdlg), TRUE);
gtk_widget_show (dirdlg);
vbox = GTK_DIALOG (dirdlg)->vbox;
hbox = gtk_hbox_new (FALSE, 10);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 10);
label1 = gtk_label_new ("Path:");
gtk_box_pack_start (GTK_BOX (hbox), label1, FALSE, TRUE, 10);
gtk_widget_show (label1);
thing = gtk_entry_new_with_max_length (255);
gtk_box_pack_start (GTK_BOX (hbox), thing, TRUE, TRUE, 10);
gtk_widget_show (thing);
path_entry = thing;
hbox = gtk_hbox_new (FALSE, 10);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 10);
thing = gtk_label_new ("Volume name:");
gtk_box_pack_start (GTK_BOX (hbox), thing, FALSE, TRUE, 10);
gtk_widget_show (thing);
thing = gtk_entry_new_with_max_length (255);
gtk_box_pack_start (GTK_BOX (hbox), thing, TRUE, TRUE, 10);
gtk_widget_show (thing);
gtk_widget_set_usize (thing, 200, -1);
volname_entry = thing;
hbox = GTK_DIALOG (dirdlg)->action_area;
button = gtk_button_new_with_label ("OK");
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC(newdir_ok), NULL);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gtk_widget_grab_default (button);
gtk_widget_show (button);
button = gtk_button_new_with_label ("Cancel");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT (dirdlg));
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gtk_widget_show (button);
}
static void did_newdir (void)
{
hd_change_mode = 0;
create_dirdlg ("Add a new mounted directory");
}
static void did_newhdf (void)
{
hd_change_mode = 0;
}
static void did_hdchange (void)
{
int secspertrack, surfaces, reserved, blocksize, size;
int cylinders, readonly;
char *volname, *rootdir;
char *failure;
failure = get_filesys_unit (currprefs.mountinfo, selected_hd_row,
&volname, &rootdir, &readonly,
&secspertrack, &surfaces, &reserved,
&cylinders, &size, &blocksize);
hd_change_mode = 1;
if (is_hardfile (currprefs.mountinfo, selected_hd_row)) {
} else {
create_dirdlg ("Change a mounted directory");
gtk_entry_set_text (GTK_ENTRY (volname_entry), volname);
gtk_entry_set_text (GTK_ENTRY (path_entry), rootdir);
}
}
static void did_hddel (void)
{
kill_filesys_unit (currprefs.mountinfo, selected_hd_row);
set_hd_state ();
}
static void hdselect (GtkWidget *widget, gint row, gint column, GdkEventButton *bevent,
gpointer user_data)
{
selected_hd_row = row;
gtk_widget_set_sensitive (hdchange_button, TRUE);
gtk_widget_set_sensitive (hddel_button, TRUE);
}
static void hdunselect (GtkWidget *widget, gint row, gint column, GdkEventButton *bevent,
gpointer user_data)
{
gtk_widget_set_sensitive (hdchange_button, FALSE);
gtk_widget_set_sensitive (hddel_button, FALSE);
}
static GtkWidget *make_buttons (const char *label, GtkWidget *box, void (*sigfunc) (void), GtkWidget *(*create)(const char *label))
{
GtkWidget *thing = create (label);
gtk_widget_show (thing);
gtk_signal_connect (GTK_OBJECT (thing), "clicked", (GtkSignalFunc) sigfunc, NULL);
gtk_box_pack_start (GTK_BOX (box), thing, TRUE, TRUE, 0);
return thing;
}
#define make_button(label, box, sigfunc) make_buttons(label, box, sigfunc, gtk_button_new_with_label)
static void make_hd_widgets (GtkWidget *dvbox)
{
GtkWidget *thing, *buttonbox, *hbox;
char *titles [] = {
"Volume", "File/Directory", "R/O", "Heads", "Cyl.", "Sec.", "Rsrvd", "Size", "Blksize"
};
thing = gtk_clist_new_with_titles (9, titles);
gtk_clist_set_selection_mode (GTK_CLIST (thing), GTK_SELECTION_SINGLE);
gtk_signal_connect (GTK_OBJECT (thing), "select_row", (GtkSignalFunc) hdselect, NULL);
gtk_signal_connect (GTK_OBJECT (thing), "unselect_row", (GtkSignalFunc) hdunselect, NULL);
hdlist_widget = thing;
gtk_widget_set_usize (thing, -1, 200);
gtk_widget_show (thing);
add_centered_to_vbox (dvbox, thing);
hbox = gtk_hbox_new (FALSE, 10);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (dvbox), hbox, FALSE, TRUE, 0);
/* The buttons */
buttonbox = gtk_hbox_new (TRUE, 4);
gtk_widget_show (buttonbox);
gtk_box_pack_start (GTK_BOX (hbox), buttonbox, TRUE, TRUE, 0);
make_button ("New filesystem...", buttonbox, did_newdir);
#if 0 /* later... */
make_button ("New hardfile...", buttonbox, did_newhdf);
#endif
hdchange_button = make_button ("Change...", buttonbox, did_hdchange);
hddel_button = make_button ("Delete", buttonbox, did_hddel);
thing = gtk_label_new ("These settings take effect after the next reset.");
gtk_widget_show (thing);
add_centered_to_vbox (dvbox, thing);
}
static void make_about_widgets (GtkWidget *dvbox)
{
GtkWidget *thing;
GtkStyle *style;
GdkFont *font;
char t[20];
add_empty_vbox (dvbox);
sprintf (t, "UAE %d.%d.%d", UAEMAJOR, UAEMINOR, UAESUBREV);
thing = gtk_label_new (t);
gtk_widget_show (thing);
add_centered_to_vbox (dvbox, thing);
font = gdk_font_load ("-*-helvetica-medium-r-normal--*-240-*-*-*-*-*-*");
if (font) {
style = gtk_style_copy (GTK_WIDGET (thing)->style);
gdk_font_unref (style->font);
style->font = font;
gdk_font_ref (style->font);
gtk_widget_push_style (style);
gtk_widget_set_style (thing, style);
}
thing = gtk_label_new ("Choose your settings, then deselect the Pause button to start!");
gtk_widget_show (thing);
add_centered_to_vbox (dvbox, thing);
add_empty_vbox (dvbox);
}
static void create_guidlg (void)
{
GtkWidget *window, *notebook;
GtkWidget *buttonbox, *vbox, *hbox;
GtkWidget *thing;
int i;
int argc = 1;
char *a[] = {"UAE"};
char **argv = a;
static const struct _pages {
const char *title;
void (*createfunc)(GtkWidget *);
} pages[] = {
/* ??? If this isn't the first page, there are errors in draw_led. */
{ "Floppy disks", make_floppy_disks },
{ "Memory", make_mem_widgets },
{ "CPU emulation", make_cpu_widgets },
{ "Graphics", make_gfx_widgets },
{ "Chipset", make_chipset_widgets },
{ "Sound", make_sound_widgets },
{ "JIT", make_comp_widgets },
{ "Game ports", make_joy_widgets },
{ "Harddisks", make_hd_widgets },
{ "About", make_about_widgets }
};
gtk_init (&argc, &argv);
gtk_rc_parse ("uaegtkrc");
gui_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (gui_window), "UAE control");
vbox = gtk_vbox_new (FALSE, 4);
gtk_container_add (GTK_CONTAINER (gui_window), vbox);
gtk_container_set_border_width (GTK_CONTAINER (gui_window), 10);
/* First line - buttons and power LED */
hbox = gtk_hbox_new (FALSE, 10);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
/* The buttons */
buttonbox = gtk_hbox_new (TRUE, 4);
gtk_widget_show (buttonbox);
gtk_box_pack_start (GTK_BOX (hbox), buttonbox, TRUE, TRUE, 0);
make_button ("Reset", buttonbox, did_reset);
make_button ("Debug", buttonbox, did_debug);
make_button ("Quit", buttonbox, did_quit);
make_button ("Save config", buttonbox, save_config);
pause_uae_widget = make_buttons ("Pause", buttonbox, pause_uae, gtk_toggle_button_new_with_label);
/* The LED */
thing = make_led (0);
thing = make_labelled_widget ("Power:", thing);
gtk_widget_show (thing);
gtk_box_pack_start (GTK_BOX (hbox), thing, FALSE, TRUE, 0);
/* More buttons */
buttonbox = gtk_hbox_new (TRUE, 4);
gtk_widget_show (buttonbox);
gtk_box_pack_start (GTK_BOX (vbox), buttonbox, TRUE, TRUE, 0);
snap_save_widget = make_button ("Save state", buttonbox, did_savestate);
snap_load_widget = make_button ("Load state", buttonbox, did_loadstate);
/* Place a separator below those buttons. */
thing = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (vbox), thing, FALSE, TRUE, 0);
gtk_widget_show (thing);
/* Now the notebook */
notebook = gtk_notebook_new ();
gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);
gtk_widget_show (notebook);
for (i = 0; i < sizeof pages / sizeof (struct _pages); i++) {
thing = gtk_vbox_new (FALSE, 4);
gtk_widget_show (thing);
gtk_container_set_border_width (GTK_CONTAINER (thing), 10);
pages[i].createfunc (thing);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), thing, gtk_label_new (pages[i].title));
}
/* Put "about" screen first. */
gtk_notebook_set_page (GTK_NOTEBOOK (notebook), i - 1);
enable_disk_buttons (1);
enable_snap_buttons (1);
gtk_widget_show (vbox);
filesel_active = -1;
snapsel_active = -1;
gtk_timeout_add (1000, (GtkFunction)my_idle, 0);
}
static void *gtk_gui_thread (void *dummy)
{
gtk_main ();
quitted_gui = 1;
uae_sem_post (&gui_quit_sem);
return 0;
}
void gui_changesettings(void)
{
}
void gui_fps (int x)
{
}
void gui_led (int num, int on)
{
if (no_gui)
return;
/* if (num == 0)
return;
printf("LED %d %d\n", num, on);
write_comm_pipe_int (&to_gui_pipe, 1, 0);
write_comm_pipe_int (&to_gui_pipe, num == 0 ? 4 : num - 1, 0);
write_comm_pipe_int (&to_gui_pipe, on, 1);
printf("#LED %d %d\n", num, on);*/
}
void gui_filename (int num, const char *name)
{
if (no_gui)
return;
write_comm_pipe_int (&to_gui_pipe, 0, 0);
write_comm_pipe_int (&to_gui_pipe, num, 1);
/* gui_update ();*/
}
void gui_handle_events (void)
{
int pause_uae = FALSE;
if (no_gui)
return;
do {
while (pause_uae || comm_pipe_has_data (&from_gui_pipe)) {
int cmd = read_comm_pipe_int_blocking (&from_gui_pipe);
int n;
switch (cmd) {
case 0:
n = read_comm_pipe_int_blocking (&from_gui_pipe);
changed_prefs.df[n][0] = '\0';
break;
case 1:
n = read_comm_pipe_int_blocking (&from_gui_pipe);
uae_sem_wait (&gui_sem);
strncpy (changed_prefs.df[n], new_disk_string[n], 255);
free (new_disk_string[n]);
new_disk_string[n] = 0;
changed_prefs.df[n][255] = '\0';
uae_sem_post (&gui_sem);
break;
case 2:
uae_reset ();
end_pause_uae ();
break;
case 3:
activate_debugger ();
end_pause_uae ();
break;
case 4:
uae_quit ();
end_pause_uae ();
break;
case 5:
pause_uae = TRUE;
break;
case 6:
pause_uae = FALSE;
break;
case 7:
printf ("STATESAVE\n");
savestate_state = read_comm_pipe_int_blocking (&from_gui_pipe);
uae_sem_wait (&gui_sem);
savestate_filename = gui_snapname;
uae_sem_post (&gui_sem);
break;
case 8:
uae_sem_wait (&gui_sem);
strncpy (changed_prefs.romfile, gui_romname, 255);
changed_prefs.romfile[255] = '\0';
free (gui_romname);
uae_sem_post (&gui_sem);
break;
case 9:
uae_sem_wait (&gui_sem);
strncpy (changed_prefs.keyfile, gui_keyname, 255);
changed_prefs.keyfile[255] = '\0';
free (gui_keyname);
uae_sem_post (&gui_sem);
break;
}
}
} while (pause_uae);
}
void gui_update_gfx (void)
{
#if 0 /* This doesn't work... */
set_gfx_state ();
#endif
}
int gui_init (void)
{
uae_thread_id tid;
gui_active = 0;
init_comm_pipe (&to_gui_pipe, 20, 1);
init_comm_pipe (&from_gui_pipe, 20, 1);
uae_sem_init (&gui_sem, 0, 1);
uae_sem_init (&gui_init_sem, 0, 0);
uae_sem_init (&gui_quit_sem, 0, 0);
create_guidlg ();
uae_start_thread (gtk_gui_thread, NULL, &tid);
gui_update ();
if (currprefs.start_gui == 1) {
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pause_uae_widget), TRUE);
write_comm_pipe_int (&from_gui_pipe, 5, 1);
/* Handle events until Pause is unchecked. */
gui_handle_events ();
/* Quit requested? */
if (quit_program == -1) {
gui_exit ();
return -2;
}
}
return 1;
}
int gui_update (void)
{
if (no_gui)
return 0;
write_comm_pipe_int (&to_gui_pipe, 1, 1);
uae_sem_wait (&gui_init_sem);
return 0;
}
void gui_exit (void)
{
if (no_gui)
return;
quit_gui = 1;
uae_sem_wait (&gui_quit_sem);
}
void gui_lock (void)
{
uae_sem_wait (&gui_sem);
}
void gui_unlock (void)
{
uae_sem_post (&gui_sem);
}
| 56,927 | C | .c | 1,604 | 31.704489 | 131 | 0.669545 | libretro/libretro-uae | 112 | 60 | 28 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,293,002 | uaeunp.c | libretro_libretro-uae/sources/src/uaeunp.c | #include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include "sysconfig.h"
#include "sysdeps.h"
#include "options.h"
#include "zfile.h"
#include "fsdb.h"
#include "zarchive.h"
TCHAR start_path_exe[MAX_DPATH];
TCHAR start_path_data[MAX_DPATH];
TCHAR sep[] = { FSDB_DIR_SEPARATOR, 0 };
struct uae_prefs currprefs;
static int debug = 0;
static int amigatest;
#define WRITE_LOG_BUF_SIZE 4096
void write_log (const TCHAR *format, ...)
{
int count;
TCHAR buffer[WRITE_LOG_BUF_SIZE];
va_list parms;
va_start (parms, format);
if (debug) {
count = _vsntprintf (buffer, WRITE_LOG_BUF_SIZE - 1, format, parms);
_tprintf (buffer);
}
va_end (parms);
}
void gui_message (const TCHAR *format, ...)
{
}
uae_u32 uaerand (void)
{
return rand ();
}
/* convert time_t to/from AmigaDOS time */
static const uae_s64 msecs_per_day = 24 * 60 * 60 * 1000;
static const uae_s64 diff = ((8 * 365 + 2) * (24 * 60 * 60)) * (uae_u64)1000;
void timeval_to_amiga (struct mytimeval *tv, int *days, int *mins, int *ticks)
{
/* tv.tv_sec is secs since 1-1-1970 */
/* days since 1-1-1978 */
/* mins since midnight */
/* ticks past minute @ 50Hz */
uae_s64 t = tv->tv_sec * 1000 + tv->tv_usec / 1000;
t -= diff;
if (t < 0)
t = 0;
*days = t / msecs_per_day;
t -= *days * msecs_per_day;
*mins = t / (60 * 1000);
t -= *mins * (60 * 1000);
*ticks = t / (1000 / 50);
}
void amiga_to_timeval (struct mytimeval *tv, int days, int mins, int ticks)
{
uae_s64 t;
if (days < 0)
days = 0;
if (days > 9900 * 365)
days = 9900 * 365; // in future far enough?
if (mins < 0 || mins >= 24 * 60)
mins = 0;
if (ticks < 0 || ticks >= 60 * 50)
ticks = 0;
t = ticks * 20;
t += mins * (60 * 1000);
t += ((uae_u64)days) * msecs_per_day;
t += diff;
tv->tv_sec = t / 1000;
tv->tv_usec = (t % 1000) * 1000;
}
static int pattern_match (const TCHAR *str, const TCHAR *pattern)
{
enum State {
Exact, // exact match
Any, // ?
AnyRepeat // *
};
const TCHAR *s = str;
const TCHAR *p = pattern;
const TCHAR *q = 0;
int state = 0;
int match = TRUE;
while (match && *p) {
if (*p == '*') {
state = AnyRepeat;
q = p+1;
} else if (*p == '?') state = Any;
else state = Exact;
if (*s == 0) break;
switch (state) {
case Exact:
match = *s == *p;
s++;
p++;
break;
case Any:
match = TRUE;
s++;
p++;
break;
case AnyRepeat:
match = TRUE;
s++;
if (*s == *q){
// make a recursive call so we don't match on just a single character
if (pattern_match(s,q) == TRUE) {
p++;
}
}
break;
}
}
if (state == AnyRepeat) return (*s == *q);
else if (state == Any) return (*s == *p);
else return match && (*s == *p);
}
static void geterror (void)
{
TCHAR *err = zfile_geterror ();
if (!err)
return;
_tprintf (_T("%s\n"), err);
}
static const TCHAR *prots = _T("HSPARWED");
struct arcdir {
TCHAR *name;
int isdir;
uae_u32 flags;
uae_u64 size;
TCHAR *comment;
uae_u32 crc32;
int iscrc;
__time64_t dt;
int parent, nextlevel;
};
static struct arcdir **filelist;
static void dolist (struct arcdir **filelist, struct arcdir *adp, int entries, int parent, int level)
{
int ii, i;
for (ii = 0; ii < 2; ii++) {
for (i = 0; i < entries; i++) {
struct arcdir *ad = filelist[i];
int j;
TCHAR protflags[9];
TCHAR dates[32];
TCHAR crcs[16];
int flags;
struct tm *dt;
if (ad->parent != parent)
continue;
if ((ii == 0 && ad->isdir) || (ii == 1 && !ad->isdir)) {
flags = ad->flags;
if (flags >= 0) {
for (j = 0; j < 8; j++) {
protflags[j] = '-';
if (flags & (1 << (7 - j)))
protflags[j] = prots[j];
}
protflags[j] = 0;
} else {
_tcscpy (protflags, _T("--------"));
}
if (ad->dt > 0) {
dt = _gmtime64 (&ad->dt);
_tcsftime (dates, sizeof (dates) / sizeof (TCHAR), _T("%Y/%m/%d %H:%M:%S"), dt);
} else {
_tcscpy (dates, _T("-------------------"));
}
for (j = 0; j < level; j++)
_tprintf (_T(" "));
if (ad->iscrc > 0)
_stprintf (crcs, _T("%08X"), ad->crc32);
else if (ad->iscrc < 0)
_tcscpy (crcs, _T("????????"));
else
_tcscpy (crcs, _T("--------"));
if (ad->isdir > 0)
_tprintf (_T(" [DIR] %s %s %s\n"), protflags, dates, ad->name);
else if (ad->isdir < 0)
_tprintf (_T(" [VDIR] %s %s %s\n"), protflags, dates, ad->name);
else
_tprintf (_T("%10I64d %s %s %s %s\n"), ad->size, protflags, dates, crcs, ad->name);
if (ad->comment)
_tprintf (_T(" \"%s\"\n"), ad->comment);
if (ad->nextlevel >= 0) {
level++;
dolist (filelist, adp, entries, ad - adp, level);
level--;
}
}
}
}
}
static int parentid = -1, subdirid;
static int maxentries = 10000, entries;
static void resetlist (void)
{
parentid = -1;
subdirid = 0;
maxentries = 10000;
entries = 0;
}
static int unlist2 (struct arcdir *adp, const TCHAR *src, int all)
{
struct zvolume *zv;
struct zdirectory *h;
int i;
TCHAR p[MAX_DPATH];
TCHAR fn[MAX_DPATH];
struct arcdir *ad;
zv = zfile_fopen_archive_root (src, ZFD_ALL);
if (zv == NULL) {
geterror();
_tprintf (_T("Couldn't open archive '%s'\n"), src);
return 0;
}
h = zfile_opendir_archive (src);
if (!h) {
_tcscpy (p, src);
_tcscat (p, _T(".DIR"));
h = zfile_opendir_archive (src);
if (!h) {
geterror();
_tprintf (_T("Couldn't open directory '%s'\n"), src);
return 0;
}
}
while (zfile_readdir_archive (h, fn)) {
struct mystat st;
int isdir;
int flags;
TCHAR *comment;
struct zfile *zf;
uae_u32 crc32 = 0;
int iscrc = 0;
int nextdir = -1;
_tcscpy (p, src);
_tcscat (p, sep);
_tcscat (p, fn);
if (!zfile_stat_archive (p, &st)) {
st.size = -1;
st.mtime.tv_sec = st.mtime.tv_usec = 0;
}
isdir = 0;
flags = 0;
comment = 0;
zfile_fill_file_attrs_archive (p, &isdir, &flags, &comment);
flags ^= 15;
if (!isdir) {
if (0 && st.size >= 2 * 1024 * 1024) {
iscrc = -1;
} else if (st.size > 0) {
zf = zfile_open_archive (p, 0);
if (zf) {
crc32 = zfile_crc32 (zf);
iscrc = 1;
}
}
}
ad = &adp[entries++];
ad->isdir = isdir;
ad->comment = comment;
ad->flags = flags;
ad->name = my_strdup (fn);
ad->size = st.size;
ad->dt = st.mtime.tv_sec;
ad->parent = parentid;
ad->crc32 = crc32;
ad->iscrc = iscrc;
if (isdir && all) {
int oldparent = parentid;
parentid = ad - adp;
nextdir = parentid + 1;
unlist2 (adp, p, all);
parentid = oldparent;
}
ad->nextlevel = nextdir;
if (entries >= maxentries)
break;
}
if (parentid >= 0)
return 1;
filelist = xmalloc (struct arcdir*, entries);
for (i = 0; i < entries; i++) {
filelist[i] = &adp[i];
}
// bubblesort is the winner!
for (i = 0; i < entries; i++) {
int j;
for (j = i + 1; j < entries; j++) {
int diff = _tcsicmp (filelist[i]->name, filelist[j]->name);
if (diff > 0) {
struct arcdir *tmp;
tmp = filelist[i];
filelist[i] = filelist[j];
filelist[j] = tmp;
}
}
}
dolist (filelist, adp, entries, -1, 0);
zfile_closedir_archive (h);
zfile_fclose_archive (zv);
return 1;
}
static int unlist (const TCHAR *src, int all)
{
struct arcdir *adp;
adp = xcalloc (struct arcdir, maxentries);
unlist2 (adp, src, all);
return 1;
}
static int docrclist (const TCHAR *src)
{
WIN32_FIND_DATA ffd;
HANDLE h;
TCHAR path[MAX_DPATH];
_tcscpy (path, src);
_tcscat (path, _T("\\*.*"));
h = FindFirstFile (path, &ffd);
while (h) {
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
if (!_tcscmp (ffd.cFileName, _T(".")) || !_tcscmp (ffd.cFileName, _T("..")))
goto next;
_tcscpy (path, src);
_tcscat (path, _T("\\"));
_tcscat (path, ffd.cFileName);
docrclist (path);
} else {
TCHAR path2[MAX_DPATH];
_tcscpy (path, src);
_tcscat (path, _T("\\"));
_tcscat (path, ffd.cFileName);
GetFullPathName (path, MAX_DPATH, path2, NULL);
resetlist ();
unlist (path2, 1);
}
next:
if (!FindNextFile (h, &ffd)) {
FindClose (h);
break;
}
}
return 1;
}
static void setdate (const TCHAR *src, __time64_t tm)
{
struct utimbuf ut;
if (tm) {
ut.actime = ut.modtime = tm;
_wutime64 (src, &ut);
}
}
static int found;
static int unpack (const TCHAR *src, const TCHAR *filename, const TCHAR *dst, int out, int all, int level)
{
struct zdirectory *h;
struct zvolume *zv;
int ret;
uae_u8 *b;
int size;
TCHAR fn[MAX_DPATH];
ret = 0;
zv = zfile_fopen_archive_root (src, ZFD_ALL);
if (zv == NULL) {
geterror();
_tprintf (_T("Couldn't open archive '%s'\n"), src);
return 0;
}
h = zfile_opendir_archive (src);
if (!h) {
geterror();
_tprintf (_T("Couldn't open directory '%s'\n"), src);
return 0;
}
while (zfile_readdir_archive (h, fn)) {
if (all || !_tcsicmp (filename, fn)) {
TCHAR tmp[MAX_DPATH];
struct zfile *s, *d;
struct mystat st;
found = 1;
_tcscpy (tmp, src);
_tcscat (tmp, sep);
_tcscat (tmp, fn);
if (!zfile_stat_archive (tmp, &st)) {
_tprintf (_T("Couldn't stat '%s'\n"), tmp);
continue;
}
if (dst == NULL || all)
dst = fn;
if (st.mode) {
if (all > 0)
continue;
if (all < 0) {
TCHAR oldcur[MAX_DPATH];
my_mkdir (fn);
my_setcurrentdir (fn, oldcur);
unpack (tmp, fn, dst, out, all, 1);
my_setcurrentdir (oldcur, NULL);
setdate (dst, st.mtime.tv_sec);
continue;
}
_tprintf (_T("Directory extraction not yet supported\n"));
return 0;
}
s = zfile_open_archive (tmp, ZFD_ARCHIVE | ZFD_NORECURSE);
if (!s) {
geterror();
_tprintf (_T("Couldn't open '%s' for reading\n"), src);
continue;
}
zfile_fseek (s, 0, SEEK_END);
size = zfile_ftell (s);
zfile_fseek (s, 0, SEEK_SET);
b = xcalloc (uae_u8, size);
if (b) {
if (zfile_fread (b, size, 1, s) == 1) {
if (out) {
_tprintf (_T("\n"));
fwrite (b, size, 1, stdout);
} else {
d = zfile_fopen (dst, _T("wb"), 0);
if (d) {
if (zfile_fwrite (b, size, 1, d) == 1) {
ret = 1;
_tprintf (_T("%s extracted, %d bytes\n"), dst, size);
}
zfile_fclose (d);
setdate (dst, st.mtime.tv_sec);
}
}
}
xfree (b);
}
zfile_fclose (s);
if (!all)
break;
}
}
geterror ();
if (!found && !level) {
if (filename[0])
_tprintf (_T("'%s' not found\n"), filename);
else
_tprintf (_T("nothing extracted\n"));
}
return ret;
}
static int unpack2 (const TCHAR *src, const TCHAR *match, int level)
{
struct zdirectory *h;
struct zvolume *zv;
int ret;
uae_u8 *b;
int size;
TCHAR fn[MAX_DPATH];
ret = 0;
zv = zfile_fopen_archive_root (src, ZFD_ALL);
if (zv == NULL) {
geterror();
_tprintf (_T("Couldn't open archive '%s'\n"), src);
return 0;
}
h = zfile_opendir_archive (src);
if (!h) {
geterror();
_tprintf (_T("Couldn't open directory '%s'\n"), src);
return 0;
}
while (zfile_readdir_archive (h, fn)) {
TCHAR tmp[MAX_DPATH];
TCHAR *dst;
struct zfile *s, *d;
int isdir, flags;
_tcscpy (tmp, src);
_tcscat (tmp, sep);
_tcscat (tmp, fn);
zfile_fill_file_attrs_archive (tmp, &isdir, &flags, NULL);
if (isdir) {
TCHAR *p = _tcsstr (fn, _T(".DIR"));
if (isdir == ZNODE_VDIR && p && _tcslen (p) == 4) {
p[0] = 0;
if (pattern_match (fn, match))
continue;
p[0] = '.';
}
unpack2 (tmp, match, 1);
continue;
}
if (pattern_match (fn, match)) {
struct mystat st;
if (!zfile_stat_archive (tmp, &st)) {
st.mtime.tv_sec = st.mtime.tv_usec = -1;
}
found = 1;
dst = fn;
s = zfile_open_archive (tmp, ZFD_NORECURSE);
if (!s) {
geterror();
_tprintf (_T("Couldn't open '%s' for reading\n"), tmp);
continue;
}
zfile_fseek (s, 0, SEEK_END);
size = zfile_ftell (s);
zfile_fseek (s, 0, SEEK_SET);
b = xcalloc (uae_u8, size);
if (b) {
if (zfile_fread (b, size, 1, s) == 1) {
d = zfile_fopen (dst, _T("wb"), 0);
if (d) {
if (zfile_fwrite (b, size, 1, d) == 1) {
ret = 1;
_tprintf (_T("%s extracted, %d bytes\n"), dst, size);
}
zfile_fclose (d);
setdate (dst, st.mtime.tv_sec);
}
}
xfree (b);
}
zfile_fclose (s);
}
}
geterror ();
if (!found && !level) {
_tprintf (_T("'%s' not matched\n"), match);
}
return ret;
}
static int scanpath (TCHAR *src, TCHAR *outpath)
{
struct zvolume *zv;
struct zdirectory *h;
TCHAR fn[MAX_DPATH];
zv = zfile_fopen_archive_root (src, ZFD_ALL | ZFD_NORECURSE);
if (zv == NULL) {
geterror();
_tprintf (_T("Couldn't open archive '%s'\n"), src);
return 0;
}
h = zfile_opendir_archive (src);
if (!h) {
geterror();
_tprintf (_T("Couldn't open directory '%s'\n"), src);
return 0;
}
while (zfile_readdir_archive (h, fn)) {
TCHAR tmp[MAX_DPATH];
int isdir, flags;
_tcscpy (tmp, src);
_tcscat (tmp, sep);
_tcscat (tmp, fn);
zfile_fill_file_attrs_archive (tmp, &isdir, &flags, NULL);
if (isdir == ZNODE_VDIR) {
_tcscpy (outpath, tmp);
scanpath (tmp, outpath);
break;
}
}
return 1;
}
int __cdecl wmain (int argc, wchar_t *argv[], wchar_t *envp[])
{
int ok = 0, i;
int list = 0, xtract = 0, extract = 0;
int out = 0, all = 0, crclist = 0;
TCHAR path[MAX_DPATH] = { 0 }, pathx[MAX_DPATH] = { 0 };
#if 0
TCHAR tmppath[MAX_DPATH];
#endif
int used[32] = { 0 };
TCHAR *parm2 = NULL;
TCHAR *parm3 = NULL;
TCHAR *match = NULL;
resetlist ();
for (i = 0; i < argc && i < 32; i++) {
if (!_tcsicmp (argv[i], _T("-crclist"))) {
crclist = 1;
used[i] = 1;
}
if (!_tcsicmp (argv[i], _T("o"))) {
out = 1;
used[i] = 1;
}
if (!_tcsicmp (argv[i], _T("-o"))) {
out = 1;
used[i] = 1;
}
if (!_tcsicmp (argv[i], _T("l"))) {
list = 1;
used[i] = 1;
}
if (!_tcsicmp (argv[i], _T("-l"))) {
list = 1;
used[i] = 1;
}
if (!_tcsicmp (argv[i], _T("x"))) {
xtract = 1;
used[i] = 1;
}
if (!_tcsicmp (argv[i], _T("-x"))) {
xtract = 1;
used[i] = 1;
}
if (!_tcsicmp (argv[i], _T("e"))) {
extract = 1;
used[i] = 1;
}
if (!_tcsicmp (argv[i], _T("-e"))) {
extract = 1;
used[i] = 1;
}
if (!_tcsicmp (argv[i], _T("*"))) {
all = 1;
used[i] = 1;
}
if (!_tcsicmp (argv[i], _T("**"))) {
all = -1;
used[i] = 1;
}
if (!used[i] && (_tcschr (argv[i], '*') || _tcschr (argv[i], '?'))) {
extract = 1;
match = argv[i];
used[i] = 1;
}
}
for (i = 1; i < argc && i < 32; i++) {
if (!used[i]) {
_tcscpy (pathx, argv[i]);
GetFullPathName (argv[i], MAX_DPATH, path, NULL);
used[i] = 1;
break;
}
}
for (i = 1; i < argc && i < 32; i++) {
if (!used[i]) {
parm2 = argv[i];
used[i] = 1;
break;
}
}
for (i = 1; i < argc && i < 32; i++) {
if (!used[i]) {
parm3 = argv[i];
used[i] = 1;
break;
}
}
// _tcscpy (tmppath, path);
// scanpath (tmppath, path);
if (crclist) {
docrclist (_T("."));
ok = 1;
} else if (!list && match) {
unpack2 (path, match, 0);
ok = 1;
} else if (!list && !parm2 && all > 0) {
unpack2 (path, _T("*"), 0);
ok = 1;
} else if (!list && extract && parm2) {
unpack2 (path, parm2, 0);
ok = 1;
} else if (argc == 2 || (argc > 2 && list)) {
unlist (path, all);
ok = 1;
} else if (((xtract && parm2) || all || (argc >= 3 && parm2)) && !out) {
unpack (path, parm2, parm3, 0, all, 0);
ok = 1;
} else if (parm2 && (argc >= 4 && out)) {
unpack (path, parm2, parm3, 1, all, 0);
ok = 1;
}
if (!ok) {
_tprintf (_T("UAE unpacker uaeunp 0.8f by Toni Wilen (c)2012\n"));
_tprintf (_T("\n"));
_tprintf (_T("List: \"uaeunp (-l) <path>\"\n"));
_tprintf (_T("List all recursively: \"uaeunp -l <path> **\"\n"));
_tprintf (_T("Extract to file: \"uaeunp (-x) <path> <filename> [<dst name>]\"\n"));
_tprintf (_T("Extract all (single directory): \"uaeunp (-x) <path> *\"\n"));
_tprintf (_T("Extract all (recursively): \"uaeunp (-x) <path> **\"\n"));
_tprintf (_T("Extract all (recursively, current dir): \"uaeunp -e <path> <match string>\"\n"));
_tprintf (_T("Output to console: \"uaeunp (-x) -o <path> <filename>\"\n"));
_tprintf (_T("\n"));
_tprintf (_T("Supported disk image formats:\n"));
_tprintf (_T(" ADF, HDF (VHD), DMS, encrypted DMS, IPF, FDI, DSQ, WRP\n"));
_tprintf (_T("Supported filesystems:\n"));
_tprintf (_T(" OFS, FFS, SFS, SFS2 and FAT12\n"));
_tprintf (_T("Supported archive formats:\n"));
_tprintf (_T(" 7ZIP, LHA, LZX, RAR (unrar.dll), TAR, ZIP, ArchiveAccess.DLL\n"));
_tprintf (_T("Miscellaneous formats:\n"));
_tprintf (_T(" RDB partition table, GZIP, XZ\n"));
}
return 0;
}
/*
0.8f:
- PCDOS raw MFM decoding improved (multiformat disks)
0.8e:
- DSQ extra header supported
0.8c:
- do not extract archives inside archive in recursive extraction mode
0.8b:
- DMS full cylinder 0 BBS ADs skipped when extracting
- DMS BBS AD extraction support
0.8:
- tar archive support
- some fixes and improvements
0.7:
- vhd read support
- dms, ipf (and possible other) disk image formats didn't unpack inside archives
- fixed duplicate vdir entries with some image types
- all raw disk image formats support Amiga, FAT and extended adf extraction
- cache relatively slow ipf and fdi extracted data
0.6:
- rdb handling optimization (no more huge memory usage)
- fat12 supported
0.5:
- adf protection flags fixed
- sfs support added
- >512 block sizes supported (rdb hardfiles only)
0.5b:
- SFS file extraction fixed
- SFS2 supported
- block size autodetection implemented (if non-rdb hardfile)
0.5c:
- rdb_dump.dat added to rdb hardfiles, can be used to dump/backup rdb blocks
*/
| 17,616 | C | .c | 728 | 21.009615 | 106 | 0.576227 | libretro/libretro-uae | 112 | 60 | 28 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,293,161 | ppcd.c | libretro_libretro-uae/sources/src/ppc/ppcd.c | // Very accurate PowerPC Architecture disassembler (both 32 and 64-bit instructions are supported)
// Branch Target in output parameters is NOT relative. Its already precalculated
// from effective address of current instruction.
// Note, that old mnemonics and operands will be overwritten, after next disasm
// call. So dont forget to copy them away, if supposed to use them lately.
// Instruction class can be combined from many flags. There can exist, for example,
// "FPU" + "LDST" instruction, except "ILLEGAL", which cannot be combined.
// RLWINM-like instructions mask is placed in output "target" parameter.
#include <stdio.h>
#include <string.h>
#include "ppcd.h"
#define POWERPC_32 // Use generic 32-bit model
//efine POWERPC_64 // Use generic 64-bit model
//efine GEKKO // Use Gekko (32-bit ISA)
//efine BROADWAY // Use Broadway (32-bit ISA)
#define SIMPLIFIED // Allow simplified mnemonics
//efine UPPERCASE // Use upper case strings in output
#define COMMA ", "
#define LPAREN " ("
#define RPAREN ")"
#define HEX1 "0x" // prefix
#define HEX2 "" // suffix
static int bigendian = -1; // Autodetect.
// ---------------------------------------------------------------------------
// Implementation. Look away, code is messed :)
// Dont miss 'l' and '1'.
static PPCD_CB *o;
#define Instr (o->instr)
#define DIS_PC (o->pc)
// Simple decoder
#define DIS_RD ((Instr >> 21) & 0x1f)
#define DIS_RS DIS_RD
#define DIS_RA ((Instr >> 16) & 0x1f)
#define DIS_RB ((Instr >> 11) & 0x1f)
#define DIS_RC ((Instr >> 6) & 0x1f)
#define DIS_RE ((Instr >> 1) & 0x1f)
#define DIS_MB DIS_RC
#define DIS_ME DIS_RE
#define DIS_OE (Instr & 0x400)
#define DIS_SIMM ((s16)Instr)
#define DIS_UIMM (Instr & 0xffff)
#define DIS_CRM ((Instr >> 12) & 0xff)
#define AA (Instr & 2)
#define LK (Instr & 1)
#define AALK (Instr & 3)
#define Rc LK
// GPRs. sp, sd1 and sd2 are named corresponding to PPC EABI.
static const char *regname[] = {
#ifdef UPPERCASE
"R0" , "R1" , "R2", "R3" , "R4" , "R5" , "R6" , "R7" ,
"R8" , "R9" , "R10", "R11", "R12", "R13", "R14", "R15",
"R16", "R17", "R18", "R19", "R20", "R21", "R22", "R23",
"R24", "R25", "R26", "R27", "R28", "R29", "R30", "R31"
#else
"r0" , "r1" , "r2", "r3" , "r4" , "r5" , "r6" , "r7" ,
"r8" , "r9" , "r10", "r11", "r12", "r13", "r14", "r15",
"r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
"r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
#endif
};
#define REGD (regname[DIS_RD])
#define REGS (regname[DIS_RS])
#define REGA (regname[DIS_RA])
#define REGB (regname[DIS_RB])
// Illegal instruction.
static void ill(void)
{
#if 1
o->mnemonic[0] = o->operands[0] = '\0';
#else
strcpy(o->mnemonic, ".word");
sprintf(o->operands, HEX1 "%08X" HEX2, Instr);
#endif
o->iclass = PPC_DISA_ILLEGAL;
}
// Smart SIMM formatting (if hex=1, then force HEX; if s=1, use sign)
static char * simm(int val, int hex, int s)
{
static char out[16];
hex = 1;
if( ((val >= -256) && (val <= 256)) && !hex) sprintf(out, "%i", val);
else
{
u16 hexval = (u16)val;
if((hexval & 0x8000) && s) sprintf(out, "-" HEX1 "%04X" HEX2, ((~hexval) & 0xffff) + 1);
else sprintf(out, HEX1 "%04X" HEX2, hexval);
}
return out;
}
// Simple instruction form + reserved bitmask.
static void put(const char * mnem, u32 mask, u32 chkval=0, int iclass=PPC_DISA_OTHER)
{
if( (Instr & mask) != chkval ) { ill(); return; }
o->iclass |= iclass;
strncpy(o->mnemonic, mnem, sizeof(o->mnemonic));
}
// Simplified mnemonic trap conditions
static const char * t_cond[32] = {
NULL, "lgt", "llt", NULL, "eq", "lge", "lle", NULL,
"gt", NULL, NULL, NULL, "ge", NULL, NULL, NULL,
"lt", NULL, NULL, NULL, "le", NULL, NULL, NULL,
"ne", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
};
// Trap instructions.
static void trap(int L, int imm)
{
static char t_mode[2] = { 'w', 'd' };
int rd = DIS_RD; // TO
int s = (rd & 0x18) ? 1 : 0;
#ifdef SIMPLIFIED
if(t_cond[rd] != NULL)
{
sprintf(o->mnemonic, "t%c%s%c", t_mode[L & 1], t_cond[rd], imm ? 'i' : 0);
if(imm) sprintf(o->operands, "%s" COMMA "%s", REGA, simm(DIS_SIMM, 0, s));
else sprintf(o->operands, "%s" COMMA "%s", REGA, REGB);
o->iclass |= PPC_DISA_SIMPLIFIED;
}
else
#endif
{
sprintf(o->mnemonic, "t%c%c", t_mode[L & 1], imm ? 'i' : 0);
if(imm) sprintf(o->operands, "%i" COMMA "%s" COMMA "%s", rd, REGA, simm(DIS_SIMM, 0, s));
else sprintf(o->operands, "%i" COMMA "%s" COMMA "%s", rd, REGA, REGB);
}
if(L) o->iclass |= PPC_DISA_64;
o->r[1] = DIS_RA; if(!imm) o->r[2] = DIS_RB;
if(imm)
{
o->immed = Instr & 0xFFFF;
if(o->immed & 0x8000) o->immed |= 0xFFFF0000;
}
}
// DAB mask
#define DAB_D 4
#define DAB_A 2
#define DAB_B 1
// ASB mask
#define ASB_A 4
#define ASB_S 2
#define ASB_B 1
// cr%i
#ifdef UPPERCASE
static char crname[] = "CR";
#else
static char crname[] = "cr";
#endif
// fr%i
#ifdef UPPERCASE
static char fregname[] = "FR";
#else
static char fregname[] = "fr";
#endif
// Integer instructions
// form: 'D' rD, rA, (s)IMM
// 'S' rA, rS, (s)IMM
// 'X' rD, rA, rB
// 'Z' rA, rS, rB
// 'F' frD, rA, rB
// dab LSB bits : [D][A][B] (D should always present)
// 'hex' for logic opcodes, 's' for alu opcodes, 'crfD' and 'L' for cmp opcodes
// 'imm': 1 to show immediate operand
static void integer(const char *mnem, char form, int dab, int hex=0, int s=1, int crfD=0, int L=0, int imm=1)
{
char * ptr = o->operands;
int rd = DIS_RD, ra = DIS_RA, rb = DIS_RB;
strncpy(o->mnemonic, mnem, sizeof(o->mnemonic));
if(crfD) ptr += sprintf(ptr, "%s%i" COMMA, crname, rd >> 2); // CMP only
if(L) ptr += sprintf(ptr, "%i" COMMA, rd & 1); // CMP only
if(form == 'D')
{
if(dab & DAB_D) ptr += sprintf(ptr, "%s", REGD);
if(dab & DAB_A)
{
if(dab & DAB_D) ptr += sprintf(ptr, "%s", COMMA);
ptr += sprintf(ptr, "%s", REGA);
}
if(imm) ptr += sprintf(ptr, COMMA "%s", simm(s ? DIS_SIMM : DIS_UIMM, hex, s));
}
else if(form == 'S')
{
if(dab & ASB_A) ptr += sprintf(ptr, "%s", REGA);
if(dab & ASB_S)
{
if(dab & ASB_A) ptr += sprintf(ptr, "%s", COMMA);
ptr += sprintf(ptr, "%s", REGS);
}
if(imm) ptr += sprintf(ptr, COMMA "%s", simm(s ? DIS_SIMM : DIS_UIMM, hex, s));
}
else if(form == 'X') // DAB
{
if(dab & DAB_D) ptr += sprintf(ptr, "%s", REGD);
if(dab & DAB_A)
{
if(dab & DAB_D) ptr += sprintf(ptr, "%s", COMMA);
ptr += sprintf(ptr, "%s", REGA);
}
if(dab & DAB_B)
{
if(dab & (DAB_D|DAB_A)) ptr += sprintf(ptr, "%s", COMMA);
ptr += sprintf(ptr, "%s", REGB);
}
}
else if(form == 'F') // FPU DAB
{
if(dab & DAB_D) ptr += sprintf(ptr, "%s%i", fregname, rd);
if(dab & DAB_A)
{
if(dab & DAB_D) ptr += sprintf(ptr, "%s", COMMA);
ptr += sprintf(ptr, "%s", REGA);
}
if(dab & DAB_B)
{
if(dab & (DAB_D|DAB_A)) ptr += sprintf(ptr, "%s", COMMA);
ptr += sprintf(ptr, "%s", REGB);
}
}
else if(form == 'Z') // ASB
{
if(dab & ASB_A) ptr += sprintf(ptr, "%s", REGA);
if(dab & ASB_S)
{
if(dab & ASB_A) ptr += sprintf(ptr, "%s", COMMA);
ptr += sprintf(ptr, "%s", REGS);
}
if(dab & ASB_B)
{
if(dab & (ASB_A|ASB_S)) ptr += sprintf(ptr, "%s", COMMA);
ptr += sprintf(ptr, "%s", REGB);
}
}
else { ill(); return; }
if(form == 'D' || form == 'X' || form == 'F') { o->r[0] = rd; o->r[1] = ra; }
if(form == 'S' || form == 'Z') { o->r[0] = ra; o->r[1] = rd; }
if(form == 'X' || form == 'Z' || form == 'F') o->r[2] = rb;
if((form == 'D' || form == 'S') && imm)
{
o->immed = Instr & 0xFFFF;
if(o->immed & 0x8000 && s) o->immed |= 0xFFFF0000;
}
o->iclass |= PPC_DISA_INTEGER;
}
// Compare instructions (wraps to integer call)
static void cmp(const char *l, const char *i)
{
char mnem[sizeof(o->mnemonic)];
int rd = DIS_RD;
if(rd & 2) { ill(); return; } // Reserved bit set
if(rd & 1)
{
#ifndef POWERPC_64
{ ill(); return; }
#endif
o->iclass |= PPC_DISA_64;
}
#ifdef SIMPLIFIED
sprintf(mnem, "cmp%s%c%s", l, (rd & 1) ? 'd' : 'w', i);
integer(mnem, (*i == 'i') ? 'D' : 'X', DAB_A|DAB_B, 0, 1, (rd >> 2) ? 1 : 0, 0);
o->iclass |= PPC_DISA_SIMPLIFIED;
#else
sprintf(mnem, "cmp%s%s", l, i);
integer(mnem, (*i == 'i') ? 'D' : 'X', DAB_A|DAB_B, 0, 1, 1, 1);
#endif
}
// Add immediate (wraps to integer call)
static void addi(const char *suffix)
{
char mnem[sizeof(o->mnemonic)];
#ifdef SIMPLIFIED
if( (suffix[0] == '\0') && (DIS_RA == 0) ) // Load immediate
{
integer("li", 'D', DAB_D, 0, 1);
o->iclass |= PPC_DISA_SIMPLIFIED;
return;
}
if( (suffix[0] == 's') && (DIS_RA == 0) ) // Load address HI
{
integer("lis", 'D', DAB_D, 1, 0);
o->iclass |= PPC_DISA_SIMPLIFIED;
return;
}
if(DIS_UIMM & 0x8000)
{
sprintf(mnem, "subi%s", suffix);
// Fix immediate field.
u16 value = (u16)(~(DIS_UIMM) + 1);
Instr = (Instr & ~0xFFFF) | value;
integer(mnem, 'D', DAB_D|DAB_A, 0, 1);
o->iclass |= PPC_DISA_SIMPLIFIED;
}
else
{
sprintf(mnem, "addi%s", suffix);
integer(mnem, 'D', DAB_D|DAB_A, 0, 0);
}
#else
sprintf(mnem, "addi%s", suffix);
integer(mnem, 'D', DAB_D|DAB_A);
#endif
}
// Branch suffix: AA || LK.
static const char *b_opt[4] = { "", "l", "a", "la" };
// Branch condition code: 4 * BO[1] + (BI & 3)
static const char * b_cond[8] = {
"ge", "le", "ne", "ns", "lt", "gt", "eq", "so"
};
// Branch on CTR code: BO[0..3]
static const char * b_ctr[16] = {
"dnzf", "dzf", NULL, NULL, "dnzt", "dzt", NULL, NULL,
"dnz", "dz", NULL, NULL, NULL, NULL, NULL, NULL
};
// Place target address in operands. Helper for bcx/bx calls.
static char *place_target(char *ptr, int comma)
{
char *old;
u32 *t = (u32 *)&o->target;
if(comma) ptr += sprintf(ptr, "%s", COMMA);
old = ptr;
#ifdef POWERPC_32
ptr += sprintf(ptr, HEX1 "%08X" HEX2, (u32)o->target);
#endif
#ifdef POWERPC_64
ptr = old;
if(bigendian) ptr += sprintf(ptr, HEX1 "%08X_%08X" HEX2, t[0], t[1]);
else ptr += sprintf(ptr, HEX1 "%08X_%08X" HEX2, t[1], t[0]);
#endif
return ptr;
}
// Branch conditional.
// Disp:1 - branch with displacement..
// Disp:0 - branch by register (L:1 for LR, L:0 for CTR).
static void bcx(int Disp, int L)
{
u64 bd = 0;
int bo = DIS_RD, bi = DIS_RA;
const char *r = Disp ? "" : (L ? "lr" : "ctr");
char *ptr = o->operands;
if( DIS_RB && !Disp ) { ill(); return; }
o->operands[0] = '\0';
o->target = 0;
o->iclass |= PPC_DISA_BRANCH;
// Calculate displacement and target address
if(Disp)
{
bd = DIS_UIMM & ~3;
if(bd & 0x8000) bd |= 0xffffffffffff0000LL;
o->target = (AA ? 0 : DIS_PC) + bd;
}
else o->target = 0;
// Calculate branch prediction hint
char y = (bo & 1) ^ ((((s64)bd < 0) && Disp) ? 1 : 0);
y = y ? '+' : '-';
if(bo & 4) // No CTR decrement // BO[2]
{
if(bo & 16) // Branch always // BO[0]
{
#ifdef SIMPLIFIED
sprintf(o->mnemonic, "b%s%s", r, b_opt[Disp ? AALK : LK]);
if(Disp) ptr = place_target(ptr, 0);
o->iclass |= PPC_DISA_SIMPLIFIED;
return;
#endif // SIMPLIFIED
}
else // Branch conditional
{
if(bo & 2) { ill(); return; } // BO[3]
#ifdef SIMPLIFIED
const char *cond = b_cond[((bo & 8) >> 1) | (bi & 3)];
if(cond != NULL) // BO[1]
{
sprintf(o->mnemonic, "b%s%s%s%c", cond, r, b_opt[Disp ? AALK : LK], y);
if(bi >= 4) ptr += sprintf(ptr, "%s%i", crname, bi >> 2);
if(Disp) ptr = place_target(ptr, bi >= 4);
o->iclass |= PPC_DISA_SIMPLIFIED;
return;
}
#endif // SIMPLIFIED
}
}
else // Decrement CTR
{
if(!L && !Disp) { ill(); return; }
if(bo & 8) { ill(); return; } // BO[1]
#ifdef SIMPLIFIED
if(b_ctr[bo >> 1])
{
sprintf(o->mnemonic, "b%s%s%s%c", b_ctr[bo >> 1], r, b_opt[Disp ? AALK : LK], y);
if(!(bo & 16)) ptr += sprintf(ptr, "%i", bi);
if(Disp) ptr = place_target(ptr, !(bo & 16));
o->iclass |= PPC_DISA_SIMPLIFIED;
return;
}
#endif // SIMPLIFIED
}
// Not simplified standard form
sprintf(o->mnemonic, "bc%s%s", r, b_opt[Disp ? AALK : LK]);
ptr += sprintf(ptr, "%i" COMMA "%i", bo, bi);
if(Disp) ptr = place_target(ptr, 1);
}
// Branch unconditional
static void bx(void)
{
// Calculate displacement and target address
u64 bd = Instr & 0x03fffffc;
if(bd & 0x02000000) bd |= 0xfffffffffc000000LL;
o->target = (AA ? 0 : DIS_PC) + bd;
o->iclass |= PPC_DISA_BRANCH;
sprintf(o->mnemonic, "b%s", b_opt[AALK]);
place_target(o->operands, 0);
}
// Move CR field
static void mcrf(void)
{
if(Instr & 0x63f801) { ill(); return; }
strncpy(o->mnemonic, "mcrf", sizeof(o->mnemonic));
sprintf(o->operands, "%s%i" COMMA "%s%i", crname, DIS_RD >> 2, crname, DIS_RA >> 2);
}
// CR logic operations
static void crop(const char *name, const char *simp="", int ddd=0, int daa=0)
{
if(Instr & 1) { ill(); return; }
int crfD = DIS_RD, crfA = DIS_RA, crfB = DIS_RB;
#ifdef SIMPLIFIED
if( crfA == crfB )
{
if( (crfD == crfA) && ddd )
{
sprintf(o->mnemonic, "cr%s", simp);
sprintf(o->operands, "%i", crfD);
o->r[0] = crfD;
o->iclass |= PPC_DISA_SIMPLIFIED;
return;
}
if( daa )
{
sprintf(o->mnemonic, "cr%s", simp);
sprintf(o->operands, "%i" COMMA "%i", crfD, crfA);
o->r[0] = crfD; o->r[1] = crfA;
o->iclass |= PPC_DISA_SIMPLIFIED;
return;
}
}
#endif
sprintf(o->mnemonic, "cr%s", name);
sprintf(o->operands, "%i" COMMA "%i" COMMA "%i", crfD, crfA, crfB);
o->r[0] = crfD; o->r[1] = crfA; o->r[2] = crfB;
}
#define MASK32(b, e) \
{ \
u32 mask = ((u32)0xffffffff >> (b)) ^ (((e) >= 31) ? 0 : ((u32)0xffffffff) >> ((e) + 1)); \
o->target = ((b) > (e)) ? (~mask) : (mask); \
}
#define MASK64(b, e) \
{ \
u64 mask = ((u64)0xffffffffffffffff >> (b)) ^ (((e) >= 63) ? 0 : ((u64)0xffffffffffffffff) >> ((e) + 1)); \
o->target = ((b) > (e)) ? (~mask) : (mask); \
}
// Rotate left word.
static void rlw(const char *name, int rb, int ins=0)
{
int mb = DIS_MB, me = DIS_ME;
char * ptr = o->operands;
sprintf(o->mnemonic, "rlw%s%c", name, Rc ? '.' : '\0');
ptr += sprintf(ptr, "%s" COMMA "%s" COMMA, REGA, REGS);
if(rb) ptr += sprintf(ptr, "%s" COMMA, REGB);
else ptr += sprintf(ptr, "%i" COMMA, DIS_RB); // sh
ptr += sprintf(ptr, "%i" COMMA "%i", mb, me);
// Put mask in target.
MASK32(mb, me);
#ifdef POWERPC_64
MASK64(mb+32, me+32);
#endif
o->r[0] = DIS_RA;
o->r[1] = DIS_RS;
if(rb) o->r[2] = DIS_RB;
o->iclass |= PPC_DISA_INTEGER;
}
// RLD mask
#define RLDM_LEFT 0 // MASK(b, 63)
#define RLDM_RIGHT 1 // MASK(0, e)
#define RLDM_INS 2 // MASK(b, ~n)
// Rotate left double-word.
static void rld(char *name, int rb, int mtype)
{
#ifdef POWERPC_64
int m = DIS_MB, n = DIS_RB;
if(Instr & 0x20) m += 32; // b or e
if(Instr & 0x02) n += 32; // sh
char * ptr = o->operands;
sprintf(o->mnemonic, "rld%s%c", name, Rc ? '.' : '\0');
ptr += sprintf(ptr, "%s" COMMA "%s" COMMA, REGA, REGS);
if(rb) ptr += sprintf(ptr, "%s" COMMA, REGB);
else ptr += sprintf(ptr, "%i" COMMA, n);
ptr += sprintf(ptr, "%i", m);
// Put mask in target.
switch(mtype)
{
case RLDM_LEFT: MASK64(m, 63); break;
case RLDM_RIGHT: MASK64(0, m); break;
case RLDM_INS: MASK64(m, ~n); break;
}
o->r[0] = DIS_RA;
o->r[1] = DIS_RS;
if(rb) o->r[2] = DIS_RB;
o->iclass |= PPC_DISA_64 | PPC_DISA_INTEGER;
#endif
}
// Load/Store.
static void ldst(const char *name, int x/*indexed*/, int load=1, int L=0, int string=0, int fload=0)
{
if(x) integer(name, fload ? 'F' : 'X', DAB_D|DAB_A|DAB_B);
else
{
int rd = DIS_RD, ra = DIS_RA;
s16 imm = DIS_SIMM;
strcpy (o->mnemonic, name);
if(fload) sprintf (o->operands, "%s%i" COMMA "%s" LPAREN "%s" RPAREN, fregname, rd, simm(imm, 0, 1), regname[ra]);
else sprintf (o->operands, "%s" COMMA "%s" LPAREN "%s" RPAREN, regname[rd], simm(imm, 0, 1), regname[ra]);
o->r[0] = rd;
o->r[1] = ra;
o->immed = DIS_UIMM & 0x8000 ? DIS_UIMM | 0xFFFF0000 : DIS_UIMM;
}
o->iclass = PPC_DISA_LDST;
if(L) o->iclass |= PPC_DISA_64;
if(string) o->iclass |= PPC_DISA_STRING;
if(fload) o->iclass |= PPC_DISA_FPU;
}
// Cache.
static void cache(const char *name, int flag=PPC_DISA_OTHER)
{
if (DIS_RD) { ill(); return; }
else
{
integer(name, 'X', DAB_A|DAB_B);
o->r[0] = o->r[1];
o->r[1] = o->r[2];
o->r[2] = 0;
o->iclass &= ~PPC_DISA_INTEGER;
o->iclass |= flag;
}
}
static void movesr(const char *name, int from, int L, int xform)
{
int reg = DIS_RD, sreg = DIS_RA & 0xF, regb = DIS_RB;
strncpy(o->mnemonic, name, sizeof(o->mnemonic));
if(xform)
{
if(Instr & 0x001F0001) { ill(); return; }
sprintf(o->operands, "%s" COMMA "%s", regname[reg], regname[regb]);
o->r[0] = reg;
o->r[1] = regb;
}
else
{
if(Instr & 0x0010F801) { ill(); return; }
if(from)
{
sprintf(o->operands, "%s" COMMA "%i", regname[reg], sreg);
o->r[0] = reg;
o->r[1] = sreg;
}
else
{
sprintf(o->operands, "%i" COMMA "%s", sreg, regname[reg]);
o->r[0] = sreg;
o->r[1] = reg;
}
}
if(L) o->iclass |= PPC_DISA_OEA | PPC_DISA_OPTIONAL | PPC_DISA_BRIDGE | PPC_DISA_64;
else o->iclass |= PPC_DISA_OEA | PPC_DISA_BRIDGE;
}
static void mtcrf(void)
{
int rs = DIS_RS, crm = DIS_CRM;
#ifdef SIMPLIFIED
if(crm == 0xFF)
{
strncpy(o->mnemonic, "mtcr", sizeof(o->mnemonic));
sprintf(o->operands, "%s", regname[rs]);
}
else
#endif
{
strncpy(o->mnemonic, "mtcrf", sizeof(o->mnemonic));
sprintf(o->operands, HEX1 "%02X" HEX2 COMMA "%s", crm, regname[rs]);
}
o->r[0] = rs;
}
static void mcrxr(void)
{
if (Instr & 0x007FF800) { ill(); return; }
strcpy (o->mnemonic, "mcrxr");
sprintf (o->operands, "%s%i", crname, DIS_RD >> 2);
o->r[0] = DIS_RD >> 2;
}
static const char *spr_name(int n)
{
static char def[8];
switch(n)
{
// General architecture special-purpose registers.
case 1: return "XER";
case 8: return "LR";
case 9: return "CTR";
case 18: return "DSISR";
case 19: return "DAR";
case 22: return "DEC";
case 25: return "SDR1";
case 26: return "SRR0";
case 27: return "SRR1";
case 272: return "SPRG0";
case 273: return "SPRG1";
case 274: return "SPRG2";
case 275: return "SPRG3";
#ifdef POWERPC_64
case 280: return "ASR";
#endif
case 284: return "TBL";
case 285: return "TBU";
case 287: return "PVR";
case 528: return "IBAT0U";
case 529: return "IBAT0L";
case 530: return "IBAT1U";
case 531: return "IBAT1L";
case 532: return "IBAT2U";
case 533: return "IBAT2L";
case 534: return "IBAT3U";
case 535: return "IBAT3L";
case 536: return "DBAT0U";
case 537: return "DBAT0L";
case 538: return "DBAT1U";
case 539: return "DBAT1L";
case 540: return "DBAT2U";
case 541: return "DBAT2L";
case 542: return "DBAT3U";
case 543: return "DBAT3L";
// Optional registers.
#if !defined(GEKKO) && !defined(BROADWAY)
case 282: return "EAR";
case 1013: return "DABR";
case 1022: return "FPECR";
case 1023: return "PIR";
#endif
// Gekko-specific SPRs
#ifdef GEKKO
case 282: return "EAR";
case 912: return "GQR0";
case 913: return "GQR1";
case 914: return "GQR2";
case 915: return "GQR3";
case 916: return "GQR4";
case 917: return "GQR5";
case 918: return "GQR6";
case 919: return "GQR7";
case 920: return "HID2";
case 921: return "WPAR";
case 922: return "DMAU";
case 923: return "DMAL";
case 936: return "UMMCR0";
case 940: return "UMMCR1";
case 937: return "UPMC1";
case 938: return "UPMC2";
case 939: return "USIA";
case 941: return "UPMC3";
case 942: return "UPMC4";
case 943: return "USDA";
case 952: return "MMCR0";
case 953: return "PMC1";
case 954: return "PMC2";
case 955: return "SIA";
case 956: return "MMCR1";
case 957: return "PMC3";
case 958: return "PMC4";
case 959: return "SDA";
case 1008: return "HID0";
case 1009: return "HID1";
case 1010: return "IABR";
case 1013: return "DABR";
case 1017: return "L2CR";
case 1019: return "ICTC";
case 1020: return "THRM1";
case 1021: return "THRM2";
case 1022: return "THRM3";
#endif
}
sprintf(def, "%u", n);
return def;
}
static const char *tbr_name(int n)
{
static char def[8];
switch(n)
{
// General architecture time-base registers.
case 268: return "TBL";
case 269: return "TBU";
}
sprintf(def, "%u", n);
return def;
}
static void movespr(int from)
{
int spr = (DIS_RB << 5) | DIS_RA, f = 1;
const char *fix;
if( !((spr == 1) || (spr == 8) || (spr == 9)) ) o->iclass |= PPC_DISA_OEA;
// Handle simplified mnemonic
if (spr == 1) { fix = "xer"; o->iclass |= PPC_DISA_SIMPLIFIED; }
else if (spr == 8) { fix = "lr"; o->iclass |= PPC_DISA_SIMPLIFIED; }
else if (spr == 9) { fix = "ctr"; o->iclass |= PPC_DISA_SIMPLIFIED; }
else { fix = "spr"; f = 0; }
// Mnemonics and operands.
sprintf (o->mnemonic, "m%c%s", from ? 'f' : 't', fix);
if (f)
{
sprintf (o->operands, "%s", regname[DIS_RD]);
o->r[0] = DIS_RD;
}
else
{
if (from)
{
sprintf (o->operands, "%s" COMMA "%s", regname[DIS_RD], spr_name(spr));
o->r[0] = DIS_RD;
o->r[1] = spr;
}
else
{
sprintf (o->operands, "%s" COMMA "%s", spr_name(spr), regname[DIS_RD]);
o->r[0] = spr;
o->r[1] = DIS_RD;
}
}
}
static void movetbr(void)
{
int tbr = (DIS_RB << 5) | DIS_RA, f = 1;
const char *fix;
// Handle simplified mnemonic
if (tbr == 268) { fix = "tbl"; o->iclass |= PPC_DISA_SIMPLIFIED; }
else if (tbr == 269) { fix = "tbu"; o->iclass |= PPC_DISA_SIMPLIFIED; }
else { fix = "tb"; f = 0; }
// Mnemonics and operands.
sprintf (o->mnemonic, "mf%s", fix);
if (f)
{
sprintf (o->operands, "%s", regname[DIS_RD]);
o->r[0] = DIS_RD;
}
else
{
sprintf (o->operands, "%s" COMMA "%s", regname[DIS_RD], tbr_name(tbr));
o->r[0] = DIS_RD;
o->r[1] = tbr;
}
}
static void srawi(void)
{
int rs = DIS_RS, ra = DIS_RA, sh = DIS_RB;
sprintf (o->mnemonic, "srawi%c", Rc ? '.' : 0);
sprintf (o->operands, "%s" COMMA "%s" COMMA "%i", regname[ra], regname[rs], sh);
o->r[0] = ra;
o->r[1] = rs;
o->r[2] = sh;
o->iclass = PPC_DISA_INTEGER;
}
static void sradi(void)
{
int rs = DIS_RS, ra = DIS_RA, sh = (((Instr >> 1) & 1) << 5) | DIS_RB;
sprintf (o->mnemonic, "sradi%c", Rc ? '.' : 0);
sprintf (o->operands, "%s" COMMA "%s" COMMA "%i", regname[ra], regname[rs], sh);
o->r[0] = ra;
o->r[1] = rs;
o->r[2] = sh;
o->iclass = PPC_DISA_INTEGER | PPC_DISA_64;
}
static void lsswi(const char *name)
{
int rd = DIS_RD, ra = DIS_RA, nb = DIS_RB;
strcpy (o->mnemonic, name);
sprintf (o->operands, "%s" COMMA "%s" COMMA "%i", regname[rd], regname[ra], nb);
o->r[0] = rd;
o->r[1] = ra;
o->r[2] = nb;
o->iclass = PPC_DISA_LDST | PPC_DISA_STRING;
}
#define FPU_DAB 1
#define FPU_DB 2
#define FPU_DAC 3
#define FPU_DACB 4
#define FPU_D 5
static void fpu(const char *name, u32 mask, int type, int flag=PPC_DISA_OTHER)
{
int d = DIS_RD, a = DIS_RA, c = DIS_RC, b = DIS_RB;
if(Instr & mask) { ill(); return; }
strcpy (o->mnemonic, name);
switch (type)
{
case FPU_DAB:
sprintf (o->operands, "%s%i" COMMA "%s%i" COMMA "%s%i", fregname, d, fregname, a, fregname, b);
o->r[0] = d; o->r[1] = a; o->r[2] = b;
break;
case FPU_DB:
sprintf (o->operands, "%s%i" COMMA "%s%i", fregname, d, fregname, b);
o->r[0] = d; o->r[1] = b;
break;
case FPU_DAC:
sprintf (o->operands, "%s%i" COMMA "%s%i" COMMA "%s%i", fregname, d, fregname, a, fregname, c);
o->r[0] = d; o->r[1] = a; o->r[2] = c;
break;
case FPU_DACB:
sprintf (o->operands, "%s%i" COMMA "%s%i" COMMA "%s%i" COMMA "%s%i", fregname, d, fregname, a, fregname, c, fregname, b);
o->r[0] = d; o->r[1] = a; o->r[2] = c; o->r[3] = b;
break;
case FPU_D:
sprintf (o->operands, "%s%i", fregname, d);
o->r[0] = d;
break;
}
o->iclass = PPC_DISA_FPU | flag;
}
static void fcmp(const char *name)
{
int crfd = DIS_RD >> 2, ra = DIS_RA, rb = DIS_RB;
if (Instr & 0x00600001) { ill(); return; }
strcpy (o->mnemonic, name);
sprintf (o->operands, "%i" COMMA "%s%i" COMMA "%s%i", crfd, fregname, ra, fregname, rb);
o->r[0] = crfd; o->r[1] = ra; o->r[2] = rb;
o->iclass = PPC_DISA_FPU;
}
static void mtfsf(void)
{
int fm = (Instr >> 17) & 0xFF, rb = DIS_RB;
if(Instr & 0x02010000) { ill(); return; }
sprintf (o->mnemonic, "mtfsf%c", Rc ? '.' : 0);
sprintf (o->operands, HEX1 "%02X" HEX2 COMMA "%s%i", fm, fregname, rb);
o->r[0] = fm; o->r[1] = rb;
o->iclass = PPC_DISA_FPU;
}
static void mtfsb(const char *name)
{
int crbd = DIS_RD;
if (Instr & 0x001FF800) { ill(); return; }
strcpy (o->mnemonic, name);
sprintf (o->operands, "%i", crbd);
o->r[0] = crbd;
o->iclass = PPC_DISA_FPU;
}
static void mcrfs(void)
{
int crfD = DIS_RD >> 2, crfS = DIS_RA >> 2;
if (Instr & 0x0063F801) { ill(); return; }
strcpy (o->mnemonic, "mcrfs");
sprintf (o->operands, "%s%i" COMMA "%s%i", crname, crfD, crname, crfS);
o->r[0] = crfD; o->r[1] = crfS;
o->iclass = PPC_DISA_FPU;
}
static void mtfsfi(void)
{
int crfD = DIS_RD >> 2, imm = DIS_RB >> 1;
if (Instr & 0x007F0800) { ill(); return; }
sprintf (o->mnemonic, "mtfsfi%c", Rc ? '.' : 0);
sprintf (o->operands, "%s%i" COMMA "%i", crname, crfD, imm);
o->r[0] = crfD; o->r[1] = imm;
o->iclass = PPC_DISA_FPU;
}
/*
***********************************************************************************
* Architecture-specific extensions:
* Processor model: GEKKO
***********************************************************************************
*/
#ifdef GEKKO
static void ps_cmpx(int n)
{
static char *fix[] = { "u0", "o0", "u1", "o1" };
if(Instr & 0x00600001) { ill(); return; }
sprintf(o->mnemonic, "ps_cmp%s", fix[n]);
o->r[0] = DIS_RD>>2; o->r[1] = DIS_RA; o->r[2] = DIS_RB;
sprintf(o->operands, "%s%d" COMMA "%s%d" COMMA "%s%d", crname, o->r[0], fregname, o->r[1], fregname, o->r[2]);
o->iclass = PPC_DISA_FPU | PPC_DISA_SPECIFIC;
}
static char *ps_ldst_offs(unsigned long val)
{
static char buf[8];
if(val == 0)
{
return "0";
}
else
{
if(val <= 128)
{
sprintf(buf, "%i", val);
return buf;
}
if(val & 0x800) sprintf(buf, "-" HEX1 "%03X" HEX2, ((~val) & 0xfff) + 1);
else sprintf(buf, HEX1 "%03X" HEX2, val);
return buf;
}
}
static void ps_ldst(char *fix)
{
int s = DIS_RS, a = DIS_RA, d = (Instr & 0xfff);
sprintf(o->mnemonic, "psq_%s", fix);
sprintf( o->operands, "%s%i" COMMA "%s" LPAREN "%s" RPAREN COMMA "%i" COMMA "%i",
fregname, s, ps_ldst_offs(d), regname[a], (Instr >> 15) & 1, (Instr >> 12) & 7 );
o->r[0] = s; o->r[1] = a; o->r[2] = DIS_RB >> 1;
o->immed = d & 0x800 ? d | 0xFFFFF000 : d;
o->iclass = PPC_DISA_FPU | PPC_DISA_LDST | PPC_DISA_SPECIFIC;
}
static void ps_ldstx(char *fix)
{
int d = DIS_RD, a = DIS_RA, b = DIS_RB;
if(Instr & 1) { ill(); return; }
sprintf(o->mnemonic, "psq_%s", fix);
sprintf(o->operands, "%s%i" COMMA "%s" COMMA "%s" COMMA "%i" COMMA "%i", fregname, d, regname[a], regname[b], (Instr >> 10) & 1, (Instr >> 7) & 7);
o->r[0] = d; o->r[1] = a; o->r[2] = b; o->r[3] = DIS_RC >> 1;
o->iclass = PPC_DISA_FPU | PPC_DISA_LDST | PPC_DISA_SPECIFIC;
}
static void ps_dacb(char *fix)
{
int a = DIS_RA, b = DIS_RB, c = DIS_RC, d = DIS_RD;
sprintf(o->mnemonic, "ps_%s%c", fix, Rc ? '.' : 0);
sprintf(o->operands, "%s%i" COMMA "%s%i" COMMA "%s%i" COMMA "%s%i", fregname, d, fregname, a, fregname, c, fregname, b);
o->r[0] = d; o->r[1] = a; o->r[2] = c; o->r[3] = b;
o->iclass = PPC_DISA_FPU | PPC_DISA_SPECIFIC;
}
static void ps_dac(char *fix)
{
int a = DIS_RA, c = DIS_RC, d = DIS_RD;
if(Instr & 0x0000F800) { ill(); return; }
sprintf(o->mnemonic, "ps_%s%c", fix, Rc ? '.' : 0);
sprintf(o->operands, "%s%i" COMMA "%s%i" COMMA "%s%i", fregname, d, fregname, a, fregname, c);
o->r[0] = d; o->r[1] = a; o->r[2] = c;
o->iclass = PPC_DISA_FPU | PPC_DISA_SPECIFIC;
}
static void ps_dab(char *fix, int unmask=0)
{
int d = DIS_RD, a = DIS_RA, b = DIS_RB;
if(Instr & 0x000007C0 && !unmask) { ill(); return; }
sprintf(o->mnemonic, "ps_%s%c", fix, Rc ? '.' : 0);
sprintf(o->operands, "%s%i" COMMA "%s%i" COMMA "%s%i", fregname, d, fregname, a, fregname, b);
o->r[0] = d; o->r[1] = a; o->r[2] = b;
o->iclass = PPC_DISA_FPU | PPC_DISA_SPECIFIC;
}
static void ps_db(char *fix, int aonly=0)
{
int d = DIS_RD, b = DIS_RB;
if(aonly) { if(Instr & 0x001F0000) { ill(); return; } }
else { if(Instr & 0x001F07C0) { ill(); return; } }
sprintf(o->mnemonic, "ps_%s%c", fix, Rc ? '.' : 0);
sprintf(o->operands, "%s%i" COMMA "%s%i", fregname, d, fregname, b);
o->r[0] = d; o->r[1] = b;
o->iclass = PPC_DISA_FPU | PPC_DISA_SPECIFIC;
}
#endif /* END OF GEKKO */
// ---------------------------------------------------------------------------
void PPCDisasm(PPCD_CB *discb)
{
// Save parameters in local variables for static calls
o = discb;
if(o == NULL) return;
// Detect endianness order.
if(bigendian == -1)
{
u8 test_value[2] = { 0xAA, 0xBB };
u16 *value = (u16 *)test_value;
if(*value == 0xAABB) bigendian = 1;
else bigendian = 0;
}
// Reset output parameters
o->iclass = PPC_DISA_OTHER;
o->r[0] = o->r[1] = o->r[2] = o->r[3] = 0;
o->immed = 0;
o->target = 0;
o->mnemonic[0] = o->operands[0] = '\0';
// Lets go!
/*
* Main table
*/
switch(Instr >> 26 /* Main opcode, base 8 */) {
#ifdef POWERPC_64
case 002: trap(1, 1); break; // tdi
#endif
case 003: trap(0, 1); break; // twi
case 007: integer("mulli", 'D', DAB_D|DAB_A); break; // mulli
case 010: integer("subfic", 'D', DAB_D|DAB_A); break; // subfic
case 012: cmp("l", "i"); break; // cmpli
case 013: cmp("", "i"); break; // cmpi
case 014: addi("c"); break; // addic
case 015: addi("c."); break; // addic.
case 016: addi(""); break; // addi
case 017: addi("s"); break; // addis
case 020: bcx(1, 0); break; // bcx
case 021: put("sc", 0x03ffffff, 2); break; // sc
case 022: bx(); break; // bx
case 024: rlw("imi", 0, 1); break; // rlwimix
case 025: rlw("inm", 0); break; // rlwinmx
case 027: rlw("nm", 1); break; // rlwnmx
case 030: // ori
#ifdef SIMPLIFIED
if(Instr == 0x60000000) put("nop", 0, 0, PPC_DISA_INTEGER | PPC_DISA_SIMPLIFIED);
else
#endif
integer("ori", 'S', ASB_A|ASB_S, 1, 0); break;
case 031: integer("oris", 'S', ASB_A|ASB_S, 1, 0); break; // oris
case 032: integer("xori", 'S', ASB_A|ASB_S, 1, 0); break; // xori
case 033: integer("xoris", 'S', ASB_A|ASB_S, 1, 0); break; // xoris
case 034: integer("andi.", 'S', ASB_A|ASB_S, 1, 0); break; // andi.
case 035: integer("andis.", 'S', ASB_A|ASB_S, 1, 0); break; // andis.
case 040: ldst("lwz", 0, 1); break; // lwz
case 041: ldst("lwzu", 0, 1); break; // lwzu
case 042: ldst("lbz", 0, 1); break; // lbz
case 043: ldst("lbzu", 0, 1); break; // lbzu
case 044: ldst("stw", 0, 0); break; // stw
case 045: ldst("stwu", 0, 0); break; // stwu
case 046: ldst("stb", 0, 0); break; // stb
case 047: ldst("stbu", 0, 0); break; // stbu
case 050: ldst("lhz", 0, 1); break; // lhz
case 051: ldst("lhzu", 0, 1); break; // lhzu
case 052: ldst("lha", 0, 1); break; // lha
case 053: ldst("lhau", 0, 1); break; // lhau
case 054: ldst("sth", 0, 0); break; // sth
case 055: ldst("sthu", 0, 0); break; // sthu
case 056: ldst("lmw", 0, 1, 0, 1); break; // lmw
case 057: ldst("stmw", 0, 0, 0, 1); break; // stmw
case 060: ldst("lfs", 0, 1, 0, 0, 1); break; // lfs
case 061: ldst("lfsu", 0, 1, 0, 0, 1); break; // lfsu
case 062: ldst("lfd", 0, 1, 0, 0, 1); break; // lfd
case 063: ldst("lfdu", 0, 1, 0, 0, 1); break; // lfdu
case 064: ldst("stfs", 0, 0, 0, 0, 1); break; // stfs
case 065: ldst("stfsu", 0, 0, 0, 0, 1); break; // stfsu
case 066: ldst("stfd", 0, 0, 0, 0, 1); break; // stfd
case 067: ldst("stfdu", 0, 0, 0, 0, 1); break; // stfdu
/*
* Extention 1.
*/
case 023:
switch((Instr >> 1) & 0x3ff /* Extended opcode 023, base 8 */) {
case 00020: bcx(0, 1); break; // bclrx
case 01020: bcx(0, 0); break; // bcctrx
case 00000: mcrf(); break; // mcrf
case 00401: crop("and"); break; // crand
case 00201: crop("andc"); break; // crandc
case 00441: crop("eqv", "set", 1); break; // creqv
case 00341: crop("nand"); break; // crnand
case 00041: crop("nor", "not", 0, 1); break; // crnor
case 00701: crop("or", "move", 0, 1); break; // cror
case 00641: crop("orc"); break; // crorc
case 00301: crop("xor", "clr", 1); break; // crxor
case 00226: put("isync", 0x3fff801); break; // isync
#ifdef POWERPC_32
case 00062: put("rfi", 0x3fff801, 0, PPC_DISA_OEA | PPC_DISA_BRIDGE ); break; // rfi
#endif
#ifdef POWERPC_64
case 00022: put("rfid", 0x3fff801, 0, PPC_DISA_OEA | PPC_DISA_64 ); break; // rfid
#endif
default: ill(); break;
} break;
#ifdef POWERPC_64
case 036:
switch((Instr >> 1) & 0xf /* Rotate left double */) {
case 0x0: rld("icl", 0, RLDM_LEFT); break; // rldiclx
case 0x1: rld("icl", 0, RLDM_LEFT); break;
case 0x2: rld("icr", 0, RLDM_RIGHT); break; // rldicrx
case 0x3: rld("icr", 0, RLDM_RIGHT); break;
case 0x4: rld("ic", 0, RLDM_INS); break; // rldicx
case 0x5: rld("ic", 0, RLDM_INS); break;
case 0x6: rld("imi", 0, RLDM_INS); break; // rldimix
case 0x7: rld("imi", 0, RLDM_INS); break;
case 0x8: rld("cl", 1, RLDM_LEFT); break; // rldclx
case 0x9: rld("cr", 1, RLDM_RIGHT); break; // rldcrx
default: ill(); break;
} break;
#endif
/*
* Extention 2.
*/
#define OE 02000
case 037:
switch(Instr & 0x7ff /* Extended opcode 037, base 8 */) {
case 00000: cmp("", ""); break; // cmp
case 00010: // tw
#ifdef SIMPLIFIED
if(Instr == 0x7FE00008) put("trap", 0, 0, PPC_DISA_SIMPLIFIED);
else
#endif
trap(0, 0); break;
case 00020: integer("subfc", 'X', DAB_D|DAB_A|DAB_B); break; // subfcx
case 00020|OE: integer("subfco", 'X', DAB_D|DAB_A|DAB_B); break;
case 00021: integer("subfc.", 'X', DAB_D|DAB_A|DAB_B); break;
case 00021|OE: integer("subfco.", 'X', DAB_D|DAB_A|DAB_B); break;
case 00024: integer("addc", 'X', DAB_D|DAB_A|DAB_B); break; // addcx
case 00024|OE: integer("addco", 'X', DAB_D|DAB_A|DAB_B); break;
case 00025: integer("addc.", 'X', DAB_D|DAB_A|DAB_B); break;
case 00025|OE: integer("addco.", 'X', DAB_D|DAB_A|DAB_B); break;
case 00026: integer("mulhwu", 'X', DAB_D|DAB_A|DAB_B); break; // mulhwu
case 00027: integer("mulhwu.", 'X', DAB_D|DAB_A|DAB_B); break;
case 00046: if(DIS_RA | DIS_RB) ill(); // mfcr
else { integer("mfcr", 'D', DAB_D, 0,0,0,0,0); o->iclass = PPC_DISA_OTHER; } break;
case 00050: ldst("lwarx", 1); break; // lwarx
case 00056: ldst("lwzx", 1); break; // lwzx
case 00060: integer("slw", 'Z', ASB_A|ASB_S|ASB_B); break; // slwx
case 00061: integer("slw.", 'Z', ASB_A|ASB_S|ASB_B); break;
case 00064: if(DIS_RB) ill(); // cntlzwx
else integer("cntlzw", 'S', ASB_A|ASB_S, 0,0,0,0,0); break;
case 00065: if(DIS_RB) ill();
else integer("cntlzw.", 'S', ASB_A|ASB_S, 0,0,0,0,0); break;
case 00070: integer("and", 'Z', ASB_A|ASB_S|ASB_B); break; // andx
case 00071: integer("and.", 'Z', ASB_A|ASB_S|ASB_B); break;
case 00100: cmp("l", ""); break; // cmpl
case 00120: integer("subf", 'X', DAB_D|DAB_A|DAB_B); break; // subfx
case 00120|OE: integer("subfo", 'X', DAB_D|DAB_A|DAB_B); break;
case 00121: integer("subf.", 'X', DAB_D|DAB_A|DAB_B); break;
case 00121|OE: integer("subfo.", 'X', DAB_D|DAB_A|DAB_B); break;
case 00154: cache("dcbst"); break; // dcbst
case 00156: ldst("lwzux", 1); break; // lwzux
case 00170: integer("andc", 'Z', ASB_A|ASB_S|ASB_B); break; // andcx
case 00171: integer("andc.", 'Z', ASB_A|ASB_S|ASB_B); break;
case 00226: integer("mulhw", 'X', DAB_D|DAB_A|DAB_B); break; // mulhw
case 00227: integer("mulhw.", 'X', DAB_D|DAB_A|DAB_B); break;
case 00246: if(DIS_RA || DIS_RB) ill(); // mfmsr
else { integer("mfmsr", 'X', DAB_D); o->iclass = PPC_DISA_OEA; } break;
case 00254: cache("dcbf"); break; // dcbf
case 00256: ldst("lbzx", 1, 1, 0); break; // lbzx
case 00320: if(DIS_RB) ill(); // negx
else integer("neg", 'X', DAB_D|DAB_A); break;
case 00321: if(DIS_RB) ill();
else integer("neg.", 'X', DAB_D|DAB_A); break;
case 00320|OE: if(DIS_RB) ill();
else integer("nego", 'X', DAB_D|DAB_A); break;
case 00321|OE: if(DIS_RB) ill();
else integer("nego.", 'X', DAB_D|DAB_A); break;
case 00356: ldst("lbzux", 1, 1); break; // lbzux
case 00370: // norx
#ifdef SIMPLIFIED
if(DIS_RS == DIS_RB) { integer("not", 'Z', ASB_A|ASB_S); o->iclass |= PPC_DISA_SIMPLIFIED; }
else
#endif
integer("nor", 'Z', ASB_A|ASB_S|ASB_B); break;
case 00371: integer("nor.", 'Z', ASB_A|ASB_S|ASB_B); break;
case 00420: integer("subfe", 'X', DAB_D|DAB_A|DAB_B); break; // subfex
case 00420|OE: integer("subfeo", 'X', DAB_D|DAB_A|DAB_B); break;
case 00421: integer("subfe.", 'X', DAB_D|DAB_A|DAB_B); break;
case 00421|OE: integer("subfeo.", 'X', DAB_D|DAB_A|DAB_B); break;
case 00424: integer("adde", 'X', DAB_D|DAB_A|DAB_B); break; // addex
case 00424|OE: integer("addeo", 'X', DAB_D|DAB_A|DAB_B); break;
case 00425: integer("adde.", 'X', DAB_D|DAB_A|DAB_B); break;
case 00425|OE: integer("addeo.", 'X', DAB_D|DAB_A|DAB_B); break;
case 00440: mtcrf(); break; // mtcrf
#ifdef POWERPC_32
case 00444: if(DIS_RA || DIS_RB) ill(); // mtmsr
else { integer("mtmsr", 'X', DAB_D); o->iclass = PPC_DISA_OEA | PPC_DISA_BRIDGE; } break;
#endif
case 00455: ldst("stwcx.", 1, 0, 0); break; // stwcx.
case 00456: ldst("stwx", 1, 0, 0); break; // stwx
case 00556: ldst("stwux", 1, 0, 0); break; // stwux
case 00620: if(DIS_RB) ill(); // subfzex
else integer("subfze", 'X', DAB_D|DAB_A); break;
case 00620|OE: if(DIS_RB) ill();
else integer("subfzeo", 'X', DAB_D|DAB_A); break;
case 00621: if(DIS_RB) ill();
else integer("subfze.", 'X', DAB_D|DAB_A); break;
case 00621|OE: if(DIS_RB) ill();
else integer("subfzeo.", 'X', DAB_D|DAB_A); break;
case 00624: if(DIS_RB) ill(); // addzex
else integer("addze", 'X', DAB_D|DAB_A); break;
case 00624|OE: if(DIS_RB) ill();
else integer("addzeo", 'X', DAB_D|DAB_A); break;
case 00625: if(DIS_RB) ill();
else integer("addze.", 'X', DAB_D|DAB_A); break;
case 00625|OE: if(DIS_RB) ill();
else integer("addzeo.", 'X', DAB_D|DAB_A); break;
#ifdef POWERPC_32
case 00644: movesr("mtsr", 0, 0, 0); break; // mtsr
#endif
case 00656: ldst("stbx", 1, 0, 0); break; // stbx
case 00720: if(DIS_RB) ill(); // subfmex
else integer("subfme", 'X', DAB_D|DAB_A); break;
case 00720|OE: if(DIS_RB) ill();
else integer("subfmeo", 'X', DAB_D|DAB_A); break;
case 00721: if(DIS_RB) ill();
else integer("subfme.", 'X', DAB_D|DAB_A); break;
case 00721|OE: if(DIS_RB) ill();
else integer("subfmeo.", 'X', DAB_D|DAB_A); break;
case 00724: if(DIS_RB) ill(); // addmex
else integer("addme", 'X', DAB_D|DAB_A); break;
case 00724|OE: if(DIS_RB) ill();
else integer("addmeo", 'X', DAB_D|DAB_A); break;
case 00725: if(DIS_RB) ill();
else integer("addme.", 'X', DAB_D|DAB_A); break;
case 00725|OE: if(DIS_RB) ill();
else integer("addmeo.", 'X', DAB_D|DAB_A); break;
case 00726: integer("mullw", 'X', DAB_D|DAB_A|DAB_B); break; // mullwx
case 00726|OE: integer("mullwo", 'X', DAB_D|DAB_A|DAB_B); break;
case 00727: integer("mullw.", 'X', DAB_D|DAB_A|DAB_B); break;
case 00727|OE: integer("mullwo.", 'X', DAB_D|DAB_A|DAB_B); break;
#ifdef POWERPC_32
case 00744: movesr("mtsrin", 0, 0, 1); break; // mtsrin
#endif
case 00754: cache("dcbtst"); break; // dcbtst
case 00756: ldst("stbux", 1, 0, 0); break; // stbux
case 01024: integer("add", 'X', DAB_D|DAB_A|DAB_B); break; // addx
case 01024|OE: integer("addo", 'X', DAB_D|DAB_A|DAB_B); break;
case 01025: integer("add.", 'X', DAB_D|DAB_A|DAB_B); break;
case 01025|OE: integer("addo.", 'X', DAB_D|DAB_A|DAB_B); break;
case 01054: cache("dcbt"); break; // dcbt
case 01056: ldst("lhzx", 1); break; // lhzx
case 01070: integer("eqv", 'Z', ASB_A|ASB_S|ASB_B); break; // eqvx
case 01071: integer("eqv.", 'Z', ASB_A|ASB_S|ASB_B); break;
case 01144: if(DIS_RD || DIS_RA) ill(); // tlbie
else { integer("tlbie", 'X', DAB_B); o->iclass = PPC_DISA_OEA | PPC_DISA_OPTIONAL; o->r[0] = o->r[2]; o->r[2] = 0; } break;
case 01154: integer("eciwx", 'X', DAB_D|DAB_A|DAB_B); o->iclass = PPC_DISA_OPTIONAL; break; // eciwx
case 01156: ldst("lhzux", 1); break; // lhzux
case 01170: integer("xor", 'Z', ASB_A|ASB_S|ASB_B); break; // xorx
case 01171: integer("xor.", 'Z', ASB_A|ASB_S|ASB_B); break;
case 01246: movespr(1); break; // mfspr
case 01256: ldst("lhax", 1); break; // lhax
#if !defined(GEKKO)
case 01344: put("tlbia", 0x03FFF800, 0, PPC_DISA_OEA | PPC_DISA_OPTIONAL); break; // tlbia
#endif
case 01346: movetbr(); break; // mftb
case 01356: ldst("lhaux", 1); break; // lhaux
case 01456: ldst("sthx", 1, 0); break; // sthx
case 01470: integer("orc", 'Z', ASB_A|ASB_S|ASB_B); break; // orcx
case 01471: integer("orc.", 'Z', ASB_A|ASB_S|ASB_B); break;
case 01554: integer("ecowx", 'X', DAB_D|DAB_A|DAB_B); o->iclass = PPC_DISA_OPTIONAL; break; // ecowx
case 01556: ldst("sthux", 1, 0); break; // sthux
case 01570: integer("or", 'Z', ASB_A|ASB_S|ASB_B); break; // orx
case 01571: integer("or.", 'Z', ASB_A|ASB_S|ASB_B); break;
case 01626: integer("divwu", 'X', DAB_D|DAB_A|DAB_B); break; // divwux
case 01626|OE: integer("divwuo", 'X', DAB_D|DAB_A|DAB_B); break;
case 01627: integer("divwu.", 'X', DAB_D|DAB_A|DAB_B); break;
case 01627|OE: integer("divwuo.", 'X', DAB_D|DAB_A|DAB_B); break;
case 01646: movespr(0); break; // mtspr
case 01654: cache("dcbi", PPC_DISA_OEA); break; // dcbi
case 01670: integer("nand", 'Z', ASB_A|ASB_S|ASB_B); break; // nandx
case 01671: integer("nand.", 'Z', ASB_A|ASB_S|ASB_B); break;
case 01726: integer("divw", 'X', DAB_D|DAB_A|DAB_B); break; // divwx
case 01726|OE: integer("divwo", 'X', DAB_D|DAB_A|DAB_B); break;
case 01727: integer("divw.", 'X', DAB_D|DAB_A|DAB_B); break;
case 01727|OE: integer("divwo.", 'X', DAB_D|DAB_A|DAB_B); break;
case 02000: mcrxr(); break; // mcrxr
case 02052: ldst("lswx", 1, 1, 0, 1); break; // lswx
case 02054: ldst("lwbrx", 1); break; // lwbrx
case 02056: ldst("lfsx", 1, 1, 0, 0, 1); break; // lfsx
case 02060: integer("srw", 'Z', ASB_A|ASB_S|ASB_B); break; // srwx
case 02061: integer("srw.", 'Z', ASB_A|ASB_S|ASB_B); break;
case 02154: put("tlbsync", 0x03FFF800, 0, PPC_DISA_OEA | PPC_DISA_OPTIONAL); break; // tlbsync
case 02156: ldst("lfsux", 1, 1, 0, 0, 1); break; // lfsux
#ifdef POWERPC_32
case 02246: movesr("mfsr", 1, 0, 0); break; // mfsr
#endif
case 02252: lsswi("lswi"); break; // lswi
case 02254: put("sync", 0x03FFF800, 0); break; // sync
case 02256: ldst("lfdx", 1, 1, 0, 0, 1); break; // lfdx
case 02356: ldst("lfdux", 1, 1, 0, 0, 1); break; // lfdux
#ifdef POWERPC_32
case 02446: movesr("mfsrin", 1, 0, 1); break; // mfsrin
#endif
case 02452: ldst("stswx", 1, 1, 0, 1); break; // stswx
case 02454: ldst("stwbrx", 1, 0); break; // stwbrx
case 02456: ldst("stfsx", 1, 1, 0, 0, 1); break; // stfsx
case 02556: ldst("stfsux", 1, 1, 0, 0, 1); break; // stfsux
case 02652: lsswi("stswi"); break; // stswi
case 02656: ldst("stfdx", 1, 1, 0, 0, 1); break; // stfdx
#if !defined(GEKKO)
case 02754: cache("dcba", PPC_DISA_OPTIONAL); break; // dcba
#endif
case 02756: ldst("stfdux", 1, 1, 0, 0, 1); break; // stfdux
case 03054: ldst("lhbrx", 1); break; // lhbrx
case 03060: integer("sraw", 'Z', ASB_A|ASB_S|ASB_B); break; // srawx
case 03061: integer("sraw.", 'Z', ASB_A|ASB_S|ASB_B); break;
case 03160: srawi(); break; // srawi
case 03161: srawi(); break;
case 03254: put("eieio", 0x03FFF800, 0); break; // eieio
case 03454: ldst("sthbrx", 1, 0); break; // sthbrx
case 03464: if(DIS_RB) ill(); // extshx
else integer("extsh", 'S', ASB_A|ASB_S, 0,0,0,0,0); break;
case 03465: if(DIS_RB) ill();
else integer("extsh.", 'S', ASB_A|ASB_S, 0,0,0,0,0); break;
case 03564: if(DIS_RB) ill(); // extsbx
else integer("extsb", 'S', ASB_A|ASB_S, 0,0,0,0,0); break;
case 03565: if(DIS_RB) ill();
else integer("extsb.", 'S', ASB_A|ASB_S, 0,0,0,0,0); break;
case 03654: cache("icbi"); break; // icbi
case 03656: ldst("stfiwx", 1, 1, 0, 0, 1); o->iclass |= PPC_DISA_OPTIONAL; break; // stfiwx
case 03754: cache("dcbz"); break; // dcbz
#ifdef POWERPC_64
case 00022: integer("mulhdu", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break; // mulhdux
case 00023: integer("mulhdu.", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break;
case 00052: ldst("ldx", 1, 1, 1); break; // ldx
case 00066: integer("sld", 'Z', ASB_A|ASB_S|ASB_B); o->iclass |= PPC_DISA_64; break; // sldx
case 00067: integer("sld.", 'Z', ASB_A|ASB_S|ASB_B); o->iclass |= PPC_DISA_64; break;
case 00152: ldst("ldux", 1, 1, 1); break; // ldux
case 00164: if(DIS_RB) ill(); // cntlzdx
else integer("cntlzd", 'S', ASB_A|ASB_S, 0,0,0,0,0); o->iclass |= PPC_DISA_64; break;
case 00165: if(DIS_RB) ill();
else integer("cntlzd.", 'S', ASB_A|ASB_S, 0,0,0,0,0); o->iclass |= PPC_DISA_64; break;
case 00210: trap(1, 0); break;
case 00222: integer("mulhd", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break; // mulhdx
case 00223: integer("mulhd.", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break;
case 00244: movesr("mtsrd", 0, 1, 0); break; // mtrsd
case 00250: ldst("ldarx", 1, 1, 1); break; // ldarx
case 00344: movesr("mtsrdin", 0, 1, 1); break; // mtrsdin
case 00452: ldst("stdx", 1, 0, 1); break; // stdx
case 00544: if(DIS_RA || DIS_RB) ill(); // mtmsrd
else { integer("mtmsrd", 'X', DAB_D); o->iclass = PPC_DISA_OEA | PPC_DISA_64; } break;
case 00552: ldst("stdux", 1, 0, 1); break; // stdux
case 00655: ldst("stdcx.", 1, 0, 1); break; // stdcx.
case 00722: integer("mulld", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break; // mulldx
case 00722|OE: integer("mulldo", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break;
case 00723: integer("mulld.", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break;
case 00723|OE: integer("mulldo.", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break;
case 01252: ldst("lwax", 1, 1, 1); break; // lwax
case 01352: ldst("lwaux", 1, 1, 1); break; // lwaux
case 03164: sradi(); break; // sradi
case 03165: sradi(); break;
case 03166: sradi(); break;
case 03167: sradi(); break;
case 01544: if(DIS_RD || DIS_RA) ill(); // slbie
else { integer("slbie", 'X', DAB_B); o->iclass = PPC_DISA_64 | PPC_DISA_OEA | PPC_DISA_OPTIONAL; o->r[0] = o->r[2]; o->r[2] = 0; } break;
case 01622: integer("divdu", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break; // divdux
case 01622|OE: integer("divduo", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break;
case 01623: integer("divdu.", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break;
case 01623|OE: integer("divduo.", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break;
case 01722: integer("divd", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break; // divdx
case 01722|OE: integer("divdo", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break;
case 01723: integer("divd.", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break;
case 01723|OE: integer("divdo.", 'X', DAB_D|DAB_A|DAB_B); o->iclass |= PPC_DISA_64; break;
case 01744: put("slbia", 0x03FFF800, 0, PPC_DISA_64 | PPC_DISA_OEA | PPC_DISA_OPTIONAL); break; // slbia
case 02066: integer("srd", 'Z', ASB_A|ASB_S|ASB_B); o->iclass |= PPC_DISA_64; break; // srdx
case 02067: integer("srd.", 'Z', ASB_A|ASB_S|ASB_B); o->iclass |= PPC_DISA_64; break;
case 03064: integer("srad", 'Z', ASB_A|ASB_S|ASB_B); o->iclass |= PPC_DISA_64; break; // sradx
case 03065: integer("srad.", 'Z', ASB_A|ASB_S|ASB_B); o->iclass |= PPC_DISA_64; break;
case 03664: if(DIS_RB) ill(); // extswx
else { integer("extsw", 'S', ASB_A|ASB_S, 0,0,0,0,0); o->iclass |= PPC_DISA_64; } break;
case 03665: if(DIS_RB) ill();
else { integer("extsw.", 'S', ASB_A|ASB_S, 0,0,0,0,0); o->iclass |= PPC_DISA_64; } break;
#endif
default: ill(); break;
} break;
/*
* Extention 3.
*/
#ifdef POWERPC_64
case 072:
switch(Instr & 3) {
case 0: Instr &= ~3; ldst("ld", 0, 1, 1); break; // ld
case 1: Instr &= ~3; ldst("ldu", 0, 1, 1); break; // ldu
case 2: Instr &= ~3; ldst("lwa", 0, 1, 1); break; // lwa
default: ill(); break;
} break;
#endif
/*
* Extention 4.
*/
#define MASK_D (0x1F << 21)
#define MASK_A (0x1F << 16)
#define MASK_B (0x1F << 11)
#define MASK_C (0x1F << 6)
case 073:
switch(Instr & 0x3F) {
case 044: fpu("fdivs", MASK_C, FPU_DAB); break; // fdivsx
case 045: fpu("fdivs.", MASK_C, FPU_DAB); break;
case 050: fpu("fsubs", MASK_C, FPU_DAB); break; // fsubsx
case 051: fpu("fsubs.", MASK_C, FPU_DAB); break;
case 052: fpu("fadds", MASK_C, FPU_DAB); break; // faddsx
case 053: fpu("fadds.", MASK_C, FPU_DAB); break;
#if !defined(GEKKO)
case 054: fpu("fsqrts", MASK_A|MASK_C, FPU_DB, PPC_DISA_OPTIONAL); break; // fsqrtsx
case 055: fpu("fsqrts.", MASK_A|MASK_C, FPU_DB, PPC_DISA_OPTIONAL); break;
#endif
case 060: fpu("fres", MASK_A|MASK_C, FPU_DB, PPC_DISA_OPTIONAL); break; // fresx
case 061: fpu("fres.", MASK_A|MASK_C, FPU_DB, PPC_DISA_OPTIONAL); break;
case 062: fpu("fmuls", MASK_B, FPU_DAC); break; // fmulsx
case 063: fpu("fmuls.", MASK_B, FPU_DAC); break;
case 070: fpu("fmsubs", 0, FPU_DACB); break; // fmsubsx
case 071: fpu("fmsubs.", 0, FPU_DACB); break;
case 072: fpu("fmadds", 0, FPU_DACB); break; // fmaddsx
case 073: fpu("fmadds.", 0, FPU_DACB); break;
case 074: fpu("fnmsubs", 0, FPU_DACB); break; // fnmsubsx
case 075: fpu("fnmsubs.", 0, FPU_DACB); break;
case 076: fpu("fnmadds", 0, FPU_DACB); break; // fnmaddsx
case 077: fpu("fnmadds.", 0, FPU_DACB); break;
default: ill(); break;
} break;
/*
* Extention 5.
*/
#ifdef POWERPC_64
case 076:
switch(Instr & 3) {
case 0: Instr &= ~3; ldst("std", 0, 0, 1); break; // std
case 1: Instr &= ~3; ldst("stdu", 0, 0, 1); break; // stdu
default: ill(); break;
} break;
#endif
/*
* Extention 6.
*/
case 077:
switch(Instr & 0x3F) {
case 000:
switch(DIS_RC)
{
case 0: fcmp("fcmpu"); break; // fcmpu
case 1: fcmp("fcmpo"); break; // fcmpo
case 2: mcrfs(); break; // mcrfs
default: ill(); break;
}
break;
case 014:
switch(DIS_RC)
{
case 1: mtfsb("mtfsb1"); break; // mtfsb1
case 2: mtfsb("mtfsb0"); break; // mtfsb0
case 4: mtfsfi(); break; // mtfsfi
default: ill(); break;
}
break;
case 015:
switch(DIS_RC)
{
case 1: mtfsb("mtfsb1."); break; // mtfsb1.
case 2: mtfsb("mtfsb0."); break; // mtfsb0.
case 4: mtfsfi(); break; // mtfsfi.
default: ill(); break;
}
break;
case 016:
switch(DIS_RC)
{
case 18: fpu("mffs", MASK_A|MASK_B, FPU_D); break; // mffs
case 22: mtfsf(); break; // mtfsf
default: ill(); break;
}
break;
case 017:
switch(DIS_RC)
{
case 18: fpu("mffs.", MASK_A|MASK_B, FPU_D); break; // mffs.
case 22: mtfsf(); break; // mtfsf.
default: ill(); break;
}
break;
case 020:
switch(DIS_RC)
{
case 1: fpu("fneg", MASK_A, FPU_DB); break; // fneg
case 2: fpu("fmr", MASK_A, FPU_DB); break; // fmr
case 4: fpu("fnabs", MASK_A, FPU_DB); break; // fnabs
case 8: fpu("fabs", MASK_A, FPU_DB); break; // fabs
default: ill(); break;
}
break;
case 021:
switch(DIS_RC)
{
case 1: fpu("fneg.", MASK_A, FPU_DB); break; // fneg
case 2: fpu("fmr.", MASK_A, FPU_DB); break; // fmr
case 4: fpu("fnabs.", MASK_A, FPU_DB); break; // fnabs
case 8: fpu("fabs.", MASK_A, FPU_DB); break; // fabs
default: ill(); break;
}
break;
case 030:
switch(DIS_RC)
{
case 0: fpu("frsp", MASK_A, FPU_DB); break; // frsp
default: ill(); break;
}
break;
case 031:
switch(DIS_RC)
{
case 0: fpu("frsp.", MASK_A, FPU_DB); break; // frsp.
default: ill(); break;
}
break;
case 034:
switch(DIS_RC)
{
case 0: fpu("fctiw", MASK_A, FPU_DB); break; // fctiw
#ifdef POWERPC_64
case 25: fpu("fctid", MASK_A, FPU_DB); break; // fctid
case 26: fpu("fcfid", MASK_A, FPU_DB); break; // fcfid
#endif
default: ill(); break;
}
break;
case 035:
switch(DIS_RC)
{
case 0: fpu("fctiw.", MASK_A, FPU_DB); break; // fctiw.
#ifdef POWERPC_64
case 25: fpu("fctid.", MASK_A, FPU_DB); break; // fctid.
case 26: fpu("fcfid.", MASK_A, FPU_DB); break; // fcfid.
#endif
default: ill(); break;
}
break;
case 036:
switch(DIS_RC)
{
case 0: fpu("fctiwz", MASK_A, FPU_DB); break; // fctiwz
#ifdef POWERPC_64
case 25: fpu("fctidz", MASK_A, FPU_DB); break; // fctidz
#endif
default: ill(); break;
}
break;
case 037:
switch(DIS_RC)
{
case 0: fpu("fctiwz.", MASK_A, FPU_DB); break; // fctiwz.
#ifdef POWERPC_64
case 25: fpu("fctidz.", MASK_A, FPU_DB); break; // fctidz.
#endif
default: ill(); break;
}
break;
case 044: fpu("fdiv", MASK_C, FPU_DAB); break; // fdivx
case 045: fpu("fdiv.", MASK_C, FPU_DAB); break;
case 050: fpu("fsub", MASK_C, FPU_DAB); break; // fsubx
case 051: fpu("fsub.", MASK_C, FPU_DAB); break;
case 052: fpu("fadd", MASK_C, FPU_DAB); break; // faddx
case 053: fpu("fadd.", MASK_C, FPU_DAB); break;
#if !defined(GEKKO)
case 054: fpu("fsqrt", MASK_A|MASK_C, FPU_DB, PPC_DISA_OPTIONAL); break; // fsqrtx
case 055: fpu("fsqrt.", MASK_A|MASK_C, FPU_DB, PPC_DISA_OPTIONAL); break;
#endif
case 056: fpu("fsel", 0, FPU_DACB, PPC_DISA_OPTIONAL); break; // fselx
case 057: fpu("fsel.", 0, FPU_DACB, PPC_DISA_OPTIONAL); break;
case 062: fpu("fmul", MASK_B, FPU_DAC); break; // fmulx
case 063: fpu("fmul.", MASK_B, FPU_DAC); break;
case 064: fpu("frsqrte", MASK_A|MASK_C, FPU_DB, PPC_DISA_OPTIONAL); break; // frsqrtex
case 065: fpu("frsqrte.", MASK_A|MASK_C, FPU_DB, PPC_DISA_OPTIONAL); break;
case 070: fpu("fmsub", 0, FPU_DACB); break; // fmsubx
case 071: fpu("fmsub.", 0, FPU_DACB); break;
case 072: fpu("fmadd", 0, FPU_DACB); break; // fmaddx
case 073: fpu("fmadd.", 0, FPU_DACB); break;
case 074: fpu("fnmsub", 0, FPU_DACB); break; // fnmsubx
case 075: fpu("fnmsub.", 0, FPU_DACB); break;
case 076: fpu("fnmadd", 0, FPU_DACB); break; // fnmaddx
case 077: fpu("fnmadd.", 0, FPU_DACB); break;
default: ill(); break;
} break;
/*
***********************************************************************************
* GEKKO Extention.
***********************************************************************************
*/
#ifdef GEKKO
case 004:
if(((Instr >> 1) & 0x3FF) == 1014)
{
cache("dcbz_l", PPC_DISA_SPECIFIC); // dcbz_l
}
else switch((Instr >> 1) & 0x1f)
{
case 0: ps_cmpx((Instr >> 6) & 3); break; // ps_cmpXX
case 6: if(Instr & 0x40) ps_ldstx("lux"); // ps_lux
else ps_ldstx("lx"); break; // ps_lx
case 7: if(Instr & 0x40) ps_ldstx("stux"); // ps_stux
else ps_ldstx("stx"); break; // ps_stx
case 8:
switch((Instr >> 6) & 0x1f)
{
case 1: ps_db("neg", 1); break; // ps_negx
case 2: ps_db("mr", 1); break; // ps_mrx
case 4: ps_db("nabs", 1); break; // ps_nabsx
case 8: ps_db("abs", 1); break; // ps_absx
default: ill(); break;
} break;
case 10: ps_dacb("sum0"); break; // ps_sum0x
case 11: ps_dacb("sum1"); break; // ps_sum1x
case 12: ps_dac("muls0"); break; // ps_muls0x
case 13: ps_dac("muls1"); break; // ps_muls1x
case 14: ps_dacb("madds0"); break; // ps_madds0x
case 15: ps_dacb("madds1"); break; // ps_madds1x
case 16:
switch((Instr >> 6) & 0x1f)
{
case 16: ps_dab("merge00", 1); break; // ps_merge00x
case 17: ps_dab("merge01", 1); break; // ps_merge11x
case 18: ps_dab("merge10", 1); break; // ps_merge10x
case 19: ps_dab("merge11", 1); break; // ps_merge11x
default: ill(); break;
} break;
case 18: ps_dab("div"); break; // ps_divx
case 20: ps_dab("sub"); break; // ps_subx
case 21: ps_dab("add"); break; // ps_addx
case 23: ps_dacb("sel"); break; // ps_selx
case 24: ps_db("res"); break; // ps_resx
case 25: ps_dac("mul"); break; // ps_mulx
case 26: ps_db("rsqrte"); break; // ps_rsqrtex
case 28: ps_dacb("msub"); break; // ps_msubx
case 29: ps_dacb("madd"); break; // ps_maddx
case 30: ps_dacb("nmsub"); break; // ps_nmsubx
case 31: ps_dacb("nmadd"); break; // ps_nmaddx
default: ill(); break;
} break;
case 070: ps_ldst("l"); break; // psq_l
case 071: ps_ldst("lu"); break; // psq_lu
case 074: ps_ldst("st"); break; // psq_st
case 075: ps_ldst("stu"); break; // psq_stu
#endif /* GEKKO */
default: ill(); break;
}
#ifdef UPPERCASE
strupr(o->mnemonic);
#endif
}
char *PPCDisasmSimple(u64 pc, u32 instr)
{
PPCD_CB dis_out;
static char output[256];
dis_out.pc = pc;
dis_out.instr = instr;
PPCDisasm(&dis_out);
sprintf(output, "%08llX %08X %-10s %s", pc, instr, dis_out.mnemonic, dis_out.operands);
return output;
}
| 70,870 | C | .c | 1,623 | 36.583487 | 157 | 0.468625 | libretro/libretro-uae | 112 | 60 | 28 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | false | false | true | true | false | false | false |
1,293,252 | kjmp2.c | libretro_libretro-uae/sources/src/archivers/mp2/kjmp2.c | /******************************************************************************
** kjmp2 -- a minimal MPEG-1/2 Audio Layer II decoder library **
** version 1.1 **
*******************************************************************************
** Copyright (C) 2006-2013 Martin J. Fiedler <[email protected]> **
** **
** 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. **
******************************************************************************/
#include <math.h>
#include "kjmp2.h"
#ifdef _MSC_VER
#define FASTCALL __fastcall
#else
#define FASTCALL
#endif
////////////////////////////////////////////////////////////////////////////////
// TABLES AND CONSTANTS //
////////////////////////////////////////////////////////////////////////////////
// mode constants
#define STEREO 0
#define JOINT_STEREO 1
#define DUAL_CHANNEL 2
#define MONO 3
// sample rate table
static const unsigned short sample_rates[8] = {
44100, 48000, 32000, 0, // MPEG-1
22050, 24000, 16000, 0 // MPEG-2
};
// bitrate table
static const short bitrates[28] = {
32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, // MPEG-1
8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 // MPEG-2
};
// scale factor base values (24-bit fixed-point)
static const int scf_base[3] = { 0x02000000, 0x01965FEA, 0x01428A30 };
// synthesis window
static const int D[512] = {
0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000,-0x00001,
-0x00001,-0x00001,-0x00001,-0x00002,-0x00002,-0x00003,-0x00003,-0x00004,
-0x00004,-0x00005,-0x00006,-0x00006,-0x00007,-0x00008,-0x00009,-0x0000A,
-0x0000C,-0x0000D,-0x0000F,-0x00010,-0x00012,-0x00014,-0x00017,-0x00019,
-0x0001C,-0x0001E,-0x00022,-0x00025,-0x00028,-0x0002C,-0x00030,-0x00034,
-0x00039,-0x0003E,-0x00043,-0x00048,-0x0004E,-0x00054,-0x0005A,-0x00060,
-0x00067,-0x0006E,-0x00074,-0x0007C,-0x00083,-0x0008A,-0x00092,-0x00099,
-0x000A0,-0x000A8,-0x000AF,-0x000B6,-0x000BD,-0x000C3,-0x000C9,-0x000CF,
0x000D5, 0x000DA, 0x000DE, 0x000E1, 0x000E3, 0x000E4, 0x000E4, 0x000E3,
0x000E0, 0x000DD, 0x000D7, 0x000D0, 0x000C8, 0x000BD, 0x000B1, 0x000A3,
0x00092, 0x0007F, 0x0006A, 0x00053, 0x00039, 0x0001D,-0x00001,-0x00023,
-0x00047,-0x0006E,-0x00098,-0x000C4,-0x000F3,-0x00125,-0x0015A,-0x00190,
-0x001CA,-0x00206,-0x00244,-0x00284,-0x002C6,-0x0030A,-0x0034F,-0x00396,
-0x003DE,-0x00427,-0x00470,-0x004B9,-0x00502,-0x0054B,-0x00593,-0x005D9,
-0x0061E,-0x00661,-0x006A1,-0x006DE,-0x00718,-0x0074D,-0x0077E,-0x007A9,
-0x007D0,-0x007EF,-0x00808,-0x0081A,-0x00824,-0x00826,-0x0081F,-0x0080E,
0x007F5, 0x007D0, 0x007A0, 0x00765, 0x0071E, 0x006CB, 0x0066C, 0x005FF,
0x00586, 0x00500, 0x0046B, 0x003CA, 0x0031A, 0x0025D, 0x00192, 0x000B9,
-0x0002C,-0x0011F,-0x00220,-0x0032D,-0x00446,-0x0056B,-0x0069B,-0x007D5,
-0x00919,-0x00A66,-0x00BBB,-0x00D16,-0x00E78,-0x00FDE,-0x01148,-0x012B3,
-0x01420,-0x0158C,-0x016F6,-0x0185C,-0x019BC,-0x01B16,-0x01C66,-0x01DAC,
-0x01EE5,-0x02010,-0x0212A,-0x02232,-0x02325,-0x02402,-0x024C7,-0x02570,
-0x025FE,-0x0266D,-0x026BB,-0x026E6,-0x026ED,-0x026CE,-0x02686,-0x02615,
-0x02577,-0x024AC,-0x023B2,-0x02287,-0x0212B,-0x01F9B,-0x01DD7,-0x01BDD,
0x019AE, 0x01747, 0x014A8, 0x011D1, 0x00EC0, 0x00B77, 0x007F5, 0x0043A,
0x00046,-0x003E5,-0x00849,-0x00CE3,-0x011B4,-0x016B9,-0x01BF1,-0x0215B,
-0x026F6,-0x02CBE,-0x032B3,-0x038D3,-0x03F1A,-0x04586,-0x04C15,-0x052C4,
-0x05990,-0x06075,-0x06771,-0x06E80,-0x0759F,-0x07CCA,-0x083FE,-0x08B37,
-0x09270,-0x099A7,-0x0A0D7,-0x0A7FD,-0x0AF14,-0x0B618,-0x0BD05,-0x0C3D8,
-0x0CA8C,-0x0D11D,-0x0D789,-0x0DDC9,-0x0E3DC,-0x0E9BD,-0x0EF68,-0x0F4DB,
-0x0FA12,-0x0FF09,-0x103BD,-0x1082C,-0x10C53,-0x1102E,-0x113BD,-0x116FB,
-0x119E8,-0x11C82,-0x11EC6,-0x120B3,-0x12248,-0x12385,-0x12467,-0x124EF,
0x1251E, 0x124F0, 0x12468, 0x12386, 0x12249, 0x120B4, 0x11EC7, 0x11C83,
0x119E9, 0x116FC, 0x113BE, 0x1102F, 0x10C54, 0x1082D, 0x103BE, 0x0FF0A,
0x0FA13, 0x0F4DC, 0x0EF69, 0x0E9BE, 0x0E3DD, 0x0DDCA, 0x0D78A, 0x0D11E,
0x0CA8D, 0x0C3D9, 0x0BD06, 0x0B619, 0x0AF15, 0x0A7FE, 0x0A0D8, 0x099A8,
0x09271, 0x08B38, 0x083FF, 0x07CCB, 0x075A0, 0x06E81, 0x06772, 0x06076,
0x05991, 0x052C5, 0x04C16, 0x04587, 0x03F1B, 0x038D4, 0x032B4, 0x02CBF,
0x026F7, 0x0215C, 0x01BF2, 0x016BA, 0x011B5, 0x00CE4, 0x0084A, 0x003E6,
-0x00045,-0x00439,-0x007F4,-0x00B76,-0x00EBF,-0x011D0,-0x014A7,-0x01746,
0x019AE, 0x01BDE, 0x01DD8, 0x01F9C, 0x0212C, 0x02288, 0x023B3, 0x024AD,
0x02578, 0x02616, 0x02687, 0x026CF, 0x026EE, 0x026E7, 0x026BC, 0x0266E,
0x025FF, 0x02571, 0x024C8, 0x02403, 0x02326, 0x02233, 0x0212B, 0x02011,
0x01EE6, 0x01DAD, 0x01C67, 0x01B17, 0x019BD, 0x0185D, 0x016F7, 0x0158D,
0x01421, 0x012B4, 0x01149, 0x00FDF, 0x00E79, 0x00D17, 0x00BBC, 0x00A67,
0x0091A, 0x007D6, 0x0069C, 0x0056C, 0x00447, 0x0032E, 0x00221, 0x00120,
0x0002D,-0x000B8,-0x00191,-0x0025C,-0x00319,-0x003C9,-0x0046A,-0x004FF,
-0x00585,-0x005FE,-0x0066B,-0x006CA,-0x0071D,-0x00764,-0x0079F,-0x007CF,
0x007F5, 0x0080F, 0x00820, 0x00827, 0x00825, 0x0081B, 0x00809, 0x007F0,
0x007D1, 0x007AA, 0x0077F, 0x0074E, 0x00719, 0x006DF, 0x006A2, 0x00662,
0x0061F, 0x005DA, 0x00594, 0x0054C, 0x00503, 0x004BA, 0x00471, 0x00428,
0x003DF, 0x00397, 0x00350, 0x0030B, 0x002C7, 0x00285, 0x00245, 0x00207,
0x001CB, 0x00191, 0x0015B, 0x00126, 0x000F4, 0x000C5, 0x00099, 0x0006F,
0x00048, 0x00024, 0x00002,-0x0001C,-0x00038,-0x00052,-0x00069,-0x0007E,
-0x00091,-0x000A2,-0x000B0,-0x000BC,-0x000C7,-0x000CF,-0x000D6,-0x000DC,
-0x000DF,-0x000E2,-0x000E3,-0x000E3,-0x000E2,-0x000E0,-0x000DD,-0x000D9,
0x000D5, 0x000D0, 0x000CA, 0x000C4, 0x000BE, 0x000B7, 0x000B0, 0x000A9,
0x000A1, 0x0009A, 0x00093, 0x0008B, 0x00084, 0x0007D, 0x00075, 0x0006F,
0x00068, 0x00061, 0x0005B, 0x00055, 0x0004F, 0x00049, 0x00044, 0x0003F,
0x0003A, 0x00035, 0x00031, 0x0002D, 0x00029, 0x00026, 0x00023, 0x0001F,
0x0001D, 0x0001A, 0x00018, 0x00015, 0x00013, 0x00011, 0x00010, 0x0000E,
0x0000D, 0x0000B, 0x0000A, 0x00009, 0x00008, 0x00007, 0x00007, 0x00006,
0x00005, 0x00005, 0x00004, 0x00004, 0x00003, 0x00003, 0x00002, 0x00002,
0x00002, 0x00002, 0x00001, 0x00001, 0x00001, 0x00001, 0x00001, 0x00001
};
///////////// Table 3-B.2: Possible quantization per subband ///////////////////
// quantizer lookup, step 1: bitrate classes
static const char quant_lut_step1[2][16] = {
// 32, 48, 56, 64, 80, 96,112,128,160,192,224,256,320,384 <- bitrate
{ 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2 }, // mono
// 16, 24, 28, 32, 40, 48, 56, 64, 80, 96,112,128,160,192 <- BR / chan
{ 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2 } // stereo
};
// quantizer lookup, step 2: bitrate class, sample rate -> B2 table idx, sblimit
#define QUANT_TAB_A (27 | 64) // Table 3-B.2a: high-rate, sblimit = 27
#define QUANT_TAB_B (30 | 64) // Table 3-B.2b: high-rate, sblimit = 30
#define QUANT_TAB_C 8 // Table 3-B.2c: low-rate, sblimit = 8
#define QUANT_TAB_D 12 // Table 3-B.2d: low-rate, sblimit = 12
static const char quant_lut_step2[3][4] = {
// 44.1 kHz, 48 kHz, 32 kHz
{ QUANT_TAB_C, QUANT_TAB_C, QUANT_TAB_D }, // 32 - 48 kbit/sec/ch
{ QUANT_TAB_A, QUANT_TAB_A, QUANT_TAB_A }, // 56 - 80 kbit/sec/ch
{ QUANT_TAB_B, QUANT_TAB_A, QUANT_TAB_B }, // 96+ kbit/sec/ch
};
// quantizer lookup, step 3: B2 table, subband -> nbal, row index
// (upper 4 bits: nbal, lower 4 bits: row index)
static const char quant_lut_step3[3][32] = {
// low-rate table (3-B.2c and 3-B.2d)
{ 0x44,0x44, // SB 0 - 1
0x34,0x34,0x34,0x34,0x34,0x34,0x34,0x34,0x34,0x34 // SB 2 - 12
},
// high-rate table (3-B.2a and 3-B.2b)
{ 0x43,0x43,0x43, // SB 0 - 2
0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42, // SB 3 - 10
0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31, // SB 11 - 22
0x20,0x20,0x20,0x20,0x20,0x20,0x20 // SB 23 - 29
},
// MPEG-2 LSR table (B.2 in ISO 13818-3)
{ 0x45,0x45,0x45,0x45, // SB 0 - 3
0x34,0x34,0x34,0x34,0x34,0x34,0x34, // SB 4 - 10
0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24, // SB 11 -
0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24 // - 29
}
};
// quantizer lookup, step 4: table row, allocation[] value -> quant table index
static const char quant_lut_step4[6][16] = {
{ 0, 1, 2, 17 },
{ 0, 1, 2, 3, 4, 5, 6, 17 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17 },
{ 0, 1, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 },
{ 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
};
// quantizer specification structure
struct quantizer_spec {
unsigned short nlevels;
unsigned char grouping;
unsigned char cw_bits;
};
// quantizer table
static const struct quantizer_spec quantizer_table[17] = {
{ 3, 1, 5 }, // 1
{ 5, 1, 7 }, // 2
{ 7, 0, 3 }, // 3
{ 9, 1, 10 }, // 4
{ 15, 0, 4 }, // 5
{ 31, 0, 5 }, // 6
{ 63, 0, 6 }, // 7
{ 127, 0, 7 }, // 8
{ 255, 0, 8 }, // 9
{ 511, 0, 9 }, // 10
{ 1023, 0, 10 }, // 11
{ 2047, 0, 11 }, // 12
{ 4095, 0, 12 }, // 13
{ 8191, 0, 13 }, // 14
{ 16383, 0, 14 }, // 15
{ 32767, 0, 15 }, // 16
{ 65535, 0, 16 } // 17
};
////////////////////////////////////////////////////////////////////////////////
// STATIC VARIABLES AND FUNCTIONS //
////////////////////////////////////////////////////////////////////////////////
#define KJMP2_MAGIC 0x32706D
static int initialized = 0;
static int bit_window;
static int bits_in_window;
static const unsigned char *frame_pos;
#define show_bits(bit_count) (bit_window >> (24 - (bit_count)))
static int FASTCALL get_bits(int bit_count) {
int result = show_bits(bit_count);
bit_window = (bit_window << bit_count) & 0xFFFFFF;
bits_in_window -= bit_count;
while (bits_in_window < 16) {
bit_window |= (*frame_pos++) << (16 - bits_in_window);
bits_in_window += 8;
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
// INITIALIZATION //
////////////////////////////////////////////////////////////////////////////////
static int N[64][32]; // N[i][j] as 8-bit fixed-point
void kjmp2_init(kjmp2_context_t *mp2) {
int i, j;
// check if global initialization is required
if (!initialized) {
int *nptr = &N[0][0];
// compute N[i][j]
for (i = 0; i < 64; ++i)
for (j = 0; j < 32; ++j)
*nptr++ = (int) (256.0 * cos(((16 + i) * ((j << 1) + 1)) * 0.0490873852123405));
initialized = 1;
}
// perform local initialization: clean the context and put the magic in it
for (i = 0; i < 2; ++i)
for (j = 1023; j >= 0; --j)
mp2->V[i][j] = 0;
mp2->Voffs = 0;
mp2->id = KJMP2_MAGIC;
}
int kjmp2_get_sample_rate(const unsigned char *frame) {
if (!frame)
return 0;
if (( frame[0] != 0xFF) // no valid syncword?
|| ((frame[1] & 0xF6) != 0xF4) // no MPEG-1/2 Audio Layer II?
|| ((frame[2] - 0x10) >= 0xE0)) // invalid bitrate?
return 0;
return sample_rates[(((frame[1] & 0x08) >> 1) ^ 4) // MPEG-1/2 switch
+ ((frame[2] >> 2) & 3)]; // actual rate
}
////////////////////////////////////////////////////////////////////////////////
// DECODE HELPER FUNCTIONS //
////////////////////////////////////////////////////////////////////////////////
static const struct quantizer_spec* FASTCALL read_allocation(int sb, int b2_table) {
int table_idx = quant_lut_step3[b2_table][sb];
table_idx = quant_lut_step4[table_idx & 15][get_bits(table_idx >> 4)];
return table_idx ? (&quantizer_table[table_idx - 1]) : 0;
}
static void FASTCALL read_samples(const struct quantizer_spec *q, int scalefactor, int *sample) {
int idx, adj, scale;
int val;
if (!q) {
// no bits allocated for this subband
sample[0] = sample[1] = sample[2] = 0;
return;
}
// resolve scalefactor
if (scalefactor == 63) {
scalefactor = 0;
} else {
adj = scalefactor / 3;
scalefactor = (scf_base[scalefactor % 3] + ((1 << adj) >> 1)) >> adj;
}
// decode samples
adj = q->nlevels;
if (q->grouping) {
// decode grouped samples
val = get_bits(q->cw_bits);
sample[0] = val % adj;
val /= adj;
sample[1] = val % adj;
sample[2] = val / adj;
} else {
// decode direct samples
for(idx = 0; idx < 3; ++idx)
sample[idx] = get_bits(q->cw_bits);
}
// postmultiply samples
scale = 65536 / (adj + 1);
adj = ((adj + 1) >> 1) - 1;
for (idx = 0; idx < 3; ++idx) {
// step 1: renormalization to [-1..1]
val = (adj - sample[idx]) * scale;
// step 2: apply scalefactor
sample[idx] = ( val * (scalefactor >> 12) // upper part
+ ((val * (scalefactor & 4095) + 2048) >> 12)) // lower part
>> 12; // scale adjust
}
}
////////////////////////////////////////////////////////////////////////////////
// FRAME DECODE FUNCTION //
////////////////////////////////////////////////////////////////////////////////
static const struct quantizer_spec *allocation[2][32];
static int scfsi[2][32];
static int scalefactor[2][32][3];
static int sample[2][32][3];
static int U[512];
unsigned long kjmp2_decode_frame(
kjmp2_context_t *mp2,
const unsigned char *frame,
signed short *pcm
) {
unsigned bit_rate_index_minus1;
unsigned sampling_frequency;
unsigned padding_bit;
unsigned mode;
unsigned long frame_size;
int bound, sblimit;
int sb, ch, gr, part, idx, nch, i, j, sum;
int table_idx;
// general sanity check
if (!initialized || !mp2 || (mp2->id != KJMP2_MAGIC) || !frame)
return 0;
// check for valid header: syncword OK, MPEG-Audio Layer 2
if ((frame[0] != 0xFF) || ((frame[1] & 0xF6) != 0xF4))
return 0;
// set up the bitstream reader
bit_window = frame[2] << 16;
bits_in_window = 8;
frame_pos = &frame[3];
// read the rest of the header
bit_rate_index_minus1 = get_bits(4) - 1;
if (bit_rate_index_minus1 > 13)
return 0; // invalid bit rate or 'free format'
sampling_frequency = get_bits(2);
if (sampling_frequency == 3)
return 0;
if ((frame[1] & 0x08) == 0) { // MPEG-2
sampling_frequency += 4;
bit_rate_index_minus1 += 14;
}
padding_bit = get_bits(1);
get_bits(1); // discard private_bit
mode = get_bits(2);
// parse the mode_extension, set up the stereo bound
if (mode == JOINT_STEREO) {
bound = (get_bits(2) + 1) << 2;
} else {
get_bits(2);
bound = (mode == MONO) ? 0 : 32;
}
// discard the last 4 bits of the header and the CRC value, if present
get_bits(4);
if ((frame[1] & 1) == 0)
get_bits(16);
// compute the frame size
frame_size = (144000 * bitrates[bit_rate_index_minus1]
/ sample_rates[sampling_frequency]) + padding_bit;
if (!pcm)
return frame_size; // no decoding
// prepare the quantizer table lookups
if (sampling_frequency & 4) {
// MPEG-2 (LSR)
table_idx = 2;
sblimit = 30;
} else {
// MPEG-1
table_idx = (mode == MONO) ? 0 : 1;
table_idx = quant_lut_step1[table_idx][bit_rate_index_minus1];
table_idx = quant_lut_step2[table_idx][sampling_frequency];
sblimit = table_idx & 63;
table_idx >>= 6;
}
if (bound > sblimit)
bound = sblimit;
// read the allocation information
for (sb = 0; sb < bound; ++sb)
for (ch = 0; ch < 2; ++ch)
allocation[ch][sb] = read_allocation(sb, table_idx);
for (sb = bound; sb < sblimit; ++sb)
allocation[0][sb] = allocation[1][sb] = read_allocation(sb, table_idx);
// read scale factor selector information
nch = (mode == MONO) ? 1 : 2;
for (sb = 0; sb < sblimit; ++sb) {
for (ch = 0; ch < nch; ++ch)
if (allocation[ch][sb])
scfsi[ch][sb] = get_bits(2);
if (mode == MONO)
scfsi[1][sb] = scfsi[0][sb];
}
// read scale factors
for (sb = 0; sb < sblimit; ++sb) {
for (ch = 0; ch < nch; ++ch)
if (allocation[ch][sb]) {
switch (scfsi[ch][sb]) {
case 0: scalefactor[ch][sb][0] = get_bits(6);
scalefactor[ch][sb][1] = get_bits(6);
scalefactor[ch][sb][2] = get_bits(6);
break;
case 1: scalefactor[ch][sb][0] =
scalefactor[ch][sb][1] = get_bits(6);
scalefactor[ch][sb][2] = get_bits(6);
break;
case 2: scalefactor[ch][sb][0] =
scalefactor[ch][sb][1] =
scalefactor[ch][sb][2] = get_bits(6);
break;
case 3: scalefactor[ch][sb][0] = get_bits(6);
scalefactor[ch][sb][1] =
scalefactor[ch][sb][2] = get_bits(6);
break;
}
}
if (mode == MONO)
for (part = 0; part < 3; ++part)
scalefactor[1][sb][part] = scalefactor[0][sb][part];
}
// coefficient input and reconstruction
for (part = 0; part < 3; ++part)
for (gr = 0; gr < 4; ++gr) {
// read the samples
for (sb = 0; sb < bound; ++sb)
for (ch = 0; ch < 2; ++ch)
read_samples(allocation[ch][sb], scalefactor[ch][sb][part], &sample[ch][sb][0]);
for (sb = bound; sb < sblimit; ++sb) {
read_samples(allocation[0][sb], scalefactor[0][sb][part], &sample[0][sb][0]);
for (idx = 0; idx < 3; ++idx)
sample[1][sb][idx] = sample[0][sb][idx];
}
for (ch = 0; ch < 2; ++ch)
for (sb = sblimit; sb < 32; ++sb)
for (idx = 0; idx < 3; ++idx)
sample[ch][sb][idx] = 0;
// synthesis loop
for (idx = 0; idx < 3; ++idx) {
// shifting step
mp2->Voffs = table_idx = (mp2->Voffs - 64) & 1023;
for (ch = 0; ch < 2; ++ch) {
// matrixing
for (i = 0; i < 64; ++i) {
sum = 0;
for (j = 0; j < 32; ++j)
sum += N[i][j] * sample[ch][j][idx]; // 8b*15b=23b
// intermediate value is 28 bit (23 + 5), clamp to 14b
mp2->V[ch][table_idx + i] = (sum + 8192) >> 14;
}
// construction of U
for (i = 0; i < 8; ++i)
for (j = 0; j < 32; ++j) {
U[(i << 6) + j] = mp2->V[ch][(table_idx + (i << 7) + j ) & 1023];
U[(i << 6) + j + 32] = mp2->V[ch][(table_idx + (i << 7) + j + 96) & 1023];
}
// apply window
for (i = 0; i < 512; ++i)
U[i] = (U[i] * D[i] + 32) >> 6;
// output samples
for (j = 0; j < 32; ++j) {
sum = 0;
for (i = 0; i < 16; ++i)
sum -= U[(i << 5) + j];
sum = (sum + 8) >> 4;
if (sum < -32768) sum = -32768;
if (sum > 32767) sum = 32767;
pcm[(idx << 6) | (j << 1) | ch] = (signed short) sum;
}
} // end of synthesis channel loop
} // end of synthesis sub-block loop
// adjust PCM output pointer: decoded 3 * 32 = 96 stereo samples
pcm += 192;
} // decoding of the granule finished
return frame_size;
}
| 22,382 | C | .c | 463 | 40.688985 | 102 | 0.513977 | libretro/libretro-uae | 112 | 60 | 28 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | false | false | false | true | true | true | false | false |
1,307,951 | driver.c | mongodb_mongo-bi-connector-odbc-driver/driver/driver.c | /*
Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/ODBC is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
MySQL Connectors. There are special exceptions to the terms and
conditions of the GPLv2 as it is applied to this software, see the
FLOSS License Exception
<http://www.mysql.com/about/legal/licensing/foss-exception.html>.
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; version 2 of the License.
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.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
@file driver.c
@brief Stub for forcing creation of precompiled headers.
*/
#include "driver.h"
| 1,214 | C | .c | 24 | 47.5 | 78 | 0.777589 | mongodb/mongo-bi-connector-odbc-driver | 109 | 40 | 3 | GPL-2.0 | 9/7/2024, 9:44:01 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
1,396,634 | screenfade.h | headcrab-junkyard_OGS/goldsrc/common/screenfade.h | /*
* This file is part of OGS Engine
* Copyright (C) 2018 BlackPhrase
*
* OGS Engine 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 3 of the License, or
* (at your option) any later version.
*
* OGS Engine 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 OGS Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/// @file
#pragma once | 740 | C | .c | 19 | 37.105263 | 71 | 0.755556 | headcrab-junkyard/OGS | 98 | 13 | 0 | GPL-3.0 | 9/7/2024, 9:44:18 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
1,396,684 | DedicatedExports.h | headcrab-junkyard_OGS/goldsrc/dedicated/DedicatedExports.h | /*
* This file is part of OGS Engine
* Copyright (C) 2018 BlackPhrase
*
* OGS Engine 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 3 of the License, or
* (at your option) any later version.
*
* OGS Engine 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 OGS Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/// @file
#pragma once
#include "IDedicatedExports.h"
class CDedicatedExports final : public IDedicatedExports
{
public:
CDedicatedExports();
~CDedicatedExports();
void Sys_Printf(const char *text) override;
}; | 936 | C | .c | 27 | 32.777778 | 71 | 0.766593 | headcrab-junkyard/OGS | 98 | 13 | 0 | GPL-3.0 | 9/7/2024, 9:44:18 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,396,743 | demo_api.c | headcrab-junkyard_OGS/goldsrc/engine/demo_api.c | /*
* This file is part of OGS Engine
* Copyright (C) 2018 BlackPhrase
*
* OGS Engine 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 3 of the License, or
* (at your option) any later version.
*
* OGS Engine 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 OGS Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/// @file
/// @brief demo api implementation
#include "quakedef.h"
#include "demo_api.h"
int DemoAPI_IsRecording()
{
return cls.demorecording;
};
int DemoAPI_IsPlayingback()
{
return cls.demoplayback;
};
int DemoAPI_IsTimeDemo()
{
return cls.timedemo;
};
void DemoAPI_WriteBuffer(int size, byte *buffer){
// TODO
};
demo_api_t demoapi =
{
DemoAPI_IsRecording,
DemoAPI_IsPlayingback,
DemoAPI_IsTimeDemo,
DemoAPI_WriteBuffer
}; | 1,161 | C | .c | 43 | 25.209302 | 71 | 0.760791 | headcrab-junkyard/OGS | 98 | 13 | 0 | GPL-3.0 | 9/7/2024, 9:44:18 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,396,832 | in_sdl2.c | headcrab-junkyard_OGS/goldsrc/engine/sdl2/in_sdl2.c | /*
* This file is part of OGS Engine
* Copyright (C) 1996-1997 Id Software, Inc.
* Copyright (C) 2018 BlackPhrase
*
* OGS Engine 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 3 of the License, or
* (at your option) any later version.
*
* OGS Engine 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 OGS Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/// @file
/// @brief for systems without a mouse
#include "quakedef.h"
void IN_Init()
{
}
void IN_Shutdown()
{
}
void IN_Commands()
{
}
void IN_Move(usercmd_t *cmd)
{
}
// TODO: IN_ClearStates?
// TODO: unused?
/*
===========
IN_ModeChanged
===========
*/
/*
void IN_ModeChanged()
{
}
*/ | 1,057 | C | .c | 45 | 21.955556 | 71 | 0.721393 | headcrab-junkyard/OGS | 98 | 13 | 0 | GPL-3.0 | 9/7/2024, 9:44:18 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,397,134 | mgldos.h | headcrab-junkyard_OGS/legacy/scitech/include/mgldos.h | /****************************************************************************
*
* MegaGraph Graphics Library
*
* Copyright (C) 1996 SciTech Software.
* All rights reserved.
*
* Filename: $Workfile: mgldos.h $
* Version: $Revision: 1.9 $
*
* Language: ANSI C
* Environment: IBM PC (MS DOS)
*
* Description: Header file for the MGLDOS binding for the MSDOS environment.
*
* $Date: 30 Jan 1997 17:31:58 $ $Author: KendallB $
*
****************************************************************************/
#ifndef __MGLDOS_H
#define __MGLDOS_H
#ifndef MGLDOS
#define MGLDOS
#endif
/*---------------------- Macros and type definitions ----------------------*/
typedef void *MGL_HWND;
/*------------------------- Function Prototypes ---------------------------*/
#ifdef __cplusplus
extern "C" { /* Use "C" linkage when in C++ mode */
#endif
/* Initialise the MGL for fullscreen output */
bool MGLAPI MGL_init(m_int *driver,m_int *mode,const char *mglpath);
/* Change the active display mode. You must destroy all display device
* contexts before calling this function, and re-create them again with
* the new display mode. Does not affect any event handling hooks.
*/
bool MGLAPI MGL_changeDisplayMode(m_int mode);
/* Disable/enable event handling (call before calling MGL_init */
void MGLAPI MGL_useEvents(bool use);
/* Device context management */
MGLDC * MGLAPI MGL_createDisplayDC(m_int numBuffers);
MGLDC * MGLAPI MGL_createScrollingDC(m_int virtualX,m_int virtualY,m_int numBuffers);
MGLDC * MGLAPI MGL_createOffscreenDC(void);
MGLDC * MGLAPI MGL_createLinearOffscreenDC(void);
MGLDC * MGLAPI MGL_createMemoryDC(m_int xSize,m_int ySize,m_int bitsPerPixel,pixel_format_t *pf);
bool MGLAPI MGL_destroyDC(MGLDC *dc);
/* Generic helper functions */
ulong MGLAPI MGL_getTicks(void);
ulong MGLAPI MGL_getTickResolution(void);
void MGLAPI MGL_delay(m_int millseconds);
void MGLAPI MGL_beep(m_int freq,m_int milliseconds);
void MGLAPI MGL_suspend(void);
void MGLAPI MGL_resume(void);
/* Fullscreen specific routines */
void MGLAPI MGL_setPaletteSnowLevel(MGLDC *dc,m_int level);
m_int MGLAPI MGL_getPaletteSnowLevel(MGLDC *dc);
/* Determine if a specific scancode'ed key is held down (PC specific) */
bool MGLAPI EVT_isKeyDown(uchar scanCode);
#ifdef __cplusplus
} /* End of "C" linkage for C++ */
#endif
#endif /* __MGLDOS_H */
| 2,399 | C | .h | 61 | 37.918033 | 98 | 0.664076 | headcrab-junkyard/OGS | 98 | 13 | 0 | GPL-3.0 | 9/7/2024, 9:44:18 AM (Europe/Amsterdam) | false | false | true | true | false | false | true | false |
1,397,136 | dplay.h | headcrab-junkyard_OGS/legacy/dxsdk/sdk/inc/dplay.h | /*==========================================================================;
*
* Copyright (C) 1994-1995 Microsoft Corporation. All Rights Reserved.
*
* File: dplay.h
* Content: DirectPlay include file
*
***************************************************************************/
#ifndef __DPLAY_INCLUDED__
#define __DPLAY_INCLUDED__
#ifdef _WIN32
/* for DECLARE_INTERFACE and HRESULT. */
#include <ole2.h>
#endif
#define _FACDP 0x877
#define MAKE_DPHRESULT( code ) MAKE_HRESULT( 1, _FACDP, code )
#ifdef __cplusplus
extern "C" {
#endif
#pragma pack(push, 1)
/*============================================================================
*
* DirectPlay Structures
*
* Various structures used to invoke DirectPlay.
*
*==========================================================================*/
#ifdef __cplusplus
/* 'struct' not 'class' per the way DECLARE_INTERFACE_ is defined */
struct IDirectPlay;
typedef struct IDirectPlay FAR *LPDIRECTPLAY;
#else
typedef struct IDirectPlay FAR *LPDIRECTPLAY;
#endif
typedef DWORD DPID, FAR *LPDPID;
typedef struct _DPCAPS
{
DWORD dwSize;
DWORD dwFlags;
DWORD dwMaxBufferSize;
DWORD dwMaxQueueSize; // Function of DPlay, not SP.
DWORD dwMaxPlayers;
DWORD dwHundredBaud; // 24 is 2400, 96 is 9600, etc.
DWORD dwLatency;
} DPCAPS;
typedef DPCAPS FAR *LPDPCAPS;
#define DPLONGNAMELEN 52
#define DPSHORTNAMELEN 20
#define DPSESSIONNAMELEN 32
#define DPPASSWORDLEN 16
#define DPUSERRESERVED 16
typedef struct
{
DWORD dwSize;
GUID guidSession; // Id for Game. Null is all games.
DWORD dwSession; // session identifier
DWORD dwMaxPlayers; // Maximum players allowed in game.
DWORD dwCurrentPlayers; // Current players in Game.
DWORD dwFlags; // DPOPEN_* flags
char szSessionName[DPSESSIONNAMELEN];// Human readable name for Game
char szUserField[DPUSERRESERVED];
DWORD dwReserved1; // Reserved for future MS use.
char szPassword[DPPASSWORDLEN]; // Password to be allowed into game.
DWORD dwReserved2; // Reserved for future MS use.
DWORD dwUser1;
DWORD dwUser2;
DWORD dwUser3;
DWORD dwUser4;
} DPSESSIONDESC;
typedef DPSESSIONDESC FAR *LPDPSESSIONDESC;
/*
* Create API
*/
typedef BOOL (FAR PASCAL * LPDPENUMDPCALLBACK)(
LPGUID lpSPGuid,
LPSTR lpFriendlyName,
DWORD dwMajorVersion,
DWORD dwMinorVersion,
LPVOID lpContext);
typedef BOOL (FAR PASCAL * LPDPENUMSESSIONSCALLBACK)(
LPDPSESSIONDESC lpDPSGameDesc,
LPVOID lpContext,
LPDWORD lpdwTimeOut,
DWORD dwFlags);
extern HRESULT WINAPI DirectPlayCreate( LPGUID lpGUID, LPDIRECTPLAY FAR *lplpDP, IUnknown FAR *pUnk);
extern HRESULT WINAPI DirectPlayEnumerate( LPDPENUMDPCALLBACK, LPVOID );
/* Player enumeration callback prototype */
typedef BOOL (FAR PASCAL *LPDPENUMPLAYERSCALLBACK)(
DPID dpId,
LPSTR lpFriendlyName,
LPSTR lpFormalName,
DWORD dwFlags,
LPVOID lpContext );
/*
* IDirectPlay
*/
#undef INTERFACE
#define INTERFACE IDirectPlay
#ifdef _WIN32
DECLARE_INTERFACE_( IDirectPlay, IUnknown )
{
/*** IUnknown methods ***/
STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID * ppvObj) PURE;
STDMETHOD_(ULONG,AddRef) (THIS) PURE;
STDMETHOD_(ULONG,Release) (THIS) PURE;
/*** IDirectPlay methods ***/
STDMETHOD(AddPlayerToGroup) (THIS_ DPID, DPID) PURE;
STDMETHOD(Close) (THIS) PURE;
STDMETHOD(CreatePlayer) (THIS_ LPDPID,LPSTR,LPSTR,LPHANDLE) PURE;
STDMETHOD(CreateGroup) (THIS_ LPDPID,LPSTR,LPSTR) PURE;
STDMETHOD(DeletePlayerFromGroup)(THIS_ DPID,DPID) PURE;
STDMETHOD(DestroyPlayer) (THIS_ DPID) PURE;
STDMETHOD(DestroyGroup) (THIS_ DPID) PURE;
STDMETHOD(EnableNewPlayers) (THIS_ BOOL) PURE;
STDMETHOD(EnumGroupPlayers) (THIS_ DPID, LPDPENUMPLAYERSCALLBACK,LPVOID,DWORD) PURE;
STDMETHOD(EnumGroups) (THIS_ DWORD, LPDPENUMPLAYERSCALLBACK,LPVOID,DWORD) PURE;
STDMETHOD(EnumPlayers) (THIS_ DWORD, LPDPENUMPLAYERSCALLBACK,LPVOID,DWORD) PURE;
STDMETHOD(EnumSessions) (THIS_ LPDPSESSIONDESC,DWORD,LPDPENUMSESSIONSCALLBACK,LPVOID,DWORD) PURE;
STDMETHOD(GetCaps) (THIS_ LPDPCAPS) PURE;
STDMETHOD(GetMessageCount) (THIS_ DPID, LPDWORD) PURE;
STDMETHOD(GetPlayerCaps) (THIS_ DPID, LPDPCAPS) PURE;
STDMETHOD(GetPlayerName) (THIS_ DPID,LPSTR,LPDWORD,LPSTR,LPDWORD) PURE;
STDMETHOD(Initialize) (THIS_ LPGUID) PURE;
STDMETHOD(Open) (THIS_ LPDPSESSIONDESC) PURE;
STDMETHOD(Receive) (THIS_ LPDPID,LPDPID,DWORD,LPVOID,LPDWORD) PURE;
STDMETHOD(SaveSession) (THIS_ LPSTR) PURE;
STDMETHOD(Send) (THIS_ DPID, DPID, DWORD, LPVOID, DWORD) PURE;
STDMETHOD(SetPlayerName) (THIS_ DPID,LPSTR,LPSTR) PURE;
};
#endif
/****************************************************************************
*
* DIRECTPLAY ERRORS
*
* Errors are represented by negative values and cannot be combined.
*
****************************************************************************/
#define DP_OK 0
#define DPERR_ALREADYINITIALIZED MAKE_DPHRESULT( 5 )
#define DPERR_ACCESSDENIED MAKE_DPHRESULT( 10 )
#define DPERR_ACTIVEPLAYERS MAKE_DPHRESULT( 20 )
#define DPERR_BUFFERTOOSMALL MAKE_DPHRESULT( 30 )
#define DPERR_CANTADDPLAYER MAKE_DPHRESULT( 40 )
#define DPERR_CANTCREATEGROUP MAKE_DPHRESULT( 50 )
#define DPERR_CANTCREATEPLAYER MAKE_DPHRESULT( 60 )
#define DPERR_CANTCREATESESSION MAKE_DPHRESULT( 70 )
#define DPERR_CAPSNOTAVAILABLEYET MAKE_DPHRESULT( 80 )
#define DPERR_EXCEPTION MAKE_DPHRESULT( 90 )
#define DPERR_GENERIC E_FAIL
#define DPERR_INVALIDFLAGS MAKE_DPHRESULT( 120 )
#define DPERR_INVALIDOBJECT MAKE_DPHRESULT( 130 )
#define DPERR_INVALIDPARAM E_INVALIDARG
#define DPERR_INVALIDPARAMS DPERR_INVALIDPARAM
#define DPERR_INVALIDPLAYER MAKE_DPHRESULT( 150 )
#define DPERR_NOCAPS MAKE_DPHRESULT( 160 )
#define DPERR_NOCONNECTION MAKE_DPHRESULT( 170 )
#define DPERR_NOMEMORY E_OUTOFMEMORY
#define DPERR_OUTOFMEMORY DPERR_NOMEMORY
#define DPERR_NOMESSAGES MAKE_DPHRESULT( 190 )
#define DPERR_NONAMESERVERFOUND MAKE_DPHRESULT( 200 )
#define DPERR_NOPLAYERS MAKE_DPHRESULT( 210 )
#define DPERR_NOSESSIONS MAKE_DPHRESULT( 220 )
#define DPERR_SENDTOOBIG MAKE_DPHRESULT( 230 )
#define DPERR_TIMEOUT MAKE_DPHRESULT( 240 )
#define DPERR_UNAVAILABLE MAKE_DPHRESULT( 250 )
#define DPERR_UNSUPPORTED E_NOTIMPL
#define DPERR_BUSY MAKE_DPHRESULT( 270 )
#define DPERR_USERCANCEL MAKE_DPHRESULT( 280 )
#define DPOPEN_OPENSESSION 0x00000001
#define DPOPEN_CREATESESSION 0x00000002
#define DPSEND_GUARANTEE 0x00000001
#define DPSEND_HIGHPRIORITY 0x00000002
#define DPSEND_TRYONCE 0x00000004
#define DPRECEIVE_ALL 0x00000001
#define DPRECEIVE_TOPLAYER 0x00000002
#define DPRECEIVE_FROMPLAYER 0x00000004
#define DPRECEIVE_PEEK 0x00000008
#define DPCAPS_NAMESERVICE 0x00000001 // A name server is supported.
#define DPCAPS_NAMESERVER 0x00000002 // You are the name server.
#define DPCAPS_GUARANTEED 0x00000004 // SP's don't have to implement guarantees.
#define DPENUMSESSIONS_AVAILABLE 0x00000001 // All games that match password (if given)
// and have openings.
#define DPENUMSESSIONS_ALL 0x00000002
#define DPENUMSESSIONS_PREVIOUS 0x00000004
#define DPENUMPLAYERS_ALL 0x00000000
#define DPENUMPLAYERS_PREVIOUS 0x00000004
#define DPENUMPLAYERS_LOCAL 0x00000008
#define DPENUMPLAYERS_REMOTE 0x00000010
#define DPENUMPLAYERS_GROUP 0x00000020
#define DPENUMPLAYERS_SESSION 0x00000080
//
// This flag is set on the enumsessions callback when the time out has occured.
// This means that there is no session data for this callback.
// If lpdwTimeOut is set to a non-zero value and the EnumSessionsCallback returns
// TRUE then EnumSessions will continue until the next timeout occurs.
// Timeouts are in milliseconds.
#define DPESC_TIMEDOUT 0x00000001
//
// System message structures and types.
//
// System messages have a leading 4 byte type code to identify the message.
// an app knows it is a system message because it is addressed 'To' player 0.
//
#define DPSYS_ADDPLAYER 0x0003 // DPMSG_ADDPLAYER
#define DPSYS_DELETEPLAYER 0x0005 // DPMSG_DELETEPLAYER
#define DPSYS_ADDPLAYERTOGROUP 0x0007 // DPMSG_GROUPADD
#define DPSYS_INVITE 0x000e // DPMSG_INVITE, Net only.
#define DPSYS_DELETEGROUP 0x0020 // DPMSG_DELETEPLAYER
#define DPSYS_DELETEPLAYERFROMGRP 0x0021 // DPMSG_GROUPDELETE
#define DPSYS_SESSIONLOST 0x0031
#define DPSYS_CONNECT 0x484b // DPMSG_GENERIC
typedef struct
{
DWORD dwType;
DWORD dwPlayerType;
DPID dpId;
char szLongName[DPLONGNAMELEN];
char szShortName[DPSHORTNAMELEN];
DWORD dwCurrentPlayers;
} DPMSG_ADDPLAYER;
typedef DPMSG_ADDPLAYER DPMSG_ADDGROUP;
typedef struct
{
DWORD dwType;
DPID dpIdGroup;
DPID dpIdPlayer;
} DPMSG_GROUPADD;
typedef DPMSG_GROUPADD DPMSG_GROUPDELETE;
typedef struct
{
DWORD dwType;
DPID dpId;
} DPMSG_DELETEPLAYER;
typedef struct
{
DWORD dwType;
DPSESSIONDESC dpsDesc;
} DPMSG_INVITE;
typedef struct
{
DWORD dwType;
} DPMSG_GENERIC;
#pragma pack(pop)
DEFINE_GUID( IID_IDirectPlay, 0x5454e9a0, 0xdb65, 0x11ce, 0x92, 0x1c, 0x00, 0xaa, 0x00, 0x6c, 0x49, 0x72);
#ifdef __cplusplus
};
#endif
#endif
| 10,605 | C | .h | 248 | 39.766129 | 109 | 0.632554 | headcrab-junkyard/OGS | 98 | 13 | 0 | GPL-3.0 | 9/7/2024, 9:44:18 AM (Europe/Amsterdam) | true | false | true | true | true | true | true | false |
1,397,139 | d3drmobj.h | headcrab-junkyard_OGS/legacy/dxsdk/sdk/inc/d3drmobj.h | /*==========================================================================;
*
* Copyright (C) 1995-1996 Microsoft Corporation. All Rights Reserved.
*
* File: d3drm.h
* Content: Direct3DRM include file
*
***************************************************************************/
#ifndef _D3DRMOBJ_H_
#define _D3DRMOBJ_H_
#include <objbase.h> /* Use Windows header files */
#define VIRTUAL
#include "d3drmdef.h"
#include "d3d.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* The methods for IUnknown
*/
#define IUNKNOWN_METHODS(kind) \
STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID *ppvObj) kind; \
STDMETHOD_(ULONG, AddRef) (THIS) kind; \
STDMETHOD_(ULONG, Release) (THIS) kind
/*
* The methods for IDirect3DRMObject
*/
#define IDIRECT3DRMOBJECT_METHODS(kind) \
STDMETHOD(Clone) (THIS_ LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObj) kind; \
STDMETHOD(AddDestroyCallback) (THIS_ D3DRMOBJECTCALLBACK, LPVOID argument) kind; \
STDMETHOD(DeleteDestroyCallback) (THIS_ D3DRMOBJECTCALLBACK, LPVOID argument) kind; \
STDMETHOD(SetAppData) (THIS_ DWORD data) kind; \
STDMETHOD_(DWORD, GetAppData) (THIS) kind; \
STDMETHOD(SetName) (THIS_ LPCSTR) kind; \
STDMETHOD(GetName) (THIS_ LPDWORD lpdwSize, LPSTR lpName) kind; \
STDMETHOD(GetClassName) (THIS_ LPDWORD lpdwSize, LPSTR lpName) kind
#define WIN_TYPES(itype, ptype) \
typedef interface itype FAR *LP##ptype, FAR **LPLP##ptype
WIN_TYPES(IDirect3DRMObject, DIRECT3DRMOBJECT);
WIN_TYPES(IDirect3DRMDevice, DIRECT3DRMDEVICE);
WIN_TYPES(IDirect3DRMViewport, DIRECT3DRMVIEWPORT);
WIN_TYPES(IDirect3DRMFrame, DIRECT3DRMFRAME);
WIN_TYPES(IDirect3DRMVisual, DIRECT3DRMVISUAL);
WIN_TYPES(IDirect3DRMMesh, DIRECT3DRMMESH);
WIN_TYPES(IDirect3DRMMeshBuilder, DIRECT3DRMMESHBUILDER);
WIN_TYPES(IDirect3DRMFace, DIRECT3DRMFACE);
WIN_TYPES(IDirect3DRMLight, DIRECT3DRMLIGHT);
WIN_TYPES(IDirect3DRMTexture, DIRECT3DRMTEXTURE);
WIN_TYPES(IDirect3DRMWrap, DIRECT3DRMWRAP);
WIN_TYPES(IDirect3DRMMaterial, DIRECT3DRMMATERIAL);
WIN_TYPES(IDirect3DRMAnimation, DIRECT3DRMANIMATION);
WIN_TYPES(IDirect3DRMAnimationSet, DIRECT3DRMANIMATIONSET);
WIN_TYPES(IDirect3DRMUserVisual, DIRECT3DRMUSERVISUAL);
WIN_TYPES(IDirect3DRMShadow, DIRECT3DRMSHADOW);
WIN_TYPES(IDirect3DRMArray, DIRECT3DRMOBJECTARRAY);
WIN_TYPES(IDirect3DRMDeviceArray, DIRECT3DRMDEVICEARRAY);
WIN_TYPES(IDirect3DRMFaceArray, DIRECT3DRMFACEARRAY);
WIN_TYPES(IDirect3DRMViewportArray, DIRECT3DRMVIEWPORTARRAY);
WIN_TYPES(IDirect3DRMFrameArray, DIRECT3DRMFRAMEARRAY);
WIN_TYPES(IDirect3DRMVisualArray, DIRECT3DRMVISUALARRAY);
WIN_TYPES(IDirect3DRMPickedArray, DIRECT3DRMPICKEDARRAY);
WIN_TYPES(IDirect3DRMLightArray, DIRECT3DRMLIGHTARRAY);
/*
* Direct3DRM Object classes
*/
DEFINE_GUID(CLSID_CDirect3DRMDevice, 0x4fa3568e, 0x623f, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(CLSID_CDirect3DRMViewport, 0x4fa3568f, 0x623f, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(CLSID_CDirect3DRMFrame, 0x4fa35690, 0x623f, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(CLSID_CDirect3DRMMesh, 0x4fa35691, 0x623f, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(CLSID_CDirect3DRMMeshBuilder, 0x4fa35692, 0x623f, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(CLSID_CDirect3DRMFace, 0x4fa35693, 0x623f, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(CLSID_CDirect3DRMLight, 0x4fa35694, 0x623f, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(CLSID_CDirect3DRMTexture, 0x4fa35695, 0x623f, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(CLSID_CDirect3DRMWrap, 0x4fa35696, 0x623f, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(CLSID_CDirect3DRMMaterial, 0x4fa35697, 0x623f, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(CLSID_CDirect3DRMAnimation, 0x4fa35698, 0x623f, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(CLSID_CDirect3DRMAnimationSet, 0x4fa35699, 0x623f, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(CLSID_CDirect3DRMUserVisual, 0x4fa3569a, 0x623f, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(CLSID_CDirect3DRMShadow, 0x4fa3569b, 0x623f, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
/*
* Direct3DRM Object interfaces
*/
DEFINE_GUID(IID_IDirect3DRMObject, 0xeb16cb00, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMDevice, 0xe9e19280, 0x6e05, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMViewport, 0xeb16cb02, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMFrame, 0xeb16cb03, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMVisual, 0xeb16cb04, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMMesh, 0xa3a80d01, 0x6e12, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMMeshBuilder, 0xa3a80d02, 0x6e12, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMFace, 0xeb16cb07, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMLight, 0xeb16cb08, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMTexture, 0xeb16cb09, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMWrap, 0xeb16cb0a, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMMaterial, 0xeb16cb0b, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMAnimation, 0xeb16cb0d, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMAnimationSet, 0xeb16cb0e, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMDeviceArray, 0xeb16cb10, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMViewportArray, 0xeb16cb11, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMFrameArray, 0xeb16cb12, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMVisualArray, 0xeb16cb13, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMLightArray, 0xeb16cb14, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMPickedArray, 0xeb16cb16, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMFaceArray, 0xeb16cb17, 0xd271, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMUserVisual, 0x59163de0, 0x6d43, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
DEFINE_GUID(IID_IDirect3DRMShadow, 0xaf359780, 0x6ba3, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
typedef void (*D3DRMOBJECTCALLBACK)(LPDIRECT3DRMOBJECT obj, LPVOID arg);
typedef void (*D3DRMFRAMEMOVECALLBACK)(LPDIRECT3DRMFRAME obj, LPVOID arg, D3DVALUE delta);
typedef void (*D3DRMUPDATECALLBACK)(LPDIRECT3DRMDEVICE obj, LPVOID arg, int, LPD3DRECT);
typedef int (*D3DRMUSERVISUALCALLBACK)(LPDIRECT3DRMUSERVISUAL obj, LPVOID arg,
D3DRMUSERVISUALREASON reason,
LPDIRECT3DRMDEVICE dev,
LPDIRECT3DRMVIEWPORT view);
typedef HRESULT (*D3DRMLOADTEXTURECALLBACK)
(char *tex_name, void *arg, LPDIRECT3DRMTEXTURE *);
typedef void (*D3DRMLOADCALLBACK)
(LPDIRECT3DRMOBJECT object, REFIID objectguid, LPVOID arg);
typedef struct _D3DRMPICKDESC
{
ULONG ulFaceIdx;
LONG lGroupIdx;
D3DVECTOR vPosition;
} D3DRMPICKDESC, *LPD3DRMPICKDESC;
#undef INTERFACE
#define INTERFACE IDirect3DRMObject
/*
* Base class
*/
DECLARE_INTERFACE_(IDirect3DRMObject, IUnknown)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
};
#undef INTERFACE
#define INTERFACE IDirect3DRMVisual
DECLARE_INTERFACE_(IDirect3DRMVisual, IDirect3DRMObject)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
};
#undef INTERFACE
#define INTERFACE IDirect3DRMDevice
DECLARE_INTERFACE_(IDirect3DRMDevice, IDirect3DRMObject)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
/*
* IDirect3DRMDevice methods
*/
STDMETHOD(Init)(THIS_ ULONG width, ULONG height) PURE;
STDMETHOD(InitFromD3D)(THIS_ LPDIRECT3D lpD3D, LPDIRECT3DDEVICE lpD3DDev) PURE;
STDMETHOD(InitFromClipper)(THIS_ LPDIRECTDRAWCLIPPER lpDDClipper, LPGUID lpGUID, int width, int height) PURE;
STDMETHOD(Update)(THIS) PURE;
STDMETHOD(AddUpdateCallback)(THIS_ D3DRMUPDATECALLBACK, LPVOID arg) PURE;
STDMETHOD(DeleteUpdateCallback)(THIS_ D3DRMUPDATECALLBACK, LPVOID arg) PURE;
STDMETHOD(SetBufferCount)(THIS_ DWORD) PURE;
STDMETHOD_(DWORD, GetBufferCount)(THIS) PURE;
STDMETHOD(SetDither)(THIS_ BOOL) PURE;
STDMETHOD(SetShades)(THIS_ DWORD) PURE;
STDMETHOD(SetQuality)(THIS_ D3DRMRENDERQUALITY) PURE;
STDMETHOD(SetTextureQuality)(THIS_ D3DRMTEXTUREQUALITY) PURE;
STDMETHOD(GetViewports)(THIS_ LPDIRECT3DRMVIEWPORTARRAY *return_views) PURE;
STDMETHOD_(BOOL, GetDither)(THIS) PURE;
STDMETHOD_(DWORD, GetShades)(THIS) PURE;
STDMETHOD_(DWORD, GetHeight)(THIS) PURE;
STDMETHOD_(DWORD, GetWidth)(THIS) PURE;
STDMETHOD_(DWORD, GetTrianglesDrawn)(THIS) PURE;
STDMETHOD_(DWORD, GetWireframeOptions)(THIS) PURE;
STDMETHOD_(D3DRMRENDERQUALITY, GetQuality)(THIS) PURE;
STDMETHOD_(D3DCOLORMODEL, GetColorModel)(THIS) PURE;
STDMETHOD_(D3DRMTEXTUREQUALITY, GetTextureQuality)(THIS) PURE;
STDMETHOD(GetDirect3DDevice)(THIS_ LPDIRECT3DDEVICE *) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMViewport
DECLARE_INTERFACE_(IDirect3DRMViewport, IDirect3DRMObject)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
/*
* IDirect3DRMViewport methods
*/
STDMETHOD(Init)
( THIS_ LPDIRECT3DRMDEVICE dev, LPDIRECT3DRMFRAME camera,
DWORD xpos, DWORD ypos, DWORD width, DWORD height
) PURE;
STDMETHOD(Clear)(THIS) PURE;
STDMETHOD(Render)(THIS_ LPDIRECT3DRMFRAME) PURE;
STDMETHOD(SetFront)(THIS_ D3DVALUE) PURE;
STDMETHOD(SetBack)(THIS_ D3DVALUE) PURE;
STDMETHOD(SetField)(THIS_ D3DVALUE) PURE;
STDMETHOD(SetUniformScaling)(THIS_ BOOL) PURE;
STDMETHOD(SetCamera)(THIS_ LPDIRECT3DRMFRAME) PURE;
STDMETHOD(SetProjection)(THIS_ D3DRMPROJECTIONTYPE) PURE;
STDMETHOD(Transform)(THIS_ D3DRMVECTOR4D *d, D3DVECTOR *s) PURE;
STDMETHOD(InverseTransform)(THIS_ D3DVECTOR *d, D3DRMVECTOR4D *s) PURE;
STDMETHOD(Configure)(THIS_ LONG x, LONG y, DWORD width, DWORD height) PURE;
STDMETHOD(ForceUpdate)(THIS_ DWORD x1, DWORD y1, DWORD x2, DWORD y2) PURE;
STDMETHOD(SetPlane)(THIS_ D3DVALUE left, D3DVALUE right, D3DVALUE bottom, D3DVALUE top) PURE;
STDMETHOD(GetCamera)(THIS_ LPDIRECT3DRMFRAME *) PURE;
STDMETHOD(GetDevice)(THIS_ LPDIRECT3DRMDEVICE *) PURE;
STDMETHOD(GetPlane)(THIS_ D3DVALUE *left, D3DVALUE *right, D3DVALUE *bottom, D3DVALUE *top) PURE;
STDMETHOD(Pick)(THIS_ LONG x, LONG y, LPDIRECT3DRMPICKEDARRAY *return_visuals) PURE;
STDMETHOD_(BOOL, GetUniformScaling)(THIS) PURE;
STDMETHOD_(LONG, GetX)(THIS) PURE;
STDMETHOD_(LONG, GetY)(THIS) PURE;
STDMETHOD_(DWORD, GetWidth)(THIS) PURE;
STDMETHOD_(DWORD, GetHeight)(THIS) PURE;
STDMETHOD_(D3DVALUE, GetField)(THIS) PURE;
STDMETHOD_(D3DVALUE, GetBack)(THIS) PURE;
STDMETHOD_(D3DVALUE, GetFront)(THIS) PURE;
STDMETHOD_(D3DRMPROJECTIONTYPE, GetProjection)(THIS) PURE;
STDMETHOD(GetDirect3DViewport)(THIS_ LPDIRECT3DVIEWPORT *) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMFrame
DECLARE_INTERFACE_(IDirect3DRMFrame, IDirect3DRMVisual)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
/*
* IDirect3DRMFrame methods
*/
STDMETHOD(AddChild)(THIS_ LPDIRECT3DRMFRAME child) PURE;
STDMETHOD(AddLight)(THIS_ LPDIRECT3DRMLIGHT) PURE;
STDMETHOD(AddMoveCallback)(THIS_ D3DRMFRAMEMOVECALLBACK, VOID *arg) PURE;
STDMETHOD(AddTransform)(THIS_ D3DRMCOMBINETYPE, D3DRMMATRIX4D) PURE;
STDMETHOD(AddTranslation)(THIS_ D3DRMCOMBINETYPE, D3DVALUE x, D3DVALUE y, D3DVALUE z) PURE;
STDMETHOD(AddScale)(THIS_ D3DRMCOMBINETYPE, D3DVALUE sx, D3DVALUE sy, D3DVALUE sz) PURE;
STDMETHOD(AddRotation)(THIS_ D3DRMCOMBINETYPE, D3DVALUE x, D3DVALUE y, D3DVALUE z, D3DVALUE theta) PURE;
STDMETHOD(AddVisual)(THIS_ LPDIRECT3DRMVISUAL) PURE;
STDMETHOD(GetChildren)(THIS_ LPDIRECT3DRMFRAMEARRAY *children) PURE;
STDMETHOD_(D3DCOLOR, GetColor)(THIS) PURE;
STDMETHOD(GetLights)(THIS_ LPDIRECT3DRMLIGHTARRAY *lights) PURE;
STDMETHOD_(D3DRMMATERIALMODE, GetMaterialMode)(THIS) PURE;
STDMETHOD(GetParent)(THIS_ LPDIRECT3DRMFRAME *) PURE;
STDMETHOD(GetPosition)(THIS_ LPDIRECT3DRMFRAME reference, LPD3DVECTOR return_position) PURE;
STDMETHOD(GetRotation)(THIS_ LPDIRECT3DRMFRAME reference, LPD3DVECTOR axis, LPD3DVALUE return_theta) PURE;
STDMETHOD(GetScene)(THIS_ LPDIRECT3DRMFRAME *) PURE;
STDMETHOD_(D3DRMSORTMODE, GetSortMode)(THIS) PURE;
STDMETHOD(GetTexture)(THIS_ LPDIRECT3DRMTEXTURE *) PURE;
STDMETHOD(GetTransform)(THIS_ D3DRMMATRIX4D return_matrix) PURE;
STDMETHOD(GetVelocity)(THIS_ LPDIRECT3DRMFRAME reference, LPD3DVECTOR return_velocity, BOOL with_rotation) PURE;
STDMETHOD(GetOrientation)(THIS_ LPDIRECT3DRMFRAME reference, LPD3DVECTOR dir, LPD3DVECTOR up) PURE;
STDMETHOD(GetVisuals)(THIS_ LPDIRECT3DRMVISUALARRAY *visuals) PURE;
STDMETHOD(GetTextureTopology)(THIS_ BOOL *wrap_u, BOOL *wrap_v) PURE;
STDMETHOD(InverseTransform)(THIS_ D3DVECTOR *d, D3DVECTOR *s) PURE;
STDMETHOD(Load)(THIS_ LPVOID filename, LPVOID name, D3DRMLOADOPTIONS loadflags, D3DRMLOADTEXTURECALLBACK, LPVOID lpArg)PURE;
STDMETHOD(LookAt)(THIS_ LPDIRECT3DRMFRAME target, LPDIRECT3DRMFRAME reference, D3DRMFRAMECONSTRAINT) PURE;
STDMETHOD(Move)(THIS_ D3DVALUE delta) PURE;
STDMETHOD(DeleteChild)(THIS_ LPDIRECT3DRMFRAME) PURE;
STDMETHOD(DeleteLight)(THIS_ LPDIRECT3DRMLIGHT) PURE;
STDMETHOD(DeleteMoveCallback)(THIS_ D3DRMFRAMEMOVECALLBACK, VOID *arg) PURE;
STDMETHOD(DeleteVisual)(THIS_ LPDIRECT3DRMVISUAL) PURE;
STDMETHOD_(D3DCOLOR, GetSceneBackground)(THIS) PURE;
STDMETHOD(GetSceneBackgroundDepth)(THIS_ LPDIRECTDRAWSURFACE *) PURE;
STDMETHOD_(D3DCOLOR, GetSceneFogColor)(THIS) PURE;
STDMETHOD_(BOOL, GetSceneFogEnable)(THIS) PURE;
STDMETHOD_(D3DRMFOGMODE, GetSceneFogMode)(THIS) PURE;
STDMETHOD(GetSceneFogParams)(THIS_ D3DVALUE *return_start, D3DVALUE *return_end, D3DVALUE *return_density) PURE;
STDMETHOD(SetSceneBackground)(THIS_ D3DCOLOR) PURE;
STDMETHOD(SetSceneBackgroundRGB)(THIS_ D3DVALUE red, D3DVALUE green, D3DVALUE blue) PURE;
STDMETHOD(SetSceneBackgroundDepth)(THIS_ LPDIRECTDRAWSURFACE) PURE;
STDMETHOD(SetSceneBackgroundImage)(THIS_ LPDIRECT3DRMTEXTURE) PURE;
STDMETHOD(SetSceneFogEnable)(THIS_ BOOL) PURE;
STDMETHOD(SetSceneFogColor)(THIS_ D3DCOLOR) PURE;
STDMETHOD(SetSceneFogMode)(THIS_ D3DRMFOGMODE) PURE;
STDMETHOD(SetSceneFogParams)(THIS_ D3DVALUE start, D3DVALUE end, D3DVALUE density) PURE;
STDMETHOD(SetColor)(THIS_ D3DCOLOR) PURE;
STDMETHOD(SetColorRGB)(THIS_ D3DVALUE red, D3DVALUE green, D3DVALUE blue) PURE;
STDMETHOD_(D3DRMZBUFFERMODE, GetZbufferMode)(THIS) PURE;
STDMETHOD(SetMaterialMode)(THIS_ D3DRMMATERIALMODE) PURE;
STDMETHOD(SetOrientation)
( THIS_ LPDIRECT3DRMFRAME reference,
D3DVALUE dx, D3DVALUE dy, D3DVALUE dz,
D3DVALUE ux, D3DVALUE uy, D3DVALUE uz
) PURE;
STDMETHOD(SetPosition)(THIS_ LPDIRECT3DRMFRAME reference, D3DVALUE x, D3DVALUE y, D3DVALUE z) PURE;
STDMETHOD(SetRotation)(THIS_ LPDIRECT3DRMFRAME reference, D3DVALUE x, D3DVALUE y, D3DVALUE z, D3DVALUE theta) PURE;
STDMETHOD(SetSortMode)(THIS_ D3DRMSORTMODE) PURE;
STDMETHOD(SetTexture)(THIS_ LPDIRECT3DRMTEXTURE) PURE;
STDMETHOD(SetTextureTopology)(THIS_ BOOL wrap_u, BOOL wrap_v) PURE;
STDMETHOD(SetVelocity)(THIS_ LPDIRECT3DRMFRAME reference, D3DVALUE x, D3DVALUE y, D3DVALUE z, BOOL with_rotation) PURE;
STDMETHOD(SetZbufferMode)(THIS_ D3DRMZBUFFERMODE) PURE;
STDMETHOD(Transform)(THIS_ D3DVECTOR *d, D3DVECTOR *s) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMMesh
DECLARE_INTERFACE_(IDirect3DRMMesh, IDirect3DRMVisual)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
/*
* IDirect3DRMMesh methods
*/
STDMETHOD(Scale)(THIS_ D3DVALUE sx, D3DVALUE sy, D3DVALUE sz) PURE;
STDMETHOD(Translate)(THIS_ D3DVALUE tx, D3DVALUE ty, D3DVALUE tz) PURE;
STDMETHOD(GetBox)(THIS_ D3DRMBOX *) PURE;
STDMETHOD(AddGroup)(THIS_ unsigned vCount, unsigned fCount, unsigned vPerFace, unsigned *fData, D3DRMGROUPINDEX *returnId) PURE;
STDMETHOD(SetVertices)(THIS_ D3DRMGROUPINDEX id, unsigned index, unsigned count, D3DRMVERTEX *values) PURE;
STDMETHOD(SetGroupColor)(THIS_ D3DRMGROUPINDEX id, D3DCOLOR value) PURE;
STDMETHOD(SetGroupColorRGB)(THIS_ D3DRMGROUPINDEX id, D3DVALUE red, D3DVALUE green, D3DVALUE blue) PURE;
STDMETHOD(SetGroupMapping)(THIS_ D3DRMGROUPINDEX id, D3DRMMAPPING value) PURE;
STDMETHOD(SetGroupQuality)(THIS_ D3DRMGROUPINDEX id, D3DRMRENDERQUALITY value) PURE;
STDMETHOD(SetGroupMaterial)(THIS_ D3DRMGROUPINDEX id, LPDIRECT3DRMMATERIAL value) PURE;
STDMETHOD(SetGroupTexture)(THIS_ D3DRMGROUPINDEX id, LPDIRECT3DRMTEXTURE value) PURE;
STDMETHOD_(unsigned, GetGroupCount)(THIS) PURE;
STDMETHOD(GetGroup)(THIS_ D3DRMGROUPINDEX id, unsigned *vCount, unsigned *fCount, unsigned *vPerFace, DWORD *fDataSize, unsigned *fData) PURE;
STDMETHOD(GetVertices)(THIS_ D3DRMGROUPINDEX id, DWORD index, DWORD count, D3DRMVERTEX *returnPtr) PURE;
STDMETHOD_(D3DCOLOR, GetGroupColor)(THIS_ D3DRMGROUPINDEX id) PURE;
STDMETHOD_(D3DRMMAPPING, GetGroupMapping)(THIS_ D3DRMGROUPINDEX id) PURE;
STDMETHOD_(D3DRMRENDERQUALITY, GetGroupQuality)(THIS_ D3DRMGROUPINDEX id) PURE;
STDMETHOD(GetGroupMaterial)(THIS_ D3DRMGROUPINDEX id, LPDIRECT3DRMMATERIAL *returnPtr) PURE;
STDMETHOD(GetGroupTexture)(THIS_ D3DRMGROUPINDEX id, LPDIRECT3DRMTEXTURE *returnPtr) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMShadow
DECLARE_INTERFACE_(IDirect3DRMShadow, IDirect3DRMVisual)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
/*
* IDirect3DRMShadow methods
*/
STDMETHOD(Init)
( THIS_ LPDIRECT3DRMVISUAL visual, LPDIRECT3DRMLIGHT light,
D3DVALUE px, D3DVALUE py, D3DVALUE pz,
D3DVALUE nx, D3DVALUE ny, D3DVALUE nz
) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMFace
DECLARE_INTERFACE_(IDirect3DRMFace, IDirect3DRMObject)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
/*
* IDirect3DRMFace methods
*/
STDMETHOD(AddVertex)(THIS_ D3DVALUE x, D3DVALUE y, D3DVALUE z) PURE;
STDMETHOD(AddVertexAndNormalIndexed)(THIS_ DWORD vertex, DWORD normal) PURE;
STDMETHOD(SetColorRGB)(THIS_ D3DVALUE, D3DVALUE, D3DVALUE) PURE;
STDMETHOD(SetColor)(THIS_ D3DCOLOR) PURE;
STDMETHOD(SetTexture)(THIS_ LPDIRECT3DRMTEXTURE) PURE;
STDMETHOD(SetTextureCoordinates)(THIS_ DWORD vertex, D3DVALUE u, D3DVALUE v) PURE;
STDMETHOD(SetMaterial)(THIS_ LPDIRECT3DRMMATERIAL) PURE;
STDMETHOD(SetTextureTopology)(THIS_ BOOL wrap_u, BOOL wrap_v) PURE;
STDMETHOD(GetVertex)(THIS_ DWORD index, D3DVECTOR *vertex, D3DVECTOR *normal) PURE;
STDMETHOD(GetVertices)(THIS_ DWORD *vertex_count, D3DVECTOR *coords, D3DVECTOR *normals);
STDMETHOD(GetTextureCoordinates)(THIS_ DWORD vertex, D3DVALUE *u, D3DVALUE *v) PURE;
STDMETHOD(GetTextureTopology)(THIS_ BOOL *wrap_u, BOOL *wrap_v) PURE;
STDMETHOD(GetNormal)(THIS_ D3DVECTOR *) PURE;
STDMETHOD(GetTexture)(THIS_ LPDIRECT3DRMTEXTURE *) PURE;
STDMETHOD(GetMaterial)(THIS_ LPDIRECT3DRMMATERIAL *) PURE;
STDMETHOD_(int, GetVertexCount)(THIS) PURE;
STDMETHOD_(int, GetVertexIndex)(THIS_ DWORD which) PURE;
STDMETHOD_(int, GetTextureCoordinateIndex)(THIS_ DWORD which) PURE;
STDMETHOD_(D3DCOLOR, GetColor)(THIS) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMMeshBuilder
DECLARE_INTERFACE_(IDirect3DRMMeshBuilder, IDirect3DRMVisual)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
/*
* IDirect3DRMMeshBuilder methods
*/
STDMETHOD(Load)(THIS_ LPVOID filename, LPVOID name, D3DRMLOADOPTIONS loadflags, D3DRMLOADTEXTURECALLBACK, LPVOID lpArg) PURE;
STDMETHOD(Save)(THIS_ const char *filename, D3DRMXOFFORMAT, D3DRMSAVEOPTIONS save) PURE;
STDMETHOD(Scale)(THIS_ D3DVALUE sx, D3DVALUE sy, D3DVALUE sz) PURE;
STDMETHOD(Translate)(THIS_ D3DVALUE tx, D3DVALUE ty, D3DVALUE tz) PURE;
STDMETHOD(SetColorSource)(THIS_ D3DRMCOLORSOURCE) PURE;
STDMETHOD(GetBox)(THIS_ D3DRMBOX *) PURE;
STDMETHOD(GenerateNormals)(THIS) PURE;
STDMETHOD_(D3DRMCOLORSOURCE, GetColorSource)(THIS) PURE;
STDMETHOD(AddMesh)(THIS_ LPDIRECT3DRMMESH) PURE;
STDMETHOD(AddMeshBuilder)(THIS_ LPDIRECT3DRMMESHBUILDER) PURE;
STDMETHOD(AddFrame)(THIS_ LPDIRECT3DRMFRAME) PURE;
STDMETHOD(AddFace)(THIS_ LPDIRECT3DRMFACE) PURE;
STDMETHOD(AddFaces)
( THIS_ DWORD vcount, D3DVECTOR *vertices, DWORD ncount, D3DVECTOR *normals,
DWORD *data, LPDIRECT3DRMFACEARRAY*
) PURE;
STDMETHOD(ReserveSpace)(THIS_ DWORD vertex_Count, DWORD normal_count, DWORD face_count) PURE;
STDMETHOD(SetColorRGB)(THIS_ D3DVALUE red, D3DVALUE green, D3DVALUE blue) PURE;
STDMETHOD(SetColor)(THIS_ D3DCOLOR) PURE;
STDMETHOD(SetTexture)(THIS_ LPDIRECT3DRMTEXTURE) PURE;
STDMETHOD(SetMaterial)(THIS_ LPDIRECT3DRMMATERIAL) PURE;
STDMETHOD(SetTextureTopology)(THIS_ BOOL wrap_u, BOOL wrap_v) PURE;
STDMETHOD(SetQuality)(THIS_ D3DRMRENDERQUALITY) PURE;
STDMETHOD(SetPerspective)(THIS_ BOOL) PURE;
STDMETHOD(SetVertex)(THIS_ DWORD index, D3DVALUE x, D3DVALUE y, D3DVALUE z) PURE;
STDMETHOD(SetNormal)(THIS_ DWORD index, D3DVALUE x, D3DVALUE y, D3DVALUE z) PURE;
STDMETHOD(SetTextureCoordinates)(THIS_ DWORD index, D3DVALUE u, D3DVALUE v) PURE;
STDMETHOD(SetVertexColor)(THIS_ DWORD index, D3DCOLOR) PURE;
STDMETHOD(SetVertexColorRGB)(THIS_ DWORD index, D3DVALUE red, D3DVALUE green, D3DVALUE blue) PURE;
STDMETHOD(GetFaces)(THIS_ LPDIRECT3DRMFACEARRAY*) PURE;
STDMETHOD(GetVertices)
( THIS_ DWORD *vcount, D3DVECTOR *vertices, DWORD *ncount, D3DVECTOR *normals, DWORD *face_data_size, DWORD *face_data
) PURE;
STDMETHOD(GetTextureCoordinates)(THIS_ DWORD index, D3DVALUE *u, D3DVALUE *v) PURE;
STDMETHOD_(int, AddVertex)(THIS_ D3DVALUE x, D3DVALUE y, D3DVALUE z) PURE;
STDMETHOD_(int, AddNormal)(THIS_ D3DVALUE x, D3DVALUE y, D3DVALUE z) PURE;
STDMETHOD(CreateFace)(THIS_ LPDIRECT3DRMFACE*) PURE;
STDMETHOD_(D3DRMRENDERQUALITY, GetQuality)(THIS) PURE;
STDMETHOD_(BOOL, GetPerspective)(THIS) PURE;
STDMETHOD_(int, GetFaceCount)(THIS) PURE;
STDMETHOD_(int, GetVertexCount)(THIS) PURE;
STDMETHOD_(D3DCOLOR, GetVertexColor)(THIS_ DWORD index) PURE;
STDMETHOD(CreateMesh)(THIS_ LPDIRECT3DRMMESH*) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMLight
DECLARE_INTERFACE_(IDirect3DRMLight, IDirect3DRMObject)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
/*
* IDirect3DRMLight methods
*/
STDMETHOD(SetType)(THIS_ D3DRMLIGHTTYPE) PURE;
STDMETHOD(SetColor)(THIS_ D3DCOLOR) PURE;
STDMETHOD(SetColorRGB)(THIS_ D3DVALUE red, D3DVALUE green, D3DVALUE blue) PURE;
STDMETHOD(SetRange)(THIS_ D3DVALUE) PURE;
STDMETHOD(SetUmbra)(THIS_ D3DVALUE) PURE;
STDMETHOD(SetPenumbra)(THIS_ D3DVALUE) PURE;
STDMETHOD(SetConstantAttenuation)(THIS_ D3DVALUE) PURE;
STDMETHOD(SetLinearAttenuation)(THIS_ D3DVALUE) PURE;
STDMETHOD(SetQuadraticAttenuation)(THIS_ D3DVALUE) PURE;
STDMETHOD_(D3DVALUE, GetRange)(THIS) PURE;
STDMETHOD_(D3DVALUE, GetUmbra)(THIS) PURE;
STDMETHOD_(D3DVALUE, GetPenumbra)(THIS) PURE;
STDMETHOD_(D3DVALUE, GetConstantAttenuation)(THIS) PURE;
STDMETHOD_(D3DVALUE, GetLinearAttenuation)(THIS) PURE;
STDMETHOD_(D3DVALUE, GetQuadraticAttenuation)(THIS) PURE;
STDMETHOD_(D3DCOLOR, GetColor)(THIS) PURE;
STDMETHOD_(D3DRMLIGHTTYPE, GetType)(THIS) PURE;
STDMETHOD(SetEnableFrame)(THIS_ LPDIRECT3DRMFRAME) PURE;
STDMETHOD(GetEnableFrame)(THIS_ LPDIRECT3DRMFRAME*) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMTexture
DECLARE_INTERFACE_(IDirect3DRMTexture, IDirect3DRMVisual)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
/*
* IDirect3DRMTexture methods
*/
STDMETHOD(InitFromFile)(THIS_ const char *filename) PURE;
STDMETHOD(InitFromSurface)(THIS_ LPDIRECTDRAWSURFACE lpDDS) PURE;
STDMETHOD(InitFromResource)(THIS_ HRSRC) PURE;
STDMETHOD(Changed)(THIS_ BOOL pixels, BOOL palette) PURE;
STDMETHOD(SetColors)(THIS_ DWORD) PURE;
STDMETHOD(SetShades)(THIS_ DWORD) PURE;
STDMETHOD(SetDecalSize)(THIS_ D3DVALUE width, D3DVALUE height) PURE;
STDMETHOD(SetDecalOrigin)(THIS_ LONG x, LONG y) PURE;
STDMETHOD(SetDecalScale)(THIS_ DWORD) PURE;
STDMETHOD(SetDecalTransparency)(THIS_ BOOL) PURE;
STDMETHOD(SetDecalTransparentColor)(THIS_ D3DCOLOR) PURE;
STDMETHOD(GetDecalSize)(THIS_ D3DVALUE *width_return, D3DVALUE *height_return) PURE;
STDMETHOD(GetDecalOrigin)(THIS_ LONG *x_return, LONG *y_return) PURE;
STDMETHOD_(D3DRMIMAGE *, GetImage)(THIS) PURE;
STDMETHOD_(DWORD, GetShades)(THIS) PURE;
STDMETHOD_(DWORD, GetColors)(THIS) PURE;
STDMETHOD_(DWORD, GetDecalScale)(THIS) PURE;
STDMETHOD_(BOOL, GetDecalTransparency)(THIS) PURE;
STDMETHOD_(D3DCOLOR, GetDecalTransparentColor)(THIS) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMWrap
DECLARE_INTERFACE_(IDirect3DRMWrap, IDirect3DRMObject)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
/*
* IDirect3DRMWrap methods
*/
STDMETHOD(Init)
( THIS_ D3DRMWRAPTYPE, LPDIRECT3DRMFRAME ref,
D3DVALUE ox, D3DVALUE oy, D3DVALUE oz,
D3DVALUE dx, D3DVALUE dy, D3DVALUE dz,
D3DVALUE ux, D3DVALUE uy, D3DVALUE uz,
D3DVALUE ou, D3DVALUE ov,
D3DVALUE su, D3DVALUE sv
) PURE;
STDMETHOD(Apply)(THIS_ LPDIRECT3DRMOBJECT) PURE;
STDMETHOD(ApplyRelative)(THIS_ LPDIRECT3DRMFRAME frame, LPDIRECT3DRMOBJECT) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMMaterial
DECLARE_INTERFACE_(IDirect3DRMMaterial, IDirect3DRMObject)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
/*
* IDirect3DRMMaterial methods
*/
STDMETHOD(SetPower)(THIS_ D3DVALUE power) PURE;
STDMETHOD(SetSpecular)(THIS_ D3DVALUE r, D3DVALUE g, D3DVALUE b) PURE;
STDMETHOD(SetEmissive)(THIS_ D3DVALUE r, D3DVALUE g, D3DVALUE b) PURE;
STDMETHOD_(D3DVALUE, GetPower)(THIS) PURE;
STDMETHOD(GetSpecular)(THIS_ D3DVALUE* r, D3DVALUE* g, D3DVALUE* b) PURE;
STDMETHOD(GetEmissive)(THIS_ D3DVALUE* r, D3DVALUE* g, D3DVALUE* b) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMAnimation
DECLARE_INTERFACE_(IDirect3DRMAnimation, IDirect3DRMObject)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
/*
* IDirect3DRMAnimation methods
*/
STDMETHOD(SetOptions)(THIS_ D3DRMANIMATIONOPTIONS flags) PURE;
STDMETHOD(AddRotateKey)(THIS_ D3DVALUE time, D3DRMQUATERNION *q) PURE;
STDMETHOD(AddPositionKey)(THIS_ D3DVALUE time, D3DVALUE x, D3DVALUE y, D3DVALUE z) PURE;
STDMETHOD(AddScaleKey)(THIS_ D3DVALUE time, D3DVALUE x, D3DVALUE y, D3DVALUE z) PURE;
STDMETHOD(DeleteKey)(THIS_ D3DVALUE time) PURE;
STDMETHOD(SetFrame)(THIS_ LPDIRECT3DRMFRAME frame) PURE;
STDMETHOD(SetTime)(THIS_ D3DVALUE time) PURE;
STDMETHOD_(D3DRMANIMATIONOPTIONS, GetOptions)(THIS) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMAnimationSet
DECLARE_INTERFACE_(IDirect3DRMAnimationSet, IDirect3DRMObject)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
/*
* IDirect3DRMAnimationSet methods
*/
STDMETHOD(AddAnimation)(THIS_ LPDIRECT3DRMANIMATION aid) PURE;
STDMETHOD(Load)(THIS_ LPVOID filename, LPVOID name, D3DRMLOADOPTIONS loadflags, D3DRMLOADTEXTURECALLBACK, LPVOID lpArg, LPDIRECT3DRMFRAME parent)PURE;
STDMETHOD(DeleteAnimation)(THIS_ LPDIRECT3DRMANIMATION aid) PURE;
STDMETHOD(SetTime)(THIS_ D3DVALUE time) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMUserVisual
DECLARE_INTERFACE_(IDirect3DRMUserVisual, IDirect3DRMVisual)
{
IUNKNOWN_METHODS(PURE);
IDIRECT3DRMOBJECT_METHODS(PURE);
/*
* IDirect3DRMUserVisual methods
*/
STDMETHOD(Init)(THIS_ D3DRMUSERVISUALCALLBACK fn, void *arg) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMArray
DECLARE_INTERFACE_(IDirect3DRMArray, IUnknown)
{
IUNKNOWN_METHODS(PURE);
STDMETHOD_(DWORD, GetSize)(THIS) PURE;
/* No GetElement method as it would get overloaded
* in derived classes, and overloading is
* a no-no in COM
*/
};
#undef INTERFACE
#define INTERFACE IDirect3DRMDeviceArray
DECLARE_INTERFACE_(IDirect3DRMDeviceArray, IDirect3DRMArray)
{
IUNKNOWN_METHODS(PURE);
STDMETHOD_(DWORD, GetSize)(THIS) PURE;
STDMETHOD(GetElement)(THIS_ DWORD index, LPDIRECT3DRMDEVICE *) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMFrameArray
DECLARE_INTERFACE_(IDirect3DRMFrameArray, IDirect3DRMArray)
{
IUNKNOWN_METHODS(PURE);
STDMETHOD_(DWORD, GetSize)(THIS) PURE;
STDMETHOD(GetElement)(THIS_ DWORD index, LPDIRECT3DRMFRAME *) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMViewportArray
DECLARE_INTERFACE_(IDirect3DRMViewportArray, IDirect3DRMArray)
{
IUNKNOWN_METHODS(PURE);
STDMETHOD_(DWORD, GetSize)(THIS) PURE;
STDMETHOD(GetElement)(THIS_ DWORD index, LPDIRECT3DRMVIEWPORT *) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMVisualArray
DECLARE_INTERFACE_(IDirect3DRMVisualArray, IDirect3DRMArray)
{
IUNKNOWN_METHODS(PURE);
STDMETHOD_(DWORD, GetSize)(THIS) PURE;
STDMETHOD(GetElement)(THIS_ DWORD index, LPDIRECT3DRMVISUAL *) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMPickedArray
DECLARE_INTERFACE_(IDirect3DRMPickedArray, IDirect3DRMArray)
{
IUNKNOWN_METHODS(PURE);
STDMETHOD_(DWORD, GetSize)(THIS) PURE;
STDMETHOD(GetPick)(THIS_ DWORD index, LPDIRECT3DRMVISUAL *, LPDIRECT3DRMFRAMEARRAY *, LPD3DRMPICKDESC) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMLightArray
DECLARE_INTERFACE_(IDirect3DRMLightArray, IDirect3DRMArray)
{
IUNKNOWN_METHODS(PURE);
STDMETHOD_(DWORD, GetSize)(THIS) PURE;
STDMETHOD(GetElement)(THIS_ DWORD index, LPDIRECT3DRMLIGHT *) PURE;
};
#undef INTERFACE
#define INTERFACE IDirect3DRMFaceArray
DECLARE_INTERFACE_(IDirect3DRMFaceArray, IDirect3DRMArray)
{
IUNKNOWN_METHODS(PURE);
STDMETHOD_(DWORD, GetSize)(THIS) PURE;
STDMETHOD(GetElement)(THIS_ DWORD index, LPDIRECT3DRMFACE *) PURE;
};
#ifdef __cplusplus
};
#endif
#endif /* _D3DRMOBJ_H_ */
| 31,645 | C | .h | 619 | 47.092084 | 154 | 0.75393 | headcrab-junkyard/OGS | 98 | 13 | 0 | GPL-3.0 | 9/7/2024, 9:44:18 AM (Europe/Amsterdam) | true | false | false | true | true | true | false | false |
1,397,140 | dsetup.h | headcrab-junkyard_OGS/legacy/dxsdk/sdk/inc/dsetup.h | /*==========================================================================
*
* Copyright (C) 1995-1996 Microsoft Corporation. All Rights Reserved.
*
* File: dsetup.h
* Content: DirectXSetup, error codes and flags
***************************************************************************/
#ifndef __DSETUP_H__
#define __DSETUP_H__
#ifdef _WIN32
#define COM_NO_WINDOWS_H
#include <objbase.h>
#else
#define GUID void
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define DSETUPERR_BADWINDOWSVERSION -1
#define DSETUPERR_SOURCEFILENOTFOUND -2
#define DSETUPERR_BADSOURCESIZE -3
#define DSETUPERR_BADSOURCETIME -4
#define DSETUPERR_NOCOPY -5
#define DSETUPERR_OUTOFDISKSPACE -6
#define DSETUPERR_CANTFINDINF -7
#define DSETUPERR_CANTFINDDIR -8
#define DSETUPERR_INTERNAL -9
#define DSETUPERR_NTWITHNO3D -10
#define MAX_INFLINE (16*1024)
#define MAX_DESCRIPTION 256
#define DSETUP_DDRAW 0x00000001 /* install DirectDraw */
#define DSETUP_DSOUND 0x00000002 /* install DirectSound */
#define DSETUP_DPLAY 0x00000004 /* install DirectPlay */
#define DSETUP_DDRAWDRV 0x00000008 /* install DirectDraw Drivers */
#define DSETUP_DSOUNDDRV 0x00000010 /* install DirectSound Drivers */
#define DSETUP_DPLAYSP 0x00000020 /* install DirectPlay Providers */
#define DSETUP_DVIDEO 0x00000040 /* install DirectVideo */
#define DSETUP_REINSTALL 0x00000080 /* install DirectX even if existing components have the same version */
#define DSETUP_DRVINFONLY 0x00000100 /* install DirectX inf files but not drivers */
#define DSETUP_D3D 0x00000200 /* install Direct3D */
#define DSETUP_REQUIRESD3D 0x00000400 | DSETUP_D3D /* install Direct3D, pop up dialog box on NT, if no D3D present */
#define DSETUP_DIRECTX (DSETUP_D3D | DSETUP_DDRAW | DSETUP_DSOUND | DSETUP_DPLAY | DSETUP_DDRAWDRV | DSETUP_DSOUNDDRV | DSETUP_DPLAYSP)
int WINAPI DirectXSetup( HWND hwnd, LPSTR root_path, DWORD flags );
int WINAPI DirectXDeviceDriverSetup( HWND hwnd, LPSTR driver_class, LPSTR inf_path, LPSTR driver_path, DWORD flags );
int WINAPI DirectXSetupIsJapan( void );
int WINAPI DirectXSetupIsJapanNec( void );
typedef int (WINAPI * LPDIRECTXSETUP)( HWND, LPSTR, DWORD );
typedef int (WINAPI * LPDIRECTXDEVICEDRIVERSETUP)( HWND, LPSTR, LPSTR, LPSTR, DWORD );
typedef int (WINAPI * LPDIRECTXSETUPISJAPAN)( void );
typedef int (WINAPI * LPDIRECTXSETUPISJAPANNEC)( void );
#ifdef __cplusplus
};
#endif
#endif
| 2,794 | C | .h | 54 | 50.407407 | 144 | 0.627933 | headcrab-junkyard/OGS | 98 | 13 | 0 | GPL-3.0 | 9/7/2024, 9:44:18 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,397,141 | d3drm.h | headcrab-junkyard_OGS/legacy/dxsdk/sdk/inc/d3drm.h | /*==========================================================================;
*
* Copyright (C) 1995-1996 Microsoft Corporation. All Rights Reserved.
*
* File: d3drm.h
* Content: Direct3DRM include file
*
***************************************************************************/
#ifndef __D3DRM_H__
#define __D3DRM_H__
#include "d3drmobj.h"
#ifdef __cplusplus
extern "C" {
struct IDirect3DRM;
#endif
typedef void (*D3DRMDEVICEPALETTECALLBACK)
(LPDIRECT3DRMDEVICE lpDirect3DRMDev, LPVOID lpArg, DWORD dwIndex, LONG red, LONG green, LONG blue);
DEFINE_GUID(IID_IDirect3DRM, 0x2bc49361, 0x8327, 0x11cf, 0xac, 0x4a, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1);
WIN_TYPES(IDirect3DRM, DIRECT3DRM);
/* Create a Direct3DRM API */
STDAPI Direct3DRMCreate(LPDIRECT3DRM FAR *lplpDirect3DRM);
#undef INTERFACE
#define INTERFACE IDirect3DRM
DECLARE_INTERFACE_(IDirect3DRM, IUnknown)
{
IUNKNOWN_METHODS(PURE);
STDMETHOD(CreateObject)
(THIS_ REFCLSID rclsid, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID FAR* ppv) PURE;
STDMETHOD(CreateFrame) (THIS_ LPDIRECT3DRMFRAME, LPDIRECT3DRMFRAME *) PURE;
STDMETHOD(CreateMesh) (THIS_ LPDIRECT3DRMMESH *) PURE;
STDMETHOD(CreateMeshBuilder)(THIS_ LPDIRECT3DRMMESHBUILDER *) PURE;
STDMETHOD(CreateFace) (THIS_ LPDIRECT3DRMFACE *) PURE;
STDMETHOD(CreateAnimation) (THIS_ LPDIRECT3DRMANIMATION *) PURE;
STDMETHOD(CreateAnimationSet)(THIS_ LPDIRECT3DRMANIMATIONSET *) PURE;
STDMETHOD(CreateTexture) (THIS_ LPD3DRMIMAGE, LPDIRECT3DRMTEXTURE *) PURE;
STDMETHOD(CreateLight) (THIS_ D3DRMLIGHTTYPE, D3DCOLOR, LPDIRECT3DRMLIGHT *) PURE;
STDMETHOD(CreateLightRGB)
(THIS_ D3DRMLIGHTTYPE, D3DVALUE, D3DVALUE, D3DVALUE, LPDIRECT3DRMLIGHT *) PURE;
STDMETHOD(CreateMaterial) (THIS_ D3DVALUE, LPDIRECT3DRMMATERIAL *) PURE;
STDMETHOD(CreateDevice) (THIS_ DWORD, DWORD, LPDIRECT3DRMDEVICE *) PURE;
/* Create a Windows Device using DirectDraw surfaces */
STDMETHOD(CreateDeviceFromSurface)
( THIS_ LPGUID lpGUID, LPDIRECTDRAW lpDD,
LPDIRECTDRAWSURFACE lpDDSBack, LPDIRECT3DRMDEVICE *
) PURE;
/* Create a Windows Device using D3D objects */
STDMETHOD(CreateDeviceFromD3D)
( THIS_ LPDIRECT3D lpD3D, LPDIRECT3DDEVICE lpD3DDev,
LPDIRECT3DRMDEVICE *
) PURE;
STDMETHOD(CreateDeviceFromClipper)
( THIS_ LPDIRECTDRAWCLIPPER lpDDClipper, LPGUID lpGUID,
int width, int height, LPDIRECT3DRMDEVICE *) PURE;
STDMETHOD(CreateTextureFromSurface)(THIS_ LPDIRECTDRAWSURFACE lpDDS, LPDIRECT3DRMTEXTURE *) PURE;
STDMETHOD(CreateShadow)
( THIS_ LPDIRECT3DRMVISUAL, LPDIRECT3DRMLIGHT,
D3DVALUE px, D3DVALUE py, D3DVALUE pz,
D3DVALUE nx, D3DVALUE ny, D3DVALUE nz,
LPDIRECT3DRMVISUAL *
) PURE;
STDMETHOD(CreateViewport)
( THIS_ LPDIRECT3DRMDEVICE, LPDIRECT3DRMFRAME, DWORD, DWORD,
DWORD, DWORD, LPDIRECT3DRMVIEWPORT *
) PURE;
STDMETHOD(CreateWrap)
( THIS_ D3DRMWRAPTYPE, LPDIRECT3DRMFRAME,
D3DVALUE ox, D3DVALUE oy, D3DVALUE oz,
D3DVALUE dx, D3DVALUE dy, D3DVALUE dz,
D3DVALUE ux, D3DVALUE uy, D3DVALUE uz,
D3DVALUE ou, D3DVALUE ov,
D3DVALUE su, D3DVALUE sv,
LPDIRECT3DRMWRAP *
) PURE;
STDMETHOD(CreateUserVisual) (THIS_ D3DRMUSERVISUALCALLBACK, LPVOID lPArg, LPDIRECT3DRMUSERVISUAL *) PURE;
STDMETHOD(LoadTexture) (THIS_ const char *, LPDIRECT3DRMTEXTURE *) PURE;
STDMETHOD(LoadTextureFromResource) (THIS_ HRSRC rs, LPDIRECT3DRMTEXTURE *) PURE;
STDMETHOD(SetSearchPath) (THIS_ LPCSTR) PURE;
STDMETHOD(AddSearchPath) (THIS_ LPCSTR) PURE;
STDMETHOD(GetSearchPath) (THIS_ DWORD *size_return, LPSTR path_return);
//STDMETHOD(GetSearchPath) (THIS_ int *return_count, char ***return_path) PURE;
STDMETHOD(SetDefaultTextureColors)(THIS_ DWORD) PURE;
STDMETHOD(SetDefaultTextureShades)(THIS_ DWORD) PURE;
STDMETHOD(GetDevices) (THIS_ LPDIRECT3DRMDEVICEARRAY *) PURE;
STDMETHOD(GetNamedObject) (THIS_ const char *, LPDIRECT3DRMOBJECT *) PURE;
STDMETHOD(EnumerateObjects) (THIS_ D3DRMOBJECTCALLBACK, LPVOID) PURE;
STDMETHOD(Load)
( THIS_ LPVOID, LPVOID, LPIID *, DWORD, D3DRMLOADOPTIONS,
D3DRMLOADCALLBACK, LPVOID, D3DRMLOADTEXTURECALLBACK, LPVOID,
LPDIRECT3DRMFRAME
) PURE;
STDMETHOD(Tick) (THIS_ D3DVALUE) PURE;
};
#define D3DRM_OK DD_OK
#define D3DRMERR_BADOBJECT MAKE_DDHRESULT(781)
#define D3DRMERR_BADTYPE MAKE_DDHRESULT(782)
#define D3DRMERR_BADALLOC MAKE_DDHRESULT(783)
#define D3DRMERR_FACEUSED MAKE_DDHRESULT(784)
#define D3DRMERR_NOTFOUND MAKE_DDHRESULT(785)
#define D3DRMERR_NOTDONEYET MAKE_DDHRESULT(786)
#define D3DRMERR_FILENOTFOUND MAKE_DDHRESULT(787)
#define D3DRMERR_BADFILE MAKE_DDHRESULT(788)
#define D3DRMERR_BADDEVICE MAKE_DDHRESULT(789)
#define D3DRMERR_BADVALUE MAKE_DDHRESULT(790)
#define D3DRMERR_BADMAJORVERSION MAKE_DDHRESULT(791)
#define D3DRMERR_BADMINORVERSION MAKE_DDHRESULT(792)
#define D3DRMERR_UNABLETOEXECUTE MAKE_DDHRESULT(793)
#ifdef __cplusplus
};
#endif
#endif /* _D3DRMAPI_H_ */
| 5,354 | C | .h | 110 | 44.081818 | 109 | 0.693948 | headcrab-junkyard/OGS | 98 | 13 | 0 | GPL-3.0 | 9/7/2024, 9:44:18 AM (Europe/Amsterdam) | true | false | true | true | true | true | true | false |
1,397,145 | d3dtypes.h | headcrab-junkyard_OGS/legacy/dxsdk/sdk/inc/d3dtypes.h | /*==========================================================================;
*
* Copyright (C) 1995-1996 Microsoft Corporation. All Rights Reserved.
*
* File: d3dtypes.h
* Content: Direct3D types include file
*
***************************************************************************/
#ifndef _D3DTYPES_H_
#define _D3DTYPES_H_
#ifndef WIN32
#include "subwtype.h"
#else
#include <windows.h>
#endif
#include <ddraw.h>
#pragma pack(4)
#if defined(__cplusplus)
extern "C"
{
#endif
/* D3DVALUE is the fundamental Direct3D fractional data type */
#define D3DVALP(val, prec) ((float)(val))
#define D3DVAL(val) ((float)(val))
typedef float D3DVALUE, *LPD3DVALUE;
#define D3DDivide(a, b) (float)((double) (a) / (double) (b))
#define D3DMultiply(a, b) ((a) * (b))
typedef LONG D3DFIXED;
#ifndef RGB_MAKE
/*
* Format of CI colors is
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | alpha | color index | fraction |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
#define CI_GETALPHA(ci) ((ci) >> 24)
#define CI_GETINDEX(ci) (((ci) >> 8) & 0xffff)
#define CI_GETFRACTION(ci) ((ci) & 0xff)
#define CI_ROUNDINDEX(ci) CI_GETINDEX((ci) + 0x80)
#define CI_MASKALPHA(ci) ((ci) & 0xffffff)
#define CI_MAKE(a, i, f) (((a) << 24) | ((i) << 8) | (f))
/*
* Format of RGBA colors is
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | alpha | red | green | blue |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
#define RGBA_GETALPHA(rgb) ((rgb) >> 24)
#define RGBA_GETRED(rgb) (((rgb) >> 16) & 0xff)
#define RGBA_GETGREEN(rgb) (((rgb) >> 8) & 0xff)
#define RGBA_GETBLUE(rgb) ((rgb) & 0xff)
#define RGBA_MAKE(r, g, b, a) ((D3DCOLOR) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)))
/* D3DRGB and D3DRGBA may be used as initialisers for D3DCOLORs
* The float values must be in the range 0..1
*/
#define D3DRGB(r, g, b) \
(0xff000000L | ( ((long)((r) * 255)) << 16) | (((long)((g) * 255)) << 8) | (long)((b) * 255))
#define D3DRGBA(r, g, b, a) \
( (((long)((a) * 255)) << 24) | (((long)((r) * 255)) << 16) \
| (((long)((g) * 255)) << 8) | (long)((b) * 255) \
)
/*
* Format of RGB colors is
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | ignored | red | green | blue |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
#define RGB_GETRED(rgb) (((rgb) >> 16) & 0xff)
#define RGB_GETGREEN(rgb) (((rgb) >> 8) & 0xff)
#define RGB_GETBLUE(rgb) ((rgb) & 0xff)
#define RGBA_SETALPHA(rgba, x) (((x) << 24) | ((rgba) & 0x00ffffff))
#define RGB_MAKE(r, g, b) ((D3DCOLOR) (((r) << 16) | ((g) << 8) | (b)))
#define RGBA_TORGB(rgba) ((D3DCOLOR) ((rgba) & 0xffffff))
#define RGB_TORGBA(rgb) ((D3DCOLOR) ((rgb) | 0xff000000))
#endif
/*
* Flags for Enumerate functions
*/
/*
* Stop the enumeration
*/
#define D3DENUMRET_CANCEL DDENUMRET_CANCEL
/*
* Continue the enumeration
*/
#define D3DENUMRET_OK DDENUMRET_OK
typedef HRESULT (WINAPI* LPD3DVALIDATECALLBACK)(LPVOID lpUserArg, DWORD dwOffset);
typedef HRESULT (WINAPI* LPD3DENUMTEXTUREFORMATSCALLBACK)(LPDDSURFACEDESC lpDdsd, LPVOID lpContext);
typedef DWORD D3DCOLOR, D3DCOLOR, *LPD3DCOLOR;
typedef DWORD D3DMATERIALHANDLE, *LPD3DMATERIALHANDLE;
typedef DWORD D3DTEXTUREHANDLE, *LPD3DTEXTUREHANDLE;
typedef DWORD D3DMATRIXHANDLE, *LPD3DMATRIXHANDLE;
typedef struct _D3DCOLORVALUE {
union {
D3DVALUE r;
D3DVALUE dvR;
};
union {
D3DVALUE g;
D3DVALUE dvG;
};
union {
D3DVALUE b;
D3DVALUE dvB;
};
union {
D3DVALUE a;
D3DVALUE dvA;
};
} D3DCOLORVALUE;
typedef struct _D3DRECT {
union {
LONG x1;
LONG lX1;
};
union {
LONG y1;
LONG lY1;
};
union {
LONG x2;
LONG lX2;
};
union {
LONG y2;
LONG lY2;
};
} D3DRECT, *LPD3DRECT;
typedef struct _D3DVECTOR {
union {
D3DVALUE x;
D3DVALUE dvX;
};
union {
D3DVALUE y;
D3DVALUE dvY;
};
union {
D3DVALUE z;
D3DVALUE dvZ;
};
} D3DVECTOR, *LPD3DVECTOR;
/*
* Vertex data types supported in an ExecuteBuffer.
*/
/*
* Homogeneous vertices
*/
typedef struct _D3DHVERTEX {
DWORD dwFlags; /* Homogeneous clipping flags */
union {
D3DVALUE hx;
D3DVALUE dvHX;
};
union {
D3DVALUE hy;
D3DVALUE dvHY;
};
union {
D3DVALUE hz;
D3DVALUE dvHZ;
};
} D3DHVERTEX, *LPD3DHVERTEX;
/*
* Transformed/lit vertices
*/
typedef struct _D3DTLVERTEX {
union {
D3DVALUE sx; /* Screen coordinates */
D3DVALUE dvSX;
};
union {
D3DVALUE sy;
D3DVALUE dvSY;
};
union {
D3DVALUE sz;
D3DVALUE dvSZ;
};
union {
D3DVALUE rhw; /* Reciprocal of homogeneous w */
D3DVALUE dvRHW;
};
union {
D3DCOLOR color; /* Vertex color */
D3DCOLOR dcColor;
};
union {
D3DCOLOR specular; /* Specular component of vertex */
D3DCOLOR dcSpecular;
};
union {
D3DVALUE tu; /* Texture coordinates */
D3DVALUE dvTU;
};
union {
D3DVALUE tv;
D3DVALUE dvTV;
};
} D3DTLVERTEX, *LPD3DTLVERTEX;
/*
* Untransformed/lit vertices
*/
typedef struct _D3DLVERTEX {
union {
D3DVALUE x; /* Homogeneous coordinates */
D3DVALUE dvX;
};
union {
D3DVALUE y;
D3DVALUE dvY;
};
union {
D3DVALUE z;
D3DVALUE dvZ;
};
DWORD dwReserved;
union {
D3DCOLOR color; /* Vertex color */
D3DCOLOR dcColor;
};
union {
D3DCOLOR specular; /* Specular component of vertex */
D3DCOLOR dcSpecular;
};
union {
D3DVALUE tu; /* Texture coordinates */
D3DVALUE dvTU;
};
union {
D3DVALUE tv;
D3DVALUE dvTV;
};
} D3DLVERTEX, *LPD3DLVERTEX;
/*
* Untransformed/unlit vertices
*/
typedef struct _D3DVERTEX {
union {
D3DVALUE x; /* Homogeneous coordinates */
D3DVALUE dvX;
};
union {
D3DVALUE y;
D3DVALUE dvY;
};
union {
D3DVALUE z;
D3DVALUE dvZ;
};
union {
D3DVALUE nx; /* Normal */
D3DVALUE dvNX;
};
union {
D3DVALUE ny;
D3DVALUE dvNY;
};
union {
D3DVALUE nz;
D3DVALUE dvNZ;
};
union {
D3DVALUE tu; /* Texture coordinates */
D3DVALUE dvTU;
};
union {
D3DVALUE tv;
D3DVALUE dvTV;
};
} D3DVERTEX, *LPD3DVERTEX;
/*
* Matrix, viewport, and tranformation structures and definitions.
*/
typedef struct _D3DMATRIX {
D3DVALUE _11, _12, _13, _14;
D3DVALUE _21, _22, _23, _24;
D3DVALUE _31, _32, _33, _34;
D3DVALUE _41, _42, _43, _44;
} D3DMATRIX, *LPD3DMATRIX;
typedef struct _D3DVIEWPORT {
DWORD dwSize;
DWORD dwX;
DWORD dwY; /* Top left */
DWORD dwWidth;
DWORD dwHeight; /* Dimensions */
D3DVALUE dvScaleX; /* Scale homogeneous to screen */
D3DVALUE dvScaleY; /* Scale homogeneous to screen */
D3DVALUE dvMaxX; /* Min/max homogeneous x coord */
D3DVALUE dvMaxY; /* Min/max homogeneous y coord */
D3DVALUE dvMinZ;
D3DVALUE dvMaxZ; /* Min/max homogeneous z coord */
} D3DVIEWPORT, *LPD3DVIEWPORT;
/*
* Values for clip fields.
*/
#define D3DCLIP_LEFT 0x00000001L
#define D3DCLIP_RIGHT 0x00000002L
#define D3DCLIP_TOP 0x00000004L
#define D3DCLIP_BOTTOM 0x00000008L
#define D3DCLIP_FRONT 0x00000010L
#define D3DCLIP_BACK 0x00000020L
#define D3DCLIP_GEN0 0x00000040L
#define D3DCLIP_GEN1 0x00000080L
#define D3DCLIP_GEN2 0x00000100L
#define D3DCLIP_GEN3 0x00000200L
#define D3DCLIP_GEN4 0x00000400L
#define D3DCLIP_GEN5 0x00000800L
/*
* Values for d3d status.
*/
#define D3DSTATUS_CLIPUNIONLEFT D3DCLIP_LEFT
#define D3DSTATUS_CLIPUNIONRIGHT D3DCLIP_RIGHT
#define D3DSTATUS_CLIPUNIONTOP D3DCLIP_TOP
#define D3DSTATUS_CLIPUNIONBOTTOM D3DCLIP_BOTTOM
#define D3DSTATUS_CLIPUNIONFRONT D3DCLIP_FRONT
#define D3DSTATUS_CLIPUNIONBACK D3DCLIP_BACK
#define D3DSTATUS_CLIPUNIONGEN0 D3DCLIP_GEN0
#define D3DSTATUS_CLIPUNIONGEN1 D3DCLIP_GEN1
#define D3DSTATUS_CLIPUNIONGEN2 D3DCLIP_GEN2
#define D3DSTATUS_CLIPUNIONGEN3 D3DCLIP_GEN3
#define D3DSTATUS_CLIPUNIONGEN4 D3DCLIP_GEN4
#define D3DSTATUS_CLIPUNIONGEN5 D3DCLIP_GEN5
#define D3DSTATUS_CLIPINTERSECTIONLEFT 0x00001000L
#define D3DSTATUS_CLIPINTERSECTIONRIGHT 0x00002000L
#define D3DSTATUS_CLIPINTERSECTIONTOP 0x00004000L
#define D3DSTATUS_CLIPINTERSECTIONBOTTOM 0x00008000L
#define D3DSTATUS_CLIPINTERSECTIONFRONT 0x00010000L
#define D3DSTATUS_CLIPINTERSECTIONBACK 0x00020000L
#define D3DSTATUS_CLIPINTERSECTIONGEN0 0x00040000L
#define D3DSTATUS_CLIPINTERSECTIONGEN1 0x00080000L
#define D3DSTATUS_CLIPINTERSECTIONGEN2 0x00100000L
#define D3DSTATUS_CLIPINTERSECTIONGEN3 0x00200000L
#define D3DSTATUS_CLIPINTERSECTIONGEN4 0x00400000L
#define D3DSTATUS_CLIPINTERSECTIONGEN5 0x00800000L
#define D3DSTATUS_ZNOTVISIBLE 0x01000000L
#define D3DSTATUS_CLIPUNIONALL ( \
D3DSTATUS_CLIPUNIONLEFT | \
D3DSTATUS_CLIPUNIONRIGHT | \
D3DSTATUS_CLIPUNIONTOP | \
D3DSTATUS_CLIPUNIONBOTTOM | \
D3DSTATUS_CLIPUNIONFRONT | \
D3DSTATUS_CLIPUNIONBACK | \
D3DSTATUS_CLIPUNIONGEN0 | \
D3DSTATUS_CLIPUNIONGEN1 | \
D3DSTATUS_CLIPUNIONGEN2 | \
D3DSTATUS_CLIPUNIONGEN3 | \
D3DSTATUS_CLIPUNIONGEN4 | \
D3DSTATUS_CLIPUNIONGEN5 \
)
#define D3DSTATUS_CLIPINTERSECTIONALL ( \
D3DSTATUS_CLIPINTERSECTIONLEFT | \
D3DSTATUS_CLIPINTERSECTIONRIGHT | \
D3DSTATUS_CLIPINTERSECTIONTOP | \
D3DSTATUS_CLIPINTERSECTIONBOTTOM | \
D3DSTATUS_CLIPINTERSECTIONFRONT | \
D3DSTATUS_CLIPINTERSECTIONBACK | \
D3DSTATUS_CLIPINTERSECTIONGEN0 | \
D3DSTATUS_CLIPINTERSECTIONGEN1 | \
D3DSTATUS_CLIPINTERSECTIONGEN2 | \
D3DSTATUS_CLIPINTERSECTIONGEN3 | \
D3DSTATUS_CLIPINTERSECTIONGEN4 | \
D3DSTATUS_CLIPINTERSECTIONGEN5 \
)
#define D3DSTATUS_DEFAULT ( \
D3DSTATUS_CLIPINTERSECTIONALL | \
D3DSTATUS_ZNOTVISIBLE)
/*
* Options for direct transform calls
*/
#define D3DTRANSFORM_CLIPPED 0x00000001l
#define D3DTRANSFORM_UNCLIPPED 0x00000002l
typedef struct _D3DTRANSFORMDATA {
DWORD dwSize;
LPVOID lpIn; /* Input vertices */
DWORD dwInSize; /* Stride of input vertices */
LPVOID lpOut; /* Output vertices */
DWORD dwOutSize; /* Stride of output vertices */
LPD3DHVERTEX lpHOut; /* Output homogeneous vertices */
DWORD dwClip; /* Clipping hint */
DWORD dwClipIntersection;
DWORD dwClipUnion; /* Union of all clip flags */
D3DRECT drExtent; /* Extent of transformed vertices */
} D3DTRANSFORMDATA, *LPD3DTRANSFORMDATA;
/*
* Structure defining position and direction properties for lighting.
*/
typedef struct _D3DLIGHTINGELEMENT {
D3DVECTOR dvPosition; /* Lightable point in model space */
D3DVECTOR dvNormal; /* Normalised unit vector */
} D3DLIGHTINGELEMENT, *LPD3DLIGHTINGELEMENT;
/*
* Structure defining material properties for lighting.
*/
typedef struct _D3DMATERIAL {
DWORD dwSize;
union {
D3DCOLORVALUE diffuse; /* Diffuse color RGBA */
D3DCOLORVALUE dcvDiffuse;
};
union {
D3DCOLORVALUE ambient; /* Ambient color RGB */
D3DCOLORVALUE dcvAmbient;
};
union {
D3DCOLORVALUE specular; /* Specular 'shininess' */
D3DCOLORVALUE dcvSpecular;
};
union {
D3DCOLORVALUE emissive; /* Emissive color RGB */
D3DCOLORVALUE dcvEmissive;
};
union {
D3DVALUE power; /* Sharpness if specular highlight */
D3DVALUE dvPower;
};
D3DTEXTUREHANDLE hTexture; /* Handle to texture map */
DWORD dwRampSize;
} D3DMATERIAL, *LPD3DMATERIAL;
typedef enum _D3DLIGHTTYPE {
D3DLIGHT_POINT = 1,
D3DLIGHT_SPOT = 2,
D3DLIGHT_DIRECTIONAL = 3,
D3DLIGHT_PARALLELPOINT = 4,
D3DLIGHT_GLSPOT = 5,
} D3DLIGHTTYPE;
/*
* Structure defining a light source and its properties.
*/
typedef struct _D3DLIGHT {
DWORD dwSize;
D3DLIGHTTYPE dltType; /* Type of light source */
D3DCOLORVALUE dcvColor; /* Color of light */
D3DVECTOR dvPosition; /* Position in world space */
D3DVECTOR dvDirection; /* Direction in world space */
D3DVALUE dvRange; /* Cutoff range */
D3DVALUE dvFalloff; /* Falloff */
D3DVALUE dvAttenuation0; /* Constant attenuation */
D3DVALUE dvAttenuation1; /* Linear attenuation */
D3DVALUE dvAttenuation2; /* Quadratic attenuation */
D3DVALUE dvTheta; /* Inner angle of spotlight cone */
D3DVALUE dvPhi; /* Outer angle of spotlight cone */
} D3DLIGHT, *LPD3DLIGHT;
typedef struct _D3DLIGHTDATA {
DWORD dwSize;
LPD3DLIGHTINGELEMENT lpIn; /* Input positions and normals */
DWORD dwInSize; /* Stride of input elements */
LPD3DTLVERTEX lpOut; /* Output colors */
DWORD dwOutSize; /* Stride of output colors */
} D3DLIGHTDATA, *LPD3DLIGHTDATA;
typedef enum _D3DCOLORMODEL {
D3DCOLOR_MONO = 1,
D3DCOLOR_RGB = 2,
} D3DCOLORMODEL;
/*
* Options for clearing
*/
#define D3DCLEAR_TARGET 0x00000001l /* Clear target surface */
#define D3DCLEAR_ZBUFFER 0x00000002l /* Clear target z buffer */
/*
* Execute buffers are allocated via Direct3D. These buffers may then
* be filled by the application with instructions to execute along with
* vertex data.
*/
/*
* Supported op codes for execute instructions.
*/
typedef enum _D3DOPCODE {
D3DOP_POINT = 1,
D3DOP_LINE = 2,
D3DOP_TRIANGLE = 3,
D3DOP_MATRIXLOAD = 4,
D3DOP_MATRIXMULTIPLY = 5,
D3DOP_STATETRANSFORM = 6,
D3DOP_STATELIGHT = 7,
D3DOP_STATERENDER = 8,
D3DOP_PROCESSVERTICES = 9,
D3DOP_TEXTURELOAD = 10,
D3DOP_EXIT = 11,
D3DOP_BRANCHFORWARD = 12,
D3DOP_SPAN = 13,
D3DOP_SETSTATUS = 14,
} D3DOPCODE;
typedef struct _D3DINSTRUCTION {
BYTE bOpcode; /* Instruction opcode */
BYTE bSize; /* Size of each instruction data unit */
WORD wCount; /* Count of instruction data units to follow */
} D3DINSTRUCTION, *LPD3DINSTRUCTION;
/*
* Structure for texture loads
*/
typedef struct _D3DTEXTURELOAD {
D3DTEXTUREHANDLE hDestTexture;
D3DTEXTUREHANDLE hSrcTexture;
} D3DTEXTURELOAD, *LPD3DTEXTURELOAD;
/*
* Structure for picking
*/
typedef struct _D3DPICKRECORD {
BYTE bOpcode;
BYTE bPad;
DWORD dwOffset;
D3DVALUE dvZ;
} D3DPICKRECORD, *LPD3DPICKRECORD;
/*
* The following defines the rendering states which can be set in the
* execute buffer.
*/
typedef enum _D3DSHADEMODE {
D3DSHADE_FLAT = 1,
D3DSHADE_GOURAUD = 2,
D3DSHADE_PHONG = 3,
} D3DSHADEMODE;
typedef enum _D3DFILLMODE {
D3DFILL_POINT = 1,
D3DFILL_WIREFRAME = 2,
D3DFILL_SOLID = 3,
} D3DFILLMODE;
typedef struct _D3DLINEPATTERN {
WORD wRepeatFactor;
WORD wLinePattern;
} D3DLINEPATTERN;
typedef enum _D3DTEXTUREFILTER {
D3DFILTER_NEAREST = 1,
D3DFILTER_LINEAR = 2,
D3DFILTER_MIPNEAREST = 3,
D3DFILTER_MIPLINEAR = 4,
D3DFILTER_LINEARMIPNEAREST = 5,
D3DFILTER_LINEARMIPLINEAR = 6,
} D3DTEXTUREFILTER;
typedef enum _D3DBLEND {
D3DBLEND_ZERO = 1,
D3DBLEND_ONE = 2,
D3DBLEND_SRCCOLOR = 3,
D3DBLEND_INVSRCCOLOR = 4,
D3DBLEND_SRCALPHA = 5,
D3DBLEND_INVSRCALPHA = 6,
D3DBLEND_DESTALPHA = 7,
D3DBLEND_INVDESTALPHA = 8,
D3DBLEND_DESTCOLOR = 9,
D3DBLEND_INVDESTCOLOR = 10,
D3DBLEND_SRCALPHASAT = 11,
D3DBLEND_BOTHSRCALPHA = 12,
D3DBLEND_BOTHINVSRCALPHA = 13,
} D3DBLEND;
typedef enum _D3DTEXTUREBLEND {
D3DTBLEND_DECAL = 1,
D3DTBLEND_MODULATE = 2,
D3DTBLEND_DECALALPHA = 3,
D3DTBLEND_MODULATEALPHA = 4,
D3DTBLEND_DECALMASK = 5,
D3DTBLEND_MODULATEMASK = 6,
D3DTBLEND_COPY = 7,
} D3DTEXTUREBLEND;
typedef enum _D3DTEXTUREADDRESS {
D3DTADDRESS_WRAP = 1,
D3DTADDRESS_MIRROR = 2,
D3DTADDRESS_CLAMP = 3,
} D3DTEXTUREADDRESS;
typedef enum _D3DCULL {
D3DCULL_NONE = 1,
D3DCULL_CW = 2,
D3DCULL_CCW = 3,
} D3DCULL;
typedef enum _D3DCMPFUNC {
D3DCMP_NEVER = 1,
D3DCMP_LESS = 2,
D3DCMP_EQUAL = 3,
D3DCMP_LESSEQUAL = 4,
D3DCMP_GREATER = 5,
D3DCMP_NOTEQUAL = 6,
D3DCMP_GREATEREQUAL = 7,
D3DCMP_ALWAYS = 8,
} D3DCMPFUNC;
typedef enum _D3DFOGMODE {
D3DFOG_NONE = 0,
D3DFOG_EXP = 1,
D3DFOG_EXP2 = 2,
D3DFOG_LINEAR = 3
} D3DFOGMODE;
/*
* Amount to add to a state to generate the override for that state.
*/
#define D3DSTATE_OVERRIDE_BIAS 256
/*
* A state which sets the override flag for the specified state type.
*/
#define D3DSTATE_OVERRIDE(type) ((DWORD) (type) + D3DSTATE_OVERRIDE_BIAS)
typedef enum _D3DTRANSFORMSTATETYPE {
D3DTRANSFORMSTATE_WORLD = 1,
D3DTRANSFORMSTATE_VIEW = 2,
D3DTRANSFORMSTATE_PROJECTION = 3,
} D3DTRANSFORMSTATETYPE;
typedef enum _D3DLIGHTSTATETYPE {
D3DLIGHTSTATE_MATERIAL = 1,
D3DLIGHTSTATE_AMBIENT = 2,
D3DLIGHTSTATE_COLORMODEL = 3,
D3DLIGHTSTATE_FOGMODE = 4,
D3DLIGHTSTATE_FOGSTART = 5,
D3DLIGHTSTATE_FOGEND = 6,
D3DLIGHTSTATE_FOGDENSITY = 7,
} D3DLIGHTSTATETYPE;
typedef enum _D3DRENDERSTATETYPE {
D3DRENDERSTATE_TEXTUREHANDLE = 1, /* Texture handle */
D3DRENDERSTATE_ANTIALIAS = 2, /* Antialiasing prim edges */
D3DRENDERSTATE_TEXTUREADDRESS = 3, /* D3DTEXTUREADDRESS */
D3DRENDERSTATE_TEXTUREPERSPECTIVE = 4, /* TRUE for perspective correction */
D3DRENDERSTATE_WRAPU = 5, /* TRUE for wrapping in u */
D3DRENDERSTATE_WRAPV = 6, /* TRUE for wrapping in v */
D3DRENDERSTATE_ZENABLE = 7, /* TRUE to enable z test */
D3DRENDERSTATE_FILLMODE = 8, /* D3DFILL_MODE */
D3DRENDERSTATE_SHADEMODE = 9, /* D3DSHADEMODE */
D3DRENDERSTATE_LINEPATTERN = 10, /* D3DLINEPATTERN */
D3DRENDERSTATE_MONOENABLE = 11, /* TRUE to enable mono rasterization */
D3DRENDERSTATE_ROP2 = 12, /* ROP2 */
D3DRENDERSTATE_PLANEMASK = 13, /* DWORD physical plane mask */
D3DRENDERSTATE_ZWRITEENABLE = 14, /* TRUE to enable z writes */
D3DRENDERSTATE_ALPHATESTENABLE = 15, /* TRUE to enable alpha tests */
D3DRENDERSTATE_LASTPIXEL = 16, /* TRUE for last-pixel on lines */
D3DRENDERSTATE_TEXTUREMAG = 17, /* D3DTEXTUREFILTER */
D3DRENDERSTATE_TEXTUREMIN = 18, /* D3DTEXTUREFILTER */
D3DRENDERSTATE_SRCBLEND = 19, /* D3DBLEND */
D3DRENDERSTATE_DESTBLEND = 20, /* D3DBLEND */
D3DRENDERSTATE_TEXTUREMAPBLEND = 21, /* D3DTEXTUREBLEND */
D3DRENDERSTATE_CULLMODE = 22, /* D3DCULL */
D3DRENDERSTATE_ZFUNC = 23, /* D3DCMPFUNC */
D3DRENDERSTATE_ALPHAREF = 24, /* D3DFIXED */
D3DRENDERSTATE_ALPHAFUNC = 25, /* D3DCMPFUNC */
D3DRENDERSTATE_DITHERENABLE = 26, /* TRUE to enable dithering */
D3DRENDERSTATE_BLENDENABLE = 27, /* TRUE to enable alpha blending */
D3DRENDERSTATE_FOGENABLE = 28, /* TRUE to enable fog */
D3DRENDERSTATE_SPECULARENABLE = 29, /* TRUE to enable specular */
D3DRENDERSTATE_ZVISIBLE = 30, /* TRUE to enable z checking */
D3DRENDERSTATE_SUBPIXEL = 31, /* TRUE to enable subpixel correction */
D3DRENDERSTATE_SUBPIXELX = 32, /* TRUE to enable correction in X only */
D3DRENDERSTATE_STIPPLEDALPHA = 33, /* TRUE to enable stippled alpha */
D3DRENDERSTATE_FOGCOLOR = 34, /* D3DCOLOR */
D3DRENDERSTATE_FOGTABLEMODE = 35, /* D3DFOGMODE */
D3DRENDERSTATE_FOGTABLESTART = 36, /* Fog table start */
D3DRENDERSTATE_FOGTABLEEND = 37, /* Fog table end */
D3DRENDERSTATE_FOGTABLEDENSITY = 38, /* Fog table density */
D3DRENDERSTATE_STIPPLEENABLE = 39, /* TRUE to enable stippling */
D3DRENDERSTATE_STIPPLEPATTERN00 = 64, /* Stipple pattern 01... */
D3DRENDERSTATE_STIPPLEPATTERN01 = 65,
D3DRENDERSTATE_STIPPLEPATTERN02 = 66,
D3DRENDERSTATE_STIPPLEPATTERN03 = 67,
D3DRENDERSTATE_STIPPLEPATTERN04 = 68,
D3DRENDERSTATE_STIPPLEPATTERN05 = 69,
D3DRENDERSTATE_STIPPLEPATTERN06 = 70,
D3DRENDERSTATE_STIPPLEPATTERN07 = 71,
D3DRENDERSTATE_STIPPLEPATTERN08 = 72,
D3DRENDERSTATE_STIPPLEPATTERN09 = 73,
D3DRENDERSTATE_STIPPLEPATTERN10 = 74,
D3DRENDERSTATE_STIPPLEPATTERN11 = 75,
D3DRENDERSTATE_STIPPLEPATTERN12 = 76,
D3DRENDERSTATE_STIPPLEPATTERN13 = 77,
D3DRENDERSTATE_STIPPLEPATTERN14 = 78,
D3DRENDERSTATE_STIPPLEPATTERN15 = 79,
D3DRENDERSTATE_STIPPLEPATTERN16 = 80,
D3DRENDERSTATE_STIPPLEPATTERN17 = 81,
D3DRENDERSTATE_STIPPLEPATTERN18 = 82,
D3DRENDERSTATE_STIPPLEPATTERN19 = 83,
D3DRENDERSTATE_STIPPLEPATTERN20 = 84,
D3DRENDERSTATE_STIPPLEPATTERN21 = 85,
D3DRENDERSTATE_STIPPLEPATTERN22 = 86,
D3DRENDERSTATE_STIPPLEPATTERN23 = 87,
D3DRENDERSTATE_STIPPLEPATTERN24 = 88,
D3DRENDERSTATE_STIPPLEPATTERN25 = 89,
D3DRENDERSTATE_STIPPLEPATTERN26 = 90,
D3DRENDERSTATE_STIPPLEPATTERN27 = 91,
D3DRENDERSTATE_STIPPLEPATTERN28 = 92,
D3DRENDERSTATE_STIPPLEPATTERN29 = 93,
D3DRENDERSTATE_STIPPLEPATTERN30 = 94,
D3DRENDERSTATE_STIPPLEPATTERN31 = 95,
} D3DRENDERSTATETYPE;
#define D3DRENDERSTATE_STIPPLEPATTERN(y) (D3DRENDERSTATE_STIPPLEPATTERN00 + (y))
typedef struct _D3DSTATE {
union {
D3DTRANSFORMSTATETYPE dtstTransformStateType;
D3DLIGHTSTATETYPE dlstLightStateType;
D3DRENDERSTATETYPE drstRenderStateType;
};
union {
DWORD dwArg[1];
D3DVALUE dvArg[1];
};
} D3DSTATE, *LPD3DSTATE;
/*
* Operation used to load matrices
* hDstMat = hSrcMat
*/
typedef struct _D3DMATRIXLOAD {
D3DMATRIXHANDLE hDestMatrix; /* Destination matrix */
D3DMATRIXHANDLE hSrcMatrix; /* Source matrix */
} D3DMATRIXLOAD, *LPD3DMATRIXLOAD;
/*
* Operation used to multiply matrices
* hDstMat = hSrcMat1 * hSrcMat2
*/
typedef struct _D3DMATRIXMULTIPLY {
D3DMATRIXHANDLE hDestMatrix; /* Destination matrix */
D3DMATRIXHANDLE hSrcMatrix1; /* First source matrix */
D3DMATRIXHANDLE hSrcMatrix2; /* Second source matrix */
} D3DMATRIXMULTIPLY, *LPD3DMATRIXMULTIPLY;
/*
* Operation used to transform and light vertices.
*/
typedef struct _D3DPROCESSVERTICES {
DWORD dwFlags; /* Do we transform or light or just copy? */
WORD wStart; /* Index to first vertex in source */
WORD wDest; /* Index to first vertex in local buffer */
DWORD dwCount; /* Number of vertices to be processed */
DWORD dwReserved; /* Must be zero */
} D3DPROCESSVERTICES, *LPD3DPROCESSVERTICES;
#define D3DPROCESSVERTICES_TRANSFORMLIGHT 0x00000000L
#define D3DPROCESSVERTICES_TRANSFORM 0x00000001L
#define D3DPROCESSVERTICES_COPY 0x00000002L
#define D3DPROCESSVERTICES_OPMASK 0x00000007L
#define D3DPROCESSVERTICES_UPDATEEXTENTS 0x00000008L
#define D3DPROCESSVERTICES_NOCOLOR 0x00000010L
/*
* Triangle flags
*/
/*
* Tri strip and fan flags.
* START loads all three vertices
* EVEN and ODD load just v3 with even or odd culling
* START_FLAT contains a count from 0 to 29 that allows the
* whole strip or fan to be culled in one hit.
* e.g. for a quad len = 1
*/
#define D3DTRIFLAG_START 0x00000000L
#define D3DTRIFLAG_STARTFLAT(len) (len) /* 0 < len < 30 */
#define D3DTRIFLAG_ODD 0x0000001eL
#define D3DTRIFLAG_EVEN 0x0000001fL
/*
* Triangle edge flags
* enable edges for wireframe or antialiasing
*/
#define D3DTRIFLAG_EDGEENABLE1 0x00000100L /* v0-v1 edge */
#define D3DTRIFLAG_EDGEENABLE2 0x00000200L /* v1-v2 edge */
#define D3DTRIFLAG_EDGEENABLE3 0x00000400L /* v2-v0 edge */
#define D3DTRIFLAG_EDGEENABLETRIANGLE \
(D3DTRIFLAG_EDGEENABLE1 | D3DTRIFLAG_EDGEENABLE2 | D3DTRIFLAG_EDGEENABLE3)
/*
* Primitive structures and related defines. Vertex offsets are to types
* D3DVERTEX, D3DLVERTEX, or D3DTLVERTEX.
*/
/*
* Triangle list primitive structure
*/
typedef struct _D3DTRIANGLE {
union {
WORD v1; /* Vertex indices */
WORD wV1;
};
union {
WORD v2;
WORD wV2;
};
union {
WORD v3;
WORD wV3;
};
WORD wFlags; /* Edge (and other) flags */
} D3DTRIANGLE, *LPD3DTRIANGLE;
/*
* Line strip structure.
* The instruction count - 1 defines the number of line segments.
*/
typedef struct _D3DLINE {
union {
WORD v1; /* Vertex indices */
WORD wV1;
};
union {
WORD v2;
WORD wV2;
};
} D3DLINE, *LPD3DLINE;
/*
* Span structure
* Spans join a list of points with the same y value.
* If the y value changes, a new span is started.
*/
typedef struct _D3DSPAN {
WORD wCount; /* Number of spans */
WORD wFirst; /* Index to first vertex */
} D3DSPAN, *LPD3DSPAN;
/*
* Point structure
*/
typedef struct _D3DPOINT {
WORD wCount; /* number of points */
WORD wFirst; /* index to first vertex */
} D3DPOINT, *LPD3DPOINT;
/*
* Forward branch structure.
* Mask is logically anded with the driver status mask
* if the result equals 'value', the branch is taken.
*/
typedef struct _D3DBRANCH {
DWORD dwMask; /* Bitmask against D3D status */
DWORD dwValue;
BOOL bNegate; /* TRUE to negate comparison */
DWORD dwOffset; /* How far to branch forward (0 for exit)*/
} D3DBRANCH, *LPD3DBRANCH;
/*
* Status used for set status instruction.
* The D3D status is initialised on device creation
* and is modified by all execute calls.
*/
typedef struct _D3DSTATUS {
DWORD dwFlags; /* Do we set extents or status */
DWORD dwStatus; /* D3D status */
D3DRECT drExtent;
} D3DSTATUS, *LPD3DSTATUS;
#define D3DSETSTATUS_STATUS 0x00000001L
#define D3DSETSTATUS_EXTENTS 0x00000002L
#define D3DSETSTATUS_ALL (D3DSETSTATUS_STATUS | D3DSETSTATUS_EXTENTS)
/*
* Statistics structure
*/
typedef struct _D3DSTATS {
DWORD dwSize;
DWORD dwTrianglesDrawn;
DWORD dwLinesDrawn;
DWORD dwPointsDrawn;
DWORD dwSpansDrawn;
DWORD dwVerticesProcessed;
} D3DSTATS, *LPD3DSTATS;
/*
* Execute options.
* When calling using D3DEXECUTE_UNCLIPPED all the primitives
* inside the buffer must be contained within the viewport.
*/
#define D3DEXECUTE_CLIPPED 0x00000001l
#define D3DEXECUTE_UNCLIPPED 0x00000002l
typedef struct _D3DEXECUTEDATA {
DWORD dwSize;
DWORD dwVertexOffset;
DWORD dwVertexCount;
DWORD dwInstructionOffset;
DWORD dwInstructionLength;
DWORD dwHVertexOffset;
D3DSTATUS dsStatus; /* Status after execute */
} D3DEXECUTEDATA, *LPD3DEXECUTEDATA;
/*
* Palette flags.
* This are or'ed with the peFlags in the PALETTEENTRYs passed to DirectDraw.
*/
#define D3DPAL_FREE 0x00 /* Renderer may use this entry freely */
#define D3DPAL_READONLY 0x40 /* Renderer may not set this entry */
#define D3DPAL_RESERVED 0x80 /* Renderer may not use this entry */
#if defined(__cplusplus)
};
#endif
#pragma pack()
#endif /* _D3DTYPES_H_ */
| 31,001 | C | .h | 859 | 31.866123 | 100 | 0.586496 | headcrab-junkyard/OGS | 98 | 13 | 0 | GPL-3.0 | 9/7/2024, 9:44:18 AM (Europe/Amsterdam) | true | false | false | true | true | true | false | false |
1,397,146 | dsound.h | headcrab-junkyard_OGS/legacy/dxsdk/sdk/inc/dsound.h | /*==========================================================================;
*
* Copyright (C) 1995,1996 Microsoft Corporation. All Rights Reserved.
*
* File: dsound.h
* Content: DirectSound include file
*
***************************************************************************/
#ifndef __DSOUND_INCLUDED__
#define __DSOUND_INCLUDED__
#ifdef _WIN32
#define COM_NO_WINDOWS_H
#include <objbase.h>
#endif
#define _FACDS 0x878
#define MAKE_DSHRESULT( code ) MAKE_HRESULT( 1, _FACDS, code )
#ifdef __cplusplus
extern "C" {
#endif
// Direct Sound Component GUID {47D4D946-62E8-11cf-93BC-444553540000}
DEFINE_GUID(CLSID_DirectSound,
0x47d4d946, 0x62e8, 0x11cf, 0x93, 0xbc, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0);
// DirectSound 279afa83-4981-11ce-a521-0020af0be560
DEFINE_GUID(IID_IDirectSound,0x279AFA83,0x4981,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60);
// DirectSoundBuffer 279afa85-4981-11ce-a521-0020af0be560
DEFINE_GUID(IID_IDirectSoundBuffer,0x279AFA85,0x4981,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60);
//==========================================================================;
//
// Structures...
//
//==========================================================================;
#ifdef __cplusplus
/* 'struct' not 'class' per the way DECLARE_INTERFACE_ is defined */
struct IDirectSound;
struct IDirectSoundBuffer;
#endif
typedef struct IDirectSound *LPDIRECTSOUND;
typedef struct IDirectSoundBuffer *LPDIRECTSOUNDBUFFER;
typedef struct IDirectSoundBuffer **LPLPDIRECTSOUNDBUFFER;
typedef struct _DSCAPS
{
DWORD dwSize;
DWORD dwFlags;
DWORD dwMinSecondarySampleRate;
DWORD dwMaxSecondarySampleRate;
DWORD dwPrimaryBuffers;
DWORD dwMaxHwMixingAllBuffers;
DWORD dwMaxHwMixingStaticBuffers;
DWORD dwMaxHwMixingStreamingBuffers;
DWORD dwFreeHwMixingAllBuffers;
DWORD dwFreeHwMixingStaticBuffers;
DWORD dwFreeHwMixingStreamingBuffers;
DWORD dwMaxHw3DAllBuffers;
DWORD dwMaxHw3DStaticBuffers;
DWORD dwMaxHw3DStreamingBuffers;
DWORD dwFreeHw3DAllBuffers;
DWORD dwFreeHw3DStaticBuffers;
DWORD dwFreeHw3DStreamingBuffers;
DWORD dwTotalHwMemBytes;
DWORD dwFreeHwMemBytes;
DWORD dwMaxContigFreeHwMemBytes;
DWORD dwUnlockTransferRateHwBuffers;
DWORD dwPlayCpuOverheadSwBuffers;
DWORD dwReserved1;
DWORD dwReserved2;
} DSCAPS, *LPDSCAPS;
typedef struct _DSBCAPS
{
DWORD dwSize;
DWORD dwFlags;
DWORD dwBufferBytes;
DWORD dwUnlockTransferRate;
DWORD dwPlayCpuOverhead;
} DSBCAPS, *LPDSBCAPS;
typedef struct _DSBUFFERDESC
{
DWORD dwSize;
DWORD dwFlags;
DWORD dwBufferBytes;
DWORD dwReserved;
LPWAVEFORMATEX lpwfxFormat;
} DSBUFFERDESC, *LPDSBUFFERDESC;
typedef LPVOID* LPLPVOID;
typedef BOOL (FAR PASCAL * LPDSENUMCALLBACKW)(GUID FAR *, LPWSTR, LPWSTR, LPVOID);
typedef BOOL (FAR PASCAL * LPDSENUMCALLBACKA)(GUID FAR *, LPSTR, LPSTR, LPVOID);
extern HRESULT WINAPI DirectSoundCreate(GUID FAR * lpGUID, LPDIRECTSOUND * ppDS, IUnknown FAR *pUnkOuter );
extern HRESULT WINAPI DirectSoundEnumerateW(LPDSENUMCALLBACKW lpCallback, LPVOID lpContext );
extern HRESULT WINAPI DirectSoundEnumerateA(LPDSENUMCALLBACKA lpCallback, LPVOID lpContext );
#ifdef UNICODE
#define LPDSENUMCALLBACK LPDSENUMCALLBACKW
#define DirectSoundEnumerate DirectSoundEnumerateW
#else
#define LPDSENUMCALLBACK LPDSENUMCALLBACKA
#define DirectSoundEnumerate DirectSoundEnumerateA
#endif
//
// IDirectSound
//
#undef INTERFACE
#define INTERFACE IDirectSound
#ifdef _WIN32
DECLARE_INTERFACE_( IDirectSound, IUnknown )
{
/*** IUnknown methods ***/
STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID * ppvObj) PURE;
STDMETHOD_(ULONG,AddRef) (THIS) PURE;
STDMETHOD_(ULONG,Release) (THIS) PURE;
/*** IDirectSound methods ***/
STDMETHOD( CreateSoundBuffer)(THIS_ LPDSBUFFERDESC, LPLPDIRECTSOUNDBUFFER, IUnknown FAR *) PURE;
STDMETHOD( GetCaps)(THIS_ LPDSCAPS ) PURE;
STDMETHOD( DuplicateSoundBuffer)(THIS_ LPDIRECTSOUNDBUFFER, LPLPDIRECTSOUNDBUFFER ) PURE;
STDMETHOD( SetCooperativeLevel)(THIS_ HWND, DWORD ) PURE;
STDMETHOD( Compact)(THIS ) PURE;
STDMETHOD( GetSpeakerConfig)(THIS_ LPDWORD ) PURE;
STDMETHOD( SetSpeakerConfig)(THIS_ DWORD ) PURE;
STDMETHOD( Initialize)(THIS_ GUID FAR * ) PURE;
};
#if !defined(__cplusplus) || defined(CINTERFACE)
#define IDirectSound_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
#define IDirectSound_AddRef(p) (p)->lpVtbl->AddRef(p)
#define IDirectSound_Release(p) (p)->lpVtbl->Release(p)
#define IDirectSound_CreateSoundBuffer(p,a,b,c) (p)->lpVtbl->CreateSoundBuffer(p,a,b,c)
#define IDirectSound_GetCaps(p,a) (p)->lpVtbl->GetCaps(p,a)
#define IDirectSound_DuplicateSoundBuffer(p,a,b) (p)->lpVtbl->DuplicateSoundBuffer(p,a,b)
#define IDirectSound_SetCooperativeLevel(p,a,b) (p)->lpVtbl->SetCooperativeLevel(p,a,b)
#define IDirectSound_Compact(p) (p)->lpVtbl->Compact(p)
#define IDirectSound_GetSpeakerConfig(p,a) (p)->lpVtbl->GetSpeakerConfig(p,a)
#define IDirectSound_SetSpeakerConfig(p,b) (p)->lpVtbl->SetSpeakerConfig(p,b)
#define IDirectSound_Initialize(p,a) (p)->lpVtbl->Initialize(p,a)
#endif
#endif
//
// IDirectSoundBuffer
//
#undef INTERFACE
#define INTERFACE IDirectSoundBuffer
#ifdef _WIN32
DECLARE_INTERFACE_( IDirectSoundBuffer, IUnknown )
{
/*** IUnknown methods ***/
STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID * ppvObj) PURE;
STDMETHOD_(ULONG,AddRef) (THIS) PURE;
STDMETHOD_(ULONG,Release) (THIS) PURE;
/*** IDirectSoundBuffer methods ***/
STDMETHOD( GetCaps)(THIS_ LPDSBCAPS ) PURE;
STDMETHOD(GetCurrentPosition)(THIS_ LPDWORD,LPDWORD ) PURE;
STDMETHOD( GetFormat)(THIS_ LPWAVEFORMATEX, DWORD, LPDWORD ) PURE;
STDMETHOD( GetVolume)(THIS_ LPLONG ) PURE;
STDMETHOD( GetPan)(THIS_ LPLONG ) PURE;
STDMETHOD( GetFrequency)(THIS_ LPDWORD ) PURE;
STDMETHOD( GetStatus)(THIS_ LPDWORD ) PURE;
STDMETHOD( Initialize)(THIS_ LPDIRECTSOUND, LPDSBUFFERDESC ) PURE;
STDMETHOD( Lock)(THIS_ DWORD,DWORD,LPVOID,LPDWORD,LPVOID,LPDWORD,DWORD ) PURE;
STDMETHOD( Play)(THIS_ DWORD,DWORD,DWORD ) PURE;
STDMETHOD(SetCurrentPosition)(THIS_ DWORD ) PURE;
STDMETHOD( SetFormat)(THIS_ LPWAVEFORMATEX ) PURE;
STDMETHOD( SetVolume)(THIS_ LONG ) PURE;
STDMETHOD( SetPan)(THIS_ LONG ) PURE;
STDMETHOD( SetFrequency)(THIS_ DWORD ) PURE;
STDMETHOD( Stop)(THIS ) PURE;
STDMETHOD( Unlock)(THIS_ LPVOID,DWORD,LPVOID,DWORD ) PURE;
STDMETHOD( Restore)(THIS ) PURE;
};
#if !defined(__cplusplus) || defined(CINTERFACE)
#define IDirectSoundBuffer_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
#define IDirectSoundBuffer_AddRef(p) (p)->lpVtbl->AddRef(p)
#define IDirectSoundBuffer_Release(p) (p)->lpVtbl->Release(p)
#define IDirectSoundBuffer_GetCaps(p,a) (p)->lpVtbl->GetCaps(p,a)
#define IDirectSoundBuffer_GetCurrentPosition(p,a,b) (p)->lpVtbl->GetCurrentPosition(p,a,b)
#define IDirectSoundBuffer_GetFormat(p,a,b,c) (p)->lpVtbl->GetFormat(p,a,b,c)
#define IDirectSoundBuffer_GetVolume(p,a) (p)->lpVtbl->GetVolume(p,a)
#define IDirectSoundBuffer_GetPan(p,a) (p)->lpVtbl->GetPan(p,a)
#define IDirectSoundBuffer_GetFrequency(p,a) (p)->lpVtbl->GetFrequency(p,a)
#define IDirectSoundBuffer_GetStatus(p,a) (p)->lpVtbl->GetStatus(p,a)
#define IDirectSoundBuffer_Initialize(p,a,b) (p)->lpVtbl->Initialize(p,a,b)
#define IDirectSoundBuffer_Lock(p,a,b,c,d,e,f,g) (p)->lpVtbl->Lock(p,a,b,c,d,e,f,g)
#define IDirectSoundBuffer_Play(p,a,b,c) (p)->lpVtbl->Play(p,a,b,c)
#define IDirectSoundBuffer_SetCurrentPosition(p,a) (p)->lpVtbl->SetCurrentPosition(p,a)
#define IDirectSoundBuffer_SetFormat(p,a) (p)->lpVtbl->SetFormat(p,a)
#define IDirectSoundBuffer_SetVolume(p,a) (p)->lpVtbl->SetVolume(p,a)
#define IDirectSoundBuffer_SetPan(p,a) (p)->lpVtbl->SetPan(p,a)
#define IDirectSoundBuffer_SetFrequency(p,a) (p)->lpVtbl->SetFrequency(p,a)
#define IDirectSoundBuffer_Stop(p) (p)->lpVtbl->Stop(p)
#define IDirectSoundBuffer_Unlock(p,a,b,c,d) (p)->lpVtbl->Unlock(p,a,b,c,d)
#define IDirectSoundBuffer_Restore(p) (p)->lpVtbl->Restore(p)
#endif
#endif
/*
* Return Codes
*/
#define DS_OK 0
/*
* The call failed because resources (such as a priority level)
* were already being used by another caller.
*/
#define DSERR_ALLOCATED MAKE_DSHRESULT( 10 )
/*
* The control (vol,pan,etc.) requested by the caller is not available.
*/
#define DSERR_CONTROLUNAVAIL MAKE_DSHRESULT( 30 )
/*
* An invalid parameter was passed to the returning function
*/
#define DSERR_INVALIDPARAM E_INVALIDARG
/*
* This call is not valid for the current state of this object
*/
#define DSERR_INVALIDCALL MAKE_DSHRESULT( 50 )
/*
* An undetermined error occured inside the DSound subsystem
*/
#define DSERR_GENERIC E_FAIL
/*
* The caller does not have the priority level required for the function to
* succeed.
*/
#define DSERR_PRIOLEVELNEEDED MAKE_DSHRESULT( 70 )
/*
* The DSound subsystem couldn't allocate sufficient memory to complete the
* caller's request.
*/
#define DSERR_OUTOFMEMORY E_OUTOFMEMORY
/*
* The specified WAVE format is not supported
*/
#define DSERR_BADFORMAT MAKE_DSHRESULT( 100 )
/*
* The function called is not supported at this time
*/
#define DSERR_UNSUPPORTED E_NOTIMPL
/*
* No sound driver is available for use
*/
#define DSERR_NODRIVER MAKE_DSHRESULT( 120 )
/*
* This object is already initialized
*/
#define DSERR_ALREADYINITIALIZED MAKE_DSHRESULT( 130 )
/*
* This object does not support aggregation
*/
#define DSERR_NOAGGREGATION CLASS_E_NOAGGREGATION
/*
* The buffer memory has been lost, and must be Restored.
*/
#define DSERR_BUFFERLOST MAKE_DSHRESULT( 150 )
/*
* Another app has a higher priority level, preventing this call from
* succeeding.
*/
#define DSERR_OTHERAPPHASPRIO MAKE_DSHRESULT( 160 )
/*
* The Initialize() member on the Direct Sound Object has not been
* called or called successfully before calls to other members.
*/
#define DSERR_UNINITIALIZED MAKE_DSHRESULT( 170 )
//==========================================================================;
//
// Flags...
//
//==========================================================================;
#define DSCAPS_PRIMARYMONO 0x00000001
#define DSCAPS_PRIMARYSTEREO 0x00000002
#define DSCAPS_PRIMARY8BIT 0x00000004
#define DSCAPS_PRIMARY16BIT 0x00000008
#define DSCAPS_CONTINUOUSRATE 0x00000010
#define DSCAPS_EMULDRIVER 0x00000020
#define DSCAPS_CERTIFIED 0x00000040
#define DSCAPS_SECONDARYMONO 0x00000100
#define DSCAPS_SECONDARYSTEREO 0x00000200
#define DSCAPS_SECONDARY8BIT 0x00000400
#define DSCAPS_SECONDARY16BIT 0x00000800
#define DSBPLAY_LOOPING 0x00000001
#define DSBSTATUS_PLAYING 0x00000001
#define DSBSTATUS_BUFFERLOST 0x00000002
#define DSBSTATUS_LOOPING 0x00000004
#define DSBLOCK_FROMWRITECURSOR 0x00000001
#define DSSCL_NORMAL 1
#define DSSCL_PRIORITY 2
#define DSSCL_EXCLUSIVE 3
#define DSSCL_WRITEPRIMARY 4
#define DSBCAPS_PRIMARYBUFFER 0x00000001
#define DSBCAPS_STATIC 0x00000002
#define DSBCAPS_LOCHARDWARE 0x00000004
#define DSBCAPS_LOCSOFTWARE 0x00000008
#define DSBCAPS_CTRLFREQUENCY 0x00000020
#define DSBCAPS_CTRLPAN 0x00000040
#define DSBCAPS_CTRLVOLUME 0x00000080
#define DSBCAPS_CTRLDEFAULT 0x000000E0 // Pan + volume + frequency.
#define DSBCAPS_CTRLALL 0x000000E0 // All control capabilities
#define DSBCAPS_STICKYFOCUS 0x00004000
#define DSBCAPS_GETCURRENTPOSITION2 0x00010000 // More accurate play cursor under emulation
#define DSSPEAKER_HEADPHONE 1
#define DSSPEAKER_MONO 2
#define DSSPEAKER_QUAD 3
#define DSSPEAKER_STEREO 4
#define DSSPEAKER_SURROUND 5
#ifdef __cplusplus
};
#endif
#endif /* __DSOUND_INCLUDED__ */
| 13,051 | C | .h | 301 | 40.950166 | 107 | 0.664271 | headcrab-junkyard/OGS | 98 | 13 | 0 | GPL-3.0 | 9/7/2024, 9:44:18 AM (Europe/Amsterdam) | true | false | false | true | true | true | false | false |
1,397,147 | dinput.h | headcrab-junkyard_OGS/legacy/dxsdk/sdk/inc/dinput.h | /****************************************************************************
*
* Copyright (C) 1996 Microsoft Corporation. All Rights Reserved.
*
* File: dinput.h
* Content: DirectInput include file
*
****************************************************************************/
#ifndef __DINPUT_INCLUDED__
#define __DINPUT_INCLUDED__
#ifdef _WIN32
#define COM_NO_WINDOWS_H
#include <objbase.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define DIRECTINPUT_VERSION 0x0300
/****************************************************************************
*
* Class IDs
*
****************************************************************************/
DEFINE_GUID(CLSID_DirectInput, 0x25E609E0,0xB259,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(CLSID_DirectInputDevice,0x25E609E1,0xB259,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
/****************************************************************************
*
* Interfaces
*
****************************************************************************/
DEFINE_GUID(IID_IDirectInputA, 0x89521360,0xAA8A,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(IID_IDirectInputW, 0x89521361,0xAA8A,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(IID_IDirectInputDeviceA,0x5944E680,0xC92E,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(IID_IDirectInputDeviceW,0x5944E681,0xC92E,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
/****************************************************************************
*
* Predefined object types
*
****************************************************************************/
DEFINE_GUID(GUID_XAxis, 0xA36D02E0,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(GUID_YAxis, 0xA36D02E1,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(GUID_ZAxis, 0xA36D02E2,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(GUID_RAxis, 0xA36D02E3,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(GUID_UAxis, 0xA36D02E4,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(GUID_VAxis, 0xA36D02E5,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(GUID_Button, 0xA36D02F0,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(GUID_Key, 0x55728220,0xD33C,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(GUID_POV, 0xA36D02F2,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
/****************************************************************************
*
* Predefined product GUIDs
*
****************************************************************************/
DEFINE_GUID(GUID_SysMouse, 0x6F1D2B60,0xD5A0,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(GUID_SysKeyboard,0x6F1D2B61,0xD5A0,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
/****************************************************************************
*
* Interfaces and Structures...
*
****************************************************************************/
/****************************************************************************
*
* IDirectInputDevice
*
****************************************************************************/
#define DIDEVTYPE_DEVICE 1
#define DIDEVTYPE_MOUSE 2
#define DIDEVTYPE_KEYBOARD 3
#define DIDEVTYPE_JOYSTICK 4
#define DIDEVTYPEMOUSE_UNKNOWN 1
#define DIDEVTYPEMOUSE_TRADITIONAL 2
#define DIDEVTYPEMOUSE_FINGERSTICK 3
#define DIDEVTYPEMOUSE_TOUCHPAD 4
#define DIDEVTYPEMOUSE_TRACKBALL 5
#define DIDEVTYPEKEYBOARD_PCXT 1
#define DIDEVTYPEKEYBOARD_OLIVETTI 2
#define DIDEVTYPEKEYBOARD_PCAT 3
#define DIDEVTYPEKEYBOARD_PCENH 4
#define DIDEVTYPEKEYBOARD_NOKIA1050 5
#define DIDEVTYPEKEYBOARD_NOKIA9140 6
#define DIDEVTYPEKEYBOARD_NEC98 7
#define DIDEVTYPEKEYBOARD_NEC98LAPTOP 8
#define DIDEVTYPEKEYBOARD_NEC98106 9
#define DIDEVTYPEKEYBOARD_JAPAN106 10
#define DIDEVTYPEKEYBOARD_JAPANAX 11
#define DIDEVTYPEKEYBOARD_J3100 12
#define GET_DIDEVICE_TYPE(dwDevType) LOBYTE(dwDevType)
#define GET_DIDEVICE_SUBTYPE(dwDevType) HIBYTE(dwDevType)
typedef struct _DIDEVCAPS {
DWORD dwSize;
DWORD dwFlags;
DWORD dwDevType;
DWORD dwAxes;
DWORD dwButtons;
DWORD dwPOVs;
} DIDEVCAPS, *LPDIDEVCAPS;
#define DIDC_ATTACHED 0x00000001
#define DIDC_POLLEDDEVICE 0x00000002
#define DIDFT_ALL 0x00000000
#define DIDFT_RELAXIS 0x00000001
#define DIDFT_ABSAXIS 0x00000002
#define DIDFT_AXIS 0x00000003
#define DIDFT_PSHBUTTON 0x00000004
#define DIDFT_TGLBUTTON 0x00000008
#define DIDFT_BUTTON 0x0000000C
#define DIDFT_POV 0x00000010
#define DIDFT_ANYINSTANCE 0x0000FF00
#define DIDFT_MAKEINSTANCE(n) ((BYTE)(n) << 8)
#define DIDFT_GETTYPE(n) LOBYTE(n)
#define DIDFT_GETINSTANCE(n) HIBYTE(n)
typedef struct _DIOBJECTDATAFORMAT {
const GUID *pguid;
DWORD dwOfs;
DWORD dwType;
DWORD dwFlags;
} DIOBJECTDATAFORMAT, *LPDIOBJECTDATAFORMAT;
typedef const DIOBJECTDATAFORMAT *LPCDIOBJECTDATAFORMAT;
typedef struct _DIDATAFORMAT {
DWORD dwSize;
DWORD dwObjSize;
DWORD dwFlags;
DWORD dwDataSize;
DWORD dwNumObjs;
LPDIOBJECTDATAFORMAT rgodf;
} DIDATAFORMAT, *LPDIDATAFORMAT;
typedef const DIDATAFORMAT *LPCDIDATAFORMAT;
#define DIDF_ABSAXIS 0x00000001
#define DIDF_RELAXIS 0x00000002
extern const DIDATAFORMAT c_dfDIMouse;
extern const DIDATAFORMAT c_dfDIKeyboard;
typedef struct DIDEVICEOBJECTINSTANCEA {
DWORD dwSize;
GUID guidType;
DWORD dwOfs;
DWORD dwType;
DWORD dwFlags;
CHAR tszName[MAX_PATH];
} DIDEVICEOBJECTINSTANCEA, *LPDIDEVICEOBJECTINSTANCEA;
typedef struct DIDEVICEOBJECTINSTANCEW {
DWORD dwSize;
GUID guidType;
DWORD dwOfs;
DWORD dwType;
DWORD dwFlags;
WCHAR tszName[MAX_PATH];
} DIDEVICEOBJECTINSTANCEW, *LPDIDEVICEOBJECTINSTANCEW;
#ifdef UNICODE
typedef DIDEVICEOBJECTINSTANCEW DIDEVICEOBJECTINSTANCE;
typedef LPDIDEVICEOBJECTINSTANCEW LPDIDEVICEOBJECTINSTANCE;
#else
typedef DIDEVICEOBJECTINSTANCEA DIDEVICEOBJECTINSTANCE;
typedef LPDIDEVICEOBJECTINSTANCEA LPDIDEVICEOBJECTINSTANCE;
#endif // UNICODE
typedef const DIDEVICEOBJECTINSTANCEA *LPCDIDEVICEOBJECTINSTANCEA;
typedef const DIDEVICEOBJECTINSTANCEW *LPCDIDEVICEOBJECTINSTANCEW;
typedef const DIDEVICEOBJECTINSTANCE *LPCDIDEVICEOBJECTINSTANCE;
typedef BOOL (FAR PASCAL * LPDIENUMDEVICEOBJECTSCALLBACKA)(LPCDIDEVICEOBJECTINSTANCEA, LPVOID);
typedef BOOL (FAR PASCAL * LPDIENUMDEVICEOBJECTSCALLBACKW)(LPCDIDEVICEOBJECTINSTANCEW, LPVOID);
#ifdef UNICODE
#define LPDIENUMDEVICEOBJECTSCALLBACK LPDIENUMDEVICEOBJECTSCALLBACKW
#else
#define LPDIENUMDEVICEOBJECTSCALLBACK LPDIENUMDEVICEOBJECTSCALLBACKA
#endif // !UNICODE
typedef struct DIPROPHEADER {
DWORD dwSize;
DWORD dwHeaderSize;
DWORD dwObj;
DWORD dwHow;
} DIPROPHEADER, *LPDIPROPHEADER;
typedef const DIPROPHEADER *LPCDIPROPHEADER;
#define DIPH_DEVICE 0
#define DIPH_BYOFFSET 1
#define DIPH_BYID 2
typedef struct DIPROPDWORD {
DIPROPHEADER diph;
DWORD dwData;
} DIPROPDWORD, *LPDIPROPDWORD;
typedef const DIPROPDWORD *LPCDIPROPDWORD;
typedef struct DIPROPRANGE {
DIPROPHEADER diph;
LONG lMin;
LONG lMax;
} DIPROPRANGE, *LPDIPROPRANGE;
typedef const DIPROPRANGE *LPCDIPROPRANGE;
#define DIPROPRANGE_NOMIN ((LONG)0x80000000)
#define DIPROPRANGE_NOMAX ((LONG)0x7FFFFFFF)
#ifdef __cplusplus
#define MAKEDIPROP(prop) (*(const GUID *)(prop))
#else
#define MAKEDIPROP(prop) ((REFGUID)(prop))
#endif
#define DIPROP_BUFFERSIZE MAKEDIPROP(1)
#define DIPROP_AXISMODE MAKEDIPROP(2)
#define DIPROPAXISMODE_ABS 0
#define DIPROPAXISMODE_REL 1
#define DIPROP_GRANULARITY MAKEDIPROP(3)
#define DIPROP_RANGE MAKEDIPROP(4)
typedef struct DIDEVICEOBJECTDATA {
DWORD dwOfs;
DWORD dwData;
DWORD dwTimeStamp;
DWORD dwSequence;
} DIDEVICEOBJECTDATA, *LPDIDEVICEOBJECTDATA;
#define DIGDD_PEEK 0x00000001
#define DISEQUENCE_COMPARE(dwSequence1, cmp, dwSequence2) \
((int)((dwSequence1) - (dwSequence2)) cmp 0)
#define DISCL_EXCLUSIVE 0x00000001
#define DISCL_NONEXCLUSIVE 0x00000002
#define DISCL_FOREGROUND 0x00000004
#define DISCL_BACKGROUND 0x00000008
typedef struct DIDEVICEINSTANCEA {
DWORD dwSize;
GUID guidInstance;
GUID guidProduct;
DWORD dwDevType;
CHAR tszInstanceName[MAX_PATH];
CHAR tszProductName[MAX_PATH];
} DIDEVICEINSTANCEA, *LPDIDEVICEINSTANCEA;
typedef struct DIDEVICEINSTANCEW {
DWORD dwSize;
GUID guidInstance;
GUID guidProduct;
DWORD dwDevType;
WCHAR tszInstanceName[MAX_PATH];
WCHAR tszProductName[MAX_PATH];
} DIDEVICEINSTANCEW, *LPDIDEVICEINSTANCEW;
#ifdef UNICODE
typedef DIDEVICEINSTANCEW DIDEVICEINSTANCE;
typedef LPDIDEVICEINSTANCEW LPDIDEVICEINSTANCE;
#else
typedef DIDEVICEINSTANCEA DIDEVICEINSTANCE;
typedef LPDIDEVICEINSTANCEA LPDIDEVICEINSTANCE;
#endif // UNICODE
typedef const DIDEVICEINSTANCEA *LPCDIDEVICEINSTANCEA;
typedef const DIDEVICEINSTANCEW *LPCDIDEVICEINSTANCEW;
typedef const DIDEVICEINSTANCE *LPCDIDEVICEINSTANCE;
#undef INTERFACE
#define INTERFACE IDirectInputDeviceW
DECLARE_INTERFACE_(IDirectInputDeviceW, IUnknown)
{
/*** IUnknown methods ***/
STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
STDMETHOD_(ULONG,Release)(THIS) PURE;
/*** IDirectInputDeviceW methods ***/
STDMETHOD(GetCapabilities)(THIS_ LPDIDEVCAPS) PURE;
STDMETHOD(EnumObjects)(THIS_ LPDIENUMDEVICEOBJECTSCALLBACKW,LPVOID,DWORD) PURE;
STDMETHOD(GetProperty)(THIS_ REFGUID,LPDIPROPHEADER) PURE;
STDMETHOD(SetProperty)(THIS_ REFGUID,LPCDIPROPHEADER) PURE;
STDMETHOD(Acquire)(THIS) PURE;
STDMETHOD(Unacquire)(THIS) PURE;
STDMETHOD(GetDeviceState)(THIS_ DWORD,LPVOID) PURE;
STDMETHOD(GetDeviceData)(THIS_ DWORD,LPDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
STDMETHOD(SetDataFormat)(THIS_ LPCDIDATAFORMAT) PURE;
STDMETHOD(SetEventNotification)(THIS_ HANDLE) PURE;
STDMETHOD(SetCooperativeLevel)(THIS_ HWND,DWORD) PURE;
STDMETHOD(GetObjectInfo)(THIS_ LPDIDEVICEOBJECTINSTANCEW,DWORD,DWORD) PURE;
STDMETHOD(GetDeviceInfo)(THIS_ LPDIDEVICEINSTANCEW) PURE;
STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD,REFGUID) PURE;
};
typedef struct IDirectInputDeviceW *LPDIRECTINPUTDEVICEW;
#undef INTERFACE
#define INTERFACE IDirectInputDeviceA
DECLARE_INTERFACE_(IDirectInputDeviceA, IUnknown)
{
/*** IUnknown methods ***/
STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
STDMETHOD_(ULONG,Release)(THIS) PURE;
/*** IDirectInputDeviceA methods ***/
STDMETHOD(GetCapabilities)(THIS_ LPDIDEVCAPS) PURE;
STDMETHOD(EnumObjects)(THIS_ LPDIENUMDEVICEOBJECTSCALLBACKA,LPVOID,DWORD) PURE;
STDMETHOD(GetProperty)(THIS_ REFGUID,LPDIPROPHEADER) PURE;
STDMETHOD(SetProperty)(THIS_ REFGUID,LPCDIPROPHEADER) PURE;
STDMETHOD(Acquire)(THIS) PURE;
STDMETHOD(Unacquire)(THIS) PURE;
STDMETHOD(GetDeviceState)(THIS_ DWORD,LPVOID) PURE;
STDMETHOD(GetDeviceData)(THIS_ DWORD,LPDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
STDMETHOD(SetDataFormat)(THIS_ LPCDIDATAFORMAT) PURE;
STDMETHOD(SetEventNotification)(THIS_ HANDLE) PURE;
STDMETHOD(SetCooperativeLevel)(THIS_ HWND,DWORD) PURE;
STDMETHOD(GetObjectInfo)(THIS_ LPDIDEVICEOBJECTINSTANCEA,DWORD,DWORD) PURE;
STDMETHOD(GetDeviceInfo)(THIS_ LPDIDEVICEINSTANCEA) PURE;
STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD,REFGUID) PURE;
};
typedef struct IDirectInputDeviceA *LPDIRECTINPUTDEVICEA;
#ifdef UNICODE
#define IID_IDirectInputDevice IID_IDirectInputDeviceW
#define IDirectInputDevice IDirectInputDeviceW
#define IDirectInputDeviceVtbl IDirectInputDeviceWVtbl
#else
#define IID_IDirectInputDevice IID_IDirectInputDeviceA
#define IDirectInputDevice IDirectInputDeviceA
#define IDirectInputDeviceVtbl IDirectInputDeviceAVtbl
#endif
typedef struct IDirectInputDevice *LPDIRECTINPUTDEVICE;
#if !defined(__cplusplus) || defined(CINTERFACE)
#define IDirectInputDevice_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
#define IDirectInputDevice_AddRef(p) (p)->lpVtbl->AddRef(p)
#define IDirectInputDevice_Release(p) (p)->lpVtbl->Release(p)
#define IDirectInputDevice_GetCapabilities(p,a) (p)->lpVtbl->GetCapabilities(p,a)
#define IDirectInputDevice_EnumObjects(p,a,b,c) (p)->lpVtbl->EnumObjects(p,a,b,c)
#define IDirectInputDevice_GetProperty(p,a,b) (p)->lpVtbl->GetProperty(p,a,b)
#define IDirectInputDevice_SetProperty(p,a,b) (p)->lpVtbl->SetProperty(p,a,b)
#define IDirectInputDevice_Acquire(p) (p)->lpVtbl->Acquire(p)
#define IDirectInputDevice_Unacquire(p) (p)->lpVtbl->Unacquire(p)
#define IDirectInputDevice_GetDeviceState(p,a,b) (p)->lpVtbl->GetDeviceState(p,a,b)
#define IDirectInputDevice_GetDeviceData(p,a,b,c,d) (p)->lpVtbl->GetDeviceData(p,a,b,c,d)
#define IDirectInputDevice_SetDataFormat(p,a) (p)->lpVtbl->SetDataFormat(p,a)
#define IDirectInputDevice_SetEventNotification(p,a) (p)->lpVtbl->SetEventNotification(p,a)
#define IDirectInputDevice_SetCooperativeLevel(p,a,b) (p)->lpVtbl->SetCooperativeLevel(p,a,b)
#define IDirectInputDevice_GetObjectInfo(p,a,b,c) (p)->lpVtbl->GetObjectInfo(p,a,b,c)
#define IDirectInputDevice_GetDeviceInfo(p,a) (p)->lpVtbl->GetDeviceInfo(p,a)
#define IDirectInputDevice_RunControlPanel(p,a,b) (p)->lpVtbl->RunControlPanel(p,a,b)
#define IDirectInputDevice_Initialize(p,a,b,c) (p)->lpVtbl->Initialize(p,a,b,c)
#endif
/****************************************************************************
*
* Mouse
*
****************************************************************************/
typedef struct _DIMOUSESTATE {
LONG lX;
LONG lY;
LONG lZ;
BYTE rgbButtons[4];
} DIMOUSESTATE, *LPDIMOUSESTATE;
#define DIMOFS_X FIELD_OFFSET(DIMOUSESTATE, lX)
#define DIMOFS_Y FIELD_OFFSET(DIMOUSESTATE, lY)
#define DIMOFS_Z FIELD_OFFSET(DIMOUSESTATE, lZ)
#define DIMOFS_BUTTON0 (FIELD_OFFSET(DIMOUSESTATE, rgbButtons) + 0)
#define DIMOFS_BUTTON1 (FIELD_OFFSET(DIMOUSESTATE, rgbButtons) + 1)
#define DIMOFS_BUTTON2 (FIELD_OFFSET(DIMOUSESTATE, rgbButtons) + 2)
#define DIMOFS_BUTTON3 (FIELD_OFFSET(DIMOUSESTATE, rgbButtons) + 3)
/****************************************************************************
*
* Keyboard
*
****************************************************************************/
/****************************************************************************
*
* DirectInput keyboard scan codes
*
****************************************************************************/
#define DIK_ESCAPE 0x01
#define DIK_1 0x02
#define DIK_2 0x03
#define DIK_3 0x04
#define DIK_4 0x05
#define DIK_5 0x06
#define DIK_6 0x07
#define DIK_7 0x08
#define DIK_8 0x09
#define DIK_9 0x0A
#define DIK_0 0x0B
#define DIK_MINUS 0x0C /* - on main keyboard */
#define DIK_EQUALS 0x0D
#define DIK_BACK 0x0E /* backspace */
#define DIK_TAB 0x0F
#define DIK_Q 0x10
#define DIK_W 0x11
#define DIK_E 0x12
#define DIK_R 0x13
#define DIK_T 0x14
#define DIK_Y 0x15
#define DIK_U 0x16
#define DIK_I 0x17
#define DIK_O 0x18
#define DIK_P 0x19
#define DIK_LBRACKET 0x1A
#define DIK_RBRACKET 0x1B
#define DIK_RETURN 0x1C /* Enter on main keyboard */
#define DIK_LCONTROL 0x1D
#define DIK_A 0x1E
#define DIK_S 0x1F
#define DIK_D 0x20
#define DIK_F 0x21
#define DIK_G 0x22
#define DIK_H 0x23
#define DIK_J 0x24
#define DIK_K 0x25
#define DIK_L 0x26
#define DIK_SEMICOLON 0x27
#define DIK_APOSTROPHE 0x28
#define DIK_GRAVE 0x29 /* accent grave */
#define DIK_LSHIFT 0x2A
#define DIK_BACKSLASH 0x2B
#define DIK_Z 0x2C
#define DIK_X 0x2D
#define DIK_C 0x2E
#define DIK_V 0x2F
#define DIK_B 0x30
#define DIK_N 0x31
#define DIK_M 0x32
#define DIK_COMMA 0x33
#define DIK_PERIOD 0x34 /* . on main keyboard */
#define DIK_SLASH 0x35 /* / on main keyboard */
#define DIK_RSHIFT 0x36
#define DIK_MULTIPLY 0x37 /* * on numeric keypad */
#define DIK_LMENU 0x38 /* left Alt */
#define DIK_SPACE 0x39
#define DIK_CAPITAL 0x3A
#define DIK_F1 0x3B
#define DIK_F2 0x3C
#define DIK_F3 0x3D
#define DIK_F4 0x3E
#define DIK_F5 0x3F
#define DIK_F6 0x40
#define DIK_F7 0x41
#define DIK_F8 0x42
#define DIK_F9 0x43
#define DIK_F10 0x44
#define DIK_NUMLOCK 0x45
#define DIK_SCROLL 0x46 /* Scroll Lock */
#define DIK_NUMPAD7 0x47
#define DIK_NUMPAD8 0x48
#define DIK_NUMPAD9 0x49
#define DIK_SUBTRACT 0x4A /* - on numeric keypad */
#define DIK_NUMPAD4 0x4B
#define DIK_NUMPAD5 0x4C
#define DIK_NUMPAD6 0x4D
#define DIK_ADD 0x4E /* + on numeric keypad */
#define DIK_NUMPAD1 0x4F
#define DIK_NUMPAD2 0x50
#define DIK_NUMPAD3 0x51
#define DIK_NUMPAD0 0x52
#define DIK_DECIMAL 0x53 /* . on numeric keypad */
#define DIK_F11 0x57
#define DIK_F12 0x58
#define DIK_F13 0x64 /* (NEC PC98) */
#define DIK_F14 0x65 /* (NEC PC98) */
#define DIK_F15 0x66 /* (NEC PC98) */
#define DIK_KANA 0x70 /* (Japanese keyboard) */
#define DIK_CONVERT 0x79 /* (Japanese keyboard) */
#define DIK_NOCONVERT 0x7B /* (Japanese keyboard) */
#define DIK_YEN 0x7D /* (Japanese keyboard) */
#define DIK_NUMPADEQUALS 0x8D /* = on numeric keypad (NEC PC98) */
#define DIK_CIRCUMFLEX 0x90 /* (Japanese keyboard) */
#define DIK_AT 0x91 /* (NEC PC98) */
#define DIK_COLON 0x92 /* (NEC PC98) */
#define DIK_UNDERLINE 0x93 /* (NEC PC98) */
#define DIK_KANJI 0x94 /* (Japanese keyboard) */
#define DIK_STOP 0x95 /* (NEC PC98) */
#define DIK_AX 0x96 /* (Japan AX) */
#define DIK_UNLABELED 0x97 /* (J3100) */
#define DIK_NUMPADENTER 0x9C /* Enter on numeric keypad */
#define DIK_RCONTROL 0x9D
#define DIK_NUMPADCOMMA 0xB3 /* , on numeric keypad (NEC PC98) */
#define DIK_DIVIDE 0xB5 /* / on numeric keypad */
#define DIK_SYSRQ 0xB7
#define DIK_RMENU 0xB8 /* right Alt */
#define DIK_HOME 0xC7 /* Home on arrow keypad */
#define DIK_UP 0xC8 /* UpArrow on arrow keypad */
#define DIK_PRIOR 0xC9 /* PgUp on arrow keypad */
#define DIK_LEFT 0xCB /* LeftArrow on arrow keypad */
#define DIK_RIGHT 0xCD /* RightArrow on arrow keypad */
#define DIK_END 0xCF /* End on arrow keypad */
#define DIK_DOWN 0xD0 /* DownArrow on arrow keypad */
#define DIK_NEXT 0xD1 /* PgDn on arrow keypad */
#define DIK_INSERT 0xD2 /* Insert on arrow keypad */
#define DIK_DELETE 0xD3 /* Delete on arrow keypad */
#define DIK_LWIN 0xDB /* Left Windows key */
#define DIK_RWIN 0xDC /* Right Windows key */
#define DIK_APPS 0xDD /* AppMenu key */
/*
* Alternate names for keys, to facilitate transition from DOS.
*/
#define DIK_BACKSPACE DIK_BACK /* backspace */
#define DIK_NUMPADSTAR DIK_MULTIPLY /* * on numeric keypad */
#define DIK_LALT DIK_LMENU /* left Alt */
#define DIK_CAPSLOCK DIK_CAPITAL /* CapsLock */
#define DIK_NUMPADMINUS DIK_SUBTRACT /* - on numeric keypad */
#define DIK_NUMPADPLUS DIK_ADD /* + on numeric keypad */
#define DIK_NUMPADPERIOD DIK_DECIMAL /* . on numeric keypad */
#define DIK_NUMPADSLASH DIK_DIVIDE /* / on numeric keypad */
#define DIK_RALT DIK_RMENU /* right Alt */
#define DIK_UPARROW DIK_UP /* UpArrow on arrow keypad */
#define DIK_PGUP DIK_PRIOR /* PgUp on arrow keypad */
#define DIK_LEFTARROW DIK_LEFT /* LeftArrow on arrow keypad */
#define DIK_RIGHTARROW DIK_RIGHT /* RightArrow on arrow keypad */
#define DIK_DOWNARROW DIK_DOWN /* DownArrow on arrow keypad */
#define DIK_PGDN DIK_NEXT /* PgDn on arrow keypad */
/****************************************************************************
*
* IDirectInput
*
****************************************************************************/
#define DIENUM_STOP 0
#define DIENUM_CONTINUE 1
typedef BOOL (FAR PASCAL * LPDIENUMDEVICESCALLBACKA)(LPCDIDEVICEINSTANCEA, LPVOID);
typedef BOOL (FAR PASCAL * LPDIENUMDEVICESCALLBACKW)(LPCDIDEVICEINSTANCEW, LPVOID);
#ifdef UNICODE
#define LPDIENUMDEVICESCALLBACK LPDIENUMDEVICESCALLBACKW
#else
#define LPDIENUMDEVICESCALLBACK LPDIENUMDEVICESCALLBACKA
#endif // !UNICODE
#define DIEDFL_ALLDEVICES 0x00000000
#define DIEDFL_ATTACHEDONLY 0x00000001
#undef INTERFACE
#define INTERFACE IDirectInputW
DECLARE_INTERFACE_(IDirectInputW, IUnknown)
{
/*** IUnknown methods ***/
STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
STDMETHOD_(ULONG,Release)(THIS) PURE;
/*** IDirectInputW methods ***/
STDMETHOD(CreateDevice)(THIS_ REFGUID,LPDIRECTINPUTDEVICEW *,LPUNKNOWN) PURE;
STDMETHOD(EnumDevices)(THIS_ DWORD,LPDIENUMDEVICESCALLBACKW,LPVOID,DWORD) PURE;
STDMETHOD(GetDeviceStatus)(THIS_ REFGUID) PURE;
STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD) PURE;
};
typedef struct IDirectInputW *LPDIRECTINPUTW;
#undef INTERFACE
#define INTERFACE IDirectInputA
DECLARE_INTERFACE_(IDirectInputA, IUnknown)
{
/*** IUnknown methods ***/
STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
STDMETHOD_(ULONG,Release)(THIS) PURE;
/*** IDirectInputA methods ***/
STDMETHOD(CreateDevice)(THIS_ REFGUID,LPDIRECTINPUTDEVICEA *,LPUNKNOWN) PURE;
STDMETHOD(EnumDevices)(THIS_ DWORD,LPDIENUMDEVICESCALLBACKA,LPVOID,DWORD) PURE;
STDMETHOD(GetDeviceStatus)(THIS_ REFGUID) PURE;
STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD) PURE;
};
typedef struct IDirectInputA *LPDIRECTINPUTA;
#ifdef UNICODE
#define IID_IDirectInput IID_IDirectInputW
#define IDirectInput IDirectInputW
#define IDirectInputVtbl IDirectInputWVtbl
#else
#define IID_IDirectInput IID_IDirectInputA
#define IDirectInput IDirectInputA
#define IDirectInputVtbl IDirectInputAVtbl
#endif
typedef struct IDirectInput *LPDIRECTINPUT;
#if !defined(__cplusplus) || defined(CINTERFACE)
#define IDirectInput_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
#define IDirectInput_AddRef(p) (p)->lpVtbl->AddRef(p)
#define IDirectInput_Release(p) (p)->lpVtbl->Release(p)
#define IDirectInput_CreateDevice(p,a,b,c) (p)->lpVtbl->CreateDevice(p,a,b,c)
#define IDirectInput_EnumDevices(p,a,b,c,d) (p)->lpVtbl->EnumDevices(p,a,b,c,d)
#define IDirectInput_GetDeviceStatus(p,a) (p)->lpVtbl->GetDeviceStatus(p,a)
#define IDirectInput_RunControlPanel(p,a,b) (p)->lpVtbl->RunControlPanel(p,a,b)
#define IDirectInput_Initialize(p,a,b) (p)->lpVtbl->Initialize(p,a,b)
#endif
extern HRESULT WINAPI DirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA *ppDI, LPUNKNOWN punkOuter);
extern HRESULT WINAPI DirectInputCreateW(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTW *ppDI, LPUNKNOWN punkOuter);
#ifdef UNICODE
#define DirectInputCreate DirectInputCreateW
#else
#define DirectInputCreate DirectInputCreateA
#endif // !UNICODE
/****************************************************************************
*
* Return Codes
*
****************************************************************************/
/*
* The operation completed successfully.
*/
#define DI_OK S_OK
/*
* The device exists but is not currently attached.
*/
#define DI_NOTATTACHED S_FALSE
/*
* The device buffer overflowed; some input was lost.
*/
#define DI_BUFFEROVERFLOW S_FALSE
/*
* The change in device properties had no effect.
*/
#define DI_PROPNOEFFECT S_FALSE
/*
* The device is a polled device. As a result, device buffering
* will not collect any data and event notifications will not be
* signalled until GetDeviceState is called.
*/
#define DI_POLLEDDEVICE ((HRESULT)0x00000002L)
/*
* The application requires a newer version of DirectInput.
*/
#define DIERR_OLDDIRECTINPUTVERSION \
MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_OLD_WIN_VERSION)
/*
* The application was written for an unsupported prerelease version
* of DirectInput.
*/
#define DIERR_BETADIRECTINPUTVERSION \
MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_RMODE_APP)
/*
* The object could not be created due to an incompatible driver version
* or mismatched or incomplete driver components.
*/
#define DIERR_BADDRIVERVER \
MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_BAD_DRIVER_LEVEL)
/*
* The device or device instance is not registered with DirectInput.
*/
#define DIERR_DEVICENOTREG REGDB_E_CLASSNOTREG
/*
* The requested object does not exist.
*/
#define DIERR_OBJECTNOTFOUND \
MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_FILE_NOT_FOUND)
/*
* An invalid parameter was passed to the returning function,
* or the object was not in a state that admitted the function
* to be called.
*/
#define DIERR_INVALIDPARAM E_INVALIDARG
/*
* The specified interface is not supported by the object
*/
#define DIERR_NOINTERFACE E_NOINTERFACE
/*
* An undetermined error occured inside the DInput subsystem
*/
#define DIERR_GENERIC E_FAIL
/*
* The DInput subsystem couldn't allocate sufficient memory to complete the
* caller's request.
*/
#define DIERR_OUTOFMEMORY E_OUTOFMEMORY
/*
* The function called is not supported at this time
*/
#define DIERR_UNSUPPORTED E_NOTIMPL
/*
* This object has not been initialized
*/
#define DIERR_NOTINITIALIZED \
MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_NOT_READY)
/*
* This object is already initialized
*/
#define DIERR_ALREADYINITIALIZED \
MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_ALREADY_INITIALIZED)
/*
* This object does not support aggregation
*/
#define DIERR_NOAGGREGATION CLASS_E_NOAGGREGATION
/*
* Another app has a higher priority level, preventing this call from
* succeeding.
*/
#define DIERR_OTHERAPPHASPRIO E_ACCESSDENIED
/*
* Access to the input device has been lost. It must be re-acquired.
*/
#define DIERR_INPUTLOST \
MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_READ_FAULT)
/*
* The operation cannot be performed while the device is acquired.
*/
#define DIERR_ACQUIRED \
MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_BUSY)
/*
* The operation cannot be performed unless the device is acquired.
*/
#define DIERR_NOTACQUIRED \
MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_INVALID_ACCESS)
/*
* The specified property cannot be changed.
*/
#define DIERR_READONLY E_ACCESSDENIED
/*
* The device already has an event notification associated with it.
*/
#define DIERR_HANDLEEXISTS E_ACCESSDENIED
/*
* Data is not yet available.
*/
#ifndef E_PENDING
#define E_PENDING 0x80070007L
#endif
#ifdef __cplusplus
};
#endif
#endif /* __DINPUT_INCLUDED__ */
/****************************************************************************
*
* Definitions for non-IDirectInput (VJoyD) features defined more recently
* than the current sdk files
*
****************************************************************************/
#ifdef _INC_MMSYSTEM
#ifndef MMNOJOY
#ifndef __VJOYDX_INCLUDED__
#define __VJOYDX_INCLUDED__
#ifdef __cplusplus
extern "C" {
#endif
/*
* Flag to indicate that the dwReserved2 field of the JOYINFOEX structure
* contains mini-driver specific data to be passed by VJoyD to the mini-
* driver instead of doing a poll.
*/
#define JOY_PASSDRIVERDATA 0x10000000l
/*
* Informs the joystick driver that the configuration has been changed
* and should be reloaded from the registery.
* dwFlags is reserved and should be set to zero
*/
WINMMAPI MMRESULT WINAPI joyConfigChanged( DWORD dwFlags );
/*
* Hardware Setting indicating that the device is a headtracker
*/
#define JOY_HWS_ISHEADTRACKER 0x02000000l
/*
* Hardware Setting indicating that the VxD is used to replace
* the standard analog polling
*/
#define JOY_HWS_ISGAMEPORTDRIVER 0x04000000l
#ifdef __cplusplus
};
#endif
#endif /* __VJOYDX_INCLUDED__ */
#endif /* not MMNOJOY */
#endif /* _INC_MMSYSTEM */
/****************************************************************************
*
* Definitions for non-IDirectInput (VJoyD) features defined more recently
* than the current ddk files
*
****************************************************************************/
#ifdef _INC_MMDDK
#ifndef MMNOJOYDEV
#ifndef __VJOYDXD_INCLUDED__
#define __VJOYDXD_INCLUDED__
/*
* Poll type in which the do_other field of the JOYOEMPOLLDATA
* structure contains mini-driver specific data passed from an app.
*/
#define JOY_OEMPOLL_PASSDRIVERDATA 7
#endif /* __VJOYDXD_INCLUDED__ */
#endif /* not MMNOJOYDEV */
#endif /* _INC_MMDDK */
| 31,010 | C | .h | 745 | 39.559732 | 118 | 0.653682 | headcrab-junkyard/OGS | 98 | 13 | 0 | GPL-3.0 | 9/7/2024, 9:44:18 AM (Europe/Amsterdam) | true | false | true | true | true | false | true | false |
1,418,811 | product_store_hal.c | BrewPi_firmware/platform/spark/firmware/hal/src/core/product_store_hal.c |
#include "product_store_hal.h"
/**
* Sets the value at a specific product store index.
* @return The previous value.
*/
uint16_t HAL_SetProductStore(ProductStoreIndex index, uint16_t value)
{
return 0xFFFF;
}
/**
* Fetches the value at a given index in the product store.
* @param index
* @return
*/
uint16_t HAL_GetProductStore(ProductStoreIndex index)
{
return 0xFFFF;
}
| 392 | C | .c | 18 | 19.722222 | 69 | 0.745946 | BrewPi/firmware | 97 | 55 | 8 | AGPL-3.0 | 9/7/2024, 9:44:18 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
1,520,663 | q_color.c | DrBeef_JKXR/Projects/Android/jni/OpenJK/shared/qcommon/q_color.c | #include "q_color.h"
vec4_t colorBlack = {0, 0, 0, 1};
vec4_t colorRed = {1, 0, 0, 1};
vec4_t colorGreen = {0, 1, 0, 1};
vec4_t colorBlue = {0, 0, 1, 1};
vec4_t colorYellow = {1, 1, 0, 1};
vec4_t colorOrange = {1, 0.5, 0, 1};
vec4_t colorMagenta= {1, 0, 1, 1};
vec4_t colorCyan = {0, 1, 1, 1};
vec4_t colorWhite = {1, 1, 1, 1};
vec4_t colorLtGrey = {0.75, 0.75, 0.75, 1};
vec4_t colorMdGrey = {0.5, 0.5, 0.5, 1};
vec4_t colorDkGrey = {0.25, 0.25, 0.25, 1};
vec4_t colorLtBlue = {0.367f, 0.261f, 0.722f, 1};
vec4_t colorDkBlue = {0.199f, 0.0f, 0.398f, 1};
vec4_t g_color_table[Q_COLOR_BITS+1] = {
{ 0.0, 0.0, 0.0, 1.0 }, // black
{ 1.0, 0.0, 0.0, 1.0 }, // red
{ 0.0, 1.0, 0.0, 1.0 }, // green
{ 1.0, 1.0, 0.0, 1.0 }, // yellow
{ 0.0, 0.0, 1.0, 1.0 }, // blue
{ 0.0, 1.0, 1.0, 1.0 }, // cyan
{ 1.0, 0.0, 1.0, 1.0 }, // magenta
{ 1.0, 1.0, 1.0, 1.0 }, // white
{ 1.0, 0.5, 0.0, 1.0 }, // orange
{ 0.5, 0.5, 0.5, 1.0 }, // md.grey
};
vec4_t colorTable[CT_MAX] =
{
{0, 0, 0, 0}, // CT_NONE
{0, 0, 0, 1}, // CT_BLACK
{1, 0, 0, 1}, // CT_RED
{0, 1, 0, 1}, // CT_GREEN
{0, 0, 1, 1}, // CT_BLUE
{1, 1, 0, 1}, // CT_YELLOW
{1, 0, 1, 1}, // CT_MAGENTA
{0, 1, 1, 1}, // CT_CYAN
{1, 1, 1, 1}, // CT_WHITE
{0.75f, 0.75f, 0.75f, 1}, // CT_LTGREY
{0.50f, 0.50f, 0.50f, 1}, // CT_MDGREY
{0.25f, 0.25f, 0.25f, 1}, // CT_DKGREY
{0.15f, 0.15f, 0.15f, 1}, // CT_DKGREY2
{0.992f, 0.652f, 0.0f, 1}, // CT_VLTORANGE -- needs values
{0.810f, 0.530f, 0.0f, 1}, // CT_LTORANGE
{0.610f, 0.330f, 0.0f, 1}, // CT_DKORANGE
{0.402f, 0.265f, 0.0f, 1}, // CT_VDKORANGE
{0.503f, 0.375f, 0.996f, 1}, // CT_VLTBLUE1
{0.367f, 0.261f, 0.722f, 1}, // CT_LTBLUE1
{0.199f, 0.0f, 0.398f, 1}, // CT_DKBLUE1
{0.160f, 0.117f, 0.324f, 1}, // CT_VDKBLUE1
{0.300f, 0.628f, 0.816f, 1}, // CT_VLTBLUE2 -- needs values
{0.300f, 0.628f, 0.816f, 1}, // CT_LTBLUE2
{0.191f, 0.289f, 0.457f, 1}, // CT_DKBLUE2
{0.125f, 0.250f, 0.324f, 1}, // CT_VDKBLUE2
{0.796f, 0.398f, 0.199f, 1}, // CT_VLTBROWN1 -- needs values
{0.796f, 0.398f, 0.199f, 1}, // CT_LTBROWN1
{0.558f, 0.207f, 0.027f, 1}, // CT_DKBROWN1
{0.328f, 0.125f, 0.035f, 1}, // CT_VDKBROWN1
{0.996f, 0.796f, 0.398f, 1}, // CT_VLTGOLD1 -- needs values
{0.996f, 0.796f, 0.398f, 1}, // CT_LTGOLD1
{0.605f, 0.441f, 0.113f, 1}, // CT_DKGOLD1
{0.386f, 0.308f, 0.148f, 1}, // CT_VDKGOLD1
{0.648f, 0.562f, 0.784f, 1}, // CT_VLTPURPLE1 -- needs values
{0.648f, 0.562f, 0.784f, 1}, // CT_LTPURPLE1
{0.437f, 0.335f, 0.597f, 1}, // CT_DKPURPLE1
{0.308f, 0.269f, 0.375f, 1}, // CT_VDKPURPLE1
{0.816f, 0.531f, 0.710f, 1}, // CT_VLTPURPLE2 -- needs values
{0.816f, 0.531f, 0.710f, 1}, // CT_LTPURPLE2
{0.566f, 0.269f, 0.457f, 1}, // CT_DKPURPLE2
{0.343f, 0.226f, 0.316f, 1}, // CT_VDKPURPLE2
{0.929f, 0.597f, 0.929f, 1}, // CT_VLTPURPLE3
{0.570f, 0.371f, 0.570f, 1}, // CT_LTPURPLE3
{0.355f, 0.199f, 0.355f, 1}, // CT_DKPURPLE3
{0.285f, 0.136f, 0.230f, 1}, // CT_VDKPURPLE3
{0.953f, 0.378f, 0.250f, 1}, // CT_VLTRED1
{0.953f, 0.378f, 0.250f, 1}, // CT_LTRED1
{0.593f, 0.121f, 0.109f, 1}, // CT_DKRED1
{0.429f, 0.171f, 0.113f, 1}, // CT_VDKRED1
{.25f, 0, 0, 1}, // CT_VDKRED
{.70f, 0, 0, 1}, // CT_DKRED
{0.717f, 0.902f, 1.0f, 1}, // CT_VLTAQUA
{0.574f, 0.722f, 0.804f, 1}, // CT_LTAQUA
{0.287f, 0.361f, 0.402f, 1}, // CT_DKAQUA
{0.143f, 0.180f, 0.201f, 1}, // CT_VDKAQUA
{0.871f, 0.386f, 0.375f, 1}, // CT_LTPINK
{0.435f, 0.193f, 0.187f, 1}, // CT_DKPINK
{ 0, .5f, .5f, 1}, // CT_LTCYAN
{ 0, .25f, .25f, 1}, // CT_DKCYAN
{ .179f, .51f, .92f, 1}, // CT_LTBLUE3
{ .199f, .71f, .92f, 1}, // CT_LTBLUE3
{ .5f, .05f, .4f, 1}, // CT_DKBLUE3
{ 0.0f, .613f, .097f, 1}, // CT_HUD_GREEN
{ 0.835f, .015f, .015f, 1}, // CT_HUD_RED
{ .567f, .685f, 1.0f, .75f}, // CT_ICON_BLUE
{ .515f, .406f, .507f, 1}, // CT_NO_AMMO_RED
{ 1.0f, .658f, .062f, 1}, // CT_HUD_ORANGE
{ 0.549f, .854f, 1.0f, 1.0f}, // CT_TITLE
};
unsigned ColorBytes3 (float r, float g, float b) {
unsigned i;
( (byte *)&i )[0] = (byte)(r * 255);
( (byte *)&i )[1] = (byte)(g * 255);
( (byte *)&i )[2] = (byte)(b * 255);
return i;
}
unsigned ColorBytes4 (float r, float g, float b, float a) {
unsigned i;
( (byte *)&i )[0] = (byte)(r * 255);
( (byte *)&i )[1] = (byte)(g * 255);
( (byte *)&i )[2] = (byte)(b * 255);
( (byte *)&i )[3] = (byte)(a * 255);
return i;
}
float NormalizeColor( const vec3_t in, vec3_t out ) {
float max;
max = in[0];
if ( in[1] > max ) {
max = in[1];
}
if ( in[2] > max ) {
max = in[2];
}
if ( !max ) {
VectorClear( out );
} else {
out[0] = in[0] / max;
out[1] = in[1] / max;
out[2] = in[2] / max;
}
return max;
}
| 4,705 | C | .c | 131 | 33.870229 | 62 | 0.53496 | DrBeef/JKXR | 88 | 2 | 7 | GPL-2.0 | 9/7/2024, 9:44:40 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,713,595 | Si446x.c | ZakKemble_Si446x/Si446x/Si446x.c | /*
* Project: Si4463 Radio Library for AVR and Arduino
* Author: Zak Kemble, [email protected]
* Copyright: (C) 2017 by Zak Kemble
* License: GNU GPL v3 (see License.txt)
* Web: http://blog.zakkemble.co.uk/si4463-radio-library-avr-arduino/
*/
#ifdef ARDUINO
#include <Arduino.h>
#include <SPI.h>
#else
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/atomic.h>
#include <util/delay.h>
#include "Si446x_spi.h"
#endif
#include <string.h>
#include <stdint.h>
#include "Si446x.h"
#include "Si446x_config.h"
#include "Si446x_defs.h"
#include "radio_config.h"
#define IDLE_STATE SI446X_IDLE_MODE
// When FIFOs are combined it becomes a 129 byte FiFO
// The first byte is used for length, then the remaining 128 bytes for the packet data
#define MAX_PACKET_LEN SI446X_MAX_PACKET_LEN
#define IRQ_PACKET 0
#define IRQ_MODEM 1
#define IRQ_CHIP 2
#define rssi_dBm(val) ((val / 2) - 134)
#if SI446X_INTERRUPTS != 0
#if defined(ARDUINO) && SI446X_IRQ == -1
#error "SI446X_INTERRUPTS is 1, but SI446X_IRQ is set to -1!"
#elif !defined(ARDUINO) && !defined(IRQ_BIT)
#error "SI446X_INTERRUPTS is 1, but SI446X_IRQ_PORT or SI446X_IRQ_BIT has not been set!"
#endif
#endif
#ifdef ARDUINO
#define delay_ms(ms) delay(ms)
#define delay_us(us) delayMicroseconds(us)
#define spiSelect() (digitalWrite(SI446X_CSN, LOW))
#define spiDeselect() (digitalWrite(SI446X_CSN, HIGH))
#define spi_transfer_nr(data) (SPI.transfer(data))
#define spi_transfer(data) (SPI.transfer(data))
#else
#define delay_ms(ms) _delay_ms(ms)
#define delay_us(us) _delay_us(us)
#define spiSelect() (CSN_PORT &= ~_BV(CSN_BIT))
#define spiDeselect() (CSN_PORT |= _BV(CSN_BIT))
#endif
static const uint8_t config[] PROGMEM = RADIO_CONFIGURATION_DATA_ARRAY;
static volatile uint8_t enabledInterrupts[3];
// http://stackoverflow.com/questions/10802324/aliasing-a-function-on-a-c-interface-within-a-c-application-on-linux
#if defined(__cplusplus)
extern "C" {
#endif
static void __empty_callback0(void){}
static void __empty_callback1(int16_t param1){(void)(param1);}
#if defined(__cplusplus)
}
#endif
void __attribute__((weak, alias ("__empty_callback0"))) SI446X_CB_CMDTIMEOUT(void);
void __attribute__((weak, alias ("__empty_callback1"))) SI446X_CB_RXBEGIN(int16_t rssi);
void __attribute__((weak)) SI446X_CB_RXCOMPLETE(uint8_t length, int16_t rssi){(void)(length);(void)(rssi);}
void __attribute__((weak, alias ("__empty_callback1"))) SI446X_CB_RXINVALID(int16_t rssi);
void __attribute__((weak, alias ("__empty_callback0"))) SI446X_CB_SENT(void);
void __attribute__((weak, alias ("__empty_callback0"))) SI446X_CB_WUT(void);
void __attribute__((weak, alias ("__empty_callback0"))) SI446X_CB_LOWBATT(void);
#if SI446X_ENABLE_ADDRMATCHING
void __attribute__((weak, alias ("__empty_callback0"))) SI446X_CB_ADDRMATCH(void);
void __attribute__((weak, alias ("__empty_callback0"))) SI446X_CB_ADDRMISS(void);
#endif
// TODO
//void __attribute__((weak)) SI446X_CB_DEBUG(uint8_t* interrupts){(void)(interrupts);}
// http://www.nongnu.org/avr-libc/user-manual/atomic_8h_source.html
#ifdef ARDUINO
#if SI446X_INTERRUPTS != 0
// It's not possible to get the current interrupt enabled state in Arduino (SREG only works for AVR based Arduinos, and no way of getting attachInterrupt() status), so we use a counter thing instead
static volatile uint8_t isrState_local;
#endif
#if SI446X_INTERRUPTS == 1 || SI446X_INT_SPI_COMMS == 1
static volatile uint8_t isrState;
static volatile uint8_t isrBusy; // Don't mess with global interrupts if we're inside an ISR
static inline uint8_t interrupt_off(void)
{
if(!isrBusy)
{
noInterrupts();
isrState++;
}
return 1;
}
static inline uint8_t interrupt_on(void)
{
if(!isrBusy)
{
if(isrState > 0)
isrState--;
if(isrState == 0)
interrupts();
}
return 0;
}
#endif
#endif
static inline uint8_t cselect(void)
{
// spi_enable();
spiSelect();
return 1;
}
static inline uint8_t cdeselect(void)
{
spiDeselect();
// spi_disable();
return 0;
}
#define CHIPSELECT() for(uint8_t _cs = cselect(); _cs; _cs = cdeselect())
// TODO
// 2 types of interrupt blocks
// Local (SI446X_NO_INTERRUPT()): Disables the pin interrupt so the ISR does not run while normal code is busy in the Si446x code, however another interrupt can enter the code which would be bad.
// Global (SI446X_ATOMIC()): Disable all interrupts, don't use waitForResponse() inside here as it can take a while to complete. These blocks are to make sure no other interrupts use the SPI bus.
// If an interrupt might do some SPI communications with another device then we
// need to turn global interrupts off while communicating with the radio.
// Otherwise, just turn off our own radio interrupt while doing SPI stuff.
#if SI446X_INTERRUPTS == 0 && SI446X_INT_SPI_COMMS == 0
#define SI446X_ATOMIC() ((void)(0));
#elif defined(ARDUINO)
#define SI446X_ATOMIC() for(uint8_t _cs2 = interrupt_off(); _cs2; _cs2 = interrupt_on())
#else
#define SI446X_ATOMIC() ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
#endif
// When doing SPI comms with the radio or doing multiple commands we don't want the radio interrupt to mess it up.
uint8_t Si446x_irq_off()
{
#if SI446X_INTERRUPTS != 0
#ifdef ARDUINO
detachInterrupt(digitalPinToInterrupt(SI446X_IRQ));
isrState_local++;
return 0;
#else
uint8_t origVal = SI446X_REG_EXTERNAL_INT;
SI446X_REG_EXTERNAL_INT &= ~_BV(SI446X_BIT_EXTERNAL_INT);
origVal = !!(origVal & _BV(SI446X_BIT_EXTERNAL_INT));
//origVal += 1; // We always want to return a non-zero value so the for() loop will loop TODO
return origVal;
#endif
#else
return 0;
#endif
}
void Si446x_irq_on(uint8_t origVal)
{
#if SI446X_INTERRUPTS != 0
#ifdef ARDUINO
((void)(origVal));
if(isrState_local > 0)
isrState_local--;
if(isrState_local == 0)
attachInterrupt(digitalPinToInterrupt(SI446X_IRQ), Si446x_SERVICE, FALLING);
#else
if(origVal)// == 2) TODO
SI446X_REG_EXTERNAL_INT |= _BV(SI446X_BIT_EXTERNAL_INT);
#endif
#else
((void)(origVal));
#endif
}
// Read CTS and if its ok then read the command buffer
static uint8_t getResponse(void* buff, uint8_t len)
{
uint8_t cts = 0;
SI446X_ATOMIC()
{
CHIPSELECT()
{
// Send command
spi_transfer_nr(SI446X_CMD_READ_CMD_BUFF);
// Get CTS value
cts = (spi_transfer(0xFF) == 0xFF);
if(cts)
{
// Get response data
for(uint8_t i=0;i<len;i++)
((uint8_t*)buff)[i] = spi_transfer(0xFF);
}
}
}
return cts;
}
// Keep trying to read the command buffer, with timeout of around 500ms
static uint8_t waitForResponse(void* out, uint8_t outLen, uint8_t useTimeout)
{
// With F_CPU at 8MHz and SPI at 4MHz each check takes about 7us + 10us delay
uint16_t timeout = 40000;
while(!getResponse(out, outLen))
{
delay_us(10);
if(useTimeout && !--timeout)
{
SI446X_CB_CMDTIMEOUT();
return 0;
}
}
return 1;
}
static void doAPI(void* data, uint8_t len, void* out, uint8_t outLen)
{
SI446X_NO_INTERRUPT()
{
if(waitForResponse(NULL, 0, 1)) // Make sure it's ok to send a command
{
SI446X_ATOMIC()
{
CHIPSELECT()
{
for(uint8_t i=0;i<len;i++)
spi_transfer_nr(((uint8_t*)data)[i]); // (pgm_read_byte(&((uint8_t*)data)[i]));
}
}
if(((uint8_t*)data)[0] == SI446X_CMD_IRCAL) // If we're doing an IRCAL then wait for its completion without a timeout since it can sometimes take a few seconds
waitForResponse(NULL, 0, 0);
else if(out != NULL) // If we have an output buffer then read command response into it
waitForResponse(out, outLen, 1);
}
}
}
// Configure a bunch of properties (up to 12 properties in one go)
static void setProperties(uint16_t prop, void* values, uint8_t len)
{
// len must not be greater than 12
uint8_t data[16] = {
SI446X_CMD_SET_PROPERTY,
(uint8_t)(prop>>8),
len,
(uint8_t)prop
};
// Copy values into data, starting at index 4
memcpy(data + 4, values, len);
doAPI(data, len + 4, NULL, 0);
}
// Set a single property
static inline void setProperty(uint16_t prop, uint8_t value)
{
setProperties(prop, &value, 1);
}
/*
// Set a 16bit property
static void setProperty16(uint16_t prop, uint16_t value)
{
uint8_t properties[] = {value>>8, value};
setProperties(prop, properties, sizeof(properties));
}
*/
// Read a bunch of properties
static void getProperties(uint16_t prop, void* values, uint8_t len)
{
uint8_t data[] = {
SI446X_CMD_GET_PROPERTY,
(uint8_t)(prop>>8),
len,
(uint8_t)prop
};
doAPI(data, sizeof(data), values, len);
}
// Read a single property
static inline uint8_t getProperty(uint16_t prop)
{
uint8_t val;
getProperties(prop, &val, 1);
return val;
}
// Do an ADC conversion
static uint16_t getADC(uint8_t adc_en, uint8_t adc_cfg, uint8_t part)
{
uint8_t data[6] = {
SI446X_CMD_GET_ADC_READING,
adc_en,
adc_cfg
};
doAPI(data, 3, data, 6);
return (data[part]<<8 | data[part + 1]);
}
// Read a fast response register
static uint8_t getFRR(uint8_t reg)
{
uint8_t frr = 0;
SI446X_ATOMIC()
{
CHIPSELECT()
{
spi_transfer_nr(reg);
frr = spi_transfer(0xFF);
}
}
return frr;
}
// Ge the patched RSSI from the beginning of the packet
static int16_t getLatchedRSSI(void)
{
uint8_t frr = getFRR(SI446X_CMD_READ_FRR_A);
int16_t rssi = rssi_dBm(frr);
return rssi;
}
// Get current radio state
static si446x_state_t getState(void)
{
uint8_t state = getFRR(SI446X_CMD_READ_FRR_B);
if(state == SI446X_STATE_TX_TUNE)
state = SI446X_STATE_TX;
else if(state == SI446X_STATE_RX_TUNE)
state = SI446X_STATE_RX;
else if(state == SI446X_STATE_READY2)
state = SI446X_STATE_READY;
return (si446x_state_t)state;
}
// Set new state
static void setState(si446x_state_t newState)
{
uint8_t data[] = {
SI446X_CMD_CHANGE_STATE,
newState
};
doAPI(data, sizeof(data), NULL, 0);
}
// Clear RX and TX FIFOs
static void clearFIFO(void)
{
// 'static const' saves 20 bytes of flash here, but uses 2 bytes of RAM
static const uint8_t clearFifo[] = {
SI446X_CMD_FIFO_INFO,
SI446X_FIFO_CLEAR_RX | SI446X_FIFO_CLEAR_TX
};
doAPI((uint8_t*)clearFifo, sizeof(clearFifo), NULL, 0);
}
/*
// Sometimes the Si446x gets all messed up if it receives a bad packet, so we have to enable the INVALID SYNC interrupt when
// a new packet starts coming in. If the INVALID SYNC interrupt is triggered then RX mode is restarted. The interrupt is turned off again
// if the packet is successfully received.
void __attribute__((weak)) SI446X_CB_RXINVALIDSYNC(void)
{
setState(IDLE_STATE);
clearFIFO();
uint8_t data = SI446X_CMD_START_RX; // Restart RX with same params as before (channel etc)
doAPI(&data, sizeof(data), NULL, 0);
// TODO turn off interrupt?
}
*/
// TODO use Si446x_setupCallback instead?
/*static void fix_invalidSync_irq(uint8_t enable)
{
uint8_t data = getProperty(SI446X_INT_CTL_MODEM_ENABLE);
enable ? (data |= 32) : (data &= ~32); // TODO use def for 32
enabledInterrupts[IRQ_MODEM] = data;
setProperty(SI446X_INT_CTL_MODEM_ENABLE, data);
}
*/
// Read pending interrupts
// Reading interrupts will also clear them
// Buff should either be NULL (just clear interrupts) or a buffer of atleast 8 bytes for storing statuses
static void interrupt(void* buff)
{
uint8_t data = SI446X_CMD_GET_INT_STATUS;
doAPI(&data, sizeof(data), buff, 8);
}
// Similar to interrupt() but with the option of not clearing certain interrupt flags
static void interrupt2(void* buff, uint8_t clearPH, uint8_t clearMODEM, uint8_t clearCHIP)
{
uint8_t data[] = {
SI446X_CMD_GET_INT_STATUS,
clearPH,
clearMODEM,
clearCHIP
};
doAPI(data, sizeof(data), buff, 8);
}
// Reset the RF chip
static void resetDevice(void)
{
#ifdef ARDUINO
digitalWrite(SI446X_SDN, HIGH);
delay_ms(50);
digitalWrite(SI446X_SDN, LOW);
delay_ms(50);
#else
SDN_PORT |= _BV(SDN_BIT);
delay_ms(50);
SDN_PORT &= ~_BV(SDN_BIT);
delay_ms(50);
#endif
}
/*
// TODO
// External version of interrupt()
void Si446x_interrupt(uint8_t* buff)
{
uint8_t data[4] = {SI446X_CMD_GET_INT_STATUS, 0xff, 0xff, 0xff};
doAPI(&data, sizeof(data), buff, 8);
}
*/
// Apply the radio configuration
static void applyStartupConfig(void)
{
uint8_t buff[17];
for(uint16_t i=0;i<sizeof(config);i++)
{
memcpy_P(buff, &config[i], sizeof(buff));
doAPI(&buff[1], buff[0], NULL, 0);
i += buff[0];
}
}
void Si446x_init()
{
spiDeselect();
#ifdef ARDUINO
pinMode(SI446X_CSN, OUTPUT);
pinMode(SI446X_SDN, OUTPUT);
#if SI446X_IRQ != -1
pinMode(SI446X_IRQ, INPUT_PULLUP);
#endif
SPI.begin();
#else
CSN_DDR |= _BV(CSN_BIT);
SDN_DDR |= _BV(SDN_BIT);
#ifdef IRQ_BIT
// Interrupt pin (input with pullup)
#if defined(PUEA) || defined(PUEB) || defined(PUEC) || defined(PUED) || defined(PUEE)
IRQ_PUE |= _BV(IRQ_BIT);
#else
IRQ_PORT |= _BV(IRQ_BIT);
#endif
#endif
spi_init();
#endif
resetDevice();
applyStartupConfig();
interrupt(NULL);
Si446x_sleep();
enabledInterrupts[IRQ_PACKET] = (1<<SI446X_PACKET_RX_PEND) | (1<<SI446X_CRC_ERROR_PEND);
//enabledInterrupts[IRQ_MODEM] = (1<<SI446X_SYNC_DETECT_PEND);
#ifndef ARDUINO
// TODO Interrupt should trigger on low level, not falling edge?
#endif
Si446x_irq_on(1);
}
void Si446x_getInfo(si446x_info_t* info)
{
uint8_t data[8] = {
SI446X_CMD_PART_INFO
};
doAPI(data, 1, data, 8);
info->chipRev = data[0];
info->part = (data[1]<<8) | data[2];
info->partBuild = data[3];
info->id = (data[4]<<8) | data[5];
info->customer = data[6];
info->romId = data[7];
data[0] = SI446X_CMD_FUNC_INFO;
doAPI(data, 1, data, 6);
info->revExternal = data[0];
info->revBranch = data[1];
info->revInternal = data[2];
info->patch = (data[3]<<8) | data[4];
info->func = data[5];
}
int16_t Si446x_getRSSI()
{
uint8_t data[3] = {
SI446X_CMD_GET_MODEM_STATUS,
0xFF
};
doAPI(data, 2, data, 3);
int16_t rssi = rssi_dBm(data[2]);
return rssi;
}
si446x_state_t Si446x_getState()
{
// TODO what about the state change delay with transmitting?
return getState();
}
void Si446x_setTxPower(uint8_t pwr)
{
setProperty(SI446X_PA_PWR_LVL, pwr);
}
#if SI446X_ENABLE_ADDRMATCHING
// API docs say that you can match on the same byte, but programming guide says you can't!
// Truth is that you can't match on the same byte (that means broadcast flag needs to be on a separate byte than the address :/)
void Si446x_setAddress(si446x_addrMode_t mode, uint8_t address)
{
uint8_t data[] = {
address,
0xFF,
SI446X_MATCH_EN | 1,
0x80,
0x80,
2,
0x00,
0x00,
3,
0x00,
0x00,
4
};
if(mode == SI446X_ADDRMODE_DISABLE) // Set everything to 0 to disable address matching
memset(data, 0, sizeof(data));
else if(mode == SI446X_ADDRMODE_ADDR) // Disable matching for the 2nd byte
{
data[3] = 0x00;
data[4] = 0x00;
}
setProperties(SI446X_MATCH_VALUE_1, data, sizeof(data));
}
#endif
void Si446x_setLowBatt(uint16_t voltage)
{
// voltage should be between 1500 and 3050
uint8_t batt = (voltage / 50) - 30;//((voltage * 2) - 3000) / 100;
setProperty(SI446X_GLOBAL_LOW_BATT_THRESH, batt);
}
void Si446x_setupWUT(uint8_t r, uint16_t m, uint8_t ldc, uint8_t config)
{
// Maximum value of r is 20
// The API docs say that if r or m are 0, then they will have the same effect as if they were 1, but this doesn't seem to be the case?
// Check valid config
// TODO needed?
if(!(config & (SI446X_WUT_RUN | SI446X_WUT_BATT | SI446X_WUT_RX)))
return;
SI446X_NO_INTERRUPT()
{
// Disable WUT
setProperty(SI446X_GLOBAL_WUT_CONFIG, 0);
uint8_t doRun = !!(config & SI446X_WUT_RUN);
uint8_t doBatt = !!(config & SI446X_WUT_BATT);
uint8_t doRx = (config & SI446X_WUT_RX);
// Setup WUT interrupts
uint8_t intChip = 0;//getProperty(SI446X_INT_CTL_CHIP_ENABLE); // No other CHIP interrupts are enabled so dont bother reading the current state
//intChip &= ~((1<<SI446X_INT_CTL_CHIP_LOW_BATT_EN)|(1<<SI446X_INT_CTL_CHIP_WUT_EN));
intChip |= doBatt<<SI446X_INT_CTL_CHIP_LOW_BATT_EN;
intChip |= doRun<<SI446X_INT_CTL_CHIP_WUT_EN;
enabledInterrupts[IRQ_CHIP] = intChip;
setProperty(SI446X_INT_CTL_CHIP_ENABLE, intChip);
// Set WUT clock source to internal 32KHz RC
if(getProperty(SI446X_GLOBAL_CLK_CFG) != SI446X_DIVIDED_CLK_32K_SEL_RC)
{
setProperty(SI446X_GLOBAL_CLK_CFG, SI446X_DIVIDED_CLK_32K_SEL_RC);
delay_us(300); // Need to wait 300us for clock source to stabilize, see GLOBAL_WUT_CONFIG:WUT_EN info
}
// Setup WUT
uint8_t properties[5];
properties[0] = doRx ? SI446X_GLOBAL_WUT_CONFIG_WUT_LDC_EN_RX : 0;
properties[0] |= doBatt<<SI446X_GLOBAL_WUT_CONFIG_WUT_LBD_EN;
properties[0] |= (1<<SI446X_GLOBAL_WUT_CONFIG_WUT_EN);
properties[1] = m>>8;
properties[2] = m;
properties[3] = r | SI446X_LDC_MAX_PERIODS_TWO | (1<<SI446X_WUT_SLEEP);
properties[4] = ldc;
setProperties(SI446X_GLOBAL_WUT_CONFIG, properties, sizeof(properties));
}
}
void Si446x_disableWUT()
{
SI446X_NO_INTERRUPT()
{
setProperty(SI446X_GLOBAL_WUT_CONFIG, 0);
setProperty(SI446X_GLOBAL_CLK_CFG, 0);
}
}
// TODO
// ADDRESS MATCH (only useful with address mode on)
// ADDRESS MISS (only useful with address mode on)
// PACKET SENT
// PACKET RX (must never be turned off, otherwise RX mode would be pointless)
// PACKET RX INVALID (must never be turned off, otherwise RX mode would be pointless)
// PACKET BEGIN (SYNC, modem)
// WUT and LOWBATT (cant turn off/on from here, use wutSetup instead)
// INVALID SYNC (the fix thing)
void Si446x_setupCallback(uint16_t callbacks, uint8_t state)
{
SI446X_NO_INTERRUPT()
{
uint8_t data[2];
getProperties(SI446X_INT_CTL_PH_ENABLE, data, sizeof(data));
if(state)
{
data[0] |= callbacks>>8;
data[1] |= callbacks;
}
else
{
data[0] &= ~(callbacks>>8);
data[1] &= ~callbacks;
}
// TODO
// make sure RXCOMPELTE, RXINVALID and RXBEGIN? are always enabled
enabledInterrupts[IRQ_PACKET] = data[0];
enabledInterrupts[IRQ_MODEM] = data[1];
setProperties(SI446X_INT_CTL_PH_ENABLE, data, sizeof(data));
}
/*
// TODO remove
uint8_t data[4];
data[0] = 0xFF;
data[1] = 0b11111100;
data[2] = 0b11111011;
data[3] = 0xff;
setProperties(SI446X_INT_CTL_ENABLE, data, sizeof(data));
*/
}
uint8_t Si446x_sleep()
{
if(getState() == SI446X_STATE_TX)
return 0;
setState(SI446X_STATE_SLEEP);
return 1;
}
void Si446x_read(void* buff, uint8_t len)
{
SI446X_ATOMIC()
{
CHIPSELECT()
{
spi_transfer_nr(SI446X_CMD_READ_RX_FIFO);
for(uint8_t i=0;i<len;i++)
((uint8_t*)buff)[i] = spi_transfer(0xFF);
}
}
}
/*
// TODO maybe
void Si446x_write(void* buff, uint8_t len)
{
// if we are going to do this then we need dual FIFO so we can stay in RX mode while filling TX FIFO
// also need a public clearFIFO for TX and RX
// this will also allow multiple transmissions without writing FIFO again
// however, we wont know if the packet is corrupt until the whole thing has been transmitted/received - might run out of memory if its a large packet, unless its written to some external SPI RAM as its being received
SI446X_ATOMIC()
{
// Load data to FIFO
CHIPSELECT()
{
spi_transfer_nr(SI446X_CMD_WRITE_TX_FIFO);
for(uint8_t i=0;i<len;i++)
spi_transfer_nr(((uint8_t*)buff)[i]);
}
}
}
*/
#include <stdio.h>
uint8_t Si446x_TX(void* packet, uint8_t len, uint8_t channel, si446x_state_t onTxFinish)
{
// TODO what happens if len is 0?
#if SI446X_FIXED_LENGTH
// Stop the unused parameter warning
((void)(len));
#endif
SI446X_NO_INTERRUPT()
{
if(getState() == SI446X_STATE_TX) // Already transmitting
return 0;
// TODO collision avoid or maybe just do collision detect (RSSI jump)
setState(IDLE_STATE);
clearFIFO();
interrupt2(NULL, 0, 0, 0xFF);
SI446X_ATOMIC()
{
// Load data to FIFO
CHIPSELECT()
{
spi_transfer_nr(SI446X_CMD_WRITE_TX_FIFO);
#if !SI446X_FIXED_LENGTH
spi_transfer_nr(len);
for(uint8_t i=0;i<len;i++)
spi_transfer_nr(((uint8_t*)packet)[i]);
#else
for(uint8_t i=0;i<SI446X_FIXED_LENGTH;i++)
spi_transfer_nr(((uint8_t*)packet)[i]);
#endif
}
}
#if !SI446X_FIXED_LENGTH
// Set packet length
setProperty(SI446X_PKT_FIELD_2_LENGTH_LOW, len);
#endif
// Begin transmit
uint8_t data[] = {
SI446X_CMD_START_TX,
channel,
(uint8_t)(onTxFinish<<4),
0,
SI446X_FIXED_LENGTH,
0,
0
};
doAPI(data, sizeof(data), NULL, 0);
#if !SI446X_FIXED_LENGTH
// Reset packet length back to max for receive mode
setProperty(SI446X_PKT_FIELD_2_LENGTH_LOW, MAX_PACKET_LEN);
#endif
}
return 1;
}
void Si446x_RX(uint8_t channel)
{
SI446X_NO_INTERRUPT()
{
setState(IDLE_STATE);
clearFIFO();
//fix_invalidSync_irq(0);
//Si446x_setupCallback(SI446X_CBS_INVALIDSYNC, 0);
//setProperty(SI446X_PKT_FIELD_2_LENGTH_LOW, MAX_PACKET_LEN); // TODO ?
interrupt2(NULL, 0, 0, 0xFF); // TODO needed?
// TODO RX timeout to sleep if WUT LDC enabled
uint8_t data[] = {
SI446X_CMD_START_RX,
channel,
0,
0,
SI446X_FIXED_LENGTH,
SI446X_STATE_NOCHANGE, // RX Timeout
IDLE_STATE, // RX Valid
SI446X_STATE_SLEEP // IDLE_STATE // RX Invalid (using SI446X_STATE_SLEEP for the INVALID_SYNC fix)
};
doAPI(data, sizeof(data), NULL, 0);
}
}
uint16_t Si446x_adc_gpio(uint8_t pin)
{
uint16_t result = getADC(SI446X_ADC_CONV_GPIO | pin, (SI446X_ADC_SPEED<<4) | SI446X_ADC_RANGE_3P6, 0);
return result;
}
uint16_t Si446x_adc_battery()
{
uint16_t result = getADC(SI446X_ADC_CONV_BATT, (SI446X_ADC_SPEED<<4), 2);
result = ((uint32_t)result * 75) / 32; // result * 2.34375;
return result;
}
float Si446x_adc_temperature()
{
float result = getADC(SI446X_ADC_CONV_TEMP, (SI446X_ADC_SPEED<<4), 4);
result = (899/4096.0) * result - 293;
return result;
}
void Si446x_writeGPIO(si446x_gpio_t pin, uint8_t value)
{
uint8_t data[] = {
SI446X_CMD_GPIO_PIN_CFG,
SI446X_GPIO_MODE_DONOTHING,
SI446X_GPIO_MODE_DONOTHING,
SI446X_GPIO_MODE_DONOTHING,
SI446X_GPIO_MODE_DONOTHING,
SI446X_NIRQ_MODE_DONOTHING,
SI446X_SDO_MODE_DONOTHING,
SI446X_GPIO_DRV_HIGH
};
data[pin + 1] = value;
doAPI(data, sizeof(data), NULL, 0);
}
uint8_t Si446x_readGPIO()
{
uint8_t data[4] = {
SI446X_CMD_GPIO_PIN_CFG
};
doAPI(data, 1, data, sizeof(data));
uint8_t states = data[0]>>7 | (data[1] & 0x80)>>6 | (data[2] & 0x80)>>5 | (data[3] & 0x80)>>4;
return states;
}
uint8_t Si446x_dump(void* buff, uint8_t group)
{
static const uint8_t groupSizes[] PROGMEM = {
SI446X_PROP_GROUP_GLOBAL, 0x0A,
SI446X_PROP_GROUP_INT, 0x04,
SI446X_PROP_GROUP_FRR, 0x04,
SI446X_PROP_GROUP_PREAMBLE, 0x0E,
SI446X_PROP_GROUP_SYNC, 0x06,
SI446X_PROP_GROUP_PKT, 0x40,
SI446X_PROP_GROUP_MODEM, 0x60,
SI446X_PROP_GROUP_MODEM_CHFLT, 0x24,
SI446X_PROP_GROUP_PA, 0x07,
SI446X_PROP_GROUP_SYNTH, 0x08,
SI446X_PROP_GROUP_MATCH, 0x0C,
SI446X_PROP_GROUP_FREQ_CONTROL, 0x08,
SI446X_PROP_GROUP_RX_HOP, 0x42,
SI446X_PROP_GROUP_PTI, 0x04
};
uint8_t length = 0;
for(uint8_t i=0;i<sizeof(groupSizes);i+=2)
{
uint8_t buff[2];
memcpy_P(buff, &groupSizes[i], sizeof(buff));
if(buff[0] == group)
{
length = buff[1];
break;
}
}
if(buff == NULL)
return length;
for(uint8_t i=0;i<length;i+=16)
{
uint8_t count = length - i;
if(count > 16)
count = 16;
getProperties((group<<8) | i, ((uint8_t*)buff) + i, count);
}
return length;
}
#if defined(ARDUINO) || SI446X_INTERRUPTS == 0
void Si446x_SERVICE()
#else
ISR(INT_VECTOR)
#endif
{
#if defined(ARDUINO) && (SI446X_INTERRUPTS == 1 || SI446X_INT_SPI_COMMS == 1)
isrBusy = 1;
#endif
uint8_t interrupts[8];
interrupt(interrupts);
// TODO remove
//SI446X_CB_DEBUG(interrupts);
//printf_P(PSTR("INT %hhu/%hhu %hhu/%hhu %hhu/%hhu\n"), interrupts[2], interrupts[3], interrupts[4], interrupts[5], interrupts[6], interrupts[7]);
// We could read the enabled interrupts properties instead of keep their states in RAM, but that would be much slower
interrupts[2] &= enabledInterrupts[IRQ_PACKET];
interrupts[4] &= enabledInterrupts[IRQ_MODEM];
interrupts[6] &= enabledInterrupts[IRQ_CHIP];
// Valid PREAMBLE and SYNC, packet data now begins
if(interrupts[4] & (1<<SI446X_SYNC_DETECT_PEND))
{
//fix_invalidSync_irq(1);
// Si446x_setupCallback(SI446X_CBS_INVALIDSYNC, 1); // Enable INVALID_SYNC when a new packet starts, sometimes a corrupted packet will mess the radio up
SI446X_CB_RXBEGIN(getLatchedRSSI());
}
/*
// Disable INVALID_SYNC
if((interrupts[4] & (1<<SI446X_INVALID_SYNC_PEND)) || (interrupts[2] & ((1<<SI446X_PACKET_SENT_PEND)|(1<<SI446X_CRC_ERROR_PEND))))
{
//fix_invalidSync_irq(0);
Si446x_setupCallback(SI446X_CBS_INVALIDSYNC, 0);
}
*/
// INVALID_SYNC detected, sometimes the radio gets messed up in this state and requires a RX restart
// if(interrupts[4] & (1<<SI446X_INVALID_SYNC_PEND))
// SI446X_CB_RXINVALIDSYNC();
#if SI446X_ENABLE_ADDRMATCHING
// Address match success
// NOTE: This will still be called even if the packet failed the CRC
if(interrupts[2] & (1<<SI446X_FILTER_MATCH_PEND))
SI446X_CB_ADDRMATCH();
// Address match missed
// NOTE: This will still be called even if the packet failed the CRC
if(interrupts[2] & (1<<SI446X_FILTER_MISS_PEND))
SI446X_CB_ADDRMISS();
#endif
// Valid packet
if(interrupts[2] & (1<<SI446X_PACKET_RX_PEND))
{
#if !SI446X_FIXED_LENGTH
uint8_t len = 0;
Si446x_read(&len, 1);
#else
uint8_t len = SI446X_FIXED_LENGTH;
#endif
SI446X_CB_RXCOMPLETE(len, getLatchedRSSI());
}
// Corrupted packet
// NOTE: This will still be called even if the address did not match, but the packet failed the CRC
// This will not be called if the address missed, but the packet passed CRC
if(interrupts[2] & (1<<SI446X_CRC_ERROR_PEND))
{
#if IDLE_STATE == SI446X_STATE_READY
if(getState() == SI446X_STATE_SPI_ACTIVE)
setState(IDLE_STATE); // We're in sleep mode (acually, we're now in SPI active mode) after an invalid packet to fix the INVALID_SYNC issue
#endif
SI446X_CB_RXINVALID(getLatchedRSSI()); // TODO remove RSSI stuff for invalid packets, entering SLEEP mode looses the latched value?
}
// Packet sent
if(interrupts[2] & (1<<SI446X_PACKET_SENT_PEND))
SI446X_CB_SENT();
if(interrupts[6] & (1<<SI446X_LOW_BATT_PEND))
SI446X_CB_LOWBATT();
if(interrupts[6] & (1<<SI446X_WUT_PEND))
SI446X_CB_WUT();
#if defined(ARDUINO) && (SI446X_INTERRUPTS == 1 || SI446X_INT_SPI_COMMS == 1)
isrBusy = 0;
#endif
}
| 26,177 | C | .c | 887 | 27.342728 | 217 | 0.710928 | ZakKemble/Si446x | 73 | 30 | 2 | GPL-3.0 | 9/7/2024, 9:45:04 AM (Europe/Amsterdam) | false | false | false | true | true | false | false | false |
1,773,476 | success_ternary_op_01.c | bsc-pm_mcxx/tests/04_compat_gcc.dg/success_ternary_op_01.c | /*--------------------------------------------------------------------
(C) Copyright 2006-2012 Barcelona Supercomputing Center
Centro Nacional de Supercomputacion
This file is part of Mercurium C/C++ source-to-source compiler.
See AUTHORS file in the top level directory for information
regarding developers and contributors.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
Mercurium C/C++ source-to-source compiler 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 Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public
License along with Mercurium C/C++ source-to-source compiler; if
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA.
--------------------------------------------------------------------*/
/*
<testinfo>
test_generator=config/mercurium
</testinfo>
*/
void f(void) {
int i = 0;
i = (i) ? : 42;
}
| 1,334 | C | .c | 29 | 41.724138 | 70 | 0.670295 | bsc-pm/mcxx | 69 | 23 | 11 | LGPL-3.0 | 9/7/2024, 9:45:36 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,773,480 | success_attribute_parameter_declarator_01.c | bsc-pm_mcxx/tests/04_compat_gcc.dg/success_attribute_parameter_declarator_01.c | /*
<testinfo>
test_generator=config/mercurium
</testinfo>
*/
typedef void* pointer_t;
void foo ( pointer_t __attribute__((__unused__)) bar )
{
}
| 145 | C | .c | 9 | 15.111111 | 54 | 0.705882 | bsc-pm/mcxx | 69 | 23 | 11 | LGPL-3.0 | 9/7/2024, 9:45:36 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,773,494 | success_int128_t_01.c | bsc-pm_mcxx/tests/04_compat_gcc.dg/success_int128_t_01.c | /*--------------------------------------------------------------------
(C) Copyright 2006-2012 Barcelona Supercomputing Center
Centro Nacional de Supercomputacion
This file is part of Mercurium C/C++ source-to-source compiler.
See AUTHORS file in the top level directory for information
regarding developers and contributors.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
Mercurium C/C++ source-to-source compiler 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 Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public
License along with Mercurium C/C++ source-to-source compiler; if
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA.
--------------------------------------------------------------------*/
/*
<testinfo>
test_generator=config/mercurium
</testinfo>
*/
int main()
{
#if defined(__SIZEOF_INT128__)
__int128_t a = 0;
__uint128_t b = 0;
b = b + a;
#endif
return 0;
}
| 1,400 | C | .c | 34 | 37.411765 | 70 | 0.672107 | bsc-pm/mcxx | 69 | 23 | 11 | LGPL-3.0 | 9/7/2024, 9:45:36 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,774,270 | success_builtin_01.c | bsc-pm_mcxx/tests/04_compat_xl.dg/success_builtin_01.c | /*--------------------------------------------------------------------
(C) Copyright 2006-2012 Barcelona Supercomputing Center
Centro Nacional de Supercomputacion
This file is part of Mercurium C/C++ source-to-source compiler.
See AUTHORS file in the top level directory for information
regarding developers and contributors.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
Mercurium C/C++ source-to-source compiler 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 Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public
License along with Mercurium C/C++ source-to-source compiler; if
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA.
--------------------------------------------------------------------*/
/*
<testinfo>
test_generator=config/mercurium-extensions
</testinfo>
*/
extern void _Builtin foo(void *);
| 1,319 | C | .c | 26 | 46.692308 | 70 | 0.689168 | bsc-pm/mcxx | 69 | 23 | 11 | LGPL-3.0 | 9/7/2024, 9:45:36 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
1,776,217 | success_160.c | bsc-pm_mcxx/tests/01_parser.dg/success_160.c | /*--------------------------------------------------------------------
(C) Copyright 2006-2012 Barcelona Supercomputing Center
Centro Nacional de Supercomputacion
This file is part of Mercurium C/C++ source-to-source compiler.
See AUTHORS file in the top level directory for information
regarding developers and contributors.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
Mercurium C/C++ source-to-source compiler 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 Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public
License along with Mercurium C/C++ source-to-source compiler; if
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA.
--------------------------------------------------------------------*/
/*
<testinfo>
test_generator=config/mercurium
</testinfo>
*/
typedef unsigned char T;
typedef unsigned char S;
typedef T(F)(S);
F *a = 0;
| 1,351 | C | .c | 29 | 42.862069 | 70 | 0.688411 | bsc-pm/mcxx | 69 | 23 | 11 | LGPL-3.0 | 9/7/2024, 9:45:36 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,115,085 | flogger.c | teuben_nemo/usr/lib/flogger/flogger.c |
/*
NAME
flogger
DESCRIPTION
Put the sort routines through the paces. Verify that they actually
order data properly and that they don't molest the memory locations
immediately above or below the array. Tries some common worst-case
situations like already-ordered data and comparison functions which
are defective.
Prints out estimates for each sort algorithm for usage of heap space,
stack space, and run time and also for the number of calls to the
comparison function.
Takes one command line argument which specifies the number of items
to put in the array. Larger values take longer to run.
AUTHORSHIP
Mike Lee, currently [email protected]
REFERENCES
Knuth, Art of Computer Programming Vol 3: Searching and Sorting
Kernighan & Richtie, The C Programming Language, Second Edition
WORK REMAINING
The main loop is hopeless.
See the TODO document (which should accompany this program.)
COPYRIGHT
Copyright 1992 Michael Lee.
(1) Permission to use, copy, distribute, and make changes is granted
providing that (a) that you do so without charging anyone a fee and
(b) this copyright notice must be included verbatim in all copies and
distributions.
(2) There is no warranty for this program, to the extent permitted by
applicable law. This program is provided "AS IS" without warranty of
any kind, either expressed or implied, including, but not limited to,
the implied warranties of merchantability and fitness for a particular
purpose. The entire risk as to the quality and performance of this
program is with the user. Should this program prove defective, the
user assumes the cost of all necessary servicing, repair or correction.
(3) In no event unless required by applicable law will the copyright
holder be liable to the user for damages, including any general,
special, incidental or consequential damages arising out of the use
or inability to use this program (including but not limited to loss of
data or data being rendered inaccurate or losses sustained by the
user or third parties or a failure of this program to operate with any
other programs), even if such holder or third party has been advised
of the possibility of such damages.
(4) Object code produced by a compiler from this code may be
incorporated into commercial products without being subject to
restrictions (1)(a) or (1)(b).
*/
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <signal.h>
#include <setjmp.h>
#include <sys/types.h>
#include <sys/times.h>
#include <sys/param.h>
#include "sorting.h"
#define TEST_TYPE double
#define TEST_FUNC double_compare
#define DEFAULT_COUNT 2220 /* product of 4 and several primes */
#define CANARY_LOW -77.0
#define CANARY_HIGH -88.0
#define TEST_RANDOM 1
#define TEST_ASCEND 2
#define TEST_DESCEND 3
#define TEST_FIB_ASC 4
#define TEST_FIB_DESC 5
#define TEST_SURPRISE 6
#define TEST_MOSTLY 7
#define TEST_EQUIV 8
static int compare_count;
static int s_heap;
static char * s_low, * s_high;
#define CHECK_CANARIES \
{ \
if (*(TEST_TYPE *) a == CANARY_LOW || *(TEST_TYPE *) b == CANARY_LOW)\
{ \
printf("ran off the bottom of the array!\n"); \
fflush(stdout); \
longjmp(next, 1); \
} \
if (*(TEST_TYPE *) a == CANARY_HIGH || *(TEST_TYPE *) b == CANARY_HIGH)\
{ \
printf("ran off the top of the array!\n"); \
fflush(stdout); \
longjmp(next, 1); \
} \
}
#define UPDATE_S_HEAP \
{ struct mallinfo mi; \
mi = mallinfo(); \
if (s_heap < mi.uordblks) s_heap = mi.uordblks; \
if (s_low == NULL || where < s_low) s_low = where; \
if (s_high == NULL || where > s_high) s_high = where; \
compare_count ++; }
static jmp_buf next;
void catch_quit()
{
printf("\n");
fflush(stdout);
longjmp(next, 1);
}
void test_sort_func();
int int_compare(a, b) int * a, *b;
{
char foo;
char * where = &foo;
CHECK_CANARIES;
UPDATE_S_HEAP;
if (*a > *b) return 1;
if (*a < *b) return -1;
return 0;
}
int double_compare(a, b) double * a, *b;
{
char foo;
char * where = &foo;
CHECK_CANARIES;
UPDATE_S_HEAP;
if (*a > *b) return 1;
if (*a < *b) return -1;
return 0;
}
/*ARGSUSED*/
int lie_ascending(a, b) char * a, *b;
{
char foo;
char * where = &foo;
CHECK_CANARIES;
UPDATE_S_HEAP;
return -1;
}
/*ARGSUSED*/
int lie_descending(a, b) char * a, *b;
{
char foo;
char * where = &foo;
CHECK_CANARIES;
UPDATE_S_HEAP;
return 1;
}
/*ARGSUSED*/
int lie_equal(a, b) char * a, *b;
{
char foo;
char * where = &foo;
CHECK_CANARIES;
UPDATE_S_HEAP;
return 0;
}
/*ARGSUSED*/
int surprise(a, b) char * a, *b;
{
char foo;
char * where = &foo;
CHECK_CANARIES;
UPDATE_S_HEAP;
foo = rand() >> 23;
if ((unsigned char) foo < 85) return -1;
if ((unsigned char) foo < 171) return 0;
return 1;
}
int main(argc, argv) int argc; char * argv[];
{
int n;
int stage = 0;
int done = 0;
printf("sort flogger version %d patch level %d.\n",
FLOGGER_VERSION, FLOGGER_PATCHLEVEL);
if (argc > 1)
n = atoi(argv[1]);
else
n = DEFAULT_COUNT;
if (n < 0) n = -n;
printf("timer resolution = %1.6f\n", 1.0/(double)HZ);
printf("element size = %d\n", sizeof(TEST_TYPE));
printf("number of elements = %d", n);
fflush(stdout);
setjmp(next);
signal(SIGINT, catch_quit);
/* apologies for the bizarre code layout */
while (! done) switch (stage)
{
case 0: printf("\n*** qsort ***\n");
printf("data compares stack ");
printf("heap user system\n");
fflush(stdout);
stage ++; test_sort_func(qsort, n, 1); break;
case 1: stage ++; test_sort_func(qsort, n, 2); break;
case 2: stage ++; test_sort_func(qsort, n, 3); break;
case 3: stage ++; test_sort_func(qsort, n, 4); break;
case 4: stage ++; test_sort_func(qsort, n, 5); break;
case 5: stage ++; test_sort_func(qsort, n, 6); break;
case 6: stage ++; test_sort_func(qsort, n, 7); break;
case 7: stage ++; test_sort_func(qsort, n, 8); break;
case 10: _maybe_sorted = 0;
printf("\n*** merge_sort ***\n");
printf("data compares stack ");
printf("heap user system\n");
fflush(stdout);
stage ++; test_sort_func(merge_sort, n, 1); break;
case 11: stage ++; test_sort_func(merge_sort, n, 2); break;
case 12: stage ++; test_sort_func(merge_sort, n, 3); break;
case 13: stage ++; test_sort_func(merge_sort, n, 4); break;
case 14: stage ++; test_sort_func(merge_sort, n, 5); break;
case 15: stage ++; test_sort_func(merge_sort, n, 6); break;
case 16: stage ++; test_sort_func(merge_sort, n, 7); break;
case 17: stage ++; test_sort_func(merge_sort, n, 8); break;
case 20: _maybe_sorted = 1;
printf("\n*** merge_sort(_maybe_sorted) ***\n");
printf("data compares stack ");
printf("heap user system\n");
fflush(stdout);
stage ++; test_sort_func(merge_sort, n, 1); break;
case 21: stage ++; test_sort_func(merge_sort, n, 2); break;
case 22: stage ++; test_sort_func(merge_sort, n, 3); break;
case 23: stage ++; test_sort_func(merge_sort, n, 4); break;
case 24: stage ++; test_sort_func(merge_sort, n, 5); break;
case 25: stage ++; test_sort_func(merge_sort, n, 6); break;
case 26: stage ++; test_sort_func(merge_sort, n, 7); break;
case 27: stage ++; test_sort_func(merge_sort, n, 8); break;
case 30: printf("\n*** heap_sort ***\n");
printf("data compares stack ");
printf("heap user system\n");
fflush(stdout);
stage ++; test_sort_func(heap_sort, n, 1); break;
case 31: stage ++; test_sort_func(heap_sort, n, 2); break;
case 32: stage ++; test_sort_func(heap_sort, n, 3); break;
case 33: stage ++; test_sort_func(heap_sort, n, 4); break;
case 34: stage ++; test_sort_func(heap_sort, n, 5); break;
case 35: stage ++; test_sort_func(heap_sort, n, 6); break;
case 36: stage ++; test_sort_func(heap_sort, n, 7); break;
case 37: stage ++; test_sort_func(heap_sort, n, 8); break;
case 40: printf("\n*** shell_sort ***\n");
printf("data compares stack ");
printf("heap user system\n");
fflush(stdout);
stage ++; test_sort_func(shell_sort, n, 1); break;
case 41: stage ++; test_sort_func(shell_sort, n, 2); break;
case 42: stage ++; test_sort_func(shell_sort, n, 3); break;
case 43: stage ++; test_sort_func(shell_sort, n, 4); break;
case 44: stage ++; test_sort_func(shell_sort, n, 5); break;
case 45: stage ++; test_sort_func(shell_sort, n, 6); break;
case 46: stage ++; test_sort_func(shell_sort, n, 7); break;
case 47: stage ++; test_sort_func(shell_sort, n, 8); break;
case 50: printf("\n*** quick_sort ***\n");
printf("data compares stack ");
printf("heap user system\n");
fflush(stdout);
stage ++; test_sort_func(quick_sort, n, 1); break;
case 51: stage ++; test_sort_func(quick_sort, n, 2); break;
case 52: stage ++; test_sort_func(quick_sort, n, 3); break;
case 53: stage ++; test_sort_func(quick_sort, n, 4); break;
case 54: stage ++; test_sort_func(quick_sort, n, 5); break;
case 55: stage ++; test_sort_func(quick_sort, n, 6); break;
case 56: stage ++; test_sort_func(quick_sort, n, 7); break;
case 57: stage ++; test_sort_func(quick_sort, n, 8); break;
case 60: printf("\n*** insertion_sort ***\n");
printf("data compares stack ");
printf("heap user system\n");
fflush(stdout);
stage ++; test_sort_func(insertion_sort, n, 1); break;
case 61: stage ++; test_sort_func(insertion_sort, n, 2); break;
case 62: stage ++; test_sort_func(insertion_sort, n, 3); break;
case 63: stage ++; test_sort_func(insertion_sort, n, 4); break;
case 64: stage ++; test_sort_func(insertion_sort, n, 5); break;
case 65: stage ++; test_sort_func(insertion_sort, n, 6); break;
case 66: stage ++; test_sort_func(insertion_sort, n, 7); break;
case 67: stage ++; test_sort_func(insertion_sort, n, 8); break;
case 70: printf("\n*** bubble_sort ***\n");
printf("data compares stack ");
printf("heap user system\n");
fflush(stdout);
stage ++; test_sort_func(bubble_sort, n, 1); break;
case 71: stage ++; test_sort_func(bubble_sort, n, 2); break;
case 72: stage ++; test_sort_func(bubble_sort, n, 3); break;
case 73: stage ++; test_sort_func(bubble_sort, n, 4); break;
case 74: stage ++; test_sort_func(bubble_sort, n, 5); break;
case 75: stage ++; test_sort_func(bubble_sort, n, 6); break;
case 76: stage ++; test_sort_func(bubble_sort, n, 7); break;
case 77: stage ++; test_sort_func(bubble_sort, n, 8); break;
case 80: if (n >= 15)
{
stage += 10;
break; /* algorithm is factorial! give up! */
}
printf("\n*** bogo_sort ***\n");
printf("data compares stack ");
printf("heap user system\n");
fflush(stdout);
stage ++; test_sort_func(bogo_sort, n, 1); break;
case 81: stage ++; test_sort_func(bogo_sort, n, 2); break;
case 82: stage ++; test_sort_func(bogo_sort, n, 3); break;
case 83: stage ++; test_sort_func(bogo_sort, n, 4); break;
case 84: stage ++; test_sort_func(bogo_sort, n, 5); break;
case 85: stage ++; test_sort_func(bogo_sort, n, 6); break;
case 86: stage ++; test_sort_func(bogo_sort, n, 7); break;
case 87: stage ++; test_sort_func(bogo_sort, n, 8); break;
case 90: done = 1;
default: stage++;
}
return 0;
}
void test_sort_func(func, n, situation)
int (*func)();
int n;
int situation;
{
unsigned int i;
static TEST_TYPE * foo = NULL;
TEST_TYPE temp;
int (*fp)();
int old_heap;
struct tms start, finish;
/* in case of ctrl-c */
if (foo != NULL) free((char *) foo);
foo = (TEST_TYPE *) malloc((n+2) * sizeof(TEST_TYPE));
if (foo == NULL)
{
printf("insufficient memory to conduct test.\n");
exit(1);
}
/* store magic values above and below the array so that we
can verify the the sort didn't run off either end */
foo[0] = (TEST_TYPE) CANARY_LOW;
foo[n+1] = (TEST_TYPE) CANARY_HIGH;
srand((int) n);
/* initialize the contents of the array appropriately for
the situation we are presenting to the sort function */
for (i = 1; i <= n; i ++)
{
switch(situation)
{
case TEST_RANDOM:
case TEST_FIB_ASC:
case TEST_FIB_DESC:
case TEST_SURPRISE:
do {
foo[i] = rand();
} while (foo[i] == CANARY_LOW || foo[i] == CANARY_HIGH);
break;
case TEST_ASCEND:
case TEST_MOSTLY:
case TEST_EQUIV:
foo[i] = i;
break;
case TEST_DESCEND:
foo[i] = n - i;
break;
}
}
if (situation == TEST_MOSTLY && n > 0)
{
temp = foo[1];
foo[1] = foo[n];
foo[n] = temp;
}
compare_count = 0;
s_low = NULL;
s_high = NULL;
old_heap = mallinfo().uordblks;
s_heap = old_heap;
switch(situation)
{
case TEST_RANDOM: printf("random: "); fp = TEST_FUNC; break;
case TEST_ASCEND: printf("ascend: "); fp = TEST_FUNC; break;
case TEST_DESCEND: printf("descend: "); fp = TEST_FUNC; break;
case TEST_FIB_ASC: printf("fib asc: "); fp = lie_ascending; break;
case TEST_FIB_DESC: printf("fib desc: "); fp = lie_descending; break;
case TEST_SURPRISE: printf("surprise: "); fp = surprise; break;
case TEST_MOSTLY: printf("mostly: "); fp = TEST_FUNC; break;
case TEST_EQUIV: printf("equiv: "); fp = lie_equal; break;
default: fp = NULL; break;
}
fflush(stdout);
times(&start);
/* actually call the sort function */
(*func)((char *) &foo[1], (int) n, sizeof(TEST_TYPE), fp);
times(&finish);
/*
printf("\n");
for (i = 0; i < n; i ++) printf(i % 5 == 4 ? "%11d\n" : "%11d ", foo[i]);
printf("\n");
*/
/* print out one row of data */
printf("%11d", compare_count);
printf("%11ld", (long) (s_high - s_low));
printf("%11d", s_heap - old_heap);
printf("%11.2f",
(double) (finish.tms_utime - start.tms_utime) / (double) HZ);
printf("%11.2f",
(double) (finish.tms_stime - start.tms_stime) / (double) HZ);
fflush(stdout);
if (mallinfo().uordblks - old_heap != 0)
printf(" (%d leak!)", mallinfo().uordblks - old_heap);
printf("\n");
/* check the areas immediately above and immediately below
the array for contamination */
if (foo[0] != CANARY_LOW)
printf("wrote before beginning of array!\n");
if (foo[n+1] != CANARY_HIGH)
printf("wrote past end of array!\n");
/* if appropriate, make sure the data was actually sorted */
if (situation == TEST_RANDOM || situation == TEST_ASCEND ||
situation == TEST_DESCEND || situation == TEST_MOSTLY)
for (i = 2; i <= n; i ++)
{
if ((*TEST_FUNC)(&foo[i], &foo[i-1]) < 0)
{
printf("out of order at position %d\n", i);
break;
}
}
/* check for sortedness, but for this case it's not an error
just the normal behavior of the algorithm */
if (situation == TEST_EQUIV)
{
int stable = 1;
for (i = 2; i <= n && stable; i ++)
{
if ((*TEST_FUNC)(&foo[i], &foo[i-1]) < 0) stable = 0;
}
if (stable)
printf("algorithm appears to be stable.\n");
else
printf("algorithm is not stable.\n");
}
if (foo != NULL)
{
free((char *) foo);
foo = NULL;
}
return;
}
| 16,075 | C | .c | 434 | 32.052995 | 76 | 0.605329 | teuben/nemo | 57 | 42 | 60 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,115,086 | insert_sort.c | teuben_nemo/usr/lib/flogger/insert_sort.c |
/*
NAME
insertion sort
DESCRIPTION
Sorts by inserting each successive record into its proper place in
the preceeding, already sorted records. Perform a binary search on
the preceeding records to find where to insert the current record,
then shift all the records over to make room in the right place.
AUTHORSHIP
This is properly called the binary insertion sort and credit is
given for first publication to John Mauchly, 1946.
REFERENCES
Knuth, Art of Computer Programming Vol 3, page 83.
COMPLEXITY
O(n log n) comparisons
O(0.25 * n^2) memory operations
Iterative.
COPYRIGHT
Copyright 1992 Michael Lee.
(1) Permission to use, copy, distribute, and make changes is granted
providing that (a) that you do so without charging anyone a fee and
(b) this copyright notice must be included verbatim in all copies and
distributions.
(2) There is no warranty for this program, to the extent permitted by
applicable law. This program is provided "AS IS" without warranty of
any kind, either expressed or implied, including, but not limited to,
the implied warranties of merchantability and fitness for a particular
purpose. The entire risk as to the quality and performance of this
program is with the user. Should this program prove defective, the
user assumes the cost of all necessary servicing, repair or correction.
(3) In no event unless required by applicable law will the copyright
holder be liable to the user for damages, including any general,
special, incidental or consequential damages arising out of the use
or inability to use this program (including but not limited to loss of
data or data being rendered inaccurate or losses sustained by the
user or third parties or a failure of this program to operate with any
other programs), even if such holder or third party has been advised
of the possibility of such damages.
(4) Object code produced by a compiler from this code may be
incorporated into commercial products without being subject to
restrictions (1)(a) or (1)(b).
*/
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <assert.h>
#include "sorting.h"
int insertion_sort(base, nelem, width, cmpr_func)
char * base;
int nelem;
int width;
int (*cmpr_func)();
{
int i, top, middle, bottom;
int found, test;
char * temp;
temp = malloc(width);
assert(temp != NULL);
for (i = 1; i < nelem; i++)
{
/* binary search looking for place between base[0] and base[i-1] where
you can insert base[i] into in order. */
bottom = 0;
top = i-1;
middle = 0;
found = 0;
while (top >= bottom && ! found)
{
middle = (top+bottom) / 2;
test = (*cmpr_func)(base+middle*width, base+i*width);
if (test > 0)
top = middle - 1;
else if (test < 0)
{
middle ++;
bottom = middle;
}
else
{
middle ++;
found = 1;
}
}
/* make room at base[middle] for base[i] */
if (i != middle)
{
memcpy(temp, base+i*width, width);
memmove(base+middle*width+width, base+middle*width, (i-middle)*width);
memcpy(base+middle*width, temp, width);
}
}
if (temp != NULL) free(temp);
return 0;
}
| 3,298 | C | .c | 95 | 30.515789 | 76 | 0.705957 | teuben/nemo | 57 | 42 | 60 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,115,087 | bogo_sort.c | teuben_nemo/usr/lib/flogger/bogo_sort.c |
#undef TEST
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
#define RAND_MAX 32767
/*
In alt.folklore.computers, there has been a discussion of the worst
possible sorting algorithm, which has been called "bogosort".
My interpretation of the algorithm is this: Exchange two randomly
chosen elements of the array to be sorted. Check to see if the array
is in order. Iterate until done.
From what I've read, theoretical analysis of this algorithm gives it a
performance of O(n!), which means that the time to sort is
proportional to the factorial of the number of elements. And since
the algorithm is random in nature, it could range from instantaneous
(only two entries out of order, and it happens to exchange them first)
to to infinite (it might never succeed).
So, for kicks I coded up a bogosort routine.
In my testing, I discovered that the mean time to sort an array of ten
integers was 75 seconds (25MHz 486, Unix, gcc 2.1, "optimized").
Extrapolating from this, assuming O(n!), gives 312 days to sort 15
integers and 1,593,378 years to sort 20 integers. Someone with a much
faster machine than mine will have to verify these figures.
--
Richard Krehbiel [email protected]
OS/2 2.0 will do for me until AmigaDOS for the 386 comes along...
===== cut here ====== bogosort.c =====================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#define TRUE 1
#define FALSE 0
#if 0
#define range_rand(range) ((long)rand() * (long)range / (RAND_MAX + 1))
#if ! defined(range_rand)
int range_rand(range) int range;
{
return (long)rand() * (long)range / (RAND_MAX + 1);
}
#endif
#endif
/* bogo sort is sensitive to rand()'s repeating-lower-digits feature
plus the above macro and function gave me different results with
and without -O, so I replaced them with this slow but serviceable
function. */
int range_rand(range)
int range;
{
int result;
extern long random();
do {
result = (int) random();
}
while (result < 0);
result = result % range;
return result;
}
void swap_elem(elem1, elem2, elem_size)
register char *elem1;
register char *elem2;
register size_t elem_size;
{
/***
int temp;
temp = *(int*) elem1;
*(int*) elem1 = *(int*) elem2;
*(int*) elem2 = temp;
***/
while(elem_size-- > 0)
{
char temp;
temp = *elem1;
*elem1++ = *elem2;
*elem2++ = temp;
}
}
int in_order(base, n_elem, elem_size, compare)
register char *base;
register int n_elem;
register size_t elem_size;
int (*compare)();
{
while(--n_elem > 0)
{
if(compare(base, base+elem_size) > 0)
return FALSE;
base += elem_size;
}
return TRUE;
}
/*
The bogo() function:
This function is called with the same arguments as qsort. When it returns,
the elements of the given array are in order.
You may wish to call srand() before using bogosort.
*/
int bogo_sort(base, n_elem, elem_size, compare)
char *base;
int n_elem;
size_t elem_size;
int (*compare)();
{
assert(n_elem <= RAND_MAX);
while(!in_order(base, n_elem, elem_size, compare))
{
register char *elem1, *elem2;
elem1 = base + (range_rand(n_elem) * elem_size);
elem2 = base + (range_rand(n_elem) * elem_size);
swap_elem(elem1, elem2, elem_size);
}
}
#ifdef TEST
int array[100]; /* Up to 100 elements - no further */
int int_compare(i1, i2)
char *i1; char *i2;
{
return *(int *)i1 - *(int *)i2;
}
main(argc, argv)
int argc; char *argv[];
{
time_t now;
int n_elem;
int i;
if(argc < 2)
{
fprintf(stderr, "useage: %s <number of elements>\n",
argv[0]);
exit(EXIT_FAILURE);
}
n_elem = atoi(argv[1]);
if(n_elem > 100)
{
fprintf(stderr,
"No more than 100 elements, please (as if your life is that long...)\n");
exit(EXIT_FAILURE);
}
now = time((time_t *)NULL);
srandom(now);
fputs("Starting array:\n", stdout);
for(i = 0; i < n_elem; i++)
{
array[i] = random();
printf("%d ", array[i]);
}
fputs("\n", stdout);
bogo_sort((char *)array, n_elem, sizeof(int), int_compare);
fputs("Ending array:\n", stdout);
for(i = 0; i < n_elem; i++)
{
printf("%d ", array[i]);
}
fputs("\n", stdout);
}
#endif
| 4,211 | C | .c | 156 | 24.519231 | 77 | 0.677403 | teuben/nemo | 57 | 42 | 60 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,115,088 | merge_sort.c | teuben_nemo/usr/lib/flogger/merge_sort.c |
/*
NAME
merge sort
DESCRIPTION
Divide up the array into halves, then quarters, then eighths and so
on until it can be divided no more. Perform a "tape merge" on
adjacent sections, building up larger ordered subsections until
you're done.
This version has some nifty features:
1. It avoids mempcy for arrays of 4 byte or 8 bytes, so sorting
pointers, ints, longs, float, doubles, or appropriately size tiny
structures works quickly. Someday I will add merge2 and merge16
and round out the collection, but beyond that the savings are
questionable.
2. After the merges of subsections become larger than a certain
number of records, a quick check is made to see if the last item
of the first subsection is less than the first item of the second
subsection; in this case the array is already in order there so
there's no point in doing a merge of the two subsections. This
feature can be turned off by setting _maybe_sorted to 0.
3. Array indexes and pointer math have been simplified to a degree.
A sophisticated compiler would have no trouble performing strength
reduction, but this way some improvement is available even if you
don't cc -O.
4. If it can't malloc the space it needs, it gives up and calls qsort().
AUTHORSHIP
Knuth mentions Von Neumann as the first person who implemented a
decent merge sort. Merge sort as an algorithm probably predates
electronic computers.
REFERENCES
John Von Neumann, Collected Works 5, 1963
Knuth, Art of Computer Programming Vol 3, pg 159-168
COMPLEXITY
O(n log n)
This code is recursive, although the algorithm can be (and often is)
implemented without recursion.
Unlike many sort algorithms, this takes 2n memory.
PORTABILITY PROBLEMS
My choice of sizes for special sort functions and for the
MAYBE_THRESHOLD aren't necessarily ideal for all computers
for all time.
The alignment check is hopelessly RISC-centric, but easy to remove.
COPYRIGHT
Copyright 1992 Michael Lee.
(1) Permission to use, copy, distribute, and make changes is granted
providing that (a) that you do so without charging anyone a fee and
(b) this copyright notice must be included verbatim in all copies and
distributions.
(2) There is no warranty for this program, to the extent permitted by
applicable law. This program is provided "AS IS" without warranty of
any kind, either expressed or implied, including, but not limited to,
the implied warranties of merchantability and fitness for a particular
purpose. The entire risk as to the quality and performance of this
program is with the user. Should this program prove defective, the
user assumes the cost of all necessary servicing, repair or correction.
(3) In no event unless required by applicable law will the copyright
holder be liable to the user for damages, including any general,
special, incidental or consequential damages arising out of the use
or inability to use this program (including but not limited to loss of
data or data being rendered inaccurate or losses sustained by the
user or third parties or a failure of this program to operate with any
other programs), even if such holder or third party has been advised
of the possibility of such damages.
(4) Object code produced by a compiler from this code may be
incorporated into commercial products without being subject to
restrictions (1)(a) or (1)(b).
*/
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include "sorting.h"
#ifdef PARANOID
#include <assert.h>
#endif
int _maybe_sorted = 1;
static int merge4();
static int merge8();
static int mergen();
int merge_sort(base, nelem, width, cmpr_func)
char * base;
int nelem;
int width;
int (*cmpr_func)();
{
if (width == sizeof(chunk4) && (int) base % sizeof(chunk4) == 0)
return merge4((chunk4 *) base, nelem, cmpr_func);
else if (width == sizeof(chunk8) && (int) base % sizeof(chunk8) == 0)
return merge8((chunk8 *) base, nelem, cmpr_func);
else
return mergen(base, nelem, width, cmpr_func);
}
static int merge4(base, nelem, cmpr_func)
chunk4 * base;
int nelem;
int (*cmpr_func)();
{
int split;
int a, b;
chunk4 * c;
int in_order;
static chunk4 * out = NULL;
int mine = 0;
if (out == NULL)
{
out = (chunk4 *) malloc(nelem * sizeof(chunk4));
if (out == NULL)
{
qsort((char *) base, nelem, sizeof(chunk4), cmpr_func);
return 0;
}
mine = 1;
}
split = (nelem+1) / 2;
if (split > 1)
(void) merge4(base, split, cmpr_func);
if (nelem - split > 1)
(void) merge4(base+split, nelem-split, cmpr_func);
if (_maybe_sorted && nelem > MAYBE_THRESHOLD &&
(*cmpr_func)(base+split, base+split-1) >= 0)
{
if (mine)
{
free((char *) out);
out = NULL;
}
return 0;
}
a = 0;
b = split;
c = out;
while(a < split)
{
if (b >= nelem)
in_order = 1;
else
in_order = ((*cmpr_func)(base+a, base+b) <= 0);
if (in_order)
{
*c = *(base + a);
c ++;
a ++;
}
else
{
*c = *(base + b);
c ++;
b ++;
}
#ifdef PARANOID
assert(c - out <= nelem);
#endif
}
#ifdef PARANOID
assert(c - out <= nelem);
#endif
for (a = 0; a < c - out; a ++) base[a] = out[a];
if (mine)
{
free((char *) out);
out = NULL;
}
return 0;
}
static int merge8(base, nelem, cmpr_func)
chunk8 * base;
int nelem;
int (*cmpr_func)();
{
int split;
int a, b;
chunk8 * c;
int in_order;
static chunk8 * out = NULL;
int mine = 0;
if (out == NULL)
{
out = (chunk8 *) malloc(nelem * sizeof(chunk8));
if (out == NULL)
{
qsort((char *) base, nelem, sizeof(chunk8), cmpr_func);
return 0;
}
mine = 1;
}
split = (nelem+1) / 2;
if (split > 1)
(void) merge8(base, split, cmpr_func);
if (nelem - split > 1)
(void) merge8(base+split, nelem-split, cmpr_func);
if (_maybe_sorted && nelem > MAYBE_THRESHOLD &&
(*cmpr_func)(base+split, base+split-1) >= 0)
{
if (mine)
{
free((char *) out);
out = NULL;
}
return 0;
}
a = 0;
b = split;
c = out;
while(a < split)
{
if (b >= nelem)
in_order = 1;
else
in_order = ((*cmpr_func)(base+a, base+b) <= 0);
if (in_order)
{
*c = *(base + a);
c ++;
a ++;
}
else
{
*c = *(base + b);
c ++;
b ++;
}
#ifdef PARANOID
assert(c - out <= nelem);
#endif
}
#ifdef PARANOID
assert(c - out <= nelem);
#endif
for (a = 0; a < c - out; a ++) base[a] = out[a];
if (mine)
{
free((char *) out);
out = NULL;
}
return 0;
}
static int mergen(base, nelem, width, cmpr_func)
char * base;
int nelem;
int (*cmpr_func)();
int width;
{
int split, nw, sw;
int a, b;
char * c;
int in_order;
static char * out = NULL;
int mine = 0;
nw = nelem*width;
if (out == NULL)
{
out = (char *) malloc(nw);
if (out == NULL)
{
qsort(base, nelem, width, cmpr_func);
return 0;
}
mine = 1;
}
split = (nelem+1) / 2;
sw = split*width;
if (split > 1)
(void) mergen(base, split, width, cmpr_func);
if (nelem - split > 1)
(void) mergen(base+sw, nelem-split, width, cmpr_func);
if (_maybe_sorted && nelem > MAYBE_THRESHOLD &&
(*cmpr_func)(base+sw, base+sw-width) >= 0)
{
if (mine)
{
free(out);
out = NULL;
}
return 0;
}
a = 0;
b = sw;
c = out;
while(a < sw)
{
if (b >= nw)
in_order = 1;
else
in_order = ((*cmpr_func)(base+a, base+b) <= 0);
/* todo: try coalescing adjacent iterations into the
same call to memcpy when in_order is the same */
if (in_order)
{
memcpy(c, base+a, width);
c += width;
a += width;
}
else
{
memcpy(c, base+b, width);
c += width;
b += width;
}
#ifdef PARANOID
assert(c - out <= nelem * width);
#endif
}
#ifdef PARANOID
assert(c - out <= nelem * width);
#endif
memcpy(base, out, c - out);
if (mine)
{
free(out);
out = NULL;
}
return 0;
}
| 8,283 | C | .c | 313 | 22.236422 | 74 | 0.640687 | teuben/nemo | 57 | 42 | 60 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | true | true | false | false |
2,115,089 | heap_sort.c | teuben_nemo/usr/lib/flogger/heap_sort.c |
/*
NAME
heap sort
DESCRIPTION
See some of the comments below for a partial description.
AUTHORSHIP
This version was written by [email protected]
who has gracefully given me permission to include it in
this package of sort algorithms.
The original heapsort is credited to Williams by Knuth and
some improvements are credited to Floyd by Standish.
REFERENCES
J. W. J. Williams, CACM 7 1964
R. W. Floyd, Algorithm 245: Treesort 3, CACM 7:12 December, 1964
Knuth, Art of Computer Programming Vol 3, page 145ff
Thomas A. Standish, Data Structure Techniques, page 91-92
COMPLEXITY
O(n log n)
Iterative.
COPYRIGHT
Questions about the copyright status of should be addressed
to the author.
*/
#include <stdio.h>
#include <malloc.h>
#include <string.h>
/* this is an interface routine that takes a parameter
list like qsort's and then calls the real heapsort. */
int heap_sort(base, nelem, width, cmpr_func)
char * base;
int nelem;
int width;
int (*cmpr_func)();
{
char ** temp_in;
char * temp_out;
int i;
temp_in = (char **) malloc(nelem * sizeof(char *));
for (i = 0; i < nelem; i++)
temp_in[i] = base+i*width;
heapsort(temp_in, nelem, cmpr_func);
temp_out = malloc(nelem * width);
for (i = 0; i < nelem; i++)
memcpy(temp_out+i*width, temp_in[i], width);
memcpy(base, temp_out, nelem*width);
free((char *) temp_in);
free(temp_out);
return 0;
}
/*
From uunet!Thunder.McRCIM.McGill.EDU!mouse Fri Nov 20 04:41:30 1992
Date: Fri, 20 Nov 92 05:13:19 -0500
From: der Mouse <uunet!Thunder.McRCIM.McGill.EDU!mouse>
To: [email protected]
Subject: Re: qucik, merge, shell and bubble sort
Status: R
> I'll also be adding heapsort and shellsort algorithms; if anyone has
> a qsort-like drop-in replacement for either or both of those I'd
> appreciate a copy.
Note the interface difference (an extra level of pointers, which is a
bit of a pain because it often means allocating an array of char *),
but here's a heapsort I've been using. (I wrote it.)
*/
#if 0
heapsort(ptrs,nels,cmp)
char **ptrs; /* should be `<unknown>**ptrs', but no such type exists */
int nels;
int (*cmp)();
#endif
/*
Sorts the ptrs vector. (*cmp)(ptrs[i],ptrs[j]) should return:
< 0 if *ptrs[i] < *ptrs[j]
= 0 if *ptrs[i] = *ptrs[j]
> 0 if *ptrs[i] > *ptrs[j]
For example, if the ptrs are actually pointers to int, it would
be perfectly good to write a cmp function as follows (unless the
integers are so large that overflow can occur in the subtraction):
int cmp(p1,p2)
char *p1;
char *p2;
{
return(*(int *)p1 - *(int *)p2);
}
Tip: If the ptrs are character string pointers, the standard
strcmp() function is a good cmp function.
The vector will be in non-decreasing order by this criterion on
return from heapsort.
*/
static _heapsort_bubble_up(size,ptrs,cmp)
int size;
char **ptrs;
int (*cmp)();
{
int i;
int p;
char *temp;
i = size;
while (1)
{ if (i == 0)
{ return;
}
p = (i - 1) >> 1;
if ((*cmp)(ptrs[i],ptrs[p]) > 0)
{ temp = ptrs[i];
ptrs[i] = ptrs[p];
ptrs[p] = temp;
i = p;
}
else
{ return;
}
}
}
static _heapsort_bubble_down(size,ptrs,cmp)
int size;
char **ptrs;
int (*cmp)();
{
int i;
int j;
int l;
int r;
int cl;
int cr;
char *temp;
i = 0;
while (1)
{ if (i >= size)
{ return;
}
l = i + i + 1;
r = l + 1;
cl = (l >= size) ? 1 : ((*cmp)(ptrs[i],ptrs[l]) >= 0);
cr = (r >= size) ? 1 : ((*cmp)(ptrs[i],ptrs[r]) >= 0);
switch ((cl<<1)|cr)
{ case 0:
j = ((*cmp)(ptrs[l],ptrs[r]) > 0) ? l : r;
break;
case 1:
j = l;
break;
case 2:
j = r;
break;
case 3:
return;
}
temp = ptrs[j];
ptrs[j] = ptrs[i];
ptrs[i] = temp;
i = j;
}
}
heapsort(ptrs,nels,cmp)
char **ptrs;
int nels;
int (*cmp)();
{
int size;
char *temp;
if (nels <= 1)
{ return;
}
size = 1;
while (size < nels)
{ _heapsort_bubble_up(size,ptrs,cmp);
size ++;
}
while (size > 1)
{ size --;
temp = ptrs[size];
ptrs[size] = ptrs[0];
ptrs[0] = temp;
_heapsort_bubble_down(size,ptrs,cmp);
}
}
| 4,436 | C | .c | 176 | 20.8125 | 74 | 0.605974 | teuben/nemo | 57 | 42 | 60 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,115,090 | quick_sort.c | teuben_nemo/usr/lib/flogger/quick_sort.c |
/*
NAME
quicksort, or partition exchange sort
DESCRIPTION
Sort by partitioning, then sort the partitions, and so on.
AUTHORSHIP
C. A. R. Hoare.
This particular implementation is taken from K&R2.
REFERENCES
Hoare, Comp. J. 5, 1962
Knuth, Vol 3, page 114ff
Kernighan & Ritchie The C Programming Language, Revised Edition, pg 87
Standish, Data Structure Techniques pg 23-27
Sedgewick, Implementing Quicksort Programs CACM 21:10 October 1978
COMPLEXITY
Best case O(n log n)
Worse case O(n^2)
Recursive.
PORTABILITY PROBLEMS
Same problems as with merge_sort.
COPYRIGHT
Copyright 1992 Michael Lee.
(1) Permission to use, copy, distribute, and make changes is granted
providing that (a) that you do so without charging anyone a fee and
(b) this copyright notice must be included verbatim in all copies and
distributions.
(2) There is no warranty for this program, to the extent permitted by
applicable law. This program is provided "AS IS" without warranty of
any kind, either expressed or implied, including, but not limited to,
the implied warranties of merchantability and fitness for a particular
purpose. The entire risk as to the quality and performance of this
program is with the user. Should this program prove defective, the
user assumes the cost of all necessary servicing, repair or correction.
(3) In no event unless required by applicable law will the copyright
holder be liable to the user for damages, including any general,
special, incidental or consequential damages arising out of the use
or inability to use this program (including but not limited to loss of
data or data being rendered inaccurate or losses sustained by the
user or third parties or a failure of this program to operate with any
other programs), even if such holder or third party has been advised
of the possibility of such damages.
(4) Object code produced by a compiler from this code may be
incorporated into commercial products without being subject to
restrictions (1)(a) or (1)(b).
*/
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <assert.h>
#include "sorting.h"
static char * copy_buffer = NULL;
static int quick_sortn();
static int quick_sort4();
static int quick_sort8();
int quick_sort(base, nelem, width, cmpr_func)
char * base;
int nelem;
int width;
int (*cmpr_func)();
{
copy_buffer = malloc(width);
assert(copy_buffer != NULL);
if (width == sizeof(chunk4) && (long) base % sizeof(chunk4) == 0)
quick_sort4((chunk4 *) base, cmpr_func, 0, nelem-1);
else if (width == sizeof(chunk8) && (long) base % sizeof(chunk8) == 0)
quick_sort8((chunk8 *) base, cmpr_func, 0, nelem-1);
else
quick_sortn(base, width, cmpr_func, 0, nelem-1);
free(copy_buffer);
copy_buffer = NULL;
}
static quick_sortn(base, width, cmpr_func, left, right)
char * base;
int width;
int (*cmpr_func)();
int left, right;
{
int i, last;
int half = (left+right)/2;
if (left >= right) return;
memcpy(copy_buffer, base+width*left, width);
memcpy(base+width*left, base+width*half, width);
memcpy(base+width*half, copy_buffer, width);
last = left;
for (i = left + 1; i <= right; i++)
if ((*cmpr_func)(base+width*i, base+width*left) < 0)
{
last ++;
if (last == i) continue;
memcpy(copy_buffer, base+width*last, width);
memcpy(base+width*last, base+width*i, width);
memcpy(base+width*i, copy_buffer, width);
}
memcpy(copy_buffer, base+width*left, width);
memcpy(base+width*left, base+width*last, width);
memcpy(base+width*last, copy_buffer, width);
quick_sortn(base, width, cmpr_func, left, last-1);
quick_sortn(base, width, cmpr_func, last+1, right);
}
static quick_sort4(base, cmpr_func, left, right)
chunk4 * base;
int (*cmpr_func)();
int left, right;
{
int i, last;
chunk4 temp;
if (left >= right) return;
temp = base[left];
base[left] = base[(left+right)/2];
base[(left+right)/2] = temp;
last = left;
for (i = left + 1; i <= right; i++)
if ((*cmpr_func)(&base[i], &base[left]) < 0)
{
last ++;
if (last == i) continue;
temp = base[last];
base[last] = base[i];
base[i] = temp;
}
temp = base[left];
base[left] = base[last];
base[last] = temp;
quick_sort4(base, cmpr_func, left, last-1);
quick_sort4(base, cmpr_func, last+1, right);
}
static quick_sort8(base, cmpr_func, left, right)
chunk8 * base;
int (*cmpr_func)();
int left, right;
{
int i, last;
chunk8 temp;
if (left >= right) return;
temp = base[left];
base[left] = base[(left+right)/2];
base[(left+right)/2] = temp;
last = left;
for (i = left + 1; i <= right; i++)
if ((*cmpr_func)(&base[i], &base[left]) < 0)
{
last ++;
if (last == i) continue;
temp = base[last];
base[last] = base[i];
base[i] = temp;
}
temp = base[left];
base[left] = base[last];
base[last] = temp;
quick_sort8(base, cmpr_func, left, last-1);
quick_sort8(base, cmpr_func, last+1, right);
}
| 5,105 | C | .c | 154 | 29.603896 | 73 | 0.687946 | teuben/nemo | 57 | 42 | 60 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,115,091 | bubble_sort.c | teuben_nemo/usr/lib/flogger/bubble_sort.c |
/*
NAME
bubble sort
DESCRIPTION
Traipse up and down the records until the entire array is in order
exchanging records with their neighbors if the adjacent records are
out of order with respect to each other. A flag keeps track of
whether exchanges were done; when an entire pass is made and no
exchanges were performed, the sort is complete. Also, after each
pass, the element at the end of the pass is guaranteed to be in it's
final place so the next pass excludes it.
This algorithm reverses direction on each pass, so that a single item
out of order won't force worst-case behavior. Knuth refers to this
as the "cocktail shaker sort."
AUTHORSHIP
Unknown to me.
REFERENCES
Knuth Vol 3, page 106-111
COMPLEXITY
Best case O(n)
Worst case O(n^2)
Iterative.
COPYRIGHT
Copyright 1992 Michael Lee.
(1) Permission to use, copy, distribute, and make changes is granted
providing that (a) that you do so without charging anyone a fee and
(b) this copyright notice must be included verbatim in all copies and
distributions.
(2) There is no warranty for this program, to the extent permitted by
applicable law. This program is provided "AS IS" without warranty of
any kind, either expressed or implied, including, but not limited to,
the implied warranties of merchantability and fitness for a particular
purpose. The entire risk as to the quality and performance of this
program is with the user. Should this program prove defective, the
user assumes the cost of all necessary servicing, repair or correction.
(3) In no event unless required by applicable law will the copyright
holder be liable to the user for damages, including any general,
special, incidental or consequential damages arising out of the use
or inability to use this program (including but not limited to loss of
data or data being rendered inaccurate or losses sustained by the
user or third parties or a failure of this program to operate with any
other programs), even if such holder or third party has been advised
of the possibility of such damages.
(4) Object code produced by a compiler from this code may be
incorporated into commercial products without being subject to
restrictions (1)(a) or (1)(b).
*/
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <assert.h>
#include "sorting.h"
int bubble_sort(base, nelem, width, cmpr_func)
char * base;
int nelem;
int width;
int (*cmpr_func)();
{
int top = nelem - 1;
int bottom = 0;
int i, did_swap = 1;
char * temp;
temp = malloc(width);
assert(temp != NULL);
while (top > bottom)
{
did_swap = 0;
for (i = bottom; i < top; i++)
if ((*cmpr_func)(base+i*width, base+(i+1)*width) > 0)
{
memcpy(temp, base+i*width, width);
memcpy(base+i*width, base+(i+1)*width, width);
memcpy(base+(i+1)*width, temp, width);
did_swap = 1;
}
if (!did_swap) break;
top--;
did_swap = 0;
for (i = top - 1; i >= bottom; i--)
if ((*cmpr_func)(base+i*width, base+(i+1)*width) > 0)
{
memcpy(temp, base+i*width, width);
memcpy(base+i*width, base+(i+1)*width, width);
memcpy(base+(i+1)*width, temp, width);
did_swap = 1;
}
if (!did_swap) break;
bottom ++;
}
free(temp);
return 0;
}
| 3,389 | C | .c | 93 | 32.462366 | 73 | 0.709302 | teuben/nemo | 57 | 42 | 60 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,115,092 | shell_sort.c | teuben_nemo/usr/lib/flogger/shell_sort.c |
/*
NAME
shell sort
DESCRIPTION
An exhange sort algorithm which exchanges over larger distances
than bubble sort, thus reducing the number of exchanges needed.
AUTHORSHIP
D. L. Shell
REFERENCES
D. L. Shell, CACM 2, July 1959
Kernighan & Ritchie, C Programming Language, Second Edition, pg 62
Knuth, Art of Computer Programming Vol 3, pg 84-95
COMPLEXITY
I'm not exactly sure, but I think it's O(N^1.5)
Iterative.
COPYRIGHT
Copyright 1992 Michael Lee.
(1) Permission to use, copy, distribute, and make changes is granted
providing that (a) that you do so without charging anyone a fee and
(b) this copyright notice must be included verbatim in all copies and
distributions.
(2) There is no warranty for this program, to the extent permitted by
applicable law. This program is provided "AS IS" without warranty of
any kind, either expressed or implied, including, but not limited to,
the implied warranties of merchantability and fitness for a particular
purpose. The entire risk as to the quality and performance of this
program is with the user. Should this program prove defective, the
user assumes the cost of all necessary servicing, repair or correction.
(3) In no event unless required by applicable law will the copyright
holder be liable to the user for damages, including any general,
special, incidental or consequential damages arising out of the use
or inability to use this program (including but not limited to loss of
data or data being rendered inaccurate or losses sustained by the
user or third parties or a failure of this program to operate with any
other programs), even if such holder or third party has been advised
of the possibility of such damages.
(4) Object code produced by a compiler from this code may be
incorporated into commercial products without being subject to
restrictions (1)(a) or (1)(b).
*/
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <assert.h>
#include "sorting.h"
int shell_sort(base, nelem, width, cmpr_func)
char * base;
int nelem;
int width;
int (*cmpr_func)();
{
int gap, i, j;
char * temp;
temp = malloc(width);
assert(temp != NULL);
for (gap = nelem / 2; gap > 0; gap /= 2)
{
for (i = gap; i < nelem; i++)
{
for (j = i-gap;
j >=0 && (*cmpr_func)(base+j*width, base+(j+gap)*width) > 0;
j -= gap)
{
memcpy(temp, base+j*width, width);
memcpy(base+j*width, base+(j+gap)*width, width);
memcpy(base+(j+gap)*width, temp, width);
}
}
}
if (temp != NULL) free(temp);
return 0;
}
| 2,668 | C | .c | 73 | 32.780822 | 73 | 0.718677 | teuben/nemo | 57 | 42 | 60 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,235,957 | gp2x.c | KS-Presto_Wolf4SDL/GP2X/gp2x.c | //
// GP2X specific code
//
// by Pickle
//
#if defined(GP2X)
#include "gp2x.h"
static bool volume_init = false;
static unsigned int screenshot_count = 0;
#if defined(GP2X_940)
static int volume = 70;
#else
static int volume = 10;
#endif
static int intUp = 0;
static int intDown = 0;
static int intLeft = 0;
static int intRight = 0;
static int intUpRight = 0;
static int intUpLeft = 0;
static int intDownRight = 0;
static int intDownLeft = 0;
static int intButtonR = 0;
static int intButtonL = 0;
static int intButtonA = 0;
static int intButtonB = 0;
static int intButtonX = 0;
static int intButtonY = 0;
static int intButtonSel = 0;
static int intButtonSrt = 0;
static int intButtonStick = 0;
#if defined(GP2X_940)
void GP2X_Shutdown(void)
{
YM3812Shutdown();
}
void GP2X_MemoryInit( void )
{
SDL_GP2X_AllowGfxMemory(NULL,0);
}
#endif
void GP2X_AdjustVolume( int direction )
{
if( volume <= 10 )
{
if( direction == VOLUME_UP ) volume += VOLUME_CHANGE_RATE/2;
if( direction == VOLUME_DOWN ) volume -= VOLUME_CHANGE_RATE/2;
}
else
{
if( direction == VOLUME_UP ) volume += VOLUME_CHANGE_RATE;
if( direction == VOLUME_DOWN ) volume -= VOLUME_CHANGE_RATE;
}
if( volume < VOLUME_MIN ) volume = VOLUME_MIN;
if( volume > VOLUME_MAX ) volume = VOLUME_MAX;
printf( "Volume Change: %i\n", volume );
unsigned long soundDev = open("/dev/mixer", O_RDWR);
if(soundDev)
{
int vol = ((volume << 8) | volume);
ioctl(soundDev, SOUND_MIXER_WRITE_PCM, &vol);
close(soundDev);
}
}
void GP2X_ButtonDown( int button )
{
if( !volume_init )
{
GP2X_AdjustVolume(VOLUME_NOCHG);
volume_init = 1;
}
switch( button )
{
case GP2X_BUTTON_UP: intUp = 1; break;
case GP2X_BUTTON_DOWN: intDown = 1; break;
case GP2X_BUTTON_RIGHT: intRight = 1; break;
case GP2X_BUTTON_LEFT: intLeft = 1; break;
case GP2X_BUTTON_UPRIGHT: intUpRight = 1; break;
case GP2X_BUTTON_UPLEFT: intUpLeft = 1; break;
case GP2X_BUTTON_DOWNRIGHT: intDownRight = 1; break;
case GP2X_BUTTON_DOWNLEFT: intDownLeft = 1; break;
case GP2X_BUTTON_SELECT: intButtonSel = 1; break;
case GP2X_BUTTON_START: intButtonSrt = 1; break;
case GP2X_BUTTON_X: intButtonX = 1; LastASCII = 'x'; break;
case GP2X_BUTTON_Y: intButtonY = 1; LastASCII = 'y'; break;
case GP2X_BUTTON_A: intButtonA = 1; LastASCII = 'a'; break;
case GP2X_BUTTON_B: intButtonB = 1; LastASCII = 'b'; break;
case GP2X_BUTTON_R: intButtonR = 1; break;
case GP2X_BUTTON_L: intButtonL = 1; break;
case GP2X_BUTTON_VOLUP: GP2X_AdjustVolume( VOLUME_UP ); break;
case GP2X_BUTTON_VOLDOWN: GP2X_AdjustVolume( VOLUME_DOWN ); break;
case GP2X_BUTTON_CLICK: intButtonStick = 1; break;
}
if( intButtonL & intButtonR )
{
// Status Bar
SetKeyboard( SDLK_TAB, KEY_DOWN );
// Music Player (doesnt work, it appears the event's arnt happening soon enough)
SetKeyboard( sc_M, KEY_DOWN );
SetKeyboard( SDLK_LALT, KEY_UP );
SetKeyboard( SDLK_LEFT, KEY_UP );
SetKeyboard( SDLK_RIGHT, KEY_UP );
}
else if( intButtonL & !intButtonR )
{
// Strafe Left
SetKeyboard( SDLK_LALT, KEY_DOWN );
SetKeyboard( SDLK_LEFT, KEY_DOWN );
}
else if( intButtonR & !intButtonL )
{
// Strafe Right
SetKeyboard( SDLK_LALT, KEY_DOWN );
SetKeyboard( SDLK_RIGHT, KEY_DOWN );
}
// Left Direction
if( intLeft | intDownLeft | intUpLeft )
{
// UNstrafe
SetKeyboard( SDLK_LALT, KEY_UP );
SetKeyboard( SDLK_RIGHT, KEY_UP );
// Turn
SetKeyboard( SDLK_LEFT, KEY_DOWN );
}
// Right Direction
if( intRight | intDownRight | intUpRight )
{
// UNstrafe
SetKeyboard( SDLK_LALT, KEY_UP );
SetKeyboard( SDLK_LEFT, KEY_UP );
// Turn
SetKeyboard( SDLK_RIGHT, KEY_DOWN );
}
// Up Direction
if( intUp | intUpRight | intUpLeft ) {
SetKeyboard( SDLK_UP, KEY_DOWN );
}
// Down Direction
if( intDown | intDownRight | intDownLeft ) {
SetKeyboard( SDLK_DOWN, KEY_DOWN );
}
if( intButtonSel & intButtonSrt ) {
// Pause
SetKeyboard( SDLK_PAUSE, KEY_DOWN );
}
else if( intButtonL & intButtonSel ) {
fpscounter ^= 1; // Turn On FPS Counter
}
else if( intButtonL & intButtonSrt ) {
Screenshot();
}
else if( intButtonSel & !intButtonSrt ) {
// Escape
SetKeyboard( SDLK_ESCAPE, KEY_DOWN );
}
else if( !intButtonSel & intButtonSrt ) {
// Enter
SetKeyboard( SDLK_RETURN, KEY_DOWN );
}
if( intButtonX ) {
// Shoot
SetKeyboard( SDLK_LCTRL, KEY_DOWN );
}
if( intButtonY ) {
// Yes
SetKeyboard( SDLK_y, KEY_DOWN );
if( gamestate.chosenweapon == gamestate.bestweapon )
{
SetKeyboard( SDLK_1, KEY_DOWN );
}
else
{
SetKeyboard( SDLK_1 + gamestate.chosenweapon + 1, KEY_DOWN );
}
}
if( intButtonA ) {
// Open
SetKeyboard( SDLK_SPACE, KEY_DOWN );
}
if( intButtonB ) {
// No
SetKeyboard( SDLK_n, KEY_DOWN );
// Run
SetKeyboard( SDLK_LSHIFT, KEY_DOWN );
}
}
void GP2X_ButtonUp( int button )
{
switch( button )
{
case GP2X_BUTTON_UP: intUp = 0; break;
case GP2X_BUTTON_DOWN: intDown = 0; break;
case GP2X_BUTTON_RIGHT: intRight = 0; break;
case GP2X_BUTTON_LEFT: intLeft = 0; break;
case GP2X_BUTTON_UPRIGHT: intUpRight = 0; break;
case GP2X_BUTTON_UPLEFT: intUpLeft = 0; break;
case GP2X_BUTTON_DOWNRIGHT: intDownRight = 0; break;
case GP2X_BUTTON_DOWNLEFT: intDownLeft = 0; break;
case GP2X_BUTTON_SELECT: intButtonSel = 0; break;
case GP2X_BUTTON_START: intButtonSrt = 0; break;
case GP2X_BUTTON_X: intButtonX = 0; break;
case GP2X_BUTTON_Y: intButtonY = 0; break;
case GP2X_BUTTON_A: intButtonA = 0; break;
case GP2X_BUTTON_B: intButtonB = 0; break;
case GP2X_BUTTON_R: intButtonR = 0; break;
case GP2X_BUTTON_L: intButtonL = 0; break;
case GP2X_BUTTON_CLICK: intButtonStick = 0; break;
}
if( !intButtonL | !intButtonR )
{
SetKeyboard( SDLK_TAB, KEY_UP );
SetKeyboard( sc_M, KEY_UP );
SetKeyboard( SDLK_LALT, KEY_UP );
}
if( !intLeft & !intDownLeft & !intUpLeft )
{
if( !intButtonL )
{
SetKeyboard( SDLK_LALT, KEY_UP );
SetKeyboard( SDLK_LEFT, KEY_UP );
}
if( intButtonR )
{
SetKeyboard( SDLK_LALT, KEY_DOWN );
SetKeyboard( SDLK_RIGHT, KEY_DOWN );
}
}
if( !intRight & !intDownRight & !intUpRight )
{
if( !intButtonR )
{
SetKeyboard( SDLK_LALT, KEY_UP );
SetKeyboard( SDLK_RIGHT, KEY_UP );
}
if( intButtonL )
{
SetKeyboard( SDLK_LALT, KEY_DOWN );
SetKeyboard( SDLK_LEFT, KEY_DOWN );
}
}
if( !intUp & !intUpRight & !intUpLeft ) {
SetKeyboard( SDLK_UP, KEY_UP );
}
if( !intDown & !intDownRight & !intDownLeft ) {
SetKeyboard( SDLK_DOWN, KEY_UP );
}
if( !intButtonSel & !intButtonSrt ) {
SetKeyboard( SDLK_PAUSE, KEY_UP );
}
if( !intButtonSel ) {
SetKeyboard( SDLK_ESCAPE, KEY_UP );
}
if( !intButtonSrt ) {
SetKeyboard( SDLK_RETURN, KEY_UP );
}
if( !intButtonX ) {
SetKeyboard( SDLK_LCTRL, KEY_UP );
}
if( !intButtonY ) {
SetKeyboard( SDLK_y, KEY_UP );
SetKeyboard( SDLK_1, KEY_UP );
SetKeyboard( SDLK_2, KEY_UP );
SetKeyboard( SDLK_3, KEY_UP );
SetKeyboard( SDLK_4, KEY_UP );
}
if( !intButtonA ) {
SetKeyboard( SDLK_SPACE, KEY_UP );
}
if( !intButtonB ) {
SetKeyboard( SDLK_n, KEY_UP );
SetKeyboard( SDLK_LSHIFT, KEY_UP );
}
}
void Screenshot( void )
{
char filename[32];
snprintf( filename, sizeof(filename), "Screenshot_%i.bmp", screenshot_count );
SDL_SaveBMP(screen, filename );
screenshot_count++;
}
void SetKeyboard( unsigned int key, int press )
{
// press = 1 = down, press = 0 = up
if( press )
{
LastScan = key;
Keyboard[key] = 1;
}
else
{
Keyboard[key] = 0;
}
}
#endif // GP2X
| 7,976 | C | .c | 294 | 24.707483 | 82 | 0.64479 | KS-Presto/Wolf4SDL | 52 | 26 | 0 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,235,958 | fmopl.c | KS-Presto_Wolf4SDL/GP2X/fmopl.c | /*
** based on:
**
** File: fmopl.c - software implementation of FM sound generator
** types OPL and OPL2
**
** Copyright (C) 2002,2003 Jarek Burczynski (bujar at mame dot net)
** Copyright (C) 1999,2000 Tatsuyuki Satoh , MultiArcadeMachineEmulator development
**
** Version 0.70
**
** from the dosbox 0.72 source
*/
#define LOG_MSG printf
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include "fmopl.h"
#include "fmopl_940/fmopl_shared.h"
#ifndef PI
#define PI 3.14159265358979323846
#endif
/* output final shift */
#if (OPL_SAMPLE_BITS==16)
#define FINAL_SH (0)
#define MAXOUT (+32767)
#define MINOUT (-32768)
#else
#define FINAL_SH (8)
#define MAXOUT (+127)
#define MINOUT (-128)
#endif
#define FREQ_SH 16 /* 16.16 fixed point (frequency calculations) */
#define EG_SH 16 /* 16.16 fixed point (EG timing) */
#define LFO_SH 24 /* 8.24 fixed point (LFO calculations) */
#define TIMER_SH 16 /* 16.16 fixed point (timers calculations) */
#define FREQ_MASK ((1<<FREQ_SH)-1)
/* envelope output entries */
#define ENV_BITS 10
#define ENV_LEN (1<<ENV_BITS)
#define ENV_STEP (128.0/ENV_LEN)
#define MAX_ATT_INDEX ((1<<(ENV_BITS-1))-1) /*511*/
#define MIN_ATT_INDEX (0)
/* register number to channel number , slot offset */
#define SLOT1 0
#define SLOT2 1
/* Envelope Generator phases */
#define EG_ATT 4
#define EG_DEC 3
#define EG_SUS 2
#define EG_REL 1
#define EG_OFF 0
#define OPL_TYPE_WAVESEL 0x01 /* waveform select */
#define OPL_TYPE_ADPCM 0x02 /* DELTA-T ADPCM unit */
#define OPL_TYPE_KEYBOARD 0x04 /* keyboard interface */
#define OPL_TYPE_IO 0x08 /* I/O port */
/* ---------- Generic interface section ---------- */
#define OPL_TYPE_YM3526 (0)
#define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL)
#define OPL_TYPE_Y8950 (OPL_TYPE_ADPCM|OPL_TYPE_KEYBOARD|OPL_TYPE_IO)
#define WAIT_IF_MSG_BUF_FULL while( *NSubmittedMessages - *NExecutedMessages>= MSG_BUF_SIZE){};
#define WAIT_FOR_SYNC \
while( (*NSubmittedMessages - *NExecutedMessages) % (int) MSG_BUF_SIZE !=0 ){};
#define ADD_MESSAGE(mtype, i,j,k) \
{ \
int n = ((*NSubmittedMessages)+1) % ((int) MSG_BUF_SIZE); \
MessageBuffer[n].type=mtype; \
MessageBuffer[n].data1=i; \
MessageBuffer[n].data2=j; \
MessageBuffer[n].data3=k; \
(*NSubmittedMessages)++; \
}
//if((*NSubmittedMessages) % (int) 500 ==0)
// LOG_MSG("OPL2: %d %d %d\n",*NSubmittedMessages,*NExecutedMessages,*NSubmittedMessages-*NExecutedMessages);
typedef struct fm_opl_lite {
int T[2]; /* timer counters */
int TC[2];
UINT8 st[2]; /* timer enable */
UINT32 *fn_tab;
/* external event callback handlers */
OPL_TIMERHANDLER TimerHandler; /* TIMER handler */
int TimerParam; /* TIMER parameter */
OPL_IRQHANDLER IRQHandler; /* IRQ handler */
int IRQParam; /* IRQ parameter */
OPL_UPDATEHANDLER UpdateHandler; /* stream update handler */
int UpdateParam; /* stream update parameter */
UINT8 type; /* chip type */
UINT8 address; /* address register */
UINT8 status; /* status flag */
UINT8 statusmask; /* status mask */
UINT8 mode; /* Reg.08 : CSM,notesel,etc. */
int clock; /* master clock (Hz) */
int rate; /* sampling rate (Hz) */
double freqbase; /* frequency base */
double TimerBase; /* Timer base time (==sampling time)*/
} FM_OPLlite;
/* status set and IRQ handling */
inline void OPL_STATUS_SET(FM_OPLlite *OPL,int flag)
{
/* set status flag */
OPL->status |= flag;
if(!(OPL->status & 0x80))
{
if(OPL->status & OPL->statusmask)
{ /* IRQ on */
OPL->status |= 0x80;
/* callback user interrupt handler (IRQ is OFF to ON) */
if(OPL->IRQHandler) (OPL->IRQHandler)(OPL->IRQParam,1);
}
}
}
/* status reset and IRQ handling */
inline void OPL_STATUS_RESET(FM_OPLlite *OPL,int flag)
{
/* reset status flag */
OPL->status &=~flag;
if((OPL->status & 0x80))
{
if (!(OPL->status & OPL->statusmask) )
{
OPL->status &= 0x7f;
/* callback user interrupt handler (IRQ is ON to OFF) */
if(OPL->IRQHandler) (OPL->IRQHandler)(OPL->IRQParam,0);
}
}
}
/* IRQ mask set */
inline void OPL_STATUSMASK_SET(FM_OPLlite *OPL,int flag)
{
OPL->statusmask = flag;
/* IRQ handling check */
OPL_STATUS_SET(OPL,0);
OPL_STATUS_RESET(OPL,0);
}
/* generic table initialize */
static int init_tables(void)
{
signed int i,x;
signed int n;
double o,m;
for (x=0; x<TL_RES_LEN; x++)
{
m = (1<<16) / pow(2.0, (x+1) * (ENV_STEP/4.0) / 8.0);
m = floor(m);
/* we never reach (1<<16) here due to the (x+1) */
/* result fits within 16 bits at maximum */
n = (int)m; /* 16 bits here */
n >>= 4; /* 12 bits here */
if (n&1) /* round to nearest */
n = (n>>1)+1;
else
n = n>>1;
/* 11 bits here (rounded) */
n <<= 1; /* 12 bits here (as in real chip) */
tl_tab[ x*2 + 0 ] = n;
tl_tab[ x*2 + 1 ] = -tl_tab[ x*2 + 0 ];
for (i=1; i<12; i++)
{
tl_tab[ x*2+0 + i*2*TL_RES_LEN ] = tl_tab[ x*2+0 ]>>i;
tl_tab[ x*2+1 + i*2*TL_RES_LEN ] = -tl_tab[ x*2+0 + i*2*TL_RES_LEN ];
}
}
for (i=0; i<SIN_LEN; i++)
{
/* non-standard sinus */
m = sin( ((i*2)+1) * PI / SIN_LEN ); /* checked against the real chip */
/* we never reach zero here due to ((i*2)+1) */
if (m>0.0)
o = 8*log(1.0/m)/log(2.0); /* convert to 'decibels' */
else
o = 8*log(-1.0/m)/log(2.0); /* convert to 'decibels' */
o = o / (ENV_STEP/4);
n = (int)(2.0*o);
if (n&1) /* round to nearest */
n = (n>>1)+1;
else
n = n>>1;
sin_tab[ i ] = n*2 + (m>=0.0? 0: 1 );
}
for (i=0; i<SIN_LEN; i++)
{
/* waveform 1: __ __ */
/* / \____/ \____*/
/* output only first half of the sinus waveform (positive one) */
if (i & (1<<(SIN_BITS-1)) )
sin_tab[1*SIN_LEN+i] = TL_TAB_LEN;
else
sin_tab[1*SIN_LEN+i] = sin_tab[i];
/* waveform 2: __ __ __ __ */
/* / \/ \/ \/ \*/
/* abs(sin) */
sin_tab[2*SIN_LEN+i] = sin_tab[i & (SIN_MASK>>1) ];
/* waveform 3: _ _ _ _ */
/* / |_/ |_/ |_/ |_*/
/* abs(output only first quarter of the sinus waveform) */
if (i & (1<<(SIN_BITS-2)) )
sin_tab[3*SIN_LEN+i] = TL_TAB_LEN;
else
sin_tab[3*SIN_LEN+i] = sin_tab[i & (SIN_MASK>>2)];
}
return 1;
}
static void OPL_initalize(FM_OPLlite *OPL, FM_OPL *OPLs)
{
int i;
/* frequency base */
OPL->freqbase = (OPL->rate) ? ((double)OPL->clock / 72.0) / OPL->rate : 0;
/* Timer base time */
OPL->TimerBase = 1.0 / ((double)OPL->clock / 72.0 );
/* make fnumber -> increment counter table */
for( i=0 ; i < 1024 ; i++ )
{
/* opn phase increment counter = 20bit */
OPL->fn_tab[i] = (UINT32)( (double)i * 64 * OPL->freqbase * (1<<(FREQ_SH-10)) );
/* -10 because chip works with 10.10 fixed point, while we use 16.16 */
}
/* Amplitude modulation: 27 output levels (triangle waveform); 1 level takes one of: 192, 256 or 448 samples */
/* One entry from LFO_AM_TABLE lasts for 64 samples */
OPLs->lfo_am_inc = (UINT32)((1.0 / 64.0 ) * (1<<LFO_SH) * OPL->freqbase);
/* Vibrato: 8 output levels (triangle waveform); 1 level takes 1024 samples */
OPLs->lfo_pm_inc = (UINT32)((1.0 / 1024.0) * (1<<LFO_SH) * OPL->freqbase);
/* Noise generator: a step takes 1 sample */
OPLs->noise_f = (UINT32)((1.0 / 1.0) * (1<<FREQ_SH) * OPL->freqbase);
OPLs->eg_timer_add = (UINT32)((1<<EG_SH) * OPL->freqbase);
OPLs->eg_timer_overflow = ( 1 ) * (1<<EG_SH);
}
/* write a value v to register r on OPL chip */
static void OPLWriteReg(FM_OPLlite *OPL, int r, int v)
{
/* adjust bus to 8 bits */
r &= 0xff;
v &= 0xff;
switch(r&0xe0)
{
case 0x00: /* 00-1f:control */
switch(r&0x1f)
{
case 0x01: /* waveform select enable */
break;
case 0x02: /* Timer 1 */
OPL->T[0] = (256-v)*4;
break;
case 0x03: /* Timer 2 */
OPL->T[1] = (256-v)*16;
break;
case 0x04: /* IRQ clear / mask and Timer enable */
if(v&0x80)
{ /* IRQ flag clear */
OPL_STATUS_RESET(OPL,0x7f);
}
else
{ /* set IRQ mask ,timer enable*/
OPL->st[0] = v&1;
OPL->st[1] = (v>>1)&1;
/* IRQRST,T1MSK,t2MSK,EOSMSK,BRMSK,x,ST2,ST1 */
OPL_STATUS_RESET(OPL, v & 0x78 );
OPL_STATUSMASK_SET(OPL, (~v) & 0x78 );
/* timer 1 */
if(OPL->st[0])
{
OPL->TC[0]=OPL->T[0]*20;
double interval = (double)OPL->T[0]*OPL->TimerBase;
if (OPL->TimerHandler) (OPL->TimerHandler)(OPL->TimerParam+0,interval);
}
/* timer 2 */
if(OPL->st[1])
{
OPL->TC[1]=OPL->T[1]*20;
double interval =(double)OPL->T[1]*OPL->TimerBase;
if (OPL->TimerHandler) (OPL->TimerHandler)(OPL->TimerParam+1,interval);
}
}
break;
case 0x08: /* MODE,DELTA-T control 2 : CSM,NOTESEL,x,x,smpl,da/ad,64k,rom */
OPL->mode = v;
break;
default:
//logerror("FMOPL.C: write to unknown register: %02x\n",r);
break;
}
break;
case 0x20: /* am ON, vib ON, ksr, eg_type, mul */
break;
case 0x40:
break;
case 0x60:
break;
case 0x80:
break;
case 0xa0:
break;
case 0xc0:
break;
case 0xe0: /* waveform select */
break;
}
}
static void OPLResetChip(FM_OPLlite *OPL)
{
int c,s;
int i;
OPL->mode = 0; /* normal mode */
OPL_STATUS_RESET(OPL,0x7f);
/* reset with register write */
OPLWriteReg(OPL,0x01,0); /* wavesel disable */
OPLWriteReg(OPL,0x02,0); /* Timer1 */
OPLWriteReg(OPL,0x03,0); /* Timer2 */
OPLWriteReg(OPL,0x04,0); /* IRQ mask clear */
for(i = 0xff ; i >= 0x20 ; i-- ) OPLWriteReg(OPL,i,0);
}
/* Create one of virtual YM3812/YM3526/Y8950 */
/* 'clock' is chip clock in Hz */
/* 'rate' is sampling rate */
void OPLCreate(int type, int clock, int rate, FM_OPLlite* OPL, FM_OPL* OPLs)
{
OPL->type = type;
OPL->clock = clock;
OPL->rate = rate;
/* init global tables */
OPL_initalize(OPL,OPLs);
}
/* Destroy one of virtual YM3812 */
static void OPLDestroy(FM_OPLlite *OPL)
{
free(OPL);
}
/* Optional handlers */
static void OPLSetTimerHandler(FM_OPLlite *OPL,OPL_TIMERHANDLER TimerHandler,int channelOffset)
{
OPL->TimerHandler = TimerHandler;
OPL->TimerParam = channelOffset;
}
static void OPLSetIRQHandler(FM_OPLlite *OPL,OPL_IRQHANDLER IRQHandler,int param)
{
OPL->IRQHandler = IRQHandler;
OPL->IRQParam = param;
}
static void OPLSetUpdateHandler(FM_OPLlite *OPL,OPL_UPDATEHANDLER UpdateHandler,int param)
{
OPL->UpdateHandler = UpdateHandler;
OPL->UpdateParam = param;
}
static int OPLWrite(FM_OPLlite *OPL,int a,int v)
{
if( !(a&1) )
{ /* address port */
OPL->address = v & 0xff;
}
else
{ /* data port */
if(OPL->UpdateHandler) OPL->UpdateHandler(OPL->UpdateParam,0);
OPLWriteReg(OPL,OPL->address,v);
}
return OPL->status>>7;
}
static unsigned char OPLRead(FM_OPLlite *OPL,int a)
{
if( !(a&1) )
{
/* status port */
if (OPL->st[0]) {
if (OPL->TC[0]) OPL->TC[0]--;
else {
OPL->TC[0]=OPL->T[0]*20;
OPL_STATUS_SET(OPL,0x40);
}
}
if (OPL->st[1]) {
if (OPL->TC[1]) OPL->TC[1]--;
else {
OPL->TC[1]=OPL->T[1]*20;
OPL_STATUS_SET(OPL,0x40);
}
}
return OPL->status & (OPL->statusmask|0x80);
}
return 0xff;
}
static int OPLTimerOver(FM_OPLlite *OPL,int c)
{
if( c )
{ /* Timer B */
OPL_STATUS_SET(OPL,0x20);
}
else
{ /* Timer A */
OPL_STATUS_SET(OPL,0x40);
/* CSM mode key,TL controll */
if( OPL->mode & 0x80 )
{ /* CSM mode total level latch and auto key on */
int ch;
if(OPL->UpdateHandler) OPL->UpdateHandler(OPL->UpdateParam,0);
}
}
return OPL->status>>7;
}
#define MAX_OPL_CHIPS 2
#if (BUILD_YM3812)
static FM_OPLlite *OPLlite_YM3812[MAX_OPL_CHIPS];
extern "C" {
static int Status940=0;
static int g_hMemory=0;
static volatile unsigned short *g_pusRegs;
static unsigned char *g_pSharedMemory = 0;
void UpdateThreadEntry(void);
void Pause940(int n);
void Reset940(int yes);
void Startup940();
void Shutdown940();
void CleanUp(void);
void InitSharedMemory();
}
void Pause940(int n)
{
if(n)
g_pusRegs[0x0904>>1] &= 0xFFFE;
else
g_pusRegs[0x0904>>1] |= 1;
}
void Reset940(int yes)
{
g_pusRegs[0x3B48>>1] = ((yes&1) << 7) | (0x03);
}
void Startup940()
{
int nLen, nRead;
FILE *fp;
unsigned char ucData[1000];
Reset940(1);
Pause940(1);
g_pusRegs[0x3B40>>1] = 0;
g_pusRegs[0x3B42>>1] = 0;
g_pusRegs[0x3B44>>1] = 0xffff;
g_pusRegs[0x3B46>>1] = 0xffff;
// load code940.bin
nLen = 0;
fp = fopen("code940.bin", "r");
if(!fp) {
LOG_MSG("no 940 core found\n");
return;
} else
{
LOG_MSG("940 core found\n");
}
while(1)
{
nRead = fread(ucData, 1, 1000, fp);
if(nRead <= 0)
break;
memcpy(g_pSharedMemory + nLen, ucData, nRead);
nLen += nRead;
}
fclose(fp);
Reset940(0);
Pause940(0);
usleep(10000);
}
void Shutdown940()
{
Reset940(1);
Pause940(1);
}
void CleanUp(void)
{
Status940--;
//if(Status940>0) return;
//if(g_pSharedMemory)
// munmap(g_pSharedMemory, 0xF80000);
g_pSharedMemory = 0;
Shutdown940();
close(g_hMemory);
printf("Core shutdown\n");
}
void InitSharedMemory()
{
if(g_hMemory) return;
LOG_MSG("Once?\n");
g_hMemory = open("/dev/mem", O_RDWR);
g_pusRegs = (unsigned short *) mmap(0, 0x10000,
PROT_READ|PROT_WRITE, MAP_SHARED, g_hMemory, 0xc0000000);
g_pSharedMemory = (unsigned char *) mmap(0, 0xF80000,
PROT_READ|PROT_WRITE, MAP_SHARED, g_hMemory, 0x3000000);
memset(g_pSharedMemory,0,0x400000);
}
void UpdateThreadEntry(void)
{
Status940++;
if(Status940==1) Startup940();
}
static void InitMemory()
{
SharedBuff_ptr = (char *) (g_pSharedMemory + BUFF_BASE_ADDRESS);
SharedData_ptr = (char *) (g_pSharedMemory + DATA_BASE_ADDRESS);
memset(SharedBuff_ptr,0, END_OFFSET);
memset(SharedData_ptr,0, END_OFFSET2);
}
int YM3812Init(int num, int clock, int rate)
{
int i;
char *ptr;
if (YM3812NumChips)
return -1; /* duplicate init. */
if(END_OFFSET>OPL2_MSG_SIZE ||
END_OFFSET2>OPL2_DAT_SIZE) {
LOG_MSG("OPL2 memory data error\n");
return -1;
}
InitSharedMemory();
InitMemory();
LOG_MSG("OPL2 reports\n");
LOG_MSG("OPL2 mem: %d %d %d %d\n", sizeof(OPL_SLOT),
sizeof(OPL_CH),sizeof(FM_OPL),OPL_SIZE);
ptr=(SharedData_ptr + NUMCHIP_OFFSET);
YM3812NumChips=(int *) ptr;
*YM3812NumChips = num;
ptr=(SharedBuff_ptr + NSUB_OFFSET);
NSubmittedMessages=(int *) ptr;
*NSubmittedMessages=-1;
ptr=(SharedBuff_ptr + NEX_OFFSET);
NExecutedMessages=(int *) ptr;
*NExecutedMessages=-1;
ptr=(SharedBuff_ptr + MSG_BUF_OFFSET);
MessageBuffer=(CoreMessage *) ptr;
ptr=(SharedBuff_ptr + TL_TAB_OFFSET);
tl_tab=(signed int *) ptr;
ptr=(SharedBuff_ptr + SIN_TAB_OFFSET);
sin_tab=(unsigned int *) ptr;
init_tables();
for (i = 0;i < *YM3812NumChips; i++)
{
ptr=(SharedBuff_ptr + BUFPOS_OFFSET+ i*sizeof(int));
BufWritePos[i]=(int *) ptr;
*BufWritePos[i]=0;
ptr=(SharedBuff_ptr + READPOS_OFFSET +i*sizeof(int));
BufReadPos[i]=(int *) ptr;
*BufReadPos[i]=0;
ptr=(SharedBuff_ptr + DATA_OFFSET + i * SHARED_BUF_SIZE * sizeof(INT16));
SharedBuffer[i]=(INT16 *) ptr;
ptr=(SharedData_ptr + OPL_OFFSET + i*OPL_SIZE);
OPL_YM3812[i] = (FM_OPL*) ptr;
ptr = (char *) malloc(sizeof(FM_OPLlite));
memset(ptr , 0, sizeof(FM_OPLlite));
OPLlite_YM3812[i] = (FM_OPLlite *) ptr;
ptr=(SharedBuff_ptr + FNTAB_OFFSET+i*1024*sizeof(UINT32));
OPLlite_YM3812[i]->fn_tab=(UINT32 *) ptr;
OPLCreate(OPL_TYPE_YM3812,clock,rate,OPLlite_YM3812[i],OPL_YM3812[i]);
}
UpdateThreadEntry();
ADD_MESSAGE(INIT ,num ,clock ,rate );
for (i = 0;i < *YM3812NumChips; i++)
{
YM3812ResetChip(i);
}
return 0;
}
void YM3812Shutdown(void)
{
int i;
LOG_MSG("OPL2 ...\n");
ADD_MESSAGE(SHUTDOWN,0,0,0);
WAIT_FOR_SYNC;
LOG_MSG("OPL2 end\n");
for (i = 0;i < *YM3812NumChips; i++)
{
/* emulator shutdown */
OPLDestroy(OPLlite_YM3812[i]);
OPL_YM3812[i] = NULL;
OPLlite_YM3812[i] = NULL;
}
*YM3812NumChips = 0;
CleanUp();
}
void YM3812ResetChip(int which)
{
ADD_MESSAGE(RESET,which,0,0);
OPLResetChip(OPLlite_YM3812[which]);
}
int YM3812Write(int which, int a, int v)
{
ADD_MESSAGE(WRITE,which,0,a);
ADD_MESSAGE(WRITE,which,1,v);
OPLWriteReg(OPLlite_YM3812[which], a, v);
return (OPLlite_YM3812[which]->status>>7);
}
unsigned char YM3812Read(int which, int a)
{
ADD_MESSAGE(READ,which,a,0);
/* YM3812 always returns bit2 and bit1 in HIGH state */
return OPLRead(OPLlite_YM3812[which], a) | 0x06 ;
}
int YM3812TimerOver(int which, int c)
{
ADD_MESSAGE(TIMEROVER,which,c,0);
return OPLTimerOver(OPLlite_YM3812[which], c);
}
void YM3812SetTimerHandler(int which, OPL_TIMERHANDLER TimerHandler, int channelOffset)
{
OPLSetTimerHandler(OPLlite_YM3812[which], TimerHandler, channelOffset);
}
void YM3812SetIRQHandler(int which,OPL_IRQHANDLER IRQHandler,int param)
{
OPLSetIRQHandler(OPLlite_YM3812[which], IRQHandler, param);
}
void YM3812SetUpdateHandler(int which,OPL_UPDATEHANDLER UpdateHandler,int param)
{
OPLSetUpdateHandler(OPLlite_YM3812[which], UpdateHandler, param);
}
void YM3812UpdateOne(int which, INT16 *buffer, int length)
{
int i,ncopy,nfree,nbuff,d,bufpos;
INT16 lt;
static int warn=1;
d=*NSubmittedMessages-*NExecutedMessages;
if(warn && d>MSG_BUF_SIZE)
{
LOG_MSG("OPL2: buffer running full");
warn=0;
}
else
{
if(d<MSG_BUF_SIZE) warn=1;
}
bufpos=*BufReadPos[which];
d=*BufWritePos[which]- bufpos;
nbuff=WRAPPED(d,SHARED_BUF_SIZE);
ncopy=MIN(length, nbuff);
nfree=SHARED_BUF_SIZE - bufpos;
if(ncopy < nfree)
{
for(i=0;i<ncopy;i++)
{
lt=Amp( SharedBuffer[which][ bufpos+i ] );
buffer[2*i]=lt;
buffer[2*i+1]=lt; //for stereo
}
(*BufReadPos[which])+=ncopy;
}
else
{
for(i=0;i<nfree;i++)
{
lt=Amp( SharedBuffer[which][ bufpos+i ] );
buffer[2*i]=lt;
buffer[2*i+1]=lt;
}
for(i=0;i<ncopy-nfree;i++)
{
lt=Amp( SharedBuffer[which][i] );
buffer[2*i+2*nfree]=lt;
buffer[2*i+2*nfree+1]=lt;
}
*BufReadPos[which]=ncopy-nfree;
}
if(ncopy < length)
{
bufpos=*BufReadPos[which];
lt=Amp( SharedBuffer[which][WRAPPED(bufpos-1,SHARED_BUF_SIZE)] );
for(i=ncopy;i<length;i++)
{
buffer[2*i]=lt;
buffer[2*i+1]=lt;
}
}
ADD_MESSAGE(UPDATE, which, length, 0);
}
INT16 Amp( INT16 value )
{
INT32 temp;
int offset = 2;
temp = value;
temp <<= offset;
if( temp > MAXOUT ) temp = MAXOUT;
if( temp < MINOUT ) temp = MINOUT;
return (INT16)temp;
}
#endif /* BUILD_YM3812 */
| 18,626 | C | .c | 680 | 24.972059 | 112 | 0.637466 | KS-Presto/Wolf4SDL | 52 | 26 | 0 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,235,967 | dc_vmu.c | KS-Presto_Wolf4SDL/dc/dc_vmu.c | //Wolf4SDL\DC
//dc_vmu.cpp
//2009 - Cyle Terry
#if defined(_arch_dreamcast)
#include <string.h>
#include "../wl_def.h"
#include "dc/maple.h"
#include "dc/maple/controller.h"
#include "dc/maple/vmu.h"
#include "dc/vmu_pkg.h"
#include "kos/fs.h"
#include "zlib/zlib.h"
#include "dc_vmu.h"
maple_device_t *vmu_lcd_addr[8];
void DC_StatusDrawLCD(int lcd) {
const char *character;
int x, y;
int xi, xb;
int i = 0;
uint8 bitmap[48 * 32 / 8];
maple_device_t *vmu_lcd_addr;
memset(bitmap, 0, sizeof(bitmap));
character = e_BJFaces[lcd - FACE1APIC];
if(character) {
for(y = 0; y < LCD_HEIGHT; y++) {
for(x = 0; x < LCD_WIDTH; x++) {
xi = x / 8;
xb = 0x80 >> (x % 8);
if(character[(31 - y) * 48 + (47 - x)] == '.')
bitmap[y * (48 / 8) + xi] |= xb;
}
}
}
while ((vmu_lcd_addr = maple_enum_type(i++, MAPLE_FUNC_LCD)))
vmu_draw_lcd(vmu_lcd_addr, bitmap);
vmu_shutdown ();
}
void DC_StatusClearLCD() {
int x, y;
int xi;
int i = 0;
uint8 bitmap[48 * 32 / 8];
maple_device_t *vmu_lcd_addr;
memset(bitmap, 0, sizeof(bitmap));
for(y = 0; y < LCD_HEIGHT; y++) {
for(x = 0; x < LCD_WIDTH; x++) {
xi = x / 8;
bitmap[y * (48 / 8) + xi] |= 0;
}
}
while ((vmu_lcd_addr = maple_enum_type(i++, MAPLE_FUNC_LCD)))
vmu_draw_lcd(vmu_lcd_addr, bitmap);
vmu_shutdown ();
}
void DC_SaveToVMU(char *fname, char *str) {
char destination[32];
int filesize = 0;
int vmu_package_size;
unsigned long zipsize = 0;
unsigned char *vmu_package_out;
unsigned char *data;
unsigned char *zipdata;
file_t file;
vmu_pkg_t vmu_package;
DiskFlopAnim(102, 85);
strcpy(destination, "/vmu/a1/");
strcat(destination, fname);
file = fs_open(fname, O_RDONLY);
filesize = fs_total(file);
data = (unsigned char*)malloc(filesize);
fs_read(file, data, filesize);
fs_close(file);
DiskFlopAnim(102, 85);
zipsize = filesize * 2;
zipdata = (unsigned char*)malloc(zipsize);
compress(zipdata, &zipsize, data, filesize);
DiskFlopAnim(102, 85);
#ifdef SPEAR
strcpy(vmu_package.desc_short, "Sod4SDL\\DC");
strcpy(vmu_package.app_id, "Sod4SDL\\DC");
#else
strcpy(vmu_package.desc_short, "Wolf4SDL\\DC");
strcpy(vmu_package.app_id, "Wolf4SDL\\DC");
#endif
if(str == NULL)
strcpy(vmu_package.desc_long, "Configuration");
else {
strcpy(vmu_package.desc_long, "Game Save - ");
strcat(vmu_package.desc_long, str);
}
vmu_package.icon_cnt = 1;
vmu_package.icon_anim_speed = 0;
memcpy(&vmu_package.icon_pal[0], vmu_bios_save_icon, 32);
vmu_package.icon_data = vmu_bios_save_icon + 32;
vmu_package.eyecatch_type = VMUPKG_EC_NONE;
vmu_package.data_len = zipsize;
vmu_package.data = zipdata;
vmu_pkg_build(&vmu_package, &vmu_package_out, &vmu_package_size);
DiskFlopAnim(102, 85);
fs_unlink(destination);
file = fs_open(destination, O_WRONLY);
fs_write(file, vmu_package_out, vmu_package_size);
fs_close(file);
DiskFlopAnim(102, 85);
free(vmu_package_out);
free(data);
free(zipdata);
}
int DC_LoadFromVMU(char *fname) {
char fpath[64];
int file;
int filesize;
unsigned long unzipsize;
unsigned char *data;
unsigned char *unzipdata;
vmu_pkg_t vmu_package;
sprintf(fpath, "/vmu/a1/%s", fname);
file = fs_open(fpath, O_RDONLY);
if(file == 0) return 0;
filesize = fs_total(file);
if(filesize <= 0) return 0;
data = (unsigned char*)malloc(filesize);
fs_read(file, data, filesize);
fs_close(file);
if(!strcmp(fname, configname))
DiskFlopAnim(102, 85);
vmu_pkg_parse(data, &vmu_package);
if(!strcmp(fname, configname))
DiskFlopAnim(102, 85);
unzipdata = (unsigned char*)malloc(65536);
unzipsize = 65536;
uncompress(unzipdata, &unzipsize, (unsigned char*)vmu_package.data, vmu_package.data_len);
if(!strcmp(fname, configname))
DiskFlopAnim(102, 85);
fs_unlink(fname);
file = fs_open(fname, O_WRONLY);
fs_write(file, unzipdata, unzipsize);
fs_close(file);
if(!strcmp(fname, configname))
DiskFlopAnim(102, 85);
free(data);
free(unzipdata);
return 1;
}
#endif
| 4,417 | C | .c | 145 | 24.993103 | 94 | 0.611662 | KS-Presto/Wolf4SDL | 52 | 26 | 0 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,235,968 | dc_main.h | KS-Presto_Wolf4SDL/dc/dc_main.h | //Wolf4SDL\DC
//dc_main.h
//2009 - Cyle Terry
#ifndef __DC_MAIN_H_
#define __DC_MAIN_H_
typedef uint8 uint8_t;
typedef uint16 uint16_t;
typedef uint32 uint32_t;
typedef int8 int8_t;
typedef int16 int16_t;
typedef int32 int32_t;
typedef int64 int64_t;
typedef ptr_t uintptr_t;
//dc_cd.cpp
int DC_CheckDrive();
//dc_main.cpp
void DC_Init();
void DC_CheckArguments();
int DC_CheckForMaps(char *path);
#ifdef SPEAR
#ifndef SPEARDEMO
int DC_SetMission(char *path);
#endif
#endif
//dc_maple.cpp
int DC_ButtonPress(int button);
int DC_MousePresent();
void DC_WaitButtonPress(int button);
void DC_WaitButtonRelease(int button);
//dc_video.cpp
void DC_VideoInit();
void DC_DrawString(int x, int y, char *str);
void DC_CLS();
void DC_Flip();
//dc_vmu.cpp
extern void DiskFlopAnim(int x, int y);
void DC_StatusDrawLCD(int index);
void DC_StatusClearLCD();
void DC_SaveToVMU(char *fname, char *str);
int DC_LoadFromVMU(char *fname);
#endif
| 970 | C | .c | 41 | 21.780488 | 49 | 0.740499 | KS-Presto/Wolf4SDL | 52 | 26 | 0 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | true | false | false | true | true | false | true | false |
2,235,969 | dc_video.c | KS-Presto_Wolf4SDL/dc/dc_video.c | //Wolf4SDL\DC
//dc_video.cpp
//2009 - Cyle Terry
#if defined(_arch_dreamcast)
#include <string.h>
#include <malloc.h>
#include "../wl_def.h"
#include "dc/biosfont.h"
#include "dc/video.h"
static uint16 *bbuffer;
void DC_VideoInit() {
bbuffer = (uint16 *)malloc(640 * 480 * 2);
DC_CLS();
}
void DC_DrawString(int x, int y, char *str) {
bfont_draw_str(bbuffer + ((y + 1) * 24 * 640) + (x * 12), 640, 0, str);
}
void DC_Flip() {
memcpy(vram_s, bbuffer, 640 * 480 * 2);
}
void DC_CLS() {
int x, y, ofs;
for(y = 0; y < 480; y++) {
ofs = (640 * y);
for(x = 0; x < 640; x++)
bbuffer[ofs + x] = 0;
}
}
#endif
| 665 | C | .c | 29 | 19.724138 | 75 | 0.568471 | KS-Presto/Wolf4SDL | 52 | 26 | 0 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,235,970 | dc_maple.c | KS-Presto_Wolf4SDL/dc/dc_maple.c | //Wolf4SDL\DC
//dc_maple.cpp
//2009 - Cyle Terry
#if defined(_arch_dreamcast)
#include <SDL.h>
#include "dc/maple.h"
#include "dc/maple/controller.h"
#include "dc/maple/vmu.h"
int DC_MousePresent() {
return maple_first_mouse() != 0;
}
void DC_WaitButtonPress(int button)
{
int first_controller = 0;
cont_cond_t controller_condition;
first_controller = maple_first_controller();
cont_get_cond(first_controller, &controller_condition);
while((controller_condition.buttons & button)) {
SDL_Delay(5);
cont_get_cond(first_controller, &controller_condition);
}
}
void DC_WaitButtonRelease(int button)
{
int first_controller = 0;
cont_cond_t controller_condition;
first_controller = maple_first_controller();
cont_get_cond(first_controller, &controller_condition);
while(!(controller_condition.buttons & button)) {
SDL_Delay(5);
cont_get_cond(first_controller, &controller_condition);
}
}
int DC_ButtonPress(int button)
{
int first_controller = 0;
cont_cond_t controller_condition;
first_controller = maple_first_controller();
cont_get_cond(first_controller, &controller_condition);
if(!(controller_condition.buttons & button))
return 1;
else
return 0;
}
#endif
| 1,294 | C | .c | 45 | 24.666667 | 63 | 0.705024 | KS-Presto/Wolf4SDL | 52 | 26 | 0 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,235,971 | dc_main.c | KS-Presto_Wolf4SDL/dc/dc_main.c | //Wolf4SDL\DC
//dc_main.cpp
//2009 - Cyle Terry
#if defined(_arch_dreamcast)
//TODO: Use Port A Only
#include <string.h>
#include "../wl_def.h"
#include "dc/video.h"
#include "kos/dbglog.h"
#include "kos/fs.h"
#include "zlib/zlib.h"
char dcwolf3dpath[1024];
void DC_CheckArguments() {
FILE *fp;
char *buf;
char *result = NULL;
bool sampleRateGiven = false;
bool audioBufferGiven = false;
int length = 0;
fp = fopen("/cd/data/wolf3d/args.txt", "r");
if (!fp)
return;
fseek(fp, 0, SEEK_END);
length = ftell (fp);
fseek(fp, 0, SEEK_SET);
buf = (char *)malloc(length + 2);
fread(buf, 1, length, fp);
buf[length] = 0;
fclose(fp);
result = strtok(buf, " ");
while (result != NULL) {
#ifndef SPEAR
if (!strcmp(result, "--goobers"))
#else
if (!strcmp(result, "--debugmode"))
#endif
param_debugmode = true;
else if (!strcmp(result, "--baby"))
param_difficulty = 0;
else if (!strcmp(result, "--easy"))
param_difficulty = 1;
else if (!strcmp(result, "--normal"))
param_difficulty = 2;
else if (!strcmp(result, "--hard"))
param_difficulty = 3;
else if (!strcmp(result, "--nowait"))
param_nowait = true;
else if (!strcmp(result, "--tedlevel")) {
result = strtok(NULL, " ");
param_tedlevel = atoi(result);
} else if (!strcmp(result, "--res")) {
result = strtok(NULL, " ");
screenWidth = atoi(result);
result = strtok(NULL, " ");
screenHeight = atoi(result);
if ( screenWidth % 320 && screenHeight % 200) {
dbglog(DBG_DEBUG, "Screen height\\width must be a multiple of 320x200\n");
dbglog(DBG_DEBUG, "Defaulting to 320x200\n");
screenWidth = 320;
screenHeight = 200;
}
} else if (!strcmp(result, "--resf")) {
result = strtok(NULL, " ");
screenWidth = atoi(result);
result = strtok(NULL, " ");
screenHeight = atoi(result);
if (screenWidth < 320 && screenHeight < 200) {
dbglog(DBG_DEBUG, "Screen height\\width must be at least 320x200\n");
dbglog(DBG_DEBUG, "Defaulting to 320x200\n");
screenWidth = 320;
screenHeight = 200;
}
} else if (!strcmp(result, "--bits")) {
result = strtok(NULL, " ");
screenBits = atoi(result);
switch (screenBits) {
case 8:
case 16:
case 24:
case 32:
break;
default:
dbglog(DBG_DEBUG, "Screen bits must be either 8, 16, 24 or 32\n");
dbglog(DBG_DEBUG, "Defaulting to 8\n");
screenBits = 8;
break;
}
result = strtok(NULL, " ");
param_samplerate = atoi(result);
sampleRateGiven = true;
} else if (!strcmp(result, "--dblbuf")) { //Was --nodblbuf
usedoublebuffering = true;
} else if (!strcmp(result, "--extravbls")) {
result = strtok(NULL, " ");
extravbls = atoi(result);
if(extravbls < 0) {
dbglog(DBG_DEBUG, "Extravbls must be positive!\n");
dbglog(DBG_DEBUG, "Defaulting to 0\n");
extravbls = 0;
}
} else if (!strcmp(result, "--samplerate")) {
result = strtok(NULL, " ");
param_samplerate = atoi(result);
sampleRateGiven = true;
} else if (!strcmp(result, "--audiobuffer")) {
result = strtok(NULL, " ");
param_audiobuffer = atoi(result);
audioBufferGiven = true;
} else if (!strcmp(result, "--goodtimes"))
param_goodtimes = true;
result = strtok(NULL, " ");
}
free(buf);
if (sampleRateGiven && !audioBufferGiven)
param_audiobuffer = 4096 / (44100 / param_samplerate);
}
int DC_CheckForMaps(char *path) {
file_t dir;
dirent_t *dirent;
char fpath[1024];
int disc_status;
for(;;) {
SDL_Delay(5);
disc_status = DC_CheckDrive();
#ifdef SPEAR
DC_DrawString(4, 1, "Sod4SDL\\DC");
#else
DC_DrawString(4, 1, "Wolf4SDL\\DC");
#endif
switch(disc_status) {
//case CD_STATUS_BUSY:
//case CD_STATUS_OPEN:
// DC_DrawString(4, 6, "Please insert your Wolfenstein 3D CD.");
// break;
default:
dir = fs_open(path, O_DIR);
while(dirent = fs_readdir(dir)) {
#ifdef SPEAR
#ifdef SPEARDEMO
if(!strcmp(dirent->name, "AUDIOHED.SDM")) {
fs_close(dir);
strcpy(dcwolf3dpath, path);
return 0;
}
#else
if(!strcmp(dirent->name, "AUDIOHED.SOD")) {
fs_close(dir);
strcpy(dcwolf3dpath, path);
param_mission = DC_SetMission(path);
return 0;
}
#endif
#else
#ifdef UPLOAD
if(!strcmp(dirent->name, "AUDIOHED.WL1")) {
fs_close(dir);
strcpy(dcwolf3dpath, path);
return 0;
}
#else
if(!strcmp(dirent->name, "AUDIOHED.WL6")) {
fs_close(dir);
strcpy(dcwolf3dpath, path);
return 0;
}
#endif
#endif
strcpy(fpath, path);
sprintf(fpath, "%s/%s", fpath, dirent->name);
DC_CheckForMaps(fpath);
}
fs_close(dir);
return -1;
}
DC_Flip();
}
}
void DC_LoadMaps() {
DC_CheckForMaps("/cd");
DC_CLS();
fs_chdir(dcwolf3dpath);
#ifdef SPEAR
#ifndef SPEARDEMO
fs_copy("audiohed.sod", "/ram/audiohed.sod");
fs_copy("audiot.sod", "/ram/audiot.sod");
fs_copy("vgadict.sod", "/ram/vgadict.sod");
fs_copy("vgagraph.sod", "/ram/vgagraph.sod");
fs_copy("vgahead.sod", "/ram/vgahead.sod");
switch(param_mission) {
case 0:
fs_copy("gamemaps.sod", "/ram/gamemaps.sod");
fs_copy("maphead.sod", "/ram/maphead.sod");
fs_copy("vswap.sod", "/ram/vswap.sod");
break;
case 1:
fs_copy("gamemaps.sd1", "/ram/gamemaps.sd1");
fs_copy("maphead.sd1", "/ram/maphead.sd1");
fs_copy("vswap.sd1", "/ram/vswap.sd1");
break;
case 2:
fs_copy("gamemaps.sd2", "/ram/gamemaps.sd2");
fs_copy("maphead.sd2", "/ram/maphead.sd2");
fs_copy("vswap.sd2", "/ram/vswap.sd2");
break;
case 3:
fs_copy("gamemaps.sd3", "/ram/gamemaps.sd3");
fs_copy("maphead.sd3", "/ram/maphead.sd3");
fs_copy("vswap.sd3", "/ram/vswap.sd3");
break;
}
#else
fs_copy("audiohed.sdm", "/ram/audiohed.sdm");
fs_copy("audiot.sdm", "/ram/audiot.sdm");
fs_copy("vgadict.sdm", "/ram/vgadict.sdm");
fs_copy("vgagraph.sdm", "/ram/vgagraph.sdm");
fs_copy("vgahead.sdm", "/ram/vgahead.sdm");
fs_copy("gamemaps.sdm", "/ram/gamemaps.sdm");
fs_copy("maphead.sdm", "/ram/maphead.sdm");
fs_copy("vswap.sdm", "/ram/vswap.sdm");
#endif
#else
#ifndef UPLOAD
fs_copy("audiohed.wl6", "/ram/audiohed.wl6");
fs_copy("audiot.wl6", "/ram/audiot.wl6");
fs_copy("vgadict.wl6", "/ram/vgadict.wl6");
fs_copy("vgagraph.wl6", "/ram/vgagraph.wl6");
fs_copy("vgahead.wl6", "/ram/vgahead.wl6");
fs_copy("gamemaps.wl6", "/ram/gamemaps.wl6");
fs_copy("maphead.wl6", "/ram/maphead.wl6");
fs_copy("vswap.wl6", "/ram/vswap.wl6");
#else
fs_copy("audiohed.wl1", "/ram/audiohed.wl1");
fs_copy("audiot.wl1", "/ram/audiot.wl1");
fs_copy("vgadict.wl1", "/ram/vgadict.wl1");
fs_copy("vgagraph.wl1", "/ram/vgagraph.wl1");
fs_copy("vgahead.wl1", "/ram/vgahead.wl1");
fs_copy("gamemaps.wl1", "/ram/gamemaps.wl1");
fs_copy("maphead.wl1", "/ram/maphead.wl1");
fs_copy("vswap.wl1", "/ram/vswap.wl1");
#endif
#endif
fs_chdir("/ram");
}
void DC_Init() {
DC_CheckArguments();
DC_VideoInit();
DC_LoadMaps();
DC_CLS();
}
#ifdef SPEAR
#ifndef SPEARDEMO
int DC_SetMission(char *path) {
int mission1 = 0;
int mission2 = 0;
int mission3 = 0;
int missions = 0;
int last_mission = 0;
int current_mission = 0;
int previous_mission = 0;
int font_y = 0;
char fname[1024];
bool finished = false;
FILE *fp;
sprintf(fname, "%s/MAPHEAD.SOD", path);
fp = fopen(fname, "r");
if(fp) {
fclose(fp);
last_mission = 1;
mission1 = 1;
missions++;
}
sprintf(fname, "%s/MAPHEAD.SD2", path);
fp = fopen(fname, "r");
if(fp) {
fclose(fp);
last_mission = 2;
mission2 = 1;
missions++;
}
sprintf(fname, "%s/MAPHEAD.SD3", path);
fp = fopen(fname, "r");
if(fp) {
fclose(fp);
last_mission = 3;
mission3 = 1;
missions++;
}
if(missions > 1) {
while(!finished) {
SDL_Delay(5);
DC_CLS();
DC_DrawString(2, 6 + current_mission, ">");
font_y = 6;
DC_DrawString(4, 1, "Sod4SDL\\DC");
if(mission1 == 1) {
DC_DrawString(4, font_y, "Spear of Destiny (Original Mission)");
font_y++;
}
if(mission2 == 1) {
DC_DrawString(4, font_y, "Mission 2 - Return to Danger");
font_y++;
}
if(mission3 == 1) {
DC_DrawString(4, font_y, "Mission 3 - Ultimate Challenge");
font_y++;
}
if(DC_ButtonPress(CONT_A)) {
finished = true;
break;
} else if(DC_ButtonPress(CONT_DPAD_DOWN)) {
current_mission++;
previous_mission = -1;
if(current_mission > (missions - 1))
current_mission = 0;
DC_WaitButtonRelease(CONT_DPAD_DOWN);
} else if(DC_ButtonPress(CONT_DPAD_UP)) {
current_mission--;
previous_mission = -1;
if(current_mission < 0)
current_mission = missions - 1;
DC_WaitButtonRelease(CONT_DPAD_UP);
}
DC_Flip();
}
/* Return Selected Mission */
// XXX: What does this do? Are the fall throughs intended?!
switch(current_mission) {
case 1:
if(mission1) return 1;
if(mission2 && !mission1) return 2;
case 2:
if(mission2 && mission1) return 2;
if(mission3 && mission1 && !mission2) return 3;
if(mission3 && mission2 && !mission1) return 3;
case 3:
if(mission3 && mission2 && mission1) return 3;
}
}
return last_mission;
}
#endif
#endif
#endif
| 11,405 | C | .c | 343 | 23.241983 | 90 | 0.504081 | KS-Presto/Wolf4SDL | 52 | 26 | 0 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,235,973 | dc_cd.c | KS-Presto_Wolf4SDL/dc/dc_cd.c | //Wolf4SDL\DC
//dc_cd.cpp
//2009 - Cyle Terry
#if defined(_arch_dreamcast)
#include "dc/cdrom.h"
int DC_CheckDrive() {
int disc_status;
int disc_type;
cdrom_get_status(&disc_status, &disc_type);
return disc_status;
}
#endif
| 244 | C | .c | 12 | 17.666667 | 47 | 0.697368 | KS-Presto/Wolf4SDL | 52 | 26 | 0 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,235,987 | wl_shade.h | KS-Presto_Wolf4SDL/wl_shade.h | #if defined(USE_SHADING) && !defined(_WL_SHADE_H_)
#define _WL_SHADE_H_
#define SHADE_COUNT 32
#define LSHADE_NOSHADING 0xff
#define LSHADE_NORMAL 0
#define LSHADE_FOG 5
extern uint8_t shadetable[SHADE_COUNT][256];
void InitLevelShadeTable();
int GetShade(int scale);
#endif
| 280 | C | .h | 10 | 26.5 | 50 | 0.784906 | KS-Presto/Wolf4SDL | 52 | 26 | 0 | GPL-2.0 | 9/7/2024, 9:46:14 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
2,354,143 | imagedata.c | soonuse_epd-library-stm32/2.13inch_e-paper/stm32/BSP/imagedata.c | /**
* @filename : imagedata.c
* @brief : data file for epd demo
*
* Copyright (C) Waveshare September 5 2017
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documnetation 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
* furished 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 OR 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 "imagedata.h"
const unsigned char IMAGE_DATA[] = {
/* 0X00,0X01,0X80,0X00,0XFA,0X00, */
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X38,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X0F,0X00,0X00,0X78,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X1F,0X80,0X00,0XF8,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XFF,0XC0,0X03,0XF8,0X00,0X00,0X00,
0X00,0X00,0X00,0X01,0X00,0X00,0X00,0X00,0X01,0XFF,0XE0,0X1F,0XF8,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0XC0,0X00,0X00,0X00,0X03,0XFF,0X70,0X1F,0XF0,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X7E,0X00,0X00,0X00,0X03,0XFF,0X78,0X38,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X3F,0X00,0X00,0X00,0X03,0XFF,0XF8,0XF0,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X0F,0XC0,0X00,0X00,0X03,0XF0,0XF8,0XC1,0XF8,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X03,0XF0,0X00,0X00,0X03,0XF3,0XF3,0X8F,0XFE,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X01,0XF8,0X00,0X00,0X03,0XFF,0XF3,0XBF,0XFF,0XC0,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X3E,0X00,0X00,0X03,0XFF,0XFA,0X7F,0XFF,0XF0,0X00,0X00,
0X00,0X0F,0X00,0X00,0X00,0X3F,0XE0,0X00,0X00,0XE7,0XFB,0XFF,0XFF,0XF0,0X00,0X00,
0X00,0X07,0X00,0X00,0X00,0X3F,0XF0,0X00,0X00,0XE7,0XFB,0XFF,0XFF,0XE0,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X1F,0XFC,0X00,0X00,0XFF,0XFB,0XFF,0XFF,0XE0,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X0F,0XFE,0X00,0X00,0X7F,0XFB,0XCF,0XFF,0XE0,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X03,0XFE,0X00,0X00,0X3F,0XF9,0XCF,0XFF,0XE0,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X01,0XFF,0X80,0X00,0X0F,0XF1,0XFF,0XFF,0XE0,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0XFF,0XC0,0X00,0X00,0X3D,0XEF,0XFF,0XE0,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X7F,0XE0,0X00,0X03,0XFF,0XF7,0XFF,0XC0,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X3F,0XE0,0X00,0X3F,0XFF,0XFF,0XFF,0X80,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X1F,0XE0,0X00,0X7E,0XFF,0XFF,0XFF,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X0F,0XE0,0X00,0X3E,0XFF,0XF1,0XFF,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X0F,0XE0,0X00,0X3F,0XFF,0XBF,0XFC,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X07,0XF0,0X00,0X3E,0X7F,0X3F,0XF8,0X38,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X07,0XF0,0X00,0X7E,0X7F,0XC0,0X00,0X7C,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X07,0XF0,0X00,0X7E,0X3F,0XC0,0X01,0XFE,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X07,0XF0,0X00,0X7F,0X1F,0XDF,0XFF,0XFF,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X03,0XF0,0X00,0X7F,0X87,0XEF,0XFF,0XFF,0X80,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X03,0XF0,0X00,0X7F,0XE3,0XF1,0XFF,0XFF,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X03,0XF0,0X01,0X87,0XFC,0X78,0XFE,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X03,0XF0,0X03,0X01,0XF8,0XFF,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X03,0XF0,0X0E,0X00,0X01,0XFF,0X80,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X03,0XF0,0X0C,0X00,0X03,0XFF,0X80,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X03,0XF0,0X1C,0X00,0X0F,0X98,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X03,0XF0,0X38,0X00,0X7F,0X9C,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X03,0XF0,0X30,0X00,0X3F,0XDC,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X07,0XFE,0X07,0XE0,0X30,0X00,0X1F,0XFE,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X0F,0XFF,0X87,0XF0,0X70,0X00,0X1F,0XFC,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X1F,0XFF,0XC7,0XF0,0X00,0X00,0X0F,0XFE,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X3F,0XFF,0XE7,0XE0,0X00,0X00,0X0F,0XF0,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X7F,0XFF,0XF3,0XE0,0X7F,0XFF,0XEF,0XE0,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0XFF,0X9F,0XFB,0XCF,0XFF,0XFF,0XC6,0X18,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X03,0XFF,0XCF,0XF9,0XDF,0XFF,0XFF,0XC0,0X08,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X0E,0XFF,0XDF,0XFD,0XFF,0XFF,0XFE,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X01,0XF0,0XFF,0XFF,0XFD,0XFF,0XFE,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X03,0XF8,0XFF,0XFF,0XFD,0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X07,0XFC,0XFF,0XDF,0XFD,0XFF,0XF8,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X0F,0XFE,0XC7,0XDF,0XFD,0XFF,0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X3E,0X7F,0XF7,0XDF,0XFF,0XFE,0X30,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X3E,0X7F,0XF7,0XDF,0XCF,0XF0,0X38,0X00,0X06,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X7E,0X7F,0XFF,0XFF,0X9F,0XE0,0X38,0X00,0X1F,0XC0,0X00,0X00,0X00,0X00,
0X00,0X03,0X7F,0X1F,0XFF,0XFE,0X3E,0X00,0X3C,0X00,0X3B,0XE0,0X00,0X00,0X00,0X00,
0X00,0X03,0X7F,0X8F,0XFF,0XFE,0X7C,0X00,0X3C,0X00,0X3B,0XE0,0X00,0X00,0X00,0X00,
0X00,0X03,0X7F,0X87,0XFE,0X3F,0XF8,0X00,0X3C,0X00,0X7F,0XF0,0X00,0X00,0X00,0X00,
0X00,0X03,0X7F,0XA1,0XF8,0X1F,0XFC,0X00,0X1C,0X00,0X7C,0XF0,0X00,0X00,0X00,0X00,
0X00,0X03,0X3F,0XFF,0XF0,0X0F,0XFC,0X00,0X0C,0X00,0X7E,0X7C,0X00,0X00,0X00,0X00,
0X00,0X03,0X3F,0XFF,0XF0,0X0F,0XFE,0X00,0X0C,0X00,0X7F,0X3C,0X00,0X00,0X00,0X00,
0X00,0X03,0X1F,0XFF,0XF0,0X0F,0XFF,0X00,0X0C,0X00,0X3F,0X80,0X00,0X00,0X00,0X00,
0X00,0X03,0X0F,0XFF,0XF0,0X0E,0X7F,0X80,0X0C,0X00,0X3F,0XC0,0X00,0X00,0X00,0X00,
0X00,0X03,0X07,0XFF,0XF8,0X0E,0X3F,0XC0,0X0C,0X00,0X1F,0XF0,0X00,0X00,0X00,0X00,
0X00,0X03,0X03,0XFF,0XF8,0X1E,0X1F,0XE0,0X0C,0X00,0X0F,0XF0,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X3F,0XFE,0X3F,0X87,0XE0,0X3C,0X00,0X0F,0XBE,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X47,0XFF,0XFF,0XF0,0X60,0X3C,0X00,0X0F,0XBF,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X31,0XFF,0XFF,0XF8,0XE0,0X38,0X00,0X0F,0XBF,0X80,0X00,0X00,0X00,
0X00,0X03,0X06,0X11,0XFF,0XFD,0XFF,0XE0,0X38,0X00,0X0F,0X1F,0X80,0X00,0X00,0X00,
0X00,0X03,0X0E,0X13,0XFF,0XF9,0XFF,0XE0,0X30,0X00,0X0E,0X07,0X80,0X00,0X00,0X00,
0X00,0X03,0X3C,0XD7,0XFD,0XFD,0XFF,0XE0,0X30,0X00,0X1C,0XC7,0X80,0X00,0X00,0X00,
0X00,0X03,0X39,0XEF,0XFB,0XFF,0XFF,0XE0,0X30,0X00,0X3D,0XFF,0X80,0X00,0X00,0X00,
0X00,0X03,0X73,0XEF,0XFB,0XFF,0XFF,0XE0,0X60,0X00,0X3D,0XFF,0X80,0X00,0X00,0X00,
0X00,0X03,0X67,0XEF,0XFB,0XFF,0XFF,0XC0,0XC0,0X00,0X3F,0XFF,0X80,0X00,0X00,0X00,
0X00,0X03,0X8F,0XF7,0XE3,0XFF,0XFF,0X80,0XE0,0X00,0X1B,0XFF,0X80,0X00,0X00,0X00,
0X00,0X03,0X9F,0XF3,0XE1,0XFF,0XE0,0X01,0XC0,0X00,0X3B,0XFF,0XC0,0X00,0X00,0X00,
0X00,0X03,0X3F,0XF1,0XF9,0XFF,0XC0,0X03,0X80,0X00,0X7F,0XFF,0XE0,0X00,0X00,0X00,
0X00,0X03,0X7F,0XF1,0XFD,0XFF,0X80,0X07,0X00,0X00,0X1F,0XFF,0XF8,0X00,0X00,0X00,
0X00,0X03,0XFF,0XF1,0XFF,0XFF,0X80,0X0F,0X00,0X00,0X3F,0XFF,0XFC,0X00,0X00,0X00,
0X00,0X03,0XFF,0XE0,0XFF,0XFF,0X00,0X0E,0X00,0X00,0X3F,0XFF,0X9C,0X00,0X00,0X00,
0X00,0X03,0XFF,0X80,0X0F,0XFF,0X00,0X06,0X00,0X00,0X03,0XF6,0X7C,0X00,0X00,0X00,
0X00,0X03,0XFF,0X00,0X1F,0X7C,0X00,0XF8,0X00,0X00,0X09,0XF0,0X3C,0X00,0X00,0X00,
0X00,0X03,0XFE,0X00,0X3F,0X38,0X01,0XFC,0X00,0X00,0X1C,0XF8,0X1C,0X00,0X00,0X00,
0X00,0X03,0XFC,0X00,0XFF,0X90,0X03,0XFE,0X00,0X00,0X3D,0XFF,0X9C,0X00,0X00,0X00,
0X00,0X03,0XF8,0X00,0XFF,0XC0,0X0F,0XFF,0X00,0X00,0X73,0XFF,0XCC,0X00,0X00,0X00,
0X00,0X03,0XF0,0X00,0XFF,0XE0,0X0F,0XFF,0X00,0X00,0X61,0XFF,0XFC,0X60,0X00,0X00,
0X00,0X03,0XF0,0X01,0XFF,0XF0,0X1F,0XFF,0X00,0X00,0XC0,0XFF,0XFF,0XF0,0X00,0X00,
0X00,0X07,0XE0,0X01,0XFF,0XBF,0XFF,0XFF,0X80,0X00,0XE0,0X00,0X7F,0XF0,0X00,0X00,
0X00,0X03,0XC0,0X01,0XFF,0X3F,0XFF,0XFF,0X80,0X00,0XC0,0X00,0X3F,0XF8,0X00,0X00,
0X00,0X01,0X80,0X01,0XFE,0X7F,0XFF,0XFF,0X80,0X00,0X80,0X00,0X1F,0XFC,0X00,0X00,
0X00,0X07,0X00,0X00,0XFE,0X7F,0XFF,0XFF,0X80,0X00,0X80,0X00,0X0C,0XFC,0X00,0X00,
0X00,0X03,0X00,0X00,0XF0,0X7F,0XFF,0XFF,0X00,0X00,0X80,0X00,0X04,0X7C,0X00,0X00,
0X00,0X03,0X00,0X00,0X7E,0X3F,0XFF,0XFC,0X00,0X01,0X80,0X00,0X03,0XFC,0X00,0X00,
0X00,0X03,0X00,0X00,0X7E,0X3F,0XFF,0XFE,0X00,0X01,0X80,0X00,0X01,0XF0,0X00,0X00,
0X00,0X03,0X00,0X00,0X3F,0XDF,0XBF,0XFF,0X80,0X01,0X80,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X3F,0XCF,0XBF,0XFF,0XC0,0X01,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X7F,0XCF,0XFF,0XFF,0XE0,0X01,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0XFF,0XCF,0XCF,0XFF,0XC0,0X01,0X80,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X1E,0XFF,0XEF,0XC7,0XFF,0XC0,0X01,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X01,0XFC,0XFF,0XE7,0XF0,0X7F,0X80,0X03,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X07,0X07,0XC0,0XFF,0XF3,0XF8,0XFF,0X00,0X0F,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X0F,0X80,0X7F,0XF3,0XF9,0XFE,0X00,0X0E,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0X1F,0X00,0X3F,0XF3,0XFB,0XFE,0X00,0X0C,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0X38,0X00,0X03,0XF9,0XFB,0XF3,0XE0,0X18,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0XF0,0X00,0X3C,0XF9,0XFB,0XEF,0XF0,0X30,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0XC0,0X00,0X7D,0XF9,0XFB,0XCF,0XF0,0X70,0X00,0X00,0X18,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0XFF,0XF8,0XFB,0XCF,0XFC,0XC0,0X00,0X03,0XF8,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0XFF,0XFC,0XFB,0XFF,0XFC,0X00,0X00,0X07,0XF8,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0XFF,0XDE,0XFB,0XFF,0X7C,0X00,0X00,0X3F,0XFC,0X00,0X00,0X00,
0X00,0X01,0X00,0X00,0XFF,0XDE,0XF3,0XFF,0X3C,0X00,0X00,0X7F,0XFE,0X00,0X00,0X00,
0X00,0X01,0X00,0X00,0XFF,0XC2,0XF3,0XFF,0X1C,0X00,0X00,0XFF,0XFE,0X00,0X00,0X00,
0X00,0X01,0X00,0X00,0XFB,0XE3,0XFF,0XFF,0X3C,0X00,0X00,0XFF,0XFF,0X00,0X00,0X00,
0X00,0X01,0X00,0X00,0XF9,0XEF,0XFF,0XFE,0X3C,0X00,0X00,0XFF,0XFF,0X00,0X00,0X00,
0X00,0X01,0X00,0X00,0XFC,0XFF,0XFF,0XF9,0XFC,0X00,0X00,0XDC,0X7F,0X00,0X00,0X00,
0X00,0X01,0X00,0X01,0XFE,0X7F,0XFF,0XE3,0XFE,0X00,0X00,0XFF,0XBF,0X00,0X00,0X00,
0X00,0X01,0X00,0X01,0XFE,0X3F,0XFF,0XC7,0XFE,0X00,0X00,0XFF,0X9F,0X00,0X00,0X00,
0X00,0X01,0X00,0X03,0XFF,0X3F,0XFF,0XCF,0XFF,0X00,0X00,0XFF,0XBF,0X00,0X00,0X00,
0X00,0X01,0X00,0XFF,0XFF,0XCF,0XFF,0XFF,0XFF,0X80,0X00,0XFF,0XFE,0X00,0X00,0X00,
0X00,0X01,0X0F,0XE0,0X7F,0XFF,0X87,0XFF,0XFF,0X80,0X00,0XFF,0XC0,0X00,0X00,0X00,
0X00,0X01,0X1F,0X80,0X3F,0XFF,0X03,0XFF,0XCE,0X00,0X00,0XFF,0X00,0X00,0X00,0X00,
0X00,0X01,0XF0,0X00,0X0F,0XFE,0X01,0XFC,0X1E,0X00,0X00,0XF0,0X00,0X00,0X00,0X00,
0X00,0X01,0XE0,0X7F,0XC7,0XFC,0X01,0XFC,0X3E,0X00,0X00,0XC1,0XFF,0XE0,0X00,0X00,
0X00,0X01,0XC1,0XFF,0XF7,0XF8,0X01,0XFF,0XFC,0X00,0X01,0X8D,0XFF,0XF0,0X00,0X00,
0X00,0X01,0X87,0XFF,0XFB,0XFC,0X01,0XFF,0XF8,0X00,0X0F,0X1E,0XFF,0XF8,0X00,0X00,
0X00,0X01,0X3F,0X80,0X03,0XFC,0X01,0XFF,0XF0,0X00,0X0E,0X7E,0X7F,0XFE,0X00,0X00,
0X00,0X01,0XF8,0X00,0X07,0XFE,0X01,0XFF,0XE2,0X00,0X1E,0X7F,0X3F,0XFC,0X00,0X00,
0X00,0X01,0XE0,0XFF,0X9F,0XDF,0X03,0XFF,0XC6,0X60,0X1C,0XFF,0X8F,0XFE,0X00,0X00,
0X00,0X01,0X8F,0XC0,0XFF,0X3F,0XC7,0XEF,0XE3,0X78,0X3E,0X1F,0XCF,0XFF,0X00,0X00,
0X00,0X01,0XDF,0X80,0XFE,0X7F,0XEF,0XE7,0XF1,0XBC,0X7F,0X0F,0XCF,0XFF,0XC0,0X00,
0X00,0X01,0XFC,0X00,0XFD,0XFF,0XFF,0XE3,0XF1,0X9E,0X3F,0XC3,0XE7,0XFF,0X00,0X00,
0X00,0X01,0XF8,0X01,0XF1,0XF9,0XFF,0XF1,0XFD,0XCF,0X9F,0XE1,0XFF,0XFF,0X00,0X00,
0X00,0X01,0X80,0X01,0XF3,0XF1,0XFF,0XF9,0XFD,0XC1,0X9F,0XF8,0XFF,0XE0,0X00,0X00,
0X00,0X01,0X00,0X01,0XFF,0XE3,0XFD,0XFE,0XFF,0XC0,0X3F,0XF0,0X00,0X03,0X80,0X00,
0X00,0X01,0X00,0X00,0XFF,0XE3,0XFD,0XFF,0X7F,0XC0,0X7F,0XC0,0X00,0X07,0X80,0X00,
0X00,0X01,0X00,0X00,0XFF,0XE7,0XFC,0XFF,0X07,0X80,0XFF,0XCF,0XFF,0XFF,0X00,0X00,
0X00,0X01,0X00,0X00,0XFF,0XEF,0XCE,0X7F,0X07,0X00,0X7E,0X7F,0XFF,0XFE,0X00,0X00,
0X00,0X01,0X1F,0XFE,0XFF,0XFF,0XCE,0X7F,0X3E,0X00,0X3E,0X7F,0XFF,0XFC,0X00,0X00,
0X00,0X01,0XFF,0XFF,0XFF,0XF1,0XCE,0X3F,0X3E,0X00,0X3F,0XFC,0X07,0XF8,0X00,0X00,
0X00,0X01,0XFF,0XFF,0X3F,0XE1,0X8E,0X3F,0X3E,0X00,0X1F,0XFC,0X07,0XF0,0X00,0X00,
0X00,0X01,0XE0,0X00,0X0E,0X03,0X8E,0X3F,0X3E,0X00,0X0F,0XFF,0XF8,0X00,0X00,0X00,
0X00,0X01,0XFF,0XFF,0X87,0XFF,0X8E,0X3F,0X1E,0X00,0X04,0XFE,0X3E,0X00,0X00,0X00,
0X00,0X01,0XFF,0XFF,0XC7,0XFF,0X8F,0X3F,0XBE,0X00,0X00,0XFE,0X1E,0X00,0X00,0X00,
0X00,0X01,0XFF,0XFF,0XC7,0XFF,0X8F,0X9F,0XFE,0X00,0X00,0XFC,0X3F,0X80,0X00,0X00,
0X00,0X01,0X87,0XFF,0X8F,0XFF,0X8F,0X9F,0XFE,0X00,0X00,0X79,0XFF,0XC0,0X00,0X00,
0X00,0X01,0X00,0X06,0X3F,0XFF,0X8F,0XDF,0XFE,0X00,0X00,0X7F,0XFF,0XC0,0X00,0X00,
0X00,0X01,0X00,0X00,0X7F,0XFF,0X8F,0X8F,0XFC,0X00,0X00,0X1F,0XFF,0XE0,0X00,0X00,
0X00,0X01,0X80,0X00,0XFF,0XFF,0X8F,0X1F,0X00,0X00,0X00,0X0F,0XFF,0XF0,0X00,0X00,
0X00,0X01,0XC0,0X01,0XFF,0XFF,0X8E,0X3F,0X81,0X00,0X00,0X01,0XFF,0XE0,0X00,0X00,
0X00,0X01,0XE0,0X01,0XFF,0XFF,0X8E,0X7F,0XC3,0X80,0X00,0X00,0XFF,0X80,0X00,0X00,
0X00,0X01,0XF8,0X00,0XFF,0XF3,0X8E,0X7F,0XE7,0XC0,0X00,0X00,0X7F,0X00,0X00,0X00,
0X00,0X01,0XFF,0X80,0XFF,0XE7,0X8F,0XFF,0XC4,0XE0,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0X87,0XE1,0XFF,0XDF,0X8F,0XFF,0XCE,0X1C,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0XF1,0XF8,0XFF,0XFF,0X8F,0XFF,0XCF,0XCF,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0XFE,0X1C,0XFF,0XBE,0X43,0XE0,0X1F,0XF3,0X80,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0XFF,0X06,0X7F,0X3E,0X63,0XC1,0X3F,0XF1,0XE0,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0XFF,0X83,0X3E,0X3C,0XF3,0X81,0X1F,0XF8,0XF0,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0XFF,0XE1,0X80,0X39,0XFF,0X00,0X07,0XFE,0X78,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0XFF,0XFE,0X60,0X1F,0XFE,0X1C,0X03,0XFF,0X1C,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0X0F,0XFF,0X3C,0X1F,0XFE,0X60,0X01,0XFF,0X8E,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0X01,0XFF,0X9E,0X0F,0XFF,0XC0,0X00,0X3F,0XC3,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0X00,0X7F,0XC3,0X8F,0XFD,0X80,0X00,0X3F,0XE3,0X80,0X00,0X00,0X00,0X00,
0X00,0X01,0X00,0X3F,0XE1,0XC7,0XFC,0X00,0X00,0X3F,0XF1,0XC0,0X00,0X00,0X00,0X00,
0X00,0X01,0X00,0X1F,0XF1,0XE3,0XF8,0X00,0X00,0X07,0XF0,0X60,0X00,0X00,0X00,0X00,
0X00,0X01,0X80,0X0F,0XF1,0XE1,0XF0,0X00,0X00,0X03,0XF8,0X30,0X00,0X00,0X00,0X00,
0X00,0X01,0X80,0X01,0XF8,0X30,0X00,0X00,0X00,0X01,0XFC,0X3C,0X00,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0XF8,0X18,0X00,0X00,0X00,0X00,0XFC,0X0E,0X00,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0XFC,0X0C,0X00,0X00,0X00,0X00,0XFE,0X0F,0X00,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X7C,0X0C,0X00,0X00,0X00,0X00,0X7E,0X07,0X80,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X7C,0X06,0X00,0X00,0X00,0X00,0X3F,0X03,0X80,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X7E,0X06,0X00,0X00,0X00,0X00,0X1F,0X81,0X80,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X1E,0X03,0X00,0X00,0X00,0X00,0X0F,0X80,0XC0,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X0E,0X01,0X00,0X00,0X00,0X00,0X07,0X80,0X60,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X0F,0X01,0X80,0X00,0X00,0X00,0X03,0XC0,0X30,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X07,0X81,0XC0,0X00,0X00,0X00,0X01,0XC0,0X38,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X07,0X81,0XC0,0X00,0X00,0X00,0X00,0XC0,0X18,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X07,0XC0,0XE0,0X00,0X00,0X00,0X00,0X40,0X08,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X03,0XC0,0XF0,0X00,0X00,0X00,0X00,0X00,0X04,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X03,0XC0,0X70,0X00,0X00,0X00,0X00,0X00,0X06,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X01,0XC0,0X70,0X00,0XF8,0X00,0X00,0X00,0X02,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X03,0XC0,0X30,0X00,0XFF,0XF0,0X00,0X00,0X07,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X03,0XC0,0X30,0X01,0XFF,0XF8,0X00,0X00,0X03,0X80,0X00,0X00,
0X00,0X01,0X80,0X00,0X01,0XC0,0X30,0X01,0XFF,0XFC,0X00,0X00,0X03,0X80,0X00,0X00,
0X00,0X01,0X80,0X00,0X01,0XC0,0X18,0X01,0XFF,0XFE,0X00,0X00,0X03,0X80,0X00,0X00,
0X00,0X01,0X80,0X00,0X01,0XC0,0X08,0X00,0XFF,0XFF,0X00,0X00,0X01,0XC0,0X00,0X00,
0X00,0X01,0X80,0X00,0X01,0XC0,0X08,0X00,0X67,0XFF,0X00,0X00,0X01,0XC0,0X00,0X00,
0X00,0X01,0X80,0X00,0X01,0XC0,0X08,0X00,0XFF,0XFF,0X00,0X00,0X00,0XC0,0X00,0X00,
0X00,0X01,0X80,0X00,0X01,0X80,0X08,0X03,0XFF,0XBF,0X80,0X00,0X00,0X40,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X07,0XFF,0X3F,0X80,0X00,0X00,0X40,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X03,0XFF,0XBF,0XC0,0X00,0X00,0X40,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X03,0XFF,0X3F,0XC0,0X00,0X00,0X40,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X03,0XF0,0X1F,0XC0,0X00,0X00,0X40,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X03,0XFF,0XCF,0XF0,0X00,0X00,0X40,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X01,0XFF,0XE7,0XFC,0X00,0X00,0XC0,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X01,0XFF,0XF3,0XFF,0XF0,0X01,0XC0,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X01,0XFF,0XF8,0XFF,0XF8,0X01,0X80,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X00,0X7F,0XFC,0X7F,0XFF,0X03,0X80,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X00,0X1F,0XFF,0X00,0X7F,0X83,0X80,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X00,0X3F,0XFF,0X80,0X1F,0XC7,0X80,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X00,0X3F,0XFF,0XFF,0XFF,0XC3,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X00,0X3F,0XFF,0XFF,0XFF,0XC4,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X00,0X3F,0XFF,0XFF,0XFF,0XC4,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X18,0X00,0X1F,0XFF,0XFF,0XFF,0XC4,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X38,0X00,0X0F,0XFF,0XFF,0XFF,0XC0,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X78,0X00,0X03,0XFF,0XFF,0XFF,0XC0,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0XF8,0X00,0X00,0X7F,0XFF,0XFF,0XFC,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X01,0XF8,0X00,0X00,0X3F,0XFF,0XFF,0XFC,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X38,0X00,0X00,0X3F,0XFF,0XF9,0XFC,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X18,0X00,0X00,0X3F,0XFF,0XF3,0XFC,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X00,0X00,0X3F,0XFF,0XE7,0XFC,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X08,0X00,0X00,0X3C,0XFC,0X1F,0XF8,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X8C,0X00,0X00,0X7E,0X00,0X7F,0X98,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X79,0X8C,0X00,0X07,0XFF,0X0F,0XFF,0X9C,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0XFC,0XC6,0X00,0X0F,0XFF,0X7F,0XFF,0X78,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X01,0XF8,0X46,0X00,0X0F,0XFF,0X7F,0XFE,0X78,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X03,0XFC,0X07,0X00,0X0F,0XFF,0X7F,0XFE,0X78,0X00,0X00,0X00,
0X00,0X00,0X80,0X00,0X07,0XFE,0X07,0XC0,0X0F,0XFF,0X7F,0XFE,0X60,0X00,0X00,0X00,
0X00,0X00,0X80,0X00,0X07,0XF9,0XE7,0XE0,0X07,0XFF,0X7F,0XF8,0XC0,0X00,0X00,0X00,
0X00,0X00,0X80,0X00,0X03,0XE3,0XF3,0XF0,0X03,0XFF,0XFF,0XF1,0XC0,0X00,0X00,0X00,
0X00,0X00,0X80,0X00,0X7F,0XC3,0XF3,0X38,0X01,0XFF,0XFF,0XF1,0X80,0X00,0X00,0X00,
0X00,0X00,0X80,0X00,0XFF,0XDF,0XF3,0X1C,0X00,0X7F,0XFF,0XE3,0X80,0X00,0X00,0X00,
0X00,0X00,0X80,0X00,0XFF,0X9F,0XF3,0X8E,0X00,0X3F,0XFF,0XE7,0X80,0X00,0X00,0X00,
0X00,0X00,0X80,0X00,0XFE,0X33,0XFB,0XCF,0X00,0X1F,0XFF,0XCF,0X00,0X00,0X00,0X00,
0X00,0X00,0X80,0X01,0XFE,0X3F,0XF1,0XCF,0X00,0X0F,0XFF,0XCF,0X00,0X00,0X00,0X00,
0X00,0X00,0X80,0X00,0X0C,0X7F,0XCD,0XE3,0X80,0X0F,0XFF,0XDF,0X00,0X00,0X00,0X00,
0X00,0X00,0X80,0X01,0X01,0XFC,0X8E,0X7F,0X80,0X0F,0XFF,0X9F,0X00,0X00,0X00,0X00,
0X00,0X00,0X80,0X0F,0XF9,0XFC,0X1E,0X3F,0X80,0X0F,0XF3,0XBF,0X00,0X00,0X00,0X00,
0X00,0X00,0X80,0X0F,0XFD,0XFC,0X3E,0X3F,0X80,0X0F,0XE1,0XBF,0X00,0X00,0X00,0X00,
0X00,0X00,0X80,0X0F,0XFC,0XFC,0X3F,0X3F,0X80,0X0F,0XC1,0X3F,0X00,0X00,0X00,0X00,
0X00,0X00,0X80,0X1F,0XE5,0XF8,0X3B,0X9F,0X80,0X0F,0XC2,0X3F,0X80,0X00,0X00,0X00,
0X00,0X00,0X80,0X1F,0XCF,0XF0,0X33,0XDF,0XC0,0X03,0X9C,0X0F,0X80,0X00,0X00,0X00,
0X00,0X00,0X80,0X00,0X0E,0X00,0X39,0XD9,0XC0,0X00,0X38,0X63,0XC0,0X00,0X00,0X00,
0X00,0X00,0X80,0X0F,0XFE,0X00,0X0F,0XEE,0XF0,0X00,0XFF,0XF3,0XF0,0X00,0X00,0X00,
0X00,0X00,0X80,0X1F,0XFE,0X00,0X07,0XEE,0X78,0X01,0XFF,0XFF,0XF0,0X00,0X00,0X00,
0X00,0X00,0X00,0X1F,0XFE,0X00,0X07,0XEE,0X3C,0X01,0XFF,0XFF,0XF0,0X00,0X00,0X00,
0X00,0X00,0X00,0X1F,0XFE,0X00,0X07,0XEF,0X3C,0X01,0XFF,0XFF,0XF0,0X00,0X00,0X00,
0X00,0X00,0X00,0X1F,0X7C,0X00,0X00,0XEF,0XFC,0X01,0XFF,0XFF,0XF0,0X00,0X00,0X00,
0X00,0X00,0X00,0X1E,0X1C,0X00,0X00,0X6F,0XFC,0X01,0XFF,0XFF,0XC0,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X33,0XFE,0X00,0XFF,0XFF,0XC0,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFE,0X00,0XFF,0XFF,0X80,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X07,0XFE,0X00,0X3F,0XFF,0X80,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X07,0XFE,0X00,0X1F,0XFF,0X80,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFC,0X00,0X03,0XFF,0X80,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0XFE,0X00,0X03,0XFF,0X80,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X7E,0X00,0X03,0XFF,0X80,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0XFE,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X78,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X30,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
};
| 21,844 | C | .c | 278 | 76.464029 | 81 | 0.786837 | soonuse/epd-library-stm32 | 49 | 26 | 3 | GPL-3.0 | 9/7/2024, 9:47:02 AM (Europe/Amsterdam) | true | false | false | true | true | true | false | false |
2,474,270 | 093-dwarf2eh002.c | pipcet_asmjs/tests/093-dwarf2eh002/093-dwarf2eh002.c | #include <stdio.h>
void f ()
{
printf (" in f()\n");
throw 1;
}
main() {
try {
printf(" before throw\n");
f();
}
catch (...) {
printf(" in catch\n");
return 6;
}
printf(" back in main\n");
return 10;
}
| 232 | C | .c | 18 | 10.222222 | 28 | 0.528571 | pipcet/asmjs | 46 | 3 | 8 | GPL-3.0 | 9/7/2024, 9:47:02 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,474,514 | foo4.c | pipcet_asmjs/unsorted-experimentation/foo4.c | #include <stdlib.h>
#include <stdio.h>
#define JSEXPORT(what, name, prototype) \
void jsexport_ ## what (void) __attribute__((constructor)); \
void jsexport2_ ## what (void *what2) \
{ \
prototype = nullptr; \
what = (decltype(what))what2; \
asm(".pushsection .jsexport." name "\n\t" \
".asciz \"" #what "\"\n\t" \
".asciz \"" name "\"\n\t" \
".asciz \"" #prototype "\"\n\t" \
".popsection"); \
\
printf("%s %s %p\n", name, #prototype, (void *)what2); \
} \
\
void jsexport_ ## what (void) \
{ \
jsexport2_##what ((void *)what); \
}
__attribute__((stackcall)) extern int f(int a, int b);
__attribute__((stackcall, regparm(3))) __attribute__((always_inline)) extern int g(int);
__attribute__((stackcall)) __attribute__((jsexport)) int h(int, long long);
__attribute__((stackcall)) __attribute__((jsexport)) int k(int, long long);
JSEXPORT(qsort, "qsort", int (*qsort)(void *, size_t, size_t, int (*)(const void *, const void *)))
int main(void)
{
}
| 1,727 | C | .c | 29 | 49.655172 | 99 | 0.353301 | pipcet/asmjs | 46 | 3 | 8 | GPL-3.0 | 9/7/2024, 9:47:02 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,513,503 | lynxdef.h | libretro-mirrors_mednafen-git/src/lynx/lynxdef.h | //
// Copyright (c) 2004 K. Wilkins
//
// 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.
//
//////////////////////////////////////////////////////////////////////////////
// Handy - An Atari Lynx Emulator //
// Copyright (c) 1996,1997 //
// K. Wilkins //
//////////////////////////////////////////////////////////////////////////////
// Generic lyynx definition header file //
//////////////////////////////////////////////////////////////////////////////
// //
// This header file provides the definition of all of the useful hardware //
// addreses within the Lynx. //
// //
// K. Wilkins //
// August 1997 //
// //
//////////////////////////////////////////////////////////////////////////////
// Revision History: //
// ----------------- //
// //
// 01Aug1997 KW Document header added & class documented. //
// //
//////////////////////////////////////////////////////////////////////////////
#define TMPADR 0xfc00
#define TMPADRL 0xfc00
#define TMPADRH 0xfc01
#define TILTACUM 0xfc02
#define TILTACUML 0xfc02
#define TILTACUMH 0xfc03
#define HOFF 0xfc04
#define HOFFL 0xfc04
#define HOFFH 0xfc05
#define VOFF 0xfc06
#define VOFFL 0xfc06
#define VOFFH 0xfc07
#define VIDBAS 0xfc08
#define VIDBASL 0xfc08
#define VIDBASH 0xfc09
#define COLLBAS 0xfc0a
#define COLLBASL 0xfc0a
#define COLLBASH 0xfc0b
#define VIDADR 0xfc0c
#define VIDADRL 0xfc0c
#define VIDADRH 0xfc0d
#define COLLADR 0xfc0e
#define COLLADRL 0xfc0e
#define COLLADRH 0xfc0f
#define SCBNEXT 0xfc10
#define SCBNEXTL 0xfc10
#define SCBNEXTH 0xfc11
#define SPRDLINE 0xfc12
#define SPRDLINEL 0xfc12
#define SPRDLINEH 0xfc13
#define HPOSSTRT 0xfc14
#define HPOSSTRTL 0xfc14
#define HPOSSTRTH 0xfc15
#define VPOSSTRT 0xfc16
#define VPOSSTRTL 0xfc16
#define VPOSSTRTH 0xfc17
#define SPRHSIZ 0xfc18
#define SPRHSIZL 0xfc18
#define SPRHSIZH 0xfc19
#define SPRVSIZ 0xfc1a
#define SPRVSIZL 0xfc1a
#define SPRVSIZH 0xfc1b
#define STRETCH 0xfc1c
#define STRETCHL 0xfc1c
#define STRETCHH 0xfc1d
#define TILT 0xfc1e
#define TILTL 0xfc1e
#define TILTH 0xfc1f
#define SPRDOFF 0xfc20
#define SPRDOFFL 0xfc20
#define SPRDOFFH 0xfc21
#define SPRVPOS 0xfc22
#define SPRVPOSL 0xfc22
#define SPRVPOSH 0xfc23
#define COLLOFF 0xfc24
#define COLLOFFL 0xfc24
#define COLLOFFH 0xfc25
#define VSIZACUM 0xfc26
#define VSIZACUML 0xfc26
#define VSIZACUMH 0xfc27
#define HSIZOFF 0xfc28
#define HSIZOFFL 0xfc28
#define HSIZOFFH 0xfc29
#define VSIZOFF 0xfc2a
#define VSIZOFFL 0xfc2a
#define VSIZOFFH 0xfc2b
#define SCBADR 0xfc2c
#define SCBADRL 0xfc2c
#define SCBADRH 0xfc2d
#define PROCADR 0xfc2e
#define PROCADRL 0xfc2e
#define PROCADRH 0xfc2f
#define MATHD 0xfc52
#define MATHC 0xfc53
#define MATHB 0xfc54
#define MATHA 0xfc55
#define MATHP 0xfc56
#define MATHN 0xfc57
#define MATHH 0xfc60
#define MATHG 0xfc61
#define MATHF 0xfc62
#define MATHE 0xfc63
#define MATHM 0xfc6c
#define MATHL 0xfc6d
#define MATHK 0xfc6e
#define MATHJ 0xfc6f
#define SPRCTL0 0xfc80
#define SPRCTL1 0xfc81
#define SPRCOLL 0xfc82
#define SPRINIT 0xfc83
#define SUZYHREV 0xfc88
#define SUZYSREV 0xfc89
#define SUZYBUSEN 0xfc90
#define SPRGO 0xfc91
#define SPRSYS 0xfc92
#define JOYSTICK 0xfcb0
#define SWITCHES 0xfcb1
#define RCART0 0xfcb2
#define RCART1 0xfcb3
#define LEDS 0xfcc0
#define PPORTSTAT 0xfcc2
#define PPORTDATA 0xfcc3
#define HOWIE 0xfcc4
#define TIM0BKUP 0xfd00
#define TIM0CTLA 0xfd01
#define TIM0CNT 0xfd02
#define TIM0CTLB 0xfd03
#define TIM1BKUP 0xfd04
#define TIM1CTLA 0xfd05
#define TIM1CNT 0xfd06
#define TIM1CTLB 0xfd07
#define TIM2BKUP 0xfd08
#define TIM2CTLA 0xfd09
#define TIM2CNT 0xfd0a
#define TIM2CTLB 0xfd0b
#define TIM3BKUP 0xfd0c
#define TIM3CTLA 0xfd0d
#define TIM3CNT 0xfd0e
#define TIM3CTLB 0xfd0f
#define TIM4BKUP 0xfd10
#define TIM4CTLA 0xfd11
#define TIM4CNT 0xfd12
#define TIM4CTLB 0xfd13
#define TIM5BKUP 0xfd14
#define TIM5CTLA 0xfd15
#define TIM5CNT 0xfd16
#define TIM5CTLB 0xfd17
#define TIM6BKUP 0xfd18
#define TIM6CTLA 0xfd19
#define TIM6CNT 0xfd1a
#define TIM6CTLB 0xfd1b
#define TIM7BKUP 0xfd1c
#define TIM7CTLA 0xfd1d
#define TIM7CNT 0xfd1e
#define TIM7CTLB 0xfd1f
#define AUD0VOL 0xfd20
#define AUD0SHFTFB 0xfd21
#define AUD0OUTVAL 0xfd22
#define AUD0L8SHFT 0xfd23
#define AUD0TBACK 0xfd24
#define AUD0CTL 0xfd25
#define AUD0COUNT 0xfd26
#define AUD0MISC 0xfd27
#define AUD1VOL 0xfd28
#define AUD1SHFTFB 0xfd29
#define AUD1OUTVAL 0xfd2a
#define AUD1L8SHFT 0xfd2b
#define AUD1TBACK 0xfd2c
#define AUD1CTL 0xfd2d
#define AUD1COUNT 0xfd2e
#define AUD1MISC 0xfd2f
#define AUD2VOL 0xfd30
#define AUD2SHFTFB 0xfd31
#define AUD2OUTVAL 0xfd32
#define AUD2L8SHFT 0xfd33
#define AUD2TBACK 0xfd34
#define AUD2CTL 0xfd35
#define AUD2COUNT 0xfd36
#define AUD2MISC 0xfd37
#define AUD3VOL 0xfd38
#define AUD3SHFTFB 0xfd39
#define AUD3OUTVAL 0xfd3a
#define AUD3L8SHFT 0xfd3b
#define AUD3TBACK 0xfd3c
#define AUD3CTL 0xfd3d
#define AUD3COUNT 0xfd3e
#define AUD3MISC 0xfd3f
#define ATTEN_A 0xFD40 //
#define ATTEN_B 0xFD41
#define ATTEN_C 0xFD42 // Lynx2 Regs see macros/handy.equ
#define ATTEN_D 0xFD43
#define MPAN 0xFD44 //
#define MSTEREO 0xfd50
#define INTRST 0xfd80
#define INTSET 0xfd81
#define MAGRDY0 0xfd84
#define MAGRDY1 0xfd85
#define AUDIN 0xfd86
#define SYSCTL1 0xfd87
#define MIKEYHREV 0xfd88
#define MIKEYSREV 0xfd89
#define IODIR 0xfd8a
#define IODAT 0xfd8b
#define SERCTL 0xfd8c
#define SERDAT 0xfd8d
#define SDONEACK 0xfd90
#define CPUSLEEP 0xfd91
#define DISPCTL 0xfd92
#define PBKUP 0xfd93
#define DISPADR 0xfd94
#define DISPADRL 0xfd94
#define DISPADRH 0xfd95
#define Mtest0 0xfd9c
#define Mtest1 0xfd9d
#define Mtest2 0xfd9e
#define GREEN0 0xfda0
#define GREEN1 0xfda1
#define GREEN2 0xfda2
#define GREEN3 0xfda3
#define GREEN4 0xfda4
#define GREEN5 0xfda5
#define GREEN6 0xfda6
#define GREEN7 0xfda7
#define GREEN8 0xfda8
#define GREEN9 0xfda9
#define GREENA 0xfdaa
#define GREENB 0xfdab
#define GREENC 0xfdac
#define GREEND 0xfdad
#define GREENE 0xfdae
#define GREENF 0xfdaf
#define BLUERED0 0xfdb0
#define BLUERED1 0xfdb1
#define BLUERED2 0xfdb2
#define BLUERED3 0xfdb3
#define BLUERED4 0xfdb4
#define BLUERED5 0xfdb5
#define BLUERED6 0xfdb6
#define BLUERED7 0xfdb7
#define BLUERED8 0xfdb8
#define BLUERED9 0xfdb9
#define BLUEREDA 0xfdba
#define BLUEREDB 0xfdbb
#define BLUEREDC 0xfdbc
#define BLUEREDD 0xfdbd
#define BLUEREDE 0xfdbe
#define BLUEREDF 0xfdbf
#define MMAPCTL 0xfff9
#define CPUNMI 0xfffa
#define CPUNMIL 0xfffa
#define CPUNMIH 0xfffb
#define CPURESET 0xfffc
#define CPURESETL 0xfffc
#define CPURESETH 0xfffd
#define CPUINT 0xfffe
#define CPUINTL 0xfffe
#define CPUINTH 0xffff
| 8,759 | C | .h | 279 | 29.53405 | 78 | 0.650142 | libretro-mirrors/mednafen-git | 45 | 29 | 0 | GPL-2.0 | 9/7/2024, 9:47:02 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
2,585,991 | invert.c | freeman1974_libpsd/src/invert.c | /**
* libpsd - Photoshop file formats (*.psd) decode library
* Copyright (C) 2004-2007 Graphest Software.
*
* libpsd is the legal property of its developers, whose names are too numerous
* to list here. Please refer to the COPYRIGHT file distributed with this
* source distribution.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library 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 Library 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
*
* $Id: invert.c, created by Patrick in 2006.05.22, [email protected] Exp $
*/
#include <math.h>
#include "libpsd.h"
#include "psd_stream.h"
#include "psd_color.h"
#include "psd_rect.h"
#include "psd_blend.h"
extern void psd_adjustment_blend_image(psd_context * context, psd_layer_record * layer, psd_rect * dst_rect,
psd_uchar * lookup_table);
psd_status psd_get_layer_invert(psd_context * context, psd_layer_record * layer)
{
layer->layer_info_type[layer->layer_info_count] = psd_layer_info_type_invert;
layer->layer_type = psd_layer_type_invert;
layer->layer_info_count ++;
// there is no parameter in invert layer.
layer->adjustment_valid = psd_true;
return psd_status_done;
}
psd_bool psd_layer_blend_invert(psd_context * context, psd_layer_record * layer, psd_rect * dst_rect)
{
psd_int i;
psd_uchar lookup_table[256];
for(i = 0; i < 256; i ++)
lookup_table[i] = 255 - i;
psd_adjustment_blend_image(context, layer, dst_rect, lookup_table);
layer->adjustment_valid = psd_false;
return psd_true;
}
| 2,123 | C | .c | 51 | 38.352941 | 109 | 0.727628 | freeman1974/libpsd | 44 | 11 | 5 | GPL-2.0 | 9/7/2024, 9:47:02 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
2,826,797 | writelog.c | bernds_UAE/src/writelog.c | /*
* UAE - The Un*x Amiga Emulator
*
* Standard write_log that writes to the console
*
* Copyright 2001 Bernd Schmidt
*/
#include "sysconfig.h"
#include "sysdeps.h"
void write_log_standard (const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
#ifdef HAVE_VFPRINTF
vfprintf (stderr, fmt, ap);
#else
/* Technique stolen from GCC. */
{
int x1, x2, x3, x4, x5, x6, x7, x8;
x1 = va_arg (ap, int);
x2 = va_arg (ap, int);
x3 = va_arg (ap, int);
x4 = va_arg (ap, int);
x5 = va_arg (ap, int);
x6 = va_arg (ap, int);
x7 = va_arg (ap, int);
x8 = va_arg (ap, int);
fprintf (stderr, fmt, x1, x2, x3, x4, x5, x6, x7, x8);
}
#endif
}
| 672 | C | .c | 31 | 19.096774 | 55 | 0.599374 | bernds/UAE | 37 | 6 | 0 | GPL-2.0 | 9/7/2024, 9:50:43 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,914,477 | a9746.c | ps2homebrew_Fceumm-PS2/src/boards/a9746.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
#include "mmc3.h"
static DECLFW(UNLA9746Write) {
// FCEU_printf("write raw %04x:%02x\n",A,V);
switch (A & 0xE003) {
case 0x8000: EXPREGS[1] = V; EXPREGS[0] = 0; break;
case 0x8002: EXPREGS[0] = V; EXPREGS[1] = 0; break;
case 0x8001:
{
uint8 bits_rev = ((V & 0x20) >> 5) | ((V & 0x10) >> 3) | ((V & 0x08) >> 1) | ((V & 0x04) << 1);
switch (EXPREGS[0]) {
case 0x26: setprg8(0x8000, bits_rev); break;
case 0x25: setprg8(0xA000, bits_rev); break;
case 0x24: setprg8(0xC000, bits_rev); break;
case 0x23: setprg8(0xE000, bits_rev); break;
}
switch (EXPREGS[1]) {
case 0x0a:
case 0x08: EXPREGS[2] = (V << 4); break;
case 0x09: setchr1(0x0000, EXPREGS[2] | (V >> 1)); break;
case 0x0b: setchr1(0x0400, EXPREGS[2] | (V >> 1) | 1); break;
case 0x0c:
case 0x0e: EXPREGS[2] = (V << 4); break;
case 0x0d: setchr1(0x0800, EXPREGS[2] | (V >> 1)); break;
case 0x0f: setchr1(0x0c00, EXPREGS[2] | (V >> 1) | 1); break;
case 0x10:
case 0x12: EXPREGS[2] = (V << 4); break;
case 0x11: setchr1(0x1000, EXPREGS[2] | (V >> 1)); break;
case 0x14:
case 0x16: EXPREGS[2] = (V << 4); break;
case 0x15: setchr1(0x1400, EXPREGS[2] | (V >> 1)); break;
case 0x18:
case 0x1a: EXPREGS[2] = (V << 4); break;
case 0x19: setchr1(0x1800, EXPREGS[2] | (V >> 1)); break;
case 0x1c:
case 0x1e: EXPREGS[2] = (V << 4); break;
case 0x1d: setchr1(0x1c00, EXPREGS[2] | (V >> 1)); break;
}
}
break;
}
}
static void UNLA9746Power(void) {
GenMMC3Power();
SetWriteHandler(0x8000, 0xbfff, UNLA9746Write);
}
void UNLA9746_Init(CartInfo *info) {
GenMMC3_Init(info, 128, 256, 0, 0);
info->Power = UNLA9746Power;
AddExState(EXPREGS, 6, 0, "EXPR");
}
| 2,533 | C | .c | 70 | 33.842857 | 97 | 0.664768 | ps2homebrew/Fceumm-PS2 | 32 | 10 | 3 | GPL-2.0 | 9/7/2024, 9:56:41 AM (Europe/Amsterdam) | false | true | false | true | true | true | false | false |
2,914,506 | 15.c | ps2homebrew_Fceumm-PS2/src/boards/15.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "mapinc.h"
static uint16 latchea;
static uint8 latched;
static uint8 *WRAM = NULL;
static uint32 WRAMSIZE;
static SFORMAT StateRegs[] =
{
{ &latchea, 2, "AREG" },
{ &latched, 1, "DREG" },
{ 0 }
};
static void Sync(void) {
int i;
setmirror(((latched >> 6) & 1) ^ 1);
switch (latchea) {
case 0x8000:
for (i = 0; i < 4; i++)
setprg8(0x8000 + (i << 13), (((latched & 0x7F) << 1) + i) ^ (latched >> 7));
break;
case 0x8002:
for (i = 0; i < 4; i++)
setprg8(0x8000 + (i << 13), ((latched & 0x7F) << 1) + (latched >> 7));
break;
case 0x8001:
case 0x8003:
for (i = 0; i < 4; i++) {
unsigned int b;
b = latched & 0x7F;
if (i >= 2 && !(latchea & 0x2))
b = 0x7F;
setprg8(0x8000 + (i << 13), (i & 1) + ((b << 1) ^ (latched >> 7)));
}
break;
}
}
static DECLFW(M15Write) {
latchea = A;
latched = V;
Sync();
}
static void StateRestore(int version) {
Sync();
}
static void M15Power(void) {
latchea = 0x8000;
latched = 0;
setchr8(0);
setprg8r(0x10, 0x6000, 0);
SetReadHandler(0x6000, 0x7FFF, CartBR);
SetWriteHandler(0x6000, 0x7FFF, CartBW);
SetWriteHandler(0x8000, 0xFFFF, M15Write);
SetReadHandler(0x8000, 0xFFFF, CartBR);
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
Sync();
}
static void M15Reset(void) {
latchea = 0x8000;
latched = 0;
Sync();
}
static void M15Close(void) {
if (WRAM)
FCEU_gfree(WRAM);
WRAM = NULL;
}
void Mapper15_Init(CartInfo *info) {
info->Power = M15Power;
info->Reset = M15Reset;
info->Close = M15Close;
GameStateRestore = StateRestore;
WRAMSIZE = 8192;
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
if (info->battery) {
info->SaveGame[0] = WRAM;
info->SaveGameLen[0] = WRAMSIZE;
}
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0);
}
| 2,642 | C | .c | 100 | 24.3 | 81 | 0.682464 | ps2homebrew/Fceumm-PS2 | 32 | 10 | 3 | GPL-2.0 | 9/7/2024, 9:56:41 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
2,914,512 | SA-9602B.c | ps2homebrew_Fceumm-PS2/src/boards/SA-9602B.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2012 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
#include "mmc3.h"
static void SA9602BPW(uint32 A, uint8 V) {
setprg8r(EXPREGS[1], A, V & 0x3F);
if (MMC3_cmd & 0x40)
setprg8r(0, 0x8000, ~(1));
else
setprg8r(0, 0xc000, ~(1));
setprg8r(0, 0xe000, ~(0));
}
static DECLFW(SA9602BWrite) {
switch (A & 0xe001) {
case 0x8000: EXPREGS[0] = V; break;
case 0x8001:
if ((EXPREGS[0] & 7) < 6) {
EXPREGS[1] = V >> 6;
FixMMC3PRG(MMC3_cmd);
}
break;
}
MMC3_CMDWrite(A, V);
}
static void SA9602BPower(void) {
EXPREGS[0] = EXPREGS[1] = 0;
GenMMC3Power();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xBFFF, SA9602BWrite);
}
void SA9602B_Init(CartInfo *info) {
GenMMC3_Init(info, 512, 0, 0, 0);
pwrap = SA9602BPW;
mmc3opts |= 2;
info->SaveGame[0] = UNIFchrrama;
info->SaveGameLen[0] = 32 * 1024;
info->Power = SA9602BPower;
AddExState(EXPREGS, 2, 0, "EXPR");
}
| 1,704 | C | .c | 56 | 28.375 | 81 | 0.715764 | ps2homebrew/Fceumm-PS2 | 32 | 10 | 3 | GPL-2.0 | 9/7/2024, 9:56:41 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
2,914,518 | mihunche.c | ps2homebrew_Fceumm-PS2/src/boards/mihunche.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2013 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint16 latche;
static SFORMAT StateRegs[] =
{
{ &latche, 2, "LATC" },
{ 0 }
};
static void Sync(void) {
setprg32(0x8000, 0);
if(CHRsize[0] == 8192) {
setchr4(0x0000, latche & 1);
setchr4(0x1000, latche & 1);
} else {
setchr8(latche & 1); // actually, my bad, overdumped roms, the real CHR size if 8K
}
setmirror(MI_0 + (latche & 1));
}
static DECLFW(UNLCC21Write1) {
latche = A;
Sync();
}
static DECLFW(UNLCC21Write2) {
latche = V;
Sync();
}
static void UNLCC21Power(void) {
latche = 0;
Sync();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8001, 0xFFFF, UNLCC21Write1);
SetWriteHandler(0x8000, 0x8000, UNLCC21Write2); // another one many-in-1 mapper, there is a lot of similar carts with little different wirings
}
static void StateRestore(int version) {
Sync();
}
void UNLCC21_Init(CartInfo *info) {
info->Power = UNLCC21Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 1,805 | C | .c | 59 | 28.694915 | 143 | 0.736327 | ps2homebrew/Fceumm-PS2 | 32 | 10 | 3 | GPL-2.0 | 9/7/2024, 9:56:41 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
2,914,527 | bonza.c | ps2homebrew_Fceumm-PS2/src/boards/bonza.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
#define CARD_EXTERNAL_INSERED 0x80
static uint8 prg_reg;
static uint8 chr_reg;
static SFORMAT StateRegs[] =
{
{ &prg_reg, 1, "PREG" },
{ &chr_reg, 1, "CREG" },
{ 0 }
};
/*
cmd[0] = response on/off
0x00 - on
0x80 - off
cmd[1] = cmd
_GET_CHALLENGE: .BYTE 0,$B4, 0, 0,$62
_SELECT_FILE_1_0200: .BYTE 0,$A4, 1, 0, 2, 2, 0
_SELECT_FILE_2_0201: .BYTE 0,$A4, 2, 0, 2, 2, 1
_SELECT_FILE_2_0203: .BYTE 0,$A4, 2, 0, 2, 2, 3
_SELECT_FILE_2_0204: .BYTE 0,$A4, 2, 0, 2, 2, 4
_SELECT_FILE_2_0205: .BYTE 0,$A4, 2, 0, 2, 2, 5
_SELECT_FILE_2_3F04: .BYTE 0,$A4, 2, 0, 2,$3F, 4
_SELECT_FILE_2_4F00: .BYTE 0,$A4, 2, 0, 2,$4F, 0
_READ_BINARY_5: .BYTE 0,$B0,$85, 0, 2
_READ_BINARY_6: .BYTE 0,$B0,$86, 0, 4
_READ_BINARY_6_0: .BYTE 0,$B0,$86, 0,$18
_READ_BINARY_0: .BYTE 0,$B0, 0, 2, 3
_READ_BINARY_0_0: .BYTE 0,$B0, 0, 0, 4
_READ_BINARY_0_1: .BYTE 0,$B0, 0, 0, $C
_READ_BINARY_0_2: .BYTE 0,$B0, 0, 0,$10
_UPDATE_BINARY: .BYTE 0,$D6, 0, 0, 4
_UPDATE_BINARY_0: .BYTE 0,$D6, 0, 0,$10
_GET_RESPONSE: .BYTE $80,$C0, 2,$A1, 8
_GET_RESPONSE_0: .BYTE 0,$C0, 0, 0, 2
_GET_RESPONSE_1: .BYTE 0,$C0, 0, 0, 6
_GET_RESPONSE_2: .BYTE 0,$C0, 0, 0, 8
_GET_RESPONSE_3: .BYTE 0,$C0, 0, 0, $C
_GET_RESPONSE_4: .BYTE 0,$C0, 0, 0,$10
byte_8C0B: .BYTE $80,$30, 0, 2, $A, 0, 1
byte_8C48: .BYTE $80,$32, 0, 1, 4
byte_8C89: .BYTE $80,$34, 0, 0, 8, 0, 0
byte_8D01: .BYTE $80,$36, 0, 0, $C
byte_8CA7: .BYTE $80,$38, 0, 2, 4
byte_8BEC: .BYTE $80,$3A, 0, 3, 0
byte_89A0: .BYTE 0,$48, 0, 0, 6
byte_8808: .BYTE 0,$54, 0, 0,$1C
byte_89BF: .BYTE 0,$58, 0, 0,$1C
_MANAGE_CHANNEL: .BYTE 0,$70, 0, 0, 8
byte_8CE5: .BYTE 0,$74, 0, 0,$12
byte_8C29: .BYTE 0,$76, 0, 0, 8
byte_8CC6: .BYTE 0,$78, 0, 0,$12
*/
static uint8 sim0reset[0x1F] = {
0x3B, 0xE9, 0x00, 0xFF, 0xC1, 0x10, 0x31, 0xFE,
0x55, 0xC8, 0x10, 0x20, 0x55, 0x47, 0x4F, 0x53,
0x56, 0x53, 0x43, 0xAD, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10
};
static void Sync(void) {
setprg32(0x8000, prg_reg);
setchr8(chr_reg);
}
static void StateRestore(int version) {
Sync();
}
static DECLFW(M216WriteHi) {
prg_reg = A & 1;
chr_reg = (A & 0x0E) >> 1;
Sync();
}
static DECLFW(M216Write5000) {
// FCEU_printf("WRITE: %04x:%04x (PC=%02x cnt=%02x)\n",A,V,X.PC,sim0bcnt);
}
static DECLFR(M216Read5000) {
// FCEU_printf("READ: %04x PC=%04x out=%02x byte=%02x cnt=%02x bit=%02x\n",A,X.PC,sim0out,sim0byte,sim0bcnt,sim0bit);
return 0;
}
static void Power(void) {
prg_reg = 0;
chr_reg = 0;
Sync();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, M216WriteHi);
SetWriteHandler(0x5000, 0x5000, M216Write5000);
SetReadHandler(0x5000, 0x5000, M216Read5000);
}
void Mapper216_Init(CartInfo *info) {
info->Power = Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 3,966 | C | .c | 110 | 34.390909 | 117 | 0.605531 | ps2homebrew/Fceumm-PS2 | 32 | 10 | 3 | GPL-2.0 | 9/7/2024, 9:56:41 AM (Europe/Amsterdam) | false | true | false | true | true | true | false | false |
2,914,531 | super24.c | ps2homebrew_Fceumm-PS2/src/boards/super24.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
#include "mmc3.h"
static uint8 *CHRRAM = NULL;
static int masko8[8] = { 63, 31, 15, 1, 3, 0, 0, 0 };
static void Super24PW(uint32 A, uint8 V) {
uint32 NV = V & masko8[EXPREGS[0] & 7];
NV |= (EXPREGS[1] << 1);
setprg8r((NV >> 6) & 0xF, A, NV);
}
static void Super24CW(uint32 A, uint8 V) {
if (EXPREGS[0] & 0x20)
setchr1r(0x10, A, V);
else {
uint32 NV = V | (EXPREGS[2] << 3);
setchr1r((NV >> 9) & 0xF, A, NV);
}
}
static DECLFW(Super24Write) {
switch (A) {
case 0x5FF0:
EXPREGS[0] = V;
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
break;
case 0x5FF1:
EXPREGS[1] = V;
FixMMC3PRG(MMC3_cmd);
break;
case 0x5FF2:
EXPREGS[2] = V;
FixMMC3CHR(MMC3_cmd);
break;
}
}
static void Super24Power(void) {
EXPREGS[0] = 0x24;
EXPREGS[1] = 159;
EXPREGS[2] = 0;
GenMMC3Power();
SetWriteHandler(0x5000, 0x7FFF, Super24Write);
SetReadHandler(0x8000, 0xFFFF, CartBR);
}
static void Super24Reset(void) {
EXPREGS[0] = 0x24;
EXPREGS[1] = 159;
EXPREGS[2] = 0;
MMC3RegReset();
}
static void Super24Close(void) {
if (CHRRAM)
FCEU_gfree(CHRRAM);
CHRRAM = NULL;
}
void Super24_Init(CartInfo *info) {
GenMMC3_Init(info, 128, 256, 0, 0);
info->Power = Super24Power;
info->Reset = Super24Reset;
info->Close = Super24Close;
cwrap = Super24CW;
pwrap = Super24PW;
CHRRAM = (uint8*)FCEU_gmalloc(8192);
SetupCartCHRMapping(0x10, CHRRAM, 8192, 1);
AddExState(CHRRAM, 8192, 0, "CHRR");
AddExState(EXPREGS, 3, 0, "BIG2");
}
| 2,301 | C | .c | 84 | 25.345238 | 81 | 0.707428 | ps2homebrew/Fceumm-PS2 | 32 | 10 | 3 | GPL-2.0 | 9/7/2024, 9:56:41 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
2,914,536 | 232.c | ps2homebrew_Fceumm-PS2/src/boards/232.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2012 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 bank, preg;
static SFORMAT StateRegs[] =
{
{ &bank, 1, "BANK" },
{ &preg, 1, "PREG" },
{ 0 }
};
static void Sync(void) {
// uint32 bbank = (bank & 0x18) >> 1;
uint32 bbank = ((bank & 0x10) >> 2) | (bank & 8); // some dumps have bbanks swapped, if swap commands,
// then all roms can be played, but with some swapped
// games in menu. if not, some dumps are unplayable
// make hard dump for both cart types to check
setprg16(0x8000, bbank | (preg & 3));
setprg16(0xC000, bbank | 3);
setchr8(0);
}
static DECLFW(M232WriteBank) {
bank = V;
Sync();
}
static DECLFW(M232WritePreg) {
preg = V;
Sync();
}
static void M232Power(void) {
bank = preg = 0;
Sync();
SetWriteHandler(0x8000, 0xBFFF, M232WriteBank);
SetWriteHandler(0xC000, 0xFFFF, M232WritePreg);
SetReadHandler(0x8000, 0xFFFF, CartBR);
}
static void StateRestore(int version) {
Sync();
}
void Mapper232_Init(CartInfo *info) {
info->Power = M232Power;
AddExState(&StateRegs, ~0, 0, 0);
GameStateRestore = StateRestore;
}
| 1,905 | C | .c | 60 | 29.283333 | 103 | 0.710942 | ps2homebrew/Fceumm-PS2 | 32 | 10 | 3 | GPL-2.0 | 9/7/2024, 9:56:41 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
2,914,537 | bmc13in1jy110.c | ps2homebrew_Fceumm-PS2/src/boards/bmc13in1jy110.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* BMC 42-in-1 "reset switch" type
*/
#include "mapinc.h"
static uint8 bank_mode;
static uint8 bank_value;
static uint8 prgb[4];
static SFORMAT StateRegs[] =
{
{ &bank_mode, 1, "BNM" },
{ &bank_value, 1, "BMV" },
{ prgb, 4, "PRGB" },
{ 0 }
};
static void Sync(void) {
// FCEU_printf("%02x: %02x %02x\n", bank_mode, bank_value, prgb[0]);
switch (bank_mode & 7) {
case 0:
setprg32(0x8000, bank_value & 7); break;
case 1:
setprg16(0x8000, ((8 + (bank_value & 7)) >> 1) + prgb[1]);
setprg16(0xC000, (bank_value & 7) >> 1);
case 4:
setprg32(0x8000, 8 + (bank_value & 7)); break;
case 5:
setprg16(0x8000, ((8 + (bank_value & 7)) >> 1) + prgb[1]);
setprg16(0xC000, ((8 + (bank_value & 7)) >> 1) + prgb[3]);
case 2:
setprg8(0x8000, prgb[0] >> 2);
setprg8(0xa000, prgb[1]);
setprg8(0xc000, prgb[2]);
setprg8(0xe000, ~0);
break;
case 3:
setprg8(0x8000, prgb[0]);
setprg8(0xa000, prgb[1]);
setprg8(0xc000, prgb[2]);
setprg8(0xe000, prgb[3]);
break;
}
}
static DECLFW(BMC13in1JY110Write) {
// FCEU_printf("%04x:%04x\n",A,V);
switch (A) {
case 0x8000:
case 0x8001:
case 0x8002:
case 0x8003: prgb[A & 3] = V; break;
case 0xD000: bank_mode = V; break;
case 0xD001: setmirror(V & 3);
case 0xD002: break;
case 0xD003: bank_value = V; break;
}
Sync();
}
static void BMC13in1JY110Power(void) {
prgb[0] = prgb[1] = prgb[2] = prgb[3] = 0;
bank_mode = 0;
bank_value = 0;
setprg32(0x8000, 0);
setchr8(0);
SetWriteHandler(0x8000, 0xFFFF, BMC13in1JY110Write);
SetReadHandler(0x8000, 0xFFFF, CartBR);
}
static void StateRestore(int version) {
Sync();
}
void BMC13in1JY110_Init(CartInfo *info) {
info->Power = BMC13in1JY110Power;
AddExState(&StateRegs, ~0, 0, 0);
GameStateRestore = StateRestore;
}
| 2,574 | C | .c | 90 | 26.566667 | 81 | 0.691159 | ps2homebrew/Fceumm-PS2 | 32 | 10 | 3 | GPL-2.0 | 9/7/2024, 9:56:41 AM (Europe/Amsterdam) | false | false | false | true | false | false | false | false |
2,914,544 | 235.c | ps2homebrew_Fceumm-PS2/src/boards/235.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint16 cmdreg;
static SFORMAT StateRegs[] =
{
{ &cmdreg, 2, "CREG" },
{ 0 }
};
static void Sync(void) {
if (cmdreg & 0x400)
setmirror(MI_0);
else
setmirror(((cmdreg >> 13) & 1) ^ 1);
if (cmdreg & 0x800) {
setprg16(0x8000, ((cmdreg & 0x300) >> 3) | ((cmdreg & 0x1F) << 1) | ((cmdreg >> 12) & 1));
setprg16(0xC000, ((cmdreg & 0x300) >> 3) | ((cmdreg & 0x1F) << 1) | ((cmdreg >> 12) & 1));
} else
setprg32(0x8000, ((cmdreg & 0x300) >> 4) | (cmdreg & 0x1F));
}
static DECLFW(M235Write) {
cmdreg = A;
Sync();
}
static void M235Power(void) {
setchr8(0);
SetWriteHandler(0x8000, 0xFFFF, M235Write);
SetReadHandler(0x8000, 0xFFFF, CartBR);
cmdreg = 0;
Sync();
}
static void M235Restore(int version) {
Sync();
}
void Mapper235_Init(CartInfo *info) {
info->Power = M235Power;
GameStateRestore = M235Restore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 1,724 | C | .c | 56 | 28.857143 | 92 | 0.701385 | ps2homebrew/Fceumm-PS2 | 32 | 10 | 3 | GPL-2.0 | 9/7/2024, 9:56:41 AM (Europe/Amsterdam) | false | true | false | true | false | true | false | false |
2,914,549 | ghostbusters63in1.c | ps2homebrew_Fceumm-PS2/src/boards/ghostbusters63in1.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* 63in1 ghostbusters
*/
#include "mapinc.h"
static uint8 reg[2], bank;
static uint8 banks[4] = { 0, 0, 1, 2 };
static uint8 *CHRROM = NULL;
static uint32 CHRROMSIZE;
static SFORMAT StateRegs[] =
{
{ reg, 2, "REGS" },
{ &bank, 1, "BANK" },
{ 0 }
};
static void Sync(void) {
if (reg[0] & 0x20) {
setprg16r(banks[bank], 0x8000, reg[0] & 0x1F);
setprg16r(banks[bank], 0xC000, reg[0] & 0x1F);
} else
setprg32r(banks[bank], 0x8000, (reg[0] >> 1) & 0x0F);
if (reg[1] & 2)
setchr8r(0x10, 0);
else
setchr8(0);
setmirror((reg[0] & 0x40) >> 6);
}
static DECLFW(BMCGhostbusters63in1Write) {
reg[A & 1] = V;
bank = ((reg[0] & 0x80) >> 7) | ((reg[1] & 1) << 1);
// FCEU_printf("reg[0]=%02x, reg[1]=%02x, bank=%02x\n",reg[0],reg[1],bank);
Sync();
}
static DECLFR(BMCGhostbusters63in1Read) {
if (bank == 1)
return X.DB;
else
return CartBR(A);
}
static void BMCGhostbusters63in1Power(void) {
reg[0] = reg[1] = 0;
Sync();
SetReadHandler(0x8000, 0xFFFF, BMCGhostbusters63in1Read);
SetWriteHandler(0x8000, 0xFFFF, BMCGhostbusters63in1Write);
}
static void BMCGhostbusters63in1Reset(void) {
reg[0] = reg[1] = 0;
}
static void StateRestore(int version) {
Sync();
}
static void BMCGhostbusters63in1Close(void) {
if (CHRROM)
FCEU_gfree(CHRROM);
CHRROM = NULL;
}
void BMCGhostbusters63in1_Init(CartInfo *info) {
info->Reset = BMCGhostbusters63in1Reset;
info->Power = BMCGhostbusters63in1Power;
info->Close = BMCGhostbusters63in1Close;
CHRROMSIZE = 8192; // dummy CHRROM, VRAM disable
CHRROM = (uint8*)FCEU_gmalloc(CHRROMSIZE);
SetupCartPRGMapping(0x10, CHRROM, CHRROMSIZE, 0);
AddExState(CHRROM, CHRROMSIZE, 0, "CROM");
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 2,550 | C | .c | 83 | 28.783133 | 81 | 0.720456 | ps2homebrew/Fceumm-PS2 | 32 | 10 | 3 | GPL-2.0 | 9/7/2024, 9:56:41 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
2,914,572 | 01-222.c | ps2homebrew_Fceumm-PS2/src/boards/01-222.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* TXC mappers, originally much complex banksitching
*
* 01-22111-000 (05-00002-010) (132, 22211) - MGC-001 Qi Wang
* 01-22110-000 (52S ) - MGC-002 2-in-1 Gun
* 01-22111-100 (02-00002-010) (173 ) - MGC-008 Mahjong Block
* (079 ) - MGC-012 Poke Block
* 01-22110-200 (05-00002-010) (036 ) - MGC-014 Strike Wolf
* 01-22000-400 (05-00002-010) (036 ) - MGC-015 Policeman
* 01-22017-000 (05-PT017-080) (189 ) - MGC-017 Thunder Warrior
* 01-11160-000 (04-02310-000) ( , 11160) - MGC-023 6-in-1
* 01-22270-000 (05-00002-010) (132, 22211) - MGC-xxx Creatom
* 01-22200-400 (------------) (079 ) - ET.03 F-15 City War
* (172 ) - 1991 Du Ma Racing
*
*/
#include "mapinc.h"
static uint8 reg[4], cmd, is172, is173;
static SFORMAT StateRegs[] =
{
{ reg, 4, "REGS" },
{ &cmd, 1, "CMD" },
{ 0 }
};
static void Sync(void) {
setprg32(0x8000, (reg[2] >> 2) & 1);
if (is172)
setchr8((((cmd ^ reg[2]) >> 3) & 2) | (((cmd ^ reg[2]) >> 5) & 1)); // 1991 DU MA Racing probably CHR bank sequence is WRONG, so it is possible to
// rearrange CHR banks for normal UNIF board and mapper 172 is unneccessary
else
setchr8(reg[2] & 3);
}
static DECLFW(UNL22211WriteLo) {
// FCEU_printf("bs %04x %02x\n",A,V);
reg[A & 3] = V;
}
static DECLFW(UNL22211WriteHi) {
// FCEU_printf("bs %04x %02x\n",A,V);
cmd = V;
Sync();
}
static DECLFR(UNL22211ReadLo) {
return (reg[1] ^ reg[2]) | (is173 ? 0x01 : 0x40);
// if(reg[3])
// return reg[2];
// else
// return X.DB;
}
static void UNL22211Power(void) {
Sync();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetReadHandler(0x4100, 0x4100, UNL22211ReadLo);
SetWriteHandler(0x4100, 0x4103, UNL22211WriteLo);
SetWriteHandler(0x8000, 0xFFFF, UNL22211WriteHi);
}
static void StateRestore(int version) {
Sync();
}
void UNL22211_Init(CartInfo *info) {
is172 = 0;
is173 = 0;
info->Power = UNL22211Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
void Mapper172_Init(CartInfo *info) {
is172 = 1;
is173 = 0;
info->Power = UNL22211Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
void Mapper173_Init(CartInfo *info) {
is172 = 0;
is173 = 1;
info->Power = UNL22211Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 3,220 | C | .c | 97 | 31.175258 | 148 | 0.663131 | ps2homebrew/Fceumm-PS2 | 32 | 10 | 3 | GPL-2.0 | 9/7/2024, 9:56:41 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
2,914,575 | 8237.c | ps2homebrew_Fceumm-PS2/src/boards/8237.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2011 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Super Game (Sugar Softec) protected mapper
* Pocahontas 2 (Unl) [U][!], etc.
* TODO: 9in1 LION KING HANGS!
*/
#include "mapinc.h"
#include "mmc3.h"
static uint8 cmdin;
static uint8 regperm[8][8] =
{
{ 0, 1, 2, 3, 4, 5, 6, 7 },
{ 0, 2, 6, 1, 7, 3, 4, 5 },
{ 0, 5, 4, 1, 7, 2, 6, 3 }, // unused
{ 0, 6, 3, 7, 5, 2, 4, 1 },
{ 0, 2, 5, 3, 6, 1, 7, 4 },
{ 0, 1, 2, 3, 4, 5, 6, 7 }, // empty
{ 0, 1, 2, 3, 4, 5, 6, 7 }, // empty
{ 0, 1, 2, 3, 4, 5, 6, 7 }, // empty
};
static uint8 adrperm[8][8] =
{
{ 0, 1, 2, 3, 4, 5, 6, 7 },
{ 3, 2, 0, 4, 1, 5, 6, 7 },
{ 0, 1, 2, 3, 4, 5, 6, 7 }, // unused
{ 5, 0, 1, 2, 3, 7, 6, 4 },
{ 3, 1, 0, 5, 2, 4, 6, 7 },
{ 0, 1, 2, 3, 4, 5, 6, 7 }, // empty
{ 0, 1, 2, 3, 4, 5, 6, 7 }, // empty
{ 0, 1, 2, 3, 4, 5, 6, 7 }, // empty
};
static void UNL8237CW(uint32 A, uint8 V) {
if (EXPREGS[0] & 0x40)
setchr1(A, ((EXPREGS[1] & 0xc) << 6) | (V & 0x7F) | ((EXPREGS[1] & 0x20) << 2));
else
setchr1(A, ((EXPREGS[1] & 0xc) << 6) | V);
}
static void UNL8237PW(uint32 A, uint8 V) {
if (EXPREGS[0] & 0x40) {
uint8 sbank = (EXPREGS[1] & 0x10);
if (EXPREGS[0] & 0x80) {
uint8 bank = ((EXPREGS[1] & 3) << 4) | (EXPREGS[0] & 0x7) | (sbank >> 1);
if (EXPREGS[0] & 0x20)
setprg32(0x8000, bank >> 1);
else {
setprg16(0x8000, bank);
setprg16(0xC000, bank);
}
} else
setprg8(A, ((EXPREGS[1] & 3) << 5) | (V & 0x0F) | sbank);
} else {
if (EXPREGS[0] & 0x80) {
uint8 bank = ((EXPREGS[1] & 3) << 4) | (EXPREGS[0] & 0xF);
if (EXPREGS[0] & 0x20)
setprg32(0x8000, bank >> 1);
else {
setprg16(0x8000, bank);
setprg16(0xC000, bank);
}
} else
setprg8(A, ((EXPREGS[1] & 3) << 5) | (V & 0x1F));
}
}
static void UNL8237ACW(uint32 A, uint8 V) {
if (EXPREGS[0] & 0x40)
setchr1(A, ((EXPREGS[1] & 0xE) << 7) | (V & 0x7F) | ((EXPREGS[1] & 0x20) << 2));
else
setchr1(A, ((EXPREGS[1] & 0xE) << 7) | V);
}
static void UNL8237APW(uint32 A, uint8 V) {
if (EXPREGS[0] & 0x40) {
uint8 sbank = (EXPREGS[1] & 0x10);
if (EXPREGS[0] & 0x80) {
uint8 bank = ((EXPREGS[1] & 3) << 4) | ((EXPREGS[1] & 8) << 3) | (EXPREGS[0] & 0x7) | (sbank >> 1);
if (EXPREGS[0] & 0x20) {
// FCEU_printf("8000:%02X\n",bank>>1);
setprg32(0x8000, bank >> 1);
} else {
// FCEU_printf("8000-C000:%02X\n",bank);
setprg16(0x8000, bank);
setprg16(0xC000, bank);
}
} else {
// FCEU_printf("%04x:%02X\n",A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x0F)|sbank);
setprg8(A, ((EXPREGS[1] & 3) << 5) | ((EXPREGS[1] & 8) << 4) | (V & 0x0F) | sbank);
}
} else {
if (EXPREGS[0] & 0x80) {
uint8 bank = ((EXPREGS[1] & 3) << 4) | ((EXPREGS[1] & 8) << 3) | (EXPREGS[0] & 0xF);
if (EXPREGS[0] & 0x20) {
// FCEU_printf("8000:%02X\n",(bank>>1)&0x07);
setprg32(0x8000, bank >> 1);
} else {
// FCEU_printf("8000-C000:%02X\n",bank&0x0F);
setprg16(0x8000, bank);
setprg16(0xC000, bank);
}
} else {
// FCEU_printf("%04X:%02X\n",A,(((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x1F))&0x1F);
setprg8(A, ((EXPREGS[1] & 3) << 5) | ((EXPREGS[1] & 8) << 4) | (V & 0x1F));
}
}
}
static DECLFW(UNL8237Write) {
uint8 dat = V;
uint8 adr = adrperm[EXPREGS[2]][((A >> 12) & 6) | (A & 1)];
uint16 addr = (adr & 1) | ((adr & 6) << 12) | 0x8000;
if (adr < 4) {
if (!adr)
dat = (dat & 0xC0) | (regperm[EXPREGS[2]][dat & 7]);
MMC3_CMDWrite(addr, dat);
} else
MMC3_IRQWrite(addr, dat);
}
static DECLFW(UNL8237ExWrite) {
switch (A) {
case 0x5000: EXPREGS[0] = V; FixMMC3PRG(MMC3_cmd); break;
case 0x5001: EXPREGS[1] = V; FixMMC3PRG(MMC3_cmd); FixMMC3CHR(MMC3_cmd); break;
case 0x5007: EXPREGS[2] = V; break;
}
}
static void UNL8237Power(void) {
EXPREGS[0] = EXPREGS[2] = 0;
EXPREGS[1] = 3;
GenMMC3Power();
SetWriteHandler(0x8000, 0xFFFF, UNL8237Write);
SetWriteHandler(0x5000, 0x7FFF, UNL8237ExWrite);
}
void UNL8237_Init(CartInfo *info) {
GenMMC3_Init(info, 256, 256, 0, 0);
cwrap = UNL8237CW;
pwrap = UNL8237PW;
info->Power = UNL8237Power;
AddExState(EXPREGS, 3, 0, "EXPR");
AddExState(&cmdin, 1, 0, "CMDI");
}
void UNL8237A_Init(CartInfo *info) {
GenMMC3_Init(info, 256, 256, 0, 0);
cwrap = UNL8237ACW;
pwrap = UNL8237APW;
info->Power = UNL8237Power;
AddExState(EXPREGS, 3, 0, "EXPR");
AddExState(&cmdin, 1, 0, "CMDI");
}
| 5,107 | C | .c | 161 | 29.254658 | 102 | 0.588366 | ps2homebrew/Fceumm-PS2 | 32 | 10 | 3 | GPL-2.0 | 9/7/2024, 9:56:41 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |
2,914,618 | bmc70in1.c | ps2homebrew_Fceumm-PS2/src/boards/bmc70in1.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 is_large_banks, hw_switch;
static uint8 large_bank;
static uint8 prg_bank;
static uint8 chr_bank;
static uint8 bank_mode;
static uint8 mirroring;
static SFORMAT StateRegs[] =
{
{ &large_bank, 1, "LB" },
{ &hw_switch, 1, "DPSW" },
{ &prg_bank, 1, "PRG" },
{ &chr_bank, 1, "CHR" },
{ &bank_mode, 1, "BM" },
{ &mirroring, 1, "MIRR" },
{ 0 }
};
static void Sync(void) {
switch (bank_mode) {
case 0x00:
case 0x10:
setprg16(0x8000, large_bank | prg_bank);
setprg16(0xC000, large_bank | 7);
break;
case 0x20:
setprg32(0x8000, (large_bank | prg_bank) >> 1);
break;
case 0x30:
setprg16(0x8000, large_bank | prg_bank);
setprg16(0xC000, large_bank | prg_bank);
break;
}
setmirror(mirroring);
if (!is_large_banks)
setchr8(chr_bank);
}
static DECLFR(BMC70in1Read) {
if (bank_mode == 0x10)
// if(is_large_banks)
return CartBR((A & 0xFFF0) | hw_switch);
// else
// return CartBR((A&0xFFF0)|hw_switch);
else
return CartBR(A);
}
static DECLFW(BMC70in1Write) {
if (A & 0x4000) {
bank_mode = A & 0x30;
prg_bank = A & 7;
} else {
mirroring = ((A & 0x20) >> 5) ^ 1;
if (is_large_banks)
large_bank = (A & 3) << 3;
else
chr_bank = A & 7;
}
Sync();
}
static void BMC70in1Reset(void) {
bank_mode = 0;
large_bank = 0;
Sync();
hw_switch++;
hw_switch &= 0xf;
}
static void BMC70in1Power(void) {
setchr8(0);
bank_mode = 0;
large_bank = 0;
Sync();
SetReadHandler(0x8000, 0xFFFF, BMC70in1Read);
SetWriteHandler(0x8000, 0xffff, BMC70in1Write);
}
static void StateRestore(int version) {
Sync();
}
void BMC70in1_Init(CartInfo *info) {
is_large_banks = 0;
hw_switch = 0xd;
info->Power = BMC70in1Power;
info->Reset = BMC70in1Reset;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
void BMC70in1B_Init(CartInfo *info) {
is_large_banks = 1;
hw_switch = 0x6;
info->Power = BMC70in1Power;
info->Reset = BMC70in1Reset;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
| 2,823 | C | .c | 111 | 23.432432 | 81 | 0.703183 | ps2homebrew/Fceumm-PS2 | 32 | 10 | 3 | GPL-2.0 | 9/7/2024, 9:56:41 AM (Europe/Amsterdam) | false | true | false | true | true | true | false | false |
2,914,626 | __dummy_mapper.c | ps2homebrew_Fceumm-PS2/src/boards/__dummy_mapper.c | /* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2013 CaH4e3
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mapinc.h"
static uint8 reg[8];
static uint8 IRQa;
static int16 IRQCount, IRQLatch;
/*
static uint8 *WRAM = NULL;
static uint32 WRAMSIZE;
static uint8 *CHRRAM = NULL;
static uint32 CHRRAMSIZE;
*/
static SFORMAT StateRegs[] =
{
{ reg, 8, "REGS" },
{ &IRQa, 1, "IRQA" },
{ &IRQCount, 2, "IRQC" },
{ &IRQLatch, 2, "IRQL" },
{ 0 }
};
static void Sync(void) {
}
static DECLFW(MNNNWrite) {
}
static void MNNNPower(void) {
// SetReadHandler(0x6000, 0x7fff, CartBR);
// SetWriteHandler(0x6000, 0x7fff, CartBW);
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, MNNNWrite);
}
static void MNNNReset(void) {
}
/*
static void MNNNClose(void) {
if (WRAM)
FCEU_gfree(WRAM);
if (CHRRAM)
FCEU_gfree(CHRRAM);
WRAM = CHRRAM = NULL;
}
*/
static void MNNNIRQHook() {
X6502_IRQBegin(FCEU_IQEXT);
}
static void StateRestore(int version) {
Sync();
}
void MapperNNN_Init(CartInfo *info) {
info->Reset = MNNNReset;
info->Power = MNNNPower;
// info->Close = MNNNClose;
GameHBIRQHook = MNNNIRQHook;
GameStateRestore = StateRestore;
/*
CHRRAMSIZE = 8192;
CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE);
SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1);
AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM");
*/
/*
WRAMSIZE = 8192;
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) {
info->SaveGame[0] = WRAM;
info->SaveGameLen[0] = WRAMSIZE;
}
*/
AddExState(&StateRegs, ~0, 0, 0);
}
| 2,337 | C | .c | 88 | 24.829545 | 81 | 0.733244 | ps2homebrew/Fceumm-PS2 | 32 | 10 | 3 | GPL-2.0 | 9/7/2024, 9:56:41 AM (Europe/Amsterdam) | true | true | false | true | true | true | false | false |