idewritesectorscommand.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 72 行

JAVA
72
字号
/*
 * $Id: IDEWriteSectorsCommand.java,v 1.1 2003/11/25 11:50:42 epr Exp $
 */
package org.jnode.driver.ide;

/**
 * This is a simple write command for IDE drives.
 * It uses the old style non DMA command style for the moment.
 * @author gbin
 */
public class IDEWriteSectorsCommand extends IDERWSectorsCommand {

	private final byte[] data;
	private final int offset;
	private final int length;
	private int currentPosition;

	//private int readSectors;

	public IDEWriteSectorsCommand(
		int taskfile,
		boolean master,
		long lbaStart,
		int sectors,
		byte[] src,
		int srcOffset,
		int length) {
		super(taskfile, master, lbaStart, sectors);
		this.data = src;
		this.offset = srcOffset;
		this.currentPosition = srcOffset;
		this.length = length;
	}

	/**
	 * @see org.jnode.driver.ide.IDECommand#setup(IDEBus)
	 */
	protected void setup(IDEBus ide) {
		super.setup(ide);
		ide.setCommandReg(CMD_WRITE);
		transfertASector(ide);
	}

	private void transfertASector(IDEBus ide) {
		ide.waitUntilNotBusy();
		for (int i = 0; i < 256; i++) {
			ide.setDataReg(
				(data[currentPosition] & 0xFF)  + ((data[currentPosition + 1]&0xFF) << 8));
			currentPosition += 2;
		}
	}

	/**
	 * @see org.jnode.driver.ide.IDECommand#handleIRQ(IDEBus)
	 */
	protected void handleIRQ(IDEBus ide) {
		final int state = ide.getStatusReg();
		if ((state & ST_ERROR) != 0) {
			setError(ide.getErrorReg());
			notifyFinished();
		} else {
			if (currentPosition < offset + length) {
				transfertASector(ide);
			} else {
				notifyFinished();
			}

		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?