From 97649fedb7865d889dab2e20139bc887d871ed00 Mon Sep 17 00:00:00 2001 From: Joshua Wise Date: Sat, 29 Mar 2008 04:12:10 -0400 Subject: [PATCH 1/1] PUSH and POP work --- FPGABoy.ise | Bin 162780 -> 162762 bytes GBZ80Core.v | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++-- rom.hex | 7 ++-- 3 files changed, 105 insertions(+), 6 deletions(-) diff --git a/FPGABoy.ise b/FPGABoy.ise index 5a47155ec16ce79f541ac5154e5b64947b0b0e51..7770eb008676e674792cd2feea4e53b9fad09ccc 100644 GIT binary patch delta 3072 zcma)8YgAKL7QQ=PVgThK1pz4rh^_JpAOo>jq`cy5GNZfBE!sCmr%>rq`J9_TyaVlmd6zNeK|k zjlXCqfjCYo4+Gmc14rS{luP3$_$6GdOBhAqF*hasyzF)c;xSv1NjX0$SSqZQt~Nlu zW3Ydoj}u%oc2e$Ss--IoMbjjPm99bOmp*_5?&M2r0TS@p%d@GX-Te1vK%Y@W`2}}i zeleh{yJ801FlK%Jhmr1RI^pkycen@c)O-Rudr~<(=}A3t%e_4GsT^-Pp7dTpg&%n9 z%!iG0CtBt_w~f805|&C6|miQjlnYG0NqBq*8^M? zxEkvM{iwuHV4j|kyeLzzx2O;>IcN;mEj~eAJX>6+uhj@bRY{i_ zM0eg|!r2Rk>!4sJR!R|}Pk`DT4ZlW-EfG5NAEmJdfbs-hh(s!~O5I8!oZYfyGb^94 zEyLy`qfcJ`RknKk#b1wbg>liWRZdjLD|wN@^}jW#o6c@M|0y?;P+<{rJSx;OEWaRa z=d_{sHs5Kfj0{g)zqfg%OZ%JgPv8D7`uM}~lDGQyMg|vuUJ=n$zILoiY1El3$AbIk zJoynvYUOBO7tMN&HXh`%>VmB#x)7|nSZ1YrjbAqNPa_y6gaIi&Y*OIvrW7+{p)?oo zH60W}at`yGvn9HvIM!Tlrpq(1k5*u53k4ZN7M0%~v@(WAR`S}8Sl*(*v2VjAx;+?h z=`#Ud;D*;PiSYa)9`25VmlR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Qrpk0_Y8Yd%F zF5vyv6)ke3?fH3(F6$(T_kfQDMg2>1!2@O&!k32LXiMUrzc|)1GnHu?Yf<$8|IdL& z84q82N-}Q@3sOx{reBSR-@G|Kh7@^1nNSpWns|Fbo`Ch2$UZL!)rdbW5M~lJCbqDT zVj9L+3w%`a>x`gcbGKDpr|Nu<-mr-zb*Yv8EG^zbk;Hy!>YogNty zLb!C;V|WTB1sSl#@HCD5I|DZJw2f<_)M%1q8Uv=16PZwINoiBJk+W;SUArg?_E7oA zY2n(=9PrRMW@FjA6z3eGuv;&<-sJ9JEjPnf_; q^h`|8-xQm^J}px*IX?Eoh~Qbd8`Fb6c~^VlG{~=8HUCyZRsRoJ$dkJO diff --git a/GBZ80Core.v b/GBZ80Core.v index fa9ed0b..cb80cb8 100644 --- a/GBZ80Core.v +++ b/GBZ80Core.v @@ -28,6 +28,8 @@ `define INSN_LD_reg_reg 8'b01xxxxxx `define INSN_LD_reg_imm16 8'b00xx0001 `define INSN_LD_SP_HL 8'b11111001 +`define INSN_PUSH_reg 8'b11xx0101 +`define INSN_POP_reg 8'b11xx0001 `define INSN_reg_A 3'b111 `define INSN_reg_B 3'b000 `define INSN_reg_C 3'b001 @@ -40,6 +42,10 @@ `define INSN_reg16_DE 2'b01 `define INSN_reg16_HL 2'b10 `define INSN_reg16_SP 2'b11 +`define INSN_stack_AF 2'b11 +`define INSN_stack_BC 2'b00 +`define INSN_stack_DE 2'b01 +`define INSN_stack_HL 2'b10 module GBZ80Core( input clk, output reg [15:0] busaddress, /* BUS_* is latched on STATE_FETCH. */ @@ -101,6 +107,10 @@ module GBZ80Core( if (rd) rdata <= busdata; buswr <= 0; busrd <= 0; + wr <= 0; + rd <= 0; + address <= 16'bxxxxxxxxxxxxxxxx; // Make it obvious if something of type has happened. + wdata <= 8'bxxxxxxxx; state <= `STATE_EXECUTE; end `STATE_EXECUTE: begin @@ -163,7 +173,7 @@ module GBZ80Core( case(cycle) 0: begin address <= {registers[`REG_H], registers[`REG_L]}; - wr <= 0; rd <= 1; + rd <= 1; end 1: begin tmp <= rdata; @@ -202,8 +212,6 @@ module GBZ80Core( `INSN_LD_SP_HL: begin case (cycle) 0: begin - rd <= 0; - address <= 16'bxxxxxxxxxxxxxxxx; tmp <= registers[`REG_H]; end 1: begin @@ -213,6 +221,51 @@ module GBZ80Core( end endcase end + `INSN_PUSH_reg: begin /* PUSH is 16 cycles! */ + case (cycle) + 0: begin + wr <= 1; + address <= {registers[`REG_SPH],registers[`REG_SPL]}-1; + case (opcode[5:4]) + `INSN_stack_AF: wdata <= registers[`REG_A]; + `INSN_stack_BC: wdata <= registers[`REG_B]; + `INSN_stack_DE: wdata <= registers[`REG_D]; + `INSN_stack_HL: wdata <= registers[`REG_H]; + endcase + end + 1: begin + wr <= 1; + address <= {registers[`REG_SPH],registers[`REG_SPL]}-1; + case (opcode[5:4]) + `INSN_stack_AF: wdata <= registers[`REG_F]; + `INSN_stack_BC: wdata <= registers[`REG_C]; + `INSN_stack_DE: wdata <= registers[`REG_E]; + `INSN_stack_HL: wdata <= registers[`REG_L]; + endcase + end + 2: begin /* TWIDDLE OUR FUCKING THUMBS! */ end + 3: begin + `EXEC_NEWCYCLE; + `EXEC_INC_PC; + end + endcase + end + `INSN_POP_reg: begin /* POP is 12 cycles! */ + case (cycle) + 0: begin + rd <= 1; + address <= {registers[`REG_SPH],registers[`REG_SPL]}; + end + 1: begin + rd <= 1; + address <= {registers[`REG_SPH],registers[`REG_SPL]}; + end + 2: begin + `EXEC_NEWCYCLE; + `EXEC_INC_PC; + end + endcase + end default: $stop; endcase @@ -308,6 +361,51 @@ module GBZ80Core( end endcase end + `INSN_PUSH_reg: begin /* PUSH is 16 cycles! */ + case (cycle) + 0: begin + {registers[`REG_SPH],registers[`REG_SPL]} = + {registers[`REG_SPH],registers[`REG_SPL]} - 1; + cycle <= 1; + end + 1: begin + {registers[`REG_SPH],registers[`REG_SPL]} = + {registers[`REG_SPH],registers[`REG_SPL]} - 1; + cycle <= 2; + end + 2: cycle <= 3; + 3: cycle <= 0; + endcase + end + `INSN_POP_reg: begin /* POP is 12 cycles! */ + case (cycle) + 0: begin + cycle <= 1; + {registers[`REG_SPH],registers[`REG_SPL]} = + {registers[`REG_SPH],registers[`REG_SPL]} + 1; + end + 1: begin + case (opcode[5:4]) + `INSN_stack_AF: registers[`REG_F] <= rdata; + `INSN_stack_BC: registers[`REG_C] <= rdata; + `INSN_stack_DE: registers[`REG_E] <= rdata; + `INSN_stack_HL: registers[`REG_L] <= rdata; + endcase + {registers[`REG_SPH],registers[`REG_SPL]} = + {registers[`REG_SPH],registers[`REG_SPL]} + 1; + cycle <= 2; + end + 2: begin + case (opcode[5:4]) + `INSN_stack_AF: registers[`REG_A] <= rdata; + `INSN_stack_BC: registers[`REG_B] <= rdata; + `INSN_stack_DE: registers[`REG_D] <= rdata; + `INSN_stack_HL: registers[`REG_H] <= rdata; + endcase + cycle <= 0; + end + endcase + end endcase state <= `STATE_FETCH; end diff --git a/rom.hex b/rom.hex index a90b962..00214cd 100644 --- a/rom.hex +++ b/rom.hex @@ -4,8 +4,8 @@ 01 // LD SP, HL F9 -// LD B, (HL) -46 +// POP BC +C1 // LD A, 12h 3E 12 @@ -20,4 +20,5 @@ F9 76 @100 -56 \ No newline at end of file +00 +56 -- 2.43.0