summaryrefslogtreecommitdiff
path: root/engine/card_flip.asm
blob: 9aeb94aec49034fe718e0ea7e23caddba289022b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
CARDFLIP_LIGHT_OFF EQU $ef
CARDFLIP_LIGHT_ON  EQU $f5
CARDFLIP_DECK_SIZE EQU 4 * 6

_CardFlip: ; e00ee (38:40ee)
	ld hl, Options
	set 4, [hl]
	call ClearBGPalettes
	call ClearTileMap
	call ClearSprites
	ld de, MUSIC_NONE
	call PlayMusic
	call DelayFrame
	call DisableLCD
	call LoadStandardFont
	call LoadFontsExtra

	ld hl, CardFlipLZ01
	ld de, VTiles2 tile $00
	call Decompress
	ld hl, CardFlipLZ02
	ld de, VTiles2 tile $3e
	call Decompress
	ld hl, CardFlipLZ03
	ld de, VTiles0 tile $00
	call Decompress
	ld hl, CardFlipOffButtonGFX
	ld de, VTiles1 tile $6f
	ld bc, 1 tiles
	call CopyBytes
	ld hl, CardFlipOnButtonGFX
	ld de, VTiles1 tile $75
	ld bc, 1 tiles
	call CopyBytes

	call CardFlip_ShiftDigitsLeftTwoPixels
	call CardFlip_InitTilemap
	call CardFlip_InitAttrPals
	call EnableLCD
	call WaitBGMap2
	ld a, $e4
	call DmgToCgbBGPals
	ld de, $e4e4
	call DmgToCgbObjPals
	call DelayFrame
	xor a
	ld [wJumptableIndex], a
	ld a, $2
	ld [wCardFlipCursorY], a
	ld [wCardFlipCursorX], a
	ld de, MUSIC_GAME_CORNER
	call PlayMusic
.MasterLoop
	ld a, [wJumptableIndex]
	bit 7, a
	jr nz, .leavethegame
	call .CardFlip
	jr .MasterLoop
.leavethegame
	call WaitSFX
	ld de, SFX_QUIT_SLOTS
	call PlaySFX
	call WaitSFX
	call ClearBGPalettes
	ld hl, Options
	res 4, [hl]
	ret

.CardFlip: ; e0191 (38:4191)
	ld a, [wJumptableIndex]
	ld e, a
	ld d, 0
	ld hl, .Jumptable
rept 2
	add hl, de
endr
	ld a, [hli]
	ld h, [hl]
	ld l, a
	jp [hl]
; e01a0 (38:41a0)

.Jumptable: ; e01a0
	
	dw .AskPlayWithThree
	dw .DeductCoins
	dw .ChooseACard
	dw .PlaceYourBet
	dw .CheckTheCard
	dw .TabulateTheResult
	dw .PlayAgain
	dw .Quit
; e01b0

.Increment: ; e01b0
	ld hl, wJumptableIndex
	inc [hl]
	ret
; e01b5

.AskPlayWithThree: ; e01b5
	ld hl, .PlayWithThreeCoinsText
	call CardFlip_UpdateCoinBalanceDisplay
	call YesNoBox
	jr c, .SaidNo
	call CardFlip_ShuffleDeck
	call .Increment
	ret

.SaidNo
	ld a, 7
	ld [wJumptableIndex], a
	ret
; e01cd

.PlayWithThreeCoinsText: ; 0xe01cd
	; Play with three coins?
	text_jump UnknownText_0x1c5793
	db "@"
; 0xe01d2

.DeductCoins: ; e01d2
	ld a, [Coins]
	ld h, a
	ld a, [Coins + 1]
	ld l, a
	ld a, h
	and a
	jr nz, .deduct ; You have at least 256 coins.
	ld a, l
	cp 3
	jr nc, .deduct ; You have at least 3 coins.
	ld hl, .NotEnoughCoinsText
	call CardFlip_UpdateCoinBalanceDisplay
	ld a, 7
	ld [wJumptableIndex], a
	ret

.deduct
	ld de, -3
	add hl, de
	ld a, h
	ld [Coins], a
	ld a, l
	ld [Coins + 1], a
	ld de, SFX_TRANSACTION
	call PlaySFX
	xor a
	ld [hBGMapMode], a
	call CardFlip_PrintCoinBalance
	ld a, $1
	ld [hBGMapMode], a
	call WaitSFX
	call .Increment
	ret
; e0212

.NotEnoughCoinsText: ; 0xe0212
	; Not enough coins…
	text_jump UnknownText_0x1c57ab
	db "@"
; 0xe0217

.ChooseACard: ; e0217
	xor a
	ld [hBGMapMode], a
	hlcoord 0, 0
	lb bc, 12, 9
	call CardFlip_FillGreenBox
	hlcoord 9, 0
	ld bc, SCREEN_WIDTH
	ld a, [wCardFlipNumCardsPlayed]
	call AddNTimes
	ld [hl], CARDFLIP_LIGHT_ON
	ld a, $1
	ld [hBGMapMode], a
	ld c, 20
	call DelayFrames
	hlcoord 2, 0
	call PlaceCardFaceDown
	ld a, $1
	ld [hBGMapMode], a
	ld c, 20
	call DelayFrames
	hlcoord 2, 6
	call PlaceCardFaceDown
	call WaitBGMap
	ld hl, .ChooseACardText
	call CardFlip_UpdateCoinBalanceDisplay
	xor a
	ld [wCardFlipWhichCard], a
.loop
	call JoyTextDelay
	ld a, [hJoyLast]
	and A_BUTTON
	jr nz, .next
	ld de, SFX_KINESIS
	call PlaySFX
	call PlaceOAMCardBorder
	ld c, 4
	call DelayFrames
	ld hl, wCardFlipWhichCard
	ld a, [hl]
	xor $1
	ld [hl], a
	jr .loop

.next
	ld de, SFX_SLOT_MACHINE_START
	call PlaySFX
	ld a, $3
