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

📄 cpu.pas

📁 delphi编制的nes模拟器--tNes
💻 PAS
📖 第 1 页 / 共 5 页
字号:
                setnz(tempbyte);
                memwrite(taddr, tempbyte);

                inc(cycles, 6);
                inc(pc, 2);
            end;

        $0E: //asl absolute
            begin

				taddr:=AbAddress(pc);
				tempbyte := memread(taddr);

{$IFDEF debug}
                curIns := 'ASL $' + intToHex(taddr, 0);
{$ENDIF}

                ps.cf := tempbyte and $80;
                ps.cf := ps.cf shr 7;
                asm
          shl tempbyte,1;
                end;

                setnz(tempbyte);
                memwrite(taddr, tempbyte);

                inc(cycles, 6);
                inc(pc, 3);
            end;

        $1E: //asl absolute.x
            begin

				taddr:=IABAddress(pc,x);
				tempbyte :=memread(taddr);

{$IFDEF debug}
                curIns := 'ASL $' + intToHex(taddr-x, 0) + ',X';
{$ENDIF}


                ps.cf := tempbyte and $80;
                ps.cf := ps.cf shr 7;
                asm
					shl tempbyte,1;
                end;

                setnz(tempbyte);
                memwrite(taddr, tempbyte);

                inc(cycles, 7);
                inc(pc, 3);
            end;
  //*                                       *
  //*       asl instruction 2005/12/21      *
  //*---------------end---------------------*


  //*                                       *
  //*       bcc instruction 2005/12/23      *
  //*---------------start-------------------*
        $90:
            begin

                inc(pc, 2);
                if ps.cf <> 0 then
                begin
                    inc(cycles, 2);
{$IFDEF debug}
					curIns := 'BCC $' + intToHex(ShortInt(memread(pc + 1)), 0) + '  NO Jump';
{$ENDIF}
                end
                else
                begin
                    inc(cycles, 4);
                    offset := shortint(memread(pc - 1));
                    pc := pc + offset;
{$IFDEF debug}
                    curIns := 'BCC $' + intToHex(ShortInt(memread(pc + 1)), 0) + ' Jump';
{$ENDIF}
                end;
            end;
  //*                                       *
  //*       bcc instruction 2005/12/23      *
  //*---------------end---------------------*

  //*                                       *
  //*       bcs instruction 2005/12/23      *
  //*---------------start-------------------*
        $B0:
            begin

                inc(pc, 2);
                if ps.cf = 0 then
                begin
                    inc(cycles, 2);
{$IFDEF debug}
                    curIns := 'BCS $' + intToHex(ShortInt(memread(pc + 1)), 0) + ' NO Jump';
{$ENDIF}
                end
                else
                begin
                    inc(cycles, 4);
                    offset := shortint(memread(pc - 1));
                    pc := pc + offset;
{$IFDEF debug}
                    curIns := 'BCS $' + intToHex(ShortInt(memread(pc + 1)), 0) + ' Jump';
{$ENDIF}
                end;
            end;
  //*                                       *
  //*       bcs instruction 2005/12/23      *
  //*---------------end---------------------*

  //*                                       *
  //*       beq instruction 2005/12/23      *
  //*---------------start-------------------*
        $F0:
            begin

                inc(pc, 2);
                if ps.zf = 0 then
                begin

                    inc(cycles, 2);
{$IFDEF debug}
                    curIns := 'BCS $' + intToHex(ShortInt(memread(pc + 1)), 0) + ' NO Jump';
{$ENDIF}
                end
                else
                begin
                    inc(cycles, 4);
                    offset := shortint(memread(pc - 1));
                    pc := pc + offset;
{$IFDEF debug}
                    curIns := 'BCS $' + intToHex(ShortInt(memread(pc + 1)), 0) + ' Jump';
{$ENDIF}
                end;
            end;
  //*                                       *
  //*       beq instruction 2005/12/23      *
  //*---------------end---------------------*




  //*                                       *
  //*       bit instruction 2005/12/23      *
  //*---------------start-------------------*
  //*modifed by 2005/12/31
        $24: //bit with zero page
			begin

				taddr:=ZpAddress(pc);
				tempbyte:=memread(taddr);
{$IFDEF debug}
				curIns := 'BIT $' + intToHex(taddr, 0);
{$ENDIF}


                ps.off := (tempbyte and $40) shr 6;
                ps.nf := (tempbyte and $80) shr 7;
                if (a and tempbyte) = 0 then
                    ps.zf := 1
                else ps.zf := 0;

                inc(cycles, 3);
                inc(pc, 2);
            end;

        $2C: //bit with absolute
            begin

			   taddr:=AbAddress(pc);
				tempbyte:=memread(taddr);
{$IFDEF debug}
                curIns := 'BIT $' + intToHex(taddr, 0);
{$ENDIF}

                ps.off := (tempbyte and $40) shr 6;
				ps.nf := (tempbyte and $80) shr 7;

                if (a and tempbyte) = 0 then
                    ps.zf := 1
                else ps.zf := 0;

                inc(cycles, 4);
                inc(pc, 3);
            end;
  //*                                       *
  //*       bit instruction 2005/12/23      *
  //*---------------end---------------------*

  //*  (branch if minus)                                                       *
  //*        bmi instruction 2005/12/25      *
  //*-------------------start----------------*
        $30:
            begin

                inc(pc, 2);
                if ps.nf = 0 then
                begin
                    inc(cycles, 2);
{$IFDEF debug}
                    curIns := 'BMI $' + intToHex(ShortInt(memread(pc + 1)), 0) + ' NO Jump';
{$ENDIF}
                end
                else
                begin
                    inc(cycles, 4);
                    offset := shortint(memread(pc - 1));
                    pc := pc + offset;

