Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 01234567890123456789012345678901234567890123456789012345678901234567890123456789
- http://12me21.github.io/sbhighlight3/#../DIFIE.txt
- This is the code I wrote for chip-8 tetris. It's designed to be read by my
- interpreter, written in SmileBASIC.
- A few things to explain about SmileBASIC:
- ' starts a comment
- &H and &B are the hexadecimal and binary prefixes
- DATA stores values that can be read with RESTORE/READ/COPY
- Labels (for GOTO, DATA, etc.) are prefixed with @
- In an expression, @LABEL is a string, equvilant to "@LABEL"
- My addresser:
- Normal (positive) data values are read directly as instructions
- Negative numbers have special meanings:
- -1 : end of program
- -2,label : define label
- -3,instruction,label : instruction with address.
- -4,instruction,label : instruction with address, offset by 1 byte.
- Comments:
- Most of the lines are commented in my own variant of chip-8 assembly. I
- probably forgot to update some of the comments so they might not match
- the actual instruction.
- The Program:
- While making a chip-8 interpreter, I was reading the code of some existing
- games, and tetris had a lot of flaws (It relied on the interpreter running at a
- specific speed rather than using the delay timer for everything, and was
- generally very slow).
- Around this time I found out about the chip-8 contest (octojam 4), so it was
- the perfect time to make something in chip-8.
- I designed tetris to be as small as possible (without sacrificing
- gameplay, of course). It would probably run a bit faster if I put some
- subroutines inline, but the main speed limitation is the sprite drawing, not
- the code, anyway. The entire game is around 730 bytes, and 180 of those are data while the rest is code.
- One of the lesser-known and VERY important restrictions on the original Cosmac
- VIP interpreter is that you can only draw 1 sprite per frame. This means that
- limiting sprite draws is the biggest thing you can do to improve speed. For
- 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
- blocks wide, so you have to use 2 sprites).
- Originally I was going to write the entire thing by hand, but around halfway
- through I got really tired of having to update all the addresses every time I
- added something (Some of the comments still have my addresses in them like
- '48A LD v1,1B). I designed a system to automatically calculate addresses which
- made everything a lot easier. By the time I was finished, I had memorized many
- of the instructions, though by now I've probably forgotten most of them.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement