karl2d.odin 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. package karl2d
  2. import "base:runtime"
  3. import "core:mem"
  4. import "core:log"
  5. import "core:math"
  6. import "core:math/linalg"
  7. import "core:slice"
  8. import "core:image"
  9. import "core:image/bmp"
  10. import "core:image/png"
  11. import "core:image/tga"
  12. import hm "handle_map"
  13. _ :: bmp
  14. _ :: png
  15. _ :: tga
  16. Handle :: hm.Handle
  17. Texture_Handle :: distinct Handle
  18. // Opens a window and initializes some internal state. The internal state will use `allocator` for
  19. // all dynamically allocated memory. The return value can be ignored unless you need to later call
  20. // `set_state`.
  21. init :: proc(window_width: int, window_height: int, window_title: string,
  22. allocator := context.allocator, loc := #caller_location) -> ^State {
  23. s = new(State, allocator, loc)
  24. s.allocator = allocator
  25. s.custom_context = context
  26. s.width = window_width
  27. s.height = window_height
  28. s.wi = WINDOW_INTERFACE_WIN32
  29. wi = s.wi
  30. window_state_alloc_error: runtime.Allocator_Error
  31. s.window_state, window_state_alloc_error = mem.alloc(wi.state_size())
  32. log.assertf(window_state_alloc_error == nil, "Failed allocating memory for window state: %v", window_state_alloc_error)
  33. wi.init(s.window_state, window_width, window_height, window_title, allocator)
  34. s.window = wi.window_handle()
  35. s.rb = BACKEND_D3D11
  36. rb_alloc_error: runtime.Allocator_Error
  37. s.rb_state, rb_alloc_error = mem.alloc(s.rb.state_size())
  38. log.assertf(rb_alloc_error == nil, "Failed allocating memory for rendering backend: %v", rb_alloc_error)
  39. s.proj_matrix = make_default_projection(window_width, window_height)
  40. s.view_matrix = 1
  41. s.rb.init(s.rb_state, s.window, window_width, window_height, allocator)
  42. s.vertex_buffer_cpu = make([]u8, VERTEX_BUFFER_MAX, allocator, loc)
  43. white_rect: [16*16*4]u8
  44. slice.fill(white_rect[:], 255)
  45. s.shape_drawing_texture = s.rb.load_texture(white_rect[:], 16, 16)
  46. s.default_shader = s.rb.load_shader(string(DEFAULT_SHADER_SOURCE), {
  47. .RG32_Float,
  48. .RG32_Float,
  49. .RGBA8_Norm,
  50. })
  51. return s
  52. }
  53. DEFAULT_SHADER_SOURCE :: #load("shader.hlsl")
  54. // Closes the window and cleans up the internal state.
  55. shutdown :: proc() {
  56. s.rb.destroy_texture(s.shape_drawing_texture)
  57. destroy_shader(s.default_shader)
  58. s.rb.shutdown()
  59. delete(s.vertex_buffer_cpu, s.allocator)
  60. wi.shutdown()
  61. a := s.allocator
  62. free(s.window_state, a)
  63. free(s.rb_state, a)
  64. free(s, a)
  65. s = nil
  66. }
  67. // Clear the backbuffer with supplied color.
  68. clear :: proc(color: Color) {
  69. s.rb.clear(color)
  70. }
  71. // Present the backbuffer. Call at end of frame to make everything you've drawn appear on the screen.
  72. present :: proc() {
  73. draw_current_batch()
  74. s.rb.present()
  75. }
  76. // Call at start or end of frame to process all events that have arrived to the window.
  77. //
  78. // WARNING: Not calling this will make your program impossible to interact with.
  79. process_events :: proc() {
  80. s.keys_went_up = {}
  81. s.keys_went_down = {}
  82. wi.process_events()
  83. events := wi.get_events()
  84. for &event in events {
  85. switch &e in event {
  86. case Window_Event_Close_Wanted:
  87. s.shutdown_wanted = true
  88. case Window_Event_Key_Went_Down:
  89. s.keys_went_down[e.key] = true
  90. s.keys_is_held[e.key] = true
  91. case Window_Event_Key_Went_Up:
  92. s.keys_is_held[e.key] = false
  93. s.keys_went_up[e.key] = true
  94. }
  95. }
  96. wi.clear_events()
  97. }
  98. /* Flushes the current batch. This sends off everything to the GPU that has been queued in the
  99. current batch. Normally, you do not need to do this manually. It is done automatically when these
  100. procedures run:
  101. present
  102. set_camera
  103. set_shader
  104. TODO: complete this list and motivate why it needs to happen on those procs (or do that in the
  105. docs for those procs).
  106. */
  107. draw_current_batch :: proc() {
  108. shader := s.batch_shader.? or_else s.default_shader
  109. s.rb.draw(shader, s.batch_texture, s.vertex_buffer_cpu[:s.vertex_buffer_cpu_used])
  110. s.vertex_buffer_cpu_used = 0
  111. }
  112. // Can be used to restore the internal state using the pointer returned by `init`. Useful after
  113. // reloading the library (for example, when doing code hot reload).
  114. set_internal_state :: proc(state: ^State) {
  115. s = state
  116. s.rb.set_internal_state(s.rb_state)
  117. }
  118. get_screen_width :: proc() -> int {
  119. return s.rb.get_swapchain_width()
  120. }
  121. get_screen_height :: proc() -> int {
  122. return s.rb.get_swapchain_height()
  123. }
  124. key_went_down :: proc(key: Keyboard_Key) -> bool {
  125. return s.keys_went_down[key]
  126. }
  127. key_went_up :: proc(key: Keyboard_Key) -> bool {
  128. return s.keys_went_up[key]
  129. }
  130. key_is_held :: proc(key: Keyboard_Key) -> bool {
  131. return s.keys_is_held[key]
  132. }
  133. shutdown_wanted :: proc() -> bool {
  134. return s.shutdown_wanted
  135. }
  136. set_window_position :: proc(x: int, y: int) {
  137. wi.set_position(x, y)
  138. }
  139. set_window_size :: proc(width: int, height: int) {
  140. panic("Not implemented")
  141. }
  142. set_camera :: proc(camera: Maybe(Camera)) {
  143. if camera == s.batch_camera {
  144. return
  145. }
  146. draw_current_batch()
  147. s.batch_camera = camera
  148. s.proj_matrix = make_default_projection(s.width, s.height)
  149. if c, c_ok := camera.?; c_ok {
  150. origin_trans := linalg.matrix4_translate(vec3_from_vec2(-c.origin))
  151. translate := linalg.matrix4_translate(vec3_from_vec2(c.target))
  152. rot := linalg.matrix4_rotate_f32(c.rotation * math.RAD_PER_DEG, {0, 0, 1})
  153. camera_matrix := translate * rot * origin_trans
  154. s.view_matrix = linalg.inverse(camera_matrix)
  155. s.proj_matrix[0, 0] *= c.zoom
  156. s.proj_matrix[1, 1] *= c.zoom
  157. } else {
  158. s.view_matrix = 1
  159. }
  160. s.rb.set_view_projection_matrix(s.proj_matrix * s.view_matrix)
  161. }
  162. load_texture_from_file :: proc(filename: string) -> Texture {
  163. img, img_err := image.load_from_file(filename, options = {.alpha_add_if_missing}, allocator = context.temp_allocator)
  164. if img_err != nil {
  165. log.errorf("Error loading texture %v: %v", filename, img_err)
  166. return {}
  167. }
  168. backend_tex := s.rb.load_texture(img.pixels.buf[:], img.width, img.height)
  169. return {
  170. handle = backend_tex,
  171. width = img.width,
  172. height = img.height,
  173. }
  174. }
  175. destroy_texture :: proc(tex: Texture) {
  176. s.rb.destroy_texture(tex.handle)
  177. }
  178. draw_rect :: proc(r: Rect, c: Color) {
  179. if s.batch_texture != TEXTURE_NONE && s.batch_texture != s.shape_drawing_texture {
  180. draw_current_batch()
  181. }
  182. s.batch_texture = s.shape_drawing_texture
  183. _batch_vertex({r.x, r.y}, {0, 0}, c)
  184. _batch_vertex({r.x + r.w, r.y}, {1, 0}, c)
  185. _batch_vertex({r.x + r.w, r.y + r.h}, {1, 1}, c)
  186. _batch_vertex({r.x, r.y}, {0, 0}, c)
  187. _batch_vertex({r.x + r.w, r.y + r.h}, {1, 1}, c)
  188. _batch_vertex({r.x, r.y + r.h}, {0, 1}, c)
  189. }
  190. draw_rect_outline :: proc(r: Rect, thickness: f32, color: Color) {
  191. t := thickness
  192. // Based on DrawRectangleLinesEx from Raylib
  193. top := Rect {
  194. r.x,
  195. r.y,
  196. r.w,
  197. t,
  198. }
  199. bottom := Rect {
  200. r.x,
  201. r.y + r.h - t,
  202. r.w,
  203. t,
  204. }
  205. left := Rect {
  206. r.x,
  207. r.y + t,
  208. t,
  209. r.h - t * 2,
  210. }
  211. right := Rect {
  212. r.x + r.w - t,
  213. r.y + t,
  214. t,
  215. r.h - t * 2,
  216. }
  217. draw_rect(top, color)
  218. draw_rect(bottom, color)
  219. draw_rect(left, color)
  220. draw_rect(right, color)
  221. }
  222. draw_circle :: proc(center: Vec2, radius: f32, color: Color) {
  223. panic("not implemented")
  224. }
  225. draw_line :: proc(start: Vec2, end: Vec2, thickness: f32, color: Color) {
  226. }
  227. draw_texture :: proc(tex: Texture, pos: Vec2, tint := WHITE) {
  228. draw_texture_ex(
  229. tex,
  230. {0, 0, f32(tex.width), f32(tex.height)},
  231. {pos.x, pos.y, f32(tex.width), f32(tex.height)},
  232. {},
  233. 0,
  234. tint,
  235. )
  236. }
  237. draw_texture_rect :: proc(tex: Texture, rect: Rect, pos: Vec2, tint := WHITE) {
  238. draw_texture_ex(
  239. tex,
  240. rect,
  241. {pos.x, pos.y, rect.w, rect.h},
  242. {},
  243. 0,
  244. tint,
  245. )
  246. }
  247. draw_texture_ex :: proc(tex: Texture, src: Rect, dst: Rect, origin: Vec2, rotation: f32, tint := WHITE) {
  248. if tex.width == 0 || tex.height == 0 {
  249. return
  250. }
  251. if s.batch_texture != TEXTURE_NONE && s.batch_texture != tex.handle {
  252. draw_current_batch()
  253. }
  254. r := dst
  255. r.x -= origin.x
  256. r.y -= origin.y
  257. s.batch_texture = tex.handle
  258. tl, tr, bl, br: Vec2
  259. // Rotation adapted from Raylib's "DrawTexturePro"
  260. if rotation == 0 {
  261. x := dst.x - origin.x
  262. y := dst.y - origin.y
  263. tl = { x, y }
  264. tr = { x + dst.w, y }
  265. bl = { x, y + dst.h }
  266. br = { x + dst.w, y + dst.h }
  267. } else {
  268. sin_rot := math.sin(rotation * math.RAD_PER_DEG)
  269. cos_rot := math.cos(rotation * math.RAD_PER_DEG)
  270. x := dst.x
  271. y := dst.y
  272. dx := -origin.x
  273. dy := -origin.y
  274. tl = {
  275. x + dx * cos_rot - dy * sin_rot,
  276. y + dx * sin_rot + dy * cos_rot,
  277. }
  278. tr = {
  279. x + (dx + dst.w) * cos_rot - dy * sin_rot,
  280. y + (dx + dst.w) * sin_rot + dy * cos_rot,
  281. }
  282. bl = {
  283. x + dx * cos_rot - (dy + dst.h) * sin_rot,
  284. y + dx * sin_rot + (dy + dst.h) * cos_rot,
  285. }
  286. br = {
  287. x + (dx + dst.w) * cos_rot - (dy + dst.h) * sin_rot,
  288. y + (dx + dst.w) * sin_rot + (dy + dst.h) * cos_rot,
  289. }
  290. }
  291. ts := Vec2{f32(tex.width), f32(tex.height)}
  292. up := Vec2{src.x, src.y} / ts
  293. us := Vec2{src.w, src.h} / ts
  294. c := tint
  295. _batch_vertex(tl, up, c)
  296. _batch_vertex(tr, up + {us.x, 0}, c)
  297. _batch_vertex(br, up + us, c)
  298. _batch_vertex(tl, up, c)
  299. _batch_vertex(br, up + us, c)
  300. _batch_vertex(bl, up + {0, us.y}, c)
  301. }
  302. load_shader :: proc(shader_source: string, layout_formats: []Shader_Input_Format = {}) -> Shader {
  303. return s.rb.load_shader(shader_source, layout_formats)
  304. }
  305. destroy_shader :: proc(shader: Shader) {
  306. s.rb.destroy_shader(shader)
  307. }
  308. set_shader :: proc(shader: Maybe(Shader)) {
  309. if maybe_handle_equal(shader, s.batch_shader) {
  310. return
  311. }
  312. draw_current_batch()
  313. s.batch_shader = shader
  314. }
  315. maybe_handle_equal :: proc(m1: Maybe($T), m2: Maybe(T)) -> bool {
  316. if m1 == nil && m2 == nil {
  317. return true
  318. }
  319. m1v, m1v_ok := m1.?
  320. m2v, m2v_ok := m2.?
  321. if !m1v_ok || !m2v_ok {
  322. return false
  323. }
  324. return m1v.handle == m2v.handle
  325. }
  326. set_shader_constant :: proc(shd: Shader, loc: Shader_Constant_Location, val: $T) {
  327. draw_current_batch()
  328. if int(loc.buffer_idx) >= len(shd.constant_buffers) {
  329. log.warnf("Constant buffer idx %v is out of bounds", loc.buffer_idx)
  330. return
  331. }
  332. b := &shd.constant_buffers[loc.buffer_idx]
  333. if int(loc.offset) + size_of(val) > len(b.cpu_data) {
  334. log.warnf("Constant buffer idx %v is trying to be written out of bounds by at offset %v with %v bytes", loc.buffer_idx, loc.offset, size_of(val))
  335. return
  336. }
  337. dst := (^T)(&b.cpu_data[loc.offset])
  338. dst^ = val
  339. }
  340. set_shader_constant_mat4 :: proc(shader: Shader, loc: Shader_Constant_Location, val: matrix[4,4]f32) {
  341. set_shader_constant(shader, loc, val)
  342. }
  343. set_shader_constant_f32 :: proc(shader: Shader, loc: Shader_Constant_Location, val: f32) {
  344. set_shader_constant(shader, loc, val)
  345. }
  346. set_shader_constant_vec2 :: proc(shader: Shader, loc: Shader_Constant_Location, val: Vec2) {
  347. set_shader_constant(shader, loc, val)
  348. }
  349. get_default_shader :: proc() -> Shader {
  350. return s.default_shader
  351. }
  352. set_scissor_rect :: proc(scissor_rect: Maybe(Rect)) {
  353. panic("not implemented")
  354. }
  355. screen_to_world :: proc(pos: Vec2, camera: Camera) -> Vec2 {
  356. panic("not implemented")
  357. }
  358. draw_text :: proc(text: string, pos: Vec2, font_size: f32, color: Color) {
  359. }
  360. mouse_button_went_down :: proc(button: Mouse_Button) -> bool {
  361. panic("not implemented")
  362. }
  363. mouse_button_went_up :: proc(button: Mouse_Button) -> bool {
  364. panic("not implemented")
  365. }
  366. mouse_button_is_held :: proc(button: Mouse_Button) -> bool {
  367. panic("not implemented")
  368. }
  369. get_mouse_wheel_delta :: proc() -> f32 {
  370. return 0
  371. }
  372. get_mouse_position :: proc() -> Vec2 {
  373. panic("not implemented")
  374. }
  375. _batch_vertex :: proc(v: Vec2, uv: Vec2, color: Color) {
  376. v := v
  377. if s.vertex_buffer_cpu_used == len(s.vertex_buffer_cpu) {
  378. panic("Must dispatch here")
  379. }
  380. shd := s.batch_shader.? or_else s.default_shader
  381. base_offset := s.vertex_buffer_cpu_used
  382. pos_offset := shd.default_input_offsets[.Position]
  383. uv_offset := shd.default_input_offsets[.UV]
  384. color_offset := shd.default_input_offsets[.Color]
  385. if pos_offset != -1 {
  386. (^Vec2)(&s.vertex_buffer_cpu[base_offset + pos_offset])^ = v
  387. }
  388. if uv_offset != -1 {
  389. (^Vec2)(&s.vertex_buffer_cpu[base_offset + uv_offset])^ = uv
  390. }
  391. if color_offset != -1 {
  392. (^Color)(&s.vertex_buffer_cpu[base_offset + color_offset])^ = color
  393. }
  394. override_offset: int
  395. for &o, idx in shd.input_overrides {
  396. input := &shd.inputs[idx]
  397. sz := shader_input_format_size(input.format)
  398. if o.used != 0 {
  399. mem.copy(&s.vertex_buffer_cpu[base_offset + override_offset], raw_data(&o.val), o.used)
  400. }
  401. override_offset += sz
  402. }
  403. s.vertex_buffer_cpu_used += shd.vertex_size
  404. }
  405. State :: struct {
  406. allocator: runtime.Allocator,
  407. custom_context: runtime.Context,
  408. wi: Window_Interface,
  409. window_state: rawptr,
  410. rb: Rendering_Backend,
  411. rb_state: rawptr,
  412. shutdown_wanted: bool,
  413. keys_went_down: #sparse [Keyboard_Key]bool,
  414. keys_went_up: #sparse [Keyboard_Key]bool,
  415. keys_is_held: #sparse [Keyboard_Key]bool,
  416. window: Window_Handle,
  417. width: int,
  418. height: int,
  419. shape_drawing_texture: Texture_Handle,
  420. batch_camera: Maybe(Camera),
  421. batch_shader: Maybe(Shader),
  422. batch_texture: Texture_Handle,
  423. view_matrix: Mat4,
  424. proj_matrix: Mat4,
  425. vertex_buffer_cpu: []u8,
  426. vertex_buffer_cpu_used: int,
  427. default_shader: Shader,
  428. }
  429. @(private="file")
  430. s: ^State
  431. wi: Window_Interface
  432. Shader_Input_Format :: enum {
  433. Unknown,
  434. RGBA32_Float,
  435. RGBA8_Norm,
  436. RGBA8_Norm_SRGB,
  437. RG32_Float,
  438. R32_Float,
  439. }
  440. Color :: [4]u8
  441. Vec2 :: [2]f32
  442. Vec3 :: [3]f32
  443. Mat4 :: matrix[4,4]f32
  444. Vec2i :: [2]int
  445. Rect :: struct {
  446. x, y: f32,
  447. w, h: f32,
  448. }
  449. Texture :: struct {
  450. handle: Texture_Handle,
  451. width: int,
  452. height: int,
  453. }
  454. Shader :: struct {
  455. handle: Shader_Handle,
  456. constant_buffers: []Shader_Constant_Buffer,
  457. constant_lookup: map[string]Shader_Constant_Location,
  458. constant_builtin_locations: [Shader_Builtin_Constant]Maybe(Shader_Constant_Location),
  459. inputs: []Shader_Input,
  460. input_overrides: []Shader_Input_Value_Override,
  461. default_input_offsets: [Shader_Default_Inputs]int,
  462. vertex_size: int,
  463. }
  464. Camera :: struct {
  465. target: Vec2,
  466. origin: Vec2,
  467. rotation: f32,
  468. zoom: f32,
  469. }
  470. // Support for up to 255 mouse buttons. Cast an int to type `Mouse_Button` to use things outside the
  471. // options presented here.
  472. Mouse_Button :: enum {
  473. Left,
  474. Right,
  475. Middle,
  476. Max = 255,
  477. }
  478. // TODO: These are just copied from raylib, we probably want a list of our own "default colors"
  479. WHITE :: Color { 255, 255, 255, 255 }
  480. BLACK :: Color { 0, 0, 0, 255 }
  481. GRAY :: Color{ 130, 130, 130, 255 }
  482. RED :: Color { 230, 41, 55, 255 }
  483. YELLOW :: Color { 253, 249, 0, 255 }
  484. BLUE :: Color { 0, 121, 241, 255 }
  485. MAGENTA :: Color { 255, 0, 255, 255 }
  486. DARKGRAY :: Color{ 80, 80, 80, 255 }
  487. GREEN :: Color{ 0, 228, 48, 255 }
  488. Shader_Handle :: distinct Handle
  489. SHADER_NONE :: Shader_Handle {}
  490. // Based on Raylib / GLFW
  491. Keyboard_Key :: enum {
  492. None = 0,
  493. // Alphanumeric keys
  494. Apostrophe = 39,
  495. Comma = 44,
  496. Minus = 45,
  497. Period = 46,
  498. Slash = 47,
  499. Zero = 48,
  500. One = 49,
  501. Two = 50,
  502. Three = 51,
  503. Four = 52,
  504. Five = 53,
  505. Six = 54,
  506. Seven = 55,
  507. Eight = 56,
  508. Nine = 57,
  509. Semicolon = 59,
  510. Equal = 61,
  511. A = 65,
  512. B = 66,
  513. C = 67,
  514. D = 68,
  515. E = 69,
  516. F = 70,
  517. G = 71,
  518. H = 72,
  519. I = 73,
  520. J = 74,
  521. K = 75,
  522. L = 76,
  523. M = 77,
  524. N = 78,
  525. O = 79,
  526. P = 80,
  527. Q = 81,
  528. R = 82,
  529. S = 83,
  530. T = 84,
  531. U = 85,
  532. V = 86,
  533. W = 87,
  534. X = 88,
  535. Y = 89,
  536. Z = 90,
  537. Left_Bracket = 91,
  538. Backslash = 92,
  539. Right_Bracket = 93,
  540. Grave = 96,
  541. // Function keys
  542. Space = 32,
  543. Escape = 256,
  544. Enter = 257,
  545. Tab = 258,
  546. Backspace = 259,
  547. Insert = 260,
  548. Delete = 261,
  549. Right = 262,
  550. Left = 263,
  551. Down = 264,
  552. Up = 265,
  553. Page_Up = 266,
  554. Page_Down = 267,
  555. Home = 268,
  556. End = 269,
  557. Caps_Lock = 280,
  558. Scroll_Lock = 281,
  559. Num_Lock = 282,
  560. Print_Screen = 283,
  561. Pause = 284,
  562. F1 = 290,
  563. F2 = 291,
  564. F3 = 292,
  565. F4 = 293,
  566. F5 = 294,
  567. F6 = 295,
  568. F7 = 296,
  569. F8 = 297,
  570. F9 = 298,
  571. F10 = 299,
  572. F11 = 300,
  573. F12 = 301,
  574. Left_Shift = 340,
  575. Left_Control = 341,
  576. Left_Alt = 342,
  577. Left_Super = 343,
  578. Right_Shift = 344,
  579. Right_Control = 345,
  580. Right_Alt = 346,
  581. Right_Super = 347,
  582. Menu = 348,
  583. // Keypad keys
  584. KP_0 = 320,
  585. KP_1 = 321,
  586. KP_2 = 322,
  587. KP_3 = 323,
  588. KP_4 = 324,
  589. KP_5 = 325,
  590. KP_6 = 326,
  591. KP_7 = 327,
  592. KP_8 = 328,
  593. KP_9 = 329,
  594. KP_Decimal = 330,
  595. KP_Divide = 331,
  596. KP_Multiply = 332,
  597. KP_Subtract = 333,
  598. KP_Add = 334,
  599. KP_Enter = 335,
  600. KP_Equal = 336,
  601. }