Hacker News Viewer

MOS tech 6502 8-bit microprocessor in pure SQL powered by Postgres

by adunk on 4/14/2026, 5:46:49 AM

https://github.com/lasect/pg_6502

Comments

by: Someone

This, basically, uses a table to store 64 kilobytes of memory, a single-row table for storing register values, and uses regular procedural programming to run the CPU (<a href="https:&#x2F;&#x2F;github.com&#x2F;lasect&#x2F;pg_6502&#x2F;blob&#x2F;main&#x2F;init&#x2F;05_execute.sql" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lasect&#x2F;pg_6502&#x2F;blob&#x2F;main&#x2F;init&#x2F;05_execute....</a>)<p>I give that an A+ for perseverance, but I would have hoped to see something that uses the strengths of SQL more.<p>For example, there could be a table with the decode ROM (<a href="https:&#x2F;&#x2F;www.cpcwiki.eu&#x2F;index.php&#x2F;MOS_6502#The_Decode_ROM_.28PLA.29" rel="nofollow">https:&#x2F;&#x2F;www.cpcwiki.eu&#x2F;index.php&#x2F;MOS_6502#The_Decode_ROM_.28...</a>) that could be used to drive the logic.<p>Have a main loop that uses the inputs of that ROM to look up the output bits and update a table, and add triggers that handle each “micro-op”. A SQL engine could run those triggers in parallel until they hit a race condition, but those can be avoided a bit by having separate tables for each register.<p>Even better would be if there were tables with every logic gate and wire in the original CPU, using a trigger to move the signals around. That would be a good test of the trigger handling in a SQL engine.

4/14/2026, 9:32:55 AM


by: m000

Cool! How about Postgres on MOS tech 6502 8-bit microprocessor powered by Microsoft&#x27;s 6502 BASIC?

4/14/2026, 9:12:33 AM


by: anthk

Kim-1 emulator and assembler for T3X0:<p><a href="https:&#x2F;&#x2F;t3x.org&#x2F;t3x&#x2F;0&#x2F;sim65kit.html" rel="nofollow">https:&#x2F;&#x2F;t3x.org&#x2F;t3x&#x2F;0&#x2F;sim65kit.html</a><p><a href="https:&#x2F;&#x2F;t3x.org&#x2F;kimuno&#x2F;" rel="nofollow">https:&#x2F;&#x2F;t3x.org&#x2F;kimuno&#x2F;</a><p>Pocket calc as 6502 code<p><a href="https:&#x2F;&#x2F;t3x.org&#x2F;kimuno&#x2F;kimcalc.html" rel="nofollow">https:&#x2F;&#x2F;t3x.org&#x2F;kimuno&#x2F;kimcalc.html</a><p>T3x0 compiler to build the emulator:<p><a href="https:&#x2F;&#x2F;t3x.org&#x2F;t3x&#x2F;0&#x2F;index.html" rel="nofollow">https:&#x2F;&#x2F;t3x.org&#x2F;t3x&#x2F;0&#x2F;index.html</a><p>I&#x27;ve got to run under OpenBSD&#x2F;i386 but it needs a bit of tweaks in the Makefile. On the target section:<p><pre><code> # CFLAGS=$CFLAGS&quot; -m32&quot; # on x86 64-bit systems CFLAGS=$CFLAGS&quot; -static&quot; # in case all else fails CFLAGS=$CFLAGS&quot; -fPIC&quot; # get rid of stupid linker errors CFLAGS=$CFLAGS&quot; -Wl,-z,notext&quot; # get rid of stupid linker errors CFLAGS=$CFLAGS&quot; -fno-PIE -no-pie&quot; # get rid of stupid linker errors </code></pre> Do the same in the bin&#x2F;tx0.sh and bin&#x2F;build.sh just in case. In my system I set the target to unix-386, and T3XDIR it&#x27;s set to T3XDIR=&#x2F;usr&#x2F;local&#x2F;t3x&#x2F;lib in the Makefile and bin&#x2F;tx0.sh scripts.<p>Also, T3XBIN it&#x27;s set to BINDIR= &#x2F;usr&#x2F;local&#x2F;t3x&#x2F;bin<p>Then I ran:<p><pre><code> sh bin&#x2F;modpath.sh &#x2F;usr&#x2F;local&#x2F;t3x&#x2F;lib gmake all-native doas gmake install-native install-modules </code></pre> But it was still broken. Then, I edited &#x2F;usr&#x2F;local&#x2F;t3x&#x2F;bin&#x2F;tx0 and set<p>TX3DIR is above, and ditto with the four CFLAGS flags I posted.<p>Just the ones at lines 38-42.<p>OFC set PATH to &#x2F;usr&#x2F;local&#x2F;t3x0&#x2F;bin:$PATH in ~&#x2F;.profile:<p><pre><code> export PATH=&#x2F;usr&#x2F;local&#x2F;t3x0&#x2F;bin:$PATH </code></pre> Yeah, it&#x27;s tricky, but from now on everything will just compile with<p><pre><code> &#x27;tx0 foo&#x27; </code></pre> where &#x27;foo&#x27; it&#x27;s a foo.t file.<p>This was compiled under an Atom n270 CPU based netbook. I think the author uses a Pentium III machine. If T3X0 can do a MOS 6502 emulation that well, you can try expanding s65&#x2F;sim65 to cover the Apple I emulation.<p>And, as a plus, it might run fast on DOS 386 machines if s65&#x2F;sim65 it&#x27;s compiled a native binary.

4/14/2026, 11:00:02 AM