diff --git a/pipelined-cpu/srcs/board/cpu21_board_top.v b/pipelined-cpu/srcs/board/cpu21_board_top.v index a3c5ec0..0e55cce 100644 --- a/pipelined-cpu/srcs/board/cpu21_board_top.v +++ b/pipelined-cpu/srcs/board/cpu21_board_top.v @@ -180,7 +180,14 @@ module cpu21_board_top #( wire frame_tick; wire [15:0] sw_vec = {12'b0, sw_flag, irq_sw}; // 中断连线:SW0 与鼠标共用一个入口,SW1 与"关卡入口"共用一个入口。 - wire [2:0] irq_vec = {irq_sw[2], (level_irq | irq_sw[1]), (mouse_irq | irq_sw[0])}; + // 中断线对应关系(必须与 saolei/sw/linker.ld、mmio.h 的约定一致): + // irq_vec[0] = IRQ1 -> 入口 0x100 = 关卡(游戏),由 LEVEL 软件中断拉起 + // irq_vec[1] = IRQ2 -> 入口 0x200 = 鼠标读取,由事件 FIFO 非空拉起 + // irq_vec[2] = IRQ3 -> 入口 0x300 = 备用 + // (原来 mouse 接在 [0]、level 接在 [1],正好对调:第一个鼠标事件会跳进关卡 + // 入口把棋盘画出来,而鼠标 ISR 永不执行,FIFO 不弹空、中断线恒高 —— 于是 + // 只能收到一次事件。拨码开关 SW[2:0] 仍按位 OR 进来,兼容原中断测试程序。) + wire [2:0] irq_vec = {irq_sw[2], (mouse_irq | irq_sw[1]), (level_irq | irq_sw[0])}; // --------------------------------------------------------------------------- // 指令 ROM:组合读(未用到的地址填 NOP) @@ -195,6 +202,7 @@ module cpu21_board_top #( // 扫雷程序(由 saolei/tools/build.ps1 生成的 cpu21_saolei_rom.vh)。 // 综合/仿真时定义宏 SAOLEI_ROM 即可切换到这个程序;不定义就是下面的跑马灯。 `include "cpu21_saolei_rom.vh" + `elsif RISC_V_INTRUPT_CCAB_ROM // 中断综合测试程序:三个中断入口由镜像中的实际标签位置决定。 `include "risc-v-intrupt-ccab.vh" diff --git a/pipelined-cpu/srcs/rtl/cpu21_mmio.v b/pipelined-cpu/srcs/rtl/cpu21_mmio.v index dbd5b80..a8b3a13 100644 --- a/pipelined-cpu/srcs/rtl/cpu21_mmio.v +++ b/pipelined-cpu/srcs/rtl/cpu21_mmio.v @@ -35,8 +35,8 @@ // 同一块 RAM),读操作把 fb_rdata_i 组合回读数据,保持"组合读"的时序不变。 // // 两个中断源: -// mouse_irq_o = 中断使能 && 事件 FIFO 非空(接 irq_i[0]) -// level_irq_o = LEVEL 寄存器(软件中断,接 irq_i[1],用来"进入关卡") +// mouse_irq_o = 中断使能 && 事件 FIFO 非空(顶层接到 irq_i[1] = IRQ2 = 入口 0x200) +// level_irq_o = LEVEL 寄存器(软件中断,顶层接到 irq_i[0] = IRQ1 = 入口 0x100 = 关卡) // // 以后要增加外设(UART、SD 卡等)时只需在这里扩展地址译码。 // ----------------------------------------------------------------------------- diff --git a/pipelined-cpu/srcs/rtl/cpu21_pointer.v b/pipelined-cpu/srcs/rtl/cpu21_pointer.v index 969e41c..265eacc 100644 --- a/pipelined-cpu/srcs/rtl/cpu21_pointer.v +++ b/pipelined-cpu/srcs/rtl/cpu21_pointer.v @@ -76,16 +76,20 @@ module cpu21_pointer #( reg [4:0] sel; always @* begin sel = 5'b0; + // 注意:sel 的每一位必须和下面的输出一致,也必须和 pend_next 一一对应! + // sel[4]=点击 sel[3]=上(-dy) sel[2]=下(+dy) sel[1]=左(-dx) sel[0]=右(+dx) + // 而且 press_pend_q <= pend_next & ~sel 要求 sel 的位数与 pend_next 同域, + // 否则被选中的那一位清不掉、ev_valid_o 会永久为 1(中断线一直挂着)。 if (pend_next[4]) sel = 5'b10000; // BTNC:点击 else if (pend_next[3]) - sel = 5'b01000; // BTNU:上 + sel = 5'b01000; // BTNU:上 else if (pend_next[2]) - sel = 5'b00010; // BTND:下 + sel = 5'b00100; // BTND:下 else if (pend_next[1]) - sel = 5'b00001; // BTNL:左 + sel = 5'b00010; // BTNL:左 else if (pend_next[0]) - sel = 5'b00100; // BTNR:右 + sel = 5'b00001; // BTNR:右 end always @(posedge clk or posedge reset) begin