for(ii=0;ii<31;ii++)
{
i=31;
while(i){*VRAM_OFFSET = 0x0800+0x40*ii+0x02*i; *VRAM_VIDEO= 0xFF; i--;
}
i=0x0968;
while(++i<0x103E){*VRAM_OFFSET = i; *VRAM_VIDEO= 0x00;}
for(ii=6;ii<32 ;ii++)
{
//i=31;
//while(--i){*VRAM_OFFSET = 0x0800+0x40*ii+0x02*i; *VRAM_VIDEO= 0xFF;}
//0x0800+off+2=0x0968 off=6
//0x0800+off+62=0x103E off=31
off=0x40*ii;
*VRAM_OFFSET = 0x0800+off+2; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+4; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+6; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+8; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+10; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+12; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+14; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+16; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+18; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+20; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+22; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+24; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+26; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+28; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+30; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+32; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+34; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+36; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+38; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+40; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+42; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+44; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+46; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+48; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+50; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+52; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+54; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+56; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+58; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+60; *VRAM_VIDEO= 0xFF;
*VRAM_OFFSET = 0x0800+off+62; *VRAM_VIDEO= 0xFF;
}
*VRAM_MODULO = 2;
for(ii=6;ii<32 ;ii++)
{
*VRAM_OFFSET = 0x0802+(0x40*ii);
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
*VRAM_VIDEO= 0xFF;
}
__asm__ (
" move.l #0x3C0002, %%a0 \n"
" move.w #0x2, 2(%%a0) \n" //vram modulo
" move.w #25, %%d0 \n" //do 26 times (6-31)
" move.w #0x0982, %%d1 \n" //0x0802 + 0x40*6
"0: \n"
" move.w %%d1, -2(%%a0) \n" //sets addr
" add.w #0x40, %%d1 \n" //add 0x40 for next
".rept 31 \n"
" move.w #0xff, (%%a0) \n" //write data
// " nop \n" //uncomment if writing is too fast for LSPC
".endr \n"
" dbra %%d0, 0b \n" //loop
:::"d0","d1","a0"
);
__asm__
(
" move.l #0x3C0002, %%a0 \n"
" move.w #0x2, 2(%%a0) \n" //vram modulo
" move.w #25, %%d0 \n" //do 26 times (6-31)
" move.w #0x0982, %%d1 \n" //0x0802 + 0x40*6
"0: \n"
" move.w %%d1, -2(%%a0) \n" //sets addr
" add.w #0x40, %%d1 \n" //add 0x40 for next
".rept 31 \n"
" move.w #0xff, (%%a0) \n" //write data
// " nop \n" //uncomment if writing is too fast for LSPC
".endr \n"
" dbra %%d0, 0b \n" //loop
" move.l #0x3C0002, %%a0 \n"
" move.w #0x1, 2(%%a0) \n" //vram modulo
:::"d0","d1","a0"
);
DWORD input;
// z80 emulator functions
// Reading from buttons
unsigned Z80_RDMEM (dword A)
{
hexdata = 0xff;
// $0000-$3FFF ROM
if (A < 0x4000)
return PHOENIX_ROM[A];
else
// $4000-$4FFF RAM/VRAM
if (A < 0x5000)
return (RAM[A-0x4000]);
else
if (A < 0x7000)
return (0xFF);
else
// $7000-$73FF Buttons
if (A < 0x7400)
{
// Reading from buttons port
input = poll_joystick(PORT1, READ_BIOS);
if (input & JOY_LEFT ) {
//exdata &= ~(1<<6);
hexdata &=~0x40;
}
if (input & JOY_RIGHT ) {
//hexdata &= ~(1<<5);
hexdata &=~0x20;
}
if (input & JOY_A ) {
//hexdata &= ~(1<<4); // fire
hexdata &=~0x10;
}
if (input & JOY_B ) {
//hexdata &= ~(1<<7); // shield
hexdata &=~0x80;
}
if (input & JOY_START){
//hexdata &= ~(1<<1); // 1p start
hexdata &=~0x02;
}
if (input & JOY_SELECT){
// hexdata &= ~(1<<0); // coin 1
hexdata &=~0x01;
}
return (hexdata);
}
else
if (A < 0x7800)
return (0xFF);
else
// unmapped
return (0xFF);
}
//C code:
unsigned short code,A;
int x,y,yBg,k;
yBg=(A&0x1F)+k
*VRAM_OFFSET = 0x0800 + (x<<6) + (yBg<<1);
*VRAM_VIDEO = 512+code;
*VRAM_VIDEO = ((code >> 5)| 0x00 ) << 3;
//ASM code:
__asm__(
"move.w #0x0800, %%d1 \n" //
"movw %0, %%d0 \n" // load x from C
"lsl.w #0x6, %%d0 \n" //-- x<<6
"add.w %%d0, %%d1 \n" // 0x0800+(x<<6)
"movw %1, %%d0 \n" // load y=A & 0x1F from C
"andi.w #0x001f, %%d0 \n" // y=(A&0x1F)
"movw %2, %%d2 \n" //-- Load k from C in d2
"add.w %%d2, %%d0 \n" // yBg=y+k
"lsl.w #0x1, %%d0 \n" // yBg<<1
"add.w %%d0, %%d1 \n" // 0x0800+(x<<6)+(yBg<<1)
"move.w %%d1, (0x3C0000) \n" // write data to VRAM_OFFSET
"move.w %3, %%d0 \n" // load code from C
"move.w %%d0, %%d1 \n" // Backup code into d1
"add.w #0x200, %%d0 \n" // 512+code
"move.w %%d0, (0x3C0002) \n" // VRAM_VIDEO in a0 *VRAM_VIDEO = 512+code
"and.w #0xffe0, %%d1 \n"
"lsl.w #0x3, %%d1 \n"
"move.w %%d1, (0x3C0002) \n" // *VRAM_VIDEO VRAM_VIDEO in a0 ((code >> 5) | 0x00 ) << 8
:
:"a"(x), "a"(A), "a"(k), "a" (code)
:"d0" ,"d1", "d2"
);