Yu-Gi-Oh! Duel Monsters II: Dark duel Stories:ROM map

From Data Crystal
Jump to navigation Jump to search

Bank 0

rst 00

ROM0:0000 F3               di   
ROM0:0001 C3 9B 17         jp   179B

rst 08

ROM0:0008 C3 D5 11         jp   11D5

rst 10 (error trap)

ROM0:0010 18 FE            jr   0010

rst 18 (error trap)

ROM0:0018 18 FE            jr   0018

rst 20 (error trap)

ROM0:0020 18 FE            jr   0020

rst 28 (error trap)

ROM0:0028 18 FE            jr   0028

rst 30 (error trap)

ROM0:0030 18 FE            jr   0030

rst 38 (error trap)

ROM0:0038 18 FE            jr   0038

rst 40 (vblank)

ROM0:0040 C3 36 04         jp   0436

rst 48 (LCD)

ROM0:0048 C3 0F DD         jp   DD0F

rst 50 (timer)

ROM0:0050 C3 2C 17         jp   172C

rst 58 (serial)

ROM0:0058 C3 EC 01         jp   01EC

rst 60 (joypad)

ROM0:0060 18 FE            jr   0060

ROM start

ROM0:0100 00               nop  
ROM0:0101 C3 50 01         jp   0150
ROM0:0150 E0 DD            ld   (ff00+DD),a	// System running the game
ROM0:0152 21 00 D0         ld   hl,D000
ROM0:0155 F9               ld   sp,hl
ROM0:0156 21 A0 D5         ld   hl,D5A0
ROM0:0159 11 00 00         ld   de,0000
ROM0:015C 0E 00            ld   c,00
ROM0:015E 1A               ld   a,(de)
ROM0:015F 22               ldi  (hl),a
ROM0:0160 13               inc  de
ROM0:0161 0D               dec  c
ROM0:0162 20 FA            jr   nz,015E
ROM0:0164 0E 00            ld   c,00
ROM0:0166 1A               ld   a,(de)
ROM0:0167 22               ldi  (hl),a
ROM0:0168 13               inc  de
ROM0:0169 0D               dec  c
ROM0:016A 20 FA            jr   nz,0166
ROM0:016C 0E 00            ld   c,00
ROM0:016E 1A               ld   a,(de)
ROM0:016F 22               ldi  (hl),a
ROM0:0170 13               inc  de
ROM0:0171 0D               dec  c
ROM0:0172 20 FA            jr   nz,016E
ROM0:0174 CD 22 12         call 1222		// Initialize Bank, enable Interrupts
ROM0:0177 CF               rst  08
ROM0:0178 07               rlca 
ROM0:0179 04               inc  b
ROM0:017A CD F5 31         call 31F5		// (DD07) = 0
ROM0:017D 3E 00            ld   a,00
ROM0:017F CF               rst  08

Wait for vblank

  • 0x436-0x45E - Wait for vblank
ROM0:0436 F5               push af
ROM0:0437 E5               push hl
ROM0:0438 C5               push bc
ROM0:0439 D5               push de
ROM0:043A 06 00            ld   b,00
ROM0:043C FA 7D D8         ld   a,(D87D)
ROM0:043F 4F               ld   c,a
ROM0:0440 21 48 04         ld   hl,0448
ROM0:0443 09               add  hl,bc
ROM0:0444 2A               ldi  a,(hl)
ROM0:0445 66               ld   h,(hl)
ROM0:0446 6F               ld   l,a
ROM0:0447 E9               jp   hl
ROM0:0448 66               ld   h,(hl)
ROM0:0449 04               inc  b
ROM0:044A 7F               ld   a,a
ROM0:044B 04               inc  b
ROM0:044C A5               and  l
ROM0:044D 04               inc  b
ROM0:044E CE 04            adc  a,04
ROM0:0450 41               ld   b,c
ROM0:0451 05               dec  b
ROM0:0452 F0 06            ld   a,(ff00+06)		// TIMEMOD
ROM0:0454 48               ld   c,b
ROM0:0455 08 22 09         ld   (0922),sp
ROM0:0458 68               ld   l,b
ROM0:0459 0A               ld   a,(bc)
ROM0:045A C0               ret  nz
ROM0:045B 0B               dec  bc
ROM0:045C 61               ld   h,c
ROM0:045D 0C               inc  c
ROM0:045E C3 30 4C         jp   4C30

0:0F16 (called by Main Menu)

  • 0xF16-0xF33 - ? (called by Main Menu)
ROM0:0F16 F5               push af
ROM0:0F17 C5               push bc
ROM0:0F18 E5               push hl
ROM0:0F19 EA 7C D8         ld   (D87C),a
ROM0:0F1C 4F               ld   c,a
ROM0:0F1D 06 00            ld   b,00
ROM0:0F1F 21 34 0F         ld   hl,0F34
ROM0:0F22 09               add  hl,bc
ROM0:0F23 2A               ldi  a,(hl)
ROM0:0F24 66               ld   h,(hl)
ROM0:0F25 6F               ld   l,a
ROM0:0F26 01 2B 0F         ld   bc,0F2B
ROM0:0F29 C5               push bc
ROM0:0F2A E9               jp   hl
ROM0:0F2B 3E 00            ld   a,00
ROM0:0F2D EA 7B D8         ld   (D87B),a
ROM0:0F30 E1               pop  hl
ROM0:0F31 C1               pop  bc
ROM0:0F32 F1               pop  af
ROM0:0F33 C9               ret  

0:1107 (call 0:1881)

ROM0:1107 F5               push af
ROM0:1108 CD 81 18         call 1881
          80 E4

0:110D (reti from 0:1881)

ROM0:110D CD 9B 17         call 179B
ROM0:1110 CD 60 18         call 1860
          80 E4
ROM0:1115 28 F6            jr   z,110D
ROM0:1117 F1               pop  af
ROM0:1118 C9               ret

rst 08 instructions

  • 0x11D5-0x120A - rst 08 jumps here: bank switch, load pointer to next instructions
ROM0:11D5 F5               push af
ROM0:11D6 E8 FD            add  sp,FD
ROM0:11D8 F5               push af
ROM0:11D9 E5               push hl
ROM0:11DA C5               push bc
ROM0:11DB D5               push de
ROM0:11DC F8 06            ld   hl,sp+06
ROM0:11DE 54               ld   d,h
ROM0:11DF 5D               ld   e,l
ROM0:11E0 F8 0E            ld   hl,sp+0E
ROM0:11E2 3A               ldd  a,(hl)
ROM0:11E3 47               ld   b,a
ROM0:11E4 3A               ldd  a,(hl)
ROM0:11E5 4F               ld   c,a
ROM0:11E6 FA 00 40         ld   a,(4000)	// Load current Bank in accumulator
ROM0:11E9 32               ldd  (hl),a
ROM0:11EA 7E               ld   a,(hl)
ROM0:11EB 12               ld   (de),a
ROM0:11EC 3E 12            ld   a,12
ROM0:11EE 32               ldd  (hl),a
ROM0:11EF 3E 0B            ld   a,0B
ROM0:11F1 32               ldd  (hl),a
ROM0:11F2 0A               ld   a,(bc)
ROM0:11F3 5F               ld   e,a
ROM0:11F4 03               inc  bc
ROM0:11F5 16 40            ld   d,40
ROM0:11F7 0A               ld   a,(bc)
ROM0:11F8 03               inc  bc
ROM0:11F9 EA 00 20         ld   (2000),a	// Bank switch
ROM0:11FC 1A               ld   a,(de)
ROM0:11FD 32               ldd  (hl),a
ROM0:11FE 1D               dec  e
ROM0:11FF 1A               ld   a,(de)
ROM0:1200 77               ld   (hl),a		// Address to return to
ROM0:1201 F8 0D            ld   hl,sp+0D
ROM0:1203 79               ld   a,c
ROM0:1204 22               ldi  (hl),a
ROM0:1205 70               ld   (hl),b
ROM0:1206 D1               pop  de
ROM0:1207 C1               pop  bc
ROM0:1208 E1               pop  hl
ROM0:1209 F1               pop  af
ROM0:120A C9               ret

Initialize Bank and enable Interrupts

ROM0:1222 F5               push af
ROM0:1223 F3               di   
ROM0:1224 3E 00            ld   a,00
ROM0:1226 EA 00 20         ld   (2000),a		;ROM Bank 0
ROM0:1229 3E 00            ld   a,00
ROM0:122B EA 00 30         ld   (3000),a
ROM0:122E 3E 00            ld   a,00
ROM0:1230 EA 00 40         ld   (4000),a		;RAM Bank 0
ROM0:1233 3E 00            ld   a,00
ROM0:1235 E0 4F            ld   (ff00+4F),a
ROM0:1237 FB               ei   
ROM0:1238 F1               pop  af
ROM0:1239 C9               ret

Bank switch

  • 0x123A-0x123D - Bank switch
ROM0:123A EA 00 20         ld   (2000),a
ROM0:123D C9               ret

0:13BE (to document)

  • 0x13BE-0x13E3 - ?
ROM0:13BE F5               push af
ROM0:13BF E5               push hl
ROM0:13C0 D5               push de
ROM0:13C1 16 00            ld   d,00
ROM0:13C3 CB 23            sla  e
ROM0:13C5 CB 23            sla  e
ROM0:13C7 21 00 D5         ld   hl,D500
ROM0:13CA 19               add  hl,de		// hl = D500 + (e × 4)
ROM0:13CB D1               pop  de
ROM0:13CC 79               ld   a,c
ROM0:13CD 22               ldi  (hl),a
ROM0:13CE 78               ld   a,b
ROM0:13CF 22               ldi  (hl),a
ROM0:13D0 7A               ld   a,d
ROM0:13D1 22               ldi  (hl),a
ROM0:13D2 3E 00            ld   a,00
ROM0:13D4 22               ldi  (hl),a
ROM0:13D5 79               ld   a,c
ROM0:13D6 22               ldi  (hl),a
ROM0:13D7 78               ld   a,b
ROM0:13D8 C6 08            add  a,08
ROM0:13DA 22               ldi  (hl),a
ROM0:13DB 7A               ld   a,d
ROM0:13DC C6 02            add  a,02
ROM0:13DE 22               ldi  (hl),a
ROM0:13DF 36 00            ld   (hl),00
ROM0:13E1 E1               pop  hl
ROM0:13E2 F1               pop  af
ROM0:13E3 C9               ret


  • 0x1403-0x1419 - ?
ROM0:1403 F5               push af
ROM0:1404 C5               push bc
ROM0:1405 1E 00            ld   e,00
ROM0:1407 0E 08            ld   c,08
ROM0:1409 CB 22            sla  d
ROM0:140B CB 13            rl   e
ROM0:140D 7B               ld   a,e
ROM0:140E B8               cp   b
ROM0:140F 38 03            jr   c,1414
ROM0:1411 90               sub  b
ROM0:1412 5F               ld   e,a
ROM0:1413 14               inc  d
ROM0:1414 0D               dec  c
ROM0:1415 20 F2            jr   nz,1409
ROM0:1417 C1               pop  bc
ROM0:1418 F1               pop  af
ROM0:1419 C9               ret

? operation

  • 0x14A2-0x14C1 - ? operation
ROM0:14A2 F5               push af
ROM0:14A3 78               ld   a,b
ROM0:14A4 BA               cp   d
ROM0:14A5 20 0B            jr   nz,14B2		// If(PRN ≠ b), jump to 0:14B2
ROM0:14A7 79               ld   a,c
ROM0:14A8 BB               cp   e
ROM0:14A9 20 07            jr   nz,14B2		// If(e ≠ c), jump to 0:14B2
ROM0:14AB 01 00 00         ld   bc,0000
ROM0:14AE 1E 01            ld   e,01
ROM0:14B0 18 0E            jr   14C0		// Else bc = 0, e = 1, and get out of this function
ROM0:14B2 7B               ld   a,e
ROM0:14B3 91               sub  c
ROM0:14B4 27               daa  
ROM0:14B5 4F               ld   c,a
ROM0:14B6 7A               ld   a,d
ROM0:14B7 98               sbc  b
ROM0:14B8 27               daa  
ROM0:14B9 47               ld   b,a		// b = PRN - ((max - min) + 1)
ROM0:14BA 1E 02            ld   e,02
ROM0:14BC 30 02            jr   nc,14C0
ROM0:14BE 1E 00            ld   e,00
ROM0:14C0 F1               pop  af
ROM0:14C1 C9               ret  

0:179B (to document)

  • 0x179B-0x180A - ?
ROM0:179B E5               push hl
ROM0:179C 21 FF FF         ld   hl,FFFF
ROM0:179F CB 96            res  2,(hl)
ROM0:17A1 F5               push af
ROM0:17A2 C5               push bc
ROM0:17A3 D5               push de
ROM0:17A4 F3               di   
ROM0:17A5 F0 DF            ld   a,(ff00+DF)
ROM0:17A7 4F               ld   c,a
ROM0:17A8 D6 E0            sub  a,E0
ROM0:17AA 47               ld   b,a
ROM0:17AB 07               rlca 
ROM0:17AC 80               add  b
ROM0:17AD 5F               ld   e,a
ROM0:17AE 3E 00            ld   a,00
ROM0:17B0 E2               ld   (ff00+c),a
ROM0:17B1 0C               inc  c
ROM0:17B2 79               ld   a,c
ROM0:17B3 FE E4            cp   a,E4
ROM0:17B5 20 02            jr   nz,17B9
ROM0:17B7 0E E0            ld   c,E0
ROM0:17B9 F2               ld   a,(ff00+c)
ROM0:17BA FE 01            cp   a,01
ROM0:17BC 20 F3            jr   nz,17B1
ROM0:17BE 79               ld   a,c
ROM0:17BF E0 DF            ld   (ff00+DF),a
ROM0:17C1 3E 02            ld   a,02
ROM0:17C3 E2               ld   (ff00+c),a
ROM0:17C4 3E E8            ld   a,E8
ROM0:17C6 83               add  e
ROM0:17C7 4F               ld   c,a
ROM0:17C8 F8 00            ld   hl,sp+00
ROM0:17CA 7D               ld   a,l
ROM0:17CB E2               ld   (ff00+c),a
ROM0:17CC 0C               inc  c
ROM0:17CD 7C               ld   a,h
ROM0:17CE E2               ld   (ff00+c),a
ROM0:17CF 0C               inc  c
ROM0:17D0 FA 00 40         ld   a,(4000)
ROM0:17D3 E2               ld   (ff00+c),a
ROM0:17D4 F0 DF            ld   a,(ff00+DF)
ROM0:17D6 D6 E0            sub  a,E0
ROM0:17D8 47               ld   b,a
ROM0:17D9 07               rlca 
ROM0:17DA 80               add  b
ROM0:17DB 5F               ld   e,a
ROM0:17DC C6 E8            add  a,E8
ROM0:17DE 4F               ld   c,a
ROM0:17DF F2               ld   a,(ff00+c)
ROM0:17E0 6F               ld   l,a
ROM0:17E1 0C               inc  c
ROM0:17E2 F2               ld   a,(ff00+c)
ROM0:17E3 67               ld   h,a
ROM0:17E4 F9               ld   sp,hl
ROM0:17E5 0C               inc  c
ROM0:17E6 F2               ld   a,(ff00+c)
ROM0:17E7 EA 00 20         ld   (2000),a
ROM0:17EA 16 00            ld   d,00
ROM0:17EC 21 EF 16         ld   hl,16EF
ROM0:17EF 19               add  hl,de
ROM0:17F0 7E               ld   a,(hl)
ROM0:17F1 E0 05            ld   (ff00+05),a		// TIMECNT
ROM0:17F3 2A               ldi  a,(hl)
ROM0:17F4 E0 06            ld   (ff00+06),a		// TIMEMOD
ROM0:17F6 2A               ldi  a,(hl)
ROM0:17F7 E0 07            ld   (ff00+07),a		// TIMCONT
ROM0:17F9 7E               ld   a,(hl)
ROM0:17FA E0 07            ld   (ff00+07),a
ROM0:17FC D1               pop  de
ROM0:17FD C1               pop  bc
ROM0:17FE F1               pop  af
ROM0:17FF 21 0F FF         ld   hl,FF0F
ROM0:1802 CB 96            res  2,(hl)
ROM0:1804 2E FF            ld   l,FF
ROM0:1806 CB D6            set  2,(hl)
ROM0:1808 E1               pop  hl
ROM0:1809 D9               reti 
ROM0:180A C9               ret

