Page 1 of 5

Project-28 - A somewhat Minimal 6502 system

Posted: Thu Jan 30, 2025 2:14 pm
by drogon
I've written about this in the past, but wanted to give an update as I've been working on it recently and made a brief mention of it recently in another thread...

This project was a sort of (personal) challenge to a comment I made about my own variant of TinyBasic. I said something along the lines of "I felt it might be a good fit for a minimal 4K system"... So I set about doing it as my winter 2023 project - and it went well. I had it done by the Solstice, a PCB made and tested and a bodge wire fitted!) and interfaced it to a quick hack of a piece of stripboard with 18 LEDs on making a sort of flashing tree decoration.

https://unicorn.drogon.net/6507-tree.mp4

So what is it:

It's a small SBC (95mm²) with a 6507 CPU on-board, with 4KB of usable RAM and 4KB ROM. The ROM holds my own TinyBasic interpreter with serial IO routines. There is an on-board button which can be read as well as 4 LEDs which are under program control. The board also features a W65C22 VIA for GPIO. The button, LEDs and VIA have instructions built in to the on-board TinyBasic interpreter to save you using peek & poke to access them.

The 6507 can only address 8KB with its 13 pin address bus so a split of 4KB ROM and 4KB RAM works well.

The "ROM" is actually a 32KB EEPROM arranged as banks of 4KB. The CPU can only see one bank at a time and the setup is that one bank is used for the code of the TinyBasic interpreter and the other 7 are used to save/load programs from.
IMG_20231220_193620_DRO.jpg
This is the Revision 1 board - I have recently changed the layout slightly and fixed the bodge wire I needed for this board and will be testing this soon. Note that the RAM is physically under the EEPROM. CPU, RAM and EEPROM are all 28-pin chips, hence the name: Project-28.

The board has 4 on-board LEDs that you can use as well as a button for one-bit input.

The CPU is a 6507 clocked at 2Mhz. It's been very stable so-far, but I'm not sure I can get many more Rockwell parts and I'll be testing UMC parts soon to see if they also run at 2Mhz.

The TinyBasic plus bit-banged serial IO and the code to access the button, LEDs and handle loading and saving Basic program to/from the EEPROM all fit into 4KB. It was quite a challenge even though it's a "classic" TinyBasic in that it uses an IL (Intermediate Language - a sort of virtual machine) to save space - there was still a lot of 6502 code to be written, squeezed, optimised and so on. One challenge is that the code to access the EEPROM needs to run from RAM, so it has to be copied into RAM, called, do the bank switching, save/load/dir and return back to the main code. (And due to size considerations, this code is now split into 2 parts, so 2 segments of code to copy and run in RAM).

The Basic is fairly straightforward for a TinyBasic with the addition of DO...UNTIL as well as FOR...NEXT. GOTO and GOSUB takes an expression so you can use that to GOTO 10+N for example. There are the usual TinyBasic 26 variables which are treated as 16-bit 2s compliment signed integers. Overflow is checked on all arithmetic operations. Additionally there is one more variable: @ which can be used as a general purpose variable, but has the side-effect of defining the field width of printed (decimal) numbers. Hexadecimal numbers are supported and can be input and printed too.

Even though the board runs at 2Mhz it's not blindingly fast. It's slower than most 6502 Basics of the era due to it's using an IL. the IL is a sort of virtual machine interpreted by the 6502 which then interprets and runs the Basic program. Turtles all the way down, as they say.

There are additional commands to manipulate the VIA using a wiring-like interface where it's considered to be a 16-pin device. You can read and write individual pins and change their modes in a manner similar to the wiring interface used in Arduino systems. Also to to read the button and read/write the on-board LEDs...
  • IF BTN THEN ... :REM If Button is being pushed
  • LED = 9 : REM Set LEDs to 1001 (9 in binary)
  • LED = LED + 1 : REM increment the 'count' on the LEDs.
  • PM P,M : REM PinMode, set pin P to mode M (1 for output, 0 for input)
  • X = DR P : REM DigitalRead pin P
  • DW P,V : REM DigitalWrite pin P with value V (0 or 1)
Pins 0 through 15 correspond to PA0..PA7 then PB0...PB7 on the VIA. As well as port A[0-7] and port B[0-7] The CA2 and CB2 pins are available as output only, but the wiring commands can't access them (yet - they will be pins 16 and 17 if I can squeeze the code in) but for now you need to use peek/poke for that....

