QL Assembly Language Programming

Learn to program the Motorola MC6800x processor on your Sinclair QL.


Dedication

This book is dedicated to small army of dedicated users of the Sinclair QL computer. It's been around since 1984 and will be celebrating its 21st birthday in 2005. Here's hoping it can manage another 21 years.

In addition, it must be dedicated to my wife Alison, who has tolerated my need to 'play' with computers for many many years. She doesn't understand how or why I can work with computers all day, then come home and still want to 'play' with them in my free time. It's a woman thing - they just don't understand :o)

Table of Contents

Where did this book come from ?
1. QL Assembly Language Programming
1. Introduction
2. The Project ... QLTedit
3. The 6800x Processor
3.1. Registers
3.2. Data Registers
3.3. Address Registers
3.4. Status Register
3.4.1. The System Byte
3.4.2. The User Byte
3.5. The Program Counter
4. Addressing Modes
4.1. Register Direct
4.2. Absolute
4.3. Relative
4.4. Address Register Indirect
4.5. Register Indirect With Displacement
4.6. Register Indirect With Displacement And Index
4.7. Register Indirect With Pre Decrement Or Post Increment
4.8. Immediate
5. End of Part 1
2. The 6800x Instruction Set
1. Introduction
2. The MOVE Instruction Family
2.1. Exercise
2.2. Answers
3. The CMP Instruction Family
4. Signed and Unsigned Numbers
5. Testing Condition Codes and Branching
6. End of Part 2
3. The 6800x Instruction Set - continued
1. Introduction
2. More Branches.
3. Counting
3.1. Adding and Subtracting
3.2. Division and Multiplication
3.3. Negation
4. The Project
5. End of Part 3
4. The 6800x Instruction Set - continued
1. Introduction
2. Tie the NOT
3. This OR That
4. This AND That
5. Exclusive OR Instructions
6. Shifting And Rotating
7. End of Part 4
5. The 6800x Instruction Set - continued
1. Introduction.
1.1. A Few Quickies !
1.2. A Few Little Bits
1.3. Testing, Testing
1.4. And Finally ?
1.5. So Here We Are !
1.5.1. Comparing Things
1.5.2. Signed Numbers being MOVEd
2. End of Part 5
6. 6800x Exceptions And Exception Handling
1. Introduction
2. Exceptions
3. Working QDOS Exceptions
4. What happens when an exception occurs ?
5. Building an exception handler.
6. The exception handler code.
7. How it works.
8. End of Part 6
7. Extending SuperBasic
1. Introduction
2. Linking To SuperBasic
3. Procedures
4. Functions
5. Getting Parameters
5.1. Keeping Things Even
5.2. Two Of These And One Of Those Please
6. Name Table Entries
7. Name List
8. The Maths Stack
8.1. A1 Is Negative
8.2. A1 Is Zero
8.3. A1 Is Positive
9. Returning Values From Functions
10. Channel Tables
11. Exercise
12. End of Part 7
8. The QL Screen
1. Introduction
2. The Screen
3. Mode 4 - screen memory usage
4. Mode 8 - screen memory usage
5. That calculation again!
6. Problems
7. Exercise
8. Answer
9. End of Part 8
9. Subroutines
1. Introduction
2. Subroutines
3. Building A Library
4. Documentation
5. The Subroutine Library
6. STR_COPY
7. STR_APPEND
8. STR_REVERSE
9. STR_INSERT
10. STR_COMP
11. STR_COMPI
12. FILE_CLOSE
13. FILE_OPEN
14. FILE_OPENIN
15. FILE_OPENNEW
16. FILE_OPENOVER
17. FILE_OPENDIR
18. FILE_GET_HEAD
19. FILE_SET_HEAD
20. PRINT
21. LINE_FEED
22. INPUT
23. JOB_HEADER
24. MEM_ALLOC
25. MEM_DEALLOC
26. SCR_MODE
27. CLS
28. SCR_PAPER
29. SCR_PAPER_SB
30. SCR_INK
31. SCR_STRIP
32. COLOURS
33. The Librarian
33.1. So how does this lot work ?
34. End of Part 9
10. Linked Lists
1. Introduction
2. Linked Lists
2.1. Adding Nodes.
2.2. Deleting Nodes.
2.3. Finding Nodes.
2.4. The Code Wrapper.
2.5. Running The Wrapper Code.
2.6. Problem Areas.
3. Doubly Linked Lists.
3.1. Adding Nodes.
3.2. Deleting Nodes.
3.3. Finding Nodes.
3.4. A Better Mousetrap.
3.5. Double Trouble.
3.6. Sorting Lists.
4. Remember those arrays?
5. End of Part 10
11. Single Linked Lists Demo Code
1. Introduction
2. How Does The Code Work?
3. End of Chapter 11
12. Doubly Linked Lists Demo Code
1. Introduction
2. How Does The Code Work?
3. End of Chapter 12
13. Recursion
1. Introduction
2. Recursion in Assembly Language
2.1. Factorials
2.2. The Fibonacci Series
3. End of Chapter 13
14. Program Development
1. Introduction
2. Program Development in Assembly Language
2.1. The Initial Thought.
2.2. Work It Out.
2.3. Start Writing Code.
2.4. Testing The Code.
3. End of Chapter 14

List of Tables

2.1. Signed & Unsigned Tests
4.1. Truth Table for Logical OR
4.2. Truth Table for Logical AND
4.3. Truth Table for Logical EOR
6.1. MC6800x Exception Table
6.2. QDOS Exception Table
7.1. Definition Block For BP_INIT
7.2. Register Settings On Entry To SuperBasic Extensions
7.3. Vectored Routines For Parameter Fetching
7.4. Function Return Data Types
7.5. SuperBasic Channel Table Definition
8.1. Mode 4 Screen Memory Word Format
8.2. Mode 4 Colour Codes
8.3. Mode 8 Screen Memory Word Format
8.4. Mode 8 Colour Codes
8.5. Bitmaps for Mode 4 pixel masking

List of Examples

3.1. BSR Example
3.2. DBNE Example
3.3. Looping Example
3.4. Another Looping Example
3.5. Potentially Bug-ridden Looping Example
3.6. Bug-fixed Looping Example
3.7. ABCD Example
3.8. DIVS Example
4.1. Pretty Bad Privacy Example
4.2. LSL Example
4.3. LSR Example
4.4. LSL Multiplication Example
4.5. LSR Division Example