Skip to content

Commit

Permalink
Merge pull request #1779 from spicyjpeg/vscode-extension
Browse files Browse the repository at this point in the history
VS Code extension: update to reflect changes in ps1-bare-metal repo
  • Loading branch information
nicolasnoble authored Oct 24, 2024
2 parents e9dc935 + bc418e6 commit b4ff93b
Show file tree
Hide file tree
Showing 14 changed files with 293 additions and 139 deletions.
2 changes: 2 additions & 0 deletions tools/vscode-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ The panel will have the ability to install the tools on the most popular platfor

### Changelog

- 0.3.8
- Added automatic setup of Python virtual environments in order to reflect the changes in ps1-bare-metal.
- 0.3.7
- Bumping gcc to 14.2.0
- Bumping binutils to 2.43
Expand Down
36 changes: 34 additions & 2 deletions tools/vscode-extension/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class PSXDevPanel {
case 'restorePsyq':
restorePsyq()
break
case 'restorePythonEnv':
restorePythonEnv()
break
case 'updateModules':
updateModules()
break
Expand Down Expand Up @@ -219,8 +222,8 @@ class PSXDevPanel {
<p>Before debugging a PlayStation 1 application, you'll need to have a target able to run PlayStation 1 code accessible through the gdb protocol. You can <vscode-link href="https://unirom.github.io/debug_gdb/" target="_blank">connect to a real PlayStation 1</vscode-link>, or you can run an emulator with a gdb server. You can click the button below to launch the <vscode-link href="https://pcsx-redux.consoledev.net" target="_blank">PCSX-Redux</vscode-link> PlayStation 1 emulator in debugger mode.</p><br/>
<vscode-button id="show-redux-settings" appearance="secondary">Open Settings folder</vscode-button> <vscode-button id="launch-redux">Launch PCSX-Redux</vscode-button><br/>
<hr/>
<p>After cloning a project that uses the Psy-Q library, it'll be necessary to restore it. You can press the button below in order to restore the library into the current workspace.</p><br/>
<vscode-button id="restore-psyq">Restore Psy-Q</vscode-button><br/>
<p>After cloning a project that uses Psy-Q libraries or a Python virtual environment, it'll be necessary to restore them. Use the buttons below in order to restore the appropriate dependencies into the current workspace.</p><br/>
<vscode-button id="restore-psyq">Restore Psy-Q</vscode-button> <vscode-button id="restore-python-env">Restore Python environment</vscode-button><br/>
<hr/>
<p>The templates will create git repositories with submodules. These submodules may update frequently with bug fixes and new features. The updates should not break backward compatibility in general, and should be safe to do. Press the button below to update the submodules in the current workspace.</p><br/>
<vscode-button id="update-modules">Update modules</vscode-button><br/>
Expand Down Expand Up @@ -287,6 +290,12 @@ exports.activate = (context) => {
})
)

context.subscriptions.push(
vscode.commands.registerCommand('psxDev.restorePythonEnv', () => {
restorePythonEnv()
})
)

