-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.s
138 lines (128 loc) · 2.69 KB
/
message.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
.include "global.inc"
.export push_msg
.export update_message_str
.export has_amount
.segment "ZEROPAGE"
max_messages = 3
message_strlen = 18
messages: .res .sizeof(Message)*max_messages
tmp_message: .res .sizeof(Message)
.segment "CODE"
; clobbers: x
.proc clear_messages
ldx #0
clear_messages:
lda #Messages::none
sta messages, x
txa
clc
adc #.sizeof(Message)
tax
cmp #.sizeof(Message) * max_messages
bne clear_messages
rts
.endproc
; Use messages as a message stack & push the message.
;
; in: type
; x: amount
; clobbers: all registers
.proc push_msg
sta tmp_message
txa
sta tmp_message+Message::amount
; initialize x to end of message list - 1
ldx #.sizeof(Message)*max_messages - .sizeof(Message)*2
shift_messages:
; store current message at messages+message_size
txa
clc
adc #.sizeof(Message)
tay
lda messages, x
sta messages, y
lda messages+Message::amount, x
sta messages+Message::amount, y
txa
sec
sbc #.sizeof(Message)
tax
bcs shift_messages
; done shifting, now store first message
lda tmp_message
sta messages
lda tmp_message+Message::amount
sta messages+Message::amount
rts
.endproc
.proc update_message_str
; update the str_pointer to point to the correct message
; uses index in x for message
lda messages+Message::type, x
cmp #Messages::none
beq load_blank
cmp #Messages::hit
beq load_hit
cmp #Messages::hurt
beq load_hurt
cmp #Messages::kill
beq load_kill
cmp #Messages::levelup
beq load_levelup
load_blank:
; default condition
lda #<txt_blank
sta str_pointer
lda #>txt_blank
sta str_pointer+1
rts
load_hit:
lda #<txt_hit
sta str_pointer
lda #>txt_hit
sta str_pointer+1
rts
load_hurt:
lda #<txt_hurt
sta str_pointer
lda #>txt_hurt
sta str_pointer+1
rts
load_kill:
lda #<txt_kill
sta str_pointer
lda #>txt_kill
sta str_pointer+1
rts
load_levelup:
lda #<txt_lvlup
sta str_pointer
lda #>txt_lvlup
sta str_pointer+1
rts
.endproc
; out: 0 if type uses amount at end of str
.proc has_amount
lda messages+Message::type, x
cmp #Messages::hit
beq success
cmp #Messages::hurt
beq success
cmp #Messages::heal
beq success
; default condition
lda #1
rts
success:
lda #0
rts
.endproc
.segment "RODATA"
txt_blank: .asciiz " "
txt_hit: .asciiz "You hit it for "
txt_hurt: .asciiz "You got hit for "
txt_kill: .asciiz "It died!"
txt_heal: .asciiz "You healed for "
txt_scroll: .asciiz "You read the scroll"
txt_quaff: .asciiz "*gulp*" ; todo need asterisk
txt_lvlup: .asciiz "You leveled up!"