6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 4:25 pm

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Sun Oct 28, 2012 10:40 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
I've just got this working: it's an extension of Nick Morgan's 6502js simulator(*) to support 16bit and 32bit variants(*). There's a minimal assembler and disassembler: you can also use DCB directives to load a binary in.

See http://biged.github.com/6502js/ which should look like this:
Attachment:
File comment: extension of Nick Morgan's easyjs simulator
easy6502-16bitmode.png
easy6502-16bitmode.png [ 55.19 KiB | Viewed 2224 times ]


There's more to do on the assembler: it doesn't support full expressions for any more cases than I needed for the test. But I know how to add that.

Here's a test program:
Code:
; pi program ported from the 65816 version
; by Bruce Clark as seen on 6502.org

; I/O is memory-mapped in py65:
PUTC     = $f001
GETC     = $f005 ; blocking input

; easy6502 loads to $0600
*=$600

TMP = $700
S = TMP+1
R = S+1
Q = R+1
P = Q+1

START:
   JSR INIT
   LDX #359
   LDY #1193
L1:
   ; no PHY on 65Org16
   STA TMP
   TYA
   PHA
   LDA TMP

   PHA

   ; no PHX on 65Org16
   STA TMP
   TXA
   PHA
   LDA TMP

   ; no STZ on 65Org16
   STA TMP
   LDA #0
   STA Q
   LDA TMP

   TYA
   TAX
L2:TXA
   JSR MUL
   STA S
   LDA #10
   STA Q
   LDA P-1,X
   JSR MUL
   CLC
   ADC S
   STA Q
   TXA
   ASL

   ; no DEC on 65Org16
   SEC
   SBC #1

   JSR DIV
   STA P-1,X
   DEX
   BNE L2
   LDA #10
   JSR DIV
   STA P

   ; no PLX on 65Org16                                                                                                                                                                                                       
   STA TMP
   PLA 
   TAX
   LDA TMP

   PLA
   LDY Q
   CPY #10
   BCC L3
   LDY #0

   ; no INC on 65Org16
   ; carry is set
   ADC #0

L3:CPX #358
   BCC L4
   BNE L5
   JSR OUTPUT
   LDA #46
L4:JSR OUTPUT
L5:TYA
   EOR #48

   ; no PLY on 65Org16
   STA TMP
   PLA
   TAY
   LDA TMP

   CPX #358
   BCS L6
   DEY
   DEY
   DEY
L6:DEX
   BNE L1
   JMP OUTPUT

INIT:
   LDA #2
   LDX #1192
I1:STA P,X
   DEX
   BPL I1
   RTS

MUL:
   STA R
   LDY #16
M1:ASL
   ASL Q
   BCC M2
   CLC
   ADC R
M2:DEY
   BNE M1
   RTS

DIV:
   STA R
   LDY #16
   LDA #0
   ASL Q
D1:ROL
   CMP R
   BCC D2
   SBC R
D2:ROL Q
   DEY
   BNE D1
   RTS

OUTPUT:
   WDM #0
   RTS


You'll only be able to assemble this successfully in 16bit or 32bit mode.

Comments welcome.

Cheers
Ed

(*)16 and 32bit variants of nmos6502 which I think of as 65Org16 and 65Org32.

(*)6502js is the simulator found in easy6502


Last edited by BigEd on Wed Dec 05, 2012 1:53 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 29, 2012 7:36 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
I just committed some fixes. The emulator now runs Nick's snake game demo in 8bit, computes pi with the above program in 16bit, and with a few changes the same program runs in 32 bit:
- initialise S to 1ff or so, otherwise the stack sits over the I/O locations
- change 16 to 32 in two places.

This might be the first program to run on the 65Org32!

(Edit to fix typo: thanks Jeff)


