aslfaqs
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
aslfaqs [2025/09/20 16:22] – [How do I use virtual methods to create polymorphic objects?] reggie | aslfaqs [2025/09/23 17:33] (current) – [How do negative numbers work?] reggie | ||
---|---|---|---|
Line 365: | Line 365: | ||
decb ; loop count | decb ; loop count | ||
bne sprEraseLoop | bne sprEraseLoop | ||
- | rts | + | rts |
- | | + | |
==== How do I use local variables? ==== | ==== How do I use local variables? ==== | ||
Line 538: | Line 537: | ||
==== What is indirection and how do I use it? ==== | ==== What is indirection and how do I use it? ==== | ||
- | The standard way of accessing a variable in memory is via **direct extended** addressing. A 16-bit address is given, and an 8 or 16 bit operand is read from this ' | + | The standard way of accessing a variable in memory is via **direct extended** addressing. A 16-bit address is given, and an 8 or 16 bit operand is read from this ' |
CURSPOS rmb 2 | CURSPOS rmb 2 | ||
Line 544: | Line 543: | ||
ldx # | ldx # | ||
ldd # | ldd # | ||
- | std ,x | + | std ,x |
stx CURSPOS | stx CURSPOS | ||
| | ||
ldb [CURSPOS] ; what character is at the cursor position? | ldb [CURSPOS] ; what character is at the cursor position? | ||
rts | rts | ||
- | |||
- | As well as direct extended mode, indirection can be used on PC relative and indexed addressing modes too. But note that because we are always specifying a 16-bit address, auto-increment/ | ||
As well as direct extended mode, indirection can be used on PC relative and indexed addressing modes too. But note that because we are always specifying a 16-bit addresss, auto-increment/ | As well as direct extended mode, indirection can be used on PC relative and indexed addressing modes too. But note that because we are always specifying a 16-bit addresss, auto-increment/ | ||
Line 569: | Line 566: | ||
clr ,-s ; reserve and zero value of longest strng so far | clr ,-s ; reserve and zero value of longest strng so far | ||
loop: | loop: | ||
- | lda [, | + | lda [, |
cmpa ,s ; is A higher than longest? | cmpa ,s ; is A higher than longest? | ||
bls short ; skip if not | bls short ; skip if not | ||
Line 610: | Line 607: | ||
Suppose we have a sprite library that deals with simple movement and animation, and want to expand it to include features such as collision detection, keeping in bounds, and more. To our sprite object we can add a field SPRMETHODS to point to a table of subroutines. Thus every sprite instance can have its own dynamic type specification. | Suppose we have a sprite library that deals with simple movement and animation, and want to expand it to include features such as collision detection, keeping in bounds, and more. To our sprite object we can add a field SPRMETHODS to point to a table of subroutines. Thus every sprite instance can have its own dynamic type specification. | ||
+ | We can create a heirarchical structure where one class inherits its methods from its parent. So for a game we might start with: | ||
+ | |||
+ | Basic: | ||
+ | --Animated: As Basic, but with a framelist displaying animated images\\ | ||
+ | ----Morpher: | ||
+ | |||
+ | ; Structure offsets | ||
+ | | ||
sprStatus EQU 0 | sprStatus EQU 0 | ||
sprMask EQU 1 | sprMask EQU 1 | ||
Line 617: | Line 622: | ||
sprMethods EQU 8 | sprMethods EQU 8 | ||
sprCounter EQU 10 | sprCounter EQU 10 | ||
+ | sprMorphTo EQU 12 | ||
+ | | ||
+ | ; Subroutine library | ||
| | ||
sprInitBasic rts | sprInitBasic rts | ||
Line 624: | Line 632: | ||
sprDoneBasic rts | sprDoneBasic rts | ||
sprDrawAnimated rts | sprDrawAnimated rts | ||
- | | + | |
+ | |||
+ | ; Class definitions: | ||
+ | |||
sprMethodsBasic | sprMethodsBasic | ||
- | sprMethodsAnimated | + | sprMethodsAnimated |
- | | + | |
+ | |||
+ | ; Instance templates | ||
+ | | ||
cloud fdb 0, | cloud fdb 0, | ||
explosion fdb 0, | explosion fdb 0, | ||
- | | + | |
+ | bonusDrop | ||
+ | |||
+ | Note that all the organisational work is down to the programmer; the assembler won't give any help keeping the structures in order. | ||
+ | ==== How do negative numbers work? ==== | ||
+ | Think of an old-fashioned clock face as an analogy with an 8-bit register. An hour has 60 minutes, marked as 0 to 59. The minute hand goes only one way, and when it come round to zero the hour hand advances. | ||
+ | |||
+ | An 8-bit register has 256 values, marked as 0 to 255, and when it overflows round to zero the carry flag is set. | ||
+ | |||
+ | How do negative numbers work on a clock? It's entirely down to how we choose to read them. We can say " | ||
+ | |||
+ | In binary the principle works just the same, only (for an 8-bit value) we subtract from 256 instead of 60, ie. "minus ten" equals " | ||
+ | |||
+ | Which signed numbers are positive and which negative? Highest bit set means negative, so unsigned values 128 to 255 represent -128 to -1. Positive signed values range from 0 to 127. This is called " | ||
+ | |||
+ | This format is chosen because the underlying circuitry doesn' | ||
+ | |||
+ | Which instructions deal with signed numbers? There' | ||
+ | |||
+ | Signed branches | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | Miscellaneous instructions | ||
+ | | ||
+ | NEG (8-bit only) | ||
+ | SEX Sign EXtend B to D | ||
+ | COMA; COMB; ADDD #1 negate D | ||
+ | |||
+ | Note that other than the simple BPL/BMI, the signed variants are not commonly used. If you do choose one, think twice whether you meant the unsigned variant. Signed comparisons should not be used with addresses for example. | ||
+ | |||
+ | |||
- | ==== How do negative numbers work? ==== | ||
==== What do all the instructions do? ==== | ==== What do all the instructions do? ==== | ||
[Will get round to this one] | [Will get round to this one] |
aslfaqs.1758385333.txt.gz · Last modified: 2025/09/20 16:22 by reggie