0:1832 (error trap)

ROM0:1832 18 FE            jr   1832


ROM0:1881 F5               push af
ROM0:1882 C5               push bc
ROM0:1883 D5               push de
ROM0:1884 E5               push hl
ROM0:1885 F8 08            ld   hl,sp+08
ROM0:1887 2A               ldi  a,(hl)
ROM0:1888 5F               ld   e,a
ROM0:1889 56               ld   d,(hl)
ROM0:188A 1A               ld   a,(de)
ROM0:188B 47               ld   b,a
ROM0:188C 13               inc  de
ROM0:188D 1A               ld   a,(de)
ROM0:188E 4F               ld   c,a
ROM0:188F 13               inc  de
ROM0:1890 7A               ld   a,d
ROM0:1891 32               ldd  (hl),a
ROM0:1892 73               ld   (hl),e
ROM0:1893 F3               di   
ROM0:1894 3E FF            ld   a,FF
ROM0:1896 A8               xor  b
ROM0:1897 47               ld   b,a
ROM0:1898 F2               ld   a,(ff00+c)
ROM0:1899 A0               and  b
ROM0:189A E2               ld   (ff00+c),a
ROM0:189B E1               pop  hl
ROM0:189C D1               pop  de
ROM0:189D C1               pop  bc
ROM0:189E F1               pop  af
ROM0:189F D9               reti 
ROM0:18A0 C9               ret

0:1CE4 (to document)

  • 0x1CE4-0x1CEE - ?
ROM0:1CE4 F5               push af
ROM0:1CE5 78               ld   a,b
ROM0:1CE6 EA 6B DA         ld   (DA6B),a
ROM0:1CE9 79               ld   a,c
ROM0:1CEA EA 6C DA         ld   (DA6C),a
ROM0:1CED F1               pop  af
ROM0:1CEE C9               ret

Write Fusion Monster ID to the selected area

ROM0:1D0F F5               push af
ROM0:1D10 C5               push bc
ROM0:1D11 E5               push hl
ROM0:1D12 CD 4A 1D         call 1D4A
ROM0:1D15 60               ld   h,b
ROM0:1D16 69               ld   l,c
ROM0:1D17 FA 6D DA         ld   a,(DA6D)
ROM0:1D1A 22               ldi  (hl),a       ;Copy monster ID from wDA6D to the selected area
ROM0:1D1B FA 6E DA         ld   a,(DA6E)
ROM0:1D1E 22               ldi  (hl),a
ROM0:1D1F FA 6F DA         ld   a,(DA6F)
ROM0:1D22 22               ldi  (hl),a       ;Copy card flags from wDA6F to the selected area
ROM0:1D23 E1               pop  hl
ROM0:1D24 C1               pop  bc
ROM0:1D25 F1               pop  af
ROM0:1D26 C9               ret  
ROM0:1D27 F5               push af
ROM0:1D28 C5               push bc
ROM0:1D29 E5               push hl
ROM0:1D2A CD 4A 1D         call 1D4A
ROM0:1D2D 60               ld   h,b


ROM0:1D2E 69               ld   l,c
ROM0:1D2F 2A               ldi  a,(hl)
ROM0:1D30 EA 6D DA         ld   (DA6D),a
ROM0:1D33 2A               ldi  a,(hl)
ROM0:1D34 EA 6E DA         ld   (DA6E),a
ROM0:1D37 2A               ldi  a,(hl)
ROM0:1D38 EA 6F DA         ld   (DA6F),a
ROM0:1D3B E1               pop  hl
ROM0:1D3C C1               pop  bc
ROM0:1D3D F1               pop  af
ROM0:1D3E C9               ret  

Call Fusion check

ROM0:1D3F F5               push af
ROM0:1D40 C5               push bc
ROM0:1D41 CF               rst  08
ROM0:1D42 05               dec  b
ROM0:1D43 09               add  hl,bc
ROM0:1D44 CD 0F 1D         call 1D0F
ROM0:1D47 C1               pop  bc
ROM0:1D48 F1               pop  af
ROM0:1D49 C9               ret  


ROM0:1D4A F5               push af
ROM0:1D4B E5               push hl
ROM0:1D4C 06 00            ld   b,00
ROM0:1D4E FA 6C DA         ld   a,(DA6C)
ROM0:1D51 4F               ld   c,a
ROM0:1D52 CB 21            sla  c
ROM0:1D54 21 72 1D         ld   hl,1D72
ROM0:1D57 09               add  hl,bc
ROM0:1D58 2A               ldi  a,(hl)
ROM0:1D59 66               ld   h,(hl)
ROM0:1D5A 6F               ld   l,a
ROM0:1D5B E5               push hl
ROM0:1D5C 06 00            ld   b,00
ROM0:1D5E FA 6B DA         ld   a,(DA6B)
ROM0:1D61 4F               ld   c,a
ROM0:1D62 CB 21            sla  c
ROM0:1D64 21 7A 1D         ld   hl,1D7A
ROM0:1D67 09               add  hl,bc
ROM0:1D68 2A               ldi  a,(hl)
ROM0:1D69 46               ld   b,(hl)
ROM0:1D6A 4F               ld   c,a
ROM0:1D6B E1               pop  hl
ROM0:1D6C 09               add  hl,bc
ROM0:1D6D 44               ld   b,h
ROM0:1D6E 4D               ld   c,l
ROM0:1D6F E1               pop  hl
ROM0:1D70 F1               pop  af
ROM0:1D71 C9               ret  

Checks if Card ID is 721

  • 0x1D86-0x1D97 - ?
ROM0:1D86 D5               push de
ROM0:1D87 1E 00            ld   e,00
ROM0:1D89 78               ld   a,b
ROM0:1D8A FE 02            cp   a,02
ROM0:1D8C 20 07            jr   nz,1D95
ROM0:1D8E 79               ld   a,c
ROM0:1D8F FE D0            cp   a,D0
ROM0:1D91 20 02            jr   nz,1D95
ROM0:1D93 1E 01            ld   e,01
ROM0:1D95 7B               ld   a,e
ROM0:1D96 D1               pop  de
ROM0:1D97 C9               ret

0:1DA7 (to document)

  • 0x1DA7-0x1DC1 - ?
ROM0:1DA7 C5               push bc
ROM0:1DA8 D5               push de
ROM0:1DA9 E5               push hl
ROM0:1DAA 2E 02            ld   l,02
ROM0:1DAC CD A2 14         call 14A2
ROM0:1DAF 7B               ld   a,e
ROM0:1DB0 FE 01            cp   a,01
ROM0:1DB2 20 02            jr   nz,1DB6
ROM0:1DB4 2E 01            ld   l,01
ROM0:1DB6 7B               ld   a,e
ROM0:1DB7 FE 00            cp   a,00
ROM0:1DB9 20 02            jr   nz,1DBD
ROM0:1DBB 2E 00            ld   l,00
ROM0:1DBD 7D               ld   a,l
ROM0:1DBE E1               pop  hl
ROM0:1DBF D1               pop  de
ROM0:1DC0 C1               pop  bc
ROM0:1DC1 C9               ret


  • 0x20DB-0x210A - Pseudo-Random Number Generator
ROM0:20DB F5               push af
ROM0:20DC C5               push bc
ROM0:20DD D5               push de
ROM0:20DE FA 19 DB         ld   a,(DB19)
ROM0:20E1 47               ld   b,a
ROM0:20E2 4F               ld   c,a
ROM0:20E3 FA 18 DB         ld   a,(DB18)
ROM0:20E6 CB 19            rr   c
ROM0:20E8 1F               rra  
ROM0:20E9 CB 1A            rr   d
ROM0:20EB A8               xor  b
ROM0:20EC CB 12            rl   d
ROM0:20EE 17               rla  
ROM0:20EF CB 11            rl   c
ROM0:20F1 EA 19 DB         ld   (DB19),a
ROM0:20F4 FA 17 DB         ld   a,(DB17)
ROM0:20F7 EA 18 DB         ld   (DB18),a
ROM0:20FA FA 16 DB         ld   a,(DB16)
ROM0:20FD EA 17 DB         ld   (DB17),a
ROM0:2100 79               ld   a,c
ROM0:2101 EA 16 DB         ld   (DB16),a
ROM0:2104 EA 1C DB         ld   (DB1C),a
ROM0:2107 D1               pop  de
ROM0:2108 C1               pop  bc
ROM0:2109 F1               pop  af
ROM0:210A C9               ret

Pseudo-Random Number between m and n

  • 0x210B-0x2132 - Stores a Pseudo-Random Number between (DB1A) and (DB1B) in (DB1C)
ROM0:210B F5               push af
ROM0:210C C5               push bc
ROM0:210D D5               push de
ROM0:210E FA 1A DB         ld   a,(DB1A)	// Min value for PRN
ROM0:2111 4F               ld   c,a
ROM0:2112 FA 1B DB         ld   a,(DB1B)	// Max value for PRN
ROM0:2115 B9               cp   c
ROM0:2116 20 05            jr   nz,211D		// If(min ≠ max), jump to 0:211D
ROM0:2118 EA 1C DB         ld   (DB1C),a	// PRN = max
ROM0:211B 18 12            jr   212F		// Get out of this function
ROM0:211D 91               sub  c
ROM0:211E 47               ld   b,a
ROM0:211F 04               inc  b		// b = (max - min) + 1
ROM0:2120 CD DB 20         call 20DB		// PRNG
ROM0:2123 FA 1C DB         ld   a,(DB1C)
ROM0:2126 57               ld   d,a		// d = PRN
ROM0:2127 CD 03 14         call 1403		// ? operation; set e to 0, 1 or 2
ROM0:212A 7B               ld   a,e
ROM0:212B 81               add  c		// a = e + min
ROM0:212C EA 1C DB         ld   (DB1C),a	// Store the value in (DB1C)
ROM0:212F D1               pop  de
ROM0:2130 C1               pop  bc
ROM0:2131 F1               pop  af
ROM0:2132 C9               ret

Gives a random Card 1

  • 0x2507-0x2566 - ?
ROM0:2507 F5               push af
ROM0:2508 D5               push de
ROM0:2509 E5               push hl
ROM0:250A 3E 00            ld   a,00
ROM0:250C EA 1A DB         ld   (DB1A),a
ROM0:250F 3E FF            ld   a,FF
ROM0:2511 EA 1B DB         ld   (DB1B),a
ROM0:2514 CD 0B 21         call 210B
ROM0:2517 FA 1C DB         ld   a,(DB1C)
ROM0:251A 5F               ld   e,a
ROM0:251B 3E 00            ld   a,00
ROM0:251D EA 1A DB         ld   (DB1A),a
ROM0:2520 3E 07            ld   a,07
ROM0:2522 EA 1B DB         ld   (DB1B),a
ROM0:2525 CD 0B 21         call 210B
ROM0:2528 FA 1C DB         ld   a,(DB1C)
ROM0:252B 57               ld   d,a
ROM0:252C 60               ld   h,b
ROM0:252D 69               ld   l,c		// Set hl to pointer from RO40:410D
ROM0:252E 01 00 00         ld   bc,0000
ROM0:2531 AF               xor  a
ROM0:2532 F5               push af
ROM0:2533 C5               push bc
ROM0:2534 E6 01            and  a,01
ROM0:2536 20 14            jr   nz,254C
ROM0:2538 2A               ldi  a,(hl)
ROM0:2539 47               ld   b,a
ROM0:253A 7E               ld   a,(hl)
ROM0:253B E6 F0            and  a,F0
ROM0:253D CB 38            srl  b
ROM0:253F 1F               rra  
ROM0:2540 CB 38            srl  b
ROM0:2542 1F               rra  
ROM0:2543 CB 38            srl  b
ROM0:2545 1F               rra  
ROM0:2546 CB 38            srl  b
ROM0:2548 1F               rra  
ROM0:2549 4F               ld   c,a
ROM0:254A 18 06            jr   2552
ROM0:254C 2A               ldi  a,(hl)
ROM0:254D E6 0F            and  a,0F
ROM0:254F 47               ld   b,a
ROM0:2550 2A               ldi  a,(hl)
ROM0:2551 4F               ld   c,a
ROM0:2552 CD A7 1D         call 1DA7
ROM0:2555 C1               pop  bc
ROM0:2556 FE 00            cp   a,00
ROM0:2558 20 04            jr   nz,255E
ROM0:255A E8 02            add  sp,02
ROM0:255C 18 05            jr   2563
ROM0:255E 03               inc  bc
ROM0:255F F1               pop  af
ROM0:2560 3C               inc  a
ROM0:2561 18 CF            jr   2532
ROM0:2563 E1               pop  hl
ROM0:2564 D1               pop  de
ROM0:2565 F1               pop  af
ROM0:2566 C9               ret  

Stage 5 opponents Decks IDs

  • 0x25BE-0x25CC - Loads Stage 5 opponent's Deck ID
ROM0:25BE 23               inc  hl
ROM0:25BF 04               inc  b
ROM0:25C0 06 00            ld   b,00
ROM0:25C2 4F               ld   c,a
ROM0:25C3 21 CD 25         ld   hl,25CD
ROM0:25C6 09               add  hl,bc
ROM0:25C7 7E               ld   a,(hl)
ROM0:25C8 EA 87 DB         ld   (DB87),a
ROM0:25CB F1               pop  af
ROM0:25CC C9               ret  
  • 0x25CD-0x25D0 - Stage 5 opponents Decks IDs
0F 12 13 14

Gives a random Card 2

  • 0x29E7-0x2A04 - ?
