vga.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* VGA: VESA LFB (from boot). Shadow buffer with 30Hz USWC flush. */
  2. #ifndef VGA_H
  3. #define VGA_H
  4. /* Boot video info at 0x600 (written by boot.S in safe conventional memory).
  5. Layout: valid(1) width(2) height(2) pitch(2) bpp(1) lfb_base(4) vram_64k(2) = 14 bytes. */
  6. struct vga_boot_fb_info {
  7. unsigned char valid;
  8. unsigned short width;
  9. unsigned short height;
  10. unsigned short pitch;
  11. unsigned char bpp;
  12. unsigned int lfb_base;
  13. unsigned short vram_64k; /* total VRAM in 64KB blocks (from VBE) */
  14. } __attribute__((packed));
  15. #define VGA_BOOT_FB ((volatile struct vga_boot_fb_info *)0x600)
  16. /* Shadow buffer lives at 1MB — safely above kernel, stacks, DMA, and program load area. */
  17. #define VGA_SHADOW_BASE 0x100000
  18. /* LFB API. RGB 0..255. All drawing goes into the shadow buffer; flush copies to VRAM at 30Hz. */
  19. unsigned int vga_fb_width(void);
  20. unsigned int vga_fb_height(void);
  21. unsigned int vga_fb_pitch(void);
  22. unsigned int vga_fb_bpp(void);
  23. unsigned int vga_fb_vram_kb(void);
  24. unsigned int vga_fb_pci_id(void);
  25. void *vga_fb_ptr(void);
  26. int vga_has_vesa(void);
  27. void vga_put_pixel_rgb(unsigned int x, unsigned int y, unsigned int r, unsigned int g, unsigned int b);
  28. void vga_fill_rect(unsigned int x, unsigned int y, unsigned int w, unsigned int h,
  29. unsigned int r, unsigned int g, unsigned int b);
  30. void vga_clear_rgb(unsigned int r, unsigned int g, unsigned int b);
  31. /* Tightly packed row-major: each row is w * pixel_bytes contiguous (pixel_bytes from bpp). */
  32. void vga_fb_read_rect(unsigned int x, unsigned int y, unsigned int w, unsigned int h,
  33. unsigned char *buf);
  34. void vga_fb_write_rect(unsigned int x, unsigned int y, unsigned int w, unsigned int h,
  35. const unsigned char *buf);
  36. /* Initialize shadow buffer (called once from kernel_main after vga_cache_boot_fb). */
  37. void vga_shadow_init(void);
  38. /* Copy shadow buffer to VRAM. Called by 30Hz timer or manually after init. */
  39. void vga_fb_flush(void);
  40. /* Flag set by PIT IRQ when 30Hz flush is due. Main loop checks and clears. */
  41. extern int vga_shadow_flush_pending;
  42. /* Called from main loop: if pending, copies shadow to VRAM and draws debug square. */
  43. void vga_fb_flush_pending_check(void);
  44. /* Returns 1 if shadow buffer is active, 0 if rendering directly to VRAM. */
  45. int vga_shadow_is_active(void);
  46. /* Mark rows dirty for direct buffer manipulators (e.g. fbtext_scroll). */
  47. void vga_fb_mark_dirty_rect(unsigned int y, unsigned int h);
  48. #endif