Indexed indirect. For a relaxing demo.
Cat's Eye Technologies
8 years ago
0 | |
assign byte table screen 1024
|
|
0 |
assign byte table screen $0400
|
1 | 1 |
assign byte table screen2 1274
|
2 | 2 |
assign byte table screen3 1524
|
3 | 3 |
assign byte table screen4 1774
|
|
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
|
|
20 |
|
|
21 |
reserve byte value
|
|
22 |
|
|
23 |
reserve byte m_hi
|
|
24 |
reserve byte m_lo
|
|
25 |
reserve byte n_hi
|
|
26 |
reserve byte n_lo
|
|
27 |
|
16 | 28 |
routine main {
|
17 | 29 |
lda #5
|
18 | 30 |
sta vic_border
|
19 | 31 |
lda #0
|
20 | 32 |
sta vic_bg
|
|
33 |
jsr reset_pos
|
21 | 34 |
jsr clear_screen
|
22 | 35 |
sei {
|
23 | 36 |
copy vector cinv to save_cinv
|
|
27 | 40 |
repeat bcc { }
|
28 | 41 |
}
|
29 | 42 |
|
|
43 |
routine reset_pos {
|
|
44 |
lda #$00
|
|
45 |
sta pos_lo
|
|
46 |
lda #$04
|
|
47 |
sta pos_hi
|
|
48 |
}
|
|
49 |
|
30 | 50 |
routine our_cinv {
|
31 | |
inc screen
|
|
51 |
lda value
|
|
52 |
inc value
|
|
53 |
ldy #0
|
|
54 |
sta (pos_lo), y
|
|
55 |
jsr increment_pos
|
|
56 |
jsr compare_pos
|
|
57 |
if beq {
|
|
58 |
jsr reset_pos
|
|
59 |
} else {
|
|
60 |
}
|
32 | 61 |
jmp save_cinv
|
|
62 |
}
|
|
63 |
|
|
64 |
routine increment_pos {
|
|
65 |
clc
|
|
66 |
lda pos_lo
|
|
67 |
adc #1
|
|
68 |
sta pos_lo
|
|
69 |
lda pos_hi
|
|
70 |
adc #0
|
|
71 |
sta pos_hi
|
|
72 |
}
|
|
73 |
|
|
74 |
routine compare_pos {
|
|
75 |
lda pos_lo
|
|
76 |
sta m_lo
|
|
77 |
lda pos_hi
|
|
78 |
sta m_hi
|
|
79 |
lda #$07
|
|
80 |
sta n_hi
|
|
81 |
lda #$e8
|
|
82 |
sta n_lo
|
|
83 |
jsr compare_16_bit
|
|
84 |
}
|
|
85 |
|
|
86 |
routine compare_16_bit {
|
|
87 |
lda m_hi
|
|
88 |
cmp n_hi
|
|
89 |
if beq {
|
|
90 |
lda m_lo
|
|
91 |
cmp n_lo
|
|
92 |
} else {
|
|
93 |
}
|
33 | 94 |
}
|
34 | 95 |
|
35 | 96 |
routine clear_screen {
|
58 | 58 |
|
59 | 59 |
emitInstr p r (COPYINDEXED (NamedLocation label) A X) = "lda " ++ label ++ ", x"
|
60 | 60 |
emitInstr p r (COPYINDEXED (NamedLocation label) A Y) = "lda " ++ label ++ ", y"
|
|
61 |
|
|
62 |
emitInstr p r (COPYINDIRECTINDEXED A (NamedLocation label) Y) = "sta (" ++ label ++ "), y"
|
61 | 63 |
|
62 | 64 |
emitInstr p r (CMP A (NamedLocation label)) = "cmp " ++ label
|
63 | 65 |
emitInstr p r (CMP X (NamedLocation label)) = "cpx " ++ label
|
56 | 56 |
data Instruction = PUT StorageLocation DataValue
|
57 | 57 |
| COPY StorageLocation StorageLocation
|
58 | 58 |
| COPYINDEXED StorageLocation StorageLocation StorageLocation
|
|
59 |
| COPYINDIRECTINDEXED StorageLocation StorageLocation StorageLocation
|
59 | 60 |
| CMPIMM StorageLocation DataValue
|
60 | 61 |
| CMP StorageLocation StorageLocation
|
61 | 62 |
| ADDIMM StorageLocation DataValue
|
9 | 9 |
|
10 | 10 |
{-
|
11 | 11 |
|
12 | |
Toplevel := {Decl} {Routine}.
|
|
12 |
Toplevel := {Decl [Comment]} {Routine}.
|
13 | 13 |
Decl := "reserve" StorageType LocationName
|
14 | 14 |
| "assign" StorageType LocationName Address
|
15 | 15 |
| "external" RoutineName Address.
|
|
36 | 36 |
|
37 | 37 |
toplevel :: Parser Program
|
38 | 38 |
toplevel = do
|
39 | |
decls <- many (try assign <|> try reserve <|> try external)
|
|
39 |
decls <- many decl
|
40 | 40 |
routines <- many routine
|
41 | 41 |
return $ Program decls routines
|
|
42 |
|
|
43 |
decl :: Parser Decl
|
|
44 |
decl = do
|
|
45 |
d <- (try assign <|> try reserve <|> try external)
|
|
46 |
optional comment
|
|
47 |
return d
|
42 | 48 |
|
43 | 49 |
reserve :: Parser Decl
|
44 | 50 |
reserve = do
|
|
124 | 130 |
return $ case c of
|
125 | 131 |
"x" -> X
|
126 | 132 |
"y" -> Y
|
|
133 |
|
|
134 |
data Directness = Direct LocationName
|
|
135 |
| Indirect LocationName
|
|
136 |
deriving (Ord, Show, Eq)
|
|
137 |
|
|
138 |
indirect_location :: Parser Directness
|
|
139 |
indirect_location = do
|
|
140 |
string "("
|
|
141 |
spaces
|
|
142 |
l <- locationName
|
|
143 |
string ")"
|
|
144 |
spaces
|
|
145 |
return $ Indirect l
|
|
146 |
|
|
147 |
direct_location :: Parser Directness
|
|
148 |
direct_location = do
|
|
149 |
l <- locationName
|
|
150 |
return $ Direct l
|
|
151 |
|
|
152 |
directness_location = (try indirect_location) <|> direct_location
|
|
153 |
|
|
154 |
indirect_indexed :: (Directness -> [StorageLocation] -> Instruction) -> Parser Instruction
|
|
155 |
indirect_indexed f = do
|
|
156 |
d <- directness_location
|
|
157 |
indexes <- many index
|
|
158 |
return $ f d indexes
|
127 | 159 |
|
128 | 160 |
absolute_indexed :: (LocationName -> [StorageLocation] -> Instruction) -> Parser Instruction
|
129 | 161 |
absolute_indexed f = do
|
|
304 | 336 |
sta = do
|
305 | 337 |
string "sta"
|
306 | 338 |
spaces
|
307 | |
absolute_indexed gen
|
|
339 |
indirect_indexed gen
|
308 | 340 |
where
|
309 | |
gen l [] = COPY A (NamedLocation l)
|
310 | |
gen l [reg] = COPYINDEXED A (NamedLocation l) reg
|
|
341 |
gen (Direct l) [] = COPY A (NamedLocation l)
|
|
342 |
gen (Direct l) [reg] = COPYINDEXED A (NamedLocation l) reg
|
|
343 |
gen (Indirect l) [reg] = COPYINDIRECTINDEXED A (NamedLocation l) reg
|
311 | 344 |
|
312 | 345 |
stx :: Parser Instruction
|
313 | 346 |
stx = do
|