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

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Oct 24, 2011 12:23 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Aficionados of minimally commented code in unusual languages might like to take a look at this (by Brian Armstrong).

It seems to me fairly small and simple so maybe it's an interesting approach?

He defines 256 pairs of offsets into two lists of functions: a list of operations and a list of addressing modes.

It's a bit difficult to read because there are no symbolic names for the registers, just numeric indices into the state vector for the machine (and indices into index 3 for the status bits updates.) But that's just cosmetic.

Cheers
Ed


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 24, 2011 1:04 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
My emulator works in a similar way. I use a 256 instruction jump table to a piece of code that consists of two macro calls. For example:
Code:
LDA_IMM:
  _IMM
  _LDA
  bra  Execute

LDA_ABS:
  _ABS  RD_ADDR
  _LDA
  bra  Execute

The address macro computes the physical memory address corresponding emulated target address ready for the instruction to access. I had to add a parameter the memory address mode because the PIC I'm using needs to know if the final address will be read (LDA) or written (STA) or both (INC/ROL).

Originally I had two subroutine calls but to minimise execution time I went for macros in the end. I also use the devices processor flags for NZVC and generate P only when needed.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 24, 2011 1:28 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
I had another look at lib6502 and it's sort of similar (but in C.) One difference is that the machinery for handling the next opcode is replicated, so you save the jump. Acorn's emulator does the same - it does cost code space of course.

So: Brian uses a table of function indices; you and Ian both use a jump table; Acorn used a 256-way computed jump (costs more code space.)

Cheers
Ed


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Oct 25, 2011 12:49 pm 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
BigEd wrote:
I had another look at lib6502 and it's sort of similar (but in C.) One difference is that the machinery for handling the next opcode is replicated, so you save the jump. Acorn's emulator does the same - it does cost code space of course.


Replicating code could also slow it down, if the resulting code no longer fits in the L1 instruction cache.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 13 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: