VHDL on 6502?

Programming the 6502 microprocessor and its relatives in assembly and other languages.
User avatar
wayfarer
Posts: 191
Joined: 19 Mar 2023
Location: about an hour outside of Springfield

VHDL on 6502?

Post by wayfarer »

in the interest of developing other languages and environments for the 6502, Id like to look at VHDL.
it is 'compiled' to an ASCII text format, is simple, small and can be implemented on the 6502 'capably'.

It is a general purpose language and as such, may be very suitable to write, compile, elaborate, simulate and even use as an exe.
I might try my hand at this in the future. I am interested in whether or not there is much call for it. I would be highly interested in using a 65xx vhdl environment for all sorts of programs.

Any experience or information here?

Things we need:
A text editor1;
A text parser/syntax checker;
an analysis stage evaluator, this runs through everything.
an elaborator, this links and creates a file.
a simulator, that runs that file, and can evaluate all signals, time deltas etc.
a waveform viewer. this just looks at a wave file, and turns it into pixels.

so the elaborator/simulator, may be computationally intensive. drawing fractals is too,
so it will depend on the hardware, the vhdl desired, etc. how complex of a program you create,
however, vhdl is incredibly portable.
Last edited by wayfarer on Wed May 14, 2025 2:54 pm, edited 1 time in total.
greghol
Posts: 29
Joined: 04 Oct 2019
Location: Rancho Cordova, CA

Re: VHDL on 6502?

Post by greghol »

VHDL is a Hardware Description Language. I can see using VHDL to create logic hardware. i.e. 6502 itself or some other digital logic. But using VHDL seems like a lot of work to run on the 6502 and would run slow if there was a 6502 VHDL simulator. It would be fun and challenging I suppose.

Greg
White Flame
Posts: 704
Joined: 24 Jul 2012

Re: VHDL on 6502?

Post by White Flame »

Specifically, VHDL is a parallel execution spec, and you'll need tons of code, data, and time to execute that on a sequential processor. I don't really see what makes sense with this, can you elaborate?
User avatar
wayfarer
Posts: 191
Joined: 19 Mar 2023
Location: about an hour outside of Springfield

Re: VHDL on 6502?

Post by wayfarer »

well, VHDL, is a very simple language, with a few keywords, operators and types.
and all operations can be mapped to the 6502 fairly easily,
except for multiplication and exponentiation.
the ieee.std_libraries, are fairly simple and self contained.
both the creation of VHDL files, and the output of 'compilation' are ASCII files (iso-8859?)

making a vhdl programming environment, is just a text editor.
making a 'compiler' would take time, though it is largely byte manipulation.

Simulating a vhdl file can be quite intensive, if you have a lot of signals and complex values.
that can take some time, if you want a waveform to review in a waveform viewer.

text.io packages allow for simple text input and output. and a few other features allow OS integration.
you can make an exe in vhdl, that gets and prints text. So for simple discrete logic, programs and math,
VHDL, is 'as fast or good as the compiler and how its used'.

You do not have to use vhdl, to write a video accelerator simulation. you can write OS calls, text programs and
math or logic solving programs, that are basically ASCII, until final compilation to exe, elaboration, simulation
or interpretation, on software.

You can totally write Hollywood Hyjinx of some Dork Lost in Caverns under some Maniac's Mansion in VHDL.
you can calculate the 4th digit of Pi or the Fibonnacci sequence. VHDL, is a general purpose, component/signal
based language, that is human readable, easily parsed. and can do text.io; im not saying its the Best General Purpose language,
being able to model in it, on a 6502, to write programs, its as good as anything else.
plasmo
Posts: 1273
Joined: 21 Dec 2018
Location: Albuquerque NM USA

Re: VHDL on 6502?

Post by plasmo »

WHAT?!
SamCoVT
Posts: 344
Joined: 13 May 2018

Re: VHDL on 6502?

Post by SamCoVT »

The output of the VHDL compilers I use is generally not a text file. I get binary .bit or .bin files that can be programmed into the FPGA/CPLD that I wrote a Hardware Description for in VHDL (while you can get ASCII versions of those, they are either just 0s and 1s or a hex format for programming into a flash chip). The binary output files are specific to an exact make/model of FPGA or CPLD and will only work with that device. Most of the generated files are larger than 64K, with some ranging into the megabytes.

While VHDL does have some general purpose programming facilities, most of those exist to assist with the business of generating a hardware description or running a simulation. Some of the constructs are only available when doing simulation.

