llvm-mos-sdk
bank.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_BANK_H_
10 #define _PCE_BANK_H_
11 
12 #include <stdbool.h>
13 #include <stdint.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
27 __attribute__((leaf)) uint8_t pce_bank0_get(void);
32 __attribute__((leaf)) void pce_bank0_set(uint8_t id);
37 __attribute__((leaf)) uint8_t pce_bank1_get(void);
42 __attribute__((leaf)) void pce_bank1_set(uint8_t id);
47 __attribute__((leaf)) uint8_t pce_bank2_get(void);
52 __attribute__((leaf)) void pce_bank2_set(uint8_t id);
57 __attribute__((leaf)) uint8_t pce_bank3_get(void);
62 __attribute__((leaf)) void pce_bank3_set(uint8_t id);
67 __attribute__((leaf)) uint8_t pce_bank4_get(void);
72 __attribute__((leaf)) void pce_bank4_set(uint8_t id);
77 __attribute__((leaf)) uint8_t pce_bank5_get(void);
82 __attribute__((leaf)) void pce_bank5_set(uint8_t id);
87 __attribute__((leaf)) uint8_t pce_bank6_get(void);
92 __attribute__((leaf)) void pce_bank6_set(uint8_t id);
97 __attribute__((leaf)) uint8_t pce_bank7_get(void);
102 __attribute__((leaf)) void pce_bank7_set(uint8_t id);
107 __attribute__((leaf)) void pce_bank23i_set(uint8_t id);
112 __attribute__((leaf)) void pce_bank234i_set(uint8_t id);
117 __attribute__((leaf)) void pce_bank2345i_set(uint8_t id);
122 __attribute__((leaf)) void pce_bank23456i_set(uint8_t id);
127 __attribute__((leaf)) void pce_bank34i_set(uint8_t id);
132 __attribute__((leaf)) void pce_bank345i_set(uint8_t id);
137 __attribute__((leaf)) void pce_bank3456i_set(uint8_t id);
142 __attribute__((leaf)) void pce_bank45i_set(uint8_t id);
147 __attribute__((leaf)) void pce_bank456i_set(uint8_t id);
152 __attribute__((leaf)) void pce_bank56i_set(uint8_t id);
153 
154 static inline void pce_bank2_size1_push(void) {
155  __attribute__((leaf)) asm volatile("tma #$04\n"
156  "pha\n"
157  ""
158  :
159  :
160  : "a");
161 }
162 
163 static inline void pce_bank2_size1_pop(void) {
164  __attribute__((leaf)) asm volatile("pla\n"
165  "tam #$04\n"
166  ""
167  :
168  :
169  : "a");
170 }
171 
172 static inline void pce_bank2_size2_push(void) {
173  __attribute__((leaf)) asm volatile("tma #$04\n"
174  "pha\n"
175  "tma #$08\n"
176  "pha\n"
177  ""
178  :
179  :
180  : "a");
181 }
182 
183 static inline void pce_bank2_size2_pop(void) {
184  __attribute__((leaf)) asm volatile("pla\n"
185  "tam #$08\n"
186  "pla\n"
187  "tam #$04\n"
188  ""
189  :
190  :
191  : "a");
192 }
193 
194 static inline void pce_bank2_size3_push(void) {
195  __attribute__((leaf)) asm volatile("tma #$04\n"
196  "pha\n"
197  "tma #$08\n"
198  "pha\n"
199  "tma #$10\n"
200  "pha\n"
201  ""
202  :
203  :
204  : "a");
205 }
206 
207 static inline void pce_bank2_size3_pop(void) {
208  __attribute__((leaf)) asm volatile("pla\n"
209  "tam #$10\n"
210  "pla\n"
211  "tam #$08\n"
212  "pla\n"
213  "tam #$04\n"
214  ""
215  :
216  :
217  : "a");
218 }
219 
220 static inline void pce_bank2_size4_push(void) {
221  __attribute__((leaf)) asm volatile("tma #$04\n"
222  "pha\n"
223  "tma #$08\n"
224  "pha\n"
225  "tma #$10\n"
226  "pha\n"
227  "tma #$20\n"
228  "pha\n"
229  ""
230  :
231  :
232  : "a");
233 }
234 
235 static inline void pce_bank2_size4_pop(void) {
236  __attribute__((leaf)) asm volatile("pla\n"
237  "tam #$20\n"
238  "pla\n"
239  "tam #$10\n"
240  "pla\n"
241  "tam #$08\n"
242  "pla\n"
243  "tam #$04\n"
244  ""
245  :
246  :
247  : "a");
248 }
249 
250 static inline void pce_bank2_size5_push(void) {
251  __attribute__((leaf)) asm volatile("tma #$04\n"
252  "pha\n"
253  "tma #$08\n"
254  "pha\n"
255  "tma #$10\n"
256  "pha\n"
257  "tma #$20\n"
258  "pha\n"
259  "tma #$40\n"
260  "pha\n"
261  ""
262  :
263  :
264  : "a");
265 }
266 
267 static inline void pce_bank2_size5_pop(void) {
268  __attribute__((leaf)) asm volatile("pla\n"
269  "tam #$40\n"
270  "pla\n"
271  "tam #$20\n"
272  "pla\n"
273  "tam #$10\n"
274  "pla\n"
275  "tam #$08\n"
276  "pla\n"
277  "tam #$04\n"
278  ""
279  :
280  :
281  : "a");
282 }
283 
284 static inline void pce_bank3_size1_push(void) {
285  __attribute__((leaf)) asm volatile("tma #$08\n"
286  "pha\n"
287  ""
288  :
289  :
290  : "a");
291 }
292 
293 static inline void pce_bank3_size1_pop(void) {
294  __attribute__((leaf)) asm volatile("pla\n"
295  "tam #$08\n"
296  ""
297  :
298  :
299  : "a");
300 }
301 
302 static inline void pce_bank3_size2_push(void) {
303  __attribute__((leaf)) asm volatile("tma #$08\n"
304  "pha\n"
305  "tma #$10\n"
306  "pha\n"
307  ""
308  :
309  :
310  : "a");
311 }
312 
313 static inline void pce_bank3_size2_pop(void) {
314  __attribute__((leaf)) asm volatile("pla\n"
315  "tam #$10\n"
316  "pla\n"
317  "tam #$08\n"
318  ""
319  :
320  :
321  : "a");
322 }
323 
324 static inline void pce_bank3_size3_push(void) {
325  __attribute__((leaf)) asm volatile("tma #$08\n"
326  "pha\n"
327  "tma #$10\n"
328  "pha\n"
329  "tma #$20\n"
330  "pha\n"
331  ""
332  :
333  :
334  : "a");
335 }
336 
337 static inline void pce_bank3_size3_pop(void) {
338  __attribute__((leaf)) asm volatile("pla\n"
339  "tam #$20\n"
340  "pla\n"
341  "tam #$10\n"
342  "pla\n"
343  "tam #$08\n"
344  ""
345  :
346  :
347  : "a");
348 }
349 
350 static inline void pce_bank3_size4_push(void) {
351  __attribute__((leaf)) asm volatile("tma #$08\n"
352  "pha\n"
353  "tma #$10\n"
354  "pha\n"
355  "tma #$20\n"
356  "pha\n"
357  "tma #$40\n"
358  "pha\n"
359  ""
360  :
361  :
362  : "a");
363 }
364 
365 static inline void pce_bank3_size4_pop(void) {
366  __attribute__((leaf)) asm volatile("pla\n"
367  "tam #$40\n"
368  "pla\n"
369  "tam #$20\n"
370  "pla\n"
371  "tam #$10\n"
372  "pla\n"
373  "tam #$08\n"
374  ""
375  :
376  :
377  : "a");
378 }
379 
380 static inline void pce_bank4_size1_push(void) {
381  __attribute__((leaf)) asm volatile("tma #$10\n"
382  "pha\n"
383  ""
384  :
385  :
386  : "a");
387 }
388 
389 static inline void pce_bank4_size1_pop(void) {
390  __attribute__((leaf)) asm volatile("pla\n"
391  "tam #$10\n"
392  ""
393  :
394  :
395  : "a");
396 }
397 
398 static inline void pce_bank4_size2_push(void) {
399  __attribute__((leaf)) asm volatile("tma #$10\n"
400  "pha\n"
401  "tma #$20\n"
402  "pha\n"
403  ""
404  :
405  :
406  : "a");
407 }
408 
409 static inline void pce_bank4_size2_pop(void) {
410  __attribute__((leaf)) asm volatile("pla\n"
411  "tam #$20\n"
412  "pla\n"
413  "tam #$10\n"
414  ""
415  :
416  :
417  : "a");
418 }
419 
420 static inline void pce_bank4_size3_push(void) {
421  __attribute__((leaf)) asm volatile("tma #$10\n"
422  "pha\n"
423  "tma #$20\n"
424  "pha\n"
425  "tma #$40\n"
426  "pha\n"
427  ""
428  :
429  :
430  : "a");
431 }
432 
433 static inline void pce_bank4_size3_pop(void) {
434  __attribute__((leaf)) asm volatile("pla\n"
435  "tam #$40\n"
436  "pla\n"
437  "tam #$20\n"
438  "pla\n"
439  "tam #$10\n"
440  ""
441  :
442  :
443  : "a");
444 }
445 
446 static inline void pce_bank5_size1_push(void) {
447  __attribute__((leaf)) asm volatile("tma #$20\n"
448  "pha\n"
449  ""
450  :
451  :
452  : "a");
453 }
454 
455 static inline void pce_bank5_size1_pop(void) {
456  __attribute__((leaf)) asm volatile("pla\n"
457  "tam #$20\n"
458  ""
459  :
460  :
461  : "a");
462 }
463 
464 static inline void pce_bank5_size2_push(void) {
465  __attribute__((leaf)) asm volatile("tma #$20\n"
466  "pha\n"
467  "tma #$40\n"
468  "pha\n"
469  ""
470  :
471  :
472  : "a");
473 }
474 
475 static inline void pce_bank5_size2_pop(void) {
476  __attribute__((leaf)) asm volatile("pla\n"
477  "tam #$40\n"
478  "pla\n"
479  "tam #$20\n"
480  ""
481  :
482  :
483  : "a");
484 }
485 
486 static inline void pce_bank6_size1_push(void) {
487  __attribute__((leaf)) asm volatile("tma #$40\n"
488  "pha\n"
489  ""
490  :
491  :
492  : "a");
493 }
494 
495 static inline void pce_bank6_size1_pop(void) {
496  __attribute__((leaf)) asm volatile("pla\n"
497  "tam #$40\n"
498  ""
499  :
500  :
501  : "a");
502 }
503 
504 #define PCE_BANK_MASK(n) (1 << (n))
505 #define PCE_BANK_OFFSET(n) ((n) << 13)
506 #define PCE_BANK_SIZE(n) ((n) << 13)
507 
508 #ifdef __cplusplus
509 }
510 #endif
511 
512 #endif /* _PCE_BANK_H_ */
std::uint8_t
::uint8_t uint8_t
Definition: cstdint:21