⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 input.pas

📁 delphi编制的nes模拟器--tNes
💻 PAS
字号:
unit input;

interface
uses
    DXInput;

type
    TInput = class
        read_number1: Integer;
        read_number2: integer;
        Reset1: Boolean;
        Reset2: Boolean;
        Strobe1: Boolean;
        Strobe2: Boolean;
        m_DXI1: TdxInput;
        m_DXI2: TdxInput;
        constructor Create(DXI1, DXI2: TdxInput);
        function InputRead(addr: Word): Byte;
        procedure InputWrite(addr: Word; data: Byte);
    end;
implementation

{ TInput }

constructor TInput.Create(DXI1, DXI2: TDXInput);
begin
    read_number1 := 0;
    read_number2 := 0;

    Reset1 := False;
    Reset2 := False;

    Strobe1 := false;
    Strobe2 := False;

    m_DXI1 := DXI1;
    m_dxi2 := DXI2;
end;

function TInput.InputRead(addr: Word): Byte;
begin
    m_DXI1.Update;
    m_DXI2.Update;
    if addr = $4016 then
    begin
        if not Reset1 then
        begin
            Result := $40;
            Exit;
        end;

        Inc(read_number1);
        case read_number1 of
            1: if isButton1 in m_DXI1.States then //button a
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;
            2: if isButton2 in m_DXI1.States then //button b
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;
            3: if isButton3 in m_DXI1.States then //button select
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;
            4: if isButton4 in m_DXI1.States then //button start
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;

            5: if isup in m_DXI1.States then //up
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;

            6: if isdown in m_DXI1.States then //down
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;

            7: if isleft in m_DXI1.States then //left
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;

            8: if isright in m_DXI1.States then //right
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;
            17..19: Result := $40;
            20: Result := $41;
            24: begin
                    Reset1 := False;
                    Result := $40;
                end;

        else
            Result := $40;
        end;
    end else if addr = $4017 then
    begin
		if not Reset2 then
        begin
            Result := $40;
            Exit;
        end;

		Inc(read_number2);
		case read_number2 of
            1: if isButton1 in m_DXI2.States then
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;
            2: if isButton2 in m_DXI2.States then
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;
            3: if isButton3 in m_DXI2.States then
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;
            4: if isButton4 in m_DXI2.States then
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;

            5: if isup in m_DXI2.States then
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;

            6: if isdown in m_DXI2.States then
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;

            7: if isleft in m_DXI2.States then
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;

            8: if isright in m_DXI2.States then
                begin
                    Result := $41;
                    Exit;
                end else
                begin
                    Result := $40;
                    exit;
                end;
            17..19: Result := $40;
            20: Result := $41;
            24: begin
                    Reset2 := False;
                    Result := $40;
                end;

        else
            Result := $40;
        end;
    end;
end;

procedure TInput.InputWrite(addr: Word; data: Byte);
begin
    if addr = $4016 then
    begin
        if Strobe1 and (data = 0) then
        begin
			Reset1 := True;
			Strobe1 := False;
			read_number1 := 0;


        end else
        begin
            if (data = 1) then
                Strobe1 := True;
        end;

	end else
		begin
			if Strobe1 and (data = 0) then
			begin
				Reset1 := True;
				Strobe1 := False;
				read_number1 := 0;
			end else
			begin
				if (data = 1) then
					Strobe1 := True;
			end;
		end;    
end;

end.

⌨️ 快捷键说明

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