Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Do you analyze page crossings / try to eliminate them?
2024-03-13 13:16
cadaver

Registered: Feb 2002
Posts: 1154
Do you analyze page crossings / try to eliminate them?

Particularly in a game context, where code isn't easily separated into hot paths + data can be spread out in a manner that is not conductive to page-aligning everything cleanly?

As for the methods, I personally do that by symbol table analysis + a customizable simple emulator for runtime detection & counting ( https://github.com/cadaver/oldschoolengine2 )
 
... 28 posts hidden. Click here to view all posts....
 
2024-03-14 14:38
Frostbyte

Registered: Aug 2003
Posts: 174
Fucking "you cannot edit this post".

A build option would be very nice though as the above litters the code a bit and you need to remember to put the checks in place yourself.
2024-03-14 14:52
chatGPZ

Registered: Dec 2001
Posts: 11146
An option to warn at all page crossings wouldn't be terribly useful for most non trivial programs - you'd just drown in warnings :)
2024-03-14 15:28
Frostbyte

Registered: Aug 2003
Posts: 174
Quote: An option to warn at all page crossings wouldn't be terribly useful for most non trivial programs - you'd just drown in warnings :)

Not useful for most scenarios, agreed - that's why it'd be a build option. Enable it when you need it. :)
2024-03-14 15:51
cadaver

Registered: Feb 2002
Posts: 1154
Nice macro approach!

I also try to put the already ready or "least modified" code to the beginning, though it's made harder when I insist on stupid things like falling through to main loop from some long-winded initialization :)
2024-03-14 18:04
trident

Registered: May 2002
Posts: 76
i use kickassembler and a set of macros that look like this:

loop:
// some code
bne_page(loop)

that trigger an error (or warning / assert) if that bne crosses a page boundary.

inside the bne_page() macro is the same type of macro magic that frostbyte posted.

sometimes you want a page boundary to be crossed (typically when doing really tightly timed rastercode). for this usecase there is a second set of macros:

loop:
// some code that intentionally crosses a page boundary
bne_different_page(loop)
2024-03-14 22:05
Peiselulli

Registered: Oct 2006
Posts: 81
ACME macros:

	!macro check_same_page_start {
	!set page_check_page_addr = * & $ff00
	}

	!macro check_same_page_end {
	!if (page_check_page_addr != ( * & $ff00)) {
		!error "not the same page"
	}
	}


I place this macros around the interesting code (stable or highly optimized)
2024-03-14 22:30
JackAsser

Registered: Jun 2002
Posts: 1990
Quote: Hmm interesting. This motivated me to look at KickAssembler docs, seems that there is no automagic option to warn/error about page crossings at compile time, but for branches there is a suggestion to do it manually like so:

        beq label1
        .errorif (>*) != (>label1), "Branch crosses a page!"
        nop // some code to branch over
        nop
label1:

Thus I suppose the above could also be used for tables:
table1:
        nop // some table data
        nop
        .errorif (>*) != (>table1), "Table crosses a page!"


A build option


That's exactly how I do it for critical sections such as a clock slide.

I generally don't align data or code if I don't have to, hence the error hints to me when I must to. (to save space generally).
2024-03-15 03:35
ws

Registered: Apr 2012
Posts: 229
Cool solutions here!
Actually, i never thought about that before, because CBMprgStudio warns automatically on compile that branches or commands cross page boundaries. But tables i always aligned manually until now and observed behavior in RAM by monitoring with ICU64/Retrodebugger.
2024-03-15 06:20
ChristopherJam

Registered: Aug 2004
Posts: 1381
While we're swapping notes, this is what I use in ca65 to fail compilation if somethings no longer on the same page as the address passed in:
.macro assert_same_page label_
   .assert >(label_) = >(*), error, "Page crossing detected!"
.endmacro

Then here's an example clock slide:
    sta :+ +1
:   bcc :-
    assert_same_page(:+)
    .byte $80,$80,$80,$80
    .byte $80,$80,$80,$04,$ea
:

I do like Trident's bxx_page/bxx_different_page concept mind - I might have to steal that :)
2024-03-15 08:23
tlr

Registered: Sep 2003
Posts: 1724
I too approve of tridents solution. It is a nice complement, well worth stealing. :)

For a long time I used these macros in dasm:
	MAC	START_SAMEPAGE
_SAMEPAGE_MARKER	SET	.
_SAMEPAGE_NAME		SET	{0}
	ENDM

	MAC	END_SAMEPAGE
	IF	>_SAMEPAGE_MARKER != >.
	IF	_SAMEPAGE_NAME!=""
	ERROR	"[SAMEPAGE] Page crossing not allowed! (",_SAMEPAGE_NAME,"@",_SAMEPAGE_MARKER,"-",.,")"
	ELSE
	ERROR	"[SAMEPAGE] Page crossing not allowed! (",_SAMEPAGE_MARKER,"-",.,")"
	ENDIF
	ELSE
	IF	_SAMEPAGE_NAME!=""
	INFO	"[SAMEPAGE] successful SAMEPAGE. (",_SAMEPAGE_NAME,"@",_SAMEPAGE_MARKER,"-",.,")"
	ELSE
	INFO	"[SAMEPAGE] successful SAMEPAGE. (",_SAMEPAGE_MARKER,"-",.,")"
	ENDIF
	ENDIF
	ENDM
Note the capitals on pseudo ops. I don't do that anymore. :)

These can be used with START_SAMEPAGE <name> and END_SAMEPAGE to get a nice visual on what is happening.
 INFO: [SAMEPAGE] successful SAMEPAGE. ( get_byte @ $5d8 - $5dd )
Nowadays I've switched to assembler provided pseudo ops.
Previous - 1 | 2 | 3 | 4 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Wayne/Art Ravers
Guests online: 115
Top Demos
1 Next Level  (9.8)
2 13:37  (9.7)
3 Mojo  (9.7)
4 50 Years of Flex  (9.7)
5 Coma Light 13  (9.7)
6 Edge of Disgrace  (9.6)
7 Comaland 100%  (9.6)
8 Uncensored  (9.6)
9 No Bounds  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.7)
2 It's More Fun to Com..  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Rainbow Connection  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Booze Design  (9.3)
3 Censor Design  (9.3)
4 Crest  (9.3)
5 Performers  (9.3)
Top Webmasters
1 Slaygon  (9.7)
2 Perff  (9.6)
3 Morpheus  (9.5)
4 Sabbi  (9.5)
5 CreaMD  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.045 sec.