From 4b68c49ce668b74735ac8c4ee35cbe134ebb4fc7 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Sun, 17 Dec 2023 01:10:53 -0600 Subject: [PATCH] New keyboard code tested. New non-event-driven framework started. --- CHANGELOG | 3 ++ assets/Framework.singe | 36 +++++++++++++ assets/Service.singe | 117 +++++++++++++++++++++++++++++++++++++++++ src/singe.c | 7 ++- 4 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 assets/Service.singe diff --git a/CHANGELOG b/CHANGELOG index 1ca1f6cd0..1a2082f07 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -22,6 +22,9 @@ New Features which default audio track you want (-o or --audio). For games with multiple languages, you can specify AUDIO_TRACK in the games.dat as well. +- New keyboard methods to make handling input easier, especially multiple + keypresses for diagonal movement. + - SINGE_DEAD_ZONE global variable now available based on the DEAD_ZONE controller configuration option. diff --git a/assets/Framework.singe b/assets/Framework.singe index 131060df7..f33b8f4d8 100644 --- a/assets/Framework.singe +++ b/assets/Framework.singe @@ -326,6 +326,27 @@ SCANCODE = { SCANCODE_MIN = 4 -- Lowest value SCANCODE_MAX = 286 -- Highest value, not the number of items in the table. +MODIFIER = { + NONE = { name = "NONE", value = 0x0000 }, + LSHIFT = { name = "LSHIFT", value = 0x0001 }, + RSHIFT = { name = "RSHIFT", value = 0x0002 }, + LCTRL = { name = "LCTRL", value = 0x0040 }, + RCTRL = { name = "RCTRL", value = 0x0080 }, + LALT = { name = "LALT", value = 0x0100 }, + RALT = { name = "RALT", value = 0x0200 }, + LGUI = { name = "LGUI", value = 0x0400 }, + RGUI = { name = "RGUI", value = 0x0800 }, + NUM = { name = "NUM", value = 0x1000 }, + CAPS = { name = "CAPS", value = 0x2000 }, + MODE = { name = "MODE", value = 0x4000 }, + SCROLL = { name = "SCROLL", value = 0x8000 }, + + SHIFT = { name = "SHIFT", value = 0x0001 + 0x0002 }, + CTRL = { name = "CTRL", value = 0x0040 + 0x0080 }, + ALT = { name = "ALT", value = 0x0100 + 0x0200 }, + GUI = { name = "GUI", value = 0x0400 + 0x0800 } +} + GAMEPAD_0 = { AXIS_LEFT_X = { name = "AXIS_LEFT_X", value = 500 }, AXIS_LEFT_X_L = { name = "AXIS_LEFT_X_L", value = 501 }, @@ -497,3 +518,18 @@ if singeGetHeight ~= nil then daphneGetWidth = singeGetWidth daphneScreenshot = singeScreenshot end + + +-- Singe 2.10 Threaded Application Support ------------------------------------ + + +if singeMain ~= nil then + onOverlayUpdate = function() + coroutine.resume(SINGE_SELF) + return(OVERLAY_UPDATED) + end + singeYield = coroutine.yield + SINGE_SELF = coroutine.create(singeMain) +end + + diff --git a/assets/Service.singe b/assets/Service.singe new file mode 100644 index 000000000..ac27b5423 --- /dev/null +++ b/assets/Service.singe @@ -0,0 +1,117 @@ +--[[ + * + * Singe 2 + * Copyright (C) 2006-2024 Scott Duensing + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 3 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * +--]] + + +local socket = require("socket") +local copas = require("copas") +local https = require("copas.http").request + + +dofile("Singe/Framework.singe") + + +function get(url) + local download = {} + download.url = url + download.finished = false + copas.addthread(function(d) + d.result, d.error = https(d.url) + d.finished = true + end, + download) + return download +end + + +function onInputPressed(what) + + if what == SWITCH_LEFT then + discStepBackward() + end + + if what == SWITCH_RIGHT then + discStepForward() + end + +end + + +function onOverlayUpdate() + + copas.step() + + colorBackground(0, 0, 0, 127) -- this dims the background 50% + overlayClear() + + overlayPrint(1, 1, dldGameList.url.." "..(dldGameList.finished and 'true' or 'false')) + if dldGameList.finished then + overlayPrint(1, 2, dldGameList.error) + overlayPrint(1, 3, dldGameList.result) + end + + colorForeground(255, 0, 0) + overlayBox(0, 0, overlayGetWidth() - 1, overlayGetHeight() - 1) + + spriteDraw((overlayGetWidth() - spriteGetWidth(sprServiceMenu)) / 2, 25, sprServiceMenu) + + return(OVERLAY_UPDATED) + +end + + +function onShutdown() + + spriteUnload(sprServiceMenu) + fontUnload(fntSans18) + fontUnload(fntSans32) + +end + + +copas.running = true + +dldGameList = get("https://kangaroopunch.com/api/singeSoftware") + +overlaySetResolution(vldpGetWidth(), vldpGetHeight()) + +DISC_SINGE_LOGO = 140 + +discSkipToFrame(DISC_SINGE_LOGO) +discPause() + +fontQuality(FONT_QUALITY_BLENDED) +fntSans18 = fontLoad("Singe/FreeSansBold.ttf", 18) +fntSans32 = fontLoad("Singe/FreeSansBold.ttf", 32) + +fontSelect(fntSans32) +sprServiceMenu = fontToSprite("Singe Service Menu") + + + +--[[ + +Game Management + + +--]] + diff --git a/src/singe.c b/src/singe.c index 0d3b03cf3..830f4be80 100644 --- a/src/singe.c +++ b/src/singe.c @@ -5048,10 +5048,6 @@ void singe(SDL_Window *window, SDL_Renderer *renderer, ConfigT *conf) { progTrace("Script is running"); while (_global.running) { - // Clear per-loop values. - _global.keyboardLastDown = SDL_SCANCODE_UNKNOWN; - _global.keyboardLastUp = SDL_SCANCODE_UNKNOWN; - // SDL Event Loop while (SDL_PollEvent(&event)) { switch (event.type) { @@ -5296,6 +5292,9 @@ void singe(SDL_Window *window, SDL_Renderer *renderer, ConfigT *conf) { _global.refreshDisplay = true; } frameClock = SDL_GetTicks() + 15; // Don't eat all the CPU. + // Clear per-frame values. + _global.keyboardLastDown = SDL_SCANCODE_UNKNOWN; + _global.keyboardLastUp = SDL_SCANCODE_UNKNOWN; } // Update display