.loop2
	push af
	call PlaceOAMCardBorder
	ld c, 4
	call DelayFrames
	call ClearSprites
	ld c, 4
	call DelayFrames
	pop af
	dec a
	jr nz, .loop2
	ld hl, wCardFlipWhichCard
	ld a, [hl]
	push af
	xor $1
	ld [hl], a
	call GetCoordsOfChosenCard
	lb bc, 6, 5
	call CardFlip_FillGreenBox
	pop af
	ld [wCardFlipWhichCard], a
	call .Increment
	ret
; e02b2

.ChooseACardText: ; 0xe02b2
	; Choose a card.
	text_jump UnknownText_0x1c57be
	db "@"
; 0xe02b7

.PlaceYourBet: ; e02b7
	ld hl, .PlaceYourBetText
	call CardFlip_UpdateCoinBalanceDisplay
.betloop
	call JoyTextDelay
	ld a, [hJoyLast]
	and A_BUTTON
	jr nz, .betdone
	call ChooseCard_HandleJoypad
	call CardFlip_UpdateCursorOAM
	call DelayFrame
	jr .betloop

.betdone
	call .Increment
	ret
; e02d5

.PlaceYourBetText: ; 0xe02d5
	; Place your bet.
	text_jump UnknownText_0x1c57ce
	db "@"
; 0xe02da

.CheckTheCard: ; e02da
	xor a
	ld [hVBlankCounter], a
	call CardFlip_UpdateCursorOAM
	call WaitSFX
	ld de, SFX_CHOOSE_A_CARD
	call PlaySFX
	call WaitSFX
	ld a, [wCardFlipNumCardsPlayed]
	ld e, a
	ld d, 0
	ld hl, wDeck
rept 2
	add hl, de
endr
	ld a, [wCardFlipWhichCard]
	ld e, a
	add hl, de
	ld a, [hl]
	ld [wCardFlipFaceUpCard], a
	ld e, a
	ld hl, wDiscardPile
	add hl, de
	ld [hl], TRUE
	call GetCoordsOfChosenCard
	call CardFlip_DisplayCardFaceUp
	call WaitBGMap2
	call .Increment
	ret
; e0314

.TabulateTheResult: ; e0314
	call CardFlip_CheckWinCondition
	call WaitPressAorB_BlinkCursor
	call .Increment
	ret
; e031e

.PlayAgain: ; e031e
	call ClearSprites
	ld hl, .PlayAgainText
	call CardFlip_UpdateCoinBalanceDisplay
	call YesNoBox
	jr nc, .Continue
	call .Increment
	ret

.Continue
	ld a, [wCardFlipNumCardsPlayed]
	inc a
	ld [wCardFlipNumCardsPlayed], a
	cp 12
	jr c, .KeepTheCurrentDeck
	call CardFlip_InitTilemap
	ld a, $1
	ld [hBGMapMode], a
	call CardFlip_ShuffleDeck
	ld hl, .CardsShuffledText
	call PrintText
	jr .LoopAround

.KeepTheCurrentDeck
	call CardFlip_BlankDiscardedCardSlot

.LoopAround
	ld a, 1
	ld [wJumptableIndex], a
	ret
; e0356

.PlayAgainText: ; 0xe0356
	; Want to play again?
	text_jump UnknownText_0x1c57df
	db "@"
; 0xe035b

.CardsShuffledText: ; 0xe035b
	; The cards have been shuffled.
	text_jump UnknownText_0x1c57f4
	db "@"
; 0xe0360

.Quit: ; e0360
	ld hl, wJumptableIndex
	set 7, [hl]
	ret
; e0366

CardFlip_ShuffleDeck: ; e0366
	ld hl, wDeck
	ld bc, CARDFLIP_DECK_SIZE
	xor a
	call ByteFill
	ld de, wDeck
	ld c, CARDFLIP_DECK_SIZE - 1
.loop
	call Random
	and $1f
	cp CARDFLIP_DECK_SIZE
	jr nc, .loop
	ld l, a
	ld h, $0
	add hl, de
	ld a, [hl]
	and a
	jr nz, .loop
	ld [hl], c
	dec c
	jr nz, .loop
	xor a
	ld [wCardFlipNumCardsPlayed], a
	ld hl, wDiscardPile
	ld bc, CARDFLIP_DECK_SIZE
	call ByteFill
	ret
; e0398

CollapseCursorPosition: ; e0398
	ld hl, 0
	ld bc, 6
	ld a, [wCardFlipCursorY]
	call AddNTimes
	ld b, $0
	ld a, [wCardFlipCursorX]
	ld c, a
	add hl, bc
	ret
; e03ac

GetCoordsOfChosenCard: ; e03ac
	ld a, [wCardFlipWhichCard]
	and a
	jr nz, .BottomCard
	hlcoord 2, 0
	bcpixel 2, 3
	jr .done

.BottomCard
	hlcoord 2, 6
	bcpixel 8, 3

.done
	ret
; e03c1

PlaceCardFaceDown: ; e03c1
	xor a
	ld [hBGMapMode], a
	ld de, .FaceDownCardTilemap
	lb bc, 6, 5
	call CardFlip_CopyToBox
	ret
; e03ce

.FaceDownCardTilemap: ; e03ce
	db $08, $09, $09, $09, $0a
	db $0b, $28, $2b, $28, $0c
	db $0b, $2c, $2d, $2e, $0c
	db $0b, $2f, $30, $31, $0c
	db $0b, $32, $33, $34, $0c
	db $0d, $0e, $0e, $0e, $0f
; e03ec

CardFlip_DisplayCardFaceUp: ; e03ec
	xor a
	ld [hBGMapMode], a
	push hl
	push hl
	; Flip the card face up.
	ld de, .FaceUpCardTilemap
	lb bc, 6, 5
	call CardFlip_CopyToBox

	; Get the level and species of the upturned card.
	ld a, [wCardFlipFaceUpCard]
	ld e, a
	ld d, 0
	ld hl, .Deck
rept 2
	add hl, de
endr
	ld a, [hli]
	ld e, a
	ld d, [hl]

	; Place the level.
	pop hl
	ld bc, 3 + SCREEN_WIDTH
	add hl, bc
	ld [hl], e

	; Place the Pokepic.
	ld bc, SCREEN_HEIGHT
	add hl, bc
	ld a, d
	ld de, SCREEN_WIDTH
	ld b, 3
