Advertisement
12Me21

chip 8 tetris

Mar 22nd, 2018
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. 01234567890123456789012345678901234567890123456789012345678901234567890123456789
  2.  
  3. http://12me21.github.io/sbhighlight3/#../DIFIE.txt
  4.  
  5. This is the code I wrote for chip-8 tetris. It's designed to be read by my
  6. interpreter, written in SmileBASIC.
  7.  
  8. A few things to explain about SmileBASIC:
  9.  
  10. ' starts a comment
  11. &H and &B are the hexadecimal and binary prefixes
  12. DATA stores values that can be read with RESTORE/READ/COPY
  13. Labels (for GOTO, DATA, etc.) are prefixed with @
  14. In an expression, @LABEL is a string, equvilant to "@LABEL"
  15.  
  16.  
  17. My addresser:
  18.  
  19. Normal (positive) data values are read directly as instructions
  20. Negative numbers have special meanings:
  21. -1 : end of program
  22. -2,label : define label
  23. -3,instruction,label : instruction with address.
  24. -4,instruction,label : instruction with address, offset by 1 byte.
  25.  
  26. Comments:
  27.  
  28. Most of the lines are commented in my own variant of chip-8 assembly. I
  29. probably forgot to update some of the comments so they might not match
  30. the actual instruction.
  31.  
  32.  
  33. The Program:
  34.  
  35. While making a chip-8 interpreter, I was reading the code of some existing
  36. games, and tetris had a lot of flaws (It relied on the interpreter running at a
  37. specific speed rather than using the delay timer for everything, and was
  38. generally very slow).
  39.  
  40. Around this time I found out about the chip-8 contest (octojam 4), so it was
  41. the perfect time to make something in chip-8.
  42.  
  43. I designed tetris to be as small as possible (without sacrificing
  44. gameplay, of course). It would probably run a bit faster if I put some
  45. subroutines inline, but the main speed limitation is the sprite drawing, not
  46. the code, anyway. The entire game is around 730 bytes, and 180 of those are data while the rest is code.
  47.  
  48. One of the lesser-known and VERY important restrictions on the original Cosmac
  49. VIP interpreter is that you can only draw 1 sprite per frame. This means that
  50. limiting sprite draws is the biggest thing you can do to improve speed. For
  51. example, rather than doing 10 or 20 sprite draws to check if a row is filled, you only need to do either 2 or 4 by checking 5 pixels at once (Tetris is 10
  52. blocks wide, so you have to use 2 sprites).
  53.  
  54. Originally I was going to write the entire thing by hand, but around halfway
  55. through I got really tired of having to update all the addresses every time I
  56. added something (Some of the comments still have my addresses in them like
  57. '48A LD v1,1B). I designed a system to automatically calculate addresses which
  58. made everything a lot easier. By the time I was finished, I had memorized many
  59. of the instructions, though by now I've probably forgotten most of them.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement