Author Topic: World's smallest viable "Hello World" in SCI?  (Read 1373 times)

0 Members and 1 Guest are viewing this topic.

Offline Kawa

World's smallest viable "Hello World" in SCI?
« on: October 26, 2023, 02:09:03 PM »
Removed every single script resource and .sc file from a fresh project and made a blank script 0. Here's what I put in:
Code: [Select]
(script# 0)
(public
WeirdThing 0
)

(instance WeirdThing
(method (play)
(Display {Hello, world!} 100 10 0 102 15)
(Animate)
(Wait 100)
)
)

Aaaand yeah, it compiles. 108 bytes, and when you run it it prints "Hello, world!" at effectively 10x10 (because lol invisible status line), waits a bit so you can tell it's there, and self-terminates.

Here's what SV made of those 108 bytes:
Code: [Select]
export000_0 = WeirdThing

WeirdThing::play:
pushi $6 ; loop
lofss string_0048 ; "Hello, world!"
pushi $64 ; 100, 'd', allTrue
pushi $a ; 10, nsLeft
push0
pushi $66 ; 102, 'f', isEmpty
pushi $f ; 15, lsBottom
callk Display, $c
push0
callk Animate, $0
push1
pushi $64 ; 100, 'd', allTrue
callk Wait, $2
ret

; export000_0
instance WeirdThing of Object
{
play()
}

string_0048 = "Hello, world!"
string_0056 = "WeirdThing"


But what if... what if I were to buy fast food and disguise it as my own cooking try compiling it in SC instead? Let's see. First, I'll adjust the definition a little bit:
Code: [Select]
(instance WeirdThing of RootObj
(properties name "WeirdThing") ;if left out, the instance is nameless and that's cheating a bit
(methods play)
And then because SC insists on having a system.sh despite my script not using it, I'll whip up a minimal one:
Code: [Select]
(global
)
(extern
Animate $ffff 11
Display $ffff 27
Wait $ffff 69
)

End result is almost the same basic bytecode:
Code: [Select]
export000_0 = WeirdThing

WeirdThing::play:
pushi $6 ; loop
lofsa string_0055 ; "Hello, world!"
push ;<-- this was a lofss in Companion.
pushi $64 ; 100, 'd', allTrue
pushi $a ; 10, nsLeft
push0
pushi $66 ; 102, 'f', isEmpty
pushi $f ; 15, lsBottom
callk Display, $c
push0
callk Animate, $0
push1
pushi $64 ; 100, 'd', allTrue
callk Wait, $2
ret

; export000_0
instance WeirdThing of Object
{
play()
}

;interesting how this is in the opposite order...
string_004a = "WeirdThing"
string_0055 = "Hello, world!"

I learned nothing today.



Offline lskovlun

Re: World's smallest viable "Hello World" in SCI?
« Reply #1 on: October 26, 2023, 07:52:48 PM »
In SCI1.1, you can simply say (SetQuitStr {Hello World!}) and be done with it.

Offline lskovlun

Re: World's smallest viable "Hello World" in SCI?
« Reply #2 on: October 26, 2023, 10:50:36 PM »
Also, didn't you add ENDOOM support to your terp? That would reduce the smallest Hello World program to just a return instruction.

Offline Kawa

Re: World's smallest viable "Hello World" in SCI?
« Reply #3 on: October 27, 2023, 03:31:24 AM »
One, this setup for whatever reason doesn't seem to work in 1.1. It complains of an unknown property #86 or something along that numerical range.

Two, if you use SetQuitStr you can't exactly do anything else. After all, you're done with it.

Three, as a proof of concept you could use this with an even more custom interpreter that straight-up runs in text mode to have a general use text based console SCI, with a custom string input kernel function.

Offline lskovlun

Re: World's smallest viable "Hello World" in SCI?
« Reply #4 on: October 27, 2023, 03:45:23 AM »
A third option I can think of is that some SCI versions (I know that it was added, and I think it was subsequently removed) can optionally draw a view on screen (VIEW.999?) before starting the PMachine (the picture of the Hero during QFG2 startup is implemented that way). Then, a call to Wait will make sure the user sees it.


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

Page created in 0.026 seconds with 23 queries.