ROM0:29E7 F5               push af
ROM0:29E8 D5               push de
ROM0:29E9 E5               push hl
ROM0:29EA FA 00 40         ld   a,(4000)
ROM0:29ED F5               push af
ROM0:29EE 3E 40            ld   a,40
ROM0:29F0 CD 3A 12         call 123A		// Switch to Bank 40
ROM0:29F3 CD 23 40         call 4023
ROM0:29F6 7A               ld   a,d
ROM0:29F7 CD 3A 12         call 123A		// Switch to Bank 24 or 25, from RO40:410D
ROM0:29FA CD 07 25         call 2507
ROM0:29FD F1               pop  af
ROM0:29FE CD 3A 12         call 123A		// Switch to Bank D
ROM0:2A01 E1               pop  hl
ROM0:2A02 D1               pop  de
ROM0:2A03 F1               pop  af
ROM0:2A04 C9               ret

Initialize Duel Records

  • 0x2A10-0x2A2A - Sets Duel Records to either 0 duels, or 9 duels if debug game
ROM0:2A10 FE 00            cp   a,00
ROM0:2A12 20 05            jr   nz,2A19		// If debug, jump to 0:2A19
ROM0:2A14 11 49 2A         ld   de,2A49
ROM0:2A17 18 03            jr   2A1C		// Else, jump to 0:2A1C
ROM0:2A19 11 A1 2A         ld   de,2AA1
ROM0:2A1C 0E 16            ld   c,16
ROM0:2A1E 1A               ld   a,(de)
ROM0:2A1F 22               ldi  (hl),a
ROM0:2A20 13               inc  de
ROM0:2A21 1A               ld   a,(de)
ROM0:2A22 22               ldi  (hl),a
ROM0:2A23 13               inc  de
ROM0:2A24 0D               dec  c
ROM0:2A25 20 F7            jr   nz,2A1E
ROM0:2A27 21 FB DB         ld   hl,DBFB
ROM0:2A2A CF               rst  08
  • 0x2A2D-0x2A48 - Sets Duel Records to either 0 wins, or 9 wins if debug game
ROM0:2A2D FE 00            cp   a,00
ROM0:2A2F 20 05            jr   nz,2A36		// If debug, jump to 0:2A36
ROM0:2A31 11 75 2A         ld   de,2A75
ROM0:2A34 18 03            jr   2A39		// Else, jump to 0:2A39
ROM0:2A36 11 CD 2A         ld   de,2ACD
ROM0:2A39 0E 16            ld   c,16
ROM0:2A3B 1A               ld   a,(de)
ROM0:2A3C 22               ldi  (hl),a
ROM0:2A3D 13               inc  de
ROM0:2A3E 1A               ld   a,(de)
ROM0:2A3F 22               ldi  (hl),a
ROM0:2A40 13               inc  de
ROM0:2A41 0D               dec  c
ROM0:2A42 20 F7            jr   nz,2A3B
ROM0:2A44 E1               pop  hl
ROM0:2A45 D1               pop  de
ROM0:2A46 C1               pop  bc
ROM0:2A47 F1               pop  af
ROM0:2A48 C9               ret  
  • 0x2A49-0x2AA0 - Duel Records
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
  • 0x2AA1-0x2AF8 - Debug Duel Records
09 00 09 00 09 00 09 00 09 00 09 00 09 00 09 00
09 00 09 00 09 00 09 00 09 00 09 00 09 00 09 00
09 00 09 00 04 00 04 00 04 00 04 00 09 00 09 00
09 00 09 00 09 00 09 00 09 00 09 00 09 00 09 00
09 00 09 00 09 00 09 00 09 00 09 00 09 00 09 00
04 00 04 00 04 00 04

idk for now

Set wC920 to accumulator

ROM0:2D0A F5               push af
ROM0:2D0B C5               push bc
ROM0:2D0C D5               push de
ROM0:2D0D E5               push hl
ROM0:2D0E CF               rst  08
          07 3E => pointer 3E:4007, function 3E:4076 - Set wC920 to accumulator
ROM0:2D11 E1               pop  hl
ROM0:2D12 D1               pop  de
ROM0:2D13 C1               pop  bc
ROM0:2D14 F1               pop  af
ROM0:2D15 C9               ret

0:2D16 (Set wC920 to 0, and?)

ROM0:2D16 F5               push af
ROM0:2D17 3E 00            ld   a,00          ;a = 0
ROM0:2D19 CD 0A 2D         call 2D0A          ;Set wC920 to 0
ROM0:2D1C CD 07 11         call 1107
ROM0:2D1F F1               pop  af
ROM0:2D20 C9               ret  

0:2D21 (Set wC920 to 2, and?)

ROM0:2D21 F5               push af
ROM0:2D22 3E 02            ld   a,02          ;a = 2
ROM0:2D24 CD 0A 2D         call 2D0A          ;Set wC920 to 2
ROM0:2D27 CD 07 11         call 1107
ROM0:2D2A F1               pop  af
ROM0:2D2B C9               ret  

0:2D2C (Set wC920 to 3, and?)

ROM0:2D2C F5               push af
ROM0:2D2D 3E 03            ld   a,03          ;a = 3
ROM0:2D2F CD 0A 2D         call 2D0A          ;Set wC920 to 3
ROM0:2D32 CD 07 11         call 1107
ROM0:2D35 F1               pop  af
ROM0:2D36 C9               ret  

0:2D37 (Set wC920 to 4, and?)

ROM0:2D37 F5               push af
ROM0:2D38 3E 04            ld   a,04          ;a = 4
ROM0:2D3A CD 0A 2D         call 2D0A          ;Set wC920 to 4
ROM0:2D3D CD 07 11         call 1107
ROM0:2D40 F1               pop  af
ROM0:2D41 C9               ret  

0:2D42 (Set wC920 to 5, and?)

ROM0:2D42 F5               push af
ROM0:2D43 3E 05            ld   a,05          ;a = 5
ROM0:2D45 CD 0A 2D         call 2D0A          ;Set wC920 to 5
ROM0:2D48 CD 07 11         call 1107
ROM0:2D4B F1               pop  af
ROM0:2D4C C9               ret  

0:2D4D (Set wC920 to 6, and?)

ROM0:2D4D F5               push af
ROM0:2D4E 3E 06            ld   a,06          ;a = 6
ROM0:2D50 CD 0A 2D         call 2D0A          ;Set wC920 to 6
ROM0:2D53 CD 07 11         call 1107
ROM0:2D56 F1               pop  af
ROM0:2D57 C9               ret  

0:2D58 (Set wC920 to 10, and?)

ROM0:2D58 F5               push af
ROM0:2D59 3E 0A            ld   a,0A          ;a = 10
ROM0:2D5B CD 0A 2D         call 2D0A          ;Set wC920 to 10
ROM0:2D5E CD 07 11         call 1107
ROM0:2D61 F1               pop  af
ROM0:2D62 C9               ret  

0:2D63 (Set wC920 to 11, and?)

ROM0:2D63 F5               push af
ROM0:2D64 3E 0B            ld   a,0B          ;a = 11
ROM0:2D66 CD 0A 2D         call 2D0A          ;Set wC920 to 11
ROM0:2D69 CD 07 11         call 1107
ROM0:2D6C F1               pop  af
ROM0:2D6D C9               ret  

0:2D6E (Set wC920 to 12, and?)

ROM0:2D6E F5               push af
ROM0:2D6F 3E 0C            ld   a,0C          ;a = 12
ROM0:2D71 CD 0A 2D         call 2D0A          ;Set wC920 to 12
ROM0:2D74 CD 07 11         call 1107
ROM0:2D77 F1               pop  af
ROM0:2D78 C9               ret  

0:2D79 (Set wC920 to 13, and?)

ROM0:2D79 F5               push af
ROM0:2D7A 3E 0D            ld   a,0D          ;a = 13
ROM0:2D7C CD 0A 2D         call 2D0A          ;Set wC920 to 13
ROM0:2D7F CD 07 11         call 1107
ROM0:2D82 F1               pop  af
ROM0:2D83 C9               ret  

0:2D84 (Set wC920 to 14, and?)

ROM0:2D84 F5               push af
ROM0:2D85 3E 0E            ld   a,0E          ;a = 14
ROM0:2D87 CD 0A 2D         call 2D0A          ;Set wC920 to 14
ROM0:2D8A CD 07 11         call 1107
ROM0:2D8D F1               pop  af
ROM0:2D8E C9               ret  

0:2D8F (Set wC920 to 15, and?)

ROM0:2D8F F5               push af
ROM0:2D90 3E 0F            ld   a,0F          ;a = 15
ROM0:2D92 CD 0A 2D         call 2D0A          ;Set wC920 to 15
ROM0:2D95 CD 07 11         call 1107
ROM0:2D98 F1               pop  af
ROM0:2D99 C9               ret  

0:2D9A (Set wC920 to 18, and?)

ROM0:2D9A F5               push af
ROM0:2D9B 3E 12            ld   a,12          ;a = 18
ROM0:2D9D CD 0A 2D         call 2D0A          ;Set wC920 to 18
ROM0:2DA0 CD 07 11         call 1107
ROM0:2DA3 F1               pop  af
ROM0:2DA4 C9               ret  

0:2DA5 (Set wC920 to 16, and?)

ROM0:2DA5 F5               push af
ROM0:2DA6 3E 10            ld   a,10          ;a = 16
ROM0:2DA8 CD 0A 2D         call 2D0A          ;Set wC920 to 16
ROM0:2DAB CD 07 11         call 1107
ROM0:2DAE F1               pop  af
ROM0:2DAF C9               ret  

0:2DB0 (Set wC920 to 7, and?)

ROM0:2DB0 F5               push af
ROM0:2DB1 3E 07            ld   a,07          ;a = 7
ROM0:2DB3 CD 0A 2D         call 2D0A          ;Set wC920 to 7
ROM0:2DB6 CD 07 11         call 1107
ROM0:2DB9 F1               pop  af
ROM0:2DBA C9               ret  

0:2DBB (Set wC920 to 19, and?)

ROM0:2DBB F5               push af
ROM0:2DBC 3E 13            ld   a,13          ;a = 19
ROM0:2DBE CD 0A 2D         call 2D0A          ;Set wC920 to 19
ROM0:2DC1 CD 07 11         call 1107
ROM0:2DC4 F1               pop  af
ROM0:2DC5 C9               ret  

0:2DC6 (Set wC920 to 1, and?)

ROM0:2DC6 F5               push af
ROM0:2DC7 3E 01            ld   a,01          ;a = 1
ROM0:2DC9 CD 0A 2D         call 2D0A          ;Set wC920 to 1
ROM0:2DCC CD 07 11         call 1107
ROM0:2DCF F1               pop  af
ROM0:2DD0 C9               ret  

0:2DD (Set wC920 to 9, and?)1

ROM0:2DD1 F5               push af
ROM0:2DD2 3E 09            ld   a,09          ;a = 9
ROM0:2DD4 CD 0A 2D         call 2D0A          ;Set wC920 to 9
ROM0:2DD7 CD 07 11         call 1107
ROM0:2DDA F1               pop  af
ROM0:2DDB C9               ret

0:31F5 (sets (DD07) to 0)

  • 0x31F5-0x31FC - Sets (DD07) to 0
ROM0:31F5 F5               push af
ROM0:31F6 3E 00            ld   a,00
ROM0:31F8 EA 07 DD         ld   (DD07),a
ROM0:31FB F1               pop  af
ROM0:31FC C9               ret

0:31FD (sets (DD07) to 0 or 4)

  • 0x31FD-0x3225 - Sets (DD07) to 0 or 4
ROM0:31FD F5               push af
ROM0:31FE C5               push bc
ROM0:31FF E5               push hl
ROM0:3200 78               ld   a,b
ROM0:3201 FE 00            cp   a,00
ROM0:3203 20 0C            jr   nz,3211
ROM0:3205 79               ld   a,c
ROM0:3206 FE 11            cp   a,11
ROM0:3208 20 05            jr   nz,320F
ROM0:320A 3E 04            ld   a,04
ROM0:320C EA 07 DD         ld   (DD07),a
ROM0:320F 18 11            jr   3222
ROM0:3211 FA 07 DD         ld   a,(DD07)
ROM0:3214 FE 04            cp   a,04
ROM0:3216 28 0A            jr   z,3222
ROM0:3218 06 00            ld   b,00
ROM0:321A 21 26 32         ld   hl,3226
ROM0:321D 09               add  hl,bc
ROM0:321E 7E               ld   a,(hl)
ROM0:321F EA 07 DD         ld   (DD07),a
ROM0:3222 E1               pop  hl
ROM0:3223 C1               pop  bc
ROM0:3224 F1               pop  af
ROM0:3225 C9               ret

Bank 1

Initialize Cards in trunk

  • 0x474F-0x4774 - Initialize the cards owned to 0, or 200 if debug game
ROM1:474F FE 00            cp   a,00
ROM1:4751 20 04            jr   nz,4757		// If debug, jump to 1:4757
ROM1:4753 3E FF            ld   a,FF
ROM1:4755 18 02            jr   4759		// Else, jump to 1:4759
ROM1:4757 3E C8            ld   a,C8		// If debug, gives the player 200 copies of each card
ROM1:4759 06 02            ld   b,02
ROM1:475B 0E 00            ld   c,00
ROM1:475D 22               ldi  (hl),a
ROM1:475E 0D               dec  c
ROM1:475F 20 FC            jr   nz,475D
ROM1:4761 05               dec  b
ROM1:4762 20 F7            jr   nz,475B
ROM1:4764 0E D0            ld   c,D0
ROM1:4766 22               ldi  (hl),a
ROM1:4767 0D               dec  c
ROM1:4768 20 FC            jr   nz,4766		// Set (D5A0) to (D86F) to 0, or 200 if debug game
ROM1:476A AF               xor  a
ROM1:476B EA B7 D8         ld   (D8B7),a	// Set (D8B7) and (D8B8) to 0
ROM1:476E EA B8 D8         ld   (D8B8),a
ROM1:4771 E1               pop  hl
ROM1:4772 C1               pop  bc
ROM1:4773 F1               pop  af
ROM1:4774 C9               ret


ROM1:4932 F5               push af
ROM1:4933 E5               push hl
ROM1:4934 E8 FE            add  sp,FE
ROM1:4936 F8 00            ld   hl,sp+00
ROM1:4938 AF               xor  a
ROM1:4939 22               ldi  (hl),a
ROM1:493A 22               ldi  (hl),a
ROM1:493B 22               ldi  (hl),a
ROM1:493C 01 00 00         ld   bc,0000
ROM1:493F CF               rst  08
          03 09
ROM1:4942 FA 81 D9         ld   a,(D981)
ROM1:4945 FE 14            cp   a,14
ROM1:4947 30 23            jr   nc,496C
ROM1:4949 CF               rst  08
          3D 05