Last edited by BigEd on Tue Oct 30, 2012 7:02 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 29, 2012 10:57 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
Looks good, BigEd!


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 30, 2012 12:03 am 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
I wanted to say something as well when I first read your initial post BigEd. I know emulators like VICE, which can emulate the C64, and I know Mikal Kowalski's assembler for the PC. These are excellent tools for 6502(c) development on the PC. I'm just not sure where to place your development of this PC software you have developed for the 65Org16 core? Forgive my questions please if they're ignorant please.

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 30, 2012 4:52 am 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
ElEctric_EyE wrote:
I wanted to say something as well when I first read your initial post BigEd. I know emulators like VICE, which can emulate the C64, and I know Mikal Kowalski's assembler for the PC. These are excellent tools for 6502(c) development on the PC. I'm just not sure where to place your development of this PC software you have developed for the 65Org16 core? Forgive my questions please if they're ignorant please.


I don't want to speak for BigEd, but I can use my simulator effort as potentially an example.

I had an itch to dabble with the "low level" coding, and I thought maybe building a classic 8-Bit machine, like a Z80 or 6502, would be interesting. But when I thought it all through, the machine itself didn't interest me as much as trying to write something for one.

So I scratched my itch by writing a 6502 simulator, and, because I was on a Mac, and not happy with what I found, I ended up writing a 6502 assembler as well.

My virtual 6502 machine is little more than a CPU with 64K of RAM and a serial port (I should say "character I/O"). No ROM, no monitor, nothing else. But its enough to get Fig-Forth up and running (I have rudimentary disk I/O working as well).

But it's enough to do 6502 development. To give someone a taste of what it's like to write low level code for these kinds of machines. And at the same time, it's not burdened with assumptions. It's not a C64/Apple/Atari, so all of the zero page is mine to abuse, for example.

By creating a simulator for the 65Org16/32, a simple one that happens to have a console as well as some graphics, it lets someone "taste" the -16/32 CPU. See what it's like. "What would it be like to have a 16b Accumulator?" Get your hands dirty without have to do a lot of work.

So, I think it's exciting in its way. It makes the CPU seem more real, and lets the designers start playing with new instructions, or whatever, "for real", rather than as thought experiments or expensive hardware (time and/or $$$) assignments. Now they can write real code and see how it handles.

Good stuff.


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 30, 2012 7:12 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Thanks whartung - that's pretty close. Demonstrating and allowing for exploration of these two architecture extensions was the main idea. Also, it's handy to have a way to run short code sequences. It would take more work to make this approach the scope of Michal's tool, but this one supports our new CPUs and is open source.

(Note that the emulator is a browser page, not a PC program. You can download the source and use it purely locally, which is good if you're extending or fixing it, or you can just point your browser at http://biged.github.com/6502js/ No need to install anything.)

Cheers Ed


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 30, 2012 11:28 am 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
Ah, no hardware! I get it, thanks. :)

Nice skills BigEd, keep the 65Org32 dream alive!

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 23, 2012 7:53 pm 
Offline
Site Admin
User avatar

Joined: Fri Aug 30, 2002 1:08 am
Posts: 281
Location: Northern California
BigEd wrote:
It would take more work to make this approach the scope of Michal's tool, but this one supports our new CPUs and is open source.

It didn't used to be available, but Michal Kowalski released the source of his program a while back.

_________________
- Mike Naberezny (mike@naberezny.com) http://6502.org


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 23, 2012 9:04 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Goodness, I had no idea. It's v1.2.6 so we need to check what's missing wrt 1.2.11, and how to build it.
Cheers
Ed


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 30, 2012 7:05 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
I just fixed a bug with ROR in 32-bit mode - this mode needs some care in JavaScript because it pretends to have 32bit integers for bit operations but is actually using floats.

Here's my test program, which runs in all sizes: 8, 16 and 32 bit:
Code:
init: 
 lda #$ff
 asl
 tax
 txs
 clc
 lda #255
 sta 4
 sta 5
 lda #1
 sta 3
top:
 dec 5
 bne top
 pha
 lda 4
 sta 5
 pla
 iny
 rol
 bcc top
 rol
 ror 3
 bcc skip
 ror 3
skip:
 ldx 3
 jmp top
There's a pointless loop to slow things down to the point where you can see what's happening.


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

All times are UTC


Who is online

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