Advertising (This ad goes away for registered users. You can Login or Register)

[Tutorial] Python PSP Programming

Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
hgoel0974
Retired Mod
Posts: 2155
Joined: Mon Jul 23, 2012 11:42 pm
Location: New York

Re: [Tutorial] Python PSP Programming

Post by hgoel0974 »

SifJar wrote:Can anyone give me some pointers on running the code on PC? I have installed PyGame, and tried importing pygame as psp2d, but that didn't work (pygame has no Screen() function), so I'm not sure what I need to do. Or am I meant to import both pygame and psp2d (in which case, where do I get the psp2d module for PC)? Any advice would be great, would make it much easier to mess around with this rather than having to transfer py scripts back and forth between my PC and PSP for editing.

EDIT: Well I figured that out, needed to download this: https://code.google.com/p/pspstacklessp ... p&can=2&q=

But I do have another question; what would be the correct way to exit a program? For example I have this script:

Code: Select all

#! /usr/bin/env python
import pygame, psp2d
scr = psp2d.Screen()
fnt = psp2d.Font("font.png")
img = psp2d.Image(480, 272)
img.clear(psp2d.Color(0,0,0))
fnt.drawText(img, 0, 0, "Hello World!")
fnt.drawText(img, 0, 20, "Press X to change the screen")
scr.blit(img)
scr.swap()
while True:
    pad = psp2d.Controller()
    if pad.cross:
        img.clear(psp2d.Color(255,0,0))
        fnt.drawText(img, 0, 0, "Now it's RED!")
        fnt.drawText(img, 0, 20, "Triangle to quit, Circle to change again!")
        scr.blit(img)
        scr.swap()
        while True:
            pad = psp2d.Controller()
            if pad.triangle: exit() #HERE
            elif pad.circle:
                img.clear(psp2d.Color(0,255,0))
                fnt.drawText(img, 0, 0, "GREEN!")
                fnt.drawText(img, 0, 20, "Square to exit now")
                scr.blit(img)
                scr.swap()
                while True:
                    pad = psp2d.Controller()
                    if pad.square: exit() #HERE
which works great apart from exiting the program (the lines commented with "#HERE"), which crashes both then PSP and when it is run on the PC. Is there some better way to do this? If so, could someone please tell me it? I've tried looking at samples, but I can't seem to find what I'm looking for...

EDIT: Actually, this does work on PC. But not on the PSP. And obviously the PSP is the more important factor here (although ideally the solution would work on both)
You don't need to have the pygame import, that is automatic in psp2d ;) The PSP can't run it because of that, also, if you ever have any problem, you should take a look at the pytrace.txt that is created in the same folder, it contains a detailed description of the error
Advertising
"If the truth is a cruel mistress, then a lie must be a nice girl"
SifJar
Posts: 251
Joined: Tue Jan 11, 2011 10:19 pm

Re: [Tutorial] Python PSP Programming

Post by SifJar »

hgoel0974 wrote:You don't need to have the pygame import, that is automatic in psp2d ;) The PSP can't run it because of that, also, if you ever have any problem, you should take a look at the pytrace.txt that is created in the same folder, it contains a detailed description of the error
Yeah, I figured out how to make psp2d work on the PC, I just had the pygame import there while I was using it on PC. I had it removed for the PSP; the script worked fine on the PSP, except for exiting. I should probably specify that it didn't "crash" as such, it would just hang whenever I called "exit()", and stop responding to any button other than Home, which would allow me to choose to exit to the XMB, but would not actually load the XMB, but would also hang on the "Please Wait" screen, forcing me to hold the power button to turn off the PSP and then turn it back on again.

Also, you do need the pygame import on PC, at least with the psp2d.py module I have. I personally found a script called "runner.py" that will import pygame and then load the script, so you can load the script unmodified from the PSP version. But pygame is imported by runner.py, not by psp2d.
Advertising
hgoel0974
Retired Mod
Posts: 2155
Joined: Mon Jul 23, 2012 11:42 pm
Location: New York

Re: [Tutorial] Python PSP Programming

Post by hgoel0974 »

SifJar wrote:
hgoel0974 wrote:You don't need to have the pygame import, that is automatic in psp2d ;) The PSP can't run it because of that, also, if you ever have any problem, you should take a look at the pytrace.txt that is created in the same folder, it contains a detailed description of the error
Yeah, I figured out how to make psp2d work on the PC, I just had the pygame import there while I was using it on PC. I had it removed for the PSP; the script worked fine on the PSP, except for exiting. I should probably specify that it didn't "crash" as such, it would just hang whenever I called "exit()", and stop responding to any button other than Home, which would allow me to choose to exit to the XMB, but would not actually load the XMB, but would also hang on the "Please Wait" screen, forcing me to hold the power button to turn off the PSP and then turn it back on again.

Also, you do need the pygame import on PC, at least with the psp2d.py module I have. I personally found a script called "runner.py" that will import pygame and then load the script, so you can load the script unmodified from the PSP version. But pygame is imported by runner.py, not by psp2d.
That is weird, you shouldn't need to add an import pygame thing
"If the truth is a cruel mistress, then a lie must be a nice girl"
SifJar
Posts: 251
Joined: Tue Jan 11, 2011 10:19 pm

Re: [Tutorial] Python PSP Programming

Post by SifJar »

hgoel0974 wrote:That is weird, you shouldn't need to add an import pygame thing
I have downloaded two versions of the psp2d.py wrapper, neither have had a pygame import in them, so in both cases it had to be imported manually. It's not a big deal, it all works just fine.
grief3r
Posts: 358
Joined: Sat Nov 09, 2013 4:12 am

Re: [Tutorial] Python PSP Programming

Post by grief3r »

how many threads can the psp processor handle?
PSV1001 2.61 FieldRunners
PSP1001 6.60 Pro-C
PSP 3001 6.20 Pro-C2
hgoel0974
Retired Mod
Posts: 2155
Joined: Mon Jul 23, 2012 11:42 pm
Location: New York

Re: [Tutorial] Python PSP Programming

Post by hgoel0974 »

grief3r wrote:how many threads can the psp processor handle?
I don't think there's a limit but you wouldn't want to do too many, it's just one core ;)
"If the truth is a cruel mistress, then a lie must be a nice girl"
grief3r
Posts: 358
Joined: Sat Nov 09, 2013 4:12 am

Re: [Tutorial] Python PSP Programming

Post by grief3r »

so multiple threads = multiple pc registers?
PSV1001 2.61 FieldRunners
PSP1001 6.60 Pro-C
PSP 3001 6.20 Pro-C2
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: [Tutorial] Python PSP Programming

Post by m0skit0 »

grief3r wrote:so multiple threads = multiple pc registers?
Yes, operating system takes care of saving each thread CPU state and restoring it. This is called context-switching.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
alevisawesom
Posts: 106
Joined: Sun Mar 16, 2014 5:34 pm

Re: [Tutorial] Python PSP Programming

Post by alevisawesom »

I am kind of a noob to python (know a lot of C though), and am having trouble with the first exercise. It just exits to the XMB after about 5 seconds.
Code:

Code: Select all

import psp2d
font = psp2d.font("font.png")
image = psp2d.Image(480, 272)
screen = psp2d.Screen()
CLEAR_COLOR = psp2d.Color(0,0,0)
image.clear(CLEAR_COLOR)
font.drawText(image, 0, 0, "Hello World")
font.drawText(image, 0, 30, "Press Circle to exit")
screen.blit(image)
screen.swap()
x = True
while x == True:
    pad = psp2d.Controller()
    if pad.circle:
        font.drawText(image, 0, 60, "Goodbye!")
        screen.blit(image)
        screen.swap()
        x = False
Using Python 2.7.3.
Directory structure:
Documents
PSP
Hello
EBOOT.PBP
font.png
psp2d.py
pspmp3.py
pspnet.py
pspogg.py
pspos.py
pspsnd.py
python.zip
script.py
sfont.py

Anybody have anything? I'm using this as a basis for making a clone of "2048", as I need to learn some PSP programming basics before I jump in. Very skilled with C (NOT python), but there's probably a problem with my dir structure...
Please refer to me as arcticsn0w, not alevisawesom.

PSP 2001 - 6.61 ME-2.3 (main)
PS2 Slim - FMCB
iPod touch 5 - 8.1.1 jailbroken
iPad 2 - 8.1.1 jailbroken
OG Pebble - 2.8.1 PebbleBits
Android Tab - 4.2.2 rooted
Wii - 4.3, HBC
2010 MBP - OS X 10.10
Acid_Snake
Retired Mod
Posts: 3100
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: [Tutorial] Python PSP Programming

Post by Acid_Snake »

well the best step to solve it without breaking your head too much is to look for a file named pytrace.txt, which contains python's generated traceback for debugging.
When it comes to python there's two types of errors: syntax error (this would equate to C's compilation-time errors) and runtime errors (which equate to C's runtime errors). Both of which python tells you what the error is about and where it happened. On PC this is done by printing on the terminal, on PSP we gotta look at the file pytrace.txt
Locked

Return to “Programming and Security”