llvm-mos-sdk
config.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Adrian "asie" Siekierka
3  *
4  * Licensed under the Apache License, Version 2.0 with LLVM Exceptions,
5  * See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
6  * information.
7  */
8 
9 #ifndef _PCE_CONFIG_H_
10 #define _PCE_CONFIG_H_
11 
12 #include <stdbool.h>
13 #include <stdint.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
23 #define __PCE_RAM_BANK_DECLARE(id, offset, size) \
24  asm(".global __ram_bank" #id "\n.global __ram_bank" #id \
25  "_size\n.equ __ram_bank" #id ", ((" #offset \
26  ") << 13)\n.equ __ram_bank" #id "_size, ((" #size ") << 13)\n")
27 
28 #define __PCE_RAM_BANK_USE(id, offset) \
29  static inline void pce_ram_bank##id##_map(void) { \
30  __attribute__((leaf)) asm volatile("lda #__ram_bank" #id "_bank\n" \
31  "tam #(1 << " #offset ")\n" \
32  : \
33  : \
34  : "a", "p"); \
35  }
36 
37 #define __PCE_RAM_BANK_CALLBACK_DECLARE(id, offset) \
38  __attribute__(( \
39  leaf, callback(1), noinline, \
40  section("text.pce_ram_bank" #id \
41  "_call"))) void pce_ram_bank##id##_call(void (*method)(void)) { \
42  pce_bank##offset##_size1_push(); \
43  pce_ram_bank##id##_map(); \
44  method(); \
45  pce_bank##offset##_size1_pop(); \
46  }
47 
48 #define __PCE_RAM_BANK_CALLBACK_USE(id) \
49  __attribute__((leaf, callback(1))) void pce_ram_bank##id##_call( \
50  void (*method)(void))
51 
52 #ifdef PCE_CONFIG_IMPLEMENTATION
53 #define PCE_RAM_BANK_AT(id, offset) \
54  __PCE_RAM_BANK_DECLARE(id, offset, 1); \
55  __PCE_RAM_BANK_USE(id, offset) \
56  __PCE_RAM_BANK_CALLBACK_DECLARE(id, offset)
57 #define PCE_CDB_USE_PSG_DRIVER(value) \
58  asm(".global __pce_cdb_use_psg\n.equ __pce_cdb_use_psg, " #value "\n")
59 #define PCE_CDB_USE_GRAPHICS_DRIVER(value) \
60  asm(".global __pce_cdb_use_graphics\n.equ __pce_cdb_use_graphics, " #value \
61  "\n")
62 #else
63 
83 #define PCE_RAM_BANK_AT(id, offset) \
84  __PCE_RAM_BANK_USE(id, offset) \
85  __PCE_RAM_BANK_CALLBACK_USE(id)
86 
90 #define PCE_CDB_USE_PSG_DRIVER(value)
91 
95 #define PCE_CDB_USE_GRAPHICS_DRIVER(value)
96 #endif
97 
98 #ifdef __cplusplus
99 }
100 #endif
101 
102 #endif /* _PCE_CONFIG_H_ */