added old 3ds stuff
This commit is contained in:
parent
526bdc91cc
commit
61e90aef4f
13 changed files with 853 additions and 5574 deletions
129
public/blog/old3ds_helloworld.md
Normal file
129
public/blog/old3ds_helloworld.md
Normal file
|
@ -0,0 +1,129 @@
|
|||
---
|
||||
title: 3DS Programming - Hello World
|
||||
description: A guide to creating a simple Hello, World program for the 3DS. (Old)
|
||||
date: 2025-01-01
|
||||
tags: ['3ds', 'programming', 'c', 'devkitpro', 'old']
|
||||
next: old3ds_romfs.md
|
||||
---
|
||||
|
||||
# Hello, World!
|
||||
|
||||
> [!warning]
|
||||
> This guide of mine is old - Like 3 years old at the time of posting. I prefer to keep it up, but I don't think it very highly - It should still work though.
|
||||
> I might make a new one in the future.
|
||||
> I'm doing some alterations at least to make it more readable.
|
||||
> It doesn't teach why things are done very well is my primary issue with it.
|
||||
|
||||
'Hello, World!' is a very simple program used for checking a program's build system, and showing its basic syntax.
|
||||
We should do both before going forward. You should have your project set up for this.
|
||||
|
||||
And if you are using VSCode, I would recommend you get the include paths set up.
|
||||
|
||||
## Begin coding
|
||||
|
||||
Start by including 'stdio.h' (or 'cstdio'!) and '3ds.h'.
|
||||
A quick explanation of '3ds.h'
|
||||
|
||||
'3ds.h' is the file containing references to all the VITAL things we can use to program on the system.
|
||||
|
||||
It does not include many features, such as (And certainly not limited to) rendering capabilities, aside from running the console)
|
||||
|
||||
## Main loop
|
||||
|
||||
Start by setting up a main function as usual for C/C++.
|
||||
|
||||
To initialize the graphics, we need to run gfxInitDefault().
|
||||
|
||||
To initialize the console, we need to run consoleInit([SCREEN HERE], NULL).
|
||||
|
||||
Replace '[SCREEN HERE]' with either GFX_TOP or GFX_BOTTOM, depending on what screen you want.
|
||||
|
||||
At this point, the code should look something like this:
|
||||
|
||||
<!-- Note: I originally used images for these, but... Why did I do that? -->
|
||||
|
||||
```c
|
||||
#include <stdio.h>
|
||||
#include <3ds.h>
|
||||
|
||||
int main() {
|
||||
// Initialize the console
|
||||
gfxInitDefault();
|
||||
consoleInit(GFX_BOTTOM, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
As the console is now ready, you can now print to the screen. You can use puts(), printf(), std::cout, etc.
|
||||
|
||||
If we try and run it now, it should immediately close itself, as there is no main loop.
|
||||
|
||||
To create a main loop, we create a while loop with aptMainLoop() as its argument:
|
||||
|
||||
```c
|
||||
// Initialize the console
|
||||
// ...
|
||||
|
||||
/// Main loop
|
||||
while(aptMainLoop()) {
|
||||
// Code here
|
||||
}
|
||||
```
|
||||
|
||||
This will loop infinitely until the user closes the program.
|
||||
|
||||
## Input
|
||||
|
||||
Okay, so we now have a main loop... How do we exit back to the Homebrew Launcher?
|
||||
|
||||
Simple. We can scan for input, and break if it detects a button, in this case START, being pressed.
|
||||
|
||||
We can scan for input with hidScanInput(), and get which keys are down with hidKeysDown() like so:
|
||||
|
||||
```c
|
||||
// Main loop
|
||||
while(aptMainLoop()) {
|
||||
// Scan for input
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown();
|
||||
}
|
||||
```
|
||||
|
||||
Every button is mapped to a different bit on the unsigned 32-bit integer.
|
||||
|
||||
We can get specific keys via an AND operation between the integer and the desired key:
|
||||
|
||||
```c
|
||||
// Main loop
|
||||
while(aptMainLoop()) {
|
||||
// Scan for input
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown();
|
||||
|
||||
// Break if START is pressed
|
||||
if(kDown & KEY_START) break;
|
||||
}
|
||||
```
|
||||
|
||||
## Wrapping up
|
||||
|
||||
We can add V-Sync with gspWaitForVBlank(), which may help if you want that and don't want to draw anything aside from the console. You can disregard this if you want:
|
||||
|
||||
```c
|
||||
// Main loop
|
||||
while(aptMainLoop()) {
|
||||
// Scan for input
|
||||
// ...
|
||||
// Break if START is pressed
|
||||
// ...
|
||||
|
||||
// Wait for V-Blank
|
||||
gspWaitForVBlank();
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
And we are done. You can run the program, and get the words 'Hello, World!' printed on the screen:
|
||||
|
||||

|
161
public/blog/old3ds_romfs.md
Normal file
161
public/blog/old3ds_romfs.md
Normal file
|
@ -0,0 +1,161 @@
|
|||
---
|
||||
title: 3DS Programming - Using RomFS
|
||||
description: A guide to using RomFS on the 3DS. (Old)
|
||||
date: 2025-01-01
|
||||
tags: ['3ds', 'programming', 'c', 'devkitpro', 'old']
|
||||
previous: old3ds_helloworld.md
|
||||
next: old3ds_touchscreen.md
|
||||
---
|
||||
|
||||
# Accessing ROM files with RomFS
|
||||
|
||||
> [!warning]
|
||||
> This guide of mine is old - Like 3 years old at the time of posting. I prefer to keep it up, but I don't think it very highly - It should still work though.
|
||||
> I might make a new one in the future.
|
||||
> I'm doing some alterations at least to make it more readable.
|
||||
> It doesn't teach why things are done very well is my primary issue with it.
|
||||
|
||||
RomFS allows us to access files stored on the ROM file, cartridge, or application.
|
||||
|
||||
It can be used to read things such as graphics assets, audio data, and other data.
|
||||
|
||||
## RomFS folder
|
||||
|
||||
You may have noticed while building that there is a folder named 'romfs' in your project:
|
||||
|
||||
```
|
||||
- Project
|
||||
- build
|
||||
- **romfs**
|
||||
- source
|
||||
- Makefile
|
||||
- Project.3dsx
|
||||
```
|
||||
|
||||
(If it is not already present, create it now.)
|
||||
|
||||
This is where all the program files are stored. These files are mounted on 'romfs:/' when the app is running.
|
||||
|
||||
If you have any sprites, they will appear in the 'gfx' directory inside of 'romfs:/', and are accessed accordingly.
|
||||
|
||||
Create a text file inside of 'romfs', name it something like 'sample.txt' (or 'sample' if you have file extensions off):
|
||||
|
||||
```
|
||||
- Project
|
||||
- build
|
||||
- **romfs**
|
||||
- sample.txt
|
||||
- source
|
||||
- Makefile
|
||||
- Project.3dsx
|
||||
```
|
||||
|
||||
This file will appear as 'romfs:/sample.txt' in the program.
|
||||
|
||||
## Using RomFS
|
||||
|
||||
We will initialize RomFS, check if a file exists, and then deinitialize.
|
||||
|
||||
### Initializing
|
||||
|
||||
Initializing RomFS is trivial - It only takes one simple function to do it:
|
||||
|
||||
```c
|
||||
// Initialize the console
|
||||
// ...
|
||||
|
||||
// Initialize RomFS
|
||||
romfsInit();
|
||||
|
||||
// Main loop
|
||||
// ...
|
||||
```
|
||||
|
||||
### Using
|
||||
|
||||
To access a file, we do basically the exact same thing we could do on a home computer in C or C++, just with a different drive.
|
||||
|
||||
We will check if the file exists, first by trying to open it, and checking if it failed to open. This is what you would normally do in C:
|
||||
|
||||
```c
|
||||
// Check if the file exists
|
||||
FILE* file = fopen("romfs:/sample.txt", "r");
|
||||
|
||||
if (file == NULL) {
|
||||
// File does not exist
|
||||
puts("File does not exist.");
|
||||
} else {
|
||||
// File exists
|
||||
puts("File exists.");
|
||||
}
|
||||
|
||||
// Close the file
|
||||
fclose(file);
|
||||
|
||||
// Main loop
|
||||
```
|
||||
|
||||
You can play with this by adding or removing sample.txt from the 'romfs' folder.
|
||||
|
||||
### De-initializing
|
||||
|
||||
Like initializing RomFS, it only takes another simple function to de-initialize:
|
||||
|
||||
```c
|
||||
// Main loop
|
||||
// ...
|
||||
|
||||
// De-initialize RomFS
|
||||
romfsExit();
|
||||
|
||||
// Return...
|
||||
```
|
||||
|
||||
And that is all you need to access files on the ROM.
|
||||
|
||||
## Wrapping up
|
||||
|
||||
Our code should now look like this:
|
||||
|
||||
```c
|
||||
#include <stdio.h>
|
||||
#include <3ds.h>
|
||||
|
||||
int main() {
|
||||
// Initialize the console
|
||||
gfxInitDefault();
|
||||
consoleInit(GFX_BOTTOM, NULL);
|
||||
|
||||
// Initialize RomFS
|
||||
romfsInit();
|
||||
|
||||
// Check if the file exists
|
||||
FILE* file = fopen("romfs:/sample.txt", "r");
|
||||
|
||||
if (file == NULL) {
|
||||
// File does not exist
|
||||
puts("File does not exist.");
|
||||
} else {
|
||||
// File exists
|
||||
puts("File exists.");
|
||||
}
|
||||
|
||||
// Close the file
|
||||
fclose(file);
|
||||
|
||||
// Main loop
|
||||
while(aptMainLoop()) {
|
||||
// Scan for input
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown();
|
||||
|
||||
// Close the program if START is pressed
|
||||
if (kDown & KEY_START) break;
|
||||
}
|
||||
|
||||
// De-initialize RomFS
|
||||
romfsExit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
98
public/blog/old3ds_touchscreen.md
Normal file
98
public/blog/old3ds_touchscreen.md
Normal file
|
@ -0,0 +1,98 @@
|
|||
---
|
||||
title: 3DS Programming - Touchscreen Input
|
||||
description: A guide to using the touchscreen on the 3DS. (Old)
|
||||
date: 2025-01-01
|
||||
tags: ['3ds', 'programming', 'c', 'devkitpro', 'old']
|
||||
previous: old3ds_romfs.md
|
||||
---
|
||||
|
||||
# Touchscreen Input
|
||||
|
||||
> [!warning]
|
||||
> This guide of mine is old - Like 3 years old at the time of posting. I prefer to keep it up, but I don't think it very highly - It should still work though.
|
||||
> I might make a new one in the future.
|
||||
> I'm doing some alterations at least to make it more readable.
|
||||
> It doesn't teach why things are done very well is my primary issue with it.
|
||||
|
||||
Here we will find the position of a touch on the touchscreen.
|
||||
|
||||
It is very simple to do this.
|
||||
|
||||
## Getting the touch position
|
||||
|
||||
To find the touch position, we need to request the touchPosition type from the OS, and read from that.
|
||||
|
||||
We must first create a touchPosition like so:
|
||||
|
||||
```c
|
||||
// Check for input
|
||||
// ...
|
||||
|
||||
// Will contain the position of the touch
|
||||
touchPosition touch;
|
||||
|
||||
// Will obtain that information
|
||||
hidTouchRead(&touch);
|
||||
|
||||
// Exit program if START is pressed
|
||||
// ...
|
||||
```
|
||||
|
||||
Then, we must read from it like so:
|
||||
|
||||
The touch position is stored in our touchPosition as 'px' and 'py'.
|
||||
|
||||
## Printing the information to the screen
|
||||
|
||||
To print the position so we may see it, we should, instead of spamming the console with it, overwrite the X and Y position output by setting the position of the output first.
|
||||
|
||||
This would make it much easier to read, although we would need some whitespace after it to prevent anything getting printed without overwriting:
|
||||
|
||||
```c
|
||||
// Print the touch screen coordinates
|
||||
// Keep the whitespace if you do not want issues
|
||||
printf("\x1b[1;0H X=%u Y=%u ", touch.px, touch.py);
|
||||
|
||||
// Exit program if START is pressed
|
||||
// ...
|
||||
```
|
||||
|
||||
The position should default to [0, 0] when no touch is found:
|
||||
|
||||

|
||||
|
||||
## Wrapping up
|
||||
|
||||
Our code should now look like this:
|
||||
```c
|
||||
#include <stdio.h>
|
||||
#include <3ds.h>
|
||||
|
||||
int main() {
|
||||
// Initialize the console
|
||||
gfxInitDefault();
|
||||
consoleInit(GFX_BOTTOM, NULL);
|
||||
|
||||
// Will contain the position of the touch
|
||||
// This can either be inside or outside the main loop
|
||||
touchPosition touch;
|
||||
|
||||
while (aptMainLoop()) {
|
||||
// Check for input
|
||||
hidScanInput();
|
||||
|
||||
// Will obtain that information
|
||||
hidTouchRead(&touch);
|
||||
|
||||
// Print the touch screen coordinates
|
||||
// Keep the whitespace if you do not want issues
|
||||
printf("\x1b[1;0H X=%u Y=%u ", touch.px, touch.py);
|
||||
|
||||
// Exit program if START is pressed
|
||||
if (hidKeysDown() & KEY_START)
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
title: Styling Test
|
||||
description: A test post to see how the site styling looks
|
||||
date: 2024-12-31
|
||||
date: 2025-01-01
|
||||
tags: ['meta', 'web']
|
||||
---
|
||||
|
||||
|
|
BIN
public/files/old3ds/helloworld/dkp_progress0.png
Normal file
BIN
public/files/old3ds/helloworld/dkp_progress0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
public/files/old3ds/touchscreen/dkp_touch0.png
Normal file
BIN
public/files/old3ds/touchscreen/dkp_touch0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Loading…
Add table
Add a link
Reference in a new issue