i8080でHello, World

Absolute assembler for i8080/i8085を使ってSC-3000で、TMS9918を表示するプログラムを開発して行きます。

f:id:tanam:20140827235315p:image:w360

下記ホームページにある"Hello World" program for Z80 and TMS9918をi8080に移植しました。

https://www.msx.org/forum/development/msx-development/nyyrikkis-helloworld-code

; This is a "Hello World" program for i8080 and TMS9918 / TMS9928 / TMS9929 /
; V9938 or V9958 VDP.
;
; This version of Hello World was written by Timo "NYYRIKKI" Soilamaa
; 17.10.2001
; Modified by TANAM
; 30.05.2018
;----------------------------------------------------------------------
; Configure this part:

DATAP EQU 0BEH ; SC-3000 VDP Data port

CMDP EQU 0BFH ; SC-3000 VDP Command port
;-----------------------------------------------------------------------
; Program starts here:
;
		ORG 0 ; Z80 starts always from here when power is turned on
		JP START
START:
		DI ; We don't know, how interrupts works in this system, so we disable them.
		LXI SP,1FFFH
		LXI HL,00C0H
		LHLD 0001H
; Let's set VDP write address to #0000
		XRA A
		OUT CMDP
		MVI A,40H
		OUT CMDP

; Now let's clear first 16Kb of VDP memory
		LXI HL,3FFFH
CLEAR:
		MVI A,0
		OUT DATAP
		DCX H
		MOV A,H
		ORA L
		NOP ; Let's wait 8 clock cycles just in case VDP is not quick enough.
		NOP
		JNZ CLEAR

; Now it is time to set up VDP registers:
;----------------------------------------
; Register 0 to #0
;
; Set mode selection bit M3 (maybe also M4 & M5) to zero and 
; disable external video & horizontal interrupt

		OUT CMDP
		MVI A,80H
		OUT CMDP
;---------------------------------------- 
; Register 1 to #50
;
; Select 40 column mode, enable screen and disable vertical interrupt

		MVI A,50H
		OUT CMDP
		MVI A,81H
		OUT CMDP
;---------------------------------------- 
; Register 2 to #0
;
; Set pattern name table to #0000

		XRA A
		OUT CMDP
		MVI A,82H
		OUT CMDP
;---------------------------------------- 
; Register 3 is ignored as 40 column mode does not need color table
;
;---------------------------------------- 
; Register 4 to #1
; Set pattern generator table to #800

		MVI A,1H
		OUT CMDP
		MVI A,84H
		OUT CMDP
;---------------------------------------- 
; Registers 5 (Sprite attribute) & 6 (Sprite pattern) are ignored 
; as 40 column mode does not have sprites

;---------------------------------------- 
; Register 7 to #F0
; Set colors to white on black

		MVI A,0F0H
		OUT CMDP
		MVI A,87H
		OUT CMDP
;----------------------------------------

; Let's set VDP write address to #808 so, that we can write
; character set to memory
; (No need to write SPACE it is clear char already)
		MVI A,8
		OUT CMDP
		MVI A,48H
		OUT CMDP

; Let's copy character set
		LXI H, CHARS
		MVI B, CHARS_END-CHARS
COPYCHARS:
		MOV A,M
		OUT DATAP
		INX H
		NOP ; Let's wait 8 clock cycles just in case VDP is not quick enough.
		NOP
		DCR B
		JNZ COPYCHARS

; Let's set write address to start of name table
		XRA A
		OUT CMDP
		MVI A,40H
		OUT CMDP

; Let's put characters to screen
		LXI H,ORDER
		MVI B,ORDER_END-ORDER
COPYORDER:
		MOV A,M
		OUT DATAP
		INX H

		DCR B
		JNZ COPYORDER

; The end
		HLT

; Character set:
; --------------
ORDER:
 DB 1,2,3,3,4,0,5,4,6,3,7,0
ORDER_END:

CHARS:

; H
 DB 88H,88H,88H,0F8H,88H,88H,88H,00H
; e
 DB 00H,00H,70H,88H,0F8H,80H,70H,00H
; l
 DB 60H,20H,20H,20H,20H,20H,70H,00H
; o
 DB 00H,00H,70H,88H,88H,88H,70H,00H
; W
 DB 88H,88H,88H,0A8H,0A8H,0D8H,88H,00H
; r
 DB 00H,00H,0B0H,0C8H,80H,80H,80H,00H
; d
 DB 08H,08H,68H,98H,88H,98H,68H,00H
chars_end:

 DB 00H
		END

次は、SG-1000 Loaderを書き直していきます。