How to achieve double buffering in 8bpp mode:
So, as many of you are aware, the LCD supports changing the LCD base address in order to achieve double buffering. This is a lot more useful than copying the data from the buffer to the screen, as you can simply swap the buffers. However, it is not a simple as setting the new base address and continuing perfectly. In layman's terms there is a time difference between when the address is changed to when it actually has any effect on the screen. Basically, a wait time, kind of like the old LCD I guess. Luckily there are some useful interrupts that can be taken advantage of, and plus the ez80 processor interrupts don't have to be enabled for the LCD controller to trigger them. So, here we go:
Near the beginning of your code, setup the 8bpp mode, and set the LNBUIM bit (2) in the Interrupt Mask Set/Clear Register. The LNBUIM bit(2) tells the controller to generate an interrupt when the LCD base address can be updated (Halfway through a frame redraw). LCDIMSC is the interrupt controller register.
Code: di
ld a,(LCDIMSC)
or %00000100
ld (LCDIMSC),a
ld a,lcdBpp8
ld (mpLcdCtrl),a
Now, whenever you want to update the screen, just call this function:
Code: updateScrn:
ld hl,vBuf1
ld de,(LCDUPBASE)
or a,a
sbc hl,de
add hl,de
jr nz,+_
ld hl,vBuf2
_:
ld (currentDrawingBuffer),de
ld de,LCDICR
ld a,(de)
or %00000100
ld (de),a
ld (LCDUPBASE),hl
_:
ld a,(LCDRIS)
and %00000100
jr z,-_
ret
LCDUPBASE is the address of the LCD base (It's upper because of the style of this LCD). LCDICR is the Interrupt Clear Register; we need to clear the fact that the LCD base address ha not been yet copied to the LCD's current address. LCDRIS is the Raw Interrupt Status register, this tells us if it is okay to update the LCD address (Otherwise is is probable you may get some flicker).
Here are all the defines you will need:
Code: #define LCDUPBASE 0E30010h
#define LCDIMSC 0E3001Ch
#define LCDRIS 0E30020h
#define LCDICR 0E30028h
#define vBuf1 0D40000h
#define vBuf2 0D52C00h
Hope this helps, and I can't wait to see what you come up with!