discolando
Member
Are there any tried-and-true (and fast) routines available online for Turbo C 2.01 for copying a full 16k buffer to CGA video RAM? Either native C or ASM is fine. Thanks!
.8086
.model compact
.code
public _copyBuffer2Video
_copyBuffer2Video proc near
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
_copyBuffer2Video endp
end
void copyBuffer2Video (char *buffer);
#include <mem.h>
copyBuffer2Video_PureC (char *buffer)
{
char far *vbufCGA = (char far *) 0xb8000000;
memcpy (vbufCGA, buffer, 0x4000);
}
char buffer[16384];
char *buffer;
#include <stdlib.h>
buffer = malloc (0x4000);
#include <bios.h>
#include <stdlib.h>
#define Enter_Key 0x0d
void copyBuffer2Video(char *buffer);
void setGraphicsMode();
void setTextMode();
char *buffer;
void waitForEnter()
{
unsigned char keycode;
unsigned char ckeycode;
do {
keycode = bioskey(0);
ckeycode = keycode & 0xFF;
} while (ckeycode != Enter_Key);
}
void main()
{
int x;
setGraphicsMode();
buffer = malloc (0x4000);
for (x = 0; x < 16384; x++) {
buffer[x] = 0xAA;
}
copyBuffer2Video(buffer);
waitForEnter();
for (x = 0; x < 16384; x++) {
buffer[x] = 0x55;
}
copyBuffer2Video(buffer);
waitForEnter();
free(buffer);
setTextMode();
}
tasm /ml cga
c:\tc\tcc -c -mc test.c
c:\tc\tlink test cga c:\tc\lib\c0c.obj,,,c:\tc\lib\cc.lib
At least on my computer, it works. Just in case, remember to compile the C file also in Compact model.
Doesn't TCC have an inline assembly feature (sorry, I'm a MSC user)? It should be possible to include this in your code and automatically handle the model size issue. The code's pretty much a rep movsw.
I wonder how the assembly version would compare with the memcopy() intrinsic? MSC can inline this function into a movsb+movsw pair.
Chuck(G) said:Doesn't TCC have an inline assembly feature (sorry, I'm a MSC user)? It should be possible to include this in your code and automatically handle the model size issue. The code's pretty much a rep movsw.
discolando said:What modifications would I need to make to have it work as expected with other memory models?
_copyBuffer2Video proc near
ARG buffer: dword
push bp
mov bp,sp
mov si,offset [buffer]
mov ax,0b800h
mov es,ax
xor di,di
mov cx,2000h
rep movsw
pop bp
ret
_copyBuffer2Video endp
_copyBuffer2Video proc far
mov ax,0B800h
mov ds,ax
mov si,s_offset //ds:si SCREEN
les di,[spritedata] //es:di Sprite data array
//even lines
//process one byte (4 pixels)
mov al,byte ptr es:[di] //get sprite mask
inc di
mov bl,byte ptr es:[di] //get sprite data
inc di
mov ah,byte ptr ds:[si] //get screen data, sprite data will be pasted on top
and ah,al //screen data = screen data AND mask
or ah,bl //masked screen data = masked screen data OR sprite byte
mov byte ptr ds:[si],ah //paste processed byte to screen
inc si //go to next byte
//Now you'll process (for example) 4 bytes for a 16x16 sprite and then go to next line
add si,80-4
//Next line...
//Finally draw 8 even lines and jump to the odd ones
add si,Odd_Lines address //= something like 80*100, I can't remember.