cscg22-gearboy

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

global.s (8373B)


      1        .GG_STATE       = 0x00
      2        
      3        .GGSTATE_STT    = 0b10000000
      4        .GGSTATE_NJAP   = 0b01000000
      5        .GGSTATE_NNTS   = 0b00100000
      6
      7        .GG_EXT_7BIT    = 0x01
      8
      9        .GG_EXT_CTL     = 0x02
     10
     11        .GGEXT_NINIT    = 0b10000000
     12
     13        .GG_SIO_SEND    = 0x03
     14        .GG_SIO_RECV    = 0x04
     15        .GG_SIO_CTL     = 0x05
     16
     17        .SIOCTL_TXFL    = 0b00000001
     18        .SIOCTL_RXRD    = 0b00000010
     19        .SIOCTL_FRER    = 0b00000100
     20        .SIOCTL_INT     = 0b00001000
     21        .SIOCTL_TON     = 0b00010000
     22        .SIOCTL_RON     = 0b00100000
     23        .SIOCTL_BS0     = 0b01000000
     24        .SIOCTL_BS1     = 0b10000000
     25
     26        .GG_SOUND_PAN   = 0x06
     27
     28        .SOUNDPAN_TN1R  = 0b00000001
     29        .SOUNDPAN_TN2R  = 0b00000010
     30        .SOUNDPAN_TN3R  = 0b00000100
     31        .SOUNDPAN_NOSR  = 0b00001000
     32        .SOUNDPAN_TN1L  = 0b00010000
     33        .SOUNDPAN_TN2L  = 0b00100000
     34        .SOUNDPAN_TN3L  = 0b01000000
     35        .SOUNDPAN_NOSL  = 0b10000000
     36
     37        .MEMORY_CTL     = 0x3E
     38
     39        .MEMCTL_JOYON   = 0b00000000
     40        .MEMCTL_JOYOFF  = 0b00000100
     41        .MEMCTL_BASEON  = 0b00000000
     42        .MEMCTL_BASEOFF = 0b00001000
     43        .MEMCTL_RAMON   = 0b00000000
     44        .MEMCTL_RAMOFF  = 0b00010000
     45        .MEMCTL_CROMON  = 0b00000000
     46        .MEMCTL_CROMOFF = 0b00100000
     47        .MEMCTL_ROMON   = 0b00000000
     48        .MEMCTL_ROMOFF  = 0b01000000
     49        .MEMCTL_EXTON   = 0b00000000
     50        .MEMCTL_EXTOFF  = 0b10000000
     51
     52        .JOY_CTL        = 0x3F
     53
     54        .JOY_P1_LATCH   = 0b00000010
     55        .JOY_P2_LATCH   = 0b00001000
     56
     57        .VDP_VRAM       = 0x4000
     58        .VDP_TILEMAP    = 0x7800
     59        .VDP_CRAM       = 0xC000
     60        .VDP_SAT        = 0x7F00
     61
     62        .VDP_SAT_TERM   = 0xD0
     63
     64        .VDP_VCOUNTER   = 0x7E
     65        .VDP_PSG        = 0x7F
     66        .VDP_HCOUNTER   = 0x7F
     67
     68        .VDP_DATA       = 0xBE
     69        .VDP_CMD        = 0xBF
     70        .VDP_STAT       = 0xBF
     71
     72        .STATF_INT_VBL  = 0b10000000
     73        .STATF_9_SPR    = 0b01000000
     74        .STATF_SPR_COLL = 0b00100000
     75
     76        .VDP_REG_MASK   = 0b10000000
     77        .VDP_R0         = 0b10000000
     78
     79        .R0_VSCRL       = 0b00000000
     80        .R0_VSCRL_INH   = 0b10000000
     81        .R0_HSCRL       = 0b00000000
     82        .R0_HSCRL_INH   = 0b01000000
     83        .R0_NO_LCB      = 0b00000000
     84        .R0_LCB         = 0b00100000
     85        .R0_IE1_OFF     = 0b00000000
     86        .R0_IE1         = 0b00010000
     87        .R0_SS_OFF      = 0b00000000
     88        .R0_SS          = 0b00001000
     89        .R0_DEFAULT     = 0b00000110
     90        .R0_ES_OFF      = 0b00000000
     91        .R0_ES          = 0b00000001
     92
     93        .VDP_R1         = 0b10000001
     94
     95        .R1_DEFAULT     = 0b10000000
     96        .R1_DISP_OFF    = 0b00000000
     97        .R1_DISP_ON     = 0b01000000
     98        .R1_IE_OFF      = 0b00000000
     99        .R1_IE          = 0b00100000
    100        .R1_SPR_8X8     = 0b00000000
    101        .R1_SPR_8X16    = 0b00000010
    102
    103        .VDP_R2         = 0b10000010
    104
    105        .R2_MAP_0x3800  = 0xFF
    106        .R2_MAP_0x3000  = 0xFD
    107        .R2_MAP_0x2800  = 0xFB
    108        .R2_MAP_0x2000  = 0xF9
    109        .R2_MAP_0x1800  = 0xF7
    110        .R2_MAP_0x1000  = 0xF5
    111        .R2_MAP_0x0800  = 0xF3
    112        .R2_MAP_0x0000  = 0xF1
    113
    114        .VDP_R3         = 0b10000011
    115        .VDP_R4         = 0b10000100
    116        .VDP_R5         = 0b10000101
    117
    118        .R5_SAT_0x3F00  = 0xFF
    119        .R5_SAT_MASK    = 0b10000001
    120
    121        .VDP_R6         = 0b10000110
    122
    123        .R6_BANK0       = 0xFB
    124        .R6_DATA_0x0000 = 0xFB
    125        .R6_BANK1       = 0xFF
    126        .R6_DATA_0x2000 = 0xFF
    127
    128        .VDP_R7         = 0b10000111
    129        .VDP_RBORDER    = 0b10000111
    130
    131        .R7_COLOR_MASK  = 0b11110000
    132
    133        .VDP_R8         = 0b10001000
    134        .VDP_RSCX       = 0b10001000
    135
    136        .VDP_R9         = 0b10001001
    137        .VDP_RSCY       = 0b10001001
    138
    139        .VDP_R10        = 0b10001010
    140
    141        .R10_INT_OFF    = 0xFF
    142        .R10_INT_EVERY  = 0x00
    143
    144        .JOYPAD_COUNT   = 1
    145
    146        .UP             = 0b00000001
    147        .DOWN           = 0b00000010
    148        .LEFT           = 0b00000100
    149        .RIGHT          = 0b00001000
    150        .A              = 0b00010000
    151        .B              = 0b00100000
    152        .SELECT         = 0b00100000    ; map to B
    153        .START          = 0b10000000    ; Game Gear Start button
    154
    155        .JOY_PORT1      = 0xDC
    156
    157        .JOY_P1_UP      = 0b00000001
    158        .JOY_P1_DOWN    = 0b00000010
    159        .JOY_P1_LEFT    = 0b00000100
    160        .JOY_P1_RIGHT   = 0b00001000
    161        .JOY_P1_SW1     = 0b00010000
    162        .JOY_P1_TRIGGER = 0b00010000
    163        .JOY_P1_SW2     = 0b00100000
    164        .JOY_P2_UP      = 0b01000000
    165        .JOY_P2_DOWN    = 0b10000000
    166
    167        .JOY_PORT2      = 0xDD
    168
    169        .JOY_P2_LEFT    = 0b00000001
    170        .JOY_P2_RIGHT   = 0b00000010
    171        .JOY_P2_SW1     = 0b00000100
    172        .JOY_P2_TRIGGER = 0b00000100
    173        .JOY_P2_SW2     = 0b00001000
    174        .JOY_RESET      = 0b00010000
    175        .JOY_P1_LIGHT   = 0b01000000
    176        .JOY_P2_LIGHT   = 0b10000000
    177
    178        .FMADDRESS      = 0xF0
    179        .FMDATA         = 0xF1
    180        .AUDIOCTRL      = 0xF2
    181
    182        .RAM_CONTROL    = 0xfffc
    183
    184        .RAMCTL_BANK    = 0b00000100
    185        .RAMCTL_ROM     = 0b00000000
    186        .RAMCTL_RAM     = 0b00001000
    187        .RAMCTL_RO      = 0b00010000
    188        .RAMCTL_PROT    = 0b10000000
    189
    190        .GLASSES_3D     = 0xfff8
    191
    192        .MAP_FRAME0     = 0xfffd
    193        .MAP_FRAME1     = 0xfffe
    194        .MAP_FRAME2     = 0xffff
    195
    196        .BIOS           = 0xC000
    197
    198        .SYSTEM_PAL     = 0x00
    199        .SYSTEM_NTSC    = 0x01
    200
    201        .CPU_CLOCK      = 3579545
    202
    203        ;; GBDK library screen modes
    204
    205        .T_MODE         = 0x02  ; Text mode (bit 2)
    206        .T_MODE_OUT     = 0x02  ; Text mode output only
    207        .T_MODE_INOUT   = 0x03  ; Text mode with input
    208        .M_NO_SCROLL    = 0x04  ; Disables scrolling of the screen in text mode
    209        .M_NO_INTERP    = 0x08  ; Disables special character interpretation
    210
    211        ;; Screen dimentions in tiles
    212
    213        .SCREEN_X_OFS   = 6
    214        .SCREEN_Y_OFS   = 3
    215        .SCREEN_WIDTH   = 20
    216        .SCREEN_HEIGHT  = 18
    217        .VDP_MAP_HEIGHT = 28
    218        .VDP_MAP_WIDTH  = 32
    219
    220        ;; Interrupt flags
    221
    222        .VBL_IFLAG      = 0x01
    223        .LCD_IFLAG      = 0x02
    224
    225        ; characters
    226        .CR             = 0x0A
    227        .SPACE          = 0x00
    228
    229        ;; Global variables
    230        .globl  .mode
    231
    232        ;; Interrupt routines
    233        .globl _INT_ISR
    234        .globl _NMI_ISR
    235
    236        ;; Symbols defined at link time
    237        .globl  .STACK
    238        .globl  _shadow_OAM
    239        .globl  __shadow_OAM_OFF
    240
    241        ;; Main user routine
    242        .globl  _main
    243
    244        ;; Macro definitions
    245
    246.macro VDP_WRITE_DATA regH regL ?lbl
    247        ld a, i
    248        ld a, regL
    249        di
    250        out (#.VDP_DATA), a     ; 11
    251        ld a, regH              ; 4
    252        jp po, lbl              ; 7/12
    253        ei                      ; 4 (total: 26/27)
    254lbl:
    255        out (#.VDP_DATA), a
    256.endm
    257
    258.macro VDP_WRITE_CMD regH regL ?lbl
    259        ld a, i
    260        ld a, regL
    261        di
    262        out (#.VDP_CMD), a
    263        ld a, regH
    264        jp po, lbl
    265        ei
    266lbl:
    267        out (#.VDP_CMD), a
    268.endm
    269
    270.macro VDP_DELAY ?lbl
    271        nop
    272        jr lbl
    273lbl:
    274.endm
    275
    276.macro VDP_CANCEL_INT
    277        in a, (.VDP_STAT)       ; cancel pending VDP interrupts
    278.endm
    279
    280.macro WRITE_VDP_CMD_HL
    281        rst 0x10
    282.endm
    283
    284.macro WRITE_VDP_DATA_HL
    285        rst 0x20
    286.endm
    287
    288.macro CALL_HL
    289        rst 0x30
    290.endm
    291
    292.macro DISABLE_VBLANK_COPY
    293        ld a, #1
    294        ld (__shadow_OAM_OFF), a
    295.endm
    296
    297.macro ENABLE_VBLANK_COPY
    298        xor a
    299        ld (__shadow_OAM_OFF), a
    300.endm
    301
    302.macro ADD_A_REG16 regH regL
    303        add regL
    304        ld regL, a
    305        adc regH
    306        sub regL
    307        ld regH, a
    308.endm
    309
    310.macro MUL_DE_BY_A_RET_HL ?lbl1 ?lbl2
    311        ; Multiply DE by A, return result in HL; preserves: BC
    312        ld hl, #0
    313lbl1:
    314        srl a
    315        jp nc, lbl2
    316        add hl, de
    317lbl2:
    318        sla e
    319        rl d
    320        or a
    321        jp nz, lbl1
    322.endm
    323
    324.macro DIV_PART divident divisor ?lbl
    325        rl divident
    326        rla
    327        sub divisor
    328        jr  nc, lbl
    329        add divisor
    330lbl:
    331.endm
    332.macro FAST_DIV8 divident divisor
    333        ; returns modulus in A
    334        .rept 8
    335                DIV_PART divident divisor
    336        .endm
    337        ld a, divident
    338        cpl
    339.endm
    340.macro FAST_MOD8 divident divisor
    341        ; returns modulus in A
    342        .rept 8
    343                DIV_PART divident divisor
    344        .endm
    345.endm