.row
	push hl
	ld c, 3
.col
	ld [hli], a
	inc a
	dec c
	jr nz, .col
	pop hl
	add hl, de
	dec b
	jr nz, .row
	pop hl

	; Pointless CGB check
	ld a, [hCGB]
	and a
	ret z

	; Set the attributes
	ld de, AttrMap - TileMap
	add hl, de
	ld a, [wCardFlipFaceUpCard]
	and 3
	inc a
	lb bc, 6, 5
	call CardFlip_FillBox
	ret
; e043b

.FaceUpCardTilemap: ; e043b
	db $18, $19, $19, $19, $1a
	db $1b, $35, $7f, $7f, $1c
	db $0b, $28, $28, $28, $0c
	db $0b, $28, $28, $28, $0c
	db $0b, $28, $28, $28, $0c
	db $1d, $1e, $1e, $1e, $1f
; e0459

.Deck: ; e0459
	; level, pic anchor (3x3)
	db "1",$4e, "1",$57, "1",$69, "1",$60
	db "2",$4e, "2",$57, "2",$69, "2",$60
	db "3",$4e, "3",$57, "3",$69, "3",$60
	db "4",$4e, "4",$57, "4",$69, "4",$60
	db "5",$4e, "5",$57, "5",$69, "5",$60
	db "6",$4e, "6",$57, "6",$69, "6",$60
; e0489

CardFlip_UpdateCoinBalanceDisplay: ; e0489
	push hl
	hlcoord 0, 12
	ld b, 4
	ld c, SCREEN_WIDTH - 2
	call TextBox
	pop hl
	call PrintTextBoxText
	call CardFlip_PrintCoinBalance
	ret
; e049c

CardFlip_PrintCoinBalance: ; e049c
	hlcoord 9, 15
	ld b, 1
	ld c, 9
	call TextBox
	hlcoord 10, 16
	ld de, .CoinStr
	call PlaceString
	hlcoord 15, 16
	ld de, Coins
	lb bc, PRINTNUM_LEADINGZEROS | 2, 4
	call PrintNum
	ret
; e04bc

.CoinStr:
	db "COIN@"
; e04c1

CardFlip_InitTilemap: ; e04c1 (38:44c1)
	xor a
	ld [hBGMapMode], a
	hlcoord 0, 0
	ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
	ld a, $29
	call ByteFill
	hlcoord 9, 0
	ld de, CardFlipTilemap
	lb bc, 12, 11
	call CardFlip_CopyToBox
	hlcoord 0, 12
	lb bc, 4, 18
	call TextBox
	ret
; e04e5 (38:44e5)

CardFlip_FillGreenBox: ; e04e5
	ld a, $29

CardFlip_FillBox: ; e04e7 (38:44e7)
.row
	push bc
	push hl
.col
	ld [hli], a
	dec c
	jr nz, .col
	pop hl
	ld bc, SCREEN_WIDTH
	add hl, bc
	pop bc
	dec b
	jr nz, .row
	ret

CardFlip_CopyToBox: ; e04f7 (38:44f7)
.row
	push bc
	push hl
.col
	ld a, [de]
	inc de
	ld [hli], a
	dec c
	jr nz, .col
	pop hl
	ld bc, SCREEN_WIDTH
	add hl, bc
	pop bc
	dec b
	jr nz, .row
	ret
; e0509 (38:4509)

CardFlip_CopyOAM: ; e0509
	ld de, Sprites
	ld a, [hli]
.loop
	push af
	ld a, [hli]
	add b
	ld [de], a
	inc de
	ld a, [hli]
	add c
	ld [de], a
	inc de
	ld a, [hli]
	ld [de], a
	inc de
	ld a, [hli]
	ld [de], a
	inc de
	pop af
	dec a
	jr nz, .loop
	ret
; e0521

CardFlip_ShiftDigitsLeftTwoPixels: ; e0521 (38:4521)
	ld de, VTiles1 tile ("0" & $7f)
	ld hl, VTiles1 tile ("0" & $7f) + 2
	ld bc, 10 tiles - 2
	call CopyBytes
	ld hl, VTiles1 tile $7f + 1 tiles - 2
	xor a
	ld [hli], a
	ld [hl], a
	ret
; e0534 (38:4534)

CardFlip_BlankDiscardedCardSlot: ; e0534
	xor a
	ld [hBGMapMode], a
	ld a, [wCardFlipFaceUpCard]
	ld e, a
	ld d, 0

	and 3 ; get mon
	ld c, a
	ld b, 0

	ld a, e
	and $1c ; get level
	srl a
	add .Jumptable % $100
	ld l, a
	ld a, 0
	adc .Jumptable / $100
	ld h, a
	ld a, [hli]
	ld h, [hl]
	ld l, a
	jp [hl]
; e0553

.Jumptable: ; e0553
	
	dw .Level1
	dw .Level2
	dw .Level3
	dw .Level4
	dw .Level5
	dw .Level6
; e055f

.Level1: ; e055f
	ld hl, wDiscardPile + 4
	add hl, de
	ld a, [hl]
	and a
	jr nz, .discarded2
	hlcoord 13, 3
rept 2
	add hl, bc
endr
	ld [hl], $36
	ld bc, SCREEN_WIDTH
	add hl, bc
	ld [hl], $37
	ret

.discarded2
	hlcoord 13, 3
rept 2
	add hl, bc
endr
	ld [hl], $36
	ld bc, SCREEN_WIDTH
	add hl, bc
	ld [hl], $3d
	ret
; e0583

.Level2: ; e0583
	ld hl, wDiscardPile - 4
	add hl, de
	ld a, [hl]
	and a
	jr nz, .discarded1
	hlcoord 13, 4
rept 2
	add hl, bc
endr
	ld [hl], $3b
	ld bc, SCREEN_WIDTH
	add hl, bc
	ld [hl], $3a
	ret

.discarded1
	hlcoord 13, 4
rept 2
	add hl, bc
endr
	ld [hl], $3d
	ld bc, SCREEN_WIDTH
	add hl, bc
	ld [hl], $3a
	ret
; e05a7

.Level3: ; e05a7
	ld hl, wDiscardPile + 4
	add hl, de
	ld a, [hl]
	and a
	jr nz, .discarded4
	hlcoord 13, 6
rept 2
	add hl, bc
endr
	ld [hl], $36
	ld bc, SCREEN_WIDTH
	add hl, bc
	ld [hl], $38
	ret

.discarded4
	hlcoord 13, 6
rept 2
	add hl, bc
endr
	ld [hl], $36
	ld bc, SCREEN_WIDTH
	add hl, bc
	ld [hl], $3d
	ret
; e05cb

.Level4: ; e05cb
	ld hl, wDiscardPile - 4
	add hl, de
	ld a, [hl]
	and a
	jr nz, .discarded3
	hlcoord 13, 7
rept 2
	add hl, bc
endr
	ld [hl], $3c
	ld bc, SCREEN_WIDTH
	add hl, bc
	ld [hl], $3a
	ret

.discarded3
	hlcoord 13, 7
rept 2
	add hl, bc
endr
	ld [hl], $3d
	ld bc, SCREEN_WIDTH
	add hl, bc
	ld [hl], $3a
	ret
; e05ef

.Level5: ; e05ef
	ld hl, wDiscardPile + 4
	add hl, de
	ld a, [hl]
	and a
	jr nz, .discarded6
	hlcoord 13, 9
rept 2
	add hl, bc
endr
	ld [hl], $36
	ld bc, SCREEN_WIDTH
	add hl, bc
	ld [hl], $39
	ret

.discarded6
	hlcoord 13, 9
rept 2
	add hl, bc
endr
	ld [hl], $36
	ld bc, SCREEN_WIDTH
	add hl, bc
	ld [hl], $3d
	ret
; e0613

.Level6: ; e0613
	ld hl, wDiscardPile - 4
	add hl, de
	ld a, [hl]
	and a
	jr nz, .discarded5
	hlcoord 13, 10
rept 2
	add hl, bc
endr
	ld [hl], $3c
	ld bc, SCREEN_WIDTH
	add hl, bc
	ld [hl], $3a
	ret

.discarded5
	hlcoord 13, 10
rept 2
	add hl, bc
endr
	ld [hl], $3d
	ld bc, SCREEN_WIDTH
	add hl, bc
	ld [hl], $3a
	ret
; e0637

CardFlip_CheckWinCondition: ; e0637
	call CollapseCursorPosition
	add hl, hl
	ld de, .Jumptable
	add hl, de
	ld a, [hli]
	ld h, [hl]
	ld l, a
	jp [hl]
; e0643

.Jumptable: ; e0643
	
	dw .Impossible
	dw .Impossible
	dw .PikaJiggly
	dw .PikaJiggly
	dw .PoliOddish
	dw .PoliOddish

	dw .Impossible
	dw .Impossible
	dw .Pikachu
	dw .Jigglypuff
	dw .Poliwag
	dw .Oddish

	dw .OneTwo
	dw .One
	dw .PikaOne
	dw .JigglyOne
	dw .PoliOne
	dw .OddOne

	dw .OneTwo
	dw .Two
	dw .PikaTwo
	dw .JigglyTwo
	dw .PoliTwo
	dw .OddTwo

	dw .ThreeFour
	dw .Three
	dw .PikaThree
	dw .JigglyThree
	dw .PoliThree
	dw .OddThree

	dw .ThreeFour
	dw .Four
	dw .PikaFour
	dw .JigglyFour
	dw .PoliFour
	dw .OddFour

	dw .FiveSix
	dw .Five
	dw .PikaFive
	dw .JigglyFive
	dw .PoliFive
	dw .OddFive

	dw .FiveSix
	dw .Six
	dw .PikaSix
	dw .JigglySix
	dw .PoliSix
	dw .OddSix
; e06a3

.Impossible: ; e06a3
	jp .Lose
; e06a6

.PikaJiggly: ; e06a6
	ld a, [wCardFlipFaceUpCard]
	and $2
	jp nz, .Lose
	jr .WinSix

.PoliOddish: ; e06b0
	ld a, [wCardFlipFaceUpCard]
	and $2
	jr nz, .WinSix
	jp .Lose

.WinSix: ; e06ba
	ld c, $6
	ld de, SFX_2ND_PLACE
	jp .Payout
; e06c2

.OneTwo: ; e06c2
	ld a, [wCardFlipFaceUpCard]
	and $18
	jr z, .WinNine
	jp .Lose

.ThreeFour: ; e06cc
	ld a, [wCardFlipFaceUpCard]
	and $18
	cp $8
	jr z, .WinNine
	jp .Lose

.FiveSix: ; e06d8
	ld a, [wCardFlipFaceUpCard]
	and $18
	cp $10
	jr z, .WinNine
	jp .Lose

.WinNine: ; e06e4
	ld c, $9
	ld de, SFX_2ND_PLACE
	jp .Payout
; e06ec

.Pikachu: ; e06ec
	ld a, [wCardFlipFaceUpCard]
	and $3
	jr z, .WinTwelve
	jp .Lose

.Jigglypuff: ; e06f6
	ld a, [wCardFlipFaceUpCard]
	and $3
	cp $1
	jr z, .WinTwelve
	jp .Lose

.Poliwag: ; e0702
	ld a, [wCardFlipFaceUpCard]
	and $3
	cp $2
	jr z, .WinTwelve
	jp .Lose

.Oddish: ; e070e
	ld a, [wCardFlipFaceUpCard]
	and $3
	cp $3
	jr z, .WinTwelve
	jp .Lose

.WinTwelve: ; e071a
	ld c, $c
	ld de, SFX_2ND_PLACE
	jp .Payout
; e0722

.One: ; e0722
	ld a, [wCardFlipFaceUpCard]
	and $1c
	jr z, .WinEighteen
	jp .Lose

.Two: ; e072c
	ld a, [wCardFlipFaceUpCard]
	and $1c
	cp $4
	jr z, .WinEighteen
	jp .Lose

