]> git.sur5r.net Git - cc65/blob - samples/hello.c
Merge pull request #7 from cvemu/master
[cc65] / samples / hello.c
1 /*
2 ** Fancy hello world program using cc65.
3 **
4 ** Ullrich von Bassewitz (ullrich@von-bassewitz.de)
5 **
6 */
7
8
9
10 #include <stdlib.h>
11 #include <string.h>
12 #include <conio.h>
13 #include <joystick.h>
14
15
16
17 /*****************************************************************************/
18 /*                                   Data                                    */
19 /*****************************************************************************/
20
21
22
23 static const char Text [] = "Hello world!";
24
25
26
27 /*****************************************************************************/
28 /*                                   Code                                    */
29 /*****************************************************************************/
30
31
32
33 int main (void)
34 {
35     unsigned char XSize, YSize;
36
37     /* Set screen colors, hide the cursor */
38     textcolor (COLOR_WHITE);
39     bordercolor (COLOR_BLACK);
40     bgcolor (COLOR_BLACK);
41     cursor (0);
42
43     /* Clear the screen, put cursor in upper left corner */
44     clrscr ();
45
46     /* Ask for the screen size */
47     screensize (&XSize, &YSize);
48
49     /* Draw a border around the screen */
50
51     /* Top line */
52     cputc (CH_ULCORNER);
53     chline (XSize - 2);
54     cputc (CH_URCORNER);
55
56     /* Vertical line, left side */
57     cvlinexy (0, 1, YSize - 2);
58
59     /* Bottom line */
60     cputc (CH_LLCORNER);
61     chline (XSize - 2);
62     cputc (CH_LRCORNER);
63
64     /* Vertical line, right side */
65     cvlinexy (XSize - 1, 1, YSize - 2);
66
67     /* Write the greeting in the mid of the screen */
68     gotoxy ((XSize - strlen (Text)) / 2, YSize / 2);
69     cprintf ("%s", Text);
70
71 #if defined(__NES__) || defined(__PCE__) || defined(__GAMATE__)
72
73     /* Wait for the user to press a button */
74     joy_install (joy_static_stddrv);
75     while (!joy_read (JOY_1)) ;
76     joy_uninstall ();
77
78 #else
79
80     /* Wait for the user to press a key */
81     (void) cgetc ();
82
83 #endif
84
85     /* Clear the screen again */
86     clrscr ();
87
88     /* Done */
89     return EXIT_SUCCESS;
90 }