OpenCores
Issue List
DJNZ/DEC fails #10
Open gryzor opened this issue over 5 years ago
gryzor commented over 5 years ago

Instruction DJNZ fails like this:

ADDR Instruction

00E6 ld bc,$0000 00E9 djnz $00E9 00EB di 00EC dec c 00ED jr nz,$00E9

TV80 does not loop around 00E9 but just continues on to 00EB.

I simulated this with iVerilog. I can provide waveforms if you contact me.

Thanks.

gryzor commented over 5 years ago

I set up the same simulation with Verilator and it ran correctly. Still, there might be something not very standard-ish in the verilog code if two verilog simulators produce different results.

gryzor commented over 5 years ago

I was wrong: it fails with Verilator too. It seems that the problem is related to the use of a clock enable. DJNZ runs correctly if the input "cen" is set to 1'b1, and fails if the input is a clock enable signal, that effectively halves the clock rate. The clock enable toggles on the negative edge of the original clock.

So this is a genuine bug.

gryzor commented over 5 years ago

The problem is in file tv80s.v, the tstate always block is not gated by the cen signal, so the tstate advances even when clock enable is low.

To solve it just add a "if (cen)" in that block. Exactly, make line 107:

  else if(cen)

instead of

  else

and that solves the problem.

ghutchis commented about 5 years ago

Sorry for late reply but you have already tracked down the source of the bug. This repository is no longer maintained, the maintained version is now on github: https://github.com/hutch31/tv80

In the github version of the code cen is tied to 1 in tv80s (I have never used clock enable in any of my implementations).

ghutchis was assigned about 5 years ago

Assignee
ghutchis
Labels
Bug