ROM1:494C 5F               ld   e,a
ROM1:494D FA 83 D9         ld   a,(D983)
ROM1:4950 BB               cp   e
ROM1:4951 28 02            jr   z,4955
ROM1:4953 30 17            jr   nc,496C
ROM1:4955 CD 75 47         call 4775
ROM1:4958 CD 18 48         call 4818
ROM1:495B FE FF            cp   a,FF
ROM1:495D 20 01            jr   nz,4960
ROM1:495F AF               xor  a
ROM1:4960 F8 00            ld   hl,sp+00
ROM1:4962 86               add  (hl)
ROM1:4963 22               ldi  (hl),a
ROM1:4964 3E 00            ld   a,00
ROM1:4966 8E               adc  (hl)
ROM1:4967 22               ldi  (hl),a
ROM1:4968 3E 00            ld   a,00
ROM1:496A 8E               adc  (hl)
ROM1:496B 77               ld   (hl),a
ROM1:496C 03               inc  bc
ROM1:496D 11 D0 02         ld   de,02D0
ROM1:4970 CD 98 1D         call 1D98
ROM1:4973 FE 00            cp   a,00
ROM1:4975 20 C8            jr   nz,493F
ROM1:4977 F8 00            ld   hl,sp+00
ROM1:4979 2A               ldi  a,(hl)
ROM1:497A 5F               ld   e,a
ROM1:497B 2A               ldi  a,(hl)
ROM1:497C 4F               ld   c,a
ROM1:497D 2A               ldi  a,(hl)
ROM1:497E 47               ld   b,a
ROM1:497F E8 02            add  sp,02
ROM1:4981 E1               pop  hl
ROM1:4982 F1               pop  af
ROM1:4983 C9               ret

Check if card is forbidden

ROM1:4984 C5               push bc
ROM1:4985 D5               push de
ROM1:4986 E5               push hl
ROM1:4987 50               ld   d,b
ROM1:4988 59               ld   e,c
ROM1:4989 21 AD 49         ld   hl,49AD
ROM1:498C 2A               ldi  a,(hl)
ROM1:498D 4F               ld   c,a
ROM1:498E 2A               ldi  a,(hl)
ROM1:498F 47               ld   b,a
ROM1:4990 CD 86 1D         call 1D86
ROM1:4993 FE 01            cp   a,01
ROM1:4995 20 04            jr   nz,499B
ROM1:4997 0E 00            ld   c,00
ROM1:4999 18 0D            jr   49A8
ROM1:499B CD 98 1D         call 1D98
ROM1:499E FE 00            cp   a,00
ROM1:49A0 20 04            jr   nz,49A6
ROM1:49A2 0E 01            ld   c,01
ROM1:49A4 18 02            jr   49A8
ROM1:49A6 18 E4            jr   498C
ROM1:49A8 79               ld   a,c
ROM1:49A9 E1               pop  hl
ROM1:49AA D1               pop  de
ROM1:49AB C1               pop  bc
ROM1:49AC C9               ret  

Forbidden cards array

6B 01 - Black Luster Soldier
67 01 - Zera the Mant
63 01 - Super War-lion
6C 01 - Fiend's Mirror
7B 01 - Blue Eyes Ultimate Dragon
75 01 - Gate Guardian
BC 02 - Performance of Swords   
BD 02 - Hungry Burger
BE 02 - Sengenjin
BF 02 - Skull Guardian
C0 02 - Tri-Horned Dragon
C1 02 - Serpent Night Dragon
C5 02 - Crab Turtle
CF 02 - Mask of Shine & Darkness
C4 02 - Chakra
CA 02 - Psycho-Puppet
CC 02 - Javelin Beetle
CB 02 - Garma Sword 
C3 02 - Cosmo Queen
CE 02 - Dokurorider
CD 02 - Fortress Whale
C8 02 - Meteor Black Dragon
D0 02 - ?

Graphics 1

  • 0x5000-0x5B00 - Cursors

Checks Game Boy Color

ROM1:5BB3 F5               push af
ROM1:5BB4 F0 DD            ld   a,(ff00+DD)
ROM1:5BB6 FE 11            cp   a,11
ROM1:5BB8 20 03            jr   nz,5BBD		// If(system ≠ GBC), get out of this function
ROM1:5BBA CD D7 5B         call 5BD7
ROM1:5BBD F1               pop  af
ROM1:5BBE C9               ret

Bank 2


ROM2:4D8A F5               push af
ROM2:4D8B CD 16 2D         call 2D16
ROM2:4D8E 3E 04            ld   a,04
ROM2:4D90 EA BF D9         ld   (D9BF),a
ROM2:4D93 3E 71            ld   a,71
ROM2:4D95 EA C0 D9         ld   (D9C0),a
ROM2:4D98 CF               rst  08
ROM2:4D99 03               inc  bc
ROM2:4D9A 06 CD            ld   b,CD
ROM2:4D9C 6E               ld   l,(hl)
ROM2:4D9D 2D               dec  l
ROM2:4D9E CD B2 43         call 43B2
ROM2:4DA1 F1               pop  af
ROM2:4DA2 C9               ret  

Bank 3

CPU Deck

Initialize CPU Deck

  • 0xB24A-0xB263 - Initialize CPU Deck
ROM3:424A F5               push af
ROM3:424B C5               push bc
ROM3:424C E5               push hl
ROM3:424D 3E 00            ld   a,00
ROM3:424F EA 65 D9         ld   (D965),a	// Current card in CPU Deck is the first card
ROM3:4252 21 15 D9         ld   hl,D915
ROM3:4255 0E 28            ld   c,28
ROM3:4257 3E D0            ld   a,D0
ROM3:4259 22               ldi  (hl),a
ROM3:425A 3E 02            ld   a,02
ROM3:425C 22               ldi  (hl),a
ROM3:425D 0D               dec  c
ROM3:425E 20 F7            jr   nz,4257		// Fills CPU deck with 0x2D0 (no card)
ROM3:4260 E1               pop  hl
ROM3:4261 C1               pop  bc
ROM3:4262 F1               pop  af
ROM3:4263 C9               ret  

Current card in CPU Deck

  • 0xB264-0xB26E - Current card in CPU Deck
ROM3:4264 EA 65 D9         ld   (D965),a	// Current card in CPU Deck = accumulator
ROM3:4267 C9               ret  
ROM3:4268 F5               push af
ROM3:4269 AF               xor  a
ROM3:426A EA 65 D9         ld   (D965),a	// Current card in CPU Deck is the first card
ROM3:426D F1               pop  af
ROM3:426E C9               ret

Remove card from CPU Deck

  • 0xB26F-0xB286 - Delete the card CPU drew from its Deck
ROM3:426F F5               push af
ROM3:4270 C5               push bc
ROM3:4271 E5               push hl
ROM3:4272 06 00            ld   b,00
ROM3:4274 FA 65 D9         ld   a,(D965)	// Current card in CPU Deck
ROM3:4277 4F               ld   c,a
ROM3:4278 CB 21            sla  c
ROM3:427A 21 15 D9         ld   hl,D915
ROM3:427D 09               add  hl,bc
ROM3:427E 3E D0            ld   a,D0
ROM3:4280 22               ldi  (hl),a
ROM3:4281 36 02            ld   (hl),02		// Replace card in deck by 0x2D0 (no card)
ROM3:4283 E1               pop  hl
ROM3:4284 C1               pop  bc
ROM3:4285 F1               pop  af
ROM3:4286 C9               ret

CPU draw a card

  • 0xB287-0xB29B - Read next card to be drawn by CPU
ROM3:4287 F5               push af
ROM3:4288 E5               push hl
ROM3:4289 06 00            ld   b,00
ROM3:428B FA 65 D9         ld   a,(D965)	// Current card in CPU Deck
ROM3:428E 4F               ld   c,a
ROM3:428F CB 21            sla  c
ROM3:4291 21 15 D9         ld   hl,D915
ROM3:4294 09               add  hl,bc
ROM3:4295 2A               ldi  a,(hl)
ROM3:4296 4F               ld   c,a
ROM3:4297 3A               ldd  a,(hl)		// bc = card at (D915) + (cards drawn × 2)
ROM3:4298 47               ld   b,a
ROM3:4299 E1               pop  hl
ROM3:429A F1               pop  af
ROM3:429B C9               ret

Increase pointer to card in CPU Deck

  • 0xB29C-0xB2A9 - Increase pointer to card in CPU Deck
ROM3:429C F5               push af
ROM3:429D FA 65 D9         ld   a,(D965)	// Current card in CPU Deck
ROM3:42A0 FE 28            cp   a,28
ROM3:42A2 30 04            jr   nc,42A8		// If no more cards in CPU deck, get out of this function
ROM3:42A4 3C               inc  a
ROM3:42A5 EA 65 D9         ld   (D965),a	// (D965)++
ROM3:42A8 F1               pop  af
ROM3:42A9 C9               ret

Add card to CPU Deck

  • 0xB2AA-0xB2BF - Add card to CPU Deck
ROM3:42AA F5               push af
ROM3:42AB E5               push hl
ROM3:42AC C5               push bc
ROM3:42AD 06 00            ld   b,00
ROM3:42AF FA 65 D9         ld   a,(D965)	// Current card in CPU Deck
ROM3:42B2 4F               ld   c,a
ROM3:42B3 CB 21            sla  c
ROM3:42B5 21 15 D9         ld   hl,D915
ROM3:42B8 09               add  hl,bc
ROM3:42B9 C1               pop  bc		// Card to add in CPU Deck
ROM3:42BA 79               ld   a,c
ROM3:42BB 22               ldi  (hl),a
ROM3:42BC 70               ld   (hl),b		// Add card to CPU Deck
ROM3:42BD E1               pop  hl
ROM3:42BE F1               pop  af
ROM3:42BF C9               ret

CPU Draw Phase

  • 0xB2AA-0xB2BF - Probably the whole CPU Draw Phase
ROM3:42C0 F5               push af
ROM3:42C1 C5               push bc
ROM3:42C2 47               ld   b,a
ROM3:42C3 CD 65 4C         call 4C65
ROM3:42C6 FE 00            cp   a,00
ROM3:42C8 28 26            jr   z,42F0
ROM3:42CA FA 65 D9         ld   a,(D965)	// Current card in CPU Deck
ROM3:42CD FE 28            cp   a,28
ROM3:42CF 30 1F            jr   nc,42F0		// If the CPU has no card left in its deck, get out of this function
ROM3:42D1 0E 00            ld   c,00
ROM3:42D3 CD E4 1C         call 1CE4
ROM3:42D6 CD 87 42         call 4287		// CPU draw a card
ROM3:42D9 CD 6F 42         call 426F		// Remove card from CPU Deck
ROM3:42DC CD 9C 42         call 429C		// Increase pointer to card in CPU Deck
ROM3:42DF 79               ld   a,c
ROM3:42E0 EA 6D DA         ld   (DA6D),a
ROM3:42E3 78               ld   a,b
ROM3:42E4 EA 6E DA         ld   (DA6E),a
ROM3:42E7 CD C5 21         call 21C5
ROM3:42EA CD 77 21         call 2177
ROM3:42ED CD 3F 1D         call 1D3F
ROM3:42F0 C1               pop  bc
ROM3:42F1 F1               pop  af
ROM3:42F2 C9               ret

3:42F3 (to document)

  • 0xB2F3-0xB306 - ?
ROM3:42F3 F5               push af
ROM3:42F4 C5               push bc
ROM3:42F5 CD 68 42         call 4268		// Current card in CPU Deck is the first card
ROM3:42F8 06 00            ld   b,00
ROM3:42FA 0E 05            ld   c,05
ROM3:42FC 78               ld   a,b
ROM3:42FD CD C0 42         call 42C0
ROM3:4300 04               inc  b
ROM3:4301 0D               dec  c
ROM3:4302 20 F8            jr   nz,42FC
ROM3:4304 C1               pop  bc
ROM3:4305 F1               pop  af
ROM3:4306 C9               ret

3:447F (to document)

  • 0xB47F-0xB482 - Stores ? in (DA22)
ROM3:447F EA 22 DA         ld   (DA22),a
ROM3:4482 C9               ret

3:4483 (set DA22 to 0)

  • 0xB483-0xB489 - ?
ROM3:4483 F5               push af
ROM3:4484 AF               xor  a
ROM3:4485 EA 22 DA         ld   (DA22),a		// (DA22) = 0
ROM3:4488 F1               pop  af
ROM3:4489 C9               ret  

3:448A (to document)

  • 0xB48A-0xB4A1 - ?
ROM3:448A F5               push af
ROM3:448B C5               push bc
ROM3:448C E5               push hl
ROM3:448D 06 00            ld   b,00
ROM3:448F FA 22 DA         ld   a,(DA22)
ROM3:4492 4F               ld   c,a
ROM3:4493 CB 21            sla  c
ROM3:4495 21 D2 D9         ld   hl,D9D2
ROM3:4498 09               add  hl,bc
ROM3:4499 3E D0            ld   a,D0
ROM3:449B 22               ldi  (hl),a
ROM3:449C 36 02            ld   (hl),02
ROM3:449E E1               pop  hl
ROM3:449F C1               pop  bc
ROM3:44A0 F1               pop  af
ROM3:44A1 C9               ret  

3:44A2 (to document)

  • 0xB4A2-0xB4B5 - ?
ROM3:44A2 F5               push af
ROM3:44A3 E5               push hl
ROM3:44A4 06 00            ld   b,00
ROM3:44A6 FA 22 DA         ld   a,(DA22)
ROM3:44A9 4F               ld   c,a
ROM3:44AA CB 21            sla  c
ROM3:44AC 21 D2 D9         ld   hl,D9D2
ROM3:44AF 09               add  hl,bc		// hl = D9D2 + ((DA22) × 2)
ROM3:44B0 2A               ldi  a,(hl)
ROM3:44B1 4F               ld   c,a
ROM3:44B2 46               ld   b,(hl)		// Loads card ID (or 0x2D0 if no card)
ROM3:44B3 E1               pop  hl
ROM3:44B4 F1               pop  af
ROM3:44B5 C9               ret  

3:59EC (to document)

  • 0xC9EC-0xC9F3 - ?
ROM3:59EC FA 1C DB         ld   a,(DB1C)
ROM3:59EF 57               ld   d,a
ROM3:59F0 CD 04 5A         call 5A04
ROM3:59F3 CF               rst  08

3:5A04 (to document)

  • 0xCA04-0xCA25 - ?
ROM3:5A04 F5               push af
ROM3:5A05 C5               push bc
ROM3:5A06 D5               push de
ROM3:5A07 E5               push hl
ROM3:5A08 5F               ld   e,a
ROM3:5A09 7B               ld   a,e
ROM3:5A0A CD 7F 44         call 447F
ROM3:5A0D CD A2 44         call 44A2
ROM3:5A10 CD 86 1D         call 1D86		// Checks if Card ID is 721
ROM3:5A13 FE 01            cp   a,01
ROM3:5A15 28 0A            jr   z,5A21		// If(bc == 721), get out of this function
ROM3:5A17 1C               inc  e
ROM3:5A18 7B               ld   a,e
ROM3:5A19 FE 28            cp   a,28
ROM3:5A1B 20 02            jr   nz,5A1F
ROM3:5A1D 1E 00            ld   e,00
ROM3:5A1F 18 E8            jr   5A09
ROM3:5A21 E1               pop  hl
ROM3:5A22 D1               pop  de
ROM3:5A23 C1               pop  bc
ROM3:5A24 F1               pop  af
ROM3:5A25 C9               ret

Bank 4

rst 08 pointers

28 40
7E 40
1E 4A
3A 4A - Save file sanity check
BC 4A - Save after a Duel
D2 4A
D5 4B - Normal New Game
E8 4B - Debug New Game
2B 4A - Enable MBC2 RAM
33 4A - Disable MBC2 RAM
FB 4B - Enables Debug
0F 44 - ?
59 4D
6A 4F
A1 58
BE 58
08 5A
E4 59
48 5A

Main Menu

Main Menu handler

  • 0x1017F-0x101A7 - Main Menu handler
ROM4:417F C5               push bc
ROM4:4180 E5               push hl
ROM4:4181 3E 04            ld   a,04
ROM4:4183 CD 16 0F         call 0F16
ROM4:4186 CD AC 42         call 42AC		// Branch to selected Menu
ROM4:4189 CD 9A 10         call 109A
ROM4:418C CD 07 11         call 1107
ROM4:418F 06 00            ld   b,00
ROM4:4191 FA 1D DB         ld   a,(DB1D)
ROM4:4194 4F               ld   c,a
ROM4:4195 CB 21            sla  c
ROM4:4197 21 A8 41         ld   hl,41A8
ROM4:419A 09               add  hl,bc
ROM4:419B 2A               ldi  a,(hl)
ROM4:419C 66               ld   h,(hl)
ROM4:419D 6F               ld   l,a
ROM4:419E 01 A3 41         ld   bc,41A3
ROM4:41A1 C5               push bc
ROM4:41A2 E9               jp   hl
ROM4:41A3 3E 01            ld   a,01
ROM4:41A5 E1               pop  hl
ROM4:41A6 C1               pop  bc
ROM4:41A7 C9               ret  

Updates Menu ID

  • 0x10271-0x10283 - Updates Menu ID in Main Menu
ROM4:4271 3E 04            ld   a,04
ROM4:4273 CD 16 0F         call 0F16
ROM4:4276 CD 8D 42         call 428D
ROM4:4279 CD AC 42         call 42AC
ROM4:427C CD 9A 10         call 109A
ROM4:427F CD 07 11         call 1107
ROM4:4282 AF               xor  a
ROM4:4283 C9               ret  

Initializes Menu ID

  • 0x10284-0x1028A - Initializes Menu ID to 0
ROM4:4284 F5               push af
ROM4:4285 AF               xor  a
ROM4:4286 EA 1D DB         ld   (DB1D),a
ROM4:4289 F1               pop  af
ROM4:428A C9               ret  

Increment Menu ID

  • 0x1028D-0x1029B - Menu ID + 1
ROM4:428D F5               push af
ROM4:428E FA 1D DB         ld   a,(DB1D)
ROM4:4291 3C               inc  a
ROM4:4292 FE 06            cp   a,06
ROM4:4294 20 01            jr   nz,4297
ROM4:4296 AF               xor  a
ROM4:4297 EA 1D DB         ld   (DB1D),a
ROM4:429A F1               pop  af
ROM4:429B C9               ret  

Decrement Menu ID

  • 0x1029C-0x102AB - Menu ID - 1
ROM4:429C F5               push af
ROM4:429D FA 1D DB         ld   a,(DB1D)
ROM4:42A0 3D               dec  a
ROM4:42A1 FE FF            cp   a,FF
ROM4:42A3 20 02            jr   nz,42A7
ROM4:42A5 3E 05            ld   a,05
ROM4:42A7 EA 1D DB         ld   (DB1D),a
ROM4:42AA F1               pop  af
ROM4:42AB C9               ret  

Branch to selected Menu

  • 0x102AC-0x102C1 - Branch to specific instructions for selected Menu ID
ROM4:42AC F5               push af
ROM4:42AD C5               push bc
ROM4:42AE D5               push de
ROM4:42AF E5               push hl
ROM4:42B0 FA 1D DB         ld   a,(DB1D)
ROM4:42B3 CD C2 42         call 42C2
ROM4:42B6 79               ld   a,c
ROM4:42B7 11 02 00         ld   de,0002
ROM4:42BA CD BE 13         call 13BE
ROM4:42BD E1               pop  hl
ROM4:42BE D1               pop  de
ROM4:42BF C1               pop  bc
ROM4:42C0 F1               pop  af
ROM4:42C1 C9               ret  

Load data of selected Menu ID

  • 0x102C2-0x102D2 - Load array corresponding to Menu ID
ROM4:42C2 F5               push af
ROM4:42C3 E5               push hl
ROM4:42C4 06 00            ld   b,00
ROM4:42C6 4F               ld   c,a
ROM4:42C7 CB 21            sla  c
ROM4:42C9 21 D3 42         ld   hl,42D3
ROM4:42CC 09               add  hl,bc		// hl = 0x42D3 + (Menu ID × 2)
ROM4:42CD 2A               ldi  a,(hl)
ROM4:42CE 47               ld   b,a
ROM4:42CF 4E               ld   c,(hl)
ROM4:42D0 E1               pop  hl
ROM4:42D1 F1               pop  af
ROM4:42D2 C9               ret  

Menus pointers

  • 0x102D3-0x102E2 - Menus pointers array
50 26 - Campaign
74 3B - Versus
73 62 - Trade
51 78 - Records
2E 62 - Change Name
2D 3B - Password
F5 C5 - Sound Test
0E 01 - Character Viewer

SRAM management

4:4403 (to document)

  • 0x10403-0x10407 - Calls 4:440F, then rst 08
ROM4:4403 F5               push af
ROM4:4404 CD 0F 44         call 440F
ROM4:4407 CF               rst  08
  • 0x1040F-0x1041E - ?
ROM4:440F C5               push bc
ROM4:4410 E5               push hl
ROM4:4411 06 00            ld   b,00
ROM4:4413 CD 08 5A         call 5A08		// Load Stage 5 opponent ID
ROM4:4416 4F               ld   c,a
ROM4:4417 21 1F 44         ld   hl,441F
ROM4:441A 09               add  hl,bc
ROM4:441B 7E               ld   a,(hl)
ROM4:441C E1               pop  hl
ROM4:441D C1               pop  bc
ROM4:441E C9               ret  
  • 0x1041F-0x10422 - Array ?
14 15 16 17

Enable MBC2 RAM

  • 0x10A2B-0x10A32 - Enable MBC2 battery RAM
ROM4:4A2B F5               push af
ROM4:4A2C 3E 0A            ld   a,0A
ROM4:4A2E EA 00 00         ld   (0000),a
ROM4:4A31 F1               pop  af
ROM4:4A32 C9               ret

Disable MBC2 RAM

  • 0x10A33-0x10A39 - Disable MBC2 battery RAM
ROM4:4A33 F5               push af
ROM4:4A34 AF               xor  a
ROM4:4A35 EA 00 00         ld   (0000),a
ROM4:4A38 F1               pop  af
ROM4:4A39 C9               ret

Save file sanity check

  • 0x10A3A-0x10A74 - Save file sanity check, creates a new save file if the current save is corrupted
ROM4:4A3A F5               push af
ROM4:4A3B CD 2B 4A         call 4A2B		// Enable MBC2 RAM
ROM4:4A3E FA FF B7         ld   a,(B7FF)	// Debug
ROM4:4A41 EA 96 DB         ld   (DB96),a	// Copies Debug value to (DB96)
ROM4:4A44 3E 00            ld   a,00
ROM4:4A46 EA 98 DB         ld   (DB98),a	// (DB98) = 0
ROM4:4A49 CD 6F 4C         call 4C6F		// SRAM KONAMI check
ROM4:4A4C FE 01            cp   a,01
ROM4:4A4E 20 0B            jr   nz,4A5B		// If the « KONAMI » string is correct, jump to 4:4A5B
ROM4:4A50 CD 73 50         call 5073		// Name Input screen
ROM4:4A53 CD 75 4A         call 4A75		// Erase SRAM and create a new Save File
ROM4:4A56 3E 01            ld   a,01
ROM4:4A58 EA 98 DB         ld   (DB98),a	// (DB98) = 1
ROM4:4A5B CD 93 4B         call 4B93		// Check SRAM Block and Checksum
ROM4:4A5E FE 01            cp   a,01
ROM4:4A60 20 0B            jr   nz,4A6D		// If the save file is not corrupted, jump to 4:4A6D
ROM4:4A62 CD 73 50         call 5073		// Name Input screen
ROM4:4A65 CD 75 4A         call 4A75		// Erase SRAM and create a new Save File
ROM4:4A68 3E 01            ld   a,01
ROM4:4A6A EA 98 DB         ld   (DB98),a	// (DB98) = 1
ROM4:4A6D CD E2 4A         call 4AE2		// Clones SRAM if SRAM block 2
ROM4:4A70 CD 33 4A         call 4A33		// Disable MBC2 RAM
ROM4:4A73 F1               pop  af
ROM4:4A74 C9               ret

New Save file

  • 0x10A3A-0x10A74 - Creates a new Save file
ROM4:4A75 CD 8E 4A         call 4A8E		// Erases save file
ROM4:4A78 CD A6 4A         call 4AA6		// Blanks (B800) to (BFFF), set Stage 5 opponent and (FFDB) to a PRN
ROM4:4A7B CD 4D 4C         call 4C4D
ROM4:4A7E CD 13 4C         call 4C13		// SRAM Block 1
ROM4:4A81 CD 8C 4C         call 4C8C		// Copy Data in SRAM
ROM4:4A84 CD 20 4C         call 4C20		// SRAM Block 1
ROM4:4A87 CD EF 4A         call 4AEF		// Clones SRAM
ROM4:4A8A CD 06 4C         call 4C06		// SRAM write successful !
ROM4:4A8D C9               ret

Blanks SRAM

  • 0x10A8E-0x10AA5 - 00s SRAM area (A000) to (BFFF)
ROM4:4A8E F5               push af
ROM4:4A8F C5               push bc
ROM4:4A90 D5               push de
ROM4:4A91 E5               push hl
ROM4:4A92 21 00 A0         ld   hl,A000
ROM4:4A95 AF               xor  a
ROM4:4A96 06 20            ld   b,20
ROM4:4A98 0E 00            ld   c,00
ROM4:4A9A 22               ldi  (hl),a
ROM4:4A9B 0D               dec  c
ROM4:4A9C 20 FC            jr   nz,4A9A
ROM4:4A9E 05               dec  b
ROM4:4A9F 20 F7            jr   nz,4A98
ROM4:4AA1 E1               pop  hl
ROM4:4AA2 D1               pop  de
ROM4:4AA3 C1               pop  bc
ROM4:4AA4 F1               pop  af
ROM4:4AA5 C9               ret
  • 0x10AA6-0x10AB5 - Calls 4:5866, then rst 08
ROM4:4AA6 CD 66 58         call 5866	// Blanks (B800) to (BFFF), set Stage 5 opponent and (FFDB) to a PRN
ROM4:4AA9 CF               rst  08

Save after a Duel

  • 0x10ABC-0x10AD1 - Save after a Duel
ROM4:4ABC CD 2B 4A         call 4A2B		// Enable MBC2 RAM
ROM4:4ABF CD 13 4C         call 4C13		// SRAM Block 1
ROM4:4AC2 CD 8C 4C         call 4C8C		// Copy Data in SRAM
ROM4:4AC5 CD 20 4C         call 4C20		// SRAM Block 2
ROM4:4AC8 CD EF 4A         call 4AEF		// Clones SRAM
ROM4:4ACB CD 06 4C         call 4C06		// SRAM block 0
ROM4:4ACE CD 33 4A         call 4A33		// Disable MBC2 RAM
ROM4:4AD1 C9               ret

Save after Deck change

  • 0x10ABC-0x10AD1 -
ROM4:4AD2 CD 2B 4A         call 4A2B		// Enable MBC2 RAM
ROM4:4AD5 CD 06 4C         call 4C06		// SRAM Block 0
ROM4:4AD8 CD 13 4B         call 4C13		// SRAM Block 1
ROM4:4ADB CD BA 4C         call 4CBA
ROM4:4ADE CD 33 4A         call 4A33		// Disable MBC2 RAM
ROM4:4AE1 C9               ret

Clones SRAM

  • 0x10AE2-0x10AEE - Checks SRAM block, and clones it if it's a temporary block
ROM4:4AE2 F5               push af
ROM4:4AE3 FA F0 B7         ld   a,(B7F0)
ROM4:4AE6 FE 02            cp   a,02
ROM4:4AE8 20 03            jr   nz,4AED		// If(SRAM block ≠ 2), jump to 4:4AED
ROM4:4AEA CD EF 4A         call 4AEF		// Clones SRAM
ROM4:4AED F1               pop  af
ROM4:4AEE C9               ret  
  • 0x10AEF-0x10B12 - Clones SRAM 0xA000-0xABF8
ROM4:4AEF F5               push af
ROM4:4AF0 C5               push bc
ROM4:4AF1 D5               push de
ROM4:4AF2 E5               push hl
ROM4:4AF3 21 00 A0         ld   hl,A000
ROM4:4AF6 11 F8 AB         ld   de,ABF8
ROM4:4AF9 0E F8            ld   c,F8
ROM4:4AFB 2A               ldi  a,(hl)
ROM4:4AFC 12               ld   (de),a
ROM4:4AFD 13               inc  de
ROM4:4AFE 0D               dec  c
ROM4:4AFF 20 FA            jr   nz,4AFB
ROM4:4B01 06 0B            ld   b,0B
ROM4:4B03 0E 00            ld   c,00
ROM4:4B05 2A               ldi  a,(hl)
ROM4:4B06 12               ld   (de),a
ROM4:4B07 13               inc  de
ROM4:4B08 0D               dec  c
ROM4:4B09 20 FA            jr   nz,4B05
ROM4:4B0B 05               dec  b
ROM4:4B0C 20 F5            jr   nz,4B03
ROM4:4B0E E1               pop  hl
ROM4:4B0F D1               pop  de
ROM4:4B10 C1               pop  bc
ROM4:4B11 F1               pop  af
ROM4:4B12 C9               ret

SRAM checksum pointers

  • 0x10B55-0x10B58 - SRAM checksum pointers array

SRAM Checksum calculation

  • 0x10B59-0x10B8E - Calculate SRAM checksum
