Language…
19 users online: anonimzwx, codfish1002, Danik2343, DanMario24YT,  Deeke, Golden Yoshi,  Gonzales555, Green, Heitor Porfirio, iamtheratio, imamelia, Irondill, koffe190, LightAligns, MorrieTheMagpie, PMH,  Segment1Zone2, TheOrangeToad, xxxblackangel2208xxx - Guests: 277 - Bots: 234
Users: 64,795 (2,375 active)
Latest user: mathew

Coding with C in N64 - N64Toolchain 1.0.1

With this tutorial you will be able to access the RAM and to modify it.
All is done using C language. If you wanna learn C, you can look here.
The compilation of the C code will produce, through some programs, a binary code that will be converted then in a GameShark code.


Toolchain 1.0 by gzrt
Includes by frauber
Fixes in 1.0.1 by DamiHack



Menu

  1. Installation
    1. Install MinGW
    2. Configure MinGW

  2. Compilation
    1. Prepare your own code
    2. Compile your own code





Installation


STEP 1

Install MinGW

  1. Download the installer here
  2. Launch it
  3. Click on Next
  4. Click on Next again
  5. Click on Download latest repository catalogues
  6. Click on Next
  7. Click on I accept the agreement
  8. Click on Next
  9. (Not recommended) If you want, change the Destination Location
  10. Click on Next
  11. (Not recommended) If you want, change or don't create the Start Menu Folder
  12. Click on Next
  13. Select C Compiler
  14. If you want, select also other components
  15. Select MSYS Basic System
  16. Select MinGW Developer Toolkit
  17. Click on Next
  18. Click on Install
  19. Wait the completion of the installation
  20. Unselect Display mingw-get log
  21. Click on Finish



STEP 2

Configure MinGW

  1. Download the Toolchain here
  2. Extract it in C:\MinGW
  3. Launch MinGW Shell
  4. Wait the loading of the console
  5. Enter cd /c/MinGW/n64tree-win32/bin ("/c/" is the equivalent of "C:/", replace "/c/MinGW/" with your Destination Location if you edited it)
  6. Enter export PATH=$PATH: 'pwd'
  7. Close MinGW Shell



Compilation


STEP 1

Prepare your own code


To try we'll do an Hello World. The game we are going to edit is Super Mario 64.
  1. Create a new folder in "n64tree-win32" called hacks (or whatever you want) where you'll put your hacks
  2. Create a new folder called "HelloWorld" (or whatever you want) in the folder you've just created
  3. Here create a new text file called "hook.txt"
  4. In the file you've just created enter this GameShark code:
    Code
    812CB26C 0C10
    812CB26E 0000
    812CB278 1000
    812CB27A 0040
    
  5. Now create a new file called main.c (or whatever you want in .c)
  6. In the file jou've just created, enter:
    Code
    #include "n64.h" // Include Standard N64 Library
    #include "explode.h" // Include SM64 Library
    
    void _start()
    {
    	asm volatile("la $gp, _gp"); // Ensure the correct data pointer is loaded
    	PrintXY(80, 75, "Hello World"); // Print "Hello World" on X: 80 and Y: 75
    }
    
  7. Save it
  8. At this point create a new file called "Makefile" without any extension
  9. In the file you've just created enter:
    Code
    # Name
    PRJNAME	= main
    PARTS	= $(PRJNAME).o
    
    # Vars
    N64_ROOT	= ../..
    N64_PREFIX	= mips64-
    N64_BIN		= $(N64_ROOT)/bin
    INC_ROOT	= include
    INC_FLAGS	= -I. -I $(N64_ROOT)/$(INC_ROOT)
    LIB_FLAGS	= -L. -T $(N64_ROOT)/$(INC_ROOT)/mario64.x
    GS_TYPE		= default
    
    # Flags
    NOBUILTIN	= -fno-builtin
    CFLAGS		= -std=gnu99 -nodefaultlibs -march=vr4300 -mtune=vr4300 -mabi=32 $(INC_FLAGS) $(NOBUILTIN) -o3
    ASFLAGS		= -march=vr4300 -mabi=32
    LINK_FLAGS	= $(LIB_FLAGS) $(LIBS)
    
    # Programs
    CC		= $(N64_BIN)/$(N64_PREFIX)gcc
    LD		= $(N64_BIN)/$(N64_PREFIX)ld
    OBJCOPY		= $(N64_BIN)/$(N64_PREFIX)objcopy
    CHEAT		= $(N64_BIN)/$(GS_TYPE)cheat
    BINCODE		= $(N64_BIN)/bin2code
    
    # Process
    all: $(PRJNAME).bin
    	$(BINCODE) $(PRJNAME).bin 80400000 codes.txt # Turn binary into GS code
    	cat hook.txt codes.txt | $(CHEAT) "Mario 64" 0 > Cheats.ini # Turn into cheat format
    
    $(PRJNAME).bin: $(PRJNAME).elf
    	$(OBJCOPY) $(PRJNAME).elf $(PRJNAME).bin -O binary
    
    $(PRJNAME).elf: $(PARTS)
    	$(LD) -o $(PRJNAME).elf	$(PARTS) $(LINK_FLAGS)
    	
    clean:
    	rm *.o *.elf *~ *.bin Cheats.ini codes.txt -vf
    

    PRJNAME is the name of the C file without the extension
    GS_TYPE is the output format. You can choose "nemu" for formatted nemu cheat or "default" for simple code



