Skip to content

Commit 1ad0883

Browse files
Clean up example files
Will still need to find a good method to just clear the screen
1 parent ba21115 commit 1ad0883

File tree

39 files changed

+251
-469
lines changed

39 files changed

+251
-469
lines changed

examples/debugging/src/main.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@ void main(void) {
2626
/* Remove the watchpoint that we had set */
2727
dbg_RemoveWatchpoint(&dbg_test_var_1);
2828
dbg_RemoveWatchpoint(&dbg_test_var_2);
29-
30-
/* Clean up everything */
31-
prgm_CleanUp();
3229

3330
/* Set this value to zero */
3431
dbg_test_var_2 = 0;
3532

3633
/* Fail this assertion */
3734
assert(dbg_test_var_2);
3835
}
39-

examples/fileio_detect/src/main.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,20 @@ void main(void) {
2525
const char search_string[] = { 0xFD, 0x21, 0x80, 0x00 };
2626

2727
/* Find all of the variables that start with this string */
28-
while((var_name = ti_Detect(&search_pos, search_string)) != NULL) {
28+
while ((var_name = ti_Detect(&search_pos, search_string)) != NULL) {
2929
/* Print the name of the variable (Should be LibLoad) */
3030
printText(0, y++, var_name);
3131
}
3232

3333
/* Wait for a key */
34-
while(!os_GetCSC());
34+
while (!os_GetCSC());
3535

36-
/* Clean up everything */
36+
/* Close all open files */
3737
ti_CloseAll();
38-
prgm_CleanUp();
3938
}
4039

4140
/* Draw text on the homescreen at the given X/Y location */
4241
void printText(int8_t xpos, int8_t ypos, const char *text) {
4342
os_SetCursorPos(ypos, xpos);
4443
os_PutStrFull(text);
4544
}
46-

examples/fileio_factorize/src/main.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
/* Keep these headers */
21
#include <stdbool.h>
32
#include <stddef.h>
43
#include <stdint.h>
54
#include <tice.h>
6-
7-
/* Standard headers - it's recommended to leave them included */
5+
86
#include <math.h>
97
#include <stdio.h>
108
#include <stdlib.h>
11-
#include <string.h>
129

13-
/* Shared library headers - depends on which ones you wish to use */
1410
#include <fileioc.h>
1511

1612
void prime_factors(unsigned int n);
@@ -27,22 +23,23 @@ void main(void) {
2723
int in;
2824

2925
/* Get the answer variable */
30-
if(ti_RclVar(TI_REAL_TYPE, ti_Ans, &real_in)) return;
31-
if((in = os_RealToInt24(real_in)) < 1) return;
26+
if (ti_RclVar(TI_REAL_TYPE, ti_Ans, &real_in)) return;
27+
if ((in = os_RealToInt24(real_in)) < 1) return;
3228

29+
/* Get the prime factors of the input */
3330
prime_factors((unsigned)in);
3431

35-
if(!total_primes) return;
32+
/* Create a list to store the primes */
33+
if (!total_primes) return;
3634
list_out = ti_MallocList(total_primes);
3735

38-
for(i=0; i<total_primes; i++) {
36+
/* Write out the list of primes */
37+
for (i=0; i<total_primes; i++) {
3938
list_out->items[i] = os_Int24ToReal(primes[i]);
4039
}
4140

41+
/* Set the new answer */
4242
ti_SetVar(TI_REAL_LIST_TYPE, ti_Ans, list_out);
43-
44-
/* Clean up everything */
45-
prgm_CleanUp();
4643
}
4744

4845
/* Store to an array all the prime numbers */
@@ -54,9 +51,7 @@ void prime_factors(unsigned int n) {
5451
n /= 2;
5552
}
5653

57-
if (n == 1) {
58-
return;
59-
}
54+
if (n == 1) return;
6055

6156
div = 3;
6257
end = sqrt(n);
@@ -67,9 +62,7 @@ void prime_factors(unsigned int n) {
6762
primes[total_primes++] = div;
6863
n /= div;
6964
} while (!(n % div));
70-
if (n == 1) {
71-
return;
72-
}
65+
if (n == 1) return;
7366
end = sqrt(n);
7467
}
7568
div += 2;

examples/fileio_os_vars/src/main.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
/* Keep these headers */
21
#include <stdbool.h>
32
#include <stddef.h>
43
#include <stdint.h>
54
#include <tice.h>
6-
7-
/* Standard headers - it's recommended to leave them included */
5+
86
#include <math.h>
97
#include <stdio.h>
108
#include <stdlib.h>
119
#include <string.h>
1210

13-
/* Shared library headers - depends on which ones you wish to use */
1411
#include <fileioc.h>
1512

1613
/* Some function prototypes. Maybe in the future these functions will become a library */
@@ -61,9 +58,6 @@ void main(void) {
6158
matrix_element(my_matrix, 0, 1) = real_2_5;
6259
ti_SetVar(TI_MATRIX_TYPE, ti_Ans, my_matrix);
6360
free(my_matrix);
64-
65-
/* Clean up everything */
66-
prgm_CleanUp();
6761
}
6862

6963
/* Stores some ints to a complex variable type */
@@ -104,4 +98,4 @@ cplx_t StrsToCplx(char *real, char **real_end, char *imag, char **imag_end) {
10498
res.imag = os_StrToReal(imag, imag_end);
10599
res.imag.sign |= TI_CPLX_TYPE;
106100
return res;
107-
}
101+
}