ROM4:4B59 F5               push af
ROM4:4B5A C5               push bc
ROM4:4B5B E5               push hl
ROM4:4B5C 06 00            ld   b,00
ROM4:4B5E FA 97 DB         ld   a,(DB97)
ROM4:4B61 4F               ld   c,a
ROM4:4B62 CB 21            sla  c
ROM4:4B64 21 8F 4B         ld   hl,4B8F
ROM4:4B67 09               add  hl,bc		// hl = 0x4B8F + (Save file block × 2)
ROM4:4B68 2A               ldi  a,(hl)
ROM4:4B69 66               ld   h,(hl)
ROM4:4B6A 6F               ld   l,a		// hl = Save file block pointer
ROM4:4B6B 11 00 00         ld   de,0000
ROM4:4B6E 0E F6            ld   c,F6
ROM4:4B70 2A               ldi  a,(hl)		// Add every byte of the SRAM block
ROM4:4B71 83               add  e
ROM4:4B72 5F               ld   e,a
ROM4:4B73 3E 00            ld   a,00
ROM4:4B75 8A               adc  d
ROM4:4B76 57               ld   d,a
ROM4:4B77 0D               dec  c
ROM4:4B78 20 F6            jr   nz,4B70
ROM4:4B7A 06 0B            ld   b,0B
ROM4:4B7C 0E 00            ld   c,00
ROM4:4B7E 2A               ldi  a,(hl)
ROM4:4B7F 83               add  e
ROM4:4B80 5F               ld   e,a
ROM4:4B81 3E 00            ld   a,00
ROM4:4B83 8A               adc  d
ROM4:4B84 57               ld   d,a
ROM4:4B85 0D               dec  c
ROM4:4B86 20 F6            jr   nz,4B7E
ROM4:4B88 05               dec  b
ROM4:4B89 20 F1            jr   nz,4B7C		// Loop until it's finished
ROM4:4B8B E1               pop  hl
ROM4:4B8C C1               pop  bc
ROM4:4B8D F1               pop  af
ROM4:4B8E C9               ret

SRAM blocks pointers

  • 0x10B8F-0x10B92 - SRAM blocks pointers array
00 A0 - Block 1
F8 AB - Block 2

SRAM Block and Checksum check

  • 0x10AEF-0x10B12 - Save file sanity check
ROM4:4B93 C5               push bc
ROM4:4B94 D5               push de
ROM4:4B95 E5               push hl
ROM4:4B96 FA F0 B7         ld   a,(B7F0)	// SRAM block
ROM4:4B99 FE 03            cp   a,03
ROM4:4B9B 38 04            jr   c,4BA1		// If the SRAM block is valid, jump to 4:4BA1
ROM4:4B9D 3E 01            ld   a,01		// Else, flag the save file as corrupted...
ROM4:4B9F 18 2D            jr   4BCE		// ...and get out of this function
ROM4:4BA1 06 00            ld   b,00
ROM4:4BA3 FA F0 B7         ld   a,(B7F0)
ROM4:4BA6 4F               ld   c,a	
ROM4:4BA7 21 D2 4B         ld   hl,4BD2
ROM4:4BAA 09               add  hl,bc		// hl = 0x4BD2 + SRAM block
ROM4:4BAB 7E               ld   a,(hl)
ROM4:4BAC EA 97 DB         ld   (DB97),a	// (DB97) = Save file block
ROM4:4BAF CD 59 4B         call 4B59		// de = SRAM Checksum
ROM4:4BB2 06 00            ld   b,00
ROM4:4BB4 FA 97 DB         ld   a,(DB97)
ROM4:4BB7 4F               ld   c,a
ROM4:4BB8 CB 21            sla  c
ROM4:4BBA 21 55 4B         ld   hl,4B55
ROM4:4BBD 09               add  hl,bc		// hl = 0x4B55 + (Save file block × 2)
ROM4:4BBE 2A               ldi  a,(hl)
ROM4:4BBF 66               ld   h,(hl)
ROM4:4BC0 6F               ld   l,a
ROM4:4BC1 2A               ldi  a,(hl)
ROM4:4BC2 BB               cp   e
ROM4:4BC3 28 02            jr   z,4BC7
ROM4:4BC5 06 01            ld   b,01		// If the checksum is invalid, flag the save file as corrupted
ROM4:4BC7 7E               ld   a,(hl)
ROM4:4BC8 BA               cp   d
ROM4:4BC9 28 02            jr   z,4BCD
ROM4:4BCB 06 01            ld   b,01		// If the checksum is invalid, flag the save file as corrupted
ROM4:4BCD 78               ld   a,b
ROM4:4BCE E1               pop  hl
ROM4:4BCF D1               pop  de
ROM4:4BD0 C1               pop  bc
ROM4:4BD1 C9               ret  
  • 0x10BD2-0x10BD5 - Save file blocks array
01 01 00

Normal New Game

  • 0x10BD5-0x10BE7 - Normal New Game
ROM4:4BD5 F5               push af
ROM4:4BD6 CD 2B 4A         call 4A2B		// Enable MBC2 RAM
ROM4:4BD9 3E AA            ld   a,AA
ROM4:4BDB EA F1 B7         ld   (B7F1),a
ROM4:4BDE 3E 00            ld   a,00
ROM4:4BE0 EA FF B7         ld   (B7FF),a	// No debug
ROM4:4BE3 CD 33 4A         call 4A33		// Disable MBC2 RAM
ROM4:4BE6 F1               pop  af
ROM4:4BE7 C9               ret  

Debug New Game

  • 0x10BD5-0x10BE7 - Debug New Game
ROM4:4BE8 F5               push af
ROM4:4BE9 CD 2B 4A         call 4A2B		// Enable MBC2 RAM
ROM4:4BEC 3E AA            ld   a,AA
ROM4:4BEE EA F1 B7         ld   (B7F1),a
ROM4:4BF1 3E 01            ld   a,01
ROM4:4BF3 EA FF B7         ld   (B7FF),a	// Debug
ROM4:4BF6 CD 33 4A         call 4A33		// Disable MBC2 RAM
ROM4:4BF9 F1               pop  af
ROM4:4BFA C9               ret  
  • 0x10BFB-0x10C05 - Enables Debug features if RAM 0xDB96 ≠ 0 (copy from SRAM 0xB7FF), and the xor a is removed
ROM4:4BFB FA 96 DB         ld   a,(DB96)
ROM4:4BFE FE 00            cp   a,00
ROM4:4C00 28 02            jr   z,4C04
ROM4:4C02 3E 01            ld   a,01
ROM4:4C04 AF               xor  a
ROM4:4C05 C9               ret

SRAM blocks

  • 0x10C06-0x10C12 - Writes 0x00 to SRAM 0xB7F0, writes 0x00 to WRAM 0xDB97
ROM4:4C06 F5               push af
ROM4:4C07 3E 00            ld   a,00
ROM4:4C09 EA F0 B7         ld   (B7F0),a
ROM4:4C0C 3E 00            ld   a,00
ROM4:4C0E EA 97 DB         ld   (DB97),a
ROM4:4C11 F1               pop  af
ROM4:4C12 C9               ret  
  • 0x10C13-0x10C1F - Writes 0x01 to SRAM 0xB7F0, writes 0x00 to WRAM 0xDB97
ROM4:4C13 F5               push af
ROM4:4C14 3E 01            ld   a,01
ROM4:4C16 EA F0 B7         ld   (B7F0),a
ROM4:4C19 3E 00            ld   a,00
ROM4:4C1B EA 97 DB         ld   (DB97),a
ROM4:4C1E F1               pop  af
ROM4:4C1F C9               ret
  • 0x10C20-0x10C2C - Writes 0x02 to SRAM 0xB7F0, writes 0x01 to WRAM 0xDB97
ROM4:4C20 F5               push af
ROM4:4C21 3E 02            ld   a,02
ROM4:4C23 EA F0 B7         ld   (B7F0),a
ROM4:4C26 3E 01            ld   a,01
ROM4:4C28 EA 97 DB         ld   (DB97),a
ROM4:4C2B F1               pop  af
ROM4:4C2C C9               ret


  • 0x10C64-0x10C6E - Date of build and « KONAMI » string used to check SRAM existence in function 4:4C6F.
99 04 11 00 02 4B 4F 4E 41 4D 49
April 11, 1999 - KONAMI
  • 0x10C6F-0x10C8B - Control the presence of date of build and « KONAMI » string in SRAM at 0xB7F1-0xB7FB, to determine if save data exists.
ROM4:4C6F C5               push bc
ROM4:4C70 D5               push de
ROM4:4C71 E5               push hl
ROM4:4C72 06 00            ld   b,00
ROM4:4C74 21 F1 B7         ld   hl,B7F1
ROM4:4C77 11 64 4C         ld   de,4C64
ROM4:4C7A 0E 0B            ld   c,0B
ROM4:4C7C 1A               ld   a,(de)
ROM4:4C7D BE               cp   (hl)
ROM4:4C7E 28 02            jr   z,4C82		// If the current character is ok, jump to 4:4CB2
ROM4:4C80 06 01            ld   b,01		// Else b = 1
ROM4:4C82 23               inc  hl
ROM4:4C83 13               inc  de
ROM4:4C84 0D               dec  c
ROM4:4C85 20 F5            jr   nz,4C7C		// Loops 11 times to see if « 99 04 11 KONAMI » is present in SRAM at (B7F1)-(B7FB).
ROM4:4C87 78               ld   a,b
ROM4:4C88 E1               pop  hl
ROM4:4C89 D1               pop  de
ROM4:4C8A C1               pop  bc
ROM4:4C8B C9               ret

Copy data to SRAM after a Duel

  • 0x10C8C-0x10CB9 - Copy various data in SRAM, including Stage 5 opponent
ROM4:4C8C F5               push af
ROM4:4C8D C5               push bc
ROM4:4C8E D5               push de
ROM4:4C8F E5               push hl
ROM4:4C90 11 00 A0         ld   de,A000
ROM4:4C93 01 E5 4C         ld   bc,4CE5
ROM4:4C96 0A               ld   a,(bc)
ROM4:4C97 6F               ld   l,a
ROM4:4C98 03               inc  bc
ROM4:4C99 0A               ld   a,(bc)
ROM4:4C9A 67               ld   h,a		// Load RAM pointer from 4:4CE5
ROM4:4C9B 03               inc  bc
ROM4:4C9C FE 00            cp   a,00
ROM4:4C9E 20 05            jr   nz,4CA5
ROM4:4CA0 7D               ld   a,l
ROM4:4CA1 FE 00            cp   a,00
ROM4:4CA3 28 0D            jr   z,4CB2		// If there's no more data to be saved, jump to 4:4CB2
ROM4:4CA5 C5               push bc
ROM4:4CA6 0A               ld   a,(bc)
ROM4:4CA7 4F               ld   c,a		// Load # of bytes to be read
ROM4:4CA8 2A               ldi  a,(hl)		// Load data at RAM pointer
ROM4:4CA9 12               ld   (de),a		// ... And write it to SRAM
ROM4:4CAA 13               inc  de
ROM4:4CAB 0D               dec  c
ROM4:4CAC 20 FA            jr   nz,4CA8		// If there's still data to be retrieved from RAM, loop to 4:4AC8
ROM4:4CAE C1               pop  bc
ROM4:4CAF 03               inc  bc
ROM4:4CB0 18 E4            jr   4C96		// Jump to 4:4C96 (next data to be copied to SRAM)
ROM4:4CB2 CD 37 4B         call 4B37
ROM4:4CB5 E1               pop  hl
ROM4:4CB6 D1               pop  de
ROM4:4CB7 C1               pop  bc
ROM4:4CB8 F1               pop  af
ROM4:4CB9 C9               ret

Copy data to SRAM after a Deck change

  • 0x10CBA-0x10CE4 - Copy various data in SRAM
ROM4:4CBA F5               push af
ROM4:4CBB C5               push bc
ROM4:4CBC D5               push de
ROM4:4CBD E5               push hl
ROM4:4CBE 11 00 A0         ld   de,A000
ROM4:4CC1 01 E5 4C         ld   bc,4CE5
ROM4:4CC4 0A               ld   a,(bc)
ROM4:4CC5 6F               ld   l,a
ROM4:4CC6 03               inc  bc
ROM4:4CC7 0A               ld   a,(bc)
ROM4:4CC8 67               ld   h,a
ROM4:4CC9 03               inc  bc
ROM4:4CCA FE 00            cp   a,00
ROM4:4CCC 20 05            jr   nz,4CD3
ROM4:4CCE 7D               ld   a,l
ROM4:4CCF FE 00            cp   a,00
ROM4:4CD1 28 0D            jr   z,4CE0
ROM4:4CD3 C5               push bc
ROM4:4CD4 0A               ld   a,(bc)
ROM4:4CD5 4F               ld   c,a
ROM4:4CD6 1A               ld   a,(de)
ROM4:4CD7 22               ldi  (hl),a
ROM4:4CD8 13               inc  de
ROM4:4CD9 0D               dec  c
ROM4:4CDA 20 FA            jr   nz,4CD6
ROM4:4CDC C1               pop  bc
ROM4:4CDD 03               inc  bc
ROM4:4CDE 18 E4            jr   4CC4
ROM4:4CE0 E1               pop  hl
ROM4:4CE1 D1               pop  de
ROM4:4CE2 C1               pop  bc
ROM4:4CE3 F1               pop  af
ROM4:4CE4 C9               ret

WRAM and HRAM pointers

  • 0x10CE5-0x10D1F - RAM pointers
16 DB 04 - PRNG, 4 bytes
47 DC 04 - (DC47), 4 bytes
DC FF 01 - Stage 5 opponent, 1 byte
DB FF 01 - (FFDB), 1 byte
4F DC 01 - (DC4F), 1 byte
C5 D8 50 - Player's Deck, 80 bytes
A0 D5 C8 - Cards in trunk, 720 bytes
68 D6 C8 - ...
30 D7 C8 - ...
F8 D7 78 - ...
CF DB 2C - Duel Records, 44 bytes
FB DB 2C - Wins Records, 44 bytes
30 DC 08 - (DC30), 8 bytes
00 B8 C8 - (B800), 200 bytes
C8 B8 C8 - (B8C8), 200 bytes
90 B9 C8 - (B990), 200 bytes
58 BA C8 - (BA58), 200 bytes
1B DD 5A - (DD1B), 90 bytes
D9 FF 02 - Deck Capacity, 2 bytes

Call Name Input screen

  • 0x11073-0x11076 - a = 0x0A, then rst 08 to the Name Input screen
ROM4:5073 F5               push af
ROM4:5074 3E 0A            ld   a,0A
ROM4:5076 CF               rst  08	// Continue to 3B:4004 (Name Input screen)
  • 0x11077-0x11078 - Pointer to 3B:4003
03 3B

Blanks SRAM (B800), set (FFDB) (FFDC)

  • 0x11866-0x118A0 - Blanks (B800) to (BFFF), set Stage 5 opponent and (FFDB) to a Pseudo-Random Number