... and so there are also peek and poke commands (both byte and word) if you want to manipulate it directly for e.g. 8-bit port access.

Some commands are different to what you might expect in a Basic - unless you've had experience of Acorn Atom or BBC Basic. Hex numbers are supported but have to be prefixed with the ampersand (&) character rather than the usual $ or even 0x characters. (Dollar $ is the string prefix)

Prefixing a variable with the twiddle (~) symbol in a PRINT instruction will cause it to be printed as a 4-digit hexadecimal number. e.g. PRINT ~66 will show 0042 on the terminal. There is an additional output instruction: VDU. This takes a list of number or variables and outputs them as their single byte ASCII code. e.g. VDU 12,10,10,7 may clear the screen and move the cursor down 2 lines and ring the bell on some terminals.

Peek and Poke are called "indirection operators" and rather than the keyword peek or poke are the characters ? (for byte indirection) or ! for word indirection. e.g. to poke the value $AA into the VIA port A: ?&1F1 = &AA similarly to read port V into variable Z: Z = ?&1F0

(The VIA occupies addresses $01F0 through $01F0F in the memory map, so stack is initialised to $EF rather than the traditional $FF)

Strings are supported but string space allocation and manipulation is left as an exercise to the user. Saying $A will treat variable A as a pointer, so:

Code: Select all

A = TOP : REM Start of free RAM after the program
$A = "Hello"
B = ?(A+2) : Rem get 3rd character of A
VDU B : REM output the letter l
Strings can be copied and printed but you need to allocate space yourself. See the manual for more.

Programs can be saved into the EEPROM - there are 7 save slots and these are just numbers. If you have a line zero in your program which is a REM statement then that line is printed with the DIR command.

Code: Select all

>DIR
 1:
 2:
 3:
 4:
 5:
 6: Hello
 7:

>CH 6
Hello, World!

>LIST
    0 REM Hello
   10 PRINT "Hello, World!"
   20 END
(Also demonstrates the CH or chain command - loads and runs a program but does not clear the variables while RUN normally does a clear).

There is a turnkey or autostart feature - if the program in slot 1 has the magic string: !BOOT after the REM statement then it will be loaded and run at power on time. This is how I was running my tree lights program with it powered from a USB power bank.

Using the wiring commands and LED: (I have a 10 LED bargraph display hooked up, so ...)

Code: Select all

   10 REM Blinky Lights
   15 REM first 10 pins output
   20 FOR P = 0 TO 9 : PM P,1 : NEXT P
   40 FOR P = 0 TO 9
   45 LED = P
   50 DW P, 1
   60 FOR J = 1 TO 20 : NEXT J : REM DELAY
   70 DW P, 0
   80 NEXT P
   85 IF BTN END
   90 GOTO 40
What now?

Well, my plan is to offer it as a kit to solder up yourself and have a bit of minimalistic fun. you have 4K of RAM for your Basic program (3K more than the Sinclair ZX80!) so don't waste it. (Technically, 3328 bytes as Page 0, 1 and 2 are used by the system and Basic program start at $300) The full specification of it all is on my website - see the link below.

And realistically, if I sell 10 of these I'll be happy. This isn't my retirement project...

Comments here are welcome - maybe even suggestions. This year has been sent mostly on code golfing trying to squeeze the already full 4K code further so I can fit in the EEPROM protection code and the VIA GPIO code. This has come as a slight speed reduction, but that's the way it is.

Cheers,

-Gordon

Re: Project-28 - A somewhat Minimal 6502 system

Posted: Thu Jan 30, 2025 4:34 pm
by BigEd
Very nice! And good to see that code golfing come good for you.

Re: Project-28 - A somewhat Minimal 6502 system

Posted: Wed Feb 05, 2025 9:37 pm
by drogon
Just assembled a Mk-2 board:
project28-2.jpg
It's all working fine at 2Mhz and it fired up first time and auto-loaded my 'test' Larson scanner for the 4 LEDs. Just have to test the VIA now, but I'm not expecting any surprises there. (I did change the layout as the address decoding was "optimised" for PCB routing when I did it first time round - so that actually means a small code change in my wiring GPIO commands, but it's just a constant offset).

Meanwhile, on the software front, I've been squeezing and squeezing to fit in the GPIO commands and put back the 'call' command and I now have a "massive" 44 bytes spare... I'm thinking of a simple speaker and beep command... Hmmm.. (Open to suggestions, maybe!)

Cheers,

-Gordon

Re: Project-28 - A somewhat Minimal 6502 system

Posted: Thu Feb 06, 2025 7:36 am
by BigEd
Looks great! I think you have some amusing legends on there but I can't quite make them all out.

I gather the four-wire connector there is 5V power and TTL serial? Presumably there are many USB-serial cables which offer that interface... in fact I might even have one myself.

(The EEPROM is the writeable store, and holds a selection of Basic programs in slots - no need for SD Card, I think.)

Re: Project-28 - A somewhat Minimal 6502 system

Posted: Thu Feb 06, 2025 7:56 am
by drogon
BigEd wrote:
Looks great! I think you have some amusing legends on there but I can't quite make them all out.

I gather the four-wire connector there is 5V power and TTL serial? Presumably there are many USB-serial cables which offer that interface... in fact I might even have one myself.

(The EEPROM is the writeable store, and holds a selection of Basic programs in slots - no need for SD Card, I think.)
Ah yes. The Legends turned out a bit too close to the sockets ... So from the bottom up, we have:
  • Big IO - The 6522 VIA
  • Magic Glue - The GAL that does the address decoding and R/W qualifying. Also the 1-bit inputs.
  • Memories Saved and Lost - The RAM and the EEPROM - The RAM chip is under the EEPROM.
  • Brain Box - The 6507.
  • Latchy Loo - An 8-bit 74ALC573 which is the output register for the LEDs, the top 3 bits of the EEPROM address and the serial output.
  • The buttons are Push Me for the one-bit input (readable with the BTN command) and Reset.
  • Wobulator is the 2Mhz can oscillator.
The TTL serial - the pin ordering seems chaotic - I tried to find an adapter that might just plug in and I did at the time, but can't find it anymore, so flying leads it is.

And yes, the EEPROM is a 32KB device - 8 "slots" or "banks" of 4KB each. One for the TinyBasic and support code, 7 to store Basic programs - literally as memory images. There is no "filing system" although if your program starts with a Line 0 and a REM statement then that is printed out wih the DIR command.

Code: Select all

>DIR
 1:! Larson 4
 2: Larson4
 3: TV Plot Generator
 4: Pi - Spigot
 5: Sieve
 6: Mandelbrot
 7: Memory Dump
Any program in slot 1 that has REM! on the first line is automatically loaded and run at power on time.

I'll put a VIA in it today and test that too.

Code: Select all

>CH 3
TVPLOT
CREATIVE COMPUTING
MORRISTOWN, NEW JERSEY



This program automatically comes up with television
shows guaranteed to appeal to the masses and win
high Neilsen ratings.

Here is a sample plot:

THE STORY IS ABOUT A DODDERING TOWN MARSHALL WHO IS A DISASTER AT
WINNING RACES AND WHO SAVES THE ANIMALS.
-Gordon

Re: Project-28 - A somewhat Minimal 6502 system

Posted: Thu Feb 06, 2025 8:00 am
by BigEd
Ah yes, I see now you already said "The TinyBasic plus bit-banged serial IO and the code to access the button, LEDs and handle loading and saving Basic program to/from the EEPROM all fit into 4KB."

I like the auto-boot option!

Re: Project-28 - A somewhat Minimal 6502 system

Posted: Thu Feb 06, 2025 8:47 am
by drogon
It ran Mandelbrot overnight many times (about 10.5 minutes a run), and:

Code: Select all

    0 REM Sieve
  100 @=4
  110 REM Limit will be 78*29 so we fit a screen
  120 L=78*29-1
  130 C=TOP : $C=".*"
  135 Z=C+4 : REM The array
  140 PR "Init... ";
  150 FOR I = 0 TO L : ?(Z+I) = 1 : NEXT I
  160 ?(Z+0)=0:?(Z+1)=0 : REM We know 0 and 1 are not prime...
  180 REM Get upper limit - square root of the number we're looking at
  181 PR "Finding limit: ";
  190 S=L : GOSUB 1000 : U = Q
  200 PRINT "Upper limit is: ",U
  210 PRINT "Finding..."
  220 GOSUB 600
  225 PR ""
  230 GOSUB 2000
  240 END
  600 REM Find Primes
  610 F=2
  620 DO
  630  P=?(Z+F)
  640  IF P=1 GOSUB 800
  650  F=F+1
  660 UNTIL F > U
  670 RETURN
  800 REM Strikeout
  801 PR F;
  810 REM F is the found Prime. Uses J.
  820 J=F+F
  830 DO
  840  ?(Z+J)=0
  850  J=J+F
  860 UNTIL J >= L
  870 RETURN
 1000 REM Integer Square Root - Herons method.
 1010 REM Input: S, Output Q, uses X,Y
 1100 IF S < 2 Q=S : RETURN
 1110 X=S/2
 1120 Y=(S/X+X)/2
 1130 DO
 1140  X=Y
 1150  Y=(S/X+X)/2
 1160 UNTIL X <= Y
 1170 Q=X
 1180 RETURN
 2000 REM Print
 2010 REM Uses I,J
 2020 J=0:FOR I = 0 TO L
 2030  VDU ?(C+?(Z+I))
 2040  J=J+1:IF J=78 PR "" : J=0
 2050 NEXT I
 2060 RETURN
produces:

Code: Select all

>RUN
Init... Finding limit: sqrt ( 2261) is    47
Finding...
    2    3    5    7   11   13   17   19   23   29   31   37   41   43   47
..**.*.*...*.*...*.*...*.....*.*.....*...*.*...*.....*.....*.*.....*...*.*....
.*...*.....*.......*...*.*...*.*...*.............*...*.....*.*.........*.*....
.*.....*...*.....*.....*.*.........*.*...*.*...........*...........*...*.*...*
.....*.*.........*.....*.....*.....*.*.....*...*.*.........*.............*...*
.*...*.............*.....*.........*.*...*.....*.......*.....*.....*...*.....*
.......*...*.......*.........*.*.........*.*.....*...*.....*.......*...*.*...*
...........*.......*...*.......*...*.....*...........*.*.................*....
.*.........*.....*.....*.*.....*.........*.....*.....*.*.....*.....*...*.*....
.......*.........*.*...*.....*.....*.*...........*...*.....*.......*.........*
.......*.........*.......*.....*.....*...*.......*.....*...*.......*...*......
.......*.........*...........*.*.........*.*...*.*.........*.............*...*
.*...*.............*...*.*...*...................*...*.......*.........*......
.*...*.....*.....*.............*...*.....*.....*.......*.....*...........*...*
.....*.*.........*.*.....*.........*.*.........*.*.....*.................*...*
.*...*.....*.....*.......*.....*.....*.....................*.*.........*......
.*.........*.....*.....*.......*...........*...*.....*.....*.*.....*..........
.*.........*.................*.*...*.....*.*.....*...*.*...*...........*.*....
.*.................................*.....*.....*.......*.................*....
.....*.............*...*.*...*.....*.......*...*.*.....*...........*.........*
.*...*.*...*.....*...........*...........*.......*...........*.....*...*.....*
.......*...*.......*...*.............*...*.....*.*...*.....*.*.....*.........*
...................*.....*...*.*.......................*...*.*.........*......
.....*.*.........*.......*.....*.....*.....*.................*.....*...*.*....
.......*.........*...........*.......*...............*.............*.....*...*
.*...*.*.........*...........*.....*.....*.................*.*...............*
.*.....................*.....*.......*.....*...*.*...*.......*.....*.........*
.*.........*.............*.........*.....*...........*.*...*.*.........*......
.....*.*...............*.*.....*...*.*.........*.......*.................*....
...................*...*.....*.......*...............*.*...*.......*.........*
Which looks OK.

-Gordon

Re: Project-28 - A somewhat Minimal 6502 system

Posted: Thu Feb 06, 2025 9:26 am
by BigEd
I do like a sieve! Good idea to print a count?

Looks to me like the final number is marked as prime but isn't. Uh-oh.

Here are some primes:
1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011,2017, 2027,
2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099,
2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179,
2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251,
then
2267, 2269, 2273,

Re: Project-28 - A somewhat Minimal 6502 system

Posted: Thu Feb 06, 2025 10:27 am
by drogon
BigEd wrote:
I do like a sieve! Good idea to print a count?

Looks to me like the final number is marked as prime but isn't. Uh-oh.

Here are some primes:
1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011,2017, 2027,
2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099,
2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179,
2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251,
then
2267, 2269, 2273,
Good spot!

The error was line 860:

Code: Select all

  860 UNTIL J >= L
Ought to be:

Code: Select all

  860 UNTIL J > L
Now:

Code: Select all

>RUN
Init... Finding limit: Upper limit is:    47
Finding...
    2    3    5    7   11   13   17   19   23   29   31   37   41   43   47
..**.*.*...*.*...*.*...*.....*.*.....*...*.*...*.....*.....*.*.....*...*.*....
.*...*.....*.......*...*.*...*.*...*.............*...*.....*.*.........*.*....
.*.....*...*.....*.....*.*.........*.*...*.*...........*...........*...*.*...*
.....*.*.........*.....*.....*.....*.*.....*...*.*.........*.............*...*
.*...*.............*.....*.........*.*...*.....*.......*.....*.....*...*.....*
.......*...*.......*.........*.*.........*.*.....*...*.....*.......*...*.*...*
...........*.......*...*.......*...*.....*...........*.*.................*....
.*.........*.....*.....*.*.....*.........*.....*.....*.*.....*.....*...*.*....
.......*.........*.*...*.....*.....*.*...........*...*.....*.......*.........*
.......*.........*.......*.....*.....*...*.......*.....*...*.......*...*......
.......*.........*...........*.*.........*.*...*.*.........*.............*...*
.*...*.............*...*.*...*...................*...*.......*.........*......
.*...*.....*.....*.............*...*.....*.....*.......*.....*...........*...*
.....*.*.........*.*.....*.........*.*.........*.*.....*.................*...*
.*...*.....*.....*.......*.....*.....*.....................*.*.........*......
.*.........*.....*.....*.......*...........*...*.....*.....*.*.....*..........
.*.........*.................*.*...*.....*.*.....*...*.*...*...........*.*....
.*.................................*.....*.....*.......*.................*....
.....*.............*...*.*...*.....*.......*...*.*.....*...........*.........*
.*...*.*...*.....*...........*...........*.......*...........*.....*...*.....*
.......*...*.......*...*.............*...*.....*.*...*.....*.*.....*.........*
...................*.....*...*.*.......................*...*.*.........*......
.....*.*.........*.......*.....*.....*.....*.................*.....*...*.*....
.......*.........*...........*.......*...............*.............*.....*...*
.*...*.*.........*...........*.....*.....*.................*.*...............*
.*.....................*.....*.......*.....*...*.*...*.......*.....*.........*
.*.........*.............*.........*.....*...........*.*...*.*.........*......
.....*.*...............*.*.....*...*.*.........*.......*.................*....
...................*...*.....*.......*...............*.*...*.......*..........
Cheers,

-Gordon

Re: Project-28 - A somewhat Minimal 6502 system

Posted: Thu Feb 06, 2025 11:03 am
by drogon
A slighty more "classic" prime number generator:

Code: Select all

  100 PRINT "Find Prime numbers.."
  101 PRINT "Upper limit ";
  102 INPUT L
  105 Z = 0 : C = 0 : W = 10 : @ = 4
  106 W=20
  110 FOR N = 0 TO L
  120  GOSUB 800
  130  IF P GOSUB 900
  140 NEXT N
  150 IF C <> 0 THEN PRINT ""
  160 PRINT "Found ", Z, " primes."
  170 END
  800 REM Is it Prime?
  810 REM Input N, output P - true or false (1 or 0)
  811 REM
  820 IF N < 1 P = 0 : RETURN : REM 0 and 1 are not Prime
  830 IF N < 4 P = 1 : RETURN : REM 2 and 3 are Prime
  834 IF N%2 = 0 P = 0 : RETURN : REM Trivial case for even numbers
  840 S = N : GOSUB 1000 : U = Q : REM Test up to the sqrt of S
  845 T = 3
  850 REM
  860   IF N % T = 0 THEN P = 0 : RETURN
  870   T = T + 2
  880 IF T <= Q GOTO 850
  890 P = 1
  899 RETURN
  900 REM Print N 
  970 PR N;
  980 Z = Z + 1 : C = C + 1 : IF C > W PRINT "" : C = 0
  990 RETURN
 1000 REM Integer Square Root - Herons method.
 1010 REM     Input: S, Output Q, uses X,Y
 1100 IF S < 2 Q=S : RETURN
 1110 X=S/2
 1120 Y=(S/X+X)/2
 1130 DO
 1140  X=Y : Y=(S/X+X)/2
 1160 UNTIL X <= Y
 1170 Q=X
 1180 RETURN
Output:

Code: Select all

Find Prime numbers..
Upper limit ?2300
    1    2    3    5    7   11   13   17   19   23   29   31   37   41   43   47   53   59   61   67   71
   73   79   83   89   97  101  103  107  109  113  127  131  137  139  149  151  157  163  167  173  179
  181  191  193  197  199  211  223  227  229  233  239  241  251  257  263  269  271  277  281  283  293
  307  311  313  317  331  337  347  349  353  359  367  373  379  383  389  397  401  409  419  421  431
  433  439  443  449  457  461  463  467  479  487  491  499  503  509  521  523  541  547  557  563  569
  571  577  587  593  599  601  607  613  617  619  631  641  643  647  653  659  661  673  677  683  691
  701  709  719  727  733  739  743  751  757  761  769  773  787  797  809  811  821  823  827  829  839
  853  857  859  863  877  881  883  887  907  911  919  929  937  941  947  953  967  971  977  983  991
  997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123
 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289
 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451
 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597
 1601 1607 1609 1613 1619 1621 1627 1637 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747
 1753 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913
 1931 1933 1949 1951 1973 1979 1987 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083
 2087 2089 2099 2111 2113 2129 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251
 2267 2269 2273 2281 2287 2293 2297
Found   343 primes.
This did take a few minutes to run!

Oddly, I was considering removing the DO...UNTIL keywords when I was looking to squeeze more into it, but glad I left them in - however, here I can't use DO...UNTIL as I need (want) to break out of the loop on line 860. Wonder if I could include a BREAK sort of construct? Might not be that easy at first glance as FOR, DO, GOSUB all have their own stacks. MS Basics have a POP command to POP the Gosub stack - wonder if that might work here... Hm... the code might look like:

Code: Select all

  860   IF N % T = 0 THEN P = 0 : DPOP : RETURN
The DPOP simply removing the last entry on the DO stack - it wouldn't then do a GOTO the line after the UNTIL or anything... Of course I could just re-write the whole thing with a proper stack and frame pointer, but hey, this is TinyBasic after all ;-)



-Gordon

Re: Project-28 - A somewhat Minimal 6502 system

Posted: Thu Feb 06, 2025 12:09 pm
by drogon
Well, I added DPOP at the cost of 14 bytes. Currently I have 28 bytes spare, so I could add POP for Gosub/Return if needed.

The loop of the prime code now looks like:

Code: Select all

  850 DO
  860   IF N % T = 0 THEN P = 0 : DPOP: RETURN
  870   T = T + 2
  880 UNTIL T > Q
Is this a good thing? Who knows but I'll leave it there for now.

-Gordon

Re: Project-28 - A somewhat Minimal 6502 system

Posted: Thu Feb 06, 2025 12:31 pm
by BigEd
Is DPOP the same as UNTIL TRUE ?

Re: Project-28 - A somewhat Minimal 6502 system

Posted: Thu Feb 06, 2025 1:21 pm
by drogon
BigEd wrote:
Is DPOP the same as UNTIL TRUE ?

Er... Yes. (Although there is no TRUE keyword, but anything non-zero is TRUE, so: UNTIL1 ...

And a quick test:

Code: Select all

>860  IF N%T = 0 THEN P=0 : UNTIL1 : RETURN
Works.

Hmm..

So at the expense of slightly increased Basic source code size (it's not tokenised) I could claw back those 14 bytes...

Cheers,

-Gordon

Re: Project-28 - A somewhat Minimal 6502 system

Posted: Thu Feb 06, 2025 3:58 pm
by drogon
Testing the "wiring" GPIO commands on the Rev 2 board with the VIA and it's working well. I needed a "bodge wire" on the Rev 1 as I'd forgotten to wire up the VIAs enable line - I blamed my original breadboard version which didn't use the VIA...
IMG_20250206_155353_DRO.jpg
that's 10 LEDs on port A 0-7 and port B 0-1 and a button on port B7, or in wiring terms, pins 0-9 and 15.

Test code:

Code: Select all

    0 REM GPIO Test
   10 FOR I = 0 TO 10 : PM I,1 : NEXT I
   12 PM 15,0 : REM Input - button
   20 REM
   30 FOR P = 0 TO 10
   40   DW P,1
   50   GOSUB 200
   60 NEXT P
   70 REM
   80 FOR P = 0 TO 10
   90   DW P,0
  100   GOSUB 200
  120 NEXT P
  130 IF NOT DR 15 END
  140 GOTO 30
  199 REM
  200 D = 10
  210 DO : D = D - 1 : UNTIL D = 0
  220 RETURN
Running well - runs until I push the button, basically.

PM is PinMode, DW is digitalWrite and DR is digitalRead to mimic those used in the wiring programming/hardware system used in Arduinos and Raspbery Pis.


-Gordon

Re: Project-28 - A somewhat Minimal 6502 system

Posted: Thu Feb 06, 2025 4:25 pm
by BigEd
Really nice!