RE: Software 6502-on-6502

ncoplin_at_orbeng.com
Date: 2002-10-31 05:15:44

Hi Cameron,

I was just catching up with old postings and this idea caught my attention.
C't Aug1985 (German magazine) had an article about simulation of a 65C02
with a software 6502 emulator, and so it raises the question how about a
software 65816. With an REU some of the block-move type functions would
execute very fast, and the 16bit indexing could be done with zp
instructions.... as you say with a virtual memory manager you could use any
RAM expansion to pretend to be real RAM.

I did have some questions about the actually code you used:
1) what did your decode routine look like. How did decode the op code and
jmp to the right routine (an efficient way of doing this would be handy for
some other coding projects...)
2) what do you estimate the emulated through-put was relative to the 1MHz
base, ie did your sample program run effective at 0.2Mhz or slower/faster?

Regards, Nick

-----Original Message-----
From: Cameron Kaiser [mailto:spectre@stockholm.ptloma.edu]
Sent: Wednesday, 2 October 2002 1:04 AM
To: cbm-hackers@cling.gu.se
Subject: Software 6502-on-6502


Well, last night was a very productive all-night hack session. (Medical
students aren't *always* studying.)

In between cranking more speed out of Nether G2's core renderer (10fps!
wahoo!), I finally threw together some ideas that had been floating through
my head about a software 6502-on-6502 emulator (i.e., an emulator in 6502
assembly that emulates a 6502). While this might seem like an academic
pursuit at best, I think it would be the most elegant way of adding things
to the 6502 that we don't have yet such as true MMU facilities, protected
memory, virtual memory, etc.

In any case, it was functional enough to run this:

testp	lda $d020
	sta $d021
	tay
	iny
	sty $02
	ldx #0
	lda #1
tlup	sta $0400,x
	sta $0500,x
	sta $0600,x
	sta $0700,x
	inx
	bne tlup
	brk

All memory access is trapped and checked, all instructions are byte-code
verified, and as you can see, immediate, absolute, implied, branch and
absolute,x addressing modes are all working. I just need to finish the rest
of the opcodes, which were pretty easy (just distill an instruction into a
safe variant, and then run that variant, which sets all the proper flags and
whatnot for me), as well as the other addressing modes.

While I was hand-typing the instruction decode table, there were some 
intriguing instruction patterns that came out. The table is below. I don't
use any of these generalisations for decoding (just a simple raw lookup),
but they might be useful to someone trying to write a better (dis)assembler.

	; master instruction decode table

vectab	.word	opbrk,	opora,	opbad,	opbad
	.word 	opbad,	opora,	opasl,	opbad	; $00-7
	.word 	opphp,	opora,	opasl,	opbad
	.word 	opbad,	opora,	opasl,	opbad	; $08-f
	.word	opbpl,	opora,	opbad,	opbad
	.word	opbad,	opora,	opasl,	opbad	; $10-7
	.word	opclc,	opora,	opbad,	opbad
	.word	opbad,	opora,	opasl,	opbad	; $18-f
	.word	opjsr,	opand,	opbad,	opbad
	.word	opbit,	opand,	oprol,	opbad	; $20-7
	.word	opplp,	opand,	oprol,	opbad
	.word	opbit,	opand,	oprol,	opbad	; $28-f
	.word	opbmi,	opand,	opbad,	opbad
	.word	opbad,	opand,	oprol,	opbad	; $30-7
	.word	opsec,	opand,	opbad,	opbad
	.word	opbad,	opand,	oprol,	opbad	; $38-f
	.word	oprti,	opeor,	opbad,	opbad
	.word	opbad,	opeor,	oplsr,	opbad	; $40-7
	.word	oppha,	opeor,	oplsr,	opbad
	.word	opjmp,	opeor,	oplsr,	opbad	; $48-f
	.word	opbvc,	opeor,	opbad,	opbad
	.word	opbad,	opeor,	oplsr,	opbad	; $50-7
	.word	opcli,	opeor,	opbad,	opbad
	.word	opbad,	opeor,	oplsr,	opbad	; $58-f
	.word	oprts,	opadc,	opbad,	opbad
	.word	opbad,	opadc,	opror,	opbad	; $60-7
	.word	oppla,	opadc,	opror,	opbad
	.word	opjmp,	opadc,	opror,	opbad	; $68-f
	.word	opbvs,	opadc,	opbad,	opbad
	.word	opbad,	opadc,	opror,	opbad	; $70-7
	.word	opsei,	opadc,	opbad,	opbad
	.word	opbad,	opadc,	opror,	opbad	; $78-f
	.word	opbad,	opsta,	opbad,	opbad
	.word	opsty,	opsta,	opstx,	opbad	; $80-7
	.word	opdey,	opbad,	optxa,	opbad
	.word	opsty,	opsta,	opstx,	opbad	; $88-f
	.word	opbcc,	opsta,	opbad,	opbad
	.word	opsty,	opsta,	opstx,	opbad	; $90-7
	.word	optya,	opsta,	optxs,	opbad
	.word	opbad,	opsta,	opbad,	opbad	; $98-f
	.word	opldy,	oplda,	opldx,	opbad
	.word	opldy,	oplda,	opldx,	opbad	; $a0-7
	.word	optay,	oplda,	optax,	opbad
	.word	opldy,	oplda,	opldx,	opbad	; $a8-f
	.word	opbcs,	oplda,	opbad,	opbad
	.word	opldy,	oplda,	opldx,	opbad	; $b0-7
	.word	opclv,	oplda,	optsx,	opbad
	.word	opldy,	oplda,	opldx,	opbad	; $b8-f
	.word	opcpy,	opcmp,	opbad,	opbad
	.word	opcpy,	opcmp,	opdec,	opbad	; $c0-7
	.word	opiny,	opcmp,	opdex,	opbad
	.word	opcpy,	opcmp,	opdec,	opbad	; $c8-f
	.word	opbne,	opcmp,	opbad,	opbad
	.word	opbad,	opcmp,	opdec,	opbad	; $d0-7
	.word	opcld,	opcmp,	opbad,	opbad
	.word	opbad,	opcmp,	opdec,	opbad	; $d8-f
	.word	opcpx,	opsbc,	opbad,	opbad
	.word	opcpx,	opsbc,	opinc,	opbad	; $e0-7
	.word	opinx,	opsbc,	opnop,	opbad
	.word	opcpx,	opsbc,	opinc,	opbad	; $e8-f
	.word	opbeq,	opsbc,	opbad,	opbad
	.word	opbad,	opsbc,	opinc,	opbad	; $f0-7
	.word	opsed,	opsbc,	opbad,	opbad
	.word	opbad,	opsbc,	opinc,	opbad	; $f8-f

-- 
----------------------------- personal page: http://www.armory.com/~spectre/
--
 Cameron Kaiser, Point Loma Nazarene University *
ckaiser@stockholm.ptloma.edu
-- Math according to Pentium: 2 / 2 = 1.037587439439485486372112039523781385
...

       Message was sent through the cbm-hackers mailing list


PLEASE TAKE NOTE:

The contents of this email (including any attachments) may be
privileged and confidential. Any unauthorised use of the contents
is expressly prohibited. If you have received this email in error,
please advise us immediately (you can contact us by telephone
on +61 8 9441 2311 by reverse charge) and then permanently
delete this email together with any attachments. We appreciate
your co-operation.

Whilst Orbital endeavours to take reasonable care to ensure
that this email and any attachments are free from viruses or other
defects, Orbital does not represent or warrant that such is explicitly
the case

(C) 2000: Orbital Engine Company (Australia) PTY LTD and its
affiliates


       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail 2.1.4.