rpsubc8 / ESP32TinyCPC

AMSTRAD CPC Emulator TTGO VGA32
Do What The F*ck You Want To Public License
41 stars 6 forks source link

wish list! #1

Closed WacKEDmaN closed 3 years ago

WacKEDmaN commented 3 years ago

hello, ive just found this CPC emu for ESP32, i was wanting to do it myself for a long time!..but im hopeless at coding!.. 🙄

a few little issues im having,.. i cant find the ';' button! (semicolon) needed for basic print statements... or the '|' pipe key!.... sound is a little bit off.. like one of the channels needs to be set to noise only or something.. they sound a little too rich for cpc!😄

....emulation is a little slow at times... but i cant expect too much on that front!... 😛 some colors seem to be off aswell... but i guess thats just a limitation of the VGA32...

a few additions id like to see... option for 104 pc keyboard layout (eg " move near enter instead of cpcs shift+2) loading DSK from SDCARD..even if they are in your .h format... (possably roms too?) PSRAM support... my TTGO VGA32 v1.4 says it has 8MB PSRAM and 4MB FLASH...

thanks for putting the time and effort in to port this over and sharing it!...

rpsubc8 commented 3 years ago

Thank you very much.

I have not implemented all the key remapping, only the ones I needed for my tests.

In the CPCem.ino in the SDL_keys_poll procedure are the keys that are used. The ';' is cpckeys[3][4]= which is currently commented out, and will not work. In the next upload, I will add the key.

The '|' pipe key is achieved with the combination SHIFT+F10: cpckeys[3][2]= keymap[0x09];

The sound, I recreated a quick and simple version (dirty sound) of only 3 channels (the fourth one is not used). There are no envelopes or an analog output, in fact, an audio is output in binary volume mode (high and low), with no in-between. It's a fast, low CPU consumption solution, so at least it has sound, but it's not an exact recreation of CPC audio.

The color palette for the 64 color mode is defined in the CRTC.cpp at gb_const_colorNormal35. The video DAC is 6-bit BBGGRR, so it is not exact to the CPC, but very similar. It can be adjusted by changing the values.

If the emulation is slow, you have to play with the configuration parameters of the gbConfig.ini, specifically with the options use_lib_ultrafast_vga, and even changing the video mode use_lib_320x200_video_noborder, so you get double the speed. Also the gb_frame_crt_skip if set to 1, skips emulation frames, getting double speed. From the OSD menu you can lower the wait times, specifically if you set it to 0, the emulation is x3.

The use of psram, I will keep it in mind for future uploads. So far, I have focused more on dispensing with the psram, to be able to reach more ESP32 micros of low resources, as is the case of the TTGO VGA32 1.0, 1.1 and 1.2.

WacKEDmaN commented 3 years ago

i have tried adding use_lib_ultrafast_vga ..but i just get a black screen or crashing...same if i change to either of the 320x200 modes...same with both use_lib_128k and use_lib_vga_low_memory

ive also tryed changing frame skip and polling speeds, they do help on some games...ill have to try them all on 0!..i havent done that!... ,,fair enough on the PSRAM usage.. i guess the same goes for the SDCARD.. but the option would be nice :)

im using arduino ide.. and this config current, with 6128 somewhat working..97% app space usage on compile! (9 of my own dsks) .. also disabled BT you had commented out in the main ino,

