marioballano / emudore Goto Github PK
View Code? Open in Web Editor NEWemudore, a Commodore 64 emulator
License: Apache License 2.0
emudore, a Commodore 64 emulator
License: Apache License 2.0
Here's another patch (the previous was for double height):
void Vic::draw_sprite(int x, int y, int sprite, int row)
{
uint8_t swid = is_double_width_sprite(sprite) == true ? 2 : 1;
uint16_t addr = get_sprite_ptr(sprite);
for(int w=0;w<swid;w++)
{
for (int i=0; i < 3 ; i++)
{
uint8_t data = mem_->vic_read_byte(addr + row * 3 + i);
for (int j=0; j < 8; j++)
{
if(ISSET_BIT(data,j))
{
uint16_t newX = (x+w + (i*8*swid) + (8*swid) - (j*swid)) ;
uint8_t side_border_offset = 0;
uint8_t top_border_offset=0;
uint8_t btm_border_offset=0;
// 38 col mode
if(!ISSET_BIT(cr2_,3))
side_border_offset = 8;
// 24 line mode
if(!ISSET_BIT(cr1_,3))
{
top_border_offset=2;
btm_border_offset=4;
}
if(newX <= kGFirstCol+side_border_offset || y <= kGFirstCol + top_border_offset ||
newX > kGResX+kGFirstCol-side_border_offset || y >= kGResY+kGFirstCol - btm_border_offset)
{
io_->screen_update_pixel(newX,y,border_color_);
}
else
{
io_->screen_update_pixel(newX,y,sprite_colors_[sprite]);
}
}
}
}
}
}
Hello, I wanted to say thank you for sharing this work and congratulations. Your code is the closest emulation I could work with successfully. My aim has always been to take a C64 emulator and modify it so that an x86 (or ARM) could boot right into it, bare metal, instead of needing an OS to load it. Basically the emulation IS the operating system...making your PC a C64.
I took the code you have here and did exactly that. I crossed it with some barebones OS code, and after many days of struggling, was able to get something working as a proof of concept. Id really love to see something like this continue to develop. We have android running on toasters, so why not a c64?
The link to my repo is:
https://github.com/xlar54/emudore64
I apologize for the naming - unless you dont mind. I dont really have a name for the OS right now. I provided a link back to your repo and providing full credit to you for the emulation. Let me know what you think, and thank you.
This one was a bit of a brain teaser until it just kind of hit me. Your code is soooooo close to having it. Here's the updated function to provide it. I havent tested multicolor (although should work) or collisions yet though.
(Also sorry Im not sending pull requests. I working from my codebase which is obviously modified for the operating system)
void Vic::draw_raster_sprites()
{
if(sprite_enabled_ != 0)
{
int rstr = raster_counter();
int y = rstr - kFirstVisibleLine;
int sp_y = rstr - kSpritesFirstLine;
/* loop over sprites reverse order /
for(int n=7; n >= 0 ; n--)
{
int height = is_double_height_sprite(n) ? kSpriteHeight * 2 : kSpriteHeight;
/ check if the sprite is visible */
if(is_sprite_enabled(n) &&
sp_y >= my_[n] &&
sp_y < my_[n] + height)
{
int row = 0; //sp_y - my_[n];
if(is_double_height_sprite(n))
row = (int)(sp_y-my_[n]) / 2;
else
row = sp_y - my_[n];
int x = kSpritesFirstCol + sprite_x(n);
if(is_multicolor_sprite(n))
{
draw_mcsprite(x,y,n,row);
}
else
{
draw_sprite(x,y,n,row);
}
}
}
}
}
Hi,
love the project.
Does it include a break key , the 10 goto 10 seems endless.
Interested in the keyboard mapping to C64 key`s.
Hey Mario,
One question I have for you - dont know if its my implementation or if you can replicate it in your code. If I patch RAM such as:
mem_ram_[0xc000] = 0xff;
It will place that value just fine. But if I try to POKE a new value into that memory location, it treats it like a ROM and wont overwrite those values. Seems to happen anywhere I set RAM.
Could you try this and see if you get the same problem?
Implement support for Commodore serial IEEE-488 bus (IEC Bus)
./emudore a_mind_is_born.prg
Unknown instruction: 4B at 00dc
I fixed this in my repo, you can just pull from the following functions (rather than pasting them here)
void Vic::draw_mcsprite(int x, int y, int sprite, int row)
and
void Vic::draw_sprite(int x, int y, int sprite, int row)
https://github.com/xlar54/emudore64/blob/master/src/c64/vic.cpp
I have a test program for this, but I cant extract it from the harddrive just yet. But the following pokes may help:
53271 - double height(0 = off for all, 255 = on for all)
53277 - double width (0= off for all, 255 = on for all)
53276 - multicolor sprite mode (0 = off, 255 all on)
(the color differences are because the test program cycled colors, and my snapshot timings were off)
its pretty much all inclusive at this point, containing the 38 & 24 column code in there, h/v scrolling, and extended background color mode. At some point Ill look into sprite collisions and will update you.
In the VIC code, the sprite 5 X pos is missing. Add this and you're good:
In Vic::read_register()
...
switch(r)
case 0xa: // sprite 5 x coord
same with Vic::write_register()
Control register 53270, bit 3 handles 38 or 40 column mode. POKE53270,0 should make it go 38 column and POKE53270,8 should return to normal.
Here's a patch you can apply to provide this function:
`void Vic::draw_raster_char_mode()
{
int rstr = raster_counter();
int y = rstr - kFirstVisibleLine;
if((rstr >= kGFirstLine) && (rstr < kGLastLine) && !is_screen_off())
{
/* draw background */
if(!ISSET_BIT(cr2_,3)) // 38 columns
io_->screen_draw_rect(kGFirstCol+8,y,kGResX-16,bgcolor_[0]);
else
io_->screen_draw_rect(kGFirstCol,y,kGResX,bgcolor_[0]);
/* draw characters */
for(int column=0; column < kGCols ; column++)
{
if(!ISSET_BIT(cr2_,3)) // 38 columns
{
if(column == 0) continue;
if(column == kGCols-1) continue;
}
int x = kGFirstCol + column * 8;
int line = rstr - kGFirstLine;
int row = line/8;
int char_row = line % 8;
/* retrieve screen character */
uint8_t c = get_screen_char(column,row);
/* retrieve character bitmap data */
uint8_t data = get_char_data(c,char_row);
/* retrieve color data */
uint8_t color = get_char_color(column,row);
/* draw character */
if(graphic_mode_ == kMCCharMode && ISSET_BIT(color,3))
draw_mcchar(x,y,data,(color&0x7));
else
draw_char(x,y,data,color);
}
}
}
`
I started the emulator and it worked out of the box. The first thing I thought to do is run some kind of TCP client and IRC would be fun to see on the C64.
This is a C64 IRC client
http://contiki.cbm8bit.com/
Its options for networking are "RR+RR-NET" "TFE" and "ETH64". If you know what these are (I don't), is it possible to support one of them?
This one will require a basic prog to confirm, but it should be easy enough. The issue is that sprites overlap the screen border. This fix will correct it (and incorporates the 38 col fix earlier as well) I havent tried it yet on multicolor sprites, but I dont think it fixes that one yet.
Basically it still renders the sprite, but uses the border color for the overlapping pixels so it appears to go under the border. Works in all directions.
`void Vic::draw_sprite(int x, int y, int sprite, int row)
{
uint16_t addr = get_sprite_ptr(sprite);
for (int i=0; i < 3 ; i++)
{
uint8_t data = mem_->vic_read_byte(addr + row * 3 + i);
for (int j=0; j < 8; j++)
{
if(ISSET_BIT(data,j))
{
uint16_t newX = x + i*8 + 8 - j;
uint8_t border38 = 0;
if(!ISSET_BIT(cr2_,3)) // if border mode is 38 columns
border38 = 8;
if(newX <= kGFirstCol+border38 || y <= kGFirstCol || newX > kGResX+kGFirstCol-border38 || y > kGResY+kGFirstCol)
{
io_->screen_update_pixel(newX,y,border_color_);
}
else
{
io_->screen_update_pixel(newX,y,sprite_colors_[sprite]);
}
}
}
}
}`
The README states emudore is single threaded so how would I build it without threads? I'm trying to build it for Serenity which doesn't have complete pthreads support yet.
I have tried commenting out the thread related bits in FindSDL2.cmake but I still get this error:
[ 70%] Building CXX object CMakeFiles/emudore.dir/src/io.cpp.o
/home/local/ISDADS/sgs548/src/serenity/Ports/emudore/emudore-master/src/io.cpp: In member function 'void IO::handle_keydown(SDL_Keycode)':
/home/local/ISDADS/sgs548/src/serenity/Ports/emudore/emudore-master/src/io.cpp:284:20: warning: catching polymorphic type 'const class std::out_of_range' by value [-Wcatch-value=]
catch(const std::out_of_range){}
^~~~~~~~~~~~
/home/local/ISDADS/sgs548/src/serenity/Ports/emudore/emudore-master/src/io.cpp: In member function 'void IO::handle_keyup(SDL_Keycode)':
/home/local/ISDADS/sgs548/src/serenity/Ports/emudore/emudore-master/src/io.cpp:297:20: warning: catching polymorphic type 'const class std::out_of_range' by value [-Wcatch-value=]
catch(const std::out_of_range){}
^~~~~~~~~~~~
/home/local/ISDADS/sgs548/src/serenity/Ports/emudore/emudore-master/src/io.cpp: In member function 'void IO::type_character(char)':
/home/local/ISDADS/sgs548/src/serenity/Ports/emudore/emudore-master/src/io.cpp:315:20: warning: catching polymorphic type 'const class std::out_of_range' by value [-Wcatch-value=]
catch(const std::out_of_range){}
^~~~~~~~~~~~
/home/local/ISDADS/sgs548/src/serenity/Ports/emudore/emudore-master/src/io.cpp: In member function 'void IO::vsync()':
/home/local/ISDADS/sgs548/src/serenity/Ports/emudore/emudore-master/src/io.cpp:376:8: error: 'std::this_thread' has not been declared
std::this_thread::sleep_for(ttw);
^~~~~~~~~~~
CMakeFiles/emudore.dir/build.make:206: recipe for target 'CMakeFiles/emudore.dir/src/io.cpp.o' failed
make[3]: *** [CMakeFiles/emudore.dir/src/io.cpp.o] Error 1
make[3]: Leaving directory '/home/local/ISDADS/sgs548/src/serenity/Ports/emudore/emudore-master/build'
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/emudore.dir/all' failed
make[2]: *** [CMakeFiles/emudore.dir/all] Error 2
make[2]: Leaving directory '/home/local/ISDADS/sgs548/src/serenity/Ports/emudore/emudore-master/build'
Makefile:83: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/home/local/ISDADS/sgs548/src/serenity/Ports/emudore/emudore-master/build'
Makefile:2: recipe for target 'release' failed
make: *** [release] Error 2
This mode lets you have different background colors for characters 0-63. There were a number of changes needed to support it, including a new method that needs to also be added to the header file:
inline void draw_ext_backcolor_char(int x, int y, uint8_t data, uint8_t color, uint8_t c);
You may want to run a diff, but i think otherwise we are pretty much still in sync.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.