git @ Cat's Eye Technologies SixtyPical / 571b3d4
Fix jmp (vector) syntax. Filename extension is `.60p`. --HG-- rename : eg/cinv.60pical => eg/cinv.60p rename : eg/demo.60pical => eg/demo.60p rename : eg/hi.60pical => eg/hi.60p rename : eg/screen.60pical => eg/screen1.60p rename : eg/screen2.60pical => eg/screen2.60p rename : eg/screen3.60pical => eg/screen3.60p Cat's Eye Technologies 8 years ago
21 changed file(s) with 185 addition(s) and 367 deletion(s). Raw diff Collapse all Expand all
179179 * Character tables ("strings" to everybody else)
180180 * Work out the analyses again and document them
181181 * Addressing modes; rename instructions to match
182 * fix jmp (vector) syntax
182 * `jsr (vector)`
183 * `jmp routine`
184 * insist on EOL after each instruction. need spacesWOEOL production
141141 | }
142142 ? duplicate routine name
143143
144 We can jump to a vector.
144 We can jump indirectly through a vector.
145145
146146 | reserve vector blah
147147 | routine main {
148 | jmp blah
149 | }
150 = True
151
152 We can't jump to a word.
148 | jmp (blah)
149 | }
150 = True
151
152 We can't jump indirectly through a word.
153153
154154 | reserve word blah
155155 | routine main {
156 | jmp blah
156 | jmp (blah)
157157 | }
158158 ? jmp to non-vector
159159
160 We can't jump to a byte.
160 We can't jump indirectly through a byte.
161161
162162 | assign byte screen 1024
163163 | routine main {
164 | jmp screen
164 | jmp (screen)
165165 | }
166166 ? jmp to non-vector
167167
110110 |
111111 | routine our_cinv {
112112 | inc screen
113 | jmp save_cinv
113 | jmp (save_cinv)
114114 | }
115115 = main:
116116 = sei
+0
-4
eg/char_actor_demo.60p less more
0 assign byte table screen 1024
1
2 assign byte table actor_x 49152
3 assign byte table actor_x 49152
0 assign byte screen 1024
1 assign vector cinv 788
2 reserve vector save_cinv
3
4 routine main {
5 sei {
6 copy vector cinv to save_cinv
7 copy routine our_cinv to cinv
8 }
9 }
10
11 routine our_cinv {
12 inc screen
13 jmp (save_cinv)
14 }
+0
-15
eg/cinv.60pical less more
0 assign byte screen 1024
1 assign vector cinv 788
2 reserve vector save_cinv
3
4 routine main {
5 sei {
6 copy vector cinv to save_cinv
7 copy routine our_cinv to cinv
8 }
9 }
10
11 routine our_cinv {
12 inc screen
13 jmp save_cinv
14 }
+0
-24
eg/compare.60pical less more
0 reserve byte m_high
1 reserve byte m_low
2 reserve byte n_high
3 reserve byte n_low
4
5 routine compare_16_bit {
6 lda m_high
7 cmp n_high
8 if beq {
9 lda m_low
10 cmp n_low
11 } else {
12 }
13 }
14
15 routine compare_16_bit {
16 lda >m
17 cmp >n
18 if beq {
19 lda <m
20 cmp <n
21 } else {
22 }
23 }
0 assign byte table screen $0400
1 assign byte table screen2 1274
2 assign byte table screen3 1524
3 assign byte table screen4 1774
4
5 assign byte table colormap 55296
6 assign byte table colormap2 55546
7 assign byte table colormap3 55796
8 assign byte table colormap4 56046
9
10 assign byte vic_border 53280
11 assign byte table vic_bg 53281
12
13 assign vector cinv 788
14 reserve vector save_cinv
15
16 assign word position $fb
17
18 reserve byte value
19
20 reserve word m
21 reserve word n
22
23 routine main {
24 lda #5
25 sta vic_border
26 lda #0
27 sta vic_bg
28 jsr reset_position
29 jsr clear_screen
30 sei {
31 copy vector cinv to save_cinv
32 copy routine our_cinv to cinv
33 }
34 clc
35 repeat bcc { }
36 }
37
38 routine reset_position {
39 lda #$00
40 sta <position
41 lda #$04
42 sta >position
43 }
44
45 routine our_cinv {
46 lda value
47 inc value
48 ldy #0
49 sta (position), y
50 jsr increment_pos
51 jsr compare_pos
52 if beq {
53 jsr reset_position
54 } else {
55 }
56 jmp (save_cinv)
57 }
58
59 routine increment_pos {
60 clc
61 lda <position
62 adc #1
63 sta <position
64 lda >position
65 adc #0
66 sta >position
67 }
68
69 routine compare_pos {
70 lda <position
71 sta <m
72 lda >position
73 sta >m
74 lda #$07
75 sta >n
76 lda #$e8
77 sta <n
78 jsr compare_16_bit
79 }
80
81 routine compare_16_bit {
82 lda >m
83 cmp >n
84 if beq {
85 lda <m
86 cmp <n
87 } else {
88 }
89 }
90
91 routine clear_screen {
92 ldy #0
93 repeat bne {
94 lda #1
95 sta colormap, y
96 sta colormap2, y
97 sta colormap3, y
98 sta colormap4, y
99
100 lda #32
101 sta screen, y
102 sta screen2, y
103 sta screen3, y
104 sta screen4, y
105
106 iny
107 cpy #250
108 }
109 }
+0
-110
eg/demo.60pical less more
0 assign byte table screen $0400
1 assign byte table screen2 1274
2 assign byte table screen3 1524
3 assign byte table screen4 1774
4
5 assign byte table colormap 55296
6 assign byte table colormap2 55546
7 assign byte table colormap3 55796
8 assign byte table colormap4 56046
9
10 assign byte vic_border 53280
11 assign byte table vic_bg 53281
12
13 assign vector cinv 788
14 reserve vector save_cinv
15
16 assign word position $fb
17
18 reserve byte value
19
20 reserve word m
21 reserve word n
22
23 routine main {
24 lda #5
25 sta vic_border
26 lda #0
27 sta vic_bg
28 jsr reset_position
29 jsr clear_screen
30 sei {
31 copy vector cinv to save_cinv
32 copy routine our_cinv to cinv
33 }
34 clc
35 repeat bcc { }
36 }
37
38 routine reset_position {
39 lda #$00
40 sta <position
41 lda #$04
42 sta >position
43 }
44
45 routine our_cinv {
46 lda value
47 inc value
48 ldy #0
49 sta (position), y
50 jsr increment_pos
51 jsr compare_pos
52 if beq {
53 jsr reset_position
54 } else {
55 }
56 jmp save_cinv
57 }
58
59 routine increment_pos {
60 clc
61 lda <position
62 adc #1
63 sta <position
64 lda >position
65 adc #0
66 sta >position
67 }
68
69 routine compare_pos {
70 lda <position
71 sta <m
72 lda >position
73 sta >m
74 lda #$07
75 sta >n
76 lda #$e8
77 sta <n
78 jsr compare_16_bit
79 }
80
81 routine compare_16_bit {
82 lda >m
83 cmp >n
84 if beq {
85 lda <m
86 cmp <n
87 } else {
88 }
89 }
90
91 routine clear_screen {
92 ldy #0
93 repeat bne {
94 lda #1
95 sta colormap, y
96 sta colormap2, y
97 sta colormap3, y
98 sta colormap4, y
99
100 lda #32
101 sta screen, y
102 sta screen2, y
103 sta screen3, y
104 sta screen4, y
105
106 iny
107 cpy #250
108 }
109 }
6565 jsr reset_position
6666 } else { }
6767 }
68 jmp save_cinv
68 jmp (save_cinv)
6969 }
7070
7171 routine reset_position {
0 external chrout 65490
1 routine main {
2 lda #72
3 jsr chrout
4 lda #73
5 jsr chrout
6 lda #13
7 jsr chrout
8 }
+0
-9
eg/hi.60pical less more
0 external chrout 65490
1 routine main {
2 lda #72
3 jsr chrout
4 lda #73
5 jsr chrout
6 lda #13
7 jsr chrout
8 }
+0
-10
eg/screen.60pical less more
0 assign byte screen 1024
1 routine main {
2 ldy #0
3 repeat bne {
4 inc screen
5 dey
6 cpy #0
7 }
8 sty screen
9 }
0 assign byte screen 1024
1 routine main {
2 ldy #0
3 repeat bne {
4 inc screen
5 dey
6 cpy #0
7 }
8 sty screen
9 }
0 assign byte screen 1024
1 routine main {
2 repeat bcc {
3 inc screen
4 clc
5 }
6 }
+0
-7
eg/screen2.60pical less more
0 assign byte screen 1024
1 routine main {
2 repeat bcc {
3 inc screen
4 clc
5 }
6 }
0 assign byte table screen 1024
1 reserve byte value
2 routine main {
3 lda #0
4 sta value
5 ldx #0
6 repeat bne {
7 lda value
8 inc value
9 sta screen, x
10 inx
11 cpx #80
12 }
13 }
+0
-14
eg/screen3.60pical less more
0 assign byte table screen 1024
1 reserve byte value
2 routine main {
3 lda #0
4 sta value
5 ldx #0
6 repeat bne {
7 lda value
8 inc value
9 sta screen, x
10 inx
11 cpx #80
12 }
13 }
+0
-160
eg/sprite_actor_thing_ugh.60p less more
0 assign byte table actor_0_sprite_x 60
1 assign byte table actor_0_sprite_y 68
2 assign byte table vic_sprite_0_x 53281
3 assign byte table vic_sprite_0_y 53289
4
5 reserve byte actor_msb
6 reserve byte msb_counter
7
8 reserve vector logic_vector
9
10 assign byte vic_sprite_x_msb 55555
11
12 routine main {
13 jsr display_actors
14 }
15
16 routine display_actors {
17 ldy #0
18 ldx #0
19
20 repeat bne {
21 lda actor_0_sprite_x, y
22 sta vic_sprite_0_x, x
23 lda actor_0_sprite_y, y
24 sta vic_sprite_0_y, x
25
26 iny
27 inx
28 inx
29 cpy #8
30 }
31
32 lda actor_msb
33 sta vic_sprite_x_msb
34 }
35
36 routine update_actors {
37
38 lda #1
39 sta msb_counter
40 lda #0
41 sta actor_msb
42
43 ldy #0
44 repeat ... {
45
46 lda actor_0_logic_high, y
47 if bne {
48 sta logic_vector+1
49 lda actor_0_logic_low, y
50 sta logic_vector
51
52 save y
53 jsr logic_vector
54 restore y
55 }
56
57 // update_xvel
58
59 clc
60 lda actor_0_xvel, y
61 adc actor_0_xacc, y
62 cmp #max_vel
63 bcc xvel_within_limit ; branch if accumulator is less
64 cmp #min_vel
65 bcs xvel_within_limit ; branch if accumulator is greater or equal
66 jmp update_xpos
67
68 xvel_within_limit:
69 sta actor_0_xvel, y
70
71 update_xpos:
72 clc
73 lda actor_0_xpos_low, y
74 adc actor_0_xvel, y
75 sta actor_0_xpos_low, y
76
77 lda #0
78 sta sign_extend
79 lda actor_0_xvel, y
80 and #$80
81 beq carry_x
82 dec sign_extend
83
84 carry_x:
85 lda actor_0_xpos_high, y
86 adc sign_extend ; $00, or $ff if xvel < 0
87 sta actor_0_xpos_high, y
88
89 update_yvel:
90 clc
91 lda actor_0_yvel, y
92 adc actor_0_yacc, y
93 cmp #max_vel
94 bcc yvel_within_limit ; branch if accumulator is less
95 cmp #min_vel
96 bcs yvel_within_limit ; branch if accumulator is greater or equal
97 jmp update_ypos
98
99 yvel_within_limit:
100 sta actor_0_yvel, y
101
102 update_ypos:
103 clc
104 lda actor_0_ypos_low, y
105 adc actor_0_yvel, y
106 sta actor_0_ypos_low, y
107
108 lda #0
109 sta sign_extend
110 lda actor_0_yvel, y
111 and #$80
112 beq carry_y
113 dec sign_extend
114
115 carry_y:
116 lda actor_0_ypos_high, y
117 adc sign_extend
118 sta actor_0_ypos_high, y
119
120 precompute_sprite_position:
121
122 lda actor_0_xpos_low, y
123 sta temp_low
124 lda actor_0_xpos_high, y
125 sta temp_high
126
127 jsr shift_temp
128 jsr shift_temp
129 jsr shift_temp
130 sta actor_0_sprite_x, y
131
132 lda temp_high ; calculate the sprite's msb
133 beq advance_msb_counter
134 lda actor_msb
135 ora msb_counter
136 sta actor_msb
137
138 advance_msb_counter:
139 asl msb_counter
140
141 set_sprite_y:
142 lda actor_0_ypos_low, y
143 sta temp_low
144 lda actor_0_ypos_high, y
145 sta temp_high
146
147 jsr shift_temp
148 jsr shift_temp
149 jsr shift_temp
150 sta actor_0_sprite_y, y
151
152 next_actor:
153 cpy #$07
154 beq exit_actor_loop
155 iny
156 jmp update_actor_loop
157
158 exit_actor_loop:
159 rts
1414 -- -- -- -- driver -- -- -- --
1515
1616 usage = do
17 putStrLn "Usage: sixtypical (parse|check|analyze|emit) filename.60pical"
17 putStrLn "Usage: sixtypical (parse|check|analyze|emit) filename.60p"
1818 exitWith $ ExitFailure 1
1919
2020 main = do
489489 jmp = do
490490 string "jmp"
491491 spaces
492 l <- locationName
492 string "("
493 spaces
494 l <- locationName
495 string ")"
496 spaces
493497 return $ JMPVECTOR (NamedLocation Nothing l)
494498
495499 jsr :: Parser Instruction