VGA에 대한 I/O 포트에 쓰고 읽는 코드가 있습니다. 인라인 어셈블러에서 작동하는 C 코드 기능을 구현하려고합니다. Open Watcom 2.0을 사용하고 DOS 16bit 용으로 컴파일하고 있습니다.struct 구조체에서 Open Watcom 인라인 어셈블리를 사용하여 구조체 멤버에 액세스
VGA의 색상 표에 쓰려면이 기능이 필요합니다. 이것은 올바르게 작동하지 않습니다.
편집 : setPaletteColor의 코드가 완전히 정확하지는 않습니다. 실제 코드를 반영하도록 업데이트했습니다.
void setPaletteColor (unsigned char index, rgbColor *p_color)
{
_asm
{
; tell VGA card we are going to update a palette register
mov dx,PALETTE_MASK
mov al,0xff
out dx,al
; tell VGA which register we will be updating
mov dx,PALETTE_REGISTER_WR
mov al,index
out dx,al
; update the color in the register at index
mov dx,PALETTE_DATA
mov al,*p_color
out dx,al
mov al,*p_color // this is actually *(p_color+1) but this actually gets the next structure not the next data member, so I left it out of the code I typed for my question.
out dx,al
mov al,*p_color // same here, actually is *(p_color+2)
out dx,al
}
}
독서를 위해, 나는 이것을 가지고있다. 이것은 또한 올바르게 작동하지 않습니다.
void getPaletteColor (unsigned char index, rgbColor *p_color)
{
unsigned char *p_red = &p_color->red;
unsigned char *p_green = &p_color->green;
unsigned char *p_blue = &p_color->blue;
_asm
{
; tell VGA card we are going to read a palette register
mov dx,PALETTE_MASK
mov al,0xff
out dx,al
; tell VGA which register we will be reading
mov dx,PALETTE_REGISTER_RD
mov al,index
out dx,al
; read the data into the color struct at 'p_color'
mov dx,PALETTE_DATA
in al,dx
mov *p_red,al
in al,dx
mov *p_green,al
in al,dx
mov *p_blue,al
}
}
이제는 작동하는 순수 C 버전이 있습니다.
void setPaletteColor (unsigned char index, rgbColor *p_color)
{
outp(PALETTE_MASK,0xff);
outp(PALETTE_REGISTER_WR, index);
outp(PALETTE_DATA,p_color->red);
outp(PALETTE_DATA,p_color->green);
outp(PALETTE_DATA,p_color->blue);
}
및 읽기 용.
void getPaletteColor (unsigned char index, rgbColor *p_color)
{
outp(PALETTE_MASK,0xff);
outp(PALETTE_REGISTER_RD, index);
p_color->red = inp(PALETTE_DATA);
p_color->green = inp(PALETTE_DATA);
p_color->blue = inp(PALETTE_DATA);
}
참고 : '.'문자는 사용할 수 없습니다. 연산자도 '->'연산자도 지원하지 않으므로 컴파일러에서 지원하지 않습니다.
다음은 rgbColor 구조체의 정의입니다.
typedef struct rgbColorTag
{
unsigned char red;
unsigned char green;
unsigned char blue;
} rgbColor;
도움이 http://bos.asmhackers.net/docs/vga_without_bios/docs/palettesetting.pdf합니까? 너와 똑같은 일을하는 것 같아. –
* 참고 : '.'문자는 사용할 수 없습니다. 연산자 및 인라인 어셈블리의 '->'연산자는 컴파일러에서 지원하지 않으므로 * C의 로컬 변수에 데이터를 할당하고 인라인 asm에서 읽거나 씁니다. 그것은 컴파일러가 실제로 스택에 복사하기위한 추가 명령어를 내 보낸 것처럼 바보 같이 처리 할 수도 있습니다. 순수한 C 버전의 문제점은 무엇입니까? 컴파일러가 느린 코드를 생성합니까?인라인 asm으로 직접 코드를 수행하는 것이 더 빠른 코드를 얻을 수 있다고 생각하는 이유는 무엇입니까? 또는'outp'는 내장 함수가 아니라 실제 함수라고 불립니다. –
@PeterCordes 내 어셈블리 "getPaletteColor()"를 보겠습니다. 로컬 포인터 변수를 사용하여 색상 구조체에 대한 멤버의 오프셋을 가져옵니다. 순수한 C 버전은 괜찮지 만이 모든 작업을 수행하는 방법을 알고 싶습니다. 이것이 내가 DOS 프로그램을 작성한 이유입니다. 이것은 모두 학습 경험이며, 지금까지 많이 배웠습니다. 'outp '는 I/O 포트에 쓰기 위해 컴파일러와 함께 제공되는 함수입니다. 'inp'와 동일합니다. – SeanRamey