; ****************************************************************************
; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - vidata.s
; ----------------------------------------------------------------------------
; Last Update: 29/07/2016
; ----------------------------------------------------------------------------
; Beginning: 16/01/2016
; ----------------------------------------------------------------------------
; Assembler: NASM version 2.11 (trdos386.s)
; ----------------------------------------------------------------------------
; Turkish Rational DOS
; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
;
; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
; vidata.inc (11/03/2015)
;
; Derived from 'IBM PC-AT' BIOS source code (1985) 
; ****************************************************************************

; Retro UNIX 386 v1 Kernel - VIDATA.S
; Last Modification: 11/03/2015
;		    (Data section for 'VIDEO.INC')	
;
; ///////// VIDEO DATA ///////////////

;----------------------------------------
;	VIDEO DISPLAY DATA AREA		;
;----------------------------------------
CRT_MODE:	db	3	; CURRENT DISPLAY MODE (TYPE)
CRT_MODE_SET:	db	29h	; CURRENT SETTING OF THE 3X8 REGISTER
				; (29h default setting for video mode 3)
				; Mode Select register Bits
				;   BIT 0 - 80x25 (1), 40x25 (0)
				;   BIT 1 - ALPHA (0), 320x200 GRAPHICS (1)
				;   BIT 2 - COLOR (0), BW (1)
				;   BIT 3 - Video Sig. ENABLE (1), DISABLE (0)
				;   BIT 4 - 640x200 B&W Graphics Mode (1)
				;   BIT 5 - ALPHA mode BLINKING (1)
				;   BIT 6, 7 - Not Used

; Mode 0 - 2Ch = 101100b	; 40x25 text, 16 gray colors
; Mode 1 - 28h = 101000b	; 40x25 text, 16 fore colors, 8 back colors
; Mode 2 - 2Dh = 101101b	; 80x25 text, 16 gray colors	
; Mode 3 - 29h = 101001b	; 80x25 text, 16 fore color, 8 back color
; Mode 4 - 2Ah = 101010b	; 320x200 graphics, 4 colors
; Mode 5 - 2Eh = 101110b	; 320x200 graphics, 4 gray colors
; Mode 6 - 1Eh = 011110b	; 640x200 graphics, 2 colors
; Mode 7 - 29h = 101001b	; 80x25 text, black & white colors
; Mode & 37h = Video signal OFF

; 24/06/2016
CRT_COLS:	db	80	; Number of columns

; 01/07/2016
CRT_PALETTE:	db 	0	; Current palette setting

; 03/07/2016
CHAR_HEIGHT:	db	16	; Default character height
VGA_VIDEO_CTL:	db	60h	; ROM BIOS DATA AREA Offset 87h
VGA_SWITCHES:	db 	0F9h	; Feature Bit Switches (the basic screen)
VGA_MODESET_CTL: db	051h	; Basic mode set options (VGA video flags)
				; ROM BIOS DATA AREA Offset 89h
				; Bit 7, 4 : Mode
				;	  01 : 400-line mode
				; Bit 6	: Display switch enabled =  1			
				; Bit 5	: Reserved  = 0
				; Bit 3	: Default palette loading 
				;	  disabled = 0
				; Bit 2 : Color monitor = 0
				; Bit 1 = Gray scale summing 
				;	  disabled = 0
				; Bit 0 = VGA active = 1
VGA_ROWS:	db	25

; 16/01/2016
chr_attrib:  ; Character color/attributes for viode pages (0 to 7)
	db	07h, 07h, 07h, 07h, 07h, 07h, 07h, 07h
; 30/01/2016
vmode:
	db	3,3,3,3,3,3,3,3 ; video modes for pseudo screens 

CURSOR_MODE: ; cursor start (ch) = 14, cursor end (cl) = 15
	db	15, 14 ; 07/07/2016 - TRDOS 386 (TRDOS v2.0)

;align 4
;VGA_BASE: ; 26/07/2016
;	dd	 0B8000h  ; (Mode < 0Dh) or 0A0000h (mode >= 0Dh)

align 2

vga_modes:
	; 25/07/2016
	; 09/07/2016
	; 03/07/2016
	; valid (implemented) video modes (>7, extension to IBM PC CGA modes)
	db 	03h, 02h, 01h, 00h, 07h, 04h, 05h, 06h
	db	13h, 0F0h, 12h, 6Ah, 0Dh, 0Eh, 10h, 11h