examples/fileio_read_write/src/main.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,15 @@ void main(void) {
6464
printText(0, 0, "An error occured");
6565
noerr:
6666

67-
/* Get the scan codes */
68-
while(!os_GetCSC());
67+
/* Pause */
68+
while (!os_GetCSC());
6969

70+
/* Close all open files */
7071
ti_CloseAll();
71-
prgm_CleanUp();
7272
}
7373

7474
/* Draw text on the homescreen at the given X/Y location */
7575
void printText(int8_t xpos, int8_t ypos, const char *text) {
7676
os_SetCursorPos(ypos, xpos);
7777
os_PutStrFull(text);
7878
}
79-

examples/fileio_tokens/src/main.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,44 @@
1-
/* Keep these headers */
21
#include <stdbool.h>
32
#include <stddef.h>
43
#include <stdint.h>
54
#include <tice.h>
6-
7-
/* Standard headers - it's recommended to leave them included */
8-
#include <math.h>
5+
96
#include <stdio.h>
107
#include <stdlib.h>
118
#include <string.h>
129

13-
/* Shared library headers -- depends on which ones you wish to use */
1410
#include <fileioc.h>
1511

16-
/* Declare some strings and variables */
17-
const char prgmName[] = "ABC";
12+
/* Declare the program name */
13+
const char *prgmName = "ABC";
1814

1915
/* Function prototypes */
2016
void printText(int8_t xpos, int8_t ypos, const char *text);
2117

2218
/* Main Function */
2319
void main(void) {
24-
ti_var_t myProgram;
20+
ti_var_t prgm;
2521
uint8_t *data_ptr;
26-
uint8_t token_length;
2722

2823
/* Close any files that may be open already */
2924
ti_CloseAll();
3025

31-
/* Open a new variable; deleting it if it already exists */
32-
myProgram = ti_OpenVar(prgmName,"r",ti_Program);
26+
/* Open the program for reading */
27+
prgm = ti_OpenVar(prgmName, "r", TI_PRGM_TYPE);
3328

3429
/* Make sure we opened okay */
35-
if (!myProgram) goto err;
30+
if (!prgm) goto err;
3631

37-
data_ptr = ti_GetDataPtr( myProgram );
38-
printText( 0, 0, ti_GetTokenString( &data_ptr, NULL, NULL ) );
39-
printText( 0, 1, ti_GetTokenString( &data_ptr, NULL, NULL ) );
32+
data_ptr = ti_GetDataPtr(prgm);
33+
printText(0, 0, ti_GetTokenString(&data_ptr, NULL, NULL));
34+
printText(0, 1, ti_GetTokenString(&data_ptr, NULL, NULL));
4035

4136
err:
42-
/* Wait for a key */
43-
while( !os_GetCSC() );
37+
/* Pause */
38+
while (!os_GetCSC());
4439

40+
/* Close files */
4541
ti_CloseAll();
46-
prgm_CleanUp();
4742
}
4843

4944
/* Draw text on the homescreen at the given X/Y location */

examples/gfx_buffered_cube/src/main.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
/* Keep these headers */
21
#include <stdbool.h>
32
#include <stddef.h>
43
#include <stdint.h>
54
#include <tice.h>
65

7-
/* Standard headers - it's recommended to leave them included */
86
#include <math.h>
97
#include <stdio.h>
108
#include <stdlib.h>
119
#include <string.h>
1210

