| |
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? |
|
| |
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 :) |
| |
tlr
Registered: Sep 2003 Posts: 1727 |
Quoting BurglarI 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. |
| |
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? :) |
| |
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. |
| |
Rastah Bar
Registered: Oct 2012 Posts: 336 |
Maybe like this:
sta somewhere
php
pla
ora #%01000000
pha
lda somewhere
plp
|
| |
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. |
| |
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 :) |
| |
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! |
| |
tlr
Registered: Sep 2003 Posts: 1727 |
Quoting FreshYour 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. |
| |
tlr
Registered: Sep 2003 Posts: 1727 |
Quoting TWWYou 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 |