{$IFDEF debug}
                    curIns := 'BMI $' + intToHex(ShortInt(memread(pc + 1)), 0) + ' Jump';
{$ENDIF}
                end;
            end;
  //*                                       *
  //*       bmi instruction 2005/12/25      *
  //*---------------end---------------------*


  //*                                       *
  //*       bne instruction 2005/12/25      *
  //*---------------start-------------------*
        $D0:
            begin

                inc(pc, 2);
                if ps.zf = 1 then
                begin
                    inc(cycles, 2);
{$IFDEF debug}
                    curIns := 'BNE $' + intToHex(ShortInt(memread(pc + 1)), 0) + 'NO Jump';
{$ENDIF}
                end
                else
                begin
                    inc(cycles, 4);
                    offset := shortint(memread(pc - 1));
                    pc := pc + offset;

{$IFDEF debug}
                    curIns := 'BNE $' + intToHex(ShortInt(memread(pc + 1)), 0) + ' Jump';
{$ENDIF}
                end;
            end;
  //*                                       *
  //*       bne instruction 2005/12/25      *
  //*---------------end---------------------*


  //*      branch if positive               *
  //*       bpl instruction 2005/12/25      *
  //*---------------start-------------------*
        $10:
            begin

                inc(pc, 2);
                if ps.nf = 1 then
                begin
                    inc(cycles, 2);
{$IFDEF debug}
                    curIns := 'BPL $' + intToHex(ShortInt(memread(pc + 1)), 0) + ' NO Jump';
{$ENDIF}
                end
                else
                begin
                    inc(cycles, 4);
                    offset := shortint(memread(pc - 1));
                    pc := pc + offset;
{$IFDEF debug}
                    curIns := 'BPL $' + intToHex(ShortInt(memread(pc + 1)), 0) + ' Jump';
{$ENDIF}
                end;
            end;
  //*                                       *
  //*       bpl instruction 2005/12/25      *
  //*---------------end---------------------*


  //*                                       *
  //*       brk instruction 2005/12/25      *
  //*---------------start-------------------*
        $00:
            begin
{$IFDEF debug}
                curIns := 'BRK';
{$ENDIF}

				inc(pc,2);       // Modified by tian 2006-02-21 10:27:07
				tempbyte := pc shr 8;
				push(tempbyte); //high----->low
				push(pc and $FF);

				ps.bf := 1;
				push(pscombine);

				pc := (memread(brkvector + 1) shl 8) or memread(brkvector);

				inc(cycles, 7);

            end;
  //*                                       *
  //*       brk instruction 2005/12/25      *
  //*---------------end---------------------*


  //*      branch if overflow  clear             *
  //*       bvc instruction 2005/12/25      *
  //*---------------start-------------------*
        $50:
            begin

                inc(pc, 2);
                if ps.off = 1 then
                begin
                    inc(cycles, 2);
{$IFDEF debug}
                    curIns := 'BVC $' + intToHex(ShortInt(memread(pc + 1)), 0) + ' NO Jump';
{$ENDIF}
                end
                else
                begin
                    inc(cycles, 4);
                    offset := shortint(memread(pc - 1));
                    pc := pc + offset;

