require '_h2ph_pre.ph';

no warnings 'redefine';

unless(defined(&WDCEVENT_H)) {
    eval 'sub WDCEVENT_H () {1;}' unless defined(&WDCEVENT_H);
    eval("sub WDCEVENT_STATUS () { 1; }") unless defined(&WDCEVENT_STATUS);
    eval("sub WDCEVENT_ERROR () { 2; }") unless defined(&WDCEVENT_ERROR);
    eval("sub WDCEVENT_ATAPI_CMD () { 3; }") unless defined(&WDCEVENT_ATAPI_CMD);
    eval("sub WDCEVENT_ATAPI_DONE () { 4; }") unless defined(&WDCEVENT_ATAPI_DONE);
    eval("sub WDCEVENT_ATA_SHORT () { 5; }") unless defined(&WDCEVENT_ATA_SHORT);
    eval("sub WDCEVENT_ATA_LONG () { 6; }") unless defined(&WDCEVENT_ATA_LONG);
    eval("sub WDCEVENT_SET_DRIVE1 () { 7; }") unless defined(&WDCEVENT_SET_DRIVE1);
    eval("sub WDCEVENT_SET_DRIVE0 () { 8; }") unless defined(&WDCEVENT_SET_DRIVE0);
    eval("sub WDCEVENT_REG () { 9; }") unless defined(&WDCEVENT_REG);
    eval("sub WDCEVENT_ATA_EXT () { 10; }") unless defined(&WDCEVENT_ATA_EXT);
    if(defined(&_KERNEL)) {
	eval 'sub WDC_LOG_STATUS {
	    my($chp,$status) = @_;
    	    eval q({  &if ( ($chp->{ch_prev_log_status}) == $status) ;  ($chp->{ch_prev_log_status}) = $status;  &wdc_log($chp,  &WDCEVENT_STATUS, 1, $status); });
	}' unless defined(&WDC_LOG_STATUS);
	eval 'sub WDC_LOG_ERROR {
	    my($chp,$error) = @_;
    	    eval q({  &wdc_log($chp,  &WDCEVENT_ERROR, 1, $error); });
	}' unless defined(&WDC_LOG_ERROR);
	eval 'sub WDC_LOG_ATAPI_CMD {
	    my($chp,$drive,$flags,$len,$cmd) = @_;
    	    eval q({  &u_int8_t  $record[20];  $record[0] = ($flags >> 8);  $record[1] = $flags & 0xff;  &bcopy($cmd,  $record[2], $len);  &wdc_log($chp,  &WDCEVENT_ATAPI_CMD, $len + 2,  &record); });
	}' unless defined(&WDC_LOG_ATAPI_CMD);
	eval 'sub WDC_LOG_ATAPI_DONE {
	    my($chp,$drive,$flags,$error) = @_;
    	    eval q({ \'char\'  $record[3] = {$flags >> 8, $flags & 0xff, $error};  &wdc_log($chp,  &WDCEVENT_ATAPI_DONE, 3,  &record); });
	}' unless defined(&WDC_LOG_ATAPI_DONE);
	eval 'sub WDC_LOG_ATA_CMDSHORT {
	    my($chp,$cmd) = @_;
    	    eval q({  &wdc_log($chp,  &WDCEVENT_ATA_SHORT, 1, $cmd); });
	}' unless defined(&WDC_LOG_ATA_CMDSHORT);
	eval 'sub WDC_LOG_ATA_CMDLONG {
	    my($chp,$head,$precomp,$cylinhi,$cylinlo,$sector,$count,$command) = @_;
    	    eval q({ \'char\'  $record[8] = { $head, $precomp, $cylinhi, $cylinlo, $sector, $count, $command };  &wdc_log($chp,  &WDCEVENT_ATA_LONG, 7,  &record); });
	}' unless defined(&WDC_LOG_ATA_CMDLONG);
	eval 'sub WDC_LOG_SET_DRIVE {
	    my($chp,$drive) = @_;
    	    eval q({  &wdc_log($chp, $drive ?  &WDCEVENT_SET_DRIVE1 :  &WDCEVENT_SET_DRIVE0, 0,  &NULL); });
	}' unless defined(&WDC_LOG_SET_DRIVE);
	eval 'sub WDC_LOG_REG {
	    my($chp,$reg,$val) = @_;
    	    eval q({ \'char\'  $record[3];  $record[0] = $reg;  $record[1] = ($val >> 8);  $record[2] = $val & 0xff;  &wdc_log($chp,  &WDCEVENT_REG, 3,  &record); });
	}' unless defined(&WDC_LOG_REG);
	eval 'sub WDC_LOG_ATA_CMDEXT {
	    my($chp,$lba_hi1,$lba_hi2,$lba_mi1,$lba_mi2,$lba_lo1,$lba_lo2,$count1,$count2,$command) = @_;
    	    eval q({ \'char\'  $record[9] = { $lba_hi1, $lba_hi2, $lba_mi1, $lba_mi2, $lba_lo1, $lba_lo2, $count1, $count2, $command };  &wdc_log($chp,  &WDCEVENT_ATA_EXT, 9,  &record); });
	}' unless defined(&WDC_LOG_ATA_CMDEXT);
    }
}
1;
