Khatoblepas
New Member
- Joined
- Sep 3, 2025
- Messages
- 6
I'm currently writing a game in Turbo C using CGA graphics, and I've run into a really annoying problem with writing to the screen. I'm using a double buffer that I write to and then copy it to the screen to update it, but at my current skill level, I can't figure out how to only update the bits of the screen I've changed. I can do it in C, but then it's super slow and causes there to be giant holes in the screen where it isn't updated, and copying the entire buffer multiple times a second can't be right.
I'd like to implement some kind of dirty rectangle system, but I need some help modifying the asm that pushes the data to video ram.
Here's the current buffer copying code:
I'd like for it to only copy a set rectangle, so probably:
- set starting position to (Y*80+x)
- mov width/4 bytes
- skip ahead 80-width/4 bytes.
- repeat for 1/2 height.
- skip ahead 0x8000 bytes from (y*80+x).
- repeat the above for the other 1/2 height.
If it has to round up so it draws one extra row or byte it doesn't matter.
But thinking about how to juggle this in assembler gives me a headache. I'm not sure I have enough registers to hold everything in. Is this even the right direction to go in? All I want is to be able to draw to the screen fast so I can work on an animation system. If anyone knows how I should go about writing it in assembler I'd be eternally grateful. Does anyone have any other advice on CGA programming? I've got sprites I can draw at an arbitrary place on the screen, a tile engine, it's just very very slow at the moment.
I'd like to implement some kind of dirty rectangle system, but I need some help modifying the asm that pushes the data to video ram.
Here's the current buffer copying code:
Code:
public _cgaCopyBuffer
_cgaCopyBuffer proc far
ARG buffer: dword
push bp
mov bp,sp
push ds
lds si,[buffer]
mov ax,0b800h
mov es,ax
xor di,di
mov cx,2000h
rep movsw
pop ds
pop bp
ret
_cgaCopyBuffer endp
I'd like for it to only copy a set rectangle, so probably:
- set starting position to (Y*80+x)
- mov width/4 bytes
- skip ahead 80-width/4 bytes.
- repeat for 1/2 height.
- skip ahead 0x8000 bytes from (y*80+x).
- repeat the above for the other 1/2 height.
If it has to round up so it draws one extra row or byte it doesn't matter.
But thinking about how to juggle this in assembler gives me a headache. I'm not sure I have enough registers to hold everything in. Is this even the right direction to go in? All I want is to be able to draw to the screen fast so I can work on an animation system. If anyone knows how I should go about writing it in assembler I'd be eternally grateful. Does anyone have any other advice on CGA programming? I've got sprites I can draw at an arbitrary place on the screen, a tile engine, it's just very very slow at the moment.