Tips and Tricks for Atari 400 800.doc

(265 KB) Pobierz
TIPS AND TRICKS FOR ATARI 400/800

ARITHMETIC

 

CHAPTER 1

 

1.1.                             Input and output of numbers

 

   When working with numbers one often wants to input and output them via the screen. The following programs show how th is can be done with hexadecimal as well as decimal numbers.

 

1.1.1.               Hexadecimal input

 

   This program allows you to enter hexadecimal numbers using the keyboard. The number entered is displayed on the screen. The input stops if a character different from the hexadecimal numbers (0.. F) is entered.

The program first deletes memory locations EXPR and EXPR+1. This ensures a result equal to zero, even if an invalid number is entered. Next, the program reads a character and checks whether or not it is a hexadecimal number. If it is, then the upper bits of the number in the accumulator are erased and the lower bits are shifted up. Now, these four bits can be shifted to EXPR from the right. The preceeding number in EXPR is shifted to the left by doing so.

   If you enter a number with more- than four digits, only the last four digits are used.

   Example : ABCDEF => CDEF

 

 

 

HEXINPUT  ROUTINE

 

 

EXPR                             EQU $80.1

SCROUT               EQU $F6A4

GETCHR               EQU $F6DD

ORG $A800

 

A800:              A2 00                            HEXIN                            LDX              #0

A802:              86 80                                                        STX              EXPR

A804:              86 81                                                        STX              EXPR+1

A806:              20 2C A8              HEXINI              JSR              NEXTCH

A809:              C9 30                                                        CMP              '0

A80B:              94 1E                                                        BCC              HEXRTS

A80D:              C9 3A                                                        CMP              '9+1

A80F:              90 0A                                                        BCC              HEXIN2

A811:              C9 41                                                        CMP              'A

A813:              90 16                                                        BCC              HEXRTS

A815:              C9 47                                                        CMP              'F+1

A817:              80 12                                                        BCS              HEXRTS

A819:              E9 36                                                        SBC              'A-10-1

A81B:              0A                            HEXIN2              ASL             

A81C: 0A                                                        ASL             

A81D: 0A                                                        ASL             

A81E: 0A                                                        ASL

A81F:              A2 04                                                        LDX              #4

A821: 0A                             HEXIN3              ASL             

A822:              26 80                                                        ROL              EXPR

A824:              26 81                                                        ROL              EXPR+1

A826: CA                                                        DEX             

A827:              DO F8                                                        BNE              HEXIN3

A829:              FO DB                                                        BEQ              HEXINI ALWAYS !!

A82B: 60                            HEXRTS              RTS             

 

A82C:              20 DD F6                NEXTCH               JSR               GETCHR

A82F: 20 A4 F6                                           JSR              SCROUT SHOW CHARAC'.

A832: 60                                                         RTS

 

PHYSICAL ENDADDRESS: $A833

*** NO WARNINGS

 

EXPR              $80

GETCHR              $F6DD

HEXIN1              $A806

HEXIN3              $A821

NEXTCH              $A82C

                           

SCROUT              $F6A4

HEXIN                            $A800 UNUSED

HEXIN2              $A81b

HEXRTS              $A82B

 

 

1.1.2.               Hexadecimal output

 

   The next program explains the output process of the calculated numerals.

   You will recognize, that the portion of the program which controls the output is a subroutine. This subroutine only displays the contents of the accumulator. This means that you first have to load the accumulator with, for example, the contents of EXPR+1, then jump into the subroutine where first the MSB (EXPR+1 in our case) and then the LSB (EXPR) will be printed.

Subroutine PRBYTE independently prints the most significant bytes of the accumulator first and the least significant bytes second.

 

 

 

 

HEXOUT  PRINTS  1  BYTE

 

 

                                          EXPR                            EPZ              $80.1

                                          SCROUTE              EQU              $F6A4

ORG              $A800

A800:              A5 81                            PRWORD              LDA              EXPR+1

A802:              20 0B A8                                          JSR              PRBYTE

A805:              A5 80                                                        LDA              EXPR

A807:              20 A8                                                        JSR              PRBYTE

A80A:              60                                                        RTS

 

* THE VERY PRBYTE ROUTINE

 

A80B:              48                            PRBYTE              PHA

A80C:              4A                                                        LSR

A80D:              4A                                                        LSR

A80E:              4A                                                        LSR

A80F:              4A                                                        LSR

A810:              20 16 A8                                          JSR              HEXOUT

A813:              68                                                        PLA

A814:              29 0E                                                        AND              #$00001111

A816:              C9 0A                            HEXOUT              CMP              #10

A818:              B0 04                                                        BCS              ALFA

A81A:              09 30                                                        ORA              '0

A81C:              D0 02                                                        BNE              HXOUT

A81E:              69 36                            ALFA                            ADC              'A-10-1

A820:              4C A4 F6              HXOUT                            JMP              SCROUT

 

PHYSICAL ENDADDRESS:$A823

 

*** NO WARNINGS

 

EXPR                             $80

PRWORD               $A800   UNUSED                            

HEXOUT               $A816                             ...

Zgłoś jeśli naruszono regulamin