fix(saolei): 修好鼠标事件链路三处 RTL bug —— 仿真里扫雷已能正常游玩

1) cpu21_pointer.v: sel 的位映射写错了(pend[2]->bit1, pend[1]->bit0, pend[0]->bit2),
   而输出读的是 sel[1]=-dx / sel[2]=+dy / sel[3]=-dy / sel[0]=+dx。
   后果:方向全乱(按下变左移、按右变下移),更致命的是清除逻辑
   press_pend_q <= pend_next & ~sel 清不掉被选中的那一位 -> ev_valid_o 永久为 1
   -> 鼠标中断线一直挂着 -> CPU 只收到一个上升沿、之后再无事件。改成一一对应。
2) cpu21_board_top.v: 鼠标中断与 LEVEL 软件中断的接线正好对调
   (mouse 接 irq_vec[0]=IRQ1=0x100=关卡入口, level 接 irq_vec[1]=IRQ2=0x200=鼠标)。
   后果:第一个鼠标事件把关卡叫起来画棋盘, 而鼠标 ISR 永不执行 -> FIFO 不弹空。
   按 linker.ld/mmio.h 约定交换;拨码开关 SW[2:0] 仍按位 OR 进来。
3) cpu21_mmio.v: 同步中断线注释。

仿真验证(tb_saolei + fb2png): 事件队列正常出入(h/t 同步增长)、光标方向正确、
点击 START 进关卡、关卡内点击揭开格子(fb_we +90)、数字场 1/2/3 与大片 BFS 展开均正确
This commit is contained in:
2026-09-19 19:33:18 +08:00
parent 3f765ae4c5
commit 47d2f22d07
3 changed files with 19 additions and 7 deletions
+9 -1
View File
@@ -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"
+2 -2
View File
@@ -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 卡等)时只需在这里扩展地址译码。
// -----------------------------------------------------------------------------
+8 -4
View File
@@ -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