6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 7:43 pm

All times are UTC




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sat Jul 21, 2012 5:43 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8514
Location: Midwestern USA
In the process of writing a macro to automate and "error proof" a computational process that I frequently encounter in dealing with things like block and inode allocation maps on disk drives, I ran across an interesting anomaly in the Kowalski simulator. Rather than try to explain it, here's a test program that uses the macro as part of code that computes the number of bits in a hard drive disk block, given the block size in bytes.

Code:
   .opt proc65c02,caseinsensitive
;===============================================================================
;
shiftfac .macro .op
;
;   ————————————————————————————————————————————————————————————————
;   This macro converts a power-of-2 value into the number of shifts
;   required to perform integer multiplication or division using the
;   ASL, LSR, ROL & ROR instructions.  The macro parameter must be 2
;   or an exact multiple of 2, such as 16 or 32768, & cannot exceed
;   65536 (2^16).  The output of this macro is an LDX # instruction.
;
;   The following example multiplies the value in NUM & NUM+1 by 16,
;   with the remainder stored at NUM+2:
;
;            shiftfac 16           ;generates LDX #4
;   loop     asl num               ;each left rotate...
;            rol num+1             ;multiplies the number...
;            rol num+2             ;by 2
;            dex
;            bne loop
;   ————————————————————————————————————————————————————————————————
;
.shift   .=1
         .if .op != 2
         .else
.shift   .=.shift+1
           .if .op != 4
           .else
.shift   .=.shift+1
           .if .op != 8
           .else
.shift   .=.shift+1
            .if .op != 16
            .else
.shift   .=.shift+1
             .if .op != 32
             .else
.shift   .=.shift+1
              .if .op != 64
              .else
.shift   .=.shift+1
               .if .op != 128
               .else
.shift   .=.shift+1
                .if .op != 256
                .else
.shift   .=.shift+1
                 .if .op != 512
                 .else
.shift   .=.shift+1
                  .if .op != 1024
                  .else
.shift   .=.shift+1
                   .if .op != 2048
                   .else
.shift   .=.shift+1
                    .if .op != 4096
                    .else
.shift   .=.shift+1
                     .if .op != 8192
                     .else
.shift   .=.shift+1
                      .if .op != 16384
                      .else
.shift   .=.shift+1
                       .if .op != 32768
                       .else
.shift   .=.shift+1
                        .if .op == 65536
                          .error "MACRO ERROR: "+%0$+": INVALID OPERAND"
                        .endif
                       .endif
                      .endif
                     .endif
                    .endif
                   .endif
                  .endif
                 .endif
                .endif
               .endif
              .endif
             .endif
            .endif
           .endif
          .endif
         .endif
         ldx #.shift
         .endm
;
;
;   test code — computes number of bits in a disk block...
;
         *=$2000
;
num      =$00                  ;number storage
;
blksiz   =512                  ;size of a disk block
n_bits   =8                    ;bits in a byte
;
         ldx #<blksiz          ;block size LSB
         ldy #>blksiz          ;block size MSB
         stx num               ;set LSB
         sty num+1             ;set MSB
         stz num+2             ;clear overflow
         shiftfac n_bits       ;get number of shifts
;
loop     asl num               ;each left rotate...
         rol num+1             ;multiplies the number...
         rol num+2             ;by 2
         dex
         bne loop
;
         brk
   .end

If you copy the above program into the simulator, it will assemble and run without error, and will produce the correct result, which is $001000 or 4096. However, if you examine the logic tree in the macro body you will see the anomaly. :? :roll: :?:

Comments? Has anyone else run into this?

—————————————————————————————————————————————————————————————————
EDIT: This problem has been corrected in an update to the simulator. The current version is now 1.2.11.
—————————————————————————————————————————————————————————————————

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


Last edited by BigDumbDinosaur on Sun Jul 22, 2012 11:33 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 21, 2012 8:14 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
Seems Kowalski got the expression evaluation for IFs inverted. This ..
Code:
   .ORG   $3000
   
   .IF   1==1
   LDA   #1
   .ELSE
   LDA   #0
   .ENDIF

   .IF   1!=1
   LDX   #1
   .ELSE
   LDX   #0
   .ENDIF
   
   .end

..generates..
Code:
LDA #0
LDX #1

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 21, 2012 5:15 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8514
Location: Midwestern USA
BitWise wrote:
Seems Kowalski got the expression evaluation for IFs inverted. This ..
Code:
   .ORG   $3000
   
   .IF   1==1
   LDA   #1
   .ELSE
   LDA   #0
   .ENDIF

   .IF   1!=1
   LDX   #1
   .ELSE
   LDX   #0
   .ENDIF
   
   .end

..generates..
Code:
LDA #0
LDX #1

Exactly! I went around in circles for a while with the equality test before realizing that the tests were backwards. Urk!

However, the less-than and greater-than tests seem to be okay.

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


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 22, 2012 4:12 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8514
Location: Midwestern USA
BigDumbDinosaur wrote:
BitWise wrote:
Seems Kowalski got the expression evaluation for IFs inverted. This ..
Code:
   .ORG   $3000
   
   .IF   1==1
   LDA   #1
   .ELSE
   LDA   #0
   .ENDIF

   .IF   1!=1
   LDX   #1
   .ELSE
   LDX   #0
   .ENDIF
   
   .end

..generates..
Code:
LDA #0
LDX #1

Exactly! I went around in circles for a while with the equality test before realizing that the tests were backwards. Urk!

However, the less-than and greater-than tests seem to be okay.

Version 1.2.9 fixes this problem.

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


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 22, 2012 10:24 pm 
Offline

Joined: Fri Aug 30, 2002 2:05 pm
Posts: 347
Location: UK
The latest version is 1.2.11


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 22, 2012 11:31 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8514
Location: Midwestern USA
leeeeee wrote:
The latest version is 1.2.11

Yep. The version jump was because Mr. Kowalski fixed a problem that developed after he released V1.2.9, which was double-spacing in the listing output. He also got the .PARAMTYPE macro feature working.

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


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 22, 2012 11:39 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
This is a great update. I've been using 1.2.6 I had found from my limited google searches years ago.

Even though I've never come across the aforementioned issues, thanks for the posts!

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 25, 2012 3:43 pm 
Offline

Joined: Fri Jun 27, 2003 8:12 am
Posts: 618
Location: Meadowbrook
Still waiting for the instructions in english for the help file. Still a fantastic program, period....

_________________
"My biggest dream in life? Building black plywood Habitrails"


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 25, 2012 4:26 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8514
Location: Midwestern USA
leeeeee wrote:
The latest version is 1.2.11

It's now 1.2.12.

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


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 30, 2017 9:39 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
BigDumbDinosaur wrote:

Yep. The version jump was because Mr. Kowalski fixed a problem that developed after he released V1.2.9, which was double-spacing in the listing output. He also got the .PARAMTYPE macro feature working.


Hi BDD,

I've been searching through the forum for bugs/feature requests/etc with the Kowalski Simulator and found this. Can you describe the purpose and use of the .PARAMTYPE feature?

I will post a consolidated list of bugs and feature requests once its completed.

Thanks!

Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 30, 2017 11:54 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8514
Location: Midwestern USA
8BIT wrote:
Can you describe the purpose and use of the .PARAMTYPE feature?

What .PARAMTYPE does is report if a parameter passed to a macro is a character string or a number. Consider the following macro call:

Code:
         printstr "This is a test."

Furthermore, suppose the PRINTSTR macro is as follows:

Code:
printstr .macro .string
         .if .paramtype(.string) == 2
             (assemble code to process as a character string)
         .else
             (assemble code to process as an address)
         .endif
         .endm

The above macro invocation would process "This is a test." as a character string. On the other hand, the following invocation:

Code:
         printstr straddr

would result in the macro handling the parameter as a numeric value, presumably a string's address.

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 01, 2017 12:25 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
Ok, thanks. What is the range of values returned then?

2 = string

0 = ?
1 = ?
3 = ?

I'm having trouble finding the details in the source.

thanks!

Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 01, 2017 1:53 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8514
Location: Midwestern USA
8BIT wrote:
Ok, thanks. What is the range of values returned then?

2 = string

0 = ?
1 = ?
3 = ?

I'm having trouble finding the details in the source.

thanks!

Daryl

As far as I know, the .PARAMTYPE evaluation returns 1 for numeric and 2 for string.

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 01, 2017 2:16 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
thanks a bunch!!!

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 01, 2017 10:07 pm 
Offline
User avatar

Joined: Mon May 12, 2014 6:18 pm
Posts: 365
It would also be useful to have other types like character as well. We discussed this on another thread. The Kowalski macros are fairly crippled, especially compared to something like the CA65 assembler. I haven't looked at the source but how hard would it be to disable macros and let the simulator accept input from a more functional macro program?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 79 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: