Added GRAPHTST.ASM

This commit is contained in:
2024-09-15 00:55:11 +02:00
parent 2a5d0fa967
commit ac0c32d189

50
src/GRAPHTST.ASM Normal file
View File

@@ -0,0 +1,50 @@
; This is a simple test program for using escape sequences.
; Defines some routines that send escape sequences to the terminal
ORG 100H ; CP/M programs start at this address
JMP START ; jump to the main entry point
; Variable storage space
MsgStr: DB 'Hello, world.',13,10,0
ClsStr: DB 27,'[2J',0
HmeStr: DB 27,'[H',0
Stack: DW 0 ; place to save the old stack
SBOT: DS 32 ; reserve a local stack
; Constants
STOP: EQU $-1 ; top of our stack
BDOS: EQU 5 ; adress of the BDOS call
; Start of code
; PRINTF: Prints a string on the screen using a BDOS function.
; The address of the string is expected to be in register HL.
PRINTF:
PRLOOP: MOV A, M ; read next char
ORA A ; check, if string has ended
JZ PREND ; if char == 0, then leave
MOV E, A ; load the char into E
MVI C, 2 ; call BDOS function id 2
PUSH H ; save the HL register
CALL BDOS ; call the BDOS function
POP H ; restore the HL register
INX H ; point to the next char
JMP PRLOOP ; do the next char
PREND: RET ; return from subroutine
; CLS: Clears the screen by printing an escape sequence
CLS: LXI H, ClsStr ; Load the escape sequence
CALL PRINTF ; print the sequence
RET ; return
; HOME: Places the cursor in the upper right corner.
HOME: LXI H, HmeStr ; Load the escape sequence
CALL PRINTF ; print the sequence
RET
; Start of the main code block
START: LXI H, 0 ; blank out HL
DAD SP ; HL = SP
SHLD Stack ; save the original stack
LXI H, STOP ; set HL to the new stack top
SPHL ; set SP to point to our new stack
CALL CLS ; clear the screen
CALL HOME ; place cursor in the top left
LXI H, MsgStr ; load the string addr into HL
CALL PRINTF ; call our self defined print routine
LHLD Stack ; load original stack addr into HL
SPHL ; restore the original stack
RET ; return control back to CP/M
END