libmsx
C library for MSX
Loading...
Searching...
No Matches
sm2.h
Go to the documentation of this file.
1// -*- coding: utf-8-unix -*-
2/*
3 * Copyright (c) 2021-2025 Daishi Mori (mori0091)
4 *
5 * This software is released under the MIT License.\n
6 * See https://github.com/mori0091/libmsx/blob/main/LICENSE
7 *
8 * GitHub libmsx project\n
9 * https://github.com/mori0091/libmsx
10 */
27#ifndef SM2_H_
28#define SM2_H_
29
30#include "sm2_cfg.h"
31
32#include <sprite.h>
33#include <sprite_color.h>
34
46#define sm2_Slice(T) \
47 struct { \
48 T * ptr; \
49 uint8_t len; \
50 }
51
52#define SM2_SLICE(a) {.ptr = (a), .len = sizeof(a)/sizeof((a)[0])}
53
57typedef struct sm2_Cel {
61 uint8_t depth;
66 uint32_t addr;
68
72typedef struct sm2_Frame {
74 size_t duration;
76 sm2_Slice(const uint8_t) cel_ids;
78
82typedef struct sm2_SpriteSheet {
84 sm2_Slice(const sm2_Frame) frames;
86 sm2_Slice(const sm2_Cel) cels;
88
98
102typedef struct sm2_FrameTag {
103 uint8_t from;
104 uint8_t to;
105 uint8_t direction;
106 size_t repeats;
108
120
135void sm2_init(void);
136
157void sm2_init_sprite(sm2_Sprite * s, const sm2_SpriteSheet * sheet, const sm2_FrameTag * tag);
158
174
190inline void sm2_update_sprites(sm2_Sprite ss[], size_t num) {
191 while (num--) {
193 ss++;
194 }
195}
196
215void sm2_flush(void);
216
231void sm2_add_sprite(const sm2_Sprite * s, int x, int y);
232
246void sm2_add_cel(const sm2_Cel * cel, int x, int y);
247
272void sm2_reserve(uint8_t n);
273
281uint8_t sm2_get_reserved(void);
282
299void sm2_put_sprite(uint8_t base_plane, const sm2_Sprite * s, int x, int y);
300
315void sm2_put_cel(uint8_t base_plane, const sm2_Cel * cel, int x, int y);
316
319#endif // SM2_H_
void sm2_update_sprites(sm2_Sprite ss[], size_t num)
MSX2 Update the animation state of a series of sprite objects.
Definition sm2.h:190
void sm2_update_sprite(sm2_Sprite *s)
MSX2 Update the animation state of sprite object.
void sm2_init_sprite(sm2_Sprite *s, const sm2_SpriteSheet *sheet, const sm2_FrameTag *tag)
MSX2 Construction and (re)initialization of the animated color sprite.
uint8_t direction
Animation direction.
Definition sm2.h:105
uint8_t curr_direction
Current animation direction; forward/reverse.
Definition sm2.h:116
uint8_t depth
Number of sprite planes required to display the sprite cel.
Definition sm2.h:61
size_t repeats
Number of repeats; 0 means inf.
Definition sm2.h:106
uint32_t addr
Base address of image data (pattern, color table, and layout information).
Definition sm2.h:66
const sm2_SpriteSheet * sheet
Sprite sheet.
Definition sm2.h:113
const sm2_FrameTag * tag
Current range of animation frames.
Definition sm2.h:114
uint8_t to
last frame number.
Definition sm2.h:104
uint8_t curr_frame
Index of current frame.
Definition sm2.h:115
size_t repeats
Repeat count; Number of loops finished.
Definition sm2.h:118
uint8_t from
1st frame number.
Definition sm2.h:103
size_t remaining_duration
Remaining duration of the current frame.
Definition sm2.h:117
SM2_Direction
Enumeration of animation direction.
Definition sm2.h:92
struct sm2_Sprite sm2_Sprite
Sprite - Animation state of a sprite.
struct sm2_Frame sm2_Frame
Frame - The frame of the sprite animation.
struct sm2_SpriteSheet sm2_SpriteSheet
SpriteSheet - Whole animation frames and cels of a sprite sheet.
struct sm2_Cel sm2_Cel
Cel - The image of the sprite animation layer.
struct sm2_FrameTag sm2_FrameTag
FrameTag - Definition of a range of animation frames.
@ SM2_PINGPONG_REVERSE
Definition sm2.h:96
@ SM2_REVERSE
Definition sm2.h:94
@ SM2_FORWARD
Definition sm2.h:93
@ SM2_PINGPONG
Definition sm2.h:95
Cel - The image of the sprite animation layer.
Definition sm2.h:57
FrameTag - Definition of a range of animation frames.
Definition sm2.h:102
Sprite - Animation state of a sprite.
Definition sm2.h:112
void sm2_add_sprite(const sm2_Sprite *s, int x, int y)
MSX2 Add the cels of the current frame of the sprite object to the internal buffer.
void sm2_reserve(uint8_t n)
MSX2 Reserves some sprite planes for direct access.
void sm2_put_sprite(uint8_t base_plane, const sm2_Sprite *s, int x, int y)
MSX2 Display the cels of the current frame of the sprite object.
uint8_t sm2_get_reserved(void)
MSX2 Returns the number of reserved sprite planes.
void sm2_flush(void)
MSX2 Display the sprite cels registered in the internal buffer.
void sm2_add_cel(const sm2_Cel *cel, int x, int y)
MSX2 Add a sprite cel to the internal buffer.
void sm2_put_cel(uint8_t base_plane, const sm2_Cel *cel, int x, int y)
MSX2 Display the sprite cel.
void sm2_init(void)
MSX2 Initialize SM2 module.
SM2 (Sprite Mode 2) Runtime configuration.
Sprites.
Sprite color table interface.
Frame - The frame of the sprite animation.
Definition sm2.h:72
sm2_Slice(const uint8_t) cel_ids
List of cel numbers for each layer.
size_t duration
Duration of animation frame in milliseconds.
Definition sm2.h:74
SpriteSheet - Whole animation frames and cels of a sprite sheet.
Definition sm2.h:82
sm2_Slice(const sm2_Frame) frames
List of animation frames.
sm2_Slice(const sm2_Cel) cels
List of whole cels.