#ifndef _GB_CONFIG_H
 #define _GB_CONFIG_H

 //usar raton amx
 #define use_lib_amx_mouse
 //zurdo
 //#define use_lib_amx_mouse_lefthanded

 //Video mode
 #define use_lib_400x300
 //#define use_lib_320x200_video_border
 //#define use_lib_320x200_video_noborder

 //Video colors
 //#define use_lib_vga8colors
 //#define use_lib_use_bright

 //Video ram consume
 //#define use_lib_vga_low_memory

 //Video CPU optimice speed
 //#define use_lib_ultrafast_vga

 //RAM mode
 #define use_lib_cheat_128k  
 //#define use_lib_128k
 #define use_lib_fix_psram_128k

 //Sound
 #define use_lib_sound_ay8912

 //Bank switch optimice speed
 #define usb_lib_optimice_checkchange_bankswitch

 //Usar tabla precalculada 256 bytes flash znptable
 #define use_lib_lookup_znptable
 //Usar tabla precalculada 64 KB flash znptable16
 #define use_lib_lookup_znptable16

 //Logs
 //#define use_lib_log_serial

 //Read mouse poll millis
 #define gb_ms_mouse 10
 //Read keyboard poll x millis
 #define gb_ms_keyboard 20
 //Read sound poll x millis
 #define gb_ms_sound 1
 //Skip x frames
 #define gb_frame_crt_skip 0
 //Delay millis iteration emulate
 #define gb_delay_emulate_ms 0

 #ifdef use_lib_128k
  #define use_lib_mem_blocks
 #endif 

 #ifdef use_lib_vga8colors
  #define COLOR_3B
 #else 
  #define COLOR_6B
 #endif

 //fabgl dependence
 // - use_lib_sound_ay8912

 //use_lib_vga8colors - 3 pin vga
 //use_lib_use_bright - 6 pin vga
#endif

thanks.. 👍 look forward to seeing any updates in the future! ...i have forked and may do a few tweaks if i can find them and get them working!

rpsubc8 commented 3 years ago

The emulator is designed for CPC 464 with 64KB. It is better to disable all 128K options to save the 64KB of RAM, and leave the 128K mode for experiments. In the case of the 6128, including the option, the extra consumption in FLASH of the ROM is added, as well as the RAM consumption. It is a not very stable mode, and given the low RAM of the TTGO VGA32 board, it leaves the system unstable, causing it to reboot. If the ESP32 has less than 70 KB free, it will be reset. The disabled BT option is intended to remove all Bluetooth resources, when the module is in use, to save RAM. But in most of the ESP32's that I have tested, you get just the opposite, when using this option, because including this call implies to have included other libraries, which consume RAM. 400x300 pixel with double buffering is 240 KB of RAM consumption just for the video. 320x200 with double buffering is 128 KB. For the 8-color mode, and without double buffering, it is 48 KB of RAM. The use_lib_vga_low_memory option is to not use double buffering, which saves half the video RAM, but that mode is very slow, on the order of half the emulation. You can only mitigate the speed, if you combine use_lib_vga_low_memory with use_lib_ultrafast_vga. The use_lib_ultrafast_vga option allows direct access to the video pointer, which translates to double the emulation speed. When you are in 128KB mode, you cannot use 400x300 with double buffering, because there is not enough RAM, in particular you have to use 320x200, and in most cases with the use_lib_vga_low_memory mode. You have to remove the 64 color mode and switch to 8 colors. This is only with 128K mode, because in 64K mode, we can have everything at maximum, there is no RAM problem. The use_lib_128k and use_lib_cheat_128k modes are the normal ones to enable 128K mode with SRAM, while use_lib_fix_psram_128k uses PSRAM. This psram mode requires uncommenting in the platformio the lines -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue or enable the psram option in the ARDUINO IDE. If you are not going to use psram, it is always best to disable psram, because we save resources and the board runs faster. This option of using psram, is for experiments I was doing, I do not recommend it. Even if the board has psram (TTGO VGA v1.4), you have to tell it not to use psram, and use only SRAM, either in 64K or 128K mode, unless you specifically want psram, with all the inconveniences of speed and power consumption. I always recommend using the 64K mode, unless you want to experiment. To save RAM, if you are not going to use the mouse, you have to disable use_lib_amx_mouse. The same for the sound use_lib_sound_ay8912. This way, we save RAM, FLASH and CPU, which does not have to check. Also comment use_lib_log_serial to not use the virtual serial port.

