Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
So I'm looking in the tice.h file and looking at os_GetSymTablePtr() and os_NextSymEntry(). I need some help.

Purpose: I'm trying to create a loop that returns every program and appvar type variable on the calc.

Questions:
1. os_GetSymTablePtr() has a void argument and is void type. Shouldn't it return an int?
2. for os_NextSymEntry(), it has arguments of *entry, *type, *nameLength, *name, and **data. Can these be NULL? I'm assuming they do have to be declared.
3. Once I call NextSymEntry, is the format the same as thought it was assembly, in that the first two or three bytes is the size of the variable?
Assuming I documented it correctly, it would be:
Code:
void *entry = os_GetSymTablePtr();
uint24_t type;
uint24_t nameLength;
const char name[9];
void *data;
while ((entry = os_NextSymEntry(entry, &type, &nameLength, name, &data))) {
    if (type == 0x05 || type == 0x15) { // Program || AppVar
        var_t *var = data;
        uint16_t varSize = var->size;
        uint8_t *varData = var->data;
    }
}


You could also just use ti_DetectVar in fileioc.
So I'm finally back to this. I feel like I lost a lot of what I previously knew, so please go easy on me. Be that as it may, I am trying, in this code, to set up a struct, named MyShip (for my Star Trek Multiplayer), containing positional and vector data, as well an array of pointers to instances of pre-defined structures, such that the stats of the ship's individual systems are accessible by referring to MyShip.ShipSystems[n].

After editing this topic about 500 times, I managed to recall the exchange with Kerm at one point where he explained to me how to set up an array of structures and edited my post accordingly. My only question now is... will C not like having structures of differing sizes here, or is that ok?


Code:
struct MyShip = {
            float xPos;
            float yPos;
            float zPos;
            float xyVector;  // Direction to move on XY
            float zVector; // Direction to move on Z
            char installedModules = 15;
            char maxModules = 20;
            struct ShipSystems[20] = {
                {       // Hull Armor (1)
                    char moduleType = sys_HullArmor;
                    char name = "Hull Armor";
                    char health = 50;
                    char maxHealth = 50;
                    char online = 1;
                    char power = 0;
                },
                {       // Structural Integrity (2)
                    char moduleType = sys_StructuralIntegrity;
                    char name = "Structural Integrity";
                    char health = 50;
                    char maxHealth = 50;
                    char online = 1;
                    char power = 0;
                },
                {       // Warp Drive (3)
                    char moduleType = sys_WarpDrive;
                    char name = "Warp Drive";
                    char maxWarpFactor = 1;
                    char health = 50;
                    char maxHealth = 50;
                    char online = 1;
                    char power = 0;
                },
                {       // Warp Core (4)
                    char moduleType = sys_WarpCore;
                    char name = "Warp Core";
                    char powerOutput = 5;
                    char health = 50;
                    char maxHealth = 50;
                    char online = 1;
                    char power = 0;
                },
                {       // Transporters (5)
                    char moduleType = sys_Transporter;
                    char name = "Transporter";
                    char range = 100;
                    char health = 50;
                    char maxHealth = 50;
                    char power = 0;
                    char online = 1;
                },
                {       // Navigational Sensors (6)
                    char moduleType = sys_NavSensors;
                    char name = "Navigational Sensors";
                    int range = 100;
                    char health = 50;
                    char maxHealth = 50;
                    char power = 0;
                    char online = 1;
                },
                {       // Targetting Sensors (7)
                    char moduleType = sys_TargSensors;
                    char name = "Targetting Sensors";
                    char range = 50;
                    char health = 50;
                    char maxHealth = 50;
                    char power = 0;
                    char online = 1;
                },
                {       // Phasers (8)
                    char moduleType = sys_Phasers;
                    char name = "Phasers";
                    char equippedProjectile = 0;
                    char range = 50;
                    char health = 50;
                    char maxHealth = 50;
                    char power = 0;
                    char online = 1;
                },
                {       // Torpedoes (9)
                    char moduleType = sys_Torpedoes;
                    char name = "Torpedoes";
                    char equippedProjectile = 0;
                    char range = 50;
                    char health = 50;
                    char maxHealth = 50;
                    char power = 0;
                    char online = 1;
                },
                {       // Shields (10)
                    char moduleType = sys_Shields;
                    char name = "Shields";
                    char style = 0;   // 0 = normal, 1 = gridded, 2 = multiphasic, 3 = temporal
                    char healthNormal = 50;
                    char healthAft = 50;
                    char healthPort = 50;
                    char healthStarboard = 50;
                    char healthForward = 50;
                    char healthDorsal = 50;
                    char healthVentral = 50;
                    char maxHealth = 50;
                    char power = 0;
                    char online = 1;
                },
                {       // Life Support (11)
                    char moduleType = sys_LifeSupport;
                    char name = "Life Support";
                    char health = 50;
                    char maxHealth = 50;
                },
                {       // Auto Repair (12)
                    char moduleType = sys_AutoRepair;
                    char name = "Repair";
                    char repairSpeed = 1;
                },
                {       // Communication (13)
                    char moduleType = sys_Communication;
                    char name = "Communication";
                    char health = 50;
                    char maxHealth = 50;
                    char power = 100;
                    char range = 100;
                },
                {       // Main Power (14)
                    char moduleType = sys_MainPower;
                    char name = "Main Power";
                    char powerReserve = 0;
                },
                {       // Auxiliary Power (15)
                    char moduleType = sys_AuxiliaryPower;
                    char name = "Auxiliary Power";
                    char powerReserve = 0;
                }
            };
        };
