;----------------------------------------------------------------------- ; RS232C ---> MIDI Out Module Program [Z-80] ;----------------------------------------------------------------------- name y80main p65c02 ;##### MemoryEI/O MAP ##### program_area equ 00000h int_area equ 00038h work_area equ 04000h ram_area equ 04100h stack_pointer equ 5fffh uart0 equ 08000h uart1 equ 08001h rs232c equ 0b000h ;##### RAM Map ##### org work_area work ds 1 hlflag ds 1 hlbuf ds 1 databuf ds 1 rxtop ds 1 rxend ds 1 rxdata ds 1 txtop ds 1 txend ds 1 txdata ds 1 org ram_area rxfifo ds 256 txfifo ds 256 ;##### Macro Defines ##### macro &push db 0f5h ; push af endmac macro &pop db 0f1h ; pop af endmac macro &ex db 008h ; ex af,af' db 0d9h ; exx endmac macro &stack db 031h ; ld sp,nn db .low.\0 db .high.\0 endmac macro &lda db 03ah ; ld a,(nn) db .low.\0 db .high.\0 endmac macro &sta db 032h ; ld (nn),a db .low.\0 db .high.\0 endmac macro &movi db 03eh ; ld a,n db \0 db 032h ; ld (nn),a db .low.\1 db .high.\1 endmac macro &move db 03ah ; ld a,(nn) db .low.\0 db .high.\0 db 032h ; ld (nn),a db .low.\1 db .high.\1 endmac macro &movex db 03ah ; ld a,(nn) db .low.\0 db .high.\0 db 0eeh,0ffh ; xor a,0ffh db 032h ; ld (nn),a db .low.\1 db .high.\1 endmac macro &jsr db 0cdh ; call xx,nn db .low.\0 db .high.\0 endmac macro &jsrnz db 0c4h ; call nz,nn db .low.\0 db .high.\0 endmac macro &jmp db 0c3h ; jp xx,nn db .low.\0 db .high.\0 endmac macro &beq db 0cah ; jp z,nn db .low.\0 db .high.\0 endmac macro &bne db 0c2h ; jp nz,nn db .low.\0 db .high.\0 endmac macro &rts db 0c9h ; ret xx endmac macro &and db 0e6h ; and a,n db \0 endmac macro &eor db 0eeh ; xor a,n db \0 endmac macro &ora db 0f6h ; or a,n db \0 endmac macro &cmp db 0feh ; cp a,n db \0 endmac macro &inc db 03ch ; inc a endmac macro &dec db 03dh ; dec a endmac macro &seth db 026h ; ld h,n db .high.\0 endmac macro &setl db 03ah ; ld a,(nn) db .low.\0 db .high.\0 db 06fh ; ld l,a endmac macro &gethl db 07eh ; ld a,(hl) endmac macro &puthl db 077h ; ld (hl),a endmac macro &nop db 000h ; endmac ;##### Program Start ( <-- Power ON Reset ) ##### org program_area &stack stack_pointer db 0f3h ; db 0edh,56h ; &jmp main_routine ;##### RS232C INT Sequence ##### org int_area &ex &setl rxtop &lda rs232c &puthl db 2ch ; db 7dh ; &sta rxtop &ex db 0fbh ; db 0edh,4dh ; ;##### Main Program Area ##### main_routine: &jsr io_initial loop: &jsr rs232c_rx_check &jsr midi_tx_sequence &jmp loop ;##### RS232C Receive Data Check Sequence ##### rs232c_rx_check: &lda rxend db 47h ; &lda rxtop db 0b8h ; &bne rs232c_rx_data_found &rts rs232c_rx_data_found: db 78h ; &inc &sta rxend db 68h ; &seth rxfifo &gethl &sta rxdata &cmp 03ah &bne rs232c_rx_check_not_colon &movi 0,hlflag &rts rs232c_rx_check_not_colon: &cmp 030h &bne rs232c_rx_check_not_0 &movi 0,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_0: &cmp 031h &bne rs232c_rx_check_not_1 &movi 1,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_1: &cmp 032h &bne rs232c_rx_check_not_2 &movi 2,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_2: &cmp 033h &bne rs232c_rx_check_not_3 &movi 3,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_3: &cmp 034h &bne rs232c_rx_check_not_4 &movi 4,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_4: &cmp 035h &bne rs232c_rx_check_not_5 &movi 5,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_5: &cmp 036h &bne rs232c_rx_check_not_6 &movi 6,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_6: &cmp 037h &bne rs232c_rx_check_not_7 &movi 7,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_7: &cmp 038h &bne rs232c_rx_check_not_8 &movi 8,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_8: &cmp 039h &bne rs232c_rx_check_not_9 &movi 9,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_9: &cmp 041h &bne rs232c_rx_check_not_10 &movi 10,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_10: &cmp 042h &bne rs232c_rx_check_not_11 &movi 11,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_11: &cmp 043h &bne rs232c_rx_check_not_12 &movi 12,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_12: &cmp 044h &bne rs232c_rx_check_not_13 &movi 13,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_13: &cmp 045h &bne rs232c_rx_check_not_14 &movi 14,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_14: &cmp 046h &bne rs232c_rx_check_not_15 &movi 15,hlbuf &jmp rs232c_hl_check rs232c_rx_check_not_15: &rts rs232c_hl_check: &lda hlflag &cmp 0 &bne rs232c_rx_low_data &movi 1,hlflag &lda hlbuf db 0cbh ; db 027h ; db 0cbh ; db 027h ; db 0cbh ; db 027h ; db 0cbh ; db 027h ; &sta databuf &rts rs232c_rx_low_data: &movi 0,hlflag &lda hlbuf db 47h ; &lda databuf db 0b0h ; &sta databuf &seth txfifo &setl txtop &lda databuf &puthl db 2ch ; db 7dh ; &sta txtop &rts ;##### MIDI Transmit Data Check Sequence ##### midi_tx_sequence: &lda txend db 47h ; &lda txtop db 0b8h ; &bne midi_tx_data_found &rts midi_tx_data_found: &lda uart1 &and 00000001b &cmp 0 &bne midi_tx_uart_ok &rts midi_tx_uart_ok: db 78h ; &inc &sta txend db 68h ; &seth txfifo &gethl &sta uart0 &rts ;##### System I/O Initialize ##### io_initial: ; <71051 MIDI UART Initialize> &movi 0,uart1 &movi 0,uart1 &movi 0,uart1 &movi 01000000b,uart1 ; Software Reset &movi 01001110b,uart1 ; Mode Set &movi 00010001b,uart1 ; Command Set ; <71051 RS232C UART Initialize> &movi 0,rs232c+1 &movi 0,rs232c+1 &movi 0,rs232c+1 &movi 01000000b,rs232c+1 ; Software Reset &movi 01001110b,rs232c+1 ; Mode Set &movi 00010100b,rs232c+1 ; Command Set ; &ex &seth rxfifo &ex ; &movi 0,work &seth work_area ram_clear_work: &setl work db 3eh,00h ; ld a,#0 &puthl &lda work &inc &sta work &cmp 0 &bne ram_clear_work ; db 0fbh ; &rts end