Initial commit

This commit is contained in:
mykola2312 2019-11-17 05:52:33 +02:00
commit 8ab7485a57
29 changed files with 1220399 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 KiB

BIN
1509466213181567779.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 KiB

7
Makefile Normal file
View file

@ -0,0 +1,7 @@
all:
nasm -f bin boot.asm -o boot.bin
nasm -f bin demo.asm -o demo.bin
palette summer.bmp palette.bin
mapper
qemu-system-i386 -fda demo.img -soundhw sb16,adlib,pcspk

140
blaster.asm Normal file
View file

@ -0,0 +1,140 @@
; Sound
dsp_handler:
mov al,20h
out 20h,al
iret
install_dsp:
; Get interrupt
mov dx,word [dsp_base]
add dx,0Eh
in ax,dx
shl ax,2 ; Mul by 4
; Install IRQ handler
mov bx,ax
xor ax,ax
mov es,ax
mov word [es:bx],dsp_handler
mov word [es:bx+2],cs
ret
write_dsp:
push ax
mov dx,word [dsp_base]
add dx,0Ch
.dsp_write_loop:
in ax,dx
and al,80h
jnz .dsp_write_loop
mov dx,word [dsp_base]
add dx,0Ch
pop ax
out dx,al
ret
read_dsp:
mov ax,word [dsp_base]
add ax,0Eh
.dsp_read_loop:
in ax,dx
and dx,80h
jz .dsp_read_loop
mov ax,word [dsp_base]
add ax,0Ah
in ax,dx
mov ax,dx
ret
reset_dsp:
mov dx,word [dsp_base]
add dx,06h
mov ax,1
out dx,al
push ax
mov ax,55
call sleep
pop ax
xor ax,ax
out dx,al
ret
play_dsp:
push bp
mov bp,sp
; 1 +4 - offset
; 2 +6 - segment
; 3 +8 - size
dec word [bp+08h]
mov ax,5
out 0Ah,al
xor ax,ax
out 0Ch,al
mov al,49h
out 0Bh,al
; Calc offset
mov ax,word [bp+06h] ; Segment
shl ax,4
add ax,word [bp+04h] ; Offset
out 02h,al
shr ax,8
out 02h,al
; Calc page
mov ax,word [bp+04h] ; Offset
shr ax,4
add ax,word [bp+06h] ; Segment
shr ax,12
out 83h,al
; Calc size
mov ax,word [bp+08h] ; Size
out 03h,al
shr ax,8
out 03h,al
;
xor al,al
inc al
out 0Ah,al
; Write time constant = 6
mov al,40h
call write_dsp
mov al,06h
call write_dsp
; Set the playback type
mov al,14h
call write_dsp
mov ax,word [bp+08h]
call write_dsp ; Lo(size)
shr ax,8
call write_dsp ; Hi(size)
mov sp,bp
pop bp
ret 06h
speaker_on:
mov ax,0D1h
call write_dsp
ret
speaker_off:
mov ax,0D3h
call write_dsp
ret

1218387
bochsout.txt Normal file

File diff suppressed because it is too large Load diff

1264
bochsrc.bxrc Normal file

File diff suppressed because it is too large Load diff

44
boot.asm Normal file
View file

@ -0,0 +1,44 @@
org 0x7C00
use16
; In bootloader we need to load demo.bin
; And far call it
; sector 2-3 demo.bin
DEMO_SEG equ 07E0h
mov ax,DEMO_SEG
mov es,ax
xor bx,bx
mov ah,02h
mov al,2 ; 2 Sectors
mov ch,0 ; Cylinder
mov cl,2 ; Sector 2
xor dx,dx
int 13h
;mov ax,cs
;mov ds,ax
;mov ah,42h
;mov si,ata_packet
;mov dl,0x80
;xor dl,dl
;int 13h
;Here we far jump
jmp DEMO_SEG:0000h
ata_packet:
db 16
db 0
num_sec dw 2
buf_off dw 0
buf_seg dw DEMO_SEG
lbaadrl dd 1 ; sector 2
lbaadrh dd 0
TIMES 510 - ($ - $$) db 0
dw 0xAA55