Ok, so after some time on google and looking at examples, I fixed up my errors.
I then built the program and it successfully compiled.
After that, I decided to move the code that creates the initial ship structures into its own separate file.
I then built the program again to make sure I didn't break anything. I got a lot of undefined variables in the "newname.c" file for all of the associations that are in the ship.h and systems.h files, as well as some out of scope.
Responded by including the ship.h and weapons.h file within the data.h file. Now, began getting errors about types already existing.
Then tried defining the variables in the ship.h and weapons.h file as extern type. Got the first set of errors.
I'm assuming I've done something wrong with linking the files together. I've enclosed a link to my entire source, zipped, so that someone can have a look and suggest how properly link these includes. I've done everything I can think of.
https://www.mediafire.com/file/17uops1vk6fd5tj/src.zip
New question: Not particularly interested in overall correctness *within* the function right now, I'm mostly interested in the arguments the function receives, and how I handle referencing the structure within. Also I have a few... guesses based on what I've seen. Please correct me if I'm wrong.

1. If the argument to the function is a &, inside the function it should be a *.
2. If the argument to the function is a *, inside the function you should just have the variable without anything.


Code:

SetModule(&ShipSystem[number], m_System, s_LifeSupport);  // to call a function to set the module to default values

// Function to set module to its defaults
// arguments: pointer to the selected "module", one byte type, one byte subtype, one byte weapon type (optional)
Module_t* SetModule(Module_t *module, char type, char subtype, char weaptype){
    module->moduleID = type;
    module->subID = subtype;
    module->power = 0;
    module->maxhealth = 10;
    module->DataFields = {10,0,0,0,0,0};
    switch (type){
        case m_System:
            module->moduleOnline = true;
            switch(subtype){
                case sWarpDrive:
                    module->DataFields = {10,1,0,0,0,0};
                    break;
                case sTransporter:
                case sNavSensors:
                case sTargSensors:
                case sCommunication:
                    module->DataFields = {10,100,0,0,0,0};
                    break;
                case sMainPower:
                case sAuxiliaryPower:
                    module->DataFields = {0,0,0,0,0,0};
                    break;
                case sAutoRepair:
                    module->DataFields = {1,0,0,0,0,0};
            }
            break
        case m_Weapons:
        case m_Shield:
            module->weapID = weaptype;
            module->modulation = random;
            module->moduleOnline = false;
            break;
        case m_Misc:
    }
}
So, just for the sake of getting this stuff written down somewhere I can reference it, based on what I was told in SAX a while back:

A bit of googling what I'm trying to do and a few compile attempts and this at least compiled properly. I'll pop it in a debugger and see what happens:

Code:

Module_t* ShipModules[20];  // to declare the array;
ShipModules[i] = malloc(sizeof(Module_t));   // to allocate and save pointer to structure.

To Use Structure:
functionToDoStuff(ShipModules[i]));   // function call
sometype_t functionToDoStuff(Module_t *module)   // function prototype
module->structField;     // to access structure fields


Code compiles nicely, and I see the text "Created Modules" and "Deleted Modules" in coordination with the module creation and free() loops, respectively. I'd say success so far. Binary included, since certain individuals seem to think having questions means you haven't compiled. :p

https://www.mediafire.com/file/hj11h5lu03j9oh6/STARTREK.8xp
So I have a new question.
How would I handle 3d trig? For instance, let's say I want to move a certain degree along the X/Y axis, and then a degree along the Z. I seem to remember that for (X,Y), given angle V it was (speed*cos(V), speed*sin(V)) to calculate the X and Y to move per cycle. In 3-dimensional space, how would that change?

Edit: While typing this, I found the following:

Code:

x = cos(A)*cos(B)
y = sin(A)*cos(B)
z = sin(B)
where A is the X,Z angle and B is the Z angle (or whichever you choose to use as your 3rd axis)


My question is... does the axis you choose as your 3rd matter? And lastly, for the purposes of this, would you recommend I use iPart int and fPart char data types, or simply use a float for this?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 6 of 6
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement