forked from jeff-1amstudios/c64-smooth-scrolling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacros.asm
69 lines (60 loc) · 2.23 KB
/
macros.asm
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
; Constants
SYSTEM_IRQ_VECTOR = $314
!macro set16im .value, .dest { ; store a 16bit constant to a memory location
lda #<.value
sta .dest
lda #>.value
sta .dest+1
}
!macro set16 .value, .dest { ; copy a 16bit memory location to dest
lda .value
sta .dest
lda .value+1
sta .dest+1
}
!macro add16im .n1, .n2, .result { ; add a 16bit constant to a memory location, store in result
clc ; ensure carry is clear
lda .n1+0 ; add the two least significant bytes
adc #<.n2
sta .result+0
lda .n1+1 ; add the two most significant bytes
adc #>.n2
sta .result+1
}
!macro add16 .n1, .n2, .result { ; add 2 16bit memory locations, store in result
clc
lda .n1
adc .n2
sta .result+0
lda .n1+1
adc .n2+1
sta .result+1
}
!macro set_raster_interrupt .line, .handler {
sei ; disable interrupts
lda #.line
sta $d012 ; this is the raster line register
+set16im .handler, SYSTEM_IRQ_VECTOR ; set system IRQ vector to our handler
cli ; enable interrupts
}
!macro disable_x_scroll { ; set horizontal softscroll value to 0
lda $d016
and #$F8
sta $d016
}
!macro update_x_scroll .xvalue { ; set horizontal softscroll value to xvalue
lda $d016
and #$F8
clc
adc .xvalue
sta $d016
}
!macro debug_print .value, .column { ; put a char in the bottom line of the screen
lda .value
clc
adc #$30
sta $0400+40*24+.column
sta $0800+40*24+.column
lda #1
sta $d800+40*24+.column
}