Skip to content

Commit c367c94

Browse files
authored
Merge pull request #965 from boriel-basic/refact/move_array_bound_to_array_folder_runtime
refact: move bound.asm into /array/ runtime folder
2 parents fdafd55 + 9e7ce1d commit c367c94

File tree

9 files changed

+1918
-158
lines changed

9 files changed

+1918
-158
lines changed

src/arch/z80/backend/runtime/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class CoreLabels:
182182
CoreLabels.FP_PUSH_REV: "pushf.asm",
183183
CoreLabels.FTOF16REG: "ftof16reg.asm",
184184
CoreLabels.FTOU32REG: "ftou32reg.asm",
185-
CoreLabels.LBOUND: "bound.asm",
185+
CoreLabels.LBOUND: "array/arraybound.asm",
186186
CoreLabels.LEF: "cmp/lef.asm",
187187
CoreLabels.LEI16: "cmp/lei16.asm",
188188
CoreLabels.LEI32: "cmp/lei32.asm",
@@ -254,7 +254,7 @@ class CoreLabels:
254254
CoreLabels.SWAP32: "swap32.asm",
255255
CoreLabels.U32TOFREG: "u32tofreg.asm",
256256
CoreLabels.U8TOFREG: "u32tofreg.asm",
257-
CoreLabels.UBOUND: "bound.asm",
257+
CoreLabels.UBOUND: "array/arraybound.asm",
258258
CoreLabels.XOR16: "bool/xor16.asm",
259259
CoreLabels.XOR8: "bool/xor8.asm",
260260
CoreLabels.XOR32: "bool/xor32.asm",

