Page 1 of 1

Tuner Patch

Posted: Thu Aug 27, 2009 7:51 am
by lemm

Code: Select all

%ext ck1
%version 1.31

################ Tuner Patch ###############
#-Alters a word variable in the code segment when the up/down arrows are pressed.
#-To alter something in another segment replace '$2E' in the base patch 
#-To invert up/down keys, swap $7F in the third row and $7C in the fourth row,
# and swap the min/maxvalues/deltas

#BASE PATCH - place this before CONSTANTS

#Skip diagonal-key checking                    
%patch $55EF $EB $4A          #jmp short 0x563B

#Disable vorticon border flash 
%patch $4A45 $C3  	

#tuning code
%patch $55F1 
$2E $A1 $00 $00 $8B $1E $CA $7F	 	
$D1 $E3	$2E $FF $A7 $00 $00	$3D
$00 $00 $7F $16 $05 $00 $00 $EB
$0D $3D $00 $00 $7C $0C $05 $00
$00 $EB $03 $B8 $00 $00 $2E $A3
$00 $00 $E9 $00 $00        

#jump table
%patch $4A48                     
$00 $56 $00 $56 $14 $56 $0A $56              
$0A $56 $0A $56 $14 $56 $00 $56 	         
$14 $56              

#CONSTANTS - Pick one block to tune a value in game (A jmp to $55F1 is required, they are included in these examples)

#1. Pogo Jetpack

%patch $55F3 $5B $3F       #VALUE_W (word in memory to be altered)
%patch $5619 $5B $3F	                      
%patch $55FE $48 $4A       #JUMPTABL_W (offset of jump table in code segment)
%patch $5601 $20 $00       #MAXVAL_W (maximum value; when up arrow pressed)
%patch $5606 $04 $00       #UPDELTA_W (rate of upwards change) 
%patch $560B $C0 $FF       #MINVAL_W (minimum value; when down arrow pressed)
%patch $5610 $FC $FF       #DOWNDELTA_W (rate of downward change)
%patch $5615 $F2 $FF       #DEFAULT_W (default vlaue; when no up or down pressed)
%patch $561C $32 $E9       #EXIT_W (jmp near at end of tuner patch)

#This is the jump to $55F1
%patch $3F49 $E9 $A5 $16 

##############################################

#2. Adjustable Raygun Angle

%patch $55F3 $EE $46        #VALUE_W
%patch $5619 $EE $46
%patch $55FE $48 $4A        #JUMPTABL_W
%patch $5601 $40 $00        #MAXVAL_W
%patch $5606 $40 $00        #UPDELTA_W
%patch $560B $C0 $FF        #MINVAL_W
%patch $5610 $C0 $FF        #DOWNDELTA_W
%patch $5615 $00 $00        #DEFAULT_W
%patch $561C $1D $00        #EXIT_W

#This constitutes the jump to $55F1
%patch $55EF $90 $90          

%end





Directions

Posted: Thu Aug 27, 2009 8:06 am
by lemm
This patch allows keen to "tune" a variable by pressing up or down. When up or down is released, the variable returns to its default value. This patch overwrites the code that checks for pg up, pg down, end and insert, so these keys will be unavailable.

To use it, first copy in the base patch.
Then, right below where you put the base patch, copy in ONE block of constants. You can edit the maximum, minimum, and default values, as well as the rates of change (deltas) in either direction.

Two complete examples are provided, one alters pogo-jetpack thrust, the other alters keen's raygun angle. I will probably add more later.

Posted: Thu Aug 27, 2009 9:08 am
by CommanderSpleen
Very excellent work. I guess this provides infinite pogo rather than using a counter to limit it?

Posted: Thu Aug 27, 2009 1:27 pm
by Mink
Wow, that's quite impressive. It opens up so many possibilities for new puzzles and level design, that I may have to use it if I ever make a Keen 1 mod. Nice work.

Posted: Sat Aug 29, 2009 11:45 am
by lemm
CommanderSpleen wrote:Very excellent work. I guess this provides infinite pogo rather than using a counter to limit it?

The normal vertical displacement due to pogoing is calculated by the call to pogo_jump at 3F46. This alters keen_pos_y. The if-block at 3F49 will overwrite that if god_mode !=0 && word_1B01C (ctrl/pogo button is pressed) != 0.

Code: Select all

	// seg000:3F2D
	if (MEMW(word_1B01C) != 0 && (short)MEMW(keen_pos_y) < 0) {
		// seg000:3F3B
		PUSHI(0xffff);
		PUSHI(0xc8);
		EMU_CALL(a_pogo_jump, 3F46, think_30);
		reg_sp += 4;
	}

	// seg000:3F49
	if (MEMW(god_mode) != 0 && MEMW(word_1B01C) != 0) {
		// seg000:3F57
		W_MEMW(keen_pos_y, 0xff38);
	}


Also, I *think* that the keen-movement data is stored in a three-word chunk from 1B01A to 1B01E. Word_1B01A stores an int 0 thru 8, with 0 = up, 1 = up-right...clockwise until 7 = up-left, and 8 = no movement.

Word_1B01C stores ctrl up/down and Word_1B01E stores Alt up/down.

Also, it looks like the data segment = 0x1305

Posted: Sun Aug 30, 2009 1:45 pm
by levellass
Ok, so what are the chances of this being improved as suggested?

Also note that in CKPatch you don't have to start every line with a %patch location, if more $ values are given, CKP assumes they come right after the last ones it's patched. This may make things look tidier.

Posted: Wed Sep 02, 2009 3:46 pm
by lemm
Well I am starting to understand how these behaviour functions operate, so the patch I posted will probably be scrapped in favor of a better design. But it will be posted within the next couple of days.

Posted: Wed Sep 02, 2009 3:51 pm
by Fleexy
Wow, you know a lot of assembly, lemm! Do you think you could help me with my Cosmo 1 dissasembly?

Posted: Wed Sep 02, 2009 5:22 pm
by lemm
I know about ten commands in assembly. I've been reading up on it only for 3 weeks :p. Sorry, I wouldn't be able to help you much...


All I can say is read Art of Assembly

and try a decompiler:

DCC: http://www.itee.uq.edu.au/~cristina/dcc.html
or
REC: http://www.backerstreet.com/rec/rec.htm

Posted: Thu Sep 03, 2009 7:01 pm
by lemm
levellass wrote:Ok, so what are the chances of this being improved as suggested?

Also note that in CKPatch you don't have to start every line with a %patch location, if more $ values are given, CKP assumes they come right after the last ones it's patched. This may make things look tidier.
Levellass, I fixed the bugs and made it as compact as I could. Also, it's generalized now to tune any word in the code segment.. shot velocity, speed, jump height etc. I put two examples in.


commented version

Posted: Fri Sep 04, 2009 10:33 am
by levellass
So, where do I put the jumps for either patch? (To the new code.)

Posted: Fri Sep 04, 2009 2:13 pm
by lemm
They were included in the examples. Sorry, I wrote it like another one was required.

Posted: Mon Sep 07, 2009 3:50 pm
by KeenRush
Pretty neat!