As for the gb_frame_crt_skip option, you have to put exactly:

define gb_frame_crt_skip 1

With the value to 1, we indicate that it is going to skip half of the frames, that being 50, it becomes 25, that is to say, that automatically it is twice as fast.

The DKS's I recommend that if it is possible to put the files of a DSK in another one, since many DSK's are half empty. In this way, we can compact and fit more games and programs in the FLASH. I don't recommend to reach the top of the FLASH (90%), because even if it records, it starts to do strange things. I don't use a single byte of RAM for FDD and DSK emulation. The whole disk structure is in Flash, being much more efficient, but with the problem, that you can't record on it.

Congratulations for the fork, the idea of the project is to create the basis, so that anyone can adapt it to their needs, improve it or do whatever they want.

WacKEDmaN commented 3 years ago

very strange that i can use 400x300 with 128K mode... but not the others... even with 128k mode disabled the other modes dont work..ill try try out some other combos and see that happens!

yup i thought of compacting dsk's alot are mostly empty... (AA covertapes coversions work nice!)

thanks for the write up.. gives me a bit to think about! :P

WacKEDmaN commented 3 years ago

so i disabled -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue in boards.txt for esp32 on arduino ide... now i can run the lower res modes.... use_lib_320x200_video_border is all squashed... like its CPC mode 2!...real mode 2 is unreadable!... use_lib_320x200_video_noborder working fine ... is guess i can live without the border :)

rpsubc8 commented 3 years ago

Thank you for the tests.

I have updated the repository, you can proceed to download the new update. I have raised the ';' key, it can be removed by pressing the 'ñ' key or the left shift key and the ','. I have accelerated the access in use_lib_ultrafast_vga and use_lib_vga_low_memory mode for 8 colors and 64 colors. Until now, the 8 color mode did not allow the combination use_lib_ultrafast_vga with use_lib_vga_low_memory. It is not important, because you would see only 8 colors, but it is useful for testing. If I am not mistaken, right now all possible combinations of each video mode would work with: use_lib_vga8colors use_lib_vga_low_memory use_lib_ultrafast_vga

The 128K mode requires a lot of SRAM, so either change the video mode to lower resolution, or use the use_lib_vga_low_memory, or remove the sound and mouse. You can only have all the options to the maximum, when you are in 464 mode. The emulator from the origin, is thought for CPC 464, the 664 and 6128 mode is extra.

