Dipping my Toes into Atari 8-Bit Assembly – Hello World!

First the obligatory comment: It’s been a long time since I have posted anything at all. Not sure why per say just haven’t had a ton to say. Now on to what I want to say today.

Since I was a young child, I have had a fantasy about learning to program in assembler. Specifically 6502 assembly language for the Atari 8 bit computer line. I never really did much to make that ‘dream’ into a reality. I learned many other languages on a few different platforms, but my understanding of the 8-bit Atari internals was pretty limited.

As I have posted, I got an Atari 8-bit machine in the last year or two. I haven’t had a ton of time playing with it, but I would still like to learn 6502 Assembly. I decided to start playing with Mac/65 on the Atari itself and MADS on my MacBook Air M1 to see if I could even get a type in Hello world working, modify it a little and understand some of it. I’m not aspiring to become the next retro game developer for this platform or anything. I want to understand the platform/language at this level and maybe use it to springboard into the Commander X16 when it becomes available.

I found this program over on https://unfinishedbitness.info/tag/byte/ - and decided to give it a go on the Atari.  And, OMG, after looking through this guy's blog it is definitely something I plan to bookmark and re-visit.  He's done a ton of 8-bit programming not only in Assembler but in Action! and Basic as well. 
05     .OPT OBJ
10     *= $0600
0100 ; CIO
0110 ICHID = $0340 ;IOCB 0 S:
0120 ICCOM = $0342 ;IOCB Command
0130 ICBAL = $0344 ;Xfer Buffer Adr
0140 ICBAH = $0345
0150 ICPTL = $0346 ;PutByte Adr
0160 ICPTH = $0347
0170 ICBLL = $0348 ;Buffer Len
0180 ICBLH = $0349
0190 CIOV = $E456 ; CIO Vector
0500 ; Setup CIO Call
0510     LDX #0 ;IOCB 0
0520     LDA #9 ;Put Cmd Val
0530     STA ICCOM,X ;Set it as the cmd
0540     LDA #HELLO&255 ;Str low byte
0550     STA ICBAL,X
0560     LDA #HELLO/256 ;Str high byte
0570     STA ICBAH,X
0580     LDA #0 ;Str Len low byte
0590     STA ICBLL,X
0600     LDA #$FF ;Str Len high byte
0610     STA ICBLH,X
0620 ; Call CIO
0630     JSR CIOV
0640     RTS 
1000 HELLO .BYTE "Hello World!",$9B

I typed this into Mac/65, and it didn’t work. I’m not sure if I did something wrong or if it just was wiping out the address code or output before I got out of the debugger. In any case, I wasn’t going to be discouraged. I went through the code, and it looked like it was compiling correctly.

MAC/65 Assembler Atari 8-Bit Listing a program

I knew from some past playing with assembler on this Atari that Mac/65 was kind of touchy about some standard memory locations where programs like this were located. I recently went through the Atari Roots book and remembered this is the case with many example programs there. In any case, I changed line 10 from above to:

10     *= $3000

I was immediately rewarded, fresh from the DDT debug of G 3000 with this:

Pretty cool; I now have something on the screen! I mean, I didn’t figure anything out here or anything — I just typed in someone else’s program. The way I did with I was ten years old from Compute! and Antic magazines with BASIC programs. But, I remember too that doing precisely this and then experimenting with the code is what allowed me to learn BASIC back in those days. So maybe I could still do this.

There were a couple of problems with this program:

From DOS 2.5’s Binary Load command there was no output after assembling to disk with:

ASM ,,#D2:

That said the program would load just fine under Spartados.

Trying to understand this, I ran across a similar but more complex version of a Hello World example on Wikipedia https://en.wikipedia.org/wiki/Atari_Assembler_Editor#Example_code. Here was a snippet I found that looked promising.

0020 START
0320 RUNAD = $02E0   ;RUN ADDRESS

...

0590 ; INIT RUN ADDRESS
0600 ; ----------------
0610     *=  RUNAD
0620     .WORD START
0630     .END

I used this code and some internet searching to find this site, https://cc65.github.io/doc/atari.html#s2, for a C compiler for the Atari 8 bit line (that might be something fun to check out at some point as well). In it indicates:

A run vector is added to the end of the file ($02E0 $02E1 <run vector>) 

CC65 Documentation

This reference looks precisely like what is happening up here. We are setting up an address RUNAD = $02E0. Then, at the end of the program, we are loading that address with our program’s start address. So I set out to fix this program with the following changes:

10        *= $3000
0020 START
0030 RUNAD = $02E0 ;  Run Vector Location

...

1100.    *=RUNAD
1110     .WORD START

Success!

Atari Dos 2.5 Screen after running modified Hello World program with the Run Vector Set.

I am going to stop here for now. Though there is still a ‘problem’ to solve with this (it only stays on the screen for about a second). I do plan to write more about my experiments with Atari 6502 assembler soon, though. I did, in fact, get this program to compile from my MacBook Air using MADS and added a loop to it to allow the program to run for a while before continuing. I’ll save that part for later.