Created
February 28, 2013 00:13
-
-
Save blondie7575/5053109 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mainloop: | |
| // Wait for VBL to process commands | |
| sbrs VBL,2 // Bit 2 of VBL register is our rendering window | |
| rjmp mainloop | |
| // Poll the FIFO to see if there's a command pending | |
| in accum,PINB | |
| sbrs accum,fifoReady | |
| rjmp mainloop | |
| // Set up Port D as an input | |
| ldi accum,0x00 | |
| out DDRD,accum | |
| ldi accum,0xff | |
| clr accum | |
| out PORTD,accum | |
| nop // Make sure PORTD has changed direction | |
| // Read from the FIFO | |
| sbi PORTB,vramOE // Kick VRAM off the bus so we can read the FIFO | |
| cbi PORTB,fifoRead | |
| nop // Allow for FIFO data setup time | |
| sbi PORTB,fifoRead | |
| in regS,PIND | |
| cbi PORTB,vramOE // Give bus back to VRAM | |
| // See if this is a new command, or completing a previous two-byte packet | |
| lds accum,CMDBUFFER | |
| cpi accum,0 | |
| brne mainHaveParamByte | |
| sts CMDBUFFER,regS | |
| rjmp mainloop | |
| mainHaveParamByte: | |
| sts CMDPARAM,regS | |
| lds regT,CMDBUFFER | |
| clr accum | |
| sts CMDBUFFER,accum | |
| cpi regT,NUM_COMMANDS | |
| brge mainloop // Illegal command, ignore it | |
| // Bounce off a jump table based on command value | |
| lsl regT | |
| ldi XL,lo8(pm(renderJumpTable)) | |
| ldi XH,hi8(pm(renderJumpTable)) | |
| clr accum | |
| add XL,regT | |
| adc XH,accum | |
| push XL // Using ret, trick AVR into jumping to an indirect address | |
| push XH | |
| ret // Note that we're not using ijmp, because we can't use Z | |
| renderJumpTable: | |
| nop | |
| rjmp mainloop | |
| rcall renderFillScreen | |
| rjmp mainloop | |
| rcall renderPlotChar | |
| rjmp mainloop | |
| rcall renderPlotStr | |
| rjmp mainloop | |
| rcall renderFontColor | |
| rjmp mainloop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment