Jump to content

X16 Assembly Tutorial


SlithyMatt
 Share

Recommended Posts

4 minutes ago, borgar said:

There are plenty of tutorials for 6502 assembly out there (here is one that starts gently https://codeburst.io/an-introduction-to-6502-assembly-and-low-level-programming-7c11fa6b9cb9). It might not be a bad idea to do read a few such documents before jumping into videos.

I think you probably should not start out with something too ambitious for your first attempts. You probably can a lot of smaller programs without having to deal directly with the stack pointer. You can start by transferring parameters in the registers (A, X and Y) and/or direct memory addresses (Zero Page or not) and limit your self to implicit stack use with JSR/RTS.

I'd also recommend taking looking at Prog8 (https://prog8.readthedocs.io/en/latest/#). This gives you something a lot faster than Basic while not being as completely low level as assembly.  Prog8 allow inclusion of assembly into the program fairly gracefully when you need "full speed" and if you just need a few really fast (non-recursive) functions you don't not need to learn to use the program stack. And since Prog8 produces assembly output (before producing the binary with 64tass) it will also allow you to learn a lot from looking at the produced output when you are interested.

BTW, back in the day (80's) when I did some limited machine code programming I basically had no understanding of the stack and the only stack related commands I used was just JSR and RTS. But what I wrote then was basically stuff gleaned from some assembly examples in various C64 magazines and I probably only understood about half the 6502 instruction set.

Thanks for the links. My first program I want to write would be an appointment Calendar for the x16 with some nice graphics for the day. Once program loads you type in the month that you want to add data to. then once on that screen you type in the day number which would open an editor to add times of reminders and description for that day. Once you are done writing all the appointments you have for that month you can save the updated calendar file either to the hard disc or to a floppy for load up later. I figured this maybe too hard to write in

basic so I thought maybe handling more variables would be more suited for assembly. Again thanks for the links, I will continue to follow the series on YT while also reading this more basic documentation and hopefully eventually everything will start clicking in my head.

Link to comment
Share on other sites

Posted (edited)

This is a great 6502 tutorial: https://skilldrick.github.io/easy6502/

And pretty much all of what you learn there can be applied to the 65C02.    I basically started with that tutorial, and then did a bunch of stuff in the VICE C64 emulator.    At first I was using a Fast Load cartridge image and its built in monitor to do simple Assembly programs.  Then graduated to the Super Snapshot and its built in monitor, but also Turbo Macro Pro (this is all still on the C64).  @Robin Harbron in his 8-bit Show And Tell channel on YouTube turned me on to Super Snapshot and Turbo Macro Pro.  Here is his Assembly Language playlist: 

 

 

I'd recommend cutting your Assembly Language teeth on the C64 (the 6510 is a 6502 with just a few changes).  As the C64 is a fixed and known platform with 35+ years of information that can be easily found on the web.  Then once you're more comfortable with 6502 Assembly, start learning the in's and out's of the X16 and VERA, which should be relatively quick and easy at that point.

Edited by x16tial
  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...

just wanted to pop in and say thanks to Matt for these outstanding tutorials!  Looking at the slides, the scripts, and especially the nice clean per-topic demos, seems like there must be hours of work in each hour of video.

  • Thanks 1
Link to comment
Share on other sites

  • 3 weeks later...

Summary of Matt's Videos, as I run through them

Requirements:

 

IF YOU'RE NEW TO THE 6502 OR ASSEMBLY LANGUAGE, START HERE

Lesson One (27m): Foundations. What assembly language is, the 6502 architecture (and related processors), registers, memory addresses and how instructions work.  The anatomy of an assembly language program at 14:00.  lda, inc, sta, and rts.  cl65 invocation at 18:00.  Examining the .list and .PRG at 20:00.  X16 debugger at 23:00.

Lesson Two (32m): Addressing modes. X16 Memory Map intro.  Addressing modes 4:00.  Examples 11:30.  Jump table 22:00.  Build script 26:00, execute & debug.

 

IF YOU'RE A NOVICE, START HERE

Lesson Three (24m): Flow control.  C versus assembly 1:00. Status register and compares 5:45. Loops (C versus assembly) 12:00. Functions (C versus assembly) 13:30.  X16 KERNAL 16:00.  Example program 16:45.

Lesson Four (22m): Unsigned math and logic.  Add- and Subtract-with-carry 3:00. 16-bit arithmetic 5:45.  Inc and Dec 8:00.  Mul and div overview 9:20.  Shift and rotate 11:00.  Bitwise ops 13:20. Logicals 14:50.  Example 16:00.

 

IF YOU DID SOME ASSEMBLY ON SOMETHING ELSE, START HERE

Lesson Five (21m): The Program Stack.  JSR and RTS 6:28. RTI 7:10.  Push and Pull 7:45. Stack transfers 8:50.  Examples of playing with the stack; also .asciiz 11:30.

Lesson Six (22m): New bit test and branch opcodes in the 65C02.  The old BIT 3:00. TRB and TSB 5:45.  BBRn, BBSn, RMBn, SMBn 7:00.  Example 12:00.

Lesson Seven (19m): The rest of the 65C02's instruction set.  Basically Lesson Six, part Deux.  Also, ERRATA for previous sessions starting at 10:00.  Example 12:00.

 

IF YOU'RE NEW TO COMMODORE, BUT NOT 65C02, START HERE

Lesson Eight (36m): The KERNAL.   ROM banks 3:00. Jump table example: CHROUT 4:00. Hacking the jump table 6:00. CHRIN 9:25. GETIN 10:40. Keyboard buffer 11:30. SCREEN 12:50. PLOT 14:00. File load (SETLFS, SETNAM, LOAD) 15:10.  Saving a memory block to file (SAVE) 20:45.  Example involving screen mode, keyboard input, and load/save to file 20:50

 

IF YOU'RE NEW TO THE COMMANDER X16, BUT NOT THE KERNAL OR 65C02, START AT LESSON NINE.

 

 

 

 

Edited by rje
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use