Frant's Amiga 68K assembler adventures
Page 1 of 1
Frant
King's Bounty



Posts: 24893
Location: Your Mom
PostPosted: Fri, 16th Aug 2024 08:05    Post subject: Frant's Amiga 68K assembler adventures
Part 1:

So I felt the urge to really get back into 68K assembler on the Amiga and this time stick with it.

I haven't done any real programming on the Amiga since 1994. I've made 2-3 attempts to get into it again the last couple of years but then forgot about it (truth: gave up after an hour).

I really believed that it would all come back to me almost instantly as I started. Oh how wrong I was. I remember the basics of it but I soon realized I had forgotten a TON of important things like various addressing variations, advanced use of registers and a lot that's needed to actually write useful code.

I created a disk with AsmTwo, the best assembler for OG Amiga coding IMHO, this particular version based on AsmOne, focusing on pure A500 68000 OCS/ECS assembly for effectiveness and saving a lot of RAM for actual code.

So I downloaded a startup sample source code from an online assembler course to get me started. A startup routine sets up everything needed for demo coding including turning off most of the OS, system interrupts etc. which gives me full control of the system and RAM.

Let's just say that the sample startup source code is 75% gibberish to me. Granted, it was written by a very skilled and advanced demo coder from a group called Scoopex which explains the dense and complex (for me) code he wrote.
(link to the page: Coppershade

I started AsmTwo, reserved 100KB chipmem for code and data and loaded "PhotonsMiniStartup.S" and was presented with this:



It was mainly me going "huh? what's that? what's he doing? how..?". I recognized all the mnemonics like move.*, bne/bra, lea, add etc. but the addressing modes of registers, jumps and branching was just gibberish to me.

I realised I had to go simple and re-learn a lot of the basic stuff before being able to follow more advanced code. I guess that's what happens when you haven't programmed in ~30 years. So I decided to write the simplest program I could think of:

Code:

loop:
   add.w #$0001, $dff180   ; add 1 to the background color register
   btst #6, $bfe001            ; is the left mouse button tested?
   bne loop                        ; no? goto loop
   rts                                 ; otherwise return to assembler/os


That obviously worked since it's one of the most simple things you can do in assembler. No setup, no initialization of various system components (except for testing the mouse button), no calls to the operating system etc.

Now I have to take the next step re-learning my old hobby.


Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn!
Back to top
iconized




Posts: 4782
Location: Pays-Bas
PostPosted: Fri, 16th Aug 2024 09:01    Post subject:
Good luck! Smile
Back to top
Ankh




Posts: 23471
Location: Trelleborg
PostPosted: Fri, 16th Aug 2024 09:43    Post subject:
Keep us updated!


shitloads of new stuff in my pc. Cant keep track of it all.
Back to top
LeoNatan
☢ NFOHump Despot ☢



Posts: 74732
Location: Israel
PostPosted: Fri, 16th Aug 2024 14:47    Post subject:
Any reason to go with direct assembly and not with C and something like https://github.com/bebbo/amiga-gcc ?

I understand if it’s for nostalgia purposes and you want to relive the experiences you had when your were writing the assembly yourself. But if the source of your hunger is making actual software, it is more than likely that a modern compiler will produce a more optimized binary than you would, and your velocity is likely to skyrocket.


My IMDb Ratings | Fix NFOHump Cookies | Hide Users / Threads | Embedded Content (Videos/GIFs/Twitter/Reddit) | The Derps Collection

“Don't cry because it's over. Smile because it happened.”
Back to top
Frant
King's Bounty



Posts: 24893
Location: Your Mom
PostPosted: Fri, 16th Aug 2024 17:55    Post subject:
Nah, I'm only doing it for fun, not for productivity. It's partly because of nostalgia but also a way to stimulate my brain.

The goal is to make an intro or a demo at some point. Pure assembler is fun on Amiga. I have total control over everything in the machine and the mindset of programming in assembler on the Amiga is quite rewarding (at least when you get something to work).

Assembler on the Amiga is the most efficient language for games, demos, intros etc. Most games were written in 68K assembler for that very reason.


Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn!
Back to top
Nalo
nothing



Posts: 13714

PostPosted: Fri, 6th Dec 2024 18:42    Post subject:
Bump. Update?
Back to top
Frant
King's Bounty



Posts: 24893
Location: Your Mom
PostPosted: Fri, 6th Dec 2024 19:45    Post subject:
Been slow going. I've been trying to find a good commented startup/init code example so I can write my own. I don't want to copy someone else's code, I want to understand every part of it.

Addressing modes are many and complex; the macro assembler I'm using have different syntaxes for various things that I have to learn to be able to code like I used back in the day when I used a different (and clunkier) assembler (SEKA).

I need to dig up my old Amiga Hardware Reference manual but I have no idea where it is. A proper startup/init routine can be quite complex with many hardware registers to manipulate in order to turn off the OS, take control of all interrupts etc. etc. etc.

I looked at Photon from Scoopex example but he's written a massive startup/init source that covers everything and is divided into a wrapper and the exhaustive init source.

The easiest thing would be to copy the startup/init code from one of my early 90'ies source codes but I often wrote spaghetti code back in the day to get to the actual meat of the project and thus they're sloppy, have low compatibility with expansions/later CPU's/later OS revisions and so on. In other words it's not really usable for what I want to do.

I need to sort out that initial speed bump, find my hardware reference manual, check out some of my old source codes to see how I did things.

"I'll be back!"


Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn!
Back to top
Ankh




Posts: 23471
Location: Trelleborg
PostPosted: Fri, 6th Dec 2024 22:21    Post subject:
Frant wrote:
Been slow going. I've been trying to find a good commented startup/init code example so I can write my own. I don't want to copy someone else's code, I want to understand every part of it.

Addressing modes are many and complex; the macro assembler I'm using have different syntaxes for various things that I have to learn to be able to code like I used back in the day when I used a different (and clunkier) assembler (SEKA).

I need to dig up my old Amiga Hardware Reference manual but I have no idea where it is. A proper startup/init routine can be quite complex with many hardware registers to manipulate in order to turn off the OS, take control of all interrupts etc. etc. etc.

I looked at Photon from Scoopex example but he's written a massive startup/init source that covers everything and is divided into a wrapper and the exhaustive init source.

The easiest thing would be to copy the startup/init code from one of my early 90'ies source codes but I often wrote spaghetti code back in the day to get to the actual meat of the project and thus they're sloppy, have low compatibility with expansions/later CPU's/later OS revisions and so on. In other words it's not really usable for what I want to do.

I need to sort out that initial speed bump, find my hardware reference manual, check out some of my old source codes to see how I did things.

"I'll be back!"


https://archive.org/details/amiga-hardware-reference-manual-3rd-edition

Smile


shitloads of new stuff in my pc. Cant keep track of it all.
Back to top
Frant
King's Bounty



Posts: 24893
Location: Your Mom
PostPosted: Sat, 7th Dec 2024 22:16    Post subject:
Thanks. I prefer paper books that I can have next to me when I code. I'll find my HRM. I know in which room it is, I just have to look through stuff.


I think I've found a really good example of a startup routine. Every single line is commented which makes it a lot easier to understand.

https://bumbershootsoft.wordpress.com/2024/08/10/amiga-500-bare-metal-startup-code/


Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn!
Back to top
Frant
King's Bounty



Posts: 24893
Location: Your Mom
PostPosted: Wed, 22nd Apr 2026 05:51    Post subject:
I found the treasure of all treasures for Amiga 68K assembler programming documentation.

Abacus_Amiga_Machine_Language.pdf
Abacus_Amiga_System_Programmers_Guide.pdf
Commodore_Amiga_Hardware_Reference_Manual_2nd.pdf
Commodore_Amiga_Hardware_Reference_Manual_[600dpi][ocr].pdf
Commodore_Amiga_ROM_Kernel_Reference_Manual_Exec.pdf
Commodore_Amiga_ROM_Kernel_Reference_Manual_Includes_and_Autodocs_2nd_[600dpi][ocr].pdf
Commodore_An_Overview_of_the_Advanced_Amiga_Architecture_1993_Dev_Con_Release_DocRe
Motorola_MC68000_Programming_Reference_Card.pdf

Now I need to set up a second monitor to display the documentation while I'm programming in ASMTwo on the main display.

There's not really much else one need beyond the information in those books. The most important ones, esp. for demo coding, are the books covering the hardware/architecture. I already know most of the instructions and their use except for some more complex addressing modes etc. so it's mainly all the hardware/chipset addresses and how to use them that matters.

One of the most important chipset features is the Blitter which is part of the Agnus co-processor. It's got direct dma access to chipmem (the main 512-1024 KB memory on A500) that is accessible for both the CPU and the chipset hardware as opposed to any expansion memory that is only accessible to the CPU.

The documentation on how to use for instance the blitter which is a pretty complex thing to control entirely without depending on using Rom/OS libraries to do it for you and even then it's quite tricky unless you know it inside and out, something which I don't, especially not since it's been 35 years since I wrote a single line of code for it.

It's basically a fast, versatile and customizable memory block copier that copy's variable sized chunks of chip memory quickly using the DMA independently from the CPU. You can use two different sources (A and B) and combine them while using some advanced bit manipulation (masking, transformation etc.) to a destination (D) that is for instance an object showing up on screen.

Using masking you can "blit" a block of memory containing an image of a ball, apply a mask during the blit with the result in the blitter skipping the pixels during the copy using the mask to draw the ball onto the screen without drawing the surrounding empty/background pixels in the square or rectangular chunk that is being copied.

Besides being faster than the stock MC68000 CPU the main chipset functions (blitter, copper, audio etc.) work independently from the CPU. They share the DMA bus which means you have to know or control how much DMA time each component (incl. CPU) can use.
You can use the default timing and priority rules or you can take control over it and distribute the bandwidth as you see fit. If you do the latter you have to make sure the CPU/Copper/Blitter don't try to use the bus at the same time as well as make sure each task is given the bandwidth it needs at any given time.
That's mostly necessary for complex 50/60 fps graphical stuff where they try to squeeze as much performance as possible from the Amiga while keeping it running at full framerate.

The thing is that I know a lot of these concepts but I need to relearn the actual nitty-gritty programming. It's not like any high level language where you don't control the hardware directly, you tell a lower level abstraction layer to do it for you.


When I studied system development I realized that high level programming isn't "fun" like that, at least not for me. It's just a necessary means to an end. Sure, solving various problems using C/C++/C#/database/whatever can be quite satisfying it feels a bit like "cheating" compared to programming assembler. I've never felt "oh, I want to make something in Visual C#". That's not fun to me, that's just work.

I realize that's purely a "me"-thing. My first "era" of programming (beyond basic) was assembler on the C64 and later Amiga 500/1200. I enjoyed learning Pascal since it challenged me to think about programming in a more pure problem solving way compared to assembler. You're distanced from the nitty gritty of low level programming where you have to know what every byte does and which registers you have to read/manipulate which paradoxically makes it both easier and more difficult to use for any given end result.

After learning C# well enough it felt more like programming basic except it was magnitudes more powerful. C is more hands-on bare metal than it's younger siblings but it's still like an advanced form of basic compared to pure assembly. It's used purely for the end result, not for the fun of it. Again, that's a me-thing.

Anyway, over the last couple of months I've developed a kind of plan or strategy on how to go about it properly. Ironically I took inspiration from the time I studied system development. Breaking down a problem into smaller pieces.. like creating a flow chart and then split each entry into the needed functions that must be implemented. I clearly remember those classes. They were very enlightening and useful.

_rant_over: cmp.l d0,(a6)
bne _rant_over
rts

>a
> Assembly ok - no errors
>
> j _rant_over
>

c:\


Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn!
Back to top
madmax17




Posts: 20693
Location: Croatia
PostPosted: Wed, 22nd Apr 2026 12:52    Post subject:
Amiga had some great games Very Happy
Back to top
Frant
King's Bounty



Posts: 24893
Location: Your Mom
PostPosted: Thu, 23rd Apr 2026 03:10    Post subject:
It sure did.


Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn!
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group