Download presentation
Presentation is loading. Please wait.
1
EE 319K Introduction to Embedded Systems
2-D Arrays, Bitmaps, Sprites, Game Engines
2
Agenda Agenda Software design 2-D array Bitmaps Wav Files Game Engines
Lab 9
3
Software Design Modular programming Make it easier to understand
Each screen is a complete story without scrolling Maximize the number of modules Minimize the interdependency Bandwidth of data passed from one to another Control coupling: actions in one cause effects in another Shared variables (very bad) Book Section 5.2
4
Software Design Design for test Manage resources
Consider how it will be tested while designing Module has three files Header: What the module does Code: How it works Test: A main program used to test the module Manage resources LCD graphics Time (processor cycles) A fun game requires careful control of time Input/Output Switches, slide pot, DAC, LCD
5
2-D Array or Matrix What: 2 rows and 3 columns, 8 bits each Why:
unsigned char M[2][3]; Why: Images Maps How: (C uses row major) C code to access M[i][j] = 5; Write this in assembly (R0=i, R1=j) i = row j = column n= # of columns Base+n*i+j Base+2*(n*i+j) Base+4*(n*i+j) Num of bytes/element
6
2-D Array or Matrix j i Base+2*(7*i+j) What: 6 rows and 7 columns Why:
short Connect4[6][7]; Why: Images Maps How: (row major) Write C code to set array values to 0 i Base+2*(7*i+j)
7
2-D Array or Matrix j i Assuming C[6][7] // check the rows
for(i=0;i<6;i++){ for(j=0;j<4;j++){ if((C[i][j]==1) &&(C[i][j+1]==1) &&(C[i][j+2]==1) &&(C[i][j+3]==1)){ Iwin(); } i 0 means free 1 means me -1 means you
8
Nokia 5110 Graphics Format Column 0 Row 0 Row 48
LCD is 48 rows, 84 columns, 1 bits/pixel Column 84
9
BMP File Format Sprites as objects moving across screen
Sprites are monochrome W pixels wide by H pixels high
10
BMP File Format 16 wide, 10 high Placed at x=48, y=24 F F F F
Nokia5110_PrintBMP(48,24,SmallEnemy10pointA,0); 16 wide, 10 high Placed at x=48, y=24 F F F F FFFFFFFFFF FFFFFFFFFFFF FFF FFFF FFF F FFFFFFFF F F F F F The raw data from BMP file to illustrate how the image is stored (0s replaced with spaces).
11
BMP File Format Example BMP file written as C constant Header (w x h)
const unsigned char Enemy10Point1[] = { 0x42,0x4D,0xC6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x00,0x00,0x00,0x28,0x00, 0x00,0x00,0x10,0x00,0x00,0x00,0x0A,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x00,0x00, 0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x80, 0x00,0x00,0x00,0x80,0x80,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x80, 0x00,0x00,0x80,0x80,0x80,0x00,0xC0,0xC0,0xC0,0x00,0x00,0x00,0xFF,0x00,0x00,0xFF, 0x00,0x00,0x00,0xFF,0xFF,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF,0xFF,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x0F,0x00,0x00,0x00,0x00,0xF0,0x00, 0x00,0x00,0xF0,0x00,0x00,0x0F,0x00,0x00, 0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xF0,0x00, 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00, 0x00,0xFF,0xF0,0xFF,0xFF,0x0F,0xFF,0x00, 0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0x0F,0x00, 0x00,0xF0,0x0F,0x00,0x00,0xF0,0x0F,0x00, 0xFF }; Example BMP file written as C constant Header (w x h) Pixel data We use 4-bit BMP but all values above a threshold are deemed 1 for monochrome.
12
BMP Header Format
13
Timer 2A Periodic interrupt
Resolution: bus period Precision: 32 bits Max period: 53 sec (80 MHz) 0) activate timer2 clock 1) disable timer2A 2) Precision to 32 bits 3) periodic mode 4) TAILR value 5) clock resolution 6) clear timeout flag 7) arm timeout 8) priority 4 9) enable in NVIC 10) enable timer2A
14
77 total INTERRUPT VECTORS Lab 7 Lab 8 Lab 9 Vector address Number IRQ
ISR name in Startup.s NVIC Priority bits 0x 14 -2 PendSV_Handler NVIC_SYS_PRI3_R 23 – 21 0x C 15 -1 SysTick_Handler 31 – 29 0x 16 GPIOPortA_Handler NVIC_PRI0_R 7 – 5 0x 17 1 GPIOPortB_Handler 15 – 13 0x 18 2 GPIOPortC_Handler 0x C 19 3 GPIOPortD_Handler 0x 20 4 GPIOPortE_Handler NVIC_PRI1_R 0x 21 5 UART0_Handler 0x 22 6 UART1_Handler 0x C 23 7 SSI0_Handler 0x 24 8 I2C0_Handler NVIC_PRI2_R 0x 25 9 PWMFault_Handler 0x 26 10 PWM0_Handler 0x C 27 11 PWM1_Handler 0x 28 12 PWM2_Handler NVIC_PRI3_R 0x 29 13 Quadrature0_Handler 0x 30 ADC0_Handler 0x C 31 ADC1_Handler 0x 32 ADC2_Handler NVIC_PRI4_R 0x 33 ADC3_Handler 0x 34 WDT_Handler 0x C 35 Timer0A_Handler 0x 36 Timer0B_Handler NVIC_PRI5_R 0x 37 Timer1A_Handler 0x 38 Timer1B_Handler 0x C 39 Timer2A_Handler 0x000000A0 40 Timer2B_Handler NVIC_PRI6_R 0x000000A4 41 Comp0_Handler 0x000000A8 42 Comp1_Handler 0x000000AC 43 Comp2_Handler 0x000000B0 44 SysCtl_Handler NVIC_PRI7_R 0x000000B4 45 FlashCtl_Handler 0x000000B8 46 GPIOPortF_Handler 0x000000BC 47 GPIOPortG_Handler 0x000000C0 48 GPIOPortH_Handler NVIC_PRI8_R 0x000000C4 49 UART2_Handler 0x000000C8 50 SSI1_Handler 0x000000CC 51 Timer3A_Handler 0x000000D0 52 Timer3B_Handler NVIC_PRI9_R 0x000000D4 53 I2C1_Handler 0x000000D8 54 Quadrature1_Handler 0x000000DC 55 CAN0_Handler 0x000000E0 56 CAN1_Handler NVIC_PRI10_R 0x000000E4 57 CAN2_Handler 0x000000E8 58 Ethernet_Handler 0x000000EC 59 Hibernate_Handler 0x000000F0 60 USB0_Handler NVIC_PRI11_R 0x000000F4 61 PWM3_Handler 0x000000F8 62 uDMA_Handler 0x000000FC 63 uDMA_Error Lab 7 Lab 8 Lab 9 77 total INTERRUPT VECTORS
15
Timer 2A Periodic interrupt
Max is 53 sec unsigned long TimerCount; void Timer2_Init(unsigned long period){ unsigned long volatile delay; SYSCTL_RCGCTIMER_R |= 0x04; // 0) activate timer2 delay = SYSCTL_RCGCTIMER_R; TimerCount = 0; TIMER2_CTL_R = 0x ; // 1) disable timer2A TIMER2_CFG_R = 0x ; // 2) 32-bit mode TIMER2_TAMR_R = 0x ; // 3) periodic mode TIMER2_TAILR_R = period-1; // 4) reload value TIMER2_TAPR_R = 0; // 5) clock resolution TIMER2_ICR_R = 0x ; // 6) clear timeout flag TIMER2_IMR_R = 0x ; // 7) arm timeout NVIC_PRI5_R = (NVIC_PRI5_R&0x00FFFFFF)|0x ; // 8) priority 4 NVIC_EN0_R = 1<<23; // 9) enable IRQ 23 in TIMER2_CTL_R = 0x ; // 10) enable timer2A } Output sound at kHz
16
Timer 2A plays sounds TATORIS Ack Output sounds here Stuff
// trigger is Timer2A Time-Out Interrupt // set periodically TATORIS set on rollover void Timer2A_Handler(void){ TIMER2_ICR_R = 0x ; // acknowledge TimerCount++; // run some background stuff here } void Timer2A_Stop(void){ TIMER2_CTL_R &= ~0x ; // disable void Timer2A_Start(void){ TIMER2_CTL_R |= 0x ; // enable TATORIS Ack Output sounds here Stuff Call to stop sound Call to start sound
17
Lab9 – Space Invaders, Pipe Dreams …
There must be at least one button and one slide pot. There must be at least three images on the LCD display that move. There must be sounds appropriate for the game. The score should be displayed on the screen (but it could be displayed before or after the game action). At least two interrupt ISRs must used in an appropriate manner. The game must have a “time” aspect to it (For e.g., if you don’t move a sprite within a certain time it could be killed). Contrast with ConnectFour which is a taking “turns” game The game must be both simple to learn and fun to play.
18
Lab 9 – Grading The TA will certify your game and put you into one of two groups. Group A or B Lab 9 will be graded subjectively by other students During class we will setup two groups of stations each One team member demonstrates The other team member scores other 7 games in group Games are rank-ordered according to level of fun. Score is based on rank in group. 80 if 0th to 49th percentile 90 if 50th to 74th percentile 100 if 75th to 100th percentile
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.