c64_assembler/builder/instruction.rs
1use crate::{
2 instruction::{operation::Operation, Instruction},
3 memory::{
4 address_mode::{AddressMode, Immediate},
5 label::AddressReference,
6 Address,
7 },
8 Instructions,
9};
10
11/// Utility to build instructions.
12///
13/// # Example
14///
15/// ```
16/// use c64_assembler::builder::InstructionBuilder;
17///
18/// let instructions = InstructionBuilder::default()
19/// .label("main_entry_point")
20/// .lda_imm(0x00)
21/// .sta_addr("VIC2_BORDER_COLOR")
22/// .rts()
23/// .build();
24/// ```
25#[derive(Default, Clone)]
26pub struct InstructionBuilder {
27 instructions: Instructions,
28}
29
30impl InstructionBuilder {
31 fn add_instruction(&mut self, operation: Operation, address_mode: AddressMode) {
32 self.instructions.instructions.push(Instruction {
33 operation,
34 address_mode,
35 comments: vec![],
36 });
37 }
38
39 /// Record a new adc instruction with the given addressing mode.
40 fn adc(&mut self, addressing_mode: AddressMode) -> &mut Self {
41 self.add_instruction(Operation::ADC, addressing_mode);
42 self
43 }
44
45 /// Record a adc instruction with data (byte).
46 /// # Example
47 /// ```
48 /// use c64_assembler::builder::InstructionBuilder;
49 /// let instructions = InstructionBuilder::default()
50 /// .adc_imm(0xC0)
51 /// .build();
52 /// ```
53 pub fn adc_imm(&mut self, byte: u8) -> &mut Self {
54 self.adc(AddressMode::Immediate(Immediate::Byte(byte)))
55 }
56
57 /// Record a adc instruction with lower byte of an address.
58 ///
59 /// # Example
60 /// ```
61 /// use c64_assembler::builder::InstructionBuilder;
62 /// let instructions = InstructionBuilder::default()
63 /// .adc_imm_low("test_data")
64 /// .label("test_data")
65 /// .build();
66 /// ```
67 pub fn adc_imm_low(&mut self, address_name: &str) -> &mut Self {
68 self.adc(AddressMode::Immediate(Immediate::Low(AddressReference::new(
69 address_name,
70 ))))
71 }
72
73 /// Record a adc instruction with higher byte of an address.
74 ///
75 /// # Example
76 /// ```
77 /// use c64_assembler::builder::InstructionBuilder;
78 /// let instructions = InstructionBuilder::default()
79 /// .adc_imm_high("test_data")
80 /// .label("test_data")
81 /// .build();
82 /// ```
83 pub fn adc_imm_high(&mut self, address_name: &str) -> &mut Self {
84 self.adc(AddressMode::Immediate(Immediate::High(AddressReference::new(
85 address_name,
86 ))))
87 }
88
89 /// Record a adc instruction that use an absolute address.
90 ///
91 /// # Example
92 /// ```
93 /// use c64_assembler::builder::InstructionBuilder;
94 /// let instructions = InstructionBuilder::default()
95 /// .adc_addr("test_label")
96 /// .label("test_label")
97 /// .build();
98 /// ```
99 pub fn adc_addr(&mut self, address_name: &str) -> &mut Self {
100 self.adc(AddressMode::Absolute(AddressReference::new(address_name)))
101 }
102
103 /// Record a adc instruction that use an absolute address with an offset.
104 /// Offset is in bytes.
105 ///
106 /// # Example
107 /// ```
108 /// use c64_assembler::builder::InstructionBuilder;
109 /// let instructions = InstructionBuilder::default()
110 /// .adc_addr_offs("test_label", 8)
111 /// .label("test_label")
112 /// .build();
113 /// ```
114 pub fn adc_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
115 self.adc(AddressMode::Absolute(AddressReference::with_offset(
116 address_name,
117 offset,
118 )))
119 }
120
121 /// Record a adc instructon that use an absolute address with x-register as indexer.
122 ///
123 /// # Example
124 /// ```
125 /// use c64_assembler::builder::InstructionBuilder;
126 /// let instructions = InstructionBuilder::default()
127 /// .ldx_imm(0x08)
128 /// .adc_addr_x("test_label")
129 /// .label("test_label")
130 /// .build();
131 /// ```
132 pub fn adc_addr_x(&mut self, address_name: &str) -> &mut Self {
133 self.adc(AddressMode::AbsoluteX(AddressReference::new(address_name)))
134 }
135
136 /// Record a adc instructon that use an absolute address with y-register as indexer.
137 ///
138 /// # Example
139 /// ```
140 /// use c64_assembler::builder::InstructionBuilder;
141 /// let instructions = InstructionBuilder::default()
142 /// .ldy_imm(0x08)
143 /// .adc_addr_y("test_label")
144 /// .label("test_label")
145 /// .build();
146 /// ```
147 pub fn adc_addr_y(&mut self, address_name: &str) -> &mut Self {
148 self.adc(AddressMode::AbsoluteY(AddressReference::new(address_name)))
149 }
150
151 /// Record a adc instruction that uses indexed indirect addressing mode.
152 ///
153 /// # Example
154 /// ```
155 /// use c64_assembler::builder::InstructionBuilder;
156 /// let instructions = InstructionBuilder::default()
157 /// .ldx_imm(0x08)
158 /// .adc_ind_x("test_label")
159 /// .label("test_label")
160 /// .build();
161 /// ```
162 pub fn adc_ind_x(&mut self, address_name: &str) -> &mut Self {
163 self.adc(AddressMode::IndexedIndirect(AddressReference::new(address_name)))
164 }
165
166 /// Record a adc instruction that uses indirect indexed addressing mode.
167 ///
168 /// # Example
169 /// ```
170 /// use c64_assembler::builder::InstructionBuilder;
171 /// let instructions = InstructionBuilder::default()
172 /// .ldy_imm(0x08)
173 /// .adc_ind_y("test_label")
174 /// .label("test_label")
175 /// .build();
176 /// ```
177 pub fn adc_ind_y(&mut self, address_name: &str) -> &mut Self {
178 self.adc(AddressMode::IndirectIndexed(AddressReference::new(address_name)))
179 }
180
181 /// Record a new and instruction with the given addressing mode.
182 fn and(&mut self, addressing_mode: AddressMode) -> &mut Self {
183 self.add_instruction(Operation::AND, addressing_mode);
184 self
185 }
186
187 /// Record a and instruction with data (byte).
188 /// # Example
189 /// ```
190 /// use c64_assembler::builder::InstructionBuilder;
191 /// let instructions = InstructionBuilder::default()
192 /// .and_imm(0xC0)
193 /// .build();
194 /// ```
195 pub fn and_imm(&mut self, byte: u8) -> &mut Self {
196 self.and(AddressMode::Immediate(Immediate::Byte(byte)))
197 }
198
199 /// Record a and instruction with lower byte of an address.
200 ///
201 /// # Example
202 /// ```
203 /// use c64_assembler::builder::InstructionBuilder;
204 /// let instructions = InstructionBuilder::default()
205 /// .and_imm_low("test_data")
206 /// .label("test_data")
207 /// .build();
208 /// ```
209 pub fn and_imm_low(&mut self, address_name: &str) -> &mut Self {
210 self.and(AddressMode::Immediate(Immediate::Low(AddressReference::new(
211 address_name,
212 ))))
213 }
214
215 /// Record a and instruction with higher byte of an address.
216 ///
217 /// # Example
218 /// ```
219 /// use c64_assembler::builder::InstructionBuilder;
220 /// let instructions = InstructionBuilder::default()
221 /// .and_imm_high("test_data")
222 /// .label("test_data")
223 /// .build();
224 /// ```
225 pub fn and_imm_high(&mut self, address_name: &str) -> &mut Self {
226 self.and(AddressMode::Immediate(Immediate::High(AddressReference::new(
227 address_name,
228 ))))
229 }
230
231 /// Record a and instruction that use an absolute address.
232 ///
233 /// # Example
234 /// ```
235 /// use c64_assembler::builder::InstructionBuilder;
236 /// let instructions = InstructionBuilder::default()
237 /// .and_addr("test_label")
238 /// .label("test_label")
239 /// .build();
240 /// ```
241 pub fn and_addr(&mut self, address_name: &str) -> &mut Self {
242 self.and(AddressMode::Absolute(AddressReference::new(address_name)))
243 }
244
245 /// Record a and instruction that use an absolute address with an offset.
246 /// Offset is in bytes.
247 ///
248 /// # Example
249 /// ```
250 /// use c64_assembler::builder::InstructionBuilder;
251 /// let instructions = InstructionBuilder::default()
252 /// .and_addr_offs("test_label", 8)
253 /// .label("test_label")
254 /// .build();
255 /// ```
256 pub fn and_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
257 self.and(AddressMode::Absolute(AddressReference::with_offset(
258 address_name,
259 offset,
260 )))
261 }
262
263 /// Record a and instructon that use an absolute address with x-register as indexer.
264 ///
265 /// # Example
266 /// ```
267 /// use c64_assembler::builder::InstructionBuilder;
268 /// let instructions = InstructionBuilder::default()
269 /// .ldx_imm(0x08)
270 /// .and_addr_x("test_label")
271 /// .label("test_label")
272 /// .build();
273 /// ```
274 pub fn and_addr_x(&mut self, address_name: &str) -> &mut Self {
275 self.and(AddressMode::AbsoluteX(AddressReference::new(address_name)))
276 }
277
278 /// Record a and instructon that use an absolute address with y-register as indexer.
279 ///
280 /// # Example
281 /// ```
282 /// use c64_assembler::builder::InstructionBuilder;
283 /// let instructions = InstructionBuilder::default()
284 /// .ldy_imm(0x08)
285 /// .and_addr_y("test_label")
286 /// .label("test_label")
287 /// .build();
288 /// ```
289 pub fn and_addr_y(&mut self, address_name: &str) -> &mut Self {
290 self.and(AddressMode::AbsoluteY(AddressReference::new(address_name)))
291 }
292
293 /// Record a and instruction that uses indexed indirect addressing mode.
294 ///
295 /// # Example
296 /// ```
297 /// use c64_assembler::builder::InstructionBuilder;
298 /// let instructions = InstructionBuilder::default()
299 /// .ldx_imm(0x08)
300 /// .and_ind_x("test_label")
301 /// .label("test_label")
302 /// .build();
303 /// ```
304 pub fn and_ind_x(&mut self, address_name: &str) -> &mut Self {
305 self.and(AddressMode::IndexedIndirect(AddressReference::new(address_name)))
306 }
307
308 /// Record a and instruction that uses indirect indexed addressing mode.
309 ///
310 /// # Example
311 /// ```
312 /// use c64_assembler::builder::InstructionBuilder;
313 /// let instructions = InstructionBuilder::default()
314 /// .ldy_imm(0x08)
315 /// .and_ind_y("test_label")
316 /// .label("test_label")
317 /// .build();
318 /// ```
319 pub fn and_ind_y(&mut self, address_name: &str) -> &mut Self {
320 self.and(AddressMode::IndirectIndexed(AddressReference::new(address_name)))
321 }
322
323 /// Record a new asl instruction with the given addressing mode.
324 fn asl(&mut self, addressing_mode: AddressMode) -> &mut Self {
325 self.add_instruction(Operation::ASL, addressing_mode);
326 self
327 }
328
329 /// Record a asl instruction that uses accumulator as address mode.
330 ///
331 /// # Example
332 /// ```
333 /// use c64_assembler::builder::InstructionBuilder;
334 /// let instructions = InstructionBuilder::default()
335 /// .asl_acc()
336 /// .build();
337 /// ```
338 pub fn asl_acc(&mut self) -> &mut Self {
339 self.asl(AddressMode::Accumulator)
340 }
341
342 /// Record a asl instruction that use an absolute address.
343 ///
344 /// # Example
345 /// ```
346 /// use c64_assembler::builder::InstructionBuilder;
347 /// let instructions = InstructionBuilder::default()
348 /// .asl_addr("test_label")
349 /// .label("test_label")
350 /// .build();
351 /// ```
352 pub fn asl_addr(&mut self, address_name: &str) -> &mut Self {
353 self.asl(AddressMode::Absolute(AddressReference::new(address_name)))
354 }
355
356 /// Record a asl instruction that use an absolute address with an offset.
357 /// Offset is in bytes.
358 ///
359 /// # Example
360 /// ```
361 /// use c64_assembler::builder::InstructionBuilder;
362 /// let instructions = InstructionBuilder::default()
363 /// .asl_addr_offs("test_label", 8)
364 /// .label("test_label")
365 /// .build();
366 /// ```
367 pub fn asl_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
368 self.asl(AddressMode::Absolute(AddressReference::with_offset(
369 address_name,
370 offset,
371 )))
372 }
373
374 /// Record a asl instructon that use an absolute address with x-register as indexer.
375 ///
376 /// # Example
377 /// ```
378 /// use c64_assembler::builder::InstructionBuilder;
379 /// let instructions = InstructionBuilder::default()
380 /// .ldx_imm(0x08)
381 /// .asl_addr_x("test_label")
382 /// .label("test_label")
383 /// .build();
384 /// ```
385 pub fn asl_addr_x(&mut self, address_name: &str) -> &mut Self {
386 self.asl(AddressMode::AbsoluteX(AddressReference::new(address_name)))
387 }
388
389 /// Record a new bcc instruction with the given addressing mode.
390 fn bcc(&mut self, addressing_mode: AddressMode) -> &mut Self {
391 self.add_instruction(Operation::BCC, addressing_mode);
392 self
393 }
394
395 /// Record a bcc instruction that use relativeeeeeeeee address.
396 ///
397 /// # Example
398 /// ```
399 /// use c64_assembler::builder::InstructionBuilder;
400 /// let instructions = InstructionBuilder::default()
401 /// .bcc_addr("test_label")
402 /// .label("test_label")
403 /// .build();
404 /// ```
405 pub fn bcc_addr(&mut self, address_name: &str) -> &mut Self {
406 self.bcc(AddressMode::Relative(AddressReference::new(address_name)))
407 }
408
409 /// Record a bcc instruction that use a relative address with an offset.
410 /// Offset is in bytes.
411 ///
412 /// # Example
413 /// ```
414 /// use c64_assembler::builder::InstructionBuilder;
415 /// let instructions = InstructionBuilder::default()
416 /// .bcc_addr_offs("test_label", 8)
417 /// .label("test_label")
418 /// .build();
419 /// ```
420 pub fn bcc_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
421 self.bcc(AddressMode::Relative(AddressReference::with_offset(
422 address_name,
423 offset,
424 )))
425 }
426
427 /// Record a new bcs instruction with the given addressing mode.
428 fn bcs(&mut self, addressing_mode: AddressMode) -> &mut Self {
429 self.add_instruction(Operation::BCS, addressing_mode);
430 self
431 }
432
433 /// Record a bcs instruction that use relativeeeeeeeee address.
434 ///
435 /// # Example
436 /// ```
437 /// use c64_assembler::builder::InstructionBuilder;
438 /// let instructions = InstructionBuilder::default()
439 /// .bcs_addr("test_label")
440 /// .label("test_label")
441 /// .build();
442 /// ```
443 pub fn bcs_addr(&mut self, address_name: &str) -> &mut Self {
444 self.bcs(AddressMode::Relative(AddressReference::new(address_name)))
445 }
446
447 /// Record a bcs instruction that use a relative address with an offset.
448 /// Offset is in bytes.
449 ///
450 /// # Example
451 /// ```
452 /// use c64_assembler::builder::InstructionBuilder;
453 /// let instructions = InstructionBuilder::default()
454 /// .bcs_addr_offs("test_label", 8)
455 /// .label("test_label")
456 /// .build();
457 /// ```
458 pub fn bcs_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
459 self.bcs(AddressMode::Relative(AddressReference::with_offset(
460 address_name,
461 offset,
462 )))
463 }
464
465 /// Record a new beq instruction with the given addressing mode.
466 fn beq(&mut self, addressing_mode: AddressMode) -> &mut Self {
467 self.add_instruction(Operation::BEQ, addressing_mode);
468 self
469 }
470
471 /// Record a beq instruction that use relativeeeeeeeee address.
472 ///
473 /// # Example
474 /// ```
475 /// use c64_assembler::builder::InstructionBuilder;
476 /// let instructions = InstructionBuilder::default()
477 /// .beq_addr("test_label")
478 /// .label("test_label")
479 /// .build();
480 /// ```
481 pub fn beq_addr(&mut self, address_name: &str) -> &mut Self {
482 self.beq(AddressMode::Relative(AddressReference::new(address_name)))
483 }
484
485 /// Record a beq instruction that use a relative address with an offset.
486 /// Offset is in bytes.
487 ///
488 /// # Example
489 /// ```
490 /// use c64_assembler::builder::InstructionBuilder;
491 /// let instructions = InstructionBuilder::default()
492 /// .beq_addr_offs("test_label", 8)
493 /// .label("test_label")
494 /// .build();
495 /// ```
496 pub fn beq_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
497 self.beq(AddressMode::Relative(AddressReference::with_offset(
498 address_name,
499 offset,
500 )))
501 }
502
503 /// Record a new bit instruction with the given addressing mode.
504 fn bit(&mut self, addressing_mode: AddressMode) -> &mut Self {
505 self.add_instruction(Operation::BIT, addressing_mode);
506 self
507 }
508
509 /// Record a bit instruction that use an absolute address.
510 ///
511 /// # Example
512 /// ```
513 /// use c64_assembler::builder::InstructionBuilder;
514 /// let instructions = InstructionBuilder::default()
515 /// .bit_addr("test_label")
516 /// .label("test_label")
517 /// .build();
518 /// ```
519 pub fn bit_addr(&mut self, address_name: &str) -> &mut Self {
520 self.bit(AddressMode::Absolute(AddressReference::new(address_name)))
521 }
522
523 /// Record a bit instruction that use an absolute address with an offset.
524 /// Offset is in bytes.
525 ///
526 /// # Example
527 /// ```
528 /// use c64_assembler::builder::InstructionBuilder;
529 /// let instructions = InstructionBuilder::default()
530 /// .bit_addr_offs("test_label", 8)
531 /// .label("test_label")
532 /// .build();
533 /// ```
534 pub fn bit_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
535 self.bit(AddressMode::Absolute(AddressReference::with_offset(
536 address_name,
537 offset,
538 )))
539 }
540
541 /// Record a new bmi instruction with the given addressing mode.
542 fn bmi(&mut self, addressing_mode: AddressMode) -> &mut Self {
543 self.add_instruction(Operation::BMI, addressing_mode);
544 self
545 }
546
547 /// Record a bmi instruction that use relativeeeeeeeee address.
548 ///
549 /// # Example
550 /// ```
551 /// use c64_assembler::builder::InstructionBuilder;
552 /// let instructions = InstructionBuilder::default()
553 /// .bmi_addr("test_label")
554 /// .label("test_label")
555 /// .build();
556 /// ```
557 pub fn bmi_addr(&mut self, address_name: &str) -> &mut Self {
558 self.bmi(AddressMode::Relative(AddressReference::new(address_name)))
559 }
560
561 /// Record a bmi instruction that use a relative address with an offset.
562 /// Offset is in bytes.
563 ///
564 /// # Example
565 /// ```
566 /// use c64_assembler::builder::InstructionBuilder;
567 /// let instructions = InstructionBuilder::default()
568 /// .bmi_addr_offs("test_label", 8)
569 /// .label("test_label")
570 /// .build();
571 /// ```
572 pub fn bmi_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
573 self.bmi(AddressMode::Relative(AddressReference::with_offset(
574 address_name,
575 offset,
576 )))
577 }
578
579 /// Record a new bne instruction with the given addressing mode.
580 fn bne(&mut self, addressing_mode: AddressMode) -> &mut Self {
581 self.add_instruction(Operation::BNE, addressing_mode);
582 self
583 }
584
585 /// Record a bne instruction that use relativeeeeeeeee address.
586 ///
587 /// # Example
588 /// ```
589 /// use c64_assembler::builder::InstructionBuilder;
590 /// let instructions = InstructionBuilder::default()
591 /// .bne_addr("test_label")
592 /// .label("test_label")
593 /// .build();
594 /// ```
595 pub fn bne_addr(&mut self, address_name: &str) -> &mut Self {
596 self.bne(AddressMode::Relative(AddressReference::new(address_name)))
597 }
598
599 /// Record a bne instruction that use a relative address with an offset.
600 /// Offset is in bytes.
601 ///
602 /// # Example
603 /// ```
604 /// use c64_assembler::builder::InstructionBuilder;
605 /// let instructions = InstructionBuilder::default()
606 /// .bne_addr_offs("test_label", 8)
607 /// .label("test_label")
608 /// .build();
609 /// ```
610 pub fn bne_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
611 self.bne(AddressMode::Relative(AddressReference::with_offset(
612 address_name,
613 offset,
614 )))
615 }
616
617 /// Record a new bpl instruction with the given addressing mode.
618 fn bpl(&mut self, addressing_mode: AddressMode) -> &mut Self {
619 self.add_instruction(Operation::BPL, addressing_mode);
620 self
621 }
622
623 /// Record a bpl instruction that use relativeeeeeeeee address.
624 ///
625 /// # Example
626 /// ```
627 /// use c64_assembler::builder::InstructionBuilder;
628 /// let instructions = InstructionBuilder::default()
629 /// .bpl_addr("test_label")
630 /// .label("test_label")
631 /// .build();
632 /// ```
633 pub fn bpl_addr(&mut self, address_name: &str) -> &mut Self {
634 self.bpl(AddressMode::Relative(AddressReference::new(address_name)))
635 }
636
637 /// Record a bpl instruction that use a relative address with an offset.
638 /// Offset is in bytes.
639 ///
640 /// # Example
641 /// ```
642 /// use c64_assembler::builder::InstructionBuilder;
643 /// let instructions = InstructionBuilder::default()
644 /// .bpl_addr_offs("test_label", 8)
645 /// .label("test_label")
646 /// .build();
647 /// ```
648 pub fn bpl_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
649 self.bpl(AddressMode::Relative(AddressReference::with_offset(
650 address_name,
651 offset,
652 )))
653 }
654
655 /// Record a new brk instruction (addressing mode is implied).
656 ///
657 /// # Example
658 /// ```
659 /// use c64_assembler::builder::InstructionBuilder;
660 /// let instructions = InstructionBuilder::default()
661 /// .brk()
662 /// .build();
663 /// ```
664 pub fn brk(&mut self) -> &mut Self {
665 self.add_instruction(Operation::BRK, AddressMode::Implied);
666 self
667 }
668
669 /// Record a new bvc instruction with the given addressing mode.
670 fn bvc(&mut self, addressing_mode: AddressMode) -> &mut Self {
671 self.add_instruction(Operation::BVC, addressing_mode);
672 self
673 }
674
675 /// Record a bvc instruction that use relativeeeeeeeee address.
676 ///
677 /// # Example
678 /// ```
679 /// use c64_assembler::builder::InstructionBuilder;
680 /// let instructions = InstructionBuilder::default()
681 /// .bvc_addr("test_label")
682 /// .label("test_label")
683 /// .build();
684 /// ```
685 pub fn bvc_addr(&mut self, address_name: &str) -> &mut Self {
686 self.bvc(AddressMode::Relative(AddressReference::new(address_name)))
687 }
688
689 /// Record a bvc instruction that use a relative address with an offset.
690 /// Offset is in bytes.
691 ///
692 /// # Example
693 /// ```
694 /// use c64_assembler::builder::InstructionBuilder;
695 /// let instructions = InstructionBuilder::default()
696 /// .bvc_addr_offs("test_label", 8)
697 /// .label("test_label")
698 /// .build();
699 /// ```
700 pub fn bvc_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
701 self.bvc(AddressMode::Relative(AddressReference::with_offset(
702 address_name,
703 offset,
704 )))
705 }
706
707 /// Record a new bvs instruction with the given addressing mode.
708 fn bvs(&mut self, addressing_mode: AddressMode) -> &mut Self {
709 self.add_instruction(Operation::BVS, addressing_mode);
710 self
711 }
712
713 /// Record a bvs instruction that use relativeeeeeeeee address.
714 ///
715 /// # Example
716 /// ```
717 /// use c64_assembler::builder::InstructionBuilder;
718 /// let instructions = InstructionBuilder::default()
719 /// .bvs_addr("test_label")
720 /// .label("test_label")
721 /// .build();
722 /// ```
723 pub fn bvs_addr(&mut self, address_name: &str) -> &mut Self {
724 self.bvs(AddressMode::Relative(AddressReference::new(address_name)))
725 }
726
727 /// Record a bvs instruction that use a relative address with an offset.
728 /// Offset is in bytes.
729 ///
730 /// # Example
731 /// ```
732 /// use c64_assembler::builder::InstructionBuilder;
733 /// let instructions = InstructionBuilder::default()
734 /// .bvs_addr_offs("test_label", 8)
735 /// .label("test_label")
736 /// .build();
737 /// ```
738 pub fn bvs_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
739 self.bvs(AddressMode::Relative(AddressReference::with_offset(
740 address_name,
741 offset,
742 )))
743 }
744
745 /// Record a new clc instruction (addressing mode is implied).
746 ///
747 /// # Example
748 /// ```
749 /// use c64_assembler::builder::InstructionBuilder;
750 /// let instructions = InstructionBuilder::default()
751 /// .clc()
752 /// .build();
753 /// ```
754 pub fn clc(&mut self) -> &mut Self {
755 self.add_instruction(Operation::CLC, AddressMode::Implied);
756 self
757 }
758
759 /// Record a new cld instruction (addressing mode is implied).
760 ///
761 /// # Example
762 /// ```
763 /// use c64_assembler::builder::InstructionBuilder;
764 /// let instructions = InstructionBuilder::default()
765 /// .cld()
766 /// .build();
767 /// ```
768 pub fn cld(&mut self) -> &mut Self {
769 self.add_instruction(Operation::CLD, AddressMode::Implied);
770 self
771 }
772
773 /// Record a new cli instruction (addressing mode is implied).
774 ///
775 /// # Example
776 /// ```
777 /// use c64_assembler::builder::InstructionBuilder;
778 /// let instructions = InstructionBuilder::default()
779 /// .cli()
780 /// .build();
781 /// ```
782 pub fn cli(&mut self) -> &mut Self {
783 self.add_instruction(Operation::CLI, AddressMode::Implied);
784 self
785 }
786
787 /// Record a new clv instruction (addressing mode is implied).
788 ///
789 /// # Example
790 /// ```
791 /// use c64_assembler::builder::InstructionBuilder;
792 /// let instructions = InstructionBuilder::default()
793 /// .clv()
794 /// .build();
795 /// ```
796 pub fn clv(&mut self) -> &mut Self {
797 self.add_instruction(Operation::CLV, AddressMode::Implied);
798 self
799 }
800
801 /// Record a new cmp instruction with the given addressing mode.
802 fn cmp(&mut self, addressing_mode: AddressMode) -> &mut Self {
803 self.add_instruction(Operation::CMP, addressing_mode);
804 self
805 }
806
807 /// Record a cmp instruction with data (byte).
808 /// # Example
809 /// ```
810 /// use c64_assembler::builder::InstructionBuilder;
811 /// let instructions = InstructionBuilder::default()
812 /// .cmp_imm(0xC0)
813 /// .build();
814 /// ```
815 pub fn cmp_imm(&mut self, byte: u8) -> &mut Self {
816 self.cmp(AddressMode::Immediate(Immediate::Byte(byte)))
817 }
818
819 /// Record a cmp instruction with lower byte of an address.
820 ///
821 /// # Example
822 /// ```
823 /// use c64_assembler::builder::InstructionBuilder;
824 /// let instructions = InstructionBuilder::default()
825 /// .cmp_imm_low("test_data")
826 /// .label("test_data")
827 /// .build();
828 /// ```
829 pub fn cmp_imm_low(&mut self, address_name: &str) -> &mut Self {
830 self.cmp(AddressMode::Immediate(Immediate::Low(AddressReference::new(
831 address_name,
832 ))))
833 }
834
835 /// Record a cmp instruction with higher byte of an address.
836 ///
837 /// # Example
838 /// ```
839 /// use c64_assembler::builder::InstructionBuilder;
840 /// let instructions = InstructionBuilder::default()
841 /// .cmp_imm_high("test_data")
842 /// .label("test_data")
843 /// .build();
844 /// ```
845 pub fn cmp_imm_high(&mut self, address_name: &str) -> &mut Self {
846 self.cmp(AddressMode::Immediate(Immediate::High(AddressReference::new(
847 address_name,
848 ))))
849 }
850
851 /// Record a cmp instruction that use an absolute address.
852 ///
853 /// # Example
854 /// ```
855 /// use c64_assembler::builder::InstructionBuilder;
856 /// let instructions = InstructionBuilder::default()
857 /// .cmp_addr("test_label")
858 /// .label("test_label")
859 /// .build();
860 /// ```
861 pub fn cmp_addr(&mut self, address_name: &str) -> &mut Self {
862 self.cmp(AddressMode::Absolute(AddressReference::new(address_name)))
863 }
864
865 /// Record a cmp instruction that use an absolute address with an offset.
866 /// Offset is in bytes.
867 ///
868 /// # Example
869 /// ```
870 /// use c64_assembler::builder::InstructionBuilder;
871 /// let instructions = InstructionBuilder::default()
872 /// .cmp_addr_offs("test_label", 8)
873 /// .label("test_label")
874 /// .build();
875 /// ```
876 pub fn cmp_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
877 self.cmp(AddressMode::Absolute(AddressReference::with_offset(
878 address_name,
879 offset,
880 )))
881 }
882
883 /// Record a cmp instructon that use an absolute address with x-register as indexer.
884 ///
885 /// # Example
886 /// ```
887 /// use c64_assembler::builder::InstructionBuilder;
888 /// let instructions = InstructionBuilder::default()
889 /// .ldx_imm(0x08)
890 /// .cmp_addr_x("test_label")
891 /// .label("test_label")
892 /// .build();
893 /// ```
894 pub fn cmp_addr_x(&mut self, address_name: &str) -> &mut Self {
895 self.cmp(AddressMode::AbsoluteX(AddressReference::new(address_name)))
896 }
897
898 /// Record a cmp instructon that use an absolute address with y-register as indexer.
899 ///
900 /// # Example
901 /// ```
902 /// use c64_assembler::builder::InstructionBuilder;
903 /// let instructions = InstructionBuilder::default()
904 /// .ldy_imm(0x08)
905 /// .cmp_addr_y("test_label")
906 /// .label("test_label")
907 /// .build();
908 /// ```
909 pub fn cmp_addr_y(&mut self, address_name: &str) -> &mut Self {
910 self.cmp(AddressMode::AbsoluteY(AddressReference::new(address_name)))
911 }
912
913 /// Record a cmp instruction that uses indexed indirect addressing mode.
914 ///
915 /// # Example
916 /// ```
917 /// use c64_assembler::builder::InstructionBuilder;
918 /// let instructions = InstructionBuilder::default()
919 /// .ldx_imm(0x08)
920 /// .cmp_ind_x("test_label")
921 /// .label("test_label")
922 /// .build();
923 /// ```
924 pub fn cmp_ind_x(&mut self, address_name: &str) -> &mut Self {
925 self.cmp(AddressMode::IndexedIndirect(AddressReference::new(address_name)))
926 }
927
928 /// Record a cmp instruction that uses indirect indexed addressing mode.
929 ///
930 /// # Example
931 /// ```
932 /// use c64_assembler::builder::InstructionBuilder;
933 /// let instructions = InstructionBuilder::default()
934 /// .ldy_imm(0x08)
935 /// .cmp_ind_y("test_label")
936 /// .label("test_label")
937 /// .build();
938 /// ```
939 pub fn cmp_ind_y(&mut self, address_name: &str) -> &mut Self {
940 self.cmp(AddressMode::IndirectIndexed(AddressReference::new(address_name)))
941 }
942
943 /// Record a new cpx instruction with the given addressing mode.
944 fn cpx(&mut self, addressing_mode: AddressMode) -> &mut Self {
945 self.add_instruction(Operation::CPX, addressing_mode);
946 self
947 }
948
949 /// Record a cpx instruction with data (byte).
950 /// # Example
951 /// ```
952 /// use c64_assembler::builder::InstructionBuilder;
953 /// let instructions = InstructionBuilder::default()
954 /// .cpx_imm(0xC0)
955 /// .build();
956 /// ```
957 pub fn cpx_imm(&mut self, byte: u8) -> &mut Self {
958 self.cpx(AddressMode::Immediate(Immediate::Byte(byte)))
959 }
960
961 /// Record a cpx instruction with lower byte of an address.
962 ///
963 /// # Example
964 /// ```
965 /// use c64_assembler::builder::InstructionBuilder;
966 /// let instructions = InstructionBuilder::default()
967 /// .cpx_imm_low("test_data")
968 /// .label("test_data")
969 /// .build();
970 /// ```
971 pub fn cpx_imm_low(&mut self, address_name: &str) -> &mut Self {
972 self.cpx(AddressMode::Immediate(Immediate::Low(AddressReference::new(
973 address_name,
974 ))))
975 }
976
977 /// Record a cpx instruction with higher byte of an address.
978 ///
979 /// # Example
980 /// ```
981 /// use c64_assembler::builder::InstructionBuilder;
982 /// let instructions = InstructionBuilder::default()
983 /// .cpx_imm_high("test_data")
984 /// .label("test_data")
985 /// .build();
986 /// ```
987 pub fn cpx_imm_high(&mut self, address_name: &str) -> &mut Self {
988 self.cpx(AddressMode::Immediate(Immediate::High(AddressReference::new(
989 address_name,
990 ))))
991 }
992
993 /// Record a cpx instruction that use an absolute address.
994 ///
995 /// # Example
996 /// ```
997 /// use c64_assembler::builder::InstructionBuilder;
998 /// let instructions = InstructionBuilder::default()
999 /// .cpx_addr("test_label")
1000 /// .label("test_label")
1001 /// .build();
1002 /// ```
1003 pub fn cpx_addr(&mut self, address_name: &str) -> &mut Self {
1004 self.cpx(AddressMode::Absolute(AddressReference::new(address_name)))
1005 }
1006
1007 /// Record a cpx instruction that use an absolute address with an offset.
1008 /// Offset is in bytes.
1009 ///
1010 /// # Example
1011 /// ```
1012 /// use c64_assembler::builder::InstructionBuilder;
1013 /// let instructions = InstructionBuilder::default()
1014 /// .cpx_addr_offs("test_label", 8)
1015 /// .label("test_label")
1016 /// .build();
1017 /// ```
1018 pub fn cpx_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
1019 self.cpx(AddressMode::Absolute(AddressReference::with_offset(
1020 address_name,
1021 offset,
1022 )))
1023 }
1024
1025 /// Record a new cpy instruction with the given addressing mode.
1026 fn cpy(&mut self, addressing_mode: AddressMode) -> &mut Self {
1027 self.add_instruction(Operation::CPY, addressing_mode);
1028 self
1029 }
1030
1031 /// Record a cpy instruction with data (byte).
1032 /// # Example
1033 /// ```
1034 /// use c64_assembler::builder::InstructionBuilder;
1035 /// let instructions = InstructionBuilder::default()
1036 /// .cpy_imm(0xC0)
1037 /// .build();
1038 /// ```
1039 pub fn cpy_imm(&mut self, byte: u8) -> &mut Self {
1040 self.cpy(AddressMode::Immediate(Immediate::Byte(byte)))
1041 }
1042
1043 /// Record a cpy instruction with lower byte of an address.
1044 ///
1045 /// # Example
1046 /// ```
1047 /// use c64_assembler::builder::InstructionBuilder;
1048 /// let instructions = InstructionBuilder::default()
1049 /// .cpy_imm_low("test_data")
1050 /// .label("test_data")
1051 /// .build();
1052 /// ```
1053 pub fn cpy_imm_low(&mut self, address_name: &str) -> &mut Self {
1054 self.cpy(AddressMode::Immediate(Immediate::Low(AddressReference::new(
1055 address_name,
1056 ))))
1057 }
1058
1059 /// Record a cpy instruction with higher byte of an address.
1060 ///
1061 /// # Example
1062 /// ```
1063 /// use c64_assembler::builder::InstructionBuilder;
1064 /// let instructions = InstructionBuilder::default()
1065 /// .cpy_imm_high("test_data")
1066 /// .label("test_data")
1067 /// .build();
1068 /// ```
1069 pub fn cpy_imm_high(&mut self, address_name: &str) -> &mut Self {
1070 self.cpy(AddressMode::Immediate(Immediate::High(AddressReference::new(
1071 address_name,
1072 ))))
1073 }
1074
1075 /// Record a cpy instruction that use an absolute address.
1076 ///
1077 /// # Example
1078 /// ```
1079 /// use c64_assembler::builder::InstructionBuilder;
1080 /// let instructions = InstructionBuilder::default()
1081 /// .cpy_addr("test_label")
1082 /// .label("test_label")
1083 /// .build();
1084 /// ```
1085 pub fn cpy_addr(&mut self, address_name: &str) -> &mut Self {
1086 self.cpy(AddressMode::Absolute(AddressReference::new(address_name)))
1087 }
1088
1089 /// Record a cpy instruction that use an absolute address with an offset.
1090 /// Offset is in bytes.
1091 ///
1092 /// # Example
1093 /// ```
1094 /// use c64_assembler::builder::InstructionBuilder;
1095 /// let instructions = InstructionBuilder::default()
1096 /// .cpy_addr_offs("test_label", 8)
1097 /// .label("test_label")
1098 /// .build();
1099 /// ```
1100 pub fn cpy_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
1101 self.cpy(AddressMode::Absolute(AddressReference::with_offset(
1102 address_name,
1103 offset,
1104 )))
1105 }
1106
1107 /// Record a new dec instruction with the given addressing mode.
1108 fn dec(&mut self, addressing_mode: AddressMode) -> &mut Self {
1109 self.add_instruction(Operation::DEC, addressing_mode);
1110 self
1111 }
1112
1113 /// Record a dec instruction that use an absolute address.
1114 ///
1115 /// # Example
1116 /// ```
1117 /// use c64_assembler::builder::InstructionBuilder;
1118 /// let instructions = InstructionBuilder::default()
1119 /// .dec_addr("test_label")
1120 /// .label("test_label")
1121 /// .build();
1122 /// ```
1123 pub fn dec_addr(&mut self, address_name: &str) -> &mut Self {
1124 self.dec(AddressMode::Absolute(AddressReference::new(address_name)))
1125 }
1126
1127 /// Record a dec instruction that use an absolute address with an offset.
1128 /// Offset is in bytes.
1129 ///
1130 /// # Example
1131 /// ```
1132 /// use c64_assembler::builder::InstructionBuilder;
1133 /// let instructions = InstructionBuilder::default()
1134 /// .dec_addr_offs("test_label", 8)
1135 /// .label("test_label")
1136 /// .build();
1137 /// ```
1138 pub fn dec_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
1139 self.dec(AddressMode::Absolute(AddressReference::with_offset(
1140 address_name,
1141 offset,
1142 )))
1143 }
1144
1145 /// Record a dec instructon that use an absolute address with x-register as indexer.
1146 ///
1147 /// # Example
1148 /// ```
1149 /// use c64_assembler::builder::InstructionBuilder;
1150 /// let instructions = InstructionBuilder::default()
1151 /// .ldx_imm(0x08)
1152 /// .dec_addr_x("test_label")
1153 /// .label("test_label")
1154 /// .build();
1155 /// ```
1156 pub fn dec_addr_x(&mut self, address_name: &str) -> &mut Self {
1157 self.dec(AddressMode::AbsoluteX(AddressReference::new(address_name)))
1158 }
1159
1160 /// Record a new dex instruction (addressing mode is implied).
1161 ///
1162 /// # Example
1163 /// ```
1164 /// use c64_assembler::builder::InstructionBuilder;
1165 /// let instructions = InstructionBuilder::default()
1166 /// .dex()
1167 /// .build();
1168 /// ```
1169 pub fn dex(&mut self) -> &mut Self {
1170 self.add_instruction(Operation::DEX, AddressMode::Implied);
1171 self
1172 }
1173
1174 /// Record a new dey instruction (addressing mode is implied).
1175 ///
1176 /// # Example
1177 /// ```
1178 /// use c64_assembler::builder::InstructionBuilder;
1179 /// let instructions = InstructionBuilder::default()
1180 /// .dey()
1181 /// .build();
1182 /// ```
1183 pub fn dey(&mut self) -> &mut Self {
1184 self.add_instruction(Operation::DEY, AddressMode::Implied);
1185 self
1186 }
1187
1188 /// Record a new eor instruction with the given addressing mode.
1189 fn eor(&mut self, addressing_mode: AddressMode) -> &mut Self {
1190 self.add_instruction(Operation::EOR, addressing_mode);
1191 self
1192 }
1193
1194 /// Record a eor instruction with data (byte).
1195 /// # Example
1196 /// ```
1197 /// use c64_assembler::builder::InstructionBuilder;
1198 /// let instructions = InstructionBuilder::default()
1199 /// .eor_imm(0xC0)
1200 /// .build();
1201 /// ```
1202 pub fn eor_imm(&mut self, byte: u8) -> &mut Self {
1203 self.eor(AddressMode::Immediate(Immediate::Byte(byte)))
1204 }
1205
1206 /// Record a eor instruction with lower byte of an address.
1207 ///
1208 /// # Example
1209 /// ```
1210 /// use c64_assembler::builder::InstructionBuilder;
1211 /// let instructions = InstructionBuilder::default()
1212 /// .eor_imm_low("test_data")
1213 /// .label("test_data")
1214 /// .build();
1215 /// ```
1216 pub fn eor_imm_low(&mut self, address_name: &str) -> &mut Self {
1217 self.eor(AddressMode::Immediate(Immediate::Low(AddressReference::new(
1218 address_name,
1219 ))))
1220 }
1221
1222 /// Record a eor instruction with higher byte of an address.
1223 ///
1224 /// # Example
1225 /// ```
1226 /// use c64_assembler::builder::InstructionBuilder;
1227 /// let instructions = InstructionBuilder::default()
1228 /// .eor_imm_high("test_data")
1229 /// .label("test_data")
1230 /// .build();
1231 /// ```
1232 pub fn eor_imm_high(&mut self, address_name: &str) -> &mut Self {
1233 self.eor(AddressMode::Immediate(Immediate::High(AddressReference::new(
1234 address_name,
1235 ))))
1236 }
1237
1238 /// Record a eor instruction that use an absolute address.
1239 ///
1240 /// # Example
1241 /// ```
1242 /// use c64_assembler::builder::InstructionBuilder;
1243 /// let instructions = InstructionBuilder::default()
1244 /// .eor_addr("test_label")
1245 /// .label("test_label")
1246 /// .build();
1247 /// ```
1248 pub fn eor_addr(&mut self, address_name: &str) -> &mut Self {
1249 self.eor(AddressMode::Absolute(AddressReference::new(address_name)))
1250 }
1251
1252 /// Record a eor instruction that use an absolute address with an offset.
1253 /// Offset is in bytes.
1254 ///
1255 /// # Example
1256 /// ```
1257 /// use c64_assembler::builder::InstructionBuilder;
1258 /// let instructions = InstructionBuilder::default()
1259 /// .eor_addr_offs("test_label", 8)
1260 /// .label("test_label")
1261 /// .build();
1262 /// ```
1263 pub fn eor_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
1264 self.eor(AddressMode::Absolute(AddressReference::with_offset(
1265 address_name,
1266 offset,
1267 )))
1268 }
1269
1270 /// Record a eor instructon that use an absolute address with x-register as indexer.
1271 ///
1272 /// # Example
1273 /// ```
1274 /// use c64_assembler::builder::InstructionBuilder;
1275 /// let instructions = InstructionBuilder::default()
1276 /// .ldx_imm(0x08)
1277 /// .eor_addr_x("test_label")
1278 /// .label("test_label")
1279 /// .build();
1280 /// ```
1281 pub fn eor_addr_x(&mut self, address_name: &str) -> &mut Self {
1282 self.eor(AddressMode::AbsoluteX(AddressReference::new(address_name)))
1283 }
1284
1285 /// Record a eor instructon that use an absolute address with y-register as indexer.
1286 ///
1287 /// # Example
1288 /// ```
1289 /// use c64_assembler::builder::InstructionBuilder;
1290 /// let instructions = InstructionBuilder::default()
1291 /// .ldy_imm(0x08)
1292 /// .eor_addr_y("test_label")
1293 /// .label("test_label")
1294 /// .build();
1295 /// ```
1296 pub fn eor_addr_y(&mut self, address_name: &str) -> &mut Self {
1297 self.eor(AddressMode::AbsoluteY(AddressReference::new(address_name)))
1298 }
1299
1300 /// Record a eor instruction that uses indexed indirect addressing mode.
1301 ///
1302 /// # Example
1303 /// ```
1304 /// use c64_assembler::builder::InstructionBuilder;
1305 /// let instructions = InstructionBuilder::default()
1306 /// .ldx_imm(0x08)
1307 /// .eor_ind_x("test_label")
1308 /// .label("test_label")
1309 /// .build();
1310 /// ```
1311 pub fn eor_ind_x(&mut self, address_name: &str) -> &mut Self {
1312 self.eor(AddressMode::IndexedIndirect(AddressReference::new(address_name)))
1313 }
1314
1315 /// Record a eor instruction that uses indirect indexed addressing mode.
1316 ///
1317 /// # Example
1318 /// ```
1319 /// use c64_assembler::builder::InstructionBuilder;
1320 /// let instructions = InstructionBuilder::default()
1321 /// .ldy_imm(0x08)
1322 /// .eor_ind_y("test_label")
1323 /// .label("test_label")
1324 /// .build();
1325 /// ```
1326 pub fn eor_ind_y(&mut self, address_name: &str) -> &mut Self {
1327 self.eor(AddressMode::IndirectIndexed(AddressReference::new(address_name)))
1328 }
1329
1330 /// Record a new inc instruction with the given addressing mode.
1331 fn inc(&mut self, addressing_mode: AddressMode) -> &mut Self {
1332 self.add_instruction(Operation::INC, addressing_mode);
1333 self
1334 }
1335
1336 /// Record a inc instruction that use an absolute address.
1337 ///
1338 /// # Example
1339 /// ```
1340 /// use c64_assembler::builder::InstructionBuilder;
1341 /// let instructions = InstructionBuilder::default()
1342 /// .inc_addr("test_label")
1343 /// .label("test_label")
1344 /// .build();
1345 /// ```
1346 pub fn inc_addr(&mut self, address_name: &str) -> &mut Self {
1347 self.inc(AddressMode::Absolute(AddressReference::new(address_name)))
1348 }
1349
1350 /// Record a inc instruction that use an absolute address with an offset.
1351 /// Offset is in bytes.
1352 ///
1353 /// # Example
1354 /// ```
1355 /// use c64_assembler::builder::InstructionBuilder;
1356 /// let instructions = InstructionBuilder::default()
1357 /// .inc_addr_offs("test_label", 8)
1358 /// .label("test_label")
1359 /// .build();
1360 /// ```
1361 pub fn inc_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
1362 self.inc(AddressMode::Absolute(AddressReference::with_offset(
1363 address_name,
1364 offset,
1365 )))
1366 }
1367
1368 /// Record a inc instructon that use an absolute address with x-register as indexer.
1369 ///
1370 /// # Example
1371 /// ```
1372 /// use c64_assembler::builder::InstructionBuilder;
1373 /// let instructions = InstructionBuilder::default()
1374 /// .ldx_imm(0x08)
1375 /// .inc_addr_x("test_label")
1376 /// .label("test_label")
1377 /// .build();
1378 /// ```
1379 pub fn inc_addr_x(&mut self, address_name: &str) -> &mut Self {
1380 self.inc(AddressMode::AbsoluteX(AddressReference::new(address_name)))
1381 }
1382
1383 /// Record a new inx instruction (addressing mode is implied).
1384 ///
1385 /// # Example
1386 /// ```
1387 /// use c64_assembler::builder::InstructionBuilder;
1388 /// let instructions = InstructionBuilder::default()
1389 /// .inx()
1390 /// .build();
1391 /// ```
1392 pub fn inx(&mut self) -> &mut Self {
1393 self.add_instruction(Operation::INX, AddressMode::Implied);
1394 self
1395 }
1396
1397 /// Record a new iny instruction (addressing mode is implied).
1398 ///
1399 /// # Example
1400 /// ```
1401 /// use c64_assembler::builder::InstructionBuilder;
1402 /// let instructions = InstructionBuilder::default()
1403 /// .iny()
1404 /// .build();
1405 /// ```
1406 pub fn iny(&mut self) -> &mut Self {
1407 self.add_instruction(Operation::INY, AddressMode::Implied);
1408 self
1409 }
1410
1411 /// Record a new jmp instruction with the given addressing mode.
1412 fn jmp(&mut self, addressing_mode: AddressMode) -> &mut Self {
1413 self.add_instruction(Operation::JMP, addressing_mode);
1414 self
1415 }
1416
1417 /// Record a jmp instruction that use an absolute address.
1418 ///
1419 /// # Example
1420 /// ```
1421 /// use c64_assembler::builder::InstructionBuilder;
1422 /// let instructions = InstructionBuilder::default()
1423 /// .jmp_addr("test_label")
1424 /// .label("test_label")
1425 /// .build();
1426 /// ```
1427 pub fn jmp_addr(&mut self, address_name: &str) -> &mut Self {
1428 self.jmp(AddressMode::Absolute(AddressReference::new(address_name)))
1429 }
1430
1431 /// Record a jmp instruction that use an absolute address with an offset.
1432 /// Offset is in bytes.
1433 ///
1434 /// # Example
1435 /// ```
1436 /// use c64_assembler::builder::InstructionBuilder;
1437 /// let instructions = InstructionBuilder::default()
1438 /// .jmp_addr_offs("test_label", 8)
1439 /// .label("test_label")
1440 /// .build();
1441 /// ```
1442 pub fn jmp_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
1443 self.jmp(AddressMode::Absolute(AddressReference::with_offset(
1444 address_name,
1445 offset,
1446 )))
1447 }
1448
1449 /// Record a jmp instruction that uses indirect addressing mode.
1450 ///
1451 /// # Example
1452 /// ```
1453 /// use c64_assembler::builder::InstructionBuilder;
1454 /// let instructions = InstructionBuilder::default()
1455 /// .jmp_ind("test_label")
1456 /// .label("test_label")
1457 /// .build();
1458 /// ```
1459 pub fn jmp_ind(&mut self, address_name: &str) -> &mut Self {
1460 self.jmp(AddressMode::Indirect(AddressReference::new(address_name)))
1461 }
1462
1463 /// Record a new jsr instruction with the given addressing mode.
1464 fn jsr(&mut self, addressing_mode: AddressMode) -> &mut Self {
1465 self.add_instruction(Operation::JSR, addressing_mode);
1466 self
1467 }
1468
1469 /// Record a jsr instruction that use an absolute address.
1470 ///
1471 /// # Example
1472 /// ```
1473 /// use c64_assembler::builder::InstructionBuilder;
1474 /// let instructions = InstructionBuilder::default()
1475 /// .jsr_addr("test_label")
1476 /// .label("test_label")
1477 /// .build();
1478 /// ```
1479 pub fn jsr_addr(&mut self, address_name: &str) -> &mut Self {
1480 self.jsr(AddressMode::Absolute(AddressReference::new(address_name)))
1481 }
1482
1483 /// Record a jsr instruction that use an absolute address with an offset.
1484 /// Offset is in bytes.
1485 ///
1486 /// # Example
1487 /// ```
1488 /// use c64_assembler::builder::InstructionBuilder;
1489 /// let instructions = InstructionBuilder::default()
1490 /// .jsr_addr_offs("test_label", 8)
1491 /// .label("test_label")
1492 /// .build();
1493 /// ```
1494 pub fn jsr_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
1495 self.jsr(AddressMode::Absolute(AddressReference::with_offset(
1496 address_name,
1497 offset,
1498 )))
1499 }
1500
1501 /// Record a new lda instruction with the given addressing mode.
1502 fn lda(&mut self, addressing_mode: AddressMode) -> &mut Self {
1503 self.add_instruction(Operation::LDA, addressing_mode);
1504 self
1505 }
1506
1507 /// Record a lda instruction with data (byte).
1508 /// # Example
1509 /// ```
1510 /// use c64_assembler::builder::InstructionBuilder;
1511 /// let instructions = InstructionBuilder::default()
1512 /// .lda_imm(0xC0)
1513 /// .build();
1514 /// ```
1515 pub fn lda_imm(&mut self, byte: u8) -> &mut Self {
1516 self.lda(AddressMode::Immediate(Immediate::Byte(byte)))
1517 }
1518
1519 /// Record a lda instruction with lower byte of an address.
1520 ///
1521 /// # Example
1522 /// ```
1523 /// use c64_assembler::builder::InstructionBuilder;
1524 /// let instructions = InstructionBuilder::default()
1525 /// .lda_imm_low("test_data")
1526 /// .label("test_data")
1527 /// .build();
1528 /// ```
1529 pub fn lda_imm_low(&mut self, address_name: &str) -> &mut Self {
1530 self.lda(AddressMode::Immediate(Immediate::Low(AddressReference::new(
1531 address_name,
1532 ))))
1533 }
1534
1535 /// Record a lda instruction with higher byte of an address.
1536 ///
1537 /// # Example
1538 /// ```
1539 /// use c64_assembler::builder::InstructionBuilder;
1540 /// let instructions = InstructionBuilder::default()
1541 /// .lda_imm_high("test_data")
1542 /// .label("test_data")
1543 /// .build();
1544 /// ```
1545 pub fn lda_imm_high(&mut self, address_name: &str) -> &mut Self {
1546 self.lda(AddressMode::Immediate(Immediate::High(AddressReference::new(
1547 address_name,
1548 ))))
1549 }
1550
1551 /// Record a lda instruction that use an absolute address.
1552 ///
1553 /// # Example
1554 /// ```
1555 /// use c64_assembler::builder::InstructionBuilder;
1556 /// let instructions = InstructionBuilder::default()
1557 /// .lda_addr("test_label")
1558 /// .label("test_label")
1559 /// .build();
1560 /// ```
1561 pub fn lda_addr(&mut self, address_name: &str) -> &mut Self {
1562 self.lda(AddressMode::Absolute(AddressReference::new(address_name)))
1563 }
1564
1565 /// Record a lda instruction that use an absolute address with an offset.
1566 /// Offset is in bytes.
1567 ///
1568 /// # Example
1569 /// ```
1570 /// use c64_assembler::builder::InstructionBuilder;
1571 /// let instructions = InstructionBuilder::default()
1572 /// .lda_addr_offs("test_label", 8)
1573 /// .label("test_label")
1574 /// .build();
1575 /// ```
1576 pub fn lda_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
1577 self.lda(AddressMode::Absolute(AddressReference::with_offset(
1578 address_name,
1579 offset,
1580 )))
1581 }
1582
1583 /// Record a lda instructon that use an absolute address with x-register as indexer.
1584 ///
1585 /// # Example
1586 /// ```
1587 /// use c64_assembler::builder::InstructionBuilder;
1588 /// let instructions = InstructionBuilder::default()
1589 /// .ldx_imm(0x08)
1590 /// .lda_addr_x("test_label")
1591 /// .label("test_label")
1592 /// .build();
1593 /// ```
1594 pub fn lda_addr_x(&mut self, address_name: &str) -> &mut Self {
1595 self.lda(AddressMode::AbsoluteX(AddressReference::new(address_name)))
1596 }
1597
1598 /// Record a lda instructon that use an absolute address with y-register as indexer.
1599 ///
1600 /// # Example
1601 /// ```
1602 /// use c64_assembler::builder::InstructionBuilder;
1603 /// let instructions = InstructionBuilder::default()
1604 /// .ldy_imm(0x08)
1605 /// .lda_addr_y("test_label")
1606 /// .label("test_label")
1607 /// .build();
1608 /// ```
1609 pub fn lda_addr_y(&mut self, address_name: &str) -> &mut Self {
1610 self.lda(AddressMode::AbsoluteY(AddressReference::new(address_name)))
1611 }
1612
1613 /// Record a lda instruction that uses indexed indirect addressing mode.
1614 ///
1615 /// # Example
1616 /// ```
1617 /// use c64_assembler::builder::InstructionBuilder;
1618 /// let instructions = InstructionBuilder::default()
1619 /// .ldx_imm(0x08)
1620 /// .lda_ind_x("test_label")
1621 /// .label("test_label")
1622 /// .build();
1623 /// ```
1624 pub fn lda_ind_x(&mut self, address_name: &str) -> &mut Self {
1625 self.lda(AddressMode::IndexedIndirect(AddressReference::new(address_name)))
1626 }
1627
1628 /// Record a lda instruction that uses indirect indexed addressing mode.
1629 ///
1630 /// # Example
1631 /// ```
1632 /// use c64_assembler::builder::InstructionBuilder;
1633 /// let instructions = InstructionBuilder::default()
1634 /// .ldy_imm(0x08)
1635 /// .lda_ind_y("test_label")
1636 /// .label("test_label")
1637 /// .build();
1638 /// ```
1639 pub fn lda_ind_y(&mut self, address_name: &str) -> &mut Self {
1640 self.lda(AddressMode::IndirectIndexed(AddressReference::new(address_name)))
1641 }
1642
1643 /// Record a new ldx instruction with the given addressing mode.
1644 fn ldx(&mut self, addressing_mode: AddressMode) -> &mut Self {
1645 self.add_instruction(Operation::LDX, addressing_mode);
1646 self
1647 }
1648
1649 /// Record a ldx instruction with data (byte).
1650 /// # Example
1651 /// ```
1652 /// use c64_assembler::builder::InstructionBuilder;
1653 /// let instructions = InstructionBuilder::default()
1654 /// .ldx_imm(0xC0)
1655 /// .build();
1656 /// ```
1657 pub fn ldx_imm(&mut self, byte: u8) -> &mut Self {
1658 self.ldx(AddressMode::Immediate(Immediate::Byte(byte)))
1659 }
1660
1661 /// Record a ldx instruction with lower byte of an address.
1662 ///
1663 /// # Example
1664 /// ```
1665 /// use c64_assembler::builder::InstructionBuilder;
1666 /// let instructions = InstructionBuilder::default()
1667 /// .ldx_imm_low("test_data")
1668 /// .label("test_data")
1669 /// .build();
1670 /// ```
1671 pub fn ldx_imm_low(&mut self, address_name: &str) -> &mut Self {
1672 self.ldx(AddressMode::Immediate(Immediate::Low(AddressReference::new(
1673 address_name,
1674 ))))
1675 }
1676
1677 /// Record a ldx instruction with higher byte of an address.
1678 ///
1679 /// # Example
1680 /// ```
1681 /// use c64_assembler::builder::InstructionBuilder;
1682 /// let instructions = InstructionBuilder::default()
1683 /// .ldx_imm_high("test_data")
1684 /// .label("test_data")
1685 /// .build();
1686 /// ```
1687 pub fn ldx_imm_high(&mut self, address_name: &str) -> &mut Self {
1688 self.ldx(AddressMode::Immediate(Immediate::High(AddressReference::new(
1689 address_name,
1690 ))))
1691 }
1692
1693 /// Record a ldx instruction that use an absolute address.
1694 ///
1695 /// # Example
1696 /// ```
1697 /// use c64_assembler::builder::InstructionBuilder;
1698 /// let instructions = InstructionBuilder::default()
1699 /// .ldx_addr("test_label")
1700 /// .label("test_label")
1701 /// .build();
1702 /// ```
1703 pub fn ldx_addr(&mut self, address_name: &str) -> &mut Self {
1704 self.ldx(AddressMode::Absolute(AddressReference::new(address_name)))
1705 }
1706
1707 /// Record a ldx instruction that use an absolute address with an offset.
1708 /// Offset is in bytes.
1709 ///
1710 /// # Example
1711 /// ```
1712 /// use c64_assembler::builder::InstructionBuilder;
1713 /// let instructions = InstructionBuilder::default()
1714 /// .ldx_addr_offs("test_label", 8)
1715 /// .label("test_label")
1716 /// .build();
1717 /// ```
1718 pub fn ldx_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
1719 self.ldx(AddressMode::Absolute(AddressReference::with_offset(
1720 address_name,
1721 offset,
1722 )))
1723 }
1724
1725 /// Record a ldx instructon that use an absolute address with y-register as indexer.
1726 ///
1727 /// # Example
1728 /// ```
1729 /// use c64_assembler::builder::InstructionBuilder;
1730 /// let instructions = InstructionBuilder::default()
1731 /// .ldy_imm(0x08)
1732 /// .ldx_addr_y("test_label")
1733 /// .label("test_label")
1734 /// .build();
1735 /// ```
1736 pub fn ldx_addr_y(&mut self, address_name: &str) -> &mut Self {
1737 self.ldx(AddressMode::AbsoluteY(AddressReference::new(address_name)))
1738 }
1739
1740 /// Record a new ldy instruction with the given addressing mode.
1741 fn ldy(&mut self, addressing_mode: AddressMode) -> &mut Self {
1742 self.add_instruction(Operation::LDY, addressing_mode);
1743 self
1744 }
1745
1746 /// Record a ldy instruction with data (byte).
1747 /// # Example
1748 /// ```
1749 /// use c64_assembler::builder::InstructionBuilder;
1750 /// let instructions = InstructionBuilder::default()
1751 /// .ldy_imm(0xC0)
1752 /// .build();
1753 /// ```
1754 pub fn ldy_imm(&mut self, byte: u8) -> &mut Self {
1755 self.ldy(AddressMode::Immediate(Immediate::Byte(byte)))
1756 }
1757
1758 /// Record a ldy instruction with lower byte of an address.
1759 ///
1760 /// # Example
1761 /// ```
1762 /// use c64_assembler::builder::InstructionBuilder;
1763 /// let instructions = InstructionBuilder::default()
1764 /// .ldy_imm_low("test_data")
1765 /// .label("test_data")
1766 /// .build();
1767 /// ```
1768 pub fn ldy_imm_low(&mut self, address_name: &str) -> &mut Self {
1769 self.ldy(AddressMode::Immediate(Immediate::Low(AddressReference::new(
1770 address_name,
1771 ))))
1772 }
1773
1774 /// Record a ldy instruction with higher byte of an address.
1775 ///
1776 /// # Example
1777 /// ```
1778 /// use c64_assembler::builder::InstructionBuilder;
1779 /// let instructions = InstructionBuilder::default()
1780 /// .ldy_imm_high("test_data")
1781 /// .label("test_data")
1782 /// .build();
1783 /// ```
1784 pub fn ldy_imm_high(&mut self, address_name: &str) -> &mut Self {
1785 self.ldy(AddressMode::Immediate(Immediate::High(AddressReference::new(
1786 address_name,
1787 ))))
1788 }
1789
1790 /// Record a ldy instruction that use an absolute address.
1791 ///
1792 /// # Example
1793 /// ```
1794 /// use c64_assembler::builder::InstructionBuilder;
1795 /// let instructions = InstructionBuilder::default()
1796 /// .ldy_addr("test_label")
1797 /// .label("test_label")
1798 /// .build();
1799 /// ```
1800 pub fn ldy_addr(&mut self, address_name: &str) -> &mut Self {
1801 self.ldy(AddressMode::Absolute(AddressReference::new(address_name)))
1802 }
1803
1804 /// Record a ldy instruction that use an absolute address with an offset.
1805 /// Offset is in bytes.
1806 ///
1807 /// # Example
1808 /// ```
1809 /// use c64_assembler::builder::InstructionBuilder;
1810 /// let instructions = InstructionBuilder::default()
1811 /// .ldy_addr_offs("test_label", 8)
1812 /// .label("test_label")
1813 /// .build();
1814 /// ```
1815 pub fn ldy_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
1816 self.ldy(AddressMode::Absolute(AddressReference::with_offset(
1817 address_name,
1818 offset,
1819 )))
1820 }
1821
1822 /// Record a ldy instructon that use an absolute address with x-register as indexer.
1823 ///
1824 /// # Example
1825 /// ```
1826 /// use c64_assembler::builder::InstructionBuilder;
1827 /// let instructions = InstructionBuilder::default()
1828 /// .ldx_imm(0x08)
1829 /// .ldy_addr_x("test_label")
1830 /// .label("test_label")
1831 /// .build();
1832 /// ```
1833 pub fn ldy_addr_x(&mut self, address_name: &str) -> &mut Self {
1834 self.ldy(AddressMode::AbsoluteX(AddressReference::new(address_name)))
1835 }
1836
1837 /// Record a new lsr instruction with the given addressing mode.
1838 fn lsr(&mut self, addressing_mode: AddressMode) -> &mut Self {
1839 self.add_instruction(Operation::LSR, addressing_mode);
1840 self
1841 }
1842
1843 /// Record a lsr instruction that uses accumulator as address mode.
1844 ///
1845 /// # Example
1846 /// ```
1847 /// use c64_assembler::builder::InstructionBuilder;
1848 /// let instructions = InstructionBuilder::default()
1849 /// .lsr_acc()
1850 /// .build();
1851 /// ```
1852 pub fn lsr_acc(&mut self) -> &mut Self {
1853 self.lsr(AddressMode::Accumulator)
1854 }
1855
1856 /// Record a lsr instruction that use an absolute address.
1857 ///
1858 /// # Example
1859 /// ```
1860 /// use c64_assembler::builder::InstructionBuilder;
1861 /// let instructions = InstructionBuilder::default()
1862 /// .lsr_addr("test_label")
1863 /// .label("test_label")
1864 /// .build();
1865 /// ```
1866 pub fn lsr_addr(&mut self, address_name: &str) -> &mut Self {
1867 self.lsr(AddressMode::Absolute(AddressReference::new(address_name)))
1868 }
1869
1870 /// Record a lsr instruction that use an absolute address with an offset.
1871 /// Offset is in bytes.
1872 ///
1873 /// # Example
1874 /// ```
1875 /// use c64_assembler::builder::InstructionBuilder;
1876 /// let instructions = InstructionBuilder::default()
1877 /// .lsr_addr_offs("test_label", 8)
1878 /// .label("test_label")
1879 /// .build();
1880 /// ```
1881 pub fn lsr_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
1882 self.lsr(AddressMode::Absolute(AddressReference::with_offset(
1883 address_name,
1884 offset,
1885 )))
1886 }
1887
1888 /// Record a lsr instructon that use an absolute address with x-register as indexer.
1889 ///
1890 /// # Example
1891 /// ```
1892 /// use c64_assembler::builder::InstructionBuilder;
1893 /// let instructions = InstructionBuilder::default()
1894 /// .ldx_imm(0x08)
1895 /// .lsr_addr_x("test_label")
1896 /// .label("test_label")
1897 /// .build();
1898 /// ```
1899 pub fn lsr_addr_x(&mut self, address_name: &str) -> &mut Self {
1900 self.lsr(AddressMode::AbsoluteX(AddressReference::new(address_name)))
1901 }
1902
1903 /// Record a new nop instruction (addressing mode is implied).
1904 ///
1905 /// # Example
1906 /// ```
1907 /// use c64_assembler::builder::InstructionBuilder;
1908 /// let instructions = InstructionBuilder::default()
1909 /// .nop()
1910 /// .build();
1911 /// ```
1912 pub fn nop(&mut self) -> &mut Self {
1913 self.add_instruction(Operation::NOP, AddressMode::Implied);
1914 self
1915 }
1916
1917 /// Record a new ora instruction with the given addressing mode.
1918 fn ora(&mut self, addressing_mode: AddressMode) -> &mut Self {
1919 self.add_instruction(Operation::ORA, addressing_mode);
1920 self
1921 }
1922
1923 /// Record a ora instruction with data (byte).
1924 /// # Example
1925 /// ```
1926 /// use c64_assembler::builder::InstructionBuilder;
1927 /// let instructions = InstructionBuilder::default()
1928 /// .ora_imm(0xC0)
1929 /// .build();
1930 /// ```
1931 pub fn ora_imm(&mut self, byte: u8) -> &mut Self {
1932 self.ora(AddressMode::Immediate(Immediate::Byte(byte)))
1933 }
1934
1935 /// Record a ora instruction with lower byte of an address.
1936 ///
1937 /// # Example
1938 /// ```
1939 /// use c64_assembler::builder::InstructionBuilder;
1940 /// let instructions = InstructionBuilder::default()
1941 /// .ora_imm_low("test_data")
1942 /// .label("test_data")
1943 /// .build();
1944 /// ```
1945 pub fn ora_imm_low(&mut self, address_name: &str) -> &mut Self {
1946 self.ora(AddressMode::Immediate(Immediate::Low(AddressReference::new(
1947 address_name,
1948 ))))
1949 }
1950
1951 /// Record a ora instruction with higher byte of an address.
1952 ///
1953 /// # Example
1954 /// ```
1955 /// use c64_assembler::builder::InstructionBuilder;
1956 /// let instructions = InstructionBuilder::default()
1957 /// .ora_imm_high("test_data")
1958 /// .label("test_data")
1959 /// .build();
1960 /// ```
1961 pub fn ora_imm_high(&mut self, address_name: &str) -> &mut Self {
1962 self.ora(AddressMode::Immediate(Immediate::High(AddressReference::new(
1963 address_name,
1964 ))))
1965 }
1966
1967 /// Record a ora instruction that use an absolute address.
1968 ///
1969 /// # Example
1970 /// ```
1971 /// use c64_assembler::builder::InstructionBuilder;
1972 /// let instructions = InstructionBuilder::default()
1973 /// .ora_addr("test_label")
1974 /// .label("test_label")
1975 /// .build();
1976 /// ```
1977 pub fn ora_addr(&mut self, address_name: &str) -> &mut Self {
1978 self.ora(AddressMode::Absolute(AddressReference::new(address_name)))
1979 }
1980
1981 /// Record a ora instruction that use an absolute address with an offset.
1982 /// Offset is in bytes.
1983 ///
1984 /// # Example
1985 /// ```
1986 /// use c64_assembler::builder::InstructionBuilder;
1987 /// let instructions = InstructionBuilder::default()
1988 /// .ora_addr_offs("test_label", 8)
1989 /// .label("test_label")
1990 /// .build();
1991 /// ```
1992 pub fn ora_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
1993 self.ora(AddressMode::Absolute(AddressReference::with_offset(
1994 address_name,
1995 offset,
1996 )))
1997 }
1998
1999 /// Record a ora instructon that use an absolute address with x-register as indexer.
2000 ///
2001 /// # Example
2002 /// ```
2003 /// use c64_assembler::builder::InstructionBuilder;
2004 /// let instructions = InstructionBuilder::default()
2005 /// .ldx_imm(0x08)
2006 /// .ora_addr_x("test_label")
2007 /// .label("test_label")
2008 /// .build();
2009 /// ```
2010 pub fn ora_addr_x(&mut self, address_name: &str) -> &mut Self {
2011 self.ora(AddressMode::AbsoluteX(AddressReference::new(address_name)))
2012 }
2013
2014 /// Record a ora instructon that use an absolute address with y-register as indexer.
2015 ///
2016 /// # Example
2017 /// ```
2018 /// use c64_assembler::builder::InstructionBuilder;
2019 /// let instructions = InstructionBuilder::default()
2020 /// .ldy_imm(0x08)
2021 /// .ora_addr_y("test_label")
2022 /// .label("test_label")
2023 /// .build();
2024 /// ```
2025 pub fn ora_addr_y(&mut self, address_name: &str) -> &mut Self {
2026 self.ora(AddressMode::AbsoluteY(AddressReference::new(address_name)))
2027 }
2028
2029 /// Record a ora instruction that uses indexed indirect addressing mode.
2030 ///
2031 /// # Example
2032 /// ```
2033 /// use c64_assembler::builder::InstructionBuilder;
2034 /// let instructions = InstructionBuilder::default()
2035 /// .ldx_imm(0x08)
2036 /// .ora_ind_x("test_label")
2037 /// .label("test_label")
2038 /// .build();
2039 /// ```
2040 pub fn ora_ind_x(&mut self, address_name: &str) -> &mut Self {
2041 self.ora(AddressMode::IndexedIndirect(AddressReference::new(address_name)))
2042 }
2043
2044 /// Record a ora instruction that uses indirect indexed addressing mode.
2045 ///
2046 /// # Example
2047 /// ```
2048 /// use c64_assembler::builder::InstructionBuilder;
2049 /// let instructions = InstructionBuilder::default()
2050 /// .ldy_imm(0x08)
2051 /// .ora_ind_y("test_label")
2052 /// .label("test_label")
2053 /// .build();
2054 /// ```
2055 pub fn ora_ind_y(&mut self, address_name: &str) -> &mut Self {
2056 self.ora(AddressMode::IndirectIndexed(AddressReference::new(address_name)))
2057 }
2058
2059 /// Record a new pha instruction (addressing mode is implied).
2060 ///
2061 /// # Example
2062 /// ```
2063 /// use c64_assembler::builder::InstructionBuilder;
2064 /// let instructions = InstructionBuilder::default()
2065 /// .pha()
2066 /// .build();
2067 /// ```
2068 pub fn pha(&mut self) -> &mut Self {
2069 self.add_instruction(Operation::PHA, AddressMode::Implied);
2070 self
2071 }
2072
2073 /// Record a new php instruction (addressing mode is implied).
2074 ///
2075 /// # Example
2076 /// ```
2077 /// use c64_assembler::builder::InstructionBuilder;
2078 /// let instructions = InstructionBuilder::default()
2079 /// .php()
2080 /// .build();
2081 /// ```
2082 pub fn php(&mut self) -> &mut Self {
2083 self.add_instruction(Operation::PHP, AddressMode::Implied);
2084 self
2085 }
2086
2087 /// Record a new pla instruction (addressing mode is implied).
2088 ///
2089 /// # Example
2090 /// ```
2091 /// use c64_assembler::builder::InstructionBuilder;
2092 /// let instructions = InstructionBuilder::default()
2093 /// .pla()
2094 /// .build();
2095 /// ```
2096 pub fn pla(&mut self) -> &mut Self {
2097 self.add_instruction(Operation::PLA, AddressMode::Implied);
2098 self
2099 }
2100
2101 /// Record a new plp instruction (addressing mode is implied).
2102 ///
2103 /// # Example
2104 /// ```
2105 /// use c64_assembler::builder::InstructionBuilder;
2106 /// let instructions = InstructionBuilder::default()
2107 /// .plp()
2108 /// .build();
2109 /// ```
2110 pub fn plp(&mut self) -> &mut Self {
2111 self.add_instruction(Operation::PLP, AddressMode::Implied);
2112 self
2113 }
2114
2115 /// Record a new rol instruction with the given addressing mode.
2116 fn rol(&mut self, addressing_mode: AddressMode) -> &mut Self {
2117 self.add_instruction(Operation::ROL, addressing_mode);
2118 self
2119 }
2120
2121 /// Record a rol instruction that uses accumulator as address mode.
2122 ///
2123 /// # Example
2124 /// ```
2125 /// use c64_assembler::builder::InstructionBuilder;
2126 /// let instructions = InstructionBuilder::default()
2127 /// .rol_acc()
2128 /// .build();
2129 /// ```
2130 pub fn rol_acc(&mut self) -> &mut Self {
2131 self.rol(AddressMode::Accumulator)
2132 }
2133
2134 /// Record a rol instruction that use an absolute address.
2135 ///
2136 /// # Example
2137 /// ```
2138 /// use c64_assembler::builder::InstructionBuilder;
2139 /// let instructions = InstructionBuilder::default()
2140 /// .rol_addr("test_label")
2141 /// .label("test_label")
2142 /// .build();
2143 /// ```
2144 pub fn rol_addr(&mut self, address_name: &str) -> &mut Self {
2145 self.rol(AddressMode::Absolute(AddressReference::new(address_name)))
2146 }
2147
2148 /// Record a rol instruction that use an absolute address with an offset.
2149 /// Offset is in bytes.
2150 ///
2151 /// # Example
2152 /// ```
2153 /// use c64_assembler::builder::InstructionBuilder;
2154 /// let instructions = InstructionBuilder::default()
2155 /// .rol_addr_offs("test_label", 8)
2156 /// .label("test_label")
2157 /// .build();
2158 /// ```
2159 pub fn rol_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
2160 self.rol(AddressMode::Absolute(AddressReference::with_offset(
2161 address_name,
2162 offset,
2163 )))
2164 }
2165
2166 /// Record a rol instructon that use an absolute address with x-register as indexer.
2167 ///
2168 /// # Example
2169 /// ```
2170 /// use c64_assembler::builder::InstructionBuilder;
2171 /// let instructions = InstructionBuilder::default()
2172 /// .ldx_imm(0x08)
2173 /// .rol_addr_x("test_label")
2174 /// .label("test_label")
2175 /// .build();
2176 /// ```
2177 pub fn rol_addr_x(&mut self, address_name: &str) -> &mut Self {
2178 self.rol(AddressMode::AbsoluteX(AddressReference::new(address_name)))
2179 }
2180
2181 /// Record a new ror instruction with the given addressing mode.
2182 fn ror(&mut self, addressing_mode: AddressMode) -> &mut Self {
2183 self.add_instruction(Operation::ROR, addressing_mode);
2184 self
2185 }
2186
2187 /// Record a ror instruction that uses accumulator as address mode.
2188 ///
2189 /// # Example
2190 /// ```
2191 /// use c64_assembler::builder::InstructionBuilder;
2192 /// let instructions = InstructionBuilder::default()
2193 /// .ror_acc()
2194 /// .build();
2195 /// ```
2196 pub fn ror_acc(&mut self) -> &mut Self {
2197 self.ror(AddressMode::Accumulator)
2198 }
2199
2200 /// Record a ror instruction that use an absolute address.
2201 ///
2202 /// # Example
2203 /// ```
2204 /// use c64_assembler::builder::InstructionBuilder;
2205 /// let instructions = InstructionBuilder::default()
2206 /// .ror_addr("test_label")
2207 /// .label("test_label")
2208 /// .build();
2209 /// ```
2210 pub fn ror_addr(&mut self, address_name: &str) -> &mut Self {
2211 self.ror(AddressMode::Absolute(AddressReference::new(address_name)))
2212 }
2213
2214 /// Record a ror instruction that use an absolute address with an offset.
2215 /// Offset is in bytes.
2216 ///
2217 /// # Example
2218 /// ```
2219 /// use c64_assembler::builder::InstructionBuilder;
2220 /// let instructions = InstructionBuilder::default()
2221 /// .ror_addr_offs("test_label", 8)
2222 /// .label("test_label")
2223 /// .build();
2224 /// ```
2225 pub fn ror_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
2226 self.ror(AddressMode::Absolute(AddressReference::with_offset(
2227 address_name,
2228 offset,
2229 )))
2230 }
2231
2232 /// Record a ror instructon that use an absolute address with x-register as indexer.
2233 ///
2234 /// # Example
2235 /// ```
2236 /// use c64_assembler::builder::InstructionBuilder;
2237 /// let instructions = InstructionBuilder::default()
2238 /// .ldx_imm(0x08)
2239 /// .ror_addr_x("test_label")
2240 /// .label("test_label")
2241 /// .build();
2242 /// ```
2243 pub fn ror_addr_x(&mut self, address_name: &str) -> &mut Self {
2244 self.ror(AddressMode::AbsoluteX(AddressReference::new(address_name)))
2245 }
2246
2247 /// Record a new rti instruction (addressing mode is implied).
2248 ///
2249 /// # Example
2250 /// ```
2251 /// use c64_assembler::builder::InstructionBuilder;
2252 /// let instructions = InstructionBuilder::default()
2253 /// .rti()
2254 /// .build();
2255 /// ```
2256 pub fn rti(&mut self) -> &mut Self {
2257 self.add_instruction(Operation::RTI, AddressMode::Implied);
2258 self
2259 }
2260
2261 /// Record a new rts instruction (addressing mode is implied).
2262 ///
2263 /// # Example
2264 /// ```
2265 /// use c64_assembler::builder::InstructionBuilder;
2266 /// let instructions = InstructionBuilder::default()
2267 /// .rts()
2268 /// .build();
2269 /// ```
2270 pub fn rts(&mut self) -> &mut Self {
2271 self.add_instruction(Operation::RTS, AddressMode::Implied);
2272 self
2273 }
2274
2275 /// Record a new sbc instruction with the given addressing mode.
2276 fn sbc(&mut self, addressing_mode: AddressMode) -> &mut Self {
2277 self.add_instruction(Operation::SBC, addressing_mode);
2278 self
2279 }
2280
2281 /// Record a sbc instruction with data (byte).
2282 /// # Example
2283 /// ```
2284 /// use c64_assembler::builder::InstructionBuilder;
2285 /// let instructions = InstructionBuilder::default()
2286 /// .sbc_imm(0xC0)
2287 /// .build();
2288 /// ```
2289 pub fn sbc_imm(&mut self, byte: u8) -> &mut Self {
2290 self.sbc(AddressMode::Immediate(Immediate::Byte(byte)))
2291 }
2292
2293 /// Record a sbc instruction with lower byte of an address.
2294 ///
2295 /// # Example
2296 /// ```
2297 /// use c64_assembler::builder::InstructionBuilder;
2298 /// let instructions = InstructionBuilder::default()
2299 /// .sbc_imm_low("test_data")
2300 /// .label("test_data")
2301 /// .build();
2302 /// ```
2303 pub fn sbc_imm_low(&mut self, address_name: &str) -> &mut Self {
2304 self.sbc(AddressMode::Immediate(Immediate::Low(AddressReference::new(
2305 address_name,
2306 ))))
2307 }
2308
2309 /// Record a sbc instruction with higher byte of an address.
2310 ///
2311 /// # Example
2312 /// ```
2313 /// use c64_assembler::builder::InstructionBuilder;
2314 /// let instructions = InstructionBuilder::default()
2315 /// .sbc_imm_high("test_data")
2316 /// .label("test_data")
2317 /// .build();
2318 /// ```
2319 pub fn sbc_imm_high(&mut self, address_name: &str) -> &mut Self {
2320 self.sbc(AddressMode::Immediate(Immediate::High(AddressReference::new(
2321 address_name,
2322 ))))
2323 }
2324
2325 /// Record a sbc instruction that use an absolute address.
2326 ///
2327 /// # Example
2328 /// ```
2329 /// use c64_assembler::builder::InstructionBuilder;
2330 /// let instructions = InstructionBuilder::default()
2331 /// .sbc_addr("test_label")
2332 /// .label("test_label")
2333 /// .build();
2334 /// ```
2335 pub fn sbc_addr(&mut self, address_name: &str) -> &mut Self {
2336 self.sbc(AddressMode::Absolute(AddressReference::new(address_name)))
2337 }
2338
2339 /// Record a sbc instruction that use an absolute address with an offset.
2340 /// Offset is in bytes.
2341 ///
2342 /// # Example
2343 /// ```
2344 /// use c64_assembler::builder::InstructionBuilder;
2345 /// let instructions = InstructionBuilder::default()
2346 /// .sbc_addr_offs("test_label", 8)
2347 /// .label("test_label")
2348 /// .build();
2349 /// ```
2350 pub fn sbc_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
2351 self.sbc(AddressMode::Absolute(AddressReference::with_offset(
2352 address_name,
2353 offset,
2354 )))
2355 }
2356
2357 /// Record a sbc instructon that use an absolute address with x-register as indexer.
2358 ///
2359 /// # Example
2360 /// ```
2361 /// use c64_assembler::builder::InstructionBuilder;
2362 /// let instructions = InstructionBuilder::default()
2363 /// .ldx_imm(0x08)
2364 /// .sbc_addr_x("test_label")
2365 /// .label("test_label")
2366 /// .build();
2367 /// ```
2368 pub fn sbc_addr_x(&mut self, address_name: &str) -> &mut Self {
2369 self.sbc(AddressMode::AbsoluteX(AddressReference::new(address_name)))
2370 }
2371
2372 /// Record a sbc instructon that use an absolute address with y-register as indexer.
2373 ///
2374 /// # Example
2375 /// ```
2376 /// use c64_assembler::builder::InstructionBuilder;
2377 /// let instructions = InstructionBuilder::default()
2378 /// .ldy_imm(0x08)
2379 /// .sbc_addr_y("test_label")
2380 /// .label("test_label")
2381 /// .build();
2382 /// ```
2383 pub fn sbc_addr_y(&mut self, address_name: &str) -> &mut Self {
2384 self.sbc(AddressMode::AbsoluteY(AddressReference::new(address_name)))
2385 }
2386
2387 /// Record a sbc instruction that uses indexed indirect addressing mode.
2388 ///
2389 /// # Example
2390 /// ```
2391 /// use c64_assembler::builder::InstructionBuilder;
2392 /// let instructions = InstructionBuilder::default()
2393 /// .ldx_imm(0x08)
2394 /// .sbc_ind_x("test_label")
2395 /// .label("test_label")
2396 /// .build();
2397 /// ```
2398 pub fn sbc_ind_x(&mut self, address_name: &str) -> &mut Self {
2399 self.sbc(AddressMode::IndexedIndirect(AddressReference::new(address_name)))
2400 }
2401
2402 /// Record a sbc instruction that uses indirect indexed addressing mode.
2403 ///
2404 /// # Example
2405 /// ```
2406 /// use c64_assembler::builder::InstructionBuilder;
2407 /// let instructions = InstructionBuilder::default()
2408 /// .ldy_imm(0x08)
2409 /// .sbc_ind_y("test_label")
2410 /// .label("test_label")
2411 /// .build();
2412 /// ```
2413 pub fn sbc_ind_y(&mut self, address_name: &str) -> &mut Self {
2414 self.sbc(AddressMode::IndirectIndexed(AddressReference::new(address_name)))
2415 }
2416
2417 /// Record a new sec instruction (addressing mode is implied).
2418 ///
2419 /// # Example
2420 /// ```
2421 /// use c64_assembler::builder::InstructionBuilder;
2422 /// let instructions = InstructionBuilder::default()
2423 /// .sec()
2424 /// .build();
2425 /// ```
2426 pub fn sec(&mut self) -> &mut Self {
2427 self.add_instruction(Operation::SEC, AddressMode::Implied);
2428 self
2429 }
2430
2431 /// Record a new sed instruction (addressing mode is implied).
2432 ///
2433 /// # Example
2434 /// ```
2435 /// use c64_assembler::builder::InstructionBuilder;
2436 /// let instructions = InstructionBuilder::default()
2437 /// .sed()
2438 /// .build();
2439 /// ```
2440 pub fn sed(&mut self) -> &mut Self {
2441 self.add_instruction(Operation::SED, AddressMode::Implied);
2442 self
2443 }
2444
2445 /// Record a new sei instruction (addressing mode is implied).
2446 ///
2447 /// # Example
2448 /// ```
2449 /// use c64_assembler::builder::InstructionBuilder;
2450 /// let instructions = InstructionBuilder::default()
2451 /// .sei()
2452 /// .build();
2453 /// ```
2454 pub fn sei(&mut self) -> &mut Self {
2455 self.add_instruction(Operation::SEI, AddressMode::Implied);
2456 self
2457 }
2458
2459 /// Record a new sta instruction with the given addressing mode.
2460 fn sta(&mut self, addressing_mode: AddressMode) -> &mut Self {
2461 self.add_instruction(Operation::STA, addressing_mode);
2462 self
2463 }
2464
2465 /// Record a sta instruction that use an absolute address.
2466 ///
2467 /// # Example
2468 /// ```
2469 /// use c64_assembler::builder::InstructionBuilder;
2470 /// let instructions = InstructionBuilder::default()
2471 /// .sta_addr("test_label")
2472 /// .label("test_label")
2473 /// .build();
2474 /// ```
2475 pub fn sta_addr(&mut self, address_name: &str) -> &mut Self {
2476 self.sta(AddressMode::Absolute(AddressReference::new(address_name)))
2477 }
2478
2479 /// Record a sta instruction that use an absolute address with an offset.
2480 /// Offset is in bytes.
2481 ///
2482 /// # Example
2483 /// ```
2484 /// use c64_assembler::builder::InstructionBuilder;
2485 /// let instructions = InstructionBuilder::default()
2486 /// .sta_addr_offs("test_label", 8)
2487 /// .label("test_label")
2488 /// .build();
2489 /// ```
2490 pub fn sta_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
2491 self.sta(AddressMode::Absolute(AddressReference::with_offset(
2492 address_name,
2493 offset,
2494 )))
2495 }
2496
2497 /// Record a sta instructon that use an absolute address with x-register as indexer.
2498 ///
2499 /// # Example
2500 /// ```
2501 /// use c64_assembler::builder::InstructionBuilder;
2502 /// let instructions = InstructionBuilder::default()
2503 /// .ldx_imm(0x08)
2504 /// .sta_addr_x("test_label")
2505 /// .label("test_label")
2506 /// .build();
2507 /// ```
2508 pub fn sta_addr_x(&mut self, address_name: &str) -> &mut Self {
2509 self.sta(AddressMode::AbsoluteX(AddressReference::new(address_name)))
2510 }
2511
2512 /// Record a sta instructon that use an absolute address with y-register as indexer.
2513 ///
2514 /// # Example
2515 /// ```
2516 /// use c64_assembler::builder::InstructionBuilder;
2517 /// let instructions = InstructionBuilder::default()
2518 /// .ldy_imm(0x08)
2519 /// .sta_addr_y("test_label")
2520 /// .label("test_label")
2521 /// .build();
2522 /// ```
2523 pub fn sta_addr_y(&mut self, address_name: &str) -> &mut Self {
2524 self.sta(AddressMode::AbsoluteY(AddressReference::new(address_name)))
2525 }
2526
2527 /// Record a sta instruction that uses indexed indirect addressing mode.
2528 ///
2529 /// # Example
2530 /// ```
2531 /// use c64_assembler::builder::InstructionBuilder;
2532 /// let instructions = InstructionBuilder::default()
2533 /// .ldx_imm(0x08)
2534 /// .sta_ind_x("test_label")
2535 /// .label("test_label")
2536 /// .build();
2537 /// ```
2538 pub fn sta_ind_x(&mut self, address_name: &str) -> &mut Self {
2539 self.sta(AddressMode::IndexedIndirect(AddressReference::new(address_name)))
2540 }
2541
2542 /// Record a sta instruction that uses indirect indexed addressing mode.
2543 ///
2544 /// # Example
2545 /// ```
2546 /// use c64_assembler::builder::InstructionBuilder;
2547 /// let instructions = InstructionBuilder::default()
2548 /// .ldy_imm(0x08)
2549 /// .sta_ind_y("test_label")
2550 /// .label("test_label")
2551 /// .build();
2552 /// ```
2553 pub fn sta_ind_y(&mut self, address_name: &str) -> &mut Self {
2554 self.sta(AddressMode::IndirectIndexed(AddressReference::new(address_name)))
2555 }
2556
2557 /// Record a new stx instruction with the given addressing mode.
2558 fn stx(&mut self, addressing_mode: AddressMode) -> &mut Self {
2559 self.add_instruction(Operation::STX, addressing_mode);
2560 self
2561 }
2562
2563 /// Record a stx instruction that use an absolute address.
2564 ///
2565 /// # Example
2566 /// ```
2567 /// use c64_assembler::builder::InstructionBuilder;
2568 /// let instructions = InstructionBuilder::default()
2569 /// .stx_addr("test_label")
2570 /// .label("test_label")
2571 /// .build();
2572 /// ```
2573 pub fn stx_addr(&mut self, address_name: &str) -> &mut Self {
2574 self.stx(AddressMode::Absolute(AddressReference::new(address_name)))
2575 }
2576
2577 /// Record a stx instruction that use an absolute address with an offset.
2578 /// Offset is in bytes.
2579 ///
2580 /// # Example
2581 /// ```
2582 /// use c64_assembler::builder::InstructionBuilder;
2583 /// let instructions = InstructionBuilder::default()
2584 /// .stx_addr_offs("test_label", 8)
2585 /// .label("test_label")
2586 /// .build();
2587 /// ```
2588 pub fn stx_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
2589 self.stx(AddressMode::Absolute(AddressReference::with_offset(
2590 address_name,
2591 offset,
2592 )))
2593 }
2594
2595 /// Record a stx instructon that use an absolute address with y-register as indexer.
2596 ///
2597 /// # Example
2598 /// ```
2599 /// use c64_assembler::builder::InstructionBuilder;
2600 /// let instructions = InstructionBuilder::default()
2601 /// .ldy_imm(0x08)
2602 /// .stx_addr_y("test_label")
2603 /// .label("test_label")
2604 /// .build();
2605 /// ```
2606 pub fn stx_addr_y(&mut self, address_name: &str) -> &mut Self {
2607 self.stx(AddressMode::AbsoluteY(AddressReference::new(address_name)))
2608 }
2609
2610 /// Record a new sty instruction with the given addressing mode.
2611 fn sty(&mut self, addressing_mode: AddressMode) -> &mut Self {
2612 self.add_instruction(Operation::STY, addressing_mode);
2613 self
2614 }
2615
2616 /// Record a sty instruction that use an absolute address.
2617 ///
2618 /// # Example
2619 /// ```
2620 /// use c64_assembler::builder::InstructionBuilder;
2621 /// let instructions = InstructionBuilder::default()
2622 /// .sty_addr("test_label")
2623 /// .label("test_label")
2624 /// .build();
2625 /// ```
2626 pub fn sty_addr(&mut self, address_name: &str) -> &mut Self {
2627 self.sty(AddressMode::Absolute(AddressReference::new(address_name)))
2628 }
2629
2630 /// Record a sty instruction that use an absolute address with an offset.
2631 /// Offset is in bytes.
2632 ///
2633 /// # Example
2634 /// ```
2635 /// use c64_assembler::builder::InstructionBuilder;
2636 /// let instructions = InstructionBuilder::default()
2637 /// .sty_addr_offs("test_label", 8)
2638 /// .label("test_label")
2639 /// .build();
2640 /// ```
2641 pub fn sty_addr_offs(&mut self, address_name: &str, offset: Address) -> &mut Self {
2642 self.sty(AddressMode::Absolute(AddressReference::with_offset(
2643 address_name,
2644 offset,
2645 )))
2646 }
2647
2648 /// Record a sty instructon that use an absolute address with x-register as indexer.
2649 ///
2650 /// # Example
2651 /// ```
2652 /// use c64_assembler::builder::InstructionBuilder;
2653 /// let instructions = InstructionBuilder::default()
2654 /// .ldx_imm(0x08)
2655 /// .sty_addr_x("test_label")
2656 /// .label("test_label")
2657 /// .build();
2658 /// ```
2659 pub fn sty_addr_x(&mut self, address_name: &str) -> &mut Self {
2660 self.sty(AddressMode::AbsoluteX(AddressReference::new(address_name)))
2661 }
2662
2663 /// Record a new tax instruction (addressing mode is implied).
2664 ///
2665 /// # Example
2666 /// ```
2667 /// use c64_assembler::builder::InstructionBuilder;
2668 /// let instructions = InstructionBuilder::default()
2669 /// .tax()
2670 /// .build();
2671 /// ```
2672 pub fn tax(&mut self) -> &mut Self {
2673 self.add_instruction(Operation::TAX, AddressMode::Implied);
2674 self
2675 }
2676
2677 /// Record a new tay instruction (addressing mode is implied).
2678 ///
2679 /// # Example
2680 /// ```
2681 /// use c64_assembler::builder::InstructionBuilder;
2682 /// let instructions = InstructionBuilder::default()
2683 /// .tay()
2684 /// .build();
2685 /// ```
2686 pub fn tay(&mut self) -> &mut Self {
2687 self.add_instruction(Operation::TAY, AddressMode::Implied);
2688 self
2689 }
2690
2691 /// Record a new tsx instruction (addressing mode is implied).
2692 ///
2693 /// # Example
2694 /// ```
2695 /// use c64_assembler::builder::InstructionBuilder;
2696 /// let instructions = InstructionBuilder::default()
2697 /// .tsx()
2698 /// .build();
2699 /// ```
2700 pub fn tsx(&mut self) -> &mut Self {
2701 self.add_instruction(Operation::TSX, AddressMode::Implied);
2702 self
2703 }
2704
2705 /// Record a new txa instruction (addressing mode is implied).
2706 ///
2707 /// # Example
2708 /// ```
2709 /// use c64_assembler::builder::InstructionBuilder;
2710 /// let instructions = InstructionBuilder::default()
2711 /// .txa()
2712 /// .build();
2713 /// ```
2714 pub fn txa(&mut self) -> &mut Self {
2715 self.add_instruction(Operation::TXA, AddressMode::Implied);
2716 self
2717 }
2718
2719 /// Record a new txs instruction (addressing mode is implied).
2720 ///
2721 /// # Example
2722 /// ```
2723 /// use c64_assembler::builder::InstructionBuilder;
2724 /// let instructions = InstructionBuilder::default()
2725 /// .txs()
2726 /// .build();
2727 /// ```
2728 pub fn txs(&mut self) -> &mut Self {
2729 self.add_instruction(Operation::TXS, AddressMode::Implied);
2730 self
2731 }
2732
2733 /// Record a new tya instruction (addressing mode is implied).
2734 ///
2735 /// # Example
2736 /// ```
2737 /// use c64_assembler::builder::InstructionBuilder;
2738 /// let instructions = InstructionBuilder::default()
2739 /// .tya()
2740 /// .build();
2741 /// ```
2742 pub fn tya(&mut self) -> &mut Self {
2743 self.add_instruction(Operation::TYA, AddressMode::Implied);
2744 self
2745 }
2746
2747 /// Record some raw data (bytes) in the instruction stream.
2748 ///
2749 /// # Example
2750 /// ```
2751 /// use c64_assembler::builder::InstructionBuilder;
2752 /// let instructions = InstructionBuilder::default()
2753 /// .label("my_data")
2754 /// .raw(&[0x42, 0xDE, 0xAD])
2755 /// .build();
2756 /// ```
2757 pub fn raw(&mut self, data: &[u8]) -> &mut Self {
2758 self.add_instruction(Operation::Raw(Vec::from(data)), AddressMode::Implied);
2759 self
2760 }
2761
2762 /// Record a label into the instruction stream.
2763 ///
2764 /// # Example
2765 /// ```
2766 /// use c64_assembler::builder::InstructionBuilder;
2767 /// let instructions = InstructionBuilder::default()
2768 /// .label("my_data")
2769 /// .raw(&[0x42, 0xDE, 0xAD])
2770 /// .build();
2771 /// ```
2772 pub fn label(&mut self, label: &str) -> &mut Self {
2773 self.add_instruction(Operation::Label(label.to_string()), AddressMode::Implied);
2774 self
2775 }
2776
2777 /// Add a comment to the last instruction.
2778 ///
2779 /// # Example
2780 /// ```
2781 /// use c64_assembler::builder::InstructionBuilder;
2782 /// let instructions = InstructionBuilder::default()
2783 /// .label("frame_number").comment("Current frame number")
2784 /// .raw(&[0x00, 0x00]).comment("Frames are counted from 0")
2785 /// .build();
2786 /// ```
2787 pub fn comment(&mut self, comment: &str) -> &mut Self {
2788 self.instructions
2789 .instructions
2790 .last_mut()
2791 .unwrap()
2792 .comments
2793 .push(comment.to_string());
2794 self
2795 }
2796
2797 /// Add a basic program, when run will start the instructions recorded right after.
2798 ///
2799 /// ```basic
2800 /// 10 SYS 2062
2801 /// ```
2802 ///
2803 /// NOTE: Application entry point should be 0x0800 and add_basic_header must be
2804 /// called as first instruction in the first module.
2805 ///
2806 /// # Example
2807 /// ```
2808 /// use c64_assembler::builder::InstructionBuilder;
2809 /// let instructions = InstructionBuilder::default()
2810 /// .add_basic_header()
2811 /// .rts()
2812 /// .build();
2813 /// ```
2814 pub fn add_basic_header(&mut self) -> &mut Self {
2815 /* Basic line header */
2816 self.raw(&[0x00, 0x0c, 0x08])
2817 .comment("New basic line")
2818 /* 10 SYS 2062 */
2819 .raw(&[0x0a, 0x00, 0x9e, 0x20, 0x32, 0x30, 0x36, 0x32])
2820 .comment("10 SYS 2062")
2821 /* Basic line heaer */
2822 .raw(&[0x00, 0x00, 0x00])
2823 .comment("End basic program")
2824 }
2825
2826 /// Create [crate::Instructions] from this instance.
2827 pub fn build(&self) -> Instructions {
2828 self.instructions.clone()
2829 }
2830}