Advertisement
rimsky82

Tetris Piece Generation

Nov 11th, 2019
1,570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Tetris NES
  2.  
  3. Almost completely random, except for a single dupe check.  If the normal logic pulls a duplicate piece, a second logic chooses another after manipulating rng.  There is no second check for a duplicate, so they obviously still happen.  Just not as often.
  4.  
  5.  
  6. 00:9907:E6 1A     INC $001A = #$02                      ; increase piece counter
  7. 00:9909:A5 17     LDA $0017 = #$FA                      ; Load value from rng
  8. 00:990B:18        CLC
  9. 00:990C:65 1A     ADC $001A = #$02                      ; Add piece counter to rng value (more randomness?)
  10. 00:990E:29 07     AND #$07                              ; AND with 7 (0-6 are pieces)
  11. 00:9910:C9 07     CMP #$07                              ; if 7,
  12. 00:9912:F0 08     BEQ $991C                             ; goto $991C
  13.  
  14. 00:9914:AA        TAX                                   ; Copy our piece to X register
  15. 00:9915:BD 4E 99  LDA $994E,X @ $9958 = #$02            ; Load A with our piece's PieceID for correct orientation
  16. 00:9918:C5 19     CMP $0019 = #$0E                      ; Compare with the last piece we had
  17. 00:991A:D0 1C     BNE $9938                             ; If different, goto $9938 (Done)
  18.  
  19. 00:991C:A2 17     LDX #$17                              ; We landed here on a 7 or a duplicate
  20. 00:991E:A0 02     LDY #$02
  21. 00:9920:20 47 AB  JSR $AB47
  22.  
  23. This subroutine manipulates RNG to pull a different value by rotating the bits right of each rng byte.
  24. Not sure what it is doing to the carry flag.
  25.  
  26. 00:AB47:B5 00     LDA $00,X @ $0017 = #$AC
  27. 00:AB49:29 02     AND #$02
  28. 00:AB4B:85 00     STA $0000 = #$8E
  29. 00:AB4D:B5 01     LDA $01,X @ $0018 = #$EF
  30. 00:AB4F:29 02     AND #$02
  31. 00:AB51:45 00     EOR $0000 = #$8E
  32. 00:AB53:18        CLC
  33. 00:AB54:F0 01     BEQ $AB57
  34. 00:AB56:38        SEC
  35. 00:AB57:76 00     ROR $00,X @ $0017 = #$AC
  36. 00:AB59:E8        INX
  37. 00:AB5A:88        DEY
  38. 00:AB5B:D0 FA     BNE $AB57
  39. 00:AB5D:60        RTS -----------------------------------------
  40.  
  41. 00:9923:A5 17     LDA $0017 = #$FA                      ; Reload from manipulated rng
  42. 00:9925:29 07     AND #$07                              ; AND with 7 again
  43. 00:9927:18        CLC
  44. 00:9928:65 19     ADC $0019 = #$0E                      ; Add piece counter
  45.  
  46. 00:992A:C9 07     CMP #$07                              ; If less than 7,
  47. 00:992C:90 06     BCC $9934                             ; goto $9934, we're done
  48.  
  49. 00:992E:38        SEC                                   ; If 7 or more,
  50. 00:992F:E9 07     SBC #$07                              ; Subtract 7
  51. 00:9931:4C 2A 99  JMP $992A                             ; goto check again, loop until we have < 7
  52.  
  53. 00:9934:AA        TAX                                   ; Copy our piece to X register
  54. 00:9935:BD 4E 99  LDA $994E,X @ $9958 = #$02            ; Load A with our piece's PieceID for correct orientation
  55.  
  56. 00:9938:85 19     STA $0019 = #$0E                      ; Our piece is chosen, store it in NEXT
  57. 00:993A:60        RTS -----------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement