CE-Programming / CEmu

Third-party TI-84 Plus CE / TI-83 Premium CE emulator, focused on developer features
https://ce-programming.github.io/CEmu/
Other
1.1k stars 77 forks source link

LCD interrupt timing is a little bit off #198

Open runer112 opened 6 years ago

runer112 commented 6 years ago

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
mateoconlechuga commented 6 years ago

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.

runer112 commented 6 years ago

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

mateoconlechuga commented 6 years ago

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.

adriweb commented 6 years ago

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