.Three: ; e0738
	ld a, [wCardFlipFaceUpCard]
	and $1c
	cp $8
	jr z, .WinEighteen
	jp .Lose

.Four: ; e0744
	ld a, [wCardFlipFaceUpCard]
	and $1c
	cp $c
	jr z, .WinEighteen
	jp .Lose

.Five: ; e0750
	ld a, [wCardFlipFaceUpCard]
	and $1c
	cp $10
	jr z, .WinEighteen
	jp .Lose

.Six: ; e075c
	ld a, [wCardFlipFaceUpCard]
	and $1c
	cp $14
	jr z, .WinEighteen
	jp .Lose

.WinEighteen: ; e0768
	ld c, $12
	ld de, SFX_2ND_PLACE
	jp .Payout
; e0770


.PikaOne: ; e0770
	ld e, $0
	jr .CheckWin72

.JigglyOne: ; e0774
	ld e, $1
	jr .CheckWin72

.PoliOne: ; e0778
	ld e, $2
	jr .CheckWin72

.OddOne: ; e077c
	ld e, $3
	jr .CheckWin72

.PikaTwo: ; e0780
	ld e, $4
	jr .CheckWin72

.JigglyTwo: ; e0784
	ld e, $5
	jr .CheckWin72

.PoliTwo: ; e0788
	ld e, $6
	jr .CheckWin72

.OddTwo: ; e078c
	ld e, $7
	jr .CheckWin72

.PikaThree: ; e0790
	ld e, $8
	jr .CheckWin72

.JigglyThree: ; e0794
	ld e, $9
	jr .CheckWin72

.PoliThree: ; e0798
	ld e, $a
	jr .CheckWin72

.OddThree: ; e079c
	ld e, $b
	jr .CheckWin72

.PikaFour: ; e07a0
	ld e, $c
	jr .CheckWin72

.JigglyFour: ; e07a4
	ld e, $d
	jr .CheckWin72

.PoliFour: ; e07a8
	ld e, $e
	jr .CheckWin72

.OddFour: ; e07ac
	ld e, $f
	jr .CheckWin72

.PikaFive: ; e07b0
	ld e, $10
	jr .CheckWin72

.JigglyFive: ; e07b4
	ld e, $11
	jr .CheckWin72

.PoliFive: ; e07b8
	ld e, $12
	jr .CheckWin72

.OddFive: ; e07bc
	ld e, $13
	jr .CheckWin72

.PikaSix: ; e07c0
	ld e, $14
	jr .CheckWin72

.JigglySix: ; e07c4
	ld e, $15
	jr .CheckWin72

.PoliSix: ; e07c8
	ld e, $16
	jr .CheckWin72

.OddSix: ; e07cc
	ld e, $17

.CheckWin72: ; e07ce
	ld a, [wCardFlipFaceUpCard]
	cp e
	jr nz, .Lose
	ld c, 72
	ld de, SFX_2ND_PLACE
	jr .Payout

.Lose: ; e07db
	ld de, SFX_WRONG
	call PlaySFX
	ld hl, .Text_Darn
	call CardFlip_UpdateCoinBalanceDisplay
	call WaitSFX
	ret

.Payout: ; e07eb
	push bc
	push de
	ld hl, .Text_Yeah
	call CardFlip_UpdateCoinBalanceDisplay
	pop de
	call PlaySFX
	call WaitSFX
	pop bc
.loop
	push bc
	call .IsCoinCaseFull
	jr c, .full
	call .AddCoinPlaySFX

.full
	call CardFlip_PrintCoinBalance
	ld c, 2
	call DelayFrames
	pop bc
	dec c
	jr nz, .loop
	ret
; e0811

.Text_Yeah: ; 0xe0811
	; Yeah!
	text_jump UnknownText_0x1c5813
	db "@"
; 0xe0816

.Text_Darn: ; 0xe0816
	; Darn…
	text_jump UnknownText_0x1c581a
	db "@"
; 0xe081b

.AddCoinPlaySFX: ; e081b
	ld a, [Coins]
	ld h, a
	ld a, [Coins + 1]
	ld l, a
	inc hl
	ld a, h
	ld [Coins], a
	ld a, l
	ld [Coins + 1], a
	ld de, SFX_PAY_DAY
	call PlaySFX
	ret
; e0833

.IsCoinCaseFull: ; e0833
	ld a, [Coins]
	cp 9999 / $100
	jr c, .less
	jr z, .check_low
	jr .more

.check_low
	ld a, [Coins + 1]
	cp 9999 % $100
	jr c, .less

.more
	scf
	ret

.less
	and a
	ret
; e0849

PlaceOAMCardBorder: ; e0849
	call GetCoordsOfChosenCard
	ld hl, .SpriteData
	call CardFlip_CopyOAM
	ret
; e0853

.SpriteData: ; e0853
	db 18
	dsprite 0, 0, 0, 0, $04, $00
	dsprite 0, 0, 1, 0, $06, $00
	dsprite 0, 0, 2, 0, $06, $00
	dsprite 0, 0, 3, 0, $06, $00
	dsprite 0, 0, 4, 0, $04, $20

	dsprite 1, 0, 0, 0, $05, $00
	dsprite 1, 0, 4, 0, $05, $20

	dsprite 2, 0, 0, 0, $05, $00
	dsprite 2, 0, 4, 0, $05, $20

	dsprite 3, 0, 0, 0, $05, $00
	dsprite 3, 0, 4, 0, $05, $20

	dsprite 4, 0, 0, 0, $05, $00
	dsprite 4, 0, 4, 0, $05, $20

	dsprite 5, 0, 0, 0, $04, $40
	dsprite 5, 0, 1, 0, $06, $40
	dsprite 5, 0, 2, 0, $06, $40
	dsprite 5, 0, 3, 0, $06, $40
	dsprite 5, 0, 4, 0, $04, $60
; e089c

ChooseCard_HandleJoypad: ; e089c
	ld hl, hJoyLast
	ld a, [hl]
	and D_LEFT
	jp nz, .d_left
	ld a, [hl]
	and D_RIGHT
	jp nz, .d_right
	ld a, [hl]
	and D_UP
	jp nz, .d_up
	ld a, [hl]
	and D_DOWN
	jp nz, .d_down
	ret
