-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconvert.p8
59 lines (55 loc) · 1.21 KB
/
convert.p8
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
;
; Code to extract upper and lower 4 bit nibbles from ubyte and convert
; to correct PETSCII character based on nibble.
;
convert {
%option force_output
ubyte[] table = [ $20, $7E, $7C, $E2, $7B, $61, $FF, $EC,
$6C, $7F, $E1, $FB, $62, $FC, $FE, $A0 ]
; sub get_high_old(ubyte data) -> ubyte {
; return table[ (data & 240) >> 4 ]
; }
inline asmsub get_high(ubyte value @A) clobbers(Y) -> ubyte @A {
%asm {{
and #$F0
lsr a
lsr a
lsr a
lsr a
tay
lda p8b_convert.p8v_table,y
}}
}
; sub get_low_old(ubyte data) -> ubyte {
; return table[ data & 15 ]
; }
inline asmsub get_low(ubyte value @A) clobbers(Y) -> ubyte @A {
%asm {{
and #$0F
tay
lda p8b_convert.p8v_table,y
}}
}
; sub to_nibble_old(ubyte cnv) -> ubyte {
; ubyte i = 0
; while i < 7 {
; if table[i] == cnv
; return i
; i++
; }
; return 7
; }
asmsub to_nibble(ubyte cnv @A) -> ubyte @A {
%asm {{
ldy #6
- cmp p8v_table,y
beq +
dey
bpl -
lda #7
rts
+ tya
rts
}}
}
}