6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Tue Nov 12, 2024 11:00 am

All times are UTC




Post new topic Reply to topic  [ 57 posts ]  Go to page Previous  1, 2, 3, 4
Author Message
PostPosted: Thu Oct 07, 2021 2:08 pm 
Offline

Joined: Sun May 30, 2021 2:16 am
Posts: 375
Got another one. I'm trying to port a program for the 65c816, and I encountered this bit of code:
Code:
;===============================================================================
; D - Disassemble Memory
;-------------------------------------------------------------------------------

                cmp     #'D'                    ; Memory display?
                bne     NotDisassemble

                ldx     #ADDR_S                 ; Parse start address
                jsr     GetAddr
                bcc     $+5
                jmp     ShowError
                ldx     #ADDR_E                 ; Parse end address
                jsr     GetAddr
                bcc     $+5
                jmp     ShowError

                php
                pla
                sta     FLAGS


My assembler doesn't like the "$+5". I think the code is trying to advance the PC five addresses forward, if the carry flag is cleared,in which case I think I could do:
Code:
BCC *+5


Is this correct, anybody? I've not encountered "$+" before.

Jon


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 07, 2021 2:39 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1485
Location: Scotland
Jmstein7 wrote:
Got another one. I'm trying to port a program for the 65c816, and I encountered this bit of code:
Code:
;===============================================================================
; D - Disassemble Memory
;-------------------------------------------------------------------------------

                cmp     #'D'                    ; Memory display?
                bne     NotDisassemble

                ldx     #ADDR_S                 ; Parse start address
                jsr     GetAddr
                bcc     $+5
                jmp     ShowError
                ldx     #ADDR_E                 ; Parse end address
                jsr     GetAddr
                bcc     $+5
                jmp     ShowError

                php
                pla
                sta     FLAGS


My assembler doesn't like the "$+5". I think the code is trying to advance the PC five addresses forward, if the carry flag is cleared,in which case I think I could do:
Code:
BCC *+5


Is this correct, anybody? I've not encountered "$+" before.


Does it work with *+5?

To remove confusion, I'd be inclined to replace them with labels though.

so:

Code:
                ldx     #ADDR_S                 ; Parse start address
                jsr     GetAddr
                bcc     startOk
                jmp     ShowError
startOK:
                ldx     #ADDR_E                 ; Parse end address
                jsr     GetAddr
                bcc     endOK
                jmp     ShowError
endOK:


and so on.

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 07, 2021 3:09 pm 
Offline

Joined: Sun May 30, 2021 2:16 am
Posts: 375
drogon wrote:
Does it work with *+5?

To remove confusion, I'd be inclined to replace them with labels though.

so:

Code:
                ldx     #ADDR_S                 ; Parse start address
                jsr     GetAddr
                bcc     startOk
                jmp     ShowError
startOK:
                ldx     #ADDR_E                 ; Parse end address
                jsr     GetAddr
                bcc     endOK
                jmp     ShowError
endOK:


and so on.

-Gordon


Great idea! There are thousands of lines of code, so it would be hard to debug. The other item I'm having trouble with is this:
Code:
                .macro      MNEM(P,Q,R)
                .dword      ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')
                .endmacro


It is telling me that this is an "Unsupported format of parameters" with regards to .dword ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')

Argh!


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 07, 2021 3:19 pm 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 336
Jmstein7 wrote:
.dword ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')

It's taking three characters and packing them into a 16 bit word. P is given the top 6 bits, Q is given the next 5, and R the lowest 5. @ is encoded as 0, A as 1, B as 2, and so on. Unwrapping it: P-'@' subtracts the code for @ from P, giving 0, 1, 2, ... Then it shifts that up 5 bits. Q-'@' does the same to Q, these two result get ORed together by the |, then the result of that is shifted five bits up. Finally the value from R gets ORed in.
Your assembler obviously doesn't like this expression as it is, but I couldn't guess exactly what it's complaining about. It's not the most helpful error message. I'd start by stripping the expression down the the bare minimum and gradually adding bits back until it fails. So
Code:
    .dword P
    .dword P-'@'
    .dword (P-'@')<<5

and so on. Knowing which bit of syntax it's unhappy about will help a lot in trying to write something that it does like.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 07, 2021 3:21 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1485
Location: Scotland
Jmstein7 wrote:

