shithub: m8c

Download patch

ref: 801ff4c1769a417308965b9bbf64630ec91a981a
parent: 393a3e1397be03d7e34bcc65829dcebec18f2146
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Tue Apr 9 18:53:16 EDT 2024

add devcontainer file, prepare for model02 changes

--- /dev/null
+++ b/.devcontainer.json
@@ -1,0 +1,5 @@
+{
+    "build": {
+        "dockerfile": "Dockerfile"
+    }
+}
\ No newline at end of file
--- /dev/null
+++ b/Dockerfile
@@ -1,0 +1,2 @@
+FROM mcr.microsoft.com/devcontainers/cpp
+RUN apt-get update && apt-get install -y libsdl2-dev libserialport-dev
--- a/src/command.c
+++ b/src/command.c
@@ -18,7 +18,7 @@
   draw_character_command_datalength = 12,
   draw_oscilloscope_waveform_command = 0xFC,
   draw_oscilloscope_waveform_command_mindatalength = 1 + 3,
-  draw_oscilloscope_waveform_command_maxdatalength = 1 + 3 + 320,
+  draw_oscilloscope_waveform_command_maxdatalength = 1 + 3 + 480,
   joypad_keypressedstate_command = 0xFB,
   joypad_keypressedstate_command_datalength = 3,
   system_info_command = 0xFF,
@@ -144,7 +144,7 @@
       break;
     }
 
-    char *hwtype[3] = {"Headless", "Beta M8", "Production M8"};
+    char *hwtype[4] = {"Headless", "Beta M8", "Production M8", "Production M8 Model:02"};
 
     static int system_info_printed = 0;
 
@@ -152,6 +152,12 @@
       SDL_Log("** Hardware info ** Device type: %s, Firmware ver %d.%d.%d",
               hwtype[recv_buf[1]], recv_buf[2], recv_buf[3], recv_buf[4]);
       system_info_printed = 1;
