Gonna Learn 6510 ML Code

Anything you like and probably not related to Bard's Tale
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Gonna Learn 6510 ML Code

Post by Darendor »

Alright, given how I'm interested obsessed in trying to make a C64 Bard's Tale Game Maker program, it occurs to me I need to seriously learn how ML works.

Every time I see something like "ORA($3100,Z)" I get a little frightened and concerned, and this should not be.

Does anyone have any recommendations? Like some kind of retro online course or do I just find a bunch of books at the library? :?


Any advice is welcome.
Methuselas
Posts: 347
Joined: Tue Apr 28, 2009 11:03 pm

Re: Gonna Learn 6510 ML Code

Post by Methuselas »

Had to dig through a bunch of old Amiga bookmarks to find this, but I hope it helps. Will post more, if I find them:

https://www.commodore.ca/manuals/c64_pr ... nguage.pdf
"Using No Way as Way; Having No Limitation As Limitation". - Bruce Lee.

BTBuilder Stuff - https://drive.google.com/folderview?id= ... sp=sharing
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Re: Gonna Learn 6510 ML Code

Post by Darendor »

Ah the Holy Grail of C64 ML programming. Of course!

The PRG also references this book here: http://archive.6502.org/books/mcs6500_f ... manual.pdf

Gonna have a ton of Google Chrome windows open I think. :roll:


Thank you, by the way.
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Re: Gonna Learn 6510 ML Code

Post by Darendor »

Holy sh...ovels.

I'm reading this and it's blowing my mind.

Code: Select all

2.2.4.3 EOR— "Exclusive OR" Memory with Accumulator
The EOR instruction transfers the memory and the accumulator
to the adder which performs a binary "EXCLUSIVE OR" on a bit-by-bit
basis and stores the result in the accumulator.
This is indicated symbolically by A ^ M -* A.
This instruction affects the accumulator; sets the zero flag
if the result in the accumulator is 0, otherwise resets the zero flag
sets the negative flag if the result in the accumulator has bit 7 on,
otherwise resets the negative flag.
EOR is a "Group One" instruction having addressing modes of
Immediate; Absolute; Zero Page; Absolute,X; Absolute,?; Zero Page,X;
Indexed Indirect; and Indirect Indexed.
One of the uses of the EOR instruction is in complementing
bytes. This is accomplished below by exclusive ORA-ing the byte with
all l ’s.
Example 2.21: Complementing a byte with EOR
LDA 1010 1111
EOR 1111 1111
STA 0101 0000
What does "complementing a byte" even mean? "Hi there Mr Byte, you sure do look nice in those shoes today!" :?
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Re: Gonna Learn 6510 ML Code

Post by Darendor »

Wait a minute, I just figured it out.

Eeyore - I mean, EOR - turns all bits that are ON to OFF, and all bits that are OFF, to ON.

The 4 sets of bits immediately beside LDA, EOR and STA were throwing me off, I think.
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Re: Gonna Learn 6510 ML Code

Post by Darendor »

But then again, why bother with Eeyore - EOR - when you can just program the byte directly:

Code: Select all

LDA #$09 (9 for instance)
STA $0802 (store byte 9 at memory location 802)

Hmm. Mysteries.
Methuselas
Posts: 347
Joined: Tue Apr 28, 2009 11:03 pm

Re: Gonna Learn 6510 ML Code

Post by Methuselas »

Is it helping, at least?

If not, maybe something here will:

http://69.60.118.202/commodore/index.htm
"Using No Way as Way; Having No Limitation As Limitation". - Bruce Lee.

BTBuilder Stuff - https://drive.google.com/folderview?id= ... sp=sharing
drifting
Posts: 152
Joined: Wed Dec 07, 2011 10:21 pm

Re: Gonna Learn 6510 ML Code

Post by drifting »

Darendor wrote: Thu Feb 21, 2019 11:47 am Wait a minute, I just figured it out.

Eeyore - I mean, EOR - turns all bits that are ON to OFF, and all bits that are OFF, to ON.

The 4 sets of bits immediately beside LDA, EOR and STA were throwing me off, I think.
That isn't right. EOR turns off all bits that are 1 in both numbers or 0 in both numbers. If both bits are 1, then the result is 0. If both bits are 0, then the result is also zero. If one bit is 1 and the other is 0 then the result is 1. The logic table is

Code: Select all

 A  |  B  |  R
 -------------
 0  |  0  |  0
 0  |  1  |  1
 1  |  0  |  1
 1  |  1  |  0
In x86 assembly it's used a lot to set a register to 0. xor ax, ax is very common in x86 assembler since it takes fewer cycles than setting the register directly via mov ax, 0
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Re: Gonna Learn 6510 ML Code

Post by Darendor »

drifting wrote: Fri Feb 22, 2019 7:26 am
Darendor wrote: Thu Feb 21, 2019 11:47 am Wait a minute, I just figured it out.

Eeyore - I mean, EOR - turns all bits that are ON to OFF, and all bits that are OFF, to ON.

