Announcement

Collapse
No announcement yet.

beginner

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • beginner

    Trying to understand by the examples,
    Was having trouble adding scr_printf function to an existing c file.
    What do i have to include into my demo2a.c and makefile to be able to use scr_printf?
    I have this example:
    hello.c


    #include <tamtypes.h>
    #include <kernel.h>
    #include <sifrpc.h>
    #include <stdio.h>
    #include <debug.h>

    int main(int argc, char *argv[])
    {
    SifInitRpc(0);

    init_scr();
    scr_printf("Hello, world!\n");
    printf("Hello, world!\n");

    while(1) {}

    return 0;
    }

    makefile:

    EE_BIN = hello.elf
    EE_OBJS = hello.o
    EE_LIBS = -ldebug

    all: $(EE_BIN)

    clean:
    rm -f *.elf *.o *.a

    include $(PS2SDK)/samples/Makefile.pref
    include $(PS2SDK)/samples/Makefile.eeglobal

    I tryed to include all these header files in my demo2a.c and then call scr_pritnf in the main function,nogo.Any point in the right direction would be greatly appreciated.

  • #2
    What's the error you're getting?
    I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

    Comment


    • #3
      that above example worked,i was trying to use the scr_printf function in another,i see examples of all these functions seperate,was just trying to learn how to combine them,my feeble attempt looked like this:
      / File: demo2a.c
      //
      //---------------------------------------------------------------------------
      #include "g2.h"
      #include <tamtypes.h> // I ADDED THESE .H FILES FROM THE HELLO EXAMPLE
      #include <kernel.h>
      #include <sifrpc.h>
      #include <stdio.h>
      #include <debug.h>


      extern uint32 ff_w;
      extern uint32 ff_h;
      extern uint32 ff[];


      //---------------------------------------------------------------------------
      int main(int argc, char **argv)
      {
      argc=argc;
      argv=argv;

      g2_init(PAL_640_256_32);

      SifInitRpc(0); // I TRIED TO ADD THE SCR_PRINTF FUNCTION HERE

      init_scr();

      scr_printf("Hello, world!\n");
      printf("Hello, world!\n");

      // clear the screen
      g2_set_fill_color(0, 0, 0);
      g2_fill_rect(0, 0, g2_get_max_x(), g2_get_max_y());

      g2_put_image(0, 35, ff_w, ff_h, ff);

      while(1)
      {

      }

      // ok...it will never get here...
      g2_end();
      return(0);
      }

      MAKEFILE:

      #----------------------------------------------------------------------------
      # File: Makefile
      #
      #----------------------------------------------------------------------------
      CC=ee-gcc
      AS=ee-as
      LD=ee-elf-ld
      BMP2C=bmp2c
      EE_LIBS = -ldebug //ADDED THESE FROM HELLO MAKEFILE
      EE_BIN = demo2.elf
      EE_OBJS = hello.o

      OBJ_DIR = obj
      BMP_DIR = resources

      CFLAGS = -Wall -W -EL -G0 -O0 -mips3 -nostdlib -DPS2_EE

      BMP_SRC = ff.c
      C_SRC = g2.c demo2a.c $(BMP_SRC)
      S_SRC = crt0.s ps2_asm.s dma_asm.s gs_asm.s

      C_OBJ = $(addprefix $(OBJ_DIR)/, $(C_SRC:.c=.o))
      S_OBJ = $(addprefix $(OBJ_DIR)/, $(S_SRC:.s=.o))

      demo1.elf: $(C_OBJ) $(S_OBJ)
      @echo "-------------------------------------------------"
      $(CC) $(CFLAGS) -Tlinkfile -o demo2a.elf $(C_OBJ) $(S_OBJ) -Wl,-Map,demo2a.map

      $(OBJ_DIR)/%.o: %.c
      @echo "-------------------------------------------------"
      $(CC) -c $(CFLAGS) $< -o $@

      $(OBJ_DIR)/%.o: %.s
      @echo "-------------------------------------------------"
      $(CC) -xassembler-with-cpp -c $(CFLAGS) $< -o $@

      %.c: $(BMP_DIR)/%.bmp
      @echo "-------------------------------------------------"
      $(BMP2C) $< $(*F) > $@

      clean:
      rm -f $(C_OBJ) $(S_OBJ) *.map *.elf $(BMP_SRC)

      ff.c: $(BMP_DIR)/ff.bmp

      include $(PS2SDK)/samples/Makefile.pref //ADDED THIS FROM HELLO MAKEFILE
      include $(PS2SDK)/samples/Makefile.eeglobal

      I commented next to what i added
      errors were no such file for tamtype-debug,inplicit declaration of 'sifinitrpc' , and 'scr_printf' .

      Comment


      • #4
        Sorry; I haven't had a chance to take a good look. I'll try to make an example that combines both concepts a little later today, or tomorrow.
        I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

        Comment


        • #5
          ok thanks,just tryin to learn all this lol

          Comment


          • #6
            Ack, I haven't done this yet. I took a brief look at the makefile for demo2a, and I believe it's not referencing the include directories that most new makefiles should by default. I'll take a more detailed look later, if you haven't figured it out by then.
            I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

            Comment


            • #7
              Taking a more detailed look, there are some things in the makefile for demo2a that I just don't understand. I've never seen $(addprefix before (though Googling around a little shows that it's not unheard of), and there are some other things I'm not familiar with as well ($(CC) -c $(CFLAGS) $< -o $@ , for example).

              As the makefiles for these tutorials are a little complex (and somewhat dated, with some deprecated pieces here and there), I've set out to write a line-by-line explanation of the entire thing, starting with the makefile for demo2a. I've had to do some learning myself, heh. Hopefully, the result of this work is that a lot more newcomers can understand what's going on in these tutorials. Here's what I've got so far:

              Hello, this is LB, of GSHI.org. I hope this breakdown helps explain some things to beginners, who might not be accustomed to PS2 development, GCC, C, or even programming in general. You should have the demo2a (ps2tut_02a) makefile open while reading this explanation, preferably using a decent editor, such as Crimson Editor (with line numbering turned on). I'll explain each line, first including the line itself, then my explanation. I'll probably explain a few lines together, if the need arises. Don't be discouraged if some of the information here is confusing or alien to you; just grasp what you can, and you can go study what you don't in more detail later. I don't have room in this little explanation to go into each topic in great depth (though I'm not averse to doing so at a later date), so you may still have to do some footwork yourself (Google, etc) to get the answers to all of your curiosities. Anyway, on with the show


              #----------------------------------------------------------------------------
              # File: Makefile
              # Author: Tony Saveski, [email protected]
              #----------------------------------------------------------------------------


              These first few lines are commented out, by beginning the line with the character #. One can also comment by preceding your desired comment with //, or by preceding your desired comment with /*, and following it with */ (in this way, you can comment right in the middle of a line of code).



              CC=ee-gcc


              This simply states that the C compiler will be ee-gcc (GNU Compiler Collection for the Emotion Engine).



              AS=ee-as


              This states that the assembler will be the Emotion Engine assembler (for the MIPSIV r5900l processor, to be specific).



              LD=ee-elf-ld


              This means that the linker used will be the Emotion Engine ELF linker (as opposed to an IRX linker, I suppose).



              BMP2C=bmp2c


              This simply means that if $(BMP2C) is referenced, "bmp2c" will actually be referenced.



              OBJ_DIR = obj


              This states that if $(OBJ_DIR) is referenced, "obj" will actually be referenced.



              BMP_DIR = resources


              This states that if $(BMP_DIR) is referenced, "resources" will actually be referenced.



              CFLAGS = -Wall -W -EL -G0 -O0 -mips3 -nostdlib -DPS2_EE


              CFLAGS refers to variables that can be set to specify additional switches to be passed to a compiler in the process of compilation. For a list of GCC 3.2.3 (the closest documented version to 3.2.2) MIPS-specific compiler options, take a look at http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/MIPS-Opt
              ions.html#MIPS%20Options , and for a list of all GCC Options, check out http://gcc.gnu.org/onlinedocs/gcc-3....Option%20Index

              -Wall enables all warnings, even though most of them can generally be ignored.
              -W turns on all warnings based on the C99 standard.
              -EL compiles code in Little Endian mode
              -G0 puts global and static items less than or equal to 0 bytes into the small data or bss sections instead of the normal data or bss section.
              -O0 means "Do not optimize."
              -mips3 makes GCC issue (64-bit) instructions from level 3 of the MIPS ISA (Industry Standard Architecture).
              -nostdlib means "Do not use the standard system startup files or libraries when linking. No startup files and only the libraries you specify will be passed to the linker."
              -DPS2_EE is a preprocessor option, specifying a predefined macro, which (in this case) is referenced in defines.h.



              BMP_SRC = ff.c


              This states that if $(BMP_SRC) is referenced, "ff.c" will actually be referenced.



              C_SRC = g2.c demo2a.c $(BMP_SRC)


              This states that if $(C_SRC) is referenced, "g2.c", "demo2a.c", and $(BMP_SRC) will actually be referenced.



              S_SRC = crt0.s ps2_asm.s dma_asm.s gs_asm.s


              This states that if $(S_SRC) is referenced, "crt0.s", "ps2_asm.s", "dma_asm.s", and "gs_asm.s" will actually be referenced.



              C_OBJ = $(addprefix $(OBJ_DIR)/, $(C_SRC:.c=.o))


              ???????


              TO BE CONTINUED
              I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

              Comment


              • #8
                Oh, and one of the problems must be the CFLAGS entry, "-nostdlib". However, removing that doesn't fix the problem, and in this case, I believe increases problems, as some included source has the same file name as some naturally included libraries. Bleh...I'll tinker around with it more as time allows. Feel free to dive in yourself as well, or to prod anyone else for answers.
                I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

                Comment


                • #9
                  Learning GNU make:
                  http://www.gnu.org/software/make/manual/
                  http://www.oreilly.de/catalog/make3/book/index.html

                  Comment

                  Working...
                  X