cscg22-gearboy

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

get_data.s (2920B)


      1        .include        "global.s"
      2
      3        .globl  .copy_vram
      4
      5        .area   _HOME
      6
      7_get_bkg_data::
      8_get_win_data::
      9        LDH     A,(.LCDC)
     10        AND     #LCDCF_BG8000
     11        JP      NZ,_get_sprite_data
     12
     13        PUSH    BC
     14
     15        LDA     HL,7(SP)        ; Skip return address and registers
     16        LD      A,(HL-)         ; BC = data
     17        LD      B, A
     18        LD      A,(HL-)
     19        LD      C, A
     20        LD      A,(HL-)         ; E = nb_tiles
     21        LD      E, A
     22        LD      L,(HL)          ; L = first_tile
     23        PUSH    HL
     24
     25        XOR     A
     26        OR      E               ; Is nb_tiles == 0?
     27        JR      NZ,1$
     28        LD      DE,#0x1000      ; DE = nb_tiles = 256
     29        JR      2$
     301$:
     31        LD      H,#0x00         ; HL = nb_tiles
     32        LD      L,E
     33        ADD     HL,HL           ; HL *= 16
     34        ADD     HL,HL
     35        ADD     HL,HL
     36        ADD     HL,HL
     37        LD      D,H             ; DE = nb_tiles
     38        LD      E,L
     392$:
     40        POP     HL              ; HL = first_tile
     41        LD      A,L
     42        RLCA                    ; Sign extend (patterns have signed numbers)
     43        SBC     A
     44        LD      H,A
     45        ADD     HL,HL           ; HL *= 16
     46        ADD     HL,HL
     47        ADD     HL,HL
     48        ADD     HL,HL
     49
     50        PUSH    BC
     51        LD      BC,#0x9000
     52        ADD     HL,BC
     53        POP     BC
     54
     553$:                             ; Special version of '.copy_vram'
     56        BIT     3,H             ; Bigger than 0x9800
     57        JR      Z,4$
     58        BIT     4,H
     59        JR      Z,4$
     60        RES     4,H             ; Switch to 0x8800
     614$:
     62        WAIT_STAT
     63
     64        LD      A,(HL+)
     65        LD      (BC),A
     66        INC     BC
     67        DEC     DE
     68        LD      A,D
     69        OR      E
     70        JR      NZ,3$
     71
     72        POP     BC
     73        RET
     74
     75_get_sprite_data::
     76        PUSH    BC
     77
     78        LDA     HL,7(SP)        ; Skip return address and registers
     79        LD      A,(HL-)         ; BC = data
     80        LD      B, A
     81        LD      A,(HL-)
     82        LD      C, A
     83        LD      A,(HL-)         ; E = nb_tiles
     84        LD      E, A
     85        LD      L,(HL)          ; L = first_tile
     86        PUSH    HL
     87
     88        XOR     A
     89        OR      E               ; Is nb_tiles == 0?
     90        JR      NZ,1$
     91        LD      DE,#0x1000      ; DE = nb_tiles = 256
     92        JR      2$
     931$:
     94        LD      H,#0x00         ; HL = nb_tiles
     95        LD      L,E
     96        ADD     HL,HL           ; HL *= 16
     97        ADD     HL,HL
     98        ADD     HL,HL
     99        ADD     HL,HL
    100        LD      D,H             ; DE = nb_tiles
    101        LD      E,L
    1022$:
    103        POP     HL              ; HL = first_tile
    104        LD      L,A
    105        ADD     HL,HL           ; HL *= 16
    106        ADD     HL,HL
    107        ADD     HL,HL
    108        ADD     HL,HL
    109
    110        PUSH    BC
    111        LD      BC,#0x8000
    112        ADD     HL,BC
    113        LD      B,H
    114        LD      C,L
    115        POP     HL
    116
    117        CALL    .copy_vram
    118
    119        POP     BC
    120        RET