10 May 2018, 01:45 | #21 | ||||||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
Code:
linker a.o b.o c.o -o myprogram Quote:
Quote:
Quote:
Quote:
Quote:
Otherwise I see no suboptimal code at all. You can still call these routines with BSR, or do PC-relative or small-data references, as if the exported symbols had been "included". Your only issue will be that you might lose 2 bytes between object from time to time, because AmigaDOS hunk sizes are always a multiple of 4. |
||||||
10 May 2018, 10:34 | #22 | |||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
On the other hand, in object files you can not make adaptative code (i.e. code that will open only the libs the program really uses, etc). I mean, no if/endc depending on something defined in the main program. Not when the program grows ; only when the included file itself grows in a significative manner, which is unlikely to happen in this case (and with a fast enough asm on a fast enough machine, it needs to be really big to count : PhxAss on WinUae JIT can assemble a 1MB asm source in less than 1 second !). Quote:
Quote:
In addition, attempts to have them called with PC-relative modes may fail in big projects, where the called module is at the limit of the allowed range (a likely story in a large program where the included code can be called from anywhere). What happens if the linker wants to write 16-bit PC offset but the distance is >32kb ? A good asm can adapt to this. But even the best linker in the world can't do better than generating an error. |
|||
10 May 2018, 13:01 | #23 | |||||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
Just put your routines, which you want to link on demand, in separate object files. Then put all these objects into a library - e.g. myroutines.lib. When linking your main program with -lmyroutines only those objects will be included where the linker has seen references to its symbols. And for automatically opening/closing libraries there is a linker-feature called constructor/destructor lists. For example, your program references GfxBase and the linker pulls an object into the linking process which adds a constructor pointer for opening graphics.library. The only thing you have to do is processing the constructor/destructor function pointer lists in your startup code. Quote:
Quote:
Quote:
Quote:
As a conclusion for Akira I can only say he has to make his own experiences and find his personal best approach. As we can see there are several options, and as they are used by excellent coders like Stingray and Meynaf since many decades they cannot be all that wrong. Everybody has to find his personal priorities. Last edited by phx; 10 May 2018 at 13:02. Reason: typo |
|||||
10 May 2018, 13:39 | #24 | ||||||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
But someone like Akira needs the simplest solution to start with. Fiddling with linkers is too much to learn at once i'm afraid - and looks overkill for simple ReadJoypad.s. There is something to learn here though : no two programmers will ever agree on how things must be done |
||||||
10 May 2018, 15:59 | #25 | |
Registered User
Join Date: May 2001
Location: ?
Posts: 19,645
|
Quote:
Maybe unlike other people, I don't like to get offered "the simplest solution" only, I like to read all the options and then do a comfortable average of what I researched as my solution. So this thread has been very educational with the perspective of three experienced programmers. For the time being I will probably not deal with linking because I can barely compile :P but it seems like a powerful tool to consider in the near future. |
|
03 June 2018, 20:14 | #26 |
Registered User
Join Date: Mar 2018
Location: Prague
Posts: 35
|
I decided to learn how to use joystick. It required reading lots of manuals and hunting down some example codes before I managed to get anything working. To make life easier for the other newbies like me, here's a simple example how to read joystick:
------ #include <stdio.h> #define REG_CIAA_PRA_R *((volatile const unsigned char*) 0xBFE001) #define REG_CIAA_DDRA *((volatile unsigned char*) 0xBFE201) #define REG_JOY1DAT_R *((volatile const unsigned short*) 0xDFF00C) int main() { // Clear bits 6 & 7 in CIAA DDRA --> PRA0 bits 6 & 7 are in input mode (fire buttons) REG_CIAA_DDRA &= ~((1 << 6) | (1 << 7)); while (1) { const unsigned short joystick_bits = REG_JOY1DAT_R; const unsigned short joystick_vert_bits = 2*(joystick_bits & 0x0101); const unsigned short joystick_up_down = (joystick_bits & 0x0202) ^ joystick_vert_bits; if (joystick_up_down & 0x0200) printf("UP "); if (joystick_up_down & 0x0002) printf("DOWN "); if (joystick_bits & 0x0200) printf("LEFT "); if (joystick_bits & 0x0002) printf("RIGHT "); if (!(REG_CIAA_PRA_R & 0x80)) printf("FIRE "); printf("\n"); } return 0; } |
03 June 2018, 23:03 | #27 |
Knight Of The Kingdom
Join Date: Feb 2016
Location: It's a bald world!
Posts: 179
|
I'm handling JoyStick Pressed very simply in a tutorial I'm writing
Code:
move.w $dff00c,d0 move.w d0,d1 JoyStickRight: btst #1,d0 beq JoyStickLeft add.w #2,Bob_XPosition JoyStickLeft: btst #9,d0 beq JoyStickUp sub.w #2,Bob_XPosition JoyStickUp: lsr.w #1,d1 eor.w d1,d0 btst #0,d0 beq JoyStickDown add.w #2,Bob_YPosition JoyStickDown: btst #8,d0 beq JoyPressedDone sub.w #2,Bob_YPosition JoyPressedDone: rts |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
implement others 68000 machines ? | turrican3 | support.WinUAE | 28 | 23 November 2017 00:54 |
Joystick reading code | borchen | Coders. Asm / Hardware | 57 | 23 November 2014 14:08 |
Req: Tanks 'n' Stuff Src Code | kevingpo | request.Old Rare Games | 1 | 07 July 2003 12:07 |
Should I implement PM download now ? | RCK | project.EAB | 12 | 08 January 2002 01:21 |
|
|