-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsmult8.a
More file actions
66 lines (59 loc) · 1.22 KB
/
Copy pathsmult8.a
File metadata and controls
66 lines (59 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
; smult8.a
; from mult65 (Nick Jameson's 3D Demo for the BBC Micro (1994), https://github.com/simondotm/bbc-micro-3d/blob/master/source/culling.asm)
; adjusted by TobyLobster for signed multiply
;
; 8 bit x 8 bit signed multiplication, 16 bit result
; Average cycles: 62.99
; 1068 bytes
* = $0200
multiplicand = $02 ; 1 byte
multiplier = $03 ; 1 byte
result = $04 ; 2 bytes
lmul0 = $06 ; pointer into square table low
lmul1 = $08 ; pointer into square table high
prod_low = $0a
; Align tables to start of page
squaretable1_lsb
!for i, 0, 511 {
!byte <((i*i)/4)
}
squaretable1_msb
!for i, 0, 511 {
!byte >((i*i)/4)
}
; 8 bit x 8bit signed multiply, 16 bit result
;
; On Entry:
; X: multiplier
; Y: multiplicand
; On Exit:
; (prod_low, A): product
mult
stx lmul0
stx lmul1
tya
sec
sbc lmul0
bcs +
sbc #0 ; negate A
eor #$ff
+
tax
lda (lmul0),Y
sbc squaretable1_lsb,X
sta prod_low
lda (lmul1),Y
sbc squaretable1_msb,X
; Step 2: apply sign (See C=Hacking16 for details).
cpy #$80
bcc +
sbc lmul0
+
bit lmul0
bpl +
sty temp
sec
temp = * + 1
sbc #0
+
rts