Page 1 of 2

Kowalski Simulator Macro Anomalies

Posted: Sat Jul 21, 2012 5:43 am
by BigDumbDinosaur
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: Select all

	.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.
—————————————————————————————————————————————————————————————————

Re: Kowalski Simulator Macro Anomalies

Posted: Sat Jul 21, 2012 8:14 am
by BitWise
Seems Kowalski got the expression evaluation for IFs inverted. This ..

Code: Select all

	.ORG	$3000
	
	.IF	1==1
	LDA	#1
	.ELSE
	LDA	#0
	.ENDIF

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

Code: Select all

LDA #0
LDX #1

Re: Kowalski Simulator Macro Anomalies

Posted: Sat Jul 21, 2012 5:15 pm
by BigDumbDinosaur
BitWise wrote:
Seems Kowalski got the expression evaluation for IFs inverted. This ..

Code: Select all

	.ORG	$3000
	
	.IF	1==1
	LDA	#1
	.ELSE
	LDA	#0
	.ENDIF

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

Code: Select all

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.

Re: Kowalski Simulator Macro Anomalies

Posted: Sun Jul 22, 2012 4:12 am
by BigDumbDinosaur
BigDumbDinosaur wrote:
BitWise wrote:
Seems Kowalski got the expression evaluation for IFs inverted. This ..

Code: Select all

	.ORG	$3000
	
	.IF	1==1
	LDA	#1
	.ELSE
	LDA	#0
	.ENDIF

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

Code: Select all

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.

Re: Kowalski Simulator Macro Anomalies

Posted: Sun Jul 22, 2012 10:24 pm
by leeeeee
The latest version is 1.2.11

Re: Kowalski Simulator Macro Anomalies

Posted: Sun Jul 22, 2012 11:31 pm
by BigDumbDinosaur
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.

Re: Kowalski Simulator Macro Anomalies

Posted: Sun Jul 22, 2012 11:39 pm
by ElEctric_EyE
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!

Re: Kowalski Simulator Macro Anomalies

Posted: Wed Jul 25, 2012 3:43 pm
by Nightmaretony
Still waiting for the instructions in english for the help file. Still a fantastic program, period....

Re: Kowalski Simulator Macro Anomalies

Posted: Wed Jul 25, 2012 4:26 pm
by BigDumbDinosaur
leeeeee wrote:
The latest version is 1.2.11
It's now 1.2.12.

Re: Kowalski Simulator Macro Anomalies

Posted: Thu Nov 30, 2017 9:39 pm
by 8BIT
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

Re: Kowalski Simulator Macro Anomalies

Posted: Thu Nov 30, 2017 11:54 pm
by BigDumbDinosaur
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: Select all

         printstr "This is a test."
Furthermore, suppose the PRINTSTR macro is as follows:

Code: Select all

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: Select all

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

Re: Kowalski Simulator Macro Anomalies

Posted: Fri Dec 01, 2017 12:25 am
by 8BIT
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

Re: Kowalski Simulator Macro Anomalies

Posted: Fri Dec 01, 2017 1:53 am
by BigDumbDinosaur
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.

Re: Kowalski Simulator Macro Anomalies

Posted: Fri Dec 01, 2017 2:16 am
by 8BIT
thanks a bunch!!!

Re: Kowalski Simulator Macro Anomalies

Posted: Fri Dec 01, 2017 10:07 pm
by Druzyek
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?