This commit is contained in:
2021-09-14 18:46:50 +03:00
parent d605c6a016
commit b6ddeca1c3
180 changed files with 5909 additions and 2039 deletions

BIN
_play/fat16.img.gz Normal file

Binary file not shown.

BIN
_play/fat16.img/fat16.img Normal file

Binary file not shown.

105
_play/stage1.asm Normal file
View File

@@ -0,0 +1,105 @@
bits 16
org 0x07C0
xchg bx, bx
jmp main
VideoAddrSeg dw 0xB800
VideoAddrOff dw 0x0000
Cursor dw 0
; Print character to screen; AL = character
PrintCh:
pusha ; save all registers
push ax ; save ax
mov ax, [Cursor] ; get cursor position
mov bx, 2
xor dx, dx
mul bx ; multiply by two
mov bx, [VideoAddrSeg] ; es = video memory segment
mov cx, [VideoAddrOff] ; di = video memory offset
add cx, ax ; add it to di
pop ax
mov byte [bx:cx], al ; put character
inc word[Cursor] ; Cursor++
call UpdateCursor
popa
ret
; Add 80 to cursor
NewLine:
add word[Cursor], 80
call UpdateCursor
ret
; Go to the beginning of the line
BeginLine:
pusha ; save all registers
mov ax, [Cursor] ; get cursor position
mov bx, 80 ; number of chars/line
xor dx, dx ; empty dx
div bx ; divide ax/bx
sub word[Cursor], dx ; subtract remainder from cursor
call UpdateCursor
popa
ret
; Update cursor position
UpdateCursor:
ret
main:
mov ax, 0
.loop:
push ax
mov bx, 10
xor dx, dx
div bx
cmp dx, 0
je .newline
.back:
cmp ax, 256
je .done
call PrintCh
inc ax
jmp .loop
.newline:
call NewLine
call BeginLine
jmp .back
.done:
mov ax, 'D'
call PrintCh
mov ax, 'O'
call PrintCh
mov ax, 'N'
call PrintCh
mov ax, 'E'
call PrintCh
cli
hlt
TIMES 510-($-$$) db 0
DW 0xAA55

24
_play/stage2/MAKE.BAT Normal file
View File

@@ -0,0 +1,24 @@
@echo off
set nasm_path=C:\nasm
set djgpp_path=C:\DJGPP\bin
goto build
:error
@echo.
@echo There have been build errors. Building halted.
@pause
exit
:build
@echo Compiling stage 2...
del stage2.cta
%nasm_path%\nasm.exe -f bin stage2.asm -o stage2.cta
:test
if not exist stage2.cta goto error
:copy
@echo Copying stage 2 to floppy...
copy stage2.cta A:\stage2.cta >nul

BIN
_play/stage2/STAGE2.CTA Normal file

Binary file not shown.

201
_play/stage2/stage2.asm Normal file
View File

