git @ Cat's Eye Technologies SixtyPical / 061a166
Indexed indirect. For a relaxing demo. Cat's Eye Technologies 8 years ago
5 changed file(s) with 117 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
309309 | ldy #1
310310 | lda #1 ; we
311311 | ldx #1 ; found under the bridge by the old mill yesterday
312 | }
313 = True
314
315 A comment may appear after each declaration.
316
317 | reserve byte lives ; fnord
318 | assign byte gdcol 647 ; fnord
319 | external blastoff 4 ; fnnnnnnnnnnnnnnnnfffffffff
320 |
321 | routine main {
322 | nop
312323 | }
313324 = True
314325
485496 | sta screen
486497 | sta screen, x
487498 | sta screen, y
499 | sta (screen), y
488500 | dec screen
489501 | clc
490502 | cld
529541 = sta screen
530542 = sta screen, x
531543 = sta screen, y
544 = sta (screen), y
532545 = dec screen
533546 = clc
534547 = cld
0 assign byte table screen 1024
0 assign byte table screen $0400
11 assign byte table screen2 1274
22 assign byte table screen3 1524
33 assign byte table screen4 1774
1313 assign vector cinv 788
1414 reserve vector save_cinv
1515
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
1628 routine main {
1729 lda #5
1830 sta vic_border
1931 lda #0
2032 sta vic_bg
33 jsr reset_pos
2134 jsr clear_screen
2235 sei {
2336 copy vector cinv to save_cinv
2740 repeat bcc { }
2841 }
2942
43 routine reset_pos {
44 lda #$00
45 sta pos_lo
46 lda #$04
47 sta pos_hi
48 }
49
3050 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 }
3261 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 }
3394 }
3495
3596 routine clear_screen {
5858
5959 emitInstr p r (COPYINDEXED (NamedLocation label) A X) = "lda " ++ label ++ ", x"
6060 emitInstr p r (COPYINDEXED (NamedLocation label) A Y) = "lda " ++ label ++ ", y"
61
62 emitInstr p r (COPYINDIRECTINDEXED A (NamedLocation label) Y) = "sta (" ++ label ++ "), y"
6163
6264 emitInstr p r (CMP A (NamedLocation label)) = "cmp " ++ label
6365 emitInstr p r (CMP X (NamedLocation label)) = "cpx " ++ label
5656 data Instruction = PUT StorageLocation DataValue
5757 | COPY StorageLocation StorageLocation
5858 | COPYINDEXED StorageLocation StorageLocation StorageLocation
59 | COPYINDIRECTINDEXED StorageLocation StorageLocation StorageLocation
5960 | CMPIMM StorageLocation DataValue
6061 | CMP StorageLocation StorageLocation
6162 | ADDIMM StorageLocation DataValue
99
1010 {-
1111
12 Toplevel := {Decl} {Routine}.
12 Toplevel := {Decl [Comment]} {Routine}.
1313 Decl := "reserve" StorageType LocationName
1414 | "assign" StorageType LocationName Address
1515 | "external" RoutineName Address.
3636
3737 toplevel :: Parser Program
3838 toplevel = do
39 decls <- many (try assign <|> try reserve <|> try external)
39 decls <- many decl
4040 routines <- many routine
4141 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
4248
4349 reserve :: Parser Decl
4450 reserve = do
124130 return $ case c of
125131 "x" -> X
126132 "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
127159
128160 absolute_indexed :: (LocationName -> [StorageLocation] -> Instruction) -> Parser Instruction
129161 absolute_indexed f = do
304336 sta = do
305337 string "sta"
306338 spaces
307 absolute_indexed gen
339 indirect_indexed gen
308340 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
311344
312345 stx :: Parser Instruction
313346 stx = do