Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    2
  • comments
    2
  • views
    2704

Blitting and Soldering

Sign in to follow this  
Segmented

772 views

Hello all. I promised myself I would post the progress on my game before starting to work on the PUTT contest, so here it goes =) When I came to the question of input for the raspberry pi, my first assumption was that the easiest method would be to use the USB port. However, I reached dead-ends everywhere and eventually decided it was better to wire up my SNES controller to the GPIO port instead, because even if it required I do a bit of soldering it couldn't possibly take longer than writing even a small USB driver.

I ended up using jumper connectors on the pi end, and nails of sufficient diameter on the other.

lu1sRD1.jpg

Major shout out to a guy named Peter Lemon. He has a demo here which is actually exactly what I was trying to accomplish, and most of this was just essentially a replication of his work.

The SNES controller seems to work in two stages. First, you toggle the "latch" high and then low. I presume this updates the controller's internal state. Next you read in the "data" value, and toggle the "clock" high and then low. Repeat this step until all 16 bits of data are read from the controller. Each bit is a button's state on the controller, but its more convenient to append the bits altogether into a single bitfield and use that.

Lastly, I improved upon the blit code from last time. Now it will properly clip when it runs off the screen... that is until it goes completely off, and then it starts drawing random artifacts all over the place.... but nothings perfect =) Since I refactored the code from last time to play nicer with the registers I'd better post everything for it to make sense, instead of as snippets:

.macro var name r .ifdef __\name .unreq \name .endif \name .req \r .set __\name, 1 .endm .macro nop_delay count .rept \count nop .endr .endm .set VS_BASE, 0x2000B208 .set VS_MAG, 12 .set MB_BASE, 0x2000B880 .set MB_STATUS, 0x18 .set MB_WRITE, 0x20 .set GP_BASE, 0x20200000 .set GP_SEL0, 0 .set GP_SEL1, 4 .arm@ ============================================================================== mov sp, #0x8000 var base, r11 var fbi, r10 var fbp, r10 var req, r9 var res, r9 var px, r8 var py, r12@ Initiate output pins. ldr base, =GP_BASE mov req, #0x9 str req, [base, #GP_SEL1]@ Wait til the mailbox is not busy. ldr base, =MB_BASEbusy$: ldr res, [base, #MB_STATUS] tst res, #0x80000000 bne busy$@ Ask for framebuffer info (fbi). ldr fbi, =framebufinfo add req, fbi, #0x40000000 add req, #1 str req, [base, #MB_WRITE]listen$: ldr res, [base, #MB_STATUS] tst res, #0x40000000 bne listen$ ldr res, [base] cmp res, #1 bne listen$@ Wait for v-sync. mov px, #0 mov py, #0 ldr fbp, [fbi, #32]render$: ldr base, =VS_BASE mov req, #0x10000 str req, [base, #VS_MAG] ldr r0, =0x20600000 mov req, #0 str req, [r0]vsync$: ldr res, [base] tst res, #0x10000 beq vsync$@ Poll input. ldr base, =GP_BASE mov req, #0x800 str req, [base, #0x1c] @@ latch on nop_delay 12 str req, [base, #0x28] @@ latch off nop_delay 12 mov r0, #15 mov r1, #0nextbutton$: mov r1, r1, lsl #1 ldr res, [base, #0x34] @@ read bit tst res, #0x10 orreq r1, #1 mov req, #0x400 str req, [base, #0x1c] @@ clock on nop_delay 12 str req, [base, #0x28] @@ clock off nop_delay 12 subs r0, #1 bge nextbutton$ tst r1, #0b0000000100000000 @@ left subeq px, #1 tst r1, #0b0000001000000000 @@ right addeq px, #1 tst r1, #0b0000100000000000 @@ down addeq py, #1 tst r1, #0b0000010000000000 @@ up subeq py, #1 mov r0, #256 mov r1, #240 mov r2, fbp mov r3, px mov r4, py mov r5, #16 mov r6, #16 ldr r7, =spritesheet bl blit_clip b render$@ ==============================================================================@ Blit a spritesheet var dst, r0 var src, r1 var drofs, r2 var srofs, r3 var rowsiz, r4 var nrows, r5blit: push {r6-r8} add r6, srofs, rowsiz mul r6, nrows add r6, srcouter$: add r7, src, rowsizinner$: ldrb r8, [src] strb r8, [dst] add src, #1 add dst, #1 cmp src, r7 blt inner$ add dst, r2 add src, r3 cmp src, r6 blt outer$ pop {r6-r8} mov pc, lr@ ==============================================================================@ Blitting done with clipping var dw, r0 var dh, r1 var dst, r2 var sx, r3 var sy, r4 var sw, r5 var sh, r6 var src, r7blit_clip: var drofs, r8 var srofs, r9 var rowsiz, r10 var nrows, r11 push {r8-r12} mov drofs, #0 mov srofs, #0 mov rowsiz, sw mov nrows, sh cmp sx, #0 addgt drofs, sx addgt dst, sx sublt src, sx addlt rowsiz, sx add sx, sw subs sx, dw, sx addgt drofs, sx addlt rowsiz, sx cmp sy, #0 mullt r12, sy, sw sublt src, r12 addlt nrows, sy mulgt r12, sy, dw addgt dst, r12 add sy, sh subs sy, dh, sy addlt nrows, sy mov r0, dst mov r1, src mov r2, drofs mov r3, srofs mov r4, rowsiz mov r5, nrows pop {r8-r12} b blit@ ============================================================================== .poolspritesheet: .byte 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 .byte 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1 .byte 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 .byte 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1 .byte 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 .byte 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1 .byte 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 .byte 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1 .byte 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 .byte 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1 .byte 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 .byte 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1 .byte 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 .byte 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1 .byte 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 .byte 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1 .align 12framebufinfo: .int 640 .int 480 .int 256 .int 240 .int 0 .int 8 .int 0 .int 0 .int 0 .int 0OK thats all for now, time to go to bed smile.png Thanks for stopping by!
Sign in to follow this  


1 Comment


Recommended Comments

This brings back fond memories of getting an snes controller to work with zsnes back in the day. Have fun!

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!