-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnv_state_saver_macs.asm
102 lines (83 loc) · 3.03 KB
/
nv_state_saver_macs.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//////////////////////////////////////////////////////////////////////////////
// nv_state_saver_macs.asm
// Copyright(c) 2021 Neal Smith.
// License: MIT. See LICENSE file in root directory.
//////////////////////////////////////////////////////////////////////////////
// some macros to save and restore state
//////////////////////////////////////////////////////////////////////////////
#importonce
#if !NV_C64_UTIL_DATA
.error "Error - nv_math8_macs.asm: NV_C64_UTIL_DATA not defined. Import nv_c64_util_data.asm"
#endif
// the #if above doesn't seem to always work so..
// if data hasn't been imported yet, import it into default location
#importif !NV_C64_UTIL_DATA "nv_c64_util_default_data.asm"
//////////////////////////////////////////////////////////////////////////////
// inline macro to the values in two memory locations on the stack
// macro params:
// one: a memory location that's value will be saved on the stack
// two: a memory location that's value will be saved on the stack
// To restore the memory locations their values saved, use the macro
// restore_two(one, two)
// with params in same order as this macro
.macro save_two(one, two)
{
lda one
pha
lda two
pha
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to the values in four memory locations on the stack
// macro params:
// one: a memory location that's value will be saved on the stack
// two: a memory location that's value will be saved on the stack
// three: a memory location that's value will be saved on the stack
// four: a memory location that's value will be saved on the stack
// To restore the memory locations their values saved, use the macro
// restore_four(one, two, three, four)
// with params in same order as this macro
.macro save_four(one, two, three, four)
{
lda one
pha
lda two
pha
lda three
pha
lda four
pha
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to restore values in two memory locations from the stack.
// the memory locations must have been saved with save_two(one, two)
// macro params:
// one: a memory location that's value will be restored from the stack
// two: a memory location that's value will be restored from the stack
.macro restore_two(one, two)
{
pla
sta two
pla
sta one
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to restore values in four memory locations from the stack.
// the memory locations must have been saved with
// save_four(one, two, three, four)
// macro params:
// one: a memory location that's value will be restored from the stack
// two: a memory location that's value will be restored from the stack
// three: a memory location that's value will be restored from the stack
// four: a memory location that's value will be restored from the stack
.macro restore_four(one, two, three, four)
{
pla
sta four
pla
sta three
pla
sta two
pla
sta one
}