We're on Discord! Please join our server now if you don't want to miss anything! (More info) | Join the UCC4 contest! (More info)

* WalrusIRC (More rooms available on our Discord server)

Author Topic: Double buffering makes program slow & visual artifacts for each render.  (Read 1565 times)

0 Members and 1 Guest are viewing this topic.

Offline Midnightas

  • New User
  • Join Date: Feb 2018
  • Location:
  • Posts: 7
  • Post Rating Ratio: +0/-0
  • Making hello worlds since 10.
    • @UCt26YFLiAK1T3b3o-1IZXKw
    • @midnightas
I added double buffering into my program, as before you could see it rendering visually and flickering.
But now with double buffering, half of the screen flickers (not exactly half, I can't find a pattern, but it's mostly pixels at the bottom), and it now takes around half a second to render, before the buffers are swapped again.
I'm assuming this is because we wait for the interrupt, but it still seems to be very long.
Code: [Select]
call SJQ_setgraphics
loop:
; Simple buffer cleaning, sets everything to 0.
ld HL, (SJQ_curbuf)
ld (HL), 0
ld DE, (SJQ_curbuf)
inc DE
ld BC, 320 * 240 - 1
ldir

; do some more drawing here.

call SJQ_bufswap

SJQ_setgraphics:
; Sets the palette.
ld HL, SJQ_PALETTE
ld DE, $E30200
ld BC, SJQ_PALETTE_END - SJQ_PALETTE
ldir
; Enables 8bpp.
ld A, $27
ld ($E30018), A
; Sets up double buffering.
ld HL, vRam
ld (mpLcdBase), HL
ld hl, vRam + 320 * 240
ld (SJQ_curbuf), HL
ld HL, mpLcdImsc
ld (HL), 4
ret

SJQ_bufswap:
ld HL, (SJQ_curbuf)
ld DE, (mpLcdBase)
ld (SJQ_curbuf), DE
ld (mpLcdBase), HL
_:
ld HL, mpLcdIcr
set 2, (HL)
ld HL, mpLcdRis
_:
bit 2, (HL)
jr Z, -_
ret

SJQ_bufwap, the third third of SJQ_setgraphics are all that work on the double buffering, of course I found little docs on the internet (searching stuff like 'double buffering ti', or using exact matching, etc).
« Last Edit: December 24, 2018, 05:06:39 pm by Midnightas »



Offline c4ooo

  • Pedanticity prevents ambiguity
  • Super User
  • CW Contest II Winner
  • *
  • Join Date: Aug 2015
  • Location: 127.0.0.1
  • Posts: 1040
  • Post Rating Ratio: +13/-4
  • Advanced forumer
  • Gender: Male
Your code... all seems correct (checked it against the code I normally use).
Can you post your entire code; I could try to make it work.

Offline Midnightas

  • New User
  • Join Date: Feb 2018
  • Location:
  • Posts: 7
  • Post Rating Ratio: +0/-0
  • Making hello worlds since 10.
    • @UCt26YFLiAK1T3b3o-1IZXKw
    • @midnightas
Here's a repo I just setup: https://gitlab.com/midn/sjq

Thanks for your help!

Offline c4ooo

  • Pedanticity prevents ambiguity
  • Super User
  • CW Contest II Winner
  • *
  • Join Date: Aug 2015
  • Location: 127.0.0.1
  • Posts: 1040
  • Post Rating Ratio: +13/-4
  • Advanced forumer
  • Gender: Male
This bug was.. interesting to track down haha. Seems like spasm interprets the following line:  (line 51 in main.asm)
ld hl, vRam + 320 * 240
as
ld hl, (vRam + 320) * 240
instead of
ld hl, vRam + (320 * 240)
and changing it to either
ld hl, vRam + (320 * 240)
or
ld hl, vRam + 76800
fixed the problem for me ;)
« Last Edit: December 29, 2018, 10:19:47 pm by c4ooo »

Offline Midnightas

  • New User
  • Join Date: Feb 2018
  • Location:
  • Posts: 7
  • Post Rating Ratio: +0/-0
  • Making hello worlds since 10.
    • @UCt26YFLiAK1T3b3o-1IZXKw
    • @midnightas
Wow, I blame the tools. Thank you so much for using your free time on this issue!

Offline Midnightas

  • New User
  • Join Date: Feb 2018
  • Location:
  • Posts: 7
  • Post Rating Ratio: +0/-0
  • Making hello worlds since 10.
    • @UCt26YFLiAK1T3b3o-1IZXKw
    • @midnightas
Slight additional question, if I may, but if I wanted to add the ability to draw transparent sprites, I'm assuming I'll have to lose the ldir instruction?
One way I see going about this is to use ldi in a loop instead (which checks if it's equal to some "transparent" value).

Offline c4ooo

  • Pedanticity prevents ambiguity
  • Super User
  • CW Contest II Winner
  • *
  • Join Date: Aug 2015
  • Location: 127.0.0.1
  • Posts: 1040
  • Post Rating Ratio: +13/-4
  • Advanced forumer
  • Gender: Male
Slight additional question, if I may, but if I wanted to add the ability to draw transparent sprites, I'm assuming I'll have to lose the ldir instruction?
One way I see going about this is to use ldi in a loop instead (which checks if it's equal to some "transparent" value).
Makes sense. You might want to take a look at https://github.com/CE-Programming/toolchain/blob/master/src/graphx/graphx.asm#L2177 and the other functions in that document.

 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games