BIN
boot.bin Normal file

Binary file not shown.

27
bx_enh_dbg.ini Normal file
View file

@ -0,0 +1,27 @@
# bx_enh_dbg_ini
SeeReg[0] = TRUE
SeeReg[1] = TRUE
SeeReg[2] = TRUE
SeeReg[3] = TRUE
SeeReg[4] = FALSE
SeeReg[5] = FALSE
SeeReg[6] = FALSE
SeeReg[7] = FALSE
SingleCPU = FALSE
ShowIOWindows = TRUE
ShowButtons = TRUE
SeeRegColors = TRUE
ignoreNxtT = TRUE
ignSSDisasm = TRUE
UprCase = 0
DumpInAsciiMode = 3
isLittleEndian = TRUE
DefaultAsmLines = 512
DumpWSIndex = 0
DockOrder = 0x123
ListWidthPix[0] = 417
ListWidthPix[1] = 271
ListWidthPix[2] = 321
FontName = System
FontSize = -16
MainWindow = 300, 175, 1325, 701

8
data.asm Normal file
View file

@ -0,0 +1,8 @@
load_time dw 0FFFFh
old_timer dd 0
count dw 0
dsp_base dw 220h
drive_num db 0

199
demo.asm Normal file
View file

@ -0,0 +1,199 @@
org 0h
use16
jmp _start
%include "timer.asm"
%include "blaster.asm"
%include "x86ata.asm"
BUF_SEG equ 0820h
SND_SEG1 equ 0900h
SND_SEG2 equ 0100h
_exit:
; Restore timer
cli
call remove_timer
sti
jmp $
; Main code
setup_video:
xor ax,ax
mov al,13h
int 10h
ret
load_palette:
; Load sectors
push 2 ; Sector number
push BUF_SEG ; Segment
push 0 ; Offset
push 3 ; Block
call read_sector
; Load palette to VGA
mov dx,03C8h
xor al,al
out dx,al
push ds
mov ax,BUF_SEG
mov ds,ax
xor si,si
mov cx,256
mov dx,03C9h
cli
.write_palette:
lodsb
out dx,al
lodsb
out dx,al
lodsb
out dx,al
loop .write_palette
sti
pop ds
ret
load_image:
; Load image directly to video buf
; by 64 sectors at once
push 64 ; Sector num
push 0A000h ; Segment
push 0 ; Offset
push 5 ; Block
call read_sector
push 64 ; Sector num
push 0A000h ; Segment
push 8000h ; Offset
push 69 ; Block
call read_sector
ret
play_sound:
push bp
mov bp,sp
sub sp,04h ; Allocate 2 variables
; -2 - block pointer
; -4 - parity
; Load first sectors
push 32
push SND_SEG1
push 0
push 132
call read_sector
mov word [bp-02h],164
mov word [bp-04h],0
.play_n_load:
mov word [cs:count],72
mov ax,word [bp-04h]
test ax,ax
jnz .play_odd
push 4000h
push SND_SEG1
push 0 ; Offset
mov word [bp-04h],1
call play_dsp
jmp .play_finish
.play_odd:
push 4000h
push SND_SEG2
push 0 ; Offset
call play_dsp
mov word [bp-04h],0
.play_finish:
mov ax,word [bp-04h]
test ax,ax
jnz .load_odd
push 32
push SND_SEG1
push 0
push word [bp-02h]
call read_sector
jmp .load_finish
.load_odd:
push 32
push SND_SEG2
push 0
push word [bp-02h]
call read_sector
.load_finish:
; Wait
nop
nop
nop
mov ax,word [cs:count]
test ax,ax
jnz .load_finish
; Next step
mov cx,word [bp-02h]
add cx,32
mov word [bp-02h],cx
cmp cx,694
jl .play_n_load
; Return
mov sp,bp
pop bp
ret
_start:
mov byte [drive_num],dl
; Setup segments
mov ax,cs
mov ds,ax
; Setup stack
mov ax,50h
mov ss,ax
mov sp,1F0h ; 1 KiB stack
; Install timer
cli
call install_timer
sti
; Setup video
call setup_video
mov ax,1000
call sleep
call load_palette
call load_image
; Sound part
mov word [dsp_base],220h
cli
call install_dsp
sti
; Load and play sound
call speaker_on
;mov ax,0D1h
;call write_dsp
;call init_dsp
call reset_dsp
hang:
call play_sound
jmp hang
;call speaker_off
;jmp _exit
%include "data.asm"

