Refactor text plotting routines to C

* Moves plot character routines to C from i386 assembly
This commit is contained in:
Aaron Culliney 2014-04-05 15:25:27 -07:00
parent a43d31a22e
commit 29609230bc
3 changed files with 115 additions and 175 deletions

View File

@ -72,7 +72,7 @@ genfont_SOURCES = src/genfont.c
src/font.c: src/font.txt genfont
./genfont < $< > $@
src/asm386/glue.S: src/disk.c src/misc.c @AUDIO_GLUE_C@
src/asm386/glue.S: src/disk.c src/misc.c src/display.c @AUDIO_GLUE_C@
./src/asm386/genglue $^ > $@
###############################################################################

View File

@ -126,12 +126,6 @@
* esi: from table
* eax: to graphics memory
* ------------------------------------------------------------------------- */
#define PlotCharacter40Row\
PlotCharacter40Row640\
subl $12, %esi;\
addl $ SCANWIDTH-12, %eax;\
PlotCharacter40Row640\
addl $2, %esi;
#define PlotCharacter40Row640\
movl (%esi), %ecx; \
movl %ecx, (%eax); \
@ -522,7 +516,7 @@ plot_dhires##X##_cont: \
* setup to plot the text/lores stuff.
* eax: graphics memory pointer
* ------------------------------------------------------------------------- */
#define PlotTextPagePre(OFF,GM,PAGE)\
#define PlotTextPagePre(OFF,GM)\
pushal; /*Save everything -MUST BE MATCHED!*/\
xorb %ah, %ah;\
movl %eax, %esi; /*ESI=EAX=Chr code*/\
@ -532,55 +526,6 @@ plot_dhires##X##_cont: \
addl SN(GM), %eax; /*Graphic addr*/
/* -------------------------------------------------------------------------
* Common code for plotting an 80 column character.
* Only 640x400 resolution can do this.
* eax: graphics memory pointer
* esi: precalculated font pointer
* OFF 0x400, 0x800
* PAGE 0, 1
* ------------------------------------------------------------------------- */
#define Plot80Character(TAG,OFF,GM,PAGE)\
PlotTextPagePre(OFF,GM,PAGE)/* does a pushal */\
plot_80character_correct_page##TAG:\
addw %bx, %ax; /*screen offset*/\
shll $6, %esi; /* * 64 = 8cols * 8rows*/\
addl $ Font80, %esi; /*Font addr*/\
\
PlotCharacter80Row;\
addl $2, %esi;\
addl $ SCANWIDTH-6, %eax; /*Go to next row*/\
\
PlotCharacter80Row;\
addl $2, %esi;\
addl $ SCANWIDTH-6, %eax; /*Go to next row*/\
\
PlotCharacter80Row;\
addl $2, %esi;\
addl $ SCANWIDTH-6, %eax; /*Go to next row*/\
\
PlotCharacter80Row;\
addl $2, %esi;\
addl $ SCANWIDTH-6, %eax; /*Go to next row*/\
\
PlotCharacter80Row;\
addl $2, %esi;\
addl $ SCANWIDTH-6, %eax; /*Go to next row*/\
\
PlotCharacter80Row;\
addl $2, %esi;\
addl $ SCANWIDTH-6, %eax; /*Go to next row*/\
\
PlotCharacter80Row;\
addl $2, %esi;\
addl $ SCANWIDTH-6, %eax; /*Go to next row*/\
\
PlotCharacter80Row;\
\
popal; /* MATCHES pushal from PlotTextPagePre */
/* -----------------------------------------------------------------
* Scan through video memory (text & graphics) and call the updating
* routines. Depending on softswitch settings, either text or
@ -633,10 +578,15 @@ iie_soft_write_text0:
testl $SS_TEXT, SN(softswitches) # Text mode?
jz iie_write_lores0 # graphics
testl $SS_80COL, SN(softswitches)
jnz plot_80character0 # 80 col text
jnz iie_plot_80character0 # 80 col text
testl $SS_TEXTWRT, SN(softswitches)
jnz ram_nop # NOP (in auxram)
jmp plot_character0 # 40 col text
call plot_character0 # 40 col text
ret
iie_plot_80character0:
call plot_80character0
ret
iie_write_lores0:
testl $(SS_HIRES|SS_TEXTWRT), SN(softswitches)
@ -652,10 +602,11 @@ iie_soft_write_text0_mixed:
testl $(SS_TEXT|SS_MIXED), SN(softswitches)
jz iie_write_lores0
testl $SS_80COL, SN(softswitches)
jnz plot_80character0
jnz iie_plot_80character0
testl $SS_TEXTWRT, SN(softswitches)
jnz ram_nop # NOP (in auxram)
jmp plot_character0 # 40 col text
call plot_character0 # 40 col text
ret
/* video__write_2e_text1 - handle text page1 //e specific */
E(video__write_2e_text1)
@ -666,10 +617,15 @@ iie_soft_write_text1:
testl $SS_TEXT, SN(softswitches) # Text mode?
jz iie_write_lores1 # graphics
testl $SS_80COL, SN(softswitches)
jnz plot_80character1 # 80 col text
jnz iie_plot_80character1 # 80 col text
testl $SS_RAMWRT, SN(softswitches)
jnz ram_nop # NOP (in auxram)
jmp plot_character1 # 40 col text
call plot_character1 # 40 col text
ret
iie_plot_80character1:
call plot_80character1
ret
iie_write_lores1:
testl $(SS_HIRES|SS_RAMWRT), SN(softswitches)
@ -686,10 +642,11 @@ iie_soft_write_text1_mixed:
testl $(SS_TEXT|SS_MIXED), SN(softswitches)
jz iie_write_lores1
testl $SS_80COL, SN(softswitches)
jnz plot_80character1
jnz iie_plot_80character1
testl $SS_RAMWRT, SN(softswitches)
jnz ram_nop # NOP (in auxram)
jmp plot_character1 # 40 col text
call plot_character1 # 40 col text
ret
/* video__write_2e_even0 - handle hires page //e specific */
@ -849,98 +806,10 @@ iie_plot_dhires1:
ret
.align 4
plot_80character0:
pushl %ebx
pushl EffectiveAddr_E
orl $BANK2, EffectiveAddr_E # aux ram
movl $0, %ebx # +0 screen offset
movb SN(apple_ii_64k)(,EffectiveAddr_E,1), %al
andl $0xFFFF, EffectiveAddr_E
Plot80Character(0a,$0x400,video__fb1,$0)
popl EffectiveAddr_E # main ram
movl $7, %ebx # +7 screen offset
movb SN(apple_ii_64k)(,EffectiveAddr_E,1), %al
Plot80Character(0b,$0x400,video__fb1,$0)
popl %ebx
ret
.align 4
plot_80character1:
pushl %ebx
pushl EffectiveAddr_E
orl $BANK2, EffectiveAddr_E # aux ram
movl $0, %ebx # +0 screen offset
movb SN(apple_ii_64k)(,EffectiveAddr_E,1), %al
andl $0xFFFF, EffectiveAddr_E
Plot80Character(1a,$0x800,video__fb2,$1)
popl EffectiveAddr_E # main ram
movl $7, %ebx # +7 screen offset
movb SN(apple_ii_64k)(,EffectiveAddr_E,1), %al
Plot80Character(1b,$0x800,video__fb2,$1)
popl %ebx
ret
/* plot character on first text page */
.align 4
plot_character0:
PlotTextPagePre($0x400,video__fb1,$0)
plot_character_correct_page:
shll $7, %esi # * 128
addl $ Font, %esi # Font addr
PlotCharacter40Row
addl $2, %esi;
addl $ SCANSTEP, %eax # Go to next row
PlotCharacter40Row
addl $2, %esi;
addl $ SCANSTEP, %eax # Go to next row
PlotCharacter40Row
addl $2, %esi;
addl $ SCANSTEP, %eax # Go to next row
PlotCharacter40Row
addl $2, %esi;
addl $ SCANSTEP, %eax # Go to next row
PlotCharacter40Row
addl $2, %esi;
addl $ SCANSTEP, %eax # Go to next row
PlotCharacter40Row
addl $2, %esi;
addl $ SCANSTEP, %eax # Go to next row
PlotCharacter40Row
addl $2, %esi;
addl $ SCANSTEP, %eax # Go to next row
PlotCharacter40Row
popal
ret
/* plot character on second text page */
.align 4
plot_character1:
PlotTextPagePre($0x800,video__fb2,$1)
jmp plot_character_correct_page # same as page 0
/* plot lores block first page */
plot_block0:
PlotTextPagePre($0x400,video__fb1,$0)
PlotTextPagePre($0x400,video__fb1)
plot_block_correct_page:
movw %si, %dx # Compute color
andb $0x0F, %dl
@ -988,7 +857,7 @@ plot_block_correct_page:
.align 4
plot_block1:
PlotTextPagePre($0x800,video__fb2,$1)
PlotTextPagePre($0x800,video__fb2)
jmp plot_block_correct_page