; e08b8

.d_left: ; e08b8
	ld hl, wCardFlipCursorX
	ld a, [wCardFlipCursorY]
	and a
	jr z, .mon_pair_left
	cp $1
	jr z, .mon_group_left
	ld a, [hl]
	and a
	ret z
	dec [hl]
	jp .play_sound

.mon_group_left
	ld a, [hl]
	cp $3
	jr c, .left_to_number_gp
	dec [hl]
	jp .play_sound

.mon_pair_left
	ld a, [hl]
	and $e
	ld [hl], a
	cp $3
	jr c, .left_to_number_gp
rept 2
	dec [hl]
endr
	jp .play_sound

.left_to_number_gp
	ld a, $2
	ld [wCardFlipCursorY], a
	ld a, $1
	ld [wCardFlipCursorX], a
	jp .play_sound
; e08ef

.d_right: ; e08ef
	ld hl, wCardFlipCursorX
	ld a, [wCardFlipCursorY]
	and a
	jr z, .mon_pair_right
	ld a, [hl]
	cp $5
	ret nc
	inc [hl]
	jr .play_sound

.mon_pair_right
	ld a, [hl]
	and $e
	ld [hl], a
	cp $4
	ret nc
rept 2
	inc [hl]
endr
	jr .play_sound

.d_up: ; e090a
	ld hl, wCardFlipCursorY
	ld a, [wCardFlipCursorX]
	and a
	jr z, .num_pair_up
	cp $1
	jr z, .num_gp_up
	ld a, [hl]
	and a
	ret z
	dec [hl]
	jr .play_sound

.num_gp_up
	ld a, [hl]
	cp $3
	jr c, .up_to_mon_group
	dec [hl]
	jr .play_sound

.num_pair_up
	ld a, [hl]
	and $e
	ld [hl], a
	cp $3
	jr c, .up_to_mon_group
rept 2
	dec [hl]
endr
	jr .play_sound

.up_to_mon_group
	ld a, $1
	ld [wCardFlipCursorY], a
	ld a, $2
	ld [wCardFlipCursorX], a
	jr .play_sound

.d_down: ; e093d
	ld hl, wCardFlipCursorY
	ld a, [wCardFlipCursorX]
	and a
	jr z, .num_pair_down
	ld hl, wCardFlipCursorY
	ld a, [hl]
	cp $7
	ret nc
	inc [hl]
	jr .play_sound

.num_pair_down
	ld a, [hl]
	and $e
	ld [hl], a
	cp $6
	ret nc
rept 2
	inc [hl]
endr

.play_sound: ; e0959
	ld de, SFX_POKEBALLS_PLACED_ON_TABLE
	call PlaySFX
	ret
; e0960

CardFlip_UpdateCursorOAM: ; e0960
	call ClearSprites
	ld a, [hCGB]
	and a
	jr nz, .skip
	ld a, [hVBlankCounter]
	and $4
	ret nz

.skip
	call CollapseCursorPosition
rept 2
	add hl, hl
endr
	ld de, .OAMData
	add hl, de
	ld a, [hli]
	ld c, a
	ld a, [hli]
	ld b, a
	ld a, [hli]
	ld h, [hl]
	ld l, a
	call CardFlip_CopyOAM
	ret
; e0981

.OAMData: ; e0981
cardflip_cursor: MACRO
if _NARG >= 5
	dbpixel \1, \2, \3, \4
	dw \5
else
	dbpixel \1, \2
	dw \3
endc
endm


	cardflip_cursor 11,  2,       .Impossible
	cardflip_cursor 12,  2,       .Impossible
	cardflip_cursor 13,  2,       .PokeGroupPair
	cardflip_cursor 13,  2,       .PokeGroupPair
	cardflip_cursor 17,  2,       .PokeGroupPair
	cardflip_cursor 17,  2,       .PokeGroupPair

	cardflip_cursor 11,  3,       .Impossible
	cardflip_cursor 12,  3,       .Impossible
	cardflip_cursor 13,  3,       .PokeGroup
	cardflip_cursor 15,  3,       .PokeGroup
	cardflip_cursor 17,  3,       .PokeGroup
	cardflip_cursor 19,  3,       .PokeGroup

	cardflip_cursor 11,  5,       .NumGroupPair
	cardflip_cursor 12,  5,       .NumGroup
	cardflip_cursor 13,  5,       .SingleTile
	cardflip_cursor 15,  5,       .SingleTile
	cardflip_cursor 17,  5,       .SingleTile
	cardflip_cursor 19,  5,       .SingleTile

	cardflip_cursor 11,  5,       .NumGroupPair
	cardflip_cursor 12,  6, 0, 4, .NumGroup
	cardflip_cursor 13,  6, 0, 4, .SingleTile
	cardflip_cursor 15,  6, 0, 4, .SingleTile
	cardflip_cursor 17,  6, 0, 4, .SingleTile
	cardflip_cursor 19,  6, 0, 4, .SingleTile

	cardflip_cursor 11,  8,       .NumGroupPair
	cardflip_cursor 12,  8,       .NumGroup
	cardflip_cursor 13,  8,       .SingleTile
	cardflip_cursor 15,  8,       .SingleTile
	cardflip_cursor 17,  8,       .SingleTile
	cardflip_cursor 19,  8,       .SingleTile

	cardflip_cursor 11,  8,       .NumGroupPair
	cardflip_cursor 12,  9, 0, 4, .NumGroup
	cardflip_cursor 13,  9, 0, 4, .SingleTile
	cardflip_cursor 15,  9, 0, 4, .SingleTile
	cardflip_cursor 17,  9, 0, 4, .SingleTile
	cardflip_cursor 19,  9, 0, 4, .SingleTile

	cardflip_cursor 11, 11,       .NumGroupPair
	cardflip_cursor 12, 11,       .NumGroup
	cardflip_cursor 13, 11,       .SingleTile
	cardflip_cursor 15, 11,       .SingleTile
	cardflip_cursor 17, 11,       .SingleTile
	cardflip_cursor 19, 11,       .SingleTile

	cardflip_cursor 11, 11,       .NumGroupPair
	cardflip_cursor 12, 12, 0, 4, .NumGroup
	cardflip_cursor 13, 12, 0, 4, .SingleTile
	cardflip_cursor 15, 12, 0, 4, .SingleTile
	cardflip_cursor 17, 12, 0, 4, .SingleTile
	cardflip_cursor 19, 12, 0, 4, .SingleTile