STEP 2

Compile your own code


  1. Open MinGW Shell
  2. Enter cd /c/MinGW/n64tree-win32/hacks ("/c/" is the equivalent of "C:/", replace "/c/MinGW/" with your Destination Location if you edited it and replace "hacks" with the name of the folder where all your hacks are placed, if you edited it)
  3. Enter cd HelloWorld (Replace "HelloWorld" with the name of the folder where all the files you've just created are placed, if you edited it)
  4. Enter make on MinGW Shell
  5. If you didn't any error, a file called Cheats.ini will be created
  6. Open Cheats.ini where the code is finally produced
  7. Insert the GameShark code in an emulator
  8. Launch the SM64 US 1.0 ROM
  9. The result will be this:

  10. If you want to apply some changes to the C code:
    1. Enter make clean on MinGW Shell
    2. Edit the C file
    3. Enter make on MinGW Shell
  11. Close MinGW Shell


Good job!
srsly, you should not take messiaens work and republish it. also, if you know, what this is actually doing (which i confidently doubt), you should explain, how to create function, that don't get hooked from mario's debug menu and that could actually be used in a hack. after that, you will have to explain, how to insert the asm code without using a gameshark device. when you are done with that, explain, how behavior scripts work. after that, someone will be able to actually use this :V
Originally posted by Kazeshin
srsly, you should not take messiaens work and republish it. also, if you know, what this is actually doing (which i confidently doubt), you should explain, how to create function, that don't get hooked from mario's debug menu and that could actually be used in a hack. after that, you will have to explain, how to insert the asm code without using a gameshark device. when you are done with that, explain, how behavior scripts work. after that, someone will be able to actually use this :V


Can you explain better?
P.S. I only wanted to explain this with new MinGW version and a better directory order
And if you are saying that I'm not giving credits, watch the comment of the ZIP file.
of course. the gameshark code generated has 2 parts; first part is the hook and should be deleted and be completely ignored. the second part is the actual ASM code. this code has to be inserted at where it gets called by the behavior script. (0C 00 00 00 80 XX XX XX to call it; XX XX XX - 245000 <while this has to be in the checksum area).

a person has to be able to edit behavior scripts and to know at least a bit of ASM, before he can actually use it. coding in C is just easier and messiaen himself didn't used this every time.
I can't see the part in your tutorial where you give Messiaen aka Frauber any credits for the software.
Originally posted by Kazeshin
of course. the gameshark code generated has 2 parts; first part is the hook and should be deleted and be completely ignored. the second part is the actual ASM code. this code has to be inserted at where it gets called by the behavior script. (0C 00 00 00 80 XX XX XX to call it; XX XX XX - 245000 <while this has to be in the checksum area).

a person has to be able to edit behavior scripts and to know at least a bit of ASM, before he can actually use it. coding in C is just easier and messiaen himself didn't used this every time.


I asked you to write better precisely, not to explain how it works.
I know how it works because sometimes I had to patch GameShark to ROM with HEX.
However thanks, if I did/said something wrong correct me and explain because I returned in SM64 Hacking only some days ago and I forgot 50% of the basics considering that 90% of new discoveries didn't exist in the past, so I am stuck at Starxxon's tools, old midi2mml, frauber's obj importer gui, etc. xD.
But I didn't say "frauber used this every time".
I re-did a tutorial on how to code with C in N64 (as the title says).

Originally posted by UED
I can't see the part in your tutorial where you give Messiaen aka Frauber any credits for the software.


It is in the ZIP of the Toolchain.
However, I noticed you are commenting first of download the files, so I post it also in the thread.
Originally posted by DamiHack
Originally posted by Kazeshin
of course. the gameshark code generated has 2 parts; first part is the hook and should be deleted and be completely ignored. the second part is the actual ASM code. this code has to be inserted at where it gets called by the behavior script. (0C 00 00 00 80 XX XX XX to call it; XX XX XX - 245000 <while this has to be in the checksum area).

a person has to be able to edit behavior scripts and to know at least a bit of ASM, before he can actually use it. coding in C is just easier and messiaen himself didn't used this every time.


I asked you to write better precisely, not to explain how it works.
I know how it works because sometimes I had to patch GameShark to ROM with HEX.
However thanks, if I did/said something wrong correct me and explain because I returned in SM64 Hacking only some days ago and I forgot 50% of the basics considering that 90% of new discoveries didn't exist in the past, so I am stuck at Starxxon's tools, old midi2mml, frauber's obj importer gui, etc. xD.
But I didn't say "frauber used this every time".
I re-did a tutorial on how to code with C in N64 (as the title says).


Actually you "re-did" my old little C tutorial from a while ago. It was more like a video upload, but posted a tutorial on my google site too. (Way before the video upload)

Here the link:
http://sites.google.com/site/cajetan64/home/coding-in-n64-with-c

I don't get, why it had to be "re-done". So a little explaintation would be interessting.

Then again: If you're redoing a tutorial, you could've added some stuff I didn't do + For example like Kaze said, on how to create a function, that doesn't get hooked from mario.

Greetings,
Tarek701.

Originally posted by Tarek701
Originally posted by DamiHack
Originally posted by Kazeshin
of course. the gameshark code generated has 2 parts; first part is the hook and should be deleted and be completely ignored. the second part is the actual ASM code. this code has to be inserted at where it gets called by the behavior script. (0C 00 00 00 80 XX XX XX to call it; XX XX XX - 245000 <while this has to be in the checksum area).

a person has to be able to edit behavior scripts and to know at least a bit of ASM, before he can actually use it. coding in C is just easier and messiaen himself didn't used this every time.


I asked you to write better precisely, not to explain how it works.
I know how it works because sometimes I had to patch GameShark to ROM with HEX.
However thanks, if I did/said something wrong correct me and explain because I returned in SM64 Hacking only some days ago and I forgot 50% of the basics considering that 90% of new discoveries didn't exist in the past, so I am stuck at Starxxon's tools, old midi2mml, frauber's obj importer gui, etc. xD.
But I didn't say "frauber used this every time".
I re-did a tutorial on how to code with C in N64 (as the title says).


Actually you "re-did" my old little C tutorial from a while ago. It was more like a video upload, but posted a tutorial on my google site too. (Way before the video upload)

Here the link:
http://sites.google.com/site/cajetan64/home/coding-in-n64-with-c

I don't get, why it had to be "re-done". So a little explaintation would be interessting.

Then again: If you're redoing a tutorial, you could've added some stuff I didn't do + For example like Kaze said, on how to create a function, that doesn't get hooked from mario.

Greetings,
Tarek701.


I did a new tutorial with new version of MinGW, new Makefile, better explaination in the C file, better directory order.
Isn't this some stuff you didn't do?
Everyone can write a tutorial and every tutorial can regard the same argument.
Can't I write a tutorial? I didn't copy anything.
For example everyone can do a tutorial on how to use TT64, how to use Obj Importer GUI and also how to install MinGW step by step.

Mod Edit: Edited out drama from outside SMWCentral.
Please don't mention any drama made outside the site DemiHack, it's against the rules to do so on SMWCentral. Consider this a warning.
Originally posted by Vinnyboiler
Please don't mention any drama made outside the site DemiHack, it's against the rules to do so on SMWCentral. Consider this a warning.


Okay, sorry.
Originally posted by Vinnyboiler
Please don't mention any drama made outside the site DemiHack, it's against the rules to do so on SMWCentral. Consider this a warning.


Yes, some moderators were already angry about him. I'm happy, that I didn't read anything what DamiHack said later. But I can imagine myself, what he would've said. (Including some wrong facts)

Then:
Originally posted by DamiHack
Originally posted by Tarek701
Originally posted by DamiHack
Originally posted by Kazeshin
of course. the gameshark code generated has 2 parts; first part is the hook and should be deleted and be completely ignored. the second part is the actual ASM code. this code has to be inserted at where it gets called by the behavior script. (0C 00 00 00 80 XX XX XX to call it; XX XX XX - 245000 <while this has to be in the checksum area).

a person has to be able to edit behavior scripts and to know at least a bit of ASM, before he can actually use it. coding in C is just easier and messiaen himself didn't used this every time.


I asked you to write better precisely, not to explain how it works.
I know how it works because sometimes I had to patch GameShark to ROM with HEX.
However thanks, if I did/said something wrong correct me and explain because I returned in SM64 Hacking only some days ago and I forgot 50% of the basics considering that 90% of new discoveries didn't exist in the past, so I am stuck at Starxxon's tools, old midi2mml, frauber's obj importer gui, etc. xD.
But I didn't say "frauber used this every time".
I re-did a tutorial on how to code with C in N64 (as the title says).


Actually you "re-did" my old little C tutorial from a while ago. It was more like a video upload, but posted a tutorial on my google site too. (Way before the video upload)

Here the link:
http://sites.google.com/site/cajetan64/home/coding-in-n64-with-c

I don't get, why it had to be "re-done". So a little explaintation would be interessting.

Then again: If you're redoing a tutorial, you could've added some stuff I didn't do + For example like Kaze said, on how to create a function, that doesn't get hooked from mario.

Greetings,
Tarek701.


I did a new tutorial with new version of MinGW, new Makefile, better explaination in the C file, better directory order.
Isn't this some stuff you didn't do?
Everyone can write a tutorial and every tutorial can regard the same argument.
Can't I write a tutorial? I didn't copy anything.
For example everyone can do a tutorial on how to use TT64, how to use Obj Importer GUI and also how to install MinGW step by step.

Mod Edit: Edited out drama from outside SMWCentral.


You're retarded, aren't you? I've never said anything bad about, that you write a new tutorial about C coding. I also never talked about, that you "copied" something. O_o. I simply asked, why it actually had to be redone, cause I wrote already one, that included all the same stuff you're providing here. The new makefile, what does it include? Is it the makefile CpuHacka posted? If yes, then you can be sure, that I included it. A better directory "folder"? Mhhh, well... Not really stuff, which need to be "fixed", as they were never errors or something. Every user could've done it themself.

Greetings,
Tarek701.

Originally posted by Tarek701
Originally posted by Vinnyboiler
Please don't mention any drama made outside the site DemiHack, it's against the rules to do so on SMWCentral. Consider this a warning.


Yes, some moderators were already angry about him. I'm happy, that I didn't read anything what DamiHack said later. But I can imagine myself, what he would've said. (Including some wrong facts)


I said only real facts, Tarek701.

Originally posted by Tarek701
Originally posted by DamiHack
Originally posted by Tarek701
(edited by moderator)


I did a new tutorial with new version of MinGW, new Makefile, better explaination in the C file, better directory order.
Isn't this some stuff you didn't do?
Everyone can write a tutorial and every tutorial can regard the same argument.
Can't I write a tutorial? I didn't copy anything.
For example everyone can do a tutorial on how to use TT64, how to use Obj Importer GUI and also how to install MinGW step by step.

Mod Edit: Edited out drama from outside SMWCentral.


You're retarded, aren't you? I've never said anything bad about, that you write a new tutorial about C coding. I also never talked about, that you "copied" something. O_o. I simply asked, why it actually had to be redone, cause I wrote already one, that included all the same stuff you're providing here. The new makefile, what does it include? Is it the makefile CpuHacka posted? If yes, then you can be sure, that I included it. A better directory "folder"? Mhhh, well... Not really stuff, which need to be "fixed", as they were never errors or something. Every user could've done it themself.

Greetings,
Tarek701.


I've never said anything bad about, too.
And I repeat: I did a new tutorial with new version of MinGW, new Makefile, better explaination in the C file, better directory order.
Do you know what is the meaning of "order"?
I didn't say "directory folder" and it isn't the Makefile that CpuHacka posted.
There were many variables not used and some badly used in it.
I also added:
  • The function to choose the Cheats.ini emulator type
  • New gscheat.exe
  • frauber's includes (headers)
  • A new N64.h with a little change by frauber


Originally posted by Tarek701
You're retarded, aren't you?

No, I'm not retarded.
You are violating a rule of General Behavior:
Originally posted by Kieran Menor
Treat other users with respect. Don't provoke others.


Mod edit: Flattened that quote pyramid a bit.
Both, tarek701 and damihack, failed to realize, that the actual link to MinGW is NOWHERE! And still, there are instructions for it.
If you make a tutorial, you should first look over it, before you post it. If I'm wrong, correct me. But both links lead to n64tree-win32. So, fix your stuff please before posting anything.
Your layout has been removed.