File: atari2600hello.c

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (56 lines) | stat: -rw-r--r-- 1,922 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*****************************************************************************/
/*                                                                           */
/* Atari VCS 2600 sample C program                                           */
/*                                                                           */
/* Florent Flament (contact@florentflament.com), 2017                        */
/*                                                                           */
/*****************************************************************************/

#include <atari2600.h>

// PAL Timings
// Roughly computed based on Stella Programmer's guide (Steve Wright)
// scanlines count per section.
#define VBLANK_TIM64 51 // 45 lines * 76 cycles/line / 64 cycles/tick
#define KERNAL_T1024 17 // 228 lines * 76 cycles/line / 1024 cycles/tick
#define OVERSCAN_TIM64 42 // 36 lines * 76 cycles/line / 64 cycles/tick

// Testing memory zones
const unsigned char rodata_v[] = "Hello!";
unsigned char data_v = 0x77;
unsigned char bss_v;

void main(void) {
    unsigned char color = 0x79; // Stack variable
    bss_v = 0x88; // Testing BSS variable

    for/*ever*/(;;) {
        // Vertical Sync signal
        TIA.vsync = 0x02;
        TIA.wsync = 0x00;
        TIA.wsync = 0x00;
        TIA.wsync = 0x00;
        TIA.vsync = 0x00;

        // Vertical Blank timer setting
        RIOT.tim64t = VBLANK_TIM64;

        // Doing frame computation during blank
        TIA.colubk = color++; // Update color

        // Wait for end of Vertical Blank
        while (RIOT.timint == 0) {}
        TIA.wsync = 0x00;
        TIA.vblank = 0x00; // Turn on beam

        // Display frame
        RIOT.t1024t = KERNAL_T1024;
        while (RIOT.timint == 0) {}
        TIA.wsync = 0x00;
        TIA.vblank = 0x02; // Turn off beam

        // Overscan
        RIOT.tim64t = OVERSCAN_TIM64;
        while (RIOT.timint == 0) {}
    }
}