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