+    }
+
+    if (recv_buf[1] == 0x03) {
+      set_mk2_mode(1);
+    } else {
+      set_mk2_mode(0);
     }
 
     if (recv_buf[5] == 0x01) {
--- a/src/command.h
+++ b/src/command.h
@@ -37,7 +37,7 @@
 
 struct draw_oscilloscope_waveform_command {
   struct color color;
-  uint8_t waveform[320];
+  uint8_t waveform[480];
   uint16_t waveform_size;
 };
 
--- a/src/fx_cube.c
+++ b/src/fx_cube.c
@@ -79,7 +79,7 @@
   SDL_memcpy(nodes, default_nodes, sizeof(default_nodes));
 
   scale(50, 50, 50);
-  rotate_cube(M_PI / 4, SDL_atan(SDL_sqrt(2)));
+  rotate_cube(M_PI / 6, SDL_atan(SDL_sqrt(2)));
 
   SDL_SetTextureBlendMode(texture_cube, SDL_BLENDMODE_BLEND);
   SDL_SetTextureBlendMode(texture_text, SDL_BLENDMODE_BLEND);
@@ -99,8 +99,8 @@
   SDL_SetRenderDrawColor(fx_renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
   SDL_RenderClear(fx_renderer);
 
-  int seconds = SDL_GetTicks() / 1000;
-  float scalefactor = 1 + (SDL_sin(seconds) * 0.01);
+  unsigned int seconds = SDL_GetTicks() / 1000;
+  float scalefactor = 1 + (SDL_sin(seconds) * 0.005);
 
   scale(scalefactor, scalefactor, scalefactor);
   rotate_cube(M_PI / 180, M_PI / 270);
--- a/src/main.c
+++ b/src/main.c
@@ -99,7 +99,7 @@
     // try to init serial port
     int port_inited = init_serial(1, preferred_device);
     // if port init was successful, try to enable and reset display
-    if (port_inited == 1 && enable_and_reset_display(0) == 1) {
+    if (port_inited == 1 && enable_and_reset_display() == 1) {
       // if audio routing is enabled, try to initialize audio devices
       if (conf.audio_enabled == 1) {
         audio_init(conf.audio_buffer_size, conf.audio_device_name);
--- a/src/render.c
+++ b/src/render.c
@@ -7,6 +7,7 @@
 #include <stdio.h>
 
 #include "SDL2_inprint.h"
+#include "SDL_video.h"
 #include "command.h"
 #include "fx_cube.h"
 
@@ -23,8 +24,15 @@
 static uint32_t ticks_fps;
 static int fps;
 static int large_font_enabled = 0;
+static int mk2_mode_enabled = 0;
 static int screen_offset_y = 0;
 
+static const int m8_mk1_texture_width = 320;
+static const int m8_mk1_texture_height = 240;
+static const int m8_mk2_texture_width = 480;
+static const int m8_mk2_texture_height = 320;
+
+
 uint8_t fullscreen = 0;
 
 static uint8_t dirty = 0;
@@ -33,9 +41,8 @@
 int initialize_sdl(int init_fullscreen, int init_use_gpu) {
   // ticks = SDL_GetTicks();
 
-  const int window_width = 640;  // SDL window width
-  const int window_height = 480; // SDL window height
 
+
   if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
     SDL_LogCritical(SDL_LOG_CATEGORY_ERROR, "SDL_Init: %s\n", SDL_GetError());
     return -1;
@@ -44,7 +51,7 @@
   atexit(SDL_Quit);
 
   win = SDL_CreateWindow("m8c", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
-                         window_width, window_height,
+                         m8_mk1_texture_width * 2, m8_mk1_texture_height * 2,
                          SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL |
                              SDL_WINDOW_RESIZABLE | init_fullscreen);
 
@@ -51,7 +58,7 @@
   rend = SDL_CreateRenderer(
       win, -1, init_use_gpu ? SDL_RENDERER_ACCELERATED : SDL_RENDERER_SOFTWARE);
 
-  SDL_RenderSetLogicalSize(rend, 320, 240);
+  SDL_RenderSetLogicalSize(rend, m8_mk1_texture_width, m8_mk1_texture_height);
 
   maintexture = SDL_CreateTexture(rend, SDL_PIXELFORMAT_ARGB8888,
                                   SDL_TEXTUREACCESS_TARGET, 320, 240);
@@ -80,15 +87,64 @@
   prepare_inline_font(font->bits, font->width, font->height);
 }
 
+void set_mk2_mode(int enabled) {
+
+  int h, w;
+
+  if (enabled) {
+    mk2_mode_enabled = 1;
+    // Query window size and resize if smaller than default
+    SDL_GetWindowSize(win, &w, &h);
+    if (w < (m8_mk2_texture_width * 2) || h < (m8_mk2_texture_height * 2)) {
+      SDL_SetWindowSize(win, (m8_mk2_texture_width * 2),
+                        (m8_mk2_texture_height * 2));
+    }
+
+    SDL_RenderSetLogicalSize(rend, m8_mk2_texture_width, m8_mk2_texture_height);
+
+    SDL_DestroyTexture(maintexture);
+    maintexture = SDL_CreateTexture(rend, SDL_PIXELFORMAT_ARGB8888,
+                                    SDL_TEXTUREACCESS_TARGET, m8_mk2_texture_width, m8_mk2_texture_height);
+
+    // Initialize and activate the MK2 font
+    set_large_mode(large_font_enabled);
+  } else if (mk2_mode_enabled == 1) {
+    // In the rare case that a MK2 is changed to MK1 without quitting first
+    
+    mk2_mode_enabled = 0;
+    // Query window size and resize if smaller than default
+    SDL_GetWindowSize(win, &w, &h);
+    if (w < (m8_mk1_texture_width * 2) || h < (m8_mk1_texture_height * 2)) {
+      SDL_SetWindowSize(win, (m8_mk1_texture_height * 2),
+                        (m8_mk1_texture_width * 2));
+    }
+
+    SDL_DestroyTexture(maintexture);
+    maintexture = SDL_CreateTexture(rend, SDL_PIXELFORMAT_ARGB8888,
+                                    SDL_TEXTUREACCESS_TARGET, m8_mk1_texture_width, m8_mk1_texture_height);
+
+    // Initialize and activate the MK2 font
+    set_large_mode(large_font_enabled);
+  }
+}
+
 void set_large_mode(int enabled) {
   if (enabled) {
     large_font_enabled = 1;
-    screen_offset_y = 40;
-    change_font(&inline_font_large);
+    if (mk2_mode_enabled == 1) {
+      // TODO mk2 changes
+    } else {
+      screen_offset_y = 40;
+      change_font(&inline_font_large);
+    }
   } else {
-    large_font_enabled = 0;
-    screen_offset_y = 0;
-    change_font(&inline_font_small);
+    if (mk2_mode_enabled == 1) {
+      // TODO mk2 changes
+    } else {
+      large_font_enabled = 0;
+      screen_offset_y = 0;
+      change_font(&inline_font_small);
+    }
   }
 }
 
@@ -148,7 +204,8 @@
   // Background color changed
   if (render_rect.x == 0 && render_rect.y <= 0 && render_rect.w == 320 &&
       render_rect.h >= 240) {
-    SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "BG color change: %d %d %d",command->color.r,command->color.g,command->color.b);
+    SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "BG color change: %d %d %d",
+                 command->color.r, command->color.g, command->color.b);
     background_color.r = command->color.r;
     background_color.g = command->color.g;
     background_color.b = command->color.b;
--- a/src/render.h
+++ b/src/render.h
@@ -13,6 +13,7 @@
 void draw_rectangle(struct draw_rectangle_command *command);
 int draw_character(struct draw_character_command *command);
 void set_large_mode(int enabled);
+void set_mk2_mode(int enabled);
 void view_changed(int view);
 
 void render_screen();
--- a/src/serial.h
+++ b/src/serial.h
@@ -4,6 +4,7 @@
 #ifndef _SERIAL_H_
 #define _SERIAL_H_
 
+#include <stdint.h>
 #ifdef USE_LIBUSB
 // Max packet length of the USB endpoint
 #define serial_read_size 512
--