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 */
28#ifndef SM2_H_
29#define SM2_H_
30
31#include "sm2_cfg.h"
32
33#include <sprite.h>
34#include <sprite_color.h>
35
47#define sm2_Slice(T) \
48 struct { \
49 T * ptr; \
50 uint8_t len; \
51 }
52
53#define SM2_SLICE(a) {.ptr = (a), .len = sizeof(a)/sizeof((a)[0])}
54
58typedef struct sm2_Cel {
62 uint8_t depth;
67 uint32_t addr;
69
73typedef struct sm2_Frame {
75 size_t duration;
77 sm2_Slice(const uint8_t) cel_ids;
79
89
99
103typedef struct sm2_FrameTag {
104 uint8_t from;
105 uint8_t to;
106 uint8_t direction;
107 size_t repeat;
109
121
136void sm2_init(void);
137
158void sm2_init_sprite(sm2_Sprite * s, const sm2_SpriteSheet * sheet, const sm2_FrameTag * tag);
159
175
191inline void sm2_update_sprites(sm2_Sprite ss[], size_t num) {
192 while (num--) {
194 ss++;
195 }
196}
197
216void sm2_flush(void);
217
232void sm2_add_sprite(const sm2_Sprite * s, int x, int y);
233
247void sm2_add_cel(const sm2_Cel * cel, int x, int y);
248
273void sm2_reserve(uint8_t n);
274
282uint8_t sm2_get_reserved(void);
283
300void sm2_put_sprite(uint8_t base_plane, const sm2_Sprite * s, int x, int y);
301
316void sm2_put_cel(uint8_t base_plane, const sm2_Cel * cel, int x, int y);
317
320#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:191
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:106
uint8_t curr_direction
Current animation direction; forward/reverse.
Definition sm2.h:117
size_t repeat
Repeat count; Number of loops finished.
Definition sm2.h:119
uint8_t depth
Number of sprite planes required to display the sprite cel.
Definition sm2.h:62
struct sm2_SpriteSheet::@2 cels
List of whole cels.
struct sm2_SpriteSheet::@1 frames
List of animation frames.
uint32_t addr
Base address of image data (pattern, color table, and layout information).
Definition sm2.h:67
const sm2_SpriteSheet * sheet
Sprite sheet.
Definition sm2.h:114
const sm2_FrameTag * tag
Current range of animation frames.
Definition sm2.h:115
uint8_t to
last frame number.
Definition sm2.h:105
size_t repeat
Number of repeats; 0 means inf.
Definition sm2.h:107
uint8_t curr_frame
Index of current frame.
Definition sm2.h:116
size_t duration
Duration of animation frame in milliseconds.
Definition sm2.h:75
struct sm2_Frame::@0 cel_ids
List of cel numbers for each layer.
uint8_t from
1st frame number.
Definition sm2.h:104
size_t remaining_duration
Remaining duration of the current frame.
Definition sm2.h:118
SM2_Direction
Enumeration of animation direction.
Definition sm2.h:93
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.
#define sm2_Slice(T)
Macro for defining anonymous slice type of array.
Definition sm2.h:47
@ SM2_PINGPONG_REVERSE
Definition sm2.h:97
@ SM2_REVERSE
Definition sm2.h:95
@ SM2_FORWARD
Definition sm2.h:94
@ SM2_PINGPONG
Definition sm2.h:96
Cel - The image of the sprite animation layer.
Definition sm2.h:58
Frame - The frame of the sprite animation.
Definition sm2.h:73
FrameTag - Definition of a range of animation frames.
Definition sm2.h:103
Sprite - Animation state of a sprite.
Definition sm2.h:113
SpriteSheet - Whole animation frames and cels of a sprite sheet.
Definition sm2.h:83
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.