llvm-mos-sdk
atari2600-common
vcslib.h
Go to the documentation of this file.
1
// Copyright 2023 LLVM-MOS Project
2
// Licensed under the Apache License, Version 2.0 with LLVM Exceptions.
3
// See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
4
// information.
5
6
#ifndef _VCSLIB_H
7
#define _VCSLIB_H
8
9
#include <
atari2600.h
>
10
#include <stdint.h>
11
12
#if defined(__ATARI2600_MAPPER__)
13
#include <mapper.h>
14
#endif
15
16
// Define data types for different data sizes and signedness
17
18
typedef
unsigned
char
byte
;
// 8-bit unsigned data type
19
typedef
signed
char
sbyte
;
// 8-bit signed data type
20
typedef
unsigned
short
word
;
// 16-bit unsigned data type
21
22
// Atari 2600 kernel helpers, called in a sequence every frame
23
24
void
kernel_1
(
void
);
// before preframe
25
void
kernel_2
(
void
);
// before kernel
26
void
kernel_3
(
void
);
// after kernel
27
void
kernel_4
(
void
);
// after postframe
28
29
// Function to set horizontal position of a game object.
30
31
typedef
enum
{
PLAYER_0
=0,
PLAYER_1
,
MISSILE_0
,
MISSILE_1
,
BALL
}
TIAObject
;
32
33
// A = X coordinate
34
// X = object index
35
__attribute__((leaf))
void
_set_horiz_pos(
byte
xpos,
byte
objindex
);
36
37
// swap order of call
38
#define set_horiz_pos(objindex,xpos) _set_horiz_pos(xpos,objindex)
39
40
// Waits for next scanline start
41
#define do_wsync() \
42
__attribute__((leaf)) asm volatile("sta $42 /* WSYNC */"
);
43
44
// Applies horizontal motion to sprite(s) after set_horiz_pos()
45
#define apply_hmove() \
46
__attribute__((leaf)) asm volatile("sta $42 /* WSYNC */"
"\n" "sta $6a /* HMOVE */");
47
48
// Macros
49
50
#define P0 0
51
#define P1 1
52
#define M0 2
53
#define M1 3
54
#define BALL 4
55
56
#define SW_RESET() ((RIOT.swchb & RESET_MASK) == 0)
57
#define SW_SELECT() ((RIOT.swchb & SELECT_MASK) == 0)
58
#define SW_COLOR() ((RIOT.swchb & BW_MASK) != 0)
59
#define SW_P0_PRO() ((RIOT.swchb & P0_DIFF_MASK) != 0)
60
#define SW_P1_PRO() ((RIOT.swchb & P1_DIFF_MASK) != 0)
61
62
#define JOY_UP(plyr) (!(RIOT.swcha & ((plyr) ? 0x1 : ~MOVE_UP)))
63
#define JOY_DOWN(plyr) (!(RIOT.swcha & ((plyr) ? 0x2 : ~MOVE_DOWN)))
64
#define JOY_LEFT(plyr) (!(RIOT.swcha & ((plyr) ? 0x4 : ~MOVE_LEFT)))
65
#define JOY_RIGHT(plyr) (!(RIOT.swcha & ((plyr) ? 0x8 : ~MOVE_RIGHT)))
66
#define JOY_FIRE(plyr) !(((plyr) ? TIA.inpt5 : TIA.inpt4) & 0x80)
67
68
// make color greyscale if black and white switch is set
69
#define COLOR_CONV(color) (SW_COLOR() ? color : color & 0x0f)
70
71
// macros for setting PIA timers
72
#define _CYCLES(lines) (((lines) * 76) - 13)
73
#define _TIM64(cycles) (((cycles) >> 6) - (((cycles) & 63) < 12))
74
#define _T1024(cycles) ((cycles) >> 10)
75
76
#ifdef PAL
77
#define VBLANK_TIM64 _TIM64(_CYCLES(45))
78
#define KERNAL_T1024 _T1024(_CYCLES(250))
79
#define OVERSCAN_TIM64 _TIM64(_CYCLES(36))
80
#else
81
#define VBLANK_TIM64 _TIM64(_CYCLES(37))
82
#define KERNAL_TIM64 _TIM64(_CYCLES(194))
83
#define OVERSCAN_TIM64 _TIM64(_CYCLES(32))
84
#endif
85
86
#endif
atari2600.h
objindex
byte objindex
Definition:
vcslib.h:35
byte
unsigned char byte
Definition:
vcslib.h:18
word
unsigned short word
Definition:
vcslib.h:20
kernel_4
void kernel_4(void)
BALL
#define BALL
Definition:
vcslib.h:54
kernel_2
void kernel_2(void)
kernel_3
void kernel_3(void)
kernel_1
void kernel_1(void)
TIAObject
TIAObject
Definition:
vcslib.h:31
PLAYER_0
@ PLAYER_0
Definition:
vcslib.h:31
MISSILE_0
@ MISSILE_0
Definition:
vcslib.h:31
PLAYER_1
@ PLAYER_1
Definition:
vcslib.h:31
MISSILE_1
@ MISSILE_1
Definition:
vcslib.h:31
sbyte
signed char sbyte
Definition:
vcslib.h:19
Generated by
1.9.1