@@ -0,0 +1,201 @@
;***** stage2.asm ****************************************************
;* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
;* *
;* Playground........ *
;* ================== *
;* *
;************************************************************ cta os */
bits 16
org 0x500
xchg bx,bx
jmp main ; go to start
;*******************************************************
; Preprocessor directives
;*******************************************************
%include "stdio.inc" ; basic i/o routines
;*******************************************************
; Data Section
;*******************************************************
vbeControllerInfo:
vbeControllerInfo_signature dd 0 ; "VESA", taken as 4 bytes
vbeControllerInfo_version dw 0 ; 0x0300 for VBE 3.0
vbeControllerInfo_oemString dd 0 ; isa vbeFarPtr, taken as 2 shorts
vbeControllerInfo_capabilities dd 0 ; taken as 4 bytes
vbeControllerInfo_videomodes dd 0 ; isa vbeFarPtr, taken as 2 shorts
vbeControllerInfo_totalMemory dw 0 ; as # of 64k blocks
vbeControllerInfoReserved times 1EEh db 0
TemporaryStorage dd 0 ; temporary storage
printSuccess db 0x0D, 0x0A, "Information received successfully: ", 0x0A, 0x0D, 0x00
printInfo1 db "-> Signature: ", 0x00
printInfo2 db 0x0D, 0x0A, "-> Version: 0x", 0x00
printInfo3 db 0x0D, 0x0A, "-> OEMString (address): 0x", 0x00
printInfo4 db 0x0D, 0x0A, "-> Capabilities: 0x", 0x00
printInfo5 db 0x0D, 0x0A, "-> Video modes (address): 0x", 0x00
printInfo6 db 0x0D, 0x0A, "-> Total memory (KB): ", 0x00
printFailure db "Error, unexpected return: ", 0x00
;*******************************************************
; Code Section
;*******************************************************
main:
;-------------------------------;
; Setup segments and stack ;
;-------------------------------;
cli ; clear interrupts
xor ax, ax ; null segments
mov ds, ax
mov es, ax
mov ax, 0x0000 ; stack begins at 0x9000-0xffff
mov ss, ax
mov sp, 0xFFFF
sti ; enable interrupts
; Switch to graphic mode
mov ax, 0012h
int 10h
int 09h
mov ax, 0
int 16h
; **************************************
; * Start by getting some VESA info *
; **************************************
xor eax, eax
mov ebx, eax
mov ecx, eax
mov edx, eax
mov eax, vbeControllerInfo
push eax
and eax, 0fh
mov dx, ax
pop eax
shr eax, 4
mov es, ax
mov di, dx
mov ax, 4F00h
int 10h
; See if interrupt returned ok.
cmp ax, 004Fh
je .yes
; no:
mov si, printFailure ; print error message
call Puts16
call PrintHEX ; print error code
jmp .done
.yes:
mov si, printSuccess ; print success message
call Puts16
; Print Info1
mov si, printInfo1
call Puts16
mov si, vbeControllerInfo_signature
call Puts16
; Print Info2
mov si, printInfo2
call Puts16
xor eax, eax
mov ax, [vbeControllerInfo_version]
call PrintHEX
; Print Info3
mov si, printInfo3
call Puts16
mov eax, [vbeControllerInfo_oemString]
call PrintHEX
; Print Info4
mov si, printInfo4
call Puts16
mov eax, [vbeControllerInfo_capabilities]
call PrintHEX
; Print Info5
mov si, printInfo5
call Puts16
mov eax, [vbeControllerInfo_videomodes]
call PrintHEX
; Print Info6
mov si, printInfo6
call Puts16
xor eax, eax
mov ax, [vbeControllerInfo_totalMemory]
call PrintINT
.done:
cli
hlt
vbeModeInfo:
vbeModeInfo_attributes dw 0
vbeModeInfo_winA db 0
vbeModeInfo_winB db 0
vbeModeInfo_granularity dw 0
vbeModeInfo_winsize dw 0
vbeModeInfo_segmentA dw 0
vbeModeInfo_segmentB dw 0
vbeModeInfo_realFctPtr dd 0
vbeModeInfo_pitc dw 0 ; // bytes per scanline
vbeModeInfo_Xres dw 0
vbeModeInfo_Yres dw 0
vbeModeInfo_Wchar db 0
vbeModeInfo_Ychar db 0
vbeModeInfo_planes db 0
vbeModeInfo_bpp db 0
vbeModeInfo_banks db 0
vbeModeInfo_memory_model db 0
vbeModeInfo_bank_size db 0
vbeModeInfo_image_pages db 0
vbeModeInfo_reserved0 db 0
; VBE v1.2+
vbeModeInfo_red_mask db 0
vbeModeInfo_red_position db 0
vbeModeInfo_green_mask db 0
vbeModeInfo_green_position db 0
vbeModeInfo_blue_mask db 0
vbeModeInfo_blue_position db 0
vbeModeInfo_rsv_mask db 0
vbeModeInfo_rsv_position db 0
vbeModeInfo_directcolor_attrib db 0
; VBE v2.0+
vbeModeInfo_physbase dd 0
vbeModeInfo_start_offscreen_mem dd 0
vbeModeInfo_size_offscreen_mem dw 0
; VBE v3.0+
vbeModeInfo_bytes_per_scanline dw 0
vbeModeInfo_number_images_banked db 0
vbeModeInfo_number_images_linear db 0
vbeModeInfo_linear_red_mask db 0
vbeModeInfo_linear_red_pos db 0
vbeModeInfo_linear_green_mask db 0
vbeModeInfo_linear_green_pos db 0
vbeModeInfo_linear_blue_mask db 0
vbeModeInfo_linear_blue_pos db 0
vbeModeInfo_linear_res_mask db 0
vbeModeInfo_linear_res_pos db 0
vbeModeInfo_max_pixel_clock dd 0

