cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

metasprites_flip.s (3899B)


      1        .include    "global.s"
      2
      3        .title  "Metasprites"
      4        .module Metasprites
      5
      6        .area   _DATA
      7
      8        .globl ___current_metasprite, ___current_base_tile, ___render_shadow_OAM
      9
     10        .area   _CODE
     11
     12; uint8_t __move_metasprite(uint8_t id, uint8_t x, uint8_t y)
     13
     14___move_metasprite_hflip::
     15        ldhl    sp, #4
     16        ld      a, (hl-)
     17        ld      b, a
     18        ld      a, (hl-)
     19        ld      c, a
     20        ld      a, (hl)
     21        cp      #40
     22        jr      nc, 3$
     23
     24        add     a
     25        add     a
     26        ld      e, a
     27
     28        ld      hl, #___current_metasprite
     29        ld      a, (hl+)
     30        ld      h, (hl)
     31        ld      l, a
     32
     33        ld      a, (___render_shadow_OAM)
     34        ld      d, a
     351$:
     36        ld      a, (hl+)
     37        cp      #0x80
     38        jr      z, 2$
     39        cpl
     40        inc     a
     41        add     b
     42        ld      b, a
     43        ld      (de), a
     44        inc     e
     45
     46        ld      a, (hl+)    ; dx
     47        add     c
     48        ld      c, a
     49        ld      (de), a
     50        inc     e
     51
     52        ld      a, (___current_base_tile)
     53        add     (hl)        ; tile
     54        inc     hl
     55        ld      (de), a
     56        inc     e
     57
     58        ld      a, (hl+)    ; props
     59        xor     #0x40
     60        ld      (de), a
     61        inc     e
     62
     63        ld      a, e
     64        cp      #160
     65        jr      c, 1$
     662$:
     67        ld      a, e
     68        srl     a
     69        srl     a
     70        ldhl    sp, #2
     713$:
     72        sub     (hl)
     73        ld      e, a
     74
     75        ret
     76
     77___move_metasprite_vflip::
     78        ldhl    sp, #4
     79        ld      a, (hl-)
     80        ld      b, a
     81        ld      a, (hl-)
     82        ld      c, a
     83        ld      a, (hl)
     84        cp      #40
     85        jr      nc, 3$
     86
     87        add     a
     88        add     a
     89        ld      e, a
     90
     91        ld      hl, #___current_metasprite
     92        ld      a, (hl+)
     93        ld      h, (hl)
     94        ld      l, a
     95
     96        ld      a, (___render_shadow_OAM)
     97        ld      d, a
     981$:
     99        ld      a, (hl+)    ; dy
    100        cp      #0x80
    101        jr      z, 2$
    102        add     b
    103        ld      b, a
    104        ld      (de), a
    105        inc     e
    106
    107        ld      a, (hl+)    ; dx
    108        cpl
    109        inc     a
    110        add     c
    111        ld      c, a
    112        ld      (de), a
    113        inc     e
    114
    115        ld      a, (___current_base_tile)
    116        add     (hl)        ; tile
    117        inc     hl
    118        ld      (de), a
    119        inc     e
    120
    121        ld      a, (hl+)    ; props
    122        xor     #0x20
    123        ld      (de), a
    124        inc     e
    125
    126        ld      a, e
    127        cp      #160
    128        jr      c, 1$
    1292$:
    130        ld      a, e
    131        srl     a
    132        srl     a
    133        ldhl    sp, #2
    1343$:
    135        sub     (hl)
    136        ld      e, a
    137
    138        ret
    139
    140___move_metasprite_hvflip::
    141        ldhl    sp, #4
    142        ld      a, (hl-)
    143        ld      b, a
    144        ld      a, (hl-)
    145        ld      c, a
    146        ld      a, (hl)
    147        cp      #40
    148        jr      nc, 3$
    149
    150        add     a
    151        add     a
    152        ld      e, a
    153
    154        ld      hl, #___current_metasprite
    155        ld      a, (hl+)
    156        ld      h, (hl)
    157        ld      l, a
    158
    159        ld      a, (___render_shadow_OAM)
    160        ld      d, a
    1611$:
    162        ld      a, (hl+)
    163        cp      #0x80
    164        jr      z, 2$
    165        cpl
    166        inc     a
    167        add     b
    168        ld      b, a
    169        ld      (de), a
    170        inc     e
    171
    172        ld      a, (hl+)    ; dx
    173        cpl
    174        inc     a
    175        add     c
    176        ld      c, a
    177        ld      (de), a
    178        inc     e
    179
    180        ld      a, (___current_base_tile)
    181        add     (hl)        ; tile
    182        inc     hl
    183        ld      (de), a
    184        inc     e
    185
    186        ld      a, (hl+)    ; props
    187        xor     #0x60
    188        ld      (de), a
    189        inc     e
    190
    191        ld      a, e
    192        cp      #160
    193        jr      c, 1$
    1942$:
    195        ld      a, e
    196        srl     a
    197        srl     a
    198        ldhl    sp, #2
    1993$:
    200        sub     (hl)
    201        ld      e, a
    202
    203        ret