Improved MENSCH™ Microcomputer Software

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Martin_H
Posts: 837
Joined: 08 Jan 2014

Improved MENSCH™ Microcomputer Software

Post by Martin_H »

In the hardware subforum I documented the design and build of my w65c265 SBC. See: viewtopic.php?f=4&t=7630

Now that it's working, I am writing a set of Arduino like examples using 65816 assembly in native mode. The goal is to first learn that assembler, but also to create a library of functions for things like PWM, RC Servo control, and timing input pulse widths.

Here's a link to my Github repo: https://github.com/Martin-H1/65816/tree ... 20Reloaded

The toolchain I'm using is make, ca65, ld65, srec_cat. This results in s record files that I can upload using the w65c265's monitor ROM. Eventually I will create a custom EEPROM with a Forth kernel, but I wanted to get a feel for the hardware first.
Martin_H
Posts: 837
Joined: 08 Jan 2014

Re: Improved MENSCH™ Microcomputer Software

Post by Martin_H »

The journey of a robot control library starts with a blink sample: https://www.youtube.com/shorts/JZgF9ZxpzOM

I have to show you guys because my wife saw it and was underwhelmed. At least she didn't point out that I could have used a 555 timer and saved a lot of time and money.
User avatar
BigDumbDinosaur
Posts: 9427
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Improved MENSCH™ Microcomputer Software

Post by BigDumbDinosaur »

Martin_H wrote:
I have to show you guys because my wife saw it and was underwhelmed.
I suspect she would be underwhelmed if you had managed to fire a rocket and have it hit Mars.  Wives can be like that...I have one who’s the same way.  :D
Quote:
At least she didn't point out that I could have used a 555 timer and saved a lot of time and money.
That’s only because she didn’t want to hurt your feelings.  :lol:
x86?  We ain't got no x86.  We don't NEED no stinking x86!
barnacle
Posts: 1831
Joined: 19 Jan 2004
Location: Potsdam, DE
Contact:

Re: Improved MENSCH™ Microcomputer Software

Post by barnacle »

Mine is underwhelmed by my efforts to keep mental degradation at bay. "What does it do when it's finished?" and "Are you swearing at Microsoft?" are her favorites... along with "Why isn't the mouse working?". :mrgreen:

Neil
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: Improved MENSCH™ Microcomputer Software

Post by BigEd »

Moaning about your chosen life partner - very cringe. And not a good look, for a forum which seeks new and younger members of all kinds.
User avatar
BigDumbDinosaur
Posts: 9427
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Improved MENSCH™ Microcomputer Software

Post by BigDumbDinosaur »

BigEd wrote:
Moaning about your chosen life partner - very cringe. And not a good look, for a forum which seeks new and younger members of all kinds.
Lighten up, Ed.  We’re joking, not complaining.  My wife is actually quite supportive of my hobby activities.  She is also quite adept at helping me come to my senses when I go off on a tangent.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
Martin_H
Posts: 837
Joined: 08 Jan 2014

Re: Improved MENSCH™ Microcomputer Software

Post by Martin_H »

@Neil and BDD, I showed my wife this thread and she thought it was a hoot.

No progress on the library today because I turned an oil lamp for my wife as an anniversary present.

https://youtube.com/shorts/0fAgXcp8KEc
barnacle
Posts: 1831
Joined: 19 Jan 2004
Location: Potsdam, DE
Contact:

Re: Improved MENSCH™ Microcomputer Software

Post by barnacle »

Thanks Martin. That's a nice piece - what's the wood? Your video didn't say.

Neil
Martin_H
Posts: 837
Joined: 08 Jan 2014

Re: Improved MENSCH™ Microcomputer Software

Post by Martin_H »

barnacle wrote:
That's a nice piece - what's the wood? Your video didn't say.
Thanks, it's Bolivian coffeewood. I couldn't remember while recording the video, so I just added that to the title and description. I had to look it up as I often buy turning blanks and let them sit until I can think of a project for them. By that time, I have often forgotten what wood it is or where I bought it. Fortunately, I found the receipt this time.
User avatar
BigDumbDinosaur
Posts: 9427
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Improved MENSCH™ Microcomputer Software

Post by BigDumbDinosaur »

Martin_H wrote:
No progress on the library today because I turned an oil lamp for my wife as an anniversary present.
That is indeed a fine piece of craftsmanship.  One question, though.

How were you able to fit the 65C02 inside of it, along with the oil burner?  :D  And, when the C02 needs to do some I/O, does it communicate with smoke signals?  :lol:

Just kidding and happy anniversary!
x86?  We ain't got no x86.  We don't NEED no stinking x86!
Martin_H
Posts: 837
Joined: 08 Jan 2014

