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 > best way to implement SEV?
2023-04-02 14:18
tlr

Registered: Sep 2003
Posts: 1717
best way to implement SEV?

I currently have this...
	php
	pha
	txa
	pha
	tsx
	pla
	pla
	pla
	ora	#%01000000	; sev
	pha
	txs
	pla
	tax
	pla
	plp
...which is 16 bytes, uses 3 bytes stack. I suppose it isn't that much, but all those single byte instructions make it look huge. Any nice alternatives?
 
... 5 posts hidden. Click here to view all posts....
 
2023-04-02 21:59
tlr

Registered: Sep 2003
Posts: 1717
Quote: Maybe like this:
	sta somewhere
	php
	pla
	ora #%01000000
	pha
	lda somewhere
	plp


Yes, that works if we use one zp location. 10 bytes, 1 byte stack. I prefer only stack but this is shorter.
2023-04-03 02:10
Fresh

Registered: Jan 2005
Posts: 101
While I clearly think Rastah Bar is the best solution, I'm adding this as a curious alternative, even though I do know it's not likely to fit any normal C64 code context, anyway...

Your first solution is not IRQ safe, as it relies on some bytes under SP not being changed during the routine execution.
Now, I honestly don't know the internals of superfluid, but if the code you're writing your library for is *not* indeed using IRQs, you may prepare $fffe and $ffff and use something like this:
IRQhandler:
 	sta somewhere
	pla
	ora #%01000000
	pha
	lda somewhere
	rti

This can be called with just brk followed by any byte, which is a bit shorter than jsr: if the routine is called quite often you're going to get back the bytes you "lost" for initializing the IRQ handler and maybe even gaining some space. Moreover, it's even a bit faster!

My (silly) two cents :)
2023-04-03 07:50
TWW

Registered: Jul 2009
Posts: 541
Quote: Yes, that works if we use one zp location. 10 bytes, 1 byte stack. I prefer only stack but this is shorter.

You can skip the ZP by using SMC at the cost of 1 byte (same execution time).

Now try figguring out how to do it without messing up the regs, stack or the flags while having it flexible to use in a library and ensure the execution cycles remain fixed (no branching^^) :D (hint, you cant...) <--- Bait!
2023-04-03 08:23
tlr

Registered: Sep 2003
Posts: 1717
Quoting Fresh
Your first solution is not IRQ safe, as it relies on some bytes under SP not being changed during the routine execution.
Now, I honestly don't know the internals of superfluid, but if the code you're writing your library for is *not* indeed using IRQs, you may prepare $fffe and $ffff and use something like this:
IRQhandler:
 	sta somewhere
	pla
	ora #%01000000
	pha
	lda somewhere
	rti

This can be called with just brk followed by any byte, which is a bit shorter than jsr: if the routine is called quite often you're going to get back the bytes you "lost" for initializing the IRQ handler and maybe even gaining some space. Moreover, it's even a bit faster!

Interesting approach but maybe not so practical. :)

for information, it is used in superfluid in many places to pass an additional easily branchable return flag besides the carry.
2023-04-03 08:25
tlr

Registered: Sep 2003
Posts: 1717
Quoting TWW
You can skip the ZP by using SMC at the cost of 1 byte (same execution time).

Now try figguring out how to do it without messing up the regs, stack or the flags while having it flexible to use in a library and ensure the execution cycles remain fixed (no branching^^) :D (hint, you cant...) <--- Bait!

In my case the code is in ROM so no self mod for me, but please post any interesting solutions for others to use.
2023-04-03 11:13
Krill

Registered: Apr 2002
Posts: 2850
Quoting tlr
for information, it is used in superfluid in many places to pass an additional easily branchable return flag besides the carry.
So it's accu for a return code, with the N and Z flags set according to that value, plus independent C and V flags?

If so, i'll ask the XY question again. =)

What about
pha
bit $xxxx; %x1xxxxxx somewhere in ROM code
pla
to set the V flag with N+Z tied to accu value?
2023-04-03 11:33
Fresh

Registered: Jan 2005
Posts: 101
If thats the case you dont even need to save/restore A.
Edit: my bad, you're perfectly right!
2023-04-03 11:34
Krill

Registered: Apr 2002
Posts: 2850
Quoting Fresh
If thats the case you dont even need to save/restore A.
The BIT instruction sets N and Z, and those flags being set according to the value in the accu is a prerequisite.

Edit: Ah. :)
2023-04-03 11:35
Fresh

Registered: Jan 2005
Posts: 101
Yes, I realized It Just a second after submitting :D
2023-04-03 12:29
tlr

Registered: Sep 2003
Posts: 1717
Quoting Krill
Quoting tlr
for information, it is used in superfluid in many places to pass an additional easily branchable return flag besides the carry.
So it's accu for a return code, with the N and Z flags set according to that value, plus independent C and V flags?

If so, i'll ask the XY question again. =)

What about
pha
bit $xxxx; %x1xxxxxx somewhere in ROM code
pla
to set the V flag with N+Z tied to accu value?
Yes, I suppose that should do the trick in most cases. It can be X/Y for return codes in some places though, think $ffd5.

So far I found it easier to just preserve everything to be safe.
Previous - 1 | 2 - 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
Guests online: 120
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Dawnfall V1.1  (9.5)
8 Quadrants  (9.5)
9 Daah, Those Acid Pil..  (9.5)
10 Birth of a Flower  (9.5)
Top Groups
1 Nostalgia  (9.3)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (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.054 sec.