now it plays properly, will fix up some leftovers later
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 31 Dec 2022 02:12:09 +0000 (04:12 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 31 Dec 2022 02:12:09 +0000 (04:12 +0200)
Makefile
bootcard.asm
tools/gentune.c [new file with mode: 0644]

index 4da4343..7b0705b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -39,3 +39,6 @@ com: $(com)
 .PHONY: rundos
 rundos: $(com)
        dosbox-x $(com)
+
+tools/gentune: tools/gentune.c
+       $(CC) -o $@ $< $(LDFLAGS)
index 1f29b88..a782832 100644 (file)
@@ -201,13 +201,14 @@ drawbg:
 textout:
        mov al, [si]
        and al, al
-       jz .done
+       jz textout_done
        mov ah, 0eh
        mov bx, 82
        int 10h
        inc si
        jmp textout
-.done: ret
+textout_done:
+       ret
 
 %ifdef MIDI
 note_on:
@@ -217,17 +218,18 @@ note_on:
        mov ax, [pnote]
        call sendmidi
        mov ax, 127
-       call sendmidi
-       ret
+       jmp sendmidi
 
 note_off:
+       mov ax, [pnote]
+       test ax, ax
+       jz textout_done
        mov ax, 80h     ; note-off command for channel 0
        call sendmidi
        mov ax, [pnote]
        call sendmidi
        mov ax, 64
-       call sendmidi
-       ret
+       jmp sendmidi
 
 all_notes_off:
        mov ax, 0b0h    ; channel mode message for channel 0...
@@ -235,11 +237,11 @@ all_notes_off:
        mov ax, 7bh     ; all notes off
        call sendmidi
        xor ax, ax
-       call sendmidi
-       ret
+       mov [pnote], ax
+       jmp sendmidi
 
 waitmidi:
-       mov ax, 331h
+       mov dx, 331h
 .wait: in al, dx       ; read status port
        test al, 40h    ; test output-ready bit (0: ready)
        jnz .wait
@@ -289,7 +291,6 @@ tintr:
        jb .end
 
 %ifdef MIDI
-       call note_off
        mov al, [music + 1 + bx]
        xor ah, ah
        add bx, 2
@@ -313,6 +314,10 @@ tintr:
        mov word [cmap + bx + 1], 2f2fh
 
 %ifdef MIDI
+       push ax
+       ;call note_off
+       call all_notes_off
+       pop ax
        call note_on
 %else
        mov bx, ax
diff --git a/tools/gentune.c b/tools/gentune.c
new file mode 100644 (file)
index 0000000..627900e
--- /dev/null
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <stdint.h>
+
+uint32_t music[] = {
+       0x0a2f8f00, 0xa11123a1, 0x23a11423, 0x28000023, 0xbe322f8f, 0x25c0391f,
+       0x4b23a13c, 0x8f500000, 0x23a15a2f, 0x641ab161, 0x476e1ab1, 0x1fbe751c,
+       0x8223a178, 0xa18925c0, 0x1fbe8c23, 0xaa0000a0, 0
+};
+
+struct {
+       unsigned int cnt;
+       const char *name;
+} notes[] = {
+       {0, "0"},
+       {6833, "F3"},
+       {7239, "E3"},
+       {8126, "D3"},
+       {9121, "C3"},
+       {9664, "B2"},
+       {12175, "G2"},
+       {0, 0}
+};
+
+const char *pre =
+       "G2     equ 12175\n"
+       "C3     equ 9121\n"
+       "D3     equ 8126\n"
+       "B2     equ 9664\n"
+       "F3     equ 6833\n"
+       "E3     equ 7239\n"
+       "\n"
+       "%macro EV 2\n"
+       "       db %1 >> 4\n"
+       "       dw %2\n"
+       "%endmacro\n\n";
+
+
+int main(void)
+{
+       int i, j;
+       unsigned char *mptr = (unsigned char*)music;
+
+       printf("%s", pre);
+
+       printf("music:");
+       for(i=0; i<22; i++) {
+               const char *nn = "?";
+               unsigned int tm = (unsigned int)*mptr++ << 4;
+               unsigned int cnt = *(uint16_t*)mptr;
+               mptr += 2;
+
+               for(j=0; notes[j].name; j++) {
+                       if(notes[j].cnt == cnt) {
+                               nn = notes[j].name;
+                               break;
+                       }
+               }
+
+               printf("\tEV  %4u,  %s\n", tm, nn);
+       }
+       return 0;
+}