tests/functional/arch/zx48k/lbound12.asm

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,84 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY:
538538
#line 142 "/zxbasic/src/lib/arch/zx48k/runtime/array/arrayalloc.asm"
539539
pop namespace
540540
#line 98 "arch/zx48k/lbound12.bas"
541+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array/arraybound.asm"
542+
; ---------------------------------------------------------
543+
; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel)
544+
; http://www.boriel.com
545+
;
546+
; ZX BASIC Compiler http://www.zxbasic.net
547+
; This code is released under the BSD License
548+
; ---------------------------------------------------------
549+
; Implements both LBOUND(array, N) and UBOUND(array, N) function
550+
; Parameters:
551+
; HL = PTR to array
552+
; [stack - 2] -> N (dimension)
553+
push namespace core
554+
PROC
555+
LOCAL __BOUND
556+
LOCAL __DIM_NOT_EXIST
557+
LOCAL __CONT
558+
__LBOUND:
559+
ld a, 4
560+
jr __BOUND
561+
__UBOUND:
562+
ld a, 6
563+
__BOUND:
564+
ex de, hl ; DE <-- Array ptr
565+
pop hl ; HL <-- Ret address
566+
ex (sp), hl ; CALLEE: HL <-- N, (SP) <-- Ret address
567+
ex de, hl ; DE <-- N, HL <-- ARRAY_PTR
568+
push hl
569+
ld c, (hl)
570+
inc hl
571+
ld h, (hl)
572+
ld l, c ; HL = start of dimension table (first position contains number of dimensions - 1)
573+
ld c, (hl)
574+
inc hl
575+
ld b, (hl)
576+
inc bc ; Number of total dimensions of the array
577+
pop hl ; Recovers ARRAY PTR
578+
ex af, af' ; Saves A for later
579+
ld a, d
580+
or e
581+
jr nz, __CONT ; N = 0 => Return number of dimensions
582+
;; Return the number of dimensions of the array
583+
ld h, b
584+
ld l, c
585+
ret
586+
__CONT:
587+
dec de
588+
ex af, af' ; Recovers A (contains PTR offset)
589+
ex de, hl ; HL = N (dimension asked) - 1, DE = Array PTR
590+
or a
591+
sbc hl, bc ; if no Carry => the user asked for a dimension that does not exist. Return 0
592+
jr nc, __DIM_NOT_EXIST
593+
add hl, bc ; restores HL = (N - 1)
594+
add hl, hl ; hl *= 2
595+
ex de, hl ; hl = ARRAY_PTR + 3, DE jsz = (N - 1) * 2
596+
ld b, 0
597+
ld c, a
598+
add hl, bc ; HL = &BOUND_PTR
599+
ld a, (hl)
600+
inc hl
601+
ld h, (hl)
602+
ld l, a ; LD HL, (HL) => Origin of L/U Bound table
603+
; for LBound only, HL = 0x0000 (NULL) if the array is all 0-based
604+
or h
605+
ret z ; Should never happen for UBound
606+
add hl, de ; hl += OFFSET __LBOUND._xxxx
607+
ld e, (hl) ; de = (hl)
608+
inc hl
609+
ld d, (hl)
610+
ex de, hl ; hl = de => returns result in HL
611+
ret
612+
__DIM_NOT_EXIST:
613+
; The dimension requested by the user does not exists. Return 0
614+
ld hl, 0
615+
ret
616+
ENDP
617+
pop namespace
618+
#line 99 "arch/zx48k/lbound12.bas"
541619
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array/arraystrfree.asm"
542620
; This routine is in charge of freeing an array of strings from memory
543621
; HL = Pointer to start of array in memory
@@ -742,84 +820,6 @@ __ARRAYSTR_FREE_MEM: ; like the above, buf also frees the array itself
742820
pop hl ; recovers array block pointer
743821
jp __MEM_FREE ; Frees it and returns from __MEM_FREE
744822
pop namespace
745-
#line 99 "arch/zx48k/lbound12.bas"
746-
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bound.asm"
747-
; ---------------------------------------------------------
748-
; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel)
749-
; http://www.boriel.com
750-
;
751-
; ZX BASIC Compiler http://www.zxbasic.net
752-
; This code is released under the BSD License
753-
; ---------------------------------------------------------
754-
; Implements both LBOUND(array, N) and UBOUND(array, N) function
755-
; Parameters:
756-
; HL = PTR to array
757-
; [stack - 2] -> N (dimension)
758-
push namespace core
759-
PROC
760-
LOCAL __BOUND
761-
LOCAL __DIM_NOT_EXIST
762-
LOCAL __CONT
763-
__LBOUND:
764-
ld a, 4
765-
jr __BOUND
766-
__UBOUND:
767-
ld a, 6
768-
__BOUND:
769-
ex de, hl ; DE <-- Array ptr
770-
pop hl ; HL <-- Ret address
771-
ex (sp), hl ; CALLEE: HL <-- N, (SP) <-- Ret address
772-
ex de, hl ; DE <-- N, HL <-- ARRAY_PTR
773-
push hl
774-
ld c, (hl)
775-
inc hl
776-
ld h, (hl)
777-
ld l, c ; HL = start of dimension table (first position contains number of dimensions - 1)
778-
ld c, (hl)
779-
inc hl
780-
ld b, (hl)
781-
inc bc ; Number of total dimensions of the array
782-
pop hl ; Recovers ARRAY PTR
783-
ex af, af' ; Saves A for later
784-
ld a, d
785-
or e
786-
jr nz, __CONT ; N = 0 => Return number of dimensions
787-
;; Return the number of dimensions of the array
788-
ld h, b
789-
ld l, c
790-
ret
791-
__CONT:
792-
dec de
793-
ex af, af' ; Recovers A (contains PTR offset)
794-
ex de, hl ; HL = N (dimension asked) - 1, DE = Array PTR
795-
or a
796-
sbc hl, bc ; if no Carry => the user asked for a dimension that does not exist. Return 0
797-
jr nc, __DIM_NOT_EXIST
798-
add hl, bc ; restores HL = (N - 1)
799-
add hl, hl ; hl *= 2
800-
ex de, hl ; hl = ARRAY_PTR + 3, DE jsz = (N - 1) * 2
801-
ld b, 0
802-
ld c, a
803-
add hl, bc ; HL = &BOUND_PTR
804-
ld a, (hl)
805-
inc hl
806-
ld h, (hl)
807-
ld l, a ; LD HL, (HL) => Origin of L/U Bound table
808-
; for LBound only, HL = 0x0000 (NULL) if the array is all 0-based
809-
or h
810-
ret z ; Should never happen for UBound
811-
add hl, de ; hl += OFFSET __LBOUND._xxxx
812-
ld e, (hl) ; de = (hl)
813-
inc hl
814-
ld d, (hl)
815-
ex de, hl ; hl = de => returns result in HL
816-
ret
817-
__DIM_NOT_EXIST:
818-
; The dimension requested by the user does not exists. Return 0
819-
ld hl, 0
820-
ret
821-
ENDP
822-
pop namespace
823823
#line 100 "arch/zx48k/lbound12.bas"
824824
.LABEL.__LABEL5:
825825
DEFB 01h

