Author Topic: Yet Another Z80 ASM Tutorial  (Read 5195 times)

0 Members and 1 Guest are viewing this topic.

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Yet Another Z80 ASM Tutorial
« on: December 18, 2014, 04:06:10 pm »
YAZTA. What a silly name. This is a crosspost:

For a week or two, I've had this thought about making another Z80 assembly tutorial. At the moment, the best tutorial out there is Asm In 28 Days, but I've heard complaints regarding its usability for new people for actual learning material. Sure, it makes a wonderful reference but the one thing I've found is that it doesn't have workable, testable examples and things that one can be done to help reinforce learning. I don't know about most of the other people out there, but I learn best by doing, and the tutorial I want to make will cater to that sort of crowd.

I started writing a sort of road map concerning the topics that should be discussed, and in what order to present them in. I figured that if I want to actually write a tutorial, I'd best have an outline first before announcing anything since an announcement in and of itself isn't all that helpful in getting this idea off the ground.

This is what I have after a bit of thinking. Comments and suggestions appreciated.

Code: [Select]
Z80 Assembly Tutorial For the TI-83 Plus (SE)
Centered around creating a simple game, then making it run faster. Better.
Each section should have DIY tasks to help them understand a concept better.
Subsections explaining actual instructions will be indexed in a different color.

* Introduction
   What ASM is, isn't, what it takes to learn, and tutorial methodology.

* Development Environment
  - Assemblers and getting your first binary (.8xp) assembled.
  - Link software if you have actual hardware
  - Emulators and how to use them.

* Numbers, Variables, and Memory
  - A forward. All these topics will involve the use of the LD instruction and
    its many variations.
  - Numbers
    - Discussion on decimal, hexadecimal, and binary and why to use them.
    - A short note on octal and that it was historically used.
  - Variables
    - Discussion of registers and their short term scope
      - A short note on other special purpose registers and their functions
    - Short discussion about the stack and its longer but still short term scope
    - Discussion of SafeRAM and their scope in-program.
    - Discussion of files and their persistence after a program ends.
  - Memory
    - What memory is, and the different types on the calculator
    - Memory maps and address range
    - A listing of various stretches of safeRAM on the calculator
    - Memory access is just another number. Talk about indirection here.
  - Hardware
    - Very short explanation that additional hardware such as keyboard, memory map
      ports or LCD are accessed via IN/OUT instructions. Each has their method of
      access, and is only briefly mentioned here because memory was discussed.

* System Calls
  - A short section on what a bcall is.
  - Locations and places of references for said system calls.

* Something Useful - Messing Around With Text
( Should showcase all manners of LD instructions and use here )
  - Introducing useful romcalls for messing with the homescreen.
  - A reminder that romcalls can and will mess around with the contents of registers
    and that registers are for SHORT TERM STORAGE.
  - Displaying a string.
  - Introduce the CALL/RET instructions for subroutines
  - Displaying one character at a time
  - Introduce math instructions (ADD/SUB) (INC/DEC)
  - Displaying numbers from registers

* Key input
  - Introduce program control flow via CP/JP
  - Introduce system calls for getting key input, link to reference table
  - Have the user do stuff with keypresses to make the program display different things
  - Implement text "sprite" onscreen and move it around.
  - Introduce and explain z80 FLAGS
    - Tie in this knowledge with math instructions
    - Using that knowledge, implement movement boundary checking

* The Graph Screen and Graph Buffer
  - Introduction to graph buffer and the separation between that and the LCD
  - Displaying text on the graph buffer.
    - Re-implement text sprite on graph buffer
  - Using system calls to draw lines and boxes onscreen
  - Introduction to sprites and the many methods of drawing them to screen
    - Will use ION sprite routine as basis. Its operation will not be explained yet.
    - A note that this topic will be re-visited later on to support clipping

* The Stack
  - Introduction to what the stack is and what it's used for
  - Introduction to PUSH/POP
    - Explanation of push/pop procedures.
      - Upgrade previous program with it.
    - Explanation of CALL/RET and how it messes with the stack
  - Explanation of EX (SP),HL and its use
  - Short explanation of direct stack manipulation
    - Note on how this is generally used to create an exit-from-anywhere point.
    - Caveats about using SP in a manner other than for call/variable stack purposes
      - Link forward to interrupts section if student really wants to abuse SP

