Author Topic: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")  (Read 12092 times)

0 Members and 1 Guest are viewing this topic.

Offline Kawa

Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
« Reply #30 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.

Offline doomlazer

Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
« Reply #31 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

« Last Edit: October 08, 2022, 02:39:58 PM by doomlazer »

Offline Kawa

Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
« Reply #32 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.

Offline doomlazer

Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
« Reply #33 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.
« Last Edit: October 06, 2022, 07:47:07 PM by doomlazer »

Offline Collector

Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
« Reply #34 on: October 06, 2022, 03:26:21 PM »
What about the [SHIFT+/]?
KQII Remake Pic

Offline doomlazer

Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
« Reply #35 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.
« Last Edit: October 06, 2022, 11:12:48 PM by doomlazer »

Offline Collector

Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
« Reply #36 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.
KQII Remake Pic

Offline doomlazer

Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
« Reply #37 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!

Offline Collector

Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
« Reply #38 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.
KQII Remake Pic

Offline doomlazer

Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
« Reply #39 on: October 07, 2022, 05:46:02 PM »
Great, always good to have another set of eyes on things! Thanks for all your help.

Offline deckarep

Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
« Reply #40 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

Offline doomlazer

Re: King's Quest 6 Debug Mode (previous subject was: "Compilation error help")
« Reply #41 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.


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

Page created in 0.073 seconds with 24 queries.