; e0a41

.SingleTile: ; e0a41
	db 6
	dsprite   0, 0,  -1, 7, $00, $80
	dsprite   0, 0,   0, 0, $02, $80
	dsprite   0, 0,   1, 0, $03, $80
	dsprite   0, 5,  -1, 7, $00, $c0
	dsprite   0, 5,   0, 0, $02, $c0
	dsprite   0, 5,   1, 0, $03, $80

.PokeGroup: ; e0a5a
	db 26
	dsprite   0, 0,  -1, 7, $00, $80
	dsprite   0, 0,   0, 0, $02, $80
	dsprite   0, 0,   1, 0, $00, $a0
	dsprite   1, 0,  -1, 7, $01, $80
	dsprite   1, 0,   1, 0, $01, $a0
	dsprite   2, 0,  -1, 7, $01, $80
	dsprite   2, 0,   1, 0, $03, $80
	dsprite   3, 0,  -1, 7, $01, $80
	dsprite   3, 0,   1, 0, $03, $80
	dsprite   4, 0,  -1, 7, $01, $80
	dsprite   4, 0,   1, 0, $03, $80
	dsprite   5, 0,  -1, 7, $01, $80
	dsprite   5, 0,   1, 0, $03, $80
	dsprite   6, 0,  -1, 7, $01, $80
	dsprite   6, 0,   1, 0, $03, $80
	dsprite   7, 0,  -1, 7, $01, $80
	dsprite   7, 0,   1, 0, $03, $80
	dsprite   8, 0,  -1, 7, $01, $80
	dsprite   8, 0,   1, 0, $03, $80
	dsprite   9, 0,  -1, 7, $01, $80
	dsprite   9, 0,   1, 0, $03, $80
	dsprite  10, 0,  -1, 7, $01, $80
	dsprite  10, 0,   1, 0, $03, $80
	dsprite  10, 1,  -1, 7, $00, $c0
	dsprite  10, 1,   0, 0, $02, $c0
	dsprite  10, 1,   1, 0, $03, $80

.NumGroup: ; e0ac3
	db 20
	dsprite   0, 0,  -1, 7, $00, $80
	dsprite   0, 0,   0, 0, $02, $80
	dsprite   0, 0,   1, 0, $02, $80
	dsprite   0, 0,   2, 0, $03, $80
	dsprite   0, 0,   3, 0, $02, $80
	dsprite   0, 0,   4, 0, $03, $80
	dsprite   0, 0,   5, 0, $02, $80
	dsprite   0, 0,   6, 0, $03, $80
	dsprite   0, 0,   7, 0, $02, $80
	dsprite   0, 0,   8, 0, $03, $80
	dsprite   0, 5,  -1, 7, $00, $c0
	dsprite   0, 5,   0, 0, $02, $c0
	dsprite   0, 5,   1, 0, $02, $c0
	dsprite   0, 5,   2, 0, $03, $80
	dsprite   0, 5,   3, 0, $02, $c0
	dsprite   0, 5,   4, 0, $03, $80
	dsprite   0, 5,   5, 0, $02, $c0
	dsprite   0, 5,   6, 0, $03, $80
	dsprite   0, 5,   7, 0, $02, $c0
	dsprite   0, 5,   8, 0, $03, $80

.NumGroupPair: ; e0b14
	db 30
	dsprite   0, 0,   0, 0, $00, $80
	dsprite   0, 0,   1, 0, $02, $80
	dsprite   0, 0,   2, 0, $02, $80
	dsprite   0, 0,   3, 0, $03, $80
	dsprite   0, 0,   4, 0, $02, $80
	dsprite   0, 0,   5, 0, $03, $80
	dsprite   0, 0,   6, 0, $02, $80
	dsprite   0, 0,   7, 0, $03, $80
	dsprite   0, 0,   8, 0, $02, $80
	dsprite   0, 0,   9, 0, $03, $80
	dsprite   1, 0,   0, 0, $01, $80
	dsprite   1, 0,   3, 0, $03, $80
	dsprite   1, 0,   5, 0, $03, $80
	dsprite   1, 0,   7, 0, $03, $80
	dsprite   1, 0,   9, 0, $03, $80
	dsprite   2, 0,   0, 0, $01, $80
	dsprite   2, 0,   3, 0, $03, $80
	dsprite   2, 0,   5, 0, $03, $80
	dsprite   2, 0,   7, 0, $03, $80
	dsprite   2, 0,   9, 0, $03, $80
	dsprite   2, 1,   0, 0, $00, $c0
	dsprite   2, 1,   1, 0, $02, $c0
	dsprite   2, 1,   2, 0, $02, $c0
	dsprite   2, 1,   3, 0, $03, $80
	dsprite   2, 1,   4, 0, $03, $80
	dsprite   2, 1,   5, 0, $03, $80
	dsprite   2, 1,   6, 0, $03, $80
	dsprite   2, 1,   7, 0, $03, $80
	dsprite   2, 1,   8, 0, $03, $80
	dsprite   2, 1,   9, 0, $03, $80