BIN
demo.bin Normal file

Binary file not shown.

BIN
demo.img Normal file

Binary file not shown.

15
map.txt Normal file
View file

@ -0,0 +1,15 @@
Sector 1 - bootloader
Sector 2 - demo.bin part 1
Sector 3 - demo.bin part 2
Sector 4 - palette part 1
Sector 5 - palette part 2
Sector 6 - image part 1
Sector 131 - image part 125
Sector 132 - sound part 1
Sector 694 - sound part 562
demo.bin 07E0:0000
dataload 0820:0000
snd_seg1 0900:0000
snd_seg2 0100:0000

52
mapper.c Normal file
View file

@ -0,0 +1,52 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void map_file(void* base,int sector,const char* fname)
{
FILE* in;
long size;
char* buf;
in = fopen(fname,"rb");
fseek(in,0L,SEEK_END);
size = ftell(in);
fseek(in,0L,SEEK_SET);
buf = (char*)malloc(size);
fread(buf,size,1,in);
fclose(in);
memcpy((char*)base+(sector-1)*512,buf,size);
free(buf);
}
/*
Sector 1 - boot.bin
Sector 2 - demo.bin part 1
Sector 3 - demo.bin part 2
Sector 4 - palette part 1
Sector 5 - palette part 2
Sector 6 - image part 1
Sector 131 - image part 125
Sector 132 - sound part 1
Sector 694 - sound part 562
*/
int main(int argc,char** argv)
{
FILE* fout;
char* image;
image = (char*)malloc(512*2880);
map_file(image,1,"boot.bin");
map_file(image,2,"demo.bin");
map_file(image,4,"palette.bin");
map_file(image,6,"summer.bin");
map_file(image,132,"sound.bin");
fout = fopen("demo.img","wb");
fwrite(image,512*2880,1,fout);
fclose(fout);
return 0;
}

BIN
mapper.exe Normal file

Binary file not shown.

BIN
palette.bin Normal file

Binary file not shown.

44
palette.c Normal file
View file

@ -0,0 +1,44 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char** argv)
{
FILE* fbmp;
FILE* fout;
int i;
char b,g,r;
char* buf;
fbmp = fopen(argv[1],"rb");
fout = fopen(argv[2],"wb");
fseek(fbmp,0x36,SEEK_SET);
for(i = 0; i < 256; i++)
{
b = fgetc(fbmp) >> 2;
g = fgetc(fbmp) >> 2;
r = fgetc(fbmp) >> 2;
fgetc(fbmp);
fputc(r,fout);
fputc(g,fout);
fputc(b,fout);
}
//fclose(fbmp);
fclose(fout);
buf = (char*)malloc(320*200);
fseek(fbmp,0x436,SEEK_SET);
fread(buf,320*200,1,fbmp);
fclose(fbmp);
fout = fopen("summer.bin","wb");
for(i = 0; i < 200; i++)
fwrite(&buf[320*(200-i-1)],320,1,fout);
fclose(fout);
free(buf);
return 0;
}

BIN
palette.exe Normal file

Binary file not shown.

11
sb16.log Normal file
View file

