Running Games and Apps. |
SAGA Coding Tricks | page 1 2
|
---|
|
---|
| | Gunnar von Boehn (Apollo Team Member) Posts 6254 28 Apr 2020 07:34
| The other day my son Arne (12) was coding his first Amiga ASM game. Lets us show some small SAGA coding tricks he used.1) How to play a Game music with few lines of code move.l #musik,$DFF0A0 ; We play one 2.5 Min PCM music file 22khz move.w #5670,$DFF0A4 ; Length low bits move.w #158,$DFF0A6 ; Sample rate 22050 move.w #27,$DFF0AE ; Length high bits move.w #64,$DFF0A8 ; Volume move.w #64,$DFF0AC ; Volume Far Side move.w #$8001,$DFF096 ; Turn AUDIO DMA on for Channel 0incbin "SpyVsSpy.aiff" ; 3.5 MB music file
The music PCM file is a converted MP3. Its mono, 8bit, 22050 Khz, and about 2.5 minute long. As you see with just a few MOVE instructions a complete background music can be played. The Amiga Audio chipset will automatically loop the music. SAGA Audio Hardware allow to position a channel. We use this and play this it back with max Volume of 64 on both sides LEFT and RIGHT
| |
| | Ray Couzens
Posts 93 28 Apr 2020 09:01
| This doesn't look difficult, there is hope for me yet to start learning ASM on the V4 :-)
| |
| | Gunnar von Boehn (Apollo Team Member) Posts 6254 28 Apr 2020 09:15
| Yes I think coding for AMIGA is very easy. We can also post more examples to show how to "show sprites", "move sprites", "check collision", "use joystick" ... In short all you need to make a small game
| |
| | Ray Couzens
Posts 93 28 Apr 2020 10:09
| That would be very much appreciated.
| |
| | Olle Haerstedt
Posts 110 28 Apr 2020 11:01
| Something to add to a wiki of snippets. ;D
| |
| | Peeri the Sunlight
Posts 72 28 Apr 2020 11:43
| Thanx BigGun, This forum is excelent place and I read it daily, but coding tricks etc. should be collected some kind of guideline or tricks and hints to apollo-accelrators wiki, to be "permanently" visible and and maybe to even make somekind of tutorials there. Just these small examples to show newbie cooders that its not hard at all. Even I can bit contribute something, if it is open for community updates (after moderation). Small examples, routines, good optimizing practices etc. free to use modify, benefit etc. All for build eventually some kind of coder base again. (it has been alread 25 years since my last commercial release for Amiga!!! need to do something)
| |
| | Kamelito Loveless
Posts 261 28 Apr 2020 12:14
| Nice but the link below state that it is a complete list of SAGA registers, but yet the one you used are not there why? https://www.apollo-accelerators.com/wiki/doku.php/saga:registers:start
| |
| | Peeri the Sunlight
Posts 72 28 Apr 2020 12:47
| Kamelito Loveless wrote:
| Nice but the link below state that it is a complete list of SAGA registers, but yet the one you used are not there why? https://www.apollo-accelerators.com/wiki/doku.php/saga:registers:start |
At work now, and not havin RKRM at hand. These seems to be just normal Amiga registers. Not SAGA specific.
| |
| | Kamelito Loveless
Posts 261 28 Apr 2020 13:03
| $AC to $AE are existing registers but are not used on Amigas.
| |
| | A1200 Coder
Posts 74 28 Apr 2020 14:09
| That's great for age of 12. When I was 12 years old, I had initially a difficulty in understanding even BASIC on C64, how to use variables and all that to create a working text adventure. I mean it was easy to print out text on screen and read input from keyboard, but how do you get it to work so that when you picked up an object, you couldn't do it again, and the game knew which items you had. When I was 15, I learned to code asm on Amiga, typed in the examples of various programming books, indeed one was that audio example you gave. But it was always a bit hacky, with hardware accessing code, mixed with OS library programming code. But what really got me going was a book on Amiga games programming, which only used asm and hardware. It featured many examples, like ready code for a hardware disk trackloader, filled blitter polygon, scrolling examples, audio, serial port programming, keyboard routine, bobs & sprites, interrupts and all that which you needed. It also had a playroutine for protracker music. I believe we need another good manual that explains also AGA chipset and SAGA. The hardware ref manual is simply no good for a games programmer, much more detailed examples are needed to get going fast. For AGA and SAGA topics could be: CPU sprites, mixing audio to get more channels, or splitting up an audio channel for several bands of sound effects (TDM). Efficient real-time 2d rotation of sprites, and c2p routines with texture mapping. And someone should make a book on amiga system programming, with latest OS 3.2 releases and up.
| |
| | Kamelito Loveless
Posts 261 28 Apr 2020 15:14
| Do you remember the name of that book?
| |
| | Gunnar von Boehn (Apollo Team Member) Posts 6254 28 Apr 2020 16:28
| A1200 coder wrote:
| The hardware ref manual is simply no good for a games programmer, much more detailed examples are needed to get going fast.
|
I think it would be great if we develop some small demo games. Like "Deluxe" Versions of of classics. I believe we can with a pages of ASM using the AMIGA Sprites make real nice games. So think we could teach people how to write a short game on a Sunday afternoon.
| |
| | Mr Niding
Posts 459 28 Apr 2020 16:50
| This is one of my best and earliest memories on the C64 gamingwise; EXTERNAL LINK
| |
| | Olivier Landemarre
Posts 147 28 Apr 2020 18:40
| Gunnar von Boehn wrote:
| The other day my son Arne (12) was coding his first Amiga ASM game. Lets us show some small SAGA coding tricks he used. 1) How to play a Game music with few lines of code move.l #musik,$DFF0A0 ; We play one 2.5 Min PCM music file 22khz move.w #5670,$DFF0A4 ; Length low bits move.w #158,$DFF0A6 ; Sample rate 22050 move.w #27,$DFF0AE ; Length high bits move.w #64,$DFF0A8 ; Volume move.w #64,$DFF0AC ; Volume Far Side move.w #$8001,$DFF096 ; Turn AUDIO DMA on for Channel 0 incbin "SpyVsSpy.aiff" ; 3.5 MB music file
The music PCM file is a converted MP3. Its mono, 8bit, 22050 Khz, and about 2.5 minute long. As you see with just a few MOVE instructions a complete background music can be played. The Amiga Audio chipset will automatically loop the music. SAGA Audio Hardware allow to position a channel. We use this and play this it back with max Volume of 64 on both sides LEFT and RIGHT
|
looks simple but in this case you suppose your music is fully in the memory bloc and need big buffer and suppose convert music file to PCM before able to play. Music player decode at fly so it need minimum 3 buffer 2 for the system audio to switch when one is finish to the second and a third for decode and replace the buffer already played. Apllication need to know when a buffer is played to replace by a new one or feed this buffer. I suppose it is possible but where can found some information for this? Olivier
| |
| | Mark Watson
Posts 5 28 Apr 2020 20:34
| The sample has to be loaded into memory yes, but the re-sampling is done in hardware. There may be a small buffer in hardware somewhere, but it will not be stored in main memory on your device and it is probably very small with low latency. Amiga hardware reference is here: EXTERNAL LINK From the description in hw reference manual you can see that looping has no cost in buffer sizes as samples are pulled two values at a time based on AUDxPOS ($DFF0A0 in this case) register which is reloaded when chipset gets to the end of the sample. You can write one value to AUDxPOS wait until it is read the first time and then write the next sample. There are various options for waiting, which one is best depends on playback needs, there's an interrupt that can be added to load a new value exactly when a sample ends for example.
| |
| | Gunnar von Boehn (Apollo Team Member) Posts 6254 28 Apr 2020 22:04
| Olivier Landemarre wrote:
| looks simple but in this case you suppose your music is fully in the memory bloc and need big buffer and suppose convert music file to PCM before able to play.
|
Yes the focus on this example was being simple or making game coding very easy.
| |
| | Chris Chris
Posts 25 29 Apr 2020 06:42
| Amiga coding in ASM is really a nice thing.You can create functions, sub routines, objects, modules and also use makros. This makes coding finally very comfortable and systematic. When a functions is tested and does its job then put it into a sub routine and forget about it. Over time there will be a good summary of routines, so that you can concentrate only on what you are targeting to. Important is only to make good comments of each routine and how to use the routine. This could mean just as example: - Sub routine for back ground music (repeated) - Sub routine for sounds that are played at a certain event, so only once - Sub routine that controls the sprite of the main player based on the joystick - subroutine to move a playfield (background picture) based on joystick right or joystick left - sub routine for sprite enemy 1 and so step by step means routine by routine a project is created. Or a Intro/Demo where you can see how all is working. Due to Motorola Code it makes code reading really nice. The AMIGA has its BLITTER, COPPER, AGA that makes AMIGA different from many other platform when you want to make GFX, DEMOS and SOUND. You can read also this code easily. And also after years you can step back into old projects and make get run again for having fun. What I am missing for today is that there is no "ready to run ASM environment". You need to start from scratch: take the Vamp, update the core, put OS on, update OS, then create an environment for ASM and then step into VSAM. It would be nice for future when a small VASM environment would be added with some "asm trining files" ( 1) hardware coding 2) OS code opening a window ) to test if ASM environment works. This would make starting coding more easier for newbies and would make give a positive direct feedback of success when receiving a new VAMP. All the best and have fun ! Greetz
| |
| | A1200 Coder
Posts 74 29 Apr 2020 08:39
| Kamelito Loveless wrote:
| Do you remember the name of that book?
|
Yes, I'm not sure if it's useful for you, because it's written entirely in finnish and its only for OCS Amigas. It's called "Amigan pelintekijän opas". If you google for this title, you should find it as a pdf download. But yeah, some good short code examples there still, also for audio programming. Unfortunately, if I remember correctly, nobody ever wrote a good game programming book for Amiga in english, which is only about asm+hardware.
| |
| | Gunnar von Boehn (Apollo Team Member) Posts 6254 29 Apr 2020 08:45
| A1200 coder wrote:
| Unfortunately, if I remember correctly, nobody ever wrote a good game programming book for Amiga in english, which is only about asm+hardware.
|
Actually the hardware reference manual contains all info you need. It explains with example how to use the Copper. It explains with example how to display a screen. It explains with example how to play audio. It explains with example how to use Sprites. It explains VBL IRQ and Joystick and mouse. What else do you need to know to write a game?
| |
| | A1200 Coder
Posts 74 29 Apr 2020 09:14
| Gunnar von Boehn wrote:
|
A1200 coder wrote:
| Unfortunately, if I remember correctly, nobody ever wrote a good game programming book for Amiga in english, which is only about asm+hardware. |
Actually the hardware reference manual contains all info you need. It explains with example how to use the Copper. It explains with example how to display a screen. It explains with example how to play audio. It explains with example how to use Sprites. It explains VBL IRQ and Joystick and mouse. What else do you need to know to write a game?
|
Well, you often need a mousedriver and a keyboard routine that works. Not so easy to make from scratch and there are no such things in HW ref manual. And then of course some scrolling methods, which doesn't update whole screen. Blitter examples for filled vectors would also be nice. Also some floppy trackloader is good to have ready made, if needed. And some discussion about music module players would be nice to have (cia or vbl timed). On AGA, you may need some info on how to open a hardware screen for other screenmodes than OCS offers (e.g. VGA+doublePAL), not explained well in hardware ref manual (or anywhere else), even if it covers ECS chipset. AGA chipset was also never documented by Commodore.
| |
|
|
|