oPossum 1,083 Posted June 29, 2011 Share Posted June 29, 2011 15.7 ksps WOW! 16.6 ms sweep Amazing! Special limited time offer - only $4.30! Order now. Operators are standing by. .cdecls C, LIST, "msp430g2231.h" .text .global _main .bss sync_state, 2 .bss sync_lines, 2 .bss video_state, 2 .bss vid_line, 2 _main ; mov #WDTPW | WDTHOLD, &WDTCTL ; No watchdog ; mov #XT2OFF + 15, &BCSCTL1 ; DCO 16 Mhz mov #0x86, &DCOCTL ; ; mov #0x0280, SP ; Stack pointer ; mov.b #0xF0, &P1DIR ; I/O assignment mov.b #0x50, &P1SEL ; Enable Timer A output, SMCLK output clr.b &P1REN ; clr.b &P1OUT ; ; mov #0x0002, &ADC10AE0 ; Analog in on P1.1 (A1) mov #0x1000, &ADC10CTL1 ; Select A1 ; Configure ADC mov #ADC10SHT_0 | ADC10SR | ADC10ON | ENC, &ADC10CTL0 ; call #video_init ; Begin video ; jmp $ ; ; video_init ; --- Initialize Video Generation --- clr &sync_state ; Init state machine mov #1, sync_lines ; clr &video_state ; mov #1016, &TACCR0 ; Setup Timer A period for 63.5 us mov #75, &TACCR1 ; Setup Timer A compare for video sync mov #0x0210, &TACTL ; Timer A config: SMCLK, count up mov #0x0060, &TACCTL1 ; Setup Timer A set/reset output mode bis #0x0010, &TACCTL0 ; Enable PWM interupt eint ; Enable interupts ret ; ; video_isr ; --- Video ISR --- dec &sync_lines ; Decrement sync lines jne vid_state ; Skip sync if not zero... add &sync_state, PC ; Jump to sync handler... ; - Field 1/3 jmp vid_eq ; Pre Equalizing jmp vid_vsync ; Vertical Sync jmp vid_eq ; Post Equalizing jmp vid_vbi ; VBI jmp vid_active ; Active Video jmp vid_half ; Video half line ; - Field 2/4 jmp vid_eq ; Pre Equalizing jmp vid_vsync ; Vertical Sync jmp vid_eq ; Post Equalizing jmp vid_half ; Video half line jmp vid_vbi ; VBI jmp vid_active ; Active Video clr &sync_state ; Reset sync state ;jmp vid_eq ; Same as first state ; vid_eq ; Equalizing pulses - 6 half lines mov #508, &TACCR0 ; Half line mov #38, &TACCR1 ; Equalizing pulse duration mov #6, &sync_lines ; 6 half lines clr &video_state ; No video generation during sync incd &sync_state ; Next state reti ; ; vid_vsync ; Vertical sync - 6 half lines mov #508 - 75, &TACCR1 ; Sync pulse duration mov #6, &sync_lines ; 6 half lines incd &sync_state ; Next state reti ; ; vid_half ; Video half line - 1 half line mov #508, &TACCR0 ; Half line mov #75, &TACCR1 ; Sync pulse duration mov #1, &sync_lines ; 1 half line incd &sync_state ; Next state clr &video_state ; No video generation during half line and sync reti ; ; vid_vbi ; Vertical blanking interval - 11 lines mov #1016, &TACCR0 ; Full line mov #75, &TACCR1 ; Sync pulse duration mov #11, &sync_lines ; 11 lines incd &sync_state ; Next state reti ; ; vid_active ; Active video - 242 lines mov #242, &sync_lines ; 242 lines incd &sync_state ; Next state mov #2, &video_state ; Generate video clr &vid_line ; Clear video line count jmp vid_field ; Generate video... ; vid_blank_9 ; 9 blank lines mov #9, &sync_lines ; incd &sync_state ; clr &video_state ; reti ; ; vid_state ; -- Active Video Generation add &video_state, PC ; reti ; No active video ;jmp vid_field ; Field ; vid_field ; push R12 ; ; mov &TAR, R12 ; cmp #160, R12 ; jlo $ - 8 ; and #7, R12 ; rla R12 ; add R12, PC ; nop ; nop ; nop ; nop ; nop ; nop ; nop ; ; mov &ADC10MEM, R12 ; Get ADC results bis #ADC10SC, &ADC10CTL0 ; Start new conversion ; cmp #750, R12 ; Limit upper ADC value jlo inrange ; mov #750 - 2, R12 ; ; inrange sub #4, R12 ; Subtract four w/ four cycles per iteration nop ; jc $ - 4 ; inv R12 ; Negate the remainder rla R12 ; Multiply by two add R12, PC ; One cycle granularity computed jump nop ; nop ; nop ; ; bis.b #0x80, &P1OUT ; bic.b #0x80, &P1OUT ; ; pop R12 ; ; reti ; ; ; Interrupt Vectors .sect ".reset" ; .short _main ; .sect ".int09" ; TACCR0 CCIFG .short video_isr ; ; .end ; Rickta59, RobG, zeke and 3 others 6 Quote Link to post Share on other sites
zeke 693 Posted June 30, 2011 Share Posted June 30, 2011 That's cool. I would be surprised to see you code up a SNES-like game pretty soon Does the 16MHz DCO limit you very much? What could you accomplish with a 24MHz DCO? Quote Link to post Share on other sites
zborgerd 62 Posted June 30, 2011 Share Posted June 30, 2011 Outstanding! Which assembler did you use? Quote Link to post Share on other sites
oPossum 1,083 Posted June 30, 2011 Author Share Posted June 30, 2011 I am using CCS. Higher clock allows use of sprites, fonts, overlays, and such. At lower frequencies everything has to be in a frame buffer or be very simple dynamic content. The small flash and RAM is much more limiting than the speed. Quote Link to post Share on other sites
Rickta59 589 Posted June 30, 2011 Share Posted June 30, 2011 Nice work! What are the chances of a VGA version of this. I have a couple of those that could be put to use but no extra TVs. -rick Quote Link to post Share on other sites
oPossum 1,083 Posted June 30, 2011 Author Share Posted June 30, 2011 Good project for you VGA is easier than NTSC. The sync is very simple. Set Timer A for ~31.5 kHz for hsync, and do vsync at ~60 Hz in the ISR. Quote Link to post Share on other sites
Mac 67 Posted June 30, 2011 Share Posted June 30, 2011 ... The small flash and RAM is much more limiting than the speed. I hear ya. While 2 kB on the '2231 might sound like a lot, it's really only 1 kWord. And if you can achieve an average of two words per instruction, then you're really only talking about 500 instructions. Yikes! BTW, thank you for all the great examples you've been posting. It's been an incredible education. Cheerful regards, Mike Quote Link to post Share on other sites
zeke 693 Posted June 30, 2011 Share Posted June 30, 2011 Yeah, I'm feeling inadequate now. :oops: My stuff is just simple stuff written in slow-pokey old C. :roll: I feel like I'm driving a rusty old 59 Cadillac and oPossum is taunting me while driving his pimped out Rice Rocket. Quote Link to post Share on other sites
zeke 693 Posted June 30, 2011 Share Posted June 30, 2011 Yeah, I'm feeling inadequate now. :oops: My stuff is just simple stuff written in slow-pokey old C. :roll: I feel like I'm driving a rusty old 59 Cadillac and oPossum is taunting me while driving his pimped out Rice Rocket. Quote Link to post Share on other sites
RobG 1,892 Posted June 30, 2011 Share Posted June 30, 2011 Remember zeke that you can write in C, take the resulting assembly, tweak it, and put it back in CCS. New engine for your old Caddy. Quote Link to post Share on other sites
zeke 693 Posted July 1, 2011 Share Posted July 1, 2011 Kinda like stuffing one of those leafblower turbos on that old Caddie, eh? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.