You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

921 lines
23 KiB

  1. ;*
  2. ;* Gameboy Hardware definitions
  3. ;*
  4. ;* Based on Jones' hardware.inc
  5. ;* And based on Carsten Sorensen's ideas.
  6. ;*
  7. ;* Rev 1.1 - 15-Jul-97 : Added define check
  8. ;* Rev 1.2 - 18-Jul-97 : Added revision check macro
  9. ;* Rev 1.3 - 19-Jul-97 : Modified for RGBASM V1.05
  10. ;* Rev 1.4 - 27-Jul-97 : Modified for new subroutine prefixes
  11. ;* Rev 1.5 - 15-Aug-97 : Added _HRAM, PAD, CART defines
  12. ;* : and Nintendo Logo
  13. ;* Rev 1.6 - 30-Nov-97 : Added rDIV, rTIMA, rTMA, & rTAC
  14. ;* Rev 1.7 - 31-Jan-98 : Added _SCRN0, _SCRN1
  15. ;* Rev 1.8 - 15-Feb-98 : Added rSB, rSC
  16. ;* Rev 1.9 - 16-Feb-98 : Converted I/O registers to $FFXX format
  17. ;* Rev 2.0 - : Added GBC registers
  18. ;* Rev 2.1 - : Added MBC5 & cart RAM enable/disable defines
  19. ;* Rev 2.2 - : Fixed NR42,NR43, & NR44 equates
  20. ;* Rev 2.3 - : Fixed incorrect _HRAM equate
  21. ;* Rev 2.4 - 27-Apr-13 : Added some cart defines (AntonioND)
  22. ;* Rev 2.5 - 03-May-15 : Fixed format (AntonioND)
  23. ;* Rev 2.6 - 09-Apr-16 : Added GBC OAM and cart defines (AntonioND)
  24. ;* Rev 2.7 - 19-Jan-19 : Added rPCMXX (ISSOtm)
  25. ;* Rev 2.8 - 03-Feb-19 : Added audio registers flags (Álvaro Cuesta)
  26. ;* Rev 2.9 - 28-Feb-20 : Added utility rP1 constants
  27. ;* Rev 3.0 - 27-Aug-20 : Register ordering, byte-based sizes, OAM additions, general cleanup (Blitter Object)
  28. ;* Rev 4.0 - 03-May-21 : Updated to use RGBDS 0.5.0 syntax, changed IEF_LCDC to IEF_STAT (Eievui)
  29. IF __RGBDS_MAJOR__ == 0 && __RGBDS_MINOR__ < 5
  30. FAIL "This version of 'hardware.inc' requires RGBDS version 0.5.0 or later."
  31. ENDC
  32. ; If all of these are already defined, don't do it again.
  33. IF !DEF(HARDWARE_INC)
  34. DEF HARDWARE_INC EQU 1
  35. MACRO rev_Check_hardware_inc
  36. ;NOTE: REVISION NUMBER CHANGES MUST BE ADDED
  37. ;TO SECOND PARAMETER IN FOLLOWING LINE.
  38. IF \1 > 4.0 ;PUT REVISION NUMBER HERE
  39. WARN "Version \1 or later of 'hardware.inc' is required."
  40. ENDC
  41. ENDM
  42. DEF _VRAM EQU $8000 ; $8000->$9FFF
  43. DEF _VRAM8000 EQU _VRAM
  44. DEF _VRAM8800 EQU _VRAM+$800
  45. DEF _VRAM9000 EQU _VRAM+$1000
  46. DEF _SCRN0 EQU $9800 ; $9800->$9BFF
  47. DEF _SCRN1 EQU $9C00 ; $9C00->$9FFF
  48. DEF _SRAM EQU $A000 ; $A000->$BFFF
  49. DEF _RAM EQU $C000 ; $C000->$CFFF / $C000->$DFFF
  50. DEF _RAMBANK EQU $D000 ; $D000->$DFFF
  51. DEF _OAMRAM EQU $FE00 ; $FE00->$FE9F
  52. DEF _IO EQU $FF00 ; $FF00->$FF7F,$FFFF
  53. DEF _AUD3WAVERAM EQU $FF30 ; $FF30->$FF3F
  54. DEF _HRAM EQU $FF80 ; $FF80->$FFFE
  55. ; *** MBC5 Equates ***
  56. DEF rRAMG EQU $0000 ; $0000->$1fff
  57. DEF rROMB0 EQU $2000 ; $2000->$2fff
  58. DEF rROMB1 EQU $3000 ; $3000->$3fff - If more than 256 ROM banks are present.
  59. DEF rRAMB EQU $4000 ; $4000->$5fff - Bit 3 enables rumble (if present)
  60. ;***************************************************************************
  61. ;*
  62. ;* Custom registers
  63. ;*
  64. ;***************************************************************************
  65. ; --
  66. ; -- P1 ($FF00)
  67. ; -- Register for reading joy pad info. (R/W)
  68. ; --
  69. DEF rP1 EQU $FF00
  70. DEF P1F_5 EQU %00100000 ; P15 out port, set to 0 to get buttons
  71. DEF P1F_4 EQU %00010000 ; P14 out port, set to 0 to get dpad
  72. DEF P1F_3 EQU %00001000 ; P13 in port
  73. DEF P1F_2 EQU %00000100 ; P12 in port
  74. DEF P1F_1 EQU %00000010 ; P11 in port
  75. DEF P1F_0 EQU %00000001 ; P10 in port
  76. DEF P1F_GET_DPAD EQU P1F_5
  77. DEF P1F_GET_BTN EQU P1F_4
  78. DEF P1F_GET_NONE EQU P1F_4 | P1F_5
  79. ; --
  80. ; -- SB ($FF01)
  81. ; -- Serial Transfer Data (R/W)
  82. ; --
  83. DEF rSB EQU $FF01
  84. ; --
  85. ; -- SC ($FF02)
  86. ; -- Serial I/O Control (R/W)
  87. ; --
  88. DEF rSC EQU $FF02
  89. ; --
  90. ; -- DIV ($FF04)
  91. ; -- Divider register (R/W)
  92. ; --
  93. DEF rDIV EQU $FF04
  94. ; --
  95. ; -- TIMA ($FF05)
  96. ; -- Timer counter (R/W)
  97. ; --
  98. DEF rTIMA EQU $FF05
  99. ; --
  100. ; -- TMA ($FF06)
  101. ; -- Timer modulo (R/W)
  102. ; --
  103. DEF rTMA EQU $FF06
  104. ; --
  105. ; -- TAC ($FF07)
  106. ; -- Timer control (R/W)
  107. ; --
  108. DEF rTAC EQU $FF07
  109. DEF TACF_START EQU %00000100
  110. DEF TACF_STOP EQU %00000000
  111. DEF TACF_4KHZ EQU %00000000
  112. DEF TACF_16KHZ EQU %00000011
  113. DEF TACF_65KHZ EQU %00000010
  114. DEF TACF_262KHZ EQU %00000001
  115. ; --
  116. ; -- IF ($FF0F)
  117. ; -- Interrupt Flag (R/W)
  118. ; --
  119. DEF rIF EQU $FF0F
  120. ; --
  121. ; -- AUD1SWEEP/NR10 ($FF10)
  122. ; -- Sweep register (R/W)
  123. ; --
  124. ; -- Bit 6-4 - Sweep Time
  125. ; -- Bit 3 - Sweep Increase/Decrease
  126. ; -- 0: Addition (frequency increases???)
  127. ; -- 1: Subtraction (frequency increases???)
  128. ; -- Bit 2-0 - Number of sweep shift (# 0-7)
  129. ; -- Sweep Time: (n*7.8ms)
  130. ; --
  131. DEF rNR10 EQU $FF10
  132. DEF rAUD1SWEEP EQU rNR10
  133. DEF AUD1SWEEP_UP EQU %00000000
  134. DEF AUD1SWEEP_DOWN EQU %00001000
  135. ; --
  136. ; -- AUD1LEN/NR11 ($FF11)
  137. ; -- Sound length/Wave pattern duty (R/W)
  138. ; --
  139. ; -- Bit 7-6 - Wave Pattern Duty (00:12.5% 01:25% 10:50% 11:75%)
  140. ; -- Bit 5-0 - Sound length data (# 0-63)
  141. ; --
  142. DEF rNR11 EQU $FF11
  143. DEF rAUD1LEN EQU rNR11
  144. ; --
  145. ; -- AUD1ENV/NR12 ($FF12)
  146. ; -- Envelope (R/W)
  147. ; --
  148. ; -- Bit 7-4 - Initial value of envelope
  149. ; -- Bit 3 - Envelope UP/DOWN
  150. ; -- 0: Decrease
  151. ; -- 1: Range of increase
  152. ; -- Bit 2-0 - Number of envelope sweep (# 0-7)
  153. ; --
  154. DEF rNR12 EQU $FF12
  155. DEF rAUD1ENV EQU rNR12
  156. ; --
  157. ; -- AUD1LOW/NR13 ($FF13)
  158. ; -- Frequency low byte (W)
  159. ; --
  160. DEF rNR13 EQU $FF13
  161. DEF rAUD1LOW EQU rNR13
  162. ; --
  163. ; -- AUD1HIGH/NR14 ($FF14)
  164. ; -- Frequency high byte (W)
  165. ; --
  166. ; -- Bit 7 - Initial (when set, sound restarts)
  167. ; -- Bit 6 - Counter/consecutive selection
  168. ; -- Bit 2-0 - Frequency's higher 3 bits
  169. ; --
  170. DEF rNR14 EQU $FF14
  171. DEF rAUD1HIGH EQU rNR14
  172. ; --
  173. ; -- AUD2LEN/NR21 ($FF16)
  174. ; -- Sound Length; Wave Pattern Duty (R/W)
  175. ; --
  176. ; -- see AUD1LEN for info
  177. ; --
  178. DEF rNR21 EQU $FF16
  179. DEF rAUD2LEN EQU rNR21
  180. ; --
  181. ; -- AUD2ENV/NR22 ($FF17)
  182. ; -- Envelope (R/W)
  183. ; --
  184. ; -- see AUD1ENV for info
  185. ; --
  186. DEF rNR22 EQU $FF17
  187. DEF rAUD2ENV EQU rNR22
  188. ; --
  189. ; -- AUD2LOW/NR23 ($FF18)
  190. ; -- Frequency low byte (W)
  191. ; --
  192. DEF rNR23 EQU $FF18
  193. DEF rAUD2LOW EQU rNR23
  194. ; --
  195. ; -- AUD2HIGH/NR24 ($FF19)
  196. ; -- Frequency high byte (W)
  197. ; --
  198. ; -- see AUD1HIGH for info
  199. ; --
  200. DEF rNR24 EQU $FF19
  201. DEF rAUD2HIGH EQU rNR24
  202. ; --
  203. ; -- AUD3ENA/NR30 ($FF1A)
  204. ; -- Sound on/off (R/W)
  205. ; --
  206. ; -- Bit 7 - Sound ON/OFF (1=ON,0=OFF)
  207. ; --
  208. DEF rNR30 EQU $FF1A
  209. DEF rAUD3ENA EQU rNR30
  210. ; --
  211. ; -- AUD3LEN/NR31 ($FF1B)
  212. ; -- Sound length (R/W)
  213. ; --
  214. ; -- Bit 7-0 - Sound length
  215. ; --
  216. DEF rNR31 EQU $FF1B
  217. DEF rAUD3LEN EQU rNR31
  218. ; --
  219. ; -- AUD3LEVEL/NR32 ($FF1C)
  220. ; -- Select output level
  221. ; --
  222. ; -- Bit 6-5 - Select output level
  223. ; -- 00: 0/1 (mute)
  224. ; -- 01: 1/1
  225. ; -- 10: 1/2
  226. ; -- 11: 1/4
  227. ; --
  228. DEF rNR32 EQU $FF1C
  229. DEF rAUD3LEVEL EQU rNR32
  230. ; --
  231. ; -- AUD3LOW/NR33 ($FF1D)
  232. ; -- Frequency low byte (W)
  233. ; --
  234. ; -- see AUD1LOW for info
  235. ; --
  236. DEF rNR33 EQU $FF1D
  237. DEF rAUD3LOW EQU rNR33
  238. ; --
  239. ; -- AUD3HIGH/NR34 ($FF1E)
  240. ; -- Frequency high byte (W)
  241. ; --
  242. ; -- see AUD1HIGH for info
  243. ; --
  244. DEF rNR34 EQU $FF1E
  245. DEF rAUD3HIGH EQU rNR34
  246. ; --
  247. ; -- AUD4LEN/NR41 ($FF20)
  248. ; -- Sound length (R/W)
  249. ; --
  250. ; -- Bit 5-0 - Sound length data (# 0-63)
  251. ; --
  252. DEF rNR41 EQU $FF20
  253. DEF rAUD4LEN EQU rNR41
  254. ; --
  255. ; -- AUD4ENV/NR42 ($FF21)
  256. ; -- Envelope (R/W)
  257. ; --
  258. ; -- see AUD1ENV for info
  259. ; --
  260. DEF rNR42 EQU $FF21
  261. DEF rAUD4ENV EQU rNR42
  262. ; --
  263. ; -- AUD4POLY/NR43 ($FF22)
  264. ; -- Polynomial counter (R/W)
  265. ; --
  266. ; -- Bit 7-4 - Selection of the shift clock frequency of the (scf)
  267. ; -- polynomial counter (0000-1101)
  268. ; -- freq=drf*1/2^scf (not sure)
  269. ; -- Bit 3 - Selection of the polynomial counter's step
  270. ; -- 0: 15 steps
  271. ; -- 1: 7 steps
  272. ; -- Bit 2-0 - Selection of the dividing ratio of frequencies (drf)
  273. ; -- 000: f/4 001: f/8 010: f/16 011: f/24
  274. ; -- 100: f/32 101: f/40 110: f/48 111: f/56 (f=4.194304 Mhz)
  275. ; --
  276. DEF rNR43 EQU $FF22
  277. DEF rAUD4POLY EQU rNR43
  278. ; --
  279. ; -- AUD4GO/NR44 ($FF23)
  280. ; --
  281. ; -- Bit 7 - Inital
  282. ; -- Bit 6 - Counter/consecutive selection
  283. ; --
  284. DEF rNR44 EQU $FF23
  285. DEF rAUD4GO EQU rNR44
  286. ; --
  287. ; -- AUDVOL/NR50 ($FF24)
  288. ; -- Channel control / ON-OFF / Volume (R/W)
  289. ; --
  290. ; -- Bit 7 - Vin->SO2 ON/OFF (Vin??)
  291. ; -- Bit 6-4 - SO2 output level (volume) (# 0-7)
  292. ; -- Bit 3 - Vin->SO1 ON/OFF (Vin??)
  293. ; -- Bit 2-0 - SO1 output level (volume) (# 0-7)
  294. ; --
  295. DEF rNR50 EQU $FF24
  296. DEF rAUDVOL EQU rNR50
  297. DEF AUDVOL_VIN_LEFT EQU %10000000 ; SO2
  298. DEF AUDVOL_VIN_RIGHT EQU %00001000 ; SO1
  299. ; --
  300. ; -- AUDTERM/NR51 ($FF25)
  301. ; -- Selection of Sound output terminal (R/W)
  302. ; --
  303. ; -- Bit 7 - Output sound 4 to SO2 terminal
  304. ; -- Bit 6 - Output sound 3 to SO2 terminal
  305. ; -- Bit 5 - Output sound 2 to SO2 terminal
  306. ; -- Bit 4 - Output sound 1 to SO2 terminal
  307. ; -- Bit 3 - Output sound 4 to SO1 terminal
  308. ; -- Bit 2 - Output sound 3 to SO1 terminal
  309. ; -- Bit 1 - Output sound 2 to SO1 terminal
  310. ; -- Bit 0 - Output sound 0 to SO1 terminal
  311. ; --
  312. DEF rNR51 EQU $FF25
  313. DEF rAUDTERM EQU rNR51
  314. ; SO2
  315. DEF AUDTERM_4_LEFT EQU %10000000
  316. DEF AUDTERM_3_LEFT EQU %01000000
  317. DEF AUDTERM_2_LEFT EQU %00100000
  318. DEF AUDTERM_1_LEFT EQU %00010000
  319. ; SO1
  320. DEF AUDTERM_4_RIGHT EQU %00001000
  321. DEF AUDTERM_3_RIGHT EQU %00000100
  322. DEF AUDTERM_2_RIGHT EQU %00000010
  323. DEF AUDTERM_1_RIGHT EQU %00000001
  324. ; --
  325. ; -- AUDENA/NR52 ($FF26)
  326. ; -- Sound on/off (R/W)
  327. ; --
  328. ; -- Bit 7 - All sound on/off (sets all audio regs to 0!)
  329. ; -- Bit 3 - Sound 4 ON flag (read only)
  330. ; -- Bit 2 - Sound 3 ON flag (read only)
  331. ; -- Bit 1 - Sound 2 ON flag (read only)
  332. ; -- Bit 0 - Sound 1 ON flag (read only)
  333. ; --
  334. DEF rNR52 EQU $FF26
  335. DEF rAUDENA EQU rNR52
  336. DEF AUDENA_ON EQU %10000000
  337. DEF AUDENA_OFF EQU %00000000 ; sets all audio regs to 0!
  338. ; --
  339. ; -- LCDC ($FF40)
  340. ; -- LCD Control (R/W)
  341. ; --
  342. DEF rLCDC EQU $FF40
  343. DEF LCDCF_OFF EQU %00000000 ; LCD Control Operation
  344. DEF LCDCF_ON EQU %10000000 ; LCD Control Operation
  345. DEF LCDCF_WIN9800 EQU %00000000 ; Window Tile Map Display Select
  346. DEF LCDCF_WIN9C00 EQU %01000000 ; Window Tile Map Display Select
  347. DEF LCDCF_WINOFF EQU %00000000 ; Window Display
  348. DEF LCDCF_WINON EQU %00100000 ; Window Display
  349. DEF LCDCF_BG8800 EQU %00000000 ; BG & Window Tile Data Select
  350. DEF LCDCF_BG8000 EQU %00010000 ; BG & Window Tile Data Select
  351. DEF LCDCF_BG9800 EQU %00000000 ; BG Tile Map Display Select
  352. DEF LCDCF_BG9C00 EQU %00001000 ; BG Tile Map Display Select
  353. DEF LCDCF_OBJ8 EQU %00000000 ; OBJ Construction
  354. DEF LCDCF_OBJ16 EQU %00000100 ; OBJ Construction
  355. DEF LCDCF_OBJOFF EQU %00000000 ; OBJ Display
  356. DEF LCDCF_OBJON EQU %00000010 ; OBJ Display
  357. DEF LCDCF_BGOFF EQU %00000000 ; BG Display
  358. DEF LCDCF_BGON EQU %00000001 ; BG Display
  359. ; "Window Character Data Select" follows BG
  360. ; --
  361. ; -- STAT ($FF41)
  362. ; -- LCDC Status (R/W)
  363. ; --
  364. DEF rSTAT EQU $FF41
  365. DEF STATF_LYC EQU %01000000 ; LYC=LY Coincidence (Selectable)
  366. DEF STATF_MODE10 EQU %00100000 ; Mode 10
  367. DEF STATF_MODE01 EQU %00010000 ; Mode 01 (V-Blank)
  368. DEF STATF_MODE00 EQU %00001000 ; Mode 00 (H-Blank)
  369. DEF STATF_LYCF EQU %00000100 ; Coincidence Flag
  370. DEF STATF_HBL EQU %00000000 ; H-Blank
  371. DEF STATF_VBL EQU %00000001 ; V-Blank
  372. DEF STATF_OAM EQU %00000010 ; OAM-RAM is used by system
  373. DEF STATF_LCD EQU %00000011 ; Both OAM and VRAM used by system
  374. DEF STATF_BUSY EQU %00000010 ; When set, VRAM access is unsafe
  375. ; --
  376. ; -- SCY ($FF42)
  377. ; -- Scroll Y (R/W)
  378. ; --
  379. DEF rSCY EQU $FF42
  380. ; --
  381. ; -- SCX ($FF43)
  382. ; -- Scroll X (R/W)
  383. ; --
  384. DEF rSCX EQU $FF43
  385. ; --
  386. ; -- LY ($FF44)
  387. ; -- LCDC Y-Coordinate (R)
  388. ; --
  389. ; -- Values range from 0->153. 144->153 is the VBlank period.
  390. ; --
  391. DEF rLY EQU $FF44
  392. ; --
  393. ; -- LYC ($FF45)
  394. ; -- LY Compare (R/W)
  395. ; --
  396. ; -- When LY==LYC, STATF_LYCF will be set in STAT
  397. ; --
  398. DEF rLYC EQU $FF45
  399. ; --
  400. ; -- DMA ($FF46)
  401. ; -- DMA Transfer and Start Address (W)
  402. ; --
  403. DEF rDMA EQU $FF46
  404. ; --
  405. ; -- BGP ($FF47)
  406. ; -- BG Palette Data (W)
  407. ; --
  408. ; -- Bit 7-6 - Intensity for %11
  409. ; -- Bit 5-4 - Intensity for %10
  410. ; -- Bit 3-2 - Intensity for %01
  411. ; -- Bit 1-0 - Intensity for %00
  412. ; --
  413. DEF rBGP EQU $FF47
  414. ; --
  415. ; -- OBP0 ($FF48)
  416. ; -- Object Palette 0 Data (W)
  417. ; --
  418. ; -- See BGP for info
  419. ; --
  420. DEF rOBP0 EQU $FF48
  421. ; --
  422. ; -- OBP1 ($FF49)
  423. ; -- Object Palette 1 Data (W)
  424. ; --
  425. ; -- See BGP for info
  426. ; --
  427. DEF rOBP1 EQU $FF49
  428. ; --
  429. ; -- WY ($FF4A)
  430. ; -- Window Y Position (R/W)
  431. ; --
  432. ; -- 0 <= WY <= 143
  433. ; -- When WY = 0, the window is displayed from the top edge of the LCD screen.
  434. ; --
  435. DEF rWY EQU $FF4A
  436. ; --
  437. ; -- WX ($FF4B)
  438. ; -- Window X Position (R/W)
  439. ; --
  440. ; -- 7 <= WX <= 166
  441. ; -- When WX = 7, the window is displayed from the left edge of the LCD screen.
  442. ; -- Values of 0-6 and 166 are unreliable due to hardware bugs.
  443. ; --
  444. DEF rWX EQU $FF4B
  445. ; --
  446. ; -- SPEED ($FF4D)
  447. ; -- Select CPU Speed (R/W)
  448. ; --
  449. DEF rKEY1 EQU $FF4D
  450. DEF rSPD EQU rKEY1
  451. DEF KEY1F_DBLSPEED EQU %10000000 ; 0=Normal Speed, 1=Double Speed (R)
  452. DEF KEY1F_PREPARE EQU %00000001 ; 0=No, 1=Prepare (R/W)
  453. ; --
  454. ; -- VBK ($FF4F)
  455. ; -- Select Video RAM Bank (R/W)
  456. ; --
  457. ; -- Bit 0 - Bank Specification (0: Specify Bank 0; 1: Specify Bank 1)
  458. ; --
  459. DEF rVBK EQU $FF4F
  460. ; --
  461. ; -- HDMA1 ($FF51)
  462. ; -- High byte for Horizontal Blanking/General Purpose DMA source address (W)
  463. ; -- CGB Mode Only
  464. ; --
  465. DEF rHDMA1 EQU $FF51
  466. ; --
  467. ; -- HDMA2 ($FF52)
  468. ; -- Low byte for Horizontal Blanking/General Purpose DMA source address (W)
  469. ; -- CGB Mode Only
  470. ; --
  471. DEF rHDMA2 EQU $FF52
  472. ; --
  473. ; -- HDMA3 ($FF53)
  474. ; -- High byte for Horizontal Blanking/General Purpose DMA destination address (W)
  475. ; -- CGB Mode Only
  476. ; --
  477. DEF rHDMA3 EQU $FF53
  478. ; --
  479. ; -- HDMA4 ($FF54)
  480. ; -- Low byte for Horizontal Blanking/General Purpose DMA destination address (W)
  481. ; -- CGB Mode Only
  482. ; --
  483. DEF rHDMA4 EQU $FF54
  484. ; --
  485. ; -- HDMA5 ($FF55)
  486. ; -- Transfer length (in tiles minus 1)/mode/start for Horizontal Blanking, General Purpose DMA (R/W)
  487. ; -- CGB Mode Only
  488. ; --
  489. DEF rHDMA5 EQU $FF55
  490. DEF HDMA5F_MODE_GP EQU %00000000 ; General Purpose DMA (W)
  491. DEF HDMA5F_MODE_HBL EQU %10000000 ; HBlank DMA (W)
  492. ; -- Once DMA has started, use HDMA5F_BUSY to check when the transfer is complete
  493. DEF HDMA5F_BUSY EQU %10000000 ; 0=Busy (DMA still in progress), 1=Transfer complete (R)
  494. ; --
  495. ; -- RP ($FF56)
  496. ; -- Infrared Communications Port (R/W)
  497. ; -- CGB Mode Only
  498. ; --
  499. DEF rRP EQU $FF56
  500. DEF RPF_ENREAD EQU %11000000
  501. DEF RPF_DATAIN EQU %00000010 ; 0=Receiving IR Signal, 1=Normal
  502. DEF RPF_WRITE_HI EQU %00000001
  503. DEF RPF_WRITE_LO EQU %00000000
  504. ; --
  505. ; -- BCPS ($FF68)
  506. ; -- Background Color Palette Specification (R/W)
  507. ; --
  508. DEF rBCPS EQU $FF68
  509. DEF BCPSF_AUTOINC EQU %10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing)
  510. ; --
  511. ; -- BCPD ($FF69)
  512. ; -- Background Color Palette Data (R/W)
  513. ; --
  514. DEF rBCPD EQU $FF69
  515. ; --
  516. ; -- OCPS ($FF6A)
  517. ; -- Object Color Palette Specification (R/W)
  518. ; --
  519. DEF rOCPS EQU $FF6A
  520. DEF OCPSF_AUTOINC EQU %10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing)
  521. ; --
  522. ; -- OCPD ($FF6B)
  523. ; -- Object Color Palette Data (R/W)
  524. ; --
  525. DEF rOCPD EQU $FF6B
  526. ; --
  527. ; -- SMBK/SVBK ($FF70)
  528. ; -- Select Main RAM Bank (R/W)
  529. ; --
  530. ; -- Bit 2-0 - Bank Specification (0,1: Specify Bank 1; 2-7: Specify Banks 2-7)
  531. ; --
  532. DEF rSVBK EQU $FF70
  533. DEF rSMBK EQU rSVBK
  534. ; --
  535. ; -- PCM12 ($FF76)
  536. ; -- Sound channel 1&2 PCM amplitude (R)
  537. ; --
  538. ; -- Bit 7-4 - Copy of sound channel 2's PCM amplitude
  539. ; -- Bit 3-0 - Copy of sound channel 1's PCM amplitude
  540. ; --
  541. DEF rPCM12 EQU $FF76
  542. ; --
  543. ; -- PCM34 ($FF77)
  544. ; -- Sound channel 3&4 PCM amplitude (R)
  545. ; --
  546. ; -- Bit 7-4 - Copy of sound channel 4's PCM amplitude
  547. ; -- Bit 3-0 - Copy of sound channel 3's PCM amplitude
  548. ; --
  549. DEF rPCM34 EQU $FF77
  550. ; --
  551. ; -- IE ($FFFF)
  552. ; -- Interrupt Enable (R/W)
  553. ; --
  554. DEF rIE EQU $FFFF
  555. DEF IEF_HILO EQU %00010000 ; Transition from High to Low of Pin number P10-P13
  556. DEF IEF_SERIAL EQU %00001000 ; Serial I/O transfer end
  557. DEF IEF_TIMER EQU %00000100 ; Timer Overflow
  558. DEF IEF_STAT EQU %00000010 ; STAT
  559. DEF IEF_VBLANK EQU %00000001 ; V-Blank
  560. ;***************************************************************************
  561. ;*
  562. ;* Flags common to multiple sound channels
  563. ;*
  564. ;***************************************************************************
  565. ; --
  566. ; -- Square wave duty cycle
  567. ; --
  568. ; -- Can be used with AUD1LEN and AUD2LEN
  569. ; -- See AUD1LEN for more info
  570. ; --
  571. DEF AUDLEN_DUTY_12_5 EQU %00000000 ; 12.5%
  572. DEF AUDLEN_DUTY_25 EQU %01000000 ; 25%
  573. DEF AUDLEN_DUTY_50 EQU %10000000 ; 50%
  574. DEF AUDLEN_DUTY_75 EQU %11000000 ; 75%
  575. ; --
  576. ; -- Audio envelope flags
  577. ; --
  578. ; -- Can be used with AUD1ENV, AUD2ENV, AUD4ENV
  579. ; -- See AUD1ENV for more info
  580. ; --
  581. DEF AUDENV_UP EQU %00001000
  582. DEF AUDENV_DOWN EQU %00000000
  583. ; --
  584. ; -- Audio trigger flags
  585. ; --
  586. ; -- Can be used with AUD1HIGH, AUD2HIGH, AUD3HIGH
  587. ; -- See AUD1HIGH for more info
  588. ; --
  589. DEF AUDHIGH_RESTART EQU %10000000
  590. DEF AUDHIGH_LENGTH_ON EQU %01000000
  591. DEF AUDHIGH_LENGTH_OFF EQU %00000000
  592. ;***************************************************************************
  593. ;*
  594. ;* CPU values on bootup (a=type, b=qualifier)
  595. ;*
  596. ;***************************************************************************
  597. DEF BOOTUP_A_DMG EQU $01 ; Dot Matrix Game
  598. DEF BOOTUP_A_CGB EQU $11 ; Color GameBoy
  599. DEF BOOTUP_A_MGB EQU $FF ; Mini GameBoy (Pocket GameBoy)
  600. ; if a=BOOTUP_A_CGB, bit 0 in b can be checked to determine if real CGB or
  601. ; other system running in GBC mode
  602. DEF BOOTUP_B_CGB EQU %00000000
  603. DEF BOOTUP_B_AGB EQU %00000001 ; GBA, GBA SP, Game Boy Player, or New GBA SP
  604. ;***************************************************************************
  605. ;*
  606. ;* Cart related
  607. ;*
  608. ;***************************************************************************
  609. ; $0143 Color GameBoy compatibility code
  610. DEF CART_COMPATIBLE_DMG EQU $00
  611. DEF CART_COMPATIBLE_DMG_GBC EQU $80
  612. DEF CART_COMPATIBLE_GBC EQU $C0
  613. ; $0146 GameBoy/Super GameBoy indicator
  614. DEF CART_INDICATOR_GB EQU $00
  615. DEF CART_INDICATOR_SGB EQU $03
  616. ; $0147 Cartridge type
  617. DEF CART_ROM EQU $00
  618. DEF CART_ROM_MBC1 EQU $01
  619. DEF CART_ROM_MBC1_RAM EQU $02
  620. DEF CART_ROM_MBC1_RAM_BAT EQU $03
  621. DEF CART_ROM_MBC2 EQU $05
  622. DEF CART_ROM_MBC2_BAT EQU $06
  623. DEF CART_ROM_RAM EQU $08
  624. DEF CART_ROM_RAM_BAT EQU $09
  625. DEF CART_ROM_MMM01 EQU $0B
  626. DEF CART_ROM_MMM01_RAM EQU $0C
  627. DEF CART_ROM_MMM01_RAM_BAT EQU $0D
  628. DEF CART_ROM_MBC3_BAT_RTC EQU $0F
  629. DEF CART_ROM_MBC3_RAM_BAT_RTC EQU $10
  630. DEF CART_ROM_MBC3 EQU $11
  631. DEF CART_ROM_MBC3_RAM EQU $12
  632. DEF CART_ROM_MBC3_RAM_BAT EQU $13
  633. DEF CART_ROM_MBC5 EQU $19
  634. DEF CART_ROM_MBC5_BAT EQU $1A
  635. DEF CART_ROM_MBC5_RAM_BAT EQU $1B
  636. DEF CART_ROM_MBC5_RUMBLE EQU $1C
  637. DEF CART_ROM_MBC5_RAM_RUMBLE EQU $1D
  638. DEF CART_ROM_MBC5_RAM_BAT_RUMBLE EQU $1E
  639. DEF CART_ROM_MBC7_RAM_BAT_GYRO EQU $22
  640. DEF CART_ROM_POCKET_CAMERA EQU $FC
  641. DEF CART_ROM_BANDAI_TAMA5 EQU $FD
  642. DEF CART_ROM_HUDSON_HUC3 EQU $FE
  643. DEF CART_ROM_HUDSON_HUC1 EQU $FF
  644. ; $0148 ROM size
  645. ; these are kilobytes
  646. DEF CART_ROM_32KB EQU $00 ; 2 banks
  647. DEF CART_ROM_64KB EQU $01 ; 4 banks
  648. DEF CART_ROM_128KB EQU $02 ; 8 banks
  649. DEF CART_ROM_256KB EQU $03 ; 16 banks
  650. DEF CART_ROM_512KB EQU $04 ; 32 banks
  651. DEF CART_ROM_1024KB EQU $05 ; 64 banks
  652. DEF CART_ROM_2048KB EQU $06 ; 128 banks
  653. DEF CART_ROM_4096KB EQU $07 ; 256 banks
  654. DEF CART_ROM_8192KB EQU $08 ; 512 banks
  655. DEF CART_ROM_1152KB EQU $52 ; 72 banks
  656. DEF CART_ROM_1280KB EQU $53 ; 80 banks
  657. DEF CART_ROM_1536KB EQU $54 ; 96 banks
  658. ; $0149 SRAM size
  659. ; these are kilobytes
  660. DEF CART_SRAM_NONE EQU 0
  661. DEF CART_SRAM_2KB EQU 1 ; 1 incomplete bank
  662. DEF CART_SRAM_8KB EQU 2 ; 1 bank
  663. DEF CART_SRAM_32KB EQU 3 ; 4 banks
  664. DEF CART_SRAM_128KB EQU 4 ; 16 banks
  665. DEF CART_SRAM_ENABLE EQU $0A
  666. DEF CART_SRAM_DISABLE EQU $00
  667. ; $014A Destination code
  668. DEF CART_DEST_JAPANESE EQU $00
  669. DEF CART_DEST_NON_JAPANESE EQU $01
  670. ;***************************************************************************
  671. ;*
  672. ;* Keypad related
  673. ;*
  674. ;***************************************************************************
  675. DEF PADF_DOWN EQU $80
  676. DEF PADF_UP EQU $40
  677. DEF PADF_LEFT EQU $20
  678. DEF PADF_RIGHT EQU $10
  679. DEF PADF_START EQU $08
  680. DEF PADF_SELECT EQU $04
  681. DEF PADF_B EQU $02
  682. DEF PADF_A EQU $01
  683. DEF PADB_DOWN EQU $7
  684. DEF PADB_UP EQU $6
  685. DEF PADB_LEFT EQU $5
  686. DEF PADB_RIGHT EQU $4
  687. DEF PADB_START EQU $3
  688. DEF PADB_SELECT EQU $2
  689. DEF PADB_B EQU $1
  690. DEF PADB_A EQU $0
  691. ;***************************************************************************
  692. ;*
  693. ;* Screen related
  694. ;*
  695. ;***************************************************************************
  696. DEF SCRN_X EQU 160 ; Width of screen in pixels
  697. DEF SCRN_Y EQU 144 ; Height of screen in pixels
  698. DEF SCRN_X_B EQU 20 ; Width of screen in bytes
  699. DEF SCRN_Y_B EQU 18 ; Height of screen in bytes
  700. DEF SCRN_VX EQU 256 ; Virtual width of screen in pixels
  701. DEF SCRN_VY EQU 256 ; Virtual height of screen in pixels
  702. DEF SCRN_VX_B EQU 32 ; Virtual width of screen in bytes
  703. DEF SCRN_VY_B EQU 32 ; Virtual height of screen in bytes
  704. ;***************************************************************************
  705. ;*
  706. ;* OAM related
  707. ;*
  708. ;***************************************************************************
  709. ; OAM attributes
  710. ; each entry in OAM RAM is 4 bytes (sizeof_OAM_ATTRS)
  711. RSRESET
  712. DEF OAMA_Y RB 1 ; y pos
  713. DEF OAMA_X RB 1 ; x pos
  714. DEF OAMA_TILEID RB 1 ; tile id
  715. DEF OAMA_FLAGS RB 1 ; flags (see below)
  716. DEF sizeof_OAM_ATTRS RB 0
  717. DEF OAM_COUNT EQU 40 ; number of OAM entries in OAM RAM
  718. ; flags
  719. DEF OAMF_PRI EQU %10000000 ; Priority
  720. DEF OAMF_YFLIP EQU %01000000 ; Y flip
  721. DEF OAMF_XFLIP EQU %00100000 ; X flip
  722. DEF OAMF_PAL0 EQU %00000000 ; Palette number; 0,1 (DMG)
  723. DEF OAMF_PAL1 EQU %00010000 ; Palette number; 0,1 (DMG)
  724. DEF OAMF_BANK0 EQU %00000000 ; Bank number; 0,1 (GBC)
  725. DEF OAMF_BANK1 EQU %00001000 ; Bank number; 0,1 (GBC)
  726. DEF OAMF_PALMASK EQU %00000111 ; Palette (GBC)
  727. DEF OAMB_PRI EQU 7 ; Priority
  728. DEF OAMB_YFLIP EQU 6 ; Y flip
  729. DEF OAMB_XFLIP EQU 5 ; X flip
  730. DEF OAMB_PAL1 EQU 4 ; Palette number; 0,1 (DMG)
  731. DEF OAMB_BANK1 EQU 3 ; Bank number; 0,1 (GBC)
  732. ;*
  733. ;* Nintendo scrolling logo
  734. ;* (Code won't work on a real GameBoy)
  735. ;* (if next lines are altered.)
  736. MACRO NINTENDO_LOGO
  737. DB $CE,$ED,$66,$66,$CC,$0D,$00,$0B,$03,$73,$00,$83,$00,$0C,$00,$0D
  738. DB $00,$08,$11,$1F,$88,$89,$00,$0E,$DC,$CC,$6E,$E6,$DD,$DD,$D9,$99
  739. DB $BB,$BB,$67,$63,$6E,$0E,$EC,$CC,$DD,$DC,$99,$9F,$BB,$B9,$33,$3E
  740. ENDM
  741. ; Deprecated constants. Please avoid using.
  742. DEF IEF_LCDC EQU %00000010 ; LCDC (see STAT)
  743. ENDC ;HARDWARE_INC