Switch Trickery

Completed patches for Keen1.
Post Reply
User avatar
CommanderSpleen
Posts: 1017
Joined: Sun Aug 31, 2003 12:11 pm
Location: The Land of Sparkly Things
Contact:

Switch Trickery

Post by CommanderSpleen »

Here be the current results of my search for a solution to PATCH REQUEST: Switch Trickery. My main plan at the moment is to make all switches alternate between two tiles, an ability normally reserved for tiles $1E0 and $1ED.

Code: Select all

# Switch tiles change to the next in the tileset when flipped
# Doesn't affect lightswitch
%patch $36D5 $05 $01 $00 $26 $89 $07 $90 $90 $90 $90 $90 $90 $90 $90 $90
Not particularly useful in its current incarnation, but I'm working on it.

Notes, whinges and failed attempts:
I am working on making it revert to tile $1E0 when $1E1 is reached (thus keeping the Keen2 switch in tact), but it's run into some issues. If it would work, the two reference tiles could easily be changed to allow an indefinite series of tiles to be alternated between.

It's pretty cramped around there, and I'm not sure how to jump back and forth over large distances in order to access empty space, so I've shuffled around the code a bit... alas, I believe I've broken it.

If I could work out how to determine the tile properties directly, this would be so much easier. I've found a single reference to $0019, the Switch On tile, but as far as I can tell it's an irrelevant fluke.

Code: Select all

# Basically the same as above but will have the same
# problem as the following one at tile $1ED
%patch $36DD                                                     $74 $08 $05
             $01 $00 $26 $89 $07 $EB $46 $26 $C7 $07 $E0 $01 $EB $3F $07 $EB
             $3C $FD $26 $C7 $07 $E0 $01 $EB $34 $26 $C7 $07 $ED $01 $EB $2D
# Switches go wacky
%patch $36DD                                         $3D $E1 $02 $74 $08 $05
             $01 $00 $26 $89 $07 $EB $46 $26 $C7 $07 $E0 $01 $EB $3F $07 $EB
             $3C $FD $26 $C7 $07 $E0 $01 $EB $34 $26 $C7 $07 $ED $01 $EB $2D

Code: Select all

The Assembly code (and a couple of annotations) behind it:
$36DA:
cmp ax, 010F
je 371A
cmp ax, 01E1
je 36E7 [1]
add ax,0001

es:
mov word ptr [bx], ax
jmp 372D
[1]es:
mov word ptr [bx],01E0
jmp 372D
Patching is sooo much easier when you remember to select that bloody checkbox in W32Dasm to detect 16-bit Assembly... all this time I've been working in 32-bit and it screws things up big time.

Now for sleep...
User avatar
MultiMania
Patch Master
Posts: 153
Joined: Mon Nov 24, 2003 3:09 am
Location: Deep in the heart of keen.
Contact:

Post by MultiMania »

For those poor souls who need help for hacking the switches, here is the disassembly of that bit of code.

Code: Select all

seg000:36BC loc_36BC:                               ; CODE XREF: DoSwitches+33j
seg000:36BC                 mov     ax, word_1B26A
seg000:36BF                 imul    PlaneSize
seg000:36C3                 add     ax, word_1B268
seg000:36C7                 shl     ax, 1
seg000:36C9                 les     bx, dword_19C98
seg000:36CD                 add     bx, ax
seg000:36CF                 mov     ax, es:[bx]
seg000:36D2                 mov     [bp+var_4], ax
seg000:36D5                 cmp     ax, 10Fh        ; Light Switch
seg000:36D8                 jz      loc_371A
seg000:36DA                 cmp     ax, 1E0h        ; On Switch
seg000:36DD                 jz      loc_36E6
seg000:36DF                 cmp     ax, 1EDh        ; Off Switch
seg000:36E2                 jz      loc_3700
seg000:36E4                 jmp     short loc_372D
seg000:36E6 ; ---------------------------------------------------------------------------
seg000:36E6 
seg000:36E6 loc_36E6:                               ; CODE XREF: DoSwitches+10Bj
seg000:36E6                 mov     ax, word_1B26A
seg000:36E9                 imul    PlaneSize
seg000:36ED                 add     ax, word_1B268
seg000:36F1                 shl     ax, 1
seg000:36F3                 les     bx, dword_19C98
seg000:36F7                 add     bx, ax
seg000:36F9                 mov     word ptr es:[bx], 1EDh ; Off Switch
seg000:36FE                 jmp     short loc_372D
seg000:3700 ; ---------------------------------------------------------------------------
seg000:3700 
seg000:3700 loc_3700:                               ; CODE XREF: DoSwitches+110j
seg000:3700                 mov     ax, word_1B26A
seg000:3703                 imul    PlaneSize
seg000:3707                 add     ax, word_1B268
seg000:370B                 shl     ax, 1
seg000:370D                 les     bx, dword_19C98
seg000:3711                 add     bx, ax
seg000:3713                 mov     word ptr es:[bx], 1E0h ; On Switch
seg000:3718                 jmp     short loc_372D
seg000:371A ; ---------------------------------------------------------------------------
seg000:371A 
seg000:371A loc_371A:                               ; CODE XREF: DoSwitches+106j
seg000:371A                 cmp     word_1B26E, 0
seg000:371F                 jz      loc_3727
seg000:3721                 call    LightSwitch
seg000:3724                 jmp     loc_3861
Post Reply