-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrts-jumptable.asm
106 lines (93 loc) · 1.49 KB
/
rts-jumptable.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
100
101
102
103
104
105
106
*=$0801
!word $080C ; Pointer to next BASIC line
!word $000A ; Line number $000A = 10
!byte $9E ; SYS BASIC token
!pet " $810",0 ; Address where ASM starts
!word $0000 ; EOF BASIC program
*=$0810
CHROUT = $FFD2
main_func:!byte $ff
lda #>@ret1-1 ; Push return address onto stack
pha ; Otherwise the function that is called
lda #<@ret1-1 ; via the jumptable will not be able to
pha ; use rts to return.
ldx #2 ; Load index into jump table
inx
lda Jump_table,x ; Push function address to stack
pha ; remembering that cpu is little-endian
dex
lda Jump_table,x
pha
rts ; Jump to function
@ret1: lda #>@ret2-1
pha
lda #<@ret2-1
pha
ldx #4
inx
lda Jump_table,x
pha
dex
lda Jump_table,x
pha
rts
@ret2: lda #>@ret3-1
pha
lda #<@ret3-1
pha
ldx #0
inx
lda Jump_table,x
pha
dex
lda Jump_table,x
pha
rts
@ret3: lda #>@ret4-1
pha
lda #<@ret4-1
pha
ldx #6
inx
lda Jump_table,x
pha
dex
lda Jump_table,x
pha
rts
@ret4: rts
; Write 1 and a new line on screen
func1:
lda #$31
jsr CHROUT
lda #13
jsr CHROUT
rts
; Write 2 and a new line on screen
func2:
lda #$32
jsr CHROUT
lda #13
jsr CHROUT
rts
; Write 3 and a new line on screen
func3:
lda #$33
jsr CHROUT
lda #13
jsr CHROUT
rts
; Write 4 and a new line on screen
func4:
lda #$34
jsr CHROUT
lda #13
jsr CHROUT
rts
; The jumptable needs to contain the function address - 1 in order
; to be able to use rts to jump to the function
Jump_table:
!word func1-1
!word func2-1
!word func3-1
!word func4-1