Lua 5.3 didn't need an x86 emulator. But now, it has one regardless.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

platform_curses.lua 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. os.setlocale('')
  2. local curses = require "curses"
  3. local cp437_trans = require "table_cp437"
  4. dofile("kbdmaps.lua")
  5. function platform_sleep(t)
  6. -- for what pvrpose
  7. os.execute("sleep " .. tonumber(t))
  8. end
  9. local stdscr = curses.initscr()
  10. curses.cbreak()
  11. curses.echo(false)
  12. curses.nl(false)
  13. stdscr:clear()
  14. stdscr:nodelay(true)
  15. stdscr:scrollok(true)
  16. stdscr:keypad(true)
  17. function platform_beep(freq)
  18. emu_debug(2, "BEEP " .. freq)
  19. end
  20. function platform_key_down(v)
  21. return false
  22. end
  23. function emu_debug(level, s, tb)
  24. if level >= 1 then
  25. io.stderr:write(s .. "\n")
  26. if tb then debug.traceback() end
  27. io.stderr:flush()
  28. end
  29. end
  30. local queued_up = {}
  31. -- non-blocking, returns (ascii char, bios scan code) or nil on none
  32. function platform_getc()
  33. local c = stdscr:getch()
  34. if c == nil then return nil end
  35. if type(c) == "string" then c = string.byte() end
  36. if c == 263 then c = 8 end
  37. emu_debug(2, string.format("getc %d", c))
  38. if map_char_to_key[c] then
  39. if c >= 0 and c < 128 then return c,map_char_to_key[c]
  40. else return 0,map_char_to_key[c] end
  41. end
  42. return nil
  43. end
  44. function platform_error(msg)
  45. curses.endwin()
  46. print(msg)
  47. print(debug.traceback())
  48. end
  49. local function platform_kbd_tick()
  50. local getmore = true
  51. while getmore do
  52. if #queued_up > 0 then
  53. kbd_send_ibm(queued_up[1][1], queued_up[1][2])
  54. table.remove(queued_up, 1)
  55. end
  56. local ch, code = platform_getc()
  57. if ch ~= nil then
  58. kbd_send_ibm(code, ch)
  59. -- queued_up[#queued_up+1] = {code | 0x80, ch}
  60. else getmore = false end
  61. end
  62. end
  63. function platform_render_cga_mono(vram, addr)
  64. platform_kbd_tick()
  65. end
  66. function platform_render_mcga_13h(vram, addr)
  67. platform_kbd_tick()
  68. end
  69. function platform_render_pcjr_160(vram, addr)
  70. platform_kbd_tick()
  71. end
  72. function platform_render_pcjr_320(vram, addr)
  73. platform_kbd_tick()
  74. end
  75. function platform_render_text(vram, addr, width, height, pitch)
  76. platform_kbd_tick()
  77. local dlines = video_pop_dirty_lines()
  78. for y,v in pairs(dlines) do
  79. local base = addr + (y * pitch)
  80. for x=0,width-1 do
  81. local chr = cp437_trans[vram[base + x*2] or 0]
  82. local atr = vram[base + x*2 + 1] or 0
  83. stdscr:mvaddstr(y, x, utf8.char(chr))
  84. end
  85. end
  86. stdscr:refresh()
  87. end
  88. function platform_finish()
  89. curses.endwin()
  90. end
  91. dofile("emu_core.lua")