Teaching BASIC

Feel free to talk about any other retro stuff here including Commodore, Sinclair, Atari, Amstrad, Apple... the list goes on!
SerErris
Posts: 172
Joined: Sat Aug 08, 2020 9:18 am

Teaching BASIC

Post by SerErris »


6502 is also very bare bones ... you cannot even add x to a. I grew up on a Z80 and never understood why people loved the 6502. It is most likely a nostalgia thing, as the C64 were everywhere and people had access to a 6502 . Z80 was much more in UK and in Germany present and still compared to Commodore a fraction of the Market. However looking from today’s perspective the Z80 was much easier to program for real things. For learning assembler in general the 6502 is pretty good as it has only very few commands to learn. The addressing modes then makes it difficult to understand. Esp Indexing has some serious limitations that you need to work around and that no one would put in any CPU anymore those days.

User avatar
StephenHorn
Posts: 565
Joined: Tue Apr 28, 2020 12:00 am
Contact:

Teaching BASIC

Post by StephenHorn »



2 hours ago, SerErris said:




6502 is also very bare bones ... you cannot even add x to a. I grew up on a Z80 and never understood why people loved the 6502. It is most likely a nostalgia thing, as the C64 were everywhere and people had access to a 6502 . Z80 was much more in UK and in Germany present and still compared to Commodore a fraction of the Market. However looking from today’s perspective the Z80 was much easier to program for real things. For learning assembler in general the 6502 is pretty good as it has only very few commands to learn. The addressing modes then makes it difficult to understand. Esp Indexing has some serious limitations that you need to work around and that no one would put in any CPU anymore those days.



One of the differences between the Z80 and the 6502, it sounds like, is that the 6502 effectively only had the accumulator. For additional general-purpose registers, most folks looked to ZP memory, which could be accessed more quickly than the rest of memory. The X and Y registers are not intended to be general-purpose, they are index registers. There's just enough power in the opcodes to blur that distinction a little, though, so I can understand the confusion.

Developer for Box16, the other X16 emulator. (Box16 on GitHub)
I also accept pull requests for x16emu, the official X16 emulator. (x16-emulator on GitHub)
StinkerB06
Posts: 74
Joined: Tue Jun 30, 2020 12:32 am

Teaching BASIC

Post by StinkerB06 »



54 minutes ago, StephenHorn said:




The X and Y registers are not intended to be general-purpose, they are index registers. There's just enough power in the opcodes to blur that distinction a little, though, so I can understand the confusion.



Yeah, especially with LDX, STX, LDY, and STY. You'd normally use the accumulator when doing memory transfers (i.e. with LDA & STA'ing), but you can indeed do the same with the X and Y, just with less addressing modes.

For example, the standard 6502 has increment/decrement instructions that can only be performed on index registers or directly on memory contents (i.e. RMW), but not the accumulator. If I want to do a "dest=src+1", then I'd use an LDX/INX/STX triplet. Changing the X's to Y's will work just fine as well. However, changing them to A's won't work (needs ADC with relevant CLC/SEC), but thankfully, the 65C02 in the CX16 added INA and DEA, so I can be able to use the accumulator for this operation.

User avatar
StephenHorn
Posts: 565
Joined: Tue Apr 28, 2020 12:00 am
Contact:

Teaching BASIC

Post by StephenHorn »



32 minutes ago, StinkerB06 said:




the 65C02 in the CX16 added INA and DEA, so I can be able to use the accumulator for this operation



Those opcodes are not listed in the reference I've been using (http://www.obelisk.me.uk/65C02/reference.html), nor any other 65C02 references I've found, including the datasheet for the WDC 65C02S. Also, they are not implemented in the emulator.

Developer for Box16, the other X16 emulator. (Box16 on GitHub)
I also accept pull requests for x16emu, the official X16 emulator. (x16-emulator on GitHub)
StinkerB06
Posts: 74
Joined: Tue Jun 30, 2020 12:32 am

Teaching BASIC

Post by StinkerB06 »



8 minutes ago, StephenHorn said:




Those opcodes are not listed in the reference I've been using (http://www.obelisk.me.uk/65C02/reference.html), nor any other 65C02 references I've found, including the datasheet for the WDC 65C02S. Also, they are not implemented in the emulator.



INA and DEA are alternative mnemonics for "INC A" and "DEC A", to be consistent with the X and Y equivalents.

