How can I improve this pixel buffer program?

3

GAMELEGEND 2026-07-08 04:29

One thing I have noticed is when the pixels are being set to the fourth color in the palette without a WAIT VBL command you can see the pixels get set to the second color in the palette before they get set to the fourth color.

Pixel.nx | Open in app
2026-07-08 04:29

SP4CEBAR 2026-07-10 10:28

If you remove wait vbl then vbl will interrupt the code when it is time to draw a frame, this is likely why you see it being set to the second color

Perhaps your code, sets one bit before the other so that the second color appears before the fourth if vbl interrupts in between

For bug fixes and optimizations you can always ask AI, chatgpt knows how to write NX code


SP4CEBAR 2026-07-10 10:37

I've analysed your code and found that your code has to write to the pixel buffer three times if it wants to set a pixel to pixel_color 3

If vbl interrupt happens in between the second and last pixel buffer writes then you get the behavior you described


SP4CEBAR 2026-07-10 10:41 (Edited)

Here's my pixel buffer if you want to look at it


SP4CEBAR 2026-07-10 10:49

my program has this subprogram to achieve overlays (though it costs petformance to use subprograms)

SUB OVERLAY2_FASTER(A0,N,C0,C1)
  A1=A0+8
  M=255 XOR N
  POKE A0,(PEEK(A0) AND M) OR C0*N
  POKE A1,(PEEK(A1) AND M) OR C1*N
END SUB


*^~ I| Raichu |I ~^* 2026-07-10 15:34

jesus, chat gpt knows how to code in .nx? that’s bad, considering that means your’s, mine’s, and everybody else’s code has been fed into it.


*^~ I| Raichu |I ~^* 2026-07-10 15:34

jesus, chat gpt knows how to code in .nx? that’s bad, considering that means your’s, mine’s, and everybody else’s code has been fed into it.


GAMELEGEND 2026-07-10 22:25 (Edited)

I realized that if I want to clear a pixel(set it to color 0) then I can OR the value of the row of eight pixels AKA PEEK(FRAMEBUFFER_MEM_ADDR(X, Y)) with BITMASK(X) and then AND the result with NOT BITMASK(X) and it will give me a 0 wherever I want and will not mess with the other 7 bits.

for example:

X = 0, Y = 0
PEEK(FRAMEBUFFER_MEM_ADDR(X, Y)) = %11111111
BITMASK(X) = %10000000

so (PEEK(FRAME_MEM_ADDR(X, Y) OR BITMASK(X)) AND (NOT BITMASK(X)) = (%11111111 OR %1000000) AND %01111111 = %11111111 AND 01111111 = %01111111

and if I want a 1 wherever I want all I have to do is AND (PEEK(FRAMEBUFFER_MEM_ADDR(X, Y)) OR BITMASK(X)) with %11111111


GAMELEGEND 2026-07-10 22:28

I really don't know what I was thinking when I was making the SET_PIXEL sub program but then I had an interesting idea and here is the new function

SUB SET_PIXEL2(X, Y, PIXEL_COLOR)
  IF (PIXEL_COLOR < 0) OR (PIXEL_COLOR > 3) THEN EXIT SUB

  POKE FRAMEBUFFER_MEM_ADDR(X, Y), (PEEK(FRAMEBUFFER_MEM_ADDR(X, Y)) OR BITMASK(X)) AND LOW_BYTE_COLOR(X MOD 8, PIXEL_COLOR)
  POKE FRAMEBUFFER_MEM_ADDR(X, Y)+8, (PEEK(FRAMEBUFFER_MEM_ADDR(X, Y)+8) OR BITMASK(X)) AND HIGH_BYTE_COLOR(X MOD 8, PIXEL_COLOR)
END SUB

I don't know how efficient it is because I have not done much testing yet.

Pixel.nx | Open in app
2026-07-10 22:28

Log in to reply.