So...

Lately, doubledogdare610, me, and seanlego have started to work on the DOOM port to the CE. Now.... out of this group, guess who knows practically no C?

That's right.

Me.

So I am asking for help here, and here's my first question:

How do I make a header in C? I've seen some of the #include (or something like that), but past that, I have no idea.
That depends on the IDE you are using. Usually, if you click the file button which is normally at the top left corner of the window, and click new project, it should be in there. Look for C header file, or C++ Header file. They're basically the same except the C++ can accept C++ code. But don't try to code in C++, it won't compile for the calculator. Just input C code.
So if you are trying to program using the C SDK, you can get that set up, and then in the examples directory there is a template. Use that to get started. You may need to add the graphics, keypad, fileioc, and debug libraries. That is just adding this beneath the other includes:

Code:

#include <graphx.h>
#include <debug.h>
#include <keypadc.h>
#include <fileioc.h>


If you want some sort of list of commands, you can just open those include files (located in CEdev/Lib/ce) and there you have it Smile
Unicorn wrote:
So if you are trying to program using the C SDK, you can get that set up, and then in the examples directory there is a template. Use that to get started. You may need to add the graphics, keypad, fileioc, and debug libraries. That is just adding this beneath the other includes:

Code:

#include <graphx.h>
#include <debug.h>
#include <keypadc.h>
#include <fileioc.h>


If you want some sort of list of commands, you can just open those include files (located in CEdev/Lib/ce) and there you have it Smile

For the C SDK libraries, the code looks like this:

Code:
#include <lib\ce\graphx.h>
#include <lib\ce\fileioc.h>
#include <lib\ce\keypadc.h>


Edit:
I did not know you can just use <graphx.h>. Thanks to Unicorn, now I know.
I've programmed in C and C++, there is virtually no difference. I never used things like unions and overloaded functions. My "C++" code was %99 C. I did technically use classes, but they were global and practically could have been structs.

The only really useful thing about C++ I encountered was it has much better string libraries. Dealing with characters is the bane of C, and it's less awful and buggy in C++. Dealing with strings is the one time I long for anything other than C.. Python, QBASIC, even Perl. Literally everything is better than C when it comes to dealing with strings.

The main thing I had to watch out for in C is keeping track of pointers. I'd say 4/5 of my bugs were caused by a pointer referencing something out of scope.
Thanks, guys!

Second question:

How do controls work? For example, what code would be needed to accept input from the up key on the CE? Is it similar to the GetKey routine in Basic? Or is it something completely different?
Use os_GetCSC() or the keypadc.h header using kb_ScanGroup(kb_group_7); If you use os_GetCSC(); the key values are on tibasicdev.wikidot.com. Bottom right picture.
Thanks, seanlego!
WhyGodotWhy wrote:

The main thing I had to watch out for in C is keeping track of pointers. I'd say 4/5 of my bugs were caused by a pointer referencing something out of scope.


What's a pointer?

EDIT: I now know what a pointer is.

Next question:

How do I reference the screen in C? Like, how would I put a red pixel at 15,15?
caleb1997 wrote:
How do I reference the screen in C? Like, how would I put a red pixel at 15,15?

You can either do it in C manually, or you can use the provided libraries to perform a bunch of different graphical things. For example:


Code:
gfx_SetColor( gfx_red );
gfx_SetPixel( 15, 15 );
Thanks, Mateo!

Next question: Let's say that I want to look to the right, and on my right is a doorway.

How do I store the graphics needed to show the doorway?
caleb1997 wrote:
Thanks, Mateo!

Next question: Let's say that I want to look to the right, and on my right is a doorway.

How do I store the graphics needed to show the doorway?


You want to use a bitmap. It is simply a two-dimensional array of integers, each integer representing a pixel. However, you'll want to compress it when it's stored away in flash memory, and then decompress it to VRAM when you need it.
Ok then. I have another question.

Does the compiler included in the C SDK toolkit require installment? Or can I download it onto my flashdrive and run it off there?
You can use it on your flash drive if you configure things properly.
Thanks, Mateo.

