- fixed potentially incorrect ds in timer interrupt
[bootcard] / bootcard.asm
index 434bf0b..f823219 100644 (file)
@@ -12,6 +12,8 @@ tmoffs                equ nticks + 4
 muscur         equ tmoffs + 4
 data_end       equ muscur + 4
 
+backbuf_seg    equ 1000h
+
 OSC_FREQ       equ 1193182
 PIT_DATA0      equ 40h
 PIT_CMD                equ 43h
@@ -23,8 +25,7 @@ KB_CTRL               equ 61h
 %define DIV_ROUND(a, b)        ((a) / (b) + ((a) % (b)) / ((b) / 2))
 
 %macro setcursor 2
-       mov dl, %1
-       mov dh, %2
+       mov dx, %1 | (%2 << 8)
        xor bx, bx
        mov ah, 2
        int 10h
@@ -48,7 +49,7 @@ KB_CTRL               equ 61h
        out PIT_DATA0 + %1, al
 %endmacro
 
-start: xor eax, eax
+start: xor ax, ax
        mov ds, ax
        mov es, ax
        mov ss, ax
@@ -65,61 +66,90 @@ start:      xor eax, eax
 
        mov ax, 13h
        int 10h
+       push backbuf_seg
+       pop es
+
+       sti
+
+mainloop:
+       call drawbg
+
+       push ds
+       push es
+       push es
+       pop ds
        push 0a000h
        pop es
+       xor di, di
+       xor si, si
+       mov cx, 32000
+
+       mov dx, 3dah
+.invb: in al, dx
+       and al, 8
+       jnz .invb
+.novb: in al, dx
+       and al, 8
+       jz .novb
+
+       rep movsw
+       pop es
+       pop ds
+
+       setcursor 10, 0
+       mov si, str1
+       call textout
+       setcursor 12, 1
+       mov si, str2
+       call textout
+
+       jmp mainloop
 
-       ; setup palette
-       mov cx, 128
-       mov dx, 3c8h
-       mov al, 16
-       out dx, al
-       inc dx
-.cmapsetup:
-       mov al, cl
-       shr al, 2
-       out dx, al
-       neg al
-       and al, 03fh
-       shr al, 1
-       mov ah, al
-       shr al, 2
-       out dx, al
-       mov al, ah
-       out dx, al
-       dec cx
-       jnz .cmapsetup
-       
 drawbg:
        mov bx, 200
-       xor di, di
+       mov di, 5120
 .fillgrad:
        mov ax, bx
-       add ax, 16
        mov ah, al
-       mov cx, 320
+       mov cx, 2400    ; 15 lines
        rep stosw
-       dec bx
+       inc bx
+       cmp bx, 208
        jnz .fillgrad
 
-       setcursor 10, 12
-       mov si, str1
-       call textout
-       setcursor 12, 13
-       mov si, str2
-       call textout
+       ; mountains
+       mov cx, 320
+       mov bp, sp
+.mnt:  mov [bp - 2], cx
+       fild word [bp - 2]
+       fidiv word [w30]
+       fsincos
+       fiadd word [w5]
+       fimul word [w5]
+       fistp word [bp - 2]
+       ;fistp word [bp - 4]
+       mov bx, [bp - 2]
+       add bx, 100
+       imul bx, bx, 320
+       add bx, cx
+.mntcol:
+       mov byte [es:bx], 0
+       add bx, 320
+       cmp bx, 64000
+       jb .mntcol
 
-       sti
+       dec cx
+       jnz .mnt
+       
+       ret
 
-infloop:
-       hlt
-       jmp infloop
 
 textout:
        mov al, [si]
        and al, al
        jz .done
        mov ah, 0eh
-       mov bx, 0fh
+       mov bx, 82
        int 10h
        inc si
        jmp textout
@@ -127,6 +157,9 @@ textout:
 
 timer_intr:
        pusha
+       push ds
+       push word 0
+       pop ds
        mov ax, [nticks]
        inc ax
        mov [nticks], ax
@@ -140,7 +173,7 @@ timer_intr:
        cmp ax, cx
        jb .eoi
 
-       inc dword [muscur]
+       inc word [muscur]
        mov ax, [music + 2 + bx] ; event counter reload
        test ax, ax
        jz .off
@@ -153,6 +186,7 @@ timer_intr:
 
 .eoi:  mov al, 20h
        out 20h, al     ; EOI
+       pop ds
        popa
        iret
 
@@ -164,14 +198,14 @@ timer_intr:
        
 
 str1:  db 'message message blah',0
-str2:  db 'Michael & Athina',0
+str2:  db 'Michael & Athena',0
 
-G2     equ 24351/2
-C3     equ 18243/2
-D3     equ 16252/2
-B2     equ 19328/2
-F3     equ 13666/2
-E3     equ 14479/2
+G2     equ 12175
+C3     equ 9121
+D3     equ 8126
+B2     equ 9664
+F3     equ 6833
+E3     equ 7239
 
 %define TM(x)  (40 + (x) * 4)
 
@@ -213,6 +247,9 @@ music:      dw 0, 0
        dd 0820280ch
        dd 00000800h
        dd 0001f800h
+
+w5:    dw 5
+w30:   dw 30
        times 510-($-$$) db 0
        dw 0aa55h