Skip to content

Commit 9b73bef

Browse files
committed
Add a good graphx program template
1 parent 58f6c3a commit 9b73bef

File tree

5 files changed

+128
-5
lines changed

5 files changed

+128
-5
lines changed

examples/gfx_template/iconc.png

910 Bytes
Loading

examples/gfx_template/makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ----------------------------
2+
# Set NAME to the program name
3+
# Set ICON to the png icon file name
4+
# Set DESCRIPTION to display within a compatible shell
5+
# Set COMPRESSED to "YES" to create a compressed program
6+
# ----------------------------
7+
8+
NAME ?= DEMO
9+
COMPRESSED ?= NO
10+
ICON ?= iconc.png
11+
DESCRIPTION ?= "C SDK Demo"
12+
13+
# ----------------------------
14+
15+
include $(CEDEV)/include/.makefile

examples/gfx_template/readme.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### Template
2+
3+
You can clone this directory for your own projects.
4+
5+
To add code, fill in the void main() function in main.c. You can also create your
6+
own .c and .h files and add them to the directory; the Makefile included in this
7+
template will automatically find and compile the new .c files.
8+
9+
In addition, you can also add your own .asm files, which will be detected and added
10+
appropritately to the proper segment.
11+
12+
---
13+
14+
This template is a part of the C SDK Toolchain for use on the CE.

examples/gfx_template/src/main.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
*--------------------------------------
3+
* Program Name:
4+
* Author:
5+
* License:
6+
* Description:
7+
*--------------------------------------
8+
*/
9+
10+
/* Keep these headers */
11+
#include <stdbool.h>
12+
#include <stddef.h>
13+
#include <stdint.h>
14+
#include <tice.h>
15+
16+
/* Standard headers (recommended) */
17+
#include <math.h>
18+
#include <stdio.h>
19+
#include <stdlib.h>
20+
#include <string.h>
21+
22+
#include <graphx.h>
23+
24+
/* Put your function prototypes here */
25+
void begin();
26+
void end();
27+
bool step();
28+
void draw();
29+
30+
/* Put all your globals here */
31+
bool partial_redraw;
32+
33+
void main() {
34+
begin(); // No rendering allowed!
35+
gfx_Begin();
36+
gfx_SetDrawBuffer(); // Draw to the buffer to avoid rendering artifats
37+
38+
while (step()) { // No rendering allowed in step!
39+
if (partial_redraw) // Only want to redraw part of the previous frame?
40+
gfx_BlitScreen(); // Copy previous frame as a base for this frame
41+
draw(); // As little non-rendering logic as possible
42+
gfx_SwapDraw(); // Queue the buffered frame to be displayed
43+
}
44+
45+
gfx_End();
46+
end();
47+
}
48+
49+
/* Put other functions here */
50+
void begin() {
51+
/* Implement me! */
52+
}
53+
54+
void end() {
55+
/* Implement me! */
56+
}
57+
58+
void step() {
59+
/* Implement me! */
60+
}
61+
62+
void draw() {
63+
/* Implement me! */
64+
}

src/graphx/graphx.h

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
11
/**
22
* @file
3+
* @brief Contains optimized graphics operations and routines
4+
*
5+
* Example program template with best graphx buffer usage pattern:
6+
* @code
7+
* // Standard #includes omitted
8+
*
9+
* bool partial_redraw;
10+
*
11+
* // Implement us!
12+
* void begin();
13+
* void end();
14+
* bool step();
15+
* void draw();
16+
*
17+
* void main() {
18+
* begin(); // No rendering allowed!
19+
* gfx_Begin();
20+
* gfx_SetDrawBuffer(); // Draw to the buffer to avoid rendering artifats
21+
*
22+
* while (step()) { // No rendering allowed in step!
23+
* if (partial_redraw) // Only want to redraw part of the previous frame?
24+
* gfx_BlitScreen(); // Copy previous frame as a base for this frame
25+
* draw(); // As little non-rendering logic as possible
26+
* gfx_SwapDraw(); // Queue the buffered frame to be displayed
27+
* }
28+
*
29+
* gfx_End();
30+
* end();
31+
* }
32+
* @endcode
33+
*
334
* @authors Matt "MateoConLechuga" Waltz
435
* @authors Jacob "jacobly" Young
536
* @authors Zachary "Runer112" Wassall
637
* @authors Patrick "tr1p1ea" Prendergast
738
* @authors "grosged"
8-
* @brief Contains optimized graphics operations and routines
939
*/
1040

1141
#ifndef H_GRAPHX
@@ -757,16 +787,16 @@ uint8_t gfx_GetDraw(void);
757787
* the next invocation of a graphx drawing function will block, waiting for this
758788
* event. To block and wait explicitly, use gfx_Wait().
759789
*
790+
* The LCD driver maintains its own screen buffer pointer for the duration of a
791+
* refresh. The swap performed by this function will only be picked up at a
792+
* point between refreshes.
793+
*
760794
* @remarks
761795
* In practice, this function should be invoked immediately after finishing
762796
* drawing a frame to the drawing buffer, and invocation of the first graphx
763797
* drawing function for the next frame should be scheduled as late as possible
764798
* relative to non-drawing logic. Non-drawing logic can execute during time when
765799
* a drawing function may otherwise block.
766-
*
767-
* The LCD driver maintains its own screen buffer pointer for the duration of a
768-
* refresh. The swap performed by this function will only be picked up at a
769-
* point between refreshes.
770800
*/
771801
void gfx_SwapDraw(void);
772802

0 commit comments

Comments
 (0)