@@ -447,6 +447,34 @@ set_type:
447
447
xit: rts
448
448
.endproc
449
449
450
+ ; Label definition search/create
451
+ .proc E_LABEL_DEF
452
+ jsr label_create
453
+
454
+ ; Fills all undefined labels with current position - saved for the label
455
+ bcs nfound
456
+
457
+ ; Check label number
458
+ cloop: bmi error ; label already defined
459
+
460
+ ; Write current codep to AX
461
+ jsr patch_codep
462
+ ldy #0
463
+ lda #1
464
+ sta (tmp1), y
465
+
466
+ ; Continue
467
+ next: jsr next_laddr
468
+ bcc cloop
469
+ nfound:
470
+ lda #128
471
+ jsr add_laddr_list
472
+ bcs error
473
+ bcc advance_varn
474
+ error: sec
475
+ rts
476
+ .endproc
477
+
450
478
; Loop iteration for label-address,
451
479
; increment pointer, compares with end
452
480
; and reads values
@@ -551,34 +579,6 @@ nfound: lda #0
551
579
ret: rts
552
580
.endproc
553
581
554
- ; Label definition search/create
555
- .proc E_LABEL_DEF
556
- jsr label_create
557
-
558
- ; Fills all undefined labels with current position - saved for the label
559
- bcs nfound
560
-
561
- ; Check label number
562
- cloop: bmi error ; label already defined
563
-
564
- ; Write current codep to AX
565
- jsr patch_codep
566
- ldy #0
567
- lda #1
568
- sta (tmp1), y
569
-
570
- ; Continue
571
- next: jsr next_laddr
572
- bcc cloop
573
- nfound:
574
- lda #128
575
- jsr add_laddr_list
576
- bcs error
577
- jmp advance_varn
578
- error: sec
579
- xit: rts
580
- .endproc
581
-
582
582
; Check if all labels are defined
583
583
; Returns C=1 if ok.
584
584
.proc check_labels
@@ -591,10 +591,10 @@ start:
591
591
cpy laddr_ptr
592
592
lda tmp1+1
593
593
sbc laddr_ptr+1
594
- bcs E_LABEL_DEF ::xit
594
+ bcs E_LABEL ::ret
595
595
596
596
lda (tmp1), y
597
- beq E_LABEL_DEF ::xit
597
+ beq E_LABEL ::ret
598
598
599
599
; Note: C = 0 from above!
600
600
tya
@@ -606,25 +606,6 @@ start:
606
606
.endproc
607
607
608
608
; Actions for LOOPS
609
- .proc pop_patch_codep
610
- jsr pop_codep
611
- .endproc ; Fall through
612
- .proc patch_codep
613
- ; Patches saved position with current position
614
- sta tmp2
615
- stx tmp2+1
616
- jsr get_codep
617
- ldy #0
618
- clc
619
- adc reloc_addr
620
- sta (tmp2),y
621
- iny
622
- txa
623
- adc reloc_addr+1
624
- sta (tmp2),y
625
- clc
626
- rts ; C is cleared on exit!
627
- .endproc
628
609
629
610
.proc E_PUSH_LT
630
611
; Push current position, don't emit
@@ -722,7 +703,8 @@ rtsclc: clc
722
703
.proc E_POP_PROC_1
723
704
; Pop saved "jump to end" position
724
705
lda #LT_PROC_1
725
- jmp pop_patch_codep
706
+ .assert LT_PROC_1 = 0 , error, "LT_PROC_1 must be 0"
707
+ beq pop_patch_codep
726
708
.endproc
727
709
728
710
.proc E_EXIT_LOOP
@@ -827,14 +809,32 @@ comp_y: cpx #$FC
827
809
bmi no_elif
828
810
lda #LT_ELIF
829
811
cmp loop_stk, y
830
- bne no_elif
831
- ; ELIF, remove from stack and patch
832
- jmp pop_patch_codep
812
+ beq pop_patch_codep ; ELIF, remove from stack and patch
833
813
no_elif:
834
814
clc
835
815
rts
836
816
.endproc
837
817
818
+ .proc pop_patch_codep
819
+ jsr pop_codep
820
+ .endproc ; Fall through
821
+ .proc patch_codep
822
+ ; Patches saved position with current position
823
+ sta tmp2
824
+ stx tmp2+1
825
+ jsr get_codep
826
+ ldy #0
827
+ clc
828
+ adc reloc_addr
829
+ sta (tmp2),y
830
+ iny
831
+ txa
832
+ adc reloc_addr+1
833
+ sta (tmp2),y
834
+ clc
835
+ rts ; C is cleared on exit!
836
+ .endproc
837
+
838
838
.proc E_ELIF
839
839
ldy #LT_ELIF
840
840
.byte $2C ; Skip 2 bytes over next "LDA"
@@ -857,7 +857,7 @@ type: lda #LT_ELSE
857
857
; Parch current position + 2 (over jump)
858
858
lda tmp1
859
859
ldx tmp1+1
860
- jmp patch_codep
860
+ bne patch_codep
861
861
.endproc
862
862
863
863
; vi:syntax=asm_ca65
0 commit comments