Use words in demo.
Cat's Eye Technologies
8 years ago
13 | 13 |
assign vector cinv 788
|
14 | 14 |
reserve vector save_cinv
|
15 | 15 |
|
16 | |
; TODO: this should be a word
|
17 | |
|
18 | |
assign byte pos_lo $fb
|
19 | |
assign byte pos_hi $fc
|
|
16 |
assign word position $fb
|
20 | 17 |
|
21 | 18 |
reserve byte value
|
22 | 19 |
|
23 | |
reserve byte m_hi
|
24 | |
reserve byte m_lo
|
25 | |
reserve byte n_hi
|
26 | |
reserve byte n_lo
|
|
20 |
reserve word m
|
|
21 |
reserve word n
|
27 | 22 |
|
28 | 23 |
routine main {
|
29 | 24 |
lda #5
|
30 | 25 |
sta vic_border
|
31 | 26 |
lda #0
|
32 | 27 |
sta vic_bg
|
33 | |
jsr reset_pos
|
|
28 |
jsr reset_position
|
34 | 29 |
jsr clear_screen
|
35 | 30 |
sei {
|
36 | 31 |
copy vector cinv to save_cinv
|
|
40 | 35 |
repeat bcc { }
|
41 | 36 |
}
|
42 | 37 |
|
43 | |
routine reset_pos {
|
|
38 |
routine reset_position {
|
44 | 39 |
lda #$00
|
45 | |
sta pos_lo
|
|
40 |
sta <position
|
46 | 41 |
lda #$04
|
47 | |
sta pos_hi
|
|
42 |
sta >position
|
48 | 43 |
}
|
49 | 44 |
|
50 | 45 |
routine our_cinv {
|
51 | 46 |
lda value
|
52 | 47 |
inc value
|
53 | 48 |
ldy #0
|
54 | |
sta (pos_lo), y
|
|
49 |
sta (position), y
|
55 | 50 |
jsr increment_pos
|
56 | 51 |
jsr compare_pos
|
57 | 52 |
if beq {
|
58 | |
jsr reset_pos
|
|
53 |
jsr reset_position
|
59 | 54 |
} else {
|
60 | 55 |
}
|
61 | 56 |
jmp save_cinv
|
|
63 | 58 |
|
64 | 59 |
routine increment_pos {
|
65 | 60 |
clc
|
66 | |
lda pos_lo
|
|
61 |
lda <position
|
67 | 62 |
adc #1
|
68 | |
sta pos_lo
|
69 | |
lda pos_hi
|
|
63 |
sta <position
|
|
64 |
lda >position
|
70 | 65 |
adc #0
|
71 | |
sta pos_hi
|
|
66 |
sta >position
|
72 | 67 |
}
|
73 | 68 |
|
74 | 69 |
routine compare_pos {
|
75 | |
lda pos_lo
|
76 | |
sta m_lo
|
77 | |
lda pos_hi
|
78 | |
sta m_hi
|
|
70 |
lda <position
|
|
71 |
sta <m
|
|
72 |
lda >position
|
|
73 |
sta >m
|
79 | 74 |
lda #$07
|
80 | |
sta n_hi
|
|
75 |
sta >n
|
81 | 76 |
lda #$e8
|
82 | |
sta n_lo
|
|
77 |
sta <n
|
83 | 78 |
jsr compare_16_bit
|
84 | 79 |
}
|
85 | 80 |
|
86 | 81 |
routine compare_16_bit {
|
87 | |
lda m_hi
|
88 | |
cmp n_hi
|
|
82 |
lda >m
|
|
83 |
cmp >n
|
89 | 84 |
if beq {
|
90 | |
lda m_lo
|
91 | |
cmp n_lo
|
|
85 |
lda <m
|
|
86 |
cmp <n
|
92 | 87 |
} else {
|
93 | 88 |
}
|
94 | 89 |
}
|
51 | 51 |
emitInstr p r (COPY (LowByteOf (NamedLocation st label)) A) = "lda " ++ label
|
52 | 52 |
emitInstr p r (COPY (HighByteOf (NamedLocation st label)) A) = "lda " ++ label ++ "+1"
|
53 | 53 |
|
|
54 |
emitInstr p r (COPY A (LowByteOf (NamedLocation st label))) = "sta " ++ label
|
|
55 |
emitInstr p r (COPY A (HighByteOf (NamedLocation st label))) = "sta " ++ label ++ "+1"
|
|
56 |
|
54 | 57 |
emitInstr p r (COPY A X) = "tax"
|
55 | 58 |
emitInstr p r (COPY A Y) = "tay"
|
56 | 59 |
emitInstr p r (COPY X A) = "txa"
|
|
72 | 75 |
emitInstr p r (CMP A (Immediate val)) = "cmp #" ++ (show val)
|
73 | 76 |
emitInstr p r (CMP X (Immediate val)) = "cpx #" ++ (show val)
|
74 | 77 |
emitInstr p r (CMP Y (Immediate val)) = "cpy #" ++ (show val)
|
|
78 |
|
|
79 |
emitInstr p r (CMP A (LowByteOf (NamedLocation st label))) = "cmp " ++ label
|
|
80 |
emitInstr p r (CMP A (HighByteOf (NamedLocation st label))) = "cmp " ++ label ++ "+1"
|
75 | 81 |
|
76 | 82 |
emitInstr p r (ADD A (NamedLocation st label)) = "adc " ++ label
|
77 | 83 |
emitInstr p r (ADD A (Immediate val)) = "adc #" ++ (show val)
|
271 | 271 |
addressing_mode gen
|
272 | 272 |
where
|
273 | 273 |
gen (Immediately v) [] = CMP A (Immediate v)
|
|
274 |
gen (LowBytely l) [] = CMP A (LowByteOf (NamedLocation Nothing l))
|
|
275 |
gen (HighBytely l) [] = CMP A (HighByteOf (NamedLocation Nothing l))
|
274 | 276 |
gen (Directly l) [] = CMP A (NamedLocation Nothing l)
|
275 | 277 |
|
276 | 278 |
cpx :: Parser Instruction
|
|
364 | 366 |
spaces
|
365 | 367 |
addressing_mode gen
|
366 | 368 |
where
|
|
369 |
gen (LowBytely l) [] = COPY A (LowByteOf (NamedLocation Nothing l))
|
|
370 |
gen (HighBytely l) [] = COPY A (HighByteOf (NamedLocation Nothing l))
|
367 | 371 |
gen (Directly l) [] = COPY A (NamedLocation Nothing l)
|
368 | 372 |
gen (Directly l) [reg] = COPY A (Indexed (NamedLocation Nothing l) reg)
|
369 | 373 |
gen (Indirectly l) [reg] = COPY A (IndirectIndexed (NamedLocation Nothing l) reg)
|