SlithyMatt
Posts: 913
Joined: Tue Apr 28, 2020 2:45 am

Teaching BASIC

Post by SlithyMatt »


Do any assemblers use INA or DEA? I've never seen that mnemonic before. For ca65 you just use implicit INC and DEC, as long as you are specifying a 65C02 target.

StinkerB06
Posts: 74
Joined: Tue Jun 30, 2020 12:32 am

Teaching BASIC

Post by StinkerB06 »


From Wikipedia:

INC and DEC with no parameters now increment or decrement the accumulator. This was an odd oversight in the original instruction set, which only included INX/DEX,INY/DEY and INC addr/DEC addr. Some assemblers use the alternate forms INA/DEA or INC A/DEC A.

BruceMcF
Posts: 1336
Joined: Fri Jul 03, 2020 4:27 am

Teaching BASIC

Post by BruceMcF »



On 8/28/2020 at 9:49 PM, SerErris said:




6502 is also very bare bones ... you cannot even add x to a. I grew up on a Z80 and never understood why people loved the 6502.



It was an actually reduced instruction set processor before the instruction set got expanded ... so without the dogma.

When you are used to the Z80, your reaction is "how can I do as much as possible in the registers" because with four clock cycles to each memory cycle, going out memory is expensive.With the 6502, your reaction is "how can I do as much as possible in zero page, because you save 20% to 25% of your clock cycles on a Read-Modify-Write.

But the most complex instruction only takes six clock cycles, so a 6502 programmer looks at a z80 instruction set and sees instructions that take 15 or 23 clock cycles and asks, " wait a minute, is that a typo?"

And some of the oversights in the 6502 are fixed in the 65C02 ... the fastest generally practical direct threaded Forth "NextOp" in the NMOS 6502 is self modifying in the zero page:

DoNext: INC IPV+1 : INC IPV+1 : BEQ +

IPV: JMP (COLD)

+ INC IPV+2 : BRA IPV ; = 20clock cycles including JMP DoNext, 29 on pages crossing

... and it requires aligned addresses, which is a pain. Meanwhile a faster 65C02 DoNext is:

DoNext: INX : INX : JMP (COLD,X) ; 13 cycles, including JMP NextOp at end of primitives.

... with updating the instruction pointer deferred until calling high level calls or executing branches.

 

SerErris
Posts: 172
Joined: Sat Aug 08, 2020 9:18 am

Teaching BASIC

Post by SerErris »


Yep, that might be a thing and the approach is different. However the Z80 had so much other thing (other than the memory access issue) like 16bit index registers and other stuff. The concept of pages in memory was also completely new to me, as the Z80, did not know any pages. 

But anyhow .. the beauty of the 6502 is that it is very easy to learn. On the other hand it is at the same time very difficult to master. You need to be either very bright, or read a lot of stuff that is not officially documented, but hidden everywhere (like in this thread now ? ). 

Thanks @BruceMcF for the knowledge sharing .. appreciate it.

BruceMcF
Posts: 1336
Joined: Fri Jul 03, 2020 4:27 am

Teaching BASIC

Post by BruceMcF »


I really think that the 6502 is not harder to master if it's your first processor, rather it's harder to master if it's your second or later. The peculiarities are not on their own hard to master, what is hard to overcome are habits of thought assuming more orthogonal operations.

"I want to do a post-indexed indirect, which index register is that again?" is a question of someone who has originally learned programming on a chip with multiple registers able to do a set of indirect addressed operations. Someone who learns the 65C02 at the outset thinks, "I want to do an (a),Y" and which register it is that can do it is not a question. Indeed, since I learned 6502 programming by the seat of my pants, I've had to unlearn some bad habits to get xForth working reliably ... like trying to use BMI and BPL after a CMP operation for an unsigned comparison instead of using BCC and BCS.

The Z80 is DEFINITELY kinder to high level languages. A main reason I would like a CP/M box of a Z80 and it's own RAM, calling a support program in the CX16 for it's I/O, are all of the old classic languages available in CP/M ... not only multiple Forth's and both interpreted and compiled Basic's, but also bytecode & Turbo Pascal, Aztec, BDS, and Mix C, and the original self-hosting Small C, Microsoft Fortran and Cobol, Nevada Fortran and Cobol, Modula2, APL, Ada, etc.

A CP/M box is a 1970's and 1980's "living programming history in a can".

Post Reply