* Arrays and Jump Tables
  - Arrays and what they are
    (Now would be a great time to discuss indirection
    - How to read/write to/from them
    - Methods of managing them (if at all)
      - Great place to introduce block copy instructions (LDI[R]/LDD[R])
      - At this point, we can create a graphscreen game
        based on avoiding other moving objects
  - Jump tables
    - What they're for
    - Jump tables filled with 2-byte addresses
    - Jump tables filled with 1-byte offsets

* Bitmasking and Bit Math
  - Introduction to system flags and BIT/SET/RES instructions
    - Messing around with inverting text and those various flags.
      - While we're at it, accelerate text drawing by making vputs routines buffer-only
  - Introduction to the zillions of rotate/shift instructions available on the z80
    - Might as well introduce direct keyboard reading now
      - Shifting and rotating results out to carry seems like a great method to use.
      - Upgrade the game with this.
  - Introduction to AND/OR/XOR instructions
    - Methods of bitpacking so varibles take up less space
    - Setting, resetting, or testing multiple flags at the same time
    - Bitmasking and examining how ION's sprite routine works

* Interrupts
  - Explanation of what interrupts are and how they may be useful
  - Enable, disable, and create and clean up after interrupts
    - Hardware differences that influence this on the SE's and 84's

* LCD and Direct Access
  - Details of the screen itself and manner of access via ports including delays
  - Reference of commands and things you can do
  - Introduction to ION's fastcopy routine
  - Introduction to grayscale. How to abuse interrupts and slowness of LCD to achieve
 
* Accessing Variables Outside Your Program
  - List of what a file is and the various filetypes on the calc
    - Details of each file type and their use
  - Romcalls used to check for, access, create and delete variables
    - With this, perhaps we can create an external high score file?
    - How to resize variables if you weren't sure how large they ought to be on create
  - Explanation of what the VAT is and how to traverse it
  - Explanation of how to access archived variables without unarchiving them first

* Use of TI's Floating Point Structures
  - An overview of what floating point numbers are, and a quick note on fixed-point
    - None of our examples will use them, but this topic is covered for completeness.
      Perhaps you'll get an idea that requires decimal precision and this works.
      That circular version of the worm game comes to mind.
  - Details of TI's floating point format
  - Available romcalls for moving floats and float-sized data.
  - Available romcalls for manipulating the Floating Point Stack (FPS)
  - Available romcalls for mathematical purposes

* Fixed Point Mathematics and Mult/Div routines
  - What fixed point math is and why it may be better to use it
  - Outline of multiplication
    - Naive method
    - Faster multiplication method and why it works
  - Outline of division
    - Naive method
    - How to use fixed point math ideas to multiply by reciprocal instead.
      - Division is slow and awkward. This is a way to avoid it
    - Faster division algorithms and why they work.
      - Oh gawd. I am NOT looking forward to this section.

* Creating Flash Applications
  - What Flash Applications (FlashAPPs) are and why to use them
  - Changes to the dev environment to support FlashAPPs
  - Differences that must be observed (e.x. how to exit flashapps, no SMC, etc.)
  - Multipage FlashAPPs
    - Doing it TI's way, through the use of an in-app bcall table.
    - Doing it our way, through the use of a pagechange stub.
      - Might as well introduce how to mess around with memory mappings here.
      - Also discuss cross-page access

THIS IS WHAT I HAVE SO FAR.
CHERRIES FOR EVERYONE.
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Yet Another Z80 ASM Tutorial
« Reply #1 on: December 18, 2014, 07:48:08 pm »
(Wish me luck posting through those SMF Last IP post errors. I tried earlier and lost my entire post content due to being on a phone and copy/pasting on a phone is like winning at the lottery x.x)

Anyway I like this idea because lack of working examples were always an issue for many people in ASM in 28 days and while Hot Dog tutorial fixes this, it is meant as an add-on to ASM in 28 days, not a full replacement. A new full tutorial aimed at visual people would be a must for ASM learning. Some people will say that we need to understand the basics first before worrying about working code, but the thing is that some people get bored very fast when they try to learn without examples from the real programming world and others just don't understand without them.

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Yet Another Z80 ASM Tutorial
« Reply #2 on: January 02, 2015, 05:33:56 pm »
I think a couple people at revsoft were talking about doing a new tutorial a while back. I know chickendude was specifically interested in adding to one that catered to game programming. Might want to see if any of them are interested in contributing. There was some discussion on Cemetech a while ago as well, but they seemed to be looking to update in 28 days. That said, you can never have enough good learning material, and lots of examples where you can see what things are doing is a great idea imo. :)