blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
3
357
content_id
stringlengths
40
40
detected_licenses
listlengths
0
58
license_type
stringclasses
2 values
repo_name
stringlengths
4
115
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringlengths
4
58
visit_date
timestamp[ns]date
2015-07-14 21:31:45
2023-09-06 10:45:08
revision_date
timestamp[ns]date
1970-01-01 00:00:00
2023-09-05 23:26:37
committer_date
timestamp[ns]date
1970-01-01 00:00:00
2023-09-05 23:26:37
github_id
int64
966
689M
star_events_count
int64
0
209k
fork_events_count
int64
0
110k
gha_license_id
stringclasses
24 values
gha_event_created_at
timestamp[ns]date
2012-06-07 00:51:45
2023-09-14 21:58:52
gha_created_at
timestamp[ns]date
2008-02-03 21:17:16
2023-08-24 19:49:39
gha_language
stringclasses
180 values
src_encoding
stringclasses
35 values
language
stringclasses
1 value
is_vendor
bool
1 class
is_generated
bool
2 classes
length_bytes
int64
6
10.4M
extension
stringclasses
121 values
filename
stringlengths
1
148
content
stringlengths
6
10.4M
a13c24751a92e04d3ea662b73e93a597dc36c4ce
afa734f8682b7f5ce1ede4cac2e5454f9fe06dd2
/http_route.h
9eca8bb3b92acc373cdd84ca7466213259229066
[]
no_license
vladsemyr/CLogger
053db20a306509b5c46f10450970e93be88bd4f1
a5373883181ba9beeceb6b219168ad2ef39f34d4
refs/heads/main
2023-06-21T22:34:17.397077
2021-07-13T07:07:27
2021-07-13T07:07:27
380,139,270
0
0
null
null
null
null
UTF-8
C
false
false
1,192
h
http_route.h
#ifndef HTTP_ROUTE_H #define HTTP_ROUTE_H #include "http_header_parser.h" typedef int (*HttpRouteFunction)(); struct HttpRouteTableRow { enum HttpMethod method; String_t url; HttpRouteFunction function; }; struct HttpRouteTable { struct HttpRouteTableRow *rows; size_t row_registered_count; }; // TODO: функция инициализации таблицы void HttpRouteRegisterUrl( struct HttpRouteTable *table, enum HttpMethod method, String_t *url, HttpRouteFunction function); #define HttpRouteRegisterUrl2(ptr_table, method, url, function) { \ String_t _url = stringMethods.Create(url, sizeof(url)-1); \ HttpRouteRegisterUrl( \ ptr_table, \ method, \ &_url, \ function \ ); \ } void HttpRoute( struct HttpRouteTable *route_table, struct HttpRequest *request); #endif
1cee3c09dbad99b62dd9ea0b313f5f3d9a3559f6
fc3ae07559e17a8fa70ce96bc3d6266e24e10ee0
/0x0B-malloc_free/2-str_concat.c
9ea762c6329313813070c2c61a21adc3e95ed2f2
[]
no_license
cbayonao/holbertonschool-low_level_programming
b24066b287cd40b0f460d2c9efc81c70343747e1
1782608547ee7699d473894317f5e30d7c297681
refs/heads/master
2020-07-28T08:35:40.861656
2020-04-19T23:47:48
2020-04-19T23:47:48
209,366,644
0
0
null
null
null
null
UTF-8
C
false
false
575
c
2-str_concat.c
#include "holberton.h" #include <stdio.h> #include <stdlib.h> /** * str_concat - count the characters on a string * @s1: char * @s2: char * Return: char */ char *str_concat(char *s1, char *s2) { int x = 0, y = 0, i = 0, i2 = 0; char *array; if (s1 == NULL) s1 = ""; if (s2 == NULL) s2 = ""; for (; s1[x] != '\0'; x++) ; for (; s2[y] != '\0'; y++) ; array = malloc(sizeof(char) * x + y + 1); if (array == NULL) return (NULL); for (; i != x; i++) array[i] = s1[i]; for (; i != x + y; i++) { array[i] = s2[i2]; i2++; } return (array); }
8bf9bcbcc6398b2e794840c2607aded8571dab7b
30ebeda5a611deef3a2956a9adda480c99d33c8d
/Init_Container.h
62ea8492999bbb9425b74362c7c374545ed73bb2
[]
no_license
AnnaKramarenko/PROC
8c3bafefa3a45b4abe24002edef3a0e55fc5b725
89f5df0151ef4c1e469f6e271e1de5c63c5cc56e
refs/heads/main
2023-04-26T23:18:28.452088
2021-05-16T12:45:10
2021-05-16T12:45:10
362,766,587
0
0
null
2021-05-16T12:43:51
2021-04-29T09:44:00
C++
WINDOWS-1251
C
false
false
232
h
Init_Container.h
#ifndef INIT_CONTAINER_H #define INIT_CONTAINER_H #include "Container.h" //Функция инициализации контейнера void Init_Container(Container* Head, Container* Tail); #endif // INIT_CONTAINER_H
9986e3b3d291ea703816ab522a291f58d2c3b4c5
0833a2a510889836dc9154f5e39b9a96a223ba48
/mk-108.1/sys/pathname.h
d76a673f4c0095cab9a3ab64731af0f822a99df3
[]
no_license
johnsonjh/NeXTMach
189929022146f35dd13792c114de5da83f355a70
f6bdb9c3268f0eadc545d41bcc0564453b17001e
refs/heads/master
2023-05-14T00:51:20.245305
2021-08-19T20:18:35
2021-08-19T20:18:35
398,064,783
19
8
null
2021-08-19T20:20:42
2021-08-19T20:18:55
C
UTF-8
C
false
false
1,728
h
pathname.h
/* @(#)pathname.h 2.2 88/05/25 NFSSRC4.0 from 2.6 86/07/16 SMI */ /* * HISTORY * 27-Sep-89 Morris Meyer (mmeyer) at NeXT * NFS 4.0 Changes: Addtional path manipulation routines. */ /* * Pathname structure. * System calls which operate on path names gather the * pathname from system call into this structure and reduce * it by peeling off translated components. If a symbolic * link is encountered the new pathname to be translated * is also assembled in this structure. */ struct pathname { char *pn_buf; /* underlying storage */ char *pn_path; /* remaining pathname */ u_int pn_pathlen; /* remaining length */ }; #define PN_STRIP 0x00 /* Strip next component off pn */ #define PN_PEEK 0x01 /* Only peek at next pn component */ #define pn_peekcomponent(PNP, COMP) pn_getcomponent(PNP, COMP, PN_PEEK) #define pn_stripcomponent(PNP, COMP) pn_getcomponent(PNP, COMP, PN_STRIP) #define pn_peekchar(PNP) ((PNP)->pn_pathlen>0?*((PNP)->pn_path):0) #define pn_pathleft(PNP) ((PNP)->pn_pathlen) #define pn_getpath(PNP) ((PNP)->pn_path) #define pn_copy(PNP1, PNP2) (pn_set(PNP2, pn_getpath(PNP1))) extern int pn_alloc(); /* allocat buffer for pathname */ extern int pn_get(); /* allocate buf and copy path into it */ #ifdef notneeded extern int pn_getchar(); /* get next pathname char */ #endif extern int pn_set(); /* set pathname to string */ extern int pn_combine(); /* combine to pathnames (for symlink) */ extern int pn_getcomponent(); /* get next component of pathname */ extern void pn_skipslash(); /* skip over slashes */ extern void pn_free(); /* free pathname buffer */ extern int pn_append(); /* Append string to pathname */ extern int pn_getlast(); /* Get last component of pathname */
685964710f86660a74d7b0c905406d6af3a4ab7f
259f2e3eee5e925249e15e38a80ff1e90bc52f62
/CAR_Project A1_v2/CAR_Project A1/HAL/MOTOR/motor.c
f687e4ac8f10baa9e8a4e6a85c64fa1a593875ff
[]
no_license
ayaayman12/Static_Design_Challenge
fc44c16b5ce918cdfcc9a585c7a616d4961dedc4
686bb7d43cf4cb311b5712d798e779c9fe5b698b
refs/heads/master
2021-01-07T07:10:17.685499
2020-02-19T15:56:48
2020-02-19T15:56:48
241,615,176
0
0
null
null
null
null
UTF-8
C
false
false
3,840
c
motor.c
/* * motor.c * * Created: 2/16/2020 10:05:28 PM * Author: A_ayman */ #include "motor.h" volatile uint8_t gu8_DutyCycle=0; ERROR_STATUS Motor_Init(uint8_t Motor_Number) { strDIOCfg_t Dio_motor; uint8_t u8_Ret=E_OK; if(Motor_Number==1) { /*set direction for motor1*/ Dio_motor.GPIO=MOTOR_OUT_1A_GPIO; Dio_motor.pins=MOTOR_OUT_1A_BIT|MOTOR_OUT_1B_BIT|MOTOR_EN_1_BIT; Dio_motor.dir=OUTPUT; u8_Ret|=DIO_Init(&Dio_motor); } else if(Motor_Number==2) { Dio_motor.GPIO=MOTOR_OUT_2A_GPIO; Dio_motor.pins=MOTOR_OUT_2A_BIT|MOTOR_OUT_2B_BIT|MOTOR_EN_2_BIT; Dio_motor.dir=OUTPUT; u8_Ret|=DIO_Init(&Dio_motor); } else { /*do nothing just indicate that function not working well*/ u8_Ret= E_NOK; } Pwm_Cfg_s Pwm_Cfg; Pwm_Cfg_s Pwm_Cfg1; Pwm_Cfg.Channel =PWM_CH1A; Pwm_Cfg.Prescaler=0; Pwm_Cfg1.Channel =PWM_CH1B; Pwm_Cfg1.Prescaler=0; u8_Ret|=Pwm_Init(&Pwm_Cfg); //for motor one u8_Ret|=Pwm_Init(&Pwm_Cfg1);//for motor two return u8_Ret; } ERROR_STATUS Motor_Direction(uint8_t Motor_Number, uint8_t Motor_Direction) { uint8_t u8_Ret=E_OK; if (Motor_Number==MOTOR_1) { switch (Motor_Direction) { case (MOTOR_STOP): { u8_Ret|=DIO_Write(MOTOR_OUT_1A_GPIO,MOTOR_OUT_1A_BIT,LOW); u8_Ret|=DIO_Write(MOTOR_OUT_1B_GPIO,MOTOR_OUT_1B_BIT,LOW); break; } case (MOTOR_FORWARD): { u8_Ret|=DIO_Write(MOTOR_OUT_1A_GPIO,MOTOR_OUT_1A_BIT,HIGH); u8_Ret|=DIO_Write(MOTOR_OUT_1B_GPIO,MOTOR_OUT_1B_BIT,LOW); break; } case (MOTOR_BACKWARD): { u8_Ret|=DIO_Write(MOTOR_OUT_1A_GPIO,MOTOR_OUT_1A_BIT,LOW); u8_Ret|=DIO_Write(MOTOR_OUT_1B_GPIO,MOTOR_OUT_1B_BIT,HIGH); break; } default: u8_Ret=E_NOK; break; } } else if (MOTOR_2) //case motor 2 { switch (Motor_Direction) { case (MOTOR_STOP): { u8_Ret|=DIO_Write(MOTOR_OUT_2A_GPIO,MOTOR_OUT_2A_BIT,LOW); u8_Ret|=DIO_Write(MOTOR_OUT_2B_GPIO,MOTOR_OUT_2B_BIT,LOW); break; } case (MOTOR_FORWARD): { u8_Ret|=DIO_Write(MOTOR_OUT_2A_GPIO,MOTOR_OUT_2A_BIT,HIGH); u8_Ret|=DIO_Write(MOTOR_OUT_2B_GPIO,MOTOR_OUT_2B_BIT,LOW); break; } case (MOTOR_BACKWARD): { u8_Ret|=DIO_Write(MOTOR_OUT_2A_GPIO,MOTOR_OUT_2A_BIT,LOW); u8_Ret|=DIO_Write(MOTOR_OUT_2B_GPIO,MOTOR_OUT_2B_BIT,HIGH); break; } default: u8_Ret=E_NOK; break; } } else { u8_Ret=E_NOK; } return u8_Ret; } ERROR_STATUS Motor_Start(uint8_t Motor_Number, uint8_t Mot_Speed) { uint8_t u8_Ret=E_OK; gu8_DutyCycle=Mot_Speed; switch(Motor_Number) { case (MOTOR_1): { u8_Ret|=Pwm_Start(PWM_CH1A,gu8_DutyCycle,T0_FERQ_50); u8_Ret=E_OK; break; } case (MOTOR_2): { u8_Ret|=Pwm_Start(PWM_CH1B,gu8_DutyCycle,T0_FERQ_50); u8_Ret=E_OK; break; } default: u8_Ret=E_NOK; break; } return u8_Ret; } ERROR_STATUS Motor_SpeedUpdate(uint8_t Motor_Number, uint8_t Speed) { uint8_t u8_Ret=E_OK; gu8_DutyCycle=Speed; switch(Motor_Number) { case (MOTOR_1): { u8_Ret|=Pwm_Update(PWM_CH1A,gu8_DutyCycle,T0_FERQ_50); break; } case (MOTOR_2): { u8_Ret|=Pwm_Update(PWM_CH1B,gu8_DutyCycle,T0_FERQ_50); break; } default: u8_Ret=E_NOK; break; } return u8_Ret; } ERROR_STATUS Motor_Stop(uint8_t Motor_Number) { uint8_t u8_Ret=E_OK; if (Motor_Number==MOTOR_1) { u8_Ret|=DIO_Write(MOTOR_OUT_1A_GPIO,MOTOR_OUT_1A_BIT,LOW); u8_Ret|=DIO_Write(MOTOR_OUT_1B_GPIO,MOTOR_OUT_1B_BIT,LOW); u8_Ret|=DIO_Write(MOTOR_EN_1_GPIO,MOTOR_EN_1_BIT,LOW); } else if (Motor_Number==MOTOR_2) { u8_Ret|=DIO_Write(MOTOR_OUT_2A_GPIO,MOTOR_OUT_2A_BIT,LOW); u8_Ret|=DIO_Write(MOTOR_OUT_2B_GPIO,MOTOR_OUT_2B_BIT,LOW); u8_Ret|=DIO_Write(MOTOR_EN_2_GPIO,MOTOR_EN_2_BIT,LOW); } else { u8_Ret=E_NOK; } return u8_Ret; }
449ad779eb42848e2e7f48f40bc835c7191db332
754e2d23d46fb68f38146cb9249fa5c8551eed32
/conversor.h
c60faf488e2c5e8e75d39b49cde502c08d0a7f94
[]
no_license
TiagoSD22/Calculadora
af9dcc9a8b00f08ca82e5d2309b42ac2462989e8
0d06c956d3fab388da9e611258ad8ada6ba9494c
refs/heads/master
2020-03-30T07:05:39.462909
2018-09-30T00:42:03
2018-09-30T00:42:03
150,914,495
0
0
null
null
null
null
UTF-8
C
false
false
166
h
conversor.h
#ifndef CONVERSOR #define CONVERSOR int Logaritmo_Discreto(int numero, int base); int Inverter(int numero); int Fatorial(int numero); #endif // CONVERSOR
859d20e36d9eabeaee573626ddfba0eb713beebb
cf25670178058cdf3e6be9e4b387d3f56a10246c
/03.hybrid_implementation/warray.c
6baef79310a3bdd3a69439d351c3ec963b501ab1
[]
no_license
shubham166/pagerank-clusters
f0db3408a5536450d52bed41d1b255f6fc1c490a
b1ba6fe8e77c3fb6de12773ffce0e9018943ac0f
refs/heads/master
2021-01-25T10:16:41.458948
2014-07-23T10:15:06
2014-07-23T10:15:06
22,140,700
0
0
null
null
null
null
UTF-8
C
false
false
1,632
c
warray.c
#include <malloc.h> #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "warray.h" void warray_init(warray *W, int size) { int i; assert(W!=NULL); W->size = size; W->elements = (int*)malloc(sizeof(int)*size); for(i = 0;i<W->size;i++) W->elements[i]= 0; } /*void warray_init(int *W,int size); { }*/ void warray_Wo_read(warray *Wo, matrix *m) { assert(m!=NULL); assert(Wo!=NULL); int i,j; for(j=0;j<m->size;j++) { for(i = 0;i < m->size;i++) { if(m->elements[i][j] > 0) Wo->elements[j]++; // printf(Wo->elements[j] } } } void warray_Wg_read(warray *Wg, matrix *m,int r,int c) { assert(m!=NULL); assert(Wg!=NULL); int size = 0; int i,j; for(i=0;i<r;i++) for(j=0;j<c;j++) if(m->elements[i][j]==1) size++; Wg->size = size; Wg->elements = (int*)malloc(size*sizeof(int)); int index = 0; for(i = 0;i<r;i++) for(j =0;j<c;j++) if(m->elements[i][j]==1) Wg->elements[index++] = j; } void warray_Wi_read(warray *Wi,matrix *m , int r,int c) { assert(m!=NULL); assert(Wi!=NULL); Wi->size = r+1; Wi->elements = (int*)malloc((r+1)*sizeof(int)); int count=0,i,j; Wi->elements[0] = 0; for(i = 1;i<=r;i++) { for(j = 0;j<c;j++) { if(m->elements[i-1][j] == 1) count++; } Wi->elements[i] = count; } } void rankvec_init(rankvec *r, int size) { r->size = size; r->elements = (float*)malloc(size*sizeof(float)); int i; for(i = 0;i<size;i++) r->elements[i] = 1/(float)size; } void rankvec_copy(rankvec *r1, rankvec *r2) { int size = r1->size; int i; for(i = 0;i<size;i++) r1->elements[i] = r2->elements[i]; }
26078d02bd44606561dd6c5e15ab964bea4fee8f
a72f3b718f3f2f745cc3cd9dc8ef0a97fe296159
/Temp/StagingArea/Data/il2cppOutput/AssemblyU2DUnityScript_CompilerGenerated_U24adapto3781474987MethodDeclarations.h
6741208bdbfe6122123d8c95b485d95d4e622755
[]
no_license
omarojo/Memoria
5da9ba4aa65ce609dc89672fc3f330a6e6ab0bf0
aa7ace81a65a865527d10504dd6a86425601e767
refs/heads/master
2021-01-20T16:17:11.314496
2016-08-10T09:01:58
2016-08-10T09:01:58
65,316,285
0
0
null
null
null
null
UTF-8
C
false
false
1,958
h
AssemblyU2DUnityScript_CompilerGenerated_U24adapto3781474987MethodDeclarations.h
#pragma once #include "il2cpp-config.h" #ifndef _MSC_VER # include <alloca.h> #else # include <malloc.h> #endif #include <stdint.h> #include <assert.h> #include <exception> // CompilerGenerated.$adaptor$__GeneralBasicJS$callable2$70_33__$Action$1 struct U24adaptorU24__GeneralBasicJSU24callable2U2470_33__U24ActionU241_t3781474987; // CompilerGenerated.__GeneralBasicJS$callable2$70_33__ struct __GeneralBasicJSU24callable2U2470_33___t3751671189; // System.Object struct Il2CppObject; // System.Action`1<System.Object> struct Action_1_t271665211; #include "codegen/il2cpp-codegen.h" #include "AssemblyU2DUnityScript_CompilerGenerated___General3751671189.h" #include "mscorlib_System_Object4170816371.h" // System.Void CompilerGenerated.$adaptor$__GeneralBasicJS$callable2$70_33__$Action$1::.ctor(CompilerGenerated.__GeneralBasicJS$callable2$70_33__) extern "C" void U24adaptorU24__GeneralBasicJSU24callable2U2470_33__U24ActionU241__ctor_m452469104 (U24adaptorU24__GeneralBasicJSU24callable2U2470_33__U24ActionU241_t3781474987 * __this, __GeneralBasicJSU24callable2U2470_33___t3751671189 * ___from0, const MethodInfo* method) IL2CPP_METHOD_ATTR; // System.Void CompilerGenerated.$adaptor$__GeneralBasicJS$callable2$70_33__$Action$1::Invoke(System.Object) extern "C" void U24adaptorU24__GeneralBasicJSU24callable2U2470_33__U24ActionU241_Invoke_m267170701 (U24adaptorU24__GeneralBasicJSU24callable2U2470_33__U24ActionU241_t3781474987 * __this, Il2CppObject * ___obj0, const MethodInfo* method) IL2CPP_METHOD_ATTR; // System.Action`1<System.Object> CompilerGenerated.$adaptor$__GeneralBasicJS$callable2$70_33__$Action$1::Adapt(CompilerGenerated.__GeneralBasicJS$callable2$70_33__) extern "C" Action_1_t271665211 * U24adaptorU24__GeneralBasicJSU24callable2U2470_33__U24ActionU241_Adapt_m998554303 (Il2CppObject * __this /* static, unused */, __GeneralBasicJSU24callable2U2470_33___t3751671189 * ___from0, const MethodInfo* method) IL2CPP_METHOD_ATTR;
7e2a569b9cc100e2129794a50ce5e0d127ce2127
e1a4182bea76c9f25ebca53a0f7d91318dd0962d
/walkingpad - HC89S105K8/HC89S105xx_BootLoader/xmodem.h
5a54ee8b73e940e396268aee518a7658faf568f6
[]
no_license
Gul-Hameed007/WP
a7a08a79e02220b69649abb3308fd03031dff412
eb8635a26a958e27ab3195855067990f0ac94ae3
refs/heads/master
2021-09-20T21:20:24.075089
2018-08-15T09:11:39
2018-08-15T09:11:39
null
0
0
null
null
null
null
UTF-8
C
false
false
567
h
xmodem.h
# ifndef XMODEM_H_ # define XMODEM_H_ #define SOH 0x01 #define STX 0x02 #define EOT 0x04 #define ACK 0x06 #define NAK 0x15 #define CAN 0x18 #define CTRLZ 0x1A #define MAXRETRANS 25 #define TICK_PER_SECOND 320000 int _inbyte(char *ch,unsigned short sec); void _outbyte(char c); int _innbyte(char *ch, int n, unsigned short sec); void _outnbyte(char *c, int n); unsigned short crc16_ccitt( const char *buf, int len ); static int check(int crc, const char *buf, int sz); static void flushinput(void); int xmodemReceive(char *dest, unsigned int destsz); #endif
70ed1d51964fd5f8c4adb8e88c20c015768e2fc5
0f5e7c855849f14588168134921632e06a373589
/Pods/AudioKit/macOS/AudioKit.framework/Versions/A/Headers/vocwrapper.h
32beae3562226192df7999bb6df0bf6b9a489be1
[ "MIT" ]
permissive
vanshg/MacAssistant
477a743289a6ff34c8127d14c66ccfef4ca92a2c
a0c3b4fd6d01815159ca286b0bc135b0b55a5104
refs/heads/master
2023-03-07T18:11:18.372398
2023-03-05T23:23:34
2023-03-05T23:23:34
89,634,004
1,763
186
MIT
2020-09-22T18:54:18
2017-04-27T19:40:13
Swift
UTF-8
C
false
false
378
h
vocwrapper.h
typedef struct { SPFLOAT freq; SPFLOAT pos; SPFLOAT diam; SPFLOAT tenseness; SPFLOAT nasal; sp_voc *voc; } sp_vocwrapper; int sp_vocwrapper_create(sp_vocwrapper **p); int sp_vocwrapper_destroy(sp_vocwrapper **p); int sp_vocwrapper_init(sp_data *sp, sp_vocwrapper *p); int sp_vocwrapper_compute(sp_data *sp, sp_vocwrapper *p, SPFLOAT *in, SPFLOAT *out);
9fcb726c5106d1fc4b66cd33230322a1e51d5234
399dec81c5e692f0d79c00391d33f3514868bfa4
/d_blktiger.c
b567bf4df06ecdbfd949792265627b3f5dfee856
[]
no_license
slaminger/fba_saturn
4946c2e3e56c11869f16f4f6752e9d777a0c874c
96506fbd2f8aa39484f0b67894d25c9022a695b8
refs/heads/master
2020-05-04T18:38:16.336575
2019-03-31T20:49:58
2019-03-31T20:49:58
null
0
0
null
null
null
null
UTF-8
C
false
false
49,502
c
d_blktiger.c
// FB Alpha Black Tiger driver module // Based on MAME driver by Paul Leaman #include "d_blktiger.h" #define RAZE0 1 #define nYM2203Clockspeed 3579545 //#define DEBUG_PCM 1 #define PCM_SFX 1 #define PCM_MUSIC 1 /* <vbt1> where and when you update the nbg map <vbt1> in loop, during vblank in , during vblank out ? <vbt1> with dma, etc <CyberWarriorX> vblank in <CyberWarriorX> vblank in is the start of the vblank. vblank out is the end of it */ /* vbt> <Kale_> Ok, have you asked to Arbee? <vbt> <Kale_> The idea is first to write a sound engine to m68k, using a portion of the shared RAM as your i/o registers <vbt> <Kale_> Then banging the individual registers according to what the 2203 expects <vbt> <smf-> I might just emulate the games sound program on the 68000 <vbt> <smf-> I imagine the sh2 would be happier emulating one less z80 <vbt> <smf-> as it running in rom you could probably even do an upfront translation <l_oliveira> you're pressing it or not. releasing the key tells the chip to stop producing the sound <l_oliveira> the CPU will send key off writes to the chips registers making all channels stop producing sound <l_oliveira> on arcade games it's usually 0x0000 or 0xFFFF for stopping <l_oliveira> or 0x00 if it's an 8 bit machine <l_oliveira> some drivers you need to write twice to acknowledge <l_oliveira> some games write 0xFF then 0x00 to mute <l_oliveira> 0xFF is just to change the register to tell the driver to expect a command next time the value changes <l_oliveira> like the CPU keeps pooling the register to see if the value changed and acknowledges only the second change <l_oliveira> some registers actually fire an interrupt when there's a write and in that case the CPU doesn't need to keep polling so making double write is meaningless <l_oliveira> depends on the arcade board design <l_oliveira> I had to deal with that stuff when I modified CAPCOM/Sony Zinc 1 and 2 (PS1 based game boards) sound drivers to run on CPS2, I did create a translator stub code which converts the CPS2 shared RAM command string into the 4 writes on a 8bit port ZN games use to talk with the sound driver <l_oliveira> the ZN sound drivers fire up a NMI every time the host writes to the I/O port and the driver acknowledges that a command is sent after the interrupt is fired four times <l_oliveira> CPS2 Z80 just keeps pooling at an fixed address of the shared ram. I re-purposed the NMI code and put my shared ram pooling stub on the main program loop of the Z80. Every time a command comes at the shared ram it emulates the four NMI behavior in software using the Z80 itself */ //--------------------------------------------------------------------------------------------------------------- int ovlInit(char *szShortName) { struct BurnDriver nBurnDrvBlktiger = { "blktiger", "blktgr", "Black Tiger", blktigerRomInfo, blktigerRomName, DrvInputInfo, DrvDIPInfo, DrvInit, DrvExit, DrvFrame, NULL }; if (strcmp(nBurnDrvBlktiger.szShortName, szShortName) == 0) memcpy(shared,&nBurnDrvBlktiger,sizeof(struct BurnDriver)); ss_reg = (SclNorscl *)SS_REG; ss_regs = (SclSysreg *)SS_REGS; ss_regd = (SclDataset *)SS_REGD; } static void palette_write(INT32 offset) { // UINT8 r,g,b; UINT16 data = (DrvPalRAM[offset]) | (DrvPalRAM[offset | 0x400] << 8); if(offset >=0x300) { // fg offset 300 unsigned short position = remap4to16_lut[offset&0xff]; colBgAddr2[position] = cram_lut[data];//RGB(r>>3, g>>3, b>>3); } else { // bg 0x000-0xff // sprites 0x200-0x2ff unsigned short position = remap16_lut[offset]; DrvPalette[position] = cram_lut[data];//RGB(r>>3, g>>3, b>>3); } } static void DrvRomBankswitch(INT32 bank) { *DrvRomBank = bank & 0x0f; UINT32 nBank = 0x10000 + (bank & 0x0f) * 0x4000; #ifdef RAZE0 z80_map_read (0x8000, 0xbfff, DrvZ80ROM0 + nBank); z80_map_fetch (0x8000, 0xbfff, DrvZ80ROM0 + nBank); #endif } static void DrvVidRamBankswitch(INT32 bank) { *DrvVidBank = (bank & 0x03); UINT32 nBank = (bank & 3) * 0x1000; #ifdef RAZE0 z80_map_read (0xc000, 0xcfff, DrvBgRAM + nBank); z80_map_fetch (0xc000, 0xcfff, DrvBgRAM + nBank); #else CZetMapArea(0xc000, 0xcfff, 0, DrvBgRAM + nBank); // CZetMapArea(0xc000, 0xcfff, 1, DrvBgRAM + nBank); CZetMapArea(0xc000, 0xcfff, 2, DrvBgRAM + nBank); #endif } void __fastcall blacktiger_write(UINT16 address, UINT8 data) { if ((address & 0xf800) == 0xd800) // CZetMapArea(0xd800, 0xdfff, 0, DrvPalRAM); { if(DrvPalRAM[address & 0x7ff] != data) { DrvPalRAM[address & 0x7ff] = data; palette_write(address & 0x3ff); } return; } if (address >= 0xd000 && address <= 0xd3ff) { address &= 0x3ff; if(DrvTxRAM[address] != data) { DrvTxRAM[address] = data; UINT32 attr = DrvTxRAM[address | 0x400]; UINT32 code = data | ((attr & 0xe0) << 3); UINT32 x = fg_map_lut[address]; ss_map[x] = (attr & 0x1f); ss_map[x+1] =code; } return; } if (address >= 0xd400 && address <= 0xd7ff) { address &= 0x7ff; if(DrvTxRAM[address] != data) { DrvTxRAM[address] = data; UINT32 code = DrvTxRAM[address & 0x3ff] | ((data & 0xe0) << 3); UINT32 x = fg_map_lut[(address & 0x3ff)]; ss_map[x] = (data & 0x1f); ss_map[x+1] =code; } return; } // CZetMapArea(0xc000, 0xcfff, 1, DrvBgRAM + nBank); if (address >= 0xc000 && address <= 0xcfff) { UINT32 nBank = (*DrvVidBank) * 0x1000; address = (address & 0xfff) + nBank; if(DrvBgRAM[address]!=data) { DrvBgRAM[address]=data; updateBgTile2Words(/* *DrvScreenLayout,*/ address>>1); } return; } return; } UINT8 __fastcall blacktiger_read(UINT16 address) { return 0; } void __fastcall blacktiger_out(UINT16 port, UINT8 data) { switch (port & 0xff) { case 0x00: { *soundlatch = data; unsigned int i; PcmStatus *st=NULL; if(data!=255) if(sfx_list[data].loop==0 && data!=48) { for(i=0;i<8;i++) { PcmWork *work = *(PcmWork **)pcm14[i]; st = &work->status; st->cnt_loop = 0; // st->audio_process_fp = vbt_pcm_AudioProcess; st->need_ci = PCM_OFF; #ifdef DEBUG_PCM if(i==0) { if(st->play ==PCM_STAT_PLAY_ERR_STOP) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"errstp",40,20+i*10); else if (st->play ==PCM_STAT_PLAY_CREATE) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"create",40,20+i*10); else if (st->play ==PCM_STAT_PLAY_PAUSE) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"pause ",40,20+i*10); else if (st->play ==PCM_STAT_PLAY_START) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"start ",40,20+i*10); else if (st->play ==PCM_STAT_PLAY_HEADER) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"header",40,20+i*10); else if (st->play ==PCM_STAT_PLAY_TIME) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"playin",40,20+i*10); else if (st->play ==PCM_STAT_PLAY_END) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"end ",40,20+i*10); else FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"error ",40,40+i*10); } #endif // if (st->play == PCM_STAT_PLAY_CREATE && i>0) if((st->play == PCM_STAT_PLAY_CREATE || st->play == PCM_STAT_PLAY_END) && i>0) //vbt // if ((st->play == PCM_STAT_PLAY_CREATE || st->play == PCM_STAT_PLAY_END) && i>0) break; } #ifdef DEBUG_PCM1 FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"0",10,20); if(i==1) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"1",10,30); if(i==2) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"2",10,40); if(i==3) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"3",10,50); if(i==4) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"4",10,60); if(i==5) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"5",10,70); if(i==6) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"6",10,80); if(i==7) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"7",10,90); if(i==8) FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"8",10,100); #endif #ifdef PCM_SFX if(sfx_list[data].size!=0) { pcm_info[i].position = 0; pcm_info[i].ring_position = 0; pcm_info[i].track_position = sfx_list[data].position; pcm_info[i].size = sfx_list[data].size*8; pcm_info[i].num = data; PcmInfo info; PCM_INFO_FILE_TYPE(&info) = PCM_FILE_TYPE_NO_HEADER; PCM_INFO_DATA_TYPE(&info)=PCM_DATA_TYPE_RLRLRL;//PCM_DATA_TYPE_LRLRLR; PCM_INFO_CHANNEL(&info) = 0x01; PCM_INFO_SAMPLING_BIT(&info) = 16; PCM_INFO_SAMPLING_RATE(&info) = SOUNDRATE;//30720L;//44100L; PCM_INFO_FILE_SIZE(&info) = pcm_info[i].size; //sfx_list[data].size;//SOUNDRATE*2;//0x4000;//214896; PCM_SetInfo(pcm14[i], &info); st->play = PCM_STAT_PLAY_HEADER; } #endif } else { if( current_pcm != data) { current_pcm = data; PCM_MeStop(pcm14[0]); // pcm_EndProcess(pcm14[0]); PCM_DestroyStmHandle(pcm14[0]); stmClose(stm); UpdateStreamPCM(data, &pcm14[0], &para[0]); } } } return; case 0x01: DrvRomBankswitch(data); return; case 0x03: if (DrvDips[2] & 1) { coin_lockout = ~data << 6; } return; case 0x04: if (data & 0x20) { // CZetClose(); #ifdef SND #ifndef RAZE /* if((*(volatile Uint8 *)0xfffffe11 & 0x80) != 0x80) { SPR_WaitEndSlaveSH(); }*/ CZetOpen(1); CZetReset(); // CZetClose(); #else z80_reset(); #endif #endif // CZetOpen(0); } *flipscreen = data & 0x40; *DrvFgEnable = ~data & 0x80; ss_regs->dispenbl &= 0xfffb; ss_regs->dispenbl |= (*DrvFgEnable >> 5) & 0x0004; BGON = ss_regs->dispenbl; return; case 0x06: watchdog = 0; return; case 0x08: *DrvScrollx = (*DrvScrollx & 0xff00) | data; ss_reg->n1_move_y = (((*DrvScrolly)+16)<<16) ; // ? remettre return; case 0x09: *DrvScrollx = (*DrvScrollx & 0x00ff) | (data << 8); ss_reg->n1_move_y = (((*DrvScrolly)+16)<<16) ; // ? remettre return; case 0x0a: *DrvScrolly = (*DrvScrolly & 0xff00) | data; ss_reg->n1_move_x = (((*DrvScrollx))<<16) ; return; case 0x0b: *DrvScrolly = (*DrvScrolly & 0x00ff) | (data << 8); ss_reg->n1_move_x = (((*DrvScrollx))<<16) ; return; case 0x0c: *DrvBgEnable = ~data & 0x02; *DrvSprEnable = ~data & 0x04; /* ss_regs->dispenbl &= 0xfffD; ss_regs->dispenbl |= (*DrvBgEnable >> 1) & 0x0002; BGON = ss_regs->dispenbl; */ return; case 0x0d: DrvVidRamBankswitch(data); return; case 0x0e: { UINT32 plate_addr[4]; if(data) // 1 = 128x64, 0 = 64x128 { bg_map_lut = &bg_map_lut2x1[0]; PLANEADDR1 = ss_regd->normap[2] = 0x3430; } else { bg_map_lut = &bg_map_lut2x2[0]; PLANEADDR1 = ss_regd->normap[2] = 0x3030; } } return; } } UINT8 __fastcall blacktiger_in(UINT16 port) { switch (port & 0xff) { case 0x00: case 0x01: case 0x02: return DrvInputs[port & 3]; case 0x03: case 0x04: return DrvDips[~port & 1]; case 0x05: return 0x01; case 0x07: #ifdef RAZE0 return z80_get_reg(Z80_REG_DE) >> 8; #endif } return 0; } void __fastcall blacktiger_sound_write(UINT16 address, UINT8 data) { switch (address) { case 0xe000: #ifdef SND BurnYM2203Write(0, 0, data); #endif return; case 0xe001: #ifdef SND BurnYM2203Write(0, 1, data); #endif return; case 0xe002: #ifdef SND BurnYM2203Write(1, 0, data); #endif return; case 0xe003: #ifdef SND BurnYM2203Write(1, 1, data); #endif return; } } UINT8 __fastcall blacktiger_sound_read(UINT16 address) { switch (address) { case 0xc800: return *soundlatch; case 0xe000: #ifdef SND return BurnYM2203Read(0, 0); #else return 0; #endif case 0xe001: #ifdef SND return BurnYM2203Read(0, 1); #else return 0; #endif case 0xe002: #ifdef SND return BurnYM2203Read(1, 0); #else return 0; #endif case 0xe003: #ifdef SND return BurnYM2203Read(1, 1); #else return 0; #endif } return 0; } static INT32 MemIndex() { UINT8 *Next; Next = AllMem; DrvZ80ROM0 = Next; Next += 0x050000; #ifdef SND DrvZ80ROM1 = Next; Next += 0x008000; #endif UINT8 *ss_vram = (UINT8 *)SS_SPRAM; DrvGfxROM0 = SS_CACHE; //Next; Next += 0x020000; // DrvGfxROM1 = SS_CACHE + 0x010000; DrvGfxROM1 = SS_CACHE + 0x08000; DrvGfxROM2 = (UINT8 *)(ss_vram+0x1100); DrvPalette = (UINT16*)colBgAddr; //(UINT32*)Next; Next += 0x0400 * sizeof(UINT32); AllRam = Next; DrvZ80RAM0 = Next; Next += 0x001e00; #ifdef SND DrvZ80RAM1 = Next; Next += 0x000800; #endif DrvPalRAM = Next; Next += 0x000800; DrvTxRAM = Next; Next += 0x000800; DrvBgRAM = Next; Next += 0x004000; DrvSprRAM = Next; Next += 0x000200; DrvSprBuf = Next; Next += 0x000200; DrvScreenLayout = Next; Next += 0x000001; DrvBgEnable = Next; Next += 0x000001; DrvFgEnable = Next; Next += 0x000001; DrvSprEnable = Next; Next += 0x000001; DrvVidBank = Next; Next += 0x000001; DrvRomBank = Next; Next += 0x000001; DrvScrollx = (UINT16*)Next; Next += 0x0001 * sizeof (UINT16); DrvScrolly = (UINT16*)Next; Next += 0x0001 * sizeof (UINT16); soundlatch = Next; Next += 0x000001; flipscreen = Next; Next += 0x000001; // coin_lockout = Next; Next += 0x000001; RamEnd = Next; #ifdef CZET CZ80Context = Next; Next += (0x1080*2); #endif remap16_lut = Next; Next += 768 * sizeof (UINT16); remap4to16_lut = Next; Next += 256 * sizeof (UINT16); cram_lut = Next; Next += 4096 * sizeof (UINT16); fg_map_lut = Next; Next += 0x400 * sizeof (UINT16); bg_map_lut2x1 = Next; Next += 0x2000 * sizeof (UINT16); bg_map_lut2x2 = Next; Next += 0x2000 * sizeof (UINT16); #ifdef SND ym_buffer = (INT16*)Next; Next += 4096 * 4 * 2 * sizeof(INT16); #endif MemEnd = Next; return 0; } //------------------------------------------------------------------------------------------------------------------------------------- static INT32 DrvDoReset(INT32 full_reset) { if (full_reset) { memset (AllRam, 0, RamEnd - AllRam); memset(SOUND_BUFFER,0x00,RING_BUF_SIZE*8); } #ifdef RAZE0 z80_reset(); DrvRomBankswitch(1); DrvVidRamBankswitch(1); #endif #ifdef SND #ifndef RAZE CZetOpen(1); CZetReset(); // CZetClose(); #else z80_reset(); #endif #endif #ifdef SND BurnYM2203Reset(); #endif watchdog = 0; return 0; } static INT32 DrvGfxDecode() { INT32 Plane[4] = { ((0x40000 * 8) / 2) + 4, ((0x40000 * 8) / 2) + 0, 4, 0 }; INT32 XOffs[16] = { 0, 1, 2, 3, 8+0, 8+1, 8+2, 8+3, 16*16+0, 16*16+1, 16*16+2, 16*16+3, 16*16+8+0, 16*16+8+1, 16*16+8+2, 16*16+8+3 }; INT32 YOffs[16] = { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16, 8*16, 9*16, 10*16, 11*16, 12*16, 13*16, 14*16, 15*16 }; UINT8 *tmp = (UINT8*)0x00200000; //malloc(0x40000); // texte memcpyl (tmp, DrvGfxROM0, 0x08000); GfxDecode4Bpp(0x0800, 2, 8, 8, Plane + 2, XOffs, YOffs, 0x080, tmp, DrvGfxROM0); for (int i=0;i<0x10000;i++ ) { if ((DrvGfxROM0[i]& 0x03) ==0x00)DrvGfxROM0[i] = DrvGfxROM0[i] & 0x30 | 0x3; else if ((DrvGfxROM0[i]& 0x03)==0x03) DrvGfxROM0[i] = DrvGfxROM0[i] & 0x30; if ((DrvGfxROM0[i]& 0x30) ==0x00)DrvGfxROM0[i] = 0x30 | DrvGfxROM0[i] & 0x03; else if ((DrvGfxROM0[i]& 0x30)==0x30) DrvGfxROM0[i] = DrvGfxROM0[i] & 0x03; } //bg memcpyl (tmp, DrvGfxROM1, 0x40000); GfxDecode4Bpp(0x0800, 4, 16, 16, Plane + 0, XOffs, YOffs, 0x200, tmp, DrvGfxROM1); // tile16x16toSaturn(0,0x0400, DrvGfxROM1); // tile16x16toSaturn(1,0x0400, DrvGfxROM1+0x20000); tile16x16toSaturn(1,0x0800, DrvGfxROM1); for (int i=0;i<0x40000;i++ ) { if ((DrvGfxROM1[i]& 0x0f) ==0x00)DrvGfxROM1[i] = DrvGfxROM1[i] & 0xf0 | 0xf; else if ((DrvGfxROM1[i]& 0x0f)==0x0f) DrvGfxROM1[i] = DrvGfxROM1[i] & 0xf0; if ((DrvGfxROM1[i]& 0xf0) ==0x00)DrvGfxROM1[i] = 0xf0 | DrvGfxROM1[i] & 0x0f; else if ((DrvGfxROM1[i]& 0xf0)==0xf0) DrvGfxROM1[i] = DrvGfxROM1[i] & 0x0f; } //sprites memcpyl (tmp, DrvGfxROM2, 0x40000); GfxDecode4Bpp(0x0800, 4, 16, 16, Plane + 0, XOffs, YOffs, 0x200, tmp, DrvGfxROM2); for (int i=0;i<0x40000;i++ ) { if ((DrvGfxROM2[i]& 0x0f) ==0x00)DrvGfxROM2[i] = DrvGfxROM2[i] & 0xf0 | 0xf; else if ((DrvGfxROM2[i]& 0x0f)==0x0f) DrvGfxROM2[i] = DrvGfxROM2[i] & 0xf0; if ((DrvGfxROM2[i]& 0xf0) ==0x00)DrvGfxROM2[i] = 0xf0 | DrvGfxROM2[i] & 0x0f; else if ((DrvGfxROM2[i]& 0xf0)==0xf0) DrvGfxROM2[i] = DrvGfxROM2[i] & 0x0f; } return 0; } #ifdef SND static void DrvFMIRQHandler(INT32 irq, INT32 nStatus) { if (nStatus & 1) { CZetSetIRQLine(0xff, CZET_IRQSTATUS_ACK); } else { CZetSetIRQLine(0, CZET_IRQSTATUS_NONE); } } //int aaa = 10; static INT32 DrvSynchroniseStream(INT32 nSoundRate) { return (INT32)CZetTotalCycles() * nSoundRate / nYM2203Clockspeed; } static INT32 DrvGetTime() { // return (INT32)CZetTotalCyclesSlave() / nYM2203Clockspeed; return (INT32)CZetTotalCycles() / nYM2203Clockspeed; } #endif static INT32 DrvInit() { DrvInitSaturn(); AllMem = NULL; MemIndex(); INT32 nLen = MemEnd - (UINT8 *)0; #if 1 if ((AllMem = (UINT8 *)malloc(nLen)) == NULL) { FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)"malloc failed",4,80); return 1; } #endif memset(AllMem, 0, nLen); MemIndex(); make_lut(); { for (INT32 i = 0; i < 5; i++) { if (BurnLoadRom(DrvZ80ROM0 + i * 0x10000, 0 + i, 1)) return 1; } #ifdef SND if (BurnLoadRom(DrvZ80ROM1, 5, 1)) return 1; #endif if (BurnLoadRom(DrvGfxROM0, 6, 1)) return 1; for (INT32 i = 0; i < 4; i++) { if (BurnLoadRom(DrvGfxROM1 + i * 0x10000, 7 + i, 1)) return 1; if (BurnLoadRom(DrvGfxROM2 + i * 0x10000, 11 + i, 1)) return 1; } DrvGfxDecode(); } PCM_MeStop(pcm); int fid = GFS_NameToId((Sint8 *)"SFX.ROM"); long fileSize = GetFileSize(fid); GFS_Load(fid, 0, (UINT8*)0x00200000, fileSize); stmInit(); Set14PCM(); drawWindow(0,224,240,0,64); #ifdef CZET #ifndef RAZE CZetInit2(2,CZ80Context); #else CZetInit2(1,CZ80Context); #endif #endif #ifdef RAZE0 z80_map_read(0x0000, 0x7fff, DrvZ80ROM0); z80_map_fetch(0x0000, 0x7fff, DrvZ80ROM0); z80_map_read(0xd000, 0xd7ff, DrvTxRAM); z80_map_fetch(0xd000, 0xd7ff, DrvTxRAM); z80_map_read(0xd800, 0xdfff, DrvPalRAM); z80_map_fetch(0xd800, 0xdfff, DrvPalRAM); z80_map_read(0xe000, 0xfdff, DrvZ80RAM0); z80_map_write(0xe000, 0xfdff, DrvZ80RAM0); z80_map_fetch(0xe000, 0xfdff, DrvZ80RAM0); z80_map_read(0xfe00, 0xffff, DrvSprRAM); z80_map_write(0xfe00, 0xffff, DrvSprRAM); z80_map_fetch(0xfe00, 0xffff, DrvSprRAM); z80_add_write(0xc000, 0xdfff, 1, (void *)&blacktiger_write); // z80_add_read(0xc000, 0xcfff, 1, (void *)&blacktiger_read); z80_set_in(blacktiger_in); z80_set_out(blacktiger_out); #endif #ifdef CZET #ifndef RAZE CZetOpen(1); CZetMapArea(0x0000, 0x7fff, 0, DrvZ80ROM1); CZetMapArea(0x0000, 0x7fff, 2, DrvZ80ROM1); CZetMapArea(0xc000, 0xc7ff, 0, DrvZ80RAM1); CZetMapArea(0xc000, 0xc7ff, 1, DrvZ80RAM1); CZetMapArea(0xc000, 0xc7ff, 2, DrvZ80RAM1); CZetSetWriteHandler(blacktiger_sound_write); CZetSetReadHandler(blacktiger_sound_read); CZetClose(); #endif #endif #ifdef SND BurnYM2203Init(2, ym_buffer, nYM2203Clockspeed, &DrvFMIRQHandler, DrvSynchroniseStream, DrvGetTime, 0); BurnTimerAttachZet(nYM2203Clockspeed); #endif DrvDoReset(1); for (INT32 i = 0; i < 0x400; i++) { palette_write(i); } return 0; } //------------------------------------------------------------------------------------------------------------------------------------- static INT32 DrvExit() { SPR_InitSlaveSH(); #ifdef RAZE0 z80_stop_emulating(); z80_add_write(0xc000, 0xdfff, 1, (void *)NULL); z80_set_in((unsigned char (*)(unsigned short))NULL); z80_set_out((void (*)(unsigned short, unsigned char))NULL); #endif #ifdef SND BurnYM2203Exit(); #endif #ifdef CZET CZetExit2(); #endif for(unsigned int i=0;i<14;i++) { PCM_MeStop(pcm14[i]); } memset(SOUND_BUFFER,0x00,PCM_BLOCK_SIZE*14); STM_ResetTrBuf(stm); PCM_DestroyStmHandle(pcm14[0]); stmClose(stm); CZ80Context = DrvZ80ROM0 = DrvZ80ROM1 = DrvGfxROM0 = DrvGfxROM1 = DrvGfxROM2 = NULL; DrvZ80RAM0 = DrvZ80RAM1 = DrvPalRAM = DrvTxRAM = DrvBgRAM = DrvSprRAM = DrvSprBuf = NULL; /* DrvScreenLayout =*/ DrvBgEnable = DrvFgEnable = DrvSprEnable = DrvVidBank = DrvRomBank = NULL; DrvPalette = DrvScrollx = DrvScrolly = NULL; soundlatch = flipscreen /*= coin_lockout*/ = NULL; remap16_lut = remap4to16_lut = cram_lut = fg_map_lut = bg_map_lut2x1 = bg_map_lut2x2 = NULL; MemEnd = AllRam = RamEnd = NULL; watchdog = 0; coin_lockout = 0; free (AllMem); AllMem = NULL; nSoundBufferPos=0; return 0; } //------------------------------------------------------------------------------------------------------------------------------------- static INT32 DrvFrame() { // cheat code level //DrvZ80RAM0[0xF3A1-0xe000]=4; // niveau 4 pour transparence // cheat code invincible //DrvZ80RAM0[0xE905-0xe000]= 0x01; //DrvZ80RAM0[0xF424-0xe000]= 0x0F; *(Uint16 *)0x25E00000 = colBgAddr[0]; if (watchdog >= 180) { DrvDoReset(0); } watchdog++; { DrvInputs[0] = DrvInputs[1] = DrvInputs[2] = 0xff; for (INT32 i = 0; i < 8; i++) { DrvInputs[0] ^= (DrvJoy1[i] & 1) << i; DrvInputs[1] ^= (DrvJoy2[i] & 1) << i; DrvInputs[2] ^= (DrvJoy3[i] & 1) << i; } DrvInputs[0] |= coin_lockout; } // UINT32 nInterleave = 100; UINT32 nInterleave = 20; UINT32 nCyclesTotal = 3000000 / 60; ///2; UINT32 nCyclesDone = 0; #ifdef CZET CZetNewFrame(); CZetOpen(1); #endif INT32 nNext, nCyclesSegment; for (UINT32 i = 0; i < nInterleave; i++) { #ifdef RAZE0 nNext = (i + 1) * nCyclesTotal / nInterleave; nCyclesSegment = nNext - nCyclesDone; nCyclesDone += z80_emulate(nCyclesSegment); // if (i == 98) z80_raise_IRQ(0); // if (i == 99) z80_lower_IRQ(); if (i == 18) z80_raise_IRQ(0); if (i == 19) z80_lower_IRQ(); #endif } #ifdef PCM_MUSIC playMusic(&pcm14[0]); #endif #ifdef PCM_SFX for (unsigned int i=1;i<8;i++) { if(pcm_info[i].position<pcm_info[i].size && pcm_info[i].num != 0xff) { int size=PCM_COPY_SIZE; if(pcm_info[i].position+(size*2)>pcm_info[i].size) { // memcpy((INT16 *)(PCM_ADDR+(PCM_BLOCK_SIZE*i))+pcm_info[i].position,(INT16*)(0x00200000+pcm_info[i].track_position),size); memcpy((INT16 *)(PCM_ADDR+(PCM_BLOCK_SIZE*i))+pcm_info[i].ring_position,(INT16*)(0x00200000+pcm_info[i].track_position),size); size=pcm_info[i].size-pcm_info[i].position; pcm_info[i].num = 0xff; } else { // memcpyl((INT16 *)(PCM_ADDR+(PCM_BLOCK_SIZE*i))+pcm_info[i].position,(INT16*)(0x00200000+pcm_info[i].track_position),size); memcpyl((INT16 *)(PCM_ADDR+(PCM_BLOCK_SIZE*i))+pcm_info[i].ring_position,(INT16*)(0x00200000+pcm_info[i].track_position),size); } pcm_info[i].track_position+=size; pcm_info[i].position+=size; pcm_info[i].ring_position+=size; if(pcm_info[i].ring_position>=RING_BUF_SIZE) { pcm_info[i].ring_position=0; } // if(PCM_GetPlayStatus(pcm14[i]) != PCM_STAT_PLAY_CREATE && PCM_GetPlayStatus(pcm14[i]) != PCM_STAT_PLAY_END) { PCM_NotifyWriteSize(pcm14[i], size); PCM_Task(pcm14[i]); // vbt_PCM_MeTask(pcm14[i]); } } else { //#ifdef DEBUG_PCM // FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)" ",100,40+i*10); // FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)itoa(PCM_HN_CNT_LOOP(pcm14[i])),100,40+i*10); //#endif // if(PCM_GetPlayStatus(pcm14[i]) != PCM_STAT_PLAY_CREATE) { //if(i==0) //FNT_Print256_2bpp((volatile unsigned char *)SS_FONT,(unsigned char *)" stopping pcm 0 !!!! ",100,80); PCM_MeStop(pcm14[i]); // memset((INT16 *)(PCM_ADDR+(PCM_BLOCK_SIZE*i)),0x00,RING_BUF_SIZE); } } } #endif draw_sprites(); memcpyl (DrvSprBuf, DrvSprRAM, 0x200); return 0; } //------------------------------------------------------------------------------------------------------------------------------------- static void draw_sprites() { UINT32 delta = 3; for (INT32 offs = 0x200 - 4; offs >= 0; offs -= 4) { UINT32 attr = DrvSprBuf[offs+1]; INT32 sx = DrvSprBuf[offs + 3] - ((attr & 0x10) << 4); INT32 sy = DrvSprBuf[offs + 2]; if (sy < -15 || sy > 239 || sx < -15 || sx > 255) { ss_sprite[delta].charSize = 0; } else { UINT32 code = DrvSprBuf[offs] | ((attr & 0xe0) << 3); UINT32 color = attr & 0x07; UINT32 flipx = (attr & 0x08) << 1; ss_sprite[delta].control = ( JUMP_NEXT | FUNC_NORMALSP) | flipx; ss_sprite[delta].drawMode = ( ECD_DISABLE | COMPO_REP); ss_sprite[delta].ax = sx; ss_sprite[delta].ay = sy; ss_sprite[delta].charSize = 0x210; ss_sprite[delta].color = color<<4;//Colour<<4; ss_sprite[delta].charAddr = 0x220+(code<<4); } delta++; } } //------------------------------------------------------------------------------------------------------------------------------------- static void initLayers() { Uint16 CycleTb[]={ 0xff56, 0xffff, //A0 0xffff, 0xffff, //A1 0x15f2,0x4eff, //B0 0xffff, 0xffff //B1 // 0x4eff, 0x1fff, //B1 }; SclConfig scfg; // 3 nbg // nbg1 16*16 background // ? passer en 1 word ? scfg.dispenbl = ON; scfg.charsize = SCL_CHAR_SIZE_2X2;//OK du 1*1 surtout pas toucher // scfg.pnamesize = SCL_PN1WORD; //2word scfg.pnamesize = SCL_PN2WORD; //2word scfg.platesize = SCL_PL_SIZE_2X2; // ou 2X2 ? scfg.coltype = SCL_COL_TYPE_16;//SCL_COL_TYPE_256; scfg.datatype = SCL_CELL; // scfg.patnamecontrl = 0x0008;// VRAM A0? scfg.patnamecontrl = 0x0008;// VRAM A0? scfg.flip = SCL_PN_10BIT; // on force ? 0 scfg.plate_addr[0] = (Uint32)(SS_MAP2); scfg.plate_addr[1] = (Uint32)(SS_MAP2+0x1000); scfg.plate_addr[2] = (Uint32)(SS_MAP2+0x1000); // good 0x400 scfg.plate_addr[3] = (Uint32)(SS_MAP2+0x1000); SCL_SetConfig(SCL_NBG1, &scfg); // 3 nbg scfg.pnamesize = SCL_PN2WORD; //2word scfg.platesize = SCL_PL_SIZE_1X1; // ou 2X2 ? scfg.charsize = SCL_CHAR_SIZE_1X1; scfg.plate_addr[0] = (Uint32)SS_MAP; scfg.plate_addr[1] = (Uint32)SS_MAP; scfg.plate_addr[2] = (Uint32)SS_MAP; scfg.plate_addr[3] = (Uint32)SS_MAP; // nbg2 8x8 foreground SCL_SetConfig(SCL_NBG2, &scfg); scfg.bmpsize = SCL_BMP_SIZE_512X256; scfg.datatype = SCL_BITMAP; scfg.mapover = SCL_OVER_0; scfg.plate_addr[0] = (Uint32)SS_FONT; scfg.dispenbl = ON; // scfg.dispenbl = OFF; SCL_SetConfig(SCL_NBG0, &scfg); SCL_SetCycleTable(CycleTb); } //------------------------------------------------------------------------------------------------------------------------------------- static void initColors() { memset(SclColRamAlloc256,0,sizeof(SclColRamAlloc256)); colBgAddr = (Uint16*)SCL_AllocColRam(SCL_NBG1,OFF); SCL_AllocColRam(SCL_NBG3,OFF); SCL_AllocColRam(SCL_SPR,OFF); colBgAddr2 = (Uint16*)SCL_AllocColRam(SCL_NBG2,OFF); SCL_AllocColRam(SCL_NBG3,OFF); SCL_AllocColRam(SCL_NBG3,OFF); SCL_SetColRamOffset(SCL_NBG0, 3,OFF); SCL_SetColRam(SCL_NBG0,8,8,palette); // vbt ? remettre } //------------------------------------------------------------------------------------------------------------------------------------- static PcmHn createHandle(PcmCreatePara *para) { PcmHn pcm; pcm = PCM_CreateMemHandle(para); if (pcm == NULL) { return NULL; } return pcm; } //------------------------------------------------------------------------------------------------------------------------------------- static void Set14PCM() { // PcmCreatePara para[14]; PcmInfo info[8]; static PcmWork g_movie_work[8]; PcmStatus *st; for (int i=0; i<8; i++) { PCM_PARA_WORK(&para[i]) = (struct PcmWork *)&g_movie_work[i]; // PCM_PARA_RING_ADDR(&para[i]) = (Sint8 *)PCM_ADDR+0x40000+(0x4000*(i+1)); #if 0 if(i==0) { // PCM_PARA_RING_ADDR(&para[i]) = (Sint8 *)PCM_ADDR+0x64000; PCM_PARA_RING_ADDR(&para[i]) = (Sint8 *)PCM_ADDR+0x40000; PCM_PARA_RING_SIZE(&para[i]) = RING_BUF_SIZE; //0x20000; } else #endif { // PCM_PARA_RING_ADDR(&para[i]) = (Sint8 *)PCM_ADDR+0x40000+(0x4000*(i+1)); // PCM_PARA_RING_ADDR(&para[i]) = (Sint8 *)PCM_ADDR+0x60000+(PCM_BLOCK_SIZE*i); PCM_PARA_RING_ADDR(&para[i]) = (Sint8 *)PCM_ADDR+0x40000+(PCM_BLOCK_SIZE*i); PCM_PARA_RING_SIZE(&para[i]) = RING_BUF_SIZE;//<<1; } // PCM_PARA_PCM_ADDR(&para[i]) = PCM_ADDR+(0x4000*(i+1)); PCM_PARA_PCM_ADDR(&para[i]) = PCM_ADDR+(PCM_BLOCK_SIZE*i); //*(i+1)); PCM_PARA_PCM_SIZE(&para[i]) = PCM_SIZE; memset((Sint8 *)SOUND_BUFFER,0,SOUNDRATE*16); st = &g_movie_work[i].status; st->need_ci = PCM_OFF; // st->audio_process_fp = vbt_pcm_AudioProcess; PCM_INFO_FILE_TYPE(&info[i]) = PCM_FILE_TYPE_NO_HEADER; PCM_INFO_DATA_TYPE(&info[i])=PCM_DATA_TYPE_RLRLRL;//PCM_DATA_TYPE_LRLRLR; PCM_INFO_CHANNEL(&info[i]) = 0x01; PCM_INFO_SAMPLING_BIT(&info[i]) = 16; PCM_INFO_SAMPLING_RATE(&info[i]) = SOUNDRATE;//30720L;//44100L; if(i==0) { // int fid = GFS_NameToId("048.pcm"); // int fz = GetFileSize(fid); PCM_INFO_FILE_SIZE(&info[i]) = sfx_list[0].size;//SOUNDRATE*2;//0x4000;//214896; STM_ResetTrBuf(stm); pcm14[i] = PCM_CreateStmHandle(&para[i], stm); PCM_SetPcmStreamNo(pcm14[i], i); PCM_SetInfo(pcm14[i], &info[i]); // vbt ajout // PCM_SetPcmCmdBlockNo(pcm14[i], i); // *(volatile UINT16*)(0x25A00000 + 0x100000 + 0x20 * i) &= 0xFF9F;//~0x60; PCM_ChangePcmPara(pcm14[i]); } else { PCM_INFO_SAMPLE_FILE(&info[i]) = RING_BUF_SIZE;//SOUNDRATE*2;//30720L;//214896; PCM_INFO_FILE_SIZE(&info[i]) = PCM_COPY_SIZE;//SOUNDRATE*2;//0x4000;//214896; pcm14[i] = createHandle(&para[i]); PCM_SetPcmStreamNo(pcm14[i], i); PCM_SetInfo(pcm14[i], &info[i]); // vbt : ajout // PCM_SetPcmCmdBlockNo(pcm14[i], i); // *(volatile UINT16*)(0x25A00000 + 0x100000 + 0x20 * i) &= 0xFF9F;//~0x60; PCM_ChangePcmPara(pcm14[i]); } // VBT : enleve la lecture en boucle !! merci zeromu!!! PCM_Start(pcm14[i]); } } //------------------------------------------------------------------------------------------------------------------------------------- static void make_lut(void) { unsigned int i,delta=0; for (i = 0; i < 4096;i++) { UINT8 r,g,b; // UINT16 data = (DrvPalRAM[offset]) | (DrvPalRAM[offset | 0x400] << 8); r = (i >> 4) & 0x0f; g = (i >> 0) & 0x0f; b = (i >> 8) & 0x0f; r |= r << 4; g |= g << 4; b |= b << 4; cram_lut[i] = RGB(r>>3, g>>3, b>>3); } for (i = 0; i < 256;i++) { if ((i%4)==0) { remap4to16_lut[i] = delta+3; } else if (((i+1)%4)==0) { remap4to16_lut[i] = delta-3; } else { remap4to16_lut[i] = delta; } delta++; if ((delta & 3) == 0) delta += 12; } for (i = 0; i < 768;i++) { if ((i%16)==0) { remap16_lut[i] = i+15; } else if (((i+1)%16)==0) { remap16_lut[i] = i-15; } else { remap16_lut[i] = i; } } for (i = 0; i < 0x400; i++) { int sy = ((i >> 5) & 0x1f)<<7; int sx = (i & 0x1f)<<1; fg_map_lut[i] = sy | sx; } //------------------------------------------------------------------------------- //#if 1 INT32 sx, sy; // x0-63,y0-15 for (UINT32 offs = 0; offs < 0x100; offs++) // page 8 16x16 { sx = (offs & 0x0f); sy = ((offs) >> 4); // page 0 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x100; offs < 0x200; offs++) // page 8 16x16 { sx = (offs & 0x0f)+16; sy = ((offs-0x100) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x200; offs < 0x300; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x400; sy = ((offs-0x200) >> 4); // page 2 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x300; offs < 0x400; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x400+16; sy = ((offs-0x300) >> 4); // page 3 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } // x0-63,y16-31 for (UINT32 offs = 0x400; offs < 0x500; offs++) // page 8 16x16 { sx = (offs & 0x0f); sy = ((offs-0x300) >> 4); // page 0 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x500; offs < 0x600; offs++) // page 8 16x16 { sx = (offs & 0x0f)+16; sy = ((offs-0x400) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x600; offs < 0x700; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x400; sy = ((offs-0x500) >> 4); // page 2 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x700; offs < 0x800; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x400+16; sy = ((offs-0x600) >> 4); // page 3 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } // x0-63,y32-47 for (UINT32 offs = 0x800; offs < 0x900; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800+0; sy = ((offs-0x800) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x900; offs < 0xA00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800+16; sy = ((offs-0x900) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0xA00; offs < 0xB00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800+0x400; sy = ((offs-0xA00) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0xB00; offs < 0xC00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800+0x400+16; sy = ((offs-0xB00) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } // x0-63,y48-63 for (UINT32 offs = 0xC00; offs < 0xD00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800; sy = ((offs-0xB00) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0xD00; offs < 0xE00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800+16; sy = ((offs-0xC00) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0xE00; offs < 0xF00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800+0x400; sy = ((offs-0xD00) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0xF00; offs < 0x1000; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800+0x400+16; sy = ((offs-0xE00) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } // x64-127-63,y0-15 for (UINT32 offs = 0x1000; offs < 0x1100; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000; sy = ((offs-0x1000) >> 4); // page 0 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1100; offs < 0x1200; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+16; sy = ((offs-0x1100) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1200; offs < 0x1300; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x400; sy = ((offs-0x1200) >> 4); // page 2 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1300; offs < 0x1400; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x400+16; sy = ((offs-0x1300) >> 4); // page 3 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } // x64-127,y16-31 for (UINT32 offs = 0x1400; offs < 0x1500; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000; sy = ((offs-0x1300) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1500; offs < 0x1600; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+16; sy = ((offs-0x1400) >> 4); // page 9 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1600; offs < 0x1700; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x400; sy = ((offs-0x1500) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1700; offs < 0x1800; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x400+16; sy = ((offs-0x1600) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } // x64-127,y32-47 for (UINT32 offs = 0x1800; offs < 0x1900; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800+0; sy = ((offs-0x1800) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1900; offs < 0x1A00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800+16; sy = ((offs-0x1900) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1A00; offs < 0x1B00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800+0x400; sy = ((offs-0x1A00) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1B00; offs < 0x1C00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800+0x400+16; sy = ((offs-0x1B00) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } // x64-127,y48-63 for (UINT32 offs = 0x1C00; offs < 0x1D00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800; sy = ((offs-0x1B00) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1D00; offs < 0x1E00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800+16; sy = ((offs-0x1C00) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1E00; offs < 0x1F00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800+0x400; sy = ((offs-0x1D00) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1F00; offs < 0x2000; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800+0x400+16; sy = ((offs-0x1E00) >> 4); // page 1 16x16 bg_map_lut2x2[offs] = sx|(sy<<5); } //#else // INT32 sx, sy; // x0-63,y0-15 for (UINT32 offs = 0; offs < 0x100; offs++) // page 8 16x16 { sx = (offs & 0x0f); sy = ((offs) >> 4); // page 0 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x100; offs < 0x200; offs++) // page 8 16x16 { sx = (offs & 0x0f)+16; sy = ((offs-0x100) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x200; offs < 0x300; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x400; sy = ((offs-0x200) >> 4); // page 2 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x300; offs < 0x400; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x400+16; sy = ((offs-0x300) >> 4); // page 3 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } //--------------------------------------------------------------------------------- // x0-63,y16-31 for (UINT32 offs = 0x800; offs < 0x900; offs++) // page 8 16x16 { sx = (offs & 0x0f); sy = ((offs-0x700) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x900; offs < 0xA00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+16; sy = ((offs-0x800) >> 4); // page 9 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0xA00; offs < 0xB00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x400; sy = ((offs-0x900) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0xB00; offs < 0xC00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x400+16; sy = ((offs-0xA00) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } //--------------------------------------------------------------------------------- // x0-63,y32-47 for (UINT32 offs = 0x1000; offs < 0x1100; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800+0; sy = ((offs-0x1000) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1100; offs < 0x1200; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800+16; sy = ((offs-0x1100) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1200; offs < 0x1300; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800+0x400; sy = ((offs-0x1200) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1300; offs < 0x1400; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800+0x400+16; sy = ((offs-0x1300) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } //--------------------------------------------------------------------------------- // x0-63,y48-63 for (UINT32 offs = 0x1800; offs < 0x1900; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800; sy = ((offs-0x1700) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1900; offs < 0x1A00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800+16; sy = ((offs-0x1800) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1A00; offs < 0x1B00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800+0x400; sy = ((offs-0x1900) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1B00; offs < 0x1C00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x800+0x400+16; sy = ((offs-0x1A00) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } //--------------------------------------------------------------------------------- // x64-127-63,y0-15 for (UINT32 offs = 0x400; offs < 0x500; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000; sy = ((offs-0x400) >> 4); // page 0 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x500; offs < 0x600; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+16; sy = ((offs-0x500) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x600; offs < 0x700; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x400; sy = ((offs-0x600) >> 4); // page 2 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x700; offs < 0x800; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x400+16; sy = ((offs-0x700) >> 4); // page 3 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } //--------------------------------------------------------------------------------- // x64-127,y16-31 for (UINT32 offs = 0xC00; offs < 0xD00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000; sy = ((offs-0xB00) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0xD00; offs < 0xE00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+16; sy = ((offs-0xC00) >> 4); // page 9 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0xE00; offs < 0xF00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x400; sy = ((offs-0xD00) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0xF00; offs < 0x1000; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x400+16; sy = ((offs-0xE00) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } //--------------------------------------------------------------------------------- // x64-127,y32-47 for (UINT32 offs = 0x1400; offs < 0x1500; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800+0; sy = ((offs-0x1400) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1500; offs < 0x1600; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800+16; sy = ((offs-0x1500) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1600; offs < 0x1700; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800+0x400; sy = ((offs-0x1600) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1700; offs < 0x1800; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800+0x400+16; sy = ((offs-0x1700) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } //--------------------------------------------------------------------------------- // x64-127,y48-63 for (UINT32 offs = 0x1C00; offs < 0x1D00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800; sy = ((offs-0x1B00) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1D00; offs < 0x1E00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800+16; sy = ((offs-0x1C00) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1E00; offs < 0x1F00; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800+0x400; sy = ((offs-0x1D00) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } for (UINT32 offs = 0x1F00; offs < 0x2000; offs++) // page 8 16x16 { sx = (offs & 0x0f)+0x1000+0x800+0x400+16; sy = ((offs-0x1E00) >> 4); // page 1 16x16 bg_map_lut2x1[offs] = sx|(sy<<5); } //--------------------------------------------------------------------------------- //#endif // commenter si 1 word for (UINT32 offs = 0; offs < 0x2000; offs++) // page 8 16x16 { bg_map_lut2x2[offs] = bg_map_lut2x2[offs] * 2; bg_map_lut2x1[offs] = bg_map_lut2x1[offs] * 2; } } //------------------------------------------------------------------------------------------------------------------------------------- void dummy() { } //------------------------------------------------------------------------------------------------------------------------------------- static void DrvInitSaturn() { SPR_InitSlaveSH(); SPR_RunSlaveSH((PARA_RTN*)dummy,NULL); #ifdef DEBUG GFS_SetErrFunc(errGfsFunc, NULL); PCM_SetErrFunc(errPcmFunc, NULL); #endif SS_MAP = ss_map =(Uint16 *)SCL_VDP2_VRAM_B1+0xC000; //c SS_MAP2 = ss_map2 =(Uint16 *)SCL_VDP2_VRAM_B1+0x8000; //8000 // SS_MAP = ss_map =(Uint16 *)SCL_VDP2_VRAM_B1; //c // SS_MAP2 = ss_map2 =(Uint16 *)SCL_VDP2_VRAM_B1+0x8000; //8 SS_FONT = ss_font =(Uint16 *)SCL_VDP2_VRAM_B1+0x0000; //SS_FONT = ss_font =(Uint16 *)NULL; SS_CACHE= cache =(Uint8 *)SCL_VDP2_VRAM_A0; ss_BgPriNum = (SclSpPriNumRegister *)SS_N0PRI; ss_SpPriNum = (SclSpPriNumRegister *)SS_SPPRI; ss_OtherPri = (SclOtherPriRegister *)SS_OTHR; ss_BgColMix = (SclBgColMixRegister *)SS_BGMIX; ss_sprite = (SprSpCmd *)SS_SPRIT; ss_scl = (Fixed32 *)SS_SCL; sfx_list = &sfx_blktiger[0]; nBurnLinescrollSize = 0; nBurnSprites = 128+3; // nBurnFunction = PCM_VblIn;//smpVblIn; //3 nbg SS_SET_N0PRIN(7); // window SS_SET_N1PRIN(4); // bg SS_SET_N2PRIN(6); // fg SS_SET_S0PRIN(4); // sp SS_SET_N1SPRM(1); // 1 for special priority ss_regs->specialcode=0x000e; // sfcode, upper 8bits, function b, lower 8bits function a ss_regs->specialcode_sel=0; // sfsel, bit 0 for nbg0 // 1 sfcs, bit 0 = 1 for funcion code b, 0 for function code a initLayers(); initColors(); initSprites(256-1,224-1,0,0,0,-16); SCL_Open(); // ss_reg->n1_move_y = 16 <<16; ss_reg->n2_move_y = 16;//(0<<16) ; // ss_reg->n2_move_x = 8;//(0<<16) ; SCL_Close(); memset((Uint8 *)SCL_VDP2_VRAM_B1 ,0x22,0x8000); FNT_Print256_2bppSel((volatile Uint8 *)SS_FONT,(Uint8 *)"Loading. Please Wait",24,40); memset((Uint8 *)ss_map2,0x11,0x8000); // memset((Uint8 *)ss_map3,0,0x2000); // memset((Uint8 *)bg_map_dirty,1,0x4000); SprSpCmd *ss_spritePtr; for (unsigned int i = 3; i <nBurnSprites; i++) { ss_spritePtr = &ss_sprite[i]; ss_spritePtr->control = ( JUMP_NEXT | FUNC_NORMALSP); ss_spritePtr->drawMode = ( ECD_DISABLE | COMPO_REP); // 16 couleurs ss_spritePtr->charSize = 0x210; //0x100 16*16 } *(unsigned int*)OPEN_CSH_VAR(nSoundBufferPos) = 0; } //------------------------------------------------------------------------------------------------------------------------------------- static void tile16x16toSaturn (unsigned char reverse, unsigned int num, unsigned char *pDest) { unsigned int c; for (c = 0; c < num; c++) { unsigned char new_tile[128]; UINT8 *dpM = pDest + (c * 128); memcpyl(new_tile,dpM,128); unsigned int i=0,j=0,k=0; for (k=0;k<128;k+=64) { dpM = pDest + ((c * 128)+k); for (i=0;i<32;i+=4,j+=8) { if(reverse) { dpM[i]=new_tile[j]; dpM[i+1]=new_tile[j+1]; dpM[i+2]=new_tile[j+2]; dpM[i+3]=new_tile[j+3]; dpM[i+32]=new_tile[j+4]; dpM[i+33]=new_tile[j+5]; dpM[i+34]=new_tile[j+6]; dpM[i+35]=new_tile[j+7]; } else { dpM[i+32]=new_tile[j]; dpM[i+33]=new_tile[j+1]; dpM[i+34]=new_tile[j+2]; dpM[i+35]=new_tile[j+3]; dpM[i+0]=new_tile[j+4]; dpM[i+1]=new_tile[j+5]; dpM[i+2]=new_tile[j+6]; dpM[i+3]=new_tile[j+7]; } } } } } //------------------------------------------------------------------------------------------------------------------------------------- void updateBgTile2Words(/*INT32 type,*/ UINT32 offs) { UINT32 ofst; UINT32 attr = DrvBgRAM[(offs<<1) + 1]; UINT32 color = (attr >> 3) & 0x0f; UINT32 code = DrvBgRAM[(offs<<1)] + ((attr & 0x07) << 8); // + ((3-DrvVidBank[0])*0x400); UINT32 flipx = attr & 0x80; ofst = bg_map_lut[offs]; // if(color==0) // ss_map2[ofst] = (color | flipx << 7) | 0x3000; //| 0x4000; // | flipx << 7; // vbt remttre le flip ? // else // ss_map2[ofst] = (color | flipx << 7); //| 0x4000; // | flipx << 7; // vbt remttre le flip ? ss_map2[ofst] = (color | flipx << 7); //| 0x4000; // | flipx << 7; // vbt remttre le flip ? ss_map2[ofst+1] = (code<<2)+0x1000; /* 01:51:39<derek> m_bg_tilemap8x4->set_transmask(0, 0xffff, 0x8000); // split type 0 is totally transparent in front half 01:51:40<derek> m_bg_tilemap8x4->set_transmask(1, 0xfff0, 0x800f); // split type 1 has pens 4-15 transparent in front half 01:51:41<derek> m_bg_tilemap8x4->set_transmask(2, 0xff00, 0x80ff); // split type 1 has pens 8-15 transparent in front half 01:51:42<derek> m_bg_tilemap8x4->set_transmask(3, 0xf000, 0x8fff); // split type 1 has pens 12-15 transparent in front half */ } //---------------------------------------------------------------------------------------------------------------
29ae72245f7d592b809eb597287ec34ba8c5f0d2
a1a4f704bef83be72db521c890f064b851c4230b
/examples/pubi.c
d12d8ffbc5a40d37efd4c701de0f0e3911da069f
[ "BSD-3-Clause-Open-MPI" ]
permissive
openpmix/openpmix
ac121b4a7726c2aec7640b7eff3e8c953ff98e7e
f94108d34934d3ba2e015ddc9a6058627470d8c4
refs/heads/master
2023-09-01T11:56:02.630065
2023-08-24T22:51:16
2023-08-24T23:30:57
44,704,948
79
61
NOASSERTION
2023-09-14T20:52:36
2015-10-21T21:14:54
C
UTF-8
C
false
false
7,342
c
pubi.c
/* * Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. * Copyright (c) 2004-2011 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2006-2013 Los Alamos National Security, LLC. * All rights reserved. * Copyright (c) 2009-2012 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2011 Oak Ridge National Labs. All rights reserved. * Copyright (c) 2013-2020 Intel, Inc. All rights reserved. * Copyright (c) 2015 Mellanox Technologies, Inc. All rights reserved. * Copyright (c) 2019 IBM Corporation. All rights reserved. * Copyright (c) 2021 Nanook Consulting. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ * */ #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <unistd.h> #include <pmix.h> #include "examples.h" int main(int argc, char **argv) { pmix_proc_t myproc; int rc; pmix_value_t *val = NULL; pmix_proc_t proc; uint32_t nprocs; pmix_info_t *info; pmix_pdata_t *pdata; size_t n; EXAMPLES_HIDE_UNUSED_PARAMS(argc, argv); /* init us */ if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Init failed: %d\n", myproc.nspace, myproc.rank, rc); exit(0); } fprintf(stderr, "Client ns %s rank %d: Running\n", myproc.nspace, myproc.rank); /* get our universe size */ PMIX_PROC_CONSTRUCT(&proc); PMIX_LOAD_PROCID(&proc, myproc.nspace, PMIX_RANK_WILDCARD); if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_UNIV_SIZE, NULL, 0, &val))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Get universe size failed: %d\n", myproc.nspace, myproc.rank, rc); goto done; } nprocs = val->data.uint32; PMIX_VALUE_RELEASE(val); fprintf(stderr, "Client %s:%d universe size %d\n", myproc.nspace, myproc.rank, nprocs); /* publish something */ if (0 == myproc.rank) { fprintf(stderr, "%s:%d publishing two keys\n", myproc.nspace, myproc.rank); PMIX_INFO_CREATE(info, 2); (void) strncpy(info[0].key, "FOOBAR", PMIX_MAX_KEYLEN); info[0].value.type = PMIX_UINT8; info[0].value.data.uint8 = 1; (void) strncpy(info[1].key, "PANDA", PMIX_MAX_KEYLEN); info[1].value.type = PMIX_SIZE; info[1].value.data.size = 123456; if (PMIX_SUCCESS != (rc = PMIx_Publish(info, 2))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Publish failed: %d\n", myproc.nspace, myproc.rank, rc); goto done; } fprintf(stderr, "%s:%d publish complete\n", myproc.nspace, myproc.rank); PMIX_INFO_FREE(info, 2); } /* lookup something */ if (0 != myproc.rank) { PMIX_PDATA_CREATE(pdata, 2); fprintf(stderr, "%s:%d looking up key FOOBAR\n", myproc.nspace, myproc.rank); (void) strncpy(pdata[0].key, "FOOBAR", PMIX_MAX_KEYLEN); (void) strncpy(pdata[1].key, "PANDA", PMIX_MAX_KEYLEN); PMIX_INFO_CREATE(info, 1); rc = 0; PMIX_INFO_LOAD(&info[0], PMIX_WAIT, &rc, PMIX_INT); if (PMIX_SUCCESS != (rc = PMIx_Lookup(pdata, 2, info, 1))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Lookup failed: %d\n", myproc.nspace, myproc.rank, rc); goto done; } PMIX_INFO_FREE(info, 1); /* check the return for value and source */ for (n = 0; n < 2; n++) { if (0 != strncmp(myproc.nspace, pdata[n].proc.nspace, PMIX_MAX_NSLEN)) { fprintf(stderr, "Client ns %s rank %d: PMIx_Lookup returned wrong nspace: %s\n", myproc.nspace, myproc.rank, pdata[n].proc.nspace); goto done; } if (0 != pdata[n].proc.rank) { fprintf(stderr, "Client ns %s rank %d: PMIx_Lookup returned wrong rank: %d\n", myproc.nspace, myproc.rank, pdata[n].proc.rank); goto done; } } if (PMIX_UINT8 != pdata[0].value.type) { fprintf(stderr, "Client ns %s rank %d: PMIx_Lookup returned wrong type: %d\n", myproc.nspace, myproc.rank, pdata[0].value.type); goto done; } if (1 != pdata[0].value.data.uint8) { fprintf(stderr, "Client ns %s rank %d: PMIx_Lookup returned wrong value: %d\n", myproc.nspace, myproc.rank, (int) pdata[0].value.data.uint8); goto done; } if (PMIX_SIZE != pdata[1].value.type) { fprintf(stderr, "Client ns %s rank %d: PMIx_Lookup returned wrong type: %d\n", myproc.nspace, myproc.rank, pdata[1].value.type); goto done; } if (123456 != pdata[1].value.data.size) { fprintf(stderr, "Client ns %s rank %d: PMIx_Lookup returned wrong value: %d\n", myproc.nspace, myproc.rank, (int) pdata[1].value.data.size); goto done; } PMIX_PDATA_FREE(pdata, 2); fprintf(stderr, "PUBLISH-LOOKUP SUCCEEDED\n"); } /* call fence so rank 0 waits before leaving */ if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Fence failed: %d\n", myproc.nspace, myproc.rank, rc); goto done; } if (0 == myproc.rank) { char **keys; keys = (char **) malloc(3 * sizeof(char *)); keys[0] = "FOOBAR"; keys[1] = "PANDA"; keys[2] = NULL; fprintf(stderr, "%s:%d unpublishing two keys\n", myproc.nspace, myproc.rank); if (PMIX_SUCCESS != (rc = PMIx_Unpublish(keys, NULL, 0))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Unpublish failed: %d\n", myproc.nspace, myproc.rank, rc); free(keys); goto done; } free(keys); fprintf(stderr, "UNPUBLISH SUCCEEDED\n"); } /* call fence again so everyone waits for rank 0 before leaving */ if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Fence failed: %d\n", myproc.nspace, myproc.rank, rc); goto done; } done: /* finalize us */ fprintf(stderr, "Client ns %s rank %d: Finalizing\n", myproc.nspace, myproc.rank); if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) { fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %d\n", myproc.nspace, myproc.rank, rc); } else { fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank); } fflush(stderr); return (0); }
f643e220573480445ffbdd285c65e5ab44960aa3
485d19ae16febdd66e13f775a51abd7186bbebc6
/4_TD/main.c
08367bfde42b56a99c61ba151c21df9a965c24fa
[]
no_license
Bjiornulf/intro_C
bc5bb4e21f6138f3c0b82a3e937a85864a60d6d8
7bf1344f9f0f8099f1bac241c58a70a8c62e0b1b
refs/heads/master
2023-06-08T21:00:09.957208
2021-06-09T07:15:40
2021-06-09T07:15:40
372,836,574
0
0
null
null
null
null
UTF-8
C
false
false
453
c
main.c
#include <stdlib.h> #include "person.h" #include "date.h" #include "list.h" int main() { Date *bdate = create_date(6, 3, 2001); println_date(bdate); Person *todor = create_person("Todor", "Peev", bdate); print_person(todor); List *list = NULL; for (int i = 0; i < 10; i++) { list = push_list(create_date(i, 1, 2021), list); } map_list(&void_println_date, list); free_list(&void_free_date, list); free_person(todor); free_date(bdate); }
60e3280e4e43ea8255bf03e497cabd1d0b0d1c0f
b452bbb87214f174122f425f6f98f4c3890c3cca
/internal/ccall/gvc/gvconfig.c
997fffc4ce2fb9a6950dcab96bf511a7887198a6
[ "MIT" ]
permissive
goccy/go-graphviz
bea9bc86b42734aff7ffae283aeae71702ca588a
865af036ddbb745c4424bbd2fdaa9a75668cf0d4
refs/heads/master
2023-07-20T08:05:39.868377
2023-03-21T23:49:44
2023-03-21T23:49:44
236,740,615
511
66
MIT
2023-07-07T13:53:28
2020-01-28T13:24:09
Go
UTF-8
C
false
false
16,977
c
gvconfig.c
/* $Id$ $Revision$ */ /* vim:set shiftwidth=4 ts=8: */ /************************************************************************* * Copyright (c) 2011 AT&T Intellectual Property * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: See CVS logs. Details at http://www.graphviz.org/ *************************************************************************/ #include "config.h" #include "gvconfig.h" #include <string.h> #ifndef WIN32 #include <regex.h> #endif #ifdef ENABLE_LTDL #include <sys/types.h> #ifdef WIN32 #include <windows.h> #define GLOB_NOSPACE 1 /* Ran out of memory. */ #define GLOB_ABORTED 2 /* Read error. */ #define GLOB_NOMATCH 3 /* No matches found. */ #define GLOB_NOSORT 4 #define DMKEY "Software\\Microsoft" //key to look for library dir typedef struct { int gl_pathc; /* count of total paths so far */ int gl_matchc; /* count of paths matching pattern */ int gl_offs; /* reserved at beginning of gl_pathv */ int gl_flags; /* returned flags */ char **gl_pathv; /* list of paths matching pattern */ } glob_t; static void globfree (glob_t* pglob); static int glob (GVC_t * gvc, char*, int, int (*errfunc)(const char *, int), glob_t*); #else #include <glob.h> #endif #include <sys/stat.h> #ifdef HAVE_UNISTD_H #include <unistd.h> #endif #endif #ifdef __APPLE__ #include <mach-o/dyld.h> #endif #include "memory.h" #include "const.h" #include "types.h" #include "gvplugin.h" #include "gvcjob.h" #include "gvcint.h" #include "gvcproc.h" /* FIXME */ extern Dt_t * textfont_dict_open(GVC_t *gvc); /* A config for gvrender is a text file containing a list of plugin librariess and their capabilities using a tcl-like syntax Lines beginning with '#' are ignored as comments Blank lines are allowed and ignored. plugin_library_path packagename { plugin_api { plugin_type plugin_quality ... } ... ... e.g. /usr/lib/graphviz/libgvplugin_cairo.so cairo {renderer {x 0 png 10 ps -10}} /usr/lib/graphviz/libgvplugin_gd.so gd {renderer {png 0 gif 0 jpg 0}} Internally the config is maintained as lists of plugin_types for each plugin_api. If multiple plugins of the same type are found then the highest quality wins. If equal quality then the last-one-installed wins (thus giving preference to external plugins over internal builtins). */ static gvplugin_package_t * gvplugin_package_record(GVC_t * gvc, char *path, char *name) { gvplugin_package_t *package = gmalloc(sizeof(gvplugin_package_t)); package->path = (path) ? strdup(path) : NULL; package->name = strdup(name); package->next = gvc->packages; gvc->packages = package; return package; } #ifdef ENABLE_LTDL /* separator - consume all non-token characters until next token. This includes: comments: '#' ... '\n' nesting: '{' unnesting: '}' whitespace: ' ','\t','\n' *nest is changed according to nesting/unnesting processed */ static void separator(int *nest, char **tokens) { char c, *s; s = *tokens; while ((c = *s)) { /* #->eol = comment */ if (c == '#') { s++; while ((c = *s)) { s++; if (c == '\n') break; } continue; } if (c == '{') { (*nest)++; s++; continue; } if (c == '}') { (*nest)--; s++; continue; } if (c == ' ' || c == '\n' || c == '\t') { s++; continue; } break; } *tokens = s; } /* token - capture all characters until next separator, then consume separator, return captured token, leave **tokens pointing to next token. */ static char *token(int *nest, char **tokens) { char c, *s, *t; s = t = *tokens; while ((c = *s)) { if (c == '#' || c == ' ' || c == '\t' || c == '\n' || c == '{' || c == '}') break; s++; } *tokens = s; separator(nest, tokens); *s = '\0'; return t; } static int gvconfig_plugin_install_from_config(GVC_t * gvc, char *s) { char *path, *name, *api; const char *type; api_t gv_api; int quality, rc; int nest = 0; gvplugin_package_t *package; separator(&nest, &s); while (*s) { path = token(&nest, &s); if (nest == 0) name = token(&nest, &s); else name = "x"; package = gvplugin_package_record(gvc, path, name); do { api = token(&nest, &s); gv_api = gvplugin_api(api); do { if (nest == 2) { type = token(&nest, &s); if (nest == 2) quality = atoi(token(&nest, &s)); else quality = 0; rc = gvplugin_install (gvc, gv_api, type, quality, package, NULL); if (!rc) { agerr(AGERR, "config error: %s %s %s\n", path, api, type); return 0; } } } while (nest == 2); } while (nest == 1); } return 1; } #endif void gvconfig_plugin_install_from_library(GVC_t * gvc, char *path, gvplugin_library_t *library) { gvplugin_api_t *apis; gvplugin_installed_t *types; gvplugin_package_t *package; int i; package = gvplugin_package_record(gvc, path, library->packagename); for (apis = library->apis; (types = apis->types); apis++) { for (i = 0; types[i].type; i++) { gvplugin_install(gvc, apis->api, types[i].type, types[i].quality, package, &types[i]); } } } static void gvconfig_plugin_install_builtins(GVC_t * gvc) { const lt_symlist_t *s; const char *name; if (gvc->common.builtins == NULL) return; for (s = gvc->common.builtins; (name = s->name); s++) if (name[0] == 'g' && strstr(name, "_LTX_library")) gvconfig_plugin_install_from_library(gvc, NULL, (gvplugin_library_t *)(s->address)); } #ifdef ENABLE_LTDL static void gvconfig_write_library_config(GVC_t *gvc, char *path, gvplugin_library_t *library, FILE *f) { gvplugin_api_t *apis; gvplugin_installed_t *types; int i; fprintf(f, "%s %s {\n", path, library->packagename); for (apis = library->apis; (types = apis->types); apis++) { fprintf(f, "\t%s {\n", gvplugin_api_name(apis->api)); for (i = 0; types[i].type; i++) { /* verify that dependencies are available */ if (! (gvplugin_load(gvc, apis->api, types[i].type))) fprintf(f, "#FAILS"); fprintf(f, "\t\t%s %d\n", types[i].type, types[i].quality); } fputs ("\t}\n", f); } fputs ("}\n", f); } #define BSZ 1024 #define DOTLIBS "/.libs" #define STRLEN(s) (sizeof(s)-1) char * gvconfig_libdir(GVC_t * gvc) { static char line[BSZ]; static char *libdir; static boolean dirShown = 0; char *tmp; if (!libdir) { libdir=getenv("GVBINDIR"); if (!libdir) { #ifdef WIN32 int r; char* s; MEMORY_BASIC_INFORMATION mbi; if (VirtualQuery (&gvconfig_libdir, &mbi, sizeof(mbi)) == 0) { agerr(AGERR,"failed to get handle for executable.\n"); return 0; } r = GetModuleFileName ((HMODULE)mbi.AllocationBase, line, BSZ); if (!r || (r == BSZ)) { agerr(AGERR,"failed to get path for executable.\n"); return 0; } s = strrchr(line,'\\'); if (!s) { agerr(AGERR,"no slash in path %s.\n", line); return 0; } *s = '\0'; libdir = line; #else libdir = "graphviz"; #ifdef __APPLE__ uint32_t i, c = _dyld_image_count(); size_t len, ind; const char* path; for (i = 0; i < c; ++i) { path = _dyld_get_image_name(i); tmp = strstr(path, "/libgvc."); if (tmp) { if (tmp > path) { /* Check for real /lib dir. Don't accept pre-install /.libs */ char* s = tmp-1; /* back up to previous slash (or head of string) */ while ((*s != '/') && (s > path)) s--; if (strncmp (s, DOTLIBS, STRLEN(DOTLIBS)) == 0) continue; } ind = tmp - path; /* byte offset */ len = ind + sizeof("/graphviz"); if (len < BSZ) libdir = line; else libdir = gmalloc(len); bcopy (path, libdir, ind); /* plugins are in "graphviz" subdirectory */ strcpy(libdir+ind, "/graphviz"); break; } } #else FILE* f = fopen ("/proc/self/maps", "r"); char* path; if (f) { while (!feof (f)) { if (!fgets (line, sizeof (line), f)) continue; if (!strstr (line, " r-xp ")) continue; path = strchr (line, '/'); if (!path) continue; tmp = strstr (path, "/libgvc."); if (tmp) { *tmp = 0; /* Check for real /lib dir. Don't accept pre-install /.libs */ if (strcmp(strrchr(path,'/'), "/.libs") == 0) continue; strcpy(line, path); /* use line buffer for result */ strcat(line, "/graphviz"); /* plugins are in "graphviz" subdirectory */ libdir = line; break; } } fclose (f); } #endif #endif } } if (gvc->common.verbose && !dirShown) { fprintf (stderr, "libdir = \"%s\"\n", (libdir ? libdir : "<null>")); dirShown = 1; } return libdir; } #endif #ifdef ENABLE_LTDL static void config_rescan(GVC_t *gvc, char *config_path) { FILE *f = NULL; glob_t globbuf; char *config_glob, *config_re, *path, *libdir; int i, rc, re_status; gvplugin_library_t *library; regex_t re; #ifndef WIN32 char *plugin_glob = "libgvplugin_*"; #endif #if defined(DARWIN_DYLIB) char *plugin_re_beg = "[^0-9]\\."; char *plugin_re_end = "\\.dylib$"; #elif defined(__MINGW32__) char *plugin_glob = "libgvplugin_*"; char *plugin_re_beg = "[^0-9]-"; char *plugin_re_end = "\\.dll$"; #elif defined(__CYGWIN__) plugin_glob = "cyggvplugin_*"; char *plugin_re_beg = "[^0-9]-"; char *plugin_re_end = "\\.dll$"; #elif defined(WIN32) char *plugin_glob = "gvplugin_*"; char *plugin_re_beg = "[^0-9]"; char *plugin_re_end = "\\.dll$"; #elif ((defined(__hpux__) || defined(__hpux)) && !(defined(__ia64))) char *plugin_re_beg = "\\.sl\\."; char *plugin_re_end = "$"; #else /* Everyone else */ char *plugin_re_beg = "\\.so\\."; char *plugin_re_end= "$"; #endif if (config_path) { f = fopen(config_path,"w"); if (!f) { agerr(AGERR,"failed to open %s for write.\n", config_path); exit(1); } fprintf(f, "# This file was generated by \"dot -c\" at time of install.\n\n"); fprintf(f, "# You may temporarily disable a plugin by removing or commenting out\n"); fprintf(f, "# a line in this file, or you can modify its \"quality\" value to affect\n"); fprintf(f, "# default plugin selection.\n\n"); fprintf(f, "# Manual edits to this file **will be lost** on upgrade.\n\n"); } libdir = gvconfig_libdir(gvc); config_re = gmalloc(strlen(plugin_re_beg) + 20 + strlen(plugin_re_end) + 1); #if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) sprintf(config_re,"%s%s", plugin_re_beg, plugin_re_end); #elif defined(GVPLUGIN_VERSION) sprintf(config_re,"%s%d%s", plugin_re_beg, GVPLUGIN_VERSION, plugin_re_end); #else sprintf(config_re,"%s[0-9]+%s", plugin_re_beg, plugin_re_end); #endif if (regcomp(&re, config_re, REG_EXTENDED|REG_NOSUB) != 0) { agerr(AGERR,"cannot compile regular expression %s", config_re); } config_glob = gmalloc(strlen(libdir) + 1 + strlen(plugin_glob) + 1); strcpy(config_glob, libdir); strcat(config_glob, DIRSEP); strcat(config_glob, plugin_glob); /* load all libraries even if can't save config */ #if defined(WIN32) rc = glob(gvc, config_glob, GLOB_NOSORT, NULL, &globbuf); #else rc = glob(config_glob, GLOB_NOSORT, NULL, &globbuf); #endif if (rc == 0) { for (i = 0; i < globbuf.gl_pathc; i++) { re_status = regexec(&re, globbuf.gl_pathv[i], (size_t) 0, NULL, 0); if (re_status == 0) { library = gvplugin_library_load(gvc, globbuf.gl_pathv[i]); if (library) { gvconfig_plugin_install_from_library(gvc, globbuf.gl_pathv[i], library); } } } /* rescan with all libs loaded to check cross dependencies */ for (i = 0; i < globbuf.gl_pathc; i++) { re_status = regexec(&re, globbuf.gl_pathv[i], (size_t) 0, NULL, 0); if (re_status == 0) { library = gvplugin_library_load(gvc, globbuf.gl_pathv[i]); if (library) { path = strrchr(globbuf.gl_pathv[i],DIRSEP[0]); if (path) path++; if (f && path) gvconfig_write_library_config(gvc, path, library, f); } } } } regfree(&re); globfree(&globbuf); free(config_glob); free(config_re); if (f) fclose(f); } #endif /* gvconfig - parse a config file and install the identified plugins */ void gvconfig(GVC_t * gvc, boolean rescan) { #if 0 gvplugin_library_t **libraryp; #endif #ifdef ENABLE_LTDL int sz, rc; struct stat config_st, libdir_st; FILE *f = NULL; char *config_text = NULL; char *libdir; char *config_file_name = GVPLUGIN_CONFIG_FILE; #define MAX_SZ_CONFIG 100000 #endif /* builtins don't require LTDL */ gvconfig_plugin_install_builtins(gvc); gvc->config_found = FALSE; #ifdef __ENABLE_LTDL__ if (gvc->common.demand_loading) { /* see if there are any new plugins */ libdir = gvconfig_libdir(gvc); rc = stat(libdir, &libdir_st); if (rc == -1) { gvtextlayout_select(gvc); /* choose best available textlayout plugin immediately */ /* if we fail to stat it then it probably doesn't exist so just fail silently */ return; } if (! gvc->config_path) { gvc->config_path = gmalloc(strlen(libdir) + 1 + strlen(config_file_name) + 1); strcpy(gvc->config_path, libdir); strcat(gvc->config_path, DIRSEP); strcat(gvc->config_path, config_file_name); } if (rescan) { config_rescan(gvc, gvc->config_path); gvc->config_found = TRUE; gvtextlayout_select(gvc); /* choose best available textlayout plugin immediately */ return; } /* load in the cached plugin library data */ rc = stat(gvc->config_path, &config_st); if (rc == -1) { gvtextlayout_select(gvc); /* choose best available textlayout plugin immediately */ /* silently return without setting gvc->config_found = TRUE */ return; } else if (config_st.st_size > MAX_SZ_CONFIG) { agerr(AGERR,"%s is bigger than I can handle.\n", gvc->config_path); } else { f = fopen(gvc->config_path,"r"); if (!f) { agerr (AGERR,"failed to open %s for read.\n", gvc->config_path); return; } else { config_text = gmalloc(config_st.st_size + 1); sz = fread(config_text, 1, config_st.st_size, f); if (sz == 0) { agerr(AGERR,"%s is zero sized, or other read error.\n", gvc->config_path); free(config_text); } else { gvc->config_found = TRUE; config_text[sz] = '\0'; /* make input into a null terminated string */ rc = gvconfig_plugin_install_from_config(gvc, config_text); /* NB. config_text not freed because we retain char* into it */ } } if (f) { fclose(f); } } } #endif gvtextlayout_select(gvc); /* choose best available textlayout plugin immediately */ textfont_dict_open(gvc); /* initialize font dict */ } #ifdef ENABLE_LTDL #ifdef WIN32 /* Emulating windows glob */ /* glob: * Assumes only GLOB_NOSORT flag given. That is, there is no offset, * and no previous call to glob. */ static int glob (GVC_t* gvc, char* pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob) { char* libdir; WIN32_FIND_DATA wfd; HANDLE h; char** str=0; int arrsize=0; int cnt = 0; pglob->gl_pathc = 0; pglob->gl_pathv = NULL; h = FindFirstFile (pattern, &wfd); if (h == INVALID_HANDLE_VALUE) return GLOB_NOMATCH; libdir = gvconfig_libdir(gvc); do { if (cnt >= arrsize-1) { arrsize += 512; if (str) str = (char**)realloc (str, arrsize*sizeof(char*)); else str = (char**)malloc (arrsize*sizeof(char*)); if (!str) return GLOB_NOSPACE; } str[cnt] = (char*)malloc (strlen(libdir)+1+strlen(wfd.cFileName)+1); if (!str[cnt]) return GLOB_NOSPACE; strcpy(str[cnt],libdir); strcat(str[cnt],DIRSEP); strcat(str[cnt],wfd.cFileName); cnt++; } while (FindNextFile (h, &wfd)); str[cnt] = 0; pglob->gl_pathc = cnt; pglob->gl_pathv = (char**)realloc(str, (cnt+1)*sizeof(char*)); return 0; } static void globfree (glob_t* pglob) { int i; for (i = 0; i < pglob->gl_pathc; i++) free (pglob->gl_pathv[i]); if (pglob->gl_pathv) free (pglob->gl_pathv); } #endif #endif
98ef31b01ebcd3c3423e3f78d06777762db37867
35732ac0df40726a3db8efc8365485482f9787ae
/UNIX/FT_SH1/includes/utils.h
bb5cb6bbd858751b9f39b41bef998a497796963c
[]
no_license
maksru/42
14460fe8e4a1963f30fca8460de364eaafe50617
6a6f7031a3f4bd52948e68c4a4afe11265034cfe
refs/heads/master
2020-03-09T11:49:37.825174
2014-05-21T00:04:11
2014-05-21T00:04:11
null
0
0
null
null
null
null
UTF-8
C
false
false
1,157
h
utils.h
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mfassi-f <mfassi-f@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2013/12/26 14:28:22 by mfassi-f #+# #+# */ /* Updated: 2013/12/27 18:21:37 by mfassi-f ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef UTILS_H # define UTILS_H # include <libft.h> char **find(char **src, char *to_find); int findi(char **src, char *to_find); int len_arr(char **arr); char *ft_strtoupper(char *str); char *ft_strnjoin(char const *s1, char const *s2, size_t len_s2); #endif
e1a520871793d58697591023e09d50ab5dc2189b
03b95147e47162d014a8da3189e74e454add5ffd
/src/exec/system/stm_tpl.h
0849464c5917edf0e12fd19a1aebeaf656669fa2
[]
no_license
zfjsail/nemu
8a546762cba7d66c3f223181dce9125364e8f116
4bd04b8be9a41228ed64afea1663a2a98665635e
refs/heads/master
2021-01-10T01:46:24.530609
2016-03-27T01:24:50
2016-03-27T01:24:50
54,783,296
0
0
null
null
null
null
UTF-8
C
false
false
726
h
stm_tpl.h
#include "exec/helper.h" #include "cpu/modrm.h" #include "cpu/reg.h" #include "exec/template-start.h" make_helper(concat(l_dt_,SUFFIX)) { ModR_M mm; mm.val = instr_fetch(eip+2,1); if(mm.reg == 2) { swaddr_t addr; int len = read_ModR_M(eip + 2,&addr); cpu.gdtr.limit = swaddr_read(addr, 2); addr += 2; cpu.gdtr.base = swaddr_read(addr,4); print_asm("lgdt" str(SUFFIX)" 0x%x",addr - 2); return len + 2; } else if(mm.reg == 3) { swaddr_t addr; int len = read_ModR_M(eip + 2,&addr); cpu.idtr.limit = swaddr_read(addr,2); addr += 2; cpu.idtr.base = swaddr_read(addr,4); print_asm("lidt" str(SUFFIX) " 0x%x",addr - 2); return len + 2; } else //inv return 0; } #include "exec/template-end.h"
50f7d45107ee57355138c5f60c02fb9b4db93822
8098eba23016f5bef6d60e350e999de092c742bf
/nvdimm_stub/nvdimm_stub.c
446408043bc90075c79fd31369e56cb4e91317e6
[]
no_license
urb31075/KernelLubricant
91f8760169d19956b9e6b1e0934f5bf56c4522b9
1d905383d25f42ea90ec6d23694dac74d7fd129a
refs/heads/master
2020-04-01T23:56:02.784968
2018-10-24T09:26:18
2018-10-24T09:26:18
153,780,086
0
0
null
null
null
null
UTF-8
C
false
false
8,911
c
nvdimm_stub.c
#include <linux/module.h> #include <linux/platform_device.h> #include <linux/dma-mapping.h> #include <linux/dmapool.h> #include <linux/device.h> #include <linux/string.h> #include <linux/list.h> #include <linux/mutex.h> #include <linux/slab.h> #include <linux/types.h> //#include <linux/pmem.h> #include "nvdimm_alloc.h" #define DRV KBUILD_MODNAME ": " #ifdef DEBUG #define dbg(fmt, ...) printk(DRV fmt, ##__VA_ARGS__) #else #define dbg(fmt, ...) do { } while(0) #endif static unsigned long nvdimm_usage = 0; #if 0 void nvdimm_recover(void); struct list_head *nvdimm_get_list_head(void); #endif /* --- chunk API start --- */ void *chunk_get_data_addr(chunk_t *chunk) { return (void *) chunk + sizeof(chunk_t); } EXPORT_SYMBOL(chunk_get_data_addr); static size_t chunk_real_size(chunk_t *chunk) { return chunk->size + sizeof(chunk_t); } chunk_t *chunk_find(void *addr) { chunk_t *chunk = NULL; mutex_lock(&chunk_list.mtx); list_for_each_entry(chunk, &chunk_list.list, list) { if ((void *) chunk == (addr - sizeof(chunk_t))) { mutex_unlock(&chunk_list.mtx); return chunk; } } mutex_unlock(&chunk_list.mtx); return NULL; } EXPORT_SYMBOL(chunk_find); static void chunk_add(chunk_t *chunk) { mutex_lock(&chunk_list.mtx); list_add_tail(&chunk->list, &chunk_list.list); if (!chunk->recovered) nvdimm_usage += PAGE_ALIGN(chunk_real_size(chunk)); mutex_unlock(&chunk_list.mtx); } void chunk_delete(chunk_t *chunk) { if (chunk->recovered) { size_t len = chunk_real_size(chunk); dbg("free recovered chunk [%zu] bytes\n", PAGE_ALIGN(chunk->size)); list_del(&chunk->list); memset(chunk, 0, len); kfree((void *) chunk); } else { dbg("free [%zu] bytes at [%llx] address\n", PAGE_ALIGN(chunk->size), chunk->paddr); nvdimm_usage -= PAGE_ALIGN(chunk_real_size(chunk)); list_del(&chunk->list); } } EXPORT_SYMBOL(chunk_delete); void chunk_delete_locked(chunk_t *chunk) { mutex_lock(&chunk_list.mtx); chunk_delete(chunk); mutex_unlock(&chunk_list.mtx); } EXPORT_SYMBOL(chunk_delete_locked); /*static void chunk_delete_all(void) { chunk_t *n, *tmp; mutex_lock(&chunk_list.mtx); list_for_each_entry_safe(n, tmp, &chunk_list.list, list) { nvdimm_free_by_chunk_addr(n, 0); } mutex_unlock(&chunk_list.mtx); }*/ /* --- chunk API end --- */ int nvdimm_dev_probe(struct platform_device *pdev) { int ret = 0; struct resource *mem; struct device *dev = &pdev->dev; mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!mem) { dev_err(dev, "platform_get_resource err\n"); return -EINVAL; } priv->pdev = pdev; priv->res = mem; priv->repaired = 0; //platform_set_drvdata(pdev, priv); ret = baum_dma_declare_coherent_memory(dev, mem->start, mem->start, resource_size(mem), DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE); //debug_urb if (ret != DMA_MEMORY_MAP) { dev_err(dev, "unable to declare DMA memory %d\n", ret); goto err_devm_kzalloc; } if (dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(64))) { ret = -ENODEV; dev_err(dev, "dma_coerce_mask_and_coherent err\n"); goto err_dma; } if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64))) { ret = -ENODEV; dev_err(dev, "dma_set_mask_and_coherent err\n"); goto err_dma; } mutex_init(&chunk_list.mtx); INIT_LIST_HEAD(&chunk_list.list); #if 1 nvdimm_recover(); #if 0 chunk_t *chunk, *tmp; struct list_head *head = nvdimm_get_list_head(); list_for_each_entry_safe(chunk, tmp, head, list) { u32 l = readl(chunk_get_data_addr(chunk)); printk("data %x\n", l); chunk_utilize(chunk); } #endif #endif return 0; err_dma: dma_release_declared_memory(dev); err_devm_kzalloc: return ret; } int nvdimm_dev_remove(struct platform_device *pdev) { //chunk_delete_all(); mutex_destroy(&chunk_list.mtx); dma_release_declared_memory(&pdev->dev); return 0; } void nvdimm_dev_release(struct device *dev) { } u8 nvdimm_recovered(void) { return priv->repaired; } EXPORT_SYMBOL(nvdimm_recovered); void nvdimm_recover(void) { struct device *dev = &priv->pdev->dev; size_t res_len = resource_size(priv->res); void *base = dev->dma_mem->virt_base; phys_addr_t offset; for (offset = 0; offset < res_len; offset += PAGE_SIZE) { if (readl(base + offset) == CHUNK_MAGIC) { chunk_t *chunk = base + offset; chunk_t *new_chunk; new_chunk = kzalloc(chunk_real_size(chunk), GFP_KERNEL); if (!new_chunk) { dbg("could not allocate memory for chunk\n"); continue; } memcpy(new_chunk, chunk, chunk_real_size(chunk)); new_chunk->recovered = 1; chunk_add(new_chunk); // !!! fix it at release memset(chunk, 0, chunk_real_size(chunk)); dbg("recovered data at 0x%llx, size %zu\n", new_chunk->paddr, new_chunk->size); } } priv->repaired = 1; } EXPORT_SYMBOL(nvdimm_recover); void *nvdimm_alloc(size_t size, int flags) { void *addr; dma_addr_t dma_addr; struct device *dev = &priv->pdev->dev; chunk_t *chunk = NULL; addr = dma_alloc_coherent(dev, size + sizeof(chunk_t), &dma_addr, flags); if (addr) { dbg("allocate [%zu] bytes at address [%llx] %llx\n", PAGE_ALIGN(size), dma_addr, addr); memset(addr, 0, size + sizeof(chunk_t)); } else { dbg("could not allocate buffer\n"); return NULL; } chunk = addr; chunk->magic = CHUNK_MAGIC; chunk->paddr = dma_addr; chunk->size = size; chunk->recovered = 0; chunk_add(chunk); return addr + sizeof(chunk_t); } EXPORT_SYMBOL(nvdimm_alloc); void nvdimm_free_by_chunk_addr(chunk_t *chunk, bool locked) { struct device *dev = &priv->pdev->dev; size_t len; dma_addr_t paddr; if (!chunk) return; len = chunk_real_size(chunk); paddr = chunk->paddr; if (locked) chunk_delete_locked(chunk); else chunk_delete(chunk); memset(chunk, 0, len); dma_free_coherent(dev, len, (void *) chunk, paddr); } EXPORT_SYMBOL(nvdimm_free_by_chunk_addr); void nvdimm_free_by_data_addr(void *addr, bool locked) { chunk_t *chunk = NULL; chunk = chunk_find(addr); if (!chunk) { dbg("!! could not find appropriate address [%llx] in chunk_list\n", addr); return; } nvdimm_free_by_chunk_addr(chunk, locked); } EXPORT_SYMBOL(nvdimm_free_by_data_addr); // get percentage of available space unsigned short nvdimm_percentage(void) { return (100 * (resource_size(priv->res) - nvdimm_usage)) / resource_size(priv->res); } EXPORT_SYMBOL(nvdimm_percentage); struct list_head *nvdimm_get_list_head(void) { return &chunk_list.list; } EXPORT_SYMBOL(nvdimm_get_list_head); void nvdimm_list_mutex_lock(void) { mutex_lock(&chunk_list.mtx); } EXPORT_SYMBOL(nvdimm_list_mutex_lock); void nvdimm_list_mutex_unlock(void) { mutex_unlock(&chunk_list.mtx); } EXPORT_SYMBOL(nvdimm_list_mutex_unlock); static int __init nvdimm_drv_init(void) { printk(KERN_INFO "NVDIMM STUB INIT\n"); return 0; //debug_urb /* int ret; ret = platform_driver_register(&nvdimm_drv); if (ret) { printk("platform_driver_register ret %d\n", ret); goto err_driver_register; } ret = platform_device_register(&nvdimm_dev); if (ret) { printk("platform_device_register ret %d\n", ret); platform_driver_unregister(&nvdimm_drv); goto err_driver_register; } printk(DRV "loaded\n"); return 0; err_driver_register: return ret;*/ } static void __exit nvdimm_drv_exit(void) { platform_device_unregister(&nvdimm_dev); platform_driver_unregister(&nvdimm_drv); printk(DRV "unloaded\n"); } module_init(nvdimm_drv_init); module_exit(nvdimm_drv_exit); MODULE_AUTHOR("Sergey Katyshev <s.katyshev@npobaum.ru, perplexus@ya.ru>"); MODULE_LICENSE("Dual BSD/GPL"); MODULE_DESCRIPTION("This module provides API to allocate memory at NVDIMM memory");
ad604355cace573817a01a96c9b0b955fb2563dc
219b926bf85af1b732dac779182683a3fa016505
/1.23.c
72c6eaa3775478f5a5c0fd01a58f77aaa9517f06
[]
no_license
r78/kir
61a33525f41bd2cf638cbfd9d19f49ac398626c3
62ca647a2720aa264d61803bac46d40fa1b994cd
refs/heads/master
2021-01-15T15:37:27.596395
2016-12-04T11:34:50
2016-12-04T11:34:50
54,801,178
0
0
null
null
null
null
UTF-8
C
false
false
1,805
c
1.23.c
#include <stdio.h> #define MAXLINE 1000 /* maximum input line length */ #define TRUE 0 #define FALSE 1 int get_line(char line[], int maxline); void uncomment(char s[], int len); int in_cmt, cmt_end, in_quote, quote_chr; /* removes all coments from a c program don't forget to handle quoted strings and characters properly c comments do not nest */ int main() { int len; char line[MAXLINE]; extern int in_cmt, cmt_end; in_cmt = FALSE; in_quote = FALSE; cmt_end = -1; while ((len = get_line(line, MAXLINE)) > 0) { uncomment(line, len); } return 0; } void uncomment(char s[], int len) { int i; char c; int cmt_start = -1; extern int in_cmt, cmt_end, in_quote, quote_chr; for (i = 0; (c = s[i]) != '\0'; i++) { //check if we are inside quoted text if (in_quote == FALSE) { if (c == '"' || c == '\'') { printf("%c", c); quote_chr = c; in_quote = TRUE; } if (in_quote == FALSE) { if (in_cmt == FALSE) { if (c == '/' && s[i+1] == '*') { cmt_start = i; i++; in_cmt = TRUE; } if (in_cmt == FALSE) printf("%c", c); } else { if (c == '*' && s[i+1] == '/') { i++; in_cmt = FALSE; } else { if (cmt_start > -1 && c == '\n') printf("\n"); } } } } else { printf("%c", c); if (c == quote_chr) { in_quote = FALSE; quote_chr = '\0'; } } } } /* get_line: read a line into s, return length */ int get_line(char s[], int lim) { int c, i; for (i=0; i < lim-1 && (c=getchar())!=EOF && (c!='\n'); ++i) { s[i] = c; } if (c == '\n') { s[i] = c; ++i; } s[i] = '\0'; return i; }
da3c7f9f9c9d99378b1a8356d886fe57ea20a538
5468c049676a97691e20dfdfb38659e9c9cf17ba
/panther_sdk/openwrt/package/legacy/iot/src/alert/alert_api.h
b63a7d99e16f01bc44431bfcf528d9be53d557f5
[]
no_license
mehome/my_demo
eb305f2a51199981b712a46cafe25ba8474b8c34
0dfb59557befcece5ac2707acab2b7b1a3fa46a7
refs/heads/master
2020-05-30T04:20:05.253204
2019-03-15T06:58:13
2019-03-15T06:58:13
null
0
0
null
null
null
null
UTF-8
C
false
false
234
h
alert_api.h
#ifndef __ALERT_APT_H__ #define __ALERT_APT_H__ #include <stdlib.h> #include "AlertManager.h" #define ALERTS_DIRECTIVES_SETALERT "SetAlert" #define ALERTS_DIRECTIVES_DELETEALERT "DeleteAlert" #endif
21fdd1cfb9142f225c576729246f1999129415b4
1b882e301b3503af4c69ebf3ea5a75be843063c0
/libft/lib-funcs/ft_putendl.c
9cf05a67139bd63c1bd3465af9082a2e85db5199
[]
no_license
BFlorian91/fillit
87def2866c89d70f847b54aa877be47eaa0beace
f23ecb3f18b2142b24c4140476108391265e7d25
refs/heads/master
2020-04-15T22:09:36.031401
2019-01-19T14:21:17
2019-01-19T14:21:17
165,061,881
0
1
null
2019-01-13T14:37:30
2019-01-10T13:09:07
C
UTF-8
C
false
false
1,005
c
ft_putendl.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putendl.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: flbeaumo <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/11/13 11:58:35 by flbeaumo #+# #+# */ /* Updated: 2018/11/17 14:10:51 by flbeaumo ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" void ft_putendl(char const *s) { if (s != NULL) { ft_putstr(s); ft_putchar('\n'); } }
1b25ead41deaa52937032073e9729c37ea7bb1c4
d51d53248412a66807f548543c2a8dd5b49cc318
/main_inverter.c
34da42fcd0de23f4cbc39e995e287d14cdba2a45
[]
no_license
oreo22/thesis
a8c8af60dfb100994780753e3ea1429556de1505
60fe402203e4a56c750591cd1b43e7bb317cad64
refs/heads/master
2021-05-02T07:20:51.454839
2018-02-24T21:37:03
2018-02-24T21:37:03
120,826,879
0
0
null
null
null
null
UTF-8
C
false
false
2,510
c
main_inverter.c
#include <stdint.h> #include "PLL.h" #include "PWM.h" #include "tm4c123gh6pm.h" #include "utilities.h" #include "ADC.h" #include "SysTickInts.h" #include "Measurements.h" #include "VoltageConverter.h" //#include "SPI.h" //extern uint8_t ADCflag; //extern uint32_t ADCvalue[100]; uint8_t condition=0; //Master Controller Command uint8_t shutDown=0; /*DC ADC: PE5, PE4, PE1, PE0 AC ADC: PE3, PE2 MOSFET Switches (PWM): PB5 for top switch, PB6 for bottom switch INVERTER CTRLS (Output GPIO): PD2 (+Vcont), PD3 (-Vcont) for inverter LIGHTS: PF2 AND PF3 */ void Init(void){ DisableInterrupts(); PLL_Init(); // bus clock at 80 MHz SYSCTL_RCGCGPIO_R |= 0x00000020; // activate port F GPIO_Init(); PWM0B2_Init(2000, 500); //25% duty cycle, change second number to % of first PWM0A_Init(2000, 500); //1st number is frequency and 2nd # is duty cycle ADC_Init_DC(13333); //800 1 kHz sampling, PE5, PE4, PE1, PE0 bus_freq/desired_freq EnableInterrupts(); condition =2; } double invOutput=0; float dcVin=0; void chargeBat(void){ DisableInterrupts(); NVIC_ST_CTRL_R = 0; // disable SysTick NVIC_ST_RELOAD_R = 0;// disarm the systick by setting reload value to 0 //check if systick is still interrupting... GPIO_PORTD_DATA_R |=0x00; //PD2 off, PD3 off EnableInterrupts(); while(condition==1){ invOutput=calculateV(); buckMode(invOutput); //tell the converter about the new voltage } } void dischargeBat(void){ DisableInterrupts(); SysTick_Init(1067); // initialize SysTick timer, sawtooth has 25 pts, so to get a 30kHz signal, you have to interrupt 30kHz *25 EnableInterrupts(); while(condition==2){ invOutput=calculateV(); //voltage level it should boost to dcVin=12; //the input to the boost // boostMode(invOutput,dcVin); } } void neutral(void){ //turn off everything except SPI to get readings DisableInterrupts(); NVIC_ST_CTRL_R = 0; // disable SysTick NVIC_ST_RELOAD_R = 0;// disarm the systick by setting reload value to 0 //check if systick is still interrupting... GPIO_PORTD_DATA_R =0x00; //PD2 off, PD3 off GPIO_PORTB_DATA_R =0x00; EnableInterrupts(); } volatile uint32_t Counts = 0; int main(void){ Init(); // heartbeat(); while(shutDown != 1){ if (condition==1){ chargeBat(); } if (condition==2){ dischargeBat(); } if (condition==0){ neutral(); } else{ WaitForInterrupt(); } } } // Interrupt service routine // Executed every 12.5ns*(period)
f22872c2ba40b2befe5416103dd3b52fb7d970f1
483a250c7c8550e14139ab8bf9a06b17f5e4c19a
/time.c
681fe1317947061b76589d36f13ceb7fd4a02470
[ "MIT" ]
permissive
Mobink980/C-and-C-plus-plus-Development
98c058d1aa0f8095a2df733348c3d1f55ec035b6
ecb86f31c608b1c69a0c3332dfabcb7abb7b7b96
refs/heads/master
2022-05-12T21:22:51.655116
2022-05-12T17:54:39
2022-05-12T17:54:39
236,071,512
1
0
null
null
null
null
UTF-8
C
false
false
489
c
time.c
#include <stdio.h> #include <conio.h> #include <time.h> int main() { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYSTEM TIME //printing the time of the system struct tm *local, *gm; time_t t; t = time(NULL); local = localtime(&t); printf("Local time and date: %s\n", asctime(local)); gm = gmtime(&t); printf("Coordinated Universal Time and date is : %s", asctime(gm)); getch(); //For keeping the command line open return 0; }
75a1821c34765da9a125e13eb71e4713e3bcb869
86e4bd9ba50107ef338fe96b84d4cf15b97a1e8d
/Tutorial & book study/Function power.c
061bdeaf1e1992b97089ad444b64c1306e3411cc
[]
no_license
RedwanSharafatKabir/C-programming-language
e939ee860bb4e7fd8b895f6cda429698d7335e50
829aa14c3b52c1e6b4f8e3773a73d8000ed79391
refs/heads/master
2020-03-12T00:28:27.849444
2019-11-03T19:34:41
2019-11-03T19:34:41
130,349,941
1
0
null
null
null
null
UTF-8
C
false
false
194
c
Function power.c
#include<stdio.h> int name(int a, int b) { int n; n=pow(a,b); return n; } int main() { int m,x,y; scanf("%d%d",&x,&y); m=name(x,y); printf("%d\n",m); return 0; }
03a51aa84cb5ba22cea66c4c79ecf57a7a2ae1cd
4c3202bdbfcb89712a6837fbaa937ffb89922fe1
/src/swreset.h
d9bd21265ec1628bda10b2479a31f4a54933be2d
[]
no_license
takunoko/Letro
aae90ccb6c7b5101d57f89cc116e1fd83a45e9f5
24528528fdd4315c01110f3e28effe7f3f896d7a
refs/heads/master
2020-12-24T19:13:52.947377
2012-11-01T08:15:54
2012-11-01T08:15:54
null
0
0
null
null
null
null
UTF-8
C
false
false
452
h
swreset.h
/* * swreset.h * * Created: 2012/09/05 16:23:16 * Author: makoto */ //特にいじらないでください #ifndef SWRESET_H_ #define SWRESET_H_ #ifndef _BUILD_ #include <avr/iom1284p.h> #endif #define SW_RESET_BTN PORTB4 #define SW_RESET_PIN PINB #define SW_RESET_PORT PORTB #define SW_RESET_DDR DDRB void sw_reset_init(void); void sw_reset_enable(void); void sw_reset_disable(void); void sw_reset_menu(void); #endif /* SWRESET_H_ */
a064f60afaf431b9e50e238787dfca82a3024c52
1563f68327c606a36780492f5a7cae9b16959ab7
/src/GAME.h
cbd8c3a47bfccecb3e21fa8acea764c9a168e07f
[]
no_license
thanapat722/NightmareHalloween-Game
697a20ffecf4606eec25196e84519842170ee5b0
b5511731d6b72d9266d6c6726b2e32f2cbbf1f8c
refs/heads/master
2023-02-22T18:02:43.198393
2021-01-21T13:39:19
2021-01-21T13:39:19
308,598,509
1
0
null
null
null
null
UTF-8
C
false
false
1,746
h
GAME.h
#pragma once int main() { //Variables float darkraiMoveSpeed = 0.3; float enemyMoveSpeed = 0.3; sf::RenderWindow window(sf::VideoMode(800, 800), "Test!", sf::Style::Close | sf::Style::Resize); sf::View view(sf::Vector2f(0.0f, 0.0f), sf::Vector2f(VIEW_HEIGHT, VIEW_HEIGHT)); sf::RectangleShape bg, darkrai; sf::Texture bgTexture, darkraiTexture; window.setSize(sf::Vector2u(1000, 800)); // Map bgTexture.loadFromFile("photo/pvz/nightyard.jpg"); bg.setSize(sf::Vector2f(1400.0f, 600.0f)); bg.setPosition(0.0f, 0.0f); bg.setTexture(&bgTexture); // Player Sprite sf::Texture playerTexture; playerTexture.loadFromFile("photo/mobs/kenf.png"); //player.setOrigin(player.getSize() / 2.0f); Player player(&playerTexture, sf::Vector2u(12, 12), 0.16f, 180.0f); Platform platform1(nullptr, sf::Vector2f(400.0f, 200.0f), sf::Vector2f(500.0f, 500.0f)); Platform platform2(nullptr, sf::Vector2f(400.0f, 200.0f), sf::Vector2f(500.0f, 0.0f)); float deltaTime = 0.0f; sf::Clock clock; while (window.isOpen()) { deltaTime = clock.restart().asSeconds(); sf::Event event; while (window.pollEvent(event)) { switch (event.type) { case sf::Event::Closed: window.close(); break; case sf::Event::Resized: ResizeView(window, view); break; } } player.Update(deltaTime); platform1.GetCollider().CheckCollision(player.GetCollider(), 0.0f); platform2.GetCollider().CheckCollision(player.GetCollider(), 0.0f); view.setCenter(player.GetPosition()); window.clear(); window.setView(view); window.draw(bg); player.Draw(window); platform1.Draw(window); platform2.Draw(window); window.display(); } return 0; }
ce78df6b6b4bc2819eac215320a88eeee4705220
3d13ffe64f084a7a31841b0c6f5c513818177267
/libft/srcs/list/ft_lstsize.c
a0054d6775ef110e12dc4c3ec07646b34599c01b
[ "MIT" ]
permissive
besellem/so_long
b0e4717ec5cf697ae8157fbbaaa724409f41934a
ff99cf21ce330a1d287c60b7328c22f4837b2ed9
refs/heads/master
2023-06-09T16:01:36.964546
2021-07-04T12:44:40
2021-07-04T12:44:40
382,421,712
1
0
null
null
null
null
UTF-8
C
false
false
1,048
c
ft_lstsize.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_lstsize.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: besellem <besellem@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/09/13 23:17:12 by besellem #+# #+# */ /* Updated: 2021/04/19 13:30:41 by besellem ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" int ft_lstsize(t_list *lst) { t_list *tmp; int i; tmp = lst; i = 0; while (tmp) { tmp = tmp->next; ++i; } return (i); }
07a0b88d32aca19d73dd4c9a0bb19c097d000ccc
ecbc39e69acf9b6403e69f68d9299a5ef6f96c10
/integral/integral.c
8f8c8181b6a9d4b3b71d59d08d241895fc1cc367
[]
no_license
flowreaction/integral.c
3a7f01ab0f220eae34213b2c4314c282260bde69
bec99aa8f799e996ec82c15a81e7afa507307656
refs/heads/master
2021-08-31T02:16:59.253973
2017-12-20T06:45:13
2017-12-20T06:45:13
113,227,891
0
0
null
null
null
null
ISO-8859-1
C
false
false
3,141
c
integral.c
/* Aufgabe 5.2 integral.c Autor Florian Bopp Datum 6.12.17 Kurzbeschreibung: Diese Programm berechnet ein Integral einer beliebigen Funktion auf 2 verschiedene varianten. In aufgabe (a) wird ein beispielrechteck berechnet. In Aufgabe (b) wird wird über eine Funktion ein Integral berechnet und in aufgabe (c) wird dies wiederholt über eie andere Funktion welche die Trapezformel für integrale beinhaltet. */ #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> //functions void flashStandardInput(void){ int intCharacter; while ((intCharacter = getchar()) != '\n' && intCharacter != EOF); } //Irgendeine Mathematische funktion von welcher ein Integral berechnet werden soll double f(double x) { return 4 - x*x; } //Aufgabe (a) double flaeche(double von, double bis) { return f((von + bis) / 2) * (bis - von); //berechnung eines rechtecks (funktionswert(höhe) * breite) } //Aufgabe (b) double integral(double von, double bis, int anzahl) { double ergebnis = 0; double teilvon = von; //variable welche sich im forloop weiterschiebt double teilbis = (bis - von)/anzahl; //variable welche sic im foorloop weiterschiebt int i; for ( i = 1; i <= anzahl; i++) { //For loop für die menge der teilintervalle ergebnis = ergebnis + flaeche(teilvon, teilbis * i + von); //die Funktion fläche wird aufgerufen und angepasst an die teilintervalle ausgeführt teilvon = teilbis * i + von; //teilvon wird der aktuelle wert von teilbis zugeordnet } return ergebnis; } //Aufgabe (c) trapez reihe zur berechnung von integralen double integral_trapez(double von, double bis, int n) { double ergebnis = 0; double h = (bis - von) / n; int i; for (i = 1; i <= n-1; i++) { //For schleife zum errechnen der Folge ergebnis = ergebnis + f(von + i*h); } ergebnis = (ergebnis*2 + f(von) + f(bis))*(h / 2); //Das Ergebnis der Folge wird mit dem Rest der Trapez Formel verrechnet return ergebnis; } // Main function int main(void) { double von, bis; int teilintervalle; char janein; do { //Do-While schleife in welcher die Integrale berechnet werden. printf("Bitte Integralsgrenzen eigeben.\nVon: "); scanf("%lf", &von); flashStandardInput(); printf("\nBis: "); scanf("%lf", &bis); flashStandardInput(); printf("\n\nBitte die Anzahl der Teilintervalle angeben: "); scanf("%d", &teilintervalle); flashStandardInput(); printf("\n\n\n"); printf("Fl%cche von einem rechteck des Intervalles ist %f\n\n\n", 132, flaeche(von, bis)); //Aufgabe a wird abgerufen printf("Fl%cche der funktion integral = %f\n\n", 132, integral(von, bis, teilintervalle)); //Aufgabe b wird abgerufen printf("Fl%cche der funktion integral_trapez = %f\n\n", 132, integral_trapez(von, bis, teilintervalle)); //Aufgabe c wird abgerufen do{ printf("\n\n\n\nNoch ein Integral berechnen?\ny/n:"); scanf("%c", &janein); flashStandardInput(); } while (janein != 'y' && janein != 'n'); //abfrage ob nochmal ein integral berechnet werden soll printf("\n\n"); } while (janein == 'y'); return 0; }
ad1cb03bc73c140e9906c5cc0c33ed1fa9a84400
a48c5c7b68ef4bff85da1f8ebf4a4a8738d511e5
/lab12/readFiles.c
4c8e6d7bbe3732a3dac98bedf2907a1f33674ff0
[ "MIT" ]
permissive
mihaimusat/APD-labs-2019
0f1b90f305bf5e512556a7431441e15dbfc77054
ba401a510a1ce3009ca8a5864d99bbcd5019fcb3
refs/heads/master
2021-01-01T14:26:57.339234
2020-02-11T12:33:09
2020-02-11T12:33:09
239,319,645
0
1
null
null
null
null
UTF-8
C
false
false
2,597
c
readFiles.c
#include <string.h> #include <stdio.h> #include <stdlib.h> #include <pthread.h> /** * @author cristian.chilipirea * * Create files using * dd if=/dev/urandom of=1.txt bs=1024 count=104800 * dd if=/dev/urandom of=2.txt bs=1024 count=104800 */ int N; int P; int NReps; char* buff1; char* buff2; int* threadIds; pthread_t* threads; void getArgs(int argc, char** argv) { if (argc < 4) { printf("Not enough paramters: ./program N NReps P\n"); exit(1); } N = atoi(argv[1]); NReps = atoi(argv[2]); P = atoi(argv[3]); } void finalise() { if (buff1 != NULL) { free(buff1); } if (buff2 != NULL) { free(buff2); } if (threads != NULL) { free(threads); } if (threadIds != NULL) { free(threadIds); } } void init() { int i; buff1 = malloc(N * sizeof(*buff1)); if (buff1 == NULL) { printf("Malloc failed for the buffer."); exit(1); } buff2 = malloc(N * sizeof(*buff2)); if (buff2 == NULL) { printf("Malloc failed for the buffer."); finalise(); exit(1); } threads = malloc(P * sizeof(*threads)); if (threads == NULL) { printf("Malloc failed for threads.\n"); finalise(); exit(1); } threadIds = malloc(P * sizeof(*threadIds)); if (threadIds == NULL) { printf("Malloc failed for thread ids.\n"); finalise(); exit(1); } } void* parReadFiles(void* arg) { int i; FILE *in; int tid = *(int*)arg; if (tid == 0) { in = fopen("1.txt", "rb"); for (i = 0; i != NReps; ++i) { fread(buff1, sizeof(*buff1), N, in); fseek(in, 0, SEEK_SET); } if (P == 1) { FILE* in2 = fopen("2.txt", "rb"); for (i = 0; i != NReps; ++i) { fread(buff2, sizeof(*buff2), N, in2); fseek(in, 0, SEEK_SET); } } } else { in = fopen("2.txt", "rb"); for (i = 0; i != NReps; ++i) { fread(buff2, sizeof(*buff1), N, in); fseek(in, 0, SEEK_SET); } } } int main(int argc, char** argv) { int i; getArgs(argc, argv); init(); for (i = 0; i != P; ++i) { threadIds[i] = i; pthread_create(threads + i, NULL, parReadFiles, threadIds + i); } for (i = 0; i != P; ++i) { pthread_join(threads[i], NULL); } finalise(); return 0; }
d6a4e0b4d2bb6d0833dfae0f14e226ac8909501f
3e70eda6819fec5bf5ba2299573b333a3a610131
/monster/online/src/db_cache.h
a90df66d83c23a8242d2b9c70110e0604361c652
[]
no_license
dawnbreaks/taomee
cdd4f9cecaf659d134d207ae8c9dd2247bef97a1
f21b3633680456b09a40036d919bf9f58c9cd6d7
refs/heads/master
2021-01-17T10:45:31.240038
2013-03-14T08:10:27
2013-03-14T08:10:27
null
0
0
null
null
null
null
UTF-8
C
false
false
1,186
h
db_cache.h
/** * ===================================================================================== * @file ucount.h * @brief * * Detailed description starts here. * * @internal * Created 07/30/2011 01:38:05 PM * Revision 1.0.0.0 * Compiler gcc/g++ * Company TaoMee.Inc, ShangHai. * Copyright Copyright (c) 2011, TaoMee.Inc, ShangHai. * * @author luis (程龙), luis@taomee.com * This source code was wrote for TaoMee,Inc. ShangHai CN. * ===================================================================================== */ #ifndef H_DB_CACHE_H_20120605 #define H_DB_CACHE_H_20120605 #include "data_structure.h" #include "user_manager.h" void handle_cache_svr_return(svr_msg_header_t *p_ucount_pkg, int len); int handle_get_pinboard_return(usr_info_t *p_user, svr_msg_header_t *p_ucount_pkg); int handle_enter_show_return(usr_info_t *p_user, svr_msg_header_t *p_pkg); int handle_join_show_return(usr_info_t *p_user, svr_msg_header_t *p_pkg); int handle_vote_show_return(usr_info_t *p_user, svr_msg_header_t *p_pkg); int handle_history_show_return(usr_info_t *p_user, svr_msg_header_t *p_pkg); #endif //H_DB_CACHE_H_20120605
411f7b30fd42bc6a036613127e49c94b4f4e7ac1
b9211ff8d3ebd8ecb4764061fdc4f4a679c53415
/Main_app/Main_app/Main_app/distance_sensor.h
07e56dc26cadddcfca949da15498ffdcd4f7c1b4
[]
no_license
had995/URS-Projekt
dc001a0ef4c2773ee1dff747ef7456ccd626568f
bf793e05e59418650b5bd62e4736528cc1660f9b
refs/heads/master
2021-01-09T19:30:21.727059
2020-03-31T17:27:57
2020-03-31T17:27:57
242,427,388
0
0
null
null
null
null
UTF-8
C
false
false
2,045
h
distance_sensor.h
#define DISTANCE_SENSOR_H /* Functions used for controlling distance sensor */ void SENSOR_Init(void){ DDRD = _BV(5); /* Make trigger pin as output */ PORTD = _BV(6); /* Turn on Pull-up */ sei(); /* Enable global interrupt */ TIMSK = (1 << TOIE1); /* Enable Timer1 overflow interrupts */ TCCR1A = 0; /* Turning back to 0 because of lcd */ } ISR(TIMER1_OVF_vect) { TimerOverflow++; /* Increment Timer Overflow count */ } float mesure_distance(){ /* Give 10us trigger pulse on trig. pin to HC-SR04 */ PORTD |= (1 << Trigger_pin); _delay_us(10); PORTD &= (~(1 << Trigger_pin)); TCNT1 = 0; /* Clear Timer counter */ TCCR1B = 0x41; /* Capture on rising edge, No prescaler*/ TIFR = (1<<ICF1); /* Clear ICP flag (Input Capture flag) */ TIFR = (1<<TOV1); /* Clear Timer Overflow flag */ /*Calculate width of Echo by Input Capture (ICP) */ while ((TIFR & (1 << ICF1)) == 0);/* Wait for rising edge */ TCNT1 = 0; /* Clear Timer counter */ TCCR1B = 0x01; /* Capture on falling edge, No prescaler */ TIFR = 1<<ICF1; /* Clear ICP flag (Input Capture flag) */ TIFR = 1<<TOV1; /* Clear Timer Overflow flag */ TimerOverflow = 0;/* Clear Timer overflow count */ while ((TIFR & (1 << ICF1)) == 0);/* Wait for falling edge */ count = ICR1 + (65535 * TimerOverflow); /*When a capture is triggered according to the ICES1 setting, the counter value is copied into the Input Capture Register (ICR1). The event will also set the Input Capture Flag (ICF1), and this can be used to cause an Input Capture Interrupt, if this interrupt is enabled. */ /* 7372800 MHz Timer freq, 0.136us time for one instruction, sound speed =343 m/s, 34300 cm/s */ /* distance = speed * time / 2 */ distance = (float)count / 428.67; return distance; } void distance_to_string(float distance){ dtostrf((double)distance, 2, 2, string);/* distance to string */ //strcat(string, " cm "); /* Concat unit i.e.cm */ lcd_clrscr(); //lcd_puts("Visina: "); lcd_puts(string); /* Print distance */ }
a363f7075c1fc7d57e4f20a12a0f6bd5678838a0
e15c5e2bedb20f193e3e62b304d5af3ae0cb17e5
/PD_Lab/Assignment_02B/ASSG2B_B170065CS_ANOOP_9.c
0901850b6f42fdb6c44093f9f1fe9e35e3dd1e8d
[]
no_license
anoopbabu99/PD_Lab
0f504abbb3e1fc1eaaac7a0abd26db9f4b0c5dab
1c6a051e8c8ade025fda52491190143957316221
refs/heads/master
2020-09-25T17:46:12.981779
2019-12-10T06:48:03
2019-12-10T06:48:03
226,056,941
0
0
null
null
null
null
UTF-8
C
false
false
1,036
c
ASSG2B_B170065CS_ANOOP_9.c
#include <stdio.h> #include <stdlib.h> struct node { int data; struct node *link; }; struct node *root = NULL; void append(); void display(); int length(); int main() { struct node *temp; int n, len, i=0,k,c=0; printf("Enter the value of n: \t"); scanf("%d",&n); printf("Enter the elements of the linked list: \t"); while(i<n) { append(); i++; } printf("Enter the element to be searched: \t"); scanf("%d",&k); len=length(); temp=root; for(i=1; i<len+1; i++) { if(temp->data==k) {printf("Element found at node: \t%d\n",i); c++; temp=temp->link;} else temp=temp->link; } if(c==0) printf("Integer not found\n"); } int length() { int count=0; struct node *temp; temp=root; while(temp!=NULL) { count++; temp=temp->link; } return count; } void append() { struct node *temp; temp=(struct node*)malloc(sizeof(struct node)); scanf("%d", &temp->data); temp->link=NULL; if(root==NULL) { root=temp; } else { struct node *p; p=root; while(p->link!=NULL) { p=p->link; } p->link=temp; } }
37854a2cc018722b2cbb73978cc4cf6c47d92b6e
5bc61e23a6c1969a60efb41226d1c62175bc832d
/BackJoonProblems/C/Math/10757.c
644e84ca95420ba21b289dd798d34445fe8894e2
[]
no_license
yws2995/Project
9c8e8fbdd6c2b131dbd072a4dca766c8043b2995
18cd104df447cdc9c08447b733f0af506d2bcce8
refs/heads/main
2023-07-27T07:40:55.524137
2021-09-13T11:54:20
2021-09-13T11:54:20
389,561,091
0
0
null
null
null
null
UTF-8
C
false
false
245
c
10757.c
#include <stdio.h> #define MAX_CAPACITANCY 100000 int main(void) { char a[MAX_CAPACITANCY] = { 0, }; char b[MAX_CAPACITANCY] = { 0, }; scanf("%s", a); scanf("%s", b); return 0; }
158c4389c86a38a9824b048485595fc6ab971af5
976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f
/source/linux/drivers/dma/extr_amba-pl08x.c_pl08x_burst.c
0df0795095a6e565715feaeface111d908e6daa3
[]
no_license
isabella232/AnghaBench
7ba90823cf8c0dd25a803d1688500eec91d1cf4e
9a5f60cdc907a0475090eef45e5be43392c25132
refs/heads/master
2023-04-20T09:05:33.024569
2021-05-07T18:36:26
2021-05-07T18:36:26
null
0
0
null
null
null
null
UTF-8
C
false
false
774
c
extr_amba-pl08x.c_pl08x_burst.c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ typedef struct TYPE_3__ TYPE_1__ ; /* Type definitions */ typedef scalar_t__ u32 ; struct TYPE_3__ {scalar_t__ burstwords; scalar_t__ reg; } ; /* Variables and functions */ int ARRAY_SIZE (TYPE_1__*) ; TYPE_1__* burst_sizes ; __attribute__((used)) static u32 pl08x_burst(u32 maxburst) { int i; for (i = 0; i < ARRAY_SIZE(burst_sizes); i++) if (burst_sizes[i].burstwords <= maxburst) break; return burst_sizes[i].reg; }
5e15f19b89aa97cb160080c0cae099386d39f8e4
ba14741dad5b924c60cfd689c7bc51a95a3f9e6c
/tp1/tp1_servidor_baash/parsear_entrada.c
48b2a92e7c67007596f5532f547826a304eeb22f
[]
no_license
Sepulveda25/so2-2018
89a206aaa66f9124b00ed283b0a6f0b3d243dbd2
32e041801d76cd68dc0274043c4e3ef8c2a51269
refs/heads/master
2023-04-01T17:36:14.938790
2018-06-05T19:47:33
2018-06-05T19:47:33
356,075,933
0
0
null
null
null
null
UTF-8
C
false
false
925
c
parsear_entrada.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #define TAM 1024 /*! \param entrada es la cadena que se quiere parsear. \param entrada_parseada[] es donde se va almacenando la cadena ya parseada. \param caracteres son los caracteres que se quieren quitar de la cadena \return Devuelve la longitud de entrada_parseada. */ ///\par Función parsear_entrada. /// Esta funcion quita la los simbolos (que se le pasan caracteres). Es util para transformar una cadena en una lista de cadenas int parsear_entrada(char *entrada,char *entrada_parseada[],char *caracteres){ // se ingresa cada palabra a una posicion del vector entrada_parseada int i=0; char *token; token = strtok( entrada, caracteres); //se quitan los "caracteres" entrada_parseada[i]=token;// while(token!=NULL){ i++; token = strtok( NULL, caracteres);//se siguen quitando los "caracteres" entrada_parseada[i]=token; } return i; }
a11eb0fbd1ad86054364289212728e00c6c0bc12
9ac0dc4e158ef922634ca64c63b32369fa780df0
/shiyan3/shel.c
cacb1cca0c8b38750ce21e86d460116a814717fe
[]
no_license
gaofengyun/linux
32f0273259b88a4e7d761add55ede9a42788270d
2b301f9c631e4b95a72189c00a8fa9d9b35ea33f
refs/heads/master
2021-01-21T16:00:33.289488
2017-05-23T14:23:52
2017-05-23T14:23:52
91,869,247
0
0
null
null
null
null
UTF-8
C
false
false
921
c
shel.c
#include<stdio.h> #include<string.h> #include<unistd.h> #include<sys/types.h> #include<pwd.h> #define N 100 #define M 20 int main(){ int pid,i; char *p,*ch = " "; char buf[N]; char path[N],name[M]; char *arr[M]; while(1){ gethostname(name,M);//返回本地主机的标准主机名 getcwd(path,N);//获得当前工作目录 printf("%s:%s~ ", name,path); fflush(stdout);//清空缓冲 gets(buf); /* 函数返回字符串str1中紧接“标记”的部分的指针, 字符串str2是作为标记的分隔符。 如果分隔标记没有找到,函数返回NULL。为了将字符串转换成标记, 第一次调用str1 指向作为标记的分隔符。之后所以的调用str1 都应为NULL*/ p = strtok(buf,ch); arr[0] = p; i = 1; while(1){ p = strtok(NULL,ch); arr[i] = p; if(p == NULL) break; i++; } pid = fork(); if(pid == 0)//子进程 execvp(arr[0], arr); wait(NULL); } }
b051eae0b720f5931ee5a79a4c32886970349b9e
31de05a80a61b2bb059671913e1883990c93f1a6
/2.1.3_getopt_shortlong.c
fd40afd53758b81da45e6f0f892a7771dc1939b0
[]
no_license
RubyHuynh/Study_C
beba37fe29787b0fcc2e527df761367492deade6
5fcc99fdedf18e943e12119294026cce3c0b5e62
refs/heads/master
2022-06-17T16:21:48.797061
2022-06-02T06:04:27
2022-06-02T06:04:27
192,298,916
1
0
null
null
null
null
UTF-8
C
false
false
1,615
c
2.1.3_getopt_shortlong.c
#include <stdio.h> #include <stdlib.h> #include <getopt.h> const char* prg_name; #define S_HELP 'h' #define S_OUTPUT 'o' #define S_VERBOSE 'v' #define L_HELP "help" #define L_OUTPUT "output" #define L_VERBOSE "verbose" void usage(FILE *stream, int exit_code) { fprintf(stream, "Usage %s options\n", prg_name); fprintf(stream, "-%c --%s \n" "-%c --%s out_file \n" "-%c --%s \n" , S_HELP, L_HELP, S_OUTPUT, L_OUTPUT, S_VERBOSE, L_VERBOSE); exit(exit_code); } int main(int argc, char* argv[]) { int next_opt = 0; const char* const short_opts = "ho:v"; const struct option long_opts[] = { {L_HELP, 0, NULL, S_HELP}, {L_OUTPUT, 1, NULL, S_OUTPUT}, {L_VERBOSE, 0, NULL, S_VERBOSE}, {NULL, 0, NULL, 0} }; const char* o_file = NULL; int verbose = 0; prg_name = argv[0]; do { next_opt = getopt_long(argc, argv, short_opts, long_opts, NULL); switch (next_opt) { case S_HELP: usage(stdout, 0); case S_OUTPUT: o_file = optarg; break; case S_VERBOSE: verbose = 2; break; case -1: /* done */ break; case '?': /* invalid option */ usage(stderr, 1); default: /* should not happen */ abort(); } } while (next_opt != -1); printf("=====\n Done: output=%s verbose=%d \n", o_file, verbose); return 0; }
f7d0e584b438fe1b537c0fbf8dfb58acc2755de7
3fed19f20289bcf3b72f0733335c0369b903573d
/algorithm/kuaisupaixu/main.c
642f9397c67cfb6c4517c362431024cb01dd9736
[]
no_license
lishuai-lws/npucoding
d4b063ab638dddf2fadce0351aff0cf90f9c555b
469b1a38d03b84de885136f427d91528725d7eaa
refs/heads/main
2023-03-20T00:15:39.216678
2021-03-13T12:44:44
2021-03-13T12:44:44
null
0
0
null
null
null
null
UTF-8
C
false
false
775
c
main.c
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 2 void quicksort(int a[],int n,int left,int right) { int i,j,t; if(left<right) { i=left; j=right+1; while(1) { while(i+1<n&&a[++i]<a[left]); while(j-1>-1&&a[--j]>a[left]); if(i>=j)break; t=a[i],a[i]=a[j],a[j]=t; } t=a[left],a[left]=a[j],a[j]=t; quicksort(a,n,left,j-1); quicksort(a,n,j+1,right); } } int main() { int a[N],i; //srand((unsigned int)time(0)); for(i=0;i<N;i++) { scanf("%d",&a[i]); } quicksort(a,N,0,N-1); for(i=0;i<N;i++) printf("%d ",a[i]); return 0; } //56 89 12 6 4 36 99 48 15 42
9e9e5320bb9515da768005036ca1ba828577f28e
74450d2e5c5d737ab8eb3f3f2e8b7d2e8b40bb5e
/github_code/avl-tree/cpp/20.c
0038259e4bf8d5c934338f0f9e1ae03f45282dec
[]
no_license
ulinka/tbcnn-attention
10466b0925987263f722fbc53de4868812c50da7
55990524ce3724d5bfbcbc7fd2757abd3a3fd2de
refs/heads/master
2020-08-28T13:59:25.013068
2019-05-10T08:05:37
2019-05-10T08:05:37
null
0
0
null
null
null
null
UTF-8
C
false
false
7,636
c
20.c
// // AVL-Tree.cpp // SWTest // // Created by Risman Adnan on 7/15/15. // Copyright (c) 2015 Risman Adnan. All rights reserved. // /* AVL Tree | Set 1 (Insertion) AVL tree is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be more than one for all nodes. Why AVL Trees? Most of the BST operations (e.g., search, max, min, insert, delete.. etc) take O(h) time where h is the height of the BST. The cost of these operations may become O(n) for a skewed Binary tree. If we make sure that height of the tree remains O(Logn) after every insertion and deletion, then we can guarantee an upper bound of O(Logn) for all these operations. The height of an AVL tree is always O(Logn) where n is the number of nodes in the tree (See this video lecture for proof). */ #include<cstdio> #include<cstdlib> #include<iostream> using namespace std; // An AVL tree node typedef struct node { int key; struct node *left; struct node *right; int height; }node; // A utility function to get maximum of two integers int max(int a, int b); // A utility function to get height of the tree int height(node *N) { if (N == NULL) return 0; return N->height; } // A utility function to get maximum of two integers int max(int a, int b) { return (a > b)? a : b; } /* Helper function that allocates a new node with the given key and NULL left and right pointers. */ node* newNode(int key) { node* tmp = new node(); tmp->key = key; tmp->left = NULL; tmp->right = NULL; tmp->height = 1; // new node is initially added at leaf return(tmp); } // A utility function to right rotate subtree rooted with y // See the diagram given above. node *rightRotate(node *y) { node *x = y->left; node *T2 = x->right; // Perform rotation x->right = y; y->left = T2; // Update heights y->height = max(height(y->left), height(y->right))+1; x->height = max(height(x->left), height(x->right))+1; // Return new root return x; } // A utility function to left rotate subtree rooted with x // See the diagram given above. node *leftRotate(node *x) { node *y = x->right; node *T2 = y->left; // Perform rotation y->left = x; x->right = T2; // Update heights x->height = max(height(x->left), height(x->right))+1; y->height = max(height(y->left), height(y->right))+1; // Return new root return y; } // Get Balance factor of node N int getBalance(node *N) { if (N == NULL) return 0; return height(N->left) - height(N->right); } node* insert(node* node, int key) { /* 1. Perform the normal BST rotation */ if (node == NULL) return(newNode(key)); if (key < node->key) node->left = insert(node->left, key); else node->right = insert(node->right, key); /* 2. Update height of this ancestor node */ node->height = max(height(node->left), height(node->right)) + 1; /* 3. Get the balance factor of this ancestor node to check whether this node became unbalanced */ int balance = getBalance(node); // If this node becomes unbalanced, then there are 4 cases // Left Left Case if (balance > 1 && key < node->left->key) return rightRotate(node); // Right Right Case if (balance < -1 && key > node->right->key) return leftRotate(node); // Left Right Case if (balance > 1 && key > node->left->key) { node->left = leftRotate(node->left); return rightRotate(node); } // Right Left Case if (balance < -1 && key < node->right->key) { node->right = rightRotate(node->right); return leftRotate(node); } /* return the (unchanged) node pointer */ return node; } /* Given a non-empty binary search tree, return the node with minimum key value found in that tree. Note that the entire tree does not need to be searched. */ node * minValueNode(node* t) { node* current = t; /* loop down to find the leftmost leaf */ while (current->left != NULL) current = current->left; return current; } node* deleteNode(node* root, int key) { // STEP 1: PERFORM STANDARD BST DELETE if (root == NULL) return root; // If the key to be deleted is smaller than the root's key, // then it lies in left subtree if ( key < root->key ) root->left = deleteNode(root->left, key); // If the key to be deleted is greater than the root's key, // then it lies in right subtree else if( key > root->key ) root->right = deleteNode(root->right, key); // if key is same as root's key, then This is the node // to be deleted else { // node with only one child or no child if( (root->left == NULL) || (root->right == NULL) ) { struct node *temp = root->left ? root->left : root->right; // No child case if(temp == NULL) { temp = root; root = NULL; } else // One child case *root = *temp; // Copy the contents of the non-empty child free(temp); } else { // node with two children: Get the inorder successor (smallest // in the right subtree) node* temp = minValueNode(root->right); // Copy the inorder successor's data to this node root->key = temp->key; // Delete the inorder successor root->right = deleteNode(root->right, temp->key); } } // If the tree had only one node then return if (root == NULL) return root; // STEP 2: UPDATE HEIGHT OF THE CURRENT NODE root->height = max(height(root->left), height(root->right)) + 1; // STEP 3: GET THE BALANCE FACTOR OF THIS NODE (to check whether // this node became unbalanced) int balance = getBalance(root); // If this node becomes unbalanced, then there are 4 cases // Left Left Case if (balance > 1 && getBalance(root->left) >= 0) return rightRotate(root); // Left Right Case if (balance > 1 && getBalance(root->left) < 0) { root->left = leftRotate(root->left); return rightRotate(root); } // Right Right Case if (balance < -1 && getBalance(root->right) <= 0) return leftRotate(root); // Right Left Case if (balance < -1 && getBalance(root->right) > 0) { root->right = rightRotate(root->right); return leftRotate(root); } return root; } // A utility function to print preorder traversal of the tree. // The function also prints height of every node void preOrder(node *root) { if(root != NULL) { cout << root->key << " " ; preOrder(root->left); preOrder(root->right); } } /* Drier program to test above function*/ int main() { struct node *root = NULL; /* Constructing tree given in the above figure */ root = insert(root, 10); root = insert(root, 20); root = insert(root, 30); root = insert(root, 40); root = insert(root, 50); root = insert(root, 25); /* The constructed AVL Tree would be 30 / \ 20 40 / \ \ 10 25 50 */ cout << "Pre order traversal of the constructed AVL tree is \n"; preOrder(root); return 0; }
e8ceb9da04f75b535cc61fe8523a831d34d0e296
b49c9e81a1cfb1fe2d3a2723c2e75de1eca1f2b3
/MidtermExam/SumOfInteger/SumOfInteger/main.c
2ecf0cf1102d61fefe330eb9f909e8d9ab55dfe0
[]
no_license
arkss/C_language
1d04c8ca3591645b6bf0d36c7d0a76f3c7f0422d
d0db7ed93278507a5d3850de801321e110415930
refs/heads/master
2020-04-07T04:28:46.845996
2018-12-25T04:47:10
2018-12-25T04:47:10
158,058,470
0
0
null
null
null
null
UTF-8
C
false
false
350
c
main.c
#include <stdio.h> int get_sum(int a, int b) { int i; int sum; for(i=a;i<=b;i++) { sum += i; } return sum; } int main(void) { int a,b; int result; printf("두 수 사이의 합을 구합니다."); scanf("%d %d",&a,&b); result = get_sum(a,b); printf("합은 %d입니다.\n",result); }
b32d00b7066113e5f98754e32ec4a4baa2fbcacd
fa00e492bdc1deae0f2b2b1927855719c774c736
/sort/bubble_sort.c
6ecdfa009cd07ee245064bf08cf9ab3352e95bde
[]
no_license
FengYusheng/data-structure-and-algorithm
bce2a7bc12046910fa5f4fa256a16278f7fca02f
6e70bb6ebd8591f79a1a949f09676caf97d9c997
refs/heads/master
2020-12-24T12:29:05.998799
2018-08-20T02:02:00
2018-08-20T02:02:00
72,997,459
0
0
null
null
null
null
UTF-8
C
false
false
1,261
c
bubble_sort.c
#include<stdio.h> #include<stdbool.h> #define MAX 10 int srcArray[MAX] = {1,8,4,6,0,3,5,2,7,9}; void printArray() { int i = 0; printf("["); for (i = 0; i < MAX; i++) { i < MAX - 1 ? printf("%d, ", srcArray[i]) : printf("%d", srcArray[i]); } printf("]\n"); } void _swapItems(int *a, int *b) { if (a != b) { *a = *a ^ *b; *b = *a ^ *b; *a = *a ^ *b; } } void bubble_sort(int arr[], int len) { int i = 0, j = 0; bool swapped = false; for (i = 0; i < len - 1; i++) { printf("iteration %d#: ", i); printArray(); for (j = 0; j < len - i - 1; j++) { printf("Items compared: %d %d", arr[j], arr[j+1]); if (arr[j] > arr[j+1]) { _swapItems(&arr[j], &arr[j+1]); swapped = true; printf(" ==> swapped [%d %d]\n", arr[j], arr[j+1]); } else { printf(" ==> not swapped\n"); } } if (false == swapped) { break; } } } int main() { printf("Input array: "); printArray(); bubble_sort(srcArray, MAX); printf("Output array: "); printArray(); return 0; }
b9a9df9ce411714203e1797b585566ebcb567faa
5c6f2e98efacbd9e73da423d0427fbc302283a5f
/01- HLEDMAT/HLEDMAT_program.c
8e45a84e26f0a1c43455050cb761d136c1094c5d
[]
no_license
Abomariam1/Stm32
18235de12b2958ca4b87bcd823c16a76160a0a74
bf6291aa93d7bb6e533ded8524b9daa91413e6eb
refs/heads/main
2023-04-01T20:02:26.324100
2021-04-07T08:58:05
2021-04-07T08:58:05
null
0
0
null
null
null
null
UTF-8
C
false
false
3,291
c
HLEDMAT_program.c
#include "STD_TYPES.h" #include "BIT_MATH.h" #include "DIO_interface.h" #include "STK_interface.h" #include "HLEDMAT_interface.h" #include "HLEDMAT_private.h" #include "HLEDMAT_config.h" void HLEDMAT_voidInit(void) { MGPIO_VidSetPinDirection(HLEDMAT_ROW_0,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_ROW_1,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_ROW_2,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_ROW_3,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_ROW_4,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_ROW_5,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_ROW_6,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_ROW_7,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_COL_0,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_COL_1,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_COL_2,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_COL_3,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_COL_4,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_COL_5,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_COL_6,0b0010); MGPIO_VidSetPinDirection(HLEDMAT_COL_7,0b0010); } void HLEDMAT_voidDisplayFrame(u8 *Copy_u8Frame) { /* Save the desired Frame */ HLEDMAT_u8Frame = Copy_u8Frame; /* Reset the frame Start */ HLEDMAT_u8CurrentIdx = 0; /* Dislay The first Column */ ActivateColumn(HLEDMAT_u8CurrentIdx); SetRowsValue (Copy_u8Frame[HLEDMAT_u8CurrentIdx]); /* Start timer */ MSTK_voidSetIntervalPeriodic(2000,DisplayNextColumn); } void DisplayNextColumn(void) { HLEDMAT_u8CurrentIdx++; if (HLEDMAT_u8CurrentIdx == 8) { HLEDMAT_u8CurrentIdx = 0; } /* Dislay The first Column */ ActivateColumn(HLEDMAT_u8CurrentIdx); SetRowsValue (Copy_u8Frame[HLEDMAT_u8CurrentIdx]); } void SetRowsValue (u8 Copy_u8Value) { u8 Local_u8Idx; u8 Local_u8Bit[8]; for (Local_u8Idx =0; Local_u8Idx<8;Local_u8Idx++) { GET_BIT(Copy_u8Value[Local_u8Idx],Local_u8Idx); } MGPIO_VidSetPinValue(HLEDMAT_ROW_0,Copy_u8Value[0]); MGPIO_VidSetPinValue(HLEDMAT_ROW_1,Copy_u8Value[1]); MGPIO_VidSetPinValue(HLEDMAT_ROW_2,Copy_u8Value[2]); MGPIO_VidSetPinValue(HLEDMAT_ROW_3,Copy_u8Value[3]); MGPIO_VidSetPinValue(HLEDMAT_ROW_4,Copy_u8Value[4]); MGPIO_VidSetPinValue(HLEDMAT_ROW_5,Copy_u8Value[5]); MGPIO_VidSetPinValue(HLEDMAT_ROW_6,Copy_u8Value[6]); MGPIO_VidSetPinValue(HLEDMAT_ROW_7,Copy_u8Value[7]); } void ActivateColumn(u8 Copy_u8Col) { /* Disable All */ MGPIO_VidSetPinValue(HLEDMAT_COL_0,HIGH); MGPIO_VidSetPinValue(HLEDMAT_COL_1,HIGH); MGPIO_VidSetPinValue(HLEDMAT_COL_2,HIGH); MGPIO_VidSetPinValue(HLEDMAT_COL_3,HIGH); MGPIO_VidSetPinValue(HLEDMAT_COL_4,HIGH); MGPIO_VidSetPinValue(HLEDMAT_COL_5,HIGH); MGPIO_VidSetPinValue(HLEDMAT_COL_6,HIGH); MGPIO_VidSetPinValue(HLEDMAT_COL_7,HIGH); /* Enable the desired pin only */ switch (Copy_u8Col) { case 0: MGPIO_VidSetPinValue(HLEDMAT_COL_0,LOW); break; case 1: MGPIO_VidSetPinValue(HLEDMAT_COL_1,LOW); break; case 2: MGPIO_VidSetPinValue(HLEDMAT_COL_2,LOW); break; case 3: MGPIO_VidSetPinValue(HLEDMAT_COL_3,LOW); break; case 4: MGPIO_VidSetPinValue(HLEDMAT_COL_4,LOW); break; case 5: MGPIO_VidSetPinValue(HLEDMAT_COL_5,LOW); break; case 6: MGPIO_VidSetPinValue(HLEDMAT_COL_6,LOW); break; case 7: MGPIO_VidSetPinValue(HLEDMAT_COL_7,LOW); break; } }
aafef59efb71d7d41df3d9d188b72bff424e82dd
caea8d9e7c789061cc2afa5853c22c54274ad224
/engine/include/apidef.h
9bb3d4f3ffc5a44f29b50d7dd6ac83ece6d997eb
[ "MIT" ]
permissive
tristanred/MicroEngine
183338d5573f3c99417ce0706f3b06881bd7a67c
06635144b729420caf7c743e3d7ab325569ae293
refs/heads/master
2021-06-04T02:59:54.291499
2020-05-22T21:31:59
2020-05-22T21:31:59
134,793,491
0
0
MIT
2020-05-16T00:52:44
2018-05-25T02:33:37
C
UTF-8
C
false
false
532
h
apidef.h
// Library export macro #ifdef _WIN32 #if defined(MICROENGINE_EXPORTS) #define ENGINE_API extern "C" __declspec(dllexport) #define ENGINE_CLASS __declspec(dllexport) #elif defined(MICROENGINE_LOADDLL) #define ENGINE_API extern "C" __declspec(dllimport) #define ENGINE_CLASS __declspec(dllimport) #else // defined(MICROENGINE_EXPORTS) #define ENGINE_API extern "C" #define ENGINE_CLASS __declspec(dllexport) #endif // defined(MICROENGINE_EXPORTS) #else // _WIN32 #define ENGINE_API #define ENGINE_CLASS #endif // _WIN32
297cb0ea4d404913e772716c8ae09a8add2c3594
1f4fd04d5590aba5fa653c395c17d5f8d5dc74e0
/src/main.c
dc55b8c22d67b3dc6cbaa03396fec39efedacdd1
[]
no_license
modulusx/pebble-pistorm
1c15b90b089c40369fecce21ab974a4742000dbc
652f178f38bc300be2433ed97a35f4f92a5b36cd
refs/heads/master
2021-01-10T06:43:52.259166
2016-01-18T18:57:14
2016-01-18T18:57:14
49,683,784
0
0
null
null
null
null
UTF-8
C
false
false
4,967
c
main.c
#include "pebble.h" #define KEY_FORWARD 0 #define KEY_RIGHT 1 #define KEY_LEFT 2 #define KEY_STOP 3 #define KEY_MENU_ITEMS 10 #define KEY_MENU_TITLE 11 #define KEY_ACTION 12 typedef struct { Window *menu_window; SimpleMenuLayer *menu_layer; SimpleMenuSection *menu_sections; SimpleMenuItem *menu_items; int index; int num_sections; int num_items; char* titles; } WindowConfig; static WindowConfig *s_main; static void sendToPubNub(int index) { Tuplet value = TupletInteger(KEY_ACTION,index); DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_tuplet(iter,&value); app_message_outbox_send(); } static void menu_select_callback(int index, void *ctx) { sendToPubNub(index); layer_mark_dirty(simple_menu_layer_get_layer(s_main->menu_layer)); } static void menu_window_load(Window *window) { int num_a_items = 0; s_main->menu_items[num_a_items++] = (SimpleMenuItem) { .title = "Loading...", .callback = menu_select_callback, }; s_main->menu_sections[0] = (SimpleMenuSection) { .title = PBL_IF_RECT_ELSE("PiStorm", NULL), .num_items = s_main->num_items, .items = s_main->menu_items, }; Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); s_main->menu_layer = simple_menu_layer_create(bounds, window, s_main->menu_sections, s_main->num_sections, NULL); layer_add_child(window_layer, simple_menu_layer_get_layer(s_main->menu_layer)); } void menu_window_unload(Window *window) { simple_menu_layer_destroy(s_main->menu_layer); } WindowConfig* createWC() { WindowConfig *wc; wc = malloc(sizeof(WindowConfig)); wc->num_sections = 1; wc->num_items = 1; wc->index = 0; wc->menu_window = window_create(); wc->menu_sections = malloc(wc->num_sections * sizeof(SimpleMenuSection)); wc->menu_items = malloc(wc->num_items * sizeof(SimpleMenuItem)); wc->titles = malloc(sizeof(char)*16); return wc; } void updateWC() { free(s_main->menu_items); free(s_main->menu_sections); s_main->menu_items = malloc(s_main->num_items * sizeof(SimpleMenuItem)); s_main->menu_sections = malloc(s_main->num_sections * sizeof(SimpleMenuSection)); simple_menu_layer_destroy(s_main->menu_layer); for (int i=0; i < s_main->num_items; i++) { s_main->menu_items[i] = (SimpleMenuItem) { .title = &s_main->titles[i*16], .callback = menu_select_callback, }; } s_main->menu_sections[0] = (SimpleMenuSection) { .title = PBL_IF_RECT_ELSE("PiStorm", NULL), .num_items = s_main->num_items, .items = s_main->menu_items, }; Layer *window_layer = window_get_root_layer(s_main->menu_window); GRect bounds = layer_get_frame(window_layer); s_main->menu_layer = simple_menu_layer_create(bounds, s_main->menu_window, s_main->menu_sections, s_main->num_sections, NULL); layer_add_child(window_layer, simple_menu_layer_get_layer(s_main->menu_layer)); } void deleteWC() { free(s_main->menu_sections); free(s_main->menu_items); free(s_main->titles); } static void inbox_received_callback(DictionaryIterator *iterator, void *context) { static char buffer_title[16]; Tuple *t = dict_read_first(iterator); while(t != NULL) { switch(t->key) { case KEY_MENU_ITEMS: s_main->num_items = t->value->uint32; free(s_main->titles); s_main->titles = malloc(s_main->num_items * sizeof(char) * 16); break; case KEY_MENU_TITLE: snprintf(buffer_title, sizeof(buffer_title), "%s", t->value->cstring); memcpy(&s_main->titles[s_main->index*16],&buffer_title,16); s_main->index++; break; default: APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognized!", (int)t->key); break; } t = dict_read_next(iterator); } if (s_main->index == s_main->num_items) updateWC(); } static void inbox_dropped_callback(AppMessageResult reason, void *context) { APP_LOG(APP_LOG_LEVEL_ERROR, "Message dropped!"); } static void outbox_failed_callback(DictionaryIterator *iterator, AppMessageResult reason, void *context) { APP_LOG(APP_LOG_LEVEL_ERROR, "Outbox send failed!"); } static void outbox_sent_callback(DictionaryIterator *iterator, void *context) { APP_LOG(APP_LOG_LEVEL_INFO, "Outbox send success!"); } static void init() { s_main = createWC(); window_set_window_handlers(s_main->menu_window, (WindowHandlers) { .load = menu_window_load, .unload = menu_window_unload, }); window_stack_push(s_main->menu_window, true); app_message_register_inbox_received(inbox_received_callback); app_message_register_inbox_dropped(inbox_dropped_callback); app_message_register_outbox_failed(outbox_failed_callback); app_message_register_outbox_sent(outbox_sent_callback); app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); } static void deinit() { window_destroy(s_main->menu_window); deleteWC(); } int main(void) { init(); app_event_loop(); deinit(); }
e8f8c955197b3571053c2dc609387de381b9bbc1
a9aa074f0d0bbbd75bc5ea72c4a60c3985407762
/suzaku/hxd/src/module/HXDHKFitsRead/HXDHKFitsReadPST.c
14176ade83d825298c5937f802d1ed779820f53c
[]
no_license
Areustle/heasoft-6.20
d54e5d5b8769a2544472d98b1ac738a1280da6c1
1162716527d9d275cdca064a82bf4d678fbafa15
refs/heads/master
2021-01-21T10:29:55.195578
2017-02-28T14:26:43
2017-02-28T14:26:43
83,440,883
0
1
null
null
null
null
UTF-8
C
false
false
151,352
c
HXDHKFitsReadPST.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "cli.h" #include "com.h" #include "bnk.h" #include "evs.h" #include "anl.h" #include "fitsio.h" #include "cfortran.h" #include "HXD.h" enum { HK=2,SYS,ACU,SCL,PWH,RHK }; enum { STM=2,PPR,PST,AET_HC,AET_SC }; enum { MEM_DMP=2,ECC_DMP,IO_DMP,RECC_DMP,RIO_DMP }; enum { SFC=2,SFF1,SFF2,DLT,SP_PMT,SP_PIN }; enum { HXD_PST_PI_VER, HXD_PST_ERR_CNT, HXD_PST_RET_ERR, HXD_PST_ERR_SYS, HXD_PST_ERR_PI, HXD_PST_ERR_PICD, HXD_PST_WEV_TOUT, HXD_PST_GST_CALL, HXD_PST_GST_PARA, HXD_PST_PST_CALL, HXD_PST_PST_DISC, HXD_PST_PPS_CALL, HXD_PST_GCM_CALL, HXD_PST_PCM_CALL, HXD_PST_GWE_CALL, HXD_PST_GWE_SIZE, HXD_PST_PWE_RJCT, HXD_PST_PWE_CALL, HXD_PST_GWE_LNER, HXD_PST_GMN_CALL, HXD_PST_GMN_CNT, HXD_PST_PMN_CALL, HXD_PST_PMN_DISC, HXD_PST_GHK_CALL, HXD_PST_GHK_CNT, HXD_PST_PHK_CALL, HXD_PST_PHK_DISC, HXD_PST_GBST_CALL, HXD_PST_GBST_CNT, HXD_PST_PBST_CALL, HXD_PST_PBST_DISC, HXD_PST_BST_CNT0, HXD_PST_BST_CNT1, HXD_PST_BST_CNT2, HXD_PST_BST_CNT3, HXD_PST_BST_CURMD, HXD_PST_CMD_RJCT, HXD_PST_GTR_CALL, HXD_PST_GTR_LNER, HXD_PST_PTR_CALL, HXD_PST_PTR_DISC, HXD_PST_TRN_CNT0, HXD_PST_TRN_CNT1, HXD_PST_TRN_CNT2, HXD_PST_TRN_CNT3, HXD_PST_GB_FLG, HXD_PST_GB_FRZ, HXD_PST_PHSF_SEQ, HXD_PST_PHSF_CALL, HXD_PST_PHSF_DISC, HXD_PST_PHSF_C0, HXD_PST_PHSF_C1, HXD_PST_PHSF_PS0, HXD_PST_PHSF_PS1, HXD_PST_UNI_DIS0, HXD_PST_UNI_DIS1, HXD_PST_UNI_DIS2, HXD_PST_UNI_DIS3, HXD_PST_2D_DIS0, HXD_PST_2D_DIS1, HXD_PST_2D_DIS2, HXD_PST_2D_DIS3, HXD_PST_2D_DIS4, HXD_PST_2D_DIS5, HXD_PST_2D_DIS6, HXD_PST_2D_DIS7, HXD_PST_2D_DIS8, HXD_PST_2D_DIS9, HXD_PST_2D_DIS10, HXD_PST_2D_DIS11, HXD_PST_2D_DIS12, HXD_PST_2D_DIS13, HXD_PST_2D_DIS14, HXD_PST_2D_DIS15, HXD_PST_FL_DIS0, HXD_PST_EVSEL_FL_DIS1, HXD_PST_FL_DIS2, HXD_PST_FL_DIS3, HXD_PST_FL_DIS4, HXD_PST_FL_DIS5, HXD_PST_FL_DIS6, HXD_PST_FLG_DIS7, HXD_PST_FL_DIS8, HXD_PST_FL_DIS9, HXD_PST_FL_DIS10, HXD_PST_FL_DIS11, HXD_PST_FL_DIS12, HXD_PST_FL_DIS13, HXD_PST_FL_DIS14, HXD_PST_FL_DIS15, HXD_PST_TR_DIS0, HXD_PST_TR_DIS1, HXD_PST_TR_DIS2, HXD_PST_TR_DIS3, HXD_PST_TR_DIS4, HXD_PST_TR_DIS5, HXD_PST_TR_DIS6, HXD_PST_TR_DIS7, HXD_PST_TR_DIS8, HXD_PST_TR_DIS9, HXD_PST_TR_DIS10, HXD_PST_TR_DIS11, HXD_PST_TR_DIS12, HXD_PST_TR_DIS13, HXD_PST_TR_DIS14, HXD_PST_TR_DIS15, HXD_PST_HT_DIS0, HXD_PST_HT_DIS1, HXD_PST_HT_DIS2, HXD_PST_HT_DIS3, HXD_PST_HT_DIS4, HXD_PST_HT_DIS5, HXD_PST_HT_DIS6, HXD_PST_HT_DIS7, HXD_PST_HT_DIS8, HXD_PST_HT_DIS9, HXD_PST_HT_DIS10, HXD_PST_HT_DIS11, HXD_PST_HT_DIS12, HXD_PST_HT_DIS13, HXD_PST_HT_DIS14, HXD_PST_HT_DIS15, HXD_PST_HP_DIS0, HXD_PST_HP_DIS1, HXD_PST_HP_DIS2, HXD_PST_HP_DIS3, HXD_PST_HP_DIS4, HXD_PST_HP_DIS5, HXD_PST_HP_DIS6, HXD_PST_HP_DIS7, HXD_PST_HP_DIS8, HXD_PST_HP_DIS9, HXD_PST_HP_DIS10, HXD_PST_HP_DIS11, HXD_PST_HP_DIS12, HXD_PST_HP_DIS13, HXD_PST_HP_DIS14, HXD_PST_HP_DIS15, HXD_PST_DT_DIS0, HXD_PST_DT_DIS1, HXD_PST_DT_DIS2, HXD_PST_DT_DIS3, HXD_PST_DT_DIS4, HXD_PST_DT_DIS5, HXD_PST_DT_DIS6, HXD_PST_DT_DIS7, HXD_PST_DT_DIS8, HXD_PST_DT_DIS9, HXD_PST_DT_DIS10, HXD_PST_DT_DIS11, HXD_PST_DT_DIS12, HXD_PST_DT_DIS13, HXD_PST_DT_DIS14, HXD_PST_DT_DIS15, HXD_PST_DT_SUM0, HXD_PST_DT_SUM1, HXD_PST_DT_SUM2, HXD_PST_DT_SUM3, HXD_PST_DT_SUM4, HXD_PST_DT_SUM5, HXD_PST_DT_SUM6, HXD_PST_DT_SUM7, HXD_PST_DT_SUM8, HXD_PST_DT_SUM9, HXD_PST_DT_SUM10, HXD_PST_DT_SUM11, HXD_PST_DT_SUM12, HXD_PST_DT_SUM13, HXD_PST_DT_SUM14, HXD_PST_DT_SUM15, HXD_PST_PL_DIS0, HXD_PST_PL_DIS1, HXD_PST_PL_DIS2, HXD_PST_PL_DIS3, HXD_PST_PL_DIS4, HXD_PST_PL_DIS5, HXD_PST_PL_DIS6, HXD_PST_PL_DIS7, HXD_PST_PL_DIS8, HXD_PST_PL_DIS9, HXD_PST_PL_DIS10, HXD_PST_PL_DIS11, HXD_PST_PL_DIS12, HXD_PST_PL_DIS13, HXD_PST_PL_DIS14, HXD_PST_PL_DIS15, HXD_PST_PT_DIS0, HXD_PST_PT_DIS1, HXD_PST_PT_DIS2, HXD_PST_PT_DIS3, HXD_PST_PT_DIS4, HXD_PST_PT_DIS5, HXD_PST_PT_DIS6, HXD_PST_PT_DIS7, HXD_PST_PT_DIS8, HXD_PST_PT_DIS9, HXD_PST_PT_DIS10, HXD_PST_PT_DIS11, HXD_PST_PT_DIS12, HXD_PST_PT_DIS13, HXD_PST_PT_DIS14, HXD_PST_PT_DIS15, HXD_PST_PREV_W0, HXD_PST_PREV_W1, HXD_PST_PREV_W2, HXD_PST_PREV_W3, HXD_PST_PREV_W4, HXD_PST_PREV_W5, HXD_PST_PREV_W6, HXD_PST_PREV_W7, HXD_PST_PREV_W8, HXD_PST_PREV_W9, HXD_PST_PREV_W10, HXD_PST_PREV_W11, HXD_PST_PREV_W12, HXD_PST_PREV_W13, HXD_PST_PREV_W14, HXD_PST_PREV_W15, HXD_PST_PREV_N0, HXD_PST_PREV_N1, HXD_PST_PREV_N2, HXD_PST_PREV_N3, HXD_PST_PREV_N4, HXD_PST_PREV_N5, HXD_PST_PREV_N6, HXD_PST_PREV_N7, HXD_PST_PREV_N8, HXD_PST_PREV_N9, HXD_PST_PREV_N10, HXD_PST_PREV_N11, HXD_PST_PREV_N12, HXD_PST_PREV_N13, HXD_PST_PREV_N14, HXD_PST_PREV_N15, HXD_PST_PREV_I0, HXD_PST_PREV_I1, HXD_PST_PREV_I2, HXD_PST_PREV_I3, HXD_PST_PREV_I4, HXD_PST_PREV_I5, HXD_PST_PREV_I6, HXD_PST_PREV_I7, HXD_PST_PREV_I8, HXD_PST_PREV_I9, HXD_PST_PREV_I10, HXD_PST_PREV_I11, HXD_PST_PREV_I12, HXD_PST_PREV_I13, HXD_PST_PREV_I14, HXD_PST_PREV_I15, HXD_PST_DT_PS0, HXD_PST_DT_PS1, HXD_PST_DT_PS2, HXD_PST_DT_PS3, HXD_PST_DT_PS4, HXD_PST_DT_PS5, HXD_PST_DT_PS6, HXD_PST_DT_PS7, HXD_PST_DT_PS8, HXD_PST_DT_PS9, HXD_PST_DT_PS10, HXD_PST_DT_PS11, HXD_PST_DT_PS12, HXD_PST_DT_PS13, HXD_PST_DT_PS14, HXD_PST_DT_PS15, HXD_PST_ACU_TI0, HXD_PST_ACU_TI1, HXD_PST_ACU_TI2, HXD_PST_ACU_TI3, HXD_PST_ACU_TI4, HXD_PST_ACU_TI5, HXD_PST_ACU_TI6, HXD_PST_ACU_TI7, HXD_PST_ACU_TI8, HXD_PST_ACU_TI9, HXD_PST_ACU_TI10, HXD_PST_ACU_TI11, HXD_PST_ACU_TI12, HXD_PST_ACU_TI13, HXD_PST_ACU_TI14, HXD_PST_ACU_TI15, HXD_PST_BST_REQ0, HXD_PST_BST_REQ1, HXD_PST_BST_REQ2, HXD_PST_BST_REQ3, HXD_PST_TPUTMOD0, HXD_PST_TPUTMOD1, HXD_PST_TPUTMOD2, HXD_PST_TPUTMOD3, HXD_PST_BST_TRGF, HXD_PST_BST_PH_F, HXD_PST_BST_WLDF, HXD_PST_BST_PSEF, HXD_PST_GB_F_PAT, HXD_PST_GB_ENA, }; static char pname[] = "HXDHKFitsReadPST"; static int colnum[296]; static int time_colnum; void HXDHKFitsReadPST_init() { BnkDef( "HXD:PST:PACKET_AETIME", sizeof(double) ); BnkDef( "HXD:PST:PI_VERSION", sizeof(int) ); BnkDef( "HXD:PST:ERROR_COUNT", sizeof(int) ); BnkDef( "HXD:PST:RETURNED_ERROR", sizeof(int) ); BnkDef( "HXD:PST:ERR_SYS", sizeof(int) ); BnkDef( "HXD:PST:ERR_PI", sizeof(int) ); BnkDef( "HXD:PST:ERR_PICOD", sizeof(int) ); BnkDef( "HXD:PST:WEVT_TIMEOUT", sizeof(int) ); BnkDef( "HXD:PST:GSTS_CALL", sizeof(int) ); BnkDef( "HXD:PST:GSTS_PARAM", sizeof(int) ); BnkDef( "HXD:PST:PSTS_CALL", sizeof(int) ); BnkDef( "HXD:PST:PSTS_DISCARD", sizeof(int) ); BnkDef( "HXD:PST:PPST_CALL", sizeof(int) ); BnkDef( "HXD:PST:GCMD_CALL", sizeof(int) ); BnkDef( "HXD:PST:PCMD_CALL", sizeof(int) ); BnkDef( "HXD:PST:GWEL_CALL", sizeof(int) ); BnkDef( "HXD:PST:GWEL_SIZE", sizeof(int) ); BnkDef( "HXD:PST:PWEL_OVERWRITE", sizeof(int) ); BnkDef( "HXD:PST:PWEL_CALL", sizeof(int) ); BnkDef( "HXD:PST:GWEL_LENERROR", sizeof(int) ); BnkDef( "HXD:PST:GMON_CALL", sizeof(int) ); BnkDef( "HXD:PST:GMON_COUNT", sizeof(int) ); BnkDef( "HXD:PST:PMON_CALL", sizeof(int) ); BnkDef( "HXD:PST:PMON_DISCARD", sizeof(int) ); BnkDef( "HXD:PST:GHK_CALL", sizeof(int) ); BnkDef( "HXD:PST:GHK_COUNT", sizeof(int) ); BnkDef( "HXD:PST:PHK_CALL", sizeof(int) ); BnkDef( "HXD:PST:PHK_DISCARD", sizeof(int) ); BnkDef( "HXD:PST:GBST_CALL", sizeof(int) ); BnkDef( "HXD:PST:GBST_COUNT", sizeof(int) ); BnkDef( "HXD:PST:PBST_CALL", sizeof(int) ); BnkDef( "HXD:PST:PBST_DISCARD", sizeof(int) ); BnkDef( "HXD:PST:BST_CNT_TPU", sizeof(int)*4 ); BnkDef( "HXD:PST:BST_CURR_BD", sizeof(int) ); BnkDef( "HXD:PST:CMD_RJT_CNT", sizeof(int) ); BnkDef( "HXD:PST:GTRN_CALL", sizeof(int) ); BnkDef( "HXD:PST:GTRN_LENERROR", sizeof(int) ); BnkDef( "HXD:PST:PTRN_CALL", sizeof(int) ); BnkDef( "HXD:PST:PTRN_DISCARD", sizeof(int) ); BnkDef( "HXD:PST:TRN_COUNT", sizeof(int)*4 ); BnkDef( "HXD:PST:GB_FLG", sizeof(int) ); BnkDef( "HXD:PST:GB_FRZ", sizeof(int) ); BnkDef( "HXD:PST:PHSF_SEQ", sizeof(int) ); BnkDef( "HXD:PST:PHSF_CALL", sizeof(int) ); BnkDef( "HXD:PST:PHSF_DISCARD", sizeof(int) ); BnkDef( "HXD:PST:PHSF_COUNTER", sizeof(int)*2 ); BnkDef( "HXD:PST:PHSF_PSEUD", sizeof(int)*2 ); BnkDef( "HXD:PST:EVSEL_UNI_DISCD", sizeof(int)*4 ); BnkDef( "HXD:PST:EVSEL_2D_DISCD", sizeof(int)*16 ); BnkDef( "HXD:PST:EVSEL_FLG_DISCD", sizeof(int)*16 ); BnkDef( "HXD:PST:EVSEL_TRG_DISCD", sizeof(int)*16 ); BnkDef( "HXD:PST:EVSEL_HIT_DISCD", sizeof(int)*16 ); BnkDef( "HXD:PST:EVSEL_HITPIN_DISCD", sizeof(int)*16 ); BnkDef( "HXD:PST:EVSEL_DT_DISCD", sizeof(int)*16 ); BnkDef( "HXD:PST:EVSEL_DT_SUMT", sizeof(int)*16 ); BnkDef( "HXD:PST:EVSEL_PINLD_DISCD", sizeof(int)*16 ); BnkDef( "HXD:PST:EVSEL_PINTRG_DISCD", sizeof(int)*16 ); BnkDef( "HXD:PST:PREV_PWEL", sizeof(int)*16 ); BnkDef( "HXD:PST:PREV_NON_EXIST", sizeof(int)*16 ); BnkDef( "HXD:PST:PREV_INVAL", sizeof(int)*16 ); BnkDef( "HXD:PST:EVSEL_DT_PSEUD", sizeof(int)*16 ); BnkDef( "HXD:PST:EVSL_ACU_CNT", sizeof(int)*16 ); BnkDef( "HXD:PST:BST_RQUEST_CNT", sizeof(int)*4 ); BnkDef( "HXD:PST:TPU_TIM_MOD", sizeof(int)*4 ); BnkDef( "HXD:PST:BST_TRG_FLG", sizeof(int) ); BnkDef( "HXD:PST:BST_PH_FLG", sizeof(int) ); BnkDef( "HXD:PST:BST_WLD_FLG", sizeof(int) ); BnkDef( "HXD:PST:BST_PSE_FLG", sizeof(int) ); BnkDef( "HXD:PST:GB_FLG_PAT", sizeof(int) ); BnkDef( "HXD:PST:GB_ENA", sizeof(int) ); } int HXDHKFitsReadPST_bgnrun(fitsfile *fp) { int istat = 0; int casesen = TRUE; int hdutype; fits_movabs_hdu( fp, PST, &hdutype, &istat ); if ( istat ) { fprintf(stderr, "%s: fits_movabs_hdu failed (%d)\n", pname, istat); return istat; } else { if( fits_get_colnum(fp, casesen, "TIME", &time_colnum, &istat) ){ fprintf(stderr, "%s: fits_get_colnum('TIME') failed (%d)\n", pname, istat); return istat; } } if( fits_get_colnum(fp, casesen, "HXD_PST_PI_VER", &colnum[HXD_PST_PI_VER], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PI_VER') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ERR_CNT", &colnum[HXD_PST_ERR_CNT], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ERR_CNT') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_RET_ERR", &colnum[HXD_PST_RET_ERR], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_RET_ERR') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ERR_SYS", &colnum[HXD_PST_ERR_SYS], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ERR_SYS') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ERR_PI", &colnum[HXD_PST_ERR_PI], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ERR_PI') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ERR_PICD", &colnum[HXD_PST_ERR_PICD], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ERR_PICD') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_WEV_TOUT", &colnum[HXD_PST_WEV_TOUT], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_WEV_TOUT') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GST_CALL", &colnum[HXD_PST_GST_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GST_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GST_PARA", &colnum[HXD_PST_GST_PARA], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GST_PARA') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PST_CALL", &colnum[HXD_PST_PST_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PST_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PST_DISC", &colnum[HXD_PST_PST_DISC], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PST_DISC') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PPS_CALL", &colnum[HXD_PST_PPS_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PPS_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GCM_CALL", &colnum[HXD_PST_GCM_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GCM_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PCM_CALL", &colnum[HXD_PST_PCM_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PCM_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GWE_CALL", &colnum[HXD_PST_GWE_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GWE_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GWE_SIZE", &colnum[HXD_PST_GWE_SIZE], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GWE_SIZE') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PWE_RJCT", &colnum[HXD_PST_PWE_RJCT], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PWE_RJCT') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PWE_CALL", &colnum[HXD_PST_PWE_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PWE_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GWE_LNER", &colnum[HXD_PST_GWE_LNER], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GWE_LNER') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GMN_CALL", &colnum[HXD_PST_GMN_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GMN_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GMN_CNT", &colnum[HXD_PST_GMN_CNT], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GMN_CNT') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PMN_CALL", &colnum[HXD_PST_PMN_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PMN_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PMN_DISC", &colnum[HXD_PST_PMN_DISC], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PMN_DISC') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GHK_CALL", &colnum[HXD_PST_GHK_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GHK_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GHK_CNT", &colnum[HXD_PST_GHK_CNT], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GHK_CNT') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PHK_CALL", &colnum[HXD_PST_PHK_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PHK_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PHK_DISC", &colnum[HXD_PST_PHK_DISC], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PHK_DISC') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GBST_CALL", &colnum[HXD_PST_GBST_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GBST_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GBST_CNT", &colnum[HXD_PST_GBST_CNT], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GBST_CNT') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PBST_CALL", &colnum[HXD_PST_PBST_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PBST_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PBST_DISC", &colnum[HXD_PST_PBST_DISC], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PBST_DISC') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_BST_CNT0", &colnum[HXD_PST_BST_CNT0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_BST_CNT0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_BST_CNT1", &colnum[HXD_PST_BST_CNT1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_BST_CNT1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_BST_CNT2", &colnum[HXD_PST_BST_CNT2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_BST_CNT2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_BST_CNT3", &colnum[HXD_PST_BST_CNT3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_BST_CNT3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_BST_CURMD", &colnum[HXD_PST_BST_CURMD], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_BST_CURMD') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_CMD_RJCT", &colnum[HXD_PST_CMD_RJCT], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_CMD_RJCT') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GTR_CALL", &colnum[HXD_PST_GTR_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GTR_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GTR_LNER", &colnum[HXD_PST_GTR_LNER], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GTR_LNER') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PTR_CALL", &colnum[HXD_PST_PTR_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PTR_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PTR_DISC", &colnum[HXD_PST_PTR_DISC], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PTR_DISC') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TRN_CNT0", &colnum[HXD_PST_TRN_CNT0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TRN_CNT0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TRN_CNT1", &colnum[HXD_PST_TRN_CNT1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TRN_CNT1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TRN_CNT2", &colnum[HXD_PST_TRN_CNT2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TRN_CNT2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TRN_CNT3", &colnum[HXD_PST_TRN_CNT3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TRN_CNT3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GB_FLG", &colnum[HXD_PST_GB_FLG], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GB_FLG') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GB_FRZ", &colnum[HXD_PST_GB_FRZ], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GB_FRZ') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PHSF_SEQ", &colnum[HXD_PST_PHSF_SEQ], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PHSF_SEQ') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PHSF_CALL", &colnum[HXD_PST_PHSF_CALL], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PHSF_CALL') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PHSF_DISC", &colnum[HXD_PST_PHSF_DISC], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PHSF_DISC') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PHSF_C0", &colnum[HXD_PST_PHSF_C0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PHSF_C0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PHSF_C1", &colnum[HXD_PST_PHSF_C1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PHSF_C1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PHSF_PS0", &colnum[HXD_PST_PHSF_PS0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PHSF_PS0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PHSF_PS1", &colnum[HXD_PST_PHSF_PS1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PHSF_PS1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_UNI_DIS0", &colnum[HXD_PST_UNI_DIS0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_UNI_DIS0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_UNI_DIS1", &colnum[HXD_PST_UNI_DIS1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_UNI_DIS1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_UNI_DIS2", &colnum[HXD_PST_UNI_DIS2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_UNI_DIS2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_UNI_DIS3", &colnum[HXD_PST_UNI_DIS3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_UNI_DIS3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS0", &colnum[HXD_PST_2D_DIS0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS1", &colnum[HXD_PST_2D_DIS1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS2", &colnum[HXD_PST_2D_DIS2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS3", &colnum[HXD_PST_2D_DIS3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS4", &colnum[HXD_PST_2D_DIS4], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS4') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS5", &colnum[HXD_PST_2D_DIS5], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS5') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS6", &colnum[HXD_PST_2D_DIS6], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS6') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS7", &colnum[HXD_PST_2D_DIS7], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS7') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS8", &colnum[HXD_PST_2D_DIS8], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS8') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS9", &colnum[HXD_PST_2D_DIS9], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS9') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS10", &colnum[HXD_PST_2D_DIS10], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS10') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS11", &colnum[HXD_PST_2D_DIS11], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS11') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS12", &colnum[HXD_PST_2D_DIS12], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS12') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS13", &colnum[HXD_PST_2D_DIS13], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS13') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS14", &colnum[HXD_PST_2D_DIS14], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS14') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_2D_DIS15", &colnum[HXD_PST_2D_DIS15], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_2D_DIS15') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FL_DIS0", &colnum[HXD_PST_FL_DIS0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FL_DIS0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_EVSEL_FL_DIS1", &colnum[HXD_PST_EVSEL_FL_DIS1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_EVSEL_FL_DIS1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FL_DIS2", &colnum[HXD_PST_FL_DIS2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FL_DIS2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FL_DIS3", &colnum[HXD_PST_FL_DIS3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FL_DIS3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FL_DIS4", &colnum[HXD_PST_FL_DIS4], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FL_DIS4') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FL_DIS5", &colnum[HXD_PST_FL_DIS5], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FL_DIS5') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FL_DIS6", &colnum[HXD_PST_FL_DIS6], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FL_DIS6') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FLG_DIS7", &colnum[HXD_PST_FLG_DIS7], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FLG_DIS7') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FL_DIS8", &colnum[HXD_PST_FL_DIS8], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FL_DIS8') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FL_DIS9", &colnum[HXD_PST_FL_DIS9], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FL_DIS9') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FL_DIS10", &colnum[HXD_PST_FL_DIS10], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FL_DIS10') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FL_DIS11", &colnum[HXD_PST_FL_DIS11], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FL_DIS11') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FL_DIS12", &colnum[HXD_PST_FL_DIS12], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FL_DIS12') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FL_DIS13", &colnum[HXD_PST_FL_DIS13], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FL_DIS13') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FL_DIS14", &colnum[HXD_PST_FL_DIS14], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FL_DIS14') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_FL_DIS15", &colnum[HXD_PST_FL_DIS15], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_FL_DIS15') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS0", &colnum[HXD_PST_TR_DIS0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS1", &colnum[HXD_PST_TR_DIS1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS2", &colnum[HXD_PST_TR_DIS2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS3", &colnum[HXD_PST_TR_DIS3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS4", &colnum[HXD_PST_TR_DIS4], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS4') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS5", &colnum[HXD_PST_TR_DIS5], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS5') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS6", &colnum[HXD_PST_TR_DIS6], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS6') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS7", &colnum[HXD_PST_TR_DIS7], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS7') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS8", &colnum[HXD_PST_TR_DIS8], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS8') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS9", &colnum[HXD_PST_TR_DIS9], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS9') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS10", &colnum[HXD_PST_TR_DIS10], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS10') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS11", &colnum[HXD_PST_TR_DIS11], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS11') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS12", &colnum[HXD_PST_TR_DIS12], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS12') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS13", &colnum[HXD_PST_TR_DIS13], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS13') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS14", &colnum[HXD_PST_TR_DIS14], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS14') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TR_DIS15", &colnum[HXD_PST_TR_DIS15], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TR_DIS15') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS0", &colnum[HXD_PST_HT_DIS0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS1", &colnum[HXD_PST_HT_DIS1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS2", &colnum[HXD_PST_HT_DIS2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS3", &colnum[HXD_PST_HT_DIS3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS4", &colnum[HXD_PST_HT_DIS4], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS4') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS5", &colnum[HXD_PST_HT_DIS5], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS5') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS6", &colnum[HXD_PST_HT_DIS6], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS6') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS7", &colnum[HXD_PST_HT_DIS7], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS7') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS8", &colnum[HXD_PST_HT_DIS8], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS8') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS9", &colnum[HXD_PST_HT_DIS9], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS9') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS10", &colnum[HXD_PST_HT_DIS10], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS10') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS11", &colnum[HXD_PST_HT_DIS11], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS11') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS12", &colnum[HXD_PST_HT_DIS12], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS12') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS13", &colnum[HXD_PST_HT_DIS13], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS13') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS14", &colnum[HXD_PST_HT_DIS14], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS14') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HT_DIS15", &colnum[HXD_PST_HT_DIS15], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HT_DIS15') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS0", &colnum[HXD_PST_HP_DIS0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS1", &colnum[HXD_PST_HP_DIS1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS2", &colnum[HXD_PST_HP_DIS2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS3", &colnum[HXD_PST_HP_DIS3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS4", &colnum[HXD_PST_HP_DIS4], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS4') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS5", &colnum[HXD_PST_HP_DIS5], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS5') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS6", &colnum[HXD_PST_HP_DIS6], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS6') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS7", &colnum[HXD_PST_HP_DIS7], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS7') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS8", &colnum[HXD_PST_HP_DIS8], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS8') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS9", &colnum[HXD_PST_HP_DIS9], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS9') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS10", &colnum[HXD_PST_HP_DIS10], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS10') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS11", &colnum[HXD_PST_HP_DIS11], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS11') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS12", &colnum[HXD_PST_HP_DIS12], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS12') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS13", &colnum[HXD_PST_HP_DIS13], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS13') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS14", &colnum[HXD_PST_HP_DIS14], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS14') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_HP_DIS15", &colnum[HXD_PST_HP_DIS15], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_HP_DIS15') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS0", &colnum[HXD_PST_DT_DIS0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS1", &colnum[HXD_PST_DT_DIS1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS2", &colnum[HXD_PST_DT_DIS2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS3", &colnum[HXD_PST_DT_DIS3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS4", &colnum[HXD_PST_DT_DIS4], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS4') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS5", &colnum[HXD_PST_DT_DIS5], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS5') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS6", &colnum[HXD_PST_DT_DIS6], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS6') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS7", &colnum[HXD_PST_DT_DIS7], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS7') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS8", &colnum[HXD_PST_DT_DIS8], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS8') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS9", &colnum[HXD_PST_DT_DIS9], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS9') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS10", &colnum[HXD_PST_DT_DIS10], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS10') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS11", &colnum[HXD_PST_DT_DIS11], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS11') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS12", &colnum[HXD_PST_DT_DIS12], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS12') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS13", &colnum[HXD_PST_DT_DIS13], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS13') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS14", &colnum[HXD_PST_DT_DIS14], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS14') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_DIS15", &colnum[HXD_PST_DT_DIS15], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_DIS15') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM0", &colnum[HXD_PST_DT_SUM0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM1", &colnum[HXD_PST_DT_SUM1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM2", &colnum[HXD_PST_DT_SUM2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM3", &colnum[HXD_PST_DT_SUM3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM4", &colnum[HXD_PST_DT_SUM4], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM4') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM5", &colnum[HXD_PST_DT_SUM5], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM5') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM6", &colnum[HXD_PST_DT_SUM6], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM6') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM7", &colnum[HXD_PST_DT_SUM7], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM7') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM8", &colnum[HXD_PST_DT_SUM8], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM8') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM9", &colnum[HXD_PST_DT_SUM9], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM9') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM10", &colnum[HXD_PST_DT_SUM10], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM10') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM11", &colnum[HXD_PST_DT_SUM11], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM11') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM12", &colnum[HXD_PST_DT_SUM12], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM12') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM13", &colnum[HXD_PST_DT_SUM13], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM13') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM14", &colnum[HXD_PST_DT_SUM14], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM14') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_SUM15", &colnum[HXD_PST_DT_SUM15], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_SUM15') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS0", &colnum[HXD_PST_PL_DIS0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS1", &colnum[HXD_PST_PL_DIS1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS2", &colnum[HXD_PST_PL_DIS2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS3", &colnum[HXD_PST_PL_DIS3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS4", &colnum[HXD_PST_PL_DIS4], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS4') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS5", &colnum[HXD_PST_PL_DIS5], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS5') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS6", &colnum[HXD_PST_PL_DIS6], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS6') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS7", &colnum[HXD_PST_PL_DIS7], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS7') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS8", &colnum[HXD_PST_PL_DIS8], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS8') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS9", &colnum[HXD_PST_PL_DIS9], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS9') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS10", &colnum[HXD_PST_PL_DIS10], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS10') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS11", &colnum[HXD_PST_PL_DIS11], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS11') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS12", &colnum[HXD_PST_PL_DIS12], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS12') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS13", &colnum[HXD_PST_PL_DIS13], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS13') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS14", &colnum[HXD_PST_PL_DIS14], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS14') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PL_DIS15", &colnum[HXD_PST_PL_DIS15], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PL_DIS15') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS0", &colnum[HXD_PST_PT_DIS0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS1", &colnum[HXD_PST_PT_DIS1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS2", &colnum[HXD_PST_PT_DIS2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS3", &colnum[HXD_PST_PT_DIS3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS4", &colnum[HXD_PST_PT_DIS4], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS4') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS5", &colnum[HXD_PST_PT_DIS5], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS5') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS6", &colnum[HXD_PST_PT_DIS6], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS6') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS7", &colnum[HXD_PST_PT_DIS7], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS7') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS8", &colnum[HXD_PST_PT_DIS8], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS8') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS9", &colnum[HXD_PST_PT_DIS9], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS9') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS10", &colnum[HXD_PST_PT_DIS10], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS10') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS11", &colnum[HXD_PST_PT_DIS11], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS11') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS12", &colnum[HXD_PST_PT_DIS12], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS12') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS13", &colnum[HXD_PST_PT_DIS13], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS13') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS14", &colnum[HXD_PST_PT_DIS14], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS14') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PT_DIS15", &colnum[HXD_PST_PT_DIS15], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PT_DIS15') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W0", &colnum[HXD_PST_PREV_W0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W1", &colnum[HXD_PST_PREV_W1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W2", &colnum[HXD_PST_PREV_W2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W3", &colnum[HXD_PST_PREV_W3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W4", &colnum[HXD_PST_PREV_W4], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W4') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W5", &colnum[HXD_PST_PREV_W5], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W5') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W6", &colnum[HXD_PST_PREV_W6], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W6') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W7", &colnum[HXD_PST_PREV_W7], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W7') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W8", &colnum[HXD_PST_PREV_W8], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W8') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W9", &colnum[HXD_PST_PREV_W9], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W9') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W10", &colnum[HXD_PST_PREV_W10], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W10') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W11", &colnum[HXD_PST_PREV_W11], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W11') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W12", &colnum[HXD_PST_PREV_W12], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W12') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W13", &colnum[HXD_PST_PREV_W13], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W13') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W14", &colnum[HXD_PST_PREV_W14], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W14') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_W15", &colnum[HXD_PST_PREV_W15], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_W15') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N0", &colnum[HXD_PST_PREV_N0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N1", &colnum[HXD_PST_PREV_N1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N2", &colnum[HXD_PST_PREV_N2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N3", &colnum[HXD_PST_PREV_N3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N4", &colnum[HXD_PST_PREV_N4], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N4') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N5", &colnum[HXD_PST_PREV_N5], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N5') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N6", &colnum[HXD_PST_PREV_N6], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N6') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N7", &colnum[HXD_PST_PREV_N7], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N7') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N8", &colnum[HXD_PST_PREV_N8], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N8') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N9", &colnum[HXD_PST_PREV_N9], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N9') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N10", &colnum[HXD_PST_PREV_N10], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N10') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N11", &colnum[HXD_PST_PREV_N11], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N11') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N12", &colnum[HXD_PST_PREV_N12], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N12') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N13", &colnum[HXD_PST_PREV_N13], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N13') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N14", &colnum[HXD_PST_PREV_N14], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N14') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_N15", &colnum[HXD_PST_PREV_N15], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_N15') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I0", &colnum[HXD_PST_PREV_I0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I1", &colnum[HXD_PST_PREV_I1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I2", &colnum[HXD_PST_PREV_I2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I3", &colnum[HXD_PST_PREV_I3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I4", &colnum[HXD_PST_PREV_I4], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I4') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I5", &colnum[HXD_PST_PREV_I5], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I5') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I6", &colnum[HXD_PST_PREV_I6], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I6') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I7", &colnum[HXD_PST_PREV_I7], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I7') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I8", &colnum[HXD_PST_PREV_I8], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I8') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I9", &colnum[HXD_PST_PREV_I9], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I9') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I10", &colnum[HXD_PST_PREV_I10], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I10') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I11", &colnum[HXD_PST_PREV_I11], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I11') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I12", &colnum[HXD_PST_PREV_I12], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I12') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I13", &colnum[HXD_PST_PREV_I13], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I13') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I14", &colnum[HXD_PST_PREV_I14], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I14') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_PREV_I15", &colnum[HXD_PST_PREV_I15], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_PREV_I15') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS0", &colnum[HXD_PST_DT_PS0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS1", &colnum[HXD_PST_DT_PS1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS2", &colnum[HXD_PST_DT_PS2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS3", &colnum[HXD_PST_DT_PS3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS4", &colnum[HXD_PST_DT_PS4], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS4') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS5", &colnum[HXD_PST_DT_PS5], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS5') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS6", &colnum[HXD_PST_DT_PS6], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS6') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS7", &colnum[HXD_PST_DT_PS7], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS7') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS8", &colnum[HXD_PST_DT_PS8], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS8') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS9", &colnum[HXD_PST_DT_PS9], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS9') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS10", &colnum[HXD_PST_DT_PS10], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS10') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS11", &colnum[HXD_PST_DT_PS11], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS11') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS12", &colnum[HXD_PST_DT_PS12], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS12') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS13", &colnum[HXD_PST_DT_PS13], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS13') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS14", &colnum[HXD_PST_DT_PS14], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS14') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_DT_PS15", &colnum[HXD_PST_DT_PS15], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_DT_PS15') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI0", &colnum[HXD_PST_ACU_TI0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI1", &colnum[HXD_PST_ACU_TI1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI2", &colnum[HXD_PST_ACU_TI2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI3", &colnum[HXD_PST_ACU_TI3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI4", &colnum[HXD_PST_ACU_TI4], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI4') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI5", &colnum[HXD_PST_ACU_TI5], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI5') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI6", &colnum[HXD_PST_ACU_TI6], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI6') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI7", &colnum[HXD_PST_ACU_TI7], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI7') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI8", &colnum[HXD_PST_ACU_TI8], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI8') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI9", &colnum[HXD_PST_ACU_TI9], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI9') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI10", &colnum[HXD_PST_ACU_TI10], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI10') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI11", &colnum[HXD_PST_ACU_TI11], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI11') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI12", &colnum[HXD_PST_ACU_TI12], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI12') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI13", &colnum[HXD_PST_ACU_TI13], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI13') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI14", &colnum[HXD_PST_ACU_TI14], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI14') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_ACU_TI15", &colnum[HXD_PST_ACU_TI15], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_ACU_TI15') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_BST_REQ0", &colnum[HXD_PST_BST_REQ0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_BST_REQ0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_BST_REQ1", &colnum[HXD_PST_BST_REQ1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_BST_REQ1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_BST_REQ2", &colnum[HXD_PST_BST_REQ2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_BST_REQ2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_BST_REQ3", &colnum[HXD_PST_BST_REQ3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_BST_REQ3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TPUTMOD0", &colnum[HXD_PST_TPUTMOD0], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TPUTMOD0') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TPUTMOD1", &colnum[HXD_PST_TPUTMOD1], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TPUTMOD1') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TPUTMOD2", &colnum[HXD_PST_TPUTMOD2], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TPUTMOD2') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_TPUTMOD3", &colnum[HXD_PST_TPUTMOD3], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_TPUTMOD3') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_BST_TRGF", &colnum[HXD_PST_BST_TRGF], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_BST_TRGF') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_BST_PH_F", &colnum[HXD_PST_BST_PH_F], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_BST_PH_F') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_BST_WLDF", &colnum[HXD_PST_BST_WLDF], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_BST_WLDF') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_BST_PSEF", &colnum[HXD_PST_BST_PSEF], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_BST_PSEF') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GB_F_PAT", &colnum[HXD_PST_GB_F_PAT], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GB_F_PAT') failed (%d)\n", pname, istat); return istat;} if( fits_get_colnum(fp, casesen, "HXD_PST_GB_ENA", &colnum[HXD_PST_GB_ENA], &istat) ){ fprintf(stderr, "%s: fits_get_colnum('HXD_PST_GB_ENA') failed (%d)\n", pname, istat); return istat;} return ANL_OK; } int HXDHKFitsReadPST_ana(fitsfile *fp, int irow) { int istat = 0; int anynul; int casesen = TRUE; int hdutype; long firstelem = 1; long nelements = 1; double time; fits_movabs_hdu( fp, PST, &hdutype, &istat ); if ( istat ) { fprintf(stderr, "%s: fits_movabs_hdu (%d) failed (%d)\n", pname, PST, istat); return istat; } else { double nulval=1.0; fits_read_col_dbl(fp, time_colnum, irow, firstelem, nelements, nulval, &time, &anynul, &istat); BnkfPutM ("HXD:PST:PACKET_AETIME", sizeof(double), &time); BnkfPutM ("HXD:ALL:PACKET_AETIME", sizeof(double), &time); } { unsigned int data[1]; unsigned char nulval=1; unsigned char hxd_pst_pi_ver; fits_read_col_byt(fp, colnum[HXD_PST_PI_VER], irow, firstelem, nelements, nulval, &hxd_pst_pi_ver, &anynul, &istat); data[0] = hxd_pst_pi_ver; BnkfPutM ("HXD:PST:PI_VERSION", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_err_cnt; fits_read_col_usht(fp, colnum[HXD_PST_ERR_CNT], irow, firstelem, nelements, nulval, &hxd_pst_err_cnt, &anynul, &istat); data[0] = hxd_pst_err_cnt; BnkfPutM ("HXD:PST:ERROR_COUNT", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_ret_err; fits_read_col_usht(fp, colnum[HXD_PST_RET_ERR], irow, firstelem, nelements, nulval, &hxd_pst_ret_err, &anynul, &istat); data[0] = hxd_pst_ret_err; BnkfPutM ("HXD:PST:RETURNED_ERROR", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_err_sys; fits_read_col_usht(fp, colnum[HXD_PST_ERR_SYS], irow, firstelem, nelements, nulval, &hxd_pst_err_sys, &anynul, &istat); data[0] = hxd_pst_err_sys; BnkfPutM ("HXD:PST:ERR_SYS", sizeof(int)*1, data); } { unsigned int data[1]; unsigned char nulval=1; unsigned char hxd_pst_err_pi; fits_read_col_byt(fp, colnum[HXD_PST_ERR_PI], irow, firstelem, nelements, nulval, &hxd_pst_err_pi, &anynul, &istat); data[0] = hxd_pst_err_pi; BnkfPutM ("HXD:PST:ERR_PI", sizeof(int)*1, data); } { unsigned int data[1]; unsigned char nulval=1; unsigned char hxd_pst_err_picd; fits_read_col_byt(fp, colnum[HXD_PST_ERR_PICD], irow, firstelem, nelements, nulval, &hxd_pst_err_picd, &anynul, &istat); data[0] = hxd_pst_err_picd; BnkfPutM ("HXD:PST:ERR_PICOD", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_wev_tout; fits_read_col_usht(fp, colnum[HXD_PST_WEV_TOUT], irow, firstelem, nelements, nulval, &hxd_pst_wev_tout, &anynul, &istat); data[0] = hxd_pst_wev_tout; BnkfPutM ("HXD:PST:WEVT_TIMEOUT", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_gst_call; fits_read_col_usht(fp, colnum[HXD_PST_GST_CALL], irow, firstelem, nelements, nulval, &hxd_pst_gst_call, &anynul, &istat); data[0] = hxd_pst_gst_call; BnkfPutM ("HXD:PST:GSTS_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_gst_para; fits_read_col_usht(fp, colnum[HXD_PST_GST_PARA], irow, firstelem, nelements, nulval, &hxd_pst_gst_para, &anynul, &istat); data[0] = hxd_pst_gst_para; BnkfPutM ("HXD:PST:GSTS_PARAM", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_pst_call; fits_read_col_usht(fp, colnum[HXD_PST_PST_CALL], irow, firstelem, nelements, nulval, &hxd_pst_pst_call, &anynul, &istat); data[0] = hxd_pst_pst_call; BnkfPutM ("HXD:PST:PSTS_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_pst_disc; fits_read_col_usht(fp, colnum[HXD_PST_PST_DISC], irow, firstelem, nelements, nulval, &hxd_pst_pst_disc, &anynul, &istat); data[0] = hxd_pst_pst_disc; BnkfPutM ("HXD:PST:PSTS_DISCARD", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_pps_call; fits_read_col_usht(fp, colnum[HXD_PST_PPS_CALL], irow, firstelem, nelements, nulval, &hxd_pst_pps_call, &anynul, &istat); data[0] = hxd_pst_pps_call; BnkfPutM ("HXD:PST:PPST_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_gcm_call; fits_read_col_usht(fp, colnum[HXD_PST_GCM_CALL], irow, firstelem, nelements, nulval, &hxd_pst_gcm_call, &anynul, &istat); data[0] = hxd_pst_gcm_call; BnkfPutM ("HXD:PST:GCMD_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_pcm_call; fits_read_col_usht(fp, colnum[HXD_PST_PCM_CALL], irow, firstelem, nelements, nulval, &hxd_pst_pcm_call, &anynul, &istat); data[0] = hxd_pst_pcm_call; BnkfPutM ("HXD:PST:PCMD_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned int nulval=1; unsigned int hxd_pst_gwe_call; fits_read_col_uint(fp, colnum[HXD_PST_GWE_CALL], irow, firstelem, nelements, nulval, &hxd_pst_gwe_call, &anynul, &istat); data[0] = hxd_pst_gwe_call; BnkfPutM ("HXD:PST:GWEL_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_gwe_size; fits_read_col_usht(fp, colnum[HXD_PST_GWE_SIZE], irow, firstelem, nelements, nulval, &hxd_pst_gwe_size, &anynul, &istat); data[0] = hxd_pst_gwe_size; BnkfPutM ("HXD:PST:GWEL_SIZE", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_pwe_rjct; fits_read_col_usht(fp, colnum[HXD_PST_PWE_RJCT], irow, firstelem, nelements, nulval, &hxd_pst_pwe_rjct, &anynul, &istat); data[0] = hxd_pst_pwe_rjct; BnkfPutM ("HXD:PST:PWEL_OVERWRITE", sizeof(int)*1, data); } { unsigned int data[1]; unsigned int nulval=1; unsigned int hxd_pst_pwe_call; fits_read_col_uint(fp, colnum[HXD_PST_PWE_CALL], irow, firstelem, nelements, nulval, &hxd_pst_pwe_call, &anynul, &istat); data[0] = hxd_pst_pwe_call; BnkfPutM ("HXD:PST:PWEL_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned int nulval=1; unsigned int hxd_pst_gwe_lner; fits_read_col_uint(fp, colnum[HXD_PST_GWE_LNER], irow, firstelem, nelements, nulval, &hxd_pst_gwe_lner, &anynul, &istat); data[0] = hxd_pst_gwe_lner; BnkfPutM ("HXD:PST:GWEL_LENERROR", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_gmn_call; fits_read_col_usht(fp, colnum[HXD_PST_GMN_CALL], irow, firstelem, nelements, nulval, &hxd_pst_gmn_call, &anynul, &istat); data[0] = hxd_pst_gmn_call; BnkfPutM ("HXD:PST:GMON_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_gmn_cnt; fits_read_col_usht(fp, colnum[HXD_PST_GMN_CNT], irow, firstelem, nelements, nulval, &hxd_pst_gmn_cnt, &anynul, &istat); data[0] = hxd_pst_gmn_cnt; BnkfPutM ("HXD:PST:GMON_COUNT", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_pmn_call; fits_read_col_usht(fp, colnum[HXD_PST_PMN_CALL], irow, firstelem, nelements, nulval, &hxd_pst_pmn_call, &anynul, &istat); data[0] = hxd_pst_pmn_call; BnkfPutM ("HXD:PST:PMON_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_pmn_disc; fits_read_col_usht(fp, colnum[HXD_PST_PMN_DISC], irow, firstelem, nelements, nulval, &hxd_pst_pmn_disc, &anynul, &istat); data[0] = hxd_pst_pmn_disc; BnkfPutM ("HXD:PST:PMON_DISCARD", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_ghk_call; fits_read_col_usht(fp, colnum[HXD_PST_GHK_CALL], irow, firstelem, nelements, nulval, &hxd_pst_ghk_call, &anynul, &istat); data[0] = hxd_pst_ghk_call; BnkfPutM ("HXD:PST:GHK_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_ghk_cnt; fits_read_col_usht(fp, colnum[HXD_PST_GHK_CNT], irow, firstelem, nelements, nulval, &hxd_pst_ghk_cnt, &anynul, &istat); data[0] = hxd_pst_ghk_cnt; BnkfPutM ("HXD:PST:GHK_COUNT", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_phk_call; fits_read_col_usht(fp, colnum[HXD_PST_PHK_CALL], irow, firstelem, nelements, nulval, &hxd_pst_phk_call, &anynul, &istat); data[0] = hxd_pst_phk_call; BnkfPutM ("HXD:PST:PHK_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_phk_disc; fits_read_col_usht(fp, colnum[HXD_PST_PHK_DISC], irow, firstelem, nelements, nulval, &hxd_pst_phk_disc, &anynul, &istat); data[0] = hxd_pst_phk_disc; BnkfPutM ("HXD:PST:PHK_DISCARD", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_gbst_call; fits_read_col_usht(fp, colnum[HXD_PST_GBST_CALL], irow, firstelem, nelements, nulval, &hxd_pst_gbst_call, &anynul, &istat); data[0] = hxd_pst_gbst_call; BnkfPutM ("HXD:PST:GBST_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_gbst_cnt; fits_read_col_usht(fp, colnum[HXD_PST_GBST_CNT], irow, firstelem, nelements, nulval, &hxd_pst_gbst_cnt, &anynul, &istat); data[0] = hxd_pst_gbst_cnt; BnkfPutM ("HXD:PST:GBST_COUNT", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_pbst_call; fits_read_col_usht(fp, colnum[HXD_PST_PBST_CALL], irow, firstelem, nelements, nulval, &hxd_pst_pbst_call, &anynul, &istat); data[0] = hxd_pst_pbst_call; BnkfPutM ("HXD:PST:PBST_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_pbst_disc; fits_read_col_usht(fp, colnum[HXD_PST_PBST_DISC], irow, firstelem, nelements, nulval, &hxd_pst_pbst_disc, &anynul, &istat); data[0] = hxd_pst_pbst_disc; BnkfPutM ("HXD:PST:PBST_DISCARD", sizeof(int)*1, data); } { unsigned int data[4]; unsigned short nulval=1; unsigned short hxd_pst_bst_cnt0; unsigned short hxd_pst_bst_cnt1; unsigned short hxd_pst_bst_cnt2; unsigned short hxd_pst_bst_cnt3; fits_read_col_usht(fp, colnum[HXD_PST_BST_CNT0], irow, firstelem, nelements, nulval, &hxd_pst_bst_cnt0, &anynul, &istat); data[0] = hxd_pst_bst_cnt0; fits_read_col_usht(fp, colnum[HXD_PST_BST_CNT1], irow, firstelem, nelements, nulval, &hxd_pst_bst_cnt1, &anynul, &istat); data[1] = hxd_pst_bst_cnt1; fits_read_col_usht(fp, colnum[HXD_PST_BST_CNT2], irow, firstelem, nelements, nulval, &hxd_pst_bst_cnt2, &anynul, &istat); data[2] = hxd_pst_bst_cnt2; fits_read_col_usht(fp, colnum[HXD_PST_BST_CNT3], irow, firstelem, nelements, nulval, &hxd_pst_bst_cnt3, &anynul, &istat); data[3] = hxd_pst_bst_cnt3; BnkfPutM ("HXD:PST:BST_CNT_TPU", sizeof(int)*4, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_bst_curmd; fits_read_col_usht(fp, colnum[HXD_PST_BST_CURMD], irow, firstelem, nelements, nulval, &hxd_pst_bst_curmd, &anynul, &istat); data[0] = hxd_pst_bst_curmd; BnkfPutM ("HXD:PST:BST_CURR_BD", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_cmd_rjct; fits_read_col_usht(fp, colnum[HXD_PST_CMD_RJCT], irow, firstelem, nelements, nulval, &hxd_pst_cmd_rjct, &anynul, &istat); data[0] = hxd_pst_cmd_rjct; BnkfPutM ("HXD:PST:CMD_RJT_CNT", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_gtr_call; fits_read_col_usht(fp, colnum[HXD_PST_GTR_CALL], irow, firstelem, nelements, nulval, &hxd_pst_gtr_call, &anynul, &istat); data[0] = hxd_pst_gtr_call; BnkfPutM ("HXD:PST:GTRN_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_gtr_lner; fits_read_col_usht(fp, colnum[HXD_PST_GTR_LNER], irow, firstelem, nelements, nulval, &hxd_pst_gtr_lner, &anynul, &istat); data[0] = hxd_pst_gtr_lner; BnkfPutM ("HXD:PST:GTRN_LENERROR", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_ptr_call; fits_read_col_usht(fp, colnum[HXD_PST_PTR_CALL], irow, firstelem, nelements, nulval, &hxd_pst_ptr_call, &anynul, &istat); data[0] = hxd_pst_ptr_call; BnkfPutM ("HXD:PST:PTRN_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_ptr_disc; fits_read_col_usht(fp, colnum[HXD_PST_PTR_DISC], irow, firstelem, nelements, nulval, &hxd_pst_ptr_disc, &anynul, &istat); data[0] = hxd_pst_ptr_disc; BnkfPutM ("HXD:PST:PTRN_DISCARD", sizeof(int)*1, data); } { unsigned int data[4]; unsigned short nulval=1; unsigned short hxd_pst_trn_cnt0; unsigned short hxd_pst_trn_cnt1; unsigned short hxd_pst_trn_cnt2; unsigned short hxd_pst_trn_cnt3; fits_read_col_usht(fp, colnum[HXD_PST_TRN_CNT0], irow, firstelem, nelements, nulval, &hxd_pst_trn_cnt0, &anynul, &istat); data[0] = hxd_pst_trn_cnt0; fits_read_col_usht(fp, colnum[HXD_PST_TRN_CNT1], irow, firstelem, nelements, nulval, &hxd_pst_trn_cnt1, &anynul, &istat); data[1] = hxd_pst_trn_cnt1; fits_read_col_usht(fp, colnum[HXD_PST_TRN_CNT2], irow, firstelem, nelements, nulval, &hxd_pst_trn_cnt2, &anynul, &istat); data[2] = hxd_pst_trn_cnt2; fits_read_col_usht(fp, colnum[HXD_PST_TRN_CNT3], irow, firstelem, nelements, nulval, &hxd_pst_trn_cnt3, &anynul, &istat); data[3] = hxd_pst_trn_cnt3; BnkfPutM ("HXD:PST:TRN_COUNT", sizeof(int)*4, data); } { unsigned int data[1]; unsigned char nulval=1; unsigned char hxd_pst_gb_flg; fits_read_col_byt(fp, colnum[HXD_PST_GB_FLG], irow, firstelem, nelements, nulval, &hxd_pst_gb_flg, &anynul, &istat); data[0] = hxd_pst_gb_flg; BnkfPutM ("HXD:PST:GB_FLG", sizeof(int)*1, data); } { unsigned int data[1]; unsigned char nulval=1; unsigned char hxd_pst_gb_frz; fits_read_col_byt(fp, colnum[HXD_PST_GB_FRZ], irow, firstelem, nelements, nulval, &hxd_pst_gb_frz, &anynul, &istat); data[0] = hxd_pst_gb_frz; BnkfPutM ("HXD:PST:GB_FRZ", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_phsf_seq; fits_read_col_usht(fp, colnum[HXD_PST_PHSF_SEQ], irow, firstelem, nelements, nulval, &hxd_pst_phsf_seq, &anynul, &istat); data[0] = hxd_pst_phsf_seq; BnkfPutM ("HXD:PST:PHSF_SEQ", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_phsf_call; fits_read_col_usht(fp, colnum[HXD_PST_PHSF_CALL], irow, firstelem, nelements, nulval, &hxd_pst_phsf_call, &anynul, &istat); data[0] = hxd_pst_phsf_call; BnkfPutM ("HXD:PST:PHSF_CALL", sizeof(int)*1, data); } { unsigned int data[1]; unsigned short nulval=1; unsigned short hxd_pst_phsf_disc; fits_read_col_usht(fp, colnum[HXD_PST_PHSF_DISC], irow, firstelem, nelements, nulval, &hxd_pst_phsf_disc, &anynul, &istat); data[0] = hxd_pst_phsf_disc; BnkfPutM ("HXD:PST:PHSF_DISCARD", sizeof(int)*1, data); } { unsigned int data[2]; unsigned int nulval=1; unsigned int hxd_pst_phsf_c0; unsigned int hxd_pst_phsf_c1; fits_read_col_uint(fp, colnum[HXD_PST_PHSF_C0], irow, firstelem, nelements, nulval, &hxd_pst_phsf_c0, &anynul, &istat); data[0] = hxd_pst_phsf_c0; fits_read_col_uint(fp, colnum[HXD_PST_PHSF_C1], irow, firstelem, nelements, nulval, &hxd_pst_phsf_c1, &anynul, &istat); data[1] = hxd_pst_phsf_c1; BnkfPutM ("HXD:PST:PHSF_COUNTER", sizeof(int)*2, data); } { unsigned int data[2]; unsigned int nulval=1; unsigned int hxd_pst_phsf_ps0; unsigned int hxd_pst_phsf_ps1; fits_read_col_uint(fp, colnum[HXD_PST_PHSF_PS0], irow, firstelem, nelements, nulval, &hxd_pst_phsf_ps0, &anynul, &istat); data[0] = hxd_pst_phsf_ps0; fits_read_col_uint(fp, colnum[HXD_PST_PHSF_PS1], irow, firstelem, nelements, nulval, &hxd_pst_phsf_ps1, &anynul, &istat); data[1] = hxd_pst_phsf_ps1; BnkfPutM ("HXD:PST:PHSF_PSEUD", sizeof(int)*2, data); } { unsigned int data[4]; unsigned short nulval=1; unsigned short hxd_pst_uni_dis0; unsigned short hxd_pst_uni_dis1; unsigned short hxd_pst_uni_dis2; unsigned short hxd_pst_uni_dis3; fits_read_col_usht(fp, colnum[HXD_PST_UNI_DIS0], irow, firstelem, nelements, nulval, &hxd_pst_uni_dis0, &anynul, &istat); data[0] = hxd_pst_uni_dis0; fits_read_col_usht(fp, colnum[HXD_PST_UNI_DIS1], irow, firstelem, nelements, nulval, &hxd_pst_uni_dis1, &anynul, &istat); data[1] = hxd_pst_uni_dis1; fits_read_col_usht(fp, colnum[HXD_PST_UNI_DIS2], irow, firstelem, nelements, nulval, &hxd_pst_uni_dis2, &anynul, &istat); data[2] = hxd_pst_uni_dis2; fits_read_col_usht(fp, colnum[HXD_PST_UNI_DIS3], irow, firstelem, nelements, nulval, &hxd_pst_uni_dis3, &anynul, &istat); data[3] = hxd_pst_uni_dis3; BnkfPutM ("HXD:PST:EVSEL_UNI_DISCD", sizeof(int)*4, data); } { unsigned int data[16]; unsigned int nulval=1; unsigned int hxd_pst_2d_dis0; unsigned int hxd_pst_2d_dis1; unsigned int hxd_pst_2d_dis2; unsigned int hxd_pst_2d_dis3; unsigned int hxd_pst_2d_dis4; unsigned int hxd_pst_2d_dis5; unsigned int hxd_pst_2d_dis6; unsigned int hxd_pst_2d_dis7; unsigned int hxd_pst_2d_dis8; unsigned int hxd_pst_2d_dis9; unsigned int hxd_pst_2d_dis10; unsigned int hxd_pst_2d_dis11; unsigned int hxd_pst_2d_dis12; unsigned int hxd_pst_2d_dis13; unsigned int hxd_pst_2d_dis14; unsigned int hxd_pst_2d_dis15; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS0], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis0, &anynul, &istat); data[0] = hxd_pst_2d_dis0; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS1], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis1, &anynul, &istat); data[1] = hxd_pst_2d_dis1; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS2], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis2, &anynul, &istat); data[2] = hxd_pst_2d_dis2; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS3], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis3, &anynul, &istat); data[3] = hxd_pst_2d_dis3; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS4], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis4, &anynul, &istat); data[4] = hxd_pst_2d_dis4; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS5], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis5, &anynul, &istat); data[5] = hxd_pst_2d_dis5; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS6], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis6, &anynul, &istat); data[6] = hxd_pst_2d_dis6; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS7], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis7, &anynul, &istat); data[7] = hxd_pst_2d_dis7; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS8], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis8, &anynul, &istat); data[8] = hxd_pst_2d_dis8; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS9], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis9, &anynul, &istat); data[9] = hxd_pst_2d_dis9; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS10], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis10, &anynul, &istat); data[10] = hxd_pst_2d_dis10; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS11], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis11, &anynul, &istat); data[11] = hxd_pst_2d_dis11; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS12], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis12, &anynul, &istat); data[12] = hxd_pst_2d_dis12; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS13], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis13, &anynul, &istat); data[13] = hxd_pst_2d_dis13; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS14], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis14, &anynul, &istat); data[14] = hxd_pst_2d_dis14; fits_read_col_uint(fp, colnum[HXD_PST_2D_DIS15], irow, firstelem, nelements, nulval, &hxd_pst_2d_dis15, &anynul, &istat); data[15] = hxd_pst_2d_dis15; BnkfPutM ("HXD:PST:EVSEL_2D_DISCD", sizeof(int)*16, data); } { unsigned int data[16]; unsigned int nulval=1; unsigned int hxd_pst_fl_dis0; unsigned int hxd_pst_evsel_fl_dis1; unsigned int hxd_pst_fl_dis2; unsigned int hxd_pst_fl_dis3; unsigned int hxd_pst_fl_dis4; unsigned int hxd_pst_fl_dis5; unsigned int hxd_pst_fl_dis6; unsigned int hxd_pst_flg_dis7; unsigned int hxd_pst_fl_dis8; unsigned int hxd_pst_fl_dis9; unsigned int hxd_pst_fl_dis10; unsigned int hxd_pst_fl_dis11; unsigned int hxd_pst_fl_dis12; unsigned int hxd_pst_fl_dis13; unsigned int hxd_pst_fl_dis14; unsigned int hxd_pst_fl_dis15; fits_read_col_uint(fp, colnum[HXD_PST_FL_DIS0], irow, firstelem, nelements, nulval, &hxd_pst_fl_dis0, &anynul, &istat); data[0] = hxd_pst_fl_dis0; fits_read_col_uint(fp, colnum[HXD_PST_EVSEL_FL_DIS1], irow, firstelem, nelements, nulval, &hxd_pst_evsel_fl_dis1, &anynul, &istat); data[1] = hxd_pst_evsel_fl_dis1; fits_read_col_uint(fp, colnum[HXD_PST_FL_DIS2], irow, firstelem, nelements, nulval, &hxd_pst_fl_dis2, &anynul, &istat); data[2] = hxd_pst_fl_dis2; fits_read_col_uint(fp, colnum[HXD_PST_FL_DIS3], irow, firstelem, nelements, nulval, &hxd_pst_fl_dis3, &anynul, &istat); data[3] = hxd_pst_fl_dis3; fits_read_col_uint(fp, colnum[HXD_PST_FL_DIS4], irow, firstelem, nelements, nulval, &hxd_pst_fl_dis4, &anynul, &istat); data[4] = hxd_pst_fl_dis4; fits_read_col_uint(fp, colnum[HXD_PST_FL_DIS5], irow, firstelem, nelements, nulval, &hxd_pst_fl_dis5, &anynul, &istat); data[5] = hxd_pst_fl_dis5; fits_read_col_uint(fp, colnum[HXD_PST_FL_DIS6], irow, firstelem, nelements, nulval, &hxd_pst_fl_dis6, &anynul, &istat); data[6] = hxd_pst_fl_dis6; fits_read_col_uint(fp, colnum[HXD_PST_FLG_DIS7], irow, firstelem, nelements, nulval, &hxd_pst_flg_dis7, &anynul, &istat); data[7] = hxd_pst_flg_dis7; fits_read_col_uint(fp, colnum[HXD_PST_FL_DIS8], irow, firstelem, nelements, nulval, &hxd_pst_fl_dis8, &anynul, &istat); data[8] = hxd_pst_fl_dis8; fits_read_col_uint(fp, colnum[HXD_PST_FL_DIS9], irow, firstelem, nelements, nulval, &hxd_pst_fl_dis9, &anynul, &istat); data[9] = hxd_pst_fl_dis9; fits_read_col_uint(fp, colnum[HXD_PST_FL_DIS10], irow, firstelem, nelements, nulval, &hxd_pst_fl_dis10, &anynul, &istat); data[10] = hxd_pst_fl_dis10; fits_read_col_uint(fp, colnum[HXD_PST_FL_DIS11], irow, firstelem, nelements, nulval, &hxd_pst_fl_dis11, &anynul, &istat); data[11] = hxd_pst_fl_dis11; fits_read_col_uint(fp, colnum[HXD_PST_FL_DIS12], irow, firstelem, nelements, nulval, &hxd_pst_fl_dis12, &anynul, &istat); data[12] = hxd_pst_fl_dis12; fits_read_col_uint(fp, colnum[HXD_PST_FL_DIS13], irow, firstelem, nelements, nulval, &hxd_pst_fl_dis13, &anynul, &istat); data[13] = hxd_pst_fl_dis13; fits_read_col_uint(fp, colnum[HXD_PST_FL_DIS14], irow, firstelem, nelements, nulval, &hxd_pst_fl_dis14, &anynul, &istat); data[14] = hxd_pst_fl_dis14; fits_read_col_uint(fp, colnum[HXD_PST_FL_DIS15], irow, firstelem, nelements, nulval, &hxd_pst_fl_dis15, &anynul, &istat); data[15] = hxd_pst_fl_dis15; BnkfPutM ("HXD:PST:EVSEL_FLG_DISCD", sizeof(int)*16, data); } { unsigned int data[16]; unsigned int nulval=1; unsigned int hxd_pst_tr_dis0; unsigned int hxd_pst_tr_dis1; unsigned int hxd_pst_tr_dis2; unsigned int hxd_pst_tr_dis3; unsigned int hxd_pst_tr_dis4; unsigned int hxd_pst_tr_dis5; unsigned int hxd_pst_tr_dis6; unsigned int hxd_pst_tr_dis7; unsigned int hxd_pst_tr_dis8; unsigned int hxd_pst_tr_dis9; unsigned int hxd_pst_tr_dis10; unsigned int hxd_pst_tr_dis11; unsigned int hxd_pst_tr_dis12; unsigned int hxd_pst_tr_dis13; unsigned int hxd_pst_tr_dis14; unsigned int hxd_pst_tr_dis15; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS0], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis0, &anynul, &istat); data[0] = hxd_pst_tr_dis0; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS1], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis1, &anynul, &istat); data[1] = hxd_pst_tr_dis1; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS2], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis2, &anynul, &istat); data[2] = hxd_pst_tr_dis2; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS3], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis3, &anynul, &istat); data[3] = hxd_pst_tr_dis3; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS4], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis4, &anynul, &istat); data[4] = hxd_pst_tr_dis4; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS5], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis5, &anynul, &istat); data[5] = hxd_pst_tr_dis5; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS6], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis6, &anynul, &istat); data[6] = hxd_pst_tr_dis6; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS7], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis7, &anynul, &istat); data[7] = hxd_pst_tr_dis7; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS8], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis8, &anynul, &istat); data[8] = hxd_pst_tr_dis8; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS9], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis9, &anynul, &istat); data[9] = hxd_pst_tr_dis9; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS10], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis10, &anynul, &istat); data[10] = hxd_pst_tr_dis10; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS11], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis11, &anynul, &istat); data[11] = hxd_pst_tr_dis11; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS12], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis12, &anynul, &istat); data[12] = hxd_pst_tr_dis12; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS13], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis13, &anynul, &istat); data[13] = hxd_pst_tr_dis13; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS14], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis14, &anynul, &istat); data[14] = hxd_pst_tr_dis14; fits_read_col_uint(fp, colnum[HXD_PST_TR_DIS15], irow, firstelem, nelements, nulval, &hxd_pst_tr_dis15, &anynul, &istat); data[15] = hxd_pst_tr_dis15; BnkfPutM ("HXD:PST:EVSEL_TRG_DISCD", sizeof(int)*16, data); } { unsigned int data[16]; unsigned int nulval=1; unsigned int hxd_pst_ht_dis0; unsigned int hxd_pst_ht_dis1; unsigned int hxd_pst_ht_dis2; unsigned int hxd_pst_ht_dis3; unsigned int hxd_pst_ht_dis4; unsigned int hxd_pst_ht_dis5; unsigned int hxd_pst_ht_dis6; unsigned int hxd_pst_ht_dis7; unsigned int hxd_pst_ht_dis8; unsigned int hxd_pst_ht_dis9; unsigned int hxd_pst_ht_dis10; unsigned int hxd_pst_ht_dis11; unsigned int hxd_pst_ht_dis12; unsigned int hxd_pst_ht_dis13; unsigned int hxd_pst_ht_dis14; unsigned int hxd_pst_ht_dis15; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS0], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis0, &anynul, &istat); data[0] = hxd_pst_ht_dis0; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS1], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis1, &anynul, &istat); data[1] = hxd_pst_ht_dis1; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS2], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis2, &anynul, &istat); data[2] = hxd_pst_ht_dis2; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS3], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis3, &anynul, &istat); data[3] = hxd_pst_ht_dis3; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS4], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis4, &anynul, &istat); data[4] = hxd_pst_ht_dis4; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS5], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis5, &anynul, &istat); data[5] = hxd_pst_ht_dis5; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS6], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis6, &anynul, &istat); data[6] = hxd_pst_ht_dis6; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS7], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis7, &anynul, &istat); data[7] = hxd_pst_ht_dis7; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS8], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis8, &anynul, &istat); data[8] = hxd_pst_ht_dis8; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS9], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis9, &anynul, &istat); data[9] = hxd_pst_ht_dis9; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS10], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis10, &anynul, &istat); data[10] = hxd_pst_ht_dis10; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS11], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis11, &anynul, &istat); data[11] = hxd_pst_ht_dis11; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS12], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis12, &anynul, &istat); data[12] = hxd_pst_ht_dis12; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS13], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis13, &anynul, &istat); data[13] = hxd_pst_ht_dis13; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS14], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis14, &anynul, &istat); data[14] = hxd_pst_ht_dis14; fits_read_col_uint(fp, colnum[HXD_PST_HT_DIS15], irow, firstelem, nelements, nulval, &hxd_pst_ht_dis15, &anynul, &istat); data[15] = hxd_pst_ht_dis15; BnkfPutM ("HXD:PST:EVSEL_HIT_DISCD", sizeof(int)*16, data); } { unsigned int data[16]; unsigned int nulval=1; unsigned int hxd_pst_hp_dis0; unsigned int hxd_pst_hp_dis1; unsigned int hxd_pst_hp_dis2; unsigned int hxd_pst_hp_dis3; unsigned int hxd_pst_hp_dis4; unsigned int hxd_pst_hp_dis5; unsigned int hxd_pst_hp_dis6; unsigned int hxd_pst_hp_dis7; unsigned int hxd_pst_hp_dis8; unsigned int hxd_pst_hp_dis9; unsigned int hxd_pst_hp_dis10; unsigned int hxd_pst_hp_dis11; unsigned int hxd_pst_hp_dis12; unsigned int hxd_pst_hp_dis13; unsigned int hxd_pst_hp_dis14; unsigned int hxd_pst_hp_dis15; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS0], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis0, &anynul, &istat); data[0] = hxd_pst_hp_dis0; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS1], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis1, &anynul, &istat); data[1] = hxd_pst_hp_dis1; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS2], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis2, &anynul, &istat); data[2] = hxd_pst_hp_dis2; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS3], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis3, &anynul, &istat); data[3] = hxd_pst_hp_dis3; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS4], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis4, &anynul, &istat); data[4] = hxd_pst_hp_dis4; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS5], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis5, &anynul, &istat); data[5] = hxd_pst_hp_dis5; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS6], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis6, &anynul, &istat); data[6] = hxd_pst_hp_dis6; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS7], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis7, &anynul, &istat); data[7] = hxd_pst_hp_dis7; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS8], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis8, &anynul, &istat); data[8] = hxd_pst_hp_dis8; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS9], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis9, &anynul, &istat); data[9] = hxd_pst_hp_dis9; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS10], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis10, &anynul, &istat); data[10] = hxd_pst_hp_dis10; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS11], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis11, &anynul, &istat); data[11] = hxd_pst_hp_dis11; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS12], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis12, &anynul, &istat); data[12] = hxd_pst_hp_dis12; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS13], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis13, &anynul, &istat); data[13] = hxd_pst_hp_dis13; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS14], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis14, &anynul, &istat); data[14] = hxd_pst_hp_dis14; fits_read_col_uint(fp, colnum[HXD_PST_HP_DIS15], irow, firstelem, nelements, nulval, &hxd_pst_hp_dis15, &anynul, &istat); data[15] = hxd_pst_hp_dis15; BnkfPutM ("HXD:PST:EVSEL_HITPIN_DISCD", sizeof(int)*16, data); } { unsigned int data[16]; unsigned int nulval=1; unsigned int hxd_pst_dt_dis0; unsigned int hxd_pst_dt_dis1; unsigned int hxd_pst_dt_dis2; unsigned int hxd_pst_dt_dis3; unsigned int hxd_pst_dt_dis4; unsigned int hxd_pst_dt_dis5; unsigned int hxd_pst_dt_dis6; unsigned int hxd_pst_dt_dis7; unsigned int hxd_pst_dt_dis8; unsigned int hxd_pst_dt_dis9; unsigned int hxd_pst_dt_dis10; unsigned int hxd_pst_dt_dis11; unsigned int hxd_pst_dt_dis12; unsigned int hxd_pst_dt_dis13; unsigned int hxd_pst_dt_dis14; unsigned int hxd_pst_dt_dis15; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS0], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis0, &anynul, &istat); data[0] = hxd_pst_dt_dis0; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS1], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis1, &anynul, &istat); data[1] = hxd_pst_dt_dis1; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS2], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis2, &anynul, &istat); data[2] = hxd_pst_dt_dis2; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS3], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis3, &anynul, &istat); data[3] = hxd_pst_dt_dis3; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS4], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis4, &anynul, &istat); data[4] = hxd_pst_dt_dis4; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS5], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis5, &anynul, &istat); data[5] = hxd_pst_dt_dis5; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS6], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis6, &anynul, &istat); data[6] = hxd_pst_dt_dis6; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS7], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis7, &anynul, &istat); data[7] = hxd_pst_dt_dis7; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS8], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis8, &anynul, &istat); data[8] = hxd_pst_dt_dis8; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS9], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis9, &anynul, &istat); data[9] = hxd_pst_dt_dis9; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS10], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis10, &anynul, &istat); data[10] = hxd_pst_dt_dis10; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS11], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis11, &anynul, &istat); data[11] = hxd_pst_dt_dis11; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS12], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis12, &anynul, &istat); data[12] = hxd_pst_dt_dis12; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS13], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis13, &anynul, &istat); data[13] = hxd_pst_dt_dis13; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS14], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis14, &anynul, &istat); data[14] = hxd_pst_dt_dis14; fits_read_col_uint(fp, colnum[HXD_PST_DT_DIS15], irow, firstelem, nelements, nulval, &hxd_pst_dt_dis15, &anynul, &istat); data[15] = hxd_pst_dt_dis15; BnkfPutM ("HXD:PST:EVSEL_DT_DISCD", sizeof(int)*16, data); } { unsigned int data[16]; unsigned int nulval=1; unsigned int hxd_pst_dt_sum0; unsigned int hxd_pst_dt_sum1; unsigned int hxd_pst_dt_sum2; unsigned int hxd_pst_dt_sum3; unsigned int hxd_pst_dt_sum4; unsigned int hxd_pst_dt_sum5; unsigned int hxd_pst_dt_sum6; unsigned int hxd_pst_dt_sum7; unsigned int hxd_pst_dt_sum8; unsigned int hxd_pst_dt_sum9; unsigned int hxd_pst_dt_sum10; unsigned int hxd_pst_dt_sum11; unsigned int hxd_pst_dt_sum12; unsigned int hxd_pst_dt_sum13; unsigned int hxd_pst_dt_sum14; unsigned int hxd_pst_dt_sum15; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM0], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum0, &anynul, &istat); data[0] = hxd_pst_dt_sum0; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM1], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum1, &anynul, &istat); data[1] = hxd_pst_dt_sum1; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM2], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum2, &anynul, &istat); data[2] = hxd_pst_dt_sum2; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM3], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum3, &anynul, &istat); data[3] = hxd_pst_dt_sum3; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM4], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum4, &anynul, &istat); data[4] = hxd_pst_dt_sum4; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM5], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum5, &anynul, &istat); data[5] = hxd_pst_dt_sum5; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM6], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum6, &anynul, &istat); data[6] = hxd_pst_dt_sum6; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM7], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum7, &anynul, &istat); data[7] = hxd_pst_dt_sum7; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM8], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum8, &anynul, &istat); data[8] = hxd_pst_dt_sum8; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM9], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum9, &anynul, &istat); data[9] = hxd_pst_dt_sum9; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM10], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum10, &anynul, &istat); data[10] = hxd_pst_dt_sum10; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM11], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum11, &anynul, &istat); data[11] = hxd_pst_dt_sum11; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM12], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum12, &anynul, &istat); data[12] = hxd_pst_dt_sum12; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM13], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum13, &anynul, &istat); data[13] = hxd_pst_dt_sum13; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM14], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum14, &anynul, &istat); data[14] = hxd_pst_dt_sum14; fits_read_col_uint(fp, colnum[HXD_PST_DT_SUM15], irow, firstelem, nelements, nulval, &hxd_pst_dt_sum15, &anynul, &istat); data[15] = hxd_pst_dt_sum15; BnkfPutM ("HXD:PST:EVSEL_DT_SUMT", sizeof(int)*16, data); } { unsigned int data[16]; unsigned int nulval=1; unsigned int hxd_pst_pl_dis0; unsigned int hxd_pst_pl_dis1; unsigned int hxd_pst_pl_dis2; unsigned int hxd_pst_pl_dis3; unsigned int hxd_pst_pl_dis4; unsigned int hxd_pst_pl_dis5; unsigned int hxd_pst_pl_dis6; unsigned int hxd_pst_pl_dis7; unsigned int hxd_pst_pl_dis8; unsigned int hxd_pst_pl_dis9; unsigned int hxd_pst_pl_dis10; unsigned int hxd_pst_pl_dis11; unsigned int hxd_pst_pl_dis12; unsigned int hxd_pst_pl_dis13; unsigned int hxd_pst_pl_dis14; unsigned int hxd_pst_pl_dis15; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS0], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis0, &anynul, &istat); data[0] = hxd_pst_pl_dis0; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS1], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis1, &anynul, &istat); data[1] = hxd_pst_pl_dis1; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS2], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis2, &anynul, &istat); data[2] = hxd_pst_pl_dis2; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS3], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis3, &anynul, &istat); data[3] = hxd_pst_pl_dis3; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS4], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis4, &anynul, &istat); data[4] = hxd_pst_pl_dis4; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS5], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis5, &anynul, &istat); data[5] = hxd_pst_pl_dis5; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS6], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis6, &anynul, &istat); data[6] = hxd_pst_pl_dis6; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS7], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis7, &anynul, &istat); data[7] = hxd_pst_pl_dis7; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS8], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis8, &anynul, &istat); data[8] = hxd_pst_pl_dis8; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS9], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis9, &anynul, &istat); data[9] = hxd_pst_pl_dis9; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS10], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis10, &anynul, &istat); data[10] = hxd_pst_pl_dis10; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS11], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis11, &anynul, &istat); data[11] = hxd_pst_pl_dis11; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS12], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis12, &anynul, &istat); data[12] = hxd_pst_pl_dis12; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS13], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis13, &anynul, &istat); data[13] = hxd_pst_pl_dis13; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS14], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis14, &anynul, &istat); data[14] = hxd_pst_pl_dis14; fits_read_col_uint(fp, colnum[HXD_PST_PL_DIS15], irow, firstelem, nelements, nulval, &hxd_pst_pl_dis15, &anynul, &istat); data[15] = hxd_pst_pl_dis15; BnkfPutM ("HXD:PST:EVSEL_PINLD_DISCD", sizeof(int)*16, data); } { unsigned int data[16]; unsigned int nulval=1; unsigned int hxd_pst_pt_dis0; unsigned int hxd_pst_pt_dis1; unsigned int hxd_pst_pt_dis2; unsigned int hxd_pst_pt_dis3; unsigned int hxd_pst_pt_dis4; unsigned int hxd_pst_pt_dis5; unsigned int hxd_pst_pt_dis6; unsigned int hxd_pst_pt_dis7; unsigned int hxd_pst_pt_dis8; unsigned int hxd_pst_pt_dis9; unsigned int hxd_pst_pt_dis10; unsigned int hxd_pst_pt_dis11; unsigned int hxd_pst_pt_dis12; unsigned int hxd_pst_pt_dis13; unsigned int hxd_pst_pt_dis14; unsigned int hxd_pst_pt_dis15; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS0], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis0, &anynul, &istat); data[0] = hxd_pst_pt_dis0; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS1], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis1, &anynul, &istat); data[1] = hxd_pst_pt_dis1; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS2], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis2, &anynul, &istat); data[2] = hxd_pst_pt_dis2; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS3], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis3, &anynul, &istat); data[3] = hxd_pst_pt_dis3; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS4], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis4, &anynul, &istat); data[4] = hxd_pst_pt_dis4; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS5], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis5, &anynul, &istat); data[5] = hxd_pst_pt_dis5; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS6], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis6, &anynul, &istat); data[6] = hxd_pst_pt_dis6; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS7], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis7, &anynul, &istat); data[7] = hxd_pst_pt_dis7; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS8], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis8, &anynul, &istat); data[8] = hxd_pst_pt_dis8; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS9], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis9, &anynul, &istat); data[9] = hxd_pst_pt_dis9; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS10], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis10, &anynul, &istat); data[10] = hxd_pst_pt_dis10; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS11], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis11, &anynul, &istat); data[11] = hxd_pst_pt_dis11; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS12], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis12, &anynul, &istat); data[12] = hxd_pst_pt_dis12; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS13], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis13, &anynul, &istat); data[13] = hxd_pst_pt_dis13; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS14], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis14, &anynul, &istat); data[14] = hxd_pst_pt_dis14; fits_read_col_uint(fp, colnum[HXD_PST_PT_DIS15], irow, firstelem, nelements, nulval, &hxd_pst_pt_dis15, &anynul, &istat); data[15] = hxd_pst_pt_dis15; BnkfPutM ("HXD:PST:EVSEL_PINTRG_DISCD", sizeof(int)*16, data); } { unsigned int data[16]; unsigned int nulval=1; unsigned int hxd_pst_prev_w0; unsigned int hxd_pst_prev_w1; unsigned int hxd_pst_prev_w2; unsigned int hxd_pst_prev_w3; unsigned int hxd_pst_prev_w4; unsigned int hxd_pst_prev_w5; unsigned int hxd_pst_prev_w6; unsigned int hxd_pst_prev_w7; unsigned int hxd_pst_prev_w8; unsigned int hxd_pst_prev_w9; unsigned int hxd_pst_prev_w10; unsigned int hxd_pst_prev_w11; unsigned int hxd_pst_prev_w12; unsigned int hxd_pst_prev_w13; unsigned int hxd_pst_prev_w14; unsigned int hxd_pst_prev_w15; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W0], irow, firstelem, nelements, nulval, &hxd_pst_prev_w0, &anynul, &istat); data[0] = hxd_pst_prev_w0; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W1], irow, firstelem, nelements, nulval, &hxd_pst_prev_w1, &anynul, &istat); data[1] = hxd_pst_prev_w1; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W2], irow, firstelem, nelements, nulval, &hxd_pst_prev_w2, &anynul, &istat); data[2] = hxd_pst_prev_w2; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W3], irow, firstelem, nelements, nulval, &hxd_pst_prev_w3, &anynul, &istat); data[3] = hxd_pst_prev_w3; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W4], irow, firstelem, nelements, nulval, &hxd_pst_prev_w4, &anynul, &istat); data[4] = hxd_pst_prev_w4; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W5], irow, firstelem, nelements, nulval, &hxd_pst_prev_w5, &anynul, &istat); data[5] = hxd_pst_prev_w5; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W6], irow, firstelem, nelements, nulval, &hxd_pst_prev_w6, &anynul, &istat); data[6] = hxd_pst_prev_w6; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W7], irow, firstelem, nelements, nulval, &hxd_pst_prev_w7, &anynul, &istat); data[7] = hxd_pst_prev_w7; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W8], irow, firstelem, nelements, nulval, &hxd_pst_prev_w8, &anynul, &istat); data[8] = hxd_pst_prev_w8; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W9], irow, firstelem, nelements, nulval, &hxd_pst_prev_w9, &anynul, &istat); data[9] = hxd_pst_prev_w9; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W10], irow, firstelem, nelements, nulval, &hxd_pst_prev_w10, &anynul, &istat); data[10] = hxd_pst_prev_w10; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W11], irow, firstelem, nelements, nulval, &hxd_pst_prev_w11, &anynul, &istat); data[11] = hxd_pst_prev_w11; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W12], irow, firstelem, nelements, nulval, &hxd_pst_prev_w12, &anynul, &istat); data[12] = hxd_pst_prev_w12; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W13], irow, firstelem, nelements, nulval, &hxd_pst_prev_w13, &anynul, &istat); data[13] = hxd_pst_prev_w13; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W14], irow, firstelem, nelements, nulval, &hxd_pst_prev_w14, &anynul, &istat); data[14] = hxd_pst_prev_w14; fits_read_col_uint(fp, colnum[HXD_PST_PREV_W15], irow, firstelem, nelements, nulval, &hxd_pst_prev_w15, &anynul, &istat); data[15] = hxd_pst_prev_w15; BnkfPutM ("HXD:PST:PREV_PWEL", sizeof(int)*16, data); } { unsigned int data[16]; unsigned int nulval=1; unsigned int hxd_pst_prev_n0; unsigned int hxd_pst_prev_n1; unsigned int hxd_pst_prev_n2; unsigned int hxd_pst_prev_n3; unsigned int hxd_pst_prev_n4; unsigned int hxd_pst_prev_n5; unsigned int hxd_pst_prev_n6; unsigned int hxd_pst_prev_n7; unsigned int hxd_pst_prev_n8; unsigned int hxd_pst_prev_n9; unsigned int hxd_pst_prev_n10; unsigned int hxd_pst_prev_n11; unsigned int hxd_pst_prev_n12; unsigned int hxd_pst_prev_n13; unsigned int hxd_pst_prev_n14; unsigned int hxd_pst_prev_n15; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N0], irow, firstelem, nelements, nulval, &hxd_pst_prev_n0, &anynul, &istat); data[0] = hxd_pst_prev_n0; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N1], irow, firstelem, nelements, nulval, &hxd_pst_prev_n1, &anynul, &istat); data[1] = hxd_pst_prev_n1; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N2], irow, firstelem, nelements, nulval, &hxd_pst_prev_n2, &anynul, &istat); data[2] = hxd_pst_prev_n2; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N3], irow, firstelem, nelements, nulval, &hxd_pst_prev_n3, &anynul, &istat); data[3] = hxd_pst_prev_n3; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N4], irow, firstelem, nelements, nulval, &hxd_pst_prev_n4, &anynul, &istat); data[4] = hxd_pst_prev_n4; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N5], irow, firstelem, nelements, nulval, &hxd_pst_prev_n5, &anynul, &istat); data[5] = hxd_pst_prev_n5; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N6], irow, firstelem, nelements, nulval, &hxd_pst_prev_n6, &anynul, &istat); data[6] = hxd_pst_prev_n6; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N7], irow, firstelem, nelements, nulval, &hxd_pst_prev_n7, &anynul, &istat); data[7] = hxd_pst_prev_n7; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N8], irow, firstelem, nelements, nulval, &hxd_pst_prev_n8, &anynul, &istat); data[8] = hxd_pst_prev_n8; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N9], irow, firstelem, nelements, nulval, &hxd_pst_prev_n9, &anynul, &istat); data[9] = hxd_pst_prev_n9; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N10], irow, firstelem, nelements, nulval, &hxd_pst_prev_n10, &anynul, &istat); data[10] = hxd_pst_prev_n10; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N11], irow, firstelem, nelements, nulval, &hxd_pst_prev_n11, &anynul, &istat); data[11] = hxd_pst_prev_n11; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N12], irow, firstelem, nelements, nulval, &hxd_pst_prev_n12, &anynul, &istat); data[12] = hxd_pst_prev_n12; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N13], irow, firstelem, nelements, nulval, &hxd_pst_prev_n13, &anynul, &istat); data[13] = hxd_pst_prev_n13; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N14], irow, firstelem, nelements, nulval, &hxd_pst_prev_n14, &anynul, &istat); data[14] = hxd_pst_prev_n14; fits_read_col_uint(fp, colnum[HXD_PST_PREV_N15], irow, firstelem, nelements, nulval, &hxd_pst_prev_n15, &anynul, &istat); data[15] = hxd_pst_prev_n15; BnkfPutM ("HXD:PST:PREV_NON_EXIST", sizeof(int)*16, data); } { unsigned int data[16]; unsigned int nulval=1; unsigned int hxd_pst_prev_i0; unsigned int hxd_pst_prev_i1; unsigned int hxd_pst_prev_i2; unsigned int hxd_pst_prev_i3; unsigned int hxd_pst_prev_i4; unsigned int hxd_pst_prev_i5; unsigned int hxd_pst_prev_i6; unsigned int hxd_pst_prev_i7; unsigned int hxd_pst_prev_i8; unsigned int hxd_pst_prev_i9; unsigned int hxd_pst_prev_i10; unsigned int hxd_pst_prev_i11; unsigned int hxd_pst_prev_i12; unsigned int hxd_pst_prev_i13; unsigned int hxd_pst_prev_i14; unsigned int hxd_pst_prev_i15; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I0], irow, firstelem, nelements, nulval, &hxd_pst_prev_i0, &anynul, &istat); data[0] = hxd_pst_prev_i0; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I1], irow, firstelem, nelements, nulval, &hxd_pst_prev_i1, &anynul, &istat); data[1] = hxd_pst_prev_i1; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I2], irow, firstelem, nelements, nulval, &hxd_pst_prev_i2, &anynul, &istat); data[2] = hxd_pst_prev_i2; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I3], irow, firstelem, nelements, nulval, &hxd_pst_prev_i3, &anynul, &istat); data[3] = hxd_pst_prev_i3; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I4], irow, firstelem, nelements, nulval, &hxd_pst_prev_i4, &anynul, &istat); data[4] = hxd_pst_prev_i4; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I5], irow, firstelem, nelements, nulval, &hxd_pst_prev_i5, &anynul, &istat); data[5] = hxd_pst_prev_i5; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I6], irow, firstelem, nelements, nulval, &hxd_pst_prev_i6, &anynul, &istat); data[6] = hxd_pst_prev_i6; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I7], irow, firstelem, nelements, nulval, &hxd_pst_prev_i7, &anynul, &istat); data[7] = hxd_pst_prev_i7; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I8], irow, firstelem, nelements, nulval, &hxd_pst_prev_i8, &anynul, &istat); data[8] = hxd_pst_prev_i8; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I9], irow, firstelem, nelements, nulval, &hxd_pst_prev_i9, &anynul, &istat); data[9] = hxd_pst_prev_i9; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I10], irow, firstelem, nelements, nulval, &hxd_pst_prev_i10, &anynul, &istat); data[10] = hxd_pst_prev_i10; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I11], irow, firstelem, nelements, nulval, &hxd_pst_prev_i11, &anynul, &istat); data[11] = hxd_pst_prev_i11; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I12], irow, firstelem, nelements, nulval, &hxd_pst_prev_i12, &anynul, &istat); data[12] = hxd_pst_prev_i12; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I13], irow, firstelem, nelements, nulval, &hxd_pst_prev_i13, &anynul, &istat); data[13] = hxd_pst_prev_i13; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I14], irow, firstelem, nelements, nulval, &hxd_pst_prev_i14, &anynul, &istat); data[14] = hxd_pst_prev_i14; fits_read_col_uint(fp, colnum[HXD_PST_PREV_I15], irow, firstelem, nelements, nulval, &hxd_pst_prev_i15, &anynul, &istat); data[15] = hxd_pst_prev_i15; BnkfPutM ("HXD:PST:PREV_INVAL", sizeof(int)*16, data); } { unsigned int data[16]; unsigned int nulval=1; unsigned int hxd_pst_dt_ps0; unsigned int hxd_pst_dt_ps1; unsigned int hxd_pst_dt_ps2; unsigned int hxd_pst_dt_ps3; unsigned int hxd_pst_dt_ps4; unsigned int hxd_pst_dt_ps5; unsigned int hxd_pst_dt_ps6; unsigned int hxd_pst_dt_ps7; unsigned int hxd_pst_dt_ps8; unsigned int hxd_pst_dt_ps9; unsigned int hxd_pst_dt_ps10; unsigned int hxd_pst_dt_ps11; unsigned int hxd_pst_dt_ps12; unsigned int hxd_pst_dt_ps13; unsigned int hxd_pst_dt_ps14; unsigned int hxd_pst_dt_ps15; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS0], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps0, &anynul, &istat); data[0] = hxd_pst_dt_ps0; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS1], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps1, &anynul, &istat); data[1] = hxd_pst_dt_ps1; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS2], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps2, &anynul, &istat); data[2] = hxd_pst_dt_ps2; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS3], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps3, &anynul, &istat); data[3] = hxd_pst_dt_ps3; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS4], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps4, &anynul, &istat); data[4] = hxd_pst_dt_ps4; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS5], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps5, &anynul, &istat); data[5] = hxd_pst_dt_ps5; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS6], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps6, &anynul, &istat); data[6] = hxd_pst_dt_ps6; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS7], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps7, &anynul, &istat); data[7] = hxd_pst_dt_ps7; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS8], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps8, &anynul, &istat); data[8] = hxd_pst_dt_ps8; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS9], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps9, &anynul, &istat); data[9] = hxd_pst_dt_ps9; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS10], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps10, &anynul, &istat); data[10] = hxd_pst_dt_ps10; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS11], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps11, &anynul, &istat); data[11] = hxd_pst_dt_ps11; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS12], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps12, &anynul, &istat); data[12] = hxd_pst_dt_ps12; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS13], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps13, &anynul, &istat); data[13] = hxd_pst_dt_ps13; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS14], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps14, &anynul, &istat); data[14] = hxd_pst_dt_ps14; fits_read_col_uint(fp, colnum[HXD_PST_DT_PS15], irow, firstelem, nelements, nulval, &hxd_pst_dt_ps15, &anynul, &istat); data[15] = hxd_pst_dt_ps15; BnkfPutM ("HXD:PST:EVSEL_DT_PSEUD", sizeof(int)*16, data); } { unsigned int data[16]; unsigned short nulval=1; unsigned short hxd_pst_acu_ti0; unsigned short hxd_pst_acu_ti1; unsigned short hxd_pst_acu_ti2; unsigned short hxd_pst_acu_ti3; unsigned short hxd_pst_acu_ti4; unsigned short hxd_pst_acu_ti5; unsigned short hxd_pst_acu_ti6; unsigned short hxd_pst_acu_ti7; unsigned short hxd_pst_acu_ti8; unsigned short hxd_pst_acu_ti9; unsigned short hxd_pst_acu_ti10; unsigned short hxd_pst_acu_ti11; unsigned short hxd_pst_acu_ti12; unsigned short hxd_pst_acu_ti13; unsigned short hxd_pst_acu_ti14; unsigned short hxd_pst_acu_ti15; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI0], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti0, &anynul, &istat); data[0] = hxd_pst_acu_ti0; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI1], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti1, &anynul, &istat); data[1] = hxd_pst_acu_ti1; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI2], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti2, &anynul, &istat); data[2] = hxd_pst_acu_ti2; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI3], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti3, &anynul, &istat); data[3] = hxd_pst_acu_ti3; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI4], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti4, &anynul, &istat); data[4] = hxd_pst_acu_ti4; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI5], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti5, &anynul, &istat); data[5] = hxd_pst_acu_ti5; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI6], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti6, &anynul, &istat); data[6] = hxd_pst_acu_ti6; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI7], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti7, &anynul, &istat); data[7] = hxd_pst_acu_ti7; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI8], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti8, &anynul, &istat); data[8] = hxd_pst_acu_ti8; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI9], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti9, &anynul, &istat); data[9] = hxd_pst_acu_ti9; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI10], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti10, &anynul, &istat); data[10] = hxd_pst_acu_ti10; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI11], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti11, &anynul, &istat); data[11] = hxd_pst_acu_ti11; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI12], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti12, &anynul, &istat); data[12] = hxd_pst_acu_ti12; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI13], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti13, &anynul, &istat); data[13] = hxd_pst_acu_ti13; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI14], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti14, &anynul, &istat); data[14] = hxd_pst_acu_ti14; fits_read_col_usht(fp, colnum[HXD_PST_ACU_TI15], irow, firstelem, nelements, nulval, &hxd_pst_acu_ti15, &anynul, &istat); data[15] = hxd_pst_acu_ti15; BnkfPutM ("HXD:PST:EVSL_ACU_CNT", sizeof(int)*16, data); } { unsigned int data[4]; unsigned short nulval=1; unsigned short hxd_pst_bst_req0; unsigned short hxd_pst_bst_req1; unsigned short hxd_pst_bst_req2; unsigned short hxd_pst_bst_req3; fits_read_col_usht(fp, colnum[HXD_PST_BST_REQ0], irow, firstelem, nelements, nulval, &hxd_pst_bst_req0, &anynul, &istat); data[0] = hxd_pst_bst_req0; fits_read_col_usht(fp, colnum[HXD_PST_BST_REQ1], irow, firstelem, nelements, nulval, &hxd_pst_bst_req1, &anynul, &istat); data[1] = hxd_pst_bst_req1; fits_read_col_usht(fp, colnum[HXD_PST_BST_REQ2], irow, firstelem, nelements, nulval, &hxd_pst_bst_req2, &anynul, &istat); data[2] = hxd_pst_bst_req2; fits_read_col_usht(fp, colnum[HXD_PST_BST_REQ3], irow, firstelem, nelements, nulval, &hxd_pst_bst_req3, &anynul, &istat); data[3] = hxd_pst_bst_req3; BnkfPutM ("HXD:PST:BST_RQUEST_CNT", sizeof(int)*4, data); } { unsigned int data[4]; unsigned char nulval=1; unsigned char hxd_pst_tputmod0; unsigned char hxd_pst_tputmod1; unsigned char hxd_pst_tputmod2; unsigned char hxd_pst_tputmod3; fits_read_col_byt(fp, colnum[HXD_PST_TPUTMOD0], irow, firstelem, nelements, nulval, &hxd_pst_tputmod0, &anynul, &istat); data[0] = hxd_pst_tputmod0; fits_read_col_byt(fp, colnum[HXD_PST_TPUTMOD1], irow, firstelem, nelements, nulval, &hxd_pst_tputmod1, &anynul, &istat); data[1] = hxd_pst_tputmod1; fits_read_col_byt(fp, colnum[HXD_PST_TPUTMOD2], irow, firstelem, nelements, nulval, &hxd_pst_tputmod2, &anynul, &istat); data[2] = hxd_pst_tputmod2; fits_read_col_byt(fp, colnum[HXD_PST_TPUTMOD3], irow, firstelem, nelements, nulval, &hxd_pst_tputmod3, &anynul, &istat); data[3] = hxd_pst_tputmod3; BnkfPutM ("HXD:PST:TPU_TIM_MOD", sizeof(int)*4, data); } { unsigned int data[1]; unsigned char nulval=1; unsigned char hxd_pst_bst_trgf; fits_read_col_byt(fp, colnum[HXD_PST_BST_TRGF], irow, firstelem, nelements, nulval, &hxd_pst_bst_trgf, &anynul, &istat); data[0] = hxd_pst_bst_trgf; BnkfPutM ("HXD:PST:BST_TRG_FLG", sizeof(int)*1, data); } { unsigned int data[1]; unsigned char nulval=1; unsigned char hxd_pst_bst_ph_f; fits_read_col_byt(fp, colnum[HXD_PST_BST_PH_F], irow, firstelem, nelements, nulval, &hxd_pst_bst_ph_f, &anynul, &istat); data[0] = hxd_pst_bst_ph_f; BnkfPutM ("HXD:PST:BST_PH_FLG", sizeof(int)*1, data); } { unsigned int data[1]; unsigned char nulval=1; unsigned char hxd_pst_bst_wldf; fits_read_col_byt(fp, colnum[HXD_PST_BST_WLDF], irow, firstelem, nelements, nulval, &hxd_pst_bst_wldf, &anynul, &istat); data[0] = hxd_pst_bst_wldf; BnkfPutM ("HXD:PST:BST_WLD_FLG", sizeof(int)*1, data); } { unsigned int data[1]; unsigned char nulval=1; unsigned char hxd_pst_bst_psef; fits_read_col_byt(fp, colnum[HXD_PST_BST_PSEF], irow, firstelem, nelements, nulval, &hxd_pst_bst_psef, &anynul, &istat); data[0] = hxd_pst_bst_psef; BnkfPutM ("HXD:PST:BST_PSE_FLG", sizeof(int)*1, data); } { unsigned int data[1]; unsigned char nulval=1; unsigned char hxd_pst_gb_f_pat; fits_read_col_byt(fp, colnum[HXD_PST_GB_F_PAT], irow, firstelem, nelements, nulval, &hxd_pst_gb_f_pat, &anynul, &istat); data[0] = hxd_pst_gb_f_pat; BnkfPutM ("HXD:PST:GB_FLG_PAT", sizeof(int)*1, data); } { unsigned int data[1]; unsigned char nulval=1; unsigned char hxd_pst_gb_ena; fits_read_col_byt(fp, colnum[HXD_PST_GB_ENA], irow, firstelem, nelements, nulval, &hxd_pst_gb_ena, &anynul, &istat); data[0] = hxd_pst_gb_ena; BnkfPutM ("HXD:PST:GB_ENA", sizeof(int)*1, data); } if ( istat ) { fprintf(stderr, "%s: fits_read_col failed (%d)\n", pname, istat); return istat; } return ANL_OK; }
79cd0f4b5dfc39d6f7321b75373fda5951672e8b
55032e2c244ad8a516351a9c16b16ab09ee23a48
/main_acquisition/Libraries/IMU10DOF/l3gd20.c
48f994f1769edf1aa567569e89c9b938c636a6bb
[]
no_license
ul-gaul/acquisition
76ec37c98f3e217ee1d1b137a23eeb2f314cdbe9
d26c02ed46440c77a6192045b46d9845ae08ca13
refs/heads/master
2021-06-26T13:18:15.535004
2019-06-12T17:04:35
2019-06-12T17:04:35
135,636,295
1
1
null
2019-06-12T17:04:36
2018-05-31T21:18:18
null
UTF-8
C
false
false
2,521
c
l3gd20.c
/* * l3gd20.c * * Created on: Jul 1, 2018 * Author: laplace */ #include "l3gd20.h" /* Private variables */ L3GD20_scale L3GD20_INT_Scale; /* Public */ L3GD20_result L3GD20_Init(L3GD20_scale scale) { uint8_t resultData; resultData = i2c_read(L3GD20_ADDRESS_R, GYRO_REGISTER_WHO_AM_I); if (resultData != GYRO_WHO_AM_I) { /* Sensor connected is not L3GD20 */ return L3GD20_Result_Error; } /* Enable L3GD20 Power bit */ i2c_write(L3GD20_ADDRESS_W, GYRO_REGISTER_CTRL_REG1, 0xFF); /* Set L3GD20 scale */ if (scale == L3GD20_Scale_250) { i2c_write(L3GD20_ADDRESS_W, GYRO_REGISTER_CTRL_REG4, 0x00); } else if (scale == L3GD20_Scale_500) { i2c_write(L3GD20_ADDRESS_W, GYRO_REGISTER_CTRL_REG4, 0x10); } else if (scale == L3GD20_Scale_2000) { i2c_write(L3GD20_ADDRESS_W, GYRO_REGISTER_CTRL_REG4, 0x20); } /* Save scale */ L3GD20_INT_Scale = scale; /* Set high-pass filter settings */ i2c_write(L3GD20_ADDRESS_W, GYRO_REGISTER_CTRL_REG2, 0x00); /* Enable high-pass filter */ i2c_write(L3GD20_ADDRESS_W, GYRO_REGISTER_CTRL_REG5, 0x10); /* Everything OK */ return L3GD20_Result_Ok; } L3GD20_result L3GD20_Read(L3GD20_struct* L3DG20_Data) { float temp, s; unsigned char resultData; /* Read X axis */ resultData= i2c_read(L3GD20_ADDRESS_R, GYRO_REGISTER_OUT_X_L); L3DG20_Data->X = resultData; resultData = i2c_read(L3GD20_ADDRESS_R, GYRO_REGISTER_OUT_X_H); L3DG20_Data->X |= resultData << 8; /* Read Y axis */ resultData = i2c_read(L3GD20_ADDRESS_R, GYRO_REGISTER_OUT_Y_L); L3DG20_Data->Y = resultData; resultData = i2c_read(L3GD20_ADDRESS_R, GYRO_REGISTER_OUT_Y_H); L3DG20_Data->Y |= resultData << 8; /* Read Z axis */ resultData = i2c_read(L3GD20_ADDRESS_R, GYRO_REGISTER_OUT_Z_L); L3DG20_Data->Z = resultData; resultData = i2c_read(L3GD20_ADDRESS_R, GYRO_REGISTER_OUT_Z_H); L3DG20_Data->Z |= resultData << 8; /* Set sensitivity scale correction */ if (L3GD20_INT_Scale == L3GD20_Scale_250) { /* Sensitivity at 250 range = 8.75 mdps/digit */ s = GYRO_SENSITIVITY_250DPS; } else if (L3GD20_INT_Scale == L3GD20_Scale_500) { /* Sensitivity at 500 range = 17.5 mdps/digit */ s = GYRO_SENSITIVITY_500DPS; } else { /* Sensitivity at 2000 range = 70 mdps/digit */ s = GYRO_SENSITIVITY_2000DPS; } temp = (float)L3DG20_Data->X * s; L3DG20_Data->X = (int16_t) temp; temp = (float)L3DG20_Data->Y * s; L3DG20_Data->Y = (int16_t) temp; temp = (float)L3DG20_Data->Z * s; L3DG20_Data->Z = (int16_t) temp; /* Return OK */ return L3GD20_Result_Ok; }
5d2921a95e830848b7223c65ecb666f148e6d6a7
dfdce0f7ed9469ab366bb3f3b65dcd9eb59618da
/随机步法.c
e81ae16badcebc29ab9985169a7c3f05a3bd7230
[]
no_license
JJ-Peter/C_language
46c99fd7c1d93812f638e5458cf5c4012e7978d2
e00de74d7ad4aabaee5d372b2d8d1901d3bf8392
refs/heads/main
2023-03-07T06:27:21.638260
2021-02-18T06:07:23
2021-02-18T06:07:23
330,643,593
0
0
null
null
null
null
GB18030
C
false
false
2,076
c
随机步法.c
/* *Name:Random footwork *Time:2021/2/2 *Author:Peter Gu */ #include<stdio.h> #include<stdlib.h> #include<time.h> int x,y; //打印数组 void print_table(char arr[10][10]) { printf("\n"); for(y=0;y<10;y++){ for(x=0;x<10;x++){ printf("%c ",arr[x][y]); } printf("\n"); } printf("\n"); } int main(void) { //this_x this_y 当前坐标 //direction 行走方向 0,1,2,3 上右下左 //flag 行走成功标记 flag_up_fail等为对应方向行走失败标记 int this_x,this_y,direction,flag,flag_up_fail,flag_right_fail,flag_down_fail,flag_left_fail; char arr[10][10],ch; //初始化数组为'.' for(x=0;x<10;x++){ for(y=0;y<10;y++){ arr[x][y]='.'; } } srand((unsigned)time(NULL)); //寻找数组的起始位置 this_x=rand()%10; this_y=rand()%10; //开始随机行走 for(ch='A';ch<='Z';ch++){ srand((unsigned)time(NULL)+ch); flag=0; flag_up_fail=0,flag_right_fail=0,flag_down_fail=0,flag_left_fail=0; while(1){ direction=rand()%4; switch(direction){ case 0://向上 if((this_y-1)>=0 && arr[this_x][this_y-1]=='.'){ this_y -=1; arr[this_x][this_y]=ch; flag=1; } else{ flag_up_fail=1; } break; case 1://向右 if((this_x+1)<=9 && arr[this_x+1][this_y]=='.'){ this_x +=1; arr[this_x][this_y]=ch; flag=1; } else{ flag_right_fail=1; } break; case 2://向下 if((this_y+1)<=9 && arr[this_x][this_y+1]=='.'){ this_y +=1; arr[this_x][this_y]=ch; flag=1; } else{ flag_down_fail=1; } break; case 3://向左 if((this_x-1)>=0 && arr[this_x-1][this_y]=='.'){ this_x -=1; arr[this_x][this_y]=ch; flag=1; } else{ flag_left_fail=1; } break; } if(flag_up_fail==1 && flag_right_fail==1 && flag_down_fail==1 && flag_left_fail==1){ print_table(arr); //四方碰壁,提前退出for循环 } if(flag==1){ break; } } } print_table(arr); //执行完for循环后 return 0; }
a3d5817065dd8581ceb04f9c8ab550fd29bb4197
7196019973afc18f681c4c2ac0711f4065857a13
/function/pointFunction.c
a4893ab90b389dbef6d35c718e3ee535f81c4e9e
[]
no_license
yyueshui/c-learn
36b91f8f1e9cd56f5fe02c44bc9e949889289d0f
4051cedc017b0e1ab527f878fc70fd8aba372a86
refs/heads/master
2021-01-21T20:38:54.882173
2017-08-10T08:50:26
2017-08-10T08:50:26
92,265,020
0
0
null
null
null
null
UTF-8
C
false
false
406
c
pointFunction.c
// // Created by yuanyueshui on 2017/8/10. // #include <stdio.h> int max(int, int); int max(int x, int y) { return x > y ? x : y; } int main(void) { /* p 是函数指针 */ int (*p)(int, int) = max; // &可以省略 int a = 1; int b = 2; int c = 3; /* 与直接调用函数等价,d = max(max(a, b), c) */ int d = p(p(a, b), c); printf("%d", d); return 0; }
f6a11fc671aab1fab01e069a71561c3942c532df
e0d440c67a45fde17199ce14ceb156d1f3d4a1ec
/Projeto/main.c
4351a9d13a0009891641da8e222dbf8a3a23259e
[]
no_license
rlimaa/aeds-tp1
6c59fdb5b3865ce58138d7879e368f81a3298d99
f42407f5e0c8044a667e76df4cc68a4c0ddad674
refs/heads/master
2020-03-17T08:22:25.218593
2018-05-15T00:13:33
2018-05-15T00:13:33
133,436,062
0
0
null
null
null
null
ISO-8859-1
C
false
false
1,247
c
main.c
#include "TADmanipulacaoPGM.h" int main(int argc, char *argv[]) { Ponto inicio_match;//Ponto onde o match se inicia PGM *cena, *objeto;//Ponteiros para cena e objeto printf("\nLendo Imagens ..."); cena=LePGM(argv[1]);//Lê cena do primeiro argumento após o nome do executável objeto=LePGM(argv[2]);//Lê objeto do segundo argumento após o nome do executável printf("\nPronto!\n"); printf("\nAplicando o Algoritmo de Correlacao Cruzada por meio da Janela Deslizante...\n"); if((argv[4]!= NULL)&&(argv[4][0]=='1'))//decide se sera utilizada a janela deslizante ou a janela deslizante modificada inicio_match=JanelaDeslizanteMod(&(*cena), &(*objeto));//Chama a função JanelaDeslizanteMod e recebe o ponto inicial de match else inicio_match=JanelaDeslizante(&(*cena), &(*objeto));//Chama a função JanelaDeslizante e recebe o ponto inicial de match printf("\nPronto! "); printf("Ponto inicial de Match encontrado: %d %d\n\nGerando Saida...",inicio_match.x, inicio_match.y); GeraSaida(inicio_match, argv[3]);//Gera Saida.txt LiberaMemoria(cena);//Libera Memória de cena LiberaMemoria(objeto);//Libera Memória de objeto return 0;//Fim }
ea9e17d75172ca7fb0d829386e5b93e054623f48
72fda86c971fec9c5e15bd02a02fa3ee49563845
/vendor/libftm/src/vec3/ftm_vec3init.c
ff5047ce13fbc419c99fe1ddc1a08781fb831f7c
[]
no_license
cacharle/scop
f6bfca9e0744fe489ca7a3f86e30d4359da8ac5d
84a5a84861c95174e6dc4b28301fc4bcb0192069
refs/heads/master
2022-07-04T08:45:13.075590
2020-05-14T17:40:07
2020-05-14T17:40:07
null
0
0
null
null
null
null
UTF-8
C
false
false
1,057
c
ftm_vec3init.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ftm_vec3init.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/05/12 11:19:55 by charles #+# #+# */ /* Updated: 2020/05/12 11:20:53 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libftm_vec3.h" t_ftmvec3 *ftm_vec3init(t_ftmvec3 *vec3, float x, float y, float z) { vec3->v[0] = x; vec3->v[1] = y; vec3->v[2] = z; return (vec3); }
5376b303a0e7e1c321767a754ef0f2692551d27d
9de212789b13e1cc68cb3a32dfe3a8d205d1ada2
/sources/eir.c
57f5bbaa4692dab1c1d38bb985470294adb80df7
[]
no_license
aadarshasubedi/Eir
f8108f3e4f76d95645bce14cd2dc27e5e665e2fe
35d610b24f69b61dc6bf5d688481bc5b9a67b00a
refs/heads/master
2021-01-18T01:45:37.763435
2016-04-01T23:47:25
2016-04-01T23:47:25
null
0
0
null
null
null
null
UTF-8
C
false
false
26,686
c
eir.c
/* ############################################################################# ** ** Tasks list if all dev milestones tasks are done : ** ------------------------------------------------- ** ** TODO: add max text length in rendering text creation function ** TODO: redo rendering text batch using new array with swap to avoid frame time alloc ** TODO: remove macro for array definition and manipulation. write all code ! ** TODO: remove *_component suffix in struct, func and files ! ** TODO: remove all prefix eir_*_ in struct, func and files to avoid long code ** TODO: add const in function parameter when it is possible ** TODO: remove memleaks ** TODO: do :retab in all files ** TODO: split the big eir_gme_system.c function in multiple systems function ** and files. ** ** ############################################################################# */ #include <stdio.h> #include <stdarg.h> #include <stdlib.h> #include <stdbool.h> #include <stddef.h> #include "maths/eir_mth_vector.h" #include "system/eir_sys_env.h" #include "system/eir_sys_timer_func.h" #include "system/eir_sys_file_system.h" #include "system/eir_sys_memory.h" #include "system/eir_sys_joystick_func.h" #include "system/eir_sys_win_api_func.h" #include "graphics/eir_gfx_sprite.h" #include "graphics/eir_gfx_types.h" #include "graphics/eir_gfx_defines.h" #include "graphics/eir_gfx_sprite_batch.h" #include "graphics/eir_gfx_env.h" #include "graphics/eir_gfx_api_func.h" #include "graphics/eir_gfx_func.h" #include "sound/eir_snd_api_func.h" #include "sound/eir_snd_env.h" #include "game/eir_gme_env.h" #include "game/eir_gme_func.h" #include "game/eir_gme_system.h" #include "kernel/eir_ker_env.h" #include "fsm/eir_fsm_func.h" #include "physics/eir_phy_motion_func.h" const int WINDOW_WIDTH = 1024; const int WINDOW_HEIGHT = 728; const float PLAYER_FRICTION = 10.0f; const float PLAYER_SPEED = 2000.0f; static void eir_init_all_api(eir_ker_env_t * env, int width, int height) { eir_sys_win_api_init(); eir_sys_win_api_create_window(&env->sys_env, width, height); eir_gfx_api_init(); eir_snd_api_init(); eir_gfx_api_load_sprite_shaders(&env->gfx_env); eir_gfx_api_load_text_shaders(&env->gfx_env); eir_gfx_api_load_rect_shaders(&env->gfx_env); } static void eir_stop(eir_ker_env_t * env) { eir_gfx_api_unload_rect_shaders(&env->gfx_env); eir_gfx_api_unload_text_shaders(&env->gfx_env); eir_gfx_api_unload_sprite_shaders(&env->gfx_env); eir_snd_api_release(); eir_gfx_api_release(); eir_sys_win_api_destroy_window(&env->sys_env); eir_sys_win_api_release(); } static void eir_check_allocate_and_free_func() { if (!eir_sys_allocate) { eir_sys_allocate = eir_sys_default_allocate; } if (!eir_sys_free) { eir_sys_free = eir_sys_default_free; } } static void eir_render_frame_rate( eir_gfx_text_t * gfx_text, const eir_mth_vec2_t * position, float font_size, const eir_gfx_color_t * color, float elapsed_time ) { char c[32]; sprintf(c, "frame rate: %1.3f", elapsed_time); eir_gfx_modify_text(gfx_text, c, position, font_size, color); } static void eir_render_player_direction( eir_gfx_text_t * gfx_text, const eir_mth_vec2_t * position, float font_size, const eir_gfx_color_t * color, eir_gme_direction_t direction ) { if (direction == EIR_GME_DIRECTION_UP) { eir_gfx_modify_text(gfx_text, "direction: up", position, font_size, color); } else if (direction == EIR_GME_DIRECTION_UP_RIGHT) { eir_gfx_modify_text(gfx_text, "direction: up/right", position, font_size, color); } else if (direction == EIR_GME_DIRECTION_RIGHT) { eir_gfx_modify_text(gfx_text, "direction: right", position, font_size, color); } else if (direction == EIR_GME_DIRECTION_BOTTOM_RIGHT) { eir_gfx_modify_text(gfx_text, "direction: bottom/right", position, font_size, color); } else if (direction == EIR_GME_DIRECTION_BOTTOM) { eir_gfx_modify_text(gfx_text, "direction: bottom", position, font_size, color); } else if (direction == EIR_GME_DIRECTION_BOTTOM_LEFT) { eir_gfx_modify_text(gfx_text, "direction: bottom/left", position, font_size, color); } else if (direction == EIR_GME_DIRECTION_LEFT) { eir_gfx_modify_text(gfx_text, "direction: left", position, font_size, color); } else if (direction == EIR_GME_DIRECTION_UP_LEFT) { eir_gfx_modify_text(gfx_text, "direction: up/left", position, font_size, color); } else { eir_gfx_modify_text(gfx_text, "direction: unknown", position, font_size, color); } } static void eir_render_player_velocity( eir_gfx_text_t * gfx_text, const eir_mth_vec2_t * position, float font_size, const eir_gfx_color_t * color, float x, float y ) { char c [32]; sprintf(c, "velocity: (%1.3f; %1.3f)", x, y); eir_gfx_modify_text(gfx_text, c, position, font_size, color); } static void eir_set_allocate_func(eir_allocate_t allocate_func) { eir_sys_allocate = allocate_func; } static void eir_set_free_func(eir_free_t free_func) { eir_sys_free = free_func; } static void eir_init_env(eir_ker_env_t * env, int width, int height) { eir_check_allocate_and_free_func(); if (env) { eir_init_all_api(env, width, height); eir_gfx_init_env(&env->gfx_env, width, height); eir_snd_init_env(&env->snd_env); eir_fsm_init_env(&env->fsm_env); eir_sys_init_env(&env->sys_env); eir_gme_init_env(&env->gme_env); } } static eir_gme_input_controller_buffer_t * eir_get_input_controller_buffer( eir_gme_env_t * env, int controller_index ) { eir_gme_input_controller_buffer_t * input_controller_buffer = 0; if ( env && controller_index >= 0 && controller_index < EIR_GME_TOTAL_INPUT_CONTROLLER ) { input_controller_buffer = &env->input_controllers[controller_index]; } return input_controller_buffer; } static double eir_get_current_time(eir_sys_env_t * env) { double result = 0.0; if (env) { result = env->timer.last_time; } return result; } static void eir_run(eir_ker_env_t * env) { //player_t * player = &game->player; //eir_ker_env_t * env = player->env; eir_gfx_env_t * gfx_env = &env->gfx_env; eir_sys_env_t * sys_env = &env->sys_env; eir_snd_env_t * snd_env = &env->snd_env; eir_gme_env_t * gme_env = &env->gme_env; eir_fsm_env_t * fsm_env = &env->fsm_env; if (!gfx_env || !sys_env || !snd_env || !gme_env) { return; } #ifdef EIR_DEBUG eir_gfx_group_t * debug_info_group = eir_gfx_create_group(gfx_env, 0, 3, 0); eir_gfx_text_t * frame_text = 0; eir_mth_vec2_t frame_text_pos; float frame_text_font_size = 32.0f; eir_gfx_color_t frame_text_color; frame_text_pos.x = 0.0f; frame_text_pos.y = 0.0f; frame_text_color.r = 0.0f; frame_text_color.g = 1.0f; frame_text_color.b = 0.0f; frame_text_color.a = 0.7f; frame_text = eir_gfx_add_text_to_group( debug_info_group, "DEBUG", &frame_text_pos, frame_text_font_size, &frame_text_color, true, true, true ); eir_gfx_text_t * player_info_text = 0; eir_mth_vec2_t player_info_text_pos; float player_info_text_font_size = 16.0f; eir_gfx_color_t player_info_text_color; player_info_text_pos.x = 0.0f; player_info_text_pos.y = 40.0f; player_info_text_color.r = 1.0f; player_info_text_color.g = 0.0f; player_info_text_color.b = 0.0f; player_info_text_color.a = 0.7f; player_info_text = eir_gfx_add_text_to_group( debug_info_group, "DEBUG", &player_info_text_pos, player_info_text_font_size, &player_info_text_color, true, true, true ); eir_gfx_text_t * player_velocity_text = 0; eir_mth_vec2_t player_velocity_text_pos; float player_velocity_text_font_size = 16.0f; eir_gfx_color_t player_velocity_text_color; player_velocity_text_pos.x = 0.0f; player_velocity_text_pos.y = 60.0f; player_velocity_text_color.r = 1.0f; player_velocity_text_color.g = 0.0f; player_velocity_text_color.b = 0.0f; player_velocity_text_color.a = 0.7f; player_velocity_text = eir_gfx_add_text_to_group( debug_info_group, "DEBUG", &player_velocity_text_pos, player_velocity_text_font_size, &player_velocity_text_color, true, true, true ); #endif double time_per_frame = 1.0f / 60.0f; double time_since_last_update = 0.0f; eir_sys_start_timer(&sys_env->timer); eir_gme_start_all_components_systems(gme_env->curr_world); for (;;) { eir_sys_update_timer(&sys_env->timer); time_since_last_update += sys_env->timer.elapsed_time; while (time_since_last_update > time_per_frame) { time_since_last_update -= time_per_frame; if (!eir_sys_win_api_poll_all_events(gme_env, sys_env)) { return; } // UPDATE ALL SYSTEMS HERE EXCEPT RENDERING AND TIMER eir_gme_update_all_components_systems(gme_env->curr_world, time_per_frame); if (gme_env->curr_world) { eir_gfx_update_camera_view(gfx_env, &gme_env->curr_world->camera.position); } } #ifdef EIR_DEBUG if (sys_env->timer.elapsed_time > 0.033) { frame_text_color.r = 1.0f; frame_text_color.g = 0.0f; frame_text_color.b = 0.0f; frame_text_color.a = 1.0f; } else { frame_text_color.r = 0.0f; frame_text_color.g = 1.0f; frame_text_color.b = 0.0f; frame_text_color.a = 1.0f; } eir_render_frame_rate( frame_text, &frame_text_pos, frame_text_font_size, &frame_text_color, sys_env->timer.elapsed_time ); // TODO: replace hard coded 1 by player entity value or other stuff eir_render_player_velocity( player_velocity_text, &player_velocity_text_pos, player_velocity_text_font_size, &player_velocity_text_color, gme_env->curr_world->motion_params.data[1].motion_param.velocity.x, gme_env->curr_world->motion_params.data[1].motion_param.velocity.y ); eir_render_player_direction( player_info_text, &player_info_text_pos, player_info_text_font_size, &player_info_text_color, gme_env->curr_world->directions.data[1].direction ); #endif eir_gfx_api_set_clear_color(); eir_gfx_api_clear_buffer(); eir_gfx_render_all_batches(gfx_env); eir_sys_win_api_swap_buffer(sys_env); } } static void eir_release_env(eir_ker_env_t * env) { EIR_KER_LOG_MESSAGE("destroy all env"); if (env) { eir_stop(env); eir_gfx_release_env(&env->gfx_env); eir_snd_release_env(&env->snd_env); eir_fsm_release_env(&env->fsm_env); eir_sys_release_env(&env->sys_env); eir_gme_release_env(&env->gme_env); } } static void eir_display_mem_leaks() { #ifdef EIR_DEBUG EIR_SYS_LOG_ALLOCATED_ELEM; #endif } static bool validate_idle_state(void * user_data) { bool result = false; if (user_data) { eir_gme_entity_proxy_t * entity_proxy = (eir_gme_entity_proxy_t *)user_data; eir_gme_world_t * world = entity_proxy->world; eir_gme_entity_t entity = entity_proxy->entity; eir_gme_input_controller_buffer_t * pad_buffer = world->pads.data[entity].input_buffer; eir_gme_input_controller_buffer_t * keyboard_buffer = world->keyboards.data[entity].input_buffer; if (!pad_buffer->controllers[1].is_analog) { if ( keyboard_buffer && pad_buffer && !pad_buffer->controllers[1].is_connected && !keyboard_buffer->controllers[1].buttons[EIR_GME_MOVE_RIGHT_BUTTON_INDEX].pressed && !keyboard_buffer->controllers[1].buttons[EIR_GME_MOVE_LEFT_BUTTON_INDEX].pressed && !keyboard_buffer->controllers[1].buttons[EIR_GME_MOVE_DOWN_BUTTON_INDEX].pressed && !keyboard_buffer->controllers[1].buttons[EIR_GME_MOVE_UP_BUTTON_INDEX].pressed && !keyboard_buffer->controllers[1].buttons[EIR_GME_ACTION_1_BUTTON_INDEX].pressed ) { result = true; } else if ( pad_buffer && pad_buffer->controllers[1].is_connected && !pad_buffer->controllers[1].buttons[EIR_GME_MOVE_RIGHT_BUTTON_INDEX].pressed && !pad_buffer->controllers[1].buttons[EIR_GME_MOVE_LEFT_BUTTON_INDEX].pressed && !pad_buffer->controllers[1].buttons[EIR_GME_MOVE_DOWN_BUTTON_INDEX].pressed && !pad_buffer->controllers[1].buttons[EIR_GME_MOVE_UP_BUTTON_INDEX].pressed && !pad_buffer->controllers[1].buttons[EIR_GME_ACTION_1_BUTTON_INDEX].pressed ) { result = true; } } } return result; } static bool validate_move_state(void * user_data) { bool result = false; if (user_data) { eir_gme_entity_proxy_t * entity_proxy = (eir_gme_entity_proxy_t *)user_data; eir_gme_world_t * world = entity_proxy->world; eir_gme_entity_t entity = entity_proxy->entity; eir_gme_input_controller_buffer_t * pad_buffer = world->pads.data[entity].input_buffer; eir_gme_input_controller_buffer_t * keyboard_buffer = world->keyboards.data[entity].input_buffer; if ( keyboard_buffer && pad_buffer && !pad_buffer->controllers[1].is_connected && ( keyboard_buffer->controllers[1].buttons[EIR_GME_MOVE_RIGHT_BUTTON_INDEX].pressed || keyboard_buffer->controllers[1].buttons[EIR_GME_MOVE_LEFT_BUTTON_INDEX].pressed || keyboard_buffer->controllers[1].buttons[EIR_GME_MOVE_DOWN_BUTTON_INDEX].pressed || keyboard_buffer->controllers[1].buttons[EIR_GME_MOVE_UP_BUTTON_INDEX].pressed ) ) { result = true; } else if ( pad_buffer && pad_buffer->controllers[1].is_connected && !pad_buffer->controllers[1].is_analog && ( pad_buffer->controllers[1].buttons[EIR_GME_MOVE_RIGHT_BUTTON_INDEX].pressed || pad_buffer->controllers[1].buttons[EIR_GME_MOVE_LEFT_BUTTON_INDEX].pressed || pad_buffer->controllers[1].buttons[EIR_GME_MOVE_DOWN_BUTTON_INDEX].pressed || pad_buffer->controllers[1].buttons[EIR_GME_MOVE_UP_BUTTON_INDEX].pressed ) ) { result = true; } else if ( pad_buffer && pad_buffer->controllers[1].is_connected && pad_buffer->controllers[1].is_analog && ( pad_buffer->controllers[1].left_stick_value_x || pad_buffer->controllers[1].left_stick_value_y ) ) { result = true; } } return result; } static void update_idle_state(void * user_data) { if (user_data) { eir_gme_entity_proxy_t * entity_proxy = (eir_gme_entity_proxy_t *)user_data; eir_gme_set_entity_acceleration( entity_proxy->world, entity_proxy->entity, 0.0f, 0.0f, PLAYER_SPEED, PLAYER_FRICTION ); } } static void update_move_state(void * user_data) { if (user_data) { eir_gme_entity_proxy_t * entity_proxy = (eir_gme_entity_proxy_t *)user_data; eir_gme_world_t * world = entity_proxy->world; eir_gme_entity_t entity = entity_proxy->entity; eir_gme_input_controller_buffer_t * pad_buffer = world->pads.data[entity].input_buffer; eir_gme_input_controller_buffer_t * keyboard_buffer = world->keyboards.data[entity].input_buffer; float x_velocity = 0.0f; float y_velocity = 0.0f; if (pad_buffer->controllers[1].is_analog) { x_velocity = pad_buffer->controllers[1].left_stick_value_x; y_velocity = pad_buffer->controllers[1].left_stick_value_y; } else { if ( keyboard_buffer->controllers[1].buttons[EIR_GME_MOVE_RIGHT_BUTTON_INDEX].pressed || pad_buffer->controllers[1].buttons[EIR_GME_MOVE_RIGHT_BUTTON_INDEX].pressed ) { x_velocity = 1.0f; } if ( keyboard_buffer->controllers[1].buttons[EIR_GME_MOVE_LEFT_BUTTON_INDEX].pressed || pad_buffer->controllers[1].buttons[EIR_GME_MOVE_LEFT_BUTTON_INDEX].pressed ) { x_velocity = -1.0f; } if ( keyboard_buffer->controllers[1].buttons[EIR_GME_MOVE_DOWN_BUTTON_INDEX].pressed || pad_buffer->controllers[1].buttons[EIR_GME_MOVE_DOWN_BUTTON_INDEX].pressed ) { y_velocity = 1.0f; } if ( keyboard_buffer->controllers[1].buttons[EIR_GME_MOVE_UP_BUTTON_INDEX].pressed || pad_buffer->controllers[1].buttons[EIR_GME_MOVE_UP_BUTTON_INDEX].pressed ) { y_velocity = -1.0f; } } if (eir_mth_abs(x_velocity) > 0.0f && eir_mth_abs(y_velocity) > 0.0f) { //x_velocity *= 0.707107f; //y_velocity *= 0.707107f; } eir_gme_set_entity_acceleration( world, entity, x_velocity, y_velocity, PLAYER_SPEED, PLAYER_FRICTION ); } } int main() { // INIT ENV eir_ker_env_t env; eir_init_env(&env, WINDOW_WIDTH, WINDOW_HEIGHT); eir_fsm_env_t * fsm_env = &env.fsm_env; eir_gme_env_t * gme_env = &env.gme_env; eir_gfx_env_t * gfx_env = &env.gfx_env; eir_gme_entity_proxy_t player_entity_proxy; // INIT STATE MACHINE eir_fsm_set_state_machine_capacity(fsm_env, 1); eir_fsm_state_machine_t * fsm = eir_fsm_create_state_machine(fsm_env, 10, &player_entity_proxy); eir_fsm_state_t * idle_state = eir_fsm_create_state(fsm); eir_fsm_state_t * move_state = eir_fsm_create_state(fsm); eir_fsm_state_t * end_state = eir_fsm_create_state(fsm); eir_fsm_set_begin_state(fsm, idle_state); eir_fsm_set_end_state(fsm, end_state); eir_fsm_set_state_validate_func(idle_state, validate_idle_state); eir_fsm_set_state_validate_func(move_state, validate_move_state); eir_fsm_set_state_update_func(idle_state, update_idle_state); eir_fsm_set_state_update_func(move_state, update_move_state); eir_fsm_add_state_transition(idle_state, move_state); eir_fsm_add_state_transition(move_state, idle_state); // INIT GFX ITEMS CAPACITY eir_gfx_set_image_capacity(gfx_env, 10); eir_gfx_set_texture_capacity(gfx_env, 10); eir_gfx_set_group_capacity(gfx_env, 10); // LOAD SPRITE eir_gfx_image_t * ph_atlas_image = eir_gfx_load_image(gfx_env, PLACE_HOLDER_IMAGE_PATH, false); eir_gfx_texture_t * ph_texture = eir_gfx_create_texture(gfx_env, ph_atlas_image); // COMMON STRUCT eir_mth_vec2_t position; eir_mth_vec2_t size; eir_mth_vec2_t uv_offset; eir_mth_vec2_t uv_size; eir_gfx_color_t color; // INIT WORLD ENTITIES eir_gme_set_world_capacity(gme_env, 1); eir_gme_world_t * world = eir_gme_create_world(gme_env, 10); // TEMP MAP ENTITY int col_count = 40; int row_count = 40; int tiles_count = col_count * row_count; int tile_width = 32; int tile_height = 32; int layers_count = 2; int col_count_2 = 10; int row_count_2 = 10; int tiles_count_2 = col_count_2 * row_count_2; eir_gfx_image_t * tiles_set_image = eir_gfx_load_image( gfx_env, "../resources/images/PH_tiles_set.png", false ); eir_gfx_texture_t * tiles_set_texture = eir_gfx_create_texture( gfx_env, tiles_set_image ); eir_gfx_group_t * tiles_set_group = eir_gfx_create_group(gfx_env, 1, 0, 0); eir_gfx_sprite_batch_t * tiles_set_batch = eir_gfx_add_sprite_batch_to_group( tiles_set_group, tiles_set_texture, tiles_count, true, false, true ); eir_gfx_group_t * tiles_set_group_2 = eir_gfx_create_group(gfx_env, 1, 0, 0); eir_gfx_sprite_batch_t * tiles_set_batch_2 = eir_gfx_add_sprite_batch_to_group( tiles_set_group_2, tiles_set_texture, tiles_count, true, false, true ); uv_size.x = (float)tile_width; uv_size.y = (float)tile_height; eir_gme_entity_t map_entity = eir_gme_create_world_entity(world); eir_gme_set_entity_map( world, map_entity, layers_count ); eir_gme_set_entity_map_layer( world, map_entity, tiles_set_group, tiles_set_batch, 0, col_count, row_count, tile_width, tile_height, tiles_count ); position.x = 300.0f; position.y = 300.0f; eir_gme_set_entity_map_layer( world, map_entity, tiles_set_group_2, tiles_set_batch_2, &position, col_count_2, row_count_2, tile_width, tile_height, tiles_count_2 ); int x_offset_divisor = RAND_MAX / 16; int y_offset_divisor = RAND_MAX / 15; for (int i = 0; i < col_count; ++i) { for (int j = 0; j < row_count; ++j) { int x_offset_index = rand() / x_offset_divisor; int y_offset_index = rand() / y_offset_divisor; bool navigable = true; uv_offset.x = uv_size.x * 13; //x_offset_index; uv_offset.y = uv_size.y * 4; //y_offset_index; if ( (i > (col_count / 4) && i < (col_count / 2) + (col_count / 4)) && (j > (row_count / 4) && j < (row_count / 2) + (row_count / 4)) ) { uv_offset.x = uv_size.x * 0; //x_offset_index; uv_offset.y = uv_size.y * 4; //y_offset_index; navigable = false; } eir_gme_set_entity_map_tile( world, map_entity, 0, i, j, &uv_offset, &uv_size, navigable ); } } for (int i = 0; i < col_count_2; ++i) { for (int j = 0; j < row_count_2; ++j) { int x_offset_index = rand() / x_offset_divisor; int y_offset_index = rand() / y_offset_divisor; uv_offset.x = uv_size.x * 0; //x_offset_index; uv_offset.y = uv_size.y * 0; //y_offset_index; eir_gme_set_entity_map_tile( world, map_entity, 1, i, j, &uv_offset, &uv_size, true ); } } // CREATE SPRITE eir_gfx_group_t * sprites_group = eir_gfx_create_group(gfx_env, 10, 0, 0); eir_gfx_sprite_batch_t * sprites_batch = eir_gfx_add_sprite_batch_to_group( sprites_group, ph_texture, 3, true, false, true ); position.x = 0.0f; position.y = 0.0f; size.x = 64.0f; size.y = 64.0f; uv_offset.x = 0.0f; uv_offset.y = 0.0f; uv_size.x = 64.0f; uv_size.y = 64.0f; color.r = 1.0f; color.g = 0.0f; color.b = 0.0f; color.a = 0.2f; eir_gfx_sprite_proxy_t * obj_sprite = eir_gfx_add_sprite_to_batch( sprites_batch, &position, &size, &uv_offset, &uv_size, &color, true ); position.x = 0.0f; position.y = 0.0f; size.x = 64.0f; size.y = 64.0f; uv_offset.x = 0.0f; uv_offset.y = 0.0f; uv_size.x = 64.0f; uv_size.y = 64.0f; color.r = 1.0f; color.g = 0.0f; color.b = 0.0f; color.a = 0.2f; eir_gfx_sprite_proxy_t * player_sprite = eir_gfx_add_sprite_to_batch( sprites_batch, &position, &size, &uv_offset, &uv_size, &color, true ); // CREATE RECT eir_gfx_group_t * rect_group = eir_gfx_create_group(gfx_env, 0, 0, 10); eir_gfx_rect_batch_t * rect_batch = eir_gfx_add_rect_batch_to_group( rect_group, 3, true, false, true ); position.x = 0.0f; position.y = 64.0f; size.x = 64.0f; size.y = 64.0f; uv_offset.x = 0.0f; uv_offset.y = 0.0f; uv_size.x = 64.0f; uv_size.y = 64.0f; color.r = 1.0f; color.g = 1.0f; color.b = 0.0f; color.a = 0.2f; eir_gfx_rect_proxy_t * entity_aabb_rect_proxy = eir_gfx_add_rect_to_batch( rect_batch, &position, &size, &color, true ); // PLAYER ENTITY eir_gme_entity_t entity = eir_gme_create_world_entity(world); eir_gme_set_entity_position(world, entity, 10.0f, 10.0f); eir_gme_set_entity_size(world, entity, 64, 64); eir_gme_set_entity_sprite(world, entity, player_sprite); eir_gme_set_entity_color(world, entity, 1.0f, 1.0f, 1.0f, 1.0f); eir_gme_set_entity_acceleration(world, entity, 0.0f, 0.0f, PLAYER_SPEED, PLAYER_FRICTION); eir_gme_set_entity_aabb(world, entity, 8.0f, 8.0f, 48.0f, 48.0f); eir_gme_set_entity_aabb_primitive(world, entity, entity_aabb_rect_proxy); eir_gme_set_entity_physic(world, entity, 0.5f); eir_gme_set_entity_direction(world, entity, EIR_GME_DIRECTION_BOTTOM); eir_gme_set_entity_fsm(world, entity, fsm); eir_gme_set_entity_keyboard_controller( world, entity, eir_get_input_controller_buffer(gme_env, 0) ); eir_gme_set_entity_pad_controller( world, entity, eir_get_input_controller_buffer(gme_env, 1) ); eir_gme_set_entity_map_layer_link(world, entity, map_entity, 0); eir_gme_set_entity_colliding_map_tiles(world, entity, 9); player_entity_proxy.entity = entity; player_entity_proxy.world = world; // OTHER ENTITY eir_gme_entity_t entity2 = eir_gme_create_world_entity(world); eir_gme_set_entity_position(world, entity2, 200.0f, -10.0f); eir_gme_set_entity_size(world, entity2, 64, 64); eir_gme_set_entity_sprite(world, entity2, obj_sprite); eir_gme_set_entity_color(world, entity2, 1.0f, 0.0f, 0.0f, 0.5f); eir_gme_set_entity_aabb(world, entity2, 0.0f, 0.0f, 64.0f, 64.0f); eir_gme_set_entity_physic(world, entity2, 1.0f); // SET ACTIVE STUFF eir_gme_set_active_world(gme_env, world); eir_gme_set_active_camera(world, entity, 3.0f, WINDOW_WIDTH, WINDOW_HEIGHT); // ORDER GFX GROUPS eir_gfx_set_group_index(gfx_env, tiles_set_group, 0); eir_gfx_set_group_index(gfx_env, sprites_group, 1); eir_gfx_set_group_index(gfx_env, tiles_set_group_2, 2); // RUN EIR ENGINE eir_run(&env); // RELEASE ENV eir_release_env(&env); eir_display_mem_leaks(); return 0; }
352ab68c3ebb735f36be666ce426697247a55ab0
7d86a9ba76a993351550e6a5756d7215ccb7f92a
/01-C语言/菜鸟教程C语言复习/12-递归/recursion.c
101d699d818e5083076ba3b042ee1e96ede6d792
[]
no_license
mapleleaf-nine/Embedded-software-development
2e46d8e715e9a193924219c18338f98e731c0e00
585087ec4480fb5eb1f04ba1e10aa63ef10ba60c
refs/heads/main
2023-03-31T15:15:51.462827
2021-04-02T09:10:09
2021-04-02T09:10:09
350,319,862
0
0
null
null
null
null
UTF-8
C
false
false
248
c
recursion.c
#include <stdio.h> int recursion(unsigned int i); int main() { int i = 3; printf("%d! = %d\n",i, recursion(i)); return 0; } int recursion(unsigned int i) { if (i<=1) { return 1; } return i * recursion(i - 1); }
681ed7004b6e0e3b5c226c1ae3092f8ccdb92c42
04558054b4363b695b136227b91d41a2f00b7a94
/rwProcMem33/phy_mem.c
68cd6beacda9e1559aee3d9a2464c7beeb14d86d
[]
no_license
fengjixuchui/op7t
ddc2e184c08e77d8c07b13f99e5d6504267dda5d
a4c43028ca19cef8178f74e703e577992a974619
refs/heads/dev
2023-08-26T02:12:31.039542
2021-10-18T03:38:50
2021-10-18T03:38:50
415,865,737
0
0
null
2021-10-18T03:38:41
2021-10-11T09:47:12
null
UTF-8
C
false
false
7,791
c
phy_mem.c
#include <asm/io.h> #include <asm/uaccess.h> #include <linux/fs.h> #include <linux/highmem.h> #include <linux/slab.h> #include "phy_mem.h" #include "version_control.h" #include "remote_proc_cmdline.h" #define PAGEMAP_ENTRY sizeof(uint64_t) #define GET_BIT(X, Y) (X & ((uint64_t)1 << Y)) >> Y #define GET_PFN(X) X & 0x7FFFFFFFFFFFFF const int __endian_bit = 1; #define is_bigendian() ( (*(char*)&__endian_bit) == 0 ) struct file * open_pagemap(int pid) { struct file *filp = NULL; char szFilePath[256]; memset(szFilePath, 0, sizeof(szFilePath)); snprintf(szFilePath, sizeof(szFilePath), "/proc/%d/pagemap", pid); filp = filp_open(szFilePath, O_RDONLY, 0); if (IS_ERR(filp)) { return NULL; } return filp; } size_t get_pagemap_phy_addr(struct file * lpPagemap, size_t virt_addr) { uint64_t page_size = PAGE_SIZE; uint64_t file_offset; mm_segment_t pold_fs; uint64_t read_val; unsigned char c_buf[PAGEMAP_ENTRY]; int i; unsigned char c; printk_debug(KERN_INFO "page_size %d\n", page_size); printk_debug(KERN_INFO "Big endian? %d\n", is_bigendian()); file_offset = virt_addr / page_size * PAGEMAP_ENTRY; printk_debug(KERN_INFO "Vaddr: 0x%lx, Page_size: %lld, Entry_size: %d\n", virt_addr, page_size, PAGEMAP_ENTRY); printk_debug(KERN_INFO "Reading at 0x%llx\n", (unsigned long long) file_offset); pold_fs = get_fs(); set_fs(KERNEL_DS); if (lpPagemap->f_op->llseek(lpPagemap, file_offset, SEEK_SET) == -1) { printk_debug(KERN_INFO "Failed to do llseek!"); set_fs(pold_fs); return 0; } read_val = 0; if (lpPagemap->f_op->read(lpPagemap, c_buf, PAGEMAP_ENTRY, &lpPagemap->f_pos) != PAGEMAP_ENTRY) { printk_debug(KERN_INFO "Failed to do read!"); set_fs(pold_fs); return 0; } set_fs(pold_fs); if (!is_bigendian()) { for (i = 0; i < PAGEMAP_ENTRY / 2; i++) { c = c_buf[PAGEMAP_ENTRY - i - 1]; c_buf[PAGEMAP_ENTRY - i - 1] = c_buf[i]; c_buf[i] = c; } } for (i = 0; i < PAGEMAP_ENTRY; i++) { printk_debug(KERN_INFO "[%d]0x%x ", i, c_buf[i]); read_val = (read_val << 8) + c_buf[i]; } printk_debug(KERN_INFO "\n"); printk_debug(KERN_INFO "Result: 0x%llx\n", (unsigned long long) read_val); if (GET_BIT(read_val, 63)) { uint64_t pfn = GET_PFN(read_val); printk_debug(KERN_INFO "PFN: 0x%llx (0x%llx)\n", pfn, pfn * page_size + virt_addr % page_size); return pfn * page_size + virt_addr % page_size; } else { printk_debug(KERN_INFO "Page not present\n"); } if (GET_BIT(read_val, 62)) { printk_debug(KERN_INFO "Page swapped\n"); } return 0; } void close_pagemap(struct file* lpPagemap) { filp_close(lpPagemap, NULL); } size_t get_proc_phy_addr(struct pid* proc_pid_struct, size_t virt_addr) { struct file * pFile = open_pagemap(get_proc_pid(proc_pid_struct)); size_t phy_addr = 0; printk_debug(KERN_INFO "open_pagemap %d\n", pFile); if (pFile) { phy_addr = get_pagemap_phy_addr(pFile, virt_addr); close_pagemap(pFile); } return phy_addr; } static inline int __valid_phys_addr_range(size_t addr, size_t count) { return addr + count <= __pa(high_memory); } #ifndef xlate_dev_mem_ptr #define xlate_dev_mem_ptr(p) __va(p) #endif #ifndef unxlate_dev_mem_ptr #define unxlate_dev_mem_ptr unxlate_dev_mem_ptr void __weak unxlate_dev_mem_ptr(unsigned long phys, void *addr) { } #endif size_t read_ram_physical_addr_to_kernel(size_t phy_addr, char* lpBuf, size_t read_size) { if (!__valid_phys_addr_range(phy_addr, read_size)) { printk_debug(KERN_INFO "Error in valid_phys_addr_range:0x%llx,size:%ld\n", phy_addr, read_size); return 0; } char *bounce = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!bounce) { return 0; } size_t realRead = 0; while (read_size > 0) { size_t sz = size_inside_page(phy_addr, read_size); /* * On ia64 if a page has been mapped somewhere as uncached, then * it must also be accessed uncached by the kernel or data * corruption may occur. */ char *ptr = xlate_dev_mem_ptr(phy_addr); if (!ptr) { printk_debug(KERN_INFO "Error in xlate_dev_mem_ptr:0x%llx\n", phy_addr); kfree(bounce); return realRead; } int probe = probe_kernel_read(bounce, ptr, sz); unxlate_dev_mem_ptr(phy_addr, ptr); if (probe) { kfree(bounce); return realRead; } memcpy(lpBuf, bounce, sz); lpBuf += sz; phy_addr += sz; read_size -= sz; realRead += sz; } kfree(bounce); return realRead; } size_t read_ram_physical_addr_to_user(size_t phy_addr, char* lpBuf, size_t read_size) { if (!__valid_phys_addr_range(phy_addr, read_size)) { printk_debug(KERN_INFO "Error in valid_phys_addr_range:0x%llx,size:%ld\n", phy_addr, read_size); return 0; } char *bounce = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!bounce) { return 0; } size_t realRead = 0; while (read_size > 0) { size_t sz = size_inside_page(phy_addr, read_size); /* * On ia64 if a page has been mapped somewhere as uncached, then * it must also be accessed uncached by the kernel or data * corruption may occur. */ char *ptr = xlate_dev_mem_ptr(phy_addr); if (!ptr) { printk_debug(KERN_INFO "Error in xlate_dev_mem_ptr:0x%llx\n", phy_addr); kfree(bounce); return realRead; } int probe = probe_kernel_read(bounce, ptr, sz); unxlate_dev_mem_ptr(phy_addr, ptr); if (probe) { kfree(bounce); return realRead; } unsigned long remaining = copy_to_user(lpBuf, bounce, sz); if (remaining) { printk_debug(KERN_INFO "Error in copy_to_user\n"); kfree(bounce); return realRead; } lpBuf += sz; phy_addr += sz; read_size -= sz; realRead += sz; } kfree(bounce); return realRead; } size_t write_ram_physical_addr_from_kernel(size_t phy_addr, char* lpBuf, size_t write_size) { if (!__valid_phys_addr_range(phy_addr, write_size)) { printk_debug(KERN_INFO "Error in valid_phys_addr_range:0x%llx,size:%ld\n", phy_addr, write_size); return 0; } size_t realWrite = 0; while (write_size > 0) { size_t sz = size_inside_page(phy_addr, write_size); /* * On ia64 if a page has been mapped somewhere as uncached, then * it must also be accessed uncached by the kernel or data * corruption may occur. */ char *ptr = xlate_dev_mem_ptr(phy_addr); if (!ptr) { printk_debug(KERN_INFO "Error in xlate_dev_mem_ptr:0x%llx\n", phy_addr); return realWrite; } memcpy(ptr, lpBuf, sz); unxlate_dev_mem_ptr(phy_addr, ptr); lpBuf += sz; phy_addr += sz; write_size -= sz; realWrite += sz; } return realWrite; } size_t write_ram_physical_addr_from_user(size_t phy_addr, char* lpBuf, size_t write_size) { if (!__valid_phys_addr_range(phy_addr, write_size)) { printk_debug(KERN_INFO "Error in valid_phys_addr_range:0x%llx,size:%ld\n", phy_addr, write_size); return 0; } size_t realWrite = 0; while (write_size > 0) { size_t sz = size_inside_page(phy_addr, write_size); /* * On ia64 if a page has been mapped somewhere as uncached, then * it must also be accessed uncached by the kernel or data * corruption may occur. */ char *ptr = xlate_dev_mem_ptr(phy_addr); if (!ptr) { printk_debug(KERN_INFO "Error in xlate_dev_mem_ptr:0x%llx\n", phy_addr); return realWrite; } unsigned long copied = copy_from_user(ptr, lpBuf, sz); unxlate_dev_mem_ptr(phy_addr, ptr); if (copied) { realWrite += sz - copied; printk_debug(KERN_INFO "Error in copy_from_user\n"); return realWrite; } lpBuf += sz; phy_addr += sz; write_size -= sz; realWrite += sz; } return realWrite; }
7f17436668cc6c7df8d55dc31aaca5153920452b
7664f318ed04bd0680f3d82321c18896e3ef6ad5
/src/overlays/actors/ovl_En_Mk/z_en_mk.c
314397a9ff37a13056bbe9cd1a3909e8bc19b8a0
[]
no_license
zeldaret/oot
9c80ce17f2d8fd61514b375f92ee4739b5ce9d4e
2875ab4fcf5c5f81d76353d1ee0024c9ea8d0b23
refs/heads/master
2023-08-29T05:29:31.356427
2023-08-28T22:48:52
2023-08-28T22:48:52
247,875,738
4,401
802
null
2023-09-14T13:34:38
2020-03-17T04:02:19
C
UTF-8
C
false
false
12,055
c
z_en_mk.c
/* * File: z_en_mk.c * Overlay: ovl_En_Mk * Description: Lakeside Professor */ #include "z_en_mk.h" #include "assets/objects/object_mk/object_mk.h" #define FLAGS (ACTOR_FLAG_0 | ACTOR_FLAG_3 | ACTOR_FLAG_4) void EnMk_Init(Actor* thisx, PlayState* play); void EnMk_Destroy(Actor* thisx, PlayState* play); void EnMk_Update(Actor* thisx, PlayState* play); void EnMk_Draw(Actor* thisx, PlayState* play); void EnMk_Wait(EnMk* this, PlayState* play); ActorInit En_Mk_InitVars = { ACTOR_EN_MK, ACTORCAT_NPC, FLAGS, OBJECT_MK, sizeof(EnMk), (ActorFunc)EnMk_Init, (ActorFunc)EnMk_Destroy, (ActorFunc)EnMk_Update, (ActorFunc)EnMk_Draw, }; static ColliderCylinderInit sCylinderInit = { { COLTYPE_NONE, AT_NONE, AC_ON | AC_TYPE_ENEMY, OC1_ON | OC1_TYPE_ALL, OC2_TYPE_1, COLSHAPE_CYLINDER, }, { ELEMTYPE_UNK0, { 0x00000000, 0x00, 0x00 }, { 0xFFCFFFFF, 0x00, 0x00 }, TOUCH_NONE, BUMP_ON, OCELEM_ON, }, { 30, 40, 0, { 0, 0, 0 } }, }; void EnMk_Init(Actor* thisx, PlayState* play) { EnMk* this = (EnMk*)thisx; s32 swimFlag; this->actor.minVelocityY = -4.0f; this->actor.gravity = -1.0f; ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 36.0f); SkelAnime_InitFlex(play, &this->skelAnime, &object_mk_Skel_005DF0, &object_mk_Anim_000D88, this->jointTable, this->morphTable, 13); Animation_PlayLoop(&this->skelAnime, &object_mk_Anim_000D88); Collider_InitCylinder(play, &this->collider); Collider_SetCylinder(play, &this->collider, &this->actor, &sCylinderInit); this->actor.colChkInfo.mass = 0xFF; Actor_SetScale(&this->actor, 0.01f); this->actionFunc = EnMk_Wait; this->flags = 0; this->swimFlag = 0; this->actor.targetMode = 6; if (GET_ITEMGETINF(ITEMGETINF_10)) { this->flags |= 4; } } void EnMk_Destroy(Actor* thisx, PlayState* play) { EnMk* this = (EnMk*)thisx; Collider_DestroyCylinder(play, &this->collider); } void func_80AACA40(EnMk* this, PlayState* play) { if (Actor_TextboxIsClosing(&this->actor, play)) { this->actor.flags &= ~ACTOR_FLAG_16; this->actionFunc = EnMk_Wait; } this->flags |= 1; } void func_80AACA94(EnMk* this, PlayState* play) { if (Actor_HasParent(&this->actor, play) != 0) { this->actor.parent = NULL; this->actionFunc = func_80AACA40; Interface_SetSubTimer(240); CLEAR_EVENTINF(EVENTINF_MARATHON_ACTIVE); } else { Actor_OfferGetItem(&this->actor, play, GI_EYE_DROPS, 10000.0f, 50.0f); } } void func_80AACB14(EnMk* this, PlayState* play) { if (Actor_TextboxIsClosing(&this->actor, play)) { this->actionFunc = func_80AACA94; Actor_OfferGetItem(&this->actor, play, GI_EYE_DROPS, 10000.0f, 50.0f); } } void func_80AACB6C(EnMk* this, PlayState* play) { if (Actor_ProcessTalkRequest(&this->actor, play)) { this->actionFunc = func_80AACB14; } this->flags |= 1; } void func_80AACBAC(EnMk* this, PlayState* play) { if (this->timer > 0) { this->timer--; this->actor.shape.rot.y -= 0x800; } else { this->actionFunc = func_80AACB6C; Message_ContinueTextbox(play, 0x4030); } } void func_80AACC04(EnMk* this, PlayState* play) { if (this->timer > 0) { this->timer--; } else { this->timer = 16; this->actionFunc = func_80AACBAC; Animation_Change(&this->skelAnime, &object_mk_Anim_000D88, 1.0f, 0.0f, Animation_GetLastFrame(&object_mk_Anim_000D88), ANIMMODE_LOOP, -4.0f); this->flags &= ~2; } } void func_80AACCA0(EnMk* this, PlayState* play) { if (this->timer > 0) { this->timer--; this->actor.shape.rot.y += 0x800; } else { this->timer = 120; this->actionFunc = func_80AACC04; Animation_Change(&this->skelAnime, &object_mk_Anim_000724, 1.0f, 0.0f, Animation_GetLastFrame(&object_mk_Anim_000724), ANIMMODE_LOOP, -4.0f); this->flags &= ~2; } } void func_80AACD48(EnMk* this, PlayState* play) { Player* player = GET_PLAYER(play); if ((Message_GetState(&play->msgCtx) == TEXT_STATE_EVENT) && Message_ShouldAdvance(play)) { Message_CloseTextbox(play); this->actionFunc = func_80AACCA0; play->msgCtx.msgMode = MSGMODE_PAUSED; player->exchangeItemId = EXCH_ITEM_NONE; this->timer = 16; Animation_Change(&this->skelAnime, &object_mk_Anim_000D88, 1.0f, 0.0f, Animation_GetLastFrame(&object_mk_Anim_000D88), ANIMMODE_LOOP, -4.0f); this->flags &= ~2; } this->flags |= 1; } void func_80AACE2C(EnMk* this, PlayState* play) { if ((Message_GetState(&play->msgCtx) == TEXT_STATE_EVENT) && Message_ShouldAdvance(play)) { Message_ContinueTextbox(play, 0x4001); Animation_Change(&this->skelAnime, &object_mk_Anim_000AC0, 1.0f, 0.0f, Animation_GetLastFrame(&object_mk_Anim_000AC0), ANIMMODE_ONCE, -4.0f); this->flags &= ~2; this->actionFunc = func_80AACD48; } this->flags |= 1; } void func_80AACEE8(EnMk* this, PlayState* play) { if ((Message_GetState(&play->msgCtx) == TEXT_STATE_EVENT) && Message_ShouldAdvance(play)) { Message_ContinueTextbox(play, 0x4000); Animation_Change(&this->skelAnime, &object_mk_Anim_000AC0, 1.0f, 0.0f, Animation_GetLastFrame(&object_mk_Anim_000AC0), ANIMMODE_LOOP, -4.0f); this->flags &= ~2; this->actionFunc = func_80AACE2C; } this->flags |= 1; } void func_80AACFA0(EnMk* this, PlayState* play) { if (Actor_HasParent(&this->actor, play)) { this->actor.parent = NULL; this->actionFunc = func_80AACA40; SET_ITEMGETINF(ITEMGETINF_10); } else { Actor_OfferGetItem(&this->actor, play, GI_HEART_PIECE, 10000.0f, 50.0f); } } void func_80AAD014(EnMk* this, PlayState* play) { if (Actor_TextboxIsClosing(&this->actor, play)) { this->actionFunc = func_80AACFA0; Actor_OfferGetItem(&this->actor, play, GI_HEART_PIECE, 10000.0f, 50.0f); } this->flags |= 1; } void EnMk_Wait(EnMk* this, PlayState* play) { s16 angle; s32 swimFlag; Player* player = GET_PLAYER(play); s32 playerExchangeItem; if (Actor_ProcessTalkRequest(&this->actor, play)) { playerExchangeItem = func_8002F368(play); if (this->actor.textId != 0x4018) { player->actor.textId = this->actor.textId; this->actionFunc = func_80AACA40; } else { if (INV_CONTENT(ITEM_ODD_MUSHROOM) == ITEM_EYE_DROPS) { player->actor.textId = 0x4032; this->actionFunc = func_80AACA40; } else { switch (playerExchangeItem) { case EXCH_ITEM_NONE: if (this->swimFlag >= 8) { if (GET_ITEMGETINF(ITEMGETINF_10)) { player->actor.textId = 0x4075; this->actionFunc = func_80AACA40; } else { player->actor.textId = 0x4074; this->actionFunc = func_80AAD014; this->swimFlag = 0; } } else { if (this->swimFlag == 0) { player->actor.textId = 0x4018; this->actionFunc = func_80AACA40; } else { player->actor.textId = 0x406C + this->swimFlag; this->actionFunc = func_80AACA40; } } break; case EXCH_ITEM_EYEBALL_FROG: player->actor.textId = 0x4019; this->actionFunc = func_80AACEE8; Animation_Change(&this->skelAnime, &object_mk_Anim_000368, 1.0f, 0.0f, Animation_GetLastFrame(&object_mk_Anim_000368), ANIMMODE_ONCE, -4.0f); this->flags &= ~2; gSaveContext.subTimerState = SUBTIMER_STATE_OFF; Sfx_PlaySfxCentered(NA_SE_SY_TRE_BOX_APPEAR); break; default: player->actor.textId = 0x4018; this->actionFunc = func_80AACA40; break; } } } } else { this->actor.textId = Text_GetFaceReaction(play, 0x1A); if (this->actor.textId == 0) { this->actor.textId = 0x4018; } angle = this->actor.yawTowardsPlayer - this->actor.shape.rot.y; if ((ABS(angle) < 0x2151) && (this->actor.xzDistToPlayer < 100.0f)) { func_8002F298(&this->actor, play, 100.0f, EXCH_ITEM_EYEBALL_FROG); this->flags |= 1; } } } void EnMk_Update(Actor* thisx, PlayState* play) { EnMk* this = (EnMk*)thisx; s32 pad; Vec3s vec; Player* player; s16 swimFlag; Collider_UpdateCylinder(&this->actor, &this->collider); CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base); Actor_MoveXZGravity(&this->actor); Actor_UpdateBgCheckInfo(play, &this->actor, 0.0f, 0.0f, 0.0f, UPDBGCHECKINFO_FLAG_2); if (!(this->flags & 2) && SkelAnime_Update(&this->skelAnime)) { this->flags |= 2; } this->actionFunc(this, play); if (this->flags & 1) { Actor_TrackPlayer(play, &this->actor, &this->headRotation, &vec, this->actor.focus.pos); } else { Math_SmoothStepToS(&this->headRotation.x, 0, 6, 6200, 100); Math_SmoothStepToS(&this->headRotation.y, 0, 6, 6200, 100); } player = GET_PLAYER(play); if (this->flags & 8) { if (!(player->stateFlags2 & PLAYER_STATE2_10)) { this->flags &= ~8; } } else { if (player->currentBoots == PLAYER_BOOTS_IRON) { this->flags |= 8; } else if (player->stateFlags2 & PLAYER_STATE2_10) { swimFlag = player->actor.yDistToWater; if (swimFlag > 0) { if (swimFlag >= 320) { if (swimFlag >= 355) { swimFlag = 8; } else { swimFlag = 7; } } else if (swimFlag < 80) { swimFlag = 1; } else { swimFlag *= 0.025f; } if (this->swimFlag < swimFlag) { this->swimFlag = swimFlag; if (!(this->flags & 4) && (this->swimFlag >= 8)) { this->flags |= 4; Sfx_PlaySfxCentered(NA_SE_SY_CORRECT_CHIME); } } } } } } s32 EnMk_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* thisx) { EnMk* this = (EnMk*)thisx; if (limbIndex == 11) { rot->y -= this->headRotation.y; rot->z += this->headRotation.x; } return false; } void EnMk_PostLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* rot, void* thisx) { static Vec3f D_80AAD64C = { 1000.0f, -100.0f, 0.0f }; EnMk* this = (EnMk*)thisx; if (limbIndex == 11) { Matrix_MultVec3f(&D_80AAD64C, &this->actor.focus.pos); } } void EnMk_Draw(Actor* thisx, PlayState* play) { EnMk* this = (EnMk*)thisx; Gfx_SetupDL_37Opa(play->state.gfxCtx); SkelAnime_DrawFlexOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, this->skelAnime.dListCount, EnMk_OverrideLimbDraw, EnMk_PostLimbDraw, &this->actor); }
3789e4a02418a584d7e2a28003fa5c1e0f1eaa19
210716e10269c02d0468c4ffa0b324d07addf909
/VCU-APP/Core/Inc/Libs/finger.h
febb5d1cbe6dc1303794c6af24c4eda88481930c
[]
no_license
zhuhaijun753/gen-core
66e67f2c9702c15ace4946fcedf049fe784c0e12
8608f418a6b279f7efb1dd6028323254eb85c995
refs/heads/master
2023-06-14T00:33:36.100538
2021-07-13T07:48:19
2021-07-13T07:48:19
null
0
0
null
null
null
null
UTF-8
C
false
false
1,219
h
finger.h
/* * finger.h * * Created on: Aug 28, 2019 * Author: Pudja Mansyurin */ #ifndef INC_LIBS__FINGER_H_ #define INC_LIBS__FINGER_H_ /* Includes * --------------------------------------------*/ #include "App/util.h" /* Exported constants * --------------------------------------------*/ #define FINGER_SCAN_MS ((uint16_t)10000) #define FINGER_USER_MAX ((uint8_t)5) /* Exported types * -------------------------------------------*/ typedef uint8_t finger_db_t[FINGER_USER_MAX]; typedef struct { uint8_t id; uint8_t verified; uint8_t registering; } finger_data_t; /* Public functions prototype * --------------------------------------------*/ uint8_t FGR_Init(void); void FGR_DeInit(void); uint8_t FGR_Probe(void); void FGR_Verify(void); void FGR_Flush(void); uint8_t FGR_Fetch(void); uint8_t FGR_Enroll(uint8_t *id, uint8_t *ok); uint8_t FGR_DeleteID(uint8_t id); uint8_t FGR_ResetDB(void); uint8_t FGR_SetPassword(uint32_t password); void FGR_Authenticate(void); const finger_data_t *FGR_IO_Data(void); uint8_t FGR_IO_ID(void); void FGR_IO_ClearID(void); void FGR_IO_ClearDB(void); uint8_t FGR_IO_DB(uint8_t idx); #endif /* INC_LIBS__FINGER_H_ */
34ad321c7d858a6843d3db1b993287795d1ce081
936d232bccb1e561263047382eb46bcc49733b6b
/testit.C
021d534d0de75a21eb9bf5526c6d623492eed513
[ "Apache-2.0" ]
permissive
shenki/phosphor-host-ipmid
28eb25f5902bc1144337eab61546d22b9bf405a3
ec906d6326d3a816ff7badc56f9889820ebf2e06
refs/heads/master
2021-01-18T20:10:59.094198
2015-10-20T05:50:53
2015-10-20T05:50:53
44,511,599
0
0
null
2015-10-19T04:40:35
2015-10-19T04:40:35
null
UTF-8
C
false
false
3,021
c
testit.C
#include <stdio.h> #include <string.h> #include <stdint.h> unsigned char g_sensortype [][2] = { {0xc7, 58}, {0x01, 113}, {0xc7, 56}, {0x01, 114}, {0xc6, 54}, {0x07, 40}, {0xC1, 121}, {0xC2, 137}, {0x07, 36}, {0x07, 43}, {0xC1, 122}, {0xC1, 119}, {0x01, 12}, {0x01, 111}, {0x01, 116}, {0xC1, 127}, {0xC2, 134}, {0xC2, 130}, {0xc, 33}, {0xC1, 125}, {0x01, 115}, {0x22, 4}, {0xC2, 138}, {0x01, 108}, {0x01, 102}, {0xc, 46}, {0x7, 11}, {0xC1, 120}, {0x07, 39}, {0x07, 42}, {0x5, 21}, {0xC2, 131}, {0xc1, 48}, {0x12, 53}, {0xC1, 124}, {0x01, 117}, {0xC1, 126}, {0xf, 5}, {0x23, 0}, {0xC2, 139}, {0x07, 34}, {0x09, 146}, {0x02, 178}, {0xC2, 140}, {0xC1, 118}, {0xC2, 133}, {0x07, 38}, {0xC2, 143}, {0x01, 101}, {0xc3, 9}, {0x7, 10}, {0xc2, 51}, {0x01, 109}, {0xc, 32}, {0x7, 8}, {0xC1, 129}, {0x01, 112}, {0x01, 107}, {0x07, 37}, {0x07, 44}, {0x1f, 50}, {0xC2, 144}, {0xc7, 52}, {0xC2, 141}, {0x01, 106}, {0x01, 110}, {0x01, 103}, {0x9, 28}, {0x07, 35}, {0xc7, 55}, {0x03, 179}, {0x07, 41}, {0xc, 30}, {0x01, 100}, {0xC1, 128}, {0xC2, 135}, {0x01, 105}, {0x7, 47}, {0xC2, 145}, {0xc7, 57}, {0x01, 104}, {0x07, 45}, {0xC2, 132}, {0xc4, 49}, {0xC1, 123}, {0xC2, 142}, {0x01, 13}, {0xC2, 136}, {0xc, 31}, {0xff,0xff} }; unsigned char findSensor(char sensor_number) { int i=0; // TODO : This function should actually call // a dbus object and have it return the data // it is not ready yet so use a Palmetto // based lookup table for now. The g_sensortype // can be removed once the dbus method exists while (g_sensortype[i][0] != 0xff) { if (g_sensortype[i][1] == sensor_number) { break; } else { i++; } } return g_sensortype[i][0]; } int set_sensor_dbus_state_v(uint8_t number, const char *method, char *value) { printf("Attempting to log Variant Sensor 0x%02x via %s with a value of %s\n", number, method, value); } int set_sensor_dbus_state(uint8_t number, const char *method, const char *value) { printf("Attempting to log Sensor 0x%02x via %s with a value of %s\n", number, method, value); return 0; } extern int updateSensorRecordFromSSRAESC(const void *record); uint8_t testrec_boot1[] = {0x05, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00}; uint8_t testrec_boot2[] = {0x05, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}; uint8_t testrec_boot3[] = {0x05, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00}; uint8_t testrec_boot4[] = {0x05, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00}; // DIMM Present uint8_t testrec_sensor1[] {0x1F, 0xa9, 0x00, 0x40, 0x00, 0x10, 0x00, 0x00}; // DIMM Not present uint8_t testrec_sensor2[] {0x1F, 0xa9, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00}; uint8_t testrec_bootprogress[] = {05, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x14, 0x00 }; int main() { updateSensorRecordFromSSRAESC(testrec_bootprogress); updateSensorRecordFromSSRAESC(testrec_sensor1); updateSensorRecordFromSSRAESC(testrec_sensor2); return 0; }
ffa4240fb70ed271ed8db5a76b81a1e6c6d16142
40f2ba4b76f9e71c3d3509c9117ae98fcdd659d7
/peer.c
28fe1c4af7275cabe4569d948bdb4b807e2f1613
[]
no_license
harryge00/BittorrentP2PService
6d4f527c0bdac287cc2ae3e3242e14b941fe4f0e
1a2fcab4d99ba3e764d417a201a31410a3e2d9a3
refs/heads/master
2021-01-10T11:32:48.695015
2016-02-16T14:28:59
2016-02-16T14:28:59
51,644,923
1
0
null
null
null
null
UTF-8
C
false
false
11,494
c
peer.c
#include <sys/types.h> #include <arpa/inet.h> #include <sys/socket.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "debug.h" #include "chunk.h" #include <stdbool.h> #include "common.h" #include "spiffy.h" #include "bt_parse.h" #include "input_buffer.h" struct source_chunk { struct sockaddr peer_addr; int sock; uint8_t hash[SHA1_HASH_SIZE]; struct source_chunk* next; int state; }; struct source_chunk* download_waiting_queue = NULL; int upload_chunk_id; bool uploading = false; struct sockaddr upload_addr; int upload_sock; int sent_seq_number, sent_byte_number; void peer_run(bt_config_t *config); int main(int argc, char **argv) { bt_init(&config, argc, argv); DPRINTF(DEBUG_INIT, "peer.c main beginning\n"); #ifdef TESTING config.identity = 1; // your group number here strcpy(config.chunk_file, "chunkfile"); strcpy(config.has_chunk_file, "haschunks"); #endif bt_parse_command_line(&config); #ifdef DEBUG if (debug & DEBUG_INIT) { bt_dump_config(&config); } #endif peer_run(&config); return 0; } void process_inbound_udp(int sock) { #define BUFLEN 1500 struct sockaddr_in from; socklen_t fromlen; char buf[BUFLEN]; char sendBuf[BUFLEN]; fromlen = sizeof(from); spiffy_recvfrom(sock, buf, BUFLEN, 0, (struct sockaddr *) &from, &fromlen); //parsing recvBuf unsigned short magic_number = ntohs(*(unsigned short*)buf); unsigned char packet_version = *(unsigned char*)(buf+2); unsigned char packet_type = *(unsigned char*)(buf+3); unsigned short packet_header_len = ntohs(*(unsigned short*)(buf+4)); unsigned short packet_len = ntohs(*(unsigned short*)(buf+6)); unsigned int seq_number =ntohl(*(unsigned int*)(buf+8)); unsigned int ack_number = ntohl(*(unsigned int*)(buf+12)); // printf("%d,%d,%d\n", magic_number, packet_version, packet_type); // printf("%d,%d\n", packet_header_len, packet_len); // printf("PROCESS_INBOUND_UDP SKELETON -- replace!\n" // "Incoming message from %s:%d\n\n", // inet_ntoa(from.sin_addr), // ntohs(from.sin_port)); int i, chunk_id; char chunk_count; struct sockaddr* dst_addr; uint8_t* hash; switch(packet_type) { case WHOHAS: printf("receive WHOHAS\n"); chunk_count = buf[16]; char matched_count = 0; for(i=0;i<chunk_count;i++) { hash = (uint8_t*)(buf+20 + i*SHA1_HASH_SIZE); if(find_chunk(hash)>=0){ memcpy(sendBuf + 20 + matched_count * SHA1_HASH_SIZE, hash, SHA1_HASH_SIZE); matched_count++; } } if(matched_count > 0) { fill_header(sendBuf, IHAVE, 20 + SHA1_HASH_SIZE * matched_count, 0, 0); sendBuf[16] = matched_count; dst_addr = (struct sockaddr*)&from; spiffy_sendto(sock, sendBuf, 20 + SHA1_HASH_SIZE * matched_count, 0, dst_addr, sizeof(*dst_addr)); } break; case IHAVE: printf("receive IHAVE\n"); chunk_count = buf[16]; for(i=0;i<chunk_count;i++) { hash = (uint8_t*)(buf+20 + i*SHA1_HASH_SIZE); print_hash(hash); if(download_waiting_queue == NULL) { download_waiting_queue = (struct source_chunk*) malloc(sizeof(struct source_chunk)); memcpy(download_waiting_queue->hash, hash, SHA1_HASH_SIZE); download_waiting_queue->next = NULL; download_waiting_queue->sock = sock; download_waiting_queue->peer_addr = *(struct sockaddr*)&from; fill_header(sendBuf, GET, 36, 0, 0); memcpy(sendBuf+16, hash, SHA1_HASH_SIZE); chunk_id = get_chunk_id(hash, current_request); current_request->chunks[chunk_id].state=RECEIVING; dst_addr = (struct sockaddr*)&from; spiffy_sendto(sock, sendBuf, 36, 0, dst_addr, sizeof(*dst_addr)); download_waiting_queue->state = RECEIVING; } else { struct source_chunk* p_chunk = download_waiting_queue; while(1) { if(memcmp(hash, p_chunk->hash, SHA1_HASH_SIZE) == 0) { printf("another peer also has "); print_hash(hash); break; } if(p_chunk->next == NULL) { p_chunk->next = (struct source_chunk*) malloc(sizeof(struct source_chunk)); p_chunk = p_chunk->next; memcpy(p_chunk->hash, hash, SHA1_HASH_SIZE); p_chunk->next = NULL; p_chunk->sock = sock; p_chunk->state = NOT_STARTED; p_chunk->peer_addr = *(struct sockaddr*)&from; break; } else { p_chunk = p_chunk->next; } } } } break; case GET: printf("receive GET from sock %d\n", sock); memcpy(hash, buf+16, SHA1_HASH_SIZE); print_hash(hash); uploading = true; upload_chunk_id = find_chunk(hash); sent_seq_number = 0; sent_byte_number = 0; upload_sock = sock; upload_addr = *(struct sockaddr*) &from; break; case DATA: printf("receive DATA %d, len %d\n", seq_number, packet_len-16); hash = NULL; struct source_chunk* p_chunk = download_waiting_queue; while(p_chunk != NULL) { if(p_chunk->state == RECEIVING) { hash = p_chunk->hash; break; } p_chunk = p_chunk->next; } print_hash(hash); chunk_id = get_chunk_id(hash, current_request); save_data_packet(buf, chunk_id); fill_header(sendBuf, ACK, 16, 0, seq_number); dst_addr = (struct sockaddr*) &from; spiffy_sendto(sock, sendBuf, 16, 0, dst_addr, sizeof(*dst_addr)); if(save_chunk(chunk_id) > 0) { printf("one chunk ok\n "); p_chunk->state = OWNED; p_chunk = p_chunk->next; if(p_chunk == NULL) { printf("finished downloading request\n"); } else { p_chunk->state = RECEIVING; memset(sendBuf, 0, 16); fill_header(sendBuf, GET, 36, 0, 0); memcpy(sendBuf+16, p_chunk->hash, SHA1_HASH_SIZE); dst_addr = &p_chunk->peer_addr; spiffy_sendto(sock, sendBuf, 16, 0, dst_addr, sizeof(*dst_addr)); } } // printf("sent data\n"); break; case ACK: printf("receive ACK %d\n", ack_number); if(sent_byte_number >= BT_CHUNK_SIZE) { printf("finished uploading\n"); uploading = false; } break; case DENIED: printf("receive DENIED\n"); break; default: printf("Unexpected packet type!\n"); } } void process_get(char *chunkfile, char *outputfile) { printf("PROCESS GET SKELETON CODE CALLED. Fill me in! (%s, %s)\n", chunkfile, outputfile); if(current_request != NULL) { printf("previous request:%s, %d", current_request->filename, current_request->chunk_number); } current_request = parse_has_get_chunk_file(chunkfile, outputfile); char *sendBuf = (char*) malloc(BUFLEN); unsigned short packet_length; FILE *f = fopen(chunkfile, "r"); char line[255]; char chunk_count = 0; unsigned int id; uint8_t hash[SHA1_HASH_SIZE*2+1]; uint8_t binary_hash[SHA1_HASH_SIZE]; struct bt_peer_s* peer; struct sockaddr* dst_addr; // printf("len:%d, %s\n", packet_length, sendBuf); while (fgets(line, 255, f) != NULL) { if (line[0] == '#'){ continue; } sscanf(line, "%d %s", &id, hash); hex2binary((char*)hash, SHA1_HASH_SIZE*2, binary_hash); memcpy(sendBuf + 20 + 20 * chunk_count, (char*)binary_hash, sizeof(binary_hash)); chunk_count++; if(chunk_count >= 74 ) { //reached the maximum size of a packet printf("WHOHAS packet has 74 chunks\n"); fill_header(sendBuf, WHOHAS, 1500, 0, 0); *(sendBuf + 16) = chunk_count; peer = config.peers; while(peer!=NULL) { if(peer->id==config.identity){ peer = peer->next; } else{ dst_addr = (struct sockaddr*)&peer->addr; spiffy_sendto(sock, sendBuf, 1500, 0, dst_addr, sizeof(*dst_addr)); peer = peer->next; } } memset(sendBuf, 0, BUFLEN); chunk_count = 0; } } fclose(f); packet_length = 20 + 20 * chunk_count; fill_header(sendBuf, WHOHAS, packet_length, 0, 0); *(sendBuf + 16) = chunk_count; // printf("chunk_count:%d, %s\n", sendBuf[16], sendBuf); peer = config.peers; while(peer!=NULL) { if(peer->id==config.identity){ peer = peer->next; } else{ dst_addr = (struct sockaddr*)&peer->addr; spiffy_sendto(sock, sendBuf, packet_length, 0, dst_addr, sizeof(*dst_addr)); peer = peer->next; } } free(sendBuf); } void handle_user_input(char *line, void *cbdata) { char chunkf[128], outf[128]; bzero(chunkf, sizeof(chunkf)); bzero(outf, sizeof(outf)); if (sscanf(line, "GET %120s %120s", chunkf, outf)) { printf("%s\n", line); if (strlen(outf) > 0) { FILE *fp = fopen(outf, "w+"); fclose(fp); process_get(chunkf, outf); } } } void send_data_packet() { char* sendBuf = (char*) malloc(BUFLEN); int data_length; if(sent_byte_number >= BT_CHUNK_SIZE) { return; } if(sent_byte_number + MAX_DATA_PACKET_SIZE > BT_CHUNK_SIZE) { data_length = BT_CHUNK_SIZE - sent_byte_number; } else { data_length = MAX_DATA_PACKET_SIZE; } fill_header(sendBuf, DATA, data_length + 16, sent_seq_number + 1, 0); read_file(master_data_file_name, sendBuf + 16, data_length, upload_chunk_id * BT_CHUNK_SIZE + sent_byte_number); printf("sending data %d (%d) len %d \n", sent_seq_number + 1, sent_byte_number, data_length); spiffy_sendto(upload_sock, sendBuf, data_length+16, 0, &upload_addr, sizeof(upload_addr)); sent_seq_number++; sent_byte_number += data_length; } void peer_run(bt_config_t *config) { struct sockaddr_in myaddr; fd_set readfds; struct user_iobuf *userbuf; if ((userbuf = create_userbuf()) == NULL) { perror("peer_run could not allocate userbuf"); exit(-1); } if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) == -1) { perror("peer_run could not create socket"); exit(-1); } printf("mysock:%d\n", sock); bzero(&myaddr, sizeof(myaddr)); myaddr.sin_family = AF_INET; myaddr.sin_addr.s_addr = htonl(INADDR_ANY); myaddr.sin_port = htons(config->myport); if (bind(sock, (struct sockaddr *) &myaddr, sizeof(myaddr)) == -1) { perror("peer_run could not bind socket"); exit(-1); } spiffy_init(config->identity, (struct sockaddr *)&myaddr, sizeof(myaddr)); printf("init OK\n"); //parse_chunk_file(config->has_chunk_file); has_chunk_table = parse_has_get_chunk_file(config->has_chunk_file, NULL); total_chunk_table = parse_total_chunk_file(config->chunk_file, NULL); printf("Parsed Ok\n"); char read_buffer[MAX_LINE_LENGTH]; FILE* master_chunk_file = fopen(config->chunk_file, "r"); fgets(read_buffer, MAX_LINE_LENGTH, master_chunk_file); fclose(master_chunk_file); memset(master_data_file_name, 0, FILE_NAME_SIZE); sscanf(read_buffer, "File:%s", master_data_file_name); printf("master_data_file_name: %s\n", master_data_file_name); while (1) { int nfds; FD_SET(STDIN_FILENO, &readfds); FD_SET(sock, &readfds); nfds = select(sock+1, &readfds, NULL, NULL, NULL); if (nfds > 0) { if (FD_ISSET(sock, &readfds)) { process_inbound_udp(sock); } if (FD_ISSET(STDIN_FILENO, &readfds)) { process_user_input(STDIN_FILENO, userbuf, handle_user_input, "Currently unused"); } } if(uploading) { send_data_packet(); } if(all_chunk_finished(current_request)){ printf("all chunk finished, GET request DONE\n"); free(current_request->filename); free(current_request->chunks); free(current_request); current_request = NULL; } } }
dff7872c0cf1ce90633c9866f5021ff04bca7cb2
cd0bc8afac44d99477cc6244d677bfe55139e869
/lib/my_printf/src/utils/strcp.c
d311f33c2cc28d00814b997c2a1d534f5fa04251
[]
no_license
AymericAstaing/42sh_epitech
29908c58fca21f7ffa8db293816ea3938f27ad77
4171af10bdc9abedc4fc0181e8d9b3e70ec76704
refs/heads/master
2022-01-06T00:08:57.889056
2019-06-28T10:11:40
2019-06-28T10:11:40
null
0
0
null
null
null
null
UTF-8
C
false
false
164
c
strcp.c
/* ** EPITECH PROJECT, 2017 ** Str copy ** File description: ** Copy string */ void strcp(char *s1, char const *s2) { *s1 = *s2; if (s2) strcp(s1++, s2++); }
6a228fc44aa0de5a9652b7767b37a215e7961e26
976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f
/source/linux/fs/xfs/libxfs/extr_xfs_rmap.h_xfs_owner_info_pack.c
7bae54c25083eb8edaabf74350a759da8f71e9dc
[]
no_license
isabella232/AnghaBench
7ba90823cf8c0dd25a803d1688500eec91d1cf4e
9a5f60cdc907a0475090eef45e5be43392c25132
refs/heads/master
2023-04-20T09:05:33.024569
2021-05-07T18:36:26
2021-05-07T18:36:26
null
0
0
null
null
null
null
UTF-8
C
false
false
1,187
c
extr_xfs_rmap.h_xfs_owner_info_pack.c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ /* Type definitions */ typedef int /*<<< orphan*/ uint64_t ; struct xfs_owner_info {int /*<<< orphan*/ oi_flags; int /*<<< orphan*/ oi_offset; int /*<<< orphan*/ oi_owner; } ; /* Variables and functions */ int /*<<< orphan*/ XFS_OWNER_INFO_ATTR_FORK ; int /*<<< orphan*/ XFS_OWNER_INFO_BMBT_BLOCK ; unsigned int XFS_RMAP_ATTR_FORK ; unsigned int XFS_RMAP_BMBT_BLOCK ; int /*<<< orphan*/ XFS_RMAP_OFF (int /*<<< orphan*/ ) ; __attribute__((used)) static inline void xfs_owner_info_pack( struct xfs_owner_info *oinfo, uint64_t owner, uint64_t offset, unsigned int flags) { oinfo->oi_owner = owner; oinfo->oi_offset = XFS_RMAP_OFF(offset); oinfo->oi_flags = 0; if (flags & XFS_RMAP_ATTR_FORK) oinfo->oi_flags |= XFS_OWNER_INFO_ATTR_FORK; if (flags & XFS_RMAP_BMBT_BLOCK) oinfo->oi_flags |= XFS_OWNER_INFO_BMBT_BLOCK; }
ad4ff7a6947b5c347c69619377a8675d4a804332
b9d681e2797df1d77da1e568b33ae3bd5ec48972
/src/ft_strncpy.c
9d906603baca79bc6d29372d51b68d9f6cbc51b7
[]
no_license
rmoswela/libft_wtc
c5d4baa816ec5459f04243959ebcf57e9d6a7c5b
4f2fc19e8363a80b9fbe164bd059600b31bbb6e3
refs/heads/master
2021-05-02T13:39:25.914855
2016-11-29T20:12:27
2016-11-29T20:12:27
72,650,687
1
0
null
null
null
null
UTF-8
C
false
false
1,238
c
ft_strncpy.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strncpy.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rmoswela <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/21 14:11:45 by rmoswela #+# #+# */ /* Updated: 2016/11/22 11:18:39 by ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft.h" /*funtion to copy n bytes from string src to dest and if src is less than * n the rest dest is filled with nul characters*/ char *ft_strncpy(char *dest, char *src, size_t n) { size_t loop; loop = 0; while (src[loop] != '\0' && loop < n) { dest[loop] = src[loop]; loop++; } dest[loop] = '\0'; return (dest); }
69a06d7954e68ddb1df4d91e2b9f34e3b117bf6c
f07954fbaa1013657d58c9021430a967a2106e70
/simple_examples/pointers_2.c
bc1eeed671258fa6075d52644c8a686a5dcc75d9
[ "MIT" ]
permissive
uselessscat/c-practices
58d6c89d77fb009292703e64ad61815a8284d3a3
0c02083e78c3bad175d6308523c583f66375e3b5
refs/heads/main
2022-12-24T08:08:58.541199
2020-10-02T03:34:49
2020-10-02T03:34:49
262,241,301
0
0
null
null
null
null
UTF-8
C
false
false
796
c
pointers_2.c
/** Ejemplo de punteros */ #include<stdio.h> int main() { int integer = 1; // estos son equivalentes int array0[10]; // pero en este caso, array1 es un tipo puntero int (*array1)[10]; int *array2 = &integer; // array de 10 punteros // [] tiene mayor precendencia que * int *array3[10]; array3[0] = array2; int *(*array4)[10]; printf("%lu %lu\n", sizeof(array0), sizeof(*array0)); printf("%lu %lu %lu\n", sizeof(array1), sizeof(*array1), sizeof(**array1)); printf("%lu %lu\n", sizeof(array2), sizeof(*array2)); printf("%lu %lu %lu\n", sizeof(array3), sizeof(*array3), sizeof(**array3)); printf("%lu %lu %lu %lu\n", sizeof(array4), sizeof(*array4), sizeof(**array4), sizeof(***array4)); return 0; }
886ef3d1f2fb15403665796357fbb3e63cf1516a
04c36dadc97eef8501cb2983b8240e3044a92907
/tests/gr_test_prevalence.c
b94d7755d6c87447c5d28dc5170773e371a41ff7
[ "MIT" ]
permissive
willvieira/STModel-Simulation
e7c7246ce953ec7411f1d9a41f9db853e1498743
ee5bb2b7d1045a5813a87f6c1c58629b98fb0a56
refs/heads/master
2020-05-30T06:45:47.212920
2015-08-17T18:36:07
2015-08-17T18:36:07
82,616,532
0
0
null
2017-02-21T00:18:15
2017-02-21T00:18:15
null
UTF-8
C
false
false
2,992
c
gr_test_prevalence.c
#include <assert.h> #include <time.h> #include <gsl/gsl_rng.h> #include <math.h> #include "../src/grid.c" #include "../src/climate.c" int main() { /* test out the computation of prevalence on a small controlled grid */ int testResult = 0; // verify that st_state_to_index fails properly testResult += (st_state_to_index('D') != -1); // test both neighborhood types Grid * testGr = gr_make_grid(3, 3, MOORE, UNIFORM, 0, NULL); StateData prevalence; gr_compute_local_prevalence(testGr, 1, 1, prevalence); testResult += prevalence[st_state_to_index('T')] != 3.0/8.0; testResult += prevalence[st_state_to_index('B')] != 3.0/8.0; testResult += prevalence[st_state_to_index('M')] != 2.0/8.0; testResult += prevalence[st_state_to_index('R')] != 0; testGr = gr_make_grid(3, 3, VONNE, UNIFORM, 0, NULL); gr_compute_local_prevalence(testGr, 1, 1, prevalence); testResult += prevalence[st_state_to_index('T')] != 1.0/4.0; testResult += prevalence[st_state_to_index('B')] != 1.0/4.0; testResult += prevalence[st_state_to_index('M')] != 2.0/4.0; testResult += prevalence[st_state_to_index('R')] != 0; // test edges in each direction with MOORE neighborhoods, also add an R testGr = gr_make_grid(3, 3, MOORE, UNIFORM, 0, NULL); testGr->stateCurrent[1][2] = 'R'; double epsilon = 0.0000001; gr_compute_local_prevalence(testGr, 2, 2, prevalence); testResult += prevalence[st_state_to_index('T')] != 0; testResult += prevalence[st_state_to_index('B')] != 0; testResult += fabs(prevalence[st_state_to_index('M')] - 2.0/3.0) > epsilon; testResult += fabs(prevalence[st_state_to_index('R')] - 1.0/3.0) > epsilon; gr_compute_local_prevalence(testGr, 0, 1, prevalence); testResult += fabs(prevalence[st_state_to_index('T')] - 2.0/5.0) > epsilon; testResult += fabs(prevalence[st_state_to_index('B')] - 1.0/5.0) > epsilon; testResult += fabs(prevalence[st_state_to_index('M')] - 1.0/5.0) > epsilon; testResult += fabs(prevalence[st_state_to_index('R')] - 1.0/5.0) > epsilon; // test global prevalence testGr = gr_make_grid(180, 180, MOORE, UNIFORM, 0, NULL); // set up RNG gsl_rng *rng = gsl_rng_alloc(gsl_rng_mt19937); assert(rng); // Declare global prevalence and init on 0 StateData globalPrevalence; for(int i = 0; i < GR_NUM_STATES; i++) globalPrevalence[i] = 0; // Compute prevalence on all cells for(int x = 0 ; x < testGr->xdim; x++){ for(int y = 0 ; y < testGr->ydim; y++){ //printf("Cell %d,%d \n",x,y); gr_compute_global_prevalence(testGr,x,y,prevalence,rng); for(int i = 0; i < GR_NUM_STATES; i++) { globalPrevalence[i] += prevalence[i]/(testGr->ydim*testGr->xdim); //printf("GlobPrev of %d: %f \n",i,globalPrevalence[i]); } } } epsilon=0.005; testResult += fabs(prevalence[st_state_to_index('T')] - 0.33) < epsilon; testResult += fabs(prevalence[st_state_to_index('B')] - 0.33) < epsilon; testResult += fabs(prevalence[st_state_to_index('M')] - 0.33) < epsilon; gsl_rng_free(rng); return testResult; }
9e1df5eba95456f201a750f10ebccb0b17bc7d18
dd77bc0394348a84db3b60ae168e693716582928
/bsl-parse/BSLStatement_Var.c
3dfafc23c5a0a4726e918ceb928f30ba7517cf9c
[]
no_license
samdmarshall/bsl-validator
065cf9e14856f8280990816eea846ecde1249cd6
7ea183574f67cca528dec34bca0bdb588683d89c
refs/heads/master
2021-01-19T01:46:15.589331
2020-04-23T18:08:28
2020-04-23T18:08:28
26,695,703
0
0
null
null
null
null
UTF-8
C
false
false
2,937
c
BSLStatement_Var.c
// // BSLStatement_Var.c // bsl-parse // // Created by Samantha Marshall on 1/8/15. // Copyright (c) 2015 Samantha Marshall. All rights reserved. // #include "BSLStatement_Var.h" #include "BSLVariable.h" #include "BSLSymbol.h" #include "BSLStack.h" bsl_statement_var bsl_statement_const_create(bsl_tkn_ir **token, bsl_context *context) { bsl_statement_var constant = {0}; bsl_tkn_ir *curr = *token; debug_printf("%s", "constant creation: "); bsl_variable *variable = bsl_variable_parse_token(token, context); memcpy(&(constant.variable), variable, sizeof(bsl_variable)); free(variable); #if DEBUG char *var_text = bsl_variable_print(constant.variable); debug_printf("%s\n", var_text); free(var_text); #endif *token = curr->next; return constant; } bsl_statement_var bsl_statement_var_create(bsl_tkn_ir **token, bsl_context *context) { bsl_statement_var var = {0}; bsl_tkn_ir *curr = *token; debug_printf("%s", "variable creation: "); bsl_symbol *var_symbol = bsl_symbol_create(bsl_symbol_type_variable); bsl_symbol_update_info(var_symbol, curr->token->offset); var.variable = bsl_variable_parse(&curr, context); debug_printf("%s %s = ", bsl_variable_get_type_name(var.variable.type), var.variable.name); var_symbol->u.value = var.variable; bsl_symbol *symbol_test = bsl_frame_search_scope(var_symbol->u.value.name, context); if (symbol_test == NULL) { bsl_db_register_state(var_symbol->u.value.name, var_symbol, context); } else { // error, already registered symbol bsl_context_assign_error(context, bsl_error_registered_symbol); // ERROR ASSIGNMENT bsl_symbol_duplicate_description(var_symbol, symbol_test); bsl_context_check_error(context); } #if DEBUG char *var_text = bsl_variable_print(var.variable); debug_printf("%s\n", var_text); free(var_text); #endif // move current position *token = curr; return var; } bsl_statement_var bsl_statement_var_assign(bsl_tkn_ir **token, bsl_context *context) { bsl_statement_var var = {}; bsl_tkn_ir *curr = *token; debug_printf("%s", "variable assignment: "); char *name = calloc(curr->token->offset.length + 1, sizeof(char)); strncpy(name, curr->token->contents, sizeof(char) * curr->token->offset.length); bsl_symbol *var_symbol = bsl_frame_search_scope(name, context); if (var_symbol->type == bsl_symbol_type_variable) { memcpy(&(var.variable), &(var_symbol->u.value), sizeof(bsl_variable)); } #if DEBUG char *var1_text = bsl_variable_print(var_symbol->u.value); debug_printf("%s %s", var_symbol->u.value.name, var1_text); free(var1_text); #endif if (curr->next != NULL) { debug_printf("%s", " -> "); bsl_variable_parse_assign(&curr, context, &(var.variable)); bsl_variable *symbol_variable = &(var_symbol->u.value); bsl_variable_set(symbol_variable, &(var.variable)); bsl_db_register_state(var.variable.name, var_symbol, context); } // move current position *token = curr; return var; }
efc2678195f870d6f9a13a8257c322636d776a6c
bf1c26557e8b67dd46ef652b6cc4e4b258ace68a
/steve/xapp/CD32/DEV/CDMPEG/Include/iffp/ilbm.h
c05adf66fbc1f888290e9f8ee081a641c88b5385
[]
no_license
allison-null/mediapoint-amiga
c269bcd2f14a651985ce508971fe951b3e9aa94d
d81803d3d024151d73eb1ef1ccba1f0ff228a7a4
refs/heads/master
2020-04-23T00:49:25.587081
2018-01-20T21:20:52
2018-01-20T21:20:52
null
0
0
null
null
null
null
UTF-8
C
false
false
11,172
h
ilbm.h
/* * * ilbm.h: Definitions for IFFParse ILBM reader. * * 5/92 * 39.1 - 7/92 - added setcolors, interface change for loadcmap * 39.5 - 11/92 - get rid of BytesPerRow macro which duplicated RowBytes * AND conflicted with a system structure member name. * Changed "BitsPerRow" macro to "RowBits" to match. * Also unconditionalized extern of GfxBase and IntuitionBase */ #ifndef IFFP_ILBM_H #define IFFP_ILBM_H #ifndef IFFP_IFF_H #include "iffp/iff.h" #endif #ifndef INTUITION_INTUITION_H #include <intuition/intuition.h> #endif #ifndef GRAPHICS_VIDEOCONTROL_H #include <graphics/videocontrol.h> #endif #ifndef NO_PROTOS #include <clib/graphics_protos.h> #include <clib/intuition_protos.h> #include <clib/alib_protos.h> #endif extern struct Library *IntuitionBase; extern struct Library *GfxBase; #ifndef NO_SAS_PRAGMAS #include <pragmas/intuition_pragmas.h> #include <pragmas/graphics_pragmas.h> #endif /* IFF types we may encounter */ #define ID_ILBM MAKE_ID('I','L','B','M') /* ILBM Chunk ID's we may encounter * (see iffp/iff.h for some other generic chunks) */ #define ID_BMHD MAKE_ID('B','M','H','D') #define ID_CMAP MAKE_ID('C','M','A','P') #define ID_CRNG MAKE_ID('C','R','N','G') #define ID_CCRT MAKE_ID('C','C','R','T') #define ID_GRAB MAKE_ID('G','R','A','B') #define ID_SPRT MAKE_ID('S','P','R','T') #define ID_DEST MAKE_ID('D','E','S','T') #define ID_CAMG MAKE_ID('C','A','M','G') /* Use this constant instead of sizeof(ColorRegister). * ONLY VALID FOR size of color register AS STORED in ILBM.CMAP */ #define sizeofColorRegister 3 typedef WORD Color4; /* Amiga RAM version of a color-register, * with 4 bits each RGB in low 12 bits.*/ typedef struct { ULONG r; ULONG g; ULONG b; } Color32; /* Maximum number of bitplanes storable in BitMap structure */ #define MAXAMDEPTH 8 /* Use ViewPort->ColorMap.Count instead #define MAXAMCOLORREG 32 */ /* Maximum planes this code can save */ #define MAXSAVEDEPTH 24 /* Convert image width to even number of BytesPerRow for ILBM save. * Do NOT use this macro to determine the actual number of bytes per row * in an Amiga BitMap. Use BitMap->BytesPerRow for scan-line modulo. * Use your screen or viewport width to determine width. Or under * V39, use GetBitMapAttr(). */ #define RowBytes(w) ((((w) + 15) >> 4) << 1) #define RowBits(w) ((((w) + 15) >> 4) << 4) /* Flags that should be masked out of old 16-bit CAMG before save or use. * Note that 32-bit mode id (non-zero high word) bits should not be twiddled */ #define BADFLAGS (SPRITES|VP_HIDE|GENLOCK_AUDIO|GENLOCK_VIDEO) #define OLDCAMGMASK (~BADFLAGS) /* Masking techniques */ #define mskNone 0 #define mskHasMask 1 #define mskHasTransparentColor 2 #define mskLasso 3 /* We plan to define this value, to mean that the BMHD.transparentColor * variable contains a count of alpha channel planes which are stored * in the BODY AFTER the image planes. As always, the count of * masking/alpha planes is not included in BMHD.nPlanes. * If you have any comments or input, contact Chris Ludwig (CATS US). */ #define mskHasAlpha 4 /* Compression techniques */ #define cmpNone 0 #define cmpByteRun1 1 /* ---------- BitMapHeader ---------------------------------------------*/ /* Required Bitmap header (BMHD) structure describes an ILBM */ typedef struct { UWORD w, h; /* Width, height in pixels */ WORD x, y; /* x, y position for this bitmap */ UBYTE nPlanes; /* # of planes (not including mask) */ UBYTE masking; /* a masking technique listed above */ UBYTE compression; /* cmpNone or cmpByteRun1 */ UBYTE flags; /* as defined or approved by Commodore */ UWORD transparentColor; UBYTE xAspect, yAspect; WORD pageWidth, pageHeight; } BitMapHeader; /* BMHD flags */ /* Advisory that 8 significant bits-per-gun have been stored in CMAP * i.e. that the CMAP is definitely not 4-bit values shifted left. * This bit will disable nibble examination by color loading routine. */ #define BMHDB_CMAPOK 7 #define BMHDF_CMAPOK (1 << BMHDB_CMAPOK) /* ---------- ColorRegister --------------------------------------------*/ /* A CMAP chunk is a packed array of ColorRegisters (3 bytes each). */ typedef struct { UBYTE red, green, blue; /* MUST be UBYTEs so ">> 4" won't sign extend.*/ } ColorRegister; /* ---------- Point2D --------------------------------------------------*/ /* A Point2D is stored in a GRAB chunk. */ typedef struct { WORD x, y; /* coordinates (pixels) */ } Point2D; /* ---------- DestMerge ------------------------------------------------*/ /* A DestMerge is stored in a DEST chunk. */ typedef struct { UBYTE depth; /* # bitplanes in the original source */ UBYTE pad1; /* UNUSED; for consistency store 0 here */ UWORD planePick; /* how to scatter source bitplanes into destination */ UWORD planeOnOff; /* default bitplane data for planePick */ UWORD planeMask; /* selects which bitplanes to store into */ } DestMerge; /* ---------- SpritePrecedence -----------------------------------------*/ /* A SpritePrecedence is stored in a SPRT chunk. */ typedef UWORD SpritePrecedence; /* ---------- Camg Amiga Viewport Mode Display ID ----------------------*/ /* The CAMG chunk is used to store the Amiga display mode in which * an ILBM is meant to be displayed. This is very important, especially * for special display modes such as HAM and HALFBRITE where the * pixels are interpreted differently. * Under V37 and higher, store a 32-bit Amiga DisplayID (aka. ModeID) * in the ULONG ViewModes CAMG variable (from GetVPModeID(viewport)). * Pre-V37, instead store the 16-bit viewport->Modes. * See the current IFF manual for information on screening for bad CAMG * chunks when interpreting a CAMG as a 32-bit DisplayID or 16-bit ViewMode. * The chunk's content is declared as a ULONG. */ typedef struct { ULONG ViewModes; } CamgChunk; /* ---------- CRange cycling chunk -------------------------------------*/ #define RNG_NORATE 36 /* Dpaint uses this rate to mean non-active */ /* A CRange is store in a CRNG chunk. */ typedef struct { WORD pad1; /* reserved for future use; store 0 here */ WORD rate; /* 60/sec=16384, 30/sec=8192, 1/sec=16384/60=273 */ WORD active; /* bit0 set = active, bit 1 set = reverse */ UBYTE low, high; /* lower and upper color registers selected */ } CRange; /* ---------- Ccrt (Graphicraft) cycling chunk -------------------------*/ /* A Ccrt is stored in a CCRT chunk. */ typedef struct { WORD direction; /* 0=don't cycle, 1=forward, -1=backwards */ UBYTE start; /* range lower */ UBYTE end; /* range upper */ LONG seconds; /* seconds between cycling */ LONG microseconds; /* msecs between cycling */ WORD pad; /* future exp - store 0 here */ } CcrtChunk; /* If you are writing all of your chunks by hand, * you can use these macros for these simple chunks. */ #define putbmhd(iff, bmHdr) \ PutCk(iff, ID_BMHD, sizeof(BitMapHeader), (BYTE *)bmHdr) #define putgrab(iff, point2D) \ PutCk(iff, ID_GRAB, sizeof(Point2D), (BYTE *)point2D) #define putdest(iff, destMerge) \ PutCk(iff, ID_DEST, sizeof(DestMerge), (BYTE *)destMerge) #define putsprt(iff, spritePrec) \ PutCk(iff, ID_SPRT, sizeof(SpritePrecedence), (BYTE *)spritePrec) #define putcamg(iff, camg) \ PutCk(iff, ID_CAMG, sizeof(CamgChunk),(BYTE *)camg) #define putcrng(iff, crng) \ PutCk(iff, ID_CRNG, sizeof(CRange),(BYTE *)crng) #define putccrt(iff, ccrt) \ PutCk(iff, ID_CCRT, sizeof(CcrtChunk),(BYTE *)ccrt) #ifndef NO_PROTOS /* unpacker.c */ BOOL unpackrow(BYTE **pSource, BYTE **pDest, WORD srcBytes0, WORD dstBytes0); /* packer.c */ LONG packrow(BYTE **pSource, BYTE **pDest, LONG rowSize); /* ilbmr.c ILBM reader routines */ LONG loadbody(struct IFFHandle *iff, struct BitMap *bitmap, BitMapHeader *bmhd); LONG loadbody2(struct IFFHandle *iff, struct BitMap *bitmap, BYTE *mask, BitMapHeader *bmhd, BYTE *buffer, ULONG bufsize); LONG loadcmap(struct ILBMInfo *ilbm); LONG getcolors(struct ILBMInfo *ilbm); LONG setcolors(struct ILBMInfo *ilbm, struct ViewPort *vp); void freecolors(struct ILBMInfo *ilbm); LONG alloccolortable(struct ILBMInfo *ilbm); ULONG getcamg(struct ILBMInfo *ilbm); /* ilbmw.c ILBM writer routines */ long initbmhd(BitMapHeader *bmhd, struct BitMap *bitmap, WORD masking, WORD compression, WORD transparentColor, WORD width, WORD height, WORD pageWidth, WORD pageHeight, ULONG modeid); long putcmap(struct IFFHandle *iff,APTR colortable,UWORD ncolors,UWORD bitspergun); long putbody(struct IFFHandle *iff, struct BitMap *bitmap, BYTE *mask, BitMapHeader *bmHdr, BYTE *buffer, LONG bufsize); /* getdisplay.c (used to load a display) */ LONG showilbm(struct ILBMInfo *ilbm, UBYTE *filename); BOOL unshowilbm(struct ILBMInfo *ilbm); LONG createdisplay(struct ILBMInfo *); BOOL deletedisplay(struct ILBMInfo *); LONG getdisplay(struct ILBMInfo *); BOOL freedisplay(struct ILBMInfo *); /* getbitmap.c (used if just loading brush or bitmap) */ LONG createbrush(struct ILBMInfo *); void deletebrush(struct ILBMInfo *); LONG getbitmap(struct ILBMInfo *); void freebitmap(struct ILBMInfo *); /* screen.c (opens 1.3 or 2.0 screen) */ struct Screen *openidscreen(struct ILBMInfo *,SHORT,SHORT,SHORT,ULONG); struct Window *opendisplay(struct ILBMInfo *,SHORT,SHORT,SHORT,ULONG); ULONG modefallback(ULONG, SHORT, SHORT, SHORT); void clipit(SHORT wide, SHORT high, struct Rectangle *spos, struct Rectangle *dclip, struct Rectangle *txto, struct Rectangle *stdo,struct Rectangle *maxo, struct Rectangle * uclip); BOOL closedisplay(struct ILBMInfo *ilbm); /* loadilbm.c */ LONG loadbrush(struct ILBMInfo *ilbm, UBYTE *filename); void unloadbrush(struct ILBMInfo *ilbm); LONG queryilbm(struct ILBMInfo *ilbm, UBYTE *filename); LONG loadilbm(struct ILBMInfo *ilbm, UBYTE *filename); void unloadilbm(struct ILBMInfo *ilbm); /* saveilbm.c */ LONG screensave(struct ILBMInfo *ilbm, struct Screen *scr, struct Chunk *chunklist1, struct Chunk *chunklist2, UBYTE *filename); LONG saveilbm(struct ILBMInfo *ilbm, struct BitMap *bitmap, ULONG modeid, WORD width, WORD height, WORD pagewidth, WORD pageheight, APTR colortable, UWORD count, UWORD bitspergun, WORD masking, WORD transparentColor, struct Chunk *chunklist1, struct Chunk *chunklist2, UBYTE *filename); /* screendump.c (print screen or brush) */ int screendump(struct Screen *scr, UWORD srcx, UWORD srcy, UWORD srcw, UWORD srch, LONG destcols, UWORD special); /* bmprintc.c (write C source for ILBM) */ void BMPrintCRep(struct BitMap *bm, FILE *fp, UBYTE *name, UBYTE *fmt); #endif /* NO_PROTOS */ #endif /* IFFP_ILBM_H */
40783a99be533291b09c665ade1ff52995ce1f09
1f90bf31bc393da974f290ca48ca21ec5b0028c6
/REE_TEE_shizheng_nommap/bl_fp_demo_paul/jni/include/bf_device.h
2218728975b08949890840aeefbf7eec474fc83a
[]
no_license
changliang328/learngit
f1da210850dd07d507d71ce8cc8055b904872140
306bde543ebd146714949649716fe2ab57c997c0
refs/heads/master
2020-12-02T06:29:59.770391
2018-02-02T02:49:53
2018-02-02T02:49:53
96,844,144
0
2
null
null
null
null
UTF-8
C
false
false
1,341
h
bf_device.h
#ifndef bf_DEVICE_H #define bf_DEVICE_H #ifdef __cplusplus extern "C" { #endif #include <stdlib.h> #include <stdbool.h> #include "bf_types.h" #ifdef FP_M_AUTO_TEST #define IMAGE_VALUE_MIN 1 #define IMAGE_VALUE_MAX 100 #define EVENT_VALUE_MIN 101 #define EVENT_VALUE_MAX 107 #define IMAGE_FOR_EVENT 101 #endif #define SILEAD_6185_ID 0x6185 #define SILEAD_6163_ID 0x6163 #define GOODIX_3288_ID 0x3288 #define GOODIX_3268_ID 0x3268 struct bf_ree_device { int devfd; int sysfs_fd; int cancel_fds[2]; }; typedef struct bf_ree_device bf_ree_device_t; int32_t fingerprint_open(void); int32_t fingerprint_close(void); int32_t enable_Irq_ioctl(void); int32_t disable_Irq_ioctl(void); int32_t enable_power_ioctl(void); int32_t disable_power_ioctl(void); int32_t do_hwreset_ioctl(void); void bf_ree_device_destroy(bf_ree_device_t* device); bf_ree_device_t* bf_ree_device_new(); int bf_ree_device_wait_irq_paul_timeout(bf_ree_device_t* device, int timeout); int bf_ree_device_set_cancel(bf_ree_device_t* device); int bf_ree_device_clear_cancel(bf_ree_device_t* device); int bf_key_event_ioctl(navigation_info *navi_info); int bf_io_init(void); int bf_io_exit(void); int32_t clear_pollflag_ioctl(void); int bf_ree_device_wait_irq_paul(bf_ree_device_t* device); int32_t disable_spi_ioctl(void); #ifdef __cplusplus } #endif #endif
f998d11044ee93f159ab8c9f52ce3a5c5305bd28
0f6a12799f6bfdb6c3d6c7ca6bb694d12065b572
/pila.h
59cd9a57e36d014bdca4d8fead28bd97fe2f418b
[]
no_license
EstructurasDeDatos1/Pila-generica
356d274548f143f6a96d9ff99b53d194d0f935a5
110ba9bf513901e0195902e4c0e649521fc61093
refs/heads/master
2022-06-14T05:55:51.822298
2020-04-23T21:50:33
2020-04-23T21:50:33
258,338,749
0
0
null
null
null
null
UTF-8
C
false
false
483
h
pila.h
#ifndef PILA_H_INCLUDED #define PILA_H_INCLUDED typedef struct { void **pila; int maxDatos; int tamDato; int tos; } TPila; TPila *nuevaPila(int tamDato,int maxDatos); int vacia(TPila *pila); int llena(TPila *pila); void pop(TPila *pila, void *dato); void push(TPila *pila, void *valor); void top(TPila *pila, void *tope); void liberaPila(TPila *pila); void imprimePila(TPila *pila,void (*funcion)(void *info) ); #endif // PILA_H_INCLUDED
1be83bb26599ac5b9749179439a5ff80bcf5ac10
420e878cecd6fb2ea82752c6d6b231527fcc69e3
/NextDimension-21/include.i860/sys/exception.h
9ae438cb410982aeffbe35fbbe8769f07ae8540d
[]
no_license
johnsonjh/NeXTDimension
22f68eb58cf0e2dfd6ed30617385473c90807545
79d1d9c4084b3aefa70b65a559c830e01cbf83cb
refs/heads/master
2023-05-14T00:50:36.548727
2021-08-19T19:37:46
2021-08-19T19:37:46
398,036,869
17
5
null
2021-08-19T18:23:05
2021-08-19T18:20:08
C
UTF-8
C
false
false
1,552
h
exception.h
/* * Mach Operating System * Copyright (c) 1987 Carnegie-Mellon University * All rights reserved. The CMU software License Agreement specifies * the terms and conditions for use and redistribution. */ /* ********************************************************************** * HISTORY * $Log: exception.h,v $ * Revision 2.1 88/11/25 13:05:34 rvb * 2.1 * * Revision 2.2 88/08/24 02:26:52 mwyoung * Adjusted include file references. * [88/08/17 02:12:09 mwyoung] * * * 29-Sep-87 David Black (dlb) at Carnegie-Mellon University * Created. * ********************************************************************** */ #include <machine/exception.h> /* * Machine-independent exception definitions. */ #define EXC_BAD_ACCESS 1 /* Could not access memory */ /* Code contains kern_return_t describing error. */ /* Subcode contains bad memory address. */ #define EXC_BAD_INSTRUCTION 2 /* Instruction failed */ /* Illegal or undefined instruction or operand */ #define EXC_ARITHMETIC 3 /* Arithmetic exception */ /* Exact nature of exception is in code field */ #define EXC_EMULATION 4 /* Emulation instruction */ /* Emulation support instruction encountered */ /* Details in code and subcode fields */ #define EXC_SOFTWARE 5 /* Software generated exception */ /* Exact exception is in code field. */ /* Codes 0 - 0xFFFF reserved to hardware */ /* Codes 0x10000 - 0x1FFFF reserved for OS emulation (Unix) */ #define EXC_BREAKPOINT 6 /* Trace, breakpoint, etc. */ /* Details in code field. */
1c3e626ba98cdc435c786e4ff3b9b010b4452376
f710d659192211cd07f5017e3e7aa6e444091672
/ParNMPC/timersrc/timer_unix.c
0afd3b3fe06c226e76c6c757eb5c4d0e2d085802
[]
no_license
deng-haoyang/ParNMPC-Dev
8bb88ab9c1d598090ca5468f7f84478b63685ed9
e8e84346565e0df504b1608a6a57e93b5123b146
refs/heads/master
2022-11-27T22:47:57.087932
2020-08-07T05:29:28
2020-08-07T05:29:28
281,027,298
0
0
null
null
null
null
UTF-8
C
false
false
208
c
timer_unix.c
#include "timer_unix.h" double timer_unix(void) { double time; struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); time = t.tv_sec + t.tv_nsec/1000000000.0; return time; }
bbcfa3f07be045093521aa1505d6861dcef41e0c
aecf66cb7287833b9d229fe60be05c2315e17dc3
/vector/vector.c
f59a058c81d11ea72331a728fc1b4fdb6c769d5a
[]
no_license
Joker066/DS
d2ea6e5826b17b9cf366048dfff56c38997dfca4
00c12ea776fc96a483ebcd8bdbd6e4d2dd224208
refs/heads/master
2023-03-23T06:42:49.096386
2021-03-23T06:58:51
2021-03-23T06:58:51
346,686,621
0
0
null
null
null
null
UTF-8
C
false
false
8,103
c
vector.c
#include <stdlib.h> #include <stdio.h> typedef struct vector vector; //API prototype vector *new_vector(); void vector_dispose(vector*); void vector_expand(vector*); void vector_print(const vector*); int vector_size(const vector*); int vector_is_empty(const vector*); int vector_peek_front(const vector*); int vector_peek_back(const vector*); int vector_at(const vector*, int index); void vector_set(vector*, int index, int value); void vector_push_front(vector*, int); void vector_push_back(vector*, int); int vector_pop_front(vector*); int vector_pop_back(vector*); void vector_insert(vector*, int, int); void vector_remove(vector*, int); int vector_search(const vector*, int); //def struct vector { int size, capacity; int head, tail; int *array; void (*dispose)(vector *self); void (*print)(const vector *self); int (*length)(const vector *self); int (*is_empty)(const vector *self); int (*peek_front)(const vector *self); int (*peek_back)(const vector *self); int (*at)(const vector *self, int dex); void (*set)(vector *self, int index, int value); void (*push_front)(vector *self, int value); void (*push_back)(vector *self, int value); int (*pop_front)(vector *self); int (*pop_back)(vector *self); void (*insert)(vector *self, int index, int value); void (*remove)(vector *self, int index); int (*search)(const vector *self, int value); }; //API def vector *new_vector(){ vector *v = (vector*)malloc(sizeof(vector)); v->size = 0, v->capacity = 2; v->head = 0, v->tail = 0; v->array = (int*)malloc(v->capacity * sizeof(int)); v->dispose = vector_dispose; v->print = vector_print; v->length = vector_size; v->is_empty = vector_is_empty; v->peek_front = vector_peek_front; v->peek_back = vector_peek_back; v->at = vector_at; v->set = vector_set; v->push_front = vector_push_front; v->push_back = vector_push_back; v->pop_front = vector_pop_front; v->pop_back = vector_pop_back; v->insert = vector_insert; v->remove = vector_remove; v->search = vector_search; return v; } void vector_dispose(vector *self){ free(self->array); free(self); } void vector_expand(vector *self){ if (self->size < self->capacity) return; self->capacity <<= 1; int *ori_arr = self->array; int *new_arr = (int*)malloc(self->capacity * sizeof(int)); int i = self->head, j = 0; int s = 0; while (s < self->size) { new_arr[j] = ori_arr[i]; i = (i + 1) % self->capacity; j = (j + 1) % self->capacity; s++; } self->array = new_arr; self->head = 0; self->tail = (self->head + self->size - 1) % self->capacity; free(ori_arr); } void vector_print(const vector *self){ if (vector_is_empty(self)) { printf("empty.\n"); return; } printf("["); if (self->head <= self->tail) { for (int i = self->head; i < self->tail; i++) printf("%d, ", self->array[i]); } else{ for (int i = self->head; i < self->tail + self->capacity; i++) { i %= self->capacity; printf("%d, ", self->array[i]); } } printf("%d]\n", self->array[self->tail]); } int vector_size(const vector *self){ return self->size; } int vector_is_empty(const vector *self){ return self->size == 0; } int vector_peek_front(const vector *self){ if (vector_is_empty(self)) { printf("vector is empty. error code: "); return -1; } return self->array[self->head]; } int vector_peek_back(const vector *self){ if (vector_is_empty(self)) { printf("vector is empty. error code: "); return -1; } return self->array[self->tail]; } int vector_at(const vector *self, int index){ if (vector_is_empty(self)) { printf("vector is empty. error code: "); return -1; } if (index >= self->size) { printf("index out of range. error code: "); return -2; } return self->array[(self->head + index) % self->capacity]; } void vector_set(vector *self, int index, int value){ if (vector_is_empty(self)) printf("vector is empty. error code: -1\n"); if (index >= self->size) printf("index out of range. error code: -2\n"); self->array[(self->head + index) % self->capacity] = value; } void vector_push_front(vector *self, int value){ vector_expand(self); if (self->size > 0) self->head = !self->head ? self->capacity - 1 : self->head - 1; self->array[self->head] = value; self->size++; } void vector_push_back(vector *self, int value){ vector_expand(self); if (self->size > 0) self->tail = (self->tail + 1) % self->capacity; self->array[self->tail] = value; self->size++; } int vector_pop_front(vector *self){ if (vector_is_empty(self)) { printf("vector is empty. error code: "); return -1; } int pop = self->array[self->head]; self->head = (self->head + 1) % self->capacity; self->size--; return pop; } int vector_pop_back(vector *self){ if (vector_is_empty(self)) { printf("vector is empty. error code: "); return -1; } int pop = self->array[self->tail]; self->tail = !self->size ? self->capacity - 1 : self->tail - 1; self->size--; return pop; } void vector_insert(vector *self, int index, int value){ if (index < 0 || index > self->size) printf("index out of range. error code: -2\n"); if (index == self->size) { vector_push_back(self, value); return; } int new_index = (self->head + index) % self->capacity; if (vector_is_empty(self)) { self->array[new_index] = value; self->size++; return; } if (self->size < self->capacity) { int i = self->tail; int s = 0; while (s < self->size) { if (self->head <= self->tail || new_index <= self->tail) { if (new_index <= i) self->array[(i + 1) % self->capacity] = self->array[i]; if (new_index == i) { self->array[i] = value; break; } } else if (self->head <= new_index) { if (i <= self->tail || i >= new_index) self->array[(i + 1) % self->capacity] = self->array[i]; if (i == new_index) { self->array[i] = value; break; } } i = !i ? self->capacity - 1 : i - 1; s++; } self->tail = (self->tail + 1) % self->capacity; } else{ self->capacity <<= 1; int *ori_arr = self->array; int *new_arr = (int*)malloc(self->capacity * sizeof(int)); int i = self->tail, j = self->size - 1; int s = 0; while (s < self->size) { if (self->head <= self->tail || new_index <= self->tail) { if (new_index <= i) { new_arr[(j + 1) % self->capacity] = ori_arr[i]; if (i == new_index) new_arr[j] = value; } else new_arr[j] = ori_arr[i]; } else if (self->head <= new_index) { if (i <= self->tail || new_index <= i) { new_arr[(j + 1) % self->capacity] = ori_arr[i]; if (i == new_index) new_arr[j] = value; } else new_arr[j] = ori_arr[i]; } i = !i ? self->size - 1 : i -1; j = !j ? self->capacity - 1 : j - 1; s++; } self->array = new_arr; free(ori_arr); self->head = 0; self->tail = self->size; } self->size++; } void vector_remove(vector *self, int index){ if (vector_is_empty(self)) printf("vector is empty. error code: -1\n"); if (index >= self->size) printf("index out of range. error code: -2\n"); int new_index = (self->head + index) % self->capacity; if (self->size == 1) { self->tail = !self->tail ? self->size - 1 : self->tail - 1; self->size--; return; } int i = self->head; int s = 0; while (s < self->size) { if (self->head <= self->tail) { if (new_index <= i) self->array[i] = self->array[(i + 1) % self->capacity]; } else { if (new_index <= self->tail) { if (new_index <= i && i <= self->tail) self->array[i] = self->array[(i + 1) % self->capacity]; } else if (i <= self->tail || new_index <= i) self->array[i] = self->array[(i + 1) % self->capacity]; } i = (i + 1) % self->capacity; s++; } self->tail = !self->tail ? self->capacity - 1 : self->tail - 1; self->size--; } int vector_search(const vector *self, int value){ if (self->head <= self->tail) { for (int i = self->head; i < self->tail; i++) if (self->array[i] == value) return i - self->head; } else{ int index = 0; for (int i = self->head; i < self->tail + self->capacity; i++) { i %= self->capacity; if (self->array[i] == value) return index; index++; } } printf("not in vector. error code: "); return -3; }
61bfb4507b7b7c43a3ee9c00d3aa306c110c4717
932430b3bcf28b29b4136b918c67e8287df5e24c
/ps2keypolled.h
9d4061c9eaceab7fc3c9117feddb8adb736d02c4
[]
no_license
WestfW/ps2keypolled
9fc7929a6d3af07851544fba03b8c8036ba3b8ae
728c2eb92111831f6417410e87d133488daed50b
refs/heads/master
2021-01-02T23:07:27.628258
2018-03-12T02:38:12
2018-03-12T02:38:12
32,194,113
7
2
null
2018-03-12T02:38:13
2015-03-14T03:28:33
C
UTF-8
C
false
false
792
h
ps2keypolled.h
/* * ps2keypolled.h * Copyright 2009 by Bill Westfield * * defines for polled interface to PS2-like keyboards. */ #ifdef __cplusplus extern "C"{ #endif extern unsigned char ps2k_getcode(void); extern int ps2k_getkey(void); extern void ps2k_sendbyte(unsigned char); extern unsigned char ps2k_translate(int); extern void ps2k_init (unsigned char clock, unsigned char data); #ifdef __cplusplus } // extern "C" #endif #if defined(ARDUINO) && ARDUINO >= 100 #include "Arduino.h" #else #include "WProgram.h" #endif /* * Value to add to "extended" keycodes. Can be 0x80 to fit in a singlpe * byte, which ALMOST never conflicts with anything. Or it can be 100. */ #define PS2K_EXTEND 0x100 #define PS2K_NOKEY 0xFF extern unsigned char ps2k_clk, ps2k_dat;
dba0c3dd4b98e14c4e3acef4c5f2cbb7e2739ead
f81d56379cab754c75b5459e8e844fb0db37f259
/torch/lib/THD/master_worker/master/generic/THDTensorRandom.h
0857ebddaec6201b01de75ef16330bc7da15af65
[ "BSD-2-Clause", "BSD-3-Clause", "LicenseRef-scancode-generic-cla", "Apache-2.0" ]
permissive
ezyang/pytorch-unattached
f64620e0eb5acb236f8683530a4df9e33289dc33
11f19b43d2405d90d4b0b21986eba57a9329ac9a
refs/heads/c10
2023-08-02T06:30:48.239351
2018-06-25T18:58:54
2018-06-25T18:58:54
88,668,619
14
4
NOASSERTION
2022-11-18T07:26:45
2017-04-18T20:40:24
C++
UTF-8
C
false
false
1,813
h
THDTensorRandom.h
#ifndef TH_GENERIC_FILE #define TH_GENERIC_FILE "master_worker/master/generic/THDTensorRandom.h" #else THD_API void THDTensor_(random)(THDTensor *self, THDGenerator *_generator); THD_API void THDTensor_(geometric)(THDTensor *self, THDGenerator *_generator, double p); THD_API void THDTensor_(bernoulli)(THDTensor *self, THDGenerator *_generator, double p); THD_API void THDTensor_(bernoulli_FloatTensor)(THDTensor *self, THDGenerator *_generator, THDFloatTensor *p); THD_API void THDTensor_(bernoulli_DoubleTensor)(THDTensor *self, THDGenerator *_generator, THDDoubleTensor *p); THD_API void THDTensor_(uniform)(THDTensor *self, THDGenerator *_generator, double a, double b); THD_API void THDTensor_(normal)(THDTensor *self, THDGenerator *_generator, double mean, double stdv); THD_API void THDTensor_(exponential)(THDTensor *self, THDGenerator *_generator, double lambda); THD_API void THDTensor_(cauchy)(THDTensor *self, THDGenerator *_generator, double median, double sigma); THD_API void THDTensor_(logNormal)(THDTensor *self, THDGenerator *_generator, double mean, double stdv); THD_API void THDTensor_(multinomial)(THDLongTensor *self, THDGenerator *_generator, THDTensor *prob_dist, int n_sample, int with_replacement); #endif
e1bfe491c3dd142dce70eed31aba4960dacccc70
2137b6bdeca5aa6ae1115ea19915eef3df4e3daf
/pipeline.c
3a884d1c45751b51a5d85f371738add2a0dd5e7a
[]
no_license
NButler3112/CPE315_Lab7
55e61d570d1743859641c8ac81f0da74c29a9ee3
d7b2d5df82b2e4a053f661df174e84b527a817dd
refs/heads/master
2021-01-23T05:45:09.143673
2017-06-03T23:38:28
2017-06-03T23:38:28
92,984,142
0
0
null
null
null
null
UTF-8
C
false
false
7,277
c
pipeline.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "helper.h" #include "execute.h" MB_HDR mb_hdr; ADDR addr; IF_ID if_id; ID_EX id_ex; EX_MEM ex_mem; MEM_WB mem_wb; int haltflag = 0; unsigned clock_count; unsigned instr_count; unsigned instruction = 0; unsigned mem_pointer = 0; unsigned memory[1024]; unsigned registers[32] = { 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, 0}; unsigned rFlags[32] = { 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, 0}; static void checkArgc(int argc) { if (argc != 2) { fprintf(stderr, "Usage: ./pipeline testcase\n"); exit(EXIT_FAILURE); } } static FILE* openFile(char *fileName) { FILE* file = fopen(fileName, "rb"); if (file == NULL) { perror(NULL); exit(EXIT_FAILURE); } fread((void*) &mb_hdr, sizeof(mb_hdr), 1, file); if (strcmp(mb_hdr.signature, "~MB") != 0) { fprintf(stderr, "'%s' is not a mips_asm binary file.\n", fileName); fclose(file); exit(EXIT_FAILURE); } return file; } static void readInstr(FILE *file) { int n; while (mem_pointer < sizeof(memory)) { n = fread((void*) &memory[mem_pointer/4], 4, 1, file); if (n) mem_pointer += 4; else break; } } static IF_ID clearIfId(void) { IF_ID i; return i; } static EX_MEM clearExMem(void) { EX_MEM e; return e;; } static void wb() { if (mem_wb.active != 1) { /*fprintf(stderr, "WRITEBACK\n");*/ /*SAVING TO MEMORY (STORE)*/ if (mem_wb.memFlag == 1) { memory[mem_wb.memAddr] = mem_wb.value; } /*SAVING TO REGISTERS (EVERYTHING EXCEPT STORE)*/ else if (mem_wb.dReg != 0) registers[mem_wb.dReg] = mem_wb.value; /*SHOW REGISTERS AS AVAILABLE FOR USE*/ rFlags[mem_wb.dReg] = 0; } } static void mem() { if (ex_mem.active != 1) { /*fprintf(stderr, "MEMORY\n");*/ /*SET NORMAL EX_MEM VALUES*/ mem_wb.active = 1; mem_wb.dReg = ex_mem.dReg; mem_wb.memAddr = ex_mem.memAddr; mem_wb.value = ex_mem.aluOut; mem_wb.memFlag = 0; /*IF BRANCH OR JUMP IS HAPPENING*/ /*Must clear IF_ID and ID_EX registers. Set active to high to indicate * not execute since it doesn't have valid passing registers*/ addr.pc = ex_mem.nextPC; if (ex_mem.bjFlag == 1) { if_id = clearIfId(); id_ex = decodeInstr(0x00000000, 0x00000000); id_ex.iType = 'r'; if_id.active = 1; id_ex.active = 1; ex_mem.active = 1; /*printf("NEW PC BECAUSE OF BRANCH AND JUMP: 0x%08x\n", pc);*/ } /*IF MEMORY NEEDS TO BE ACCESS (READ OR WRITE)*/ /*Based on mFlag, determines new value (load) or memFlag (store)*/ else if (ex_mem.mFlag != 0) { switch(ex_mem.mFlag) { case 1: mem_wb.value = makeSignExtByte(memory[ex_mem.memAddr] & 0x000000FF); break; case 2: mem_wb.value = makeSignExtHalfWord(memory[ex_mem.memAddr] & 0x0000FFFF); break; case 3: mem_wb.value = memory[ex_mem.memAddr]; break; case 4: mem_wb.value = 0x000000FF & makeSignExtByte(memory[ex_mem.memAddr] &\ 0x000000FF); break; case 5: mem_wb.value = 0x0000FFFF & makeSignExtHalfWord(memory[ex_mem.memAddr] &\ 0x0000FFFF); break; case 10: mem_wb.memFlag = 1; break; } } mem_wb.active = 0; /*printMEM_WB(mem_wb);*/ } } static void ex() { if (id_ex.active != 1) { /*fprintf(stderr, "EXECUTE\n");*/ /*IF REGISTER INSTRUCTION*/ if (id_ex.iType == 'r') { ex_mem = executeR(id_ex, &haltflag); } /*IF JUMP INSTRUCTION*/ else if (id_ex.iType == 'j') { ex_mem = executeJ(id_ex); } /*IF IMMEDIATE INSTRUCTION*/ else if (id_ex.iType == 'i') { ex_mem = executeI(id_ex); } /*NO INVALID INSTRUCTION BC ALREADY HANDLED IN ID*/ /*IF REGISTER IS BEING EDITED*/ /*Clear passing register and set this function as active to wait for * updated value*/ if (ex_mem.dReg != 0 && rFlags[ex_mem.dReg] == 1) { clearExMem(); ex_mem.active = 1; } /*IF REGISTER IS NOT BEING EDITED*/ /*Set register flag to indicate is will being edited*/ if (rFlags[ex_mem.dReg] == 0) { ex_mem.active = 0; if (ex_mem.dReg != 0) rFlags[ex_mem.dReg] = 1; } /*printEX_MEM(ex_mem);*/ } } static void id() { if (if_id.active != 1) { /*fprintf(stderr, "DECODE\n");*/ /*Pull instruction variables from instuction no matter the instruction * type*/ id_ex = decodeInstr(if_id.instruction, if_id.nextPC); /*Determine instruction type*/ switch (id_ex.opcode) { case 0x00: id_ex.iType = 'r'; break; case 0x02: case 0x03: id_ex.iType = 'j'; break; case 0x04: case 0x05: case 0x08: case 0x09: case 0x0A: case 0x0B: case 0x0C: case 0x0D: case 0x0E: case 0x0F: case 0x20: case 0x21: case 0x23: case 0x24: case 0x25: case 0x28: case 0x29: case 0x2B: id_ex.iType = 'i'; break; default: /* Invalid Instruction */ invalidInstr(if_id.instruction, addr.pc); break; } /*PULL DATA FROM REGISTERS*/ id_ex.ra = registers[id_ex.rs]; id_ex.rb = registers[id_ex.rt]; id_ex.active = 0; /*printID_EX(id_ex);*/ } } static void instrF() { if (addr.old_pc != addr.pc) { addr.old_pc = addr.pc; instr_count += 1; if_id.active = 1; if_id.instruction = memory[addr.pc/4]; if_id.nextPC = addr.pc + 4; if_id.active = 0; } } static void printRegisters() { int i; printf("Registers:\n"); for (i = 0; i < 32; i++) { printf(" $%2d : 0x%08x\n", i, registers[i]); } } static void complete() { printRegisters(); printf("Instructions Run: %d\n", instr_count); printf("Clock Cycles: %d\n", clock_count); printf("CPI: %f\n", (float)clock_count / (float)instr_count); } int main(int argc, char **argv) { FILE *file; char *fileName; checkArgc(argc); fileName = argv[1]; file = openFile(fileName); readInstr(file); fclose(file); printInstr(mem_pointer, memory); if_id.active = 1; id_ex.active = 1; ex_mem.active = 1; mem_wb.active = 1; addr.pc = mb_hdr.entry; addr.old_pc = -1; for (haltflag = 0; haltflag == 0; clock_count++) { wb(); mem(); ex(); id(); instrF(); if (clock_count == 1000) { haltflag = 1; } } complete(); exit(EXIT_SUCCESS); }
910c8682154734b47b619baa2ab51bfadea5e5a4
1da663dea7462411c96851b84c9a489631a63f58
/paketti/dica/CHESIM/LIB13H.H
5c59cd9b4e7730019bb4181252c464b283b187ad
[]
no_license
keskival/turbo-pascal-experiments
14a8d9879da40a76b96719601d05a8249d78bc92
0d5fb15c0d42bb247b71a2353b6ce6b0919632de
refs/heads/master
2023-04-13T19:18:35.018619
2023-03-22T21:36:00
2023-03-22T21:36:00
91,951,639
14
5
null
null
null
null
UTF-8
C
false
false
1,045
h
LIB13H.H
/************************************************************************/ /* lib13h.h */ /************************************************************************/ #ifndef _chem_lib13h_h #define _chem_lib13h_h unsigned char *virt; void inline flips(char *virt) { int i=16000,eedeeii=0xA0000; int *virscr; virscr=(int *)virt; _farsetsel(_dos_ds); do { _farnspokel(eedeeii,*virscr); virscr++; eedeeii+=4; } while (--i); } void clear(char *virt) { int i=16000; int *virscr; virscr=(int *)virt; while (i--) *(virscr++)=0; } void setcolor(unsigned char num,unsigned char r, unsigned char g, unsigned char b) { outportb(0x3c8,num); outportb(0x3c9,r); outportb(0x3c9,g); outportb(0x3c9,b); } void init() { virt=(unsigned char *)malloc(64000); clear(virt); textmode(0x13); } void close() { free(virt); textmode(0x3); } #endif
6a4dbd266c876c4369ec784c61d3c36f6be3dfa6
07e6fc323f657d1fbfc24f861a278ab57338b80a
/cpp/common_SDL/SDL2OGL3/DrawField.h
5c0d1e91db9dc1422daf7614fae56340ee89bdba
[ "MIT" ]
permissive
ProkopHapala/SimpleSimulationEngine
99cf2532501698ee8a03b2e40d1e4bedd9a12609
47543f24f106419697e82771289172d7773c7810
refs/heads/master
2022-09-05T01:02:42.820199
2022-08-28T10:22:41
2022-08-28T10:22:41
40,007,027
35
4
null
null
null
null
UTF-8
C
false
false
2,010
h
DrawField.h
#ifndef DrawField_h #define DrawField_h typedef Vec3d (*VecFieldFunc)(Vec3d R); void plotVortexFilaments( int n, Vec3d* CPs, Vec3d dDir ){ glBegin(GL_LINE_STRIP); glColor3f(1.0,1.0,1.0); for(int i=0; i<n;i++){ glVertex3f( CPs[i].x, CPs[i].y, CPs[i].z ); } glEnd(); glColor3f(0.75,0.75,0.75); glBegin(GL_LINES); for(int i=0; i<n;i++){ Vec3d p = CPs[i]; glVertex3f( p.x, p.y, p.z ); p.add( dDir ); glVertex3f( p.x, p.y, p.z ); } glEnd(); }; void plotVecPlane( Vec2i n, Vec3d p0, Vec3d a, Vec3d b, double sz, double dt, VecFieldFunc func ){ glBegin(GL_LINES); for(int ia=0; ia<n.a; ia++ ){ for(int ib=0; ib<n.b; ib++ ){ Vec3d p = p0 + a*ia + b*ib; if( sz>0 ){ glVertex3f( p.x-sz, p.y , p.z ); glVertex3f( p.x+sz, p.y, p.z ); glVertex3f( p.x , p.y-sz, p.z ); glVertex3f( p.x, p.y+sz, p.z ); glVertex3f( p.x , p.y , p.z-sz ); glVertex3f( p.x, p.y, p.z+sz ); } glVertex3f( p.x, p.y, p.z ); Vec3d v = func(p); //printf( "(%f,%f,%f) (%f,%f,%f)\n", p.x, p.y, p.z, v.x, v.y, v.z ); p.add_mul( v, dt); glVertex3f( p.x, p.y, p.z ); } } glEnd(); } void plotStreamLine( int n, double dt, Vec3d p, VecFieldFunc func ){ glBegin(GL_LINE_STRIP); for(int i=0; i<n; i++ ){ Vec3d v = func(p); p.add_mul(v,dt); glVertex3f( p.x, p.y, p.z ); //printf( "(%f,%f,%f) (%f,%f,%f)\n", p.x, p.y, p.z, v.x, v.y, v.z ); } glEnd(); //exit(0); } void plotStreamLinePlane( Vec2i n, int ns, Vec3d p0, Vec3d a, Vec3d b, double dt, VecFieldFunc func ){ for(int ia=0; ia<n.a; ia++ ){ for(int ib=0; ib<n.b; ib++ ){ Vec3d p = p0 + a*ia + b*ib; //printf( "(%i,%i) (%f,%f,%f) \n", ia, ib, p.x, p.y, p.z ); plotStreamLine( ns, dt, p, func ); } } } #endif
1cdf585f63c9d03884146023f30ffafa27c2c7c0
37091577b141fff8c19f1a5f72bf582938d48063
/bricklet_linear_poti_v2.h
c6c59f96eb97903ccfe6b6417a5b9899ba23e0be
[ "CC0-1.0" ]
permissive
stif/tf-mcu-bindings
cc805e8cd5a709bc68a793021f9a5e536d501818
d0fbc77223441a558be28f78379813b63577ae3d
refs/heads/master
2023-07-28T01:10:49.414049
2021-09-20T14:10:25
2021-09-20T14:10:25
396,976,505
0
0
null
null
null
null
UTF-8
C
false
false
17,481
h
bricklet_linear_poti_v2.h
/* *********************************************************** * This file was automatically generated on 2020-09-10. * * * * C/C++ for Microcontrollers Bindings Version 2.0.0 * * * * If you have a bugfix for this file and want to commit it, * * please fix the bug in the generator. You can find a link * * to the generators git repository on tinkerforge.com * *************************************************************/ #ifndef TF_BRICKLET_LINEAR_POTI_V2_H #define TF_BRICKLET_LINEAR_POTI_V2_H #include "config.h" #include "tfp.h" #include "hal_common.h" #include "macros.h" #ifdef __cplusplus extern "C" { #endif /** * \defgroup BrickletLinearPotiV2 Linear Poti Bricklet 2.0 */ struct TF_LinearPotiV2; #ifdef TF_IMPLEMENT_CALLBACKS typedef void (*TF_LinearPotiV2PositionHandler)(struct TF_LinearPotiV2 *device, uint8_t position, void *user_data); #endif /** * \ingroup BrickletLinearPotiV2 * * 59mm linear potentiometer */ typedef struct TF_LinearPotiV2 { TF_TfpContext tfp; #ifdef TF_IMPLEMENT_CALLBACKS TF_LinearPotiV2PositionHandler position_handler; void *position_user_data; #endif uint8_t response_expected[1]; } TF_LinearPotiV2; /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_GET_POSITION 1 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_SET_POSITION_CALLBACK_CONFIGURATION 2 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_GET_POSITION_CALLBACK_CONFIGURATION 3 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_GET_SPITFP_ERROR_COUNT 234 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_SET_BOOTLOADER_MODE 235 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_GET_BOOTLOADER_MODE 236 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_SET_WRITE_FIRMWARE_POINTER 237 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_WRITE_FIRMWARE 238 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_SET_STATUS_LED_CONFIG 239 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_GET_STATUS_LED_CONFIG 240 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_GET_CHIP_TEMPERATURE 242 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_RESET 243 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_WRITE_UID 248 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_READ_UID 249 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_FUNCTION_GET_IDENTITY 255 #ifdef TF_IMPLEMENT_CALLBACKS /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_CALLBACK_POSITION 4 #endif /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_THRESHOLD_OPTION_OFF 'x' /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_THRESHOLD_OPTION_OUTSIDE 'o' /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_THRESHOLD_OPTION_INSIDE 'i' /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_THRESHOLD_OPTION_SMALLER '<' /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_THRESHOLD_OPTION_GREATER '>' /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_BOOTLOADER_MODE_BOOTLOADER 0 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_BOOTLOADER_MODE_FIRMWARE 1 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT 2 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT 3 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT 4 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_BOOTLOADER_STATUS_OK 0 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_BOOTLOADER_STATUS_INVALID_MODE 1 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_BOOTLOADER_STATUS_NO_CHANGE 2 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT 3 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT 4 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_BOOTLOADER_STATUS_CRC_MISMATCH 5 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_STATUS_LED_CONFIG_OFF 0 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_STATUS_LED_CONFIG_ON 1 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_STATUS_LED_CONFIG_SHOW_HEARTBEAT 2 /** * \ingroup BrickletLinearPotiV2 */ #define TF_LINEAR_POTI_V2_STATUS_LED_CONFIG_SHOW_STATUS 3 /** * \ingroup BrickletLinearPotiV2 * * This constant is used to identify a Linear Poti Bricklet 2.0. * * The {@link linear_poti_v2_get_identity} function and the * {@link IPCON_CALLBACK_ENUMERATE} callback of the IP Connection have a * \c device_identifier parameter to specify the Brick's or Bricklet's type. */ #define TF_LINEAR_POTI_V2_DEVICE_IDENTIFIER 2139 /** * \ingroup BrickletLinearPotiV2 * * This constant represents the display name of a Linear Poti Bricklet 2.0. */ #define TF_LINEAR_POTI_V2_DEVICE_DISPLAY_NAME "Linear Poti Bricklet 2.0" /** * \ingroup BrickletLinearPotiV2 * * Creates the device object \c linear_poti_v2 with the unique device ID \c uid and adds * it to the IPConnection \c ipcon. */ TF_ATTRIBUTE_NONNULL_ALL int tf_linear_poti_v2_create(TF_LinearPotiV2 *linear_poti_v2, const char *uid, TF_HalContext *hal); /** * \ingroup BrickletLinearPotiV2 * * Removes the device object \c linear_poti_v2 from its IPConnection and destroys it. * The device object cannot be used anymore afterwards. */ TF_ATTRIBUTE_NONNULL_ALL int tf_linear_poti_v2_destroy(TF_LinearPotiV2 *linear_poti_v2); /** * \ingroup BrickletLinearPotiV2 * * Returns the response expected flag for the function specified by the * \c function_id parameter. It is *true* if the function is expected to * send a response, *false* otherwise. * * For getter functions this is enabled by default and cannot be disabled, * because those functions will always send a response. For callback * configuration functions it is enabled by default too, but can be disabled * via the linear_poti_v2_set_response_expected function. For setter functions it is * disabled by default and can be enabled. * * Enabling the response expected flag for a setter function allows to * detect timeouts and other error conditions calls of this setter as well. * The device will then send a response for this purpose. If this flag is * disabled for a setter function then no response is sent and errors are * silently ignored, because they cannot be detected. */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_get_response_expected(TF_LinearPotiV2 *linear_poti_v2, uint8_t function_id, bool *ret_response_expected); /** * \ingroup BrickletLinearPotiV2 * * Changes the response expected flag of the function specified by the * \c function_id parameter. This flag can only be changed for setter * (default value: *false*) and callback configuration functions * (default value: *true*). For getter functions it is always enabled. * * Enabling the response expected flag for a setter function allows to detect * timeouts and other error conditions calls of this setter as well. The device * will then send a response for this purpose. If this flag is disabled for a * setter function then no response is sent and errors are silently ignored, * because they cannot be detected. */ TF_ATTRIBUTE_NONNULL_ALL int tf_linear_poti_v2_set_response_expected(TF_LinearPotiV2 *linear_poti_v2, uint8_t function_id, bool response_expected); /** * \ingroup BrickletLinearPotiV2 * * Changes the response expected flag for all setter and callback configuration * functions of this device at once. */ TF_ATTRIBUTE_NONNULL_ALL void tf_linear_poti_v2_set_response_expected_all(TF_LinearPotiV2 *linear_poti_v2, bool response_expected); #ifdef TF_IMPLEMENT_CALLBACKS /** * \ingroup BrickletLinearPotiV2 * * Registers the given \c handler to the Position callback. The * \c user_data will be passed as the last parameter to the \c handler. * * Signature: \code void callback(uint8_t position, void *user_data) \endcode * * This callback is triggered periodically according to the configuration set by * {@link tf_linear_poti_v2_set_position_callback_configuration}. * * The parameter is the same as {@link tf_linear_poti_v2_get_position}. */ TF_ATTRIBUTE_NONNULL(1) void tf_linear_poti_v2_register_position_callback(TF_LinearPotiV2 *linear_poti_v2, TF_LinearPotiV2PositionHandler handler, void *user_data); #endif #ifdef TF_IMPLEMENT_CALLBACKS /** * \ingroup BrickletLinearPotiV2 * * Polls for callbacks. Will block for the given timeout in microseconds. * * This function can be used in a non-blocking fashion by calling it with a timeout of 0. */ TF_ATTRIBUTE_NONNULL_ALL int tf_linear_poti_v2_callback_tick(TF_LinearPotiV2 *linear_poti_v2, uint32_t timeout_us); #endif /** * \ingroup BrickletLinearPotiV2 * * Returns the position of the linear potentiometer. The value is * between 0 (slider down) and 100 (slider up). * * * If you want to get the value periodically, it is recommended to use the * {@link tf_linear_poti_v2_register_position_callback} callback. You can set the callback configuration * with {@link tf_linear_poti_v2_set_position_callback_configuration}. */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_get_position(TF_LinearPotiV2 *linear_poti_v2, uint8_t *ret_position); /** * \ingroup BrickletLinearPotiV2 * * The period is the period with which the {@link tf_linear_poti_v2_register_position_callback} callback is triggered * periodically. A value of 0 turns the callback off. * * If the `value has to change`-parameter is set to true, the callback is only * triggered after the value has changed. If the value didn't change * within the period, the callback is triggered immediately on change. * * If it is set to false, the callback is continuously triggered with the period, * independent of the value. * * It is furthermore possible to constrain the callback with thresholds. * * The `option`-parameter together with min/max sets a threshold for the {@link tf_linear_poti_v2_register_position_callback} callback. * * The following options are possible: * * \verbatim * "Option", "Description" * * "'x'", "Threshold is turned off" * "'o'", "Threshold is triggered when the value is *outside* the min and max values" * "'i'", "Threshold is triggered when the value is *inside* or equal to the min and max values" * "'<'", "Threshold is triggered when the value is smaller than the min value (max is ignored)" * "'>'", "Threshold is triggered when the value is greater than the min value (max is ignored)" * \endverbatim * * If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period. */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_set_position_callback_configuration(TF_LinearPotiV2 *linear_poti_v2, uint32_t period, bool value_has_to_change, char option, uint8_t min, uint8_t max); /** * \ingroup BrickletLinearPotiV2 * * Returns the callback configuration as set by {@link tf_linear_poti_v2_set_position_callback_configuration}. */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_get_position_callback_configuration(TF_LinearPotiV2 *linear_poti_v2, uint32_t *ret_period, bool *ret_value_has_to_change, char *ret_option, uint8_t *ret_min, uint8_t *ret_max); /** * \ingroup BrickletLinearPotiV2 * * Returns the error count for the communication between Brick and Bricklet. * * The errors are divided into * * * ACK checksum errors, * * message checksum errors, * * framing errors and * * overflow errors. * * The errors counts are for errors that occur on the Bricklet side. All * Bricks have a similar function that returns the errors on the Brick side. */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_get_spitfp_error_count(TF_LinearPotiV2 *linear_poti_v2, uint32_t *ret_error_count_ack_checksum, uint32_t *ret_error_count_message_checksum, uint32_t *ret_error_count_frame, uint32_t *ret_error_count_overflow); /** * \ingroup BrickletLinearPotiV2 * * Sets the bootloader mode and returns the status after the requested * mode change was instigated. * * You can change from bootloader mode to firmware mode and vice versa. A change * from bootloader mode to firmware mode will only take place if the entry function, * device identifier and CRC are present and correct. * * This function is used by Brick Viewer during flashing. It should not be * necessary to call it in a normal user program. */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_set_bootloader_mode(TF_LinearPotiV2 *linear_poti_v2, uint8_t mode, uint8_t *ret_status); /** * \ingroup BrickletLinearPotiV2 * * Returns the current bootloader mode, see {@link tf_linear_poti_v2_set_bootloader_mode}. */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_get_bootloader_mode(TF_LinearPotiV2 *linear_poti_v2, uint8_t *ret_mode); /** * \ingroup BrickletLinearPotiV2 * * Sets the firmware pointer for {@link tf_linear_poti_v2_write_firmware}. The pointer has * to be increased by chunks of size 64. The data is written to flash * every 4 chunks (which equals to one page of size 256). * * This function is used by Brick Viewer during flashing. It should not be * necessary to call it in a normal user program. */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_set_write_firmware_pointer(TF_LinearPotiV2 *linear_poti_v2, uint32_t pointer); /** * \ingroup BrickletLinearPotiV2 * * Writes 64 Bytes of firmware at the position as written by * {@link tf_linear_poti_v2_set_write_firmware_pointer} before. The firmware is written * to flash every 4 chunks. * * You can only write firmware in bootloader mode. * * This function is used by Brick Viewer during flashing. It should not be * necessary to call it in a normal user program. */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_write_firmware(TF_LinearPotiV2 *linear_poti_v2, uint8_t data[64], uint8_t *ret_status); /** * \ingroup BrickletLinearPotiV2 * * Sets the status LED configuration. By default the LED shows * communication traffic between Brick and Bricklet, it flickers once * for every 10 received data packets. * * You can also turn the LED permanently on/off or show a heartbeat. * * If the Bricklet is in bootloader mode, the LED is will show heartbeat by default. */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_set_status_led_config(TF_LinearPotiV2 *linear_poti_v2, uint8_t config); /** * \ingroup BrickletLinearPotiV2 * * Returns the configuration as set by {@link tf_linear_poti_v2_set_status_led_config} */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_get_status_led_config(TF_LinearPotiV2 *linear_poti_v2, uint8_t *ret_config); /** * \ingroup BrickletLinearPotiV2 * * Returns the temperature as measured inside the microcontroller. The * value returned is not the ambient temperature! * * The temperature is only proportional to the real temperature and it has bad * accuracy. Practically it is only useful as an indicator for * temperature changes. */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_get_chip_temperature(TF_LinearPotiV2 *linear_poti_v2, int16_t *ret_temperature); /** * \ingroup BrickletLinearPotiV2 * * Calling this function will reset the Bricklet. All configurations * will be lost. * * After a reset you have to create new device objects, * calling functions on the existing ones will result in * undefined behavior! */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_reset(TF_LinearPotiV2 *linear_poti_v2); /** * \ingroup BrickletLinearPotiV2 * * Writes a new UID into flash. If you want to set a new UID * you have to decode the Base58 encoded UID string into an * integer first. * * We recommend that you use Brick Viewer to change the UID. */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_write_uid(TF_LinearPotiV2 *linear_poti_v2, uint32_t uid); /** * \ingroup BrickletLinearPotiV2 * * Returns the current UID as an integer. Encode as * Base58 to get the usual string version. */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_read_uid(TF_LinearPotiV2 *linear_poti_v2, uint32_t *ret_uid); /** * \ingroup BrickletLinearPotiV2 * * Returns the UID, the UID where the Bricklet is connected to, * the position, the hardware and firmware version as well as the * device identifier. * * The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). * A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always as * position 'z'. * * The device identifier numbers can be found :ref:`here <device_identifier>`. * |device_identifier_constant| */ TF_ATTRIBUTE_NONNULL(1) int tf_linear_poti_v2_get_identity(TF_LinearPotiV2 *linear_poti_v2, char ret_uid[8], char ret_connected_uid[8], char *ret_position, uint8_t ret_hardware_version[3], uint8_t ret_firmware_version[3], uint16_t *ret_device_identifier); #ifdef __cplusplus } #endif #endif
0eceba1e83cd0ed66a07a7626d4a693022257694
49ee0aef40f0cdf6d7d8313c1a38205fb29a468d
/NB15230赵铭骐/大作业 test4ios/Classes/Native/mscorlib_System_Collections_Generic_KeyValuePair_2_gen_2.h
db85964b27361438f53201c4a9bfbf487c8500e7
[ "MIT" ]
permissive
Rakerth/iPhone2015
50ddf5e2dd8f7eb2128a7ac931da4103406c213b
b27f4f65a67f6332b46bf95fd88aa2b61fdd8712
refs/heads/master
2021-01-19T07:23:12.672214
2016-01-13T09:01:43
2016-01-13T09:01:43
48,903,194
0
0
null
2016-01-02T15:06:05
2016-01-02T08:06:21
Objective-C
UTF-8
C
false
false
854
h
mscorlib_System_Collections_Generic_KeyValuePair_2_gen_2.h
#pragma once #include "il2cpp-config.h" #ifndef _MSC_VER # include <alloca.h> #else # include <malloc.h> #endif #include <stdint.h> // System.String struct String_t; // UnityStandardAssets.CrossPlatformInput.CrossPlatformInputManager/VirtualButton struct VirtualButton_t54; #include "mscorlib_System_ValueType.h" // System.Collections.Generic.KeyValuePair`2<System.String,UnityStandardAssets.CrossPlatformInput.CrossPlatformInputManager/VirtualButton> struct KeyValuePair_2_t1878 { // TKey System.Collections.Generic.KeyValuePair`2<System.String,UnityStandardAssets.CrossPlatformInput.CrossPlatformInputManager/VirtualButton>::key String_t* ___key_0; // TValue System.Collections.Generic.KeyValuePair`2<System.String,UnityStandardAssets.CrossPlatformInput.CrossPlatformInputManager/VirtualButton>::value VirtualButton_t54 * ___value_1; };
59995773d953b20500aa235a305739a23a15cd47
4dccea588745d5b21dfd2185d62f3604fbeaeda3
/testingCode/src/battery/battery.c
7f078b10d933c64bb3edb5a8ebfd76c60c305516
[]
no_license
eyl1302/project
b0c21eeb34aac795ff85300f5895909c8dfa4d89
8a2ae4a93912dcc7fc1b3de9e8960925718eaab5
refs/heads/master
2021-01-12T12:21:40.924238
2016-11-17T08:37:44
2016-11-17T08:37:44
72,457,928
0
0
null
null
null
null
UTF-8
C
false
false
6,107
c
battery.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <pthread.h> #include "common.h" #include "system.h" #include "battery.h" #include "bq27541.h" #include "batteryQueue.h" #include "systemQueue.h" // Varibale BATTERY_DEVICE_HANDLE batteryHandle; // Internal Function void fnBatteryThread(void *arg); void fnBatteryReplytoSystem(u8 reply); //void fnGGaugeProcess(BATTERY_DEVICE_HANDLE *batteryHandle); /* * date: 2016/09/22 * modify : hk * description: Create Battery Control Thread */ void fnBatteryThreadCreate(void) { pthread_t battery_thread; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); // Battery Thread pthread_attr_setstacksize(&attr, BATTERY_STACK_SIZE); if(pthread_create(&battery_thread, &attr, (void*)&fnBatteryThread, NULL)) printf("\n ### hk_dbg, %s : battery create fail!!\n", __FUNCTION__); pthread_attr_destroy(&attr); return; } //------------------------------------------------ /* * date: 2016/09/22 * modify : hk * description: Create Battery Control Thraed */ void fnBatteryThread(void *arg) { u8 reply; BATTERY_QUQEUE_T bty; // Initial Battery Queue fnBatteryQueueInit(); while(1) { // Pop From Queue if(fnBatteryQueuePop(&bty) == HK_SUCCESS) { if(bty.cmd == BQ_AUTOTEST) { // Process RTC Event reply = fnBatteryProcess(BC_START); // Reply To System fnBatteryReplytoSystem(reply); } } usleep(BATTERY_SLEEP_TIME); } return; } //------------------------------------------------ /* * date: 2016/09/22 * modify : hk * description: Reply to System Module */ void fnBatteryReplytoSystem(u8 reply) { SYSTEM_QUQEUE_T sys; sys.cmd = SC_REPLY; sys.func = SC_BATTERY; sys.reply = reply; // Push to System Queue fnSystemQueuePush(sys); return; } //------------------------------------------------ /* * date: 2016/07/11 * modify : hk * description: Initial Battery Control */ void fnBatteryInit(void) { // Craete Battery Thread fnBatteryThreadCreate(); // Point Battery Access Function to Device(bq27541...) batteryHandle.batteryFunc = &bq27541; return; } //------------------------------------------------ /* * date: 2016/07/12 * modify : hk * description: Debug Battery */ u8 fnBatteryDebug(void) { u8 idx; u32 cmd; while(1) { idx = 1; printf("\r\n ====================== Battery Debug ======================\r\n\n"); printf(" %d. Read Register \r\n\n", idx++); printf(" %d. Write Register \r\n\n", idx++); printf(" %d. Return \r\n\n", idx); printf(" Please Enter Command(1 ~ %d): ", idx); cmd = fnSystemInputString(); //hk_dbg("### hk_dbg, %s : cmd:%d\n", __FUNCTION__, cmd); switch(cmd) { case BD_REG_READ: { u8 reg; u8 data; char str[32]; printf("\n Please Inpu Register (Format:rr): "); scanf("\t %s", str); if(strlen(str) == BATTERY_REG_LEN) // a(2) { reg = fnStrToHEX(str, BATTERY_REG_STR, BATTERY_REG_LEN); batteryHandle.batteryFunc->pRegRead(reg, &data); printf("\n ### hk_dbg, %s : reg:0x%02x, data:0x%02x\n", __FUNCTION__, reg, data); } else printf("\n ### hk_dbg, %s : Format Error, Please try again!!\n", __FUNCTION__); } break; case BD_REG_WRITE: { u8 reg; u8 data; char str[64]; printf("\n Please Inpu Register & Data(Format:rrdd): "); scanf("\t %s", str); if(strlen(str) == (BATTERY_REG_LEN + BATTERY_DATA_LEN)) // r(2)+d(2) { reg = fnStrToHEX(str, BATTERY_REG_STR, BATTERY_REG_LEN); data = fnStrToHEX(str, BATTERY_DATA_STR, BATTERY_DATA_LEN); printf("\n ### hk_dbg, %s : reg:0x%02x, data:0x%02x\n", __FUNCTION__, reg, data); batteryHandle.batteryFunc->pRegWrite(reg, data); batteryHandle.batteryFunc->pRegRead(reg, &data); printf("\n ### hk_dbg, %s : reg:0x%02x, data:0x%02x\n", __FUNCTION__, reg, data); } else printf("\n ### hk_dbg, %s : Format Error, Please try again!!\n", __FUNCTION__); } break; case BD_RETURN: return HK_NA; break; default: hk_dbg("\n ### hk_dbg, %s : Unknow command:%d, Please Try again! \n", __FUNCTION__, cmd); break; } sleep(1); } return HK_NA; } //------------------------------------------------ /* * date: 2016/06/21 * modify : hk * description: Process Battery Event */ u8 fnBatteryProcess(u8 cmd) { u8 result = HK_NA; switch(cmd) { case BC_START: { result = batteryHandle.batteryFunc->pBatteryGet(&batteryHandle.battery); printf("\n "); system("date"); // Print date & time for read gas gauge printf("\n ### hk_dbg, %s, Capacity : %d!!\n", __FUNCTION__, batteryHandle.battery.cap); printf("\n ### hk_dbg, %s, Temperature : %d!!\n", __FUNCTION__, batteryHandle.battery.temp); printf("\n ### hk_dbg, %s, Current : %d!!\n", __FUNCTION__, batteryHandle.battery.cur); printf("\n ### hk_dbg, %s, Voltage : %d!!\n", __FUNCTION__, batteryHandle.battery.vol); printf("\n ### hk_dbg, %s, Status : %s!!\n", __FUNCTION__, batteryHandle.battery.status); if(result == HK_SUCCESS) { if(batteryHandle.battery.cap > CAPCITY_MIN) // Capacity { if(batteryHandle.battery.temp < TEMPERATURE_MAX) // Temperature { if(batteryHandle.battery.cur == CURRENT_MIN) // Current { if(batteryHandle.battery.vol > VOLTAGE_MIN) // Voltage { printf("\n ### hk_dbg, %s : Battery Pass!! \n", __FUNCTION__); return HK_SUCCESS; } } } } } printf("\n ### hk_dbg, %s : Battery Fail!! \n", __FUNCTION__); return HK_FAIL; } break; case BC_DBG: result = fnBatteryDebug(); break; default: hk_dbg("\n ### hk_dbg, %s : unknow battery command:%d, Please try again!!\n", __FUNCTION__, cmd); } return result; } //------------------------------------------------
94a92eac9152b1817333ee9121bdced4730757c6
cc4a505d441b4c079ff64480baf889ffcffe545e
/0001-0099/0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.c
bb9476f995d80e4f11f4131805bd73723ddb94e5
[]
no_license
vicch/leetcode
0ef0ba243d57d272f29d23ed0d834cf734ee55bb
b5a9cf15b9178deb22a6d373f1669c6990378ae2
refs/heads/master
2023-09-01T15:25:23.533562
2023-09-01T02:16:25
2023-09-01T02:16:25
67,243,892
0
0
null
null
null
null
UTF-8
C
false
false
2,575
c
0021-merge-two-sorted-lists.c
#include <stdio.h> #include <stdlib.h> #include <limits.h> struct ListNode { int val; struct ListNode* next; }; struct List { struct ListNode* head; struct ListNode* tail; }; struct ListNode* makeList(int* nums, int len); void printList(struct ListNode* head); struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2); int getNextVal(struct ListNode** l1, struct ListNode** l2); int main() { int seq1[] = {}; struct ListNode* lh1 = makeList(seq1, 0); printList(lh1); int seq2[] = {-5, 1}; struct ListNode* lh2 = makeList(seq2, 2); printList(lh2); struct ListNode* lh3 = mergeTwoLists(lh1, lh2); printList(lh3); return 0; } struct ListNode* makeList(int* nums, int len) { int i; struct ListNode* new; struct List* list = malloc(sizeof(struct List)); if (len == 0) return NULL; for (i = 0; i < len; i++) { new = malloc(sizeof(struct ListNode)); new->val = nums[i]; new->next = NULL; if (i == 0) { list->head = new; } else { list->tail->next = new; } list->tail = new; } return list->head; } void printList(struct ListNode* head) { struct ListNode *iter; if (head == NULL) { printf("\n"); return; } iter = head; while (iter->next != NULL) { printf("%d->", iter->val); iter = iter->next; } printf("%d\n", iter->val); } struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2) { struct ListNode* head; struct ListNode* tail; struct ListNode* new; int val; head = tail = NULL; while ((val = getNextVal(&l1, &l2)) != INT_MAX) { new = malloc(sizeof(struct ListNode)); new->val = val; new->next = NULL; if (head == NULL) { head = new; } else { tail->next = new; } tail = new; } return head; } int getNextVal(struct ListNode** l1, struct ListNode** l2) { int val; if (*l1 != NULL || *l2 != NULL) { if (*l1 == NULL) { val = (*l2)->val; *l2 = (*l2)->next; } else if (*l2 == NULL) { val = (*l1)->val; *l1 = (*l1)->next; } else { if ((*l1)->val < (*l2)->val) { val = (*l1)->val; *l1 = (*l1)->next; } else { val = (*l2)->val; *l2 = (*l2)->next; } } } else { val = INT_MAX; } return val; }
205283d0ba8705a6423826bf9f10d97992390635
4cd081f153102dd13a102f4476201cea9c634daf
/Platform Specific Builds/Arduino Uno/Scheduler/Scheduler Uno/scheduler/scheduler_timer.c
cbc0633618c026b2a7682215152b1b8bd964a68e
[]
no_license
prabhpreet/Scheduler
20534f20604db9b7095075a6f002244381ef3fb8
d53365b063b05bbcfb353a3073e31475a99901ef
refs/heads/master
2020-06-02T12:40:16.804264
2015-07-29T16:06:25
2015-07-29T16:06:25
27,505,756
0
0
null
null
null
null
UTF-8
C
false
false
1,001
c
scheduler_timer.c
/* * scheduler_timer.c * * Created: 27-12-2014 10:41:21 * Author: Prabhpreet */ #include "scheduler_timer.h" volatile time_t clock; volatile time_t compare; char str[10]; //ISR(TIMER_INTERRUPT) __attribute__ ( ( signal, naked ) ); void scheduler_timer_init() { cli(); TCCR0A = 0x00; TCCR0B = TIMER_PRESCALING_MODE; TIMSK0 = 0x01; clock = 0; compare = 0; sei(); } void scheduler_timer_stop() { cli(); TCCR0B = 0x00; clock = 0; sei(); } void scheduler_timer_set(time_t time) { compare = time; } ISR(TIMER_INTERRUPT, ISR_NAKED) { cli(); scheduler_save_context(); clock++; if(clock >= compare && compare != 0) //NULL never gonna happen! { if(task != NULL) { ready_queue_add(task); task->stack_pointer = SP; uart_println("R"); } SP = scheduler_sp; compare = 0; uart_println("Save."); scheduler_restore_context(); uart_println("Wow."); reti(); //Required since ISR is naked! } scheduler_restore_context(); reti(); //Required since ISR is naked! }
172f7fefde6d3350582e37d7173b0854379589f4
d209a4d3042969b9449d7ea3218acfc5839c4697
/clientLogin.c
305e829fc2759cc824a3b3ea02a06e66d023a287
[]
no_license
Kloakira/Linux-chatroom-socket
dd7bd1e32eeb55addae316a801b4977fd18af99e
1fcf7c1b4d499e4590048df4b3ad2a555640f538
refs/heads/main
2023-02-10T15:42:36.138091
2021-01-05T11:09:24
2021-01-05T11:09:24
326,970,243
11
0
null
null
null
null
UTF-8
C
false
false
2,252
c
clientLogin.c
#include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include <unistd.h> #include <string.h> #include <arpa/inet.h> #include <stdlib.h> #include <time.h> #include <sys/stat.h> #include <fcntl.h> #include "clientLogin.h" struct Msg msg; void Interface() { printf("====# MENU #===\n"); printf ("\t1. 注册\n"); printf ("\t2. 登录\n"); printf("====# #===\n"); } /**用户注册 消息内容设定为:#service 用户名:输入 密码:输入 操作类型cmd:1.注册 返回类型:改动过的msg.cmd 1002(成功) -1(失败)*/ void Reg(int sockfd) { char name[20]; char password[20]; strcpy(msg.msg,"#service"); printf("==UserName==:"); scanf("%s",name); while(getchar()!='\n'); strcpy(msg.name,name); printf("==PassWord==:"); scanf("%s",password); while(getchar()!='\n'); strcpy(msg.password,password); msg.cmd=1; write(sockfd,&msg,sizeof(msg)); read(sockfd,&msg,sizeof(msg)); printf("msg.cmd = %d\n", msg.cmd); if(msg.cmd==1001){ printf("Login success!waiting...\n"); } else if(msg.cmd==-1){ printf("the UserName has been used.\n"); printf("returning...\n"); sleep(1); } } /**用户登录 消息内容设定为:#service 用户名:输入 密码:输入 操作类型cmd:2.登录 返回类型:改动过的msg.cmd 1001(成功) -1(失败)*/ void Entry(int sockfd) { char name[20]; char password[20]; strcpy(msg.msg,"#service"); printf("==UserName==:"); scanf("%s",name); while(getchar()!='\n'); strcpy(msg.name,name); printf("==PassWord==:"); scanf("%s",password); strcpy(msg.password,password); msg.cmd=2; write(sockfd,&msg,sizeof(msg)); read(sockfd,&msg,sizeof(msg)); printf("msg.cmd = %d\n", msg.cmd); if(msg.cmd==-1){ printf("Fail To Login ,Please Resume Load...\n"); } else if(msg.cmd==1002){ printf("Login success ! waiting...\n"); } } //客户端 注册/登录的选择 struct Msg ask_server(int sockfd) { char ch[2]; while (1) { Interface(); scanf("%c",ch); while(getchar()!= '\n'); switch(ch[0]) { case '1': // 注册 Reg(sockfd); break; case '2': // 登录 Entry(sockfd); break; } sleep(2); system("clear"); return msg; } }
4da4bbfa0ae515a6b9031ca076941df522b891d9
4bd17bc9c6d934966f04539b799a152fd640183a
/deps/gettext/gettext-tools/gnulib-lib/csharpexec.c
1d8d0cc4ad1241a84ce0ad7392866963626a9569
[ "MIT", "GPL-1.0-or-later", "GPL-3.0-or-later", "GPL-3.0-only", "LGPL-2.1-or-later" ]
permissive
pereorga/poedit
60dd962515309fae8b84e08c4191eb108c6a03b8
b006bcde8f951487456420c2254bb1027a32b353
refs/heads/master
2020-06-25T15:00:00.798615
2019-07-28T22:42:52
2019-07-28T22:42:52
199,343,455
1
0
MIT
2019-07-28T22:42:53
2019-07-28T22:31:45
C++
UTF-8
C
false
false
9,849
c
csharpexec.c
/* Execute a C# program. Copyright (C) 2003-2016 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2003. 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 3 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, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <alloca.h> /* Specification. */ #include "csharpexec.h" #include <stdio.h> #include <stdlib.h> #include "execute.h" #include "sh-quote.h" #include "xmalloca.h" #include "error.h" #include "gettext.h" /* Handling of MONO_PATH is just like Java CLASSPATH. */ #define CLASSPATHVAR "MONO_PATH" #define new_classpath new_monopath #define set_classpath set_monopath #define reset_classpath reset_monopath #include "classpath.h" #include "classpath.c" #undef reset_classpath #undef set_classpath #undef new_classpath #undef CLASSPATHVAR /* Handling of clix' PATH variable is just like Java CLASSPATH. */ #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ /* Native Windows, Cygwin */ #define CLASSPATHVAR "PATH" #elif defined __APPLE__ && defined __MACH__ /* Mac OS X */ #define CLASSPATHVAR "DYLD_LIBRARY_PATH" #else /* Normal Unix */ #define CLASSPATHVAR "LD_LIBRARY_PATH" #endif #define new_classpath new_clixpath #define set_classpath set_clixpath #define reset_classpath reset_clixpath #include "classpath.h" #include "classpath.c" #undef reset_classpath #undef set_classpath #undef new_classpath #undef CLASSPATHVAR #define _(str) gettext (str) /* Survey of CIL interpreters. Program from ilrun pnet mono mono clix sscli With Mono, the MONO_PATH is a colon separated list of pathnames. (On Windows: semicolon separated list of pathnames.) We try the CIL interpreters in the following order: 1. "ilrun", because it is a completely free system. 2. "mono", because it is a partially free system but doesn't integrate well with Unix. 3. "clix", although it is not free, because it is a kind of "reference implementation" of C#. But the order can be changed through the --enable-csharp configuration option. */ static int execute_csharp_using_pnet (const char *assembly_path, const char * const *libdirs, unsigned int libdirs_count, const char * const *args, unsigned int nargs, bool verbose, bool quiet, execute_fn *executer, void *private_data) { static bool ilrun_tested; static bool ilrun_present; if (!ilrun_tested) { /* Test for presence of ilrun: "ilrun --version >/dev/null 2>/dev/null" */ char *argv[3]; int exitstatus; argv[0] = "ilrun"; argv[1] = "--version"; argv[2] = NULL; exitstatus = execute ("ilrun", "ilrun", argv, false, false, true, true, true, false, NULL); ilrun_present = (exitstatus == 0); ilrun_tested = true; } if (ilrun_present) { unsigned int argc; char **argv; char **argp; unsigned int i; bool err; argc = 1 + 2 * libdirs_count + 1 + nargs; argv = (char **) xmalloca ((argc + 1) * sizeof (char *)); argp = argv; *argp++ = "ilrun"; for (i = 0; i < libdirs_count; i++) { *argp++ = "-L"; *argp++ = (char *) libdirs[i]; } *argp++ = (char *) assembly_path; for (i = 0; i < nargs; i++) *argp++ = (char *) args[i]; *argp = NULL; /* Ensure argv length was correctly calculated. */ if (argp - argv != argc) abort (); if (verbose) { char *command = shell_quote_argv (argv); printf ("%s\n", command); free (command); } err = executer ("ilrun", "ilrun", argv, private_data); freea (argv); return err; } else return -1; } static int execute_csharp_using_mono (const char *assembly_path, const char * const *libdirs, unsigned int libdirs_count, const char * const *args, unsigned int nargs, bool verbose, bool quiet, execute_fn *executer, void *private_data) { static bool mono_tested; static bool mono_present; if (!mono_tested) { /* Test for presence of mono: "mono --version >/dev/null 2>/dev/null" */ char *argv[3]; int exitstatus; argv[0] = "mono"; argv[1] = "--version"; argv[2] = NULL; exitstatus = execute ("mono", "mono", argv, false, false, true, true, true, false, NULL); mono_present = (exitstatus == 0); mono_tested = true; } if (mono_present) { char *old_monopath; char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *)); unsigned int i; bool err; /* Set MONO_PATH. */ old_monopath = set_monopath (libdirs, libdirs_count, false, verbose); argv[0] = "mono"; argv[1] = (char *) assembly_path; for (i = 0; i <= nargs; i++) argv[2 + i] = (char *) args[i]; if (verbose) { char *command = shell_quote_argv (argv); printf ("%s\n", command); free (command); } err = executer ("mono", "mono", argv, private_data); /* Reset MONO_PATH. */ reset_monopath (old_monopath); freea (argv); return err; } else return -1; } static int execute_csharp_using_sscli (const char *assembly_path, const char * const *libdirs, unsigned int libdirs_count, const char * const *args, unsigned int nargs, bool verbose, bool quiet, execute_fn *executer, void *private_data) { static bool clix_tested; static bool clix_present; if (!clix_tested) { /* Test for presence of clix: "clix >/dev/null 2>/dev/null ; test $? = 1" */ char *argv[2]; int exitstatus; argv[0] = "clix"; argv[1] = NULL; exitstatus = execute ("clix", "clix", argv, false, false, true, true, true, false, NULL); clix_present = (exitstatus == 0 || exitstatus == 1); clix_tested = true; } if (clix_present) { char *old_clixpath; char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *)); unsigned int i; bool err; /* Set clix' PATH variable. */ old_clixpath = set_clixpath (libdirs, libdirs_count, false, verbose); argv[0] = "clix"; argv[1] = (char *) assembly_path; for (i = 0; i <= nargs; i++) argv[2 + i] = (char *) args[i]; if (verbose) { char *command = shell_quote_argv (argv); printf ("%s\n", command); free (command); } err = executer ("clix", "clix", argv, private_data); /* Reset clix' PATH variable. */ reset_clixpath (old_clixpath); freea (argv); return err; } else return -1; } bool execute_csharp_program (const char *assembly_path, const char * const *libdirs, unsigned int libdirs_count, const char * const *args, bool verbose, bool quiet, execute_fn *executer, void *private_data) { unsigned int nargs; int result; /* Count args. */ { const char * const *arg; for (nargs = 0, arg = args; *arg != NULL; nargs++, arg++) ; } /* First try the C# implementation specified through --enable-csharp. */ #if CSHARP_CHOICE_PNET result = execute_csharp_using_pnet (assembly_path, libdirs, libdirs_count, args, nargs, verbose, quiet, executer, private_data); if (result >= 0) return (bool) result; #endif #if CSHARP_CHOICE_MONO result = execute_csharp_using_mono (assembly_path, libdirs, libdirs_count, args, nargs, verbose, quiet, executer, private_data); if (result >= 0) return (bool) result; #endif /* Then try the remaining C# implementations in our standard order. */ #if !CSHARP_CHOICE_PNET result = execute_csharp_using_pnet (assembly_path, libdirs, libdirs_count, args, nargs, verbose, quiet, executer, private_data); if (result >= 0) return (bool) result; #endif #if !CSHARP_CHOICE_MONO result = execute_csharp_using_mono (assembly_path, libdirs, libdirs_count, args, nargs, verbose, quiet, executer, private_data); if (result >= 0) return (bool) result; #endif result = execute_csharp_using_sscli (assembly_path, libdirs, libdirs_count, args, nargs, verbose, quiet, executer, private_data); if (result >= 0) return (bool) result; if (!quiet) error (0, 0, _("C# virtual machine not found, try installing pnet")); return true; }
ad91b7571efb41af34c647782ed4e40560b6304a
ad57ffe2372cf614796e316b4865ba02a760acab
/nlopt/stop.c
94c60fefc46f1d841bd874acfe6a0f9011a95d92
[ "LGPL-2.0-or-later", "LGPL-2.1-only", "BSD-3-Clause" ]
permissive
NREL/ssc
6208c26a9bbab21d7beca630d61b8640fe073f49
38860345e14a14357cf2ad4f1918729a0c7ac0c6
refs/heads/develop
2023-08-30T10:09:17.654286
2023-08-16T20:27:59
2023-08-16T20:27:59
94,245,800
74
84
BSD-3-Clause
2023-09-14T20:03:50
2017-06-13T18:40:17
C++
UTF-8
C
false
false
4,058
c
stop.c
/* Copyright (c) 2007-2012 Massachusetts Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include <math.h> #include "nlopt-util.h" /* utility routines to implement the various stopping criteria */ static int relstop(double vold, double vnew, double reltol, double abstol) { if (nlopt_isinf(vold)) return 0; return(fabs(vnew - vold) < abstol || fabs(vnew - vold) < reltol * (fabs(vnew) + fabs(vold)) * 0.5 || (reltol > 0 && vnew == vold)); /* catch vnew == vold == 0 */ } int nlopt_stop_ftol(const nlopt_stopping *s, double f, double oldf) { return (relstop(oldf, f, s->ftol_rel, s->ftol_abs)); } int nlopt_stop_f(const nlopt_stopping *s, double f, double oldf) { return (f <= s->minf_max || nlopt_stop_ftol(s, f, oldf)); } int nlopt_stop_x(const nlopt_stopping *s, const double *x, const double *oldx) { unsigned i; for (i = 0; i < s->n; ++i) if (!relstop(oldx[i], x[i], s->xtol_rel, s->xtol_abs[i])) return 0; return 1; } int nlopt_stop_dx(const nlopt_stopping *s, const double *x, const double *dx) { unsigned i; for (i = 0; i < s->n; ++i) if (!relstop(x[i] - dx[i], x[i], s->xtol_rel, s->xtol_abs[i])) return 0; return 1; } static double sc(double x, double smin, double smax) { return smin + x * (smax - smin); } /* some of the algorithms rescale x to a unit hypercube, so we need to scale back before we can compare to the tolerances */ int nlopt_stop_xs(const nlopt_stopping *s, const double *xs, const double *oldxs, const double *scale_min, const double *scale_max) { unsigned i; for (i = 0; i < s->n; ++i) if (relstop(sc(oldxs[i], scale_min[i], scale_max[i]), sc(xs[i], scale_min[i], scale_max[i]), s->xtol_rel, s->xtol_abs[i])) return 1; return 0; } int nlopt_stop_evals(const nlopt_stopping *s) { return (s->maxeval > 0 && s->nevals >= s->maxeval); } int nlopt_stop_time_(double start, double maxtime) { return (maxtime > 0 && nlopt_seconds() - start >= maxtime); } int nlopt_stop_time(const nlopt_stopping *s) { return nlopt_stop_time_(s->start, s->maxtime); } int nlopt_stop_evalstime(const nlopt_stopping *stop) { return nlopt_stop_evals(stop) || nlopt_stop_time(stop); } int nlopt_stop_forced(const nlopt_stopping *stop) { return stop->force_stop && *(stop->force_stop); } unsigned nlopt_count_constraints(unsigned p, const nlopt_constraint *c) { unsigned i, count = 0; for (i = 0; i < p; ++i) count += c[i].m; return count; } unsigned nlopt_max_constraint_dim(unsigned p, const nlopt_constraint *c) { unsigned i, max_dim = 0; for (i = 0; i < p; ++i) if (c[i].m > max_dim) max_dim = c[i].m; return max_dim; } void nlopt_eval_constraint(double *result, double *grad, const nlopt_constraint *c, unsigned n, const double *x) { if (c->f) result[0] = c->f(n, x, grad, c->f_data); else c->mf(c->m, result, n, x, grad, c->f_data); }
09559a1ac0abae45ececc55e03c15afbbf7ea531
515123319bc4164ec6c12919cf11ef399d2adaa5
/lab_10_01_02/inc/stack_functions.h
bfca283b46ea63a3573ac8203d6d860988ea24a9
[ "MIT" ]
permissive
Untouchabl3Pineapple/iu7-c
1897b5f338cd35553924e5f73bfe9c3b7906c67c
c1d47eab5cf3c816aa3aaa1c3d4d9a042b1747fa
refs/heads/master
2023-02-03T02:16:12.126180
2020-12-29T16:03:24
2020-12-29T16:03:24
325,328,489
3
1
null
null
null
null
UTF-8
C
false
false
346
h
stack_functions.h
#ifndef __STACK_FUNCTIONS_H__ #define __STACK_FUNCTIONS_H__ #include <stdlib.h> #include "constants.h" #include "data_structures.h" #include "memory_functions.h" int push(node_t **head, const int coefficient, const int degree); int del(node_t **head); int empty(node_t *head); int reverse(node_t **head); #endif // __STACK_FUNCTIONS_H__
42b377096d300a908be369793edfb5de24673da0
de3e7248a696702c641037edb290652bb7d4a867
/0x05-pointers_arrays_strings/0-reset_to_98.c
7b6dcb4322c9147bcdf46496ec28db34aecfa749
[]
no_license
santizabe/holbertonschool-low_level_programming
63c90df0ed5941708e1c7a07de01916868c8d609
5f8846703635c70bc783c8d2ac6f4130af3eb82a
refs/heads/master
2023-01-22T20:00:40.792633
2020-12-03T21:41:29
2020-12-03T21:41:29
271,411,194
0
0
null
null
null
null
UTF-8
C
false
false
150
c
0-reset_to_98.c
#include <stdio.h> /** * reset_to_98 - resets any int to 98 * @n: char to be reseted */ void reset_to_98(int *n) { int **b; b = &n; **b = 98; }
93a213a24e07c85f9b8398ed8ca21a8c9cac3af6
8207db10624d6f7531e1ad9e4e35fb4df3de51e2
/Parallel/program/lec3/a.c
4cf45ffb0790b004ddcbd074baaafb96a67ed06d
[]
no_license
JianWang2018/Course
25a70483338ffadbe9ea45c63e64dcc9bfd54bb9
6707dcab8c85f1e4060f087ac7667e9cf6c39c67
refs/heads/master
2018-10-27T00:08:18.466335
2018-10-04T23:54:30
2018-10-04T23:54:30
83,001,713
2
0
null
null
null
null
UTF-8
C
false
false
408
c
a.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(int argc, char* argv[]) { int i; char *my[2]; if (argc < 2) { printf("Usage: a.out command\n"); exit(0); } for (i = 1; i< argc; i++) { my[0] = argv[i]; my[1] = NULL; if (fork() == 0) { if(execv(argv[i], &my[0]) == -1) { printf("Command execution failed.\n"); exit(0); } } } }
1892f23afd25e2d3a3fb95825e9737d17ad32725
41ac1c41d73538ae4c3dfe53a0ecca0eddf75d48
/C-Programming/11-C-Characters-Strings/06.Palindromes/main.c
61c69323d1916ee3f9ea013871ca6ceeb6df6464
[]
no_license
lyudoGO/SoftUniOpenCourses
c71d3fab91425bffd5846f787404a76eb8bef63c
203696397e764eb074d52fff28fed83869ac2339
refs/heads/master
2021-01-18T23:43:11.188718
2016-06-21T09:33:44
2016-06-21T09:33:44
47,958,309
0
0
null
null
null
null
UTF-8
C
false
false
3,190
c
main.c
/* * Write a program that extracts from a given text all palindromes, * e.g. ABBA, lamal, exe and prints them on the console on a single line, * separated by comma and space. Use spaces, commas, dots, question marks and * exclamation marks as word delimiters. Print only unique palindromes, * sorted lexicographically. String comparison should be case-sensitive. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define PALINDROME_COUNT 8 int is_palindrome(char *word, char wordLen); void print_palindromes(char **palindromes, size_t size); int is_contains(char **palindromes, char *palindrome, size_t size); int str_cmp(const void *first, const void *second) ; int main(int argc, char** argv) { char *text = NULL, delemiters[6] = " .,?!"; size_t textSize; printf("Please, enter a text: "); size_t textLen = getline(&text, &textSize, stdin); text[textLen - 1] = '\0'; char **palindromes = calloc(PALINDROME_COUNT, sizeof(char *)); if (!palindromes) { printf("Not enough memory!"); return 1; } size_t count = 0; char *token = strtok(text, delemiters); while (token) { size_t wordLen = strlen(token); if (is_palindrome(token, wordLen)) { palindromes[count] = malloc(wordLen); if (!is_contains(palindromes, token, count)) { strcpy(palindromes[count], token); count++; } } token = strtok(NULL, delemiters); } size_t stringsLen = count - 1 / sizeof(char *); qsort(palindromes, stringsLen, sizeof(char *), str_cmp); print_palindromes(palindromes, count); // release memory while (count > 0) { free(palindromes[count]); count--; } free(text); free(palindromes); return (EXIT_SUCCESS); } int is_palindrome(char *word, char wordLen) { size_t i, isPalindrome = 1; for (i = 0; i < wordLen / 2; i++) { if (word[i] != word[wordLen - 1 - i]) { isPalindrome = 0; } } return isPalindrome; } void print_palindromes(char **palindromes, size_t size) { size_t i; for (i = 0; i < size; i++) { if (i == size - 1) { printf("%s\n", palindromes[i]); } else { printf("%s, ", palindromes[i]); } } } int is_contains(char **palindromes, char *palindrome, size_t size) { size_t i, isContains = 0; for (i = 0; i <= size; i++) { if (strstr(palindromes[i], palindrome)) { isContains = 1; break; } } return isContains; } /* qsort C-string comparison function */ int str_cmp(const void *first, const void *second) { const char *ptrFirst = *(const char **)first; const char *ptrSecond = *(const char **)second; size_t firstLen = strlen(first); size_t secondLen = strlen(second); char lowerFirst[firstLen], lowerSecond[secondLen]; strcpy(lowerFirst, ptrFirst); strcpy(lowerSecond, ptrSecond); return strcmp(strlwr(lowerFirst), strlwr(lowerSecond)); }
08b2e6cff7ff4cdd9722e62fc40d05d04e68f892
24700ea55cf10f83efbf2b85b1939b84e7312a03
/examples/main_HH_Channel_Noise_LowMemory.c
2770e1a9397d2f2f73be54b099de412182b90da2
[]
no_license
mbiggio/SDEint
eb49d2a17ca2c890d4a82e9164625298235c89b8
0c16f00950c148d84f1768096742749a3de13507
refs/heads/master
2021-01-25T10:44:35.602535
2015-04-03T23:05:36
2015-04-03T23:05:36
33,385,381
2
0
null
null
null
null
UTF-8
C
false
false
1,684
c
main_HH_Channel_Noise_LowMemory.c
#include <stdlib.h> #include <stdio.h> #include <time.h> #include <math.h> #include <gsl/gsl_rng.h> #include <gsl/gsl_randist.h> #include <gsl/gsl_cblas.h> #include "Solver.h" #include "HH_Channel_Noise.h" int main(int argc, char* argv[]) { FILE* f_in; f_in = fopen("input_HH_CN.dat","r"); double pars[10]; double Tspan[2]; Tspan[0] = 0.0; double dt; int print_step; char outfile[50]; double th = -20.0; if(!ParseData_HH_Channel_Noise(pars,Tspan,outfile,&dt,&print_step,f_in)) return 1; fclose(f_in); FILE* f_out; f_out = fopen(outfile,"w"); double x0[15] = {0.1, 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}; // Allocation and Initialization of Random Number Generator const gsl_rng_type * T; gsl_rng * r; gsl_rng_env_setup(); T = gsl_rng_default; r = gsl_rng_alloc(T); gsl_rng_set(r,1); #ifdef LYAP // Parameters for the Calculation of the Maximum LE gsl_rng * r_lyap; r_lyap = gsl_rng_alloc(T); gsl_rng_set(r_lyap,1); double tau = 10*dt; double alpha = 1e-8; double lyapexp = 0; SdeSolverLyapLog(Stepper_EM,Update_VF_HH_Channel_Noise,Update_Diffusion_HH_Channel_Noise,Update_Diffusion_Deriv_HH_Channel_Noise,Tspan,x0,15,12,dt,pars,r,r_lyap,tau,alpha,&lyapexp,f_out,print_step); printf("Computed value of maximum Lyapunov Exponent: %f\n",lyapexp); #else SdeSolverSpikeDetection(Stepper_EM,Update_VF_HH_Channel_Noise,Update_Diffusion_HH_Channel_Noise,Update_Diffusion_Deriv_HH_Channel_Noise,Tspan,x0,15,12,dt,pars,r,f_out,th,1); #endif fclose(f_out); return 0; }
be10a0f6494b3274e57f4a58cc14ce0113fcf892
6c1d2d4cb0c02dfcb58734117451406e1ea31921
/xspice/mif/mifmpara.c
5afbc7b009dc5e9eeab4e732b4aa7cb1c497fa9b
[]
no_license
kakungulu/ramspice
29176a5df927e2fa2fcd280b556f7a2d9e393da5
10e5f97c7e2e548c8e7f79c8723e5fca3fba42e0
refs/heads/master
2021-07-01T16:50:10.465953
2015-05-06T23:53:07
2015-05-06T23:53:07
30,081,733
0
1
null
null
null
null
UTF-8
C
false
false
5,968
c
mifmpara.c
#include "ramspice_types.h" /*============================================================================ FILE MIFmParam.c MEMBER OF process XSPICE Copyright 1991 Georgia Tech Research Corporation Atlanta, Georgia 30332 All Rights Reserved PROJECT A-8503 AUTHORS 9/12/91 Bill Kuhn MODIFICATIONS <date> <person name> <nature of modifications> SUMMARY This file contains the function used to assign the value of a parameter read from the .model card into the appropriate structure in the model. INTERFACES MIFmParam() REFERENCED FILES None. NON-STANDARD FEATURES None. ============================================================================*/ /* #include "prefix.h" */ #include "ngspice/ngspice.h" #include <stdio.h> //#include "CONST.h" //#include "util.h" #include "ngspice/ifsim.h" //#include "resdefs.h" #include "ngspice/devdefs.h" #include "ngspice/sperror.h" #include <string.h> #include "ngspice/mifproto.h" #include "ngspice/mifparse.h" #include "ngspice/mifdefs.h" #include "ngspice/mifcmdat.h" /* #include "suffix.h" */ /* MIFmParam This function is called by SPICE/Nutmeg to set the value of a parameter on a model according to information parsed from a .model card or information supplied interactively by a user. It takes the value of the parameter input in an IFvalue structure and sets the parameter on the specified model structure. Unlike the procedure for SPICE 3C1 devices, MIFmParam does not use enumerations for identifying the parameter to set. Instead, the parameter is identified directly by the index value of the parameter in the SPICEdev.DEVpublic.modelParms array. */ int MIFmParam( int param_index, /* The parameter to set */ IFvalue *value, /* The value of the parameter */ GENmodel *inModel) /* The model structure on which to set the value */ { MIFmodel *model; int mod_type; int value_type; int i; Mif_Boolean_t is_array; /* Arrange for access to MIF specific data in the model */ model = (MIFmodel *) inModel; /* Get model type */ mod_type = model->MIFmodType; if((mod_type < 0) || (mod_type >= DEVmaxnum)) return(E_BADPARM); /* Check parameter index for validity */ if((param_index < 0) || (param_index >= model->num_param)) return(E_BADPARM); /* get value type to know which members of unions to access */ value_type = DEVices[mod_type]->DEVpublic.modelParms[param_index].dataType; value_type &= IF_VARTYPES; /* determine if the parameter is an array or not */ is_array = value_type & IF_VECTOR; /* initialize the parameter is_null and size elements and allocate elements */ model->param[param_index]->is_null = MIF_FALSE; if(is_array) { model->param[param_index]->size = value->v.numValue; model->param[param_index]->element = TMALLOC(Mif_Value_t, value->v.numValue); } else { model->param[param_index]->size = 1; model->param[param_index]->element = TMALLOC(Mif_Value_t, 1); } /* Transfer the values from the SPICE3C1 value union to the param elements */ /* This is analagous to what SPICE3 does with other device types */ if(! is_array) { switch(value_type) { case IF_FLAG: model->param[param_index]->element[0].bvalue = value->iValue; break; case IF_INTEGER: model->param[param_index]->element[0].ivalue = value->iValue; break; case IF_REAL: model->param[param_index]->element[0].rvalue = value->rValue; break; case IF_STRING: /* we don't trust the caller to keep the string alive, so copy it */ model->param[param_index]->element[0].svalue = TMALLOC(char, 1 + strlen(value->sValue)); strcpy(model->param[param_index]->element[0].svalue, value->sValue); break; case IF_COMPLEX: /* we don't trust the caller to have a parallel complex structure */ /* so copy the real and imaginary parts explicitly */ model->param[param_index]->element[0].cvalue.real = value->cValue.real; model->param[param_index]->element[0].cvalue.imag = value->cValue.imag; break; default: return(E_BADPARM); } } else { /* it is an array */ for(i = 0; i < value->v.numValue; i++) { switch(value_type) { case IF_FLAGVEC: model->param[param_index]->element[i].bvalue = value->v.vec.iVec[i]; break; case IF_INTVEC: model->param[param_index]->element[i].ivalue = value->v.vec.iVec[i]; break; case IF_REALVEC: model->param[param_index]->element[i].rvalue = value->v.vec.rVec[i]; break; case IF_STRINGVEC: /* we don't trust the caller to keep the string alive, so copy it */ model->param[param_index]->element[i].svalue = TMALLOC(char, 1 + strlen(value->v.vec.sVec[i])); strcpy(model->param[param_index]->element[i].svalue, value->v.vec.sVec[i]); break; case IF_CPLXVEC: /* we don't trust the caller to have a parallel complex structure */ /* so copy the real and imaginary parts explicitly */ model->param[param_index]->element[i].cvalue.real = value->v.vec.cVec[i].real; model->param[param_index]->element[i].cvalue.imag = value->v.vec.cVec[i].imag; break; default: return(E_BADPARM); } /* end switch */ } /* end for number of elements of vector */ } /* end else */ return(OK); }
f0e471306bac690eeecede758dc15f8e85a64704
1844898c96e08d69229d143cc8658dd6dd1173ef
/loader/krn/dm_path.c
f8d79f4acb7bd8608a1925bcbf6c94601add25d2
[]
no_license
slabs-forge/nkos
ec8b7f6672f81e94741a092e84fc5eef59e31975
9afaa67cecfb6b9ad5e98a84b563730f3b07522e
refs/heads/master
2021-01-02T03:54:10.296061
2020-02-10T09:49:33
2020-02-10T09:49:33
239,474,861
0
0
null
null
null
null
UTF-8
C
false
false
2,482
c
dm_path.c
/* * NK Loader - Kernel functions * * Author : Sebastien LAURENT * Date : 02/09/2011 * * Device Manager (Disk) path utilities */ #include "loader/utl/string.h" #include "loader/utl/stdio.h" #include "loader/krn/dm_path.h" struct dm_path_t { uint32_t s; uint32_t p; uint32_t n; } __attribute__((aligned (4))); /* * Liberation d'un path */ void dm_path_free(struct dm_path_t* path) { free(path); } /* * Creation d'un dm_path_t */ struct dm_path_t* dm_path_create(const char* filename) { struct dm_path_t* path; uint32_t n = strlen(filename); path =(struct dm_path_t*) malloc(n+sizeof(struct dm_path_t)); if (path == 0) return path; path->s = 0; path->p = 0; path->n = n; memmove(path+1,filename,n); dm_path_next(path); return path; } /* * Prefixer un chemin */ struct dm_path_t* dm_path_prepend(struct dm_path_t* path, const char* name) { struct dm_path_t* new; char* s = (char*)(path+1); char* d; size_t l = strlen(name); size_t sep = 0; if (l>0 && name[l-1] != '/') { l++; sep = 1; } if (l >= path->s) { new = (struct dm_path_t*) malloc(path->n - path->s + l + sizeof(struct dm_path_t)); if (new == 0) return 0; d = (char*)(new+1); new -> s = 0; new -> p = 0; new -> n = l + path->n - path->s; memmove(d,name,l); if (sep == 1) { d[l-1]='/'; } memmove(d+l,s+path->s,path->n - path->s); free(path); dm_path_next(new); return new; } memmove(s+path->s-l,name,l); if (sep == 1) { *(s+path->s-1)='/'; } path->s -= l; path->p = path->s; dm_path_next(path); return path; } /* * Passe a l element suivant */ void dm_path_next(struct dm_path_t* path) { const char* s = (const char*)(path + 1); const char *sep; if (path->s == path->n) { return; } path->s = path->p; while ( path->s < path->n && s[path->s] == '/') path->s++; sep = strchr(s+path->s,'/'); path->p = ( sep == 0 ? path->n : sep - s); } /* * get current path name */ const char* dm_path_name(struct dm_path_t* path) { const char* s = (const char*)(path + 1); return s + path->s; } /* * get current path size */ size_t dm_path_size(struct dm_path_t* path) { const char* s = (const char*)(path + 1); return path->p - path->s; } int32_t dm_path_hasnext(struct dm_path_t* path) { return (path->s < path->n); } /* * print debuging information */ void dm_path_debug(struct dm_path_t* path) { const char* s = (const char*)(path + 1); printf("%.*s", path->p - path->s, s + path->s); }
84f7ffcac1e5317b16fefef186388f7f8944bc85
a5a99f646e371b45974a6fb6ccc06b0a674818f2
/GeneratorInterface/AlpgenInterface/interface/AlpgenCommonBlocks.h
b766c035d3bc9d2f1e36eaab862fd3c1372c8a14
[ "Apache-2.0" ]
permissive
cms-sw/cmssw
4ecd2c1105d59c66d385551230542c6615b9ab58
19c178740257eb48367778593da55dcad08b7a4f
refs/heads/master
2023-08-23T21:57:42.491143
2023-08-22T20:22:40
2023-08-22T20:22:40
10,969,551
1,006
3,696
Apache-2.0
2023-09-14T19:14:28
2013-06-26T14:09:07
C++
UTF-8
C
false
false
1,346
h
AlpgenCommonBlocks.h
#ifndef GeneratorInterface_AlpgenInterface_AlpgenCommonBlocks_h #define GeneratorInterface_AlpgenInterface_AlpgenCommonBlocks_h /// A C/C++ representation of the ALPGEN Common Blocks: /// AHOPTS, AHPPARA, AHPARS, AHCUTS. extern "C" { extern struct AHOPTS { double etclus; // needs to be set up double rclus; // needs to be set up double etaclmax; int iexc; // needs to be set up int npfst; int nplst; int nljets; int njstart; int njlast; int ickkw; } ahopts_; extern struct AHPPARA { double masses[6]; // mc,mb,mt,mw,mz,mh (set up these) double ebeam; int ih1, ih2, ihrd; // ihrd needs to be set up int itopprc; int nw, nz, nh, nph; int ihvy, ihvy2; int npart, ndns, pdftyp; } ahppara_; extern struct AHPARS { static const unsigned int nparam = 200; double parval[nparam]; char chpar[nparam][8]; char chpdes[nparam][70]; int parlen[nparam]; int partyp[nparam]; } ahpars_; extern struct AHCUTS { double ptjmin, ptjmax; double etajmax, drjmin; double ptbmin, ptbmax; double etabmax, drbmin; double ptcmin, ptcmax; double etacmax, drcmin; double ptphmin; double etaphmax; double drphjmin, drphmin, drphlmin; double ptlmin; double etalmax, drlmin; double metmin; double mllmin, mllmax; } ahcuts_; } #endif // GeneratorInterface_AlpgenInterface_AlpgenCommonBlocks_h
d8f9a144686b9bbea86284c90fa7426263700441
85fd2b14378531ef279b97e0aad61cb6be19557d
/src/cpu/x86_mediana/libmediana/trunk/mediana.c
dc0f2df9765b10c5b6fa89dd9ad6c3242d5b7c2e
[ "MIT" ]
permissive
heruix/vdisasm
2bd17938822657592cd13084b22d1aa61b3f7818
5827a579782d247e51e281533362517318dc47b4
refs/heads/master
2020-12-02T16:12:32.343551
2015-06-05T11:49:51
2015-06-05T11:49:51
null
0
0
null
null
null
null
UTF-8
C
false
false
98,589
c
mediana.c
/****************************************************************************** * Copyright (c) 2010, Mikae * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Mikae. * 4. Neither the name of Mikae nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY Mikae ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL Mikae BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************* * * Core file of the disassembler. If you found a bug, or want to suggest a * feature, feel free to contact me: * * mika0x65@gmail.com * mika0x65.livejournal.com * ******************************************************************************* */ #include <string.h> #include "mediana.h" #include "utils.h" #include "tables.h" #include "tables.inc" #ifndef UNREFERENCED_PARAMETER #define UNREFERENCED_PARAMETER #endif #define PREF_SEG_INDEX 0x0 #define PREF_OPSIZE_INDEX 0x1 #define PREF_ADDRSIZE_INDEX 0x2 #define PREF_REP_INDEX 0x3 #define PREF_LOCK_INDEX 0x4 #define PREF_REX_INDEX 0x5 #define PREFIX_COUNT 0x6 //PREF_SEG_* #define PREF_CS_ID 0x0 #define PREF_DS_ID 0x1 #define PREF_ES_ID 0x2 #define PREF_SS_ID 0x3 #define PREF_FS_ID 0x4 #define PREF_GS_ID 0x5 //PREF_OPSIZE_* #define PREF_OPSIZE_ID 0x6 //PREF_ADDRSIZE_* #define PREF_ADDRSIZE_ID 0x7 //PREF_REP_* #define PREF_REPZ_ID 0x8 #define PREF_REPNZ_ID 0x9 //PREF_LOCK_* #define PREF_LOCK_ID 0xA //PREF_REX_* #define PREF_REX_ID 0xB //Used to convert rax, ... rdi to r8, ... r15 #define REG_CODE_64 0x8 //Holds operand's real and intended sizes, value of sign. struct OPERAND_SIZE { uint16_t size_in_stream; uint16_t size; uint8_t sign; }; struct DISASM_INTERNAL_DATA { uint8_t prefixes[PREFIX_COUNT]; //Valuable prefixes. uint8_t severe_err; //Severe disassembling error. uint32_t err; //Disassembling error. uint8_t is_opsize_used; //Prefixes were used during disassembling. uint8_t is_addrsize_used; // uint8_t is_seg_used; // uint8_t is_rex_used; // struct RWBUFF rbuff; //Contains current offset and buffer size. }; /****************************************************** * Operand's type qualifers (TQ_*) handlers' prototypes. ******************************************************* */ static uint32_t tq_1(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_3(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_A(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_C(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_D(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_E(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_G(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_H(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_I(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_J(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_M(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_N(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_O(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_P(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_Q(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_R(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_S(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_T(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_U(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_V(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_W(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_X(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_Y(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_Z(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_rAX(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_rCX(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_rDX(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_rBX(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_rSP(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_rBP(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_rSI(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_rDI(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_fST0(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_fES(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_fEST(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_CS(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_DS(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_SS(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_ES(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_FS(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t tq_GS(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t pref_CS_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t pref_DS_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t pref_SS_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t pref_ES_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t pref_FS_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t pref_GS_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t pref_OPSIZE_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t pref_ADDRSIZE_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t pref_REPZ_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t pref_REPNZ_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t pref_LOCK_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); //Array of type qualifiers' handlers. static uint32_t (*tq_handlers[])(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) = { tq_1, tq_3, tq_A, tq_C, tq_D, tq_E, tq_G, tq_H, tq_I, tq_J, tq_M, tq_N, tq_O, tq_P, tq_Q, tq_R, tq_S, tq_T, tq_U, tq_V, tq_W, tq_X, tq_Y, tq_Z, tq_rAX, tq_rCX, tq_rDX, tq_rBX, tq_rSP, tq_rBP, tq_rSI, tq_rDI, tq_fES, tq_fEST, tq_fST0, tq_CS, tq_DS, tq_ES, tq_SS, tq_FS, tq_GS, pref_CS_set, pref_DS_set, pref_ES_set, pref_SS_set, pref_FS_set, pref_GS_set, pref_OPSIZE_set, pref_ADDRSIZE_set, pref_REPZ_set, pref_REPNZ_set, pref_LOCK_set }; /******************************************************* * Operand's size qualifiers (SQ_*) handlers' prototypes. ******************************************************** */ static void sq_a(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_b(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_bcd(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_bdqp(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_bs(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_bsj(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_bss(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_d(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_ddq(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_di(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_dq(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_dq64(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_dqp(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_dr(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_ds(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_e(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_er(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_p(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_pd(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_pi(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_ps(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_psd(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_psq(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_ptp(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_q(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_qdq(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_qi(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_s(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_sd(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_sr(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_ss(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_st(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_stx(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_v(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_v67d64(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_vd64(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_vds(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_vq64(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_vqp(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_vs(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_w(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_wdq(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_wdqp(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_wi(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_wv(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void sq_wvqp(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); //Array of size qualifiers' handlers. static void (*sq_handlers[])(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) = { sq_a, sq_b, sq_bcd, sq_bdqp, sq_bs, sq_bsj, sq_bss, sq_d, sq_ddq, sq_di, sq_dq, sq_dq64, sq_dqp, sq_dr, sq_ds, sq_e, sq_er, sq_p, sq_pd, sq_pi, sq_ps, sq_psd, sq_psq, sq_ptp, sq_q, sq_qdq, sq_qi, sq_s, sq_sd, sq_sr, sq_ss, sq_st, sq_stx, sq_v, sq_v67d64, sq_vd64, sq_vds, sq_vq64, sq_vqp, sq_vs, sq_w, sq_wdq, sq_wdqp, sq_wi, sq_wv, sq_wvqp }; /*************************************** * Postprocessing functions's prototypes. **************************************** */ static uint32_t post_proc_arpl_movsxd(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params); static uint32_t post_proc_nop_pause(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params); static uint32_t post_proc_multinop(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params); static uint32_t post_proc_cmpxchg8b(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params); static uint32_t post_proc_pextrd(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params); static uint32_t post_proc_pinsrd(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params); static uint32_t post_proc_lea(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params); //Array of potsprocessing handlers. static uint32_t (*postprocs[])(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params) = { post_proc_arpl_movsxd, post_proc_nop_pause, post_proc_multinop, post_proc_cmpxchg8b, post_proc_pextrd, post_proc_pinsrd, post_proc_lea }; //Table for building 16bit addresses in my representation. static struct ADDR addrs_16bit[] = { //seg mod base index scale { SREG_CODE_DS, ADDR_MOD_BASE | ADDR_MOD_IDX, REG_CODE_BX, REG_CODE_SI, 0x1 }, { SREG_CODE_DS, ADDR_MOD_BASE | ADDR_MOD_IDX, REG_CODE_BX, REG_CODE_DI, 0x1 }, { SREG_CODE_SS, ADDR_MOD_BASE | ADDR_MOD_IDX, REG_CODE_BP, REG_CODE_SI, 0x1 }, { SREG_CODE_SS, ADDR_MOD_BASE | ADDR_MOD_IDX, REG_CODE_BP, REG_CODE_DI, 0x1 }, { SREG_CODE_DS, ADDR_MOD_BASE, REG_CODE_SI, 0x0, 0x1 }, { SREG_CODE_DS, ADDR_MOD_BASE, REG_CODE_DI, 0x0, 0x1 }, { SREG_CODE_DS, ADDR_MOD_DISP, 0x0, 0x0, 0x1 }, { SREG_CODE_DS, ADDR_MOD_BASE, REG_CODE_BX, 0x0, 0x1 }, { SREG_CODE_DS, ADDR_MOD_BASE | ADDR_MOD_IDX | ADDR_MOD_DISP, REG_CODE_BX, REG_CODE_SI, 0x1 }, { SREG_CODE_DS, ADDR_MOD_BASE | ADDR_MOD_IDX | ADDR_MOD_DISP, REG_CODE_BX, REG_CODE_DI, 0x1 }, { SREG_CODE_SS, ADDR_MOD_BASE | ADDR_MOD_IDX | ADDR_MOD_DISP, REG_CODE_BP, REG_CODE_SI, 0x1 }, { SREG_CODE_SS, ADDR_MOD_BASE | ADDR_MOD_IDX | ADDR_MOD_DISP, REG_CODE_BP, REG_CODE_DI, 0x1 }, { SREG_CODE_DS, ADDR_MOD_BASE | ADDR_MOD_DISP, REG_CODE_SI, 0x0, 0x1 }, { SREG_CODE_DS, ADDR_MOD_BASE | ADDR_MOD_DISP, REG_CODE_DI, 0x0, 0x1 }, { SREG_CODE_SS, ADDR_MOD_BASE | ADDR_MOD_DISP, REG_CODE_BP, 0x0, 0x1 }, { SREG_CODE_DS, ADDR_MOD_BASE | ADDR_MOD_DISP, REG_CODE_BX, 0x0, 0x1 }, { SREG_CODE_DS, ADDR_MOD_BASE | ADDR_MOD_IDX | ADDR_MOD_DISP, REG_CODE_BX, REG_CODE_SI, 0x1 }, { SREG_CODE_DS, ADDR_MOD_BASE | ADDR_MOD_IDX | ADDR_MOD_DISP, REG_CODE_BX, REG_CODE_DI, 0x1 }, { SREG_CODE_SS, ADDR_MOD_BASE | ADDR_MOD_IDX | ADDR_MOD_DISP, REG_CODE_BP, REG_CODE_SI, 0x1 }, { SREG_CODE_SS, ADDR_MOD_BASE | ADDR_MOD_IDX | ADDR_MOD_DISP, REG_CODE_BP, REG_CODE_DI, 0x1 }, { SREG_CODE_DS, ADDR_MOD_BASE | ADDR_MOD_DISP, REG_CODE_SI, 0x0, 0x1 }, { SREG_CODE_DS, ADDR_MOD_BASE | ADDR_MOD_DISP, REG_CODE_DI, 0x0, 0x1 }, { SREG_CODE_SS, ADDR_MOD_BASE | ADDR_MOD_DISP, REG_CODE_BP, 0x0, 0x1 }, { SREG_CODE_DS, ADDR_MOD_BASE | ADDR_MOD_DISP, REG_CODE_BX, 0x0, 0x1 } }; static uint8_t sregs_codes[] = { SREG_CODE_CS, SREG_CODE_DS, SREG_CODE_ES, SREG_CODE_SS, SREG_CODE_FS, SREG_CODE_GS }; static uint16_t pref_bits[] = { INSTR_PREFIX_CS, INSTR_PREFIX_DS, INSTR_PREFIX_ES, INSTR_PREFIX_SS, INSTR_PREFIX_FS, INSTR_PREFIX_GS, INSTR_PREFIX_OPSIZE, INSTR_PREFIX_ADDRSIZE, INSTR_PREFIX_REPNZ, INSTR_PREFIX_REPZ, INSTR_PREFIX_LOCK, INSTR_PREFIX_REX }; /********************************** * Some unsorted internal prototypes. *********************************** */ static void create_reg_operand(struct INSTRUCTION *instr, int op_index, uint8_t type, uint8_t code, uint16_t size); static void create_xmmreg_operand(struct INSTRUCTION *instr, int op_index, uint8_t code, uint16_t size, uint8_t rex, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void create_genreg_operand(struct INSTRUCTION *instr, int op_index, uint8_t code, uint16_t size, uint8_t rex, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void get_seg(struct INSTRUCTION *instr, int op_index, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint8_t get_operand_size(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint8_t get_operand_size_16_32(struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t parse_mem_operand(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static uint32_t parse_rm_operand(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode); static void movsx(void *value, unsigned int size1, unsigned int size2); static void add_sf_prefix(uint8_t prefixes[], uint32_t index, struct INSTRUCTION *instr, struct DISASM_PARAMS *params); static void readbuff_init(struct RWBUFF *rbuff, uint8_t *origin_offset, uint8_t *offset, size_t bufflen) { rbuff ->offset = offset; rbuff ->origin_offset = origin_offset; if (bufflen < MAX_INSTRUCTION_LEN) { rbuff ->length = bufflen; rbuff ->err = DASM_ERR_NO_BUFF; } else { rbuff ->length = MAX_INSTRUCTION_LEN; rbuff ->err = DASM_ERR_TOO_LONG; } } static int readbuff_get_bytes(struct RWBUFF *rbuff, struct DISASM_INTERNAL_DATA *idata, void *result, size_t count) { int res; if (rbuff ->offset - rbuff ->origin_offset + count > rbuff ->length) { idata ->severe_err = rbuff ->err; res = 0; } else { memcpy(result, rbuff ->offset, count); res = 1; } return res; } static int readbuff_get_bytes_inc(struct RWBUFF *rbuff, struct DISASM_INTERNAL_DATA *idata, void *result, unsigned int count) { int res; res = readbuff_get_bytes(rbuff, idata, result, count); rbuff ->offset += count; return res; } static void readbuff_inc(struct RWBUFF *rbuff, unsigned int count) { rbuff ->offset += count; } /******************************************** * Operand's type qualifiers' (TQ_*) handlers. ********************************************* */ static uint32_t tq_1(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); instr ->ops[op_index].flags |= OPERAND_TYPE_IMM; instr ->ops[op_index].size = 1; instr ->ops[op_index].value.imm.imm8 = 0x1; return 0x0; } static uint32_t tq_3(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); instr ->ops[op_index].flags |= OPERAND_TYPE_IMM; instr ->ops[op_index].size = 1; instr ->ops[op_index].value.imm.imm8 = 0x3; return 0; } static uint32_t tq_A(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(mode); instr ->ops[op_index].flags |= OPERAND_TYPE_DIR; instr ->ops[op_index].size = opsize ->size; instr ->ops[op_index].value.far_addr.offset = (uint8_t)(idata ->rbuff.offset - idata ->rbuff.origin_offset); //memcpy(&(instr ->ops[op_index].value.far_addr), offset, instr ->ops[op_index].size); //readbuff_get_bytes_inc(&idata ->rbuff, idata, &(instr ->ops[op_index].value.far_addr), instr ->ops[op_index].size); readbuff_get_bytes_inc(&idata ->rbuff, idata, &(instr ->ops[op_index].value.far_addr.far_addr32), instr ->ops[op_index].size); return instr ->ops[op_index].size; } static uint32_t tq_C(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); create_reg_operand(instr, op_index, REG_TYPE_CR, (instr ->modrm >> 0x3) & 0x7, instr ->ops[op_index].size); return 0x0; } static uint32_t tq_D(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); create_reg_operand(instr, op_index, REG_TYPE_DBG, (instr ->modrm >> 0x3) & 0x7, instr ->ops[op_index].size); return 0x0; } static uint32_t tq_E(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { return parse_rm_operand(instr, op_index, opsize, idata, mode); } static uint32_t tq_G(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { create_genreg_operand(instr, op_index, (instr ->modrm >> 3) & 0x7, opsize ->size, PREFIX_REX_R, idata, mode); return 0x0; } static uint32_t tq_H(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { create_genreg_operand(instr, op_index, instr ->modrm & 0x7, opsize ->size, PREFIX_REX_B, idata, mode); return 0x0; } static uint32_t tq_I(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(mode); instr ->ops[op_index].flags |= OPERAND_TYPE_IMM; instr ->ops[op_index].size = opsize ->size; instr ->ops[op_index].value.imm.size = (uint8_t)opsize ->size_in_stream; instr ->ops[op_index].value.imm.offset = (uint8_t)(idata ->rbuff.offset - idata ->rbuff.origin_offset); //memcpy(&(instr ->ops[op_index].value.imm.imm8), offset, opsize ->size_in_stream); readbuff_get_bytes_inc(&idata ->rbuff, idata, &(instr ->ops[op_index].value.imm.imm8), opsize ->size_in_stream); movsx(&(instr ->ops[op_index].value.imm.imm8), opsize ->size_in_stream, 0x8); return (uint8_t)opsize ->size_in_stream; } static uint32_t tq_J(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { instr ->ops[op_index].flags |= OPERAND_FLAG_REL; return tq_I(instr, op_index, opsize, idata, mode); } static uint32_t tq_M(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { uint32_t res = parse_rm_operand(instr, op_index, opsize, idata, mode); if ((instr ->modrm & 0xC0) == 0xC0) { if (!idata ->err) idata ->err = DASM_ERR_RM_REG;//error: rm encodes memory. } return res; } static uint32_t tq_N(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); create_reg_operand(instr, op_index, REG_TYPE_MMX, instr ->modrm & 0x7, opsize ->size); return 0x0; } static uint32_t tq_O(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { uint32_t res; res = instr ->addrsize; instr ->ops[op_index].flags |= OPERAND_TYPE_MEM; instr ->ops[op_index].size = opsize ->size; instr ->ops[op_index].value.addr.mod = ADDR_MOD_DISP; //memcpy(&(instr ->disp.value), offset, instr ->addrsize); readbuff_get_bytes_inc(&idata ->rbuff, idata, &(instr ->disp.value), instr ->addrsize); instr ->disp.offset = 1; instr ->disp.size = instr ->addrsize; get_seg(instr, op_index, idata, mode); return res; } static uint32_t tq_P(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); create_reg_operand(instr, op_index, REG_TYPE_MMX, (instr ->modrm >> 0x3) & 0x7, opsize ->size); return 0x0; } static uint32_t tq_Q(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { uint32_t res; res = 0x0; if ((instr ->modrm & 0xC0) == 0xC0) { create_reg_operand(instr, op_index, REG_TYPE_MMX, instr ->modrm & 0x7, opsize ->size); } else { res = parse_mem_operand(instr, op_index, opsize, idata, mode); } return res; } static uint32_t tq_R(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { uint32_t res = parse_rm_operand(instr, op_index, opsize, idata, mode); if ((instr ->modrm & 0xC0) != 0xC0) { if (!idata ->err) idata ->err = DASM_ERR_RM_MEM;//error: rm encodes memory. } return res; } static uint32_t tq_S(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); create_reg_operand(instr, op_index, REG_TYPE_SEG, (instr ->modrm >> 3) & 0x7, 2); return 0x0; } static uint32_t tq_T(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); create_reg_operand(instr, op_index, REG_TYPE_TR, (instr ->modrm >> 0x3) & 0x7, opsize ->size); return 0x0; } static uint32_t tq_U(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if ((instr ->modrm & 0xC0) != 0xC0) { if (!idata ->err) { idata ->err = DASM_ERR_RM_MEM; } } else { create_xmmreg_operand(instr, op_index, instr ->modrm & 0x7, opsize ->size, PREFIX_REX_B, idata, mode); } return 0x0; } static uint32_t tq_V(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { create_xmmreg_operand(instr, op_index, (instr ->modrm >> 0x3) & 0x7, opsize ->size, PREFIX_REX_R, idata, mode); return 0; } static uint32_t tq_W(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { uint32_t res; if ((instr ->modrm & 0xC0) == 0xC0) { create_xmmreg_operand(instr, op_index, instr ->modrm & 0x7, opsize ->size, PREFIX_REX_B, idata, mode); res = 0; } else { res = parse_mem_operand(instr, op_index, opsize, idata, mode); } return res; } static uint32_t tq_X(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { uint32_t res; res = 0; instr ->ops[op_index].flags |= OPERAND_TYPE_MEM; instr ->ops[op_index].size = opsize ->size; instr ->ops[op_index].value.addr.mod = ADDR_MOD_BASE; instr ->ops[op_index].value.addr.base = REG_CODE_SI; get_seg(instr, op_index, idata, mode); return 0x0; } static uint32_t tq_Y(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(idata); instr ->ops[op_index].flags |= OPERAND_TYPE_MEM; instr ->ops[op_index].size = opsize ->size; if (mode == DISASSEMBLE_MODE_64) instr ->ops[op_index].value.addr.seg = SREG_CODE_CS; else instr ->ops[op_index].value.addr.seg = SREG_CODE_ES; instr ->ops[op_index].value.addr.mod = ADDR_MOD_BASE; instr ->ops[op_index].value.addr.base = REG_CODE_DI; return 0x0; } static uint32_t tq_Z(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { //We already consumed opcode, hence we need to look backward. create_genreg_operand(instr, op_index, idata ->rbuff.offset[-1] & 0x7, opsize ->size, PREFIX_REX_B, idata, mode); return 0x0; } static uint32_t tq_rAX(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { create_genreg_operand(instr, op_index, REG_CODE_AX, opsize ->size, PREFIX_REX_B, idata, mode); return 0x0; } static uint32_t tq_rCX(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { create_genreg_operand(instr, op_index, REG_CODE_CX, opsize ->size, PREFIX_REX_B, idata, mode); return 0x0; } static uint32_t tq_rDX(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { create_genreg_operand(instr, op_index, REG_CODE_DX, opsize ->size, PREFIX_REX_B, idata, mode); return 0x0; } static uint32_t tq_rBX(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { create_genreg_operand(instr, op_index, REG_CODE_BX, opsize ->size, PREFIX_REX_B, idata, mode); return 0x0; } static uint32_t tq_rSP(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { create_genreg_operand(instr, op_index, REG_CODE_SP, opsize ->size, PREFIX_REX_B, idata, mode); return 0x0; } static uint32_t tq_rBP(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { create_genreg_operand(instr, op_index, REG_CODE_BP, opsize ->size, PREFIX_REX_B, idata, mode); return 0x0; } static uint32_t tq_rSI(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { create_genreg_operand(instr, op_index, REG_CODE_SI, opsize ->size, PREFIX_REX_B, idata, mode); return 0x0; } static uint32_t tq_rDI(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { create_genreg_operand(instr, op_index, REG_CODE_DI, opsize ->size, PREFIX_REX_B, idata, mode); return 0x0; } static uint32_t tq_fES(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { uint32_t res; if ((instr ->modrm & 0xC0) == 0xC0) res = tq_fEST(instr, op_index, opsize, idata, mode); else res = tq_M(instr, op_index, opsize, idata, mode); return res; } static uint32_t tq_fEST(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); create_reg_operand(instr, op_index, REG_TYPE_FPU, instr ->modrm & 0x7, opsize ->size); return 0; } static uint32_t tq_fST0(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); create_reg_operand(instr, op_index, REG_TYPE_FPU, FREG_CODE_ST0, opsize ->size); return 0; } static uint32_t tq_CS(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); create_reg_operand(instr, op_index, REG_TYPE_SEG, SREG_CODE_CS, opsize ->size); return 0; } static uint32_t tq_DS(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); create_reg_operand(instr, op_index, REG_TYPE_SEG, SREG_CODE_DS, opsize ->size); return 0; } static uint32_t tq_ES(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); create_reg_operand(instr, op_index, REG_TYPE_SEG, SREG_CODE_ES, opsize ->size); return 0; } static uint32_t tq_SS(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); create_reg_operand(instr, op_index, REG_TYPE_SEG, SREG_CODE_SS, opsize ->size); return 0; } static uint32_t tq_FS(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); create_reg_operand(instr, op_index, REG_TYPE_SEG, SREG_CODE_FS, opsize ->size); return 0; } static uint32_t tq_GS(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); create_reg_operand(instr, op_index, REG_TYPE_SEG, SREG_CODE_GS, opsize ->size); return 0; } static uint32_t pref_CS_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(op_index); UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); return PREF_SEG_INDEX << 8 | PREF_CS_ID; } static uint32_t pref_DS_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(op_index); UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); return PREF_SEG_INDEX << 8 | PREF_DS_ID; } static uint32_t pref_ES_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(op_index); UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); return PREF_SEG_INDEX << 8 | PREF_ES_ID; } static uint32_t pref_SS_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(op_index); UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); return PREF_SEG_INDEX << 8 | PREF_SS_ID; } static uint32_t pref_FS_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(op_index); UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); return PREF_SEG_INDEX << 8 | PREF_FS_ID; } static uint32_t pref_GS_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(op_index); UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); return PREF_SEG_INDEX << 8 | PREF_GS_ID; } static uint32_t pref_OPSIZE_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(op_index); UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); return PREF_OPSIZE_INDEX << 8 | PREF_OPSIZE_ID; } static uint32_t pref_ADDRSIZE_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(op_index); UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); return PREF_ADDRSIZE_INDEX << 8 | PREF_ADDRSIZE_ID; } static uint32_t pref_REPZ_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(op_index); UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); return PREF_REP_INDEX << 8 | PREF_REPZ_ID; } static uint32_t pref_REPNZ_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(op_index); UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); return PREF_REP_INDEX << 8 | PREF_REPNZ_ID; } static uint32_t pref_LOCK_set(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(op_index); UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); return PREF_LOCK_INDEX << 8 | PREF_LOCK_ID; } /******************************************** * Operand's size qualifiers' (SQ_*) handlers. ********************************************* */ static void sq_a(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(opsize); UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); } static void sq_b(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); opsize ->size_in_stream = 1; opsize ->size = 1; opsize ->sign = 0; } static void sq_bcd(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { sq_er(opsize, instr, idata, mode); } static void sq_bdqp(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if ((instr ->modrm & 0xC0) == 0xC0) { sq_dqp(opsize, instr, idata, mode); } else { sq_b(opsize, instr, idata, mode); } } static void sq_bs(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); opsize ->size_in_stream = 1; if (mode != DISASSEMBLE_MODE_64) { opsize ->size = get_operand_size_16_32(idata, mode); } else { if (idata ->prefixes[PREF_OPSIZE_INDEX] != 0xFF) { opsize ->size = get_operand_size_16_32(idata, mode); } else { opsize ->size = 8; } } opsize ->sign = 1; } static void sq_bsj(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); opsize ->size_in_stream = 1; if (mode == DISASSEMBLE_MODE_64) { opsize ->size = 8; } else { opsize ->size = get_operand_size_16_32(idata, mode); } opsize ->sign = 1; } static void sq_bss(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); opsize ->size_in_stream = 1; switch(mode) { case DISASSEMBLE_MODE_16: opsize ->size = 2; break; case DISASSEMBLE_MODE_32: opsize ->size = 4; break; case DISASSEMBLE_MODE_64: opsize ->size = 8; break; } opsize ->sign = 1; } static void sq_d(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); opsize ->size_in_stream = 4; opsize ->size = 4; opsize ->sign = 0; } static void sq_ddq(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if ((instr ->modrm & 0xC0) == 0xC0) { sq_dq(opsize, instr, idata, mode); } else { sq_d(opsize, instr, idata, mode); } } static void sq_di(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); opsize ->size_in_stream = 4; opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_dq(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); opsize ->size_in_stream = 16; opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_dq64(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if (mode != DISASSEMBLE_MODE_64) { sq_d(opsize, instr, idata, mode); } else { sq_q(opsize, instr, idata, mode); } } static void sq_dqp(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if (mode == DISASSEMBLE_MODE_64) { opsize ->size_in_stream = get_operand_size(instr, idata, mode); opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } else { sq_d(opsize, instr, idata, mode); } } static void sq_dr(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); opsize ->size_in_stream = 8; opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_ds(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { sq_d(opsize, instr, idata, mode); opsize ->sign = 1; } static void sq_e(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); if (get_operand_size_16_32(idata, mode) == 2) { opsize ->size_in_stream = 14; } else { opsize ->size_in_stream = 28; } opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_er(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); opsize ->size_in_stream = 10; opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_p(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); opsize ->size_in_stream = get_operand_size_16_32(idata, mode) + 2; opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_pd(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { sq_dq(opsize, instr, idata, mode); } static void sq_pi(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { sq_q(opsize, instr, idata, mode); } static void sq_ps(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); opsize ->size_in_stream = 16; opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_psd(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if ((instr ->modrm & 0xC0) == 0xC0) { sq_d(opsize, instr, idata, mode); } else { sq_ps(opsize, instr, idata, mode); } } static void sq_psq(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { sq_q(opsize, instr, idata, mode); } static void sq_ptp(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if (mode == DISASSEMBLE_MODE_64) { opsize ->size_in_stream = get_operand_size(instr, idata, mode) + 2; opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } else { sq_p(opsize, instr, idata, mode); } } static void sq_q(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); opsize ->size_in_stream = 8; opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_qdq(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if ((instr ->modrm & 0xC0) == 0xC0) { sq_dq(opsize, instr, idata, mode); } else { sq_q(opsize, instr, idata, mode); } } static void sq_qi(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); opsize ->size_in_stream = 8; opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_s(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); opsize ->size_in_stream = 6; opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_sd(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { sq_dq(opsize, instr, idata, mode); } static void sq_sr(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); opsize ->size_in_stream = 4; opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_ss(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { sq_dq(opsize, instr, idata, mode); } static void sq_st(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); if (get_operand_size_16_32(idata, mode) == 2) { opsize ->size_in_stream = 94; } else { opsize ->size_in_stream = 108; } opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_stx(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); opsize ->size_in_stream = 512; opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_v(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); opsize ->size_in_stream = get_operand_size_16_32(idata, mode); opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_v67d64(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if (mode == DISASSEMBLE_MODE_64) { if (idata ->prefixes[PREF_ADDRSIZE_INDEX] != 0xFF) { sq_d(opsize, instr, idata, mode); idata ->is_addrsize_used = 1; } else { sq_q(opsize, instr, idata, mode); } } else { if (idata ->prefixes[PREF_ADDRSIZE_INDEX] != 0xFF) { mode ^= (DISASSEMBLE_MODE_16 | DISASSEMBLE_MODE_32); idata ->is_addrsize_used = 1; } if (mode == DISASSEMBLE_MODE_16) { sq_w(opsize, instr, idata, mode); } else { sq_d(opsize, instr, idata, mode); } } } static void sq_vd64(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if (mode != DISASSEMBLE_MODE_64) { sq_v(opsize, instr, idata, mode); } else { if (idata ->prefixes[PREF_OPSIZE_INDEX] != 0xFF) { idata ->is_opsize_used = 1; sq_w(opsize, instr, idata, mode); } else { sq_q(opsize, instr, idata, mode); } } } static void sq_vds(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if (mode == DISASSEMBLE_MODE_64) { /* sq_v(opsize, instr, idata, mode); if (opsize ->size_in_stream == 4) { opsize ->size = 8; opsize ->sign = 1; } */ opsize ->size_in_stream = 4; opsize ->size = 8; opsize ->sign = 1; } else { sq_v(opsize, instr, idata, mode); } } static void sq_vq64(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if (mode == DISASSEMBLE_MODE_64) { sq_q(opsize, instr, idata, mode); } else { sq_v(opsize, instr, idata, mode); } } static void sq_vqp(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if (mode == DISASSEMBLE_MODE_64) { opsize ->size_in_stream = get_operand_size(instr, idata, mode); opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } else { sq_v(opsize, instr, idata, mode); } } static void sq_vs(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if (mode != DISASSEMBLE_MODE_64) { sq_v(opsize, instr, idata, mode); } else { opsize ->size_in_stream = get_operand_size_16_32(idata, mode); if (idata ->prefixes[PREF_OPSIZE_INDEX] != 0xFF) { opsize ->size = 2; } else { opsize ->size = 8; } } } static void sq_w(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); opsize ->size_in_stream = 2; opsize ->size = 2; opsize ->sign = 0; } static void sq_wdq(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if ((instr ->modrm & 0xC0) == 0xC0) { sq_dq(opsize, instr, idata, mode); } else { sq_w(opsize, instr, idata, mode); } } static void sq_wdqp(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if ((instr ->modrm & 0xC0) == 0xC0) { sq_dqp(opsize, instr, idata, mode); } else { sq_w(opsize, instr, idata, mode); } } static void sq_wi(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { UNREFERENCED_PARAMETER(instr); UNREFERENCED_PARAMETER(idata); UNREFERENCED_PARAMETER(mode); opsize ->size_in_stream = 2; opsize ->size = opsize ->size_in_stream; opsize ->sign = 0; } static void sq_wv(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if ((instr ->modrm & 0xC0) == 0xC0) { sq_v(opsize, instr, idata, mode); } else { sq_w(opsize, instr, idata, mode); } } static void sq_wvqp(struct OPERAND_SIZE *opsize, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if ((instr ->modrm & 0xC0) == 0xC0) { sq_vqp(opsize, instr, idata, mode); } else { sq_w(opsize, instr, idata, mode); } } /************************* * Postprocessing routines. ************************** */ static uint32_t post_proc_arpl_movsxd(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params) { uint32_t res; res = 0; if (params ->mode == DISASSEMBLE_MODE_64) { struct OPERAND_SIZE opsize; struct RWBUFF *rbuff; instr ->id = ID_MOVSXD; instr ->groups = GRP_GEN | GRP_CONVER; instr ->tested_flags = 0; instr ->modified_flags = 0; instr ->set_flags = 0; instr ->cleared_flags = 0; instr ->flags &= (INSTR_FLAG_MODRM | INSTR_FLAG_SIB); unistrcpy(instr ->mnemonic, _UT("movsxd")); rbuff = &idata ->rbuff; readbuff_init(rbuff, rbuff ->origin_offset, rbuff ->origin_offset + instr ->opcode_offset + 1, rbuff ->length - instr ->opcode_offset); res = instr ->opcode_offset; res++; //opcode byte. if (instr ->flags & INSTR_FLAG_MODRM) { res++; idata ->rbuff.offset++; } if (instr ->flags & INSTR_FLAG_SIB) { res++; idata ->rbuff.offset++; } memset(instr ->ops, 0x0, sizeof(instr ->ops)); instr ->ops[0].flags = OPERAND_FLAG_PRESENT; instr ->ops[0].flags |= OPERAND_FLAG_WRITE; instr ->ops[1].flags = OPERAND_FLAG_PRESENT; instr ->ops[1].flags |= OPERAND_FLAG_READ; sq_q(&opsize, instr, idata, params ->mode); res += tq_G(instr, 0, &opsize, idata, params ->mode); sq_d(&opsize, instr, idata, params ->mode); res += tq_E(instr, 1, &opsize, idata, params ->mode); if (instr ->ops[1].flags & OPERAND_TYPE_MEM) { get_seg(instr, 1, idata, params ->mode); } *len = res; } return res; } static uint32_t post_proc_nop_pause(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params) { UNREFERENCED_PARAMETER(len); UNREFERENCED_PARAMETER(params); if (idata ->prefixes[PREF_REP_INDEX] == PREF_REPNZ_ID) { instr ->id = ID_PAUSE; instr ->groups = GRP_CACHECT | GRP_SSE2; idata ->prefixes[PREF_REP_INDEX] = 0xFF; unistrcpy(instr ->mnemonic, _UT("pause")); } return 0; } static uint32_t post_proc_multinop(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params) { UNREFERENCED_PARAMETER(len); if (params ->arch & ARCH_AMD) { if ((instr ->modrm & 0xC0) == 0xC0) { idata ->err = DASM_ERR_RM_REG; } else { switch((instr ->modrm >> 0x3) & 0x7) { case 0: unistrcpy(instr ->mnemonic, _UT("prefetch")); break; case 1: unistrcpy(instr ->mnemonic, _UT("prefetchw")); break; case 2: case 3: case 4: case 5: case 6: case 7: unistrcpy(instr ->mnemonic, _UT("prefetch")); break; } } } return 0; } static uint32_t post_proc_cmpxchg8b(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params) { UNREFERENCED_PARAMETER(len); instr ->opsize = 8; if (params ->mode == DISASSEMBLE_MODE_64) { if (idata ->prefixes[PREF_REX_INDEX] != 0xFF && instr ->rex & PREFIX_REX_W) { idata ->is_rex_used = 1; unistrcpy(instr ->mnemonic, _UT("cmpxchg16b")); instr ->ops[0].size = 16; instr ->opsize = 16; } } return 0; } static uint32_t post_proc_pextrd(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params) { UNREFERENCED_PARAMETER(len); if (params ->mode == DISASSEMBLE_MODE_64) { if (idata ->prefixes[PREF_REX_INDEX] != 0xFF && instr ->rex & PREFIX_REX_W) { idata ->is_rex_used = 1; instr ->id = ID_PEXTRQ; unistrcpy(instr ->mnemonic, _UT("pextrq")); instr ->ops[0].size = 8; } } return 0; } static uint32_t post_proc_pinsrd(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params) { UNREFERENCED_PARAMETER(len); if (params ->mode == DISASSEMBLE_MODE_64) { if (idata ->prefixes[PREF_REX_INDEX] != 0xFF && instr ->rex & PREFIX_REX_W) { idata ->is_rex_used = 1; instr ->id = ID_PINSRQ; unistrcpy(instr ->mnemonic, _UT("pinsrq")); instr ->ops[0].size = 8; } } return 0; } static uint32_t post_proc_lea(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint32_t *len, struct DISASM_PARAMS *params) { UNREFERENCED_PARAMETER(len); if (idata ->prefixes[PREF_SEG_INDEX] != 0xFF) { add_sf_prefix(idata ->prefixes, PREF_SEG_INDEX, instr, params); } return 0; } /******************************* * Some internal common routines. ******************************** */ static void movsx(void *value, unsigned int size1, unsigned int size2) { uint8_t msb; if (size1 < size2) { msb = *((uint8_t *)((uint8_t *)value + size1 - 1)); if (msb & 0x80) memset((uint8_t *)value + size1, 0xFF, size2 - size1); else memset((uint8_t *)value + size1, 0x0, size2 - size1); } } //Creates OPERAND_TYPE_REG operand of given type. static void create_reg_operand(struct INSTRUCTION *instr, int op_index, uint8_t type, uint8_t code, uint16_t size) { instr ->ops[op_index].flags |= OPERAND_TYPE_REG; instr ->ops[op_index].value.reg.type = type; instr ->ops[op_index].value.reg.code = code; instr ->ops[op_index].size = (uint8_t)size; } static void create_genreg_operand(struct INSTRUCTION *instr, int op_index, uint8_t code, uint16_t size, uint8_t rex_rxb, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if (mode != DISASSEMBLE_MODE_64) { if (code > REG_CODE_BX && size == 1) { code += 0xC; } } else { if (idata ->prefixes[PREF_REX_INDEX] == 0xFF) { if (code > REG_CODE_BX && size == 1) { code += 0xC; } } else { rex_rxb &= (PREFIX_REX_R | PREFIX_REX_X | PREFIX_REX_B); if (instr ->rex & rex_rxb) { code |= REG_CODE_64; idata ->is_rex_used = 1; } } } create_reg_operand(instr, op_index, REG_TYPE_GEN, code, size); } static void create_xmmreg_operand(struct INSTRUCTION *instr, int op_index, uint8_t code, uint16_t size, uint8_t rex, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if (mode == DISASSEMBLE_MODE_64 && idata ->prefixes[PREF_REX_INDEX] != 0xFF) { if (instr ->rex & rex) { code |= REG_CODE_64; idata ->is_rex_used = 1; } } create_reg_operand(instr, op_index, REG_TYPE_XMM, code, size); } //Returns size accordingly to disassemble mode and opsize prefix. static uint8_t get_operand_size_16_32(struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { uint8_t res; if (mode == DISASSEMBLE_MODE_64) mode = DISASSEMBLE_MODE_32; if (idata ->prefixes[PREF_OPSIZE_INDEX] != 0xFF) { mode ^= (DISASSEMBLE_MODE_16 | DISASSEMBLE_MODE_32); idata ->is_opsize_used = 1; } if (mode == DISASSEMBLE_MODE_16) res = 2; else res = 4; return res; } //Returns size accordingly to disassemble mode, size override and REX.W prefixes. static uint8_t get_operand_size(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { uint8_t res; if (mode == DISASSEMBLE_MODE_64) { if (idata ->prefixes[PREF_REX_INDEX] != 0xFF && instr ->rex & PREFIX_REX_W) { res = 8; idata ->is_rex_used = 1; } else { res = get_operand_size_16_32(idata, mode); } } else { res = get_operand_size_16_32(idata, mode); } return res; } //Returns address size. Address size is common for all operands. static void get_address_size(struct INSTRUCTION *instr, uint8_t prefixes[], uint8_t mode) { if (mode == DISASSEMBLE_MODE_64) { if (prefixes[PREF_ADDRSIZE_INDEX] != 0xFF) instr ->addrsize = 4; else instr ->addrsize = 8; } else { if (prefixes[PREF_ADDRSIZE_INDEX] != 0xFF) mode ^= (DISASSEMBLE_MODE_16 | DISASSEMBLE_MODE_32); if (mode == DISASSEMBLE_MODE_16) instr ->addrsize = 2; else instr ->addrsize = 4; } } //Calculates segment for memory addressing operands accordingly to //mode, segment override prefixes and address base register. static void get_seg(struct INSTRUCTION *instr, int op_index, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if (idata ->prefixes[PREF_SEG_INDEX] == 0xFF) { if (mode == DISASSEMBLE_MODE_64) { instr ->ops[op_index].value.addr.seg = SREG_CODE_CS; } else { if ( !(instr ->ops[op_index].value.addr.mod & ADDR_MOD_BASE) ) { instr ->ops[op_index].value.addr.seg = SREG_CODE_DS; } else { if ((instr ->ops[op_index].value.addr.base != REG_CODE_BP) && (instr ->ops[op_index].value.addr.base != REG_CODE_SP)) { instr ->ops[op_index].value.addr.seg = SREG_CODE_DS; } else { instr ->ops[op_index].value.addr.seg = SREG_CODE_SS; } } } } else { if (mode == DISASSEMBLE_MODE_64) { if (idata ->prefixes[PREF_SEG_INDEX] == PREF_FS_ID || idata ->prefixes[PREF_SEG_INDEX] == PREF_GS_ID) { instr ->ops[op_index].value.addr.seg = sregs_codes[idata ->prefixes[PREF_SEG_INDEX]]; idata ->is_seg_used = 1; instr ->ops[op_index].flags |= OPERAND_FLAG_SEG_OVERRIDE; } else { instr ->ops[op_index].value.addr.seg = SREG_CODE_CS; } } else { instr ->ops[op_index].value.addr.seg = sregs_codes[idata ->prefixes[PREF_SEG_INDEX]]; //Set flag if prefix was really used. if ( !(instr ->ops[op_index].value.addr.mod & ADDR_MOD_BASE) ) { if (idata ->prefixes[PREF_SEG_INDEX] != PREF_DS_ID) { idata ->is_seg_used = 1; instr ->ops[op_index].flags |= OPERAND_FLAG_SEG_OVERRIDE; } } else { if ((instr ->ops[op_index].value.addr.base == REG_CODE_BP) || (instr ->ops[op_index].value.addr.base == REG_CODE_SP)) { if (instr ->ops[op_index].value.addr.seg != SREG_CODE_SS) { idata ->is_seg_used = 1; instr ->ops[op_index].flags |= OPERAND_FLAG_SEG_OVERRIDE; } } else { if (instr ->ops[op_index].value.addr.seg != SREG_CODE_DS) { idata ->is_seg_used = 1; instr ->ops[op_index].flags |= OPERAND_FLAG_SEG_OVERRIDE; } } } } } } //Builds ADDR.mod field from instruction's MODRM byte. static void get_mod_type_modrm(struct INSTRUCTION *instr, int op_index) { if (instr ->ops[op_index].value.addr.mod != 0x0) { instr ->ops[op_index].value.addr.mod = ADDR_MOD_BASE | ADDR_MOD_DISP; } else { switch(instr ->ops[op_index].value.addr.base) { case REG_CODE_IP: instr ->ops[op_index].value.addr.mod = ADDR_MOD_BASE | ADDR_MOD_DISP; break; case REG_CODE_BP: case REG_CODE_R13: instr ->ops[op_index].value.addr.mod = ADDR_MOD_DISP; break; default: instr ->ops[op_index].value.addr.mod = ADDR_MOD_BASE; break; } } } //Builds ADDR.mod field from instruction's SIB byte. static void get_mod_type_sib(struct INSTRUCTION *instr, int op_index) { if (instr ->ops[op_index].value.addr.index == REG_CODE_SP) { get_mod_type_modrm(instr, op_index); } else { if (instr ->ops[op_index].value.addr.mod == 0) { if ( (instr ->ops[op_index].value.addr.base == REG_CODE_BP) || (instr ->ops[op_index].value.addr.base == REG_CODE_R13) ) { instr ->ops[op_index].value.addr.mod = ADDR_MOD_IDX | ADDR_MOD_DISP; } else { instr ->ops[op_index].value.addr.mod = ADDR_MOD_BASE | ADDR_MOD_IDX; } } else { instr ->ops[op_index].value.addr.mod = ADDR_MOD_BASE | ADDR_MOD_IDX | ADDR_MOD_DISP; } } } //Calculates displacement's size and copies it to struct DISPLACEMENT. static uint8_t get_disp(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, int op_index) { uint8_t len; switch(instr ->ops[op_index].value.addr.mod) { case 0x0: if (instr ->ops[op_index].value.addr.base == REG_CODE_BP || instr ->ops[op_index].value.addr.base == REG_CODE_IP) len = instr ->addrsize; else len = 0x0; break; case 0x1: len = 0x1; break; case 0x2: len = instr ->addrsize; break; default: len = 0; idata ->severe_err = DASM_ERR_INTERNAL; break; } if (len == 8) len = 4; instr ->disp.size = len; if (len) { //memcpy(&(instr ->disp.value), offset, len); readbuff_get_bytes_inc(&idata ->rbuff, idata, &(instr ->disp.value), len); movsx(&(instr ->disp.value), len, 0x8); instr ->disp.offset = (uint8_t)(idata ->rbuff.offset - idata ->rbuff.origin_offset); } return len; } //Parses 16bit memory address operand. static uint32_t parse_mem_operand_16(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, int op_index) { uint8_t len; unsigned int index; instr ->ops[op_index].value.addr.mod = instr ->modrm >> 0x6; len = get_disp(instr, idata, op_index); index = (instr ->modrm >> 0x3 & 0x18) | (instr ->modrm & 0x7); instr ->ops[op_index].value.addr.seg = addrs_16bit[index].seg; instr ->ops[op_index].value.addr.mod = addrs_16bit[index].mod; instr ->ops[op_index].value.addr.base = addrs_16bit[index].base; instr ->ops[op_index].value.addr.index = addrs_16bit[index].index; instr ->ops[op_index].value.addr.scale = addrs_16bit[index].scale; return len; } //Parses 32/64bit memory address operand. static uint32_t parse_mem_operand_32_64(struct INSTRUCTION *instr, int op_index, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { uint32_t len = 0; if (instr ->flags & INSTR_FLAG_SIB) { instr ->ops[op_index].value.addr.mod = instr ->modrm >> 0x6; instr ->ops[op_index].value.addr.base = instr ->sib & 0x7; instr ->ops[op_index].value.addr.index = (instr ->sib >> 3) & 0x7; instr ->ops[op_index].value.addr.scale = 1 << (instr ->sib >> 0x6); if (mode == DISASSEMBLE_MODE_64 && idata ->prefixes[PREF_REX_INDEX] != 0xFF) { if (instr ->rex & PREFIX_REX_B) { instr ->ops[op_index].value.addr.base |= REG_CODE_64; idata ->is_rex_used = 1; } if (instr ->rex & PREFIX_REX_X) { instr ->ops[op_index].value.addr.index |= REG_CODE_64; idata ->is_rex_used = 1; } } len = get_disp(instr, idata, op_index); get_mod_type_sib(instr, op_index); } else { instr ->ops[op_index].value.addr.mod = instr ->modrm >> 0x6; instr ->ops[op_index].value.addr.base = instr ->modrm & 0x7; if (mode == DISASSEMBLE_MODE_64) { if (idata ->prefixes[PREF_REX_INDEX] != 0xFF && instr ->rex & PREFIX_REX_B) { instr ->ops[op_index].value.addr.base |= REG_CODE_64; idata ->is_rex_used = 1; } if ( (instr ->ops[op_index].value.addr.mod == 0x0) && ((instr ->ops[op_index].value.addr.base == REG_CODE_BP) || (instr ->ops[op_index].value.addr.base == REG_CODE_R13)) ) { instr ->ops[op_index].value.addr.base = REG_CODE_IP; } } len = get_disp(instr, idata, op_index); get_mod_type_modrm(instr, op_index); } get_seg(instr, op_index, idata, mode); return len; } //Parses memory address operand. static uint32_t parse_mem_operand(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { uint32_t len; instr ->ops[op_index].flags |= OPERAND_TYPE_MEM; instr ->ops[op_index].size = opsize ->size; if (instr ->addrsize == 2) { len = parse_mem_operand_16(instr, idata, op_index); } else { len = parse_mem_operand_32_64(instr, op_index, idata, mode); } idata ->is_addrsize_used = 1; return len; } //Parses operand accordingly to MODRM value. static uint32_t parse_rm_operand(struct INSTRUCTION *instr, int op_index, struct OPERAND_SIZE *opsize, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { uint32_t len = 0; if ((instr ->modrm & 0xC0) == 0xC0) { create_genreg_operand(instr, op_index, instr ->modrm & 0x7, opsize ->size, PREFIX_REX_B, idata, mode); } else { len = parse_mem_operand(instr, op_index, opsize, idata, mode); } return len; } static uint32_t parse_operand(struct INTERNAL_OPERAND *iop, struct INSTRUCTION *instr, int op_index, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { uint32_t res = 0; struct OPERAND_SIZE opsize; if (iop ->flags & FLG_W) instr ->ops[op_index].flags |= OPERAND_FLAG_WRITE; if (iop ->flags & FLG_R) instr ->ops[op_index].flags |= OPERAND_FLAG_READ; if (iop ->flags & FLG_X) instr ->ops[op_index].flags |= OPERAND_FLAG_EXEC; if (iop ->type != TQ_NULL) { instr ->ops[op_index].flags |= OPERAND_FLAG_PRESENT; if (iop ->size >= sizeof(sq_handlers) / sizeof(sq_handlers[0])) { idata ->severe_err = DASM_ERR_INTERNAL; } else { sq_handlers[iop ->size](&opsize, instr, idata, mode); } if (iop ->size >= sizeof(tq_handlers) / sizeof(tq_handlers[0])) { idata ->severe_err = DASM_ERR_INTERNAL; } else { res = tq_handlers[iop ->type](instr, op_index, &opsize, idata, mode); } } return res; } //Checks if LOCK is superfluous. static uint8_t check_lock_superfluous(struct INSTRUCTION *instr, struct OPCODE_DESCRIPTOR *opcode) { uint8_t res; int i; struct OPERAND *op; if (!(opcode ->props & PROP_LOCK)) { res = DASM_ERR_NON_LOCKABLE; } else { op = NULL; for (i = 0; i < MAX_OPERANDS_COUNT; i++) { if (instr ->ops[i].flags & OPERAND_TYPE_MEM) { op = instr ->ops + i; break; } } if (!op) { res = DASM_ERR_NON_LOCKABLE; } else if (!(op ->flags & OPERAND_FLAG_WRITE)) { res = DASM_ERR_NON_LOCKABLE; } else { res = DASM_ERR_OK; } } return res; } //Applies disassembling options. static void apply_disasm_options(struct INSTRUCTION *instr, uint32_t len, struct DISASM_PARAMS *params) { int i; for (i = 0; i < MAX_OPERANDS_COUNT; i++) { if (params ->options & DISASM_OPTION_APPLY_REL) { if (instr ->ops[i].flags & OPERAND_FLAG_REL) { instr ->ops[i].value.imm.imm64 += len + params ->base; } } if (params ->options & DISASM_OPTION_OPTIMIZE_DISP) { if ((instr ->ops[i].flags & OPERAND_TYPE_MEM) && (instr ->ops[i].value.addr.mod != ADDR_MOD_DISP)) { if (instr ->disp.value.d64 == 0x0) instr ->ops[i].value.addr.mod &= ~ADDR_MOD_DISP; } } if (params ->options & DISASM_OPTION_COMPUTE_RIP) { if ((instr ->ops[i].flags & OPERAND_TYPE_MEM) && (instr ->ops[i].value.addr.mod == (ADDR_MOD_BASE | ADDR_MOD_DISP)) && (instr ->ops[i].value.addr.base == REG_CODE_IP)) { instr ->ops[i].value.addr.mod = ADDR_MOD_DISP; instr ->disp.value.d64 += len + params ->base; } } } } //Copies instruction's flags from struct OPCODE_DESCRIPTOR to struct INSTRUCTION. static void copy_instr_flags(struct INSTRUCTION *instr, struct OPCODE_DESCRIPTOR *opcode) { if (opcode ->props & PROP_IOPL) instr ->flags |= INSTR_FLAG_IOPL; if (opcode ->props & PROP_RING0) instr ->flags |= INSTR_FLAG_RING0; if (opcode ->props & PROP_SERIAL) instr ->flags |= INSTR_FLAG_SERIAL; if (opcode ->props & PROP_UNDOC) instr ->flags |= INSTR_FLAG_UNDOC; } //Copies instruction's tested, modified, set, cleared and underfined //eflags values from struct OPCODE_DESCRIPTOR to struct INSTRUCTION. static void copy_eflags(struct INSTRUCTION *instr, struct OPCODE_DESCRIPTOR *opcode) { instr ->tested_flags = opcode ->tested_flags; instr ->modified_flags = opcode ->modified_flags; instr ->set_flags = opcode ->set_flags; instr ->cleared_flags = opcode ->cleared_flags; instr ->undefined_flags = opcode ->undefined_flags; } //Copies MODRM and SIB bytes to struct INSTRUCTION. static uint8_t parse_modrm_sib(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, struct OPCODE_DESCRIPTOR *opcode) { uint8_t len = 0; if (opcode ->props & PROP_MODRM) { len++; instr ->flags |= INSTR_FLAG_MODRM; readbuff_get_bytes_inc(&idata ->rbuff, idata, &instr ->modrm, 1); if (instr ->addrsize != 2) { if ((instr ->modrm & 0x7) == 0x4 && (instr ->modrm & 0xC0) != 0xC0) { len++; instr ->flags |= INSTR_FLAG_SIB; readbuff_get_bytes_inc(&idata ->rbuff, idata, &instr ->sib, 1); } } } return len; } //Converts prefixes from internal to external representation. static void convert_prefixes(struct INSTRUCTION *instr, uint8_t prefixes[]) { int i; for (i = 0; i < PREFIX_COUNT; i++) { if (prefixes[i] != 0xFF) instr ->prefixes |= pref_bits[prefixes[i]]; } } //If DISASM_PARAMS.sf_prefixes != NULL, copies superfluous prefix's value to the array. static void add_sf_prefix_value(uint8_t prefixes[], int index, uint8_t value, struct INSTRUCTION *instr, struct DISASM_PARAMS *params) { instr ->flags |= INSTR_FLAG_SF_PREFIXES; if (params ->sf_prefixes) params ->sf_prefixes[params ->sf_prefixes_len++] = value; prefixes[index] = 0xFF; } //Gets superfluous prefix's value by its index and call to function above :). static void add_sf_prefix(uint8_t prefixes[], uint32_t index, struct INSTRUCTION *instr, struct DISASM_PARAMS *params) { add_sf_prefix_value(prefixes, index, pref_opcodes[prefixes[index]], instr, params); } //Checks if opcode-extension prefixes (repz, repnz, opsize) are superfluous. /* static void check_ext_sf_prefixes(uint8_t prefixes[], struct INSTRUCTION *instr, struct DISASM_PARAMS *params) { if (prefixes[PREF_OPSIZE_INDEX] != 0xFF) add_sf_prefix(prefixes, PREF_OPSIZE_INDEX, instr, params); if (prefixes[PREF_REP_INDEX] != 0xFF) add_sf_prefix(prefixes, PREF_OPSIZE_INDEX, instr, params); } */ //Get instruction's size. Well, really this is size of implicit operand // that influences on instruction's mnemonic. static void get_instruction_opsize(struct MULTI_MNEMONIC *multi_mnemonic, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { struct OPERAND_SIZE opsize; if (multi_mnemonic ->size >= sizeof(sq_handlers) / sizeof(sq_handlers[0])) { opsize.sign = 0; opsize.size = 0; opsize.size_in_stream = 0; idata ->severe_err = DASM_ERR_INTERNAL; } else { sq_handlers[multi_mnemonic ->size](&opsize, instr, idata, mode); } instr ->opsize = (uint8_t)opsize.size; //Possible sizes are 2/4/8. } //Parses instruction's mnemonic. If mnemonic is simple, it is just copied to // struct INSTRUCTION. If mnemonic contains has multi mnemonic indicator (MM_INDICATOR) // at first character then it depends on implicit operand's size. In this case the function // calls get_instruction_opsize and builds choses mnemonic basing on result. static void parse_mnemonic(struct OPCODE_DESCRIPTOR *opcode, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t mode) { if (opcode ->mnemonic.value[0] != MM_INDICATOR) { unistrcpy(instr ->mnemonic, opcode ->mnemonic.value); } else { get_instruction_opsize(opcode ->mnemonic.multi_mnemonic, instr, idata, mode); if (!instr ->opsize) { idata ->severe_err = DASM_ERR_INTERNAL; } else { if (instr ->opsize == 1) { unistrcpy(instr ->mnemonic,opcode ->mnemonic.multi_mnemonic ->values[0]); } else { unistrcpy(instr ->mnemonic,opcode ->mnemonic.multi_mnemonic ->values[bsf(instr ->opsize) - 1]); } } } } //Main function for parsing prefixes. Reads input stream until meets non-prefix byte // or maximum instruction length is exceeded. The function checks if a prefix of the same group // was already met and if so, replaces old prefix with a new one. // Old prefix is added to superfluous prefixes array. // The function also checks if a prefix is opcode-extension. static uint32_t parse_prefixes(struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, uint8_t *ext_table_index, uint8_t *ext_pref_index, struct DISASM_PARAMS *params) { uint8_t pref_code; uint8_t rex_found; uint8_t pref_id; uint8_t pref_index; uint32_t res; uint32_t tmp; struct OPCODE_DESCRIPTOR *ptr; res = 0; rex_found = 0; for(;;) { readbuff_get_bytes(&idata ->rbuff, idata, &pref_code, 1); /*pref_code = *offset; if (res > MAX_INSTRUCTION_LEN) { idata ->severe_err = DASM_ERR_TOO_LONG;//error: instruction too long. break; } */ if (idata ->severe_err) break; ptr = &(tables[IDX_1BYTE].opcodes[pref_code]); if ( !( (ptr ->groups & GRP_PREFIX) || (params ->mode == DISASSEMBLE_MODE_64 && pref_code >= 0x40 && pref_code <= 0x4F && !rex_found) ) ) { break; } else { if (rex_found) { idata ->severe_err = DASM_ERR_REX_NOOPCD;//error: an opcode should follow after rex. break; } if (!rex_found && params ->mode == DISASSEMBLE_MODE_64) { if ( (pref_code >= 0x40) && (pref_code <= 0x4F) ) { idata ->prefixes[PREF_REX_INDEX] = PREF_REX_ID; instr ->rex = pref_code; rex_found = 1; readbuff_inc(&idata ->rbuff, 1); res++; continue; } } tmp = tq_handlers[ptr ->ops[0].type](instr, 0, NULL, NULL, params ->mode); pref_index = (uint8_t)(tmp >> 8); pref_id = tmp & 0xFF; if (idata ->prefixes[pref_index] != 0xFF) { add_sf_prefix(idata ->prefixes, pref_index, instr, params); } idata ->prefixes[pref_index] = pref_id; //Used later for prefix table switch. if (ptr ->id == ID_66 || ptr ->id == ID_REPZ || ptr ->id == ID_REPNZ) { *ext_table_index = ptr ->props & 0xFF; *ext_pref_index = pref_index; } readbuff_inc(&idata ->rbuff, 1); res++; } } return res; } //Reads input stream and iterates through tables looking up appropriate struct OPCODE_DESCRIPTOR. // Byte value at [offset] is used as index, the function checks tables limits and max instruction's length. static uint32_t lookup_opcode(uint8_t table, struct OPCODE_DESCRIPTOR **opcode_descr, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata) { uint8_t max; uint8_t opcode, orig_opcode; uint32_t res; res = 0; *opcode_descr = NULL; for(;;) { readbuff_get_bytes(&idata ->rbuff, idata, &opcode, 1); orig_opcode = opcode; if (idata ->severe_err) break; opcode >>= tables[table].shift; opcode &= tables[table].mask; opcode -= tables[table].min; //It looks strange, but I want that table descriptors contain // "real" values. max = tables[table].max - tables[table].min; if (opcode > max) { idata ->severe_err = DASM_ERR_BADCODE; break; } if ( !(tables[table].props & TBL_PROP_MODRM) ) { readbuff_inc(&idata ->rbuff, 1); res++; instr ->opcodes[instr ->opcodes_len++] = orig_opcode; } if (tables[table].opcodes[opcode].groups & GRP_SWITCH) { table = tables[table].opcodes[opcode].props & 0xFF; continue; } break; } if ( !(idata ->severe_err) ) *opcode_descr = &(tables[table].opcodes[opcode]); return res; } //Main function for parsing opcode and prefixes. First of all it parses all prefixes and then // looks up for struct OPCODE_DESCRIPTOR. The following algorithm is used to handle instructions that // use prefixes as opcode extension: // // * Have we prefix that may be opcode extension? // No: Lookup starts from 1byte table. // * Is instruction found? // No: Error. // Yes: Success. // Yes: Lookup starts from 'ext_table_index' table. // * Is instruction found? // No: Lookup starts from 1byte table. // * Is instruction found? // No: Error. // Yes: Success. // Yes: Success. static uint32_t parse_opcode(struct OPCODE_DESCRIPTOR **opcode_descr, struct INSTRUCTION *instr, struct DISASM_INTERNAL_DATA *idata, struct DISASM_PARAMS *params) { uint8_t ext_table_index; uint8_t ext_prefix_index; uint32_t res; uint32_t tmp; ext_table_index = 0xFF; res = parse_prefixes(instr, idata, &ext_table_index, &ext_prefix_index, params); if (!idata ->severe_err) { instr ->opcode_offset = (uint8_t)res; if (ext_table_index != 0xFF && *(idata ->rbuff.offset) == 0xF) { tmp = lookup_opcode(ext_table_index, opcode_descr, instr, idata); if (!idata ->severe_err && (*opcode_descr) ->id != ID_NULL) { instr ->opcode_pref = pref_opcodes[idata ->prefixes[ext_prefix_index]]; idata ->prefixes[ext_prefix_index] = 0xFF; //check_ext_sf_prefixes(idata ->prefixes, instr, params); if (idata ->prefixes[PREF_REP_INDEX] != 0xFF) { add_sf_prefix(&idata ->prefixes[PREF_REP_INDEX], PREF_REP_INDEX, instr, params); } res += tmp; } else { idata ->severe_err = 0; instr ->opcodes_len = 0; readbuff_init(&idata ->rbuff, idata ->rbuff.origin_offset, idata ->rbuff.origin_offset + instr ->opcode_offset, idata ->rbuff.length - instr ->opcode_offset); res += lookup_opcode(IDX_1BYTE, opcode_descr, instr, idata); } } else { res += lookup_opcode(IDX_1BYTE, opcode_descr, instr, idata); } if (!idata ->severe_err && (*opcode_descr) ->id == ID_NULL) { idata ->severe_err = DASM_ERR_BADCODE;//error: invalid opcode. } } return res; } //Disassembler's entry point. So long because does everything :). uint32_t medi_disassemble(uint8_t *buff, size_t bufflen, struct INSTRUCTION *instr, struct DISASM_PARAMS *params) { uint32_t len; uint32_t res; struct OPCODE_DESCRIPTOR *opcode; struct DISASM_INTERNAL_DATA idata; //Setup everything. memset(instr, 0x0, sizeof(*instr)); memset(&idata, 0x0, sizeof(idata)); memset(idata.prefixes, 0xFF, sizeof(idata.prefixes)); readbuff_init(&idata.rbuff, buff, buff, bufflen); params ->sf_prefixes_len = 0; len = res = 0; //Lookup opcode. res = parse_opcode(&opcode, instr, &idata, params); if (idata.severe_err) { return idata.severe_err; } len += res; get_address_size(instr, idata.prefixes, params ->mode); //Parse MODRM and SIB bytes. res = parse_modrm_sib(instr, &idata, opcode); if (idata.severe_err) { return idata.severe_err; } len += res; //Copy flags, eflags, id, groups. copy_eflags(instr, opcode); copy_instr_flags(instr, opcode); instr ->id = opcode ->id; instr ->groups = opcode ->groups; //Parse mnemonic. parse_mnemonic(opcode, instr, &idata, params ->mode); if (idata.severe_err) { return idata.severe_err; } //Deal with operands. res = parse_operand(opcode ->ops, instr, 0, &idata, params ->mode); if (idata.severe_err) { return idata.severe_err; } len += res; res = parse_operand(opcode ->ops + 1, instr, 1, &idata, params ->mode); if (idata.severe_err) { return idata.severe_err; } len += res; res = parse_operand(opcode ->ops + 2, instr, 2, &idata, params ->mode); if (idata.severe_err) { return idata.severe_err; } len += res; //Do postprocessing if necessary. if (opcode ->props & PROP_POST_PROC) { res = postprocs[opcode ->props >> POST_PROC_SHIFT](instr, &idata, &len, params); if (idata.severe_err) { return idata.severe_err; } } //Check if REX is superfluous. if (params ->mode == DISASSEMBLE_MODE_64 && instr ->rex && !idata.is_rex_used) add_sf_prefix_value(idata.prefixes, PREF_REX_INDEX, instr ->rex, instr, params); //Check if opsize is superfluous. if (!idata.is_opsize_used && idata.prefixes[PREF_OPSIZE_INDEX] != 0xFF) add_sf_prefix(idata.prefixes, PREF_OPSIZE_INDEX, instr, params); //Check if addrsize is superfluous. if (!idata.is_addrsize_used && idata.prefixes[PREF_ADDRSIZE_INDEX] != 0xFF) add_sf_prefix(idata.prefixes, PREF_ADDRSIZE_INDEX, instr, params); //Check if segment prefix is superfluous. if (!idata.is_seg_used && idata.prefixes[PREF_SEG_INDEX] != 0xFF) add_sf_prefix(idata.prefixes, PREF_SEG_INDEX, instr, params); //Check if repz/repnz prefix is superfluous. if (!(opcode ->props & PROP_ALLOW_REP) && idata.prefixes[PREF_REP_INDEX] != 0xFF) add_sf_prefix(idata.prefixes, PREF_REP_INDEX, instr, params); //Convert prefixes to output representation. convert_prefixes(instr, idata.prefixes); //And post checks. if (!(params ->arch & opcode ->arch)) idata.err = DASM_ERR_ANOT_ARCH;//error: another architecture. else if (instr ->prefixes & INSTR_PREFIX_LOCK) idata.err = check_lock_superfluous(instr, opcode);//error: check if prefix lock on non-lockable instruction. else if ((opcode ->props & PROP_I64) && (params ->mode == DISASSEMBLE_MODE_64)) idata.err = DASM_ERR_16_32_ONLY;//error: instruction is 16/32bit mode only. else if (opcode ->props & PROP_O64 && params ->mode != DISASSEMBLE_MODE_64) idata.err = DASM_ERR_64_ONLY;//error: instruction is 64bit mode only. apply_disasm_options(instr, len, params); //Copy length instr ->length = (uint8_t)len; return idata.err; }
bef0fd58d0405bb6579881ef8ab91aec14505ffe
a97a88663c73460135e9285042d2e8ecd3570052
/GTThreads (Symmetric multiprocessor)/gt_matrix.c
cd60c96b39556206566b8f86725cb8034635f072
[]
no_license
PandaWei/gtthreads
2084db593402e3ec47c3ddbe2375cd63d6513443
db8e52a443718eec78bf38c67eb64b1388632592
refs/heads/master
2020-12-24T22:19:31.464933
2016-06-17T03:42:58
2016-06-17T03:42:58
61,343,479
0
0
null
2016-06-17T03:38:44
2016-06-17T03:38:42
C
UTF-8
C
false
false
6,611
c
gt_matrix.c
#include <stdio.h> #include <unistd.h> #include <linux/unistd.h> #include <sys/syscall.h> #include <sys/time.h> #include <sys/types.h> #include <sched.h> #include <signal.h> #include <setjmp.h> #include <errno.h> #include <assert.h> #include <math.h> #include <stdlib.h> #include "gt_include.h" #define ROWS 32 #define COLS ROWS #define SIZE COLS #define SIZE_FIRST SIZE //32// //First set of 32 threads out of 128 threads multiply matrices of size 32 #define SIZE_SECOND SIZE*2 //64// //Second set of 32 threads out of 128 threads multiply matrices of size 64 #define SIZE_THIRD SIZE*4 //128// //Third set of 32 threads out of 128 threads multiply matrices of size 128 #define SIZE_FOURTH SIZE*8 //256// //Last set of 32 threads out of 128 threads multiply matrices of size 256 :) #define NUM_GROUPS 4 #define PER_GROUP_COLS (SIZE/NUM_GROUPS) #define NUM_THREADS 128 #define PER_THREAD_ROWS (SIZE/NUM_THREADS) /* A[SIZE][SIZE] X B[SIZE][SIZE] = C[SIZE][SIZE] * Let T(g, t) be thread 't' in group 'g'. * T(g, t) is responsible for multiplication : * A(rows)[(t-1)*SIZE -> (t*SIZE - 1)] X B(cols)[(g-1)*SIZE -> (g*SIZE - 1)] */ typedef struct matrix { int m[256][256]; int rows; int cols; unsigned int reserved[2]; } matrix_t; typedef struct __uthread_arg { matrix_t *_A, *_B, *_C; unsigned int reserved0; unsigned int tid; unsigned int gid; int start_row; /* start_row -> (start_row + PER_THREAD_ROWS) */ int start_col; /* start_col -> (start_col + PER_GROUP_COLS) */ int end_row; int end_col; }uthread_arg_t; struct timeval tv1; static void generate_matrix(matrix_t *mat, int val) { int i,j; mat->rows = 256; //Matrices of all threads initialized to size 256, but each thread only multiplies the size it has to. mat->cols = 256; for(i = 0; i < mat->rows;i++) for( j = 0; j < mat->cols; j++ ){ mat->m[i][j] = val; } return; } static void print_matrix(void *p) { int i, j; #define ptr1 ((uthread_arg_t *)p) for(i=0;i<ptr1->end_row;i++) { for(j=0;j<ptr1->end_col;j++) printf(" %d ",ptr1->_C->m[i][j]); printf("\n"); } return; } static void init_matrices(matrix_t *A, matrix_t *B, matrix_t *C) { generate_matrix(A, 1); generate_matrix(B, 1); generate_matrix(C, 0); return; } static void * uthread_mulmat(void *p) { int i, j, k; int start_row, end_row; int start_col, end_col; unsigned int cpuid; struct timeval tv2; #define ptr ((uthread_arg_t *)p) ptr->_A = (matrix_t*)malloc(sizeof(matrix_t)); ptr->_B = (matrix_t*)malloc(sizeof(matrix_t)); ptr->_C = (matrix_t*)malloc(sizeof(matrix_t)); init_matrices(ptr->_A, ptr->_B, ptr->_C); i=0; j= 0; k=0; start_row = ptr->start_row; end_row = ptr->end_row;//(ptr->start_row + PER_THREAD_ROWS); #ifdef GT_GROUP_SPLIT start_col = ptr->start_col; end_col = ptr->end_col;//(ptr->start_col + PER_THREAD_ROWS); #else start_col = 0; end_col = ptr->end_col; #endif #ifdef GT_THREADS cpuid = kthread_cpu_map[kthread_apic_id()]->cpuid; fprintf(stderr, "\nThread(id:%d, group:%d, cpu:%d) started",ptr->tid, ptr->gid, cpuid); #else fprintf(stderr, "\nThread(id:%d, group:%d) started",ptr->tid, ptr->gid); #endif for(i = start_row; i < end_row; i++) for(j = start_col; j < end_col; j++) for(k = 0; k < end_row; k++){ //Only multiply matrix of size the thread actually has to. ptr->_C->m[i][j] += ptr->_A->m[i][k] * ptr->_B->m[k][j]; } #ifdef GT_THREADS fprintf(stderr, "\nThread(id:%d, group:%d) finished (TIME : %lu s and %lu us)", ptr->tid, ptr->gid, (tv2.tv_sec - tv1.tv_sec), (tv2.tv_usec - tv1.tv_usec)); #else gettimeofday(&tv2,NULL); fprintf(stderr, "\nThread(id:%d, group:%d) finished (TIME : %lu s and %lu us)", ptr->tid, ptr->gid, (tv2.tv_sec - tv1.tv_sec), (tv2.tv_usec - tv1.tv_usec)); gt_spin_lock(stat_lock); exec[ptr->gid] += (double)(((tv2.tv_sec - tv1.tv_sec)) + ((tv2.tv_usec - tv1.tv_usec)/100000)); exec_thread[ptr->gid][ptr->tid]+= (double)(((tv2.tv_sec - tv1.tv_sec)) + ((tv2.tv_usec - tv1.tv_usec)/100000)); gt_spin_unlock(stat_lock); gt_yield(); #endif //print_matrix(ptr); #undef ptr return 0; } uthread_arg_t uargs[NUM_THREADS]; uthread_t utids[NUM_THREADS]; int main() { gt_spinlock_init(stat_lock); uthread_arg_t *uarg = (uthread_arg_t*)malloc(sizeof(uthread_arg_t)); int inx; int i=0, j, k, l; double sd=0, sd2=0; for(j=0; j<4; j++){ vruntime[j]=0; exec[j]=0; for(k=0; k<128; k++){ vruntime_thread[j][k]=0; exec_thread[j][k]=0; } } gtthread_app_init(); gettimeofday(&tv1,NULL); for(inx=0; inx<NUM_THREADS; inx++){ uarg = &uargs[inx]; uarg->tid = inx; uarg->gid = (inx % NUM_GROUPS); uarg->start_row = 0; #ifdef GT_GROUP_SPLIT uarg->start_col = 0; #endif //Assign the size of matrix each thread has to multiply. //Assign consecutive threads to multiply matrices of different sizes. I thought of assigning the first 32 threads to multiply matrix of SIZE, //the next 32 threads to multiply matrix of SIZE*2 and so on, but this approach sort of more accurately loads the threads uniformly. switch(uarg->gid){ case 0: { uarg->end_row = SIZE_FIRST; uarg->end_col = SIZE_FIRST; break;} case 1: { uarg->end_row = SIZE_SECOND; uarg->end_col = SIZE_SECOND; break;} case 2: { uarg->end_row = SIZE_THIRD; uarg->end_col = SIZE_THIRD; break;} case 3: { uarg->end_row = SIZE_FOURTH; uarg->end_col = SIZE_FOURTH; break;} } uthread_create(&utids[inx], uthread_mulmat, uarg, uarg->gid); } gtthread_app_exit(); //STATS///////////////////////////////////////////////////////////////////// for(j=0; j<4; j++){ printf("Mean vruntime for threads in vgroup %d is %lf us\n", j, vruntime[j]/32); printf("Mean total execution time for threads in vgroup %d is %lf s\n", j, exec[j]/32); } for(j=0; j<4; j++){ vruntime[j] = vruntime[j]/100000; for(k=0; k<128; k++) { if(vruntime_thread[j][k]!=0){ vruntime_thread[j][k] = (vruntime_thread[j][k])/100000; sd += pow((vruntime_thread[j][k]-(vruntime[j]/32)),2); //printf("vruntime %f vruntimegp %f sd %f\n", vruntime_thread[j][k], vruntime[j]/32, sd); } if(exec_thread[j][k]!=0){ sd2 += pow((exec_thread[j][k]-(exec[j]/32)),2); } } sd = sqrt(sd)/sqrt(32); sd2 = sqrt(sd2)/sqrt(32); printf("Standard deviation of vruntime for threads in vgroup %d is %lf\n",j,sd); printf("Standard deviation of total execution time for threads in vgroup %d is %lf\n",j,sd2); sd=0; sd2=0; } return 0; }
a88721ce24586dd22f49a33ea2e563e9181c8831
95200d7e891c2691c95a60c5e8bb17a12af9f3d9
/main_adc.c
7a7164f47ac3f27d8853959db4baf2e493050a48
[ "CC0-1.0" ]
permissive
bernardocarvalho/dsPIC-codes
15e9e2647fa6b5152237209693eb055aef7538b7
28e52f3a7bfc7e943d59e20431aa67d8a4d52e09
refs/heads/master
2020-12-20T00:22:53.732179
2020-02-28T19:08:36
2020-02-28T19:08:36
235,897,932
0
2
CC0-1.0
2020-01-28T14:10:57
2020-01-23T22:18:25
Makefile
UTF-8
C
false
false
12,267
c
main_adc.c
/* * Program name, short description, creation date and author's name * Optional: Include Licence information (GPL, CC, EULA, etc) */ //Parameter defines #define FCY 29491200UL //Library includes #include <xc.h> // xc.h finds the correct library to include based on $MCU #include <libpic30.h> //Device configuration registers #pragma config FPR = XT_PLL16 #pragma config FOS = PRI #pragma config FCKSMEN = CSW_FSCM_OFF #pragma config WDT = WDT_OFF #pragma config MCLRE = MCLR_EN #pragma config FPWRT = PWRT_OFF //extern void nop_test(void); #define LED1 _LATF0 //define port for LED1 #define LED2 _LATF1 //define port for LED1 /*This is global var to use with UART2*/ char c; unsigned int an0pin[128]; unsigned int an1pin[128]; unsigned char count=0; unsigned char printdata=0; /* This is TMR1 ISR */ void __attribute__((interrupt, auto_psv)) _T1Interrupt(void){ IFS0bits.T1IF = 0; LED2 = ~LED2; if(count >= 0 && count <= 127){ _SAMP=0; while(!_DONE); an0pin[count]=ADCBUF1; an1pin[count]=ADCBUF0; count++; } } /* This is UART2 receive ISR */ void __attribute__((__interrupt__, __no_auto_psv__)) _U2RXInterrupt(void){ IFS1bits.U2RXIF = 0; //resets RX2 interrupt flag c = U2RXREG; //reads the character to the c variable if(c=='q'){ _T1IE = 0; count=0; T1CONbits.TON = 0; TMR1 = 0; } else if(c=='a'){ _T1IE = 1; TMR1 = 0; count = 0; T1CONbits.TON = 1; } else {} } /*This is the UART2 configuration routine*/ void uart_config(void){ /********************************** SerialPort configuration **********************************/ U2MODEbits.UARTEN = 0; // Bit15 TX, RX DISABLED, ENABLE at end of func U2MODEbits.USIDL = 0; // Bit13 Continue in Idle U2MODEbits.WAKE = 0; // Bit7 No Wake up (since we don't sleep here) U2MODEbits.LPBACK = 0; // Bit6 No Loop Back U2MODEbits.ABAUD = 0; // Bit5 No Autobaud (would require sending '55') U2MODEbits.PDSEL = 0; // Bits1,2 8bit, No Parity U2MODEbits.STSEL = 0; // Bit0 One Stop Bit // Load a value into Baud Rate Generator. Example is for 11500. // U2BRG = (Fcy/(16*BaudRate))-1 // U2BRG = (29491200/(16*115200))-1 // U2BRG = 15 U2BRG = 15; IFS1bits.U2RXIF = 0; // Clear the Receive Interrupt Flag IEC1bits.U2RXIE = 1; // Enable Receive Interrupts U2MODEbits.UARTEN = 1; // And turn the peripheral on __C30_UART = 2; /********************************** End of serialPort configuration **********************************/ } void configure_simsamp_autosamp_adc10(){ // dsPIC30F4011 - ADC 10-bits (Simultaneous sampling AN0 and AN1 using automatic sampling and MUXA) //Other options are avaliable to obtain simultaneously sample two pins. This is just an example! // Important Notes :) : // // MUXA and BUFFER connections: // AN1 -(connection)-> Connected to CH0 -(converting...)-> Write Buffer 0x0 (ADCBUF0) // AN0 -(connection)-> Connected to CH1 -(converting...)-> Write Buffer 0x1 (ADCBUF1) // // OPERATION ROUTINE: // _SAMP=0; will start conversion since sampling is automatic // while(!_DONE); wait until conversion is done and buffers are ready // an0pin=ADCBUF1; get the data on the buffers corresponding to the two pins // an1pin=ADCBUF0; //****************************// //ADCON1: A/D Control Register 1 //****************************// ADCON1bits.ADON=0; //**A/D Operating Mode bit**// // 0-A/D converter is off // 1-A/D converter module is operating // NOTE: Remember to put the ADON register to 1 before using! ADCON1bits.ADSIDL=0; //**Stop in Idle Mode bit**// // 0-Continue module operation in Idle mode // 1-Discontinue module operation when device enters Idle mode ADCON1bits.FORM=0; //**Sata Output Format bits**// // 0-Integer // 1-Signed integer // 2-Fractional // 3-Singed fractional ADCON1bits.SSRC=0; //**Conversion Trigger Source Select bits**// // 0-Clearing SAMP bit ends sampling and starts conversion // 1-Active transition on INT0 pin ends sampling and starts conversion // 2-General purpose Timer3 compare ends sampling and starts conversion // 3-Motor Control PWM interval ends sampling and starts conversion // 4-Reserved // 5-Reserved // 6-Reserved // 7-Internal counter ends sampling and starts conversion (auto convert) ADCON1bits.SIMSAM=1; //Simultaneous Sample Select bit (only applicable when CHPS = 01 or 1x) //1 = Samples CH0, CH1, CH2, CH3 simultaneously (when CHPS = 1x) //or //Samples CH0 and CH1 simultaneously (when CHPS = 01) //0 = Samples multiple channels individually in sequence ADCON1bits.ASAM=1; //**A/D Sample Auto-Start bit**// // 0-Sampling begins when SAMP bit set // 1-Sampling begins immediately after last conversion completes. SAMP bit is auto set. ADCON1bits.SAMP=0; //**A/D Sample Enable bit**// // 0-A/D sample/hold amplifiers are holding // 1-At least one A/D sample/hold amplifier is sampling //****************************// //ADCON2: A/D Control Register 2 //****************************// ADCON2bits.VCFG=0; //**Voltage Reference Configuration bits**// // 0- AVdd and AVss // 1- External Vref+_pin and AVss // 2- AVdd and External Vref-_pin // 3- External Vref+ pin and External Vref- pin // (4-7)- AVdd and AVss ADCON2bits.CHPS = 1; //1x = Converts CH0, CH1, CH2 and CH3 //01 = Converts CH0 and CH1 //00 = Converts CH0 ADCON2bits.CSCNA=0; //**Scan Input Selections for CH0+ S/H Input for MUX A Multiplexer Setting bit**/ // 0-Do not scan inputs // 1-Scan inputs ADCON2bits.BUFS=0; //**Buffer Fill Status bit**// // 0-A/D is currently filling buffer 0x0-0x7, user should access data in 0x8-0xF // 1-A/D is currently filling buffer 0x8-0xF, user should access data in 0x0-0x7 ADCON2bits.SMPI=0; //**Sample/Convert Sequences Per Interrupt Selection bits**// // 0-Interrupts at the completion of conversion for each sample/convert sequence // 1-Interrupts at the completion of conversion for each 2nd sample/convert sequence // ... // 14-Interrupts at the completion of conversion for each 15th sample/convert sequence // 15-Interrupts at the completion of conversion for each 16th sample/convert sequence ADCON2bits.BUFM=0; //**Buffer Mode Select bit**// // 0-Buffer configured as one 16-word buffer ADCBUF(15...0) // 0-Buffer configured as one 8-word buffer ADCBUF(15...8), ADCBUF(7...0) ADCON2bits.ALTS=0; //**Alternate Input Sample Mode Select bit**// // 0-Always use MUX A input multiplexer settings /* 1-Uses MUX A input multiplexer settings for first sample, then alternate between MUX B and MUX A input multiplexer settings for all subsequent samples*/ //****************************// //ADCON3: A/D Control Register 3 //****************************// ADCON3bits.SAMC=3; //**Auto Sample Time bits**// (Used when you have auto conversion mode enabled which is not the case) // (0-31) Tad ADCON3bits.ADRC=0; //**A/D Conversion Clock Source bit**// // 0-Clock derived from system clock // 1-A/D internal RC clock ADCON3bits.ADCS=20; //**A/D Conversion Clock Select bits**// // (1-64)*Tcy/2 //******************************// //ADCHS: A/D Input Select Register //******************************// ADCHSbits.CH123NB=0; //(MUXB not used in this application) ADCHSbits.CH123SB=0; //(MUXB not used in this application) ADCHSbits.CH123NA=0; //0x -> CH1-, CH2-, CH3- = VREF- (GND) ADCHSbits.CH123SA=0; //0 -> CH1+ = AN0, CH2+ = AN1, CH3+ = AN2 ADCHSbits.CH0NB=0; //Channel 0 Negative Input Select. Same definition as in CH0NA (MUXB not used in this application) ADCHSbits.CH0SB=0; //Channel 0 Positive Input Select for MUX B Multiplexer Setting bits (MUXB not used in this application) ADCHSbits.CH0NA=0; // Channel 0 Negative Input Select for MUX A Multiplexer Setting bit //1 = Channel 0 negative input is AN1 //0 = Channel 0 negative input is VREF- (GND) ADCHSbits.CH0SA=1; //Channel 0 Positive Input Select for MUX A Multiplexer Setting bits //1111 = Channel 0 positive input is AN15 //1110 = Channel 0 positive input is AN14 //1101 = Channel 0 positive input is AN13 //... //0001 = Channel 0 positive input is AN1 //0000 = Channel 0 positive input is AN0 //*************************************// //ADPCFG: A/D Port Configuration Register //*************************************// ADPCFG = 0xFFFC; //AN0 and AN1 selected as ADC input (No need to define TRIS for these pins!) //1 = Analog input pin in Digital mode, port read input enabled, A/D input multiplexer input connected to AVSS //0 = Analog input pin in Analog mode, port read input disabled, A/D samples pin voltage //*************************************// //ADCSSL: A/D Input Scan Select Register //*************************************// ADCSSL = 0x0000; //AN0 and AN1 - A/D Input Pin Scan Selection bits (for sequential sampling only!) //1 = Select ANx for input scan //0 = Skip ANx for input scan // AD Interrupts _ADIE=0; //No interruptions are required for this application. Use your own timer. //Otherwise set ADIE register to 1 and check register SMPI value! // Start the ADC module! (Keep it here OR comment and set the bit to 1 on a specific position of your code) ADCON1bits.ADON=1; } //Device Main routine int main() { short int ii; long il=5, ll =2, lk; float a=1.1, b=1.1, c; TRISFbits.TRISF1 = 0; TRISEbits.TRISE8 = 1; LATFbits.LATF1 = 1; //nop_test(); //assembly function call example /* Beggining of execution */ printf("Serial port says: Hello\n\r"); //checks if UART2 is working fine _TRISF0 = 0; //Configure led port as output _TRISF1 = 0; //Configure led port as output LED1 = 1; LED2 = 1; /*Timer_1 config*/ T1CONbits.TON = 0; //Timer_1 is OFF TMR1 = 0; //resets Timer_1 PR1 = 29490; //sets the maximum count for Timer_1 to generate an interrupt every 1ms T1CONbits.TCS = 0; //choose FCY as clock source for Timer_1 T1CONbits.TCKPS = 0x0; //sets the Timer-1 pre-scaler at 1 IFS0bits.T1IF = 0; //clears the Timer_1 interrupt flag _T1IE = 0; //disables Timer_1 Interrupts T1CONbits.TON = 0; //turns Timer_1 ON uart_config(); configure_simsamp_autosamp_adc10(); printf("Serial port says: Hello\n\r"); //checks if UART2 is working fine LED1 = 0; /*main cycle*/ while(1) { if(count>=128){ _T1IE = 0; count=0; T1CONbits.TON = 0; TMR1 = 0; printf("Acquisition Results:\n\r"); for(count=0;count<128;count++){ __delay_ms(50); printf("%03d\t%04d\t%04d\n\r", count,an0pin[count],an1pin[count]); } count=0; printf("END\n\r"); } else{} } return 0; }
32138fb2a3627437293f88c7093f0bedf8a53c88
bb1b915d481ad766bd0b04584ab90027edf185b0
/土壤传感器/see/NIxie.H
643169c3e5a45893884c32ae592491c270f479d0
[]
no_license
smallcatx0/learnC51
e4c9476ee2dfc8e131eeac50b118cafaba67da18
eb8f4288782d501d8c41e699b7d55b404ac885bd
refs/heads/master
2021-05-14T09:58:36.197163
2017-08-06T06:54:12
2017-08-06T06:54:12
116,340,090
0
0
null
null
null
null
GB18030
C
false
false
915
h
NIxie.H
/* 数码管显示头文件 数码管段选P3^6 位选P3^7 数据口 N_IO 此文件包含数码管 段选(shu[]) 位选(wei[])码 带小数点的段选码为(shu[]|0x80) 数码管显示函数:Shuma_Display(wei[],shu[]); 2017-1-14 17:47:49 */ #ifndef NIxie #define NIxie #ifndef uchar #define uchar unsigned char #endif #ifndef uint #define uint unsigned int #endif /*------------ 数码管参数设置 ------------------*/ #define N_IO P1 sbit D = P2^7; sbit W = P2^6; uchar code shu[]={0x3f,0x06,0x5b,0x4f,0x66, 0x6d,0x7d,0x07,0x7f,0x6f, /*前面是0~9的断选码*/ 0x77,0x7c,0x39,0x5e,0x79,0x71,/*A-F*/ 0x40,/*-*/}; uchar code wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //--------数码管显示函数------- void Shuma_Display(uchar w,uchar d){ uchar i; // 送位选 N_IO = w; W = 1; W = 0; // 送断选 N_IO = d; D = 1; D = 0; for(i=0;i<250;i++); } #endif
2cf665c8d25a7724248b32509eecf88cf7f86827
38fd1cfc8a03ebdb4359c9a76b9e704b5eba557a
/src/cacacomun.c
82261e5ef8b7e2fa311690005052fa2f173f1a77
[]
no_license
weskerhluffy/unos_locos
809a6a6cebc35b125fcb4be3d490d3176b5a61c1
aaca0456d9200dc63311031db38beb460f4d36fb
refs/heads/master
2021-01-01T05:38:25.460551
2015-02-28T19:03:07
2015-02-28T19:03:07
15,855,228
0
0
null
null
null
null
UTF-8
C
false
false
77,533
c
cacacomun.c
/* * cacacomun.c * * Created on: 07/02/2014 * Author: ernesto */ #include <config.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef HAVE_EXECINFO_H # include <execinfo.h> #endif #include <stdarg.h> #include <zlog.h> #include <time.h> #include <inttypes.h> #include <sys/time.h> #ifdef __MACH__ #include <mach/clock.h> #include <mach/mach.h> #endif #include <math.h> #include "cacacomun.h" zlog_category_t *cacategoria = NULL; bool zlog_inicializado = falso; #undef ADDITEM #define ADDITEM( criterio_ordenacion, comentario) [criterio_ordenacion]=comentario const char* GRAFO_NOMBRES_CRITERIOS_ORDENACION[GRAFO_PRINCIPAL + 1] = { #include "tipos_ordenacion.h" }; #undef ADDITEM int lee_matriz_int_archivo(const char * nombre_archivo, tipo_dato matrix[MAX_COLUMNAS_INPUT][MAX_FILAS_INPUT], int *filas) { int indice_filas = 0; int indice_columnas = 0; long numero = 0; char *inicio_cadena_num = NULL; char linea[TAM_MAX_LINEA]; FILE *fp; fp = fopen(nombre_archivo, "r"); if (fp == NULL) { perror("Error while opening the file.\n"); exit(EXIT_FAILURE); } while (fgets(linea, TAM_MAX_LINEA, fp) != NULL) { /* writing content to stdout */ inicio_cadena_num = strtok(linea, " "); indice_columnas = 0; while (inicio_cadena_num != NULL) { numero = strtol(inicio_cadena_num, NULL, 10); matrix[indice_columnas][indice_filas] = (tipo_dato) numero; inicio_cadena_num = strtok(NULL, " "); indice_columnas++; } indice_filas++; } *filas = indice_filas; fclose(fp); return 0; } int mierda(const char * nombre_archivo, tipo_dato matrix[MAX_COLUMNAS_INPUT][MAX_FILAS_INPUT], int *filas) { int indice_filas = 0; int indice_columnas = 0; long numero = 0; char *inicio_cadena_num = NULL; char linea[TAM_MAX_LINEA]; FILE *fp; fp = fopen(nombre_archivo, "r"); if (fp == NULL) { perror("Error while opening the file.\n"); exit(EXIT_FAILURE); } while (fgets(linea, TAM_MAX_LINEA, fp) != NULL) { /* writing content to stdout */ inicio_cadena_num = strtok(linea, " "); indice_columnas = 0; while (inicio_cadena_num != NULL) { numero = strtol(inicio_cadena_num, NULL, 10); matrix[indice_columnas][indice_filas] = (tipo_dato) numero; inicio_cadena_num = strtok(NULL, " "); indice_columnas++; } indice_filas++; } *filas = indice_filas; fclose(fp); return 0; } int lee_matriz_long_stdin(tipo_dato matrix[MAX_COLUMNAS_INPUT][MAX_FILAS_INPUT], int *filas) { int indice_filas = 0; char linea[TAM_MAX_LINEA]; fgets(linea, TAM_MAX_LINEA, stdin); sscanf(linea, "%ld %ld", &matrix[0][indice_filas], &matrix[1][indice_filas]); indice_filas++; while (fgets(linea, TAM_MAX_LINEA, stdin) && sscanf(linea, "%ld %ld", &matrix[0][indice_filas], &matrix[1][indice_filas]) == 2) { indice_filas++; } *filas = indice_filas; return 0; } /* XXX: : http://www.eclipse.org/forums/index.php/t/26571/ */ /* XXX: : http://stackoverflow.com/questions/3537542/a-doxygen-eclipse-plugin-with-automatic-code-completion */ int lee_matrix_long_stdin(tipo_dato *matrix, int *num_filas, int *num_columnas, int num_max_filas, int num_max_columnas) { int indice_filas = 0; int indice_columnas = 0; long numero = 0; char *siguiente_cadena_numero = NULL; char *cadena_numero_actual = NULL; char linea[TAM_MAX_LINEA]; caca_log_debug("DDDDDDDDDDDentro de leer mierda"); /* XXX: : http://stackoverflow.com/questions/2195823/reading-unknown-number-of-integers-from-stdin-c */ while (fgets(linea, TAM_MAX_LINEA, stdin)) { caca_log_debug("escaneando linea"); indice_columnas = 0; caca_log_debug("transformando linea '%s'", linea); cadena_numero_actual = linea; for (siguiente_cadena_numero = linea;; siguiente_cadena_numero = cadena_numero_actual) { caca_log_debug("la cadena restante '%s'", cadena_numero_actual); numero = strtol(siguiente_cadena_numero, &cadena_numero_actual, 10); caca_log_debug("el num actual %ld", numero); if (cadena_numero_actual == siguiente_cadena_numero) { caca_log_debug("se llego al final de la cadena"); break; } caca_log_debug("guardando el numero %ld en fil %d, col %d", numero, indice_filas, indice_columnas); *(matrix + indice_filas * num_max_columnas + indice_columnas) = numero; indice_columnas++; if (indice_columnas >= num_max_columnas) { perror("se leyeron demasiadas columnas, a la verga"); abort(); } } caca_log_debug("salio del ciclo de linea"); /* *(*num_columnas + indice_filas) = indice_columnas; */ if (num_columnas) { num_columnas[indice_filas] = indice_columnas; } caca_log_debug("c asigno el numero de columnas"); indice_filas++; caca_log_debug("terminada de procesar linea '%s'", linea); if (indice_filas >= num_max_filas) { perror("se leyeron demasiadas filas, a la verga"); abort(); } } *num_filas = indice_filas; caca_log_debug("termino de recibir mierda"); return 0; } int caca_imprime_matrix(void *matrix, int num_filas, int *num_columnas, int num_columnas_fijo) { bool es_array = falso; int i = 0, j = 0; int num_columnas_actual = 0; tipo_dato numero_actual = 0; tipo_dato *matrix_array = NULL; tipo_dato **matrix_pointer = NULL; matrix_array = matrix; matrix_pointer = matrix; caca_log_debug("Me corto los webos"); caca_log_debug("pero q mierda void pointer %p %p", matrix, sbrk(0)); /* es_array = !from_stack(matrix); */ es_array = verdadero; caca_log_debug("determinado q es array %d", es_array); if (!num_columnas && !num_columnas_fijo) { caca_log_debug("No mames no ay nada con q trabajar"); } num_columnas_actual = num_columnas_fijo ? num_columnas_fijo : 0; for (i = 0; i < num_filas; i++) { caca_log_debug("En la fila %d de %d", i, num_filas); if (num_columnas) { num_columnas_actual = *(num_columnas + i); } if (num_columnas_fijo) { num_columnas_actual = num_columnas_fijo; } /* caca_log_debug("el num d cols actual %d", num_columnas_actual); */ for (j = 0; j < num_columnas_actual; j++) { if (es_array) { /* caca_log_debug("copiando array"); */ numero_actual = *(matrix_array + i * num_columnas_actual + j); } else { caca_log_debug("copiando apuntadores bidimensional"); numero_actual = *(*(matrix_pointer + i) + j); } /* caca_log_debug("copiado numero"); */ if (numero_actual) { caca_log_debug("en %d %d el num %ld", i, j, numero_actual); } } } caca_log_debug("El # de filas %d", num_filas); if (num_columnas) { for (i = 0; i < num_filas; i++) { caca_log_debug("en fila %d, columnas %d", i, *(num_columnas + i)); } } else { caca_log_debug("num d columnas para todas las filas %d", num_columnas_fijo); } return 0; } /*int init_grafo(tipo_dato[3][MAX_FILAS_INPUT], grafo_contexto *ctx, int num_filas, bool usar_hashes) */ int init_grafo(void *matrix, int num_filas, grafo_contexto *ctx, bool usar_hashes, bool relaciones_bidireccionales) { int i = 0; int contador_nodos = 0; GRAFO_TIPO_RESULTADO_BUSQUEDA tipo_resultado = GRAFO_NADA_ENCONTRADO; tipo_dato distancia_actual = 0, indice_nodo_origen_actual = 0, indice_nodo_destino_actual = 0; /* XXX: : http://stackoverflow.com/questions/11454376/cast-void-pointer-to-integer-array */ tipo_dato (*matrix_int)[3] = NULL; nodo nodo_tmp; nodo *nodo_origen_actual = NULL; nodo *nodo_destino_actual = NULL; nodo *nodos_encontrados[2] = { NULL }; matrix_int = (tipo_dato (*)[3]) matrix; caca_log_debug("despues de acer el cacast"); memset((void *) ctx, 0, sizeof(grafo_contexto)); caca_log_debug("despues de acer el set de ceros"); memset((void *) ctx->matrix_distancias, MAX_VALOR, sizeof(ctx->matrix_distancias)); memset((void *) &nodo_tmp, 0, sizeof(nodo)); caca_log_debug("despues de inicializar contexto %s", "mierdadsdsadsa"); caca_imprime_matrix(matrix, num_filas, NULL, 3); for (i = 0; i < num_filas; i++) { indice_nodo_origen_actual = *(*(matrix_int + i) + GRAFO_NODO_ORIGEN); indice_nodo_destino_actual = *(*(matrix_int + i) + GRAFO_NODO_DESTINO); distancia_actual = *(*(matrix_int + i) + GRAFO_DISTANCIA_ENTRE_NODOS); caca_log_debug("En fila %d, origen %ld, destino %ld, distancia %ld", i, indice_nodo_origen_actual, indice_nodo_destino_actual, distancia_actual); nodo_tmp.indice = indice_nodo_origen_actual; tipo_resultado = busqueda_binaria(ctx->inicio, &nodo_tmp, GRAFO_PRINCIPAL, (void *) &nodos_encontrados); switch (tipo_resultado) { case GRAFO_NODO_ENCONTRADO: nodo_origen_actual = *nodos_encontrados; break; case GRAFO_NODOS_PRE_POST_ENCONTRADOS: nodo_origen_actual = grafo_nodo_alloc(ctx, 1); nodo_origen_actual->indice = indice_nodo_origen_actual; caca_log_debug("anadiendo %p a lista principal, entre %p y %p", nodo_origen_actual, *nodos_encontrados, *(nodos_encontrados + 1)) ; grafo_insertar_nodo(*nodos_encontrados, *(nodos_encontrados + 1), nodo_origen_actual, GRAFO_PRINCIPAL); /* if (*(nodos_encontrados + 1) == ctx->inicio) { */ if (!*nodos_encontrados) { *grafo_apuntador_num_nodos_asociados(nodo_origen_actual, GRAFO_PRINCIPAL) = *grafo_apuntador_num_nodos_asociados( ctx->inicio, GRAFO_PRINCIPAL) + 1; ctx->inicio = nodo_origen_actual; } else { (*grafo_apuntador_num_nodos_asociados(ctx->inicio, GRAFO_PRINCIPAL))++; } *grafo_apuntador_num_nodos_asociados(nodo_origen_actual, GRAFO_INDICE) = -1; *grafo_apuntador_num_nodos_asociados(nodo_origen_actual, GRAFO_DISTANCIA) = -1; contador_nodos++; break; case GRAFO_NADA_ENCONTRADO: nodo_origen_actual = grafo_nodo_alloc(ctx, 1); nodo_origen_actual->indice = indice_nodo_origen_actual; ctx->inicio = nodo_origen_actual; *grafo_apuntador_num_nodos_asociados(nodo_origen_actual, GRAFO_PRINCIPAL) = 0; *grafo_apuntador_num_nodos_asociados(nodo_origen_actual, GRAFO_INDICE) = -1; *grafo_apuntador_num_nodos_asociados(nodo_origen_actual, GRAFO_DISTANCIA) = -1; caca_log_debug("Se inicia la lista de nodos en ctx") ; contador_nodos++; break; default: perror("no se pudo configurar ctx d graph"); exit(1); break; } nodo_destino_actual = grafo_nodo_alloc(ctx, 1); nodo_destino_actual->distancia = distancia_actual; nodo_destino_actual->indice = indice_nodo_destino_actual; caca_log_debug("insertando nodo %p en lista de indices de %p", nodo_destino_actual, nodo_origen_actual); grafo_anadir_nodo(nodo_origen_actual, nodo_destino_actual, GRAFO_INDICE); caca_log_debug("insertando nodo %p en lista de distancias de %p", nodo_destino_actual, nodo_origen_actual); grafo_anadir_nodo(nodo_origen_actual, nodo_destino_actual, GRAFO_DISTANCIA); if (usar_hashes) { ctx->matrix_distancias[indice_nodo_origen_actual][indice_nodo_destino_actual] = distancia_actual; *(ctx->referencias_nodos_por_indice + indice_nodo_origen_actual) = nodo_origen_actual; } if (relaciones_bidireccionales) { caca_log_debug("Dando de alta relacion espejo-pendejoº"); nodo_tmp.indice = indice_nodo_destino_actual; tipo_resultado = busqueda_binaria(ctx->inicio, &nodo_tmp, GRAFO_PRINCIPAL, (void *) &nodos_encontrados); switch (tipo_resultado) { case GRAFO_NODO_ENCONTRADO: nodo_origen_actual = *nodos_encontrados; break; case GRAFO_NODOS_PRE_POST_ENCONTRADOS: nodo_origen_actual = grafo_nodo_alloc(ctx, 1); nodo_origen_actual->indice = indice_nodo_destino_actual; caca_log_debug("anadiendo %p a lista principal, entre %p y %p", nodo_origen_actual, *nodos_encontrados, *(nodos_encontrados + 1)) ; grafo_insertar_nodo(*nodos_encontrados, *(nodos_encontrados + 1), nodo_origen_actual, GRAFO_PRINCIPAL); if (!*nodos_encontrados) { *grafo_apuntador_num_nodos_asociados(nodo_origen_actual, GRAFO_PRINCIPAL) = *grafo_apuntador_num_nodos_asociados(ctx->inicio, GRAFO_PRINCIPAL) + 1; ctx->inicio = nodo_origen_actual; } else { (*grafo_apuntador_num_nodos_asociados(ctx->inicio, GRAFO_PRINCIPAL))++; } *grafo_apuntador_num_nodos_asociados(nodo_origen_actual, GRAFO_INDICE) = -1; *grafo_apuntador_num_nodos_asociados(nodo_origen_actual, GRAFO_DISTANCIA) = -1; contador_nodos++; break; case GRAFO_NADA_ENCONTRADO: nodo_origen_actual = grafo_nodo_alloc(ctx, 1); nodo_origen_actual->indice = indice_nodo_destino_actual; ctx->inicio = nodo_origen_actual; *grafo_apuntador_num_nodos_asociados(nodo_origen_actual, GRAFO_PRINCIPAL) = 0; *grafo_apuntador_num_nodos_asociados(nodo_origen_actual, GRAFO_INDICE) = -1; *grafo_apuntador_num_nodos_asociados(nodo_origen_actual, GRAFO_DISTANCIA) = -1; caca_log_debug("Se inicia la lista de nodos en ctx") ; contador_nodos++; break; default: perror("no se pudo configurar ctx d graph"); exit(1); break; } nodo_destino_actual = grafo_nodo_alloc(ctx, 1); nodo_destino_actual->distancia = distancia_actual; nodo_destino_actual->indice = indice_nodo_origen_actual; caca_log_debug("insertando nodo %p en lista de indices de %p", nodo_destino_actual, nodo_origen_actual); grafo_anadir_nodo(nodo_origen_actual, nodo_destino_actual, GRAFO_INDICE); caca_log_debug("insertando nodo %p en lista de distancias de %p", nodo_destino_actual, nodo_origen_actual); grafo_anadir_nodo(nodo_origen_actual, nodo_destino_actual, GRAFO_DISTANCIA); if (usar_hashes) { ctx->matrix_distancias[indice_nodo_destino_actual][indice_nodo_origen_actual] = distancia_actual; *(ctx->referencias_nodos_por_indice + indice_nodo_destino_actual) = nodo_origen_actual; } } } return (contador_nodos); } nodo *grafo_nodo_alloc(grafo_contexto *ctx, int localidades_solicitadas) { nodo *inicio_localidades_allocadas = NULL; if ((sizeof(ctx->nodos_disponibles) - ctx->localidades_usadas) >= localidades_solicitadas) { inicio_localidades_allocadas = ctx->nodos_disponibles + ctx->localidades_usadas; ctx->localidades_usadas += localidades_solicitadas; #ifdef GRAFO_DEBUG_ALLOC caca_log_debug("el inicio actual es %p", ctx->nodos_disponibles + ctx->localidades_usadas); #endif } #ifdef GRAFO_DEBUG_ALLOC caca_log_debug( "las localidades usadas son %d, la direccion regresada es %p, cuyo inicio es %p", ctx->localidades_usadas, inicio_localidades_allocadas, ctx->nodos_disponibles); #endif return inicio_localidades_allocadas; } GRAFO_TIPO_RESULTADO_BUSQUEDA busqueda_lineal(nodo *inicio, nodo *nodo_a_buscar, GRAFO_CRITERIOS_ORDENACION criterio_busqueda, void *nodos_encontrados, int limite_nodos_busqueda) { int num_nodos_recorridos = 0; GRAFO_TIPO_RESULTADO_BUSQUEDA tipo_resultado = GRAFO_NADA_ENCONTRADO; char buffer[MAX_TAM_CADENA] = { '\0' }; char buffer1[MAX_TAM_CADENA] = { '\0' }; nodo *nodo_actual = NULL; nodo *nodo_anterior = NULL; nodo **nodos_encontrados_int = NULL; nodos_encontrados_int = ((nodo **) nodos_encontrados); nodo_actual = inicio; /* GRAFO_AVANZAR_NODO(nodo_actual, criterio_busqueda, verdadero); */ caca_log_debug("nodo inicial %p, nodo a buscar %p, limite de buskeda %d", inicio, nodo_a_buscar, limite_nodos_busqueda); while (nodo_actual && num_nodos_recorridos <= limite_nodos_busqueda && tipo_resultado == GRAFO_NADA_ENCONTRADO) { caca_log_debug( "Comparando actual %s con el q c busca %s con criterio %s", grafo_nodo_a_cadena(nodo_actual, buffer, NULL), grafo_nodo_a_cadena(nodo_a_buscar, buffer1, NULL), GRAFO_NOMBRES_CRITERIOS_ORDENACION[criterio_busqueda]); switch (criterio_busqueda) { case GRAFO_VALOR: nodo_anterior = nodo_actual; if (nodo_actual->valor == nodo_a_buscar->valor) { tipo_resultado = GRAFO_NODO_ENCONTRADO; continue; } if (nodo_actual->valor > nodo_a_buscar->valor) { tipo_resultado = GRAFO_NODOS_PRE_POST_ENCONTRADOS; continue; } nodo_actual = nodo_actual->siguiente_valor; break; case GRAFO_DISTANCIA: nodo_anterior = nodo_actual; caca_log_debug("Se asigno nodo anterior en distancia") ; if (nodo_actual->distancia == nodo_a_buscar->distancia) { tipo_resultado = GRAFO_NODO_ENCONTRADO; continue; } if (nodo_actual->distancia > nodo_a_buscar->distancia) { tipo_resultado = GRAFO_NODOS_PRE_POST_ENCONTRADOS; continue; } nodo_actual = nodo_actual->siguiente_distancia; caca_log_debug("Avanzado en distancia con tipo resultado %d", tipo_resultado) ; break; case GRAFO_INDICE: nodo_anterior = nodo_actual; caca_log_debug( "comparando indices nodo actual %ld con nodo a buscar %ld", nodo_actual->indice, nodo_a_buscar->indice) ; if (nodo_actual->indice == nodo_a_buscar->indice) { tipo_resultado = GRAFO_NODO_ENCONTRADO; continue; } if (nodo_actual->indice > nodo_a_buscar->indice) { tipo_resultado = GRAFO_NODOS_PRE_POST_ENCONTRADOS; continue; } nodo_actual = nodo_actual->siguiente_indice; caca_log_debug("Avanzado en indice con tipo resultado %d", tipo_resultado) ; break; case GRAFO_PRINCIPAL: nodo_anterior = nodo_actual; if (nodo_actual->indice == nodo_a_buscar->indice) { tipo_resultado = GRAFO_NODO_ENCONTRADO; continue; } if (nodo_actual->indice > nodo_a_buscar->indice) { tipo_resultado = GRAFO_NODOS_PRE_POST_ENCONTRADOS; continue; } nodo_actual = nodo_actual->siguiente; break; default: perror("en busqueda lineal hubo un error culero al buscar"); exit(1); break; } caca_log_debug("Salio del case con %d", tipo_resultado); num_nodos_recorridos++; } /* if (tipo_resultado != GRAFO_NADA_ENCONTRADO) { num_nodos_recorridos++; } else { if (nodo_actual) { tipo_resultado = GRAFO_NODOS_PRE_POST_ENCONTRADOS; } } */ if (tipo_resultado == GRAFO_NADA_ENCONTRADO && nodo_actual) { tipo_resultado = GRAFO_NODOS_PRE_POST_ENCONTRADOS; } if (nodo_actual && num_nodos_recorridos <= limite_nodos_busqueda) { if (tipo_resultado == GRAFO_NODO_ENCONTRADO) { *nodos_encontrados_int = nodo_actual; } if (tipo_resultado == GRAFO_NODOS_PRE_POST_ENCONTRADOS) { switch (criterio_busqueda) { case GRAFO_VALOR: *nodos_encontrados_int = nodo_actual->anterior_valor; *(nodos_encontrados_int + 1) = nodo_actual; break; case GRAFO_DISTANCIA: *nodos_encontrados_int = nodo_actual->anterior_distancia; *(nodos_encontrados_int + 1) = nodo_actual; break; case GRAFO_INDICE: *nodos_encontrados_int = nodo_actual->anterior_indice; *(nodos_encontrados_int + 1) = nodo_actual; break; case GRAFO_PRINCIPAL: *nodos_encontrados_int = nodo_actual->anterior; *(nodos_encontrados_int + 1) = nodo_actual; break; default: perror( "en busqueda lineal hubo un error culero al asignar resultados"); exit(EXIT_FAILURE); break; } } } else { caca_log_debug("Se reccorrio toda la lista sin encontrar"); if (nodo_anterior) { caca_log_debug( "HAy un nodo anterior, lo q significa que al menos c recorrio un nodo"); tipo_resultado = GRAFO_NODOS_PRE_POST_ENCONTRADOS; switch (criterio_busqueda) { case GRAFO_VALOR: *nodos_encontrados_int = nodo_anterior; *(nodos_encontrados_int + 1) = nodo_anterior->siguiente_valor; break; case GRAFO_DISTANCIA: *nodos_encontrados_int = nodo_anterior; *(nodos_encontrados_int + 1) = nodo_anterior->siguiente_distancia; break; case GRAFO_INDICE: *nodos_encontrados_int = nodo_anterior; *(nodos_encontrados_int + 1) = nodo_anterior->siguiente_indice; break; case GRAFO_PRINCIPAL: *nodos_encontrados_int = nodo_anterior; *(nodos_encontrados_int + 1) = nodo_anterior->siguiente; caca_log_debug("El nodo anterior %p, el nodo siguiente %p", *nodos_encontrados_int, *(nodos_encontrados_int + 1)) ; break; default: perror( "en busqueda lineal hubo un error culero al asignar resultados sin nodo actual"); exit(EXIT_FAILURE); break; } } } return tipo_resultado; } GRAFO_TIPO_RESULTADO_BUSQUEDA busqueda_binaria(nodo *inicio, nodo *nodo_a_buscar, GRAFO_CRITERIOS_ORDENACION criterio_busqueda, void *nodos_encontrados) { int i = 0; GRAFO_TIPO_RESULTADO_BUSQUEDA tipo_resultado = GRAFO_NADA_ENCONTRADO; char buffer[MAX_TAM_CADENA]; nodo *nodo_actual = NULL; nodo *arreglo_nodos_tmp[MAX_NODOS] = { NULL }; nodo_actual = inicio; caca_log_debug("El nodo inicial %p", inicio); if (!nodo_actual) { return tipo_resultado; } caca_log_debug("Antes de creaer el arreglo temporal"); do { caca_log_debug("En iteracion %d", i); *(arreglo_nodos_tmp + i) = nodo_actual; caca_log_debug("Nodo actual %p", nodo_actual); caca_log_debug("en la iteracion %d el nodo es %s", i, grafo_nodo_a_cadena(nodo_actual, buffer, NULL)); GRAFO_AVANZAR_NODO(nodo_actual, criterio_busqueda, falso); i++; } while (nodo_actual); caca_log_debug("Despues de creaer el arreglo temporal"); tipo_resultado = busqueda_binaria_recursiva(inicio, arreglo_nodos_tmp, nodo_a_buscar, criterio_busqueda, nodos_encontrados, 0, *grafo_apuntador_num_nodos_asociados(inicio, criterio_busqueda)); caca_log_debug("Al salir %d", tipo_resultado); return tipo_resultado; } GRAFO_TIPO_RESULTADO_BUSQUEDA busqueda_binaria_recursiva(nodo *inicio, nodo **arreglo_nodos, nodo *nodo_a_buscar, GRAFO_CRITERIOS_ORDENACION criterio_busqueda, void *nodos_encontrados, int indice_inicial, int indice_final) { int resultado_comparacion = 0; int indice_medio = 0; GRAFO_TIPO_RESULTADO_BUSQUEDA tipo_resultado = GRAFO_NADA_ENCONTRADO; char cadena1[MAX_TAM_CADENA] = { '\0' }; char cadena2[MAX_TAM_CADENA] = { '\0' }; nodo **nodos_encontrados_int = NULL; nodos_encontrados_int = ((nodo **) nodos_encontrados); caca_log_debug("entrando con inicio %d y fin %d", indice_inicial, indice_final); caca_log_debug("nodo inicial %p, nodo a buscar %p", inicio, nodo_a_buscar); if ((indice_final - indice_inicial) <= GRAFO_LIMITE_ORDENACION_LINEAL) { caca_log_debug("buscando linealmento, ventana menor a %d", GRAFO_LIMITE_ORDENACION_LINEAL); tipo_resultado = busqueda_lineal(*(arreglo_nodos + indice_inicial), nodo_a_buscar, criterio_busqueda, nodos_encontrados, indice_final - indice_inicial + 1); } else { indice_medio = (indice_inicial + indice_final) / 2; caca_log_debug("el indice medio pendejo es %d", indice_medio); resultado_comparacion = grafo_comparar_nodos(nodo_a_buscar, *(arreglo_nodos + indice_medio), criterio_busqueda); caca_log_debug("la comparacion se hizo"); caca_log_debug("comparando nodo %s con %s (posicion %d), resultado %d", grafo_nodo_a_cadena(nodo_a_buscar, cadena1, NULL), grafo_nodo_a_cadena(*(arreglo_nodos + indice_medio), cadena2, NULL), indice_medio, resultado_comparacion); if (resultado_comparacion == CACA_COMPARACION_IZQ_IGUAL) { tipo_resultado = GRAFO_NODO_ENCONTRADO; *nodos_encontrados_int = *(arreglo_nodos + indice_medio); } else { if (resultado_comparacion == CACA_COMPARACION_IZQ_MENOR) { indice_final = indice_medio - 1; } else { if (resultado_comparacion == CACA_COMPARACION_IZQ_MAYOR) { indice_inicial = indice_medio + 1; } else { perror("What the fuck?? busqueda_binaria_recursiva"); exit(1); } } caca_log_debug( "recursividad arreglo_nodos %d final %d, el medio es %d", indice_inicial, indice_final, indice_medio); tipo_resultado = busqueda_binaria_recursiva(inicio, arreglo_nodos, nodo_a_buscar, criterio_busqueda, nodos_encontrados, indice_inicial, indice_final); caca_log_debug("recursividad resultado %d ", tipo_resultado); } } caca_log_debug("al salir d la funcion %d", tipo_resultado); return tipo_resultado; } /* XXX: : http://stackoverflow.com/questions/2679182/have-macro-return-a-value */ static int grafo_comparar_nodos(nodo *nodo1, nodo *nodo2, GRAFO_CRITERIOS_ORDENACION criterio_busqueda) { tipo_dato val1 = 0, val2 = 0; int resultado_comparacion; char cadena1[MAX_TAM_CADENA]; char cadena2[MAX_TAM_CADENA]; caca_log_debug("entro a grafo_comparar_nodos"); caca_log_debug("comparando %s con %s", grafo_nodo_a_cadena(nodo1, cadena1, NULL), grafo_nodo_a_cadena(nodo2, cadena2, NULL)); switch (criterio_busqueda) { case GRAFO_VALOR: val1 = nodo1->valor; val2 = nodo2->valor; break; case GRAFO_DISTANCIA: val1 = nodo1->distancia; val2 = nodo2->distancia; break; case GRAFO_INDICE: case GRAFO_PRINCIPAL: val1 = nodo1->indice; val2 = nodo2->indice; break; default: perror("en GRAFO_COMPARAR_NODOS %s un error culero al buscar"); exit(EXIT_FAILURE); break; } if (val1 < val2) { resultado_comparacion = CACA_COMPARACION_IZQ_MENOR; } else { if (val1 > val2) { resultado_comparacion = CACA_COMPARACION_IZQ_MAYOR; } else { resultado_comparacion = CACA_COMPARACION_IZQ_IGUAL; } } caca_log_debug("resultado de comparacion %s con %s %d", grafo_nodo_a_cadena(nodo1, cadena1, NULL), grafo_nodo_a_cadena(nodo2, cadena2, NULL), resultado_comparacion); return resultado_comparacion; } /* XXX: : http://stackoverflow.com/questions/4867229/code-for-printf-function-in-c */ void caca_log_debug_func(const char *format, ...) { va_list arg; va_list arg2; const char *PEDAZO_TIMESTAMP_HEADER = "tiempo: %s; "; const char *HEADER = "archivo: %s; funcion: %s; linea %d; nivel: %zd caca 8====D "; char formato[MAX_TAM_CADENA + sizeof(HEADER) + sizeof(PEDAZO_TIMESTAMP_HEADER)] = { '\0' }; char pedazo_timestamp[sizeof(PEDAZO_TIMESTAMP_HEADER) + 100] = { '\0' }; char cadena_timestamp[100] = { '\0' }; timestamp_caca(cadena_timestamp); sprintf(pedazo_timestamp, PEDAZO_TIMESTAMP_HEADER, cadena_timestamp); strcpy(formato, pedazo_timestamp); strcat(formato, HEADER); strcat(formato, format); if (!zlog_inicializado) { init_zlog("/Users/ernesto/workspace/unos_locos/zlog.conf"); } if (!cacategoria) { INIT_ZLOG_CATEGORY(cacategoria, "cacacomun"); } va_start(arg, format); va_copy(arg2, arg); /* XXX: : http://stackoverflow.com/questions/5977326/call-printf-using-va-list */ vzlog_debug(cacategoria, formato, arg2); va_end(arg2); va_end(arg); } void init_zlog(const char *arch_conf) { int rc = 0; rc = zlog_init(arch_conf); if (rc) { printf("init failed\n"); exit(EXIT_FAILURE); } zlog_inicializado = verdadero; } static char *grafo_nodo_a_cadena(nodo *node, char *cadena_buffer, int *characteres_escritos) { if (!node) { perror("q pedo, pasaron un nodo vacio!"); abort(); } if (characteres_escritos) { /* caca_log_debug("Se regresaran los characteres escribtos"); */ *characteres_escritos = sprintf(cadena_buffer, "{valor:%ld,indice:%ld,distancia:%ld} (%p) ", node->valor, node->indice, node->distancia, node); } else { sprintf(cadena_buffer, "{valor:%ld,indice:%ld,distancia:%ld} (%p) ", node->valor, node->indice, node->distancia, node); } /* caca_log_debug("Termina conversion"); */ return cadena_buffer; } int caca_apuntador_valido(void *p) { /* extern char _etext; */ /* return (p != NULL ) && ((char*) p > &_etext); */ return (p != NULL); } bool from_stack(void *ptr) { caca_log_debug("comparando %p con %p", ptr, sbrk(0)); return ptr > sbrk(0); } void grafo_insertar_nodo(nodo *nodo_anterior, nodo *nodo_siguiente, nodo *nodo_a_insertar, GRAFO_CRITERIOS_ORDENACION criterio_busqueda) { nodo **apuntador_nodo_anterior = NULL; nodo **apuntador_nodo_siguiente = NULL; nodo **nodo_a_insertar_siguente = NULL; nodo **nodo_a_insertar_anterior = NULL; if (!nodo_anterior && !nodo_siguiente) { perror("grafo_insertar_nodo no puede continuar"); exit(1); } switch (criterio_busqueda) { case GRAFO_VALOR: apuntador_nodo_anterior = nodo_anterior ? &nodo_anterior->siguiente_valor : NULL; apuntador_nodo_siguiente = nodo_siguiente ? &nodo_siguiente->anterior_valor : NULL; nodo_a_insertar_siguente = &nodo_a_insertar->siguiente_valor; nodo_a_insertar_anterior = &nodo_a_insertar->anterior_valor; break; case GRAFO_DISTANCIA: apuntador_nodo_anterior = nodo_anterior ? &nodo_anterior->siguiente_distancia : NULL; apuntador_nodo_siguiente = nodo_siguiente ? &nodo_siguiente->anterior_distancia : NULL; nodo_a_insertar_siguente = &nodo_a_insertar->siguiente_distancia; nodo_a_insertar_anterior = &nodo_a_insertar->anterior_distancia; break; case GRAFO_INDICE: apuntador_nodo_anterior = nodo_anterior ? &nodo_anterior->siguiente_indice : NULL; apuntador_nodo_siguiente = nodo_siguiente ? &nodo_siguiente->anterior_indice : NULL; nodo_a_insertar_siguente = &nodo_a_insertar->siguiente_indice; nodo_a_insertar_anterior = &nodo_a_insertar->anterior_indice; break; case GRAFO_PRINCIPAL: apuntador_nodo_anterior = nodo_anterior ? &nodo_anterior->siguiente : NULL; apuntador_nodo_siguiente = nodo_siguiente ? &nodo_siguiente->anterior : NULL; nodo_a_insertar_siguente = &nodo_a_insertar->siguiente; nodo_a_insertar_anterior = &nodo_a_insertar->anterior; caca_log_debug( "insertando %p, nodo a insrtar anterior %p, cuyo valor es %p, nodo a insertar siguiente %p, cuyo valor es %p", nodo_a_insertar, nodo_a_insertar_anterior, *nodo_a_insertar_anterior, nodo_a_insertar_siguente, *nodo_a_insertar_siguente) ; break; default: perror("fallo en grafo_insertar_nodo"); exit(EXIT_FAILURE); break; } if (apuntador_nodo_anterior) { *apuntador_nodo_anterior = nodo_a_insertar; } if (apuntador_nodo_siguiente) { *apuntador_nodo_siguiente = nodo_a_insertar; } *nodo_a_insertar_siguente = nodo_siguiente; *nodo_a_insertar_anterior = nodo_anterior; caca_log_debug("nodo %p entre %p y %p", nodo_a_insertar, nodo_anterior, nodo_siguiente); } void grafo_anadir_nodo(nodo *nodo_inicial, nodo *nodo_a_anadir, GRAFO_CRITERIOS_ORDENACION criterio_busqueda) { GRAFO_TIPO_RESULTADO_BUSQUEDA tipo_resultado; nodo *nodo_anterior = NULL; nodo *nodo_siguiente = NULL; nodo *nodo_inicial_tmp = NULL; nodo *nodos_encontrados[2] = { NULL }; caca_log_debug( "Anadiendo nodo %ld (%p) a lista %ld (%p) de %s, num de nodos asociados %d", nodo_a_anadir->indice, nodo_a_anadir, nodo_inicial->indice, nodo_inicial, GRAFO_NOMBRES_CRITERIOS_ORDENACION[criterio_busqueda], *grafo_apuntador_num_nodos_asociados(nodo_inicial, criterio_busqueda)); nodo_inicial_tmp = nodo_inicial; if (criterio_busqueda != GRAFO_PRINCIPAL) { GRAFO_AVANZAR_NODO(nodo_inicial_tmp, criterio_busqueda, verdadero); if (nodo_inicial_tmp) { *grafo_apuntador_num_nodos_asociados(nodo_inicial_tmp, criterio_busqueda) = *grafo_apuntador_num_nodos_asociados( nodo_inicial, criterio_busqueda); } } tipo_resultado = busqueda_binaria(nodo_inicial_tmp, nodo_a_anadir, criterio_busqueda, (void *) &nodos_encontrados); switch (tipo_resultado) { case GRAFO_NODOS_PRE_POST_ENCONTRADOS: nodo_anterior = *(nodos_encontrados); nodo_siguiente = *(nodos_encontrados + 1); break; case GRAFO_NODO_ENCONTRADO: GRAFO_NODO_SIG_ANT(nodo_anterior, nodo_siguiente, *nodos_encontrados, criterio_busqueda) ; break; case GRAFO_NADA_ENCONTRADO: nodo_anterior = nodo_inicial; nodo_siguiente = NULL; break; default: perror("init_grafo error"); exit(1); break; } grafo_insertar_nodo(nodo_anterior, nodo_siguiente, nodo_a_anadir, criterio_busqueda); (*grafo_apuntador_num_nodos_asociados(nodo_inicial, criterio_busqueda))++; caca_log_debug( "al terminar de añadir el # de nodos asociados en principal %d", *grafo_apuntador_num_nodos_asociados(nodo_inicial, criterio_busqueda)); nodo_inicial_tmp = nodo_inicial; GRAFO_AVANZAR_NODO(nodo_inicial_tmp, criterio_busqueda, verdadero); if (nodo_inicial_tmp) { *grafo_apuntador_num_nodos_asociados(nodo_inicial_tmp, criterio_busqueda) = *grafo_apuntador_num_nodos_asociados( nodo_inicial, criterio_busqueda); (*grafo_apuntador_num_nodos_asociados(nodo_inicial_tmp, criterio_busqueda))++; caca_log_debug( "al terminar de añadir el # de nodos asociados en 1ero a buscar %d", *grafo_apuntador_num_nodos_asociados(nodo_inicial_tmp, criterio_busqueda)); } } void imprimir_lista_adjacencia(nodo *nodo_inicial) { const char *FORMATO_CONCAT_NODO = " --> "; int caracteres_escritos = 0; char *ap_cadena = NULL; char *buffer = NULL; nodo *nodo_actual = NULL; nodo *nodo_adjacente_actual = NULL; nodo_actual = nodo_inicial; caca_log_debug("La matrix de adjacencia es:"); buffer = calloc(1000, sizeof(char)); while (nodo_actual) { nodo_adjacente_actual = nodo_actual; ap_cadena = buffer; caca_log_debug("Conexiones de nodo %s.", grafo_nodo_a_cadena(nodo_adjacente_actual, ap_cadena, &caracteres_escritos)); strcpy(ap_cadena, GRAFO_NOMBRES_CRITERIOS_ORDENACION[GRAFO_DISTANCIA]); ap_cadena += strlen( GRAFO_NOMBRES_CRITERIOS_ORDENACION[GRAFO_DISTANCIA]); nodo_adjacente_actual = nodo_actual->siguiente_distancia; while (nodo_adjacente_actual) { /* caca_log_debug("Direccion nodo adjacente %p", nodo_adjacente_actual); */ strcpy(ap_cadena, FORMATO_CONCAT_NODO); ap_cadena += strlen(FORMATO_CONCAT_NODO); grafo_nodo_a_cadena(nodo_adjacente_actual, ap_cadena, &caracteres_escritos); ap_cadena += caracteres_escritos; nodo_adjacente_actual = nodo_adjacente_actual->siguiente_distancia; } caca_log_debug("%s", buffer); ap_cadena = buffer; strcpy(ap_cadena, GRAFO_NOMBRES_CRITERIOS_ORDENACION[GRAFO_INDICE]); ap_cadena += strlen(GRAFO_NOMBRES_CRITERIOS_ORDENACION[GRAFO_INDICE]); nodo_adjacente_actual = nodo_actual->siguiente_indice; while (nodo_adjacente_actual) { /* caca_log_debug("Direccion nodo adjacente %p", nodo_adjacente_actual); */ strcpy(ap_cadena, FORMATO_CONCAT_NODO); ap_cadena += strlen(FORMATO_CONCAT_NODO); grafo_nodo_a_cadena(nodo_adjacente_actual, ap_cadena, &caracteres_escritos); ap_cadena += caracteres_escritos; nodo_adjacente_actual = nodo_adjacente_actual->siguiente_indice; } caca_log_debug("%s", buffer); nodo_actual = nodo_actual->siguiente; } } static int *grafo_apuntador_num_nodos_asociados(nodo *nodo, GRAFO_CRITERIOS_ORDENACION criterio_busqueda) { int *num_nodos = NULL; switch (criterio_busqueda) { case GRAFO_VALOR: num_nodos = &(nodo)->num_nodos_asociados_valor; break; case GRAFO_DISTANCIA: num_nodos = &(nodo)->num_nodos_asociados_distancia; break; case GRAFO_INDICE: num_nodos = &(nodo)->num_nodos_asociados_indice; break; case GRAFO_PRINCIPAL: num_nodos = &(nodo)->num_nodos_asociados; break; default: perror("en GRAFO_NUM_NODOS_ASOCIADOS hubo un error culero al buscar"); exit(EXIT_FAILURE); break; } return num_nodos; } void arbol_avl_init(arbol_binario_contexto *ctx, tipo_dato *indices, tipo_dato *datos, int num_datos, nodo_arbol_binario **arreglo_referencias_nodos) { int i = 0; tipo_dato dato_actual = 0; nodo_arbol_binario *nodo_actual = NULL; memset((void *) ctx, 0, sizeof(arbol_binario_contexto)); memset((void *) ctx->nodos_disponibles, 0, sizeof(ctx->nodos_disponibles)); caca_log_debug("initializando con num de datos %d", num_datos); for (i = 0; i < num_datos; i++) { caca_log_debug("en contador %d indice %ld", i, indices ? *(indices + i) : i + 1); if (indices && *(indices + i) == ARBOL_AVL_INDICE_INVALIDO) { caca_log_debug( "Ignorando indice %d, %ld, contienen indice invalido", i, *(indices + i)); continue; } if (!ctx->raiz) { ctx->raiz = arbol_binario_nodo_allocar(ctx, 1); if (indices) { ctx->raiz->indice = *(indices + i); } else { ctx->raiz->indice = 1; } if (arreglo_referencias_nodos) { if (indices) { *(arreglo_referencias_nodos + *(indices + i)) = ctx->raiz; } else { *(arreglo_referencias_nodos + 1) = ctx->raiz; } } ctx->raiz->valor = *(datos + i); caca_log_debug("dada de alta raiz %d,%ld,%ld", i, ctx->raiz->indice, ctx->raiz->valor); continue; } dato_actual = *(datos + i); nodo_actual = arbol_binario_nodo_allocar(ctx, 1); nodo_actual->valor = dato_actual; if (indices) { nodo_actual->indice = *(indices + i); } else { nodo_actual->indice = i + 1; } arbol_avl_insertar(&ctx->raiz, nodo_actual, ctx->no_indices_repetidos); if (arreglo_referencias_nodos) { if (indices) { *(arreglo_referencias_nodos + *(indices + i)) = nodo_actual; } else { *(arreglo_referencias_nodos + i + 1) = nodo_actual; } } caca_log_debug("Raiz actual %ld", ctx->raiz->valor); } } void arbol_avl_insertar(nodo_arbol_binario **raiz, nodo_arbol_binario *nodo_a_insertar, bool no_indices_repetidos) { nodo_arbol_binario *raiz_int = NULL; raiz_int = *raiz; char *buffer = NULL; char *buffer1 = NULL; buffer = calloc(1000, sizeof(char)); buffer1 = calloc(1000, sizeof(char)); caca_log_debug("Insertando nodo %s, ancestro actual %s", arbol_binario_nodo_a_cadena(nodo_a_insertar, buffer, NULL), raiz_int ? arbol_binario_nodo_a_cadena(raiz_int, buffer1, NULL) : "No hay nada en raiz"); if (!raiz_int) { *raiz = nodo_a_insertar; return; } switch (arbol_avl_compara_nodos(raiz_int, nodo_a_insertar)) { case CACA_COMPARACION_IZQ_MENOR: caca_log_debug("Insercion BST a la der") ; if (raiz_int->hijo_der) { caca_log_debug("Recursiva"); arbol_avl_insertar(&raiz_int->hijo_der, nodo_a_insertar, no_indices_repetidos); } else { raiz_int->hijo_der = nodo_a_insertar; ARBOL_BINARIO_ACTUALIZAR_PADRE(nodo_a_insertar, raiz_int); } break; case CACA_COMPARACION_IZQ_MAYOR: caca_log_debug("Insercion BST a la izq") ; if (raiz_int->hijo_izq) { caca_log_debug("Recursiva %p", &raiz_int->hijo_izq); arbol_avl_insertar(&raiz_int->hijo_izq, nodo_a_insertar, no_indices_repetidos); } else { caca_log_debug("Directa"); raiz_int->hijo_izq = nodo_a_insertar; ARBOL_BINARIO_ACTUALIZAR_PADRE(nodo_a_insertar, raiz_int); } break; case CACA_COMPARACION_IZQ_IGUAL: if (no_indices_repetidos) { perror("NO mames, una llave repetida, ahhhhh !"); exit(1); } else { caca_log_debug("Insercion BST a la der aunke las llaves son =s"); if (raiz_int->hijo_der) { caca_log_debug("Recursiva"); arbol_avl_insertar(&raiz_int->hijo_der, nodo_a_insertar, no_indices_repetidos); } else { raiz_int->hijo_der = nodo_a_insertar; ARBOL_BINARIO_ACTUALIZAR_PADRE(nodo_a_insertar, raiz_int); } } break; default: perror("NO mames, resultado increible en arbol_avl_insertar!"); exit(1); break; } caca_log_debug("Echa la insercion BST de %ld en ancestro %ld", ARBOL_AVL_GET_VALOR(nodo_a_insertar), ARBOL_AVL_GET_VALOR(raiz_int)); ARBOL_AVL_ACTUALIZAR_ALTURA(raiz_int); caca_log_debug("algura es %d", raiz_int->altura); caca_log_debug("hijo der %ld %p %p", ARBOL_AVL_GET_VALOR((*raiz)->hijo_izq), (*raiz)->hijo_izq, &(*raiz)->hijo_izq); switch (arbol_avl_diferencia_alturas_subarboles(raiz_int, 1, verdadero)) { case ARBOL_AVL_ALTURA_CARGADA_IZQ: caca_log_debug("Arbol cagado a la izq en %ld", raiz_int->valor) ; if (ARBOL_AVL_GET_VALOR( raiz_int->hijo_izq) < ARBOL_AVL_GET_VALOR(nodo_a_insertar)) { caca_log_debug("con hijo a la der"); arbol_binario_rotar_izq(&raiz_int->hijo_izq); } arbol_binario_rotar_der(raiz); caca_log_debug("Ahora la raiz %p %ld, izq %ld, der %ld", raiz, ARBOL_AVL_GET_VALOR(*raiz), ARBOL_AVL_GET_VALOR((*raiz)->hijo_izq), ARBOL_AVL_GET_VALOR((*raiz)->hijo_der)) ; break; case ARBOL_AVL_ALTURA_CARGADA_DER: caca_log_debug("Arbol cagado a la der en %ld", raiz_int->valor) ; if (ARBOL_AVL_GET_VALOR( raiz_int->hijo_der) > ARBOL_AVL_GET_VALOR(nodo_a_insertar)) { caca_log_debug("con hijo a la izq"); arbol_binario_rotar_der(&raiz_int->hijo_der); } arbol_binario_rotar_izq(raiz); caca_log_debug("Ahora la raiz %p %ld, izq %ld, der %ld", raiz, ARBOL_AVL_GET_VALOR(*raiz), ARBOL_AVL_GET_VALOR((*raiz)->hijo_izq), ARBOL_AVL_GET_VALOR((*raiz)->hijo_der)) ; break; case ARBOL_AVL_ALTURA_BALANCEADA: caca_log_debug("Excelente, en nodo %s, altura balancelada", arbol_binario_nodo_a_cadena(raiz_int, buffer, NULL)) ; break; default: perror("error en altura indeterminada, verga"); exit(1); break; } caca_log_debug("termino con valor %ld, raiz %p y ap raiz %p", ARBOL_AVL_GET_VALOR(*raiz), *raiz, raiz); arbol_binario_recorrido_preoder(*raiz); } static int arbol_avl_compara_nodos(nodo_arbol_binario *nodo1, nodo_arbol_binario *nodo2) { caca_log_debug("Comparando %ld con %ld", nodo1->valor, nodo2->valor); if (nodo1->valor < nodo2->valor) { return CACA_COMPARACION_IZQ_MENOR; } else { if (nodo1->valor > nodo2->valor) { return CACA_COMPARACION_IZQ_MAYOR; } else { return CACA_COMPARACION_IZQ_IGUAL; } } } static int caca_int_max(int a, int b) { return (a > b) ? a : b; } static int arbol_avl_diferencia_alturas_subarboles(nodo_arbol_binario *nodo, int tolerancia, bool considerar_balanceado_cargado_der) { int diferencia_alturas = 0; diferencia_alturas = ARBOL_AVL_GET_ALTURA( nodo->hijo_izq) - ARBOL_AVL_GET_ALTURA(nodo->hijo_der); caca_log_debug("La diferecnai entre %ld de %ld y %ld de %ld es resultao %d", ARBOL_AVL_GET_ALTURA(nodo->hijo_izq), ARBOL_AVL_GET_INDICE(nodo->hijo_izq), ARBOL_AVL_GET_ALTURA(nodo->hijo_der), ARBOL_AVL_GET_INDICE(nodo->hijo_der), diferencia_alturas); if (considerar_balanceado_cargado_der) { return diferencia_alturas < 0 - tolerancia ? ARBOL_AVL_ALTURA_CARGADA_DER : diferencia_alturas > tolerancia ? ARBOL_AVL_ALTURA_CARGADA_IZQ : ARBOL_AVL_ALTURA_BALANCEADA; } else { return diferencia_alturas < 0 - tolerancia ? ARBOL_AVL_ALTURA_CARGADA_DER : diferencia_alturas > tolerancia ? ARBOL_AVL_ALTURA_CARGADA_IZQ : ARBOL_AVL_ALTURA_BALANCEADA; } } static void arbol_binario_rotar_izq(nodo_arbol_binario **nodo) { nodo_arbol_binario *nodo_int = NULL; nodo_arbol_binario *hijo_der = NULL; nodo_arbol_binario *hijo_der_subarbol_izq = NULL; caca_log_debug("rotando %ld", ARBOL_AVL_GET_VALOR(*nodo)); nodo_int = *nodo; hijo_der = nodo_int->hijo_der; caca_log_debug("Asignado hijo der %ld", ARBOL_AVL_GET_VALOR(hijo_der)); hijo_der_subarbol_izq = hijo_der->hijo_izq; caca_log_debug("Asignado subarbol izq hijo der %ld", ARBOL_AVL_GET_VALOR(hijo_der_subarbol_izq)); caca_log_debug("Antes de la rotacion"); nodo_int->hijo_der = hijo_der_subarbol_izq; hijo_der->hijo_izq = nodo_int; ARBOL_BINARIO_ACTUALIZAR_PADRE(hijo_der, ARBOL_AVL_GET_PADRE(nodo_int)); ARBOL_BINARIO_ACTUALIZAR_PADRE(hijo_der_subarbol_izq, nodo_int); ARBOL_BINARIO_ACTUALIZAR_PADRE(nodo_int, hijo_der); caca_log_debug("Rotados los nodos"); ARBOL_AVL_ACTUALIZAR_ALTURA(nodo_int); ARBOL_AVL_ACTUALIZAR_ALTURA(hijo_der); caca_log_debug("Alturas actualizadas"); *nodo = hijo_der; } static void arbol_binario_rotar_der(nodo_arbol_binario **nodo) { nodo_arbol_binario *nodo_int = NULL; nodo_arbol_binario *hijo_izq = NULL; nodo_arbol_binario *hijo_izq_subarbol_der = NULL; caca_log_debug("rotando %ld hijo izq %ld hijo der %ld", ARBOL_AVL_GET_VALOR(*nodo), ARBOL_AVL_GET_VALOR((*nodo)->hijo_izq), ARBOL_AVL_GET_VALOR((*nodo)->hijo_der)); nodo_int = *nodo; hijo_izq = nodo_int->hijo_izq; caca_log_debug("Asignado hijo izq %ld", ARBOL_AVL_GET_VALOR(hijo_izq)); hijo_izq_subarbol_der = hijo_izq->hijo_der; caca_log_debug("Asignado subarbol der hijo izq %ld", ARBOL_AVL_GET_VALOR(hijo_izq_subarbol_der)); caca_log_debug("Antes de la rotacion"); nodo_int->hijo_izq = hijo_izq_subarbol_der; hijo_izq->hijo_der = nodo_int; ARBOL_BINARIO_ACTUALIZAR_PADRE(hijo_izq, ARBOL_AVL_GET_PADRE(nodo_int)); ARBOL_BINARIO_ACTUALIZAR_PADRE(hijo_izq_subarbol_der, nodo_int); ARBOL_BINARIO_ACTUALIZAR_PADRE(nodo_int, hijo_izq); caca_log_debug("Rotados los nodos"); ARBOL_AVL_ACTUALIZAR_ALTURA(nodo_int); ARBOL_AVL_ACTUALIZAR_ALTURA(hijo_izq); caca_log_debug("Alturas actualizadas"); *nodo = hijo_izq; } static char *arbol_binario_nodo_a_cadena(nodo_arbol_binario *node, char *cadena_buffer, int *characteres_escritos) { int characteres_escritos_int = 0; characteres_escritos_int = sprintf(cadena_buffer, "{indice:%ld, valor:%ld, altura %d, direccion %p, hijo izq:%ld (%p), hijo der:%ld (%p), padre:%ld (%p)} ", node->indice, node->valor, ARBOL_AVL_GET_ALTURA(node), node, ARBOL_AVL_GET_VALOR(node->hijo_izq), node->hijo_izq, ARBOL_AVL_GET_VALOR(node->hijo_der), node->hijo_der, ARBOL_AVL_GET_VALOR(node->padre), node->padre); if (characteres_escritos) { *characteres_escritos = characteres_escritos_int; } return cadena_buffer; } static nodo_arbol_binario *arbol_binario_nodo_allocar( arbol_binario_contexto *ctx, int localidades_solicitadas) { nodo_arbol_binario *inicio_localidades_allocadas = NULL; if ((sizeof(ctx->nodos_disponibles) - ctx->localidades_usadas) >= localidades_solicitadas) { inicio_localidades_allocadas = ctx->nodos_disponibles + ctx->localidades_usadas; ctx->localidades_usadas += localidades_solicitadas; } return inicio_localidades_allocadas; } void arbol_binario_recorrido_preoder(nodo_arbol_binario *raiz) { char buffer[MAX_TAM_CADENA]; if (!raiz) { return; } caca_log_debug("%s ", arbol_binario_nodo_a_cadena(raiz, buffer, NULL)); arbol_binario_recorrido_preoder(raiz->hijo_izq); arbol_binario_recorrido_preoder(raiz->hijo_der); } void arbol_binario_colectar_datos_recorrido_preoder(nodo_arbol_binario *raiz, tipo_dato *datos_ordenados, int *num_datos_colectados) { if (!raiz) { return; } *(datos_ordenados + (*num_datos_colectados)++) = raiz->valor; arbol_binario_colectar_datos_recorrido_preoder(raiz->hijo_izq, datos_ordenados, num_datos_colectados); arbol_binario_colectar_datos_recorrido_preoder(raiz->hijo_der, datos_ordenados, num_datos_colectados); } static nodo_arbol_binario *arbol_binario_get_nodo_minimo_valor( nodo_arbol_binario *raiz) { nodo_arbol_binario *nodo_actual = NULL; nodo_actual = raiz; while (nodo_actual->hijo_izq) { nodo_actual = nodo_actual->hijo_izq; } return nodo_actual; } void arbol_binario_borrar_nodo(nodo_arbol_binario **raiz, tipo_dato valor_a_borrar) { nodo_arbol_binario *raiz_int = NULL; nodo_arbol_binario *nodo_min = NULL; raiz_int = *raiz; if (!raiz_int) { caca_log_debug("Raiz nula, pq la mandan?"); return; } if (raiz_int->valor > valor_a_borrar) { arbol_binario_borrar_nodo(&raiz_int->hijo_izq, valor_a_borrar); } else { if (raiz_int->valor < valor_a_borrar) { arbol_binario_borrar_nodo(&raiz_int->hijo_der, valor_a_borrar); } else { if (!raiz_int->hijo_izq) { *raiz = raiz_int->hijo_der; } else { if (!raiz_int->hijo_der) { *raiz = raiz_int->hijo_izq; } else { nodo_min = arbol_binario_get_nodo_minimo_valor( raiz_int->hijo_der); raiz_int->valor = nodo_min->valor; arbol_binario_borrar_nodo(&raiz_int->hijo_der, raiz_int->valor); } } } } } void arbol_binario_recorrido_inoder(nodo_arbol_binario *raiz) { char buffer[MAX_TAM_CADENA]; if (!raiz) { return; } arbol_binario_recorrido_inoder(raiz->hijo_izq); caca_log_debug("%s ", arbol_binario_nodo_a_cadena(raiz, buffer, NULL)); arbol_binario_recorrido_inoder(raiz->hijo_der); } void arbol_binario_colectar_datos_recorrido_inoder(nodo_arbol_binario *raiz, tipo_dato *datos_ordenados, int *num_datos_colectados) { if (!raiz) { return; } arbol_binario_colectar_datos_recorrido_inoder(raiz->hijo_izq, datos_ordenados, num_datos_colectados); *(datos_ordenados + (*num_datos_colectados)++) = raiz->valor; arbol_binario_colectar_datos_recorrido_inoder(raiz->hijo_der, datos_ordenados, num_datos_colectados); } void arbol_avl_borrar(nodo_arbol_binario **raiz, tipo_dato valor_a_borrar) { nodo_arbol_binario *raiz_int = NULL; nodo_arbol_binario *nodo_min = NULL; raiz_int = *raiz; if (!raiz_int) { caca_log_debug("Raiz nula, pq la mandan?"); return; } if (raiz_int->valor > valor_a_borrar) { arbol_avl_borrar(&raiz_int->hijo_izq, valor_a_borrar); } else { if (raiz_int->valor < valor_a_borrar) { arbol_avl_borrar(&raiz_int->hijo_der, valor_a_borrar); } else { if (!raiz_int->hijo_izq) { *raiz = raiz_int->hijo_der; } else { if (!raiz_int->hijo_der) { *raiz = raiz_int->hijo_izq; } else { nodo_min = arbol_binario_get_nodo_minimo_valor( raiz_int->hijo_der); raiz_int->valor = nodo_min->valor; arbol_avl_borrar(&raiz_int->hijo_der, raiz_int->valor); ARBOL_BINARIO_ACTUALIZAR_HIJO_IZQ(nodo_min, raiz_int->hijo_izq); ARBOL_BINARIO_ACTUALIZAR_HIJO_DER(nodo_min, raiz_int->hijo_der); ARBOL_BINARIO_ACTUALIZAR_PADRE(nodo_min, raiz_int->padre); nodo_min->altura = ARBOL_AVL_GET_ALTURA(raiz_int); ARBOL_BINARIO_ACTUALIZAR_PADRE(raiz_int->hijo_izq, nodo_min); ARBOL_BINARIO_ACTUALIZAR_PADRE(raiz_int->hijo_der, nodo_min); *raiz = nodo_min; } } } } caca_log_debug("Terminado borrado BST"); if (!*raiz) { caca_log_debug("Se borro el ultimo nodo"); return; } ARBOL_AVL_ACTUALIZAR_ALTURA(raiz_int); switch (arbol_avl_diferencia_alturas_subarboles(raiz_int, 1, verdadero)) { case ARBOL_AVL_ALTURA_CARGADA_IZQ: caca_log_debug("Arbol cagado a la izq") ; if (arbol_avl_diferencia_alturas_subarboles(raiz_int->hijo_izq, 0, falso) == ARBOL_AVL_ALTURA_CARGADA_DER) { caca_log_debug("Con ijo cagado a la derecha"); arbol_binario_rotar_izq(&raiz_int->hijo_izq); } caca_log_debug("Rotando nodo raiz") ; arbol_binario_rotar_der(raiz); caca_log_debug("Ahora la raiz %ld, izq %ld, der %ld", ARBOL_AVL_GET_VALOR(*raiz), ARBOL_AVL_GET_VALOR((*raiz)->hijo_izq), ARBOL_AVL_GET_VALOR((*raiz)->hijo_der)) ; break; case ARBOL_AVL_ALTURA_CARGADA_DER: caca_log_debug("Arbol cagado a la der") ; if (arbol_avl_diferencia_alturas_subarboles(raiz_int->hijo_der, 0, verdadero) == ARBOL_AVL_ALTURA_CARGADA_IZQ) { caca_log_debug("Con ijo cagado a la izq"); arbol_binario_rotar_der(&raiz_int->hijo_der); } caca_log_debug("Rotando nodo raiz") ; arbol_binario_rotar_izq(raiz); caca_log_debug("Ahora la raiz %ld, izq %ld, der %ld", ARBOL_AVL_GET_VALOR(*raiz), ARBOL_AVL_GET_VALOR((*raiz)->hijo_izq), ARBOL_AVL_GET_VALOR((*raiz)->hijo_der)) ; break; case ARBOL_AVL_ALTURA_BALANCEADA: caca_log_debug("Arbol balanceado") ; break; default: caca_log_debug("Mother of fuck arbol_avl_borrar") ; break; } } void arbol_avl_borrar_referencia_directa(nodo_arbol_binario **raiz, nodo_arbol_binario *nodo_a_borrar) { nodo_arbol_binario *ancestro_actual = NULL; nodo_arbol_binario *nodo_a_borrar_padre = NULL; nodo_arbol_binario *nodo_min = NULL; nodo_arbol_binario **ancestro_actual_apuntador = NULL; nodo_arbol_binario **nodo_a_borrar_ref = NULL; if (!nodo_a_borrar) { caca_log_debug("Nodo a borrar nula, pq la mandan?"); abort(); } if (!(nodo_a_borrar_padre = ARBOL_AVL_GET_PADRE(nodo_a_borrar))) { nodo_a_borrar_padre = NULL; nodo_a_borrar_ref = raiz; } else { caca_log_debug("Borrando nodo no raiz"); caca_log_debug("Calculando referencia en arbolazo, padre %p", nodo_a_borrar_padre); nodo_a_borrar_ref = nodo_a_borrar->valor < (nodo_a_borrar_padre)->valor ? &nodo_a_borrar_padre->hijo_izq : nodo_a_borrar->valor > (nodo_a_borrar_padre)->valor ? &nodo_a_borrar_padre->hijo_der : nodo_a_borrar->indice == ARBOL_AVL_GET_INDICE(nodo_a_borrar_padre->hijo_izq) ? &nodo_a_borrar_padre->hijo_izq : &nodo_a_borrar_padre->hijo_der; caca_log_debug( "la referencia del nodo a borrar %p, referencia de ijo izq %p, de ijo der %p", nodo_a_borrar_ref, &nodo_a_borrar_padre->hijo_izq, &nodo_a_borrar_padre->hijo_der); caca_log_debug("borrando nodo %ld, indice %ld", nodo_a_borrar->valor, nodo_a_borrar->indice); } ancestro_actual = nodo_a_borrar->padre; ancestro_actual_apuntador = &nodo_a_borrar->padre; caca_log_debug( "ancestro actual de nodo a borrar %p, su apuntador %p, lo que apunta %p", ancestro_actual, ancestro_actual_apuntador, *ancestro_actual_apuntador); if (nodo_a_borrar_padre) { caca_log_debug("estado original de padre %p hijod izq %p hiijos der %p", nodo_a_borrar_padre, nodo_a_borrar_padre->hijo_izq, nodo_a_borrar_padre->hijo_der); } if (!nodo_a_borrar->hijo_izq) { caca_log_debug("Borrando directamente sin hijo izq"); ARBOL_BINARIO_ACTUALIZAR_PADRE(nodo_a_borrar->hijo_der, ancestro_actual); *nodo_a_borrar_ref = nodo_a_borrar->hijo_der; if (nodo_a_borrar_padre) { caca_log_debug("asi kedo el ancestro %p hijod izq %p hiijos der %p", nodo_a_borrar_padre, nodo_a_borrar_padre->hijo_izq, nodo_a_borrar_padre->hijo_der); } } else { if (!nodo_a_borrar->hijo_der) { caca_log_debug("Borrando directamente sin hijo der"); ARBOL_BINARIO_ACTUALIZAR_PADRE(nodo_a_borrar->hijo_izq, ancestro_actual); *nodo_a_borrar_ref = nodo_a_borrar->hijo_izq; } else { caca_log_debug("Borrando nodo intermedio"); nodo_min = arbol_binario_get_nodo_minimo_valor( nodo_a_borrar->hijo_der); arbol_avl_borrar_referencia_directa(raiz, nodo_min); ARBOL_BINARIO_ACTUALIZAR_HIJO_IZQ(nodo_min, nodo_a_borrar->hijo_izq); ARBOL_BINARIO_ACTUALIZAR_HIJO_DER(nodo_min, nodo_a_borrar->hijo_der); ARBOL_BINARIO_ACTUALIZAR_PADRE(nodo_min, nodo_a_borrar->padre); nodo_min->altura = ARBOL_AVL_GET_ALTURA(nodo_a_borrar); ARBOL_BINARIO_ACTUALIZAR_PADRE(nodo_a_borrar->hijo_izq, nodo_min); ARBOL_BINARIO_ACTUALIZAR_PADRE(nodo_a_borrar->hijo_der, nodo_min); *nodo_a_borrar_ref = nodo_min; } } caca_log_debug("Terminado borrado BST con ancestro %p", *ancestro_actual_apuntador); do { if (!ARBOL_AVL_GET_PADRE(nodo_a_borrar)) { caca_log_debug("el q c intenta borrar es la raiz"); break; } caca_log_debug("En el ancestro %ld %p", ARBOL_AVL_GET_INDICE(ancestro_actual), ancestro_actual); if (ARBOL_AVL_GET_PADRE(ancestro_actual)) { if (ARBOL_AVL_GET_VALOR( ancestro_actual) <= ARBOL_AVL_GET_VALOR(ancestro_actual->padre)) { ancestro_actual_apuntador = &ancestro_actual->padre->hijo_izq; } else { ancestro_actual_apuntador = &ancestro_actual->padre->hijo_der; } } else { ancestro_actual_apuntador = raiz; }; ARBOL_AVL_ACTUALIZAR_ALTURA(ancestro_actual); switch (arbol_avl_diferencia_alturas_subarboles(ancestro_actual, 1, verdadero)) { case ARBOL_AVL_ALTURA_CARGADA_IZQ: caca_log_debug("Arbol cagado a la izq") ; if (arbol_avl_diferencia_alturas_subarboles( ancestro_actual->hijo_izq, 0, falso) == ARBOL_AVL_ALTURA_CARGADA_DER) { caca_log_debug("Con ijo cagado a la derecha"); arbol_binario_rotar_izq(&ancestro_actual->hijo_izq); } caca_log_debug( "Rotando nodo ancestro_actual_apuntador %p, contenido %p, %p", ancestro_actual_apuntador, *ancestro_actual_apuntador, ancestro_actual) ; arbol_binario_rotar_der(ancestro_actual_apuntador); caca_log_debug( "Ahora la ancestro_actual_apuntador %ld, izq %ld, der %ld", ARBOL_AVL_GET_VALOR(*ancestro_actual_apuntador), ARBOL_AVL_GET_VALOR((*ancestro_actual_apuntador)->hijo_izq), ARBOL_AVL_GET_VALOR((*ancestro_actual_apuntador)->hijo_der)) ; break; case ARBOL_AVL_ALTURA_CARGADA_DER: caca_log_debug("Arbol cagado a la der") ; if (arbol_avl_diferencia_alturas_subarboles( ancestro_actual->hijo_der, 0, verdadero) == ARBOL_AVL_ALTURA_CARGADA_IZQ) { caca_log_debug("Con ijo cagado a la izq"); arbol_binario_rotar_der(&ancestro_actual->hijo_der); } caca_log_debug("Rotando nodo ancestro_actual_apuntador") ; arbol_binario_rotar_izq(ancestro_actual_apuntador); caca_log_debug( "Ahora la ancestro_actual_apuntador %ld, izq %ld, der %ld", ARBOL_AVL_GET_VALOR(*ancestro_actual_apuntador), ARBOL_AVL_GET_VALOR((*ancestro_actual_apuntador)->hijo_izq), ARBOL_AVL_GET_VALOR((*ancestro_actual_apuntador)->hijo_der)) ; break; case ARBOL_AVL_ALTURA_BALANCEADA: caca_log_debug("Arbol balanceado %ld", ancestro_actual->valor) ; break; default: caca_log_debug("Mother of fuck arbol_avl_borrar") ; break; } ancestro_actual = ancestro_actual->padre; } while (ancestro_actual); caca_log_debug("termino borrado x ref de %p", nodo_a_borrar); } void cola_prioridad_modificar_valor_nodo(cola_prioridad_contexto *cpctx, tipo_dato indice, tipo_dato nuevo_valor) { char buffer[MAX_TAM_CADENA] = { '\0' }; nodo_arbol_binario *referencia_directa = NULL; nodo_arbol_binario *nuevo_nodo = NULL; nodo_arbol_binario **referencias_directas = NULL; nodo_arbol_binario **raiz = NULL; referencias_directas = cpctx->referencias_directas_por_indice; raiz = &cpctx->actx->raiz; referencia_directa = *(referencias_directas + indice); caca_log_debug("Modificando valor de %s", arbol_binario_nodo_a_cadena(referencia_directa, buffer, NULL)); caca_log_debug("antes de borrar"); arbol_binario_recorrido_inoder(cpctx->actx->raiz); arbol_avl_borrar_referencia_directa(&cpctx->actx->raiz, referencia_directa); caca_log_debug("tras borrar quedo"); arbol_binario_recorrido_inoder(cpctx->actx->raiz); nuevo_nodo = arbol_binario_nodo_allocar(cpctx->actx, 1); /* nuevo_nodo = referencia_directa; */ memset(nuevo_nodo, 0, sizeof(nodo_arbol_binario)); nuevo_nodo->indice = indice; nuevo_nodo->valor = nuevo_valor; caca_log_debug("Re-insertando %s", arbol_binario_nodo_a_cadena(nuevo_nodo, buffer, NULL)); arbol_avl_insertar(raiz, nuevo_nodo, falso); *(referencias_directas + indice) = nuevo_nodo; } void dijkstra_relaxar_nodo(grafo_contexto *gctx, cola_prioridad_contexto *cpctx, tipo_dato ind_nodo_origen, tipo_dato ind_nodo_destino, tipo_dato *antecesores) { GRAFO_TIPO_RESULTADO_BUSQUEDA tipo_resultado; tipo_dato dist_origen_dest = 0; nodo nodo_tmp; nodo_arbol_binario *distancia_min_origen = NULL; nodo_arbol_binario *distancia_min_destino = NULL; nodo_arbol_binario **distancias_minimas = NULL; nodo *nodos_encontrados[2] = { NULL }; nodo_tmp.indice = ind_nodo_origen; caca_log_debug("buscando nodo origen en grafo principal %ld", ind_nodo_origen); tipo_resultado = busqueda_binaria(gctx->inicio, &nodo_tmp, GRAFO_PRINCIPAL, (void *) nodos_encontrados); if (tipo_resultado != GRAFO_NODO_ENCONTRADO) { perror("El nodo origen no fue en contrado n l grafo"); exit(EXIT_FAILURE); } nodo_tmp.indice = ind_nodo_destino; caca_log_debug("buscando nodo destino %ld en grafo de %ld", ind_nodo_destino, ind_nodo_origen); tipo_resultado = busqueda_binaria((*nodos_encontrados)->siguiente_indice, &nodo_tmp, GRAFO_INDICE, (void *) nodos_encontrados); caca_log_debug("resultado de la busqueda de nodo destino %d", tipo_resultado); if (tipo_resultado != GRAFO_NODO_ENCONTRADO) { perror("El nodo destino no fue encontrado aunke el oringen si"); exit(EXIT_FAILURE); } dist_origen_dest = (*nodos_encontrados)->distancia; distancias_minimas = cpctx->referencias_directas_por_indice; distancia_min_origen = *(distancias_minimas + ind_nodo_origen); distancia_min_destino = *(distancias_minimas + ind_nodo_destino); caca_log_debug("distancia de %ld a %ld: %ld", distancia_min_origen->indice, distancia_min_destino->indice, dist_origen_dest); if (distancia_min_destino->valor > distancia_min_origen->valor + dist_origen_dest) { cola_prioridad_modificar_valor_nodo(cpctx, ind_nodo_destino, distancia_min_origen->valor + dist_origen_dest); if (antecesores) { *(antecesores + ind_nodo_destino) = ind_nodo_origen; } } } void dijkstra_main(void *matrix_distancias, int num_filas, tipo_dato ind_nodo_origen, tipo_dato ind_nodo_destino, grafo_contexto *gctx, tipo_dato *distancias_minimas, tipo_dato *antecesores) { int i; int contador = 0; int num_nodos = 0; tipo_dato indice_origen_actual = 0; tipo_dato indice_destino_actual = 0; tipo_dato max_indice = 0; grafo_contexto gctx_mem; grafo_contexto *gctx_int; cola_prioridad_contexto cpctx; nodo *nodo_origen_actual = NULL; nodo *nodo_destino_actual = NULL; nodo_cola_prioridad *nodo_mas_cercas = NULL; bool nodos_distancias_minimas_calculadas[MAX_NODOS] = { falso }; char buffer[MAX_TAM_CADENA] = { '\0' }; nodo_cola_prioridad distancias_minimas_nodos[MAX_NODOS]; caca_log_debug("INitiado dikstra con nodo origen %ld", ind_nodo_origen); caca_inutiliza_nodo_cola_prioridad(distancias_minimas_nodos, MAX_NODOS); if (gctx) { gctx_int = gctx; } else { gctx_int = &gctx_mem; init_grafo(matrix_distancias, num_filas, gctx_int, falso, verdadero); } caca_log_debug("INitiado grafo"); imprimir_lista_adjacencia(gctx_int->inicio); nodo_origen_actual = gctx_int->inicio; while (nodo_origen_actual) { caca_log_debug("initializando nodo de cola d prioridad de %s", grafo_nodo_a_cadena(nodo_origen_actual, buffer, NULL)); if (nodo_origen_actual->indice == ind_nodo_origen) { caca_log_debug("Initializado nodo origen %ld", ind_nodo_origen); (distancias_minimas_nodos + nodo_origen_actual->indice)->valor = 0; } else { caca_log_debug("Initializado nodo no origen %ld", nodo_origen_actual->indice); (distancias_minimas_nodos + nodo_origen_actual->indice)->valor = MAX_VALOR; } if (nodo_origen_actual->indice > max_indice) { max_indice = nodo_origen_actual->indice; if (max_indice > MAX_NODOS) { perror( "El indice maximo supera el maximo de nodos permitidos, a la mierda todo"); abort(); } } (distancias_minimas_nodos + nodo_origen_actual->indice)->indice = nodo_origen_actual->indice; GRAFO_AVANZAR_NODO(nodo_origen_actual, GRAFO_PRINCIPAL, falso); contador++; } num_nodos = contador; caca_log_debug("initializando cola de prioridad con indice maximo %ld", max_indice); cola_prioridad_init(&cpctx, distancias_minimas_nodos, NULL, NULL, max_indice + 1, NULL, NULL); caca_log_debug("a punto de relaxar todos los nodos"); contador = 0; while (!cola_prioridad_es_vacia(&cpctx)) { nodo_mas_cercas = cola_prioridad_pop(&cpctx); nodos_distancias_minimas_calculadas[nodo_mas_cercas->indice] = verdadero; caca_log_debug("revisando vecinos de %s", arbol_binario_nodo_a_cadena(nodo_mas_cercas, buffer, NULL)); indice_origen_actual = nodo_mas_cercas->indice; nodo_origen_actual = grafo_get_nodo_origen_por_indice(gctx_int, indice_origen_actual); caca_log_debug("masajeando nodos de %s", grafo_nodo_a_cadena(nodo_origen_actual, buffer, NULL)); nodo_destino_actual = nodo_origen_actual; while ((nodo_destino_actual = nodo_destino_actual->siguiente_distancia)) { indice_destino_actual = nodo_destino_actual->indice; if (!(*(nodos_distancias_minimas_calculadas + indice_destino_actual))) { dijkstra_relaxar_nodo(gctx_int, &cpctx, indice_origen_actual, indice_destino_actual, antecesores); caca_log_debug("Relaxado nodo %s,distancia minima actual %ld", grafo_nodo_a_cadena(nodo_destino_actual, buffer, NULL), (*(cpctx.referencias_directas_por_indice + indice_destino_actual))->valor); } } /* if (contador > 40) { exit(EXIT_FAILURE); } */ contador++; } *(antecesores + ind_nodo_origen) = 0; for (i = 0; i < max_indice + 1; i++) { caca_log_debug("llenando distancia minima de %d", i); *(distancias_minimas + i) = i == ind_nodo_origen ? 0 : caca_apuntador_valido( (*(cpctx.referencias_directas_por_indice + i))) ? (*(cpctx.referencias_directas_por_indice + i))->valor : COLA_PRIORIDAD_VALOR_INVALIDO; } } void cola_prioridad_init(cola_prioridad_contexto *ctx, nodo_cola_prioridad *nodos, tipo_dato *valores, tipo_dato *indices, int num_nodos, arbol_binario_contexto *actx, nodo_arbol_binario **referencias_directas) { int i; tipo_dato indices_int[MAX_NODOS] = { ARBOL_AVL_INDICE_INVALIDO }; tipo_dato datos[MAX_NODOS] = { ARBOL_AVL_INDICE_INVALIDO }; memset(ctx, 0, sizeof(cola_prioridad_contexto)); memset(ctx->referencias_directas_por_indice_mem, 0, sizeof(ctx->referencias_directas_por_indice_mem)); memset(indices_int, COLA_PRIORIDAD_VALOR_INVALIDO, sizeof(indices_int)); memset(datos, COLA_PRIORIDAD_VALOR_INVALIDO, sizeof(datos)); if (actx) { if (!referencias_directas) { perror("se paso un contexto de arbol sin referencias directas"); exit(1); } ctx->actx = actx; ctx->referencias_directas_por_indice = referencias_directas; } else { for (i = 0; i < num_nodos; i++) { if (nodos) { if ((nodos + i)->indice == COLA_PRIORIDAD_VALOR_INVALIDO) { continue; } *(indices_int + i) = (nodos + i)->indice; *(datos + i) = (nodos + i)->valor; } else { if (!valores) { perror("no se proporcionaron nodos ni valores"); exit(1); } if (indices) { *(indices_int + i) = *(indices + i); } else { *(indices_int + i) = i + 1; } *(datos + i) = *(valores + i); } caca_log_debug("en indice %ld, valor %ld", *(indices_int + i), *(datos + i)); } ctx->actx = &ctx->actx_mem; ctx->referencias_directas_por_indice = ctx->referencias_directas_por_indice_mem; arbol_avl_init(ctx->actx, indices_int, datos, num_nodos, ctx->referencias_directas_por_indice); } } nodo_cola_prioridad *cola_prioridad_pop(cola_prioridad_contexto *ctx) { nodo_arbol_binario *nodo_actual = NULL; nodo_arbol_binario *nodo_anterior = NULL; caca_log_debug("popeando la cola de prioridad"); nodo_actual = ctx->actx->raiz; while (nodo_actual) { nodo_anterior = nodo_actual; nodo_actual = nodo_actual->hijo_izq; } arbol_avl_borrar_referencia_directa(&ctx->actx->raiz, nodo_anterior); return nodo_anterior; } void cola_prioridad_get_valores(cola_prioridad_contexto *ctx, tipo_dato *valores, int *num_valores) { arbol_binario_colectar_datos_recorrido_inoder(ctx->actx->raiz, valores, num_valores); } bool cola_prioridad_es_vacia(cola_prioridad_contexto *ctx) { return !ctx->actx->raiz; } nodo *grafo_get_nodo_origen_por_indice(grafo_contexto *ctx, tipo_dato indice) { GRAFO_TIPO_RESULTADO_BUSQUEDA tipo_resultado; nodo nodo_tmp; nodo *nodo_encontrado = NULL; nodo *nodos_encontrados[2] = { NULL }; nodo_tmp.indice = indice; tipo_resultado = busqueda_binaria(ctx->inicio, &nodo_tmp, GRAFO_PRINCIPAL, (void *) nodos_encontrados); if (tipo_resultado == GRAFO_NODO_ENCONTRADO) { nodo_encontrado = *nodos_encontrados; } return nodo_encontrado; } nodo *grafo_get_nodo_destino_por_indice(grafo_contexto *ctx, nodo *nodo_origen, tipo_dato indice) { GRAFO_TIPO_RESULTADO_BUSQUEDA tipo_resultado; nodo nodo_tmp; nodo *nodo_encontrado = NULL; nodo *nodos_encontrados[2] = { NULL }; nodo_tmp.indice = indice; tipo_resultado = busqueda_binaria(nodo_origen, &nodo_tmp, GRAFO_INDICE, (void *) nodos_encontrados); if (tipo_resultado == GRAFO_NODO_ENCONTRADO) { nodo_encontrado = *nodos_encontrados; } return nodo_encontrado; } tipo_dato grafo_get_distancia_entre_nodos_por_indice(grafo_contexto *ctx, tipo_dato indice_origen, tipo_dato indice_destino) { tipo_dato distancia = 0; nodo *nodo_origen = NULL; nodo *nodo_destino = NULL; nodo_origen = grafo_get_nodo_origen_por_indice(ctx, indice_origen); nodo_destino = grafo_get_nodo_destino_por_indice(ctx, nodo_origen, indice_destino); distancia = nodo_destino->distancia; return distancia; } char *caca_arreglo_a_cadena(tipo_dato *arreglo, int tam_arreglo, char *buffer) { char *ap_buffer = NULL; int characteres_escritos = 0; int i; ap_buffer = buffer; for (i = 0; i < tam_arreglo; i++) { characteres_escritos += sprintf(ap_buffer + characteres_escritos, "%ld", *(arreglo + i)); if (i < tam_arreglo - 1) { *(ap_buffer + characteres_escritos++) = ','; } } return ap_buffer; } /* XXX: http://stackoverflow.com/questions/9596945/how-to-get-appropriate-timestamp-in-c-for-logs */ /* XXX: http://stackoverflow.com/questions/3756323/getting-the-current-time-in-milliseconds */ /* XXX: http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x */ void timestamp_caca(char *stime) { time_t ltime; struct tm result; long ms; struct timespec spec; char parte_milisecundos[50]; ltime = time(NULL); localtime_r(&ltime, &result); asctime_r(&result, stime); *(stime + strlen(stime) - 1) = ' '; current_utc_time(&spec); ms = round(spec.tv_nsec / 1.0e3); /* Convert nanoseconds to milliseconds */ sprintf(parte_milisecundos, "%ld", ms); strcat(stime, parte_milisecundos); } void current_utc_time(struct timespec *ts) { #ifdef __MACH__ /* OS X does not have clock_gettime, use clock_get_time */ clock_serv_t cclock; mach_timespec_t mts; host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); clock_get_time(cclock, &mts); mach_port_deallocate(mach_task_self(), cclock); ts->tv_sec = mts.tv_sec; ts->tv_nsec = mts.tv_nsec; #else clock_gettime(CLOCK_REALTIME, ts); #endif } void grafo_copia_profunda(const grafo_contexto *ctx_origen, grafo_contexto *ctx_destino, tipo_dato *indices_a_ignorar, int tam_indices_a_ignorar) { GRAFO_CRITERIOS_ORDENACION i; nodo *nodo_origen_principal_actual = NULL; nodo *nodo_origen_ordenado_actual = NULL; nodo *nodo_destino_principal_actual = NULL; nodo *nodo_destino_principal_previo = NULL; nodo *nodo_destino_ordenado_actual = NULL; nodo *nodo_destino_ordenado_previo = NULL; nodo_origen_principal_actual = ctx_origen->inicio; while (nodo_origen_principal_actual) { caca_log_debug("lopp de principales"); caca_log_debug("procesando %ld", nodo_origen_principal_actual->indice); if (indices_a_ignorar && caca_arreglo_contiene(indices_a_ignorar, tam_indices_a_ignorar, nodo_origen_principal_actual->indice)) { caca_log_debug("ignorando algo en principales"); caca_log_debug("ignorando prinipal %ld x esta n lista de ignorar", nodo_origen_principal_actual->indice); nodo_origen_principal_actual = nodo_origen_principal_actual->siguiente; continue; } nodo_destino_principal_actual = grafo_nodo_alloc(ctx_destino, 1); memset(nodo_destino_principal_actual, 0, sizeof(nodo)); memset(nodo_destino_principal_actual, sizeof(nodo), 0); grafo_copia_nodo(nodo_origen_principal_actual, nodo_destino_principal_actual); if (nodo_destino_principal_previo) { nodo_destino_principal_previo->siguiente = nodo_destino_principal_actual; nodo_destino_principal_actual->anterior = nodo_destino_principal_previo; } else { ctx_destino->inicio = nodo_destino_principal_actual; } nodo_destino_principal_previo = nodo_destino_principal_actual; caca_log_debug("copiado nodo principal %ld %ld", nodo_destino_principal_actual->indice, nodo_destino_principal_actual->distancia); for (i = GRAFO_INDICE; i < GRAFO_PRINCIPAL; i++) { caca_log_debug("copiando nodos ordenados por %s", GRAFO_NOMBRES_CRITERIOS_ORDENACION[i]); nodo_destino_ordenado_previo = NULL; nodo_origen_ordenado_actual = nodo_origen_principal_actual; GRAFO_AVANZAR_NODO(nodo_origen_ordenado_actual, i, verdadero); while (nodo_origen_ordenado_actual) { caca_log_debug("lopp de adjacentes"); caca_log_debug("procesando %ld", nodo_origen_ordenado_actual->indice); if (indices_a_ignorar && caca_arreglo_contiene(indices_a_ignorar, tam_indices_a_ignorar, nodo_origen_ordenado_actual->indice)) { caca_log_debug( "ignorando adjacente %ld x esta n lista de ignorar", nodo_origen_ordenado_actual->indice); GRAFO_AVANZAR_NODO(nodo_origen_ordenado_actual, i, verdadero); continue; } nodo_destino_ordenado_actual = grafo_nodo_alloc(ctx_destino, 1); memset(nodo_destino_ordenado_actual, 0, sizeof(nodo)); memset(nodo_destino_ordenado_actual, sizeof(nodo), 0); grafo_copia_nodo(nodo_origen_ordenado_actual, nodo_destino_ordenado_actual); if (nodo_destino_ordenado_previo) { GRAFO_ASIGNAR_ANTERIOR(nodo_destino_ordenado_previo, nodo_destino_ordenado_actual, i); GRAFO_ASIGNAR_SIGUIENTE(nodo_destino_ordenado_actual, nodo_destino_ordenado_previo, i); } else { GRAFO_ASIGNAR_SIGUIENTE(nodo_destino_ordenado_actual, nodo_destino_principal_actual, i); GRAFO_ASIGNAR_ANTERIOR(nodo_destino_principal_actual, nodo_destino_ordenado_actual, i); caca_log_debug("asignando 1ero de lista ordenada"); } caca_log_debug("copiado nodo adjacente %ld %ld", nodo_destino_ordenado_actual->indice, nodo_destino_ordenado_actual->distancia); caca_log_debug("de original %ld %ld", nodo_origen_ordenado_actual->indice, nodo_origen_ordenado_actual->distancia); GRAFO_AVANZAR_NODO(nodo_origen_ordenado_actual, i, verdadero); nodo_destino_ordenado_previo = nodo_destino_ordenado_actual; } } nodo_origen_principal_actual = nodo_origen_principal_actual->siguiente; } } #define GRAFO_COPIA_PROPIEDAD(propiedad) nodo_destino->propiedad = nodo_origen->propiedad static void grafo_copia_nodo(const nodo *nodo_origen, nodo *nodo_destino) { GRAFO_COPIA_PROPIEDAD(distancia); GRAFO_COPIA_PROPIEDAD(indice); GRAFO_COPIA_PROPIEDAD(num_nodos_asociados); GRAFO_COPIA_PROPIEDAD(num_nodos_asociados_distancia); GRAFO_COPIA_PROPIEDAD(num_nodos_asociados_indice); GRAFO_COPIA_PROPIEDAD(num_nodos_asociados_valor); GRAFO_COPIA_PROPIEDAD(valor); } static bool caca_arreglo_contiene(tipo_dato *arreglo, int tam_arreglo, tipo_dato valor_buscado) { int i; for (i = 0; i < tam_arreglo; i++) { caca_log_debug("estoy en %d", i); if (*(arreglo + i) == valor_buscado) { return verdadero; } } return falso; } #define GRAFO_GET_APUNTADOR_POSICION_MATRIX(apuntador_destino,posicion_filas,posicion_columnas) \ if (es_array) { \ apuntador_destino= (matrix_array + posicion_filas * num_columnas + posicion_columnas); \ } else { \ apuntador_destino= (*(matrix_pointer + posicion_filas) + posicion_columnas); \ } void grafo_get_representacion_en_matriz_ordenada(grafo_contexto *ctx, void *matrix, int num_columnas) { bool es_array = falso; int contador_filas = 0; int contador_columnas = 0; void **apuntador_matrix = NULL; tipo_dato *matrix_array = NULL; tipo_dato **matrix_pointer = NULL; tipo_dato *apuntador_a_posicion_en_matrix = NULL; nodo *nodo_actual = NULL; nodo *nodo_adjacente_actual = NULL; nodo_actual = ctx->inicio; apuntador_matrix = matrix; matrix_array = (tipo_dato *) apuntador_matrix; matrix_pointer = (tipo_dato **) apuntador_matrix; /* es_array = !from_stack(matrix); */ es_array = verdadero; caca_log_debug("Transformando listas en matrix:"); while (nodo_actual) { nodo_adjacente_actual = nodo_actual; GRAFO_AVANZAR_NODO(nodo_adjacente_actual, GRAFO_INDICE, verdadero); contador_columnas = 0; GRAFO_GET_APUNTADOR_POSICION_MATRIX(apuntador_a_posicion_en_matrix, contador_filas, contador_columnas); caca_log_debug( "el apuntador destino del nodo principal %p en %d %d, cuyo valor es %ld", apuntador_a_posicion_en_matrix, contador_filas, contador_columnas, nodo_actual->indice); *apuntador_a_posicion_en_matrix = nodo_actual->indice; contador_columnas++; while (nodo_adjacente_actual) { GRAFO_GET_APUNTADOR_POSICION_MATRIX(apuntador_a_posicion_en_matrix, contador_filas, contador_columnas); caca_log_debug("en adjacente indice %d %d", contador_filas, contador_columnas); *apuntador_a_posicion_en_matrix = nodo_adjacente_actual->indice; GRAFO_AVANZAR_NODO(nodo_adjacente_actual, GRAFO_INDICE, verdadero); contador_columnas++; } contador_filas++; contador_columnas = 0; GRAFO_GET_APUNTADOR_POSICION_MATRIX(apuntador_a_posicion_en_matrix, contador_filas, contador_columnas); *apuntador_a_posicion_en_matrix = nodo_actual->indice; contador_columnas++; nodo_adjacente_actual = nodo_actual; GRAFO_AVANZAR_NODO(nodo_adjacente_actual, GRAFO_DISTANCIA, verdadero); while (nodo_adjacente_actual) { GRAFO_GET_APUNTADOR_POSICION_MATRIX(apuntador_a_posicion_en_matrix, contador_filas, contador_columnas); caca_log_debug("en adjacente distancia %d %d", contador_filas, contador_columnas); *apuntador_a_posicion_en_matrix = nodo_adjacente_actual->indice; GRAFO_AVANZAR_NODO(nodo_adjacente_actual, GRAFO_DISTANCIA, verdadero); contador_columnas++; } nodo_actual = nodo_actual->siguiente; contador_filas++; } caca_log_debug("termino representacion en matrix"); } static void caca_inutiliza_nodo_cola_prioridad(nodo_cola_prioridad *nodos, int num_nodos) { int i; for (i = 0; i < num_nodos; i++) { COLA_PRIORIDAD_ASIGNA_INDICE((nodos + i), COLA_PRIORIDAD_VALOR_INVALIDO); COLA_PRIORIDAD_ASIGNA_VALOR((nodos + i), COLA_PRIORIDAD_VALOR_INVALIDO); } } char *caca_arreglo_a_cadena_float(float *arreglo, int tam_arreglo, char *buffer) { char *ap_buffer = NULL; int characteres_escritos = 0; int i; ap_buffer = buffer; for (i = 0; i < tam_arreglo; i++) { characteres_escritos += sprintf(ap_buffer + characteres_escritos, "%f", *(arreglo + i)); if (i < tam_arreglo - 1) { *(ap_buffer + characteres_escritos++) = ','; } } return ap_buffer; } void caca_realinea_array(tipo_dato *arreglo, int num_filas, int alineacion_actual, int alineacion_nueva) { int i, j; for (i = 0; i < num_filas; i++) { for (j = 0; j < alineacion_nueva; j++) { *(arreglo + i * alineacion_nueva + j) = *(arreglo + i * alineacion_actual + j); } } }
0da4979dad9e1da7cb51c47b7526b83f1149e26d
701e220bb13e5efdc0de945a8d179d53f81d94bb
/42/ft_select/tcaron/libft/ft_putnbr.c
f380142296173a4618c942c9b1cddc1ba719827a
[]
no_license
Elojah/Meuh2.0
486273ac9d5192c6f945f5ed9a56b3582f2aafb0
1706b6cd96deb56af8ab5b2164c05584435c7e35
refs/heads/master
2021-01-11T18:20:18.614432
2017-05-19T14:35:10
2017-05-19T14:35:10
28,937,663
0
0
null
null
null
null
UTF-8
C
false
false
1,404
c
ft_putnbr.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putnbr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tcaron <tcaron@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2013/11/21 10:20:46 by tcaron #+# #+# */ /* Updated: 2013/11/21 10:20:47 by tcaron ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" static int ft_pow(int nb, int exponent); void ft_putnbr(int n) { int save; size_t len; save = n; len = 0; if (!n) ft_putchar('0'); if (n < 0) { ft_putchar('-'); n = -n; } while (save) { save /= 10; len++; } while (len) { ft_putchar(n / ft_pow(10, (int)len - 1) + '0'); n -= n / ft_pow(10, (int)len - 1) * ft_pow(10, (int)len - 1); len--; } } static int ft_pow(int nb, int exponent) { if (!exponent) return (1); return (nb * ft_pow(nb, exponent - 1)); }
9944e8b16f431d40d07709d89c9614c90944cc0b
a2ea36292cbe10cf11e9d4d400ef88d251dd53da
/HMI_Dislpay.c
7804706bbb274b0672537fb4ccc875f4a58c9f1f
[]
no_license
DesignMyself/carcontrol1
d6a970e9e8c812abe541a2f592c3ad91fd5bbc02
8e1e1b3d53bbd285f4cd4edd365432dde916658e
refs/heads/master
2020-04-21T23:49:58.882987
2019-02-17T14:59:00
2019-02-17T14:59:00
169,958,994
0
0
null
null
null
null
GB18030
C
false
false
4,954
c
HMI_Dislpay.c
#include "HDMI.H" #include "app_uSart.h" #include "math.h" /******串口屏结束字符********/ void HMI_End(uint8_t uart_value) { uart_putchar_f(uart_value,0xff); uart_putchar_f(uart_value,0xff); uart_putchar_f(uart_value,0xff); } /********************选择串口发送单个字符****************/ void uart_putchar_f(uint8_t uart_value,uint8_t value) { if(uart_value==3) { uart3_putchar(value); } if(uart_value==1) { uart1_putchar(value); } } /********************大彩屏的接收开始指令****************/ void BEGIN_CMD(uint8_t uart_value) { if(uart_value==3) { uart3_putchar(0XEE); } else if(uart_value==1) { uart1_putchar(0XEE); } } /********************选择串口发送单个字符****************/ void TX_8(uint8_t uart_value,uint8_t P1) { if(uart_value==3) { uart3_putchar((P1)&0xFF); } else if(uart_value==1) { uart1_putchar((P1)&0xFF); } } /*************选择串口发送字符串**********/ void send_string(uint8_t uart_value,char *str2) { if(uart_value==3) { rt_kprintf(str2); } if(uart_value==1) { uart1_putstring(str2); } } /********************选择串口发送2个字节****************/ void TX_16(uint8_t uart_value,uint16_t P1) { TX_8(uart_value,(P1)>>8); TX_8(uart_value,P1); } void TX_32(uint8_t uart_value,uint32_t P1) { TX_16(uart_value,(P1)>>16); TX_16(uart_value,(P1)&0xFFFF); } /********正数精度为0.01*************/ void HDMI0_2(uint8_t uart_value,char *str1,float num) { num=(uint32_t)num; send_string(uart_value,str1); //uart_putchar_f(uart_value,34);//双引号输入ASII码,括号内为十进制 Value_Asii(uart_value,num); //uart_putchar_f(uart_value,34);//双引号输入ASII码 HMI_End(uart_value); } void HDMI_val(uint8_t uart_value,char *str1,uint8_t num) { send_string(uart_value,str1); uart_putchar_f(uart_value,num); HMI_End(uart_value); } void END_CMD(uint8_t uart_value) { TX_8(uart_value,0XFF); TX_8(uart_value,0XFC); TX_8(uart_value,0XFF); TX_8(uart_value,0XFF); } /*****************把数值转为ASII****/ void Value_Asii(uint8_t uart_value,float value) { uint8_t zero_sign=0; uint8_t ch1[12]; uint8_t i=0; int32_t num; uint16_t num1; num=(int32_t)fabs(value); num1=(value-num)*100; ch1[0]='-'; ch1[1]=num/1000000+48; ch1[2]=num%1000000/100000+48; ch1[3]=num%1000000%100000/10000+48; ch1[4]=num%1000000%100000%10000/1000+48; ch1[5]=num%1000000%100000%10000%1000/100+48; ch1[6]=num%1000000%100000%10000%1000%100/10+48; ch1[7]=num%1000000%100000%10000%1000%100%10+48; ch1[8]=46; ch1[9]=num1/10+48; ch1[10]=num1%10+48; if(uart_value==3) { if(value<0) { uart3_putchar(ch1[0]); } for(i=1;i<10;i++) { if(ch1[i]!=48) { zero_sign=1; } if(zero_sign==1) { uart3_putchar(ch1[i]); } } } if(uart_value==1) { if(value<0) { uart1_putchar(ch1[0]); } for(i=1;i<10;i++) { if(ch1[i]!=48) { zero_sign=1; } if(zero_sign==1) { uart1_putchar(ch1[i]); } } } if(uart_value==2) { if(value<0) { uart2_putchar(ch1[0]); } for(i=1;i<10;i++) { if(ch1[i]!=48) { zero_sign=1; } if(zero_sign==1) { uart2_putchar(ch1[i]); } } } } /***************大彩显示信息************/ void SetProgressValue(rt_uint16_t screen_id,rt_uint16_t control_id,char *str,uint8_t uart_value) { BEGIN_CMD(uart_value); TX_8(uart_value,0xB1); TX_8(uart_value,0x10); TX_16(uart_value,screen_id); TX_16(uart_value,control_id); send_string( uart_value,str); END_CMD(uart_value); } /***************大彩显示句子和数值************/ void SetProgress_mess_value(rt_uint16_t screen_id,rt_uint16_t control_id,char *str1,float value,uint8_t uart_value) { // char * val; // *val=(char)value; BEGIN_CMD(uart_value); TX_8(uart_value,0xB1); TX_8(uart_value,0x10); TX_16(uart_value,screen_id); TX_16(uart_value,control_id); send_string( uart_value,str1); Value_Asii(uart_value,value); //rt_kprintf(val); END_CMD(uart_value); } /*************屏幕中显示图标*******/ void Send_Icon(rt_uint16_t screen_id,rt_uint16_t control_id,rt_uint8_t zhen_id,uint8_t uart_value) { BEGIN_CMD(uart_value);//EE TX_8(uart_value,0xB1); TX_8(uart_value,0x23); TX_16(uart_value,screen_id); TX_16(uart_value,control_id); TX_8(uart_value,zhen_id); END_CMD(uart_value); } /*************屏幕中显示图标*******/ void Send_Angle(rt_uint16_t screen_id,rt_uint16_t control_id,uint32_t value,uint8_t uart_value) { BEGIN_CMD(uart_value);//EE TX_8(uart_value,0xB1); TX_8(uart_value,0x10); TX_16(uart_value,screen_id); TX_16(uart_value,control_id); TX_32(uart_value,value); END_CMD(uart_value); }
6c70e47c35e43d5f4c555bb595cf76ffc6726d6c
89afd8f4d2c8512ff44f17f1fd3ebec3889ba2f0
/410/pebp3-master 2/kern/vm_manager/frame_alloc.c
590bf05d56ee604fb973cc6fac59ff51cf39d925
[]
no_license
subnr01/Algorithms
409ff153d638fdc0aca0867d38b4b86a4e4327d4
1571b55ea58bda1e474cda72504e92bba83e2cd2
refs/heads/master
2021-03-30T18:01:38.427382
2017-02-20T12:25:01
2017-02-20T12:25:01
24,578,737
0
0
null
null
null
null
UTF-8
C
false
false
5,260
c
frame_alloc.c
/** @file frame_alloc.c * @brief This is an extended frame allocator module for ZFOD and * reserved allocation. * * """ NOTE * In the new architecture, we do reservation first and allocation * second. This makes the entire memory code cleaner. When doing * allocation, one has already reserved as many frames as he needs. * So during allocation we don't need to decrement the frame count. * We only do it in try_reserve function. * * The crux of the idea is that reserving a frame is the same as * decrementing the free frame count but not actually changing * the free frame list. Thus, reservation allows us remove a frame * from the list at a later time. * """ * * """ Frame allocation operation details * The free frames are managed by a linked list structure. And There's * a special address mapped to the head of the list. * * The module provides two main functions: allocation and recycle * frames. * * In allocation, we first get the physical address of that special * page, and save it as return value. Then, we map the special page to * the physical address of next free frame in the list. * * Similarly, the recycle process mainly consists of three steps: * 1. get the physical address of special page. * 2. map the special page to the recycled free frames. * 3. set a field in current page, the new recycled free frame to point * back to the previous physical address. * * """ Concurrency and solution * The frame allocator is shared by all processes and all threads. We * use a kernel mutex to protect it. Only one thread (thus one process) * could get access to the frame allocator at one time. * * @author Hongchao Deng (hongchad) * @author Alan Keith (arkeith) * @bugs No known bugs */ #include <pmm.h> #include "_pmm.h" #include <klock.h> #include "page_allocator.h" #include "_page_allocator.h" #include <page.h> #include <vmm.h> #include <stdint.h> #include <assert.h> #define KERNLOG_L5_ON #include <kernlog.h> /** @brief reserve one frame and return zfod frame * * This function isn't useful at all. I changed my architecture to use * the model of reservation first and allocation second. And this file * is still kept to remain compatible with old page allocator modules. * * @return frame physical address on success. * 0 on failure. */ uintptr_t zfod_alloc_frame() { kmutex_lock(&frame_mutex);{ if( ! freeframe_count ){ kmutex_unlock(&frame_mutex); return PMM_NULL; } // reserve a frame freeframe_count --; } kmutex_unlock(&frame_mutex); // returning the zfod frame return zfodframe; } /** @brief allocate frame for zfod page fault handler * @return Physical address of free frame */ uintptr_t zfodfault_allocframe() { uintptr_t freeframe_paddr; kmutex_lock(&frame_mutex);{ //get_physical_addr will not fail here, alloc_freeframe in kernel, //so page table is always present freeframe_paddr = get_physical_addr(alloc_freeframe); assert(freeframe_paddr != 0); assert( GET_LIST_PREV(alloc_freeframe) % PAGE_SIZE == 0); // map the freeframe head to the next one in list. assert( VMM_SUCCESS == mapper(alloc_freeframe, GET_LIST_PREV(alloc_freeframe), VMM_DEFAULT_FLAG) ); } kmutex_unlock(&frame_mutex); return freeframe_paddr; } /** @brief recycle a free frame "logically". * * @return Void. */ void zfod_free_frame() { kmutex_lock(& frame_mutex); { freeframe_count ++; } kmutex_unlock(& frame_mutex); } /** @brief recycle a free frame * * @param paddr The physical address of free frame * @return Void. */ void exec_freeandreserve(uintptr_t paddr) { // just don't increment the freeframe_count uintptr_t prev_addr; assert(paddr % PAGE_SIZE == 0); assert(paddr != 0); if(paddr == zfodframe) return; kmutex_lock(&frame_mutex);{ //get_physical_addr will not fail here, alloc_freeframe in kernel, //so page table is always present prev_addr = get_physical_addr(alloc_freeframe); assert(prev_addr != 0); assert( VMM_SUCCESS == mapper(alloc_freeframe, paddr, VMM_DEFAULT_FLAG) ); // set the list prev field to previous head. GET_LIST_PREV(alloc_freeframe) = prev_addr; } kmutex_unlock(&frame_mutex); } /** @brief recycle a free frame * * @param paddr The physical address of free frame * @return physical frame address */ uintptr_t exec_alloc_reserved_frame() { // just don't decrement the freeframe_count uintptr_t freeframe_paddr; kmutex_lock(&frame_mutex);{ //get_physical_addr will not fail here, alloc_freeframe in kernel, //so page table is always present freeframe_paddr = get_physical_addr(alloc_freeframe); assert(freeframe_paddr != 0); assert( GET_LIST_PREV(alloc_freeframe) % PAGE_SIZE == 0); // map the freeframe head to the next one in list. assert( VMM_SUCCESS == mapper(alloc_freeframe, GET_LIST_PREV(alloc_freeframe), VMM_DEFAULT_FLAG) ); } kmutex_unlock(&frame_mutex); return freeframe_paddr; }
7a86bb24680f744dbe91b978a63ee3dbc7316f18
67e62d4e5c85c2981dc42693870697841c5a73e8
/usf_obj.h
9ada81fa966d7ecd733bf3ac5138a159a5984fa0
[]
no_license
muneeb/pyusf
04feb5863bb8b957f30c2d92ff572246bb516582
a8b6c394f6ea338675eec7d9335c6f9947b765ab
refs/heads/master
2021-01-21T13:11:10.601200
2013-02-26T13:19:58
2013-02-26T13:19:58
null
0
0
null
null
null
null
UTF-8
C
false
false
269
h
usf_obj.h
#ifndef _USF_OBJ_H_ #define _USF_OBJ_H_ #include <Python.h> #include <uart/usf.h> #include "header_obj.h" typedef struct { PyObject_HEAD usf_file_t *usf_file; header_obj_t *header; } usf_obj_t; extern PyTypeObject usf_obj_type; #endif /* _USF_OBJ_H_ */
33993e14fa74f94e9cd1943285a7db84300f92a1
9ec5c73c22685cb7cb4216a7d367f5173083d56a
/sphost/include/thirdparty/oss2/linuxbase/linux/etherdevice.h
46b3d45c9dd15cb7be5dfc79fd014bd167424f0b
[]
no_license
chadmuska/test
0f06d622e22eda54a14b8275f287d728cbc53a84
68af41f3243feccda6952e85ff75f17a434963eb
refs/heads/master
2020-03-19T23:19:17.368909
2018-06-12T01:53:48
2018-06-12T01:53:48
137,002,080
1
1
null
null
null
null
UTF-8
C
false
false
1,533
h
etherdevice.h
#ifndef _LINUX_ETHERDEVICE_H #define _LINUX_ETHERDEVICE_H #include <string.h> #include <linux/if_ether.h> #include <linux/random.h> static inline bool is_multicast_ether_addr(const u8 *addr) { u16 a = *(const u16 *)addr; return 0x01 & a; } static inline bool is_zero_ether_addr(const u8 *addr) { return (*(const u16 *)(addr + 0) | *(const u16 *)(addr + 2) | *(const u16 *)(addr + 4)) == 0; } static inline void ether_addr_copy(u8 *dst, const u8 *src) { u16 *a = (u16 *)dst; const u16 *b = (const u16 *)src; a[0] = b[0]; a[1] = b[1]; a[2] = b[2]; } static inline void eth_broadcast_addr(u8 *addr) { memset(addr, 0xff, ETH_ALEN); } static inline void eth_zero_addr(u8 *addr) { memset(addr, 0x00, ETH_ALEN); } static inline void eth_random_addr(u8 *addr) { get_random_bytes(addr, ETH_ALEN); addr[0] &= 0xfe; /* clear multicast bit */ addr[0] |= 0x02; /* set local assignment bit (IEEE802) */ } static inline bool is_valid_ether_addr(const u8 *addr) { /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to * explicitly check for it here. */ return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr); } static inline bool ether_addr_equal(const u8 *addr1, const u8 *addr2) { const u16 *a = (const u16 *)addr1; const u16 *b = (const u16 *)addr2; return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) == 0; } static inline bool is_broadcast_ether_addr(const u8 *addr) { return (*(const u16 *)(addr + 0) & *(const u16 *)(addr + 2) & *(const u16 *)(addr + 4)) == 0xffff; } #endif
c6ff90b4630870f0a32fc2159884dfa3864df5af
280d5a5296a174c15653b91b42515a4401ea39b6
/c/vector.h
fbf932ab851f46369d98501da61bee721733f52a
[]
no_license
orasraf1241/World_Weather
dd068ddccf9fe8f968bf07bb442e4b57a4be525e
d9b0f8b0d43637d05f65f5dcaad38a31326a7053
refs/heads/master
2023-08-24T11:30:42.939997
2021-10-06T15:35:39
2021-10-06T15:35:39
423,880,714
0
0
null
null
null
null
UTF-8
C
false
false
1,344
h
vector.h
/******************************************************************** * File Name: vector.h * Description: * Author:Or Asraf * Reviewer: * Date:28.08.21 ********************************************************************/ #include <stdio.h> #include <stdlib.h> #ifndef __VECTOR_H_ #define __VECTOR_H_ typedef struct vector vector_t; /*Create vector object, test for successfull allocation O(1)*/ vector_t *VectorCreate(size_t capacity); /*add an element to the vector return if reallocation happenes O if not return FAIL_TO_ALLOCATE*/ int VectorAppend(vector_t *v, void *element); /* This func insert the element to vector in the index the user*/ int VectorSet(const vector_t *v, size_t index, void *element); /* Return the value of the element in the provided index*/ void *VectorGet(const vector_t *v, size_t index); /*Remove the last element in the vector*/ void VectorPop(vector_t *v); /* return vector size */ size_t VectorSize(const vector_t *v); /* return vector capacity */ size_t VectorCapacity(const vector_t *v); /*O(1)*/ void VectorDestroy(vector_t *v); #endif /*__VECTOR_H__*/