context.subscriptions.push(
vscode.commands.registerCommand('psxDev.updateModules', () => {
updateModules()
Expand Down Expand Up @@ -363,6 +372,29 @@ function restorePsyq () {
}
}

function restorePythonEnv () {
if (vscode.workspace.workspaceFolders) {
templates
.createPythonEnv({
path: vscode.workspace.workspaceFolders[0].uri.fsPath,
name: 'env',
requirementsFiles: [
vscode.Uri.joinPath(
vscode.workspace.workspaceFolders[0].uri,
'ps1-bare-metal',
'tools',
'requirements.txt'
).fsPath
]
})
.catch((err) => {
vscode.window.showErrorMessage(err.message)
})
} else {
vscode.window.showErrorMessage('Please open a project first.')
}
}

function showReduxSettings () {
const pathToOpen = vscode.Uri.joinPath(
globalStorageUri,
Expand Down
6 changes: 6 additions & 0 deletions tools/vscode-extension/media/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import {
const panelTab = document.createElement('vscode-panel-tab')
panelTab.textContent = category
panels.appendChild(panelTab)
templateKeys // Suppress unused variable warning
}
for (const [category, templateKeys] of Object.entries(categories)) {
const panel = document.createElement('vscode-panel-view')
Expand Down Expand Up @@ -295,6 +296,11 @@ import {
document.getElementById('restore-psyq').addEventListener('click', () => {
vscode.postMessage({ command: 'restorePsyq' })
})
document
.getElementById('restore-python-env')
.addEventListener('click', () => {
vscode.postMessage({ command: 'restorePythonEnv' })
})
document.getElementById('update-modules').addEventListener('click', () => {
vscode.postMessage({ command: 'updateModules' })
})
Expand Down
9 changes: 7 additions & 2 deletions tools/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "psx-dev",
"displayName": "PSX.Dev",
"description": "PlayStation 1 development made easy",
"version": "0.3.7",
"version": "0.3.8",
"engines": {
"vscode": "^1.75.0"
},
Expand Down Expand Up @@ -72,6 +72,11 @@
"title": "Restore Psy-Q",
"category": "PSX.Dev"
},
{
"command": "psxDev.restorePythonEnv",
"title": "Restore Python environment",
"category": "PSX.Dev"
},
{
"command": "psxDev.showReduxSettings",
"title": "Show PCSX-Redux Settings",
Expand Down Expand Up @@ -111,6 +116,6 @@
"open-file-explorer": "^1.0.2",
"simple-git": "^3.16.1",
"unzipper": "^0.10.11",
"which": "^3.0.0"
"which": "^5.0.0"
}
}
6 changes: 3 additions & 3 deletions tools/vscode-extension/pcsx-redux.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const dmg = require('dmg')
const dmgMount = util.promisify(dmg.mount)
const dmgUnmount = util.promisify(dmg.unmount)
const terminal = require('./terminal.js')
const execAsync = require('node:child_process').exec
const exec = util.promisify(execAsync)
const execFileAsync = require('node:child_process').execFile
const execFile = util.promisify(execFileAsync)
const os = require('node:os')

const updateInfo = {
Expand Down Expand Up @@ -97,7 +97,7 @@ exports.install = async () => {
'https://aka.ms/vs/17/release/vc_redist.x64.exe',
fullPath
)
await exec(fullPath)
await execFile(fullPath)
}
}

Expand Down
62 changes: 60 additions & 2 deletions tools/vscode-extension/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require('node:path')
const fs = require('fs-extra')
const Mustache = require('mustache')
const { simpleGit } = require('simple-git')
const terminal = require('./terminal.js')
const progressNotification = require('./progressnotification.js')

let extensionUri
Expand Down Expand Up @@ -365,6 +366,7 @@ const baseCMakeTemplate = combine(baseTemplate, {
name: '.gitignore',
content: [
'build/',
'env/',
'.cache/',
'__pycache__/',
'*.pyc',
Expand Down Expand Up @@ -521,6 +523,27 @@ async function createGitRepository (fullPath, template, progressReporter) {
return git
}

async function createPythonEnv (fullPath, name, packages, requirementsFiles) {
// On Windows "python" and "python3" are aliased to a script that opens the
// Microsoft Store by default, so the "py" launcher is invoked instead.
const pythonCommand = (process.platform === 'win32') ? 'py' : 'python3'
await terminal.run(pythonCommand, ['-m', 'venv', name], {
cwd: fullPath
})
const pipCommand = path.join(fullPath, name, 'bin', 'pip')
if (packages && packages.length) {
await terminal.run(pipCommand, ['install', ...packages], {
cwd: fullPath
})
}
if (requirementsFiles && requirementsFiles.length) {
const options = requirementsFiles.flatMap((file) => ['-r', file])
await terminal.run(pipCommand, ['install', ...options], {
cwd: fullPath
})
}
}

async function copyTemplateDirectory (git, fullPath, name, templates, data) {
const binaryExtensions = ['.bin', '.dat', '.png', '.tim']
const ignoredFiles = ['PSX.Dev-README.md']
Expand Down Expand Up @@ -620,6 +643,20 @@ const templates = {
],
{ projectName: name, isCMake: true }
)
progressReporter.report({ message: 'Setting up Python environment...' })
await createPythonEnv(
fullPath,
'env',
[],
[
path.join(
fullPath,
'ps1-bare-metal',
'tools',
'requirements.txt'
)
]
)
}
},
cmake_cube: {
Expand Down Expand Up @@ -659,6 +696,20 @@ const templates = {
],
{ projectName: name, isCMake: true }
)
progressReporter.report({ message: 'Setting up Python environment...' })
await createPythonEnv(
fullPath,
'env',
[],
[
path.join(
fullPath,
'ps1-bare-metal',
'tools',
'requirements.txt'
)
]
)
}
},
psyq_cube: {
Expand Down Expand Up @@ -731,7 +782,6 @@ const templates = {
netyarozeTemplate,
progressReporter
)

await copyTemplateDirectory(
git,
fullPath,
Expand Down Expand Up @@ -787,7 +837,7 @@ exports.createProjectFromTemplate = async function (tools, options) {
let rejecter
const { progressReporter, progressResolver } =
await progressNotification.notify(
'Creating project...',
'Creating project',
'Creating directories...'
)
const ret = new Promise((resolve, reject) => {
Expand All @@ -806,6 +856,14 @@ exports.createProjectFromTemplate = async function (tools, options) {
})
return ret
}
exports.createPythonEnv = async function (options) {
await createPythonEnv(
options.path,
options.name,
options.packages,
options.requirementsFiles
)
}

exports.setExtensionUri = (uri) => {
extensionUri = uri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ project(
HOMEPAGE_URL "https://github.com/grumpycoders/pcsx-redux"
)

# Locate a working Python installation in order to run the scripts in the tools
# directory.
find_package(Python3 3.10 REQUIRED COMPONENTS Interpreter)
# Set up compiler flags and initialize the Python environment used to run the
# scripts in the tools directory.
include(ps1-bare-metal/cmake/setup.cmake)
include(ps1-bare-metal/cmake/virtualenv.cmake)

# Build a "common" library containing basic support code. We are going to link
# this library into our executable.
Expand All @@ -39,40 +40,8 @@ target_include_directories(
ps1-bare-metal/src/libc
)

# Define a helper function to embed the contents of a file into the executable.
function(addBinaryFile target name path)
set(_file "${PROJECT_BINARY_DIR}/includes/${target}_${name}.s")
cmake_path(ABSOLUTE_PATH path OUTPUT_VARIABLE _path)

# Generate an assembly listing that uses the .incbin directive to embed the
# file and add it to the executable's list of source files. This may look
# hacky, but it works and lets us easily customize the symbol name (i.e. the
# name of the "array" that will contain the file's data).
file(
CONFIGURE
OUTPUT "${_file}"
CONTENT [[
.section .data.${name}, "aw"
.balign 8

.global ${name}
.type ${name}, @object
.size ${name}, (${name}_end - ${name})

${name}:
.incbin "${_path}"
${name}_end:
]]
ESCAPE_QUOTES
NEWLINE_STYLE LF
)

target_sources(${target} PRIVATE "${_file}")
set_source_files_properties("${_file}" PROPERTIES OBJECT_DEPENDS "${_path}")
endfunction()

# Create the main executable. You may add more source files by listing them
# here, or other images or files by adding calls to addBinaryFile().
# Compile the main executable. You may add more source files by listing them
# here.
add_executable(
{{projectName}}
src/font.c
Expand All @@ -82,8 +51,28 @@ add_executable(
)
target_link_libraries({{projectName}} PRIVATE common)

addBinaryFile({{projectName}} fontTexture assets/fontTexture.dat)
addBinaryFile({{projectName}} fontPalette assets/fontPalette.dat)
# Define a CMake macro that invokes convertImage.py in order to generate VRAM
# texture data from an image file.
function(convertImage input bpp)
add_custom_command(
OUTPUT ${ARGN}
DEPENDS "${PROJECT_SOURCE_DIR}/${input}"
COMMAND
"${Python3_EXECUTABLE}"
"${PROJECT_SOURCE_DIR}/ps1-bare-metal/tools/convertImage.py"
-b ${bpp}
"${PROJECT_SOURCE_DIR}/${input}"
${ARGN}
VERBATIM
)
endfunction()

# Convert the font spritesheet to a 4bpp texture and palette, then embed them
# into the executable. The addBinaryFile() macro is defined in setup.cmake; you
# may call it multiple times to embed other data into the binary.
convertImage(assets/font.png 4 fontTexture.dat fontPalette.dat)
addBinaryFile({{projectName}} fontTexture "${PROJECT_BINARY_DIR}/fontTexture.dat")
addBinaryFile({{projectName}} fontPalette "${PROJECT_BINARY_DIR}/fontPalette.dat")

# Add a step to run convertExecutable.py after the executable is compiled in
# order to convert it into a PS1 executable. By default all custom commands run
Expand All @@ -95,6 +84,7 @@ add_custom_command(
COMMAND
"${Python3_EXECUTABLE}"
"${PROJECT_SOURCE_DIR}/ps1-bare-metal/tools/convertExecutable.py"
"$<TARGET_FILE:{{projectName}}>" {{projectName}}.psexe
"$<TARGET_FILE:{{projectName}}>"
{{projectName}}.psexe
VERBATIM
)
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
#include <stdint.h>
#include "ps1/gpucmd.h"

// In order for Z averaging to work properly, ORDERING_TABLE_SIZE should be set
// to either a relatively high value (1024 or more) or a multiple of 12; see
// setupGTE() for more details. Higher values will take up more memory but are
// required to render more complex scenes with wide depth ranges correctly.
#define DMA_MAX_CHUNK_SIZE 16
#define CHAIN_BUFFER_SIZE 1024
#define ORDERING_TABLE_SIZE 32
#define ORDERING_TABLE_SIZE 240

typedef struct {
uint32_t data[CHAIN_BUFFER_SIZE];
Expand Down
Loading

0 comments on commit b4ff93b

Please sign in to comment.