gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 5d8434767276e4b905d98493ade0c06746cc2330 parent 8de2a68801e1824459d93a0daf2270d2b53fc278 Author: Toxa <56631470+untoxa@users.noreply.github.com> Date: Thu, 22 Apr 2021 14:46:32 +0300 Merge pull request #177 from gbdk-2020/SDCC-12207 Sdcc 12207 Diffstat:
| R | gbdk-lib/examples/gb/banks_farptr/Makefile -> gbdk-lib/examples/broken/banks_farptr/Makefile | 0 | |
| R | gbdk-lib/examples/gb/banks_farptr/bank2code.c -> gbdk-lib/examples/broken/banks_farptr/bank2code.c | 0 | |
| R | gbdk-lib/examples/gb/banks_farptr/banks_farptr.c -> gbdk-lib/examples/broken/banks_farptr/banks_farptr.c | 0 | |
| M | gbdk-lib/examples/gb/bcd/bcd.c | 8 | ++++---- |
| M | gbdk-lib/examples/gb/ram_function/ram_fn.c | 4 | ++-- |
| M | gbdk-lib/examples/gb/sgb_border/sgb_border.c | 41 | ++++++++++++++++++----------------------- |
| M | gbdk-lib/examples/gb/space/Makefile | 4 | +++- |
| M | gbdk-lib/examples/gb/space/space.s | 2 | +- |
| M | gbdk-lib/include/gb/gb.h | 25 | +++++++++++++++++++++++++ |
| M | gbdk-lib/libc/gb/Makefile | 2 | +- |
| M | gbdk-lib/libc/gb/crt0.s | 46 | ++++++++++++++++++++++++++++++++++++++++------ |
| A | gbdk-lib/libc/gb/get_tile.s | 51 | +++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | gbdk-lib/libc/gb/pad_ex.s | 31 | +++++++++++++++++++++++++------ |
| M | gbdk-lib/libc/gb/sgb.s | 28 | ++++++++++++++++------------ |
14 files changed, 186 insertions(+), 56 deletions(-)
diff --git a/gbdk-lib/examples/gb/banks_farptr/Makefile b/gbdk-lib/examples/broken/banks_farptr/Makefile diff --git a/gbdk-lib/examples/gb/banks_farptr/bank2code.c b/gbdk-lib/examples/broken/banks_farptr/bank2code.c diff --git a/gbdk-lib/examples/gb/banks_farptr/banks_farptr.c b/gbdk-lib/examples/broken/banks_farptr/banks_farptr.c diff --git a/gbdk-lib/examples/gb/bcd/bcd.c b/gbdk-lib/examples/gb/bcd/bcd.c @@ -16,21 +16,21 @@ void main() { font_init(); font_set(font_load(font_spect)); - len = bcd2text(&bcd, 0x11, buf); + len = bcd2text(&bcd, 0x10, buf); set_bkg_tiles(5, 5, len, 1, buf); bcd_add(&bcd, &bcd2); - len = bcd2text(&bcd, 0x11, buf); + len = bcd2text(&bcd, 0x10, buf); set_bkg_tiles(5, 6, len, 1, buf); bcd_sub(&bcd, &bcd3); - len = bcd2text(&bcd, 0x11, buf); + len = bcd2text(&bcd, 0x10, buf); set_bkg_tiles(5, 7, len, 1, buf); uint2bcd(12345, &bcd); - len = bcd2text(&bcd, 0x11, buf); + len = bcd2text(&bcd, 0x10, buf); set_bkg_tiles(5, 8, len, 1, buf); } diff --git a/gbdk-lib/examples/gb/ram_function/ram_fn.c b/gbdk-lib/examples/gb/ram_function/ram_fn.c @@ -20,8 +20,8 @@ unsigned char __at _inc_hiram hiram_buffer[]; // those are function pointer variables, we can initialize them right here typedef void (*inc_t)(void); -inc_t inc_ram_var = (inc_t)&ram_buffer; -inc_t inc_hiram_var = (inc_t)&hiram_buffer; +inc_t inc_ram_var = (inc_t)ram_buffer; +inc_t inc_hiram_var = (inc_t)hiram_buffer; // those are defined by passing parameters to the linker, they must be located at the same // addresses where ram_buffer and hiram_buffer are located diff --git a/gbdk-lib/examples/gb/sgb_border/sgb_border.c b/gbdk-lib/examples/gb/sgb_border/sgb_border.c @@ -10,33 +10,13 @@ #define SGB_SCR_FREEZE 1 #define SGB_SCR_UNFREEZE 0 -unsigned char map_buf[20]; - #define SGB_TRANSFER(A,B) map_buf[0]=(A),map_buf[1]=(B),sgb_transfer(map_buf) -void transfer_tiles(unsigned char * data, size_t size) { - UBYTE ntiles; - if (size > 256 * 32) ntiles = 0; else ntiles = size >> 5; - - if ((!ntiles) || (ntiles > 128U)) { - set_bkg_data(0, 0, data); - if (ntiles) ntiles -= 128U; - data += (128 * 32); - } else { - set_bkg_data(0, ntiles << 1, data); - SGB_TRANSFER((SGB_CHR_TRN << 3) | 1, SGB_CHR_BLOCK0); - return; - } - SGB_TRANSFER((SGB_CHR_TRN << 3) | 1, SGB_CHR_BLOCK0); - - set_bkg_data(0, ntiles << 1, data); - SGB_TRANSFER((SGB_CHR_TRN << 3) | 1, SGB_CHR_BLOCK1); -} - void set_sgb_border(unsigned char * tiledata, size_t tiledata_size, unsigned char * tilemap, size_t tilemap_size, unsigned char * palette, size_t palette_size) { if (sgb_check()) { + unsigned char map_buf[20]; memset(map_buf, 0, sizeof(map_buf)); SGB_TRANSFER((SGB_MASK_EN << 3) | 1, SGB_SCR_FREEZE); @@ -52,11 +32,26 @@ void set_sgb_border(unsigned char * tiledata, size_t tiledata_size, UBYTE i = 0U; for (UBYTE y = 0; y != 14U; ++y) { UBYTE * dout = map_buf; - for(UBYTE x = 0U; x != 20U; ++x, *dout++ = i++); + for (UBYTE x = 0U; x != 20U; ++x) { + *dout++ = i++; + } set_bkg_tiles(0, y, 20, 1, map_buf); } + memset(map_buf, 0, sizeof(map_buf)); - transfer_tiles(tiledata, tiledata_size); + // transfer tile data + UBYTE ntiles = (tiledata_size > 256 * 32) ? 0 : tiledata_size >> 5; + if ((!ntiles) || (ntiles > 128U)) { + set_bkg_data(0, 0, tiledata); + SGB_TRANSFER((SGB_CHR_TRN << 3) | 1, SGB_CHR_BLOCK0); + if (ntiles) ntiles -= 128U; + tiledata += (128 * 32); + set_bkg_data(0, ntiles << 1, tiledata); + SGB_TRANSFER((SGB_CHR_TRN << 3) | 1, SGB_CHR_BLOCK1); + } else { + set_bkg_data(0, ntiles << 1, tiledata); + SGB_TRANSFER((SGB_CHR_TRN << 3) | 1, SGB_CHR_BLOCK0); + } // transfer map and palettes set_bkg_data(0, (UBYTE)(tilemap_size >> 4), tilemap); diff --git a/gbdk-lib/examples/gb/space/Makefile b/gbdk-lib/examples/gb/space/Makefile @@ -1,4 +1,6 @@ -CC = ../../../bin/lcc -Wa-l -Wl-m -Wl-j +GBDK = ../../.. +LIB = $(GBDK)/lib/small/asxxxx/ +CC = $(GBDK)/bin/lcc -Wa-I$(LIB) -Wa-l -Wl-m -Wl-j BINS = space.gb diff --git a/gbdk-lib/examples/gb/space/space.s b/gbdk-lib/examples/gb/space/space.s @@ -19,7 +19,7 @@ ;; Note that the window is kept in the lower right part of the screen ;; since it can't be made transparent - .include "../../../lib/small/asxxxx/global.s" + .include "global.s" .globl .init_vram .globl .copy_vram diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -617,6 +617,14 @@ void hiramcpy(UINT8 dst, */ void set_vram_byte(UBYTE * addr, UINT8 v) __preserves_regs(b, c); +/** + * Get byte from vram at given memory location + * + * @param addr address to read from + * @return read value + */ +UINT8 get_vram_byte(UBYTE * addr) __preserves_regs(b, c); + /** * Get address of X,Y tile of background map @@ -808,6 +816,14 @@ void get_bkg_tiles(UINT8 x, UINT8 * set_bkg_tile_xy(UBYTE x, UBYTE y, UBYTE t) __preserves_regs(b, c); +/** + * Get single tile t on background layer at x,y + * @param x X-coordinate + * @param y Y-coordinate + * @return returns tile index + */ +UINT8 get_bkg_tile_xy(UBYTE x, UBYTE y) __preserves_regs(b, c); + /** Moves the Background Layer to the position specified in __x__ and __y__ in pixels. @@ -1000,6 +1016,15 @@ void get_win_tiles(UINT8 x, UINT8 * set_win_tile_xy(UBYTE x, UBYTE y, UBYTE t) __preserves_regs(b, c); +/** + * Get single tile t on window layer at x,y + * @param x X-coordinate + * @param y Y-coordinate + * @return returns the tile index + */ +UINT8 get_win_tile_xy(UBYTE x, UBYTE y) __preserves_regs(b, c); + + /** Moves the Window to the __x__, __y__ position on the screen. @param x X coordinate for Left edge of the Window (actual displayed location will be X - 7) diff --git a/gbdk-lib/libc/gb/Makefile b/gbdk-lib/libc/gb/Makefile @@ -10,7 +10,7 @@ CSRC = digits.c gprint.c gprintf.c gprintln.c gprintn.c ASSRC = cgb.s cpy_data.s \ drawing.s drawing_isr.s color.s \ f_ibm_full.s f_ibm_sh.s f_italic.s f_min.s f_spect.s \ - get_bk_t.s get_data.s \ + get_bk_t.s get_data.s get_tile.s \ get_wi_t.s get_xy_t.s global.s \ get_addr.s \ hiramcpy.s init_tt.s input.s \ diff --git a/gbdk-lib/libc/gb/crt0.s b/gbdk-lib/libc/gb/crt0.s @@ -57,7 +57,7 @@ ; .org 0x70 ;; space for drawing.s bit table - .org 0x80 + .org 0x80 .int:: PUSH BC PUSH DE @@ -181,10 +181,10 @@ _reset:: ;; Clear CRT0 global variables LD HL,#.start_crt_globals - LD C,#(.end_crt_globals - .start_crt_globals) + LD C,#(.end_crt_globals - .start_crt_globals) RST 0x28 -; LD (.mode),A ; Clearing (.mode) is performed when clearing RAM +; LD (.mode),A ; Clearing (.mode) is performed when clearing RAM ;; Store CPU type LD A,D @@ -315,13 +315,15 @@ _set_interrupts:: .area _CODE_0 ;; Constant data .area _LIT + .area _INITIALIZER ;; Constant data used to init _DATA - .area _GSINIT + .area _GSINIT .area _GSFINAL - ;; Initialised in ram data - .area _DATA ;; Uninitialised ram data + .area _DATA .area _BSS + ;; Initialised in ram data + .area _INITIALIZED ;; For malloc .area _HEAP @@ -349,9 +351,41 @@ __current_bank:: ; Current bank .ds 0x01 ; Is VBL interrupt finished? __shadow_OAM_base:: .ds 0x01 + ;; Runtime library .area _GSINIT gsinit:: + LD DE, #l__INITIALIZER + LD A, D + OR E + JR Z, 4$ + LD HL, #s__INITIALIZED + LD BC, #s__INITIALIZER + + SRL D + RR E + JR NC,3$ + LD A,(BC) + LD (HL+),A + INC BC +3$: + INC D + INC E + JR 2$ +1$: + LD A,(BC) + LD (HL+),A + INC BC + LD A,(BC) + LD (HL+),A + INC BC +2$: + DEC E + JR NZ,1$ + DEC D + JR NZ,1$ +4$: + .area _GSFINAL ret diff --git a/gbdk-lib/libc/gb/get_tile.s b/gbdk-lib/libc/gb/get_tile.s @@ -0,0 +1,51 @@ +.include "global.s" + +.area _CODE + +_get_vram_byte:: + ldhl sp,#2 + ld a,(hl+) + ld h,(hl) + ld l,a + WAIT_STAT + ld e,(hl) + ret + +_get_win_tile_xy:: + ldh a,(.LCDC) + bit 6,a + jr z,.is98 + jr .is9c +_get_bkg_tile_xy:: + ldh a,(.LCDC) + bit 3,a + jr nz,.is9c +.is98: + ld d,#0x98 ; DE = origin + jr .set_tile_xy +.is9c: + ld d,#0x9C ; DE = origin + +.get_tile_xy: + ldhl sp,#3 + + ld a, (hl-) + ld l, (hl) + + ld e, d + swap a + rlca + ld h, a + and #0x03 + add e + ld d, a + ld a, #0xE0 + and h + add l + ld l, a + ld h, d ; dest DE = BASE + 0x20 * Y + X + + WAIT_STAT + ld e, (hl) + + ret diff --git a/gbdk-lib/libc/gb/pad_ex.s b/gbdk-lib/libc/gb/pad_ex.s @@ -1,16 +1,31 @@ .include "global.s" + .MLT_REQ = 0x11 + .area _BASE _joypad_init:: call .sgb_check ld a, e + inc e or a jr Z, 1$ - ldhl sp, #2 - ld a, (hl) + ldhl sp, #0x02 + ld e, (hl) + + add sp, #-0x10 + ldhl sp, #0 + ld c, #0x10 + xor a + rst 0x28 + + ldhl sp, #0 + ld a, #((.MLT_REQ << 3) | 1) + ld (hl+), a + + ld a, e cp a, #0x02 jr Z, 3$ @@ -19,22 +34,26 @@ _joypad_init:: jr 5$ 3$: - ld hl, #.MLT_REQ_2 + ld a, #0x01 + ld (hl-), a call .sgb_transfer ld e, #0x02 jr 2$ 4$: - ld hl, #.MLT_REQ_4 + ld a, #0x03 + ld (hl-), a call .sgb_transfer ld e, #0x04 jr 2$ 5$: - ld hl, #.MLT_REQ_1 + ld a, #0x00 + ld (hl-), a call .sgb_transfer -1$: ld e, #0x01 2$: + add sp, #0x10 +1$: ldhl sp, #3 ld a, (hl+) ld h, (hl) diff --git a/gbdk-lib/libc/gb/sgb.s b/gbdk-lib/libc/gb/sgb.s @@ -34,7 +34,16 @@ .sgb_check:: _sgb_check:: PUSH BC - LD HL,#.MLT_REQ_4 + ADD SP, #-0x10 + LDHL SP, #0 + LD C, #0x10 + XOR A + RST 0x28 + LDHL SP,#0 + LD A,#((.MLT_REQ << 3) | 1) + LD (HL+),A + LD A,#0x03 + LD (HL-),A CALL .sgb_transfer LD C,#.P1 LD A,#(.P14 | .P15) @@ -69,12 +78,15 @@ _sgb_check:: JR NZ,3$ 2$: LD E,#0 - POP BC - RET + JR 4$ 1$: - LD HL,#.MLT_REQ_1 + LDHL SP,#1 + LD A,#0x00 + LD (HL-),A CALL .sgb_transfer LD E,#1 +4$: + ADD SP,#0x10 POP BC RET @@ -140,11 +152,3 @@ _sgb_transfer:: 6$: POP BC RET - - -.MLT_REQ_1:: - .byte ((.MLT_REQ << 3) | 1), 0x00 -.MLT_REQ_2:: - .byte ((.MLT_REQ << 3) | 1), 0x01 -.MLT_REQ_4:: - .byte ((.MLT_REQ << 3) | 1), 0x03
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.