Author Topic: Returning pairs of values in SCI  (Read 586 times)

0 Members and 2 Guests are viewing this topic.

Offline lskovlun

Returning pairs of values in SCI
« on: September 16, 2023, 06:52:16 PM »
I have finally gotten around to writing this. Pairs arise in SCI in several contexts, both as x,y coordinates and as far text references, but in the stock SCI language there is no such thing as a pair. However, the PMachine can be coerced into returning pairs of values from functions. Since it is a hack, you need to stow the values away immediately (and in the right order), but it can be done. This bit of code was written for the original compiler, since the Companion compiler tends to get stuck in an animation loop trying to resize the messages window; I then hex-edited it to put my hack in place (in Companion you would simply use an asm directive) - the following shows the result of a later decompilation. I therefore haven't tested it with Companion, but I know that my original works:
Code: [Select]
;;; Sierra Script 1.0 - (do not remove this comment)
(script# 935)
(include sci.sh)

(public
RetPair 0
PairFst 1
PairSnd 2
)

(procedure (RetPair param1 param2)
(== param2 param2)
(return param1)
)

(procedure (PairFst)
)

(procedure (PairSnd &tmp temp0)
(asm
pprev   
sst      temp0
lat      temp0
ret     
)
)
You can then do things like:
Code: [Select]
(procedure (WhosAPair)
        (RetPair {Larry} {Patti}))

(procedure (FarTextPair)
        (RetPair "This is a far text string"))
and retrieve the results with
Code: [Select]
                       (WhosAPair)
                        (= el1 (PairFst))
                        (= el2 (PairSnd))
                        (Printf "Pair (%s, %s)" el1 el2)
                        (FarTextPair)
                        (= el1 (PairFst))
                        (= el2 (PairSnd))
                        (Printf el1 el2)
I'd like to make the retrieval a bit neater, but that'll have to wait.

EDIT:  :'( this does not work in SSCI. Figures. But I consider that a bug in SSCI.
« Last Edit: September 16, 2023, 08:14:35 PM by lskovlun »



Offline Collector

Re: Returning pairs of values in SCI
« Reply #1 on: September 16, 2023, 09:42:32 PM »
When I get some time I'll add this to the Wiki.

By SSCI do you mean Studio Script?
KQII Remake Pic

Offline lskovlun

Re: Returning pairs of values in SCI
« Reply #2 on: September 16, 2023, 10:35:33 PM »
When I get some time I'll add this to the Wiki.

By SSCI do you mean Studio Script?
Sierra SCI, unfortunately. I've implemented a bug fix on top of Kawa's interpreter, and LSL6 starts up fine with it.
So maybe the pair code can still work, at least in SCI1.1 where we have interpreter source.


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.017 seconds with 22 queries.