ROM4:5866 F5               push af
ROM4:5867 C5               push bc
ROM4:5868 D5               push de
ROM4:5869 E5               push hl
ROM4:586A 21 16 DB         ld   hl,DB16
ROM4:586D 11 47 DC         ld   de,DC47
ROM4:5870 0E 04            ld   c,04
ROM4:5872 2A               ldi  a,(hl)
ROM4:5873 12               ld   (de),a
ROM4:5874 13               inc  de
ROM4:5875 0D               dec  c
ROM4:5876 20 FA            jr   nz,5872
ROM4:5878 21 00 B8         ld   hl,B800
ROM4:587B AF               xor  a
ROM4:587C 06 04            ld   b,04
ROM4:587E 0E C8            ld   c,C8
ROM4:5880 22               ldi  (hl),a		// Blanks (B800) to (BFFF)
ROM4:5881 0D               dec  c
ROM4:5882 20 FC            jr   nz,5880
ROM4:5884 05               dec  b		// Loop 800 times
ROM4:5885 20 F7            jr   nz,587E
ROM4:5887 AF               xor  a
ROM4:5888 EA 4F DC         ld   (DC4F),a	// (DC4F) = 0
ROM4:588B FA 48 DC         ld   a,(DC48)	// a = PRN
ROM4:588E E6 03            and  a,03
ROM4:5890 E0 DC            ld   (ff00+DC),a	// Stage 5 opponent = a
ROM4:5892 CD DB 20         call 20DB		// PRNG
ROM4:5895 FA 1C DB         ld   a,(DB1C)
ROM4:5898 E6 07            and  a,07
ROM4:589A E0 DB            ld   (ff00+DB),a
ROM4:589C E1               pop  hl
ROM4:589D D1               pop  de
ROM4:589E C1               pop  bc
ROM4:589F F1               pop  af
ROM4:58A0 C9               ret

Stage 5 opponent

Loads Stage 5 opponent ID

  • 0x11A08-0x11A0C - Loads the Stage 5 opponent ID
ROM4:5A08 F0 DC            ld   a,(ff00+DC)
ROM4:5A0A E6 03            and  a,03
ROM4:5A0C C9               ret

Changes Stage 5 opponent

  • 0x11A0D-0x11A47 - Calls PRNG to determine if the Stage 5 opponent changes
3/4096 chance to change Stage 5 opponent after each duel: 1/256, then 1/4, then 3/4
ROM4:5A0D F5               push af
ROM4:5A0E C5               push bc
ROM4:5A0F CD DB 20         call 20DB		// PRNG, between 0 and 255
ROM4:5A12 FA 1C DB         ld   a,(DB1C)
ROM4:5A15 FE 00            cp   a,00
ROM4:5A17 20 2C            jr   nz,5A45		// If PRN ≠ 0, get out of this function
ROM4:5A19 3E 00            ld   a,00
ROM4:5A1B EA 1A DB         ld   (DB1A),a	// min = 0
ROM4:5A1E 3E 03            ld   a,03
ROM4:5A20 EA 1B DB         ld   (DB1B),a	// max = 3
ROM4:5A23 CD 0B 21         call 210B		// PRNG, between 0 and 3
ROM4:5A26 FA 1C DB         ld   a,(DB1C)
ROM4:5A29 FE 00            cp   a,00
ROM4:5A2B 20 18            jr   nz,5A45		// If(PRN ≠ 0), get out of this function
ROM4:5A2D F0 DC            ld   a,(ff00+DC)
ROM4:5A2F 47               ld   b,a		// b = Stage 5 opponent ID
ROM4:5A30 3E 00            ld   a,00
ROM4:5A32 EA 1A DB         ld   (DB1A),a	// min = 0
ROM4:5A35 3E 03            ld   a,03
ROM4:5A37 EA 1B DB         ld   (DB1B),a	// max = 3
ROM4:5A3A CD 0B 21         call 210B		// PRNG, between 0 and 3
ROM4:5A3D FA 1C DB         ld   a,(DB1C)
ROM4:5A40 B8               cp   b
ROM4:5A41 28 02            jr   z,5A45		// If(PRN == Stage 5 opponent ID), get out of this function
ROM4:5A43 E0 DC            ld   (ff00+DC),a	// Load new Stage 5 opponent ID in (FFDC)
ROM4:5A45 C1               pop  bc
ROM4:5A46 F1               pop  af
ROM4:5A47 C9               ret

Bank 5

Deck Capacity

Initial DC

  • 0x15B2E-0x15B45 - Initial Deck Capacity
ROM5:5B2E FE 00            cp   a,00
ROM5:5B30 20 0A            jr   nz,5B3C              ;if debug, jump to 5:5B3C
ROM5:5B32 3E 90            ld   a,90
ROM5:5B34 E0 D9            ld   (ff00+D9),a
ROM5:5B36 3E 01            ld   a,01
ROM5:5B38 E0 DA            ld   (ff00+DA),a          ;set Deck Capacity to 400
ROM5:5B3A 18 08            jr   5B44
ROM5:5B3C 3E 0F            ld   a,0F
ROM5:5B3E E0 D9            ld   (ff00+D9),a
ROM5:5B40 3E 27            ld   a,27
ROM5:5B42 E0 DA            ld   (ff00+DA),a          ;set Deck Capacity to 9999
ROM5:5B44 F1               pop  af
ROM5:5B45 C9               ret

Retrieve current DC

ROM5:5B46 F5               push af
ROM5:5B47 F0 D9            ld   a,(ff00+D9)
ROM5:5B49 4F               ld   c,a
ROM5:5B4A F0 DA            ld   a,(ff00+DA)
ROM5:5B4C 47               ld   b,a          ;bc = deck_capacity
ROM5:5B4D F1               pop  af
ROM5:5B4E C9               ret  


ROM5:5B4F C5               push bc
ROM5:5B50 F0 D9            ld   a,(ff00+D9)
ROM5:5B52 4F               ld   c,a
ROM5:5B53 F0 DA            ld   a,(ff00+DA)
ROM5:5B55 47               ld   b,a          ;bc = deck_capacity
ROM5:5B56 CD 60 5B         call 5B60
ROM5:5B59 C1               pop  bc
ROM5:5B5A C9               ret  

a = 13, push / pop deck_capacity

ROM5:5B5B C5               push bc
ROM5:5B5C 3E 0D            ld   a,0D
ROM5:5B5E C1               pop  bc
ROM5:5B5F C9               ret  

Duelist Level calculation

ROM5:5B60 C5               push bc
ROM5:5B61 D5               push de
ROM5:5B62 79               ld   a,c
ROM5:5B63 D6 90            sub  a,90
ROM5:5B65 5F               ld   e,a
ROM5:5B66 78               ld   a,b
ROM5:5B67 DE 01            sbc  a,01
ROM5:5B69 57               ld   d,a             ;de = deck_capacity - 400
ROM5:5B6A 01 07 00         ld   bc,0007         ;bc = 7
ROM5:5B6D CD 42 14         call 1442
ROM5:5B70 7B               ld   a,e
ROM5:5B71 C6 0F            add  a,0F            ;a += 15
ROM5:5B73 5F               ld   e,a
ROM5:5B74 7A               ld   a,d
ROM5:5B75 CE 00            adc  a,00
ROM5:5B77 57               ld   d,a
ROM5:5B78 7A               ld   a,d
ROM5:5B79 FE 00            cp   a,00
ROM5:5B7B 28 02            jr   z,5B7F
ROM5:5B7D 1E FF            ld   e,FF
ROM5:5B7F 7B               ld   a,e
ROM5:5B80 D1               pop  de
ROM5:5B81 C1               pop  bc
ROM5:5B82 C9               ret  

Increment DC

ROM5:5B83 F5               push af
ROM5:5B84 C5               push bc
ROM5:5B85 D5               push de
ROM5:5B86 F0 D9            ld   a,(ff00+D9)
ROM5:5B88 C6 01            add  a,01
ROM5:5B8A 4F               ld   c,a
ROM5:5B8B F0 DA            ld   a,(ff00+DA)
ROM5:5B8D CE 00            adc  a,00
ROM5:5B8F 47               ld   b,a              ;deck_capacity ++
ROM5:5B90 11 0F 27         ld   de,270F          ;de = 9999
ROM5:5B93 CD A7 1D         call 1DA7
ROM5:5B96 FE 00            cp   a,00
ROM5:5B98 20 02            jr   nz,5B9C          ;if(deck_capacity ≤ 9999), jump to 5:5B9C
ROM5:5B9A 42               ld   b,d
ROM5:5B9B 4B               ld   c,e              ;else deck_capacity = 9999
ROM5:5B9C 79               ld   a,c
ROM5:5B9D E0 D9            ld   (ff00+D9),a
ROM5:5B9F 78               ld   a,b
ROM5:5BA0 E0 DA            ld   (ff00+DA),a      ;store deck_capacity in hFFD9
ROM5:5BA2 D1               pop  de
ROM5:5BA3 C1               pop  bc
ROM5:5BA4 F1               pop  af
ROM5:5BA5 C9               ret  

Decrement DC

ROM5:5BA6 F5               push af
ROM5:5BA7 C5               push bc
ROM5:5BA8 D5               push de
ROM5:5BA9 F0 D9            ld   a,(ff00+D9)
ROM5:5BAB D6 01            sub  a,01
ROM5:5BAD 4F               ld   c,a
ROM5:5BAE F0 DA            ld   a,(ff00+DA)
ROM5:5BB0 DE 00            sbc  a,00
ROM5:5BB2 47               ld   b,a              ;deck_capacity --
ROM5:5BB3 11 90 01         ld   de,0190          ;de = 400
ROM5:5BB6 CD A7 1D         call 1DA7
ROM5:5BB9 FE 02            cp   a,02
ROM5:5BBB 20 02            jr   nz,5BBF          ;if(deck_capacity ≥ 400), jump to 5:5BBF
ROM5:5BBD 42               ld   b,d
ROM5:5BBE 4B               ld   c,e              ;else deck_capacity = 400
ROM5:5BBF 79               ld   a,c
ROM5:5BC0 E0 D9            ld   (ff00+D9),a
ROM5:5BC2 78               ld   a,b
ROM5:5BC3 E0 DA            ld   (ff00+DA),a      ;store deck_capacity in hFFD9
ROM5:5BC5 D1               pop  de
ROM5:5BC6 C1               pop  bc
ROM5:5BC7 F1               pop  af
ROM5:5BC8 C9               ret  

DC + 3

ROM5:5BC9 F5               push af
ROM5:5BCA 3E 03            ld   a,03
ROM5:5BCC CD 83 5B         call 5B83        ;Increment DC
ROM5:5BCF 3D               dec  a
ROM5:5BD0 20 FA            jr   nz,5BCC
ROM5:5BD2 F1               pop  af
ROM5:5BD3 C9               ret  

DC + 2

ROM5:5BD4 F5               push af
ROM5:5BD5 3E 02            ld   a,02
ROM5:5BD7 CD 83 5B         call 5B83        ;Increment DC
ROM5:5BDA 3D               dec  a
ROM5:5BDB 20 FA            jr   nz,5BD7
ROM5:5BDD F1               pop  af
ROM5:5BDE C9               ret  

DC + 10

ROM5:5BDF F5               push af
ROM5:5BE0 3E 0A            ld   a,0A
ROM5:5BE2 CD 83 5B         call 5B83        ;Increment DC
ROM5:5BE5 3D               dec  a
ROM5:5BE6 20 FA            jr   nz,5BE2
ROM5:5BE8 F1               pop  af
ROM5:5BE9 C9               ret  

DC + 5

ROM5:5BEA F5               push af
ROM5:5BEB 3E 05            ld   a,05
ROM5:5BED CD 83 5B         call 5B83        ;Increment DC
ROM5:5BF0 3D               dec  a
ROM5:5BF1 20 FA            jr   nz,5BED
ROM5:5BF3 F1               pop  af
ROM5:5BF4 C9               ret  

DC + 1

ROM5:5BF5 F5               push af
ROM5:5BF6 3E 01            ld   a,01
ROM5:5BF8 CD 83 5B         call 5B83        ;Increment DC
ROM5:5BFB 3D               dec  a
ROM5:5BFC 20 FA            jr   nz,5BF8
ROM5:5BFE F1               pop  af
ROM5:5BFF C9               ret  

DC - 50

ROM5:5C00 F5               push af
ROM5:5C01 C5               push bc
ROM5:5C02 D5               push de
ROM5:5C03 01 32 00         ld   bc,0032
ROM5:5C06 11 00 00         ld   de,0000
ROM5:5C09 CD A6 5B         call 5BA6        ;Decrement DC
ROM5:5C0C 0B               dec  bc
ROM5:5C0D CD 98 1D         call 1D98
ROM5:5C10 FE 00            cp   a,00
ROM5:5C12 20 F5            jr   nz,5C09
ROM5:5C14 D1               pop  de
ROM5:5C15 C1               pop  bc
ROM5:5C16 F1               pop  af
ROM5:5C17 C9               ret  


ROM5:5C18 C5               push bc
ROM5:5C19 D5               push de
ROM5:5C1A E5               push hl
ROM5:5C1B 2E 00            ld   l,00
ROM5:5C1D CF               rst  08
          09 0E
ROM5:5C20 F0 D9            ld   a,(ff00+D9)
ROM5:5C22 5F               ld   e,a
ROM5:5C23 F0 DA            ld   a,(ff00+DA)
ROM5:5C25 57               ld   d,a                 ;de = deck_capacity
ROM5:5C26 CD A7 1D         call 1DA7
ROM5:5C29 FE 00            cp   a,00
ROM5:5C2B 20 02            jr   nz,5C2F
ROM5:5C2D 2E 01            ld   l,01
ROM5:5C2F 7D               ld   a,l
ROM5:5C30 E1               pop  hl
ROM5:5C31 D1               pop  de
ROM5:5C32 C1               pop  bc
ROM5:5C33 C9               ret  

Check Link Duel DC

ROM5:5C34 C5               push bc
ROM5:5C35 D5               push de
ROM5:5C36 E5               push hl
ROM5:5C37 CF               rst  08
          09 0E
ROM5:5C3A 16 00            ld   d,00
ROM5:5C3C CF               rst  08
          89 0E
ROM5:5C3F 5F               ld   e,a
ROM5:5C40 CB 23            sla  e
ROM5:5C42 21 59 5C         ld   hl,5C59
ROM5:5C45 19               add  hl,de
ROM5:5C46 2A               ldi  a,(hl)
ROM5:5C47 56               ld   d,(hl)
ROM5:5C48 5F               ld   e,a                 ;de = max_deck_capacity
ROM5:5C49 CD A7 1D         call 1DA7
ROM5:5C4C 2E 00            ld   l,00
ROM5:5C4E FE 00            cp   a,00
ROM5:5C50 20 02            jr   nz,5C54
ROM5:5C52 2E 01            ld   l,01
ROM5:5C54 7D               ld   a,l
ROM5:5C55 E1               pop  hl
ROM5:5C56 D1               pop  de
ROM5:5C57 C1               pop  bc
ROM5:5C58 C9               ret  
Link Duel DC array
F4 01 -  500
BC 02 -  700
E8 03 - 1000
D0 07 - 2000
0F 27 - 9999

Check if enough DC for Password mode

  • Check if Deck Capacity ≥ 600 when trying to access Password menu
ROM5:5C63 C5               push bc
ROM5:5C64 D5               push de
ROM5:5C65 E5               push hl
ROM5:5C66 2E 00            ld   l,00
ROM5:5C68 01 58 02         ld   bc,0258              ;bc = 600
ROM5:5C6B F0 D9            ld   a,(ff00+D9)
ROM5:5C6D 5F               ld   e,a
ROM5:5C6E F0 DA            ld   a,(ff00+DA)
ROM5:5C70 57               ld   d,a                  ;de = Deck Capacity
ROM5:5C71 CD A7 1D         call 1DA7
ROM5:5C74 FE 00            cp   a,00
ROM5:5C76 20 02            jr   nz,5C7A
ROM5:5C78 2E 01            ld   l,01
ROM5:5C7A 7D               ld   a,l
ROM5:5C7B E1               pop  hl
ROM5:5C7C D1               pop  de
ROM5:5C7D C1               pop  bc
ROM5:5C7E C9               ret

