Megalextoria - RDF feed
https://www.megalextoria.com/forum2/
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.some ML questions 65C02 to 6502 conversion.
https://www.megalextoria.com/forum2/index.php?t=rview&goto=105441&th=44401#msg_105441
description is "test memory with accumulator" but that means about
nothing to me.. I've read about 40 websites on 6502 instruction and
haven't found a better description. Is it like a compare? please
elaborate.
Also, I'm trying to translate some code from 65C02 instruction to work on
the C64's 6502-opcodes. One of the codes is like this:
JMP (ABC, X)
Where ABC is an array of words that have vectors of different
subroutines. Problem is, I'm having great difficulty figuring out a way
to duplicate this with 6502 instructions without re-writing the whole
dang code. It seemed easy at first, but the more I looked at it, I
realized it wasn't.
And one last question.. what does BRA do? It stands for Branch Always..
I suspect it is like a JMP command, only rather than using an address to
jump to, it uses a number of bytes forward or backward.. Probably good
for making code portable. if I'm wrong, somebody tell me.. Can I just
substitute JMP in place of BRA?
Here is an example of the main issue with the JMP command:
tax ; save back to x
lda byte ; load scancode back into A
jmp (kbccmd,x) ; execute scancode routine, return
JMPBYTE1 = $02D5
JMPBYTE2 = $02D6
tax ; save back to x
LDA kbccmd,x
STA $02D5
INX
LDA kbccmd,x
STA $02D6
lda byte ; load scancode back into A
jmp (JMPBYTE1)
So.. either that didn't work, or there are other issues.
Any help?]]>David Murray2005-03-08T04:45:58-00:00Re: some ML questions 65C02 to 6502 conversion.
https://www.megalextoria.com/forum2/index.php?t=rview&goto=105442&th=44401#msg_105442
> Can anybody explain to me exactly what the BIT instruction does?
From 6502.org:
BIT sets the Z flag as though the value in the address tested were ANDed
with the accumulator. The S and V flags are set to match bits 7 and 6
respectively in the value stored at the tested address.
BIT is often used to skip one or two following bytes as in:
CLOSE1 LDX #$10 If entered here, we
.BYTE $2C effectively perform
CLOSE2 LDX #$20 a BIT test on $20A2,
.BYTE $2C another one on $30A2,
CLOSE3 LDX #$30 and end up with the X
CLOSEX LDA #12 register still at $10
STA ICCOM,X upon arrival here.
> Also, I'm trying to translate some code from 65C02 instruction to work on
> the C64's 6502-opcodes. One of the codes is like this:
>
> JMP (ABC, X)
>
> Where ABC is an array of words that have vectors of different
> subroutines. Problem is, I'm having great difficulty figuring out a way
> to duplicate this with 6502 instructions without re-writing the whole
> dang code. It seemed easy at first, but the more I looked at it, I
> realized it wasn't.
Easiest is probably to use self mod code:
lda (ABC,X)
sta ptr
lda (ABC+1,X)
sta ptr+1
jmp (ptr)
> And one last question.. what does BRA do? It stands for Branch Always..
> I suspect it is like a JMP command, only rather than using an address to
> jump to, it uses a number of bytes forward or backward.. Probably good
> for making code portable. if I'm wrong, somebody tell me.. Can I just
> substitute JMP in place of BRA?
You can, but note that bra is 2 bytes, jmp is 3.
Jim
--
Jim Brain, Brain Innovations brain@jbrain.comhttp://www.jbrain.com
Dabbling in WWW, Embedded Systems, Old CBM computers, and Good Times!]]>Jim Brain2005-03-08T05:05:25-00:00Re: some ML questions 65C02 to 6502 conversion.
https://www.megalextoria.com/forum2/index.php?t=rview&goto=105469&th=44401#msg_105469
Xns9612E740AC8F4neverspamnospamcom@151.164.30.42>,
David Murray <spamsucks@stopspam.com> wrote:
> Also, I'm trying to translate some code from 65C02 instruction to work on
> the C64's 6502-opcodes. One of the codes is like this:
>
> JMP (ABC, X)
>
> Where ABC is an array of words that have vectors of different
> subroutines. Problem is, I'm having great difficulty figuring out a way
> to duplicate this with 6502 instructions without re-writing the whole
> dang code. It seemed easy at first, but the more I looked at it, I
> realized it wasn't.
>
How "clever" do you want to be? Two straightforward approaches would
be self-modifying code or futzing the stack followed by an RTS.
> And one last question.. what does BRA do? It stands for Branch Always..
> I suspect it is like a JMP command, only rather than using an address to
> jump to, it uses a number of bytes forward or backward..
Yep. BRA is just a jump that uses relative addressing.
--
David Evans
Research Assistant Professor
School of Computer Science dfevans@bbcr.uwaterloo.ca
University of Waterloo, Canada http://bbcr.uwaterloo.ca/~dfevans/]]>dfevans2005-03-08T05:05:46-00:00Re: some ML questions 65C02 to 6502 conversion.
https://www.megalextoria.com/forum2/index.php?t=rview&goto=105523&th=44401#msg_105523
r55.12436@attbi_s52>,
Jim Brain <brain@jbrain.com> wrote:
> David Murray wrote:
>
>> And one last question.. what does BRA do? It stands for Branch Always..
>> I suspect it is like a JMP command, only rather than using an address to
>> jump to, it uses a number of bytes forward or backward.. Probably good
>> for making code portable. if I'm wrong, somebody tell me.. Can I just
>> substitute JMP in place of BRA?
>
> You can, but note that bra is 2 bytes, jmp is 3.
True, but since he is already adding to the code, a close substitution
wouldn't hurt. Try:
CLC
BCC address
for an unconditional branch like BRA. This keeps the code relative in case
mobility in memory is important.
It's been years since I've actually done any assembly coding. I remember
doing all the things that David is looking at... having a JMP table to
subroutines and I would load the address needed into a pointer loc and JMP
($xxxx) to it... using BIT to mask out opcodes, etc. Ahh, the good old
days!
------------------------------------------------------------ ---------------
Peter Schepers, | Author of : 64COPY, The C64 EMU file converter
Info Systems & Technology | http://ist.uwaterloo.ca/~schepers/personal.html
University of Waterloo, | My opinion is not likely that of the
Waterloo, Ontario, Canada | University, its employees, or anybody
(519) 888-4567 ext 2456 | on this planet. Too bad!]]>schepers2005-03-08T17:51:55-00:00Re: some ML questions 65C02 to 6502 conversion.
https://www.megalextoria.com/forum2/index.php?t=rview&goto=105525&th=44401#msg_105525
schepers@ist.uwaterloo.ca (Peter Schepers) writes:
> CLC
> BCC address
Considering how many instructions alter the carry flag, the overflow
flag may be a better subject of hi-jacking: CLV - BVC address ?
--
Anders Carlsson]]>Anders Carlsson2005-03-08T18:08:54-00:00Re: some ML questions 65C02 to 6502 conversion.
https://www.megalextoria.com/forum2/index.php?t=rview&goto=105543&th=44401#msg_105543
k2gu0nmovrd.fsf@legolas.mdh.se>,
Anders Carlsson <anders.carlsson@mds.mdh.se> wrote:
> schepers@ist.uwaterloo.ca (Peter Schepers) writes:
>
>> CLC
>> BCC address
>
> Considering how many instructions alter the carry flag, the overflow
> flag may be a better subject of hi-jacking: CLV - BVC address ?
Of course, the selection of what BRANCH type to select is up to the user.
It was only a simple example of unconditional branching.
PS.]]>schepers2005-03-09T13:18:51-00:00Re: some ML questions 65C02 to 6502 conversion.
https://www.megalextoria.com/forum2/index.php?t=rview&goto=105587&th=44401#msg_105587
brain@jbrain.com> wrote in message
news:poaXd.44934$r55.12436@attbi_s52...
> Easiest is probably to use self mod code:
>
> lda (ABC,X)
> sta ptr
> lda (ABC+1,X)
> sta ptr+1
> jmp (ptr)
>
Self-modifying code is, of course a Sin Against Nature :)
But is this code actually self-modifying? Only if 'ptr' is defined somewhere
as being equal to the address of the JMP instruction plus one, which I don't
see anywhere and isn't necessary anyway - 'ptr' can be any location
(preferrably one outside the program code, though).
'Ptr' would have to be equal to the address of the JMP instruction plus one
only if the JMP instruction was using direct addressing. But as written,
it's using indirect addressing.
But there's still a problem. The 6502 does not have an (Absolute Indirect,X)
addressing mode for any instruction - the 65C02 does, but only for the JMP
instruction.
The 6502 does have a (Zero Page Indirect,X) addressing mode which works with
LDA. If we assume that's what being used here, there are apparently two
overlapping pointers in zero page - (ABC,X) accesses a 16-bit pointer at
ABC+X/ABC+X+1, and (ABC+1,X) accesses one at ABC+X+1/ABC+X+2. Awfully tricky
stuff!
To make the overlapped pointers access two consecutive locations in main
memory you'd have to have previously stored something like:
$01 $02 $02
starting ABC+X, so you'd get $0201 and $0202 as your two 16-bit pointers.
Maybe Absolute,X addressing would be simpler? :)
Anton Treuenfels]]>Anton Treuenfels2005-03-10T05:16:14-00:00Re: some ML questions 65C02 to 6502 conversion.
https://www.megalextoria.com/forum2/index.php?t=rview&goto=105588&th=44401#msg_105588
> But is this code actually self-modifying? Only if 'ptr' is defined somewhere
It was, but I rewrote it before posting, and then it was not self
modifying, but I forgot to retitle it.
> But there's still a problem. The 6502 does not have an (Absolute Indirect,X)
> addressing mode for any instruction - the 65C02 does, but only for the JMP
> instruction.
I was assuming ABC could be in zpage.
> The 6502 does have a (Zero Page Indirect,X) addressing mode which works with
> LDA. If we assume that's what being used here, there are apparently two
> overlapping pointers in zero page - (ABC,X) accesses a 16-bit pointer at
> ABC+X/ABC+X+1, and (ABC+1,X) accesses one at ABC+X+1/ABC+X+2. Awfully tricky
> stuff!
My understanding is that JMP(ABC,X) gets the address at ABC, adds X, and
then jumps to the addressat that location. I think this instruction is
assumed that X increments by 2.
You are correct that the utility is somewhat in question.
Jim
--
Jim Brain, Brain Innovations brain@jbrain.comhttp://www.jbrain.com
Dabbling in WWW, Embedded Systems, Old CBM computers, and Good Times!]]>Jim Brain2005-03-10T06:50:56-00:00Re: some ML questions 65C02 to 6502 conversion.
https://www.megalextoria.com/forum2/index.php?t=rview&goto=105595&th=44401#msg_105595
4q6.95227@attbi_s01>,
Jim Brain <brain@jbrain.com> wrote:
> Anton Treuenfels wrote:
>> But is this code actually self-modifying? Only if 'ptr' is defined somewhere
>
> It was, but I rewrote it before posting, and then it was not self
> modifying, but I forgot to retitle it.
>
>> But there's still a problem. The 6502 does not have an (Absolute Indirect,X)
>> addressing mode for any instruction - the 65C02 does, but only for the JMP
>> instruction.
> I was assuming ABC could be in zpage.
>
>
>> The 6502 does have a (Zero Page Indirect,X) addressing mode which works with
>> LDA. If we assume that's what being used here, there are apparently two
>> overlapping pointers in zero page - (ABC,X) accesses a 16-bit pointer at
>> ABC+X/ABC+X+1, and (ABC+1,X) accesses one at ABC+X+1/ABC+X+2. Awfully tricky
>> stuff!
>
> My understanding is that JMP(ABC,X) gets the address at ABC, adds X, and
> then jumps to the addressat that location. I think this instruction is
> assumed that X increments by 2.
Actually that sounds backwards. What you seem to be saying in C would be
(*abc)+x, but it actually appears to be *(abc+x). This implies a JMP
vector table who's reference label address is ABC, indexed by X.
According to one web page describing 65C02 opcodes:
"Absolute Indexed Indirect Addressing [(Absolute,X)] (Jump Instruction
Only) With absolute indexed indirect addressing the contents of the second
and third instruction bytes are added to the X register. The result of
this addition, points to a memory location containing the low-order eight
bits of the effective address. The next memory location contains the
higher-order eight bits of the effective address."
So it would appear to take the ABC value from the opcode, add X, and it
now has the pointer address to get the JMP value from.
------------------------------------------------------------ ---------------
Peter Schepers, | Author of : 64COPY, The C64 EMU file converter
Info Systems & Technology | http://ist.uwaterloo.ca/~schepers/personal.html
University of Waterloo, | My opinion is not likely that of the
Waterloo, Ontario, Canada | University, its employees, or anybody
(519) 888-4567 ext 2456 | on this planet. Too bad!]]>schepers2005-03-10T13:13:12-00:00Re: some ML questions 65C02 to 6502 conversion.
https://www.megalextoria.com/forum2/index.php?t=rview&goto=105627&th=44401#msg_105627
>> My understanding is that JMP(ABC,X) gets the address at ABC, adds X, and
>> then jumps to the addressat that location. I think this instruction is
>> assumed that X increments by 2.
>
>
> Actually that sounds backwards. What you seem to be saying in C would be
> (*abc)+x, but it actually appears to be *(abc+x). This implies a JMP
> vector table who's reference label address is ABC, indexed by X.
My bad. Should not reply late at night. It is *(abc+x). Still,
though, my note is correct JMP(ABC,X) assumes that ABC is 2 byte
aligned, and thus X needs to be aligned as well.
Jim
--
Jim Brain, Brain Innovations brain@jbrain.comhttp://www.jbrain.com
Dabbling in WWW, Embedded Systems, Old CBM computers, and Good Times!]]>Jim Brain2005-03-10T14:42:55-00:00