tests/functional/arch/zx48k/ubound12.asm

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,84 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY_WITH_BOUNDS:
610610
#line 142 "/zxbasic/src/lib/arch/zx48k/runtime/array/arrayalloc.asm"
611611
pop namespace
612612
#line 110 "arch/zx48k/ubound12.bas"
613+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array/arraybound.asm"
614+
; ---------------------------------------------------------
615+
; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel)
616+
; http://www.boriel.com
617+
;
618+
; ZX BASIC Compiler http://www.zxbasic.net
619+
; This code is released under the BSD License
620+
; ---------------------------------------------------------
621+
; Implements both LBOUND(array, N) and UBOUND(array, N) function
622+
; Parameters:
623+
; HL = PTR to array
624+
; [stack - 2] -> N (dimension)
625+
push namespace core
626+
PROC
627+
LOCAL __BOUND
628+
LOCAL __DIM_NOT_EXIST
629+
LOCAL __CONT
630+
__LBOUND:
631+
ld a, 4
632+
jr __BOUND
633+
__UBOUND:
634+
ld a, 6
635+
__BOUND:
636+
ex de, hl ; DE <-- Array ptr
637+
pop hl ; HL <-- Ret address
638+
ex (sp), hl ; CALLEE: HL <-- N, (SP) <-- Ret address
639+
ex de, hl ; DE <-- N, HL <-- ARRAY_PTR
640+
push hl
641+
ld c, (hl)
642+
inc hl
643+
ld h, (hl)
644+
ld l, c ; HL = start of dimension table (first position contains number of dimensions - 1)
645+
ld c, (hl)
646+
inc hl
647+
ld b, (hl)
648+
inc bc ; Number of total dimensions of the array
649+
pop hl ; Recovers ARRAY PTR
650+
ex af, af' ; Saves A for later
651+
ld a, d
652+
or e
653+
jr nz, __CONT ; N = 0 => Return number of dimensions
654+
;; Return the number of dimensions of the array
655+
ld h, b
656+
ld l, c
657+
ret
658+
__CONT:
659+
dec de
660+
ex af, af' ; Recovers A (contains PTR offset)
661+
ex de, hl ; HL = N (dimension asked) - 1, DE = Array PTR
662+
or a
663+
sbc hl, bc ; if no Carry => the user asked for a dimension that does not exist. Return 0
664+
jr nc, __DIM_NOT_EXIST
665+
add hl, bc ; restores HL = (N - 1)
666+
add hl, hl ; hl *= 2
667+
ex de, hl ; hl = ARRAY_PTR + 3, DE jsz = (N - 1) * 2
668+
ld b, 0
669+
ld c, a
670+
add hl, bc ; HL = &BOUND_PTR
671+
ld a, (hl)
672+
inc hl
673+
ld h, (hl)
674+
ld l, a ; LD HL, (HL) => Origin of L/U Bound table
675+
; for LBound only, HL = 0x0000 (NULL) if the array is all 0-based
676+
or h
677+
ret z ; Should never happen for UBound
678+
add hl, de ; hl += OFFSET __LBOUND._xxxx
679+
ld e, (hl) ; de = (hl)
680+
inc hl
681+
ld d, (hl)
682+
ex de, hl ; hl = de => returns result in HL
683+
ret
684+
__DIM_NOT_EXIST:
685+
; The dimension requested by the user does not exists. Return 0
686+
ld hl, 0
687+
ret
688+
ENDP
689+
pop namespace
690+
#line 111 "arch/zx48k/ubound12.bas"
613691
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array/arraystrfree.asm"
614692
; This routine is in charge of freeing an array of strings from memory
615693
; HL = Pointer to start of array in memory
@@ -814,84 +892,6 @@ __ARRAYSTR_FREE_MEM: ; like the above, buf also frees the array itself
814892
pop hl ; recovers array block pointer
815893
jp __MEM_FREE ; Frees it and returns from __MEM_FREE
816894
pop namespace
817-
#line 111 "arch/zx48k/ubound12.bas"
818-
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bound.asm"
819-
; ---------------------------------------------------------
820-
; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel)
821-
; http://www.boriel.com
822-
;
823-
; ZX BASIC Compiler http://www.zxbasic.net
824-
; This code is released under the BSD License
825-
; ---------------------------------------------------------
826-
; Implements both LBOUND(array, N) and UBOUND(array, N) function
827-
; Parameters:
828-
; HL = PTR to array
829-
; [stack - 2] -> N (dimension)
830-
push namespace core
831-
PROC
832-
LOCAL __BOUND
833-
LOCAL __DIM_NOT_EXIST
834-
LOCAL __CONT
835-
__LBOUND:
836-
ld a, 4
837-
jr __BOUND
838-
__UBOUND:
839-
ld a, 6
840-
__BOUND:
841-
ex de, hl ; DE <-- Array ptr
842-
pop hl ; HL <-- Ret address
843-
ex (sp), hl ; CALLEE: HL <-- N, (SP) <-- Ret address
844-
ex de, hl ; DE <-- N, HL <-- ARRAY_PTR
845-
push hl
846-
ld c, (hl)
847-
inc hl
848-
ld h, (hl)
849-
ld l, c ; HL = start of dimension table (first position contains number of dimensions - 1)
850-
ld c, (hl)
851-
inc hl
852-
ld b, (hl)
853-
inc bc ; Number of total dimensions of the array
854-
pop hl ; Recovers ARRAY PTR
855-
ex af, af' ; Saves A for later
856-
ld a, d
857-
or e
858-
jr nz, __CONT ; N = 0 => Return number of dimensions
859-
;; Return the number of dimensions of the array
860-
ld h, b
861-
ld l, c
862-
ret
863-
__CONT:
864-
dec de
865-
ex af, af' ; Recovers A (contains PTR offset)
866-
ex de, hl ; HL = N (dimension asked) - 1, DE = Array PTR
867-
or a
868-
sbc hl, bc ; if no Carry => the user asked for a dimension that does not exist. Return 0
869-
jr nc, __DIM_NOT_EXIST
870-
add hl, bc ; restores HL = (N - 1)
871-
add hl, hl ; hl *= 2
872-
ex de, hl ; hl = ARRAY_PTR + 3, DE jsz = (N - 1) * 2
873-
ld b, 0
874-
ld c, a
875-
add hl, bc ; HL = &BOUND_PTR
876-
ld a, (hl)
877-
inc hl
878-
ld h, (hl)
879-
ld l, a ; LD HL, (HL) => Origin of L/U Bound table
880-
; for LBound only, HL = 0x0000 (NULL) if the array is all 0-based
881-
or h
882-
ret z ; Should never happen for UBound
883-
add hl, de ; hl += OFFSET __LBOUND._xxxx
884-
ld e, (hl) ; de = (hl)
885-
inc hl
886-
ld d, (hl)
887-
ex de, hl ; hl = de => returns result in HL
888-
ret
889-
__DIM_NOT_EXIST:
890-
; The dimension requested by the user does not exists. Return 0
891-
ld hl, 0
892-
ret
893-
ENDP
894-
pop namespace
895895
#line 112 "arch/zx48k/ubound12.bas"
896896
.LABEL.__LABEL5:
897897
DEFB 01h

0 commit comments

Comments
 (0)