Bank D


  • 0x34037-0x34050 - Check if it is a debug game, or if Grandpa's password has been entered
ROMD:4037 FE 00            cp   a,00
ROMD:4039 20 07            jr   nz,4042          ;if(debug), jump to D:4042
ROMD:403B CF               rst  08
ROMD:403C 25               dec  h
ROMD:403D 04               inc  b
ROMD:403E FE 00            cp   a,00
ROMD:4040 20 0C            jr   nz,404E          ;else if(!grandpa_drop), get out of this function
ROMD:4042 CD 5D 40         call 405D
ROMD:4045 CF               rst  08
  • 0x34037-0x34050 - ?
ROMD:4046 0D               dec  c
ROMD:4047 01 CF 17         ld   bc,17CF
ROMD:404A 01 CF 23         ld   bc,23CF
ROMD:404D 02               ld   (bc),a
ROMD:404E C1               pop  bc
ROMD:404F F1               pop  af
ROMD:4050 C9               ret
  • 0x34051-0x3405C - ?
ROMD:4051 F5               push af
ROMD:4052 06 00            ld   b,00
ROMD:4054 CF               rst  08
ROMD:4055 0F               rrca 
ROMD:4056 02               ld   (bc),a
ROMD:4057 4F               ld   c,a
ROMD:4058 CD E7 29         call 29E7
ROMD:405B F1               pop  af
ROMD:405C C9               ret  
  • 0x3405D-0x34066 - ?
ROMD:405D F5               push af
ROMD:405E 06 00            ld   b,00
ROMD:4060 0E 12            ld   c,12
ROMD:4062 CD E7 29         call 29E7	// Gives a random Card
ROMD:4065 F1               pop  af
ROMD:4066 C9               ret

Password mode

D:43B2 (Check ? when accessing Password)

ROMD:43B2 C5               push bc
ROMD:43B3 D5               push de
ROMD:43B4 CF               rst  08
          09 01
ROMD:43B7 16 00            ld   d,00
ROMD:43B9 78               ld   a,b
ROMD:43BA FE 00            cp   a,00
ROMD:43BC 20 0C            jr   nz,43CA          ;if(b ≠ 0), exit this function
ROMD:43BE 79               ld   a,c
ROMD:43BF FE 00            cp   a,00
ROMD:43C1 20 07            jr   nz,43CA          ;if(c ≠ 0), exit this function
ROMD:43C3 7B               ld   a,e
ROMD:43C4 FE 32            cp   a,32
ROMD:43C6 30 02            jr   nc,43CA          ;if(e ≥ 50), exit this function
ROMD:43C8 16 01            ld   d,01             ;d = 1
ROMD:43CA 7A               ld   a,d              ;a = 1
ROMD:43CB D1               pop  de
ROMD:43CC C1               pop  bc
ROMD:43CD C9               ret  

Card Passwords

  • 0x3476A-0x352A9 - Cards Passwords

Bank E

Is there a Save file ?

  • 0x3BB64-0x3BB6C - Is there a Save file ?
ROME:7B64 F5               push af
ROME:7B65 FA 88 DB         ld   a,(DB88)
ROME:7B68 FE 00            cp   a,00
ROME:7B6A 20 03            jr   nz,7B6F		// If there is a save file, check its integrity
ROME:7B6C CF               rst  08		// Else create a new Save file

rst 08 pointers

  • 0x3BB6D-0x3BB75 - Pointers + Bank used after a rst 08
0F 04 - Normal New Game
CF - rst 08
09 04 - Save file sanity check
CF - rst 08
0D 04

Bank 18

Graphics 2

0x48000 - ?

Bank 24 - 25

Card drops lists

0x90002 - Card drops lists, each drop rate is encoded on 3 nibbles, out of 2048.

aa ab bb cc cd dd ...

Bank 26 - 27

CPU Decks

0x98002 - CPU Decks cards lists, each card probability is encoded on 3 nibbles, out of 2048.

aa ab bb cc cd dd ...

Bank 28

Graphics 3

0xA0000 - ?

Bank 3B

rst 08 pointer

  • 0xEC002-0xEC003 - rst 08 pointer
04 40

Game Initialization

Name Input screen display

  • 0xEC004-0xEC043 - Name Input screen
RO3B:4004 F5               push af
RO3B:4005 C5               push bc
RO3B:4006 D5               push de
RO3B:4007 E5               push hl
RO3B:4008 4F               ld   c,a
RO3B:4009 F0 FF            ld   a,(ff00+FF)
RO3B:400B 57               ld   d,a
RO3B:400C E6 FC            and  a,FC
RO3B:400E E0 FF            ld   (ff00+FF),a	// Disable V-Blank and LCD STAT
RO3B:4010 D5               push de
RO3B:4011 CD 50 40         call 4050		// Blanks screen, checks system running the game
RO3B:4014 F5               push af
RO3B:4015 F0 DE            ld   a,(ff00+DE)	// a = (FFDE)
RO3B:4017 FE 00            cp   a,00
RO3B:4019 20 04            jr   nz,401F
RO3B:401B E8 04            add  sp,04
RO3B:401D 18 20            jr   403F
RO3B:401F FE 01            cp   a,01
RO3B:4021 20 04            jr   nz,4027
RO3B:4023 E8 04            add  sp,04
RO3B:4025 18 18            jr   403F
RO3B:4027 F1               pop  af
RO3B:4028 06 00            ld   b,00
RO3B:402A 21 44 40         ld   hl,4044
RO3B:402D 09               add  hl,bc
RO3B:402E 2A               ldi  a,(hl)
RO3B:402F 66               ld   h,(hl)
RO3B:4030 6F               ld   l,a
RO3B:4031 01 36 40         ld   bc,4036
RO3B:4034 C5               push bc
RO3B:4035 E9               jp   hl
RO3B:4036 D1               pop  de
RO3B:4037 21 40 FF         ld   hl,FF40
RO3B:403A CB FE            set  7,(hl)
RO3B:403C 7A               ld   a,d
RO3B:403D E0 FF            ld   (ff00+FF),a	// Restore previous Interrupt flags
RO3B:403F E1               pop  hl
RO3B:4040 D1               pop  de
RO3B:4041 C1               pop  bc
RO3B:4042 F1               pop  af
RO3B:4043 C9               ret  

Blanks screen, checks system running the game

  • 0xEC050-0xEC0CC - Blanks screen, checks system running the game
RO3B:4050 F5               push af
RO3B:4051 C5               push bc
RO3B:4052 D5               push de
RO3B:4053 E5               push hl
RO3B:4054 FE 00            cp   a,00
RO3B:4056 20 70            jr   nz,40C8
RO3B:4058 3E 00            ld   a,00
RO3B:405A E0 47            ld   (ff00+47),a	// White BG (Game Boy only)
RO3B:405C 21 40 FF         ld   hl,FF40
RO3B:405F CB FE            set  7,(hl)		// Enable LCD Display
RO3B:4061 21 0F 45         ld   hl,450F
RO3B:4064 CD 16 41         call 4116
RO3B:4067 1E 00            ld   e,00
RO3B:4069 F0 44            ld   a,(ff00+44)	// LCD Y-Coordinate
RO3B:406B FE 00            cp   a,00
RO3B:406D 20 FA            jr   nz,4069		// Wait for LCD Driver to be on first vertical line
RO3B:406F F0 44            ld   a,(ff00+44)
RO3B:4071 FE 90            cp   a,90
RO3B:4073 38 FA            jr   c,406F		// Wait for V-Blank period
RO3B:4075 16 0A            ld   d,0A
RO3B:4077 3E 20            ld   a,20		// Button keys
RO3B:4079 E0 00            ld   (ff00+00),a
RO3B:407B F0 00            ld   a,(ff00+00)
RO3B:407D F0 00            ld   a,(ff00+00)
RO3B:407F 3E 10            ld   a,10		// Direction keys
RO3B:4081 E0 00            ld   (ff00+00),a
RO3B:4083 F0 00            ld   a,(ff00+00)
RO3B:4085 F0 00            ld   a,(ff00+00)
RO3B:4087 F0 00            ld   a,(ff00+00)
RO3B:4089 F0 00            ld   a,(ff00+00)
RO3B:408B F0 00            ld   a,(ff00+00)
RO3B:408D F0 00            ld   a,(ff00+00)
RO3B:408F 3E 30            ld   a,30		// Button keys and Direction keys
RO3B:4091 E0 00            ld   (ff00+00),a
RO3B:4093 3E 30            ld   a,30
RO3B:4095 E0 00            ld   (ff00+00),a
RO3B:4097 3E 30            ld   a,30
RO3B:4099 E0 00            ld   (ff00+00),a
RO3B:409B 3E 30            ld   a,30
RO3B:409D E0 00            ld   (ff00+00),a
RO3B:409F F0 00            ld   a,(ff00+00)
RO3B:40A1 FE FE            cp   a,FE
RO3B:40A3 20 02            jr   nz,40A7
RO3B:40A5 1E 01            ld   e,01
RO3B:40A7 15               dec  d
RO3B:40A8 20 CD            jr   nz,4077	// Loop 10 times
RO3B:40AA 21 1F 45         ld   hl,451F
RO3B:40AD CD 16 41         call 4116		// Initialize Joypad 
RO3B:40B0 16 00            ld   d,00
RO3B:40B2 06 00            ld   b,00
RO3B:40B4 CB 23            sla  e
RO3B:40B6 0E 00            ld   c,00
RO3B:40B8 F0 DD            ld   a,(ff00+DD)	// a = System running the game
RO3B:40BA FE FF            cp   a,FF
RO3B:40BC 20 02            jr   nz,40C0
RO3B:40BE 0E 01            ld   c,01
RO3B:40C0 21 CD 40         ld   hl,40CD
RO3B:40C3 19               add  hl,de
RO3B:40C4 09               add  hl,bc
RO3B:40C5 7E               ld   a,(hl)		// Read corresponding value from array 3B:40CD
RO3B:40C6 E0 DE            ld   (ff00+DE),a
RO3B:40C8 E1               pop  hl
RO3B:40C9 D1               pop  de
RO3B:40CA C1               pop  bc
RO3B:40CB F1               pop  af
RO3B:40CC C9               ret

System running the game array

00 - Game Boy Color
02 - Game Boy
03 - Super Game Boy 2

Wait for Input

  • 0xEC116-0xEC15B - Wait for Input at the Name Input screen
RO3B:4116 F5               push af
RO3B:4117 C5               push bc
RO3B:4118 D5               push de
RO3B:4119 F0 44            ld   a,(ff00+44)	// LCD Y-Coordinate
RO3B:411B FE 90            cp   a,90
RO3B:411D 38 FA            jr   c,4119		// Wait for V-Blank period
RO3B:411F 3E 30            ld   a,30
RO3B:4121 E0 00            ld   (ff00+00),a
RO3B:4123 3E 00            ld   a,00
RO3B:4125 E0 00            ld   (ff00+00),a
RO3B:4127 3E 30            ld   a,30
RO3B:4129 E0 00            ld   (ff00+00),a	// Initialize Joypad
RO3B:412B 16 10            ld   d,10
RO3B:412D 2A               ldi  a,(hl)
RO3B:412E 47               ld   b,a
RO3B:412F 1E 08            ld   e,08
RO3B:4131 CB 38            srl  b
RO3B:4133 38 0A            jr   c,413F
RO3B:4135 3E 20            ld   a,20
RO3B:4137 E0 00            ld   (ff00+00),a
RO3B:4139 3E 30            ld   a,30
RO3B:413B E0 00            ld   (ff00+00),a
RO3B:413D 18 08            jr   4147
RO3B:413F 3E 10            ld   a,10
RO3B:4141 E0 00            ld   (ff00+00),a
RO3B:4143 3E 30            ld   a,30
RO3B:4145 E0 00            ld   (ff00+00),a
RO3B:4147 1D               dec  e
RO3B:4148 20 E7            jr   nz,4131
RO3B:414A 15               dec  d
RO3B:414B 20 E0            jr   nz,412D
RO3B:414D 3E 20            ld   a,20
RO3B:414F E0 00            ld   (ff00+00),a
RO3B:4151 3E 30            ld   a,30
RO3B:4153 E0 00            ld   (ff00+00),a
RO3B:4155 CD 5C 41         call 415C
RO3B:4158 D1               pop  de
RO3B:4159 C1               pop  bc
RO3B:415A F1               pop  af
RO3B:415B C9               ret

Bank 3E

Set wC920 to accumulator

RO3E:4076 EA 20 C9         ld   (C920),a
RO3E:4079 C9               ret  

Bank 40

40:4002 (to document, probably card drop subroutine)

RO40:4002 C3 26 40         jp   4026
RO40:4005 C3 3B 40         jp   403B
RO40:4008 C3 50 40         jp   4050
RO40:400B C3 65 40         jp   4065
RO40:400E C3 7A 40         jp   407A
RO40:4011 C3 8F 40         jp   408F
RO40:4014 C3 A4 40         jp   40A4
RO40:4017 C3 B9 40         jp   40B9
RO40:401A C3 CE 40         jp   40CE
RO40:401D C3 E3 40         jp   40E3
RO40:4020 C3 F8 40         jp   40F8
RO40:4023 C3 0D 41         jp   410D

40:410D (to document)

RO40:410D F5               push af
RO40:410E E5               push hl
RO40:410F 21 15 4B         ld   hl,4B15
RO40:4112 09               add  hl,bc
RO40:4113 56               ld   d,(hl)		// Stores bank 24 or 25 to register d, from array at RO40:4B15
RO40:4114 CB 21            sla  c
RO40:4116 CB 10            rl   b
RO40:4118 21 2D 4B         ld   hl,4B2D
RO40:411B 09               add  hl,bc
RO40:411C 2A               ldi  a,(hl)
RO40:411D 46               ld   b,(hl)
RO40:411E 4F               ld   c,a
RO40:411F E1               pop  hl
RO40:4120 F1               pop  af
RO40:4121 C9               ret

40:4B15 (Bank and pointers arrays)

  • 0x100B15 - 0x100B2C - Array, bank 24 or 25
24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 25
25 25 25 25 25 25 25 25
  • 0x100B2D - 0x100B5C - Array, pointers
02 40 3A 44 72 48 AA 4C E2 50 1A 55 52 59 52 59
8A 5D C2 61 FA 65 32 6A 6A 6E A2 72 DA 76 02 40
3A 44 72 48 72 48 AA 4C E2 50 1A 55 52 59 8A 5D

Internal Data for Yu-Gi-Oh! Duel Monsters II: Dark Duel Stories

ROM MapRAM MapText TableNotesTutorials