27 March 2016, 18:06 | #1 |
Zone Friend
Join Date: Jan 2005
Location: Crete
Age: 46
Posts: 191
|
Non OS friendly C and other stuff...
Hi,
I'm trying to wrap my head around how some things work, and could use some guidance. I'm tinkering with some non os friendly C code, but this subject seems to not be as widespread as asm. Sadly my asm understanding is very low. Right now (based on other peoples source), I can "close" the os and take over the machine as soon as it boots. Poking a color register I can turn the background black, and that's that. Nothing much, but a small win for me. :-) I stopped there and started reading. So, let's say one would like to program a *ahem* game with C and non OS functions. There should be a loop where everything happens: <pre> while(!end_game) { DoStuff(); } </pre> 1) How do you check the keyboard? I know the data is on CIAA on ciasdr register. I can take a look there, and get the raw keycode. So with some tinkering, I can get a function on the loop to check the register contents at each loop. Seems to work, and I can get the keys. However, I feel it's not the best solution. Do I need to setup my own interrupt (level 2?) handler to manage it, or would the simpler solution do? I assume that when I have an interrupt handler, it will get called each time a keyboard interrupt fires, and then I can go on my way (no "CheckKeyb()" in the loop). Would I then have enough 68000 time to do things? 2) On the loop itself: Does it need to wait for a scanline to reach the end of the display and then "DoStuff()" ? Or any other way to sync on the display? Otherwise the same loop would run much fuster on say an 020 vs a 00, right? I think I saw somewhere that copper could be setup to raise an interrupt when it reaches a specific line, and that could be used as a "Delay" function? 3) The copper. Read a bit, but can't really tell where it fits on the big picture. You basically load it with a copperlist (ie. a copper program) using the only three commands (MOVE, WAIT, SKIP). Does it always run? Does it always need to do something? 4) Besides the Amiga Hardware Reference Manual, and the RKMs, are there any other books in a "guide" rather than reference format? AHRM seems great for e.g. Hardware playfields, but totally lost it with the copper chapter. 6) Am I mad for trying these with C? Sorry if these sound dumb. Many thanks. |
28 March 2016, 09:03 | #2 |
Zone Friend
Join Date: May 2006
Location: France
Posts: 1,801
|
You can look at Deluxe Paint I source code to see how the Blitter is used by banging the HW for a start. (http://www.computerhistory.org/atchm...y-source-code/)
Yoy can also check how does perform a demo using the graphics.library an C : https://github.com/voitureblanche/projet-secret You can also look at the Star Frontiers demo there : http://ftp.amigascne.org/pub/amiga/G...QuarkDemo1.lha Kamelito Last edited by kamelito; 28 March 2016 at 18:18. Reason: + |
28 March 2016, 18:02 | #3 |
Zone Friend
Join Date: May 2006
Location: France
Posts: 1,801
|
|
28 March 2016, 20:55 | #4 | |||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
What's sure is that you won't overload a 68000 with that. Quote:
Otherwise, indeed, the loop will run faster on 020 than 000. Quote:
It will be stopped if its DMA channel is turned off. It will also do nothing while in a WAIT instruction, the end of a copperlist being a special form of WAIT. Its program is automatically restarted at each vblank, and it can also be started manually. Yes But if you like it just do it |
|||
29 March 2016, 09:09 | #5 |
Registered User
Join Date: Jun 2013
Location: Australia
Posts: 685
|
Of course if you launch it from Workbench the hardware will catch fire
Just wanted to also thank for the information. The links there, I never knew existed. |
30 March 2016, 00:46 | #6 | |||||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,498
|
Quote:
1. Open graphics.library: Load a NULL-View: LoadView(NULL); WaitTOF(); WaitTOF(); 2. Get the blitter: OwnBlitter(); WaitBlit(); 3. Disable all interrupts (custom->intena=0x7fff). Disable all DMA (custom->dmacon=0x7fff). Disarm the mouse sprite. 4. Disable AGA or ECS features, when not needed. Set FMODE. 5. Set up your own display and interrupt vectors. Everything can be done in C. You might need a small assembler stub to determine the VBR on 68010+ systems (movec vbr,d0), which you need as a base to write new interrupt vectors. Quote:
Quote:
Although interrupts in C are compiler specific and even impossible with some. An M68k interrupt function ends with an RTI (return from interrupt) instruction and not with an RTS (return from subroutine), which a compiler usually generates. Some compilers offer a special attribute for such functions, like __interrupt. Otherwise you have to make a small assembler stub routine which you link to the main program. Quote:
BTW, you may want to use the hardware/custom.h header file in C, when accessing custom chip registers. Define a pointer to the custom chip base: Code:
#include <hardware/custom.h> volatile struct Custom *custom = (struct Custom *)0xdff000; Quote:
C is just a very comfortable macro assembler. It is not uncommon to write larger parts of a game in C. Look at Lazycow's Powerglove, for example. |
|||||
30 March 2016, 14:20 | #7 |
Zone Friend
Join Date: Jan 2005
Location: Crete
Age: 46
Posts: 191
|
Woah, guys, many thanks for your answers. Will need some time to digest all this, esp. the source codes.
@phx Indeed, I'm using the stuff under hardware/custom.h. Thanks! |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
System friendly Protracker Replay? | AGS | Coders. System | 2 | 16 August 2014 20:53 |
Stuff for sale amiga a1200 plus more retro stuff | blast | MarketPlace | 23 | 22 June 2010 19:05 |
Amiga stuff for trade for Atari Stuff | 8bitguy1 | MarketPlace | 0 | 12 February 2009 05:36 |
Looking for the best WB friendly ECS demos - without music | mr_a500 | request.Demos | 0 | 03 April 2005 21:14 |
060 Friendly Demo? | Methanoid | request.Demos | 2 | 30 November 2004 16:07 |
|
|