If you enable it in the gbConfig.h (#define use_lib_log_serial), you can see the RAM consumption, and it is very disparate, depending on the options chosen, from 74 KB free, to 242 KB:

I'm glad it works for you: The psram and sram are different, that's why you have to disable the psram, because otherwise, modules, libraries, as well as RAM and CPU consumption are included, even if you don't use a single byte of PSRAM. In Arduino IDE, you can disable it from Tools (PSRAM_disabled). It's all explained in the documentation I left some time ago in the project:

https://github.com/rpsubc8/ESP32TinyCPC/blob/main/readmeEnglish.md

https://github.com/rpsubc8/ESP32TinyCPC/blob/main/readmeSpanish.md

The correct and comfortable display mode is 400x300. 320x200 modes with border and without border, I left them for testing, so you can run, but either you lose the border, or you lose quality. The CPC resolution in mode 2 is 640x200, which converts to 400x300, but in 320x200, you lose half the pixels. These are modes to save RAM and run mode 0 (160x200), 1 (320x200).

WacKEDmaN commented 3 years ago

thank you... i will check out the new repo tomorrow... i have read over the readme file multiple times already! :P

ill try to include some pics of the 320x200 mode with squashed fonts.. but as you said 400x300 is better ...and memory usage.. (i have ~10000 free after setup atm)

rpsubc8 commented 3 years ago

Thank you very much for your work. I think I understand the bug you are referring to in 320x200 mode with border (use_lib_320x200_video_border). It is a mode that I had for testing, where in addition to reduce to 320x200, removed half pixels of information, leaving a resolution of 160x200. Now it already takes out the correct pixels and I have left an aspect ratio for 320x200. Maybe you can use it as it is now. I have made another upload to the repository.

The memory of 10000 bytes free is very little. Below 71 KB ESP32 is unstable and won't start. If you can pass me your exact gbConfig.h file to try to simulate it.

WacKEDmaN commented 3 years ago

downloaded new repo.. default gbConfig.h works fine out of the box....(just serial turned on)

HEAP BEGIN 294860
RAM 294860
I2S TX
VGA 152752
END SETUP 152700

changed gbConfig.h to use_lib_320x200_video_border only... it fails to boot... it seems the I2S, VGA and Heap begin never happens...

HEAP BEGIN 290736
RAM 290736

added sound emulation...(400x300)

HEAP BEGIN 285744
RAM 290736
I2S TX
VGA 148628
END SETUP 147164

added use_lib_ultrafast_vga

HEAP BEGIN 285704
RAM 285704
I2S TX
VGA 148588
END SETUP 147124

added use_lib_vga_low_memory

HEAP BEGIN 285356
RAM 285356
I2S TX
VGA 159944
END SETUP 158484

added use_lib_128k (PSRAM enabled)

HEAP BEGIN 224788
RAM 224788
I2S TX
VGA 94384
END SETUP 92924

added use_lib_cheat_128k ..no mem change..

HEAP BEGIN 224788
RAM 224788
I2S TX
VGA 94384
END SETUP 92924

added use_lib_fix_psram_128k ..again no change...

HEAP BEGIN 224788
RAM 224788
I2S TX
VGA 94384
END SETUP 92924

added mouse... ...sometimes crashes or takes a while to boot with 128k set

HEAP BEGIN 224256
RAM 224256
I2S TX
VGA 93852
END SETUP 90184

i am occasionally seeing watchdog triggered... it sometimes does it after boot (any setting).. once it reloads it doesnt happen again until next power cycle...

E (29996) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (29996) task_wdt:  - IDLE0 (CPU 0)
E (29996) task_wdt: Tasks currently running:
E (29996) task_wdt: CPU 0: 
E (29996) task_wdt: CPU 1: loopTask
E (29996) task_wdt: Aborting.
abort() was called at PC 0x400eb6ab on core 0

ELF file SHA256: 0000000000000000

Backtrace: 0x4008555b:0x3ffbfa80 0x400857d9:0x3ffbfaa0 0x400eb6ab:0x3ffbfac0 0x40081d91:0x3ffbfae0 0x400e0327:0x3fffdf60 0x400e0484:0x3fffdf80 0x400e0730:0x3fffdfa0 0x40085dda:0x3fffdfe0

so looks like 320x200 with border is still broken... it doesnt boot at all (even with only that setting changed in gbConfig.h)

WacKEDmaN commented 3 years ago

so after some playing around with settings ive got it running sweet... these are my current settings...

#ifndef _GB_CONFIG_H
 #define _GB_CONFIG_H

 //usar raton amx
 //#define use_lib_amx_mouse // mouse as joystick!
 //zurdo
 //#define use_lib_amx_mouse_lefthanded  // swap buttons

 //Video mode
 #define use_lib_400x300 // best picture..
 //#define use_lib_320x200_video_border ..still squashed fonts..
 //#define use_lib_320x200_video_noborder 

 //Video colors
 //#define use_lib_vga8colorsfor

 //Video ram consume
 //#define use_lib_vga_low_memory // must use with 128k modes

 //Video CPU optimice speed
 #define use_lib_ultrafast_vga // major speedup! too fast?..adjust video polling in-game!

 //RAM mode
 //#define use_lib_128k  // needs PSRAM enabled
 //#define use_lib_cheat_128k 
 //#define use_lib_fix_psram_128k 

 //Sound
 #define use_lib_sound_ay8912 // channels are a little off..

  //Logs
 #define use_lib_log_serial // show mem usage in serial monitor..

 // no need to change anything below here...

 //Bank switch optimice speed
 #define usb_lib_optimice_checkchange_bankswitch

 //Usar tabla precalculada 256 bytes flash znptable
 #define use_lib_lookup_znptable
 //Usar tabla precalculada 64 KB flash znptable16
 #define use_lib_lookup_znptable16

 //Read mouse poll millis
 #define gb_ms_mouse 10
 //Read keyboard poll x millis
 #define gb_ms_keyboard 20
 //Read sound poll x millis
 #define gb_ms_sound 1
 //Skip x frames
 #define gb_frame_crt_skip 0
 //Delay millis iteration emulate
 #define gb_delay_emulate_ms 0

 #ifdef use_lib_128k
  #define use_lib_mem_blocks
 #endif 

 #ifdef use_lib_vga8colors
  #define COLOR_3B
 #else 
  #define COLOR_6B
 #endif

 //fabgl dependence
 // - use_lib_sound_ay8912

 //use_lib_vga8colors - 3 pin vga
 //use_lib_use_bright - 6 pin vga
#endif

Memory Usage...

HEAP BEGIN 290696
RAM 290696
I2S TX
VGA 148588
END SETUP 147124

without #define use_lib_ultrafast_vga, emulation seems a little slow..with it..it seems a little fast!!.. but i can change that with video polling from the menu depending on game...

use_lib_320x200_video_border works but it takes about 30sec to boot!..its much more readable now, but im gonna stick with 400x300

thanks again... ima try to add volume control to the menu 😃

rpsubc8 commented 3 years ago

Thank you very much for the proofs. I'm glad it works for you, as you have been able to check, playing with the parameter combinations, you get improvements, also not all ESP32 are the same.

From the results you attach me, you have to disable the psram in the Arduino IDE, not only as you have done, but in Tools --> Psram disabled, because as I said, even if we do not use any psram code, it is included in the project, consuming RAM, and CPU. Me with this configuration:

define use_lib_400x300.

define use_lib_ultrafast_vga

define use_lib_sound_ay8912

define usb_lib_optimice_checkchange_bankswitch

With psram enabled, I have 124004 bytes free, and disabled, 133832. The project is prepared for Visual Studio with Platform IDE, where you don't have to disable the psram, because it comes in the .INI.

Here are my settings: Here I can start the 6128

define use_lib_320x200_video_border

define use_lib_128k

define use_lib_sound_ay8912

define use_lib_ultrafast_vga

17:59:46.186 -> HEAP BEGIN 211884 17:59:46.186 -> RAM 211884 17:59:46.186 -> I2S TX 17:59:46.186 -> VGA 132212 17:59:46.186 -> END SETUP 130748

As you can see, for the 6128, I either go down to 320x200 or I remove the double buffer and the sound.

The 30 seconds wait at startup is very rare, either the psram is active, as I said, or you have the fabgl libraries that are not. This project requires fabgl 0.9.0. The IDE I use is IDE 1.8.11. I have not tested with others.

For CP464 mode, you can set all settings to maximum, even 400x300, because there is plenty of memory. The wathdog and reboot occurs, because there is not enough RAM.

The only mode where you have to enable psram is when you want 6128 mode with psram (very experimental):

define use_lib_fix_psram_128k

All other 6128 modes, do not require psram to be enabled (experimental):

define use_lib_128k

define use_lib_cheat_128k

I recommend you to activate:

define gb_frame_crt_skip 1

instead of:

define gb_frame_crt_crt_skip 0

It is x2 speed. With all the configurations I have mentioned, I have to reduce the speed of the emulator, because it goes in turbo mode.

WacKEDmaN commented 3 years ago

thank you... yup i think i have my head around the options now!..thanks for the clarification... i prefer changing frame skip from the menu.. it doesnt seen to need it with use_lib_ultrafast_vga..i guess only need it when running 128k...