Great idea! There are thousands of lines of code, so it would be hard to debug. The other item I'm having trouble with is this:
Code:
                .macro      MNEM(P,Q,R)
                .dword      ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')
                .endmacro


It is telling me that this is an "Unsupported format of parameters" with regards to .dword ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')

Argh!


It's compressing 3 characters into 2 bytes. Woz did this in his disassembler and one-line assembler. If this is failing for you, then your assembler doesn't support those actions, so short of changing assembler, you might need to work it out the hard way.

Although checking now - .dword - that might imply a double word and maybe 4 bytes, so compressing 3 characters into 4 bytes is odd, so I guess it really means a 16-bit word. I checked it in ca65 and it seems OK, but the syntax is different, so:

Code:
.macro  MNEM    P,Q,R
        .word   ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')
.endmacro

        MNEM    'L','D','A'


works with the output:

Code:
00C006  1  81 30                MNEM    'L','D','A'


So, L,D,A -> $81, $30.

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 07, 2021 4:32 pm 
Offline

Joined: Sun May 30, 2021 2:16 am
Posts: 375
No matter how I try, it just won’t work - word, double word, bytes, etc.

This is driving me bananas.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 07, 2021 7:26 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
Can you link us to your assembler's documentation, if any? There should be a way to get the job done without hand-translating and hard-coding the hex data.

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 07, 2021 7:38 pm 
Offline

Joined: Sun May 30, 2021 2:16 am
Posts: 375
barrym95838 wrote:
Can you link us to your assembler's documentation, if any? There should be a way to get the job done without hand-translating and hard-coding the hex data.

Mike,

Here it is: https://enginedesigns.net/download/retroassembler.html

Thanks!

Jon


Top
 Profile  
Reply with quote  
PostPosted: Sun Oct 10, 2021 2:25 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8482
Location: Midwestern USA
Jmstein7 wrote:
The other item I'm having trouble with is this:
Code:
                .macro      MNEM(P,Q,R)
                .dword      ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')
                .endmacro


It is telling me that this is an "Unsupported format of parameters" with regards to .dword ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')

Argh!

I tried that in the Kowalski assembler, which uses curly brackets instead of parentheses for determining evaluation precedence. It works as expected.

However, .DWORD in the retroassembler causes the generation of a 32-bit, little-endian value. Replace the .DWORD in the above expression with .WORD to produce the 16-bit, little-endian value expected by the mnemonic parser.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 11, 2021 1:28 pm 
Offline

Joined: Sun May 30, 2021 2:16 am
Posts: 375
BigDumbDinosaur wrote:

I tried that in the Kowalski assembler, which uses curly brackets instead of parentheses for determining evaluation precedence. It works as expected.

However, .DWORD in the retroassembler causes the generation of a 32-bit, little-endian value. Replace the .DWORD in the above expression with .WORD to produce the 16-bit, little-endian value expected by the mnemonic parser.


It didn't work with .word, but it did work with .textz . Weird.


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 11, 2021 3:02 pm 
Offline

Joined: Sun Nov 08, 2009 1:56 am
Posts: 410
Location: Minnesota
Quote:
Great idea! There are thousands of lines of code, so it would be hard to debug. The other item I'm having trouble with is this:
Code:
.macro MNEM(P,Q,R)
.dword ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')
.endmacro


It is telling me that this is an "Unsupported format of parameters" with regards to .dword ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')


It's telling you something is wrong with 'P', 'Q' , and/or 'R'. The expression itself is not a problem as the documentation says all the operators used are supported (same as C syntax).

Perhaps the problem is that P, Q, and R are not interpreted as characters but as labels? Subtracting a character from a label won't work. Are you writing

Code:
MNEM(L, D, A)


instead of

Code:
MNEM('L', 'D', 'A')


by any chance?

Also '.dword' generates a 32-bit value. Better is '.word' to generate a 16-bit one.


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 11, 2021 7:44 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8482
Location: Midwestern USA
teamtempest wrote:
It's telling you something is wrong with 'P', 'Q' , and/or 'R'...Perhaps the problem is that P, Q, and R are not interpreted as characters but as labels? Subtracting a character from a label won't work. Are you writing

Code:
MNEM(L, D, A)

That would definitely upset the apple cart, depending on if any of those are even defined and if so, what values they hold.

Quote:
Also '.dword' generates a 32-bit value. Better is '.word' to generate a 16-bit one.

As I noted in my post... :D

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 57 posts ]  Go to page Previous  1, 2, 3, 4

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: