Skip to content

Commit

Permalink
Added 16bit clean code paths to everything, -Di86 compiler define
Browse files Browse the repository at this point in the history
  • Loading branch information
drwonky committed Mar 27, 2020
1 parent 71244eb commit c53d91b
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 14 deletions.
171 changes: 164 additions & 7 deletions cga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ void cga::translate(ptr_t src)

break;
case X16:
_CX=buf_size>>2;
#ifdef i86
_CX=buf_size>>1;
_DI=FP_OFF(_buffer);
_SI=FP_OFF(src);
_BX=FP_SEG(src);
Expand All @@ -233,9 +234,27 @@ void cga::translate(ptr_t src)
_ES=_AX;

xlate16:
asm {
lodsw // 5
shl al, 4 // 3
or ah, al // 2
mov al, 0xde // 2
stosw // 4
loop xlate16 // 15
} // 44
#else
_CX=buf_size>>2;
_DI=FP_OFF(_buffer);
_SI=FP_OFF(src);
_BX=FP_SEG(src);
_DS=_BX;
_AX=FP_SEG(_buffer);
_ES=_AX;

xlate32:
asm {
lodsd // 5
and eax, 0x0F0F0F0F // 2
//and eax, 0x0F0F0F0F // 2
shl al, 4 // 3
or ah, al // 2
mov al, 0xde // 2
Expand All @@ -245,8 +264,9 @@ void cga::translate(ptr_t src)
mov al, 0xde // 2
rol eax, 16 // 3
stosd // 4
loop xlate16 // 15
loop xlate32 // 15
} // 44
#endif

break;

Expand All @@ -257,13 +277,62 @@ void cga::translate(ptr_t src)
_DI=FP_OFF(_buffer);
_CX=FP_SEG(src);
_AX=FP_SEG(_buffer);
_BX=_row_bytes;
_DS=_CX;
_ES=_AX;

#ifdef i86
xlatelo:
asm {
mov cx, 80
}
xevenlo:
asm {
lodsw // 5
// HHHH HHHH LLLL LLLL
shl al, 2 // 3 0000 00xx 0000 xx00
or al, ah // 2 0000 00xx 0000 xxxx
shl al, 4 // 2 0000 00xx xxxx 0000
mov bx, ax

lodsw
shl al, 2 // 3 0000 00xx 0000 xx00
or al, ah // 2 0000 00xx 0000 xxxx
or al, bl // 2 0000 0000 xxxx xxxx
stosb // 4

loop xevenlo //

push di
add di, 0x1FB0

mov cx, 80
} // 44
xoddlo:
asm {
lodsw // 5
// HHHH HHHH LLLL LLLL
shl al, 2 // 3 0000 00xx 0000 xx00
or al, ah // 2 0000 00xx 0000 xxxx
shl al, 4 // 2 0000 00xx xxxx 0000
mov bx, ax

lodsw
shl al, 2 // 3 0000 00xx 0000 xx00
or al, ah // 2 0000 00xx 0000 xxxx
or al, bl // 2 0000 0000 xxxx xxxx
stosb // 4

loop xoddlo //

pop di

dec dx
jnz xlatelo
} // 44
#else
xlatelo:
asm {
mov cx,bx
mov cx,80
}
xevenlo:
asm {
Expand All @@ -282,7 +351,7 @@ void cga::translate(ptr_t src)

push di
add di, 0x1FB0
mov cx,bx
mov cx,80
} // 44
xoddlo:
asm {
Expand All @@ -305,7 +374,7 @@ void cga::translate(ptr_t src)
dec dx
jnz xlatelo
} // 44

#endif
break;

case CGAHI:
Expand All @@ -318,6 +387,93 @@ void cga::translate(ptr_t src)
_DS=_CX;
_ES=_AX;