The 4 sets of bits immediately beside LDA, EOR and STA were throwing me off, I think.
That isn't right. EOR turns off all bits that are 1 in both numbers or 0 in both numbers. If both bits are 1, then the result is 0. If both bits are 0, then the result is also zero. If one bit is 1 and the other is 0 then the result is 1. The logic table is

Code: Select all

 A  |  B  |  R
 -------------
 0  |  0  |  0
 0  |  1  |  1
 1  |  0  |  1
 1  |  1  |  0
In x86 assembly it's used a lot to set a register to 0. xor ax, ax is very common in x86 assembler since it takes fewer cycles than setting the register directly via mov ax, 0
Can you explain what the 2 numbers are exactly?

I guess I'd need to see it in an example mode.

Code: Select all

LDA $0400
LDX $0800
EOR A,X
BEQ [somewhere else]
RTS
Is that more accurate? Apologies if I've missed it again.

I'd really like to nail this arithmetic portion because if I can figure all this out it'll make the rest more or less a breeze.
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Re: Gonna Learn 6510 ML Code

Post by Darendor »

Methuselas wrote: Fri Feb 22, 2019 6:35 am Is it helping, at least?

If not, maybe something here will:

http://69.60.118.202/commodore/index.htm
It is actually. I'm finding myself reading through the entire ML section.

I have a WINVICE window with a 64MON cartridge installed and I'm very, very slowly (timidly) attempting to experiment with code.
drifting
Posts: 152
Joined: Wed Dec 07, 2011 10:21 pm

Re: Gonna Learn 6510 ML Code

Post by drifting »

Darendor wrote: Fri Feb 22, 2019 10:28 am Can you explain what the 2 numbers are exactly?

I guess I'd need to see it in an example mode.

Code: Select all

LDA $0400
LDX $0800
EOR A,X
BEQ [somewhere else]
RTS
Is that more accurate? Apologies if I've missed it again.

I'd really like to nail this arithmetic portion because if I can figure all this out it'll make the rest more or less a breeze.
The two numbers of the EOR instruction are:
  1. The value in A
  2. The number in the EOR instruction
An example:

Code: Select all

LDA #$80		; Load #$80 into A
EOR #$04		; Do an exclusive or on A (#$80) and #$04
BEQ [somewhere]		; The result of which is #$84 so do not branch
RTS			; Return
Methuselas
Posts: 347
Joined: Tue Apr 28, 2009 11:03 pm

Re: Gonna Learn 6510 ML Code

Post by Methuselas »

The second link I gave you, has a bunch of games that are in ML code. You might want to also look at those.
"Using No Way as Way; Having No Limitation As Limitation". - Bruce Lee.

BTBuilder Stuff - https://drive.google.com/folderview?id= ... sp=sharing
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Re: Gonna Learn 6510 ML Code

Post by Darendor »

So drifting, if I read your example code correctly, the EOR function appears to add #$80 and #$04 together to make #$84.

Is that a coincidence or is that a constant function?

Code: Select all

LDA #$80		; Load #$80 into A
EOR #$04		; Do an exclusive or on A (#$80) and #$04
BEQ [somewhere]		; The result of which is #$84 so do not branch
RTS			; Return
The BEQ is a brance on equal, which means that it would branch to [somewhere] if it was #$84. I think.

Thank you for the patience.
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Re: Gonna Learn 6510 ML Code

Post by Darendor »

Huzzah, I discovered this:

Code: Select all

AND - turns bits off
ORA - turns bits on
EOR - flips bits over
Progress.
drifting
Posts: 152
Joined: Wed Dec 07, 2011 10:21 pm

Re: Gonna Learn 6510 ML Code

Post by drifting »

Darendor wrote: Fri Feb 22, 2019 8:58 pm So drifting, if I read your example code correctly, the EOR function appears to add #$80 and #$04 together to make #$84.

Is that a coincidence or is that a constant function?
You really shouldn't think of bit level operations as addition and subtraction. They are all bitwise operations. The EOR instruction is performing a bitwise XOR on the two numbers.
Darendor wrote: Fri Feb 22, 2019 8:58 pm

Code: Select all

LDA #$80		; Load #$80 into A
EOR #$04		; Do an exclusive or on A (#$80) and #$04
BEQ [somewhere]		; The result of which is #$84 so do not branch
RTS			; Return
The BEQ is a brance on equal, which means that it would branch to [somewhere] if it was #$84. I think.

Thank you for the patience.
This is some of the fun of assembler. The BEQ instruction doesn't actually branch on equal, it branches if the Z (zero) flag is set. The EOR instruction sets the Z flag if the result of the EOR operation is 0. The result of the EOR operation is 0 when both numbers are the same. So:

Code: Select all

LDA #$80		; Load #$80 into A
EOR #$80		; Do an exclusive or on A (#$80) and #$(80)
BEQ [somewhere]		; The result of which is 0 so branch to [somewhere]
RTS			; Not reached
A neat example of this is the LDA instruction. LDA sets the Z flag if the byte loaded into A is 0.

Code: Select all

LDA $#00		; Load #$00 into A
BEQ [somewhere]		; Branch to [somewhere] is Z is set
RTS			; Not reached
Post Reply