cscg22-gearboy

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

get_xy_t.s (2032B)


      1        .include        "global.s"
      2
      3        .area   _HOME
      4
      5        ;; Store window tile table into (BC) at xy = DE of size WH = HL
      6.get_xy_wtt::
      7        PUSH    HL              ; Store WH
      8        LDH     A,(.LCDC)
      9        AND     #LCDCF_WIN9C00
     10        JR      Z,.is98
     11        JR      .is9c
     12        ;; Store background tile table into (BC) at XY = DE of size WH = HL
     13.get_xy_btt::
     14        PUSH    HL              ; Store WH
     15        LDH     A,(.LCDC)
     16        AND     #LCDCF_BG9C00
     17        JR      NZ,.is9c
     18.is98:
     19        LD      HL,#0x9800
     20        JR      .get_xy_tt
     21.is9c:
     22        LD      HL,#0x9C00
     23        
     24        ;; Store background tile table into (BC) at XY = DE, size WH on stack, from vram from address (HL)
     25.get_xy_tt::
     26        PUSH    BC              ; Store source
     27
     28        SWAP    E
     29        RLC     E
     30        LD      A,E
     31        AND     #0x03
     32        ADD     H
     33        LD      B,A
     34        LD      A,#0xE0
     35        AND     E
     36        ADD     D
     37        LD      C,A             ; dest BC = HL + 0x20 * Y + X
     38
     39        POP     HL              ; HL = source
     40        POP     DE              ; DE = WH
     41        PUSH    DE              ; store WH
     42        PUSH    BC              ; store dest
     43
     443$:                             ; Copy W tiles
     45
     46        WAIT_STAT
     47        LD      A, (BC)
     48        LD      (HL+), A
     49        
     50        LD      A, C            ; inc dest and wrap around
     51        AND     #0xE0
     52        LD      E, A
     53        LD      A, C
     54        INC     A
     55        AND     #0x1F
     56        OR      E
     57        LD      C, A
     58
     59        DEC     D
     60        JR      NZ, 3$
     61
     62        POP     BC
     63        POP     DE
     64
     65        DEC     E
     66        RET     Z
     67
     68        PUSH    DE
     69
     70        LD      A, B            ; next row and wrap around
     71        AND     #0xFC
     72        LD      E, A            ; save high bits
     73
     74        LD      A,#0x20
     75
     76        ADD     C
     77        LD      C, A
     78        ADC     B
     79        SUB     C
     80        AND     #0x03
     81        OR      E               ; restore high bits
     82        LD      B, A
     83
     84        PUSH    BC
     85        
     86        JR      3$