6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 7:24 pm

All times are UTC




Post new topic Reply to topic  [ 59 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
PostPosted: Tue Sep 13, 2016 2:39 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
This isn't specific to the Android progress, but I'm wondering about the choice of showing the flags in an unconventional order:
N Z C I D V

I think it's normal to show them in the order they are in the status register, even though that raises the difficulty of dealing with the other two bits. Note that B will always show as set to 1.
N V - B D I Z C

This presentation helps with understanding BIT, at least, and with the result of PLP (or PLA if pulling a status register copy)

(Sorry if this is awkward because it's a different order from the one in your master instruction table.)


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 14, 2016 8:43 pm 
Offline

Joined: Wed Apr 27, 2016 2:15 pm
Posts: 141
Location: South Africa
I like the suggestion of showing the flags in the order they are stored in the status byte. This can help a lot when doing debugging to keep one's mind together.

I will adjust the display order of the flags in my next blog.

Just on the Blogger admin. I have added a short note on the JavaScript emulator blog on where to find the Android C64 Emulator series.

That is just one feature I found missing from blogger. If you want to start a new blog series, you need to create a site with a different blogspot.com alias. And there is not really a straightforward way to keep your different blog series together.


Top
 Profile  
Reply with quote  
PostPosted: Fri Sep 23, 2016 9:05 am 
Offline

Joined: Wed Apr 27, 2016 2:15 pm
Posts: 141
Location: South Africa
A just released the next part on my series, creating a C64 emulator from scratch for Android. In this post we will be adding the Comparisons and branching instructions to our emulator.

Here is the link:

http://androidemufromscratch.blogspot.c ... ching.html


Top
 Profile  
Reply with quote  
PostPosted: Fri Sep 23, 2016 9:30 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Just seen it - thanks for the credit. But... I see you say
"Secondly you will see that we hardcode the letter B for bit 4 of the status register. This is called the break flag. We will only implement functionality for setting and clearing this flag in later posts. For now we will just default it to B (This flag is set like 90% of the time)."
and this might be heading for trouble. The B flag is set 100% of the time. It's the B bit which might be zero, but it's only zero as written to the stack. The B flag is never seen (and in fact, doesn't exist! But that's even more confusing.)

I think this is more than me being pedantic - if you write an emulator which models a B bit which can be zero, you'll find yourself having to OR in a 1 when you push the value. I think it's more logical to follow the hardware, although the amount of code is probably the same in both cases. Either way, it's fairly easy to get this wrong!


Top
 Profile  
Reply with quote  
PostPosted: Fri Sep 23, 2016 3:13 pm 
Offline

Joined: Wed Apr 27, 2016 2:15 pm
Posts: 141
Location: South Africa
I fully agree, one can easily get the inner workings of the break flag wrong, especially when you don't work withvit regularly :-)

Probably the first I was forced to read up on how the break works, was when I ran the Klaus Test Suite on my JavaScript emulator. This Test Suite do some sanity checks on how you have implented the Break flag logic.


Top
 Profile  
Reply with quote  
PostPosted: Sun Sep 25, 2016 12:01 pm 
Offline

Joined: Wed Apr 27, 2016 2:15 pm
Posts: 141
Location: South Africa
I have just released the part on series on writing a C64 emulator for Android.

In this post we will be implementing the Stack and related operations.

Here is the link:

http://androidemufromscratch.blogspot.c ... tions.html


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 26, 2016 4:57 pm 
Offline

Joined: Wed Apr 27, 2016 2:15 pm
Posts: 141
Location: South Africa
I have just released Part 8 in my series for creating a C64 from scratch for Android. In this post we will implementing the remaining 6502 instructions within our emulator. So, after this post we will be ready to run a Test Suite on our emulator.

Here is the link:

http://androidemufromscratch.blogspot.c ... tions.html


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 26, 2016 5:35 pm 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 679
How good is Android at inlining functions? In the Javascript emulator inside WFDis, where I have an arbitrary obsession with small code size, I do things like this: (paraphrased)
Code:
  case ADC:
    a = doAdd(resolveRead());
    break;

  case DEX:
    x = setnz(x-1);
    break;

  case DEY:
    y = setnz(y-1);
    break;


Instead of having stuff like setting flags, masking to 8-bit values, etc as repeated operations in every instruction, they're handled by small utility functions which end up getting inlined which would be equivalently fast. But besides just being small, they're also very readable and reusable without copy/paste bugs.

(Of course, I also have resolveRead and resolveWrite, which do the Right Thing™ based on the current instruction's addressing mode, which is a slower dispatch, but keeps the code small which is a higher priority. ;) )

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 27, 2016 5:59 am 
Offline

Joined: Wed Apr 27, 2016 2:15 pm
Posts: 141
Location: South Africa
The native parts of an Android application (like my cpu.c and memory.c) is written in C. So yes, I think one might be able to inline functions within an Android application.

To be honest, I haven't thought about using inlining within my Android application, but this is definately a nice suggestion.

I am going to play around a bit with inlining and give some feedback in my next post.


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 07, 2016 8:20 am 
Offline

Joined: Wed Apr 27, 2016 2:15 pm
Posts: 141
Location: South Africa
I have just released part 9 in my series on writing a C64 emulator from scratch for Android. In this post we will attempt to run the Klaus Test Suite on the emulator to surface potential implementation bugs.

Here is the link:

http://androidemufromscratch.blogspot.c ... suite.html


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 13, 2016 3:51 pm 
Offline

Joined: Wed Apr 27, 2016 2:15 pm
Posts: 141
Location: South Africa
I have just released Part 10 in my series on writing an Android C64 emulator from scratch. In this post we we will be booting the C64 system with its ROMS, Kernal and Basic.

I will also be covering Compacting the code of the Instruction decoding switch statement with the aid of inlining utility functions, as suggested by @WhiteFlame.

Here is the link:

http://androidemufromscratch.blogspot.c ... ystem.html


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 14, 2016 9:21 am 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 679
Cool, I'm curious if you measured any execution speed difference in doing that change.

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 14, 2016 3:37 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1952
Location: Sacramento, CA, USA
I'm gonna speculate that the execution speed is about the same ... the tangible benefits here are probably source size and coolness factor.

Mike B.


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 14, 2016 4:46 pm 
Offline

Joined: Wed Apr 27, 2016 2:15 pm
Posts: 141
Location: South Africa
You are quite right @MikeB!

I ran some performance timers and couldn't really spot any performance penalty with the inlining.

On my Samsung Galaxy I got on average between 1 and 2 milliseconds per batch of 20000 emulated 6502 Cpu cycles when running the Klaus test suite for both uninlined and inlined versions.


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 14, 2016 4:47 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
It should be good for maintainability though? lib6502 does something like it, but very extreme, and using preprocessor macros.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 59 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 56 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: