CEmu icon indicating copy to clipboard operation
CEmu copied to clipboard

LCD interrupt timing is a little bit off

Open runer112 opened this issue 7 years ago • 4 comments

I wrote a program to measure the number of cycles between LCD interrupts. I noticed that, although the total time spent on a frame seems right, the exact timing of the different LCD interrupts is not.

The program prints 5 numbers. They measure the number of cycles between the vsync (vcomp) interrupt and:

  1. (next) vsync
  2. back porch
  3. active video
  4. front porch
  5. base address update

There is some additional overhead captured in the measurement as well, but that wouldn't explain the difference observed. Apart from some small deviations in the first measurement, the other measurements are consistent across runs on both hardware and CEmu.

Results on real hardware (default TI-OS timing):

lcd_timing_real

Results on CEmu:

lcd_timing_cemu

If you'd like to test this yourself, following is the source code for the program I created. Assemble with spasm-ng.

.nolist
#include "ti84pce.inc"
.list

.db tExtTok,tAsm84CeCmp
.org userMem

	call _HomeUp
	ld bc,(lcdPwr|lcdBgr)|(lcdIntVcomp)
loop:
	push bc
	call test
	pop bc
	ld a,b
	add a,1<<4
	bit 6,a
	ld b,a
	jr z,loop
	ld c,lcdIntLNBU
	call test
	call _usb_ResetTimer
	jp _GetKey

test:
	di
	ld a,(lcdPwr|lcdBgr)>>8
	ld (mpLcdCtrl+1),a
	ld hl,tmr1CountUp
	ld (mpTmrCtrl),hl
	ld de,17
	ld h,d
	ld (mpTmr1Counter),hl
	ld hl,mpLcdIcr
	ld (hl),lcdIntVcomp
waitforstart:
	ld a,(mpLcdRis)
	and a,lcdIntVcomp
	jr z,waitforstart
	ld a,tmr1Enable
	ld (mpTmrCtrl),a
	ld (hl),c
	ld l,lcdCtrl+1
	ld (hl),b
	sbc hl,hl
wait:
	add hl,de
	jr c,timeout
	ld a,(mpLcdRis)
	and a,c
	jr z,wait
	ld hl,(mpTmr1Counter)
	call _DispHL
timeout:
	jp _NewLine

runer112 avatar Feb 17 '18 20:02 runer112

Are you sure that this isn't caused by usb dma? It appears in the first screenshot that the calculator was plugged into the computer.

mateoconlechuga avatar Feb 18 '18 20:02 mateoconlechuga

Rerunning the program on hardware with the USB cable disconnected gives the same results.

runer112 avatar Feb 18 '18 20:02 runer112

So these numbers: 41 36 -6 -6 -66 correspond to the differences. When added together and accounting for difference, this results in 0. It does show that the time spent in each frame is correct; there just appears to be a number that is skewing these results. I believe this is more related to the timer issues than LCD issues.

mateoconlechuga avatar Mar 28 '18 22:03 mateoconlechuga

Tried the program today on latest CEmu master (with SPI), here's a comparison from @runer112's value on the left:

February June
lcd_timing_cemu issue198

So apparently, some got better and some got worse.

On calc (rev E), got the same numbers as @runer112 ; screenshot here again for easier comparison: lcd_timing_real

adriweb avatar Jun 03 '18 07:06 adriweb