cscg22-gearboy

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

set_xy_t.s (2244B)


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