Amiga System Programmers Guide

  • View
    24

  • Download
    10

Embed Size (px)

DESCRIPTION

Whether you want to know abouthardware, EXEC or DOS, you'll find allthis information and more in the AmigaSystem Programmer's Guide. This bookexplains how the Amiga operating systemworks, in plain simple English.Abacus

Transcript

  • i comprehensive guide to the

    inner workings of your Amiga

    Abacu

    A Data Becker Book

  • Amiga System

    Programmer's Guide

    Dittrich

    Gelfand

    Schemmel

    A Data Becker Book

  • First Printing, August 1988

    Printed in U.S.A.

    Copyright 1987,1988 Data Becker, GmbH

    Merowingerstrafie 30

    4000 Dusseldorf, West Germany

    Copyright 1988 Abacus

    5370 52nd Street SE

    Grand Rapids, MI 49508

    This book is copyrighted. No part of this book may be reproduced, stored in a retrieval

    system, or transmitted in any form or by any means, electronic, mechanical, photocopying,

    recording or otherwise without the prior written permission of Abacus Software or Data

    Becker, GmbH.

    Every effort has been made to ensure complete and accurate information concerning the

    material presented in this book. However, Abacus Software can neither guarantee nor be

    held legally responsible for any mistakes in printing or faulty instructions contained in this

    book. The authors always appreciate receiving notice of any errors or misprints.

    AmigaBASIC and MS-DOS are trademarks or registered trademarks of Microsoft

    Corporation. Amiga 500, Amiga 1000, Amiga 2000, Graphicraft, Musicraft, Sidecar and

    Textcraft are trademarks or registered trademarks ofCommodore-Amiga Inc* Seka assembler

    is a registered trademark ofKuma Corporation.

    ISBN 1-55755-035-2

    u

  • Contents

    1 The Amiga Hardware 1

    1.1 Introduction 3

    1.2 Amiga system components 4

    1.2.1 The 68000 processor 5

    1.2.2 The 8250 CIA 10

    1.2.3 The custom chips 22

    1.2.3.1 Basic structure of the Amiga 23

    1.2.3.2 The structure ofAgnus 26

    1.2.3.4 The structure ofDenise 30

    1.2.3.6 The structure ofPaula 33

    1.2.3.7 Features of the Amiga 500 36

    1.3 The Amiga interfaces 38

    1.3.1 The audio/video interfaces 39

    1.3.2 The RGB connector 40

    1.3.3 The Centronics interface 42

    1.3.4 The serial interface 45

    1.3.5 External drive connector 47

    1.3.6 The game ports 52

    1.3.7 The expansion port 54

    1.3.8 Supplying power from the interfaces 57

    1.4 Thekeyboard 59

    1.4.1 The keyboard circuit 60

    1.4.2 Data transfer 62

    1.4.3 Keyboard bugs 64

    1.5 Programming the hardware 66

    1.5.1 The memory layout 66

    1.5.2 Fundamentals 75

    1.5.3 Interrupts 86

    1.5.4 The Copper coprocessor 88

    1.5.5 Playfields 96

    1.5.6 Sprites 122

    1.5.7 Theblitter 134

    1.5.8 Sound output 167

    1.5.9 Tips, tricks, and more 182

    1.5.10 Mouse, joystick and paddles 190

    1.5.11 The serial interface 196

    1.5.12 Data transfer with the Amiga UART 198

    1.5.13 The disk controller 200

    Hi

  • Contents Amiga System Programmers Guide

    2 Exec 205

    2.1 Operating system fundamentals 207

    2.2 Introduction to programming the Amiga 208

    208

    210

    213

    215

    220

    224

    226

    226

    228

    228

    234

    235

    236

    244

    247

    247

    249

    251

    261

    265

    266

    268

    270

    271

    273

    275

    276

    276

    278

    281

    286

    287

    292

    295

    295

    298

    302

    303

    307

    iv

    2.2.1

    2.2.2

    2.2.3

    2.2.4

    2.3

    2.3.1

    2.3.2

    2.3.3

    2.3.4

    2.3.5

    2.3.6

    2.4

    2.4.1

    2.4.1.1

    2.4.2

    2.4.2.1

    2.4.2.2

    2.4.2.3

    2.4.2.4

    2.5

    2.5.1

    2.5.2

    2.5.3

    2.5.4

    2.5.5

    2.5.6

    2.6

    2.6.1

    2.6.2

    2.6.3

    2.7

    2.7.1

    2.7.2

    2.7.3

    2.7.3.1

    2.7.3.2

    2.7.4

    2.7.5

    2.8

    Differences between C and assembly language

    Construction ofnodes

    Lists

    Exec routines for list management

    Libraries

    Opening a library

    Closing a library

    Structure of a library

    Changing an existing library

    Creating a custom library

    The remaining library functions

    Multitasking

    The task structure

    Task functions

    Communication between tasks

    The task signals

    The signal functions

    The message system

    Message system, trap and exception functions

    Amigamemory management

    The AllocMemO andFreeMemO functions

    The memory list structure

    Memory management and tasks

    Internal memory management

    The Allocate and Deallocate functions

    Remaining functions

    I/O handling on the Amiga

    The IORequest structure

    Construction of a device

    I/O control with functions

    Interrupt handling on the Amiga

    The interrupt structure

    Soft interrupts

    The CIA interrupts

    The CIA resource structure

    Managing the resource structure

    Description of interrupt functions

    Example ofan interrupt server

    The ExecBase structure

  • Abacus Contents

    2.9 Reset routine and reset-proof programs 315

    2.9.1 Documentation of the reset routine 315

    2.9.2 Resident structures 323

    2.9.3 Reset-proofprograms and structures 328

    2.9.4 A proper NoFastMem 331

    3 AmigaDOS 333

    3.1 TheDOS library 335

    3.1.1 Loading the DOS library 335

    3.1.2 Calling functions and passing parameters 336

    3.1.3 The DOS functions 337

    3.1.4 DOS error messages 347

    3.2 Disks 350

    3.2.1 Tlie boot procedure 351

    3.2.2 File structures and data distribution 352

    3.2.2.1 Disk layout 353

    3.2.2.2 Program structure 358

    3.2.2.3 The IFF 363

    3.3 Programs 369

    3.3.1 Program start and parameters 369

    3.3.1.1 Calling from the CU 369

    3.3.1.2 Starting from the Workbench 372

    3.3.2 Structure of the transient CLI commands 378

    3.4 Input/Output 381

    3.4.1 Standard I/O 381

    3.4.1.1 Keyboard and screen 383

    3.4.1.2 Disk files 388

    3.4.1.3 Serial interface 389

    3.4.1.4 Parallel interface 390

    4. Devices 393

    4.1 TracKDisk device 395

    4.2 Console device 405

    4.3 Narrator device 410

    4.4 Serial device 414

    4.5 Printer device 417

    4.6 Parallel device 418

    4.7 Gameport device 419

    Appendix An overview of the library functions 423

  • 1The Amiga

    Hardware

  • Abacus 1.1 Introduction

    1.1 Introduction

    The Commodore Amiga offers the user capabilities at a price which one

    would never have dreamed of a few years ago. To make these features

    possible, a powerful operating system and hardware work closely

    together.

    A high level of user friendliness was one of the main goals the

    developers of (his computer had. The intent was to use the mouse and

    the Workbench as a graphic user interface to make it easy to use the

    computer. But not only did they want to make it easy to use, they

    wanted to provide good support for programmers as well. For almost

    any conceivable task there is a routine in the operating system which

    makes direct programming ofthe hardware unnecessary.

    But in spite of all of these system routines, for maximum speed you

    can't avoid direct machine language programming. The speed of the

    operating system routines are much slower than you would expect from

    a computer as advanced as the Amiga. The reason for this is that large

    parts of the Amiga's operating system were written in the C

    programming language. The C language produces portable, readable and

    quick running code, but programs developed in C are not as compact,

    efficient or as fast as programs developed completely in machine

    language.

    If you want to write fast and efficient programs, or if you just want to

    learn more about your Amiga, you have to work directly with the

    hardware. The following chapter offers a description of the Amiga

    hardware and the programming of the individual components.

  • 1. The Amiga Hardware Amiga System Programmer's Guide

    1.2 Amiga system

    components

    Essentially the Amiga hardware consists of the following components,

    regardless of whether the system is an Amiga 500,1000 or 2000:

    The Motorola MC68000 microprocessor

    Two serial interfaces, type 8250

    Three custom chips from Commodore, called Agnus, Denise and

    Paula

    If you ignore the RAM and logic components for a moment, the six

    chips listed above are responsible for all the functions of the Amiga.

    Interfaces All of the necessary interfaces are also available on the Amiga:

    Parallel printer port

    Serial RS-232 interface

    RGB monitor connection

    Composite video connection (not on early Amiga 2000s)

    Stereo audio output

    Connector for an RF modulator (Amiga 1000 only)

    Keyboard

    Connector for an external disk drive (Shugart-bus compatible)

    Two identical connectors for various input devices like a mouse,

    joystick or paddle

    Connector for 256K RAM expansion (Amiga 1000This will

    not be discussed in this book because only the original

    expansion from 256K to 512K bytes can be connected here. On

    the Amiga 500 and 2000 these 256K bytes are already built in.

    The Amiga 500 has a connection for a 512K RAM expansion,

    but it's completely different from this connector)

    Expansion port to connect system expansions of all types (on

    the Amiga 500 and 1000 this connection is on the side of the

    case, while on the Amiga 2000 it is in the form of multiple card

    connector inside the housing.)

    In order to understand how all of these components work together, we

    must first explain the function