Code:
//include these 6 lines if you are using pure asm only, not inline
extern "C"
{
void SetMode(void);
void PlotPixel(int x,int y,unsigned char color,
unsigned char *buffer);
void CLS(unsigned char *buffer);
}
//end of extern block
unsigned char *Screen;
unsigned char *Buffer;
int main(void)
{
Screen=(unsigned char *)MK_FP(0xa000,0);
//Do the buffer here -> whatever you need
SetMode13();
CLS(Screen);
PlotPixel(x,y,15,Screen);
getch(); //So we can see if it works
}
Here is what the pure asm file will look like if you opt for that
In pure assembly using TASM
Code:
.MODEL large
.CODE
public _CLS,_PlotPixel,_SetMode
_SetMode PROC
mov ax,013h
int 10h
ret
_SetMode ENDP
_CLS PROC
ARG buffer:DWORD
push bp
mov bp,sp ;housekeeping for C and ARG
push di ;just in case preserve DI
les di,buffer ;load full pointer into ES:DI
mov al,color ;load color in AL
mov cx,0FA00h ;prepare to block fill 64000 bytes
rep stosb ;do it
pop di ;restore DI
pop bp ;restore bp for C
ret ;return to caller
_CLS ENDP
_PlotPixel PROC
ARG x:WORD,y:WORD,color:BYTE,buffer:DWORD
push bp
mov bp,sp
mov ax,SEG buffer
mov es,ax
mov ax,y
shl ax,6
mov bx,y
shl bx,8
add bx,ax
add bx,x
mov al,color
mov es:[bx],al
pop bp
ret
_PlotPixel ENDP
END
In C using inline assembly
Code:
void SetMode(void)
{
union REG regs;
regs.x.ax=0x13;
int86(0x10,& regs,& regs);
//or
// asm {
// mov ax,013h
// int 10h
// }
}
void PlotPixel(int x,int y,unsigned char *color,
unsigned char *buffer)
{
asm {
mov ax,SEG buffer
mov es,ax
mov ax,y
shl ax,6
mov bx,y
shl bx,8
add bx,ax
add bx,x
mov al,color
mov es:[bx],al
}
}
void CLS(unsigned char *buffer)
{
asm {
push di
les di,buffer
mov al,color
mov cx,0FA00h
rep stosb
pop di
}
}
Incidentally do not use geninterrupt() as it does not preserve the registers. Use the int86(), and int86x() family of functions if you are doing interrupts from C.