aboutsummaryrefslogtreecommitdiff
path: root/src/splib.h
blob: 0fc4f1cdd75247ac67957f4eabae8f90e7c1b08a (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
   Kitsune's Curse
   Copyright (C) 2020-2023 Juan J. Martinez <jjm@usebox.net>

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
#ifndef _SPLIB_H
#define _SPLIB_H

#include <stdint.h>

// this is 160x160; 8x8 pixels tiles
#define TMW 20
#define TMH 20

#define TW 8
#define TH 8

// All the buffer must be under 0x8000
#define BUFF_ADDR 0x0100
// CONFIGURE **

#define SCREEN_ADDR(x, y) ((int)(0xc000 + x + ((y / 8) * 80) + ((y % 8) * 2048)))

#define DIRTY_BIT 0x8000
#define ADDR_BITS 0x7fff

struct st_tile
{
    uint16_t baddr;
    const uint8_t *t;
    uint16_t saddr;
    struct st_tile *n;
};

void init_tiles();
void update_screen();
void validate_screen();
void invalidate_screen();

struct st_tile *get_tile_xy(uint8_t x, uint8_t y);

void invalidate_tile(struct st_tile *st) __z88dk_fastcall;
uint8_t is_invalid_tile(struct st_tile *st) __z88dk_fastcall;
uint8_t is_invalid_tile2(struct st_tile *st) __z88dk_fastcall;

void erase_tile(struct st_tile *st) __z88dk_fastcall;
void link_buffer(struct st_tile *st) __z88dk_fastcall;
void link_buffer_xy(uint8_t x, uint8_t y);

void put_tile(const uint8_t *t, struct st_tile *st);
void put_sprite4(const uint8_t *s, uint8_t x, uint8_t y, uint8_t th, uint8_t inv);
void erase_sprite(uint8_t x, uint8_t y, uint8_t th);

void fill_screen(const uint8_t *t) __z88dk_fastcall;

// misc
void clear_screen();
void wait_vsync();
void set_hw_border(uint8_t c) __z88dk_fastcall;
void set_hw_ink(uint8_t ink, uint8_t c);
void pad_numbers(uint8_t *s, uint8_t limit, uint16_t number);
uint16_t screen_addr(uint16_t x, uint16_t y);

uint8_t abs_sub(uint8_t a, uint8_t b);

// require spfont, 63 chars (starting on 31)
void set_text_ink(uint8_t c, uint8_t c2, uint8_t c3);
void put_text(const char *s, uint8_t x, uint8_t y);

#endif // _SPLIB_H