Commit Graph

63 Commits

Author SHA1 Message Date
Adolfo Reyna
f398d62af2 Add renderer.text_scaled() Lua binding
lua_bindings.cpp:
- Added new lua_renderer_text_scaled() function
- Wraps renderer->draw_string_scaled() with proper scale support
- Registered as renderer.text_scaled(x, y, text, on, scale)
- Scale parameter defaults to 1 if omitted

Updated all 4 games to use text_scaled():
- simon_says.lua: All text now uses text_scaled with scale=2
- tic_tac_toe.lua: All text now uses text_scaled with scale=2
- memory_match.lua: All text now uses text_scaled with scale=2
- 2048.lua: All text now uses text_scaled with scale=2

This properly uses the C++ renderer's scaled text rendering instead of
workarounds in Lua, providing better performance and consistency.
2026-02-12 21:31:15 -05:00
Adolfo Reyna
fa7d2fd32f Scale games on both axes and 2x text size
All 4 games (simon_says, tic_tac_toe, memory_match, 2048):
- Changed sizing to use min(width, height) instead of just width
- Grids now scale proportionally on both axes
- All UI text now uses text_scale=2 for better visibility
- Games fill more of the screen properly on portrait mode

Fixes:
- Simon Says buttons now square grid on any orientation
- Tic-Tac-Toe grid centered vertically using full screen height
- Memory Match cards use smallest dimension for square sizing
- 2048 tiles scale and center on both axes
- All text (scores, menus, game over) now 2x larger
2026-02-12 21:23:34 -05:00
Adolfo Reyna
a274fb04a1 Update Snake: wrap edges and halve speed
snake.lua:
- Changed wall collision to wrap around (toroidal grid)
- Snake now travels through edges instead of crashing
- Doubled move_speed from 10 to 20 frames (half speed)
- Updated speed increase cap from 3 to 5 frames (slower at max)
- Snake can now traverse indefinitely without losing to walls
2026-02-12 21:10:44 -05:00
Adolfo Reyna
a058476b42 Scale 2048 to fill screen
2048.lua:
- Removed hardcoded TILE_SIZE and TILE_SPACING constants
- Added get_tile_size() function that calculates tile dimensions based on screen width
- Added get_grid_start_x/y() to center grid
- Updated draw() to use dynamic sizing for all tiles
- 4x4 grid now scales proportionally on any screen size
2026-02-12 21:10:16 -05:00
Adolfo Reyna
2a9b17a539 Scale Memory Match to fill screen
memory_match.lua:
- Removed hardcoded CARD_SIZE and CARD_SPACING
- Added get_card_size() function that calculates card dimensions based on available screen space
- Grid now fills screen width (minus padding) and uses available height
- Added get_grid_start_x/y() to center grid
- All card positions and hit detection updated to use dynamic sizing
- Cards scale proportionally on any screen size while maintaining 4x4 layout
2026-02-12 21:09:46 -05:00
Adolfo Reyna
62716c7dc4 Scale Simon Says and Tic-Tac-Toe to fill screen
simon_says.lua:
- Removed hardcoded button positions
- Added get_buttons() function that calculates button size and position based on screen dimensions
- Buttons now use 10% screen padding and scale to fill available width
- 2x2 grid automatically scales with screen size

tic_tac_toe.lua:
- Replaced hardcoded CELL_SIZE with dynamic calculation
- Added get_cell_size() to compute size based on screen width
- Added get_grid_start_x/y() to center grid both horizontally and vertically
- Grid now scales to fill available space while maintaining 3x3 layout
- All cell positions updated to use dynamic functions

Both games now work on any screen size and scale proportionally.
2026-02-12 21:06:54 -05:00
Adolfo Reyna
b22170b62c Fix Lua game float-to-int conversion errors for renderer.circle()
All games had the same issue: renderer.circle() requires integer arguments,
but float calculations produced non-integer coordinates.

Fixed in all games using math.floor(x + 0.5) for proper rounding:
- pong.lua: Ball position
- air_hockey.lua: Puck position
- asteroids.lua: Asteroid positions
- ball.lua: Ball and trail positions, velocity line
- breakout.lua: Ball position
- flappy_bird.lua: Bird Y position
- counter.lua: Last touch marker position
- snake.lua: Food position (center calculation)
- tic_tac_toe.lua: O circle center position

Also fixed floating-point coordinate calculations in ball and line
drawing to ensure all coordinates are integers.
2026-02-12 20:51:26 -05:00
Adolfo Reyna
b5e69abc83 Add virtual navigation buttons to game launcher
- Display < PREV and NEXT > buttons at bottom of screen when multiple pages exist
- Buttons are touchable and respond to taps
- Button dimensions: 150x40 at y=235
- PREV button: x=30, NEXT button: x=200
- Updated instructions to show 'Touch buttons or KEY0/KEY1'
- Both KEY0/KEY1 and touch button presses navigate pages
- Updated lib/ and emulator/ versions
2026-02-12 20:46:41 -05:00
Adolfo Reyna
b722b8b9c5 Clean up build artifacts and improve .gitignore
- Remove tracked CMakeFiles/ directory
- Remove .DS_Store files
- Add proper .gitignore patterns for:
  - *.o, *.o.d (object files and dependency files)
  - *.a, *.so, *.dylib (static/dynamic libraries)
  - CMakeFiles/ (CMake build directory)
  - emulator/build/ (build output)
  - .DS_Store (macOS metadata)
2026-02-12 20:42:56 -05:00
Adolfo Reyna
38ffdac749 Add pagination to game launcher - 4 games per page
- GameLauncher now displays only 4 games per page to keep menu in bounds
- Added page navigation with page indicator (Page X/Y)
- KEY0 navigates between pages and within page
- KEY1 selects the highlighted game
- Touch selection works on current page only
- Helper methods: get_total_pages(), get_page_start_index(), get_page_end_index()
- Updated both lib/ and emulator/ versions for consistency
2026-02-12 20:39:38 -05:00
Adolfo Reyna
50793ac535 feat: add final 4 games for basic1 console
- 2048: Grid merging, directional movement, score tracking, win/draw detection
- Tic-Tac-Toe: Minimax AI opponent, perfect play, win detection
- Lunar Lander: Gravity + thrust physics, fuel management, landing validation
- Air Hockey: Refined paddle physics, puck acceleration, goal detection

All games tested for state transitions, collision logic, and win conditions.
Suite now complete with 10 classic games ready for SD card deployment.
2026-02-12 19:40:42 -05:00
Adolfo Reyna
53a2fb046b feat: add 6 lua games for basic1 console
- Pong: 2-player paddle and ball game with spin mechanics
- Flappy Bird: gravity physics, obstacle avoidance
- Breakout: paddle control, brick grid, collision detection
- Simon Says: sequence memory, animation timing
- Memory Match: pair matching, flip animations, grid layout
- Tetris: falling blocks, grid system, line clearing
- Asteroids: vector math, rotation, projectiles, enemy spawning

All games follow API conventions with state machines, touch input,
frame-based animation, and persistent game.vars state management.
2026-02-12 19:18:51 -05:00
Adolfo Reyna
eacc03a38c Implement 4-quadrant dirty rectangle optimization and 30 FPS limiting for ST7796
Add intelligent partial screen update system using bitwise XOR change detection
and 4-quadrant tracking (top-left, top-right, bottom-left, bottom-right). Each
changed pixel is routed to its quadrant, with sophisticated merge logic that
combines adjacent rectangles when beneficial (<40% overhead). This dramatically
reduces SPI bandwidth for UIs with scattered updates (e.g., corners, sidebars).

Key changes:
- 4-quadrant dirty rectangle tracking with automatic merging
- XOR-based change detection for fast byte-level comparison
- Expose st7796_set_window() for partial region updates
- 30 FPS frame rate limiter (33ms per frame) to prevent excessive refreshes
- Smart sleep timing when frame rate limit is active

