; This is an example of the "Hello World" program for CP/M 2.2. ; ; I use ZAS HI-TECH SOFTWARE Z80 Macro Assembler that's part of HI-TECH C 3.09 ; psect bss ORG 100H JR START ; Go to program start ; ; Variable storage space ; MsgStr1: DEFM 'Hello from Zilog Z80 ...' DEFB 13, 10, '$' MsgStr2: DEFM '... and from RC2014 !!!' DEFB 13, 10, 0 Stack1: DEFW 0 ; Place to save old stack Sbot: DEFS 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 ; IO_BOARD EQU 00H ; Digital I/O board PIO1_A_D EQU 068H ; Z80 PIO #1 on SC103 PIO1_A_C EQU 06AH PIO1_B_D EQU 069H PIO1_B_C EQU 06BH PIO2_A_D EQU 06CH ; Z80 PIO #2 on SC103 PIO2_A_C EQU 06EH PIO2_B_D EQU 06DH PIO2_B_C EQU 06FH PIO3_A_D EQU 0F0H ; Z80 PIO #3 on SC103 PIO3_A_C EQU 0F2H PIO3_B_D EQU 0F1H PIO3_B_C EQU 0F3H ; ; 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 ; PIO Control Word - set output mode OUT (PIO1_A_C), A ; Send CW to the PIO #1 port A OUT (PIO2_A_C), A ; Send CW to the PIO #2 port A OUT (PIO3_A_C), A ; Send CW to the PIO #3 port A OUT (PIO1_B_C), A ; Send CW to the PIO #1 port B OUT (PIO2_B_C), A ; Send CW to the PIO #2 port B OUT (PIO3_B_C), A ; Send CW to the PIO #3 port B ;---------------------------------------------------------------------- ; BDOS function 9 (C_WRITESTR) - Output string terminated with the '$' character LD DE, MsgStr1 ; MsgStr1 - DE = address of string LD C, 9 ; We want BDOS func 9 CALL BDOS ; Call BDOS function ;---------------------------------------------------------------------- ; BDOS function 2 (C_WRITE) - Console output LD HL, MsgStr2 ; MsgStr2 - HL = address of string LOOP1: LD A, (HL) ; Read string char OR A ; Set CPU flags JP Z, LEDS ; If char = 0 done LD E, A ; E = char to send LD C, 2 ; We want BDOS func 2 PUSH HL ; Save HL register CALL BDOS ; Call BDOS function POP HL ; Restore HL register INC HL ; Point to next char JR LOOP1 ; Do next char ;---------------------------------------------------------------------- ; Play with LED's on I/O board and Z80 PIO's LEDS: LD B, 0FH LOOP2: LD A, 55H CALL OUT_TO_LEDS CALL DELAY CPL CALL OUT_TO_LEDS CALL DELAY DJNZ LOOP2 ; ; Exit and return to CP/M ; LD HL, (Stack1) ; HL = entry stack address LD SP, HL ; SP = value on entry RET ; Return control back to CP/M ;-------------------------------------------------------------------------------------- ; ; Send A to digital I/O board and to PIO's ; OUT_TO_LEDS: OUT (IO_BOARD), A ; Send A to Digital I/O board OUT (PIO1_A_D), A ; Send A to the PIO #1 port A OUT (PIO2_A_D), A ; Send A to the PIO #2 port A OUT (PIO3_A_D), A ; Send A to the PIO #3 port A OUT (PIO1_B_D), A ; Send A to the PIO #1 port B OUT (PIO2_B_D), A ; Send A to the PIO #2 port B OUT (PIO3_B_D), A ; Send A to the PIO #3 port B RET ;-------------------------------------------------------------------------------------- ; 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 ;--------------------------------------------------------------------------------------