set_tile_submap.s (3502B)
1 .include "global.s" 2 3 .title "Set tile submap" 4 .module SetTileSubmap 5 6 .area _DATA 7 8.image_tile_width:: 9 .ds 0x01 10 11 .area _INITIALIZED 12 13__submap_tile_offset:: 14 .ds 0x01 15 16 .area _INITIALIZER 17 18 .db 0x00 19 20 .area _HOME 21 22_set_bkg_submap:: 23 ldhl sp, #2 24 ld a, (hl+) ; b = x 25 ld b, a 26 ld c, (hl) ; c = y 27 28 ldhl sp, #8 29 ld a, (hl) 30 ldhl sp, #4 31 sub (hl) 32 ld (.image_tile_width), a ; .image_tile_width contains corrected width map width 33 add (hl) 34 35 ld d, #0 36 ld e, a 37 ld a, c 38 MUL_DE_BY_A_RET_HL 39 ld a, b 40 ADD_A_REG16 h, l 41 ld d, h 42 ld e, l 43 44 ldhl sp, #6 45 ld a,(hl+) 46 ld h,(hl) 47 ld l,a 48 add hl, de 49 ld b, h 50 ld c, l 51 52 ldhl sp, #2 53 ld a, (hl+) ; d = x 54 and #0x1f 55 ld d, a 56 ld a, (hl) ; e = y 57 and #0x1f 58 ld e, a 59 60 ldhl sp, #5 61 ld a,(hl-) ; a = h 62 ld h,(hl) ; h = w 63 ld l,a ; l = h 64 65 jr .set_xy_bkg_submap 66 67 ;; set window tile table from bc at xy = de of size wh = hl 68.set_xy_win_submap:: 69 push hl ; store wh 70 ldh a,(.LCDC) 71 and #LCDCF_WIN9C00 72 jr z,.is98 73 jr .is9c 74 ;; set background tile table from (bc) at xy = de of size wh = hl 75.set_xy_bkg_submap:: 76 push hl ; store wh 77 ldh a,(.LCDC) 78 and #LCDCF_BG9C00 79 jr nz,.is9c 80.is98: 81 ld hl,#0x9800 82 jr .set_xy_submap 83.is9c: 84 ld hl,#0x9c00 85 ;; set background tile from (bc) at xy = de, size wh on stack, to vram from address (hl) 86.set_xy_submap:: 87 push bc ; store source 88 89 swap e 90 rlc e 91 ld a,e 92 and #0x03 93 add h 94 ld b,a 95 ld a,#0xe0 96 and e 97 add d 98 ld c,a ; dest bc = hl + 0x20 * y + x 99 100 pop hl ; hl = source 101 pop de ; de = wh 102 push de ; store wh 103 push bc ; store dest 1043$: ; copy w tiles 105 WAIT_STAT 106 ld a, (__submap_tile_offset) 107 add (hl) 108 ld (bc), a 109 inc hl 110 111 ld a, c ; inc dest and wrap around 112 and #0xe0 113 ld e, a 114 ld a, c 115 inc a 116 and #0x1f 117 or e 118 ld c, a 119 120 dec d 121 jr nz, 3$ 122 123 ld a, (.image_tile_width) 124 ADD_A_REG16 h, l 125 126 pop bc 127 pop de 128 129 dec e 130 ret z 131 132 push de 133 134 ld a, b ; next row and wrap around 135 and #0xfc 136 ld e, a ; save high bits 137 138 ld a,#0x20 139 140 add c 141 ld c, a 142 adc b 143 sub c 144 and #0x03 145 or e ; restore high bits 146 ld b, a 147 148 push bc 149 150 jr 3$