Community

SCI Programming => SCI Syntax Help => Topic started by: OmerMor on February 26, 2016, 03:40:48 PM

Title: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: OmerMor on February 26, 2016, 03:40:48 PM
I'm trying to re-compile a decompiled script (KQ6 Spanish, script# 921).

The compiler gives the following error:
Quote
[Error]: &rest cannot be used if the send target itself contains nested procedure calls or sends. Assign the result of the procedure call or send to a temporary variable and use that instead.  Line: 17, col: 42

The relevant procedure is this:
Code: [Select]
(procedure (proc921_0 &tmp newPrint)
((= newPrint (Print new:)) addText: &rest init:)
)

I've got 2 questions:
Title: Re: Compilation error help
Post by: Kawa on February 26, 2016, 04:57:59 PM
I remember that. Split it up.
Code: [Select]
(procedure (proc921_0 &tmp newPrint)
(= newPrint (Print new:))
(newPrint addText: &rest init:)
)
Title: Re: Compilation error help
Post by: OmerMor on February 26, 2016, 05:42:37 PM
Thanks!
That did the trick.

I've been able to find and enable a debug menu for King's Quest 6. But it only works with the Spanish and Italian versions.
Every other versions crashes. I'll add more information tomorrow, and maybe together we'll be able to coerce these versions to work as well.
Title: Re: Compilation error help
Post by: OmerMor on February 27, 2016, 03:28:32 PM
OK, so here's what I've been doing:

I found that KQ6 is checking for the existence of the file 911.SCR as a trigger for an internal debug menu:

n0.sc:
Code: [Select]
(Format @temp0 0 0 911)   ; temp0 <-- "911.scr"
(if (FileIO fiEXISTS @temp0)
(= global100 1)
else
(= global100 0)
)

However most KQ6 versions no longer contain script# 911. The only versions that still has it are the Spanish and Italian ones.
I tried extracting 911.scr, and scummvm crashes because Print::addEdit in script# 921 is doing uninitialized read from temporary variables:
Code: [Select]
(method (addEdit param1 param2 param3 param4 param5 &tmp temp0 temp1)
(if (not dialog) (= dialog (Dialog new:)))
(StrCpy param1 (if (> argc 4) param5 else {}))
(if (> argc 2)
(= temp0 param3)
(if (> argc 3) (= temp1 param4))
)
(dialog
add:
((DEdit new:)
text: param1
max: param2
setSize:
moveTo: (+ temp0 4) (+ temp1 4)
yourself:
)
setSize:
)
)

This was easily fixed by initialized temp0 and temp1 to 0.
I tried to compile n921.sc but failed on the error from the start of this thread.
Kawa's tip was extremely helpful, and I managed to get the debug menu.
Great!

I now tried to backport this to the English versions of KQ6. I copied 911.* and 921.* to the game's folder.
Scummvm crash on start with the following error (floppy version):
  ERROR: Send to invalid selector 0xcd of object at 0001:1d56!

The backtrace gives the following:
Code: [Select]
...
6: script 99 - speedRoom::init()
    by 5 obj@0030:026b pc=0030:0065 sp=ST:002a fp=ST:0029 argp:ST:0028
7: script 911 - export 1 ()
    by 6 obj@0030:026b pc=0032:0024 sp=ST:0035 fp=ST:002b argp:ST:002a

frame 6's instruction is
  0030:005f: calle 038f 0001 00.

frame 7's instruction is
  0032:0024: send 06
  Kq6::addButton[INVALID](0001:2070)


Here's sv.exe for 911:export_1 :
Code: [Select]

; export911_1
code_0012: link $7
ldi $0
sat temp[$2]
ldi $0
sat temp[$1]
pushi $cd ; 205, setCursor
push1
lsg global[$14]
lag global[$1]
send $6

The decompiled snippet is:
Code: [Select]
(procedure (proc911_1 &tmp temp0 temp1 [temp2 5])
(= temp2 0)
(= temp1 0)
(gKq6 setCursor: gArrowCursor)

So it seems like problem is that Kq6::setCursor from Spanish-KQ6 is mapped to Kq6::addButton in English-Kq6.
Title: Re: Compilation error help
Post by: OmerMor on February 27, 2016, 03:38:26 PM
OK, it's not mapped to Kq6::addButton because there's no such method. It's probably just scummvm choking on this selector (0001:00cd).
I verified that in english kq6, Kq6::setCursor is located in [0c5] while in spanish kq6, Kq6::setCursor is located in [0cd] as expected.

So I guess for the 911.scr to be usable in english KQ6, it would have to be recompiled with this version.
I hope I'll manage to do that.
Title: Re: Compilation error help
Post by: OmerMor on February 27, 2016, 03:58:57 PM
Yay - success!  8) 8) 8)
I attached the debug script + fixed 921 (Print) script.
It is compatible with the English floppy version of King's Quest 6.

For extra credit, create an empty file named "g" in the game's folder.
When the game starts - enter one of these room number: {470, 480, 740, 750}. They all check for the existence of the "g" file, and give extra options.
Title: Re: Compilation error help
Post by: Kawa on February 27, 2016, 04:05:45 PM
lol "stud". I think the Carlosbashing in LSL6 was funnier for sheer scope but "where to stud" gets a good second place.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: MusicallyInspired on February 27, 2016, 04:58:12 PM
Nice, Omer!!
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Collector on February 27, 2016, 05:00:55 PM
I need to add 'magic' files to the Wiki's debug page.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Collector on September 28, 2022, 10:35:08 PM
Just revisiting this. I was just trying it and these files are ignored by Version 1.000, Interp. 1.001.054. The same with the CD version, both by ScummVM and DOSBox. What version did you try it on. I did not try it with any localized versions.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: MusicallyInspired on September 29, 2022, 03:51:49 PM
Just revisiting this. I was just trying it and these files are ignored by Version 1.000, Interp. 1.001.054. The same with the CD version, both by ScummVM and DOSBox. What version did you try it on. I did not try it with any localized versions.

I found that KQ6 is checking for the existence of the file 911.SCR as a trigger for an internal debug menu:

...

However most KQ6 versions no longer contain script# 911. The only versions that still has it are the Spanish and Italian ones.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Collector on September 30, 2022, 09:14:03 AM
Yay - success!  8) 8) 8)
I attached the debug script + fixed 921 (Print) script.
It is compatible with the English floppy version of King's Quest 6
.

For extra credit, create an empty file named "g" in the game's folder.
When the game starts - enter one of these room number: {470, 480, 740, 750}. They all check for the existence of the "g" file, and give extra options.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: MusicallyInspired on September 30, 2022, 02:01:12 PM
Quote from: Somebody somewhere probably who's 100% correct
Brandon is an idiot.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on September 30, 2022, 09:46:47 PM
The 94 King's Quest Collector's Edition also still has the 911 debugger script, so I tried to get it working with the GOG and Steam versions. It's now partially functional, only requiring the 911.scr, 911.hep, and 911.txt files attached below.

While the "Where to, STUD?" is fine, the actual DebugHandler is still in assembly and not working. I changed the "debugHandler of Actions" to "debugHandler of Feature", which stops keypresses from crashing the game, but none of the ALT+'key' commands work at the moment. Should be easy enough to rewrite from scratch or copy/paste from another debugger.

Here is the edited script if anyone is curious. 
Code: [Select]
;;; Sierra Script 1.0 - (do not remove this comment)
(script# 911)
(include sci.sh)
(use Main)
(use Class_255_0)
(use n913)
(use Print)
(use DIcon)
(use DlgWindow)
(use Class_948_0)
(use Blk)
(use CueObj)
(use SysWindow)
(use Flags)
(use User)
(use Obj)

(public
debugHandler 0
proc911_1 1
)

(local
local0
local1
)
(procedure (proc911_1 &tmp temp0 temp1 [temp2 5])
(= temp2 0)
(= temp1 0)
;(gKq6 open: gArrowCursor)
(gKq6 setCursor: gArrowCursor)
(while
(not
(!=
(= temp1
;(Controls
(Print
font: global23
;advance: {Where to, STUD?}
addText: {Where to, STUD?}
;center: @temp2 5 80
addEdit: @temp2 5 80
;setCursor: 100 {______Opening________} 0 20  -change setCursor to addButton
addButton: 100 {______Opening________} 0 20
addButton: 200 { Isle of the Crown_} 101 20
addButton: 300 {__Isle Sacred Mtn__} 0 34
addButton: 405 {_____Labyrinth_____} 101 34
addButton: 450 {__Isle of Wonder___} 0 48
addButton: 500 {___Isle of Beast___} 101 48
addButton: 550 { Isle of the Mists_} 0 62
addButton: 600 { Realm of the Dead_} 101 62
addButton: 730 {__Castle - Beauty__} 0 76
addButton: 710 {Castle - Magic Door} 101 76
addButton: -100 {_____< Restore >_____} 0 90
addButton: 205 {_____Tutorial______} 101 90
;refresh:
init: ;not refresh
)
)
0
)
)
)
(if temp2 (= temp1 (ReadNumber @temp2)))
(if (== temp1 -100) (gKq6 restore:))
;global87 should be game speed; a var between 0 and 15, but this sets it much higher for some reason.
(if (< global87 100)
(= global87 (+ global87 temp1))
else
(= global87 (+ global87 1000))
)
;this seems to set 'isTeleporting' flag, but Proc999_5 doesn't evaluate the params correctly for this purpose.
(if (proc999_5 temp1 200 300 450 500 550)
(proc913_1 103) ;flag 103 'isTeleporting' according to the SCI decompile archive
)
;(global2 east: temp1)
(global2 newRoom: temp1)
)

(procedure (localproc_0161 param1 param2 &tmp [temp0 40])
(= temp0 0)
(if (> argc 1) (Format @temp0 911 0 param2))
(return
(if (proc921_2 @temp0 10 param1)
(ReadNumber @temp0)
else
-1
)
)
)

(procedure (localproc_019c)
(if (proc999_5 (global2 style?) 11 12 13 14)
(global2 sayNext: (global2 roomToEdge:) 100 style: 100)
)
)

;(instance debugHandler of Actions
(instance debugHandler of Code
(properties)

(method (handleEvent param1 &tmp [temp0 200] temp200 temp201 temp202 temp203 temp204 [temp205 4] temp209 temp210 temp211 temp212 temp213 temp214 temp215 temp216 temp217)
(asm
pushi    #type
pushi    0
lap      param1
send     4
push   
dup     
ldi      4
eq?     
bnt      code_0b20
pushi    #claimed
pushi    1
pushi    1
lap      param1
send     6
pushi    #message
pushi    0
lap      param1
send     4
push   
dup     
ldi      7680
eq?     
bnt      code_0386
pushi    #contains
pushi    0
lag      gNewEventHandler
send     4
sat      temp203
code_0208:
lat      temp203
bnt      code_0b1c
pushi    1
push   
callk    NodeValue,  2
sat      temp204
pushi    17
lea      @temp0
push   
lofsa    {name: %s\nclass: %s\nview: %d\nloop: %d\ncel: %d\nposn: %d %d %d\nheading: %d\npri: %d\nsignal: $%x\nscaleSignal: $%x\nscaleX: %d\nscaleY: %d\nillBits: $%x\n}
push   
pushi    #name
pushi    0
lat      temp204
send     4
push   
pushi    #name
pushi    0
pushi    #-super-
pushi    0
lat      temp204
send     4
send     4
push   
pushi    #view
pushi    0
lat      temp204
send     4
push   
pushi    #loop
pushi    0
lat      temp204
send     4
push   
pushi    #cel
pushi    0
lat      temp204
send     4
push   
pushi    #x
pushi    0
lat      temp204
send     4
push   
pushi    #y
pushi    0
lat      temp204
send     4
push   
pushi    #z
pushi    0
lat      temp204
send     4
push   
pushi    #heading
pushi    0
lat      temp204
send     4
push   
pushi    #priority
pushi    0
lat      temp204
send     4
push   
pushi    #signal
pushi    0
lat      temp204
send     4
push   
pushi    #scaleSignal
pushi    0
lat      temp204
send     4
push   
pushi    #scaleX
pushi    0
lat      temp204
send     4
push   
pushi    #scaleY
pushi    0
lat      temp204
send     4
push   
pushi    #-super-
pushi    0
lat      temp204
send     4
push   
class    User
eq?     
bt       code_02d4
pushi    #-super-
pushi    0
lat      temp204
send     4
push   
class    Blk
eq?     
bnt      code_02df
code_02d4:
pushi    #illegalBits
pushi    0
lat      temp204
send     4
jmp      code_02e1
code_02df:
ldi      65535
code_02e1:
push   
callk    Format,  34
pushi    #scaleSignal
pushi    0
lat      temp204
send     4
not     
bnt      code_0357
pushi    #addText
pushi    5
pushi    #view
pushi    0
lat      temp204
send     4
push   
pushi    #loop
pushi    0
lat      temp204
send     4
push   
pushi    #cel
pushi    0
lat      temp204
send     4
push   
pushi    0
pushi    0
pushi    30
pushi    1
lsg      global23
pushi    206
pushi    3
lea      @temp0
push   
pushi    3
pushi    #view
pushi    0
lat      temp204
send     4
push   
pushi    #loop
pushi    0
lat      temp204
send     4
push   
pushi    #cel
pushi    0
lat      temp204
send     4
push   
callk    CelWide,  6
push   
pushi    0
pushi    112
pushi    0
class    Print ;Controls
send     34
jmp      code_0372
code_0357:
pushi    #font
pushi    1
lsg      global23
pushi    206
pushi    3
lea      @temp0
push   
pushi    0
pushi    0
pushi    112
pushi    0
class    Print ;Controls
send     20
code_0372:
pushi    #next
pushi    1
lst      temp203
lag      gNewEventHandler
send     6
sat      temp203
jmp      code_0208
jmp      code_0b1c
code_0386:
dup     
ldi      12288
eq?     
bnt      code_03bc
pushi    #firstTrue
pushi    1
lsg      gEgo
lag      gNewEventHandler
send     6
sal      local1
bnt      code_03a3
pushi    #hide
pushi    0
lag      gEgo
send     4
code_03a3:
pushi    #doit
pushi    0
class    Class_948_1
send     4
lal      local1
bnt      code_0b1c
pushi    #curIcon
pushi    0
lag      gEgo
send     4
jmp      code_0b1c
code_03bc:
dup     
ldi      11776
eq?     
bnt      code_0420
pushi    0
call     localproc_019c,  0
pushi    1
pushi    4
callk    Show,  2
jmp      code_0b1c ;pushi    1  -Fixes Show Control command
pushi    #elements
pushi    0
lag      gNewEventHandler
send     4
push   
callk    Animate,  2
code_03de:
pushi    #cue
pushi    0
class    Event
send     4
sap      param1
pushi    #type
pushi    0
send     4
push   
ldi      1
eq?     
bt       code_0402
pushi    #type
pushi    0
lap      param1
send     4
push   
ldi      4
eq?     
bnt      code_0404
code_0402:
jmp      code_040e
code_0404:
pushi    #new
pushi    0
lap      param1
send     4
jmp      code_03de
code_040e:
pushi    #new
pushi    0
lap      param1
send     4
pushi    1
pushi    1
callk    Show,  2
jmp      code_0b1c
code_0420:
dup     
ldi      8192
eq?     
bnt      code_044c
lag      global14
not     
sag      global14
bnt      code_043d
pushi    1
lofsa    {On}
push   
calle    proc921_0,  2
jmp      code_0b1c
code_043d:
pushi    1
lofsa    {Off}
push   
calle    proc921_0,  2
jmp      code_0b1c
code_044c:
dup     
ldi      4608
eq?     
bnt      code_045e
pushi    #doit
pushi    0
class    Flags
send     4
jmp      code_0b1c
code_045e:
dup     
ldi      8448
eq?     
bnt      code_04b8
ldi      0
sat      temp209
pushi    1
lofsa    {Flag #:}
push   
calle    proc255_1,  2
sat      temp209
pushi    1
push   
calle    proc913_0,  2
bnt      code_049e
pushi    1
lofsa    {cleared}
push   
calle    proc921_0,  2
pushi    1
lst      temp209
calle    proc913_2,  2
jmp      code_0b1c
code_049e:
pushi    1
lofsa    {set}
push   
calle    proc921_0,  2
pushi    1
lst      temp209
calle    proc913_1,  2
jmp      code_0b1c
code_04b8:
dup     
ldi      8704
eq?     
bnt      code_0511
ldi      0
sat      temp0
pushi    3
lea      @temp0
push   
pushi    5
lofsa    {Variable No.}
push   
calle    proc921_2,  6
pushi    1
lea      @temp0
push   
callk    ReadNumber,  2
sat      temp203
not     
bnt      code_04e5
ret     
code_04e5:
ldi      0
sat      temp0
pushi    3
lea      @temp0
push   
pushi    5
lofsa    {Value}
push   
calle    proc921_2,  6
pushi    1
lea      @temp0
push   
callk    ReadNumber,  2
push   
lat      temp203
sagi     gEgo
ldi      0
sat      temp0
jmp      code_0b1c
code_0511:
dup     
ldi      5888
eq?     
bnt      code_0590
code_0518:
pushi    #font
pushi    1
lsg      global23
pushi    206
pushi    3
lofsa    {Enter Inv#:}
push   
pushi    0
pushi    0
pushi    208
pushi    3
lea      @temp0
push   
pushi    5
pushi    80
pushi    213
pushi    4
pushi    100
lofsa    {Outta here!}
push   
pushi    0
pushi    17
pushi    112
pushi    0
class    Print ;Controls
send     42
sat      temp203
push   
ldi      100
eq?     
bnt      code_055b
jmp      code_0b1c
code_055b:
lat      temp0
bnt      code_0579
pushi    1
lea      @temp0
push   
callk    ReadNumber,  2
sat      temp203
pushi    #get ;#lftBordColor
pushi    1
push   
lag      gEgo
send     6
ldi      0
sat      temp0
code_0579:
lst      temp203
ldi      20
eq?     
bnt      code_0518
pushi    1
pushi    1
callk    GetTime,  2
sag      global157
jmp      code_0518
jmp      code_0b1c
code_0590:
dup     
ldi      9472
eq?     
bnt      code_06f6
pushi    0
callk    GetPort,  0
sat      temp200
pushi    1
pushi    0
callk    SetPort,  2
ldi      5
sat      temp216
ldi      16
sat      temp217
ldi      15
sat      temp212
ldi      80
sat      temp213
lst      temp212
pushi    34
lat      temp216
mul     
add     
sat      temp215
lst      temp213
pushi    10
lat      temp217
mul     
add     
sat      temp214
pushi    6
pushi    7
lst      temp212
lst      temp213
lst      temp215
push   
pushi    1
callk    Graph,  12
sat      temp210
pushi    7
pushi    11
lst      temp212
lst      temp213
lst      temp215
lst      temp214
pushi    1
pushi    255
callk    Graph,  14
ldi      0
sat      temp211
code_0608:
lst      temp211
ldi      256
lt?     
bnt      code_067b
pushi    7
pushi    11
lst      temp212
lat      temp216
add     
push   
lst      temp216
lst      temp211
ldi      8
div     
mul     
add     
push   
lst      temp213
lat      temp217
add     
push   
pushi    16
lst      temp211
ldi      8
mod     
mul     
add     
push   
lst      temp212
lat      temp216
add     
push   
lat      temp216
add     
push   
lst      temp216
lst      temp211
ldi      8
div     
mul     
add     
push   
lst      temp213
lat      temp217
add     
push   
lat      temp217
add     
push   
lst      temp217
lst      temp211
ldi      8
mod     
mul     
add     
push   
pushi    1
lst      temp211
callk    Graph,  14
+at      temp211
jmp      code_0608
code_067b:
pushi    6
pushi    12
lst      temp212
lst      temp213
lst      temp215
lst      temp214
pushi    1
callk    Graph,  12
code_0690:
pushi    #cue
pushi    0
class    Event
send     4
sat      temp201
pushi    #type
pushi    0
send     4
push   
ldi      1
eq?     
bt       code_06b6
pushi    #type
pushi    0
lat      temp201
send     4
push   
ldi      4
eq?     
bnt      code_06b8
code_06b6:
jmp      code_06c3
code_06b8:
pushi    #new
pushi    0
lat      temp201
send     4
jmp      code_0690
code_06c3:
pushi    #new
pushi    0
lat      temp201
send     4
pushi    2
pushi    8
lst      temp210
callk    Graph,  4
pushi    6
pushi    12
lst      temp212
lst      temp213
lst      temp215
lst      temp214
pushi    1
callk    Graph,  12
pushi    1
lst      temp200
callk    SetPort,  2
jmp      code_0b1c
code_06f6:
dup     
ldi      12800
eq?     
bnt      code_0709
pushi    #west
pushi    0
lag      gKq6
send     4
jmp      code_0b1c
code_0709:
dup     
ldi      9728
eq?     
bnt      code_073e
pushi    1
pushi    1
callk    MemoryInfo,  2
push   
ldi      1536
ugt?   
bnt      code_072f
pushi    #doit
pushi    0
pushi    1
pushi    952
callk    ScriptID,  2
send     4
jmp      code_0b1c
code_072f:
pushi    1
lofsa    {No Memory!!}
push   
calle    proc921_0,  2
jmp      code_0b1c
code_073e:
dup     
ldi      6400
eq?     
bnt      code_0755
pushi    0
call     localproc_019c,  0
pushi    1
pushi    2
callk    Show,  2
jmp      code_0b1c
code_0755:
dup     
ldi      4096
eq?     
bnt      code_0788
pushi    #font
pushi    1
lsg      global23
pushi    207
pushi    3
lofsa    {Cur X: %d,Y: %d}
push   
pushi    #x
pushi    0
lap      param1
send     4
push   
pushi    #y
pushi    0
lap      param1
send     4
push   
pushi    112
pushi    0
class    Print ;Controls
send     20
jmp      code_0b1c
code_0788:
dup     
ldi      4864
eq?     
bnt      code_0850
pushi    30
pushi    1
lsg      global23
pushi    207
pushi    13
lofsa    {name: %s\nscript: %s\nhorizon: %d\nvanishingX: %d\nvanishingY: %d\npicAngle: %d\nnorth: %d\nsouth: %d\neast: %d\nwest: %d\nstyle: %d\ncurPic: %d_}
push   
pushi    #name
pushi    0
lag      global2
send     4
push   
pushi    1
pushi    #lastTicks
pushi    0
lag      global2
send     4
push   
callk    IsObject,  2
bnt      code_07ca
pushi    #name
pushi    0
pushi    #lastTicks
pushi    0
lag      global2
send     4
send     4
jmp      code_07cd
code_07ca:
lofsa    {none}
code_07cd:
push   
pushi    #close
pushi    0
lag      global2
send     4
push   
pushi    #vanishingX
pushi    0
lag      global2
send     4
push   
pushi    #vanishingY
pushi    0
lag      global2
send     4
push   
pushi    #oldIconBarState
pushi    0
lag      global2
send     4
push   
pushi    #setInset
pushi    0
lag      global2
send     4
push   
pushi    #oneOnly
pushi    0
lag      global2
send     4
push   
pushi    #disposeWhenDone
pushi    0
lag      global2
send     4
push   
pushi    #killed
pushi    0
lag      global2
send     4
push   
pushi    #style
pushi    0
lag      global2
send     4
push   
pushi    #overlay
pushi    0
lag      global2
send     4
push   
pushi    32
pushi    1
class    Window
push   
pushi    67
pushi    1
pushi    170
pushi    77
pushi    1
lofsa    {Current Room}
push   
pushi    112
pushi    0
class    Print ;Controls
send     58
jmp      code_0b1c
code_0850:
dup     
ldi      5120
eq?     
bnt      code_0860
pushi    0
call     proc911_1,  0
jmp      code_0b1c
code_0860:
dup     
ldi      7936
eq?     
bnt      code_0a01
pushi    #contains
pushi    0
lag      gNewEventHandler
send     4
sat      temp203
code_0873:
lat      temp203
bnt      code_0b1c
pushi    1
push   
callk    NodeValue,  2
sat      temp204
pushi    #signal
pushi    0
send     4
push   
ldi      4
and     
not     
bnt      code_09ed
pushi    #signal
pushi    0
lat      temp204
send     4
push   
ldi      128
and     
not     
bnt      code_09ed
pushi    14
lea      @temp0
push   
lofsa    {Updating cast members\nname: %s\nclass: %s\nview: %d\nloop: %d\ncel: %d\nposn: %d %d %d\nheading: %d\npri: %d\nsignal: $%x\nillBits: $%x\n}
push   
pushi    #name
pushi    0
lat      temp204
send     4
push   
pushi    #name
pushi    0
pushi    #-super-
pushi    0
lat      temp204
send     4
send     4
push   
pushi    #view
pushi    0
lat      temp204
send     4
push   
pushi    #loop
pushi    0
lat      temp204
send     4
push   
pushi    #cel
pushi    0
lat      temp204
send     4
push   
pushi    #x
pushi    0
lat      temp204
send     4
push   
pushi    #y
pushi    0
lat      temp204
send     4
push   
pushi    #z
pushi    0
lat      temp204
send     4
push   
pushi    #heading
pushi    0
lat      temp204
send     4
push   
pushi    #priority
pushi    0
lat      temp204
send     4
push   
pushi    #signal
pushi    0
lat      temp204
send     4
push   
pushi    #-super-
pushi    0
lat      temp204
send     4
push   
class    User
eq?     
bt       code_0941
pushi    #-super-
pushi    0
lat      temp204
send     4
push   
class    Blk
eq?     
bnt      code_094c
code_0941:
pushi    #illegalBits
pushi    0
lat      temp204
send     4
jmp      code_094e
code_094c:
ldi      65535
code_094e:
push   
callk    Format,  28
pushi    #scaleSignal
pushi    0
lat      temp204
send     4
not     
bnt      code_09cb
pushi    #addText
pushi    5
pushi    #view
pushi    0
lat      temp204
send     4
push   
pushi    #loop
pushi    0
lat      temp204
send     4
push   
pushi    #cel
pushi    0
lat      temp204
send     4
push   
pushi    0
pushi    0
pushi    30
pushi    1
lsg      global23
pushi    206
pushi    3
lea      @temp0
push   
pushi    3
pushi    #view
pushi    0
lat      temp204
send     4
push   
pushi    #loop
pushi    0
lat      temp204
send     4
push   
pushi    #cel
pushi    0
lat      temp204
send     4
push   
callk    CelWide,  6
push   
pushi    0
pushi    32
pushi    1
class    Window
push   
pushi    112
pushi    0
class    Print ;Controls
send     40
jmp      code_09ed
code_09cb:
pushi    #font
pushi    1
lsg      global23
pushi    206
pushi    3
lea      @temp0
push   
pushi    0
pushi    0
pushi    32
pushi    1
class    Window
push   
pushi    112
pushi    0
class    Print ;Controls
send     26
code_09ed:
pushi    #next
pushi    1
lst      temp203
lag      gNewEventHandler
send     6
sat      temp203
jmp      code_0873
jmp      code_0b1c
code_0a01:
dup     
ldi      5632
eq?     
bnt      code_0a14
pushi    #strPointer
pushi    0
lag      gKq6
send     4
jmp      code_0b1c
code_0a14:
dup     
ldi      12032
eq?     
bnt      code_0a25
pushi    1
pushi    1
callk    Show,  2
jmp      code_0b1c
code_0a25:
dup     
ldi      4352
eq?     
bnt      code_0a37
pushi    #doit
pushi    0
class    DlgWindow
send     4
jmp      code_0b1c
code_0a37:
dup     
ldi      5376
eq?     
bnt      code_0ae5
pushi    #font
pushi    1
lsg      global23
pushi    207
pushi    3
lofsa    {vanishing x: %d,y: %d}
push   
pushi    #vanishingX
pushi    0
lag      global2
send     4
push   
pushi    #vanishingY
pushi    0
lag      global2
send     4
push   
pushi    112
pushi    0
class    Print ;Controls
send     20
pushi    1
lofsa    {vanishingX:}
push   
call     localproc_0161,  2
sat      temp203
pushi    3
push   
pushi    65535
pushi    0
calle    proc999_5,  6
bt       code_0a8f
pushi    #vanishingX
pushi    1
lst      temp203
lag      global2
send     6
code_0a8f:
pushi    1
lofsa    {vanishingY:}
push   
call     localproc_0161,  2
sat      temp203
pushi    3
push   
pushi    65535
pushi    0
calle    proc999_5,  6
bt       code_0ab6
pushi    #vanishingY
pushi    1
lst      temp203
lag      global2
send     6
code_0ab6:
pushi    #font
pushi    1
lsg      global23
pushi    207
pushi    3
lofsa    {vanishing x: %d,y: %d}
push   
pushi    #vanishingX
pushi    0
lag      global2
send     4
push   
pushi    #vanishingY
pushi    0
lag      global2
send     4
push   
pushi    112
pushi    0
class    Print ;Controls
send     20
ldi      0
sat      temp0
jmp      code_0b1c
code_0ae5:
dup     
ldi      11264
eq?     
bnt      code_0af2
ldi      1
sag      global4
jmp      code_0b1c
code_0af2:
dup     
ldi      8960
eq?     
bnt      code_0b12
pushi    #font
pushi    1
lsg      global23
pushi    206
pushi    1
lofsa    {ALT-A show Cast\nALT-B Polygon Editor\nALT-C Control map\nALT-D DebugOn toggle\nALT-F Flag set/clr\nALT-G Global set\nALT-I Inv items\nALT-L Log file\nALT-M Memory\nALT-P Priority map\nALT-Q show Cursor Coords\nALT-R Room info\nALT-S Updating cast elements\nALT-T Teleport\nALT-U return User control\nALT-V Visual map\nALT-W feature Writer\nALT-Y Vanishing point adj\nALT-Z QUICK QUIT}
push   
pushi    112
pushi    0
class    Print ;Controls
send     16
jmp      code_0b1c
code_0b12:
pushi    #claimed
pushi    1
pushi    0
lap      param1
send     6
code_0b1c:
toss   
jmp      code_0c96
code_0b20:
dup     
ldi      1
eq?     
bnt      code_0c96
pushi    #modifiers
pushi    0
lap      param1
send     4
push   
ldi      4
eq?     
bnt      code_0bab
pushi    #claimed
pushi    1
pushi    1
lap      param1
send     6
code_0b3f:
pushi    2
pushi    #type
pushi    0
pushi    #cue
pushi    0
class    Event
send     4
sat      temp201
send     4
ne?     
bnt      code_0b9f
pushi    154
pushi    #view
pushi    #x
pushi    0
lat      temp201
send     4
push   
pushi    #y
pushi    0
lat      temp201
send     4
push   
ldi      10
sub     
push   
pushi    300
pushi    1
pushi    0
pushi    #rename
pushi    0
class    OnMeAndLowY
send     4
send     14
pushi    2
pushi    #elements
pushi    0
lag      gNewEventHandler
send     4
push   
pushi    0
callk    Animate,  4
pushi    #new
pushi    0
lat      temp201
send     4
jmp      code_0b3f
code_0b9f:
pushi    #new
pushi    0
lat      temp201
send     4
jmp      code_0c96
code_0bab:
pushi    #modifiers
pushi    0
lap      param1
send     4
push   
ldi      8
and     
bnt      code_0c96
pushi    #claimed
pushi    1
pushi    1
lap      param1
send     6
pushi    30
pushi    1
pushi    999
pushi    207
pushi    3
lofsa    {%d/%d}
push   
pushi    #x
pushi    0
lap      param1
send     4
push   
pushi    #y
pushi    0
lap      param1
send     4
push   
pushi    154
pushi    2
pushi    #x
pushi    0
lap      param1
send     4
push   
ldi      20
lt?     
bnt      code_0c03
pushi    #x
pushi    0
lap      param1
send     4
jmp      code_0c2b
code_0c03:
pushi    300
pushi    #x
pushi    0
lap      param1
send     4
lt?     
bnt      code_0c1f
pushi    #x
pushi    0
lap      param1
send     4
push   
ldi      40
sub     
jmp      code_0c2b
code_0c1f:
pushi    #x
pushi    0
lap      param1
send     4
push   
ldi      20
sub     
code_0c2b:
push   
pushi    #y
pushi    0
lap      param1
send     4
push   
ldi      16
lt?     
bnt      code_0c44
pushi    #y
pushi    0
lap      param1
send     4
jmp      code_0c50
code_0c44:
pushi    #y
pushi    0
lap      param1
send     4
push   
ldi      6
sub     
code_0c50:
push   
pushi    211
pushi    1
pushi    1
pushi    112
pushi    0
class    Print ;Controls
send     34
sat      temp200
code_0c63:
pushi    2
pushi    #type
pushi    0
pushi    #cue
pushi    0
class    Event
send     4
sat      temp201
send     4
ne?     
bnt      code_0c84
pushi    #new
pushi    0
lat      temp201
send     4
jmp      code_0c63
code_0c84:
pushi    #new
pushi    0
lat      temp201
send     4
pushi    #new
pushi    0
lat      temp200
send     4
code_0c96:
toss   
ret     
)
)
)

Edit: removed out-of-date attachment

Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Collector on September 30, 2022, 11:15:21 PM
EricOakford did a full decompilation of KQ6CD, I think with no assembly. https://github.com/EricOakford/SCI-Decompilation-Archive/tree/master/kq6cd/src It would be nice to get a full decompilation of the debugger script, too.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on September 30, 2022, 11:39:08 PM
Ugh, I didn't notice until now that the debughandler::handleEvent method decompiled as "addAfter" - part of why the ALT commands weren't working. This fixes some of the ALT commands, but several (like get inv item) are still broken.

EricOakford did a full decompilation of KQ6CD, I think with no assembly. https://github.com/EricOakford/SCI-Decompilation-Archive/tree/master/kq6cd/src It would be nice to get a full decompilation of the debugger script, too.

Yes, if anyone unwinds the asm it would be nice to verify which debug commands were originally available.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Collector on October 01, 2022, 10:43:07 AM
911 is missing from both my Collector's Edition and my Collection Series. Could it be that the European release is different from the NA release? Also, if you have the EU release, can you verify if the KQ7 demo it has is interactive or not?
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on October 01, 2022, 12:56:13 PM
Debug commands

[ALT-A]      Show Cast (does nothing)
[ALT-B]      Polygon Editor (crashes game)
[ALT-C]      Control map
[ALT-D]      DebugOn Toggle (doesn't seem to disable debug)
[ALT-E]      Dialogue Editor
[ALT-F]      Flag set/clr (appears to work, needs testing)
[ALT-G]      Global set (appears to work, needs testing)
[ALT-I]      Inv items
[ALT-K]      Show Palette
[ALT-L]      Log file
[ALT-M]      Memory (crashes game)
[ALT-P]      Priority map
[ALT-Q]      show Cursor Coords
[ALT-R]      Room info (crashes game)
[ALT-S]      Updating cast element (does nothing)
[ALT-T]      Teleport ("where to, Stud" menu)
[ALT-U]      return User control (crashes game)
[ALT-V]      Visual map
[ALT-W]      feature Writer (does nothing)
[ALT-Y]      Vanishing point adj
[ALT-Z]      QUICK QUIT

[ALT-H]      Shows the above list of help commands.


Inventory Items:

Code: [Select]
0 map
1 boringBook
2 brick
3 brush
4 hair
5 clothes
6 coal
7 deadMansCoin
8 dagger
9 coin
10 egg
11 skull
12 feather
13 flower
14 flute
15 gauntlet
16 cassimaHair
17 handkerchief
18 holeInTheWall
19 huntersLamp
20 letter
21 lettuce
22 milk
23 mint
24 mirror
25 newLamp
26 nail
27 nightingale
28 ticket
29 participle
30 pearl
31 peppermint
32 note
33 potion
34 rabbitFoot
35 ribbon
36 riddleBook
37 ring
38 rose
39 royalRing
40 sacredWater
41 scarf
42 scythe
43 shield
44 skeletonKey
45 spellBook
46 teaCup
47 poem
48 tinderBox
49 tomato
50 sentence
51 ink

Event Flags
(taken from the SCI Decompile Archive (https://github.com/EricOakford/SCI-Decompilation-Archive/blob/master/kq6cd/src/game.sh))

fBefriendedClown10
fKingQueenRevived 15
fBeenAtCastleGate 18
fMadeMagicPaint 22
fBeenInBookstore 27
fBeenInPawnshop 28
fFragmented 38
fEgoDead   44
fIsVGA 48
Alexander has a reason to collect tears in a lamp 77
fTeleporting 103
fFoundHair 143
fUsedInk 151
fDrankPotion 153


Additional Debugging features

As Omer mentioned, there are additional debug features when you place a file named "g" in your KQ6 game folder while the debugger is active.

Most require that you teleport to the listed from from the opening Sierra logo.

Room 205 (help):
From the title screen click the help button - A Menu with options to skip ahead in the tutorial is show at the start.

Room 470 (dogtree):
Gives inv items tomato, teaCup, huntersLamp, skull and dagger.

Room 480 (brats):
Give flute and milk.
Assign potion to room 480.
Set flag 77.
Set Chapter 4.

Room740 (theGreatEscape):
Chose one of the many possible endings.
This also works when teleporting from room 180 to 740, which uses a seprate script.

Room750 (continuedWindup):
Gives inv item: peppermint.
Play music.
If Jollo has lamp is chosen: assign newLamp to room 750, Load 'Jollo gives lamp' script (751) and LoadMany: scripts 128, 717, 754.
If Cassima has dagger, assign it to room 870.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on October 01, 2022, 06:22:44 PM
911 is missing from both my Collector's Edition and my Collection Series. Could it be that the European release is different from the NA release? Also, if you have the EU release, can you verify if the KQ7 demo it has is interactive or not?

Ok, I was mistaken. 911 isn't in the Collector's Edition. I must of been confused checking so many different versions yesterday, but I tried again with a fresh install and none of the versions I have come with 911. As Omer said back in 2016, it must only be in the Italian and Spanish versions, which I can't find anywhere.

I'm assuming I must have imported Omer's 911.scr at some point and forgotten while switching between versions. The problem with importing Omer's 911.scr is most versions will not decompile it at all. Also, I couldn't get the existing patches to work with any versions I tried - they all crash with error 0.

In the collector's edition, 911 stops decompiling after the first two lines:

Code: [Select]
;;; Sierra Script 1.0 - (do not remove this comment)
(script# 911)
(include sci.sh)



However, I just now verified importing Omer's 911.scr into the GOG offline installer version (setup_kings_quest_6_-_heir_today_gone_tomorrow_1.034_(20239).exe) decompiles the entire patch, but with the wrong commands (i.e. setCursor instead of addButton).

Strangely, the edited patch I recompiled seems to work fine on both the GOG and Steam version as well as the Collector's Edition that couldn't decompile Omer's patch.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Collector on October 01, 2022, 09:33:18 PM
No problems. I often have so many irons in the fire that I lose track of what is what, too. I tried your fixes and everything seems to work well. I added it to the SCI debug page: http://sciwiki.sierrahelp.com//index.php?title=SCI_Debug_Modes#King.27s_Quest_6_CD
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on October 04, 2022, 02:14:28 AM
No problems. I often have so many irons in the fire that I lose track of what is what, too. I tried your fixes and everything seems to work well. I added it to the SCI debug page: http://sciwiki.sierrahelp.com//index.php?title=SCI_Debug_Modes#King.27s_Quest_6_CD

Nice, thanks. I've spent some more time with the debugger and fixed a bunch more stuff like polyedit, feature writer, Palette Display (alt+k was unlisted in help), etc.

Only three things left:
 "return user control" is disabled (doesn't work even if I rewrite it in sierra script).
"Toggle Debug" crashes on screen change because the interpreters don't have the debugger.
"Room Info" prints the information, but crashes after clearing the textbox.

Granted, I don't actually know assembly, but most of it is straightforward enough that I understand it. The part I'm unclear about is that final "send 58". Perhaps that is the cause or "67 ;width" decompiled wrong? If anyone has any insight please let me know.

One final discovery, for some reason the debugger commands are not sent to 911 in several rooms because of this proc999_5 check in Kq6::handleEvent

Code: [Select]
(else
(pEvent claimed: 1)
(if
(and
global100
(not
(proc999_5 gArrayScriptGetValue 440 450 480 270 280 470 490 670 750 740 )
)
)
(pEvent claimed: 0)
((ScriptID 911) handleEvent: pEvent)
((ScriptID 911) dispose:)
(DisposeScript 911)
)
)

What could possibly be the point of excluding all debug commands from rooms  440, 450, 480, 270, 280, 470, 490, 670, 750, 740? Doesn't make sense to me at least. I've added modified 0.scr that removes this restriction.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: lskovlun on October 04, 2022, 08:34:55 AM
Granted, I don't actually know assembly, but most of it is straightforward enough that I understand it. The part I'm unclear about is that final "send 58". Perhaps that is the cause or "67 ;width" decompiled wrong? If anyone has any insight please let me know.
My KQ6 GOG version weirds out on me for a different reason (selector mismatch) when using the Room Info feature, so I can't help you. But the send 58 is normal, that's just because it's a big Print statement.
What could possibly be the point of excluding all debug commands from rooms  440, 450, 480, 270, 280, 470, 490, 670, 750, 740? Doesn't make sense to me at least.
My guess would be heap usage. Either that or an animated sequence might bug out with some of the debug functionality. Or both.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on October 04, 2022, 03:33:00 PM
My guess would be heap usage. Either that or an animated sequence might bug out with some of the debug functionality. Or both.

Yeah, that makes sense. I don't really know KQ6 gameplay, so it's difficult for me to verify if that's the case.

I think the problem with the Room Info is that it's using "addTextF" instead of (Format @temp0 ...), then using "addText: @temp0".

I fixed this in a really stupid hacky way instead of just rewriting everything in SierraScript. I bypass the original key_alt_r asm code by jumping to the end and calling a new local procedure. Then I just wrote the Format and Print in sierraScript. I had to move the strings into 911.txt because any literal strings in the procedure or asm throws off all the other command text. It's sloppy, but it does seem to work.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Collector on October 04, 2022, 03:57:41 PM
Kawa did build a debug version of the interpreter that does run the game.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on October 04, 2022, 04:05:03 PM
Ah, Thank you. I didn't know about that. Seems to work pretty well.

Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Collector on October 04, 2022, 06:07:57 PM
Found where I got it from. https://sciprogramming.com/community/index.php?topic=1802.msg12040#msg12040
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Collector on October 04, 2022, 06:31:54 PM
Kawa's SCI2.1 debug interpreter included a readme file. The interpreter looks for help file (DBGHELP.000) that is missing. The official Sierra files we have include three such files. The attached ZIP includes your latest scripts, Kawa's debug build with readme and the missing DBGHELP files.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on October 04, 2022, 07:10:49 PM
Awesome. With Kawa's interpreter in the mix, the only missing feature is "return control to user".

Polyedit does crash under ScummVM though when moving vectors around - works fine in DOSBox. Show Pri and Show Control also don't work in SVM for some reason.

Did you update the link on the wiki? That old version was mostly broken.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Collector on October 04, 2022, 07:47:22 PM
No, not yet. I'll wait until we have as much worked out as we can get. Just noticed that [SHIFT + /] no longer calls the commands help list.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on October 05, 2022, 12:26:34 PM
Good call. I've already reverted some of my "hacks" and fixed the decompile errors properly, which makes things much more historically accurate.

Turns out [ALT+E] is actually "Dialogue Editor" based on the context clues, not the more common "show Ego info" found in other debuggers. Also, looks like there are mouse related debug features in the asm, but mouse events aren't sent to 911 at the moment. I'll investigate [SHIFT+/] as well.

If I can fix enough of the assembly I'm hoping to get things to the point where SCICompanion can magically decompile everything in SierraScript. I think I'm getting close. I'll post the fixed assembly once I finish unwinding the mouse stuff.

Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Kawa on October 05, 2022, 03:32:01 PM
Might be some Weird Loop if the original at any point had a repeat block. Those never fail to fail decompilation. I like to find their jump instructions, remove them, decompile again, and then put the repeat back.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on October 05, 2022, 04:39:10 PM
Might be some Weird Loop if the original at any point had a repeat block. Those never fail to fail decompilation. I like to find their jump instructions, remove them, decompile again, and then put the repeat back.

Thank you, that is helpful to know for future use. It's some other problem this time. Something with the [ALT+i] assembly, which I overlooked because "Give inv item" has been working fine otherwise.

Code: [Select]
code_055b:
lat      temp0
bnt      code_0579 ;breaks decompile
pushi    1
lea      @temp0
push   
callk    ReadNumber,  2
sat      temp203

I just skipped Give Inv Item and the entire debug script now decompiles in SierraScript! I need to go through everything again and test/clean/fix things (especially the (evMOUSE) stuff that I was fiddling with before I solved the decompile, but here is the mostly complete debugHandler:

Code: [Select]
;;; Sierra Script 1.0 - (do not remove this comment)
(script# 911)
(include sci.sh)
(use Main)
(use Class_255_0)
(use n913)
(use Print)
(use ClickMenu)
(use DlgWindow)
(use Class_948_0)
(use SysWindow)
(use Ego)
(use User)
(use View)
(use Obj)

(public
debugHandler 0
proc911_1 1
)

(local
local0
local1
)
(procedure (proc911_1 &tmp temp0 temp1 [temp2 5])
(= temp2 0)
(= temp1 0)
(gKq6 setCursor: gArrowCursor)
(while
(not
(!=
(= temp1
(Print
font: global23
addText: {Where to, STUD?}
addEdit: @temp2 5 80
addButton: 100 {______Opening________} 0 20
addButton: 200 { Isle of the Crown_} 101 20
addButton: 300 {__Isle Sacred Mtn__} 0 34
addButton: 405 {_____Labyrinth_____} 101 34
addButton: 450 {__Isle of Wonder___} 0 48
addButton: 500 {___Isle of Beast___} 101 48
addButton: 550 { Isle of the Mists_} 0 62
addButton: 600 { Realm of the Dead_} 101 62
addButton: 730 {__Castle - Beauty__} 0 76
addButton: 710 {Castle - Magic Door} 101 76
addButton: -100 {_____< Restore >_____} 0 90
addButton: 205 {_____Tutorial______} 101 90
init:
)
)
0
)
)
)
(if temp2 (= temp1 (ReadNumber @temp2)))
(if (== temp1 -100) (gKq6 restore:))
(if (< global87 100)
(= global87 (+ global87 temp1))
else
(= global87 (+ global87 1000))
)
(if (proc999_5 temp1 200 300 450 500 550)
(proc913_1 103)
)
(global2 newRoom: temp1)
)

(procedure (localproc_0161 param1 param2 &tmp [temp0 40])
(= temp0 0)
(if (> argc 1) (Format @temp0 911 0 param2))
(return
(if (proc921_2 @temp0 10 param1)
(ReadNumber @temp0)
else
-1
)
)
)

(procedure (localproc_019c)
(if (proc999_5 (global2 style?) dpOPEN_SCROLL_RIGHT dpOPEN_SCROLL_LEFT dpOPEN_SCROLL_UP dpOPEN_SCROLL_DOWN)
(global2 drawPic: (global2 picture?) dpCLEAR style: dpOPEN_NO_TRANSITION)
)
)

(instance debugHandler of Code
(properties)

(method (handleEvent pEvent &tmp [temp0 200] temp200 newEvent temp202 temp203 temp204 [temp205 4] temp209 temp210 temp211 temp212 temp213 temp214 temp215 temp216 temp217)
(switch (pEvent type?)
(evKEYBOARD
(pEvent claimed: 1)
(switch (pEvent message?)
(KEY_ALT_a
(= temp203 (gNewEventHandler first:))
(while temp203
(= temp204 (NodeValue temp203))
(Format
@temp0
{name: %s\nclass: %s\nview: %d\nloop: %d\ncel: %d\nposn: %d %d %d\nheading: %d\npri: %d\nsignal: $%x\nscaleSignal: $%x\nscaleX: %d\nscaleY: %d\nillBits: $%x\n}
(temp204 name?)
((temp204 -super-?) name?)
(temp204 view?)
(temp204 loop?)
(temp204 cel?)
(temp204 x?)
(temp204 y?)
(temp204 z?)
(temp204 heading?)
(temp204 priority?)
(temp204 signal?)
(temp204 scaleSignal?)
(temp204 scaleX?)
(temp204 scaleY?)
(if
(or
(== (temp204 -super-?) Actor)
(== (temp204 -super-?) Ego)
)
(temp204 illegalBits?)
else
-1
)
)
(if (not (temp204 scaleSignal?))
(Print
addIcon: (temp204 view?) (temp204 loop?) (temp204 cel?) 0 0
font: global23
addText:
@temp0
(CelWide
(temp204 view?)
(temp204 loop?)
(temp204 cel?)
)
0
init:
)
else
(Print font: global23 addText: @temp0 0 0 init:)
)
(= temp203
(gNewEventHandler next: temp203)
)
)
)
(KEY_ALT_b
(if (= local1 (gNewEventHandler first: gEgo))
(gEgo hide:)
)
(PolyEdit doit:)
(if local1 (gEgo show:))
)
(KEY_ALT_c
(localproc_019c)
(Show 4)
(Animate (gNewEventHandler elements?))
(repeat
(if
(or
(== ((= pEvent (Event new:)) type?) 1)
(== (pEvent type?) evKEYBOARD)
)
(break)
)
(pEvent dispose:)
)
(pEvent dispose:)
(Show 1)
)
(KEY_ALT_d
(if (= global14 (not global14))
(proc921_0 {On})
else
(proc921_0 {Off})
)
)
(KEY_ALT_e (DialogEditor doit:))
(KEY_ALT_f
(= temp209 0)
(= temp209 (proc255_1 {Flag #:}))
(if (proc913_0 temp209)
(proc921_0 {cleared})
(proc913_2 temp209)
else
(proc921_0 {set})
(proc913_1 temp209)
)
)
(KEY_ALT_g
(= temp0 0)
(proc921_2 @temp0 5 {Variable No.})
(if
(not (= temp203 (ReadNumber @temp0)))
(return)
)
(= temp0 0)
(proc921_2 @temp0 5 {Value})
(= [gKq6 temp203] (ReadNumber @temp0))
(= temp0 0)
)
(KEY_ALT_i
(= temp0 0)
(= temp203 0)
(while (!= temp203 100)
(= temp203
(Print
font: global23
addText: {Enter Inv#:}
addEdit: @temp0 5 80
addButton: 100 {Outta here!} 0 17
init:
)
)
(if temp0 (gEgo get: (ReadNumber @temp0)))
(= temp0 0)
)
)
(KEY_ALT_k
(= temp200 (GetPort))
(SetPort 0)
(= temp216 5)
(= temp217 16)
(= temp212 15)
(= temp213 80)
(= temp215 (+ temp212 (* 34 temp216)))
(= temp214 (+ temp213 (* 10 temp217)))
(= temp210
(Graph grSAVE_BOX temp212 temp213 temp215 temp214 1)
)
(Graph grFILL_BOX temp212 temp213 temp215 temp214 1 255)
(= temp211 0)
(while (< temp211 256)
(Graph
grFILL_BOX
(+ temp212 temp216 (* temp216 (/ temp211 8)))
(+ temp213 temp217 (* 16 (mod temp211 8)))
(+ temp212 temp216 temp216 (* temp216 (/ temp211 8)))
(+ temp213 temp217 temp217 (* temp217 (mod temp211 8)))
1
temp211
)
(++ temp211)
)
(Graph grUPDATE_BOX temp212 temp213 temp215 temp214 1)
(repeat
(if
(or
(== ((= newEvent (Event new:)) type?) 1)
(== (newEvent type?) 4)
)
(break)
)
(newEvent dispose:)
)
(newEvent dispose:)
(Graph grRESTORE_BOX temp210)
(Graph grUPDATE_BOX temp212 temp213 temp215 temp214 1)
(SetPort temp200)
)
(KEY_ALT_m (gKq6 showMem:))
(KEY_ALT_l
(if (u> (MemoryInfo 1) 1536)
((ScriptID 952) doit:)
else
(proc921_0 {No Memory!!})
)
)
(KEY_ALT_p
(localproc_019c)
(Show 2)
)
(KEY_ALT_q
(Print
font: global23
addTextF: {Cur X: %d,Y: %d} (pEvent x?) (pEvent y?)
init:
)
)
(KEY_ALT_r
(Print
font: global23
addTextF:
{name: %s\nscript: %s\nhorizon: %d\nvanishingX: %d\nvanishingY: %d\npicAngle: %d\nnorth: %d\nsouth: %d\neast: %d\nwest: %d\nstyle: %d\ncurPic: %d_}
(global2 name?)
(if (IsObject (global2 script?))
((global2 script?) name?)
else
{none}
)
(global2 horizon?)
(global2 vanishingX?)
(global2 vanishingY?)
(global2 picAngle?)
(global2 north?)
(global2 south?)
(global2 east?)
(global2 west?)
(global2 style?)
(global2 curPic?)
window: Window
width: 170
addTitle: {Current Room}
init:
)
)
(KEY_ALT_t (proc911_1))
(KEY_ALT_s
(= temp203 (gNewEventHandler first:))
(while temp203
(if
(and
(not
(&
((= temp204 (NodeValue temp203)) signal?)
$0004
)
)
(not (& (temp204 signal?) $0080))
)
(Format
@temp0
{Updating cast members\nname: %s\nclass: %s\nview: %d\nloop: %d\ncel: %d\nposn: %d %d %d\nheading: %d\npri: %d\nsignal: $%x\nillBits: $%x\n}
(temp204 name?)
((temp204 -super-?) name?)
(temp204 view?)
(temp204 loop?)
(temp204 cel?)
(temp204 x?)
(temp204 y?)
(temp204 z?)
(temp204 heading?)
(temp204 scaleX?)
(temp204 scaleY?)
(if
(or
(== (temp204 -super-?) Actor)
(== (temp204 -super-?) Ego)
)
(temp204 illegalBits?)
else
-1
)
)
(if (not (temp204 scaleSignal?))
(Print
addIcon: (temp204 view?) (temp204 loop?) (temp204 cel?) 0 0
font: global23
addText:
@temp0
(CelWide
(temp204 view?)
(temp204 loop?)
(temp204 cel?)
)
0
window: Window
init:
)
else
(Print
font: global23
addText: @temp0 0 0
window: Window
init:
)
)
)
(= temp203
(gNewEventHandler next: temp203)
)
)
)
(KEY_ALT_u (gUser canInput:))
(KEY_ALT_v (Show 1))
(KEY_ALT_w (Class_948_0 doit:))
(KEY_ALT_y
(Print
font: global23
addTextF:
{vanishing x: %d,y: %d}
(global2 vanishingX?)
(global2 vanishingY?)
init:
)
(= temp203 (localproc_0161 {vanishingX:}))
(if (proc999_5 temp203 -1 0)
else
(global2 vanishingX: temp203)
)
(= temp203 (localproc_0161 {vanishingY:}))
(if (proc999_5 temp203 -1 0)
else
(global2 vanishingY: temp203)
)
(Print
font: global23
addTextF:
{vanishing x: %d,y: %d}
(global2 vanishingX?)
(global2 vanishingY?)
init:
)
(= temp0 0)
)
(KEY_ALT_z (= global4 1))
(KEY_ALT_h
(Print
font: global23
addText:
{ALT-A show Cast\nALT-B Polygon Editor\nALT-C Control map\nALT-D DebugOn toggle\nALT-F Flag set/clr\nALT-G Global set\nALT-I Inv items\nALT-L Log file\nALT-M Memory\nALT-P Priority map\nALT-Q show Cursor Coords\nALT-R Room info\nALT-S Updating cast elements\nALT-T Teleport\nALT-U return User control\nALT-V Visual map\nALT-W feature Writer\nALT-Y Vanishing point adj\nALT-Z QUICK QUIT}
init:
)
)
(else  (pEvent claimed: 0))
)
)
(evMOUSEBUTTON
(cond
((& (pEvent modifiers?) emCTRL)
(pEvent claimed: 1)
(while (!= 2 ((= newEvent (Event new:)) type?))
((User alterEgo?)
posn: (newEvent x?) (- (newEvent y?) 10)
setMotion: 0
)
(Animate (gNewEventHandler elements?) 0)
(newEvent dispose:)
)
(newEvent dispose:)
)
((& (pEvent modifiers?) emALT)
(pEvent claimed: 1)
(= temp200
(Print
font: 999
addTextF: {%d/%d} (pEvent x?) (pEvent y?)
posn:
(cond
((< (pEvent x?) 20) (pEvent x?))
((< 300 (pEvent x?)) (- (pEvent x?) 40))
(else (- (pEvent x?) 20))
)
(if (< (pEvent y?) 16)
(pEvent y?)
else
(- (pEvent y?) 6)
)
modeless: 1
init:
)
)
(while (!= 2 ((= newEvent (Event new:)) type?))
(newEvent dispose:)
)
(newEvent dispose:)
(temp200 dispose:)
)
)
)
)
)
)


I"Room info" was crashing this whole time because 77 is "title:"

Code: [Select]
pushi    77
pushi    1
lofsa    {Current Room}

It should have been 215 which is "addTitle:"
I'm blaming the Sierra devs for not catching that one. I don't think that was a decompile mistake.


Since I skipped ALT+i in the decompile I had to rewrite the SierraScript from scratch. I *think* I have an exact match to the original assembly.

Code: [Select]
(KEY_ALT_i
(= temp0 0)
(= gNewEventHandlerFirst 0)
(while (!= gNewEventHandlerFirst 100)
(= gNewEventHandlerFirst
(Print
font: global23
addText: {Enter Inv#:}
addEdit: @temp0 5 80
addButton: 100 {Outta here!} 0 17
init:
)
)
(if temp0 (gEgo get: (ReadNumber @temp0)))
(= temp0 0)
)
)

Here is the original asm for comparison. Seems like "code_0579" is missing an operator, right? Is there a good online reference to the instruction set? I'm getting mostly links about assembling Ikea furniture when searching the web.

Code: [Select]
code_0511:
dup     
ldi      5888 ;KEY_ALT_i
eq?     
bnt      code_0590
code_0518:
pushi    #font
pushi    1
lsg      global23 ;4
pushi    206 ;addText
pushi    3
lofsa    {Enter Inv#:}
push   
pushi    0
pushi    0
pushi    208 ;addEdit
pushi    3
lea      @temp0
push   
pushi    5
pushi    80
pushi    213 ;addButton
pushi    4
pushi    100
lofsa    {Outta here!}
push   
pushi    0
pushi    17
pushi    112 ;init
pushi    0
class    Print
send     42
sat      temp203
push   
ldi      100
eq?     
bnt      code_055b
jmp      code_0b1c
code_055b:
lat      temp0
bnt      code_0579 ;This breaks decompile
pushi    1
lea      @temp0
push   
callk    ReadNumber,  2
sat      temp203
pushi    #get
pushi    1
push   
lag      gEgo
send     6
ldi      0
sat      temp0
code_0579:
lst      temp203
ldi      20
eq?     
bnt      code_0518
pushi    1
pushi    1
callk    GetTime,  2
sag      global157
jmp      code_0518
jmp      code_0b1c

SCICompanion's decompiler points right to the problem too! Here is the error:
WARNING:  debugHandler::addAfter: Analyzing control flow: Inconsistent then/else branches. Possible "continue" statement?: 1 at 0579

Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Kawa on October 06, 2022, 01:17:43 PM
Code: [Select]
lst      temp203
ldi      20
eq?     
bnt      code_0518
pushi    1
pushi    1
callk    GetTime,  2
sag      global157
jmp      code_0518
jmp      code_0b1c
Load temp203 and 20 to the stack. Check if they're equal. If not, go back to code_0518, where the Print is set up. This consumes the 20 and temp203 from the stack.
Call (GetTime SYSTIME1) (one second res, 12 hours), store the result into global157, jump twice in a row which makes no sense.

Therefore, I judge this block to be FAULTY in context.

Code: [Select]
lat      temp0
bnt      code_0579
Jump to the above bit if temp0 is false. Simple enough. It's the part it jumps to what throws things off.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on October 06, 2022, 02:57:15 PM
One final issue and I can wrap this up. There are two mouse modifier debug commands, emALT and emCTRL. emALT prints the mouse x,y. I believe emCTRL was intended to move the ego to mouse x,y.

Script 911 does NOT receive mouse events, but can be modified to pass them. 

This is what decompiles from 911:

Code: [Select]
(evMOUSEBUTTON
(cond
((== (pEvent modifiers?) emCTRL)
(pEvent claimed: 1)
(while (!= 2 ((= newEvent (Event new:)) type?))
((OnMeAndLowY rename:)
respondsTo: (newEvent x?) (- (newEvent y?) 10)
setMotion: 0
)
(Animate (gNewEventHandler elements?) 0)
(newEvent new:)
)
(newEvent new:)
)
((& (pEvent modifiers?) emALT)
(pEvent claimed: 1)
(= temp200
(Print
font: 999
addTextF: {%d/%d} (pEvent x?) (pEvent y?)
posn:
(cond
((< (pEvent x?) 20) (pEvent x?))
((< 300 (pEvent x?)) (- (pEvent x?) 40))
(else (- (pEvent x?) 20))
)
(if (< (pEvent y?) 16)
(pEvent y?)
else
(- (pEvent y?) 6)
)
modeless: 1
init:
)
)
(while (!= 2 ((= newEvent (Event new:)) type?))
(newEvent dispose:)
)
(newEvent dispose:)
(temp200 dispose:)
)
)
)

Here is what I believe the correct emCTRL code to be with decompile errors fixed.

Code: [Select]
((== (pEvent modifiers?) emCTRL)
(pEvent claimed: 1)
(while (!= 2 ((= newEvent (Event new:)) type?))
((User alterEgo?)
posn: (newEvent x?) (- (newEvent y?) 10)
setMotion: 0
)
(Animate (gNewEventHandler elements?) 0)
(newEvent dispose:)
)
(newEvent dispose:)
)

Since these features aren't super useful, and emCTRL uses "==" instead of "&" and is never true, I assume the Sierra devs might not have had these working either. I'm going to leave them disabled, but I'm open feedback on the matter.

Edit: with 0.scr passing events emCTRL works, but emALT does not. Need to investigate why.

I still need to check why Polyedit breaks on mouse click in ScummVM, but Polyedit is a separate script from 911. Depending on what I find there I'm probably just about ready to released the final 911 files.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Collector on October 06, 2022, 03:26:21 PM
What about the [SHIFT+/]?
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on October 06, 2022, 07:46:37 PM
What about the [SHIFT+/]?

I have a question about this. It seems like it's supposed to show the same output as [ALT+h] currently does, right?

Since the debug handler uses switch case, I can't just change it to ((or KEY_ALT_h KEY_QUESTION). I'd need to break out the help code to a new procedure or have redundant code (unless there is a fall through for switch that I'm missing).

Neither [SHIFT+/] or [ALT+h] is listed in the help output, so does it make more sense to get rid of [ALT+h] and change to [SHIFT+/]? I've spent the last several days trying to keep things as historically accurate as possible, so I'm not sure what the best choice is here.


Edit:

I'm seeing something strange with the emALT modifier. It seems that it's not working with leftclick only rightclick. emCTRL works fine with either so what's the deal with emALT? I guess in this instance I'll just label "Show mouse x,y" as [ALT+Right_Click] and call it good.


As for PolyEdit crashing in ScummVM. I think submitting a bug report is the best thing to do. The SVM error is:
ERROR:
parameter 0: 0034:1ffb (object), should be node
[VM] kPrevNode[35]: signature mismatch in method PolyEdit::prev (room 500, script 999, localCall ffffffff)!

I tested with Pepper Adventures in Time's debugger and Polyedit has the exact same problem. ScummVM also doesn't seem to do anything for Show (Kernel) as well. Everything works in DOSBox so for the purpose of this debugger I'm considering those issues to be a larger SVM problem and not a defect with the patch.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Collector on October 07, 2022, 07:39:23 AM
Perhaps the [SHIFT+/] came from another game and was never used with KQ6. As long as the help list is there I'd say forget the [SHIFT+/]. I'd say to not worry too much about SVM. It has its own debugger.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on October 07, 2022, 12:30:00 PM
After thinking about it last night I decided it's best to leave it ALT+h. There is no reference to [SHIFT+/] in this game and based on how inconsistent things are between debuggers in other games, this is the best choice here.

Attached are the final patch files. I believe this is as close to perfect as I can get for a KQ6 debugger restoration. Thanks all!
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: Collector on October 07, 2022, 04:17:51 PM
I made a small edit to the included readme. The debug files must be in the game's base directory to work. The are ignored if dropped in, say the PATCHES folder. Also, Kawa's sci.exe works without renaming it, so both exes can exist in the same folder and the user can start the game with either, though I did not edit the readme for it. Makes it easier to remove the debug and the original SIERRA.EXE is still there. Attached is the edited readme.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on October 07, 2022, 05:46:02 PM
Great, always good to have another set of eyes on things! Thanks for all your help.
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: deckarep on October 07, 2023, 10:41:36 PM
This thread is somewhat old but I just stumbled on the concept of the KQ6 "g" file that can get tripped.

Apparently for some of the debug stuff to you also have to come immediately from room 99 (speed test room) and have global[100] = 1

But anyways, here's the fully decompiled script with no assembly from Sluicebox sci-scripts repo as found in the dos italian version:

https://github.com/sluicebox/sci-scripts/blob/e2b933ded8540cc1d4d09c0153331abc3bc67a5b/kq6-dos-italian-1.000/src/debugHandler.sc (https://github.com/sluicebox/sci-scripts/blob/e2b933ded8540cc1d4d09c0153331abc3bc67a5b/kq6-dos-italian-1.000/src/debugHandler.sc)
Title: Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
Post by: doomlazer on October 08, 2023, 12:53:48 AM
Apparently for some of the debug stuff to you also have to come immediately from room 99 (speed test room) and have global[100] = 1

Since "Where to, STUD?" is triggered right after the speed test, you just need to teleport from there to get the additional "g" debug features for rooms 205, 470, 480, 740 and 750.