Mercurial > vba-clojure
comparison clojure/com/aurellem/assembly.clj @ 123:c9a280b8bd1c
saving progress.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 17 Mar 2012 00:29:34 -0500 |
parents | e85b53994fac |
children | f8dadd9478a5 |
comparison
equal
deleted
inserted
replaced
122:e85b53994fac | 123:c9a280b8bd1c |
---|---|
179 0x47 ;D32A | 179 0x47 ;D32A |
180 | 180 |
181 0xCA ;D32B ; if bit-0 is not 1 | 181 0xCA ;D32B ; if bit-0 is not 1 |
182 0x44 ;D32C ; GOTO not-v-blank | 182 0x44 ;D32C ; GOTO not-v-blank |
183 0xD3 ;D32D | 183 0xD3 ;D32D |
184 | |
185 ;;; in v-blank mode | 184 ;;; in v-blank mode |
186 | |
187 ;; if v-blank-prev was 0, | 185 ;; if v-blank-prev was 0, |
188 ;; increment frame-count | 186 ;; increment frame-count |
189 | 187 |
190 0xFA ;D32E ; load v-blank-prev to A | 188 0xFA ;D32E ; load v-blank-prev to A |
191 0x20 ;D32F | 189 0x20 ;D32F |
441 [] | 439 [] |
442 (set-state! (input-number)) | 440 (set-state! (input-number)) |
443 (dotimes [_ 90000] (step (view-memory @current-state 0xD352)))) | 441 (dotimes [_ 90000] (step (view-memory @current-state 0xD352)))) |
444 | 442 |
445 (defn write-memory-assembly [] | 443 (defn write-memory-assembly [] |
446 [0x18 ;D31D ; jump over | 444 [ |
447 0x02 ;D31E ; the next 2 bytes | 445 ;; Main Timing Loop |
448 0x00 ;D31F ; frame-count | 446 ;; Constantly check for v-blank and Trigger main state machine on |
449 0x00 ;D320 ; v-blank-prev | 447 ;; every transtion from v-blank to non-v-blank. |
450 | 448 |
451 0xFA ;D321 | 449 0x18 ; D31D ; Variable declaration |
452 0x41 ;D322 ; load (FF41) into A | 450 0x02 ; D31E |
453 0xFF ;D323 ; this contains mode flags | 451 0x00 ; D31F ; frame-count |
454 | 452 0x00 ; D320 ; v-blank-prev |
455 ;; if we're in v-blank, the bit-1 is 0 | 453 |
456 ;; and bit-2 is 1 Otherwise, it is not v-blank. | 454 0xFA ; D321 ; load v-blank mode flags into A |
457 0xCB ;D324 ; test bit-1 of A | 455 0x41 ; D322 |
458 0x4F ;D325 | 456 0xFF ; D323 |
459 | 457 |
460 0xC2 ;D326 ; if bit-1 is not 0 | 458 ;; Branch dependent on v-blank. v-blank happens when the last two |
461 0x44 ;D327 ; GOTO not-v-blank | 459 ;; bits in A are "01" |
462 0xD3 ;D328 | 460 0xCB ; D324 |
463 | 461 0x4F ; D325 |
464 0xCB ;D329 ; test bit-0 of A | 462 |
465 0x47 ;D32A | 463 0xC2 ; D326 ; if bit-1 is not 0, then |
466 | 464 0x44 ; D327 ; GOTO non-v-blank. |
467 0xCA ;D32B ; if bit-0 is not 1 | 465 0xD3 ; D328 |
468 0x44 ;D32C ; GOTO not-v-blank | 466 |
469 0xD3 ;D32D | 467 0xCB ; D329 |
470 | 468 0x47 ; D32A |
471 ;;; in v-blank mode | 469 |
472 | 470 0xCA ; D32B ; if bit-0 is not 1, then |
473 ;; if v-blank-prev was 0, | 471 0x44 ; D32C ; GOTO non-v-blank. |
474 ;; increment frame-count | 472 0xD3 ; D32D |
475 | 473 |
476 0xFA ;D32E ; load v-blank-prev to A | 474 ;; V-Blank |
477 0x20 ;D32F | 475 ;; Activate state-machine if this is a transition event. |
478 0xD3 ;D330 | 476 |
479 | 477 0xFA ; D32E ; load v-bank-prev into A |
480 0xCB ;D331 | 478 0x20 ; D32F |
481 0x47 ;D332 ; test bit-0 of A | 479 0xD3 ; D330 |
482 | 480 |
483 0x20 ;D333 ; skip next section | 481 0xFE ; D331 ; compare A to 0. |
484 0x07 ;D334 ; if v-blank-prev was not zero | 482 0x00 ; D332 |
485 | 483 |
486 ;; v-blank was 0, increment frame-count | 484 ;; set v-blank-prev to 1. |
487 0xFA ;D335 ; load frame-count into A | 485 0x3E ; D333 ; load 1 into A. |
488 0x1F ;D336 | 486 0x01 ; D334 |
489 0xD3 ;D337 | 487 |
490 | 488 0xEA ; D335 ; load A into v-blank-prev |
491 0x3C ;D338 ; inc A | 489 0x20 ; D336 |
492 | 490 0xD3 ; D337 |
493 0xEA ;D339 ; load A into frame-count | 491 |
494 0x1F ;D33A | 492 ;; if v-blank-prev was 0, activate state-machine |
495 0xD3 ;D33B | 493 0xC2 ; D338 ; if v-blank-prev |
496 | 494 0x46 ; D339 ; was 0, |
497 ;; set v-blank-prev to 1 | 495 0xD3 ; D33A ; GOTO state-machine |
498 0x3E ;D33C ; load 1 into A | 496 |
499 0x01 ;D33D | 497 0xC3 ; D33B |
500 | 498 0x1D ; D33C |
501 0xEA ;D33E ; load A into v-blank-prev | 499 0xD3 ; D33D ; GOTO beginning |
502 0x20 ;D33F | 500 ;; END V-blank |
503 0xD3 ;D340 | 501 |
504 | 502 ;; Non-V-Blank |
505 0xC3 ;D341 ; GOTO input handling code | 503 ;; Set v-blank-prev to 0 |
506 0x4E ;D342 | 504 0x3E ; D33E ; load 0 into A |
507 0xD3 ;D343 | 505 0x00 ; D33F |
508 | 506 |
509 ;;; not in v-blank mode | 507 0xEA ; D340 ; load A into v-blank-prev |
510 ;; set v-blank-prev to 0 | 508 0x20 ; D341 |
511 0x3E ;D344 ; load 0 into A | 509 0xD3 ; D342 |
512 0x00 ;D345 | 510 |
513 | 511 0xC3 ; D343 |
514 0xEA ;D346 ; load A into v-blank-prev | 512 0x1D ; D344 |
515 0x20 ;D347 | 513 0xD3 ; D345 ; GOTO beginning |
516 0xD3 ;D348 | 514 ;; END Not-V-Blank |
517 | 515 |
518 0xC3 ;D349 ; return to beginning | 516 ;; Main State Machine -- Input Section |
519 0x1D ;D34A | 517 ;; This is called once every frame. |
520 0xD3 ;D34B | 518 ;; It collects input and uses it to drive the |
521 | 519 ;; state transitions. |
522 0x00 ;D34C ; these are here | 520 |
523 0x00 ;D34D ; for glue | 521 ;; Increment frame-count |
524 | 522 0xFA ; D346 ; load frame-count into A |
525 | 523 0x1F ; D347 |
526 ;;; calculate input number based on button presses | 524 0xD3 ; D348 |
525 | |
526 0x3C ; D349 ; inc A | |
527 | |
528 0xEA ; D34A | |
529 0x1F ; D34B ; load A into frame-count | |
530 0xD3 ; D34C | |
531 | |
532 0x00 ; D34D ; glue :) | |
533 | |
534 | |
535 ;;;;;;;;; BEGIN RLM DEBUG | |
536 0xC3 ;; jump to beginning | |
537 0x1D | |
538 0xD3 | |
539 | |
540 ;;;;;;;;; END RLM DEBUG | |
541 | |
542 | |
527 0x18 ;D34E ; skip next 3 bytes | 543 0x18 ;D34E ; skip next 3 bytes |
528 0x03 ;D34F | 544 0x03 ;D34F |
529 ;D350 | 545 ;D350 |
530 (Integer/parseInt "00100000" 2) ; select directional pad | 546 (Integer/parseInt "00100000" 2) ; select directional pad |
531 ;D351 | 547 ;D351 |
532 (Integer/parseInt "00010000" 2) ; select buttons | 548 (Integer/parseInt "00010000" 2) ; select buttons |
533 0x00 ;D352 ; input-number | 549 0x00 ;D352 ; input-number |
534 | 550 |
535 ;; select directional pad, store low bits in B | 551 ;; select directional pad; store low bits in B |
536 | 552 |
537 0xFA ;D353 ; load (D350) into A | 553 0xFA ;D353 ; load (D350) into A |
538 0x50 ;D354 --> | 554 0x50 ;D354 --> |
539 0xD3 ;D355 --> D31F | 555 0xD3 ;D355 --> D350 |
540 | 556 |
541 0xEA ;D356 ; load (A), which is | 557 0xEA ;D356 ; load (A), which is |
542 0x00 ;D357 --> ; 00010000, into FF00 | 558 0x00 ;D357 --> ; 00010000, into FF00 |
543 0xFF ;D358 --> FF00 | 559 0xFF ;D358 --> FF00 |
544 | 560 |
545 0x06 ;D359 | 561 0x06 ;D359 |
546 ;D35A | 562 ;D35A |
547 (Integer/parseInt "11110000" 2) ; "11110000" -> B | 563 (Integer/parseInt "11110000" 2) ; "11110000" -> B |
548 0xFA ;D35B ; (FF00) -> A | 564 0xFA ;D35B ; (FF00) -> A |
549 0x00 ;D35C | 565 0x00 ;D35C |
550 0xFF ;D35D | 566 0xFF ;D35D |
551 | 567 |
552 0xCB ;D35E ; swap nybbles on A | 568 0xCB ;D35E ; swap nybbles on A |
553 0x37 ;D35F | 569 0x37 ;D35F |
554 0xA0 ;D360 ; (AND A B) -> A | 570 0xA0 ;D360 ; (AND A B) -> A |
555 0x47 ;D361 ; A -> B | 571 0x47 ;D361 ; A -> B |
556 | 572 |
557 ;; select buttons store bottom bits in C | 573 ;; select buttons; store bottom bits in C |
558 | 574 |
559 0xFA ;D362 ; load (D351) into A | 575 0xFA ;D362 ; load (D351) into A |
560 0x51 ;D363 --> | 576 0x51 ;D363 --> |
561 0xD3 ;D364 --> D31F | 577 0xD3 ;D364 --> D351 |
562 | 578 |
563 0xEA ;D365 ; load (A), which is | 579 0xEA ;D365 ; load (A), which is |
564 0x00 ;D366 --> ; 00001000, into FF00 | 580 0x00 ;D366 --> ; 00001000, into FF00 |
565 0xFF ;D367 --> FF00 | 581 0xFF ;D367 --> FF00 |
566 | 582 |
582 | 598 |
583 0xEA ;D372 ; store A into input-number | 599 0xEA ;D372 ; store A into input-number |
584 0x52 ;D373 | 600 0x52 ;D373 |
585 0xD3 ;D374 | 601 0xD3 ;D374 |
586 | 602 |
587 0xC3 ;D375 ; GOTO state machine | 603 0xC3 ;D375 ; secret jump :) |
588 ;;0x1D | 604 0x1D ;D376 |
589 0x80 ;D376 | |
590 0xD3 ;D377 | 605 0xD3 ;D377 |
591 | |
592 0x00 ;D378 | 606 0x00 ;D378 |
593 0x00 ;D379 | 607 0x00 ;D379 |
594 0x00 ;D37A | 608 0x00 ;D37A |
595 0x00 ;D37B ; these are here because | 609 0x00 ;D37B ; these are here because |
596 0x00 ;D37C ; I messed up :( | 610 0x00 ;D37C ; I messed up :( |
759 | 773 |
760 | 774 |
761 ]) | 775 ]) |
762 | 776 |
763 | 777 |
778 | |
764 (def frame-count 0xD31F) | 779 (def frame-count 0xD31F) |
765 (def input 0xD352) | 780 (def input 0xD352) |
766 (def current-mode 0xD382) | 781 (def current-mode 0xD382) |
767 | 782 |
768 (defn write-memory [] | 783 (defn write-memory [] |
780 (def start-point 0xD384) | 795 (def start-point 0xD384) |
781 | 796 |
782 (defn test-mode-2 [] | 797 (defn test-mode-2 [] |
783 (-> | 798 (-> |
784 (write-memory) | 799 (write-memory) |
785 (view-memory bytes-to-write) | 800 (view-memory frame-count) |
786 (view-memory start-point) | |
787 (step) | 801 (step) |
788 (step [:a]) | 802 (step [:a]) |
789 (step [:b]) | 803 (step [:b]) |
790 (step [:start]) | 804 (step [:start]) |
791 (step []) | 805 (step []) |
792 (view-memory bytes-to-write) | 806 (view-memory frame-count))) |
793 (view-memory start-point))) | 807 |
808 | |
809 | |
810 |