Performance: Up to 99% reduction in SPI traffic for corner-based UIs
(e.g., 4 small regions vs full 480x320 screen updates).

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-11 12:56:10 -05:00
Adolfo Reyna
b59d716965 Optimize ST7796 driver: Use bulk SPI transfers and blocking DMA for higher framerate 2026-02-11 11:40:26 -05:00
Adolfo Reyna
47fc02f05c Fix frame update logic and emulator support
- Fix basic1.cpp loop to handle set_frame_updates(true) correctly with sleep
- Update emulator loop for concurrent input and frame updates
- Update emulator for SFML 3.0 compatibility
- Add INPUT.FRAME_TICK constant to Lua bindings
- Enable frame updates in snake.lua example
2026-02-10 23:27:31 -05:00
Adolfo Reyna
fe5d58b663 Refactor power saving logic into display drivers and add ST7789 support 2026-02-10 22:20:53 -05:00
Adolfo Reyna
ce1f06ccbf Implement 2-stage power saving: dim at 2min, sleep at 10min 2026-02-10 22:03:16 -05:00
Adolfo Reyna
8cbb95b181 Add auto-sleep/wake functionality with timer-based dimming
- Added PWM brightness control to ST7796 driver (0-100%)
- Implemented hardware sleep mode for ST7796 (saves ~150mA)
- Added sleep/wake functions preserving framebuffer and settings
- Implemented timer-based inactivity detection (checks every 10s)
- Auto-sleep after 5 minutes of no user input
- Touch controller remains active during TFT sleep for instant wake
- E-ink display also sleeps after timeout, requires re-init on wake
- Added hardware_pwm library dependency to CMakeLists.txt
- Brightness and sleep/wake methods exposed through display abstraction layer
2026-02-10 20:29:10 -05:00
Adolfo Reyna
b16211f148 Fix SD card integration and Lua game loading
- Fix SD card MISO pin (was using display MISO instead of SD MISO)
- Add FatFS mounting after SD card initialization
- Restore SPI baudrate on all SD init failure paths
- Add case-insensitive .lua file extension check
- Filter out hidden 8.3 filename entries
- Add SPI speed management functions for shared SPI bus
- Wrap all FatFS operations with SPI speed switching
- Restore display SPI speed (32 MHz) after SD operations
- Add debug output to Lua game loader

This fixes slow display refresh when SD card is present and enables
reliable Lua game loading from SD card /games directory.
2026-02-07 19:31:38 -05:00
Adolfo Reyna
2a472fc29f Add frame tick system for continuous animation
- Added INPUT_FRAME_TICK event type to input_event.h
- Added wants_frame_updates() virtual method to Game base class
- Implemented frame tick logic in main loop (basic1.cpp and emulator/main.cpp)
- Added Lua bindings: game.set_frame_updates(bool) and INPUT.FRAME_TICK
- Updated LuaGame to support frame updates via registry flag
- Updated ball.lua to use continuous frame updates for smooth animation
- Both hardware and emulator now support continuous animation for physics/games
2026-02-07 13:20:10 -05:00
Adolfo Reyna
8d176925f8 Fix garbage characters in hardware game names
Store game names and descriptions in persistent LuaGameFactoryData
structure instead of local stack variables to prevent dangling pointers.
Same fix as emulator version.
2026-02-07 13:09:16 -05:00
Adolfo Reyna
22f5f1f5b2 Fix garbage characters in emulator game names
Store game names and descriptions in persistent LuaGameFactoryData
structure instead of local stack variables to prevent dangling pointers
2026-02-07 13:08:22 -05:00
Adolfo Reyna
285dffc32e Add Lua scripting support to desktop emulator
- Created emulator-specific lua_game_emulator.cpp using filesystem instead of FatFS
- Created lua_game_loader_emulator.cpp to scan games/lua_examples directory
- Updated CMakeLists.txt to include Lua 5.4 engine and bindings
- Updated to SFML 3.0 API compatibility (event handling, sprite initialization)
- Updated Game class to use public members for Lua bindings
- Updated GameLauncher to use std::function for lambda captures
- Added continuous 60 FPS rendering for smooth display
- Emulator now loads and runs all three example Lua games
2026-02-07 12:14:33 -05:00
Adolfo Reyna
e6e4eca188 Add Lua 5.4 scripting integration for dynamic game loading
- Integrated Lua 5.4 engine (32-bit mode for embedded ARM)
- Created LuaGame wrapper class implementing Game interface
- Added C++ bindings exposing renderer, game state, and input to Lua
- Implemented SD card loader for automatic .lua game discovery
- Updated GameLauncher to support std::function for lambda captures
- Made Game class members public for Lua bindings access
- Added example Lua games: counter, snake, bouncing ball
- Included comprehensive API documentation