@ -0,0 +1,11 @@
00000000000 (4) write to emulator port, value 00
00000000000 (5) emulator command 00, needs 0 arguments
00000000000 (4) executing emulator command 00 with 0 arguments
00000000000 (4) Emulator reinitialized
00000000000 (4) MPU cmd: Master reset of device
00000000000 (4) DSP Reset port write value 0
00000000000 (4) DSP resetting...
00000000000 (4) Initializing mixer...
00000000000 (4) mixer register 00 set to 00
00000000000 (1) SB16 emulation initialised, IRQ 5, IO 220/330/388, DMA 1/0
00000000000 (4) Timers initialized, midi 18, dma 19, opl 20

1
sound.bin Normal file

File diff suppressed because one or more lines are too long

BIN
summer (2).bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

1
summer.bin Normal file

File diff suppressed because one or more lines are too long

BIN
summer.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

54
timer.asm Normal file
View file

@ -0,0 +1,54 @@
; Timer
irq0_handler:
mov ax,word [cs:count]
test ax,ax
jz .skip
dec ax
mov word [cs:count],ax
.skip:
iret
; Clubbes bx
sleep:
push dx
push bx
push ax
; ax - milliseconds
xor dx,dx
mov bx,55
div bx
mov word [cs:count],ax
.loop:
mov ax,word [cs:count]
test ax,ax
jz .loop_end
jmp .loop
.loop_end:
pop ax
pop bx
pop dx
ret
install_timer:
xor ax,ax
mov es,ax
mov ax,word [es:70h]
mov word [old_timer],ax
mov ax,word [es:72h]
mov word [old_timer+2],ax
mov word [es:70h],irq0_handler
mov word [es:72h],cs
ret
remove_timer:
xor ax,ax
mov es,ax
mov ax,word [old_timer]
mov word [es:70h],ax
mov ax,word [old_timer+2]
mov word [es:72h],ax
ret

77
x86ata.asm Normal file
View file

@ -0,0 +1,77 @@
read_sector:
push bp
mov bp,sp
; +4 block num
; +6 offset
; +8 segment
; +A sector num
push ax
push bx
push dx
push cx
mov ax,word [bp+04h]
mov bx,18
xor dx,dx
div bx
; ax - track, dx - sector
inc dl
mov cl,dl
mov bx,2
xor dx,dx
div bx
mov ch,al
shl dx,8
mov bx,word [bp+06h]
mov es,word [bp+08h]
mov ax,word [bp+0Ah]
mov dl,byte [drive_num]
mov ah,02h
int 13h
pop cx
pop dx
pop bx
pop ax
mov bp,sp
pop bp
ret 08h
;read_sector:
;push bp
;mov bp,sp
; +4 block num
; +6 offset
; +8 segment
; +A sector num
;mov ax,word [bp+04h]
;mov word [ata_lbaadrl],ax
;mov ax,word [bp+06h]
;mov word [ata_buf_off],ax
;mov ax,word [bp+08h]
;mov word [ata_buf_seg],ax
;mov ax,word [bp+0Ah]
;mov word [ata_num_sec],ax
;push ds
;mov ax,cs
;mov ds,ax
;mov ah,42h
;mov dl,80h
;mov si,ata_packet
;int 13h
;pop ds
;mov bp,sp
;pop bp
;ret 08h

68
x86pit.asm Normal file
View file

@ -0,0 +1,68 @@
unmask_irq0:
; PIC 20h
mov dx,21h
in al,dx
nop
and al,0b11111110
nop
out dx,al
nop
ret
setup_pic:
; Start
mov al,11h
out 20h,al
nop
out 0A0h,al
nop
; 1. Map
mov al,20h
out 21h,al
nop
mov al,28h
out 0A1h,al
nop
; 2. Connect each other
mov al,04h
out 21h,al
nop
mov al,02h
out 0A1h,al
nop
; 3. Final
mov al,1
out 21h,al
nop
out 0A1h,al
nop
; 4. Clear
xor al,al
out 21h,al
nop
out 0A1h,al
nop
ret
setup_pit:
mov al,00110110b
out 43h,al
nop
xor cx,cx
mov al,cl
out 40h,al
nop
mov al,ch
out 40h,al
nop
ret

BIN
zero.img Normal file

Binary file not shown.

0
zero.img.lock Normal file
View file