13-
/* Shared libraries */
1411
#include <graphx.h>
1512

16-
/* Put function prototypes here */
13+
/* Function prototypes */
1714
void rotate(void);
1815

19-
/* Put globals here */
16+
/* Globals */
2017
#define ORG (-50)
2118
#define DEG (6.0)
2219
#define ANG (DEG * M_PI / 180.0)
@@ -47,10 +44,10 @@ float midx1,
4744
midx2,
4845
midy2;
4946

50-
uint8_t loop;
51-
5247
/* Place main code in main */
5348
void main(void) {
49+
uint8_t loop = 0;
50+
5451
/* Seed the random numbers */
5552
srand(rtc_Time());
5653

@@ -70,8 +67,8 @@ void main(void) {
7067
while (!os_GetCSC()) {
7168

7269
/* Change the color of the cube depending on loop (mod 16) */
73-
if (!((loop++) & 0xF)) {
74-
gfx_SetColor(rand() & 0xFE);
70+
if (!((loop++) & 0xf)) {
71+
gfx_SetColor(rand() & 0xfe);
7572
}
7673

7774
/* Call the rotation code */
@@ -81,9 +78,8 @@ void main(void) {
8178
gfx_SwapDraw();
8279
}
8380

84-
/* Clean up the program */
81+
/* End the graphics */
8582
gfx_End();
86-
prgm_CleanUp();
8783
}
8884

8985
/* Rotation code */
@@ -115,4 +111,4 @@ void rotate(void) {
115111
gfx_Line(face2[i][0], face2[i][1], face2[i+1][0], face2[i+1][1]);
116112
gfx_Line(face1[i][0], face1[i][1], face2[ i ][0], face2[ i ][1]);
117113
}
118-
}
114+
}

examples/gfx_buffering/src/main.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,47 @@
1-
/* Keep these headers */
21
#include <stdbool.h>
32
#include <stddef.h>
43
#include <stdint.h>
54
#include <tice.h>
65

7-
/* Standard headers - it's recommended to leave them included */
86
#include <math.h>
97
#include <stdio.h>
108
#include <stdlib.h>
119
#include <string.h>
1210

13-
/* Shared libraries */
1411
#include <graphx.h>
1512

16-
/*
17-
* This tutorial is meant to be played around with to get a feeling for how buffering works
18-
*/
19-
20-
/* Put function prototypes here */
21-
22-
/* Put all your code here */
13+
/* This tutorial is meant to be played around with to get a feeling for how buffering works */
2314
void main(void) {
2415
/* Initialize the 8bpp graphics */
25-
gfx_Begin( gfx_8bpp );
16+
gfx_Begin(gfx_8bpp);
2617

2718
/* Set up the palette */
28-
gfx_SetColor( gfx_black );
19+
gfx_SetColor(gfx_black);
2920

3021
/* Draw to buffer to avoid tearing */
3122
gfx_SetDrawBuffer();
3223

3324
/* Draw a line on the buffer */
34-
//gfx_FillScreen( gfx_black );
35-
gfx_Line( 0, 0, LCD_WIDTH-1, LCD_HEIGHT-1 );
25+
//gfx_FillScreen(gfx_black);
26+
gfx_Line(0, 0, LCD_WIDTH-1, LCD_HEIGHT-1);
3627

3728
/* Wait for a key */
38-
while( !os_GetCSC() );
29+
while (!os_GetCSC());
3930

4031
/* Swap the buffer with the screen */
4132
gfx_SwapDraw();
4233

4334
/* Copy part of the screen to the offscreen buffer */
44-
gfx_Blit( gfx_buffer );
45-
//gfx_BlitLines( gfx_buffer, 0, 20 );
46-
//gfx_BlitRectangle( gfx_buffer, 0, 0, 160, 120 );
35+
gfx_Blit(gfx_buffer);
36+
//gfx_BlitLines(gfx_buffer, 0, 20);
37+
//gfx_BlitRectangle(gfx_buffer, 0, 0, 160, 120);
4738

4839
/* This should cause half of the line to flicker, and the other half to stay steady */
4940

50-
while( !os_GetCSC() ) {
41+
while (!os_GetCSC()) {
5142
gfx_SwapDraw();
5243
}
5344

54-
/* Close the graphics and return to the OS */
45+
/* Close the graphics */
5546
gfx_End();
56-
prgm_CleanUp();
5747
}

0 commit comments

Comments
 (0)