a6502 - an emulator in ARM assembly (for STM32F4Discovery)

Topics pertaining to the emulation or simulation of the 65xx microprocessors and their peripheral chips.
Post Reply
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

a6502 - an emulator in ARM assembly (for STM32F4Discovery)

Post by BigEd »

Inspired by Chris' stm6502 project as announced here, I went ahead and built a similar project, but written in assembly.

The result is on github as the a6502 project - it has much the same flavour as stm6502, but runs a bit faster and is somewhat harder to code up enhancements. (However, it's quite possible to call C from assembly, so enhancements could be written in C.)

There are a few rough spots: decimal mode is not even attempted, and the four non-essential bits of the status register are not modelled. Both are feasible to fix.

On the 168MHz cpu found on the $15 STM32F4DISCOVERY, the emulated speed is about 18MHz. (Which adds a datapoint to the question raised here)

The only 'peripheral' available to the emulated software is serial i/o, over USB, initiated by use of the WDM opcode 42. The code patches supermon64, figforth and EhBASIC to use this mechanism (from a starting point of Chris' versions which are already modified to use LDA and STA absolute on address FFF0)

All the above three programs appear to work correctly, with the exception of EhBASIC's HEX$() function which needs decimal mode.

Any bugs or feedback, please let me know! And thanks to Chris for the inspiration.

Cheers
Ed
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: a6502 - an emulator in ARM assembly (for STM32F4Discover

Post by BigEd »

I have tidied the code a bit, and run a couple more programs, and not found any emulation problems:
- Acorn's HiBASIC version 3 (a fast BASIC with 45000 bytes free.)
- Bruce's program for today

I've also ported Bruce's compact monitor to the 6502 and to this platform, which gives us a single-step facility and a very small-footprint base from which to load other programs:

Code: Select all

$ cu -l /dev/ttyACM0 
Connected.
Hi
 00  00  00  00  00  00  00  00 
Go:  fdd3 
-0200@ea,20,00,03,e8,e8,
-0300@c8,c8,60,
-0200@$
0201 00 FF 00 00 80 10000000$
0300 00 FD 00 00 80 10000000$
0301 00 FD 00 01 00 00000000$
0302 00 FD 00 02 00 00000000$
0204 00 FF 00 02 00 00000000$
0205 00 FF 01 02 00 00000000$
0206 00 FF 02 02 00 00000000
leeeeee
In Memoriam
Posts: 347
Joined: 30 Aug 2002
Location: UK
Contact:

Re: a6502 - an emulator in ARM assembly (for STM32F4Discover

Post by leeeeee »

Quote:
with the exception of EhBASIC's HEX$() function which needs decimal mode.
Remove the SED and CLD from the LAB_HEXS routine and change the LAB_AL2X routine as follows.

Code: Select all

LAB_AL2X
      CMP   #$0A          ; set carry for +1 if >9
      BCC   LAB_AL20      ; skip adjust if <= 9

      ADC   #$06          ; adjust for A to F
LAB_AL20
      ADC   #'0'          ; add ASCII "0"
      STA   (str_pl),Y    ; save to temp string
      DEY                 ; decrement counter
      RTS
Lee.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: a6502 - an emulator in ARM assembly (for STM32F4Discover

Post by BigEd »

Thanks Lee - that works a treat!

This was my test program (note the anti-anti-spam filter adjustment):

Code: Select all

FOR I=1TO99:PRINT HEXdollar(I);" ";:NEXT
1 2 3 4 5 6 7 8 9 ; < = > ? @ 10 11 12 13 14 15 16 17 18 19 1; 1< 1= 1> 1? 1@ 20 21 22 23 24 25 26 27 28 29 2; 2< 2= 2> 2? 2@ 30 31 32 33 34 35 36 37 38 39 3; 3< 3= 3> 3? 3@ 40 41 42 43 44 45 46 47 48 49 4; 4< 4= 4> 4? 4@ 50 51 52 53 54 55 56 57 58 59 5; 5< 5= 5> 5? 5@ 60 61 62 63 
Ready
As fixed:

Code: Select all

FOR I=1TO99:PRINT HEXdollar(I);" ";:NEXT
1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 
Ready
Here's your change in patch form:

Code: Select all

*** ../stm6502-cjbaird/6502code/basic.a 2012-05-08 18:43:58.000000000 +0100
--- extras/basic-nodecimal.a    2012-07-01 09:13:36.000000000 +0100
***************
*** 7202,7208 ****
--- 7202,7210 ----
        JSR     LAB_MSSP                ; make string space A bytes long
        LDY     #$05                    ; set string index
  
+ .ifndef NOBCD
        SED                             ; need decimal mode for nibble convert
+ .endif
        LDA     nums_3          ; get lowest byte
        JSR     LAB_A2HX                ; convert A to ASCII hex byte and output
        LDA     nums_2          ; get middle byte
***************
*** 7236,7241 ****
--- 7238,7249 ----
        LSR                             ; /16
  LAB_AL2X
        CMP     #$0A                    ; set carry for +1 if >9
+ .ifdef NOBCD
+       BCC   LAB_AL20      ; skip adjust if <= 9
+ 
+       ADC   #$06          ; adjust for A to F
+ LAB_AL20
+ .endif
        ADC     #'0'                    ; add ASCII "0"
        STA     (str_pl),Y              ; save to temp string
        DEY                             ; decrement counter
Post Reply