Also..... How do I configure it properly? On the github repos for the toolchain, the instructions make no sense to me. Could you explain them a little bit more to me?
Have you checked out this tutorial I made on how to set it up? Just change the directories to suit your needs.
https://www.cemetech.net/learn/C_SDK_Tips_and_Tricks
*Bump*


Since I'm still trying to learn C, and I believe I'm not advanced enough for much (like DOOM), I want to pick this up where I left off.

Current goal:

Make a life counter for Magic the gathering. Nothing fancy, but the challenge here would be displaying multiple life counters- up to 8 (or 4).

First question:

What's the range on the screen? I think it goes from (0,0) to (180,320) or something like that?
The screen is 240 pixels high and 320 pixels long.
Ok. Thanks, Phoenix!

Next question:

I did look this up, but the answer given wasn't really explaining. However, I know they can be called from anywhere in a program.

What exactly is a global variable? And how can I declare a global variable? And does declaring it allow me to store a variable to it? Or how do I store a set number to a global variable?
All right then, now that that's been answered,my next question:
Would using a printchar command print the text (in the example below) playerOne, or would it print the value of playerOne?


Code:
#include <tice.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <graphx.h>
#include <keypadc.h>
#include <debug.h>
#include <fileioc.h>

int playerOne=8000
int playerTwo=8000
int playerThree=8000
int playerFour=8000
int playerFive=8000
int playerSix=8000
int playerSeven=8000
int playerEight=8000

void main() {
gfx_FillScreen(gfx_blue)
gfx_SetColor(gfx_green)
gfx_FillRectangle(10,10,50,100
              gfx_FillRectangle(150,10,50,100
gfx_PrintChar(playerOne                     
      // Main program code goes here
}

/* Other functions */
There are a few small things I see wrong in that code, but I do not have the experience necessary to answer the main question:

Here's the code with my corrections

Code:
#include <keypadc.h>
#include <debug.h>
#include <fileioc.h>

int playerOne=8000;
int playerTwo=8000;
int playerThree=8000;
int playerFour=8000;
int playerFive=8000;
int playerSix=8000;
int playerSeven=8000;
int playerEight=8000;

void main() {
gfx_FillScreen(gfx_blue);
gfx_SetColor(gfx_green);
gfx_FillRectangle(10,10,50,100);
              gfx_FillRectangle(150,10,50,100);
gfx_PrintChar(playerOne);                     
      // Main program code goes here
}

/* Other functions */


Some of the lines were missing semicolons and some were missing closing parentheses.
Unfortunately, this isn't BASIC and that won't make your program run faster.
All right then!

Thanks for all the help guys.

Next question:

How do I do math with variables?

EDIT:

I now know.

Code update!


Code:

#include <tice.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <graphx.h>
#include <keypadc.h>
#include <debug.h>
#include <fileioc.h>

int playerOne=8000;
int playerTwo=8000;
int playerThree=8000;
int playerFour=8000;
int playerFive=8000;
int playerSix=8000;
int playerSeven=8000;
int playerEight=8000;

void main() {
gfx_Begin();
gfx_FillScreen(gfx_blue);
gfx_SetColor(gfx_green);
gfx_FillRectangle(10,10,50,100);
gfx_FillRectangle(150,10,50,100);
   gfx_SetColor(gfx_red);
   gfx_SetTextXY(11,11);
   gfx_SetTextScale(3,3);
   gfx_PrintInt(playerOne,4);
   gfx_SetTextXY(151,11);
   gfx_PrintInt(playerTwo,4);
do {
gfx_SetColor(gfx_red);
gfx_PrintInt(playerOne);
gfx_SetColor(gfx_green);
gfx_FillRectangle(150,10,50,100);
      playerOne=playerOne-50;
   }while (playerOne>5000);
gfx_End();
}

/* Other functions */


Have I done anything wrong?
  
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 1 of 3
» All times are UTC - 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