View File

@ -514,7 +514,6 @@ static void c_initialize_row_col_tables(void)
}
}
}
}
static void c_initialize_tables_video(void) {
@ -598,21 +597,37 @@ void video_loadfont_int(int first, int quantity, const unsigned char *data)
}
}
static void c_interface_print_char80_line(
unsigned char **d, unsigned char **s)
{
*((unsigned int *)(*d)) = *((unsigned int *)(*s)); /*32bits*/
static inline void _plot_char40(uint8_t **d, uint8_t **s) {
*((uint32_t *)(*d)) = *((uint32_t *)(*s));
*d += 4, *s += 4;
*((unsigned short *)(*d)) = *((unsigned short *)(*s)); /*16bits*/
*d += 2, *s += 2;
*((unsigned char *)(*d)) = *((unsigned char *)(*s)); /*8bits*/
*d += SCANWIDTH-6, *s -= 6;
*((uint32_t *)(*d)) = *((uint32_t *)(*s));
*d += 4, *s += 4;
*((uint32_t *)(*d)) = *((uint32_t *)(*s));
*d += 4, *s += 4;
*((uint16_t *)(*d)) = *((uint16_t *)(*s));
*d += SCANSTEP, *s -= 12;
*((uint32_t *)(*d)) = *((uint32_t *)(*s));
*d += 4, *s += 4;
*((uint32_t *)(*d)) = *((uint32_t *)(*s));
*d += 4, *s += 4;
*((uint32_t *)(*d)) = *((uint32_t *)(*s));
*d += 4, *s += 4;
*((uint16_t *)(*d)) = *((uint16_t *)(*s));
*d += SCANSTEP, *s += 4;
}
*((unsigned int *)(*d)) = *((unsigned int *)(*s)); /*32bits*/
static inline void _plot_char80(uint8_t **d, uint8_t **s) {
*((uint32_t *)(*d)) = *((uint32_t *)(*s));
*d += 4, *s += 4;
*((unsigned short *)(*d)) = *((unsigned short *)(*s)); /*16bits*/
*((uint16_t *)(*d)) = *((uint16_t *)(*s));
*d += 2, *s += 2;
*((unsigned char *)(*d)) = *((unsigned char *)(*s)); /*8bits*/
*((uint8_t *)(*d)) = *((uint8_t *)(*s));
*d += SCANWIDTH-6, *s -= 6;
*((uint32_t *)(*d)) = *((uint32_t *)(*s));
*d += 4, *s += 4;
*((uint16_t *)(*d)) = *((uint16_t *)(*s));
*d += 2, *s += 2;
*((uint8_t *)(*d)) = *((uint8_t *)(*s));
*d += SCANWIDTH-6, *s += 2;
}
@ -626,14 +641,14 @@ void video_plotchar( int x, int y, int scheme, unsigned char c )
s = video__int_font[scheme] + c * 64;
d = video__fb1 + off;
c_interface_print_char80_line(&d,&s);
c_interface_print_char80_line(&d,&s);
c_interface_print_char80_line(&d,&s);
c_interface_print_char80_line(&d,&s);
c_interface_print_char80_line(&d,&s);
c_interface_print_char80_line(&d,&s);
c_interface_print_char80_line(&d,&s);
c_interface_print_char80_line(&d,&s);
_plot_char80(&d,&s);
_plot_char80(&d,&s);
_plot_char80(&d,&s);
_plot_char80(&d,&s);
_plot_char80(&d,&s);
_plot_char80(&d,&s);
_plot_char80(&d,&s);
_plot_char80(&d,&s);
}
#ifdef VIDEO_X11
@ -673,3 +688,59 @@ const uint8_t * const video_current_framebuffer() {
return !video__current_page ? video__fb1 : video__fb2;
}
// ----------------------------------------------------------------------------
static inline void _plot_character(const unsigned int font_off, const unsigned int fb_off, uint8_t *fb_base) {
uint8_t *fb_ptr = fb_base+fb_off;
uint8_t *font_ptr = video__wider_font+font_off;
_plot_char40(/*dst*/&fb_ptr, /*src*/&font_ptr);
_plot_char40(/*dst*/&fb_ptr, /*src*/&font_ptr);
_plot_char40(/*dst*/&fb_ptr, /*src*/&font_ptr);
_plot_char40(/*dst*/&fb_ptr, /*src*/&font_ptr);
_plot_char40(/*dst*/&fb_ptr, /*src*/&font_ptr);
_plot_char40(/*dst*/&fb_ptr, /*src*/&font_ptr);
_plot_char40(/*dst*/&fb_ptr, /*src*/&font_ptr);
_plot_char40(/*dst*/&fb_ptr, /*src*/&font_ptr);
}
GLUE_C_WRITE(plot_character0)
{
_plot_character(b<<7/* *128 */, video__screen_addresses[ea-0x0400], video__fb1);
}
GLUE_C_WRITE(plot_character1)
{
_plot_character(b<<7/* *128 */, video__screen_addresses[ea-0x0800], video__fb2);
}
static inline void _plot_80character(const unsigned int font_off, const unsigned int fb_off, uint8_t *fb_base) {
uint8_t *fb_ptr = fb_base+fb_off;
uint8_t *font_ptr = video__font+font_off;
_plot_char80(/*dst*/&fb_ptr, /*src*/&font_ptr);
_plot_char80(/*dst*/&fb_ptr, /*src*/&font_ptr);
_plot_char80(/*dst*/&fb_ptr, /*src*/&font_ptr);
_plot_char80(/*dst*/&fb_ptr, /*src*/&font_ptr);
_plot_char80(/*dst*/&fb_ptr, /*src*/&font_ptr);
_plot_char80(/*dst*/&fb_ptr, /*src*/&font_ptr);
_plot_char80(/*dst*/&fb_ptr, /*src*/&font_ptr);
_plot_char80(/*dst*/&fb_ptr, /*src*/&font_ptr);
}
// FIXME TODO NOTE : we are dup'ing the work here
GLUE_C_WRITE(plot_80character0)
{
b = apple_ii_64k[1][ea];
_plot_80character(b<<6/* *64 */, video__screen_addresses[ea-0x0400], video__fb1);
b = apple_ii_64k[0][ea];
_plot_80character(b<<6/* *64 */, video__screen_addresses[ea-0x0400]+7, video__fb1);
}
GLUE_C_WRITE(plot_80character1)
{
b = apple_ii_64k[1][ea];
_plot_80character(b<<6/* *64 */, video__screen_addresses[ea-0x0800], video__fb2);
b = apple_ii_64k[0][ea];
_plot_80character(b<<6/* *64 */, video__screen_addresses[ea-0x0800]+7, video__fb2);
}