-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory_macros.s
110 lines (89 loc) · 1.83 KB
/
memory_macros.s
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
100
101
102
103
104
105
106
107
108
109
!set const_memory_frm0 = $E0
!set const_memory_frm1 = $E2
!set const_memory_frm2 = $E4
!set const_memory_frm3 = $E6
!set const_memory_frm4 = $E8
!set const_memory_frm5 = $EA
!set const_memory_frm6 = $EC
!set const_memory_frm7 = $EE
!set const_memory_idx0 = $F0
!set const_memory_idx1 = $F2
!set const_memory_idx2 = $F4
!set const_memory_idx3 = $F6
!set const_memory_idx4 = $F8
!set const_memory_idx5 = $FA
!set const_memory_idx6 = $FC
!set const_memory_idx7 = $FE
!set const_parameter_ptr = const_memory_frm0
!set const_stack_frame_ptr = const_memory_frm1
!macro save_8bitZP .zpIndex {
lda .zpIndex
pha
}
!macro restore_8bitZP .zpIndex {
pla
sta .zpIndex
}
!macro save_16bitZP .zpIndex {
lda .zpIndex
pha
lda .zpIndex + 1
pha
}
!macro restore_16bitZP .zpIndex {
pla
sta .zpIndex + 1
pla
sta .zpIndex
}
!macro copy_16bitZP_Mem .zpIndex, .address {
lda+2 .address
sta .zpIndex
lda+2 .address + 1
sta .zpIndex + 1
}
;-4 old_param_low
;-3 old_param_high
;-2 old_stack_low
;-1 old_stack_high
; 0 old_x
;+1 <= const_stack_frame_ptr (points to this memory location)
!macro enter_stack_frame_with_bytes .frame_bytes {
+save_16bitZP const_parameter_ptr
+save_16bitZP const_stack_frame_ptr
phx
tsx
stx const_stack_frame_ptr
lda #$01
sta const_stack_frame_ptr + 1
; create space for local variables
txa
adc #.frame_bytes
tax
txs
}
!macro enter_stack_frame {
+save_16bitZP const_parameter_ptr
+save_16bitZP const_stack_frame_ptr
phx
tsx
stx const_stack_frame_ptr
lda #$01
sta const_stack_frame_ptr + 1
}
!macro restore_stack_frame_with_bytes .frame_bytes {
; clear local variables
tsx
txa
sbc #.frame_bytes
tax
txs
plx
+restore_16bitZP const_stack_frame_ptr
+restore_16bitZP const_parameter_ptr
}
!macro restore_stack_frame .frame_bytes {
plx
+restore_16bitZP const_stack_frame_ptr
+restore_16bitZP const_parameter_ptr
}