cscg22-gearboy

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

fill_rect.s (1908B)


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