gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 52934c56888a21de95f46b4b480e154b9fecc603 parent 61b72fcce32aa69363eb36c952e381ee685bc98e Author: Toxa <56631470+untoxa@users.noreply.github.com> Date: Sat, 7 Oct 2023 17:39:40 +0300 Merge pull request #586 from michel-iwaniec/nes_replace_inline_sprite_routines_with_asm NES: Move inline set_sprite* routines to asm file, and add NO_OVERLAY_LOCALS function property Diffstat:
| M | gbdk-lib/include/nes/nes.h | 30 | +++++++----------------------- |
| M | gbdk-lib/libc/targets/mos6502/nes/Makefile | 2 | +- |
| A | gbdk-lib/libc/targets/mos6502/nes/set_sprite.s | 84 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 files changed, 92 insertions(+), 24 deletions(-)
diff --git a/gbdk-lib/include/nes/nes.h b/gbdk-lib/include/nes/nes.h @@ -1003,9 +1003,7 @@ inline void SET_SHADOW_OAM_ADDRESS(void * address) { the lower 8x8 tile is (__tile__ | 0x01). \li See: @ref SPRITES_8x16 */ -inline void set_sprite_tile(uint8_t nb, uint8_t tile) { - shadow_OAM[nb].tile=tile; -} +void set_sprite_tile(uint8_t nb, uint8_t tile) NO_OVERLAY_LOCALS; /** Returns the tile number of sprite number __nb__ in the OAM. @@ -1014,9 +1012,7 @@ inline void set_sprite_tile(uint8_t nb, uint8_t tile) { @see set_sprite_tile for more details */ -inline uint8_t get_sprite_tile(uint8_t nb) { - return shadow_OAM[nb].tile; -} +uint8_t get_sprite_tile(uint8_t nb) NO_OVERLAY_LOCALS; /** Sets the OAM Property Flags of sprite number __nb__ to those defined in __prop__. @@ -1056,9 +1052,7 @@ inline uint8_t get_sprite_tile(uint8_t nb) { @see S_PALETTE, S_FLIPX, S_FLIPY, S_PRIORITY */ -inline void set_sprite_prop(uint8_t nb, uint8_t prop) { - shadow_OAM[nb].prop=prop; -} +void set_sprite_prop(uint8_t nb, uint8_t prop) NO_OVERLAY_LOCALS; /** Returns the OAM Property Flags of sprite number __nb__. @@ -1066,9 +1060,7 @@ inline void set_sprite_prop(uint8_t nb, uint8_t prop) { @param nb Sprite number, range 0 - 39 @see set_sprite_prop for property bitfield settings */ -inline uint8_t get_sprite_prop(uint8_t nb) { - return shadow_OAM[nb].prop; -} +uint8_t get_sprite_prop(uint8_t nb) NO_OVERLAY_LOCALS; /** Moves sprite number __nb__ to the __x__, __y__ position on the screen. @@ -1080,10 +1072,7 @@ inline uint8_t get_sprite_prop(uint8_t nb) { Moving the sprite to 0,0 (or similar off-screen location) will hide it. */ -inline void move_sprite(uint8_t nb, uint8_t x, uint8_t y) { - OAM_item_t * itm = &shadow_OAM[nb]; - itm->y=y, itm->x=x; -} +void move_sprite(uint8_t nb, uint8_t x, uint8_t y) NO_OVERLAY_LOCALS; /** Moves sprite number __nb__ relative to its current position. @@ -1096,19 +1085,14 @@ inline void move_sprite(uint8_t nb, uint8_t x, uint8_t y) { @see move_sprite for more details about the X and Y position */ -inline void scroll_sprite(uint8_t nb, int8_t x, int8_t y) { - OAM_item_t * itm = &shadow_OAM[nb]; - itm->y+=y, itm->x+=x; -} +void scroll_sprite(uint8_t nb, int8_t x, int8_t y) NO_OVERLAY_LOCALS; /** Hides sprite number __nb__ by moving it to Y position 240. @param nb Sprite number, range 0 - 63 */ -inline void hide_sprite(uint8_t nb) { - shadow_OAM[nb].y = 240; -} +void hide_sprite(uint8_t nb) NO_OVERLAY_LOCALS; diff --git a/gbdk-lib/libc/targets/mos6502/nes/Makefile b/gbdk-lib/libc/targets/mos6502/nes/Makefile @@ -11,7 +11,7 @@ ASSRC = f_ibm_full.s f_ibm_sh.s f_italic.s f_min.s f_spect.s \ font.s font_color.s set_data.s set_native_data.s set_1bit_data.s color.s mode.s \ metasprites.s metasprites_flipx.s metasprites_flipy.s metasprites_flipxy.s \ metasprites_common.s \ - metasprites_hide.s metasprites_hide_spr.s \ + metasprites_hide.s metasprites_hide_spr.s set_sprite.s \ vram_transfer_buffer.s \ set_tile.s set_bk_ts.s set_tile_submap.s fill_rect_bk.s \ set_attribute.s set_bk_attributes.s set_tile_submap_attributes.s flush_attributes.s \ diff --git a/gbdk-lib/libc/targets/mos6502/nes/set_sprite.s b/gbdk-lib/libc/targets/mos6502/nes/set_sprite.s @@ -0,0 +1,84 @@ +.include "global.s" + +.title "SetSprite" +.module SetSprite + +.area GBDKOVR (PAG, OVR) +_move_sprite_PARM_3:: +_scroll_sprite_PARM_3:: .ds 1 + + .area _HOME + +; +; void set_sprite_tile(uint8_t nb, uint8_t tile) +; +_set_sprite_tile:: + asl + asl + tay + txa + sta _shadow_OAM+OAM_TILE_INDEX,y + rts + +; +; void set_sprite_prop(uint8_t nb, uint8_t prop) +; +_set_sprite_prop:: + asl + asl + tay + txa + sta _shadow_OAM+OAM_ATTRIBUTES,y + rts + +; +; void move_sprite(uint8_t nb, uint8_t x, uint8_t y) +; +_move_sprite:: + asl + asl + tay + txa + sta _shadow_OAM+OAM_POS_X,y + lda *_move_sprite_PARM_3 + sta _shadow_OAM+OAM_POS_Y,y + rts + +; +; void scroll_sprite(uint8_t nb, uint8_t x, uint8_t y) +; +_scroll_sprite:: + asl + asl + tay + txa + clc + adc _shadow_OAM+OAM_POS_X,y + sta _shadow_OAM+OAM_POS_X,y + lda *_scroll_sprite_PARM_3 + clc + adc _shadow_OAM+OAM_POS_Y,y + sta _shadow_OAM+OAM_POS_Y,y + rts + +; +; hide_sprite(uint8_t nb); +; +_hide_sprite:: + asl + asl + tay + txa + lda #240 + sta _shadow_OAM+OAM_POS_Y,y + rts + +; +; uint8_t get_sprite_prop(uint8_t nb) +; +_get_sprite_prop:: + asl + asl + tay + lda _shadow_OAM+OAM_ATTRIBUTES,y + rts
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.