@@ -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