summaryrefslogtreecommitdiffstats
path: root/hacks/images/m6502/keftal.asm
blob: efb298295052ff9e70b73a50232d29d62655b2e2 (plain) (blame)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
; awfully slow.. be patient

init:
  ldx #0
  stx $0
  inx
  stx $2
  stx $3
  inx
  stx $1

loop:
  lda $2
  cmp #$20
  bne notIncF2
  inc $3
  lda #0
  sta $2
notIncF2:
  inc $2

; CALCULATE START

  lda $2
  sta $f1
  lda $2
  sta $f2
  jsr multiply

  lda $f4
  sta $f8

  lda $3
  sta $f1
  lda $3
  sta $f2
  jsr multiply

; CALCULATE STOP

  lda $f4
  clc
  adc $f8

  lsr
  lsr
  lsr
  lsr
  lsr
  ldx #0
  sta ($0,x)
  inc $0
  lda $0
  cmp #$00
  bne notNextY
  inc $1
  lda $1
  cmp #6
  beq exit
notNextY:
  jmp loop
exit:
  rts

multiply:
  lda #0
  sta $f4
  sta $f5
  ldx #8
a:asl $f4
  rol $f5
  asl $f2
  bcc b
  clc
  lda $f4
  adc $f1
  sta $f4
  bcc b
  inc $f5
b:dex
  bne a
  rts