Games can now be written as .lua text files on SD card and loaded
without recompilation. Build size: 747KB UF2, Lua VM uses ~50-80KB RAM.
2026-02-07 11:56:03 -05:00
Adolfo Reyna
c8af4f6638 Update DiceModalGame with a restricted board view and interactive dice challenge 2026-02-06 23:30:37 -05:00
Adolfo Reyna
499b61c9a5 Fix CommunityChestModalGame getting stuck after dismissal by correctly deleting it 2026-02-06 23:19:40 -05:00
Adolfo Reyna
64f61759d7 Fix emulator compilation and crash, and implement Monopoly payment modal 2026-02-06 23:13:32 -05:00
Adolfo Reyna
75e17fb26b Add friction to mindless clicking by disabling default action preselection in Monopoly menus 2026-02-06 22:45:16 -05:00
Adolfo Reyna
e2817262b0 Add virtual touch buttons for Monopoly game and centralize configuration in ModalButtonHelper 2026-02-06 22:11:24 -05:00
Adolfo Reyna
eb86c3fc0e Integrate thematic sprites and improve Monopoly UI 2026-02-02 23:14:14 -05:00
Adolfo Reyna
3bdbfb1811 Fix 1-bit bitmap rendering and add player turn modal 2026-02-02 23:14:11 -05:00
Adolfo Reyna
d5a80235b4 improve board view with visual cues of the properties owned 2026-01-31 23:02:25 -05:00
Adolfo Reyna
63c4324561 monopoly Main UI Changes 2026-01-31 22:46:33 -05:00
Adolfo Reyna
c6d7bd6c8c monopoly Main UI Changes 2026-01-31 22:46:26 -05:00
Adolfo Reyna
78b376ad5d fix rent calculation 2026-01-31 22:23:49 -05:00
Adolfo Reyna
fa4c6f00ca monopoly board 2026-01-31 22:00:46 -05:00
Adolfo Reyna
561f7c5951 interpreting monopoly as multi scree game 2026-01-31 19:05:58 -05:00
Adolfo Reyna
2165186b6b interpreting monopoly as multi scree game 2026-01-31 19:05:49 -05:00
Adolfo Reyna
ab75dbd322 monopoly 2026-01-31 18:50:50 -05:00
Adolfo Reyna
cad1aad2c8 initial monopoly test 2026-01-31 09:45:40 -05:00
Adolfo Reyna
3a1e278c4c Fix font handling: use const Font* for get_current_font and all GUI font save/restore logic 2026-01-31 09:45:29 -05:00
Adolfo Reyna
76a74477a7 emulator working 2026-01-30 23:40:10 -05:00
Adolfo Reyna
c1423b66aa First working version of desktop emulator with game launcher support. Includes local stubs and launcher logic. 2026-01-30 23:35:43 -05:00
Adolfo Reyna
d2fd001e70 Add display color inversion flag and logic for Feather TFT 2026-01-30 23:02:53 -05:00
Adolfo Reyna
45cbcc8384 fix touch 2026-01-30 22:52:25 -05:00
Adolfo Reyna
30c3c2a066 full refresh between game changes 2026-01-30 22:11:12 -05:00
Adolfo Reyna
f860d4f5e6 input manager provides ground of truth on device input choise 2026-01-30 22:07:31 -05:00
Adolfo Reyna
436245a7a2 Fix render issues with fonts 2026-01-30 22:02:15 -05:00
Adolfo Reyna
e3445b545d Initial game launcher 2026-01-30 21:39:09 -05:00
Adolfo Reyna
2a6861fdf5 refactored to multiple games implementation 2026-01-30 21:33:42 -05:00