vga_mode_count equ $ - vga_modes

vga_mode_tbl_ptr:
	; 25/07/2016
	dd	vga_mode_03h
	dd	vga_mode_03h ; mode 02h -> mode 03h 
	dd	vga_mode_01h
	dd	vga_mode_01h ; mode 00h -> mode 01h
	;dd	vga_mode_07h
	dd	vga_mode_03h ; mode 07h -> mode 03h
	dd	vga_mode_04h
	dd	vga_mode_04h ; mode 05h -> mode 04h	
	dd	vga_mode_06h
	dd	vga_mode_13h
	dd	vga_mode_F0h
	dd	vga_mode_12h
	dd	vga_mode_6Ah
	dd	vga_mode_0Dh
	dd	vga_mode_0Eh
	dd	vga_mode_10h
	dd	vga_mode_11h	

vga_memmodel: 
	; 25/07/2016
	; 07/07/2016
	CTEXT	equ 0
	;MTEXT	equ 1
	MTEXT	equ 0 ; mode 07h -> mode 03h
	CGA	equ 2
	LINEAR8 equ 5
	PLANAR4	equ 4
	PLANAR1	equ 3
	db	CTEXT, CTEXT, CTEXT, CTEXT, MTEXT, CGA, CGA, CGA
	db	LINEAR8, PLANAR4, PLANAR4, PLANAR4, PLANAR4, PLANAR4, PLANAR4, PLANAR1
;vga_pixbits:
;	; 25/07/2016
;	; 08/07/2016
;	db 	4, 4, 4, 4, 4, 2, 2, 1, 8, 4, 4, 4, 4, 4, 4, 1
vga_dac_s:
	db	2, 2, 2, 2, 0, 1, 1, 1, 3, 3, 2, 2, 1, 1, 2, 2

vga_params:
	; 25/07/2016 
	; 19/07/2016
	; 03/07/2016
	; derived from 'Plex86/Bochs VGABios' source code
	; vgabios-0.7a (2011)
	; by the LGPL VGABios Developers Team (2001-2008)
	; 'vgatables.h'
	; Oracle VirtualBox 5.0.24 VGABios Source Code
	; ('vgabios.c', 'vgatables.h', 'vgafonts.h', 'vgarom.asm')
	;
vga_mode_03h:  ; mode 03h, 80*25 text, CGA colors
 	db	80, 24, 16, 00h, 10h ; tw, th-1, ch, slength (5)
 	db	00h, 03h, 00h, 02h ; sequ regs (4)
 	db	67h	; misc reg (1)
 	db	5Fh, 4Fh, 50h, 82h, 55h, 81h, 0BFh, 1Fh
 	db	00h, 4Fh
vga_p_cm_pos equ $ - vga_mode_03h
	db	0Dh, 0Eh, 00h, 00h, 00h, 00h
 	db	9Ch, 8Eh, 8Fh, 28h, 1Fh, 96h, 0B9h, 0A3h
	db	0FFh	; crtc_regs (25)
	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
 	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
 	db	0Ch, 00h, 0Fh, 08h  ; actl regs (20)
	db	00h, 00h, 00h, 00h, 00h, 10h, 0Eh, 0Fh, 0FFh ; grdc regs (9)
vga_mode_01h:	; mode 01h, 40*25 text, CGA colors
	db	40, 24, 16, 00h, 08h ; tw, th-1, ch, slength
	db	08h, 03h, 00h, 02h  ; sequ regs
	db	67h	; misc reg
	db	2Dh, 27h, 28h, 90h, 2Bh, 0A0h, 0BFh, 1Fh
	db	00h, 4Fh, 0Dh, 0Eh, 00h, 00h, 00h, 00h
	db	9Ch, 8Eh, 8Fh, 14h, 1Fh, 96h, 0B9h, 0A3h
	db	0FFh	; crtc_regs
	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
	db	0Ch, 00h, 0Fh, 08h  ; actl regs
	db	00h, 00h, 00h, 00h, 00h, 10h, 0Eh, 0Fh, 0FFh ; grdc regs
