Mercurial > vba-clojure
comparison clojure/com/aurellem/gb/assembly.clj @ 175:5d9a7a0ca09a
beginning test of latest assembly code. 240->70.
author | Dylan Holmes <ocsenave@gmail.com> |
---|---|
date | Wed, 21 Mar 2012 18:17:37 -0500 |
parents | 412ca096a9ba |
children | 95b2758dd517 |
comparison
equal
deleted
inserted
replaced
174:5ce074824fac | 175:5d9a7a0ca09a |
---|---|
405 [] | 405 [] |
406 (set-state! (input-number)) | 406 (set-state! (input-number)) |
407 (dotimes [_ 90000] (step (view-memory @current-state 0xD352)))) | 407 (dotimes [_ 90000] (step (view-memory @current-state 0xD352)))) |
408 | 408 |
409 | 409 |
410 | |
411 | |
412 | |
413 | |
414 | |
415 | |
416 | |
417 | |
418 | |
419 | |
420 | |
421 | |
422 | |
423 | |
424 | |
425 | |
426 | |
427 | |
428 | |
429 | |
430 | |
431 | |
432 | |
433 | |
434 | |
435 | |
436 | |
437 (defn write-memory-assembly* | 410 (defn write-memory-assembly* |
438 "Currently, grabs input from the user each frame." | 411 "A program for altering in-game memory by pressing buttons." |
439 [] | 412 [] |
440 [ | 413 [ |
414 0xF3 ; stop interrupts | |
415 ;; --------- CLEANUP | |
416 0xAF ; zero A [D31E] | |
417 0x57 ; A->D; makes D=0. | |
418 | |
441 ;; --------- FRAME METRONOME | 419 ;; --------- FRAME METRONOME |
442 0x18 ;; jump ahead to cleanup. first time only. | 420 0xF1 ;; pop AF (vblank prev) [D320] |
443 0x40 ;; v-blank-prev [D31E] | 421 |
444 | 422 0x2F ;; invert A |
445 0xFA ;; load modes into A [D31F] | 423 0x47 ;; A -> B |
424 | |
425 0xF0 ;; copy STAT into A | |
446 0x41 | 426 0x41 |
447 0xFF | 427 |
448 | 428 0xCB ;; swap A nybbles; now A_0 is (VB==1). |
449 0x47 ;; A -> B | 429 0x37 |
450 0xCB ;; rotate A | 430 |
451 0x2F | 431 0xF5 ;; push AF (vbprev) |
452 0x2F ;; invert A | 432 |
453 | 433 0xA0 ;; A & B --> A. Now A_0 contains "increment?" |
454 0xA0 | 434 |
455 0x47 ;; now B_0 contains (VB==1) | 435 0xCB ;; test A_0. this result will be used twice. |
456 | 436 0x47 |
457 0xFA ;; load v-blank-prev | 437 0x28 ;; end frame (JUMP) if A_0 = 0. |
458 0x1E | 438 0x00 ;; TODO: set jump length |
459 0xD3 | |
460 | |
461 0x2F ;; complement v-blank-prev | |
462 | |
463 0xA0 ;; A & B --> A | |
464 0x4F ;; now C_0 contains increment? | |
465 | |
466 | |
467 0x78 ;; B->A | |
468 0xEA ;; spit A --> vbprev | |
469 0x1E | |
470 0xD3 | |
471 | |
472 0xCB ;test C_0 | |
473 0x41 | |
474 0x20 ; JUMP ahead to button input if nonzero | |
475 0x02 | |
476 0x18 ; JUMP back to frame metronome (D31F) | |
477 0xE7 | |
478 | 439 |
479 ;; -------- GET BUTTON INPUT | 440 ;; -------- GET BUTTON INPUT |
480 | 441 |
481 ;; btw, C_0 is now 1 | 442 ;; btw, Z bit is now 1 |
482 ;; prepare to select bits | 443 ;; prepare to select bits |
483 | |
484 0x06 ;; load 0x00 into B | |
485 0x00 ;; to initialize for "OR" loop | |
486 | 444 |
487 0x3E ;; load 0x20 into A, to measure dpad | 445 0x3E ;; load 0x20 into A, to measure dpad |
488 0x20 | 446 0x20 |
489 | 447 |
490 | 448 0x06 ;; load 0x00 into B |
449 0x00 ;; to initialize for "OR" loop | |
450 | |
491 0xE0 ;; load A into [FF00] ;; start of OR loop [D33C] | 451 0xE0 ;; load A into [FF00] ;; start of OR loop [D33C] |
492 0x00 | 452 0x00 |
493 | 453 |
494 0xF0 ;; load A from [FF00] | 454 0xF0 ;; load A from [FF00] |
495 0x00 | 455 0x00 |
496 | 456 |
497 0xE6 ;; bitmask 00001111 | 457 0xE6 ;; bitmask 00001111 |
498 0x0F | 458 0x0F |
499 | 459 |
500 0xB0 ;; A or B --> A | 460 0xB0 ;; A or B --> A |
501 0xCB | 461 |
502 0x41 ;; test bit 0 of C | 462 0x28 ;; JUMP forward if Z=0 |
503 0x28 ;; JUMP forward if 0 | |
504 0x08 | 463 0x08 |
505 | 464 |
506 0x47 ;; A -> B | 465 0x47 ;; A -> B |
507 0xCB ;; swap B nybbles | 466 0xCB ;; swap B nybbles |
508 0x30 | 467 0x30 |
509 0x0C ;; increment C | 468 |
510 0x3E ;; load 0x10 into A, to measure btns | 469 0x3E ;; load 0x10 into A, to measure btns |
511 0x10 | 470 0x10 |
471 | |
472 0xBF ;; compare(A,A) sets Z=0 | |
473 | |
512 0x18 ;; JUMP back to "load A into [FF00]" [20 steps?] | 474 0x18 ;; JUMP back to "load A into [FF00]" [20 steps?] |
513 0xED | 475 0xED |
514 | 476 |
515 | 477 |
516 ;; ------ TAKE ACTION BASED ON USER INPUT | 478 ;; ------ TAKE ACTION BASED ON USER INPUT |
534 | 496 |
535 ;; now A contains the pressed keys | 497 ;; now A contains the pressed keys |
536 0x2F ; complement A, by request. [D34F] | 498 0x2F ; complement A, by request. [D34F] |
537 | 499 |
538 0x47 ; A->B ;; now B contains the pressed keys | 500 0x47 ; A->B ;; now B contains the pressed keys |
539 0x7B ; E->A ;; now A contains the count. | |
540 | 501 |
541 0xCB ; test bit 5 of D (are we in o/p mode?) | 502 0xCB ; test bit 5 of D (are we in o/p mode?) |
542 0x6A | 503 0x6A |
543 0x28 ; if test == 0, skip this o/p section | 504 0x28 ; if test == 0, skip this o/p section |
544 0x13 ; JUMP | 505 0x13 ; JUMP |
550 | 511 |
551 ;; output mode I: moving the program counter | 512 ;; output mode I: moving the program counter |
552 0xE9 ; ** move PC to (HL) | 513 0xE9 ; ** move PC to (HL) |
553 | 514 |
554 ;; output mode II: writing bytes | 515 ;; output mode II: writing bytes |
555 0xFE ; A compare 0. finished writing? | 516 0xAF ; zero A |
556 0x00 | 517 0xBB ; compare count to zero. finished writing? |
557 0x20 ; if we are not finished, skip cleanup | 518 0x28 ; if we are finished, jump back to cleanup |
558 0x04 ; JUMP | 519 0x00 ; TODO: set jump length backwards. |
559 | |
560 ;; CLEANUP | |
561 ;; btw, A is already zero. | |
562 0xAF ; zero A [D35F] | |
563 0x57 ; A->D; makes D=0. | |
564 0x18 ; end of frame | |
565 0xBC | |
566 | |
567 ;; ---- end of cleanup | |
568 | |
569 | 520 |
570 ;; continue writing bytes | 521 ;; continue writing bytes |
571 0x1D ;; decrement E, the number of bytes to write [D363] | 522 0x78 ;; B->A |
572 0x78 ;; B->A; now A contains the pressed keys | 523 0x22 ;; copy A to (HL) and increment HL. |
573 0x77 ;; copy A to (HL) | |
574 0x23 ;; increment HL | |
575 0x18 ;; end frame. [goto D31F] | 524 0x18 ;; end frame. [goto D31F] |
576 0xB6 ;; TODO: set skip length backwards | 525 0xB6 ;; JUMP |
577 | 526 |
578 | 527 |
579 ;; ---- end of o/p section | 528 ;; ---- end of o/p section |
580 | 529 |
581 ;; i/p mode | 530 ;; i/p mode |
597 0x78 ;; B->A; now A contains the pressed keys | 546 0x78 ;; B->A; now A contains the pressed keys |
598 | 547 |
599 0x00 ;; var: thing to execute [D374] | 548 0x00 ;; var: thing to execute [D374] |
600 | 549 |
601 0x18 ;; end frame | 550 0x18 ;; end frame |
602 0xA8 | 551 0xA8 ;; JUMP |
603 ] | 552 ] |
604 ) | 553 ) |
605 | 554 |
606 (defn write-mem-dyl [] | 555 (defn write-mem-dyl [] |
607 (-> (tick (mid-game)) | 556 (-> (tick (mid-game)) |