Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
amiga:development_environments:basic:amos_professional:extension_development [2024/02/23 07:26] Topazamiga:development_environments:basic:amos_professional:extension_development [2024/03/18 21:15] (current) Topaz
Line 66: Line 66:
 When you want to demand string space, you apply for it with `L_Demande`. When you want to demand string space, you apply for it with `L_Demande`.
  
-The requested length goes into D3. It does not have to be even. You get the base address in both A0 and A1.+The requested length goes into D3. It has to be even. You get the base address in both A0 and A1.
  
 This is an AMOS string, so the first two bytes are the size of the string as a word. Then the string comes after. This is an AMOS string, so the first two bytes are the size of the string as a word. Then the string comes after.
  
-Then, you have to eventually hand `HiChaine(A5)` (be sure to preserve A5) the ending address of the string, rounded up to the nearest 2. I'm guessing you're now setting the end of the string area in memory manually.+Then, you have to eventually hand `HiChaine(A5)` (be sure to preserve A5) the ending address of the string.
  
 Make sure you don't try to allocate a zero width string with this! It will fail hard. Make sure you don't try to allocate a zero width string with this! It will fail hard.
Line 103: Line 103:
  moveq #2,d2  moveq #2,d2
  rts  rts
 +```
 +
 +Here's a better version:
 +
 +```asm
 +    ; D4 contains your string length
 +    MOVE.L D4,D3
 +    AND.W #$FFFE,D3
 +    ADDQ #2,D3 ; round up to the nearest 2
 +
 +    Rjsr L_Demande ; string is in A0/A1
 +    LEA 2(A0,D3.W),A1
 +    MOVE.L A1,HiChaine(A5)
 +    MOVE.L A0,A1 ; put A1 back
 +    MOVE.W D4,(A0)+ ; put length of string at start of memory
 +.stringstuff
 +    MOVE.B (A2)+,(A0)+
 +    BNE .stringstuff ; copy until null terminator
 +```
 +
 +You know your string code is working if you can do this:
 +
 +```basic
 +A$=My String Function$ ' returns "wow"
 +Print "cat" + A$ + "dog" ' "catwowdog"
 ``` ```