{$IFDEF debug}
                    curIns := 'BVC $' + intToHex(ShortInt(memread(pc + 1)), 0) + ' Jump';
{$ENDIF}
                end;
            end;
  //*                                       *
  //*       bvc instruction 2005/12/25      *
  //*---------------end---------------------*

  //*      branch if overflow set           *
  //*       bvs instruction 2005/12/25      *
  //*---------------start-------------------*
        $70:
            begin

                inc(pc, 2);
                if ps.off = 0 then
                begin
                    inc(cycles, 2);
{$IFDEF debug}
                    curIns := 'BVS $' + intToHex(ShortInt(memread(pc + 1)), 0) + ' NO Jump';
{$ENDIF}
                end
                else
                begin
                    inc(cycles, 4);
                    offset := shortint(memread(pc - 1));
                    pc := pc + offset;

{$IFDEF debug}
                    curIns := 'BVC $' + intToHex(ShortInt(memread(pc + 1)), 0) + ' NO Jump';
{$ENDIF}
                end;
            end;
  //*                                       *
  //*       bvs instruction 2005/12/25      *
  //*---------------end---------------------*


  //*       clear carry flag                *
  //*       clc instruction 2005/12/25      *
  //*---------------start-------------------*
        $18:
            begin
{$IFDEF debug}
                curIns := 'CLC';
{$ENDIF}

                ps.cf := 0;
                inc(cycles, 2);
                inc(pc, 1);
            end;
  //*                                       *
  //*       clc instruction 2005/12/25      *
  //*---------------end---------------------*



  //*       clear decimal mode              *
  //*       cld instruction 2005/12/25      *
  //*---------------start-------------------*
        $D8:
            begin
{$IFDEF debug}
                curIns := 'CLD';
{$ENDIF}

                ps.dm := 0;
                inc(cycles, 2);
                inc(pc, 1);
            end;
  //*                                       *
  //*       cld instruction 2005/12/25      *
  //*---------------end---------------------*



  //*       clear interrupt disable         *
  //*       cli instruction 2005/12/25      *
  //*---------------start-------------------*
        $58:
            begin
{$IFDEF debug}
                curIns := 'CLI';
{$ENDIF}

                ps.id := 0;
                inc(cycles, 2);
                inc(pc, 1);

            end;
  //*                                       *
  //*       cli instruction 2005/12/25      *
  //*---------------end---------------------*


  //*       clear overflow flag             *
  //*       clv instruction 2005/12/25      *
  //*---------------start-------------------*
        $B8:
            begin
{$IFDEF debug}
                curIns := 'CLV';
{$ENDIF}

                ps.off := 0;
                inc(cycles, 2);
                inc(pc, 1);
            end;
  //*                                       *
  //*       clv instruction 2005/12/25      *
  //*---------------end---------------------*




  //*                                       *
  //*       cmp instruction 2005/12/26      *
  //*---------------start-------------------*
        $C9: //immediate
            begin
{$IFDEF debug}
                curIns := 'CMP #$ ' + intToHex(memread(pc + 1), 0);
{$ENDIF}

				tempbyte := memread(pc + 1);

				tempflag:=Ps.off;
				
				acc := a;
				psw := psTopsw;
                asm
					mov ah,psw
					sahf
					mov al,acc
					cmp al,tempbyte
					cmc
					lahf

					mov psw,ah
				end;

				pswTops(psw);

				Ps.off:=tempflag;
				
				inc(cycles, 2);
                inc(pc, 2);

            end;
  //*                                       *
  //*       cmp instruction 2005/12/26      *
  //*---------------end---------------------*


  //*                                       *
  //*       cmp instruction 2005/12/26      *
  //*---------------start-------------------*
        $C5: //zero page
			begin

				taddr:=ZpAddress(pc);
				tempbyte:=memread(taddr);
{$IFDEF debug}
				curIns := 'CMP $' + intToHex(taddr, 0);
{$ENDIF}


				tempflag:=Ps.off;

				acc := a;
                psw := psTopsw;
                asm
					mov ah,psw
					sahf
					mov al,acc
					cmp al,tempbyte
					cmc
					lahf
					mov psw,ah
                end;
                pswTops(psw);
				Ps.off:=tempflag;

                inc(cycles, 3);
                inc(pc, 2);

            end;
  //*                                       *
  //*       cmp instruction 2005/12/26      *
  //*---------------end---------------------*


  //*                                       *
  //*       cmp instruction 2005/12/26      *
  //*---------------start-------------------*
		$D5: //zero page x
			begin

				taddr:=IzpAddress(pc,x);
				tempbyte:=memread(taddr);
{$IFDEF debug}

⌨️ 快捷键说明

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