If you want an actual general purpose programming language that is designed for a sequential processor like the 6502, with almost identical syntax to VHDL, then you probably want an Ada compiler. The VHDL syntax was lifted almost directly from Ada. Pascal would also have a similar syntax. You could write a small version of those languages that could output executables for a 6502. Many of the Pascal compilers output bytecode for a Virtual Machine that would then be run with an interpreter program (ask the interwebs about UCSD Pascal and P-code for more information on that).
User avatar
wayfarer
Posts: 191
Joined: 19 Mar 2023
Location: about an hour outside of Springfield

Re: VHDL on 6502?

Post by wayfarer »

plasmo wrote:
WHAT?!
written in a few lines of vhdl
written in a few lines of vhdl

Code: Select all

-- Console Write Line program
 use std.textio.all;-- Imports the standard textio package.
 -- Defines a design entity, without any ports.
 entity consolewrite is
 end consolewrite;
 architecture behaviour of consolewrite is
 begin
 process
 variable l : line;
 begin
 write (l, String'("Output String Literal."));
 writeline (output, l);
 write (l, String'("Input String Please."));
 writeline (output, l);
 readline (Input, l);
  writeline (output, l);

 wait;
 end process;
 end behaviour;
this compiles under ghdl to a win64_DOS exe.
its fairly large, though there is way more windows code in there than vhdl, such is the beast of compiling to a modern 64b OS
here is a disassembly (of .o maybe) on dogbolt:
https://dogbolt.org/?id=fc80475a-6653-4 ... 1d0#angr=1

attached is a pic from Reko Disassembler, you can see a lot of WinFluff.
RekoSS.png

here is the intermediary code created by ghdl prior to compilation:

however, this is the .o file for that code, this is what vhdl 'compiles to',:

_____
d† c I .text ” l $ P`.data h @ 0À.bss € 0À.xdata ( h @ 0@.rdata Ô  d @ P@/963 ú
@@@/53

@@@/18
&
@@@/4 = 0
@ B/200 ­ m
@ B/144 Î @ B/128 ì û
@ B/112 @ B.pdata 0 ! Q @ 0@/298  É Y @ BÃf.„ D Ãf.„ D Hƒì(H‹ €8 uè HƒÄ(ÃD Hƒì(H‰L$ H H‰è HƒÄ(ÃfHƒì(H‰L$ è H‹L$ LIH L è H‹D$ HÇ@ H‹D$ Ç@ HƒÄ(Ä VWSHì0 H‰Î‹A‰D$$H= ë H‰ùº A¸ è ÇD$$ ‹D$$ƒøtÜ…ÀtH‰ùº A¸ è ëÞè H‰„$ð H~H‰¼$Ð H‹FH‰„$Ø H H‰„$( H‰„$ H H‰„$ H„$ H‰„$à Æ„$è Ç„$ü Ç„$ì HŒ$Ø è H‹„$Ø H‹Œ$Ð H‰H‹Œ$ð è è H‰„$È H‹ ‹‰„$¸ H‰¼$° H‹FH‰„$À HŒ$¸ è H‹„$À H‹Œ$° H‰H‹Œ$È è è H‰„$¨ H‰¼$ˆ H‹FH‰„$ H H‰„$ H‰„$ H H‰„$ H„$ H‰„$˜ Æ„$  Ç„$ø Ç„$¤ HŒ$ è H‹„$ H‹Œ$ˆ H‰H‹Œ$¨ è è H‰„$€ ‹‰D$pH‰|$hH‹FH‰D$xHL$pè H‹D$xH‹L$hH‰H‹Œ$€ è è H‰D$`H‹ ‹ ‰D$PH‰|$HH‹FH‰D$XHL$Pè H‹D$XH‹L$HH‰H‹L$`è è H‰D$@‹‰D$0H‰|$(H‹FH‰D$8HL$0è H‹D$8H‹L$(H‰H‹L$@è è ÇF HÄ0 [_^Ã' 1 % L ' T " j # z )  * † + Ç , ß - - . 5 / L 0  1 ¯ 2 ´ . à í 3
2 . 5 4 L 5  1 ¯ 2 ´ . Ú 3 ô 2 ù . # 6 : 2 ? . b 3 y 2 ~ 7 B B B

& 0p` consolewrite.vhdl consolewrite l P0 behaviour Output String Literal. Input String Please.( 9 @ : P ; X , ˆ =   8 ° > ¸ , È ? à ' ð @ B C 0 A P * D E F %´B . @:;?2 . @?2 © ” W9 WW Wu @ W’ ` H WÁ ° ä Wð + 9 A O W e k y   — ¥ ortho-llvm consolewrite.vhdl C:/Users/Max/Documents/vhdl work__consolewrite__DECL_ELAB work__consolewrite__STMT_ELAB work__consolewrite__PKG_ELAB work__consolewrite__ARCH__behaviour__DECL_ELAB work__consolewrite__ARCH__behaviour__STMT_ELAB work__consolewrite__ARCH__behaviour__P0__PROC ­ * work__consolewrite__DECL_ELAB @ work__consolewrite__STMT_ELAB V work__consolewrite__PKG_ELAB j work__consolewrite__ARCH__behaviour__DECL_ELAB € work__consolewrite__ARCH__behaviour__STMT_ELAB – work__consolewrite__ARCH__behaviour__P0__PROC ­ ; @ ^ ` ¨ ° ” $ ( , Œ ) û
consolewrite.vhdl

òî
N ž
Jt< t
J ­‚Ã
È.ržJyȦ^¢EF?º 7 .text ” $ (ßC .data .bss .xdata ( v%ös .rdata Ô ¡Xaà Ã Ê 5 < = wöÕù È
­ [ ‹
 gcFò € r þ× p
y$É
.pdata 0 í}Dð *  7»h´ @feat.00 ÿÿ ” G ² 6 e @ Ö € ` ê ° h À ° ü › Ô ð € ¥ ` Ï ç ý ä À t   W 9 ) ` / { p • x Ê @ M P D * ˜ 0 ÿ ö ( Q Ò D ! .file þÿ gortho .debug_abbrev .rdata$.refptr.std__textio__output .rdata$.refptr.std__textio__input __ghdl_process_wait_exit .debug_pubtypes .debug_pubnames .debug_str __ghdl_program_error __ghdl_process_register .debug_info __ghdl_stack2_mark __ghdl_stack2_release std__textio__writeline std__textio__readline .debug_line std__textio__ELAB_BODY work__consolewrite__ARCH__behaviour__RTIARRAY work__consolewrite__RTIARRAY work__consolewrite__ARCH__behaviour__P0__RTIARRAY work__consolewrite__ARCH__behaviour__RTISTR work__consolewrite__ARCH__behaviour__P0__l__RTISTR work__consolewrite__RTISTR work__consolewrite__ARCH__behaviour__P0__RTISTR work__consolewrite__ARCH__behaviour__P0__U1__STL work__consolewrite__ARCH__behaviour__P0__U0__STL work__consolewrite__ARCH__behaviour__RTI work__consolewrite__ARCH__behaviour__P0__l__RTI work__RTI work__consolewrite__RTI std__textio__line__RTI work__consolewrite__ARCH__behaviour__P0__RTI work__consolewrite__ARCH__behaviour__INSTSIZE .rdata$.refptr.std__textio__ELABORATED work__consolewrite__ARCH__behaviour__P0__PROC work__consolewrite__ARCH__behaviour__STMT_ELAB work__consolewrite__STMT_ELAB work__consolewrite__ARCH__behaviour__DECL_ELAB work__consolewrite__DECL_ELAB work__consolewrite__PKG_ELAB std__textio__writeO7 _UI00000002 _UI00000001 _UI00000000

____
It is just ASCII characters, and this file, is fairly portable now. I should be usable on other platforms, though Im not 100% on that, from what Ive read, this file is the actual intermediary output. You can make text games in vhdl. If you can do that, you can do many other things. This uses about 0.5MB of resources on my laptop, +7MB of ram for the DOS window that runs it.
I have a similar ".work" file from Altera taken from edaplayground, so the level of complexity of a file, vs the output, vs how it is used is very dependent on the user

Now if we take that extra windows/64 away, its an ascii file that was compiled into something that displays a text box, gets input, and displays that input. I think porting this to 65xx, is a really cool idea. We can make a 'runner' that takes signals to and from. you can jam up any machine with any language if you try. we can Describe how we want our Hardware to work, in the Very High Speed, Integrated Circuit Language... with a simulation vs synthesis approach, and our 'os' can respond to its form of 'stdio' as we develop it to.

. Ill map the vhdl spec to 6502 operations on a spreadsheet!

(edit, replaced incorrect code file)

it is possible to test now, using this toolchain, Im not set up to implement this just yet however...:
https://github.com/nickg/nvc
uses llvm to compile VHDL to machine executable code.

https://github.com/llvm-mos/llvm-mos
has a 6502 backend for llvm

Im not able to test this for at least a couple of weeks, if someone want to give it a go, thats a very simple text io program there.
Id be interested in seeing how big/garbled it gets going to 6502.
User avatar
gilhad
Posts: 85
Joined: 26 Jan 2024
Location: Prague; Czech Republic; Europe; Earth
Contact:

Re: VHDL on 6502?

Post by gilhad »

My "man ascii" say:
Quote:
ASCII is the American Standard Code for Information Interchange. It is a 7-bit code.
The file visibly uses some chars with 8 bits and look as much "being ASCII" as any other exe, com or similar binary file to me ...
John West
Posts: 383
Joined: 03 Sep 2002

Re: VHDL on 6502?

Post by John West »

The .o file is an object file - the communication between a compiler and a linker. It is very much not ASCII, and very much not portable - it contains machine code. That particular one is, I believe, in COFF format. GHDL is going to come with a substantial runtime system that needs to be linked with the object file before it can be run. The runtime will be the part that manages simulating a highly parallel hardware description on a sequential CPU.

A wise person I know is fond of saying "just because you can, doesn't mean you should". VHDL is technically a general purpose programming language, and could in principle be used for any computing task that fits within its I/O limitations. You could get it running on a 6502, given enough memory. That doesn't mean it's a good idea. There are reasons why people generally stick to using it for its intended purposes.

If you really want to do it, just for the challenge, no one's going to stop you. But I believe you are vastly underestimating the work required, and vastly overestimating the usefulness of the result.
sark02
Posts: 241
Joined: 10 Nov 2015

Re: VHDL on 6502?

Post by sark02 »

The clock is running, but the gates aren't hooked up right...
User avatar
wayfarer
Posts: 191
Joined: 19 Mar 2023
Location: about an hour outside of Springfield

Re: VHDL on 6502?

Post by wayfarer »

SamCoVT wrote:
The output of the VHDL compilers I use is generally not a text file. I get binary .bit or .bin files that can be programmed into the FPGA/CPLD that I wrote a Hardware Description for in VHDL... [SNIP].
Totally get that, VHDL implementations are widely different. So what Im doing in VHDL and EDAPlayground.com. are completely different experiences from an Enterprise Software Suite, or someone like yourself with an fppa and the appropriate libraries and software.[
Quote:
While VHDL does have some general purpose programming facilities, most of those exist to assist with the business of generating a hardware description or running a simulation. Some of the constructs are only available when doing simulation.
Exactly! so different versions of ieee 1076 have different Program Environment expectations. in the 1993, it has the TEXTIO and STANDARD libraries, which define that, VHDL will: be able to open, close, read and write to files and that it will be able to access files and directories. The FOREIGN keyword, allows for external programs and function calls. People ran VHDL in the 80s. The size of types is implementation defined. VHDL:65 can be what we make it. Im saying, in 6502 ASM, to build the VHDL implementation and make it self hosting. For this hardware. A 10Mhz 6502 or 65816 should be able to handle TTL and discrete logic and maybe audio signals ok. To do this means making a 6502 implementation, and building an "OS", a file and directory structure around that. Everything in vhdl is ASCII, its like 'in the LRM', its really utf-8/iso-8859-1, 'extended ascii', the ascii code, in ascii order, is part of these specifications, by design.
Quote:
If you want an actual general purpose programming language that is designed for a sequential processor like the 6502, with almost identical syntax to VHDL, then you probably want an Ada compiler. The VHDL syntax was lifted almost directly from Ada. Pascal would also have a similar syntax. You could write a small version of those languages that could output executables for a 6502. Many of the Pascal compilers output bytecode for a Virtual Machine that would then be run with an interpreter program (ask the interwebs about UCSD Pascal and P-code for more information on that).
ok, I have to tell you the story now. this is the story of how VHDL came to be. I having programmed for like, 37 some odd years in a variety of languages, I immediately understood the following upon being exposed to this language.

see, Pascal and COBOL went on vacation somewhere tropical. While on vacation in this tropical location, in a market, they adopted a dog. Like a little purse dog you know? And when they got home, Pascal and COBOL gave the little dog a makeover (that went very, very badly) and it turned out the little dog wasn't a dog at all; it was an aardvark. I just love <3 VHDL.
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: VHDL on 6502?

Post by BigDumbDinosaur »

wayfarer wrote:
see, Pascal and COBOL went on vacation somewhere tropical. While on vacation in this tropical location, in a market, they adopted a dog. Like a little purse dog you know? And when they got home, Pascal and COBOL gave the little dog a makeover (that went very, very badly) and it turned out the little dog wasn't a dog at all; it was an aardvark. I just love <3 VHDL.

That makes almost as much sense to me as installing a sunroof in the International Space Station.  :D
x86?  We ain't got no x86.  We don't NEED no stinking x86!
SamCoVT
Posts: 344
Joined: 13 May 2018

Re: VHDL on 6502?

Post by SamCoVT »

While I don't think I want to invest any of my time working on such a project, I'd be interested to hear about any progress (successes or failures) you make on this if you decide to pursue it further. You may want to focus on one particular aspect of the project, such as the editor, that would be useful for any kind of self-hosted language. That may give you additional perspective on the amount of work it might take to complete more of the project.

Do you have a particular 6502 hardware you want it to run on?
User avatar
wayfarer
Posts: 191
Joined: 19 Mar 2023
Location: about an hour outside of Springfield

Re: VHDL on 6502?

Post by wayfarer »

gilhad wrote:
My "man ascii" say:
Quote:
ASCII is the American Standard Code for Information Interchange. It is a 7-bit code.
The file visibly uses some chars with 8 bits and look as much "being ASCII" as any other exe, com or similar binary file to me ...
Oh, Yeah :) the "LRM" is the ieee spec for VHDL, it covers ascii in the libraries, ASCII (or the character set that includes it) is a fundamental part of VHDL. it is embedded in the language itself.
John West wrote:
The .o file is an object file - the communication between a compiler and a linker. It is very much not ASCII, and very much not portable - it contains machine code.
Yeah, some of those files, at least from some platforms, are actually a fancy ASCII file. You can open them in a text editor and see like, the names of components and stuff. i think this is platform dependent, Altera and GHDL both give my a file, after Analysis, that can be opened and 'read', at least parts of. Its ASCII, and maybe some extended characters, and it might be thats an .o file on WinDOS... i kinda remember that being a thing anyway, from old dos programming days.
Quote:
That particular one is, I believe, in COFF format. GHDL is going to come with a substantial runtime system that needs to be linked with the object file before it can be run. The runtime will be the part that manages simulating a highly parallel hardware description on a sequential CPU.
yeah, for 6502, we will have to move away from VHDL, and dependence on C or C libraries, though 'new vhdl. 2019, has PLI/PHI, and it has all kinds of C bindings and ability to Host tools and system calls. Im still finding the 'right' specification year to use here.
Quote:
A wise person I know is fond of saying "just because you can, doesn't mean you should". VHDL is technically a general purpose programming language, and could in principle be used for any computing task that fits within its I/O limitations. You could get it running on a 6502, given enough memory. That doesn't mean it's a good idea. There are reasons why people generally stick to using it for its intended purposes.
VHDL was used in the 80s nd 90s on 8 and 16 and 32 bit computers. What you run on it, how close the language elaborates to native machine code, is all going to depend on how you make it. Im not making 'Altera Siemens VHDL for x64", Im making, a language environment, that works on a language I like. If I have to pick a language to use on 6502 because none of them do what I want right and I want to do things this way, (the reason for every other language implementation on the architecture in 2025), I pick vhdl.
Quote:
If you really want to do it, just for the challenge, no one's going to stop you. But I believe you are vastly underestimating the work required, and vastly overestimating the usefulness of the result.
I dont have an OS or programs to run, I have to write them, so, this.
BigDumbDinosaur wrote:
wayfarer wrote:
see, Pascal and COBOL went on vacation .... I just love <3 VHDL.
That makes almost as much sense to me as installing a sunroof in the International Space Station. :D
:D
SamCoVT wrote:
While I don't think I want to invest any of my time working on such a project, I'd be interested to hear about any progress (successes or failures) you make on this if you decide to pursue it further. You may want to focus on one particular aspect of the project, such as the editor, that would be useful for any kind of self-hosted language. That may give you additional perspective on the amount of work it might take to complete more of the project. Do you have a particular 6502 hardware you want it to run on?
yes, so an editor is top of the list, and a very basic set of assembly routines for: text in ascii, read and write line. the open. close, create, delete directories. This starts to create the environment support for VHDL, as required by the specification, and it allows this to be fully self hosting. At some point, the kernel, is a program in vhdl (or that functions isomorphic-ally) and the editor becomes a subprogram of that kernel, etc. Or at least, the OS, just exists enough to make a vhdl editor work, and Id just support the basics at first, a few operations or commands at a time. The logic, the Assembly of 6502 thats 'the same as' vhdl, rotate, shift, and, or, xor, etc. and get that working. I want, a 6502 library for simulation runtime, that allows basic textio, and file operations working. Then the rest of it here and there. I may include timeline control. How we simulate vhdl is up to us. So yes, an editor and a textio and file directory structure are first, I mean, I need to build those anyway right?
User avatar
wayfarer
Posts: 191
Joined: 19 Mar 2023
Location: about an hour outside of Springfield

Re: VHDL on 6502?

Post by wayfarer »

New Books!!

just got here today :)
Attachments
IMG_20250515_151058684.jpg
IMG_20250515_151041216.jpg
IMG_20250515_151025024.jpg
Post Reply