Re: Improved MENSCH™ Microcomputer Software

Post by Martin_H »

BigDumbDinosaur wrote:
Just kidding and happy anniversary!
Thanks!
Martin_H
Posts: 837
Joined: 08 Jan 2014

Re: Improved MENSCH™ Microcomputer Software

Post by Martin_H »

A decade ago, I ported the Arduino library to the Parallax Propeller microcontroller. I learned a ton about the Arduino library and microcontroller programming. Initially I considered a similar approach for this project, but that library requires a C++ compiler and is overkill anyway. Instead, I decided to write a subset of the PBasic functions. See: https://www.parallax.com/go/PBASICHelp/ ... phaRef.htm

For this library I will access VIA port A and B as an array of pins numbered 0 to 15. So far, I have written and debugged: pbHigh, pbInput, pbLow, pbOutput, pbPause, and pbToggle. In progress are: pbCount, pbFreqOut, pbPulsin, pbPulsout, pbPWM, and pbRCTime

I rewrote my blink sample to use these functions and then had it blink different pins.

Current code: https://github.com/Martin-H1/65816/tree ... 20Reloaded

I don't know if anyone on this forum has used PBasic or the Basic Stamp, but it was my first exposure to microcontroller programming. It has an integer Basic language with a simple set of I/O functions that is surprisingly capable of generating real time control signals or reading sensor data. You could bit bang I2C or SPI or talk to a GPS receiver. Lots of fun while being a low drama programming environment.
barnacle
Posts: 1831
Joined: 19 Jan 2004
Location: Potsdam, DE
Contact:

Re: Improved MENSCH™ Microcomputer Software

Post by barnacle »

I have used the Basic Stamp - but not for nearly forty years.

I used one at each end of a serial data link - one end in London, one end in Delhi - where I was allowed a bit budget on the order of bits per second (a 64kbs satellite link carried the signal; this was before common internet) to update a screen at the far end. I got it working within the constraints, but it was, as I recall, somewhat tricky.

Neil
Martin_H
Posts: 837
Joined: 08 Jan 2014

Re: Improved MENSCH™ Microcomputer Software

Post by Martin_H »

A 65816 and 6522 programming question. The following code shifts into 8-bit accumulator mode to set and test various 6522 register.

Code: Select all

PUBLIC pbPause
	tax
	OFF16MEM		; enter byte transfer mode.
@while:
	stz VIA_BASE+VIA_ACR	; select one shot mode
	lda #<ONE_MS		; one ms delay duration
	sta VIA_BASE+VIA_T2CL	; set lower latch
	lda #>ONE_MS
	sta VIA_BASE+VIA_T2CH	; set upper latch
	lda #T2IF		; start mask
@loop:	bit VIA_BASE+VIA_IFR	; time out?
	beq @loop
	lda VIA_BASE+VIA_T2CL	; clear timer 2 interrupt
	dex
	bpl @while
	ON16MEM
	rts
ENDPUBLIC
It occurs to me that I could stay in 16-bit accumulator mode if I accepted two side effects.

Code: Select all

PUBLIC pbPause
	tax
@while:
	stz VIA_BASE+VIA_ACR	; select one shot mode, Side effect: also zero PCR register.
	lda #ONE_MS			; one ms delay duration
	sta VIA_BASE+VIA_T2CL	; set lower and upper latch
	lda #T2IF				; start mask
@loop:
	bit VIA_BASE+VIA_IFR	; time out? Side effect: also read the IER.
	beq @loop
	lda VIA_BASE+VIA_T2CL	; clear timer 2 interrupt
	dex
	bpl @while
	rts
ENDPUBLIC
The modified code works, but how bad are the side effects?
User avatar
Dr Jefyll
Posts: 3526
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: Improved MENSCH™ Microcomputer Software

Post by Dr Jefyll »

Martin_H wrote:
The modified code works, but how bad are the side effects?
Perhaps the side effects are tolerable under the present circumstances, but at the very least you'd need to add some conspicuous comments to the code to warn your future self about the potential booby trap that awaits if you start using additional VIA functions (and a nasty little trap it could turn out to be, with subtle and un-intuitive symptoms).

Just my own opinion, but I'd say it's not worth the risk... especially when you consider that your OFF16MEM and ON16MEM macros, which actually deal with the problem, are so easy to use. Indeed, it's probably best to make a habit of embracing those macros (rather than trying to avoid them). For better or for worse, we're stuck with the 816's 8-/16-bittedness! Might as well adapt and become accustomed to it! (particularly when dealing with I/O)

-- Jeff
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
Post Reply