; ; Testing Z80 PIO's with RRD instruction ; Also see: ; https://retrocomputing.stackexchange.com/questions/6551/why-does-the-z80-include-the-rld-and-rrd-instructions ; .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 HL_CONTENT .DB 00H ; ; 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 ; Initialize A and (HL) LD A, 10000100B LD HL, HL_CONTENT LD (HL), 00100000B ; Display A before operation OUT (PIO1_A_D), A ; Send A to the PIO #1 port A OUT (PIO3_A_D), A ; Send A to the PIO #3 port A ; Display (HL) before operation PUSH AF LD A, (HL_CONTENT) OUT (PIO2_A_D), A ; Send (HL) to the PIO #2 port A POP AF CALL DELAY CALL DELAY CALL DELAY CALL DELAY CALL DELAY CALL DELAY ; ; Performs a 4-bit rightward rotation of the 12-bit number whose 4 most signigifcant bits are the 4 least significant ; bits of A, and its 8 least significant bits are in (HL) ; ROTATE: RRD ; After execution, expect: A = 10000000, (HL) = 01000010 ; Display A after operation OUT (PIO1_B_D), A ; Send A to the PIO #1 port B OUT (PIO3_B_D), A ; Send A to the PIO #3 port B ; Display (HL) after operation PUSH AF LD A, (HL_CONTENT) OUT (PIO2_B_D), A ; Send (HL) to the PIO #2 port B OUT (PIO4_A_D), A ; Send (HL) to the PIO #4 port A POP AF ; ------------------------------------------------------------ ; Finish and return to CP/M 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 ;-------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------- .END