;=======================================================
; Sample1.asm
;
; This is just a sample for learning to use the assembler.
;=======================================================

	.list		; This directive causes a list file to be generated

#ifdef M100					; Defined in Project->Settings->Assembler tab
#include	"m100.inc"		; We can put Model specific defines in here
#else
#error "Please define the Model and provide an include file"
#endif

;=======================================================
; Define EXTERNal symbols in other files that we want
; to access.
;=======================================================

	extern	SAMP_HELLO, SAMP_PSTRING
	
;=======================================================
; Main entry point
;=======================================================
	.aseg					; Absolute code section

	org ENTRY_ADDR			; Defined in header file

SAMP_MAIN:
	dcr  A					; Test for A=1 upon entry
	jz   SAMP_HELLO			; Jump to print "Hello World"
	dcr  A					; Test for A=2 upon entry
	jz   SAMP_PSTRING		; Jump to print BASIC string
	dcr  A					; Test for A=3 upon entry
	jz   SAMP_SAVE			; Jump to save HL
	dcr  A					; Test for A=4 upon entry
	jz   SAMP_PVALUE		; Jump to print value
	lxi  H,S_HELP			; Prepare to print help text
	jmp  M_PRINT_HL			; Print string at HL.

;=======================================================
; Save value in HL to our local storage. 
;=======================================================
SAMP_SAVE:
	shld SAMP_VAR			; Save to our variable.  
	ret

;=======================================================
; Save value in HL to our local storage. 
;=======================================================
SAMP_PVALUE:
	lxi  H,S_VAL			; Point to string
	call M_PRINT_HL
	lhld SAMP_VAR			; Get our variable
	jmp  M_PRINT_INT_HL		; Print integer in HL ROM routine

;=======================================================
; Program strings.  These are part of code space
;=======================================================
SAMP_STRINGS	.cseg		; A Named Code segment

S_HELP:
	db   "usage: call 62000,A,HL", 0Dh, 0Ah
	db   "  A=1 ", 9, 9, 9, "- Hello World", 0Dh, 0Ah
	db   "  A=2, HL=VARPTR(A$)",9, "- Print String",0Dh,0Ah
	db   "  A=3, HL=value", 9, 9, "- Save Value", 0Dh, 0Ah
	db   "  A=4 ", 9, 9, 9, "- Print Value", 0Dh, 0Ah, 0

S_VAL		db  "Value = ", 0

;=======================================================
; Variables.  These are declared in an un-named ".dseg"
; segment, so they will be located by the linker at 
; the address defined for the default variable segment
; named ".text". 
;=======================================================
	.dseg
	
SAMP_VAR	ds   2			; Reserve space for 2 byte variable

