Lab 8: Fun and games - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Lab 8: Fun and games

Description:

425 Lab8:1 J Archibald. Lab 8: Fun and games. Consider the GameBoy: ... Optimization can get addicting; use wisdom, maintain balance in your life.... 425 Lab8:11 ... – PowerPoint PPT presentation

Number of Views:153
Avg rating:3.0/5.0
Slides: 12
Provided by: jka
Category:
Tags: addicting | fun | games | lab

less

Transcript and Presenter's Notes

Title: Lab 8: Fun and games


1
Lab 8 Fun and games
  • Consider the GameBoy
  • A non-trivial embedded, real-time system.
  • Must balance computation and timely event
    handling.
  • Probably rather fun to design, develop, test.
  • We wanted to do something similar for a lab.
  • Focus application software, not the RTOS.
  • But without the overhead of programming
    everything.
  • Lets consider how it works and what you do.

2
Conceptual model
  • Imagine you are given a handheld game to play
    tetris.
  • Instead of having a mechanical interface
    (buttons), the game has an electronic interface.
  • You build a 2nd embedded system to play the first.

Your application code runs here. It plays the
game by responding to interrupts for new pieces
and sending shift and rotate commands. It does
not have to manage display, make pieces fall,
handle line clears, etc.
input
output
LameBoyTM
3
Simptris
  • A simple version of tetris
  • Special mode in simulator
  • Type simptris to prompt
  • Special window created
  • Pieces consist of three blocks.
  • Only two possible shapes corners, straight
    pieces.
  • Board is small just 6 columns wide, 16 rows
    high.
  • Score is simply total lines cleared.
  • No bonus for clearing multiple lines at once.

4
Playing details
  • You receive interrupts when new pieces appear.
  • Location, type of piece can be read from global
    variables
  • You send commands to rotate or shift each piece
    by calling functions.
  • Cant send next command until prior command
    received.
  • Transmission delay is fixed, ultimately an
    unavoidable bottleneck.
  • Pieces fall faster until your code breaks. High
    score wins.
  • For full credit clear at least 200 lines at
    default tick frequency.

5
The interface
  • The interrupts your system receives
  • reset priority 0
  • tick priority 1
  • keypress priority 2
  • game over priority 3
  • new piece priority 4
  • received command priority 5
  • touchdown priority 6
  • line clear priority 7
  • Details are communicated via global variables
  • ID, column, orientation of new piece.
  • ID of piece that touched down.
  • Screen bitmaps of pieces that have touched down.

Emu86 interrupts
Simptris interrupts
6
Interface details
  • The control functions you can call (defined in
    simptris.s)
  • void Slide_Piece(int id, int direction) //
    1right, 0left
  • void Rotate_Piece(int id, int direction) //
    1Clkwise, 0CntClkwise
  • Other required functions
  • void Seed_Simptris(long seed) // random number
    seed
  • void Start_Simptris(void)
  • Dealing with transmission delay
  • You cant call Slide_Piece( ) or Rotate_Piece( )
    until command received interrupt received after
    sending last piece.
  • Interrupt indicates clear to send rather than
    last command completed okay.
  • Cant move piece into wall, for example.
  • Recommended encapsulate communication details
    within task.

7
The simulator
  • To the prompt, type simptris and game display
    will appear.
  • Normal text output from your code will appear in
    the program output window as before.
  • You get reset, keypress, and timer ticks as
    before.
  • Simptris interrupts are added in simptris mode.
  • You decide which you want to pay attention to.
  • Write required ISRs and handlers.
  • Modify interrupt vector table.
  • For interrupts you want to ignore cant modify
    IMR in simulator, so write empty ISRs.
  • Minimal contents Save ax, send EOI command,
    restore ax, iret

8
Lab requirements
  • Your application code must use your YAK kernel.
  • Your code must accurately report CPU utilization
    and context switches every 20 ticks.
  • Your code must clear 200 lines at default tick
    frequency for full credit.
  • You are free to use any seed you want to pass off
    lab.
  • You cannot change seed more than once per game.
  • Fairly straightforward placement algorithms are
    adequate if RTOS overhead is low not an exercise
    in AI unless you make it one.
  • Only Twinkies are at stake after youve cleared
    200 lines.

9
Suggested organization
  • Heres one way to do it others are possible
  • Create multiple tasks
  • One to handle new pieces and call placement
    functions
  • One to handle communication with Simptris
  • One to handle statistics
  • Use queue to communicate piece details from new
    piece ISR to placement task.
  • Use queue to communicate move details between
    placement task and communication task.
  • Use semaphore for clear-to-send ISR to signal
    communication task.
  • Do your own design, but use good design
    principles.

10
Placement algorithms
  • Very simple algorithm can clear 80 lines
  • Straight pieces on one side, corners on the
    other.
  • Slightly more complicated algorithms work much
    better. Example
  • Change sides when unbalanced.
  • Corner goes on corner side if not flat.
  • If flat, place pieces on closest side unless
    imbalance too great.
  • More complicated algorithms can be created
    screen bit maps can be very useful for this.
  • Key objective minimize average (or worst case?)
    number of moves required for any piece.
  • Remember, pushing the envelope is not required.
    Optimization can get addicting use wisdom,
    maintain balance in your life.

11
The friendly competition
  • We will jointly pick a seed.
  • Everyone will run their code on that seed.
  • Twinkies awarded for
  • Highest score with that seed
  • Lowest score above the minimum required (minimal
    energy award)
  • A variety of noteworthy kernel achievements
    based on HW9
  • For reference
  • Minimum required 200 lines
  • Maximum observed with current simulator 450
    lines.
  • Despite rumors to the contrary, my code does not
    always win.
Write a Comment
User Comments (0)
About PowerShow.com