Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Jedfox ! (Registered 2024-05-28) 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: 1727
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?
2023-04-02 15:47
Burglar

Registered: Dec 2004
Posts: 1050
I dunno what SEV is, maybe explain that first?

judging from the code, how about this:
tsx
lda $0100,x
ora #%01000000
sta $0100,x

not sure on the exact offset, u gotta calc that urself
edit: probably I misread the code :)
2023-04-02 16:19
tlr

Registered: Sep 2003
Posts: 1727
Quoting Burglar
I dunno what SEV is, maybe explain that first?

Sure, SEV is the opposite of CLV, the elusive missing instruction. :)

The intention is not to affect anything other than just setting V=1.
2023-04-02 16:45
Krill

Registered: Apr 2002
Posts: 2855
I just use to BIT ZP with the zeropage variable set to $40.

If the N or Z flags need to be preserved or set to some specific value, it may get a little more complicated.

This is very rarely the case in real-world code, so why this code golf? :)
2023-04-02 21:16
tlr

Registered: Sep 2003
Posts: 1727
Quote: I just use to BIT ZP with the zeropage variable set to $40.

If the N or Z flags need to be preserved or set to some specific value, it may get a little more complicated.

This is very rarely the case in real-world code, so why this code golf? :)


Sure, I use bit <zp> or bit <abs> too. In this case it's part of the function library in superfluid where it is used (as a subroutine) in many places. As a library function I want everything to be preserved and only the V flag touched. I opted for no zp usage as well but that's not required.
2023-04-02 21:55
Rastah Bar

Registered: Oct 2012
Posts: 336
Maybe like this:
	sta somewhere
	php
	pla
	ora #%01000000
	pha
	lda somewhere
	plp
2023-04-02 21:59
tlr

Registered: Sep 2003
Posts: 1727
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: 1727
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: 1727
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.
 
... 5 posts hidden. Click here to view all posts....
 
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
GI-Joe/MYD!
Retroluzzer/Quantum
Sentinel/Excess/TREX
Mythus/Delysid
Hoild/Ultimate Newco..
Guests online: 117
Top Demos
1 Next Level  (9.8)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Aliens in Wonderland  (9.6)
6 Edge of Disgrace  (9.6)
7 No Bounds  (9.6)
8 Comaland 100%  (9.6)
9 Uncensored  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Happy Birthday Dr.J  (9.7)
2 Layers  (9.6)
3 It's More Fun to Com..  (9.6)
4 Cubic Dream  (9.6)
5 Party Elk 2  (9.6)
6 Copper Booze  (9.6)
7 TRSAC, Gabber & Pebe..  (9.5)
8 Rainbow Connection  (9.5)
9 Dawnfall V1.1  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Nostalgia  (9.4)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 SHAPE  (9.3)
Top NTSC-Fixers
1 Pudwerx  (10)
2 Booze  (9.7)
3 Stormbringer  (9.7)
4 Fungus  (9.6)
5 Grim Reaper  (9.3)

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