#ifdef i86
xlatehi:
asm {
mov cx,80
}
xevenhi:
asm {
lodsw // 5
// HHHH HHHH LLLL LLLL
shr ax, 1
rcl bx, 1
shr ax, 8
rcl bx, 1

lodsw

shr ax, 1
rcl bx, 1
shr ax, 8
rcl bx, 1

lodsw

shr ax, 1
rcl bx, 1
shr ax, 8
rcl bx, 1

lodsw

shr ax, 1
rcl bx, 1
shr ax, 8
rcl bx, 1
// mov ax,bx
mov es:[di],bl
inc di
// stosb // 4

loop xevenhi //

push di
add di, 0x1FB0
mov cx,80
} // 44
xoddhi:
asm {

lodsw // 5
// HHHH HHHH LLLL LLLL
shr ax, 1
rcl bx, 1
shr ax, 8
rcl bx, 1

lodsw

shr ax, 1
rcl bx, 1
shr ax, 8
rcl bx, 1

lodsw

shr ax, 1
rcl bx, 1
shr ax, 8
rcl bx, 1

lodsw

shr ax, 1
rcl bx, 1
shr ax, 8
rcl bx, 1
// mov ax,bx
mov es:[di],bl
inc di
// HHHH HHHH LLLL LLLL
loop xoddhi //

pop di

dec dx
jnz xlatehi
} // 44
#else
xlatehi:
asm {
mov cx,80
Expand Down Expand Up @@ -389,6 +545,7 @@ void cga::translate(ptr_t src)
dec dx
jnz xlatehi
} // 44
#endif

break;
}
Expand Down
26 changes: 23 additions & 3 deletions ega.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,25 @@ void ega::translate(ptr_t src)

break;
case X16:
#ifdef i86
_CX=buf_size>>1;
_DI=FP_OFF(_buffer);
_SI=FP_OFF(src);
_BX=FP_SEG(src);
_DS=_BX;
_AX=FP_SEG(_buffer);
_ES=_AX;

xlate16:
asm {
lodsw // 5
shl al, 4 // 3
or ah, al // 2
mov al, 0xde // 2
stosw // 4
loop xlate16 // 15
} // 44
#else
_CX=buf_size>>2;
_DI=FP_OFF(_buffer);
_SI=FP_OFF(src);
Expand All @@ -233,10 +252,10 @@ void ega::translate(ptr_t src)
_AX=FP_SEG(_buffer);
_ES=_AX;

xlate1:
xlate32:
asm {
lodsd // 5
and eax, 0x0F0F0F0F // 2
//and eax, 0x0F0F0F0F // 2
shl al, 4 // 3
or ah, al // 2
mov al, 0xde // 2
Expand All @@ -246,8 +265,9 @@ void ega::translate(ptr_t src)
mov al, 0xde // 2
rol eax, 16 // 3
stosd // 4
loop xlate1 // 15
loop xlate32 // 15
} // 44
#endif

break;

Expand Down
48 changes: 48 additions & 0 deletions memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,45 @@ void memory::fast_memcpy(void *dest, void *src, size_t size)
{

#ifdef __BORLANDC__
#ifdef i86
if (size > 2) { // long way default, byte copy the long way
_DI=FP_OFF(dest);
_SI=FP_OFF(src);
_BX=FP_SEG(src);
_DS=_BX;
_AX=FP_SEG(dest);
_ES=_AX;

asm {
mov bx,size // count down size
mov cx, di // dest
test cx, 1 // byte offset?
jz pre_word // no, goto work offset
movsb // copy byte
dec bx // 1 byte copied
}

pre_word:
asm {
movsw // addr must be dw aligned
sub bx,2 // 2 bytes copied, we are word aligned now
mov cx,bx
shr cx,1 // divide by 2 to get words remaining
jz post // no words left
mov ax,cx
shl ax,1
sub bx,ax // subtract dwords copied from total
cld
rep movsw // copy dwords
}
post:
asm {
test bx,1 // test number of bytes remaining
jz post_end // no bytes remaining
movsb // copy bytes
}
post_end:
#else
if (size > 4) { // long way default, byte copy the long way
_DI=FP_OFF(dest);
_SI=FP_OFF(src);
Expand Down Expand Up @@ -127,6 +166,7 @@ void memory::fast_memcpy(void *dest, void *src, size_t size)
movsb // copy bytes
}
post_end:
#endif


} else {
Expand Down Expand Up @@ -161,11 +201,19 @@ void memory::blit(ptr_t dest, ptr_t src, size_t size)
_AX=FP_SEG(dest);
_ES=_AX;

#ifdef i86
asm {
mov cx,size
shr cx,1
rep movsw
}
#else
asm {
mov cx,size
shr cx,2
rep movsd
}
#endif
#else
memcpy(dest,src,size);
#endif
Expand Down
Loading

0 comments on commit c53d91b

Please sign in to comment.