24 October 2020, 11:49 | #1 |
Zone Friend
Join Date: May 2006
Location: France
Posts: 1,801
|
Decipher C vs ASM
Hi
Is someone able to explain all those cryptic C lines for me to understand? In ASM it is easy and clear. waitmouse: btst #6, $bfe001 bne waitmouse clr.l d0 rts Now please explain all those cryptic C code please and why is it so complicated. #include <exec/types.h> volatile UBYTE *ciaa_pra = (volatile UBYTE *) 0xbfe001; #define PRA_FIR0_BIT (1 << 6) void waitmouse(void) { while ((*ciaa_pra & PRA_FIR0_BIT) != 0) ; } int main(int argc, char **argv) { waitmouse(); return 0; } |
24 October 2020, 12:04 | #2 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,187
|
C was designed to save keystrokes. That's why it's so cryptic.
|
24 October 2020, 12:12 | #3 | |
Digital Corruption
Join Date: Jan 2007
Location: Dorrigo/Australia
Age: 60
Posts: 355
|
Hi Kamelito, et al.
Quote:
types.h has the definition for UBYTE (unsigned byte value) > volatile UBYTE *ciaa_pra = (volatile UBYTE *) 0xbfe001; Volatile keyword means that the value can change at any time. The program should not try to cache the value it reads from 0xbfe001 > #define PRA_FIR0_BIT (1 << 6) Set PRA_FIR0_BIT to $40 > void waitmouse(void) { Function takes no arguments, and returns nothing. >while ((*ciaa_pra & PRA_FIR0_BIT) != 0) ; Wait for Bit#6 to be ZERO, then return. > int main(int argc, char **argv) Main function is called by the program startup code, and can have an array of string arguments passed from the command line, or through intuition. **argv points at the string argument array, and there are argc number of arguments { > waitmouse(); Call the waitmouse function which will not return until bit#6 of 0xbfe001 becomes ZERO. > return 0; Tell the operating system we had no errors. Cheers, Red |
|
24 October 2020, 12:45 | #4 |
Zone Friend
Join Date: May 2006
Location: France
Posts: 1,801
|
Thanks I’ll have to digest that.
I suppose you’ve to do this for all custom chips registers. Is there a more readable way of doing this? |
24 October 2020, 12:49 | #5 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
|
24 October 2020, 12:50 | #6 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,187
|
First off, #include <hardware/custom.h> will define all the custom registers as one big volitile structure so you can refer to them as custom.regname rather than having to define them individually.
|
24 October 2020, 15:29 | #7 | |
Registered User
Join Date: Aug 2018
Location: Untergrund/Germany
Posts: 408
|
Quote:
while (!((*(volatile char*)0xbfe001)&64)); Volatile means the read must not be cached, but must done in every iteration of the loop. Otherwise the C compiler could optimize this code fully away. Usually you would put such code into an inline function like this: inline char mouseLeft(){return !((*(volatile char*)0xbfe001)&64);} |
|
24 October 2020, 15:31 | #8 |
Zone Friend
Join Date: May 2006
Location: France
Posts: 1,801
|
Thanks, is this the way you handle it on your games?
|
24 October 2020, 15:44 | #9 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,767
|
|
24 October 2020, 15:53 | #10 |
Zone Friend
Join Date: May 2006
Location: France
Posts: 1,801
|
So if I wanna change the background color is this correct?
#include "exec/types.h" #include "hardware/custom.h" struct Custom custom; main() { custom.color[0] = 0x0F00; } |
24 October 2020, 16:04 | #11 | |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Quote:
(besides all other things like the copper list that's running will probably override your change, so maybe this isn't the best first example) (also, this will depend on you linking against something that provides that Custom struct) |
|
24 October 2020, 16:24 | #12 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
|
24 October 2020, 16:50 | #13 | |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
Quote:
void mousewait() {while(*(volatile unsigned char *) 0xbfe001 & (1<<6));} http://franke.ms/cex/z/cvoPbE |
|
24 October 2020, 17:15 | #14 |
Registered User
Join Date: Sep 2014
Location: Poland
Posts: 175
|
|
24 October 2020, 17:27 | #15 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
|
24 October 2020, 18:10 | #16 |
Zone Friend
Join Date: May 2006
Location: France
Posts: 1,801
|
Ok with a bit of help from rkm, I manage to make it work, but why it has to be extern ?
#include "exec/types.h" #include "hardware/custom.h" extern struct Custom far custom; /* far bc I had distance for data reloc16 > 32768 under sasc */ main() { long i; for (i = 0; i < 10000000 ; i++) custom.color[0] = 0x0F00; /* change bg color */ } |
24 October 2020, 18:46 | #17 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,187
|
Extern because the linker resolves the addresses.
|
24 October 2020, 21:37 | #18 |
Zone Friend
Join Date: May 2006
Location: France
Posts: 1,801
|
|
24 October 2020, 21:42 | #19 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,187
|
Probably Amiga.lib linker library.
|
24 October 2020, 21:53 | #20 |
Zone Friend
Join Date: May 2006
Location: France
Posts: 1,801
|
I should have thought of that, thanks.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Asm-One Debugger | Curbie | Coders. General | 29 | 15 May 2021 19:12 |
Tool to convert asm to gnu asm (gas) | Asman | Coders. Asm / Hardware | 13 | 30 December 2020 11:57 |
ASM: Asm-ONE or AsmPro - how to set a Hello amiga coders, I hope it is ok to hijack ? | Fireball | Coders. Asm / Hardware | 2 | 24 April 2020 21:16 |
for ASM programmers | meynaf | Coders. General | 29 | 05 August 2010 10:00 |
|
|