git.y1.nz

gbdk-2020

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

commit f220abc6c6e78175f2fc156895abbdb527ead81e
parent bbf636cadb7c30dbf110393b0c8962428eb40186
Author: Toxa <untoxa@mail.ru>
Date:   Fri, 27 Aug 2021 15:39:06 +0300

SMS/GG: get_bkg_xy_addr()

Diffstat:
Mgbdk-lib/include/gb/gb.h8++++++++
Mgbdk-lib/include/gb/hardware.h8++++++++
Mgbdk-lib/include/sms/hardware.h20++++++++++++++++++++
Mgbdk-lib/include/sms/sms.h14++++++++++----
Agbdk-lib/libc/targets/z80/coords_to_address.s48++++++++++++++++++++++++++++++++++++++++++++++++
Mgbdk-lib/libc/targets/z80/gg/Makefile1+
Mgbdk-lib/libc/targets/z80/set_tile.s34+++++-----------------------------
Mgbdk-lib/libc/targets/z80/sms/Makefile1+
8 files changed, 101 insertions(+), 33 deletions(-)

diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -650,6 +650,14 @@ void hiramcpy(uint8_t dst, #define DISPLAY_OFF \ display_off(); +/** Does nothing for GB + */ +#define HIDE_LEFT_COLUMN + +/** Does nothing for GB + */ +#define SHOW_LEFT_COLUMN + /** Turns on the background layer. Sets bit 0 of the LCDC register to 1. */ diff --git a/gbdk-lib/include/gb/hardware.h b/gbdk-lib/include/gb/hardware.h @@ -361,4 +361,12 @@ __REG IE_REG; /** Interrupt enable */ #define OAMF_PALMASK 0b00000111 +#define DEVICE_SCREEN_X_OFFSET 0 +#define DEVICE_SCREEN_Y_OFFSET 0 +#define DEVICE_SCREEN_WIDTH 20 +#define DEVICE_SCREEN_HEIGHT 18 +#define DEVICE_SCREEN_BUFFER_WIDTH 32 +#define DEVICE_SCREEN_BUFFER_HEIGHT 32 +#define DEVICE_SCREEN_MAP_ENTRY_SIZE 1 + #endif diff --git a/gbdk-lib/include/sms/hardware.h b/gbdk-lib/include/sms/hardware.h @@ -176,4 +176,24 @@ extern volatile UBYTE VDP_ATTR_SHIFT; #define VDP_SAT_TERM 0xD0 +#if defined(__TARGET_sms) +#define DEVICE_SCREEN_X_OFFSET 0 +#define DEVICE_SCREEN_Y_OFFSET 0 +#define DEVICE_SCREEN_WIDTH 32 +#define DEVICE_SCREEN_HEIGHT 28 +#define DEVICE_SCREEN_BUFFER_WIDTH 32 +#define DEVICE_SCREEN_BUFFER_HEIGHT 28 +#define DEVICE_SCREEN_MAP_ENTRY_SIZE 2 +#elif defined(__TARGET_gg) +#define DEVICE_SCREEN_X_OFFSET 6 +#define DEVICE_SCREEN_Y_OFFSET 3 +#define DEVICE_SCREEN_WIDTH 20 +#define DEVICE_SCREEN_HEIGHT 18 +#define DEVICE_SCREEN_BUFFER_WIDTH 32 +#define DEVICE_SCREEN_BUFFER_HEIGHT 28 +#define DEVICE_SCREEN_MAP_ENTRY_SIZE 2 +#else +#error Unrecognized port +#endif + #endif diff --git a/gbdk-lib/include/sms/sms.h b/gbdk-lib/include/sms/sms.h @@ -326,16 +326,16 @@ uint8_t joypad_init(uint8_t npads, joypads_t * joypads) __z88dk_callee; void joypad_ex(joypads_t * joypads) __z88dk_fastcall __preserves_regs(iyh, iyl); -#ifdef __TARGET_sms +#if defined(__TARGET_sms) #define RGB(r,g,b) ((r)|((g)<<2)|((b)<<4)) #define RGB8(r,g,b) (((r)>>6)|(((g)>>6)<<2)|(((b)>>6)<<4)) #define RGBHTML(RGB24bit) (((RGB24bit)>>22)|((((RGB24bit)&0xFFFF)>>14)<<2)|((((RGB24bit)&0xFF)>>6)<<4)) -#else -#ifdef __TARGET_gg +#elif defined(__TARGET_gg) #define RGB(r,g,b) ((r)|((g)<<4)|((b)<<8)) #define RGB8(r,g,b) (((r)>>4)|(((g)>>4)<<4)|(((b)>>4)<<8)) #define RGBHTML(RGB24bit) (((RGB24bit)>>20)|((((RGB24bit)&0xFFFF)>>12)<<4)|((((RGB24bit)&0xFF)>>4)<<8)) -#endif +#else +#error Unrecognized port #endif inline void cgb_compatibility() {} @@ -539,4 +539,10 @@ uint8_t * set_tile_xy(uint8_t x, uint8_t y, uint8_t t) __z88dk_callee __preserve #define set_bkg_tile_xy set_tile_xy #define set_win_tile_xy set_tile_xy +/** + * Get address of X,Y tile of background map + */ +uint8_t * get_bkg_xy_addr(uint8_t x, uint8_t y) __z88dk_callee __preserves_regs(iyh, iyl); +#define get_win_xy_addr get_bkg_xy_addr + #endif /* _SMS_H */ diff --git a/gbdk-lib/libc/targets/z80/coords_to_address.s b/gbdk-lib/libc/targets/z80/coords_to_address.s @@ -0,0 +1,47 @@ + .include "global.s" + + .title "VRAM utilities" + .module VRAMUtils + + .area _HOME + +; translate coords in DE and given base in BC into address in DE +.coords_to_address:: + ld a, d + add #.SCREEN_Y_OFS + ld d, a + xor a + FAST_MOD8 d #28 + ld d, a + + ld a, e + add #.SCREEN_X_OFS + and #0x1f + ld e, a + + ld a, d + rrca ; rrca(2) == rlca(6) + rrca + ld d, a + and #0x07 + add b + ld b, a + ld a, #0xC0 + and d + sla e + add e + ld e, a + ld d, b ; dest DE = BC + ((0x20 * Y) * 2) + (X * 2) + + ret + +; uint8_t * get_bkg_xy_addr(uint8_t x, uint8_t y) __z88dk_callee __preserves_regs(iyh, iyl); + +_get_bkg_xy_addr:: + pop hl + ex (sp), hl + ex de, hl + ld bc, #.VDP_TILEMAP + call .coords_to_address + ex de, hl + ret + diff --git a/gbdk-lib/libc/targets/z80/gg/Makefile b/gbdk-lib/libc/targets/z80/gg/Makefile @@ -11,6 +11,7 @@ ASSRC = 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 \ + coords_to_address.s \ set_tile.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 \ diff --git a/gbdk-lib/libc/targets/z80/set_tile.s b/gbdk-lib/libc/targets/z80/set_tile.s @@ -1,5 +1,10 @@ .include "global.s" + .title "VRAM utilities" + .module VRAMUtils + + .globl .coords_to_address + .area _HOME ; void set_vram_byte(uint8_t * addr, uint8_t v) __z88dk_callee __preserves_regs(iyh, iyl); @@ -16,35 +21,6 @@ _set_vram_byte:: ENABLE_VBLANK_COPY ret -; translate coords in DE and given base in BC into address in DE -.coords_to_address: - add #.SCREEN_Y_OFS - ld d, a - xor a - FAST_MOD8 d #28 - ld d, a - - ld a, e - add #.SCREEN_X_OFS - and #0x1f - ld e, a - - ld a, d - rrca ; rrca(2) == rlca(6) - rrca - ld d, a - and #0x07 - add b - ld b, a - ld a, #0xC0 - and d - sla e - add e - ld e, a - ld d, b ; dest DE = BC + ((0x20 * Y) * 2) + (X * 2) - - ret - ; uint8_t * set_attributed_tile_xy(uint8_t x, uint8_t y, uint16_t t) __z88dk_callee __preserves_regs(iyh, iyl); _set_attributed_tile_xy:: pop hl ; HL = ret diff --git a/gbdk-lib/libc/targets/z80/sms/Makefile b/gbdk-lib/libc/targets/z80/sms/Makefile @@ -11,6 +11,7 @@ ASSRC = 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 \ + coords_to_address.s \ set_tile.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 \

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