// Button Handler
// WARNING: Direct C++ Translation Here
function button_handler($hwnd, $msg, $wparam, $lparam){
global $function, $rom, $loaded; //Globals
if ($loaded == 1){ //Only usuable when rom is loaded
switch ($msg){
case WM_LBUTTONDOWN:
$x = $hwnd;
$tempid = 0;
while ($x >= 108){
$tempid++;
$x -= 8;
}
echo "WM_LBUTTONDOWN received (". LoWord($lparam) .", ". HiWord($lparam) .") from ". GetDlgCtrlID($hwnd) ."...\r\n";
editlvl(16400+$tempid,GetDlgCtrlID($hwnd),1);
displaylevel(16400,149520,24080); //Load level and objects
displayobjs(24892,159760,24092);
break;
case WM_RBUTTONDOWN:
$x = $hwnd;
$tempid = 0;
while ($x >= 108){
$tempid++;
$x -= 8;
}
echo "WM_RBUTTONDOWN received (". LoWord($lparam) .", ". HiWord($lparam) .") from ". GetDlgCtrlID($hwnd) ."...\r\n";
editlvl(16400+$tempid,GetDlgCtrlID($hwnd),0);
displaylevel(16400,149520,24080); //Load level and objects
displayobjs(24892,159760,24092);
break;
}
}
return CallWindowProc($function[$hwnd], $hwnd, $msg, $wparam, $lparam);
}
//Function - writebit - writebit($offset, $location)
//$offset = Rom offset
//$location = Position of the bit
//$fill = 1 for Set Bit, 0 for Clear Bit
//Writes a bit that changes a bit in the byte that is located at the offset
//Returns: 1 if successful
function writebit($offset, $location, $fill){
global $rom;
var_dump($offset);
if ($fill == 1){
$rom[$offset] = $rom[$offset] | (0x80 >> $location);
}
var_dump($offset);
var_dump(ord($rom[$offset]));
return 1;
}
//Function - Edit Level - editlvl($lvloffset, $id, $click){
//$lvloffset = Offset of level
//$id = ID of frame
//$click = Left click (solid,1) or Right click (non-solid,0)
//Edits a block of the level to flip the opposite way
//Returns: 1 if successful
function editlvl($lvloffset, $id, $click){
global $rom;
$level = $rom[$lvloffset];
if ($id <= 99){
return 0;
}
$id -= 100;
while ($id >= 8){
$id -= 8;
}
$location = $id;
$bit = readbit($lvloffset, $location);
writebit($lvloffset, $location, $click);
return 1;
}