TI 83 Plus Assembly/Advanced

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Advanced z80 programming techniques[edit | edit source]

Hooks[edit | edit source]

Interrupts[edit | edit source]

What are interrupts?[edit | edit source]

Types of interrupts[edit | edit source]

Type 0[edit | edit source]
Type 1[edit | edit source]
Type 2[edit | edit source]

How to code them[edit | edit source]

How to install them[edit | edit source]

Principles[edit | edit source]
The jump table[edit | edit source]

Direct LCD Interaction[edit | edit source]

Principles[edit | edit source]

Port $10[edit | edit source]

Writing[edit | edit source]
Reading[edit | edit source]

Port $11[edit | edit source]

Writing[edit | edit source]
Reading[edit | edit source]

Optimizations[edit | edit source]

xor a[edit | edit source]

A common shortcut to set the accumulator (A) to zero is by xor'ing it against itself:

 ; instead of doing this
   ld a,0
 ; you can do this
   xor a

This is incredibly widespread and won't affect the readability of your code. In fact, it is so common that it might even be more readable than using "ld a,0". But be warned that "xor a" modifies the flags (it sets the z flag and resets the carry, for example) whereas "ld a,0" doesn't modify any flags.

ld (addr),reg16[edit | edit source]

When writing to two consecutive bytes in memory, it can often be faster and smaller to use a 16-bit register rather than two loads with a.

 ; rather than
   ld a,$10
   ld (penCol),a
   ld a,$20
   ld (penCol),a
 ; you can do
   ld de,$2010
   ld (penCol),de

This loads e into (penCol), and d into (penCol+1). penCol+1 is penRow. Keep in mind, however, that using hl to read/write from addresses in memory is (4 t-states) faster and one byte smaller than using de/bc.

X <= A <= Y[edit | edit source]

If you want to know if the value of the accumulator is between two other values, eg. 10 and 25, you might be tempted to do something like this:

   cp 10      ; check if a >= 10
    jr c,wrongValue
   cp 26      ; check if a <= 25
    jr nc,wrongValue
 ; do whatever you wanted to do
 wrongValue:
 ; ...

However, rather than doing two comparisons and jumps, you can change the first cp into a subtraction. This turns any number less than 10 into a negative number. For example:

   sub 10      ; a value of 10 now equals 0
   cp 26-10    ; because of the sub 10, we now need to check if a is between 0 and 16, not 10 and 26
    jr nc,wrongValue
 ; do whatever you wanted to do
 wrongValue:
 ; ...

This method lets you avoid the first jr.