.PokeGroupPair: ; e0b8d
	db 38
	dsprite   0, 0,  -1, 7, $00, $80
	dsprite   0, 0,   3, 0, $00, $a0
	dsprite   1, 0,  -1, 7, $01, $80
	dsprite   1, 0,   3, 0, $01, $a0
	dsprite   2, 0,  -1, 7, $01, $80
	dsprite   2, 0,   3, 0, $01, $a0
	dsprite   3, 0,  -1, 7, $01, $80
	dsprite   3, 0,   1, 0, $03, $80
	dsprite   3, 0,   3, 0, $03, $80
	dsprite   4, 0,  -1, 7, $01, $80
	dsprite   4, 0,   1, 0, $03, $80
	dsprite   4, 0,   3, 0, $03, $80
	dsprite   5, 0,  -1, 7, $01, $80
	dsprite   5, 0,   1, 0, $03, $80
	dsprite   5, 0,   3, 0, $03, $80
	dsprite   6, 0,  -1, 7, $01, $80
	dsprite   6, 0,   1, 0, $03, $80
	dsprite   6, 0,   3, 0, $03, $80
	dsprite   7, 0,  -1, 7, $01, $80
	dsprite   7, 0,   1, 0, $03, $80
	dsprite   7, 0,   3, 0, $03, $80
	dsprite   8, 0,  -1, 7, $01, $80
	dsprite   8, 0,   1, 0, $03, $80
	dsprite   8, 0,   3, 0, $03, $80
	dsprite   9, 0,  -1, 7, $01, $80
	dsprite   9, 0,   1, 0, $03, $80
	dsprite   9, 0,   3, 0, $03, $80
	dsprite  10, 0,  -1, 7, $01, $80
	dsprite  10, 0,   1, 0, $03, $80
	dsprite  10, 0,   3, 0, $03, $80
	dsprite  11, 0,  -1, 7, $01, $80
	dsprite  11, 0,   1, 0, $03, $80
	dsprite  11, 0,   3, 0, $03, $80
	dsprite  11, 1,  -1, 7, $00, $c0
	dsprite  11, 1,   0, 0, $02, $c0
	dsprite  11, 1,   1, 0, $03, $c0
	dsprite  11, 1,   2, 0, $02, $c0
	dsprite  11, 1,   3, 0, $03, $e0

.Impossible: ; e0c26
	db 4
	dsprite   0, 0,   0, 0, $00, $80
	dsprite   0, 0,   1, 0, $00, $a0
	dsprite   1, 0,   0, 0, $00, $c0
	dsprite   1, 0,   1, 0, $00, $e0
; e0c37

CardFlip_InitAttrPals: ; e0c37 (38:4c37)
	ld a, [hCGB]
	and a
	ret z

	hlcoord 0, 0, AttrMap
	ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
	xor a
	call ByteFill

	hlcoord 12, 1, AttrMap
	lb bc, 2, 2
	ld a, $1
	call CardFlip_FillBox

	hlcoord 14, 1, AttrMap
	lb bc, 2, 2
	ld a, $2
	call CardFlip_FillBox

	hlcoord 16, 1, AttrMap
	lb bc, 2, 2
	ld a, $3
	call CardFlip_FillBox

	hlcoord 18, 1, AttrMap
	lb bc, 2, 2
	ld a, $4
	call CardFlip_FillBox

	hlcoord 9, 0, AttrMap
	lb bc, 12, 1
	ld a, $1
	call CardFlip_FillBox

	ld a, [rSVBK]
	push af
	ld a, $5
	ld [rSVBK], a
	ld hl, .palettes
	ld de, UnknBGPals
	ld bc, 9 palettes
	call CopyBytes
	pop af
	ld [rSVBK], a
	ret
; e0c93 (38:4c93)

.palettes: ; e0c93
	RGB 31, 31, 31
	RGB 17, 07, 31
	RGB 06, 19, 08
	RGB 00, 00, 00

	RGB 31, 31, 31
	RGB 29, 25, 00
	RGB 06, 19, 08
	RGB 00, 00, 00

	RGB 31, 31, 31
	RGB 31, 13, 30
	RGB 06, 19, 08
	RGB 00, 00, 00

	RGB 31, 31, 31
	RGB 08, 17, 30
	RGB 06, 19, 08
	RGB 00, 00, 00

	RGB 31, 31, 31
	RGB 08, 31, 08
	RGB 06, 19, 08
	RGB 00, 00, 00

	RGB 31, 31, 31
	RGB 17, 07, 31
	RGB 06, 19, 08
	RGB 00, 00, 00

	RGB 31, 31, 31
	RGB 17, 07, 31
	RGB 06, 19, 08
	RGB 00, 00, 00

	RGB 31, 31, 31
	RGB 17, 07, 31
	RGB 06, 19, 08
	RGB 00, 00, 00

	RGB 31, 31, 31
	RGB 31, 31, 31
	RGB 31, 00, 00
	RGB 31, 00, 00
; e0cdb

CardFlipLZ03: ; e0cdb
INCBIN "gfx/unknown/0e0cdb.2bpp.lz"

CardFlipOffButtonGFX: ; e0cf6
INCBIN "gfx/unknown/0e0cf6.2bpp"

CardFlipOnButtonGFX: ; e0d06
INCBIN "gfx/unknown/0e0d06.2bpp"

CardFlipLZ01: ; e0d16
INCBIN "gfx/unknown/0e0d16.2bpp.lz"

CardFlipLZ02: ; e0ea8
INCBIN "gfx/unknown/0e0ea8.2bpp.lz"

CardFlipTilemap: ; e110c
	db $ef, $15, $27, $2a, $2a, $06, $27, $2a, $2a, $06, $27
	db $ef, $07, $27, $3e, $3f, $42, $43, $46, $47, $4a, $4b
	db $ef, $17, $26, $40, $41, $44, $45, $48, $49, $4c, $4d
	db $ef, $25, $04, $00, $01, $00, $01, $00, $01, $00, $01
	db $ef, $05, $14, $10, $11, $10, $11, $10, $11, $10, $11
	db $ef, $16, $24, $20, $21, $20, $21, $20, $21, $20, $21
	db $ef, $25, $04, $00, $02, $00, $02, $00, $02, $00, $02
	db $ef, $05, $14, $10, $12, $10, $12, $10, $12, $10, $12
	db $ef, $16, $24, $20, $22, $20, $22, $20, $22, $20, $22
	db $ef, $25, $04, $00, $03, $00, $03, $00, $03, $00, $03
	db $ef, $05, $14, $10, $13, $10, $13, $10, $13, $10, $13
	db $ef, $16, $24, $20, $23, $20, $23, $20, $23, $20, $23
; e1190