-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
65C02 port #13
Open
nickd4
wants to merge
46
commits into
uho:master
Choose a base branch
from
nickd4:65c02_port
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
65C02 port #13
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…to bss rather than text section which avoids the need to call mprotect(), rename things
… be wrapped with PROGRAM / END, also removes automatic bye token that was generated by END
…time.seedsource, so that we can run textual forth code without the tests or the banner
… writes to stderr, fix self-hosted tokenizer termination issue (was debugged with eemit)
…ng the nonstandard words on top of gForth's standard words, produces redefinition warnings
…seedForth-i386.pre containing some compiler words so we can do special handling for DTC
…sticated tracing and symbolic debug (via annotated trace) system used to debug the 65C02 port, the trace is also available for the Z80 port and can be used for comparison
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds a 65C02 port of preForth and seedForth, and a 65C02 emulator based on https://github.com/visrealm/vrEmu6502 as a submodule that refers to my nickd4 github account (because I had to make some minor changes to the emulator backend).
The 65C02 port behaves basically the same as the Z80 port, as they are both direct threaded, so the only real change to the Forth code was in changing "call" to "jsr" and changing the relevant opcode. The assembly code does change a bit due to 65C02 vs Z80 differences -- we don't use the hardware stack for 65C02 because preForth requires >256 bytes for stack strings, and this means some changes to
dodoes
anddovar
to move return addresses from the hardware stack to our IP or stack.I've also added some debugging facilities, you can recompile either the Z80 or 65C02 emulator to produce a trace file on stderr and there's an annotator that allows a kind of symbolic debug after the fact, by interpreting the addresses in the trace relative to the symbol table produced when compiling preForth or seedForth. The annotator is written in Python, I would like to rewrite this in Forth at some stage, but I'd have to recreate some Python facilities like
bisect
,split
,join
andint
so I didn't do this yet.You can use the
-t
switch to either emulator for benchmarking (this does not require recompiling the emulator), for exampleversus
This is an interesting result, since at least for this inner interpreter, it's not true that a 1 MHz 65C02 would be equivalent to a 2..4 MHz Z80 as people are often saying. It would be closer to a 1.2 MHz Z80. On the other hand, it's clearly true that we are programming the Z80 at a higher level, since the Z80 is taking only 58% of the number of instructions @ 8.1 cycles each versus 3.8 cycles each for 65C02. This could account for why the Z80 is popular and feels somewhat easier to work with.
Another interesting metric is the size of the binary images,
versus
For preForth, which contains comparatively little assembly code (and mostly high level Forth), the difference isn't that huge. But for seedForth, which contains more assembly code, including longer routines like
um*
andum/mod
, the Z80 version is only 60% of the size, again suggesting that we are programming the Z80 at a higher level e.g. delegating 16-bit operations to the Z80. Of course, if you do not delegate those operations and program them yourself on 65C02, you can optimize them a bit.Having said all that, we should keep in mind that this particular application does not really play to the 65C02's strengths, since the requirement for 16-bit stack pointers is atypical. Ordinary applications using the 65C02's hardware stack like JSR, RTS, PLA, PHA and its addressing mode $address,X which supports smaller arrays, would be a lot faster. In this regard, the decision in preForth to use stack-strings is a bit unfortunate, and I guess commercial 6502 Forths would have had limited stack sizes.