forked from asmboy4gb/asmboy4gb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasmboy4gb.asm
4052 lines (3661 loc) · 66.4 KB
/
asmboy4gb.asm
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
INCLUDE "hardware.inc"
INCLUDE "fontCharmap.asm"
DEF BATTERY_RAM= $A000
DEF ARROW_START_X= 40
DEF ARROW_START_Y= 32
DEF HIGHER_BYTE_USED_FOR_LABELS = $E0
DEF HIGHER_BYTE_ADDRESS_CODE_END =$D0
SECTION "VBlankInterrupt", ROM0[$040]
push af
call GetButtons
and a, BUTTON_START
jp nz, NoStartButtonInterrupt
ld hl, ContinueAfterCodeRun
pop af
push hl
reti ; return to ContinueAfterCodeRun
NoStartButtonInterrupt:
pop af
reti
SECTION "Header", ROM0[$100]
jp EntryPoint
ds $150 - @, 0 ; Header will be placed here
; Do not move the following functions until Entry point other wise save cames will not work
; with new revision of the game as this addresses are commonly used by programms
; None of these functions should modify any register
FunctionToWaitForNextVBlank:
push af
_FunctionToWaitForNextVBlank1:
ld a, [rLY]
cp 144
jp nc, _FunctionToWaitForNextVBlank1
_FunctionToWaitForNextVBlank2:
ld a, [rLY]
cp 144
jp c, _FunctionToWaitForNextVBlank2
pop af
ret
DEF BACKGROUND_TILE_IN_ONE_VBLANK=64
ClearBackground:
call FunctionToWaitForNextVBlank
push af
push bc
push hl
push de
ld bc, _SCRN1 - _SCRN0
ld hl, _SCRN0
ld d, BACKGROUND_TILE_IN_ONE_VBLANK
_ClearBackgroundLoop:
ld a, 0
ld [hli], a
dec d
jp nz, _NoWaitVblankNeeded
call FunctionToWaitForNextVBlank
ld d, BACKGROUND_TILE_IN_ONE_VBLANK
_NoWaitVblankNeeded:
dec bc
ld a, b
or a, c
jp nz, _ClearBackgroundLoop
call FunctionToWaitForNextVBlank ; so caller can directly start using vram
pop de
pop hl
pop bc
pop af
ret
DEF DPAD_DOWN =%00001000
DEF DPAD_UP =%00000100
DEF DPAD_LEFT =%00000010
DEF DPAD_RIGHT =%00000001
; Return in register a DPAD_DOWN, DPAD_UP ,DPAD_LEFT ,DPAD_RIGHT bits
; only modifies a
GetDPad:
ld a, P1F_GET_DPAD
ld [rP1], a
call _GetDPadRet ; only to add delay
ld a , [rP1] ; wait until input stablized
ld a , [rP1]
ld a , [rP1] ; Okay now use this value
_GetDPadRet:
ret
DEF BUTTON_START =%00001000
DEF BUTTON_SELECT =%00000100
DEF BUTTON_B =%00000010
DEF BUTTON_A =%00000001
GetButtons:
ld a, P1F_GET_BTN
ld [rP1], a
call _GetButtonsRet ; only to add delay
ld a , [rP1] ; wait until input stablized
ld a , [rP1]
ld a , [rP1] ; Okay now use this value
_GetButtonsRet:
ret
; Parameter:
; hl destination address
; a value to print (only 0-99)
PrintNumberAsDecimal:
push bc
cp a, 100 ; ignore numbers >= 100
jp nc, _PrintNumberAsDecimalExit
ld b,0
ld c, 10
_LoopDivideBy10:
sub a,c
inc b
jp nc, _LoopDivideBy10
dec b
add a,c
ld c, a
; now b has a/10 and c has a%10
ld a, b
add a, "0"
ld [hli], a
ld a,c
add a, "0"
ld [hli], a
_PrintNumberAsDecimalExit:
pop bc
ret
; Paramter:
; hl: destination in tilemap
PrintGameOver:
push af
push bc
push de
push hl
call ClearBackground
ld de, GameOverTextLine1
ld bc, GameOverTextLine1End - GameOverTextLine1
call printStr
pop hl
ld b, 0
ld c, $3B ; skip two lines but make it centered
add hl, bc
ld de, GameOverTextLine2
ld bc, GameOverTextLine2End - GameOverTextLine2
call printStr
_WaitForButtonA:
call GetButtons
and a, BUTTON_A
jp nz, _WaitForButtonA
_PrintGameOverExit:
call FunctionToWaitForNextVBlank
pop de
pop bc
pop af
ret
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
GameOverTextLine1:
db "GAME OVER!"
GameOverTextLine1End:
GameOverTextLine2:
db "PRESS A TO CONTINUE"
GameOverTextLine2End:
EntryPoint:
; stop audio
ld a, 0
ld [rNR52], a
; Turning of LCD outside of VBlank might damage hardware
call FunctionToWaitForNextVBlank
; Turn the LCD off
ld a, 0
ld [rLCDC], a
; Copy the font to the tile area
ld de, fontStart
ld hl, $9000
ld bc, fontEnd - fontStart
CopyTiles:
ld a, [de]
ld [hli], a
inc de
dec bc
ld a, b
or a, c
jp nz, CopyTiles
; Copy the arrow to the object tile area
ld de, SelectorTile
ld hl, $8000
ld bc, SelectorTileEnd - SelectorTile
CopySelectorTile:
ld a, [de]
ld [hli], a
inc de
dec bc
ld a, b
or a, c
jp nz, CopySelectorTile
call ClearOam
MACRO printComma
ld a, ","
ld [bc],a
inc bc
ENDM
MACRO printCollon
ld a, ":"
ld [bc],a
inc bc
ENDM
MACRO printSpace
ld a, " "
ld [bc],a
inc bc
ENDM
MACRO printOpenBracket
ld a, "["
ld [bc],a
inc bc
ENDM
MACRO printClosingBracket
ld a, "]"
ld [bc],a
inc bc
ENDM
MACRO print0x
ld a, "0"
ld [bc],a
inc bc
ld a, "x"
ld [bc],a
inc bc
ENDM
MACRO printDollar
ld a, "$"
ld [bc],a
inc bc
ENDM
MACRO printA
ld a, "A"
ld [bc],a
inc bc
ENDM
MACRO resetArrow
ld hl, _OAMRAM
ld a, ARROW_START_Y
ld [hli], a
ld a, ARROW_START_X
ld [hli], a
ld a, 0
ld [hli], a
ld [hl], a
ENDM
MACRO moveBit0To2ThreeBitsLeft
sla a
sla a
sla a
and a,$38
ENDM
MACRO moveBit0To1FourBitsLeft
sla a
sla a
sla a
sla a
and a,$30
ENDM
MACRO moveBit0To1SixBitsLeft
sla a
sla a
sla a
sla a
sla a
sla a
and a, $C0
ENDM
MACRO moveBit6To7FourBitsRight
sra a
sra a
sra a
sra a
and a, $0C
ENDM
MACRO moveBit3To5ThreeBitsRight
sra a
sra a
sra a
and a, $07
ENDM
MACRO moveBit3To5OneBitRight
sra a
and a, $1C
ENDM
; Instruction value in c
; Return lenght in bc (b alsway 0)
MACRO getLengthOfInstruction
ld hl, LengthOfInstructions
ld b, 0
add hl,bc
ld a, [hl]
ld c, a
ENDM
MACRO getLabelAddress
ld hl, $9800
ld de, HeadlineSelectFirstNibble
ld bc, HeadlineSelectFirstNibbleEnd-HeadlineSelectFirstNibble
call printStr
ld de, SelectionHexNibble
ld hl, $9800
call ShowSelectionScreen
ld d,a
push de
ld hl, $9800
ld de, HeadlineSelectSecondNibble
ld bc, HeadlineSelectSecondNibbleEnd-HeadlineSelectSecondNibble
call printStr
ld de, SelectionHexNibble
ld hl, $9800
call ShowSelectionScreen
pop de
ld b, a
ld a, d
call CombineNibbles
ENDM
; Write object
ld hl, _OAMRAM
ld a, ARROW_START_Y
ld [hli], a
ld a, ARROW_START_X
ld [hli], a
ld a, 0
ld [hli], a
ld [hl], a
; Turn the LCD on
ld a, LCDCF_ON | LCDCF_BGON | LCDCF_OBJON
ld [rLCDC], a
; During the first (blank) frame, initialize display registers
ld a, %11100100
ld [rBGP], a
;ld a, %11100100
ld [rOBP0], a
; Copy to RAM
ld de, SampleCode1
ld hl, Cds
ld bc, SampleCode1End - SampleCode1
CopySample1:
ld a, [de]
ld [hli], a
inc de
dec bc
ld a, b
or a, c
jp nz, CopySample1
ld hl, CdsLabels
ld bc, CdsLabelsEnd - CdsLabels
ld a, 0
InitalizeCdsLabelsToZero:
ld [hli], a
dec bc
ld a, b
or a, c
jp nz, InitalizeCdsLabelsToZero
ld de, SampleCode1Labels
ld hl, CdsLabels
ld bc, SampleCode1LabelsEnd - SampleCode1Labels
CopySample1Labels:
ld a, [de]
ld [hli], a
inc de
dec bc
ld a, b
or a, c
jp nz, CopySample1Labels
; Multiple of 8
DEF ScrollSpeed = 8
Main:
; Init variables
ld c, $B3
ld d, $AF
nop
ld d, $95
ld a, 0
nop
ld [counter], a
ld a, 1
ld [bitmap], a
WaitB10:
ld a, [rLY]
cp 144
jp nc, WaitB10
WaitVBlank10:
ld a, [rLY]
cp 144
jp c, WaitVBlank10
Def StartVRAM=$9805
ld bc, Cds
ld de, StartVRAM
ld a, $FF
ld [FoundLabel],a
printIntrucstionLoop:
ld a,d
cp a,$9C
jp c, NoVramOverflow
ld d, $98 ; Reset to screen start
NoVramOverflow:
ld a,b
cp a, HIGHER_BYTE_ADDRESS_CODE_END
jp c, NoRamOverflow
ld bc, Cds ; start at beginning
NoRamOverflow:
push de
push bc
; Print address:
ld a, b ;first part of address
ld h, c ;
ld b, d
ld c, e
dec c
dec c
dec c
dec c
dec c
call PrintNumberAsHex ; does not modify hl
ld a, h ; second part of address
call PrintNumberAsHex
printSpace
pop bc
pop de
push de
push bc
ld a, [FoundLabel]
cp a, $ff
jp z, NormalInstructionPrint
ld h, d
ld l, e
ld de, LabelText
ld bc, LabelTextEnd-LabelText
call printStr
ld b, h
ld c, l
ld a, [FoundLabel]
call PrintNumberAsHex
printCollon
ld a, [bitmap]
set 5, a ; bitmap signal label was really printed
ld [bitmap], a
ld a, 0 ; do not increase pointer to Ram
jp IncreaseAddressesAfterPrint
NormalInstructionPrint:
call PrintInstruction
ld d, a
ld a, [bitmap]
res 4, a ; bitmap third bit means down still pressed
ld [bitmap], a
ld a, d
IncreaseAddressesAfterPrint:
ld d, 0
ld e, a
pop hl
add hl, de ; increase Ram with instruction length
ld b, h
ld c, l
pop hl
ld d, 0
ld e, $20
add hl, de ; increase destination vram to next line
ld d, h
ld e, l
SkipPrint:
push de
push bc
ld a, [bitmap]
bit 0, a
jp nz,NotAnyKey ; If drawing is going on dont evaluate keys. because logic depends on addresses printed to vram
call GetDPad
ld b,a
and a, DPAD_DOWN
jp z, DownKeyPressed
ld a, [bitmap]
res 2, a ; bitmap third bit means down still pressed
ld [bitmap], a
jp NoMovementDown
DownKeyPressed:
ld hl, _OAMRAM
ld a, [hl] ; get y position of arrow
cp a, $81
jp nc, ScrollTextDown
ld a, [bitmap]
bit 2, a
jp nz, NoMovementDown ; ignore holding down as long as arrow not at bottom
ld a, [hl]
add a, 8
ld [hl], a
ld a, [bitmap]
set 2, a ; bitmap third bit means down still pressed
ld [bitmap], a
jp NoMovementDown
ScrollTextDown:
ld a, [rSCY]
;cp a,$60
;jp z,NoMovementDown
add a, ScrollSpeed
ld [rSCY], a
ld a, [counter]
add a, ScrollSpeed
cp a, 8
jp nc, SetFlagNextLinePrint
NoFlagNextLinePrint:
ld [counter],a
jp NoMovementDown
SetFlagNextLinePrint:
sub a, 8
ld [counter], a
ld a, [bitmap]
set 1, a ; bitmap second bit means one line to print
ld [bitmap], a
NoMovementDown:
ld a,b
and a, DPAD_UP
jp z, UpKeyPressed
ld a, [bitmap]
res 3, a ; bitmap third bit means down still pressed
ld [bitmap], a
jp NoMovementUp
UpKeyPressed:
ld hl, _OAMRAM
ld a, [hl] ; get y position of arrow
cp a, $15
jp c, ScrollToBeginning
ld a, [bitmap]
bit 3, a
jp nz, NoMovementUp ; ignore holding down as long as arrow not at bottom
ld a, [hl]
sub a, 8
ld [hl], a
ld a, [bitmap]
set 3, a ; bitmap third bit means down still pressed
ld [bitmap], a
jp NoMovementUp
ScrollToBeginning:
ld bc, Cds
ld de, StartVRAM
ld a, [bitmap]
set 0, a ; bitmap first bit means complete screen refresh
ld [bitmap], a
ld a, 0
ld [rSCY], a
pop hl ; value not needed but to keep stack correct
pop hl
jp MovementUpDone
NoMovementUp:
call GetDPad
and a, DPAD_LEFT
jp nz, NoLeftKey
AskToDelete:
; save arrow position
ld a, [ _OAMRAM]
ld d,a
push de
; get address top in screen
call GetAddressInTopScreen
ld d,e
ld e,a
push de
call GetAddressOfArrow
push bc
ld de, SelectionDeleteLine
ld hl, $9800
call ShowSelectionScreen
pop bc
cp a, 1 ; Option 1 is YES
jp z, SelectedToDelete
SelecteNotToDelete:
jp redrawComplete
SelectedToDelete:
push bc
call DeleteInstructionAtAddress
pop bc
call DecreaseLabelAddress
call FunctionToWaitForNextVBlank
redrawComplete:
pop bc ; set RAM address to addres found in vram top left
pop de
; set arrow to old position:
ld hl, _OAMRAM
ld a, d
ld [hli], a
ld a, ARROW_START_X
ld [hli], a
ld a, 0
ld [hli], a
ld [hl], a
ld de, StartVRAM
ld a, [bitmap]
set 0, a ; bitmap first bit means complete screen refresh
ld [bitmap], a
ld a, 0
ld [rSCY], a
pop hl ; value not needed but to keep stack correct
pop hl
jp MovementUpDone
NoLeftKey:
call GetDPad
and a, DPAD_RIGHT
jp nz, NoRightKey
AskToAdd:
; save arrow position
ld a, [ _OAMRAM]
ld d,a
push de
; get address top in screen
call GetAddressInTopScreen
ld d,e
ld e,a
push de
call GetAddressOfArrow
push bc
SelectInstructionType:
ld de, SelectionAddInstr
ld hl, $9800
call ShowSelectionScreen
pop bc
cp a, 0
jp z, ExitSelectInstruction
cp a, 1
jp z, SelecteNOP
cp a, 2
jp z, SelectedLDA
cp a, 3
jp z, SelectedAluR8
cp a, 4
jp z, SelectedAluD8
cp a, 5
jp z, SelectedJumpCall
cp a, 6
jp z, SelectedPushPop
cp a, 7
jp z, SelectedIncDec
cp a, 8
jp z,SelectedBitOperation
cp a, 9
jp z, SelectedLabelToAdd
; no option select, should not happen
call FunctionToWaitForNextVBlank
jp redrawComplete
ExitSelectInstruction:
call FunctionToWaitForNextVBlank
jp redrawComplete
SelectedPushPop:
resetArrow
push bc
ld de, SelectionPushPop
ld hl, $9800
call ShowSelectionScreen
cp a, 0
jp z,SelectInstructionType
ld h, $C5
cp a, 1
jp z, AddPushPopCommon
ld h, $D5
cp a, 2
jp z, AddPushPopCommon
ld h, $E5
cp a, 3
jp z, AddPushPopCommon
ld h, $F5
cp a, 4
jp z, AddPushPopCommon
; pop instructions
ld h, $C1
cp a, 5
jp z, AddPushPopCommon
ld h, $D1
cp a, 6
jp z, AddPushPopCommon
ld h, $E1
cp a, 7
jp z, AddPushPopCommon
ld h, $F1
cp a, 8
jp z, AddPushPopCommon
AddPushPopCommon:
ld e, 1
pop bc
push bc
call AddInstructionAtAddress
pop bc
ld e,1
call IncreaseLabelAddress
call FunctionToWaitForNextVBlank
resetArrow
jp redrawComplete
SelectedIncDec:
resetArrow
push bc
ld de, SelectionIncDec
ld hl, $9800
call ShowSelectionScreen
cp a, 0
jp z,SelectInstructionType
cp a, 1
jp z, SelectedInc8
cp a, 2
jp z, SelectedInc16
cp a, 3
jp z, SelectedDec8
cp a, 4
jp z, SelectedDec16
SelectedInc8:
resetArrow
call GetSelectionForR8
cp a, 0 ; go back
jp z,SelectInstructionType
dec a
moveBit0To2ThreeBitsLeft
or a, $04
ld h,a
ld e,1
pop bc
push bc
call AddInstructionAtAddress
pop bc
ld e,1
call IncreaseLabelAddress
call FunctionToWaitForNextVBlank
resetArrow
jp redrawComplete
SelectedInc16:
resetArrow
ld de, SelectionR16
ld hl, $9800
call ShowSelectionScreen
cp a, 0 ; go back
jp z,SelectInstructionType
dec a
moveBit0To1FourBitsLeft
or a, $03
ld h,a
ld e,1
pop bc
push bc
call AddInstructionAtAddress
pop bc
ld e,1
call IncreaseLabelAddress
call FunctionToWaitForNextVBlank
resetArrow
jp redrawComplete
SelectedDec8:
resetArrow
call GetSelectionForR8
cp a, 0 ; go back
jp z,SelectInstructionType
dec a
moveBit0To2ThreeBitsLeft
or a, $05
ld h,a
ld e,1
pop bc
push bc
call AddInstructionAtAddress
pop bc
ld e,1
call IncreaseLabelAddress
call FunctionToWaitForNextVBlank
resetArrow
jp redrawComplete
SelectedDec16:
resetArrow
ld de, SelectionR16
ld hl, $9800
call ShowSelectionScreen
cp a, 0 ; go back
jp z,SelectInstructionType
dec a
moveBit0To1FourBitsLeft
or a, $0B
ld h,a
ld e,1
pop bc
push bc
call AddInstructionAtAddress
pop bc
ld e,1
call IncreaseLabelAddress
call FunctionToWaitForNextVBlank
resetArrow
jp redrawComplete
SelectedJumpCall:
resetArrow
push bc
ld de, SelectionAddJumpInstruction
ld hl, $9800
call ShowSelectionScreen
cp a, 0
jp z,SelectInstructionType
cp a, 1
jp z, SelectedToAddConditionalJump
cp a, 2
jp z, SelectedToAddUnconditionalJump
cp a, 3
jp z, SelectedToAddUnconditionalCall
cp a, 4
jp z, SelectedToAddUnconditionalCallAddress
cp a, 5
jp z, SelectedToAddRet
pop bc
call FunctionToWaitForNextVBlank
resetArrow
jp redrawComplete
BackToSelectedJumpCallPopBC:
pop bc
jp SelectedJumpCall
SelectedToAddConditionalJump:
resetArrow
ld de, SelectionCondition
ld hl, $9800
call ShowSelectionScreen
cp a, 0
jp z,BackToSelectedJumpCallPopBC
dec a
moveBit0To2ThreeBitsLeft
push af
InvalidLabelNumerConditionalJump:
getLabelAddress
cp a, $32
jp nc, InvalidLabelNumerConditionalJump
ld l,a ; second byte of instruction is label address
pop af
or a, $C2 ; conditional jump instruction
ld h, a
ld d, HIGHER_BYTE_USED_FOR_LABELS; third byte of instruction
ld e, 3
pop bc
push bc
call AddInstructionAtAddress
pop bc
ld e,3
call IncreaseLabelAddress
call FunctionToWaitForNextVBlank
resetArrow
jp redrawComplete
SelectedToAddUnconditionalJump:
resetArrow
InvalidLabelUnconditionalJump:
getLabelAddress
cp a, $32
jp nc, InvalidLabelUnconditionalJump
ld l,a ; second byte of instruction is label address
ld h, $C3 ; first byte of instruction
ld d, HIGHER_BYTE_USED_FOR_LABELS; third byte of instruction
ld e, 3
pop bc
push bc
call AddInstructionAtAddress
pop bc
ld e,3
call IncreaseLabelAddress
call FunctionToWaitForNextVBlank
resetArrow
jp redrawComplete
SelectedToAddUnconditionalCall:
resetArrow
InvalidLabelUnconditionalCall:
getLabelAddress
cp a, $32
jp nc, InvalidLabelUnconditionalCall
ld l,a ; second byte of instruction is label address
ld h, $CD ; first byte of instruction
ld d, HIGHER_BYTE_USED_FOR_LABELS; third byte of instruction
ld e, 3
pop bc
push bc
call AddInstructionAtAddress
pop bc
ld e,3
call IncreaseLabelAddress
call FunctionToWaitForNextVBlank
resetArrow
jp redrawComplete