Well i am gona use a structure which is gona have a map(1 key) and a list with up to 10 elements.
But now i don't know what would be the quickest way to input up to 10 elements into the list... trough procedure it would require a lot of arguments... that isn't viable if you ask me.
Maybe "Data" ? Though i got no idea how to use it...
Quickest way to input up to 10 strings into a structure ?
Re: Quickest way to input up to 10 strings into a structure
Hi spikey:
Nice example.
I read the manual a lot; must have missed this one.
Nice example.
I read the manual a lot; must have missed this one.
DE AA EB
Re: Quickest way to input up to 10 strings into a structure
Hello Primoz128. Please take a look at these examples. The first one populates a LinkedList with elements read from a data block directly, while the second encapsulates the process in a reusable procedure:Primoz128 wrote:...what would be the quickest way to input up to 10 elements into the list... trough procedure it would require a lot of arguments... Maybe "Data" ?
Code: Select all
NewList scientists.s()
Restore scientists
For readData = 1 To 8
Read.s name$
AddElement(scientists())
scientists() = name$
Next readData
ResetList(scientists())
While NextElement(scientists())
Debug scientists()
Wend
DataSection
scientists:
Data.s "Albert Einstein", "Isaac Newton", "Charles Darwin", "Guglielmo Marconi"
Data.s "Galileo Galilei", "Leonardo da Vinci", "René Descartes", "Thomas Edison"
EndDataSection
Code: Select all
Procedure asmRestore(address)
!MOV EAX, [ESP+PS0]
!MOV [PB_DataPointer],EAX
EndProcedure
Procedure fillList(List emptyList.s(), dataLabel.i, elements.i)
asmRestore(dataLabel)
For readData = 1 To elements
Read.s name$
AddElement(emptyList())
emptyList() = name$
Next readData
EndProcedure
NewList scientists.s()
fillList(scientists(), ?scientists, 8)
ResetList(scientists())
While NextElement(scientists())
Debug scientists()
Wend
DataSection
scientists:
Data.s "Albert Einstein", "Isaac Newton", "Charles Darwin", "Guglielmo Marconi"
Data.s "Galileo Galilei", "Leonardo da Vinci", "René Descartes", "Thomas Edison"
EndDataSection
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 

Re: Quickest way to input up to 10 strings into a structure
TI-99, that asmRestore is wrong for a general use because uses PS0.
That's a constant defined in the ASM code generated by PB, it's "PS" + a number and differs for every procedures. So PS0 is valid only if asmRestore it's the first procedure defined.
Moreover its value is dependent by the number and type of parameters of the procedure, so if it works when it's not the first procedure it's just by chance (the PS0 constant of another procedure has by chance the right value to access the right param in the asmRestore proc).
You can use this one instead:
That's a constant defined in the ASM code generated by PB, it's "PS" + a number and differs for every procedures. So PS0 is valid only if asmRestore it's the first procedure defined.
Moreover its value is dependent by the number and type of parameters of the procedure, so if it works when it's not the first procedure it's just by chance (the PS0 constant of another procedure has by chance the right value to access the right param in the asmRestore proc).
You can use this one instead:
Code: Select all
Procedure RestoreEx (*address)
; [DESC]
; Restore the data pointer using a variable instead of a label.
;
; [INPUT]
; *address : A pointer inside the data section.
;
; [RETURN]
; NONE
;
; [NOTES]
; Example:
;
; DataSection
; Data.i 10, 20, 30
; label_test:
; Data.i 40, 50, 60
; Data.i 70, 80, 90
; EndDataSection
;
; *ptr = ?label_test
; RestoreEx (*ptr)
; Read.i a
; Debug a ; 40
CompilerIf (#PB_Compiler_Processor = #PB_Processor_x86)
!mov eax, [p.p_address]
!mov [PB_DataPointer], eax
CompilerElse
!mov rax, [p.p_address]
!mov [PB_DataPointer], rax
CompilerEndIf
EndProcedure
"Have you tried turning it off and on again ?"
Re: Quickest way to input up to 10 strings into a structure
Or even...
No restore and no assembler.
No restore and no assembler.
Code: Select all
EnableExplicit
Procedure fillList(List emptyList.s(), dataLabel.i)
Protected *StrAdr.String
Repeat
*StrAdr = datalabel ; get string pointer address
If Len(*StrAdr\s) ; end of list marked by empty string
AddElement(EmptyList())
EmptyList() = *StrAdr\s
datalabel + SizeOf(Integer)
EndIf
Until Len(*StrAdr\s) = 0
EndProcedure
NewList scientists.s()
fillList(scientists(), ?scientists)
ResetList(scientists())
While NextElement(scientists())
Debug scientists()
Wend
; Data is declared as string pointers rather than strings
DataSection
scientists:
Data.i @"Albert Einstein", @"Isaac Newton", @"Charles Darwin", @"Guglielmo Marconi"
Data.i @"Galileo Galilei", @"Leonardo da Vinci", @"René Descartes", @"Thomas Edison"
Data.i @"" ; list terminator (so I don't have to count how many)
EndDataSection
Re: Quickest way to input up to 10 strings into a structure
Thanks to you all. Gona try and implement it soon enough.