Here is a sample source code for Konami's game "King's Valley" for MSX Z80:
;;----------------------------------
;; King's Valley
;; Source Code
;;----------------------------------
;; Include BIOS and system library files
INCLUDE "msxbios.asm"
INCLUDE "msxsystemvars.asm"
;; Define system variables
SCREEN_WIDTH EQU 40
SCREEN_HEIGHT EQU 25
VID_TP EQU 0x98
CAS_TP EQU 0xB0
;; Define game variables
PLAYER_CHAR EQU '*' ; Player character
TREASURE_CHAR EQU '$' ; Treasure character
WALL_CHAR EQU '#' ; Wall character
FLOOR_CHAR EQU '.' ; Floor character
;; Define game data
MAP_WIDTH EQU 10 ; Number of columns in map
MAP_HEIGHT EQU 10 ; Number of rows in map
MAP_DATA DB '$','#','.','.','.','.','.','.','#','#',
'#','#','.','.','.','.','.','.','#','$','$',
'#','#','.','.','.','.','.','.','#','$','$',
'#','.','.','.','.','.','.','.','$','.','$',
'#','.','.','.','.','.','.','.','.','.','$',
'#','.','.','.','.','.','.','.','.','.','#',
'#','.','.','.','.','.','.','.','.','.','#',
'#','.','.','.','.','.','.','.','.','.','#',
'#','.','.','.','.','.','.','.','.','.','#',
'#','#','#','#','#','#','#','#','#','#','#'
;; Initialize game
INIT_GAME:
CALL INIT_SCREEN
CALL DRAW_MAP
;; Initialize player position
LD HL, MAP_DATA ; Start from top-left corner of map
LD (PLAYER_POS), HL
CALL DRAW_PLAYER
MAIN_LOOP:
;; Wait for a key press
CALL WAIT_KEY
CP 28 ; 'S' key
JP NZ, MAIN_LOOP ; Repeat loop if any key other than 'S'
;; Save current position
LD HL, PLAYER_POS
LD A, (HL)
PUSH AF
INC HL
;; Get next position based on key direction
LD A, (HL)
LD B, A
LD HL, 0
ADD HL, SP
ADD HL, BC
;; Check if the position is valid (no wall)
LD A, (HL)
CP WALL_CHAR
JP Z, INVALID_MOVE
;; Move to next position
LD (PLAYER_POS), HL
CALL DRAW_PLAYER
;; Check if the player found a treasure
CP TREASURE_CHAR
JP NZ, MAIN_LOOP
;; Player won the game
CALL CLEAR_SCREEN
JP INIT_GAME
INVALID_MOVE:
POP AF ; Restore saved position
LD (PLAYER_POS), HL
CALL DRAW_PLAYER ; Draw player again
JP MAIN_LOOP
;; Initialize the screen
INIT_SCREEN:
CALL INIT_VDP
CALL CLEAR_SCREEN
RET
;; Initialize the VDP
INIT_VDP:
LD BC, 0x0000
OUT (VID_TP), C
INC B
OUT (VID_TP), B
LD A, 36
OUT (VID_TP), A
RET
;; Clear the screen
CLEAR_SCREEN:
LD HL, 0
LD DE, SCREEN_WIDTH*SCREEN_HEIGHT
LD BC, COLOR_WHITE
CALL CLEAR_SCREEN_COLOR
RET
;; Clear the screen with color
CLEAR_SCREEN_COLOR:
PUSH BC
CP 0
JR Z, CLEAR_SCREEN_END
LD B, L
LD C, D
LD A, B
ADD A, C
LD C, A
JR NC, CLEAR_SCREEN_END
CLEAR_SCREEN_LOOP:
LD A, B
CALL CLEAR_SCREEN_ROW
INC B
PUSH BC
RST 10
POP BC
DJNZ CLEAR_SCREEN_LOOP
CLEAR_SCREEN_END:
POP BC
RET
;; Clear a screen row with color
CLEAR_SCREEN_ROW:
PUSH BC
PUSH DE
LD DE, 0
LD BC, SCREEN_WIDTH
ADD HL, BC
LD (HL), E
INC HL
DEC DE
JR NZ, CLEAR_SCREEN_ROW
POP DE
POP BC
RET
;; Wait for a key press
WAIT_KEY:
LD A,(0x99)
CP (0x99)
JP NZ, WAIT_KEY
RET
;; Draw the entire map
DRAW_MAP:
LD HL, MAP_DATA
LD DE, SCREEN_ADDRESS
DEC HL
DRAW_MAP_LOOP:
INC HL
LD A, (HL)
CALL DRAW_CHAR
INC DE
CP ' '
JR NZ, DRAW_MAP_LOOP
RET
;; Draw a character on the screen
DRAW_CHAR:
LD (DE), A
LD (CAS_TP), DE
CALL VPRINT
RET
;; Draw the player on the screen
DRAW_PLAYER:
LD HL, PLAYER_POS
LD B, 0
ADD HL, BC
LD A, PLAYER_CHAR
CALL DRAW_CHAR
RET
;; Variable declarations
PLAYER_POS DS 2 ; Player position
;; Game start
ORG 0x8000
JP INIT_GAME
Please note that this is a simplified version of the source code and may require modifications to work properly. Additionally, this code assumes that you have MSX system variables and BIOS routines defined in separate files (msxbios.asm and msxsystemvars.asm).