I'm using VESA modes 10Eh and 111h. In real mode bank switching is slow, but a necessary evil. So, instead of calling the ISR via an interrupt I figured that a far call would be faster.
Obviously I was wrong. Why is the far call slower than the interrupt when interrupts are known for being notoriously slow?
Here is my code:
Code:
void far (*VideoINT)();
void far *ISR;
int main(void)
{
WORD vidoffset
WORD vidsegment
asm
{
mov ax,0
mov es,ax
mov [vidoffset],es:[010h*4]
mov [vidsegment],es:[010h*4+2]
}
ISR=MK_FP(vidsegment,vidoffset);
(void far *)VideoInt=(void far *)ISR;
...
... //this portion sets up the rendering system
... //Not relevant to question, didn't include
return 0;
}
so for bank switch:
Code:
void PlotPixel(DWORD offset,WORD color)
{
static WORD bank;
WORD actualoffset=offset & 0xFFFF;
WORD curbank=offset>>16;
asm
{
START:
mov ax,[curbank]
cmp ax,[bank]
jz PLOTPIXEL
BANKSWITCH:
mov ax,04f05h
mov bx,0
mov dx,[curbank]
push dx //Preserve dx across call
call VideoINT //far call to int 10 based on int vector table
pop dx
mov [bank],dx //Set bank to curbank
PLOTPIXEL:
mov ax,0a000h
mov es,ax
mov di,word(actualoffset)
mov ax,color
stosw
}
}
If I was to replace call VideoINT with int 10h, the entire function is faster.
This does not make sense to me. It is faster to plot pixels via a far pointer than to use an ISR to do so. Why isn't it faster to call the INT 10 ISR instead of invoking it via an interrupt? I thought this would be a way to circumvent the slow bank switch interrupt call, but I guess not.
I'm also only specifying 0 in BX because it is too slow to call or invoke the ISR twice for 0 and 1. Besides, it works fine just using 0, so I left it.
Never mind....I'm so careless. In my actual code I forgot to preserve dx across the call. So when I called the ISR, dx was obviously changed. When I assigned dx to curbank, dx did not really represent the correct bank. This forced a bank switch on every single pixel (hitting myself in the head). Sorry everyone, but I figured it out amidst writing this.
Well, anyways, this is a fast plot pixel function for VESA modes.
For those that don't like or know assembly (mine is far from perfect) this can be done in C as well.