wswan:tutorial:your_first_program
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| wswan:tutorial:your_first_program [2025/12/31 12:29] – created asie | wswan:tutorial:your_first_program [2025/12/31 15:32] (current) – asie | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Your first program ====== | + | ====== Your first program |
| - | In this chapter, | + | In this chapter, |
| + | |||
| + | ===== Creating a project ===== | ||
| First, set up a new project: | First, set up a new project: | ||
| - | $ mkdir 1-hellodisplay/ # (1)! | + | $ mkdir first-program/ # (1)! |
| - | $ wf-wswantool project new 1-hellodisplay/ # (2)! | + | $ wf-wswantool project new first-program/ # (2)! |
| - | - Create the directory "1-hellodisplay" in the terminal' | + | - Create the directory "first-program" in the terminal' |
| - | - Create a new wswan targetting | + | - Create a new wswan target |
| - | Next, compile | + | Next, compile |
| - | $ cd 1-hellodisplay/ | + | $ cd first-program/ |
| $ make | $ make | ||
| - | This will output the following | + | The build script |
| CC src/main.c | CC src/main.c | ||
| - | LD build/1-hellodisplay_stage1.elf | + | LD build/first-program_stage1.elf |
| - | ROM 1-hellodisplay.wsc | + | ROM first-program.wsc |
| MERGE | MERGE | ||
| - The C compiler is compiling the source file '' | - The C compiler is compiling the source file '' | ||
| - | - The ELF file '' | + | - The ELF file '' |
| - | - The ROM file '' | + | - The ROM file '' |
| - The '' | - The '' | ||
| - | Finally, you can run the ROM file using your emulator of choice. | + | Finally, you can run the ROM file using your emulator of choice. |
| + | |||
| + | ===== Editing source code ===== | ||
| + | |||
| + | The program is not displaying anything - after all, there' | ||
| Let's examine the '' | Let's examine the '' | ||
| Line 45: | Line 51: | ||
| </ | </ | ||
| - | - 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 default copyright header for the template file. This is required to inform you that you can use the example code contained |
| - The '' | - The '' | ||
| - The '' | - The '' | ||
| Line 52: | Line 58: | ||
| Pay special attention to the `while(1);` at the end - this is an infinite loop. | 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' | + | 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 '' | With only an infinite loop in '' | ||
| + | |||
| + | ===== Throwing shade ===== | ||
| For now, we're going to assume a " | For now, we're going to assume a " | ||
| Line 71: | Line 79: | ||
| </ | </ | ||
| - | This sets a default table, with the color value '' | + | This sets a default |
| <WRAP round info> | <WRAP round info> | ||
| - | As the " | + | As the " |
| </ | </ | ||
| Line 88: | Line 96: | ||
| while (1) { | while (1) { | ||
| outportw(WS_SCR_PAL_0_PORT, | outportw(WS_SCR_PAL_0_PORT, | ||
| - | ws_delay_ms(100); // (2)! | + | ws_delay_ms(1000); // (2)! |
| } | } | ||
| </ | </ | ||
| - 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. | - 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. | + | - 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 milliseconds. |
| That's all! Compile the code using '' | That's all! Compile the code using '' | ||
wswan/tutorial/your_first_program.1767184197.txt.gz · Last modified: by asie