;vga_mode_07h:	; mode 07h, 80*25 text, mono color
;	db	80, 24, 16, 00h, 10h  ; tw, th-1, ch, slength
;	db	00h, 03h, 00h, 02h ; sequ regs
;	db	66h	; misc reg
;	db	5Fh, 4Fh, 50h, 82h, 55h, 81h, 0BFh, 1Fh
;	db	00h, 4Fh, 0Dh, 0Eh, 00h, 00h, 00h, 00h
;	db	9Ch, 8Eh, 8Fh, 28h, 0Fh, 96h, 0B9h, 0A3h
;	db	0FFh	; crtc regs
;	db	00h, 08h, 08h, 08h, 08h, 08h, 08h, 08h
;	db	10h, 18h, 18h, 18h, 18h, 18h, 18h, 18h
;	db	0Eh, 00h, 0Fh, 08h  ; actl regs
;	db	00h, 00h, 00h, 00h, 00h, 10h, 0Ah, 0Fh, 0FFh ; grdc regs
vga_mode_04h:	; 320*200 graphics, 4 colors, CGA
	db	40, 24, 8, 00h, 08h   ; tw, th-1, ch, slength
	db	09h, 03h, 00h, 02h ; sequ regs
	db	63h	; misc reg
	db	2Dh, 27h, 28h, 90h, 2Bh, 80h, 0BFh, 1Fh
	db	00h, 0C1h, 00h, 00h, 00h, 00h, 00h, 00h
	db	9Ch, 8Eh, 8Fh, 14h, 00h, 96h, 0B9h, 0A2h
	db	0FFh	; crtc_regs
	db	00h, 13h, 15h, 17h, 02h, 04h, 06h, 07h
	db	10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h
	db	01h, 00h, 03h, 00h ; actl regs
	db 	00h, 00h, 00h, 00h, 00h, 30h, 0Fh, 0Fh, 0FFh ; grdc regs
vga_mode_06h:	; 640*200 graphics, 2 colors, CGA
	db	80, 24, 8, 00h, 10h   ;	tw, th-1, ch, slength
	db	01h, 01h, 00h, 06h ; sequ regs
	db	63h	; misc reg
	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh
	db	00h, 0C1h, 00h, 00h, 00h, 00h, 00h, 00h
	db	9Ch, 8Eh, 8Fh, 28h, 00h, 96h, 0B9h, 0C2h
	db	0FFh	; crtc regs
	db	00h, 17h, 17h, 17h, 17h, 17h, 17h, 17h
	db	17h, 17h, 17h, 17h, 17h, 17h, 17h, 17h
	db	01h, 00h, 01, 00h  ; actl regs
	db	00h, 00h, 00h, 00h, 00h, 00h, 0Dh, 0Fh, 0FFh ; grdc regs
vga_mode_13h:  ; mode 13h, 300*200, 256 colors, linear
	db 	40, 24, 8, 0, 0	; tw, th-1, ch, slength (5)
	db	01h, 0Fh, 00h, 0Eh ; sequ regs (4)
	db	63h	; misc reg (1)
	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh 
 	db 	00h, 41h, 00h, 00h, 00h, 00h, 00h, 00h
	db	9Ch, 8Eh, 8Fh, 28h, 40h, 96h, 0B9h, 0A3h
	db	0FFh	; crtc regs (25)
	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
 	db	08h, 09h, 0Ah, 0Bh, 0Ch, 0Dh, 0Eh, 0Fh
 	db	41h, 00h, 0Fh, 00h  ; actl regs (20)
	db	00h, 00h, 00h, 00h, 00h, 40h, 05h, 0Fh, 0FFh ; grdc regs (9)
vga_mode_setl equ $ - vga_mode_13h  ; = 64
vga_mode_F0h:  ; mode X ; 320*240, 256 colors, planar
	db 	40, 24, 8, 0, 0	; tw, th-1, ch, slength
	db	01h, 0Fh, 00h, 06h ; sequ regs
	db	0E3h	; misc reg
	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0Dh, 3Eh 
 	db 	00h, 41h, 00h, 00h, 00h, 00h, 00h, 00h
	db	0EAh, 0ACh, 0DFh, 28h, 00h, 0E7h, 06h, 0E3h
	db	0FFh	; crtc regs (25)
	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
 	db	08h, 09h, 0Ah, 0Bh, 0Ch, 0Dh, 0Eh, 0Fh
 	db	41h, 00h, 0Fh, 00h  ; actl regs
	db	00h, 00h, 00h, 00h, 00h, 40h, 05h, 0Fh, 0FFh ; grdc regs
