Refactor dhires graphics plotting to C

This commit is contained in:
Aaron Culliney 2014-05-23 08:27:01 -07:00
parent 46b6fa5342
commit 3d45e75ea1
4 changed files with 99 additions and 169 deletions

View File

@ -29,7 +29,7 @@ noinst_PROGRAMS = genfont
bin_PROGRAMS = apple2ix
ASM_SRC = \
src/asm386/glue.S src/asm386/cpu.S src/asm386/display.S
src/asm386/glue.S src/asm386/cpu.S
INTERFACE_CLASSIC_SRC = \
src/interface.c

View File

@ -76,7 +76,7 @@ dnl at this point we believe arch/os is good ...
ARCHOS_HACK_LDFLAGS="-L/usr/lib/i386-linux-gnu -L/lib/i386-linux-gnu"
AC_SUBST(ARCHOS_HACK_LDFLAGS)
ASM_O="src/asm386/glue.o src/asm386/cpu.o src/asm386/display.o"
ASM_O="src/asm386/glue.o src/asm386/cpu.o"
AC_SUBST(ASM_O)

View File

@ -1,159 +0,0 @@
/*
* Apple // emulator for Linux:
* Functions for low-level framebuffer output.
*
* Copyright 1994 Alexander Jean-Claude Bottema
* Copyright 1995 Stephen Lee
* Copyright 1997, 1998 Aaron Culliney
* Copyright 1998, 1999, 2000 Michael Deutschmann
*
* This software package is subject to the GNU General Public License
* version 2 or later (your choice) as published by the Free Software
* Foundation.
*
* THERE ARE NO WARRANTIES WHATSOEVER.
*
*/
#define __ASSEMBLY__
#include "apple2.h"
#include "video/video.h"
#include "cpu.h"
#include "misc.h"
/* -------------------------------------------------------------------------
* Plots a normalized byte of dhires color directly into graphics memory.
* eax: graphics memory index
* ebx: dhires_colors index
* edx: scratch
* ------------------------------------------------------------------------- */
#if 1
#define PlotDHiresByte\
xorl %edx, %edx;\
movb SN(video__dhires2)(,%ebx,1), %dl;\
/*movb %dl, %dh;*/\
shll $16, %edx;\
movb SN(video__dhires1)(,%ebx,1), %dl;\
/*movb %dl, %dh;*/\
movl %edx, (%eax);\
movl %edx, SCANWIDTH(%eax);
#else
#define PlotDHiresByte\
pushal;\
pushl %eax;\
pushl %ebx;\
call _plot_dhires_pixels;\
popl %ebx;\
popl %eax;\
popal;
#endif
/* -------------------------------------------------------------------------
* Plot a full double hires color byte into GM
* OFF 0x2000, 0x4000
* PROBLEMS:
* graphics artifiacts are not implemented correctly.
* ------------------------------------------------------------------------- */
#define PlotDHires(OFF,X,GM) \
pushl %eax; /* save regs */ \
pushl %ebx; \
pushl %ecx; \
pushl %edx; \
pushl EffectiveAddr_E; \
\
andl $0xFFFF, EffectiveAddr_E; /* erase offset */ \
btr $0, EffectiveAddr_E; /* normalize */ \
movl EffectiveAddr_E, %ecx; /* ecx = mem addrs */ \
subw OFF, EffectiveAddr; /* - graphics base */ \
movl SN(video__screen_addresses) \
(,EffectiveAddr_E,4), %eax; /* eax = GM offset */ \
movb SN(video__columns) \
(,EffectiveAddr_E,1), %bl; \
addl SN(GM), %eax; /* eax += GM base */ \
\
leal SN(apple_ii_64k), EffectiveAddr_E;\
addl %ecx, EffectiveAddr_E; \
movl EffectiveAddr_E, %ecx; \
addl $0x10000, %ecx; \
\
testb $0xFF, %bl; \
jz plot_dhires##X##_cont; \
movzbl -1(EffectiveAddr_E), %ebx; \
movb 0(%ecx), %bh; \
btr $7, %ebx; \
shrb $3, %bl; \
shlb $4, %bh; \
orb %bh, %bl; \
movzbl %bl, %ebx; \
subl $4, %eax;\
PlotDHiresByte\
addl $4, %eax;\
\
plot_dhires##X##_cont: \
movl %ecx, %edx; \
movb 2(%edx), %cl; \
shll $28, %ecx; \
\
movzbl 1(EffectiveAddr_E), %ebx; \
btr $7, %ebx; /* erase msb */ \
shll $21, %ebx; \
orl %ebx, %ecx; \
\
movzbl 1(%edx), %ebx; \
btr $7, %ebx; /* erase msb */ \
shll $14, %ebx; \
orl %ebx, %ecx; \
\
movzbl 0(EffectiveAddr_E), %ebx; \
btr $7, %ebx; /* erase msb */ \
shll $7, %ebx; \
orl %ebx, %ecx; \
\
movzbl 0(%edx), %ebx; \
btr $7, %ebx; /* erase msb */ \
orl %ebx, %ecx; \
/* 00000001 11111122 22222333 3333xxxx */ \
\
PlotDHiresByte \
addl $4, %eax;\
shrl $4, %ecx; \
movb %cl, %bl; \
PlotDHiresByte \
addl $4, %eax;\
shrl $4, %ecx; \
movb %cl, %bl; \
PlotDHiresByte \
addl $4, %eax;\
shrl $4, %ecx; \
movb %cl, %bl; \
PlotDHiresByte \
addl $4, %eax;\
shrl $4, %ecx; \
movb %cl, %bl; \
PlotDHiresByte \
addl $4, %eax;\
shrl $4, %ecx; \
movb %cl, %bl; \
PlotDHiresByte \
addl $4, %eax;\
shrl $4, %ecx; \
movb %cl, %bl; \
PlotDHiresByte \
popl EffectiveAddr_E; \
andl $0xFFFF, EffectiveAddr_E;/* for safety */ \
popl %edx; \
popl %ecx; /* restore regs */ \
popl %ebx; \
popl %eax; \
ret;
/******************************************/
E(iie_plot_dhires0)
PlotDHires($0x2000,0,video__fb1)
ret
E(iie_plot_dhires1)
PlotDHires($0x4000,1,video__fb2)
ret

