PIC 24F VGA array addressing instructions

assemblycpic

In order to make a VGA driver for a PIC 24F microcontroller, I am generating an interrupt creating a VSYNC pulse, followed by a loop that puts data to the ports. HSYNC pulses are calculated after this video loop. All timings are correct, and my CRT monitor accepts the generated signal. However, I can only write literal data for the moment, and would like to be able to write arrays filled with data to my screen. This code is currently working:

MOV     #80,W0

VID_LOOP:
    BSET    LATB,#4
    BCLR    LATB,#4
    SUB     #1,W0
BRA     NZ,VID_LOOP  

The B4 port is the R part of my signal, so this loop writes vertical lines on the screen. my W0 reg is loaded with #80, this means 80 lines are written over the screen. This loop is executed 60 times and a front and back porch are added, so I get a resolution of 80*60 PX. So far so good, but this means I only have 2 instructions to load a variable from a screenbuffer array to the port. Does anyone know how I could go about doing this? Maybe my loop could be made shorter?

Best Answer

I've solved it with a macro:

#define showpx asm("   MOV     [W8], W9"); \
    asm("   BTSC    W9,#3"); \
    asm("   BSET    PORTC, #3"); \
    asm("   MOV     W9, PORTB"); \
    asm("   INC2    W8, W8");

and repeated it like this:

#define show8px showpx; showpx; showpx; showpx; showpx; showpx; showpx; showpx;

    show8px show8px show8px show8px show8px show8px show8px show8px show8px show8px

This removes the loop overhead and works perfectly!