gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 08bc5591e12b98c11c3e6b7d5907f72564893bd6 parent 82c9a3dd9a4461b83f8a2c910f30de9b869ff49b Author: Toxa <untoxa@mail.ru> Date: Sun, 29 Aug 2021 00:01:35 +0300 SMS/GG: set_interrupts() and cross-platform scroller example Diffstat:
| M | gbdk-lib/examples/cross-platform/scroller/src/text_scroller.c | 39 | +++++++++++++++++++++++++++++++++++++-- |
| M | gbdk-lib/include/sms/sms.h | 56 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | gbdk-lib/libc/targets/z80/gg/Makefile | 5 | +++-- |
| M | gbdk-lib/libc/targets/z80/gg/global.s | 5 | +++++ |
| A | gbdk-lib/libc/targets/z80/set_interrupts.s | 46 | ++++++++++++++++++++++++++++++++++++++++++++++ |
| M | gbdk-lib/libc/targets/z80/sms/Makefile | 5 | +++-- |
| M | gbdk-lib/libc/targets/z80/sms/global.s | 5 | +++++ |
7 files changed, 155 insertions(+), 6 deletions(-)
diff --git a/gbdk-lib/examples/cross-platform/scroller/src/text_scroller.c b/gbdk-lib/examples/cross-platform/scroller/src/text_scroller.c @@ -6,9 +6,34 @@ const uint8_t scanline_offsets_tbl[] = {0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2 const uint8_t * scanline_offsets = scanline_offsets_tbl; #define SCROLL_POS 15 +#define SCROLL_POS_PIX_START ((SCROLL_POS + DEVICE_SCREEN_Y_OFFSET) * 8) - 1 +#define SCROLL_POS_PIX_END ((SCROLL_POS + DEVICE_SCREEN_X_OFFSET + 1) * 8) - 1 uint8_t scroller_x = 0; void scanline_isr() { +#if defined(__TARGET_gb) || defined(__TARGET_ap) + switch (LYC_REG) { + case 0: + SCX_REG = 0; + LYC_REG = SCROLL_POS_PIX_START; + break; + case SCROLL_POS_PIX_START: + SCX_REG = scroller_x; + LYC_REG = SCROLL_POS_PIX_END; + break; + case SCROLL_POS_PIX_END: + SCX_REG = LYC_REG = 0; + break; + } +#elif defined(__TARGET_sms) || defined(__TARGET_gg) + if (VCOUNTER == (SCROLL_POS_PIX_START - 8)) { + while (VCOUNTER != SCROLL_POS_PIX_START); + VDP_CMD = -scroller_x; VDP_CMD = VDP_RSCX; + while (VCOUNTER != SCROLL_POS_PIX_START + 8); + } else { + VDP_CMD = 0; VDP_CMD = VDP_RSCX; + } +#endif } const uint8_t scroller_text[] = "This is a text scroller demo for GBDK-2020. You can use ideas, that are "\ @@ -21,7 +46,18 @@ uint8_t * scroller_vram_addr; uint8_t * base, * limit; void main() { - printf("Scrolling %d chars", sizeof(scroller_text) - 1); + printf(" Scrolling %d chars", sizeof(scroller_text) - 1); + + CRITICAL { + add_LCD(scanline_isr); +#if defined(__TARGET_gb) || defined(__TARGET_ap) + STAT_REG |= STATF_LYC; LYC_REG = 0; +#endif + } +#if defined(__TARGET_sms) || defined(__TARGET_gg) + __WRITE_VDP_REG(VDP_R10, 0x07); +#endif + set_interrupts(VBL_IFLAG | LCD_IFLAG); HIDE_LEFT_COLUMN; base = (uint8_t *)((uint16_t)get_bkg_xy_addr(0, SCROLL_POS) & (DEVICE_SCREEN_MAP_ENTRY_SIZE==1?0xffe0:0xffc0)); @@ -34,7 +70,6 @@ void main() { while (1) { scroller_x++; - move_bkg(scroller_x, 0); if ((scroller_x & 0x07) == 0) { // next letter scroller_next_char++; diff --git a/gbdk-lib/include/sms/sms.h b/gbdk-lib/include/sms/sms.h @@ -72,6 +72,62 @@ void mode(uint8_t m) NONBANKED; */ uint8_t get_mode(void) NONBANKED; +/* Interrupt flags */ +/** Disable calling of interrupt service routines + */ +#define EMPTY_IFLAG 0x00U +/** VBlank Interrupt occurs at the start of the vertical blank. + + During this period the video ram may be freely accessed. + @see set_interrupts(), @see add_VBL + */ +#define VBL_IFLAG 0x01U +/** LCD Interrupt when triggered by the STAT register. + @see set_interrupts(), @see add_LCD +*/ +#define LCD_IFLAG 0x02U +/** Does nothing on SMS/GG + */ +#define TIM_IFLAG 0x04U +/** Does nothing on SMS/GG + */ +#define SIO_IFLAG 0x08U +/** Does nothing on SMS/GG + */ +#define JOY_IFLAG 0x10U + +void set_interrupts(uint8_t flags) __z88dk_fastcall; + +/* Limits */ +#if defined(__TARGET_sms) +/** Width of the visible screen in pixels. + */ +#define SCREENWIDTH 256U +/** Height of the visible screen in pixels. + */ +#define SCREENHEIGHT 192U +#elif defined(__TARGET_gg) +/** Width of the visible screen in pixels. + */ +#define SCREENWIDTH 160U +/** Height of the visible screen in pixels. + */ +#define SCREENHEIGHT 144U +#endif +/** The Minimum X position of the Window Layer (Left edge of screen) @see move_win() + */ +#define MINWNDPOSX 0x00U +/** The Minimum Y position of the Window Layer (Top edge of screen) @see move_win() + */ +#define MINWNDPOSY 0x00U +/** The Maximum X position of the Window Layer (Right edge of screen) @see move_win() + */ +#define MAXWNDPOSX 0x00U +/** The Maximum Y position of the Window Layer (Bottom edge of screen) @see move_win() + */ +#define MAXWNDPOSY 0x00U + + /** Interrupt handlers */ typedef void (*int_handler)(void) NONBANKED; diff --git a/gbdk-lib/libc/targets/z80/gg/Makefile b/gbdk-lib/libc/targets/z80/gg/Makefile @@ -5,9 +5,10 @@ TOPDIR = ../../../.. THIS = gg PORT = z80 -CSRC = +CSRC = -ASSRC = outi.s vmemcpy.s \ +ASSRC = set_interrupts.s \ + outi.s vmemcpy.s \ set_data.s set_2bpp_data.s \ set_tile_map.s set_tile_map_xy.s set_tile_map_compat.s set_tile_map_xy_compat.s \ set_tile_submap.s set_tile_submap_compat.s \ diff --git a/gbdk-lib/libc/targets/z80/gg/global.s b/gbdk-lib/libc/targets/z80/gg/global.s @@ -177,6 +177,11 @@ .VDP_MAP_HEIGHT = 28 .VDP_MAP_WIDTH = 32 + ;; Interrupt flags + + .VBL_IFLAG = 0x01 + .LCD_IFLAG = 0x02 + ; characters .CR = 0x0A .SPACE = 0x00 diff --git a/gbdk-lib/libc/targets/z80/set_interrupts.s b/gbdk-lib/libc/targets/z80/set_interrupts.s @@ -0,0 +1,46 @@ + .include "global.s" + + .title "Set interrupts" + .module SetInterrupts + + .globl _shadow_VDP_R0 + .globl _shadow_VDP_R1 + + .area _HOME + +_set_interrupts:: + ld a, i + di + push af + + ld a, (_shadow_VDP_R1) + bit 0, l + jr z, 1$ + or #.R1_IE + jr 2$ +1$: + and #~.R1_IE +2$: + ld (_shadow_VDP_R1), a + out (.VDP_CMD), a + ld a, #.VDP_R1 + out (.VDP_CMD), a + + ld a, (_shadow_VDP_R0) + bit 1, l + jr z, 3$ + or #.R0_IE1 + jr 4$ +3$: + and #~.R0_IE1 +4$: + ld (_shadow_VDP_R0), a + out (.VDP_CMD), a + ld a, #.VDP_R0 + out (.VDP_CMD), a + + pop af + jp po, 5$ + ei +5$: + ret diff --git a/gbdk-lib/libc/targets/z80/sms/Makefile b/gbdk-lib/libc/targets/z80/sms/Makefile @@ -5,9 +5,10 @@ TOPDIR = ../../../.. THIS = sms PORT = z80 -CSRC = +CSRC = -ASSRC = outi.s vmemcpy.s \ +ASSRC = set_interrupts.s \ + outi.s vmemcpy.s \ set_data.s set_2bpp_data.s \ set_tile_map.s set_tile_map_xy.s set_tile_map_compat.s set_tile_map_xy_compat.s \ set_tile_submap.s set_tile_submap_compat.s \ diff --git a/gbdk-lib/libc/targets/z80/sms/global.s b/gbdk-lib/libc/targets/z80/sms/global.s @@ -177,6 +177,11 @@ .VDP_MAP_HEIGHT = 28 .VDP_MAP_WIDTH = 32 + ;; Interrupt flags + + .VBL_IFLAG = 0x01 + .LCD_IFLAG = 0x02 + ; characters .CR = 0x0A .SPACE = 0x00
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.