git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit 10ed2e6f9d0bd341df376d666a24c6051ed1cd2e
parent d096d007857827172a8477f86e4de25bd5b4d228
Author: Toxa <untoxa@mail.ru>
Date:   Wed,  8 Sep 2021 21:55:20 +0300

SMS/GG: 1bpp tile data loading routines

Diffstat:
Mgbdk-lib/include/sms/sms.h15+++++++++++++++
Agbdk-lib/libc/targets/z80/color.s17+++++++++++++++++
Mgbdk-lib/libc/targets/z80/font.s13+------------
Mgbdk-lib/libc/targets/z80/gg/Makefile4++--
Mgbdk-lib/libc/targets/z80/memset_small.s2+-
Agbdk-lib/libc/targets/z80/set_1bpp_data.s111+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mgbdk-lib/libc/targets/z80/sms/Makefile4++--
7 files changed, 149 insertions(+), 17 deletions(-)

diff --git a/gbdk-lib/include/sms/sms.h b/gbdk-lib/include/sms/sms.h @@ -535,6 +535,21 @@ inline void set_sprite_2bpp_data(uint16_t start, uint16_t ntiles, const void *sr set_tile_2bpp_data((uint8_t)(start) + 0x100u, ntiles, src, _current_2bpp_palette); } +extern uint16_t _current_1bpp_colors; +inline void set_1bpp_colors(uint8_t fgcolor, uint8_t bgcolor) { + _current_1bpp_colors = ((uint16_t)fgcolor << 8) | bgcolor; +} +void set_tile_1bpp_data(uint16_t start, uint16_t ntiles, const void *src, uint16_t colors) __z88dk_callee __preserves_regs(iyh,iyl); +inline void set_bkg_1bpp_data(uint16_t start, uint16_t ntiles, const void *src) { + set_tile_1bpp_data(start, ntiles, src, _current_1bpp_colors); +} +#define set_bkg_1bit_data set_bkg_1bpp_data +inline void set_sprite_1bpp_data(uint16_t start, uint16_t ntiles, const void *src) { + set_tile_1bpp_data((uint8_t)(start) + 0x100u, ntiles, src, _current_1bpp_colors); +} +#define set_sprite_1bit_data set_sprite_1bpp_data + + /** Copies arbitrary data to an address in VRAM @param dst destination VRAM Address diff --git a/gbdk-lib/libc/targets/z80/color.s b/gbdk-lib/libc/targets/z80/color.s @@ -0,0 +1,17 @@ + .include "global.s" + + .title "Colors" + .module colors + + .area _INITIALIZED + +__current_1bpp_colors:: +.fg_colour:: + .ds 1 +.bg_colour:: + .ds 1 + + .area _INITIALIZER + + .db 0x03 ; .fg_colour + .db 0x00 ; .bg_color diff --git a/gbdk-lib/libc/targets/z80/font.s b/gbdk-lib/libc/targets/z80/font.s @@ -5,6 +5,7 @@ .globl .memset_small .globl _font_ibm + .globl .fg_colour, .bg_colour ; Structure offsets sfont_handle_sizeof = 3 @@ -41,18 +42,6 @@ plane2: plane3: .ds 1 - .area _INITIALIZED - ; The current font -.fg_colour:: - .ds 1 -.bg_colour:: - .ds 1 - - .area _INITIALIZER - - .db 0x03 ; .fg_colour - .db 0x00 ; .bg_color - .area _HOME ; void vmemcpy (unsigned int dst, const void *src, unsigned int size) __z88dk_callee __preserves_regs(iyh,iyl); diff --git a/gbdk-lib/libc/targets/z80/gg/Makefile b/gbdk-lib/libc/targets/z80/gg/Makefile @@ -10,7 +10,7 @@ CSRC = ASSRC = set_interrupts.s \ outi.s vmemcpy.s \ refresh_oam.s \ - set_data.s set_2bpp_data.s \ + set_data.s set_1bpp_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 \ coords_to_address.s \ @@ -18,7 +18,7 @@ ASSRC = set_interrupts.s \ fill_rect.s fill_rect_xy.s fill_rect_compat.s fill_rect_xy_compat.s \ metasprites.s metasprites_hide.s metasprites_hide_spr.s \ f_ibm_full.s f_ibm_sh.s f_italic.s f_min.s f_spect.s \ - font.s \ + font.s color.s \ putchar.s \ scroll.s cls.s gotoxy.s \ palette.s set_palette.s \ diff --git a/gbdk-lib/libc/targets/z80/memset_small.s b/gbdk-lib/libc/targets/z80/memset_small.s @@ -9,6 +9,6 @@ 1$: ld (hl), a inc hl - dec b + dec c jp nz, 1$ ret diff --git a/gbdk-lib/libc/targets/z80/set_1bpp_data.s b/gbdk-lib/libc/targets/z80/set_1bpp_data.s @@ -0,0 +1,111 @@ + .include "global.s" + + .title "VRAM utilities" + .module VRAMUtils + + .ez80 + + .area _HOME + +; void set_tile_1bpp_data(uint16_t start, uint16_t ntiles, const void *src, uint16_t colors) __z88dk_callee __preserves_regs(iyh,iyl); +_set_tile_1bpp_data:: + pop de ; pop ret address + pop hl + + add hl, hl + add hl, hl + add hl, hl + add hl, hl + add hl, hl + + ld bc, #.VDP_VRAM + add hl, bc + + DISABLE_VBLANK_COPY ; switch OFF copy shadow SAT + + SMS_WRITE_VDP_CMD h, l + + ex de, hl ; hl = ret + + pop bc ; bc = ntiles + pop de ; de = src + ex (sp), hl ; hl = palette + + ex de, hl + + inc b + inc c + push ix + + ld ixh, d + ld ixl, e ; ix == palette + + push iy + ld iy, #-4 + add iy, sp + ld sp, iy + push bc + jr 2$ + +1$: + ex (sp), hl + + ld d, #8 +6$: + ld c, (hl) + inc hl + + ld e, #8 +5$: + srl c + + jr c, 10$ + ld a, ixl + jr 11$ +10$: + ld a, ixh +11$: + rra + rr 0 (iy) + rra + rr 1 (iy) + rra + rr 2 (iy) + rra + rr 3 (iy) + + dec e + jr nz, 5$ + + ld a, 0 (iy) + out (.VDP_DATA), a + VDP_DELAY + ld a, 1 (iy) + out (.VDP_DATA), a + VDP_DELAY + ld a, 2 (iy) + out (.VDP_DATA), a + VDP_DELAY + ld a, 3 (iy) + out (.VDP_DATA), a + + dec d + jr nz, 6$ +2$: + ex (sp), hl + + dec l + jr nz, 1$ + + dec h + jr nz, 1$ + + ld iy, #6 + add iy, sp + ld sp, iy + pop iy + pop ix + + ENABLE_VBLANK_COPY ; switch ON copy shadow SAT + + ret diff --git a/gbdk-lib/libc/targets/z80/sms/Makefile b/gbdk-lib/libc/targets/z80/sms/Makefile @@ -10,7 +10,7 @@ CSRC = ASSRC = set_interrupts.s \ outi.s vmemcpy.s \ refresh_oam.s \ - set_data.s set_2bpp_data.s \ + set_data.s set_1bpp_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 \ coords_to_address.s \ @@ -18,7 +18,7 @@ ASSRC = set_interrupts.s \ fill_rect.s fill_rect_xy.s fill_rect_compat.s fill_rect_xy_compat.s \ metasprites.s metasprites_hide.s metasprites_hide_spr.s \ f_ibm_full.s f_ibm_sh.s f_italic.s f_min.s f_spect.s \ - font.s \ + font.s color.s \ putchar.s \ scroll.s cls.s gotoxy.s \ palette.s set_palette.s \

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.