]> git.sur5r.net Git - cc65/blob - samples/atari2600hello.c
remove TABs
[cc65] / samples / atari2600hello.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /* Atari VCS 2600 sample C program                                           */
4 /*                                                                           */
5 /* Florent Flament (contact@florentflament.com), 2017                        */
6 /*                                                                           */
7 /*****************************************************************************/
8
9 #include <atari2600.h>
10
11 // PAL Timings
12 // Roughly computed based on Stella Programmer's guide (Steve Wright)
13 // scanlines count per section.
14 #define VBLANK_TIM64 51 // 45 lines * 76 cycles/line / 64 cycles/tick
15 #define KERNAL_T1024 17 // 228 lines * 76 cycles/line / 1024 cycles/tick
16 #define OVERSCAN_TIM64 42 // 36 lines * 76 cycles/line / 64 cycles/tick
17
18 // Testing memory zones
19 const unsigned char rodata_v[] = "Hello!";
20 unsigned char data_v = 0x77;
21 unsigned char bss_v;
22
23 void main(void) {
24     unsigned char color = 0x79; // Stack variable
25     bss_v = 0x88; // Testing BSS variable
26
27     for/*ever*/(;;) {
28         // Vertical Sync signal
29         TIA.vsync = 0x02;
30         TIA.wsync = 0x00;
31         TIA.wsync = 0x00;
32         TIA.wsync = 0x00;
33         TIA.vsync = 0x00;
34
35         // Vertical Blank timer setting
36         RIOT.tim64t = VBLANK_TIM64;
37
38         // Doing frame computation during blank
39         TIA.colubk = color++; // Update color
40
41         // Wait for end of Vertical Blank
42         while (RIOT.timint == 0) {}
43         TIA.wsync = 0x00;
44         TIA.vblank = 0x00; // Turn on beam
45
46         // Display frame
47         RIOT.t1024t = KERNAL_T1024;
48         while (RIOT.timint == 0) {}
49         TIA.wsync = 0x00;
50         TIA.vblank = 0x02; // Turn off beam
51
52         // Overscan
53         RIOT.tim64t = OVERSCAN_TIM64;
54         while (RIOT.timint == 0) {}
55     }
56 }