So reveal Numero Uno just got released for the badge: Game System Emulation. There was good thought behind this too. As much as we love making games, its a different kind of challenge. That's logic and procedural coding, which is fun. But hacking hardware, learning, sticking your hand right up there and grabbing it by the OPCODEs and making some obsolete processor your bitch? Yeah, that's what its all about.
But this served a variety of purposes.
One: Should we spend hours on hours coding, debugging, debugging, debugging, debugging, compiling, running, debugging 5-6 games? Or put that effort into creating emulators for systems which have a strong community backing and rich retro history? The latter obviously. Then you get to play all the awesome homebrew public domain games out there.
Another important reason, the theme of DEFCON 25. Its retro and throwback to early hacking years. Don't believe me? What better games to include than 8-bit blocky, time sensitive, thumb smashing ROMs that give us so many pleasant member berries. Check out the DC25 retro awesome artwork thus far to put you in the mood:
And most importantly, the reason we chose the emulator we did, was for you hackers out there. Stackoverflow did a study in February about what coding languages are most looked up on weekdays and weekends. During the week, its the bleh... Sharepoint, VBA, stuff. But on the weekend...Assembly! Woot! So you DO love hardware.
This is where it gets good. No, GREAT. We want to teach you how to fish. Not give you a fish, but point you to the pond, give you some pointers, and if you feel up to it and want to code a game in CHIP8 or SCHIP, we will GLADLY throw it on the badge (I trailed off on the fishing reference, but you get it) There's no point in us re-writing CHIP8 tutorials when there are hundreds of them out there, but we will lead you in the right direction and provide guidance so we can easily integrate it . The best part, there are tons of emulators that run on your Linux, PC, Mac, Android, iOS already. So you can write and test an application without even having the badge yet.
Step 0 - History Lesson
Before you go making a game for a system, learn about it. Most of the documented knowledge on the web about CHIP8 and SCHIP stems from David Winter. It has the history, technical, screen shots, etc. You owe David Winter this if you wish to proceed. He has a beautiful website, I wouldn't change anything.
STEP 1 - Play Some Games
Get a feel for the system. Have some 8-bit fun. Look at whats already out there and think about how or what you could add to the community. And you are in for a surprise because the pad layout was a 16 key Hex set.
STEP 2 - Learn the OPCODES & Technical Specifications
Dont get scared now, this is where it gets fun. There's only 35 OPCODEs!
(especially pay attention to Matthew Mikolay's details on the PROPER use of 8XYN OPCODES, most people do SHR and SHL wrong. In the vein of hacker jeopardy - DONT F*CK IT UP)
STEP 3 - Get The CHIPPER Assembler & Some Source to Practice
Back to David Winter's page, at the bottom is a download link with the games, assembler, and documentation. Don't fret, there is an .exe and .c file in the CHIPPER directory.. Throw away the .exe, all the best hacking is done under linux anyway.
Once you have a test ASM file, the syntax is pretty easy but first you need to compile CHIPPER.
gcc chipper.c -o chipper
Then grab an assembly ASM file and execute with the following pattern:
## Assembling ROM
./chipper output_file.rom input_assembly_file.asm
Grab your favorite CHIP8 or SCHIP emulator and play that ROM!!!
Also if you just want to try messing around in a browser based environment, try this:
Main Project: https://github.com/adrianton3/chip8
So at this point, you should be frothing at the mouth to fire up your favorite text editor and start cranking out some assembly :) But first, you need to know the intricacies of our badge.
We also just found a dude who rolled an Android Based CHIP8 IDE with his own pseudo-BASIC language. This is different than the normal assembly that folks use. A lot of it has been abstracted with BASIC style coding, but there is still some assembly-ish register pushing. Take with a grain of salt, because the fact that its a higher level language means you lose efficiency in coding. We haven't mentioned yet, that a CHIP8 ROM is limited to 4096 bytes!!! So if you plan on making an intricate game, stick with assembly. But it doesnt hurt to try out the IDE and see where you can take it.
There's also a project over on GitHub for a desktop CHIP8/SCHIP IDE with full debugger available. You can download and compile yourself, he also has put together excellent documentation and precompiled executables for Linux, OSX, and Windows.
Here's an example of what I'm talking about:
CHIP8 Assembly Example
//CHIP8 Assembly Example //CHIP8 has all HEX characters pre-stored as sprites LD ST, V1 LD V1, #0D //prestored sprite for D char LD V2, #0C //prestored sprite for C char LD V3, #02 //prestored sprite for 2 char LD V4, #05 //prestored sprite for 5 char LD V5, 32 //starting X coordinate LD V6, 16 //starting Y coordinate ; Draw D LD F, V1 //load the sprite DRW V5, V6, 5 //draw the sprite ADD V5, 5 //move 5 pixels to the right ; Draw C LD F, V2 DRW V5, V6, 5 ADD V5, 5 ; Draw 2 LD F, V3 DRW V5, V6, 5 ADD V5, 5 ; Draw 5 LD F, V4 DRW V5, V6, 5 ADD V5, 5
Android CHIP8IDE BASIC Example
//CHIP8IDE BASIC Example //CHIP8 has all HEX characters pre-stored as sprites //print them by calling char(HEX#, Xcor, Ycor); char(13,0,0); //print D char(12,5,0); //print C char(2,10,0); //print 2 char(5,15,0); //print 5
STEP 4 - Integrating To Our Badge
There are some limitations to what we are going to support.
1) We have only 5 buttons on the badge, CHIP8/SCHIP has 16 buttons.
Above you see a PC keyboard layout on the left used by most emulators, and a CHIP8 keypad on the right. Thats why we only have 64 games included. Now most of these games only used less than 4-5 keys. However there was no standardization among the community as to what common actions should be mapped for the keys. For example, some games like AstroDodge used the 2 key for UP. However, Blinky used the 3 key for up. They both move up dammit! So what we did was play every game and created a mapping file (poor Hyr0n had to drink beer all day and play every CHIP8 and SCHIP game ever made), script, and auto-generate a config file for each game so we know "functionally" how the game works and can map the buttons properly. If games used more than the number of keys we allowed, we dropped it. Yeah we could have put 16 buttons on the badge, but then we'd lose precious GPIO which we need for other functions. Regardless you got at least 64 games to play at the con, unless of course, some of you dedicated assembly hackers want to try and add to the CHIP8/SCHIP community !
Now here is where it gets interesting. SCHIP has the similar layout, just different special characters and a different order. They flip the order of the numbers and use symbols. Why??? Because SCHIP primarily was played on HP48 Calculators, its a calculator pad layout.
Dont get scared now. Here's where it gets easy. Use WHATEVER damn keys you want, just no more than 5 of them. Because we have a config file layout which you will have to populate and send with the ROM. Its ASCII Text, we parse it (yeah parses are evil and a bane of security, but it was quick and dirty and worked) and tell our emulator to map a badge button to whatever key is being used for your system.
As you can see the (U)p badge button is mapped to CHIP8 key 3, (D)own to CHIP8 key 6, (A)ction button is CHIP8 key "f" and so on.CLOCK is a variable we use for timing correction, default 300Hz and we'll play and tune it from there. NOTE is the description we display for the game before it loads; It must be < 200 chars and terminate with EOF
2) That was a long explanation for the first limitation, you forgot there was another one: Sound
We don't have a speaker on the badge, but that's okay. Casinos are so damn noisy you wont hear any sound anyway. That's why we've mapped the sound to the badge LEDs. So you can use sound, you wont hear anything, but the blinking is much more satisfying anyway.
3) File name must be an 8.3 length, ending with .ch8 or .sc
Not much to explain beyond that. That's how file systems were way back when. If I MUST give an example... "helloWrd.ch8"
STEP 5 - Booze
You should celebrate at this point. Actually you should have been drinking the finest craft beer you can find during this coding endeavor, good beer means good hacking.
Oh by the way, here's the list of the 64 games we want to include (possibly m0@r):
|CHIP8||Connect 4 (2P)|
|CHIP8||Pong II (2P)|
|SCHIP||Single Dragon 1|
|SCHIP||Single Dragon 2|