6502 with a serial port - a minimal monitor?

Programming the 6502 microprocessor and its relatives in assembly and other languages.
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Re: 6502 with a serial port - a minimal monitor?

Post by 8BIT »

Here's the package. Assembles into $F700-$FFFF (2303 bytes).

There's a readme file included. Just fix the ACIA1.asm code for your terminal, and assemble.

Daryl
Attachments
SBC2OSLite.zip
(61.71 KiB) Downloaded 120 times
Please visit my website -> https://sbc.rictor.org/
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Re: 6502 with a serial port - a minimal monitor?

Post by 8BIT »

I just realized that I had the CRC tables in the upload.asm files. I can save another 512 bytes of ROM by generating the tables in RAM, as long as there's enough RAM in the target. The new code is < 2k (1792 bytes). The tables need to be placed in RAM where they won't get overwritten by the files being downloaded.

The new file is attached with added directions in the readme.

Daryl
Attachments
SBC2OSLiter.zip
This version generates the CRC tables in RAM - saves 512 bytes of ROM
(59.72 KiB) Downloaded 113 times
Please visit my website -> https://sbc.rictor.org/
User avatar
enso
Posts: 904
Joined: 29 Sep 2012

Re: 6502 with a serial port - a minimal monitor?

Post by enso »

8BIT wrote:
...I can save another 512 bytes of ROM by generating the tables in RAM, as long as there's enough RAM in the target. The new code is < 2k (1792 bytes)...
That is great! I was about to ask you if it's possible to bring the size under 2K as I am having a really hard time loading multiple 2K BRAMs...

Thanks again! I will try to integrate your code today.
In theory, there is no difference between theory and practice. In practice, there is. ...Jan van de Snepscheut
User avatar
Arlet
Posts: 2353
Joined: 16 Nov 2010
Location: Gouda, The Netherlands
Contact:

Re: 6502 with a serial port - a minimal monitor?

Post by Arlet »

Instead of using CRC tables, you could also update the CRC by code. It'll be slower, but with a 50/100MHz core, it's probably fast enough for practical purposes.
User avatar
enso
Posts: 904
Joined: 29 Sep 2012

Re: 6502 with a serial port - a minimal monitor?

Post by enso »

I presume CRC is for XModem... personally I haven't had any issues just sending binaries across the serial port, assuming the handshaking works...
In theory, there is no difference between theory and practice. In practice, there is. ...Jan van de Snepscheut
User avatar
enso
Posts: 904
Joined: 29 Sep 2012

Re: 6502 with a serial port - a minimal monitor?

Post by enso »

Oy! I didn't realize the monitor is full of 65C02 instructions... Arlet's core does 6502 only. Why isn't anything easy?
In theory, there is no difference between theory and practice. In practice, there is. ...Jan van de Snepscheut
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Re: 6502 with a serial port - a minimal monitor?

Post by 8BIT »

enso wrote:
I presume CRC is for XModem... personally I haven't had any issues just sending binaries across the serial port, assuming the handshaking works...
Yes, xmodem uses it for error detection. When sending binaries, do you have to give your receiver code the start address and file length, or is it embedded in the binary. Also, from the terminal side, how do you send a raw binary file? I tried that a long time ago but the only way to send a raw file was a text file. The programs seemed to skip sending 0x00 and sometimes 0x1b (Esc). That's when I resorted to writing the xmodem code.

Daryl
Please visit my website -> https://sbc.rictor.org/
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Re: 6502 with a serial port - a minimal monitor?

Post by 8BIT »

enso wrote:
Oy! I didn't realize the monitor is full of 65C02 instructions... Arlet's core does 6502 only. Why isn't anything easy?
Easy would be nice.... I can take a look and fix the code - should not be too hard. I can switch Tass to only assemble 6502 opcodes.

Daryl
Please visit my website -> https://sbc.rictor.org/
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: 6502 with a serial port - a minimal monitor?

Post by GARTHWILSON »

8BIT wrote:
enso wrote:
I presume CRC is for XModem... personally I haven't had any issues just sending binaries across the serial port, assuming the handshaking works...
Yes, xmodem uses it for error detection. When sending binaries, do you have to give your receiver code the start address and file length, or is it embedded in the binary. Also, from the terminal side, how do you send a raw binary file? I tried that a long time ago but the only way to send a raw file was a text file. The programs seemed to skip sending 0x00 and sometimes 0x1b (Esc). That's when I resorted to writing the xmodem code.
Intel hex (or other hex output, like Mot S19) works, since assemblers generally produce these anyway for EPROM programmers. I've used it sometimes, and in fact my PIC programmer (using the workbench computer) uses it, as if the PC were printing the Intel hex file to a serial (RS-232) printer but really the workbench computer takes it and puts it in RAM to program into the PIC.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
User avatar
BigDumbDinosaur
Posts: 9426
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: 6502 with a serial port - a minimal monitor?

Post by BigDumbDinosaur »

8BIT wrote:
enso wrote:
I presume CRC is for XModem... personally I haven't had any issues just sending binaries across the serial port, assuming the handshaking works...
Yes, xmodem uses it for error detection. When sending binaries, do you have to give your receiver code the start address and file length, or is it embedded in the binary. Also, from the terminal side, how do you send a raw binary file? I tried that a long time ago but the only way to send a raw file was a text file. The programs seemed to skip sending 0x00 and sometimes 0x1b (Esc). That's when I resorted to writing the xmodem code.

Daryl

I use Motorola S-records for transmitting code to POC. No need for something as convoluted as Xmodem on a short-range (under 50 meters) serial link, as long as a reliable form of handshaking is in place. Motorola S-record (or Intel hex) has a built-in error checking regime that is adequate for such usage, and is faster.

Xmodem and its progeny are primarily of value when data goes through modems. Even then, Xmodem is of questionable value, since all modern modems are capable of error checking in hardware.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
Arlet
Posts: 2353
Joined: 16 Nov 2010
Location: Gouda, The Netherlands
Contact:

Re: 6502 with a serial port - a minimal monitor?

Post by Arlet »

8BIT wrote:
Also, from the terminal side, how do you send a raw binary file?
Use TeraTerm. Not only does it have an option to send binary files, but it also supports a scripting language, so you can write complete upload scripts.
User avatar
enso
Posts: 904
Joined: 29 Sep 2012

Re: 6502 with a serial port - a minimal monitor?

Post by enso »

8BIT wrote:
... I can take a look and fix the code - should not be too hard...
That would be great. There are only a few places but I am worried about side effects as I am not familiar with your flag and register usage.

I've been using GtkTerm - it lets you send a binary. It doesn't have scripting, but allows you to see and send hex bytes and twiddle handshaking lines, which is nice for debugging the serial port.

EDIT: in Linux you can also

Code: Select all

cp <file> /dev/ttyUSB0
. Some terminals don't lock the serial port so you can copy while the terminal is open. You can do a similar copy in windows, although I can't remember the exact syntax for the serial port.
In theory, there is no difference between theory and practice. In practice, there is. ...Jan van de Snepscheut
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Re: 6502 with a serial port - a minimal monitor?

Post by 8BIT »

If the consensus is that xmodem is of no value, then it can be removed - reducing the Monitor to <1k. It would be about 1.5k with the Intel-hex downloader still on board. Those two are combined in one file but could be split apart if desired. It's pretty easy to modify the Monitor code to support more or less commands.

Enso, you can remove the xmodem code and replace with your own binary file transfer code if that is your preference. I can show you how to integrate it into the Monitor.

Will try to work on the 65C02-> 6502 code tonight.

Daryl
Please visit my website -> https://sbc.rictor.org/
User avatar
enso
Posts: 904
Joined: 29 Sep 2012

Re: 6502 with a serial port - a minimal monitor?

Post by enso »

8BIT wrote:
...I can show you how to integrate it into the Monitor....
I would appreciate any help you can offer. I will be happy to add binary transfer commands (it should be a couple lines of code).

BTW, having the monitor well under 2K is great as it allows us to use the same 2K BRAM for both hight ROM/vector/monitor ROM and page 0 and 1 RAM.

Thank you again for all the help :) I think your minimal monitor/loader will be a great asset to our community. I know I personally could have used it a few times in the last few years.
In theory, there is no difference between theory and practice. In practice, there is. ...Jan van de Snepscheut
User avatar
enso
Posts: 904
Joined: 29 Sep 2012

Re: 6502 with a serial port - a minimal monitor?

Post by enso »

I wrote a little parser that reads tass files and with the intention of writing out Kingswood-compatible files. Right now it just dumps the lines to the output file, fields separated by |

It splits each assembly line into 4 fields (label,opcode,operand,comment) and gives you a chance to process it and write it out. It is very easy to adapt to output any kind of code (and possibly turn into an assembler...)

I wrote it in python as I always wanted to learn it, and it seems like a pretty good language for text manipulation. Until today I haven't written a line of python - it is pretty easy (I am sure my code is terrible for those who know the language - suggestions welcome)

Code: Select all

#!/usr/bin/env python3
import sys
fileIn = open(sys.argv[1], "r")
fileOut = open("out.txt","w")
line = fileIn.readline()
lineno=0
 
while line:
  label=''
  opcode=''
  operand=''
  comment=''
  lineno=lineno+1
  #Comment lines must be skipped
  if not line.strip().startswith(';'): #first character is ;
  #split off the label
    x = line.partition(' ')
    if x[1]==' ': #split successful
      label=x[0].strip()
      l=x[2].strip()
      #now split off the comment
      x = l.partition(';')
      if x[1]==';':
        comment=';'+x[2].strip()
        l=x[0].strip()
      #now separate opcode and operand
      x=l.partition(' ')
      opcode=x[0].strip()
      if x[1]==' ':
        operand=x[2].strip()
  #unchanged line write on empty (which happens for comment-only lines too)
  if not label and not opcode and not comment:
    fileOut.write(line)
    line = fileIn.readline()
    continue

  # pad the columns
  label = label.ljust(16,' ')   #pad label column
  opcode = opcode.ljust(6,' ')
  operand = operand.ljust(18,' ')
#-----------------------------------------------
# write line
  fileOut.write ('%s\n' % '|'.join(map(str, [label,opcode,operand,comment]) ))
  line = fileIn.readline()

EDIT: fixed errors.

Strategy:
  • -skip lines containing only comments
    -separate the label (must begin in first column and end with whitespace)
    -separate the comment (anything after ; )
    -split the remaining part into opcode and operand at the first whitespace
Output looks like:

Code: Select all

                |bne   |Asm_txt9          ; no, closing, so done
                |bra   |Asm_txt1          ; yes, get first text chr
Asm_txt3        |cpy   |#$ff              ; already found opening "?
                |beq   |Asm_txt4          
                |sta   |(AddrPtr),y       ; yes, save chr
In theory, there is no difference between theory and practice. In practice, there is. ...Jan van de Snepscheut
Post Reply