View File

@ -661,7 +661,97 @@ GLUE_C_WRITE(video__write_2e_text1_mixed)
}
// ----------------------------------------------------------------------------
// Hires (and Double-Hires) GRaphics
// Double-Hires GRaphics
// PlotDHiresByte
static inline void _plot_dhires_pixels(uint8_t idx, uint8_t *fb_ptr) {
uint8_t b1 = video__dhires1[idx];
uint8_t b2 = video__dhires2[idx];
uint32_t b = (b2<<24) | (b1<<8);
*((uint32_t *)fb_ptr) = b;
*((uint32_t *)(fb_ptr+SCANWIDTH)) = b;
}
// PlotDHires
static inline void _plot_dhires(uint16_t base, uint16_t ea, uint8_t *fb_base) {
ea &= ~0x1;
uint16_t memoff = ea - base;
uint8_t *fb_ptr = fb_base+video__screen_addresses[memoff];
uint8_t col = video__columns[memoff];
uint8_t b0 = 0x0;
uint8_t b1 = 0x0;
uint32_t b = 0x0;
if (col) {
b0 = apple_ii_64k[0][ea-1];
b1 = apple_ii_64k[1][ea];
b0 &= ~0x80;
b0 = (b1<<4)|(b0>>3);
_plot_dhires_pixels(b0, fb_ptr-4);
}
b1 = apple_ii_64k[1][ea+2];
b = (b1<<28);
b0 = apple_ii_64k[0][ea+1];
b0 &= ~0x80;
b |= (b0<<21);
b1 = apple_ii_64k[1][ea+1];
b1 &= ~0x80;
b |= (b1<<14);
b0 = apple_ii_64k[0][ea];
b0 &= ~0x80;
b |= (b0<<7);
b1 = apple_ii_64k[1][ea];
b1 &= ~0x80;
b |= b1;
// 00000001 11111122 22222333 3333xxxx
_plot_dhires_pixels(b, fb_ptr);
b >>= 4;
fb_ptr += 4;
_plot_dhires_pixels(b, fb_ptr);
b >>= 4;
fb_ptr += 4;
_plot_dhires_pixels(b, fb_ptr);
b >>= 4;
fb_ptr += 4;
_plot_dhires_pixels(b, fb_ptr);
b >>= 4;
fb_ptr += 4;
_plot_dhires_pixels(b, fb_ptr);
b >>= 4;
fb_ptr += 4;
_plot_dhires_pixels(b, fb_ptr);
b >>= 4;
fb_ptr += 4;
_plot_dhires_pixels(b, fb_ptr);
}
static inline void iie_plot_dhires0(uint16_t ea) {
_plot_dhires(0x2000, ea, video__fb1);
}
static inline void iie_plot_dhires1(uint16_t ea) {
_plot_dhires(0x4000, ea, video__fb2);
}
// ----------------------------------------------------------------------------
// Hires GRaphics
// CalculateInterpColor
static inline void _calculate_interp_color(uint8_t *color_buf, const unsigned int idx, const uint8_t *interp_base, const uint16_t ea) {
@ -691,14 +781,14 @@ static inline void _calculate_interp_color(uint8_t *color_buf, const unsigned in
}
// PlotPixelsExtra
static inline void _plot_pixels(uint8_t *dst, const uint8_t *src) {
static inline void _plot_hires_pixels(uint8_t *dst, const uint8_t *src) {
uint8_t pix;
for (unsigned int i=2; i; i--) {
for (unsigned int j=DYNAMIC_SZ-1; j; j--) {
uint16_t pix = *src;
pix = ((pix<<8) | pix);
*((uint16_t *)dst) = pix;
*((uint16_t *)dst) = pix;
++src;
dst+=2;
}
@ -779,7 +869,7 @@ static inline void _plot_hires(uint16_t ea, uint8_t b, bool is_even, uint8_t *fb
}
}
_plot_pixels(fb_ptr-4, color_buf);
_plot_hires_pixels(fb_ptr-4, color_buf);
}
// DRAW_GRAPHICS
@ -792,11 +882,9 @@ static inline void _draw_hires_graphics(uint16_t ea, uint8_t b, bool is_even, ui
}
if ((softswitches & SS_80COL) && (softswitches & SS_DHIRES)) {
if (page) {
extern void iie_plot_dhires1();
iie_plot_dhires1();
iie_plot_dhires1(ea);
} else {
extern void iie_plot_dhires0();
iie_plot_dhires0();
iie_plot_dhires0(ea);
}
return;
}
@ -912,3 +1000,4 @@ void video_redraw(void) {
softswitches = softswitches_save;
}