forked from blondie7575/WeeGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.s
174 lines (150 loc) · 2.74 KB
/
utility.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
;
; utility.s
; General utilities for 6502
;
; Created by Quinn Dunki on 8/15/14.
; Copyright (c) 2014 One Girl, One Laptop Productions. All rights reserved.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; delayShort
; Sleeps for ~1/30th second
;
delayShort:
SAVE_AXY
ldy #$06 ; Loop a bit
delayShortOuter:
ldx #$ff
delayShortInner:
nop
nop
nop
nop
nop
nop
nop
dex
bne delayShortInner
dey
bne delayShortOuter
RESTORE_AXY
rts
.if 0
;;;;;;;;;;;;;;;;;;;;;;;
; scanHexDigit
; Scans a 4 bit hex value from an ASCII character
; A: ASCII character
; Out A: Hex value
;
scanHexDigit:
cmp #'a'
bcs scanHexDigitLowCase
cmp #'A'
bcs scanHexDigitLetter
sec
sbc #'0'
jmp scanHexDigitDone
scanHexDigitLowCase:
sec
sbc #32
scanHexDigitLetter:
sec
sbc #55
scanHexDigitDone:
rts
;;;;;;;;;;;;;;;;;;;;;;;
; scanHex8
; Scans an 8 bit hex value from a string
; PARAM0: Pointer to string (LSB)
; PARAM1: Pointer to string (MSB)
; Y: Offset into string
; Out A: 8-bit hex value
; Y: One past what we scanned
; Side effects: Clobbers S0
;
scanHex8:
lda (PARAM0),y
jsr scanHexDigit
asl
asl
asl
asl
sta SCRATCH0 ; Stash first digit for later
iny
lda (PARAM0),y
jsr scanHexDigit
ora SCRATCH0
iny ; Be nice and advance Y to end
rts
.endif
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGStrLen
; Finds the length of a null-terminated string
; PARAM0: String pointer, LSB
; PARAM1: String pointer, MSB
; Return: A: String length, not including null
;
WGStrLen:
phy
ldy #0
WGStrLen_loop:
lda (PARAM0),y
beq WGStrLen_done
iny
bra WGStrLen_loop
WGStrLen_done:
tya
ply
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGStoreStr
; Finds room in our block allocator and copies the given string.
; A: Terminator character
; PARAM0: String pointer, LSB
; PARAM1: String pointer, MSB
; Return: PARAM0: Stored string, LSB
; PARAM1: Stored string, MSB
; Side Effects: Clobbers SA
;
WGStoreStr:
sta WG_SCRATCHA
SAVE_AXY
ldx #0
ldy #0
WGStoreStr_findEmptyLoop:
lda WG_STRINGS,x
beq WGStoreStr_copy
txa
clc
adc #16 ; String blocks are 16 bytes wide
bcs WGStoreStr_noRoom
tax
bra WGStoreStr_findEmptyLoop
WGStoreStr_noRoom:
lda #0
sta PARAM0
sta PARAM1
bra WGStoreStr_done
WGStoreStr_copy:
phx ; Remember the start of our string
WGStoreStr_copyLoop:
lda (PARAM0),y
cmp WG_SCRATCHA
beq WGStoreStr_terminate
sta WG_STRINGS,x
inx
iny
cpy #15 ; Clip string to maximum block size
bne WGStoreStr_copyLoop
WGStoreStr_terminate:
lda #0 ; Terminate the stored string
sta WG_STRINGS,x
pla ; Return pointer to the start of the block
clc
adc #<WG_STRINGS
sta PARAM0
lda #0
adc #>WG_STRINGS
sta PARAM1
WGStoreStr_done:
RESTORE_AXY
rts