nes_port.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2022 Dozingfiretruck
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. */
  24. #include "nes.h"
  25. #include "luat_base.h"
  26. #include "luat_mem.h"
  27. #include "luat_timer.h"
  28. #include "luat_fs.h"
  29. #include "luat_lcd.h"
  30. /* memory */
  31. void *nes_malloc(int num){
  32. return luat_heap_malloc(num);
  33. }
  34. void nes_free(void *address){
  35. luat_heap_free(address);
  36. }
  37. void *nes_memcpy(void *str1, const void *str2, size_t n){
  38. return memcpy(str1, str2, n);
  39. }
  40. void *nes_memset(void *str, int c, size_t n){
  41. return memset(str,c,n);
  42. }
  43. int nes_memcmp(const void *str1, const void *str2, size_t n){
  44. return memcmp(str1,str2,n);
  45. }
  46. #if (NES_USE_FS == 1)
  47. /* io */
  48. FILE *nes_fopen( const char * filename, const char * mode ){
  49. return luat_fs_fopen(filename,mode);
  50. }
  51. size_t nes_fread(void *ptr, size_t size_of_elements, size_t number_of_elements, FILE *a_file){
  52. return luat_fs_fread(ptr, size_of_elements, number_of_elements,a_file);
  53. }
  54. int nes_fseek(FILE *stream, long int offset, int whence){
  55. return luat_fs_fseek(stream,offset,whence);
  56. }
  57. int nes_fclose( FILE *fp ){
  58. return luat_fs_fclose(fp);
  59. }
  60. #endif
  61. /* wait */
  62. void nes_wait(uint32_t ms){
  63. luat_timer_mdelay(ms);
  64. }
  65. static luat_lcd_conf_t* nes_lcd_conf;
  66. int nes_initex(nes_t *nes){
  67. nes_lcd_conf = luat_lcd_get_default();
  68. return 0;
  69. }
  70. int nes_deinitex(nes_t *nes){
  71. return 0;
  72. }
  73. int nes_draw(size_t x1, size_t y1, size_t x2, size_t y2, nes_color_t* color_data){
  74. return luat_lcd_draw(nes_lcd_conf, x1, y1, x2, y2, color_data);
  75. }
  76. void nes_frame(void){
  77. luat_timer_us_delay(10);
  78. }