Kowalski Simulator Macro Anomalies

Topics pertaining to the emulation or simulation of the 65xx microprocessors and their peripheral chips.
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Kowalski Simulator Macro Anomalies

Post 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.
—————————————————————————————————————————————————————————————————
Last edited by BigDumbDinosaur on Sun Jul 22, 2012 11:33 pm, edited 1 time in total.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
BitWise
In Memoriam
Posts: 996
Joined: 02 Mar 2004
Location: Berkshire, UK
Contact:

Re: Kowalski Simulator Macro Anomalies

Post 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
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
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Kowalski Simulator Macro Anomalies

Post 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.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Kowalski Simulator Macro Anomalies

Post 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.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
leeeeee
In Memoriam
Posts: 347
Joined: 30 Aug 2002
Location: UK
Contact:

Re: Kowalski Simulator Macro Anomalies

Post by leeeeee »

The latest version is 1.2.11
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Kowalski Simulator Macro Anomalies

Post 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.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
ElEctric_EyE
Posts: 3260
Joined: 02 Mar 2009
Location: OH, USA

Re: Kowalski Simulator Macro Anomalies

Post 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!
Nightmaretony
In Memoriam
Posts: 618
Joined: 27 Jun 2003
Location: Meadowbrook
Contact:

Re: Kowalski Simulator Macro Anomalies

Post by Nightmaretony »

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"
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Kowalski Simulator Macro Anomalies

Post by BigDumbDinosaur »

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!
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Re: Kowalski Simulator Macro Anomalies

Post 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
Please visit my website -> https://sbc.rictor.org/
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Kowalski Simulator Macro Anomalies

Post 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.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Re: Kowalski Simulator Macro Anomalies

Post 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
Please visit my website -> https://sbc.rictor.org/
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Kowalski Simulator Macro Anomalies

Post 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.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Re: Kowalski Simulator Macro Anomalies

Post by 8BIT »

thanks a bunch!!!
Please visit my website -> https://sbc.rictor.org/
User avatar
Druzyek
Posts: 367
Joined: 12 May 2014
Contact:

Re: Kowalski Simulator Macro Anomalies

Post 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?
Post Reply