vga_mode_12h:  ; mode 12h, 640*480, 16 colors, planar
 	db 	80, 29, 16, 0, 0 ; tw, th-1, ch, slength
	db	01h, 0Fh, 00h, 06h ; sequ regs
	db 	0E3h	; misc reg
	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0Bh, 3Eh
	db	00h, 40h, 00h, 00h, 00h, 00h, 00h, 00h
 	db	0EAh, 8Ch, 0DFh, 28h, 00h, 0E7h, 04h, 0E3h
	db	0FFh	; crtc regs
	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
	db	01h, 00h, 0Fh, 00h  ; actl regs
	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
vga_mode_6Ah:  ; mode 6Ah, 800*600, 16 colors, planar
 	db 	100, 36, 16, 0, 0 ; tw, th-1, ch, slength
	db	01h, 0Fh, 00h, 06h ; sequ regs
	db 	0E3h	; misc reg
	db	7Fh, 63h, 63h, 83h, 6Bh, 1Bh, 72h, 0F0h
	db	00h, 60h, 00h, 00h, 00h, 00h, 00h, 00h
 	db	59h, 8Dh, 57h, 32h, 00h, 57h, 73h, 0E3h
	db	0FFh	; crtc regs
	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
	db	01h, 00h, 0Fh, 00h  ; actl regs
	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
vga_mode_0Dh:  ; mode 0Dh, 320*200, 16 colors, planar
 	db 	40, 24, 8, 0, 20h ; tw, th-1, ch, slength
	db	09h, 0Fh, 00h, 06h ; sequ regs
	db 	63h	; misc reg
	db	2Dh, 27h, 28h, 90h, 2Bh, 80h, 0BFh, 1Fh
	db	00h, 0C0h, 00h, 00h, 00h, 00h, 00h, 00h
 	db	9Ch, 8Eh, 8Fh, 14h, 00h, 96h, 0B9h, 0E3h
	db	0FFh	; crtc regs
	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
	db	10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h
	db	01h, 00h, 0Fh, 00h  ; actl regs
	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
vga_mode_0Eh:  ; mode 0Eh, 640*200, 16 colors, planar
 	db 	80, 24, 8, 0, 40h ; tw, th-1, ch, slength
	db	01h, 0Fh, 00h, 06h ; sequ regs
	db 	63h	; misc reg
	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh
	db	00h, 0C0h, 00h, 00h, 00h, 00h, 00h, 00h
 	db	9Ch, 8Eh, 8Fh, 28h, 00h, 96h, 0B9h, 0E3h
	db	0FFh	; crtc regs
	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
	db	10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h
	db	01h, 00h, 0Fh, 00h  ; actl regs
	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
vga_mode_10h: ; mode 10h, 640*350, 16 colors, planar
 	db 	80, 24, 14, 0, 80h ; tw, th-1, ch, slength
	db	01h, 0Fh, 00h, 06h ; sequ regs
	db 	0A3h	; misc reg
	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh
	db	00h, 40h, 00h, 00h, 00h, 00h, 00h, 00h
 	db	83h, 85h, 5Dh, 28h, 0Fh, 63h, 0BAh, 0E3h
	db	0FFh	; crtc regs
	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
	db	01h, 00h, 0Fh, 00h  ; actl regs
	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
vga_mode_11h: ; mode 11h, 640*480, mono color, planar
 	db 	80, 29, 16, 0, 0   ; tw, th-1, ch, slength
	db	01h, 0Fh, 00h, 06h ; sequ regs
	db 	0E3h	; misc reg
	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0Bh, 3Eh
	db	00h, 40h, 00h, 00h, 00h, 00h, 00h, 00h
 	db	0EAh, 8Ch, 0DFh, 28h, 00h, 0E7h, 04h, 0E3h
	db	0FFh	; crtc regs
	db	00h, 3Fh, 00h, 3Fh, 00h, 3Fh, 00h, 3Fh
	db	00h, 3Fh, 00h, 3Fh, 00h, 3Fh, 00h, 3Fh
	db	01h, 00h, 0Fh, 00h  ; actl regs
	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
end_of_vga_params:

; /// End Of VIDEO DATA ///
