; ; Testing Z80 PIO's with 16-bit left-rigth rotation ; .ORG 100H ; CP/M programs start address. JP START ; Go to program start ; ; Variable storage space ; Stack1 .DW 0 ; Place to save old stack Sbot .DS 64 ; Temp stack for us to use ; ; Constants ; STOP .EQU $-1 ; Top of our stack BDOS .EQU 5 ; Address of BDOS entry ; ; Peripheral I/O adresses ; LEDS .EQU 00H ; Digital I/O board PIO1_A_D .EQU 068H ; Z80 PIO #1 PIO1_A_C .EQU 06AH PIO1_B_D .EQU 069H PIO1_B_C .EQU 06BH PIO2_A_D .EQU 06CH ; Z80 PIO #2 PIO2_A_C .EQU 06EH PIO2_B_D .EQU 06DH PIO2_B_C .EQU 06FH PIO3_A_D .EQU 0F0H ; Z80 PIO #3 PIO3_A_C .EQU 0F2H PIO3_B_D .EQU 0F1H PIO3_B_C .EQU 0F3H PIO4_A_D .EQU 0F4H ; Z80 PIO #4 PIO4_A_C .EQU 0F6H PIO4_B_D .EQU 0F5H PIO4_B_C .EQU 0F7H ; ; Start of code segment ; START: LD HL, 0000H ; HL = 0 ADD HL, SP ; HL = SP LD (Stack1), HL ; Save original stack LD HL, STOP ; HL = address of new stack LD SP, HL ; Stack pointer = our stack ; Initialize Z80 PIO's LD A, 0FH ; Control word for PIO, set output mode OUT (PIO1_A_C), A ; PIO #1 port A OUT (PIO1_B_C), A ; PIO #1 port B OUT (PIO2_A_C), A ; PIO #2 port A OUT (PIO2_B_C), A ; PIO #2 port B OUT (PIO3_A_C), A ; PIO #3 port A OUT (PIO3_B_C), A ; PIO #3 port B OUT (PIO4_A_C), A ; PIO #4 port A OUT (PIO4_B_C), A ; PIO #4 port B ; Turn all LED's OFF XOR A ; LD A, 0 -> XOR A OUT (LEDS), A OUT (PIO1_A_D), A OUT (PIO1_B_D), A OUT (PIO2_A_D), A OUT (PIO2_B_D), A OUT (PIO3_A_D), A OUT (PIO3_B_D), A OUT (PIO4_A_D), A OUT (PIO4_B_D), A REPEAT1: LD D, 10000000B LD E, 00000001B LD B, 07H ; 8 LED's = 7 rotation cycles LD A, 01010101B CALL OUT_TO_LEDS ; Display initial state CALL DELAY CALL DELAY REPEAT2: ; ; 8-bit rotation in D and E ; RLC E ; Rotate E left, bit 7 goes to bit 0 and to Carry Flag RRC D ; Rotate D right, bit 0 goes to bit 7 and to Carry Flag CPL CALL OUT_TO_LEDS CALL DELAY CALL DELAY LD H, A ; Save A IN A, (LEDS) ; Read buttons on I/O board OR 0 ; Set Zero Flag LD A, H ; Restore A JR NZ, EXIT ; If any button pressed, exit DJNZ REPEAT2 ; Loop through 7 cycles IN A, (LEDS) ; Read buttons on IO board OR 0 ; Set Zero Flag JR NZ, EXIT ; If any button pressed, exit JR REPEAT1 ; ; Exit and return code ; EXIT: LD HL, (Stack1) ; HL = entry stack address LD SP, HL ; SP = value on entry RET ; Return control back to CP/M ;-------------------------------------------------------------------------------------- ; DELAY: ; Routine to add a delay ; PUSH BC LD C, 0FFH DELAY1: LD B, 0FFH DELAY2: NOP DJNZ DELAY2 DEC C JR NZ, DELAY1 POP BC RET ;-------------------------------------------------------------------------------------- ; ; Send A to digital I/O board and BC and DE to PIO's ; OUT_TO_LEDS: OUT (LEDS), A ; Send A to Digital I/O board CALL DELAY PUSH AF LD A, B OUT (PIO1_A_D), A ; Send B to the PIO #1 port A LD A, C OUT (PIO1_B_D), A ; Send C to the PIO #1 port B LD A, D OUT (LEDS), A ; Send A to Digital I/O board OUT (PIO2_A_D), A ; Send D to the PIO #2 port A OUT (PIO3_A_D), A ; Send D to the PIO #3 port A OUT (PIO4_A_D), A ; Send D to the PIO #4 port A LD A, E OUT (PIO2_B_D), A ; Send E to the PIO #2 port B OUT (PIO3_B_D), A ; Send E to the PIO #3 port B POP AF RET ;-------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------- .END