wswan:tutorial:hello_display
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| wswan:tutorial:hello_display [2025/12/31 12:29] – asie | wswan:tutorial:hello_display [2025/12/31 12:29] (current) – removed asie | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Your first program ====== | ||
| - | |||
| - | In this chapter, we're going to learn the basics of compiling and testing a WonderSwan homebrew project; by the end of it, we will write basic code to display something on the screen. | ||
| - | |||
| - | First, set up a new project: | ||
| - | |||
| - | $ mkdir 1-hellodisplay/ | ||
| - | $ wf-wswantool project new 1-hellodisplay/ | ||
| - | |||
| - | - Create the directory " | ||
| - | - Create a new wswan targetting project with the directory and name " | ||
| - | |||
| - | Next, compile the project: | ||
| - | |||
| - | $ cd 1-hellodisplay/ | ||
| - | $ make | ||
| - | |||
| - | This will output the following lines: | ||
| - | |||
| - | CC src/main.c | ||
| - | LD build/ | ||
| - | ROM | ||
| - | MERGE | ||
| - | |||
| - | - The C compiler is compiling the source file '' | ||
| - | - The ELF file '' | ||
| - | - The ROM file '' | ||
| - | - The '' | ||
| - | |||
| - | Finally, you can run the ROM file using your emulator of choice. However, it's not displaying anything - after all, there' | ||
| - | |||
| - | Let's examine the '' | ||
| - | |||
| - | <code C> | ||
| - | // SPDX-License-Identifier: | ||
| - | // | ||
| - | // SPDX-FileContributor: | ||
| - | // (1)! | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | void main(void) { | ||
| - | while(1); | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | - The default copyright header for the template file. This is required to inform you that you can use the example code contained without restrictions. However, before writing your own code, if you wish to put different terms on your code, you should remove it. | ||
| - | - The '' | ||
| - | - The '' | ||
| - | |||
| - | <WRAP round important> | ||
| - | Pay special attention to the `while(1);` at the end - this is an infinite loop. | ||
| - | | ||
| - | You may be used to ending `main()` with a `return;` of some type. On bare metal, however, one should not return from main, as there' | ||
| - | </ | ||
| - | |||
| - | With only an infinite loop in '' | ||
| - | |||
| - | For now, we're going to assume a " | ||
| - | |||
| - | < | ||
| - | graph LR | ||
| - | A[Palette index< | ||
| - | B --> | ||
| - | </ | ||
| - | |||
| - | First, we need to initialize the shade look-up table. At the beginning of '' | ||
| - | |||
| - | <code C> | ||
| - | ws_display_set_shade_lut(WS_DISPLAY_SHADE_LUT_DEFAULT); | ||
| - | </ | ||
| - | |||
| - | This sets a default table, with the color value '' | ||
| - | |||
| - | <WRAP round info> | ||
| - | As the " | ||
| - | </ | ||
| - | |||
| - | Next, we need to enable the display. We're going to enable the " | ||
| - | |||
| - | <code C> | ||
| - | outportw(WS_DISPLAY_CTRL_PORT, | ||
| - | </ | ||
| - | |||
| - | Finally, we're going to do some changes to the display. Edit the '' | ||
| - | |||
| - | <code C> | ||
| - | while (1) { | ||
| - | outportw(WS_SCR_PAL_0_PORT, | ||
| - | ws_delay_ms(100); | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | - This loads the first palette, adds one to it, and saves it. As the lowest bits constitute the color value for the first palette index, this will cause the background color to change on every execution. | ||
| - | - As we don't have any interrupts set up yet, the only thing we can do is busy-wait - that is, stall the CPU for a specified number of microseconds. While this is not recommended for production code, it's simple enough to prevent rapid flicker in the demonstration. | ||
| - | |||
| - | That's all! Compile the code using '' | ||
wswan/tutorial/hello_display.1767184153.txt.gz · Last modified: by asie
