Jump to content
IGNORED

MADS Knowledge-Base


Recommended Posts

 

ok... can someone explain why this not work?

.macro calc
clc
lda :1
adc :1+1
adc :1+2
adc :1+81
lsr
lsr
sta offset1+1
clc
lda :1+1
adc :1+2
adc :1+3
adc :1+82
lsr
lsr
sta offset2+1
offset1 lda nibble0x
offset2 ora nibblex0
sta :1-80 
.endm
 
 
...

:10 calc (buffer+#)
 

 

adc (buffer+#)+1 ??? -> illegal addressing mode

:10 calc #               -> 0,1,2,3,4,5,6,7,8,9
:10 calc buffer+#   -> buffer, buffer, buffer, buffer, buffer ...
:10 calc buffer #    -> parameter :1 buffer , parameter :2 

only # is calculated, other expressions not

Edited by tebe
Link to comment
Share on other sites

  • 4 weeks later...

Ran into this the other day:

 

	.if .not build = hardware.MYIDE2
	jsr ResetDrive ; reset drive, and get response
	bcc got_hdd
	jsr printf
	.byte 'No HDD',155,0
	jmp jext_off
got_hdd
	.endif


If "BUILD" = hardware.SIDE, the entire block is skipped. Replacing the expression with the following fixed it:

    .if .not [build = hardware.MYIDE2]
Now, operator precedence is described as follows:

first []              (brackets)
 + - ~ < >            (unary)
 * / % & << >>        (binary)
 + - | ^              (binary)
 = == <> != < > <= >= (binary)
 !                    (unary)
 &&                   (binary)
last  ||              (binary)
And it's stated that .not is equivalent to !. So why was .not (presumably) evaluated (negating "build") before the equality operator (which apparently has a higher precedence) when no brackets were present? Apologies if I've misunderstood. It's obviously safer and wise to remove ambiguity by employing brackets at all times anyway. :) Edited by flashjazzcat
Link to comment
Share on other sites

  • 1 month later...

Related to the above, but more debilitating: why does this cause an error?

NextBank	.macro ; fill remainder of 8KB ROM bank with $FF and add cart header
	.align $BFF0,$FF
	sta $D500 ; reset to bank 0
	jmp CartReset
	.byte 0,0,0,0
CartReset
	.word CartStart ; CartStart
	.byte 0
	.byte 0 ; bit 0 = disk boot, bit 2 = cart start (otherwise init only)
	.word CartInit; CartInit
	org $A000 ; reset origin - CAUSES ASSEMBLY ERROR (CAN'T FILL FROM HIGHER ($C000) TO LOWER MEMORY LOCATION ($A000))
	nmb ; bump assembler's bank counter
	.endm


	opt h-
	opt f+
	org $A000
	
	lmb #0 ; bank 0
	
	ljsr :Bank1
	
	NextBank ; pad bank and add cart header

Bank1
	ljsr :Bank2
	
	NextBank
	
Bank2
	rts

	NextBank

MADS generates "CAN'T FILL FROM HIGHER ($C000) TO LOWER MEMORY LOCATION ($A000)", pointing (again) to ORG $A000 in the macro definition, without reference to the location of the macro call which generated the error.

Now, the macro simply pads the current bank with $FF and a cart header block. It then resets the origin to $A000, and bumps the bank counter. So why the fill error? If I remove OPT F+, the error goes away, but then any .DS statments or (more disastrously and impossible to correct) structure instances throw the origin out of whack, resulting in .ALIGN getting confused and producing ROM banks which are nowhere near 8KB in size. I HOPE OPT F+ (when I eventually get the compiler to produce a binary) results in memory skipped by .DS or a structure block producing $FF bytes.

Is there a way to reset the origin to $A000 at the start of a bank without using ORG, which seems to be what's upsetting the compiler? Or am I approaching this the wrong way?

 

NOTE: The above is example code which reproduces the issue. I will refrain from posting all 20,698 lines of the actual project. :)

Edited by flashjazzcat
Link to comment
Share on other sites

Try:

 

OPT F-

ORG ...

OPT F+

 

 

Thanks Peter! That gets rid of the ORG error. All that was throwing things off after that were structs with undefined contents. The compiler puts out warnings about these, but they only become an issue when F+ is turned on. The compiler bumps the address but doesn't output anything. So with those fixed (as they should be), everything appears to line up.

 

Thank you again. :)

Link to comment
Share on other sites

@tebe I'm about to update the English documentation. I found that http://mads.atari8.info/mads.html

has some HTML validation errors which cause exception in the display & search tools.

Could you add DOCTYPE and fix the major ones? (see http://validator.w3.org)

 

org.xml.sax.SAXParseException; lineNumber: 2444; columnNumber: 3; The element type "p" must be terminated by the matching end-tag "</p>".

at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257){code}

at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)

at org.eclipse.help.internal.dynamic.DocumentReader.read(DocumentReader.java:56)

at org.eclipse.help.internal.dynamic.XMLProcessor.process(XMLProcessor.java:49

Edited by JAC!
Link to comment
Share on other sites

  • 4 weeks later...

Here is an example of random number generator. But, I can't figure it out why on Altirra it always shows the same number. If I run the same program on Atari800Win Plus, it works just fine. Can anyone tell me what is going on?

 org $3200

STORE1 equ $CB   ; Temporary 8-bit variable
STORE2 equ $CC   ; Temporary 8-bit variable
RANDOM equ $D20A

 .var i_eff_ .byte

;
; Rand - Random routine
;
; Parameters:
; .byte a (8-bit value): A value between 0 and 255
;
; Result:
; STORE1 (8-bit value): Random number between 0 and 255
; 
Rand  .proc (.byte a) .reg
    
  sta STORE2
Loop
  lda RANDOM
  sta STORE1
  #if .byte STORE1>STORE2
    jmp Loop
  #end
;  jmp Loop
;skip
  rts

  .endp

MAIN

 jsr printf
 dta c'Random number generator demonstration',$9b,0

 jsr printf
 dta c' ',$9b,0
 
 jsr printf
 dta c'Selected number between 0 and 3',$9b,0
 Rand #3
 mva STORE1 i_eff_
 mva i_eff_ $c0
 jsr printf
 dta c'%',$9b,0
 dta a($c0)

 jsr printf
 dta c' ',$9b,0

 jsr printf
 dta c'End of program',$9b,0

 jmp *

.link 'printf.obx'

 run Main
 

Here is the binary

rand.xex

 

Greetings

 

 

 

Edited by Gury
Link to comment
Share on other sites

It's because you run the program directly from "windows" and emulator starts every time from the same starting state and is cycle exact. So your program will read always the same "random" number from $D20A at the same time (cycle count) from emulation start and the random number is not random but defined sequence of numbers derived from polynomial counters or whatever. If you copy it onto .atr image and run from DOS then you will see that it generates different numbers because you will run it at different time offset from emulation start.

Edited by MaPa
Link to comment
Share on other sites

There is alternative solution to putting program into ATR image. Just do some user key input before any random generation routine and it works perfectly, tested! (no need for ATR image). But the fact is Atari800Win does it the way I want and Altirra does not (talking about random number generation solution).

Link to comment
Share on other sites

Keep in mind that similar effects can occur on real hardware. The random number sequence is restarted whenever POKEY is placed into initialization mode, which happens at a deterministic point during boot. Programs started off of disk or otherwise over the SIO bus won't notice this because the transfer takes a variable amount of time, but a cartridge boot definitely can, as can a disk or program boot emulated by a mega-cartridge.

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

I answered my question to myself :) Probably the question was not put correctly and was not understood completely.

 

a .proc can be pointed by vectors in a way:

 

mwa #SCROL vvblkd

 

where SCROL is a proc and vvblkd is a vector address!

 

  • Like 1
Link to comment
Share on other sites

Sure.. as Gury wrote, put a user input at the start of program like waiting for a key or joystick move/trigger. You have to put extra code (like 2 instructions ;) ) at the start and remember to delete it before release of the product.

Link to comment
Share on other sites

I have a problem showing % sign with the use of dta, for example dta c'The numbers % are:',0

 

This will not work, because it waits for number argument. I tried many ways around I know of, but didn't find a solution. The example with putline works (in Mads repository), but I want to use % sign the first way.

 

Any solutions?

Link to comment
Share on other sites

Using the supplied printf? You can't display the percentage symbol unless you modify the printf routine. It should perhaps check for two consecutive "%" characters and output a single percentage symbol. Try these amendments:

?prt	lda (?strv),Y
	beq ?ext
	iny
	sty ?off
	cmp #'%'
	beq ?spc
	cmp #'@'
	beq _float
	cmp #'#'
	beq _string
?output ; new label
	jsr putchr
?nxt	ldy ?off
	bne ?prt

?ext	lda ?vecv+1
	pha
	lda ?vecv
	pha
	rts

_float	jmp float
_string	jmp string


?spc	
	iny ; new code starts here
	lda (?strv),Y
	cmp #'%'
	bne ?notdouble
	inc ?off ; bump index to skip second char
	bne ?output ; char is in A, so print it
?notdouble ; new code ends here
	jsr _word

	lda (?dtav),Y
	sta fr0
	iny
	lda (?dtav),Y
	sta fr0+1
	jsr IFP
	jsr FASC

Note this is completely untested. You'd also have to add similar checks pertaining to the other formatting characters ("#" and "@").

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...