[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] TAS in GFA Linker



On 08/09/2014 05:28, Lonny Pursell wrote:
I was re-reading the thread and noticed I missed the subtle differences
between TAS and BSET regarding what it actually tests.
TAS - entire byte - both Z and N are used
BSET - only the bit being set - only Z is used

Would this alternate patch method below work?
Should work in all cases when one doesn't have clue how the asm routine
works that they are trying to patch.

;original code
     tas    (a1)
     bpl.s  label

;alternate code
temp:       dc.w 0    ;add this somewhere or use a free register if you can

     move.b  (a1),temp ;copy the byte in question (previous value)
     bset    #7,(a1)   ;clobber bit 7 as tas would do
     tst.b   temp      ;set Z and N based on prev value like tas
     bpl.s   label     ;original branch instruction unchanged

I think it is correct (to be carefully tested).
The main idea is to consider all the bits which were *previously* set in the TAS argument, not only bit #7.

Of course, it would be better to fully understand the original routine, and be sure of the value of the other bits is important or not. In many routines, the variable used as TAS argument can only take the values of 0x00 or 0x80, so it is simpler.

Andreas's remark about interrupt safety is valid when TAS is used as a thread-safe mechanism (as it should always be). In cases where TAS usage was not justified and used as a geek-BSET (such as SDL), the thread unsafety is not a problem.

--
Vincent Rivière