386
_play/stage2/stdio.inc Normal file
View File

@@ -0,0 +1,386 @@
;***** stdio.inc *****************************************************
;* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
;* *
;* Standard Input/Output routines *
;* ============================== *
;* *
;************************************************************ cta os */
%ifndef __STDIO_INC_CTA008__
%define __STDIO_INC_CTA008__
;==========================================================
;
; 16 Bit Real Mode Routines
;==========================================================
;************************************************;
; Puts16 ()
; -Prints a null terminated string
; DS=>SI: 0 terminated string
;************************************************;
tmpStr db " ", 0x0D, 0x0A, 0x00
hex db "0123456789abcdef"
bits 16
Puts16:
pusha ; save registers
.Loop1:
lodsb ; load next byte from string from SI to AL
or al, al ; Does AL=0?
jz Puts16Done ; Yep, null terminator found-bail out
mov ah, 0eh ; Nope-Print the character
int 10h ; invoke BIOS
jmp .Loop1 ; Repeat until null terminator found
Puts16Done:
popa ; restore registers
ret ; we are done, so return
;************************************************;
; PrintINT (uint16_t number)
; -Prints an integer on the screen
;
; Parameters: ax = number
;************************************************;
PrintINT:
pusha
push ax ; save ax
mov bx, 10 ; base 10 in bx
call DigitsINT ; get number of digits
mov cx, ax ; move in cx number of digits
pop ax ; restore ax = number
mov byte[tmpStr+ecx], 0x00 ; Mark end of string
.loop:
xor dx, dx
div bx ; divide by base
add dx, '0'
mov byte[tmpStr+ecx-1], dl ; write in position
loop .loop ; loop while cx > 0
mov si, tmpStr
call Puts16
.done:
popa
ret
;************************************************;
; PrintHEX (uint32_t number)
; -Prints an integer in hex on the screen
;
; Parameters: push on the stack number
;************************************************;
PrintHEX:
pusha
push eax ; save ax
call DigitsHEX ; get number of digits
mov ecx, eax ; move in cx number of digits
pop eax ; restore ax = number
mov byte[tmpStr+ecx], 0x00 ; Mark end of string
.loop:
mov edx, eax ; Put number in edx
and edx, 0x0f ; Remove all digits but the last
shr eax, 4 ; Remove digit from end
push eax ; save eax
xor eax, eax ; make it 0
mov al, [hex+edx]
mov byte[tmpStr+ecx-1], al ; write in position
pop eax
loop .loop ; loop while cx > 0
mov si, tmpStr
call Puts16
.done:
popa
ret
;************************************************;
; DigitsHEX (uint32_t number)
; -Calculate number of digits of a number in hex
;
; Parameters: number in eax
; Returns: value in eax
;************************************************;
_Number dd 0
DigitsHEX:
pusha ; Save all registers
xor ebx, ebx ; Empty registers
mov ecx, ebx
mov edx, ebx
.loop:
cmp eax, 0
je .done
shr eax, 4
inc ecx
jmp .loop
.done:
mov dword[_Number], ecx
popa
mov eax, [_Number]
ret
;************************************************;
; DigitsINT (uint16_t number, uint16_t base)
; -Calculate number of digits of a number in the specified base
;
; Parameters: number in ax, base in bx
; Returns: value in ax
;************************************************;
DigitsINT:
pusha ; Save all registers
xor cx, cx ; Empty registers
.loop:
cmp ax, 0
je .done
xor dx, dx
div bx
inc cx
jmp .loop
.done:
mov word[_Number], cx
popa
mov ax, [_Number]
ret
;==========================================================
;
; 32 Bit Protected Mode Routines
;==========================================================
;bits 32
;%define VIDMEM 0xB8000 ; video memory
;%define COLS 80 ; width and height of screen
;%define LINES 25
;%define CHAR_ATTRIB 14 ; character attribute (White text on black background)
;_CurX db 0 ; current x/y location
;_CurY db 0
;**************************************************;
; Putch32 ()
; - Prints a character to screen
; BL => Character to print
;**************************************************;
;Putch32:
;
; pusha
; mov edi, VIDMEM
;
; xor eax, eax ; clear eax
;
; ; y * screen width
;
; mov ecx, COLS*2 ; Mode 7 has 2 bytes per char, so its COLS*2 bytes per line
; mov al, byte [_CurY] ; get y pos
; mul ecx ; multiply y*COLS
; push eax ; save eax--the multiplication
; now add _CurX * 2
; mov al, byte [_CurX] ; multiply _CurX by 2 because it is 2 bytes per char
; mov cl, 2
; mul cl
; pop ecx ; pop y*COLS result
; add eax, ecx
; add the position to draw to the base of vid memory
; xor ecx, ecx
; add edi, eax ; add it to the base address
;
; watch for new line
; cmp bl, 0x0A ; is it a newline character?
; je .Row ; yep--go to next row
;
; print the character
; mov dl, bl ; Get character
; mov dh, CHAR_ATTRIB ; the character attribute
; mov word [edi], dx ; write to video display
;
; ; go to next location
; inc byte [_CurX] ; go to next character
; jmp .done ; nope, bail out
;.Row:
; mov byte [_CurX], 0 ; go back to col 0
; inc byte [_CurY] ; go to next row
;.done:
; popa
; ret
;**************************************************;
; Puts32 ()
; - Prints a null terminated string
; parm\ EBX = address of string to print
;**************************************************;
;Puts32:
; pusha
; push ebx ; copy the string address
; pop edi
;.loop:
;-------------------------------;
; Get character ;
;-------------------------------;
; mov bl, byte [edi] ; get next character
; cmp bl, 0 ; is it 0 (Null terminator)?
; je .done ; yep-bail out
;-------------------------------;
; Print the character ;
;-------------------------------;
; call Putch32 ; Nope-print it out
;-------------------------------;
; Go to next character ;
;-------------------------------;
; inc edi ; go to next character
; jmp .loop
;.done:
;-------------------------------;
; Update hardware cursor ;
;-------------------------------;
; mov bh, byte [_CurY] ; get current position
; mov bl, byte [_CurX]
; call MovCur ; update cursor
; popa ; restore registers, and return
; ret
;**************************************************;
; MoveCur ()
; - Update hardware cursor
; parm/ bh = Y pos
; parm/ bl = x pos
;**************************************************;
;bits 32
;MovCur:
; pusha
;
;-------------------------------;
; Get current position ;
;-------------------------------;
; location = _CurX + _CurY * COLS
; xor eax, eax
; mov ecx, COLS
; mov al, bh ; get y pos
; mul ecx ; multiply y*COLS
; add al, bl ; Now add x
; mov ebx, eax
;
;--------------------------------------;
; Set low byte index to VGA register ;
;--------------------------------------;
; mov al, 0x0f
; mov dx, 0x03D4
; out dx, al
;
; mov al, bl
; mov dx, 0x03D5
; out dx, al ; low byte
;---------------------------------------;
; Set high byte index to VGA register ;
;---------------------------------------;
; xor eax, eax
; mov al, 0x0e
; mov dx, 0x03D4
; out dx, al
; mov al, bh
; mov dx, 0x03D5
; out dx, al ; high byte
; popa
; ret
;**************************************************;
; ClrScr32 ()
; - Clears screen
;**************************************************;
;
;bits 32
;
;ClrScr32:
;
; pusha
; cld
; mov edi, VIDMEM
; mov cx, 2000
; mov ah, CHAR_ATTRIB
; mov al, ' '
; rep stosw
; mov byte [_CurX], 0
; mov byte [_CurY], 0
; popa
; ret
;**************************************************;
; GotoXY ()
; - Set current X/Y location
; parm\ AL=X position
; parm\ AH=Y position
;**************************************************;
;bits 32
;GotoXY:
; pusha
; mov [_CurX], al
; mov [_CurY], ah
; popa
; ret
%endif ;__STDIO_INC_67343546FDCC56AAB872_INCLUDED__